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