Commit | Line | Data |
---|---|---|
e9e31049 GL |
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; | |
e7359f8e | 18 | struct device_node; |
e9e31049 GL |
19 | struct v4l2_device; |
20 | struct v4l2_subdev; | |
b6ee3f0d | 21 | struct v4l2_async_notifier; |
e9e31049 GL |
22 | |
23 | /* A random max subdevice number, used to allocate an array on stack */ | |
24 | #define V4L2_MAX_SUBDEVS 128U | |
25 | ||
ab4f5a4a MCC |
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 | |
ecdf0cfe | 34 | * @V4L2_ASYNC_MATCH_FWNODE: Match will use firmware node |
ab4f5a4a MCC |
35 | * |
36 | * This enum is used by the asyncrhronous sub-device logic to define the | |
37 | * algorithm that will be used to match an asynchronous device. | |
38 | */ | |
cfca7644 SN |
39 | enum v4l2_async_match_type { |
40 | V4L2_ASYNC_MATCH_CUSTOM, | |
41 | V4L2_ASYNC_MATCH_DEVNAME, | |
42 | V4L2_ASYNC_MATCH_I2C, | |
ecdf0cfe | 43 | V4L2_ASYNC_MATCH_FWNODE, |
e9e31049 GL |
44 | }; |
45 | ||
46 | /** | |
47 | * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge | |
f8b27377 MCC |
48 | * |
49 | * @match_type: type of match that will be used | |
e9e31049 GL |
50 | * @match: union of per-bus type matching data sets |
51 | * @list: used to link struct v4l2_async_subdev objects, waiting to be | |
52 | * probed, to a notifier->waiting list | |
9ca46531 SA |
53 | * |
54 | * When this struct is used as a member in a driver specific struct, | |
55 | * the driver specific struct shall contain the &struct | |
56 | * v4l2_async_subdev as its first member. | |
e9e31049 GL |
57 | */ |
58 | struct v4l2_async_subdev { | |
cfca7644 | 59 | enum v4l2_async_match_type match_type; |
e9e31049 | 60 | union { |
ecdf0cfe SA |
61 | struct { |
62 | struct fwnode_handle *fwnode; | |
63 | } fwnode; | |
e9e31049 GL |
64 | struct { |
65 | const char *name; | |
cfca7644 | 66 | } device_name; |
e9e31049 GL |
67 | struct { |
68 | int adapter_id; | |
69 | unsigned short address; | |
70 | } i2c; | |
71 | struct { | |
72 | bool (*match)(struct device *, | |
73 | struct v4l2_async_subdev *); | |
74 | void *priv; | |
75 | } custom; | |
76 | } match; | |
77 | ||
78 | /* v4l2-async core private: not to be used by drivers */ | |
79 | struct list_head list; | |
80 | }; | |
81 | ||
b6ee3f0d LP |
82 | /** |
83 | * struct v4l2_async_notifier_operations - Asynchronous V4L2 notifier operations | |
84 | * @bound: a subdevice driver has successfully probed one of the subdevices | |
2cab00bb SA |
85 | * @complete: All subdevices have been probed successfully. The complete |
86 | * callback is only executed for the root notifier. | |
b6ee3f0d LP |
87 | * @unbind: a subdevice is leaving |
88 | */ | |
89 | struct v4l2_async_notifier_operations { | |
90 | int (*bound)(struct v4l2_async_notifier *notifier, | |
91 | struct v4l2_subdev *subdev, | |
92 | struct v4l2_async_subdev *asd); | |
93 | int (*complete)(struct v4l2_async_notifier *notifier); | |
94 | void (*unbind)(struct v4l2_async_notifier *notifier, | |
95 | struct v4l2_subdev *subdev, | |
96 | struct v4l2_async_subdev *asd); | |
97 | }; | |
98 | ||
e9e31049 | 99 | /** |
f8b27377 MCC |
100 | * struct v4l2_async_notifier - v4l2_device notifier data |
101 | * | |
b6ee3f0d | 102 | * @ops: notifier operations |
9ca46531 SA |
103 | * @num_subdevs: number of subdevices used in the subdevs array |
104 | * @max_subdevs: number of subdevices allocated in the subdevs array | |
e8419d08 | 105 | * @subdevs: array of pointers to subdevice descriptors |
2cab00bb SA |
106 | * @v4l2_dev: v4l2_device of the root notifier, NULL otherwise |
107 | * @sd: sub-device that registered the notifier, NULL otherwise | |
108 | * @parent: parent notifier | |
e9e31049 | 109 | * @waiting: list of struct v4l2_async_subdev, waiting for their drivers |
b426b3a6 | 110 | * @done: list of struct v4l2_subdev, already probed |
e9e31049 | 111 | * @list: member in a global list of notifiers |
e9e31049 GL |
112 | */ |
113 | struct v4l2_async_notifier { | |
b6ee3f0d | 114 | const struct v4l2_async_notifier_operations *ops; |
e9e31049 | 115 | unsigned int num_subdevs; |
9ca46531 | 116 | unsigned int max_subdevs; |
e8419d08 | 117 | struct v4l2_async_subdev **subdevs; |
e9e31049 | 118 | struct v4l2_device *v4l2_dev; |
2cab00bb SA |
119 | struct v4l2_subdev *sd; |
120 | struct v4l2_async_notifier *parent; | |
e9e31049 GL |
121 | struct list_head waiting; |
122 | struct list_head done; | |
123 | struct list_head list; | |
e9e31049 GL |
124 | }; |
125 | ||
ab4f5a4a MCC |
126 | /** |
127 | * v4l2_async_notifier_register - registers a subdevice asynchronous notifier | |
128 | * | |
129 | * @v4l2_dev: pointer to &struct v4l2_device | |
130 | * @notifier: pointer to &struct v4l2_async_notifier | |
131 | */ | |
e9e31049 GL |
132 | int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev, |
133 | struct v4l2_async_notifier *notifier); | |
ab4f5a4a | 134 | |
2cab00bb SA |
135 | /** |
136 | * v4l2_async_subdev_notifier_register - registers a subdevice asynchronous | |
137 | * notifier for a sub-device | |
138 | * | |
139 | * @sd: pointer to &struct v4l2_subdev | |
140 | * @notifier: pointer to &struct v4l2_async_notifier | |
141 | */ | |
142 | int v4l2_async_subdev_notifier_register(struct v4l2_subdev *sd, | |
143 | struct v4l2_async_notifier *notifier); | |
144 | ||
ab4f5a4a MCC |
145 | /** |
146 | * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous notifier | |
147 | * | |
148 | * @notifier: pointer to &struct v4l2_async_notifier | |
149 | */ | |
e9e31049 | 150 | void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier); |
ab4f5a4a | 151 | |
9ca46531 SA |
152 | /** |
153 | * v4l2_async_notifier_cleanup - clean up notifier resources | |
154 | * @notifier: the notifier the resources of which are to be cleaned up | |
155 | * | |
156 | * Release memory resources related to a notifier, including the async | |
157 | * sub-devices allocated for the purposes of the notifier but not the notifier | |
158 | * itself. The user is responsible for calling this function to clean up the | |
7a9ec808 SA |
159 | * notifier after calling @v4l2_async_notifier_parse_fwnode_endpoints or |
160 | * @v4l2_fwnode_reference_parse_sensor_common. | |
9ca46531 SA |
161 | * |
162 | * There is no harm from calling v4l2_async_notifier_cleanup in other | |
163 | * cases as long as its memory has been zeroed after it has been | |
164 | * allocated. | |
165 | */ | |
166 | void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier); | |
167 | ||
ab4f5a4a MCC |
168 | /** |
169 | * v4l2_async_register_subdev - registers a sub-device to the asynchronous | |
170 | * subdevice framework | |
171 | * | |
172 | * @sd: pointer to &struct v4l2_subdev | |
173 | */ | |
e9e31049 | 174 | int v4l2_async_register_subdev(struct v4l2_subdev *sd); |
ab4f5a4a | 175 | |
aef69d54 SA |
176 | /** |
177 | * v4l2_async_register_subdev_sensor_common - registers a sensor sub-device to | |
178 | * the asynchronous sub-device | |
179 | * framework and parse set up common | |
180 | * sensor related devices | |
181 | * | |
182 | * @sd: pointer to struct &v4l2_subdev | |
183 | * | |
184 | * This function is just like v4l2_async_register_subdev() with the exception | |
185 | * that calling it will also parse firmware interfaces for remote references | |
186 | * using v4l2_async_notifier_parse_fwnode_sensor_common() and registers the | |
187 | * async sub-devices. The sub-device is similarly unregistered by calling | |
188 | * v4l2_async_unregister_subdev(). | |
189 | * | |
190 | * While registered, the subdev module is marked as in-use. | |
191 | * | |
192 | * An error is returned if the module is no longer loaded on any attempts | |
193 | * to register it. | |
194 | */ | |
195 | int __must_check v4l2_async_register_subdev_sensor_common( | |
196 | struct v4l2_subdev *sd); | |
197 | ||
ab4f5a4a MCC |
198 | /** |
199 | * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous | |
200 | * subdevice framework | |
201 | * | |
202 | * @sd: pointer to &struct v4l2_subdev | |
203 | */ | |
e9e31049 GL |
204 | void v4l2_async_unregister_subdev(struct v4l2_subdev *sd); |
205 | #endif |