18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci    v4l2 common internal API header
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci    This header contains internal shared ioctl definitions for use by the
68c2ecf20Sopenharmony_ci    internal low-level v4l2 drivers.
78c2ecf20Sopenharmony_ci    Each ioctl begins with VIDIOC_INT_ to clearly mark that it is an internal
88c2ecf20Sopenharmony_ci    define,
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci    Copyright (C) 2005  Hans Verkuil <hverkuil@xs4all.nl>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef V4L2_COMMON_H_
158c2ecf20Sopenharmony_ci#define V4L2_COMMON_H_
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <linux/time.h>
188c2ecf20Sopenharmony_ci#include <media/v4l2-dev.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* Common printk constructs for v4l-i2c drivers. These macros create a unique
218c2ecf20Sopenharmony_ci   prefix consisting of the driver name, the adapter number and the i2c
228c2ecf20Sopenharmony_ci   address. */
238c2ecf20Sopenharmony_ci#define v4l_printk(level, name, adapter, addr, fmt, arg...) \
248c2ecf20Sopenharmony_ci	printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define v4l_client_printk(level, client, fmt, arg...)			    \
278c2ecf20Sopenharmony_ci	v4l_printk(level, (client)->dev.driver->name, (client)->adapter, \
288c2ecf20Sopenharmony_ci		   (client)->addr, fmt , ## arg)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define v4l_err(client, fmt, arg...) \
318c2ecf20Sopenharmony_ci	v4l_client_printk(KERN_ERR, client, fmt , ## arg)
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define v4l_warn(client, fmt, arg...) \
348c2ecf20Sopenharmony_ci	v4l_client_printk(KERN_WARNING, client, fmt , ## arg)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define v4l_info(client, fmt, arg...) \
378c2ecf20Sopenharmony_ci	v4l_client_printk(KERN_INFO, client, fmt , ## arg)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* These three macros assume that the debug level is set with a module
408c2ecf20Sopenharmony_ci   parameter called 'debug'. */
418c2ecf20Sopenharmony_ci#define v4l_dbg(level, debug, client, fmt, arg...)			     \
428c2ecf20Sopenharmony_ci	do {								     \
438c2ecf20Sopenharmony_ci		if (debug >= (level))					     \
448c2ecf20Sopenharmony_ci			v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \
458c2ecf20Sopenharmony_ci	} while (0)
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/* Add a version of v4l_dbg to be used on drivers using dev_foo() macros */
488c2ecf20Sopenharmony_ci#define dev_dbg_lvl(__dev, __level, __debug, __fmt, __arg...)		\
498c2ecf20Sopenharmony_ci	do {								\
508c2ecf20Sopenharmony_ci		if (__debug >= (__level))				\
518c2ecf20Sopenharmony_ci			dev_printk(KERN_DEBUG, __dev, __fmt, ##__arg);	\
528c2ecf20Sopenharmony_ci	} while (0)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* These printk constructs can be used with v4l2_device and v4l2_subdev */
578c2ecf20Sopenharmony_ci#define v4l2_printk(level, dev, fmt, arg...) \
588c2ecf20Sopenharmony_ci	printk(level "%s: " fmt, (dev)->name , ## arg)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define v4l2_err(dev, fmt, arg...) \
618c2ecf20Sopenharmony_ci	v4l2_printk(KERN_ERR, dev, fmt , ## arg)
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define v4l2_warn(dev, fmt, arg...) \
648c2ecf20Sopenharmony_ci	v4l2_printk(KERN_WARNING, dev, fmt , ## arg)
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define v4l2_info(dev, fmt, arg...) \
678c2ecf20Sopenharmony_ci	v4l2_printk(KERN_INFO, dev, fmt , ## arg)
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* These three macros assume that the debug level is set with a module
708c2ecf20Sopenharmony_ci   parameter called 'debug'. */
718c2ecf20Sopenharmony_ci#define v4l2_dbg(level, debug, dev, fmt, arg...)			\
728c2ecf20Sopenharmony_ci	do {								\
738c2ecf20Sopenharmony_ci		if (debug >= (level))					\
748c2ecf20Sopenharmony_ci			v4l2_printk(KERN_DEBUG, dev, fmt , ## arg);	\
758c2ecf20Sopenharmony_ci	} while (0)
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/**
788c2ecf20Sopenharmony_ci * v4l2_ctrl_query_fill- Fill in a struct v4l2_queryctrl
798c2ecf20Sopenharmony_ci *
808c2ecf20Sopenharmony_ci * @qctrl: pointer to the &struct v4l2_queryctrl to be filled
818c2ecf20Sopenharmony_ci * @min: minimum value for the control
828c2ecf20Sopenharmony_ci * @max: maximum value for the control
838c2ecf20Sopenharmony_ci * @step: control step
848c2ecf20Sopenharmony_ci * @def: default value for the control
858c2ecf20Sopenharmony_ci *
868c2ecf20Sopenharmony_ci * Fills the &struct v4l2_queryctrl fields for the query control.
878c2ecf20Sopenharmony_ci *
888c2ecf20Sopenharmony_ci * .. note::
898c2ecf20Sopenharmony_ci *
908c2ecf20Sopenharmony_ci *    This function assumes that the @qctrl->id field is filled.
918c2ecf20Sopenharmony_ci *
928c2ecf20Sopenharmony_ci * Returns -EINVAL if the control is not known by the V4L2 core, 0 on success.
938c2ecf20Sopenharmony_ci */
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciint v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
968c2ecf20Sopenharmony_ci			 s32 min, s32 max, s32 step, s32 def);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistruct v4l2_device;
1018c2ecf20Sopenharmony_cistruct v4l2_subdev;
1028c2ecf20Sopenharmony_cistruct v4l2_subdev_ops;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/* I2C Helper functions */
1058c2ecf20Sopenharmony_ci#include <linux/i2c.h>
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/**
1088c2ecf20Sopenharmony_ci * enum v4l2_i2c_tuner_type - specifies the range of tuner address that
1098c2ecf20Sopenharmony_ci *	should be used when seeking for I2C devices.
1108c2ecf20Sopenharmony_ci *
1118c2ecf20Sopenharmony_ci * @ADDRS_RADIO:		Radio tuner addresses.
1128c2ecf20Sopenharmony_ci *				Represent the following I2C addresses:
1138c2ecf20Sopenharmony_ci *				0x10 (if compiled with tea5761 support)
1148c2ecf20Sopenharmony_ci *				and 0x60.
1158c2ecf20Sopenharmony_ci * @ADDRS_DEMOD:		Demod tuner addresses.
1168c2ecf20Sopenharmony_ci *				Represent the following I2C addresses:
1178c2ecf20Sopenharmony_ci *				0x42, 0x43, 0x4a and 0x4b.
1188c2ecf20Sopenharmony_ci * @ADDRS_TV:			TV tuner addresses.
1198c2ecf20Sopenharmony_ci *				Represent the following I2C addresses:
1208c2ecf20Sopenharmony_ci *				0x42, 0x43, 0x4a, 0x4b, 0x60, 0x61, 0x62,
1218c2ecf20Sopenharmony_ci *				0x63 and 0x64.
1228c2ecf20Sopenharmony_ci * @ADDRS_TV_WITH_DEMOD:	TV tuner addresses if demod is present, this
1238c2ecf20Sopenharmony_ci *				excludes addresses used by the demodulator
1248c2ecf20Sopenharmony_ci *				from the list of candidates.
1258c2ecf20Sopenharmony_ci *				Represent the following I2C addresses:
1268c2ecf20Sopenharmony_ci *				0x60, 0x61, 0x62, 0x63 and 0x64.
1278c2ecf20Sopenharmony_ci *
1288c2ecf20Sopenharmony_ci * NOTE: All I2C addresses above use the 7-bit notation.
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_cienum v4l2_i2c_tuner_type {
1318c2ecf20Sopenharmony_ci	ADDRS_RADIO,
1328c2ecf20Sopenharmony_ci	ADDRS_DEMOD,
1338c2ecf20Sopenharmony_ci	ADDRS_TV,
1348c2ecf20Sopenharmony_ci	ADDRS_TV_WITH_DEMOD,
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci#if defined(CONFIG_VIDEO_V4L2_I2C)
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/**
1408c2ecf20Sopenharmony_ci * v4l2_i2c_new_subdev - Load an i2c module and return an initialized
1418c2ecf20Sopenharmony_ci *	&struct v4l2_subdev.
1428c2ecf20Sopenharmony_ci *
1438c2ecf20Sopenharmony_ci * @v4l2_dev: pointer to &struct v4l2_device
1448c2ecf20Sopenharmony_ci * @adapter: pointer to struct i2c_adapter
1458c2ecf20Sopenharmony_ci * @client_type:  name of the chip that's on the adapter.
1468c2ecf20Sopenharmony_ci * @addr: I2C address. If zero, it will use @probe_addrs
1478c2ecf20Sopenharmony_ci * @probe_addrs: array with a list of address. The last entry at such
1488c2ecf20Sopenharmony_ci *	array should be %I2C_CLIENT_END.
1498c2ecf20Sopenharmony_ci *
1508c2ecf20Sopenharmony_ci * returns a &struct v4l2_subdev pointer.
1518c2ecf20Sopenharmony_ci */
1528c2ecf20Sopenharmony_cistruct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
1538c2ecf20Sopenharmony_ci		struct i2c_adapter *adapter, const char *client_type,
1548c2ecf20Sopenharmony_ci		u8 addr, const unsigned short *probe_addrs);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/**
1578c2ecf20Sopenharmony_ci * v4l2_i2c_new_subdev_board - Load an i2c module and return an initialized
1588c2ecf20Sopenharmony_ci *	&struct v4l2_subdev.
1598c2ecf20Sopenharmony_ci *
1608c2ecf20Sopenharmony_ci * @v4l2_dev: pointer to &struct v4l2_device
1618c2ecf20Sopenharmony_ci * @adapter: pointer to struct i2c_adapter
1628c2ecf20Sopenharmony_ci * @info: pointer to struct i2c_board_info used to replace the irq,
1638c2ecf20Sopenharmony_ci *	 platform_data and addr arguments.
1648c2ecf20Sopenharmony_ci * @probe_addrs: array with a list of address. The last entry at such
1658c2ecf20Sopenharmony_ci *	array should be %I2C_CLIENT_END.
1668c2ecf20Sopenharmony_ci *
1678c2ecf20Sopenharmony_ci * returns a &struct v4l2_subdev pointer.
1688c2ecf20Sopenharmony_ci */
1698c2ecf20Sopenharmony_cistruct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
1708c2ecf20Sopenharmony_ci		struct i2c_adapter *adapter, struct i2c_board_info *info,
1718c2ecf20Sopenharmony_ci		const unsigned short *probe_addrs);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci/**
1748c2ecf20Sopenharmony_ci * v4l2_i2c_subdev_set_name - Set name for an I²C sub-device
1758c2ecf20Sopenharmony_ci *
1768c2ecf20Sopenharmony_ci * @sd: pointer to &struct v4l2_subdev
1778c2ecf20Sopenharmony_ci * @client: pointer to struct i2c_client
1788c2ecf20Sopenharmony_ci * @devname: the name of the device; if NULL, the I²C device drivers's name
1798c2ecf20Sopenharmony_ci *           will be used
1808c2ecf20Sopenharmony_ci * @postfix: sub-device specific string to put right after the I²C device name;
1818c2ecf20Sopenharmony_ci *	     may be NULL
1828c2ecf20Sopenharmony_ci */
1838c2ecf20Sopenharmony_civoid v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client,
1848c2ecf20Sopenharmony_ci			      const char *devname, const char *postfix);
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci/**
1878c2ecf20Sopenharmony_ci * v4l2_i2c_subdev_init - Initializes a &struct v4l2_subdev with data from
1888c2ecf20Sopenharmony_ci *	an i2c_client struct.
1898c2ecf20Sopenharmony_ci *
1908c2ecf20Sopenharmony_ci * @sd: pointer to &struct v4l2_subdev
1918c2ecf20Sopenharmony_ci * @client: pointer to struct i2c_client
1928c2ecf20Sopenharmony_ci * @ops: pointer to &struct v4l2_subdev_ops
1938c2ecf20Sopenharmony_ci */
1948c2ecf20Sopenharmony_civoid v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
1958c2ecf20Sopenharmony_ci		const struct v4l2_subdev_ops *ops);
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci/**
1988c2ecf20Sopenharmony_ci * v4l2_i2c_subdev_addr - returns i2c client address of &struct v4l2_subdev.
1998c2ecf20Sopenharmony_ci *
2008c2ecf20Sopenharmony_ci * @sd: pointer to &struct v4l2_subdev
2018c2ecf20Sopenharmony_ci *
2028c2ecf20Sopenharmony_ci * Returns the address of an I2C sub-device
2038c2ecf20Sopenharmony_ci */
2048c2ecf20Sopenharmony_ciunsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd);
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci/**
2078c2ecf20Sopenharmony_ci * v4l2_i2c_tuner_addrs - Return a list of I2C tuner addresses to probe.
2088c2ecf20Sopenharmony_ci *
2098c2ecf20Sopenharmony_ci * @type: type of the tuner to seek, as defined by
2108c2ecf20Sopenharmony_ci *	  &enum v4l2_i2c_tuner_type.
2118c2ecf20Sopenharmony_ci *
2128c2ecf20Sopenharmony_ci * NOTE: Use only if the tuner addresses are unknown.
2138c2ecf20Sopenharmony_ci */
2148c2ecf20Sopenharmony_ciconst unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type);
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci/**
2178c2ecf20Sopenharmony_ci * v4l2_i2c_subdev_unregister - Unregister a v4l2_subdev
2188c2ecf20Sopenharmony_ci *
2198c2ecf20Sopenharmony_ci * @sd: pointer to &struct v4l2_subdev
2208c2ecf20Sopenharmony_ci */
2218c2ecf20Sopenharmony_civoid v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd);
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci#else
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistatic inline struct v4l2_subdev *
2268c2ecf20Sopenharmony_civ4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
2278c2ecf20Sopenharmony_ci		    struct i2c_adapter *adapter, const char *client_type,
2288c2ecf20Sopenharmony_ci		    u8 addr, const unsigned short *probe_addrs)
2298c2ecf20Sopenharmony_ci{
2308c2ecf20Sopenharmony_ci	return NULL;
2318c2ecf20Sopenharmony_ci}
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_cistatic inline struct v4l2_subdev *
2348c2ecf20Sopenharmony_civ4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
2358c2ecf20Sopenharmony_ci			  struct i2c_adapter *adapter, struct i2c_board_info *info,
2368c2ecf20Sopenharmony_ci			  const unsigned short *probe_addrs)
2378c2ecf20Sopenharmony_ci{
2388c2ecf20Sopenharmony_ci	return NULL;
2398c2ecf20Sopenharmony_ci}
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistatic inline void
2428c2ecf20Sopenharmony_civ4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client,
2438c2ecf20Sopenharmony_ci			 const char *devname, const char *postfix)
2448c2ecf20Sopenharmony_ci{}
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_cistatic inline void
2478c2ecf20Sopenharmony_civ4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
2488c2ecf20Sopenharmony_ci		     const struct v4l2_subdev_ops *ops)
2498c2ecf20Sopenharmony_ci{}
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_cistatic inline unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd)
2528c2ecf20Sopenharmony_ci{
2538c2ecf20Sopenharmony_ci	return I2C_CLIENT_END;
2548c2ecf20Sopenharmony_ci}
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_cistatic inline const unsigned short *
2578c2ecf20Sopenharmony_civ4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)
2588c2ecf20Sopenharmony_ci{
2598c2ecf20Sopenharmony_ci	return NULL;
2608c2ecf20Sopenharmony_ci}
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_cistatic inline void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd)
2638c2ecf20Sopenharmony_ci{}
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci#endif
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci/* SPI Helper functions */
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci#include <linux/spi/spi.h>
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci#if defined(CONFIG_SPI)
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci/**
2768c2ecf20Sopenharmony_ci *  v4l2_spi_new_subdev - Load an spi module and return an initialized
2778c2ecf20Sopenharmony_ci *	&struct v4l2_subdev.
2788c2ecf20Sopenharmony_ci *
2798c2ecf20Sopenharmony_ci *
2808c2ecf20Sopenharmony_ci * @v4l2_dev: pointer to &struct v4l2_device.
2818c2ecf20Sopenharmony_ci * @master: pointer to struct spi_master.
2828c2ecf20Sopenharmony_ci * @info: pointer to struct spi_board_info.
2838c2ecf20Sopenharmony_ci *
2848c2ecf20Sopenharmony_ci * returns a &struct v4l2_subdev pointer.
2858c2ecf20Sopenharmony_ci */
2868c2ecf20Sopenharmony_cistruct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
2878c2ecf20Sopenharmony_ci		struct spi_master *master, struct spi_board_info *info);
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci/**
2908c2ecf20Sopenharmony_ci * v4l2_spi_subdev_init - Initialize a v4l2_subdev with data from an
2918c2ecf20Sopenharmony_ci *	spi_device struct.
2928c2ecf20Sopenharmony_ci *
2938c2ecf20Sopenharmony_ci * @sd: pointer to &struct v4l2_subdev
2948c2ecf20Sopenharmony_ci * @spi: pointer to struct spi_device.
2958c2ecf20Sopenharmony_ci * @ops: pointer to &struct v4l2_subdev_ops
2968c2ecf20Sopenharmony_ci */
2978c2ecf20Sopenharmony_civoid v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
2988c2ecf20Sopenharmony_ci		const struct v4l2_subdev_ops *ops);
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci/**
3018c2ecf20Sopenharmony_ci * v4l2_spi_subdev_unregister - Unregister a v4l2_subdev
3028c2ecf20Sopenharmony_ci *
3038c2ecf20Sopenharmony_ci * @sd: pointer to &struct v4l2_subdev
3048c2ecf20Sopenharmony_ci */
3058c2ecf20Sopenharmony_civoid v4l2_spi_subdev_unregister(struct v4l2_subdev *sd);
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci#else
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_cistatic inline struct v4l2_subdev *
3108c2ecf20Sopenharmony_civ4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
3118c2ecf20Sopenharmony_ci		    struct spi_master *master, struct spi_board_info *info)
3128c2ecf20Sopenharmony_ci{
3138c2ecf20Sopenharmony_ci	return NULL;
3148c2ecf20Sopenharmony_ci}
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_cistatic inline void
3178c2ecf20Sopenharmony_civ4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
3188c2ecf20Sopenharmony_ci		     const struct v4l2_subdev_ops *ops)
3198c2ecf20Sopenharmony_ci{}
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_cistatic inline void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd)
3228c2ecf20Sopenharmony_ci{}
3238c2ecf20Sopenharmony_ci#endif
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci/*
3288c2ecf20Sopenharmony_ci * FIXME: these remaining ioctls/structs should be removed as well, but they
3298c2ecf20Sopenharmony_ci * are still used in tuner-simple.c (TUNER_SET_CONFIG) and cx18/ivtv (RESET).
3308c2ecf20Sopenharmony_ci * To remove these ioctls some more cleanup is needed in those modules.
3318c2ecf20Sopenharmony_ci *
3328c2ecf20Sopenharmony_ci * It doesn't make much sense on documenting them, as what we really want is
3338c2ecf20Sopenharmony_ci * to get rid of them.
3348c2ecf20Sopenharmony_ci */
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci/* s_config */
3378c2ecf20Sopenharmony_cistruct v4l2_priv_tun_config {
3388c2ecf20Sopenharmony_ci	int tuner;
3398c2ecf20Sopenharmony_ci	void *priv;
3408c2ecf20Sopenharmony_ci};
3418c2ecf20Sopenharmony_ci#define TUNER_SET_CONFIG           _IOW('d', 92, struct v4l2_priv_tun_config)
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci#define VIDIOC_INT_RESET		_IOW ('d', 102, u32)
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci/* Miscellaneous helper functions */
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci/**
3508c2ecf20Sopenharmony_ci * v4l_bound_align_image - adjust video dimensions according to
3518c2ecf20Sopenharmony_ci *	a given constraints.
3528c2ecf20Sopenharmony_ci *
3538c2ecf20Sopenharmony_ci * @width:	pointer to width that will be adjusted if needed.
3548c2ecf20Sopenharmony_ci * @wmin:	minimum width.
3558c2ecf20Sopenharmony_ci * @wmax:	maximum width.
3568c2ecf20Sopenharmony_ci * @walign:	least significant bit on width.
3578c2ecf20Sopenharmony_ci * @height:	pointer to height that will be adjusted if needed.
3588c2ecf20Sopenharmony_ci * @hmin:	minimum height.
3598c2ecf20Sopenharmony_ci * @hmax:	maximum height.
3608c2ecf20Sopenharmony_ci * @halign:	least significant bit on height.
3618c2ecf20Sopenharmony_ci * @salign:	least significant bit for the image size (e. g.
3628c2ecf20Sopenharmony_ci *		:math:`width * height`).
3638c2ecf20Sopenharmony_ci *
3648c2ecf20Sopenharmony_ci * Clip an image to have @width between @wmin and @wmax, and @height between
3658c2ecf20Sopenharmony_ci * @hmin and @hmax, inclusive.
3668c2ecf20Sopenharmony_ci *
3678c2ecf20Sopenharmony_ci * Additionally, the @width will be a multiple of :math:`2^{walign}`,
3688c2ecf20Sopenharmony_ci * the @height will be a multiple of :math:`2^{halign}`, and the overall
3698c2ecf20Sopenharmony_ci * size :math:`width * height` will be a multiple of :math:`2^{salign}`.
3708c2ecf20Sopenharmony_ci *
3718c2ecf20Sopenharmony_ci * .. note::
3728c2ecf20Sopenharmony_ci *
3738c2ecf20Sopenharmony_ci *    #. The clipping rectangle may be shrunk or enlarged to fit the alignment
3748c2ecf20Sopenharmony_ci *       constraints.
3758c2ecf20Sopenharmony_ci *    #. @wmax must not be smaller than @wmin.
3768c2ecf20Sopenharmony_ci *    #. @hmax must not be smaller than @hmin.
3778c2ecf20Sopenharmony_ci *    #. The alignments must not be so high there are no possible image
3788c2ecf20Sopenharmony_ci *       sizes within the allowed bounds.
3798c2ecf20Sopenharmony_ci *    #. @wmin and @hmin must be at least 1 (don't use 0).
3808c2ecf20Sopenharmony_ci *    #. For @walign, @halign and @salign, if you don't care about a certain
3818c2ecf20Sopenharmony_ci *       alignment, specify ``0``, as :math:`2^0 = 1` and one byte alignment
3828c2ecf20Sopenharmony_ci *       is equivalent to no alignment.
3838c2ecf20Sopenharmony_ci *    #. If you only want to adjust downward, specify a maximum that's the
3848c2ecf20Sopenharmony_ci *       same as the initial value.
3858c2ecf20Sopenharmony_ci */
3868c2ecf20Sopenharmony_civoid v4l_bound_align_image(unsigned int *width, unsigned int wmin,
3878c2ecf20Sopenharmony_ci			   unsigned int wmax, unsigned int walign,
3888c2ecf20Sopenharmony_ci			   unsigned int *height, unsigned int hmin,
3898c2ecf20Sopenharmony_ci			   unsigned int hmax, unsigned int halign,
3908c2ecf20Sopenharmony_ci			   unsigned int salign);
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci/**
3938c2ecf20Sopenharmony_ci * v4l2_find_nearest_size - Find the nearest size among a discrete
3948c2ecf20Sopenharmony_ci *	set of resolutions contained in an array of a driver specific struct.
3958c2ecf20Sopenharmony_ci *
3968c2ecf20Sopenharmony_ci * @array: a driver specific array of image sizes
3978c2ecf20Sopenharmony_ci * @array_size: the length of the driver specific array of image sizes
3988c2ecf20Sopenharmony_ci * @width_field: the name of the width field in the driver specific struct
3998c2ecf20Sopenharmony_ci * @height_field: the name of the height field in the driver specific struct
4008c2ecf20Sopenharmony_ci * @width: desired width.
4018c2ecf20Sopenharmony_ci * @height: desired height.
4028c2ecf20Sopenharmony_ci *
4038c2ecf20Sopenharmony_ci * Finds the closest resolution to minimize the width and height differences
4048c2ecf20Sopenharmony_ci * between what requested and the supported resolutions. The size of the width
4058c2ecf20Sopenharmony_ci * and height fields in the driver specific must equal to that of u32, i.e. four
4068c2ecf20Sopenharmony_ci * bytes.
4078c2ecf20Sopenharmony_ci *
4088c2ecf20Sopenharmony_ci * Returns the best match or NULL if the length of the array is zero.
4098c2ecf20Sopenharmony_ci */
4108c2ecf20Sopenharmony_ci#define v4l2_find_nearest_size(array, array_size, width_field, height_field, \
4118c2ecf20Sopenharmony_ci			       width, height)				\
4128c2ecf20Sopenharmony_ci	({								\
4138c2ecf20Sopenharmony_ci		BUILD_BUG_ON(sizeof((array)->width_field) != sizeof(u32) || \
4148c2ecf20Sopenharmony_ci			     sizeof((array)->height_field) != sizeof(u32)); \
4158c2ecf20Sopenharmony_ci		(typeof(&(array)[0]))__v4l2_find_nearest_size(		\
4168c2ecf20Sopenharmony_ci			(array), array_size, sizeof(*(array)),		\
4178c2ecf20Sopenharmony_ci			offsetof(typeof(*(array)), width_field),	\
4188c2ecf20Sopenharmony_ci			offsetof(typeof(*(array)), height_field),	\
4198c2ecf20Sopenharmony_ci			width, height);					\
4208c2ecf20Sopenharmony_ci	})
4218c2ecf20Sopenharmony_ciconst void *
4228c2ecf20Sopenharmony_ci__v4l2_find_nearest_size(const void *array, size_t array_size,
4238c2ecf20Sopenharmony_ci			 size_t entry_size, size_t width_offset,
4248c2ecf20Sopenharmony_ci			 size_t height_offset, s32 width, s32 height);
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci/**
4278c2ecf20Sopenharmony_ci * v4l2_g_parm_cap - helper routine for vidioc_g_parm to fill this in by
4288c2ecf20Sopenharmony_ci *      calling the g_frame_interval op of the given subdev. It only works
4298c2ecf20Sopenharmony_ci *      for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the
4308c2ecf20Sopenharmony_ci *      function name.
4318c2ecf20Sopenharmony_ci *
4328c2ecf20Sopenharmony_ci * @vdev: the struct video_device pointer. Used to determine the device caps.
4338c2ecf20Sopenharmony_ci * @sd: the sub-device pointer.
4348c2ecf20Sopenharmony_ci * @a: the VIDIOC_G_PARM argument.
4358c2ecf20Sopenharmony_ci */
4368c2ecf20Sopenharmony_ciint v4l2_g_parm_cap(struct video_device *vdev,
4378c2ecf20Sopenharmony_ci		    struct v4l2_subdev *sd, struct v4l2_streamparm *a);
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci/**
4408c2ecf20Sopenharmony_ci * v4l2_s_parm_cap - helper routine for vidioc_s_parm to fill this in by
4418c2ecf20Sopenharmony_ci *      calling the s_frame_interval op of the given subdev. It only works
4428c2ecf20Sopenharmony_ci *      for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the
4438c2ecf20Sopenharmony_ci *      function name.
4448c2ecf20Sopenharmony_ci *
4458c2ecf20Sopenharmony_ci * @vdev: the struct video_device pointer. Used to determine the device caps.
4468c2ecf20Sopenharmony_ci * @sd: the sub-device pointer.
4478c2ecf20Sopenharmony_ci * @a: the VIDIOC_S_PARM argument.
4488c2ecf20Sopenharmony_ci */
4498c2ecf20Sopenharmony_ciint v4l2_s_parm_cap(struct video_device *vdev,
4508c2ecf20Sopenharmony_ci		    struct v4l2_subdev *sd, struct v4l2_streamparm *a);
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci/* Compare two v4l2_fract structs */
4538c2ecf20Sopenharmony_ci#define V4L2_FRACT_COMPARE(a, OP, b)			\
4548c2ecf20Sopenharmony_ci	((u64)(a).numerator * (b).denominator OP	\
4558c2ecf20Sopenharmony_ci	(u64)(b).numerator * (a).denominator)
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci/* Pixel format and FourCC helpers */
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci/**
4628c2ecf20Sopenharmony_ci * enum v4l2_pixel_encoding - specifies the pixel encoding value
4638c2ecf20Sopenharmony_ci *
4648c2ecf20Sopenharmony_ci * @V4L2_PIXEL_ENC_UNKNOWN:	Pixel encoding is unknown/un-initialized
4658c2ecf20Sopenharmony_ci * @V4L2_PIXEL_ENC_YUV:		Pixel encoding is YUV
4668c2ecf20Sopenharmony_ci * @V4L2_PIXEL_ENC_RGB:		Pixel encoding is RGB
4678c2ecf20Sopenharmony_ci * @V4L2_PIXEL_ENC_BAYER:	Pixel encoding is Bayer
4688c2ecf20Sopenharmony_ci */
4698c2ecf20Sopenharmony_cienum v4l2_pixel_encoding {
4708c2ecf20Sopenharmony_ci	V4L2_PIXEL_ENC_UNKNOWN = 0,
4718c2ecf20Sopenharmony_ci	V4L2_PIXEL_ENC_YUV = 1,
4728c2ecf20Sopenharmony_ci	V4L2_PIXEL_ENC_RGB = 2,
4738c2ecf20Sopenharmony_ci	V4L2_PIXEL_ENC_BAYER = 3,
4748c2ecf20Sopenharmony_ci};
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci/**
4778c2ecf20Sopenharmony_ci * struct v4l2_format_info - information about a V4L2 format
4788c2ecf20Sopenharmony_ci * @format: 4CC format identifier (V4L2_PIX_FMT_*)
4798c2ecf20Sopenharmony_ci * @pixel_enc: Pixel encoding (see enum v4l2_pixel_encoding above)
4808c2ecf20Sopenharmony_ci * @mem_planes: Number of memory planes, which includes the alpha plane (1 to 4).
4818c2ecf20Sopenharmony_ci * @comp_planes: Number of component planes, which includes the alpha plane (1 to 4).
4828c2ecf20Sopenharmony_ci * @bpp: Array of per-plane bytes per pixel
4838c2ecf20Sopenharmony_ci * @hdiv: Horizontal chroma subsampling factor
4848c2ecf20Sopenharmony_ci * @vdiv: Vertical chroma subsampling factor
4858c2ecf20Sopenharmony_ci * @block_w: Per-plane macroblock pixel width (optional)
4868c2ecf20Sopenharmony_ci * @block_h: Per-plane macroblock pixel height (optional)
4878c2ecf20Sopenharmony_ci */
4888c2ecf20Sopenharmony_cistruct v4l2_format_info {
4898c2ecf20Sopenharmony_ci	u32 format;
4908c2ecf20Sopenharmony_ci	u8 pixel_enc;
4918c2ecf20Sopenharmony_ci	u8 mem_planes;
4928c2ecf20Sopenharmony_ci	u8 comp_planes;
4938c2ecf20Sopenharmony_ci	u8 bpp[4];
4948c2ecf20Sopenharmony_ci	u8 hdiv;
4958c2ecf20Sopenharmony_ci	u8 vdiv;
4968c2ecf20Sopenharmony_ci	u8 block_w[4];
4978c2ecf20Sopenharmony_ci	u8 block_h[4];
4988c2ecf20Sopenharmony_ci};
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_cistatic inline bool v4l2_is_format_rgb(const struct v4l2_format_info *f)
5018c2ecf20Sopenharmony_ci{
5028c2ecf20Sopenharmony_ci	return f && f->pixel_enc == V4L2_PIXEL_ENC_RGB;
5038c2ecf20Sopenharmony_ci}
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_cistatic inline bool v4l2_is_format_yuv(const struct v4l2_format_info *f)
5068c2ecf20Sopenharmony_ci{
5078c2ecf20Sopenharmony_ci	return f && f->pixel_enc == V4L2_PIXEL_ENC_YUV;
5088c2ecf20Sopenharmony_ci}
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_cistatic inline bool v4l2_is_format_bayer(const struct v4l2_format_info *f)
5118c2ecf20Sopenharmony_ci{
5128c2ecf20Sopenharmony_ci	return f && f->pixel_enc == V4L2_PIXEL_ENC_BAYER;
5138c2ecf20Sopenharmony_ci}
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ciconst struct v4l2_format_info *v4l2_format_info(u32 format);
5168c2ecf20Sopenharmony_civoid v4l2_apply_frmsize_constraints(u32 *width, u32 *height,
5178c2ecf20Sopenharmony_ci				    const struct v4l2_frmsize_stepwise *frmsize);
5188c2ecf20Sopenharmony_ciint v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
5198c2ecf20Sopenharmony_ci		     u32 width, u32 height);
5208c2ecf20Sopenharmony_ciint v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelformat,
5218c2ecf20Sopenharmony_ci			u32 width, u32 height);
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_cistatic inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)
5248c2ecf20Sopenharmony_ci{
5258c2ecf20Sopenharmony_ci	/*
5268c2ecf20Sopenharmony_ci	 * When the timestamp comes from 32-bit user space, there may be
5278c2ecf20Sopenharmony_ci	 * uninitialized data in tv_usec, so cast it to u32.
5288c2ecf20Sopenharmony_ci	 * Otherwise allow invalid input for backwards compatibility.
5298c2ecf20Sopenharmony_ci	 */
5308c2ecf20Sopenharmony_ci	return buf->timestamp.tv_sec * NSEC_PER_SEC +
5318c2ecf20Sopenharmony_ci		(u32)buf->timestamp.tv_usec * NSEC_PER_USEC;
5328c2ecf20Sopenharmony_ci}
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_cistatic inline void v4l2_buffer_set_timestamp(struct v4l2_buffer *buf,
5358c2ecf20Sopenharmony_ci					     u64 timestamp)
5368c2ecf20Sopenharmony_ci{
5378c2ecf20Sopenharmony_ci	struct timespec64 ts = ns_to_timespec64(timestamp);
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci	buf->timestamp.tv_sec  = ts.tv_sec;
5408c2ecf20Sopenharmony_ci	buf->timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
5418c2ecf20Sopenharmony_ci}
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_cistatic inline bool v4l2_is_colorspace_valid(__u32 colorspace)
5448c2ecf20Sopenharmony_ci{
5458c2ecf20Sopenharmony_ci	return colorspace > V4L2_COLORSPACE_DEFAULT &&
5468c2ecf20Sopenharmony_ci	       colorspace <= V4L2_COLORSPACE_DCI_P3;
5478c2ecf20Sopenharmony_ci}
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_cistatic inline bool v4l2_is_xfer_func_valid(__u32 xfer_func)
5508c2ecf20Sopenharmony_ci{
5518c2ecf20Sopenharmony_ci	return xfer_func > V4L2_XFER_FUNC_DEFAULT &&
5528c2ecf20Sopenharmony_ci	       xfer_func <= V4L2_XFER_FUNC_SMPTE2084;
5538c2ecf20Sopenharmony_ci}
5548c2ecf20Sopenharmony_ci
5558c2ecf20Sopenharmony_cistatic inline bool v4l2_is_ycbcr_enc_valid(__u8 ycbcr_enc)
5568c2ecf20Sopenharmony_ci{
5578c2ecf20Sopenharmony_ci	return ycbcr_enc > V4L2_YCBCR_ENC_DEFAULT &&
5588c2ecf20Sopenharmony_ci	       ycbcr_enc <= V4L2_YCBCR_ENC_SMPTE240M;
5598c2ecf20Sopenharmony_ci}
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_cistatic inline bool v4l2_is_hsv_enc_valid(__u8 hsv_enc)
5628c2ecf20Sopenharmony_ci{
5638c2ecf20Sopenharmony_ci	return hsv_enc == V4L2_HSV_ENC_180 || hsv_enc == V4L2_HSV_ENC_256;
5648c2ecf20Sopenharmony_ci}
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_cistatic inline bool v4l2_is_quant_valid(__u8 quantization)
5678c2ecf20Sopenharmony_ci{
5688c2ecf20Sopenharmony_ci	return quantization == V4L2_QUANTIZATION_FULL_RANGE ||
5698c2ecf20Sopenharmony_ci	       quantization == V4L2_QUANTIZATION_LIM_RANGE;
5708c2ecf20Sopenharmony_ci}
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci#endif /* V4L2_COMMON_H_ */
573