Hans Verkuil | b2f0648 | 2005-11-13 16:07:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | v4l2 common internal API header |
| 3 | |
| 4 | This header contains internal shared ioctl definitions for use by the |
| 5 | internal low-level v4l2 drivers. |
| 6 | Each ioctl begins with VIDIOC_INT_ to clearly mark that it is an internal |
| 7 | define, |
| 8 | |
| 9 | Copyright (C) 2005 Hans Verkuil <hverkuil@xs4all.nl> |
| 10 | |
| 11 | This program is free software; you can redistribute it and/or modify |
| 12 | it under the terms of the GNU General Public License as published by |
| 13 | the Free Software Foundation; either version 2 of the License, or |
| 14 | (at your option) any later version. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | GNU General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU General Public License |
| 22 | along with this program; if not, write to the Free Software |
| 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #ifndef V4L2_COMMON_H_ |
| 27 | #define V4L2_COMMON_H_ |
| 28 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 29 | #include <media/v4l2-dev.h> |
| 30 | |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 31 | /* Common printk constructs for v4l-i2c drivers. These macros create a unique |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 32 | prefix consisting of the driver name, the adapter number and the i2c |
| 33 | address. */ |
| 34 | #define v4l_printk(level, name, adapter, addr, fmt, arg...) \ |
| 35 | printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg) |
| 36 | |
Mauro Carvalho Chehab | cab462f | 2006-01-09 15:53:26 -0200 | [diff] [blame] | 37 | #define v4l_client_printk(level, client, fmt, arg...) \ |
Lars-Peter Clausen | f9d32f2 | 2013-09-29 10:51:01 +0200 | [diff] [blame] | 38 | v4l_printk(level, (client)->dev.driver->name, (client)->adapter, \ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 39 | (client)->addr, fmt , ## arg) |
| 40 | |
| 41 | #define v4l_err(client, fmt, arg...) \ |
| 42 | v4l_client_printk(KERN_ERR, client, fmt , ## arg) |
| 43 | |
| 44 | #define v4l_warn(client, fmt, arg...) \ |
| 45 | v4l_client_printk(KERN_WARNING, client, fmt , ## arg) |
| 46 | |
| 47 | #define v4l_info(client, fmt, arg...) \ |
| 48 | v4l_client_printk(KERN_INFO, client, fmt , ## arg) |
| 49 | |
| 50 | /* These three macros assume that the debug level is set with a module |
| 51 | parameter called 'debug'. */ |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 52 | #define v4l_dbg(level, debug, client, fmt, arg...) \ |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 53 | do { \ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 54 | if (debug >= (level)) \ |
| 55 | v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \ |
| 56 | } while (0) |
| 57 | |
Mauro Carvalho Chehab | a41231d | 2016-11-16 08:35:08 -0200 | [diff] [blame] | 58 | /* Add a version of v4l_dbg to be used on drivers using dev_foo() macros */ |
| 59 | #define dev_dbg_lvl(__dev, __level, __debug, __fmt, __arg...) \ |
| 60 | do { \ |
| 61 | if (__debug >= (__level)) \ |
| 62 | dev_printk(KERN_DEBUG, __dev, __fmt, ##__arg); \ |
| 63 | } while (0) |
| 64 | |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 65 | /* ------------------------------------------------------------------------- */ |
| 66 | |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 67 | /* These printk constructs can be used with v4l2_device and v4l2_subdev */ |
| 68 | #define v4l2_printk(level, dev, fmt, arg...) \ |
| 69 | printk(level "%s: " fmt, (dev)->name , ## arg) |
| 70 | |
| 71 | #define v4l2_err(dev, fmt, arg...) \ |
| 72 | v4l2_printk(KERN_ERR, dev, fmt , ## arg) |
| 73 | |
| 74 | #define v4l2_warn(dev, fmt, arg...) \ |
| 75 | v4l2_printk(KERN_WARNING, dev, fmt , ## arg) |
| 76 | |
| 77 | #define v4l2_info(dev, fmt, arg...) \ |
| 78 | v4l2_printk(KERN_INFO, dev, fmt , ## arg) |
| 79 | |
| 80 | /* These three macros assume that the debug level is set with a module |
| 81 | parameter called 'debug'. */ |
| 82 | #define v4l2_dbg(level, debug, dev, fmt, arg...) \ |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 83 | do { \ |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 84 | if (debug >= (level)) \ |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 85 | v4l2_printk(KERN_DEBUG, dev, fmt , ## arg); \ |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 86 | } while (0) |
| 87 | |
Mauro Carvalho Chehab | b871915 | 2016-07-21 12:26:04 -0300 | [diff] [blame] | 88 | /** |
| 89 | * v4l2_ctrl_query_fill- Fill in a struct v4l2_queryctrl |
| 90 | * |
| 91 | * @qctrl: pointer to the &struct v4l2_queryctrl to be filled |
| 92 | * @min: minimum value for the control |
| 93 | * @max: maximum value for the control |
| 94 | * @step: control step |
| 95 | * @def: default value for the control |
| 96 | * |
| 97 | * Fills the &struct v4l2_queryctrl fields for the query control. |
| 98 | * |
| 99 | * .. note:: |
| 100 | * |
| 101 | * This function assumes that the @qctrl->id field is filled. |
| 102 | * |
| 103 | * Returns -EINVAL if the control is not known by the V4L2 core, 0 on success. |
| 104 | */ |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 105 | |
Mauro Carvalho Chehab | b871915 | 2016-07-21 12:26:04 -0300 | [diff] [blame] | 106 | int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, |
| 107 | s32 min, s32 max, s32 step, s32 def); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 108 | |
| 109 | /* ------------------------------------------------------------------------- */ |
| 110 | |
Hans Verkuil | 78a3b4d | 2009-04-01 03:41:09 -0300 | [diff] [blame] | 111 | /* I2C Helper functions */ |
Hans Verkuil | 8ffbc65 | 2007-09-12 08:32:50 -0300 | [diff] [blame] | 112 | |
| 113 | struct i2c_driver; |
| 114 | struct i2c_adapter; |
| 115 | struct i2c_client; |
Jean Delvare | d2653e9 | 2008-04-29 23:11:39 +0200 | [diff] [blame] | 116 | struct i2c_device_id; |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 117 | struct v4l2_device; |
| 118 | struct v4l2_subdev; |
| 119 | struct v4l2_subdev_ops; |
Hans Verkuil | 8ffbc65 | 2007-09-12 08:32:50 -0300 | [diff] [blame] | 120 | |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 121 | /** |
| 122 | * v4l2_i2c_new_subdev - Load an i2c module and return an initialized |
| 123 | * &struct v4l2_subdev. |
| 124 | * |
| 125 | * @v4l2_dev: pointer to &struct v4l2_device |
| 126 | * @adapter: pointer to struct i2c_adapter |
| 127 | * @client_type: name of the chip that's on the adapter. |
| 128 | * @addr: I2C address. If zero, it will use @probe_addrs |
| 129 | * @probe_addrs: array with a list of address. The last entry at such |
Mauro Carvalho Chehab | 4a3fad7 | 2018-01-04 06:47:28 -0500 | [diff] [blame] | 130 | * array should be %I2C_CLIENT_END. |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 131 | * |
| 132 | * returns a &struct v4l2_subdev pointer. |
| 133 | */ |
Hans Verkuil | 3c7c937 | 2011-01-08 07:08:02 -0300 | [diff] [blame] | 134 | struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev, |
Laurent Pinchart | 9a1f8b3 | 2010-09-24 10:16:44 -0300 | [diff] [blame] | 135 | struct i2c_adapter *adapter, const char *client_type, |
Hans Verkuil | f0222c7 | 2009-06-09 17:12:33 -0300 | [diff] [blame] | 136 | u8 addr, const unsigned short *probe_addrs); |
| 137 | |
| 138 | struct i2c_board_info; |
| 139 | |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 140 | /** |
| 141 | * v4l2_i2c_new_subdev_board - Load an i2c module and return an initialized |
| 142 | * &struct v4l2_subdev. |
| 143 | * |
| 144 | * @v4l2_dev: pointer to &struct v4l2_device |
| 145 | * @adapter: pointer to struct i2c_adapter |
| 146 | * @info: pointer to struct i2c_board_info used to replace the irq, |
| 147 | * platform_data and addr arguments. |
| 148 | * @probe_addrs: array with a list of address. The last entry at such |
Mauro Carvalho Chehab | 4a3fad7 | 2018-01-04 06:47:28 -0500 | [diff] [blame] | 149 | * array should be %I2C_CLIENT_END. |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 150 | * |
| 151 | * returns a &struct v4l2_subdev pointer. |
| 152 | */ |
Hans Verkuil | f0222c7 | 2009-06-09 17:12:33 -0300 | [diff] [blame] | 153 | struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, |
Laurent Pinchart | 9a1f8b3 | 2010-09-24 10:16:44 -0300 | [diff] [blame] | 154 | struct i2c_adapter *adapter, struct i2c_board_info *info, |
| 155 | const unsigned short *probe_addrs); |
Hans Verkuil | f0222c7 | 2009-06-09 17:12:33 -0300 | [diff] [blame] | 156 | |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 157 | /** |
Sakari Ailus | 0658293 | 2018-08-29 05:52:46 -0400 | [diff] [blame^] | 158 | * v4l2_i2c_subdev_set_name - Set name for an I²C sub-device |
| 159 | * |
| 160 | * @sd: pointer to &struct v4l2_subdev |
| 161 | * @client: pointer to struct i2c_client |
| 162 | * @devname: the name of the device; if NULL, the I²C device's name will be used |
| 163 | * @postfix: sub-device specific string to put right after the I²C device name; |
| 164 | * may be NULL |
| 165 | */ |
| 166 | void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client, |
| 167 | const char *devname, const char *postfix); |
| 168 | |
| 169 | /** |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 170 | * v4l2_i2c_subdev_init - Initializes a &struct v4l2_subdev with data from |
| 171 | * an i2c_client struct. |
| 172 | * |
| 173 | * @sd: pointer to &struct v4l2_subdev |
| 174 | * @client: pointer to struct i2c_client |
| 175 | * @ops: pointer to &struct v4l2_subdev_ops |
| 176 | */ |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 177 | void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, |
| 178 | const struct v4l2_subdev_ops *ops); |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * v4l2_i2c_subdev_addr - returns i2c client address of &struct v4l2_subdev. |
| 182 | * |
| 183 | * @sd: pointer to &struct v4l2_subdev |
| 184 | * |
| 185 | * Returns the address of an I2C sub-device |
| 186 | */ |
Hans Verkuil | ab373190 | 2009-02-21 18:08:41 -0300 | [diff] [blame] | 187 | unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd); |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 188 | |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 189 | /** |
| 190 | * enum v4l2_i2c_tuner_type - specifies the range of tuner address that |
| 191 | * should be used when seeking for I2C devices. |
| 192 | * |
| 193 | * @ADDRS_RADIO: Radio tuner addresses. |
| 194 | * Represent the following I2C addresses: |
| 195 | * 0x10 (if compiled with tea5761 support) |
| 196 | * and 0x60. |
| 197 | * @ADDRS_DEMOD: Demod tuner addresses. |
| 198 | * Represent the following I2C addresses: |
| 199 | * 0x42, 0x43, 0x4a and 0x4b. |
| 200 | * @ADDRS_TV: TV tuner addresses. |
| 201 | * Represent the following I2C addresses: |
| 202 | * 0x42, 0x43, 0x4a, 0x4b, 0x60, 0x61, 0x62, |
| 203 | * 0x63 and 0x64. |
| 204 | * @ADDRS_TV_WITH_DEMOD: TV tuner addresses if demod is present, this |
| 205 | * excludes addresses used by the demodulator |
| 206 | * from the list of candidates. |
| 207 | * Represent the following I2C addresses: |
| 208 | * 0x60, 0x61, 0x62, 0x63 and 0x64. |
| 209 | * |
| 210 | * NOTE: All I2C addresses above use the 7-bit notation. |
| 211 | */ |
Hans Verkuil | c7d29e2 | 2009-01-18 19:37:59 -0300 | [diff] [blame] | 212 | enum v4l2_i2c_tuner_type { |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 213 | ADDRS_RADIO, |
| 214 | ADDRS_DEMOD, |
| 215 | ADDRS_TV, |
Hans Verkuil | c7d29e2 | 2009-01-18 19:37:59 -0300 | [diff] [blame] | 216 | ADDRS_TV_WITH_DEMOD, |
| 217 | }; |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 218 | /** |
| 219 | * v4l2_i2c_tuner_addrs - Return a list of I2C tuner addresses to probe. |
| 220 | * |
| 221 | * @type: type of the tuner to seek, as defined by |
| 222 | * &enum v4l2_i2c_tuner_type. |
| 223 | * |
| 224 | * NOTE: Use only if the tuner addresses are unknown. |
| 225 | */ |
Hans Verkuil | c7d29e2 | 2009-01-18 19:37:59 -0300 | [diff] [blame] | 226 | const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type); |
| 227 | |
Hans Verkuil | 8ffbc65 | 2007-09-12 08:32:50 -0300 | [diff] [blame] | 228 | /* ------------------------------------------------------------------------- */ |
| 229 | |
Dmitri Belimov | 85e0921 | 2010-03-23 11:23:29 -0300 | [diff] [blame] | 230 | /* SPI Helper functions */ |
| 231 | #if defined(CONFIG_SPI) |
| 232 | |
| 233 | #include <linux/spi/spi.h> |
| 234 | |
| 235 | struct spi_device; |
| 236 | |
Mauro Carvalho Chehab | b871915 | 2016-07-21 12:26:04 -0300 | [diff] [blame] | 237 | /** |
| 238 | * v4l2_spi_new_subdev - Load an spi module and return an initialized |
| 239 | * &struct v4l2_subdev. |
| 240 | * |
| 241 | * |
| 242 | * @v4l2_dev: pointer to &struct v4l2_device. |
| 243 | * @master: pointer to struct spi_master. |
| 244 | * @info: pointer to struct spi_board_info. |
| 245 | * |
| 246 | * returns a &struct v4l2_subdev pointer. |
| 247 | */ |
Dmitri Belimov | 85e0921 | 2010-03-23 11:23:29 -0300 | [diff] [blame] | 248 | struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev, |
| 249 | struct spi_master *master, struct spi_board_info *info); |
| 250 | |
Mauro Carvalho Chehab | b871915 | 2016-07-21 12:26:04 -0300 | [diff] [blame] | 251 | /** |
| 252 | * v4l2_spi_subdev_init - Initialize a v4l2_subdev with data from an |
| 253 | * spi_device struct. |
| 254 | * |
| 255 | * @sd: pointer to &struct v4l2_subdev |
| 256 | * @spi: pointer to struct spi_device. |
| 257 | * @ops: pointer to &struct v4l2_subdev_ops |
| 258 | */ |
Dmitri Belimov | 85e0921 | 2010-03-23 11:23:29 -0300 | [diff] [blame] | 259 | void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi, |
| 260 | const struct v4l2_subdev_ops *ops); |
| 261 | #endif |
| 262 | |
| 263 | /* ------------------------------------------------------------------------- */ |
| 264 | |
Mauro Carvalho Chehab | 01154ef | 2017-09-21 10:04:30 -0400 | [diff] [blame] | 265 | /* |
| 266 | * FIXME: these remaining ioctls/structs should be removed as well, but they |
| 267 | * are still used in tuner-simple.c (TUNER_SET_CONFIG) and cx18/ivtv (RESET). |
| 268 | * To remove these ioctls some more cleanup is needed in those modules. |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 269 | * |
| 270 | * It doesn't make much sense on documenting them, as what we really want is |
| 271 | * to get rid of them. |
Mauro Carvalho Chehab | 01154ef | 2017-09-21 10:04:30 -0400 | [diff] [blame] | 272 | */ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 273 | |
Hans Verkuil | 78a3b4d | 2009-04-01 03:41:09 -0300 | [diff] [blame] | 274 | /* s_config */ |
Mauro Carvalho Chehab | 7f17112 | 2007-10-18 19:56:47 -0300 | [diff] [blame] | 275 | struct v4l2_priv_tun_config { |
| 276 | int tuner; |
| 277 | void *priv; |
| 278 | }; |
Mauro Carvalho Chehab | 7f17112 | 2007-10-18 19:56:47 -0300 | [diff] [blame] | 279 | #define TUNER_SET_CONFIG _IOW('d', 92, struct v4l2_priv_tun_config) |
Hans Verkuil | 757d250 | 2006-01-23 17:11:10 -0200 | [diff] [blame] | 280 | |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 281 | #define VIDIOC_INT_RESET _IOW ('d', 102, u32) |
Hans Verkuil | 6c31e59 | 2009-04-02 11:37:41 -0300 | [diff] [blame] | 282 | |
Trent Piepho | b0d3159 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 283 | /* ------------------------------------------------------------------------- */ |
| 284 | |
| 285 | /* Miscellaneous helper functions */ |
| 286 | |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 287 | /** |
| 288 | * v4l_bound_align_image - adjust video dimensions according to |
| 289 | * a given constraints. |
| 290 | * |
| 291 | * @width: pointer to width that will be adjusted if needed. |
| 292 | * @wmin: minimum width. |
| 293 | * @wmax: maximum width. |
| 294 | * @walign: least significant bit on width. |
| 295 | * @height: pointer to height that will be adjusted if needed. |
| 296 | * @hmin: minimum height. |
| 297 | * @hmax: maximum height. |
| 298 | * @halign: least significant bit on width. |
| 299 | * @salign: least significant bit for the image size (e. g. |
| 300 | * :math:`width * height`). |
| 301 | * |
| 302 | * Clip an image to have @width between @wmin and @wmax, and @height between |
| 303 | * @hmin and @hmax, inclusive. |
| 304 | * |
| 305 | * Additionally, the @width will be a multiple of :math:`2^{walign}`, |
| 306 | * the @height will be a multiple of :math:`2^{halign}`, and the overall |
| 307 | * size :math:`width * height` will be a multiple of :math:`2^{salign}`. |
| 308 | * |
| 309 | * .. note:: |
| 310 | * |
| 311 | * #. The clipping rectangle may be shrunk or enlarged to fit the alignment |
| 312 | * constraints. |
| 313 | * #. @wmax must not be smaller than @wmin. |
| 314 | * #. @hmax must not be smaller than @hmin. |
| 315 | * #. The alignments must not be so high there are no possible image |
| 316 | * sizes within the allowed bounds. |
| 317 | * #. @wmin and @hmin must be at least 1 (don't use 0). |
| 318 | * #. For @walign, @halign and @salign, if you don't care about a certain |
| 319 | * alignment, specify ``0``, as :math:`2^0 = 1` and one byte alignment |
| 320 | * is equivalent to no alignment. |
| 321 | * #. If you only want to adjust downward, specify a maximum that's the |
| 322 | * same as the initial value. |
| 323 | */ |
| 324 | void v4l_bound_align_image(unsigned int *width, unsigned int wmin, |
Trent Piepho | b0d3159 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 325 | unsigned int wmax, unsigned int walign, |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 326 | unsigned int *height, unsigned int hmin, |
Trent Piepho | b0d3159 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 327 | unsigned int hmax, unsigned int halign, |
| 328 | unsigned int salign); |
Hans Verkuil | 3fd8e64 | 2010-09-30 09:29:37 -0300 | [diff] [blame] | 329 | |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 330 | /** |
Sakari Ailus | 95ce9c2 | 2018-02-23 04:50:14 -0500 | [diff] [blame] | 331 | * v4l2_find_nearest_size - Find the nearest size among a discrete |
| 332 | * set of resolutions contained in an array of a driver specific struct. |
| 333 | * |
| 334 | * @array: a driver specific array of image sizes |
Sakari Ailus | d2dc57b | 2018-03-21 16:29:27 -0400 | [diff] [blame] | 335 | * @array_size: the length of the driver specific array of image sizes |
Sakari Ailus | 95ce9c2 | 2018-02-23 04:50:14 -0500 | [diff] [blame] | 336 | * @width_field: the name of the width field in the driver specific struct |
| 337 | * @height_field: the name of the height field in the driver specific struct |
| 338 | * @width: desired width. |
| 339 | * @height: desired height. |
| 340 | * |
| 341 | * Finds the closest resolution to minimize the width and height differences |
| 342 | * between what requested and the supported resolutions. The size of the width |
| 343 | * and height fields in the driver specific must equal to that of u32, i.e. four |
| 344 | * bytes. |
| 345 | * |
| 346 | * Returns the best match or NULL if the length of the array is zero. |
| 347 | */ |
Sakari Ailus | d2dc57b | 2018-03-21 16:29:27 -0400 | [diff] [blame] | 348 | #define v4l2_find_nearest_size(array, array_size, width_field, height_field, \ |
Sakari Ailus | 95ce9c2 | 2018-02-23 04:50:14 -0500 | [diff] [blame] | 349 | width, height) \ |
| 350 | ({ \ |
| 351 | BUILD_BUG_ON(sizeof((array)->width_field) != sizeof(u32) || \ |
| 352 | sizeof((array)->height_field) != sizeof(u32)); \ |
Sakari Ailus | 2bbc46e | 2018-06-21 05:41:21 -0400 | [diff] [blame] | 353 | (typeof(&(array)[0]))__v4l2_find_nearest_size( \ |
Sakari Ailus | d2dc57b | 2018-03-21 16:29:27 -0400 | [diff] [blame] | 354 | (array), array_size, sizeof(*(array)), \ |
Sakari Ailus | 95ce9c2 | 2018-02-23 04:50:14 -0500 | [diff] [blame] | 355 | offsetof(typeof(*(array)), width_field), \ |
| 356 | offsetof(typeof(*(array)), height_field), \ |
| 357 | width, height); \ |
| 358 | }) |
| 359 | const void * |
| 360 | __v4l2_find_nearest_size(const void *array, size_t array_size, |
| 361 | size_t entry_size, size_t width_offset, |
| 362 | size_t height_offset, s32 width, s32 height); |
| 363 | |
| 364 | /** |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 365 | * v4l2_get_timestamp - helper routine to get a timestamp to be used when |
| 366 | * filling streaming metadata. Internally, it uses ktime_get_ts(), |
| 367 | * which is the recommended way to get it. |
| 368 | * |
| 369 | * @tv: pointer to &struct timeval to be filled. |
| 370 | */ |
Sakari Ailus | abd2329 | 2012-09-15 07:51:47 -0300 | [diff] [blame] | 371 | void v4l2_get_timestamp(struct timeval *tv); |
| 372 | |
Hans Verkuil | 672de9a | 2018-01-22 03:58:36 -0500 | [diff] [blame] | 373 | /** |
| 374 | * v4l2_g_parm_cap - helper routine for vidioc_g_parm to fill this in by |
| 375 | * calling the g_frame_interval op of the given subdev. It only works |
| 376 | * for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the |
| 377 | * function name. |
| 378 | * |
| 379 | * @vdev: the struct video_device pointer. Used to determine the device caps. |
| 380 | * @sd: the sub-device pointer. |
| 381 | * @a: the VIDIOC_G_PARM argument. |
| 382 | */ |
| 383 | int v4l2_g_parm_cap(struct video_device *vdev, |
| 384 | struct v4l2_subdev *sd, struct v4l2_streamparm *a); |
| 385 | |
| 386 | /** |
| 387 | * v4l2_s_parm_cap - helper routine for vidioc_s_parm to fill this in by |
| 388 | * calling the s_frame_interval op of the given subdev. It only works |
| 389 | * for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the |
| 390 | * function name. |
| 391 | * |
| 392 | * @vdev: the struct video_device pointer. Used to determine the device caps. |
| 393 | * @sd: the sub-device pointer. |
| 394 | * @a: the VIDIOC_S_PARM argument. |
| 395 | */ |
| 396 | int v4l2_s_parm_cap(struct video_device *vdev, |
| 397 | struct v4l2_subdev *sd, struct v4l2_streamparm *a); |
| 398 | |
Hans Verkuil | b2f0648 | 2005-11-13 16:07:55 -0800 | [diff] [blame] | 399 | #endif /* V4L2_COMMON_H_ */ |