Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 1 | /* |
| 2 | * V4L2 asynchronous subdevice registration API |
| 3 | * |
| 4 | * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de> |
| 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 version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #ifndef V4L2_ASYNC_H |
| 12 | #define V4L2_ASYNC_H |
| 13 | |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/mutex.h> |
| 16 | |
| 17 | struct device; |
Sylwester Nawrocki | e7359f8 | 2013-07-19 12:21:29 -0300 | [diff] [blame] | 18 | struct device_node; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 19 | struct v4l2_device; |
| 20 | struct v4l2_subdev; |
| 21 | struct v4l2_async_notifier; |
| 22 | |
| 23 | /* A random max subdevice number, used to allocate an array on stack */ |
| 24 | #define V4L2_MAX_SUBDEVS 128U |
| 25 | |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 26 | /** |
| 27 | * enum v4l2_async_match_type - type of asynchronous subdevice logic to be used |
| 28 | * in order to identify a match |
| 29 | * |
| 30 | * @V4L2_ASYNC_MATCH_CUSTOM: Match will use the logic provided by &struct |
| 31 | * v4l2_async_subdev.match ops |
| 32 | * @V4L2_ASYNC_MATCH_DEVNAME: Match will use the device name |
| 33 | * @V4L2_ASYNC_MATCH_I2C: Match will check for I2C adapter ID and address |
| 34 | * @V4L2_ASYNC_MATCH_OF: Match will use OF node |
Sakari Ailus | ecdf0cf | 2016-08-16 06:54:59 -0300 | [diff] [blame^] | 35 | * @V4L2_ASYNC_MATCH_FWNODE: Match will use firmware node |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 36 | * |
| 37 | * This enum is used by the asyncrhronous sub-device logic to define the |
| 38 | * algorithm that will be used to match an asynchronous device. |
| 39 | */ |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 40 | enum v4l2_async_match_type { |
| 41 | V4L2_ASYNC_MATCH_CUSTOM, |
| 42 | V4L2_ASYNC_MATCH_DEVNAME, |
| 43 | V4L2_ASYNC_MATCH_I2C, |
Sylwester Nawrocki | e7359f8 | 2013-07-19 12:21:29 -0300 | [diff] [blame] | 44 | V4L2_ASYNC_MATCH_OF, |
Sakari Ailus | ecdf0cf | 2016-08-16 06:54:59 -0300 | [diff] [blame^] | 45 | V4L2_ASYNC_MATCH_FWNODE, |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge |
Mauro Carvalho Chehab | f8b2737 | 2015-08-22 05:16:24 -0300 | [diff] [blame] | 50 | * |
| 51 | * @match_type: type of match that will be used |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 52 | * @match: union of per-bus type matching data sets |
| 53 | * @list: used to link struct v4l2_async_subdev objects, waiting to be |
| 54 | * probed, to a notifier->waiting list |
| 55 | */ |
| 56 | struct v4l2_async_subdev { |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 57 | enum v4l2_async_match_type match_type; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 58 | union { |
| 59 | struct { |
Sylwester Nawrocki | e7359f8 | 2013-07-19 12:21:29 -0300 | [diff] [blame] | 60 | const struct device_node *node; |
| 61 | } of; |
| 62 | struct { |
Sakari Ailus | ecdf0cf | 2016-08-16 06:54:59 -0300 | [diff] [blame^] | 63 | struct fwnode_handle *fwnode; |
| 64 | } fwnode; |
| 65 | struct { |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 66 | const char *name; |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 67 | } device_name; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 68 | struct { |
| 69 | int adapter_id; |
| 70 | unsigned short address; |
| 71 | } i2c; |
| 72 | struct { |
| 73 | bool (*match)(struct device *, |
| 74 | struct v4l2_async_subdev *); |
| 75 | void *priv; |
| 76 | } custom; |
| 77 | } match; |
| 78 | |
| 79 | /* v4l2-async core private: not to be used by drivers */ |
| 80 | struct list_head list; |
| 81 | }; |
| 82 | |
| 83 | /** |
Mauro Carvalho Chehab | f8b2737 | 2015-08-22 05:16:24 -0300 | [diff] [blame] | 84 | * struct v4l2_async_notifier - v4l2_device notifier data |
| 85 | * |
| 86 | * @num_subdevs: number of subdevices |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame] | 87 | * @subdevs: array of pointers to subdevice descriptors |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 88 | * @v4l2_dev: pointer to struct v4l2_device |
| 89 | * @waiting: list of struct v4l2_async_subdev, waiting for their drivers |
Sylwester Nawrocki | b426b3a | 2013-07-22 08:01:33 -0300 | [diff] [blame] | 90 | * @done: list of struct v4l2_subdev, already probed |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 91 | * @list: member in a global list of notifiers |
| 92 | * @bound: a subdevice driver has successfully probed one of subdevices |
| 93 | * @complete: all subdevices have been probed successfully |
| 94 | * @unbind: a subdevice is leaving |
| 95 | */ |
| 96 | struct v4l2_async_notifier { |
| 97 | unsigned int num_subdevs; |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame] | 98 | struct v4l2_async_subdev **subdevs; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 99 | struct v4l2_device *v4l2_dev; |
| 100 | struct list_head waiting; |
| 101 | struct list_head done; |
| 102 | struct list_head list; |
| 103 | int (*bound)(struct v4l2_async_notifier *notifier, |
| 104 | struct v4l2_subdev *subdev, |
| 105 | struct v4l2_async_subdev *asd); |
| 106 | int (*complete)(struct v4l2_async_notifier *notifier); |
| 107 | void (*unbind)(struct v4l2_async_notifier *notifier, |
| 108 | struct v4l2_subdev *subdev, |
| 109 | struct v4l2_async_subdev *asd); |
| 110 | }; |
| 111 | |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 112 | /** |
| 113 | * v4l2_async_notifier_register - registers a subdevice asynchronous notifier |
| 114 | * |
| 115 | * @v4l2_dev: pointer to &struct v4l2_device |
| 116 | * @notifier: pointer to &struct v4l2_async_notifier |
| 117 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 118 | int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev, |
| 119 | struct v4l2_async_notifier *notifier); |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous notifier |
| 123 | * |
| 124 | * @notifier: pointer to &struct v4l2_async_notifier |
| 125 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 126 | void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier); |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * v4l2_async_register_subdev - registers a sub-device to the asynchronous |
| 130 | * subdevice framework |
| 131 | * |
| 132 | * @sd: pointer to &struct v4l2_subdev |
| 133 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 134 | int v4l2_async_register_subdev(struct v4l2_subdev *sd); |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 135 | |
| 136 | /** |
| 137 | * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous |
| 138 | * subdevice framework |
| 139 | * |
| 140 | * @sd: pointer to &struct v4l2_subdev |
| 141 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 142 | void v4l2_async_unregister_subdev(struct v4l2_subdev *sd); |
| 143 | #endif |