2 * Quickcam cameras initialization data
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 "tv8532"
25 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
26 MODULE_DESCRIPTION("TV8532 USB Camera Driver");
27 MODULE_LICENSE("GPL");
29 /* specific webcam descriptor */
31 struct gspca_dev gspca_dev; /* !! must be the first item */
39 /* V4L2 controls supported by the driver */
40 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
41 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
42 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
43 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
45 static struct ctrl sd_ctrls[] = {
46 #define SD_BRIGHTNESS 0
49 .id = V4L2_CID_BRIGHTNESS,
50 .type = V4L2_CTRL_TYPE_INTEGER,
55 .default_value = 0x18f,
57 .set = sd_setbrightness,
58 .get = sd_getbrightness,
63 .id = V4L2_CID_CONTRAST,
64 .type = V4L2_CTRL_TYPE_INTEGER,
69 .default_value = 0x7fff,
71 .set = sd_setcontrast,
72 .get = sd_getcontrast,
76 static struct v4l2_pix_format sif_mode[] = {
77 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
79 .sizeimage = 176 * 144,
80 .colorspace = V4L2_COLORSPACE_SRGB,
82 {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
84 .sizeimage = 352 * 288,
85 .colorspace = V4L2_COLORSPACE_SRGB,
90 * Initialization data: this is the first set-up data written to the
91 * device (before the open data).
93 #define TESTCLK 0x10 /* reg 0x2c -> 0x12 //10 */
94 #define TESTCOMP 0x90 /* reg 0x28 -> 0x80 */
95 #define TESTLINE 0x81 /* reg 0x29 -> 0x81 */
96 #define QCIFLINE 0x41 /* reg 0x29 -> 0x81 */
97 #define TESTPTL 0x14 /* reg 0x2D -> 0x14 */
98 #define TESTPTH 0x01 /* reg 0x2E -> 0x01 */
99 #define TESTPTBL 0x12 /* reg 0x2F -> 0x0a */
100 #define TESTPTBH 0x01 /* reg 0x30 -> 0x01 */
101 #define ADWIDTHL 0xe8 /* reg 0x0c -> 0xe8 */
102 #define ADWIDTHH 0x03 /* reg 0x0d -> 0x03 */
103 #define ADHEIGHL 0x90 /* reg 0x0e -> 0x91 //93 */
104 #define ADHEIGHH 0x01 /* reg 0x0f -> 0x01 */
105 #define EXPOL 0x8f /* reg 0x1c -> 0x8f */
106 #define EXPOH 0x01 /* reg 0x1d -> 0x01 */
107 #define ADCBEGINL 0x44 /* reg 0x10 -> 0x46 //47 */
108 #define ADCBEGINH 0x00 /* reg 0x11 -> 0x00 */
109 #define ADRBEGINL 0x0a /* reg 0x14 -> 0x0b //0x0c */
110 #define ADRBEGINH 0x00 /* reg 0x15 -> 0x00 */
111 #define TV8532_CMD_UPDATE 0x84
113 #define TV8532_EEprom_Add 0x03
114 #define TV8532_EEprom_DataL 0x04
115 #define TV8532_EEprom_DataM 0x05
116 #define TV8532_EEprom_DataH 0x06
117 #define TV8532_EEprom_TableLength 0x07
118 #define TV8532_EEprom_Write 0x08
119 #define TV8532_PART_CTRL 0x00
120 #define TV8532_CTRL 0x01
121 #define TV8532_CMD_EEprom_Open 0x30
122 #define TV8532_CMD_EEprom_Close 0x29
123 #define TV8532_UDP_UPDATE 0x31
124 #define TV8532_GPIO 0x39
125 #define TV8532_GPIO_OE 0x3B
126 #define TV8532_REQ_RegWrite 0x02
127 #define TV8532_REQ_RegRead 0x03
129 #define TV8532_ADWIDTH_L 0x0C
130 #define TV8532_ADWIDTH_H 0x0D
131 #define TV8532_ADHEIGHT_L 0x0E
132 #define TV8532_ADHEIGHT_H 0x0F
133 #define TV8532_EXPOSURE 0x1C
134 #define TV8532_QUANT_COMP 0x28
135 #define TV8532_MODE_PACKET 0x29
136 #define TV8532_SETCLK 0x2C
137 #define TV8532_POINT_L 0x2D
138 #define TV8532_POINT_H 0x2E
139 #define TV8532_POINTB_L 0x2F
140 #define TV8532_POINTB_H 0x30
141 #define TV8532_BUDGET_L 0x2A
142 #define TV8532_BUDGET_H 0x2B
143 #define TV8532_VID_L 0x34
144 #define TV8532_VID_H 0x35
145 #define TV8532_PID_L 0x36
146 #define TV8532_PID_H 0x37
147 #define TV8532_DeviceID 0x83
148 #define TV8532_AD_SLOPE 0x91
149 #define TV8532_AD_BITCTRL 0x94
150 #define TV8532_AD_COLBEGIN_L 0x10
151 #define TV8532_AD_COLBEGIN_H 0x11
152 #define TV8532_AD_ROWBEGIN_L 0x14
153 #define TV8532_AD_ROWBEGIN_H 0x15
155 static const __u32 tv_8532_eeprom_data[] = {
156 /* add dataL dataM dataH */
157 0x00010001, 0x01018011, 0x02050014, 0x0305001c,
158 0x040d001e, 0x0505001f, 0x06050519, 0x0705011b,
159 0x0805091e, 0x090d892e, 0x0a05892f, 0x0b050dd9,
163 static int reg_r(struct gspca_dev *gspca_dev,
166 usb_control_msg(gspca_dev->dev,
167 usb_rcvctrlpipe(gspca_dev->dev, 0),
169 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
171 index, gspca_dev->usb_buf, 1,
173 return gspca_dev->usb_buf[0];
177 static void reg_w_1(struct gspca_dev *gspca_dev,
178 __u16 index, __u8 value)
180 gspca_dev->usb_buf[0] = value;
181 usb_control_msg(gspca_dev->dev,
182 usb_sndctrlpipe(gspca_dev->dev, 0),
184 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
186 index, gspca_dev->usb_buf, 1, 500);
190 static void reg_w_2(struct gspca_dev *gspca_dev,
191 __u16 index, __u8 val1, __u8 val2)
193 gspca_dev->usb_buf[0] = val1;
194 gspca_dev->usb_buf[1] = val2;
195 usb_control_msg(gspca_dev->dev,
196 usb_sndctrlpipe(gspca_dev->dev, 0),
198 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
200 index, gspca_dev->usb_buf, 2, 500);
203 static void tv_8532WriteEEprom(struct gspca_dev *gspca_dev)
206 __u8 reg, data0, data1, data2;
208 reg_w_1(gspca_dev, TV8532_GPIO, 0xb0);
209 reg_w_1(gspca_dev, TV8532_CTRL, TV8532_CMD_EEprom_Open);
211 while (tv_8532_eeprom_data[i]) {
212 reg = (tv_8532_eeprom_data[i] & 0xff000000) >> 24;
213 reg_w_1(gspca_dev, TV8532_EEprom_Add, reg);
215 data0 = (tv_8532_eeprom_data[i] & 0x000000ff);
216 reg_w_1(gspca_dev, TV8532_EEprom_DataL, data0);
218 data1 = (tv_8532_eeprom_data[i] & 0x0000ff00) >> 8;
219 reg_w_1(gspca_dev, TV8532_EEprom_DataM, data1);
221 data2 = (tv_8532_eeprom_data[i] & 0x00ff0000) >> 16;
222 reg_w_1(gspca_dev, TV8532_EEprom_DataH, data2);
224 reg_w_1(gspca_dev, TV8532_EEprom_Write, 0);
228 reg_w_1(gspca_dev, TV8532_EEprom_TableLength, i);
230 reg_w_1(gspca_dev, TV8532_CTRL, TV8532_CMD_EEprom_Close);
234 /* this function is called at probe time */
235 static int sd_config(struct gspca_dev *gspca_dev,
236 const struct usb_device_id *id)
238 struct sd *sd = (struct sd *) gspca_dev;
241 tv_8532WriteEEprom(gspca_dev);
243 cam = &gspca_dev->cam;
245 cam->cam_mode = sif_mode;
246 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
248 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
249 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
253 static void tv_8532ReadRegisters(struct gspca_dev *gspca_dev)
257 data = reg_r(gspca_dev, 0x0001);
258 PDEBUG(D_USBI, "register 0x01-> %x", data);
259 data = reg_r(gspca_dev, 0x0002);
260 PDEBUG(D_USBI, "register 0x02-> %x", data);
261 reg_r(gspca_dev, TV8532_ADWIDTH_L);
262 reg_r(gspca_dev, TV8532_ADWIDTH_H);
263 reg_r(gspca_dev, TV8532_QUANT_COMP);
264 reg_r(gspca_dev, TV8532_MODE_PACKET);
265 reg_r(gspca_dev, TV8532_SETCLK);
266 reg_r(gspca_dev, TV8532_POINT_L);
267 reg_r(gspca_dev, TV8532_POINT_H);
268 reg_r(gspca_dev, TV8532_POINTB_L);
269 reg_r(gspca_dev, TV8532_POINTB_H);
270 reg_r(gspca_dev, TV8532_BUDGET_L);
271 reg_r(gspca_dev, TV8532_BUDGET_H);
272 reg_r(gspca_dev, TV8532_VID_L);
273 reg_r(gspca_dev, TV8532_VID_H);
274 reg_r(gspca_dev, TV8532_PID_L);
275 reg_r(gspca_dev, TV8532_PID_H);
276 reg_r(gspca_dev, TV8532_DeviceID);
277 reg_r(gspca_dev, TV8532_AD_COLBEGIN_L);
278 reg_r(gspca_dev, TV8532_AD_COLBEGIN_H);
279 reg_r(gspca_dev, TV8532_AD_ROWBEGIN_L);
280 reg_r(gspca_dev, TV8532_AD_ROWBEGIN_H);
283 static void tv_8532_setReg(struct gspca_dev *gspca_dev)
285 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_L,
286 ADCBEGINL); /* 0x10 */
287 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_H,
288 ADCBEGINH); /* also digital gain */
289 reg_w_1(gspca_dev, TV8532_PART_CTRL,
290 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
292 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0a);
293 /******************************************************/
294 reg_w_1(gspca_dev, TV8532_ADHEIGHT_L, ADHEIGHL); /* 0e */
295 reg_w_1(gspca_dev, TV8532_ADHEIGHT_H, ADHEIGHH); /* 0f */
296 reg_w_2(gspca_dev, TV8532_EXPOSURE,
297 EXPOL, EXPOH); /* 350d 0x014c; 1c */
298 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_L,
299 ADCBEGINL); /* 0x10 */
300 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_H,
301 ADCBEGINH); /* also digital gain */
302 reg_w_1(gspca_dev, TV8532_AD_ROWBEGIN_L,
303 ADRBEGINL); /* 0x14 */
305 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x00); /* 0x91 */
306 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x02); /* 0x94 */
308 reg_w_1(gspca_dev, TV8532_CTRL,
309 TV8532_CMD_EEprom_Close); /* 0x01 */
311 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x00); /* 0x91 */
312 reg_w_1(gspca_dev, TV8532_PART_CTRL,
313 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
316 static void tv_8532_PollReg(struct gspca_dev *gspca_dev)
320 /* strange polling from tgc */
321 for (i = 0; i < 10; i++) {
322 reg_w_1(gspca_dev, TV8532_SETCLK,
323 TESTCLK); /* 0x48; //0x08; 0x2c */
324 reg_w_1(gspca_dev, TV8532_PART_CTRL, TV8532_CMD_UPDATE);
325 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */
329 /* this function is called at probe and resume time */
330 static int sd_init(struct gspca_dev *gspca_dev)
332 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32);
333 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00);
334 tv_8532ReadRegisters(gspca_dev);
335 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
336 reg_w_2(gspca_dev, TV8532_ADHEIGHT_L, ADHEIGHL,
337 ADHEIGHH); /* 401d 0x0169; 0e */
338 reg_w_2(gspca_dev, TV8532_EXPOSURE, EXPOL,
339 EXPOH); /* 350d 0x014c; 1c */
340 reg_w_1(gspca_dev, TV8532_ADWIDTH_L, ADWIDTHL); /* 0x20; 0x0c */
341 reg_w_1(gspca_dev, TV8532_ADWIDTH_H, ADWIDTHH); /* 0x0d */
343 /*******************************************************************/
344 reg_w_1(gspca_dev, TV8532_QUANT_COMP,
345 TESTCOMP); /* 0x72 compressed mode 0x28 */
346 reg_w_1(gspca_dev, TV8532_MODE_PACKET,
347 TESTLINE); /* 0x84; // CIF | 4 packet 0x29 */
349 /************************************************/
350 reg_w_1(gspca_dev, TV8532_SETCLK,
351 TESTCLK); /* 0x48; //0x08; 0x2c */
352 reg_w_1(gspca_dev, TV8532_POINT_L,
353 TESTPTL); /* 0x38; 0x2d */
354 reg_w_1(gspca_dev, TV8532_POINT_H,
355 TESTPTH); /* 0x04; 0x2e */
356 reg_w_1(gspca_dev, TV8532_POINTB_L,
357 TESTPTBL); /* 0x04; 0x2f */
358 reg_w_1(gspca_dev, TV8532_POINTB_H,
359 TESTPTBH); /* 0x04; 0x30 */
360 reg_w_1(gspca_dev, TV8532_PART_CTRL,
361 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
362 /*************************************************/
363 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */
365 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */
366 /*************************************************/
367 tv_8532_setReg(gspca_dev);
368 /*************************************************/
369 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
370 /*************************************************/
371 tv_8532_setReg(gspca_dev);
372 /*************************************************/
373 tv_8532_PollReg(gspca_dev);
377 static void setbrightness(struct gspca_dev *gspca_dev)
379 struct sd *sd = (struct sd *) gspca_dev;
380 int brightness = sd->brightness;
382 reg_w_2(gspca_dev, TV8532_EXPOSURE,
383 brightness >> 8, brightness); /* 1c */
384 reg_w_1(gspca_dev, TV8532_PART_CTRL, TV8532_CMD_UPDATE);
387 /* -- start the camera -- */
388 static int sd_start(struct gspca_dev *gspca_dev)
390 struct sd *sd = (struct sd *) gspca_dev;
392 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32);
393 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00);
394 tv_8532ReadRegisters(gspca_dev);
395 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
396 reg_w_2(gspca_dev, TV8532_ADHEIGHT_L,
397 ADHEIGHL, ADHEIGHH); /* 401d 0x0169; 0e */
398 /* reg_w_2(gspca_dev, TV8532_EXPOSURE,
399 EXPOL, EXPOH); * 350d 0x014c; 1c */
400 setbrightness(gspca_dev);
402 reg_w_1(gspca_dev, TV8532_ADWIDTH_L, ADWIDTHL); /* 0x20; 0x0c */
403 reg_w_1(gspca_dev, TV8532_ADWIDTH_H, ADWIDTHH); /* 0x0d */
405 /************************************************/
406 reg_w_1(gspca_dev, TV8532_QUANT_COMP,
407 TESTCOMP); /* 0x72 compressed mode 0x28 */
408 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
410 reg_w_1(gspca_dev, TV8532_MODE_PACKET,
411 QCIFLINE); /* 0x84; // CIF | 4 packet 0x29 */
414 reg_w_1(gspca_dev, TV8532_MODE_PACKET,
415 TESTLINE); /* 0x84; // CIF | 4 packet 0x29 */
417 /************************************************/
418 reg_w_1(gspca_dev, TV8532_SETCLK,
419 TESTCLK); /* 0x48; //0x08; 0x2c */
420 reg_w_1(gspca_dev, TV8532_POINT_L,
421 TESTPTL); /* 0x38; 0x2d */
422 reg_w_1(gspca_dev, TV8532_POINT_H,
423 TESTPTH); /* 0x04; 0x2e */
424 reg_w_1(gspca_dev, TV8532_POINTB_L,
425 TESTPTBL); /* 0x04; 0x2f */
426 reg_w_1(gspca_dev, TV8532_POINTB_H,
427 TESTPTBH); /* 0x04; 0x30 */
428 reg_w_1(gspca_dev, TV8532_PART_CTRL,
429 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
430 /************************************************/
431 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */
433 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */
434 /************************************************/
435 tv_8532_setReg(gspca_dev);
436 /************************************************/
437 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
438 /************************************************/
439 tv_8532_setReg(gspca_dev);
440 /************************************************/
441 tv_8532_PollReg(gspca_dev);
442 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */
444 gspca_dev->empty_packet = 0; /* check the empty packets */
445 sd->packet = 0; /* ignore the first packets */
450 static void sd_stopN(struct gspca_dev *gspca_dev)
452 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
455 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
456 struct gspca_frame *frame, /* target */
457 __u8 *data, /* isoc packet */
458 int len) /* iso packet length */
460 struct sd *sd = (struct sd *) gspca_dev;
461 int packet_type0, packet_type1;
463 packet_type0 = packet_type1 = INTER_PACKET;
464 if (gspca_dev->empty_packet) {
465 gspca_dev->empty_packet = 0;
466 sd->packet = gspca_dev->height / 2;
467 packet_type0 = FIRST_PACKET;
468 } else if (sd->packet == 0)
469 return; /* 2 more lines in 352x288 ! */
472 packet_type1 = LAST_PACKET;
474 /* each packet contains:
481 gspca_frame_add(gspca_dev, packet_type0,
482 frame, data + 2, gspca_dev->width);
483 gspca_frame_add(gspca_dev, packet_type1,
484 frame, data + gspca_dev->width + 6, gspca_dev->width);
487 static void setcontrast(struct gspca_dev *gspca_dev)
491 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
493 struct sd *sd = (struct sd *) gspca_dev;
495 sd->brightness = val;
496 if (gspca_dev->streaming)
497 setbrightness(gspca_dev);
501 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
503 struct sd *sd = (struct sd *) gspca_dev;
505 *val = sd->brightness;
509 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
511 struct sd *sd = (struct sd *) gspca_dev;
514 if (gspca_dev->streaming)
515 setcontrast(gspca_dev);
519 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
521 struct sd *sd = (struct sd *) gspca_dev;
527 /* sub-driver description */
528 static const struct sd_desc sd_desc = {
531 .nctrls = ARRAY_SIZE(sd_ctrls),
536 .pkt_scan = sd_pkt_scan,
539 /* -- module initialisation -- */
540 static const __devinitdata struct usb_device_id device_table[] = {
541 {USB_DEVICE(0x046d, 0x0920)},
542 {USB_DEVICE(0x046d, 0x0921)},
543 {USB_DEVICE(0x0545, 0x808b)},
544 {USB_DEVICE(0x0545, 0x8333)},
545 {USB_DEVICE(0x0923, 0x010f)},
549 MODULE_DEVICE_TABLE(usb, device_table);
551 /* -- device connect -- */
552 static int sd_probe(struct usb_interface *intf,
553 const struct usb_device_id *id)
555 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
559 static struct usb_driver sd_driver = {
561 .id_table = device_table,
563 .disconnect = gspca_disconnect,
565 .suspend = gspca_suspend,
566 .resume = gspca_resume,
570 /* -- module insert / remove -- */
571 static int __init sd_mod_init(void)
573 if (usb_register(&sd_driver) < 0)
575 PDEBUG(D_PROBE, "registered");
579 static void __exit sd_mod_exit(void)
581 usb_deregister(&sd_driver);
582 PDEBUG(D_PROBE, "deregistered");
585 module_init(sd_mod_init);
586 module_exit(sd_mod_exit);