xref: /openbmc/linux/include/media/v4l2-common.h (revision d2653e92732bd3911feff6bee5e23dbf959381db)
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 
317e8b09eaSHans Verkuil /* v4l debugging and diagnostics */
327e8b09eaSHans Verkuil 
33401998faSMauro Carvalho Chehab /* Debug bitmask flags to be used on V4L2 */
34401998faSMauro Carvalho Chehab #define V4L2_DEBUG_IOCTL     0x01
35401998faSMauro Carvalho Chehab #define V4L2_DEBUG_IOCTL_ARG 0x02
36401998faSMauro Carvalho Chehab 
377e8b09eaSHans Verkuil /* Common printk constucts for v4l-i2c drivers. These macros create a unique
387e8b09eaSHans Verkuil    prefix consisting of the driver name, the adapter number and the i2c
397e8b09eaSHans Verkuil    address. */
407e8b09eaSHans Verkuil #define v4l_printk(level, name, adapter, addr, fmt, arg...) \
417e8b09eaSHans Verkuil 	printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg)
427e8b09eaSHans Verkuil 
437e8b09eaSHans Verkuil #define v4l_client_printk(level, client, fmt, arg...)			    \
447e8b09eaSHans Verkuil 	v4l_printk(level, (client)->driver->driver.name, (client)->adapter, \
457e8b09eaSHans Verkuil 		   (client)->addr, fmt , ## arg)
467e8b09eaSHans Verkuil 
477e8b09eaSHans Verkuil #define v4l_err(client, fmt, arg...) \
487e8b09eaSHans Verkuil 	v4l_client_printk(KERN_ERR, client, fmt , ## arg)
497e8b09eaSHans Verkuil 
507e8b09eaSHans Verkuil #define v4l_warn(client, fmt, arg...) \
517e8b09eaSHans Verkuil 	v4l_client_printk(KERN_WARNING, client, fmt , ## arg)
527e8b09eaSHans Verkuil 
537e8b09eaSHans Verkuil #define v4l_info(client, fmt, arg...) \
547e8b09eaSHans Verkuil 	v4l_client_printk(KERN_INFO, client, fmt , ## arg)
557e8b09eaSHans Verkuil 
567e8b09eaSHans Verkuil /* These three macros assume that the debug level is set with a module
577e8b09eaSHans Verkuil    parameter called 'debug'. */
58f167cb4eSMauro Carvalho Chehab #define v4l_dbg(level, debug, client, fmt, arg...)			     \
597e8b09eaSHans Verkuil 	do { 								     \
607e8b09eaSHans Verkuil 		if (debug >= (level))					     \
617e8b09eaSHans Verkuil 			v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \
627e8b09eaSHans Verkuil 	} while (0)
637e8b09eaSHans Verkuil 
647e8b09eaSHans Verkuil 
657e8b09eaSHans Verkuil /* Use this macro for non-I2C drivers. Pass the driver name as the first arg. */
667e8b09eaSHans Verkuil #define v4l_print_ioctl(name, cmd)  		 \
677e8b09eaSHans Verkuil 	do {  					 \
687e8b09eaSHans Verkuil 		printk(KERN_DEBUG "%s: ", name); \
697e8b09eaSHans Verkuil 		v4l_printk_ioctl(cmd);		 \
707e8b09eaSHans Verkuil 	} while (0)
717e8b09eaSHans Verkuil 
727e8b09eaSHans Verkuil /* Use this macro in I2C drivers where 'client' is the struct i2c_client
737e8b09eaSHans Verkuil    pointer */
747e8b09eaSHans Verkuil #define v4l_i2c_print_ioctl(client, cmd) 		   \
757e8b09eaSHans Verkuil 	do {      					   \
767e8b09eaSHans Verkuil 		v4l_client_printk(KERN_DEBUG, client, ""); \
777e8b09eaSHans Verkuil 		v4l_printk_ioctl(cmd);			   \
787e8b09eaSHans Verkuil 	} while (0)
797e8b09eaSHans Verkuil 
807e8b09eaSHans Verkuil /* ------------------------------------------------------------------------- */
817e8b09eaSHans Verkuil 
829cb2318bSHans Verkuil /* Control helper functions */
839cb2318bSHans Verkuil 
849cb2318bSHans Verkuil int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
859cb2318bSHans Verkuil 		const char **menu_items);
869cb2318bSHans Verkuil const char **v4l2_ctrl_get_menu(u32 id);
879cb2318bSHans Verkuil int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def);
889cb2318bSHans Verkuil int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl);
899cb2318bSHans Verkuil int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu,
909cb2318bSHans Verkuil 		struct v4l2_queryctrl *qctrl, const char **menu_items);
919cb2318bSHans Verkuil u32 v4l2_ctrl_next(const u32 * const *ctrl_classes, u32 id);
929cb2318bSHans Verkuil 
939cb2318bSHans Verkuil /* ------------------------------------------------------------------------- */
949cb2318bSHans Verkuil 
95f3d092b8SHans Verkuil /* Register/chip ident helper function */
96f3d092b8SHans Verkuil 
97f3d092b8SHans Verkuil struct i2c_client; /* forward reference */
98f3d092b8SHans Verkuil int v4l2_chip_match_i2c_client(struct i2c_client *c, u32 id_type, u32 chip_id);
993434eb7eSHans Verkuil int v4l2_chip_ident_i2c_client(struct i2c_client *c, struct v4l2_chip_ident *chip,
1003434eb7eSHans Verkuil 		u32 ident, u32 revision);
101f3d092b8SHans Verkuil int v4l2_chip_match_host(u32 id_type, u32 chip_id);
102f3d092b8SHans Verkuil 
103f3d092b8SHans Verkuil /* ------------------------------------------------------------------------- */
104f3d092b8SHans Verkuil 
1058ffbc655SHans Verkuil /* Helper function for I2C legacy drivers */
1068ffbc655SHans Verkuil 
1078ffbc655SHans Verkuil struct i2c_driver;
1088ffbc655SHans Verkuil struct i2c_adapter;
1098ffbc655SHans Verkuil struct i2c_client;
110*d2653e92SJean Delvare struct i2c_device_id;
1118ffbc655SHans Verkuil 
1128ffbc655SHans Verkuil int v4l2_i2c_attach(struct i2c_adapter *adapter, int address, struct i2c_driver *driver,
113*d2653e92SJean Delvare 		const char *name,
114*d2653e92SJean Delvare 		int (*probe)(struct i2c_client *, const struct i2c_device_id *));
1158ffbc655SHans Verkuil 
1168ffbc655SHans Verkuil /* ------------------------------------------------------------------------- */
1178ffbc655SHans Verkuil 
1187e8b09eaSHans Verkuil /* Internal ioctls */
1197e8b09eaSHans Verkuil 
120b2f0648fSHans Verkuil /* VIDIOC_INT_DECODE_VBI_LINE */
121b2f0648fSHans Verkuil struct v4l2_decode_vbi_line {
122b2f0648fSHans Verkuil 	u32 is_second_field;	/* Set to 0 for the first (odd) field,
123b2f0648fSHans Verkuil 				   set to 1 for the second (even) field. */
124b2f0648fSHans Verkuil 	u8 *p; 			/* Pointer to the sliced VBI data from the decoder.
125b2f0648fSHans Verkuil 				   On exit points to the start of the payload. */
126b2f0648fSHans Verkuil 	u32 line;		/* Line number of the sliced VBI data (1-23) */
127b2f0648fSHans Verkuil 	u32 type;		/* VBI service type (V4L2_SLICED_*). 0 if no service found */
128b2f0648fSHans Verkuil };
129b2f0648fSHans Verkuil 
1307f171123SMauro Carvalho Chehab struct v4l2_priv_tun_config {
1317f171123SMauro Carvalho Chehab 	int tuner;
1327f171123SMauro Carvalho Chehab 	void *priv;
1337f171123SMauro Carvalho Chehab };
1347f171123SMauro Carvalho Chehab 
1355e453dc7SMichael Krufky /* audio ioctls */
136757d2505SHans Verkuil 
137757d2505SHans Verkuil /* v4l device was opened in Radio mode, to be replaced by VIDIOC_INT_S_TUNER_MODE */
1385e453dc7SMichael Krufky #define AUDC_SET_RADIO        _IO('d',88)
139757d2505SHans Verkuil 
1405e453dc7SMichael Krufky /* tuner ioctls */
141757d2505SHans Verkuil 
1425e453dc7SMichael Krufky /* Sets tuner type and its I2C addr */
1435e453dc7SMichael Krufky #define TUNER_SET_TYPE_ADDR          _IOW('d', 90, int)
144757d2505SHans Verkuil 
145757d2505SHans Verkuil /* Puts tuner on powersaving state, disabling it, except for i2c. To be replaced
146757d2505SHans Verkuil    by VIDIOC_INT_S_STANDBY. */
1475e453dc7SMichael Krufky #define TUNER_SET_STANDBY            _IOW('d', 91, int)
148757d2505SHans Verkuil 
1495e453dc7SMichael Krufky /* Sets tda9887 specific stuff, like port1, port2 and qss */
1507f171123SMauro Carvalho Chehab #define TUNER_SET_CONFIG           _IOW('d', 92, struct v4l2_priv_tun_config)
1515e453dc7SMichael Krufky 
152757d2505SHans Verkuil /* Switch the tuner to a specific tuner mode. Replacement of AUDC_SET_RADIO */
153757d2505SHans Verkuil #define VIDIOC_INT_S_TUNER_MODE	     _IOW('d', 93, enum v4l2_tuner_type)
154757d2505SHans Verkuil 
155757d2505SHans Verkuil /* Generic standby command. Passing -1 (all bits set to 1) will put the whole
156757d2505SHans Verkuil    chip into standby mode, value 0 will make the chip fully active. Specific
157757d2505SHans Verkuil    bits can be used by certain chips to enable/disable specific subsystems.
158757d2505SHans Verkuil    Replacement of TUNER_SET_STANDBY. */
159757d2505SHans Verkuil #define VIDIOC_INT_S_STANDBY 	     _IOW('d', 94, u32)
160757d2505SHans Verkuil 
16152ebc763STrent Piepho /* 100, 101 used by  VIDIOC_DBG_[SG]_REGISTER */
162b2f0648fSHans Verkuil 
163784e8fe4SHans Verkuil /* Generic reset command. The argument selects which subsystems to reset.
164784e8fe4SHans Verkuil    Passing 0 will always reset the whole chip. */
165784e8fe4SHans Verkuil #define VIDIOC_INT_RESET            	_IOW ('d', 102, u32)
166b2f0648fSHans Verkuil 
1673578d3ddSHans Verkuil /* Set the frequency (in Hz) of the audio clock output.
168b2f0648fSHans Verkuil    Used to slave an audio processor to the video decoder, ensuring that audio
1693578d3ddSHans Verkuil    and video remain synchronized.
1703578d3ddSHans Verkuil    Usual values for the frequency are 48000, 44100 or 32000 Hz.
1713578d3ddSHans Verkuil    If the frequency is not supported, then -EINVAL is returned. */
1723578d3ddSHans Verkuil #define VIDIOC_INT_AUDIO_CLOCK_FREQ 	_IOW ('d', 103, u32)
173b2f0648fSHans Verkuil 
174b2f0648fSHans Verkuil /* Video decoders that support sliced VBI need to implement this ioctl.
175b2f0648fSHans Verkuil    Field p of the v4l2_sliced_vbi_line struct is set to the start of the VBI
176b2f0648fSHans Verkuil    data that was generated by the decoder. The driver then parses the sliced
177b2f0648fSHans Verkuil    VBI data and sets the other fields in the struct accordingly. The pointer p
178b2f0648fSHans Verkuil    is updated to point to the start of the payload which can be copied
179b2f0648fSHans Verkuil    verbatim into the data field of the v4l2_sliced_vbi_data struct. If no
180b2f0648fSHans Verkuil    valid VBI data was found, then the type field is set to 0 on return. */
181b2f0648fSHans Verkuil #define VIDIOC_INT_DECODE_VBI_LINE  	_IOWR('d', 104, struct v4l2_decode_vbi_line)
182b2f0648fSHans Verkuil 
183b2f0648fSHans Verkuil /* Used to generate VBI signals on a video signal. v4l2_sliced_vbi_data is
184b2f0648fSHans Verkuil    filled with the data packets that should be output. Note that if you set
18512db5607SMauro Carvalho Chehab    the line field to 0, then that VBI signal is disabled. If no
18612db5607SMauro Carvalho Chehab    valid VBI data was found, then the type field is set to 0 on return. */
187b2f0648fSHans Verkuil #define VIDIOC_INT_S_VBI_DATA 		_IOW ('d', 105, struct v4l2_sliced_vbi_data)
188b2f0648fSHans Verkuil 
189b2f0648fSHans Verkuil /* Used to obtain the sliced VBI packet from a readback register. Not all
190b2f0648fSHans Verkuil    video decoders support this. If no data is available because the readback
191b2f0648fSHans Verkuil    register contains invalid or erroneous data -EIO is returned. Note that
192b2f0648fSHans Verkuil    you must fill in the 'id' member and the 'field' member (to determine
193b2f0648fSHans Verkuil    whether CC data from the first or second field should be obtained). */
19441f38b43SMauro Carvalho Chehab #define VIDIOC_INT_G_VBI_DATA 		_IOWR('d', 106, struct v4l2_sliced_vbi_data)
195b2f0648fSHans Verkuil 
1969bb13a6dSMauro Carvalho Chehab /* Sets I2S speed in bps. This is used to provide a standard way to select I2S
1979bb13a6dSMauro Carvalho Chehab    clock used by driving digital audio streams at some board designs.
1989bb13a6dSMauro Carvalho Chehab    Usual values for the frequency are 1024000 and 2048000.
1999bb13a6dSMauro Carvalho Chehab    If the frequency is not supported, then -EINVAL is returned. */
2009bb13a6dSMauro Carvalho Chehab #define VIDIOC_INT_I2S_CLOCK_FREQ 	_IOW ('d', 108, u32)
2019bb13a6dSMauro Carvalho Chehab 
202757d2505SHans Verkuil /* Routing definition, device dependent. It specifies which inputs (if any)
203757d2505SHans Verkuil    should be routed to which outputs (if any). */
204757d2505SHans Verkuil struct v4l2_routing {
205757d2505SHans Verkuil 	u32 input;
206757d2505SHans Verkuil 	u32 output;
207757d2505SHans Verkuil };
208757d2505SHans Verkuil 
209757d2505SHans Verkuil /* These internal commands should be used to define the inputs and outputs
2108bf2f8e7SHans Verkuil    of an audio/video chip. They will replace the v4l2 API commands
2118bf2f8e7SHans Verkuil    VIDIOC_S/G_INPUT, VIDIOC_S/G_OUTPUT, VIDIOC_S/G_AUDIO and VIDIOC_S/G_AUDOUT
2128bf2f8e7SHans Verkuil    that are meant to be used by the user.
2138bf2f8e7SHans Verkuil    The internal commands should be used to switch inputs/outputs
214757d2505SHans Verkuil    because only the driver knows how to map a 'Television' input to the precise
215757d2505SHans Verkuil    input/output routing of an A/D converter, or a DSP, or a video digitizer.
216757d2505SHans Verkuil    These four commands should only be sent directly to an i2c device, they
217757d2505SHans Verkuil    should not be broadcast as the routing is very device specific. */
218757d2505SHans Verkuil #define	VIDIOC_INT_S_AUDIO_ROUTING	_IOW ('d', 109, struct v4l2_routing)
21941f38b43SMauro Carvalho Chehab #define	VIDIOC_INT_G_AUDIO_ROUTING	_IOR ('d', 110, struct v4l2_routing)
220757d2505SHans Verkuil #define	VIDIOC_INT_S_VIDEO_ROUTING	_IOW ('d', 111, struct v4l2_routing)
22141f38b43SMauro Carvalho Chehab #define	VIDIOC_INT_G_VIDEO_ROUTING	_IOR ('d', 112, struct v4l2_routing)
222757d2505SHans Verkuil 
223b7f8292cSHans Verkuil struct v4l2_crystal_freq {
224b7f8292cSHans Verkuil 	u32 freq;	/* frequency in Hz of the crystal */
225b7f8292cSHans Verkuil 	u32 flags; 	/* device specific flags */
226b7f8292cSHans Verkuil };
227b7f8292cSHans Verkuil 
228b7f8292cSHans Verkuil /* Sets the frequency of the crystal used to generate the clocks.
229b7f8292cSHans Verkuil    An extra flags field allows device specific configuration regarding
230b7f8292cSHans Verkuil    clock frequency dividers, etc. If not used, then set flags to 0.
231b7f8292cSHans Verkuil    If the frequency is not supported, then -EINVAL is returned. */
232b7f8292cSHans Verkuil #define VIDIOC_INT_S_CRYSTAL_FREQ 	_IOW ('d', 113, struct v4l2_crystal_freq)
233b7f8292cSHans Verkuil 
2349c4dfadbSJonathan Corbet /* Initialize the sensor registors to some sort of reasonable
2359c4dfadbSJonathan Corbet    default values. */
2369c4dfadbSJonathan Corbet #define VIDIOC_INT_INIT			_IOW ('d', 114, u32)
2379c4dfadbSJonathan Corbet 
238045290b2SHans Verkuil /* Set v4l2_std_id for video OUTPUT devices. This is ignored by
239045290b2SHans Verkuil    video input devices. */
240045290b2SHans Verkuil #define VIDIOC_INT_S_STD_OUTPUT		_IOW  ('d', 115, v4l2_std_id)
241045290b2SHans Verkuil 
242045290b2SHans Verkuil /* Get v4l2_std_id for video OUTPUT devices. This is ignored by
243045290b2SHans Verkuil    video input devices. */
244045290b2SHans Verkuil #define VIDIOC_INT_G_STD_OUTPUT		_IOW  ('d', 116, v4l2_std_id)
245045290b2SHans Verkuil 
246b2f0648fSHans Verkuil #endif /* V4L2_COMMON_H_ */
247