blob: 40e8541b2b898ca04746b1a6f294f0f0b5e35eea [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 Moine6a7eba22008-06-30 15:50:11 -030028MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver");
30MODULE_LICENSE("GPL");
31
32/* specific webcam descriptor */
33struct sd {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -030034 struct gspca_dev gspca_dev; /* !! must be the first item */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030035
36 int buflen;
Jean-Francois Moinec2446b32008-07-05 11:49:20 -030037 __u8 tmpbuf[640 * 480 * 3]; /* YYUV per line */
38 __u8 tmpbuf2[640 * 480 * 2]; /* YUYV */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030039
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
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300117static 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},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300143};
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
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300153/* read 'len' bytes to gspca_dev->usb_buf */
154static void reg_r(struct gspca_dev *gspca_dev,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300155 __u16 req,
156 __u16 index,
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300157 __u16 length)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300158{
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300159 usb_control_msg(gspca_dev->dev,
160 usb_rcvctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300161 req,
162 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
163 0, /* value */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300164 index, gspca_dev->usb_buf, length,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300165 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;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300190
191 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
192 reg_w(gspca_dev->dev, 0x07, valeur, 0x0000);
193 while (retry--) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300194 reg_r(gspca_dev, 0x07, 0x0003, 2);
195 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300196 break;
197 }
198}
199
200static int spca506_ReadI2c(struct gspca_dev *gspca_dev, __u16 reg)
201{
202 int retry = 60;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300203
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) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300208 reg_r(gspca_dev, 0x07, 0x0003, 2);
209 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300210 break;
211 }
212 if (retry == 0)
213 return -1;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300214 reg_r(gspca_dev, 0x07, 0x0000, 1);
215 return gspca_dev->usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300216}
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;
310 cam->dev_name = (char *) id->driver_info;
311 cam->epaddr = 0x01;
312 cam->cam_mode = vga_mode;
313 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
314 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
315 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
316 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
317 sd->hue = sd_ctrls[SD_HUE].qctrl.default_value;
318 return 0;
319}
320
321/* this function is called at open time */
322static int sd_open(struct gspca_dev *gspca_dev)
323{
324 struct usb_device *dev = gspca_dev->dev;
325
326 reg_w(dev, 0x03, 0x00, 0x0004);
327 reg_w(dev, 0x03, 0xFF, 0x0003);
328 reg_w(dev, 0x03, 0x00, 0x0000);
329 reg_w(dev, 0x03, 0x1c, 0x0001);
330 reg_w(dev, 0x03, 0x18, 0x0001);
331 /* Init on PAL and composite input0 */
332 spca506_SetNormeInput(gspca_dev, 0, 0);
333 reg_w(dev, 0x03, 0x1c, 0x0001);
334 reg_w(dev, 0x03, 0x18, 0x0001);
335 reg_w(dev, 0x05, 0x00, 0x0000);
336 reg_w(dev, 0x05, 0xef, 0x0001);
337 reg_w(dev, 0x05, 0x00, 0x00c1);
338 reg_w(dev, 0x05, 0x00, 0x00c2);
339 reg_w(dev, 0x06, 0x18, 0x0002);
340 reg_w(dev, 0x06, 0xf5, 0x0011);
341 reg_w(dev, 0x06, 0x02, 0x0012);
342 reg_w(dev, 0x06, 0xfb, 0x0013);
343 reg_w(dev, 0x06, 0x00, 0x0014);
344 reg_w(dev, 0x06, 0xa4, 0x0051);
345 reg_w(dev, 0x06, 0x40, 0x0052);
346 reg_w(dev, 0x06, 0x71, 0x0053);
347 reg_w(dev, 0x06, 0x40, 0x0054);
348 /************************************************/
349 reg_w(dev, 0x03, 0x00, 0x0004);
350 reg_w(dev, 0x03, 0x00, 0x0003);
351 reg_w(dev, 0x03, 0x00, 0x0004);
352 reg_w(dev, 0x03, 0xFF, 0x0003);
353 reg_w(dev, 0x02, 0x00, 0x0000);
354 reg_w(dev, 0x03, 0x60, 0x0000);
355 reg_w(dev, 0x03, 0x18, 0x0001);
356 /* for a better reading mx :) */
357 /*sdca506_WriteI2c(value,register) */
358 spca506_Initi2c(gspca_dev);
359 spca506_WriteI2c(gspca_dev, 0x08, 0x01);
360 spca506_WriteI2c(gspca_dev, 0xc0, 0x02);
361 /* input composite video */
362 spca506_WriteI2c(gspca_dev, 0x33, 0x03);
363 spca506_WriteI2c(gspca_dev, 0x00, 0x04);
364 spca506_WriteI2c(gspca_dev, 0x00, 0x05);
365 spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
366 spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
367 spca506_WriteI2c(gspca_dev, 0x98, 0x08);
368 spca506_WriteI2c(gspca_dev, 0x03, 0x09);
369 spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
370 spca506_WriteI2c(gspca_dev, 0x47, 0x0b);
371 spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
372 spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
373 spca506_WriteI2c(gspca_dev, 0x03, 0x0e); /* Chroma Pal adjust */
374 spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
375 spca506_WriteI2c(gspca_dev, 0x00, 0x10);
376 spca506_WriteI2c(gspca_dev, 0x0c, 0x11);
377 spca506_WriteI2c(gspca_dev, 0xb8, 0x12);
378 spca506_WriteI2c(gspca_dev, 0x01, 0x13);
379 spca506_WriteI2c(gspca_dev, 0x00, 0x14);
380 spca506_WriteI2c(gspca_dev, 0x00, 0x15);
381 spca506_WriteI2c(gspca_dev, 0x00, 0x16);
382 spca506_WriteI2c(gspca_dev, 0x00, 0x17);
383 spca506_WriteI2c(gspca_dev, 0x00, 0x18);
384 spca506_WriteI2c(gspca_dev, 0x00, 0x19);
385 spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
386 spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
387 spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
388 spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
389 spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
390 spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
391 spca506_WriteI2c(gspca_dev, 0x02, 0x40);
392 spca506_WriteI2c(gspca_dev, 0xff, 0x41);
393 spca506_WriteI2c(gspca_dev, 0xff, 0x42);
394 spca506_WriteI2c(gspca_dev, 0xff, 0x43);
395 spca506_WriteI2c(gspca_dev, 0xff, 0x44);
396 spca506_WriteI2c(gspca_dev, 0xff, 0x45);
397 spca506_WriteI2c(gspca_dev, 0xff, 0x46);
398 spca506_WriteI2c(gspca_dev, 0xff, 0x47);
399 spca506_WriteI2c(gspca_dev, 0xff, 0x48);
400 spca506_WriteI2c(gspca_dev, 0xff, 0x49);
401 spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
402 spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
403 spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
404 spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
405 spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
406 spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
407 spca506_WriteI2c(gspca_dev, 0xff, 0x50);
408 spca506_WriteI2c(gspca_dev, 0xff, 0x51);
409 spca506_WriteI2c(gspca_dev, 0xff, 0x52);
410 spca506_WriteI2c(gspca_dev, 0xff, 0x53);
411 spca506_WriteI2c(gspca_dev, 0xff, 0x54);
412 spca506_WriteI2c(gspca_dev, 0xff, 0x55);
413 spca506_WriteI2c(gspca_dev, 0xff, 0x56);
414 spca506_WriteI2c(gspca_dev, 0xff, 0x57);
415 spca506_WriteI2c(gspca_dev, 0x00, 0x58);
416 spca506_WriteI2c(gspca_dev, 0x54, 0x59);
417 spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
418 spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
419 spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
420 spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
421 spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
422 spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
423 spca506_WriteI2c(gspca_dev, 0x00, 0x60);
424 spca506_WriteI2c(gspca_dev, 0x05, 0x61);
425 spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
426 PDEBUG(D_STREAM, "** Close Init *");
427 return 0;
428}
429
430static void sd_start(struct gspca_dev *gspca_dev)
431{
432 struct usb_device *dev = gspca_dev->dev;
433 __u16 norme;
434 __u16 channel;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300435
436 /**************************************/
437 reg_w(dev, 0x03, 0x00, 0x0004);
438 reg_w(dev, 0x03, 0x00, 0x0003);
439 reg_w(dev, 0x03, 0x00, 0x0004);
440 reg_w(dev, 0x03, 0xFF, 0x0003);
441 reg_w(dev, 0x02, 0x00, 0x0000);
442 reg_w(dev, 0x03, 0x60, 0x0000);
443 reg_w(dev, 0x03, 0x18, 0x0001);
444
445 /*sdca506_WriteI2c(value,register) */
446 spca506_Initi2c(gspca_dev);
447 spca506_WriteI2c(gspca_dev, 0x08, 0x01); /* Increment Delay */
448/* spca506_WriteI2c(gspca_dev, 0xc0, 0x02); * Analog Input Control 1 */
449 spca506_WriteI2c(gspca_dev, 0x33, 0x03);
450 /* Analog Input Control 2 */
451 spca506_WriteI2c(gspca_dev, 0x00, 0x04);
452 /* Analog Input Control 3 */
453 spca506_WriteI2c(gspca_dev, 0x00, 0x05);
454 /* Analog Input Control 4 */
455 spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
456 /* Horizontal Sync Start 0xe9-0x0d */
457 spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
458 /* Horizontal Sync Stop 0x0d-0xf0 */
459
460 spca506_WriteI2c(gspca_dev, 0x98, 0x08); /* Sync Control */
461/* Defaults value */
462 spca506_WriteI2c(gspca_dev, 0x03, 0x09); /* Luminance Control */
463 spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
464 /* Luminance Brightness */
465 spca506_WriteI2c(gspca_dev, 0x47, 0x0b); /* Luminance Contrast */
466 spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
467 /* Chrominance Saturation */
468 spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
469 /* Chrominance Hue Control */
470 spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
471 /* Chrominance Gain Control */
472 /**************************************/
473 spca506_WriteI2c(gspca_dev, 0x00, 0x10);
474 /* Format/Delay Control */
475 spca506_WriteI2c(gspca_dev, 0x0c, 0x11); /* Output Control 1 */
476 spca506_WriteI2c(gspca_dev, 0xb8, 0x12); /* Output Control 2 */
477 spca506_WriteI2c(gspca_dev, 0x01, 0x13); /* Output Control 3 */
478 spca506_WriteI2c(gspca_dev, 0x00, 0x14); /* reserved */
479 spca506_WriteI2c(gspca_dev, 0x00, 0x15); /* VGATE START */
480 spca506_WriteI2c(gspca_dev, 0x00, 0x16); /* VGATE STOP */
481 spca506_WriteI2c(gspca_dev, 0x00, 0x17); /* VGATE Control (MSB) */
482 spca506_WriteI2c(gspca_dev, 0x00, 0x18);
483 spca506_WriteI2c(gspca_dev, 0x00, 0x19);
484 spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
485 spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
486 spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
487 spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
488 spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
489 spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
490 spca506_WriteI2c(gspca_dev, 0x02, 0x40);
491 spca506_WriteI2c(gspca_dev, 0xff, 0x41);
492 spca506_WriteI2c(gspca_dev, 0xff, 0x42);
493 spca506_WriteI2c(gspca_dev, 0xff, 0x43);
494 spca506_WriteI2c(gspca_dev, 0xff, 0x44);
495 spca506_WriteI2c(gspca_dev, 0xff, 0x45);
496 spca506_WriteI2c(gspca_dev, 0xff, 0x46);
497 spca506_WriteI2c(gspca_dev, 0xff, 0x47);
498 spca506_WriteI2c(gspca_dev, 0xff, 0x48);
499 spca506_WriteI2c(gspca_dev, 0xff, 0x49);
500 spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
501 spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
502 spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
503 spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
504 spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
505 spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
506 spca506_WriteI2c(gspca_dev, 0xff, 0x50);
507 spca506_WriteI2c(gspca_dev, 0xff, 0x51);
508 spca506_WriteI2c(gspca_dev, 0xff, 0x52);
509 spca506_WriteI2c(gspca_dev, 0xff, 0x53);
510 spca506_WriteI2c(gspca_dev, 0xff, 0x54);
511 spca506_WriteI2c(gspca_dev, 0xff, 0x55);
512 spca506_WriteI2c(gspca_dev, 0xff, 0x56);
513 spca506_WriteI2c(gspca_dev, 0xff, 0x57);
514 spca506_WriteI2c(gspca_dev, 0x00, 0x58);
515 spca506_WriteI2c(gspca_dev, 0x54, 0x59);
516 spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
517 spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
518 spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
519 spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
520 spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
521 spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
522 spca506_WriteI2c(gspca_dev, 0x00, 0x60);
523 spca506_WriteI2c(gspca_dev, 0x05, 0x61);
524 spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
525 /**************************************/
526 reg_w(dev, 0x05, 0x00, 0x0003);
527 reg_w(dev, 0x05, 0x00, 0x0004);
528 reg_w(dev, 0x03, 0x10, 0x0001);
529 reg_w(dev, 0x03, 0x78, 0x0000);
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300530 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300531 case 0:
532 spca506_Setsize(gspca_dev, 0, 0x10, 0x10);
533 break;
534 case 1:
535 spca506_Setsize(gspca_dev, 1, 0x1a, 0x1a);
536 break;
537 case 2:
538 spca506_Setsize(gspca_dev, 2, 0x1c, 0x1c);
539 break;
540 case 4:
541 spca506_Setsize(gspca_dev, 4, 0x34, 0x34);
542 break;
543 default:
544/* case 5: */
545 spca506_Setsize(gspca_dev, 5, 0x40, 0x40);
546 break;
547 }
548
549 /* compress setting and size */
550 /* set i2c luma */
551 reg_w(dev, 0x02, 0x01, 0x0000);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300552 reg_w(dev, 0x03, 0x12, 0x0000);
553 reg_r(gspca_dev, 0x04, 0x0001, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300554 PDEBUG(D_STREAM, "webcam started");
555 spca506_GetNormeInput(gspca_dev, &norme, &channel);
556 spca506_SetNormeInput(gspca_dev, norme, channel);
557}
558
559static void sd_stopN(struct gspca_dev *gspca_dev)
560{
561 struct usb_device *dev = gspca_dev->dev;
562
563 reg_w(dev, 0x02, 0x00, 0x0000);
564 reg_w(dev, 0x03, 0x00, 0x0004);
565 reg_w(dev, 0x03, 0x00, 0x0003);
566}
567
568static void sd_stop0(struct gspca_dev *gspca_dev)
569{
570}
571
572static void sd_close(struct gspca_dev *gspca_dev)
573{
574}
575
576/* convert YYUV per line to YUYV (YUV 4:2:2) */
577static void yyuv_decode(unsigned char *out,
578 unsigned char *in,
579 int width,
580 int height)
581{
582 unsigned char *Ui, *Vi, *yi, *yi1;
583 unsigned char *out1;
584 int i, j;
585
586 yi = in;
587 for (i = height / 2; --i >= 0; ) {
588 out1 = out + width * 2; /* next line */
589 yi1 = yi + width;
590 Ui = yi1 + width;
591 Vi = Ui + width / 2;
592 for (j = width / 2; --j >= 0; ) {
593 *out++ = 128 + *yi++;
594 *out++ = 128 + *Ui;
595 *out++ = 128 + *yi++;
596 *out++ = 128 + *Vi;
597
598 *out1++ = 128 + *yi1++;
599 *out1++ = 128 + *Ui++;
600 *out1++ = 128 + *yi1++;
601 *out1++ = 128 + *Vi++;
602 }
603 yi += width * 2;
604 out = out1;
605 }
606}
607
608static void sd_pkt_scan(struct gspca_dev *gspca_dev,
609 struct gspca_frame *frame, /* target */
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300610 __u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300611 int len) /* iso packet length */
612{
613 struct sd *sd = (struct sd *) gspca_dev;
614
615 switch (data[0]) {
616 case 0: /* start of frame */
617 if (gspca_dev->last_packet_type == FIRST_PACKET) {
618 yyuv_decode(sd->tmpbuf2, sd->tmpbuf,
619 gspca_dev->width,
620 gspca_dev->height);
621 frame = gspca_frame_add(gspca_dev,
622 LAST_PACKET,
623 frame,
624 sd->tmpbuf2,
625 gspca_dev->width
626 * gspca_dev->height
627 * 2);
628 }
629 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
630 data, 0);
631 data += SPCA50X_OFFSET_DATA;
632 len -= SPCA50X_OFFSET_DATA;
633 if (len > 0)
634 memcpy(sd->tmpbuf, data, len);
635 else
636 len = 0;
637 sd->buflen = len;
638 return;
639 case 0xff: /* drop */
640/* gspca_dev->last_packet_type = DISCARD_PACKET; */
641 return;
642 }
643 data += 1;
644 len -= 1;
645 memcpy(&sd->tmpbuf[sd->buflen], data, len);
646 sd->buflen += len;
647}
648
649static void setbrightness(struct gspca_dev *gspca_dev)
650{
651 struct sd *sd = (struct sd *) gspca_dev;
652
653 spca506_Initi2c(gspca_dev);
654 spca506_WriteI2c(gspca_dev, sd->brightness, SAA7113_bright);
655 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
656}
657
658static void getbrightness(struct gspca_dev *gspca_dev)
659{
660 struct sd *sd = (struct sd *) gspca_dev;
661
662 sd->brightness = spca506_ReadI2c(gspca_dev, SAA7113_bright);
663}
664
665static void setcontrast(struct gspca_dev *gspca_dev)
666{
667 struct sd *sd = (struct sd *) gspca_dev;
668
669 spca506_Initi2c(gspca_dev);
670 spca506_WriteI2c(gspca_dev, sd->contrast, SAA7113_contrast);
671 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
672}
673
674static void getcontrast(struct gspca_dev *gspca_dev)
675{
676 struct sd *sd = (struct sd *) gspca_dev;
677
678 sd->contrast = spca506_ReadI2c(gspca_dev, SAA7113_contrast);
679}
680
681static void setcolors(struct gspca_dev *gspca_dev)
682{
683 struct sd *sd = (struct sd *) gspca_dev;
684
685 spca506_Initi2c(gspca_dev);
686 spca506_WriteI2c(gspca_dev, sd->colors, SAA7113_saturation);
687 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
688}
689
690static void getcolors(struct gspca_dev *gspca_dev)
691{
692 struct sd *sd = (struct sd *) gspca_dev;
693
694 sd->colors = spca506_ReadI2c(gspca_dev, SAA7113_saturation);
695}
696
697static void sethue(struct gspca_dev *gspca_dev)
698{
699 struct sd *sd = (struct sd *) gspca_dev;
700
701 spca506_Initi2c(gspca_dev);
702 spca506_WriteI2c(gspca_dev, sd->hue, SAA7113_hue);
703 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
704}
705
706static void gethue(struct gspca_dev *gspca_dev)
707{
708 struct sd *sd = (struct sd *) gspca_dev;
709
710 sd->hue = spca506_ReadI2c(gspca_dev, SAA7113_hue);
711}
712
713static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
714{
715 struct sd *sd = (struct sd *) gspca_dev;
716
717 sd->brightness = val;
718 if (gspca_dev->streaming)
719 setbrightness(gspca_dev);
720 return 0;
721}
722
723static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
724{
725 struct sd *sd = (struct sd *) gspca_dev;
726
727 getbrightness(gspca_dev);
728 *val = sd->brightness;
729 return 0;
730}
731
732static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
733{
734 struct sd *sd = (struct sd *) gspca_dev;
735
736 sd->contrast = val;
737 if (gspca_dev->streaming)
738 setcontrast(gspca_dev);
739 return 0;
740}
741
742static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
743{
744 struct sd *sd = (struct sd *) gspca_dev;
745
746 getcontrast(gspca_dev);
747 *val = sd->contrast;
748 return 0;
749}
750
751static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
752{
753 struct sd *sd = (struct sd *) gspca_dev;
754
755 sd->colors = val;
756 if (gspca_dev->streaming)
757 setcolors(gspca_dev);
758 return 0;
759}
760
761static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
762{
763 struct sd *sd = (struct sd *) gspca_dev;
764
765 getcolors(gspca_dev);
766 *val = sd->colors;
767 return 0;
768}
769
770static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
771{
772 struct sd *sd = (struct sd *) gspca_dev;
773
774 sd->hue = val;
775 if (gspca_dev->streaming)
776 sethue(gspca_dev);
777 return 0;
778}
779
780static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
781{
782 struct sd *sd = (struct sd *) gspca_dev;
783
784 gethue(gspca_dev);
785 *val = sd->hue;
786 return 0;
787}
788
789/* sub-driver description */
790static struct sd_desc sd_desc = {
791 .name = MODULE_NAME,
792 .ctrls = sd_ctrls,
793 .nctrls = ARRAY_SIZE(sd_ctrls),
794 .config = sd_config,
795 .open = sd_open,
796 .start = sd_start,
797 .stopN = sd_stopN,
798 .stop0 = sd_stop0,
799 .close = sd_close,
800 .pkt_scan = sd_pkt_scan,
801};
802
803/* -- module initialisation -- */
804#define DVNM(name) .driver_info = (kernel_ulong_t) name
805static __devinitdata struct usb_device_id device_table[] = {
806 {USB_DEVICE(0x06e1, 0xa190), DVNM("ADS Instant VCD")},
807/* {USB_DEVICE(0x0733, 0x0430), DVNM("UsbGrabber PV321c")}, */
808 {USB_DEVICE(0x0734, 0x043b), DVNM("3DeMon USB Capture aka")},
809 {USB_DEVICE(0x99fa, 0x8988), DVNM("Grandtec V.cap")},
810 {}
811};
812MODULE_DEVICE_TABLE(usb, device_table);
813
814/* -- device connect -- */
815static int sd_probe(struct usb_interface *intf,
816 const struct usb_device_id *id)
817{
818 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
819 THIS_MODULE);
820}
821
822static struct usb_driver sd_driver = {
823 .name = MODULE_NAME,
824 .id_table = device_table,
825 .probe = sd_probe,
826 .disconnect = gspca_disconnect,
827};
828
829/* -- module insert / remove -- */
830static int __init sd_mod_init(void)
831{
832 if (usb_register(&sd_driver) < 0)
833 return -1;
Jean-Francois Moine10b0e962008-07-22 05:35:10 -0300834 PDEBUG(D_PROBE, "registered");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300835 return 0;
836}
837static void __exit sd_mod_exit(void)
838{
839 usb_deregister(&sd_driver);
840 PDEBUG(D_PROBE, "deregistered");
841}
842
843module_init(sd_mod_init);
844module_exit(sd_mod_exit);