aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/gspca/tv8532.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/gspca/tv8532.c')
-rw-r--r--drivers/media/video/gspca/tv8532.c709
1 files changed, 709 insertions, 0 deletions
diff --git a/drivers/media/video/gspca/tv8532.c b/drivers/media/video/gspca/tv8532.c
new file mode 100644
index 000000000000..6218441ba1f0
--- /dev/null
+++ b/drivers/media/video/gspca/tv8532.c
@@ -0,0 +1,709 @@
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
25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 0)
26static const char version[] = "2.1.0";
27
28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("TV8532 USB Camera Driver");
30MODULE_LICENSE("GPL");
31
32/* specific webcam descriptor */
33struct sd {
34 struct gspca_dev gspca_dev; /* !! must be the first item */
35
36 int buflen; /* current length of tmpbuf */
37 __u8 tmpbuf[352 * 288 + 10 * 288]; /* no protection... */
38 __u8 tmpbuf2[352 * 288]; /* no protection... */
39
40 unsigned short brightness;
41 unsigned short contrast;
42
43 char packet;
44 char synchro;
45};
46
47/* V4L2 controls supported by the driver */
48static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
49static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
50static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
51static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
52
53static struct ctrl sd_ctrls[] = {
54#define SD_BRIGHTNESS 0
55 {
56 {
57 .id = V4L2_CID_BRIGHTNESS,
58 .type = V4L2_CTRL_TYPE_INTEGER,
59 .name = "Brightness",
60 .minimum = 1,
61 .maximum = 0x2ff,
62 .step = 1,
63 .default_value = 0x18f,
64 },
65 .set = sd_setbrightness,
66 .get = sd_getbrightness,
67 },
68#define SD_CONTRAST 1
69 {
70 {
71 .id = V4L2_CID_CONTRAST,
72 .type = V4L2_CTRL_TYPE_INTEGER,
73 .name = "Contrast",
74 .minimum = 0,
75 .maximum = 0xffff,
76 .step = 1,
77 .default_value = 0x7fff,
78 },
79 .set = sd_setcontrast,
80 .get = sd_getcontrast,
81 },
82};
83
84static struct cam_mode sif_mode[] = {
85 {V4L2_PIX_FMT_SBGGR8, 176, 144, 1},
86 {V4L2_PIX_FMT_SBGGR8, 352, 288, 0},
87};
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
155static __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,
160 0x0c0509f1, 0
161};
162
163static void reg_r(struct usb_device *dev,
164 __u16 index, __u8 *buffer)
165{
166 usb_control_msg(dev,
167 usb_rcvctrlpipe(dev, 0),
168 TV8532_REQ_RegRead,
169 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
170 0, /* value */
171 index, buffer, sizeof(__u8),
172 500);
173}
174
175static void reg_w(struct usb_device *dev,
176 __u16 index, __u8 *buffer, __u16 length)
177{
178 usb_control_msg(dev,
179 usb_sndctrlpipe(dev, 0),
180 TV8532_REQ_RegWrite,
181 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
182 0, /* value */
183 index, buffer, length, 500);
184}
185
186static void tv_8532WriteEEprom(struct gspca_dev *gspca_dev)
187{
188 int i = 0;
189 __u8 reg, data0, data1, data2, datacmd;
190 struct usb_device *dev = gspca_dev->dev;
191
192 datacmd = 0xb0;;
193 reg_w(dev, TV8532_GPIO, &datacmd, 1);
194 datacmd = TV8532_CMD_EEprom_Open;
195 reg_w(dev, TV8532_CTRL, &datacmd,
196 1);
197/* msleep(1); */
198 while (tv_8532_eeprom_data[i]) {
199 reg = (tv_8532_eeprom_data[i] & 0xff000000) >> 24;
200 reg_w(dev, TV8532_EEprom_Add, &reg, 1);
201 /* msleep(1); */
202 data0 = (tv_8532_eeprom_data[i] & 0x000000ff);
203 reg_w(dev, TV8532_EEprom_DataL, &data0, 1);
204 /* msleep(1); */
205 data1 = (tv_8532_eeprom_data[i] & 0x0000FF00) >> 8;
206 reg_w(dev, TV8532_EEprom_DataM, &data1, 1);
207 /* msleep(1); */
208 data2 = (tv_8532_eeprom_data[i] & 0x00FF0000) >> 16;
209 reg_w(dev, TV8532_EEprom_DataH, &data2, 1);
210 /* msleep(1); */
211 datacmd = 0;
212 reg_w(dev, TV8532_EEprom_Write, &datacmd, 1);
213 /* msleep(10); */
214 i++;
215 }
216 datacmd = i;
217 reg_w(dev, TV8532_EEprom_TableLength, &datacmd, 1);
218/* msleep(1); */
219 datacmd = TV8532_CMD_EEprom_Close;
220 reg_w(dev, TV8532_CTRL, &datacmd, 1);
221 msleep(10);
222}
223
224/* this function is called at probe time */
225static int sd_config(struct gspca_dev *gspca_dev,
226 const struct usb_device_id *id)
227{
228 struct sd *sd = (struct sd *) gspca_dev;
229 struct cam *cam;
230
231 tv_8532WriteEEprom(gspca_dev);
232
233 cam = &gspca_dev->cam;
234 cam->dev_name = (char *) id->driver_info;
235 cam->epaddr = 1;
236 cam->cam_mode = sif_mode;
237 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
238
239 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
240 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
241 return 0;
242}
243
244static void tv_8532ReadRegisters(struct gspca_dev *gspca_dev)
245{
246 struct usb_device *dev = gspca_dev->dev;
247 __u8 data = 0;
248/* __u16 vid, pid; */
249
250 reg_r(dev, 0x0001, &data);
251 PDEBUG(D_USBI, "register 0x01-> %x", data);
252 reg_r(dev, 0x0002, &data);
253 PDEBUG(D_USBI, "register 0x02-> %x", data);
254 reg_r(dev, TV8532_ADWIDTH_L, &data);
255 reg_r(dev, TV8532_ADWIDTH_H, &data);
256 reg_r(dev, TV8532_QUANT_COMP, &data);
257 reg_r(dev, TV8532_MODE_PACKET, &data);
258 reg_r(dev, TV8532_SETCLK, &data);
259 reg_r(dev, TV8532_POINT_L, &data);
260 reg_r(dev, TV8532_POINT_H, &data);
261 reg_r(dev, TV8532_POINTB_L, &data);
262 reg_r(dev, TV8532_POINTB_H, &data);
263 reg_r(dev, TV8532_BUDGET_L, &data);
264 reg_r(dev, TV8532_BUDGET_H, &data);
265 reg_r(dev, TV8532_VID_L, &data);
266 reg_r(dev, TV8532_VID_H, &data);
267 reg_r(dev, TV8532_PID_L, &data);
268 reg_r(dev, TV8532_PID_H, &data);
269 reg_r(dev, TV8532_DeviceID, &data);
270 reg_r(dev, TV8532_AD_COLBEGIN_L, &data);
271 reg_r(dev, TV8532_AD_COLBEGIN_H, &data);
272 reg_r(dev, TV8532_AD_ROWBEGIN_L, &data);
273 reg_r(dev, TV8532_AD_ROWBEGIN_H, &data);
274}
275
276static void tv_8532_setReg(struct gspca_dev *gspca_dev)
277{
278 struct usb_device *dev = gspca_dev->dev;
279 __u8 data = 0;
280 __u8 value[2] = { 0, 0 };
281
282 data = ADCBEGINL;
283 reg_w(dev, TV8532_AD_COLBEGIN_L, &data, 1); /* 0x10 */
284 data = ADCBEGINH; /* also digital gain */
285 reg_w(dev, TV8532_AD_COLBEGIN_H, &data, 1);
286 data = TV8532_CMD_UPDATE;
287 reg_w(dev, TV8532_PART_CTRL, &data, 1); /* 0x00<-0x84 */
288
289 data = 0x0a;
290 reg_w(dev, TV8532_GPIO_OE, &data, 1);
291 /******************************************************/
292 data = ADHEIGHL;
293 reg_w(dev, TV8532_ADHEIGHT_L, &data, 1); /* 0e */
294 data = ADHEIGHH;
295 reg_w(dev, TV8532_ADHEIGHT_H, &data, 1); /* 0f */
296 value[0] = EXPOL;
297 value[1] = EXPOH; /* 350d 0x014c; */
298 reg_w(dev, TV8532_EXPOSURE, value, 2); /* 1c */
299 data = ADCBEGINL;
300 reg_w(dev, TV8532_AD_COLBEGIN_L, &data, 1); /* 0x10 */
301 data = ADCBEGINH; /* also digital gain */
302 reg_w(dev, TV8532_AD_COLBEGIN_H, &data, 1);
303 data = ADRBEGINL;
304 reg_w(dev, TV8532_AD_ROWBEGIN_L, &data, 1); /* 0x14 */
305
306 data = 0x00;
307 reg_w(dev, TV8532_AD_SLOPE, &data, 1); /* 0x91 */
308 data = 0x02;
309 reg_w(dev, TV8532_AD_BITCTRL, &data, 1); /* 0x94 */
310
311
312 data = TV8532_CMD_EEprom_Close;
313 reg_w(dev, TV8532_CTRL, &data, 1); /* 0x01 */
314
315 data = 0x00;
316 reg_w(dev, TV8532_AD_SLOPE, &data, 1); /* 0x91 */
317 data = TV8532_CMD_UPDATE;
318 reg_w(dev, TV8532_PART_CTRL, &data, 1); /* 0x00<-0x84 */
319}
320
321static void tv_8532_PollReg(struct gspca_dev *gspca_dev)
322{
323 struct usb_device *dev = gspca_dev->dev;
324 __u8 data = 0;
325 int i;
326
327 /* strange polling from tgc */
328 for (i = 0; i < 10; i++) {
329 data = TESTCLK; /* 0x48; //0x08; */
330 reg_w(dev, TV8532_SETCLK, &data, 1); /* 0x2c */
331 data = TV8532_CMD_UPDATE;
332 reg_w(dev, TV8532_PART_CTRL, &data, 1);
333 data = 0x01;
334 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
335 }
336}
337
338/* this function is called at open time */
339static int sd_open(struct gspca_dev *gspca_dev)
340{
341 struct usb_device *dev = gspca_dev->dev;
342 __u8 data = 0;
343 __u8 dataStart = 0;
344 __u8 value[2] = { 0, 0 };
345
346 data = 0x32;
347 reg_w(dev, TV8532_AD_SLOPE, &data, 1);
348 data = 0;
349 reg_w(dev, TV8532_AD_BITCTRL, &data, 1);
350 tv_8532ReadRegisters(gspca_dev);
351 data = 0x0b;
352 reg_w(dev, TV8532_GPIO_OE, &data, 1);
353 value[0] = ADHEIGHL;
354 value[1] = ADHEIGHH; /* 401d 0x0169; */
355 reg_w(dev, TV8532_ADHEIGHT_L, value, 2); /* 0e */
356 value[0] = EXPOL;
357 value[1] = EXPOH; /* 350d 0x014c; */
358 reg_w(dev, TV8532_EXPOSURE, value, 2); /* 1c */
359 data = ADWIDTHL; /* 0x20; */
360 reg_w(dev, TV8532_ADWIDTH_L, &data, 1); /* 0x0c */
361 data = ADWIDTHH;
362 reg_w(dev, TV8532_ADWIDTH_H, &data, 1); /* 0x0d */
363
364 /*******************************************************************/
365 data = TESTCOMP; /* 0x72 compressed mode */
366 reg_w(dev, TV8532_QUANT_COMP, &data, 1); /* 0x28 */
367 data = TESTLINE; /* 0x84; // CIF | 4 packet */
368 reg_w(dev, TV8532_MODE_PACKET, &data, 1); /* 0x29 */
369
370 /************************************************/
371 data = TESTCLK; /* 0x48; //0x08; */
372 reg_w(dev, TV8532_SETCLK, &data, 1); /* 0x2c */
373 data = TESTPTL; /* 0x38; */
374 reg_w(dev, TV8532_POINT_L, &data, 1); /* 0x2d */
375 data = TESTPTH; /* 0x04; */
376 reg_w(dev, TV8532_POINT_H, &data, 1); /* 0x2e */
377 dataStart = TESTPTBL; /* 0x04; */
378 reg_w(dev, TV8532_POINTB_L, &dataStart, 1); /* 0x2f */
379 data = TESTPTBH; /* 0x04; */
380 reg_w(dev, TV8532_POINTB_H, &data, 1); /* 0x30 */
381 data = TV8532_CMD_UPDATE;
382 reg_w(dev, TV8532_PART_CTRL, &data, 1); /* 0x00<-0x84 */
383 /*************************************************/
384 data = 0x01;
385 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
386 msleep(200);
387 data = 0x00;
388 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
389 /*************************************************/
390 tv_8532_setReg(gspca_dev);
391 /*************************************************/
392 data = 0x0b;
393 reg_w(dev, TV8532_GPIO_OE, &data,
394 1);
395 /*************************************************/
396 tv_8532_setReg(gspca_dev);
397 /*************************************************/
398 tv_8532_PollReg(gspca_dev);
399 return 0;
400}
401
402static void setbrightness(struct gspca_dev *gspca_dev)
403{
404 struct sd *sd = (struct sd *) gspca_dev;
405 __u8 value[2];
406 __u8 data;
407 int brightness = sd->brightness;
408
409 value[1] = (brightness >> 8) & 0xff;
410 value[0] = (brightness) & 0xff;
411 reg_w(gspca_dev->dev, TV8532_EXPOSURE, value, 2); /* 1c */
412 data = TV8532_CMD_UPDATE;
413 reg_w(gspca_dev->dev, TV8532_PART_CTRL, &data, 1);
414}
415
416/* -- start the camera -- */
417static void sd_start(struct gspca_dev *gspca_dev)
418{
419 struct usb_device *dev = gspca_dev->dev;
420 __u8 data = 0;
421 __u8 dataStart = 0;
422 __u8 value[2];
423
424 data = 0x32;
425 reg_w(dev, TV8532_AD_SLOPE, &data, 1);
426 data = 0;
427 reg_w(dev, TV8532_AD_BITCTRL, &data, 1);
428 tv_8532ReadRegisters(gspca_dev);
429 data = 0x0b;
430 reg_w(dev, TV8532_GPIO_OE, &data, 1);
431 value[0] = ADHEIGHL;
432 value[1] = ADHEIGHH; /* 401d 0x0169; */
433 reg_w(dev, TV8532_ADHEIGHT_L, value, 2); /* 0e */
434/* value[0] = EXPOL; value[1] =EXPOH; * 350d 0x014c; */
435/* reg_w(dev,TV8532_REQ_RegWrite,0,TV8532_EXPOSURE,value,2); * 1c */
436 setbrightness(gspca_dev);
437
438 data = ADWIDTHL; /* 0x20; */
439 reg_w(dev, TV8532_ADWIDTH_L, &data, 1); /* 0x0c */
440 data = ADWIDTHH;
441 reg_w(dev, TV8532_ADWIDTH_H, &data, 1); /* 0x0d */
442
443 /************************************************/
444 data = TESTCOMP; /* 0x72 compressed mode */
445 reg_w(dev, TV8532_QUANT_COMP, &data, 1); /* 0x28 */
446 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode) {
447 /* 176x144 */
448 data = QCIFLINE; /* 0x84; // CIF | 4 packet */
449 reg_w(dev, TV8532_MODE_PACKET, &data, 1); /* 0x29 */
450 } else {
451 /* 352x288 */
452 data = TESTLINE; /* 0x84; // CIF | 4 packet */
453 reg_w(dev, TV8532_MODE_PACKET, &data, 1); /* 0x29 */
454 }
455 /************************************************/
456 data = TESTCLK; /* 0x48; //0x08; */
457 reg_w(dev, TV8532_SETCLK, &data, 1); /* 0x2c */
458 data = TESTPTL; /* 0x38; */
459 reg_w(dev, TV8532_POINT_L, &data, 1); /* 0x2d */
460 data = TESTPTH; /* 0x04; */
461 reg_w(dev, TV8532_POINT_H, &data, 1); /* 0x2e */
462 dataStart = TESTPTBL; /* 0x04; */
463 reg_w(dev, TV8532_POINTB_L, &dataStart, 1); /* 0x2f */
464 data = TESTPTBH; /* 0x04; */
465 reg_w(dev, TV8532_POINTB_H, &data, 1); /* 0x30 */
466 data = TV8532_CMD_UPDATE;
467 reg_w(dev, TV8532_PART_CTRL, &data, 1); /* 0x00<-0x84 */
468 /************************************************/
469 data = 0x01;
470 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
471 msleep(200);
472 data = 0x00;
473 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
474 /************************************************/
475 tv_8532_setReg(gspca_dev);
476 /************************************************/
477 data = 0x0b;
478 reg_w(dev, TV8532_GPIO_OE, &data, 1);
479 /************************************************/
480 tv_8532_setReg(gspca_dev);
481 /************************************************/
482 tv_8532_PollReg(gspca_dev);
483 data = 0x00;
484 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
485}
486
487static void sd_stopN(struct gspca_dev *gspca_dev)
488{
489 struct usb_device *dev = gspca_dev->dev;
490 __u8 data;
491
492 data = 0x0b;
493 reg_w(dev, TV8532_GPIO_OE, &data, 1);
494}
495
496static void sd_stop0(struct gspca_dev *gspca_dev)
497{
498}
499
500static void sd_close(struct gspca_dev *gspca_dev)
501{
502}
503
504static void tv8532_preprocess(struct gspca_dev *gspca_dev)
505{
506 struct sd *sd = (struct sd *) gspca_dev;
507/* we should received a whole frame with header and EOL marker
508 * in gspca_dev->tmpbuf and return a GBRG pattern in gspca_dev->tmpbuf2
509 * sequence 2bytes header the Alternate pixels bayer GB 4 bytes
510 * Alternate pixels bayer RG 4 bytes EOL */
511 int width = gspca_dev->width;
512 int height = gspca_dev->height;
513 unsigned char *dst = sd->tmpbuf2;
514 unsigned char *data = sd->tmpbuf;
515 int i;
516
517 /* precompute where is the good bayer line */
518 if (((data[3] + data[width + 7]) >> 1)
519 + (data[4] >> 2)
520 + (data[width + 6] >> 1) >= ((data[2] + data[width + 6]) >> 1)
521 + (data[3] >> 2)
522 + (data[width + 5] >> 1))
523 data += 3;
524 else
525 data += 2;
526 for (i = 0; i < height / 2; i++) {
527 memcpy(dst, data, width);
528 data += width + 3;
529 dst += width;
530 memcpy(dst, data, width);
531 data += width + 7;
532 dst += width;
533 }
534}
535
536static void sd_pkt_scan(struct gspca_dev *gspca_dev,
537 struct gspca_frame *frame, /* target */
538 __u8 *data, /* isoc packet */
539 int len) /* iso packet length */
540{
541 struct sd *sd = (struct sd *) gspca_dev;
542
543 if (data[0] != 0x80) {
544 sd->packet++;
545 if (sd->buflen + len > sizeof sd->tmpbuf) {
546 if (gspca_dev->last_packet_type != DISCARD_PACKET) {
547 PDEBUG(D_PACK, "buffer overflow");
548 gspca_dev->last_packet_type = DISCARD_PACKET;
549 }
550 return;
551 }
552 memcpy(&sd->tmpbuf[sd->buflen], data, len);
553 sd->buflen += len;
554 return;
555 }
556
557 /* here we detect 0x80 */
558 /* counter is limited so we need few header for a frame :) */
559
560 /* header 0x80 0x80 0x80 0x80 0x80 */
561 /* packet 00 63 127 145 00 */
562 /* sof 0 1 1 0 0 */
563
564 /* update sequence */
565 if (sd->packet == 63 || sd->packet == 127)
566 sd->synchro = 1;
567
568 /* is there a frame start ? */
569 if (sd->packet >= (gspca_dev->height >> 1) - 1) {
570 PDEBUG(D_PACK, "SOF > %d packet %d", sd->synchro,
571 sd->packet);
572 if (!sd->synchro) { /* start of frame */
573 if (gspca_dev->last_packet_type == FIRST_PACKET) {
574 tv8532_preprocess(gspca_dev);
575 frame = gspca_frame_add(gspca_dev,
576 LAST_PACKET,
577 frame, sd->tmpbuf2,
578 gspca_dev->width *
579 gspca_dev->width);
580 }
581 gspca_frame_add(gspca_dev, FIRST_PACKET,
582 frame, data, 0);
583 memcpy(sd->tmpbuf, data, len);
584 sd->buflen = len;
585 sd->packet = 0;
586 return;
587 }
588 if (gspca_dev->last_packet_type != DISCARD_PACKET) {
589 PDEBUG(D_PACK,
590 "Warning wrong TV8532 frame detection %d",
591 sd->packet);
592 gspca_dev->last_packet_type = DISCARD_PACKET;
593 }
594 return;
595 }
596
597 if (!sd->synchro) {
598 /* Drop packet frame corrupt */
599 PDEBUG(D_PACK, "DROP SOF %d packet %d",
600 sd->synchro, sd->packet);
601 sd->packet = 0;
602 gspca_dev->last_packet_type = DISCARD_PACKET;
603 return;
604 }
605 sd->synchro = 1;
606 sd->packet++;
607 memcpy(&sd->tmpbuf[sd->buflen], data, len);
608 sd->buflen += len;
609}
610
611static void setcontrast(struct gspca_dev *gspca_dev)
612{
613}
614
615static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
616{
617 struct sd *sd = (struct sd *) gspca_dev;
618
619 sd->brightness = val;
620 if (gspca_dev->streaming)
621 setbrightness(gspca_dev);
622 return 0;
623}
624
625static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
626{
627 struct sd *sd = (struct sd *) gspca_dev;
628
629 *val = sd->brightness;
630 return 0;
631}
632
633static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
634{
635 struct sd *sd = (struct sd *) gspca_dev;
636
637 sd->contrast = val;
638 if (gspca_dev->streaming)
639 setcontrast(gspca_dev);
640 return 0;
641}
642
643static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
644{
645 struct sd *sd = (struct sd *) gspca_dev;
646
647 *val = sd->contrast;
648 return 0;
649}
650
651/* sub-driver description */
652static struct sd_desc sd_desc = {
653 .name = MODULE_NAME,
654 .ctrls = sd_ctrls,
655 .nctrls = ARRAY_SIZE(sd_ctrls),
656 .config = sd_config,
657 .open = sd_open,
658 .start = sd_start,
659 .stopN = sd_stopN,
660 .stop0 = sd_stop0,
661 .close = sd_close,
662 .pkt_scan = sd_pkt_scan,
663};
664
665/* -- module initialisation -- */
666#define DVNM(name) .driver_info = (kernel_ulong_t) name
667static __devinitdata struct usb_device_id device_table[] = {
668 {USB_DEVICE(0x046d, 0x0920), DVNM("QC Express")},
669 {USB_DEVICE(0x046d, 0x0921), DVNM("Labtec Webcam")},
670 {USB_DEVICE(0x0545, 0x808b), DVNM("Veo Stingray")},
671 {USB_DEVICE(0x0545, 0x8333), DVNM("Veo Stingray")},
672 {USB_DEVICE(0x0923, 0x010f), DVNM("ICM532 cams")},
673 {}
674};
675
676MODULE_DEVICE_TABLE(usb, device_table);
677
678/* -- device connect -- */
679static int sd_probe(struct usb_interface *intf,
680 const struct usb_device_id *id)
681{
682 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
683 THIS_MODULE);
684}
685
686static struct usb_driver sd_driver = {
687 .name = MODULE_NAME,
688 .id_table = device_table,
689 .probe = sd_probe,
690 .disconnect = gspca_disconnect,
691};
692
693/* -- module insert / remove -- */
694static int __init sd_mod_init(void)
695{
696 if (usb_register(&sd_driver) < 0)
697 return -1;
698 PDEBUG(D_PROBE, "v%s registered", version);
699 return 0;
700}
701
702static void __exit sd_mod_exit(void)
703{
704 usb_deregister(&sd_driver);
705 PDEBUG(D_PROBE, "deregistered");
706}
707
708module_init(sd_mod_init);
709module_exit(sd_mod_exit);