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,
86 .id = V4L2_CID_SATURATION,
87 .type = V4L2_CTRL_TYPE_INTEGER,
93 .default_value = COLOR_DEF,
100 .id = V4L2_CID_AUTOGAIN,
101 .type = V4L2_CTRL_TYPE_BOOLEAN,
106 #define AUTOGAIN_DEF 1
107 .default_value = AUTOGAIN_DEF,
109 .set = sd_setautogain,
110 .get = sd_getautogain,
114 static struct v4l2_pix_format vga_mode[] = {
115 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
117 .sizeimage = 320 * 240,
118 .colorspace = V4L2_COLORSPACE_SRGB,
120 /* {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
122 .sizeimage = 640 * 480,
123 .colorspace = V4L2_COLORSPACE_SRGB,
127 static struct v4l2_pix_format sif_mode[] = {
128 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
130 .sizeimage = 176 * 144,
131 .colorspace = V4L2_COLORSPACE_SRGB,
133 {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
135 .sizeimage = 352 * 288,
136 .colorspace = V4L2_COLORSPACE_SRGB,
140 #define ETOMS_ALT_SIZE_1000 12
142 #define ET_GPIO_DIR_CTRL 0x04 /* Control IO bit[0..5] (0 in 1 out) */
143 #define ET_GPIO_OUT 0x05 /* Only IO data */
144 #define ET_GPIO_IN 0x06 /* Read Only IO data */
145 #define ET_RESET_ALL 0x03
147 #define ET_CTRL 0x02 /* enable i2c OutClck Powerdown mode */
149 #define ET_COMP 0x12 /* Compression register */
150 #define ET_MAXQt 0x13
151 #define ET_MINQt 0x14
152 #define ET_COMP_VAL0 0x02
153 #define ET_COMP_VAL1 0x03
155 #define ET_REG1d 0x1d
156 #define ET_REG1e 0x1e
157 #define ET_REG1f 0x1f
158 #define ET_REG20 0x20
159 #define ET_REG21 0x21
160 #define ET_REG22 0x22
161 #define ET_REG23 0x23
162 #define ET_REG24 0x24
163 #define ET_REG25 0x25
164 /* base registers for luma calculation */
165 #define ET_LUMA_CENTER 0x39
167 #define ET_G_RED 0x4d
168 #define ET_G_GREEN1 0x4e
169 #define ET_G_BLUE 0x4f
170 #define ET_G_GREEN2 0x50
171 #define ET_G_GR_H 0x51
172 #define ET_G_GB_H 0x52
174 #define ET_O_RED 0x34
175 #define ET_O_GREEN1 0x35
176 #define ET_O_BLUE 0x36
177 #define ET_O_GREEN2 0x37
179 #define ET_SYNCHRO 0x68
180 #define ET_STARTX 0x69
181 #define ET_STARTY 0x6a
182 #define ET_WIDTH_LOW 0x6b
183 #define ET_HEIGTH_LOW 0x6c
184 #define ET_W_H_HEIGTH 0x6d
186 #define ET_REG6e 0x6e /* OBW */
187 #define ET_REG6f 0x6f /* OBW */
188 #define ET_REG70 0x70 /* OBW_AWB */
189 #define ET_REG71 0x71 /* OBW_AWB */
190 #define ET_REG72 0x72 /* OBW_AWB */
191 #define ET_REG73 0x73 /* Clkdelay ns */
192 #define ET_REG74 0x74 /* test pattern */
193 #define ET_REG75 0x75 /* test pattern */
195 #define ET_I2C_CLK 0x8c
196 #define ET_PXL_CLK 0x60
198 #define ET_I2C_BASE 0x89
199 #define ET_I2C_COUNT 0x8a
200 #define ET_I2C_PREFETCH 0x8b
201 #define ET_I2C_REG 0x88
202 #define ET_I2C_DATA7 0x87
203 #define ET_I2C_DATA6 0x86
204 #define ET_I2C_DATA5 0x85
205 #define ET_I2C_DATA4 0x84
206 #define ET_I2C_DATA3 0x83
207 #define ET_I2C_DATA2 0x82
208 #define ET_I2C_DATA1 0x81
209 #define ET_I2C_DATA0 0x80
211 #define PAS106_REG2 0x02 /* pxlClk = systemClk/(reg2) */
212 #define PAS106_REG3 0x03 /* line/frame H [11..4] */
213 #define PAS106_REG4 0x04 /* line/frame L [3..0] */
214 #define PAS106_REG5 0x05 /* exposure time line offset(default 5) */
215 #define PAS106_REG6 0x06 /* exposure time pixel offset(default 6) */
216 #define PAS106_REG7 0x07 /* signbit Dac (default 0) */
217 #define PAS106_REG9 0x09
218 #define PAS106_REG0e 0x0e /* global gain [4..0](default 0x0e) */
219 #define PAS106_REG13 0x13 /* end i2c write */
221 static const __u8 GainRGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
223 static const __u8 I2c2[] = { 0x08, 0x08, 0x08, 0x08, 0x0d };
225 static const __u8 I2c3[] = { 0x12, 0x05 };
227 static const __u8 I2c4[] = { 0x41, 0x08 };
229 /* read 'len' bytes to gspca_dev->usb_buf */
230 static void reg_r(struct gspca_dev *gspca_dev,
234 struct usb_device *dev = gspca_dev->dev;
237 if (len > sizeof gspca_dev->usb_buf) {
238 err("reg_r: buffer overflow");
243 usb_rcvctrlpipe(dev, 0),
245 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
247 index, gspca_dev->usb_buf, len, 500);
248 PDEBUG(D_USBI, "reg read [%02x] -> %02x ..",
249 index, gspca_dev->usb_buf[0]);
252 static void reg_w_val(struct gspca_dev *gspca_dev,
256 struct usb_device *dev = gspca_dev->dev;
258 gspca_dev->usb_buf[0] = val;
260 usb_sndctrlpipe(dev, 0),
262 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
264 index, gspca_dev->usb_buf, 1, 500);
267 static void reg_w(struct gspca_dev *gspca_dev,
272 struct usb_device *dev = gspca_dev->dev;
275 if (len > sizeof gspca_dev->usb_buf) {
276 err("reg_w: buffer overflow");
279 PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer);
281 memcpy(gspca_dev->usb_buf, buffer, len);
283 usb_sndctrlpipe(dev, 0),
285 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
286 0, index, gspca_dev->usb_buf, len, 500);
289 static int i2c_w(struct gspca_dev *gspca_dev,
294 /* buffer should be [D0..D7] */
297 /* set the base address */
298 reg_w_val(gspca_dev, ET_I2C_BASE, 0x40);
299 /* sensor base for the pas106 */
300 /* set count and prefetch */
301 ptchcount = ((len & 0x07) << 4) | (mode & 0x03);
302 reg_w_val(gspca_dev, ET_I2C_COUNT, ptchcount);
303 /* set the register base */
304 reg_w_val(gspca_dev, ET_I2C_REG, reg);
306 reg_w_val(gspca_dev, ET_I2C_DATA0 + len, buffer[len]);
310 static int i2c_r(struct gspca_dev *gspca_dev,
313 /* set the base address */
314 reg_w_val(gspca_dev, ET_I2C_BASE, 0x40);
315 /* sensor base for the pas106 */
316 /* set count and prefetch (cnd: 4 bits - mode: 4 bits) */
317 reg_w_val(gspca_dev, ET_I2C_COUNT, 0x11);
318 reg_w_val(gspca_dev, ET_I2C_REG, reg); /* set the register base */
319 reg_w_val(gspca_dev, ET_I2C_PREFETCH, 0x02); /* prefetch */
320 reg_w_val(gspca_dev, ET_I2C_PREFETCH, 0x00);
321 reg_r(gspca_dev, ET_I2C_DATA0, 1); /* read one byte */
325 static int Et_WaitStatus(struct gspca_dev *gspca_dev)
330 reg_r(gspca_dev, ET_ClCK, 1);
331 if (gspca_dev->usb_buf[0] != 0)
337 static int et_video(struct gspca_dev *gspca_dev,
342 reg_w_val(gspca_dev, ET_GPIO_OUT,
343 on ? 0x10 /* startvideo - set Bit5 */
344 : 0); /* stopvideo */
345 ret = Et_WaitStatus(gspca_dev);
347 PDEBUG(D_ERR, "timeout video on/off");
351 static void Et_init2(struct gspca_dev *gspca_dev)
354 static const __u8 FormLine[] = { 0x84, 0x03, 0x14, 0xf4, 0x01, 0x05 };
356 PDEBUG(D_STREAM, "Open Init2 ET");
357 reg_w_val(gspca_dev, ET_GPIO_DIR_CTRL, 0x2f);
358 reg_w_val(gspca_dev, ET_GPIO_OUT, 0x10);
359 reg_r(gspca_dev, ET_GPIO_IN, 1);
360 reg_w_val(gspca_dev, ET_ClCK, 0x14); /* 0x14 // 0x16 enabled pattern */
361 reg_w_val(gspca_dev, ET_CTRL, 0x1b);
363 /* compression et subsampling */
364 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
365 value = ET_COMP_VAL1; /* 320 */
367 value = ET_COMP_VAL0; /* 640 */
368 reg_w_val(gspca_dev, ET_COMP, value);
369 reg_w_val(gspca_dev, ET_MAXQt, 0x1f);
370 reg_w_val(gspca_dev, ET_MINQt, 0x04);
371 /* undocumented registers */
372 reg_w_val(gspca_dev, ET_REG1d, 0xff);
373 reg_w_val(gspca_dev, ET_REG1e, 0xff);
374 reg_w_val(gspca_dev, ET_REG1f, 0xff);
375 reg_w_val(gspca_dev, ET_REG20, 0x35);
376 reg_w_val(gspca_dev, ET_REG21, 0x01);
377 reg_w_val(gspca_dev, ET_REG22, 0x00);
378 reg_w_val(gspca_dev, ET_REG23, 0xff);
379 reg_w_val(gspca_dev, ET_REG24, 0xff);
380 reg_w_val(gspca_dev, ET_REG25, 0x0f);
382 reg_w_val(gspca_dev, 0x30, 0x11); /* 0x30 */
383 reg_w_val(gspca_dev, 0x31, 0x40);
384 reg_w_val(gspca_dev, 0x32, 0x00);
385 reg_w_val(gspca_dev, ET_O_RED, 0x00); /* 0x34 */
386 reg_w_val(gspca_dev, ET_O_GREEN1, 0x00);
387 reg_w_val(gspca_dev, ET_O_BLUE, 0x00);
388 reg_w_val(gspca_dev, ET_O_GREEN2, 0x00);
390 reg_w_val(gspca_dev, ET_G_RED, 0x80); /* 0x4d */
391 reg_w_val(gspca_dev, ET_G_GREEN1, 0x80);
392 reg_w_val(gspca_dev, ET_G_BLUE, 0x80);
393 reg_w_val(gspca_dev, ET_G_GREEN2, 0x80);
394 reg_w_val(gspca_dev, ET_G_GR_H, 0x00);
395 reg_w_val(gspca_dev, ET_G_GB_H, 0x00); /* 0x52 */
396 /* Window control registers */
397 reg_w_val(gspca_dev, 0x61, 0x80); /* use cmc_out */
398 reg_w_val(gspca_dev, 0x62, 0x02);
399 reg_w_val(gspca_dev, 0x63, 0x03);
400 reg_w_val(gspca_dev, 0x64, 0x14);
401 reg_w_val(gspca_dev, 0x65, 0x0e);
402 reg_w_val(gspca_dev, 0x66, 0x02);
403 reg_w_val(gspca_dev, 0x67, 0x02);
405 /**************************************/
406 reg_w_val(gspca_dev, ET_SYNCHRO, 0x8f); /* 0x68 */
407 reg_w_val(gspca_dev, ET_STARTX, 0x69); /* 0x6a //0x69 */
408 reg_w_val(gspca_dev, ET_STARTY, 0x0d); /* 0x0d //0x0c */
409 reg_w_val(gspca_dev, ET_WIDTH_LOW, 0x80);
410 reg_w_val(gspca_dev, ET_HEIGTH_LOW, 0xe0);
411 reg_w_val(gspca_dev, ET_W_H_HEIGTH, 0x60); /* 6d */
412 reg_w_val(gspca_dev, ET_REG6e, 0x86);
413 reg_w_val(gspca_dev, ET_REG6f, 0x01);
414 reg_w_val(gspca_dev, ET_REG70, 0x26);
415 reg_w_val(gspca_dev, ET_REG71, 0x7a);
416 reg_w_val(gspca_dev, ET_REG72, 0x01);
417 /* Clock Pattern registers ***************** */
418 reg_w_val(gspca_dev, ET_REG73, 0x00);
419 reg_w_val(gspca_dev, ET_REG74, 0x18); /* 0x28 */
420 reg_w_val(gspca_dev, ET_REG75, 0x0f); /* 0x01 */
421 /**********************************************/
422 reg_w_val(gspca_dev, 0x8a, 0x20);
423 reg_w_val(gspca_dev, 0x8d, 0x0f);
424 reg_w_val(gspca_dev, 0x8e, 0x08);
425 /**************************************/
426 reg_w_val(gspca_dev, 0x03, 0x08);
427 reg_w_val(gspca_dev, ET_PXL_CLK, 0x03);
428 reg_w_val(gspca_dev, 0x81, 0xff);
429 reg_w_val(gspca_dev, 0x80, 0x00);
430 reg_w_val(gspca_dev, 0x81, 0xff);
431 reg_w_val(gspca_dev, 0x80, 0x20);
432 reg_w_val(gspca_dev, 0x03, 0x01);
433 reg_w_val(gspca_dev, 0x03, 0x00);
434 reg_w_val(gspca_dev, 0x03, 0x08);
435 /********************************************/
437 /* reg_r(gspca_dev, ET_I2C_BASE, 1);
438 always 0x40 as the pas106 ??? */
440 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
441 value = 0x04; /* 320 */
443 value = 0x1e; /* 0x17 * setting PixelClock
444 * 0x03 mean 24/(3+1) = 6 Mhz
445 * 0x05 -> 24/(5+1) = 4 Mhz
446 * 0x0b -> 24/(11+1) = 2 Mhz
447 * 0x17 -> 24/(23+1) = 1 Mhz
449 reg_w_val(gspca_dev, ET_PXL_CLK, value);
450 /* now set by fifo the FormatLine setting */
451 reg_w(gspca_dev, 0x62, FormLine, 6);
453 /* set exposure times [ 0..0x78] 0->longvalue 0x78->shortvalue */
454 reg_w_val(gspca_dev, 0x81, 0x47); /* 0x47; */
455 reg_w_val(gspca_dev, 0x80, 0x40); /* 0x40; */
457 /* Brightness change Brith+ decrease value */
458 /* Brigth- increase value */
459 /* original value = 0x70; */
460 reg_w_val(gspca_dev, 0x81, 0x30); /* 0x20; - set brightness */
461 reg_w_val(gspca_dev, 0x80, 0x20); /* 0x20; */
464 static void setbrightness(struct gspca_dev *gspca_dev)
466 struct sd *sd = (struct sd *) gspca_dev;
468 __u8 brightness = sd->brightness;
470 for (i = 0; i < 4; i++)
471 reg_w_val(gspca_dev, ET_O_RED + i, brightness);
474 static void getbrightness(struct gspca_dev *gspca_dev)
476 struct sd *sd = (struct sd *) gspca_dev;
480 for (i = 0; i < 4; i++) {
481 reg_r(gspca_dev, ET_O_RED + i, 1);
482 brightness += gspca_dev->usb_buf[0];
484 sd->brightness = brightness >> 3;
487 static void setcontrast(struct gspca_dev *gspca_dev)
489 struct sd *sd = (struct sd *) gspca_dev;
490 __u8 RGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
491 __u8 contrast = sd->contrast;
493 memset(RGBG, contrast, sizeof(RGBG) - 2);
494 reg_w(gspca_dev, ET_G_RED, RGBG, 6);
497 static void getcontrast(struct gspca_dev *gspca_dev)
499 struct sd *sd = (struct sd *) gspca_dev;
503 for (i = 0; i < 4; i++) {
504 reg_r(gspca_dev, ET_G_RED + i, 1);
505 contrast += gspca_dev->usb_buf[0];
507 sd->contrast = contrast >> 2;
510 static void setcolors(struct gspca_dev *gspca_dev)
512 struct sd *sd = (struct sd *) gspca_dev;
513 __u8 I2cc[] = { 0x05, 0x02, 0x02, 0x05, 0x0d };
514 __u8 i2cflags = 0x01;
515 /* __u8 green = 0; */
516 __u8 colors = sd->colors;
518 I2cc[3] = colors; /* red */
519 I2cc[0] = 15 - colors; /* blue */
520 /* green = 15 - ((((7*I2cc[0]) >> 2 ) + I2cc[3]) >> 1); */
521 /* I2cc[1] = I2cc[2] = green; */
522 if (sd->sensor == SENSOR_PAS106) {
523 i2c_w(gspca_dev, PAS106_REG13, &i2cflags, 1, 3);
524 i2c_w(gspca_dev, PAS106_REG9, I2cc, sizeof I2cc, 1);
526 /* PDEBUG(D_CONF , "Etoms red %d blue %d green %d",
527 I2cc[3], I2cc[0], green); */
530 static void getcolors(struct gspca_dev *gspca_dev)
532 struct sd *sd = (struct sd *) gspca_dev;
534 if (sd->sensor == SENSOR_PAS106) {
535 /* i2c_r(gspca_dev, PAS106_REG9); * blue */
536 i2c_r(gspca_dev, PAS106_REG9 + 3); /* red */
537 sd->colors = gspca_dev->usb_buf[0] & 0x0f;
541 static void setautogain(struct gspca_dev *gspca_dev)
543 struct sd *sd = (struct sd *) gspca_dev;
546 sd->ag_cnt = AG_CNT_START;
551 static void Et_init1(struct gspca_dev *gspca_dev)
554 /* __u8 I2c0 [] = {0x0a, 0x12, 0x05, 0x22, 0xac, 0x00, 0x01, 0x00}; */
555 __u8 I2c0[] = { 0x0a, 0x12, 0x05, 0x6d, 0xcd, 0x00, 0x01, 0x00 };
556 /* try 1/120 0x6d 0xcd 0x40 */
557 /* __u8 I2c0 [] = {0x0a, 0x12, 0x05, 0xfe, 0xfe, 0xc0, 0x01, 0x00};
560 PDEBUG(D_STREAM, "Open Init1 ET");
561 reg_w_val(gspca_dev, ET_GPIO_DIR_CTRL, 7);
562 reg_r(gspca_dev, ET_GPIO_IN, 1);
563 reg_w_val(gspca_dev, ET_RESET_ALL, 1);
564 reg_w_val(gspca_dev, ET_RESET_ALL, 0);
565 reg_w_val(gspca_dev, ET_ClCK, 0x10);
566 reg_w_val(gspca_dev, ET_CTRL, 0x19);
567 /* compression et subsampling */
568 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
569 value = ET_COMP_VAL1;
571 value = ET_COMP_VAL0;
572 PDEBUG(D_STREAM, "Open mode %d Compression %d",
573 gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv,
575 reg_w_val(gspca_dev, ET_COMP, value);
576 reg_w_val(gspca_dev, ET_MAXQt, 0x1d);
577 reg_w_val(gspca_dev, ET_MINQt, 0x02);
578 /* undocumented registers */
579 reg_w_val(gspca_dev, ET_REG1d, 0xff);
580 reg_w_val(gspca_dev, ET_REG1e, 0xff);
581 reg_w_val(gspca_dev, ET_REG1f, 0xff);
582 reg_w_val(gspca_dev, ET_REG20, 0x35);
583 reg_w_val(gspca_dev, ET_REG21, 0x01);
584 reg_w_val(gspca_dev, ET_REG22, 0x00);
585 reg_w_val(gspca_dev, ET_REG23, 0xf7);
586 reg_w_val(gspca_dev, ET_REG24, 0xff);
587 reg_w_val(gspca_dev, ET_REG25, 0x07);
589 reg_w_val(gspca_dev, ET_G_RED, 0x80);
590 reg_w_val(gspca_dev, ET_G_GREEN1, 0x80);
591 reg_w_val(gspca_dev, ET_G_BLUE, 0x80);
592 reg_w_val(gspca_dev, ET_G_GREEN2, 0x80);
593 reg_w_val(gspca_dev, ET_G_GR_H, 0x00);
594 reg_w_val(gspca_dev, ET_G_GB_H, 0x00);
595 /* Window control registers */
596 reg_w_val(gspca_dev, ET_SYNCHRO, 0xf0);
597 reg_w_val(gspca_dev, ET_STARTX, 0x56); /* 0x56 */
598 reg_w_val(gspca_dev, ET_STARTY, 0x05); /* 0x04 */
599 reg_w_val(gspca_dev, ET_WIDTH_LOW, 0x60);
600 reg_w_val(gspca_dev, ET_HEIGTH_LOW, 0x20);
601 reg_w_val(gspca_dev, ET_W_H_HEIGTH, 0x50);
602 reg_w_val(gspca_dev, ET_REG6e, 0x86);
603 reg_w_val(gspca_dev, ET_REG6f, 0x01);
604 reg_w_val(gspca_dev, ET_REG70, 0x86);
605 reg_w_val(gspca_dev, ET_REG71, 0x14);
606 reg_w_val(gspca_dev, ET_REG72, 0x00);
607 /* Clock Pattern registers */
608 reg_w_val(gspca_dev, ET_REG73, 0x00);
609 reg_w_val(gspca_dev, ET_REG74, 0x00);
610 reg_w_val(gspca_dev, ET_REG75, 0x0a);
611 reg_w_val(gspca_dev, ET_I2C_CLK, 0x04);
612 reg_w_val(gspca_dev, ET_PXL_CLK, 0x01);
614 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
616 i2c_w(gspca_dev, PAS106_REG2, I2c0, sizeof I2c0, 1);
617 i2c_w(gspca_dev, PAS106_REG9, I2c2, sizeof I2c2, 1);
619 i2c_w(gspca_dev, PAS106_REG2, &value, 1, 1);
620 i2c_w(gspca_dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
623 i2c_w(gspca_dev, PAS106_REG0e, &value, 1, 1);
627 i2c_w(gspca_dev, PAS106_REG2, I2c0, sizeof I2c0, 1);
628 i2c_w(gspca_dev, PAS106_REG9, I2c2, sizeof I2c2, 1);
630 i2c_w(gspca_dev, PAS106_REG2, &value, 1, 1);
631 i2c_w(gspca_dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
634 i2c_w(gspca_dev, PAS106_REG0e, &value, 1, 1);
635 /* bit 2 enable bit 1:2 select 0 1 2 3
636 value = 0x07; * curve 0 *
637 i2c_w(gspca_dev, PAS106_REG0f, &value, 1, 1);
643 /* i2c_w(gspca_dev, PAS106_REG5, &value, 1, 1); */
644 /* magnetude and sign bit for DAC */
645 i2c_w(gspca_dev, PAS106_REG7, I2c4, sizeof I2c4, 1);
646 /* now set by fifo the whole colors setting */
647 reg_w(gspca_dev, ET_G_RED, GainRGBG, 6);
648 getcolors(gspca_dev);
649 setcolors(gspca_dev);
652 /* this function is called at probe time */
653 static int sd_config(struct gspca_dev *gspca_dev,
654 const struct usb_device_id *id)
656 struct sd *sd = (struct sd *) gspca_dev;
659 cam = &gspca_dev->cam;
661 sd->sensor = id->driver_info;
662 if (sd->sensor == SENSOR_PAS106) {
663 cam->cam_mode = sif_mode;
664 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
666 cam->cam_mode = vga_mode;
667 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
669 sd->brightness = BRIGHTNESS_DEF;
670 sd->contrast = CONTRAST_DEF;
671 sd->colors = COLOR_DEF;
672 sd->autogain = AUTOGAIN_DEF;
677 /* this function is called at open time */
678 static int sd_open(struct gspca_dev *gspca_dev)
680 struct sd *sd = (struct sd *) gspca_dev;
682 if (sd->sensor == SENSOR_PAS106)
686 reg_w_val(gspca_dev, ET_RESET_ALL, 0x08);
687 et_video(gspca_dev, 0); /* video off */
691 /* -- start the camera -- */
692 static void sd_start(struct gspca_dev *gspca_dev)
694 struct sd *sd = (struct sd *) gspca_dev;
696 if (sd->sensor == SENSOR_PAS106)
701 setautogain(gspca_dev);
703 reg_w_val(gspca_dev, ET_RESET_ALL, 0x08);
704 et_video(gspca_dev, 1); /* video on */
707 static void sd_stopN(struct gspca_dev *gspca_dev)
709 et_video(gspca_dev, 0); /* video off */
712 static void sd_stop0(struct gspca_dev *gspca_dev)
716 static void sd_close(struct gspca_dev *gspca_dev)
720 static __u8 Et_getgainG(struct gspca_dev *gspca_dev)
722 struct sd *sd = (struct sd *) gspca_dev;
724 if (sd->sensor == SENSOR_PAS106) {
725 i2c_r(gspca_dev, PAS106_REG0e);
726 PDEBUG(D_CONF, "Etoms gain G %d", gspca_dev->usb_buf[0]);
727 return gspca_dev->usb_buf[0];
732 static void Et_setgainG(struct gspca_dev *gspca_dev, __u8 gain)
734 struct sd *sd = (struct sd *) gspca_dev;
736 if (sd->sensor == SENSOR_PAS106) {
737 __u8 i2cflags = 0x01;
739 i2c_w(gspca_dev, PAS106_REG13, &i2cflags, 1, 3);
740 i2c_w(gspca_dev, PAS106_REG0e, &gain, 1, 1);
744 #define BLIMIT(bright) \
745 (__u8)((bright > 0x1f)?0x1f:((bright < 4)?3:bright))
746 #define LIMIT(color) \
747 (unsigned char)((color > 0xff)?0xff:((color < 0)?0:color))
749 static void do_autogain(struct gspca_dev *gspca_dev)
751 struct sd *sd = (struct sd *) gspca_dev;
753 __u8 luma_mean = 128;
754 __u8 luma_delta = 20;
761 if (--sd->ag_cnt >= 0)
763 sd->ag_cnt = AG_CNT_START;
765 Gbright = Et_getgainG(gspca_dev);
766 reg_r(gspca_dev, ET_LUMA_CENTER, 4);
767 g = (gspca_dev->usb_buf[0] + gspca_dev->usb_buf[3]) >> 1;
768 r = gspca_dev->usb_buf[1];
769 b = gspca_dev->usb_buf[2];
770 r = ((r << 8) - (r << 4) - (r << 3)) >> 10;
771 b = ((b << 7) >> 10);
772 g = ((g << 9) + (g << 7) + (g << 5)) >> 10;
773 luma = LIMIT(r + g + b);
774 PDEBUG(D_FRAM, "Etoms luma G %d", luma);
775 if (luma < luma_mean - luma_delta || luma > luma_mean + luma_delta) {
776 Gbright += (luma_mean - luma) >> spring;
777 Gbright = BLIMIT(Gbright);
778 PDEBUG(D_FRAM, "Etoms Gbright %d", Gbright);
779 Et_setgainG(gspca_dev, (__u8) Gbright);
786 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
787 struct gspca_frame *frame, /* target */
788 __u8 *data, /* isoc packet */
789 int len) /* iso packet length */
793 seqframe = data[0] & 0x3f;
794 len = (int) (((data[0] & 0xc0) << 2) | data[1]);
795 if (seqframe == 0x3f) {
797 "header packet found datalength %d !!", len);
798 PDEBUG(D_FRAM, "G %d R %d G %d B %d",
799 data[2], data[3], data[4], data[5]);
801 /* don't change datalength as the chips provided it */
802 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
804 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
809 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
810 } else { /* Drop Packet */
811 gspca_dev->last_packet_type = DISCARD_PACKET;
815 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
817 struct sd *sd = (struct sd *) gspca_dev;
819 sd->brightness = val;
820 if (gspca_dev->streaming)
821 setbrightness(gspca_dev);
825 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
827 struct sd *sd = (struct sd *) gspca_dev;
829 getbrightness(gspca_dev);
830 *val = sd->brightness;
834 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
836 struct sd *sd = (struct sd *) gspca_dev;
839 if (gspca_dev->streaming)
840 setcontrast(gspca_dev);
844 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
846 struct sd *sd = (struct sd *) gspca_dev;
848 getcontrast(gspca_dev);
853 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
855 struct sd *sd = (struct sd *) gspca_dev;
858 if (gspca_dev->streaming)
859 setcolors(gspca_dev);
863 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
865 struct sd *sd = (struct sd *) gspca_dev;
867 getcolors(gspca_dev);
872 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
874 struct sd *sd = (struct sd *) gspca_dev;
877 if (gspca_dev->streaming)
878 setautogain(gspca_dev);
882 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
884 struct sd *sd = (struct sd *) gspca_dev;
890 /* sub-driver description */
891 static struct sd_desc sd_desc = {
894 .nctrls = ARRAY_SIZE(sd_ctrls),
901 .pkt_scan = sd_pkt_scan,
902 .dq_callback = do_autogain,
905 /* -- module initialisation -- */
906 static __devinitdata struct usb_device_id device_table[] = {
907 #ifndef CONFIG_USB_ET61X251
908 {USB_DEVICE(0x102c, 0x6151), .driver_info = SENSOR_PAS106},
910 {USB_DEVICE(0x102c, 0x6251), .driver_info = SENSOR_TAS5130CXX},
914 MODULE_DEVICE_TABLE(usb, device_table);
916 /* -- device connect -- */
917 static int sd_probe(struct usb_interface *intf,
918 const struct usb_device_id *id)
920 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
924 static struct usb_driver sd_driver = {
926 .id_table = device_table,
928 .disconnect = gspca_disconnect,
931 /* -- module insert / remove -- */
932 static int __init sd_mod_init(void)
934 if (usb_register(&sd_driver) < 0)
936 PDEBUG(D_PROBE, "registered");
940 static void __exit sd_mod_exit(void)
942 usb_deregister(&sd_driver);
943 PDEBUG(D_PROBE, "deregistered");
946 module_init(sd_mod_init);
947 module_exit(sd_mod_exit);