v4l2-subdev.h 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * V4L2 sub-device support header.
  4. *
  5. * Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
  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. struct led_classdev;
  36. /**
  37. * struct v4l2_decode_vbi_line - used to decode_vbi_line
  38. *
  39. * @is_second_field: Set to 0 for the first (odd) field;
  40. * set to 1 for the second (even) field.
  41. * @p: Pointer to the sliced VBI data from the decoder. On exit, points to
  42. * the start of the payload.
  43. * @line: Line number of the sliced VBI data (1-23)
  44. * @type: VBI service type (V4L2_SLICED_*). 0 if no service found
  45. */
  46. struct v4l2_decode_vbi_line {
  47. u32 is_second_field;
  48. u8 *p;
  49. u32 line;
  50. u32 type;
  51. };
  52. /*
  53. * Sub-devices are devices that are connected somehow to the main bridge
  54. * device. These devices are usually audio/video muxers/encoders/decoders or
  55. * sensors and webcam controllers.
  56. *
  57. * Usually these devices are controlled through an i2c bus, but other buses
  58. * may also be used.
  59. *
  60. * The v4l2_subdev struct provides a way of accessing these devices in a
  61. * generic manner. Most operations that these sub-devices support fall in
  62. * a few categories: core ops, audio ops, video ops and tuner ops.
  63. *
  64. * More categories can be added if needed, although this should remain a
  65. * limited set (no more than approx. 8 categories).
  66. *
  67. * Each category has its own set of ops that subdev drivers can implement.
  68. *
  69. * A subdev driver can leave the pointer to the category ops NULL if
  70. * it does not implement them (e.g. an audio subdev will generally not
  71. * implement the video category ops). The exception is the core category:
  72. * this must always be present.
  73. *
  74. * These ops are all used internally so it is no problem to change, remove
  75. * or add ops or move ops from one to another category. Currently these
  76. * ops are based on the original ioctls, but since ops are not limited to
  77. * one argument there is room for improvement here once all i2c subdev
  78. * drivers are converted to use these ops.
  79. */
  80. /*
  81. * Core ops: it is highly recommended to implement at least these ops:
  82. *
  83. * log_status
  84. * g_register
  85. * s_register
  86. *
  87. * This provides basic debugging support.
  88. *
  89. * The ioctl ops is meant for generic ioctl-like commands. Depending on
  90. * the use-case it might be better to use subdev-specific ops (currently
  91. * not yet implemented) since ops provide proper type-checking.
  92. */
  93. /**
  94. * enum v4l2_subdev_io_pin_bits - Subdevice external IO pin configuration
  95. * bits
  96. *
  97. * @V4L2_SUBDEV_IO_PIN_DISABLE: disables a pin config. ENABLE assumed.
  98. * @V4L2_SUBDEV_IO_PIN_OUTPUT: set it if pin is an output.
  99. * @V4L2_SUBDEV_IO_PIN_INPUT: set it if pin is an input.
  100. * @V4L2_SUBDEV_IO_PIN_SET_VALUE: to set the output value via
  101. * &struct v4l2_subdev_io_pin_config->value.
  102. * @V4L2_SUBDEV_IO_PIN_ACTIVE_LOW: pin active is bit 0.
  103. * Otherwise, ACTIVE HIGH is assumed.
  104. */
  105. enum v4l2_subdev_io_pin_bits {
  106. V4L2_SUBDEV_IO_PIN_DISABLE = 0,
  107. V4L2_SUBDEV_IO_PIN_OUTPUT = 1,
  108. V4L2_SUBDEV_IO_PIN_INPUT = 2,
  109. V4L2_SUBDEV_IO_PIN_SET_VALUE = 3,
  110. V4L2_SUBDEV_IO_PIN_ACTIVE_LOW = 4,
  111. };
  112. /**
  113. * struct v4l2_subdev_io_pin_config - Subdevice external IO pin configuration
  114. *
  115. * @flags: bitmask with flags for this pin's config, whose bits are defined by
  116. * &enum v4l2_subdev_io_pin_bits.
  117. * @pin: Chip external IO pin to configure
  118. * @function: Internal signal pad/function to route to IO pin
  119. * @value: Initial value for pin - e.g. GPIO output value
  120. * @strength: Pin drive strength
  121. */
  122. struct v4l2_subdev_io_pin_config {
  123. u32 flags;
  124. u8 pin;
  125. u8 function;
  126. u8 value;
  127. u8 strength;
  128. };
  129. /**
  130. * struct v4l2_subdev_core_ops - Define core ops callbacks for subdevs
  131. *
  132. * @log_status: callback for VIDIOC_LOG_STATUS() ioctl handler code.
  133. *
  134. * @s_io_pin_config: configure one or more chip I/O pins for chips that
  135. * multiplex different internal signal pads out to IO pins. This function
  136. * takes a pointer to an array of 'n' pin configuration entries, one for
  137. * each pin being configured. This function could be called at times
  138. * other than just subdevice initialization.
  139. *
  140. * @init: initialize the sensor registers to some sort of reasonable default
  141. * values. Do not use for new drivers and should be removed in existing
  142. * drivers.
  143. *
  144. * @load_fw: load firmware.
  145. *
  146. * @reset: generic reset command. The argument selects which subsystems to
  147. * reset. Passing 0 will always reset the whole chip. Do not use for new
  148. * drivers without discussing this first on the linux-media mailinglist.
  149. * There should be no reason normally to reset a device.
  150. *
  151. * @s_gpio: set GPIO pins. Very simple right now, might need to be extended with
  152. * a direction argument if needed.
  153. *
  154. * @command: called by in-kernel drivers in order to call functions internal
  155. * to subdev drivers driver that have a separate callback.
  156. *
  157. * @ioctl: called at the end of ioctl() syscall handler at the V4L2 core.
  158. * used to provide support for private ioctls used on the driver.
  159. *
  160. * @compat_ioctl32: called when a 32 bits application uses a 64 bits Kernel,
  161. * in order to fix data passed from/to userspace.
  162. *
  163. * @g_register: callback for VIDIOC_DBG_G_REGISTER() ioctl handler code.
  164. *
  165. * @s_register: callback for VIDIOC_DBG_S_REGISTER() ioctl handler code.
  166. *
  167. * @s_power: puts subdevice in power saving mode (on == 0) or normal operation
  168. * mode (on == 1). DEPRECATED. See
  169. * Documentation/driver-api/media/camera-sensor.rst . pre_streamon and
  170. * post_streamoff callbacks can be used for e.g. setting the bus to LP-11
  171. * mode before s_stream is called.
  172. *
  173. * @interrupt_service_routine: Called by the bridge chip's interrupt service
  174. * handler, when an interrupt status has be raised due to this subdev,
  175. * so that this subdev can handle the details. It may schedule work to be
  176. * performed later. It must not sleep. **Called from an IRQ context**.
  177. *
  178. * @subscribe_event: used by the drivers to request the control framework that
  179. * for it to be warned when the value of a control changes.
  180. *
  181. * @unsubscribe_event: remove event subscription from the control framework.
  182. */
  183. struct v4l2_subdev_core_ops {
  184. int (*log_status)(struct v4l2_subdev *sd);
  185. int (*s_io_pin_config)(struct v4l2_subdev *sd, size_t n,
  186. struct v4l2_subdev_io_pin_config *pincfg);
  187. int (*init)(struct v4l2_subdev *sd, u32 val);
  188. int (*load_fw)(struct v4l2_subdev *sd);
  189. int (*reset)(struct v4l2_subdev *sd, u32 val);
  190. int (*s_gpio)(struct v4l2_subdev *sd, u32 val);
  191. long (*command)(struct v4l2_subdev *sd, unsigned int cmd, void *arg);
  192. long (*ioctl)(struct v4l2_subdev *sd, unsigned int cmd, void *arg);
  193. #ifdef CONFIG_COMPAT
  194. long (*compat_ioctl32)(struct v4l2_subdev *sd, unsigned int cmd,
  195. unsigned long arg);
  196. #endif
  197. #ifdef CONFIG_VIDEO_ADV_DEBUG
  198. int (*g_register)(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg);
  199. int (*s_register)(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg);
  200. #endif
  201. int (*s_power)(struct v4l2_subdev *sd, int on);
  202. int (*interrupt_service_routine)(struct v4l2_subdev *sd,
  203. u32 status, bool *handled);
  204. int (*subscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  205. struct v4l2_event_subscription *sub);
  206. int (*unsubscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  207. struct v4l2_event_subscription *sub);
  208. };
  209. /**
  210. * struct v4l2_subdev_tuner_ops - Callbacks used when v4l device was opened
  211. * in radio mode.
  212. *
  213. * @standby: puts the tuner in standby mode. It will be woken up
  214. * automatically the next time it is used.
  215. *
  216. * @s_radio: callback that switches the tuner to radio mode.
  217. * drivers should explicitly call it when a tuner ops should
  218. * operate on radio mode, before being able to handle it.
  219. * Used on devices that have both AM/FM radio receiver and TV.
  220. *
  221. * @s_frequency: callback for VIDIOC_S_FREQUENCY() ioctl handler code.
  222. *
  223. * @g_frequency: callback for VIDIOC_G_FREQUENCY() ioctl handler code.
  224. * freq->type must be filled in. Normally done by video_ioctl2()
  225. * or the bridge driver.
  226. *
  227. * @enum_freq_bands: callback for VIDIOC_ENUM_FREQ_BANDS() ioctl handler code.
  228. *
  229. * @g_tuner: callback for VIDIOC_G_TUNER() ioctl handler code.
  230. *
  231. * @s_tuner: callback for VIDIOC_S_TUNER() ioctl handler code. @vt->type must be
  232. * filled in. Normally done by video_ioctl2 or the
  233. * bridge driver.
  234. *
  235. * @g_modulator: callback for VIDIOC_G_MODULATOR() ioctl handler code.
  236. *
  237. * @s_modulator: callback for VIDIOC_S_MODULATOR() ioctl handler code.
  238. *
  239. * @s_type_addr: sets tuner type and its I2C addr.
  240. *
  241. * @s_config: sets tda9887 specific stuff, like port1, port2 and qss
  242. *
  243. * .. note::
  244. *
  245. * On devices that have both AM/FM and TV, it is up to the driver
  246. * to explicitly call s_radio when the tuner should be switched to
  247. * radio mode, before handling other &struct v4l2_subdev_tuner_ops
  248. * that would require it. An example of such usage is::
  249. *
  250. * static void s_frequency(void *priv, const struct v4l2_frequency *f)
  251. * {
  252. * ...
  253. * if (f.type == V4L2_TUNER_RADIO)
  254. * v4l2_device_call_all(v4l2_dev, 0, tuner, s_radio);
  255. * ...
  256. * v4l2_device_call_all(v4l2_dev, 0, tuner, s_frequency);
  257. * }
  258. */
  259. struct v4l2_subdev_tuner_ops {
  260. int (*standby)(struct v4l2_subdev *sd);
  261. int (*s_radio)(struct v4l2_subdev *sd);
  262. int (*s_frequency)(struct v4l2_subdev *sd, const struct v4l2_frequency *freq);
  263. int (*g_frequency)(struct v4l2_subdev *sd, struct v4l2_frequency *freq);
  264. int (*enum_freq_bands)(struct v4l2_subdev *sd, struct v4l2_frequency_band *band);
  265. int (*g_tuner)(struct v4l2_subdev *sd, struct v4l2_tuner *vt);
  266. int (*s_tuner)(struct v4l2_subdev *sd, const struct v4l2_tuner *vt);
  267. int (*g_modulator)(struct v4l2_subdev *sd, struct v4l2_modulator *vm);
  268. int (*s_modulator)(struct v4l2_subdev *sd, const struct v4l2_modulator *vm);
  269. int (*s_type_addr)(struct v4l2_subdev *sd, struct tuner_setup *type);
  270. int (*s_config)(struct v4l2_subdev *sd, const struct v4l2_priv_tun_config *config);
  271. };
  272. /**
  273. * struct v4l2_subdev_audio_ops - Callbacks used for audio-related settings
  274. *
  275. * @s_clock_freq: set the frequency (in Hz) of the audio clock output.
  276. * Used to slave an audio processor to the video decoder, ensuring that
  277. * audio and video remain synchronized. Usual values for the frequency
  278. * are 48000, 44100 or 32000 Hz. If the frequency is not supported, then
  279. * -EINVAL is returned.
  280. *
  281. * @s_i2s_clock_freq: sets I2S speed in bps. This is used to provide a standard
  282. * way to select I2S clock used by driving digital audio streams at some
  283. * board designs. Usual values for the frequency are 1024000 and 2048000.
  284. * If the frequency is not supported, then %-EINVAL is returned.
  285. *
  286. * @s_routing: used to define the input and/or output pins of an audio chip,
  287. * and any additional configuration data.
  288. * Never attempt to use user-level input IDs (e.g. Composite, S-Video,
  289. * Tuner) at this level. An i2c device shouldn't know about whether an
  290. * input pin is connected to a Composite connector, become on another
  291. * board or platform it might be connected to something else entirely.
  292. * The calling driver is responsible for mapping a user-level input to
  293. * the right pins on the i2c device.
  294. *
  295. * @s_stream: used to notify the audio code that stream will start or has
  296. * stopped.
  297. */
  298. struct v4l2_subdev_audio_ops {
  299. int (*s_clock_freq)(struct v4l2_subdev *sd, u32 freq);
  300. int (*s_i2s_clock_freq)(struct v4l2_subdev *sd, u32 freq);
  301. int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
  302. int (*s_stream)(struct v4l2_subdev *sd, int enable);
  303. };
  304. /**
  305. * struct v4l2_mbus_frame_desc_entry_csi2
  306. *
  307. * @vc: CSI-2 virtual channel
  308. * @dt: CSI-2 data type ID
  309. */
  310. struct v4l2_mbus_frame_desc_entry_csi2 {
  311. u8 vc;
  312. u8 dt;
  313. };
  314. /**
  315. * enum v4l2_mbus_frame_desc_flags - media bus frame description flags
  316. *
  317. * @V4L2_MBUS_FRAME_DESC_FL_LEN_MAX:
  318. * Indicates that &struct v4l2_mbus_frame_desc_entry->length field
  319. * specifies maximum data length.
  320. * @V4L2_MBUS_FRAME_DESC_FL_BLOB:
  321. * Indicates that the format does not have line offsets, i.e.
  322. * the receiver should use 1D DMA.
  323. */
  324. enum v4l2_mbus_frame_desc_flags {
  325. V4L2_MBUS_FRAME_DESC_FL_LEN_MAX = BIT(0),
  326. V4L2_MBUS_FRAME_DESC_FL_BLOB = BIT(1),
  327. };
  328. /**
  329. * struct v4l2_mbus_frame_desc_entry - media bus frame description structure
  330. *
  331. * @flags: bitmask flags, as defined by &enum v4l2_mbus_frame_desc_flags.
  332. * @stream: stream in routing configuration
  333. * @pixelcode: media bus pixel code, valid if @flags
  334. * %FRAME_DESC_FL_BLOB is not set.
  335. * @length: number of octets per frame, valid if @flags
  336. * %V4L2_MBUS_FRAME_DESC_FL_LEN_MAX is set.
  337. * @bus: Bus-specific frame descriptor parameters
  338. * @bus.csi2: CSI-2-specific bus configuration
  339. */
  340. struct v4l2_mbus_frame_desc_entry {
  341. enum v4l2_mbus_frame_desc_flags flags;
  342. u32 stream;
  343. u32 pixelcode;
  344. u32 length;
  345. union {
  346. struct v4l2_mbus_frame_desc_entry_csi2 csi2;
  347. } bus;
  348. };
  349. /*
  350. * If this number is too small, it should be dropped altogether and the
  351. * API switched to a dynamic number of frame descriptor entries.
  352. */
  353. #define V4L2_FRAME_DESC_ENTRY_MAX 8
  354. /**
  355. * enum v4l2_mbus_frame_desc_type - media bus frame description type
  356. *
  357. * @V4L2_MBUS_FRAME_DESC_TYPE_UNDEFINED:
  358. * Undefined frame desc type. Drivers should not use this, it is
  359. * for backwards compatibility.
  360. * @V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL:
  361. * Parallel media bus.
  362. * @V4L2_MBUS_FRAME_DESC_TYPE_CSI2:
  363. * CSI-2 media bus. Frame desc parameters must be set in
  364. * &struct v4l2_mbus_frame_desc_entry->csi2.
  365. */
  366. enum v4l2_mbus_frame_desc_type {
  367. V4L2_MBUS_FRAME_DESC_TYPE_UNDEFINED = 0,
  368. V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL,
  369. V4L2_MBUS_FRAME_DESC_TYPE_CSI2,
  370. };
  371. /**
  372. * struct v4l2_mbus_frame_desc - media bus data frame description
  373. * @type: type of the bus (enum v4l2_mbus_frame_desc_type)
  374. * @entry: frame descriptors array
  375. * @num_entries: number of entries in @entry array
  376. */
  377. struct v4l2_mbus_frame_desc {
  378. enum v4l2_mbus_frame_desc_type type;
  379. struct v4l2_mbus_frame_desc_entry entry[V4L2_FRAME_DESC_ENTRY_MAX];
  380. unsigned short num_entries;
  381. };
  382. /**
  383. * enum v4l2_subdev_pre_streamon_flags - Flags for pre_streamon subdev core op
  384. *
  385. * @V4L2_SUBDEV_PRE_STREAMON_FL_MANUAL_LP: Set the transmitter to either LP-11
  386. * or LP-111 mode before call to s_stream().
  387. */
  388. enum v4l2_subdev_pre_streamon_flags {
  389. V4L2_SUBDEV_PRE_STREAMON_FL_MANUAL_LP = BIT(0),
  390. };
  391. /**
  392. * struct v4l2_subdev_video_ops - Callbacks used when v4l device was opened
  393. * in video mode.
  394. *
  395. * @s_routing: see s_routing in audio_ops, except this version is for video
  396. * devices.
  397. *
  398. * @s_crystal_freq: sets the frequency of the crystal used to generate the
  399. * clocks in Hz. An extra flags field allows device specific configuration
  400. * regarding clock frequency dividers, etc. If not used, then set flags
  401. * to 0. If the frequency is not supported, then -EINVAL is returned.
  402. *
  403. * @g_std: callback for VIDIOC_G_STD() ioctl handler code.
  404. *
  405. * @s_std: callback for VIDIOC_S_STD() ioctl handler code.
  406. *
  407. * @s_std_output: set v4l2_std_id for video OUTPUT devices. This is ignored by
  408. * video input devices.
  409. *
  410. * @g_std_output: get current standard for video OUTPUT devices. This is ignored
  411. * by video input devices.
  412. *
  413. * @querystd: callback for VIDIOC_QUERYSTD() ioctl handler code.
  414. *
  415. * @g_tvnorms: get &v4l2_std_id with all standards supported by the video
  416. * CAPTURE device. This is ignored by video output devices.
  417. *
  418. * @g_tvnorms_output: get v4l2_std_id with all standards supported by the video
  419. * OUTPUT device. This is ignored by video capture devices.
  420. *
  421. * @g_input_status: get input status. Same as the status field in the
  422. * &struct v4l2_input
  423. *
  424. * @s_stream: start (enabled == 1) or stop (enabled == 0) streaming on the
  425. * sub-device. Failure on stop will remove any resources acquired in
  426. * streaming start, while the error code is still returned by the driver.
  427. * The caller shall track the subdev state, and shall not start or stop an
  428. * already started or stopped subdev. Also see call_s_stream wrapper in
  429. * v4l2-subdev.c.
  430. *
  431. * New drivers should instead implement &v4l2_subdev_pad_ops.enable_streams
  432. * and &v4l2_subdev_pad_ops.disable_streams operations, and use
  433. * v4l2_subdev_s_stream_helper for the &v4l2_subdev_video_ops.s_stream
  434. * operation to support legacy users.
  435. *
  436. * Drivers should also not call the .s_stream() subdev operation directly,
  437. * but use the v4l2_subdev_enable_streams() and
  438. * v4l2_subdev_disable_streams() helpers.
  439. *
  440. * @g_pixelaspect: callback to return the pixelaspect ratio.
  441. *
  442. * @s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev
  443. * can adjust @size to a lower value and must not write more data to the
  444. * buffer starting at @data than the original value of @size.
  445. *
  446. * @pre_streamon: May be called before streaming is actually started, to help
  447. * initialising the bus. Current usage is to set a CSI-2 transmitter to
  448. * LP-11 or LP-111 mode before streaming. See &enum
  449. * v4l2_subdev_pre_streamon_flags.
  450. *
  451. * pre_streamon shall return error if it cannot perform the operation as
  452. * indicated by the flags argument. In particular, -EACCES indicates lack
  453. * of support for the operation. The caller shall call post_streamoff for
  454. * each successful call of pre_streamon.
  455. *
  456. * @post_streamoff: Called after streaming is stopped, but if and only if
  457. * pre_streamon was called earlier.
  458. */
  459. struct v4l2_subdev_video_ops {
  460. int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
  461. int (*s_crystal_freq)(struct v4l2_subdev *sd, u32 freq, u32 flags);
  462. int (*g_std)(struct v4l2_subdev *sd, v4l2_std_id *norm);
  463. int (*s_std)(struct v4l2_subdev *sd, v4l2_std_id norm);
  464. int (*s_std_output)(struct v4l2_subdev *sd, v4l2_std_id std);
  465. int (*g_std_output)(struct v4l2_subdev *sd, v4l2_std_id *std);
  466. int (*querystd)(struct v4l2_subdev *sd, v4l2_std_id *std);
  467. int (*g_tvnorms)(struct v4l2_subdev *sd, v4l2_std_id *std);
  468. int (*g_tvnorms_output)(struct v4l2_subdev *sd, v4l2_std_id *std);
  469. int (*g_input_status)(struct v4l2_subdev *sd, u32 *status);
  470. int (*s_stream)(struct v4l2_subdev *sd, int enable);
  471. int (*g_pixelaspect)(struct v4l2_subdev *sd, struct v4l2_fract *aspect);
  472. int (*s_rx_buffer)(struct v4l2_subdev *sd, void *buf,
  473. unsigned int *size);
  474. int (*pre_streamon)(struct v4l2_subdev *sd, u32 flags);
  475. int (*post_streamoff)(struct v4l2_subdev *sd);
  476. };
  477. /**
  478. * struct v4l2_subdev_vbi_ops - Callbacks used when v4l device was opened
  479. * in video mode via the vbi device node.
  480. *
  481. * @decode_vbi_line: video decoders that support sliced VBI need to implement
  482. * this ioctl. Field p of the &struct v4l2_decode_vbi_line is set to the
  483. * start of the VBI data that was generated by the decoder. The driver
  484. * then parses the sliced VBI data and sets the other fields in the
  485. * struct accordingly. The pointer p is updated to point to the start of
  486. * the payload which can be copied verbatim into the data field of the
  487. * &struct v4l2_sliced_vbi_data. If no valid VBI data was found, then the
  488. * type field is set to 0 on return.
  489. *
  490. * @s_vbi_data: used to generate VBI signals on a video signal.
  491. * &struct v4l2_sliced_vbi_data is filled with the data packets that
  492. * should be output. Note that if you set the line field to 0, then that
  493. * VBI signal is disabled. If no valid VBI data was found, then the type
  494. * field is set to 0 on return.
  495. *
  496. * @g_vbi_data: used to obtain the sliced VBI packet from a readback register.
  497. * Not all video decoders support this. If no data is available because
  498. * the readback register contains invalid or erroneous data %-EIO is
  499. * returned. Note that you must fill in the 'id' member and the 'field'
  500. * member (to determine whether CC data from the first or second field
  501. * should be obtained).
  502. *
  503. * @g_sliced_vbi_cap: callback for VIDIOC_G_SLICED_VBI_CAP() ioctl handler
  504. * code.
  505. *
  506. * @s_raw_fmt: setup the video encoder/decoder for raw VBI.
  507. *
  508. * @g_sliced_fmt: retrieve the current sliced VBI settings.
  509. *
  510. * @s_sliced_fmt: setup the sliced VBI settings.
  511. */
  512. struct v4l2_subdev_vbi_ops {
  513. int (*decode_vbi_line)(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi_line);
  514. int (*s_vbi_data)(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *vbi_data);
  515. int (*g_vbi_data)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_data *vbi_data);
  516. int (*g_sliced_vbi_cap)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_cap *cap);
  517. int (*s_raw_fmt)(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt);
  518. int (*g_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
  519. int (*s_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
  520. };
  521. /**
  522. * struct v4l2_subdev_sensor_ops - v4l2-subdev sensor operations
  523. * @g_skip_top_lines: number of lines at the top of the image to be skipped.
  524. * This is needed for some sensors, which always corrupt
  525. * several top lines of the output image, or which send their
  526. * metadata in them.
  527. * @g_skip_frames: number of frames to skip at stream start. This is needed for
  528. * buggy sensors that generate faulty frames when they are
  529. * turned on.
  530. */
  531. struct v4l2_subdev_sensor_ops {
  532. int (*g_skip_top_lines)(struct v4l2_subdev *sd, u32 *lines);
  533. int (*g_skip_frames)(struct v4l2_subdev *sd, u32 *frames);
  534. };
  535. /**
  536. * enum v4l2_subdev_ir_mode- describes the type of IR supported
  537. *
  538. * @V4L2_SUBDEV_IR_MODE_PULSE_WIDTH: IR uses struct ir_raw_event records
  539. */
  540. enum v4l2_subdev_ir_mode {
  541. V4L2_SUBDEV_IR_MODE_PULSE_WIDTH,
  542. };
  543. /**
  544. * struct v4l2_subdev_ir_parameters - Parameters for IR TX or TX
  545. *
  546. * @bytes_per_data_element: bytes per data element of data in read or
  547. * write call.
  548. * @mode: IR mode as defined by &enum v4l2_subdev_ir_mode.
  549. * @enable: device is active if true
  550. * @interrupt_enable: IR interrupts are enabled if true
  551. * @shutdown: if true: set hardware to low/no power, false: normal mode
  552. *
  553. * @modulation: if true, it uses carrier, if false: baseband
  554. * @max_pulse_width: maximum pulse width in ns, valid only for baseband signal
  555. * @carrier_freq: carrier frequency in Hz, valid only for modulated signal
  556. * @duty_cycle: duty cycle percentage, valid only for modulated signal
  557. * @invert_level: invert signal level
  558. *
  559. * @invert_carrier_sense: Send 0/space as a carrier burst. used only in TX.
  560. *
  561. * @noise_filter_min_width: min time of a valid pulse, in ns. Used only for RX.
  562. * @carrier_range_lower: Lower carrier range, in Hz, valid only for modulated
  563. * signal. Used only for RX.
  564. * @carrier_range_upper: Upper carrier range, in Hz, valid only for modulated
  565. * signal. Used only for RX.
  566. * @resolution: The receive resolution, in ns . Used only for RX.
  567. */
  568. struct v4l2_subdev_ir_parameters {
  569. unsigned int bytes_per_data_element;
  570. enum v4l2_subdev_ir_mode mode;
  571. bool enable;
  572. bool interrupt_enable;
  573. bool shutdown;
  574. bool modulation;
  575. u32 max_pulse_width;
  576. unsigned int carrier_freq;
  577. unsigned int duty_cycle;
  578. bool invert_level;
  579. /* Tx only */
  580. bool invert_carrier_sense;
  581. /* Rx only */
  582. u32 noise_filter_min_width;
  583. unsigned int carrier_range_lower;
  584. unsigned int carrier_range_upper;
  585. u32 resolution;
  586. };
  587. /**
  588. * struct v4l2_subdev_ir_ops - operations for IR subdevices
  589. *
  590. * @rx_read: Reads received codes or pulse width data.
  591. * The semantics are similar to a non-blocking read() call.
  592. * @rx_g_parameters: Get the current operating parameters and state of
  593. * the IR receiver.
  594. * @rx_s_parameters: Set the current operating parameters and state of
  595. * the IR receiver. It is recommended to call
  596. * [rt]x_g_parameters first to fill out the current state, and only change
  597. * the fields that need to be changed. Upon return, the actual device
  598. * operating parameters and state will be returned. Note that hardware
  599. * limitations may prevent the actual settings from matching the requested
  600. * settings - e.g. an actual carrier setting of 35,904 Hz when 36,000 Hz
  601. * was requested. An exception is when the shutdown parameter is true.
  602. * The last used operational parameters will be returned, but the actual
  603. * state of the hardware be different to minimize power consumption and
  604. * processing when shutdown is true.
  605. *
  606. * @tx_write: Writes codes or pulse width data for transmission.
  607. * The semantics are similar to a non-blocking write() call.
  608. * @tx_g_parameters: Get the current operating parameters and state of
  609. * the IR transmitter.
  610. * @tx_s_parameters: Set the current operating parameters and state of
  611. * the IR transmitter. It is recommended to call
  612. * [rt]x_g_parameters first to fill out the current state, and only change
  613. * the fields that need to be changed. Upon return, the actual device
  614. * operating parameters and state will be returned. Note that hardware
  615. * limitations may prevent the actual settings from matching the requested
  616. * settings - e.g. an actual carrier setting of 35,904 Hz when 36,000 Hz
  617. * was requested. An exception is when the shutdown parameter is true.
  618. * The last used operational parameters will be returned, but the actual
  619. * state of the hardware be different to minimize power consumption and
  620. * processing when shutdown is true.
  621. */
  622. struct v4l2_subdev_ir_ops {
  623. /* Receiver */
  624. int (*rx_read)(struct v4l2_subdev *sd, u8 *buf, size_t count,
  625. ssize_t *num);
  626. int (*rx_g_parameters)(struct v4l2_subdev *sd,
  627. struct v4l2_subdev_ir_parameters *params);
  628. int (*rx_s_parameters)(struct v4l2_subdev *sd,
  629. struct v4l2_subdev_ir_parameters *params);
  630. /* Transmitter */
  631. int (*tx_write)(struct v4l2_subdev *sd, u8 *buf, size_t count,
  632. ssize_t *num);
  633. int (*tx_g_parameters)(struct v4l2_subdev *sd,
  634. struct v4l2_subdev_ir_parameters *params);
  635. int (*tx_s_parameters)(struct v4l2_subdev *sd,
  636. struct v4l2_subdev_ir_parameters *params);
  637. };
  638. /**
  639. * struct v4l2_subdev_pad_config - Used for storing subdev pad information.
  640. *
  641. * @format: &struct v4l2_mbus_framefmt
  642. * @crop: &struct v4l2_rect to be used for crop
  643. * @compose: &struct v4l2_rect to be used for compose
  644. * @interval: frame interval
  645. */
  646. struct v4l2_subdev_pad_config {
  647. struct v4l2_mbus_framefmt format;
  648. struct v4l2_rect crop;
  649. struct v4l2_rect compose;
  650. struct v4l2_fract interval;
  651. };
  652. /**
  653. * struct v4l2_subdev_stream_config - Used for storing stream configuration.
  654. *
  655. * @pad: pad number
  656. * @stream: stream number
  657. * @enabled: has the stream been enabled with v4l2_subdev_enable_streams()
  658. * @fmt: &struct v4l2_mbus_framefmt
  659. * @crop: &struct v4l2_rect to be used for crop
  660. * @compose: &struct v4l2_rect to be used for compose
  661. * @interval: frame interval
  662. *
  663. * This structure stores configuration for a stream.
  664. */
  665. struct v4l2_subdev_stream_config {
  666. u32 pad;
  667. u32 stream;
  668. bool enabled;
  669. struct v4l2_mbus_framefmt fmt;
  670. struct v4l2_rect crop;
  671. struct v4l2_rect compose;
  672. struct v4l2_fract interval;
  673. };
  674. /**
  675. * struct v4l2_subdev_stream_configs - A collection of stream configs.
  676. *
  677. * @num_configs: number of entries in @config.
  678. * @configs: an array of &struct v4l2_subdev_stream_configs.
  679. */
  680. struct v4l2_subdev_stream_configs {
  681. u32 num_configs;
  682. struct v4l2_subdev_stream_config *configs;
  683. };
  684. /**
  685. * struct v4l2_subdev_krouting - subdev routing table
  686. *
  687. * @len_routes: length of routes array, in routes
  688. * @num_routes: number of routes
  689. * @routes: &struct v4l2_subdev_route
  690. *
  691. * This structure contains the routing table for a subdev.
  692. */
  693. struct v4l2_subdev_krouting {
  694. unsigned int len_routes;
  695. unsigned int num_routes;
  696. struct v4l2_subdev_route *routes;
  697. };
  698. /**
  699. * struct v4l2_subdev_state - Used for storing subdev state information.
  700. *
  701. * @_lock: default for 'lock'
  702. * @lock: mutex for the state. May be replaced by the user.
  703. * @sd: the sub-device which the state is related to
  704. * @pads: &struct v4l2_subdev_pad_config array
  705. * @routing: routing table for the subdev
  706. * @stream_configs: stream configurations (only for V4L2_SUBDEV_FL_STREAMS)
  707. *
  708. * This structure only needs to be passed to the pad op if the 'which' field
  709. * of the main argument is set to %V4L2_SUBDEV_FORMAT_TRY. For
  710. * %V4L2_SUBDEV_FORMAT_ACTIVE it is safe to pass %NULL.
  711. */
  712. struct v4l2_subdev_state {
  713. /* lock for the struct v4l2_subdev_state fields */
  714. struct mutex _lock;
  715. struct mutex *lock;
  716. struct v4l2_subdev *sd;
  717. struct v4l2_subdev_pad_config *pads;
  718. struct v4l2_subdev_krouting routing;
  719. struct v4l2_subdev_stream_configs stream_configs;
  720. };
  721. /**
  722. * struct v4l2_subdev_pad_ops - v4l2-subdev pad level operations
  723. *
  724. * @enum_mbus_code: callback for VIDIOC_SUBDEV_ENUM_MBUS_CODE() ioctl handler
  725. * code.
  726. * @enum_frame_size: callback for VIDIOC_SUBDEV_ENUM_FRAME_SIZE() ioctl handler
  727. * code.
  728. *
  729. * @enum_frame_interval: callback for VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL() ioctl
  730. * handler code.
  731. *
  732. * @get_fmt: callback for VIDIOC_SUBDEV_G_FMT() ioctl handler code.
  733. *
  734. * @set_fmt: callback for VIDIOC_SUBDEV_S_FMT() ioctl handler code.
  735. *
  736. * @get_selection: callback for VIDIOC_SUBDEV_G_SELECTION() ioctl handler code.
  737. *
  738. * @set_selection: callback for VIDIOC_SUBDEV_S_SELECTION() ioctl handler code.
  739. *
  740. * @get_frame_interval: callback for VIDIOC_SUBDEV_G_FRAME_INTERVAL()
  741. * ioctl handler code.
  742. *
  743. * @set_frame_interval: callback for VIDIOC_SUBDEV_S_FRAME_INTERVAL()
  744. * ioctl handler code.
  745. *
  746. * @get_edid: callback for VIDIOC_SUBDEV_G_EDID() ioctl handler code.
  747. *
  748. * @set_edid: callback for VIDIOC_SUBDEV_S_EDID() ioctl handler code.
  749. *
  750. * @s_dv_timings: Set custom dv timings in the sub device. This is used
  751. * when sub device is capable of setting detailed timing information
  752. * in the hardware to generate/detect the video signal.
  753. *
  754. * @g_dv_timings: Get custom dv timings in the sub device.
  755. *
  756. * @query_dv_timings: callback for VIDIOC_QUERY_DV_TIMINGS() ioctl handler code.
  757. *
  758. * @dv_timings_cap: callback for VIDIOC_SUBDEV_DV_TIMINGS_CAP() ioctl handler
  759. * code.
  760. *
  761. * @enum_dv_timings: callback for VIDIOC_SUBDEV_ENUM_DV_TIMINGS() ioctl handler
  762. * code.
  763. *
  764. * @link_validate: used by the media controller code to check if the links
  765. * that belongs to a pipeline can be used for stream.
  766. *
  767. * @get_frame_desc: get the current low level media bus frame parameters.
  768. *
  769. * @set_frame_desc: set the low level media bus frame parameters, @fd array
  770. * may be adjusted by the subdev driver to device capabilities.
  771. *
  772. * @get_mbus_config: get the media bus configuration of a remote sub-device.
  773. * The media bus configuration is usually retrieved from the
  774. * firmware interface at sub-device probe time, immediately
  775. * applied to the hardware and eventually adjusted by the
  776. * driver. Remote sub-devices (usually video receivers) shall
  777. * use this operation to query the transmitting end bus
  778. * configuration in order to adjust their own one accordingly.
  779. * Callers should make sure they get the most up-to-date as
  780. * possible configuration from the remote end, likely calling
  781. * this operation as close as possible to stream on time. The
  782. * operation shall fail if the pad index it has been called on
  783. * is not valid or in case of unrecoverable failures.
  784. *
  785. * @set_routing: Enable or disable data connection routes described in the
  786. * subdevice routing table. Subdevs that implement this operation
  787. * must set the V4L2_SUBDEV_FL_STREAMS flag.
  788. *
  789. * @enable_streams: Enable the streams defined in streams_mask on the given
  790. * source pad. Subdevs that implement this operation must use the active
  791. * state management provided by the subdev core (enabled through a call to
  792. * v4l2_subdev_init_finalize() at initialization time). Do not call
  793. * directly, use v4l2_subdev_enable_streams() instead.
  794. *
  795. * @disable_streams: Disable the streams defined in streams_mask on the given
  796. * source pad. Subdevs that implement this operation must use the active
  797. * state management provided by the subdev core (enabled through a call to
  798. * v4l2_subdev_init_finalize() at initialization time). Do not call
  799. * directly, use v4l2_subdev_disable_streams() instead.
  800. */
  801. struct v4l2_subdev_pad_ops {
  802. int (*enum_mbus_code)(struct v4l2_subdev *sd,
  803. struct v4l2_subdev_state *state,
  804. struct v4l2_subdev_mbus_code_enum *code);
  805. int (*enum_frame_size)(struct v4l2_subdev *sd,
  806. struct v4l2_subdev_state *state,
  807. struct v4l2_subdev_frame_size_enum *fse);
  808. int (*enum_frame_interval)(struct v4l2_subdev *sd,
  809. struct v4l2_subdev_state *state,
  810. struct v4l2_subdev_frame_interval_enum *fie);
  811. int (*get_fmt)(struct v4l2_subdev *sd,
  812. struct v4l2_subdev_state *state,
  813. struct v4l2_subdev_format *format);
  814. int (*set_fmt)(struct v4l2_subdev *sd,
  815. struct v4l2_subdev_state *state,
  816. struct v4l2_subdev_format *format);
  817. int (*get_selection)(struct v4l2_subdev *sd,
  818. struct v4l2_subdev_state *state,
  819. struct v4l2_subdev_selection *sel);
  820. int (*set_selection)(struct v4l2_subdev *sd,
  821. struct v4l2_subdev_state *state,
  822. struct v4l2_subdev_selection *sel);
  823. int (*get_frame_interval)(struct v4l2_subdev *sd,
  824. struct v4l2_subdev_state *state,
  825. struct v4l2_subdev_frame_interval *interval);
  826. int (*set_frame_interval)(struct v4l2_subdev *sd,
  827. struct v4l2_subdev_state *state,
  828. struct v4l2_subdev_frame_interval *interval);
  829. int (*get_edid)(struct v4l2_subdev *sd, struct v4l2_edid *edid);
  830. int (*set_edid)(struct v4l2_subdev *sd, struct v4l2_edid *edid);
  831. int (*s_dv_timings)(struct v4l2_subdev *sd, unsigned int pad,
  832. struct v4l2_dv_timings *timings);
  833. int (*g_dv_timings)(struct v4l2_subdev *sd, unsigned int pad,
  834. struct v4l2_dv_timings *timings);
  835. int (*query_dv_timings)(struct v4l2_subdev *sd, unsigned int pad,
  836. struct v4l2_dv_timings *timings);
  837. int (*dv_timings_cap)(struct v4l2_subdev *sd,
  838. struct v4l2_dv_timings_cap *cap);
  839. int (*enum_dv_timings)(struct v4l2_subdev *sd,
  840. struct v4l2_enum_dv_timings *timings);
  841. #ifdef CONFIG_MEDIA_CONTROLLER
  842. int (*link_validate)(struct v4l2_subdev *sd, struct media_link *link,
  843. struct v4l2_subdev_format *source_fmt,
  844. struct v4l2_subdev_format *sink_fmt);
  845. #endif /* CONFIG_MEDIA_CONTROLLER */
  846. int (*get_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
  847. struct v4l2_mbus_frame_desc *fd);
  848. int (*set_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
  849. struct v4l2_mbus_frame_desc *fd);
  850. int (*get_mbus_config)(struct v4l2_subdev *sd, unsigned int pad,
  851. struct v4l2_mbus_config *config);
  852. int (*set_routing)(struct v4l2_subdev *sd,
  853. struct v4l2_subdev_state *state,
  854. enum v4l2_subdev_format_whence which,
  855. struct v4l2_subdev_krouting *route);
  856. int (*enable_streams)(struct v4l2_subdev *sd,
  857. struct v4l2_subdev_state *state, u32 pad,
  858. u64 streams_mask);
  859. int (*disable_streams)(struct v4l2_subdev *sd,
  860. struct v4l2_subdev_state *state, u32 pad,
  861. u64 streams_mask);
  862. };
  863. /**
  864. * struct v4l2_subdev_ops - Subdev operations
  865. *
  866. * @core: pointer to &struct v4l2_subdev_core_ops. Can be %NULL
  867. * @tuner: pointer to &struct v4l2_subdev_tuner_ops. Can be %NULL
  868. * @audio: pointer to &struct v4l2_subdev_audio_ops. Can be %NULL
  869. * @video: pointer to &struct v4l2_subdev_video_ops. Can be %NULL
  870. * @vbi: pointer to &struct v4l2_subdev_vbi_ops. Can be %NULL
  871. * @ir: pointer to &struct v4l2_subdev_ir_ops. Can be %NULL
  872. * @sensor: pointer to &struct v4l2_subdev_sensor_ops. Can be %NULL
  873. * @pad: pointer to &struct v4l2_subdev_pad_ops. Can be %NULL
  874. */
  875. struct v4l2_subdev_ops {
  876. const struct v4l2_subdev_core_ops *core;
  877. const struct v4l2_subdev_tuner_ops *tuner;
  878. const struct v4l2_subdev_audio_ops *audio;
  879. const struct v4l2_subdev_video_ops *video;
  880. const struct v4l2_subdev_vbi_ops *vbi;
  881. const struct v4l2_subdev_ir_ops *ir;
  882. const struct v4l2_subdev_sensor_ops *sensor;
  883. const struct v4l2_subdev_pad_ops *pad;
  884. };
  885. /**
  886. * struct v4l2_subdev_internal_ops - V4L2 subdev internal ops
  887. *
  888. * @init_state: initialize the subdev state to default values
  889. *
  890. * @registered: called when this subdev is registered. When called the v4l2_dev
  891. * field is set to the correct v4l2_device.
  892. *
  893. * @unregistered: called when this subdev is unregistered. When called the
  894. * v4l2_dev field is still set to the correct v4l2_device.
  895. *
  896. * @open: called when the subdev device node is opened by an application.
  897. *
  898. * @close: called when the subdev device node is closed. Please note that
  899. * it is possible for @close to be called after @unregistered!
  900. *
  901. * @release: called when the last user of the subdev device is gone. This
  902. * happens after the @unregistered callback and when the last open
  903. * filehandle to the v4l-subdevX device node was closed. If no device
  904. * node was created for this sub-device, then the @release callback
  905. * is called right after the @unregistered callback.
  906. * The @release callback is typically used to free the memory containing
  907. * the v4l2_subdev structure. It is almost certainly required for any
  908. * sub-device that sets the V4L2_SUBDEV_FL_HAS_DEVNODE flag.
  909. *
  910. * .. note::
  911. * Never call this from drivers, only the v4l2 framework can call
  912. * these ops.
  913. */
  914. struct v4l2_subdev_internal_ops {
  915. int (*init_state)(struct v4l2_subdev *sd,
  916. struct v4l2_subdev_state *state);
  917. int (*registered)(struct v4l2_subdev *sd);
  918. void (*unregistered)(struct v4l2_subdev *sd);
  919. int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
  920. int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
  921. void (*release)(struct v4l2_subdev *sd);
  922. };
  923. /* Set this flag if this subdev is a i2c device. */
  924. #define V4L2_SUBDEV_FL_IS_I2C (1U << 0)
  925. /* Set this flag if this subdev is a spi device. */
  926. #define V4L2_SUBDEV_FL_IS_SPI (1U << 1)
  927. /* Set this flag if this subdev needs a device node. */
  928. #define V4L2_SUBDEV_FL_HAS_DEVNODE (1U << 2)
  929. /*
  930. * Set this flag if this subdev generates events.
  931. * Note controls can send events, thus drivers exposing controls
  932. * should set this flag.
  933. */
  934. #define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
  935. /*
  936. * Set this flag if this subdev supports multiplexed streams. This means
  937. * that the driver supports routing and handles the stream parameter in its
  938. * v4l2_subdev_pad_ops handlers. More specifically, this means:
  939. *
  940. * - Centrally managed subdev active state is enabled
  941. * - Legacy pad config is _not_ supported (state->pads is NULL)
  942. * - Routing ioctls are available
  943. * - Multiple streams per pad are supported
  944. */
  945. #define V4L2_SUBDEV_FL_STREAMS (1U << 4)
  946. struct regulator_bulk_data;
  947. /**
  948. * struct v4l2_subdev_platform_data - regulators config struct
  949. *
  950. * @regulators: Optional regulators used to power on/off the subdevice
  951. * @num_regulators: Number of regululators
  952. * @host_priv: Per-subdevice data, specific for a certain video host device
  953. */
  954. struct v4l2_subdev_platform_data {
  955. struct regulator_bulk_data *regulators;
  956. int num_regulators;
  957. void *host_priv;
  958. };
  959. /**
  960. * struct v4l2_subdev - describes a V4L2 sub-device
  961. *
  962. * @entity: pointer to &struct media_entity
  963. * @list: List of sub-devices
  964. * @owner: The owner is the same as the driver's &struct device owner.
  965. * @owner_v4l2_dev: true if the &sd->owner matches the owner of @v4l2_dev->dev
  966. * owner. Initialized by v4l2_device_register_subdev().
  967. * @flags: subdev flags. Can be:
  968. * %V4L2_SUBDEV_FL_IS_I2C - Set this flag if this subdev is a i2c device;
  969. * %V4L2_SUBDEV_FL_IS_SPI - Set this flag if this subdev is a spi device;
  970. * %V4L2_SUBDEV_FL_HAS_DEVNODE - Set this flag if this subdev needs a
  971. * device node;
  972. * %V4L2_SUBDEV_FL_HAS_EVENTS - Set this flag if this subdev generates
  973. * events.
  974. *
  975. * @v4l2_dev: pointer to struct &v4l2_device
  976. * @ops: pointer to struct &v4l2_subdev_ops
  977. * @internal_ops: pointer to struct &v4l2_subdev_internal_ops.
  978. * Never call these internal ops from within a driver!
  979. * @ctrl_handler: The control handler of this subdev. May be NULL.
  980. * @name: Name of the sub-device. Please notice that the name must be unique.
  981. * @grp_id: can be used to group similar subdevs. Value is driver-specific
  982. * @dev_priv: pointer to private data
  983. * @host_priv: pointer to private data used by the device where the subdev
  984. * is attached.
  985. * @devnode: subdev device node
  986. * @dev: pointer to the physical device, if any
  987. * @fwnode: The fwnode_handle of the subdev, usually the same as
  988. * either dev->of_node->fwnode or dev->fwnode (whichever is non-NULL).
  989. * @async_list: Links this subdev to a global subdev_list or
  990. * @notifier->done_list list.
  991. * @async_subdev_endpoint_list: List entry in async_subdev_endpoint_entry of
  992. * &struct v4l2_async_subdev_endpoint.
  993. * @subdev_notifier: A sub-device notifier implicitly registered for the sub-
  994. * device using v4l2_async_register_subdev_sensor().
  995. * @asc_list: Async connection list, of &struct
  996. * v4l2_async_connection.subdev_entry.
  997. * @pdata: common part of subdevice platform data
  998. * @state_lock: A pointer to a lock used for all the subdev's states, set by the
  999. * driver. This is optional. If NULL, each state instance will get
  1000. * a lock of its own.
  1001. * @privacy_led: Optional pointer to a LED classdev for the privacy LED for sensors.
  1002. * @active_state: Active state for the subdev (NULL for subdevs tracking the
  1003. * state internally). Initialized by calling
  1004. * v4l2_subdev_init_finalize().
  1005. * @enabled_pads: Bitmask of enabled pads used by v4l2_subdev_enable_streams()
  1006. * and v4l2_subdev_disable_streams() helper functions for
  1007. * fallback cases.
  1008. * @s_stream_enabled: Tracks whether streaming has been enabled with s_stream.
  1009. * This is only for call_s_stream() internal use.
  1010. *
  1011. * Each instance of a subdev driver should create this struct, either
  1012. * stand-alone or embedded in a larger struct.
  1013. *
  1014. * This structure should be initialized by v4l2_subdev_init() or one of
  1015. * its variants: v4l2_spi_subdev_init(), v4l2_i2c_subdev_init().
  1016. */
  1017. struct v4l2_subdev {
  1018. #if defined(CONFIG_MEDIA_CONTROLLER)
  1019. struct media_entity entity;
  1020. #endif
  1021. struct list_head list;
  1022. struct module *owner;
  1023. bool owner_v4l2_dev;
  1024. u32 flags;
  1025. struct v4l2_device *v4l2_dev;
  1026. const struct v4l2_subdev_ops *ops;
  1027. const struct v4l2_subdev_internal_ops *internal_ops;
  1028. struct v4l2_ctrl_handler *ctrl_handler;
  1029. char name[52];
  1030. u32 grp_id;
  1031. void *dev_priv;
  1032. void *host_priv;
  1033. struct video_device *devnode;
  1034. struct device *dev;
  1035. struct fwnode_handle *fwnode;
  1036. struct list_head async_list;
  1037. struct list_head async_subdev_endpoint_list;
  1038. struct v4l2_async_notifier *subdev_notifier;
  1039. struct list_head asc_list;
  1040. struct v4l2_subdev_platform_data *pdata;
  1041. struct mutex *state_lock;
  1042. /*
  1043. * The fields below are private, and should only be accessed via
  1044. * appropriate functions.
  1045. */
  1046. struct led_classdev *privacy_led;
  1047. /*
  1048. * TODO: active_state should most likely be changed from a pointer to an
  1049. * embedded field. For the time being it's kept as a pointer to more
  1050. * easily catch uses of active_state in the cases where the driver
  1051. * doesn't support it.
  1052. */
  1053. struct v4l2_subdev_state *active_state;
  1054. u64 enabled_pads;
  1055. bool s_stream_enabled;
  1056. };
  1057. /**
  1058. * media_entity_to_v4l2_subdev - Returns a &struct v4l2_subdev from
  1059. * the &struct media_entity embedded in it.
  1060. *
  1061. * @ent: pointer to &struct media_entity.
  1062. */
  1063. #define media_entity_to_v4l2_subdev(ent) \
  1064. ({ \
  1065. typeof(ent) __me_sd_ent = (ent); \
  1066. \
  1067. __me_sd_ent ? \
  1068. container_of(__me_sd_ent, struct v4l2_subdev, entity) : \
  1069. NULL; \
  1070. })
  1071. /**
  1072. * vdev_to_v4l2_subdev - Returns a &struct v4l2_subdev from
  1073. * the &struct video_device embedded on it.
  1074. *
  1075. * @vdev: pointer to &struct video_device
  1076. */
  1077. #define vdev_to_v4l2_subdev(vdev) \
  1078. ((struct v4l2_subdev *)video_get_drvdata(vdev))
  1079. /**
  1080. * struct v4l2_subdev_fh - Used for storing subdev information per file handle
  1081. *
  1082. * @vfh: pointer to &struct v4l2_fh
  1083. * @state: pointer to &struct v4l2_subdev_state
  1084. * @owner: module pointer to the owner of this file handle
  1085. * @client_caps: bitmask of ``V4L2_SUBDEV_CLIENT_CAP_*``
  1086. */
  1087. struct v4l2_subdev_fh {
  1088. struct v4l2_fh vfh;
  1089. struct module *owner;
  1090. #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
  1091. struct v4l2_subdev_state *state;
  1092. u64 client_caps;
  1093. #endif
  1094. };
  1095. /**
  1096. * to_v4l2_subdev_fh - Returns a &struct v4l2_subdev_fh from
  1097. * the &struct v4l2_fh embedded on it.
  1098. *
  1099. * @fh: pointer to &struct v4l2_fh
  1100. */
  1101. #define to_v4l2_subdev_fh(fh) \
  1102. container_of(fh, struct v4l2_subdev_fh, vfh)
  1103. extern const struct v4l2_file_operations v4l2_subdev_fops;
  1104. /**
  1105. * v4l2_set_subdevdata - Sets V4L2 dev private device data
  1106. *
  1107. * @sd: pointer to &struct v4l2_subdev
  1108. * @p: pointer to the private device data to be stored.
  1109. */
  1110. static inline void v4l2_set_subdevdata(struct v4l2_subdev *sd, void *p)
  1111. {
  1112. sd->dev_priv = p;
  1113. }
  1114. /**
  1115. * v4l2_get_subdevdata - Gets V4L2 dev private device data
  1116. *
  1117. * @sd: pointer to &struct v4l2_subdev
  1118. *
  1119. * Returns the pointer to the private device data to be stored.
  1120. */
  1121. static inline void *v4l2_get_subdevdata(const struct v4l2_subdev *sd)
  1122. {
  1123. return sd->dev_priv;
  1124. }
  1125. /**
  1126. * v4l2_set_subdev_hostdata - Sets V4L2 dev private host data
  1127. *
  1128. * @sd: pointer to &struct v4l2_subdev
  1129. * @p: pointer to the private data to be stored.
  1130. */
  1131. static inline void v4l2_set_subdev_hostdata(struct v4l2_subdev *sd, void *p)
  1132. {
  1133. sd->host_priv = p;
  1134. }
  1135. /**
  1136. * v4l2_get_subdev_hostdata - Gets V4L2 dev private data
  1137. *
  1138. * @sd: pointer to &struct v4l2_subdev
  1139. *
  1140. * Returns the pointer to the private host data to be stored.
  1141. */
  1142. static inline void *v4l2_get_subdev_hostdata(const struct v4l2_subdev *sd)
  1143. {
  1144. return sd->host_priv;
  1145. }
  1146. #ifdef CONFIG_MEDIA_CONTROLLER
  1147. /**
  1148. * v4l2_subdev_get_fwnode_pad_1_to_1 - Get pad number from a subdev fwnode
  1149. * endpoint, assuming 1:1 port:pad
  1150. *
  1151. * @entity: Pointer to the subdev entity
  1152. * @endpoint: Pointer to a parsed fwnode endpoint
  1153. *
  1154. * This function can be used as the .get_fwnode_pad operation for
  1155. * subdevices that map port numbers and pad indexes 1:1. If the endpoint
  1156. * is owned by the subdevice, the function returns the endpoint port
  1157. * number.
  1158. *
  1159. * Returns the endpoint port number on success or a negative error code.
  1160. */
  1161. int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity,
  1162. struct fwnode_endpoint *endpoint);
  1163. /**
  1164. * v4l2_subdev_link_validate_default - validates a media link
  1165. *
  1166. * @sd: pointer to &struct v4l2_subdev
  1167. * @link: pointer to &struct media_link
  1168. * @source_fmt: pointer to &struct v4l2_subdev_format
  1169. * @sink_fmt: pointer to &struct v4l2_subdev_format
  1170. *
  1171. * This function ensures that width, height and the media bus pixel
  1172. * code are equal on both source and sink of the link.
  1173. */
  1174. int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
  1175. struct media_link *link,
  1176. struct v4l2_subdev_format *source_fmt,
  1177. struct v4l2_subdev_format *sink_fmt);
  1178. /**
  1179. * v4l2_subdev_link_validate - validates a media link
  1180. *
  1181. * @link: pointer to &struct media_link
  1182. *
  1183. * This function calls the subdev's link_validate ops to validate
  1184. * if a media link is valid for streaming. It also internally
  1185. * calls v4l2_subdev_link_validate_default() to ensure that
  1186. * width, height and the media bus pixel code are equal on both
  1187. * source and sink of the link.
  1188. *
  1189. * The function can be used as a drop-in &media_entity_ops.link_validate
  1190. * implementation for v4l2_subdev instances. It supports all links between
  1191. * subdevs, as well as links between subdevs and video devices, provided that
  1192. * the video devices also implement their &media_entity_ops.link_validate
  1193. * operation.
  1194. */
  1195. int v4l2_subdev_link_validate(struct media_link *link);
  1196. /**
  1197. * v4l2_subdev_has_pad_interdep - MC has_pad_interdep implementation for subdevs
  1198. *
  1199. * @entity: pointer to &struct media_entity
  1200. * @pad0: pad number for the first pad
  1201. * @pad1: pad number for the second pad
  1202. *
  1203. * This function is an implementation of the
  1204. * media_entity_operations.has_pad_interdep operation for subdevs that
  1205. * implement the multiplexed streams API (as indicated by the
  1206. * V4L2_SUBDEV_FL_STREAMS subdev flag).
  1207. *
  1208. * It considers two pads interdependent if there is an active route between pad0
  1209. * and pad1.
  1210. */
  1211. bool v4l2_subdev_has_pad_interdep(struct media_entity *entity,
  1212. unsigned int pad0, unsigned int pad1);
  1213. /**
  1214. * __v4l2_subdev_state_alloc - allocate v4l2_subdev_state
  1215. *
  1216. * @sd: pointer to &struct v4l2_subdev for which the state is being allocated.
  1217. * @lock_name: name of the state lock
  1218. * @key: lock_class_key for the lock
  1219. *
  1220. * Must call __v4l2_subdev_state_free() when state is no longer needed.
  1221. *
  1222. * Not to be called directly by the drivers.
  1223. */
  1224. struct v4l2_subdev_state *__v4l2_subdev_state_alloc(struct v4l2_subdev *sd,
  1225. const char *lock_name,
  1226. struct lock_class_key *key);
  1227. /**
  1228. * __v4l2_subdev_state_free - free a v4l2_subdev_state
  1229. *
  1230. * @state: v4l2_subdev_state to be freed.
  1231. *
  1232. * Not to be called directly by the drivers.
  1233. */
  1234. void __v4l2_subdev_state_free(struct v4l2_subdev_state *state);
  1235. /**
  1236. * v4l2_subdev_init_finalize() - Finalizes the initialization of the subdevice
  1237. * @sd: The subdev
  1238. *
  1239. * This function finalizes the initialization of the subdev, including
  1240. * allocation of the active state for the subdev.
  1241. *
  1242. * This function must be called by the subdev drivers that use the centralized
  1243. * active state, after the subdev struct has been initialized and
  1244. * media_entity_pads_init() has been called, but before registering the
  1245. * subdev.
  1246. *
  1247. * The user must call v4l2_subdev_cleanup() when the subdev is being removed.
  1248. */
  1249. #define v4l2_subdev_init_finalize(sd) \
  1250. ({ \
  1251. static struct lock_class_key __key; \
  1252. const char *name = KBUILD_BASENAME \
  1253. ":" __stringify(__LINE__) ":sd->active_state->lock"; \
  1254. __v4l2_subdev_init_finalize(sd, name, &__key); \
  1255. })
  1256. int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name,
  1257. struct lock_class_key *key);
  1258. /**
  1259. * v4l2_subdev_cleanup() - Releases the resources allocated by the subdevice
  1260. * @sd: The subdevice
  1261. *
  1262. * Clean up a V4L2 async sub-device. Must be called for a sub-device as part of
  1263. * its release if resources have been associated with it using
  1264. * v4l2_async_subdev_endpoint_add() or v4l2_subdev_init_finalize().
  1265. */
  1266. void v4l2_subdev_cleanup(struct v4l2_subdev *sd);
  1267. /*
  1268. * A macro to generate the macro or function name for sub-devices state access
  1269. * wrapper macros below.
  1270. */
  1271. #define __v4l2_subdev_state_gen_call(NAME, _1, ARG, ...) \
  1272. __v4l2_subdev_state_get_ ## NAME ## ARG
  1273. /*
  1274. * A macro to constify the return value of the state accessors when the state
  1275. * parameter is const.
  1276. */
  1277. #define __v4l2_subdev_state_constify_ret(state, value) \
  1278. _Generic(state, \
  1279. const struct v4l2_subdev_state *: (const typeof(*(value)) *)(value), \
  1280. struct v4l2_subdev_state *: (value) \
  1281. )
  1282. /**
  1283. * v4l2_subdev_state_get_format() - Get pointer to a stream format
  1284. * @state: subdevice state
  1285. * @pad: pad id
  1286. * @...: stream id (optional argument)
  1287. *
  1288. * This returns a pointer to &struct v4l2_mbus_framefmt for the given pad +
  1289. * stream in the subdev state.
  1290. *
  1291. * For stream-unaware drivers the format for the corresponding pad is returned.
  1292. * If the pad does not exist, NULL is returned.
  1293. */
  1294. /*
  1295. * Wrap v4l2_subdev_state_get_format(), allowing the function to be called with
  1296. * two or three arguments. The purpose of the __v4l2_subdev_state_gen_call()
  1297. * macro is to come up with the name of the function or macro to call, using
  1298. * the last two arguments (_stream and _pad). The selected function or macro is
  1299. * then called using the arguments specified by the caller. The
  1300. * __v4l2_subdev_state_constify_ret() macro constifies the returned pointer
  1301. * when the state is const, allowing the state accessors to guarantee
  1302. * const-correctness in all cases.
  1303. *
  1304. * A similar arrangement is used for v4l2_subdev_state_crop(),
  1305. * v4l2_subdev_state_compose() and v4l2_subdev_state_get_interval() below.
  1306. */
  1307. #define v4l2_subdev_state_get_format(state, pad, ...) \
  1308. __v4l2_subdev_state_constify_ret(state, \
  1309. __v4l2_subdev_state_gen_call(format, ##__VA_ARGS__, , _pad) \
  1310. ((struct v4l2_subdev_state *)state, pad, ##__VA_ARGS__))
  1311. #define __v4l2_subdev_state_get_format_pad(state, pad) \
  1312. __v4l2_subdev_state_get_format(state, pad, 0)
  1313. struct v4l2_mbus_framefmt *
  1314. __v4l2_subdev_state_get_format(struct v4l2_subdev_state *state,
  1315. unsigned int pad, u32 stream);
  1316. /**
  1317. * v4l2_subdev_state_get_crop() - Get pointer to a stream crop rectangle
  1318. * @state: subdevice state
  1319. * @pad: pad id
  1320. * @...: stream id (optional argument)
  1321. *
  1322. * This returns a pointer to crop rectangle for the given pad + stream in the
  1323. * subdev state.
  1324. *
  1325. * For stream-unaware drivers the crop rectangle for the corresponding pad is
  1326. * returned. If the pad does not exist, NULL is returned.
  1327. */
  1328. #define v4l2_subdev_state_get_crop(state, pad, ...) \
  1329. __v4l2_subdev_state_constify_ret(state, \
  1330. __v4l2_subdev_state_gen_call(crop, ##__VA_ARGS__, , _pad) \
  1331. ((struct v4l2_subdev_state *)state, pad, ##__VA_ARGS__))
  1332. #define __v4l2_subdev_state_get_crop_pad(state, pad) \
  1333. __v4l2_subdev_state_get_crop(state, pad, 0)
  1334. struct v4l2_rect *
  1335. __v4l2_subdev_state_get_crop(struct v4l2_subdev_state *state, unsigned int pad,
  1336. u32 stream);
  1337. /**
  1338. * v4l2_subdev_state_get_compose() - Get pointer to a stream compose rectangle
  1339. * @state: subdevice state
  1340. * @pad: pad id
  1341. * @...: stream id (optional argument)
  1342. *
  1343. * This returns a pointer to compose rectangle for the given pad + stream in the
  1344. * subdev state.
  1345. *
  1346. * For stream-unaware drivers the compose rectangle for the corresponding pad is
  1347. * returned. If the pad does not exist, NULL is returned.
  1348. */
  1349. #define v4l2_subdev_state_get_compose(state, pad, ...) \
  1350. __v4l2_subdev_state_constify_ret(state, \
  1351. __v4l2_subdev_state_gen_call(compose, ##__VA_ARGS__, , _pad) \
  1352. ((struct v4l2_subdev_state *)state, pad, ##__VA_ARGS__))
  1353. #define __v4l2_subdev_state_get_compose_pad(state, pad) \
  1354. __v4l2_subdev_state_get_compose(state, pad, 0)
  1355. struct v4l2_rect *
  1356. __v4l2_subdev_state_get_compose(struct v4l2_subdev_state *state,
  1357. unsigned int pad, u32 stream);
  1358. /**
  1359. * v4l2_subdev_state_get_interval() - Get pointer to a stream frame interval
  1360. * @state: subdevice state
  1361. * @pad: pad id
  1362. * @...: stream id (optional argument)
  1363. *
  1364. * This returns a pointer to the frame interval for the given pad + stream in
  1365. * the subdev state.
  1366. *
  1367. * For stream-unaware drivers the frame interval for the corresponding pad is
  1368. * returned. If the pad does not exist, NULL is returned.
  1369. */
  1370. #define v4l2_subdev_state_get_interval(state, pad, ...) \
  1371. __v4l2_subdev_state_constify_ret(state, \
  1372. __v4l2_subdev_state_gen_call(interval, ##__VA_ARGS__, , _pad) \
  1373. ((struct v4l2_subdev_state *)state, pad, ##__VA_ARGS__))
  1374. #define __v4l2_subdev_state_get_interval_pad(state, pad) \
  1375. __v4l2_subdev_state_get_interval(state, pad, 0)
  1376. struct v4l2_fract *
  1377. __v4l2_subdev_state_get_interval(struct v4l2_subdev_state *state,
  1378. unsigned int pad, u32 stream);
  1379. #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
  1380. /**
  1381. * v4l2_subdev_get_fmt() - Fill format based on state
  1382. * @sd: subdevice
  1383. * @state: subdevice state
  1384. * @format: pointer to &struct v4l2_subdev_format
  1385. *
  1386. * Fill @format->format field based on the information in the @format struct.
  1387. *
  1388. * This function can be used by the subdev drivers which support active state to
  1389. * implement v4l2_subdev_pad_ops.get_fmt if the subdev driver does not need to
  1390. * do anything special in their get_fmt op.
  1391. *
  1392. * Returns 0 on success, error value otherwise.
  1393. */
  1394. int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
  1395. struct v4l2_subdev_format *format);
  1396. /**
  1397. * v4l2_subdev_get_frame_interval() - Fill frame interval based on state
  1398. * @sd: subdevice
  1399. * @state: subdevice state
  1400. * @fi: pointer to &struct v4l2_subdev_frame_interval
  1401. *
  1402. * Fill @fi->interval field based on the information in the @fi struct.
  1403. *
  1404. * This function can be used by the subdev drivers which support active state to
  1405. * implement v4l2_subdev_pad_ops.get_frame_interval if the subdev driver does
  1406. * not need to do anything special in their get_frame_interval op.
  1407. *
  1408. * Returns 0 on success, error value otherwise.
  1409. */
  1410. int v4l2_subdev_get_frame_interval(struct v4l2_subdev *sd,
  1411. struct v4l2_subdev_state *state,
  1412. struct v4l2_subdev_frame_interval *fi);
  1413. /**
  1414. * v4l2_subdev_set_routing() - Set given routing to subdev state
  1415. * @sd: The subdevice
  1416. * @state: The subdevice state
  1417. * @routing: Routing that will be copied to subdev state
  1418. *
  1419. * This will release old routing table (if any) from the state, allocate
  1420. * enough space for the given routing, and copy the routing.
  1421. *
  1422. * This can be used from the subdev driver's set_routing op, after validating
  1423. * the routing.
  1424. */
  1425. int v4l2_subdev_set_routing(struct v4l2_subdev *sd,
  1426. struct v4l2_subdev_state *state,
  1427. const struct v4l2_subdev_krouting *routing);
  1428. struct v4l2_subdev_route *
  1429. __v4l2_subdev_next_active_route(const struct v4l2_subdev_krouting *routing,
  1430. struct v4l2_subdev_route *route);
  1431. /**
  1432. * for_each_active_route - iterate on all active routes of a routing table
  1433. * @routing: The routing table
  1434. * @route: The route iterator
  1435. */
  1436. #define for_each_active_route(routing, route) \
  1437. for ((route) = NULL; \
  1438. ((route) = __v4l2_subdev_next_active_route((routing), (route)));)
  1439. /**
  1440. * v4l2_subdev_set_routing_with_fmt() - Set given routing and format to subdev
  1441. * state
  1442. * @sd: The subdevice
  1443. * @state: The subdevice state
  1444. * @routing: Routing that will be copied to subdev state
  1445. * @fmt: Format used to initialize all the streams
  1446. *
  1447. * This is the same as v4l2_subdev_set_routing, but additionally initializes
  1448. * all the streams using the given format.
  1449. */
  1450. int v4l2_subdev_set_routing_with_fmt(struct v4l2_subdev *sd,
  1451. struct v4l2_subdev_state *state,
  1452. const struct v4l2_subdev_krouting *routing,
  1453. const struct v4l2_mbus_framefmt *fmt);
  1454. /**
  1455. * v4l2_subdev_routing_find_opposite_end() - Find the opposite stream
  1456. * @routing: routing used to find the opposite side
  1457. * @pad: pad id
  1458. * @stream: stream id
  1459. * @other_pad: pointer used to return the opposite pad
  1460. * @other_stream: pointer used to return the opposite stream
  1461. *
  1462. * This function uses the routing table to find the pad + stream which is
  1463. * opposite the given pad + stream.
  1464. *
  1465. * @other_pad and/or @other_stream can be NULL if the caller does not need the
  1466. * value.
  1467. *
  1468. * Returns 0 on success, or -EINVAL if no matching route is found.
  1469. */
  1470. int v4l2_subdev_routing_find_opposite_end(const struct v4l2_subdev_krouting *routing,
  1471. u32 pad, u32 stream, u32 *other_pad,
  1472. u32 *other_stream);
  1473. /**
  1474. * v4l2_subdev_state_get_opposite_stream_format() - Get pointer to opposite
  1475. * stream format
  1476. * @state: subdevice state
  1477. * @pad: pad id
  1478. * @stream: stream id
  1479. *
  1480. * This returns a pointer to &struct v4l2_mbus_framefmt for the pad + stream
  1481. * that is opposite the given pad + stream in the subdev state.
  1482. *
  1483. * If the state does not contain the given pad + stream, NULL is returned.
  1484. */
  1485. struct v4l2_mbus_framefmt *
  1486. v4l2_subdev_state_get_opposite_stream_format(struct v4l2_subdev_state *state,
  1487. u32 pad, u32 stream);
  1488. /**
  1489. * v4l2_subdev_state_xlate_streams() - Translate streams from one pad to another
  1490. *
  1491. * @state: Subdevice state
  1492. * @pad0: The first pad
  1493. * @pad1: The second pad
  1494. * @streams: Streams bitmask on the first pad
  1495. *
  1496. * Streams on sink pads of a subdev are routed to source pads as expressed in
  1497. * the subdev state routing table. Stream numbers don't necessarily match on
  1498. * the sink and source side of a route. This function translates stream numbers
  1499. * on @pad0, expressed as a bitmask in @streams, to the corresponding streams
  1500. * on @pad1 using the routing table from the @state. It returns the stream mask
  1501. * on @pad1, and updates @streams with the streams that have been found in the
  1502. * routing table.
  1503. *
  1504. * @pad0 and @pad1 must be a sink and a source, in any order.
  1505. *
  1506. * Return: The bitmask of streams of @pad1 that are routed to @streams on @pad0.
  1507. */
  1508. u64 v4l2_subdev_state_xlate_streams(const struct v4l2_subdev_state *state,
  1509. u32 pad0, u32 pad1, u64 *streams);
  1510. /**
  1511. * enum v4l2_subdev_routing_restriction - Subdevice internal routing restrictions
  1512. *
  1513. * @V4L2_SUBDEV_ROUTING_NO_1_TO_N:
  1514. * an input stream shall not be routed to multiple output streams (stream
  1515. * duplication)
  1516. * @V4L2_SUBDEV_ROUTING_NO_N_TO_1:
  1517. * multiple input streams shall not be routed to the same output stream
  1518. * (stream merging)
  1519. * @V4L2_SUBDEV_ROUTING_NO_SINK_STREAM_MIX:
  1520. * all streams from a sink pad must be routed to a single source pad
  1521. * @V4L2_SUBDEV_ROUTING_NO_SOURCE_STREAM_MIX:
  1522. * all streams on a source pad must originate from a single sink pad
  1523. * @V4L2_SUBDEV_ROUTING_NO_SOURCE_MULTIPLEXING:
  1524. * source pads shall not contain multiplexed streams
  1525. * @V4L2_SUBDEV_ROUTING_NO_SINK_MULTIPLEXING:
  1526. * sink pads shall not contain multiplexed streams
  1527. * @V4L2_SUBDEV_ROUTING_ONLY_1_TO_1:
  1528. * only non-overlapping 1-to-1 stream routing is allowed (a combination of
  1529. * @V4L2_SUBDEV_ROUTING_NO_1_TO_N and @V4L2_SUBDEV_ROUTING_NO_N_TO_1)
  1530. * @V4L2_SUBDEV_ROUTING_NO_STREAM_MIX:
  1531. * all streams from a sink pad must be routed to a single source pad, and
  1532. * that source pad shall not get routes from any other sink pad
  1533. * (a combination of @V4L2_SUBDEV_ROUTING_NO_SINK_STREAM_MIX and
  1534. * @V4L2_SUBDEV_ROUTING_NO_SOURCE_STREAM_MIX)
  1535. * @V4L2_SUBDEV_ROUTING_NO_MULTIPLEXING:
  1536. * no multiplexed streams allowed on either source or sink sides.
  1537. */
  1538. enum v4l2_subdev_routing_restriction {
  1539. V4L2_SUBDEV_ROUTING_NO_1_TO_N = BIT(0),
  1540. V4L2_SUBDEV_ROUTING_NO_N_TO_1 = BIT(1),
  1541. V4L2_SUBDEV_ROUTING_NO_SINK_STREAM_MIX = BIT(2),
  1542. V4L2_SUBDEV_ROUTING_NO_SOURCE_STREAM_MIX = BIT(3),
  1543. V4L2_SUBDEV_ROUTING_NO_SINK_MULTIPLEXING = BIT(4),
  1544. V4L2_SUBDEV_ROUTING_NO_SOURCE_MULTIPLEXING = BIT(5),
  1545. V4L2_SUBDEV_ROUTING_ONLY_1_TO_1 =
  1546. V4L2_SUBDEV_ROUTING_NO_1_TO_N |
  1547. V4L2_SUBDEV_ROUTING_NO_N_TO_1,
  1548. V4L2_SUBDEV_ROUTING_NO_STREAM_MIX =
  1549. V4L2_SUBDEV_ROUTING_NO_SINK_STREAM_MIX |
  1550. V4L2_SUBDEV_ROUTING_NO_SOURCE_STREAM_MIX,
  1551. V4L2_SUBDEV_ROUTING_NO_MULTIPLEXING =
  1552. V4L2_SUBDEV_ROUTING_NO_SINK_MULTIPLEXING |
  1553. V4L2_SUBDEV_ROUTING_NO_SOURCE_MULTIPLEXING,
  1554. };
  1555. /**
  1556. * v4l2_subdev_routing_validate() - Verify that routes comply with driver
  1557. * constraints
  1558. * @sd: The subdevice
  1559. * @routing: Routing to verify
  1560. * @disallow: Restrictions on routes
  1561. *
  1562. * This verifies that the given routing complies with the @disallow constraints.
  1563. *
  1564. * Returns 0 on success, error value otherwise.
  1565. */
  1566. int v4l2_subdev_routing_validate(struct v4l2_subdev *sd,
  1567. const struct v4l2_subdev_krouting *routing,
  1568. enum v4l2_subdev_routing_restriction disallow);
  1569. /**
  1570. * v4l2_subdev_enable_streams() - Enable streams on a pad
  1571. * @sd: The subdevice
  1572. * @pad: The pad
  1573. * @streams_mask: Bitmask of streams to enable
  1574. *
  1575. * This function enables streams on a source @pad of a subdevice. The pad is
  1576. * identified by its index, while the streams are identified by the
  1577. * @streams_mask bitmask. This allows enabling multiple streams on a pad at
  1578. * once.
  1579. *
  1580. * Enabling a stream that is already enabled isn't allowed. If @streams_mask
  1581. * contains an already enabled stream, this function returns -EALREADY without
  1582. * performing any operation.
  1583. *
  1584. * Per-stream enable is only available for subdevs that implement the
  1585. * .enable_streams() and .disable_streams() operations. For other subdevs, this
  1586. * function implements a best-effort compatibility by calling the .s_stream()
  1587. * operation, limited to subdevs that have a single source pad.
  1588. *
  1589. * Return:
  1590. * * 0: Success
  1591. * * -EALREADY: One of the streams in streams_mask is already enabled
  1592. * * -EINVAL: The pad index is invalid, or doesn't correspond to a source pad
  1593. * * -EOPNOTSUPP: Falling back to the legacy .s_stream() operation is
  1594. * impossible because the subdev has multiple source pads
  1595. */
  1596. int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad,
  1597. u64 streams_mask);
  1598. /**
  1599. * v4l2_subdev_disable_streams() - Disable streams on a pad
  1600. * @sd: The subdevice
  1601. * @pad: The pad
  1602. * @streams_mask: Bitmask of streams to disable
  1603. *
  1604. * This function disables streams on a source @pad of a subdevice. The pad is
  1605. * identified by its index, while the streams are identified by the
  1606. * @streams_mask bitmask. This allows disabling multiple streams on a pad at
  1607. * once.
  1608. *
  1609. * Disabling a streams that is not enabled isn't allowed. If @streams_mask
  1610. * contains a disabled stream, this function returns -EALREADY without
  1611. * performing any operation.
  1612. *
  1613. * Per-stream disable is only available for subdevs that implement the
  1614. * .enable_streams() and .disable_streams() operations. For other subdevs, this
  1615. * function implements a best-effort compatibility by calling the .s_stream()
  1616. * operation, limited to subdevs that have a single source pad.
  1617. *
  1618. * Return:
  1619. * * 0: Success
  1620. * * -EALREADY: One of the streams in streams_mask is not enabled
  1621. * * -EINVAL: The pad index is invalid, or doesn't correspond to a source pad
  1622. * * -EOPNOTSUPP: Falling back to the legacy .s_stream() operation is
  1623. * impossible because the subdev has multiple source pads
  1624. */
  1625. int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad,
  1626. u64 streams_mask);
  1627. /**
  1628. * v4l2_subdev_s_stream_helper() - Helper to implement the subdev s_stream
  1629. * operation using enable_streams and disable_streams
  1630. * @sd: The subdevice
  1631. * @enable: Enable or disable streaming
  1632. *
  1633. * Subdevice drivers that implement the streams-aware
  1634. * &v4l2_subdev_pad_ops.enable_streams and &v4l2_subdev_pad_ops.disable_streams
  1635. * operations can use this helper to implement the legacy
  1636. * &v4l2_subdev_video_ops.s_stream operation.
  1637. *
  1638. * This helper can only be used by subdevs that have a single source pad.
  1639. *
  1640. * Return: 0 on success, or a negative error code otherwise.
  1641. */
  1642. int v4l2_subdev_s_stream_helper(struct v4l2_subdev *sd, int enable);
  1643. #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
  1644. #endif /* CONFIG_MEDIA_CONTROLLER */
  1645. /**
  1646. * v4l2_subdev_lock_state() - Locks the subdev state
  1647. * @state: The subdevice state
  1648. *
  1649. * Locks the given subdev state.
  1650. *
  1651. * The state must be unlocked with v4l2_subdev_unlock_state() after use.
  1652. */
  1653. static inline void v4l2_subdev_lock_state(struct v4l2_subdev_state *state)
  1654. {
  1655. mutex_lock(state->lock);
  1656. }
  1657. /**
  1658. * v4l2_subdev_unlock_state() - Unlocks the subdev state
  1659. * @state: The subdevice state
  1660. *
  1661. * Unlocks the given subdev state.
  1662. */
  1663. static inline void v4l2_subdev_unlock_state(struct v4l2_subdev_state *state)
  1664. {
  1665. mutex_unlock(state->lock);
  1666. }
  1667. /**
  1668. * v4l2_subdev_lock_states - Lock two sub-device states
  1669. * @state1: One subdevice state
  1670. * @state2: The other subdevice state
  1671. *
  1672. * Locks the state of two sub-devices.
  1673. *
  1674. * The states must be unlocked with v4l2_subdev_unlock_states() after use.
  1675. *
  1676. * This differs from calling v4l2_subdev_lock_state() on both states so that if
  1677. * the states share the same lock, the lock is acquired only once (so no
  1678. * deadlock occurs). The caller is responsible for ensuring the locks will
  1679. * always be acquired in the same order.
  1680. */
  1681. static inline void v4l2_subdev_lock_states(struct v4l2_subdev_state *state1,
  1682. struct v4l2_subdev_state *state2)
  1683. {
  1684. mutex_lock(state1->lock);
  1685. if (state1->lock != state2->lock)
  1686. mutex_lock(state2->lock);
  1687. }
  1688. /**
  1689. * v4l2_subdev_unlock_states() - Unlock two sub-device states
  1690. * @state1: One subdevice state
  1691. * @state2: The other subdevice state
  1692. *
  1693. * Unlocks the state of two sub-devices.
  1694. *
  1695. * This differs from calling v4l2_subdev_unlock_state() on both states so that
  1696. * if the states share the same lock, the lock is released only once.
  1697. */
  1698. static inline void v4l2_subdev_unlock_states(struct v4l2_subdev_state *state1,
  1699. struct v4l2_subdev_state *state2)
  1700. {
  1701. mutex_unlock(state1->lock);
  1702. if (state1->lock != state2->lock)
  1703. mutex_unlock(state2->lock);
  1704. }
  1705. /**
  1706. * v4l2_subdev_get_unlocked_active_state() - Checks that the active subdev state
  1707. * is unlocked and returns it
  1708. * @sd: The subdevice
  1709. *
  1710. * Returns the active state for the subdevice, or NULL if the subdev does not
  1711. * support active state. If the state is not NULL, calls
  1712. * lockdep_assert_not_held() to issue a warning if the state is locked.
  1713. *
  1714. * This function is to be used e.g. when getting the active state for the sole
  1715. * purpose of passing it forward, without accessing the state fields.
  1716. */
  1717. static inline struct v4l2_subdev_state *
  1718. v4l2_subdev_get_unlocked_active_state(struct v4l2_subdev *sd)
  1719. {
  1720. if (sd->active_state)
  1721. lockdep_assert_not_held(sd->active_state->lock);
  1722. return sd->active_state;
  1723. }
  1724. /**
  1725. * v4l2_subdev_get_locked_active_state() - Checks that the active subdev state
  1726. * is locked and returns it
  1727. *
  1728. * @sd: The subdevice
  1729. *
  1730. * Returns the active state for the subdevice, or NULL if the subdev does not
  1731. * support active state. If the state is not NULL, calls lockdep_assert_held()
  1732. * to issue a warning if the state is not locked.
  1733. *
  1734. * This function is to be used when the caller knows that the active state is
  1735. * already locked.
  1736. */
  1737. static inline struct v4l2_subdev_state *
  1738. v4l2_subdev_get_locked_active_state(struct v4l2_subdev *sd)
  1739. {
  1740. if (sd->active_state)
  1741. lockdep_assert_held(sd->active_state->lock);
  1742. return sd->active_state;
  1743. }
  1744. /**
  1745. * v4l2_subdev_lock_and_get_active_state() - Locks and returns the active subdev
  1746. * state for the subdevice
  1747. * @sd: The subdevice
  1748. *
  1749. * Returns the locked active state for the subdevice, or NULL if the subdev
  1750. * does not support active state.
  1751. *
  1752. * The state must be unlocked with v4l2_subdev_unlock_state() after use.
  1753. */
  1754. static inline struct v4l2_subdev_state *
  1755. v4l2_subdev_lock_and_get_active_state(struct v4l2_subdev *sd)
  1756. {
  1757. if (sd->active_state)
  1758. v4l2_subdev_lock_state(sd->active_state);
  1759. return sd->active_state;
  1760. }
  1761. /**
  1762. * v4l2_subdev_init - initializes the sub-device struct
  1763. *
  1764. * @sd: pointer to the &struct v4l2_subdev to be initialized
  1765. * @ops: pointer to &struct v4l2_subdev_ops.
  1766. */
  1767. void v4l2_subdev_init(struct v4l2_subdev *sd,
  1768. const struct v4l2_subdev_ops *ops);
  1769. extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers;
  1770. /**
  1771. * v4l2_subdev_call - call an operation of a v4l2_subdev.
  1772. *
  1773. * @sd: pointer to the &struct v4l2_subdev
  1774. * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
  1775. * Each element there groups a set of callbacks functions.
  1776. * @f: callback function to be called.
  1777. * The callback functions are defined in groups, according to
  1778. * each element at &struct v4l2_subdev_ops.
  1779. * @args: arguments for @f.
  1780. *
  1781. * Example: err = v4l2_subdev_call(sd, video, s_std, norm);
  1782. */
  1783. #define v4l2_subdev_call(sd, o, f, args...) \
  1784. ({ \
  1785. struct v4l2_subdev *__sd = (sd); \
  1786. int __result; \
  1787. if (!__sd) \
  1788. __result = -ENODEV; \
  1789. else if (!(__sd->ops->o && __sd->ops->o->f)) \
  1790. __result = -ENOIOCTLCMD; \
  1791. else if (v4l2_subdev_call_wrappers.o && \
  1792. v4l2_subdev_call_wrappers.o->f) \
  1793. __result = v4l2_subdev_call_wrappers.o->f( \
  1794. __sd, ##args); \
  1795. else \
  1796. __result = __sd->ops->o->f(__sd, ##args); \
  1797. __result; \
  1798. })
  1799. /**
  1800. * v4l2_subdev_call_state_active - call an operation of a v4l2_subdev which
  1801. * takes state as a parameter, passing the
  1802. * subdev its active state.
  1803. *
  1804. * @sd: pointer to the &struct v4l2_subdev
  1805. * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
  1806. * Each element there groups a set of callbacks functions.
  1807. * @f: callback function to be called.
  1808. * The callback functions are defined in groups, according to
  1809. * each element at &struct v4l2_subdev_ops.
  1810. * @args: arguments for @f.
  1811. *
  1812. * This is similar to v4l2_subdev_call(), except that this version can only be
  1813. * used for ops that take a subdev state as a parameter. The macro will get the
  1814. * active state, lock it before calling the op and unlock it after the call.
  1815. */
  1816. #define v4l2_subdev_call_state_active(sd, o, f, args...) \
  1817. ({ \
  1818. int __result; \
  1819. struct v4l2_subdev_state *state; \
  1820. state = v4l2_subdev_get_unlocked_active_state(sd); \
  1821. if (state) \
  1822. v4l2_subdev_lock_state(state); \
  1823. __result = v4l2_subdev_call(sd, o, f, state, ##args); \
  1824. if (state) \
  1825. v4l2_subdev_unlock_state(state); \
  1826. __result; \
  1827. })
  1828. /**
  1829. * v4l2_subdev_call_state_try - call an operation of a v4l2_subdev which
  1830. * takes state as a parameter, passing the
  1831. * subdev a newly allocated try state.
  1832. *
  1833. * @sd: pointer to the &struct v4l2_subdev
  1834. * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
  1835. * Each element there groups a set of callbacks functions.
  1836. * @f: callback function to be called.
  1837. * The callback functions are defined in groups, according to
  1838. * each element at &struct v4l2_subdev_ops.
  1839. * @args: arguments for @f.
  1840. *
  1841. * This is similar to v4l2_subdev_call_state_active(), except that as this
  1842. * version allocates a new state, this is only usable for
  1843. * V4L2_SUBDEV_FORMAT_TRY use cases.
  1844. *
  1845. * Note: only legacy non-MC drivers may need this macro.
  1846. */
  1847. #define v4l2_subdev_call_state_try(sd, o, f, args...) \
  1848. ({ \
  1849. int __result; \
  1850. static struct lock_class_key __key; \
  1851. const char *name = KBUILD_BASENAME \
  1852. ":" __stringify(__LINE__) ":state->lock"; \
  1853. struct v4l2_subdev_state *state = \
  1854. __v4l2_subdev_state_alloc(sd, name, &__key); \
  1855. v4l2_subdev_lock_state(state); \
  1856. __result = v4l2_subdev_call(sd, o, f, state, ##args); \
  1857. v4l2_subdev_unlock_state(state); \
  1858. __v4l2_subdev_state_free(state); \
  1859. __result; \
  1860. })
  1861. /**
  1862. * v4l2_subdev_has_op - Checks if a subdev defines a certain operation.
  1863. *
  1864. * @sd: pointer to the &struct v4l2_subdev
  1865. * @o: The group of callback functions in &struct v4l2_subdev_ops
  1866. * which @f is a part of.
  1867. * @f: callback function to be checked for its existence.
  1868. */
  1869. #define v4l2_subdev_has_op(sd, o, f) \
  1870. ((sd)->ops->o && (sd)->ops->o->f)
  1871. /**
  1872. * v4l2_subdev_notify_event() - Delivers event notification for subdevice
  1873. * @sd: The subdev for which to deliver the event
  1874. * @ev: The event to deliver
  1875. *
  1876. * Will deliver the specified event to all userspace event listeners which are
  1877. * subscribed to the v42l subdev event queue as well as to the bridge driver
  1878. * using the notify callback. The notification type for the notify callback
  1879. * will be %V4L2_DEVICE_NOTIFY_EVENT.
  1880. */
  1881. void v4l2_subdev_notify_event(struct v4l2_subdev *sd,
  1882. const struct v4l2_event *ev);
  1883. /**
  1884. * v4l2_subdev_is_streaming() - Returns if the subdevice is streaming
  1885. * @sd: The subdevice
  1886. *
  1887. * v4l2_subdev_is_streaming() tells if the subdevice is currently streaming.
  1888. * "Streaming" here means whether .s_stream() or .enable_streams() has been
  1889. * successfully called, and the streaming has not yet been disabled.
  1890. *
  1891. * If the subdevice implements .enable_streams() this function must be called
  1892. * while holding the active state lock.
  1893. */
  1894. bool v4l2_subdev_is_streaming(struct v4l2_subdev *sd);
  1895. #endif /* _V4L2_SUBDEV_H */