v4l2-common.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. /* ------------------------------------------------------------------------- */
  45. /* These printk constructs can be used with v4l2_device and v4l2_subdev */
  46. #define v4l2_printk(level, dev, fmt, arg...) \
  47. printk(level "%s: " fmt, (dev)->name , ## arg)
  48. #define v4l2_err(dev, fmt, arg...) \
  49. v4l2_printk(KERN_ERR, dev, fmt , ## arg)
  50. #define v4l2_warn(dev, fmt, arg...) \
  51. v4l2_printk(KERN_WARNING, dev, fmt , ## arg)
  52. #define v4l2_info(dev, fmt, arg...) \
  53. v4l2_printk(KERN_INFO, dev, fmt , ## arg)
  54. /* These three macros assume that the debug level is set with a module
  55. parameter called 'debug'. */
  56. #define v4l2_dbg(level, debug, dev, fmt, arg...) \
  57. do { \
  58. if (debug >= (level)) \
  59. v4l2_printk(KERN_DEBUG, dev, fmt , ## arg); \
  60. } while (0)
  61. /**
  62. * v4l2_ctrl_query_fill- Fill in a struct v4l2_queryctrl
  63. *
  64. * @qctrl: pointer to the &struct v4l2_queryctrl to be filled
  65. * @min: minimum value for the control
  66. * @max: maximum value for the control
  67. * @step: control step
  68. * @def: default value for the control
  69. *
  70. * Fills the &struct v4l2_queryctrl fields for the query control.
  71. *
  72. * .. note::
  73. *
  74. * This function assumes that the @qctrl->id field is filled.
  75. *
  76. * Returns -EINVAL if the control is not known by the V4L2 core, 0 on success.
  77. */
  78. int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
  79. s32 min, s32 max, s32 step, s32 def);
  80. /* ------------------------------------------------------------------------- */
  81. /* I2C Helper functions */
  82. struct i2c_driver;
  83. struct i2c_adapter;
  84. struct i2c_client;
  85. struct i2c_device_id;
  86. struct v4l2_device;
  87. struct v4l2_subdev;
  88. struct v4l2_subdev_ops;
  89. /**
  90. * v4l2_i2c_new_subdev - Load an i2c module and return an initialized
  91. * &struct v4l2_subdev.
  92. *
  93. * @v4l2_dev: pointer to &struct v4l2_device
  94. * @adapter: pointer to struct i2c_adapter
  95. * @client_type: name of the chip that's on the adapter.
  96. * @addr: I2C address. If zero, it will use @probe_addrs
  97. * @probe_addrs: array with a list of address. The last entry at such
  98. * array should be %I2C_CLIENT_END.
  99. *
  100. * returns a &struct v4l2_subdev pointer.
  101. */
  102. struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
  103. struct i2c_adapter *adapter, const char *client_type,
  104. u8 addr, const unsigned short *probe_addrs);
  105. struct i2c_board_info;
  106. /**
  107. * v4l2_i2c_new_subdev_board - Load an i2c module and return an initialized
  108. * &struct v4l2_subdev.
  109. *
  110. * @v4l2_dev: pointer to &struct v4l2_device
  111. * @adapter: pointer to struct i2c_adapter
  112. * @info: pointer to struct i2c_board_info used to replace the irq,
  113. * platform_data and addr arguments.
  114. * @probe_addrs: array with a list of address. The last entry at such
  115. * array should be %I2C_CLIENT_END.
  116. *
  117. * returns a &struct v4l2_subdev pointer.
  118. */
  119. struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
  120. struct i2c_adapter *adapter, struct i2c_board_info *info,
  121. const unsigned short *probe_addrs);
  122. /**
  123. * v4l2_i2c_subdev_init - Initializes a &struct v4l2_subdev with data from
  124. * an i2c_client struct.
  125. *
  126. * @sd: pointer to &struct v4l2_subdev
  127. * @client: pointer to struct i2c_client
  128. * @ops: pointer to &struct v4l2_subdev_ops
  129. */
  130. void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
  131. const struct v4l2_subdev_ops *ops);
  132. /**
  133. * v4l2_i2c_subdev_addr - returns i2c client address of &struct v4l2_subdev.
  134. *
  135. * @sd: pointer to &struct v4l2_subdev
  136. *
  137. * Returns the address of an I2C sub-device
  138. */
  139. unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd);
  140. enum v4l2_i2c_tuner_type {
  141. ADDRS_RADIO, /* Radio tuner addresses */
  142. ADDRS_DEMOD, /* Demod tuner addresses */
  143. ADDRS_TV, /* TV tuner addresses */
  144. /* TV tuner addresses if demod is present, this excludes
  145. addresses used by the demodulator from the list of
  146. candidates. */
  147. ADDRS_TV_WITH_DEMOD,
  148. };
  149. /* Return a list of I2C tuner addresses to probe. Use only if the tuner
  150. addresses are unknown. */
  151. const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type);
  152. /* ------------------------------------------------------------------------- */
  153. /* SPI Helper functions */
  154. #if defined(CONFIG_SPI)
  155. #include <linux/spi/spi.h>
  156. struct spi_device;
  157. /**
  158. * v4l2_spi_new_subdev - Load an spi module and return an initialized
  159. * &struct v4l2_subdev.
  160. *
  161. *
  162. * @v4l2_dev: pointer to &struct v4l2_device.
  163. * @master: pointer to struct spi_master.
  164. * @info: pointer to struct spi_board_info.
  165. *
  166. * returns a &struct v4l2_subdev pointer.
  167. */
  168. struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
  169. struct spi_master *master, struct spi_board_info *info);
  170. /**
  171. * v4l2_spi_subdev_init - Initialize a v4l2_subdev with data from an
  172. * spi_device struct.
  173. *
  174. * @sd: pointer to &struct v4l2_subdev
  175. * @spi: pointer to struct spi_device.
  176. * @ops: pointer to &struct v4l2_subdev_ops
  177. */
  178. void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
  179. const struct v4l2_subdev_ops *ops);
  180. #endif
  181. /* ------------------------------------------------------------------------- */
  182. /* Note: these remaining ioctls/structs should be removed as well, but they are
  183. still used in tuner-simple.c (TUNER_SET_CONFIG), cx18/ivtv (RESET) and
  184. v4l2-int-device.h (v4l2_routing). To remove these ioctls some more cleanup
  185. is needed in those modules. */
  186. /* s_config */
  187. struct v4l2_priv_tun_config {
  188. int tuner;
  189. void *priv;
  190. };
  191. #define TUNER_SET_CONFIG _IOW('d', 92, struct v4l2_priv_tun_config)
  192. #define VIDIOC_INT_RESET _IOW ('d', 102, u32)
  193. struct v4l2_routing {
  194. u32 input;
  195. u32 output;
  196. };
  197. /* ------------------------------------------------------------------------- */
  198. /* Miscellaneous helper functions */
  199. void v4l_bound_align_image(unsigned int *w, unsigned int wmin,
  200. unsigned int wmax, unsigned int walign,
  201. unsigned int *h, unsigned int hmin,
  202. unsigned int hmax, unsigned int halign,
  203. unsigned int salign);
  204. struct v4l2_discrete_probe {
  205. const struct v4l2_frmsize_discrete *sizes;
  206. int num_sizes;
  207. };
  208. const struct v4l2_frmsize_discrete *v4l2_find_nearest_format(
  209. const struct v4l2_discrete_probe *probe,
  210. s32 width, s32 height);
  211. void v4l2_get_timestamp(struct timeval *tv);
  212. #endif /* V4L2_COMMON_H_ */