V4L/DVB (8517): gspca: Bad sensor for some webcams in zc3xx since 28b8203a830e.
[deliverable/linux.git] / drivers / media / video / gspca / spca506.c
CommitLineData
6a7eba24
JFM
1/*
2 * SPCA506 chip based cameras function
3 * M Xhaard 15/04/2004 based on different work Mark Taylor and others
4 * and my own snoopy file on a pv-321c donate by a german compagny
5 * "Firma Frank Gmbh" from Saarbruecken
6 *
7 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#define MODULE_NAME "spca506"
25
26#include "gspca.h"
27
6a7eba24
JFM
28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver");
30MODULE_LICENSE("GPL");
31
32/* specific webcam descriptor */
33struct sd {
c2446b3e 34 struct gspca_dev gspca_dev; /* !! must be the first item */
6a7eba24
JFM
35
36 int buflen;
c2446b3e
JFM
37 __u8 tmpbuf[640 * 480 * 3]; /* YYUV per line */
38 __u8 tmpbuf2[640 * 480 * 2]; /* YUYV */
6a7eba24
JFM
39
40 unsigned char brightness;
41 unsigned char contrast;
42 unsigned char colors;
43 unsigned char hue;
44 char norme;
45 char channel;
46};
47
48/* V4L2 controls supported by the driver */
49static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
50static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
51static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
52static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
53static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
54static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
55static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
56static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
57
58static struct ctrl sd_ctrls[] = {
59#define SD_BRIGHTNESS 0
60 {
61 {
62 .id = V4L2_CID_BRIGHTNESS,
63 .type = V4L2_CTRL_TYPE_INTEGER,
64 .name = "Brightness",
65 .minimum = 0,
66 .maximum = 0xff,
67 .step = 1,
68 .default_value = 0x80,
69 },
70 .set = sd_setbrightness,
71 .get = sd_getbrightness,
72 },
73#define SD_CONTRAST 1
74 {
75 {
76 .id = V4L2_CID_CONTRAST,
77 .type = V4L2_CTRL_TYPE_INTEGER,
78 .name = "Contrast",
79 .minimum = 0,
80 .maximum = 0xff,
81 .step = 1,
82 .default_value = 0x47,
83 },
84 .set = sd_setcontrast,
85 .get = sd_getcontrast,
86 },
87#define SD_COLOR 2
88 {
89 {
90 .id = V4L2_CID_SATURATION,
91 .type = V4L2_CTRL_TYPE_INTEGER,
92 .name = "Saturation",
93 .minimum = 0,
94 .maximum = 0xff,
95 .step = 1,
96 .default_value = 0x40,
97 },
98 .set = sd_setcolors,
99 .get = sd_getcolors,
100 },
101#define SD_HUE 3
102 {
103 {
104 .id = V4L2_CID_HUE,
105 .type = V4L2_CTRL_TYPE_INTEGER,
106 .name = "Hue",
107 .minimum = 0,
108 .maximum = 0xff,
109 .step = 1,
110 .default_value = 0,
111 },
112 .set = sd_sethue,
113 .get = sd_gethue,
114 },
115};
116
c2446b3e
JFM
117static struct v4l2_pix_format vga_mode[] = {
118 {160, 120, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
119 .bytesperline = 160 * 2,
120 .sizeimage = 160 * 120 * 2,
121 .colorspace = V4L2_COLORSPACE_SRGB,
122 .priv = 5},
123 {176, 144, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
124 .bytesperline = 176 * 2,
125 .sizeimage = 176 * 144 * 2,
126 .colorspace = V4L2_COLORSPACE_SRGB,
127 .priv = 4},
128 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
129 .bytesperline = 320 * 2,
130 .sizeimage = 320 * 240 * 2,
131 .colorspace = V4L2_COLORSPACE_SRGB,
132 .priv = 2},
133 {352, 288, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
134 .bytesperline = 352 * 2,
135 .sizeimage = 352 * 288 * 2,
136 .colorspace = V4L2_COLORSPACE_SRGB,
137 .priv = 1},
138 {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
139 .bytesperline = 640 * 2,
140 .sizeimage = 640 * 480 * 2,
141 .colorspace = V4L2_COLORSPACE_SRGB,
142 .priv = 0},
6a7eba24
JFM
143};
144
145#define SPCA50X_OFFSET_DATA 10
146
147#define SAA7113_bright 0x0a /* defaults 0x80 */
148#define SAA7113_contrast 0x0b /* defaults 0x47 */
149#define SAA7113_saturation 0x0c /* defaults 0x40 */
150#define SAA7113_hue 0x0d /* defaults 0x00 */
151#define SAA7113_I2C_BASE_WRITE 0x4a
152
739570bb
JFM
153/* read 'len' bytes to gspca_dev->usb_buf */
154static void reg_r(struct gspca_dev *gspca_dev,
6a7eba24
JFM
155 __u16 req,
156 __u16 index,
739570bb 157 __u16 length)
6a7eba24 158{
739570bb
JFM
159 usb_control_msg(gspca_dev->dev,
160 usb_rcvctrlpipe(gspca_dev->dev, 0),
6a7eba24
JFM
161 req,
162 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
163 0, /* value */
739570bb 164 index, gspca_dev->usb_buf, length,
6a7eba24
JFM
165 500);
166}
167
168static void reg_w(struct usb_device *dev,
169 __u16 req,
170 __u16 value,
171 __u16 index)
172{
173 usb_control_msg(dev,
174 usb_sndctrlpipe(dev, 0),
175 req,
176 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
177 value, index,
178 NULL, 0, 500);
179}
180
181static void spca506_Initi2c(struct gspca_dev *gspca_dev)
182{
183 reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
184}
185
186static void spca506_WriteI2c(struct gspca_dev *gspca_dev, __u16 valeur,
187 __u16 reg)
188{
189 int retry = 60;
6a7eba24
JFM
190
191 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
192 reg_w(gspca_dev->dev, 0x07, valeur, 0x0000);
193 while (retry--) {
739570bb
JFM
194 reg_r(gspca_dev, 0x07, 0x0003, 2);
195 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
6a7eba24
JFM
196 break;
197 }
198}
199
200static int spca506_ReadI2c(struct gspca_dev *gspca_dev, __u16 reg)
201{
202 int retry = 60;
6a7eba24
JFM
203
204 reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
205 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
206 reg_w(gspca_dev->dev, 0x07, 0x01, 0x0002);
207 while (--retry) {
739570bb
JFM
208 reg_r(gspca_dev, 0x07, 0x0003, 2);
209 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
6a7eba24
JFM
210 break;
211 }
212 if (retry == 0)
213 return -1;
739570bb
JFM
214 reg_r(gspca_dev, 0x07, 0x0000, 1);
215 return gspca_dev->usb_buf[0];
6a7eba24
JFM
216}
217
218static void spca506_SetNormeInput(struct gspca_dev *gspca_dev,
219 __u16 norme,
220 __u16 channel)
221{
222 struct sd *sd = (struct sd *) gspca_dev;
223/* fixme: check if channel == 0..3 and 6..9 (8 values) */
224 __u8 setbit0 = 0x00;
225 __u8 setbit1 = 0x00;
226 __u8 videomask = 0x00;
227
228 PDEBUG(D_STREAM, "** Open Set Norme **");
229 spca506_Initi2c(gspca_dev);
230 /* NTSC bit0 -> 1(525 l) PAL SECAM bit0 -> 0 (625 l) */
231 /* Composite channel bit1 -> 1 S-video bit 1 -> 0 */
232 /* and exclude SAA7113 reserved channel set default 0 otherwise */
233 if (norme & V4L2_STD_NTSC)
234 setbit0 = 0x01;
235 if (channel == 4 || channel == 5 || channel > 9)
236 channel = 0;
237 if (channel < 4)
238 setbit1 = 0x02;
239 videomask = (0x48 | setbit0 | setbit1);
240 reg_w(gspca_dev->dev, 0x08, videomask, 0x0000);
241 spca506_WriteI2c(gspca_dev, (0xc0 | (channel & 0x0F)), 0x02);
242
243 if (norme & V4L2_STD_NTSC)
244 spca506_WriteI2c(gspca_dev, 0x33, 0x0e);
245 /* Chrominance Control NTSC N */
246 else if (norme & V4L2_STD_SECAM)
247 spca506_WriteI2c(gspca_dev, 0x53, 0x0e);
248 /* Chrominance Control SECAM */
249 else
250 spca506_WriteI2c(gspca_dev, 0x03, 0x0e);
251 /* Chrominance Control PAL BGHIV */
252
253 sd->norme = norme;
254 sd->channel = channel;
255 PDEBUG(D_STREAM, "Set Video Byte to 0x%2x", videomask);
256 PDEBUG(D_STREAM, "Set Norme: %08x Channel %d", norme, channel);
257}
258
259static void spca506_GetNormeInput(struct gspca_dev *gspca_dev,
260 __u16 *norme, __u16 *channel)
261{
262 struct sd *sd = (struct sd *) gspca_dev;
263
264 /* Read the register is not so good value change so
265 we use your own copy in spca50x struct */
266 *norme = sd->norme;
267 *channel = sd->channel;
268 PDEBUG(D_STREAM, "Get Norme: %d Channel %d", *norme, *channel);
269}
270
271static void spca506_Setsize(struct gspca_dev *gspca_dev, __u16 code,
272 __u16 xmult, __u16 ymult)
273{
274 struct usb_device *dev = gspca_dev->dev;
275
276 PDEBUG(D_STREAM, "** SetSize **");
277 reg_w(dev, 0x04, (0x18 | (code & 0x07)), 0x0000);
278 /* Soft snap 0x40 Hard 0x41 */
279 reg_w(dev, 0x04, 0x41, 0x0001);
280 reg_w(dev, 0x04, 0x00, 0x0002);
281 /* reserved */
282 reg_w(dev, 0x04, 0x00, 0x0003);
283
284 /* reserved */
285 reg_w(dev, 0x04, 0x00, 0x0004);
286 /* reserved */
287 reg_w(dev, 0x04, 0x01, 0x0005);
288 /* reserced */
289 reg_w(dev, 0x04, xmult, 0x0006);
290 /* reserved */
291 reg_w(dev, 0x04, ymult, 0x0007);
292 /* compression 1 */
293 reg_w(dev, 0x04, 0x00, 0x0008);
294 /* T=64 -> 2 */
295 reg_w(dev, 0x04, 0x00, 0x0009);
296 /* threshold2D */
297 reg_w(dev, 0x04, 0x21, 0x000a);
298 /* quantization */
299 reg_w(dev, 0x04, 0x00, 0x000b);
300}
301
302/* this function is called at probe time */
303static int sd_config(struct gspca_dev *gspca_dev,
304 const struct usb_device_id *id)
305{
306 struct sd *sd = (struct sd *) gspca_dev;
307 struct cam *cam;
308
309 cam = &gspca_dev->cam;
6a7eba24
JFM
310 cam->epaddr = 0x01;
311 cam->cam_mode = vga_mode;
312 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
313 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
314 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
315 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
316 sd->hue = sd_ctrls[SD_HUE].qctrl.default_value;
317 return 0;
318}
319
320/* this function is called at open time */
321static int sd_open(struct gspca_dev *gspca_dev)
322{
323 struct usb_device *dev = gspca_dev->dev;
324
325 reg_w(dev, 0x03, 0x00, 0x0004);
326 reg_w(dev, 0x03, 0xFF, 0x0003);
327 reg_w(dev, 0x03, 0x00, 0x0000);
328 reg_w(dev, 0x03, 0x1c, 0x0001);
329 reg_w(dev, 0x03, 0x18, 0x0001);
330 /* Init on PAL and composite input0 */
331 spca506_SetNormeInput(gspca_dev, 0, 0);
332 reg_w(dev, 0x03, 0x1c, 0x0001);
333 reg_w(dev, 0x03, 0x18, 0x0001);
334 reg_w(dev, 0x05, 0x00, 0x0000);
335 reg_w(dev, 0x05, 0xef, 0x0001);
336 reg_w(dev, 0x05, 0x00, 0x00c1);
337 reg_w(dev, 0x05, 0x00, 0x00c2);
338 reg_w(dev, 0x06, 0x18, 0x0002);
339 reg_w(dev, 0x06, 0xf5, 0x0011);
340 reg_w(dev, 0x06, 0x02, 0x0012);
341 reg_w(dev, 0x06, 0xfb, 0x0013);
342 reg_w(dev, 0x06, 0x00, 0x0014);
343 reg_w(dev, 0x06, 0xa4, 0x0051);
344 reg_w(dev, 0x06, 0x40, 0x0052);
345 reg_w(dev, 0x06, 0x71, 0x0053);
346 reg_w(dev, 0x06, 0x40, 0x0054);
347 /************************************************/
348 reg_w(dev, 0x03, 0x00, 0x0004);
349 reg_w(dev, 0x03, 0x00, 0x0003);
350 reg_w(dev, 0x03, 0x00, 0x0004);
351 reg_w(dev, 0x03, 0xFF, 0x0003);
352 reg_w(dev, 0x02, 0x00, 0x0000);
353 reg_w(dev, 0x03, 0x60, 0x0000);
354 reg_w(dev, 0x03, 0x18, 0x0001);
355 /* for a better reading mx :) */
356 /*sdca506_WriteI2c(value,register) */
357 spca506_Initi2c(gspca_dev);
358 spca506_WriteI2c(gspca_dev, 0x08, 0x01);
359 spca506_WriteI2c(gspca_dev, 0xc0, 0x02);
360 /* input composite video */
361 spca506_WriteI2c(gspca_dev, 0x33, 0x03);
362 spca506_WriteI2c(gspca_dev, 0x00, 0x04);
363 spca506_WriteI2c(gspca_dev, 0x00, 0x05);
364 spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
365 spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
366 spca506_WriteI2c(gspca_dev, 0x98, 0x08);
367 spca506_WriteI2c(gspca_dev, 0x03, 0x09);
368 spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
369 spca506_WriteI2c(gspca_dev, 0x47, 0x0b);
370 spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
371 spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
372 spca506_WriteI2c(gspca_dev, 0x03, 0x0e); /* Chroma Pal adjust */
373 spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
374 spca506_WriteI2c(gspca_dev, 0x00, 0x10);
375 spca506_WriteI2c(gspca_dev, 0x0c, 0x11);
376 spca506_WriteI2c(gspca_dev, 0xb8, 0x12);
377 spca506_WriteI2c(gspca_dev, 0x01, 0x13);
378 spca506_WriteI2c(gspca_dev, 0x00, 0x14);
379 spca506_WriteI2c(gspca_dev, 0x00, 0x15);
380 spca506_WriteI2c(gspca_dev, 0x00, 0x16);
381 spca506_WriteI2c(gspca_dev, 0x00, 0x17);
382 spca506_WriteI2c(gspca_dev, 0x00, 0x18);
383 spca506_WriteI2c(gspca_dev, 0x00, 0x19);
384 spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
385 spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
386 spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
387 spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
388 spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
389 spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
390 spca506_WriteI2c(gspca_dev, 0x02, 0x40);
391 spca506_WriteI2c(gspca_dev, 0xff, 0x41);
392 spca506_WriteI2c(gspca_dev, 0xff, 0x42);
393 spca506_WriteI2c(gspca_dev, 0xff, 0x43);
394 spca506_WriteI2c(gspca_dev, 0xff, 0x44);
395 spca506_WriteI2c(gspca_dev, 0xff, 0x45);
396 spca506_WriteI2c(gspca_dev, 0xff, 0x46);
397 spca506_WriteI2c(gspca_dev, 0xff, 0x47);
398 spca506_WriteI2c(gspca_dev, 0xff, 0x48);
399 spca506_WriteI2c(gspca_dev, 0xff, 0x49);
400 spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
401 spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
402 spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
403 spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
404 spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
405 spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
406 spca506_WriteI2c(gspca_dev, 0xff, 0x50);
407 spca506_WriteI2c(gspca_dev, 0xff, 0x51);
408 spca506_WriteI2c(gspca_dev, 0xff, 0x52);
409 spca506_WriteI2c(gspca_dev, 0xff, 0x53);
410 spca506_WriteI2c(gspca_dev, 0xff, 0x54);
411 spca506_WriteI2c(gspca_dev, 0xff, 0x55);
412 spca506_WriteI2c(gspca_dev, 0xff, 0x56);
413 spca506_WriteI2c(gspca_dev, 0xff, 0x57);
414 spca506_WriteI2c(gspca_dev, 0x00, 0x58);
415 spca506_WriteI2c(gspca_dev, 0x54, 0x59);
416 spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
417 spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
418 spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
419 spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
420 spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
421 spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
422 spca506_WriteI2c(gspca_dev, 0x00, 0x60);
423 spca506_WriteI2c(gspca_dev, 0x05, 0x61);
424 spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
425 PDEBUG(D_STREAM, "** Close Init *");
426 return 0;
427}
428
429static void sd_start(struct gspca_dev *gspca_dev)
430{
431 struct usb_device *dev = gspca_dev->dev;
432 __u16 norme;
433 __u16 channel;
6a7eba24
JFM
434
435 /**************************************/
436 reg_w(dev, 0x03, 0x00, 0x0004);
437 reg_w(dev, 0x03, 0x00, 0x0003);
438 reg_w(dev, 0x03, 0x00, 0x0004);
439 reg_w(dev, 0x03, 0xFF, 0x0003);
440 reg_w(dev, 0x02, 0x00, 0x0000);
441 reg_w(dev, 0x03, 0x60, 0x0000);
442 reg_w(dev, 0x03, 0x18, 0x0001);
443
444 /*sdca506_WriteI2c(value,register) */
445 spca506_Initi2c(gspca_dev);
446 spca506_WriteI2c(gspca_dev, 0x08, 0x01); /* Increment Delay */
447/* spca506_WriteI2c(gspca_dev, 0xc0, 0x02); * Analog Input Control 1 */
448 spca506_WriteI2c(gspca_dev, 0x33, 0x03);
449 /* Analog Input Control 2 */
450 spca506_WriteI2c(gspca_dev, 0x00, 0x04);
451 /* Analog Input Control 3 */
452 spca506_WriteI2c(gspca_dev, 0x00, 0x05);
453 /* Analog Input Control 4 */
454 spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
455 /* Horizontal Sync Start 0xe9-0x0d */
456 spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
457 /* Horizontal Sync Stop 0x0d-0xf0 */
458
459 spca506_WriteI2c(gspca_dev, 0x98, 0x08); /* Sync Control */
460/* Defaults value */
461 spca506_WriteI2c(gspca_dev, 0x03, 0x09); /* Luminance Control */
462 spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
463 /* Luminance Brightness */
464 spca506_WriteI2c(gspca_dev, 0x47, 0x0b); /* Luminance Contrast */
465 spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
466 /* Chrominance Saturation */
467 spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
468 /* Chrominance Hue Control */
469 spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
470 /* Chrominance Gain Control */
471 /**************************************/
472 spca506_WriteI2c(gspca_dev, 0x00, 0x10);
473 /* Format/Delay Control */
474 spca506_WriteI2c(gspca_dev, 0x0c, 0x11); /* Output Control 1 */
475 spca506_WriteI2c(gspca_dev, 0xb8, 0x12); /* Output Control 2 */
476 spca506_WriteI2c(gspca_dev, 0x01, 0x13); /* Output Control 3 */
477 spca506_WriteI2c(gspca_dev, 0x00, 0x14); /* reserved */
478 spca506_WriteI2c(gspca_dev, 0x00, 0x15); /* VGATE START */
479 spca506_WriteI2c(gspca_dev, 0x00, 0x16); /* VGATE STOP */
480 spca506_WriteI2c(gspca_dev, 0x00, 0x17); /* VGATE Control (MSB) */
481 spca506_WriteI2c(gspca_dev, 0x00, 0x18);
482 spca506_WriteI2c(gspca_dev, 0x00, 0x19);
483 spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
484 spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
485 spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
486 spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
487 spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
488 spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
489 spca506_WriteI2c(gspca_dev, 0x02, 0x40);
490 spca506_WriteI2c(gspca_dev, 0xff, 0x41);
491 spca506_WriteI2c(gspca_dev, 0xff, 0x42);
492 spca506_WriteI2c(gspca_dev, 0xff, 0x43);
493 spca506_WriteI2c(gspca_dev, 0xff, 0x44);
494 spca506_WriteI2c(gspca_dev, 0xff, 0x45);
495 spca506_WriteI2c(gspca_dev, 0xff, 0x46);
496 spca506_WriteI2c(gspca_dev, 0xff, 0x47);
497 spca506_WriteI2c(gspca_dev, 0xff, 0x48);
498 spca506_WriteI2c(gspca_dev, 0xff, 0x49);
499 spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
500 spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
501 spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
502 spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
503 spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
504 spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
505 spca506_WriteI2c(gspca_dev, 0xff, 0x50);
506 spca506_WriteI2c(gspca_dev, 0xff, 0x51);
507 spca506_WriteI2c(gspca_dev, 0xff, 0x52);
508 spca506_WriteI2c(gspca_dev, 0xff, 0x53);
509 spca506_WriteI2c(gspca_dev, 0xff, 0x54);
510 spca506_WriteI2c(gspca_dev, 0xff, 0x55);
511 spca506_WriteI2c(gspca_dev, 0xff, 0x56);
512 spca506_WriteI2c(gspca_dev, 0xff, 0x57);
513 spca506_WriteI2c(gspca_dev, 0x00, 0x58);
514 spca506_WriteI2c(gspca_dev, 0x54, 0x59);
515 spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
516 spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
517 spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
518 spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
519 spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
520 spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
521 spca506_WriteI2c(gspca_dev, 0x00, 0x60);
522 spca506_WriteI2c(gspca_dev, 0x05, 0x61);
523 spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
524 /**************************************/
525 reg_w(dev, 0x05, 0x00, 0x0003);
526 reg_w(dev, 0x05, 0x00, 0x0004);
527 reg_w(dev, 0x03, 0x10, 0x0001);
528 reg_w(dev, 0x03, 0x78, 0x0000);
c2446b3e 529 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
6a7eba24
JFM
530 case 0:
531 spca506_Setsize(gspca_dev, 0, 0x10, 0x10);
532 break;
533 case 1:
534 spca506_Setsize(gspca_dev, 1, 0x1a, 0x1a);
535 break;
536 case 2:
537 spca506_Setsize(gspca_dev, 2, 0x1c, 0x1c);
538 break;
539 case 4:
540 spca506_Setsize(gspca_dev, 4, 0x34, 0x34);
541 break;
542 default:
543/* case 5: */
544 spca506_Setsize(gspca_dev, 5, 0x40, 0x40);
545 break;
546 }
547
548 /* compress setting and size */
549 /* set i2c luma */
550 reg_w(dev, 0x02, 0x01, 0x0000);
739570bb
JFM
551 reg_w(dev, 0x03, 0x12, 0x0000);
552 reg_r(gspca_dev, 0x04, 0x0001, 2);
6a7eba24
JFM
553 PDEBUG(D_STREAM, "webcam started");
554 spca506_GetNormeInput(gspca_dev, &norme, &channel);
555 spca506_SetNormeInput(gspca_dev, norme, channel);
556}
557
558static void sd_stopN(struct gspca_dev *gspca_dev)
559{
560 struct usb_device *dev = gspca_dev->dev;
561
562 reg_w(dev, 0x02, 0x00, 0x0000);
563 reg_w(dev, 0x03, 0x00, 0x0004);
564 reg_w(dev, 0x03, 0x00, 0x0003);
565}
566
567static void sd_stop0(struct gspca_dev *gspca_dev)
568{
569}
570
571static void sd_close(struct gspca_dev *gspca_dev)
572{
573}
574
575/* convert YYUV per line to YUYV (YUV 4:2:2) */
576static void yyuv_decode(unsigned char *out,
577 unsigned char *in,
578 int width,
579 int height)
580{
581 unsigned char *Ui, *Vi, *yi, *yi1;
582 unsigned char *out1;
583 int i, j;
584
585 yi = in;
586 for (i = height / 2; --i >= 0; ) {
587 out1 = out + width * 2; /* next line */
588 yi1 = yi + width;
589 Ui = yi1 + width;
590 Vi = Ui + width / 2;
591 for (j = width / 2; --j >= 0; ) {
592 *out++ = 128 + *yi++;
593 *out++ = 128 + *Ui;
594 *out++ = 128 + *yi++;
595 *out++ = 128 + *Vi;
596
597 *out1++ = 128 + *yi1++;
598 *out1++ = 128 + *Ui++;
599 *out1++ = 128 + *yi1++;
600 *out1++ = 128 + *Vi++;
601 }
602 yi += width * 2;
603 out = out1;
604 }
605}
606
607static void sd_pkt_scan(struct gspca_dev *gspca_dev,
608 struct gspca_frame *frame, /* target */
c2446b3e 609 __u8 *data, /* isoc packet */
6a7eba24
JFM
610 int len) /* iso packet length */
611{
612 struct sd *sd = (struct sd *) gspca_dev;
613
614 switch (data[0]) {
615 case 0: /* start of frame */
616 if (gspca_dev->last_packet_type == FIRST_PACKET) {
617 yyuv_decode(sd->tmpbuf2, sd->tmpbuf,
618 gspca_dev->width,
619 gspca_dev->height);
620 frame = gspca_frame_add(gspca_dev,
621 LAST_PACKET,
622 frame,
623 sd->tmpbuf2,
624 gspca_dev->width
625 * gspca_dev->height
626 * 2);
627 }
628 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
629 data, 0);
630 data += SPCA50X_OFFSET_DATA;
631 len -= SPCA50X_OFFSET_DATA;
632 if (len > 0)
633 memcpy(sd->tmpbuf, data, len);
634 else
635 len = 0;
636 sd->buflen = len;
637 return;
638 case 0xff: /* drop */
639/* gspca_dev->last_packet_type = DISCARD_PACKET; */
640 return;
641 }
642 data += 1;
643 len -= 1;
644 memcpy(&sd->tmpbuf[sd->buflen], data, len);
645 sd->buflen += len;
646}
647
648static void setbrightness(struct gspca_dev *gspca_dev)
649{
650 struct sd *sd = (struct sd *) gspca_dev;
651
652 spca506_Initi2c(gspca_dev);
653 spca506_WriteI2c(gspca_dev, sd->brightness, SAA7113_bright);
654 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
655}
656
657static void getbrightness(struct gspca_dev *gspca_dev)
658{
659 struct sd *sd = (struct sd *) gspca_dev;
660
661 sd->brightness = spca506_ReadI2c(gspca_dev, SAA7113_bright);
662}
663
664static void setcontrast(struct gspca_dev *gspca_dev)
665{
666 struct sd *sd = (struct sd *) gspca_dev;
667
668 spca506_Initi2c(gspca_dev);
669 spca506_WriteI2c(gspca_dev, sd->contrast, SAA7113_contrast);
670 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
671}
672
673static void getcontrast(struct gspca_dev *gspca_dev)
674{
675 struct sd *sd = (struct sd *) gspca_dev;
676
677 sd->contrast = spca506_ReadI2c(gspca_dev, SAA7113_contrast);
678}
679
680static void setcolors(struct gspca_dev *gspca_dev)
681{
682 struct sd *sd = (struct sd *) gspca_dev;
683
684 spca506_Initi2c(gspca_dev);
685 spca506_WriteI2c(gspca_dev, sd->colors, SAA7113_saturation);
686 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
687}
688
689static void getcolors(struct gspca_dev *gspca_dev)
690{
691 struct sd *sd = (struct sd *) gspca_dev;
692
693 sd->colors = spca506_ReadI2c(gspca_dev, SAA7113_saturation);
694}
695
696static void sethue(struct gspca_dev *gspca_dev)
697{
698 struct sd *sd = (struct sd *) gspca_dev;
699
700 spca506_Initi2c(gspca_dev);
701 spca506_WriteI2c(gspca_dev, sd->hue, SAA7113_hue);
702 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
703}
704
705static void gethue(struct gspca_dev *gspca_dev)
706{
707 struct sd *sd = (struct sd *) gspca_dev;
708
709 sd->hue = spca506_ReadI2c(gspca_dev, SAA7113_hue);
710}
711
712static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
713{
714 struct sd *sd = (struct sd *) gspca_dev;
715
716 sd->brightness = val;
717 if (gspca_dev->streaming)
718 setbrightness(gspca_dev);
719 return 0;
720}
721
722static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
723{
724 struct sd *sd = (struct sd *) gspca_dev;
725
726 getbrightness(gspca_dev);
727 *val = sd->brightness;
728 return 0;
729}
730
731static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
732{
733 struct sd *sd = (struct sd *) gspca_dev;
734
735 sd->contrast = val;
736 if (gspca_dev->streaming)
737 setcontrast(gspca_dev);
738 return 0;
739}
740
741static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
742{
743 struct sd *sd = (struct sd *) gspca_dev;
744
745 getcontrast(gspca_dev);
746 *val = sd->contrast;
747 return 0;
748}
749
750static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
751{
752 struct sd *sd = (struct sd *) gspca_dev;
753
754 sd->colors = val;
755 if (gspca_dev->streaming)
756 setcolors(gspca_dev);
757 return 0;
758}
759
760static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
761{
762 struct sd *sd = (struct sd *) gspca_dev;
763
764 getcolors(gspca_dev);
765 *val = sd->colors;
766 return 0;
767}
768
769static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
770{
771 struct sd *sd = (struct sd *) gspca_dev;
772
773 sd->hue = val;
774 if (gspca_dev->streaming)
775 sethue(gspca_dev);
776 return 0;
777}
778
779static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
780{
781 struct sd *sd = (struct sd *) gspca_dev;
782
783 gethue(gspca_dev);
784 *val = sd->hue;
785 return 0;
786}
787
788/* sub-driver description */
789static struct sd_desc sd_desc = {
790 .name = MODULE_NAME,
791 .ctrls = sd_ctrls,
792 .nctrls = ARRAY_SIZE(sd_ctrls),
793 .config = sd_config,
794 .open = sd_open,
795 .start = sd_start,
796 .stopN = sd_stopN,
797 .stop0 = sd_stop0,
798 .close = sd_close,
799 .pkt_scan = sd_pkt_scan,
800};
801
802/* -- module initialisation -- */
6a7eba24 803static __devinitdata struct usb_device_id device_table[] = {
9d64fdb1
JFM
804 {USB_DEVICE(0x06e1, 0xa190)},
805/*fixme: may be IntelPCCameraPro BRIDGE_SPCA505
806 {USB_DEVICE(0x0733, 0x0430)}, */
807 {USB_DEVICE(0x0734, 0x043b)},
808 {USB_DEVICE(0x99fa, 0x8988)},
6a7eba24
JFM
809 {}
810};
811MODULE_DEVICE_TABLE(usb, device_table);
812
813/* -- device connect -- */
814static int sd_probe(struct usb_interface *intf,
815 const struct usb_device_id *id)
816{
817 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
818 THIS_MODULE);
819}
820
821static struct usb_driver sd_driver = {
822 .name = MODULE_NAME,
823 .id_table = device_table,
824 .probe = sd_probe,
825 .disconnect = gspca_disconnect,
826};
827
828/* -- module insert / remove -- */
829static int __init sd_mod_init(void)
830{
831 if (usb_register(&sd_driver) < 0)
832 return -1;
10b0e96e 833 PDEBUG(D_PROBE, "registered");
6a7eba24
JFM
834 return 0;
835}
836static void __exit sd_mod_exit(void)
837{
838 usb_deregister(&sd_driver);
839 PDEBUG(D_PROBE, "deregistered");
840}
841
842module_init(sd_mod_init);
843module_exit(sd_mod_exit);
This page took 0.066789 seconds and 5 git commands to generate.