v4l2-subdev.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. /*
  2. V4L2 sub-device support header.
  3. Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #ifndef _V4L2_SUBDEV_H
  17. #define _V4L2_SUBDEV_H
  18. #include <linux/types.h>
  19. #include <linux/v4l2-subdev.h>
  20. #include <media/media-entity.h>
  21. #include <media/v4l2-async.h>
  22. #include <media/v4l2-common.h>
  23. #include <media/v4l2-dev.h>
  24. #include <media/v4l2-fh.h>
  25. #include <media/v4l2-mediabus.h>
  26. /* generic v4l2_device notify callback notification values */
  27. #define V4L2_SUBDEV_IR_RX_NOTIFY _IOW('v', 0, u32)
  28. #define V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ 0x00000001
  29. #define V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED 0x00000002
  30. #define V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN 0x00000004
  31. #define V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN 0x00000008
  32. #define V4L2_SUBDEV_IR_TX_NOTIFY _IOW('v', 1, u32)
  33. #define V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ 0x00000001
  34. #define V4L2_DEVICE_NOTIFY_EVENT _IOW('v', 2, struct v4l2_event)
  35. struct v4l2_device;
  36. struct v4l2_ctrl_handler;
  37. struct v4l2_event;
  38. struct v4l2_event_subscription;
  39. struct v4l2_fh;
  40. struct v4l2_subdev;
  41. struct v4l2_subdev_fh;
  42. struct tuner_setup;
  43. struct v4l2_mbus_frame_desc;
  44. /* decode_vbi_line */
  45. struct v4l2_decode_vbi_line {
  46. u32 is_second_field; /* Set to 0 for the first (odd) field,
  47. set to 1 for the second (even) field. */
  48. u8 *p; /* Pointer to the sliced VBI data from the decoder.
  49. On exit points to the start of the payload. */
  50. u32 line; /* Line number of the sliced VBI data (1-23) */
  51. u32 type; /* VBI service type (V4L2_SLICED_*). 0 if no service found */
  52. };
  53. /* Sub-devices are devices that are connected somehow to the main bridge
  54. device. These devices are usually audio/video muxers/encoders/decoders or
  55. sensors and webcam controllers.
  56. Usually these devices are controlled through an i2c bus, but other busses
  57. may also be used.
  58. The v4l2_subdev struct provides a way of accessing these devices in a
  59. generic manner. Most operations that these sub-devices support fall in
  60. a few categories: core ops, audio ops, video ops and tuner ops.
  61. More categories can be added if needed, although this should remain a
  62. limited set (no more than approx. 8 categories).
  63. Each category has its own set of ops that subdev drivers can implement.
  64. A subdev driver can leave the pointer to the category ops NULL if
  65. it does not implement them (e.g. an audio subdev will generally not
  66. implement the video category ops). The exception is the core category:
  67. this must always be present.
  68. These ops are all used internally so it is no problem to change, remove
  69. or add ops or move ops from one to another category. Currently these
  70. ops are based on the original ioctls, but since ops are not limited to
  71. one argument there is room for improvement here once all i2c subdev
  72. drivers are converted to use these ops.
  73. */
  74. /* Core ops: it is highly recommended to implement at least these ops:
  75. log_status
  76. g_register
  77. s_register
  78. This provides basic debugging support.
  79. The ioctl ops is meant for generic ioctl-like commands. Depending on
  80. the use-case it might be better to use subdev-specific ops (currently
  81. not yet implemented) since ops provide proper type-checking.
  82. */
  83. /* Subdevice external IO pin configuration */
  84. #define V4L2_SUBDEV_IO_PIN_DISABLE (1 << 0) /* ENABLE assumed */
  85. #define V4L2_SUBDEV_IO_PIN_OUTPUT (1 << 1)
  86. #define V4L2_SUBDEV_IO_PIN_INPUT (1 << 2)
  87. #define V4L2_SUBDEV_IO_PIN_SET_VALUE (1 << 3) /* Set output value */
  88. #define V4L2_SUBDEV_IO_PIN_ACTIVE_LOW (1 << 4) /* ACTIVE HIGH assumed */
  89. struct v4l2_subdev_io_pin_config {
  90. u32 flags; /* V4L2_SUBDEV_IO_PIN_* flags for this pin's config */
  91. u8 pin; /* Chip external IO pin to configure */
  92. u8 function; /* Internal signal pad/function to route to IO pin */
  93. u8 value; /* Initial value for pin - e.g. GPIO output value */
  94. u8 strength; /* Pin drive strength */
  95. };
  96. /**
  97. * struct v4l2_subdev_core_ops - Define core ops callbacks for subdevs
  98. *
  99. * @log_status: callback for VIDIOC_LOG_STATUS ioctl handler code.
  100. *
  101. * @s_io_pin_config: configure one or more chip I/O pins for chips that
  102. * multiplex different internal signal pads out to IO pins. This function
  103. * takes a pointer to an array of 'n' pin configuration entries, one for
  104. * each pin being configured. This function could be called at times
  105. * other than just subdevice initialization.
  106. *
  107. * @init: initialize the sensor registers to some sort of reasonable default
  108. * values. Do not use for new drivers and should be removed in existing
  109. * drivers.
  110. *
  111. * @load_fw: load firmware.
  112. *
  113. * @reset: generic reset command. The argument selects which subsystems to
  114. * reset. Passing 0 will always reset the whole chip. Do not use for new
  115. * drivers without discussing this first on the linux-media mailinglist.
  116. * There should be no reason normally to reset a device.
  117. *
  118. * @s_gpio: set GPIO pins. Very simple right now, might need to be extended with
  119. * a direction argument if needed.
  120. *
  121. * @queryctrl: callback for VIDIOC_QUERYCTL ioctl handler code.
  122. *
  123. * @g_ctrl: callback for VIDIOC_G_CTRL ioctl handler code.
  124. *
  125. * @s_ctrl: callback for VIDIOC_S_CTRL ioctl handler code.
  126. *
  127. * @g_ext_ctrls: callback for VIDIOC_G_EXT_CTRLS ioctl handler code.
  128. *
  129. * @s_ext_ctrls: callback for VIDIOC_S_EXT_CTRLS ioctl handler code.
  130. *
  131. * @try_ext_ctrls: callback for VIDIOC_TRY_EXT_CTRLS ioctl handler code.
  132. *
  133. * @querymenu: callback for VIDIOC_QUERYMENU ioctl handler code.
  134. *
  135. * @ioctl: called at the end of ioctl() syscall handler at the V4L2 core.
  136. * used to provide support for private ioctls used on the driver.
  137. *
  138. * @compat_ioctl32: called when a 32 bits application uses a 64 bits Kernel,
  139. * in order to fix data passed from/to userspace.
  140. *
  141. * @g_register: callback for VIDIOC_G_REGISTER ioctl handler code.
  142. *
  143. * @s_register: callback for VIDIOC_G_REGISTER ioctl handler code.
  144. *
  145. * @s_power: puts subdevice in power saving mode (on == 0) or normal operation
  146. * mode (on == 1).
  147. *
  148. * @interrupt_service_routine: Called by the bridge chip's interrupt service
  149. * handler, when an interrupt status has be raised due to this subdev,
  150. * so that this subdev can handle the details. It may schedule work to be
  151. * performed later. It must not sleep. *Called from an IRQ context*.
  152. *
  153. * @subscribe_event: used by the drivers to request the control framework that
  154. * for it to be warned when the value of a control changes.
  155. *
  156. * @unsubscribe_event: remove event subscription from the control framework.
  157. */
  158. struct v4l2_subdev_core_ops {
  159. int (*log_status)(struct v4l2_subdev *sd);
  160. int (*s_io_pin_config)(struct v4l2_subdev *sd, size_t n,
  161. struct v4l2_subdev_io_pin_config *pincfg);
  162. int (*init)(struct v4l2_subdev *sd, u32 val);
  163. int (*load_fw)(struct v4l2_subdev *sd);
  164. int (*reset)(struct v4l2_subdev *sd, u32 val);
  165. int (*s_gpio)(struct v4l2_subdev *sd, u32 val);
  166. int (*queryctrl)(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc);
  167. int (*g_ctrl)(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
  168. int (*s_ctrl)(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
  169. int (*g_ext_ctrls)(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls);
  170. int (*s_ext_ctrls)(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls);
  171. int (*try_ext_ctrls)(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls);
  172. int (*querymenu)(struct v4l2_subdev *sd, struct v4l2_querymenu *qm);
  173. long (*ioctl)(struct v4l2_subdev *sd, unsigned int cmd, void *arg);
  174. #ifdef CONFIG_COMPAT
  175. long (*compat_ioctl32)(struct v4l2_subdev *sd, unsigned int cmd,
  176. unsigned long arg);
  177. #endif
  178. #ifdef CONFIG_VIDEO_ADV_DEBUG
  179. int (*g_register)(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg);
  180. int (*s_register)(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg);
  181. #endif
  182. int (*s_power)(struct v4l2_subdev *sd, int on);
  183. int (*interrupt_service_routine)(struct v4l2_subdev *sd,
  184. u32 status, bool *handled);
  185. int (*subscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  186. struct v4l2_event_subscription *sub);
  187. int (*unsubscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  188. struct v4l2_event_subscription *sub);
  189. };
  190. /**
  191. * struct s_radio - Callbacks used when v4l device was opened in radio mode.
  192. *
  193. * @s_radio: callback for VIDIOC_S_RADIO ioctl handler code.
  194. *
  195. * @s_frequency: callback for VIDIOC_S_FREQUENCY ioctl handler code.
  196. *
  197. * @g_frequency: callback for VIDIOC_G_FREQUENCY ioctl handler code.
  198. * freq->type must be filled in. Normally done by video_ioctl2
  199. * or the bridge driver.
  200. *
  201. * @enum_freq_bands: callback for VIDIOC_ENUM_FREQ_BANDS ioctl handler code.
  202. *
  203. * @g_tuner: callback for VIDIOC_G_TUNER ioctl handler code.
  204. *
  205. * @s_tuner: callback for VIDIOC_S_TUNER ioctl handler code. vt->type must be
  206. * filled in. Normally done by video_ioctl2 or the
  207. * bridge driver.
  208. *
  209. * @g_modulator: callback for VIDIOC_G_MODULATOR ioctl handler code.
  210. *
  211. * @s_modulator: callback for VIDIOC_S_MODULATOR ioctl handler code.
  212. *
  213. * @s_type_addr: sets tuner type and its I2C addr.
  214. *
  215. * @s_config: sets tda9887 specific stuff, like port1, port2 and qss
  216. */
  217. struct v4l2_subdev_tuner_ops {
  218. int (*s_radio)(struct v4l2_subdev *sd);
  219. int (*s_frequency)(struct v4l2_subdev *sd, const struct v4l2_frequency *freq);
  220. int (*g_frequency)(struct v4l2_subdev *sd, struct v4l2_frequency *freq);
  221. int (*enum_freq_bands)(struct v4l2_subdev *sd, struct v4l2_frequency_band *band);
  222. int (*g_tuner)(struct v4l2_subdev *sd, struct v4l2_tuner *vt);
  223. int (*s_tuner)(struct v4l2_subdev *sd, const struct v4l2_tuner *vt);
  224. int (*g_modulator)(struct v4l2_subdev *sd, struct v4l2_modulator *vm);
  225. int (*s_modulator)(struct v4l2_subdev *sd, const struct v4l2_modulator *vm);
  226. int (*s_type_addr)(struct v4l2_subdev *sd, struct tuner_setup *type);
  227. int (*s_config)(struct v4l2_subdev *sd, const struct v4l2_priv_tun_config *config);
  228. };
  229. /**
  230. * struct v4l2_subdev_audio_ops - Callbacks used for audio-related settings
  231. *
  232. * @s_clock_freq: set the frequency (in Hz) of the audio clock output.
  233. * Used to slave an audio processor to the video decoder, ensuring that
  234. * audio and video remain synchronized. Usual values for the frequency
  235. * are 48000, 44100 or 32000 Hz. If the frequency is not supported, then
  236. * -EINVAL is returned.
  237. *
  238. * @s_i2s_clock_freq: sets I2S speed in bps. This is used to provide a standard
  239. * way to select I2S clock used by driving digital audio streams at some
  240. * board designs. Usual values for the frequency are 1024000 and 2048000.
  241. * If the frequency is not supported, then -EINVAL is returned.
  242. *
  243. * @s_routing: used to define the input and/or output pins of an audio chip,
  244. * and any additional configuration data.
  245. * Never attempt to use user-level input IDs (e.g. Composite, S-Video,
  246. * Tuner) at this level. An i2c device shouldn't know about whether an
  247. * input pin is connected to a Composite connector, become on another
  248. * board or platform it might be connected to something else entirely.
  249. * The calling driver is responsible for mapping a user-level input to
  250. * the right pins on the i2c device.
  251. *
  252. * @s_stream: used to notify the audio code that stream will start or has
  253. * stopped.
  254. */
  255. struct v4l2_subdev_audio_ops {
  256. int (*s_clock_freq)(struct v4l2_subdev *sd, u32 freq);
  257. int (*s_i2s_clock_freq)(struct v4l2_subdev *sd, u32 freq);
  258. int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
  259. int (*s_stream)(struct v4l2_subdev *sd, int enable);
  260. };
  261. /* Indicates the @length field specifies maximum data length. */
  262. #define V4L2_MBUS_FRAME_DESC_FL_LEN_MAX (1U << 0)
  263. /*
  264. * Indicates that the format does not have line offsets, i.e. the
  265. * receiver should use 1D DMA.
  266. */
  267. #define V4L2_MBUS_FRAME_DESC_FL_BLOB (1U << 1)
  268. /**
  269. * struct v4l2_mbus_frame_desc_entry - media bus frame description structure
  270. *
  271. * @flags: V4L2_MBUS_FRAME_DESC_FL_* flags
  272. * @pixelcode: media bus pixel code, valid if FRAME_DESC_FL_BLOB is not set
  273. * @length: number of octets per frame, valid if V4L2_MBUS_FRAME_DESC_FL_BLOB
  274. * is set
  275. */
  276. struct v4l2_mbus_frame_desc_entry {
  277. u16 flags;
  278. u32 pixelcode;
  279. u32 length;
  280. };
  281. #define V4L2_FRAME_DESC_ENTRY_MAX 4
  282. /**
  283. * struct v4l2_mbus_frame_desc - media bus data frame description
  284. * @entry: frame descriptors array
  285. * @num_entries: number of entries in @entry array
  286. */
  287. struct v4l2_mbus_frame_desc {
  288. struct v4l2_mbus_frame_desc_entry entry[V4L2_FRAME_DESC_ENTRY_MAX];
  289. unsigned short num_entries;
  290. };
  291. /**
  292. * struct v4l2_subdev_video_ops - Callbacks used when v4l device was opened
  293. * in video mode.
  294. *
  295. * @s_routing: see s_routing in audio_ops, except this version is for video
  296. * devices.
  297. *
  298. * @s_crystal_freq: sets the frequency of the crystal used to generate the
  299. * clocks in Hz. An extra flags field allows device specific configuration
  300. * regarding clock frequency dividers, etc. If not used, then set flags
  301. * to 0. If the frequency is not supported, then -EINVAL is returned.
  302. *
  303. * @g_std: callback for VIDIOC_G_STD ioctl handler code.
  304. *
  305. * @s_std: callback for VIDIOC_S_STD ioctl handler code.
  306. *
  307. * @s_std_output: set v4l2_std_id for video OUTPUT devices. This is ignored by
  308. * video input devices.
  309. *
  310. * @g_std_output: get current standard for video OUTPUT devices. This is ignored
  311. * by video input devices.
  312. *
  313. * @querystd: callback for VIDIOC_QUERYSTD ioctl handler code.
  314. *
  315. * @g_tvnorms: get v4l2_std_id with all standards supported by the video
  316. * CAPTURE device. This is ignored by video output devices.
  317. *
  318. * @g_tvnorms_output: get v4l2_std_id with all standards supported by the video
  319. * OUTPUT device. This is ignored by video capture devices.
  320. *
  321. * @g_input_status: get input status. Same as the status field in the v4l2_input
  322. * struct.
  323. *
  324. * @s_stream: used to notify the driver that a video stream will start or has
  325. * stopped.
  326. *
  327. * @cropcap: callback for VIDIOC_CROPCAP ioctl handler code.
  328. *
  329. * @g_crop: callback for VIDIOC_G_CROP ioctl handler code.
  330. *
  331. * @s_crop: callback for VIDIOC_S_CROP ioctl handler code.
  332. *
  333. * @g_parm: callback for VIDIOC_G_PARM ioctl handler code.
  334. *
  335. * @s_parm: callback for VIDIOC_S_PARM ioctl handler code.
  336. *
  337. * @g_frame_interval: callback for VIDIOC_G_FRAMEINTERVAL ioctl handler code.
  338. *
  339. * @s_frame_interval: callback for VIDIOC_S_FRAMEINTERVAL ioctl handler code.
  340. *
  341. * @s_dv_timings: Set custom dv timings in the sub device. This is used
  342. * when sub device is capable of setting detailed timing information
  343. * in the hardware to generate/detect the video signal.
  344. *
  345. * @g_dv_timings: Get custom dv timings in the sub device.
  346. *
  347. * @query_dv_timings: callback for VIDIOC_QUERY_DV_TIMINGS ioctl handler code.
  348. *
  349. * @g_mbus_config: get supported mediabus configurations
  350. *
  351. * @s_mbus_config: set a certain mediabus configuration. This operation is added
  352. * for compatibility with soc-camera drivers and should not be used by new
  353. * software.
  354. *
  355. * @s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev
  356. * can adjust @size to a lower value and must not write more data to the
  357. * buffer starting at @data than the original value of @size.
  358. */
  359. struct v4l2_subdev_video_ops {
  360. int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
  361. int (*s_crystal_freq)(struct v4l2_subdev *sd, u32 freq, u32 flags);
  362. int (*g_std)(struct v4l2_subdev *sd, v4l2_std_id *norm);
  363. int (*s_std)(struct v4l2_subdev *sd, v4l2_std_id norm);
  364. int (*s_std_output)(struct v4l2_subdev *sd, v4l2_std_id std);
  365. int (*g_std_output)(struct v4l2_subdev *sd, v4l2_std_id *std);
  366. int (*querystd)(struct v4l2_subdev *sd, v4l2_std_id *std);
  367. int (*g_tvnorms)(struct v4l2_subdev *sd, v4l2_std_id *std);
  368. int (*g_tvnorms_output)(struct v4l2_subdev *sd, v4l2_std_id *std);
  369. int (*g_input_status)(struct v4l2_subdev *sd, u32 *status);
  370. int (*s_stream)(struct v4l2_subdev *sd, int enable);
  371. int (*cropcap)(struct v4l2_subdev *sd, struct v4l2_cropcap *cc);
  372. int (*g_crop)(struct v4l2_subdev *sd, struct v4l2_crop *crop);
  373. int (*s_crop)(struct v4l2_subdev *sd, const struct v4l2_crop *crop);
  374. int (*g_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param);
  375. int (*s_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param);
  376. int (*g_frame_interval)(struct v4l2_subdev *sd,
  377. struct v4l2_subdev_frame_interval *interval);
  378. int (*s_frame_interval)(struct v4l2_subdev *sd,
  379. struct v4l2_subdev_frame_interval *interval);
  380. int (*s_dv_timings)(struct v4l2_subdev *sd,
  381. struct v4l2_dv_timings *timings);
  382. int (*g_dv_timings)(struct v4l2_subdev *sd,
  383. struct v4l2_dv_timings *timings);
  384. int (*query_dv_timings)(struct v4l2_subdev *sd,
  385. struct v4l2_dv_timings *timings);
  386. int (*g_mbus_config)(struct v4l2_subdev *sd,
  387. struct v4l2_mbus_config *cfg);
  388. int (*s_mbus_config)(struct v4l2_subdev *sd,
  389. const struct v4l2_mbus_config *cfg);
  390. int (*s_rx_buffer)(struct v4l2_subdev *sd, void *buf,
  391. unsigned int *size);
  392. };
  393. /**
  394. * struct v4l2_subdev_vbi_ops - Callbacks used when v4l device was opened
  395. * in video mode via the vbi device node.
  396. *
  397. * @decode_vbi_line: video decoders that support sliced VBI need to implement
  398. * this ioctl. Field p of the v4l2_sliced_vbi_line struct is set to the
  399. * start of the VBI data that was generated by the decoder. The driver
  400. * then parses the sliced VBI data and sets the other fields in the
  401. * struct accordingly. The pointer p is updated to point to the start of
  402. * the payload which can be copied verbatim into the data field of the
  403. * v4l2_sliced_vbi_data struct. If no valid VBI data was found, then the
  404. * type field is set to 0 on return.
  405. *
  406. * @s_vbi_data: used to generate VBI signals on a video signal.
  407. * v4l2_sliced_vbi_data is filled with the data packets that should be
  408. * output. Note that if you set the line field to 0, then that VBI signal
  409. * is disabled. If no valid VBI data was found, then the type field is
  410. * set to 0 on return.
  411. *
  412. * @g_vbi_data: used to obtain the sliced VBI packet from a readback register.
  413. * Not all video decoders support this. If no data is available because
  414. * the readback register contains invalid or erroneous data -EIO is
  415. * returned. Note that you must fill in the 'id' member and the 'field'
  416. * member (to determine whether CC data from the first or second field
  417. * should be obtained).
  418. *
  419. * @g_sliced_vbi_cap: callback for VIDIOC_SLICED_VBI_CAP ioctl handler code.
  420. *
  421. * @s_raw_fmt: setup the video encoder/decoder for raw VBI.
  422. *
  423. * @g_sliced_fmt: retrieve the current sliced VBI settings.
  424. *
  425. * @s_sliced_fmt: setup the sliced VBI settings.
  426. */
  427. struct v4l2_subdev_vbi_ops {
  428. int (*decode_vbi_line)(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi_line);
  429. int (*s_vbi_data)(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *vbi_data);
  430. int (*g_vbi_data)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_data *vbi_data);
  431. int (*g_sliced_vbi_cap)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_cap *cap);
  432. int (*s_raw_fmt)(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt);
  433. int (*g_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
  434. int (*s_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
  435. };
  436. /**
  437. * struct v4l2_subdev_sensor_ops - v4l2-subdev sensor operations
  438. * @g_skip_top_lines: number of lines at the top of the image to be skipped.
  439. * This is needed for some sensors, which always corrupt
  440. * several top lines of the output image, or which send their
  441. * metadata in them.
  442. * @g_skip_frames: number of frames to skip at stream start. This is needed for
  443. * buggy sensors that generate faulty frames when they are
  444. * turned on.
  445. */
  446. struct v4l2_subdev_sensor_ops {
  447. int (*g_skip_top_lines)(struct v4l2_subdev *sd, u32 *lines);
  448. int (*g_skip_frames)(struct v4l2_subdev *sd, u32 *frames);
  449. };
  450. /*
  451. [rt]x_g_parameters: Get the current operating parameters and state of the
  452. the IR receiver or transmitter.
  453. [rt]x_s_parameters: Set the current operating parameters and state of the
  454. the IR receiver or transmitter. It is recommended to call
  455. [rt]x_g_parameters first to fill out the current state, and only change
  456. the fields that need to be changed. Upon return, the actual device
  457. operating parameters and state will be returned. Note that hardware
  458. limitations may prevent the actual settings from matching the requested
  459. settings - e.g. an actual carrier setting of 35,904 Hz when 36,000 Hz
  460. was requested. An exception is when the shutdown parameter is true.
  461. The last used operational parameters will be returned, but the actual
  462. state of the hardware be different to minimize power consumption and
  463. processing when shutdown is true.
  464. rx_read: Reads received codes or pulse width data.
  465. The semantics are similar to a non-blocking read() call.
  466. tx_write: Writes codes or pulse width data for transmission.
  467. The semantics are similar to a non-blocking write() call.
  468. */
  469. enum v4l2_subdev_ir_mode {
  470. V4L2_SUBDEV_IR_MODE_PULSE_WIDTH, /* uses struct ir_raw_event records */
  471. };
  472. struct v4l2_subdev_ir_parameters {
  473. /* Either Rx or Tx */
  474. unsigned int bytes_per_data_element; /* of data in read or write call */
  475. enum v4l2_subdev_ir_mode mode;
  476. bool enable;
  477. bool interrupt_enable;
  478. bool shutdown; /* true: set hardware to low/no power, false: normal */
  479. bool modulation; /* true: uses carrier, false: baseband */
  480. u32 max_pulse_width; /* ns, valid only for baseband signal */
  481. unsigned int carrier_freq; /* Hz, valid only for modulated signal*/
  482. unsigned int duty_cycle; /* percent, valid only for modulated signal*/
  483. bool invert_level; /* invert signal level */
  484. /* Tx only */
  485. bool invert_carrier_sense; /* Send 0/space as a carrier burst */
  486. /* Rx only */
  487. u32 noise_filter_min_width; /* ns, min time of a valid pulse */
  488. unsigned int carrier_range_lower; /* Hz, valid only for modulated sig */
  489. unsigned int carrier_range_upper; /* Hz, valid only for modulated sig */
  490. u32 resolution; /* ns */
  491. };
  492. struct v4l2_subdev_ir_ops {
  493. /* Receiver */
  494. int (*rx_read)(struct v4l2_subdev *sd, u8 *buf, size_t count,
  495. ssize_t *num);
  496. int (*rx_g_parameters)(struct v4l2_subdev *sd,
  497. struct v4l2_subdev_ir_parameters *params);
  498. int (*rx_s_parameters)(struct v4l2_subdev *sd,
  499. struct v4l2_subdev_ir_parameters *params);
  500. /* Transmitter */
  501. int (*tx_write)(struct v4l2_subdev *sd, u8 *buf, size_t count,
  502. ssize_t *num);
  503. int (*tx_g_parameters)(struct v4l2_subdev *sd,
  504. struct v4l2_subdev_ir_parameters *params);
  505. int (*tx_s_parameters)(struct v4l2_subdev *sd,
  506. struct v4l2_subdev_ir_parameters *params);
  507. };
  508. /*
  509. * Used for storing subdev pad information. This structure only needs
  510. * to be passed to the pad op if the 'which' field of the main argument
  511. * is set to V4L2_SUBDEV_FORMAT_TRY. For V4L2_SUBDEV_FORMAT_ACTIVE it is
  512. * safe to pass NULL.
  513. */
  514. struct v4l2_subdev_pad_config {
  515. struct v4l2_mbus_framefmt try_fmt;
  516. struct v4l2_rect try_crop;
  517. struct v4l2_rect try_compose;
  518. };
  519. /**
  520. * struct v4l2_subdev_pad_ops - v4l2-subdev pad level operations
  521. *
  522. * @enum_mbus_code: callback for VIDIOC_SUBDEV_ENUM_MBUS_CODE ioctl handler
  523. * code.
  524. * @enum_frame_size: callback for VIDIOC_SUBDEV_ENUM_FRAME_SIZE ioctl handler
  525. * code.
  526. *
  527. * @enum_frame_interval: callback for VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL ioctl
  528. * handler code.
  529. *
  530. * @get_fmt: callback for VIDIOC_SUBDEV_G_FMT ioctl handler code.
  531. *
  532. * @set_fmt: callback for VIDIOC_SUBDEV_S_FMT ioctl handler code.
  533. *
  534. * @get_selection: callback for VIDIOC_SUBDEV_G_SELECTION ioctl handler code.
  535. *
  536. * @set_selection: callback for VIDIOC_SUBDEV_S_SELECTION ioctl handler code.
  537. *
  538. * @get_edid: callback for VIDIOC_SUBDEV_G_EDID ioctl handler code.
  539. *
  540. * @set_edid: callback for VIDIOC_SUBDEV_S_EDID ioctl handler code.
  541. *
  542. * @dv_timings_cap: callback for VIDIOC_SUBDEV_DV_TIMINGS_CAP ioctl handler
  543. * code.
  544. *
  545. * @enum_dv_timings: callback for VIDIOC_SUBDEV_ENUM_DV_TIMINGS ioctl handler
  546. * code.
  547. *
  548. * @link_validate: used by the media controller code to check if the links
  549. * that belongs to a pipeline can be used for stream.
  550. *
  551. * @get_frame_desc: get the current low level media bus frame parameters.
  552. *
  553. * @set_frame_desc: set the low level media bus frame parameters, @fd array
  554. * may be adjusted by the subdev driver to device capabilities.
  555. */
  556. struct v4l2_subdev_pad_ops {
  557. int (*enum_mbus_code)(struct v4l2_subdev *sd,
  558. struct v4l2_subdev_pad_config *cfg,
  559. struct v4l2_subdev_mbus_code_enum *code);
  560. int (*enum_frame_size)(struct v4l2_subdev *sd,
  561. struct v4l2_subdev_pad_config *cfg,
  562. struct v4l2_subdev_frame_size_enum *fse);
  563. int (*enum_frame_interval)(struct v4l2_subdev *sd,
  564. struct v4l2_subdev_pad_config *cfg,
  565. struct v4l2_subdev_frame_interval_enum *fie);
  566. int (*get_fmt)(struct v4l2_subdev *sd,
  567. struct v4l2_subdev_pad_config *cfg,
  568. struct v4l2_subdev_format *format);
  569. int (*set_fmt)(struct v4l2_subdev *sd,
  570. struct v4l2_subdev_pad_config *cfg,
  571. struct v4l2_subdev_format *format);
  572. int (*get_selection)(struct v4l2_subdev *sd,
  573. struct v4l2_subdev_pad_config *cfg,
  574. struct v4l2_subdev_selection *sel);
  575. int (*set_selection)(struct v4l2_subdev *sd,
  576. struct v4l2_subdev_pad_config *cfg,
  577. struct v4l2_subdev_selection *sel);
  578. int (*get_edid)(struct v4l2_subdev *sd, struct v4l2_edid *edid);
  579. int (*set_edid)(struct v4l2_subdev *sd, struct v4l2_edid *edid);
  580. int (*dv_timings_cap)(struct v4l2_subdev *sd,
  581. struct v4l2_dv_timings_cap *cap);
  582. int (*enum_dv_timings)(struct v4l2_subdev *sd,
  583. struct v4l2_enum_dv_timings *timings);
  584. #ifdef CONFIG_MEDIA_CONTROLLER
  585. int (*link_validate)(struct v4l2_subdev *sd, struct media_link *link,
  586. struct v4l2_subdev_format *source_fmt,
  587. struct v4l2_subdev_format *sink_fmt);
  588. #endif /* CONFIG_MEDIA_CONTROLLER */
  589. int (*get_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
  590. struct v4l2_mbus_frame_desc *fd);
  591. int (*set_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
  592. struct v4l2_mbus_frame_desc *fd);
  593. };
  594. struct v4l2_subdev_ops {
  595. const struct v4l2_subdev_core_ops *core;
  596. const struct v4l2_subdev_tuner_ops *tuner;
  597. const struct v4l2_subdev_audio_ops *audio;
  598. const struct v4l2_subdev_video_ops *video;
  599. const struct v4l2_subdev_vbi_ops *vbi;
  600. const struct v4l2_subdev_ir_ops *ir;
  601. const struct v4l2_subdev_sensor_ops *sensor;
  602. const struct v4l2_subdev_pad_ops *pad;
  603. };
  604. /*
  605. * Internal ops. Never call this from drivers, only the v4l2 framework can call
  606. * these ops.
  607. *
  608. * registered: called when this subdev is registered. When called the v4l2_dev
  609. * field is set to the correct v4l2_device.
  610. *
  611. * unregistered: called when this subdev is unregistered. When called the
  612. * v4l2_dev field is still set to the correct v4l2_device.
  613. *
  614. * open: called when the subdev device node is opened by an application.
  615. *
  616. * close: called when the subdev device node is closed.
  617. */
  618. struct v4l2_subdev_internal_ops {
  619. int (*registered)(struct v4l2_subdev *sd);
  620. void (*unregistered)(struct v4l2_subdev *sd);
  621. int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
  622. int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
  623. };
  624. #define V4L2_SUBDEV_NAME_SIZE 32
  625. /* Set this flag if this subdev is a i2c device. */
  626. #define V4L2_SUBDEV_FL_IS_I2C (1U << 0)
  627. /* Set this flag if this subdev is a spi device. */
  628. #define V4L2_SUBDEV_FL_IS_SPI (1U << 1)
  629. /* Set this flag if this subdev needs a device node. */
  630. #define V4L2_SUBDEV_FL_HAS_DEVNODE (1U << 2)
  631. /* Set this flag if this subdev generates events. */
  632. #define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
  633. struct regulator_bulk_data;
  634. struct v4l2_subdev_platform_data {
  635. /* Optional regulators uset to power on/off the subdevice */
  636. struct regulator_bulk_data *regulators;
  637. int num_regulators;
  638. /* Per-subdevice data, specific for a certain video host device */
  639. void *host_priv;
  640. };
  641. /* Each instance of a subdev driver should create this struct, either
  642. stand-alone or embedded in a larger struct.
  643. */
  644. struct v4l2_subdev {
  645. #if defined(CONFIG_MEDIA_CONTROLLER)
  646. struct media_entity entity;
  647. #endif
  648. struct list_head list;
  649. struct module *owner;
  650. bool owner_v4l2_dev;
  651. u32 flags;
  652. struct v4l2_device *v4l2_dev;
  653. const struct v4l2_subdev_ops *ops;
  654. /* Never call these internal ops from within a driver! */
  655. const struct v4l2_subdev_internal_ops *internal_ops;
  656. /* The control handler of this subdev. May be NULL. */
  657. struct v4l2_ctrl_handler *ctrl_handler;
  658. /* name must be unique */
  659. char name[V4L2_SUBDEV_NAME_SIZE];
  660. /* can be used to group similar subdevs, value is driver-specific */
  661. u32 grp_id;
  662. /* pointer to private data */
  663. void *dev_priv;
  664. void *host_priv;
  665. /* subdev device node */
  666. struct video_device *devnode;
  667. /* pointer to the physical device, if any */
  668. struct device *dev;
  669. /* The device_node of the subdev, usually the same as dev->of_node. */
  670. struct device_node *of_node;
  671. /* Links this subdev to a global subdev_list or @notifier->done list. */
  672. struct list_head async_list;
  673. /* Pointer to respective struct v4l2_async_subdev. */
  674. struct v4l2_async_subdev *asd;
  675. /* Pointer to the managing notifier. */
  676. struct v4l2_async_notifier *notifier;
  677. /* common part of subdevice platform data */
  678. struct v4l2_subdev_platform_data *pdata;
  679. };
  680. #define media_entity_to_v4l2_subdev(ent) \
  681. container_of(ent, struct v4l2_subdev, entity)
  682. #define vdev_to_v4l2_subdev(vdev) \
  683. ((struct v4l2_subdev *)video_get_drvdata(vdev))
  684. /*
  685. * Used for storing subdev information per file handle
  686. */
  687. struct v4l2_subdev_fh {
  688. struct v4l2_fh vfh;
  689. #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
  690. struct v4l2_subdev_pad_config *pad;
  691. #endif
  692. };
  693. #define to_v4l2_subdev_fh(fh) \
  694. container_of(fh, struct v4l2_subdev_fh, vfh)
  695. #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
  696. #define __V4L2_SUBDEV_MK_GET_TRY(rtype, fun_name, field_name) \
  697. static inline struct rtype * \
  698. fun_name(struct v4l2_subdev *sd, \
  699. struct v4l2_subdev_pad_config *cfg, \
  700. unsigned int pad) \
  701. { \
  702. BUG_ON(pad >= sd->entity.num_pads); \
  703. return &cfg[pad].field_name; \
  704. }
  705. __V4L2_SUBDEV_MK_GET_TRY(v4l2_mbus_framefmt, v4l2_subdev_get_try_format, try_fmt)
  706. __V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, v4l2_subdev_get_try_crop, try_crop)
  707. __V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, v4l2_subdev_get_try_compose, try_compose)
  708. #endif
  709. extern const struct v4l2_file_operations v4l2_subdev_fops;
  710. static inline void v4l2_set_subdevdata(struct v4l2_subdev *sd, void *p)
  711. {
  712. sd->dev_priv = p;
  713. }
  714. static inline void *v4l2_get_subdevdata(const struct v4l2_subdev *sd)
  715. {
  716. return sd->dev_priv;
  717. }
  718. static inline void v4l2_set_subdev_hostdata(struct v4l2_subdev *sd, void *p)
  719. {
  720. sd->host_priv = p;
  721. }
  722. static inline void *v4l2_get_subdev_hostdata(const struct v4l2_subdev *sd)
  723. {
  724. return sd->host_priv;
  725. }
  726. #ifdef CONFIG_MEDIA_CONTROLLER
  727. int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
  728. struct media_link *link,
  729. struct v4l2_subdev_format *source_fmt,
  730. struct v4l2_subdev_format *sink_fmt);
  731. int v4l2_subdev_link_validate(struct media_link *link);
  732. #endif /* CONFIG_MEDIA_CONTROLLER */
  733. void v4l2_subdev_init(struct v4l2_subdev *sd,
  734. const struct v4l2_subdev_ops *ops);
  735. /* Call an ops of a v4l2_subdev, doing the right checks against
  736. NULL pointers.
  737. Example: err = v4l2_subdev_call(sd, video, s_std, norm);
  738. */
  739. #define v4l2_subdev_call(sd, o, f, args...) \
  740. (!(sd) ? -ENODEV : (((sd)->ops->o && (sd)->ops->o->f) ? \
  741. (sd)->ops->o->f((sd) , ##args) : -ENOIOCTLCMD))
  742. #define v4l2_subdev_has_op(sd, o, f) \
  743. ((sd)->ops->o && (sd)->ops->o->f)
  744. void v4l2_subdev_notify_event(struct v4l2_subdev *sd,
  745. const struct v4l2_event *ev);
  746. #endif