v4l2-subdev.h 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * V4L2 sub-device support header.
  4. *
  5. * Copyright (C) 2008 Hans Verkuil <[email protected]>
  6. */
  7. #ifndef _V4L2_SUBDEV_H
  8. #define _V4L2_SUBDEV_H
  9. #include <linux/types.h>
  10. #include <linux/v4l2-subdev.h>
  11. #include <media/media-entity.h>
  12. #include <media/v4l2-async.h>
  13. #include <media/v4l2-common.h>
  14. #include <media/v4l2-dev.h>
  15. #include <media/v4l2-fh.h>
  16. #include <media/v4l2-mediabus.h>
  17. /* generic v4l2_device notify callback notification values */
  18. #define V4L2_SUBDEV_IR_RX_NOTIFY _IOW('v', 0, u32)
  19. #define V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ 0x00000001
  20. #define V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED 0x00000002
  21. #define V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN 0x00000004
  22. #define V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN 0x00000008
  23. #define V4L2_SUBDEV_IR_TX_NOTIFY _IOW('v', 1, u32)
  24. #define V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ 0x00000001
  25. #define V4L2_DEVICE_NOTIFY_EVENT _IOW('v', 2, struct v4l2_event)
  26. struct v4l2_device;
  27. struct v4l2_ctrl_handler;
  28. struct v4l2_event;
  29. struct v4l2_event_subscription;
  30. struct v4l2_fh;
  31. struct v4l2_subdev;
  32. struct v4l2_subdev_fh;
  33. struct tuner_setup;
  34. struct v4l2_mbus_frame_desc;
  35. /**
  36. * struct v4l2_decode_vbi_line - used to decode_vbi_line
  37. *
  38. * @is_second_field: Set to 0 for the first (odd) field;
  39. * set to 1 for the second (even) field.
  40. * @p: Pointer to the sliced VBI data from the decoder. On exit, points to
  41. * the start of the payload.
  42. * @line: Line number of the sliced VBI data (1-23)
  43. * @type: VBI service type (V4L2_SLICED_*). 0 if no service found
  44. */
  45. struct v4l2_decode_vbi_line {
  46. u32 is_second_field;
  47. u8 *p;
  48. u32 line;
  49. u32 type;
  50. };
  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. *
  56. * Usually these devices are controlled through an i2c bus, but other buses
  57. * may also be used.
  58. *
  59. * The v4l2_subdev struct provides a way of accessing these devices in a
  60. * generic manner. Most operations that these sub-devices support fall in
  61. * a few categories: core ops, audio ops, video ops and tuner ops.
  62. *
  63. * More categories can be added if needed, although this should remain a
  64. * limited set (no more than approx. 8 categories).
  65. *
  66. * Each category has its own set of ops that subdev drivers can implement.
  67. *
  68. * A subdev driver can leave the pointer to the category ops NULL if
  69. * it does not implement them (e.g. an audio subdev will generally not
  70. * implement the video category ops). The exception is the core category:
  71. * this must always be present.
  72. *
  73. * These ops are all used internally so it is no problem to change, remove
  74. * or add ops or move ops from one to another category. Currently these
  75. * ops are based on the original ioctls, but since ops are not limited to
  76. * one argument there is room for improvement here once all i2c subdev
  77. * drivers are converted to use these ops.
  78. */
  79. /*
  80. * Core ops: it is highly recommended to implement at least these ops:
  81. *
  82. * log_status
  83. * g_register
  84. * s_register
  85. *
  86. * This provides basic debugging support.
  87. *
  88. * The ioctl ops is meant for generic ioctl-like commands. Depending on
  89. * the use-case it might be better to use subdev-specific ops (currently
  90. * not yet implemented) since ops provide proper type-checking.
  91. */
  92. /**
  93. * enum v4l2_subdev_io_pin_bits - Subdevice external IO pin configuration
  94. * bits
  95. *
  96. * @V4L2_SUBDEV_IO_PIN_DISABLE: disables a pin config. ENABLE assumed.
  97. * @V4L2_SUBDEV_IO_PIN_OUTPUT: set it if pin is an output.
  98. * @V4L2_SUBDEV_IO_PIN_INPUT: set it if pin is an input.
  99. * @V4L2_SUBDEV_IO_PIN_SET_VALUE: to set the output value via
  100. * &struct v4l2_subdev_io_pin_config->value.
  101. * @V4L2_SUBDEV_IO_PIN_ACTIVE_LOW: pin active is bit 0.
  102. * Otherwise, ACTIVE HIGH is assumed.
  103. */
  104. enum v4l2_subdev_io_pin_bits {
  105. V4L2_SUBDEV_IO_PIN_DISABLE = 0,
  106. V4L2_SUBDEV_IO_PIN_OUTPUT = 1,
  107. V4L2_SUBDEV_IO_PIN_INPUT = 2,
  108. V4L2_SUBDEV_IO_PIN_SET_VALUE = 3,
  109. V4L2_SUBDEV_IO_PIN_ACTIVE_LOW = 4,
  110. };
  111. /**
  112. * struct v4l2_subdev_io_pin_config - Subdevice external IO pin configuration
  113. *
  114. * @flags: bitmask with flags for this pin's config, whose bits are defined by
  115. * &enum v4l2_subdev_io_pin_bits.
  116. * @pin: Chip external IO pin to configure
  117. * @function: Internal signal pad/function to route to IO pin
  118. * @value: Initial value for pin - e.g. GPIO output value
  119. * @strength: Pin drive strength
  120. */
  121. struct v4l2_subdev_io_pin_config {
  122. u32 flags;
  123. u8 pin;
  124. u8 function;
  125. u8 value;
  126. u8 strength;
  127. };
  128. /**
  129. * struct v4l2_subdev_core_ops - Define core ops callbacks for subdevs
  130. *
  131. * @log_status: callback for VIDIOC_LOG_STATUS() ioctl handler code.
  132. *
  133. * @s_io_pin_config: configure one or more chip I/O pins for chips that
  134. * multiplex different internal signal pads out to IO pins. This function
  135. * takes a pointer to an array of 'n' pin configuration entries, one for
  136. * each pin being configured. This function could be called at times
  137. * other than just subdevice initialization.
  138. *
  139. * @init: initialize the sensor registers to some sort of reasonable default
  140. * values. Do not use for new drivers and should be removed in existing
  141. * drivers.
  142. *
  143. * @load_fw: load firmware.
  144. *
  145. * @reset: generic reset command. The argument selects which subsystems to
  146. * reset. Passing 0 will always reset the whole chip. Do not use for new
  147. * drivers without discussing this first on the linux-media mailinglist.
  148. * There should be no reason normally to reset a device.
  149. *
  150. * @s_gpio: set GPIO pins. Very simple right now, might need to be extended with
  151. * a direction argument if needed.
  152. *
  153. * @command: called by in-kernel drivers in order to call functions internal
  154. * to subdev drivers driver that have a separate callback.
  155. *
  156. * @ioctl: called at the end of ioctl() syscall handler at the V4L2 core.
  157. * used to provide support for private ioctls used on the driver.
  158. *
  159. * @compat_ioctl32: called when a 32 bits application uses a 64 bits Kernel,
  160. * in order to fix data passed from/to userspace.
  161. *
  162. * @g_register: callback for VIDIOC_DBG_G_REGISTER() ioctl handler code.
  163. *
  164. * @s_register: callback for VIDIOC_DBG_S_REGISTER() ioctl handler code.
  165. *
  166. * @s_power: puts subdevice in power saving mode (on == 0) or normal operation
  167. * mode (on == 1).
  168. *
  169. * @interrupt_service_routine: Called by the bridge chip's interrupt service
  170. * handler, when an interrupt status has be raised due to this subdev,
  171. * so that this subdev can handle the details. It may schedule work to be
  172. * performed later. It must not sleep. **Called from an IRQ context**.
  173. *
  174. * @subscribe_event: used by the drivers to request the control framework that
  175. * for it to be warned when the value of a control changes.
  176. *
  177. * @unsubscribe_event: remove event subscription from the control framework.
  178. */
  179. struct v4l2_subdev_core_ops {
  180. int (*log_status)(struct v4l2_subdev *sd);
  181. int (*s_io_pin_config)(struct v4l2_subdev *sd, size_t n,
  182. struct v4l2_subdev_io_pin_config *pincfg);
  183. int (*init)(struct v4l2_subdev *sd, u32 val);
  184. int (*load_fw)(struct v4l2_subdev *sd);
  185. int (*reset)(struct v4l2_subdev *sd, u32 val);
  186. int (*s_gpio)(struct v4l2_subdev *sd, u32 val);
  187. long (*command)(struct v4l2_subdev *sd, unsigned int cmd, void *arg);
  188. long (*ioctl)(struct v4l2_subdev *sd, unsigned int cmd, void *arg);
  189. #ifdef CONFIG_COMPAT
  190. long (*compat_ioctl32)(struct v4l2_subdev *sd, unsigned int cmd,
  191. unsigned long arg);
  192. #endif
  193. #ifdef CONFIG_VIDEO_ADV_DEBUG
  194. int (*g_register)(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg);
  195. int (*s_register)(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg);
  196. #endif
  197. int (*s_power)(struct v4l2_subdev *sd, int on);
  198. int (*interrupt_service_routine)(struct v4l2_subdev *sd,
  199. u32 status, bool *handled);
  200. int (*subscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  201. struct v4l2_event_subscription *sub);
  202. int (*unsubscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  203. struct v4l2_event_subscription *sub);
  204. };
  205. /**
  206. * struct v4l2_subdev_tuner_ops - Callbacks used when v4l device was opened
  207. * in radio mode.
  208. *
  209. * @standby: puts the tuner in standby mode. It will be woken up
  210. * automatically the next time it is used.
  211. *
  212. * @s_radio: callback that switches the tuner to radio mode.
  213. * drivers should explicitly call it when a tuner ops should
  214. * operate on radio mode, before being able to handle it.
  215. * Used on devices that have both AM/FM radio receiver and TV.
  216. *
  217. * @s_frequency: callback for VIDIOC_S_FREQUENCY() ioctl handler code.
  218. *
  219. * @g_frequency: callback for VIDIOC_G_FREQUENCY() ioctl handler code.
  220. * freq->type must be filled in. Normally done by video_ioctl2()
  221. * or the bridge driver.
  222. *
  223. * @enum_freq_bands: callback for VIDIOC_ENUM_FREQ_BANDS() ioctl handler code.
  224. *
  225. * @g_tuner: callback for VIDIOC_G_TUNER() ioctl handler code.
  226. *
  227. * @s_tuner: callback for VIDIOC_S_TUNER() ioctl handler code. @vt->type must be
  228. * filled in. Normally done by video_ioctl2 or the
  229. * bridge driver.
  230. *
  231. * @g_modulator: callback for VIDIOC_G_MODULATOR() ioctl handler code.
  232. *
  233. * @s_modulator: callback for VIDIOC_S_MODULATOR() ioctl handler code.
  234. *
  235. * @s_type_addr: sets tuner type and its I2C addr.
  236. *
  237. * @s_config: sets tda9887 specific stuff, like port1, port2 and qss
  238. *
  239. * .. note::
  240. *
  241. * On devices that have both AM/FM and TV, it is up to the driver
  242. * to explicitly call s_radio when the tuner should be switched to
  243. * radio mode, before handling other &struct v4l2_subdev_tuner_ops
  244. * that would require it. An example of such usage is::
  245. *
  246. * static void s_frequency(void *priv, const struct v4l2_frequency *f)
  247. * {
  248. * ...
  249. * if (f.type == V4L2_TUNER_RADIO)
  250. * v4l2_device_call_all(v4l2_dev, 0, tuner, s_radio);
  251. * ...
  252. * v4l2_device_call_all(v4l2_dev, 0, tuner, s_frequency);
  253. * }
  254. */
  255. struct v4l2_subdev_tuner_ops {
  256. int (*standby)(struct v4l2_subdev *sd);
  257. int (*s_radio)(struct v4l2_subdev *sd);
  258. int (*s_frequency)(struct v4l2_subdev *sd, const struct v4l2_frequency *freq);
  259. int (*g_frequency)(struct v4l2_subdev *sd, struct v4l2_frequency *freq);
  260. int (*enum_freq_bands)(struct v4l2_subdev *sd, struct v4l2_frequency_band *band);
  261. int (*g_tuner)(struct v4l2_subdev *sd, struct v4l2_tuner *vt);
  262. int (*s_tuner)(struct v4l2_subdev *sd, const struct v4l2_tuner *vt);
  263. int (*g_modulator)(struct v4l2_subdev *sd, struct v4l2_modulator *vm);
  264. int (*s_modulator)(struct v4l2_subdev *sd, const struct v4l2_modulator *vm);
  265. int (*s_type_addr)(struct v4l2_subdev *sd, struct tuner_setup *type);
  266. int (*s_config)(struct v4l2_subdev *sd, const struct v4l2_priv_tun_config *config);
  267. };
  268. /**
  269. * struct v4l2_subdev_audio_ops - Callbacks used for audio-related settings
  270. *
  271. * @s_clock_freq: set the frequency (in Hz) of the audio clock output.
  272. * Used to slave an audio processor to the video decoder, ensuring that
  273. * audio and video remain synchronized. Usual values for the frequency
  274. * are 48000, 44100 or 32000 Hz. If the frequency is not supported, then
  275. * -EINVAL is returned.
  276. *
  277. * @s_i2s_clock_freq: sets I2S speed in bps. This is used to provide a standard
  278. * way to select I2S clock used by driving digital audio streams at some
  279. * board designs. Usual values for the frequency are 1024000 and 2048000.
  280. * If the frequency is not supported, then %-EINVAL is returned.
  281. *
  282. * @s_routing: used to define the input and/or output pins of an audio chip,
  283. * and any additional configuration data.
  284. * Never attempt to use user-level input IDs (e.g. Composite, S-Video,
  285. * Tuner) at this level. An i2c device shouldn't know about whether an
  286. * input pin is connected to a Composite connector, become on another
  287. * board or platform it might be connected to something else entirely.
  288. * The calling driver is responsible for mapping a user-level input to
  289. * the right pins on the i2c device.
  290. *
  291. * @s_stream: used to notify the audio code that stream will start or has
  292. * stopped.
  293. */
  294. struct v4l2_subdev_audio_ops {
  295. int (*s_clock_freq)(struct v4l2_subdev *sd, u32 freq);
  296. int (*s_i2s_clock_freq)(struct v4l2_subdev *sd, u32 freq);
  297. int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
  298. int (*s_stream)(struct v4l2_subdev *sd, int enable);
  299. };
  300. /**
  301. * struct v4l2_mbus_frame_desc_entry_csi2
  302. *
  303. * @vc: CSI-2 virtual channel
  304. * @dt: CSI-2 data type ID
  305. */
  306. struct v4l2_mbus_frame_desc_entry_csi2 {
  307. u8 vc;
  308. u8 dt;
  309. };
  310. /**
  311. * enum v4l2_mbus_frame_desc_flags - media bus frame description flags
  312. *
  313. * @V4L2_MBUS_FRAME_DESC_FL_LEN_MAX:
  314. * Indicates that &struct v4l2_mbus_frame_desc_entry->length field
  315. * specifies maximum data length.
  316. * @V4L2_MBUS_FRAME_DESC_FL_BLOB:
  317. * Indicates that the format does not have line offsets, i.e.
  318. * the receiver should use 1D DMA.
  319. */
  320. enum v4l2_mbus_frame_desc_flags {
  321. V4L2_MBUS_FRAME_DESC_FL_LEN_MAX = BIT(0),
  322. V4L2_MBUS_FRAME_DESC_FL_BLOB = BIT(1),
  323. };
  324. /**
  325. * struct v4l2_mbus_frame_desc_entry - media bus frame description structure
  326. *
  327. * @flags: bitmask flags, as defined by &enum v4l2_mbus_frame_desc_flags.
  328. * @pixelcode: media bus pixel code, valid if @flags
  329. * %FRAME_DESC_FL_BLOB is not set.
  330. * @length: number of octets per frame, valid if @flags
  331. * %V4L2_MBUS_FRAME_DESC_FL_LEN_MAX is set.
  332. * @bus: Bus-specific frame descriptor parameters
  333. * @bus.csi2: CSI-2-specific bus configuration
  334. */
  335. struct v4l2_mbus_frame_desc_entry {
  336. enum v4l2_mbus_frame_desc_flags flags;
  337. u32 pixelcode;
  338. u32 length;
  339. union {
  340. struct v4l2_mbus_frame_desc_entry_csi2 csi2;
  341. } bus;
  342. };
  343. /*
  344. * If this number is too small, it should be dropped altogether and the
  345. * API switched to a dynamic number of frame descriptor entries.
  346. */
  347. #define V4L2_FRAME_DESC_ENTRY_MAX 8
  348. /**
  349. * enum v4l2_mbus_frame_desc_type - media bus frame description type
  350. *
  351. * @V4L2_MBUS_FRAME_DESC_TYPE_UNDEFINED:
  352. * Undefined frame desc type. Drivers should not use this, it is
  353. * for backwards compatibility.
  354. * @V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL:
  355. * Parallel media bus.
  356. * @V4L2_MBUS_FRAME_DESC_TYPE_CSI2:
  357. * CSI-2 media bus. Frame desc parameters must be set in
  358. * &struct v4l2_mbus_frame_desc_entry->csi2.
  359. */
  360. enum v4l2_mbus_frame_desc_type {
  361. V4L2_MBUS_FRAME_DESC_TYPE_UNDEFINED = 0,
  362. V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL,
  363. V4L2_MBUS_FRAME_DESC_TYPE_CSI2,
  364. };
  365. /**
  366. * struct v4l2_mbus_frame_desc - media bus data frame description
  367. * @type: type of the bus (enum v4l2_mbus_frame_desc_type)
  368. * @entry: frame descriptors array
  369. * @num_entries: number of entries in @entry array
  370. */
  371. struct v4l2_mbus_frame_desc {
  372. enum v4l2_mbus_frame_desc_type type;
  373. struct v4l2_mbus_frame_desc_entry entry[V4L2_FRAME_DESC_ENTRY_MAX];
  374. unsigned short num_entries;
  375. };
  376. /**
  377. * enum v4l2_subdev_pre_streamon_flags - Flags for pre_streamon subdev core op
  378. *
  379. * @V4L2_SUBDEV_PRE_STREAMON_FL_MANUAL_LP: Set the transmitter to either LP-11
  380. * or LP-111 mode before call to s_stream().
  381. */
  382. enum v4l2_subdev_pre_streamon_flags {
  383. V4L2_SUBDEV_PRE_STREAMON_FL_MANUAL_LP = BIT(0),
  384. };
  385. /**
  386. * struct v4l2_subdev_video_ops - Callbacks used when v4l device was opened
  387. * in video mode.
  388. *
  389. * @s_routing: see s_routing in audio_ops, except this version is for video
  390. * devices.
  391. *
  392. * @s_crystal_freq: sets the frequency of the crystal used to generate the
  393. * clocks in Hz. An extra flags field allows device specific configuration
  394. * regarding clock frequency dividers, etc. If not used, then set flags
  395. * to 0. If the frequency is not supported, then -EINVAL is returned.
  396. *
  397. * @g_std: callback for VIDIOC_G_STD() ioctl handler code.
  398. *
  399. * @s_std: callback for VIDIOC_S_STD() ioctl handler code.
  400. *
  401. * @s_std_output: set v4l2_std_id for video OUTPUT devices. This is ignored by
  402. * video input devices.
  403. *
  404. * @g_std_output: get current standard for video OUTPUT devices. This is ignored
  405. * by video input devices.
  406. *
  407. * @querystd: callback for VIDIOC_QUERYSTD() ioctl handler code.
  408. *
  409. * @g_tvnorms: get &v4l2_std_id with all standards supported by the video
  410. * CAPTURE device. This is ignored by video output devices.
  411. *
  412. * @g_tvnorms_output: get v4l2_std_id with all standards supported by the video
  413. * OUTPUT device. This is ignored by video capture devices.
  414. *
  415. * @g_input_status: get input status. Same as the status field in the
  416. * &struct v4l2_input
  417. *
  418. * @s_stream: used to notify the driver that a video stream will start or has
  419. * stopped.
  420. *
  421. * @g_pixelaspect: callback to return the pixelaspect ratio.
  422. *
  423. * @g_frame_interval: callback for VIDIOC_SUBDEV_G_FRAME_INTERVAL()
  424. * ioctl handler code.
  425. *
  426. * @s_frame_interval: callback for VIDIOC_SUBDEV_S_FRAME_INTERVAL()
  427. * ioctl handler code.
  428. *
  429. * @s_dv_timings: Set custom dv timings in the sub device. This is used
  430. * when sub device is capable of setting detailed timing information
  431. * in the hardware to generate/detect the video signal.
  432. *
  433. * @g_dv_timings: Get custom dv timings in the sub device.
  434. *
  435. * @query_dv_timings: callback for VIDIOC_QUERY_DV_TIMINGS() ioctl handler code.
  436. *
  437. * @s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev
  438. * can adjust @size to a lower value and must not write more data to the
  439. * buffer starting at @data than the original value of @size.
  440. *
  441. * @pre_streamon: May be called before streaming is actually started, to help
  442. * initialising the bus. Current usage is to set a CSI-2 transmitter to
  443. * LP-11 or LP-111 mode before streaming. See &enum
  444. * v4l2_subdev_pre_streamon_flags.
  445. *
  446. * pre_streamon shall return error if it cannot perform the operation as
  447. * indicated by the flags argument. In particular, -EACCES indicates lack
  448. * of support for the operation. The caller shall call post_streamoff for
  449. * each successful call of pre_streamon.
  450. *
  451. * @post_streamoff: Called after streaming is stopped, but if and only if
  452. * pre_streamon was called earlier.
  453. */
  454. struct v4l2_subdev_video_ops {
  455. int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
  456. int (*s_crystal_freq)(struct v4l2_subdev *sd, u32 freq, u32 flags);
  457. int (*g_std)(struct v4l2_subdev *sd, v4l2_std_id *norm);
  458. int (*s_std)(struct v4l2_subdev *sd, v4l2_std_id norm);
  459. int (*s_std_output)(struct v4l2_subdev *sd, v4l2_std_id std);
  460. int (*g_std_output)(struct v4l2_subdev *sd, v4l2_std_id *std);
  461. int (*querystd)(struct v4l2_subdev *sd, v4l2_std_id *std);
  462. int (*g_tvnorms)(struct v4l2_subdev *sd, v4l2_std_id *std);
  463. int (*g_tvnorms_output)(struct v4l2_subdev *sd, v4l2_std_id *std);
  464. int (*g_input_status)(struct v4l2_subdev *sd, u32 *status);
  465. int (*s_stream)(struct v4l2_subdev *sd, int enable);
  466. int (*g_pixelaspect)(struct v4l2_subdev *sd, struct v4l2_fract *aspect);
  467. int (*g_frame_interval)(struct v4l2_subdev *sd,
  468. struct v4l2_subdev_frame_interval *interval);
  469. int (*s_frame_interval)(struct v4l2_subdev *sd,
  470. struct v4l2_subdev_frame_interval *interval);
  471. int (*s_dv_timings)(struct v4l2_subdev *sd,
  472. struct v4l2_dv_timings *timings);
  473. int (*g_dv_timings)(struct v4l2_subdev *sd,
  474. struct v4l2_dv_timings *timings);
  475. int (*query_dv_timings)(struct v4l2_subdev *sd,
  476. struct v4l2_dv_timings *timings);
  477. int (*s_rx_buffer)(struct v4l2_subdev *sd, void *buf,
  478. unsigned int *size);
  479. int (*pre_streamon)(struct v4l2_subdev *sd, u32 flags);
  480. int (*post_streamoff)(struct v4l2_subdev *sd);
  481. };
  482. /**
  483. * struct v4l2_subdev_vbi_ops - Callbacks used when v4l device was opened
  484. * in video mode via the vbi device node.
  485. *
  486. * @decode_vbi_line: video decoders that support sliced VBI need to implement
  487. * this ioctl. Field p of the &struct v4l2_decode_vbi_line is set to the
  488. * start of the VBI data that was generated by the decoder. The driver
  489. * then parses the sliced VBI data and sets the other fields in the
  490. * struct accordingly. The pointer p is updated to point to the start of
  491. * the payload which can be copied verbatim into the data field of the
  492. * &struct v4l2_sliced_vbi_data. If no valid VBI data was found, then the
  493. * type field is set to 0 on return.
  494. *
  495. * @s_vbi_data: used to generate VBI signals on a video signal.
  496. * &struct v4l2_sliced_vbi_data is filled with the data packets that
  497. * should be output. Note that if you set the line field to 0, then that
  498. * VBI signal is disabled. If no valid VBI data was found, then the type
  499. * field is set to 0 on return.
  500. *
  501. * @g_vbi_data: used to obtain the sliced VBI packet from a readback register.
  502. * Not all video decoders support this. If no data is available because
  503. * the readback register contains invalid or erroneous data %-EIO is
  504. * returned. Note that you must fill in the 'id' member and the 'field'
  505. * member (to determine whether CC data from the first or second field
  506. * should be obtained).
  507. *
  508. * @g_sliced_vbi_cap: callback for VIDIOC_G_SLICED_VBI_CAP() ioctl handler
  509. * code.
  510. *
  511. * @s_raw_fmt: setup the video encoder/decoder for raw VBI.
  512. *
  513. * @g_sliced_fmt: retrieve the current sliced VBI settings.
  514. *
  515. * @s_sliced_fmt: setup the sliced VBI settings.
  516. */
  517. struct v4l2_subdev_vbi_ops {
  518. int (*decode_vbi_line)(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi_line);
  519. int (*s_vbi_data)(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *vbi_data);
  520. int (*g_vbi_data)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_data *vbi_data);
  521. int (*g_sliced_vbi_cap)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_cap *cap);
  522. int (*s_raw_fmt)(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt);
  523. int (*g_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
  524. int (*s_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
  525. };
  526. /**
  527. * struct v4l2_subdev_sensor_ops - v4l2-subdev sensor operations
  528. * @g_skip_top_lines: number of lines at the top of the image to be skipped.
  529. * This is needed for some sensors, which always corrupt
  530. * several top lines of the output image, or which send their
  531. * metadata in them.
  532. * @g_skip_frames: number of frames to skip at stream start. This is needed for
  533. * buggy sensors that generate faulty frames when they are
  534. * turned on.
  535. */
  536. struct v4l2_subdev_sensor_ops {
  537. int (*g_skip_top_lines)(struct v4l2_subdev *sd, u32 *lines);
  538. int (*g_skip_frames)(struct v4l2_subdev *sd, u32 *frames);
  539. };
  540. /**
  541. * enum v4l2_subdev_ir_mode- describes the type of IR supported
  542. *
  543. * @V4L2_SUBDEV_IR_MODE_PULSE_WIDTH: IR uses struct ir_raw_event records
  544. */
  545. enum v4l2_subdev_ir_mode {
  546. V4L2_SUBDEV_IR_MODE_PULSE_WIDTH,
  547. };
  548. /**
  549. * struct v4l2_subdev_ir_parameters - Parameters for IR TX or TX
  550. *
  551. * @bytes_per_data_element: bytes per data element of data in read or
  552. * write call.
  553. * @mode: IR mode as defined by &enum v4l2_subdev_ir_mode.
  554. * @enable: device is active if true
  555. * @interrupt_enable: IR interrupts are enabled if true
  556. * @shutdown: if true: set hardware to low/no power, false: normal mode
  557. *
  558. * @modulation: if true, it uses carrier, if false: baseband
  559. * @max_pulse_width: maximum pulse width in ns, valid only for baseband signal
  560. * @carrier_freq: carrier frequency in Hz, valid only for modulated signal
  561. * @duty_cycle: duty cycle percentage, valid only for modulated signal
  562. * @invert_level: invert signal level
  563. *
  564. * @invert_carrier_sense: Send 0/space as a carrier burst. used only in TX.
  565. *
  566. * @noise_filter_min_width: min time of a valid pulse, in ns. Used only for RX.
  567. * @carrier_range_lower: Lower carrier range, in Hz, valid only for modulated
  568. * signal. Used only for RX.
  569. * @carrier_range_upper: Upper carrier range, in Hz, valid only for modulated
  570. * signal. Used only for RX.
  571. * @resolution: The receive resolution, in ns . Used only for RX.
  572. */
  573. struct v4l2_subdev_ir_parameters {
  574. unsigned int bytes_per_data_element;
  575. enum v4l2_subdev_ir_mode mode;
  576. bool enable;
  577. bool interrupt_enable;
  578. bool shutdown;
  579. bool modulation;
  580. u32 max_pulse_width;
  581. unsigned int carrier_freq;
  582. unsigned int duty_cycle;
  583. bool invert_level;
  584. /* Tx only */
  585. bool invert_carrier_sense;
  586. /* Rx only */
  587. u32 noise_filter_min_width;
  588. unsigned int carrier_range_lower;
  589. unsigned int carrier_range_upper;
  590. u32 resolution;
  591. };
  592. /**
  593. * struct v4l2_subdev_ir_ops - operations for IR subdevices
  594. *
  595. * @rx_read: Reads received codes or pulse width data.
  596. * The semantics are similar to a non-blocking read() call.
  597. * @rx_g_parameters: Get the current operating parameters and state of
  598. * the IR receiver.
  599. * @rx_s_parameters: Set the current operating parameters and state of
  600. * the IR receiver. It is recommended to call
  601. * [rt]x_g_parameters first to fill out the current state, and only change
  602. * the fields that need to be changed. Upon return, the actual device
  603. * operating parameters and state will be returned. Note that hardware
  604. * limitations may prevent the actual settings from matching the requested
  605. * settings - e.g. an actual carrier setting of 35,904 Hz when 36,000 Hz
  606. * was requested. An exception is when the shutdown parameter is true.
  607. * The last used operational parameters will be returned, but the actual
  608. * state of the hardware be different to minimize power consumption and
  609. * processing when shutdown is true.
  610. *
  611. * @tx_write: Writes codes or pulse width data for transmission.
  612. * The semantics are similar to a non-blocking write() call.
  613. * @tx_g_parameters: Get the current operating parameters and state of
  614. * the IR transmitter.
  615. * @tx_s_parameters: Set the current operating parameters and state of
  616. * the IR transmitter. It is recommended to call
  617. * [rt]x_g_parameters first to fill out the current state, and only change
  618. * the fields that need to be changed. Upon return, the actual device
  619. * operating parameters and state will be returned. Note that hardware
  620. * limitations may prevent the actual settings from matching the requested
  621. * settings - e.g. an actual carrier setting of 35,904 Hz when 36,000 Hz
  622. * was requested. An exception is when the shutdown parameter is true.
  623. * The last used operational parameters will be returned, but the actual
  624. * state of the hardware be different to minimize power consumption and
  625. * processing when shutdown is true.
  626. */
  627. struct v4l2_subdev_ir_ops {
  628. /* Receiver */
  629. int (*rx_read)(struct v4l2_subdev *sd, u8 *buf, size_t count,
  630. ssize_t *num);
  631. int (*rx_g_parameters)(struct v4l2_subdev *sd,
  632. struct v4l2_subdev_ir_parameters *params);
  633. int (*rx_s_parameters)(struct v4l2_subdev *sd,
  634. struct v4l2_subdev_ir_parameters *params);
  635. /* Transmitter */
  636. int (*tx_write)(struct v4l2_subdev *sd, u8 *buf, size_t count,
  637. ssize_t *num);
  638. int (*tx_g_parameters)(struct v4l2_subdev *sd,
  639. struct v4l2_subdev_ir_parameters *params);
  640. int (*tx_s_parameters)(struct v4l2_subdev *sd,
  641. struct v4l2_subdev_ir_parameters *params);
  642. };
  643. /**
  644. * struct v4l2_subdev_pad_config - Used for storing subdev pad information.
  645. *
  646. * @try_fmt: &struct v4l2_mbus_framefmt
  647. * @try_crop: &struct v4l2_rect to be used for crop
  648. * @try_compose: &struct v4l2_rect to be used for compose
  649. *
  650. * This structure only needs to be passed to the pad op if the 'which' field
  651. * of the main argument is set to %V4L2_SUBDEV_FORMAT_TRY. For
  652. * %V4L2_SUBDEV_FORMAT_ACTIVE it is safe to pass %NULL.
  653. *
  654. * Note: This struct is also used in active state, and the 'try' prefix is
  655. * historical and to be removed.
  656. */
  657. struct v4l2_subdev_pad_config {
  658. struct v4l2_mbus_framefmt try_fmt;
  659. struct v4l2_rect try_crop;
  660. struct v4l2_rect try_compose;
  661. };
  662. /**
  663. * struct v4l2_subdev_state - Used for storing subdev state information.
  664. *
  665. * @_lock: default for 'lock'
  666. * @lock: mutex for the state. May be replaced by the user.
  667. * @pads: &struct v4l2_subdev_pad_config array
  668. *
  669. * This structure only needs to be passed to the pad op if the 'which' field
  670. * of the main argument is set to %V4L2_SUBDEV_FORMAT_TRY. For
  671. * %V4L2_SUBDEV_FORMAT_ACTIVE it is safe to pass %NULL.
  672. */
  673. struct v4l2_subdev_state {
  674. /* lock for the struct v4l2_subdev_state fields */
  675. struct mutex _lock;
  676. struct mutex *lock;
  677. struct v4l2_subdev_pad_config *pads;
  678. };
  679. /**
  680. * struct v4l2_subdev_pad_ops - v4l2-subdev pad level operations
  681. *
  682. * @init_cfg: initialize the pad config to default values
  683. * @enum_mbus_code: callback for VIDIOC_SUBDEV_ENUM_MBUS_CODE() ioctl handler
  684. * code.
  685. * @enum_frame_size: callback for VIDIOC_SUBDEV_ENUM_FRAME_SIZE() ioctl handler
  686. * code.
  687. *
  688. * @enum_frame_interval: callback for VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL() ioctl
  689. * handler code.
  690. *
  691. * @get_fmt: callback for VIDIOC_SUBDEV_G_FMT() ioctl handler code.
  692. *
  693. * @set_fmt: callback for VIDIOC_SUBDEV_S_FMT() ioctl handler code.
  694. *
  695. * @get_selection: callback for VIDIOC_SUBDEV_G_SELECTION() ioctl handler code.
  696. *
  697. * @set_selection: callback for VIDIOC_SUBDEV_S_SELECTION() ioctl handler code.
  698. *
  699. * @get_edid: callback for VIDIOC_SUBDEV_G_EDID() ioctl handler code.
  700. *
  701. * @set_edid: callback for VIDIOC_SUBDEV_S_EDID() ioctl handler code.
  702. *
  703. * @dv_timings_cap: callback for VIDIOC_SUBDEV_DV_TIMINGS_CAP() ioctl handler
  704. * code.
  705. *
  706. * @enum_dv_timings: callback for VIDIOC_SUBDEV_ENUM_DV_TIMINGS() ioctl handler
  707. * code.
  708. *
  709. * @link_validate: used by the media controller code to check if the links
  710. * that belongs to a pipeline can be used for stream.
  711. *
  712. * @get_frame_desc: get the current low level media bus frame parameters.
  713. *
  714. * @set_frame_desc: set the low level media bus frame parameters, @fd array
  715. * may be adjusted by the subdev driver to device capabilities.
  716. *
  717. * @get_mbus_config: get the media bus configuration of a remote sub-device.
  718. * The media bus configuration is usually retrieved from the
  719. * firmware interface at sub-device probe time, immediately
  720. * applied to the hardware and eventually adjusted by the
  721. * driver. Remote sub-devices (usually video receivers) shall
  722. * use this operation to query the transmitting end bus
  723. * configuration in order to adjust their own one accordingly.
  724. * Callers should make sure they get the most up-to-date as
  725. * possible configuration from the remote end, likely calling
  726. * this operation as close as possible to stream on time. The
  727. * operation shall fail if the pad index it has been called on
  728. * is not valid or in case of unrecoverable failures.
  729. */
  730. struct v4l2_subdev_pad_ops {
  731. int (*init_cfg)(struct v4l2_subdev *sd,
  732. struct v4l2_subdev_state *state);
  733. int (*enum_mbus_code)(struct v4l2_subdev *sd,
  734. struct v4l2_subdev_state *state,
  735. struct v4l2_subdev_mbus_code_enum *code);
  736. int (*enum_frame_size)(struct v4l2_subdev *sd,
  737. struct v4l2_subdev_state *state,
  738. struct v4l2_subdev_frame_size_enum *fse);
  739. int (*enum_frame_interval)(struct v4l2_subdev *sd,
  740. struct v4l2_subdev_state *state,
  741. struct v4l2_subdev_frame_interval_enum *fie);
  742. int (*get_fmt)(struct v4l2_subdev *sd,
  743. struct v4l2_subdev_state *state,
  744. struct v4l2_subdev_format *format);
  745. int (*set_fmt)(struct v4l2_subdev *sd,
  746. struct v4l2_subdev_state *state,
  747. struct v4l2_subdev_format *format);
  748. int (*get_selection)(struct v4l2_subdev *sd,
  749. struct v4l2_subdev_state *state,
  750. struct v4l2_subdev_selection *sel);
  751. int (*set_selection)(struct v4l2_subdev *sd,
  752. struct v4l2_subdev_state *state,
  753. struct v4l2_subdev_selection *sel);
  754. int (*get_edid)(struct v4l2_subdev *sd, struct v4l2_edid *edid);
  755. int (*set_edid)(struct v4l2_subdev *sd, struct v4l2_edid *edid);
  756. int (*dv_timings_cap)(struct v4l2_subdev *sd,
  757. struct v4l2_dv_timings_cap *cap);
  758. int (*enum_dv_timings)(struct v4l2_subdev *sd,
  759. struct v4l2_enum_dv_timings *timings);
  760. #ifdef CONFIG_MEDIA_CONTROLLER
  761. int (*link_validate)(struct v4l2_subdev *sd, struct media_link *link,
  762. struct v4l2_subdev_format *source_fmt,
  763. struct v4l2_subdev_format *sink_fmt);
  764. #endif /* CONFIG_MEDIA_CONTROLLER */
  765. int (*get_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
  766. struct v4l2_mbus_frame_desc *fd);
  767. int (*set_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
  768. struct v4l2_mbus_frame_desc *fd);
  769. int (*get_mbus_config)(struct v4l2_subdev *sd, unsigned int pad,
  770. struct v4l2_mbus_config *config);
  771. };
  772. /**
  773. * struct v4l2_subdev_ops - Subdev operations
  774. *
  775. * @core: pointer to &struct v4l2_subdev_core_ops. Can be %NULL
  776. * @tuner: pointer to &struct v4l2_subdev_tuner_ops. Can be %NULL
  777. * @audio: pointer to &struct v4l2_subdev_audio_ops. Can be %NULL
  778. * @video: pointer to &struct v4l2_subdev_video_ops. Can be %NULL
  779. * @vbi: pointer to &struct v4l2_subdev_vbi_ops. Can be %NULL
  780. * @ir: pointer to &struct v4l2_subdev_ir_ops. Can be %NULL
  781. * @sensor: pointer to &struct v4l2_subdev_sensor_ops. Can be %NULL
  782. * @pad: pointer to &struct v4l2_subdev_pad_ops. Can be %NULL
  783. */
  784. struct v4l2_subdev_ops {
  785. const struct v4l2_subdev_core_ops *core;
  786. const struct v4l2_subdev_tuner_ops *tuner;
  787. const struct v4l2_subdev_audio_ops *audio;
  788. const struct v4l2_subdev_video_ops *video;
  789. const struct v4l2_subdev_vbi_ops *vbi;
  790. const struct v4l2_subdev_ir_ops *ir;
  791. const struct v4l2_subdev_sensor_ops *sensor;
  792. const struct v4l2_subdev_pad_ops *pad;
  793. };
  794. /**
  795. * struct v4l2_subdev_internal_ops - V4L2 subdev internal ops
  796. *
  797. * @registered: called when this subdev is registered. When called the v4l2_dev
  798. * field is set to the correct v4l2_device.
  799. *
  800. * @unregistered: called when this subdev is unregistered. When called the
  801. * v4l2_dev field is still set to the correct v4l2_device.
  802. *
  803. * @open: called when the subdev device node is opened by an application.
  804. *
  805. * @close: called when the subdev device node is closed. Please note that
  806. * it is possible for @close to be called after @unregistered!
  807. *
  808. * @release: called when the last user of the subdev device is gone. This
  809. * happens after the @unregistered callback and when the last open
  810. * filehandle to the v4l-subdevX device node was closed. If no device
  811. * node was created for this sub-device, then the @release callback
  812. * is called right after the @unregistered callback.
  813. * The @release callback is typically used to free the memory containing
  814. * the v4l2_subdev structure. It is almost certainly required for any
  815. * sub-device that sets the V4L2_SUBDEV_FL_HAS_DEVNODE flag.
  816. *
  817. * .. note::
  818. * Never call this from drivers, only the v4l2 framework can call
  819. * these ops.
  820. */
  821. struct v4l2_subdev_internal_ops {
  822. int (*registered)(struct v4l2_subdev *sd);
  823. void (*unregistered)(struct v4l2_subdev *sd);
  824. int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
  825. int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
  826. void (*release)(struct v4l2_subdev *sd);
  827. };
  828. #define V4L2_SUBDEV_NAME_SIZE 32
  829. /* Set this flag if this subdev is a i2c device. */
  830. #define V4L2_SUBDEV_FL_IS_I2C (1U << 0)
  831. /* Set this flag if this subdev is a spi device. */
  832. #define V4L2_SUBDEV_FL_IS_SPI (1U << 1)
  833. /* Set this flag if this subdev needs a device node. */
  834. #define V4L2_SUBDEV_FL_HAS_DEVNODE (1U << 2)
  835. /*
  836. * Set this flag if this subdev generates events.
  837. * Note controls can send events, thus drivers exposing controls
  838. * should set this flag.
  839. */
  840. #define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
  841. struct regulator_bulk_data;
  842. /**
  843. * struct v4l2_subdev_platform_data - regulators config struct
  844. *
  845. * @regulators: Optional regulators used to power on/off the subdevice
  846. * @num_regulators: Number of regululators
  847. * @host_priv: Per-subdevice data, specific for a certain video host device
  848. */
  849. struct v4l2_subdev_platform_data {
  850. struct regulator_bulk_data *regulators;
  851. int num_regulators;
  852. void *host_priv;
  853. };
  854. /**
  855. * struct v4l2_subdev - describes a V4L2 sub-device
  856. *
  857. * @entity: pointer to &struct media_entity
  858. * @list: List of sub-devices
  859. * @owner: The owner is the same as the driver's &struct device owner.
  860. * @owner_v4l2_dev: true if the &sd->owner matches the owner of @v4l2_dev->dev
  861. * owner. Initialized by v4l2_device_register_subdev().
  862. * @flags: subdev flags. Can be:
  863. * %V4L2_SUBDEV_FL_IS_I2C - Set this flag if this subdev is a i2c device;
  864. * %V4L2_SUBDEV_FL_IS_SPI - Set this flag if this subdev is a spi device;
  865. * %V4L2_SUBDEV_FL_HAS_DEVNODE - Set this flag if this subdev needs a
  866. * device node;
  867. * %V4L2_SUBDEV_FL_HAS_EVENTS - Set this flag if this subdev generates
  868. * events.
  869. *
  870. * @v4l2_dev: pointer to struct &v4l2_device
  871. * @ops: pointer to struct &v4l2_subdev_ops
  872. * @internal_ops: pointer to struct &v4l2_subdev_internal_ops.
  873. * Never call these internal ops from within a driver!
  874. * @ctrl_handler: The control handler of this subdev. May be NULL.
  875. * @name: Name of the sub-device. Please notice that the name must be unique.
  876. * @grp_id: can be used to group similar subdevs. Value is driver-specific
  877. * @dev_priv: pointer to private data
  878. * @host_priv: pointer to private data used by the device where the subdev
  879. * is attached.
  880. * @devnode: subdev device node
  881. * @dev: pointer to the physical device, if any
  882. * @fwnode: The fwnode_handle of the subdev, usually the same as
  883. * either dev->of_node->fwnode or dev->fwnode (whichever is non-NULL).
  884. * @async_list: Links this subdev to a global subdev_list or @notifier->done
  885. * list.
  886. * @asd: Pointer to respective &struct v4l2_async_subdev.
  887. * @notifier: Pointer to the managing notifier.
  888. * @subdev_notifier: A sub-device notifier implicitly registered for the sub-
  889. * device using v4l2_async_register_subdev_sensor().
  890. * @pdata: common part of subdevice platform data
  891. * @state_lock: A pointer to a lock used for all the subdev's states, set by the
  892. * driver. This is optional. If NULL, each state instance will get
  893. * a lock of its own.
  894. * @active_state: Active state for the subdev (NULL for subdevs tracking the
  895. * state internally). Initialized by calling
  896. * v4l2_subdev_init_finalize().
  897. *
  898. * Each instance of a subdev driver should create this struct, either
  899. * stand-alone or embedded in a larger struct.
  900. *
  901. * This structure should be initialized by v4l2_subdev_init() or one of
  902. * its variants: v4l2_spi_subdev_init(), v4l2_i2c_subdev_init().
  903. */
  904. struct v4l2_subdev {
  905. #if defined(CONFIG_MEDIA_CONTROLLER)
  906. struct media_entity entity;
  907. #endif
  908. struct list_head list;
  909. struct module *owner;
  910. bool owner_v4l2_dev;
  911. u32 flags;
  912. struct v4l2_device *v4l2_dev;
  913. const struct v4l2_subdev_ops *ops;
  914. const struct v4l2_subdev_internal_ops *internal_ops;
  915. struct v4l2_ctrl_handler *ctrl_handler;
  916. char name[V4L2_SUBDEV_NAME_SIZE];
  917. u32 grp_id;
  918. void *dev_priv;
  919. void *host_priv;
  920. struct video_device *devnode;
  921. struct device *dev;
  922. struct fwnode_handle *fwnode;
  923. struct list_head async_list;
  924. struct v4l2_async_subdev *asd;
  925. struct v4l2_async_notifier *notifier;
  926. struct v4l2_async_notifier *subdev_notifier;
  927. struct v4l2_subdev_platform_data *pdata;
  928. struct mutex *state_lock;
  929. /*
  930. * The fields below are private, and should only be accessed via
  931. * appropriate functions.
  932. */
  933. /*
  934. * TODO: active_state should most likely be changed from a pointer to an
  935. * embedded field. For the time being it's kept as a pointer to more
  936. * easily catch uses of active_state in the cases where the driver
  937. * doesn't support it.
  938. */
  939. struct v4l2_subdev_state *active_state;
  940. };
  941. /**
  942. * media_entity_to_v4l2_subdev - Returns a &struct v4l2_subdev from
  943. * the &struct media_entity embedded in it.
  944. *
  945. * @ent: pointer to &struct media_entity.
  946. */
  947. #define media_entity_to_v4l2_subdev(ent) \
  948. ({ \
  949. typeof(ent) __me_sd_ent = (ent); \
  950. \
  951. __me_sd_ent ? \
  952. container_of(__me_sd_ent, struct v4l2_subdev, entity) : \
  953. NULL; \
  954. })
  955. /**
  956. * vdev_to_v4l2_subdev - Returns a &struct v4l2_subdev from
  957. * the &struct video_device embedded on it.
  958. *
  959. * @vdev: pointer to &struct video_device
  960. */
  961. #define vdev_to_v4l2_subdev(vdev) \
  962. ((struct v4l2_subdev *)video_get_drvdata(vdev))
  963. /**
  964. * struct v4l2_subdev_fh - Used for storing subdev information per file handle
  965. *
  966. * @vfh: pointer to &struct v4l2_fh
  967. * @state: pointer to &struct v4l2_subdev_state
  968. * @owner: module pointer to the owner of this file handle
  969. */
  970. struct v4l2_subdev_fh {
  971. struct v4l2_fh vfh;
  972. struct module *owner;
  973. #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
  974. struct v4l2_subdev_state *state;
  975. #endif
  976. };
  977. /**
  978. * to_v4l2_subdev_fh - Returns a &struct v4l2_subdev_fh from
  979. * the &struct v4l2_fh embedded on it.
  980. *
  981. * @fh: pointer to &struct v4l2_fh
  982. */
  983. #define to_v4l2_subdev_fh(fh) \
  984. container_of(fh, struct v4l2_subdev_fh, vfh)
  985. #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
  986. /**
  987. * v4l2_subdev_get_pad_format - ancillary routine to call
  988. * &struct v4l2_subdev_pad_config->try_fmt
  989. *
  990. * @sd: pointer to &struct v4l2_subdev
  991. * @state: pointer to &struct v4l2_subdev_state
  992. * @pad: index of the pad in the &struct v4l2_subdev_state->pads array
  993. */
  994. static inline struct v4l2_mbus_framefmt *
  995. v4l2_subdev_get_pad_format(struct v4l2_subdev *sd,
  996. struct v4l2_subdev_state *state,
  997. unsigned int pad)
  998. {
  999. if (WARN_ON(!state))
  1000. return NULL;
  1001. if (WARN_ON(pad >= sd->entity.num_pads))
  1002. pad = 0;
  1003. return &state->pads[pad].try_fmt;
  1004. }
  1005. /**
  1006. * v4l2_subdev_get_pad_crop - ancillary routine to call
  1007. * &struct v4l2_subdev_pad_config->try_crop
  1008. *
  1009. * @sd: pointer to &struct v4l2_subdev
  1010. * @state: pointer to &struct v4l2_subdev_state.
  1011. * @pad: index of the pad in the &struct v4l2_subdev_state->pads array.
  1012. */
  1013. static inline struct v4l2_rect *
  1014. v4l2_subdev_get_pad_crop(struct v4l2_subdev *sd,
  1015. struct v4l2_subdev_state *state,
  1016. unsigned int pad)
  1017. {
  1018. if (WARN_ON(!state))
  1019. return NULL;
  1020. if (WARN_ON(pad >= sd->entity.num_pads))
  1021. pad = 0;
  1022. return &state->pads[pad].try_crop;
  1023. }
  1024. /**
  1025. * v4l2_subdev_get_pad_compose - ancillary routine to call
  1026. * &struct v4l2_subdev_pad_config->try_compose
  1027. *
  1028. * @sd: pointer to &struct v4l2_subdev
  1029. * @state: pointer to &struct v4l2_subdev_state.
  1030. * @pad: index of the pad in the &struct v4l2_subdev_state->pads array.
  1031. */
  1032. static inline struct v4l2_rect *
  1033. v4l2_subdev_get_pad_compose(struct v4l2_subdev *sd,
  1034. struct v4l2_subdev_state *state,
  1035. unsigned int pad)
  1036. {
  1037. if (WARN_ON(!state))
  1038. return NULL;
  1039. if (WARN_ON(pad >= sd->entity.num_pads))
  1040. pad = 0;
  1041. return &state->pads[pad].try_compose;
  1042. }
  1043. /*
  1044. * Temprary helpers until uses of v4l2_subdev_get_try_* functions have been
  1045. * renamed
  1046. */
  1047. #define v4l2_subdev_get_try_format(sd, state, pad) \
  1048. v4l2_subdev_get_pad_format(sd, state, pad)
  1049. #define v4l2_subdev_get_try_crop(sd, state, pad) \
  1050. v4l2_subdev_get_pad_crop(sd, state, pad)
  1051. #define v4l2_subdev_get_try_compose(sd, state, pad) \
  1052. v4l2_subdev_get_pad_compose(sd, state, pad)
  1053. #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
  1054. extern const struct v4l2_file_operations v4l2_subdev_fops;
  1055. /**
  1056. * v4l2_set_subdevdata - Sets V4L2 dev private device data
  1057. *
  1058. * @sd: pointer to &struct v4l2_subdev
  1059. * @p: pointer to the private device data to be stored.
  1060. */
  1061. static inline void v4l2_set_subdevdata(struct v4l2_subdev *sd, void *p)
  1062. {
  1063. sd->dev_priv = p;
  1064. }
  1065. /**
  1066. * v4l2_get_subdevdata - Gets V4L2 dev private device data
  1067. *
  1068. * @sd: pointer to &struct v4l2_subdev
  1069. *
  1070. * Returns the pointer to the private device data to be stored.
  1071. */
  1072. static inline void *v4l2_get_subdevdata(const struct v4l2_subdev *sd)
  1073. {
  1074. return sd->dev_priv;
  1075. }
  1076. /**
  1077. * v4l2_set_subdev_hostdata - Sets V4L2 dev private host data
  1078. *
  1079. * @sd: pointer to &struct v4l2_subdev
  1080. * @p: pointer to the private data to be stored.
  1081. */
  1082. static inline void v4l2_set_subdev_hostdata(struct v4l2_subdev *sd, void *p)
  1083. {
  1084. sd->host_priv = p;
  1085. }
  1086. /**
  1087. * v4l2_get_subdev_hostdata - Gets V4L2 dev private data
  1088. *
  1089. * @sd: pointer to &struct v4l2_subdev
  1090. *
  1091. * Returns the pointer to the private host data to be stored.
  1092. */
  1093. static inline void *v4l2_get_subdev_hostdata(const struct v4l2_subdev *sd)
  1094. {
  1095. return sd->host_priv;
  1096. }
  1097. #ifdef CONFIG_MEDIA_CONTROLLER
  1098. /**
  1099. * v4l2_subdev_get_fwnode_pad_1_to_1 - Get pad number from a subdev fwnode
  1100. * endpoint, assuming 1:1 port:pad
  1101. *
  1102. * @entity: Pointer to the subdev entity
  1103. * @endpoint: Pointer to a parsed fwnode endpoint
  1104. *
  1105. * This function can be used as the .get_fwnode_pad operation for
  1106. * subdevices that map port numbers and pad indexes 1:1. If the endpoint
  1107. * is owned by the subdevice, the function returns the endpoint port
  1108. * number.
  1109. *
  1110. * Returns the endpoint port number on success or a negative error code.
  1111. */
  1112. int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity,
  1113. struct fwnode_endpoint *endpoint);
  1114. /**
  1115. * v4l2_subdev_link_validate_default - validates a media link
  1116. *
  1117. * @sd: pointer to &struct v4l2_subdev
  1118. * @link: pointer to &struct media_link
  1119. * @source_fmt: pointer to &struct v4l2_subdev_format
  1120. * @sink_fmt: pointer to &struct v4l2_subdev_format
  1121. *
  1122. * This function ensures that width, height and the media bus pixel
  1123. * code are equal on both source and sink of the link.
  1124. */
  1125. int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
  1126. struct media_link *link,
  1127. struct v4l2_subdev_format *source_fmt,
  1128. struct v4l2_subdev_format *sink_fmt);
  1129. /**
  1130. * v4l2_subdev_link_validate - validates a media link
  1131. *
  1132. * @link: pointer to &struct media_link
  1133. *
  1134. * This function calls the subdev's link_validate ops to validate
  1135. * if a media link is valid for streaming. It also internally
  1136. * calls v4l2_subdev_link_validate_default() to ensure that
  1137. * width, height and the media bus pixel code are equal on both
  1138. * source and sink of the link.
  1139. */
  1140. int v4l2_subdev_link_validate(struct media_link *link);
  1141. /**
  1142. * __v4l2_subdev_state_alloc - allocate v4l2_subdev_state
  1143. *
  1144. * @sd: pointer to &struct v4l2_subdev for which the state is being allocated.
  1145. * @lock_name: name of the state lock
  1146. * @key: lock_class_key for the lock
  1147. *
  1148. * Must call __v4l2_subdev_state_free() when state is no longer needed.
  1149. *
  1150. * Not to be called directly by the drivers.
  1151. */
  1152. struct v4l2_subdev_state *__v4l2_subdev_state_alloc(struct v4l2_subdev *sd,
  1153. const char *lock_name,
  1154. struct lock_class_key *key);
  1155. /**
  1156. * __v4l2_subdev_state_free - free a v4l2_subdev_state
  1157. *
  1158. * @state: v4l2_subdev_state to be freed.
  1159. *
  1160. * Not to be called directly by the drivers.
  1161. */
  1162. void __v4l2_subdev_state_free(struct v4l2_subdev_state *state);
  1163. /**
  1164. * v4l2_subdev_init_finalize() - Finalizes the initialization of the subdevice
  1165. * @sd: The subdev
  1166. *
  1167. * This function finalizes the initialization of the subdev, including
  1168. * allocation of the active state for the subdev.
  1169. *
  1170. * This function must be called by the subdev drivers that use the centralized
  1171. * active state, after the subdev struct has been initialized and
  1172. * media_entity_pads_init() has been called, but before registering the
  1173. * subdev.
  1174. *
  1175. * The user must call v4l2_subdev_cleanup() when the subdev is being removed.
  1176. */
  1177. #define v4l2_subdev_init_finalize(sd) \
  1178. ({ \
  1179. static struct lock_class_key __key; \
  1180. const char *name = KBUILD_BASENAME \
  1181. ":" __stringify(__LINE__) ":sd->active_state->lock"; \
  1182. __v4l2_subdev_init_finalize(sd, name, &__key); \
  1183. })
  1184. int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name,
  1185. struct lock_class_key *key);
  1186. /**
  1187. * v4l2_subdev_cleanup() - Releases the resources allocated by the subdevice
  1188. * @sd: The subdevice
  1189. *
  1190. * This function will release the resources allocated in
  1191. * v4l2_subdev_init_finalize.
  1192. */
  1193. void v4l2_subdev_cleanup(struct v4l2_subdev *sd);
  1194. /**
  1195. * v4l2_subdev_lock_state() - Locks the subdev state
  1196. * @state: The subdevice state
  1197. *
  1198. * Locks the given subdev state.
  1199. *
  1200. * The state must be unlocked with v4l2_subdev_unlock_state() after use.
  1201. */
  1202. static inline void v4l2_subdev_lock_state(struct v4l2_subdev_state *state)
  1203. {
  1204. mutex_lock(state->lock);
  1205. }
  1206. /**
  1207. * v4l2_subdev_unlock_state() - Unlocks the subdev state
  1208. * @state: The subdevice state
  1209. *
  1210. * Unlocks the given subdev state.
  1211. */
  1212. static inline void v4l2_subdev_unlock_state(struct v4l2_subdev_state *state)
  1213. {
  1214. mutex_unlock(state->lock);
  1215. }
  1216. /**
  1217. * v4l2_subdev_get_unlocked_active_state() - Checks that the active subdev state
  1218. * is unlocked and returns it
  1219. * @sd: The subdevice
  1220. *
  1221. * Returns the active state for the subdevice, or NULL if the subdev does not
  1222. * support active state. If the state is not NULL, calls
  1223. * lockdep_assert_not_held() to issue a warning if the state is locked.
  1224. *
  1225. * This function is to be used e.g. when getting the active state for the sole
  1226. * purpose of passing it forward, without accessing the state fields.
  1227. */
  1228. static inline struct v4l2_subdev_state *
  1229. v4l2_subdev_get_unlocked_active_state(struct v4l2_subdev *sd)
  1230. {
  1231. if (sd->active_state)
  1232. lockdep_assert_not_held(sd->active_state->lock);
  1233. return sd->active_state;
  1234. }
  1235. /**
  1236. * v4l2_subdev_get_locked_active_state() - Checks that the active subdev state
  1237. * is locked and returns it
  1238. *
  1239. * @sd: The subdevice
  1240. *
  1241. * Returns the active state for the subdevice, or NULL if the subdev does not
  1242. * support active state. If the state is not NULL, calls lockdep_assert_held()
  1243. * to issue a warning if the state is not locked.
  1244. *
  1245. * This function is to be used when the caller knows that the active state is
  1246. * already locked.
  1247. */
  1248. static inline struct v4l2_subdev_state *
  1249. v4l2_subdev_get_locked_active_state(struct v4l2_subdev *sd)
  1250. {
  1251. if (sd->active_state)
  1252. lockdep_assert_held(sd->active_state->lock);
  1253. return sd->active_state;
  1254. }
  1255. /**
  1256. * v4l2_subdev_lock_and_get_active_state() - Locks and returns the active subdev
  1257. * state for the subdevice
  1258. * @sd: The subdevice
  1259. *
  1260. * Returns the locked active state for the subdevice, or NULL if the subdev
  1261. * does not support active state.
  1262. *
  1263. * The state must be unlocked with v4l2_subdev_unlock_state() after use.
  1264. */
  1265. static inline struct v4l2_subdev_state *
  1266. v4l2_subdev_lock_and_get_active_state(struct v4l2_subdev *sd)
  1267. {
  1268. if (sd->active_state)
  1269. v4l2_subdev_lock_state(sd->active_state);
  1270. return sd->active_state;
  1271. }
  1272. #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
  1273. /**
  1274. * v4l2_subdev_get_fmt() - Fill format based on state
  1275. * @sd: subdevice
  1276. * @state: subdevice state
  1277. * @format: pointer to &struct v4l2_subdev_format
  1278. *
  1279. * Fill @format->format field based on the information in the @format struct.
  1280. *
  1281. * This function can be used by the subdev drivers which support active state to
  1282. * implement v4l2_subdev_pad_ops.get_fmt if the subdev driver does not need to
  1283. * do anything special in their get_fmt op.
  1284. *
  1285. * Returns 0 on success, error value otherwise.
  1286. */
  1287. int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
  1288. struct v4l2_subdev_format *format);
  1289. #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
  1290. #endif /* CONFIG_MEDIA_CONTROLLER */
  1291. /**
  1292. * v4l2_subdev_init - initializes the sub-device struct
  1293. *
  1294. * @sd: pointer to the &struct v4l2_subdev to be initialized
  1295. * @ops: pointer to &struct v4l2_subdev_ops.
  1296. */
  1297. void v4l2_subdev_init(struct v4l2_subdev *sd,
  1298. const struct v4l2_subdev_ops *ops);
  1299. extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers;
  1300. /**
  1301. * v4l2_subdev_call - call an operation of a v4l2_subdev.
  1302. *
  1303. * @sd: pointer to the &struct v4l2_subdev
  1304. * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
  1305. * Each element there groups a set of callbacks functions.
  1306. * @f: callback function to be called.
  1307. * The callback functions are defined in groups, according to
  1308. * each element at &struct v4l2_subdev_ops.
  1309. * @args: arguments for @f.
  1310. *
  1311. * Example: err = v4l2_subdev_call(sd, video, s_std, norm);
  1312. */
  1313. #define v4l2_subdev_call(sd, o, f, args...) \
  1314. ({ \
  1315. struct v4l2_subdev *__sd = (sd); \
  1316. int __result; \
  1317. if (!__sd) \
  1318. __result = -ENODEV; \
  1319. else if (!(__sd->ops->o && __sd->ops->o->f)) \
  1320. __result = -ENOIOCTLCMD; \
  1321. else if (v4l2_subdev_call_wrappers.o && \
  1322. v4l2_subdev_call_wrappers.o->f) \
  1323. __result = v4l2_subdev_call_wrappers.o->f( \
  1324. __sd, ##args); \
  1325. else \
  1326. __result = __sd->ops->o->f(__sd, ##args); \
  1327. __result; \
  1328. })
  1329. /**
  1330. * v4l2_subdev_call_state_active - call an operation of a v4l2_subdev which
  1331. * takes state as a parameter, passing the
  1332. * subdev its active state.
  1333. *
  1334. * @sd: pointer to the &struct v4l2_subdev
  1335. * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
  1336. * Each element there groups a set of callbacks functions.
  1337. * @f: callback function to be called.
  1338. * The callback functions are defined in groups, according to
  1339. * each element at &struct v4l2_subdev_ops.
  1340. * @args: arguments for @f.
  1341. *
  1342. * This is similar to v4l2_subdev_call(), except that this version can only be
  1343. * used for ops that take a subdev state as a parameter. The macro will get the
  1344. * active state, lock it before calling the op and unlock it after the call.
  1345. */
  1346. #define v4l2_subdev_call_state_active(sd, o, f, args...) \
  1347. ({ \
  1348. int __result; \
  1349. struct v4l2_subdev_state *state; \
  1350. state = v4l2_subdev_get_unlocked_active_state(sd); \
  1351. if (state) \
  1352. v4l2_subdev_lock_state(state); \
  1353. __result = v4l2_subdev_call(sd, o, f, state, ##args); \
  1354. if (state) \
  1355. v4l2_subdev_unlock_state(state); \
  1356. __result; \
  1357. })
  1358. /**
  1359. * v4l2_subdev_call_state_try - call an operation of a v4l2_subdev which
  1360. * takes state as a parameter, passing the
  1361. * subdev a newly allocated try state.
  1362. *
  1363. * @sd: pointer to the &struct v4l2_subdev
  1364. * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
  1365. * Each element there groups a set of callbacks functions.
  1366. * @f: callback function to be called.
  1367. * The callback functions are defined in groups, according to
  1368. * each element at &struct v4l2_subdev_ops.
  1369. * @args: arguments for @f.
  1370. *
  1371. * This is similar to v4l2_subdev_call_state_active(), except that as this
  1372. * version allocates a new state, this is only usable for
  1373. * V4L2_SUBDEV_FORMAT_TRY use cases.
  1374. *
  1375. * Note: only legacy non-MC drivers may need this macro.
  1376. */
  1377. #define v4l2_subdev_call_state_try(sd, o, f, args...) \
  1378. ({ \
  1379. int __result; \
  1380. static struct lock_class_key __key; \
  1381. const char *name = KBUILD_BASENAME \
  1382. ":" __stringify(__LINE__) ":state->lock"; \
  1383. struct v4l2_subdev_state *state = \
  1384. __v4l2_subdev_state_alloc(sd, name, &__key); \
  1385. v4l2_subdev_lock_state(state); \
  1386. __result = v4l2_subdev_call(sd, o, f, state, ##args); \
  1387. v4l2_subdev_unlock_state(state); \
  1388. __v4l2_subdev_state_free(state); \
  1389. __result; \
  1390. })
  1391. /**
  1392. * v4l2_subdev_has_op - Checks if a subdev defines a certain operation.
  1393. *
  1394. * @sd: pointer to the &struct v4l2_subdev
  1395. * @o: The group of callback functions in &struct v4l2_subdev_ops
  1396. * which @f is a part of.
  1397. * @f: callback function to be checked for its existence.
  1398. */
  1399. #define v4l2_subdev_has_op(sd, o, f) \
  1400. ((sd)->ops->o && (sd)->ops->o->f)
  1401. /**
  1402. * v4l2_subdev_notify_event() - Delivers event notification for subdevice
  1403. * @sd: The subdev for which to deliver the event
  1404. * @ev: The event to deliver
  1405. *
  1406. * Will deliver the specified event to all userspace event listeners which are
  1407. * subscribed to the v42l subdev event queue as well as to the bridge driver
  1408. * using the notify callback. The notification type for the notify callback
  1409. * will be %V4L2_DEVICE_NOTIFY_EVENT.
  1410. */
  1411. void v4l2_subdev_notify_event(struct v4l2_subdev *sd,
  1412. const struct v4l2_event *ev);
  1413. #endif /* _V4L2_SUBDEV_H */