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