v4l2-subdev.h 74 KB

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