v4l2-common.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 constucts 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. enum v4l2_i2c_tuner_type {
  147. ADDRS_RADIO, /* Radio tuner addresses */
  148. ADDRS_DEMOD, /* Demod tuner addresses */
  149. ADDRS_TV, /* TV tuner addresses */
  150. /* TV tuner addresses if demod is present, this excludes
  151. addresses used by the demodulator from the list of
  152. candidates. */
  153. ADDRS_TV_WITH_DEMOD,
  154. };
  155. /* Return a list of I2C tuner addresses to probe. Use only if the tuner
  156. addresses are unknown. */
  157. const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type);
  158. /* ------------------------------------------------------------------------- */
  159. /* SPI Helper functions */
  160. #if defined(CONFIG_SPI)
  161. #include <linux/spi/spi.h>
  162. struct spi_device;
  163. /**
  164. * v4l2_spi_new_subdev - Load an spi module and return an initialized
  165. * &struct v4l2_subdev.
  166. *
  167. *
  168. * @v4l2_dev: pointer to &struct v4l2_device.
  169. * @master: pointer to struct spi_master.
  170. * @info: pointer to struct spi_board_info.
  171. *
  172. * returns a &struct v4l2_subdev pointer.
  173. */
  174. struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
  175. struct spi_master *master, struct spi_board_info *info);
  176. /**
  177. * v4l2_spi_subdev_init - Initialize a v4l2_subdev with data from an
  178. * spi_device struct.
  179. *
  180. * @sd: pointer to &struct v4l2_subdev
  181. * @spi: pointer to struct spi_device.
  182. * @ops: pointer to &struct v4l2_subdev_ops
  183. */
  184. void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
  185. const struct v4l2_subdev_ops *ops);
  186. #endif
  187. /* ------------------------------------------------------------------------- */
  188. /* Note: these remaining ioctls/structs should be removed as well, but they are
  189. still used in tuner-simple.c (TUNER_SET_CONFIG), cx18/ivtv (RESET) and
  190. v4l2-int-device.h (v4l2_routing). To remove these ioctls some more cleanup
  191. is needed in those modules. */
  192. /* s_config */
  193. struct v4l2_priv_tun_config {
  194. int tuner;
  195. void *priv;
  196. };
  197. #define TUNER_SET_CONFIG _IOW('d', 92, struct v4l2_priv_tun_config)
  198. #define VIDIOC_INT_RESET _IOW ('d', 102, u32)
  199. struct v4l2_routing {
  200. u32 input;
  201. u32 output;
  202. };
  203. /* ------------------------------------------------------------------------- */
  204. /* Miscellaneous helper functions */
  205. void v4l_bound_align_image(unsigned int *w, unsigned int wmin,
  206. unsigned int wmax, unsigned int walign,
  207. unsigned int *h, unsigned int hmin,
  208. unsigned int hmax, unsigned int halign,
  209. unsigned int salign);
  210. struct v4l2_discrete_probe {
  211. const struct v4l2_frmsize_discrete *sizes;
  212. int num_sizes;
  213. };
  214. const struct v4l2_frmsize_discrete *v4l2_find_nearest_format(
  215. const struct v4l2_discrete_probe *probe,
  216. s32 width, s32 height);
  217. void v4l2_get_timestamp(struct timeval *tv);
  218. #endif /* V4L2_COMMON_H_ */