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