v4l2-subdev.h 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011
  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. The
  784. * config argument has been memset to 0 just before calling
  785. * the op.
  786. *
  787. * @set_routing: Enable or disable data connection routes described in the
  788. * subdevice routing table. Subdevs that implement this operation
  789. * must set the V4L2_SUBDEV_FL_STREAMS flag.
  790. *
  791. * @enable_streams: Enable the streams defined in streams_mask on the given
  792. * source pad. Subdevs that implement this operation must use the active
  793. * state management provided by the subdev core (enabled through a call to
  794. * v4l2_subdev_init_finalize() at initialization time). Do not call
  795. * directly, use v4l2_subdev_enable_streams() instead.
  796. *
  797. * @disable_streams: Disable the streams defined in streams_mask on the given
  798. * source pad. Subdevs that implement this operation must use the active
  799. * state management provided by the subdev core (enabled through a call to
  800. * v4l2_subdev_init_finalize() at initialization time). Do not call
  801. * directly, use v4l2_subdev_disable_streams() instead.
  802. */
  803. struct v4l2_subdev_pad_ops {
  804. int (*enum_mbus_code)(struct v4l2_subdev *sd,
  805. struct v4l2_subdev_state *state,
  806. struct v4l2_subdev_mbus_code_enum *code);
  807. int (*enum_frame_size)(struct v4l2_subdev *sd,
  808. struct v4l2_subdev_state *state,
  809. struct v4l2_subdev_frame_size_enum *fse);
  810. int (*enum_frame_interval)(struct v4l2_subdev *sd,
  811. struct v4l2_subdev_state *state,
  812. struct v4l2_subdev_frame_interval_enum *fie);
  813. int (*get_fmt)(struct v4l2_subdev *sd,
  814. struct v4l2_subdev_state *state,
  815. struct v4l2_subdev_format *format);
  816. int (*set_fmt)(struct v4l2_subdev *sd,
  817. struct v4l2_subdev_state *state,
  818. struct v4l2_subdev_format *format);
  819. int (*get_selection)(struct v4l2_subdev *sd,
  820. struct v4l2_subdev_state *state,
  821. struct v4l2_subdev_selection *sel);
  822. int (*set_selection)(struct v4l2_subdev *sd,
  823. struct v4l2_subdev_state *state,
  824. struct v4l2_subdev_selection *sel);
  825. int (*get_frame_interval)(struct v4l2_subdev *sd,
  826. struct v4l2_subdev_state *state,
  827. struct v4l2_subdev_frame_interval *interval);
  828. int (*set_frame_interval)(struct v4l2_subdev *sd,
  829. struct v4l2_subdev_state *state,
  830. struct v4l2_subdev_frame_interval *interval);
  831. int (*get_edid)(struct v4l2_subdev *sd, struct v4l2_edid *edid);
  832. int (*set_edid)(struct v4l2_subdev *sd, struct v4l2_edid *edid);
  833. int (*s_dv_timings)(struct v4l2_subdev *sd, unsigned int pad,
  834. struct v4l2_dv_timings *timings);
  835. int (*g_dv_timings)(struct v4l2_subdev *sd, unsigned int pad,
  836. struct v4l2_dv_timings *timings);
  837. int (*query_dv_timings)(struct v4l2_subdev *sd, unsigned int pad,
  838. struct v4l2_dv_timings *timings);
  839. int (*dv_timings_cap)(struct v4l2_subdev *sd,
  840. struct v4l2_dv_timings_cap *cap);
  841. int (*enum_dv_timings)(struct v4l2_subdev *sd,
  842. struct v4l2_enum_dv_timings *timings);
  843. #ifdef CONFIG_MEDIA_CONTROLLER
  844. int (*link_validate)(struct v4l2_subdev *sd, struct media_link *link,
  845. struct v4l2_subdev_format *source_fmt,
  846. struct v4l2_subdev_format *sink_fmt);
  847. #endif /* CONFIG_MEDIA_CONTROLLER */
  848. int (*get_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
  849. struct v4l2_mbus_frame_desc *fd);
  850. int (*set_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
  851. struct v4l2_mbus_frame_desc *fd);
  852. int (*get_mbus_config)(struct v4l2_subdev *sd, unsigned int pad,
  853. struct v4l2_mbus_config *config);
  854. int (*set_routing)(struct v4l2_subdev *sd,
  855. struct v4l2_subdev_state *state,
  856. enum v4l2_subdev_format_whence which,
  857. struct v4l2_subdev_krouting *route);
  858. int (*enable_streams)(struct v4l2_subdev *sd,
  859. struct v4l2_subdev_state *state, u32 pad,
  860. u64 streams_mask);
  861. int (*disable_streams)(struct v4l2_subdev *sd,
  862. struct v4l2_subdev_state *state, u32 pad,
  863. u64 streams_mask);
  864. };
  865. /**
  866. * struct v4l2_subdev_ops - Subdev operations
  867. *
  868. * @core: pointer to &struct v4l2_subdev_core_ops. Can be %NULL
  869. * @tuner: pointer to &struct v4l2_subdev_tuner_ops. Can be %NULL
  870. * @audio: pointer to &struct v4l2_subdev_audio_ops. Can be %NULL
  871. * @video: pointer to &struct v4l2_subdev_video_ops. Can be %NULL
  872. * @vbi: pointer to &struct v4l2_subdev_vbi_ops. Can be %NULL
  873. * @ir: pointer to &struct v4l2_subdev_ir_ops. Can be %NULL
  874. * @sensor: pointer to &struct v4l2_subdev_sensor_ops. Can be %NULL
  875. * @pad: pointer to &struct v4l2_subdev_pad_ops. Can be %NULL
  876. */
  877. struct v4l2_subdev_ops {
  878. const struct v4l2_subdev_core_ops *core;
  879. const struct v4l2_subdev_tuner_ops *tuner;
  880. const struct v4l2_subdev_audio_ops *audio;
  881. const struct v4l2_subdev_video_ops *video;
  882. const struct v4l2_subdev_vbi_ops *vbi;
  883. const struct v4l2_subdev_ir_ops *ir;
  884. const struct v4l2_subdev_sensor_ops *sensor;
  885. const struct v4l2_subdev_pad_ops *pad;
  886. };
  887. /**
  888. * struct v4l2_subdev_internal_ops - V4L2 subdev internal ops
  889. *
  890. * @init_state: initialize the subdev state to default values
  891. *
  892. * @registered: called when this subdev is registered. When called the v4l2_dev
  893. * field is set to the correct v4l2_device.
  894. *
  895. * @unregistered: called when this subdev is unregistered. When called the
  896. * v4l2_dev field is still set to the correct v4l2_device.
  897. *
  898. * @open: called when the subdev device node is opened by an application.
  899. *
  900. * @close: called when the subdev device node is closed. Please note that
  901. * it is possible for @close to be called after @unregistered!
  902. *
  903. * @release: called when the last user of the subdev device is gone. This
  904. * happens after the @unregistered callback and when the last open
  905. * filehandle to the v4l-subdevX device node was closed. If no device
  906. * node was created for this sub-device, then the @release callback
  907. * is called right after the @unregistered callback.
  908. * The @release callback is typically used to free the memory containing
  909. * the v4l2_subdev structure. It is almost certainly required for any
  910. * sub-device that sets the V4L2_SUBDEV_FL_HAS_DEVNODE flag.
  911. *
  912. * .. note::
  913. * Never call this from drivers, only the v4l2 framework can call
  914. * these ops.
  915. */
  916. struct v4l2_subdev_internal_ops {
  917. int (*init_state)(struct v4l2_subdev *sd,
  918. struct v4l2_subdev_state *state);
  919. int (*registered)(struct v4l2_subdev *sd);
  920. void (*unregistered)(struct v4l2_subdev *sd);
  921. int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
  922. int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
  923. void (*release)(struct v4l2_subdev *sd);
  924. };
  925. /* Set this flag if this subdev is a i2c device. */
  926. #define V4L2_SUBDEV_FL_IS_I2C (1U << 0)
  927. /* Set this flag if this subdev is a spi device. */
  928. #define V4L2_SUBDEV_FL_IS_SPI (1U << 1)
  929. /* Set this flag if this subdev needs a device node. */
  930. #define V4L2_SUBDEV_FL_HAS_DEVNODE (1U << 2)
  931. /*
  932. * Set this flag if this subdev generates events.
  933. * Note controls can send events, thus drivers exposing controls
  934. * should set this flag.
  935. */
  936. #define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
  937. /*
  938. * Set this flag if this subdev supports multiplexed streams. This means
  939. * that the driver supports routing and handles the stream parameter in its
  940. * v4l2_subdev_pad_ops handlers. More specifically, this means:
  941. *
  942. * - Centrally managed subdev active state is enabled
  943. * - Legacy pad config is _not_ supported (state->pads is NULL)
  944. * - Routing ioctls are available
  945. * - Multiple streams per pad are supported
  946. */
  947. #define V4L2_SUBDEV_FL_STREAMS (1U << 4)
  948. struct regulator_bulk_data;
  949. /**
  950. * struct v4l2_subdev_platform_data - regulators config struct
  951. *
  952. * @regulators: Optional regulators used to power on/off the subdevice
  953. * @num_regulators: Number of regululators
  954. * @host_priv: Per-subdevice data, specific for a certain video host device
  955. */
  956. struct v4l2_subdev_platform_data {
  957. struct regulator_bulk_data *regulators;
  958. int num_regulators;
  959. void *host_priv;
  960. };
  961. /**
  962. * struct v4l2_subdev - describes a V4L2 sub-device
  963. *
  964. * @entity: pointer to &struct media_entity
  965. * @list: List of sub-devices
  966. * @owner: The owner is the same as the driver's &struct device owner.
  967. * @owner_v4l2_dev: true if the &sd->owner matches the owner of @v4l2_dev->dev
  968. * owner. Initialized by v4l2_device_register_subdev().
  969. * @flags: subdev flags. Can be:
  970. * %V4L2_SUBDEV_FL_IS_I2C - Set this flag if this subdev is a i2c device;
  971. * %V4L2_SUBDEV_FL_IS_SPI - Set this flag if this subdev is a spi device;
  972. * %V4L2_SUBDEV_FL_HAS_DEVNODE - Set this flag if this subdev needs a
  973. * device node;
  974. * %V4L2_SUBDEV_FL_HAS_EVENTS - Set this flag if this subdev generates
  975. * events.
  976. *
  977. * @v4l2_dev: pointer to struct &v4l2_device
  978. * @ops: pointer to struct &v4l2_subdev_ops
  979. * @internal_ops: pointer to struct &v4l2_subdev_internal_ops.
  980. * Never call these internal ops from within a driver!
  981. * @ctrl_handler: The control handler of this subdev. May be NULL.
  982. * @name: Name of the sub-device. Please notice that the name must be unique.
  983. * @grp_id: can be used to group similar subdevs. Value is driver-specific
  984. * @dev_priv: pointer to private data
  985. * @host_priv: pointer to private data used by the device where the subdev
  986. * is attached.
  987. * @devnode: subdev device node
  988. * @dev: pointer to the physical device, if any
  989. * @fwnode: The fwnode_handle of the subdev, usually the same as
  990. * either dev->of_node->fwnode or dev->fwnode (whichever is non-NULL).
  991. * @async_list: Links this subdev to a global subdev_list or
  992. * @notifier->done_list list.
  993. * @async_subdev_endpoint_list: List entry in async_subdev_endpoint_entry of
  994. * &struct v4l2_async_subdev_endpoint.
  995. * @subdev_notifier: A sub-device notifier implicitly registered for the sub-
  996. * device using v4l2_async_register_subdev_sensor().
  997. * @asc_list: Async connection list, of &struct
  998. * v4l2_async_connection.subdev_entry.
  999. * @pdata: common part of subdevice platform data
  1000. * @state_lock: A pointer to a lock used for all the subdev's states, set by the
  1001. * driver. This is optional. If NULL, each state instance will get
  1002. * a lock of its own.
  1003. * @privacy_led: Optional pointer to a LED classdev for the privacy LED for sensors.
  1004. * @active_state: Active state for the subdev (NULL for subdevs tracking the
  1005. * state internally). Initialized by calling
  1006. * v4l2_subdev_init_finalize().
  1007. * @enabled_pads: Bitmask of enabled pads used by v4l2_subdev_enable_streams()
  1008. * and v4l2_subdev_disable_streams() helper functions for
  1009. * fallback cases.
  1010. * @s_stream_enabled: Tracks whether streaming has been enabled with s_stream.
  1011. * This is only for call_s_stream() internal use.
  1012. *
  1013. * Each instance of a subdev driver should create this struct, either
  1014. * stand-alone or embedded in a larger struct.
  1015. *
  1016. * This structure should be initialized by v4l2_subdev_init() or one of
  1017. * its variants: v4l2_spi_subdev_init(), v4l2_i2c_subdev_init().
  1018. */
  1019. struct v4l2_subdev {
  1020. #if defined(CONFIG_MEDIA_CONTROLLER)
  1021. struct media_entity entity;
  1022. #endif
  1023. struct list_head list;
  1024. struct module *owner;
  1025. bool owner_v4l2_dev;
  1026. u32 flags;
  1027. struct v4l2_device *v4l2_dev;
  1028. const struct v4l2_subdev_ops *ops;
  1029. const struct v4l2_subdev_internal_ops *internal_ops;
  1030. struct v4l2_ctrl_handler *ctrl_handler;
  1031. char name[52];
  1032. u32 grp_id;
  1033. void *dev_priv;
  1034. void *host_priv;
  1035. struct video_device *devnode;
  1036. struct device *dev;
  1037. struct fwnode_handle *fwnode;
  1038. struct list_head async_list;
  1039. struct list_head async_subdev_endpoint_list;
  1040. struct v4l2_async_notifier *subdev_notifier;
  1041. struct list_head asc_list;
  1042. struct v4l2_subdev_platform_data *pdata;
  1043. struct mutex *state_lock;
  1044. /*
  1045. * The fields below are private, and should only be accessed via
  1046. * appropriate functions.
  1047. */
  1048. struct led_classdev *privacy_led;
  1049. /*
  1050. * TODO: active_state should most likely be changed from a pointer to an
  1051. * embedded field. For the time being it's kept as a pointer to more
  1052. * easily catch uses of active_state in the cases where the driver
  1053. * doesn't support it.
  1054. */
  1055. struct v4l2_subdev_state *active_state;
  1056. u64 enabled_pads;
  1057. bool s_stream_enabled;
  1058. };
  1059. /**
  1060. * media_entity_to_v4l2_subdev - Returns a &struct v4l2_subdev from
  1061. * the &struct media_entity embedded in it.
  1062. *
  1063. * @ent: pointer to &struct media_entity.
  1064. */
  1065. #define media_entity_to_v4l2_subdev(ent) \
  1066. ({ \
  1067. typeof(ent) __me_sd_ent = (ent); \
  1068. \
  1069. __me_sd_ent ? \
  1070. container_of(__me_sd_ent, struct v4l2_subdev, entity) : \
  1071. NULL; \
  1072. })
  1073. /**
  1074. * vdev_to_v4l2_subdev - Returns a &struct v4l2_subdev from
  1075. * the &struct video_device embedded on it.
  1076. *
  1077. * @vdev: pointer to &struct video_device
  1078. */
  1079. #define vdev_to_v4l2_subdev(vdev) \
  1080. ((struct v4l2_subdev *)video_get_drvdata(vdev))
  1081. /**
  1082. * struct v4l2_subdev_fh - Used for storing subdev information per file handle
  1083. *
  1084. * @vfh: pointer to &struct v4l2_fh
  1085. * @state: pointer to &struct v4l2_subdev_state
  1086. * @owner: module pointer to the owner of this file handle
  1087. * @client_caps: bitmask of ``V4L2_SUBDEV_CLIENT_CAP_*``
  1088. */
  1089. struct v4l2_subdev_fh {
  1090. struct v4l2_fh vfh;
  1091. struct module *owner;
  1092. #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
  1093. struct v4l2_subdev_state *state;
  1094. u64 client_caps;
  1095. #endif
  1096. };
  1097. /**
  1098. * to_v4l2_subdev_fh - Returns a &struct v4l2_subdev_fh from
  1099. * the &struct v4l2_fh embedded on it.
  1100. *
  1101. * @fh: pointer to &struct v4l2_fh
  1102. */
  1103. #define to_v4l2_subdev_fh(fh) \
  1104. container_of(fh, struct v4l2_subdev_fh, vfh)
  1105. extern const struct v4l2_file_operations v4l2_subdev_fops;
  1106. /**
  1107. * v4l2_set_subdevdata - Sets V4L2 dev private device data
  1108. *
  1109. * @sd: pointer to &struct v4l2_subdev
  1110. * @p: pointer to the private device data to be stored.
  1111. */
  1112. static inline void v4l2_set_subdevdata(struct v4l2_subdev *sd, void *p)
  1113. {
  1114. sd->dev_priv = p;
  1115. }
  1116. /**
  1117. * v4l2_get_subdevdata - Gets V4L2 dev private device data
  1118. *
  1119. * @sd: pointer to &struct v4l2_subdev
  1120. *
  1121. * Returns the pointer to the private device data to be stored.
  1122. */
  1123. static inline void *v4l2_get_subdevdata(const struct v4l2_subdev *sd)
  1124. {
  1125. return sd->dev_priv;
  1126. }
  1127. /**
  1128. * v4l2_set_subdev_hostdata - Sets V4L2 dev private host data
  1129. *
  1130. * @sd: pointer to &struct v4l2_subdev
  1131. * @p: pointer to the private data to be stored.
  1132. */
  1133. static inline void v4l2_set_subdev_hostdata(struct v4l2_subdev *sd, void *p)
  1134. {
  1135. sd->host_priv = p;
  1136. }
  1137. /**
  1138. * v4l2_get_subdev_hostdata - Gets V4L2 dev private data
  1139. *
  1140. * @sd: pointer to &struct v4l2_subdev
  1141. *
  1142. * Returns the pointer to the private host data to be stored.
  1143. */
  1144. static inline void *v4l2_get_subdev_hostdata(const struct v4l2_subdev *sd)
  1145. {
  1146. return sd->host_priv;
  1147. }
  1148. #ifdef CONFIG_MEDIA_CONTROLLER
  1149. /**
  1150. * v4l2_subdev_get_fwnode_pad_1_to_1 - Get pad number from a subdev fwnode
  1151. * endpoint, assuming 1:1 port:pad
  1152. *
  1153. * @entity: Pointer to the subdev entity
  1154. * @endpoint: Pointer to a parsed fwnode endpoint
  1155. *
  1156. * This function can be used as the .get_fwnode_pad operation for
  1157. * subdevices that map port numbers and pad indexes 1:1. If the endpoint
  1158. * is owned by the subdevice, the function returns the endpoint port
  1159. * number.
  1160. *
  1161. * Returns the endpoint port number on success or a negative error code.
  1162. */
  1163. int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity,
  1164. struct fwnode_endpoint *endpoint);
  1165. /**
  1166. * v4l2_subdev_link_validate_default - validates a media link
  1167. *
  1168. * @sd: pointer to &struct v4l2_subdev
  1169. * @link: pointer to &struct media_link
  1170. * @source_fmt: pointer to &struct v4l2_subdev_format
  1171. * @sink_fmt: pointer to &struct v4l2_subdev_format
  1172. *
  1173. * This function ensures that width, height and the media bus pixel
  1174. * code are equal on both source and sink of the link.
  1175. */
  1176. int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
  1177. struct media_link *link,
  1178. struct v4l2_subdev_format *source_fmt,
  1179. struct v4l2_subdev_format *sink_fmt);
  1180. /**
  1181. * v4l2_subdev_link_validate - validates a media link
  1182. *
  1183. * @link: pointer to &struct media_link
  1184. *
  1185. * This function calls the subdev's link_validate ops to validate
  1186. * if a media link is valid for streaming. It also internally
  1187. * calls v4l2_subdev_link_validate_default() to ensure that
  1188. * width, height and the media bus pixel code are equal on both
  1189. * source and sink of the link.
  1190. *
  1191. * The function can be used as a drop-in &media_entity_ops.link_validate
  1192. * implementation for v4l2_subdev instances. It supports all links between
  1193. * subdevs, as well as links between subdevs and video devices, provided that
  1194. * the video devices also implement their &media_entity_ops.link_validate
  1195. * operation.
  1196. */
  1197. int v4l2_subdev_link_validate(struct media_link *link);
  1198. /**
  1199. * v4l2_subdev_has_pad_interdep - MC has_pad_interdep implementation for subdevs
  1200. *
  1201. * @entity: pointer to &struct media_entity
  1202. * @pad0: pad number for the first pad
  1203. * @pad1: pad number for the second pad
  1204. *
  1205. * This function is an implementation of the
  1206. * media_entity_operations.has_pad_interdep operation for subdevs that
  1207. * implement the multiplexed streams API (as indicated by the
  1208. * V4L2_SUBDEV_FL_STREAMS subdev flag).
  1209. *
  1210. * It considers two pads interdependent if there is an active route between pad0
  1211. * and pad1.
  1212. */
  1213. bool v4l2_subdev_has_pad_interdep(struct media_entity *entity,
  1214. unsigned int pad0, unsigned int pad1);
  1215. /**
  1216. * __v4l2_subdev_state_alloc - allocate v4l2_subdev_state
  1217. *
  1218. * @sd: pointer to &struct v4l2_subdev for which the state is being allocated.
  1219. * @lock_name: name of the state lock
  1220. * @key: lock_class_key for the lock
  1221. *
  1222. * Must call __v4l2_subdev_state_free() when state is no longer needed.
  1223. *
  1224. * Not to be called directly by the drivers.
  1225. */
  1226. struct v4l2_subdev_state *__v4l2_subdev_state_alloc(struct v4l2_subdev *sd,
  1227. const char *lock_name,
  1228. struct lock_class_key *key);
  1229. /**
  1230. * __v4l2_subdev_state_free - free a v4l2_subdev_state
  1231. *
  1232. * @state: v4l2_subdev_state to be freed.
  1233. *
  1234. * Not to be called directly by the drivers.
  1235. */
  1236. void __v4l2_subdev_state_free(struct v4l2_subdev_state *state);
  1237. /**
  1238. * v4l2_subdev_init_finalize() - Finalizes the initialization of the subdevice
  1239. * @sd: The subdev
  1240. *
  1241. * This function finalizes the initialization of the subdev, including
  1242. * allocation of the active state for the subdev.
  1243. *
  1244. * This function must be called by the subdev drivers that use the centralized
  1245. * active state, after the subdev struct has been initialized and
  1246. * media_entity_pads_init() has been called, but before registering the
  1247. * subdev.
  1248. *
  1249. * The user must call v4l2_subdev_cleanup() when the subdev is being removed.
  1250. */
  1251. #define v4l2_subdev_init_finalize(sd) \
  1252. ({ \
  1253. static struct lock_class_key __key; \
  1254. const char *name = KBUILD_BASENAME \
  1255. ":" __stringify(__LINE__) ":sd->active_state->lock"; \
  1256. __v4l2_subdev_init_finalize(sd, name, &__key); \
  1257. })
  1258. int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name,
  1259. struct lock_class_key *key);
  1260. /**
  1261. * v4l2_subdev_cleanup() - Releases the resources allocated by the subdevice
  1262. * @sd: The subdevice
  1263. *
  1264. * Clean up a V4L2 async sub-device. Must be called for a sub-device as part of
  1265. * its release if resources have been associated with it using
  1266. * v4l2_async_subdev_endpoint_add() or v4l2_subdev_init_finalize().
  1267. */
  1268. void v4l2_subdev_cleanup(struct v4l2_subdev *sd);
  1269. /*
  1270. * A macro to generate the macro or function name for sub-devices state access
  1271. * wrapper macros below.
  1272. */
  1273. #define __v4l2_subdev_state_gen_call(NAME, _1, ARG, ...) \
  1274. __v4l2_subdev_state_get_ ## NAME ## ARG
  1275. /*
  1276. * A macro to constify the return value of the state accessors when the state
  1277. * parameter is const.
  1278. */
  1279. #define __v4l2_subdev_state_constify_ret(state, value) \
  1280. _Generic(state, \
  1281. const struct v4l2_subdev_state *: (const typeof(*(value)) *)(value), \
  1282. struct v4l2_subdev_state *: (value) \
  1283. )
  1284. /**
  1285. * v4l2_subdev_state_get_format() - Get pointer to a stream format
  1286. * @state: subdevice state
  1287. * @pad: pad id
  1288. * @...: stream id (optional argument)
  1289. *
  1290. * This returns a pointer to &struct v4l2_mbus_framefmt for the given pad +
  1291. * stream in the subdev state.
  1292. *
  1293. * For stream-unaware drivers the format for the corresponding pad is returned.
  1294. * If the pad does not exist, NULL is returned.
  1295. */
  1296. /*
  1297. * Wrap v4l2_subdev_state_get_format(), allowing the function to be called with
  1298. * two or three arguments. The purpose of the __v4l2_subdev_state_gen_call()
  1299. * macro is to come up with the name of the function or macro to call, using
  1300. * the last two arguments (_stream and _pad). The selected function or macro is
  1301. * then called using the arguments specified by the caller. The
  1302. * __v4l2_subdev_state_constify_ret() macro constifies the returned pointer
  1303. * when the state is const, allowing the state accessors to guarantee
  1304. * const-correctness in all cases.
  1305. *
  1306. * A similar arrangement is used for v4l2_subdev_state_crop(),
  1307. * v4l2_subdev_state_compose() and v4l2_subdev_state_get_interval() below.
  1308. */
  1309. #define v4l2_subdev_state_get_format(state, pad, ...) \
  1310. __v4l2_subdev_state_constify_ret(state, \
  1311. __v4l2_subdev_state_gen_call(format, ##__VA_ARGS__, , _pad) \
  1312. ((struct v4l2_subdev_state *)state, pad, ##__VA_ARGS__))
  1313. #define __v4l2_subdev_state_get_format_pad(state, pad) \
  1314. __v4l2_subdev_state_get_format(state, pad, 0)
  1315. struct v4l2_mbus_framefmt *
  1316. __v4l2_subdev_state_get_format(struct v4l2_subdev_state *state,
  1317. unsigned int pad, u32 stream);
  1318. /**
  1319. * v4l2_subdev_state_get_crop() - Get pointer to a stream crop rectangle
  1320. * @state: subdevice state
  1321. * @pad: pad id
  1322. * @...: stream id (optional argument)
  1323. *
  1324. * This returns a pointer to crop rectangle for the given pad + stream in the
  1325. * subdev state.
  1326. *
  1327. * For stream-unaware drivers the crop rectangle for the corresponding pad is
  1328. * returned. If the pad does not exist, NULL is returned.
  1329. */
  1330. #define v4l2_subdev_state_get_crop(state, pad, ...) \
  1331. __v4l2_subdev_state_constify_ret(state, \
  1332. __v4l2_subdev_state_gen_call(crop, ##__VA_ARGS__, , _pad) \
  1333. ((struct v4l2_subdev_state *)state, pad, ##__VA_ARGS__))
  1334. #define __v4l2_subdev_state_get_crop_pad(state, pad) \
  1335. __v4l2_subdev_state_get_crop(state, pad, 0)
  1336. struct v4l2_rect *
  1337. __v4l2_subdev_state_get_crop(struct v4l2_subdev_state *state, unsigned int pad,
  1338. u32 stream);
  1339. /**
  1340. * v4l2_subdev_state_get_compose() - Get pointer to a stream compose rectangle
  1341. * @state: subdevice state
  1342. * @pad: pad id
  1343. * @...: stream id (optional argument)
  1344. *
  1345. * This returns a pointer to compose rectangle for the given pad + stream in the
  1346. * subdev state.
  1347. *
  1348. * For stream-unaware drivers the compose rectangle for the corresponding pad is
  1349. * returned. If the pad does not exist, NULL is returned.
  1350. */
  1351. #define v4l2_subdev_state_get_compose(state, pad, ...) \
  1352. __v4l2_subdev_state_constify_ret(state, \
  1353. __v4l2_subdev_state_gen_call(compose, ##__VA_ARGS__, , _pad) \
  1354. ((struct v4l2_subdev_state *)state, pad, ##__VA_ARGS__))
  1355. #define __v4l2_subdev_state_get_compose_pad(state, pad) \
  1356. __v4l2_subdev_state_get_compose(state, pad, 0)
  1357. struct v4l2_rect *
  1358. __v4l2_subdev_state_get_compose(struct v4l2_subdev_state *state,
  1359. unsigned int pad, u32 stream);
  1360. /**
  1361. * v4l2_subdev_state_get_interval() - Get pointer to a stream frame interval
  1362. * @state: subdevice state
  1363. * @pad: pad id
  1364. * @...: stream id (optional argument)
  1365. *
  1366. * This returns a pointer to the frame interval for the given pad + stream in
  1367. * the subdev state.
  1368. *
  1369. * For stream-unaware drivers the frame interval for the corresponding pad is
  1370. * returned. If the pad does not exist, NULL is returned.
  1371. */
  1372. #define v4l2_subdev_state_get_interval(state, pad, ...) \
  1373. __v4l2_subdev_state_constify_ret(state, \
  1374. __v4l2_subdev_state_gen_call(interval, ##__VA_ARGS__, , _pad) \
  1375. ((struct v4l2_subdev_state *)state, pad, ##__VA_ARGS__))
  1376. #define __v4l2_subdev_state_get_interval_pad(state, pad) \
  1377. __v4l2_subdev_state_get_interval(state, pad, 0)
  1378. struct v4l2_fract *
  1379. __v4l2_subdev_state_get_interval(struct v4l2_subdev_state *state,
  1380. unsigned int pad, u32 stream);
  1381. #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
  1382. /**
  1383. * v4l2_subdev_get_fmt() - Fill format based on state
  1384. * @sd: subdevice
  1385. * @state: subdevice state
  1386. * @format: pointer to &struct v4l2_subdev_format
  1387. *
  1388. * Fill @format->format field based on the information in the @format struct.
  1389. *
  1390. * This function can be used by the subdev drivers which support active state to
  1391. * implement v4l2_subdev_pad_ops.get_fmt if the subdev driver does not need to
  1392. * do anything special in their get_fmt op.
  1393. *
  1394. * Returns 0 on success, error value otherwise.
  1395. */
  1396. int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
  1397. struct v4l2_subdev_format *format);
  1398. /**
  1399. * v4l2_subdev_get_frame_interval() - Fill frame interval based on state
  1400. * @sd: subdevice
  1401. * @state: subdevice state
  1402. * @fi: pointer to &struct v4l2_subdev_frame_interval
  1403. *
  1404. * Fill @fi->interval field based on the information in the @fi struct.
  1405. *
  1406. * This function can be used by the subdev drivers which support active state to
  1407. * implement v4l2_subdev_pad_ops.get_frame_interval if the subdev driver does
  1408. * not need to do anything special in their get_frame_interval op.
  1409. *
  1410. * Returns 0 on success, error value otherwise.
  1411. */
  1412. int v4l2_subdev_get_frame_interval(struct v4l2_subdev *sd,
  1413. struct v4l2_subdev_state *state,
  1414. struct v4l2_subdev_frame_interval *fi);
  1415. /**
  1416. * v4l2_subdev_set_routing() - Set given routing to subdev state
  1417. * @sd: The subdevice
  1418. * @state: The subdevice state
  1419. * @routing: Routing that will be copied to subdev state
  1420. *
  1421. * This will release old routing table (if any) from the state, allocate
  1422. * enough space for the given routing, and copy the routing.
  1423. *
  1424. * This can be used from the subdev driver's set_routing op, after validating
  1425. * the routing.
  1426. */
  1427. int v4l2_subdev_set_routing(struct v4l2_subdev *sd,
  1428. struct v4l2_subdev_state *state,
  1429. const struct v4l2_subdev_krouting *routing);
  1430. struct v4l2_subdev_route *
  1431. __v4l2_subdev_next_active_route(const struct v4l2_subdev_krouting *routing,
  1432. struct v4l2_subdev_route *route);
  1433. /**
  1434. * for_each_active_route - iterate on all active routes of a routing table
  1435. * @routing: The routing table
  1436. * @route: The route iterator
  1437. */
  1438. #define for_each_active_route(routing, route) \
  1439. for ((route) = NULL; \
  1440. ((route) = __v4l2_subdev_next_active_route((routing), (route)));)
  1441. /**
  1442. * v4l2_subdev_set_routing_with_fmt() - Set given routing and format to subdev
  1443. * state
  1444. * @sd: The subdevice
  1445. * @state: The subdevice state
  1446. * @routing: Routing that will be copied to subdev state
  1447. * @fmt: Format used to initialize all the streams
  1448. *
  1449. * This is the same as v4l2_subdev_set_routing, but additionally initializes
  1450. * all the streams using the given format.
  1451. */
  1452. int v4l2_subdev_set_routing_with_fmt(struct v4l2_subdev *sd,
  1453. struct v4l2_subdev_state *state,
  1454. const struct v4l2_subdev_krouting *routing,
  1455. const struct v4l2_mbus_framefmt *fmt);
  1456. /**
  1457. * v4l2_subdev_routing_find_opposite_end() - Find the opposite stream
  1458. * @routing: routing used to find the opposite side
  1459. * @pad: pad id
  1460. * @stream: stream id
  1461. * @other_pad: pointer used to return the opposite pad
  1462. * @other_stream: pointer used to return the opposite stream
  1463. *
  1464. * This function uses the routing table to find the pad + stream which is
  1465. * opposite the given pad + stream.
  1466. *
  1467. * @other_pad and/or @other_stream can be NULL if the caller does not need the
  1468. * value.
  1469. *
  1470. * Returns 0 on success, or -EINVAL if no matching route is found.
  1471. */
  1472. int v4l2_subdev_routing_find_opposite_end(const struct v4l2_subdev_krouting *routing,
  1473. u32 pad, u32 stream, u32 *other_pad,
  1474. u32 *other_stream);
  1475. /**
  1476. * v4l2_subdev_state_get_opposite_stream_format() - Get pointer to opposite
  1477. * stream format
  1478. * @state: subdevice state
  1479. * @pad: pad id
  1480. * @stream: stream id
  1481. *
  1482. * This returns a pointer to &struct v4l2_mbus_framefmt for the pad + stream
  1483. * that is opposite the given pad + stream in the subdev state.
  1484. *
  1485. * If the state does not contain the given pad + stream, NULL is returned.
  1486. */
  1487. struct v4l2_mbus_framefmt *
  1488. v4l2_subdev_state_get_opposite_stream_format(struct v4l2_subdev_state *state,
  1489. u32 pad, u32 stream);
  1490. /**
  1491. * v4l2_subdev_state_xlate_streams() - Translate streams from one pad to another
  1492. *
  1493. * @state: Subdevice state
  1494. * @pad0: The first pad
  1495. * @pad1: The second pad
  1496. * @streams: Streams bitmask on the first pad
  1497. *
  1498. * Streams on sink pads of a subdev are routed to source pads as expressed in
  1499. * the subdev state routing table. Stream numbers don't necessarily match on
  1500. * the sink and source side of a route. This function translates stream numbers
  1501. * on @pad0, expressed as a bitmask in @streams, to the corresponding streams
  1502. * on @pad1 using the routing table from the @state. It returns the stream mask
  1503. * on @pad1, and updates @streams with the streams that have been found in the
  1504. * routing table.
  1505. *
  1506. * @pad0 and @pad1 must be a sink and a source, in any order.
  1507. *
  1508. * Return: The bitmask of streams of @pad1 that are routed to @streams on @pad0.
  1509. */
  1510. u64 v4l2_subdev_state_xlate_streams(const struct v4l2_subdev_state *state,
  1511. u32 pad0, u32 pad1, u64 *streams);
  1512. /**
  1513. * enum v4l2_subdev_routing_restriction - Subdevice internal routing restrictions
  1514. *
  1515. * @V4L2_SUBDEV_ROUTING_NO_1_TO_N:
  1516. * an input stream shall not be routed to multiple output streams (stream
  1517. * duplication)
  1518. * @V4L2_SUBDEV_ROUTING_NO_N_TO_1:
  1519. * multiple input streams shall not be routed to the same output stream
  1520. * (stream merging)
  1521. * @V4L2_SUBDEV_ROUTING_NO_SINK_STREAM_MIX:
  1522. * all streams from a sink pad must be routed to a single source pad
  1523. * @V4L2_SUBDEV_ROUTING_NO_SOURCE_STREAM_MIX:
  1524. * all streams on a source pad must originate from a single sink pad
  1525. * @V4L2_SUBDEV_ROUTING_NO_SOURCE_MULTIPLEXING:
  1526. * source pads shall not contain multiplexed streams
  1527. * @V4L2_SUBDEV_ROUTING_NO_SINK_MULTIPLEXING:
  1528. * sink pads shall not contain multiplexed streams
  1529. * @V4L2_SUBDEV_ROUTING_ONLY_1_TO_1:
  1530. * only non-overlapping 1-to-1 stream routing is allowed (a combination of
  1531. * @V4L2_SUBDEV_ROUTING_NO_1_TO_N and @V4L2_SUBDEV_ROUTING_NO_N_TO_1)
  1532. * @V4L2_SUBDEV_ROUTING_NO_STREAM_MIX:
  1533. * all streams from a sink pad must be routed to a single source pad, and
  1534. * that source pad shall not get routes from any other sink pad
  1535. * (a combination of @V4L2_SUBDEV_ROUTING_NO_SINK_STREAM_MIX and
  1536. * @V4L2_SUBDEV_ROUTING_NO_SOURCE_STREAM_MIX)
  1537. * @V4L2_SUBDEV_ROUTING_NO_MULTIPLEXING:
  1538. * no multiplexed streams allowed on either source or sink sides.
  1539. */
  1540. enum v4l2_subdev_routing_restriction {
  1541. V4L2_SUBDEV_ROUTING_NO_1_TO_N = BIT(0),
  1542. V4L2_SUBDEV_ROUTING_NO_N_TO_1 = BIT(1),
  1543. V4L2_SUBDEV_ROUTING_NO_SINK_STREAM_MIX = BIT(2),
  1544. V4L2_SUBDEV_ROUTING_NO_SOURCE_STREAM_MIX = BIT(3),
  1545. V4L2_SUBDEV_ROUTING_NO_SINK_MULTIPLEXING = BIT(4),
  1546. V4L2_SUBDEV_ROUTING_NO_SOURCE_MULTIPLEXING = BIT(5),
  1547. V4L2_SUBDEV_ROUTING_ONLY_1_TO_1 =
  1548. V4L2_SUBDEV_ROUTING_NO_1_TO_N |
  1549. V4L2_SUBDEV_ROUTING_NO_N_TO_1,
  1550. V4L2_SUBDEV_ROUTING_NO_STREAM_MIX =
  1551. V4L2_SUBDEV_ROUTING_NO_SINK_STREAM_MIX |
  1552. V4L2_SUBDEV_ROUTING_NO_SOURCE_STREAM_MIX,
  1553. V4L2_SUBDEV_ROUTING_NO_MULTIPLEXING =
  1554. V4L2_SUBDEV_ROUTING_NO_SINK_MULTIPLEXING |
  1555. V4L2_SUBDEV_ROUTING_NO_SOURCE_MULTIPLEXING,
  1556. };
  1557. /**
  1558. * v4l2_subdev_routing_validate() - Verify that routes comply with driver
  1559. * constraints
  1560. * @sd: The subdevice
  1561. * @routing: Routing to verify
  1562. * @disallow: Restrictions on routes
  1563. *
  1564. * This verifies that the given routing complies with the @disallow constraints.
  1565. *
  1566. * Returns 0 on success, error value otherwise.
  1567. */
  1568. int v4l2_subdev_routing_validate(struct v4l2_subdev *sd,
  1569. const struct v4l2_subdev_krouting *routing,
  1570. enum v4l2_subdev_routing_restriction disallow);
  1571. /**
  1572. * v4l2_subdev_enable_streams() - Enable streams on a pad
  1573. * @sd: The subdevice
  1574. * @pad: The pad
  1575. * @streams_mask: Bitmask of streams to enable
  1576. *
  1577. * This function enables streams on a source @pad of a subdevice. The pad is
  1578. * identified by its index, while the streams are identified by the
  1579. * @streams_mask bitmask. This allows enabling multiple streams on a pad at
  1580. * once.
  1581. *
  1582. * Enabling a stream that is already enabled isn't allowed. If @streams_mask
  1583. * contains an already enabled stream, this function returns -EALREADY without
  1584. * performing any operation.
  1585. *
  1586. * Per-stream enable is only available for subdevs that implement the
  1587. * .enable_streams() and .disable_streams() operations. For other subdevs, this
  1588. * function implements a best-effort compatibility by calling the .s_stream()
  1589. * operation, limited to subdevs that have a single source pad.
  1590. *
  1591. * Return:
  1592. * * 0: Success
  1593. * * -EALREADY: One of the streams in streams_mask is already enabled
  1594. * * -EINVAL: The pad index is invalid, or doesn't correspond to a source pad
  1595. * * -EOPNOTSUPP: Falling back to the legacy .s_stream() operation is
  1596. * impossible because the subdev has multiple source pads
  1597. */
  1598. int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad,
  1599. u64 streams_mask);
  1600. /**
  1601. * v4l2_subdev_disable_streams() - Disable streams on a pad
  1602. * @sd: The subdevice
  1603. * @pad: The pad
  1604. * @streams_mask: Bitmask of streams to disable
  1605. *
  1606. * This function disables streams on a source @pad of a subdevice. The pad is
  1607. * identified by its index, while the streams are identified by the
  1608. * @streams_mask bitmask. This allows disabling multiple streams on a pad at
  1609. * once.
  1610. *
  1611. * Disabling a streams that is not enabled isn't allowed. If @streams_mask
  1612. * contains a disabled stream, this function returns -EALREADY without
  1613. * performing any operation.
  1614. *
  1615. * Per-stream disable is only available for subdevs that implement the
  1616. * .enable_streams() and .disable_streams() operations. For other subdevs, this
  1617. * function implements a best-effort compatibility by calling the .s_stream()
  1618. * operation, limited to subdevs that have a single source pad.
  1619. *
  1620. * Return:
  1621. * * 0: Success
  1622. * * -EALREADY: One of the streams in streams_mask is not enabled
  1623. * * -EINVAL: The pad index is invalid, or doesn't correspond to a source pad
  1624. * * -EOPNOTSUPP: Falling back to the legacy .s_stream() operation is
  1625. * impossible because the subdev has multiple source pads
  1626. */
  1627. int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad,
  1628. u64 streams_mask);
  1629. /**
  1630. * v4l2_subdev_s_stream_helper() - Helper to implement the subdev s_stream
  1631. * operation using enable_streams and disable_streams
  1632. * @sd: The subdevice
  1633. * @enable: Enable or disable streaming
  1634. *
  1635. * Subdevice drivers that implement the streams-aware
  1636. * &v4l2_subdev_pad_ops.enable_streams and &v4l2_subdev_pad_ops.disable_streams
  1637. * operations can use this helper to implement the legacy
  1638. * &v4l2_subdev_video_ops.s_stream operation.
  1639. *
  1640. * This helper can only be used by subdevs that have a single source pad.
  1641. *
  1642. * Return: 0 on success, or a negative error code otherwise.
  1643. */
  1644. int v4l2_subdev_s_stream_helper(struct v4l2_subdev *sd, int enable);
  1645. #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
  1646. #endif /* CONFIG_MEDIA_CONTROLLER */
  1647. /**
  1648. * v4l2_subdev_lock_state() - Locks the subdev state
  1649. * @state: The subdevice state
  1650. *
  1651. * Locks the given subdev state.
  1652. *
  1653. * The state must be unlocked with v4l2_subdev_unlock_state() after use.
  1654. */
  1655. static inline void v4l2_subdev_lock_state(struct v4l2_subdev_state *state)
  1656. {
  1657. mutex_lock(state->lock);
  1658. }
  1659. /**
  1660. * v4l2_subdev_unlock_state() - Unlocks the subdev state
  1661. * @state: The subdevice state
  1662. *
  1663. * Unlocks the given subdev state.
  1664. */
  1665. static inline void v4l2_subdev_unlock_state(struct v4l2_subdev_state *state)
  1666. {
  1667. mutex_unlock(state->lock);
  1668. }
  1669. /**
  1670. * v4l2_subdev_lock_states - Lock two sub-device states
  1671. * @state1: One subdevice state
  1672. * @state2: The other subdevice state
  1673. *
  1674. * Locks the state of two sub-devices.
  1675. *
  1676. * The states must be unlocked with v4l2_subdev_unlock_states() after use.
  1677. *
  1678. * This differs from calling v4l2_subdev_lock_state() on both states so that if
  1679. * the states share the same lock, the lock is acquired only once (so no
  1680. * deadlock occurs). The caller is responsible for ensuring the locks will
  1681. * always be acquired in the same order.
  1682. */
  1683. static inline void v4l2_subdev_lock_states(struct v4l2_subdev_state *state1,
  1684. struct v4l2_subdev_state *state2)
  1685. {
  1686. mutex_lock(state1->lock);
  1687. if (state1->lock != state2->lock)
  1688. mutex_lock(state2->lock);
  1689. }
  1690. /**
  1691. * v4l2_subdev_unlock_states() - Unlock two sub-device states
  1692. * @state1: One subdevice state
  1693. * @state2: The other subdevice state
  1694. *
  1695. * Unlocks the state of two sub-devices.
  1696. *
  1697. * This differs from calling v4l2_subdev_unlock_state() on both states so that
  1698. * if the states share the same lock, the lock is released only once.
  1699. */
  1700. static inline void v4l2_subdev_unlock_states(struct v4l2_subdev_state *state1,
  1701. struct v4l2_subdev_state *state2)
  1702. {
  1703. mutex_unlock(state1->lock);
  1704. if (state1->lock != state2->lock)
  1705. mutex_unlock(state2->lock);
  1706. }
  1707. /**
  1708. * v4l2_subdev_get_unlocked_active_state() - Checks that the active subdev state
  1709. * is unlocked and returns it
  1710. * @sd: The subdevice
  1711. *
  1712. * Returns the active state for the subdevice, or NULL if the subdev does not
  1713. * support active state. If the state is not NULL, calls
  1714. * lockdep_assert_not_held() to issue a warning if the state is locked.
  1715. *
  1716. * This function is to be used e.g. when getting the active state for the sole
  1717. * purpose of passing it forward, without accessing the state fields.
  1718. */
  1719. static inline struct v4l2_subdev_state *
  1720. v4l2_subdev_get_unlocked_active_state(struct v4l2_subdev *sd)
  1721. {
  1722. if (sd->active_state)
  1723. lockdep_assert_not_held(sd->active_state->lock);
  1724. return sd->active_state;
  1725. }
  1726. /**
  1727. * v4l2_subdev_get_locked_active_state() - Checks that the active subdev state
  1728. * is locked and returns it
  1729. *
  1730. * @sd: The subdevice
  1731. *
  1732. * Returns the active state for the subdevice, or NULL if the subdev does not
  1733. * support active state. If the state is not NULL, calls lockdep_assert_held()
  1734. * to issue a warning if the state is not locked.
  1735. *
  1736. * This function is to be used when the caller knows that the active state is
  1737. * already locked.
  1738. */
  1739. static inline struct v4l2_subdev_state *
  1740. v4l2_subdev_get_locked_active_state(struct v4l2_subdev *sd)
  1741. {
  1742. if (sd->active_state)
  1743. lockdep_assert_held(sd->active_state->lock);
  1744. return sd->active_state;
  1745. }
  1746. /**
  1747. * v4l2_subdev_lock_and_get_active_state() - Locks and returns the active subdev
  1748. * state for the subdevice
  1749. * @sd: The subdevice
  1750. *
  1751. * Returns the locked active state for the subdevice, or NULL if the subdev
  1752. * does not support active state.
  1753. *
  1754. * The state must be unlocked with v4l2_subdev_unlock_state() after use.
  1755. */
  1756. static inline struct v4l2_subdev_state *
  1757. v4l2_subdev_lock_and_get_active_state(struct v4l2_subdev *sd)
  1758. {
  1759. if (sd->active_state)
  1760. v4l2_subdev_lock_state(sd->active_state);
  1761. return sd->active_state;
  1762. }
  1763. /**
  1764. * v4l2_subdev_init - initializes the sub-device struct
  1765. *
  1766. * @sd: pointer to the &struct v4l2_subdev to be initialized
  1767. * @ops: pointer to &struct v4l2_subdev_ops.
  1768. */
  1769. void v4l2_subdev_init(struct v4l2_subdev *sd,
  1770. const struct v4l2_subdev_ops *ops);
  1771. extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers;
  1772. /**
  1773. * v4l2_subdev_call - call an operation of a v4l2_subdev.
  1774. *
  1775. * @sd: pointer to the &struct v4l2_subdev
  1776. * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
  1777. * Each element there groups a set of callbacks functions.
  1778. * @f: callback function to be called.
  1779. * The callback functions are defined in groups, according to
  1780. * each element at &struct v4l2_subdev_ops.
  1781. * @args: arguments for @f.
  1782. *
  1783. * Example: err = v4l2_subdev_call(sd, video, s_std, norm);
  1784. */
  1785. #define v4l2_subdev_call(sd, o, f, args...) \
  1786. ({ \
  1787. struct v4l2_subdev *__sd = (sd); \
  1788. int __result; \
  1789. if (!__sd) \
  1790. __result = -ENODEV; \
  1791. else if (!(__sd->ops->o && __sd->ops->o->f)) \
  1792. __result = -ENOIOCTLCMD; \
  1793. else if (v4l2_subdev_call_wrappers.o && \
  1794. v4l2_subdev_call_wrappers.o->f) \
  1795. __result = v4l2_subdev_call_wrappers.o->f( \
  1796. __sd, ##args); \
  1797. else \
  1798. __result = __sd->ops->o->f(__sd, ##args); \
  1799. __result; \
  1800. })
  1801. /**
  1802. * v4l2_subdev_call_state_active - call an operation of a v4l2_subdev which
  1803. * takes state as a parameter, passing the
  1804. * subdev its active state.
  1805. *
  1806. * @sd: pointer to the &struct v4l2_subdev
  1807. * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
  1808. * Each element there groups a set of callbacks functions.
  1809. * @f: callback function to be called.
  1810. * The callback functions are defined in groups, according to
  1811. * each element at &struct v4l2_subdev_ops.
  1812. * @args: arguments for @f.
  1813. *
  1814. * This is similar to v4l2_subdev_call(), except that this version can only be
  1815. * used for ops that take a subdev state as a parameter. The macro will get the
  1816. * active state, lock it before calling the op and unlock it after the call.
  1817. */
  1818. #define v4l2_subdev_call_state_active(sd, o, f, args...) \
  1819. ({ \
  1820. int __result; \
  1821. struct v4l2_subdev_state *state; \
  1822. state = v4l2_subdev_get_unlocked_active_state(sd); \
  1823. if (state) \
  1824. v4l2_subdev_lock_state(state); \
  1825. __result = v4l2_subdev_call(sd, o, f, state, ##args); \
  1826. if (state) \
  1827. v4l2_subdev_unlock_state(state); \
  1828. __result; \
  1829. })
  1830. /**
  1831. * v4l2_subdev_call_state_try - call an operation of a v4l2_subdev which
  1832. * takes state as a parameter, passing the
  1833. * subdev a newly allocated try state.
  1834. *
  1835. * @sd: pointer to the &struct v4l2_subdev
  1836. * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
  1837. * Each element there groups a set of callbacks functions.
  1838. * @f: callback function to be called.
  1839. * The callback functions are defined in groups, according to
  1840. * each element at &struct v4l2_subdev_ops.
  1841. * @args: arguments for @f.
  1842. *
  1843. * This is similar to v4l2_subdev_call_state_active(), except that as this
  1844. * version allocates a new state, this is only usable for
  1845. * V4L2_SUBDEV_FORMAT_TRY use cases.
  1846. *
  1847. * Note: only legacy non-MC drivers may need this macro.
  1848. */
  1849. #define v4l2_subdev_call_state_try(sd, o, f, args...) \
  1850. ({ \
  1851. int __result; \
  1852. static struct lock_class_key __key; \
  1853. const char *name = KBUILD_BASENAME \
  1854. ":" __stringify(__LINE__) ":state->lock"; \
  1855. struct v4l2_subdev_state *state = \
  1856. __v4l2_subdev_state_alloc(sd, name, &__key); \
  1857. if (IS_ERR(state)) { \
  1858. __result = PTR_ERR(state); \
  1859. } else { \
  1860. v4l2_subdev_lock_state(state); \
  1861. __result = v4l2_subdev_call(sd, o, f, state, ##args); \
  1862. v4l2_subdev_unlock_state(state); \
  1863. __v4l2_subdev_state_free(state); \
  1864. } \
  1865. __result; \
  1866. })
  1867. /**
  1868. * v4l2_subdev_has_op - Checks if a subdev defines a certain operation.
  1869. *
  1870. * @sd: pointer to the &struct v4l2_subdev
  1871. * @o: The group of callback functions in &struct v4l2_subdev_ops
  1872. * which @f is a part of.
  1873. * @f: callback function to be checked for its existence.
  1874. */
  1875. #define v4l2_subdev_has_op(sd, o, f) \
  1876. ((sd)->ops->o && (sd)->ops->o->f)
  1877. /**
  1878. * v4l2_subdev_notify_event() - Delivers event notification for subdevice
  1879. * @sd: The subdev for which to deliver the event
  1880. * @ev: The event to deliver
  1881. *
  1882. * Will deliver the specified event to all userspace event listeners which are
  1883. * subscribed to the v42l subdev event queue as well as to the bridge driver
  1884. * using the notify callback. The notification type for the notify callback
  1885. * will be %V4L2_DEVICE_NOTIFY_EVENT.
  1886. */
  1887. void v4l2_subdev_notify_event(struct v4l2_subdev *sd,
  1888. const struct v4l2_event *ev);
  1889. /**
  1890. * v4l2_subdev_is_streaming() - Returns if the subdevice is streaming
  1891. * @sd: The subdevice
  1892. *
  1893. * v4l2_subdev_is_streaming() tells if the subdevice is currently streaming.
  1894. * "Streaming" here means whether .s_stream() or .enable_streams() has been
  1895. * successfully called, and the streaming has not yet been disabled.
  1896. *
  1897. * If the subdevice implements .enable_streams() this function must be called
  1898. * while holding the active state lock.
  1899. */
  1900. bool v4l2_subdev_is_streaming(struct v4l2_subdev *sd);
  1901. #endif /* _V4L2_SUBDEV_H */