Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Hans Verkuil | b2f0648 | 2005-11-13 16:07:55 -0800 | [diff] [blame] | 2 | /* |
| 3 | v4l2 common internal API header |
| 4 | |
| 5 | This header contains internal shared ioctl definitions for use by the |
| 6 | internal low-level v4l2 drivers. |
| 7 | Each ioctl begins with VIDIOC_INT_ to clearly mark that it is an internal |
| 8 | define, |
| 9 | |
| 10 | Copyright (C) 2005 Hans Verkuil <hverkuil@xs4all.nl> |
| 11 | |
Hans Verkuil | b2f0648 | 2005-11-13 16:07:55 -0800 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #ifndef V4L2_COMMON_H_ |
| 15 | #define V4L2_COMMON_H_ |
| 16 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 17 | #include <media/v4l2-dev.h> |
| 18 | |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 19 | /* Common printk constructs for v4l-i2c drivers. These macros create a unique |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 20 | prefix consisting of the driver name, the adapter number and the i2c |
| 21 | address. */ |
| 22 | #define v4l_printk(level, name, adapter, addr, fmt, arg...) \ |
| 23 | printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg) |
| 24 | |
Mauro Carvalho Chehab | cab462f | 2006-01-09 15:53:26 -0200 | [diff] [blame] | 25 | #define v4l_client_printk(level, client, fmt, arg...) \ |
Lars-Peter Clausen | f9d32f2 | 2013-09-29 10:51:01 +0200 | [diff] [blame] | 26 | v4l_printk(level, (client)->dev.driver->name, (client)->adapter, \ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 27 | (client)->addr, fmt , ## arg) |
| 28 | |
| 29 | #define v4l_err(client, fmt, arg...) \ |
| 30 | v4l_client_printk(KERN_ERR, client, fmt , ## arg) |
| 31 | |
| 32 | #define v4l_warn(client, fmt, arg...) \ |
| 33 | v4l_client_printk(KERN_WARNING, client, fmt , ## arg) |
| 34 | |
| 35 | #define v4l_info(client, fmt, arg...) \ |
| 36 | v4l_client_printk(KERN_INFO, client, fmt , ## arg) |
| 37 | |
| 38 | /* These three macros assume that the debug level is set with a module |
| 39 | parameter called 'debug'. */ |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 40 | #define v4l_dbg(level, debug, client, fmt, arg...) \ |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 41 | do { \ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 42 | if (debug >= (level)) \ |
| 43 | v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \ |
| 44 | } while (0) |
| 45 | |
Mauro Carvalho Chehab | a41231d | 2016-11-16 08:35:08 -0200 | [diff] [blame] | 46 | /* Add a version of v4l_dbg to be used on drivers using dev_foo() macros */ |
| 47 | #define dev_dbg_lvl(__dev, __level, __debug, __fmt, __arg...) \ |
| 48 | do { \ |
| 49 | if (__debug >= (__level)) \ |
| 50 | dev_printk(KERN_DEBUG, __dev, __fmt, ##__arg); \ |
| 51 | } while (0) |
| 52 | |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 53 | /* ------------------------------------------------------------------------- */ |
| 54 | |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 55 | /* These printk constructs can be used with v4l2_device and v4l2_subdev */ |
| 56 | #define v4l2_printk(level, dev, fmt, arg...) \ |
| 57 | printk(level "%s: " fmt, (dev)->name , ## arg) |
| 58 | |
| 59 | #define v4l2_err(dev, fmt, arg...) \ |
| 60 | v4l2_printk(KERN_ERR, dev, fmt , ## arg) |
| 61 | |
| 62 | #define v4l2_warn(dev, fmt, arg...) \ |
| 63 | v4l2_printk(KERN_WARNING, dev, fmt , ## arg) |
| 64 | |
| 65 | #define v4l2_info(dev, fmt, arg...) \ |
| 66 | v4l2_printk(KERN_INFO, dev, fmt , ## arg) |
| 67 | |
| 68 | /* These three macros assume that the debug level is set with a module |
| 69 | parameter called 'debug'. */ |
| 70 | #define v4l2_dbg(level, debug, dev, fmt, arg...) \ |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 71 | do { \ |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 72 | if (debug >= (level)) \ |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 73 | v4l2_printk(KERN_DEBUG, dev, fmt , ## arg); \ |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 74 | } while (0) |
| 75 | |
Mauro Carvalho Chehab | b871915 | 2016-07-21 12:26:04 -0300 | [diff] [blame] | 76 | /** |
| 77 | * v4l2_ctrl_query_fill- Fill in a struct v4l2_queryctrl |
| 78 | * |
| 79 | * @qctrl: pointer to the &struct v4l2_queryctrl to be filled |
| 80 | * @min: minimum value for the control |
| 81 | * @max: maximum value for the control |
| 82 | * @step: control step |
| 83 | * @def: default value for the control |
| 84 | * |
| 85 | * Fills the &struct v4l2_queryctrl fields for the query control. |
| 86 | * |
| 87 | * .. note:: |
| 88 | * |
| 89 | * This function assumes that the @qctrl->id field is filled. |
| 90 | * |
| 91 | * Returns -EINVAL if the control is not known by the V4L2 core, 0 on success. |
| 92 | */ |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 93 | |
Mauro Carvalho Chehab | b871915 | 2016-07-21 12:26:04 -0300 | [diff] [blame] | 94 | int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, |
| 95 | s32 min, s32 max, s32 step, s32 def); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 96 | |
| 97 | /* ------------------------------------------------------------------------- */ |
| 98 | |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 99 | struct v4l2_device; |
| 100 | struct v4l2_subdev; |
| 101 | struct v4l2_subdev_ops; |
Hans Verkuil | 8ffbc65 | 2007-09-12 08:32:50 -0300 | [diff] [blame] | 102 | |
Ezequiel Garcia | 02283b9 | 2019-08-15 13:48:03 -0300 | [diff] [blame] | 103 | /* I2C Helper functions */ |
| 104 | #include <linux/i2c.h> |
| 105 | |
| 106 | /** |
| 107 | * enum v4l2_i2c_tuner_type - specifies the range of tuner address that |
| 108 | * should be used when seeking for I2C devices. |
| 109 | * |
| 110 | * @ADDRS_RADIO: Radio tuner addresses. |
| 111 | * Represent the following I2C addresses: |
| 112 | * 0x10 (if compiled with tea5761 support) |
| 113 | * and 0x60. |
| 114 | * @ADDRS_DEMOD: Demod tuner addresses. |
| 115 | * Represent the following I2C addresses: |
| 116 | * 0x42, 0x43, 0x4a and 0x4b. |
| 117 | * @ADDRS_TV: TV tuner addresses. |
| 118 | * Represent the following I2C addresses: |
| 119 | * 0x42, 0x43, 0x4a, 0x4b, 0x60, 0x61, 0x62, |
| 120 | * 0x63 and 0x64. |
| 121 | * @ADDRS_TV_WITH_DEMOD: TV tuner addresses if demod is present, this |
| 122 | * excludes addresses used by the demodulator |
| 123 | * from the list of candidates. |
| 124 | * Represent the following I2C addresses: |
| 125 | * 0x60, 0x61, 0x62, 0x63 and 0x64. |
| 126 | * |
| 127 | * NOTE: All I2C addresses above use the 7-bit notation. |
| 128 | */ |
| 129 | enum v4l2_i2c_tuner_type { |
| 130 | ADDRS_RADIO, |
| 131 | ADDRS_DEMOD, |
| 132 | ADDRS_TV, |
| 133 | ADDRS_TV_WITH_DEMOD, |
| 134 | }; |
| 135 | |
| 136 | #if defined(CONFIG_VIDEO_V4L2_I2C) |
| 137 | |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 138 | /** |
| 139 | * v4l2_i2c_new_subdev - Load an i2c module and return an initialized |
| 140 | * &struct v4l2_subdev. |
| 141 | * |
| 142 | * @v4l2_dev: pointer to &struct v4l2_device |
| 143 | * @adapter: pointer to struct i2c_adapter |
| 144 | * @client_type: name of the chip that's on the adapter. |
| 145 | * @addr: I2C address. If zero, it will use @probe_addrs |
| 146 | * @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] | 147 | * array should be %I2C_CLIENT_END. |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 148 | * |
| 149 | * returns a &struct v4l2_subdev pointer. |
| 150 | */ |
Hans Verkuil | 3c7c937 | 2011-01-08 07:08:02 -0300 | [diff] [blame] | 151 | struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev, |
Laurent Pinchart | 9a1f8b3 | 2010-09-24 10:16:44 -0300 | [diff] [blame] | 152 | struct i2c_adapter *adapter, const char *client_type, |
Hans Verkuil | f0222c7 | 2009-06-09 17:12:33 -0300 | [diff] [blame] | 153 | u8 addr, const unsigned short *probe_addrs); |
| 154 | |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 155 | /** |
| 156 | * v4l2_i2c_new_subdev_board - Load an i2c module and return an initialized |
| 157 | * &struct v4l2_subdev. |
| 158 | * |
| 159 | * @v4l2_dev: pointer to &struct v4l2_device |
| 160 | * @adapter: pointer to struct i2c_adapter |
| 161 | * @info: pointer to struct i2c_board_info used to replace the irq, |
| 162 | * platform_data and addr arguments. |
| 163 | * @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] | 164 | * array should be %I2C_CLIENT_END. |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 165 | * |
| 166 | * returns a &struct v4l2_subdev pointer. |
| 167 | */ |
Hans Verkuil | f0222c7 | 2009-06-09 17:12:33 -0300 | [diff] [blame] | 168 | 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] | 169 | struct i2c_adapter *adapter, struct i2c_board_info *info, |
| 170 | const unsigned short *probe_addrs); |
Hans Verkuil | f0222c7 | 2009-06-09 17:12:33 -0300 | [diff] [blame] | 171 | |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 172 | /** |
Sakari Ailus | 0658293 | 2018-08-29 05:52:46 -0400 | [diff] [blame] | 173 | * v4l2_i2c_subdev_set_name - Set name for an I²C sub-device |
| 174 | * |
| 175 | * @sd: pointer to &struct v4l2_subdev |
| 176 | * @client: pointer to struct i2c_client |
| 177 | * @devname: the name of the device; if NULL, the I²C device's name will be used |
| 178 | * @postfix: sub-device specific string to put right after the I²C device name; |
| 179 | * may be NULL |
| 180 | */ |
| 181 | void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client, |
| 182 | const char *devname, const char *postfix); |
| 183 | |
| 184 | /** |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 185 | * v4l2_i2c_subdev_init - Initializes a &struct v4l2_subdev with data from |
| 186 | * an i2c_client struct. |
| 187 | * |
| 188 | * @sd: pointer to &struct v4l2_subdev |
| 189 | * @client: pointer to struct i2c_client |
| 190 | * @ops: pointer to &struct v4l2_subdev_ops |
| 191 | */ |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 192 | void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, |
| 193 | const struct v4l2_subdev_ops *ops); |
Mauro Carvalho Chehab | a39c57f | 2016-07-21 10:08:31 -0300 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * v4l2_i2c_subdev_addr - returns i2c client address of &struct v4l2_subdev. |
| 197 | * |
| 198 | * @sd: pointer to &struct v4l2_subdev |
| 199 | * |
| 200 | * Returns the address of an I2C sub-device |
| 201 | */ |
Hans Verkuil | ab373190 | 2009-02-21 18:08:41 -0300 | [diff] [blame] | 202 | unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd); |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 203 | |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 204 | /** |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 205 | * v4l2_i2c_tuner_addrs - Return a list of I2C tuner addresses to probe. |
| 206 | * |
| 207 | * @type: type of the tuner to seek, as defined by |
| 208 | * &enum v4l2_i2c_tuner_type. |
| 209 | * |
| 210 | * NOTE: Use only if the tuner addresses are unknown. |
| 211 | */ |
Hans Verkuil | c7d29e2 | 2009-01-18 19:37:59 -0300 | [diff] [blame] | 212 | const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type); |
| 213 | |
Ezequiel Garcia | 51ff392 | 2019-08-15 13:48:05 -0300 | [diff] [blame] | 214 | /** |
| 215 | * v4l2_i2c_subdev_unregister - Unregister a v4l2_subdev |
| 216 | * |
| 217 | * @sd: pointer to &struct v4l2_subdev |
| 218 | */ |
| 219 | void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd); |
| 220 | |
Ezequiel Garcia | 02283b9 | 2019-08-15 13:48:03 -0300 | [diff] [blame] | 221 | #else |
| 222 | |
| 223 | static inline struct v4l2_subdev * |
| 224 | v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev, |
| 225 | struct i2c_adapter *adapter, const char *client_type, |
| 226 | u8 addr, const unsigned short *probe_addrs) |
| 227 | { |
| 228 | return NULL; |
| 229 | } |
| 230 | |
| 231 | static inline struct v4l2_subdev * |
| 232 | v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, |
| 233 | struct i2c_adapter *adapter, struct i2c_board_info *info, |
| 234 | const unsigned short *probe_addrs) |
| 235 | { |
| 236 | return NULL; |
| 237 | } |
| 238 | |
| 239 | static inline void |
| 240 | v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client, |
| 241 | const char *devname, const char *postfix) |
| 242 | {} |
| 243 | |
| 244 | static inline void |
| 245 | v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, |
| 246 | const struct v4l2_subdev_ops *ops) |
| 247 | {} |
| 248 | |
| 249 | static inline unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd) |
| 250 | { |
| 251 | return I2C_CLIENT_END; |
| 252 | } |
| 253 | |
| 254 | static inline const unsigned short * |
| 255 | v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type) |
| 256 | { |
| 257 | return NULL; |
| 258 | } |
| 259 | |
Ezequiel Garcia | 51ff392 | 2019-08-15 13:48:05 -0300 | [diff] [blame] | 260 | static inline void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd) |
| 261 | {} |
| 262 | |
Ezequiel Garcia | 02283b9 | 2019-08-15 13:48:03 -0300 | [diff] [blame] | 263 | #endif |
| 264 | |
Hans Verkuil | 8ffbc65 | 2007-09-12 08:32:50 -0300 | [diff] [blame] | 265 | /* ------------------------------------------------------------------------- */ |
| 266 | |
Dmitri Belimov | 85e0921 | 2010-03-23 11:23:29 -0300 | [diff] [blame] | 267 | /* SPI Helper functions */ |
Dmitri Belimov | 85e0921 | 2010-03-23 11:23:29 -0300 | [diff] [blame] | 268 | |
| 269 | #include <linux/spi/spi.h> |
| 270 | |
Ezequiel Garcia | 7c795df | 2019-08-15 13:48:02 -0300 | [diff] [blame] | 271 | #if defined(CONFIG_SPI) |
Dmitri Belimov | 85e0921 | 2010-03-23 11:23:29 -0300 | [diff] [blame] | 272 | |
Mauro Carvalho Chehab | b871915 | 2016-07-21 12:26:04 -0300 | [diff] [blame] | 273 | /** |
| 274 | * v4l2_spi_new_subdev - Load an spi module and return an initialized |
| 275 | * &struct v4l2_subdev. |
| 276 | * |
| 277 | * |
| 278 | * @v4l2_dev: pointer to &struct v4l2_device. |
| 279 | * @master: pointer to struct spi_master. |
| 280 | * @info: pointer to struct spi_board_info. |
| 281 | * |
| 282 | * returns a &struct v4l2_subdev pointer. |
| 283 | */ |
Dmitri Belimov | 85e0921 | 2010-03-23 11:23:29 -0300 | [diff] [blame] | 284 | struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev, |
| 285 | struct spi_master *master, struct spi_board_info *info); |
| 286 | |
Mauro Carvalho Chehab | b871915 | 2016-07-21 12:26:04 -0300 | [diff] [blame] | 287 | /** |
| 288 | * v4l2_spi_subdev_init - Initialize a v4l2_subdev with data from an |
| 289 | * spi_device struct. |
| 290 | * |
| 291 | * @sd: pointer to &struct v4l2_subdev |
| 292 | * @spi: pointer to struct spi_device. |
| 293 | * @ops: pointer to &struct v4l2_subdev_ops |
| 294 | */ |
Dmitri Belimov | 85e0921 | 2010-03-23 11:23:29 -0300 | [diff] [blame] | 295 | void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi, |
| 296 | const struct v4l2_subdev_ops *ops); |
Ezequiel Garcia | 7c795df | 2019-08-15 13:48:02 -0300 | [diff] [blame] | 297 | |
Ezequiel Garcia | a9cff39 | 2019-08-15 13:48:04 -0300 | [diff] [blame] | 298 | /** |
| 299 | * v4l2_spi_subdev_unregister - Unregister a v4l2_subdev |
| 300 | * |
| 301 | * @sd: pointer to &struct v4l2_subdev |
| 302 | */ |
| 303 | void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd); |
| 304 | |
Ezequiel Garcia | 7c795df | 2019-08-15 13:48:02 -0300 | [diff] [blame] | 305 | #else |
| 306 | |
| 307 | static inline struct v4l2_subdev * |
| 308 | v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev, |
| 309 | struct spi_master *master, struct spi_board_info *info) |
| 310 | { |
| 311 | return NULL; |
| 312 | } |
| 313 | |
| 314 | static inline void |
| 315 | v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi, |
| 316 | const struct v4l2_subdev_ops *ops) |
| 317 | {} |
| 318 | |
Ezequiel Garcia | a9cff39 | 2019-08-15 13:48:04 -0300 | [diff] [blame] | 319 | static inline void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd) |
| 320 | {} |
Dmitri Belimov | 85e0921 | 2010-03-23 11:23:29 -0300 | [diff] [blame] | 321 | #endif |
| 322 | |
| 323 | /* ------------------------------------------------------------------------- */ |
| 324 | |
Mauro Carvalho Chehab | 01154ef | 2017-09-21 10:04:30 -0400 | [diff] [blame] | 325 | /* |
| 326 | * FIXME: these remaining ioctls/structs should be removed as well, but they |
| 327 | * are still used in tuner-simple.c (TUNER_SET_CONFIG) and cx18/ivtv (RESET). |
| 328 | * 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] | 329 | * |
| 330 | * It doesn't make much sense on documenting them, as what we really want is |
| 331 | * to get rid of them. |
Mauro Carvalho Chehab | 01154ef | 2017-09-21 10:04:30 -0400 | [diff] [blame] | 332 | */ |
Hans Verkuil | 7e8b09e | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 333 | |
Hans Verkuil | 78a3b4d | 2009-04-01 03:41:09 -0300 | [diff] [blame] | 334 | /* s_config */ |
Mauro Carvalho Chehab | 7f17112 | 2007-10-18 19:56:47 -0300 | [diff] [blame] | 335 | struct v4l2_priv_tun_config { |
| 336 | int tuner; |
| 337 | void *priv; |
| 338 | }; |
Mauro Carvalho Chehab | 7f17112 | 2007-10-18 19:56:47 -0300 | [diff] [blame] | 339 | #define TUNER_SET_CONFIG _IOW('d', 92, struct v4l2_priv_tun_config) |
Hans Verkuil | 757d250 | 2006-01-23 17:11:10 -0200 | [diff] [blame] | 340 | |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 341 | #define VIDIOC_INT_RESET _IOW ('d', 102, u32) |
Hans Verkuil | 6c31e59 | 2009-04-02 11:37:41 -0300 | [diff] [blame] | 342 | |
Trent Piepho | b0d3159 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 343 | /* ------------------------------------------------------------------------- */ |
| 344 | |
| 345 | /* Miscellaneous helper functions */ |
| 346 | |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 347 | /** |
| 348 | * v4l_bound_align_image - adjust video dimensions according to |
| 349 | * a given constraints. |
| 350 | * |
| 351 | * @width: pointer to width that will be adjusted if needed. |
| 352 | * @wmin: minimum width. |
| 353 | * @wmax: maximum width. |
| 354 | * @walign: least significant bit on width. |
| 355 | * @height: pointer to height that will be adjusted if needed. |
| 356 | * @hmin: minimum height. |
| 357 | * @hmax: maximum height. |
Niklas Söderlund | ae5a8ca | 2018-09-12 20:07:38 -0400 | [diff] [blame] | 358 | * @halign: least significant bit on height. |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 359 | * @salign: least significant bit for the image size (e. g. |
| 360 | * :math:`width * height`). |
| 361 | * |
| 362 | * Clip an image to have @width between @wmin and @wmax, and @height between |
| 363 | * @hmin and @hmax, inclusive. |
| 364 | * |
| 365 | * Additionally, the @width will be a multiple of :math:`2^{walign}`, |
| 366 | * the @height will be a multiple of :math:`2^{halign}`, and the overall |
| 367 | * size :math:`width * height` will be a multiple of :math:`2^{salign}`. |
| 368 | * |
| 369 | * .. note:: |
| 370 | * |
| 371 | * #. The clipping rectangle may be shrunk or enlarged to fit the alignment |
| 372 | * constraints. |
| 373 | * #. @wmax must not be smaller than @wmin. |
| 374 | * #. @hmax must not be smaller than @hmin. |
| 375 | * #. The alignments must not be so high there are no possible image |
| 376 | * sizes within the allowed bounds. |
| 377 | * #. @wmin and @hmin must be at least 1 (don't use 0). |
| 378 | * #. For @walign, @halign and @salign, if you don't care about a certain |
| 379 | * alignment, specify ``0``, as :math:`2^0 = 1` and one byte alignment |
| 380 | * is equivalent to no alignment. |
| 381 | * #. If you only want to adjust downward, specify a maximum that's the |
| 382 | * same as the initial value. |
| 383 | */ |
| 384 | void v4l_bound_align_image(unsigned int *width, unsigned int wmin, |
Trent Piepho | b0d3159 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 385 | unsigned int wmax, unsigned int walign, |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 386 | unsigned int *height, unsigned int hmin, |
Trent Piepho | b0d3159 | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 387 | unsigned int hmax, unsigned int halign, |
| 388 | unsigned int salign); |
Hans Verkuil | 3fd8e64 | 2010-09-30 09:29:37 -0300 | [diff] [blame] | 389 | |
Mauro Carvalho Chehab | 76a59fe | 2017-09-22 09:03:54 -0400 | [diff] [blame] | 390 | /** |
Sakari Ailus | 95ce9c2 | 2018-02-23 04:50:14 -0500 | [diff] [blame] | 391 | * v4l2_find_nearest_size - Find the nearest size among a discrete |
| 392 | * set of resolutions contained in an array of a driver specific struct. |
| 393 | * |
| 394 | * @array: a driver specific array of image sizes |
Sakari Ailus | d2dc57b | 2018-03-21 16:29:27 -0400 | [diff] [blame] | 395 | * @array_size: the length of the driver specific array of image sizes |
Sakari Ailus | 95ce9c2 | 2018-02-23 04:50:14 -0500 | [diff] [blame] | 396 | * @width_field: the name of the width field in the driver specific struct |
| 397 | * @height_field: the name of the height field in the driver specific struct |
| 398 | * @width: desired width. |
| 399 | * @height: desired height. |
| 400 | * |
| 401 | * Finds the closest resolution to minimize the width and height differences |
| 402 | * between what requested and the supported resolutions. The size of the width |
| 403 | * and height fields in the driver specific must equal to that of u32, i.e. four |
| 404 | * bytes. |
| 405 | * |
| 406 | * Returns the best match or NULL if the length of the array is zero. |
| 407 | */ |
Sakari Ailus | d2dc57b | 2018-03-21 16:29:27 -0400 | [diff] [blame] | 408 | #define v4l2_find_nearest_size(array, array_size, width_field, height_field, \ |
Sakari Ailus | 95ce9c2 | 2018-02-23 04:50:14 -0500 | [diff] [blame] | 409 | width, height) \ |
| 410 | ({ \ |
| 411 | BUILD_BUG_ON(sizeof((array)->width_field) != sizeof(u32) || \ |
| 412 | sizeof((array)->height_field) != sizeof(u32)); \ |
Sakari Ailus | 2bbc46e | 2018-06-21 05:41:21 -0400 | [diff] [blame] | 413 | (typeof(&(array)[0]))__v4l2_find_nearest_size( \ |
Sakari Ailus | d2dc57b | 2018-03-21 16:29:27 -0400 | [diff] [blame] | 414 | (array), array_size, sizeof(*(array)), \ |
Sakari Ailus | 95ce9c2 | 2018-02-23 04:50:14 -0500 | [diff] [blame] | 415 | offsetof(typeof(*(array)), width_field), \ |
| 416 | offsetof(typeof(*(array)), height_field), \ |
| 417 | width, height); \ |
| 418 | }) |
| 419 | const void * |
| 420 | __v4l2_find_nearest_size(const void *array, size_t array_size, |
| 421 | size_t entry_size, size_t width_offset, |
| 422 | size_t height_offset, s32 width, s32 height); |
| 423 | |
| 424 | /** |
Hans Verkuil | 672de9a | 2018-01-22 03:58:36 -0500 | [diff] [blame] | 425 | * v4l2_g_parm_cap - helper routine for vidioc_g_parm to fill this in by |
| 426 | * calling the g_frame_interval op of the given subdev. It only works |
| 427 | * for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the |
| 428 | * function name. |
| 429 | * |
| 430 | * @vdev: the struct video_device pointer. Used to determine the device caps. |
| 431 | * @sd: the sub-device pointer. |
| 432 | * @a: the VIDIOC_G_PARM argument. |
| 433 | */ |
| 434 | int v4l2_g_parm_cap(struct video_device *vdev, |
| 435 | struct v4l2_subdev *sd, struct v4l2_streamparm *a); |
| 436 | |
| 437 | /** |
| 438 | * v4l2_s_parm_cap - helper routine for vidioc_s_parm to fill this in by |
| 439 | * calling the s_frame_interval op of the given subdev. It only works |
| 440 | * for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the |
| 441 | * function name. |
| 442 | * |
| 443 | * @vdev: the struct video_device pointer. Used to determine the device caps. |
| 444 | * @sd: the sub-device pointer. |
| 445 | * @a: the VIDIOC_S_PARM argument. |
| 446 | */ |
| 447 | int v4l2_s_parm_cap(struct video_device *vdev, |
| 448 | struct v4l2_subdev *sd, struct v4l2_streamparm *a); |
| 449 | |
Akinobu Mita | 85de5e0 | 2018-10-20 10:26:25 -0400 | [diff] [blame] | 450 | /* Compare two v4l2_fract structs */ |
| 451 | #define V4L2_FRACT_COMPARE(a, OP, b) \ |
| 452 | ((u64)(a).numerator * (b).denominator OP \ |
| 453 | (u64)(b).numerator * (a).denominator) |
| 454 | |
Ezequiel Garcia | f44b969 | 2019-03-28 14:07:04 -0400 | [diff] [blame] | 455 | /* ------------------------------------------------------------------------- */ |
| 456 | |
| 457 | /* Pixel format and FourCC helpers */ |
| 458 | |
| 459 | /** |
Benoit Parrot | d5a897c | 2019-10-07 12:10:07 -0300 | [diff] [blame^] | 460 | * enum v4l2_pixel_encoding - specifies the pixel encoding value |
| 461 | * |
| 462 | * @V4L2_PIXEL_ENC_UNKNOWN: Pixel encoding is unknown/un-initialized |
| 463 | * @V4L2_PIXEL_ENC_YUV: Pixel encoding is YUV |
| 464 | * @V4L2_PIXEL_ENC_RGB: Pixel encoding is RGB |
| 465 | * @V4L2_PIXEL_ENC_BAYER: Pixel encoding is Bayer |
| 466 | */ |
| 467 | enum v4l2_pixel_encoding { |
| 468 | V4L2_PIXEL_ENC_UNKNOWN = 0, |
| 469 | V4L2_PIXEL_ENC_YUV = 1, |
| 470 | V4L2_PIXEL_ENC_RGB = 2, |
| 471 | V4L2_PIXEL_ENC_BAYER = 3, |
| 472 | }; |
| 473 | |
| 474 | /** |
Ezequiel Garcia | f44b969 | 2019-03-28 14:07:04 -0400 | [diff] [blame] | 475 | * struct v4l2_format_info - information about a V4L2 format |
| 476 | * @format: 4CC format identifier (V4L2_PIX_FMT_*) |
Benoit Parrot | d5a897c | 2019-10-07 12:10:07 -0300 | [diff] [blame^] | 477 | * @pixel_enc: Pixel encoding (see enum v4l2_pixel_encoding above) |
Ezequiel Garcia | f44b969 | 2019-03-28 14:07:04 -0400 | [diff] [blame] | 478 | * @mem_planes: Number of memory planes, which includes the alpha plane (1 to 4). |
| 479 | * @comp_planes: Number of component planes, which includes the alpha plane (1 to 4). |
| 480 | * @bpp: Array of per-plane bytes per pixel |
| 481 | * @hdiv: Horizontal chroma subsampling factor |
| 482 | * @vdiv: Vertical chroma subsampling factor |
| 483 | * @block_w: Per-plane macroblock pixel width (optional) |
| 484 | * @block_h: Per-plane macroblock pixel height (optional) |
| 485 | */ |
| 486 | struct v4l2_format_info { |
| 487 | u32 format; |
Benoit Parrot | d5a897c | 2019-10-07 12:10:07 -0300 | [diff] [blame^] | 488 | u8 pixel_enc; |
Ezequiel Garcia | f44b969 | 2019-03-28 14:07:04 -0400 | [diff] [blame] | 489 | u8 mem_planes; |
| 490 | u8 comp_planes; |
| 491 | u8 bpp[4]; |
| 492 | u8 hdiv; |
| 493 | u8 vdiv; |
| 494 | u8 block_w[4]; |
| 495 | u8 block_h[4]; |
| 496 | }; |
| 497 | |
Benoit Parrot | d5a897c | 2019-10-07 12:10:07 -0300 | [diff] [blame^] | 498 | static inline bool v4l2_is_format_rgb(const struct v4l2_format_info *f) |
| 499 | { |
| 500 | return f && f->pixel_enc == V4L2_PIXEL_ENC_RGB; |
| 501 | } |
Ezequiel Garcia | f44b969 | 2019-03-28 14:07:04 -0400 | [diff] [blame] | 502 | |
Benoit Parrot | d5a897c | 2019-10-07 12:10:07 -0300 | [diff] [blame^] | 503 | static inline bool v4l2_is_format_yuv(const struct v4l2_format_info *f) |
| 504 | { |
| 505 | return f && f->pixel_enc == V4L2_PIXEL_ENC_YUV; |
| 506 | } |
| 507 | |
| 508 | static inline bool v4l2_is_format_bayer(const struct v4l2_format_info *f) |
| 509 | { |
| 510 | return f && f->pixel_enc == V4L2_PIXEL_ENC_BAYER; |
| 511 | } |
| 512 | |
| 513 | const struct v4l2_format_info *v4l2_format_info(u32 format); |
Boris Brezillon | 32cddf9 | 2019-05-28 13:02:18 -0400 | [diff] [blame] | 514 | void v4l2_apply_frmsize_constraints(u32 *width, u32 *height, |
| 515 | const struct v4l2_frmsize_stepwise *frmsize); |
Boris Brezillon | ce57a82 | 2019-05-28 13:02:17 -0400 | [diff] [blame] | 516 | int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, |
| 517 | u32 width, u32 height); |
| 518 | int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelformat, |
| 519 | u32 width, u32 height); |
Ezequiel Garcia | f44b969 | 2019-03-28 14:07:04 -0400 | [diff] [blame] | 520 | |
Hans Verkuil | b2f0648 | 2005-11-13 16:07:55 -0800 | [diff] [blame] | 521 | #endif /* V4L2_COMMON_H_ */ |