blob: 94163cceb28ae0bb6ec051294420288ddbc0816a [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/*
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
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030025MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
26MODULE_DESCRIPTION("TV8532 USB Camera Driver");
27MODULE_LICENSE("GPL");
28
29/* specific webcam descriptor */
30struct sd {
31 struct gspca_dev gspca_dev; /* !! must be the first item */
32
Jean-Francois Moineba13cca2008-10-24 04:19:29 -030033 __u16 brightness;
34 __u16 contrast;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030035
Jean-Francois Moineba13cca2008-10-24 04:19:29 -030036 __u8 packet;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030037};
38
39/* V4L2 controls supported by the driver */
40static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
41static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
42static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
43static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
44
45static struct ctrl sd_ctrls[] = {
46#define SD_BRIGHTNESS 0
47 {
48 {
49 .id = V4L2_CID_BRIGHTNESS,
50 .type = V4L2_CTRL_TYPE_INTEGER,
51 .name = "Brightness",
52 .minimum = 1,
53 .maximum = 0x2ff,
54 .step = 1,
55 .default_value = 0x18f,
56 },
57 .set = sd_setbrightness,
58 .get = sd_getbrightness,
59 },
60#define SD_CONTRAST 1
61 {
62 {
63 .id = V4L2_CID_CONTRAST,
64 .type = V4L2_CTRL_TYPE_INTEGER,
65 .name = "Contrast",
66 .minimum = 0,
67 .maximum = 0xffff,
68 .step = 1,
69 .default_value = 0x7fff,
70 },
71 .set = sd_setcontrast,
72 .get = sd_getcontrast,
73 },
74};
75
Jean-Francois Moinecc611b82008-12-29 07:49:41 -030076static const struct v4l2_pix_format sif_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -030077 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
78 .bytesperline = 176,
79 .sizeimage = 176 * 144,
80 .colorspace = V4L2_COLORSPACE_SRGB,
81 .priv = 1},
82 {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
83 .bytesperline = 352,
84 .sizeimage = 352 * 288,
85 .colorspace = V4L2_COLORSPACE_SRGB,
86 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030087};
88
89/*
90 * Initialization data: this is the first set-up data written to the
91 * device (before the open data).
92 */
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
112
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
128
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
154
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300155static const __u32 tv_8532_eeprom_data[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300156/* add dataL dataM dataH */
157 0x00010001, 0x01018011, 0x02050014, 0x0305001c,
158 0x040d001e, 0x0505001f, 0x06050519, 0x0705011b,
159 0x0805091e, 0x090d892e, 0x0a05892f, 0x0b050dd9,
160 0x0c0509f1, 0
161};
162
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300163static int reg_r(struct gspca_dev *gspca_dev,
164 __u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300165{
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300166 usb_control_msg(gspca_dev->dev,
167 usb_rcvctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300168 TV8532_REQ_RegRead,
169 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
170 0, /* value */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300171 index, gspca_dev->usb_buf, 1,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300172 500);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300173 return gspca_dev->usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300174}
175
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300176/* write 1 byte */
177static void reg_w_1(struct gspca_dev *gspca_dev,
178 __u16 index, __u8 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300179{
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300180 gspca_dev->usb_buf[0] = value;
181 usb_control_msg(gspca_dev->dev,
182 usb_sndctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300183 TV8532_REQ_RegWrite,
184 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
185 0, /* value */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300186 index, gspca_dev->usb_buf, 1, 500);
187}
188
189/* write 2 bytes */
190static void reg_w_2(struct gspca_dev *gspca_dev,
191 __u16 index, __u8 val1, __u8 val2)
192{
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),
197 TV8532_REQ_RegWrite,
198 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
199 0, /* value */
200 index, gspca_dev->usb_buf, 2, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300201}
202
203static void tv_8532WriteEEprom(struct gspca_dev *gspca_dev)
204{
205 int i = 0;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300206 __u8 reg, data0, data1, data2;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300207
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300208 reg_w_1(gspca_dev, TV8532_GPIO, 0xb0);
209 reg_w_1(gspca_dev, TV8532_CTRL, TV8532_CMD_EEprom_Open);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300210/* msleep(1); */
211 while (tv_8532_eeprom_data[i]) {
212 reg = (tv_8532_eeprom_data[i] & 0xff000000) >> 24;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300213 reg_w_1(gspca_dev, TV8532_EEprom_Add, reg);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300214 /* msleep(1); */
215 data0 = (tv_8532_eeprom_data[i] & 0x000000ff);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300216 reg_w_1(gspca_dev, TV8532_EEprom_DataL, data0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300217 /* msleep(1); */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300218 data1 = (tv_8532_eeprom_data[i] & 0x0000ff00) >> 8;
219 reg_w_1(gspca_dev, TV8532_EEprom_DataM, data1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300220 /* msleep(1); */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300221 data2 = (tv_8532_eeprom_data[i] & 0x00ff0000) >> 16;
222 reg_w_1(gspca_dev, TV8532_EEprom_DataH, data2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300223 /* msleep(1); */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300224 reg_w_1(gspca_dev, TV8532_EEprom_Write, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300225 /* msleep(10); */
226 i++;
227 }
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300228 reg_w_1(gspca_dev, TV8532_EEprom_TableLength, i);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300229/* msleep(1); */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300230 reg_w_1(gspca_dev, TV8532_CTRL, TV8532_CMD_EEprom_Close);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300231 msleep(10);
232}
233
234/* this function is called at probe time */
235static int sd_config(struct gspca_dev *gspca_dev,
236 const struct usb_device_id *id)
237{
238 struct sd *sd = (struct sd *) gspca_dev;
239 struct cam *cam;
240
241 tv_8532WriteEEprom(gspca_dev);
242
243 cam = &gspca_dev->cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300244 cam->epaddr = 1;
245 cam->cam_mode = sif_mode;
246 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
247
248 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
249 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
250 return 0;
251}
252
253static void tv_8532ReadRegisters(struct gspca_dev *gspca_dev)
254{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300255 __u8 data;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300256
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300257 data = reg_r(gspca_dev, 0x0001);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300258 PDEBUG(D_USBI, "register 0x01-> %x", data);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300259 data = reg_r(gspca_dev, 0x0002);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300260 PDEBUG(D_USBI, "register 0x02-> %x", data);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300261 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);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300281}
282
283static void tv_8532_setReg(struct gspca_dev *gspca_dev)
284{
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300285 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 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300291
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300292 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0a);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300293 /******************************************************/
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300294 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 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300304
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300305 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x00); /* 0x91 */
306 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x02); /* 0x94 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300307
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300308 reg_w_1(gspca_dev, TV8532_CTRL,
309 TV8532_CMD_EEprom_Close); /* 0x01 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300310
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300311 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 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300314}
315
316static void tv_8532_PollReg(struct gspca_dev *gspca_dev)
317{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300318 int i;
319
320 /* strange polling from tgc */
321 for (i = 0; i < 10; i++) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300322 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 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300326 }
327}
328
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300329/* this function is called at probe and resume time */
330static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300331{
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300332 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32);
333 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300334 tv_8532ReadRegisters(gspca_dev);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300335 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 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300342
343 /*******************************************************************/
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300344 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 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300348
349 /************************************************/
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300350 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 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300362 /*************************************************/
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300363 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300364 msleep(200);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300365 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300366 /*************************************************/
367 tv_8532_setReg(gspca_dev);
368 /*************************************************/
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300369 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300370 /*************************************************/
371 tv_8532_setReg(gspca_dev);
372 /*************************************************/
373 tv_8532_PollReg(gspca_dev);
374 return 0;
375}
376
377static void setbrightness(struct gspca_dev *gspca_dev)
378{
379 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300380 int brightness = sd->brightness;
381
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300382 reg_w_2(gspca_dev, TV8532_EXPOSURE,
383 brightness >> 8, brightness); /* 1c */
384 reg_w_1(gspca_dev, TV8532_PART_CTRL, TV8532_CMD_UPDATE);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300385}
386
387/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300388static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300389{
Jean-Francois Moine2e0903b2008-10-27 04:43:49 -0300390 struct sd *sd = (struct sd *) gspca_dev;
391
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300392 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32);
393 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300394 tv_8532ReadRegisters(gspca_dev);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300395 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 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300400 setbrightness(gspca_dev);
401
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300402 reg_w_1(gspca_dev, TV8532_ADWIDTH_L, ADWIDTHL); /* 0x20; 0x0c */
403 reg_w_1(gspca_dev, TV8532_ADWIDTH_H, ADWIDTHH); /* 0x0d */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300404
405 /************************************************/
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300406 reg_w_1(gspca_dev, TV8532_QUANT_COMP,
407 TESTCOMP); /* 0x72 compressed mode 0x28 */
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300408 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300409 /* 176x144 */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300410 reg_w_1(gspca_dev, TV8532_MODE_PACKET,
411 QCIFLINE); /* 0x84; // CIF | 4 packet 0x29 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300412 } else {
413 /* 352x288 */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300414 reg_w_1(gspca_dev, TV8532_MODE_PACKET,
415 TESTLINE); /* 0x84; // CIF | 4 packet 0x29 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300416 }
417 /************************************************/
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300418 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 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300430 /************************************************/
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300431 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300432 msleep(200);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300433 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300434 /************************************************/
435 tv_8532_setReg(gspca_dev);
436 /************************************************/
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300437 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300438 /************************************************/
439 tv_8532_setReg(gspca_dev);
440 /************************************************/
441 tv_8532_PollReg(gspca_dev);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300442 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */
Jean-Francois Moineba13cca2008-10-24 04:19:29 -0300443
444 gspca_dev->empty_packet = 0; /* check the empty packets */
Jean-Francois Moine2e0903b2008-10-27 04:43:49 -0300445 sd->packet = 0; /* ignore the first packets */
Jean-Francois Moineba13cca2008-10-24 04:19:29 -0300446
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300447 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300448}
449
450static void sd_stopN(struct gspca_dev *gspca_dev)
451{
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300452 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300453}
454
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300455static 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 */
459{
460 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine2e0903b2008-10-27 04:43:49 -0300461 int packet_type0, packet_type1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300462
Jean-Francois Moine2e0903b2008-10-27 04:43:49 -0300463 packet_type0 = packet_type1 = INTER_PACKET;
Jean-Francois Moineba13cca2008-10-24 04:19:29 -0300464 if (gspca_dev->empty_packet) {
Jean-Francois Moine2e0903b2008-10-27 04:43:49 -0300465 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 ! */
470 sd->packet--;
471 if (sd->packet == 0)
472 packet_type1 = LAST_PACKET;
473
474 /* each packet contains:
475 * - header 2 bytes
476 * - RG line
477 * - 4 bytes
478 * - GB line
479 * - 4 bytes
480 */
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);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300485}
486
487static void setcontrast(struct gspca_dev *gspca_dev)
488{
489}
490
491static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
492{
493 struct sd *sd = (struct sd *) gspca_dev;
494
495 sd->brightness = val;
496 if (gspca_dev->streaming)
497 setbrightness(gspca_dev);
498 return 0;
499}
500
501static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
502{
503 struct sd *sd = (struct sd *) gspca_dev;
504
505 *val = sd->brightness;
506 return 0;
507}
508
509static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
510{
511 struct sd *sd = (struct sd *) gspca_dev;
512
513 sd->contrast = val;
514 if (gspca_dev->streaming)
515 setcontrast(gspca_dev);
516 return 0;
517}
518
519static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
520{
521 struct sd *sd = (struct sd *) gspca_dev;
522
523 *val = sd->contrast;
524 return 0;
525}
526
527/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300528static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300529 .name = MODULE_NAME,
530 .ctrls = sd_ctrls,
531 .nctrls = ARRAY_SIZE(sd_ctrls),
532 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300533 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300534 .start = sd_start,
535 .stopN = sd_stopN,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300536 .pkt_scan = sd_pkt_scan,
537};
538
539/* -- module initialisation -- */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300540static const __devinitdata struct usb_device_id device_table[] = {
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -0300541 {USB_DEVICE(0x046d, 0x0920)},
542 {USB_DEVICE(0x046d, 0x0921)},
543 {USB_DEVICE(0x0545, 0x808b)},
544 {USB_DEVICE(0x0545, 0x8333)},
545 {USB_DEVICE(0x0923, 0x010f)},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300546 {}
547};
548
549MODULE_DEVICE_TABLE(usb, device_table);
550
551/* -- device connect -- */
552static int sd_probe(struct usb_interface *intf,
553 const struct usb_device_id *id)
554{
555 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
556 THIS_MODULE);
557}
558
559static struct usb_driver sd_driver = {
560 .name = MODULE_NAME,
561 .id_table = device_table,
562 .probe = sd_probe,
563 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300564#ifdef CONFIG_PM
565 .suspend = gspca_suspend,
566 .resume = gspca_resume,
567#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300568};
569
570/* -- module insert / remove -- */
571static int __init sd_mod_init(void)
572{
573 if (usb_register(&sd_driver) < 0)
574 return -1;
Jean-Francois Moine10b0e962008-07-22 05:35:10 -0300575 PDEBUG(D_PROBE, "registered");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300576 return 0;
577}
578
579static void __exit sd_mod_exit(void)
580{
581 usb_deregister(&sd_driver);
582 PDEBUG(D_PROBE, "deregistered");
583}
584
585module_init(sd_mod_init);
586module_exit(sd_mod_exit);