]>
Commit | Line | Data |
---|---|---|
6a7eba24 JFM |
1 | /* |
2 | * Quickcam cameras initialization data | |
3 | * | |
4 | * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> | |
5 | * | |
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 | |
9 | * any later version. | |
10 | * | |
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. | |
15 | * | |
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 | |
19 | * | |
20 | */ | |
21 | #define MODULE_NAME "tv8532" | |
22 | ||
23 | #include "gspca.h" | |
24 | ||
6a7eba24 JFM |
25 | MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); |
26 | MODULE_DESCRIPTION("TV8532 USB Camera Driver"); | |
27 | MODULE_LICENSE("GPL"); | |
28 | ||
29 | /* specific webcam descriptor */ | |
30 | struct sd { | |
31 | struct gspca_dev gspca_dev; /* !! must be the first item */ | |
32 | ||
ba13cca7 | 33 | __u8 packet; |
6a7eba24 JFM |
34 | }; |
35 | ||
cc611b8a | 36 | static const struct v4l2_pix_format sif_mode[] = { |
c2446b3e JFM |
37 | {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
38 | .bytesperline = 176, | |
39 | .sizeimage = 176 * 144, | |
40 | .colorspace = V4L2_COLORSPACE_SRGB, | |
41 | .priv = 1}, | |
42 | {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, | |
43 | .bytesperline = 352, | |
44 | .sizeimage = 352 * 288, | |
45 | .colorspace = V4L2_COLORSPACE_SRGB, | |
46 | .priv = 0}, | |
6a7eba24 JFM |
47 | }; |
48 | ||
ca5e578f JFM |
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 | |
14bff9b8 HG |
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 | |
ca5e578f JFM |
80 | #define R28_QUANT 0x28 |
81 | #define R29_LINE 0x29 | |
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 | |
87 | #define R31_UPD 0x31 | |
88 | #define R2A_HIGH_BUDGET 0x2a | |
89 | #define R2B_LOW_BUDGET 0x2b | |
90 | #define R34_VID 0x34 | |
91 | #define R35_VIDH 0x35 | |
92 | #define R36_PID 0x36 | |
93 | #define R37_PIDH 0x37 | |
94 | #define R39_Test1 0x39 /* GPIO */ | |
1d00d6c1 | 95 | #define R3B_Test3 0x3b /* GPIO */ |
ca5e578f JFM |
96 | #define R83_AD_IDH 0x83 |
97 | #define R91_AD_SLOPEREG 0x91 | |
98 | #define R94_AD_BITCONTROL 0x94 | |
99 | ||
100 | static const u8 eeprom_data[][3] = { | |
101 | /* dataH dataM dataL */ | |
102 | {0x01, 0x00, 0x01}, | |
103 | {0x01, 0x80, 0x11}, | |
104 | {0x05, 0x00, 0x14}, | |
105 | {0x05, 0x00, 0x1c}, | |
106 | {0x0d, 0x00, 0x1e}, | |
107 | {0x05, 0x00, 0x1f}, | |
108 | {0x05, 0x05, 0x19}, | |
109 | {0x05, 0x01, 0x1b}, | |
110 | {0x05, 0x09, 0x1e}, | |
111 | {0x0d, 0x89, 0x2e}, | |
112 | {0x05, 0x89, 0x2f}, | |
113 | {0x05, 0x0d, 0xd9}, | |
114 | {0x05, 0x09, 0xf1}, | |
6a7eba24 JFM |
115 | }; |
116 | ||
6a7eba24 | 117 | |
739570bb | 118 | /* write 1 byte */ |
ca5e578f | 119 | static void reg_w1(struct gspca_dev *gspca_dev, |
739570bb | 120 | __u16 index, __u8 value) |
6a7eba24 | 121 | { |
739570bb JFM |
122 | gspca_dev->usb_buf[0] = value; |
123 | usb_control_msg(gspca_dev->dev, | |
124 | usb_sndctrlpipe(gspca_dev->dev, 0), | |
ca5e578f | 125 | 0x02, |
6a7eba24 JFM |
126 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
127 | 0, /* value */ | |
739570bb JFM |
128 | index, gspca_dev->usb_buf, 1, 500); |
129 | } | |
130 | ||
131 | /* write 2 bytes */ | |
ca5e578f JFM |
132 | static void reg_w2(struct gspca_dev *gspca_dev, |
133 | u16 index, u16 value) | |
739570bb | 134 | { |
ca5e578f JFM |
135 | gspca_dev->usb_buf[0] = value; |
136 | gspca_dev->usb_buf[1] = value >> 8; | |
739570bb JFM |
137 | usb_control_msg(gspca_dev->dev, |
138 | usb_sndctrlpipe(gspca_dev->dev, 0), | |
ca5e578f | 139 | 0x02, |
739570bb JFM |
140 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
141 | 0, /* value */ | |
142 | index, gspca_dev->usb_buf, 2, 500); | |
6a7eba24 JFM |
143 | } |
144 | ||
145 | static void tv_8532WriteEEprom(struct gspca_dev *gspca_dev) | |
146 | { | |
ca5e578f JFM |
147 | int i; |
148 | ||
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); | |
6a7eba24 | 156 | } |
ca5e578f JFM |
157 | reg_w1(gspca_dev, R07_TABLE_LEN, i); |
158 | reg_w1(gspca_dev, R01_TIMING_CONTROL_LOW, CMD_EEprom_Close); | |
6a7eba24 JFM |
159 | } |
160 | ||
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) | |
164 | { | |
6a7eba24 JFM |
165 | struct cam *cam; |
166 | ||
6a7eba24 | 167 | cam = &gspca_dev->cam; |
6a7eba24 | 168 | cam->cam_mode = sif_mode; |
ca5e578f | 169 | cam->nmodes = ARRAY_SIZE(sif_mode); |
6a7eba24 | 170 | |
6a7eba24 JFM |
171 | return 0; |
172 | } | |
173 | ||
6a7eba24 JFM |
174 | static void tv_8532_setReg(struct gspca_dev *gspca_dev) |
175 | { | |
ca5e578f | 176 | reg_w1(gspca_dev, R3B_Test3, 0x0a); /* Test0Sel = 10 */ |
6a7eba24 | 177 | /******************************************************/ |
ca5e578f JFM |
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); | |
186 | ||
ca5e578f | 187 | reg_w1(gspca_dev, R94_AD_BITCONTROL, 0x02); |
ca5e578f JFM |
188 | reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x00); |
189 | reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE); | |
190 | /* = 0x84 */ | |
6a7eba24 JFM |
191 | } |
192 | ||
012d6b02 JFM |
193 | /* this function is called at probe and resume time */ |
194 | static int sd_init(struct gspca_dev *gspca_dev) | |
6a7eba24 | 195 | { |
ca5e578f JFM |
196 | tv_8532WriteEEprom(gspca_dev); |
197 | ||
6a7eba24 JFM |
198 | return 0; |
199 | } | |
200 | ||
726795c1 | 201 | static void setexposure(struct gspca_dev *gspca_dev, s32 val) |
6a7eba24 | 202 | { |
726795c1 | 203 | reg_w2(gspca_dev, R1C_AD_EXPOSE_TIMEL, val); |
ca5e578f JFM |
204 | reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE); |
205 | /* 0x84 */ | |
6a7eba24 JFM |
206 | } |
207 | ||
726795c1 | 208 | static void setgain(struct gspca_dev *gspca_dev, s32 val) |
14bff9b8 | 209 | { |
726795c1 HV |
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); | |
14bff9b8 HG |
214 | } |
215 | ||
6a7eba24 | 216 | /* -- start the camera -- */ |
72ab97ce | 217 | static int sd_start(struct gspca_dev *gspca_dev) |
6a7eba24 | 218 | { |
2e0903b0 JFM |
219 | struct sd *sd = (struct sd *) gspca_dev; |
220 | ||
ca5e578f JFM |
221 | reg_w1(gspca_dev, R0C_AD_WIDTHL, 0xe8); /* 0x20; 0x0c */ |
222 | reg_w1(gspca_dev, R0D_AD_WIDTHH, 0x03); | |
6a7eba24 JFM |
223 | |
224 | /************************************************/ | |
ca5e578f JFM |
225 | reg_w1(gspca_dev, R28_QUANT, 0x90); |
226 | /* 0x72 compressed mode 0x28 */ | |
c2446b3e | 227 | if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { |
6a7eba24 | 228 | /* 176x144 */ |
ca5e578f JFM |
229 | reg_w1(gspca_dev, R29_LINE, 0x41); |
230 | /* CIF - 2 lines/packet */ | |
6a7eba24 JFM |
231 | } else { |
232 | /* 352x288 */ | |
ca5e578f JFM |
233 | reg_w1(gspca_dev, R29_LINE, 0x81); |
234 | /* CIF - 2 lines/packet */ | |
6a7eba24 JFM |
235 | } |
236 | /************************************************/ | |
ca5e578f JFM |
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); | |
5e027610 HG |
242 | |
243 | tv_8532_setReg(gspca_dev); | |
244 | ||
6a7eba24 | 245 | /************************************************/ |
ca5e578f | 246 | reg_w1(gspca_dev, R31_UPD, 0x01); /* update registers */ |
6a7eba24 | 247 | msleep(200); |
ca5e578f | 248 | reg_w1(gspca_dev, R31_UPD, 0x00); /* end update */ |
ba13cca7 JFM |
249 | |
250 | gspca_dev->empty_packet = 0; /* check the empty packets */ | |
2e0903b0 | 251 | sd->packet = 0; /* ignore the first packets */ |
ba13cca7 | 252 | |
72ab97ce | 253 | return 0; |
6a7eba24 JFM |
254 | } |
255 | ||
256 | static void sd_stopN(struct gspca_dev *gspca_dev) | |
257 | { | |
ca5e578f | 258 | reg_w1(gspca_dev, R3B_Test3, 0x0b); /* Test0Sel = 11 = GPIO */ |
6a7eba24 JFM |
259 | } |
260 | ||
6a7eba24 | 261 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
76dd272b | 262 | u8 *data, /* isoc packet */ |
6a7eba24 JFM |
263 | int len) /* iso packet length */ |
264 | { | |
265 | struct sd *sd = (struct sd *) gspca_dev; | |
2e0903b0 | 266 | int packet_type0, packet_type1; |
6a7eba24 | 267 | |
2e0903b0 | 268 | packet_type0 = packet_type1 = INTER_PACKET; |
ba13cca7 | 269 | if (gspca_dev->empty_packet) { |
2e0903b0 JFM |
270 | gspca_dev->empty_packet = 0; |
271 | sd->packet = gspca_dev->height / 2; | |
272 | packet_type0 = FIRST_PACKET; | |
273 | } else if (sd->packet == 0) | |
274 | return; /* 2 more lines in 352x288 ! */ | |
275 | sd->packet--; | |
276 | if (sd->packet == 0) | |
277 | packet_type1 = LAST_PACKET; | |
278 | ||
279 | /* each packet contains: | |
280 | * - header 2 bytes | |
ca5e578f | 281 | * - RGRG line |
2e0903b0 | 282 | * - 4 bytes |
ca5e578f | 283 | * - GBGB line |
2e0903b0 JFM |
284 | * - 4 bytes |
285 | */ | |
286 | gspca_frame_add(gspca_dev, packet_type0, | |
76dd272b | 287 | data + 2, gspca_dev->width); |
2e0903b0 | 288 | gspca_frame_add(gspca_dev, packet_type1, |
76dd272b | 289 | data + gspca_dev->width + 5, gspca_dev->width); |
6a7eba24 JFM |
290 | } |
291 | ||
726795c1 | 292 | static int sd_s_ctrl(struct v4l2_ctrl *ctrl) |
6a7eba24 | 293 | { |
726795c1 HV |
294 | struct gspca_dev *gspca_dev = |
295 | container_of(ctrl->handler, struct gspca_dev, ctrl_handler); | |
6a7eba24 | 296 | |
726795c1 | 297 | gspca_dev->usb_err = 0; |
6a7eba24 | 298 | |
726795c1 HV |
299 | if (!gspca_dev->streaming) |
300 | return 0; | |
6a7eba24 | 301 | |
726795c1 HV |
302 | switch (ctrl->id) { |
303 | case V4L2_CID_EXPOSURE: | |
304 | setexposure(gspca_dev, ctrl->val); | |
305 | break; | |
306 | case V4L2_CID_GAIN: | |
307 | setgain(gspca_dev, ctrl->val); | |
308 | break; | |
309 | } | |
310 | return gspca_dev->usb_err; | |
6a7eba24 JFM |
311 | } |
312 | ||
726795c1 HV |
313 | static const struct v4l2_ctrl_ops sd_ctrl_ops = { |
314 | .s_ctrl = sd_s_ctrl, | |
315 | }; | |
14bff9b8 | 316 | |
726795c1 | 317 | static int sd_init_controls(struct gspca_dev *gspca_dev) |
14bff9b8 | 318 | { |
726795c1 HV |
319 | struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; |
320 | ||
321 | gspca_dev->vdev.ctrl_handler = hdl; | |
322 | v4l2_ctrl_handler_init(hdl, 2); | |
323 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, | |
324 | V4L2_CID_EXPOSURE, 0, 0x18f, 1, 0x18f); | |
325 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, | |
326 | V4L2_CID_GAIN, 0, 0x7ff, 1, 0x100); | |
327 | ||
328 | if (hdl->error) { | |
329 | pr_err("Could not initialize controls\n"); | |
330 | return hdl->error; | |
331 | } | |
14bff9b8 HG |
332 | return 0; |
333 | } | |
334 | ||
6a7eba24 | 335 | /* sub-driver description */ |
a5ae2062 | 336 | static const struct sd_desc sd_desc = { |
6a7eba24 | 337 | .name = MODULE_NAME, |
6a7eba24 | 338 | .config = sd_config, |
012d6b02 | 339 | .init = sd_init, |
726795c1 | 340 | .init_controls = sd_init_controls, |
6a7eba24 JFM |
341 | .start = sd_start, |
342 | .stopN = sd_stopN, | |
6a7eba24 JFM |
343 | .pkt_scan = sd_pkt_scan, |
344 | }; | |
345 | ||
346 | /* -- module initialisation -- */ | |
95c967c1 | 347 | static const struct usb_device_id device_table[] = { |
9d64fdb1 JFM |
348 | {USB_DEVICE(0x046d, 0x0920)}, |
349 | {USB_DEVICE(0x046d, 0x0921)}, | |
350 | {USB_DEVICE(0x0545, 0x808b)}, | |
351 | {USB_DEVICE(0x0545, 0x8333)}, | |
352 | {USB_DEVICE(0x0923, 0x010f)}, | |
6a7eba24 JFM |
353 | {} |
354 | }; | |
355 | ||
356 | MODULE_DEVICE_TABLE(usb, device_table); | |
357 | ||
358 | /* -- device connect -- */ | |
359 | static int sd_probe(struct usb_interface *intf, | |
360 | const struct usb_device_id *id) | |
361 | { | |
362 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), | |
363 | THIS_MODULE); | |
364 | } | |
365 | ||
366 | static struct usb_driver sd_driver = { | |
367 | .name = MODULE_NAME, | |
368 | .id_table = device_table, | |
369 | .probe = sd_probe, | |
370 | .disconnect = gspca_disconnect, | |
6a709749 JFM |
371 | #ifdef CONFIG_PM |
372 | .suspend = gspca_suspend, | |
373 | .resume = gspca_resume, | |
374 | #endif | |
6a7eba24 JFM |
375 | }; |
376 | ||
ecb3b2b3 | 377 | module_usb_driver(sd_driver); |