]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/usb/gspca/spca505.c
Merge branches 'for-4.11/upstream-fixes', 'for-4.12/accutouch', 'for-4.12/cp2112...
[mirror_ubuntu-artful-kernel.git] / drivers / media / usb / gspca / spca505.c
CommitLineData
6a7eba24
JFM
1/*
2 * SPCA505 chip based cameras initialization data
3 *
4 * V4L2 by Jean-Francis Moine <http://moinejf.free.fr>
5 *
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.
10 *
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.
15 *
6a7eba24
JFM
16 */
17
133a9fe9
JP
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
6a7eba24
JFM
20#define MODULE_NAME "spca505"
21
22#include "gspca.h"
23
6a7eba24
JFM
24MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
25MODULE_DESCRIPTION("GSPCA/SPCA505 USB Camera Driver");
26MODULE_LICENSE("GPL");
27
28/* specific webcam descriptor */
29struct sd {
30 struct gspca_dev gspca_dev; /* !! must be the first item */
31
16631aed 32 u8 subtype;
6a7eba24
JFM
33#define IntelPCCameraPro 0
34#define Nxultra 1
35};
36
cc611b8a 37static const struct v4l2_pix_format vga_mode[] = {
1250ac6d 38 {160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
00b27ce6 39 .bytesperline = 160,
1250ac6d 40 .sizeimage = 160 * 120 * 3 / 2,
c2446b3e 41 .colorspace = V4L2_COLORSPACE_SRGB,
a5df5c14 42 .priv = 4},
1250ac6d 43 {176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
00b27ce6 44 .bytesperline = 176,
1250ac6d 45 .sizeimage = 176 * 144 * 3 / 2,
c2446b3e 46 .colorspace = V4L2_COLORSPACE_SRGB,
a5df5c14 47 .priv = 3},
1250ac6d 48 {320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
00b27ce6 49 .bytesperline = 320,
1250ac6d 50 .sizeimage = 320 * 240 * 3 / 2,
c2446b3e
JFM
51 .colorspace = V4L2_COLORSPACE_SRGB,
52 .priv = 2},
1250ac6d 53 {352, 288, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
00b27ce6 54 .bytesperline = 352,
1250ac6d 55 .sizeimage = 352 * 288 * 3 / 2,
c2446b3e
JFM
56 .colorspace = V4L2_COLORSPACE_SRGB,
57 .priv = 1},
1250ac6d 58 {640, 480, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
00b27ce6 59 .bytesperline = 640,
1250ac6d 60 .sizeimage = 640 * 480 * 3 / 2,
c2446b3e
JFM
61 .colorspace = V4L2_COLORSPACE_SRGB,
62 .priv = 0},
6a7eba24
JFM
63};
64
65#define SPCA50X_OFFSET_DATA 10
66
67#define SPCA50X_REG_USB 0x02 /* spca505 501 */
68
69#define SPCA50X_USB_CTRL 0x00 /* spca505 */
70#define SPCA50X_CUSB_ENABLE 0x01 /* spca505 */
a5df5c14 71
6a7eba24
JFM
72#define SPCA50X_REG_GLOBAL 0x03 /* spca505 */
73#define SPCA50X_GMISC0_IDSEL 0x01 /* Global control device ID select spca505 */
74#define SPCA50X_GLOBAL_MISC0 0x00 /* Global control miscellaneous 0 spca505 */
75
76#define SPCA50X_GLOBAL_MISC1 0x01 /* 505 */
77#define SPCA50X_GLOBAL_MISC3 0x03 /* 505 */
78#define SPCA50X_GMISC3_SAA7113RST 0x20 /* Not sure about this one spca505 */
79
a5df5c14
JFM
80/* Image format and compression control */
81#define SPCA50X_REG_COMPRESS 0x04
82
6a7eba24
JFM
83/*
84 * Data to initialize a SPCA505. Common to the CCD and external modes
85 */
16631aed
JFM
86static const u8 spca505_init_data[][3] = {
87 /* bmRequest,value,index */
6a7eba24
JFM
88 {SPCA50X_REG_GLOBAL, SPCA50X_GMISC3_SAA7113RST, SPCA50X_GLOBAL_MISC3},
89 /* Sensor reset */
16631aed
JFM
90 {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC3},
91 {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC1},
6a7eba24 92 /* Block USB reset */
16631aed 93 {SPCA50X_REG_GLOBAL, SPCA50X_GMISC0_IDSEL, SPCA50X_GLOBAL_MISC0},
6a7eba24 94
16631aed 95 {0x05, 0x01, 0x10},
6a7eba24 96 /* Maybe power down some stuff */
16631aed 97 {0x05, 0x0f, 0x11},
6a7eba24
JFM
98
99 /* Setup internal CCD ? */
16631aed
JFM
100 {0x06, 0x10, 0x08},
101 {0x06, 0x00, 0x09},
102 {0x06, 0x00, 0x0a},
103 {0x06, 0x00, 0x0b},
104 {0x06, 0x10, 0x0c},
105 {0x06, 0x00, 0x0d},
106 {0x06, 0x00, 0x0e},
107 {0x06, 0x00, 0x0f},
108 {0x06, 0x10, 0x10},
109 {0x06, 0x02, 0x11},
110 {0x06, 0x00, 0x12},
111 {0x06, 0x04, 0x13},
112 {0x06, 0x02, 0x14},
113 {0x06, 0x8a, 0x51},
114 {0x06, 0x40, 0x52},
115 {0x06, 0xb6, 0x53},
116 {0x06, 0x3d, 0x54},
6a7eba24
JFM
117 {}
118};
119
120/*
121 * Data to initialize the camera using the internal CCD
122 */
16631aed
JFM
123static const u8 spca505_open_data_ccd[][3] = {
124 /* bmRequest,value,index */
6a7eba24 125 /* Internal CCD data set */
16631aed 126 {0x03, 0x04, 0x01},
6a7eba24 127 /* This could be a reset */
16631aed 128 {0x03, 0x00, 0x01},
6a7eba24
JFM
129
130 /* Setup compression and image registers. 0x6 and 0x7 seem to be
131 related to H&V hold, and are resolution mode specific */
16631aed 132 {0x04, 0x10, 0x01},
6a7eba24 133 /* DIFF(0x50), was (0x10) */
16631aed
JFM
134 {0x04, 0x00, 0x04},
135 {0x04, 0x00, 0x05},
136 {0x04, 0x20, 0x06},
137 {0x04, 0x20, 0x07},
6a7eba24 138
16631aed 139 {0x08, 0x0a, 0x00},
6a7eba24
JFM
140 /* DIFF (0x4a), was (0xa) */
141
16631aed
JFM
142 {0x05, 0x00, 0x10},
143 {0x05, 0x00, 0x11},
144 {0x05, 0x00, 0x00},
6a7eba24 145 /* DIFF not written */
16631aed 146 {0x05, 0x00, 0x01},
6a7eba24 147 /* DIFF not written */
16631aed 148 {0x05, 0x00, 0x02},
6a7eba24 149 /* DIFF not written */
16631aed 150 {0x05, 0x00, 0x03},
6a7eba24 151 /* DIFF not written */
16631aed 152 {0x05, 0x00, 0x04},
6a7eba24 153 /* DIFF not written */
16631aed 154 {0x05, 0x80, 0x05},
6a7eba24 155 /* DIFF not written */
16631aed 156 {0x05, 0xe0, 0x06},
6a7eba24 157 /* DIFF not written */
16631aed 158 {0x05, 0x20, 0x07},
6a7eba24 159 /* DIFF not written */
16631aed 160 {0x05, 0xa0, 0x08},
6a7eba24 161 /* DIFF not written */
16631aed 162 {0x05, 0x0, 0x12},
6a7eba24 163 /* DIFF not written */
16631aed 164 {0x05, 0x02, 0x0f},
6a7eba24 165 /* DIFF not written */
16631aed 166 {0x05, 0x10, 0x46},
6a7eba24 167 /* DIFF not written */
16631aed 168 {0x05, 0x8, 0x4a},
6a7eba24
JFM
169 /* DIFF not written */
170
16631aed 171 {0x03, 0x08, 0x03},
6a7eba24 172 /* DIFF (0x3,0x28,0x3) */
16631aed
JFM
173 {0x03, 0x08, 0x01},
174 {0x03, 0x0c, 0x03},
6a7eba24 175 /* DIFF not written */
16631aed 176 {0x03, 0x21, 0x00},
6a7eba24
JFM
177 /* DIFF (0x39) */
178
179/* Extra block copied from init to hopefully ensure CCD is in a sane state */
16631aed
JFM
180 {0x06, 0x10, 0x08},
181 {0x06, 0x00, 0x09},
182 {0x06, 0x00, 0x0a},
183 {0x06, 0x00, 0x0b},
184 {0x06, 0x10, 0x0c},
185 {0x06, 0x00, 0x0d},
186 {0x06, 0x00, 0x0e},
187 {0x06, 0x00, 0x0f},
188 {0x06, 0x10, 0x10},
189 {0x06, 0x02, 0x11},
190 {0x06, 0x00, 0x12},
191 {0x06, 0x04, 0x13},
192 {0x06, 0x02, 0x14},
193 {0x06, 0x8a, 0x51},
194 {0x06, 0x40, 0x52},
195 {0x06, 0xb6, 0x53},
196 {0x06, 0x3d, 0x54},
6a7eba24
JFM
197 /* End of extra block */
198
16631aed 199 {0x06, 0x3f, 0x1},
6a7eba24 200 /* Block skipped */
16631aed
JFM
201 {0x06, 0x10, 0x02},
202 {0x06, 0x64, 0x07},
203 {0x06, 0x10, 0x08},
204 {0x06, 0x00, 0x09},
205 {0x06, 0x00, 0x0a},
206 {0x06, 0x00, 0x0b},
207 {0x06, 0x10, 0x0c},
208 {0x06, 0x00, 0x0d},
209 {0x06, 0x00, 0x0e},
210 {0x06, 0x00, 0x0f},
211 {0x06, 0x10, 0x10},
212 {0x06, 0x02, 0x11},
213 {0x06, 0x00, 0x12},
214 {0x06, 0x04, 0x13},
215 {0x06, 0x02, 0x14},
216 {0x06, 0x8a, 0x51},
217 {0x06, 0x40, 0x52},
218 {0x06, 0xb6, 0x53},
219 {0x06, 0x3d, 0x54},
220 {0x06, 0x60, 0x57},
221 {0x06, 0x20, 0x58},
222 {0x06, 0x15, 0x59},
223 {0x06, 0x05, 0x5a},
224
225 {0x05, 0x01, 0xc0},
226 {0x05, 0x10, 0xcb},
227 {0x05, 0x80, 0xc1},
6a7eba24 228 /* */
16631aed 229 {0x05, 0x0, 0xc2},
6a7eba24 230 /* 4 was 0 */
16631aed
JFM
231 {0x05, 0x00, 0xca},
232 {0x05, 0x80, 0xc1},
6a7eba24 233 /* */
16631aed
JFM
234 {0x05, 0x04, 0xc2},
235 {0x05, 0x00, 0xca},
236 {0x05, 0x0, 0xc1},
6a7eba24 237 /* */
16631aed
JFM
238 {0x05, 0x00, 0xc2},
239 {0x05, 0x00, 0xca},
240 {0x05, 0x40, 0xc1},
6a7eba24 241 /* */
16631aed
JFM
242 {0x05, 0x17, 0xc2},
243 {0x05, 0x00, 0xca},
244 {0x05, 0x80, 0xc1},
6a7eba24 245 /* */
16631aed
JFM
246 {0x05, 0x06, 0xc2},
247 {0x05, 0x00, 0xca},
248 {0x05, 0x80, 0xc1},
6a7eba24 249 /* */
16631aed
JFM
250 {0x05, 0x04, 0xc2},
251 {0x05, 0x00, 0xca},
6a7eba24 252
16631aed
JFM
253 {0x03, 0x4c, 0x3},
254 {0x03, 0x18, 0x1},
6a7eba24 255
16631aed
JFM
256 {0x06, 0x70, 0x51},
257 {0x06, 0xbe, 0x53},
258 {0x06, 0x71, 0x57},
259 {0x06, 0x20, 0x58},
260 {0x06, 0x05, 0x59},
261 {0x06, 0x15, 0x5a},
6a7eba24 262
16631aed 263 {0x04, 0x00, 0x08},
6a7eba24 264 /* Compress = OFF (0x1 to turn on) */
16631aed
JFM
265 {0x04, 0x12, 0x09},
266 {0x04, 0x21, 0x0a},
267 {0x04, 0x10, 0x0b},
268 {0x04, 0x21, 0x0c},
269 {0x04, 0x05, 0x00},
6a7eba24 270 /* was 5 (Image Type ? ) */
16631aed
JFM
271 {0x04, 0x00, 0x01},
272
273 {0x06, 0x3f, 0x01},
274
275 {0x04, 0x00, 0x04},
276 {0x04, 0x00, 0x05},
277 {0x04, 0x40, 0x06},
278 {0x04, 0x40, 0x07},
279
280 {0x06, 0x1c, 0x17},
281 {0x06, 0xe2, 0x19},
282 {0x06, 0x1c, 0x1b},
283 {0x06, 0xe2, 0x1d},
284 {0x06, 0xaa, 0x1f},
285 {0x06, 0x70, 0x20},
286
287 {0x05, 0x01, 0x10},
288 {0x05, 0x00, 0x11},
289 {0x05, 0x01, 0x00},
290 {0x05, 0x05, 0x01},
291 {0x05, 0x00, 0xc1},
6a7eba24 292 /* */
16631aed
JFM
293 {0x05, 0x00, 0xc2},
294 {0x05, 0x00, 0xca},
6a7eba24 295
16631aed
JFM
296 {0x06, 0x70, 0x51},
297 {0x06, 0xbe, 0x53},
6a7eba24
JFM
298 {}
299};
300
301/*
16631aed 302 * Made by Tomasz Zablocki (skalamandra@poczta.onet.pl)
6a7eba24 303 * SPCA505b chip based cameras initialization data
6a7eba24
JFM
304 */
305/* jfm */
306#define initial_brightness 0x7f /* 0x0(white)-0xff(black) */
307/* #define initial_brightness 0x0 //0x0(white)-0xff(black) */
308/*
309 * Data to initialize a SPCA505. Common to the CCD and external modes
310 */
16631aed 311static const u8 spca505b_init_data[][3] = {
6a7eba24
JFM
312/* start */
313 {0x02, 0x00, 0x00}, /* init */
314 {0x02, 0x00, 0x01},
315 {0x02, 0x00, 0x02},
316 {0x02, 0x00, 0x03},
317 {0x02, 0x00, 0x04},
318 {0x02, 0x00, 0x05},
319 {0x02, 0x00, 0x06},
320 {0x02, 0x00, 0x07},
321 {0x02, 0x00, 0x08},
322 {0x02, 0x00, 0x09},
323 {0x03, 0x00, 0x00},
324 {0x03, 0x00, 0x01},
325 {0x03, 0x00, 0x02},
326 {0x03, 0x00, 0x03},
327 {0x03, 0x00, 0x04},
328 {0x03, 0x00, 0x05},
329 {0x03, 0x00, 0x06},
330 {0x04, 0x00, 0x00},
331 {0x04, 0x00, 0x02},
332 {0x04, 0x00, 0x04},
333 {0x04, 0x00, 0x05},
334 {0x04, 0x00, 0x06},
335 {0x04, 0x00, 0x07},
336 {0x04, 0x00, 0x08},
337 {0x04, 0x00, 0x09},
338 {0x04, 0x00, 0x0a},
339 {0x04, 0x00, 0x0b},
340 {0x04, 0x00, 0x0c},
341 {0x07, 0x00, 0x00},
342 {0x07, 0x00, 0x03},
343 {0x08, 0x00, 0x00},
344 {0x08, 0x00, 0x01},
345 {0x08, 0x00, 0x02},
6a7eba24
JFM
346 {0x06, 0x18, 0x08},
347 {0x06, 0xfc, 0x09},
348 {0x06, 0xfc, 0x0a},
349 {0x06, 0xfc, 0x0b},
350 {0x06, 0x18, 0x0c},
351 {0x06, 0xfc, 0x0d},
352 {0x06, 0xfc, 0x0e},
353 {0x06, 0xfc, 0x0f},
354 {0x06, 0x18, 0x10},
355 {0x06, 0xfe, 0x12},
356 {0x06, 0x00, 0x11},
357 {0x06, 0x00, 0x14},
358 {0x06, 0x00, 0x13},
359 {0x06, 0x28, 0x51},
360 {0x06, 0xff, 0x53},
361 {0x02, 0x00, 0x08},
362
363 {0x03, 0x00, 0x03},
364 {0x03, 0x10, 0x03},
365 {}
366};
367
368/*
369 * Data to initialize the camera using the internal CCD
370 */
16631aed 371static const u8 spca505b_open_data_ccd[][3] = {
6a7eba24
JFM
372
373/* {0x02,0x00,0x00}, */
374 {0x03, 0x04, 0x01}, /* rst */
375 {0x03, 0x00, 0x01},
376 {0x03, 0x00, 0x00},
377 {0x03, 0x21, 0x00},
378 {0x03, 0x00, 0x04},
379 {0x03, 0x00, 0x03},
380 {0x03, 0x18, 0x03},
381 {0x03, 0x08, 0x01},
382 {0x03, 0x1c, 0x03},
383 {0x03, 0x5c, 0x03},
384 {0x03, 0x5c, 0x03},
385 {0x03, 0x18, 0x01},
386
387/* same as 505 */
388 {0x04, 0x10, 0x01},
389 {0x04, 0x00, 0x04},
390 {0x04, 0x00, 0x05},
391 {0x04, 0x20, 0x06},
392 {0x04, 0x20, 0x07},
393
394 {0x08, 0x0a, 0x00},
395
396 {0x05, 0x00, 0x10},
397 {0x05, 0x00, 0x11},
398 {0x05, 0x00, 0x12},
399 {0x05, 0x6f, 0x00},
92e8c91b
JFM
400 {0x05, initial_brightness >> 6, 0x00},
401 {0x05, (initial_brightness << 2) & 0xff, 0x01},
6a7eba24
JFM
402 {0x05, 0x00, 0x02},
403 {0x05, 0x01, 0x03},
404 {0x05, 0x00, 0x04},
405 {0x05, 0x03, 0x05},
406 {0x05, 0xe0, 0x06},
407 {0x05, 0x20, 0x07},
408 {0x05, 0xa0, 0x08},
409 {0x05, 0x00, 0x12},
410 {0x05, 0x02, 0x0f},
16631aed 411 {0x05, 0x80, 0x14}, /* max exposure off (0=on) */
6a7eba24
JFM
412 {0x05, 0x01, 0xb0},
413 {0x05, 0x01, 0xbf},
414 {0x03, 0x02, 0x06},
415 {0x05, 0x10, 0x46},
416 {0x05, 0x08, 0x4a},
417
418 {0x06, 0x00, 0x01},
419 {0x06, 0x10, 0x02},
420 {0x06, 0x64, 0x07},
421 {0x06, 0x18, 0x08},
422 {0x06, 0xfc, 0x09},
423 {0x06, 0xfc, 0x0a},
424 {0x06, 0xfc, 0x0b},
425 {0x04, 0x00, 0x01},
426 {0x06, 0x18, 0x0c},
427 {0x06, 0xfc, 0x0d},
428 {0x06, 0xfc, 0x0e},
429 {0x06, 0xfc, 0x0f},
430 {0x06, 0x11, 0x10}, /* contrast */
431 {0x06, 0x00, 0x11},
432 {0x06, 0xfe, 0x12},
433 {0x06, 0x00, 0x13},
434 {0x06, 0x00, 0x14},
435 {0x06, 0x9d, 0x51},
436 {0x06, 0x40, 0x52},
437 {0x06, 0x7c, 0x53},
438 {0x06, 0x40, 0x54},
439 {0x06, 0x02, 0x57},
440 {0x06, 0x03, 0x58},
441 {0x06, 0x15, 0x59},
442 {0x06, 0x05, 0x5a},
443 {0x06, 0x03, 0x56},
444 {0x06, 0x02, 0x3f},
445 {0x06, 0x00, 0x40},
446 {0x06, 0x39, 0x41},
447 {0x06, 0x69, 0x42},
448 {0x06, 0x87, 0x43},
449 {0x06, 0x9e, 0x44},
450 {0x06, 0xb1, 0x45},
451 {0x06, 0xbf, 0x46},
452 {0x06, 0xcc, 0x47},
453 {0x06, 0xd5, 0x48},
454 {0x06, 0xdd, 0x49},
455 {0x06, 0xe3, 0x4a},
456 {0x06, 0xe8, 0x4b},
457 {0x06, 0xed, 0x4c},
458 {0x06, 0xf2, 0x4d},
459 {0x06, 0xf7, 0x4e},
460 {0x06, 0xfc, 0x4f},
461 {0x06, 0xff, 0x50},
462
463 {0x05, 0x01, 0xc0},
464 {0x05, 0x10, 0xcb},
465 {0x05, 0x40, 0xc1},
466 {0x05, 0x04, 0xc2},
467 {0x05, 0x00, 0xca},
468 {0x05, 0x40, 0xc1},
469 {0x05, 0x09, 0xc2},
470 {0x05, 0x00, 0xca},
471 {0x05, 0xc0, 0xc1},
472 {0x05, 0x09, 0xc2},
473 {0x05, 0x00, 0xca},
474 {0x05, 0x40, 0xc1},
475 {0x05, 0x59, 0xc2},
476 {0x05, 0x00, 0xca},
477 {0x04, 0x00, 0x01},
478 {0x05, 0x80, 0xc1},
479 {0x05, 0xec, 0xc2},
480 {0x05, 0x0, 0xca},
481
482 {0x06, 0x02, 0x57},
483 {0x06, 0x01, 0x58},
484 {0x06, 0x15, 0x59},
485 {0x06, 0x0a, 0x5a},
486 {0x06, 0x01, 0x57},
487 {0x06, 0x8a, 0x03},
488 {0x06, 0x0a, 0x6c},
489 {0x06, 0x30, 0x01},
490 {0x06, 0x20, 0x02},
491 {0x06, 0x00, 0x03},
492
493 {0x05, 0x8c, 0x25},
494
495 {0x06, 0x4d, 0x51}, /* maybe saturation (4d) */
496 {0x06, 0x84, 0x53}, /* making green (84) */
497 {0x06, 0x00, 0x57}, /* sharpness (1) */
498 {0x06, 0x18, 0x08},
499 {0x06, 0xfc, 0x09},
500 {0x06, 0xfc, 0x0a},
501 {0x06, 0xfc, 0x0b},
502 {0x06, 0x18, 0x0c}, /* maybe hue (18) */
503 {0x06, 0xfc, 0x0d},
504 {0x06, 0xfc, 0x0e},
505 {0x06, 0xfc, 0x0f},
506 {0x06, 0x18, 0x10}, /* maybe contrast (18) */
507
508 {0x05, 0x01, 0x02},
509
510 {0x04, 0x00, 0x08}, /* compression */
511 {0x04, 0x12, 0x09},
512 {0x04, 0x21, 0x0a},
513 {0x04, 0x10, 0x0b},
514 {0x04, 0x21, 0x0c},
515 {0x04, 0x1d, 0x00}, /* imagetype (1d) */
516 {0x04, 0x41, 0x01}, /* hardware snapcontrol */
517
518 {0x04, 0x00, 0x04},
519 {0x04, 0x00, 0x05},
520 {0x04, 0x10, 0x06},
521 {0x04, 0x10, 0x07},
522 {0x04, 0x40, 0x06},
523 {0x04, 0x40, 0x07},
524 {0x04, 0x00, 0x04},
525 {0x04, 0x00, 0x05},
526
527 {0x06, 0x1c, 0x17},
528 {0x06, 0xe2, 0x19},
529 {0x06, 0x1c, 0x1b},
530 {0x06, 0xe2, 0x1d},
531 {0x06, 0x5f, 0x1f},
532 {0x06, 0x32, 0x20},
533
92e8c91b
JFM
534 {0x05, initial_brightness >> 6, 0x00},
535 {0x05, (initial_brightness << 2) & 0xff, 0x01},
6a7eba24
JFM
536 {0x05, 0x06, 0xc1},
537 {0x05, 0x58, 0xc2},
16631aed
JFM
538 {0x05, 0x00, 0xca},
539 {0x05, 0x00, 0x11},
6a7eba24
JFM
540 {}
541};
542
c93396e1 543static int reg_write(struct gspca_dev *gspca_dev,
16631aed 544 u16 req, u16 index, u16 value)
6a7eba24
JFM
545{
546 int ret;
c93396e1 547 struct usb_device *dev = gspca_dev->dev;
6a7eba24
JFM
548
549 ret = usb_control_msg(dev,
550 usb_sndctrlpipe(dev, 0),
16631aed 551 req,
6a7eba24
JFM
552 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
553 value, index, NULL, 0, 500);
16631aed
JFM
554 PDEBUG(D_USBO, "reg write: 0x%02x,0x%02x:0x%02x, %d",
555 req, index, value, ret);
6a7eba24 556 if (ret < 0)
133a9fe9 557 pr_err("reg write: error %d\n", ret);
6a7eba24
JFM
558 return ret;
559}
560
561/* returns: negative is error, pos or zero is data */
739570bb 562static int reg_read(struct gspca_dev *gspca_dev,
16631aed
JFM
563 u16 req, /* bRequest */
564 u16 index) /* wIndex */
6a7eba24
JFM
565{
566 int ret;
6a7eba24 567
739570bb
JFM
568 ret = usb_control_msg(gspca_dev->dev,
569 usb_rcvctrlpipe(gspca_dev->dev, 0),
16631aed 570 req,
6a7eba24 571 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
16631aed
JFM
572 0, /* value */
573 index,
574 gspca_dev->usb_buf, 2,
6a7eba24 575 500); /* timeout */
16631aed
JFM
576 if (ret < 0)
577 return ret;
739570bb 578 return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
6a7eba24
JFM
579}
580
581static int write_vector(struct gspca_dev *gspca_dev,
16631aed 582 const u8 data[][3])
6a7eba24 583{
6a7eba24
JFM
584 int ret, i = 0;
585
16631aed 586 while (data[i][0] != 0) {
c93396e1
TK
587 ret = reg_write(gspca_dev, data[i][0], data[i][2],
588 data[i][1]);
16631aed 589 if (ret < 0)
6a7eba24 590 return ret;
6a7eba24
JFM
591 i++;
592 }
593 return 0;
594}
595
596/* this function is called at probe time */
597static int sd_config(struct gspca_dev *gspca_dev,
598 const struct usb_device_id *id)
599{
600 struct sd *sd = (struct sd *) gspca_dev;
601 struct cam *cam;
6a7eba24
JFM
602
603 cam = &gspca_dev->cam;
6a7eba24 604 cam->cam_mode = vga_mode;
9d64fdb1 605 sd->subtype = id->driver_info;
6a7eba24 606 if (sd->subtype != IntelPCCameraPro)
16631aed 607 cam->nmodes = ARRAY_SIZE(vga_mode);
6a7eba24 608 else /* no 640x480 for IntelPCCameraPro */
16631aed 609 cam->nmodes = ARRAY_SIZE(vga_mode) - 1;
6a7eba24 610
6a7eba24
JFM
611 return 0;
612}
613
012d6b02
JFM
614/* this function is called at probe and resume time */
615static int sd_init(struct gspca_dev *gspca_dev)
6a7eba24 616{
253f13d5
JFM
617 struct sd *sd = (struct sd *) gspca_dev;
618
619 if (write_vector(gspca_dev,
620 sd->subtype == Nxultra
621 ? spca505b_init_data
622 : spca505_init_data))
623 return -EIO;
6a7eba24
JFM
624 return 0;
625}
626
2aed6c1b 627static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness)
a5df5c14 628{
c93396e1
TK
629 reg_write(gspca_dev, 0x05, 0x00, (255 - brightness) >> 6);
630 reg_write(gspca_dev, 0x05, 0x01, (255 - brightness) << 2);
a5df5c14
JFM
631}
632
72ab97ce 633static int sd_start(struct gspca_dev *gspca_dev)
6a7eba24 634{
1de1ddf3 635 struct sd *sd = (struct sd *) gspca_dev;
a5df5c14
JFM
636 int ret, mode;
637 static u8 mode_tb[][3] = {
638 /* r00 r06 r07 */
639 {0x00, 0x10, 0x10}, /* 640x480 */
640 {0x01, 0x1a, 0x1a}, /* 352x288 */
641 {0x02, 0x1c, 0x1d}, /* 320x240 */
642 {0x04, 0x34, 0x34}, /* 176x144 */
643 {0x05, 0x40, 0x40} /* 160x120 */
644 };
6a7eba24 645
1de1ddf3
JFM
646 if (sd->subtype == Nxultra)
647 write_vector(gspca_dev, spca505b_open_data_ccd);
648 else
649 write_vector(gspca_dev, spca505_open_data_ccd);
650 ret = reg_read(gspca_dev, 0x06, 0x16);
651
652 if (ret < 0) {
c93396e1 653 PERR("register read failed err: %d", ret);
1de1ddf3
JFM
654 return ret;
655 }
656 if (ret != 0x0101) {
133a9fe9
JP
657 pr_err("After vector read returns 0x%04x should be 0x0101\n",
658 ret);
1de1ddf3
JFM
659 }
660
c93396e1 661 ret = reg_write(gspca_dev, 0x06, 0x16, 0x0a);
1de1ddf3
JFM
662 if (ret < 0)
663 return ret;
c93396e1 664 reg_write(gspca_dev, 0x05, 0xc2, 0x12);
1de1ddf3 665
6a7eba24
JFM
666 /* necessary because without it we can see stream
667 * only once after loading module */
668 /* stopping usb registers Tomasz change */
c93396e1 669 reg_write(gspca_dev, 0x02, 0x00, 0x00);
a5df5c14
JFM
670
671 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
c93396e1
TK
672 reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x00, mode_tb[mode][0]);
673 reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x06, mode_tb[mode][1]);
674 reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x07, mode_tb[mode][2]);
a5df5c14 675
c93396e1 676 return reg_write(gspca_dev, SPCA50X_REG_USB,
6a7eba24
JFM
677 SPCA50X_USB_CTRL,
678 SPCA50X_CUSB_ENABLE);
6a7eba24
JFM
679}
680
681static void sd_stopN(struct gspca_dev *gspca_dev)
682{
683 /* Disable ISO packet machine */
c93396e1 684 reg_write(gspca_dev, 0x02, 0x00, 0x00);
6a7eba24
JFM
685}
686
98522a7b 687/* called on streamoff with alt 0 and on disconnect */
6a7eba24 688static void sd_stop0(struct gspca_dev *gspca_dev)
6a7eba24 689{
98522a7b
JFM
690 if (!gspca_dev->present)
691 return;
692
6a7eba24 693 /* This maybe reset or power control */
c93396e1
TK
694 reg_write(gspca_dev, 0x03, 0x03, 0x20);
695 reg_write(gspca_dev, 0x03, 0x01, 0x00);
696 reg_write(gspca_dev, 0x03, 0x00, 0x01);
697 reg_write(gspca_dev, 0x05, 0x10, 0x01);
698 reg_write(gspca_dev, 0x05, 0x11, 0x0f);
6a7eba24
JFM
699}
700
6a7eba24 701static void sd_pkt_scan(struct gspca_dev *gspca_dev,
16631aed 702 u8 *data, /* isoc packet */
6a7eba24
JFM
703 int len) /* iso packet length */
704{
6a7eba24
JFM
705 switch (data[0]) {
706 case 0: /* start of frame */
76dd272b 707 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
6a7eba24
JFM
708 data += SPCA50X_OFFSET_DATA;
709 len -= SPCA50X_OFFSET_DATA;
76dd272b 710 gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
1250ac6d 711 break;
6a7eba24 712 case 0xff: /* drop */
1250ac6d
JFM
713 break;
714 default:
715 data += 1;
716 len -= 1;
76dd272b 717 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1250ac6d 718 break;
6a7eba24 719 }
6a7eba24
JFM
720}
721
2aed6c1b 722static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
6a7eba24 723{
2aed6c1b
HV
724 struct gspca_dev *gspca_dev =
725 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
6a7eba24 726
2aed6c1b
HV
727 gspca_dev->usb_err = 0;
728
729 if (!gspca_dev->streaming)
730 return 0;
731
732 switch (ctrl->id) {
733 case V4L2_CID_BRIGHTNESS:
734 setbrightness(gspca_dev, ctrl->val);
735 break;
736 }
737 return gspca_dev->usb_err;
6a7eba24
JFM
738}
739
2aed6c1b
HV
740static const struct v4l2_ctrl_ops sd_ctrl_ops = {
741 .s_ctrl = sd_s_ctrl,
742};
743
744static int sd_init_controls(struct gspca_dev *gspca_dev)
6a7eba24 745{
2aed6c1b 746 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
6a7eba24 747
2aed6c1b
HV
748 gspca_dev->vdev.ctrl_handler = hdl;
749 v4l2_ctrl_handler_init(hdl, 5);
750 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
751 V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
752
753 if (hdl->error) {
754 pr_err("Could not initialize controls\n");
755 return hdl->error;
756 }
6a7eba24
JFM
757 return 0;
758}
759
760/* sub-driver description */
a5ae2062 761static const struct sd_desc sd_desc = {
6a7eba24 762 .name = MODULE_NAME,
6a7eba24 763 .config = sd_config,
2aed6c1b 764 .init_controls = sd_init_controls,
012d6b02 765 .init = sd_init,
6a7eba24
JFM
766 .start = sd_start,
767 .stopN = sd_stopN,
768 .stop0 = sd_stop0,
6a7eba24
JFM
769 .pkt_scan = sd_pkt_scan,
770};
771
772/* -- module initialisation -- */
95c967c1 773static const struct usb_device_id device_table[] = {
87581aa5
JFM
774 {USB_DEVICE(0x041e, 0x401d), .driver_info = Nxultra},
775 {USB_DEVICE(0x0733, 0x0430), .driver_info = IntelPCCameraPro},
9d64fdb1 776/*fixme: may be UsbGrabberPV321 BRIDGE_SPCA506 SENSOR_SAA7113 */
6a7eba24
JFM
777 {}
778};
779MODULE_DEVICE_TABLE(usb, device_table);
780
781/* -- device connect -- */
782static int sd_probe(struct usb_interface *intf,
783 const struct usb_device_id *id)
784{
956e42d2 785 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
6a7eba24
JFM
786 THIS_MODULE);
787}
788
789static struct usb_driver sd_driver = {
790 .name = MODULE_NAME,
791 .id_table = device_table,
792 .probe = sd_probe,
793 .disconnect = gspca_disconnect,
6a709749
JFM
794#ifdef CONFIG_PM
795 .suspend = gspca_suspend,
796 .resume = gspca_resume,
8bb58964 797 .reset_resume = gspca_resume,
6a709749 798#endif
6a7eba24
JFM
799};
800
ecb3b2b3 801module_usb_driver(sd_driver);