xref: /openbmc/linux/include/media/v4l2-common.h (revision dd99120c7165c6873a423977d1eaa41b6e2d1ffc)
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 /* Common printk constucts 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...)			    \
387e8b09eaSHans Verkuil 	v4l_printk(level, (client)->driver->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 
587e8b09eaSHans Verkuil /* ------------------------------------------------------------------------- */
597e8b09eaSHans Verkuil 
60*dd99120cSHans Verkuil /* These printk constructs can be used with v4l2_device and v4l2_subdev */
61*dd99120cSHans Verkuil #define v4l2_printk(level, dev, fmt, arg...) \
62*dd99120cSHans Verkuil 	printk(level "%s: " fmt, (dev)->name , ## arg)
63*dd99120cSHans Verkuil 
64*dd99120cSHans Verkuil #define v4l2_err(dev, fmt, arg...) \
65*dd99120cSHans Verkuil 	v4l2_printk(KERN_ERR, dev, fmt , ## arg)
66*dd99120cSHans Verkuil 
67*dd99120cSHans Verkuil #define v4l2_warn(dev, fmt, arg...) \
68*dd99120cSHans Verkuil 	v4l2_printk(KERN_WARNING, dev, fmt , ## arg)
69*dd99120cSHans Verkuil 
70*dd99120cSHans Verkuil #define v4l2_info(dev, fmt, arg...) \
71*dd99120cSHans Verkuil 	v4l2_printk(KERN_INFO, dev, fmt , ## arg)
72*dd99120cSHans Verkuil 
73*dd99120cSHans Verkuil /* These three macros assume that the debug level is set with a module
74*dd99120cSHans Verkuil    parameter called 'debug'. */
75*dd99120cSHans Verkuil #define v4l2_dbg(level, debug, dev, fmt, arg...)			\
76*dd99120cSHans Verkuil 	do { 								\
77*dd99120cSHans Verkuil 		if (debug >= (level))					\
78*dd99120cSHans Verkuil 			v4l2_printk(KERN_DEBUG, dev, fmt , ## arg); 	\
79*dd99120cSHans Verkuil 	} while (0)
80*dd99120cSHans Verkuil 
81*dd99120cSHans Verkuil /* ------------------------------------------------------------------------- */
82*dd99120cSHans Verkuil 
8335ea11ffSHans Verkuil /* Priority helper functions */
8435ea11ffSHans Verkuil 
8535ea11ffSHans Verkuil struct v4l2_prio_state {
8635ea11ffSHans Verkuil 	atomic_t prios[4];
8735ea11ffSHans Verkuil };
8835ea11ffSHans Verkuil int v4l2_prio_init(struct v4l2_prio_state *global);
8935ea11ffSHans Verkuil int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
9035ea11ffSHans Verkuil 		     enum v4l2_priority new);
9135ea11ffSHans Verkuil int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
9235ea11ffSHans Verkuil int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local);
9335ea11ffSHans Verkuil enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
9435ea11ffSHans Verkuil int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local);
9535ea11ffSHans Verkuil 
9635ea11ffSHans Verkuil /* ------------------------------------------------------------------------- */
9735ea11ffSHans Verkuil 
989cb2318bSHans Verkuil /* Control helper functions */
999cb2318bSHans Verkuil 
1009cb2318bSHans Verkuil int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
1019cb2318bSHans Verkuil 		const char **menu_items);
10269028d70SHans Verkuil const char *v4l2_ctrl_get_name(u32 id);
1039cb2318bSHans Verkuil const char **v4l2_ctrl_get_menu(u32 id);
1049cb2318bSHans Verkuil int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def);
1059cb2318bSHans Verkuil int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl);
1069cb2318bSHans Verkuil int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu,
1079cb2318bSHans Verkuil 		struct v4l2_queryctrl *qctrl, const char **menu_items);
1081e551266SHans Verkuil #define V4L2_CTRL_MENU_IDS_END (0xffffffff)
1091e551266SHans Verkuil int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids);
1109cb2318bSHans Verkuil u32 v4l2_ctrl_next(const u32 * const *ctrl_classes, u32 id);
1119cb2318bSHans Verkuil 
1129cb2318bSHans Verkuil /* ------------------------------------------------------------------------- */
1139cb2318bSHans Verkuil 
114f3d092b8SHans Verkuil /* Register/chip ident helper function */
115f3d092b8SHans Verkuil 
116f3d092b8SHans Verkuil struct i2c_client; /* forward reference */
117f3d092b8SHans Verkuil int v4l2_chip_match_i2c_client(struct i2c_client *c, u32 id_type, u32 chip_id);
1183434eb7eSHans Verkuil int v4l2_chip_ident_i2c_client(struct i2c_client *c, struct v4l2_chip_ident *chip,
1193434eb7eSHans Verkuil 		u32 ident, u32 revision);
120f3d092b8SHans Verkuil int v4l2_chip_match_host(u32 id_type, u32 chip_id);
121f3d092b8SHans Verkuil 
122f3d092b8SHans Verkuil /* ------------------------------------------------------------------------- */
123f3d092b8SHans Verkuil 
1248ffbc655SHans Verkuil /* Helper function for I2C legacy drivers */
1258ffbc655SHans Verkuil 
1268ffbc655SHans Verkuil struct i2c_driver;
1278ffbc655SHans Verkuil struct i2c_adapter;
1288ffbc655SHans Verkuil struct i2c_client;
129d2653e92SJean Delvare struct i2c_device_id;
130*dd99120cSHans Verkuil struct v4l2_device;
131*dd99120cSHans Verkuil struct v4l2_subdev;
132*dd99120cSHans Verkuil struct v4l2_subdev_ops;
1338ffbc655SHans Verkuil 
1348ffbc655SHans Verkuil int v4l2_i2c_attach(struct i2c_adapter *adapter, int address, struct i2c_driver *driver,
135d2653e92SJean Delvare 		const char *name,
136d2653e92SJean Delvare 		int (*probe)(struct i2c_client *, const struct i2c_device_id *));
1378ffbc655SHans Verkuil 
138*dd99120cSHans Verkuil /* Load an i2c module and return an initialized v4l2_subdev struct.
139*dd99120cSHans Verkuil    Only call request_module if module_name != NULL.
140*dd99120cSHans Verkuil    The client_type argument is the name of the chip that's on the adapter. */
141*dd99120cSHans Verkuil struct v4l2_subdev *v4l2_i2c_new_subdev(struct i2c_adapter *adapter,
142*dd99120cSHans Verkuil 		const char *module_name, const char *client_type, u8 addr);
143*dd99120cSHans Verkuil /* Probe and load an i2c module and return an initialized v4l2_subdev struct.
144*dd99120cSHans Verkuil    Only call request_module if module_name != NULL.
145*dd99120cSHans Verkuil    The client_type argument is the name of the chip that's on the adapter. */
146*dd99120cSHans Verkuil struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct i2c_adapter *adapter,
147*dd99120cSHans Verkuil 		const char *module_name, const char *client_type,
148*dd99120cSHans Verkuil 		const unsigned short *addrs);
149*dd99120cSHans Verkuil /* Initialize an v4l2_subdev with data from an i2c_client struct */
150*dd99120cSHans Verkuil void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
151*dd99120cSHans Verkuil 		const struct v4l2_subdev_ops *ops);
152*dd99120cSHans Verkuil 
1538ffbc655SHans Verkuil /* ------------------------------------------------------------------------- */
1548ffbc655SHans Verkuil 
1557e8b09eaSHans Verkuil /* Internal ioctls */
1567e8b09eaSHans Verkuil 
157b2f0648fSHans Verkuil /* VIDIOC_INT_DECODE_VBI_LINE */
158b2f0648fSHans Verkuil struct v4l2_decode_vbi_line {
159b2f0648fSHans Verkuil 	u32 is_second_field;	/* Set to 0 for the first (odd) field,
160b2f0648fSHans Verkuil 				   set to 1 for the second (even) field. */
161b2f0648fSHans Verkuil 	u8 *p; 			/* Pointer to the sliced VBI data from the decoder.
162b2f0648fSHans Verkuil 				   On exit points to the start of the payload. */
163b2f0648fSHans Verkuil 	u32 line;		/* Line number of the sliced VBI data (1-23) */
164b2f0648fSHans Verkuil 	u32 type;		/* VBI service type (V4L2_SLICED_*). 0 if no service found */
165b2f0648fSHans Verkuil };
166b2f0648fSHans Verkuil 
1677f171123SMauro Carvalho Chehab struct v4l2_priv_tun_config {
1687f171123SMauro Carvalho Chehab 	int tuner;
1697f171123SMauro Carvalho Chehab 	void *priv;
1707f171123SMauro Carvalho Chehab };
1717f171123SMauro Carvalho Chehab 
1725e453dc7SMichael Krufky /* audio ioctls */
173757d2505SHans Verkuil 
174757d2505SHans Verkuil /* v4l device was opened in Radio mode, to be replaced by VIDIOC_INT_S_TUNER_MODE */
1755e453dc7SMichael Krufky #define AUDC_SET_RADIO        _IO('d',88)
176757d2505SHans Verkuil 
1775e453dc7SMichael Krufky /* tuner ioctls */
178757d2505SHans Verkuil 
1795e453dc7SMichael Krufky /* Sets tuner type and its I2C addr */
1805e453dc7SMichael Krufky #define TUNER_SET_TYPE_ADDR          _IOW('d', 90, int)
181757d2505SHans Verkuil 
182757d2505SHans Verkuil /* Puts tuner on powersaving state, disabling it, except for i2c. To be replaced
183757d2505SHans Verkuil    by VIDIOC_INT_S_STANDBY. */
1845e453dc7SMichael Krufky #define TUNER_SET_STANDBY            _IOW('d', 91, int)
185757d2505SHans Verkuil 
1865e453dc7SMichael Krufky /* Sets tda9887 specific stuff, like port1, port2 and qss */
1877f171123SMauro Carvalho Chehab #define TUNER_SET_CONFIG           _IOW('d', 92, struct v4l2_priv_tun_config)
1885e453dc7SMichael Krufky 
189757d2505SHans Verkuil /* Switch the tuner to a specific tuner mode. Replacement of AUDC_SET_RADIO */
190757d2505SHans Verkuil #define VIDIOC_INT_S_TUNER_MODE	     _IOW('d', 93, enum v4l2_tuner_type)
191757d2505SHans Verkuil 
192757d2505SHans Verkuil /* Generic standby command. Passing -1 (all bits set to 1) will put the whole
193757d2505SHans Verkuil    chip into standby mode, value 0 will make the chip fully active. Specific
194757d2505SHans Verkuil    bits can be used by certain chips to enable/disable specific subsystems.
195757d2505SHans Verkuil    Replacement of TUNER_SET_STANDBY. */
196757d2505SHans Verkuil #define VIDIOC_INT_S_STANDBY 	     _IOW('d', 94, u32)
197757d2505SHans Verkuil 
19852ebc763STrent Piepho /* 100, 101 used by  VIDIOC_DBG_[SG]_REGISTER */
199b2f0648fSHans Verkuil 
200784e8fe4SHans Verkuil /* Generic reset command. The argument selects which subsystems to reset.
201784e8fe4SHans Verkuil    Passing 0 will always reset the whole chip. */
202784e8fe4SHans Verkuil #define VIDIOC_INT_RESET            	_IOW ('d', 102, u32)
203b2f0648fSHans Verkuil 
2043578d3ddSHans Verkuil /* Set the frequency (in Hz) of the audio clock output.
205b2f0648fSHans Verkuil    Used to slave an audio processor to the video decoder, ensuring that audio
2063578d3ddSHans Verkuil    and video remain synchronized.
2073578d3ddSHans Verkuil    Usual values for the frequency are 48000, 44100 or 32000 Hz.
2083578d3ddSHans Verkuil    If the frequency is not supported, then -EINVAL is returned. */
2093578d3ddSHans Verkuil #define VIDIOC_INT_AUDIO_CLOCK_FREQ 	_IOW ('d', 103, u32)
210b2f0648fSHans Verkuil 
211b2f0648fSHans Verkuil /* Video decoders that support sliced VBI need to implement this ioctl.
212b2f0648fSHans Verkuil    Field p of the v4l2_sliced_vbi_line struct is set to the start of the VBI
213b2f0648fSHans Verkuil    data that was generated by the decoder. The driver then parses the sliced
214b2f0648fSHans Verkuil    VBI data and sets the other fields in the struct accordingly. The pointer p
215b2f0648fSHans Verkuil    is updated to point to the start of the payload which can be copied
216b2f0648fSHans Verkuil    verbatim into the data field of the v4l2_sliced_vbi_data struct. If no
217b2f0648fSHans Verkuil    valid VBI data was found, then the type field is set to 0 on return. */
218b2f0648fSHans Verkuil #define VIDIOC_INT_DECODE_VBI_LINE  	_IOWR('d', 104, struct v4l2_decode_vbi_line)
219b2f0648fSHans Verkuil 
220b2f0648fSHans Verkuil /* Used to generate VBI signals on a video signal. v4l2_sliced_vbi_data is
221b2f0648fSHans Verkuil    filled with the data packets that should be output. Note that if you set
22212db5607SMauro Carvalho Chehab    the line field to 0, then that VBI signal is disabled. If no
22312db5607SMauro Carvalho Chehab    valid VBI data was found, then the type field is set to 0 on return. */
224b2f0648fSHans Verkuil #define VIDIOC_INT_S_VBI_DATA 		_IOW ('d', 105, struct v4l2_sliced_vbi_data)
225b2f0648fSHans Verkuil 
226b2f0648fSHans Verkuil /* Used to obtain the sliced VBI packet from a readback register. Not all
227b2f0648fSHans Verkuil    video decoders support this. If no data is available because the readback
228b2f0648fSHans Verkuil    register contains invalid or erroneous data -EIO is returned. Note that
229b2f0648fSHans Verkuil    you must fill in the 'id' member and the 'field' member (to determine
230b2f0648fSHans Verkuil    whether CC data from the first or second field should be obtained). */
23141f38b43SMauro Carvalho Chehab #define VIDIOC_INT_G_VBI_DATA 		_IOWR('d', 106, struct v4l2_sliced_vbi_data)
232b2f0648fSHans Verkuil 
2339bb13a6dSMauro Carvalho Chehab /* Sets I2S speed in bps. This is used to provide a standard way to select I2S
2349bb13a6dSMauro Carvalho Chehab    clock used by driving digital audio streams at some board designs.
2359bb13a6dSMauro Carvalho Chehab    Usual values for the frequency are 1024000 and 2048000.
2369bb13a6dSMauro Carvalho Chehab    If the frequency is not supported, then -EINVAL is returned. */
2379bb13a6dSMauro Carvalho Chehab #define VIDIOC_INT_I2S_CLOCK_FREQ 	_IOW ('d', 108, u32)
2389bb13a6dSMauro Carvalho Chehab 
239757d2505SHans Verkuil /* Routing definition, device dependent. It specifies which inputs (if any)
240757d2505SHans Verkuil    should be routed to which outputs (if any). */
241757d2505SHans Verkuil struct v4l2_routing {
242757d2505SHans Verkuil 	u32 input;
243757d2505SHans Verkuil 	u32 output;
244757d2505SHans Verkuil };
245757d2505SHans Verkuil 
246757d2505SHans Verkuil /* These internal commands should be used to define the inputs and outputs
2478bf2f8e7SHans Verkuil    of an audio/video chip. They will replace the v4l2 API commands
2488bf2f8e7SHans Verkuil    VIDIOC_S/G_INPUT, VIDIOC_S/G_OUTPUT, VIDIOC_S/G_AUDIO and VIDIOC_S/G_AUDOUT
2498bf2f8e7SHans Verkuil    that are meant to be used by the user.
2508bf2f8e7SHans Verkuil    The internal commands should be used to switch inputs/outputs
251757d2505SHans Verkuil    because only the driver knows how to map a 'Television' input to the precise
252757d2505SHans Verkuil    input/output routing of an A/D converter, or a DSP, or a video digitizer.
253757d2505SHans Verkuil    These four commands should only be sent directly to an i2c device, they
254757d2505SHans Verkuil    should not be broadcast as the routing is very device specific. */
255757d2505SHans Verkuil #define	VIDIOC_INT_S_AUDIO_ROUTING	_IOW ('d', 109, struct v4l2_routing)
25641f38b43SMauro Carvalho Chehab #define	VIDIOC_INT_G_AUDIO_ROUTING	_IOR ('d', 110, struct v4l2_routing)
257757d2505SHans Verkuil #define	VIDIOC_INT_S_VIDEO_ROUTING	_IOW ('d', 111, struct v4l2_routing)
25841f38b43SMauro Carvalho Chehab #define	VIDIOC_INT_G_VIDEO_ROUTING	_IOR ('d', 112, struct v4l2_routing)
259757d2505SHans Verkuil 
260b7f8292cSHans Verkuil struct v4l2_crystal_freq {
261b7f8292cSHans Verkuil 	u32 freq;	/* frequency in Hz of the crystal */
262b7f8292cSHans Verkuil 	u32 flags; 	/* device specific flags */
263b7f8292cSHans Verkuil };
264b7f8292cSHans Verkuil 
265b7f8292cSHans Verkuil /* Sets the frequency of the crystal used to generate the clocks.
266b7f8292cSHans Verkuil    An extra flags field allows device specific configuration regarding
267b7f8292cSHans Verkuil    clock frequency dividers, etc. If not used, then set flags to 0.
268b7f8292cSHans Verkuil    If the frequency is not supported, then -EINVAL is returned. */
269b7f8292cSHans Verkuil #define VIDIOC_INT_S_CRYSTAL_FREQ 	_IOW('d', 113, struct v4l2_crystal_freq)
270b7f8292cSHans Verkuil 
2719c4dfadbSJonathan Corbet /* Initialize the sensor registors to some sort of reasonable
2729c4dfadbSJonathan Corbet    default values. */
2739c4dfadbSJonathan Corbet #define VIDIOC_INT_INIT			_IOW('d', 114, u32)
2749c4dfadbSJonathan Corbet 
275045290b2SHans Verkuil /* Set v4l2_std_id for video OUTPUT devices. This is ignored by
276045290b2SHans Verkuil    video input devices. */
277045290b2SHans Verkuil #define VIDIOC_INT_S_STD_OUTPUT		_IOW('d', 115, v4l2_std_id)
278045290b2SHans Verkuil 
279045290b2SHans Verkuil /* Get v4l2_std_id for video OUTPUT devices. This is ignored by
280045290b2SHans Verkuil    video input devices. */
281045290b2SHans Verkuil #define VIDIOC_INT_G_STD_OUTPUT		_IOW('d', 116, v4l2_std_id)
2826bd6dff6SHans Verkuil 
2836bd6dff6SHans Verkuil /* Set GPIO pins. Very simple right now, might need to be extended with
2846bd6dff6SHans Verkuil    a v4l2_gpio struct if a direction is also needed. */
2856bd6dff6SHans Verkuil #define VIDIOC_INT_S_GPIO		_IOW('d', 117, u32)
286045290b2SHans Verkuil 
287b2f0648fSHans Verkuil #endif /* V4L2_COMMON_H_ */
288