aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2016-07-21 08:27:37 -0400
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2016-07-23 07:04:21 -0400
commit2873f4db2ac28b83f076bd8283389b551e9be887 (patch)
tree9200f8b3ea78c0820020fb4a91fc7394432bf1ee
parentab4f5a4afc2d7a32285baba8ffab865beba60e13 (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.rst165
-rw-r--r--Documentation/media/kapi/v4l2-subdev.rst166
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
80driver sets the struct v4l2_device mdev field, sub-devices and video nodes 80driver sets the struct v4l2_device mdev field, sub-devices and video nodes
81will automatically appear in the media framework as entities. 81will automatically appear in the media framework as entities.
82 82
83V4L2 sub-device userspace API
84-----------------------------
85
86Beside exposing a kernel API through the v4l2_subdev_ops structure, V4L2
87sub-devices can also be controlled directly by userspace applications.
88
89Device nodes named v4l-subdevX can be created in /dev to access sub-devices
90directly. If a sub-device supports direct userspace configuration it must set
91the V4L2_SUBDEV_FL_HAS_DEVNODE flag before being registered.
92
93After registering sub-devices, the v4l2_device driver can create device nodes
94for all registered sub-devices marked with V4L2_SUBDEV_FL_HAS_DEVNODE by calling
95v4l2_device_register_subdev_nodes(). Those device nodes will be automatically
96removed when sub-devices are unregistered.
97
98The device node handles a subset of the V4L2 API.
99
100VIDIOC_QUERYCTRL
101VIDIOC_QUERYMENU
102VIDIOC_G_CTRL
103VIDIOC_S_CTRL
104VIDIOC_G_EXT_CTRLS
105VIDIOC_S_EXT_CTRLS
106VIDIOC_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
114VIDIOC_DQEVENT
115VIDIOC_SUBSCRIBE_EVENT
116VIDIOC_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
132Private 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
138I2C sub-device drivers
139----------------------
140
141Since these drivers are so common, special helper functions are available to
142ease the use of these drivers (v4l2-common.h).
143
144The recommended method of adding v4l2_subdev support to an I2C driver is to
145embed the v4l2_subdev struct into the state struct that is created for each
146I2C device instance. Very simple devices have no state struct and in that case
147you can just create a v4l2_subdev directly.
148
149A typical state struct would look like this (where 'chipname' is replaced by
150the 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
159Initialize the v4l2_subdev struct as follows:
160
161.. code-block:: none
162
163 v4l2_i2c_subdev_init(&state->sd, client, subdev_ops);
164
165This function will fill in all the fields of v4l2_subdev and ensure that the
166v4l2_subdev and i2c_client both point to one another.
167
168You should also add a helper inline function to go from a v4l2_subdev pointer
169to 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
178Use 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
184And 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
190Make sure to call v4l2_device_unregister_subdev(sd) when the remove() callback
191is called. This will unregister the sub-device from the bridge driver. It is
192safe to call this even if the sub-device was never registered.
193
194You need to do this because when the bridge driver destroys the i2c adapter
195the remove() callbacks are called of the i2c devices on that adapter.
196After that the corresponding v4l2_subdev structures are invalid, so they
197have to be unregistered first. Calling v4l2_device_unregister_subdev(sd)
198from the remove() callback ensures that this is always done correctly.
199
200
201The 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
208This loads the given module (can be NULL if no module needs to be loaded) and
209calls i2c_new_device() with the given i2c_adapter and chip/address arguments.
210If all goes well, then it registers the subdev with the v4l2_device.
211
212You can also use the last argument of v4l2_i2c_new_subdev() to pass an array
213of possible I2C addresses that it should probe. These probe addresses are
214only used if the previous argument is 0. A non-zero argument means that you
215know the exact i2c address so in that case no probing will take place.
216
217Both functions return NULL if something went wrong.
218
219Note that the chipid you pass to v4l2_i2c_new_subdev() is usually
220the 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.
222The use of chipid is something that needs to be looked at more closely at a
223later date. It differs between i2c drivers and as such can be confusing.
224To see which chip variants are supported you can look in the i2c driver code
225for the i2c_device_id table. This lists all the possibilities.
226
227There are two more helper functions:
228
229v4l2_i2c_new_subdev_cfg: this function adds new irq and platform_data
230arguments and has both 'addr' and 'probed_addrs' arguments: if addr is not
2310 then that will be used (non-probing variant), otherwise the probed_addrs
232are probed.
233
234For 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
241v4l2_i2c_new_subdev_board uses an i2c_board_info struct which is passed
242to the i2c driver and replaces the irq, platform_data and addr arguments.
243
244If the subdev supports the s_config core ops, then that op is called with
245the irq and platform_data arguments after the subdev was setup. The older
246v4l2_i2c_new_(probed\_)subdev functions will call s_config as well, but with
247irq set to 0 and platform_data set to NULL.
248 83
249struct video_device 84struct 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
262called. When a subdevice is removed from the system the .unbind() method is 262called. When a subdevice is removed from the system the .unbind() method is
263called. All three callbacks are optional. 263called. All three callbacks are optional.
264 264
265V4L2 sub-device userspace API
266-----------------------------
267
268Beside exposing a kernel API through the v4l2_subdev_ops structure, V4L2
269sub-devices can also be controlled directly by userspace applications.
270
271Device nodes named v4l-subdevX can be created in /dev to access sub-devices
272directly. If a sub-device supports direct userspace configuration it must set
273the V4L2_SUBDEV_FL_HAS_DEVNODE flag before being registered.
274
275After registering sub-devices, the v4l2_device driver can create device nodes
276for all registered sub-devices marked with V4L2_SUBDEV_FL_HAS_DEVNODE by calling
277v4l2_device_register_subdev_nodes(). Those device nodes will be automatically
278removed when sub-devices are unregistered.
279
280The device node handles a subset of the V4L2 API.
281
282VIDIOC_QUERYCTRL
283VIDIOC_QUERYMENU
284VIDIOC_G_CTRL
285VIDIOC_S_CTRL
286VIDIOC_G_EXT_CTRLS
287VIDIOC_S_EXT_CTRLS
288VIDIOC_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
296VIDIOC_DQEVENT
297VIDIOC_SUBSCRIBE_EVENT
298VIDIOC_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
314Private 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
320I2C sub-device drivers
321----------------------
322
323Since these drivers are so common, special helper functions are available to
324ease the use of these drivers (v4l2-common.h).
325
326The recommended method of adding v4l2_subdev support to an I2C driver is to
327embed the v4l2_subdev struct into the state struct that is created for each
328I2C device instance. Very simple devices have no state struct and in that case
329you can just create a v4l2_subdev directly.
330
331A typical state struct would look like this (where 'chipname' is replaced by
332the 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
341Initialize the v4l2_subdev struct as follows:
342
343.. code-block:: none
344
345 v4l2_i2c_subdev_init(&state->sd, client, subdev_ops);
346
347This function will fill in all the fields of v4l2_subdev and ensure that the
348v4l2_subdev and i2c_client both point to one another.
349
350You should also add a helper inline function to go from a v4l2_subdev pointer
351to 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
360Use 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
366And 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
372Make sure to call v4l2_device_unregister_subdev(sd) when the remove() callback
373is called. This will unregister the sub-device from the bridge driver. It is
374safe to call this even if the sub-device was never registered.
375
376You need to do this because when the bridge driver destroys the i2c adapter
377the remove() callbacks are called of the i2c devices on that adapter.
378After that the corresponding v4l2_subdev structures are invalid, so they
379have to be unregistered first. Calling v4l2_device_unregister_subdev(sd)
380from the remove() callback ensures that this is always done correctly.
381
382
383The 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
390This loads the given module (can be NULL if no module needs to be loaded) and
391calls i2c_new_device() with the given i2c_adapter and chip/address arguments.
392If all goes well, then it registers the subdev with the v4l2_device.
393
394You can also use the last argument of v4l2_i2c_new_subdev() to pass an array
395of possible I2C addresses that it should probe. These probe addresses are
396only used if the previous argument is 0. A non-zero argument means that you
397know the exact i2c address so in that case no probing will take place.
398
399Both functions return NULL if something went wrong.
400
401Note that the chipid you pass to v4l2_i2c_new_subdev() is usually
402the 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.
404The use of chipid is something that needs to be looked at more closely at a
405later date. It differs between i2c drivers and as such can be confusing.
406To see which chip variants are supported you can look in the i2c driver code
407for the i2c_device_id table. This lists all the possibilities.
408
409There are two more helper functions:
410
411v4l2_i2c_new_subdev_cfg: this function adds new irq and platform_data
412arguments and has both 'addr' and 'probed_addrs' arguments: if addr is not
4130 then that will be used (non-probing variant), otherwise the probed_addrs
414are probed.
415
416For 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
423v4l2_i2c_new_subdev_board uses an i2c_board_info struct which is passed
424to the i2c driver and replaces the irq, platform_data and addr arguments.
425
426If the subdev supports the s_config core ops, then that op is called with
427the irq and platform_data arguments after the subdev was setup. The older
428v4l2_i2c_new_(probed\_)subdev functions will call s_config as well, but with
429irq set to 0 and platform_data set to NULL.
430
265V4L2 subdev kAPI 431V4L2 subdev kAPI
266^^^^^^^^^^^^^^^^ 432^^^^^^^^^^^^^^^^
267 433