21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #define MODULE_NAME "etoms"
38 #define SENSOR_PAS106 0
39 #define SENSOR_TAS5130CXX 1
41 #define AG_CNT_START 13
47 .sizeimage = 320 * 240,
60 .sizeimage = 176 * 144,
65 .sizeimage = 352 * 288,
70 #define ETOMS_ALT_SIZE_1000 12
72 #define ET_GPIO_DIR_CTRL 0x04
73 #define ET_GPIO_OUT 0x05
74 #define ET_GPIO_IN 0x06
75 #define ET_RESET_ALL 0x03
82 #define ET_COMP_VAL0 0x02
83 #define ET_COMP_VAL1 0x03
95 #define ET_LUMA_CENTER 0x39
98 #define ET_G_GREEN1 0x4e
99 #define ET_G_BLUE 0x4f
100 #define ET_G_GREEN2 0x50
101 #define ET_G_GR_H 0x51
102 #define ET_G_GB_H 0x52
104 #define ET_O_RED 0x34
105 #define ET_O_GREEN1 0x35
106 #define ET_O_BLUE 0x36
107 #define ET_O_GREEN2 0x37
109 #define ET_SYNCHRO 0x68
110 #define ET_STARTX 0x69
111 #define ET_STARTY 0x6a
112 #define ET_WIDTH_LOW 0x6b
113 #define ET_HEIGTH_LOW 0x6c
114 #define ET_W_H_HEIGTH 0x6d
116 #define ET_REG6e 0x6e
117 #define ET_REG6f 0x6f
118 #define ET_REG70 0x70
119 #define ET_REG71 0x71
120 #define ET_REG72 0x72
121 #define ET_REG73 0x73
122 #define ET_REG74 0x74
123 #define ET_REG75 0x75
125 #define ET_I2C_CLK 0x8c
126 #define ET_PXL_CLK 0x60
128 #define ET_I2C_BASE 0x89
129 #define ET_I2C_COUNT 0x8a
130 #define ET_I2C_PREFETCH 0x8b
131 #define ET_I2C_REG 0x88
132 #define ET_I2C_DATA7 0x87
133 #define ET_I2C_DATA6 0x86
134 #define ET_I2C_DATA5 0x85
135 #define ET_I2C_DATA4 0x84
136 #define ET_I2C_DATA3 0x83
137 #define ET_I2C_DATA2 0x82
138 #define ET_I2C_DATA1 0x81
139 #define ET_I2C_DATA0 0x80
141 #define PAS106_REG2 0x02
142 #define PAS106_REG3 0x03
143 #define PAS106_REG4 0x04
144 #define PAS106_REG5 0x05
145 #define PAS106_REG6 0x06
146 #define PAS106_REG7 0x07
147 #define PAS106_REG9 0x09
148 #define PAS106_REG0e 0x0e
149 #define PAS106_REG13 0x13
151 static const __u8 GainRGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
153 static const __u8 I2c2[] = { 0x08, 0x08, 0x08, 0x08, 0x0d };
155 static const __u8 I2c3[] = { 0x12, 0x05 };
157 static const __u8 I2c4[] = { 0x41, 0x08 };
164 struct usb_device *
dev = gspca_dev->
dev;
168 pr_err(
"reg_r: buffer overflow\n");
173 usb_rcvctrlpipe(dev, 0),
177 index, gspca_dev->
usb_buf, len, 500);
178 PDEBUG(D_USBI,
"reg read [%02x] -> %02x ..",
182 static void reg_w_val(
struct gspca_dev *gspca_dev,
186 struct usb_device *dev = gspca_dev->
dev;
190 usb_sndctrlpipe(dev, 0),
194 index, gspca_dev->
usb_buf, 1, 500);
197 static void reg_w(
struct gspca_dev *gspca_dev,
202 struct usb_device *dev = gspca_dev->
dev;
206 pr_err(
"reg_w: buffer overflow\n");
209 PDEBUG(D_USBO,
"reg write [%02x] = %02x..", index, *buffer);
213 usb_sndctrlpipe(dev, 0),
216 0, index, gspca_dev->
usb_buf, len, 500);
219 static int i2c_w(
struct gspca_dev *gspca_dev,
231 ptchcount = ((len & 0x07) << 4) | (mode & 0x03);
240 static int i2c_r(
struct gspca_dev *gspca_dev,
255 static int Et_WaitStatus(
struct gspca_dev *gspca_dev)
261 if (gspca_dev->
usb_buf[0] != 0)
267 static int et_video(
struct gspca_dev *gspca_dev,
275 ret = Et_WaitStatus(gspca_dev);
281 static void Et_init2(
struct gspca_dev *gspca_dev)
284 static const __u8 FormLine[] = { 0x84, 0x03, 0x14, 0xf4, 0x01, 0x05 };
286 PDEBUG(D_STREAM,
"Open Init2 ET");
290 reg_w_val(gspca_dev,
ET_ClCK, 0x14);
291 reg_w_val(gspca_dev,
ET_CTRL, 0x1b);
294 if (gspca_dev->
cam.cam_mode[(
int) gspca_dev->
curr_mode].priv)
298 reg_w_val(gspca_dev,
ET_COMP, value);
299 reg_w_val(gspca_dev,
ET_MAXQt, 0x1f);
300 reg_w_val(gspca_dev,
ET_MINQt, 0x04);
302 reg_w_val(gspca_dev,
ET_REG1d, 0xff);
303 reg_w_val(gspca_dev,
ET_REG1e, 0xff);
304 reg_w_val(gspca_dev,
ET_REG1f, 0xff);
305 reg_w_val(gspca_dev,
ET_REG20, 0x35);
306 reg_w_val(gspca_dev,
ET_REG21, 0x01);
307 reg_w_val(gspca_dev,
ET_REG22, 0x00);
308 reg_w_val(gspca_dev,
ET_REG23, 0xff);
309 reg_w_val(gspca_dev,
ET_REG24, 0xff);
310 reg_w_val(gspca_dev,
ET_REG25, 0x0f);
312 reg_w_val(gspca_dev, 0x30, 0x11);
313 reg_w_val(gspca_dev, 0x31, 0x40);
314 reg_w_val(gspca_dev, 0x32, 0x00);
315 reg_w_val(gspca_dev,
ET_O_RED, 0x00);
320 reg_w_val(gspca_dev,
ET_G_RED, 0x80);
327 reg_w_val(gspca_dev, 0x61, 0x80);
328 reg_w_val(gspca_dev, 0x62, 0x02);
329 reg_w_val(gspca_dev, 0x63, 0x03);
330 reg_w_val(gspca_dev, 0x64, 0x14);
331 reg_w_val(gspca_dev, 0x65, 0x0e);
332 reg_w_val(gspca_dev, 0x66, 0x02);
333 reg_w_val(gspca_dev, 0x67, 0x02);
343 reg_w_val(gspca_dev,
ET_REG6f, 0x01);
344 reg_w_val(gspca_dev,
ET_REG70, 0x26);
345 reg_w_val(gspca_dev,
ET_REG71, 0x7a);
346 reg_w_val(gspca_dev,
ET_REG72, 0x01);
348 reg_w_val(gspca_dev,
ET_REG73, 0x00);
349 reg_w_val(gspca_dev,
ET_REG74, 0x18);
350 reg_w_val(gspca_dev,
ET_REG75, 0x0f);
352 reg_w_val(gspca_dev, 0x8a, 0x20);
353 reg_w_val(gspca_dev, 0x8d, 0x0f);
354 reg_w_val(gspca_dev, 0x8e, 0x08);
356 reg_w_val(gspca_dev, 0x03, 0x08);
358 reg_w_val(gspca_dev, 0x81, 0xff);
359 reg_w_val(gspca_dev, 0x80, 0x00);
360 reg_w_val(gspca_dev, 0x81, 0xff);
361 reg_w_val(gspca_dev, 0x80, 0x20);
362 reg_w_val(gspca_dev, 0x03, 0x01);
363 reg_w_val(gspca_dev, 0x03, 0x00);
364 reg_w_val(gspca_dev, 0x03, 0x08);
370 if (gspca_dev->
cam.cam_mode[(
int) gspca_dev->
curr_mode].priv)
381 reg_w(gspca_dev, 0x62, FormLine, 6);
384 reg_w_val(gspca_dev, 0x81, 0x47);
385 reg_w_val(gspca_dev, 0x80, 0x40);
390 reg_w_val(gspca_dev, 0x81, 0x30);
391 reg_w_val(gspca_dev, 0x80, 0x20);
394 static void setbrightness(
struct gspca_dev *gspca_dev,
s32 val)
398 for (i = 0; i < 4; i++)
399 reg_w_val(gspca_dev,
ET_O_RED + i, val);
402 static void setcontrast(
struct gspca_dev *gspca_dev,
s32 val)
404 __u8 RGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
406 memset(RGBG, val,
sizeof(RGBG) - 2);
407 reg_w(gspca_dev,
ET_G_RED, RGBG, 6);
410 static void setcolors(
struct gspca_dev *gspca_dev,
s32 val)
412 struct sd *
sd = (
struct sd *) gspca_dev;
413 __u8 I2cc[] = { 0x05, 0x02, 0x02, 0x05, 0x0d };
414 __u8 i2cflags = 0x01;
423 i2c_w(gspca_dev,
PAS106_REG9, I2cc,
sizeof I2cc, 1);
429 static s32 getcolors(
struct gspca_dev *gspca_dev)
431 struct sd *sd = (
struct sd *) gspca_dev;
436 return gspca_dev->
usb_buf[0] & 0x0f;
441 static void setautogain(
struct gspca_dev *gspca_dev)
443 struct sd *sd = (
struct sd *) gspca_dev;
451 static void Et_init1(
struct gspca_dev *gspca_dev)
455 __u8 I2c0[] = { 0x0a, 0x12, 0x05, 0x6d, 0xcd, 0x00, 0x01, 0x00 };
460 PDEBUG(D_STREAM,
"Open Init1 ET");
465 reg_w_val(gspca_dev,
ET_ClCK, 0x10);
466 reg_w_val(gspca_dev,
ET_CTRL, 0x19);
468 if (gspca_dev->
cam.cam_mode[(
int) gspca_dev->
curr_mode].priv)
472 PDEBUG(D_STREAM,
"Open mode %d Compression %d",
473 gspca_dev->
cam.cam_mode[(
int) gspca_dev->
curr_mode].priv,
475 reg_w_val(gspca_dev,
ET_COMP, value);
476 reg_w_val(gspca_dev,
ET_MAXQt, 0x1d);
477 reg_w_val(gspca_dev,
ET_MINQt, 0x02);
479 reg_w_val(gspca_dev,
ET_REG1d, 0xff);
480 reg_w_val(gspca_dev,
ET_REG1e, 0xff);
481 reg_w_val(gspca_dev,
ET_REG1f, 0xff);
482 reg_w_val(gspca_dev,
ET_REG20, 0x35);
483 reg_w_val(gspca_dev,
ET_REG21, 0x01);
484 reg_w_val(gspca_dev,
ET_REG22, 0x00);
485 reg_w_val(gspca_dev,
ET_REG23, 0xf7);
486 reg_w_val(gspca_dev,
ET_REG24, 0xff);
487 reg_w_val(gspca_dev,
ET_REG25, 0x07);
489 reg_w_val(gspca_dev,
ET_G_RED, 0x80);
503 reg_w_val(gspca_dev,
ET_REG6f, 0x01);
505 reg_w_val(gspca_dev,
ET_REG71, 0x14);
506 reg_w_val(gspca_dev,
ET_REG72, 0x00);
508 reg_w_val(gspca_dev,
ET_REG73, 0x00);
509 reg_w_val(gspca_dev,
ET_REG74, 0x00);
510 reg_w_val(gspca_dev,
ET_REG75, 0x0a);
514 if (gspca_dev->
cam.cam_mode[(
int) gspca_dev->
curr_mode].priv) {
516 i2c_w(gspca_dev,
PAS106_REG2, I2c0,
sizeof I2c0, 1);
517 i2c_w(gspca_dev,
PAS106_REG9, I2c2,
sizeof I2c2, 1);
520 i2c_w(gspca_dev,
PAS106_REG3, I2c3,
sizeof I2c3, 1);
527 i2c_w(gspca_dev,
PAS106_REG2, I2c0,
sizeof I2c0, 1);
528 i2c_w(gspca_dev,
PAS106_REG9, I2c2,
sizeof I2c2, 1);
531 i2c_w(gspca_dev,
PAS106_REG3, I2c3,
sizeof I2c3, 1);
545 i2c_w(gspca_dev,
PAS106_REG7, I2c4,
sizeof I2c4, 1);
547 reg_w(gspca_dev,
ET_G_RED, GainRGBG, 6);
548 setcolors(gspca_dev, getcolors(gspca_dev));
552 static int sd_config(
struct gspca_dev *gspca_dev,
555 struct sd *sd = (
struct sd *) gspca_dev;
558 cam = &gspca_dev->
cam;
559 sd->
sensor =
id->driver_info;
572 static int sd_init(
struct gspca_dev *gspca_dev)
574 struct sd *sd = (
struct sd *) gspca_dev;
581 et_video(gspca_dev, 0);
586 static int sd_start(
struct gspca_dev *gspca_dev)
588 struct sd *sd = (
struct sd *) gspca_dev;
595 setautogain(gspca_dev);
598 et_video(gspca_dev, 1);
602 static void sd_stopN(
struct gspca_dev *gspca_dev)
604 et_video(gspca_dev, 0);
607 static __u8 Et_getgainG(
struct gspca_dev *gspca_dev)
609 struct sd *sd = (
struct sd *) gspca_dev;
619 static void Et_setgainG(
struct gspca_dev *gspca_dev,
__u8 gain)
621 struct sd *sd = (
struct sd *) gspca_dev;
624 __u8 i2cflags = 0x01;
631 #define BLIMIT(bright) \
632 (u8)((bright > 0x1f) ? 0x1f : ((bright < 4) ? 3 : bright))
633 #define LIMIT(color) \
634 (u8)((color > 0xff) ? 0xff : ((color < 0) ? 0 : color))
636 static void do_autogain(
struct gspca_dev *gspca_dev)
638 struct sd *sd = (
struct sd *) gspca_dev;
640 __u8 luma_mean = 128;
641 __u8 luma_delta = 20;
652 Gbright = Et_getgainG(gspca_dev);
657 r = ((r << 8) - (r << 4) - (r << 3)) >> 10;
658 b = ((b << 7) >> 10);
659 g = ((g << 9) + (g << 7) + (g << 5)) >> 10;
660 luma =
LIMIT(r + g + b);
661 PDEBUG(D_FRAM,
"Etoms luma G %d", luma);
662 if (luma < luma_mean - luma_delta || luma > luma_mean + luma_delta) {
663 Gbright += (luma_mean - luma) >> spring;
664 Gbright =
BLIMIT(Gbright);
665 PDEBUG(D_FRAM,
"Etoms Gbright %d", Gbright);
666 Et_setgainG(gspca_dev, (
__u8) Gbright);
673 static void sd_pkt_scan(
struct gspca_dev *gspca_dev,
679 seqframe = data[0] & 0x3f;
680 len = (
int) (((data[0] & 0xc0) << 2) | data[1]);
681 if (seqframe == 0x3f) {
683 "header packet found datalength %d !!", len);
684 PDEBUG(D_FRAM,
"G %d R %d G %d B %d",
685 data[2], data[3], data[4], data[5]);
702 struct gspca_dev *gspca_dev =
704 struct sd *sd = (
struct sd *)gspca_dev;
713 setbrightness(gspca_dev, ctrl->
val);
716 setcontrast(gspca_dev, ctrl->
val);
719 setcolors(gspca_dev, ctrl->
val);
723 setautogain(gspca_dev);
733 static int sd_init_controls(
struct gspca_dev *gspca_dev)
735 struct sd *sd = (
struct sd *)gspca_dev;
738 gspca_dev->
vdev.ctrl_handler = hdl;
750 pr_err(
"Could not initialize controls\n");
761 .init_controls = sd_init_controls,
764 .pkt_scan = sd_pkt_scan,
765 .dq_callback = do_autogain,
771 #if !defined CONFIG_USB_ET61X251 && !defined CONFIG_USB_ET61X251_MODULE
787 static struct usb_driver sd_driver = {
789 .id_table = device_table,
793 .suspend = gspca_suspend,
794 .resume = gspca_resume,
795 .reset_resume = gspca_resume,