v4l2-common.h 13 KB

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