v4l2-common.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. /* Control helper function */
  63. int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def);
  64. /* ------------------------------------------------------------------------- */
  65. /* I2C Helper functions */
  66. struct i2c_driver;
  67. struct i2c_adapter;
  68. struct i2c_client;
  69. struct i2c_device_id;
  70. struct v4l2_device;
  71. struct v4l2_subdev;
  72. struct v4l2_subdev_ops;
  73. /* Load an i2c module and return an initialized v4l2_subdev struct.
  74. The client_type argument is the name of the chip that's on the adapter. */
  75. struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
  76. struct i2c_adapter *adapter, const char *client_type,
  77. u8 addr, const unsigned short *probe_addrs);
  78. struct i2c_board_info;
  79. struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
  80. struct i2c_adapter *adapter, struct i2c_board_info *info,
  81. const unsigned short *probe_addrs);
  82. /* Initialize a v4l2_subdev with data from an i2c_client struct */
  83. void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
  84. const struct v4l2_subdev_ops *ops);
  85. /* Return i2c client address of v4l2_subdev. */
  86. unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd);
  87. enum v4l2_i2c_tuner_type {
  88. ADDRS_RADIO, /* Radio tuner addresses */
  89. ADDRS_DEMOD, /* Demod tuner addresses */
  90. ADDRS_TV, /* TV tuner addresses */
  91. /* TV tuner addresses if demod is present, this excludes
  92. addresses used by the demodulator from the list of
  93. candidates. */
  94. ADDRS_TV_WITH_DEMOD,
  95. };
  96. /* Return a list of I2C tuner addresses to probe. Use only if the tuner
  97. addresses are unknown. */
  98. const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type);
  99. /* ------------------------------------------------------------------------- */
  100. /* SPI Helper functions */
  101. #if defined(CONFIG_SPI)
  102. #include <linux/spi/spi.h>
  103. struct spi_device;
  104. /* Load an spi module and return an initialized v4l2_subdev struct.
  105. The client_type argument is the name of the chip that's on the adapter. */
  106. struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
  107. struct spi_master *master, struct spi_board_info *info);
  108. /* Initialize a v4l2_subdev with data from an spi_device struct */
  109. void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
  110. const struct v4l2_subdev_ops *ops);
  111. #endif
  112. /* ------------------------------------------------------------------------- */
  113. /* Note: these remaining ioctls/structs should be removed as well, but they are
  114. still used in tuner-simple.c (TUNER_SET_CONFIG), cx18/ivtv (RESET) and
  115. v4l2-int-device.h (v4l2_routing). To remove these ioctls some more cleanup
  116. is needed in those modules. */
  117. /* s_config */
  118. struct v4l2_priv_tun_config {
  119. int tuner;
  120. void *priv;
  121. };
  122. #define TUNER_SET_CONFIG _IOW('d', 92, struct v4l2_priv_tun_config)
  123. #define VIDIOC_INT_RESET _IOW ('d', 102, u32)
  124. struct v4l2_routing {
  125. u32 input;
  126. u32 output;
  127. };
  128. /* ------------------------------------------------------------------------- */
  129. /* Miscellaneous helper functions */
  130. void v4l_bound_align_image(unsigned int *w, unsigned int wmin,
  131. unsigned int wmax, unsigned int walign,
  132. unsigned int *h, unsigned int hmin,
  133. unsigned int hmax, unsigned int halign,
  134. unsigned int salign);
  135. struct v4l2_discrete_probe {
  136. const struct v4l2_frmsize_discrete *sizes;
  137. int num_sizes;
  138. };
  139. const struct v4l2_frmsize_discrete *v4l2_find_nearest_format(
  140. const struct v4l2_discrete_probe *probe,
  141. s32 width, s32 height);
  142. void v4l2_get_timestamp(struct timeval *tv);
  143. #endif /* V4L2_COMMON_H_ */