xref: /OK3568_Linux_fs/kernel/include/media/v4l2-common.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun     v4l2 common internal API header
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun     This header contains internal shared ioctl definitions for use by the
6*4882a593Smuzhiyun     internal low-level v4l2 drivers.
7*4882a593Smuzhiyun     Each ioctl begins with VIDIOC_INT_ to clearly mark that it is an internal
8*4882a593Smuzhiyun     define,
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun     Copyright (C) 2005  Hans Verkuil <hverkuil@xs4all.nl>
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun  */
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #ifndef V4L2_COMMON_H_
15*4882a593Smuzhiyun #define V4L2_COMMON_H_
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include <linux/time.h>
18*4882a593Smuzhiyun #include <media/v4l2-dev.h>
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /* Common printk constructs for v4l-i2c drivers. These macros create a unique
21*4882a593Smuzhiyun    prefix consisting of the driver name, the adapter number and the i2c
22*4882a593Smuzhiyun    address. */
23*4882a593Smuzhiyun #define v4l_printk(level, name, adapter, addr, fmt, arg...) \
24*4882a593Smuzhiyun 	printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg)
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #define v4l_client_printk(level, client, fmt, arg...)			    \
27*4882a593Smuzhiyun 	v4l_printk(level, (client)->dev.driver->name, (client)->adapter, \
28*4882a593Smuzhiyun 		   (client)->addr, fmt , ## arg)
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #define v4l_err(client, fmt, arg...) \
31*4882a593Smuzhiyun 	v4l_client_printk(KERN_ERR, client, fmt , ## arg)
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #define v4l_warn(client, fmt, arg...) \
34*4882a593Smuzhiyun 	v4l_client_printk(KERN_WARNING, client, fmt , ## arg)
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #define v4l_info(client, fmt, arg...) \
37*4882a593Smuzhiyun 	v4l_client_printk(KERN_INFO, client, fmt , ## arg)
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /* These three macros assume that the debug level is set with a module
40*4882a593Smuzhiyun    parameter called 'debug'. */
41*4882a593Smuzhiyun #define v4l_dbg(level, debug, client, fmt, arg...)			     \
42*4882a593Smuzhiyun 	do {								     \
43*4882a593Smuzhiyun 		if (debug >= (level))					     \
44*4882a593Smuzhiyun 			v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \
45*4882a593Smuzhiyun 	} while (0)
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /* Add a version of v4l_dbg to be used on drivers using dev_foo() macros */
48*4882a593Smuzhiyun #define dev_dbg_lvl(__dev, __level, __debug, __fmt, __arg...)		\
49*4882a593Smuzhiyun 	do {								\
50*4882a593Smuzhiyun 		if (__debug >= (__level))				\
51*4882a593Smuzhiyun 			dev_printk(KERN_DEBUG, __dev, __fmt, ##__arg);	\
52*4882a593Smuzhiyun 	} while (0)
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /* ------------------------------------------------------------------------- */
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /* These printk constructs can be used with v4l2_device and v4l2_subdev */
57*4882a593Smuzhiyun #define v4l2_printk(level, dev, fmt, arg...) \
58*4882a593Smuzhiyun 	printk(level "%s: " fmt, (dev)->name , ## arg)
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun #define v4l2_err(dev, fmt, arg...) \
61*4882a593Smuzhiyun 	v4l2_printk(KERN_ERR, dev, fmt , ## arg)
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun #define v4l2_warn(dev, fmt, arg...) \
64*4882a593Smuzhiyun 	v4l2_printk(KERN_WARNING, dev, fmt , ## arg)
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun #define v4l2_info(dev, fmt, arg...) \
67*4882a593Smuzhiyun 	v4l2_printk(KERN_INFO, dev, fmt , ## arg)
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /* These three macros assume that the debug level is set with a module
70*4882a593Smuzhiyun    parameter called 'debug'. */
71*4882a593Smuzhiyun #define v4l2_dbg(level, debug, dev, fmt, arg...)			\
72*4882a593Smuzhiyun 	do {								\
73*4882a593Smuzhiyun 		if (debug >= (level))					\
74*4882a593Smuzhiyun 			v4l2_printk(KERN_DEBUG, dev, fmt , ## arg);	\
75*4882a593Smuzhiyun 	} while (0)
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /**
78*4882a593Smuzhiyun  * v4l2_ctrl_query_fill- Fill in a struct v4l2_queryctrl
79*4882a593Smuzhiyun  *
80*4882a593Smuzhiyun  * @qctrl: pointer to the &struct v4l2_queryctrl to be filled
81*4882a593Smuzhiyun  * @min: minimum value for the control
82*4882a593Smuzhiyun  * @max: maximum value for the control
83*4882a593Smuzhiyun  * @step: control step
84*4882a593Smuzhiyun  * @def: default value for the control
85*4882a593Smuzhiyun  *
86*4882a593Smuzhiyun  * Fills the &struct v4l2_queryctrl fields for the query control.
87*4882a593Smuzhiyun  *
88*4882a593Smuzhiyun  * .. note::
89*4882a593Smuzhiyun  *
90*4882a593Smuzhiyun  *    This function assumes that the @qctrl->id field is filled.
91*4882a593Smuzhiyun  *
92*4882a593Smuzhiyun  * Returns -EINVAL if the control is not known by the V4L2 core, 0 on success.
93*4882a593Smuzhiyun  */
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
96*4882a593Smuzhiyun 			 s32 min, s32 max, s32 step, s32 def);
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun /* ------------------------------------------------------------------------- */
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun struct v4l2_device;
101*4882a593Smuzhiyun struct v4l2_subdev;
102*4882a593Smuzhiyun struct v4l2_subdev_ops;
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun /* I2C Helper functions */
105*4882a593Smuzhiyun #include <linux/i2c.h>
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun /**
108*4882a593Smuzhiyun  * enum v4l2_i2c_tuner_type - specifies the range of tuner address that
109*4882a593Smuzhiyun  *	should be used when seeking for I2C devices.
110*4882a593Smuzhiyun  *
111*4882a593Smuzhiyun  * @ADDRS_RADIO:		Radio tuner addresses.
112*4882a593Smuzhiyun  *				Represent the following I2C addresses:
113*4882a593Smuzhiyun  *				0x10 (if compiled with tea5761 support)
114*4882a593Smuzhiyun  *				and 0x60.
115*4882a593Smuzhiyun  * @ADDRS_DEMOD:		Demod tuner addresses.
116*4882a593Smuzhiyun  *				Represent the following I2C addresses:
117*4882a593Smuzhiyun  *				0x42, 0x43, 0x4a and 0x4b.
118*4882a593Smuzhiyun  * @ADDRS_TV:			TV tuner addresses.
119*4882a593Smuzhiyun  *				Represent the following I2C addresses:
120*4882a593Smuzhiyun  *				0x42, 0x43, 0x4a, 0x4b, 0x60, 0x61, 0x62,
121*4882a593Smuzhiyun  *				0x63 and 0x64.
122*4882a593Smuzhiyun  * @ADDRS_TV_WITH_DEMOD:	TV tuner addresses if demod is present, this
123*4882a593Smuzhiyun  *				excludes addresses used by the demodulator
124*4882a593Smuzhiyun  *				from the list of candidates.
125*4882a593Smuzhiyun  *				Represent the following I2C addresses:
126*4882a593Smuzhiyun  *				0x60, 0x61, 0x62, 0x63 and 0x64.
127*4882a593Smuzhiyun  *
128*4882a593Smuzhiyun  * NOTE: All I2C addresses above use the 7-bit notation.
129*4882a593Smuzhiyun  */
130*4882a593Smuzhiyun enum v4l2_i2c_tuner_type {
131*4882a593Smuzhiyun 	ADDRS_RADIO,
132*4882a593Smuzhiyun 	ADDRS_DEMOD,
133*4882a593Smuzhiyun 	ADDRS_TV,
134*4882a593Smuzhiyun 	ADDRS_TV_WITH_DEMOD,
135*4882a593Smuzhiyun };
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun #if defined(CONFIG_VIDEO_V4L2_I2C)
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun /**
140*4882a593Smuzhiyun  * v4l2_i2c_new_subdev - Load an i2c module and return an initialized
141*4882a593Smuzhiyun  *	&struct v4l2_subdev.
142*4882a593Smuzhiyun  *
143*4882a593Smuzhiyun  * @v4l2_dev: pointer to &struct v4l2_device
144*4882a593Smuzhiyun  * @adapter: pointer to struct i2c_adapter
145*4882a593Smuzhiyun  * @client_type:  name of the chip that's on the adapter.
146*4882a593Smuzhiyun  * @addr: I2C address. If zero, it will use @probe_addrs
147*4882a593Smuzhiyun  * @probe_addrs: array with a list of address. The last entry at such
148*4882a593Smuzhiyun  *	array should be %I2C_CLIENT_END.
149*4882a593Smuzhiyun  *
150*4882a593Smuzhiyun  * returns a &struct v4l2_subdev pointer.
151*4882a593Smuzhiyun  */
152*4882a593Smuzhiyun struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
153*4882a593Smuzhiyun 		struct i2c_adapter *adapter, const char *client_type,
154*4882a593Smuzhiyun 		u8 addr, const unsigned short *probe_addrs);
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun /**
157*4882a593Smuzhiyun  * v4l2_i2c_new_subdev_board - Load an i2c module and return an initialized
158*4882a593Smuzhiyun  *	&struct v4l2_subdev.
159*4882a593Smuzhiyun  *
160*4882a593Smuzhiyun  * @v4l2_dev: pointer to &struct v4l2_device
161*4882a593Smuzhiyun  * @adapter: pointer to struct i2c_adapter
162*4882a593Smuzhiyun  * @info: pointer to struct i2c_board_info used to replace the irq,
163*4882a593Smuzhiyun  *	 platform_data and addr arguments.
164*4882a593Smuzhiyun  * @probe_addrs: array with a list of address. The last entry at such
165*4882a593Smuzhiyun  *	array should be %I2C_CLIENT_END.
166*4882a593Smuzhiyun  *
167*4882a593Smuzhiyun  * returns a &struct v4l2_subdev pointer.
168*4882a593Smuzhiyun  */
169*4882a593Smuzhiyun struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
170*4882a593Smuzhiyun 		struct i2c_adapter *adapter, struct i2c_board_info *info,
171*4882a593Smuzhiyun 		const unsigned short *probe_addrs);
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun /**
174*4882a593Smuzhiyun  * v4l2_i2c_subdev_set_name - Set name for an I²C sub-device
175*4882a593Smuzhiyun  *
176*4882a593Smuzhiyun  * @sd: pointer to &struct v4l2_subdev
177*4882a593Smuzhiyun  * @client: pointer to struct i2c_client
178*4882a593Smuzhiyun  * @devname: the name of the device; if NULL, the I²C device drivers's name
179*4882a593Smuzhiyun  *           will be used
180*4882a593Smuzhiyun  * @postfix: sub-device specific string to put right after the I²C device name;
181*4882a593Smuzhiyun  *	     may be NULL
182*4882a593Smuzhiyun  */
183*4882a593Smuzhiyun void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client,
184*4882a593Smuzhiyun 			      const char *devname, const char *postfix);
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun /**
187*4882a593Smuzhiyun  * v4l2_i2c_subdev_init - Initializes a &struct v4l2_subdev with data from
188*4882a593Smuzhiyun  *	an i2c_client struct.
189*4882a593Smuzhiyun  *
190*4882a593Smuzhiyun  * @sd: pointer to &struct v4l2_subdev
191*4882a593Smuzhiyun  * @client: pointer to struct i2c_client
192*4882a593Smuzhiyun  * @ops: pointer to &struct v4l2_subdev_ops
193*4882a593Smuzhiyun  */
194*4882a593Smuzhiyun void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
195*4882a593Smuzhiyun 		const struct v4l2_subdev_ops *ops);
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun /**
198*4882a593Smuzhiyun  * v4l2_i2c_subdev_addr - returns i2c client address of &struct v4l2_subdev.
199*4882a593Smuzhiyun  *
200*4882a593Smuzhiyun  * @sd: pointer to &struct v4l2_subdev
201*4882a593Smuzhiyun  *
202*4882a593Smuzhiyun  * Returns the address of an I2C sub-device
203*4882a593Smuzhiyun  */
204*4882a593Smuzhiyun unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd);
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun /**
207*4882a593Smuzhiyun  * v4l2_i2c_tuner_addrs - Return a list of I2C tuner addresses to probe.
208*4882a593Smuzhiyun  *
209*4882a593Smuzhiyun  * @type: type of the tuner to seek, as defined by
210*4882a593Smuzhiyun  *	  &enum v4l2_i2c_tuner_type.
211*4882a593Smuzhiyun  *
212*4882a593Smuzhiyun  * NOTE: Use only if the tuner addresses are unknown.
213*4882a593Smuzhiyun  */
214*4882a593Smuzhiyun const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type);
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun /**
217*4882a593Smuzhiyun  * v4l2_i2c_subdev_unregister - Unregister a v4l2_subdev
218*4882a593Smuzhiyun  *
219*4882a593Smuzhiyun  * @sd: pointer to &struct v4l2_subdev
220*4882a593Smuzhiyun  */
221*4882a593Smuzhiyun void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd);
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun #else
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun static inline struct v4l2_subdev *
v4l2_i2c_new_subdev(struct v4l2_device * v4l2_dev,struct i2c_adapter * adapter,const char * client_type,u8 addr,const unsigned short * probe_addrs)226*4882a593Smuzhiyun v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
227*4882a593Smuzhiyun 		    struct i2c_adapter *adapter, const char *client_type,
228*4882a593Smuzhiyun 		    u8 addr, const unsigned short *probe_addrs)
229*4882a593Smuzhiyun {
230*4882a593Smuzhiyun 	return NULL;
231*4882a593Smuzhiyun }
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun static inline struct v4l2_subdev *
v4l2_i2c_new_subdev_board(struct v4l2_device * v4l2_dev,struct i2c_adapter * adapter,struct i2c_board_info * info,const unsigned short * probe_addrs)234*4882a593Smuzhiyun v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
235*4882a593Smuzhiyun 			  struct i2c_adapter *adapter, struct i2c_board_info *info,
236*4882a593Smuzhiyun 			  const unsigned short *probe_addrs)
237*4882a593Smuzhiyun {
238*4882a593Smuzhiyun 	return NULL;
239*4882a593Smuzhiyun }
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun static inline void
v4l2_i2c_subdev_set_name(struct v4l2_subdev * sd,struct i2c_client * client,const char * devname,const char * postfix)242*4882a593Smuzhiyun v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client,
243*4882a593Smuzhiyun 			 const char *devname, const char *postfix)
244*4882a593Smuzhiyun {}
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun static inline void
v4l2_i2c_subdev_init(struct v4l2_subdev * sd,struct i2c_client * client,const struct v4l2_subdev_ops * ops)247*4882a593Smuzhiyun v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
248*4882a593Smuzhiyun 		     const struct v4l2_subdev_ops *ops)
249*4882a593Smuzhiyun {}
250*4882a593Smuzhiyun 
v4l2_i2c_subdev_addr(struct v4l2_subdev * sd)251*4882a593Smuzhiyun static inline unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd)
252*4882a593Smuzhiyun {
253*4882a593Smuzhiyun 	return I2C_CLIENT_END;
254*4882a593Smuzhiyun }
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun static inline const unsigned short *
v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)257*4882a593Smuzhiyun v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun 	return NULL;
260*4882a593Smuzhiyun }
261*4882a593Smuzhiyun 
v4l2_i2c_subdev_unregister(struct v4l2_subdev * sd)262*4882a593Smuzhiyun static inline void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd)
263*4882a593Smuzhiyun {}
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun #endif
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun /* ------------------------------------------------------------------------- */
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun /* SPI Helper functions */
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun #include <linux/spi/spi.h>
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun #if defined(CONFIG_SPI)
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun /**
276*4882a593Smuzhiyun  *  v4l2_spi_new_subdev - Load an spi module and return an initialized
277*4882a593Smuzhiyun  *	&struct v4l2_subdev.
278*4882a593Smuzhiyun  *
279*4882a593Smuzhiyun  *
280*4882a593Smuzhiyun  * @v4l2_dev: pointer to &struct v4l2_device.
281*4882a593Smuzhiyun  * @master: pointer to struct spi_master.
282*4882a593Smuzhiyun  * @info: pointer to struct spi_board_info.
283*4882a593Smuzhiyun  *
284*4882a593Smuzhiyun  * returns a &struct v4l2_subdev pointer.
285*4882a593Smuzhiyun  */
286*4882a593Smuzhiyun struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
287*4882a593Smuzhiyun 		struct spi_master *master, struct spi_board_info *info);
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun /**
290*4882a593Smuzhiyun  * v4l2_spi_subdev_init - Initialize a v4l2_subdev with data from an
291*4882a593Smuzhiyun  *	spi_device struct.
292*4882a593Smuzhiyun  *
293*4882a593Smuzhiyun  * @sd: pointer to &struct v4l2_subdev
294*4882a593Smuzhiyun  * @spi: pointer to struct spi_device.
295*4882a593Smuzhiyun  * @ops: pointer to &struct v4l2_subdev_ops
296*4882a593Smuzhiyun  */
297*4882a593Smuzhiyun void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
298*4882a593Smuzhiyun 		const struct v4l2_subdev_ops *ops);
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun /**
301*4882a593Smuzhiyun  * v4l2_spi_subdev_unregister - Unregister a v4l2_subdev
302*4882a593Smuzhiyun  *
303*4882a593Smuzhiyun  * @sd: pointer to &struct v4l2_subdev
304*4882a593Smuzhiyun  */
305*4882a593Smuzhiyun void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd);
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun #else
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun static inline struct v4l2_subdev *
v4l2_spi_new_subdev(struct v4l2_device * v4l2_dev,struct spi_master * master,struct spi_board_info * info)310*4882a593Smuzhiyun v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
311*4882a593Smuzhiyun 		    struct spi_master *master, struct spi_board_info *info)
312*4882a593Smuzhiyun {
313*4882a593Smuzhiyun 	return NULL;
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun static inline void
v4l2_spi_subdev_init(struct v4l2_subdev * sd,struct spi_device * spi,const struct v4l2_subdev_ops * ops)317*4882a593Smuzhiyun v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
318*4882a593Smuzhiyun 		     const struct v4l2_subdev_ops *ops)
319*4882a593Smuzhiyun {}
320*4882a593Smuzhiyun 
v4l2_spi_subdev_unregister(struct v4l2_subdev * sd)321*4882a593Smuzhiyun static inline void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd)
322*4882a593Smuzhiyun {}
323*4882a593Smuzhiyun #endif
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun /* ------------------------------------------------------------------------- */
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun /*
328*4882a593Smuzhiyun  * FIXME: these remaining ioctls/structs should be removed as well, but they
329*4882a593Smuzhiyun  * are still used in tuner-simple.c (TUNER_SET_CONFIG) and cx18/ivtv (RESET).
330*4882a593Smuzhiyun  * To remove these ioctls some more cleanup is needed in those modules.
331*4882a593Smuzhiyun  *
332*4882a593Smuzhiyun  * It doesn't make much sense on documenting them, as what we really want is
333*4882a593Smuzhiyun  * to get rid of them.
334*4882a593Smuzhiyun  */
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun /* s_config */
337*4882a593Smuzhiyun struct v4l2_priv_tun_config {
338*4882a593Smuzhiyun 	int tuner;
339*4882a593Smuzhiyun 	void *priv;
340*4882a593Smuzhiyun };
341*4882a593Smuzhiyun #define TUNER_SET_CONFIG           _IOW('d', 92, struct v4l2_priv_tun_config)
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun #define VIDIOC_INT_RESET		_IOW ('d', 102, u32)
344*4882a593Smuzhiyun 
345*4882a593Smuzhiyun /* ------------------------------------------------------------------------- */
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun /* Miscellaneous helper functions */
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun /**
350*4882a593Smuzhiyun  * v4l_bound_align_image - adjust video dimensions according to
351*4882a593Smuzhiyun  *	a given constraints.
352*4882a593Smuzhiyun  *
353*4882a593Smuzhiyun  * @width:	pointer to width that will be adjusted if needed.
354*4882a593Smuzhiyun  * @wmin:	minimum width.
355*4882a593Smuzhiyun  * @wmax:	maximum width.
356*4882a593Smuzhiyun  * @walign:	least significant bit on width.
357*4882a593Smuzhiyun  * @height:	pointer to height that will be adjusted if needed.
358*4882a593Smuzhiyun  * @hmin:	minimum height.
359*4882a593Smuzhiyun  * @hmax:	maximum height.
360*4882a593Smuzhiyun  * @halign:	least significant bit on height.
361*4882a593Smuzhiyun  * @salign:	least significant bit for the image size (e. g.
362*4882a593Smuzhiyun  *		:math:`width * height`).
363*4882a593Smuzhiyun  *
364*4882a593Smuzhiyun  * Clip an image to have @width between @wmin and @wmax, and @height between
365*4882a593Smuzhiyun  * @hmin and @hmax, inclusive.
366*4882a593Smuzhiyun  *
367*4882a593Smuzhiyun  * Additionally, the @width will be a multiple of :math:`2^{walign}`,
368*4882a593Smuzhiyun  * the @height will be a multiple of :math:`2^{halign}`, and the overall
369*4882a593Smuzhiyun  * size :math:`width * height` will be a multiple of :math:`2^{salign}`.
370*4882a593Smuzhiyun  *
371*4882a593Smuzhiyun  * .. note::
372*4882a593Smuzhiyun  *
373*4882a593Smuzhiyun  *    #. The clipping rectangle may be shrunk or enlarged to fit the alignment
374*4882a593Smuzhiyun  *       constraints.
375*4882a593Smuzhiyun  *    #. @wmax must not be smaller than @wmin.
376*4882a593Smuzhiyun  *    #. @hmax must not be smaller than @hmin.
377*4882a593Smuzhiyun  *    #. The alignments must not be so high there are no possible image
378*4882a593Smuzhiyun  *       sizes within the allowed bounds.
379*4882a593Smuzhiyun  *    #. @wmin and @hmin must be at least 1 (don't use 0).
380*4882a593Smuzhiyun  *    #. For @walign, @halign and @salign, if you don't care about a certain
381*4882a593Smuzhiyun  *       alignment, specify ``0``, as :math:`2^0 = 1` and one byte alignment
382*4882a593Smuzhiyun  *       is equivalent to no alignment.
383*4882a593Smuzhiyun  *    #. If you only want to adjust downward, specify a maximum that's the
384*4882a593Smuzhiyun  *       same as the initial value.
385*4882a593Smuzhiyun  */
386*4882a593Smuzhiyun void v4l_bound_align_image(unsigned int *width, unsigned int wmin,
387*4882a593Smuzhiyun 			   unsigned int wmax, unsigned int walign,
388*4882a593Smuzhiyun 			   unsigned int *height, unsigned int hmin,
389*4882a593Smuzhiyun 			   unsigned int hmax, unsigned int halign,
390*4882a593Smuzhiyun 			   unsigned int salign);
391*4882a593Smuzhiyun 
392*4882a593Smuzhiyun /**
393*4882a593Smuzhiyun  * v4l2_find_nearest_size - Find the nearest size among a discrete
394*4882a593Smuzhiyun  *	set of resolutions contained in an array of a driver specific struct.
395*4882a593Smuzhiyun  *
396*4882a593Smuzhiyun  * @array: a driver specific array of image sizes
397*4882a593Smuzhiyun  * @array_size: the length of the driver specific array of image sizes
398*4882a593Smuzhiyun  * @width_field: the name of the width field in the driver specific struct
399*4882a593Smuzhiyun  * @height_field: the name of the height field in the driver specific struct
400*4882a593Smuzhiyun  * @width: desired width.
401*4882a593Smuzhiyun  * @height: desired height.
402*4882a593Smuzhiyun  *
403*4882a593Smuzhiyun  * Finds the closest resolution to minimize the width and height differences
404*4882a593Smuzhiyun  * between what requested and the supported resolutions. The size of the width
405*4882a593Smuzhiyun  * and height fields in the driver specific must equal to that of u32, i.e. four
406*4882a593Smuzhiyun  * bytes.
407*4882a593Smuzhiyun  *
408*4882a593Smuzhiyun  * Returns the best match or NULL if the length of the array is zero.
409*4882a593Smuzhiyun  */
410*4882a593Smuzhiyun #define v4l2_find_nearest_size(array, array_size, width_field, height_field, \
411*4882a593Smuzhiyun 			       width, height)				\
412*4882a593Smuzhiyun 	({								\
413*4882a593Smuzhiyun 		BUILD_BUG_ON(sizeof((array)->width_field) != sizeof(u32) || \
414*4882a593Smuzhiyun 			     sizeof((array)->height_field) != sizeof(u32)); \
415*4882a593Smuzhiyun 		(typeof(&(array)[0]))__v4l2_find_nearest_size(		\
416*4882a593Smuzhiyun 			(array), array_size, sizeof(*(array)),		\
417*4882a593Smuzhiyun 			offsetof(typeof(*(array)), width_field),	\
418*4882a593Smuzhiyun 			offsetof(typeof(*(array)), height_field),	\
419*4882a593Smuzhiyun 			width, height);					\
420*4882a593Smuzhiyun 	})
421*4882a593Smuzhiyun const void *
422*4882a593Smuzhiyun __v4l2_find_nearest_size(const void *array, size_t array_size,
423*4882a593Smuzhiyun 			 size_t entry_size, size_t width_offset,
424*4882a593Smuzhiyun 			 size_t height_offset, s32 width, s32 height);
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun /**
427*4882a593Smuzhiyun  * v4l2_g_parm_cap - helper routine for vidioc_g_parm to fill this in by
428*4882a593Smuzhiyun  *      calling the g_frame_interval op of the given subdev. It only works
429*4882a593Smuzhiyun  *      for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the
430*4882a593Smuzhiyun  *      function name.
431*4882a593Smuzhiyun  *
432*4882a593Smuzhiyun  * @vdev: the struct video_device pointer. Used to determine the device caps.
433*4882a593Smuzhiyun  * @sd: the sub-device pointer.
434*4882a593Smuzhiyun  * @a: the VIDIOC_G_PARM argument.
435*4882a593Smuzhiyun  */
436*4882a593Smuzhiyun int v4l2_g_parm_cap(struct video_device *vdev,
437*4882a593Smuzhiyun 		    struct v4l2_subdev *sd, struct v4l2_streamparm *a);
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun /**
440*4882a593Smuzhiyun  * v4l2_s_parm_cap - helper routine for vidioc_s_parm to fill this in by
441*4882a593Smuzhiyun  *      calling the s_frame_interval op of the given subdev. It only works
442*4882a593Smuzhiyun  *      for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the
443*4882a593Smuzhiyun  *      function name.
444*4882a593Smuzhiyun  *
445*4882a593Smuzhiyun  * @vdev: the struct video_device pointer. Used to determine the device caps.
446*4882a593Smuzhiyun  * @sd: the sub-device pointer.
447*4882a593Smuzhiyun  * @a: the VIDIOC_S_PARM argument.
448*4882a593Smuzhiyun  */
449*4882a593Smuzhiyun int v4l2_s_parm_cap(struct video_device *vdev,
450*4882a593Smuzhiyun 		    struct v4l2_subdev *sd, struct v4l2_streamparm *a);
451*4882a593Smuzhiyun 
452*4882a593Smuzhiyun /* Compare two v4l2_fract structs */
453*4882a593Smuzhiyun #define V4L2_FRACT_COMPARE(a, OP, b)			\
454*4882a593Smuzhiyun 	((u64)(a).numerator * (b).denominator OP	\
455*4882a593Smuzhiyun 	(u64)(b).numerator * (a).denominator)
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun /* ------------------------------------------------------------------------- */
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun /* Pixel format and FourCC helpers */
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun /**
462*4882a593Smuzhiyun  * enum v4l2_pixel_encoding - specifies the pixel encoding value
463*4882a593Smuzhiyun  *
464*4882a593Smuzhiyun  * @V4L2_PIXEL_ENC_UNKNOWN:	Pixel encoding is unknown/un-initialized
465*4882a593Smuzhiyun  * @V4L2_PIXEL_ENC_YUV:		Pixel encoding is YUV
466*4882a593Smuzhiyun  * @V4L2_PIXEL_ENC_RGB:		Pixel encoding is RGB
467*4882a593Smuzhiyun  * @V4L2_PIXEL_ENC_BAYER:	Pixel encoding is Bayer
468*4882a593Smuzhiyun  */
469*4882a593Smuzhiyun enum v4l2_pixel_encoding {
470*4882a593Smuzhiyun 	V4L2_PIXEL_ENC_UNKNOWN = 0,
471*4882a593Smuzhiyun 	V4L2_PIXEL_ENC_YUV = 1,
472*4882a593Smuzhiyun 	V4L2_PIXEL_ENC_RGB = 2,
473*4882a593Smuzhiyun 	V4L2_PIXEL_ENC_BAYER = 3,
474*4882a593Smuzhiyun };
475*4882a593Smuzhiyun 
476*4882a593Smuzhiyun /**
477*4882a593Smuzhiyun  * struct v4l2_format_info - information about a V4L2 format
478*4882a593Smuzhiyun  * @format: 4CC format identifier (V4L2_PIX_FMT_*)
479*4882a593Smuzhiyun  * @pixel_enc: Pixel encoding (see enum v4l2_pixel_encoding above)
480*4882a593Smuzhiyun  * @mem_planes: Number of memory planes, which includes the alpha plane (1 to 4).
481*4882a593Smuzhiyun  * @comp_planes: Number of component planes, which includes the alpha plane (1 to 4).
482*4882a593Smuzhiyun  * @bpp: Array of per-plane bytes per pixel
483*4882a593Smuzhiyun  * @hdiv: Horizontal chroma subsampling factor
484*4882a593Smuzhiyun  * @vdiv: Vertical chroma subsampling factor
485*4882a593Smuzhiyun  * @block_w: Per-plane macroblock pixel width (optional)
486*4882a593Smuzhiyun  * @block_h: Per-plane macroblock pixel height (optional)
487*4882a593Smuzhiyun  */
488*4882a593Smuzhiyun struct v4l2_format_info {
489*4882a593Smuzhiyun 	u32 format;
490*4882a593Smuzhiyun 	u8 pixel_enc;
491*4882a593Smuzhiyun 	u8 mem_planes;
492*4882a593Smuzhiyun 	u8 comp_planes;
493*4882a593Smuzhiyun 	u8 bpp[4];
494*4882a593Smuzhiyun 	u8 hdiv;
495*4882a593Smuzhiyun 	u8 vdiv;
496*4882a593Smuzhiyun 	u8 block_w[4];
497*4882a593Smuzhiyun 	u8 block_h[4];
498*4882a593Smuzhiyun };
499*4882a593Smuzhiyun 
v4l2_is_format_rgb(const struct v4l2_format_info * f)500*4882a593Smuzhiyun static inline bool v4l2_is_format_rgb(const struct v4l2_format_info *f)
501*4882a593Smuzhiyun {
502*4882a593Smuzhiyun 	return f && f->pixel_enc == V4L2_PIXEL_ENC_RGB;
503*4882a593Smuzhiyun }
504*4882a593Smuzhiyun 
v4l2_is_format_yuv(const struct v4l2_format_info * f)505*4882a593Smuzhiyun static inline bool v4l2_is_format_yuv(const struct v4l2_format_info *f)
506*4882a593Smuzhiyun {
507*4882a593Smuzhiyun 	return f && f->pixel_enc == V4L2_PIXEL_ENC_YUV;
508*4882a593Smuzhiyun }
509*4882a593Smuzhiyun 
v4l2_is_format_bayer(const struct v4l2_format_info * f)510*4882a593Smuzhiyun static inline bool v4l2_is_format_bayer(const struct v4l2_format_info *f)
511*4882a593Smuzhiyun {
512*4882a593Smuzhiyun 	return f && f->pixel_enc == V4L2_PIXEL_ENC_BAYER;
513*4882a593Smuzhiyun }
514*4882a593Smuzhiyun 
515*4882a593Smuzhiyun const struct v4l2_format_info *v4l2_format_info(u32 format);
516*4882a593Smuzhiyun void v4l2_apply_frmsize_constraints(u32 *width, u32 *height,
517*4882a593Smuzhiyun 				    const struct v4l2_frmsize_stepwise *frmsize);
518*4882a593Smuzhiyun int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
519*4882a593Smuzhiyun 		     u32 width, u32 height);
520*4882a593Smuzhiyun int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelformat,
521*4882a593Smuzhiyun 			u32 width, u32 height);
522*4882a593Smuzhiyun 
v4l2_buffer_get_timestamp(const struct v4l2_buffer * buf)523*4882a593Smuzhiyun static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)
524*4882a593Smuzhiyun {
525*4882a593Smuzhiyun 	/*
526*4882a593Smuzhiyun 	 * When the timestamp comes from 32-bit user space, there may be
527*4882a593Smuzhiyun 	 * uninitialized data in tv_usec, so cast it to u32.
528*4882a593Smuzhiyun 	 * Otherwise allow invalid input for backwards compatibility.
529*4882a593Smuzhiyun 	 */
530*4882a593Smuzhiyun 	return buf->timestamp.tv_sec * NSEC_PER_SEC +
531*4882a593Smuzhiyun 		(u32)buf->timestamp.tv_usec * NSEC_PER_USEC;
532*4882a593Smuzhiyun }
533*4882a593Smuzhiyun 
v4l2_buffer_set_timestamp(struct v4l2_buffer * buf,u64 timestamp)534*4882a593Smuzhiyun static inline void v4l2_buffer_set_timestamp(struct v4l2_buffer *buf,
535*4882a593Smuzhiyun 					     u64 timestamp)
536*4882a593Smuzhiyun {
537*4882a593Smuzhiyun 	struct timespec64 ts = ns_to_timespec64(timestamp);
538*4882a593Smuzhiyun 
539*4882a593Smuzhiyun 	buf->timestamp.tv_sec  = ts.tv_sec;
540*4882a593Smuzhiyun 	buf->timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
541*4882a593Smuzhiyun }
542*4882a593Smuzhiyun 
v4l2_is_colorspace_valid(__u32 colorspace)543*4882a593Smuzhiyun static inline bool v4l2_is_colorspace_valid(__u32 colorspace)
544*4882a593Smuzhiyun {
545*4882a593Smuzhiyun 	return colorspace > V4L2_COLORSPACE_DEFAULT &&
546*4882a593Smuzhiyun 	       colorspace <= V4L2_COLORSPACE_DCI_P3;
547*4882a593Smuzhiyun }
548*4882a593Smuzhiyun 
v4l2_is_xfer_func_valid(__u32 xfer_func)549*4882a593Smuzhiyun static inline bool v4l2_is_xfer_func_valid(__u32 xfer_func)
550*4882a593Smuzhiyun {
551*4882a593Smuzhiyun 	return xfer_func > V4L2_XFER_FUNC_DEFAULT &&
552*4882a593Smuzhiyun 	       xfer_func <= V4L2_XFER_FUNC_SMPTE2084;
553*4882a593Smuzhiyun }
554*4882a593Smuzhiyun 
v4l2_is_ycbcr_enc_valid(__u8 ycbcr_enc)555*4882a593Smuzhiyun static inline bool v4l2_is_ycbcr_enc_valid(__u8 ycbcr_enc)
556*4882a593Smuzhiyun {
557*4882a593Smuzhiyun 	return ycbcr_enc > V4L2_YCBCR_ENC_DEFAULT &&
558*4882a593Smuzhiyun 	       ycbcr_enc <= V4L2_YCBCR_ENC_SMPTE240M;
559*4882a593Smuzhiyun }
560*4882a593Smuzhiyun 
v4l2_is_hsv_enc_valid(__u8 hsv_enc)561*4882a593Smuzhiyun static inline bool v4l2_is_hsv_enc_valid(__u8 hsv_enc)
562*4882a593Smuzhiyun {
563*4882a593Smuzhiyun 	return hsv_enc == V4L2_HSV_ENC_180 || hsv_enc == V4L2_HSV_ENC_256;
564*4882a593Smuzhiyun }
565*4882a593Smuzhiyun 
v4l2_is_quant_valid(__u8 quantization)566*4882a593Smuzhiyun static inline bool v4l2_is_quant_valid(__u8 quantization)
567*4882a593Smuzhiyun {
568*4882a593Smuzhiyun 	return quantization == V4L2_QUANTIZATION_FULL_RANGE ||
569*4882a593Smuzhiyun 	       quantization == V4L2_QUANTIZATION_LIM_RANGE;
570*4882a593Smuzhiyun }
571*4882a593Smuzhiyun 
572*4882a593Smuzhiyun #endif /* V4L2_COMMON_H_ */
573