xref: /openbmc/linux/include/media/v4l2-common.h (revision 32cddf9c94d81c4cd3c63fd1fe8ea9b98feac7e5)
1b2f0648fSHans Verkuil /*
2b2f0648fSHans Verkuil     v4l2 common internal API header
3b2f0648fSHans Verkuil 
4b2f0648fSHans Verkuil     This header contains internal shared ioctl definitions for use by the
5b2f0648fSHans Verkuil     internal low-level v4l2 drivers.
6b2f0648fSHans Verkuil     Each ioctl begins with VIDIOC_INT_ to clearly mark that it is an internal
7b2f0648fSHans Verkuil     define,
8b2f0648fSHans Verkuil 
9b2f0648fSHans Verkuil     Copyright (C) 2005  Hans Verkuil <hverkuil@xs4all.nl>
10b2f0648fSHans Verkuil 
11b2f0648fSHans Verkuil     This program is free software; you can redistribute it and/or modify
12b2f0648fSHans Verkuil     it under the terms of the GNU General Public License as published by
13b2f0648fSHans Verkuil     the Free Software Foundation; either version 2 of the License, or
14b2f0648fSHans Verkuil     (at your option) any later version.
15b2f0648fSHans Verkuil 
16b2f0648fSHans Verkuil     This program is distributed in the hope that it will be useful,
17b2f0648fSHans Verkuil     but WITHOUT ANY WARRANTY; without even the implied warranty of
18b2f0648fSHans Verkuil     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19b2f0648fSHans Verkuil     GNU General Public License for more details.
20b2f0648fSHans Verkuil 
21b2f0648fSHans Verkuil     You should have received a copy of the GNU General Public License
22b2f0648fSHans Verkuil     along with this program; if not, write to the Free Software
23b2f0648fSHans Verkuil     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24b2f0648fSHans Verkuil  */
25b2f0648fSHans Verkuil 
26b2f0648fSHans Verkuil #ifndef V4L2_COMMON_H_
27b2f0648fSHans Verkuil #define V4L2_COMMON_H_
28b2f0648fSHans Verkuil 
29401998faSMauro Carvalho Chehab #include <media/v4l2-dev.h>
30401998faSMauro Carvalho Chehab 
3176a59fe7SMauro Carvalho Chehab /* Common printk constructs for v4l-i2c drivers. These macros create a unique
327e8b09eaSHans Verkuil    prefix consisting of the driver name, the adapter number and the i2c
337e8b09eaSHans Verkuil    address. */
347e8b09eaSHans Verkuil #define v4l_printk(level, name, adapter, addr, fmt, arg...) \
357e8b09eaSHans Verkuil 	printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg)
367e8b09eaSHans Verkuil 
377e8b09eaSHans Verkuil #define v4l_client_printk(level, client, fmt, arg...)			    \
38f9d32f25SLars-Peter Clausen 	v4l_printk(level, (client)->dev.driver->name, (client)->adapter, \
397e8b09eaSHans Verkuil 		   (client)->addr, fmt , ## arg)
407e8b09eaSHans Verkuil 
417e8b09eaSHans Verkuil #define v4l_err(client, fmt, arg...) \
427e8b09eaSHans Verkuil 	v4l_client_printk(KERN_ERR, client, fmt , ## arg)
437e8b09eaSHans Verkuil 
447e8b09eaSHans Verkuil #define v4l_warn(client, fmt, arg...) \
457e8b09eaSHans Verkuil 	v4l_client_printk(KERN_WARNING, client, fmt , ## arg)
467e8b09eaSHans Verkuil 
477e8b09eaSHans Verkuil #define v4l_info(client, fmt, arg...) \
487e8b09eaSHans Verkuil 	v4l_client_printk(KERN_INFO, client, fmt , ## arg)
497e8b09eaSHans Verkuil 
507e8b09eaSHans Verkuil /* These three macros assume that the debug level is set with a module
517e8b09eaSHans Verkuil    parameter called 'debug'. */
52f167cb4eSMauro Carvalho Chehab #define v4l_dbg(level, debug, client, fmt, arg...)			     \
537e8b09eaSHans Verkuil 	do {								     \
547e8b09eaSHans Verkuil 		if (debug >= (level))					     \
557e8b09eaSHans Verkuil 			v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \
567e8b09eaSHans Verkuil 	} while (0)
577e8b09eaSHans Verkuil 
58a41231d5SMauro Carvalho Chehab /* Add a version of v4l_dbg to be used on drivers using dev_foo() macros */
59a41231d5SMauro Carvalho Chehab #define dev_dbg_lvl(__dev, __level, __debug, __fmt, __arg...)		\
60a41231d5SMauro Carvalho Chehab 	do {								\
61a41231d5SMauro Carvalho Chehab 		if (__debug >= (__level))				\
62a41231d5SMauro Carvalho Chehab 			dev_printk(KERN_DEBUG, __dev, __fmt, ##__arg);	\
63a41231d5SMauro Carvalho Chehab 	} while (0)
64a41231d5SMauro Carvalho Chehab 
657e8b09eaSHans Verkuil /* ------------------------------------------------------------------------- */
667e8b09eaSHans Verkuil 
67dd99120cSHans Verkuil /* These printk constructs can be used with v4l2_device and v4l2_subdev */
68dd99120cSHans Verkuil #define v4l2_printk(level, dev, fmt, arg...) \
69dd99120cSHans Verkuil 	printk(level "%s: " fmt, (dev)->name , ## arg)
70dd99120cSHans Verkuil 
71dd99120cSHans Verkuil #define v4l2_err(dev, fmt, arg...) \
72dd99120cSHans Verkuil 	v4l2_printk(KERN_ERR, dev, fmt , ## arg)
73dd99120cSHans Verkuil 
74dd99120cSHans Verkuil #define v4l2_warn(dev, fmt, arg...) \
75dd99120cSHans Verkuil 	v4l2_printk(KERN_WARNING, dev, fmt , ## arg)
76dd99120cSHans Verkuil 
77dd99120cSHans Verkuil #define v4l2_info(dev, fmt, arg...) \
78dd99120cSHans Verkuil 	v4l2_printk(KERN_INFO, dev, fmt , ## arg)
79dd99120cSHans Verkuil 
80dd99120cSHans Verkuil /* These three macros assume that the debug level is set with a module
81dd99120cSHans Verkuil    parameter called 'debug'. */
82dd99120cSHans Verkuil #define v4l2_dbg(level, debug, dev, fmt, arg...)			\
83dd99120cSHans Verkuil 	do {								\
84dd99120cSHans Verkuil 		if (debug >= (level))					\
85dd99120cSHans Verkuil 			v4l2_printk(KERN_DEBUG, dev, fmt , ## arg);	\
86dd99120cSHans Verkuil 	} while (0)
87dd99120cSHans Verkuil 
88b8719158SMauro Carvalho Chehab /**
89b8719158SMauro Carvalho Chehab  * v4l2_ctrl_query_fill- Fill in a struct v4l2_queryctrl
90b8719158SMauro Carvalho Chehab  *
91b8719158SMauro Carvalho Chehab  * @qctrl: pointer to the &struct v4l2_queryctrl to be filled
92b8719158SMauro Carvalho Chehab  * @min: minimum value for the control
93b8719158SMauro Carvalho Chehab  * @max: maximum value for the control
94b8719158SMauro Carvalho Chehab  * @step: control step
95b8719158SMauro Carvalho Chehab  * @def: default value for the control
96b8719158SMauro Carvalho Chehab  *
97b8719158SMauro Carvalho Chehab  * Fills the &struct v4l2_queryctrl fields for the query control.
98b8719158SMauro Carvalho Chehab  *
99b8719158SMauro Carvalho Chehab  * .. note::
100b8719158SMauro Carvalho Chehab  *
101b8719158SMauro Carvalho Chehab  *    This function assumes that the @qctrl->id field is filled.
102b8719158SMauro Carvalho Chehab  *
103b8719158SMauro Carvalho Chehab  * Returns -EINVAL if the control is not known by the V4L2 core, 0 on success.
104b8719158SMauro Carvalho Chehab  */
105dd99120cSHans Verkuil 
106b8719158SMauro Carvalho Chehab int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
107b8719158SMauro Carvalho Chehab 			 s32 min, s32 max, s32 step, s32 def);
1089cb2318bSHans Verkuil 
1099cb2318bSHans Verkuil /* ------------------------------------------------------------------------- */
1109cb2318bSHans Verkuil 
11178a3b4dbSHans Verkuil /* I2C Helper functions */
1128ffbc655SHans Verkuil 
1138ffbc655SHans Verkuil struct i2c_driver;
1148ffbc655SHans Verkuil struct i2c_adapter;
1158ffbc655SHans Verkuil struct i2c_client;
116d2653e92SJean Delvare struct i2c_device_id;
117dd99120cSHans Verkuil struct v4l2_device;
118dd99120cSHans Verkuil struct v4l2_subdev;
119dd99120cSHans Verkuil struct v4l2_subdev_ops;
1208ffbc655SHans Verkuil 
121a39c57f8SMauro Carvalho Chehab /**
122a39c57f8SMauro Carvalho Chehab  * v4l2_i2c_new_subdev - Load an i2c module and return an initialized
123a39c57f8SMauro Carvalho Chehab  *	&struct v4l2_subdev.
124a39c57f8SMauro Carvalho Chehab  *
125a39c57f8SMauro Carvalho Chehab  * @v4l2_dev: pointer to &struct v4l2_device
126a39c57f8SMauro Carvalho Chehab  * @adapter: pointer to struct i2c_adapter
127a39c57f8SMauro Carvalho Chehab  * @client_type:  name of the chip that's on the adapter.
128a39c57f8SMauro Carvalho Chehab  * @addr: I2C address. If zero, it will use @probe_addrs
129a39c57f8SMauro Carvalho Chehab  * @probe_addrs: array with a list of address. The last entry at such
130a39c57f8SMauro Carvalho Chehab  *	array should be %I2C_CLIENT_END.
131a39c57f8SMauro Carvalho Chehab  *
132a39c57f8SMauro Carvalho Chehab  * returns a &struct v4l2_subdev pointer.
133a39c57f8SMauro Carvalho Chehab  */
1343c7c9370SHans Verkuil struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
1359a1f8b34SLaurent Pinchart 		struct i2c_adapter *adapter, const char *client_type,
136f0222c7dSHans Verkuil 		u8 addr, const unsigned short *probe_addrs);
137f0222c7dSHans Verkuil 
138f0222c7dSHans Verkuil struct i2c_board_info;
139f0222c7dSHans Verkuil 
140a39c57f8SMauro Carvalho Chehab /**
141a39c57f8SMauro Carvalho Chehab  * v4l2_i2c_new_subdev_board - Load an i2c module and return an initialized
142a39c57f8SMauro Carvalho Chehab  *	&struct v4l2_subdev.
143a39c57f8SMauro Carvalho Chehab  *
144a39c57f8SMauro Carvalho Chehab  * @v4l2_dev: pointer to &struct v4l2_device
145a39c57f8SMauro Carvalho Chehab  * @adapter: pointer to struct i2c_adapter
146a39c57f8SMauro Carvalho Chehab  * @info: pointer to struct i2c_board_info used to replace the irq,
147a39c57f8SMauro Carvalho Chehab  *	 platform_data and addr arguments.
148a39c57f8SMauro Carvalho Chehab  * @probe_addrs: array with a list of address. The last entry at such
149a39c57f8SMauro Carvalho Chehab  *	array should be %I2C_CLIENT_END.
150a39c57f8SMauro Carvalho Chehab  *
151a39c57f8SMauro Carvalho Chehab  * returns a &struct v4l2_subdev pointer.
152a39c57f8SMauro Carvalho Chehab  */
153f0222c7dSHans Verkuil struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
1549a1f8b34SLaurent Pinchart 		struct i2c_adapter *adapter, struct i2c_board_info *info,
1559a1f8b34SLaurent Pinchart 		const unsigned short *probe_addrs);
156f0222c7dSHans Verkuil 
157a39c57f8SMauro Carvalho Chehab /**
15806582930SSakari Ailus  * v4l2_i2c_subdev_set_name - Set name for an I²C sub-device
15906582930SSakari Ailus  *
16006582930SSakari Ailus  * @sd: pointer to &struct v4l2_subdev
16106582930SSakari Ailus  * @client: pointer to struct i2c_client
16206582930SSakari Ailus  * @devname: the name of the device; if NULL, the I²C device's name will be used
16306582930SSakari Ailus  * @postfix: sub-device specific string to put right after the I²C device name;
16406582930SSakari Ailus  *	     may be NULL
16506582930SSakari Ailus  */
16606582930SSakari Ailus void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client,
16706582930SSakari Ailus 			      const char *devname, const char *postfix);
16806582930SSakari Ailus 
16906582930SSakari Ailus /**
170a39c57f8SMauro Carvalho Chehab  * v4l2_i2c_subdev_init - Initializes a &struct v4l2_subdev with data from
171a39c57f8SMauro Carvalho Chehab  *	an i2c_client struct.
172a39c57f8SMauro Carvalho Chehab  *
173a39c57f8SMauro Carvalho Chehab  * @sd: pointer to &struct v4l2_subdev
174a39c57f8SMauro Carvalho Chehab  * @client: pointer to struct i2c_client
175a39c57f8SMauro Carvalho Chehab  * @ops: pointer to &struct v4l2_subdev_ops
176a39c57f8SMauro Carvalho Chehab  */
177dd99120cSHans Verkuil void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
178dd99120cSHans Verkuil 		const struct v4l2_subdev_ops *ops);
179a39c57f8SMauro Carvalho Chehab 
180a39c57f8SMauro Carvalho Chehab /**
181a39c57f8SMauro Carvalho Chehab  * v4l2_i2c_subdev_addr - returns i2c client address of &struct v4l2_subdev.
182a39c57f8SMauro Carvalho Chehab  *
183a39c57f8SMauro Carvalho Chehab  * @sd: pointer to &struct v4l2_subdev
184a39c57f8SMauro Carvalho Chehab  *
185a39c57f8SMauro Carvalho Chehab  * Returns the address of an I2C sub-device
186a39c57f8SMauro Carvalho Chehab  */
187ab373190SHans Verkuil unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd);
188dd99120cSHans Verkuil 
18976a59fe7SMauro Carvalho Chehab /**
19076a59fe7SMauro Carvalho Chehab  * enum v4l2_i2c_tuner_type - specifies the range of tuner address that
19176a59fe7SMauro Carvalho Chehab  *	should be used when seeking for I2C devices.
19276a59fe7SMauro Carvalho Chehab  *
19376a59fe7SMauro Carvalho Chehab  * @ADDRS_RADIO:		Radio tuner addresses.
19476a59fe7SMauro Carvalho Chehab  *				Represent the following I2C addresses:
19576a59fe7SMauro Carvalho Chehab  *				0x10 (if compiled with tea5761 support)
19676a59fe7SMauro Carvalho Chehab  *				and 0x60.
19776a59fe7SMauro Carvalho Chehab  * @ADDRS_DEMOD:		Demod tuner addresses.
19876a59fe7SMauro Carvalho Chehab  *				Represent the following I2C addresses:
19976a59fe7SMauro Carvalho Chehab  *				0x42, 0x43, 0x4a and 0x4b.
20076a59fe7SMauro Carvalho Chehab  * @ADDRS_TV:			TV tuner addresses.
20176a59fe7SMauro Carvalho Chehab  *				Represent the following I2C addresses:
20276a59fe7SMauro Carvalho Chehab  *				0x42, 0x43, 0x4a, 0x4b, 0x60, 0x61, 0x62,
20376a59fe7SMauro Carvalho Chehab  *				0x63 and 0x64.
20476a59fe7SMauro Carvalho Chehab  * @ADDRS_TV_WITH_DEMOD:	TV tuner addresses if demod is present, this
20576a59fe7SMauro Carvalho Chehab  *				excludes addresses used by the demodulator
20676a59fe7SMauro Carvalho Chehab  *				from the list of candidates.
20776a59fe7SMauro Carvalho Chehab  *				Represent the following I2C addresses:
20876a59fe7SMauro Carvalho Chehab  *				0x60, 0x61, 0x62, 0x63 and 0x64.
20976a59fe7SMauro Carvalho Chehab  *
21076a59fe7SMauro Carvalho Chehab  * NOTE: All I2C addresses above use the 7-bit notation.
21176a59fe7SMauro Carvalho Chehab  */
212c7d29e2fSHans Verkuil enum v4l2_i2c_tuner_type {
21376a59fe7SMauro Carvalho Chehab 	ADDRS_RADIO,
21476a59fe7SMauro Carvalho Chehab 	ADDRS_DEMOD,
21576a59fe7SMauro Carvalho Chehab 	ADDRS_TV,
216c7d29e2fSHans Verkuil 	ADDRS_TV_WITH_DEMOD,
217c7d29e2fSHans Verkuil };
21876a59fe7SMauro Carvalho Chehab /**
21976a59fe7SMauro Carvalho Chehab  * v4l2_i2c_tuner_addrs - Return a list of I2C tuner addresses to probe.
22076a59fe7SMauro Carvalho Chehab  *
22176a59fe7SMauro Carvalho Chehab  * @type: type of the tuner to seek, as defined by
22276a59fe7SMauro Carvalho Chehab  *	  &enum v4l2_i2c_tuner_type.
22376a59fe7SMauro Carvalho Chehab  *
22476a59fe7SMauro Carvalho Chehab  * NOTE: Use only if the tuner addresses are unknown.
22576a59fe7SMauro Carvalho Chehab  */
226c7d29e2fSHans Verkuil const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type);
227c7d29e2fSHans Verkuil 
2288ffbc655SHans Verkuil /* ------------------------------------------------------------------------- */
2298ffbc655SHans Verkuil 
23085e09219SDmitri Belimov /* SPI Helper functions */
23185e09219SDmitri Belimov #if defined(CONFIG_SPI)
23285e09219SDmitri Belimov 
23385e09219SDmitri Belimov #include <linux/spi/spi.h>
23485e09219SDmitri Belimov 
23585e09219SDmitri Belimov struct spi_device;
23685e09219SDmitri Belimov 
237b8719158SMauro Carvalho Chehab /**
238b8719158SMauro Carvalho Chehab  *  v4l2_spi_new_subdev - Load an spi module and return an initialized
239b8719158SMauro Carvalho Chehab  *	&struct v4l2_subdev.
240b8719158SMauro Carvalho Chehab  *
241b8719158SMauro Carvalho Chehab  *
242b8719158SMauro Carvalho Chehab  * @v4l2_dev: pointer to &struct v4l2_device.
243b8719158SMauro Carvalho Chehab  * @master: pointer to struct spi_master.
244b8719158SMauro Carvalho Chehab  * @info: pointer to struct spi_board_info.
245b8719158SMauro Carvalho Chehab  *
246b8719158SMauro Carvalho Chehab  * returns a &struct v4l2_subdev pointer.
247b8719158SMauro Carvalho Chehab  */
24885e09219SDmitri Belimov struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
24985e09219SDmitri Belimov 		struct spi_master *master, struct spi_board_info *info);
25085e09219SDmitri Belimov 
251b8719158SMauro Carvalho Chehab /**
252b8719158SMauro Carvalho Chehab  * v4l2_spi_subdev_init - Initialize a v4l2_subdev with data from an
253b8719158SMauro Carvalho Chehab  *	spi_device struct.
254b8719158SMauro Carvalho Chehab  *
255b8719158SMauro Carvalho Chehab  * @sd: pointer to &struct v4l2_subdev
256b8719158SMauro Carvalho Chehab  * @spi: pointer to struct spi_device.
257b8719158SMauro Carvalho Chehab  * @ops: pointer to &struct v4l2_subdev_ops
258b8719158SMauro Carvalho Chehab  */
25985e09219SDmitri Belimov void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
26085e09219SDmitri Belimov 		const struct v4l2_subdev_ops *ops);
26185e09219SDmitri Belimov #endif
26285e09219SDmitri Belimov 
26385e09219SDmitri Belimov /* ------------------------------------------------------------------------- */
26485e09219SDmitri Belimov 
26501154ef5SMauro Carvalho Chehab /*
26601154ef5SMauro Carvalho Chehab  * FIXME: these remaining ioctls/structs should be removed as well, but they
26701154ef5SMauro Carvalho Chehab  * are still used in tuner-simple.c (TUNER_SET_CONFIG) and cx18/ivtv (RESET).
26801154ef5SMauro Carvalho Chehab  * To remove these ioctls some more cleanup is needed in those modules.
26976a59fe7SMauro Carvalho Chehab  *
27076a59fe7SMauro Carvalho Chehab  * It doesn't make much sense on documenting them, as what we really want is
27176a59fe7SMauro Carvalho Chehab  * to get rid of them.
27201154ef5SMauro Carvalho Chehab  */
2737e8b09eaSHans Verkuil 
27478a3b4dbSHans Verkuil /* s_config */
2757f171123SMauro Carvalho Chehab struct v4l2_priv_tun_config {
2767f171123SMauro Carvalho Chehab 	int tuner;
2777f171123SMauro Carvalho Chehab 	void *priv;
2787f171123SMauro Carvalho Chehab };
2797f171123SMauro Carvalho Chehab #define TUNER_SET_CONFIG           _IOW('d', 92, struct v4l2_priv_tun_config)
2805e453dc7SMichael Krufky 
2816c31e598SHans Verkuil #define VIDIOC_INT_RESET		_IOW ('d', 102, u32)
2826c31e598SHans Verkuil 
283b0d3159bSTrent Piepho /* ------------------------------------------------------------------------- */
284b0d3159bSTrent Piepho 
285b0d3159bSTrent Piepho /* Miscellaneous helper functions */
286b0d3159bSTrent Piepho 
28776a59fe7SMauro Carvalho Chehab /**
28876a59fe7SMauro Carvalho Chehab  * v4l_bound_align_image - adjust video dimensions according to
28976a59fe7SMauro Carvalho Chehab  *	a given constraints.
29076a59fe7SMauro Carvalho Chehab  *
29176a59fe7SMauro Carvalho Chehab  * @width:	pointer to width that will be adjusted if needed.
29276a59fe7SMauro Carvalho Chehab  * @wmin:	minimum width.
29376a59fe7SMauro Carvalho Chehab  * @wmax:	maximum width.
29476a59fe7SMauro Carvalho Chehab  * @walign:	least significant bit on width.
29576a59fe7SMauro Carvalho Chehab  * @height:	pointer to height that will be adjusted if needed.
29676a59fe7SMauro Carvalho Chehab  * @hmin:	minimum height.
29776a59fe7SMauro Carvalho Chehab  * @hmax:	maximum height.
298ae5a8ca8SNiklas Söderlund  * @halign:	least significant bit on height.
29976a59fe7SMauro Carvalho Chehab  * @salign:	least significant bit for the image size (e. g.
30076a59fe7SMauro Carvalho Chehab  *		:math:`width * height`).
30176a59fe7SMauro Carvalho Chehab  *
30276a59fe7SMauro Carvalho Chehab  * Clip an image to have @width between @wmin and @wmax, and @height between
30376a59fe7SMauro Carvalho Chehab  * @hmin and @hmax, inclusive.
30476a59fe7SMauro Carvalho Chehab  *
30576a59fe7SMauro Carvalho Chehab  * Additionally, the @width will be a multiple of :math:`2^{walign}`,
30676a59fe7SMauro Carvalho Chehab  * the @height will be a multiple of :math:`2^{halign}`, and the overall
30776a59fe7SMauro Carvalho Chehab  * size :math:`width * height` will be a multiple of :math:`2^{salign}`.
30876a59fe7SMauro Carvalho Chehab  *
30976a59fe7SMauro Carvalho Chehab  * .. note::
31076a59fe7SMauro Carvalho Chehab  *
31176a59fe7SMauro Carvalho Chehab  *    #. The clipping rectangle may be shrunk or enlarged to fit the alignment
31276a59fe7SMauro Carvalho Chehab  *       constraints.
31376a59fe7SMauro Carvalho Chehab  *    #. @wmax must not be smaller than @wmin.
31476a59fe7SMauro Carvalho Chehab  *    #. @hmax must not be smaller than @hmin.
31576a59fe7SMauro Carvalho Chehab  *    #. The alignments must not be so high there are no possible image
31676a59fe7SMauro Carvalho Chehab  *       sizes within the allowed bounds.
31776a59fe7SMauro Carvalho Chehab  *    #. @wmin and @hmin must be at least 1 (don't use 0).
31876a59fe7SMauro Carvalho Chehab  *    #. For @walign, @halign and @salign, if you don't care about a certain
31976a59fe7SMauro Carvalho Chehab  *       alignment, specify ``0``, as :math:`2^0 = 1` and one byte alignment
32076a59fe7SMauro Carvalho Chehab  *       is equivalent to no alignment.
32176a59fe7SMauro Carvalho Chehab  *    #. If you only want to adjust downward, specify a maximum that's the
32276a59fe7SMauro Carvalho Chehab  *       same as the initial value.
32376a59fe7SMauro Carvalho Chehab  */
32476a59fe7SMauro Carvalho Chehab void v4l_bound_align_image(unsigned int *width, unsigned int wmin,
325b0d3159bSTrent Piepho 			   unsigned int wmax, unsigned int walign,
32676a59fe7SMauro Carvalho Chehab 			   unsigned int *height, unsigned int hmin,
327b0d3159bSTrent Piepho 			   unsigned int hmax, unsigned int halign,
328b0d3159bSTrent Piepho 			   unsigned int salign);
3293fd8e647SHans Verkuil 
33076a59fe7SMauro Carvalho Chehab /**
33195ce9c28SSakari Ailus  * v4l2_find_nearest_size - Find the nearest size among a discrete
33295ce9c28SSakari Ailus  *	set of resolutions contained in an array of a driver specific struct.
33395ce9c28SSakari Ailus  *
33495ce9c28SSakari Ailus  * @array: a driver specific array of image sizes
335d2dc57b1SSakari Ailus  * @array_size: the length of the driver specific array of image sizes
33695ce9c28SSakari Ailus  * @width_field: the name of the width field in the driver specific struct
33795ce9c28SSakari Ailus  * @height_field: the name of the height field in the driver specific struct
33895ce9c28SSakari Ailus  * @width: desired width.
33995ce9c28SSakari Ailus  * @height: desired height.
34095ce9c28SSakari Ailus  *
34195ce9c28SSakari Ailus  * Finds the closest resolution to minimize the width and height differences
34295ce9c28SSakari Ailus  * between what requested and the supported resolutions. The size of the width
34395ce9c28SSakari Ailus  * and height fields in the driver specific must equal to that of u32, i.e. four
34495ce9c28SSakari Ailus  * bytes.
34595ce9c28SSakari Ailus  *
34695ce9c28SSakari Ailus  * Returns the best match or NULL if the length of the array is zero.
34795ce9c28SSakari Ailus  */
348d2dc57b1SSakari Ailus #define v4l2_find_nearest_size(array, array_size, width_field, height_field, \
34995ce9c28SSakari Ailus 			       width, height)				\
35095ce9c28SSakari Ailus 	({								\
35195ce9c28SSakari Ailus 		BUILD_BUG_ON(sizeof((array)->width_field) != sizeof(u32) || \
35295ce9c28SSakari Ailus 			     sizeof((array)->height_field) != sizeof(u32)); \
3532bbc46e8SSakari Ailus 		(typeof(&(array)[0]))__v4l2_find_nearest_size(		\
354d2dc57b1SSakari Ailus 			(array), array_size, sizeof(*(array)),		\
35595ce9c28SSakari Ailus 			offsetof(typeof(*(array)), width_field),	\
35695ce9c28SSakari Ailus 			offsetof(typeof(*(array)), height_field),	\
35795ce9c28SSakari Ailus 			width, height);					\
35895ce9c28SSakari Ailus 	})
35995ce9c28SSakari Ailus const void *
36095ce9c28SSakari Ailus __v4l2_find_nearest_size(const void *array, size_t array_size,
36195ce9c28SSakari Ailus 			 size_t entry_size, size_t width_offset,
36295ce9c28SSakari Ailus 			 size_t height_offset, s32 width, s32 height);
36395ce9c28SSakari Ailus 
36495ce9c28SSakari Ailus /**
365672de9a7SHans Verkuil  * v4l2_g_parm_cap - helper routine for vidioc_g_parm to fill this in by
366672de9a7SHans Verkuil  *      calling the g_frame_interval op of the given subdev. It only works
367672de9a7SHans Verkuil  *      for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the
368672de9a7SHans Verkuil  *      function name.
369672de9a7SHans Verkuil  *
370672de9a7SHans Verkuil  * @vdev: the struct video_device pointer. Used to determine the device caps.
371672de9a7SHans Verkuil  * @sd: the sub-device pointer.
372672de9a7SHans Verkuil  * @a: the VIDIOC_G_PARM argument.
373672de9a7SHans Verkuil  */
374672de9a7SHans Verkuil int v4l2_g_parm_cap(struct video_device *vdev,
375672de9a7SHans Verkuil 		    struct v4l2_subdev *sd, struct v4l2_streamparm *a);
376672de9a7SHans Verkuil 
377672de9a7SHans Verkuil /**
378672de9a7SHans Verkuil  * v4l2_s_parm_cap - helper routine for vidioc_s_parm to fill this in by
379672de9a7SHans Verkuil  *      calling the s_frame_interval op of the given subdev. It only works
380672de9a7SHans Verkuil  *      for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the
381672de9a7SHans Verkuil  *      function name.
382672de9a7SHans Verkuil  *
383672de9a7SHans Verkuil  * @vdev: the struct video_device pointer. Used to determine the device caps.
384672de9a7SHans Verkuil  * @sd: the sub-device pointer.
385672de9a7SHans Verkuil  * @a: the VIDIOC_S_PARM argument.
386672de9a7SHans Verkuil  */
387672de9a7SHans Verkuil int v4l2_s_parm_cap(struct video_device *vdev,
388672de9a7SHans Verkuil 		    struct v4l2_subdev *sd, struct v4l2_streamparm *a);
389672de9a7SHans Verkuil 
39085de5e06SAkinobu Mita /* Compare two v4l2_fract structs */
39185de5e06SAkinobu Mita #define V4L2_FRACT_COMPARE(a, OP, b)			\
39285de5e06SAkinobu Mita 	((u64)(a).numerator * (b).denominator OP	\
39385de5e06SAkinobu Mita 	(u64)(b).numerator * (a).denominator)
39485de5e06SAkinobu Mita 
395f44b969aSEzequiel Garcia /* ------------------------------------------------------------------------- */
396f44b969aSEzequiel Garcia 
397f44b969aSEzequiel Garcia /* Pixel format and FourCC helpers */
398f44b969aSEzequiel Garcia 
399f44b969aSEzequiel Garcia /**
400f44b969aSEzequiel Garcia  * struct v4l2_format_info - information about a V4L2 format
401f44b969aSEzequiel Garcia  * @format: 4CC format identifier (V4L2_PIX_FMT_*)
402f44b969aSEzequiel Garcia  * @mem_planes: Number of memory planes, which includes the alpha plane (1 to 4).
403f44b969aSEzequiel Garcia  * @comp_planes: Number of component planes, which includes the alpha plane (1 to 4).
404f44b969aSEzequiel Garcia  * @bpp: Array of per-plane bytes per pixel
405f44b969aSEzequiel Garcia  * @hdiv: Horizontal chroma subsampling factor
406f44b969aSEzequiel Garcia  * @vdiv: Vertical chroma subsampling factor
407f44b969aSEzequiel Garcia  * @block_w: Per-plane macroblock pixel width (optional)
408f44b969aSEzequiel Garcia  * @block_h: Per-plane macroblock pixel height (optional)
409f44b969aSEzequiel Garcia  */
410f44b969aSEzequiel Garcia struct v4l2_format_info {
411f44b969aSEzequiel Garcia 	u32 format;
412f44b969aSEzequiel Garcia 	u8 mem_planes;
413f44b969aSEzequiel Garcia 	u8 comp_planes;
414f44b969aSEzequiel Garcia 	u8 bpp[4];
415f44b969aSEzequiel Garcia 	u8 hdiv;
416f44b969aSEzequiel Garcia 	u8 vdiv;
417f44b969aSEzequiel Garcia 	u8 block_w[4];
418f44b969aSEzequiel Garcia 	u8 block_h[4];
419f44b969aSEzequiel Garcia };
420f44b969aSEzequiel Garcia 
421f44b969aSEzequiel Garcia const struct v4l2_format_info *v4l2_format_info(u32 format);
422f44b969aSEzequiel Garcia 
423*32cddf9cSBoris Brezillon void v4l2_apply_frmsize_constraints(u32 *width, u32 *height,
424*32cddf9cSBoris Brezillon 				    const struct v4l2_frmsize_stepwise *frmsize);
425ce57a82fSBoris Brezillon int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
426ce57a82fSBoris Brezillon 		     u32 width, u32 height);
427ce57a82fSBoris Brezillon int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelformat,
428ce57a82fSBoris Brezillon 			u32 width, u32 height);
429f44b969aSEzequiel Garcia 
430b2f0648fSHans Verkuil #endif /* V4L2_COMMON_H_ */
431