diff options
author | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-07-21 08:27:37 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-07-23 07:04:21 -0400 |
commit | 2873f4db2ac28b83f076bd8283389b551e9be887 (patch) | |
tree | 9200f8b3ea78c0820020fb4a91fc7394432bf1ee | |
parent | ab4f5a4afc2d7a32285baba8ffab865beba60e13 (diff) |
[media] v4l2-subdev.rst: add two sections from v4l2-framework.rst
There are two additional subdev-specific sections at the
v4l2-framework file. Move them to the subdev chapter, in order
to better organize the book.
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r-- | Documentation/media/kapi/v4l2-framework.rst | 165 | ||||
-rw-r--r-- | Documentation/media/kapi/v4l2-subdev.rst | 166 |
2 files changed, 166 insertions, 165 deletions
diff --git a/Documentation/media/kapi/v4l2-framework.rst b/Documentation/media/kapi/v4l2-framework.rst index a7f64b38af5c..de341fc5b235 100644 --- a/Documentation/media/kapi/v4l2-framework.rst +++ b/Documentation/media/kapi/v4l2-framework.rst | |||
@@ -80,171 +80,6 @@ The V4L2 framework also optionally integrates with the media framework. If a | |||
80 | driver sets the struct v4l2_device mdev field, sub-devices and video nodes | 80 | driver sets the struct v4l2_device mdev field, sub-devices and video nodes |
81 | will automatically appear in the media framework as entities. | 81 | will automatically appear in the media framework as entities. |
82 | 82 | ||
83 | V4L2 sub-device userspace API | ||
84 | ----------------------------- | ||
85 | |||
86 | Beside exposing a kernel API through the v4l2_subdev_ops structure, V4L2 | ||
87 | sub-devices can also be controlled directly by userspace applications. | ||
88 | |||
89 | Device nodes named v4l-subdevX can be created in /dev to access sub-devices | ||
90 | directly. If a sub-device supports direct userspace configuration it must set | ||
91 | the V4L2_SUBDEV_FL_HAS_DEVNODE flag before being registered. | ||
92 | |||
93 | After registering sub-devices, the v4l2_device driver can create device nodes | ||
94 | for all registered sub-devices marked with V4L2_SUBDEV_FL_HAS_DEVNODE by calling | ||
95 | v4l2_device_register_subdev_nodes(). Those device nodes will be automatically | ||
96 | removed when sub-devices are unregistered. | ||
97 | |||
98 | The device node handles a subset of the V4L2 API. | ||
99 | |||
100 | VIDIOC_QUERYCTRL | ||
101 | VIDIOC_QUERYMENU | ||
102 | VIDIOC_G_CTRL | ||
103 | VIDIOC_S_CTRL | ||
104 | VIDIOC_G_EXT_CTRLS | ||
105 | VIDIOC_S_EXT_CTRLS | ||
106 | VIDIOC_TRY_EXT_CTRLS | ||
107 | |||
108 | The controls ioctls are identical to the ones defined in V4L2. They | ||
109 | behave identically, with the only exception that they deal only with | ||
110 | controls implemented in the sub-device. Depending on the driver, those | ||
111 | controls can be also be accessed through one (or several) V4L2 device | ||
112 | nodes. | ||
113 | |||
114 | VIDIOC_DQEVENT | ||
115 | VIDIOC_SUBSCRIBE_EVENT | ||
116 | VIDIOC_UNSUBSCRIBE_EVENT | ||
117 | |||
118 | The events ioctls are identical to the ones defined in V4L2. They | ||
119 | behave identically, with the only exception that they deal only with | ||
120 | events generated by the sub-device. Depending on the driver, those | ||
121 | events can also be reported by one (or several) V4L2 device nodes. | ||
122 | |||
123 | Sub-device drivers that want to use events need to set the | ||
124 | V4L2_SUBDEV_USES_EVENTS v4l2_subdev::flags and initialize | ||
125 | v4l2_subdev::nevents to events queue depth before registering the | ||
126 | sub-device. After registration events can be queued as usual on the | ||
127 | v4l2_subdev::devnode device node. | ||
128 | |||
129 | To properly support events, the poll() file operation is also | ||
130 | implemented. | ||
131 | |||
132 | Private ioctls | ||
133 | |||
134 | All ioctls not in the above list are passed directly to the sub-device | ||
135 | driver through the core::ioctl operation. | ||
136 | |||
137 | |||
138 | I2C sub-device drivers | ||
139 | ---------------------- | ||
140 | |||
141 | Since these drivers are so common, special helper functions are available to | ||
142 | ease the use of these drivers (v4l2-common.h). | ||
143 | |||
144 | The recommended method of adding v4l2_subdev support to an I2C driver is to | ||
145 | embed the v4l2_subdev struct into the state struct that is created for each | ||
146 | I2C device instance. Very simple devices have no state struct and in that case | ||
147 | you can just create a v4l2_subdev directly. | ||
148 | |||
149 | A typical state struct would look like this (where 'chipname' is replaced by | ||
150 | the name of the chip): | ||
151 | |||
152 | .. code-block:: none | ||
153 | |||
154 | struct chipname_state { | ||
155 | struct v4l2_subdev sd; | ||
156 | ... /* additional state fields */ | ||
157 | }; | ||
158 | |||
159 | Initialize the v4l2_subdev struct as follows: | ||
160 | |||
161 | .. code-block:: none | ||
162 | |||
163 | v4l2_i2c_subdev_init(&state->sd, client, subdev_ops); | ||
164 | |||
165 | This function will fill in all the fields of v4l2_subdev and ensure that the | ||
166 | v4l2_subdev and i2c_client both point to one another. | ||
167 | |||
168 | You should also add a helper inline function to go from a v4l2_subdev pointer | ||
169 | to a chipname_state struct: | ||
170 | |||
171 | .. code-block:: none | ||
172 | |||
173 | static inline struct chipname_state *to_state(struct v4l2_subdev *sd) | ||
174 | { | ||
175 | return container_of(sd, struct chipname_state, sd); | ||
176 | } | ||
177 | |||
178 | Use this to go from the v4l2_subdev struct to the i2c_client struct: | ||
179 | |||
180 | .. code-block:: none | ||
181 | |||
182 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
183 | |||
184 | And this to go from an i2c_client to a v4l2_subdev struct: | ||
185 | |||
186 | .. code-block:: none | ||
187 | |||
188 | struct v4l2_subdev *sd = i2c_get_clientdata(client); | ||
189 | |||
190 | Make sure to call v4l2_device_unregister_subdev(sd) when the remove() callback | ||
191 | is called. This will unregister the sub-device from the bridge driver. It is | ||
192 | safe to call this even if the sub-device was never registered. | ||
193 | |||
194 | You need to do this because when the bridge driver destroys the i2c adapter | ||
195 | the remove() callbacks are called of the i2c devices on that adapter. | ||
196 | After that the corresponding v4l2_subdev structures are invalid, so they | ||
197 | have to be unregistered first. Calling v4l2_device_unregister_subdev(sd) | ||
198 | from the remove() callback ensures that this is always done correctly. | ||
199 | |||
200 | |||
201 | The bridge driver also has some helper functions it can use: | ||
202 | |||
203 | .. code-block:: none | ||
204 | |||
205 | struct v4l2_subdev *sd = v4l2_i2c_new_subdev(v4l2_dev, adapter, | ||
206 | "module_foo", "chipid", 0x36, NULL); | ||
207 | |||
208 | This loads the given module (can be NULL if no module needs to be loaded) and | ||
209 | calls i2c_new_device() with the given i2c_adapter and chip/address arguments. | ||
210 | If all goes well, then it registers the subdev with the v4l2_device. | ||
211 | |||
212 | You can also use the last argument of v4l2_i2c_new_subdev() to pass an array | ||
213 | of possible I2C addresses that it should probe. These probe addresses are | ||
214 | only used if the previous argument is 0. A non-zero argument means that you | ||
215 | know the exact i2c address so in that case no probing will take place. | ||
216 | |||
217 | Both functions return NULL if something went wrong. | ||
218 | |||
219 | Note that the chipid you pass to v4l2_i2c_new_subdev() is usually | ||
220 | the same as the module name. It allows you to specify a chip variant, e.g. | ||
221 | "saa7114" or "saa7115". In general though the i2c driver autodetects this. | ||
222 | The use of chipid is something that needs to be looked at more closely at a | ||
223 | later date. It differs between i2c drivers and as such can be confusing. | ||
224 | To see which chip variants are supported you can look in the i2c driver code | ||
225 | for the i2c_device_id table. This lists all the possibilities. | ||
226 | |||
227 | There are two more helper functions: | ||
228 | |||
229 | v4l2_i2c_new_subdev_cfg: this function adds new irq and platform_data | ||
230 | arguments and has both 'addr' and 'probed_addrs' arguments: if addr is not | ||
231 | 0 then that will be used (non-probing variant), otherwise the probed_addrs | ||
232 | are probed. | ||
233 | |||
234 | For example: this will probe for address 0x10: | ||
235 | |||
236 | .. code-block:: none | ||
237 | |||
238 | struct v4l2_subdev *sd = v4l2_i2c_new_subdev_cfg(v4l2_dev, adapter, | ||
239 | "module_foo", "chipid", 0, NULL, 0, I2C_ADDRS(0x10)); | ||
240 | |||
241 | v4l2_i2c_new_subdev_board uses an i2c_board_info struct which is passed | ||
242 | to the i2c driver and replaces the irq, platform_data and addr arguments. | ||
243 | |||
244 | If the subdev supports the s_config core ops, then that op is called with | ||
245 | the irq and platform_data arguments after the subdev was setup. The older | ||
246 | v4l2_i2c_new_(probed\_)subdev functions will call s_config as well, but with | ||
247 | irq set to 0 and platform_data set to NULL. | ||
248 | 83 | ||
249 | struct video_device | 84 | struct video_device |
250 | ------------------- | 85 | ------------------- |
diff --git a/Documentation/media/kapi/v4l2-subdev.rst b/Documentation/media/kapi/v4l2-subdev.rst index 829016940597..2845a749409c 100644 --- a/Documentation/media/kapi/v4l2-subdev.rst +++ b/Documentation/media/kapi/v4l2-subdev.rst | |||
@@ -262,6 +262,172 @@ is called. After all subdevices have been located the .complete() callback is | |||
262 | called. When a subdevice is removed from the system the .unbind() method is | 262 | called. When a subdevice is removed from the system the .unbind() method is |
263 | called. All three callbacks are optional. | 263 | called. All three callbacks are optional. |
264 | 264 | ||
265 | V4L2 sub-device userspace API | ||
266 | ----------------------------- | ||
267 | |||
268 | Beside exposing a kernel API through the v4l2_subdev_ops structure, V4L2 | ||
269 | sub-devices can also be controlled directly by userspace applications. | ||
270 | |||
271 | Device nodes named v4l-subdevX can be created in /dev to access sub-devices | ||
272 | directly. If a sub-device supports direct userspace configuration it must set | ||
273 | the V4L2_SUBDEV_FL_HAS_DEVNODE flag before being registered. | ||
274 | |||
275 | After registering sub-devices, the v4l2_device driver can create device nodes | ||
276 | for all registered sub-devices marked with V4L2_SUBDEV_FL_HAS_DEVNODE by calling | ||
277 | v4l2_device_register_subdev_nodes(). Those device nodes will be automatically | ||
278 | removed when sub-devices are unregistered. | ||
279 | |||
280 | The device node handles a subset of the V4L2 API. | ||
281 | |||
282 | VIDIOC_QUERYCTRL | ||
283 | VIDIOC_QUERYMENU | ||
284 | VIDIOC_G_CTRL | ||
285 | VIDIOC_S_CTRL | ||
286 | VIDIOC_G_EXT_CTRLS | ||
287 | VIDIOC_S_EXT_CTRLS | ||
288 | VIDIOC_TRY_EXT_CTRLS | ||
289 | |||
290 | The controls ioctls are identical to the ones defined in V4L2. They | ||
291 | behave identically, with the only exception that they deal only with | ||
292 | controls implemented in the sub-device. Depending on the driver, those | ||
293 | controls can be also be accessed through one (or several) V4L2 device | ||
294 | nodes. | ||
295 | |||
296 | VIDIOC_DQEVENT | ||
297 | VIDIOC_SUBSCRIBE_EVENT | ||
298 | VIDIOC_UNSUBSCRIBE_EVENT | ||
299 | |||
300 | The events ioctls are identical to the ones defined in V4L2. They | ||
301 | behave identically, with the only exception that they deal only with | ||
302 | events generated by the sub-device. Depending on the driver, those | ||
303 | events can also be reported by one (or several) V4L2 device nodes. | ||
304 | |||
305 | Sub-device drivers that want to use events need to set the | ||
306 | V4L2_SUBDEV_USES_EVENTS v4l2_subdev::flags and initialize | ||
307 | v4l2_subdev::nevents to events queue depth before registering the | ||
308 | sub-device. After registration events can be queued as usual on the | ||
309 | v4l2_subdev::devnode device node. | ||
310 | |||
311 | To properly support events, the poll() file operation is also | ||
312 | implemented. | ||
313 | |||
314 | Private ioctls | ||
315 | |||
316 | All ioctls not in the above list are passed directly to the sub-device | ||
317 | driver through the core::ioctl operation. | ||
318 | |||
319 | |||
320 | I2C sub-device drivers | ||
321 | ---------------------- | ||
322 | |||
323 | Since these drivers are so common, special helper functions are available to | ||
324 | ease the use of these drivers (v4l2-common.h). | ||
325 | |||
326 | The recommended method of adding v4l2_subdev support to an I2C driver is to | ||
327 | embed the v4l2_subdev struct into the state struct that is created for each | ||
328 | I2C device instance. Very simple devices have no state struct and in that case | ||
329 | you can just create a v4l2_subdev directly. | ||
330 | |||
331 | A typical state struct would look like this (where 'chipname' is replaced by | ||
332 | the name of the chip): | ||
333 | |||
334 | .. code-block:: none | ||
335 | |||
336 | struct chipname_state { | ||
337 | struct v4l2_subdev sd; | ||
338 | ... /* additional state fields */ | ||
339 | }; | ||
340 | |||
341 | Initialize the v4l2_subdev struct as follows: | ||
342 | |||
343 | .. code-block:: none | ||
344 | |||
345 | v4l2_i2c_subdev_init(&state->sd, client, subdev_ops); | ||
346 | |||
347 | This function will fill in all the fields of v4l2_subdev and ensure that the | ||
348 | v4l2_subdev and i2c_client both point to one another. | ||
349 | |||
350 | You should also add a helper inline function to go from a v4l2_subdev pointer | ||
351 | to a chipname_state struct: | ||
352 | |||
353 | .. code-block:: none | ||
354 | |||
355 | static inline struct chipname_state *to_state(struct v4l2_subdev *sd) | ||
356 | { | ||
357 | return container_of(sd, struct chipname_state, sd); | ||
358 | } | ||
359 | |||
360 | Use this to go from the v4l2_subdev struct to the i2c_client struct: | ||
361 | |||
362 | .. code-block:: none | ||
363 | |||
364 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
365 | |||
366 | And this to go from an i2c_client to a v4l2_subdev struct: | ||
367 | |||
368 | .. code-block:: none | ||
369 | |||
370 | struct v4l2_subdev *sd = i2c_get_clientdata(client); | ||
371 | |||
372 | Make sure to call v4l2_device_unregister_subdev(sd) when the remove() callback | ||
373 | is called. This will unregister the sub-device from the bridge driver. It is | ||
374 | safe to call this even if the sub-device was never registered. | ||
375 | |||
376 | You need to do this because when the bridge driver destroys the i2c adapter | ||
377 | the remove() callbacks are called of the i2c devices on that adapter. | ||
378 | After that the corresponding v4l2_subdev structures are invalid, so they | ||
379 | have to be unregistered first. Calling v4l2_device_unregister_subdev(sd) | ||
380 | from the remove() callback ensures that this is always done correctly. | ||
381 | |||
382 | |||
383 | The bridge driver also has some helper functions it can use: | ||
384 | |||
385 | .. code-block:: none | ||
386 | |||
387 | struct v4l2_subdev *sd = v4l2_i2c_new_subdev(v4l2_dev, adapter, | ||
388 | "module_foo", "chipid", 0x36, NULL); | ||
389 | |||
390 | This loads the given module (can be NULL if no module needs to be loaded) and | ||
391 | calls i2c_new_device() with the given i2c_adapter and chip/address arguments. | ||
392 | If all goes well, then it registers the subdev with the v4l2_device. | ||
393 | |||
394 | You can also use the last argument of v4l2_i2c_new_subdev() to pass an array | ||
395 | of possible I2C addresses that it should probe. These probe addresses are | ||
396 | only used if the previous argument is 0. A non-zero argument means that you | ||
397 | know the exact i2c address so in that case no probing will take place. | ||
398 | |||
399 | Both functions return NULL if something went wrong. | ||
400 | |||
401 | Note that the chipid you pass to v4l2_i2c_new_subdev() is usually | ||
402 | the same as the module name. It allows you to specify a chip variant, e.g. | ||
403 | "saa7114" or "saa7115". In general though the i2c driver autodetects this. | ||
404 | The use of chipid is something that needs to be looked at more closely at a | ||
405 | later date. It differs between i2c drivers and as such can be confusing. | ||
406 | To see which chip variants are supported you can look in the i2c driver code | ||
407 | for the i2c_device_id table. This lists all the possibilities. | ||
408 | |||
409 | There are two more helper functions: | ||
410 | |||
411 | v4l2_i2c_new_subdev_cfg: this function adds new irq and platform_data | ||
412 | arguments and has both 'addr' and 'probed_addrs' arguments: if addr is not | ||
413 | 0 then that will be used (non-probing variant), otherwise the probed_addrs | ||
414 | are probed. | ||
415 | |||
416 | For example: this will probe for address 0x10: | ||
417 | |||
418 | .. code-block:: none | ||
419 | |||
420 | struct v4l2_subdev *sd = v4l2_i2c_new_subdev_cfg(v4l2_dev, adapter, | ||
421 | "module_foo", "chipid", 0, NULL, 0, I2C_ADDRS(0x10)); | ||
422 | |||
423 | v4l2_i2c_new_subdev_board uses an i2c_board_info struct which is passed | ||
424 | to the i2c driver and replaces the irq, platform_data and addr arguments. | ||
425 | |||
426 | If the subdev supports the s_config core ops, then that op is called with | ||
427 | the irq and platform_data arguments after the subdev was setup. The older | ||
428 | v4l2_i2c_new_(probed\_)subdev functions will call s_config as well, but with | ||
429 | irq set to 0 and platform_data set to NULL. | ||
430 | |||
265 | V4L2 subdev kAPI | 431 | V4L2 subdev kAPI |
266 | ^^^^^^^^^^^^^^^^ | 432 | ^^^^^^^^^^^^^^^^ |
267 | 433 | ||