2 * Etoms Et61x151 GPL Linux driver by Michel Xhaard (09/09/2004)
4 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define MODULE_NAME "etoms"
25 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
26 MODULE_DESCRIPTION("Etoms USB Camera Driver");
27 MODULE_LICENSE("GPL");
29 /* specific webcam descriptor */
31 struct gspca_dev gspca_dev; /* !! must be the first item */
33 unsigned char brightness;
34 unsigned char contrast;
36 unsigned char autogain;
39 #define SENSOR_PAS106 0
40 #define SENSOR_TAS5130CXX 1
42 #define AG_CNT_START 13
45 /* V4L2 controls supported by the driver */
46 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
47 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
48 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
49 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
50 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
51 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
52 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
53 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
55 static struct ctrl sd_ctrls[] = {
58 .id = V4L2_CID_BRIGHTNESS,
59 .type = V4L2_CTRL_TYPE_INTEGER,
64 #define BRIGHTNESS_DEF 63
65 .default_value = BRIGHTNESS_DEF,
67 .set = sd_setbrightness,
68 .get = sd_getbrightness,
72 .id = V4L2_CID_CONTRAST,
73 .type = V4L2_CTRL_TYPE_INTEGER,
78 #define CONTRAST_DEF 127
79 .default_value = CONTRAST_DEF,
81 .set = sd_setcontrast,
82 .get = sd_getcontrast,
87 .id = V4L2_CID_SATURATION,
88 .type = V4L2_CTRL_TYPE_INTEGER,
94 .default_value = COLOR_DEF,
101 .id = V4L2_CID_AUTOGAIN,
102 .type = V4L2_CTRL_TYPE_BOOLEAN,
107 #define AUTOGAIN_DEF 1
108 .default_value = AUTOGAIN_DEF,
110 .set = sd_setautogain,
111 .get = sd_getautogain,
115 static struct v4l2_pix_format vga_mode[] = {
116 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
118 .sizeimage = 320 * 240,
119 .colorspace = V4L2_COLORSPACE_SRGB,
121 /* {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
123 .sizeimage = 640 * 480,
124 .colorspace = V4L2_COLORSPACE_SRGB,
128 static struct v4l2_pix_format sif_mode[] = {
129 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
131 .sizeimage = 176 * 144,
132 .colorspace = V4L2_COLORSPACE_SRGB,
134 {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
136 .sizeimage = 352 * 288,
137 .colorspace = V4L2_COLORSPACE_SRGB,
141 #define ETOMS_ALT_SIZE_1000 12
143 #define ET_GPIO_DIR_CTRL 0x04 /* Control IO bit[0..5] (0 in 1 out) */
144 #define ET_GPIO_OUT 0x05 /* Only IO data */
145 #define ET_GPIO_IN 0x06 /* Read Only IO data */
146 #define ET_RESET_ALL 0x03
148 #define ET_CTRL 0x02 /* enable i2c OutClck Powerdown mode */
150 #define ET_COMP 0x12 /* Compression register */
151 #define ET_MAXQt 0x13
152 #define ET_MINQt 0x14
153 #define ET_COMP_VAL0 0x02
154 #define ET_COMP_VAL1 0x03
156 #define ET_REG1d 0x1d
157 #define ET_REG1e 0x1e
158 #define ET_REG1f 0x1f
159 #define ET_REG20 0x20
160 #define ET_REG21 0x21
161 #define ET_REG22 0x22
162 #define ET_REG23 0x23
163 #define ET_REG24 0x24
164 #define ET_REG25 0x25
165 /* base registers for luma calculation */
166 #define ET_LUMA_CENTER 0x39
168 #define ET_G_RED 0x4d
169 #define ET_G_GREEN1 0x4e
170 #define ET_G_BLUE 0x4f
171 #define ET_G_GREEN2 0x50
172 #define ET_G_GR_H 0x51
173 #define ET_G_GB_H 0x52
175 #define ET_O_RED 0x34
176 #define ET_O_GREEN1 0x35
177 #define ET_O_BLUE 0x36
178 #define ET_O_GREEN2 0x37
180 #define ET_SYNCHRO 0x68
181 #define ET_STARTX 0x69
182 #define ET_STARTY 0x6a
183 #define ET_WIDTH_LOW 0x6b
184 #define ET_HEIGTH_LOW 0x6c
185 #define ET_W_H_HEIGTH 0x6d
187 #define ET_REG6e 0x6e /* OBW */
188 #define ET_REG6f 0x6f /* OBW */
189 #define ET_REG70 0x70 /* OBW_AWB */
190 #define ET_REG71 0x71 /* OBW_AWB */
191 #define ET_REG72 0x72 /* OBW_AWB */
192 #define ET_REG73 0x73 /* Clkdelay ns */
193 #define ET_REG74 0x74 /* test pattern */
194 #define ET_REG75 0x75 /* test pattern */
196 #define ET_I2C_CLK 0x8c
197 #define ET_PXL_CLK 0x60
199 #define ET_I2C_BASE 0x89
200 #define ET_I2C_COUNT 0x8a
201 #define ET_I2C_PREFETCH 0x8b
202 #define ET_I2C_REG 0x88
203 #define ET_I2C_DATA7 0x87
204 #define ET_I2C_DATA6 0x86
205 #define ET_I2C_DATA5 0x85
206 #define ET_I2C_DATA4 0x84
207 #define ET_I2C_DATA3 0x83
208 #define ET_I2C_DATA2 0x82
209 #define ET_I2C_DATA1 0x81
210 #define ET_I2C_DATA0 0x80
212 #define PAS106_REG2 0x02 /* pxlClk = systemClk/(reg2) */
213 #define PAS106_REG3 0x03 /* line/frame H [11..4] */
214 #define PAS106_REG4 0x04 /* line/frame L [3..0] */
215 #define PAS106_REG5 0x05 /* exposure time line offset(default 5) */
216 #define PAS106_REG6 0x06 /* exposure time pixel offset(default 6) */
217 #define PAS106_REG7 0x07 /* signbit Dac (default 0) */
218 #define PAS106_REG9 0x09
219 #define PAS106_REG0e 0x0e /* global gain [4..0](default 0x0e) */
220 #define PAS106_REG13 0x13 /* end i2c write */
222 static const __u8 GainRGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
224 static const __u8 I2c2[] = { 0x08, 0x08, 0x08, 0x08, 0x0d };
226 static const __u8 I2c3[] = { 0x12, 0x05 };
228 static const __u8 I2c4[] = { 0x41, 0x08 };
230 /* read 'len' bytes to gspca_dev->usb_buf */
231 static void reg_r(struct gspca_dev *gspca_dev,
235 struct usb_device *dev = gspca_dev->dev;
238 if (len > USB_BUF_SZ) {
239 err("reg_r: buffer overflow");
244 usb_rcvctrlpipe(dev, 0),
246 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
248 index, gspca_dev->usb_buf, len, 500);
249 PDEBUG(D_USBI, "reg read [%02x] -> %02x ..",
250 index, gspca_dev->usb_buf[0]);
253 static void reg_w_val(struct gspca_dev *gspca_dev,
257 struct usb_device *dev = gspca_dev->dev;
259 gspca_dev->usb_buf[0] = val;
261 usb_sndctrlpipe(dev, 0),
263 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
265 index, gspca_dev->usb_buf, 1, 500);
268 static void reg_w(struct gspca_dev *gspca_dev,
273 struct usb_device *dev = gspca_dev->dev;
276 if (len > USB_BUF_SZ) {
277 err("reg_w: buffer overflow");
280 PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer);
282 memcpy(gspca_dev->usb_buf, buffer, len);
284 usb_sndctrlpipe(dev, 0),
286 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
287 0, index, gspca_dev->usb_buf, len, 500);
290 static int i2c_w(struct gspca_dev *gspca_dev,
295 /* buffer should be [D0..D7] */
298 /* set the base address */
299 reg_w_val(gspca_dev, ET_I2C_BASE, 0x40);
300 /* sensor base for the pas106 */
301 /* set count and prefetch */
302 ptchcount = ((len & 0x07) << 4) | (mode & 0x03);
303 reg_w_val(gspca_dev, ET_I2C_COUNT, ptchcount);
304 /* set the register base */
305 reg_w_val(gspca_dev, ET_I2C_REG, reg);
307 reg_w_val(gspca_dev, ET_I2C_DATA0 + len, buffer[len]);
311 static int i2c_r(struct gspca_dev *gspca_dev,
314 /* set the base address */
315 reg_w_val(gspca_dev, ET_I2C_BASE, 0x40);
316 /* sensor base for the pas106 */
317 /* set count and prefetch (cnd: 4 bits - mode: 4 bits) */
318 reg_w_val(gspca_dev, ET_I2C_COUNT, 0x11);
319 reg_w_val(gspca_dev, ET_I2C_REG, reg); /* set the register base */
320 reg_w_val(gspca_dev, ET_I2C_PREFETCH, 0x02); /* prefetch */
321 reg_w_val(gspca_dev, ET_I2C_PREFETCH, 0x00);
322 reg_r(gspca_dev, ET_I2C_DATA0, 1); /* read one byte */
326 static int Et_WaitStatus(struct gspca_dev *gspca_dev)
331 reg_r(gspca_dev, ET_ClCK, 1);
332 if (gspca_dev->usb_buf[0] != 0)
338 static int et_video(struct gspca_dev *gspca_dev,
343 reg_w_val(gspca_dev, ET_GPIO_OUT,
344 on ? 0x10 /* startvideo - set Bit5 */
345 : 0); /* stopvideo */
346 ret = Et_WaitStatus(gspca_dev);
348 PDEBUG(D_ERR, "timeout video on/off");
352 static void Et_init2(struct gspca_dev *gspca_dev)
355 static const __u8 FormLine[] = { 0x84, 0x03, 0x14, 0xf4, 0x01, 0x05 };
357 PDEBUG(D_STREAM, "Open Init2 ET");
358 reg_w_val(gspca_dev, ET_GPIO_DIR_CTRL, 0x2f);
359 reg_w_val(gspca_dev, ET_GPIO_OUT, 0x10);
360 reg_r(gspca_dev, ET_GPIO_IN, 1);
361 reg_w_val(gspca_dev, ET_ClCK, 0x14); /* 0x14 // 0x16 enabled pattern */
362 reg_w_val(gspca_dev, ET_CTRL, 0x1b);
364 /* compression et subsampling */
365 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
366 value = ET_COMP_VAL1; /* 320 */
368 value = ET_COMP_VAL0; /* 640 */
369 reg_w_val(gspca_dev, ET_COMP, value);
370 reg_w_val(gspca_dev, ET_MAXQt, 0x1f);
371 reg_w_val(gspca_dev, ET_MINQt, 0x04);
372 /* undocumented registers */
373 reg_w_val(gspca_dev, ET_REG1d, 0xff);
374 reg_w_val(gspca_dev, ET_REG1e, 0xff);
375 reg_w_val(gspca_dev, ET_REG1f, 0xff);
376 reg_w_val(gspca_dev, ET_REG20, 0x35);
377 reg_w_val(gspca_dev, ET_REG21, 0x01);
378 reg_w_val(gspca_dev, ET_REG22, 0x00);
379 reg_w_val(gspca_dev, ET_REG23, 0xff);
380 reg_w_val(gspca_dev, ET_REG24, 0xff);
381 reg_w_val(gspca_dev, ET_REG25, 0x0f);
383 reg_w_val(gspca_dev, 0x30, 0x11); /* 0x30 */
384 reg_w_val(gspca_dev, 0x31, 0x40);
385 reg_w_val(gspca_dev, 0x32, 0x00);
386 reg_w_val(gspca_dev, ET_O_RED, 0x00); /* 0x34 */
387 reg_w_val(gspca_dev, ET_O_GREEN1, 0x00);
388 reg_w_val(gspca_dev, ET_O_BLUE, 0x00);
389 reg_w_val(gspca_dev, ET_O_GREEN2, 0x00);
391 reg_w_val(gspca_dev, ET_G_RED, 0x80); /* 0x4d */
392 reg_w_val(gspca_dev, ET_G_GREEN1, 0x80);
393 reg_w_val(gspca_dev, ET_G_BLUE, 0x80);
394 reg_w_val(gspca_dev, ET_G_GREEN2, 0x80);
395 reg_w_val(gspca_dev, ET_G_GR_H, 0x00);
396 reg_w_val(gspca_dev, ET_G_GB_H, 0x00); /* 0x52 */
397 /* Window control registers */
398 reg_w_val(gspca_dev, 0x61, 0x80); /* use cmc_out */
399 reg_w_val(gspca_dev, 0x62, 0x02);
400 reg_w_val(gspca_dev, 0x63, 0x03);
401 reg_w_val(gspca_dev, 0x64, 0x14);
402 reg_w_val(gspca_dev, 0x65, 0x0e);
403 reg_w_val(gspca_dev, 0x66, 0x02);
404 reg_w_val(gspca_dev, 0x67, 0x02);
406 /**************************************/
407 reg_w_val(gspca_dev, ET_SYNCHRO, 0x8f); /* 0x68 */
408 reg_w_val(gspca_dev, ET_STARTX, 0x69); /* 0x6a //0x69 */
409 reg_w_val(gspca_dev, ET_STARTY, 0x0d); /* 0x0d //0x0c */
410 reg_w_val(gspca_dev, ET_WIDTH_LOW, 0x80);
411 reg_w_val(gspca_dev, ET_HEIGTH_LOW, 0xe0);
412 reg_w_val(gspca_dev, ET_W_H_HEIGTH, 0x60); /* 6d */
413 reg_w_val(gspca_dev, ET_REG6e, 0x86);
414 reg_w_val(gspca_dev, ET_REG6f, 0x01);
415 reg_w_val(gspca_dev, ET_REG70, 0x26);
416 reg_w_val(gspca_dev, ET_REG71, 0x7a);
417 reg_w_val(gspca_dev, ET_REG72, 0x01);
418 /* Clock Pattern registers ***************** */
419 reg_w_val(gspca_dev, ET_REG73, 0x00);
420 reg_w_val(gspca_dev, ET_REG74, 0x18); /* 0x28 */
421 reg_w_val(gspca_dev, ET_REG75, 0x0f); /* 0x01 */
422 /**********************************************/
423 reg_w_val(gspca_dev, 0x8a, 0x20);
424 reg_w_val(gspca_dev, 0x8d, 0x0f);
425 reg_w_val(gspca_dev, 0x8e, 0x08);
426 /**************************************/
427 reg_w_val(gspca_dev, 0x03, 0x08);
428 reg_w_val(gspca_dev, ET_PXL_CLK, 0x03);
429 reg_w_val(gspca_dev, 0x81, 0xff);
430 reg_w_val(gspca_dev, 0x80, 0x00);
431 reg_w_val(gspca_dev, 0x81, 0xff);
432 reg_w_val(gspca_dev, 0x80, 0x20);
433 reg_w_val(gspca_dev, 0x03, 0x01);
434 reg_w_val(gspca_dev, 0x03, 0x00);
435 reg_w_val(gspca_dev, 0x03, 0x08);
436 /********************************************/
438 /* reg_r(gspca_dev, ET_I2C_BASE, 1);
439 always 0x40 as the pas106 ??? */
441 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
442 value = 0x04; /* 320 */
444 value = 0x1e; /* 0x17 * setting PixelClock
445 * 0x03 mean 24/(3+1) = 6 Mhz
446 * 0x05 -> 24/(5+1) = 4 Mhz
447 * 0x0b -> 24/(11+1) = 2 Mhz
448 * 0x17 -> 24/(23+1) = 1 Mhz
450 reg_w_val(gspca_dev, ET_PXL_CLK, value);
451 /* now set by fifo the FormatLine setting */
452 reg_w(gspca_dev, 0x62, FormLine, 6);
454 /* set exposure times [ 0..0x78] 0->longvalue 0x78->shortvalue */
455 reg_w_val(gspca_dev, 0x81, 0x47); /* 0x47; */
456 reg_w_val(gspca_dev, 0x80, 0x40); /* 0x40; */
458 /* Brightness change Brith+ decrease value */
459 /* Brigth- increase value */
460 /* original value = 0x70; */
461 reg_w_val(gspca_dev, 0x81, 0x30); /* 0x20; - set brightness */
462 reg_w_val(gspca_dev, 0x80, 0x20); /* 0x20; */
465 static void setbrightness(struct gspca_dev *gspca_dev)
467 struct sd *sd = (struct sd *) gspca_dev;
469 __u8 brightness = sd->brightness;
471 for (i = 0; i < 4; i++)
472 reg_w_val(gspca_dev, ET_O_RED + i, brightness);
475 static void getbrightness(struct gspca_dev *gspca_dev)
477 struct sd *sd = (struct sd *) gspca_dev;
481 for (i = 0; i < 4; i++) {
482 reg_r(gspca_dev, ET_O_RED + i, 1);
483 brightness += gspca_dev->usb_buf[0];
485 sd->brightness = brightness >> 3;
488 static void setcontrast(struct gspca_dev *gspca_dev)
490 struct sd *sd = (struct sd *) gspca_dev;
491 __u8 RGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
492 __u8 contrast = sd->contrast;
494 memset(RGBG, contrast, sizeof(RGBG) - 2);
495 reg_w(gspca_dev, ET_G_RED, RGBG, 6);
498 static void getcontrast(struct gspca_dev *gspca_dev)
500 struct sd *sd = (struct sd *) gspca_dev;
504 for (i = 0; i < 4; i++) {
505 reg_r(gspca_dev, ET_G_RED + i, 1);
506 contrast += gspca_dev->usb_buf[0];
508 sd->contrast = contrast >> 2;
511 static void setcolors(struct gspca_dev *gspca_dev)
513 struct sd *sd = (struct sd *) gspca_dev;
514 __u8 I2cc[] = { 0x05, 0x02, 0x02, 0x05, 0x0d };
515 __u8 i2cflags = 0x01;
516 /* __u8 green = 0; */
517 __u8 colors = sd->colors;
519 I2cc[3] = colors; /* red */
520 I2cc[0] = 15 - colors; /* blue */
521 /* green = 15 - ((((7*I2cc[0]) >> 2 ) + I2cc[3]) >> 1); */
522 /* I2cc[1] = I2cc[2] = green; */
523 if (sd->sensor == SENSOR_PAS106) {
524 i2c_w(gspca_dev, PAS106_REG13, &i2cflags, 1, 3);
525 i2c_w(gspca_dev, PAS106_REG9, I2cc, sizeof I2cc, 1);
527 /* PDEBUG(D_CONF , "Etoms red %d blue %d green %d",
528 I2cc[3], I2cc[0], green); */
531 static void getcolors(struct gspca_dev *gspca_dev)
533 struct sd *sd = (struct sd *) gspca_dev;
535 if (sd->sensor == SENSOR_PAS106) {
536 /* i2c_r(gspca_dev, PAS106_REG9); * blue */
537 i2c_r(gspca_dev, PAS106_REG9 + 3); /* red */
538 sd->colors = gspca_dev->usb_buf[0] & 0x0f;
542 static void setautogain(struct gspca_dev *gspca_dev)
544 struct sd *sd = (struct sd *) gspca_dev;
547 sd->ag_cnt = AG_CNT_START;
552 static void Et_init1(struct gspca_dev *gspca_dev)
555 /* __u8 I2c0 [] = {0x0a, 0x12, 0x05, 0x22, 0xac, 0x00, 0x01, 0x00}; */
556 __u8 I2c0[] = { 0x0a, 0x12, 0x05, 0x6d, 0xcd, 0x00, 0x01, 0x00 };
557 /* try 1/120 0x6d 0xcd 0x40 */
558 /* __u8 I2c0 [] = {0x0a, 0x12, 0x05, 0xfe, 0xfe, 0xc0, 0x01, 0x00};
561 PDEBUG(D_STREAM, "Open Init1 ET");
562 reg_w_val(gspca_dev, ET_GPIO_DIR_CTRL, 7);
563 reg_r(gspca_dev, ET_GPIO_IN, 1);
564 reg_w_val(gspca_dev, ET_RESET_ALL, 1);
565 reg_w_val(gspca_dev, ET_RESET_ALL, 0);
566 reg_w_val(gspca_dev, ET_ClCK, 0x10);
567 reg_w_val(gspca_dev, ET_CTRL, 0x19);
568 /* compression et subsampling */
569 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
570 value = ET_COMP_VAL1;
572 value = ET_COMP_VAL0;
573 PDEBUG(D_STREAM, "Open mode %d Compression %d",
574 gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv,
576 reg_w_val(gspca_dev, ET_COMP, value);
577 reg_w_val(gspca_dev, ET_MAXQt, 0x1d);
578 reg_w_val(gspca_dev, ET_MINQt, 0x02);
579 /* undocumented registers */
580 reg_w_val(gspca_dev, ET_REG1d, 0xff);
581 reg_w_val(gspca_dev, ET_REG1e, 0xff);
582 reg_w_val(gspca_dev, ET_REG1f, 0xff);
583 reg_w_val(gspca_dev, ET_REG20, 0x35);
584 reg_w_val(gspca_dev, ET_REG21, 0x01);
585 reg_w_val(gspca_dev, ET_REG22, 0x00);
586 reg_w_val(gspca_dev, ET_REG23, 0xf7);
587 reg_w_val(gspca_dev, ET_REG24, 0xff);
588 reg_w_val(gspca_dev, ET_REG25, 0x07);
590 reg_w_val(gspca_dev, ET_G_RED, 0x80);
591 reg_w_val(gspca_dev, ET_G_GREEN1, 0x80);
592 reg_w_val(gspca_dev, ET_G_BLUE, 0x80);
593 reg_w_val(gspca_dev, ET_G_GREEN2, 0x80);
594 reg_w_val(gspca_dev, ET_G_GR_H, 0x00);
595 reg_w_val(gspca_dev, ET_G_GB_H, 0x00);
596 /* Window control registers */
597 reg_w_val(gspca_dev, ET_SYNCHRO, 0xf0);
598 reg_w_val(gspca_dev, ET_STARTX, 0x56); /* 0x56 */
599 reg_w_val(gspca_dev, ET_STARTY, 0x05); /* 0x04 */
600 reg_w_val(gspca_dev, ET_WIDTH_LOW, 0x60);
601 reg_w_val(gspca_dev, ET_HEIGTH_LOW, 0x20);
602 reg_w_val(gspca_dev, ET_W_H_HEIGTH, 0x50);
603 reg_w_val(gspca_dev, ET_REG6e, 0x86);
604 reg_w_val(gspca_dev, ET_REG6f, 0x01);
605 reg_w_val(gspca_dev, ET_REG70, 0x86);
606 reg_w_val(gspca_dev, ET_REG71, 0x14);
607 reg_w_val(gspca_dev, ET_REG72, 0x00);
608 /* Clock Pattern registers */
609 reg_w_val(gspca_dev, ET_REG73, 0x00);
610 reg_w_val(gspca_dev, ET_REG74, 0x00);
611 reg_w_val(gspca_dev, ET_REG75, 0x0a);
612 reg_w_val(gspca_dev, ET_I2C_CLK, 0x04);
613 reg_w_val(gspca_dev, ET_PXL_CLK, 0x01);
615 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
617 i2c_w(gspca_dev, PAS106_REG2, I2c0, sizeof I2c0, 1);
618 i2c_w(gspca_dev, PAS106_REG9, I2c2, sizeof I2c2, 1);
620 i2c_w(gspca_dev, PAS106_REG2, &value, 1, 1);
621 i2c_w(gspca_dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
624 i2c_w(gspca_dev, PAS106_REG0e, &value, 1, 1);
628 i2c_w(gspca_dev, PAS106_REG2, I2c0, sizeof I2c0, 1);
629 i2c_w(gspca_dev, PAS106_REG9, I2c2, sizeof I2c2, 1);
631 i2c_w(gspca_dev, PAS106_REG2, &value, 1, 1);
632 i2c_w(gspca_dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
635 i2c_w(gspca_dev, PAS106_REG0e, &value, 1, 1);
636 /* bit 2 enable bit 1:2 select 0 1 2 3
637 value = 0x07; * curve 0 *
638 i2c_w(gspca_dev, PAS106_REG0f, &value, 1, 1);
644 /* i2c_w(gspca_dev, PAS106_REG5, &value, 1, 1); */
645 /* magnetude and sign bit for DAC */
646 i2c_w(gspca_dev, PAS106_REG7, I2c4, sizeof I2c4, 1);
647 /* now set by fifo the whole colors setting */
648 reg_w(gspca_dev, ET_G_RED, GainRGBG, 6);
649 getcolors(gspca_dev);
650 setcolors(gspca_dev);
653 /* this function is called at probe time */
654 static int sd_config(struct gspca_dev *gspca_dev,
655 const struct usb_device_id *id)
657 struct sd *sd = (struct sd *) gspca_dev;
660 cam = &gspca_dev->cam;
662 sd->sensor = id->driver_info;
663 if (sd->sensor == SENSOR_PAS106) {
664 cam->cam_mode = sif_mode;
665 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
667 cam->cam_mode = vga_mode;
668 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
669 gspca_dev->ctrl_dis = (1 << COLOR_IDX);
671 sd->brightness = BRIGHTNESS_DEF;
672 sd->contrast = CONTRAST_DEF;
673 sd->colors = COLOR_DEF;
674 sd->autogain = AUTOGAIN_DEF;
679 /* this function is called at probe and resume time */
680 static int sd_init(struct gspca_dev *gspca_dev)
682 struct sd *sd = (struct sd *) gspca_dev;
684 if (sd->sensor == SENSOR_PAS106)
688 reg_w_val(gspca_dev, ET_RESET_ALL, 0x08);
689 et_video(gspca_dev, 0); /* video off */
693 /* -- start the camera -- */
694 static void sd_start(struct gspca_dev *gspca_dev)
696 struct sd *sd = (struct sd *) gspca_dev;
698 if (sd->sensor == SENSOR_PAS106)
703 setautogain(gspca_dev);
705 reg_w_val(gspca_dev, ET_RESET_ALL, 0x08);
706 et_video(gspca_dev, 1); /* video on */
709 static void sd_stopN(struct gspca_dev *gspca_dev)
711 et_video(gspca_dev, 0); /* video off */
714 static __u8 Et_getgainG(struct gspca_dev *gspca_dev)
716 struct sd *sd = (struct sd *) gspca_dev;
718 if (sd->sensor == SENSOR_PAS106) {
719 i2c_r(gspca_dev, PAS106_REG0e);
720 PDEBUG(D_CONF, "Etoms gain G %d", gspca_dev->usb_buf[0]);
721 return gspca_dev->usb_buf[0];
726 static void Et_setgainG(struct gspca_dev *gspca_dev, __u8 gain)
728 struct sd *sd = (struct sd *) gspca_dev;
730 if (sd->sensor == SENSOR_PAS106) {
731 __u8 i2cflags = 0x01;
733 i2c_w(gspca_dev, PAS106_REG13, &i2cflags, 1, 3);
734 i2c_w(gspca_dev, PAS106_REG0e, &gain, 1, 1);
738 #define BLIMIT(bright) \
739 (__u8)((bright > 0x1f)?0x1f:((bright < 4)?3:bright))
740 #define LIMIT(color) \
741 (unsigned char)((color > 0xff)?0xff:((color < 0)?0:color))
743 static void do_autogain(struct gspca_dev *gspca_dev)
745 struct sd *sd = (struct sd *) gspca_dev;
747 __u8 luma_mean = 128;
748 __u8 luma_delta = 20;
755 if (--sd->ag_cnt >= 0)
757 sd->ag_cnt = AG_CNT_START;
759 Gbright = Et_getgainG(gspca_dev);
760 reg_r(gspca_dev, ET_LUMA_CENTER, 4);
761 g = (gspca_dev->usb_buf[0] + gspca_dev->usb_buf[3]) >> 1;
762 r = gspca_dev->usb_buf[1];
763 b = gspca_dev->usb_buf[2];
764 r = ((r << 8) - (r << 4) - (r << 3)) >> 10;
765 b = ((b << 7) >> 10);
766 g = ((g << 9) + (g << 7) + (g << 5)) >> 10;
767 luma = LIMIT(r + g + b);
768 PDEBUG(D_FRAM, "Etoms luma G %d", luma);
769 if (luma < luma_mean - luma_delta || luma > luma_mean + luma_delta) {
770 Gbright += (luma_mean - luma) >> spring;
771 Gbright = BLIMIT(Gbright);
772 PDEBUG(D_FRAM, "Etoms Gbright %d", Gbright);
773 Et_setgainG(gspca_dev, (__u8) Gbright);
780 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
781 struct gspca_frame *frame, /* target */
782 __u8 *data, /* isoc packet */
783 int len) /* iso packet length */
787 seqframe = data[0] & 0x3f;
788 len = (int) (((data[0] & 0xc0) << 2) | data[1]);
789 if (seqframe == 0x3f) {
791 "header packet found datalength %d !!", len);
792 PDEBUG(D_FRAM, "G %d R %d G %d B %d",
793 data[2], data[3], data[4], data[5]);
795 /* don't change datalength as the chips provided it */
796 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
798 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
803 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
804 } else { /* Drop Packet */
805 gspca_dev->last_packet_type = DISCARD_PACKET;
809 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
811 struct sd *sd = (struct sd *) gspca_dev;
813 sd->brightness = val;
814 if (gspca_dev->streaming)
815 setbrightness(gspca_dev);
819 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
821 struct sd *sd = (struct sd *) gspca_dev;
823 getbrightness(gspca_dev);
824 *val = sd->brightness;
828 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
830 struct sd *sd = (struct sd *) gspca_dev;
833 if (gspca_dev->streaming)
834 setcontrast(gspca_dev);
838 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
840 struct sd *sd = (struct sd *) gspca_dev;
842 getcontrast(gspca_dev);
847 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
849 struct sd *sd = (struct sd *) gspca_dev;
852 if (gspca_dev->streaming)
853 setcolors(gspca_dev);
857 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
859 struct sd *sd = (struct sd *) gspca_dev;
861 getcolors(gspca_dev);
866 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
868 struct sd *sd = (struct sd *) gspca_dev;
871 if (gspca_dev->streaming)
872 setautogain(gspca_dev);
876 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
878 struct sd *sd = (struct sd *) gspca_dev;
884 /* sub-driver description */
885 static struct sd_desc sd_desc = {
888 .nctrls = ARRAY_SIZE(sd_ctrls),
893 .pkt_scan = sd_pkt_scan,
894 .dq_callback = do_autogain,
897 /* -- module initialisation -- */
898 static __devinitdata struct usb_device_id device_table[] = {
899 {USB_DEVICE(0x102c, 0x6151), .driver_info = SENSOR_PAS106},
900 #if !defined CONFIG_USB_ET61X251 && !defined CONFIG_USB_ET61X251_MODULE
901 {USB_DEVICE(0x102c, 0x6251), .driver_info = SENSOR_TAS5130CXX},
906 MODULE_DEVICE_TABLE(usb, device_table);
908 /* -- device connect -- */
909 static int sd_probe(struct usb_interface *intf,
910 const struct usb_device_id *id)
912 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
916 static struct usb_driver sd_driver = {
918 .id_table = device_table,
920 .disconnect = gspca_disconnect,
922 .suspend = gspca_suspend,
923 .resume = gspca_resume,
927 /* -- module insert / remove -- */
928 static int __init sd_mod_init(void)
930 if (usb_register(&sd_driver) < 0)
932 PDEBUG(D_PROBE, "registered");
936 static void __exit sd_mod_exit(void)
938 usb_deregister(&sd_driver);
939 PDEBUG(D_PROBE, "deregistered");
942 module_init(sd_mod_init);
943 module_exit(sd_mod_exit);