Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)     V4L2 device support header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)     Copyright (C) 2008  Hans Verkuil <hverkuil@xs4all.nl>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #ifndef _V4L2_DEVICE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define _V4L2_DEVICE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <media/media-device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <media/v4l2-subdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <media/v4l2-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define V4L2_DEVICE_NAME_SIZE (20 + 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) struct v4l2_ctrl_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * struct v4l2_device - main struct to for V4L2 device drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * @dev: pointer to struct device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * @mdev: pointer to struct media_device, may be NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * @subdevs: used to keep track of the registered subdevs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * @lock: lock this struct; can be used by the driver as well
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *	if this struct is embedded into a larger struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * @name: unique device name, by default the driver name + bus ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * @notify: notify operation called by some sub-devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * @ctrl_handler: The control handler. May be %NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * @prio: Device's priority state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * @ref: Keep track of the references to this struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * @release: Release function that is called when the ref count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *	goes to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * Each instance of a V4L2 device should create the v4l2_device struct,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * either stand-alone or embedded in a larger struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * It allows easy access to sub-devices (see v4l2-subdev.h) and provides
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * basic V4L2 device-level support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *    #) @dev->driver_data points to this struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *    #) @dev might be %NULL if there is no parent device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) struct v4l2_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct media_device *mdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct list_head subdevs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	char name[V4L2_DEVICE_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	void (*notify)(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			unsigned int notification, void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct v4l2_ctrl_handler *ctrl_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct v4l2_prio_state prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct kref ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	void (*release)(struct v4l2_device *v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * v4l2_device_get - gets a V4L2 device reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * @v4l2_dev: pointer to struct &v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * This is an ancillary routine meant to increment the usage for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * struct &v4l2_device pointed by @v4l2_dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static inline void v4l2_device_get(struct v4l2_device *v4l2_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	kref_get(&v4l2_dev->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * v4l2_device_put - puts a V4L2 device reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * @v4l2_dev: pointer to struct &v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * This is an ancillary routine meant to decrement the usage for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * struct &v4l2_device pointed by @v4l2_dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) int v4l2_device_put(struct v4l2_device *v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * v4l2_device_register - Initialize v4l2_dev and make @dev->driver_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  *	point to @v4l2_dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * @dev: pointer to struct &device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * @v4l2_dev: pointer to struct &v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *	@dev may be %NULL in rare cases (ISA devices).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  *	In such case the caller must fill in the @v4l2_dev->name field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  *	before calling this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) int __must_check v4l2_device_register(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				      struct v4l2_device *v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * v4l2_device_set_name - Optional function to initialize the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *	name field of struct &v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * @v4l2_dev: pointer to struct &v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * @basename: base name for the device name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * @instance: pointer to a static atomic_t var with the instance usage for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  *	the device driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * v4l2_device_set_name() initializes the name field of struct &v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * using the driver name and a driver-global atomic_t instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * This function will increment the instance counter and returns the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * instance value used in the name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  * Example:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  *   static atomic_t drv_instance = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  *   ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  *   instance = v4l2_device_set_name(&\ v4l2_dev, "foo", &\ drv_instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * The first time this is called the name field will be set to foo0 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * this function returns 0. If the name ends with a digit (e.g. cx18),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * then the name will be set to cx18-0 since cx180 would look really odd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			 atomic_t *instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * v4l2_device_disconnect - Change V4L2 device state to disconnected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  * @v4l2_dev: pointer to struct v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * Should be called when the USB parent disconnects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * Since the parent disappears, this ensures that @v4l2_dev doesn't have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * an invalid parent pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * .. note:: This function sets @v4l2_dev->dev to NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) void v4l2_device_disconnect(struct v4l2_device *v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  *  v4l2_device_unregister - Unregister all sub-devices and any other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  *	 resources related to @v4l2_dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * @v4l2_dev: pointer to struct v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) void v4l2_device_unregister(struct v4l2_device *v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * v4l2_device_register_subdev - Registers a subdev with a v4l2 device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * @v4l2_dev: pointer to struct &v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * @sd: pointer to &struct v4l2_subdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * While registered, the subdev module is marked as in-use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * An error is returned if the module is no longer loaded on any attempts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * to register it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int __must_check v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 					     struct v4l2_subdev *sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * v4l2_device_unregister_subdev - Unregisters a subdev with a v4l2 device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * @sd: pointer to &struct v4l2_subdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  * .. note ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  *	Can also be called if the subdev wasn't registered. In such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  *	case, it will do nothing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * __v4l2_device_register_ro_subdev_nodes - Registers device nodes for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  *      all subdevs of the v4l2 device that are marked with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  *      %V4L2_SUBDEV_FL_HAS_DEVNODE flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * @v4l2_dev: pointer to struct v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * @read_only: subdevices read-only flag. True to register the subdevices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  *	device nodes in read-only mode, false to allow full access to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  *	subdevice userspace API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int __must_check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 				    bool read_only);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * v4l2_device_register_subdev_nodes - Registers subdevices device nodes with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  *	unrestricted access to the subdevice userspace operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * Internally calls __v4l2_device_register_subdev_nodes(). See its documentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * @v4l2_dev: pointer to struct v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static inline int __must_check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	return __v4l2_device_register_subdev_nodes(v4l2_dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * v4l2_device_register_ro_subdev_nodes - Registers subdevices device nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  *	in read-only mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * Internally calls __v4l2_device_register_subdev_nodes(). See its documentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * @v4l2_dev: pointer to struct v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static inline int __must_check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) v4l2_device_register_ro_subdev_nodes(struct v4l2_device *v4l2_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return __v4l2_device_register_subdev_nodes(v4l2_dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  * v4l2_subdev_notify - Sends a notification to v4l2_device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * @sd: pointer to &struct v4l2_subdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * @notification: type of notification. Please notice that the notification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  *	type is driver-specific.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * @arg: arguments for the notification. Those are specific to each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  *	notification type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static inline void v4l2_subdev_notify(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				      unsigned int notification, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (sd && sd->v4l2_dev && sd->v4l2_dev->notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		sd->v4l2_dev->notify(sd, notification, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * v4l2_device_supports_requests - Test if requests are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * @v4l2_dev: pointer to struct v4l2_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static inline bool v4l2_device_supports_requests(struct v4l2_device *v4l2_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return v4l2_dev->mdev && v4l2_dev->mdev->ops &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	       v4l2_dev->mdev->ops->req_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /* Helper macros to iterate over all subdevs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  * v4l2_device_for_each_subdev - Helper macro that interates over all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  *	sub-devices of a given &v4l2_device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * @sd: pointer that will be filled by the macro with all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  *	&struct v4l2_subdev pointer used as an iterator by the loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * @v4l2_dev: &struct v4l2_device owning the sub-devices to iterate over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * This macro iterates over all sub-devices owned by the @v4l2_dev device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * It acts as a for loop iterator and executes the next statement with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * the @sd variable pointing to each sub-device in turn.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #define v4l2_device_for_each_subdev(sd, v4l2_dev)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	list_for_each_entry(sd, &(v4l2_dev)->subdevs, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  * __v4l2_device_call_subdevs_p - Calls the specified operation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  *	all subdevs matching the condition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  * @v4l2_dev: &struct v4l2_device owning the sub-devices to iterate over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * @sd: pointer that will be filled by the macro with all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  *	&struct v4l2_subdev pointer used as an iterator by the loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  * @cond: condition to be match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  *     Each element there groups a set of operations functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  * @f: operation function that will be called if @cond matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  *	The operation functions are defined in groups, according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  *	each element at &struct v4l2_subdev_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  * @args: arguments for @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  * Ignore any errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)  * Note: subdevs cannot be added or deleted while walking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  * the subdevs list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) #define __v4l2_device_call_subdevs_p(v4l2_dev, sd, cond, o, f, args...)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		list_for_each_entry((sd), &(v4l2_dev)->subdevs, list)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			if ((cond) && (sd)->ops->o && (sd)->ops->o->f)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 				(sd)->ops->o->f((sd) , ##args);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * __v4l2_device_call_subdevs - Calls the specified operation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  *	all subdevs matching the condition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * @v4l2_dev: &struct v4l2_device owning the sub-devices to iterate over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * @cond: condition to be match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  *     Each element there groups a set of operations functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * @f: operation function that will be called if @cond matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  *	The operation functions are defined in groups, according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  *	each element at &struct v4l2_subdev_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * @args: arguments for @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  * Ignore any errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  * Note: subdevs cannot be added or deleted while walking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  * the subdevs list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) #define __v4l2_device_call_subdevs(v4l2_dev, cond, o, f, args...)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		struct v4l2_subdev *__sd;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		__v4l2_device_call_subdevs_p(v4l2_dev, __sd, cond, o,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 						f , ##args);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * __v4l2_device_call_subdevs_until_err_p - Calls the specified operation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  *	all subdevs matching the condition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  * @v4l2_dev: &struct v4l2_device owning the sub-devices to iterate over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  * @sd: pointer that will be filled by the macro with all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  *	&struct v4l2_subdev sub-devices associated with @v4l2_dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * @cond: condition to be match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  *     Each element there groups a set of operations functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * @f: operation function that will be called if @cond matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  *	The operation functions are defined in groups, according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  *	each element at &struct v4l2_subdev_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  * @args: arguments for @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)  * If the operation returns an error other than 0 or ``-ENOIOCTLCMD``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)  * for any subdevice, then abort and return with that error code, zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)  * otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)  * Note: subdevs cannot be added or deleted while walking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  * the subdevs list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) #define __v4l2_device_call_subdevs_until_err_p(v4l2_dev, sd, cond, o, f, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	long __err = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	list_for_each_entry((sd), &(v4l2_dev)->subdevs, list) {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		if ((cond) && (sd)->ops->o && (sd)->ops->o->f)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			__err = (sd)->ops->o->f((sd) , ##args);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		if (__err && __err != -ENOIOCTLCMD)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	(__err == -ENOIOCTLCMD) ? 0 : __err;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  * __v4l2_device_call_subdevs_until_err - Calls the specified operation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)  *	all subdevs matching the condition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)  * @v4l2_dev: &struct v4l2_device owning the sub-devices to iterate over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)  * @cond: condition to be match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)  * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)  *     Each element there groups a set of operations functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)  * @f: operation function that will be called if @cond matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  *	The operation functions are defined in groups, according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  *	each element at &struct v4l2_subdev_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  * @args: arguments for @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  * If the operation returns an error other than 0 or ``-ENOIOCTLCMD``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)  * for any subdevice, then abort and return with that error code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)  * zero otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)  * Note: subdevs cannot be added or deleted while walking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  * the subdevs list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) #define __v4l2_device_call_subdevs_until_err(v4l2_dev, cond, o, f, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	struct v4l2_subdev *__sd;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	__v4l2_device_call_subdevs_until_err_p(v4l2_dev, __sd, cond, o,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 						f , ##args);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  * v4l2_device_call_all - Calls the specified operation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  *	all subdevs matching the &v4l2_subdev.grp_id, as assigned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  *	by the bridge driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  * @v4l2_dev: &struct v4l2_device owning the sub-devices to iterate over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  * @grpid: &struct v4l2_subdev->grp_id group ID to match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  *	    Use 0 to match them all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  *     Each element there groups a set of operations functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  * @f: operation function that will be called if @cond matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  *	The operation functions are defined in groups, according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  *	each element at &struct v4l2_subdev_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  * @args: arguments for @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  * Ignore any errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)  * Note: subdevs cannot be added or deleted while walking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)  * the subdevs list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) #define v4l2_device_call_all(v4l2_dev, grpid, o, f, args...)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		struct v4l2_subdev *__sd;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		__v4l2_device_call_subdevs_p(v4l2_dev, __sd,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 			(grpid) == 0 || __sd->grp_id == (grpid), o, f ,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			##args);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)  * v4l2_device_call_until_err - Calls the specified operation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)  *	all subdevs matching the &v4l2_subdev.grp_id, as assigned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)  *	by the bridge driver, until an error occurs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  * @v4l2_dev: &struct v4l2_device owning the sub-devices to iterate over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  * @grpid: &struct v4l2_subdev->grp_id group ID to match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  *	   Use 0 to match them all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)  *     Each element there groups a set of operations functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)  * @f: operation function that will be called if @cond matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)  *	The operation functions are defined in groups, according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)  *	each element at &struct v4l2_subdev_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)  * @args: arguments for @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  * If the operation returns an error other than 0 or ``-ENOIOCTLCMD``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)  * for any subdevice, then abort and return with that error code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  * zero otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  * Note: subdevs cannot be added or deleted while walking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  * the subdevs list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) #define v4l2_device_call_until_err(v4l2_dev, grpid, o, f, args...)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	struct v4l2_subdev *__sd;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	__v4l2_device_call_subdevs_until_err_p(v4l2_dev, __sd,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			(grpid) == 0 || __sd->grp_id == (grpid), o, f ,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 			##args);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)  * v4l2_device_mask_call_all - Calls the specified operation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)  *	all subdevices where a group ID matches a specified bitmask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)  * @v4l2_dev: &struct v4l2_device owning the sub-devices to iterate over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)  * @grpmsk: bitmask to be checked against &struct v4l2_subdev->grp_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)  *	    group ID to be matched. Use 0 to match them all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)  * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)  *     Each element there groups a set of operations functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)  * @f: operation function that will be called if @cond matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)  *	The operation functions are defined in groups, according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)  *	each element at &struct v4l2_subdev_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)  * @args: arguments for @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)  * Ignore any errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)  * Note: subdevs cannot be added or deleted while walking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  * the subdevs list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) #define v4l2_device_mask_call_all(v4l2_dev, grpmsk, o, f, args...)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		struct v4l2_subdev *__sd;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		__v4l2_device_call_subdevs_p(v4l2_dev, __sd,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 			(grpmsk) == 0 || (__sd->grp_id & (grpmsk)), o,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 			f , ##args);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)  * v4l2_device_mask_call_until_err - Calls the specified operation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)  *	all subdevices where a group ID matches a specified bitmask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)  * @v4l2_dev: &struct v4l2_device owning the sub-devices to iterate over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)  * @grpmsk: bitmask to be checked against &struct v4l2_subdev->grp_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)  *	    group ID to be matched. Use 0 to match them all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)  * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)  *     Each element there groups a set of operations functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)  * @f: operation function that will be called if @cond matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)  *	The operation functions are defined in groups, according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)  *	each element at &struct v4l2_subdev_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)  * @args: arguments for @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)  * If the operation returns an error other than 0 or ``-ENOIOCTLCMD``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)  * for any subdevice, then abort and return with that error code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)  * zero otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)  * Note: subdevs cannot be added or deleted while walking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)  * the subdevs list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) #define v4l2_device_mask_call_until_err(v4l2_dev, grpmsk, o, f, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	struct v4l2_subdev *__sd;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	__v4l2_device_call_subdevs_until_err_p(v4l2_dev, __sd,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			(grpmsk) == 0 || (__sd->grp_id & (grpmsk)), o,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 			f , ##args);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)  * v4l2_device_has_op - checks if any subdev with matching grpid has a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)  *	given ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)  * @v4l2_dev: &struct v4l2_device owning the sub-devices to iterate over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)  * @grpid: &struct v4l2_subdev->grp_id group ID to match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)  *	   Use 0 to match them all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)  * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)  *     Each element there groups a set of operations functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)  * @f: operation function that will be called if @cond matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)  *	The operation functions are defined in groups, according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)  *	each element at &struct v4l2_subdev_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) #define v4l2_device_has_op(v4l2_dev, grpid, o, f)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	struct v4l2_subdev *__sd;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	bool __result = false;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	list_for_each_entry(__sd, &(v4l2_dev)->subdevs, list) {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		if ((grpid) && __sd->grp_id != (grpid))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 			continue;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		if (v4l2_subdev_has_op(__sd, o, f)) {			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 			__result = true;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 			break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	__result;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)  * v4l2_device_mask_has_op - checks if any subdev with matching group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)  *	mask has a given ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)  * @v4l2_dev: &struct v4l2_device owning the sub-devices to iterate over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)  * @grpmsk: bitmask to be checked against &struct v4l2_subdev->grp_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)  *	    group ID to be matched. Use 0 to match them all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)  * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)  *     Each element there groups a set of operations functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)  * @f: operation function that will be called if @cond matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)  *	The operation functions are defined in groups, according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)  *	each element at &struct v4l2_subdev_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) #define v4l2_device_mask_has_op(v4l2_dev, grpmsk, o, f)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	struct v4l2_subdev *__sd;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	bool __result = false;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	list_for_each_entry(__sd, &(v4l2_dev)->subdevs, list) {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		if ((grpmsk) && !(__sd->grp_id & (grpmsk)))		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 			continue;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		if (v4l2_subdev_has_op(__sd, o, f)) {			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 			__result = true;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 			break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 		}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	__result;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) #endif