/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2v4l2 common internal API header34This header contains internal shared ioctl definitions for use by the5internal low-level v4l2 drivers.6Each ioctl begins with VIDIOC_INT_ to clearly mark that it is an internal7define,89Copyright (C) 2005 Hans Verkuil <[email protected]>1011*/1213#ifndef V4L2_COMMON_H_14#define V4L2_COMMON_H_1516#include <linux/time.h>17#include <media/v4l2-dev.h>1819/* Common printk constructs for v4l-i2c drivers. These macros create a unique20prefix consisting of the driver name, the adapter number and the i2c21address. */22#define v4l_printk(level, name, adapter, addr, fmt, arg...) \23printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg)2425#define v4l_client_printk(level, client, fmt, arg...) \26v4l_printk(level, (client)->dev.driver->name, (client)->adapter, \27(client)->addr, fmt , ## arg)2829#define v4l_err(client, fmt, arg...) \30v4l_client_printk(KERN_ERR, client, fmt , ## arg)3132#define v4l_warn(client, fmt, arg...) \33v4l_client_printk(KERN_WARNING, client, fmt , ## arg)3435#define v4l_info(client, fmt, arg...) \36v4l_client_printk(KERN_INFO, client, fmt , ## arg)3738/* These three macros assume that the debug level is set with a module39parameter called 'debug'. */40#define v4l_dbg(level, debug, client, fmt, arg...) \41do { \42if (debug >= (level)) \43v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \44} while (0)4546/* Add a version of v4l_dbg to be used on drivers using dev_foo() macros */47#define dev_dbg_lvl(__dev, __level, __debug, __fmt, __arg...) \48do { \49if (__debug >= (__level)) \50dev_printk(KERN_DEBUG, __dev, __fmt, ##__arg); \51} while (0)5253/* ------------------------------------------------------------------------- */5455/* These printk constructs can be used with v4l2_device and v4l2_subdev */56#define v4l2_printk(level, dev, fmt, arg...) \57printk(level "%s: " fmt, (dev)->name , ## arg)5859#define v4l2_err(dev, fmt, arg...) \60v4l2_printk(KERN_ERR, dev, fmt , ## arg)6162#define v4l2_warn(dev, fmt, arg...) \63v4l2_printk(KERN_WARNING, dev, fmt , ## arg)6465#define v4l2_info(dev, fmt, arg...) \66v4l2_printk(KERN_INFO, dev, fmt , ## arg)6768/* These three macros assume that the debug level is set with a module69parameter called 'debug'. */70#define v4l2_dbg(level, debug, dev, fmt, arg...) \71do { \72if (debug >= (level)) \73v4l2_printk(KERN_DEBUG, dev, fmt , ## arg); \74} while (0)7576/**77* v4l2_ctrl_query_fill- Fill in a struct v4l2_queryctrl78*79* @qctrl: pointer to the &struct v4l2_queryctrl to be filled80* @min: minimum value for the control81* @max: maximum value for the control82* @step: control step83* @def: default value for the control84*85* Fills the &struct v4l2_queryctrl fields for the query control.86*87* .. note::88*89* This function assumes that the @qctrl->id field is filled.90*91* Returns -EINVAL if the control is not known by the V4L2 core, 0 on success.92*/9394int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,95s32 min, s32 max, s32 step, s32 def);9697/* ------------------------------------------------------------------------- */9899struct clk;100struct v4l2_device;101struct v4l2_subdev;102struct v4l2_subdev_ops;103104/* I2C Helper functions */105#include <linux/i2c.h>106107/**108* enum v4l2_i2c_tuner_type - specifies the range of tuner address that109* 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, this123* excludes addresses used by the demodulator124* 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 {131ADDRS_RADIO,132ADDRS_DEMOD,133ADDRS_TV,134ADDRS_TV_WITH_DEMOD,135};136137#if defined(CONFIG_VIDEO_V4L2_I2C)138139/**140* v4l2_i2c_new_subdev - Load an i2c module and return an initialized141* &struct v4l2_subdev.142*143* @v4l2_dev: pointer to &struct v4l2_device144* @adapter: pointer to struct i2c_adapter145* @client_type: name of the chip that's on the adapter.146* @addr: I2C address. If zero, it will use @probe_addrs147* @probe_addrs: array with a list of address. The last entry at such148* 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,153struct i2c_adapter *adapter, const char *client_type,154u8 addr, const unsigned short *probe_addrs);155156/**157* v4l2_i2c_new_subdev_board - Load an i2c module and return an initialized158* &struct v4l2_subdev.159*160* @v4l2_dev: pointer to &struct v4l2_device161* @adapter: pointer to struct i2c_adapter162* @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 such165* 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,170struct i2c_adapter *adapter, struct i2c_board_info *info,171const unsigned short *probe_addrs);172173/**174* v4l2_i2c_subdev_set_name - Set name for an I²C sub-device175*176* @sd: pointer to &struct v4l2_subdev177* @client: pointer to struct i2c_client178* @devname: the name of the device; if NULL, the I²C device drivers's name179* will be used180* @postfix: sub-device specific string to put right after the I²C device name;181* may be NULL182*/183void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client,184const char *devname, const char *postfix);185186/**187* v4l2_i2c_subdev_init - Initializes a &struct v4l2_subdev with data from188* an i2c_client struct.189*190* @sd: pointer to &struct v4l2_subdev191* @client: pointer to struct i2c_client192* @ops: pointer to &struct v4l2_subdev_ops193*/194void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,195const struct v4l2_subdev_ops *ops);196197/**198* v4l2_i2c_subdev_addr - returns i2c client address of &struct v4l2_subdev.199*200* @sd: pointer to &struct v4l2_subdev201*202* Returns the address of an I2C sub-device203*/204unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd);205206/**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 by210* &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);215216/**217* v4l2_i2c_subdev_unregister - Unregister a v4l2_subdev218*219* @sd: pointer to &struct v4l2_subdev220*/221void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd);222223#else224225static inline struct v4l2_subdev *226v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,227struct i2c_adapter *adapter, const char *client_type,228u8 addr, const unsigned short *probe_addrs)229{230return NULL;231}232233static inline struct v4l2_subdev *234v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,235struct i2c_adapter *adapter, struct i2c_board_info *info,236const unsigned short *probe_addrs)237{238return NULL;239}240241static inline void242v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client,243const char *devname, const char *postfix)244{}245246static inline void247v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,248const struct v4l2_subdev_ops *ops)249{}250251static inline unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd)252{253return I2C_CLIENT_END;254}255256static inline const unsigned short *257v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)258{259return NULL;260}261262static inline void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd)263{}264265#endif266267/* ------------------------------------------------------------------------- */268269/* SPI Helper functions */270271#include <linux/spi/spi.h>272273#if defined(CONFIG_SPI)274275/**276* v4l2_spi_new_subdev - Load an spi module and return an initialized277* &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,287struct spi_controller *ctlr, struct spi_board_info *info);288289/**290* v4l2_spi_subdev_init - Initialize a v4l2_subdev with data from an291* spi_device struct.292*293* @sd: pointer to &struct v4l2_subdev294* @spi: pointer to struct spi_device.295* @ops: pointer to &struct v4l2_subdev_ops296*/297void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,298const struct v4l2_subdev_ops *ops);299300/**301* v4l2_spi_subdev_unregister - Unregister a v4l2_subdev302*303* @sd: pointer to &struct v4l2_subdev304*/305void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd);306307#else308309static inline struct v4l2_subdev *310v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,311struct spi_controller *ctlr, struct spi_board_info *info)312{313return NULL;314}315316static inline void317v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,318const struct v4l2_subdev_ops *ops)319{}320321static inline void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd)322{}323#endif324325/* ------------------------------------------------------------------------- */326327/*328* FIXME: these remaining ioctls/structs should be removed as well, but they329* 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 is333* to get rid of them.334*/335336/* s_config */337struct v4l2_priv_tun_config {338int tuner;339void *priv;340};341#define TUNER_SET_CONFIG _IOW('d', 92, struct v4l2_priv_tun_config)342343#define VIDIOC_INT_RESET _IOW ('d', 102, u32)344345/* ------------------------------------------------------------------------- */346347/* Miscellaneous helper functions */348349/**350* v4l_bound_align_image - adjust video dimensions according to351* 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 between365* @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 overall369* 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 alignment374* 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 image378* 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 certain381* alignment, specify ``0``, as :math:`2^0 = 1` and one byte alignment382* is equivalent to no alignment.383* #. If you only want to adjust downward, specify a maximum that's the384* same as the initial value.385*/386void v4l_bound_align_image(unsigned int *width, unsigned int wmin,387unsigned int wmax, unsigned int walign,388unsigned int *height, unsigned int hmin,389unsigned int hmax, unsigned int halign,390unsigned int salign);391392/**393* v4l2_find_nearest_size_conditional - Find the nearest size among a discrete394* set of resolutions contained in an array of a driver specific struct,395* with conditionally exlusion of certain modes396*397* @array: a driver specific array of image sizes398* @array_size: the length of the driver specific array of image sizes399* @width_field: the name of the width field in the driver specific struct400* @height_field: the name of the height field in the driver specific struct401* @width: desired width402* @height: desired height403* @func: ignores mode if returns false404* @context: context for the function405*406* Finds the closest resolution to minimize the width and height differences407* between what requested and the supported resolutions. The size of the width408* and height fields in the driver specific must equal to that of u32, i.e. four409* bytes. @func is called for each mode considered, a mode is ignored if @func410* returns false for it.411*412* Returns the best match or NULL if the length of the array is zero.413*/414#define v4l2_find_nearest_size_conditional(array, array_size, width_field, \415height_field, width, height, \416func, context) \417({ \418BUILD_BUG_ON(sizeof((array)->width_field) != sizeof(u32) || \419sizeof((array)->height_field) != sizeof(u32)); \420(typeof(&(array)[0]))__v4l2_find_nearest_size_conditional( \421(array), array_size, sizeof(*(array)), \422offsetof(typeof(*(array)), width_field), \423offsetof(typeof(*(array)), height_field), \424width, height, func, context); \425})426const void *427__v4l2_find_nearest_size_conditional(const void *array, size_t array_size,428size_t entry_size, size_t width_offset,429size_t height_offset, s32 width,430s32 height,431bool (*func)(const void *array,432size_t index,433const void *context),434const void *context);435436/**437* v4l2_find_nearest_size - Find the nearest size among a discrete set of438* resolutions contained in an array of a driver specific struct439*440* @array: a driver specific array of image sizes441* @array_size: the length of the driver specific array of image sizes442* @width_field: the name of the width field in the driver specific struct443* @height_field: the name of the height field in the driver specific struct444* @width: desired width445* @height: desired height446*447* Finds the closest resolution to minimize the width and height differences448* between what requested and the supported resolutions. The size of the width449* and height fields in the driver specific must equal to that of u32, i.e. four450* bytes.451*452* Returns the best match or NULL if the length of the array is zero.453*/454#define v4l2_find_nearest_size(array, array_size, width_field, \455height_field, width, height) \456v4l2_find_nearest_size_conditional(array, array_size, width_field, \457height_field, width, height, NULL, \458NULL)459460/**461* v4l2_g_parm_cap - helper routine for vidioc_g_parm to fill this in by462* calling the get_frame_interval op of the given subdev. It only works463* for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the464* function name.465*466* @vdev: the struct video_device pointer. Used to determine the device caps.467* @sd: the sub-device pointer.468* @a: the VIDIOC_G_PARM argument.469*/470int v4l2_g_parm_cap(struct video_device *vdev,471struct v4l2_subdev *sd, struct v4l2_streamparm *a);472473/**474* v4l2_s_parm_cap - helper routine for vidioc_s_parm to fill this in by475* calling the set_frame_interval op of the given subdev. It only works476* for V4L2_BUF_TYPE_VIDEO_CAPTURE(_MPLANE), hence the _cap in the477* function name.478*479* @vdev: the struct video_device pointer. Used to determine the device caps.480* @sd: the sub-device pointer.481* @a: the VIDIOC_S_PARM argument.482*/483int v4l2_s_parm_cap(struct video_device *vdev,484struct v4l2_subdev *sd, struct v4l2_streamparm *a);485486/* Compare two v4l2_fract structs */487#define V4L2_FRACT_COMPARE(a, OP, b) \488((u64)(a).numerator * (b).denominator OP \489(u64)(b).numerator * (a).denominator)490491/* ------------------------------------------------------------------------- */492493/* Pixel format and FourCC helpers */494495/**496* enum v4l2_pixel_encoding - specifies the pixel encoding value497*498* @V4L2_PIXEL_ENC_UNKNOWN: Pixel encoding is unknown/un-initialized499* @V4L2_PIXEL_ENC_YUV: Pixel encoding is YUV500* @V4L2_PIXEL_ENC_RGB: Pixel encoding is RGB501* @V4L2_PIXEL_ENC_BAYER: Pixel encoding is Bayer502*/503enum v4l2_pixel_encoding {504V4L2_PIXEL_ENC_UNKNOWN = 0,505V4L2_PIXEL_ENC_YUV = 1,506V4L2_PIXEL_ENC_RGB = 2,507V4L2_PIXEL_ENC_BAYER = 3,508};509510/**511* struct v4l2_format_info - information about a V4L2 format512* @format: 4CC format identifier (V4L2_PIX_FMT_*)513* @pixel_enc: Pixel encoding (see enum v4l2_pixel_encoding above)514* @mem_planes: Number of memory planes, which includes the alpha plane (1 to 4).515* @comp_planes: Number of component planes, which includes the alpha plane (1 to 4).516* @bpp: Array of per-plane bytes per pixel517* @bpp_div: Array of per-plane bytes per pixel divisors to support fractional pixel sizes.518* @hdiv: Horizontal chroma subsampling factor519* @vdiv: Vertical chroma subsampling factor520* @block_w: Per-plane macroblock pixel width (optional)521* @block_h: Per-plane macroblock pixel height (optional)522*/523struct v4l2_format_info {524u32 format;525u8 pixel_enc;526u8 mem_planes;527u8 comp_planes;528u8 bpp[4];529u8 bpp_div[4];530u8 hdiv;531u8 vdiv;532u8 block_w[4];533u8 block_h[4];534};535536static inline bool v4l2_is_format_rgb(const struct v4l2_format_info *f)537{538return f && f->pixel_enc == V4L2_PIXEL_ENC_RGB;539}540541static inline bool v4l2_is_format_yuv(const struct v4l2_format_info *f)542{543return f && f->pixel_enc == V4L2_PIXEL_ENC_YUV;544}545546static inline bool v4l2_is_format_bayer(const struct v4l2_format_info *f)547{548return f && f->pixel_enc == V4L2_PIXEL_ENC_BAYER;549}550551const struct v4l2_format_info *v4l2_format_info(u32 format);552void v4l2_apply_frmsize_constraints(u32 *width, u32 *height,553const struct v4l2_frmsize_stepwise *frmsize);554int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,555u32 width, u32 height);556int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelformat,557u32 width, u32 height);558559/**560* v4l2_get_link_freq - Get link rate from transmitter561*562* @pad: The transmitter's media pad563* @mul: The multiplier between pixel rate and link frequency. Bits per pixel on564* D-PHY, samples per clock on parallel. 0 otherwise.565* @div: The divisor between pixel rate and link frequency. Number of data lanes566* times two on D-PHY, 1 on parallel. 0 otherwise.567*568* This function obtains and returns the link frequency from the transmitter569* sub-device's pad. The link frequency is retrieved using the get_mbus_config570* sub-device pad operation. If this fails, the function falls back to obtaining571* the frequency either directly from the V4L2_CID_LINK_FREQ control if572* implemented by the transmitter, or by calculating it from the pixel rate573* obtained from the V4L2_CID_PIXEL_RATE control.574*575* Return:576* * >0: Link frequency577* * %-ENOENT: Link frequency or pixel rate control not found578* * %-EINVAL: Invalid link frequency value579*/580#ifdef CONFIG_MEDIA_CONTROLLER581s64 v4l2_get_link_freq(const struct media_pad *pad, unsigned int mul,582unsigned int div);583#endif584585void v4l2_simplify_fraction(u32 *numerator, u32 *denominator,586unsigned int n_terms, unsigned int threshold);587u32 v4l2_fraction_to_interval(u32 numerator, u32 denominator);588589/**590* v4l2_link_freq_to_bitmap - Figure out platform-supported link frequencies591* @dev: The struct device592* @fw_link_freqs: Array of link frequencies from firmware593* @num_of_fw_link_freqs: Number of entries in @fw_link_freqs594* @driver_link_freqs: Array of link frequencies supported by the driver595* @num_of_driver_link_freqs: Number of entries in @driver_link_freqs596* @bitmap: Bitmap of driver-supported link frequencies found in @fw_link_freqs597*598* This function checks which driver-supported link frequencies are enabled in599* system firmware and sets the corresponding bits in @bitmap (after first600* zeroing it).601*602* Return:603* * %0: Success604* * %-ENOENT: No match found between driver-supported link frequencies and605* those available in firmware.606* * %-ENODATA: No link frequencies were specified in firmware.607*/608int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,609unsigned int num_of_fw_link_freqs,610const s64 *driver_link_freqs,611unsigned int num_of_driver_link_freqs,612unsigned long *bitmap);613614struct clk *__devm_v4l2_sensor_clk_get(struct device *dev, const char *id,615bool legacy, bool fixed_rate,616unsigned long clk_rate);617618/**619* devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer620* for a camera sensor621*622* @dev: device for v4l2 sensor clock "consumer"623* @id: clock consumer ID624*625* This function behaves the same way as devm_clk_get() except where there626* is no clock producer like in ACPI-based platforms.627*628* For ACPI-based platforms, the function will read the "clock-frequency"629* ACPI _DSD property and register a fixed-clock with the frequency indicated630* in the property.631*632* This function also handles the special ACPI-based system case where:633*634* * The clock-frequency _DSD property is present.635* * A reference to the clock producer is present, where the clock is provided636* by a camera sensor PMIC driver (e.g. int3472/tps68470.c)637*638* In this case try to set the clock-frequency value to the provided clock.639*640* As the name indicates, this function may only be used on camera sensor641* devices. This is because generally only camera sensors do need a clock to642* query the frequency from, due to the requirement to configure the PLL for a643* given CSI-2 interface frequency where the sensor's external clock frequency644* is a factor. Additionally, the clock frequency tends to be available on ACPI645* firmware based systems for camera sensors specifically (if e.g. DisCo for646* Imaging compliant).647*648* Returns a pointer to a struct clk on success or an error pointer on failure.649*/650static inline struct clk *651devm_v4l2_sensor_clk_get(struct device *dev, const char *id)652{653return __devm_v4l2_sensor_clk_get(dev, id, false, false, 0);654}655656/**657* devm_v4l2_sensor_clk_get_legacy - lookup and obtain a reference to a clock658* producer for a camera sensor.659*660* @dev: device for v4l2 sensor clock "consumer"661* @id: clock consumer ID662* @fixed_rate: interpret the @clk_rate as a fixed rate or default rate663* @clk_rate: the clock rate664*665* This function behaves the same way as devm_v4l2_sensor_clk_get() except that666* it extends the behaviour on ACPI platforms to all platforms.667*668* The function also provides the ability to set the clock rate to a fixed669* frequency by setting @fixed_rate to true and specifying the fixed frequency670* in @clk_rate, or to use a default clock rate when the "clock-frequency"671* property is absent by setting @fixed_rate to false and specifying the default672* frequency in @clk_rate. Setting @fixed_rate to true and @clk_rate to 0 is an673* error.674*675* This function is meant to support legacy behaviour in existing drivers only.676* It must not be used in any new driver.677*678* Returns a pointer to a struct clk on success or an error pointer on failure.679*/680static inline struct clk *681devm_v4l2_sensor_clk_get_legacy(struct device *dev, const char *id,682bool fixed_rate, unsigned long clk_rate)683{684return __devm_v4l2_sensor_clk_get(dev, id, true, fixed_rate, clk_rate);685}686687static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)688{689/*690* When the timestamp comes from 32-bit user space, there may be691* uninitialized data in tv_usec, so cast it to u32.692* Otherwise allow invalid input for backwards compatibility.693*/694return buf->timestamp.tv_sec * NSEC_PER_SEC +695(u32)buf->timestamp.tv_usec * NSEC_PER_USEC;696}697698static inline void v4l2_buffer_set_timestamp(struct v4l2_buffer *buf,699u64 timestamp)700{701struct timespec64 ts = ns_to_timespec64(timestamp);702703buf->timestamp.tv_sec = ts.tv_sec;704buf->timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC;705}706707static inline bool v4l2_is_colorspace_valid(__u32 colorspace)708{709return colorspace > V4L2_COLORSPACE_DEFAULT &&710colorspace < V4L2_COLORSPACE_LAST;711}712713static inline bool v4l2_is_xfer_func_valid(__u32 xfer_func)714{715return xfer_func > V4L2_XFER_FUNC_DEFAULT &&716xfer_func < V4L2_XFER_FUNC_LAST;717}718719static inline bool v4l2_is_ycbcr_enc_valid(__u8 ycbcr_enc)720{721return ycbcr_enc > V4L2_YCBCR_ENC_DEFAULT &&722ycbcr_enc < V4L2_YCBCR_ENC_LAST;723}724725static inline bool v4l2_is_hsv_enc_valid(__u8 hsv_enc)726{727return hsv_enc == V4L2_HSV_ENC_180 || hsv_enc == V4L2_HSV_ENC_256;728}729730static inline bool v4l2_is_quant_valid(__u8 quantization)731{732return quantization == V4L2_QUANTIZATION_FULL_RANGE ||733quantization == V4L2_QUANTIZATION_LIM_RANGE;734}735736#endif /* V4L2_COMMON_H_ */737738739