1 /* 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 <linux/v4l2-subdev.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 struct media_entity; 32 33 /** 34 * @brief Open a sub-device. 35 * @param entity - sub-device media entity. 36 * 37 * Open the V4L2 subdev device node associated with @a entity. The file 38 * descriptor is stored in the media_entity structure. 39 * 40 * @return 0 on success, or a negative error code on failure. 41 */ 42 int v4l2_subdev_open(struct media_entity *entity); 43 44 /** 45 * @brief Close a sub-device. 46 * @param entity - sub-device media entity. 47 * 48 * Close the V4L2 subdev device node associated with the @a entity and opened by 49 * a previous call to v4l2_subdev_open() (either explicit or implicit). 50 */ 51 void v4l2_subdev_close(struct media_entity *entity); 52 53 /** 54 * @brief Retrieve the format on a pad. 55 * @param entity - subdev-device media entity. 56 * @param format - format to be filled. 57 * @param pad - pad number. 58 * @param which - identifier of the format to get. 59 * 60 * Retrieve the current format on the @a entity @a pad and store it in the 61 * @a format structure. 62 * 63 * @a which is set to V4L2_SUBDEV_FORMAT_TRY to retrieve the try format stored 64 * in the file handle, of V4L2_SUBDEV_FORMAT_ACTIVE to retrieve the current 65 * active format. 66 * 67 * @return 0 on success, or a negative error code on failure. 68 */ 69 int v4l2_subdev_get_format(struct media_entity *entity, 70 struct v4l2_mbus_framefmt *format, unsigned int pad, 71 enum v4l2_subdev_format_whence which); 72 73 /** 74 * @brief Set the format on a pad. 75 * @param entity - subdev-device media entity. 76 * @param format - format. 77 * @param pad - pad number. 78 * @param which - identifier of the format to set. 79 * 80 * Set the format on the @a entity @a pad to @a format. The driver is allowed to 81 * modify the requested format, in which case @a format is updated with the 82 * modifications. 83 * 84 * @a which is set to V4L2_SUBDEV_FORMAT_TRY to set the try format stored in the 85 * file handle, of V4L2_SUBDEV_FORMAT_ACTIVE to configure the device with an 86 * active format. 87 * 88 * @return 0 on success, or a negative error code on failure. 89 */ 90 int v4l2_subdev_set_format(struct media_entity *entity, 91 struct v4l2_mbus_framefmt *format, unsigned int pad, 92 enum v4l2_subdev_format_whence which); 93 94 /** 95 * @brief Retrieve a selection rectangle on a pad. 96 * @param entity - subdev-device media entity. 97 * @param r - rectangle to be filled. 98 * @param pad - pad number. 99 * @param target - selection target 100 * @param which - identifier of the format to get. 101 * 102 * Retrieve the @a target selection rectangle on the @a entity @a pad 103 * and store it in the @a rect structure. 104 * 105 * @a which is set to V4L2_SUBDEV_FORMAT_TRY to retrieve the try 106 * selection rectangle stored in the file handle, or 107 * V4L2_SUBDEV_FORMAT_ACTIVE to retrieve the current active selection 108 * rectangle. 109 * 110 * @return 0 on success, or a negative error code on failure. 111 */ 112 int v4l2_subdev_get_selection(struct media_entity *entity, 113 struct v4l2_rect *rect, unsigned int pad, unsigned int target, 114 enum v4l2_subdev_format_whence which); 115 116 /** 117 * @brief Set a selection rectangle on a pad. 118 * @param entity - subdev-device media entity. 119 * @param rect - crop rectangle. 120 * @param pad - pad number. 121 * @param target - selection target 122 * @param which - identifier of the format to set. 123 * 124 * Set the @a target selection rectangle on the @a entity @a pad to @a 125 * rect. The driver is allowed to modify the requested rectangle, in 126 * which case @a rect is updated with the modifications. 127 * 128 * @a which is set to V4L2_SUBDEV_FORMAT_TRY to set the try crop rectangle 129 * stored in the file handle, of V4L2_SUBDEV_FORMAT_ACTIVE to configure the 130 * device with an active crop rectangle. 131 * 132 * @return 0 on success, or a negative error code on failure. 133 */ 134 int v4l2_subdev_set_selection(struct media_entity *entity, 135 struct v4l2_rect *rect, unsigned int pad, unsigned int target, 136 enum v4l2_subdev_format_whence which); 137 138 /** 139 * @brief Retrieve the frame interval on a sub-device. 140 * @param entity - subdev-device media entity. 141 * @param interval - frame interval to be filled. 142 * 143 * Retrieve the current frame interval on subdev @a entity and store it in the 144 * @a interval structure. 145 * 146 * Frame interval retrieving is usually supported only on devices at the 147 * beginning of video pipelines, such as sensors. 148 * 149 * @return 0 on success, or a negative error code on failure. 150 */ 151 152 int v4l2_subdev_get_frame_interval(struct media_entity *entity, 153 struct v4l2_fract *interval); 154 155 /** 156 * @brief Set the frame interval on a sub-device. 157 * @param entity - subdev-device media entity. 158 * @param interval - frame interval. 159 * 160 * Set the frame interval on subdev @a entity to @a interval. The driver is 161 * allowed to modify the requested frame interval, in which case @a interval is 162 * updated with the modifications. 163 * 164 * Frame interval setting is usually supported only on devices at the beginning 165 * of video pipelines, such as sensors. 166 * 167 * @return 0 on success, or a negative error code on failure. 168 */ 169 int v4l2_subdev_set_frame_interval(struct media_entity *entity, 170 struct v4l2_fract *interval); 171 172 /** 173 * @brief Parse a string and apply format, crop and frame interval settings. 174 * @param media - media device. 175 * @param p - input string 176 * @param endp - pointer to string p where parsing ended (return) 177 * 178 * Parse string @a p and apply format, crop and frame interval settings to a 179 * subdev pad specified in @a p. @a endp will be written a pointer where 180 * parsing of @a p ended. 181 * 182 * Format strings are separeted by commas (,). 183 * 184 * @return 0 on success, or a negative error code on failure. 185 */ 186 int v4l2_subdev_parse_setup_formats(struct media_device *media, const char *p); 187 188 /** 189 * @brief Convert media bus pixel code to string. 190 * @param code - input string 191 * 192 * Convert media bus pixel code @a code to a human-readable string. 193 * 194 * @return A pointer to a string on success, NULL on failure. 195 */ 196 const char *v4l2_subdev_pixelcode_to_string(enum v4l2_mbus_pixelcode code); 197 198 /** 199 * @brief Parse string to media bus pixel code. 200 * @param string - input string 201 * @param lenght - length of the string 202 * 203 * Parse human readable string @a string to an media bus pixel code. 204 * 205 * @return media bus pixelcode on success, -1 on failure. 206 */ 207 enum v4l2_mbus_pixelcode v4l2_subdev_string_to_pixelcode(const char *string, 208 unsigned int length); 209 #ifdef __cplusplus 210 } 211 #endif 212 #endif 213