v4l2-int-device.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * include/media/v4l2-int-device.h
  3. *
  4. * V4L2 internal ioctl interface.
  5. *
  6. * Copyright (C) 2007 Nokia Corporation.
  7. *
  8. * Contact: Sakari Ailus <sakari.ailus@nokia.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * version 2 as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  22. * 02110-1301 USA
  23. */
  24. #ifndef V4L2_INT_DEVICE_H
  25. #define V4L2_INT_DEVICE_H
  26. #include <linux/module.h>
  27. #include <media/v4l2-common.h>
  28. #define V4L2NAMESIZE 32
  29. enum v4l2_int_type {
  30. v4l2_int_type_master = 1,
  31. v4l2_int_type_slave
  32. };
  33. enum v4l2_int_ioctl_num {
  34. /*
  35. *
  36. * "Proper" V4L ioctls, as in struct video_device.
  37. *
  38. */
  39. vidioc_int_enum_fmt_cap_num = 1,
  40. vidioc_int_g_fmt_cap_num,
  41. vidioc_int_s_fmt_cap_num,
  42. vidioc_int_try_fmt_cap_num,
  43. vidioc_int_queryctrl_num,
  44. vidioc_int_g_ctrl_num,
  45. vidioc_int_s_ctrl_num,
  46. vidioc_int_g_parm_num,
  47. vidioc_int_s_parm_num,
  48. /*
  49. *
  50. * Strictly internal ioctls.
  51. *
  52. */
  53. /* Initialise the device when slave attaches to the master. */
  54. vidioc_int_dev_init_num = 1000,
  55. /* Delinitialise the device at slave detach. */
  56. vidioc_int_dev_exit_num,
  57. /* Set device power state: 0 is off, non-zero is on. */
  58. vidioc_int_s_power_num,
  59. /* Get parallel interface clock speed for current settings. */
  60. vidioc_int_g_ext_clk_num,
  61. /*
  62. * Tell what the parallel interface clock speed actually is.
  63. */
  64. vidioc_int_s_ext_clk_num,
  65. /* Does the slave need to be reset after VIDIOC_DQBUF? */
  66. vidioc_int_g_needs_reset_num,
  67. /*
  68. *
  69. * VIDIOC_INT_* ioctls.
  70. *
  71. */
  72. /* VIDIOC_INT_RESET */
  73. vidioc_int_reset_num,
  74. /* VIDIOC_INT_INIT */
  75. vidioc_int_init_num,
  76. /* VIDIOC_INT_G_CHIP_IDENT */
  77. vidioc_int_g_chip_ident_num,
  78. /*
  79. *
  80. * Start of private ioctls.
  81. *
  82. */
  83. vidioc_int_priv_start_num = 2000,
  84. };
  85. struct v4l2_int_device;
  86. struct v4l2_int_master {
  87. int (*attach)(struct v4l2_int_device *master,
  88. struct v4l2_int_device *slave);
  89. void (*detach)(struct v4l2_int_device *master);
  90. };
  91. typedef int (v4l2_int_ioctl_func)(struct v4l2_int_device *);
  92. typedef int (v4l2_int_ioctl_func_0)(struct v4l2_int_device *);
  93. typedef int (v4l2_int_ioctl_func_1)(struct v4l2_int_device *, void *);
  94. struct v4l2_int_ioctl_desc {
  95. int num;
  96. v4l2_int_ioctl_func *func;
  97. };
  98. struct v4l2_int_slave {
  99. /* Don't touch master. */
  100. struct v4l2_int_device *master;
  101. char attach_to[V4L2NAMESIZE];
  102. int num_ioctls;
  103. struct v4l2_int_ioctl_desc *ioctls;
  104. };
  105. struct v4l2_int_device {
  106. /* Don't touch head. */
  107. struct list_head head;
  108. struct module *module;
  109. char name[V4L2NAMESIZE];
  110. enum v4l2_int_type type;
  111. union {
  112. struct v4l2_int_master *master;
  113. struct v4l2_int_slave *slave;
  114. } u;
  115. void *priv;
  116. };
  117. int v4l2_int_device_register(struct v4l2_int_device *d);
  118. void v4l2_int_device_unregister(struct v4l2_int_device *d);
  119. int v4l2_int_ioctl_0(struct v4l2_int_device *d, int cmd);
  120. int v4l2_int_ioctl_1(struct v4l2_int_device *d, int cmd, void *arg);
  121. /*
  122. *
  123. * IOCTL wrapper functions for better type checking.
  124. *
  125. */
  126. #define V4L2_INT_WRAPPER_0(name) \
  127. static inline int vidioc_int_##name(struct v4l2_int_device *d) \
  128. { \
  129. return v4l2_int_ioctl_0(d, vidioc_int_##name##_num); \
  130. } \
  131. \
  132. static inline struct v4l2_int_ioctl_desc \
  133. vidioc_int_##name##_cb(int (*func) \
  134. (struct v4l2_int_device *)) \
  135. { \
  136. struct v4l2_int_ioctl_desc desc; \
  137. \
  138. desc.num = vidioc_int_##name##_num; \
  139. desc.func = (v4l2_int_ioctl_func *)func; \
  140. \
  141. return desc; \
  142. }
  143. #define V4L2_INT_WRAPPER_1(name, arg_type, asterisk) \
  144. static inline int vidioc_int_##name(struct v4l2_int_device *d, \
  145. arg_type asterisk arg) \
  146. { \
  147. return v4l2_int_ioctl_1(d, vidioc_int_##name##_num, \
  148. (void *)arg); \
  149. } \
  150. \
  151. static inline struct v4l2_int_ioctl_desc \
  152. vidioc_int_##name##_cb(int (*func) \
  153. (struct v4l2_int_device *, \
  154. arg_type asterisk)) \
  155. { \
  156. struct v4l2_int_ioctl_desc desc; \
  157. \
  158. desc.num = vidioc_int_##name##_num; \
  159. desc.func = (v4l2_int_ioctl_func *)func; \
  160. \
  161. return desc; \
  162. }
  163. V4L2_INT_WRAPPER_1(enum_fmt_cap, struct v4l2_fmtdesc, *);
  164. V4L2_INT_WRAPPER_1(g_fmt_cap, struct v4l2_format, *);
  165. V4L2_INT_WRAPPER_1(s_fmt_cap, struct v4l2_format, *);
  166. V4L2_INT_WRAPPER_1(try_fmt_cap, struct v4l2_format, *);
  167. V4L2_INT_WRAPPER_1(queryctrl, struct v4l2_queryctrl, *);
  168. V4L2_INT_WRAPPER_1(g_ctrl, struct v4l2_control, *);
  169. V4L2_INT_WRAPPER_1(s_ctrl, struct v4l2_control, *);
  170. V4L2_INT_WRAPPER_1(g_parm, struct v4l2_streamparm, *);
  171. V4L2_INT_WRAPPER_1(s_parm, struct v4l2_streamparm, *);
  172. V4L2_INT_WRAPPER_0(dev_init);
  173. V4L2_INT_WRAPPER_0(dev_exit);
  174. V4L2_INT_WRAPPER_1(s_power, int, );
  175. V4L2_INT_WRAPPER_1(s_ext_clk, u32, );
  176. V4L2_INT_WRAPPER_1(g_ext_clk, u32, *);
  177. V4L2_INT_WRAPPER_1(g_needs_reset, void, *);
  178. V4L2_INT_WRAPPER_0(reset);
  179. V4L2_INT_WRAPPER_0(init);
  180. V4L2_INT_WRAPPER_1(g_chip_ident, int, *);
  181. #endif