v4l2-subdev.h 24 KB

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