blob: c6b76414172cd74455103acbec763b2e49882b90 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2 SN9C10x PC Camera Controllers
3 Driver for Linux
4 =============================
5
6 - Documentation -
7
8
9Index
10=====
111. Copyright
122. Disclaimer
133. License
144. Overview and features
155. Module dependencies
166. Module loading
177. Module parameters
188. Optional device control through "sysfs"
199. Supported devices
Luca Risoliaa966f3e2006-01-05 18:14:04 +00002010. Notes for V4L2 application developers
2111. Video frame formats
2212. Contact information
2313. Credits
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25
261. Copyright
27============
Luca Risoliaa966f3e2006-01-05 18:14:04 +000028Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30
312. Disclaimer
32=============
33SONiX is a trademark of SONiX Technology Company Limited, inc.
34This software is not sponsored or developed by SONiX.
35
36
373. License
38==========
39This program is free software; you can redistribute it and/or modify
40it under the terms of the GNU General Public License as published by
41the Free Software Foundation; either version 2 of the License, or
42(at your option) any later version.
43
44This program is distributed in the hope that it will be useful,
45but WITHOUT ANY WARRANTY; without even the implied warranty of
46MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47GNU General Public License for more details.
48
49You should have received a copy of the GNU General Public License
50along with this program; if not, write to the Free Software
51Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
52
53
544. Overview and features
55========================
Luca Risoliaa966f3e2006-01-05 18:14:04 +000056This driver attempts to support the video interface of the devices mounting the
57SONiX SN9C101, SN9C102 and SN9C103 PC Camera Controllers.
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59It's worth to note that SONiX has never collaborated with the author during the
60development of this project, despite several requests for enough detailed
61specifications of the register tables, compression engine and video data format
62of the above chips. Nevertheless, these informations are no longer necessary,
63becouse all the aspects related to these chips are known and have been
64described in detail in this documentation.
65
66The driver relies on the Video4Linux2 and USB core modules. It has been
67designed to run properly on SMP systems as well.
68
69The latest version of the SN9C10x driver can be found at the following URL:
70http://www.linux-projects.org/
71
72Some of the features of the driver are:
73
74- full compliance with the Video4Linux2 API (see also "Notes for V4L2
75 application developers" paragraph);
76- available mmap or read/poll methods for video streaming through isochronous
77 data transfers;
78- automatic detection of image sensor;
Luca Risoliaa966f3e2006-01-05 18:14:04 +000079- support for built-in microphone interface;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080- support for any window resolutions and optional panning within the maximum
81 pixel area of image sensor;
82- image downscaling with arbitrary scaling factors from 1, 2 and 4 in both
83 directions (see "Notes for V4L2 application developers" paragraph);
84- two different video formats for uncompressed or compressed data in low or
85 high compression quality (see also "Notes for V4L2 application developers"
86 and "Video frame formats" paragraphs);
87- full support for the capabilities of many of the possible image sensors that
88 can be connected to the SN9C10x bridges, including, for istance, red, green,
89 blue and global gain adjustments and exposure (see "Supported devices"
90 paragraph for details);
91- use of default color settings for sunlight conditions;
92- dynamic I/O interface for both SN9C10x and image sensor control and
93 monitoring (see "Optional device control through 'sysfs'" paragraph);
94- dynamic driver control thanks to various module parameters (see "Module
95 parameters" paragraph);
96- up to 64 cameras can be handled at the same time; they can be connected and
97 disconnected from the host many times without turning off the computer, if
Luca Risoliaa966f3e2006-01-05 18:14:04 +000098 the system supports hotplugging;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099- no known bugs.
100
101
1025. Module dependencies
103======================
104For it to work properly, the driver needs kernel support for Video4Linux and
105USB.
106
107The following options of the kernel configuration file must be enabled and
108corresponding modules must be compiled:
109
110 # Multimedia devices
111 #
112 CONFIG_VIDEO_DEV=m
113
Luca Risoliacd6fcc52006-01-13 17:19:43 +0000114To enable advanced debugging functionality on the device through /sysfs:
115
116 # Multimedia devices
117 #
118 CONFIG_VIDEO_ADV_DEBUG=y
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 # USB support
121 #
122 CONFIG_USB=m
123
124In addition, depending on the hardware being used, the modules below are
125necessary:
126
127 # USB Host Controller Drivers
128 #
129 CONFIG_USB_EHCI_HCD=m
130 CONFIG_USB_UHCI_HCD=m
131 CONFIG_USB_OHCI_HCD=m
132
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000133The SN9C103 controller also provides a built-in microphone interface. It is
134supported by the USB Audio driver thanks to the ALSA API:
135
136 # Sound
137 #
138 CONFIG_SOUND=y
139
140 # Advanced Linux Sound Architecture
141 #
142 CONFIG_SND=m
143
144 # USB devices
145 #
146 CONFIG_SND_USB_AUDIO=m
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148And finally:
149
150 # USB Multimedia devices
151 #
152 CONFIG_USB_SN9C102=m
153
154
1556. Module loading
156=================
157To use the driver, it is necessary to load the "sn9c102" module into memory
158after every other module required: "videodev", "usbcore" and, depending on
159the USB host controller you have, "ehci-hcd", "uhci-hcd" or "ohci-hcd".
160
161Loading can be done as shown below:
162
163 [root@localhost home]# modprobe sn9c102
164
165At this point the devices should be recognized. You can invoke "dmesg" to
166analyze kernel messages and verify that the loading process has gone well:
167
168 [user@localhost home]$ dmesg
169
170
1717. Module parameters
172====================
173Module parameters are listed below:
174-------------------------------------------------------------------------------
175Name: video_nr
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000176Type: short array (min = 0, max = 64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177Syntax: <-1|n[,...]>
178Description: Specify V4L2 minor mode number:
179 -1 = use next available
180 n = use minor number n
181 You can specify up to 64 cameras this way.
182 For example:
183 video_nr=-1,2,-1 would assign minor number 2 to the second
184 recognized camera and use auto for the first one and for every
185 other camera.
186Default: -1
187-------------------------------------------------------------------------------
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000188Name: force_munmap
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189Type: bool array (min = 0, max = 64)
190Syntax: <0|1[,...]>
191Description: Force the application to unmap previously mapped buffer memory
192 before calling any VIDIOC_S_CROP or VIDIOC_S_FMT ioctl's. Not
193 all the applications support this feature. This parameter is
194 specific for each detected camera.
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000195 0 = do not force memory unmapping
196 1 = force memory unmapping (save memory)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197Default: 0
198-------------------------------------------------------------------------------
199Name: debug
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000200Type: ushort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201Syntax: <n>
202Description: Debugging information level, from 0 to 3:
203 0 = none (use carefully)
204 1 = critical errors
205 2 = significant informations
206 3 = more verbose messages
207 Level 3 is useful for testing only, when only one device
208 is used. It also shows some more informations about the
209 hardware being detected. This parameter can be changed at
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000210 runtime thanks to the /sys filesystem interface.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211Default: 2
212-------------------------------------------------------------------------------
213
214
2158. Optional device control through "sysfs" [1]
216==========================================
Luca Risoliacd6fcc52006-01-13 17:19:43 +0000217If the kernel has been compiled with the CONFIG_VIDEO_ADV_DEBUG option enabled,
218it is possible to read and write both the SN9C10x and the image sensor
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219registers by using the "sysfs" filesystem interface.
220
221Every time a supported device is recognized, a write-only file named "green" is
222created in the /sys/class/video4linux/videoX directory. You can set the green
223channel's gain by writing the desired value to it. The value may range from 0
224to 15 for SN9C101 or SN9C102 bridges, from 0 to 127 for SN9C103 bridges.
225Similarly, only for SN9C103 controllers, blue and red gain control files are
226available in the same directory, for which accepted values may range from 0 to
227127.
228
229There are other four entries in the directory above for each registered camera:
230"reg", "val", "i2c_reg" and "i2c_val". The first two files control the
231SN9C10x bridge, while the other two control the sensor chip. "reg" and
232"i2c_reg" hold the values of the current register index where the following
233reading/writing operations are addressed at through "val" and "i2c_val". Their
234use is not intended for end-users. Note that "i2c_reg" and "i2c_val" will not
235be created if the sensor does not actually support the standard I2C protocol or
236its registers are not 8-bit long. Also, remember that you must be logged in as
237root before writing to them.
238
239As an example, suppose we were to want to read the value contained in the
240register number 1 of the sensor register table - which is usually the product
241identifier - of the camera registered as "/dev/video0":
242
243 [root@localhost #] cd /sys/class/video4linux/video0
244 [root@localhost #] echo 1 > i2c_reg
245 [root@localhost #] cat i2c_val
246
247Note that "cat" will fail if sensor registers cannot be read.
248
249Now let's set the green gain's register of the SN9C101 or SN9C102 chips to 2:
250
251 [root@localhost #] echo 0x11 > reg
252 [root@localhost #] echo 2 > val
253
254Note that the SN9C10x always returns 0 when some of its registers are read.
255To avoid race conditions, all the I/O accesses to the above files are
256serialized.
257
258The sysfs interface also provides the "frame_header" entry, which exports the
259frame header of the most recent requested and captured video frame. The header
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000260is always 18-bytes long and is appended to every video frame by the SN9C10x
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261controllers. As an example, this additional information can be used by the user
262application for implementing auto-exposure features via software.
263
264The following table describes the frame header:
265
266Byte # Value Description
267------ ----- -----------
2680x00 0xFF Frame synchronisation pattern.
2690x01 0xFF Frame synchronisation pattern.
2700x02 0x00 Frame synchronisation pattern.
2710x03 0xC4 Frame synchronisation pattern.
2720x04 0xC4 Frame synchronisation pattern.
2730x05 0x96 Frame synchronisation pattern.
Luca Risoliaa966f3e2006-01-05 18:14:04 +00002740x06 0xXX Unknown meaning. The exact value depends on the chip;
275 possible values are 0x00, 0x01 and 0x20.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760x07 0xXX Variable value, whose bits are ff00uzzc, where ff is a
277 frame counter, u is unknown, zz is a size indicator
278 (00 = VGA, 01 = SIF, 10 = QSIF) and c stands for
279 "compression enabled" (1 = yes, 0 = no).
2800x08 0xXX Brightness sum inside Auto-Exposure area (low-byte).
2810x09 0xXX Brightness sum inside Auto-Exposure area (high-byte).
282 For a pure white image, this number will be equal to 500
283 times the area of the specified AE area. For images
284 that are not pure white, the value scales down according
285 to relative whiteness.
2860x0A 0xXX Brightness sum outside Auto-Exposure area (low-byte).
2870x0B 0xXX Brightness sum outside Auto-Exposure area (high-byte).
288 For a pure white image, this number will be equal to 125
289 times the area outside of the specified AE area. For
290 images that are not pure white, the value scales down
291 according to relative whiteness.
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000292 according to relative whiteness.
293
294The following bytes are used by the SN9C103 bridge only:
295
2960x0C 0xXX Unknown meaning
2970x0D 0xXX Unknown meaning
2980x0E 0xXX Unknown meaning
2990x0F 0xXX Unknown meaning
3000x10 0xXX Unknown meaning
3010x11 0xXX Unknown meaning
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303The AE area (sx, sy, ex, ey) in the active window can be set by programming the
304registers 0x1c, 0x1d, 0x1e and 0x1f of the SN9C10x controllers, where one unit
305corresponds to 32 pixels.
306
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000307[1] Part of the meaning of the frame header has been documented by Bertrik
308 Sikken.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310
3119. Supported devices
312====================
313None of the names of the companies as well as their products will be mentioned
314here. They have never collaborated with the author, so no advertising.
315
316From the point of view of a driver, what unambiguously identify a device are
317its vendor and product USB identifiers. Below is a list of known identifiers of
318devices mounting the SN9C10x PC camera controllers:
319
320Vendor ID Product ID
321--------- ----------
3220x0c45 0x6001
3230x0c45 0x6005
3240x0c45 0x6009
3250x0c45 0x600d
3260x0c45 0x6024
3270x0c45 0x6025
3280x0c45 0x6028
3290x0c45 0x6029
3300x0c45 0x602a
3310x0c45 0x602b
3320x0c45 0x602c
Luca Risoliab9df9782005-06-25 16:30:24 +02003330x0c45 0x602d
Luca Risoliaa966f3e2006-01-05 18:14:04 +00003340x0c45 0x602e
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350x0c45 0x6030
3360x0c45 0x6080
3370x0c45 0x6082
3380x0c45 0x6083
3390x0c45 0x6088
3400x0c45 0x608a
3410x0c45 0x608b
3420x0c45 0x608c
3430x0c45 0x608e
3440x0c45 0x608f
3450x0c45 0x60a0
3460x0c45 0x60a2
3470x0c45 0x60a3
3480x0c45 0x60a8
3490x0c45 0x60aa
3500x0c45 0x60ab
3510x0c45 0x60ac
3520x0c45 0x60ae
3530x0c45 0x60af
3540x0c45 0x60b0
3550x0c45 0x60b2
3560x0c45 0x60b3
3570x0c45 0x60b8
3580x0c45 0x60ba
3590x0c45 0x60bb
3600x0c45 0x60bc
3610x0c45 0x60be
362
363The list above does not imply that all those devices work with this driver: up
364until now only the ones that mount the following image sensors are supported;
365kernel messages will always tell you whether this is the case:
366
367Model Manufacturer
368----- ------------
369HV7131D Hynix Semiconductor, Inc.
370MI-0343 Micron Technology, Inc.
Luca Risoliab9df9782005-06-25 16:30:24 +0200371OV7630 OmniVision Technologies, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372PAS106B PixArt Imaging, Inc.
373PAS202BCB PixArt Imaging, Inc.
374TAS5110C1B Taiwan Advanced Sensor Corporation
375TAS5130D1B Taiwan Advanced Sensor Corporation
376
377All the available control settings of each image sensor are supported through
378the V4L2 interface.
379
380Donations of new models for further testing and support would be much
381appreciated. Non-available hardware will not be supported by the author of this
382driver.
383
384
Luca Risoliaa966f3e2006-01-05 18:14:04 +000038510. Notes for V4L2 application developers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386=========================================
387This driver follows the V4L2 API specifications. In particular, it enforces two
388rules:
389
390- exactly one I/O method, either "mmap" or "read", is associated with each
391file descriptor. Once it is selected, the application must close and reopen the
392device to switch to the other I/O method;
393
394- although it is not mandatory, previously mapped buffer memory should always
395be unmapped before calling any "VIDIOC_S_CROP" or "VIDIOC_S_FMT" ioctl's.
396The same number of buffers as before will be allocated again to match the size
397of the new video frames, so you have to map the buffers again before any I/O
398attempts on them.
399
400Consistently with the hardware limits, this driver also supports image
401downscaling with arbitrary scaling factors from 1, 2 and 4 in both directions.
402However, the V4L2 API specifications don't correctly define how the scaling
403factor can be chosen arbitrarily by the "negotiation" of the "source" and
404"target" rectangles. To work around this flaw, we have added the convention
405that, during the negotiation, whenever the "VIDIOC_S_CROP" ioctl is issued, the
406scaling factor is restored to 1.
407
408This driver supports two different video formats: the first one is the "8-bit
409Sequential Bayer" format and can be used to obtain uncompressed video data
410from the device through the current I/O method, while the second one provides
411"raw" compressed video data (without frame headers not related to the
412compressed data). The compression quality may vary from 0 to 1 and can be
413selected or queried thanks to the VIDIOC_S_JPEGCOMP and VIDIOC_G_JPEGCOMP V4L2
414ioctl's. For maximum flexibility, both the default active video format and the
415default compression quality depend on how the image sensor being used is
416initialized (as described in the documentation of the API for the image sensors
417supplied by this driver).
418
419
Luca Risoliaa966f3e2006-01-05 18:14:04 +000042011. Video frame formats [1]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421=======================
422The SN9C10x PC Camera Controllers can send images in two possible video
423formats over the USB: either native "Sequential RGB Bayer" or Huffman
424compressed. The latter is used to achieve high frame rates. The current video
425format may be selected or queried from the user application by calling the
426VIDIOC_S_FMT or VIDIOC_G_FMT ioctl's, as described in the V4L2 API
427specifications.
428
429The name "Sequential Bayer" indicates the organization of the red, green and
430blue pixels in one video frame. Each pixel is associated with a 8-bit long
431value and is disposed in memory according to the pattern shown below:
432
433B[0] G[1] B[2] G[3] ... B[m-2] G[m-1]
434G[m] R[m+1] G[m+2] R[m+2] ... G[2m-2] R[2m-1]
435...
436... B[(n-1)(m-2)] G[(n-1)(m-1)]
437... G[n(m-2)] R[n(m-1)]
438
439The above matrix also represents the sequential or progressive read-out mode of
440the (n, m) Bayer color filter array used in many CCD/CMOS image sensors.
441
442One compressed video frame consists of a bitstream that encodes for every R, G,
443or B pixel the difference between the value of the pixel itself and some
444reference pixel value. Pixels are organised in the Bayer pattern and the Bayer
445sub-pixels are tracked individually and alternatingly. For example, in the
446first line values for the B and G1 pixels are alternatingly encoded, while in
447the second line values for the G2 and R pixels are alternatingly encoded.
448
449The pixel reference value is calculated as follows:
450- the 4 top left pixels are encoded in raw uncompressed 8-bit format;
451- the value in the top two rows is the value of the pixel left of the current
452 pixel;
453- the value in the left column is the value of the pixel above the current
454 pixel;
455- for all other pixels, the reference value is the average of the value of the
456 pixel on the left and the value of the pixel above the current pixel;
457- there is one code in the bitstream that specifies the value of a pixel
458 directly (in 4-bit resolution);
459- pixel values need to be clamped inside the range [0..255] for proper
460 decoding.
461
462The algorithm purely describes the conversion from compressed Bayer code used
463in the SN9C10x chips to uncompressed Bayer. Additional steps are required to
464convert this to a color image (i.e. a color interpolation algorithm).
465
466The following Huffman codes have been found:
4670: +0 (relative to reference pixel value)
468100: +4
469101: -4?
4701110xxxx: set absolute value to xxxx.0000
4711101: +11
4721111: -11
47311001: +20
474110000: -20
475110001: ??? - these codes are apparently not used
476
477[1] The Huffman compression algorithm has been reverse-engineered and
478 documented by Bertrik Sikken.
479
480
Luca Risoliaa966f3e2006-01-05 18:14:04 +000048112. Contact information
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482=======================
483The author may be contacted by e-mail at <luca.risolia@studio.unibo.it>.
484
485GPG/PGP encrypted e-mail's are accepted. The GPG key ID of the author is
486'FCE635A4'; the public 1024-bit key should be available at any keyserver;
487the fingerprint is: '88E8 F32F 7244 68BA 3958 5D40 99DA 5D2A FCE6 35A4'.
488
489
Luca Risoliaa966f3e2006-01-05 18:14:04 +000049013. Credits
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491===========
492Many thanks to following persons for their contribute (listed in alphabetical
493order):
494
495- Luca Capello for the donation of a webcam;
496- Joao Rodrigo Fuzaro, Joao Limirio, Claudio Filho and Caio Begotti for the
497 donation of a webcam;
Luca Risoliab9df9782005-06-25 16:30:24 +0200498- Jon Hollstrom for the donation of a webcam;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499- Carlos Eduardo Medaglia Dyonisio, who added the support for the PAS202BCB
500 image sensor;
501- Stefano Mozzi, who donated 45 EU;
Luca Risoliab9df9782005-06-25 16:30:24 +0200502- Andrew Pearce for the donation of a webcam;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503- Bertrik Sikken, who reverse-engineered and documented the Huffman compression
504 algorithm used in the SN9C10x controllers and implemented the first decoder;
505- Mizuno Takafumi for the donation of a webcam;
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000506- an "anonymous" donator (who didn't want his name to be revealed) for the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 donation of a webcam.