v4l2-subdev.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  1. /*
  2. * V4L2 sub-device support header.
  3. *
  4. * Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  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. /**
  45. * struct v4l2_decode_vbi_line - used to decode_vbi_line
  46. *
  47. * @is_second_field: Set to 0 for the first (odd) field;
  48. * set to 1 for the second (even) field.
  49. * @p: Pointer to the sliced VBI data from the decoder. On exit, points to
  50. * the start of the payload.
  51. * @line: Line number of the sliced VBI data (1-23)
  52. * @type: VBI service type (V4L2_SLICED_*). 0 if no service found
  53. */
  54. struct v4l2_decode_vbi_line {
  55. u32 is_second_field;
  56. u8 *p;
  57. u32 line;
  58. u32 type;
  59. };
  60. /*
  61. * Sub-devices are devices that are connected somehow to the main bridge
  62. * device. These devices are usually audio/video muxers/encoders/decoders or
  63. * sensors and webcam controllers.
  64. *
  65. * Usually these devices are controlled through an i2c bus, but other busses
  66. * may also be used.
  67. *
  68. * The v4l2_subdev struct provides a way of accessing these devices in a
  69. * generic manner. Most operations that these sub-devices support fall in
  70. * a few categories: core ops, audio ops, video ops and tuner ops.
  71. *
  72. * More categories can be added if needed, although this should remain a
  73. * limited set (no more than approx. 8 categories).
  74. *
  75. * Each category has its own set of ops that subdev drivers can implement.
  76. *
  77. * A subdev driver can leave the pointer to the category ops NULL if
  78. * it does not implement them (e.g. an audio subdev will generally not
  79. * implement the video category ops). The exception is the core category:
  80. * this must always be present.
  81. *
  82. * These ops are all used internally so it is no problem to change, remove
  83. * or add ops or move ops from one to another category. Currently these
  84. * ops are based on the original ioctls, but since ops are not limited to
  85. * one argument there is room for improvement here once all i2c subdev
  86. * drivers are converted to use these ops.
  87. */
  88. /*
  89. * Core ops: it is highly recommended to implement at least these ops:
  90. *
  91. * log_status
  92. * g_register
  93. * s_register
  94. *
  95. * This provides basic debugging support.
  96. *
  97. * The ioctl ops is meant for generic ioctl-like commands. Depending on
  98. * the use-case it might be better to use subdev-specific ops (currently
  99. * not yet implemented) since ops provide proper type-checking.
  100. */
  101. /**
  102. * enum v4l2_subdev_io_pin_bits - Subdevice external IO pin configuration
  103. * bits
  104. *
  105. * @V4L2_SUBDEV_IO_PIN_DISABLE: disables a pin config. ENABLE assumed.
  106. * @V4L2_SUBDEV_IO_PIN_OUTPUT: set it if pin is an output.
  107. * @V4L2_SUBDEV_IO_PIN_INPUT: set it if pin is an input.
  108. * @V4L2_SUBDEV_IO_PIN_SET_VALUE: to set the output value via
  109. * &struct v4l2_subdev_io_pin_config->value.
  110. * @V4L2_SUBDEV_IO_PIN_ACTIVE_LOW: pin active is bit 0.
  111. * Otherwise, ACTIVE HIGH is assumed.
  112. */
  113. enum v4l2_subdev_io_pin_bits {
  114. V4L2_SUBDEV_IO_PIN_DISABLE = 0,
  115. V4L2_SUBDEV_IO_PIN_OUTPUT = 1,
  116. V4L2_SUBDEV_IO_PIN_INPUT = 2,
  117. V4L2_SUBDEV_IO_PIN_SET_VALUE = 3,
  118. V4L2_SUBDEV_IO_PIN_ACTIVE_LOW = 4,
  119. };
  120. /**
  121. * struct v4l2_subdev_io_pin_config - Subdevice external IO pin configuration
  122. *
  123. * @flags: bitmask with flags for this pin's config, whose bits are defined by
  124. * &enum v4l2_subdev_io_pin_bits.
  125. * @pin: Chip external IO pin to configure
  126. * @function: Internal signal pad/function to route to IO pin
  127. * @value: Initial value for pin - e.g. GPIO output value
  128. * @strength: Pin drive strength
  129. */
  130. struct v4l2_subdev_io_pin_config {
  131. u32 flags;
  132. u8 pin;
  133. u8 function;
  134. u8 value;
  135. u8 strength;
  136. };
  137. /**
  138. * struct v4l2_subdev_core_ops - Define core ops callbacks for subdevs
  139. *
  140. * @log_status: callback for VIDIOC_LOG_STATUS() ioctl handler code.
  141. *
  142. * @s_io_pin_config: configure one or more chip I/O pins for chips that
  143. * multiplex different internal signal pads out to IO pins. This function
  144. * takes a pointer to an array of 'n' pin configuration entries, one for
  145. * each pin being configured. This function could be called at times
  146. * other than just subdevice initialization.
  147. *
  148. * @init: initialize the sensor registers to some sort of reasonable default
  149. * values. Do not use for new drivers and should be removed in existing
  150. * drivers.
  151. *
  152. * @load_fw: load firmware.
  153. *
  154. * @reset: generic reset command. The argument selects which subsystems to
  155. * reset. Passing 0 will always reset the whole chip. Do not use for new
  156. * drivers without discussing this first on the linux-media mailinglist.
  157. * There should be no reason normally to reset a device.
  158. *
  159. * @s_gpio: set GPIO pins. Very simple right now, might need to be extended with
  160. * a direction argument if needed.
  161. *
  162. * @ioctl: called at the end of ioctl() syscall handler at the V4L2 core.
  163. * used to provide support for private ioctls used on the driver.
  164. *
  165. * @compat_ioctl32: called when a 32 bits application uses a 64 bits Kernel,
  166. * in order to fix data passed from/to userspace.
  167. *
  168. * @g_register: callback for VIDIOC_DBG_G_REGISTER() ioctl handler code.
  169. *
  170. * @s_register: callback for VIDIOC_DBG_S_REGISTER() ioctl handler code.
  171. *
  172. * @s_power: puts subdevice in power saving mode (on == 0) or normal operation
  173. * mode (on == 1).
  174. *
  175. * @interrupt_service_routine: Called by the bridge chip's interrupt service
  176. * handler, when an interrupt status has be raised due to this subdev,
  177. * so that this subdev can handle the details. It may schedule work to be
  178. * performed later. It must not sleep. **Called from an IRQ context**.
  179. *
  180. * @subscribe_event: used by the drivers to request the control framework that
  181. * for it to be warned when the value of a control changes.
  182. *
  183. * @unsubscribe_event: remove event subscription from the control framework.
  184. */
  185. struct v4l2_subdev_core_ops {
  186. int (*log_status)(struct v4l2_subdev *sd);
  187. int (*s_io_pin_config)(struct v4l2_subdev *sd, size_t n,
  188. struct v4l2_subdev_io_pin_config *pincfg);
  189. int (*init)(struct v4l2_subdev *sd, u32 val);
  190. int (*load_fw)(struct v4l2_subdev *sd);
  191. int (*reset)(struct v4l2_subdev *sd, u32 val);
  192. int (*s_gpio)(struct v4l2_subdev *sd, u32 val);
  193. long (*ioctl)(struct v4l2_subdev *sd, unsigned int cmd, void *arg);
  194. #ifdef CONFIG_COMPAT
  195. long (*compat_ioctl32)(struct v4l2_subdev *sd, unsigned int cmd,
  196. unsigned long arg);
  197. #endif
  198. #ifdef CONFIG_VIDEO_ADV_DEBUG
  199. int (*g_register)(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg);
  200. int (*s_register)(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg);
  201. #endif
  202. int (*s_power)(struct v4l2_subdev *sd, int on);
  203. int (*interrupt_service_routine)(struct v4l2_subdev *sd,
  204. u32 status, bool *handled);
  205. int (*subscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  206. struct v4l2_event_subscription *sub);
  207. int (*unsubscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  208. struct v4l2_event_subscription *sub);
  209. };
  210. /**
  211. * struct v4l2_subdev_tuner_ops - Callbacks used when v4l device was opened
  212. * in radio mode.
  213. *
  214. * @standby: puts the tuner in standby mode. It will be woken up
  215. * automatically the next time it is used.
  216. *
  217. * @s_radio: callback that switches the tuner to radio mode.
  218. * drivers should explicitly call it when a tuner ops should
  219. * operate on radio mode, before being able to handle it.
  220. * Used on devices that have both AM/FM radio receiver and TV.
  221. *
  222. * @s_frequency: callback for VIDIOC_S_FREQUENCY() ioctl handler code.
  223. *
  224. * @g_frequency: callback for VIDIOC_G_FREQUENCY() ioctl handler code.
  225. * freq->type must be filled in. Normally done by video_ioctl2()
  226. * or the bridge driver.
  227. *
  228. * @enum_freq_bands: callback for VIDIOC_ENUM_FREQ_BANDS() ioctl handler code.
  229. *
  230. * @g_tuner: callback for VIDIOC_G_TUNER() ioctl handler code.
  231. *
  232. * @s_tuner: callback for VIDIOC_S_TUNER() ioctl handler code. @vt->type must be
  233. * filled in. Normally done by video_ioctl2 or the
  234. * bridge driver.
  235. *
  236. * @g_modulator: callback for VIDIOC_G_MODULATOR() ioctl handler code.
  237. *
  238. * @s_modulator: callback for VIDIOC_S_MODULATOR() ioctl handler code.
  239. *
  240. * @s_type_addr: sets tuner type and its I2C addr.
  241. *
  242. * @s_config: sets tda9887 specific stuff, like port1, port2 and qss
  243. *
  244. * .. note::
  245. *
  246. * On devices that have both AM/FM and TV, it is up to the driver
  247. * to explicitly call s_radio when the tuner should be switched to
  248. * radio mode, before handling other &struct v4l2_subdev_tuner_ops
  249. * that would require it. An example of such usage is::
  250. *
  251. * static void s_frequency(void *priv, const struct v4l2_frequency *f)
  252. * {
  253. * ...
  254. * if (f.type == V4L2_TUNER_RADIO)
  255. * v4l2_device_call_all(v4l2_dev, 0, tuner, s_radio);
  256. * ...
  257. * v4l2_device_call_all(v4l2_dev, 0, tuner, s_frequency);
  258. * }
  259. */
  260. struct v4l2_subdev_tuner_ops {
  261. int (*standby)(struct v4l2_subdev *sd);
  262. int (*s_radio)(struct v4l2_subdev *sd);
  263. int (*s_frequency)(struct v4l2_subdev *sd, const struct v4l2_frequency *freq);
  264. int (*g_frequency)(struct v4l2_subdev *sd, struct v4l2_frequency *freq);
  265. int (*enum_freq_bands)(struct v4l2_subdev *sd, struct v4l2_frequency_band *band);
  266. int (*g_tuner)(struct v4l2_subdev *sd, struct v4l2_tuner *vt);
  267. int (*s_tuner)(struct v4l2_subdev *sd, const struct v4l2_tuner *vt);
  268. int (*g_modulator)(struct v4l2_subdev *sd, struct v4l2_modulator *vm);
  269. int (*s_modulator)(struct v4l2_subdev *sd, const struct v4l2_modulator *vm);
  270. int (*s_type_addr)(struct v4l2_subdev *sd, struct tuner_setup *type);
  271. int (*s_config)(struct v4l2_subdev *sd, const struct v4l2_priv_tun_config *config);
  272. };
  273. /**
  274. * struct v4l2_subdev_audio_ops - Callbacks used for audio-related settings
  275. *
  276. * @s_clock_freq: set the frequency (in Hz) of the audio clock output.
  277. * Used to slave an audio processor to the video decoder, ensuring that
  278. * audio and video remain synchronized. Usual values for the frequency
  279. * are 48000, 44100 or 32000 Hz. If the frequency is not supported, then
  280. * -EINVAL is returned.
  281. *
  282. * @s_i2s_clock_freq: sets I2S speed in bps. This is used to provide a standard
  283. * way to select I2S clock used by driving digital audio streams at some
  284. * board designs. Usual values for the frequency are 1024000 and 2048000.
  285. * If the frequency is not supported, then %-EINVAL is returned.
  286. *
  287. * @s_routing: used to define the input and/or output pins of an audio chip,
  288. * and any additional configuration data.
  289. * Never attempt to use user-level input IDs (e.g. Composite, S-Video,
  290. * Tuner) at this level. An i2c device shouldn't know about whether an
  291. * input pin is connected to a Composite connector, become on another
  292. * board or platform it might be connected to something else entirely.
  293. * The calling driver is responsible for mapping a user-level input to
  294. * the right pins on the i2c device.
  295. *
  296. * @s_stream: used to notify the audio code that stream will start or has
  297. * stopped.
  298. */
  299. struct v4l2_subdev_audio_ops {
  300. int (*s_clock_freq)(struct v4l2_subdev *sd, u32 freq);
  301. int (*s_i2s_clock_freq)(struct v4l2_subdev *sd, u32 freq);
  302. int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
  303. int (*s_stream)(struct v4l2_subdev *sd, int enable);
  304. };
  305. /**
  306. * enum v4l2_mbus_frame_desc_entry - media bus frame description flags
  307. *
  308. * @V4L2_MBUS_FRAME_DESC_FL_LEN_MAX:
  309. * Indicates that &struct v4l2_mbus_frame_desc_entry->length field
  310. * specifies maximum data length.
  311. * @V4L2_MBUS_FRAME_DESC_FL_BLOB:
  312. * Indicates that the format does not have line offsets, i.e.
  313. * the receiver should use 1D DMA.
  314. */
  315. enum v4l2_mbus_frame_desc_flags {
  316. V4L2_MBUS_FRAME_DESC_FL_LEN_MAX = BIT(0),
  317. V4L2_MBUS_FRAME_DESC_FL_BLOB = BIT(1),
  318. };
  319. /**
  320. * struct v4l2_mbus_frame_desc_entry - media bus frame description structure
  321. *
  322. * @flags: bitmask flags, as defined by &enum v4l2_mbus_frame_desc_flags.
  323. * @pixelcode: media bus pixel code, valid if @flags
  324. * %FRAME_DESC_FL_BLOB is not set.
  325. * @length: number of octets per frame, valid if @flags
  326. * %V4L2_MBUS_FRAME_DESC_FL_LEN_MAX is set.
  327. */
  328. struct v4l2_mbus_frame_desc_entry {
  329. enum v4l2_mbus_frame_desc_flags flags;
  330. u32 pixelcode;
  331. u32 length;
  332. };
  333. #define V4L2_FRAME_DESC_ENTRY_MAX 4
  334. /**
  335. * struct v4l2_mbus_frame_desc - media bus data frame description
  336. * @entry: frame descriptors array
  337. * @num_entries: number of entries in @entry array
  338. */
  339. struct v4l2_mbus_frame_desc {
  340. struct v4l2_mbus_frame_desc_entry entry[V4L2_FRAME_DESC_ENTRY_MAX];
  341. unsigned short num_entries;
  342. };
  343. /**
  344. * struct v4l2_subdev_video_ops - Callbacks used when v4l device was opened
  345. * in video mode.
  346. *
  347. * @s_routing: see s_routing in audio_ops, except this version is for video
  348. * devices.
  349. *
  350. * @s_crystal_freq: sets the frequency of the crystal used to generate the
  351. * clocks in Hz. An extra flags field allows device specific configuration
  352. * regarding clock frequency dividers, etc. If not used, then set flags
  353. * to 0. If the frequency is not supported, then -EINVAL is returned.
  354. *
  355. * @g_std: callback for VIDIOC_G_STD() ioctl handler code.
  356. *
  357. * @s_std: callback for VIDIOC_S_STD() ioctl handler code.
  358. *
  359. * @s_std_output: set v4l2_std_id for video OUTPUT devices. This is ignored by
  360. * video input devices.
  361. *
  362. * @g_std_output: get current standard for video OUTPUT devices. This is ignored
  363. * by video input devices.
  364. *
  365. * @querystd: callback for VIDIOC_QUERYSTD() ioctl handler code.
  366. *
  367. * @g_tvnorms: get &v4l2_std_id with all standards supported by the video
  368. * CAPTURE device. This is ignored by video output devices.
  369. *
  370. * @g_tvnorms_output: get v4l2_std_id with all standards supported by the video
  371. * OUTPUT device. This is ignored by video capture devices.
  372. *
  373. * @g_input_status: get input status. Same as the status field in the
  374. * &struct &v4l2_input
  375. *
  376. * @s_stream: used to notify the driver that a video stream will start or has
  377. * stopped.
  378. *
  379. * @g_pixelaspect: callback to return the pixelaspect ratio.
  380. *
  381. * @g_frame_interval: callback for VIDIOC_SUBDEV_G_FRAME_INTERVAL()
  382. * ioctl handler code.
  383. *
  384. * @s_frame_interval: callback for VIDIOC_SUBDEV_S_FRAME_INTERVAL()
  385. * ioctl handler code.
  386. *
  387. * @s_dv_timings: Set custom dv timings in the sub device. This is used
  388. * when sub device is capable of setting detailed timing information
  389. * in the hardware to generate/detect the video signal.
  390. *
  391. * @g_dv_timings: Get custom dv timings in the sub device.
  392. *
  393. * @query_dv_timings: callback for VIDIOC_QUERY_DV_TIMINGS() ioctl handler code.
  394. *
  395. * @g_mbus_config: get supported mediabus configurations
  396. *
  397. * @s_mbus_config: set a certain mediabus configuration. This operation is added
  398. * for compatibility with soc-camera drivers and should not be used by new
  399. * software.
  400. *
  401. * @s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev
  402. * can adjust @size to a lower value and must not write more data to the
  403. * buffer starting at @data than the original value of @size.
  404. */
  405. struct v4l2_subdev_video_ops {
  406. int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
  407. int (*s_crystal_freq)(struct v4l2_subdev *sd, u32 freq, u32 flags);
  408. int (*g_std)(struct v4l2_subdev *sd, v4l2_std_id *norm);
  409. int (*s_std)(struct v4l2_subdev *sd, v4l2_std_id norm);
  410. int (*s_std_output)(struct v4l2_subdev *sd, v4l2_std_id std);
  411. int (*g_std_output)(struct v4l2_subdev *sd, v4l2_std_id *std);
  412. int (*querystd)(struct v4l2_subdev *sd, v4l2_std_id *std);
  413. int (*g_tvnorms)(struct v4l2_subdev *sd, v4l2_std_id *std);
  414. int (*g_tvnorms_output)(struct v4l2_subdev *sd, v4l2_std_id *std);
  415. int (*g_input_status)(struct v4l2_subdev *sd, u32 *status);
  416. int (*s_stream)(struct v4l2_subdev *sd, int enable);
  417. int (*g_pixelaspect)(struct v4l2_subdev *sd, struct v4l2_fract *aspect);
  418. int (*g_frame_interval)(struct v4l2_subdev *sd,
  419. struct v4l2_subdev_frame_interval *interval);
  420. int (*s_frame_interval)(struct v4l2_subdev *sd,
  421. struct v4l2_subdev_frame_interval *interval);
  422. int (*s_dv_timings)(struct v4l2_subdev *sd,
  423. struct v4l2_dv_timings *timings);
  424. int (*g_dv_timings)(struct v4l2_subdev *sd,
  425. struct v4l2_dv_timings *timings);
  426. int (*query_dv_timings)(struct v4l2_subdev *sd,
  427. struct v4l2_dv_timings *timings);
  428. int (*g_mbus_config)(struct v4l2_subdev *sd,
  429. struct v4l2_mbus_config *cfg);
  430. int (*s_mbus_config)(struct v4l2_subdev *sd,
  431. const struct v4l2_mbus_config *cfg);
  432. int (*s_rx_buffer)(struct v4l2_subdev *sd, void *buf,
  433. unsigned int *size);
  434. };
  435. /**
  436. * struct v4l2_subdev_vbi_ops - Callbacks used when v4l device was opened
  437. * in video mode via the vbi device node.
  438. *
  439. * @decode_vbi_line: video decoders that support sliced VBI need to implement
  440. * this ioctl. Field p of the &struct v4l2_decode_vbi_line is set to the
  441. * start of the VBI data that was generated by the decoder. The driver
  442. * then parses the sliced VBI data and sets the other fields in the
  443. * struct accordingly. The pointer p is updated to point to the start of
  444. * the payload which can be copied verbatim into the data field of the
  445. * &struct v4l2_sliced_vbi_data. If no valid VBI data was found, then the
  446. * type field is set to 0 on return.
  447. *
  448. * @s_vbi_data: used to generate VBI signals on a video signal.
  449. * &struct v4l2_sliced_vbi_data is filled with the data packets that
  450. * should be output. Note that if you set the line field to 0, then that
  451. * VBI signal is disabled. If no valid VBI data was found, then the type
  452. * field is set to 0 on return.
  453. *
  454. * @g_vbi_data: used to obtain the sliced VBI packet from a readback register.
  455. * Not all video decoders support this. If no data is available because
  456. * the readback register contains invalid or erroneous data %-EIO is
  457. * returned. Note that you must fill in the 'id' member and the 'field'
  458. * member (to determine whether CC data from the first or second field
  459. * should be obtained).
  460. *
  461. * @g_sliced_vbi_cap: callback for VIDIOC_G_SLICED_VBI_CAP() ioctl handler
  462. * code.
  463. *
  464. * @s_raw_fmt: setup the video encoder/decoder for raw VBI.
  465. *
  466. * @g_sliced_fmt: retrieve the current sliced VBI settings.
  467. *
  468. * @s_sliced_fmt: setup the sliced VBI settings.
  469. */
  470. struct v4l2_subdev_vbi_ops {
  471. int (*decode_vbi_line)(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi_line);
  472. int (*s_vbi_data)(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *vbi_data);
  473. int (*g_vbi_data)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_data *vbi_data);
  474. int (*g_sliced_vbi_cap)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_cap *cap);
  475. int (*s_raw_fmt)(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt);
  476. int (*g_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
  477. int (*s_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
  478. };
  479. /**
  480. * struct v4l2_subdev_sensor_ops - v4l2-subdev sensor operations
  481. * @g_skip_top_lines: number of lines at the top of the image to be skipped.
  482. * This is needed for some sensors, which always corrupt
  483. * several top lines of the output image, or which send their
  484. * metadata in them.
  485. * @g_skip_frames: number of frames to skip at stream start. This is needed for
  486. * buggy sensors that generate faulty frames when they are
  487. * turned on.
  488. */
  489. struct v4l2_subdev_sensor_ops {
  490. int (*g_skip_top_lines)(struct v4l2_subdev *sd, u32 *lines);
  491. int (*g_skip_frames)(struct v4l2_subdev *sd, u32 *frames);
  492. };
  493. /**
  494. * enum v4l2_subdev_ir_mode- describes the type of IR supported
  495. *
  496. * @V4L2_SUBDEV_IR_MODE_PULSE_WIDTH: IR uses struct ir_raw_event records
  497. */
  498. enum v4l2_subdev_ir_mode {
  499. V4L2_SUBDEV_IR_MODE_PULSE_WIDTH,
  500. };
  501. /**
  502. * struct v4l2_subdev_ir_parameters - Parameters for IR TX or TX
  503. *
  504. * @bytes_per_data_element: bytes per data element of data in read or
  505. * write call.
  506. * @mode: IR mode as defined by &enum v4l2_subdev_ir_mode.
  507. * @enable: device is active if true
  508. * @interrupt_enable: IR interrupts are enabled if true
  509. * @shutdown: if true: set hardware to low/no power, false: normal mode
  510. *
  511. * @modulation: if true, it uses carrier, if false: baseband
  512. * @max_pulse_width: maximum pulse width in ns, valid only for baseband signal
  513. * @carrier_freq: carrier frequency in Hz, valid only for modulated signal
  514. * @duty_cycle: duty cycle percentage, valid only for modulated signal
  515. * @invert_level: invert signal level
  516. *
  517. * @invert_carrier_sense: Send 0/space as a carrier burst. used only in TX.
  518. *
  519. * @noise_filter_min_width: min time of a valid pulse, in ns. Used only for RX.
  520. * @carrier_range_lower: Lower carrier range, in Hz, valid only for modulated
  521. * signal. Used only for RX.
  522. * @carrier_range_upper: Upper carrier range, in Hz, valid only for modulated
  523. * signal. Used only for RX.
  524. * @resolution: The receive resolution, in ns . Used only for RX.
  525. */
  526. struct v4l2_subdev_ir_parameters {
  527. unsigned int bytes_per_data_element;
  528. enum v4l2_subdev_ir_mode mode;
  529. bool enable;
  530. bool interrupt_enable;
  531. bool shutdown;
  532. bool modulation;
  533. u32 max_pulse_width;
  534. unsigned int carrier_freq;
  535. unsigned int duty_cycle;
  536. bool invert_level;
  537. /* Tx only */
  538. bool invert_carrier_sense;
  539. /* Rx only */
  540. u32 noise_filter_min_width;
  541. unsigned int carrier_range_lower;
  542. unsigned int carrier_range_upper;
  543. u32 resolution;
  544. };
  545. /**
  546. * struct v4l2_subdev_ir_ops - operations for IR subdevices
  547. *
  548. * @rx_read: Reads received codes or pulse width data.
  549. * The semantics are similar to a non-blocking read() call.
  550. * @rx_g_parameters: Get the current operating parameters and state of the
  551. * the IR receiver.
  552. * @rx_s_parameters: Set the current operating parameters and state of the
  553. * the IR receiver. It is recommended to call
  554. * [rt]x_g_parameters first to fill out the current state, and only change
  555. * the fields that need to be changed. Upon return, the actual device
  556. * operating parameters and state will be returned. Note that hardware
  557. * limitations may prevent the actual settings from matching the requested
  558. * settings - e.g. an actual carrier setting of 35,904 Hz when 36,000 Hz
  559. * was requested. An exception is when the shutdown parameter is true.
  560. * The last used operational parameters will be returned, but the actual
  561. * state of the hardware be different to minimize power consumption and
  562. * processing when shutdown is true.
  563. *
  564. * @tx_write: Writes codes or pulse width data for transmission.
  565. * The semantics are similar to a non-blocking write() call.
  566. * @tx_g_parameters: Get the current operating parameters and state of the
  567. * the IR transmitter.
  568. * @tx_s_parameters: Set the current operating parameters and state of the
  569. * the IR transmitter. It is recommended to call
  570. * [rt]x_g_parameters first to fill out the current state, and only change
  571. * the fields that need to be changed. Upon return, the actual device
  572. * operating parameters and state will be returned. Note that hardware
  573. * limitations may prevent the actual settings from matching the requested
  574. * settings - e.g. an actual carrier setting of 35,904 Hz when 36,000 Hz
  575. * was requested. An exception is when the shutdown parameter is true.
  576. * The last used operational parameters will be returned, but the actual
  577. * state of the hardware be different to minimize power consumption and
  578. * processing when shutdown is true.
  579. */
  580. struct v4l2_subdev_ir_ops {
  581. /* Receiver */
  582. int (*rx_read)(struct v4l2_subdev *sd, u8 *buf, size_t count,
  583. ssize_t *num);
  584. int (*rx_g_parameters)(struct v4l2_subdev *sd,
  585. struct v4l2_subdev_ir_parameters *params);
  586. int (*rx_s_parameters)(struct v4l2_subdev *sd,
  587. struct v4l2_subdev_ir_parameters *params);
  588. /* Transmitter */
  589. int (*tx_write)(struct v4l2_subdev *sd, u8 *buf, size_t count,
  590. ssize_t *num);
  591. int (*tx_g_parameters)(struct v4l2_subdev *sd,
  592. struct v4l2_subdev_ir_parameters *params);
  593. int (*tx_s_parameters)(struct v4l2_subdev *sd,
  594. struct v4l2_subdev_ir_parameters *params);
  595. };
  596. /**
  597. * struct v4l2_subdev_pad_config - Used for storing subdev pad information.
  598. *
  599. * @try_fmt: &struct v4l2_mbus_framefmt
  600. * @try_crop: &struct v4l2_rect to be used for crop
  601. * @try_compose: &struct v4l2_rect to be used for compose
  602. *
  603. * This structure only needs to be passed to the pad op if the 'which' field
  604. * of the main argument is set to %V4L2_SUBDEV_FORMAT_TRY. For
  605. * %V4L2_SUBDEV_FORMAT_ACTIVE it is safe to pass %NULL.
  606. */
  607. struct v4l2_subdev_pad_config {
  608. struct v4l2_mbus_framefmt try_fmt;
  609. struct v4l2_rect try_crop;
  610. struct v4l2_rect try_compose;
  611. };
  612. /**
  613. * struct v4l2_subdev_pad_ops - v4l2-subdev pad level operations
  614. *
  615. * @init_cfg: initialize the pad config to default values
  616. * @enum_mbus_code: callback for VIDIOC_SUBDEV_ENUM_MBUS_CODE() ioctl handler
  617. * code.
  618. * @enum_frame_size: callback for VIDIOC_SUBDEV_ENUM_FRAME_SIZE() ioctl handler
  619. * code.
  620. *
  621. * @enum_frame_interval: callback for VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL() ioctl
  622. * handler code.
  623. *
  624. * @get_fmt: callback for VIDIOC_SUBDEV_G_FMT() ioctl handler code.
  625. *
  626. * @set_fmt: callback for VIDIOC_SUBDEV_S_FMT() ioctl handler code.
  627. *
  628. * @get_selection: callback for VIDIOC_SUBDEV_G_SELECTION() ioctl handler code.
  629. *
  630. * @set_selection: callback for VIDIOC_SUBDEV_S_SELECTION() ioctl handler code.
  631. *
  632. * @get_edid: callback for VIDIOC_SUBDEV_G_EDID() ioctl handler code.
  633. *
  634. * @set_edid: callback for VIDIOC_SUBDEV_S_EDID() ioctl handler code.
  635. *
  636. * @dv_timings_cap: callback for VIDIOC_SUBDEV_DV_TIMINGS_CAP() ioctl handler
  637. * code.
  638. *
  639. * @enum_dv_timings: callback for VIDIOC_SUBDEV_ENUM_DV_TIMINGS() ioctl handler
  640. * code.
  641. *
  642. * @link_validate: used by the media controller code to check if the links
  643. * that belongs to a pipeline can be used for stream.
  644. *
  645. * @get_frame_desc: get the current low level media bus frame parameters.
  646. *
  647. * @set_frame_desc: set the low level media bus frame parameters, @fd array
  648. * may be adjusted by the subdev driver to device capabilities.
  649. */
  650. struct v4l2_subdev_pad_ops {
  651. int (*init_cfg)(struct v4l2_subdev *sd,
  652. struct v4l2_subdev_pad_config *cfg);
  653. int (*enum_mbus_code)(struct v4l2_subdev *sd,
  654. struct v4l2_subdev_pad_config *cfg,
  655. struct v4l2_subdev_mbus_code_enum *code);
  656. int (*enum_frame_size)(struct v4l2_subdev *sd,
  657. struct v4l2_subdev_pad_config *cfg,
  658. struct v4l2_subdev_frame_size_enum *fse);
  659. int (*enum_frame_interval)(struct v4l2_subdev *sd,
  660. struct v4l2_subdev_pad_config *cfg,
  661. struct v4l2_subdev_frame_interval_enum *fie);
  662. int (*get_fmt)(struct v4l2_subdev *sd,
  663. struct v4l2_subdev_pad_config *cfg,
  664. struct v4l2_subdev_format *format);
  665. int (*set_fmt)(struct v4l2_subdev *sd,
  666. struct v4l2_subdev_pad_config *cfg,
  667. struct v4l2_subdev_format *format);
  668. int (*get_selection)(struct v4l2_subdev *sd,
  669. struct v4l2_subdev_pad_config *cfg,
  670. struct v4l2_subdev_selection *sel);
  671. int (*set_selection)(struct v4l2_subdev *sd,
  672. struct v4l2_subdev_pad_config *cfg,
  673. struct v4l2_subdev_selection *sel);
  674. int (*get_edid)(struct v4l2_subdev *sd, struct v4l2_edid *edid);
  675. int (*set_edid)(struct v4l2_subdev *sd, struct v4l2_edid *edid);
  676. int (*dv_timings_cap)(struct v4l2_subdev *sd,
  677. struct v4l2_dv_timings_cap *cap);
  678. int (*enum_dv_timings)(struct v4l2_subdev *sd,
  679. struct v4l2_enum_dv_timings *timings);
  680. #ifdef CONFIG_MEDIA_CONTROLLER
  681. int (*link_validate)(struct v4l2_subdev *sd, struct media_link *link,
  682. struct v4l2_subdev_format *source_fmt,
  683. struct v4l2_subdev_format *sink_fmt);
  684. #endif /* CONFIG_MEDIA_CONTROLLER */
  685. int (*get_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
  686. struct v4l2_mbus_frame_desc *fd);
  687. int (*set_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
  688. struct v4l2_mbus_frame_desc *fd);
  689. };
  690. /**
  691. * struct v4l2_subdev_ops - Subdev operations
  692. *
  693. * @core: pointer to &struct v4l2_subdev_core_ops. Can be %NULL
  694. * @tuner: pointer to &struct v4l2_subdev_tuner_ops. Can be %NULL
  695. * @audio: pointer to &struct v4l2_subdev_audio_ops. Can be %NULL
  696. * @video: pointer to &struct v4l2_subdev_video_ops. Can be %NULL
  697. * @vbi: pointer to &struct v4l2_subdev_vbi_ops. Can be %NULL
  698. * @ir: pointer to &struct v4l2_subdev_ir_ops. Can be %NULL
  699. * @sensor: pointer to &struct v4l2_subdev_sensor_ops. Can be %NULL
  700. * @pad: pointer to &struct v4l2_subdev_pad_ops. Can be %NULL
  701. */
  702. struct v4l2_subdev_ops {
  703. const struct v4l2_subdev_core_ops *core;
  704. const struct v4l2_subdev_tuner_ops *tuner;
  705. const struct v4l2_subdev_audio_ops *audio;
  706. const struct v4l2_subdev_video_ops *video;
  707. const struct v4l2_subdev_vbi_ops *vbi;
  708. const struct v4l2_subdev_ir_ops *ir;
  709. const struct v4l2_subdev_sensor_ops *sensor;
  710. const struct v4l2_subdev_pad_ops *pad;
  711. };
  712. /**
  713. * struct v4l2_subdev_internal_ops - V4L2 subdev internal ops
  714. *
  715. * @registered: called when this subdev is registered. When called the v4l2_dev
  716. * field is set to the correct v4l2_device.
  717. *
  718. * @unregistered: called when this subdev is unregistered. When called the
  719. * v4l2_dev field is still set to the correct v4l2_device.
  720. *
  721. * @open: called when the subdev device node is opened by an application.
  722. *
  723. * @close: called when the subdev device node is closed.
  724. *
  725. * .. note::
  726. * Never call this from drivers, only the v4l2 framework can call
  727. * these ops.
  728. */
  729. struct v4l2_subdev_internal_ops {
  730. int (*registered)(struct v4l2_subdev *sd);
  731. void (*unregistered)(struct v4l2_subdev *sd);
  732. int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
  733. int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
  734. };
  735. #define V4L2_SUBDEV_NAME_SIZE 32
  736. /* Set this flag if this subdev is a i2c device. */
  737. #define V4L2_SUBDEV_FL_IS_I2C (1U << 0)
  738. /* Set this flag if this subdev is a spi device. */
  739. #define V4L2_SUBDEV_FL_IS_SPI (1U << 1)
  740. /* Set this flag if this subdev needs a device node. */
  741. #define V4L2_SUBDEV_FL_HAS_DEVNODE (1U << 2)
  742. /* Set this flag if this subdev generates events. */
  743. #define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
  744. struct regulator_bulk_data;
  745. /**
  746. * struct v4l2_subdev_platform_data - regulators config struct
  747. *
  748. * @regulators: Optional regulators used to power on/off the subdevice
  749. * @num_regulators: Number of regululators
  750. * @host_priv: Per-subdevice data, specific for a certain video host device
  751. */
  752. struct v4l2_subdev_platform_data {
  753. struct regulator_bulk_data *regulators;
  754. int num_regulators;
  755. void *host_priv;
  756. };
  757. /**
  758. * struct v4l2_subdev - describes a V4L2 sub-device
  759. *
  760. * @entity: pointer to &struct media_entity
  761. * @list: List of sub-devices
  762. * @owner: The owner is the same as the driver's &struct device owner.
  763. * @owner_v4l2_dev: true if the &sd->owner matches the owner of @v4l2_dev->dev
  764. * owner. Initialized by v4l2_device_register_subdev().
  765. * @flags: subdev flags. Can be:
  766. * %V4L2_SUBDEV_FL_IS_I2C - Set this flag if this subdev is a i2c device;
  767. * %V4L2_SUBDEV_FL_IS_SPI - Set this flag if this subdev is a spi device;
  768. * %V4L2_SUBDEV_FL_HAS_DEVNODE - Set this flag if this subdev needs a
  769. * device node;
  770. * %V4L2_SUBDEV_FL_HAS_EVENTS - Set this flag if this subdev generates
  771. * events.
  772. *
  773. * @v4l2_dev: pointer to struct &v4l2_device
  774. * @ops: pointer to struct &v4l2_subdev_ops
  775. * @internal_ops: pointer to struct &v4l2_subdev_internal_ops.
  776. * Never call these internal ops from within a driver!
  777. * @ctrl_handler: The control handler of this subdev. May be NULL.
  778. * @name: Name of the sub-device. Please notice that the name must be unique.
  779. * @grp_id: can be used to group similar subdevs. Value is driver-specific
  780. * @dev_priv: pointer to private data
  781. * @host_priv: pointer to private data used by the device where the subdev
  782. * is attached.
  783. * @devnode: subdev device node
  784. * @dev: pointer to the physical device, if any
  785. * @fwnode: The fwnode_handle of the subdev, usually the same as
  786. * either dev->of_node->fwnode or dev->fwnode (whichever is non-NULL).
  787. * @async_list: Links this subdev to a global subdev_list or @notifier->done
  788. * list.
  789. * @asd: Pointer to respective &struct v4l2_async_subdev.
  790. * @notifier: Pointer to the managing notifier.
  791. * @subdev_notifier: A sub-device notifier implicitly registered for the sub-
  792. * device using v4l2_device_register_sensor_subdev().
  793. * @pdata: common part of subdevice platform data
  794. *
  795. * Each instance of a subdev driver should create this struct, either
  796. * stand-alone or embedded in a larger struct.
  797. *
  798. * This structure should be initialized by v4l2_subdev_init() or one of
  799. * its variants: v4l2_spi_subdev_init(), v4l2_i2c_subdev_init().
  800. */
  801. struct v4l2_subdev {
  802. #if defined(CONFIG_MEDIA_CONTROLLER)
  803. struct media_entity entity;
  804. #endif
  805. struct list_head list;
  806. struct module *owner;
  807. bool owner_v4l2_dev;
  808. u32 flags;
  809. struct v4l2_device *v4l2_dev;
  810. const struct v4l2_subdev_ops *ops;
  811. const struct v4l2_subdev_internal_ops *internal_ops;
  812. struct v4l2_ctrl_handler *ctrl_handler;
  813. char name[V4L2_SUBDEV_NAME_SIZE];
  814. u32 grp_id;
  815. void *dev_priv;
  816. void *host_priv;
  817. struct video_device *devnode;
  818. struct device *dev;
  819. struct fwnode_handle *fwnode;
  820. struct list_head async_list;
  821. struct v4l2_async_subdev *asd;
  822. struct v4l2_async_notifier *notifier;
  823. struct v4l2_async_notifier *subdev_notifier;
  824. struct v4l2_subdev_platform_data *pdata;
  825. };
  826. /**
  827. * media_entity_to_v4l2_subdev - Returns a &struct v4l2_subdev from
  828. * the &struct media_entity embedded in it.
  829. *
  830. * @ent: pointer to &struct media_entity.
  831. */
  832. #define media_entity_to_v4l2_subdev(ent) \
  833. ({ \
  834. typeof(ent) __me_sd_ent = (ent); \
  835. \
  836. __me_sd_ent ? \
  837. container_of(__me_sd_ent, struct v4l2_subdev, entity) : \
  838. NULL; \
  839. })
  840. /**
  841. * vdev_to_v4l2_subdev - Returns a &struct v4l2_subdev from
  842. * the &struct video_device embedded on it.
  843. *
  844. * @vdev: pointer to &struct video_device
  845. */
  846. #define vdev_to_v4l2_subdev(vdev) \
  847. ((struct v4l2_subdev *)video_get_drvdata(vdev))
  848. /**
  849. * struct v4l2_subdev_fh - Used for storing subdev information per file handle
  850. *
  851. * @vfh: pointer to &struct v4l2_fh
  852. * @pad: pointer to &struct v4l2_subdev_pad_config
  853. */
  854. struct v4l2_subdev_fh {
  855. struct v4l2_fh vfh;
  856. #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
  857. struct v4l2_subdev_pad_config *pad;
  858. #endif
  859. };
  860. /**
  861. * to_v4l2_subdev_fh - Returns a &struct v4l2_subdev_fh from
  862. * the &struct v4l2_fh embedded on it.
  863. *
  864. * @fh: pointer to &struct v4l2_fh
  865. */
  866. #define to_v4l2_subdev_fh(fh) \
  867. container_of(fh, struct v4l2_subdev_fh, vfh)
  868. #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
  869. /**
  870. * v4l2_subdev_get_try_format - ancillary routine to call
  871. * &struct v4l2_subdev_pad_config->try_fmt
  872. *
  873. * @sd: pointer to &struct v4l2_subdev
  874. * @cfg: pointer to &struct v4l2_subdev_pad_config array.
  875. * @pad: index of the pad in the @cfg array.
  876. */
  877. static inline struct v4l2_mbus_framefmt
  878. *v4l2_subdev_get_try_format(struct v4l2_subdev *sd,
  879. struct v4l2_subdev_pad_config *cfg,
  880. unsigned int pad)
  881. {
  882. if (WARN_ON(pad >= sd->entity.num_pads))
  883. pad = 0;
  884. return &cfg[pad].try_fmt;
  885. }
  886. /**
  887. * v4l2_subdev_get_try_crop - ancillary routine to call
  888. * &struct v4l2_subdev_pad_config->try_crop
  889. *
  890. * @sd: pointer to &struct v4l2_subdev
  891. * @cfg: pointer to &struct v4l2_subdev_pad_config array.
  892. * @pad: index of the pad in the @cfg array.
  893. */
  894. static inline struct v4l2_rect
  895. *v4l2_subdev_get_try_crop(struct v4l2_subdev *sd,
  896. struct v4l2_subdev_pad_config *cfg,
  897. unsigned int pad)
  898. {
  899. if (WARN_ON(pad >= sd->entity.num_pads))
  900. pad = 0;
  901. return &cfg[pad].try_crop;
  902. }
  903. /**
  904. * v4l2_subdev_get_try_crop - ancillary routine to call
  905. * &struct v4l2_subdev_pad_config->try_compose
  906. *
  907. * @sd: pointer to &struct v4l2_subdev
  908. * @cfg: pointer to &struct v4l2_subdev_pad_config array.
  909. * @pad: index of the pad in the @cfg array.
  910. */
  911. static inline struct v4l2_rect
  912. *v4l2_subdev_get_try_compose(struct v4l2_subdev *sd,
  913. struct v4l2_subdev_pad_config *cfg,
  914. unsigned int pad)
  915. {
  916. if (WARN_ON(pad >= sd->entity.num_pads))
  917. pad = 0;
  918. return &cfg[pad].try_compose;
  919. }
  920. #endif
  921. extern const struct v4l2_file_operations v4l2_subdev_fops;
  922. /**
  923. * v4l2_set_subdevdata - Sets V4L2 dev private device data
  924. *
  925. * @sd: pointer to &struct v4l2_subdev
  926. * @p: pointer to the private device data to be stored.
  927. */
  928. static inline void v4l2_set_subdevdata(struct v4l2_subdev *sd, void *p)
  929. {
  930. sd->dev_priv = p;
  931. }
  932. /**
  933. * v4l2_get_subdevdata - Gets V4L2 dev private device data
  934. *
  935. * @sd: pointer to &struct v4l2_subdev
  936. *
  937. * Returns the pointer to the private device data to be stored.
  938. */
  939. static inline void *v4l2_get_subdevdata(const struct v4l2_subdev *sd)
  940. {
  941. return sd->dev_priv;
  942. }
  943. /**
  944. * v4l2_set_subdev_hostdata - Sets V4L2 dev private host data
  945. *
  946. * @sd: pointer to &struct v4l2_subdev
  947. * @p: pointer to the private data to be stored.
  948. */
  949. static inline void v4l2_set_subdev_hostdata(struct v4l2_subdev *sd, void *p)
  950. {
  951. sd->host_priv = p;
  952. }
  953. /**
  954. * v4l2_get_subdev_hostdata - Gets V4L2 dev private data
  955. *
  956. * @sd: pointer to &struct v4l2_subdev
  957. *
  958. * Returns the pointer to the private host data to be stored.
  959. */
  960. static inline void *v4l2_get_subdev_hostdata(const struct v4l2_subdev *sd)
  961. {
  962. return sd->host_priv;
  963. }
  964. #ifdef CONFIG_MEDIA_CONTROLLER
  965. /**
  966. * v4l2_subdev_link_validate_default - validates a media link
  967. *
  968. * @sd: pointer to &struct v4l2_subdev
  969. * @link: pointer to &struct media_link
  970. * @source_fmt: pointer to &struct v4l2_subdev_format
  971. * @sink_fmt: pointer to &struct v4l2_subdev_format
  972. *
  973. * This function ensures that width, height and the media bus pixel
  974. * code are equal on both source and sink of the link.
  975. */
  976. int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
  977. struct media_link *link,
  978. struct v4l2_subdev_format *source_fmt,
  979. struct v4l2_subdev_format *sink_fmt);
  980. /**
  981. * v4l2_subdev_link_validate - validates a media link
  982. *
  983. * @link: pointer to &struct media_link
  984. *
  985. * This function calls the subdev's link_validate ops to validate
  986. * if a media link is valid for streaming. It also internally
  987. * calls v4l2_subdev_link_validate_default() to ensure that
  988. * width, height and the media bus pixel code are equal on both
  989. * source and sink of the link.
  990. */
  991. int v4l2_subdev_link_validate(struct media_link *link);
  992. /**
  993. * v4l2_subdev_alloc_pad_config - Allocates memory for pad config
  994. *
  995. * @sd: pointer to struct v4l2_subdev
  996. */
  997. struct
  998. v4l2_subdev_pad_config *v4l2_subdev_alloc_pad_config(struct v4l2_subdev *sd);
  999. /**
  1000. * v4l2_subdev_free_pad_config - Frees memory allocated by
  1001. * v4l2_subdev_alloc_pad_config().
  1002. *
  1003. * @cfg: pointer to &struct v4l2_subdev_pad_config
  1004. */
  1005. void v4l2_subdev_free_pad_config(struct v4l2_subdev_pad_config *cfg);
  1006. #endif /* CONFIG_MEDIA_CONTROLLER */
  1007. /**
  1008. * v4l2_subdev_init - initializes the sub-device struct
  1009. *
  1010. * @sd: pointer to the &struct v4l2_subdev to be initialized
  1011. * @ops: pointer to &struct v4l2_subdev_ops.
  1012. */
  1013. void v4l2_subdev_init(struct v4l2_subdev *sd,
  1014. const struct v4l2_subdev_ops *ops);
  1015. /**
  1016. * v4l2_subdev_call - call an operation of a v4l2_subdev.
  1017. *
  1018. * @sd: pointer to the &struct v4l2_subdev
  1019. * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
  1020. * Each element there groups a set of callbacks functions.
  1021. * @f: callback function that will be called if @cond matches.
  1022. * The callback functions are defined in groups, according to
  1023. * each element at &struct v4l2_subdev_ops.
  1024. * @args...: arguments for @f.
  1025. *
  1026. * Example: err = v4l2_subdev_call(sd, video, s_std, norm);
  1027. */
  1028. #define v4l2_subdev_call(sd, o, f, args...) \
  1029. ({ \
  1030. int __result; \
  1031. if (!(sd)) \
  1032. __result = -ENODEV; \
  1033. else if (!((sd)->ops->o && (sd)->ops->o->f)) \
  1034. __result = -ENOIOCTLCMD; \
  1035. else \
  1036. __result = (sd)->ops->o->f((sd), ##args); \
  1037. __result; \
  1038. })
  1039. /**
  1040. * v4l2_subdev_has_op - Checks if a subdev defines a certain operation.
  1041. *
  1042. * @sd: pointer to the &struct v4l2_subdev
  1043. * @o: The group of callback functions in &struct v4l2_subdev_ops
  1044. * which @f is a part of.
  1045. * @f: callback function to be checked for its existence.
  1046. */
  1047. #define v4l2_subdev_has_op(sd, o, f) \
  1048. ((sd)->ops->o && (sd)->ops->o->f)
  1049. /**
  1050. * v4l2_subdev_notify_event() - Delivers event notification for subdevice
  1051. * @sd: The subdev for which to deliver the event
  1052. * @ev: The event to deliver
  1053. *
  1054. * Will deliver the specified event to all userspace event listeners which are
  1055. * subscribed to the v42l subdev event queue as well as to the bridge driver
  1056. * using the notify callback. The notification type for the notify callback
  1057. * will be %V4L2_DEVICE_NOTIFY_EVENT.
  1058. */
  1059. void v4l2_subdev_notify_event(struct v4l2_subdev *sd,
  1060. const struct v4l2_event *ev);
  1061. #endif