aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/video4linux
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-03-24 12:50:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-24 12:50:13 -0400
commit76d21c563569bcea6bc67d65cc2c460cff643058 (patch)
tree4dd2c9846ea7838077099646418978e354df1680 /Documentation/video4linux
parent6e50e9f9f4a8277b4d76de417ca77cf3921bd524 (diff)
parent472af2b05bdefcaee7e754e22cbf131110017ad6 (diff)
Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6
* 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6: (442 commits) [media] videobuf2-dma-contig: make cookie() return a pointer to dma_addr_t [media] sh_mobile_ceu_camera: Do not call vb2's mem_ops directly [media] V4L: soc-camera: explicitly require V4L2_BUF_TYPE_VIDEO_CAPTURE [media] v4l: soc-camera: Store negotiated buffer settings [media] rc: interim support for 32-bit NEC-ish scancodes [media] mceusb: topseed 0x0011 needs gen3 init for tx to work [media] lirc_zilog: error out if buffer read bytes != chunk size [media] lirc: silence some compile warnings [media] hdpvr: use same polling interval as other OS [media] ir-kbd-i2c: pass device code w/key in hauppauge case [media] rc/keymaps: Remove the obsolete rc-rc5-tv keymap [media] remove the old RC_MAP_HAUPPAUGE_NEW RC map [media] rc/keymaps: Rename Hauppauge table as rc-hauppauge [media] rc-rc5-hauppauge-new: Fix Hauppauge Grey mapping [media] rc-rc5-hauppauge-new: Add support for the old Black RC [media] rc-rc5-hauppauge-new: Add the old control to the table [media] rc-winfast: Fix the keycode tables [media] a800: Fix a few wrong IR key assignments [media] opera1: Use multimedia keys instead of an app-specific mapping [media] dw2102: Use multimedia keys instead of an app-specific mapping ... Fix up trivial conflicts (remove/modify and some real conflicts) in: arch/arm/mach-omap2/devices.c drivers/staging/Kconfig drivers/staging/Makefile drivers/staging/dabusb/dabusb.c drivers/staging/dabusb/dabusb.h drivers/staging/easycap/easycap_ioctl.c drivers/staging/usbvideo/usbvideo.c drivers/staging/usbvideo/vicam.c
Diffstat (limited to 'Documentation/video4linux')
-rw-r--r--Documentation/video4linux/README.ivtv3
-rw-r--r--Documentation/video4linux/gspca.txt10
-rw-r--r--Documentation/video4linux/omap3isp.txt278
-rw-r--r--Documentation/video4linux/v4l2-framework.txt267
4 files changed, 518 insertions, 40 deletions
diff --git a/Documentation/video4linux/README.ivtv b/Documentation/video4linux/README.ivtv
index 42b06686eb78..2579b5b709ed 100644
--- a/Documentation/video4linux/README.ivtv
+++ b/Documentation/video4linux/README.ivtv
@@ -36,8 +36,7 @@ Additional features for the PVR-350 (CX23415 based):
36 * Provides comprehensive OSD (On Screen Display: ie. graphics overlaying the 36 * Provides comprehensive OSD (On Screen Display: ie. graphics overlaying the
37 video signal) 37 video signal)
38 * Provides a framebuffer (allowing X applications to appear on the video 38 * Provides a framebuffer (allowing X applications to appear on the video
39 device) (this framebuffer is not yet part of the kernel. In the meantime it 39 device)
40 is available from www.ivtvdriver.org).
41 * Supports raw YUV output. 40 * Supports raw YUV output.
42 41
43IMPORTANT: In case of problems first read this page: 42IMPORTANT: In case of problems first read this page:
diff --git a/Documentation/video4linux/gspca.txt b/Documentation/video4linux/gspca.txt
index 261776e0c5e1..5c542e60f51d 100644
--- a/Documentation/video4linux/gspca.txt
+++ b/Documentation/video4linux/gspca.txt
@@ -103,6 +103,7 @@ spca561 046d:092d Logitech QC Elch2
103spca561 046d:092e Logitech QC Elch2 103spca561 046d:092e Logitech QC Elch2
104spca561 046d:092f Logitech QuickCam Express Plus 104spca561 046d:092f Logitech QuickCam Express Plus
105sunplus 046d:0960 Logitech ClickSmart 420 105sunplus 046d:0960 Logitech ClickSmart 420
106nw80x 046d:d001 Logitech QuickCam Pro (dark focus ring)
106sunplus 0471:0322 Philips DMVC1300K 107sunplus 0471:0322 Philips DMVC1300K
107zc3xx 0471:0325 Philips SPC 200 NC 108zc3xx 0471:0325 Philips SPC 200 NC
108zc3xx 0471:0326 Philips SPC 300 NC 109zc3xx 0471:0326 Philips SPC 300 NC
@@ -150,10 +151,12 @@ sunplus 04fc:5330 Digitrex 2110
150sunplus 04fc:5360 Sunplus Generic 151sunplus 04fc:5360 Sunplus Generic
151spca500 04fc:7333 PalmPixDC85 152spca500 04fc:7333 PalmPixDC85
152sunplus 04fc:ffff Pure DigitalDakota 153sunplus 04fc:ffff Pure DigitalDakota
154nw80x 0502:d001 DVC V6
153spca501 0506:00df 3Com HomeConnect Lite 155spca501 0506:00df 3Com HomeConnect Lite
154sunplus 052b:1507 Megapixel 5 Pretec DC-1007 156sunplus 052b:1507 Megapixel 5 Pretec DC-1007
155sunplus 052b:1513 Megapix V4 157sunplus 052b:1513 Megapix V4
156sunplus 052b:1803 MegaImage VI 158sunplus 052b:1803 MegaImage VI
159nw80x 052b:d001 EZCam Pro p35u
157tv8532 0545:808b Veo Stingray 160tv8532 0545:808b Veo Stingray
158tv8532 0545:8333 Veo Stingray 161tv8532 0545:8333 Veo Stingray
159sunplus 0546:3155 Polaroid PDC3070 162sunplus 0546:3155 Polaroid PDC3070
@@ -177,6 +180,7 @@ sunplus 055f:c530 Mustek Gsmart LCD 3
177sunplus 055f:c540 Gsmart D30 180sunplus 055f:c540 Gsmart D30
178sunplus 055f:c630 Mustek MDC4000 181sunplus 055f:c630 Mustek MDC4000
179sunplus 055f:c650 Mustek MDC5500Z 182sunplus 055f:c650 Mustek MDC5500Z
183nw80x 055f:d001 Mustek Wcam 300 mini
180zc3xx 055f:d003 Mustek WCam300A 184zc3xx 055f:d003 Mustek WCam300A
181zc3xx 055f:d004 Mustek WCam300 AN 185zc3xx 055f:d004 Mustek WCam300 AN
182conex 0572:0041 Creative Notebook cx11646 186conex 0572:0041 Creative Notebook cx11646
@@ -195,14 +199,20 @@ gl860 05e3:0503 Genesys Logic PC Camera
195gl860 05e3:f191 Genesys Logic PC Camera 199gl860 05e3:f191 Genesys Logic PC Camera
196spca561 060b:a001 Maxell Compact Pc PM3 200spca561 060b:a001 Maxell Compact Pc PM3
197zc3xx 0698:2003 CTX M730V built in 201zc3xx 0698:2003 CTX M730V built in
202nw80x 06a5:0000 Typhoon Webcam 100 USB
203nw80x 06a5:d001 Divio based webcams
204nw80x 06a5:d800 Divio Chicony TwinkleCam, Trust SpaceCam
198spca500 06bd:0404 Agfa CL20 205spca500 06bd:0404 Agfa CL20
199spca500 06be:0800 Optimedia 206spca500 06be:0800 Optimedia
207nw80x 06be:d001 EZCam Pro p35u
200sunplus 06d6:0031 Trust 610 LCD PowerC@m Zoom 208sunplus 06d6:0031 Trust 610 LCD PowerC@m Zoom
201spca506 06e1:a190 ADS Instant VCD 209spca506 06e1:a190 ADS Instant VCD
210ov534 06f8:3002 Hercules Blog Webcam
202ov534_9 06f8:3003 Hercules Dualpix HD Weblog 211ov534_9 06f8:3003 Hercules Dualpix HD Weblog
203sonixj 06f8:3004 Hercules Classic Silver 212sonixj 06f8:3004 Hercules Classic Silver
204sonixj 06f8:3008 Hercules Deluxe Optical Glass 213sonixj 06f8:3008 Hercules Deluxe Optical Glass
205pac7302 06f8:3009 Hercules Classic Link 214pac7302 06f8:3009 Hercules Classic Link
215nw80x 0728:d001 AVerMedia Camguard
206spca508 0733:0110 ViewQuest VQ110 216spca508 0733:0110 ViewQuest VQ110
207spca501 0733:0401 Intel Create and Share 217spca501 0733:0401 Intel Create and Share
208spca501 0733:0402 ViewQuest M318B 218spca501 0733:0402 ViewQuest M318B
diff --git a/Documentation/video4linux/omap3isp.txt b/Documentation/video4linux/omap3isp.txt
new file mode 100644
index 000000000000..69be2c782b98
--- /dev/null
+++ b/Documentation/video4linux/omap3isp.txt
@@ -0,0 +1,278 @@
1OMAP 3 Image Signal Processor (ISP) driver
2
3Copyright (C) 2010 Nokia Corporation
4Copyright (C) 2009 Texas Instruments, Inc.
5
6Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 Sakari Ailus <sakari.ailus@iki.fi>
8 David Cohen <dacohen@gmail.com>
9
10
11Introduction
12============
13
14This file documents the Texas Instruments OMAP 3 Image Signal Processor (ISP)
15driver located under drivers/media/video/omap3isp. The original driver was
16written by Texas Instruments but since that it has been rewritten (twice) at
17Nokia.
18
19The driver has been successfully used on the following versions of OMAP 3:
20
21 3430
22 3530
23 3630
24
25The driver implements V4L2, Media controller and v4l2_subdev interfaces.
26Sensor, lens and flash drivers using the v4l2_subdev interface in the kernel
27are supported.
28
29
30Split to subdevs
31================
32
33The OMAP 3 ISP is split into V4L2 subdevs, each of the blocks inside the ISP
34having one subdev to represent it. Each of the subdevs provide a V4L2 subdev
35interface to userspace.
36
37 OMAP3 ISP CCP2
38 OMAP3 ISP CSI2a
39 OMAP3 ISP CCDC
40 OMAP3 ISP preview
41 OMAP3 ISP resizer
42 OMAP3 ISP AEWB
43 OMAP3 ISP AF
44 OMAP3 ISP histogram
45
46Each possible link in the ISP is modelled by a link in the Media controller
47interface. For an example program see [2].
48
49
50Controlling the OMAP 3 ISP
51==========================
52
53In general, the settings given to the OMAP 3 ISP take effect at the beginning
54of the following frame. This is done when the module becomes idle during the
55vertical blanking period on the sensor. In memory-to-memory operation the pipe
56is run one frame at a time. Applying the settings is done between the frames.
57
58All the blocks in the ISP, excluding the CSI-2 and possibly the CCP2 receiver,
59insist on receiving complete frames. Sensors must thus never send the ISP
60partial frames.
61
62Autoidle does have issues with some ISP blocks on the 3430, at least.
63Autoidle is only enabled on 3630 when the omap3isp module parameter autoidle
64is non-zero.
65
66
67Events
68======
69
70The OMAP 3 ISP driver does support the V4L2 event interface on CCDC and
71statistics (AEWB, AF and histogram) subdevs.
72
73The CCDC subdev produces V4L2_EVENT_OMAP3ISP_HS_VS type event on HS_VS
74interrupt which is used to signal frame start. The event is triggered exactly
75when the reception of the first line of the frame starts in the CCDC module.
76The event can be subscribed on the CCDC subdev.
77
78(When using parallel interface one must pay account to correct configuration
79of the VS signal polarity. This is automatically correct when using the serial
80receivers.)
81
82Each of the statistics subdevs is able to produce events. An event is
83generated whenever a statistics buffer can be dequeued by a user space
84application using the VIDIOC_OMAP3ISP_STAT_REQ IOCTL. The events available
85are:
86
87 V4L2_EVENT_OMAP3ISP_AEWB
88 V4L2_EVENT_OMAP3ISP_AF
89 V4L2_EVENT_OMAP3ISP_HIST
90
91The type of the event data is struct omap3isp_stat_event_status for these
92ioctls. If there is an error calculating the statistics, there will be an
93event as usual, but no related statistics buffer. In this case
94omap3isp_stat_event_status.buf_err is set to non-zero.
95
96
97Private IOCTLs
98==============
99
100The OMAP 3 ISP driver supports standard V4L2 IOCTLs and controls where
101possible and practical. Much of the functions provided by the ISP, however,
102does not fall under the standard IOCTLs --- gamma tables and configuration of
103statistics collection are examples of such.
104
105In general, there is a private ioctl for configuring each of the blocks
106containing hardware-dependent functions.
107
108The following private IOCTLs are supported:
109
110 VIDIOC_OMAP3ISP_CCDC_CFG
111 VIDIOC_OMAP3ISP_PRV_CFG
112 VIDIOC_OMAP3ISP_AEWB_CFG
113 VIDIOC_OMAP3ISP_HIST_CFG
114 VIDIOC_OMAP3ISP_AF_CFG
115 VIDIOC_OMAP3ISP_STAT_REQ
116 VIDIOC_OMAP3ISP_STAT_EN
117
118The parameter structures used by these ioctls are described in
119include/linux/omap3isp.h. The detailed functions of the ISP itself related to
120a given ISP block is described in the Technical Reference Manuals (TRMs) ---
121see the end of the document for those.
122
123While it is possible to use the ISP driver without any use of these private
124IOCTLs it is not possible to obtain optimal image quality this way. The AEWB,
125AF and histogram modules cannot be used without configuring them using the
126appropriate private IOCTLs.
127
128
129CCDC and preview block IOCTLs
130=============================
131
132The VIDIOC_OMAP3ISP_CCDC_CFG and VIDIOC_OMAP3ISP_PRV_CFG IOCTLs are used to
133configure, enable and disable functions in the CCDC and preview blocks,
134respectively. Both IOCTLs control several functions in the blocks they
135control. VIDIOC_OMAP3ISP_CCDC_CFG IOCTL accepts a pointer to struct
136omap3isp_ccdc_update_config as its argument. Similarly VIDIOC_OMAP3ISP_PRV_CFG
137accepts a pointer to struct omap3isp_prev_update_config. The definition of
138both structures is available in [1].
139
140The update field in the structures tells whether to update the configuration
141for the specific function and the flag tells whether to enable or disable the
142function.
143
144The update and flag bit masks accept the following values. Each separate
145functions in the CCDC and preview blocks is associated with a flag (either
146disable or enable; part of the flag field in the structure) and a pointer to
147configuration data for the function.
148
149Valid values for the update and flag fields are listed here for
150VIDIOC_OMAP3ISP_CCDC_CFG. Values may be or'ed to configure more than one
151function in the same IOCTL call.
152
153 OMAP3ISP_CCDC_ALAW
154 OMAP3ISP_CCDC_LPF
155 OMAP3ISP_CCDC_BLCLAMP
156 OMAP3ISP_CCDC_BCOMP
157 OMAP3ISP_CCDC_FPC
158 OMAP3ISP_CCDC_CULL
159 OMAP3ISP_CCDC_CONFIG_LSC
160 OMAP3ISP_CCDC_TBL_LSC
161
162The corresponding values for the VIDIOC_OMAP3ISP_PRV_CFG are here:
163
164 OMAP3ISP_PREV_LUMAENH
165 OMAP3ISP_PREV_INVALAW
166 OMAP3ISP_PREV_HRZ_MED
167 OMAP3ISP_PREV_CFA
168 OMAP3ISP_PREV_CHROMA_SUPP
169 OMAP3ISP_PREV_WB
170 OMAP3ISP_PREV_BLKADJ
171 OMAP3ISP_PREV_RGB2RGB
172 OMAP3ISP_PREV_COLOR_CONV
173 OMAP3ISP_PREV_YC_LIMIT
174 OMAP3ISP_PREV_DEFECT_COR
175 OMAP3ISP_PREV_GAMMABYPASS
176 OMAP3ISP_PREV_DRK_FRM_CAPTURE
177 OMAP3ISP_PREV_DRK_FRM_SUBTRACT
178 OMAP3ISP_PREV_LENS_SHADING
179 OMAP3ISP_PREV_NF
180 OMAP3ISP_PREV_GAMMA
181
182The associated configuration pointer for the function may not be NULL when
183enabling the function. When disabling a function the configuration pointer is
184ignored.
185
186
187Statistic blocks IOCTLs
188=======================
189
190The statistics subdevs do offer more dynamic configuration options than the
191other subdevs. They can be enabled, disable and reconfigured when the pipeline
192is in streaming state.
193
194The statistics blocks always get the input image data from the CCDC (as the
195histogram memory read isn't implemented). The statistics are dequeueable by
196the user from the statistics subdev nodes using private IOCTLs.
197
198The private IOCTLs offered by the AEWB, AF and histogram subdevs are heavily
199reflected by the register level interface offered by the ISP hardware. There
200are aspects that are purely related to the driver implementation and these are
201discussed next.
202
203VIDIOC_OMAP3ISP_STAT_EN
204-----------------------
205
206This private IOCTL enables/disables a statistic module. If this request is
207done before streaming, it will take effect as soon as the pipeline starts to
208stream. If the pipeline is already streaming, it will take effect as soon as
209the CCDC becomes idle.
210
211VIDIOC_OMAP3ISP_AEWB_CFG, VIDIOC_OMAP3ISP_HIST_CFG and VIDIOC_OMAP3ISP_AF_CFG
212-----------------------------------------------------------------------------
213
214Those IOCTLs are used to configure the modules. They require user applications
215to have an in-depth knowledge of the hardware. Most of the fields explanation
216can be found on OMAP's TRMs. The two following fields common to all the above
217configure private IOCTLs require explanation for better understanding as they
218are not part of the TRM.
219
220omap3isp_[h3a_af/h3a_aewb/hist]_config.buf_size:
221
222The modules handle their buffers internally. The necessary buffer size for the
223module's data output depends on the requested configuration. Although the
224driver supports reconfiguration while streaming, it does not support a
225reconfiguration which requires bigger buffer size than what is already
226internally allocated if the module is enabled. It will return -EBUSY on this
227case. In order to avoid such condition, either disable/reconfigure/enable the
228module or request the necessary buffer size during the first configuration
229while the module is disabled.
230
231The internal buffer size allocation considers the requested configuration's
232minimum buffer size and the value set on buf_size field. If buf_size field is
233out of [minimum, maximum] buffer size range, it's clamped to fit in there.
234The driver then selects the biggest value. The corrected buf_size value is
235written back to user application.
236
237omap3isp_[h3a_af/h3a_aewb/hist]_config.config_counter:
238
239As the configuration doesn't take effect synchronously to the request, the
240driver must provide a way to track this information to provide more accurate
241data. After a configuration is requested, the config_counter returned to user
242space application will be an unique value associated to that request. When
243user application receives an event for buffer availability or when a new
244buffer is requested, this config_counter is used to match a buffer data and a
245configuration.
246
247VIDIOC_OMAP3ISP_STAT_REQ
248------------------------
249
250Send to user space the oldest data available in the internal buffer queue and
251discards such buffer afterwards. The field omap3isp_stat_data.frame_number
252matches with the video buffer's field_count.
253
254
255Technical reference manuals (TRMs) and other documentation
256==========================================================
257
258OMAP 3430 TRM:
259<URL:http://focus.ti.com/pdfs/wtbu/OMAP34xx_ES3.1.x_PUBLIC_TRM_vZM.zip>
260Referenced 2011-03-05.
261
262OMAP 35xx TRM:
263<URL:http://www.ti.com/litv/pdf/spruf98o> Referenced 2011-03-05.
264
265OMAP 3630 TRM:
266<URL:http://focus.ti.com/pdfs/wtbu/OMAP36xx_ES1.x_PUBLIC_TRM_vQ.zip>
267Referenced 2011-03-05.
268
269DM 3730 TRM:
270<URL:http://www.ti.com/litv/pdf/sprugn4h> Referenced 2011-03-06.
271
272
273References
274==========
275
276[1] include/linux/omap3isp.h
277
278[2] http://git.ideasonboard.org/?p=media-ctl.git;a=summary
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index f22f35c271f3..3b15608ee070 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -71,6 +71,10 @@ sub-device instances, the video_device struct stores V4L2 device node data
71and in the future a v4l2_fh struct will keep track of filehandle instances 71and in the future a v4l2_fh struct will keep track of filehandle instances
72(this is not yet implemented). 72(this is not yet implemented).
73 73
74The V4L2 framework also optionally integrates with the media framework. If a
75driver sets the struct v4l2_device mdev field, sub-devices and video nodes
76will automatically appear in the media framework as entities.
77
74 78
75struct v4l2_device 79struct v4l2_device
76------------------ 80------------------
@@ -83,11 +87,20 @@ You must register the device instance:
83 87
84 v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev); 88 v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev);
85 89
86Registration will initialize the v4l2_device struct and link dev->driver_data 90Registration will initialize the v4l2_device struct. If the dev->driver_data
87to v4l2_dev. If v4l2_dev->name is empty then it will be set to a value derived 91field is NULL, it will be linked to v4l2_dev.
88from dev (driver name followed by the bus_id, to be precise). If you set it 92
89up before calling v4l2_device_register then it will be untouched. If dev is 93Drivers that want integration with the media device framework need to set
90NULL, then you *must* setup v4l2_dev->name before calling v4l2_device_register. 94dev->driver_data manually to point to the driver-specific device structure
95that embed the struct v4l2_device instance. This is achieved by a
96dev_set_drvdata() call before registering the V4L2 device instance. They must
97also set the struct v4l2_device mdev field to point to a properly initialized
98and registered media_device instance.
99
100If v4l2_dev->name is empty then it will be set to a value derived from dev
101(driver name followed by the bus_id, to be precise). If you set it up before
102calling v4l2_device_register then it will be untouched. If dev is NULL, then
103you *must* setup v4l2_dev->name before calling v4l2_device_register.
91 104
92You can use v4l2_device_set_name() to set the name based on a driver name and 105You can use v4l2_device_set_name() to set the name based on a driver name and
93a driver-global atomic_t instance. This will generate names like ivtv0, ivtv1, 106a driver-global atomic_t instance. This will generate names like ivtv0, ivtv1,
@@ -108,6 +121,7 @@ You unregister with:
108 121
109 v4l2_device_unregister(struct v4l2_device *v4l2_dev); 122 v4l2_device_unregister(struct v4l2_device *v4l2_dev);
110 123
124If the dev->driver_data field points to v4l2_dev, it will be reset to NULL.
111Unregistering will also automatically unregister all subdevs from the device. 125Unregistering will also automatically unregister all subdevs from the device.
112 126
113If you have a hotpluggable device (e.g. a USB device), then when a disconnect 127If you have a hotpluggable device (e.g. a USB device), then when a disconnect
@@ -167,6 +181,21 @@ static int __devinit drv_probe(struct pci_dev *pdev,
167 state->instance = atomic_inc_return(&drv_instance) - 1; 181 state->instance = atomic_inc_return(&drv_instance) - 1;
168} 182}
169 183
184If you have multiple device nodes then it can be difficult to know when it is
185safe to unregister v4l2_device. For this purpose v4l2_device has refcounting
186support. The refcount is increased whenever video_register_device is called and
187it is decreased whenever that device node is released. When the refcount reaches
188zero, then the v4l2_device release() callback is called. You can do your final
189cleanup there.
190
191If other device nodes (e.g. ALSA) are created, then you can increase and
192decrease the refcount manually as well by calling:
193
194void v4l2_device_get(struct v4l2_device *v4l2_dev);
195
196or:
197
198int v4l2_device_put(struct v4l2_device *v4l2_dev);
170 199
171struct v4l2_subdev 200struct v4l2_subdev
172------------------ 201------------------
@@ -254,6 +283,26 @@ A sub-device driver initializes the v4l2_subdev struct using:
254Afterwards you need to initialize subdev->name with a unique name and set the 283Afterwards you need to initialize subdev->name with a unique name and set the
255module owner. This is done for you if you use the i2c helper functions. 284module owner. This is done for you if you use the i2c helper functions.
256 285
286If integration with the media framework is needed, you must initialize the
287media_entity struct embedded in the v4l2_subdev struct (entity field) by
288calling media_entity_init():
289
290 struct media_pad *pads = &my_sd->pads;
291 int err;
292
293 err = media_entity_init(&sd->entity, npads, pads, 0);
294
295The pads array must have been previously initialized. There is no need to
296manually set the struct media_entity type and name fields, but the revision
297field must be initialized if needed.
298
299A reference to the entity will be automatically acquired/released when the
300subdev device node (if any) is opened/closed.
301
302Don't forget to cleanup the media entity before the sub-device is destroyed:
303
304 media_entity_cleanup(&sd->entity);
305
257A device (bridge) driver needs to register the v4l2_subdev with the 306A device (bridge) driver needs to register the v4l2_subdev with the
258v4l2_device: 307v4l2_device:
259 308
@@ -263,6 +312,9 @@ This can fail if the subdev module disappeared before it could be registered.
263After this function was called successfully the subdev->dev field points to 312After this function was called successfully the subdev->dev field points to
264the v4l2_device. 313the v4l2_device.
265 314
315If the v4l2_device parent device has a non-NULL mdev field, the sub-device
316entity will be automatically registered with the media device.
317
266You can unregister a sub-device using: 318You can unregister a sub-device using:
267 319
268 v4l2_device_unregister_subdev(sd); 320 v4l2_device_unregister_subdev(sd);
@@ -319,6 +371,61 @@ controlled through GPIO pins. This distinction is only relevant when setting
319up the device, but once the subdev is registered it is completely transparent. 371up the device, but once the subdev is registered it is completely transparent.
320 372
321 373
374V4L2 sub-device userspace API
375-----------------------------
376
377Beside exposing a kernel API through the v4l2_subdev_ops structure, V4L2
378sub-devices can also be controlled directly by userspace applications.
379
380Device nodes named v4l-subdevX can be created in /dev to access sub-devices
381directly. If a sub-device supports direct userspace configuration it must set
382the V4L2_SUBDEV_FL_HAS_DEVNODE flag before being registered.
383
384After registering sub-devices, the v4l2_device driver can create device nodes
385for all registered sub-devices marked with V4L2_SUBDEV_FL_HAS_DEVNODE by calling
386v4l2_device_register_subdev_nodes(). Those device nodes will be automatically
387removed when sub-devices are unregistered.
388
389The device node handles a subset of the V4L2 API.
390
391VIDIOC_QUERYCTRL
392VIDIOC_QUERYMENU
393VIDIOC_G_CTRL
394VIDIOC_S_CTRL
395VIDIOC_G_EXT_CTRLS
396VIDIOC_S_EXT_CTRLS
397VIDIOC_TRY_EXT_CTRLS
398
399 The controls ioctls are identical to the ones defined in V4L2. They
400 behave identically, with the only exception that they deal only with
401 controls implemented in the sub-device. Depending on the driver, those
402 controls can be also be accessed through one (or several) V4L2 device
403 nodes.
404
405VIDIOC_DQEVENT
406VIDIOC_SUBSCRIBE_EVENT
407VIDIOC_UNSUBSCRIBE_EVENT
408
409 The events ioctls are identical to the ones defined in V4L2. They
410 behave identically, with the only exception that they deal only with
411 events generated by the sub-device. Depending on the driver, those
412 events can also be reported by one (or several) V4L2 device nodes.
413
414 Sub-device drivers that want to use events need to set the
415 V4L2_SUBDEV_USES_EVENTS v4l2_subdev::flags and initialize
416 v4l2_subdev::nevents to events queue depth before registering the
417 sub-device. After registration events can be queued as usual on the
418 v4l2_subdev::devnode device node.
419
420 To properly support events, the poll() file operation is also
421 implemented.
422
423Private ioctls
424
425 All ioctls not in the above list are passed directly to the sub-device
426 driver through the core::ioctl operation.
427
428
322I2C sub-device drivers 429I2C sub-device drivers
323---------------------- 430----------------------
324 431
@@ -457,6 +564,10 @@ You should also set these fields:
457 Otherwise you give it a pointer to a struct mutex_lock and before any 564 Otherwise you give it a pointer to a struct mutex_lock and before any
458 of the v4l2_file_operations is called this lock will be taken by the 565 of the v4l2_file_operations is called this lock will be taken by the
459 core and released afterwards. 566 core and released afterwards.
567- prio: keeps track of the priorities. Used to implement VIDIOC_G/S_PRIORITY.
568 If left to NULL, then it will use the struct v4l2_prio_state in v4l2_device.
569 If you want to have a separate priority state per (group of) device node(s),
570 then you can point it to your own struct v4l2_prio_state.
460- parent: you only set this if v4l2_device was registered with NULL as 571- parent: you only set this if v4l2_device was registered with NULL as
461 the parent device struct. This only happens in cases where one hardware 572 the parent device struct. This only happens in cases where one hardware
462 device has multiple PCI devices that all share the same v4l2_device core. 573 device has multiple PCI devices that all share the same v4l2_device core.
@@ -466,13 +577,34 @@ You should also set these fields:
466 (cx8802). Since the v4l2_device cannot be associated with a particular 577 (cx8802). Since the v4l2_device cannot be associated with a particular
467 PCI device it is setup without a parent device. But when the struct 578 PCI device it is setup without a parent device. But when the struct
468 video_device is setup you do know which parent PCI device to use. 579 video_device is setup you do know which parent PCI device to use.
580- flags: optional. Set to V4L2_FL_USE_FH_PRIO if you want to let the framework
581 handle the VIDIOC_G/S_PRIORITY ioctls. This requires that you use struct
582 v4l2_fh. Eventually this flag will disappear once all drivers use the core
583 priority handling. But for now it has to be set explicitly.
469 584
470If you use v4l2_ioctl_ops, then you should set either .unlocked_ioctl or 585If you use v4l2_ioctl_ops, then you should set .unlocked_ioctl to video_ioctl2
471.ioctl to video_ioctl2 in your v4l2_file_operations struct. 586in your v4l2_file_operations struct.
587
588Do not use .ioctl! This is deprecated and will go away in the future.
472 589
473The v4l2_file_operations struct is a subset of file_operations. The main 590The v4l2_file_operations struct is a subset of file_operations. The main
474difference is that the inode argument is omitted since it is never used. 591difference is that the inode argument is omitted since it is never used.
475 592
593If integration with the media framework is needed, you must initialize the
594media_entity struct embedded in the video_device struct (entity field) by
595calling media_entity_init():
596
597 struct media_pad *pad = &my_vdev->pad;
598 int err;
599
600 err = media_entity_init(&vdev->entity, 1, pad, 0);
601
602The pads array must have been previously initialized. There is no need to
603manually set the struct media_entity type and name fields.
604
605A reference to the entity will be automatically acquired/released when the
606video device is opened/closed.
607
476v4l2_file_operations and locking 608v4l2_file_operations and locking
477-------------------------------- 609--------------------------------
478 610
@@ -502,6 +634,9 @@ for you.
502 return err; 634 return err;
503 } 635 }
504 636
637If the v4l2_device parent device has a non-NULL mdev field, the video device
638entity will be automatically registered with the media device.
639
505Which device is registered depends on the type argument. The following 640Which device is registered depends on the type argument. The following
506types exist: 641types exist:
507 642
@@ -577,6 +712,13 @@ release, of course) will return an error as well.
577When the last user of the video device node exits, then the vdev->release() 712When the last user of the video device node exits, then the vdev->release()
578callback is called and you can do the final cleanup there. 713callback is called and you can do the final cleanup there.
579 714
715Don't forget to cleanup the media entity associated with the video device if
716it has been initialized:
717
718 media_entity_cleanup(&vdev->entity);
719
720This can be done from the release callback.
721
580 722
581video_device helper functions 723video_device helper functions
582----------------------------- 724-----------------------------
@@ -636,39 +778,25 @@ struct v4l2_fh
636-------------- 778--------------
637 779
638struct v4l2_fh provides a way to easily keep file handle specific data 780struct v4l2_fh provides a way to easily keep file handle specific data
639that is used by the V4L2 framework. Using v4l2_fh is optional for 781that is used by the V4L2 framework. New drivers must use struct v4l2_fh
640drivers. 782since it is also used to implement priority handling (VIDIOC_G/S_PRIORITY)
783if the video_device flag V4L2_FL_USE_FH_PRIO is also set.
641 784
642The users of v4l2_fh (in the V4L2 framework, not the driver) know 785The users of v4l2_fh (in the V4L2 framework, not the driver) know
643whether a driver uses v4l2_fh as its file->private_data pointer by 786whether a driver uses v4l2_fh as its file->private_data pointer by
644testing the V4L2_FL_USES_V4L2_FH bit in video_device->flags. 787testing the V4L2_FL_USES_V4L2_FH bit in video_device->flags. This bit is
645 788set whenever v4l2_fh_init() is called.
646Useful functions:
647
648- v4l2_fh_init()
649
650 Initialise the file handle. This *MUST* be performed in the driver's
651 v4l2_file_operations->open() handler.
652
653- v4l2_fh_add()
654 789
655 Add a v4l2_fh to video_device file handle list. May be called after 790struct v4l2_fh is allocated as a part of the driver's own file handle
656 initialising the file handle. 791structure and file->private_data is set to it in the driver's open
657 792function by the driver.
658- v4l2_fh_del()
659
660 Unassociate the file handle from video_device(). The file handle
661 exit function may now be called.
662 793
663- v4l2_fh_exit() 794In many cases the struct v4l2_fh will be embedded in a larger structure.
795In that case you should call v4l2_fh_init+v4l2_fh_add in open() and
796v4l2_fh_del+v4l2_fh_exit in release().
664 797
665 Uninitialise the file handle. After uninitialisation the v4l2_fh 798Drivers can extract their own file handle structure by using the container_of
666 memory can be freed. 799macro. Example:
667
668struct v4l2_fh is allocated as a part of the driver's own file handle
669structure and is set to file->private_data in the driver's open
670function by the driver. Drivers can extract their own file handle
671structure by using the container_of macro. Example:
672 800
673struct my_fh { 801struct my_fh {
674 int blah; 802 int blah;
@@ -685,15 +813,21 @@ int my_open(struct file *file)
685 813
686 ... 814 ...
687 815
816 my_fh = kzalloc(sizeof(*my_fh), GFP_KERNEL);
817
818 ...
819
688 ret = v4l2_fh_init(&my_fh->fh, vfd); 820 ret = v4l2_fh_init(&my_fh->fh, vfd);
689 if (ret) 821 if (ret) {
822 kfree(my_fh);
690 return ret; 823 return ret;
824 }
691 825
692 v4l2_fh_add(&my_fh->fh); 826 ...
693 827
694 file->private_data = &my_fh->fh; 828 file->private_data = &my_fh->fh;
695 829 v4l2_fh_add(&my_fh->fh);
696 ... 830 return 0;
697} 831}
698 832
699int my_release(struct file *file) 833int my_release(struct file *file)
@@ -702,8 +836,65 @@ int my_release(struct file *file)
702 struct my_fh *my_fh = container_of(fh, struct my_fh, fh); 836 struct my_fh *my_fh = container_of(fh, struct my_fh, fh);
703 837
704 ... 838 ...
839 v4l2_fh_del(&my_fh->fh);
840 v4l2_fh_exit(&my_fh->fh);
841 kfree(my_fh);
842 return 0;
705} 843}
706 844
845Below is a short description of the v4l2_fh functions used:
846
847int v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
848
849 Initialise the file handle. This *MUST* be performed in the driver's
850 v4l2_file_operations->open() handler.
851
852void v4l2_fh_add(struct v4l2_fh *fh)
853
854 Add a v4l2_fh to video_device file handle list. Must be called once the
855 file handle is completely initialized.
856
857void v4l2_fh_del(struct v4l2_fh *fh)
858
859 Unassociate the file handle from video_device(). The file handle
860 exit function may now be called.
861
862void v4l2_fh_exit(struct v4l2_fh *fh)
863
864 Uninitialise the file handle. After uninitialisation the v4l2_fh
865 memory can be freed.
866
867
868If struct v4l2_fh is not embedded, then you can use these helper functions:
869
870int v4l2_fh_open(struct file *filp)
871
872 This allocates a struct v4l2_fh, initializes it and adds it to the struct
873 video_device associated with the file struct.
874
875int v4l2_fh_release(struct file *filp)
876
877 This deletes it from the struct video_device associated with the file
878 struct, uninitialised the v4l2_fh and frees it.
879
880These two functions can be plugged into the v4l2_file_operation's open() and
881release() ops.
882
883
884Several drivers need to do something when the first file handle is opened and
885when the last file handle closes. Two helper functions were added to check
886whether the v4l2_fh struct is the only open filehandle of the associated
887device node:
888
889int v4l2_fh_is_singular(struct v4l2_fh *fh)
890
891 Returns 1 if the file handle is the only open file handle, else 0.
892
893int v4l2_fh_is_singular_file(struct file *filp)
894
895 Same, but it calls v4l2_fh_is_singular with filp->private_data.
896
897
707V4L2 events 898V4L2 events
708----------- 899-----------
709 900