diff options
Diffstat (limited to 'drivers/media/video/pwc')
-rw-r--r-- | drivers/media/video/pwc/Makefile | 20 | ||||
-rw-r--r-- | drivers/media/video/pwc/philips.txt | 236 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc-ctrl.c | 1541 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc-if.c | 2205 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc-ioctl.h | 292 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc-kiara.c | 318 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc-kiara.h | 45 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc-misc.c | 140 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc-nala.h | 66 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc-timon.c | 316 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc-timon.h | 61 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc-uncompress.c | 146 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc-uncompress.h | 41 | ||||
-rw-r--r-- | drivers/media/video/pwc/pwc.h | 272 |
14 files changed, 5699 insertions, 0 deletions
diff --git a/drivers/media/video/pwc/Makefile b/drivers/media/video/pwc/Makefile new file mode 100644 index 000000000000..2d93a775011a --- /dev/null +++ b/drivers/media/video/pwc/Makefile | |||
@@ -0,0 +1,20 @@ | |||
1 | ifneq ($(KERNELRELEASE),) | ||
2 | |||
3 | pwc-objs := pwc-if.o pwc-misc.o pwc-ctrl.o pwc-uncompress.o pwc-timon.o pwc-kiara.o | ||
4 | |||
5 | obj-$(CONFIG_USB_PWC) += pwc.o | ||
6 | |||
7 | else | ||
8 | |||
9 | KDIR := /lib/modules/$(shell uname -r)/build | ||
10 | PWD := $(shell pwd) | ||
11 | |||
12 | default: | ||
13 | $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules | ||
14 | |||
15 | endif | ||
16 | |||
17 | clean: | ||
18 | rm -f *.[oas] .*.flags *.ko .*.cmd .*.d .*.tmp *.mod.c | ||
19 | rm -rf .tmp_versions | ||
20 | |||
diff --git a/drivers/media/video/pwc/philips.txt b/drivers/media/video/pwc/philips.txt new file mode 100644 index 000000000000..04a640d723ed --- /dev/null +++ b/drivers/media/video/pwc/philips.txt | |||
@@ -0,0 +1,236 @@ | |||
1 | This file contains some additional information for the Philips and OEM webcams. | ||
2 | E-mail: webcam@smcc.demon.nl Last updated: 2004-01-19 | ||
3 | Site: http://www.smcc.demon.nl/webcam/ | ||
4 | |||
5 | As of this moment, the following cameras are supported: | ||
6 | * Philips PCA645 | ||
7 | * Philips PCA646 | ||
8 | * Philips PCVC675 | ||
9 | * Philips PCVC680 | ||
10 | * Philips PCVC690 | ||
11 | * Philips PCVC720/40 | ||
12 | * Philips PCVC730 | ||
13 | * Philips PCVC740 | ||
14 | * Philips PCVC750 | ||
15 | * Askey VC010 | ||
16 | * Creative Labs Webcam 5 | ||
17 | * Creative Labs Webcam Pro Ex | ||
18 | * Logitech QuickCam 3000 Pro | ||
19 | * Logitech QuickCam 4000 Pro | ||
20 | * Logitech QuickCam Notebook Pro | ||
21 | * Logitech QuickCam Zoom | ||
22 | * Logitech QuickCam Orbit | ||
23 | * Logitech QuickCam Sphere | ||
24 | * Samsung MPC-C10 | ||
25 | * Samsung MPC-C30 | ||
26 | * Sotec Afina Eye | ||
27 | * AME CU-001 | ||
28 | * Visionite VCS-UM100 | ||
29 | * Visionite VCS-UC300 | ||
30 | |||
31 | The main webpage for the Philips driver is at the address above. It contains | ||
32 | a lot of extra information, a FAQ, and the binary plugin 'PWCX'. This plugin | ||
33 | contains decompression routines that allow you to use higher image sizes and | ||
34 | framerates; in addition the webcam uses less bandwidth on the USB bus (handy | ||
35 | if you want to run more than 1 camera simultaneously). These routines fall | ||
36 | under a NDA, and may therefor not be distributed as source; however, its use | ||
37 | is completely optional. | ||
38 | |||
39 | You can build this code either into your kernel, or as a module. I recommend | ||
40 | the latter, since it makes troubleshooting a lot easier. The built-in | ||
41 | microphone is supported through the USB Audio class. | ||
42 | |||
43 | When you load the module you can set some default settings for the | ||
44 | camera; some programs depend on a particular image-size or -format and | ||
45 | don't know how to set it properly in the driver. The options are: | ||
46 | |||
47 | size | ||
48 | Can be one of 'sqcif', 'qsif', 'qcif', 'sif', 'cif' or | ||
49 | 'vga', for an image size of resp. 128x96, 160x120, 176x144, | ||
50 | 320x240, 352x288 and 640x480 (of course, only for those cameras that | ||
51 | support these resolutions). | ||
52 | |||
53 | fps | ||
54 | Specifies the desired framerate. Is an integer in the range of 4-30. | ||
55 | |||
56 | fbufs | ||
57 | This paramter specifies the number of internal buffers to use for storing | ||
58 | frames from the cam. This will help if the process that reads images from | ||
59 | the cam is a bit slow or momentarely busy. However, on slow machines it | ||
60 | only introduces lag, so choose carefully. The default is 3, which is | ||
61 | reasonable. You can set it between 2 and 5. | ||
62 | |||
63 | mbufs | ||
64 | This is an integer between 1 and 10. It will tell the module the number of | ||
65 | buffers to reserve for mmap(), VIDIOCCGMBUF, VIDIOCMCAPTURE and friends. | ||
66 | The default is 2, which is adequate for most applications (double | ||
67 | buffering). | ||
68 | |||
69 | Should you experience a lot of 'Dumping frame...' messages during | ||
70 | grabbing with a tool that uses mmap(), you might want to increase if. | ||
71 | However, it doesn't really buffer images, it just gives you a bit more | ||
72 | slack when your program is behind. But you need a multi-threaded or | ||
73 | forked program to really take advantage of these buffers. | ||
74 | |||
75 | The absolute maximum is 10, but don't set it too high! Every buffer takes | ||
76 | up 460 KB of RAM, so unless you have a lot of memory setting this to | ||
77 | something more than 4 is an absolute waste. This memory is only | ||
78 | allocated during open(), so nothing is wasted when the camera is not in | ||
79 | use. | ||
80 | |||
81 | power_save | ||
82 | When power_save is enabled (set to 1), the module will try to shut down | ||
83 | the cam on close() and re-activate on open(). This will save power and | ||
84 | turn off the LED. Not all cameras support this though (the 645 and 646 | ||
85 | don't have power saving at all), and some models don't work either (they | ||
86 | will shut down, but never wake up). Consider this experimental. By | ||
87 | default this option is disabled. | ||
88 | |||
89 | compression (only useful with the plugin) | ||
90 | With this option you can control the compression factor that the camera | ||
91 | uses to squeeze the image through the USB bus. You can set the | ||
92 | parameter between 0 and 3: | ||
93 | 0 = prefer uncompressed images; if the requested mode is not available | ||
94 | in an uncompressed format, the driver will silently switch to low | ||
95 | compression. | ||
96 | 1 = low compression. | ||
97 | 2 = medium compression. | ||
98 | 3 = high compression. | ||
99 | |||
100 | High compression takes less bandwidth of course, but it could also | ||
101 | introduce some unwanted artefacts. The default is 2, medium compression. | ||
102 | See the FAQ on the website for an overview of which modes require | ||
103 | compression. | ||
104 | |||
105 | The compression parameter does not apply to the 645 and 646 cameras | ||
106 | and OEM models derived from those (only a few). Most cams honour this | ||
107 | parameter. | ||
108 | |||
109 | leds | ||
110 | This settings takes 2 integers, that define the on/off time for the LED | ||
111 | (in milliseconds). One of the interesting things that you can do with | ||
112 | this is let the LED blink while the camera is in use. This: | ||
113 | |||
114 | leds=500,500 | ||
115 | |||
116 | will blink the LED once every second. But with: | ||
117 | |||
118 | leds=0,0 | ||
119 | |||
120 | the LED never goes on, making it suitable for silent surveillance. | ||
121 | |||
122 | By default the camera's LED is on solid while in use, and turned off | ||
123 | when the camera is not used anymore. | ||
124 | |||
125 | This parameter works only with the ToUCam range of cameras (720, 730, 740, | ||
126 | 750) and OEMs. For other cameras this command is silently ignored, and | ||
127 | the LED cannot be controlled. | ||
128 | |||
129 | Finally: this parameters does not take effect UNTIL the first time you | ||
130 | open the camera device. Until then, the LED remains on. | ||
131 | |||
132 | dev_hint | ||
133 | A long standing problem with USB devices is their dynamic nature: you | ||
134 | never know what device a camera gets assigned; it depends on module load | ||
135 | order, the hub configuration, the order in which devices are plugged in, | ||
136 | and the phase of the moon (i.e. it can be random). With this option you | ||
137 | can give the driver a hint as to what video device node (/dev/videoX) it | ||
138 | should use with a specific camera. This is also handy if you have two | ||
139 | cameras of the same model. | ||
140 | |||
141 | A camera is specified by its type (the number from the camera model, | ||
142 | like PCA645, PCVC750VC, etc) and optionally the serial number (visible | ||
143 | in /proc/bus/usb/devices). A hint consists of a string with the following | ||
144 | format: | ||
145 | |||
146 | [type[.serialnumber]:]node | ||
147 | |||
148 | The square brackets mean that both the type and the serialnumber are | ||
149 | optional, but a serialnumber cannot be specified without a type (which | ||
150 | would be rather pointless). The serialnumber is separated from the type | ||
151 | by a '.'; the node number by a ':'. | ||
152 | |||
153 | This somewhat cryptic syntax is best explained by a few examples: | ||
154 | |||
155 | dev_hint=3,5 The first detected cam gets assigned | ||
156 | /dev/video3, the second /dev/video5. Any | ||
157 | other cameras will get the first free | ||
158 | available slot (see below). | ||
159 | |||
160 | dev_hint=645:1,680:2 The PCA645 camera will get /dev/video1, | ||
161 | and a PCVC680 /dev/video2. | ||
162 | |||
163 | dev_hint=645.0123:3,645.4567:0 The PCA645 camera with serialnumber | ||
164 | 0123 goes to /dev/video3, the same | ||
165 | camera model with the 4567 serial | ||
166 | gets /dev/video0. | ||
167 | |||
168 | dev_hint=750:1,4,5,6 The PCVC750 camera will get /dev/video1, the | ||
169 | next 3 Philips cams will use /dev/video4 | ||
170 | through /dev/video6. | ||
171 | |||
172 | Some points worth knowing: | ||
173 | - Serialnumbers are case sensitive and must be written full, including | ||
174 | leading zeroes (it's treated as a string). | ||
175 | - If a device node is already occupied, registration will fail and | ||
176 | the webcam is not available. | ||
177 | - You can have up to 64 video devices; be sure to make enough device | ||
178 | nodes in /dev if you want to spread the numbers (this does not apply | ||
179 | to devfs). After /dev/video9 comes /dev/video10 (not /dev/videoA). | ||
180 | - If a camera does not match any dev_hint, it will simply get assigned | ||
181 | the first available device node, just as it used to be. | ||
182 | |||
183 | trace | ||
184 | In order to better detect problems, it is now possible to turn on a | ||
185 | 'trace' of some of the calls the module makes; it logs all items in your | ||
186 | kernel log at debug level. | ||
187 | |||
188 | The trace variable is a bitmask; each bit represents a certain feature. | ||
189 | If you want to trace something, look up the bit value(s) in the table | ||
190 | below, add the values together and supply that to the trace variable. | ||
191 | |||
192 | Value Value Description Default | ||
193 | (dec) (hex) | ||
194 | 1 0x1 Module initialization; this will log messages On | ||
195 | while loading and unloading the module | ||
196 | |||
197 | 2 0x2 probe() and disconnect() traces On | ||
198 | |||
199 | 4 0x4 Trace open() and close() calls Off | ||
200 | |||
201 | 8 0x8 read(), mmap() and associated ioctl() calls Off | ||
202 | |||
203 | 16 0x10 Memory allocation of buffers, etc. Off | ||
204 | |||
205 | 32 0x20 Showing underflow, overflow and Dumping frame On | ||
206 | messages | ||
207 | |||
208 | 64 0x40 Show viewport and image sizes Off | ||
209 | |||
210 | 128 0x80 PWCX debugging Off | ||
211 | |||
212 | For example, to trace the open() & read() fuctions, sum 8 + 4 = 12, | ||
213 | so you would supply trace=12 during insmod or modprobe. If | ||
214 | you want to turn the initialization and probing tracing off, set trace=0. | ||
215 | The default value for trace is 35 (0x23). | ||
216 | |||
217 | |||
218 | |||
219 | Example: | ||
220 | |||
221 | # modprobe pwc size=cif fps=15 power_save=1 | ||
222 | |||
223 | The fbufs, mbufs and trace parameters are global and apply to all connected | ||
224 | cameras. Each camera has its own set of buffers. | ||
225 | |||
226 | size and fps only specify defaults when you open() the device; this is to | ||
227 | accommodate some tools that don't set the size. You can change these | ||
228 | settings after open() with the Video4Linux ioctl() calls. The default of | ||
229 | defaults is QCIF size at 10 fps. | ||
230 | |||
231 | The compression parameter is semiglobal; it sets the initial compression | ||
232 | preference for all camera's, but this parameter can be set per camera with | ||
233 | the VIDIOCPWCSCQUAL ioctl() call. | ||
234 | |||
235 | All parameters are optional. | ||
236 | |||
diff --git a/drivers/media/video/pwc/pwc-ctrl.c b/drivers/media/video/pwc/pwc-ctrl.c new file mode 100644 index 000000000000..0398b812e0ce --- /dev/null +++ b/drivers/media/video/pwc/pwc-ctrl.c | |||
@@ -0,0 +1,1541 @@ | |||
1 | /* Driver for Philips webcam | ||
2 | Functions that send various control messages to the webcam, including | ||
3 | video modes. | ||
4 | (C) 1999-2003 Nemosoft Unv. | ||
5 | (C) 2004 Luc Saillard (luc@saillard.org) | ||
6 | |||
7 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
8 | driver and thus may have bugs that are not present in the original version. | ||
9 | Please send bug reports and support requests to <luc@saillard.org>. | ||
10 | |||
11 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
12 | driver and thus may have bugs that are not present in the original version. | ||
13 | Please send bug reports and support requests to <luc@saillard.org>. | ||
14 | The decompression routines have been implemented by reverse-engineering the | ||
15 | Nemosoft binary pwcx module. Caveat emptor. | ||
16 | |||
17 | This program is free software; you can redistribute it and/or modify | ||
18 | it under the terms of the GNU General Public License as published by | ||
19 | the Free Software Foundation; either version 2 of the License, or | ||
20 | (at your option) any later version. | ||
21 | |||
22 | This program is distributed in the hope that it will be useful, | ||
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
25 | GNU General Public License for more details. | ||
26 | |||
27 | You should have received a copy of the GNU General Public License | ||
28 | along with this program; if not, write to the Free Software | ||
29 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
30 | */ | ||
31 | |||
32 | /* | ||
33 | Changes | ||
34 | 2001/08/03 Alvarado Added methods for changing white balance and | ||
35 | red/green gains | ||
36 | */ | ||
37 | |||
38 | /* Control functions for the cam; brightness, contrast, video mode, etc. */ | ||
39 | |||
40 | #ifdef __KERNEL__ | ||
41 | #include <asm/uaccess.h> | ||
42 | #endif | ||
43 | #include <asm/errno.h> | ||
44 | |||
45 | #include "pwc.h" | ||
46 | #include "pwc-ioctl.h" | ||
47 | #include "pwc-uncompress.h" | ||
48 | #include "pwc-kiara.h" | ||
49 | #include "pwc-timon.h" | ||
50 | |||
51 | /* Request types: video */ | ||
52 | #define SET_LUM_CTL 0x01 | ||
53 | #define GET_LUM_CTL 0x02 | ||
54 | #define SET_CHROM_CTL 0x03 | ||
55 | #define GET_CHROM_CTL 0x04 | ||
56 | #define SET_STATUS_CTL 0x05 | ||
57 | #define GET_STATUS_CTL 0x06 | ||
58 | #define SET_EP_STREAM_CTL 0x07 | ||
59 | #define GET_EP_STREAM_CTL 0x08 | ||
60 | #define SET_MPT_CTL 0x0D | ||
61 | #define GET_MPT_CTL 0x0E | ||
62 | |||
63 | /* Selectors for the Luminance controls [GS]ET_LUM_CTL */ | ||
64 | #define AGC_MODE_FORMATTER 0x2000 | ||
65 | #define PRESET_AGC_FORMATTER 0x2100 | ||
66 | #define SHUTTER_MODE_FORMATTER 0x2200 | ||
67 | #define PRESET_SHUTTER_FORMATTER 0x2300 | ||
68 | #define PRESET_CONTOUR_FORMATTER 0x2400 | ||
69 | #define AUTO_CONTOUR_FORMATTER 0x2500 | ||
70 | #define BACK_LIGHT_COMPENSATION_FORMATTER 0x2600 | ||
71 | #define CONTRAST_FORMATTER 0x2700 | ||
72 | #define DYNAMIC_NOISE_CONTROL_FORMATTER 0x2800 | ||
73 | #define FLICKERLESS_MODE_FORMATTER 0x2900 | ||
74 | #define AE_CONTROL_SPEED 0x2A00 | ||
75 | #define BRIGHTNESS_FORMATTER 0x2B00 | ||
76 | #define GAMMA_FORMATTER 0x2C00 | ||
77 | |||
78 | /* Selectors for the Chrominance controls [GS]ET_CHROM_CTL */ | ||
79 | #define WB_MODE_FORMATTER 0x1000 | ||
80 | #define AWB_CONTROL_SPEED_FORMATTER 0x1100 | ||
81 | #define AWB_CONTROL_DELAY_FORMATTER 0x1200 | ||
82 | #define PRESET_MANUAL_RED_GAIN_FORMATTER 0x1300 | ||
83 | #define PRESET_MANUAL_BLUE_GAIN_FORMATTER 0x1400 | ||
84 | #define COLOUR_MODE_FORMATTER 0x1500 | ||
85 | #define SATURATION_MODE_FORMATTER1 0x1600 | ||
86 | #define SATURATION_MODE_FORMATTER2 0x1700 | ||
87 | |||
88 | /* Selectors for the Status controls [GS]ET_STATUS_CTL */ | ||
89 | #define SAVE_USER_DEFAULTS_FORMATTER 0x0200 | ||
90 | #define RESTORE_USER_DEFAULTS_FORMATTER 0x0300 | ||
91 | #define RESTORE_FACTORY_DEFAULTS_FORMATTER 0x0400 | ||
92 | #define READ_AGC_FORMATTER 0x0500 | ||
93 | #define READ_SHUTTER_FORMATTER 0x0600 | ||
94 | #define READ_RED_GAIN_FORMATTER 0x0700 | ||
95 | #define READ_BLUE_GAIN_FORMATTER 0x0800 | ||
96 | #define SENSOR_TYPE_FORMATTER1 0x0C00 | ||
97 | #define READ_RAW_Y_MEAN_FORMATTER 0x3100 | ||
98 | #define SET_POWER_SAVE_MODE_FORMATTER 0x3200 | ||
99 | #define MIRROR_IMAGE_FORMATTER 0x3300 | ||
100 | #define LED_FORMATTER 0x3400 | ||
101 | #define SENSOR_TYPE_FORMATTER2 0x3700 | ||
102 | |||
103 | /* Formatters for the Video Endpoint controls [GS]ET_EP_STREAM_CTL */ | ||
104 | #define VIDEO_OUTPUT_CONTROL_FORMATTER 0x0100 | ||
105 | |||
106 | /* Formatters for the motorized pan & tilt [GS]ET_MPT_CTL */ | ||
107 | #define PT_RELATIVE_CONTROL_FORMATTER 0x01 | ||
108 | #define PT_RESET_CONTROL_FORMATTER 0x02 | ||
109 | #define PT_STATUS_FORMATTER 0x03 | ||
110 | |||
111 | static const char *size2name[PSZ_MAX] = | ||
112 | { | ||
113 | "subQCIF", | ||
114 | "QSIF", | ||
115 | "QCIF", | ||
116 | "SIF", | ||
117 | "CIF", | ||
118 | "VGA", | ||
119 | }; | ||
120 | |||
121 | /********/ | ||
122 | |||
123 | /* Entries for the Nala (645/646) camera; the Nala doesn't have compression | ||
124 | preferences, so you either get compressed or non-compressed streams. | ||
125 | |||
126 | An alternate value of 0 means this mode is not available at all. | ||
127 | */ | ||
128 | |||
129 | struct Nala_table_entry { | ||
130 | char alternate; /* USB alternate setting */ | ||
131 | int compressed; /* Compressed yes/no */ | ||
132 | |||
133 | unsigned char mode[3]; /* precomputed mode table */ | ||
134 | }; | ||
135 | |||
136 | static struct Nala_table_entry Nala_table[PSZ_MAX][8] = | ||
137 | { | ||
138 | #include "pwc-nala.h" | ||
139 | }; | ||
140 | |||
141 | |||
142 | /****************************************************************************/ | ||
143 | |||
144 | |||
145 | #define SendControlMsg(request, value, buflen) \ | ||
146 | usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0), \ | ||
147 | request, \ | ||
148 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, \ | ||
149 | value, \ | ||
150 | pdev->vcinterface, \ | ||
151 | &buf, buflen, 500) | ||
152 | |||
153 | #define RecvControlMsg(request, value, buflen) \ | ||
154 | usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0), \ | ||
155 | request, \ | ||
156 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, \ | ||
157 | value, \ | ||
158 | pdev->vcinterface, \ | ||
159 | &buf, buflen, 500) | ||
160 | |||
161 | |||
162 | #if PWC_DEBUG | ||
163 | void pwc_hexdump(void *p, int len) | ||
164 | { | ||
165 | int i; | ||
166 | unsigned char *s; | ||
167 | char buf[100], *d; | ||
168 | |||
169 | s = (unsigned char *)p; | ||
170 | d = buf; | ||
171 | *d = '\0'; | ||
172 | Debug("Doing hexdump @ %p, %d bytes.\n", p, len); | ||
173 | for (i = 0; i < len; i++) { | ||
174 | d += sprintf(d, "%02X ", *s++); | ||
175 | if ((i & 0xF) == 0xF) { | ||
176 | Debug("%s\n", buf); | ||
177 | d = buf; | ||
178 | *d = '\0'; | ||
179 | } | ||
180 | } | ||
181 | if ((i & 0xF) != 0) | ||
182 | Debug("%s\n", buf); | ||
183 | } | ||
184 | #endif | ||
185 | |||
186 | static inline int send_video_command(struct usb_device *udev, int index, void *buf, int buflen) | ||
187 | { | ||
188 | return usb_control_msg(udev, | ||
189 | usb_sndctrlpipe(udev, 0), | ||
190 | SET_EP_STREAM_CTL, | ||
191 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
192 | VIDEO_OUTPUT_CONTROL_FORMATTER, | ||
193 | index, | ||
194 | buf, buflen, 1000); | ||
195 | } | ||
196 | |||
197 | |||
198 | |||
199 | static inline int set_video_mode_Nala(struct pwc_device *pdev, int size, int frames) | ||
200 | { | ||
201 | unsigned char buf[3]; | ||
202 | int ret, fps; | ||
203 | struct Nala_table_entry *pEntry; | ||
204 | int frames2frames[31] = | ||
205 | { /* closest match of framerate */ | ||
206 | 0, 0, 0, 0, 4, /* 0-4 */ | ||
207 | 5, 5, 7, 7, 10, /* 5-9 */ | ||
208 | 10, 10, 12, 12, 15, /* 10-14 */ | ||
209 | 15, 15, 15, 20, 20, /* 15-19 */ | ||
210 | 20, 20, 20, 24, 24, /* 20-24 */ | ||
211 | 24, 24, 24, 24, 24, /* 25-29 */ | ||
212 | 24 /* 30 */ | ||
213 | }; | ||
214 | int frames2table[31] = | ||
215 | { 0, 0, 0, 0, 0, /* 0-4 */ | ||
216 | 1, 1, 1, 2, 2, /* 5-9 */ | ||
217 | 3, 3, 4, 4, 4, /* 10-14 */ | ||
218 | 5, 5, 5, 5, 5, /* 15-19 */ | ||
219 | 6, 6, 6, 6, 7, /* 20-24 */ | ||
220 | 7, 7, 7, 7, 7, /* 25-29 */ | ||
221 | 7 /* 30 */ | ||
222 | }; | ||
223 | |||
224 | if (size < 0 || size > PSZ_CIF || frames < 4 || frames > 25) | ||
225 | return -EINVAL; | ||
226 | frames = frames2frames[frames]; | ||
227 | fps = frames2table[frames]; | ||
228 | pEntry = &Nala_table[size][fps]; | ||
229 | if (pEntry->alternate == 0) | ||
230 | return -EINVAL; | ||
231 | |||
232 | if (pEntry->compressed) | ||
233 | return -ENOENT; /* Not supported. */ | ||
234 | |||
235 | memcpy(buf, pEntry->mode, 3); | ||
236 | ret = send_video_command(pdev->udev, pdev->vendpoint, buf, 3); | ||
237 | if (ret < 0) { | ||
238 | Debug("Failed to send video command... %d\n", ret); | ||
239 | return ret; | ||
240 | } | ||
241 | if (pEntry->compressed && pdev->vpalette != VIDEO_PALETTE_RAW) | ||
242 | { | ||
243 | switch(pdev->type) { | ||
244 | case 645: | ||
245 | case 646: | ||
246 | /* pwc_dec1_init(pdev->type, pdev->release, buf, pdev->decompress_data); */ | ||
247 | break; | ||
248 | |||
249 | case 675: | ||
250 | case 680: | ||
251 | case 690: | ||
252 | case 720: | ||
253 | case 730: | ||
254 | case 740: | ||
255 | case 750: | ||
256 | /* pwc_dec23_init(pdev->type, pdev->release, buf, pdev->decompress_data); */ | ||
257 | break; | ||
258 | } | ||
259 | } | ||
260 | |||
261 | pdev->cmd_len = 3; | ||
262 | memcpy(pdev->cmd_buf, buf, 3); | ||
263 | |||
264 | /* Set various parameters */ | ||
265 | pdev->vframes = frames; | ||
266 | pdev->vsize = size; | ||
267 | pdev->valternate = pEntry->alternate; | ||
268 | pdev->image = pwc_image_sizes[size]; | ||
269 | pdev->frame_size = (pdev->image.x * pdev->image.y * 3) / 2; | ||
270 | if (pEntry->compressed) { | ||
271 | if (pdev->release < 5) { /* 4 fold compression */ | ||
272 | pdev->vbandlength = 528; | ||
273 | pdev->frame_size /= 4; | ||
274 | } | ||
275 | else { | ||
276 | pdev->vbandlength = 704; | ||
277 | pdev->frame_size /= 3; | ||
278 | } | ||
279 | } | ||
280 | else | ||
281 | pdev->vbandlength = 0; | ||
282 | return 0; | ||
283 | } | ||
284 | |||
285 | |||
286 | static inline int set_video_mode_Timon(struct pwc_device *pdev, int size, int frames, int compression, int snapshot) | ||
287 | { | ||
288 | unsigned char buf[13]; | ||
289 | const struct Timon_table_entry *pChoose; | ||
290 | int ret, fps; | ||
291 | |||
292 | if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3) | ||
293 | return -EINVAL; | ||
294 | if (size == PSZ_VGA && frames > 15) | ||
295 | return -EINVAL; | ||
296 | fps = (frames / 5) - 1; | ||
297 | |||
298 | /* Find a supported framerate with progressively higher compression ratios | ||
299 | if the preferred ratio is not available. | ||
300 | */ | ||
301 | pChoose = NULL; | ||
302 | while (compression <= 3) { | ||
303 | pChoose = &Timon_table[size][fps][compression]; | ||
304 | if (pChoose->alternate != 0) | ||
305 | break; | ||
306 | compression++; | ||
307 | } | ||
308 | if (pChoose == NULL || pChoose->alternate == 0) | ||
309 | return -ENOENT; /* Not supported. */ | ||
310 | |||
311 | memcpy(buf, pChoose->mode, 13); | ||
312 | if (snapshot) | ||
313 | buf[0] |= 0x80; | ||
314 | ret = send_video_command(pdev->udev, pdev->vendpoint, buf, 13); | ||
315 | if (ret < 0) | ||
316 | return ret; | ||
317 | |||
318 | /* if (pChoose->bandlength > 0 && pdev->vpalette != VIDEO_PALETTE_RAW) | ||
319 | pwc_dec23_init(pdev->type, pdev->release, buf, pdev->decompress_data); */ | ||
320 | |||
321 | pdev->cmd_len = 13; | ||
322 | memcpy(pdev->cmd_buf, buf, 13); | ||
323 | |||
324 | /* Set various parameters */ | ||
325 | pdev->vframes = frames; | ||
326 | pdev->vsize = size; | ||
327 | pdev->vsnapshot = snapshot; | ||
328 | pdev->valternate = pChoose->alternate; | ||
329 | pdev->image = pwc_image_sizes[size]; | ||
330 | pdev->vbandlength = pChoose->bandlength; | ||
331 | if (pChoose->bandlength > 0) | ||
332 | pdev->frame_size = (pChoose->bandlength * pdev->image.y) / 4; | ||
333 | else | ||
334 | pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8; | ||
335 | return 0; | ||
336 | } | ||
337 | |||
338 | |||
339 | static inline int set_video_mode_Kiara(struct pwc_device *pdev, int size, int frames, int compression, int snapshot) | ||
340 | { | ||
341 | const struct Kiara_table_entry *pChoose = NULL; | ||
342 | int fps, ret; | ||
343 | unsigned char buf[12]; | ||
344 | struct Kiara_table_entry RawEntry = {6, 773, 1272, {0xAD, 0xF4, 0x10, 0x27, 0xB6, 0x24, 0x96, 0x02, 0x30, 0x05, 0x03, 0x80}}; | ||
345 | |||
346 | if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3) | ||
347 | return -EINVAL; | ||
348 | if (size == PSZ_VGA && frames > 15) | ||
349 | return -EINVAL; | ||
350 | fps = (frames / 5) - 1; | ||
351 | |||
352 | /* special case: VGA @ 5 fps and snapshot is raw bayer mode */ | ||
353 | if (size == PSZ_VGA && frames == 5 && snapshot) | ||
354 | { | ||
355 | /* Only available in case the raw palette is selected or | ||
356 | we have the decompressor available. This mode is | ||
357 | only available in compressed form | ||
358 | */ | ||
359 | if (pdev->vpalette == VIDEO_PALETTE_RAW) | ||
360 | { | ||
361 | Info("Choosing VGA/5 BAYER mode (%d).\n", pdev->vpalette); | ||
362 | pChoose = &RawEntry; | ||
363 | } | ||
364 | else | ||
365 | { | ||
366 | Info("VGA/5 BAYER mode _must_ have a decompressor available, or use RAW palette.\n"); | ||
367 | } | ||
368 | } | ||
369 | else | ||
370 | { | ||
371 | /* Find a supported framerate with progressively higher compression ratios | ||
372 | if the preferred ratio is not available. | ||
373 | Skip this step when using RAW modes. | ||
374 | */ | ||
375 | while (compression <= 3) { | ||
376 | pChoose = &Kiara_table[size][fps][compression]; | ||
377 | if (pChoose->alternate != 0) | ||
378 | break; | ||
379 | compression++; | ||
380 | } | ||
381 | } | ||
382 | if (pChoose == NULL || pChoose->alternate == 0) | ||
383 | return -ENOENT; /* Not supported. */ | ||
384 | |||
385 | Debug("Using alternate setting %d.\n", pChoose->alternate); | ||
386 | |||
387 | /* usb_control_msg won't take staticly allocated arrays as argument?? */ | ||
388 | memcpy(buf, pChoose->mode, 12); | ||
389 | if (snapshot) | ||
390 | buf[0] |= 0x80; | ||
391 | |||
392 | /* Firmware bug: video endpoint is 5, but commands are sent to endpoint 4 */ | ||
393 | ret = send_video_command(pdev->udev, 4 /* pdev->vendpoint */, buf, 12); | ||
394 | if (ret < 0) | ||
395 | return ret; | ||
396 | |||
397 | /* if (pChoose->bandlength > 0 && pdev->vpalette != VIDEO_PALETTE_RAW) | ||
398 | pwc_dec23_init(pdev->type, pdev->release, buf, pdev->decompress_data); */ | ||
399 | |||
400 | pdev->cmd_len = 12; | ||
401 | memcpy(pdev->cmd_buf, buf, 12); | ||
402 | /* All set and go */ | ||
403 | pdev->vframes = frames; | ||
404 | pdev->vsize = size; | ||
405 | pdev->vsnapshot = snapshot; | ||
406 | pdev->valternate = pChoose->alternate; | ||
407 | pdev->image = pwc_image_sizes[size]; | ||
408 | pdev->vbandlength = pChoose->bandlength; | ||
409 | if (pdev->vbandlength > 0) | ||
410 | pdev->frame_size = (pdev->vbandlength * pdev->image.y) / 4; | ||
411 | else | ||
412 | pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8; | ||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | |||
417 | |||
418 | static void pwc_set_image_buffer_size(struct pwc_device *pdev) | ||
419 | { | ||
420 | int i, factor = 0, filler = 0; | ||
421 | |||
422 | /* for PALETTE_YUV420P */ | ||
423 | switch(pdev->vpalette) | ||
424 | { | ||
425 | case VIDEO_PALETTE_YUV420P: | ||
426 | factor = 6; | ||
427 | filler = 128; | ||
428 | break; | ||
429 | case VIDEO_PALETTE_RAW: | ||
430 | factor = 6; /* can be uncompressed YUV420P */ | ||
431 | filler = 0; | ||
432 | break; | ||
433 | } | ||
434 | |||
435 | /* Set sizes in bytes */ | ||
436 | pdev->image.size = pdev->image.x * pdev->image.y * factor / 4; | ||
437 | pdev->view.size = pdev->view.x * pdev->view.y * factor / 4; | ||
438 | |||
439 | /* Align offset, or you'll get some very weird results in | ||
440 | YUV420 mode... x must be multiple of 4 (to get the Y's in | ||
441 | place), and y even (or you'll mixup U & V). This is less of a | ||
442 | problem for YUV420P. | ||
443 | */ | ||
444 | pdev->offset.x = ((pdev->view.x - pdev->image.x) / 2) & 0xFFFC; | ||
445 | pdev->offset.y = ((pdev->view.y - pdev->image.y) / 2) & 0xFFFE; | ||
446 | |||
447 | /* Fill buffers with gray or black */ | ||
448 | for (i = 0; i < MAX_IMAGES; i++) { | ||
449 | if (pdev->image_ptr[i] != NULL) | ||
450 | memset(pdev->image_ptr[i], filler, pdev->view.size); | ||
451 | } | ||
452 | } | ||
453 | |||
454 | |||
455 | |||
456 | /** | ||
457 | @pdev: device structure | ||
458 | @width: viewport width | ||
459 | @height: viewport height | ||
460 | @frame: framerate, in fps | ||
461 | @compression: preferred compression ratio | ||
462 | @snapshot: snapshot mode or streaming | ||
463 | */ | ||
464 | int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frames, int compression, int snapshot) | ||
465 | { | ||
466 | int ret, size; | ||
467 | |||
468 | Trace(TRACE_FLOW, "set_video_mode(%dx%d @ %d, palette %d).\n", width, height, frames, pdev->vpalette); | ||
469 | size = pwc_decode_size(pdev, width, height); | ||
470 | if (size < 0) { | ||
471 | Debug("Could not find suitable size.\n"); | ||
472 | return -ERANGE; | ||
473 | } | ||
474 | Debug("decode_size = %d.\n", size); | ||
475 | |||
476 | ret = -EINVAL; | ||
477 | switch(pdev->type) { | ||
478 | case 645: | ||
479 | case 646: | ||
480 | ret = set_video_mode_Nala(pdev, size, frames); | ||
481 | break; | ||
482 | |||
483 | case 675: | ||
484 | case 680: | ||
485 | case 690: | ||
486 | ret = set_video_mode_Timon(pdev, size, frames, compression, snapshot); | ||
487 | break; | ||
488 | |||
489 | case 720: | ||
490 | case 730: | ||
491 | case 740: | ||
492 | case 750: | ||
493 | ret = set_video_mode_Kiara(pdev, size, frames, compression, snapshot); | ||
494 | break; | ||
495 | } | ||
496 | if (ret < 0) { | ||
497 | if (ret == -ENOENT) | ||
498 | Info("Video mode %s@%d fps is only supported with the decompressor module (pwcx).\n", size2name[size], frames); | ||
499 | else { | ||
500 | Err("Failed to set video mode %s@%d fps; return code = %d\n", size2name[size], frames, ret); | ||
501 | } | ||
502 | return ret; | ||
503 | } | ||
504 | pdev->view.x = width; | ||
505 | pdev->view.y = height; | ||
506 | pdev->frame_total_size = pdev->frame_size + pdev->frame_header_size + pdev->frame_trailer_size; | ||
507 | pwc_set_image_buffer_size(pdev); | ||
508 | Trace(TRACE_SIZE, "Set viewport to %dx%d, image size is %dx%d.\n", width, height, pwc_image_sizes[size].x, pwc_image_sizes[size].y); | ||
509 | return 0; | ||
510 | } | ||
511 | |||
512 | |||
513 | /* BRIGHTNESS */ | ||
514 | |||
515 | int pwc_get_brightness(struct pwc_device *pdev) | ||
516 | { | ||
517 | char buf; | ||
518 | int ret; | ||
519 | |||
520 | ret = RecvControlMsg(GET_LUM_CTL, BRIGHTNESS_FORMATTER, 1); | ||
521 | if (ret < 0) | ||
522 | return ret; | ||
523 | return buf << 9; | ||
524 | } | ||
525 | |||
526 | int pwc_set_brightness(struct pwc_device *pdev, int value) | ||
527 | { | ||
528 | char buf; | ||
529 | |||
530 | if (value < 0) | ||
531 | value = 0; | ||
532 | if (value > 0xffff) | ||
533 | value = 0xffff; | ||
534 | buf = (value >> 9) & 0x7f; | ||
535 | return SendControlMsg(SET_LUM_CTL, BRIGHTNESS_FORMATTER, 1); | ||
536 | } | ||
537 | |||
538 | /* CONTRAST */ | ||
539 | |||
540 | int pwc_get_contrast(struct pwc_device *pdev) | ||
541 | { | ||
542 | char buf; | ||
543 | int ret; | ||
544 | |||
545 | ret = RecvControlMsg(GET_LUM_CTL, CONTRAST_FORMATTER, 1); | ||
546 | if (ret < 0) | ||
547 | return ret; | ||
548 | return buf << 10; | ||
549 | } | ||
550 | |||
551 | int pwc_set_contrast(struct pwc_device *pdev, int value) | ||
552 | { | ||
553 | char buf; | ||
554 | |||
555 | if (value < 0) | ||
556 | value = 0; | ||
557 | if (value > 0xffff) | ||
558 | value = 0xffff; | ||
559 | buf = (value >> 10) & 0x3f; | ||
560 | return SendControlMsg(SET_LUM_CTL, CONTRAST_FORMATTER, 1); | ||
561 | } | ||
562 | |||
563 | /* GAMMA */ | ||
564 | |||
565 | int pwc_get_gamma(struct pwc_device *pdev) | ||
566 | { | ||
567 | char buf; | ||
568 | int ret; | ||
569 | |||
570 | ret = RecvControlMsg(GET_LUM_CTL, GAMMA_FORMATTER, 1); | ||
571 | if (ret < 0) | ||
572 | return ret; | ||
573 | return buf << 11; | ||
574 | } | ||
575 | |||
576 | int pwc_set_gamma(struct pwc_device *pdev, int value) | ||
577 | { | ||
578 | char buf; | ||
579 | |||
580 | if (value < 0) | ||
581 | value = 0; | ||
582 | if (value > 0xffff) | ||
583 | value = 0xffff; | ||
584 | buf = (value >> 11) & 0x1f; | ||
585 | return SendControlMsg(SET_LUM_CTL, GAMMA_FORMATTER, 1); | ||
586 | } | ||
587 | |||
588 | |||
589 | /* SATURATION */ | ||
590 | |||
591 | int pwc_get_saturation(struct pwc_device *pdev) | ||
592 | { | ||
593 | char buf; | ||
594 | int ret; | ||
595 | |||
596 | if (pdev->type < 675) | ||
597 | return -1; | ||
598 | ret = RecvControlMsg(GET_CHROM_CTL, pdev->type < 730 ? SATURATION_MODE_FORMATTER2 : SATURATION_MODE_FORMATTER1, 1); | ||
599 | if (ret < 0) | ||
600 | return ret; | ||
601 | return 32768 + buf * 327; | ||
602 | } | ||
603 | |||
604 | int pwc_set_saturation(struct pwc_device *pdev, int value) | ||
605 | { | ||
606 | char buf; | ||
607 | |||
608 | if (pdev->type < 675) | ||
609 | return -EINVAL; | ||
610 | if (value < 0) | ||
611 | value = 0; | ||
612 | if (value > 0xffff) | ||
613 | value = 0xffff; | ||
614 | /* saturation ranges from -100 to +100 */ | ||
615 | buf = (value - 32768) / 327; | ||
616 | return SendControlMsg(SET_CHROM_CTL, pdev->type < 730 ? SATURATION_MODE_FORMATTER2 : SATURATION_MODE_FORMATTER1, 1); | ||
617 | } | ||
618 | |||
619 | /* AGC */ | ||
620 | |||
621 | static inline int pwc_set_agc(struct pwc_device *pdev, int mode, int value) | ||
622 | { | ||
623 | char buf; | ||
624 | int ret; | ||
625 | |||
626 | if (mode) | ||
627 | buf = 0x0; /* auto */ | ||
628 | else | ||
629 | buf = 0xff; /* fixed */ | ||
630 | |||
631 | ret = SendControlMsg(SET_LUM_CTL, AGC_MODE_FORMATTER, 1); | ||
632 | |||
633 | if (!mode && ret >= 0) { | ||
634 | if (value < 0) | ||
635 | value = 0; | ||
636 | if (value > 0xffff) | ||
637 | value = 0xffff; | ||
638 | buf = (value >> 10) & 0x3F; | ||
639 | ret = SendControlMsg(SET_LUM_CTL, PRESET_AGC_FORMATTER, 1); | ||
640 | } | ||
641 | if (ret < 0) | ||
642 | return ret; | ||
643 | return 0; | ||
644 | } | ||
645 | |||
646 | static inline int pwc_get_agc(struct pwc_device *pdev, int *value) | ||
647 | { | ||
648 | unsigned char buf; | ||
649 | int ret; | ||
650 | |||
651 | ret = RecvControlMsg(GET_LUM_CTL, AGC_MODE_FORMATTER, 1); | ||
652 | if (ret < 0) | ||
653 | return ret; | ||
654 | |||
655 | if (buf != 0) { /* fixed */ | ||
656 | ret = RecvControlMsg(GET_LUM_CTL, PRESET_AGC_FORMATTER, 1); | ||
657 | if (ret < 0) | ||
658 | return ret; | ||
659 | if (buf > 0x3F) | ||
660 | buf = 0x3F; | ||
661 | *value = (buf << 10); | ||
662 | } | ||
663 | else { /* auto */ | ||
664 | ret = RecvControlMsg(GET_STATUS_CTL, READ_AGC_FORMATTER, 1); | ||
665 | if (ret < 0) | ||
666 | return ret; | ||
667 | /* Gah... this value ranges from 0x00 ... 0x9F */ | ||
668 | if (buf > 0x9F) | ||
669 | buf = 0x9F; | ||
670 | *value = -(48 + buf * 409); | ||
671 | } | ||
672 | |||
673 | return 0; | ||
674 | } | ||
675 | |||
676 | static inline int pwc_set_shutter_speed(struct pwc_device *pdev, int mode, int value) | ||
677 | { | ||
678 | char buf[2]; | ||
679 | int speed, ret; | ||
680 | |||
681 | |||
682 | if (mode) | ||
683 | buf[0] = 0x0; /* auto */ | ||
684 | else | ||
685 | buf[0] = 0xff; /* fixed */ | ||
686 | |||
687 | ret = SendControlMsg(SET_LUM_CTL, SHUTTER_MODE_FORMATTER, 1); | ||
688 | |||
689 | if (!mode && ret >= 0) { | ||
690 | if (value < 0) | ||
691 | value = 0; | ||
692 | if (value > 0xffff) | ||
693 | value = 0xffff; | ||
694 | switch(pdev->type) { | ||
695 | case 675: | ||
696 | case 680: | ||
697 | case 690: | ||
698 | /* speed ranges from 0x0 to 0x290 (656) */ | ||
699 | speed = (value / 100); | ||
700 | buf[1] = speed >> 8; | ||
701 | buf[0] = speed & 0xff; | ||
702 | break; | ||
703 | case 720: | ||
704 | case 730: | ||
705 | case 740: | ||
706 | case 750: | ||
707 | /* speed seems to range from 0x0 to 0xff */ | ||
708 | buf[1] = 0; | ||
709 | buf[0] = value >> 8; | ||
710 | break; | ||
711 | } | ||
712 | |||
713 | ret = SendControlMsg(SET_LUM_CTL, PRESET_SHUTTER_FORMATTER, 2); | ||
714 | } | ||
715 | return ret; | ||
716 | } | ||
717 | |||
718 | |||
719 | /* POWER */ | ||
720 | |||
721 | int pwc_camera_power(struct pwc_device *pdev, int power) | ||
722 | { | ||
723 | char buf; | ||
724 | |||
725 | if (pdev->type < 675 || (pdev->type < 730 && pdev->release < 6)) | ||
726 | return 0; /* Not supported by Nala or Timon < release 6 */ | ||
727 | |||
728 | if (power) | ||
729 | buf = 0x00; /* active */ | ||
730 | else | ||
731 | buf = 0xFF; /* power save */ | ||
732 | return SendControlMsg(SET_STATUS_CTL, SET_POWER_SAVE_MODE_FORMATTER, 1); | ||
733 | } | ||
734 | |||
735 | |||
736 | |||
737 | /* private calls */ | ||
738 | |||
739 | static inline int pwc_restore_user(struct pwc_device *pdev) | ||
740 | { | ||
741 | char buf; /* dummy */ | ||
742 | return SendControlMsg(SET_STATUS_CTL, RESTORE_USER_DEFAULTS_FORMATTER, 0); | ||
743 | } | ||
744 | |||
745 | static inline int pwc_save_user(struct pwc_device *pdev) | ||
746 | { | ||
747 | char buf; /* dummy */ | ||
748 | return SendControlMsg(SET_STATUS_CTL, SAVE_USER_DEFAULTS_FORMATTER, 0); | ||
749 | } | ||
750 | |||
751 | static inline int pwc_restore_factory(struct pwc_device *pdev) | ||
752 | { | ||
753 | char buf; /* dummy */ | ||
754 | return SendControlMsg(SET_STATUS_CTL, RESTORE_FACTORY_DEFAULTS_FORMATTER, 0); | ||
755 | } | ||
756 | |||
757 | /* ************************************************* */ | ||
758 | /* Patch by Alvarado: (not in the original version */ | ||
759 | |||
760 | /* | ||
761 | * the camera recognizes modes from 0 to 4: | ||
762 | * | ||
763 | * 00: indoor (incandescant lighting) | ||
764 | * 01: outdoor (sunlight) | ||
765 | * 02: fluorescent lighting | ||
766 | * 03: manual | ||
767 | * 04: auto | ||
768 | */ | ||
769 | static inline int pwc_set_awb(struct pwc_device *pdev, int mode) | ||
770 | { | ||
771 | char buf; | ||
772 | int ret; | ||
773 | |||
774 | if (mode < 0) | ||
775 | mode = 0; | ||
776 | |||
777 | if (mode > 4) | ||
778 | mode = 4; | ||
779 | |||
780 | buf = mode & 0x07; /* just the lowest three bits */ | ||
781 | |||
782 | ret = SendControlMsg(SET_CHROM_CTL, WB_MODE_FORMATTER, 1); | ||
783 | |||
784 | if (ret < 0) | ||
785 | return ret; | ||
786 | return 0; | ||
787 | } | ||
788 | |||
789 | static inline int pwc_get_awb(struct pwc_device *pdev) | ||
790 | { | ||
791 | unsigned char buf; | ||
792 | int ret; | ||
793 | |||
794 | ret = RecvControlMsg(GET_CHROM_CTL, WB_MODE_FORMATTER, 1); | ||
795 | |||
796 | if (ret < 0) | ||
797 | return ret; | ||
798 | return buf; | ||
799 | } | ||
800 | |||
801 | static inline int pwc_set_red_gain(struct pwc_device *pdev, int value) | ||
802 | { | ||
803 | unsigned char buf; | ||
804 | |||
805 | if (value < 0) | ||
806 | value = 0; | ||
807 | if (value > 0xffff) | ||
808 | value = 0xffff; | ||
809 | /* only the msb is considered */ | ||
810 | buf = value >> 8; | ||
811 | return SendControlMsg(SET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, 1); | ||
812 | } | ||
813 | |||
814 | static inline int pwc_get_red_gain(struct pwc_device *pdev, int *value) | ||
815 | { | ||
816 | unsigned char buf; | ||
817 | int ret; | ||
818 | |||
819 | ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, 1); | ||
820 | if (ret < 0) | ||
821 | return ret; | ||
822 | *value = buf << 8; | ||
823 | return 0; | ||
824 | } | ||
825 | |||
826 | |||
827 | static inline int pwc_set_blue_gain(struct pwc_device *pdev, int value) | ||
828 | { | ||
829 | unsigned char buf; | ||
830 | |||
831 | if (value < 0) | ||
832 | value = 0; | ||
833 | if (value > 0xffff) | ||
834 | value = 0xffff; | ||
835 | /* only the msb is considered */ | ||
836 | buf = value >> 8; | ||
837 | return SendControlMsg(SET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, 1); | ||
838 | } | ||
839 | |||
840 | static inline int pwc_get_blue_gain(struct pwc_device *pdev, int *value) | ||
841 | { | ||
842 | unsigned char buf; | ||
843 | int ret; | ||
844 | |||
845 | ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, 1); | ||
846 | if (ret < 0) | ||
847 | return ret; | ||
848 | *value = buf << 8; | ||
849 | return 0; | ||
850 | } | ||
851 | |||
852 | |||
853 | /* The following two functions are different, since they only read the | ||
854 | internal red/blue gains, which may be different from the manual | ||
855 | gains set or read above. | ||
856 | */ | ||
857 | static inline int pwc_read_red_gain(struct pwc_device *pdev, int *value) | ||
858 | { | ||
859 | unsigned char buf; | ||
860 | int ret; | ||
861 | |||
862 | ret = RecvControlMsg(GET_STATUS_CTL, READ_RED_GAIN_FORMATTER, 1); | ||
863 | if (ret < 0) | ||
864 | return ret; | ||
865 | *value = buf << 8; | ||
866 | return 0; | ||
867 | } | ||
868 | |||
869 | static inline int pwc_read_blue_gain(struct pwc_device *pdev, int *value) | ||
870 | { | ||
871 | unsigned char buf; | ||
872 | int ret; | ||
873 | |||
874 | ret = RecvControlMsg(GET_STATUS_CTL, READ_BLUE_GAIN_FORMATTER, 1); | ||
875 | if (ret < 0) | ||
876 | return ret; | ||
877 | *value = buf << 8; | ||
878 | return 0; | ||
879 | } | ||
880 | |||
881 | |||
882 | static inline int pwc_set_wb_speed(struct pwc_device *pdev, int speed) | ||
883 | { | ||
884 | unsigned char buf; | ||
885 | |||
886 | /* useful range is 0x01..0x20 */ | ||
887 | buf = speed / 0x7f0; | ||
888 | return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1); | ||
889 | } | ||
890 | |||
891 | static inline int pwc_get_wb_speed(struct pwc_device *pdev, int *value) | ||
892 | { | ||
893 | unsigned char buf; | ||
894 | int ret; | ||
895 | |||
896 | ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1); | ||
897 | if (ret < 0) | ||
898 | return ret; | ||
899 | *value = buf * 0x7f0; | ||
900 | return 0; | ||
901 | } | ||
902 | |||
903 | |||
904 | static inline int pwc_set_wb_delay(struct pwc_device *pdev, int delay) | ||
905 | { | ||
906 | unsigned char buf; | ||
907 | |||
908 | /* useful range is 0x01..0x3F */ | ||
909 | buf = (delay >> 10); | ||
910 | return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1); | ||
911 | } | ||
912 | |||
913 | static inline int pwc_get_wb_delay(struct pwc_device *pdev, int *value) | ||
914 | { | ||
915 | unsigned char buf; | ||
916 | int ret; | ||
917 | |||
918 | ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1); | ||
919 | if (ret < 0) | ||
920 | return ret; | ||
921 | *value = buf << 10; | ||
922 | return 0; | ||
923 | } | ||
924 | |||
925 | |||
926 | int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value) | ||
927 | { | ||
928 | unsigned char buf[2]; | ||
929 | |||
930 | if (pdev->type < 730) | ||
931 | return 0; | ||
932 | on_value /= 100; | ||
933 | off_value /= 100; | ||
934 | if (on_value < 0) | ||
935 | on_value = 0; | ||
936 | if (on_value > 0xff) | ||
937 | on_value = 0xff; | ||
938 | if (off_value < 0) | ||
939 | off_value = 0; | ||
940 | if (off_value > 0xff) | ||
941 | off_value = 0xff; | ||
942 | |||
943 | buf[0] = on_value; | ||
944 | buf[1] = off_value; | ||
945 | |||
946 | return SendControlMsg(SET_STATUS_CTL, LED_FORMATTER, 2); | ||
947 | } | ||
948 | |||
949 | static int pwc_get_leds(struct pwc_device *pdev, int *on_value, int *off_value) | ||
950 | { | ||
951 | unsigned char buf[2]; | ||
952 | int ret; | ||
953 | |||
954 | if (pdev->type < 730) { | ||
955 | *on_value = -1; | ||
956 | *off_value = -1; | ||
957 | return 0; | ||
958 | } | ||
959 | |||
960 | ret = RecvControlMsg(GET_STATUS_CTL, LED_FORMATTER, 2); | ||
961 | if (ret < 0) | ||
962 | return ret; | ||
963 | *on_value = buf[0] * 100; | ||
964 | *off_value = buf[1] * 100; | ||
965 | return 0; | ||
966 | } | ||
967 | |||
968 | static inline int pwc_set_contour(struct pwc_device *pdev, int contour) | ||
969 | { | ||
970 | unsigned char buf; | ||
971 | int ret; | ||
972 | |||
973 | if (contour < 0) | ||
974 | buf = 0xff; /* auto contour on */ | ||
975 | else | ||
976 | buf = 0x0; /* auto contour off */ | ||
977 | ret = SendControlMsg(SET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1); | ||
978 | if (ret < 0) | ||
979 | return ret; | ||
980 | |||
981 | if (contour < 0) | ||
982 | return 0; | ||
983 | if (contour > 0xffff) | ||
984 | contour = 0xffff; | ||
985 | |||
986 | buf = (contour >> 10); /* contour preset is [0..3f] */ | ||
987 | ret = SendControlMsg(SET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1); | ||
988 | if (ret < 0) | ||
989 | return ret; | ||
990 | return 0; | ||
991 | } | ||
992 | |||
993 | static inline int pwc_get_contour(struct pwc_device *pdev, int *contour) | ||
994 | { | ||
995 | unsigned char buf; | ||
996 | int ret; | ||
997 | |||
998 | ret = RecvControlMsg(GET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1); | ||
999 | if (ret < 0) | ||
1000 | return ret; | ||
1001 | |||
1002 | if (buf == 0) { | ||
1003 | /* auto mode off, query current preset value */ | ||
1004 | ret = RecvControlMsg(GET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1); | ||
1005 | if (ret < 0) | ||
1006 | return ret; | ||
1007 | *contour = buf << 10; | ||
1008 | } | ||
1009 | else | ||
1010 | *contour = -1; | ||
1011 | return 0; | ||
1012 | } | ||
1013 | |||
1014 | |||
1015 | static inline int pwc_set_backlight(struct pwc_device *pdev, int backlight) | ||
1016 | { | ||
1017 | unsigned char buf; | ||
1018 | |||
1019 | if (backlight) | ||
1020 | buf = 0xff; | ||
1021 | else | ||
1022 | buf = 0x0; | ||
1023 | return SendControlMsg(SET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, 1); | ||
1024 | } | ||
1025 | |||
1026 | static inline int pwc_get_backlight(struct pwc_device *pdev, int *backlight) | ||
1027 | { | ||
1028 | int ret; | ||
1029 | unsigned char buf; | ||
1030 | |||
1031 | ret = RecvControlMsg(GET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, 1); | ||
1032 | if (ret < 0) | ||
1033 | return ret; | ||
1034 | *backlight = buf; | ||
1035 | return 0; | ||
1036 | } | ||
1037 | |||
1038 | |||
1039 | static inline int pwc_set_flicker(struct pwc_device *pdev, int flicker) | ||
1040 | { | ||
1041 | unsigned char buf; | ||
1042 | |||
1043 | if (flicker) | ||
1044 | buf = 0xff; | ||
1045 | else | ||
1046 | buf = 0x0; | ||
1047 | return SendControlMsg(SET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1); | ||
1048 | } | ||
1049 | |||
1050 | static inline int pwc_get_flicker(struct pwc_device *pdev, int *flicker) | ||
1051 | { | ||
1052 | int ret; | ||
1053 | unsigned char buf; | ||
1054 | |||
1055 | ret = RecvControlMsg(GET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1); | ||
1056 | if (ret < 0) | ||
1057 | return ret; | ||
1058 | *flicker = buf; | ||
1059 | return 0; | ||
1060 | } | ||
1061 | |||
1062 | |||
1063 | static inline int pwc_set_dynamic_noise(struct pwc_device *pdev, int noise) | ||
1064 | { | ||
1065 | unsigned char buf; | ||
1066 | |||
1067 | if (noise < 0) | ||
1068 | noise = 0; | ||
1069 | if (noise > 3) | ||
1070 | noise = 3; | ||
1071 | buf = noise; | ||
1072 | return SendControlMsg(SET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1); | ||
1073 | } | ||
1074 | |||
1075 | static inline int pwc_get_dynamic_noise(struct pwc_device *pdev, int *noise) | ||
1076 | { | ||
1077 | int ret; | ||
1078 | unsigned char buf; | ||
1079 | |||
1080 | ret = RecvControlMsg(GET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1); | ||
1081 | if (ret < 0) | ||
1082 | return ret; | ||
1083 | *noise = buf; | ||
1084 | return 0; | ||
1085 | } | ||
1086 | |||
1087 | static int pwc_mpt_reset(struct pwc_device *pdev, int flags) | ||
1088 | { | ||
1089 | unsigned char buf; | ||
1090 | |||
1091 | buf = flags & 0x03; // only lower two bits are currently used | ||
1092 | return SendControlMsg(SET_MPT_CTL, PT_RESET_CONTROL_FORMATTER, 1); | ||
1093 | } | ||
1094 | |||
1095 | static inline int pwc_mpt_set_angle(struct pwc_device *pdev, int pan, int tilt) | ||
1096 | { | ||
1097 | unsigned char buf[4]; | ||
1098 | |||
1099 | /* set new relative angle; angles are expressed in degrees * 100, | ||
1100 | but cam as .5 degree resolution, hence divide by 200. Also | ||
1101 | the angle must be multiplied by 64 before it's send to | ||
1102 | the cam (??) | ||
1103 | */ | ||
1104 | pan = 64 * pan / 100; | ||
1105 | tilt = -64 * tilt / 100; /* positive tilt is down, which is not what the user would expect */ | ||
1106 | buf[0] = pan & 0xFF; | ||
1107 | buf[1] = (pan >> 8) & 0xFF; | ||
1108 | buf[2] = tilt & 0xFF; | ||
1109 | buf[3] = (tilt >> 8) & 0xFF; | ||
1110 | return SendControlMsg(SET_MPT_CTL, PT_RELATIVE_CONTROL_FORMATTER, 4); | ||
1111 | } | ||
1112 | |||
1113 | static inline int pwc_mpt_get_status(struct pwc_device *pdev, struct pwc_mpt_status *status) | ||
1114 | { | ||
1115 | int ret; | ||
1116 | unsigned char buf[5]; | ||
1117 | |||
1118 | ret = RecvControlMsg(GET_MPT_CTL, PT_STATUS_FORMATTER, 5); | ||
1119 | if (ret < 0) | ||
1120 | return ret; | ||
1121 | status->status = buf[0] & 0x7; // 3 bits are used for reporting | ||
1122 | status->time_pan = (buf[1] << 8) + buf[2]; | ||
1123 | status->time_tilt = (buf[3] << 8) + buf[4]; | ||
1124 | return 0; | ||
1125 | } | ||
1126 | |||
1127 | |||
1128 | int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor) | ||
1129 | { | ||
1130 | unsigned char buf; | ||
1131 | int ret = -1, request; | ||
1132 | |||
1133 | if (pdev->type < 675) | ||
1134 | request = SENSOR_TYPE_FORMATTER1; | ||
1135 | else if (pdev->type < 730) | ||
1136 | return -1; /* The Vesta series doesn't have this call */ | ||
1137 | else | ||
1138 | request = SENSOR_TYPE_FORMATTER2; | ||
1139 | |||
1140 | ret = RecvControlMsg(GET_STATUS_CTL, request, 1); | ||
1141 | if (ret < 0) | ||
1142 | return ret; | ||
1143 | if (pdev->type < 675) | ||
1144 | *sensor = buf | 0x100; | ||
1145 | else | ||
1146 | *sensor = buf; | ||
1147 | return 0; | ||
1148 | } | ||
1149 | |||
1150 | |||
1151 | /* End of Add-Ons */ | ||
1152 | /* ************************************************* */ | ||
1153 | |||
1154 | |||
1155 | int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) | ||
1156 | { | ||
1157 | int ret = 0; | ||
1158 | |||
1159 | switch(cmd) { | ||
1160 | case VIDIOCPWCRUSER: | ||
1161 | { | ||
1162 | if (pwc_restore_user(pdev)) | ||
1163 | ret = -EINVAL; | ||
1164 | break; | ||
1165 | } | ||
1166 | |||
1167 | case VIDIOCPWCSUSER: | ||
1168 | { | ||
1169 | if (pwc_save_user(pdev)) | ||
1170 | ret = -EINVAL; | ||
1171 | break; | ||
1172 | } | ||
1173 | |||
1174 | case VIDIOCPWCFACTORY: | ||
1175 | { | ||
1176 | if (pwc_restore_factory(pdev)) | ||
1177 | ret = -EINVAL; | ||
1178 | break; | ||
1179 | } | ||
1180 | |||
1181 | case VIDIOCPWCSCQUAL: | ||
1182 | { | ||
1183 | int *qual = arg; | ||
1184 | |||
1185 | if (*qual < 0 || *qual > 3) | ||
1186 | ret = -EINVAL; | ||
1187 | else | ||
1188 | ret = pwc_try_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, *qual, pdev->vsnapshot); | ||
1189 | if (ret >= 0) | ||
1190 | pdev->vcompression = *qual; | ||
1191 | break; | ||
1192 | } | ||
1193 | |||
1194 | case VIDIOCPWCGCQUAL: | ||
1195 | { | ||
1196 | int *qual = arg; | ||
1197 | *qual = pdev->vcompression; | ||
1198 | break; | ||
1199 | } | ||
1200 | |||
1201 | case VIDIOCPWCPROBE: | ||
1202 | { | ||
1203 | struct pwc_probe *probe = arg; | ||
1204 | strcpy(probe->name, pdev->vdev->name); | ||
1205 | probe->type = pdev->type; | ||
1206 | break; | ||
1207 | } | ||
1208 | |||
1209 | case VIDIOCPWCGSERIAL: | ||
1210 | { | ||
1211 | struct pwc_serial *serial = arg; | ||
1212 | strcpy(serial->serial, pdev->serial); | ||
1213 | break; | ||
1214 | } | ||
1215 | |||
1216 | case VIDIOCPWCSAGC: | ||
1217 | { | ||
1218 | int *agc = arg; | ||
1219 | if (pwc_set_agc(pdev, *agc < 0 ? 1 : 0, *agc)) | ||
1220 | ret = -EINVAL; | ||
1221 | break; | ||
1222 | } | ||
1223 | |||
1224 | case VIDIOCPWCGAGC: | ||
1225 | { | ||
1226 | int *agc = arg; | ||
1227 | |||
1228 | if (pwc_get_agc(pdev, agc)) | ||
1229 | ret = -EINVAL; | ||
1230 | break; | ||
1231 | } | ||
1232 | |||
1233 | case VIDIOCPWCSSHUTTER: | ||
1234 | { | ||
1235 | int *shutter_speed = arg; | ||
1236 | ret = pwc_set_shutter_speed(pdev, *shutter_speed < 0 ? 1 : 0, *shutter_speed); | ||
1237 | break; | ||
1238 | } | ||
1239 | |||
1240 | case VIDIOCPWCSAWB: | ||
1241 | { | ||
1242 | struct pwc_whitebalance *wb = arg; | ||
1243 | |||
1244 | ret = pwc_set_awb(pdev, wb->mode); | ||
1245 | if (ret >= 0 && wb->mode == PWC_WB_MANUAL) { | ||
1246 | pwc_set_red_gain(pdev, wb->manual_red); | ||
1247 | pwc_set_blue_gain(pdev, wb->manual_blue); | ||
1248 | } | ||
1249 | break; | ||
1250 | } | ||
1251 | |||
1252 | case VIDIOCPWCGAWB: | ||
1253 | { | ||
1254 | struct pwc_whitebalance *wb = arg; | ||
1255 | |||
1256 | memset(wb, 0, sizeof(struct pwc_whitebalance)); | ||
1257 | wb->mode = pwc_get_awb(pdev); | ||
1258 | if (wb->mode < 0) | ||
1259 | ret = -EINVAL; | ||
1260 | else { | ||
1261 | if (wb->mode == PWC_WB_MANUAL) { | ||
1262 | ret = pwc_get_red_gain(pdev, &wb->manual_red); | ||
1263 | if (ret < 0) | ||
1264 | break; | ||
1265 | ret = pwc_get_blue_gain(pdev, &wb->manual_blue); | ||
1266 | if (ret < 0) | ||
1267 | break; | ||
1268 | } | ||
1269 | if (wb->mode == PWC_WB_AUTO) { | ||
1270 | ret = pwc_read_red_gain(pdev, &wb->read_red); | ||
1271 | if (ret < 0) | ||
1272 | break; | ||
1273 | ret = pwc_read_blue_gain(pdev, &wb->read_blue); | ||
1274 | if (ret < 0) | ||
1275 | break; | ||
1276 | } | ||
1277 | } | ||
1278 | break; | ||
1279 | } | ||
1280 | |||
1281 | case VIDIOCPWCSAWBSPEED: | ||
1282 | { | ||
1283 | struct pwc_wb_speed *wbs = arg; | ||
1284 | |||
1285 | if (wbs->control_speed > 0) { | ||
1286 | ret = pwc_set_wb_speed(pdev, wbs->control_speed); | ||
1287 | } | ||
1288 | if (wbs->control_delay > 0) { | ||
1289 | ret = pwc_set_wb_delay(pdev, wbs->control_delay); | ||
1290 | } | ||
1291 | break; | ||
1292 | } | ||
1293 | |||
1294 | case VIDIOCPWCGAWBSPEED: | ||
1295 | { | ||
1296 | struct pwc_wb_speed *wbs = arg; | ||
1297 | |||
1298 | ret = pwc_get_wb_speed(pdev, &wbs->control_speed); | ||
1299 | if (ret < 0) | ||
1300 | break; | ||
1301 | ret = pwc_get_wb_delay(pdev, &wbs->control_delay); | ||
1302 | if (ret < 0) | ||
1303 | break; | ||
1304 | break; | ||
1305 | } | ||
1306 | |||
1307 | case VIDIOCPWCSLED: | ||
1308 | { | ||
1309 | struct pwc_leds *leds = arg; | ||
1310 | ret = pwc_set_leds(pdev, leds->led_on, leds->led_off); | ||
1311 | break; | ||
1312 | } | ||
1313 | |||
1314 | |||
1315 | case VIDIOCPWCGLED: | ||
1316 | { | ||
1317 | struct pwc_leds *leds = arg; | ||
1318 | ret = pwc_get_leds(pdev, &leds->led_on, &leds->led_off); | ||
1319 | break; | ||
1320 | } | ||
1321 | |||
1322 | case VIDIOCPWCSCONTOUR: | ||
1323 | { | ||
1324 | int *contour = arg; | ||
1325 | ret = pwc_set_contour(pdev, *contour); | ||
1326 | break; | ||
1327 | } | ||
1328 | |||
1329 | case VIDIOCPWCGCONTOUR: | ||
1330 | { | ||
1331 | int *contour = arg; | ||
1332 | ret = pwc_get_contour(pdev, contour); | ||
1333 | break; | ||
1334 | } | ||
1335 | |||
1336 | case VIDIOCPWCSBACKLIGHT: | ||
1337 | { | ||
1338 | int *backlight = arg; | ||
1339 | ret = pwc_set_backlight(pdev, *backlight); | ||
1340 | break; | ||
1341 | } | ||
1342 | |||
1343 | case VIDIOCPWCGBACKLIGHT: | ||
1344 | { | ||
1345 | int *backlight = arg; | ||
1346 | ret = pwc_get_backlight(pdev, backlight); | ||
1347 | break; | ||
1348 | } | ||
1349 | |||
1350 | case VIDIOCPWCSFLICKER: | ||
1351 | { | ||
1352 | int *flicker = arg; | ||
1353 | ret = pwc_set_flicker(pdev, *flicker); | ||
1354 | break; | ||
1355 | } | ||
1356 | |||
1357 | case VIDIOCPWCGFLICKER: | ||
1358 | { | ||
1359 | int *flicker = arg; | ||
1360 | ret = pwc_get_flicker(pdev, flicker); | ||
1361 | break; | ||
1362 | } | ||
1363 | |||
1364 | case VIDIOCPWCSDYNNOISE: | ||
1365 | { | ||
1366 | int *dynnoise = arg; | ||
1367 | ret = pwc_set_dynamic_noise(pdev, *dynnoise); | ||
1368 | break; | ||
1369 | } | ||
1370 | |||
1371 | case VIDIOCPWCGDYNNOISE: | ||
1372 | { | ||
1373 | int *dynnoise = arg; | ||
1374 | ret = pwc_get_dynamic_noise(pdev, dynnoise); | ||
1375 | break; | ||
1376 | } | ||
1377 | |||
1378 | case VIDIOCPWCGREALSIZE: | ||
1379 | { | ||
1380 | struct pwc_imagesize *size = arg; | ||
1381 | size->width = pdev->image.x; | ||
1382 | size->height = pdev->image.y; | ||
1383 | break; | ||
1384 | } | ||
1385 | |||
1386 | case VIDIOCPWCMPTRESET: | ||
1387 | { | ||
1388 | if (pdev->features & FEATURE_MOTOR_PANTILT) | ||
1389 | { | ||
1390 | int *flags = arg; | ||
1391 | |||
1392 | ret = pwc_mpt_reset(pdev, *flags); | ||
1393 | if (ret >= 0) | ||
1394 | { | ||
1395 | pdev->pan_angle = 0; | ||
1396 | pdev->tilt_angle = 0; | ||
1397 | } | ||
1398 | } | ||
1399 | else | ||
1400 | { | ||
1401 | ret = -ENXIO; | ||
1402 | } | ||
1403 | break; | ||
1404 | } | ||
1405 | |||
1406 | case VIDIOCPWCMPTGRANGE: | ||
1407 | { | ||
1408 | if (pdev->features & FEATURE_MOTOR_PANTILT) | ||
1409 | { | ||
1410 | struct pwc_mpt_range *range = arg; | ||
1411 | *range = pdev->angle_range; | ||
1412 | } | ||
1413 | else | ||
1414 | { | ||
1415 | ret = -ENXIO; | ||
1416 | } | ||
1417 | break; | ||
1418 | } | ||
1419 | |||
1420 | case VIDIOCPWCMPTSANGLE: | ||
1421 | { | ||
1422 | int new_pan, new_tilt; | ||
1423 | |||
1424 | if (pdev->features & FEATURE_MOTOR_PANTILT) | ||
1425 | { | ||
1426 | struct pwc_mpt_angles *angles = arg; | ||
1427 | /* The camera can only set relative angles, so | ||
1428 | do some calculations when getting an absolute angle . | ||
1429 | */ | ||
1430 | if (angles->absolute) | ||
1431 | { | ||
1432 | new_pan = angles->pan; | ||
1433 | new_tilt = angles->tilt; | ||
1434 | } | ||
1435 | else | ||
1436 | { | ||
1437 | new_pan = pdev->pan_angle + angles->pan; | ||
1438 | new_tilt = pdev->tilt_angle + angles->tilt; | ||
1439 | } | ||
1440 | /* check absolute ranges */ | ||
1441 | if (new_pan < pdev->angle_range.pan_min || | ||
1442 | new_pan > pdev->angle_range.pan_max || | ||
1443 | new_tilt < pdev->angle_range.tilt_min || | ||
1444 | new_tilt > pdev->angle_range.tilt_max) | ||
1445 | { | ||
1446 | ret = -ERANGE; | ||
1447 | } | ||
1448 | else | ||
1449 | { | ||
1450 | /* go to relative range, check again */ | ||
1451 | new_pan -= pdev->pan_angle; | ||
1452 | new_tilt -= pdev->tilt_angle; | ||
1453 | /* angles are specified in degrees * 100, thus the limit = 36000 */ | ||
1454 | if (new_pan < -36000 || new_pan > 36000 || new_tilt < -36000 || new_tilt > 36000) | ||
1455 | ret = -ERANGE; | ||
1456 | } | ||
1457 | if (ret == 0) /* no errors so far */ | ||
1458 | { | ||
1459 | ret = pwc_mpt_set_angle(pdev, new_pan, new_tilt); | ||
1460 | if (ret >= 0) | ||
1461 | { | ||
1462 | pdev->pan_angle += new_pan; | ||
1463 | pdev->tilt_angle += new_tilt; | ||
1464 | } | ||
1465 | if (ret == -EPIPE) /* stall -> out of range */ | ||
1466 | ret = -ERANGE; | ||
1467 | } | ||
1468 | } | ||
1469 | else | ||
1470 | { | ||
1471 | ret = -ENXIO; | ||
1472 | } | ||
1473 | break; | ||
1474 | } | ||
1475 | |||
1476 | case VIDIOCPWCMPTGANGLE: | ||
1477 | { | ||
1478 | |||
1479 | if (pdev->features & FEATURE_MOTOR_PANTILT) | ||
1480 | { | ||
1481 | struct pwc_mpt_angles *angles = arg; | ||
1482 | |||
1483 | angles->absolute = 1; | ||
1484 | angles->pan = pdev->pan_angle; | ||
1485 | angles->tilt = pdev->tilt_angle; | ||
1486 | } | ||
1487 | else | ||
1488 | { | ||
1489 | ret = -ENXIO; | ||
1490 | } | ||
1491 | break; | ||
1492 | } | ||
1493 | |||
1494 | case VIDIOCPWCMPTSTATUS: | ||
1495 | { | ||
1496 | if (pdev->features & FEATURE_MOTOR_PANTILT) | ||
1497 | { | ||
1498 | struct pwc_mpt_status *status = arg; | ||
1499 | ret = pwc_mpt_get_status(pdev, status); | ||
1500 | } | ||
1501 | else | ||
1502 | { | ||
1503 | ret = -ENXIO; | ||
1504 | } | ||
1505 | break; | ||
1506 | } | ||
1507 | |||
1508 | case VIDIOCPWCGVIDCMD: | ||
1509 | { | ||
1510 | struct pwc_video_command *cmd = arg; | ||
1511 | |||
1512 | cmd->type = pdev->type; | ||
1513 | cmd->release = pdev->release; | ||
1514 | cmd->command_len = pdev->cmd_len; | ||
1515 | memcpy(&cmd->command_buf, pdev->cmd_buf, pdev->cmd_len); | ||
1516 | cmd->bandlength = pdev->vbandlength; | ||
1517 | cmd->frame_size = pdev->frame_size; | ||
1518 | break; | ||
1519 | } | ||
1520 | /* | ||
1521 | case VIDIOCPWCGVIDTABLE: | ||
1522 | { | ||
1523 | struct pwc_table_init_buffer *table = arg; | ||
1524 | table->len = pdev->cmd_len; | ||
1525 | memcpy(&table->buffer, pdev->decompress_data, pdev->decompressor->table_size); | ||
1526 | break; | ||
1527 | } | ||
1528 | */ | ||
1529 | |||
1530 | default: | ||
1531 | ret = -ENOIOCTLCMD; | ||
1532 | break; | ||
1533 | } | ||
1534 | |||
1535 | if (ret > 0) | ||
1536 | return 0; | ||
1537 | return ret; | ||
1538 | } | ||
1539 | |||
1540 | |||
1541 | |||
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c new file mode 100644 index 000000000000..90eb26042817 --- /dev/null +++ b/drivers/media/video/pwc/pwc-if.c | |||
@@ -0,0 +1,2205 @@ | |||
1 | /* Linux driver for Philips webcam | ||
2 | USB and Video4Linux interface part. | ||
3 | (C) 1999-2004 Nemosoft Unv. | ||
4 | (C) 2004 Luc Saillard (luc@saillard.org) | ||
5 | |||
6 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
7 | driver and thus may have bugs that are not present in the original version. | ||
8 | Please send bug reports and support requests to <luc@saillard.org>. | ||
9 | The decompression routines have been implemented by reverse-engineering the | ||
10 | Nemosoft binary pwcx module. Caveat emptor. | ||
11 | |||
12 | This program is free software; you can redistribute it and/or modify | ||
13 | it under the terms of the GNU General Public License as published by | ||
14 | the Free Software Foundation; either version 2 of the License, or | ||
15 | (at your option) any later version. | ||
16 | |||
17 | This program is distributed in the hope that it will be useful, | ||
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | GNU General Public License for more details. | ||
21 | |||
22 | You should have received a copy of the GNU General Public License | ||
23 | along with this program; if not, write to the Free Software | ||
24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
25 | |||
26 | */ | ||
27 | |||
28 | /* | ||
29 | This code forms the interface between the USB layers and the Philips | ||
30 | specific stuff. Some adanved stuff of the driver falls under an | ||
31 | NDA, signed between me and Philips B.V., Eindhoven, the Netherlands, and | ||
32 | is thus not distributed in source form. The binary pwcx.o module | ||
33 | contains the code that falls under the NDA. | ||
34 | |||
35 | In case you're wondering: 'pwc' stands for "Philips WebCam", but | ||
36 | I really didn't want to type 'philips_web_cam' every time (I'm lazy as | ||
37 | any Linux kernel hacker, but I don't like uncomprehensible abbreviations | ||
38 | without explanation). | ||
39 | |||
40 | Oh yes, convention: to disctinguish between all the various pointers to | ||
41 | device-structures, I use these names for the pointer variables: | ||
42 | udev: struct usb_device * | ||
43 | vdev: struct video_device * | ||
44 | pdev: struct pwc_devive * | ||
45 | */ | ||
46 | |||
47 | /* Contributors: | ||
48 | - Alvarado: adding whitebalance code | ||
49 | - Alistar Moire: QuickCam 3000 Pro device/product ID | ||
50 | - Tony Hoyle: Creative Labs Webcam 5 device/product ID | ||
51 | - Mark Burazin: solving hang in VIDIOCSYNC when camera gets unplugged | ||
52 | - Jk Fang: Sotec Afina Eye ID | ||
53 | - Xavier Roche: QuickCam Pro 4000 ID | ||
54 | - Jens Knudsen: QuickCam Zoom ID | ||
55 | - J. Debert: QuickCam for Notebooks ID | ||
56 | */ | ||
57 | |||
58 | #include <linux/errno.h> | ||
59 | #include <linux/init.h> | ||
60 | #include <linux/mm.h> | ||
61 | #include <linux/module.h> | ||
62 | #include <linux/poll.h> | ||
63 | #include <linux/slab.h> | ||
64 | #include <linux/vmalloc.h> | ||
65 | #include <asm/io.h> | ||
66 | |||
67 | #include "pwc.h" | ||
68 | #include "pwc-ioctl.h" | ||
69 | #include "pwc-kiara.h" | ||
70 | #include "pwc-timon.h" | ||
71 | #include "pwc-uncompress.h" | ||
72 | |||
73 | /* Function prototypes and driver templates */ | ||
74 | |||
75 | /* hotplug device table support */ | ||
76 | static struct usb_device_id pwc_device_table [] = { | ||
77 | { USB_DEVICE(0x0471, 0x0302) }, /* Philips models */ | ||
78 | { USB_DEVICE(0x0471, 0x0303) }, | ||
79 | { USB_DEVICE(0x0471, 0x0304) }, | ||
80 | { USB_DEVICE(0x0471, 0x0307) }, | ||
81 | { USB_DEVICE(0x0471, 0x0308) }, | ||
82 | { USB_DEVICE(0x0471, 0x030C) }, | ||
83 | { USB_DEVICE(0x0471, 0x0310) }, | ||
84 | { USB_DEVICE(0x0471, 0x0311) }, | ||
85 | { USB_DEVICE(0x0471, 0x0312) }, | ||
86 | { USB_DEVICE(0x0471, 0x0313) }, /* the 'new' 720K */ | ||
87 | { USB_DEVICE(0x069A, 0x0001) }, /* Askey */ | ||
88 | { USB_DEVICE(0x046D, 0x08B0) }, /* Logitech QuickCam Pro 3000 */ | ||
89 | { USB_DEVICE(0x046D, 0x08B1) }, /* Logitech QuickCam Notebook Pro */ | ||
90 | { USB_DEVICE(0x046D, 0x08B2) }, /* Logitech QuickCam Pro 4000 */ | ||
91 | { USB_DEVICE(0x046D, 0x08B3) }, /* Logitech QuickCam Zoom (old model) */ | ||
92 | { USB_DEVICE(0x046D, 0x08B4) }, /* Logitech QuickCam Zoom (new model) */ | ||
93 | { USB_DEVICE(0x046D, 0x08B5) }, /* Logitech QuickCam Orbit/Sphere */ | ||
94 | { USB_DEVICE(0x046D, 0x08B6) }, /* Logitech (reserved) */ | ||
95 | { USB_DEVICE(0x046D, 0x08B7) }, /* Logitech (reserved) */ | ||
96 | { USB_DEVICE(0x046D, 0x08B8) }, /* Logitech (reserved) */ | ||
97 | { USB_DEVICE(0x055D, 0x9000) }, /* Samsung */ | ||
98 | { USB_DEVICE(0x055D, 0x9001) }, | ||
99 | { USB_DEVICE(0x041E, 0x400C) }, /* Creative Webcam 5 */ | ||
100 | { USB_DEVICE(0x041E, 0x4011) }, /* Creative Webcam Pro Ex */ | ||
101 | { USB_DEVICE(0x04CC, 0x8116) }, /* Afina Eye */ | ||
102 | { USB_DEVICE(0x06BE, 0x8116) }, /* new Afina Eye */ | ||
103 | { USB_DEVICE(0x0d81, 0x1910) }, /* Visionite */ | ||
104 | { USB_DEVICE(0x0d81, 0x1900) }, | ||
105 | { } | ||
106 | }; | ||
107 | MODULE_DEVICE_TABLE(usb, pwc_device_table); | ||
108 | |||
109 | static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id *id); | ||
110 | static void usb_pwc_disconnect(struct usb_interface *intf); | ||
111 | |||
112 | static struct usb_driver pwc_driver = { | ||
113 | .name = "Philips webcam", /* name */ | ||
114 | .id_table = pwc_device_table, | ||
115 | .probe = usb_pwc_probe, /* probe() */ | ||
116 | .disconnect = usb_pwc_disconnect, /* disconnect() */ | ||
117 | }; | ||
118 | |||
119 | #define MAX_DEV_HINTS 20 | ||
120 | #define MAX_ISOC_ERRORS 20 | ||
121 | |||
122 | static int default_size = PSZ_QCIF; | ||
123 | static int default_fps = 10; | ||
124 | static int default_fbufs = 3; /* Default number of frame buffers */ | ||
125 | static int default_mbufs = 2; /* Default number of mmap() buffers */ | ||
126 | int pwc_trace = TRACE_MODULE | TRACE_FLOW | TRACE_PWCX; | ||
127 | static int power_save = 0; | ||
128 | static int led_on = 100, led_off = 0; /* defaults to LED that is on while in use */ | ||
129 | static int pwc_preferred_compression = 2; /* 0..3 = uncompressed..high */ | ||
130 | static struct { | ||
131 | int type; | ||
132 | char serial_number[30]; | ||
133 | int device_node; | ||
134 | struct pwc_device *pdev; | ||
135 | } device_hint[MAX_DEV_HINTS]; | ||
136 | |||
137 | /***/ | ||
138 | |||
139 | static int pwc_video_open(struct inode *inode, struct file *file); | ||
140 | static int pwc_video_close(struct inode *inode, struct file *file); | ||
141 | static ssize_t pwc_video_read(struct file *file, char __user * buf, | ||
142 | size_t count, loff_t *ppos); | ||
143 | static unsigned int pwc_video_poll(struct file *file, poll_table *wait); | ||
144 | static int pwc_video_ioctl(struct inode *inode, struct file *file, | ||
145 | unsigned int ioctlnr, unsigned long arg); | ||
146 | static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma); | ||
147 | |||
148 | static struct file_operations pwc_fops = { | ||
149 | .owner = THIS_MODULE, | ||
150 | .open = pwc_video_open, | ||
151 | .release = pwc_video_close, | ||
152 | .read = pwc_video_read, | ||
153 | .poll = pwc_video_poll, | ||
154 | .mmap = pwc_video_mmap, | ||
155 | .ioctl = pwc_video_ioctl, | ||
156 | .compat_ioctl = v4l_compat_ioctl32, | ||
157 | .llseek = no_llseek, | ||
158 | }; | ||
159 | static struct video_device pwc_template = { | ||
160 | .owner = THIS_MODULE, | ||
161 | .name = "Philips Webcam", /* Filled in later */ | ||
162 | .type = VID_TYPE_CAPTURE, | ||
163 | .hardware = VID_HARDWARE_PWC, | ||
164 | .release = video_device_release, | ||
165 | .fops = &pwc_fops, | ||
166 | .minor = -1, | ||
167 | }; | ||
168 | |||
169 | /***************************************************************************/ | ||
170 | |||
171 | /* Okay, this is some magic that I worked out and the reasoning behind it... | ||
172 | |||
173 | The biggest problem with any USB device is of course: "what to do | ||
174 | when the user unplugs the device while it is in use by an application?" | ||
175 | We have several options: | ||
176 | 1) Curse them with the 7 plagues when they do (requires divine intervention) | ||
177 | 2) Tell them not to (won't work: they'll do it anyway) | ||
178 | 3) Oops the kernel (this will have a negative effect on a user's uptime) | ||
179 | 4) Do something sensible. | ||
180 | |||
181 | Of course, we go for option 4. | ||
182 | |||
183 | It happens that this device will be linked to two times, once from | ||
184 | usb_device and once from the video_device in their respective 'private' | ||
185 | pointers. This is done when the device is probed() and all initialization | ||
186 | succeeded. The pwc_device struct links back to both structures. | ||
187 | |||
188 | When a device is unplugged while in use it will be removed from the | ||
189 | list of known USB devices; I also de-register it as a V4L device, but | ||
190 | unfortunately I can't free the memory since the struct is still in use | ||
191 | by the file descriptor. This free-ing is then deferend until the first | ||
192 | opportunity. Crude, but it works. | ||
193 | |||
194 | A small 'advantage' is that if a user unplugs the cam and plugs it back | ||
195 | in, it should get assigned the same video device minor, but unfortunately | ||
196 | it's non-trivial to re-link the cam back to the video device... (that | ||
197 | would surely be magic! :)) | ||
198 | */ | ||
199 | |||
200 | /***************************************************************************/ | ||
201 | /* Private functions */ | ||
202 | |||
203 | /* Here we want the physical address of the memory. | ||
204 | * This is used when initializing the contents of the area. | ||
205 | */ | ||
206 | static inline unsigned long kvirt_to_pa(unsigned long adr) | ||
207 | { | ||
208 | unsigned long kva, ret; | ||
209 | |||
210 | kva = (unsigned long) page_address(vmalloc_to_page((void *)adr)); | ||
211 | kva |= adr & (PAGE_SIZE-1); /* restore the offset */ | ||
212 | ret = __pa(kva); | ||
213 | return ret; | ||
214 | } | ||
215 | |||
216 | static void * rvmalloc(unsigned long size) | ||
217 | { | ||
218 | void * mem; | ||
219 | unsigned long adr; | ||
220 | |||
221 | size=PAGE_ALIGN(size); | ||
222 | mem=vmalloc_32(size); | ||
223 | if (mem) | ||
224 | { | ||
225 | memset(mem, 0, size); /* Clear the ram out, no junk to the user */ | ||
226 | adr=(unsigned long) mem; | ||
227 | while (size > 0) | ||
228 | { | ||
229 | SetPageReserved(vmalloc_to_page((void *)adr)); | ||
230 | adr+=PAGE_SIZE; | ||
231 | size-=PAGE_SIZE; | ||
232 | } | ||
233 | } | ||
234 | return mem; | ||
235 | } | ||
236 | |||
237 | static void rvfree(void * mem, unsigned long size) | ||
238 | { | ||
239 | unsigned long adr; | ||
240 | |||
241 | if (mem) | ||
242 | { | ||
243 | adr=(unsigned long) mem; | ||
244 | while ((long) size > 0) | ||
245 | { | ||
246 | ClearPageReserved(vmalloc_to_page((void *)adr)); | ||
247 | adr+=PAGE_SIZE; | ||
248 | size-=PAGE_SIZE; | ||
249 | } | ||
250 | vfree(mem); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | |||
255 | |||
256 | |||
257 | static int pwc_allocate_buffers(struct pwc_device *pdev) | ||
258 | { | ||
259 | int i; | ||
260 | void *kbuf; | ||
261 | |||
262 | Trace(TRACE_MEMORY, ">> pwc_allocate_buffers(pdev = 0x%p)\n", pdev); | ||
263 | |||
264 | if (pdev == NULL) | ||
265 | return -ENXIO; | ||
266 | |||
267 | #ifdef PWC_MAGIC | ||
268 | if (pdev->magic != PWC_MAGIC) { | ||
269 | Err("allocate_buffers(): magic failed.\n"); | ||
270 | return -ENXIO; | ||
271 | } | ||
272 | #endif | ||
273 | /* Allocate Isochronous pipe buffers */ | ||
274 | for (i = 0; i < MAX_ISO_BUFS; i++) { | ||
275 | if (pdev->sbuf[i].data == NULL) { | ||
276 | kbuf = kmalloc(ISO_BUFFER_SIZE, GFP_KERNEL); | ||
277 | if (kbuf == NULL) { | ||
278 | Err("Failed to allocate iso buffer %d.\n", i); | ||
279 | return -ENOMEM; | ||
280 | } | ||
281 | Trace(TRACE_MEMORY, "Allocated iso buffer at %p.\n", kbuf); | ||
282 | pdev->sbuf[i].data = kbuf; | ||
283 | memset(kbuf, 0, ISO_BUFFER_SIZE); | ||
284 | } | ||
285 | } | ||
286 | |||
287 | /* Allocate frame buffer structure */ | ||
288 | if (pdev->fbuf == NULL) { | ||
289 | kbuf = kmalloc(default_fbufs * sizeof(struct pwc_frame_buf), GFP_KERNEL); | ||
290 | if (kbuf == NULL) { | ||
291 | Err("Failed to allocate frame buffer structure.\n"); | ||
292 | return -ENOMEM; | ||
293 | } | ||
294 | Trace(TRACE_MEMORY, "Allocated frame buffer structure at %p.\n", kbuf); | ||
295 | pdev->fbuf = kbuf; | ||
296 | memset(kbuf, 0, default_fbufs * sizeof(struct pwc_frame_buf)); | ||
297 | } | ||
298 | /* create frame buffers, and make circular ring */ | ||
299 | for (i = 0; i < default_fbufs; i++) { | ||
300 | if (pdev->fbuf[i].data == NULL) { | ||
301 | kbuf = vmalloc(PWC_FRAME_SIZE); /* need vmalloc since frame buffer > 128K */ | ||
302 | if (kbuf == NULL) { | ||
303 | Err("Failed to allocate frame buffer %d.\n", i); | ||
304 | return -ENOMEM; | ||
305 | } | ||
306 | Trace(TRACE_MEMORY, "Allocated frame buffer %d at %p.\n", i, kbuf); | ||
307 | pdev->fbuf[i].data = kbuf; | ||
308 | memset(kbuf, 128, PWC_FRAME_SIZE); | ||
309 | } | ||
310 | } | ||
311 | |||
312 | /* Allocate decompressor table space */ | ||
313 | kbuf = NULL; | ||
314 | switch (pdev->type) | ||
315 | { | ||
316 | case 675: | ||
317 | case 680: | ||
318 | case 690: | ||
319 | case 720: | ||
320 | case 730: | ||
321 | case 740: | ||
322 | case 750: | ||
323 | #if 0 | ||
324 | Trace(TRACE_MEMORY,"private_data(%zu)\n",sizeof(struct pwc_dec23_private)); | ||
325 | kbuf = kmalloc(sizeof(struct pwc_dec23_private), GFP_KERNEL); /* Timon & Kiara */ | ||
326 | break; | ||
327 | case 645: | ||
328 | case 646: | ||
329 | /* TODO & FIXME */ | ||
330 | kbuf = kmalloc(sizeof(struct pwc_dec23_private), GFP_KERNEL); | ||
331 | break; | ||
332 | #endif | ||
333 | ; | ||
334 | } | ||
335 | pdev->decompress_data = kbuf; | ||
336 | |||
337 | /* Allocate image buffer; double buffer for mmap() */ | ||
338 | kbuf = rvmalloc(default_mbufs * pdev->len_per_image); | ||
339 | if (kbuf == NULL) { | ||
340 | Err("Failed to allocate image buffer(s). needed (%d)\n",default_mbufs * pdev->len_per_image); | ||
341 | return -ENOMEM; | ||
342 | } | ||
343 | Trace(TRACE_MEMORY, "Allocated image buffer at %p.\n", kbuf); | ||
344 | pdev->image_data = kbuf; | ||
345 | for (i = 0; i < default_mbufs; i++) | ||
346 | pdev->image_ptr[i] = kbuf + i * pdev->len_per_image; | ||
347 | for (; i < MAX_IMAGES; i++) | ||
348 | pdev->image_ptr[i] = NULL; | ||
349 | |||
350 | kbuf = NULL; | ||
351 | |||
352 | Trace(TRACE_MEMORY, "<< pwc_allocate_buffers()\n"); | ||
353 | return 0; | ||
354 | } | ||
355 | |||
356 | static void pwc_free_buffers(struct pwc_device *pdev) | ||
357 | { | ||
358 | int i; | ||
359 | |||
360 | Trace(TRACE_MEMORY, "Entering free_buffers(%p).\n", pdev); | ||
361 | |||
362 | if (pdev == NULL) | ||
363 | return; | ||
364 | #ifdef PWC_MAGIC | ||
365 | if (pdev->magic != PWC_MAGIC) { | ||
366 | Err("free_buffers(): magic failed.\n"); | ||
367 | return; | ||
368 | } | ||
369 | #endif | ||
370 | |||
371 | /* Release Iso-pipe buffers */ | ||
372 | for (i = 0; i < MAX_ISO_BUFS; i++) | ||
373 | if (pdev->sbuf[i].data != NULL) { | ||
374 | Trace(TRACE_MEMORY, "Freeing ISO buffer at %p.\n", pdev->sbuf[i].data); | ||
375 | kfree(pdev->sbuf[i].data); | ||
376 | pdev->sbuf[i].data = NULL; | ||
377 | } | ||
378 | |||
379 | /* The same for frame buffers */ | ||
380 | if (pdev->fbuf != NULL) { | ||
381 | for (i = 0; i < default_fbufs; i++) { | ||
382 | if (pdev->fbuf[i].data != NULL) { | ||
383 | Trace(TRACE_MEMORY, "Freeing frame buffer %d at %p.\n", i, pdev->fbuf[i].data); | ||
384 | vfree(pdev->fbuf[i].data); | ||
385 | pdev->fbuf[i].data = NULL; | ||
386 | } | ||
387 | } | ||
388 | kfree(pdev->fbuf); | ||
389 | pdev->fbuf = NULL; | ||
390 | } | ||
391 | |||
392 | /* Intermediate decompression buffer & tables */ | ||
393 | if (pdev->decompress_data != NULL) { | ||
394 | Trace(TRACE_MEMORY, "Freeing decompression buffer at %p.\n", pdev->decompress_data); | ||
395 | kfree(pdev->decompress_data); | ||
396 | pdev->decompress_data = NULL; | ||
397 | } | ||
398 | pdev->decompressor = NULL; | ||
399 | |||
400 | /* Release image buffers */ | ||
401 | if (pdev->image_data != NULL) { | ||
402 | Trace(TRACE_MEMORY, "Freeing image buffer at %p.\n", pdev->image_data); | ||
403 | rvfree(pdev->image_data, default_mbufs * pdev->len_per_image); | ||
404 | } | ||
405 | pdev->image_data = NULL; | ||
406 | |||
407 | Trace(TRACE_MEMORY, "Leaving free_buffers().\n"); | ||
408 | } | ||
409 | |||
410 | /* The frame & image buffer mess. | ||
411 | |||
412 | Yes, this is a mess. Well, it used to be simple, but alas... In this | ||
413 | module, 3 buffers schemes are used to get the data from the USB bus to | ||
414 | the user program. The first scheme involves the ISO buffers (called thus | ||
415 | since they transport ISO data from the USB controller), and not really | ||
416 | interesting. Suffices to say the data from this buffer is quickly | ||
417 | gathered in an interrupt handler (pwc_isoc_handler) and placed into the | ||
418 | frame buffer. | ||
419 | |||
420 | The frame buffer is the second scheme, and is the central element here. | ||
421 | It collects the data from a single frame from the camera (hence, the | ||
422 | name). Frames are delimited by the USB camera with a short USB packet, | ||
423 | so that's easy to detect. The frame buffers form a list that is filled | ||
424 | by the camera+USB controller and drained by the user process through | ||
425 | either read() or mmap(). | ||
426 | |||
427 | The image buffer is the third scheme, in which frames are decompressed | ||
428 | and converted into planar format. For mmap() there is more than | ||
429 | one image buffer available. | ||
430 | |||
431 | The frame buffers provide the image buffering. In case the user process | ||
432 | is a bit slow, this introduces lag and some undesired side-effects. | ||
433 | The problem arises when the frame buffer is full. I used to drop the last | ||
434 | frame, which makes the data in the queue stale very quickly. But dropping | ||
435 | the frame at the head of the queue proved to be a litte bit more difficult. | ||
436 | I tried a circular linked scheme, but this introduced more problems than | ||
437 | it solved. | ||
438 | |||
439 | Because filling and draining are completely asynchronous processes, this | ||
440 | requires some fiddling with pointers and mutexes. | ||
441 | |||
442 | Eventually, I came up with a system with 2 lists: an 'empty' frame list | ||
443 | and a 'full' frame list: | ||
444 | * Initially, all frame buffers but one are on the 'empty' list; the one | ||
445 | remaining buffer is our initial fill frame. | ||
446 | * If a frame is needed for filling, we try to take it from the 'empty' | ||
447 | list, unless that list is empty, in which case we take the buffer at | ||
448 | the head of the 'full' list. | ||
449 | * When our fill buffer has been filled, it is appended to the 'full' | ||
450 | list. | ||
451 | * If a frame is needed by read() or mmap(), it is taken from the head of | ||
452 | the 'full' list, handled, and then appended to the 'empty' list. If no | ||
453 | buffer is present on the 'full' list, we wait. | ||
454 | The advantage is that the buffer that is currently being decompressed/ | ||
455 | converted, is on neither list, and thus not in our way (any other scheme | ||
456 | I tried had the problem of old data lingering in the queue). | ||
457 | |||
458 | Whatever strategy you choose, it always remains a tradeoff: with more | ||
459 | frame buffers the chances of a missed frame are reduced. On the other | ||
460 | hand, on slower machines it introduces lag because the queue will | ||
461 | always be full. | ||
462 | */ | ||
463 | |||
464 | /** | ||
465 | \brief Find next frame buffer to fill. Take from empty or full list, whichever comes first. | ||
466 | */ | ||
467 | static inline int pwc_next_fill_frame(struct pwc_device *pdev) | ||
468 | { | ||
469 | int ret; | ||
470 | unsigned long flags; | ||
471 | |||
472 | ret = 0; | ||
473 | spin_lock_irqsave(&pdev->ptrlock, flags); | ||
474 | if (pdev->fill_frame != NULL) { | ||
475 | /* append to 'full' list */ | ||
476 | if (pdev->full_frames == NULL) { | ||
477 | pdev->full_frames = pdev->fill_frame; | ||
478 | pdev->full_frames_tail = pdev->full_frames; | ||
479 | } | ||
480 | else { | ||
481 | pdev->full_frames_tail->next = pdev->fill_frame; | ||
482 | pdev->full_frames_tail = pdev->fill_frame; | ||
483 | } | ||
484 | } | ||
485 | if (pdev->empty_frames != NULL) { | ||
486 | /* We have empty frames available. That's easy */ | ||
487 | pdev->fill_frame = pdev->empty_frames; | ||
488 | pdev->empty_frames = pdev->empty_frames->next; | ||
489 | } | ||
490 | else { | ||
491 | /* Hmm. Take it from the full list */ | ||
492 | #if PWC_DEBUG | ||
493 | /* sanity check */ | ||
494 | if (pdev->full_frames == NULL) { | ||
495 | Err("Neither empty or full frames available!\n"); | ||
496 | spin_unlock_irqrestore(&pdev->ptrlock, flags); | ||
497 | return -EINVAL; | ||
498 | } | ||
499 | #endif | ||
500 | pdev->fill_frame = pdev->full_frames; | ||
501 | pdev->full_frames = pdev->full_frames->next; | ||
502 | ret = 1; | ||
503 | } | ||
504 | pdev->fill_frame->next = NULL; | ||
505 | #if PWC_DEBUG | ||
506 | Trace(TRACE_SEQUENCE, "Assigning sequence number %d.\n", pdev->sequence); | ||
507 | pdev->fill_frame->sequence = pdev->sequence++; | ||
508 | #endif | ||
509 | spin_unlock_irqrestore(&pdev->ptrlock, flags); | ||
510 | return ret; | ||
511 | } | ||
512 | |||
513 | |||
514 | /** | ||
515 | \brief Reset all buffers, pointers and lists, except for the image_used[] buffer. | ||
516 | |||
517 | If the image_used[] buffer is cleared too, mmap()/VIDIOCSYNC will run into trouble. | ||
518 | */ | ||
519 | static void pwc_reset_buffers(struct pwc_device *pdev) | ||
520 | { | ||
521 | int i; | ||
522 | unsigned long flags; | ||
523 | |||
524 | spin_lock_irqsave(&pdev->ptrlock, flags); | ||
525 | pdev->full_frames = NULL; | ||
526 | pdev->full_frames_tail = NULL; | ||
527 | for (i = 0; i < default_fbufs; i++) { | ||
528 | pdev->fbuf[i].filled = 0; | ||
529 | if (i > 0) | ||
530 | pdev->fbuf[i].next = &pdev->fbuf[i - 1]; | ||
531 | else | ||
532 | pdev->fbuf->next = NULL; | ||
533 | } | ||
534 | pdev->empty_frames = &pdev->fbuf[default_fbufs - 1]; | ||
535 | pdev->empty_frames_tail = pdev->fbuf; | ||
536 | pdev->read_frame = NULL; | ||
537 | pdev->fill_frame = pdev->empty_frames; | ||
538 | pdev->empty_frames = pdev->empty_frames->next; | ||
539 | |||
540 | pdev->image_read_pos = 0; | ||
541 | pdev->fill_image = 0; | ||
542 | spin_unlock_irqrestore(&pdev->ptrlock, flags); | ||
543 | } | ||
544 | |||
545 | |||
546 | /** | ||
547 | \brief Do all the handling for getting one frame: get pointer, decompress, advance pointers. | ||
548 | */ | ||
549 | static int pwc_handle_frame(struct pwc_device *pdev) | ||
550 | { | ||
551 | int ret = 0; | ||
552 | unsigned long flags; | ||
553 | |||
554 | spin_lock_irqsave(&pdev->ptrlock, flags); | ||
555 | /* First grab our read_frame; this is removed from all lists, so | ||
556 | we can release the lock after this without problems */ | ||
557 | if (pdev->read_frame != NULL) { | ||
558 | /* This can't theoretically happen */ | ||
559 | Err("Huh? Read frame still in use?\n"); | ||
560 | } | ||
561 | else { | ||
562 | if (pdev->full_frames == NULL) { | ||
563 | Err("Woops. No frames ready.\n"); | ||
564 | } | ||
565 | else { | ||
566 | pdev->read_frame = pdev->full_frames; | ||
567 | pdev->full_frames = pdev->full_frames->next; | ||
568 | pdev->read_frame->next = NULL; | ||
569 | } | ||
570 | |||
571 | if (pdev->read_frame != NULL) { | ||
572 | #if PWC_DEBUG | ||
573 | Trace(TRACE_SEQUENCE, "Decompressing frame %d\n", pdev->read_frame->sequence); | ||
574 | #endif | ||
575 | /* Decompression is a lenghty process, so it's outside of the lock. | ||
576 | This gives the isoc_handler the opportunity to fill more frames | ||
577 | in the mean time. | ||
578 | */ | ||
579 | spin_unlock_irqrestore(&pdev->ptrlock, flags); | ||
580 | ret = pwc_decompress(pdev); | ||
581 | spin_lock_irqsave(&pdev->ptrlock, flags); | ||
582 | |||
583 | /* We're done with read_buffer, tack it to the end of the empty buffer list */ | ||
584 | if (pdev->empty_frames == NULL) { | ||
585 | pdev->empty_frames = pdev->read_frame; | ||
586 | pdev->empty_frames_tail = pdev->empty_frames; | ||
587 | } | ||
588 | else { | ||
589 | pdev->empty_frames_tail->next = pdev->read_frame; | ||
590 | pdev->empty_frames_tail = pdev->read_frame; | ||
591 | } | ||
592 | pdev->read_frame = NULL; | ||
593 | } | ||
594 | } | ||
595 | spin_unlock_irqrestore(&pdev->ptrlock, flags); | ||
596 | return ret; | ||
597 | } | ||
598 | |||
599 | /** | ||
600 | \brief Advance pointers of image buffer (after each user request) | ||
601 | */ | ||
602 | static inline void pwc_next_image(struct pwc_device *pdev) | ||
603 | { | ||
604 | pdev->image_used[pdev->fill_image] = 0; | ||
605 | pdev->fill_image = (pdev->fill_image + 1) % default_mbufs; | ||
606 | } | ||
607 | |||
608 | |||
609 | /* This gets called for the Isochronous pipe (video). This is done in | ||
610 | * interrupt time, so it has to be fast, not crash, and not stall. Neat. | ||
611 | */ | ||
612 | static void pwc_isoc_handler(struct urb *urb, struct pt_regs *regs) | ||
613 | { | ||
614 | struct pwc_device *pdev; | ||
615 | int i, fst, flen; | ||
616 | int awake; | ||
617 | struct pwc_frame_buf *fbuf; | ||
618 | unsigned char *fillptr = NULL, *iso_buf = NULL; | ||
619 | |||
620 | awake = 0; | ||
621 | pdev = (struct pwc_device *)urb->context; | ||
622 | if (pdev == NULL) { | ||
623 | Err("isoc_handler() called with NULL device?!\n"); | ||
624 | return; | ||
625 | } | ||
626 | #ifdef PWC_MAGIC | ||
627 | if (pdev->magic != PWC_MAGIC) { | ||
628 | Err("isoc_handler() called with bad magic!\n"); | ||
629 | return; | ||
630 | } | ||
631 | #endif | ||
632 | if (urb->status == -ENOENT || urb->status == -ECONNRESET) { | ||
633 | Trace(TRACE_OPEN, "pwc_isoc_handler(): URB (%p) unlinked %ssynchronuously.\n", urb, urb->status == -ENOENT ? "" : "a"); | ||
634 | return; | ||
635 | } | ||
636 | if (urb->status != -EINPROGRESS && urb->status != 0) { | ||
637 | const char *errmsg; | ||
638 | |||
639 | errmsg = "Unknown"; | ||
640 | switch(urb->status) { | ||
641 | case -ENOSR: errmsg = "Buffer error (overrun)"; break; | ||
642 | case -EPIPE: errmsg = "Stalled (device not responding)"; break; | ||
643 | case -EOVERFLOW: errmsg = "Babble (bad cable?)"; break; | ||
644 | case -EPROTO: errmsg = "Bit-stuff error (bad cable?)"; break; | ||
645 | case -EILSEQ: errmsg = "CRC/Timeout (could be anything)"; break; | ||
646 | case -ETIMEDOUT: errmsg = "NAK (device does not respond)"; break; | ||
647 | } | ||
648 | Trace(TRACE_FLOW, "pwc_isoc_handler() called with status %d [%s].\n", urb->status, errmsg); | ||
649 | /* Give up after a number of contiguous errors on the USB bus. | ||
650 | Appearantly something is wrong so we simulate an unplug event. | ||
651 | */ | ||
652 | if (++pdev->visoc_errors > MAX_ISOC_ERRORS) | ||
653 | { | ||
654 | Info("Too many ISOC errors, bailing out.\n"); | ||
655 | pdev->error_status = EIO; | ||
656 | awake = 1; | ||
657 | wake_up_interruptible(&pdev->frameq); | ||
658 | } | ||
659 | goto handler_end; // ugly, but practical | ||
660 | } | ||
661 | |||
662 | fbuf = pdev->fill_frame; | ||
663 | if (fbuf == NULL) { | ||
664 | Err("pwc_isoc_handler without valid fill frame.\n"); | ||
665 | awake = 1; | ||
666 | goto handler_end; | ||
667 | } | ||
668 | else { | ||
669 | fillptr = fbuf->data + fbuf->filled; | ||
670 | } | ||
671 | |||
672 | /* Reset ISOC error counter. We did get here, after all. */ | ||
673 | pdev->visoc_errors = 0; | ||
674 | |||
675 | /* vsync: 0 = don't copy data | ||
676 | 1 = sync-hunt | ||
677 | 2 = synched | ||
678 | */ | ||
679 | /* Compact data */ | ||
680 | for (i = 0; i < urb->number_of_packets; i++) { | ||
681 | fst = urb->iso_frame_desc[i].status; | ||
682 | flen = urb->iso_frame_desc[i].actual_length; | ||
683 | iso_buf = urb->transfer_buffer + urb->iso_frame_desc[i].offset; | ||
684 | if (fst == 0) { | ||
685 | if (flen > 0) { /* if valid data... */ | ||
686 | if (pdev->vsync > 0) { /* ...and we are not sync-hunting... */ | ||
687 | pdev->vsync = 2; | ||
688 | |||
689 | /* ...copy data to frame buffer, if possible */ | ||
690 | if (flen + fbuf->filled > pdev->frame_total_size) { | ||
691 | Trace(TRACE_FLOW, "Frame buffer overflow (flen = %d, frame_total_size = %d).\n", flen, pdev->frame_total_size); | ||
692 | pdev->vsync = 0; /* Hmm, let's wait for an EOF (end-of-frame) */ | ||
693 | pdev->vframes_error++; | ||
694 | } | ||
695 | else { | ||
696 | memmove(fillptr, iso_buf, flen); | ||
697 | fillptr += flen; | ||
698 | } | ||
699 | } | ||
700 | fbuf->filled += flen; | ||
701 | } /* ..flen > 0 */ | ||
702 | |||
703 | if (flen < pdev->vlast_packet_size) { | ||
704 | /* Shorter packet... We probably have the end of an image-frame; | ||
705 | wake up read() process and let select()/poll() do something. | ||
706 | Decompression is done in user time over there. | ||
707 | */ | ||
708 | if (pdev->vsync == 2) { | ||
709 | /* The ToUCam Fun CMOS sensor causes the firmware to send 2 or 3 bogus | ||
710 | frames on the USB wire after an exposure change. This conditition is | ||
711 | however detected in the cam and a bit is set in the header. | ||
712 | */ | ||
713 | if (pdev->type == 730) { | ||
714 | unsigned char *ptr = (unsigned char *)fbuf->data; | ||
715 | |||
716 | if (ptr[1] == 1 && ptr[0] & 0x10) { | ||
717 | #if PWC_DEBUG | ||
718 | Debug("Hyundai CMOS sensor bug. Dropping frame %d.\n", fbuf->sequence); | ||
719 | #endif | ||
720 | pdev->drop_frames += 2; | ||
721 | pdev->vframes_error++; | ||
722 | } | ||
723 | if ((ptr[0] ^ pdev->vmirror) & 0x01) { | ||
724 | if (ptr[0] & 0x01) | ||
725 | Info("Snapshot button pressed.\n"); | ||
726 | else | ||
727 | Info("Snapshot button released.\n"); | ||
728 | } | ||
729 | if ((ptr[0] ^ pdev->vmirror) & 0x02) { | ||
730 | if (ptr[0] & 0x02) | ||
731 | Info("Image is mirrored.\n"); | ||
732 | else | ||
733 | Info("Image is normal.\n"); | ||
734 | } | ||
735 | pdev->vmirror = ptr[0] & 0x03; | ||
736 | /* Sometimes the trailer of the 730 is still sent as a 4 byte packet | ||
737 | after a short frame; this condition is filtered out specifically. A 4 byte | ||
738 | frame doesn't make sense anyway. | ||
739 | So we get either this sequence: | ||
740 | drop_bit set -> 4 byte frame -> short frame -> good frame | ||
741 | Or this one: | ||
742 | drop_bit set -> short frame -> good frame | ||
743 | So we drop either 3 or 2 frames in all! | ||
744 | */ | ||
745 | if (fbuf->filled == 4) | ||
746 | pdev->drop_frames++; | ||
747 | } | ||
748 | |||
749 | /* In case we were instructed to drop the frame, do so silently. | ||
750 | The buffer pointers are not updated either (but the counters are reset below). | ||
751 | */ | ||
752 | if (pdev->drop_frames > 0) | ||
753 | pdev->drop_frames--; | ||
754 | else { | ||
755 | /* Check for underflow first */ | ||
756 | if (fbuf->filled < pdev->frame_total_size) { | ||
757 | Trace(TRACE_FLOW, "Frame buffer underflow (%d bytes); discarded.\n", fbuf->filled); | ||
758 | pdev->vframes_error++; | ||
759 | } | ||
760 | else { | ||
761 | /* Send only once per EOF */ | ||
762 | awake = 1; /* delay wake_ups */ | ||
763 | |||
764 | /* Find our next frame to fill. This will always succeed, since we | ||
765 | * nick a frame from either empty or full list, but if we had to | ||
766 | * take it from the full list, it means a frame got dropped. | ||
767 | */ | ||
768 | if (pwc_next_fill_frame(pdev)) { | ||
769 | pdev->vframes_dumped++; | ||
770 | if ((pdev->vframe_count > FRAME_LOWMARK) && (pwc_trace & TRACE_FLOW)) { | ||
771 | if (pdev->vframes_dumped < 20) | ||
772 | Trace(TRACE_FLOW, "Dumping frame %d.\n", pdev->vframe_count); | ||
773 | if (pdev->vframes_dumped == 20) | ||
774 | Trace(TRACE_FLOW, "Dumping frame %d (last message).\n", pdev->vframe_count); | ||
775 | } | ||
776 | } | ||
777 | fbuf = pdev->fill_frame; | ||
778 | } | ||
779 | } /* !drop_frames */ | ||
780 | pdev->vframe_count++; | ||
781 | } | ||
782 | fbuf->filled = 0; | ||
783 | fillptr = fbuf->data; | ||
784 | pdev->vsync = 1; | ||
785 | } /* .. flen < last_packet_size */ | ||
786 | pdev->vlast_packet_size = flen; | ||
787 | } /* ..status == 0 */ | ||
788 | #if PWC_DEBUG | ||
789 | /* This is normally not interesting to the user, unless you are really debugging something */ | ||
790 | else { | ||
791 | static int iso_error = 0; | ||
792 | iso_error++; | ||
793 | if (iso_error < 20) | ||
794 | Trace(TRACE_FLOW, "Iso frame %d of USB has error %d\n", i, fst); | ||
795 | } | ||
796 | #endif | ||
797 | } | ||
798 | |||
799 | handler_end: | ||
800 | if (awake) | ||
801 | wake_up_interruptible(&pdev->frameq); | ||
802 | |||
803 | urb->dev = pdev->udev; | ||
804 | i = usb_submit_urb(urb, GFP_ATOMIC); | ||
805 | if (i != 0) | ||
806 | Err("Error (%d) re-submitting urb in pwc_isoc_handler.\n", i); | ||
807 | } | ||
808 | |||
809 | |||
810 | static int pwc_isoc_init(struct pwc_device *pdev) | ||
811 | { | ||
812 | struct usb_device *udev; | ||
813 | struct urb *urb; | ||
814 | int i, j, ret; | ||
815 | |||
816 | struct usb_interface *intf; | ||
817 | struct usb_host_interface *idesc = NULL; | ||
818 | |||
819 | if (pdev == NULL) | ||
820 | return -EFAULT; | ||
821 | if (pdev->iso_init) | ||
822 | return 0; | ||
823 | pdev->vsync = 0; | ||
824 | udev = pdev->udev; | ||
825 | |||
826 | /* Get the current alternate interface, adjust packet size */ | ||
827 | if (!udev->actconfig) | ||
828 | return -EFAULT; | ||
829 | |||
830 | intf = usb_ifnum_to_if(udev, 0); | ||
831 | if (intf) | ||
832 | idesc = usb_altnum_to_altsetting(intf, pdev->valternate); | ||
833 | |||
834 | if (!idesc) | ||
835 | return -EFAULT; | ||
836 | |||
837 | /* Search video endpoint */ | ||
838 | pdev->vmax_packet_size = -1; | ||
839 | for (i = 0; i < idesc->desc.bNumEndpoints; i++) | ||
840 | if ((idesc->endpoint[i].desc.bEndpointAddress & 0xF) == pdev->vendpoint) { | ||
841 | pdev->vmax_packet_size = le16_to_cpu(idesc->endpoint[i].desc.wMaxPacketSize); | ||
842 | break; | ||
843 | } | ||
844 | |||
845 | if (pdev->vmax_packet_size < 0 || pdev->vmax_packet_size > ISO_MAX_FRAME_SIZE) { | ||
846 | Err("Failed to find packet size for video endpoint in current alternate setting.\n"); | ||
847 | return -ENFILE; /* Odd error, that should be noticeable */ | ||
848 | } | ||
849 | |||
850 | /* Set alternate interface */ | ||
851 | ret = 0; | ||
852 | Trace(TRACE_OPEN, "Setting alternate interface %d\n", pdev->valternate); | ||
853 | ret = usb_set_interface(pdev->udev, 0, pdev->valternate); | ||
854 | if (ret < 0) | ||
855 | return ret; | ||
856 | |||
857 | for (i = 0; i < MAX_ISO_BUFS; i++) { | ||
858 | urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL); | ||
859 | if (urb == NULL) { | ||
860 | Err("Failed to allocate urb %d\n", i); | ||
861 | ret = -ENOMEM; | ||
862 | break; | ||
863 | } | ||
864 | pdev->sbuf[i].urb = urb; | ||
865 | Trace(TRACE_MEMORY, "Allocated URB at 0x%p\n", urb); | ||
866 | } | ||
867 | if (ret) { | ||
868 | /* De-allocate in reverse order */ | ||
869 | while (i >= 0) { | ||
870 | if (pdev->sbuf[i].urb != NULL) | ||
871 | usb_free_urb(pdev->sbuf[i].urb); | ||
872 | pdev->sbuf[i].urb = NULL; | ||
873 | i--; | ||
874 | } | ||
875 | return ret; | ||
876 | } | ||
877 | |||
878 | /* init URB structure */ | ||
879 | for (i = 0; i < MAX_ISO_BUFS; i++) { | ||
880 | urb = pdev->sbuf[i].urb; | ||
881 | |||
882 | urb->interval = 1; // devik | ||
883 | urb->dev = udev; | ||
884 | urb->pipe = usb_rcvisocpipe(udev, pdev->vendpoint); | ||
885 | urb->transfer_flags = URB_ISO_ASAP; | ||
886 | urb->transfer_buffer = pdev->sbuf[i].data; | ||
887 | urb->transfer_buffer_length = ISO_BUFFER_SIZE; | ||
888 | urb->complete = pwc_isoc_handler; | ||
889 | urb->context = pdev; | ||
890 | urb->start_frame = 0; | ||
891 | urb->number_of_packets = ISO_FRAMES_PER_DESC; | ||
892 | for (j = 0; j < ISO_FRAMES_PER_DESC; j++) { | ||
893 | urb->iso_frame_desc[j].offset = j * ISO_MAX_FRAME_SIZE; | ||
894 | urb->iso_frame_desc[j].length = pdev->vmax_packet_size; | ||
895 | } | ||
896 | } | ||
897 | |||
898 | /* link */ | ||
899 | for (i = 0; i < MAX_ISO_BUFS; i++) { | ||
900 | ret = usb_submit_urb(pdev->sbuf[i].urb, GFP_KERNEL); | ||
901 | if (ret) | ||
902 | Err("isoc_init() submit_urb %d failed with error %d\n", i, ret); | ||
903 | else | ||
904 | Trace(TRACE_MEMORY, "URB 0x%p submitted.\n", pdev->sbuf[i].urb); | ||
905 | } | ||
906 | |||
907 | /* All is done... */ | ||
908 | pdev->iso_init = 1; | ||
909 | Trace(TRACE_OPEN, "<< pwc_isoc_init()\n"); | ||
910 | return 0; | ||
911 | } | ||
912 | |||
913 | static void pwc_isoc_cleanup(struct pwc_device *pdev) | ||
914 | { | ||
915 | int i; | ||
916 | |||
917 | Trace(TRACE_OPEN, ">> pwc_isoc_cleanup()\n"); | ||
918 | if (pdev == NULL) | ||
919 | return; | ||
920 | |||
921 | /* Unlinking ISOC buffers one by one */ | ||
922 | for (i = 0; i < MAX_ISO_BUFS; i++) { | ||
923 | struct urb *urb; | ||
924 | |||
925 | urb = pdev->sbuf[i].urb; | ||
926 | if (urb != 0) { | ||
927 | if (pdev->iso_init) { | ||
928 | Trace(TRACE_MEMORY, "Unlinking URB %p\n", urb); | ||
929 | usb_kill_urb(urb); | ||
930 | } | ||
931 | Trace(TRACE_MEMORY, "Freeing URB\n"); | ||
932 | usb_free_urb(urb); | ||
933 | pdev->sbuf[i].urb = NULL; | ||
934 | } | ||
935 | } | ||
936 | |||
937 | /* Stop camera, but only if we are sure the camera is still there (unplug | ||
938 | is signalled by EPIPE) | ||
939 | */ | ||
940 | if (pdev->error_status && pdev->error_status != EPIPE) { | ||
941 | Trace(TRACE_OPEN, "Setting alternate interface 0.\n"); | ||
942 | usb_set_interface(pdev->udev, 0, 0); | ||
943 | } | ||
944 | |||
945 | pdev->iso_init = 0; | ||
946 | Trace(TRACE_OPEN, "<< pwc_isoc_cleanup()\n"); | ||
947 | } | ||
948 | |||
949 | int pwc_try_video_mode(struct pwc_device *pdev, int width, int height, int new_fps, int new_compression, int new_snapshot) | ||
950 | { | ||
951 | int ret, start; | ||
952 | |||
953 | /* Stop isoc stuff */ | ||
954 | pwc_isoc_cleanup(pdev); | ||
955 | /* Reset parameters */ | ||
956 | pwc_reset_buffers(pdev); | ||
957 | /* Try to set video mode... */ | ||
958 | start = ret = pwc_set_video_mode(pdev, width, height, new_fps, new_compression, new_snapshot); | ||
959 | if (ret) { | ||
960 | Trace(TRACE_FLOW, "pwc_set_video_mode attempt 1 failed.\n"); | ||
961 | /* That failed... restore old mode (we know that worked) */ | ||
962 | start = pwc_set_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, pdev->vcompression, pdev->vsnapshot); | ||
963 | if (start) { | ||
964 | Trace(TRACE_FLOW, "pwc_set_video_mode attempt 2 failed.\n"); | ||
965 | } | ||
966 | } | ||
967 | if (start == 0) | ||
968 | { | ||
969 | if (pwc_isoc_init(pdev) < 0) | ||
970 | { | ||
971 | Info("Failed to restart ISOC transfers in pwc_try_video_mode.\n"); | ||
972 | ret = -EAGAIN; /* let's try again, who knows if it works a second time */ | ||
973 | } | ||
974 | } | ||
975 | pdev->drop_frames++; /* try to avoid garbage during switch */ | ||
976 | return ret; /* Return original error code */ | ||
977 | } | ||
978 | |||
979 | |||
980 | /***************************************************************************/ | ||
981 | /* Video4Linux functions */ | ||
982 | |||
983 | static int pwc_video_open(struct inode *inode, struct file *file) | ||
984 | { | ||
985 | int i; | ||
986 | struct video_device *vdev = video_devdata(file); | ||
987 | struct pwc_device *pdev; | ||
988 | |||
989 | Trace(TRACE_OPEN, ">> video_open called(vdev = 0x%p).\n", vdev); | ||
990 | |||
991 | pdev = (struct pwc_device *)vdev->priv; | ||
992 | if (pdev == NULL) | ||
993 | BUG(); | ||
994 | if (pdev->vopen) | ||
995 | return -EBUSY; | ||
996 | |||
997 | down(&pdev->modlock); | ||
998 | if (!pdev->usb_init) { | ||
999 | Trace(TRACE_OPEN, "Doing first time initialization.\n"); | ||
1000 | pdev->usb_init = 1; | ||
1001 | |||
1002 | if (pwc_trace & TRACE_OPEN) | ||
1003 | { | ||
1004 | /* Query sensor type */ | ||
1005 | const char *sensor_type = NULL; | ||
1006 | int ret; | ||
1007 | |||
1008 | ret = pwc_get_cmos_sensor(pdev, &i); | ||
1009 | if (ret >= 0) | ||
1010 | { | ||
1011 | switch(i) { | ||
1012 | case 0x00: sensor_type = "Hyundai CMOS sensor"; break; | ||
1013 | case 0x20: sensor_type = "Sony CCD sensor + TDA8787"; break; | ||
1014 | case 0x2E: sensor_type = "Sony CCD sensor + Exas 98L59"; break; | ||
1015 | case 0x2F: sensor_type = "Sony CCD sensor + ADI 9804"; break; | ||
1016 | case 0x30: sensor_type = "Sharp CCD sensor + TDA8787"; break; | ||
1017 | case 0x3E: sensor_type = "Sharp CCD sensor + Exas 98L59"; break; | ||
1018 | case 0x3F: sensor_type = "Sharp CCD sensor + ADI 9804"; break; | ||
1019 | case 0x40: sensor_type = "UPA 1021 sensor"; break; | ||
1020 | case 0x100: sensor_type = "VGA sensor"; break; | ||
1021 | case 0x101: sensor_type = "PAL MR sensor"; break; | ||
1022 | default: sensor_type = "unknown type of sensor"; break; | ||
1023 | } | ||
1024 | } | ||
1025 | if (sensor_type != NULL) | ||
1026 | Info("This %s camera is equipped with a %s (%d).\n", pdev->vdev->name, sensor_type, i); | ||
1027 | } | ||
1028 | } | ||
1029 | |||
1030 | /* Turn on camera */ | ||
1031 | if (power_save) { | ||
1032 | i = pwc_camera_power(pdev, 1); | ||
1033 | if (i < 0) | ||
1034 | Info("Failed to restore power to the camera! (%d)\n", i); | ||
1035 | } | ||
1036 | /* Set LED on/off time */ | ||
1037 | if (pwc_set_leds(pdev, led_on, led_off) < 0) | ||
1038 | Info("Failed to set LED on/off time.\n"); | ||
1039 | |||
1040 | pwc_construct(pdev); /* set min/max sizes correct */ | ||
1041 | |||
1042 | /* So far, so good. Allocate memory. */ | ||
1043 | i = pwc_allocate_buffers(pdev); | ||
1044 | if (i < 0) { | ||
1045 | Trace(TRACE_OPEN, "Failed to allocate buffer memory.\n"); | ||
1046 | up(&pdev->modlock); | ||
1047 | return i; | ||
1048 | } | ||
1049 | |||
1050 | /* Reset buffers & parameters */ | ||
1051 | pwc_reset_buffers(pdev); | ||
1052 | for (i = 0; i < default_mbufs; i++) | ||
1053 | pdev->image_used[i] = 0; | ||
1054 | pdev->vframe_count = 0; | ||
1055 | pdev->vframes_dumped = 0; | ||
1056 | pdev->vframes_error = 0; | ||
1057 | pdev->visoc_errors = 0; | ||
1058 | pdev->error_status = 0; | ||
1059 | #if PWC_DEBUG | ||
1060 | pdev->sequence = 0; | ||
1061 | #endif | ||
1062 | pwc_construct(pdev); /* set min/max sizes correct */ | ||
1063 | |||
1064 | /* Set some defaults */ | ||
1065 | pdev->vsnapshot = 0; | ||
1066 | |||
1067 | /* Start iso pipe for video; first try the last used video size | ||
1068 | (or the default one); if that fails try QCIF/10 or QSIF/10; | ||
1069 | it that fails too, give up. | ||
1070 | */ | ||
1071 | i = pwc_set_video_mode(pdev, pwc_image_sizes[pdev->vsize].x, pwc_image_sizes[pdev->vsize].y, pdev->vframes, pdev->vcompression, 0); | ||
1072 | if (i) { | ||
1073 | Trace(TRACE_OPEN, "First attempt at set_video_mode failed.\n"); | ||
1074 | if (pdev->type == 730 || pdev->type == 740 || pdev->type == 750) | ||
1075 | i = pwc_set_video_mode(pdev, pwc_image_sizes[PSZ_QSIF].x, pwc_image_sizes[PSZ_QSIF].y, 10, pdev->vcompression, 0); | ||
1076 | else | ||
1077 | i = pwc_set_video_mode(pdev, pwc_image_sizes[PSZ_QCIF].x, pwc_image_sizes[PSZ_QCIF].y, 10, pdev->vcompression, 0); | ||
1078 | } | ||
1079 | if (i) { | ||
1080 | Trace(TRACE_OPEN, "Second attempt at set_video_mode failed.\n"); | ||
1081 | up(&pdev->modlock); | ||
1082 | return i; | ||
1083 | } | ||
1084 | |||
1085 | i = pwc_isoc_init(pdev); | ||
1086 | if (i) { | ||
1087 | Trace(TRACE_OPEN, "Failed to init ISOC stuff = %d.\n", i); | ||
1088 | up(&pdev->modlock); | ||
1089 | return i; | ||
1090 | } | ||
1091 | |||
1092 | pdev->vopen++; | ||
1093 | file->private_data = vdev; | ||
1094 | up(&pdev->modlock); | ||
1095 | Trace(TRACE_OPEN, "<< video_open() returns 0.\n"); | ||
1096 | return 0; | ||
1097 | } | ||
1098 | |||
1099 | /* Note that all cleanup is done in the reverse order as in _open */ | ||
1100 | static int pwc_video_close(struct inode *inode, struct file *file) | ||
1101 | { | ||
1102 | struct video_device *vdev = file->private_data; | ||
1103 | struct pwc_device *pdev; | ||
1104 | int i; | ||
1105 | |||
1106 | Trace(TRACE_OPEN, ">> video_close called(vdev = 0x%p).\n", vdev); | ||
1107 | |||
1108 | pdev = (struct pwc_device *)vdev->priv; | ||
1109 | if (pdev->vopen == 0) | ||
1110 | Info("video_close() called on closed device?\n"); | ||
1111 | |||
1112 | /* Dump statistics, but only if a reasonable amount of frames were | ||
1113 | processed (to prevent endless log-entries in case of snap-shot | ||
1114 | programs) | ||
1115 | */ | ||
1116 | if (pdev->vframe_count > 20) | ||
1117 | Info("Closing video device: %d frames received, dumped %d frames, %d frames with errors.\n", pdev->vframe_count, pdev->vframes_dumped, pdev->vframes_error); | ||
1118 | |||
1119 | switch (pdev->type) | ||
1120 | { | ||
1121 | case 675: | ||
1122 | case 680: | ||
1123 | case 690: | ||
1124 | case 720: | ||
1125 | case 730: | ||
1126 | case 740: | ||
1127 | case 750: | ||
1128 | /* pwc_dec23_exit(); *//* Timon & Kiara */ | ||
1129 | break; | ||
1130 | case 645: | ||
1131 | case 646: | ||
1132 | /* pwc_dec1_exit(); */ | ||
1133 | break; | ||
1134 | } | ||
1135 | |||
1136 | pwc_isoc_cleanup(pdev); | ||
1137 | pwc_free_buffers(pdev); | ||
1138 | |||
1139 | /* Turn off LEDS and power down camera, but only when not unplugged */ | ||
1140 | if (pdev->error_status != EPIPE) { | ||
1141 | /* Turn LEDs off */ | ||
1142 | if (pwc_set_leds(pdev, 0, 0) < 0) | ||
1143 | Info("Failed to set LED on/off time.\n"); | ||
1144 | if (power_save) { | ||
1145 | i = pwc_camera_power(pdev, 0); | ||
1146 | if (i < 0) | ||
1147 | Err("Failed to power down camera (%d)\n", i); | ||
1148 | } | ||
1149 | } | ||
1150 | pdev->vopen = 0; | ||
1151 | Trace(TRACE_OPEN, "<< video_close()\n"); | ||
1152 | return 0; | ||
1153 | } | ||
1154 | |||
1155 | /* | ||
1156 | * FIXME: what about two parallel reads ???? | ||
1157 | * ANSWER: Not supported. You can't open the device more than once, | ||
1158 | despite what the V4L1 interface says. First, I don't see | ||
1159 | the need, second there's no mechanism of alerting the | ||
1160 | 2nd/3rd/... process of events like changing image size. | ||
1161 | And I don't see the point of blocking that for the | ||
1162 | 2nd/3rd/... process. | ||
1163 | In multi-threaded environments reading parallel from any | ||
1164 | device is tricky anyhow. | ||
1165 | */ | ||
1166 | |||
1167 | static ssize_t pwc_video_read(struct file *file, char __user * buf, | ||
1168 | size_t count, loff_t *ppos) | ||
1169 | { | ||
1170 | struct video_device *vdev = file->private_data; | ||
1171 | struct pwc_device *pdev; | ||
1172 | int noblock = file->f_flags & O_NONBLOCK; | ||
1173 | DECLARE_WAITQUEUE(wait, current); | ||
1174 | int bytes_to_read; | ||
1175 | |||
1176 | Trace(TRACE_READ, "video_read(0x%p, %p, %zu) called.\n", vdev, buf, count); | ||
1177 | if (vdev == NULL) | ||
1178 | return -EFAULT; | ||
1179 | pdev = vdev->priv; | ||
1180 | if (pdev == NULL) | ||
1181 | return -EFAULT; | ||
1182 | if (pdev->error_status) | ||
1183 | return -pdev->error_status; /* Something happened, report what. */ | ||
1184 | |||
1185 | /* In case we're doing partial reads, we don't have to wait for a frame */ | ||
1186 | if (pdev->image_read_pos == 0) { | ||
1187 | /* Do wait queueing according to the (doc)book */ | ||
1188 | add_wait_queue(&pdev->frameq, &wait); | ||
1189 | while (pdev->full_frames == NULL) { | ||
1190 | /* Check for unplugged/etc. here */ | ||
1191 | if (pdev->error_status) { | ||
1192 | remove_wait_queue(&pdev->frameq, &wait); | ||
1193 | set_current_state(TASK_RUNNING); | ||
1194 | return -pdev->error_status ; | ||
1195 | } | ||
1196 | if (noblock) { | ||
1197 | remove_wait_queue(&pdev->frameq, &wait); | ||
1198 | set_current_state(TASK_RUNNING); | ||
1199 | return -EWOULDBLOCK; | ||
1200 | } | ||
1201 | if (signal_pending(current)) { | ||
1202 | remove_wait_queue(&pdev->frameq, &wait); | ||
1203 | set_current_state(TASK_RUNNING); | ||
1204 | return -ERESTARTSYS; | ||
1205 | } | ||
1206 | schedule(); | ||
1207 | set_current_state(TASK_INTERRUPTIBLE); | ||
1208 | } | ||
1209 | remove_wait_queue(&pdev->frameq, &wait); | ||
1210 | set_current_state(TASK_RUNNING); | ||
1211 | |||
1212 | /* Decompress and release frame */ | ||
1213 | if (pwc_handle_frame(pdev)) | ||
1214 | return -EFAULT; | ||
1215 | } | ||
1216 | |||
1217 | Trace(TRACE_READ, "Copying data to user space.\n"); | ||
1218 | if (pdev->vpalette == VIDEO_PALETTE_RAW) | ||
1219 | bytes_to_read = pdev->frame_size; | ||
1220 | else | ||
1221 | bytes_to_read = pdev->view.size; | ||
1222 | |||
1223 | /* copy bytes to user space; we allow for partial reads */ | ||
1224 | if (count + pdev->image_read_pos > bytes_to_read) | ||
1225 | count = bytes_to_read - pdev->image_read_pos; | ||
1226 | if (copy_to_user(buf, pdev->image_ptr[pdev->fill_image] + pdev->image_read_pos, count)) | ||
1227 | return -EFAULT; | ||
1228 | pdev->image_read_pos += count; | ||
1229 | if (pdev->image_read_pos >= bytes_to_read) { /* All data has been read */ | ||
1230 | pdev->image_read_pos = 0; | ||
1231 | pwc_next_image(pdev); | ||
1232 | } | ||
1233 | return count; | ||
1234 | } | ||
1235 | |||
1236 | static unsigned int pwc_video_poll(struct file *file, poll_table *wait) | ||
1237 | { | ||
1238 | struct video_device *vdev = file->private_data; | ||
1239 | struct pwc_device *pdev; | ||
1240 | |||
1241 | if (vdev == NULL) | ||
1242 | return -EFAULT; | ||
1243 | pdev = vdev->priv; | ||
1244 | if (pdev == NULL) | ||
1245 | return -EFAULT; | ||
1246 | |||
1247 | poll_wait(file, &pdev->frameq, wait); | ||
1248 | if (pdev->error_status) | ||
1249 | return POLLERR; | ||
1250 | if (pdev->full_frames != NULL) /* we have frames waiting */ | ||
1251 | return (POLLIN | POLLRDNORM); | ||
1252 | |||
1253 | return 0; | ||
1254 | } | ||
1255 | |||
1256 | static int pwc_video_do_ioctl(struct inode *inode, struct file *file, | ||
1257 | unsigned int cmd, void *arg) | ||
1258 | { | ||
1259 | struct video_device *vdev = file->private_data; | ||
1260 | struct pwc_device *pdev; | ||
1261 | DECLARE_WAITQUEUE(wait, current); | ||
1262 | |||
1263 | if (vdev == NULL) | ||
1264 | return -EFAULT; | ||
1265 | pdev = vdev->priv; | ||
1266 | if (pdev == NULL) | ||
1267 | return -EFAULT; | ||
1268 | |||
1269 | switch (cmd) { | ||
1270 | /* Query cabapilities */ | ||
1271 | case VIDIOCGCAP: | ||
1272 | { | ||
1273 | struct video_capability *caps = arg; | ||
1274 | |||
1275 | strcpy(caps->name, vdev->name); | ||
1276 | caps->type = VID_TYPE_CAPTURE; | ||
1277 | caps->channels = 1; | ||
1278 | caps->audios = 1; | ||
1279 | caps->minwidth = pdev->view_min.x; | ||
1280 | caps->minheight = pdev->view_min.y; | ||
1281 | caps->maxwidth = pdev->view_max.x; | ||
1282 | caps->maxheight = pdev->view_max.y; | ||
1283 | break; | ||
1284 | } | ||
1285 | |||
1286 | /* Channel functions (simulate 1 channel) */ | ||
1287 | case VIDIOCGCHAN: | ||
1288 | { | ||
1289 | struct video_channel *v = arg; | ||
1290 | |||
1291 | if (v->channel != 0) | ||
1292 | return -EINVAL; | ||
1293 | v->flags = 0; | ||
1294 | v->tuners = 0; | ||
1295 | v->type = VIDEO_TYPE_CAMERA; | ||
1296 | strcpy(v->name, "Webcam"); | ||
1297 | return 0; | ||
1298 | } | ||
1299 | |||
1300 | case VIDIOCSCHAN: | ||
1301 | { | ||
1302 | /* The spec says the argument is an integer, but | ||
1303 | the bttv driver uses a video_channel arg, which | ||
1304 | makes sense becasue it also has the norm flag. | ||
1305 | */ | ||
1306 | struct video_channel *v = arg; | ||
1307 | if (v->channel != 0) | ||
1308 | return -EINVAL; | ||
1309 | return 0; | ||
1310 | } | ||
1311 | |||
1312 | |||
1313 | /* Picture functions; contrast etc. */ | ||
1314 | case VIDIOCGPICT: | ||
1315 | { | ||
1316 | struct video_picture *p = arg; | ||
1317 | int val; | ||
1318 | |||
1319 | val = pwc_get_brightness(pdev); | ||
1320 | if (val >= 0) | ||
1321 | p->brightness = val; | ||
1322 | else | ||
1323 | p->brightness = 0xffff; | ||
1324 | val = pwc_get_contrast(pdev); | ||
1325 | if (val >= 0) | ||
1326 | p->contrast = val; | ||
1327 | else | ||
1328 | p->contrast = 0xffff; | ||
1329 | /* Gamma, Whiteness, what's the difference? :) */ | ||
1330 | val = pwc_get_gamma(pdev); | ||
1331 | if (val >= 0) | ||
1332 | p->whiteness = val; | ||
1333 | else | ||
1334 | p->whiteness = 0xffff; | ||
1335 | val = pwc_get_saturation(pdev); | ||
1336 | if (val >= 0) | ||
1337 | p->colour = val; | ||
1338 | else | ||
1339 | p->colour = 0xffff; | ||
1340 | p->depth = 24; | ||
1341 | p->palette = pdev->vpalette; | ||
1342 | p->hue = 0xFFFF; /* N/A */ | ||
1343 | break; | ||
1344 | } | ||
1345 | |||
1346 | case VIDIOCSPICT: | ||
1347 | { | ||
1348 | struct video_picture *p = arg; | ||
1349 | /* | ||
1350 | * FIXME: Suppose we are mid read | ||
1351 | ANSWER: No problem: the firmware of the camera | ||
1352 | can handle brightness/contrast/etc | ||
1353 | changes at _any_ time, and the palette | ||
1354 | is used exactly once in the uncompress | ||
1355 | routine. | ||
1356 | */ | ||
1357 | pwc_set_brightness(pdev, p->brightness); | ||
1358 | pwc_set_contrast(pdev, p->contrast); | ||
1359 | pwc_set_gamma(pdev, p->whiteness); | ||
1360 | pwc_set_saturation(pdev, p->colour); | ||
1361 | if (p->palette && p->palette != pdev->vpalette) { | ||
1362 | switch (p->palette) { | ||
1363 | case VIDEO_PALETTE_YUV420P: | ||
1364 | case VIDEO_PALETTE_RAW: | ||
1365 | pdev->vpalette = p->palette; | ||
1366 | return pwc_try_video_mode(pdev, pdev->image.x, pdev->image.y, pdev->vframes, pdev->vcompression, pdev->vsnapshot); | ||
1367 | break; | ||
1368 | default: | ||
1369 | return -EINVAL; | ||
1370 | break; | ||
1371 | } | ||
1372 | } | ||
1373 | break; | ||
1374 | } | ||
1375 | |||
1376 | /* Window/size parameters */ | ||
1377 | case VIDIOCGWIN: | ||
1378 | { | ||
1379 | struct video_window *vw = arg; | ||
1380 | |||
1381 | vw->x = 0; | ||
1382 | vw->y = 0; | ||
1383 | vw->width = pdev->view.x; | ||
1384 | vw->height = pdev->view.y; | ||
1385 | vw->chromakey = 0; | ||
1386 | vw->flags = (pdev->vframes << PWC_FPS_SHIFT) | | ||
1387 | (pdev->vsnapshot ? PWC_FPS_SNAPSHOT : 0); | ||
1388 | break; | ||
1389 | } | ||
1390 | |||
1391 | case VIDIOCSWIN: | ||
1392 | { | ||
1393 | struct video_window *vw = arg; | ||
1394 | int fps, snapshot, ret; | ||
1395 | |||
1396 | fps = (vw->flags & PWC_FPS_FRMASK) >> PWC_FPS_SHIFT; | ||
1397 | snapshot = vw->flags & PWC_FPS_SNAPSHOT; | ||
1398 | if (fps == 0) | ||
1399 | fps = pdev->vframes; | ||
1400 | if (pdev->view.x == vw->width && pdev->view.y && fps == pdev->vframes && snapshot == pdev->vsnapshot) | ||
1401 | return 0; | ||
1402 | ret = pwc_try_video_mode(pdev, vw->width, vw->height, fps, pdev->vcompression, snapshot); | ||
1403 | if (ret) | ||
1404 | return ret; | ||
1405 | break; | ||
1406 | } | ||
1407 | |||
1408 | /* We don't have overlay support (yet) */ | ||
1409 | case VIDIOCGFBUF: | ||
1410 | { | ||
1411 | struct video_buffer *vb = arg; | ||
1412 | |||
1413 | memset(vb,0,sizeof(*vb)); | ||
1414 | break; | ||
1415 | } | ||
1416 | |||
1417 | /* mmap() functions */ | ||
1418 | case VIDIOCGMBUF: | ||
1419 | { | ||
1420 | /* Tell the user program how much memory is needed for a mmap() */ | ||
1421 | struct video_mbuf *vm = arg; | ||
1422 | int i; | ||
1423 | |||
1424 | memset(vm, 0, sizeof(*vm)); | ||
1425 | vm->size = default_mbufs * pdev->len_per_image; | ||
1426 | vm->frames = default_mbufs; /* double buffering should be enough for most applications */ | ||
1427 | for (i = 0; i < default_mbufs; i++) | ||
1428 | vm->offsets[i] = i * pdev->len_per_image; | ||
1429 | break; | ||
1430 | } | ||
1431 | |||
1432 | case VIDIOCMCAPTURE: | ||
1433 | { | ||
1434 | /* Start capture into a given image buffer (called 'frame' in video_mmap structure) */ | ||
1435 | struct video_mmap *vm = arg; | ||
1436 | |||
1437 | Trace(TRACE_READ, "VIDIOCMCAPTURE: %dx%d, frame %d, format %d\n", vm->width, vm->height, vm->frame, vm->format); | ||
1438 | if (vm->frame < 0 || vm->frame >= default_mbufs) | ||
1439 | return -EINVAL; | ||
1440 | |||
1441 | /* xawtv is nasty. It probes the available palettes | ||
1442 | by setting a very small image size and trying | ||
1443 | various palettes... The driver doesn't support | ||
1444 | such small images, so I'm working around it. | ||
1445 | */ | ||
1446 | if (vm->format) | ||
1447 | { | ||
1448 | switch (vm->format) | ||
1449 | { | ||
1450 | case VIDEO_PALETTE_YUV420P: | ||
1451 | case VIDEO_PALETTE_RAW: | ||
1452 | break; | ||
1453 | default: | ||
1454 | return -EINVAL; | ||
1455 | break; | ||
1456 | } | ||
1457 | } | ||
1458 | |||
1459 | if ((vm->width != pdev->view.x || vm->height != pdev->view.y) && | ||
1460 | (vm->width >= pdev->view_min.x && vm->height >= pdev->view_min.y)) { | ||
1461 | int ret; | ||
1462 | |||
1463 | Trace(TRACE_OPEN, "VIDIOCMCAPTURE: changing size to please xawtv :-(.\n"); | ||
1464 | ret = pwc_try_video_mode(pdev, vm->width, vm->height, pdev->vframes, pdev->vcompression, pdev->vsnapshot); | ||
1465 | if (ret) | ||
1466 | return ret; | ||
1467 | } /* ... size mismatch */ | ||
1468 | |||
1469 | /* FIXME: should we lock here? */ | ||
1470 | if (pdev->image_used[vm->frame]) | ||
1471 | return -EBUSY; /* buffer wasn't available. Bummer */ | ||
1472 | pdev->image_used[vm->frame] = 1; | ||
1473 | |||
1474 | /* Okay, we're done here. In the SYNC call we wait until a | ||
1475 | frame comes available, then expand image into the given | ||
1476 | buffer. | ||
1477 | In contrast to the CPiA cam the Philips cams deliver a | ||
1478 | constant stream, almost like a grabber card. Also, | ||
1479 | we have separate buffers for the rawdata and the image, | ||
1480 | meaning we can nearly always expand into the requested buffer. | ||
1481 | */ | ||
1482 | Trace(TRACE_READ, "VIDIOCMCAPTURE done.\n"); | ||
1483 | break; | ||
1484 | } | ||
1485 | |||
1486 | case VIDIOCSYNC: | ||
1487 | { | ||
1488 | /* The doc says: "Whenever a buffer is used it should | ||
1489 | call VIDIOCSYNC to free this frame up and continue." | ||
1490 | |||
1491 | The only odd thing about this whole procedure is | ||
1492 | that MCAPTURE flags the buffer as "in use", and | ||
1493 | SYNC immediately unmarks it, while it isn't | ||
1494 | after SYNC that you know that the buffer actually | ||
1495 | got filled! So you better not start a CAPTURE in | ||
1496 | the same frame immediately (use double buffering). | ||
1497 | This is not a problem for this cam, since it has | ||
1498 | extra intermediate buffers, but a hardware | ||
1499 | grabber card will then overwrite the buffer | ||
1500 | you're working on. | ||
1501 | */ | ||
1502 | int *mbuf = arg; | ||
1503 | int ret; | ||
1504 | |||
1505 | Trace(TRACE_READ, "VIDIOCSYNC called (%d).\n", *mbuf); | ||
1506 | |||
1507 | /* bounds check */ | ||
1508 | if (*mbuf < 0 || *mbuf >= default_mbufs) | ||
1509 | return -EINVAL; | ||
1510 | /* check if this buffer was requested anyway */ | ||
1511 | if (pdev->image_used[*mbuf] == 0) | ||
1512 | return -EINVAL; | ||
1513 | |||
1514 | /* Add ourselves to the frame wait-queue. | ||
1515 | |||
1516 | FIXME: needs auditing for safety. | ||
1517 | QUESTION: In what respect? I think that using the | ||
1518 | frameq is safe now. | ||
1519 | */ | ||
1520 | add_wait_queue(&pdev->frameq, &wait); | ||
1521 | while (pdev->full_frames == NULL) { | ||
1522 | if (pdev->error_status) { | ||
1523 | remove_wait_queue(&pdev->frameq, &wait); | ||
1524 | set_current_state(TASK_RUNNING); | ||
1525 | return -pdev->error_status; | ||
1526 | } | ||
1527 | |||
1528 | if (signal_pending(current)) { | ||
1529 | remove_wait_queue(&pdev->frameq, &wait); | ||
1530 | set_current_state(TASK_RUNNING); | ||
1531 | return -ERESTARTSYS; | ||
1532 | } | ||
1533 | schedule(); | ||
1534 | set_current_state(TASK_INTERRUPTIBLE); | ||
1535 | } | ||
1536 | remove_wait_queue(&pdev->frameq, &wait); | ||
1537 | set_current_state(TASK_RUNNING); | ||
1538 | |||
1539 | /* The frame is ready. Expand in the image buffer | ||
1540 | requested by the user. I don't care if you | ||
1541 | mmap() 5 buffers and request data in this order: | ||
1542 | buffer 4 2 3 0 1 2 3 0 4 3 1 . . . | ||
1543 | Grabber hardware may not be so forgiving. | ||
1544 | */ | ||
1545 | Trace(TRACE_READ, "VIDIOCSYNC: frame ready.\n"); | ||
1546 | pdev->fill_image = *mbuf; /* tell in which buffer we want the image to be expanded */ | ||
1547 | /* Decompress, etc */ | ||
1548 | ret = pwc_handle_frame(pdev); | ||
1549 | pdev->image_used[*mbuf] = 0; | ||
1550 | if (ret) | ||
1551 | return -EFAULT; | ||
1552 | break; | ||
1553 | } | ||
1554 | |||
1555 | case VIDIOCGAUDIO: | ||
1556 | { | ||
1557 | struct video_audio *v = arg; | ||
1558 | |||
1559 | strcpy(v->name, "Microphone"); | ||
1560 | v->audio = -1; /* unknown audio minor */ | ||
1561 | v->flags = 0; | ||
1562 | v->mode = VIDEO_SOUND_MONO; | ||
1563 | v->volume = 0; | ||
1564 | v->bass = 0; | ||
1565 | v->treble = 0; | ||
1566 | v->balance = 0x8000; | ||
1567 | v->step = 1; | ||
1568 | break; | ||
1569 | } | ||
1570 | |||
1571 | case VIDIOCSAUDIO: | ||
1572 | { | ||
1573 | /* Dummy: nothing can be set */ | ||
1574 | break; | ||
1575 | } | ||
1576 | |||
1577 | case VIDIOCGUNIT: | ||
1578 | { | ||
1579 | struct video_unit *vu = arg; | ||
1580 | |||
1581 | vu->video = pdev->vdev->minor & 0x3F; | ||
1582 | vu->audio = -1; /* not known yet */ | ||
1583 | vu->vbi = -1; | ||
1584 | vu->radio = -1; | ||
1585 | vu->teletext = -1; | ||
1586 | break; | ||
1587 | } | ||
1588 | default: | ||
1589 | return pwc_ioctl(pdev, cmd, arg); | ||
1590 | } /* ..switch */ | ||
1591 | return 0; | ||
1592 | } | ||
1593 | |||
1594 | static int pwc_video_ioctl(struct inode *inode, struct file *file, | ||
1595 | unsigned int cmd, unsigned long arg) | ||
1596 | { | ||
1597 | return video_usercopy(inode, file, cmd, arg, pwc_video_do_ioctl); | ||
1598 | } | ||
1599 | |||
1600 | |||
1601 | static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma) | ||
1602 | { | ||
1603 | struct video_device *vdev = file->private_data; | ||
1604 | struct pwc_device *pdev; | ||
1605 | unsigned long start = vma->vm_start; | ||
1606 | unsigned long size = vma->vm_end-vma->vm_start; | ||
1607 | unsigned long page, pos; | ||
1608 | |||
1609 | Trace(TRACE_MEMORY, "mmap(0x%p, 0x%lx, %lu) called.\n", vdev, start, size); | ||
1610 | pdev = vdev->priv; | ||
1611 | |||
1612 | vma->vm_flags |= VM_IO; | ||
1613 | |||
1614 | pos = (unsigned long)pdev->image_data; | ||
1615 | while (size > 0) { | ||
1616 | page = vmalloc_to_pfn((void *)pos); | ||
1617 | if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) | ||
1618 | return -EAGAIN; | ||
1619 | |||
1620 | start += PAGE_SIZE; | ||
1621 | pos += PAGE_SIZE; | ||
1622 | if (size > PAGE_SIZE) | ||
1623 | size -= PAGE_SIZE; | ||
1624 | else | ||
1625 | size = 0; | ||
1626 | } | ||
1627 | |||
1628 | return 0; | ||
1629 | } | ||
1630 | |||
1631 | /***************************************************************************/ | ||
1632 | /* USB functions */ | ||
1633 | |||
1634 | /* This function gets called when a new device is plugged in or the usb core | ||
1635 | * is loaded. | ||
1636 | */ | ||
1637 | |||
1638 | static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id *id) | ||
1639 | { | ||
1640 | struct usb_device *udev = interface_to_usbdev(intf); | ||
1641 | struct pwc_device *pdev = NULL; | ||
1642 | int vendor_id, product_id, type_id; | ||
1643 | int i, hint; | ||
1644 | int features = 0; | ||
1645 | int video_nr = -1; /* default: use next available device */ | ||
1646 | char serial_number[30], *name; | ||
1647 | |||
1648 | /* Check if we can handle this device */ | ||
1649 | Trace(TRACE_PROBE, "probe() called [%04X %04X], if %d\n", | ||
1650 | le16_to_cpu(udev->descriptor.idVendor), | ||
1651 | le16_to_cpu(udev->descriptor.idProduct), | ||
1652 | intf->altsetting->desc.bInterfaceNumber); | ||
1653 | |||
1654 | /* the interfaces are probed one by one. We are only interested in the | ||
1655 | video interface (0) now. | ||
1656 | Interface 1 is the Audio Control, and interface 2 Audio itself. | ||
1657 | */ | ||
1658 | if (intf->altsetting->desc.bInterfaceNumber > 0) | ||
1659 | return -ENODEV; | ||
1660 | |||
1661 | vendor_id = le16_to_cpu(udev->descriptor.idVendor); | ||
1662 | product_id = le16_to_cpu(udev->descriptor.idProduct); | ||
1663 | |||
1664 | if (vendor_id == 0x0471) { | ||
1665 | switch (product_id) { | ||
1666 | case 0x0302: | ||
1667 | Info("Philips PCA645VC USB webcam detected.\n"); | ||
1668 | name = "Philips 645 webcam"; | ||
1669 | type_id = 645; | ||
1670 | break; | ||
1671 | case 0x0303: | ||
1672 | Info("Philips PCA646VC USB webcam detected.\n"); | ||
1673 | name = "Philips 646 webcam"; | ||
1674 | type_id = 646; | ||
1675 | break; | ||
1676 | case 0x0304: | ||
1677 | Info("Askey VC010 type 2 USB webcam detected.\n"); | ||
1678 | name = "Askey VC010 webcam"; | ||
1679 | type_id = 646; | ||
1680 | break; | ||
1681 | case 0x0307: | ||
1682 | Info("Philips PCVC675K (Vesta) USB webcam detected.\n"); | ||
1683 | name = "Philips 675 webcam"; | ||
1684 | type_id = 675; | ||
1685 | break; | ||
1686 | case 0x0308: | ||
1687 | Info("Philips PCVC680K (Vesta Pro) USB webcam detected.\n"); | ||
1688 | name = "Philips 680 webcam"; | ||
1689 | type_id = 680; | ||
1690 | break; | ||
1691 | case 0x030C: | ||
1692 | Info("Philips PCVC690K (Vesta Pro Scan) USB webcam detected.\n"); | ||
1693 | name = "Philips 690 webcam"; | ||
1694 | type_id = 690; | ||
1695 | break; | ||
1696 | case 0x0310: | ||
1697 | Info("Philips PCVC730K (ToUCam Fun)/PCVC830 (ToUCam II) USB webcam detected.\n"); | ||
1698 | name = "Philips 730 webcam"; | ||
1699 | type_id = 730; | ||
1700 | break; | ||
1701 | case 0x0311: | ||
1702 | Info("Philips PCVC740K (ToUCam Pro)/PCVC840 (ToUCam II) USB webcam detected.\n"); | ||
1703 | name = "Philips 740 webcam"; | ||
1704 | type_id = 740; | ||
1705 | break; | ||
1706 | case 0x0312: | ||
1707 | Info("Philips PCVC750K (ToUCam Pro Scan) USB webcam detected.\n"); | ||
1708 | name = "Philips 750 webcam"; | ||
1709 | type_id = 750; | ||
1710 | break; | ||
1711 | case 0x0313: | ||
1712 | Info("Philips PCVC720K/40 (ToUCam XS) USB webcam detected.\n"); | ||
1713 | name = "Philips 720K/40 webcam"; | ||
1714 | type_id = 720; | ||
1715 | break; | ||
1716 | default: | ||
1717 | return -ENODEV; | ||
1718 | break; | ||
1719 | } | ||
1720 | } | ||
1721 | else if (vendor_id == 0x069A) { | ||
1722 | switch(product_id) { | ||
1723 | case 0x0001: | ||
1724 | Info("Askey VC010 type 1 USB webcam detected.\n"); | ||
1725 | name = "Askey VC010 webcam"; | ||
1726 | type_id = 645; | ||
1727 | break; | ||
1728 | default: | ||
1729 | return -ENODEV; | ||
1730 | break; | ||
1731 | } | ||
1732 | } | ||
1733 | else if (vendor_id == 0x046d) { | ||
1734 | switch(product_id) { | ||
1735 | case 0x08b0: | ||
1736 | Info("Logitech QuickCam Pro 3000 USB webcam detected.\n"); | ||
1737 | name = "Logitech QuickCam Pro 3000"; | ||
1738 | type_id = 740; /* CCD sensor */ | ||
1739 | break; | ||
1740 | case 0x08b1: | ||
1741 | Info("Logitech QuickCam Notebook Pro USB webcam detected.\n"); | ||
1742 | name = "Logitech QuickCam Notebook Pro"; | ||
1743 | type_id = 740; /* CCD sensor */ | ||
1744 | break; | ||
1745 | case 0x08b2: | ||
1746 | Info("Logitech QuickCam 4000 Pro USB webcam detected.\n"); | ||
1747 | name = "Logitech QuickCam Pro 4000"; | ||
1748 | type_id = 740; /* CCD sensor */ | ||
1749 | break; | ||
1750 | case 0x08b3: | ||
1751 | Info("Logitech QuickCam Zoom USB webcam detected.\n"); | ||
1752 | name = "Logitech QuickCam Zoom"; | ||
1753 | type_id = 740; /* CCD sensor */ | ||
1754 | break; | ||
1755 | case 0x08B4: | ||
1756 | Info("Logitech QuickCam Zoom (new model) USB webcam detected.\n"); | ||
1757 | name = "Logitech QuickCam Zoom"; | ||
1758 | type_id = 740; /* CCD sensor */ | ||
1759 | break; | ||
1760 | case 0x08b5: | ||
1761 | Info("Logitech QuickCam Orbit/Sphere USB webcam detected.\n"); | ||
1762 | name = "Logitech QuickCam Orbit"; | ||
1763 | type_id = 740; /* CCD sensor */ | ||
1764 | features |= FEATURE_MOTOR_PANTILT; | ||
1765 | break; | ||
1766 | case 0x08b6: | ||
1767 | case 0x08b7: | ||
1768 | case 0x08b8: | ||
1769 | Info("Logitech QuickCam detected (reserved ID).\n"); | ||
1770 | name = "Logitech QuickCam (res.)"; | ||
1771 | type_id = 730; /* Assuming CMOS */ | ||
1772 | break; | ||
1773 | default: | ||
1774 | return -ENODEV; | ||
1775 | break; | ||
1776 | } | ||
1777 | } | ||
1778 | else if (vendor_id == 0x055d) { | ||
1779 | /* I don't know the difference between the C10 and the C30; | ||
1780 | I suppose the difference is the sensor, but both cameras | ||
1781 | work equally well with a type_id of 675 | ||
1782 | */ | ||
1783 | switch(product_id) { | ||
1784 | case 0x9000: | ||
1785 | Info("Samsung MPC-C10 USB webcam detected.\n"); | ||
1786 | name = "Samsung MPC-C10"; | ||
1787 | type_id = 675; | ||
1788 | break; | ||
1789 | case 0x9001: | ||
1790 | Info("Samsung MPC-C30 USB webcam detected.\n"); | ||
1791 | name = "Samsung MPC-C30"; | ||
1792 | type_id = 675; | ||
1793 | break; | ||
1794 | default: | ||
1795 | return -ENODEV; | ||
1796 | break; | ||
1797 | } | ||
1798 | } | ||
1799 | else if (vendor_id == 0x041e) { | ||
1800 | switch(product_id) { | ||
1801 | case 0x400c: | ||
1802 | Info("Creative Labs Webcam 5 detected.\n"); | ||
1803 | name = "Creative Labs Webcam 5"; | ||
1804 | type_id = 730; | ||
1805 | break; | ||
1806 | case 0x4011: | ||
1807 | Info("Creative Labs Webcam Pro Ex detected.\n"); | ||
1808 | name = "Creative Labs Webcam Pro Ex"; | ||
1809 | type_id = 740; | ||
1810 | break; | ||
1811 | default: | ||
1812 | return -ENODEV; | ||
1813 | break; | ||
1814 | } | ||
1815 | } | ||
1816 | else if (vendor_id == 0x04cc) { | ||
1817 | switch(product_id) { | ||
1818 | case 0x8116: | ||
1819 | Info("Sotec Afina Eye USB webcam detected.\n"); | ||
1820 | name = "Sotec Afina Eye"; | ||
1821 | type_id = 730; | ||
1822 | break; | ||
1823 | default: | ||
1824 | return -ENODEV; | ||
1825 | break; | ||
1826 | } | ||
1827 | } | ||
1828 | else if (vendor_id == 0x06be) { | ||
1829 | switch(product_id) { | ||
1830 | case 0x8116: | ||
1831 | /* This is essentially the same cam as the Sotec Afina Eye */ | ||
1832 | Info("AME Co. Afina Eye USB webcam detected.\n"); | ||
1833 | name = "AME Co. Afina Eye"; | ||
1834 | type_id = 750; | ||
1835 | break; | ||
1836 | default: | ||
1837 | return -ENODEV; | ||
1838 | break; | ||
1839 | } | ||
1840 | |||
1841 | } | ||
1842 | else if (vendor_id == 0x0d81) { | ||
1843 | switch(product_id) { | ||
1844 | case 0x1900: | ||
1845 | Info("Visionite VCS-UC300 USB webcam detected.\n"); | ||
1846 | name = "Visionite VCS-UC300"; | ||
1847 | type_id = 740; /* CCD sensor */ | ||
1848 | break; | ||
1849 | case 0x1910: | ||
1850 | Info("Visionite VCS-UM100 USB webcam detected.\n"); | ||
1851 | name = "Visionite VCS-UM100"; | ||
1852 | type_id = 730; /* CMOS sensor */ | ||
1853 | break; | ||
1854 | default: | ||
1855 | return -ENODEV; | ||
1856 | break; | ||
1857 | } | ||
1858 | } | ||
1859 | else | ||
1860 | return -ENODEV; /* Not any of the know types; but the list keeps growing. */ | ||
1861 | |||
1862 | memset(serial_number, 0, 30); | ||
1863 | usb_string(udev, udev->descriptor.iSerialNumber, serial_number, 29); | ||
1864 | Trace(TRACE_PROBE, "Device serial number is %s\n", serial_number); | ||
1865 | |||
1866 | if (udev->descriptor.bNumConfigurations > 1) | ||
1867 | Info("Warning: more than 1 configuration available.\n"); | ||
1868 | |||
1869 | /* Allocate structure, initialize pointers, mutexes, etc. and link it to the usb_device */ | ||
1870 | pdev = kzalloc(sizeof(struct pwc_device), GFP_KERNEL); | ||
1871 | if (pdev == NULL) { | ||
1872 | Err("Oops, could not allocate memory for pwc_device.\n"); | ||
1873 | return -ENOMEM; | ||
1874 | } | ||
1875 | pdev->type = type_id; | ||
1876 | pdev->vsize = default_size; | ||
1877 | pdev->vframes = default_fps; | ||
1878 | strcpy(pdev->serial, serial_number); | ||
1879 | pdev->features = features; | ||
1880 | if (vendor_id == 0x046D && product_id == 0x08B5) | ||
1881 | { | ||
1882 | /* Logitech QuickCam Orbit | ||
1883 | The ranges have been determined experimentally; they may differ from cam to cam. | ||
1884 | Also, the exact ranges left-right and up-down are different for my cam | ||
1885 | */ | ||
1886 | pdev->angle_range.pan_min = -7000; | ||
1887 | pdev->angle_range.pan_max = 7000; | ||
1888 | pdev->angle_range.tilt_min = -3000; | ||
1889 | pdev->angle_range.tilt_max = 2500; | ||
1890 | } | ||
1891 | |||
1892 | init_MUTEX(&pdev->modlock); | ||
1893 | spin_lock_init(&pdev->ptrlock); | ||
1894 | |||
1895 | pdev->udev = udev; | ||
1896 | init_waitqueue_head(&pdev->frameq); | ||
1897 | pdev->vcompression = pwc_preferred_compression; | ||
1898 | |||
1899 | /* Allocate video_device structure */ | ||
1900 | pdev->vdev = video_device_alloc(); | ||
1901 | if (pdev->vdev == 0) | ||
1902 | { | ||
1903 | Err("Err, cannot allocate video_device struture. Failing probe."); | ||
1904 | kfree(pdev); | ||
1905 | return -ENOMEM; | ||
1906 | } | ||
1907 | memcpy(pdev->vdev, &pwc_template, sizeof(pwc_template)); | ||
1908 | strcpy(pdev->vdev->name, name); | ||
1909 | pdev->vdev->owner = THIS_MODULE; | ||
1910 | video_set_drvdata(pdev->vdev, pdev); | ||
1911 | |||
1912 | pdev->release = le16_to_cpu(udev->descriptor.bcdDevice); | ||
1913 | Trace(TRACE_PROBE, "Release: %04x\n", pdev->release); | ||
1914 | |||
1915 | /* Now search device_hint[] table for a match, so we can hint a node number. */ | ||
1916 | for (hint = 0; hint < MAX_DEV_HINTS; hint++) { | ||
1917 | if (((device_hint[hint].type == -1) || (device_hint[hint].type == pdev->type)) && | ||
1918 | (device_hint[hint].pdev == NULL)) { | ||
1919 | /* so far, so good... try serial number */ | ||
1920 | if ((device_hint[hint].serial_number[0] == '*') || !strcmp(device_hint[hint].serial_number, serial_number)) { | ||
1921 | /* match! */ | ||
1922 | video_nr = device_hint[hint].device_node; | ||
1923 | Trace(TRACE_PROBE, "Found hint, will try to register as /dev/video%d\n", video_nr); | ||
1924 | break; | ||
1925 | } | ||
1926 | } | ||
1927 | } | ||
1928 | |||
1929 | pdev->vdev->release = video_device_release; | ||
1930 | i = video_register_device(pdev->vdev, VFL_TYPE_GRABBER, video_nr); | ||
1931 | if (i < 0) { | ||
1932 | Err("Failed to register as video device (%d).\n", i); | ||
1933 | video_device_release(pdev->vdev); /* Drip... drip... drip... */ | ||
1934 | kfree(pdev); /* Oops, no memory leaks please */ | ||
1935 | return -EIO; | ||
1936 | } | ||
1937 | else { | ||
1938 | Info("Registered as /dev/video%d.\n", pdev->vdev->minor & 0x3F); | ||
1939 | } | ||
1940 | |||
1941 | /* occupy slot */ | ||
1942 | if (hint < MAX_DEV_HINTS) | ||
1943 | device_hint[hint].pdev = pdev; | ||
1944 | |||
1945 | Trace(TRACE_PROBE, "probe() function returning struct at 0x%p.\n", pdev); | ||
1946 | usb_set_intfdata (intf, pdev); | ||
1947 | return 0; | ||
1948 | } | ||
1949 | |||
1950 | /* The user janked out the cable... */ | ||
1951 | static void usb_pwc_disconnect(struct usb_interface *intf) | ||
1952 | { | ||
1953 | struct pwc_device *pdev; | ||
1954 | int hint; | ||
1955 | |||
1956 | lock_kernel(); | ||
1957 | pdev = usb_get_intfdata (intf); | ||
1958 | usb_set_intfdata (intf, NULL); | ||
1959 | if (pdev == NULL) { | ||
1960 | Err("pwc_disconnect() Called without private pointer.\n"); | ||
1961 | goto disconnect_out; | ||
1962 | } | ||
1963 | if (pdev->udev == NULL) { | ||
1964 | Err("pwc_disconnect() already called for %p\n", pdev); | ||
1965 | goto disconnect_out; | ||
1966 | } | ||
1967 | if (pdev->udev != interface_to_usbdev(intf)) { | ||
1968 | Err("pwc_disconnect() Woops: pointer mismatch udev/pdev.\n"); | ||
1969 | goto disconnect_out; | ||
1970 | } | ||
1971 | #ifdef PWC_MAGIC | ||
1972 | if (pdev->magic != PWC_MAGIC) { | ||
1973 | Err("pwc_disconnect() Magic number failed. Consult your scrolls and try again.\n"); | ||
1974 | goto disconnect_out; | ||
1975 | } | ||
1976 | #endif | ||
1977 | |||
1978 | /* We got unplugged; this is signalled by an EPIPE error code */ | ||
1979 | if (pdev->vopen) { | ||
1980 | Info("Disconnected while webcam is in use!\n"); | ||
1981 | pdev->error_status = EPIPE; | ||
1982 | } | ||
1983 | |||
1984 | /* Alert waiting processes */ | ||
1985 | wake_up_interruptible(&pdev->frameq); | ||
1986 | /* Wait until device is closed */ | ||
1987 | while (pdev->vopen) | ||
1988 | schedule(); | ||
1989 | /* Device is now closed, so we can safely unregister it */ | ||
1990 | Trace(TRACE_PROBE, "Unregistering video device in disconnect().\n"); | ||
1991 | video_unregister_device(pdev->vdev); | ||
1992 | |||
1993 | /* Free memory (don't set pdev to 0 just yet) */ | ||
1994 | kfree(pdev); | ||
1995 | |||
1996 | disconnect_out: | ||
1997 | /* search device_hint[] table if we occupy a slot, by any chance */ | ||
1998 | for (hint = 0; hint < MAX_DEV_HINTS; hint++) | ||
1999 | if (device_hint[hint].pdev == pdev) | ||
2000 | device_hint[hint].pdev = NULL; | ||
2001 | |||
2002 | unlock_kernel(); | ||
2003 | } | ||
2004 | |||
2005 | |||
2006 | /* *grunt* We have to do atoi ourselves :-( */ | ||
2007 | static int pwc_atoi(const char *s) | ||
2008 | { | ||
2009 | int k = 0; | ||
2010 | |||
2011 | k = 0; | ||
2012 | while (*s != '\0' && *s >= '0' && *s <= '9') { | ||
2013 | k = 10 * k + (*s - '0'); | ||
2014 | s++; | ||
2015 | } | ||
2016 | return k; | ||
2017 | } | ||
2018 | |||
2019 | |||
2020 | /* | ||
2021 | * Initialization code & module stuff | ||
2022 | */ | ||
2023 | |||
2024 | static char size[10]; | ||
2025 | static int fps = 0; | ||
2026 | static int fbufs = 0; | ||
2027 | static int mbufs = 0; | ||
2028 | static int trace = -1; | ||
2029 | static int compression = -1; | ||
2030 | static int leds[2] = { -1, -1 }; | ||
2031 | static char *dev_hint[MAX_DEV_HINTS] = { }; | ||
2032 | |||
2033 | module_param_string(size, size, sizeof(size), 0); | ||
2034 | MODULE_PARM_DESC(size, "Initial image size. One of sqcif, qsif, qcif, sif, cif, vga"); | ||
2035 | module_param(fps, int, 0000); | ||
2036 | MODULE_PARM_DESC(fps, "Initial frames per second. Varies with model, useful range 5-30"); | ||
2037 | module_param(fbufs, int, 0000); | ||
2038 | MODULE_PARM_DESC(fbufs, "Number of internal frame buffers to reserve"); | ||
2039 | module_param(mbufs, int, 0000); | ||
2040 | MODULE_PARM_DESC(mbufs, "Number of external (mmap()ed) image buffers"); | ||
2041 | module_param(trace, int, 0000); | ||
2042 | MODULE_PARM_DESC(trace, "For debugging purposes"); | ||
2043 | module_param(power_save, bool, 0000); | ||
2044 | MODULE_PARM_DESC(power_save, "Turn power save feature in camera on or off"); | ||
2045 | module_param(compression, int, 0000); | ||
2046 | MODULE_PARM_DESC(compression, "Preferred compression quality. Range 0 (uncompressed) to 3 (high compression)"); | ||
2047 | module_param_array(leds, int, NULL, 0000); | ||
2048 | MODULE_PARM_DESC(leds, "LED on,off time in milliseconds"); | ||
2049 | module_param_array(dev_hint, charp, NULL, 0000); | ||
2050 | MODULE_PARM_DESC(dev_hint, "Device node hints"); | ||
2051 | |||
2052 | MODULE_DESCRIPTION("Philips & OEM USB webcam driver"); | ||
2053 | MODULE_AUTHOR("Luc Saillard <luc@saillard.org>"); | ||
2054 | MODULE_LICENSE("GPL"); | ||
2055 | |||
2056 | static int __init usb_pwc_init(void) | ||
2057 | { | ||
2058 | int i, sz; | ||
2059 | char *sizenames[PSZ_MAX] = { "sqcif", "qsif", "qcif", "sif", "cif", "vga" }; | ||
2060 | |||
2061 | Info("Philips webcam module version " PWC_VERSION " loaded.\n"); | ||
2062 | Info("Supports Philips PCA645/646, PCVC675/680/690, PCVC720[40]/730/740/750 & PCVC830/840.\n"); | ||
2063 | Info("Also supports the Askey VC010, various Logitech Quickcams, Samsung MPC-C10 and MPC-C30,\n"); | ||
2064 | Info("the Creative WebCam 5 & Pro Ex, SOTEC Afina Eye and Visionite VCS-UC300 and VCS-UM100.\n"); | ||
2065 | |||
2066 | if (fps) { | ||
2067 | if (fps < 4 || fps > 30) { | ||
2068 | Err("Framerate out of bounds (4-30).\n"); | ||
2069 | return -EINVAL; | ||
2070 | } | ||
2071 | default_fps = fps; | ||
2072 | Info("Default framerate set to %d.\n", default_fps); | ||
2073 | } | ||
2074 | |||
2075 | if (size[0]) { | ||
2076 | /* string; try matching with array */ | ||
2077 | for (sz = 0; sz < PSZ_MAX; sz++) { | ||
2078 | if (!strcmp(sizenames[sz], size)) { /* Found! */ | ||
2079 | default_size = sz; | ||
2080 | break; | ||
2081 | } | ||
2082 | } | ||
2083 | if (sz == PSZ_MAX) { | ||
2084 | Err("Size not recognized; try size=[sqcif | qsif | qcif | sif | cif | vga].\n"); | ||
2085 | return -EINVAL; | ||
2086 | } | ||
2087 | Info("Default image size set to %s [%dx%d].\n", sizenames[default_size], pwc_image_sizes[default_size].x, pwc_image_sizes[default_size].y); | ||
2088 | } | ||
2089 | if (mbufs) { | ||
2090 | if (mbufs < 1 || mbufs > MAX_IMAGES) { | ||
2091 | Err("Illegal number of mmap() buffers; use a number between 1 and %d.\n", MAX_IMAGES); | ||
2092 | return -EINVAL; | ||
2093 | } | ||
2094 | default_mbufs = mbufs; | ||
2095 | Info("Number of image buffers set to %d.\n", default_mbufs); | ||
2096 | } | ||
2097 | if (fbufs) { | ||
2098 | if (fbufs < 2 || fbufs > MAX_FRAMES) { | ||
2099 | Err("Illegal number of frame buffers; use a number between 2 and %d.\n", MAX_FRAMES); | ||
2100 | return -EINVAL; | ||
2101 | } | ||
2102 | default_fbufs = fbufs; | ||
2103 | Info("Number of frame buffers set to %d.\n", default_fbufs); | ||
2104 | } | ||
2105 | if (trace >= 0) { | ||
2106 | Info("Trace options: 0x%04x\n", trace); | ||
2107 | pwc_trace = trace; | ||
2108 | } | ||
2109 | if (compression >= 0) { | ||
2110 | if (compression > 3) { | ||
2111 | Err("Invalid compression setting; use a number between 0 (uncompressed) and 3 (high).\n"); | ||
2112 | return -EINVAL; | ||
2113 | } | ||
2114 | pwc_preferred_compression = compression; | ||
2115 | Info("Preferred compression set to %d.\n", pwc_preferred_compression); | ||
2116 | } | ||
2117 | if (power_save) | ||
2118 | Info("Enabling power save on open/close.\n"); | ||
2119 | if (leds[0] >= 0) | ||
2120 | led_on = leds[0]; | ||
2121 | if (leds[1] >= 0) | ||
2122 | led_off = leds[1]; | ||
2123 | |||
2124 | /* Big device node whoopla. Basically, it allows you to assign a | ||
2125 | device node (/dev/videoX) to a camera, based on its type | ||
2126 | & serial number. The format is [type[.serialnumber]:]node. | ||
2127 | |||
2128 | Any camera that isn't matched by these rules gets the next | ||
2129 | available free device node. | ||
2130 | */ | ||
2131 | for (i = 0; i < MAX_DEV_HINTS; i++) { | ||
2132 | char *s, *colon, *dot; | ||
2133 | |||
2134 | /* This loop also initializes the array */ | ||
2135 | device_hint[i].pdev = NULL; | ||
2136 | s = dev_hint[i]; | ||
2137 | if (s != NULL && *s != '\0') { | ||
2138 | device_hint[i].type = -1; /* wildcard */ | ||
2139 | strcpy(device_hint[i].serial_number, "*"); | ||
2140 | |||
2141 | /* parse string: chop at ':' & '/' */ | ||
2142 | colon = dot = s; | ||
2143 | while (*colon != '\0' && *colon != ':') | ||
2144 | colon++; | ||
2145 | while (*dot != '\0' && *dot != '.') | ||
2146 | dot++; | ||
2147 | /* Few sanity checks */ | ||
2148 | if (*dot != '\0' && dot > colon) { | ||
2149 | Err("Malformed camera hint: the colon must be after the dot.\n"); | ||
2150 | return -EINVAL; | ||
2151 | } | ||
2152 | |||
2153 | if (*colon == '\0') { | ||
2154 | /* No colon */ | ||
2155 | if (*dot != '\0') { | ||
2156 | Err("Malformed camera hint: no colon + device node given.\n"); | ||
2157 | return -EINVAL; | ||
2158 | } | ||
2159 | else { | ||
2160 | /* No type or serial number specified, just a number. */ | ||
2161 | device_hint[i].device_node = pwc_atoi(s); | ||
2162 | } | ||
2163 | } | ||
2164 | else { | ||
2165 | /* There's a colon, so we have at least a type and a device node */ | ||
2166 | device_hint[i].type = pwc_atoi(s); | ||
2167 | device_hint[i].device_node = pwc_atoi(colon + 1); | ||
2168 | if (*dot != '\0') { | ||
2169 | /* There's a serial number as well */ | ||
2170 | int k; | ||
2171 | |||
2172 | dot++; | ||
2173 | k = 0; | ||
2174 | while (*dot != ':' && k < 29) { | ||
2175 | device_hint[i].serial_number[k++] = *dot; | ||
2176 | dot++; | ||
2177 | } | ||
2178 | device_hint[i].serial_number[k] = '\0'; | ||
2179 | } | ||
2180 | } | ||
2181 | #if PWC_DEBUG | ||
2182 | Debug("device_hint[%d]:\n", i); | ||
2183 | Debug(" type : %d\n", device_hint[i].type); | ||
2184 | Debug(" serial# : %s\n", device_hint[i].serial_number); | ||
2185 | Debug(" node : %d\n", device_hint[i].device_node); | ||
2186 | #endif | ||
2187 | } | ||
2188 | else | ||
2189 | device_hint[i].type = 0; /* not filled */ | ||
2190 | } /* ..for MAX_DEV_HINTS */ | ||
2191 | |||
2192 | Trace(TRACE_PROBE, "Registering driver at address 0x%p.\n", &pwc_driver); | ||
2193 | return usb_register(&pwc_driver); | ||
2194 | } | ||
2195 | |||
2196 | static void __exit usb_pwc_exit(void) | ||
2197 | { | ||
2198 | Trace(TRACE_MODULE, "Deregistering driver.\n"); | ||
2199 | usb_deregister(&pwc_driver); | ||
2200 | Info("Philips webcam module removed.\n"); | ||
2201 | } | ||
2202 | |||
2203 | module_init(usb_pwc_init); | ||
2204 | module_exit(usb_pwc_exit); | ||
2205 | |||
diff --git a/drivers/media/video/pwc/pwc-ioctl.h b/drivers/media/video/pwc/pwc-ioctl.h new file mode 100644 index 000000000000..5f9cb08bc02e --- /dev/null +++ b/drivers/media/video/pwc/pwc-ioctl.h | |||
@@ -0,0 +1,292 @@ | |||
1 | #ifndef PWC_IOCTL_H | ||
2 | #define PWC_IOCTL_H | ||
3 | |||
4 | /* (C) 2001-2004 Nemosoft Unv. | ||
5 | (C) 2004 Luc Saillard (luc@saillard.org) | ||
6 | |||
7 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
8 | driver and thus may have bugs that are not present in the original version. | ||
9 | Please send bug reports and support requests to <luc@saillard.org>. | ||
10 | The decompression routines have been implemented by reverse-engineering the | ||
11 | Nemosoft binary pwcx module. Caveat emptor. | ||
12 | |||
13 | This program is free software; you can redistribute it and/or modify | ||
14 | it under the terms of the GNU General Public License as published by | ||
15 | the Free Software Foundation; either version 2 of the License, or | ||
16 | (at your option) any later version. | ||
17 | |||
18 | This program is distributed in the hope that it will be useful, | ||
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | GNU General Public License for more details. | ||
22 | |||
23 | You should have received a copy of the GNU General Public License | ||
24 | along with this program; if not, write to the Free Software | ||
25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
26 | */ | ||
27 | |||
28 | /* This is pwc-ioctl.h belonging to PWC 8.12.1 | ||
29 | It contains structures and defines to communicate from user space | ||
30 | directly to the driver. | ||
31 | */ | ||
32 | |||
33 | /* | ||
34 | Changes | ||
35 | 2001/08/03 Alvarado Added ioctl constants to access methods for | ||
36 | changing white balance and red/blue gains | ||
37 | 2002/12/15 G. H. Fernandez-Toribio VIDIOCGREALSIZE | ||
38 | 2003/12/13 Nemosft Unv. Some modifications to make interfacing to | ||
39 | PWCX easier | ||
40 | */ | ||
41 | |||
42 | /* These are private ioctl() commands, specific for the Philips webcams. | ||
43 | They contain functions not found in other webcams, and settings not | ||
44 | specified in the Video4Linux API. | ||
45 | |||
46 | The #define names are built up like follows: | ||
47 | VIDIOC VIDeo IOCtl prefix | ||
48 | PWC Philps WebCam | ||
49 | G optional: Get | ||
50 | S optional: Set | ||
51 | ... the function | ||
52 | */ | ||
53 | |||
54 | |||
55 | /* Enumeration of image sizes */ | ||
56 | #define PSZ_SQCIF 0x00 | ||
57 | #define PSZ_QSIF 0x01 | ||
58 | #define PSZ_QCIF 0x02 | ||
59 | #define PSZ_SIF 0x03 | ||
60 | #define PSZ_CIF 0x04 | ||
61 | #define PSZ_VGA 0x05 | ||
62 | #define PSZ_MAX 6 | ||
63 | |||
64 | |||
65 | /* The frame rate is encoded in the video_window.flags parameter using | ||
66 | the upper 16 bits, since some flags are defined nowadays. The following | ||
67 | defines provide a mask and shift to filter out this value. | ||
68 | |||
69 | In 'Snapshot' mode the camera freezes its automatic exposure and colour | ||
70 | balance controls. | ||
71 | */ | ||
72 | #define PWC_FPS_SHIFT 16 | ||
73 | #define PWC_FPS_MASK 0x00FF0000 | ||
74 | #define PWC_FPS_FRMASK 0x003F0000 | ||
75 | #define PWC_FPS_SNAPSHOT 0x00400000 | ||
76 | |||
77 | |||
78 | /* structure for transferring x & y coordinates */ | ||
79 | struct pwc_coord | ||
80 | { | ||
81 | int x, y; /* guess what */ | ||
82 | int size; /* size, or offset */ | ||
83 | }; | ||
84 | |||
85 | |||
86 | /* Used with VIDIOCPWCPROBE */ | ||
87 | struct pwc_probe | ||
88 | { | ||
89 | char name[32]; | ||
90 | int type; | ||
91 | }; | ||
92 | |||
93 | struct pwc_serial | ||
94 | { | ||
95 | char serial[30]; /* String with serial number. Contains terminating 0 */ | ||
96 | }; | ||
97 | |||
98 | /* pwc_whitebalance.mode values */ | ||
99 | #define PWC_WB_INDOOR 0 | ||
100 | #define PWC_WB_OUTDOOR 1 | ||
101 | #define PWC_WB_FL 2 | ||
102 | #define PWC_WB_MANUAL 3 | ||
103 | #define PWC_WB_AUTO 4 | ||
104 | |||
105 | /* Used with VIDIOCPWC[SG]AWB (Auto White Balance). | ||
106 | Set mode to one of the PWC_WB_* values above. | ||
107 | *red and *blue are the respective gains of these colour components inside | ||
108 | the camera; range 0..65535 | ||
109 | When 'mode' == PWC_WB_MANUAL, 'manual_red' and 'manual_blue' are set or read; | ||
110 | otherwise undefined. | ||
111 | 'read_red' and 'read_blue' are read-only. | ||
112 | */ | ||
113 | struct pwc_whitebalance | ||
114 | { | ||
115 | int mode; | ||
116 | int manual_red, manual_blue; /* R/W */ | ||
117 | int read_red, read_blue; /* R/O */ | ||
118 | }; | ||
119 | |||
120 | /* | ||
121 | 'control_speed' and 'control_delay' are used in automatic whitebalance mode, | ||
122 | and tell the camera how fast it should react to changes in lighting, and | ||
123 | with how much delay. Valid values are 0..65535. | ||
124 | */ | ||
125 | struct pwc_wb_speed | ||
126 | { | ||
127 | int control_speed; | ||
128 | int control_delay; | ||
129 | |||
130 | }; | ||
131 | |||
132 | /* Used with VIDIOCPWC[SG]LED */ | ||
133 | struct pwc_leds | ||
134 | { | ||
135 | int led_on; /* Led on-time; range = 0..25000 */ | ||
136 | int led_off; /* Led off-time; range = 0..25000 */ | ||
137 | }; | ||
138 | |||
139 | /* Image size (used with GREALSIZE) */ | ||
140 | struct pwc_imagesize | ||
141 | { | ||
142 | int width; | ||
143 | int height; | ||
144 | }; | ||
145 | |||
146 | /* Defines and structures for Motorized Pan & Tilt */ | ||
147 | #define PWC_MPT_PAN 0x01 | ||
148 | #define PWC_MPT_TILT 0x02 | ||
149 | #define PWC_MPT_TIMEOUT 0x04 /* for status */ | ||
150 | |||
151 | /* Set angles; when absolute != 0, the angle is absolute and the | ||
152 | driver calculates the relative offset for you. This can only | ||
153 | be used with VIDIOCPWCSANGLE; VIDIOCPWCGANGLE always returns | ||
154 | absolute angles. | ||
155 | */ | ||
156 | struct pwc_mpt_angles | ||
157 | { | ||
158 | int absolute; /* write-only */ | ||
159 | int pan; /* degrees * 100 */ | ||
160 | int tilt; /* degress * 100 */ | ||
161 | }; | ||
162 | |||
163 | /* Range of angles of the camera, both horizontally and vertically. | ||
164 | */ | ||
165 | struct pwc_mpt_range | ||
166 | { | ||
167 | int pan_min, pan_max; /* degrees * 100 */ | ||
168 | int tilt_min, tilt_max; | ||
169 | }; | ||
170 | |||
171 | struct pwc_mpt_status | ||
172 | { | ||
173 | int status; | ||
174 | int time_pan; | ||
175 | int time_tilt; | ||
176 | }; | ||
177 | |||
178 | |||
179 | /* This is used for out-of-kernel decompression. With it, you can get | ||
180 | all the necessary information to initialize and use the decompressor | ||
181 | routines in standalone applications. | ||
182 | */ | ||
183 | struct pwc_video_command | ||
184 | { | ||
185 | int type; /* camera type (645, 675, 730, etc.) */ | ||
186 | int release; /* release number */ | ||
187 | |||
188 | int size; /* one of PSZ_* */ | ||
189 | int alternate; | ||
190 | int command_len; /* length of USB video command */ | ||
191 | unsigned char command_buf[13]; /* Actual USB video command */ | ||
192 | int bandlength; /* >0 = compressed */ | ||
193 | int frame_size; /* Size of one (un)compressed frame */ | ||
194 | }; | ||
195 | |||
196 | /* Flags for PWCX subroutines. Not all modules honour all flags. */ | ||
197 | #define PWCX_FLAG_PLANAR 0x0001 | ||
198 | #define PWCX_FLAG_BAYER 0x0008 | ||
199 | |||
200 | |||
201 | /* IOCTL definitions */ | ||
202 | |||
203 | /* Restore user settings */ | ||
204 | #define VIDIOCPWCRUSER _IO('v', 192) | ||
205 | /* Save user settings */ | ||
206 | #define VIDIOCPWCSUSER _IO('v', 193) | ||
207 | /* Restore factory settings */ | ||
208 | #define VIDIOCPWCFACTORY _IO('v', 194) | ||
209 | |||
210 | /* You can manipulate the compression factor. A compression preference of 0 | ||
211 | means use uncompressed modes when available; 1 is low compression, 2 is | ||
212 | medium and 3 is high compression preferred. Of course, the higher the | ||
213 | compression, the lower the bandwidth used but more chance of artefacts | ||
214 | in the image. The driver automatically chooses a higher compression when | ||
215 | the preferred mode is not available. | ||
216 | */ | ||
217 | /* Set preferred compression quality (0 = uncompressed, 3 = highest compression) */ | ||
218 | #define VIDIOCPWCSCQUAL _IOW('v', 195, int) | ||
219 | /* Get preferred compression quality */ | ||
220 | #define VIDIOCPWCGCQUAL _IOR('v', 195, int) | ||
221 | |||
222 | |||
223 | /* Retrieve serial number of camera */ | ||
224 | #define VIDIOCPWCGSERIAL _IOR('v', 198, struct pwc_serial) | ||
225 | |||
226 | /* This is a probe function; since so many devices are supported, it | ||
227 | becomes difficult to include all the names in programs that want to | ||
228 | check for the enhanced Philips stuff. So in stead, try this PROBE; | ||
229 | it returns a structure with the original name, and the corresponding | ||
230 | Philips type. | ||
231 | To use, fill the structure with zeroes, call PROBE and if that succeeds, | ||
232 | compare the name with that returned from VIDIOCGCAP; they should be the | ||
233 | same. If so, you can be assured it is a Philips (OEM) cam and the type | ||
234 | is valid. | ||
235 | */ | ||
236 | #define VIDIOCPWCPROBE _IOR('v', 199, struct pwc_probe) | ||
237 | |||
238 | /* Set AGC (Automatic Gain Control); int < 0 = auto, 0..65535 = fixed */ | ||
239 | #define VIDIOCPWCSAGC _IOW('v', 200, int) | ||
240 | /* Get AGC; int < 0 = auto; >= 0 = fixed, range 0..65535 */ | ||
241 | #define VIDIOCPWCGAGC _IOR('v', 200, int) | ||
242 | /* Set shutter speed; int < 0 = auto; >= 0 = fixed, range 0..65535 */ | ||
243 | #define VIDIOCPWCSSHUTTER _IOW('v', 201, int) | ||
244 | |||
245 | /* Color compensation (Auto White Balance) */ | ||
246 | #define VIDIOCPWCSAWB _IOW('v', 202, struct pwc_whitebalance) | ||
247 | #define VIDIOCPWCGAWB _IOR('v', 202, struct pwc_whitebalance) | ||
248 | |||
249 | /* Auto WB speed */ | ||
250 | #define VIDIOCPWCSAWBSPEED _IOW('v', 203, struct pwc_wb_speed) | ||
251 | #define VIDIOCPWCGAWBSPEED _IOR('v', 203, struct pwc_wb_speed) | ||
252 | |||
253 | /* LEDs on/off/blink; int range 0..65535 */ | ||
254 | #define VIDIOCPWCSLED _IOW('v', 205, struct pwc_leds) | ||
255 | #define VIDIOCPWCGLED _IOR('v', 205, struct pwc_leds) | ||
256 | |||
257 | /* Contour (sharpness); int < 0 = auto, 0..65536 = fixed */ | ||
258 | #define VIDIOCPWCSCONTOUR _IOW('v', 206, int) | ||
259 | #define VIDIOCPWCGCONTOUR _IOR('v', 206, int) | ||
260 | |||
261 | /* Backlight compensation; 0 = off, otherwise on */ | ||
262 | #define VIDIOCPWCSBACKLIGHT _IOW('v', 207, int) | ||
263 | #define VIDIOCPWCGBACKLIGHT _IOR('v', 207, int) | ||
264 | |||
265 | /* Flickerless mode; = 0 off, otherwise on */ | ||
266 | #define VIDIOCPWCSFLICKER _IOW('v', 208, int) | ||
267 | #define VIDIOCPWCGFLICKER _IOR('v', 208, int) | ||
268 | |||
269 | /* Dynamic noise reduction; 0 off, 3 = high noise reduction */ | ||
270 | #define VIDIOCPWCSDYNNOISE _IOW('v', 209, int) | ||
271 | #define VIDIOCPWCGDYNNOISE _IOR('v', 209, int) | ||
272 | |||
273 | /* Real image size as used by the camera; tells you whether or not there's a gray border around the image */ | ||
274 | #define VIDIOCPWCGREALSIZE _IOR('v', 210, struct pwc_imagesize) | ||
275 | |||
276 | /* Motorized pan & tilt functions */ | ||
277 | #define VIDIOCPWCMPTRESET _IOW('v', 211, int) | ||
278 | #define VIDIOCPWCMPTGRANGE _IOR('v', 211, struct pwc_mpt_range) | ||
279 | #define VIDIOCPWCMPTSANGLE _IOW('v', 212, struct pwc_mpt_angles) | ||
280 | #define VIDIOCPWCMPTGANGLE _IOR('v', 212, struct pwc_mpt_angles) | ||
281 | #define VIDIOCPWCMPTSTATUS _IOR('v', 213, struct pwc_mpt_status) | ||
282 | |||
283 | /* Get the USB set-video command; needed for initializing libpwcx */ | ||
284 | #define VIDIOCPWCGVIDCMD _IOR('v', 215, struct pwc_video_command) | ||
285 | struct pwc_table_init_buffer { | ||
286 | int len; | ||
287 | char *buffer; | ||
288 | |||
289 | }; | ||
290 | #define VIDIOCPWCGVIDTABLE _IOR('v', 216, struct pwc_table_init_buffer) | ||
291 | |||
292 | #endif | ||
diff --git a/drivers/media/video/pwc/pwc-kiara.c b/drivers/media/video/pwc/pwc-kiara.c new file mode 100644 index 000000000000..c498c68bace1 --- /dev/null +++ b/drivers/media/video/pwc/pwc-kiara.c | |||
@@ -0,0 +1,318 @@ | |||
1 | /* Linux driver for Philips webcam | ||
2 | (C) 2004 Luc Saillard (luc@saillard.org) | ||
3 | |||
4 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
5 | driver and thus may have bugs that are not present in the original version. | ||
6 | Please send bug reports and support requests to <luc@saillard.org>. | ||
7 | The decompression routines have been implemented by reverse-engineering the | ||
8 | Nemosoft binary pwcx module. Caveat emptor. | ||
9 | |||
10 | This program is free software; you can redistribute it and/or modify | ||
11 | it under the terms of the GNU General Public License as published by | ||
12 | the Free Software Foundation; either version 2 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License | ||
21 | along with this program; if not, write to the Free Software | ||
22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | ||
24 | |||
25 | |||
26 | /* This tables contains entries for the 730/740/750 (Kiara) camera, with | ||
27 | 4 different qualities (no compression, low, medium, high). | ||
28 | It lists the bandwidth requirements for said mode by its alternate interface | ||
29 | number. An alternate of 0 means that the mode is unavailable. | ||
30 | |||
31 | There are 6 * 4 * 4 entries: | ||
32 | 6 different resolutions subqcif, qsif, qcif, sif, cif, vga | ||
33 | 6 framerates: 5, 10, 15, 20, 25, 30 | ||
34 | 4 compression modi: none, low, medium, high | ||
35 | |||
36 | When an uncompressed mode is not available, the next available compressed mode | ||
37 | will be chosen (unless the decompressor is absent). Sometimes there are only | ||
38 | 1 or 2 compressed modes available; in that case entries are duplicated. | ||
39 | */ | ||
40 | |||
41 | |||
42 | #include "pwc-kiara.h" | ||
43 | #include "pwc-uncompress.h" | ||
44 | |||
45 | const struct Kiara_table_entry Kiara_table[PSZ_MAX][6][4] = | ||
46 | { | ||
47 | /* SQCIF */ | ||
48 | { | ||
49 | /* 5 fps */ | ||
50 | { | ||
51 | {0, }, | ||
52 | {0, }, | ||
53 | {0, }, | ||
54 | {0, }, | ||
55 | }, | ||
56 | /* 10 fps */ | ||
57 | { | ||
58 | {0, }, | ||
59 | {0, }, | ||
60 | {0, }, | ||
61 | {0, }, | ||
62 | }, | ||
63 | /* 15 fps */ | ||
64 | { | ||
65 | {0, }, | ||
66 | {0, }, | ||
67 | {0, }, | ||
68 | {0, }, | ||
69 | }, | ||
70 | /* 20 fps */ | ||
71 | { | ||
72 | {0, }, | ||
73 | {0, }, | ||
74 | {0, }, | ||
75 | {0, }, | ||
76 | }, | ||
77 | /* 25 fps */ | ||
78 | { | ||
79 | {0, }, | ||
80 | {0, }, | ||
81 | {0, }, | ||
82 | {0, }, | ||
83 | }, | ||
84 | /* 30 fps */ | ||
85 | { | ||
86 | {0, }, | ||
87 | {0, }, | ||
88 | {0, }, | ||
89 | {0, }, | ||
90 | }, | ||
91 | }, | ||
92 | /* QSIF */ | ||
93 | { | ||
94 | /* 5 fps */ | ||
95 | { | ||
96 | {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}}, | ||
97 | {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}}, | ||
98 | {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}}, | ||
99 | {1, 146, 0, {0x1D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0x00, 0x80}}, | ||
100 | }, | ||
101 | /* 10 fps */ | ||
102 | { | ||
103 | {2, 291, 0, {0x1C, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x23, 0x01, 0x80}}, | ||
104 | {1, 192, 630, {0x14, 0xF4, 0x30, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xC0, 0x00, 0x80}}, | ||
105 | {1, 192, 630, {0x14, 0xF4, 0x30, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xC0, 0x00, 0x80}}, | ||
106 | {1, 192, 630, {0x14, 0xF4, 0x30, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xC0, 0x00, 0x80}}, | ||
107 | }, | ||
108 | /* 15 fps */ | ||
109 | { | ||
110 | {3, 437, 0, {0x1B, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xB5, 0x01, 0x80}}, | ||
111 | {2, 292, 640, {0x13, 0xF4, 0x30, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x20, 0x24, 0x01, 0x80}}, | ||
112 | {2, 292, 640, {0x13, 0xF4, 0x30, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x20, 0x24, 0x01, 0x80}}, | ||
113 | {1, 192, 420, {0x13, 0xF4, 0x30, 0x0D, 0x1B, 0x0C, 0x53, 0x1E, 0x18, 0xC0, 0x00, 0x80}}, | ||
114 | }, | ||
115 | /* 20 fps */ | ||
116 | { | ||
117 | {4, 589, 0, {0x1A, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x4D, 0x02, 0x80}}, | ||
118 | {3, 448, 730, {0x12, 0xF4, 0x30, 0x16, 0xC9, 0x16, 0x01, 0x0E, 0x18, 0xC0, 0x01, 0x80}}, | ||
119 | {2, 292, 476, {0x12, 0xF4, 0x30, 0x0E, 0xD8, 0x0E, 0x10, 0x19, 0x18, 0x24, 0x01, 0x80}}, | ||
120 | {1, 192, 312, {0x12, 0xF4, 0x50, 0x09, 0xB3, 0x08, 0xEB, 0x1E, 0x18, 0xC0, 0x00, 0x80}}, | ||
121 | }, | ||
122 | /* 25 fps */ | ||
123 | { | ||
124 | {5, 703, 0, {0x19, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xBF, 0x02, 0x80}}, | ||
125 | {3, 447, 610, {0x11, 0xF4, 0x30, 0x13, 0x0B, 0x12, 0x43, 0x14, 0x28, 0xBF, 0x01, 0x80}}, | ||
126 | {2, 292, 398, {0x11, 0xF4, 0x50, 0x0C, 0x6C, 0x0B, 0xA4, 0x1E, 0x28, 0x24, 0x01, 0x80}}, | ||
127 | {1, 193, 262, {0x11, 0xF4, 0x50, 0x08, 0x23, 0x07, 0x5B, 0x1E, 0x28, 0xC1, 0x00, 0x80}}, | ||
128 | }, | ||
129 | /* 30 fps */ | ||
130 | { | ||
131 | {8, 874, 0, {0x18, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x6A, 0x03, 0x80}}, | ||
132 | {5, 704, 730, {0x10, 0xF4, 0x30, 0x16, 0xC9, 0x16, 0x01, 0x0E, 0x28, 0xC0, 0x02, 0x80}}, | ||
133 | {3, 448, 492, {0x10, 0xF4, 0x30, 0x0F, 0x5D, 0x0E, 0x95, 0x15, 0x28, 0xC0, 0x01, 0x80}}, | ||
134 | {2, 292, 320, {0x10, 0xF4, 0x50, 0x09, 0xFB, 0x09, 0x33, 0x1E, 0x28, 0x24, 0x01, 0x80}}, | ||
135 | }, | ||
136 | }, | ||
137 | /* QCIF */ | ||
138 | { | ||
139 | /* 5 fps */ | ||
140 | { | ||
141 | {0, }, | ||
142 | {0, }, | ||
143 | {0, }, | ||
144 | {0, }, | ||
145 | }, | ||
146 | /* 10 fps */ | ||
147 | { | ||
148 | {0, }, | ||
149 | {0, }, | ||
150 | {0, }, | ||
151 | {0, }, | ||
152 | }, | ||
153 | /* 15 fps */ | ||
154 | { | ||
155 | {0, }, | ||
156 | {0, }, | ||
157 | {0, }, | ||
158 | {0, }, | ||
159 | }, | ||
160 | /* 20 fps */ | ||
161 | { | ||
162 | {0, }, | ||
163 | {0, }, | ||
164 | {0, }, | ||
165 | {0, }, | ||
166 | }, | ||
167 | /* 25 fps */ | ||
168 | { | ||
169 | {0, }, | ||
170 | {0, }, | ||
171 | {0, }, | ||
172 | {0, }, | ||
173 | }, | ||
174 | /* 30 fps */ | ||
175 | { | ||
176 | {0, }, | ||
177 | {0, }, | ||
178 | {0, }, | ||
179 | {0, }, | ||
180 | }, | ||
181 | }, | ||
182 | /* SIF */ | ||
183 | { | ||
184 | /* 5 fps */ | ||
185 | { | ||
186 | {4, 582, 0, {0x0D, 0xF4, 0x30, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x46, 0x02, 0x80}}, | ||
187 | {3, 387, 1276, {0x05, 0xF4, 0x30, 0x27, 0xD8, 0x26, 0x48, 0x03, 0x10, 0x83, 0x01, 0x80}}, | ||
188 | {2, 291, 960, {0x05, 0xF4, 0x30, 0x1D, 0xF2, 0x1C, 0x62, 0x04, 0x10, 0x23, 0x01, 0x80}}, | ||
189 | {1, 191, 630, {0x05, 0xF4, 0x50, 0x13, 0xA9, 0x12, 0x19, 0x05, 0x18, 0xBF, 0x00, 0x80}}, | ||
190 | }, | ||
191 | /* 10 fps */ | ||
192 | { | ||
193 | {0, }, | ||
194 | {6, 775, 1278, {0x04, 0xF4, 0x30, 0x27, 0xE8, 0x26, 0x58, 0x05, 0x30, 0x07, 0x03, 0x80}}, | ||
195 | {3, 447, 736, {0x04, 0xF4, 0x30, 0x16, 0xFB, 0x15, 0x6B, 0x05, 0x28, 0xBF, 0x01, 0x80}}, | ||
196 | {2, 292, 480, {0x04, 0xF4, 0x70, 0x0E, 0xF9, 0x0D, 0x69, 0x09, 0x28, 0x24, 0x01, 0x80}}, | ||
197 | }, | ||
198 | /* 15 fps */ | ||
199 | { | ||
200 | {0, }, | ||
201 | {9, 955, 1050, {0x03, 0xF4, 0x30, 0x20, 0xCF, 0x1F, 0x3F, 0x06, 0x48, 0xBB, 0x03, 0x80}}, | ||
202 | {4, 592, 650, {0x03, 0xF4, 0x30, 0x14, 0x44, 0x12, 0xB4, 0x08, 0x30, 0x50, 0x02, 0x80}}, | ||
203 | {3, 448, 492, {0x03, 0xF4, 0x50, 0x0F, 0x52, 0x0D, 0xC2, 0x09, 0x38, 0xC0, 0x01, 0x80}}, | ||
204 | }, | ||
205 | /* 20 fps */ | ||
206 | { | ||
207 | {0, }, | ||
208 | {9, 958, 782, {0x02, 0xF4, 0x30, 0x18, 0x6A, 0x16, 0xDA, 0x0B, 0x58, 0xBE, 0x03, 0x80}}, | ||
209 | {5, 703, 574, {0x02, 0xF4, 0x50, 0x11, 0xE7, 0x10, 0x57, 0x0B, 0x40, 0xBF, 0x02, 0x80}}, | ||
210 | {3, 446, 364, {0x02, 0xF4, 0x90, 0x0B, 0x5C, 0x09, 0xCC, 0x0E, 0x38, 0xBE, 0x01, 0x80}}, | ||
211 | }, | ||
212 | /* 25 fps */ | ||
213 | { | ||
214 | {0, }, | ||
215 | {9, 958, 654, {0x01, 0xF4, 0x30, 0x14, 0x66, 0x12, 0xD6, 0x0B, 0x50, 0xBE, 0x03, 0x80}}, | ||
216 | {6, 776, 530, {0x01, 0xF4, 0x50, 0x10, 0x8C, 0x0E, 0xFC, 0x0C, 0x48, 0x08, 0x03, 0x80}}, | ||
217 | {4, 592, 404, {0x01, 0xF4, 0x70, 0x0C, 0x96, 0x0B, 0x06, 0x0B, 0x48, 0x50, 0x02, 0x80}}, | ||
218 | }, | ||
219 | /* 30 fps */ | ||
220 | { | ||
221 | {0, }, | ||
222 | {9, 957, 526, {0x00, 0xF4, 0x50, 0x10, 0x68, 0x0E, 0xD8, 0x0D, 0x58, 0xBD, 0x03, 0x80}}, | ||
223 | {6, 775, 426, {0x00, 0xF4, 0x70, 0x0D, 0x48, 0x0B, 0xB8, 0x0F, 0x50, 0x07, 0x03, 0x80}}, | ||
224 | {4, 590, 324, {0x00, 0x7A, 0x88, 0x0A, 0x1C, 0x08, 0xB4, 0x0E, 0x50, 0x4E, 0x02, 0x80}}, | ||
225 | }, | ||
226 | }, | ||
227 | /* CIF */ | ||
228 | { | ||
229 | /* 5 fps */ | ||
230 | { | ||
231 | {0, }, | ||
232 | {0, }, | ||
233 | {0, }, | ||
234 | {0, }, | ||
235 | }, | ||
236 | /* 10 fps */ | ||
237 | { | ||
238 | {0, }, | ||
239 | {0, }, | ||
240 | {0, }, | ||
241 | {0, }, | ||
242 | }, | ||
243 | /* 15 fps */ | ||
244 | { | ||
245 | {0, }, | ||
246 | {0, }, | ||
247 | {0, }, | ||
248 | {0, }, | ||
249 | }, | ||
250 | /* 20 fps */ | ||
251 | { | ||
252 | {0, }, | ||
253 | {0, }, | ||
254 | {0, }, | ||
255 | {0, }, | ||
256 | }, | ||
257 | /* 25 fps */ | ||
258 | { | ||
259 | {0, }, | ||
260 | {0, }, | ||
261 | {0, }, | ||
262 | {0, }, | ||
263 | }, | ||
264 | /* 30 fps */ | ||
265 | { | ||
266 | {0, }, | ||
267 | {0, }, | ||
268 | {0, }, | ||
269 | {0, }, | ||
270 | }, | ||
271 | }, | ||
272 | /* VGA */ | ||
273 | { | ||
274 | /* 5 fps */ | ||
275 | { | ||
276 | {0, }, | ||
277 | {6, 773, 1272, {0x25, 0xF4, 0x30, 0x27, 0xB6, 0x24, 0x96, 0x02, 0x30, 0x05, 0x03, 0x80}}, | ||
278 | {4, 592, 976, {0x25, 0xF4, 0x50, 0x1E, 0x78, 0x1B, 0x58, 0x03, 0x30, 0x50, 0x02, 0x80}}, | ||
279 | {3, 448, 738, {0x25, 0xF4, 0x90, 0x17, 0x0C, 0x13, 0xEC, 0x04, 0x30, 0xC0, 0x01, 0x80}}, | ||
280 | }, | ||
281 | /* 10 fps */ | ||
282 | { | ||
283 | {0, }, | ||
284 | {9, 956, 788, {0x24, 0xF4, 0x70, 0x18, 0x9C, 0x15, 0x7C, 0x03, 0x48, 0xBC, 0x03, 0x80}}, | ||
285 | {6, 776, 640, {0x24, 0xF4, 0xB0, 0x13, 0xFC, 0x11, 0x2C, 0x04, 0x48, 0x08, 0x03, 0x80}}, | ||
286 | {4, 592, 488, {0x24, 0x7A, 0xE8, 0x0F, 0x3C, 0x0C, 0x6C, 0x06, 0x48, 0x50, 0x02, 0x80}}, | ||
287 | }, | ||
288 | /* 15 fps */ | ||
289 | { | ||
290 | {0, }, | ||
291 | {9, 957, 526, {0x23, 0x7A, 0xE8, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x03, 0x80}}, | ||
292 | {9, 957, 526, {0x23, 0x7A, 0xE8, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x03, 0x80}}, | ||
293 | {8, 895, 492, {0x23, 0x7A, 0xE8, 0x0F, 0x5D, 0x0C, 0x8D, 0x06, 0x58, 0x7F, 0x03, 0x80}}, | ||
294 | }, | ||
295 | /* 20 fps */ | ||
296 | { | ||
297 | {0, }, | ||
298 | {0, }, | ||
299 | {0, }, | ||
300 | {0, }, | ||
301 | }, | ||
302 | /* 25 fps */ | ||
303 | { | ||
304 | {0, }, | ||
305 | {0, }, | ||
306 | {0, }, | ||
307 | {0, }, | ||
308 | }, | ||
309 | /* 30 fps */ | ||
310 | { | ||
311 | {0, }, | ||
312 | {0, }, | ||
313 | {0, }, | ||
314 | {0, }, | ||
315 | }, | ||
316 | }, | ||
317 | }; | ||
318 | |||
diff --git a/drivers/media/video/pwc/pwc-kiara.h b/drivers/media/video/pwc/pwc-kiara.h new file mode 100644 index 000000000000..12929abbb1f0 --- /dev/null +++ b/drivers/media/video/pwc/pwc-kiara.h | |||
@@ -0,0 +1,45 @@ | |||
1 | /* Linux driver for Philips webcam | ||
2 | (C) 2004 Luc Saillard (luc@saillard.org) | ||
3 | |||
4 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
5 | driver and thus may have bugs that are not present in the original version. | ||
6 | Please send bug reports and support requests to <luc@saillard.org>. | ||
7 | The decompression routines have been implemented by reverse-engineering the | ||
8 | Nemosoft binary pwcx module. Caveat emptor. | ||
9 | |||
10 | This program is free software; you can redistribute it and/or modify | ||
11 | it under the terms of the GNU General Public License as published by | ||
12 | the Free Software Foundation; either version 2 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License | ||
21 | along with this program; if not, write to the Free Software | ||
22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | ||
24 | |||
25 | /* Entries for the Kiara (730/740/750) camera */ | ||
26 | |||
27 | #ifndef PWC_KIARA_H | ||
28 | #define PWC_KIARA_H | ||
29 | |||
30 | #include "pwc-ioctl.h" | ||
31 | |||
32 | struct Kiara_table_entry | ||
33 | { | ||
34 | char alternate; /* USB alternate interface */ | ||
35 | unsigned short packetsize; /* Normal packet size */ | ||
36 | unsigned short bandlength; /* Bandlength when decompressing */ | ||
37 | unsigned char mode[12]; /* precomputed mode settings for cam */ | ||
38 | }; | ||
39 | |||
40 | const extern struct Kiara_table_entry Kiara_table[PSZ_MAX][6][4]; | ||
41 | const extern unsigned int KiaraRomTable[8][2][16][8]; | ||
42 | |||
43 | #endif | ||
44 | |||
45 | |||
diff --git a/drivers/media/video/pwc/pwc-misc.c b/drivers/media/video/pwc/pwc-misc.c new file mode 100644 index 000000000000..b7a4bd3524c7 --- /dev/null +++ b/drivers/media/video/pwc/pwc-misc.c | |||
@@ -0,0 +1,140 @@ | |||
1 | /* Linux driver for Philips webcam | ||
2 | Various miscellaneous functions and tables. | ||
3 | (C) 1999-2003 Nemosoft Unv. | ||
4 | (C) 2004 Luc Saillard (luc@saillard.org) | ||
5 | |||
6 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
7 | driver and thus may have bugs that are not present in the original version. | ||
8 | Please send bug reports and support requests to <luc@saillard.org>. | ||
9 | The decompression routines have been implemented by reverse-engineering the | ||
10 | Nemosoft binary pwcx module. Caveat emptor. | ||
11 | |||
12 | This program is free software; you can redistribute it and/or modify | ||
13 | it under the terms of the GNU General Public License as published by | ||
14 | the Free Software Foundation; either version 2 of the License, or | ||
15 | (at your option) any later version. | ||
16 | |||
17 | This program is distributed in the hope that it will be useful, | ||
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | GNU General Public License for more details. | ||
21 | |||
22 | You should have received a copy of the GNU General Public License | ||
23 | along with this program; if not, write to the Free Software | ||
24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
25 | */ | ||
26 | |||
27 | #include <linux/slab.h> | ||
28 | |||
29 | #include "pwc.h" | ||
30 | |||
31 | struct pwc_coord pwc_image_sizes[PSZ_MAX] = | ||
32 | { | ||
33 | { 128, 96, 0 }, | ||
34 | { 160, 120, 0 }, | ||
35 | { 176, 144, 0 }, | ||
36 | { 320, 240, 0 }, | ||
37 | { 352, 288, 0 }, | ||
38 | { 640, 480, 0 }, | ||
39 | }; | ||
40 | |||
41 | /* x,y -> PSZ_ */ | ||
42 | int pwc_decode_size(struct pwc_device *pdev, int width, int height) | ||
43 | { | ||
44 | int i, find; | ||
45 | |||
46 | /* Make sure we don't go beyond our max size. | ||
47 | NB: we have different limits for RAW and normal modes. In case | ||
48 | you don't have the decompressor loaded or use RAW mode, | ||
49 | the maximum viewable size is smaller. | ||
50 | */ | ||
51 | if (pdev->vpalette == VIDEO_PALETTE_RAW) | ||
52 | { | ||
53 | if (width > pdev->abs_max.x || height > pdev->abs_max.y) | ||
54 | { | ||
55 | Debug("VIDEO_PALETTE_RAW: going beyond abs_max.\n"); | ||
56 | return -1; | ||
57 | } | ||
58 | } | ||
59 | else | ||
60 | { | ||
61 | if (width > pdev->view_max.x || height > pdev->view_max.y) | ||
62 | { | ||
63 | Debug("VIDEO_PALETTE_ not RAW: going beyond view_max.\n"); | ||
64 | return -1; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | /* Find the largest size supported by the camera that fits into the | ||
69 | requested size. | ||
70 | */ | ||
71 | find = -1; | ||
72 | for (i = 0; i < PSZ_MAX; i++) { | ||
73 | if (pdev->image_mask & (1 << i)) { | ||
74 | if (pwc_image_sizes[i].x <= width && pwc_image_sizes[i].y <= height) | ||
75 | find = i; | ||
76 | } | ||
77 | } | ||
78 | return find; | ||
79 | } | ||
80 | |||
81 | /* initialize variables depending on type and decompressor*/ | ||
82 | void pwc_construct(struct pwc_device *pdev) | ||
83 | { | ||
84 | switch(pdev->type) { | ||
85 | case 645: | ||
86 | case 646: | ||
87 | pdev->view_min.x = 128; | ||
88 | pdev->view_min.y = 96; | ||
89 | pdev->view_max.x = 352; | ||
90 | pdev->view_max.y = 288; | ||
91 | pdev->abs_max.x = 352; | ||
92 | pdev->abs_max.y = 288; | ||
93 | pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QCIF | 1 << PSZ_CIF; | ||
94 | pdev->vcinterface = 2; | ||
95 | pdev->vendpoint = 4; | ||
96 | pdev->frame_header_size = 0; | ||
97 | pdev->frame_trailer_size = 0; | ||
98 | break; | ||
99 | case 675: | ||
100 | case 680: | ||
101 | case 690: | ||
102 | pdev->view_min.x = 128; | ||
103 | pdev->view_min.y = 96; | ||
104 | /* Anthill bug #38: PWC always reports max size, even without PWCX */ | ||
105 | pdev->view_max.x = 640; | ||
106 | pdev->view_max.y = 480; | ||
107 | pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QSIF | 1 << PSZ_QCIF | 1 << PSZ_SIF | 1 << PSZ_CIF | 1 << PSZ_VGA; | ||
108 | pdev->abs_max.x = 640; | ||
109 | pdev->abs_max.y = 480; | ||
110 | pdev->vcinterface = 3; | ||
111 | pdev->vendpoint = 4; | ||
112 | pdev->frame_header_size = 0; | ||
113 | pdev->frame_trailer_size = 0; | ||
114 | break; | ||
115 | case 720: | ||
116 | case 730: | ||
117 | case 740: | ||
118 | case 750: | ||
119 | pdev->view_min.x = 160; | ||
120 | pdev->view_min.y = 120; | ||
121 | pdev->view_max.x = 640; | ||
122 | pdev->view_max.y = 480; | ||
123 | pdev->image_mask = 1 << PSZ_QSIF | 1 << PSZ_SIF | 1 << PSZ_VGA; | ||
124 | pdev->abs_max.x = 640; | ||
125 | pdev->abs_max.y = 480; | ||
126 | pdev->vcinterface = 3; | ||
127 | pdev->vendpoint = 5; | ||
128 | pdev->frame_header_size = TOUCAM_HEADER_SIZE; | ||
129 | pdev->frame_trailer_size = TOUCAM_TRAILER_SIZE; | ||
130 | break; | ||
131 | } | ||
132 | Debug("type = %d\n",pdev->type); | ||
133 | pdev->vpalette = VIDEO_PALETTE_YUV420P; /* default */ | ||
134 | pdev->view_min.size = pdev->view_min.x * pdev->view_min.y; | ||
135 | pdev->view_max.size = pdev->view_max.x * pdev->view_max.y; | ||
136 | /* length of image, in YUV format; always allocate enough memory. */ | ||
137 | pdev->len_per_image = (pdev->abs_max.x * pdev->abs_max.y * 3) / 2; | ||
138 | } | ||
139 | |||
140 | |||
diff --git a/drivers/media/video/pwc/pwc-nala.h b/drivers/media/video/pwc/pwc-nala.h new file mode 100644 index 000000000000..e6c5cb69d03b --- /dev/null +++ b/drivers/media/video/pwc/pwc-nala.h | |||
@@ -0,0 +1,66 @@ | |||
1 | /* SQCIF */ | ||
2 | { | ||
3 | {0, 0, {0x04, 0x01, 0x03}}, | ||
4 | {8, 0, {0x05, 0x01, 0x03}}, | ||
5 | {7, 0, {0x08, 0x01, 0x03}}, | ||
6 | {7, 0, {0x0A, 0x01, 0x03}}, | ||
7 | {6, 0, {0x0C, 0x01, 0x03}}, | ||
8 | {5, 0, {0x0F, 0x01, 0x03}}, | ||
9 | {4, 0, {0x14, 0x01, 0x03}}, | ||
10 | {3, 0, {0x18, 0x01, 0x03}}, | ||
11 | }, | ||
12 | /* QSIF */ | ||
13 | { | ||
14 | {0}, | ||
15 | {0}, | ||
16 | {0}, | ||
17 | {0}, | ||
18 | {0}, | ||
19 | {0}, | ||
20 | {0}, | ||
21 | {0}, | ||
22 | }, | ||
23 | /* QCIF */ | ||
24 | { | ||
25 | {0, 0, {0x04, 0x01, 0x02}}, | ||
26 | {8, 0, {0x05, 0x01, 0x02}}, | ||
27 | {7, 0, {0x08, 0x01, 0x02}}, | ||
28 | {6, 0, {0x0A, 0x01, 0x02}}, | ||
29 | {5, 0, {0x0C, 0x01, 0x02}}, | ||
30 | {4, 0, {0x0F, 0x01, 0x02}}, | ||
31 | {1, 0, {0x14, 0x01, 0x02}}, | ||
32 | {1, 0, {0x18, 0x01, 0x02}}, | ||
33 | }, | ||
34 | /* SIF */ | ||
35 | { | ||
36 | {0}, | ||
37 | {0}, | ||
38 | {0}, | ||
39 | {0}, | ||
40 | {0}, | ||
41 | {0}, | ||
42 | {0}, | ||
43 | {0}, | ||
44 | }, | ||
45 | /* CIF */ | ||
46 | { | ||
47 | {4, 0, {0x04, 0x01, 0x01}}, | ||
48 | {7, 1, {0x05, 0x03, 0x01}}, | ||
49 | {6, 1, {0x08, 0x03, 0x01}}, | ||
50 | {4, 1, {0x0A, 0x03, 0x01}}, | ||
51 | {3, 1, {0x0C, 0x03, 0x01}}, | ||
52 | {2, 1, {0x0F, 0x03, 0x01}}, | ||
53 | {0}, | ||
54 | {0}, | ||
55 | }, | ||
56 | /* VGA */ | ||
57 | { | ||
58 | {0}, | ||
59 | {0}, | ||
60 | {0}, | ||
61 | {0}, | ||
62 | {0}, | ||
63 | {0}, | ||
64 | {0}, | ||
65 | {0}, | ||
66 | }, | ||
diff --git a/drivers/media/video/pwc/pwc-timon.c b/drivers/media/video/pwc/pwc-timon.c new file mode 100644 index 000000000000..dee967173d6c --- /dev/null +++ b/drivers/media/video/pwc/pwc-timon.c | |||
@@ -0,0 +1,316 @@ | |||
1 | /* Linux driver for Philips webcam | ||
2 | (C) 2004 Luc Saillard (luc@saillard.org) | ||
3 | |||
4 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
5 | driver and thus may have bugs that are not present in the original version. | ||
6 | Please send bug reports and support requests to <luc@saillard.org>. | ||
7 | The decompression routines have been implemented by reverse-engineering the | ||
8 | Nemosoft binary pwcx module. Caveat emptor. | ||
9 | |||
10 | This program is free software; you can redistribute it and/or modify | ||
11 | it under the terms of the GNU General Public License as published by | ||
12 | the Free Software Foundation; either version 2 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License | ||
21 | along with this program; if not, write to the Free Software | ||
22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | ||
24 | |||
25 | |||
26 | /* This tables contains entries for the 675/680/690 (Timon) camera, with | ||
27 | 4 different qualities (no compression, low, medium, high). | ||
28 | It lists the bandwidth requirements for said mode by its alternate interface | ||
29 | number. An alternate of 0 means that the mode is unavailable. | ||
30 | |||
31 | There are 6 * 4 * 4 entries: | ||
32 | 6 different resolutions subqcif, qsif, qcif, sif, cif, vga | ||
33 | 6 framerates: 5, 10, 15, 20, 25, 30 | ||
34 | 4 compression modi: none, low, medium, high | ||
35 | |||
36 | When an uncompressed mode is not available, the next available compressed mode | ||
37 | will be chosen (unless the decompressor is absent). Sometimes there are only | ||
38 | 1 or 2 compressed modes available; in that case entries are duplicated. | ||
39 | */ | ||
40 | |||
41 | #include "pwc-timon.h" | ||
42 | |||
43 | const struct Timon_table_entry Timon_table[PSZ_MAX][6][4] = | ||
44 | { | ||
45 | /* SQCIF */ | ||
46 | { | ||
47 | /* 5 fps */ | ||
48 | { | ||
49 | {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}}, | ||
50 | {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}}, | ||
51 | {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}}, | ||
52 | {1, 140, 0, {0x05, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x8C, 0xFC, 0x80, 0x02}}, | ||
53 | }, | ||
54 | /* 10 fps */ | ||
55 | { | ||
56 | {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}}, | ||
57 | {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}}, | ||
58 | {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}}, | ||
59 | {2, 280, 0, {0x04, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x18, 0xA9, 0x80, 0x02}}, | ||
60 | }, | ||
61 | /* 15 fps */ | ||
62 | { | ||
63 | {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}}, | ||
64 | {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}}, | ||
65 | {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}}, | ||
66 | {3, 410, 0, {0x03, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x9A, 0x71, 0x80, 0x02}}, | ||
67 | }, | ||
68 | /* 20 fps */ | ||
69 | { | ||
70 | {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}}, | ||
71 | {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}}, | ||
72 | {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}}, | ||
73 | {4, 559, 0, {0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x2F, 0x56, 0x80, 0x02}}, | ||
74 | }, | ||
75 | /* 25 fps */ | ||
76 | { | ||
77 | {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}}, | ||
78 | {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}}, | ||
79 | {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}}, | ||
80 | {5, 659, 0, {0x01, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x93, 0x46, 0x80, 0x02}}, | ||
81 | }, | ||
82 | /* 30 fps */ | ||
83 | { | ||
84 | {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}}, | ||
85 | {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}}, | ||
86 | {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}}, | ||
87 | {7, 838, 0, {0x00, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x46, 0x3B, 0x80, 0x02}}, | ||
88 | }, | ||
89 | }, | ||
90 | /* QSIF */ | ||
91 | { | ||
92 | /* 5 fps */ | ||
93 | { | ||
94 | {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}}, | ||
95 | {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}}, | ||
96 | {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}}, | ||
97 | {1, 146, 0, {0x2D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x92, 0xFC, 0xC0, 0x02}}, | ||
98 | }, | ||
99 | /* 10 fps */ | ||
100 | { | ||
101 | {2, 291, 0, {0x2C, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x23, 0xA1, 0xC0, 0x02}}, | ||
102 | {1, 191, 630, {0x2C, 0xF4, 0x05, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xBF, 0xF4, 0xC0, 0x02}}, | ||
103 | {1, 191, 630, {0x2C, 0xF4, 0x05, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xBF, 0xF4, 0xC0, 0x02}}, | ||
104 | {1, 191, 630, {0x2C, 0xF4, 0x05, 0x13, 0xA9, 0x12, 0xE1, 0x17, 0x08, 0xBF, 0xF4, 0xC0, 0x02}}, | ||
105 | }, | ||
106 | /* 15 fps */ | ||
107 | { | ||
108 | {3, 437, 0, {0x2B, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xB5, 0x6D, 0xC0, 0x02}}, | ||
109 | {2, 291, 640, {0x2B, 0xF4, 0x05, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x08, 0x23, 0xA1, 0xC0, 0x02}}, | ||
110 | {2, 291, 640, {0x2B, 0xF4, 0x05, 0x13, 0xF7, 0x13, 0x2F, 0x13, 0x08, 0x23, 0xA1, 0xC0, 0x02}}, | ||
111 | {1, 191, 420, {0x2B, 0xF4, 0x0D, 0x0D, 0x1B, 0x0C, 0x53, 0x1E, 0x08, 0xBF, 0xF4, 0xC0, 0x02}}, | ||
112 | }, | ||
113 | /* 20 fps */ | ||
114 | { | ||
115 | {4, 588, 0, {0x2A, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x4C, 0x52, 0xC0, 0x02}}, | ||
116 | {3, 447, 730, {0x2A, 0xF4, 0x05, 0x16, 0xC9, 0x16, 0x01, 0x0E, 0x18, 0xBF, 0x69, 0xC0, 0x02}}, | ||
117 | {2, 292, 476, {0x2A, 0xF4, 0x0D, 0x0E, 0xD8, 0x0E, 0x10, 0x19, 0x18, 0x24, 0xA1, 0xC0, 0x02}}, | ||
118 | {1, 192, 312, {0x2A, 0xF4, 0x1D, 0x09, 0xB3, 0x08, 0xEB, 0x1E, 0x18, 0xC0, 0xF4, 0xC0, 0x02}}, | ||
119 | }, | ||
120 | /* 25 fps */ | ||
121 | { | ||
122 | {5, 703, 0, {0x29, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0xBF, 0x42, 0xC0, 0x02}}, | ||
123 | {3, 447, 610, {0x29, 0xF4, 0x05, 0x13, 0x0B, 0x12, 0x43, 0x14, 0x18, 0xBF, 0x69, 0xC0, 0x02}}, | ||
124 | {2, 292, 398, {0x29, 0xF4, 0x0D, 0x0C, 0x6C, 0x0B, 0xA4, 0x1E, 0x18, 0x24, 0xA1, 0xC0, 0x02}}, | ||
125 | {1, 192, 262, {0x29, 0xF4, 0x25, 0x08, 0x23, 0x07, 0x5B, 0x1E, 0x18, 0xC0, 0xF4, 0xC0, 0x02}}, | ||
126 | }, | ||
127 | /* 30 fps */ | ||
128 | { | ||
129 | {8, 873, 0, {0x28, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x69, 0x37, 0xC0, 0x02}}, | ||
130 | {5, 704, 774, {0x28, 0xF4, 0x05, 0x18, 0x21, 0x17, 0x59, 0x0F, 0x18, 0xC0, 0x42, 0xC0, 0x02}}, | ||
131 | {3, 448, 492, {0x28, 0xF4, 0x05, 0x0F, 0x5D, 0x0E, 0x95, 0x15, 0x18, 0xC0, 0x69, 0xC0, 0x02}}, | ||
132 | {2, 291, 320, {0x28, 0xF4, 0x1D, 0x09, 0xFB, 0x09, 0x33, 0x1E, 0x18, 0x23, 0xA1, 0xC0, 0x02}}, | ||
133 | }, | ||
134 | }, | ||
135 | /* QCIF */ | ||
136 | { | ||
137 | /* 5 fps */ | ||
138 | { | ||
139 | {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}}, | ||
140 | {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}}, | ||
141 | {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}}, | ||
142 | {1, 193, 0, {0x0D, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xC1, 0xF4, 0xC0, 0x02}}, | ||
143 | }, | ||
144 | /* 10 fps */ | ||
145 | { | ||
146 | {3, 385, 0, {0x0C, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x81, 0x79, 0xC0, 0x02}}, | ||
147 | {2, 291, 800, {0x0C, 0xF4, 0x05, 0x18, 0xF4, 0x18, 0x18, 0x11, 0x08, 0x23, 0xA1, 0xC0, 0x02}}, | ||
148 | {2, 291, 800, {0x0C, 0xF4, 0x05, 0x18, 0xF4, 0x18, 0x18, 0x11, 0x08, 0x23, 0xA1, 0xC0, 0x02}}, | ||
149 | {1, 194, 532, {0x0C, 0xF4, 0x05, 0x10, 0x9A, 0x0F, 0xBE, 0x1B, 0x08, 0xC2, 0xF0, 0xC0, 0x02}}, | ||
150 | }, | ||
151 | /* 15 fps */ | ||
152 | { | ||
153 | {4, 577, 0, {0x0B, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x41, 0x52, 0xC0, 0x02}}, | ||
154 | {3, 447, 818, {0x0B, 0xF4, 0x05, 0x19, 0x89, 0x18, 0xAD, 0x0F, 0x10, 0xBF, 0x69, 0xC0, 0x02}}, | ||
155 | {2, 292, 534, {0x0B, 0xF4, 0x05, 0x10, 0xA3, 0x0F, 0xC7, 0x19, 0x10, 0x24, 0xA1, 0xC0, 0x02}}, | ||
156 | {1, 195, 356, {0x0B, 0xF4, 0x15, 0x0B, 0x11, 0x0A, 0x35, 0x1E, 0x10, 0xC3, 0xF0, 0xC0, 0x02}}, | ||
157 | }, | ||
158 | /* 20 fps */ | ||
159 | { | ||
160 | {6, 776, 0, {0x0A, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x08, 0x3F, 0xC0, 0x02}}, | ||
161 | {4, 591, 804, {0x0A, 0xF4, 0x05, 0x19, 0x1E, 0x18, 0x42, 0x0F, 0x18, 0x4F, 0x4E, 0xC0, 0x02}}, | ||
162 | {3, 447, 608, {0x0A, 0xF4, 0x05, 0x12, 0xFD, 0x12, 0x21, 0x15, 0x18, 0xBF, 0x69, 0xC0, 0x02}}, | ||
163 | {2, 291, 396, {0x0A, 0xF4, 0x15, 0x0C, 0x5E, 0x0B, 0x82, 0x1E, 0x18, 0x23, 0xA1, 0xC0, 0x02}}, | ||
164 | }, | ||
165 | /* 25 fps */ | ||
166 | { | ||
167 | {9, 928, 0, {0x09, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0xA0, 0x33, 0xC0, 0x02}}, | ||
168 | {5, 703, 800, {0x09, 0xF4, 0x05, 0x18, 0xF4, 0x18, 0x18, 0x10, 0x18, 0xBF, 0x42, 0xC0, 0x02}}, | ||
169 | {3, 447, 508, {0x09, 0xF4, 0x0D, 0x0F, 0xD2, 0x0E, 0xF6, 0x1B, 0x18, 0xBF, 0x69, 0xC0, 0x02}}, | ||
170 | {2, 292, 332, {0x09, 0xF4, 0x1D, 0x0A, 0x5A, 0x09, 0x7E, 0x1E, 0x18, 0x24, 0xA1, 0xC0, 0x02}}, | ||
171 | }, | ||
172 | /* 30 fps */ | ||
173 | { | ||
174 | {0, }, | ||
175 | {9, 956, 876, {0x08, 0xF4, 0x05, 0x1B, 0x58, 0x1A, 0x7C, 0x0E, 0x20, 0xBC, 0x33, 0x10, 0x02}}, | ||
176 | {4, 592, 542, {0x08, 0xF4, 0x05, 0x10, 0xE4, 0x10, 0x08, 0x17, 0x20, 0x50, 0x4E, 0x10, 0x02}}, | ||
177 | {2, 291, 266, {0x08, 0xF4, 0x25, 0x08, 0x48, 0x07, 0x6C, 0x1E, 0x20, 0x23, 0xA1, 0x10, 0x02}}, | ||
178 | }, | ||
179 | }, | ||
180 | /* SIF */ | ||
181 | { | ||
182 | /* 5 fps */ | ||
183 | { | ||
184 | {4, 582, 0, {0x35, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x46, 0x52, 0x60, 0x02}}, | ||
185 | {3, 387, 1276, {0x35, 0xF4, 0x05, 0x27, 0xD8, 0x26, 0x48, 0x03, 0x10, 0x83, 0x79, 0x60, 0x02}}, | ||
186 | {2, 291, 960, {0x35, 0xF4, 0x0D, 0x1D, 0xF2, 0x1C, 0x62, 0x04, 0x10, 0x23, 0xA1, 0x60, 0x02}}, | ||
187 | {1, 191, 630, {0x35, 0xF4, 0x1D, 0x13, 0xA9, 0x12, 0x19, 0x05, 0x08, 0xBF, 0xF4, 0x60, 0x02}}, | ||
188 | }, | ||
189 | /* 10 fps */ | ||
190 | { | ||
191 | {0, }, | ||
192 | {6, 775, 1278, {0x34, 0xF4, 0x05, 0x27, 0xE8, 0x26, 0x58, 0x05, 0x30, 0x07, 0x3F, 0x10, 0x02}}, | ||
193 | {3, 447, 736, {0x34, 0xF4, 0x15, 0x16, 0xFB, 0x15, 0x6B, 0x05, 0x18, 0xBF, 0x69, 0x10, 0x02}}, | ||
194 | {2, 291, 480, {0x34, 0xF4, 0x2D, 0x0E, 0xF9, 0x0D, 0x69, 0x09, 0x18, 0x23, 0xA1, 0x10, 0x02}}, | ||
195 | }, | ||
196 | /* 15 fps */ | ||
197 | { | ||
198 | {0, }, | ||
199 | {9, 955, 1050, {0x33, 0xF4, 0x05, 0x20, 0xCF, 0x1F, 0x3F, 0x06, 0x48, 0xBB, 0x33, 0x10, 0x02}}, | ||
200 | {4, 591, 650, {0x33, 0xF4, 0x15, 0x14, 0x44, 0x12, 0xB4, 0x08, 0x30, 0x4F, 0x4E, 0x10, 0x02}}, | ||
201 | {3, 448, 492, {0x33, 0xF4, 0x25, 0x0F, 0x52, 0x0D, 0xC2, 0x09, 0x28, 0xC0, 0x69, 0x10, 0x02}}, | ||
202 | }, | ||
203 | /* 20 fps */ | ||
204 | { | ||
205 | {0, }, | ||
206 | {9, 958, 782, {0x32, 0xF4, 0x0D, 0x18, 0x6A, 0x16, 0xDA, 0x0B, 0x58, 0xBE, 0x33, 0xD0, 0x02}}, | ||
207 | {5, 703, 574, {0x32, 0xF4, 0x1D, 0x11, 0xE7, 0x10, 0x57, 0x0B, 0x40, 0xBF, 0x42, 0xD0, 0x02}}, | ||
208 | {3, 446, 364, {0x32, 0xF4, 0x3D, 0x0B, 0x5C, 0x09, 0xCC, 0x0E, 0x30, 0xBE, 0x69, 0xD0, 0x02}}, | ||
209 | }, | ||
210 | /* 25 fps */ | ||
211 | { | ||
212 | {0, }, | ||
213 | {9, 958, 654, {0x31, 0xF4, 0x15, 0x14, 0x66, 0x12, 0xD6, 0x0B, 0x50, 0xBE, 0x33, 0x90, 0x02}}, | ||
214 | {6, 776, 530, {0x31, 0xF4, 0x25, 0x10, 0x8C, 0x0E, 0xFC, 0x0C, 0x48, 0x08, 0x3F, 0x90, 0x02}}, | ||
215 | {4, 592, 404, {0x31, 0xF4, 0x35, 0x0C, 0x96, 0x0B, 0x06, 0x0B, 0x38, 0x50, 0x4E, 0x90, 0x02}}, | ||
216 | }, | ||
217 | /* 30 fps */ | ||
218 | { | ||
219 | {0, }, | ||
220 | {9, 957, 526, {0x30, 0xF4, 0x25, 0x10, 0x68, 0x0E, 0xD8, 0x0D, 0x58, 0xBD, 0x33, 0x60, 0x02}}, | ||
221 | {6, 775, 426, {0x30, 0xF4, 0x35, 0x0D, 0x48, 0x0B, 0xB8, 0x0F, 0x50, 0x07, 0x3F, 0x60, 0x02}}, | ||
222 | {4, 590, 324, {0x30, 0x7A, 0x4B, 0x0A, 0x1C, 0x08, 0xB4, 0x0E, 0x40, 0x4E, 0x52, 0x60, 0x02}}, | ||
223 | }, | ||
224 | }, | ||
225 | /* CIF */ | ||
226 | { | ||
227 | /* 5 fps */ | ||
228 | { | ||
229 | {6, 771, 0, {0x15, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x3F, 0x80, 0x02}}, | ||
230 | {4, 465, 1278, {0x15, 0xF4, 0x05, 0x27, 0xEE, 0x26, 0x36, 0x03, 0x18, 0xD1, 0x65, 0x80, 0x02}}, | ||
231 | {2, 291, 800, {0x15, 0xF4, 0x15, 0x18, 0xF4, 0x17, 0x3C, 0x05, 0x18, 0x23, 0xA1, 0x80, 0x02}}, | ||
232 | {1, 193, 528, {0x15, 0xF4, 0x2D, 0x10, 0x7E, 0x0E, 0xC6, 0x0A, 0x18, 0xC1, 0xF4, 0x80, 0x02}}, | ||
233 | }, | ||
234 | /* 10 fps */ | ||
235 | { | ||
236 | {0, }, | ||
237 | {9, 932, 1278, {0x14, 0xF4, 0x05, 0x27, 0xEE, 0x26, 0x36, 0x04, 0x30, 0xA4, 0x33, 0x10, 0x02}}, | ||
238 | {4, 591, 812, {0x14, 0xF4, 0x15, 0x19, 0x56, 0x17, 0x9E, 0x06, 0x28, 0x4F, 0x4E, 0x10, 0x02}}, | ||
239 | {2, 291, 400, {0x14, 0xF4, 0x3D, 0x0C, 0x7A, 0x0A, 0xC2, 0x0E, 0x28, 0x23, 0xA1, 0x10, 0x02}}, | ||
240 | }, | ||
241 | /* 15 fps */ | ||
242 | { | ||
243 | {0, }, | ||
244 | {9, 956, 876, {0x13, 0xF4, 0x0D, 0x1B, 0x58, 0x19, 0xA0, 0x05, 0x38, 0xBC, 0x33, 0x60, 0x02}}, | ||
245 | {5, 703, 644, {0x13, 0xF4, 0x1D, 0x14, 0x1C, 0x12, 0x64, 0x08, 0x38, 0xBF, 0x42, 0x60, 0x02}}, | ||
246 | {3, 448, 410, {0x13, 0xF4, 0x3D, 0x0C, 0xC4, 0x0B, 0x0C, 0x0E, 0x38, 0xC0, 0x69, 0x60, 0x02}}, | ||
247 | }, | ||
248 | /* 20 fps */ | ||
249 | { | ||
250 | {0, }, | ||
251 | {9, 956, 650, {0x12, 0xF4, 0x1D, 0x14, 0x4A, 0x12, 0x92, 0x09, 0x48, 0xBC, 0x33, 0x10, 0x03}}, | ||
252 | {6, 776, 528, {0x12, 0xF4, 0x2D, 0x10, 0x7E, 0x0E, 0xC6, 0x0A, 0x40, 0x08, 0x3F, 0x10, 0x03}}, | ||
253 | {4, 591, 402, {0x12, 0xF4, 0x3D, 0x0C, 0x8F, 0x0A, 0xD7, 0x0E, 0x40, 0x4F, 0x4E, 0x10, 0x03}}, | ||
254 | }, | ||
255 | /* 25 fps */ | ||
256 | { | ||
257 | {0, }, | ||
258 | {9, 956, 544, {0x11, 0xF4, 0x25, 0x10, 0xF4, 0x0F, 0x3C, 0x0A, 0x48, 0xBC, 0x33, 0xC0, 0x02}}, | ||
259 | {7, 840, 478, {0x11, 0xF4, 0x2D, 0x0E, 0xEB, 0x0D, 0x33, 0x0B, 0x48, 0x48, 0x3B, 0xC0, 0x02}}, | ||
260 | {5, 703, 400, {0x11, 0xF4, 0x3D, 0x0C, 0x7A, 0x0A, 0xC2, 0x0E, 0x48, 0xBF, 0x42, 0xC0, 0x02}}, | ||
261 | }, | ||
262 | /* 30 fps */ | ||
263 | { | ||
264 | {0, }, | ||
265 | {9, 956, 438, {0x10, 0xF4, 0x35, 0x0D, 0xAC, 0x0B, 0xF4, 0x0D, 0x50, 0xBC, 0x33, 0x10, 0x02}}, | ||
266 | {7, 838, 384, {0x10, 0xF4, 0x45, 0x0B, 0xFD, 0x0A, 0x45, 0x0F, 0x50, 0x46, 0x3B, 0x10, 0x02}}, | ||
267 | {6, 773, 354, {0x10, 0x7A, 0x4B, 0x0B, 0x0C, 0x09, 0x80, 0x10, 0x50, 0x05, 0x3F, 0x10, 0x02}}, | ||
268 | }, | ||
269 | }, | ||
270 | /* VGA */ | ||
271 | { | ||
272 | /* 5 fps */ | ||
273 | { | ||
274 | {0, }, | ||
275 | {6, 773, 1272, {0x1D, 0xF4, 0x15, 0x27, 0xB6, 0x24, 0x96, 0x02, 0x30, 0x05, 0x3F, 0x10, 0x02}}, | ||
276 | {4, 592, 976, {0x1D, 0xF4, 0x25, 0x1E, 0x78, 0x1B, 0x58, 0x03, 0x30, 0x50, 0x4E, 0x10, 0x02}}, | ||
277 | {3, 448, 738, {0x1D, 0xF4, 0x3D, 0x17, 0x0C, 0x13, 0xEC, 0x04, 0x30, 0xC0, 0x69, 0x10, 0x02}}, | ||
278 | }, | ||
279 | /* 10 fps */ | ||
280 | { | ||
281 | {0, }, | ||
282 | {9, 956, 788, {0x1C, 0xF4, 0x35, 0x18, 0x9C, 0x15, 0x7C, 0x03, 0x48, 0xBC, 0x33, 0x10, 0x02}}, | ||
283 | {6, 776, 640, {0x1C, 0x7A, 0x53, 0x13, 0xFC, 0x11, 0x2C, 0x04, 0x48, 0x08, 0x3F, 0x10, 0x02}}, | ||
284 | {4, 592, 488, {0x1C, 0x7A, 0x6B, 0x0F, 0x3C, 0x0C, 0x6C, 0x06, 0x48, 0x50, 0x4E, 0x10, 0x02}}, | ||
285 | }, | ||
286 | /* 15 fps */ | ||
287 | { | ||
288 | {0, }, | ||
289 | {9, 957, 526, {0x1B, 0x7A, 0x63, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x33, 0x80, 0x02}}, | ||
290 | {9, 957, 526, {0x1B, 0x7A, 0x63, 0x10, 0x68, 0x0D, 0x98, 0x06, 0x58, 0xBD, 0x33, 0x80, 0x02}}, | ||
291 | {8, 895, 492, {0x1B, 0x7A, 0x6B, 0x0F, 0x5D, 0x0C, 0x8D, 0x06, 0x58, 0x7F, 0x37, 0x80, 0x02}}, | ||
292 | }, | ||
293 | /* 20 fps */ | ||
294 | { | ||
295 | {0, }, | ||
296 | {0, }, | ||
297 | {0, }, | ||
298 | {0, }, | ||
299 | }, | ||
300 | /* 25 fps */ | ||
301 | { | ||
302 | {0, }, | ||
303 | {0, }, | ||
304 | {0, }, | ||
305 | {0, }, | ||
306 | }, | ||
307 | /* 30 fps */ | ||
308 | { | ||
309 | {0, }, | ||
310 | {0, }, | ||
311 | {0, }, | ||
312 | {0, }, | ||
313 | }, | ||
314 | }, | ||
315 | }; | ||
316 | |||
diff --git a/drivers/media/video/pwc/pwc-timon.h b/drivers/media/video/pwc/pwc-timon.h new file mode 100644 index 000000000000..a86b3782a081 --- /dev/null +++ b/drivers/media/video/pwc/pwc-timon.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /* Linux driver for Philips webcam | ||
2 | (C) 2004 Luc Saillard (luc@saillard.org) | ||
3 | |||
4 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
5 | driver and thus may have bugs that are not present in the original version. | ||
6 | Please send bug reports and support requests to <luc@saillard.org>. | ||
7 | The decompression routines have been implemented by reverse-engineering the | ||
8 | Nemosoft binary pwcx module. Caveat emptor. | ||
9 | |||
10 | This program is free software; you can redistribute it and/or modify | ||
11 | it under the terms of the GNU General Public License as published by | ||
12 | the Free Software Foundation; either version 2 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License | ||
21 | along with this program; if not, write to the Free Software | ||
22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | ||
24 | |||
25 | |||
26 | |||
27 | /* This tables contains entries for the 675/680/690 (Timon) camera, with | ||
28 | 4 different qualities (no compression, low, medium, high). | ||
29 | It lists the bandwidth requirements for said mode by its alternate interface | ||
30 | number. An alternate of 0 means that the mode is unavailable. | ||
31 | |||
32 | There are 6 * 4 * 4 entries: | ||
33 | 6 different resolutions subqcif, qsif, qcif, sif, cif, vga | ||
34 | 6 framerates: 5, 10, 15, 20, 25, 30 | ||
35 | 4 compression modi: none, low, medium, high | ||
36 | |||
37 | When an uncompressed mode is not available, the next available compressed mode | ||
38 | will be chosen (unless the decompressor is absent). Sometimes there are only | ||
39 | 1 or 2 compressed modes available; in that case entries are duplicated. | ||
40 | */ | ||
41 | |||
42 | #ifndef PWC_TIMON_H | ||
43 | #define PWC_TIMON_H | ||
44 | |||
45 | #include "pwc-ioctl.h" | ||
46 | |||
47 | struct Timon_table_entry | ||
48 | { | ||
49 | char alternate; /* USB alternate interface */ | ||
50 | unsigned short packetsize; /* Normal packet size */ | ||
51 | unsigned short bandlength; /* Bandlength when decompressing */ | ||
52 | unsigned char mode[13]; /* precomputed mode settings for cam */ | ||
53 | }; | ||
54 | |||
55 | const extern struct Timon_table_entry Timon_table[PSZ_MAX][6][4]; | ||
56 | const extern unsigned int TimonRomTable [16][2][16][8]; | ||
57 | |||
58 | |||
59 | #endif | ||
60 | |||
61 | |||
diff --git a/drivers/media/video/pwc/pwc-uncompress.c b/drivers/media/video/pwc/pwc-uncompress.c new file mode 100644 index 000000000000..ef4204eab6c4 --- /dev/null +++ b/drivers/media/video/pwc/pwc-uncompress.c | |||
@@ -0,0 +1,146 @@ | |||
1 | /* Linux driver for Philips webcam | ||
2 | Decompression frontend. | ||
3 | (C) 1999-2003 Nemosoft Unv. | ||
4 | (C) 2004 Luc Saillard (luc@saillard.org) | ||
5 | |||
6 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
7 | driver and thus may have bugs that are not present in the original version. | ||
8 | Please send bug reports and support requests to <luc@saillard.org>. | ||
9 | The decompression routines have been implemented by reverse-engineering the | ||
10 | Nemosoft binary pwcx module. Caveat emptor. | ||
11 | |||
12 | This program is free software; you can redistribute it and/or modify | ||
13 | it under the terms of the GNU General Public License as published by | ||
14 | the Free Software Foundation; either version 2 of the License, or | ||
15 | (at your option) any later version. | ||
16 | |||
17 | This program is distributed in the hope that it will be useful, | ||
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | GNU General Public License for more details. | ||
21 | |||
22 | You should have received a copy of the GNU General Public License | ||
23 | along with this program; if not, write to the Free Software | ||
24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
25 | */ | ||
26 | |||
27 | #include <asm/current.h> | ||
28 | #include <asm/types.h> | ||
29 | |||
30 | #include "pwc.h" | ||
31 | #include "pwc-uncompress.h" | ||
32 | |||
33 | int pwc_decompress(struct pwc_device *pdev) | ||
34 | { | ||
35 | struct pwc_frame_buf *fbuf; | ||
36 | int n, line, col, stride; | ||
37 | void *yuv, *image; | ||
38 | u16 *src; | ||
39 | u16 *dsty, *dstu, *dstv; | ||
40 | |||
41 | if (pdev == NULL) | ||
42 | return -EFAULT; | ||
43 | #if defined(__KERNEL__) && defined(PWC_MAGIC) | ||
44 | if (pdev->magic != PWC_MAGIC) { | ||
45 | Err("pwc_decompress(): magic failed.\n"); | ||
46 | return -EFAULT; | ||
47 | } | ||
48 | #endif | ||
49 | |||
50 | fbuf = pdev->read_frame; | ||
51 | if (fbuf == NULL) | ||
52 | return -EFAULT; | ||
53 | image = pdev->image_ptr[pdev->fill_image]; | ||
54 | if (!image) | ||
55 | return -EFAULT; | ||
56 | |||
57 | yuv = fbuf->data + pdev->frame_header_size; /* Skip header */ | ||
58 | |||
59 | /* Raw format; that's easy... */ | ||
60 | if (pdev->vpalette == VIDEO_PALETTE_RAW) | ||
61 | { | ||
62 | memcpy(image, yuv, pdev->frame_size); | ||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | if (pdev->vbandlength == 0) { | ||
67 | /* Uncompressed mode. We copy the data into the output buffer, | ||
68 | using the viewport size (which may be larger than the image | ||
69 | size). Unfortunately we have to do a bit of byte stuffing | ||
70 | to get the desired output format/size. | ||
71 | */ | ||
72 | /* | ||
73 | * We do some byte shuffling here to go from the | ||
74 | * native format to YUV420P. | ||
75 | */ | ||
76 | src = (u16 *)yuv; | ||
77 | n = pdev->view.x * pdev->view.y; | ||
78 | |||
79 | /* offset in Y plane */ | ||
80 | stride = pdev->view.x * pdev->offset.y + pdev->offset.x; | ||
81 | dsty = (u16 *)(image + stride); | ||
82 | |||
83 | /* offsets in U/V planes */ | ||
84 | stride = pdev->view.x * pdev->offset.y / 4 + pdev->offset.x / 2; | ||
85 | dstu = (u16 *)(image + n + stride); | ||
86 | dstv = (u16 *)(image + n + n / 4 + stride); | ||
87 | |||
88 | /* increment after each line */ | ||
89 | stride = (pdev->view.x - pdev->image.x) / 2; /* u16 is 2 bytes */ | ||
90 | |||
91 | for (line = 0; line < pdev->image.y; line++) { | ||
92 | for (col = 0; col < pdev->image.x; col += 4) { | ||
93 | *dsty++ = *src++; | ||
94 | *dsty++ = *src++; | ||
95 | if (line & 1) | ||
96 | *dstv++ = *src++; | ||
97 | else | ||
98 | *dstu++ = *src++; | ||
99 | } | ||
100 | dsty += stride; | ||
101 | if (line & 1) | ||
102 | dstv += (stride >> 1); | ||
103 | else | ||
104 | dstu += (stride >> 1); | ||
105 | } | ||
106 | } | ||
107 | else { | ||
108 | /* Compressed; the decompressor routines will write the data | ||
109 | in planar format immediately. | ||
110 | */ | ||
111 | int flags; | ||
112 | |||
113 | flags = PWCX_FLAG_PLANAR; | ||
114 | if (pdev->vsize == PSZ_VGA && pdev->vframes == 5 && pdev->vsnapshot) | ||
115 | { | ||
116 | printk(KERN_ERR "pwc: Mode Bayer is not supported for now\n"); | ||
117 | flags |= PWCX_FLAG_BAYER; | ||
118 | return -ENXIO; /* No such device or address: missing decompressor */ | ||
119 | } | ||
120 | |||
121 | #if 0 | ||
122 | switch (pdev->type) | ||
123 | { | ||
124 | case 675: | ||
125 | case 680: | ||
126 | case 690: | ||
127 | case 720: | ||
128 | case 730: | ||
129 | case 740: | ||
130 | case 750: | ||
131 | pwc_dec23_decompress(&pdev->image, &pdev->view, | ||
132 | &pdev->offset, yuv, image, flags, | ||
133 | pdev->decompress_data, pdev->vbandlength); | ||
134 | break; | ||
135 | case 645: | ||
136 | case 646: | ||
137 | /* TODO & FIXME */ | ||
138 | return -ENXIO; /* Missing decompressor */ | ||
139 | break; | ||
140 | } | ||
141 | #endif | ||
142 | } | ||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | |||
diff --git a/drivers/media/video/pwc/pwc-uncompress.h b/drivers/media/video/pwc/pwc-uncompress.h new file mode 100644 index 000000000000..d3b9250e4ed3 --- /dev/null +++ b/drivers/media/video/pwc/pwc-uncompress.h | |||
@@ -0,0 +1,41 @@ | |||
1 | /* (C) 1999-2003 Nemosoft Unv. | ||
2 | (C) 2004 Luc Saillard (luc@saillard.org) | ||
3 | |||
4 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
5 | driver and thus may have bugs that are not present in the original version. | ||
6 | Please send bug reports and support requests to <luc@saillard.org>. | ||
7 | The decompression routines have been implemented by reverse-engineering the | ||
8 | Nemosoft binary pwcx module. Caveat emptor. | ||
9 | |||
10 | This program is free software; you can redistribute it and/or modify | ||
11 | it under the terms of the GNU General Public License as published by | ||
12 | the Free Software Foundation; either version 2 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License | ||
21 | along with this program; if not, write to the Free Software | ||
22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | ||
24 | |||
25 | /* This file is the bridge between the kernel module and the plugin; it | ||
26 | describes the structures and datatypes used in both modules. Any | ||
27 | significant change should be reflected by increasing the | ||
28 | pwc_decompressor_version major number. | ||
29 | */ | ||
30 | #ifndef PWC_UNCOMPRESS_H | ||
31 | #define PWC_UNCOMPRESS_H | ||
32 | |||
33 | #include <linux/config.h> | ||
34 | |||
35 | #include "pwc-ioctl.h" | ||
36 | |||
37 | /* from pwc-dec.h */ | ||
38 | #define PWCX_FLAG_PLANAR 0x0001 | ||
39 | /* */ | ||
40 | |||
41 | #endif | ||
diff --git a/drivers/media/video/pwc/pwc.h b/drivers/media/video/pwc/pwc.h new file mode 100644 index 000000000000..6dd76bb3dff1 --- /dev/null +++ b/drivers/media/video/pwc/pwc.h | |||
@@ -0,0 +1,272 @@ | |||
1 | /* (C) 1999-2003 Nemosoft Unv. | ||
2 | (C) 2004 Luc Saillard (luc@saillard.org) | ||
3 | |||
4 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx | ||
5 | driver and thus may have bugs that are not present in the original version. | ||
6 | Please send bug reports and support requests to <luc@saillard.org>. | ||
7 | The decompression routines have been implemented by reverse-engineering the | ||
8 | Nemosoft binary pwcx module. Caveat emptor. | ||
9 | |||
10 | This program is free software; you can redistribute it and/or modify | ||
11 | it under the terms of the GNU General Public License as published by | ||
12 | the Free Software Foundation; either version 2 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License | ||
21 | along with this program; if not, write to the Free Software | ||
22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | ||
24 | |||
25 | #ifndef PWC_H | ||
26 | #define PWC_H | ||
27 | |||
28 | #include <linux/config.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/usb.h> | ||
31 | #include <linux/spinlock.h> | ||
32 | #include <linux/videodev.h> | ||
33 | #include <linux/wait.h> | ||
34 | #include <linux/smp_lock.h> | ||
35 | #include <asm/semaphore.h> | ||
36 | #include <asm/errno.h> | ||
37 | |||
38 | #include "pwc-uncompress.h" | ||
39 | #include "pwc-ioctl.h" | ||
40 | |||
41 | /* Defines and structures for the Philips webcam */ | ||
42 | /* Used for checking memory corruption/pointer validation */ | ||
43 | #define PWC_MAGIC 0x89DC10ABUL | ||
44 | #undef PWC_MAGIC | ||
45 | |||
46 | /* Turn some debugging options on/off */ | ||
47 | #define PWC_DEBUG 0 | ||
48 | |||
49 | /* Trace certain actions in the driver */ | ||
50 | #define TRACE_MODULE 0x0001 | ||
51 | #define TRACE_PROBE 0x0002 | ||
52 | #define TRACE_OPEN 0x0004 | ||
53 | #define TRACE_READ 0x0008 | ||
54 | #define TRACE_MEMORY 0x0010 | ||
55 | #define TRACE_FLOW 0x0020 | ||
56 | #define TRACE_SIZE 0x0040 | ||
57 | #define TRACE_PWCX 0x0080 | ||
58 | #define TRACE_SEQUENCE 0x1000 | ||
59 | |||
60 | #define Trace(R, A...) if (pwc_trace & R) printk(KERN_DEBUG PWC_NAME " " A) | ||
61 | #define Debug(A...) printk(KERN_DEBUG PWC_NAME " " A) | ||
62 | #define Info(A...) printk(KERN_INFO PWC_NAME " " A) | ||
63 | #define Err(A...) printk(KERN_ERR PWC_NAME " " A) | ||
64 | |||
65 | |||
66 | /* Defines for ToUCam cameras */ | ||
67 | #define TOUCAM_HEADER_SIZE 8 | ||
68 | #define TOUCAM_TRAILER_SIZE 4 | ||
69 | |||
70 | #define FEATURE_MOTOR_PANTILT 0x0001 | ||
71 | |||
72 | /* Version block */ | ||
73 | #define PWC_MAJOR 9 | ||
74 | #define PWC_MINOR 0 | ||
75 | #define PWC_VERSION "9.0.2-unofficial" | ||
76 | #define PWC_NAME "pwc" | ||
77 | |||
78 | /* Turn certain features on/off */ | ||
79 | #define PWC_INT_PIPE 0 | ||
80 | |||
81 | /* Ignore errors in the first N frames, to allow for startup delays */ | ||
82 | #define FRAME_LOWMARK 5 | ||
83 | |||
84 | /* Size and number of buffers for the ISO pipe. */ | ||
85 | #define MAX_ISO_BUFS 2 | ||
86 | #define ISO_FRAMES_PER_DESC 10 | ||
87 | #define ISO_MAX_FRAME_SIZE 960 | ||
88 | #define ISO_BUFFER_SIZE (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE) | ||
89 | |||
90 | /* Frame buffers: contains compressed or uncompressed video data. */ | ||
91 | #define MAX_FRAMES 5 | ||
92 | /* Maximum size after decompression is 640x480 YUV data, 1.5 * 640 * 480 */ | ||
93 | #define PWC_FRAME_SIZE (460800 + TOUCAM_HEADER_SIZE + TOUCAM_TRAILER_SIZE) | ||
94 | |||
95 | /* Absolute maximum number of buffers available for mmap() */ | ||
96 | #define MAX_IMAGES 10 | ||
97 | |||
98 | /* The following structures were based on cpia.h. Why reinvent the wheel? :-) */ | ||
99 | struct pwc_iso_buf | ||
100 | { | ||
101 | void *data; | ||
102 | int length; | ||
103 | int read; | ||
104 | struct urb *urb; | ||
105 | }; | ||
106 | |||
107 | /* intermediate buffers with raw data from the USB cam */ | ||
108 | struct pwc_frame_buf | ||
109 | { | ||
110 | void *data; | ||
111 | volatile int filled; /* number of bytes filled */ | ||
112 | struct pwc_frame_buf *next; /* list */ | ||
113 | #if PWC_DEBUG | ||
114 | int sequence; /* Sequence number */ | ||
115 | #endif | ||
116 | }; | ||
117 | |||
118 | struct pwc_device | ||
119 | { | ||
120 | struct video_device *vdev; | ||
121 | #ifdef PWC_MAGIC | ||
122 | int magic; | ||
123 | #endif | ||
124 | /* Pointer to our usb_device */ | ||
125 | struct usb_device *udev; | ||
126 | |||
127 | int type; /* type of cam (645, 646, 675, 680, 690, 720, 730, 740, 750) */ | ||
128 | int release; /* release number */ | ||
129 | int features; /* feature bits */ | ||
130 | char serial[30]; /* serial number (string) */ | ||
131 | int error_status; /* set when something goes wrong with the cam (unplugged, USB errors) */ | ||
132 | int usb_init; /* set when the cam has been initialized over USB */ | ||
133 | |||
134 | /*** Video data ***/ | ||
135 | int vopen; /* flag */ | ||
136 | int vendpoint; /* video isoc endpoint */ | ||
137 | int vcinterface; /* video control interface */ | ||
138 | int valternate; /* alternate interface needed */ | ||
139 | int vframes, vsize; /* frames-per-second & size (see PSZ_*) */ | ||
140 | int vpalette; /* palette: 420P, RAW or RGBBAYER */ | ||
141 | int vframe_count; /* received frames */ | ||
142 | int vframes_dumped; /* counter for dumped frames */ | ||
143 | int vframes_error; /* frames received in error */ | ||
144 | int vmax_packet_size; /* USB maxpacket size */ | ||
145 | int vlast_packet_size; /* for frame synchronisation */ | ||
146 | int visoc_errors; /* number of contiguous ISOC errors */ | ||
147 | int vcompression; /* desired compression factor */ | ||
148 | int vbandlength; /* compressed band length; 0 is uncompressed */ | ||
149 | char vsnapshot; /* snapshot mode */ | ||
150 | char vsync; /* used by isoc handler */ | ||
151 | char vmirror; /* for ToUCaM series */ | ||
152 | |||
153 | int cmd_len; | ||
154 | unsigned char cmd_buf[13]; | ||
155 | |||
156 | /* The image acquisition requires 3 to 4 steps: | ||
157 | 1. data is gathered in short packets from the USB controller | ||
158 | 2. data is synchronized and packed into a frame buffer | ||
159 | 3a. in case data is compressed, decompress it directly into image buffer | ||
160 | 3b. in case data is uncompressed, copy into image buffer with viewport | ||
161 | 4. data is transferred to the user process | ||
162 | |||
163 | Note that MAX_ISO_BUFS != MAX_FRAMES != MAX_IMAGES.... | ||
164 | We have in effect a back-to-back-double-buffer system. | ||
165 | */ | ||
166 | /* 1: isoc */ | ||
167 | struct pwc_iso_buf sbuf[MAX_ISO_BUFS]; | ||
168 | char iso_init; | ||
169 | |||
170 | /* 2: frame */ | ||
171 | struct pwc_frame_buf *fbuf; /* all frames */ | ||
172 | struct pwc_frame_buf *empty_frames, *empty_frames_tail; /* all empty frames */ | ||
173 | struct pwc_frame_buf *full_frames, *full_frames_tail; /* all filled frames */ | ||
174 | struct pwc_frame_buf *fill_frame; /* frame currently being filled */ | ||
175 | struct pwc_frame_buf *read_frame; /* frame currently read by user process */ | ||
176 | int frame_header_size, frame_trailer_size; | ||
177 | int frame_size; | ||
178 | int frame_total_size; /* including header & trailer */ | ||
179 | int drop_frames; | ||
180 | #if PWC_DEBUG | ||
181 | int sequence; /* Debugging aid */ | ||
182 | #endif | ||
183 | |||
184 | /* 3: decompression */ | ||
185 | struct pwc_decompressor *decompressor; /* function block with decompression routines */ | ||
186 | void *decompress_data; /* private data for decompression engine */ | ||
187 | |||
188 | /* 4: image */ | ||
189 | /* We have an 'image' and a 'view', where 'image' is the fixed-size image | ||
190 | as delivered by the camera, and 'view' is the size requested by the | ||
191 | program. The camera image is centered in this viewport, laced with | ||
192 | a gray or black border. view_min <= image <= view <= view_max; | ||
193 | */ | ||
194 | int image_mask; /* bitmask of supported sizes */ | ||
195 | struct pwc_coord view_min, view_max; /* minimum and maximum viewable sizes */ | ||
196 | struct pwc_coord abs_max; /* maximum supported size with compression */ | ||
197 | struct pwc_coord image, view; /* image and viewport size */ | ||
198 | struct pwc_coord offset; /* offset within the viewport */ | ||
199 | |||
200 | void *image_data; /* total buffer, which is subdivided into ... */ | ||
201 | void *image_ptr[MAX_IMAGES]; /* ...several images... */ | ||
202 | int fill_image; /* ...which are rotated. */ | ||
203 | int len_per_image; /* length per image */ | ||
204 | int image_read_pos; /* In case we read data in pieces, keep track of were we are in the imagebuffer */ | ||
205 | int image_used[MAX_IMAGES]; /* For MCAPTURE and SYNC */ | ||
206 | |||
207 | struct semaphore modlock; /* to prevent races in video_open(), etc */ | ||
208 | spinlock_t ptrlock; /* for manipulating the buffer pointers */ | ||
209 | |||
210 | /*** motorized pan/tilt feature */ | ||
211 | struct pwc_mpt_range angle_range; | ||
212 | int pan_angle; /* in degrees * 100 */ | ||
213 | int tilt_angle; /* absolute angle; 0,0 is home position */ | ||
214 | |||
215 | /*** Misc. data ***/ | ||
216 | wait_queue_head_t frameq; /* When waiting for a frame to finish... */ | ||
217 | #if PWC_INT_PIPE | ||
218 | void *usb_int_handler; /* for the interrupt endpoint */ | ||
219 | #endif | ||
220 | }; | ||
221 | |||
222 | |||
223 | #ifdef __cplusplus | ||
224 | extern "C" { | ||
225 | #endif | ||
226 | |||
227 | /* Global variable */ | ||
228 | extern int pwc_trace; | ||
229 | |||
230 | /** functions in pwc-if.c */ | ||
231 | int pwc_try_video_mode(struct pwc_device *pdev, int width, int height, int new_fps, int new_compression, int new_snapshot); | ||
232 | |||
233 | /** Functions in pwc-misc.c */ | ||
234 | /* sizes in pixels */ | ||
235 | extern struct pwc_coord pwc_image_sizes[PSZ_MAX]; | ||
236 | |||
237 | int pwc_decode_size(struct pwc_device *pdev, int width, int height); | ||
238 | void pwc_construct(struct pwc_device *pdev); | ||
239 | |||
240 | /** Functions in pwc-ctrl.c */ | ||
241 | /* Request a certain video mode. Returns < 0 if not possible */ | ||
242 | extern int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frames, int compression, int snapshot); | ||
243 | |||
244 | /* Various controls; should be obvious. Value 0..65535, or < 0 on error */ | ||
245 | extern int pwc_get_brightness(struct pwc_device *pdev); | ||
246 | extern int pwc_set_brightness(struct pwc_device *pdev, int value); | ||
247 | extern int pwc_get_contrast(struct pwc_device *pdev); | ||
248 | extern int pwc_set_contrast(struct pwc_device *pdev, int value); | ||
249 | extern int pwc_get_gamma(struct pwc_device *pdev); | ||
250 | extern int pwc_set_gamma(struct pwc_device *pdev, int value); | ||
251 | extern int pwc_get_saturation(struct pwc_device *pdev); | ||
252 | extern int pwc_set_saturation(struct pwc_device *pdev, int value); | ||
253 | extern int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value); | ||
254 | extern int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor); | ||
255 | |||
256 | /* Power down or up the camera; not supported by all models */ | ||
257 | extern int pwc_camera_power(struct pwc_device *pdev, int power); | ||
258 | |||
259 | /* Private ioctl()s; see pwc-ioctl.h */ | ||
260 | extern int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg); | ||
261 | |||
262 | |||
263 | /** pwc-uncompress.c */ | ||
264 | /* Expand frame to image, possibly including decompression. Uses read_frame and fill_image */ | ||
265 | extern int pwc_decompress(struct pwc_device *pdev); | ||
266 | |||
267 | #ifdef __cplusplus | ||
268 | } | ||
269 | #endif | ||
270 | |||
271 | |||
272 | #endif | ||