v4l2-subdev.h 27 KB

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