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. |
| 36 | * @mdev: pointer to struct media_device |
| 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 |
| 41 | * @notify: notify callback 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 | */ |
| 59 | |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 60 | struct v4l2_device { |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 61 | struct device *dev; |
Laurent Pinchart | 95db3a6 | 2009-12-09 08:40:05 -0300 | [diff] [blame] | 62 | #if defined(CONFIG_MEDIA_CONTROLLER) |
| 63 | struct media_device *mdev; |
| 64 | #endif |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 65 | struct list_head subdevs; |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 66 | spinlock_t lock; |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 67 | char name[V4L2_DEVICE_NAME_SIZE]; |
Hans Verkuil | 98ec633 | 2009-03-08 17:02:10 -0300 | [diff] [blame] | 68 | void (*notify)(struct v4l2_subdev *sd, |
| 69 | unsigned int notification, void *arg); |
Hans Verkuil | 0996517 | 2010-08-01 14:32:42 -0300 | [diff] [blame] | 70 | struct v4l2_ctrl_handler *ctrl_handler; |
Hans Verkuil | 0f62fd6 | 2011-02-24 10:42:24 -0300 | [diff] [blame] | 71 | struct v4l2_prio_state prio; |
Hans Verkuil | bedf8bc | 2011-03-12 06:37:19 -0300 | [diff] [blame] | 72 | struct kref ref; |
Hans Verkuil | bedf8bc | 2011-03-12 06:37:19 -0300 | [diff] [blame] | 73 | void (*release)(struct v4l2_device *v4l2_dev); |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 74 | }; |
| 75 | |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 76 | /** |
| 77 | * v4l2_device_get - gets a V4L2 device reference |
| 78 | * |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 79 | * @v4l2_dev: pointer to struct &v4l2_device |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 80 | * |
| 81 | * 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] | 82 | * struct &v4l2_device pointed by @v4l2_dev. |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 83 | */ |
Hans Verkuil | bedf8bc | 2011-03-12 06:37:19 -0300 | [diff] [blame] | 84 | static inline void v4l2_device_get(struct v4l2_device *v4l2_dev) |
| 85 | { |
| 86 | kref_get(&v4l2_dev->ref); |
| 87 | } |
| 88 | |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 89 | /** |
| 90 | * v4l2_device_put - putss a V4L2 device reference |
| 91 | * |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 92 | * @v4l2_dev: pointer to struct &v4l2_device |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 93 | * |
| 94 | * 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] | 95 | * struct &v4l2_device pointed by @v4l2_dev. |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 96 | */ |
Hans Verkuil | bedf8bc | 2011-03-12 06:37:19 -0300 | [diff] [blame] | 97 | int v4l2_device_put(struct v4l2_device *v4l2_dev); |
| 98 | |
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 | * v4l2_device_register - Initialize v4l2_dev and make @dev->driver_data |
| 101 | * point to @v4l2_dev. |
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 | * @dev: pointer to struct &device |
| 104 | * @v4l2_dev: pointer to struct &v4l2_device |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 105 | * |
| 106 | * .. note:: |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 107 | * @dev may be %NULL in rare cases (ISA devices). |
| 108 | * 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] | 109 | * before calling this function. |
| 110 | */ |
| 111 | int __must_check v4l2_device_register(struct device *dev, |
| 112 | struct v4l2_device *v4l2_dev); |
Hans Verkuil | 102e781 | 2009-05-02 10:12:50 -0300 | [diff] [blame] | 113 | |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 114 | /** |
| 115 | * v4l2_device_set_name - Optional function to initialize the |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 116 | * name field of struct &v4l2_device |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 117 | * |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 118 | * @v4l2_dev: pointer to struct &v4l2_device |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 119 | * @basename: base name for the device name |
| 120 | * @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] | 121 | * the device driver. |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 122 | * |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 123 | * 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] | 124 | * using the driver name and a driver-global atomic_t instance. |
| 125 | * |
| 126 | * This function will increment the instance counter and returns the |
| 127 | * instance value used in the name. |
| 128 | * |
| 129 | * Example: |
| 130 | * |
| 131 | * static atomic_t drv_instance = ATOMIC_INIT(0); |
| 132 | * |
| 133 | * ... |
| 134 | * |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 135 | * instance = v4l2_device_set_name(&\ v4l2_dev, "foo", &\ drv_instance); |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 136 | * |
| 137 | * The first time this is called the name field will be set to foo0 and |
| 138 | * this function returns 0. If the name ends with a digit (e.g. cx18), |
| 139 | * then the name will be set to cx18-0 since cx180 would look really odd. |
| 140 | */ |
Hans Verkuil | 102e781 | 2009-05-02 10:12:50 -0300 | [diff] [blame] | 141 | 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] | 142 | atomic_t *instance); |
Hans Verkuil | 102e781 | 2009-05-02 10:12:50 -0300 | [diff] [blame] | 143 | |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 144 | /** |
| 145 | * v4l2_device_disconnect - Change V4L2 device state to disconnected. |
| 146 | * |
| 147 | * @v4l2_dev: pointer to struct v4l2_device |
| 148 | * |
| 149 | * Should be called when the USB parent disconnects. |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 150 | * 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] | 151 | * an invalid parent pointer. |
| 152 | * |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 153 | * .. note:: This function sets @v4l2_dev->dev to NULL. |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 154 | */ |
Hans Verkuil | ae6cfaa | 2009-03-14 08:28:45 -0300 | [diff] [blame] | 155 | void v4l2_device_disconnect(struct v4l2_device *v4l2_dev); |
Hans Verkuil | 102e781 | 2009-05-02 10:12:50 -0300 | [diff] [blame] | 156 | |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 157 | /** |
| 158 | * v4l2_device_unregister - Unregister all sub-devices and any other |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 159 | * resources related to @v4l2_dev. |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 160 | * |
| 161 | * @v4l2_dev: pointer to struct v4l2_device |
| 162 | */ |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 163 | void v4l2_device_unregister(struct v4l2_device *v4l2_dev); |
| 164 | |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 165 | /** |
| 166 | * v4l2_device_register_subdev - Registers a subdev with a v4l2 device. |
| 167 | * |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 168 | * @v4l2_dev: pointer to struct &v4l2_device |
| 169 | * @sd: pointer to struct &v4l2_subdev |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 170 | * |
| 171 | * While registered, the subdev module is marked as in-use. |
| 172 | * |
| 173 | * An error is returned if the module is no longer loaded on any attempts |
| 174 | * to register it. |
| 175 | */ |
Hans Verkuil | 3a63e449 | 2009-02-14 11:54:23 -0300 | [diff] [blame] | 176 | 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] | 177 | struct v4l2_subdev *sd); |
| 178 | |
| 179 | /** |
| 180 | * v4l2_device_unregister_subdev - Unregisters a subdev with a v4l2 device. |
| 181 | * |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 182 | * @sd: pointer to struct &v4l2_subdev |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 183 | * |
| 184 | * .. note :: |
| 185 | * |
| 186 | * Can also be called if the subdev wasn't registered. In such |
| 187 | * case, it will do nothing. |
| 188 | */ |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 189 | void v4l2_device_unregister_subdev(struct v4l2_subdev *sd); |
| 190 | |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 191 | /** |
| 192 | * v4l2_device_register_subdev_nodes - Registers device nodes for all subdevs |
| 193 | * of the v4l2 device that are marked with |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 194 | * the %V4L2_SUBDEV_FL_HAS_DEVNODE flag. |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 195 | * |
| 196 | * @v4l2_dev: pointer to struct v4l2_device |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 197 | */ |
| 198 | int __must_check |
| 199 | v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev); |
| 200 | |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 201 | /** |
| 202 | * v4l2_subdev_notify - Sends a notification to v4l2_device. |
| 203 | * |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 204 | * @sd: pointer to struct &v4l2_subdev |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 205 | * @notification: type of notification. Please notice that the notification |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 206 | * type is driver-specific. |
Mauro Carvalho Chehab | 575f930 | 2016-07-20 13:05:05 -0300 | [diff] [blame] | 207 | * @arg: arguments for the notification. Those are specific to each |
| 208 | * notification type. |
| 209 | */ |
Hans Verkuil | ba76a6e | 2014-03-17 09:54:19 -0300 | [diff] [blame] | 210 | static inline void v4l2_subdev_notify(struct v4l2_subdev *sd, |
| 211 | unsigned int notification, void *arg) |
| 212 | { |
| 213 | if (sd && sd->v4l2_dev && sd->v4l2_dev->notify) |
| 214 | sd->v4l2_dev->notify(sd, notification, arg); |
| 215 | } |
| 216 | |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 217 | /* Iterate over all subdevs. */ |
Hans Verkuil | 3a63e449 | 2009-02-14 11:54:23 -0300 | [diff] [blame] | 218 | #define v4l2_device_for_each_subdev(sd, v4l2_dev) \ |
| 219 | list_for_each_entry(sd, &(v4l2_dev)->subdevs, list) |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 220 | |
| 221 | /* Call the specified callback for all subdevs matching the condition. |
| 222 | Ignore any errors. Note that you cannot add or delete a subdev |
| 223 | while walking the subdevs list. */ |
Guennadi Liakhovetski | 6c2d4dd | 2010-08-12 17:16:00 -0300 | [diff] [blame] | 224 | #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] | 225 | do { \ |
Guennadi Liakhovetski | 6c2d4dd | 2010-08-12 17:16:00 -0300 | [diff] [blame] | 226 | list_for_each_entry((sd), &(v4l2_dev)->subdevs, list) \ |
| 227 | if ((cond) && (sd)->ops->o && (sd)->ops->o->f) \ |
| 228 | (sd)->ops->o->f((sd) , ##args); \ |
| 229 | } while (0) |
| 230 | |
| 231 | #define __v4l2_device_call_subdevs(v4l2_dev, cond, o, f, args...) \ |
| 232 | do { \ |
| 233 | struct v4l2_subdev *__sd; \ |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 234 | \ |
Guennadi Liakhovetski | 6c2d4dd | 2010-08-12 17:16:00 -0300 | [diff] [blame] | 235 | __v4l2_device_call_subdevs_p(v4l2_dev, __sd, cond, o, \ |
| 236 | f , ##args); \ |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 237 | } while (0) |
| 238 | |
| 239 | /* Call the specified callback for all subdevs matching the condition. |
| 240 | If the callback returns an error other than 0 or -ENOIOCTLCMD, then |
| 241 | return with that error code. Note that you cannot add or delete a |
| 242 | subdev while walking the subdevs list. */ |
Guennadi Liakhovetski | 6c2d4dd | 2010-08-12 17:16:00 -0300 | [diff] [blame] | 243 | #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] | 244 | ({ \ |
Guennadi Liakhovetski | 6c2d4dd | 2010-08-12 17:16:00 -0300 | [diff] [blame] | 245 | long __err = 0; \ |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 246 | \ |
Guennadi Liakhovetski | 6c2d4dd | 2010-08-12 17:16:00 -0300 | [diff] [blame] | 247 | list_for_each_entry((sd), &(v4l2_dev)->subdevs, list) { \ |
| 248 | if ((cond) && (sd)->ops->o && (sd)->ops->o->f) \ |
| 249 | __err = (sd)->ops->o->f((sd) , ##args); \ |
| 250 | if (__err && __err != -ENOIOCTLCMD) \ |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 251 | break; \ |
| 252 | } \ |
Guennadi Liakhovetski | 6c2d4dd | 2010-08-12 17:16:00 -0300 | [diff] [blame] | 253 | (__err == -ENOIOCTLCMD) ? 0 : __err; \ |
| 254 | }) |
| 255 | |
| 256 | #define __v4l2_device_call_subdevs_until_err(v4l2_dev, cond, o, f, args...) \ |
| 257 | ({ \ |
| 258 | struct v4l2_subdev *__sd; \ |
| 259 | __v4l2_device_call_subdevs_until_err_p(v4l2_dev, __sd, cond, o, \ |
Guennadi Liakhovetski | c6c7354 | 2011-03-22 09:32:51 -0300 | [diff] [blame] | 260 | f , ##args); \ |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 261 | }) |
| 262 | |
| 263 | /* Call the specified callback for all subdevs matching grp_id (if 0, then |
| 264 | match them all). Ignore any errors. Note that you cannot add or delete |
| 265 | a subdev while walking the subdevs list. */ |
Guennadi Liakhovetski | 6c2d4dd | 2010-08-12 17:16:00 -0300 | [diff] [blame] | 266 | #define v4l2_device_call_all(v4l2_dev, grpid, o, f, args...) \ |
| 267 | do { \ |
| 268 | struct v4l2_subdev *__sd; \ |
| 269 | \ |
| 270 | __v4l2_device_call_subdevs_p(v4l2_dev, __sd, \ |
| 271 | !(grpid) || __sd->grp_id == (grpid), o, f , \ |
| 272 | ##args); \ |
| 273 | } while (0) |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 274 | |
| 275 | /* Call the specified callback for all subdevs matching grp_id (if 0, then |
| 276 | match them all). If the callback returns an error other than 0 or |
| 277 | -ENOIOCTLCMD, then return with that error code. Note that you cannot |
| 278 | add or delete a subdev while walking the subdevs list. */ |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 279 | #define v4l2_device_call_until_err(v4l2_dev, grpid, o, f, args...) \ |
Guennadi Liakhovetski | 6c2d4dd | 2010-08-12 17:16:00 -0300 | [diff] [blame] | 280 | ({ \ |
| 281 | struct v4l2_subdev *__sd; \ |
| 282 | __v4l2_device_call_subdevs_until_err_p(v4l2_dev, __sd, \ |
| 283 | !(grpid) || __sd->grp_id == (grpid), o, f , \ |
| 284 | ##args); \ |
| 285 | }) |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 286 | |
Hans Verkuil | 9665555 | 2016-04-03 17:44:16 -0300 | [diff] [blame] | 287 | /* |
| 288 | * Call the specified callback for all subdevs where grp_id & grpmsk != 0 |
| 289 | * (if grpmsk == `0, then match them all). Ignore any errors. Note that you |
| 290 | * cannot add or delete a subdev while walking the subdevs list. |
| 291 | */ |
| 292 | #define v4l2_device_mask_call_all(v4l2_dev, grpmsk, o, f, args...) \ |
| 293 | do { \ |
| 294 | struct v4l2_subdev *__sd; \ |
| 295 | \ |
| 296 | __v4l2_device_call_subdevs_p(v4l2_dev, __sd, \ |
| 297 | !(grpmsk) || (__sd->grp_id & (grpmsk)), o, f , \ |
| 298 | ##args); \ |
| 299 | } while (0) |
| 300 | |
| 301 | /* |
| 302 | * Call the specified callback for all subdevs where grp_id & grpmsk != 0 |
Mauro Carvalho Chehab | 65d7aba | 2016-08-30 19:16:25 -0300 | [diff] [blame] | 303 | * (if grpmsk == 0, then match them all). If the callback returns an error |
| 304 | * other than 0 or %-ENOIOCTLCMD, then return with that error code. Note that |
Hans Verkuil | 9665555 | 2016-04-03 17:44:16 -0300 | [diff] [blame] | 305 | * you cannot add or delete a subdev while walking the subdevs list. |
| 306 | */ |
| 307 | #define v4l2_device_mask_call_until_err(v4l2_dev, grpmsk, o, f, args...) \ |
| 308 | ({ \ |
| 309 | struct v4l2_subdev *__sd; \ |
| 310 | __v4l2_device_call_subdevs_until_err_p(v4l2_dev, __sd, \ |
| 311 | !(grpmsk) || (__sd->grp_id & (grpmsk)), o, f , \ |
| 312 | ##args); \ |
| 313 | }) |
| 314 | |
| 315 | /* |
| 316 | * Does any subdev with matching grpid (or all if grpid == 0) has the given |
| 317 | * op? |
| 318 | */ |
| 319 | #define v4l2_device_has_op(v4l2_dev, grpid, o, f) \ |
Hans Verkuil | 2180f92 | 2013-03-03 20:12:31 -0300 | [diff] [blame] | 320 | ({ \ |
| 321 | struct v4l2_subdev *__sd; \ |
| 322 | bool __result = false; \ |
| 323 | list_for_each_entry(__sd, &(v4l2_dev)->subdevs, list) { \ |
Hans Verkuil | 9665555 | 2016-04-03 17:44:16 -0300 | [diff] [blame] | 324 | if ((grpid) && __sd->grp_id != (grpid)) \ |
| 325 | continue; \ |
| 326 | if (v4l2_subdev_has_op(__sd, o, f)) { \ |
| 327 | __result = true; \ |
| 328 | break; \ |
| 329 | } \ |
| 330 | } \ |
| 331 | __result; \ |
| 332 | }) |
| 333 | |
| 334 | /* |
| 335 | * Does any subdev with matching grpmsk (or all if grpmsk == 0) has the given |
| 336 | * op? |
| 337 | */ |
| 338 | #define v4l2_device_mask_has_op(v4l2_dev, grpmsk, o, f) \ |
| 339 | ({ \ |
| 340 | struct v4l2_subdev *__sd; \ |
| 341 | bool __result = false; \ |
| 342 | list_for_each_entry(__sd, &(v4l2_dev)->subdevs, list) { \ |
| 343 | if ((grpmsk) && !(__sd->grp_id & (grpmsk))) \ |
| 344 | continue; \ |
Hans Verkuil | 2180f92 | 2013-03-03 20:12:31 -0300 | [diff] [blame] | 345 | if (v4l2_subdev_has_op(__sd, o, f)) { \ |
| 346 | __result = true; \ |
| 347 | break; \ |
| 348 | } \ |
| 349 | } \ |
| 350 | __result; \ |
| 351 | }) |
| 352 | |
Hans Verkuil | 2a1fcdf | 2008-11-29 21:36:58 -0300 | [diff] [blame] | 353 | #endif |