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 */
38 /* V4L2 controls supported by the driver */
39 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
);
40 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
);
42 static const struct ctrl sd_ctrls
[] = {
45 .id
= V4L2_CID_BRIGHTNESS
,
46 .type
= V4L2_CTRL_TYPE_INTEGER
,
49 .maximum
= 0x15f, /* = 352 - 1 */
51 #define BRIGHTNESS_DEF 0x14c
52 .default_value
= BRIGHTNESS_DEF
,
54 .set
= sd_setbrightness
,
55 .get
= sd_getbrightness
,
59 static const struct v4l2_pix_format sif_mode
[] = {
60 {176, 144, V4L2_PIX_FMT_SBGGR8
, V4L2_FIELD_NONE
,
62 .sizeimage
= 176 * 144,
63 .colorspace
= V4L2_COLORSPACE_SRGB
,
65 {352, 288, V4L2_PIX_FMT_SBGGR8
, V4L2_FIELD_NONE
,
67 .sizeimage
= 352 * 288,
68 .colorspace
= V4L2_COLORSPACE_SRGB
,
72 /* TV-8532A (ICM532A) registers (LE) */
73 #define R00_PART_CONTROL 0x00
74 #define LATENT_CHANGE 0x80
75 #define EXPO_CHANGE 0x04
76 #define R01_TIMING_CONTROL_LOW 0x01
77 #define CMD_EEprom_Open 0x30
78 #define CMD_EEprom_Close 0x29
79 #define R03_TABLE_ADDR 0x03
80 #define R04_WTRAM_DATA_L 0x04
81 #define R05_WTRAM_DATA_M 0x05
82 #define R06_WTRAM_DATA_H 0x06
83 #define R07_TABLE_LEN 0x07
84 #define R08_RAM_WRITE_ACTION 0x08
85 #define R0C_AD_WIDTHL 0x0c
86 #define R0D_AD_WIDTHH 0x0d
87 #define R0E_AD_HEIGHTL 0x0e
88 #define R0F_AD_HEIGHTH 0x0f
89 #define R10_AD_COL_BEGINL 0x10
90 #define R11_AD_COL_BEGINH 0x11
91 #define MIRROR 0x04 /* [10] */
92 #define R14_AD_ROW_BEGINL 0x14
93 #define R15_AD_ROWBEGINH 0x15
94 #define R1C_AD_EXPOSE_TIMEL 0x1c
95 #define R28_QUANT 0x28
97 #define R2C_POLARITY 0x2c
98 #define R2D_POINT 0x2d
99 #define R2E_POINTH 0x2e
100 #define R2F_POINTB 0x2f
101 #define R30_POINTBH 0x30
103 #define R2A_HIGH_BUDGET 0x2a
104 #define R2B_LOW_BUDGET 0x2b
106 #define R35_VIDH 0x35
108 #define R37_PIDH 0x37
109 #define R39_Test1 0x39 /* GPIO */
110 #define R3B_Test3 0x3B /* GPIO */
111 #define R83_AD_IDH 0x83
112 #define R91_AD_SLOPEREG 0x91
113 #define R94_AD_BITCONTROL 0x94
115 static const u8 eeprom_data
[][3] = {
116 /* dataH dataM dataL */
132 static int reg_r(struct gspca_dev
*gspca_dev
,
135 usb_control_msg(gspca_dev
->dev
,
136 usb_rcvctrlpipe(gspca_dev
->dev
, 0),
138 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
140 index
, gspca_dev
->usb_buf
, 1,
142 return gspca_dev
->usb_buf
[0];
146 static void reg_w1(struct gspca_dev
*gspca_dev
,
147 __u16 index
, __u8 value
)
149 gspca_dev
->usb_buf
[0] = value
;
150 usb_control_msg(gspca_dev
->dev
,
151 usb_sndctrlpipe(gspca_dev
->dev
, 0),
153 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
155 index
, gspca_dev
->usb_buf
, 1, 500);
159 static void reg_w2(struct gspca_dev
*gspca_dev
,
160 u16 index
, u16 value
)
162 gspca_dev
->usb_buf
[0] = value
;
163 gspca_dev
->usb_buf
[1] = value
>> 8;
164 usb_control_msg(gspca_dev
->dev
,
165 usb_sndctrlpipe(gspca_dev
->dev
, 0),
167 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
169 index
, gspca_dev
->usb_buf
, 2, 500);
172 static void tv_8532WriteEEprom(struct gspca_dev
*gspca_dev
)
176 reg_w1(gspca_dev
, R01_TIMING_CONTROL_LOW
, CMD_EEprom_Open
);
177 for (i
= 0; i
< ARRAY_SIZE(eeprom_data
); i
++) {
178 reg_w1(gspca_dev
, R03_TABLE_ADDR
, i
);
179 reg_w1(gspca_dev
, R04_WTRAM_DATA_L
, eeprom_data
[i
][2]);
180 reg_w1(gspca_dev
, R05_WTRAM_DATA_M
, eeprom_data
[i
][1]);
181 reg_w1(gspca_dev
, R06_WTRAM_DATA_H
, eeprom_data
[i
][0]);
182 reg_w1(gspca_dev
, R08_RAM_WRITE_ACTION
, 0);
184 reg_w1(gspca_dev
, R07_TABLE_LEN
, i
);
185 reg_w1(gspca_dev
, R01_TIMING_CONTROL_LOW
, CMD_EEprom_Close
);
189 /* this function is called at probe time */
190 static int sd_config(struct gspca_dev
*gspca_dev
,
191 const struct usb_device_id
*id
)
193 struct sd
*sd
= (struct sd
*) gspca_dev
;
196 cam
= &gspca_dev
->cam
;
197 cam
->cam_mode
= sif_mode
;
198 cam
->nmodes
= ARRAY_SIZE(sif_mode
);
200 sd
->brightness
= BRIGHTNESS_DEF
;
204 static void tv_8532ReadRegisters(struct gspca_dev
*gspca_dev
)
207 static u8 reg_tb
[] = {
233 reg_r(gspca_dev
, reg_tb
[i
]);
235 } while (reg_tb
[i
] != 0);
238 static void tv_8532_setReg(struct gspca_dev
*gspca_dev
)
240 reg_w1(gspca_dev
, R10_AD_COL_BEGINL
, 0x44);
241 /* begin active line */
242 reg_w1(gspca_dev
, R11_AD_COL_BEGINH
, 0x00);
243 /* mirror and digital gain */
244 reg_w1(gspca_dev
, R00_PART_CONTROL
, LATENT_CHANGE
| EXPO_CHANGE
);
247 reg_w1(gspca_dev
, R3B_Test3
, 0x0a); /* Test0Sel = 10 */
248 /******************************************************/
249 reg_w1(gspca_dev
, R0E_AD_HEIGHTL
, 0x90);
250 reg_w1(gspca_dev
, R0F_AD_HEIGHTH
, 0x01);
251 reg_w2(gspca_dev
, R1C_AD_EXPOSE_TIMEL
, 0x018f);
252 reg_w1(gspca_dev
, R10_AD_COL_BEGINL
, 0x44);
253 /* begin active line */
254 reg_w1(gspca_dev
, R11_AD_COL_BEGINH
, 0x00);
255 /* mirror and digital gain */
256 reg_w1(gspca_dev
, R14_AD_ROW_BEGINL
, 0x0a);
258 reg_w1(gspca_dev
, R91_AD_SLOPEREG
, 0x00);
259 reg_w1(gspca_dev
, R94_AD_BITCONTROL
, 0x02);
261 reg_w1(gspca_dev
, R01_TIMING_CONTROL_LOW
, CMD_EEprom_Close
);
263 reg_w1(gspca_dev
, R91_AD_SLOPEREG
, 0x00);
264 reg_w1(gspca_dev
, R00_PART_CONTROL
, LATENT_CHANGE
| EXPO_CHANGE
);
268 static void tv_8532_PollReg(struct gspca_dev
*gspca_dev
)
272 /* strange polling from tgc */
273 for (i
= 0; i
< 10; i
++) {
274 reg_w1(gspca_dev
, R2C_POLARITY
, 0x10);
275 reg_w1(gspca_dev
, R00_PART_CONTROL
,
276 LATENT_CHANGE
| EXPO_CHANGE
);
277 reg_w1(gspca_dev
, R31_UPD
, 0x01);
281 /* this function is called at probe and resume time */
282 static int sd_init(struct gspca_dev
*gspca_dev
)
284 tv_8532WriteEEprom(gspca_dev
);
286 reg_w1(gspca_dev
, R91_AD_SLOPEREG
, 0x32); /* slope begin 1,7V,
288 reg_w1(gspca_dev
, R94_AD_BITCONTROL
, 0x00);
289 tv_8532ReadRegisters(gspca_dev
);
290 reg_w1(gspca_dev
, R3B_Test3
, 0x0b);
291 reg_w2(gspca_dev
, R0E_AD_HEIGHTL
, 0x0190);
292 reg_w2(gspca_dev
, R1C_AD_EXPOSE_TIMEL
, 0x018f);
293 reg_w1(gspca_dev
, R0C_AD_WIDTHL
, 0xe8);
294 reg_w1(gspca_dev
, R0D_AD_WIDTHH
, 0x03);
296 /*******************************************************************/
297 reg_w1(gspca_dev
, R28_QUANT
, 0x90);
298 /* no compress - fixed Q - quant 0 */
299 reg_w1(gspca_dev
, R29_LINE
, 0x81);
300 /* 0x84; // CIF | 4 packet 0x29 */
302 /************************************************/
303 reg_w1(gspca_dev
, R2C_POLARITY
, 0x10);
304 /* 0x48; //0x08; 0x2c */
305 reg_w1(gspca_dev
, R2D_POINT
, 0x14);
307 reg_w1(gspca_dev
, R2E_POINTH
, 0x01);
309 reg_w1(gspca_dev
, R2F_POINTB
, 0x12);
311 reg_w1(gspca_dev
, R30_POINTBH
, 0x01);
313 reg_w1(gspca_dev
, R00_PART_CONTROL
, LATENT_CHANGE
| EXPO_CHANGE
);
315 /*************************************************/
316 reg_w1(gspca_dev
, R31_UPD
, 0x01); /* update registers */
318 reg_w1(gspca_dev
, R31_UPD
, 0x00); /* end update */
319 /*************************************************/
320 tv_8532_setReg(gspca_dev
);
321 /*************************************************/
322 reg_w1(gspca_dev
, R3B_Test3
, 0x0b); /* Test0Sel = 11 = GPIO */
323 /*************************************************/
324 tv_8532_setReg(gspca_dev
);
325 /*************************************************/
326 tv_8532_PollReg(gspca_dev
);
330 static void setbrightness(struct gspca_dev
*gspca_dev
)
332 struct sd
*sd
= (struct sd
*) gspca_dev
;
334 reg_w2(gspca_dev
, R1C_AD_EXPOSE_TIMEL
, sd
->brightness
);
335 reg_w1(gspca_dev
, R00_PART_CONTROL
, LATENT_CHANGE
| EXPO_CHANGE
);
339 /* -- start the camera -- */
340 static int sd_start(struct gspca_dev
*gspca_dev
)
342 struct sd
*sd
= (struct sd
*) gspca_dev
;
344 reg_w1(gspca_dev
, R91_AD_SLOPEREG
, 0x32); /* slope begin 1,7V,
346 reg_w1(gspca_dev
, R94_AD_BITCONTROL
, 0x00);
347 tv_8532ReadRegisters(gspca_dev
);
348 reg_w1(gspca_dev
, R3B_Test3
, 0x0b);
350 reg_w2(gspca_dev
, R0E_AD_HEIGHTL
, 0x0190);
351 setbrightness(gspca_dev
);
353 reg_w1(gspca_dev
, R0C_AD_WIDTHL
, 0xe8); /* 0x20; 0x0c */
354 reg_w1(gspca_dev
, R0D_AD_WIDTHH
, 0x03);
356 /************************************************/
357 reg_w1(gspca_dev
, R28_QUANT
, 0x90);
358 /* 0x72 compressed mode 0x28 */
359 if (gspca_dev
->cam
.cam_mode
[(int) gspca_dev
->curr_mode
].priv
) {
361 reg_w1(gspca_dev
, R29_LINE
, 0x41);
362 /* CIF - 2 lines/packet */
365 reg_w1(gspca_dev
, R29_LINE
, 0x81);
366 /* CIF - 2 lines/packet */
368 /************************************************/
369 reg_w1(gspca_dev
, R2C_POLARITY
, 0x10); /* slow clock */
370 reg_w1(gspca_dev
, R2D_POINT
, 0x14);
371 reg_w1(gspca_dev
, R2E_POINTH
, 0x01);
372 reg_w1(gspca_dev
, R2F_POINTB
, 0x12);
373 reg_w1(gspca_dev
, R30_POINTBH
, 0x01);
374 reg_w1(gspca_dev
, R00_PART_CONTROL
, LATENT_CHANGE
| EXPO_CHANGE
);
375 /************************************************/
376 reg_w1(gspca_dev
, R31_UPD
, 0x01); /* update registers */
378 reg_w1(gspca_dev
, R31_UPD
, 0x00); /* end update */
379 /************************************************/
380 tv_8532_setReg(gspca_dev
);
381 /************************************************/
382 reg_w1(gspca_dev
, R3B_Test3
, 0x0b); /* Test0Sel = 11 = GPIO */
383 /************************************************/
384 tv_8532_setReg(gspca_dev
);
385 /************************************************/
386 tv_8532_PollReg(gspca_dev
);
387 reg_w1(gspca_dev
, R31_UPD
, 0x00); /* end update */
389 gspca_dev
->empty_packet
= 0; /* check the empty packets */
390 sd
->packet
= 0; /* ignore the first packets */
395 static void sd_stopN(struct gspca_dev
*gspca_dev
)
397 reg_w1(gspca_dev
, R3B_Test3
, 0x0b); /* Test0Sel = 11 = GPIO */
400 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
,
401 u8
*data
, /* isoc packet */
402 int len
) /* iso packet length */
404 struct sd
*sd
= (struct sd
*) gspca_dev
;
405 int packet_type0
, packet_type1
;
407 packet_type0
= packet_type1
= INTER_PACKET
;
408 if (gspca_dev
->empty_packet
) {
409 gspca_dev
->empty_packet
= 0;
410 sd
->packet
= gspca_dev
->height
/ 2;
411 packet_type0
= FIRST_PACKET
;
412 } else if (sd
->packet
== 0)
413 return; /* 2 more lines in 352x288 ! */
416 packet_type1
= LAST_PACKET
;
418 /* each packet contains:
425 gspca_frame_add(gspca_dev
, packet_type0
,
426 data
+ 2, gspca_dev
->width
);
427 gspca_frame_add(gspca_dev
, packet_type1
,
428 data
+ gspca_dev
->width
+ 5, gspca_dev
->width
);
431 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
)
433 struct sd
*sd
= (struct sd
*) gspca_dev
;
435 sd
->brightness
= val
;
436 if (gspca_dev
->streaming
)
437 setbrightness(gspca_dev
);
441 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
)
443 struct sd
*sd
= (struct sd
*) gspca_dev
;
445 *val
= sd
->brightness
;
449 /* sub-driver description */
450 static const struct sd_desc sd_desc
= {
453 .nctrls
= ARRAY_SIZE(sd_ctrls
),
458 .pkt_scan
= sd_pkt_scan
,
461 /* -- module initialisation -- */
462 static const __devinitdata
struct usb_device_id device_table
[] = {
463 {USB_DEVICE(0x046d, 0x0920)},
464 {USB_DEVICE(0x046d, 0x0921)},
465 {USB_DEVICE(0x0545, 0x808b)},
466 {USB_DEVICE(0x0545, 0x8333)},
467 {USB_DEVICE(0x0923, 0x010f)},
471 MODULE_DEVICE_TABLE(usb
, device_table
);
473 /* -- device connect -- */
474 static int sd_probe(struct usb_interface
*intf
,
475 const struct usb_device_id
*id
)
477 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
481 static struct usb_driver sd_driver
= {
483 .id_table
= device_table
,
485 .disconnect
= gspca_disconnect
,
487 .suspend
= gspca_suspend
,
488 .resume
= gspca_resume
,
492 /* -- module insert / remove -- */
493 static int __init
sd_mod_init(void)
496 ret
= usb_register(&sd_driver
);
499 PDEBUG(D_PROBE
, "registered");
503 static void __exit
sd_mod_exit(void)
505 usb_deregister(&sd_driver
);
506 PDEBUG(D_PROBE
, "deregistered");
509 module_init(sd_mod_init
);
510 module_exit(sd_mod_exit
);