v4l2-int-device.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 <media/v4l2-common.h>
  27. #define V4L2NAMESIZE 32
  28. /*
  29. *
  30. * The internal V4L2 device interface core.
  31. *
  32. */
  33. enum v4l2_int_type {
  34. v4l2_int_type_master = 1,
  35. v4l2_int_type_slave
  36. };
  37. struct module;
  38. struct v4l2_int_device;
  39. struct v4l2_int_master {
  40. int (*attach)(struct v4l2_int_device *slave);
  41. void (*detach)(struct v4l2_int_device *slave);
  42. };
  43. typedef int (v4l2_int_ioctl_func)(struct v4l2_int_device *);
  44. typedef int (v4l2_int_ioctl_func_0)(struct v4l2_int_device *);
  45. typedef int (v4l2_int_ioctl_func_1)(struct v4l2_int_device *, void *);
  46. struct v4l2_int_ioctl_desc {
  47. int num;
  48. v4l2_int_ioctl_func *func;
  49. };
  50. struct v4l2_int_slave {
  51. /* Don't touch master. */
  52. struct v4l2_int_device *master;
  53. char attach_to[V4L2NAMESIZE];
  54. int num_ioctls;
  55. struct v4l2_int_ioctl_desc *ioctls;
  56. };
  57. struct v4l2_int_device {
  58. /* Don't touch head. */
  59. struct list_head head;
  60. struct module *module;
  61. char name[V4L2NAMESIZE];
  62. enum v4l2_int_type type;
  63. union {
  64. struct v4l2_int_master *master;
  65. struct v4l2_int_slave *slave;
  66. } u;
  67. void *priv;
  68. };
  69. void v4l2_int_device_try_attach_all(void);
  70. int v4l2_int_device_register(struct v4l2_int_device *d);
  71. void v4l2_int_device_unregister(struct v4l2_int_device *d);
  72. int v4l2_int_ioctl_0(struct v4l2_int_device *d, int cmd);
  73. int v4l2_int_ioctl_1(struct v4l2_int_device *d, int cmd, void *arg);
  74. /*
  75. *
  76. * Types and definitions for IOCTL commands.
  77. *
  78. */
  79. enum v4l2_power {
  80. V4L2_POWER_OFF = 0,
  81. V4L2_POWER_ON,
  82. V4L2_POWER_STANDBY,
  83. };
  84. /* Slave interface type. */
  85. enum v4l2_if_type {
  86. /*
  87. * Parallel 8-, 10- or 12-bit interface, used by for example
  88. * on certain image sensors.
  89. */
  90. V4L2_IF_TYPE_BT656,
  91. };
  92. enum v4l2_if_type_bt656_mode {
  93. /*
  94. * Modes without Bt synchronisation codes. Separate
  95. * synchronisation signal lines are used.
  96. */
  97. V4L2_IF_TYPE_BT656_MODE_NOBT_8BIT,
  98. V4L2_IF_TYPE_BT656_MODE_NOBT_10BIT,
  99. V4L2_IF_TYPE_BT656_MODE_NOBT_12BIT,
  100. /*
  101. * Use Bt synchronisation codes. The vertical and horizontal
  102. * synchronisation is done based on synchronisation codes.
  103. */
  104. V4L2_IF_TYPE_BT656_MODE_BT_8BIT,
  105. V4L2_IF_TYPE_BT656_MODE_BT_10BIT,
  106. };
  107. struct v4l2_if_type_bt656 {
  108. /*
  109. * 0: Frame begins when vsync is high.
  110. * 1: Frame begins when vsync changes from low to high.
  111. */
  112. unsigned frame_start_on_rising_vs:1;
  113. /* Use Bt synchronisation codes for sync correction. */
  114. unsigned bt_sync_correct:1;
  115. /* Swap every two adjacent image data elements. */
  116. unsigned swap:1;
  117. /* Inverted latch clock polarity from slave. */
  118. unsigned latch_clk_inv:1;
  119. /* Hs polarity. 0 is active high, 1 active low. */
  120. unsigned nobt_hs_inv:1;
  121. /* Vs polarity. 0 is active high, 1 active low. */
  122. unsigned nobt_vs_inv:1;
  123. enum v4l2_if_type_bt656_mode mode;
  124. /* Minimum accepted bus clock for slave (in Hz). */
  125. u32 clock_min;
  126. /* Maximum accepted bus clock for slave. */
  127. u32 clock_max;
  128. /*
  129. * Current wish of the slave. May only change in response to
  130. * ioctls that affect image capture.
  131. */
  132. u32 clock_curr;
  133. };
  134. struct v4l2_ifparm {
  135. enum v4l2_if_type if_type;
  136. union {
  137. struct v4l2_if_type_bt656 bt656;
  138. } u;
  139. };
  140. /* IOCTL command numbers. */
  141. enum v4l2_int_ioctl_num {
  142. /*
  143. *
  144. * "Proper" V4L ioctls, as in struct video_device.
  145. *
  146. */
  147. vidioc_int_enum_fmt_cap_num = 1,
  148. vidioc_int_g_fmt_cap_num,
  149. vidioc_int_s_fmt_cap_num,
  150. vidioc_int_try_fmt_cap_num,
  151. vidioc_int_queryctrl_num,
  152. vidioc_int_g_ctrl_num,
  153. vidioc_int_s_ctrl_num,
  154. vidioc_int_cropcap_num,
  155. vidioc_int_g_crop_num,
  156. vidioc_int_s_crop_num,
  157. vidioc_int_g_parm_num,
  158. vidioc_int_s_parm_num,
  159. vidioc_int_querystd_num,
  160. vidioc_int_s_std_num,
  161. vidioc_int_s_video_routing_num,
  162. /*
  163. *
  164. * Strictly internal ioctls.
  165. *
  166. */
  167. /* Initialise the device when slave attaches to the master. */
  168. vidioc_int_dev_init_num = 1000,
  169. /* Delinitialise the device at slave detach. */
  170. vidioc_int_dev_exit_num,
  171. /* Set device power state. */
  172. vidioc_int_s_power_num,
  173. /*
  174. * Get slave private data, e.g. platform-specific slave
  175. * configuration used by the master.
  176. */
  177. vidioc_int_g_priv_num,
  178. /* Get slave interface parameters. */
  179. vidioc_int_g_ifparm_num,
  180. /* Does the slave need to be reset after VIDIOC_DQBUF? */
  181. vidioc_int_g_needs_reset_num,
  182. vidioc_int_enum_framesizes_num,
  183. vidioc_int_enum_frameintervals_num,
  184. /*
  185. *
  186. * VIDIOC_INT_* ioctls.
  187. *
  188. */
  189. /* VIDIOC_INT_RESET */
  190. vidioc_int_reset_num,
  191. /* VIDIOC_INT_INIT */
  192. vidioc_int_init_num,
  193. /* VIDIOC_DBG_G_CHIP_IDENT */
  194. vidioc_int_g_chip_ident_num,
  195. /*
  196. *
  197. * Start of private ioctls.
  198. *
  199. */
  200. vidioc_int_priv_start_num = 2000,
  201. };
  202. /*
  203. *
  204. * IOCTL wrapper functions for better type checking.
  205. *
  206. */
  207. #define V4L2_INT_WRAPPER_0(name) \
  208. static inline int vidioc_int_##name(struct v4l2_int_device *d) \
  209. { \
  210. return v4l2_int_ioctl_0(d, vidioc_int_##name##_num); \
  211. } \
  212. \
  213. static inline struct v4l2_int_ioctl_desc \
  214. vidioc_int_##name##_cb(int (*func) \
  215. (struct v4l2_int_device *)) \
  216. { \
  217. struct v4l2_int_ioctl_desc desc; \
  218. \
  219. desc.num = vidioc_int_##name##_num; \
  220. desc.func = (v4l2_int_ioctl_func *)func; \
  221. \
  222. return desc; \
  223. }
  224. #define V4L2_INT_WRAPPER_1(name, arg_type, asterisk) \
  225. static inline int vidioc_int_##name(struct v4l2_int_device *d, \
  226. arg_type asterisk arg) \
  227. { \
  228. return v4l2_int_ioctl_1(d, vidioc_int_##name##_num, \
  229. (void *)(unsigned long)arg); \
  230. } \
  231. \
  232. static inline struct v4l2_int_ioctl_desc \
  233. vidioc_int_##name##_cb(int (*func) \
  234. (struct v4l2_int_device *, \
  235. arg_type asterisk)) \
  236. { \
  237. struct v4l2_int_ioctl_desc desc; \
  238. \
  239. desc.num = vidioc_int_##name##_num; \
  240. desc.func = (v4l2_int_ioctl_func *)func; \
  241. \
  242. return desc; \
  243. }
  244. V4L2_INT_WRAPPER_1(enum_fmt_cap, struct v4l2_fmtdesc, *);
  245. V4L2_INT_WRAPPER_1(g_fmt_cap, struct v4l2_format, *);
  246. V4L2_INT_WRAPPER_1(s_fmt_cap, struct v4l2_format, *);
  247. V4L2_INT_WRAPPER_1(try_fmt_cap, struct v4l2_format, *);
  248. V4L2_INT_WRAPPER_1(queryctrl, struct v4l2_queryctrl, *);
  249. V4L2_INT_WRAPPER_1(g_ctrl, struct v4l2_control, *);
  250. V4L2_INT_WRAPPER_1(s_ctrl, struct v4l2_control, *);
  251. V4L2_INT_WRAPPER_1(cropcap, struct v4l2_cropcap, *);
  252. V4L2_INT_WRAPPER_1(g_crop, struct v4l2_crop, *);
  253. V4L2_INT_WRAPPER_1(s_crop, struct v4l2_crop, *);
  254. V4L2_INT_WRAPPER_1(g_parm, struct v4l2_streamparm, *);
  255. V4L2_INT_WRAPPER_1(s_parm, struct v4l2_streamparm, *);
  256. V4L2_INT_WRAPPER_1(querystd, v4l2_std_id, *);
  257. V4L2_INT_WRAPPER_1(s_std, v4l2_std_id, *);
  258. V4L2_INT_WRAPPER_1(s_video_routing, struct v4l2_routing, *);
  259. V4L2_INT_WRAPPER_0(dev_init);
  260. V4L2_INT_WRAPPER_0(dev_exit);
  261. V4L2_INT_WRAPPER_1(s_power, enum v4l2_power, );
  262. V4L2_INT_WRAPPER_1(g_priv, void, *);
  263. V4L2_INT_WRAPPER_1(g_ifparm, struct v4l2_ifparm, *);
  264. V4L2_INT_WRAPPER_1(g_needs_reset, void, *);
  265. V4L2_INT_WRAPPER_1(enum_framesizes, struct v4l2_frmsizeenum, *);
  266. V4L2_INT_WRAPPER_1(enum_frameintervals, struct v4l2_frmivalenum, *);
  267. V4L2_INT_WRAPPER_0(reset);
  268. V4L2_INT_WRAPPER_0(init);
  269. V4L2_INT_WRAPPER_1(g_chip_ident, int, *);
  270. #endif