Linux Audio

Check our new training course

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