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