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 */
36 static const struct v4l2_pix_format sif_mode
[] = {
37 {176, 144, V4L2_PIX_FMT_SBGGR8
, V4L2_FIELD_NONE
,
39 .sizeimage
= 176 * 144,
40 .colorspace
= V4L2_COLORSPACE_SRGB
,
42 {352, 288, V4L2_PIX_FMT_SBGGR8
, V4L2_FIELD_NONE
,
44 .sizeimage
= 352 * 288,
45 .colorspace
= V4L2_COLORSPACE_SRGB
,
49 /* TV-8532A (ICM532A) registers (LE) */
50 #define R00_PART_CONTROL 0x00
51 #define LATENT_CHANGE 0x80
52 #define EXPO_CHANGE 0x04
53 #define R01_TIMING_CONTROL_LOW 0x01
54 #define CMD_EEprom_Open 0x30
55 #define CMD_EEprom_Close 0x29
56 #define R03_TABLE_ADDR 0x03
57 #define R04_WTRAM_DATA_L 0x04
58 #define R05_WTRAM_DATA_M 0x05
59 #define R06_WTRAM_DATA_H 0x06
60 #define R07_TABLE_LEN 0x07
61 #define R08_RAM_WRITE_ACTION 0x08
62 #define R0C_AD_WIDTHL 0x0c
63 #define R0D_AD_WIDTHH 0x0d
64 #define R0E_AD_HEIGHTL 0x0e
65 #define R0F_AD_HEIGHTH 0x0f
66 #define R10_AD_COL_BEGINL 0x10
67 #define R11_AD_COL_BEGINH 0x11
68 #define MIRROR 0x04 /* [10] */
69 #define R14_AD_ROW_BEGINL 0x14
70 #define R15_AD_ROWBEGINH 0x15
71 #define R1C_AD_EXPOSE_TIMEL 0x1c
72 #define R20_GAIN_G1L 0x20
73 #define R21_GAIN_G1H 0x21
74 #define R22_GAIN_RL 0x22
75 #define R23_GAIN_RH 0x23
76 #define R24_GAIN_BL 0x24
77 #define R25_GAIN_BH 0x25
78 #define R26_GAIN_G2L 0x26
79 #define R27_GAIN_G2H 0x27
80 #define R28_QUANT 0x28
82 #define R2C_POLARITY 0x2c
83 #define R2D_POINT 0x2d
84 #define R2E_POINTH 0x2e
85 #define R2F_POINTB 0x2f
86 #define R30_POINTBH 0x30
88 #define R2A_HIGH_BUDGET 0x2a
89 #define R2B_LOW_BUDGET 0x2b
94 #define R39_Test1 0x39 /* GPIO */
95 #define R3B_Test3 0x3b /* GPIO */
96 #define R83_AD_IDH 0x83
97 #define R91_AD_SLOPEREG 0x91
98 #define R94_AD_BITCONTROL 0x94
100 static const u8 eeprom_data
[][3] = {
101 /* dataH dataM dataL */
119 static void reg_w1(struct gspca_dev
*gspca_dev
,
120 __u16 index
, __u8 value
)
122 gspca_dev
->usb_buf
[0] = value
;
123 usb_control_msg(gspca_dev
->dev
,
124 usb_sndctrlpipe(gspca_dev
->dev
, 0),
126 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
128 index
, gspca_dev
->usb_buf
, 1, 500);
132 static void reg_w2(struct gspca_dev
*gspca_dev
,
133 u16 index
, u16 value
)
135 gspca_dev
->usb_buf
[0] = value
;
136 gspca_dev
->usb_buf
[1] = value
>> 8;
137 usb_control_msg(gspca_dev
->dev
,
138 usb_sndctrlpipe(gspca_dev
->dev
, 0),
140 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
142 index
, gspca_dev
->usb_buf
, 2, 500);
145 static void tv_8532WriteEEprom(struct gspca_dev
*gspca_dev
)
149 reg_w1(gspca_dev
, R01_TIMING_CONTROL_LOW
, CMD_EEprom_Open
);
150 for (i
= 0; i
< ARRAY_SIZE(eeprom_data
); i
++) {
151 reg_w1(gspca_dev
, R03_TABLE_ADDR
, i
);
152 reg_w1(gspca_dev
, R04_WTRAM_DATA_L
, eeprom_data
[i
][2]);
153 reg_w1(gspca_dev
, R05_WTRAM_DATA_M
, eeprom_data
[i
][1]);
154 reg_w1(gspca_dev
, R06_WTRAM_DATA_H
, eeprom_data
[i
][0]);
155 reg_w1(gspca_dev
, R08_RAM_WRITE_ACTION
, 0);
157 reg_w1(gspca_dev
, R07_TABLE_LEN
, i
);
158 reg_w1(gspca_dev
, R01_TIMING_CONTROL_LOW
, CMD_EEprom_Close
);
161 /* this function is called at probe time */
162 static int sd_config(struct gspca_dev
*gspca_dev
,
163 const struct usb_device_id
*id
)
167 cam
= &gspca_dev
->cam
;
168 cam
->cam_mode
= sif_mode
;
169 cam
->nmodes
= ARRAY_SIZE(sif_mode
);
174 static void tv_8532_setReg(struct gspca_dev
*gspca_dev
)
176 reg_w1(gspca_dev
, R3B_Test3
, 0x0a); /* Test0Sel = 10 */
177 /******************************************************/
178 reg_w1(gspca_dev
, R0E_AD_HEIGHTL
, 0x90);
179 reg_w1(gspca_dev
, R0F_AD_HEIGHTH
, 0x01);
180 reg_w2(gspca_dev
, R1C_AD_EXPOSE_TIMEL
, 0x018f);
181 reg_w1(gspca_dev
, R10_AD_COL_BEGINL
, 0x44);
182 /* begin active line */
183 reg_w1(gspca_dev
, R11_AD_COL_BEGINH
, 0x00);
184 /* mirror and digital gain */
185 reg_w1(gspca_dev
, R14_AD_ROW_BEGINL
, 0x0a);
187 reg_w1(gspca_dev
, R94_AD_BITCONTROL
, 0x02);
188 reg_w1(gspca_dev
, R91_AD_SLOPEREG
, 0x00);
189 reg_w1(gspca_dev
, R00_PART_CONTROL
, LATENT_CHANGE
| EXPO_CHANGE
);
193 /* this function is called at probe and resume time */
194 static int sd_init(struct gspca_dev
*gspca_dev
)
196 tv_8532WriteEEprom(gspca_dev
);
201 static void setexposure(struct gspca_dev
*gspca_dev
, s32 val
)
203 reg_w2(gspca_dev
, R1C_AD_EXPOSE_TIMEL
, val
);
204 reg_w1(gspca_dev
, R00_PART_CONTROL
, LATENT_CHANGE
| EXPO_CHANGE
);
208 static void setgain(struct gspca_dev
*gspca_dev
, s32 val
)
210 reg_w2(gspca_dev
, R20_GAIN_G1L
, val
);
211 reg_w2(gspca_dev
, R22_GAIN_RL
, val
);
212 reg_w2(gspca_dev
, R24_GAIN_BL
, val
);
213 reg_w2(gspca_dev
, R26_GAIN_G2L
, val
);
216 /* -- start the camera -- */
217 static int sd_start(struct gspca_dev
*gspca_dev
)
219 struct sd
*sd
= (struct sd
*) gspca_dev
;
221 reg_w1(gspca_dev
, R0C_AD_WIDTHL
, 0xe8); /* 0x20; 0x0c */
222 reg_w1(gspca_dev
, R0D_AD_WIDTHH
, 0x03);
224 /************************************************/
225 reg_w1(gspca_dev
, R28_QUANT
, 0x90);
226 /* 0x72 compressed mode 0x28 */
227 if (gspca_dev
->cam
.cam_mode
[(int) gspca_dev
->curr_mode
].priv
) {
229 reg_w1(gspca_dev
, R29_LINE
, 0x41);
230 /* CIF - 2 lines/packet */
233 reg_w1(gspca_dev
, R29_LINE
, 0x81);
234 /* CIF - 2 lines/packet */
236 /************************************************/
237 reg_w1(gspca_dev
, R2C_POLARITY
, 0x10); /* slow clock */
238 reg_w1(gspca_dev
, R2D_POINT
, 0x14);
239 reg_w1(gspca_dev
, R2E_POINTH
, 0x01);
240 reg_w1(gspca_dev
, R2F_POINTB
, 0x12);
241 reg_w1(gspca_dev
, R30_POINTBH
, 0x01);
243 tv_8532_setReg(gspca_dev
);
245 /************************************************/
246 reg_w1(gspca_dev
, R31_UPD
, 0x01); /* update registers */
248 reg_w1(gspca_dev
, R31_UPD
, 0x00); /* end update */
250 gspca_dev
->empty_packet
= 0; /* check the empty packets */
251 sd
->packet
= 0; /* ignore the first packets */
256 static void sd_stopN(struct gspca_dev
*gspca_dev
)
258 reg_w1(gspca_dev
, R3B_Test3
, 0x0b); /* Test0Sel = 11 = GPIO */
261 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
,
262 u8
*data
, /* isoc packet */
263 int len
) /* iso packet length */
265 struct sd
*sd
= (struct sd
*) gspca_dev
;
266 int packet_type0
, packet_type1
;
268 packet_type0
= packet_type1
= INTER_PACKET
;
269 if (gspca_dev
->empty_packet
) {
270 gspca_dev
->empty_packet
= 0;
271 sd
->packet
= gspca_dev
->pixfmt
.height
/ 2;
272 packet_type0
= FIRST_PACKET
;
273 } else if (sd
->packet
== 0)
274 return; /* 2 more lines in 352x288 ! */
277 packet_type1
= LAST_PACKET
;
279 /* each packet contains:
286 gspca_frame_add(gspca_dev
, packet_type0
,
287 data
+ 2, gspca_dev
->pixfmt
.width
);
288 gspca_frame_add(gspca_dev
, packet_type1
,
289 data
+ gspca_dev
->pixfmt
.width
+ 5,
290 gspca_dev
->pixfmt
.width
);
293 static int sd_s_ctrl(struct v4l2_ctrl
*ctrl
)
295 struct gspca_dev
*gspca_dev
=
296 container_of(ctrl
->handler
, struct gspca_dev
, ctrl_handler
);
298 gspca_dev
->usb_err
= 0;
300 if (!gspca_dev
->streaming
)
304 case V4L2_CID_EXPOSURE
:
305 setexposure(gspca_dev
, ctrl
->val
);
308 setgain(gspca_dev
, ctrl
->val
);
311 return gspca_dev
->usb_err
;
314 static const struct v4l2_ctrl_ops sd_ctrl_ops
= {
318 static int sd_init_controls(struct gspca_dev
*gspca_dev
)
320 struct v4l2_ctrl_handler
*hdl
= &gspca_dev
->ctrl_handler
;
322 gspca_dev
->vdev
.ctrl_handler
= hdl
;
323 v4l2_ctrl_handler_init(hdl
, 2);
324 v4l2_ctrl_new_std(hdl
, &sd_ctrl_ops
,
325 V4L2_CID_EXPOSURE
, 0, 0x18f, 1, 0x18f);
326 v4l2_ctrl_new_std(hdl
, &sd_ctrl_ops
,
327 V4L2_CID_GAIN
, 0, 0x7ff, 1, 0x100);
330 pr_err("Could not initialize controls\n");
336 /* sub-driver description */
337 static const struct sd_desc sd_desc
= {
341 .init_controls
= sd_init_controls
,
344 .pkt_scan
= sd_pkt_scan
,
347 /* -- module initialisation -- */
348 static const struct usb_device_id device_table
[] = {
349 {USB_DEVICE(0x046d, 0x0920)},
350 {USB_DEVICE(0x046d, 0x0921)},
351 {USB_DEVICE(0x0545, 0x808b)},
352 {USB_DEVICE(0x0545, 0x8333)},
353 {USB_DEVICE(0x0923, 0x010f)},
357 MODULE_DEVICE_TABLE(usb
, device_table
);
359 /* -- device connect -- */
360 static int sd_probe(struct usb_interface
*intf
,
361 const struct usb_device_id
*id
)
363 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
367 static struct usb_driver sd_driver
= {
369 .id_table
= device_table
,
371 .disconnect
= gspca_disconnect
,
373 .suspend
= gspca_suspend
,
374 .resume
= gspca_resume
,
375 .reset_resume
= gspca_resume
,
379 module_usb_driver(sd_driver
);