V4L/DVB (10353): gspca - some subdrivers: Don't get the control values from the webcam.
[linux-2.6/mini2440.git] / drivers / media / video / gspca / spca505.c
blob25e2bec9dc52953be0a3ed781aee8b0f033bafc8
1 /*
2 * SPCA505 chip based cameras initialization data
4 * V4L2 by Jean-Francis Moine <http://moinejf.free.fr>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define MODULE_NAME "spca505"
24 #include "gspca.h"
26 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
27 MODULE_DESCRIPTION("GSPCA/SPCA505 USB Camera Driver");
28 MODULE_LICENSE("GPL");
30 /* specific webcam descriptor */
31 struct sd {
32 struct gspca_dev gspca_dev; /* !! must be the first item */
34 unsigned char brightness;
36 char subtype;
37 #define IntelPCCameraPro 0
38 #define Nxultra 1
41 /* V4L2 controls supported by the driver */
42 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
43 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
45 static struct ctrl sd_ctrls[] = {
46 #define SD_BRIGHTNESS 0
49 .id = V4L2_CID_BRIGHTNESS,
50 .type = V4L2_CTRL_TYPE_INTEGER,
51 .name = "Brightness",
52 .minimum = 0,
53 .maximum = 255,
54 .step = 1,
55 .default_value = 127,
57 .set = sd_setbrightness,
58 .get = sd_getbrightness,
62 static const struct v4l2_pix_format vga_mode[] = {
63 {160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
64 .bytesperline = 160,
65 .sizeimage = 160 * 120 * 3 / 2,
66 .colorspace = V4L2_COLORSPACE_SRGB,
67 .priv = 5},
68 {176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
69 .bytesperline = 176,
70 .sizeimage = 176 * 144 * 3 / 2,
71 .colorspace = V4L2_COLORSPACE_SRGB,
72 .priv = 4},
73 {320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
74 .bytesperline = 320,
75 .sizeimage = 320 * 240 * 3 / 2,
76 .colorspace = V4L2_COLORSPACE_SRGB,
77 .priv = 2},
78 {352, 288, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
79 .bytesperline = 352,
80 .sizeimage = 352 * 288 * 3 / 2,
81 .colorspace = V4L2_COLORSPACE_SRGB,
82 .priv = 1},
83 {640, 480, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
84 .bytesperline = 640,
85 .sizeimage = 640 * 480 * 3 / 2,
86 .colorspace = V4L2_COLORSPACE_SRGB,
87 .priv = 0},
90 #define SPCA50X_OFFSET_DATA 10
92 #define SPCA50X_REG_USB 0x02 /* spca505 501 */
94 #define SPCA50X_USB_CTRL 0x00 /* spca505 */
95 #define SPCA50X_CUSB_ENABLE 0x01 /* spca505 */
96 #define SPCA50X_REG_GLOBAL 0x03 /* spca505 */
97 #define SPCA50X_GMISC0_IDSEL 0x01 /* Global control device ID select spca505 */
98 #define SPCA50X_GLOBAL_MISC0 0x00 /* Global control miscellaneous 0 spca505 */
100 #define SPCA50X_GLOBAL_MISC1 0x01 /* 505 */
101 #define SPCA50X_GLOBAL_MISC3 0x03 /* 505 */
102 #define SPCA50X_GMISC3_SAA7113RST 0x20 /* Not sure about this one spca505 */
105 * Data to initialize a SPCA505. Common to the CCD and external modes
107 static const __u16 spca505_init_data[][3] = {
108 /* line bmRequest,value,index */
109 /* 1819 */
110 {SPCA50X_REG_GLOBAL, SPCA50X_GMISC3_SAA7113RST, SPCA50X_GLOBAL_MISC3},
111 /* Sensor reset */
112 /* 1822 */ {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC3},
113 /* 1825 */ {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC1},
114 /* Block USB reset */
115 /* 1828 */ {SPCA50X_REG_GLOBAL, SPCA50X_GMISC0_IDSEL,
116 SPCA50X_GLOBAL_MISC0},
118 /* 1831 */ {0x5, 0x01, 0x10},
119 /* Maybe power down some stuff */
120 /* 1834 */ {0x5, 0x0f, 0x11},
122 /* Setup internal CCD ? */
123 /* 1837 */ {0x6, 0x10, 0x08},
124 /* 1840 */ {0x6, 0x00, 0x09},
125 /* 1843 */ {0x6, 0x00, 0x0a},
126 /* 1846 */ {0x6, 0x00, 0x0b},
127 /* 1849 */ {0x6, 0x10, 0x0c},
128 /* 1852 */ {0x6, 0x00, 0x0d},
129 /* 1855 */ {0x6, 0x00, 0x0e},
130 /* 1858 */ {0x6, 0x00, 0x0f},
131 /* 1861 */ {0x6, 0x10, 0x10},
132 /* 1864 */ {0x6, 0x02, 0x11},
133 /* 1867 */ {0x6, 0x00, 0x12},
134 /* 1870 */ {0x6, 0x04, 0x13},
135 /* 1873 */ {0x6, 0x02, 0x14},
136 /* 1876 */ {0x6, 0x8a, 0x51},
137 /* 1879 */ {0x6, 0x40, 0x52},
138 /* 1882 */ {0x6, 0xb6, 0x53},
139 /* 1885 */ {0x6, 0x3d, 0x54},
144 * Data to initialize the camera using the internal CCD
146 static const __u16 spca505_open_data_ccd[][3] = {
147 /* line bmRequest,value,index */
148 /* Internal CCD data set */
149 /* 1891 */ {0x3, 0x04, 0x01},
150 /* This could be a reset */
151 /* 1894 */ {0x3, 0x00, 0x01},
153 /* Setup compression and image registers. 0x6 and 0x7 seem to be
154 related to H&V hold, and are resolution mode specific */
155 /* 1897 */ {0x4, 0x10, 0x01},
156 /* DIFF(0x50), was (0x10) */
157 /* 1900 */ {0x4, 0x00, 0x04},
158 /* 1903 */ {0x4, 0x00, 0x05},
159 /* 1906 */ {0x4, 0x20, 0x06},
160 /* 1909 */ {0x4, 0x20, 0x07},
162 /* 1912 */ {0x8, 0x0a, 0x00},
163 /* DIFF (0x4a), was (0xa) */
165 /* 1915 */ {0x5, 0x00, 0x10},
166 /* 1918 */ {0x5, 0x00, 0x11},
167 /* 1921 */ {0x5, 0x00, 0x00},
168 /* DIFF not written */
169 /* 1924 */ {0x5, 0x00, 0x01},
170 /* DIFF not written */
171 /* 1927 */ {0x5, 0x00, 0x02},
172 /* DIFF not written */
173 /* 1930 */ {0x5, 0x00, 0x03},
174 /* DIFF not written */
175 /* 1933 */ {0x5, 0x00, 0x04},
176 /* DIFF not written */
177 /* 1936 */ {0x5, 0x80, 0x05},
178 /* DIFF not written */
179 /* 1939 */ {0x5, 0xe0, 0x06},
180 /* DIFF not written */
181 /* 1942 */ {0x5, 0x20, 0x07},
182 /* DIFF not written */
183 /* 1945 */ {0x5, 0xa0, 0x08},
184 /* DIFF not written */
185 /* 1948 */ {0x5, 0x0, 0x12},
186 /* DIFF not written */
187 /* 1951 */ {0x5, 0x02, 0x0f},
188 /* DIFF not written */
189 /* 1954 */ {0x5, 0x10, 0x46},
190 /* DIFF not written */
191 /* 1957 */ {0x5, 0x8, 0x4a},
192 /* DIFF not written */
194 /* 1960 */ {0x3, 0x08, 0x03},
195 /* DIFF (0x3,0x28,0x3) */
196 /* 1963 */ {0x3, 0x08, 0x01},
197 /* 1966 */ {0x3, 0x0c, 0x03},
198 /* DIFF not written */
199 /* 1969 */ {0x3, 0x21, 0x00},
200 /* DIFF (0x39) */
202 /* Extra block copied from init to hopefully ensure CCD is in a sane state */
203 /* 1837 */ {0x6, 0x10, 0x08},
204 /* 1840 */ {0x6, 0x00, 0x09},
205 /* 1843 */ {0x6, 0x00, 0x0a},
206 /* 1846 */ {0x6, 0x00, 0x0b},
207 /* 1849 */ {0x6, 0x10, 0x0c},
208 /* 1852 */ {0x6, 0x00, 0x0d},
209 /* 1855 */ {0x6, 0x00, 0x0e},
210 /* 1858 */ {0x6, 0x00, 0x0f},
211 /* 1861 */ {0x6, 0x10, 0x10},
212 /* 1864 */ {0x6, 0x02, 0x11},
213 /* 1867 */ {0x6, 0x00, 0x12},
214 /* 1870 */ {0x6, 0x04, 0x13},
215 /* 1873 */ {0x6, 0x02, 0x14},
216 /* 1876 */ {0x6, 0x8a, 0x51},
217 /* 1879 */ {0x6, 0x40, 0x52},
218 /* 1882 */ {0x6, 0xb6, 0x53},
219 /* 1885 */ {0x6, 0x3d, 0x54},
220 /* End of extra block */
222 /* 1972 */ {0x6, 0x3f, 0x1},
223 /* Block skipped */
224 /* 1975 */ {0x6, 0x10, 0x02},
225 /* 1978 */ {0x6, 0x64, 0x07},
226 /* 1981 */ {0x6, 0x10, 0x08},
227 /* 1984 */ {0x6, 0x00, 0x09},
228 /* 1987 */ {0x6, 0x00, 0x0a},
229 /* 1990 */ {0x6, 0x00, 0x0b},
230 /* 1993 */ {0x6, 0x10, 0x0c},
231 /* 1996 */ {0x6, 0x00, 0x0d},
232 /* 1999 */ {0x6, 0x00, 0x0e},
233 /* 2002 */ {0x6, 0x00, 0x0f},
234 /* 2005 */ {0x6, 0x10, 0x10},
235 /* 2008 */ {0x6, 0x02, 0x11},
236 /* 2011 */ {0x6, 0x00, 0x12},
237 /* 2014 */ {0x6, 0x04, 0x13},
238 /* 2017 */ {0x6, 0x02, 0x14},
239 /* 2020 */ {0x6, 0x8a, 0x51},
240 /* 2023 */ {0x6, 0x40, 0x52},
241 /* 2026 */ {0x6, 0xb6, 0x53},
242 /* 2029 */ {0x6, 0x3d, 0x54},
243 /* 2032 */ {0x6, 0x60, 0x57},
244 /* 2035 */ {0x6, 0x20, 0x58},
245 /* 2038 */ {0x6, 0x15, 0x59},
246 /* 2041 */ {0x6, 0x05, 0x5a},
248 /* 2044 */ {0x5, 0x01, 0xc0},
249 /* 2047 */ {0x5, 0x10, 0xcb},
250 /* 2050 */ {0x5, 0x80, 0xc1},
251 /* */
252 /* 2053 */ {0x5, 0x0, 0xc2},
253 /* 4 was 0 */
254 /* 2056 */ {0x5, 0x00, 0xca},
255 /* 2059 */ {0x5, 0x80, 0xc1},
256 /* */
257 /* 2062 */ {0x5, 0x04, 0xc2},
258 /* 2065 */ {0x5, 0x00, 0xca},
259 /* 2068 */ {0x5, 0x0, 0xc1},
260 /* */
261 /* 2071 */ {0x5, 0x00, 0xc2},
262 /* 2074 */ {0x5, 0x00, 0xca},
263 /* 2077 */ {0x5, 0x40, 0xc1},
264 /* */
265 /* 2080 */ {0x5, 0x17, 0xc2},
266 /* 2083 */ {0x5, 0x00, 0xca},
267 /* 2086 */ {0x5, 0x80, 0xc1},
268 /* */
269 /* 2089 */ {0x5, 0x06, 0xc2},
270 /* 2092 */ {0x5, 0x00, 0xca},
271 /* 2095 */ {0x5, 0x80, 0xc1},
272 /* */
273 /* 2098 */ {0x5, 0x04, 0xc2},
274 /* 2101 */ {0x5, 0x00, 0xca},
276 /* 2104 */ {0x3, 0x4c, 0x3},
277 /* 2107 */ {0x3, 0x18, 0x1},
279 /* 2110 */ {0x6, 0x70, 0x51},
280 /* 2113 */ {0x6, 0xbe, 0x53},
281 /* 2116 */ {0x6, 0x71, 0x57},
282 /* 2119 */ {0x6, 0x20, 0x58},
283 /* 2122 */ {0x6, 0x05, 0x59},
284 /* 2125 */ {0x6, 0x15, 0x5a},
286 /* 2128 */ {0x4, 0x00, 0x08},
287 /* Compress = OFF (0x1 to turn on) */
288 /* 2131 */ {0x4, 0x12, 0x09},
289 /* 2134 */ {0x4, 0x21, 0x0a},
290 /* 2137 */ {0x4, 0x10, 0x0b},
291 /* 2140 */ {0x4, 0x21, 0x0c},
292 /* 2143 */ {0x4, 0x05, 0x00},
293 /* was 5 (Image Type ? ) */
294 /* 2146 */ {0x4, 0x00, 0x01},
296 /* 2149 */ {0x6, 0x3f, 0x01},
298 /* 2152 */ {0x4, 0x00, 0x04},
299 /* 2155 */ {0x4, 0x00, 0x05},
300 /* 2158 */ {0x4, 0x40, 0x06},
301 /* 2161 */ {0x4, 0x40, 0x07},
303 /* 2164 */ {0x6, 0x1c, 0x17},
304 /* 2167 */ {0x6, 0xe2, 0x19},
305 /* 2170 */ {0x6, 0x1c, 0x1b},
306 /* 2173 */ {0x6, 0xe2, 0x1d},
307 /* 2176 */ {0x6, 0xaa, 0x1f},
308 /* 2179 */ {0x6, 0x70, 0x20},
310 /* 2182 */ {0x5, 0x01, 0x10},
311 /* 2185 */ {0x5, 0x00, 0x11},
312 /* 2188 */ {0x5, 0x01, 0x00},
313 /* 2191 */ {0x5, 0x05, 0x01},
314 /* 2194 */ {0x5, 0x00, 0xc1},
315 /* */
316 /* 2197 */ {0x5, 0x00, 0xc2},
317 /* 2200 */ {0x5, 0x00, 0xca},
319 /* 2203 */ {0x6, 0x70, 0x51},
320 /* 2206 */ {0x6, 0xbe, 0x53},
325 Made by Tomasz Zablocki (skalamandra@poczta.onet.pl)
326 * SPCA505b chip based cameras initialization data
329 /* jfm */
330 #define initial_brightness 0x7f /* 0x0(white)-0xff(black) */
331 /* #define initial_brightness 0x0 //0x0(white)-0xff(black) */
333 * Data to initialize a SPCA505. Common to the CCD and external modes
335 static const __u16 spca505b_init_data[][3] = {
336 /* start */
337 {0x02, 0x00, 0x00}, /* init */
338 {0x02, 0x00, 0x01},
339 {0x02, 0x00, 0x02},
340 {0x02, 0x00, 0x03},
341 {0x02, 0x00, 0x04},
342 {0x02, 0x00, 0x05},
343 {0x02, 0x00, 0x06},
344 {0x02, 0x00, 0x07},
345 {0x02, 0x00, 0x08},
346 {0x02, 0x00, 0x09},
347 {0x03, 0x00, 0x00},
348 {0x03, 0x00, 0x01},
349 {0x03, 0x00, 0x02},
350 {0x03, 0x00, 0x03},
351 {0x03, 0x00, 0x04},
352 {0x03, 0x00, 0x05},
353 {0x03, 0x00, 0x06},
354 {0x04, 0x00, 0x00},
355 {0x04, 0x00, 0x02},
356 {0x04, 0x00, 0x04},
357 {0x04, 0x00, 0x05},
358 {0x04, 0x00, 0x06},
359 {0x04, 0x00, 0x07},
360 {0x04, 0x00, 0x08},
361 {0x04, 0x00, 0x09},
362 {0x04, 0x00, 0x0a},
363 {0x04, 0x00, 0x0b},
364 {0x04, 0x00, 0x0c},
365 {0x07, 0x00, 0x00},
366 {0x07, 0x00, 0x03},
367 {0x08, 0x00, 0x00},
368 {0x08, 0x00, 0x01},
369 {0x08, 0x00, 0x02},
370 {0x00, 0x01, 0x00},
371 {0x00, 0x01, 0x01},
372 {0x00, 0x01, 0x34},
373 {0x00, 0x01, 0x35},
374 {0x06, 0x18, 0x08},
375 {0x06, 0xfc, 0x09},
376 {0x06, 0xfc, 0x0a},
377 {0x06, 0xfc, 0x0b},
378 {0x06, 0x18, 0x0c},
379 {0x06, 0xfc, 0x0d},
380 {0x06, 0xfc, 0x0e},
381 {0x06, 0xfc, 0x0f},
382 {0x06, 0x18, 0x10},
383 {0x06, 0xfe, 0x12},
384 {0x06, 0x00, 0x11},
385 {0x06, 0x00, 0x14},
386 {0x06, 0x00, 0x13},
387 {0x06, 0x28, 0x51},
388 {0x06, 0xff, 0x53},
389 {0x02, 0x00, 0x08},
391 {0x03, 0x00, 0x03},
392 {0x03, 0x10, 0x03},
397 * Data to initialize the camera using the internal CCD
399 static const __u16 spca505b_open_data_ccd[][3] = {
401 /* {0x02,0x00,0x00}, */
402 {0x03, 0x04, 0x01}, /* rst */
403 {0x03, 0x00, 0x01},
404 {0x03, 0x00, 0x00},
405 {0x03, 0x21, 0x00},
406 {0x03, 0x00, 0x04},
407 {0x03, 0x00, 0x03},
408 {0x03, 0x18, 0x03},
409 {0x03, 0x08, 0x01},
410 {0x03, 0x1c, 0x03},
411 {0x03, 0x5c, 0x03},
412 {0x03, 0x5c, 0x03},
413 {0x03, 0x18, 0x01},
415 /* same as 505 */
416 {0x04, 0x10, 0x01},
417 {0x04, 0x00, 0x04},
418 {0x04, 0x00, 0x05},
419 {0x04, 0x20, 0x06},
420 {0x04, 0x20, 0x07},
422 {0x08, 0x0a, 0x00},
424 {0x05, 0x00, 0x10},
425 {0x05, 0x00, 0x11},
426 {0x05, 0x00, 0x12},
427 {0x05, 0x6f, 0x00},
428 {0x05, initial_brightness >> 6, 0x00},
429 {0x05, initial_brightness << 2, 0x01},
430 {0x05, 0x00, 0x02},
431 {0x05, 0x01, 0x03},
432 {0x05, 0x00, 0x04},
433 {0x05, 0x03, 0x05},
434 {0x05, 0xe0, 0x06},
435 {0x05, 0x20, 0x07},
436 {0x05, 0xa0, 0x08},
437 {0x05, 0x00, 0x12},
438 {0x05, 0x02, 0x0f},
439 {0x05, 128, 0x14}, /* max exposure off (0=on) */
440 {0x05, 0x01, 0xb0},
441 {0x05, 0x01, 0xbf},
442 {0x03, 0x02, 0x06},
443 {0x05, 0x10, 0x46},
444 {0x05, 0x08, 0x4a},
446 {0x06, 0x00, 0x01},
447 {0x06, 0x10, 0x02},
448 {0x06, 0x64, 0x07},
449 {0x06, 0x18, 0x08},
450 {0x06, 0xfc, 0x09},
451 {0x06, 0xfc, 0x0a},
452 {0x06, 0xfc, 0x0b},
453 {0x04, 0x00, 0x01},
454 {0x06, 0x18, 0x0c},
455 {0x06, 0xfc, 0x0d},
456 {0x06, 0xfc, 0x0e},
457 {0x06, 0xfc, 0x0f},
458 {0x06, 0x11, 0x10}, /* contrast */
459 {0x06, 0x00, 0x11},
460 {0x06, 0xfe, 0x12},
461 {0x06, 0x00, 0x13},
462 {0x06, 0x00, 0x14},
463 {0x06, 0x9d, 0x51},
464 {0x06, 0x40, 0x52},
465 {0x06, 0x7c, 0x53},
466 {0x06, 0x40, 0x54},
467 {0x06, 0x02, 0x57},
468 {0x06, 0x03, 0x58},
469 {0x06, 0x15, 0x59},
470 {0x06, 0x05, 0x5a},
471 {0x06, 0x03, 0x56},
472 {0x06, 0x02, 0x3f},
473 {0x06, 0x00, 0x40},
474 {0x06, 0x39, 0x41},
475 {0x06, 0x69, 0x42},
476 {0x06, 0x87, 0x43},
477 {0x06, 0x9e, 0x44},
478 {0x06, 0xb1, 0x45},
479 {0x06, 0xbf, 0x46},
480 {0x06, 0xcc, 0x47},
481 {0x06, 0xd5, 0x48},
482 {0x06, 0xdd, 0x49},
483 {0x06, 0xe3, 0x4a},
484 {0x06, 0xe8, 0x4b},
485 {0x06, 0xed, 0x4c},
486 {0x06, 0xf2, 0x4d},
487 {0x06, 0xf7, 0x4e},
488 {0x06, 0xfc, 0x4f},
489 {0x06, 0xff, 0x50},
491 {0x05, 0x01, 0xc0},
492 {0x05, 0x10, 0xcb},
493 {0x05, 0x40, 0xc1},
494 {0x05, 0x04, 0xc2},
495 {0x05, 0x00, 0xca},
496 {0x05, 0x40, 0xc1},
497 {0x05, 0x09, 0xc2},
498 {0x05, 0x00, 0xca},
499 {0x05, 0xc0, 0xc1},
500 {0x05, 0x09, 0xc2},
501 {0x05, 0x00, 0xca},
502 {0x05, 0x40, 0xc1},
503 {0x05, 0x59, 0xc2},
504 {0x05, 0x00, 0xca},
505 {0x04, 0x00, 0x01},
506 {0x05, 0x80, 0xc1},
507 {0x05, 0xec, 0xc2},
508 {0x05, 0x0, 0xca},
510 {0x06, 0x02, 0x57},
511 {0x06, 0x01, 0x58},
512 {0x06, 0x15, 0x59},
513 {0x06, 0x0a, 0x5a},
514 {0x06, 0x01, 0x57},
515 {0x06, 0x8a, 0x03},
516 {0x06, 0x0a, 0x6c},
517 {0x06, 0x30, 0x01},
518 {0x06, 0x20, 0x02},
519 {0x06, 0x00, 0x03},
521 {0x05, 0x8c, 0x25},
523 {0x06, 0x4d, 0x51}, /* maybe saturation (4d) */
524 {0x06, 0x84, 0x53}, /* making green (84) */
525 {0x06, 0x00, 0x57}, /* sharpness (1) */
526 {0x06, 0x18, 0x08},
527 {0x06, 0xfc, 0x09},
528 {0x06, 0xfc, 0x0a},
529 {0x06, 0xfc, 0x0b},
530 {0x06, 0x18, 0x0c}, /* maybe hue (18) */
531 {0x06, 0xfc, 0x0d},
532 {0x06, 0xfc, 0x0e},
533 {0x06, 0xfc, 0x0f},
534 {0x06, 0x18, 0x10}, /* maybe contrast (18) */
536 {0x05, 0x01, 0x02},
538 {0x04, 0x00, 0x08}, /* compression */
539 {0x04, 0x12, 0x09},
540 {0x04, 0x21, 0x0a},
541 {0x04, 0x10, 0x0b},
542 {0x04, 0x21, 0x0c},
543 {0x04, 0x1d, 0x00}, /* imagetype (1d) */
544 {0x04, 0x41, 0x01}, /* hardware snapcontrol */
546 {0x04, 0x00, 0x04},
547 {0x04, 0x00, 0x05},
548 {0x04, 0x10, 0x06},
549 {0x04, 0x10, 0x07},
550 {0x04, 0x40, 0x06},
551 {0x04, 0x40, 0x07},
552 {0x04, 0x00, 0x04},
553 {0x04, 0x00, 0x05},
555 {0x06, 0x1c, 0x17},
556 {0x06, 0xe2, 0x19},
557 {0x06, 0x1c, 0x1b},
558 {0x06, 0xe2, 0x1d},
559 {0x06, 0x5f, 0x1f},
560 {0x06, 0x32, 0x20},
562 {0x05, initial_brightness >> 6, 0x00},
563 {0x05, initial_brightness << 2, 0x01},
564 {0x05, 0x06, 0xc1},
565 {0x05, 0x58, 0xc2},
566 {0x05, 0x0, 0xca},
567 {0x05, 0x0, 0x11},
571 static int reg_write(struct usb_device *dev,
572 __u16 reg, __u16 index, __u16 value)
574 int ret;
576 ret = usb_control_msg(dev,
577 usb_sndctrlpipe(dev, 0),
578 reg,
579 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
580 value, index, NULL, 0, 500);
581 PDEBUG(D_PACK, "reg write: 0x%02x,0x%02x:0x%02x, 0x%x",
582 reg, index, value, ret);
583 if (ret < 0)
584 PDEBUG(D_ERR, "reg write: error %d", ret);
585 return ret;
588 /* returns: negative is error, pos or zero is data */
589 static int reg_read(struct gspca_dev *gspca_dev,
590 __u16 reg, /* bRequest */
591 __u16 index, /* wIndex */
592 __u16 length) /* wLength (1 or 2 only) */
594 int ret;
596 gspca_dev->usb_buf[1] = 0;
597 ret = usb_control_msg(gspca_dev->dev,
598 usb_rcvctrlpipe(gspca_dev->dev, 0),
599 reg,
600 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
601 (__u16) 0, /* value */
602 (__u16) index,
603 gspca_dev->usb_buf, length,
604 500); /* timeout */
605 if (ret < 0) {
606 PDEBUG(D_ERR, "reg_read err %d", ret);
607 return -1;
609 return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
612 static int write_vector(struct gspca_dev *gspca_dev,
613 const __u16 data[][3])
615 struct usb_device *dev = gspca_dev->dev;
616 int ret, i = 0;
618 while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
619 ret = reg_write(dev, data[i][0], data[i][2], data[i][1]);
620 if (ret < 0) {
621 PDEBUG(D_ERR,
622 "Register write failed for 0x%x,0x%x,0x%x",
623 data[i][0], data[i][1], data[i][2]);
624 return ret;
626 i++;
628 return 0;
631 /* this function is called at probe time */
632 static int sd_config(struct gspca_dev *gspca_dev,
633 const struct usb_device_id *id)
635 struct sd *sd = (struct sd *) gspca_dev;
636 struct cam *cam;
638 cam = &gspca_dev->cam;
639 cam->cam_mode = vga_mode;
640 sd->subtype = id->driver_info;
641 if (sd->subtype != IntelPCCameraPro)
642 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
643 else /* no 640x480 for IntelPCCameraPro */
644 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0] - 1;
645 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
647 if (sd->subtype == Nxultra) {
648 if (write_vector(gspca_dev, spca505b_init_data))
649 return -EIO;
650 } else {
651 if (write_vector(gspca_dev, spca505_init_data))
652 return -EIO;
654 return 0;
657 /* this function is called at probe and resume time */
658 static int sd_init(struct gspca_dev *gspca_dev)
660 struct sd *sd = (struct sd *) gspca_dev;
661 int ret;
663 PDEBUG(D_STREAM, "Initializing SPCA505");
664 if (sd->subtype == Nxultra)
665 write_vector(gspca_dev, spca505b_open_data_ccd);
666 else
667 write_vector(gspca_dev, spca505_open_data_ccd);
668 ret = reg_read(gspca_dev, 6, 0x16, 2);
670 if (ret < 0) {
671 PDEBUG(D_ERR|D_STREAM,
672 "register read failed for after vector read err = %d",
673 ret);
674 return -EIO;
676 PDEBUG(D_STREAM,
677 "After vector read returns : 0x%x should be 0x0101",
678 ret & 0xffff);
680 ret = reg_write(gspca_dev->dev, 6, 0x16, 0x0a);
681 if (ret < 0) {
682 PDEBUG(D_ERR, "register write failed for (6,0xa,0x16) err=%d",
683 ret);
684 return -EIO;
686 reg_write(gspca_dev->dev, 5, 0xc2, 18);
687 return 0;
690 static int sd_start(struct gspca_dev *gspca_dev)
692 struct usb_device *dev = gspca_dev->dev;
693 int ret;
695 /* necessary because without it we can see stream
696 * only once after loading module */
697 /* stopping usb registers Tomasz change */
698 reg_write(dev, 0x02, 0x0, 0x0);
699 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
700 case 0:
701 reg_write(dev, 0x04, 0x00, 0x00);
702 reg_write(dev, 0x04, 0x06, 0x10);
703 reg_write(dev, 0x04, 0x07, 0x10);
704 break;
705 case 1:
706 reg_write(dev, 0x04, 0x00, 0x01);
707 reg_write(dev, 0x04, 0x06, 0x1a);
708 reg_write(dev, 0x04, 0x07, 0x1a);
709 break;
710 case 2:
711 reg_write(dev, 0x04, 0x00, 0x02);
712 reg_write(dev, 0x04, 0x06, 0x1c);
713 reg_write(dev, 0x04, 0x07, 0x1d);
714 break;
715 case 4:
716 reg_write(dev, 0x04, 0x00, 0x04);
717 reg_write(dev, 0x04, 0x06, 0x34);
718 reg_write(dev, 0x04, 0x07, 0x34);
719 break;
720 default:
721 /* case 5: */
722 reg_write(dev, 0x04, 0x00, 0x05);
723 reg_write(dev, 0x04, 0x06, 0x40);
724 reg_write(dev, 0x04, 0x07, 0x40);
725 break;
727 /* Enable ISO packet machine - should we do this here or in ISOC init ? */
728 ret = reg_write(dev, SPCA50X_REG_USB,
729 SPCA50X_USB_CTRL,
730 SPCA50X_CUSB_ENABLE);
732 /* reg_write(dev, 0x5, 0x0, 0x0); */
733 /* reg_write(dev, 0x5, 0x0, 0x1); */
734 /* reg_write(dev, 0x5, 0x11, 0x2); */
735 return ret;
738 static void sd_stopN(struct gspca_dev *gspca_dev)
740 /* Disable ISO packet machine */
741 reg_write(gspca_dev->dev, 0x02, 0x00, 0x00);
744 /* called on streamoff with alt 0 and on disconnect */
745 static void sd_stop0(struct gspca_dev *gspca_dev)
747 if (!gspca_dev->present)
748 return;
750 /* This maybe reset or power control */
751 reg_write(gspca_dev->dev, 0x03, 0x03, 0x20);
752 reg_write(gspca_dev->dev, 0x03, 0x01, 0x0);
753 reg_write(gspca_dev->dev, 0x03, 0x00, 0x1);
754 reg_write(gspca_dev->dev, 0x05, 0x10, 0x1);
755 reg_write(gspca_dev->dev, 0x05, 0x11, 0xf);
758 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
759 struct gspca_frame *frame, /* target */
760 __u8 *data, /* isoc packet */
761 int len) /* iso packet length */
763 switch (data[0]) {
764 case 0: /* start of frame */
765 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
766 data, 0);
767 data += SPCA50X_OFFSET_DATA;
768 len -= SPCA50X_OFFSET_DATA;
769 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
770 data, len);
771 break;
772 case 0xff: /* drop */
773 /* gspca_dev->last_packet_type = DISCARD_PACKET; */
774 break;
775 default:
776 data += 1;
777 len -= 1;
778 gspca_frame_add(gspca_dev, INTER_PACKET, frame,
779 data, len);
780 break;
784 static void setbrightness(struct gspca_dev *gspca_dev)
786 struct sd *sd = (struct sd *) gspca_dev;
788 __u8 brightness = sd->brightness;
789 reg_write(gspca_dev->dev, 5, 0x00, (255 - brightness) >> 6);
790 reg_write(gspca_dev->dev, 5, 0x01, (255 - brightness) << 2);
794 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
796 struct sd *sd = (struct sd *) gspca_dev;
798 sd->brightness = val;
799 if (gspca_dev->streaming)
800 setbrightness(gspca_dev);
801 return 0;
804 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
806 struct sd *sd = (struct sd *) gspca_dev;
808 *val = sd->brightness;
809 return 0;
812 /* sub-driver description */
813 static const struct sd_desc sd_desc = {
814 .name = MODULE_NAME,
815 .ctrls = sd_ctrls,
816 .nctrls = ARRAY_SIZE(sd_ctrls),
817 .config = sd_config,
818 .init = sd_init,
819 .start = sd_start,
820 .stopN = sd_stopN,
821 .stop0 = sd_stop0,
822 .pkt_scan = sd_pkt_scan,
825 /* -- module initialisation -- */
826 static const __devinitdata struct usb_device_id device_table[] = {
827 {USB_DEVICE(0x041e, 0x401d), .driver_info = Nxultra},
828 {USB_DEVICE(0x0733, 0x0430), .driver_info = IntelPCCameraPro},
829 /*fixme: may be UsbGrabberPV321 BRIDGE_SPCA506 SENSOR_SAA7113 */
832 MODULE_DEVICE_TABLE(usb, device_table);
834 /* -- device connect -- */
835 static int sd_probe(struct usb_interface *intf,
836 const struct usb_device_id *id)
838 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
839 THIS_MODULE);
842 static struct usb_driver sd_driver = {
843 .name = MODULE_NAME,
844 .id_table = device_table,
845 .probe = sd_probe,
846 .disconnect = gspca_disconnect,
847 #ifdef CONFIG_PM
848 .suspend = gspca_suspend,
849 .resume = gspca_resume,
850 #endif
853 /* -- module insert / remove -- */
854 static int __init sd_mod_init(void)
856 int ret;
857 ret = usb_register(&sd_driver);
858 if (ret < 0)
859 return ret;
860 PDEBUG(D_PROBE, "registered");
861 return 0;
863 static void __exit sd_mod_exit(void)
865 usb_deregister(&sd_driver);
866 PDEBUG(D_PROBE, "deregistered");
869 module_init(sd_mod_init);
870 module_exit(sd_mod_exit);