blob: 20e05572a14680c92bbff2d56ef512d71fbbf32d [file] [log] [blame]
codeworkx62f02ba2012-05-20 12:00:36 +02001/*
2 * V4L2 subdev interface library
3 *
4 * Copyright (C) 2010-2011 Ideas on board SPRL
5 *
6 * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef __SUBDEV_H__
23#define __SUBDEV_H__
24
25#include <v4l2-subdev.h>
26
27struct media_entity;
28
29/**
30 * @brief Open a sub-device.
31 * @param entity - sub-device media entity.
32 *
33 * Open the V4L2 subdev device node associated with @a entity. The file
34 * descriptor is stored in the media_entity structure.
35 *
36 * @return 0 on success, or a negative error code on failure.
37 */
38int v4l2_subdev_open(struct media_entity *entity);
39
40/**
41 * @brief Close a sub-device.
42 * @param entity - sub-device media entity.
43 *
44 * Close the V4L2 subdev device node associated with the @a entity and opened by
45 * a previous call to v4l2_subdev_open() (either explicit or implicit).
46 */
47void v4l2_subdev_close(struct media_entity *entity);
48
49/**
50 * @brief Retrieve the format on a pad.
51 * @param entity - subdev-device media entity.
52 * @param format - format to be filled.
53 * @param pad - pad number.
54 * @param which - identifier of the format to get.
55 *
56 * Retrieve the current format on the @a entity @a pad and store it in the
57 * @a format structure.
58 *
59 * @a which is set to V4L2_SUBDEV_FORMAT_TRY to retrieve the try format stored
60 * in the file handle, of V4L2_SUBDEV_FORMAT_ACTIVE to retrieve the current
61 * active format.
62 *
63 * @return 0 on success, or a negative error code on failure.
64 */
65int v4l2_subdev_get_format(struct media_entity *entity,
66 struct v4l2_mbus_framefmt *format, unsigned int pad,
67 enum v4l2_subdev_format_whence which);
68
69/**
70 * @brief Set the format on a pad.
71 * @param entity - subdev-device media entity.
72 * @param format - format.
73 * @param pad - pad number.
74 * @param which - identifier of the format to set.
75 *
76 * Set the format on the @a entity @a pad to @a format. The driver is allowed to
77 * modify the requested format, in which case @a format is updated with the
78 * modifications.
79 *
80 * @a which is set to V4L2_SUBDEV_FORMAT_TRY to set the try format stored in the
81 * file handle, of V4L2_SUBDEV_FORMAT_ACTIVE to configure the device with an
82 * active format.
83 *
84 * @return 0 on success, or a negative error code on failure.
85 */
86int v4l2_subdev_set_format(struct media_entity *entity,
87 struct v4l2_mbus_framefmt *format, unsigned int pad,
88 enum v4l2_subdev_format_whence which);
89
90/**
91 * @brief Retrieve the crop rectangle on a pad.
92 * @param entity - subdev-device media entity.
93 * @param rect - crop rectangle to be filled.
94 * @param pad - pad number.
95 * @param which - identifier of the format to get.
96 *
97 * Retrieve the current crop rectangleon the @a entity @a pad and store it in
98 * the @a rect structure.
99 *
100 * @a which is set to V4L2_SUBDEV_FORMAT_TRY to retrieve the try crop rectangle
101 * stored in the file handle, of V4L2_SUBDEV_FORMAT_ACTIVE to retrieve the
102 * current active crop rectangle.
103 *
104 * @return 0 on success, or a negative error code on failure.
105 */
106int v4l2_subdev_get_crop(struct media_entity *entity, struct v4l2_rect *rect,
107 unsigned int pad, enum v4l2_subdev_format_whence which);
108
109/**
110 * @brief Set the crop rectangle on a pad.
111 * @param entity - subdev-device media entity.
112 * @param rect - crop rectangle.
113 * @param pad - pad number.
114 * @param which - identifier of the format to set.
115 *
116 * Set the crop rectangle on the @a entity @a pad to @a rect. The driver is
117 * allowed to modify the requested rectangle, in which case @a rect is updated
118 * with the modifications.
119 *
120 * @a which is set to V4L2_SUBDEV_FORMAT_TRY to set the try crop rectangle
121 * stored in the file handle, of V4L2_SUBDEV_FORMAT_ACTIVE to configure the
122 * device with an active crop rectangle.
123 *
124 * @return 0 on success, or a negative error code on failure.
125 */
126int v4l2_subdev_set_crop(struct media_entity *entity, struct v4l2_rect *rect,
127 unsigned int pad, enum v4l2_subdev_format_whence which);
128
129/**
130 * @brief Retrieve the frame interval on a sub-device.
131 * @param entity - subdev-device media entity.
132 * @param interval - frame interval to be filled.
133 *
134 * Retrieve the current frame interval on subdev @a entity and store it in the
135 * @a interval structure.
136 *
137 * Frame interval retrieving is usually supported only on devices at the
138 * beginning of video pipelines, such as sensors.
139 *
140 * @return 0 on success, or a negative error code on failure.
141 */
142
143int v4l2_subdev_get_frame_interval(struct media_entity *entity,
144 struct v4l2_fract *interval);
145
146/**
147 * @brief Set the frame interval on a sub-device.
148 * @param entity - subdev-device media entity.
149 * @param interval - frame interval.
150 *
151 * Set the frame interval on subdev @a entity to @a interval. The driver is
152 * allowed to modify the requested frame interval, in which case @a interval is
153 * updated with the modifications.
154 *
155 * Frame interval setting is usually supported only on devices at the beginning
156 * of video pipelines, such as sensors.
157 *
158 * @return 0 on success, or a negative error code on failure.
159 */
160int v4l2_subdev_set_frame_interval(struct media_entity *entity,
161 struct v4l2_fract *interval);
162
163/**
164 * @brief Parse a string and apply format, crop and frame interval settings.
165 * @param media - media device.
166 * @param p - input string
167 * @param endp - pointer to string p where parsing ended (return)
168 *
169 * Parse string @a p and apply format, crop and frame interval settings to a
170 * subdev pad specified in @a p. @a endp will be written a pointer where
171 * parsing of @a p ended.
172 *
173 * Format strings are separeted by commas (,).
174 *
175 * @return 0 on success, or a negative error code on failure.
176 */
177int v4l2_subdev_parse_setup_formats(struct media_device *media, const char *p);
178
179/**
180 * @brief Convert media bus pixel code to string.
181 * @param code - input string
182 *
183 * Convert media bus pixel code @a code to a human-readable string.
184 *
185 * @return A pointer to a string on success, NULL on failure.
186 */
187const char *v4l2_subdev_pixelcode_to_string(enum v4l2_mbus_pixelcode code);
188
189/**
190 * @brief Parse string to media bus pixel code.
191 * @param string - input string
192 * @param lenght - length of the string
193 *
194 * Parse human readable string @a string to an media bus pixel code.
195 *
196 * @return media bus pixelcode on success, -1 on failure.
197 */
198enum v4l2_mbus_pixelcode v4l2_subdev_string_to_pixelcode(const char *string,
199 unsigned int length);
200#endif