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