xref: /openbmc/linux/include/media/v4l2-common.h (revision 9cb2318b885d2039eeb3eb5394fa215046be058f)
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 /* Prints the ioctl in a human-readable format */
657e8b09eaSHans Verkuil extern void v4l_printk_ioctl(unsigned int cmd);
667e8b09eaSHans Verkuil 
6741f38b43SMauro Carvalho Chehab /* Prints the ioctl and arg in a human-readable format */
6841f38b43SMauro Carvalho Chehab extern void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg);
6941f38b43SMauro Carvalho Chehab 
707e8b09eaSHans Verkuil /* Use this macro for non-I2C drivers. Pass the driver name as the first arg. */
717e8b09eaSHans Verkuil #define v4l_print_ioctl(name, cmd)  		 \
727e8b09eaSHans Verkuil 	do {  					 \
737e8b09eaSHans Verkuil 		printk(KERN_DEBUG "%s: ", name); \
747e8b09eaSHans Verkuil 		v4l_printk_ioctl(cmd);		 \
757e8b09eaSHans Verkuil 	} while (0)
767e8b09eaSHans Verkuil 
777e8b09eaSHans Verkuil /* Use this macro in I2C drivers where 'client' is the struct i2c_client
787e8b09eaSHans Verkuil    pointer */
797e8b09eaSHans Verkuil #define v4l_i2c_print_ioctl(client, cmd) 		   \
807e8b09eaSHans Verkuil 	do {      					   \
817e8b09eaSHans Verkuil 		v4l_client_printk(KERN_DEBUG, client, ""); \
827e8b09eaSHans Verkuil 		v4l_printk_ioctl(cmd);			   \
837e8b09eaSHans Verkuil 	} while (0)
847e8b09eaSHans Verkuil 
857e8b09eaSHans Verkuil /* ------------------------------------------------------------------------- */
867e8b09eaSHans Verkuil 
87*9cb2318bSHans Verkuil /* Control helper functions */
88*9cb2318bSHans Verkuil 
89*9cb2318bSHans Verkuil int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
90*9cb2318bSHans Verkuil 		const char **menu_items);
91*9cb2318bSHans Verkuil const char **v4l2_ctrl_get_menu(u32 id);
92*9cb2318bSHans Verkuil int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def);
93*9cb2318bSHans Verkuil int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl);
94*9cb2318bSHans Verkuil int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu,
95*9cb2318bSHans Verkuil 		struct v4l2_queryctrl *qctrl, const char **menu_items);
96*9cb2318bSHans Verkuil u32 v4l2_ctrl_next(const u32 * const *ctrl_classes, u32 id);
97*9cb2318bSHans Verkuil 
98*9cb2318bSHans Verkuil /* ------------------------------------------------------------------------- */
99*9cb2318bSHans Verkuil 
1007e8b09eaSHans Verkuil /* Internal ioctls */
1017e8b09eaSHans Verkuil 
102b2f0648fSHans Verkuil /* VIDIOC_INT_G_REGISTER and VIDIOC_INT_S_REGISTER */
103b2f0648fSHans Verkuil struct v4l2_register {
104b2f0648fSHans Verkuil 	u32 i2c_id; 		/* I2C driver ID of the I2C chip. 0 for the I2C adapter. */
105b2f0648fSHans Verkuil 	unsigned long reg;
106b2f0648fSHans Verkuil 	u32 val;
107b2f0648fSHans Verkuil };
108b2f0648fSHans Verkuil 
109b2f0648fSHans Verkuil /* VIDIOC_INT_DECODE_VBI_LINE */
110b2f0648fSHans Verkuil struct v4l2_decode_vbi_line {
111b2f0648fSHans Verkuil 	u32 is_second_field;	/* Set to 0 for the first (odd) field,
112b2f0648fSHans Verkuil 				   set to 1 for the second (even) field. */
113b2f0648fSHans Verkuil 	u8 *p; 			/* Pointer to the sliced VBI data from the decoder.
114b2f0648fSHans Verkuil 				   On exit points to the start of the payload. */
115b2f0648fSHans Verkuil 	u32 line;		/* Line number of the sliced VBI data (1-23) */
116b2f0648fSHans Verkuil 	u32 type;		/* VBI service type (V4L2_SLICED_*). 0 if no service found */
117b2f0648fSHans Verkuil };
118b2f0648fSHans Verkuil 
119b2f0648fSHans Verkuil /* VIDIOC_INT_G_CHIP_IDENT: identifies the actual chip installed on the board */
120b2f0648fSHans Verkuil enum v4l2_chip_ident {
121b2f0648fSHans Verkuil 	/* general idents: reserved range 0-49 */
122b2f0648fSHans Verkuil 	V4L2_IDENT_UNKNOWN = 0,
123b2f0648fSHans Verkuil 
124b2f0648fSHans Verkuil 	/* module saa7115: reserved range 100-149 */
125f5762e44SMauro Carvalho Chehab 	V4L2_IDENT_SAA7113 = 103,
126b2f0648fSHans Verkuil 	V4L2_IDENT_SAA7114 = 104,
127b2f0648fSHans Verkuil 	V4L2_IDENT_SAA7115 = 105,
128b2f0648fSHans Verkuil 
129b2f0648fSHans Verkuil 	/* module saa7127: reserved range 150-199 */
130b2f0648fSHans Verkuil 	V4L2_IDENT_SAA7127 = 157,
131b2f0648fSHans Verkuil 	V4L2_IDENT_SAA7129 = 159,
132b2f0648fSHans Verkuil 
133b2f0648fSHans Verkuil 	/* module cx25840: reserved range 200-249 */
134e2b8cf4cSHans Verkuil 	V4L2_IDENT_CX25836 = 236,
135e2b8cf4cSHans Verkuil 	V4L2_IDENT_CX25837 = 237,
136b2f0648fSHans Verkuil 	V4L2_IDENT_CX25840 = 240,
137b2f0648fSHans Verkuil 	V4L2_IDENT_CX25841 = 241,
138b2f0648fSHans Verkuil 	V4L2_IDENT_CX25842 = 242,
139b2f0648fSHans Verkuil 	V4L2_IDENT_CX25843 = 243,
140b2f0648fSHans Verkuil };
141b2f0648fSHans Verkuil 
1425e453dc7SMichael Krufky /* audio ioctls */
143757d2505SHans Verkuil 
144757d2505SHans Verkuil /* v4l device was opened in Radio mode, to be replaced by VIDIOC_INT_S_TUNER_MODE */
1455e453dc7SMichael Krufky #define AUDC_SET_RADIO        _IO('d',88)
146757d2505SHans Verkuil 
1475e453dc7SMichael Krufky /* tuner ioctls */
148757d2505SHans Verkuil 
1495e453dc7SMichael Krufky /* Sets tuner type and its I2C addr */
1505e453dc7SMichael Krufky #define TUNER_SET_TYPE_ADDR          _IOW('d', 90, int)
151757d2505SHans Verkuil 
152757d2505SHans Verkuil /* Puts tuner on powersaving state, disabling it, except for i2c. To be replaced
153757d2505SHans Verkuil    by VIDIOC_INT_S_STANDBY. */
1545e453dc7SMichael Krufky #define TUNER_SET_STANDBY            _IOW('d', 91, int)
155757d2505SHans Verkuil 
1565e453dc7SMichael Krufky /* Sets tda9887 specific stuff, like port1, port2 and qss */
1575e453dc7SMichael Krufky #define TDA9887_SET_CONFIG           _IOW('d', 92, int)
1585e453dc7SMichael Krufky 
159757d2505SHans Verkuil /* Switch the tuner to a specific tuner mode. Replacement of AUDC_SET_RADIO */
160757d2505SHans Verkuil #define VIDIOC_INT_S_TUNER_MODE	     _IOW('d', 93, enum v4l2_tuner_type)
161757d2505SHans Verkuil 
162757d2505SHans Verkuil /* Generic standby command. Passing -1 (all bits set to 1) will put the whole
163757d2505SHans Verkuil    chip into standby mode, value 0 will make the chip fully active. Specific
164757d2505SHans Verkuil    bits can be used by certain chips to enable/disable specific subsystems.
165757d2505SHans Verkuil    Replacement of TUNER_SET_STANDBY. */
166757d2505SHans Verkuil #define VIDIOC_INT_S_STANDBY 	     _IOW('d', 94, u32)
167757d2505SHans Verkuil 
168b2f0648fSHans Verkuil /* only implemented if CONFIG_VIDEO_ADV_DEBUG is defined */
169b2f0648fSHans Verkuil #define	VIDIOC_INT_S_REGISTER 		_IOR ('d', 100, struct v4l2_register)
170b2f0648fSHans Verkuil #define	VIDIOC_INT_G_REGISTER 		_IOWR('d', 101, struct v4l2_register)
171b2f0648fSHans Verkuil 
172b2f0648fSHans Verkuil /* Reset the I2C chip */
173b2f0648fSHans Verkuil #define VIDIOC_INT_RESET            	_IO  ('d', 102)
174b2f0648fSHans Verkuil 
1753578d3ddSHans Verkuil /* Set the frequency (in Hz) of the audio clock output.
176b2f0648fSHans Verkuil    Used to slave an audio processor to the video decoder, ensuring that audio
1773578d3ddSHans Verkuil    and video remain synchronized.
1783578d3ddSHans Verkuil    Usual values for the frequency are 48000, 44100 or 32000 Hz.
1793578d3ddSHans Verkuil    If the frequency is not supported, then -EINVAL is returned. */
1803578d3ddSHans Verkuil #define VIDIOC_INT_AUDIO_CLOCK_FREQ 	_IOW ('d', 103, u32)
181b2f0648fSHans Verkuil 
182b2f0648fSHans Verkuil /* Video decoders that support sliced VBI need to implement this ioctl.
183b2f0648fSHans Verkuil    Field p of the v4l2_sliced_vbi_line struct is set to the start of the VBI
184b2f0648fSHans Verkuil    data that was generated by the decoder. The driver then parses the sliced
185b2f0648fSHans Verkuil    VBI data and sets the other fields in the struct accordingly. The pointer p
186b2f0648fSHans Verkuil    is updated to point to the start of the payload which can be copied
187b2f0648fSHans Verkuil    verbatim into the data field of the v4l2_sliced_vbi_data struct. If no
188b2f0648fSHans Verkuil    valid VBI data was found, then the type field is set to 0 on return. */
189b2f0648fSHans Verkuil #define VIDIOC_INT_DECODE_VBI_LINE  	_IOWR('d', 104, struct v4l2_decode_vbi_line)
190b2f0648fSHans Verkuil 
191b2f0648fSHans Verkuil /* Used to generate VBI signals on a video signal. v4l2_sliced_vbi_data is
192b2f0648fSHans Verkuil    filled with the data packets that should be output. Note that if you set
19312db5607SMauro Carvalho Chehab    the line field to 0, then that VBI signal is disabled. If no
19412db5607SMauro Carvalho Chehab    valid VBI data was found, then the type field is set to 0 on return. */
195b2f0648fSHans Verkuil #define VIDIOC_INT_S_VBI_DATA 		_IOW ('d', 105, struct v4l2_sliced_vbi_data)
196b2f0648fSHans Verkuil 
197b2f0648fSHans Verkuil /* Used to obtain the sliced VBI packet from a readback register. Not all
198b2f0648fSHans Verkuil    video decoders support this. If no data is available because the readback
199b2f0648fSHans Verkuil    register contains invalid or erroneous data -EIO is returned. Note that
200b2f0648fSHans Verkuil    you must fill in the 'id' member and the 'field' member (to determine
201b2f0648fSHans Verkuil    whether CC data from the first or second field should be obtained). */
20241f38b43SMauro Carvalho Chehab #define VIDIOC_INT_G_VBI_DATA 		_IOWR('d', 106, struct v4l2_sliced_vbi_data)
203b2f0648fSHans Verkuil 
204b2f0648fSHans Verkuil /* Returns the chip identifier or V4L2_IDENT_UNKNOWN if no identification can
205b2f0648fSHans Verkuil    be made. */
20641f38b43SMauro Carvalho Chehab #define VIDIOC_INT_G_CHIP_IDENT		_IOR ('d', 107, enum v4l2_chip_ident)
207b2f0648fSHans Verkuil 
2089bb13a6dSMauro Carvalho Chehab /* Sets I2S speed in bps. This is used to provide a standard way to select I2S
2099bb13a6dSMauro Carvalho Chehab    clock used by driving digital audio streams at some board designs.
2109bb13a6dSMauro Carvalho Chehab    Usual values for the frequency are 1024000 and 2048000.
2119bb13a6dSMauro Carvalho Chehab    If the frequency is not supported, then -EINVAL is returned. */
2129bb13a6dSMauro Carvalho Chehab #define VIDIOC_INT_I2S_CLOCK_FREQ 	_IOW ('d', 108, u32)
2139bb13a6dSMauro Carvalho Chehab 
214757d2505SHans Verkuil /* Routing definition, device dependent. It specifies which inputs (if any)
215757d2505SHans Verkuil    should be routed to which outputs (if any). */
216757d2505SHans Verkuil struct v4l2_routing {
217757d2505SHans Verkuil 	u32 input;
218757d2505SHans Verkuil 	u32 output;
219757d2505SHans Verkuil };
220757d2505SHans Verkuil 
221757d2505SHans Verkuil /* These internal commands should be used to define the inputs and outputs
2228bf2f8e7SHans Verkuil    of an audio/video chip. They will replace the v4l2 API commands
2238bf2f8e7SHans Verkuil    VIDIOC_S/G_INPUT, VIDIOC_S/G_OUTPUT, VIDIOC_S/G_AUDIO and VIDIOC_S/G_AUDOUT
2248bf2f8e7SHans Verkuil    that are meant to be used by the user.
2258bf2f8e7SHans Verkuil    The internal commands should be used to switch inputs/outputs
226757d2505SHans Verkuil    because only the driver knows how to map a 'Television' input to the precise
227757d2505SHans Verkuil    input/output routing of an A/D converter, or a DSP, or a video digitizer.
228757d2505SHans Verkuil    These four commands should only be sent directly to an i2c device, they
229757d2505SHans Verkuil    should not be broadcast as the routing is very device specific. */
230757d2505SHans Verkuil #define	VIDIOC_INT_S_AUDIO_ROUTING	_IOW ('d', 109, struct v4l2_routing)
23141f38b43SMauro Carvalho Chehab #define	VIDIOC_INT_G_AUDIO_ROUTING	_IOR ('d', 110, struct v4l2_routing)
232757d2505SHans Verkuil #define	VIDIOC_INT_S_VIDEO_ROUTING	_IOW ('d', 111, struct v4l2_routing)
23341f38b43SMauro Carvalho Chehab #define	VIDIOC_INT_G_VIDEO_ROUTING	_IOR ('d', 112, struct v4l2_routing)
234757d2505SHans Verkuil 
235b7f8292cSHans Verkuil struct v4l2_crystal_freq {
236b7f8292cSHans Verkuil 	u32 freq;	/* frequency in Hz of the crystal */
237b7f8292cSHans Verkuil 	u32 flags; 	/* device specific flags */
238b7f8292cSHans Verkuil };
239b7f8292cSHans Verkuil 
240b7f8292cSHans Verkuil /* Sets the frequency of the crystal used to generate the clocks.
241b7f8292cSHans Verkuil    An extra flags field allows device specific configuration regarding
242b7f8292cSHans Verkuil    clock frequency dividers, etc. If not used, then set flags to 0.
243b7f8292cSHans Verkuil    If the frequency is not supported, then -EINVAL is returned. */
244b7f8292cSHans Verkuil #define VIDIOC_INT_S_CRYSTAL_FREQ 	_IOW ('d', 113, struct v4l2_crystal_freq)
245b7f8292cSHans Verkuil 
246b2f0648fSHans Verkuil #endif /* V4L2_COMMON_H_ */
247