aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorJean-Francois Moine <moinejf@free.fr>2008-07-14 08:38:29 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-07-20 06:26:14 -0400
commit739570bb218bb4607df1f197282561e97a98e54a (patch)
tree25555dfe5ac873bc96866c486d6f6c1dcabf24f4 /drivers/media
parent5b77ae7776183d733ec86727bcc34c52a336afd6 (diff)
V4L/DVB (8352): gspca: Buffers for USB exchanges cannot be in the stack.
gspca: Protect dq_callback() against simultaneous USB exchanges. Temporary buffer for USB exchanges added in the device struct. (all) Use a temporary buffer for all USB exchanges. Signed-off-by: Jean-Francois Moine <moinejf@free.fr> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/video/gspca/conex.c385
-rw-r--r--drivers/media/video/gspca/etoms.c443
-rw-r--r--drivers/media/video/gspca/gspca.c6
-rw-r--r--drivers/media/video/gspca/gspca.h1
-rw-r--r--drivers/media/video/gspca/mars.c158
-rw-r--r--drivers/media/video/gspca/ov519.c19
-rw-r--r--drivers/media/video/gspca/pac207.c19
-rw-r--r--drivers/media/video/gspca/pac7311.c336
-rw-r--r--drivers/media/video/gspca/sonixb.c155
-rw-r--r--drivers/media/video/gspca/sonixj.c293
-rw-r--r--drivers/media/video/gspca/spca500.c265
-rw-r--r--drivers/media/video/gspca/spca501.c23
-rw-r--r--drivers/media/video/gspca/spca505.c24
-rw-r--r--drivers/media/video/gspca/spca506.c35
-rw-r--r--drivers/media/video/gspca/spca508.c37
-rw-r--r--drivers/media/video/gspca/spca561.c115
-rw-r--r--drivers/media/video/gspca/stk014.c86
-rw-r--r--drivers/media/video/gspca/sunplus.c279
-rw-r--r--drivers/media/video/gspca/t613.c176
-rw-r--r--drivers/media/video/gspca/tv8532.c360
-rw-r--r--drivers/media/video/gspca/vc032x.c81
-rw-r--r--drivers/media/video/gspca/zc3xx.c199
22 files changed, 1700 insertions, 1795 deletions
diff --git a/drivers/media/video/gspca/conex.c b/drivers/media/video/gspca/conex.c
index b5481017dd4f..013d593b0c67 100644
--- a/drivers/media/video/gspca/conex.c
+++ b/drivers/media/video/gspca/conex.c
@@ -25,8 +25,8 @@
25#define CONEX_CAM 1 /* special JPEG header */ 25#define CONEX_CAM 1 /* special JPEG header */
26#include "jpeg.h" 26#include "jpeg.h"
27 27
28#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 28#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
29static const char version[] = "2.1.5"; 29static const char version[] = "2.1.7";
30 30
31MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 31MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
32MODULE_DESCRIPTION("GSPCA USB Conexant Camera Driver"); 32MODULE_DESCRIPTION("GSPCA USB Conexant Camera Driver");
@@ -119,40 +119,67 @@ static struct v4l2_pix_format vga_mode[] = {
119 .priv = 0}, 119 .priv = 0},
120}; 120};
121 121
122static void reg_r(struct usb_device *dev, 122/* the read bytes are found in gspca_dev->usb_buf */
123 __u16 index, 123static void reg_r(struct gspca_dev *gspca_dev,
124 __u8 *buffer, __u16 length) 124 __u16 index,
125 __u16 len)
125{ 126{
127 struct usb_device *dev = gspca_dev->dev;
128
129#ifdef CONFIG_VIDEO_ADV_DEBUG
130 if (len > sizeof gspca_dev->usb_buf) {
131 err("reg_r: buffer overflow");
132 return;
133 }
134#endif
126 usb_control_msg(dev, 135 usb_control_msg(dev,
127 usb_rcvctrlpipe(dev, 0), 136 usb_rcvctrlpipe(dev, 0),
128 0, 137 0,
129 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 138 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
130 0, 139 0,
131 index, buffer, length, 140 index, gspca_dev->usb_buf, len,
132 500); 141 500);
133 PDEBUG(D_USBI, "reg read [%02x] -> %02x ..", index, *buffer); 142 PDEBUG(D_USBI, "reg read [%02x] -> %02x ..",
143 index, gspca_dev->usb_buf[0]);
144}
145
146/* the bytes to write are in gspca_dev->usb_buf */
147static void reg_w_val(struct gspca_dev *gspca_dev,
148 __u16 index,
149 __u8 val)
150{
151 struct usb_device *dev = gspca_dev->dev;
152
153 gspca_dev->usb_buf[0] = val;
154 usb_control_msg(dev,
155 usb_sndctrlpipe(dev, 0),
156 0,
157 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
158 0,
159 index, gspca_dev->usb_buf, 1, 500);
134} 160}
135 161
136static void reg_w(struct usb_device *dev, 162static void reg_w(struct gspca_dev *gspca_dev,
137 __u16 index, 163 __u16 index,
138 const __u8 *buffer, __u16 len) 164 const __u8 *buffer,
165 __u16 len)
139{ 166{
140 __u8 tmpbuf[8]; 167 struct usb_device *dev = gspca_dev->dev;
141 168
142#ifdef CONFIG_VIDEO_ADV_DEBUG 169#ifdef CONFIG_VIDEO_ADV_DEBUG
143 if (len > sizeof tmpbuf) { 170 if (len > sizeof gspca_dev->usb_buf) {
144 PDEBUG(D_ERR|D_PACK, "reg_w: buffer overflow"); 171 err("reg_w: buffer overflow");
145 return; 172 return;
146 } 173 }
147 PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer); 174 PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer);
148#endif 175#endif
149 memcpy(tmpbuf, buffer, len); 176 memcpy(gspca_dev->usb_buf, buffer, len);
150 usb_control_msg(dev, 177 usb_control_msg(dev,
151 usb_sndctrlpipe(dev, 0), 178 usb_sndctrlpipe(dev, 0),
152 0, 179 0,
153 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 180 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
154 0, 181 0,
155 index, tmpbuf, len, 500); 182 index, gspca_dev->usb_buf, len, 500);
156} 183}
157 184
158static const __u8 cx_sensor_init[][4] = { 185static const __u8 cx_sensor_init[][4] = {
@@ -232,17 +259,14 @@ static const __u8 cx11646_fw1[][3] = {
232}; 259};
233static void cx11646_fw(struct gspca_dev*gspca_dev) 260static void cx11646_fw(struct gspca_dev*gspca_dev)
234{ 261{
235 __u8 val;
236 int i = 0; 262 int i = 0;
237 263
238 val = 0x02; 264 reg_w_val(gspca_dev, 0x006a, 0x02);
239 reg_w(gspca_dev->dev, 0x006a, &val, 1);
240 while (cx11646_fw1[i][1]) { 265 while (cx11646_fw1[i][1]) {
241 reg_w(gspca_dev->dev, 0x006b, cx11646_fw1[i], 3); 266 reg_w(gspca_dev, 0x006b, cx11646_fw1[i], 3);
242 i++; 267 i++;
243 } 268 }
244 val = 0x00; 269 reg_w_val(gspca_dev, 0x006a, 0x00);
245 reg_w(gspca_dev->dev, 0x006a, &val, 1);
246} 270}
247 271
248static const __u8 cxsensor[] = { 272static const __u8 cxsensor[] = {
@@ -273,52 +297,47 @@ static const __u8 reg7b[] = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff };
273 297
274static void cx_sensor(struct gspca_dev*gspca_dev) 298static void cx_sensor(struct gspca_dev*gspca_dev)
275{ 299{
276 __u8 val;
277 int i = 0; 300 int i = 0;
278 __u8 bufread[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
279 int length; 301 int length;
280 const __u8 *ptsensor = cxsensor; 302 const __u8 *ptsensor = cxsensor;
281 303
282 reg_w(gspca_dev->dev, 0x0020, reg20, 8); 304 reg_w(gspca_dev, 0x0020, reg20, 8);
283 reg_w(gspca_dev->dev, 0x0028, reg28, 8); 305 reg_w(gspca_dev, 0x0028, reg28, 8);
284 reg_w(gspca_dev->dev, 0x0010, reg10, 8); 306 reg_w(gspca_dev, 0x0010, reg10, 8);
285 val = 0x03; 307 reg_w_val(gspca_dev, 0x0092, 0x03);
286 reg_w(gspca_dev->dev, 0x0092, &val, 1);
287 308
288 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { 309 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
289 case 0: 310 case 0:
290 reg_w(gspca_dev->dev, 0x0071, reg71a, 4); 311 reg_w(gspca_dev, 0x0071, reg71a, 4);
291 break; 312 break;
292 case 1: 313 case 1:
293 reg_w(gspca_dev->dev, 0x0071, reg71b, 4); 314 reg_w(gspca_dev, 0x0071, reg71b, 4);
294 break; 315 break;
295 default: 316 default:
296/* case 2: */ 317/* case 2: */
297 reg_w(gspca_dev->dev, 0x0071, reg71c, 4); 318 reg_w(gspca_dev, 0x0071, reg71c, 4);
298 break; 319 break;
299 case 3: 320 case 3:
300 reg_w(gspca_dev->dev, 0x0071, reg71d, 4); 321 reg_w(gspca_dev, 0x0071, reg71d, 4);
301 break; 322 break;
302 } 323 }
303 reg_w(gspca_dev->dev, 0x007b, reg7b, 6); 324 reg_w(gspca_dev, 0x007b, reg7b, 6);
304 val = 0x00; 325 reg_w_val(gspca_dev, 0x00f8, 0x00);
305 reg_w(gspca_dev->dev, 0x00f8, &val, 1); 326 reg_w(gspca_dev, 0x0010, reg10, 8);
306 reg_w(gspca_dev->dev, 0x0010, reg10, 8); 327 reg_w_val(gspca_dev, 0x0098, 0x41);
307 val = 0x41;
308 reg_w(gspca_dev->dev, 0x0098, &val, 1);
309 for (i = 0; i < 11; i++) { 328 for (i = 0; i < 11; i++) {
310 if (i == 3 || i == 5 || i == 8) 329 if (i == 3 || i == 5 || i == 8)
311 length = 8; 330 length = 8;
312 else 331 else
313 length = 4; 332 length = 4;
314 reg_w(gspca_dev->dev, 0x00e5, ptsensor, length); 333 reg_w(gspca_dev, 0x00e5, ptsensor, length);
315 if (length == 4) 334 if (length == 4)
316 reg_r(gspca_dev->dev, 0x00e8, &val, 1); 335 reg_r(gspca_dev, 0x00e8, 1);
317 else 336 else
318 reg_r(gspca_dev->dev, 0x00e8, bufread, length); 337 reg_r(gspca_dev, 0x00e8, length);
319 ptsensor += length; 338 ptsensor += length;
320 } 339 }
321 reg_r(gspca_dev->dev, 0x00e7, bufread, 8); 340 reg_r(gspca_dev, 0x00e7, 8);
322} 341}
323 342
324static const __u8 cx_inits_176[] = { 343static const __u8 cx_inits_176[] = {
@@ -358,10 +377,9 @@ static const __u8 cx_inits_640[] = {
358 0x77, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 377 0x77, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
359}; 378};
360 379
361static int cx11646_initsize(struct gspca_dev *gspca_dev) 380static void cx11646_initsize(struct gspca_dev *gspca_dev)
362{ 381{
363 const __u8 *cxinit; 382 const __u8 *cxinit;
364 __u8 val;
365 static const __u8 reg12[] = { 0x08, 0x05, 0x07, 0x04, 0x24 }; 383 static const __u8 reg12[] = { 0x08, 0x05, 0x07, 0x04, 0x24 };
366 static const __u8 reg17[] = 384 static const __u8 reg17[] =
367 { 0x0a, 0x00, 0xf2, 0x01, 0x0f, 0x00, 0x97, 0x02 }; 385 { 0x0a, 0x00, 0xf2, 0x01, 0x0f, 0x00, 0x97, 0x02 };
@@ -381,35 +399,29 @@ static int cx11646_initsize(struct gspca_dev *gspca_dev)
381 cxinit = cx_inits_176; 399 cxinit = cx_inits_176;
382 break; 400 break;
383 } 401 }
384 val = 0x01; 402 reg_w_val(gspca_dev, 0x009a, 0x01);
385 reg_w(gspca_dev->dev, 0x009a, &val, 1); 403 reg_w_val(gspca_dev, 0x0010, 0x10);
386 val = 0x10; 404 reg_w(gspca_dev, 0x0012, reg12, 5);
387 reg_w(gspca_dev->dev, 0x0010, &val, 1); 405 reg_w(gspca_dev, 0x0017, reg17, 8);
388 reg_w(gspca_dev->dev, 0x0012, reg12, 5); 406 reg_w_val(gspca_dev, 0x00c0, 0x00);
389 reg_w(gspca_dev->dev, 0x0017, reg17, 8); 407 reg_w_val(gspca_dev, 0x00c1, 0x04);
390 val = 0x00; 408 reg_w_val(gspca_dev, 0x00c2, 0x04);
391 reg_w(gspca_dev->dev, 0x00c0, &val, 1); 409
392 val = 0x04; 410 reg_w(gspca_dev, 0x0061, cxinit, 8);
393 reg_w(gspca_dev->dev, 0x00c1, &val, 1);
394 val = 0x04;
395 reg_w(gspca_dev->dev, 0x00c2, &val, 1);
396
397 reg_w(gspca_dev->dev, 0x0061, cxinit, 8);
398 cxinit += 8; 411 cxinit += 8;
399 reg_w(gspca_dev->dev, 0x00ca, cxinit, 8); 412 reg_w(gspca_dev, 0x00ca, cxinit, 8);
400 cxinit += 8; 413 cxinit += 8;
401 reg_w(gspca_dev->dev, 0x00d2, cxinit, 8); 414 reg_w(gspca_dev, 0x00d2, cxinit, 8);
402 cxinit += 8; 415 cxinit += 8;
403 reg_w(gspca_dev->dev, 0x00da, cxinit, 6); 416 reg_w(gspca_dev, 0x00da, cxinit, 6);
404 cxinit += 8; 417 cxinit += 8;
405 reg_w(gspca_dev->dev, 0x0041, cxinit, 8); 418 reg_w(gspca_dev, 0x0041, cxinit, 8);
406 cxinit += 8; 419 cxinit += 8;
407 reg_w(gspca_dev->dev, 0x0049, cxinit, 8); 420 reg_w(gspca_dev, 0x0049, cxinit, 8);
408 cxinit += 8; 421 cxinit += 8;
409 reg_w(gspca_dev->dev, 0x0051, cxinit, 2); 422 reg_w(gspca_dev, 0x0051, cxinit, 2);
410 423
411 reg_r(gspca_dev->dev, 0x0010, &val, 1); 424 reg_r(gspca_dev, 0x0010, 1);
412 return val;
413} 425}
414 426
415static const __u8 cx_jpeg_init[][8] = { 427static const __u8 cx_jpeg_init[][8] = {
@@ -636,26 +648,21 @@ static const __u8 cxjpeg_qtable[][8] = {
636 648
637static void cx11646_jpegInit(struct gspca_dev*gspca_dev) 649static void cx11646_jpegInit(struct gspca_dev*gspca_dev)
638{ 650{
639 __u8 val;
640 int i; 651 int i;
641 int length; 652 int length;
642 653
643 val = 0x01; 654 reg_w_val(gspca_dev, 0x00c0, 0x01);
644 reg_w(gspca_dev->dev, 0x00c0, &val, 1); 655 reg_w_val(gspca_dev, 0x00c3, 0x00);
645 val = 0x00; 656 reg_w_val(gspca_dev, 0x00c0, 0x00);
646 reg_w(gspca_dev->dev, 0x00c3, &val, 1); 657 reg_r(gspca_dev, 0x0001, 1);
647 val = 0x00;
648 reg_w(gspca_dev->dev, 0x00c0, &val, 1);
649 reg_r(gspca_dev->dev, 0x0001, &val, 1);
650 length = 8; 658 length = 8;
651 for (i = 0; i < 79; i++) { 659 for (i = 0; i < 79; i++) {
652 if (i == 78) 660 if (i == 78)
653 length = 6; 661 length = 6;
654 reg_w(gspca_dev->dev, 0x0008, cx_jpeg_init[i], length); 662 reg_w(gspca_dev, 0x0008, cx_jpeg_init[i], length);
655 } 663 }
656 reg_r(gspca_dev->dev, 0x0002, &val, 1); 664 reg_r(gspca_dev, 0x0002, 1);
657 val = 0x14; 665 reg_w_val(gspca_dev, 0x0055, 0x14);
658 reg_w(gspca_dev->dev, 0x0055, &val, 1);
659} 666}
660 667
661static const __u8 reg12[] = { 0x0a, 0x05, 0x07, 0x04, 0x19 }; 668static const __u8 reg12[] = { 0x0a, 0x05, 0x07, 0x04, 0x19 };
@@ -665,31 +672,26 @@ static const __u8 regE5a[] = { 0x88, 0x0a, 0x0c, 0x01 };
665static const __u8 regE5b[] = { 0x88, 0x0b, 0x12, 0x01 }; 672static const __u8 regE5b[] = { 0x88, 0x0b, 0x12, 0x01 };
666static const __u8 regE5c[] = { 0x88, 0x05, 0x01, 0x01 }; 673static const __u8 regE5c[] = { 0x88, 0x05, 0x01, 0x01 };
667static const __u8 reg51[] = { 0x77, 0x03 }; 674static const __u8 reg51[] = { 0x77, 0x03 };
668static const __u8 reg70 = 0x03; 675#define reg70 0x03
669 676
670static void cx11646_jpeg(struct gspca_dev*gspca_dev) 677static void cx11646_jpeg(struct gspca_dev*gspca_dev)
671{ 678{
672 __u8 val;
673 int i; 679 int i;
674 int length; 680 int length;
675 __u8 Reg55; 681 __u8 Reg55;
676 __u8 bufread[8];
677 int retry; 682 int retry;
678 683
679 val = 0x01; 684 reg_w_val(gspca_dev, 0x00c0, 0x01);
680 reg_w(gspca_dev->dev, 0x00c0, &val, 1); 685 reg_w_val(gspca_dev, 0x00c3, 0x00);
681 val = 0x00; 686 reg_w_val(gspca_dev, 0x00c0, 0x00);
682 reg_w(gspca_dev->dev, 0x00c3, &val, 1); 687 reg_r(gspca_dev, 0x0001, 1);
683 val = 0x00;
684 reg_w(gspca_dev->dev, 0x00c0, &val, 1);
685 reg_r(gspca_dev->dev, 0x0001, &val, 1);
686 length = 8; 688 length = 8;
687 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { 689 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
688 case 0: 690 case 0:
689 for (i = 0; i < 27; i++) { 691 for (i = 0; i < 27; i++) {
690 if (i == 26) 692 if (i == 26)
691 length = 2; 693 length = 2;
692 reg_w(gspca_dev->dev, 0x0008, cxjpeg_640[i], length); 694 reg_w(gspca_dev, 0x0008, cxjpeg_640[i], length);
693 } 695 }
694 Reg55 = 0x28; 696 Reg55 = 0x28;
695 break; 697 break;
@@ -697,7 +699,7 @@ static void cx11646_jpeg(struct gspca_dev*gspca_dev)
697 for (i = 0; i < 27; i++) { 699 for (i = 0; i < 27; i++) {
698 if (i == 26) 700 if (i == 26)
699 length = 2; 701 length = 2;
700 reg_w(gspca_dev->dev, 0x0008, cxjpeg_352[i], length); 702 reg_w(gspca_dev, 0x0008, cxjpeg_352[i], length);
701 } 703 }
702 Reg55 = 0x16; 704 Reg55 = 0x16;
703 break; 705 break;
@@ -706,7 +708,7 @@ static void cx11646_jpeg(struct gspca_dev*gspca_dev)
706 for (i = 0; i < 27; i++) { 708 for (i = 0; i < 27; i++) {
707 if (i == 26) 709 if (i == 26)
708 length = 2; 710 length = 2;
709 reg_w(gspca_dev->dev, 0x0008, cxjpeg_320[i], length); 711 reg_w(gspca_dev, 0x0008, cxjpeg_320[i], length);
710 } 712 }
711 Reg55 = 0x14; 713 Reg55 = 0x14;
712 break; 714 break;
@@ -714,124 +716,98 @@ static void cx11646_jpeg(struct gspca_dev*gspca_dev)
714 for (i = 0; i < 27; i++) { 716 for (i = 0; i < 27; i++) {
715 if (i == 26) 717 if (i == 26)
716 length = 2; 718 length = 2;
717 reg_w(gspca_dev->dev, 0x0008, cxjpeg_176[i], length); 719 reg_w(gspca_dev, 0x0008, cxjpeg_176[i], length);
718 } 720 }
719 Reg55 = 0x0B; 721 Reg55 = 0x0B;
720 break; 722 break;
721 } 723 }
722 724
723 reg_r(gspca_dev->dev, 0x0002, &val, 1); 725 reg_r(gspca_dev, 0x0002, 1);
724 val = Reg55; 726 reg_w_val(gspca_dev, 0x0055, Reg55);
725 reg_w(gspca_dev->dev, 0x0055, &val, 1); 727 reg_r(gspca_dev, 0x0002, 1);
726 reg_r(gspca_dev->dev, 0x0002, &val, 1); 728 reg_w(gspca_dev, 0x0010, reg10, 2);
727 reg_w(gspca_dev->dev, 0x0010, reg10, 2); 729 reg_w_val(gspca_dev, 0x0054, 0x02);
728 val = 0x02; 730 reg_w_val(gspca_dev, 0x0054, 0x01);
729 reg_w(gspca_dev->dev, 0x0054, &val, 1); 731 reg_w_val(gspca_dev, 0x0000, 0x94);
730 val = 0x01; 732 reg_w_val(gspca_dev, 0x0053, 0xc0);
731 reg_w(gspca_dev->dev, 0x0054, &val, 1); 733 reg_w_val(gspca_dev, 0x00fc, 0xe1);
732 val = 0x94; 734 reg_w_val(gspca_dev, 0x0000, 0x00);
733 reg_w(gspca_dev->dev, 0x0000, &val, 1);
734 val = 0xc0;
735 reg_w(gspca_dev->dev, 0x0053, &val, 1);
736 val = 0xe1;
737 reg_w(gspca_dev->dev, 0x00fc, &val, 1);
738 val = 0x00;
739 reg_w(gspca_dev->dev, 0x0000, &val, 1);
740 /* wait for completion */ 735 /* wait for completion */
741 retry = 50; 736 retry = 50;
742 while (retry--) { 737 while (retry--) {
743 reg_r(gspca_dev->dev, 0x0002, &val, 1); 738 reg_r(gspca_dev, 0x0002, 1);
744 /* 0x07 until 0x00 */ 739 /* 0x07 until 0x00 */
745 if (val == 0x00) 740 if (gspca_dev->usb_buf[0] == 0x00)
746 break; 741 break;
747 val = 0x00; 742 reg_w_val(gspca_dev, 0x0053, 0x00);
748 reg_w(gspca_dev->dev, 0x0053, &val, 1);
749 } 743 }
750 if (retry == 0) 744 if (retry == 0)
751 PDEBUG(D_ERR, "Damned Errors sending jpeg Table"); 745 PDEBUG(D_ERR, "Damned Errors sending jpeg Table");
752 /* send the qtable now */ 746 /* send the qtable now */
753 reg_r(gspca_dev->dev, 0x0001, &val, 1); /* -> 0x18 */ 747 reg_r(gspca_dev, 0x0001, 1); /* -> 0x18 */
754 length = 8; 748 length = 8;
755 for (i = 0; i < 18; i++) { 749 for (i = 0; i < 18; i++) {
756 if (i == 17) 750 if (i == 17)
757 length = 2; 751 length = 2;
758 reg_w(gspca_dev->dev, 0x0008, cxjpeg_qtable[i], length); 752 reg_w(gspca_dev, 0x0008, cxjpeg_qtable[i], length);
759 753
760 } 754 }
761 reg_r(gspca_dev->dev, 0x0002, &val, 1); /* 0x00 */ 755 reg_r(gspca_dev, 0x0002, 1); /* 0x00 */
762 reg_r(gspca_dev->dev, 0x0053, &val, 1); /* 0x00 */ 756 reg_r(gspca_dev, 0x0053, 1); /* 0x00 */
763 val = 0x02; 757 reg_w_val(gspca_dev, 0x0054, 0x02);
764 reg_w(gspca_dev->dev, 0x0054, &val, 1); 758 reg_w_val(gspca_dev, 0x0054, 0x01);
765 val = 0x01; 759 reg_w_val(gspca_dev, 0x0000, 0x94);
766 reg_w(gspca_dev->dev, 0x0054, &val, 1); 760 reg_w_val(gspca_dev, 0x0053, 0xc0);
767 val = 0x94; 761
768 reg_w(gspca_dev->dev, 0x0000, &val, 1); 762 reg_r(gspca_dev, 0x0038, 1); /* 0x40 */
769 val = 0xc0; 763 reg_r(gspca_dev, 0x0038, 1); /* 0x40 */
770 reg_w(gspca_dev->dev, 0x0053, &val, 1); 764 reg_r(gspca_dev, 0x001f, 1); /* 0x38 */
771 765 reg_w(gspca_dev, 0x0012, reg12, 5);
772 reg_r(gspca_dev->dev, 0x0038, &val, 1); /* 0x40 */ 766 reg_w(gspca_dev, 0x00e5, regE5_8, 8);
773 reg_r(gspca_dev->dev, 0x0038, &val, 1); /* 0x40 */ 767 reg_r(gspca_dev, 0x00e8, 8);
774 reg_r(gspca_dev->dev, 0x001f, &val, 1); /* 0x38 */ 768 reg_w(gspca_dev, 0x00e5, regE5a, 4);
775 reg_w(gspca_dev->dev, 0x0012, reg12, 5); 769 reg_r(gspca_dev, 0x00e8, 1); /* 0x00 */
776 reg_w(gspca_dev->dev, 0x00e5, regE5_8, 8); 770 reg_w_val(gspca_dev, 0x009a, 0x01);
777 reg_r(gspca_dev->dev, 0x00e8, bufread, 8); 771 reg_w(gspca_dev, 0x00e5, regE5b, 4);
778 reg_w(gspca_dev->dev, 0x00e5, regE5a, 4); 772 reg_r(gspca_dev, 0x00e8, 1); /* 0x00 */
779 reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* 0x00 */ 773 reg_w(gspca_dev, 0x00e5, regE5c, 4);
780 val = 0x01; 774 reg_r(gspca_dev, 0x00e8, 1); /* 0x00 */
781 reg_w(gspca_dev->dev, 0x009a, &val, 1); 775
782 reg_w(gspca_dev->dev, 0x00e5, regE5b, 4); 776 reg_w(gspca_dev, 0x0051, reg51, 2);
783 reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* 0x00 */ 777 reg_w(gspca_dev, 0x0010, reg10, 2);
784 reg_w(gspca_dev->dev, 0x00e5, regE5c, 4); 778 reg_w_val(gspca_dev, 0x0070, reg70);
785 reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* 0x00 */
786
787 reg_w(gspca_dev->dev, 0x0051, reg51, 2);
788 reg_w(gspca_dev->dev, 0x0010, reg10, 2);
789 reg_w(gspca_dev->dev, 0x0070, &reg70, 1);
790} 779}
791 780
792static void cx11646_init1(struct gspca_dev *gspca_dev) 781static void cx11646_init1(struct gspca_dev *gspca_dev)
793{ 782{
794 __u8 val;
795 int i = 0; 783 int i = 0;
796 784
797 val = 0; 785 reg_w_val(gspca_dev, 0x0010, 0x00);
798 reg_w(gspca_dev->dev, 0x0010, &val, 1); 786 reg_w_val(gspca_dev, 0x0053, 0x00);
799 reg_w(gspca_dev->dev, 0x0053, &val, 1); 787 reg_w_val(gspca_dev, 0x0052, 0x00);
800 reg_w(gspca_dev->dev, 0x0052, &val, 1); 788 reg_w_val(gspca_dev, 0x009b, 0x2f);
801 val = 0x2f; 789 reg_w_val(gspca_dev, 0x009c, 0x10);
802 reg_w(gspca_dev->dev, 0x009b, &val, 1); 790 reg_r(gspca_dev, 0x0098, 1);
803 val = 0x10; 791 reg_w_val(gspca_dev, 0x0098, 0x40);
804 reg_w(gspca_dev->dev, 0x009c, &val, 1); 792 reg_r(gspca_dev, 0x0099, 1);
805 reg_r(gspca_dev->dev, 0x0098, &val, 1); 793 reg_w_val(gspca_dev, 0x0099, 0x07);
806 val = 0x40; 794 reg_w_val(gspca_dev, 0x0039, 0x40);
807 reg_w(gspca_dev->dev, 0x0098, &val, 1); 795 reg_w_val(gspca_dev, 0x003c, 0xff);
808 reg_r(gspca_dev->dev, 0x0099, &val, 1); 796 reg_w_val(gspca_dev, 0x003f, 0x1f);
809 val = 0x07; 797 reg_w_val(gspca_dev, 0x003d, 0x40);
810 reg_w(gspca_dev->dev, 0x0099, &val, 1); 798/* reg_w_val(gspca_dev, 0x003d, 0x60); */
811 val = 0x40; 799 reg_r(gspca_dev, 0x0099, 1); /* ->0x07 */
812 reg_w(gspca_dev->dev, 0x0039, &val, 1);
813 val = 0xff;
814 reg_w(gspca_dev->dev, 0x003c, &val, 1);
815 val = 0x1f;
816 reg_w(gspca_dev->dev, 0x003f, &val, 1);
817 val = 0x40;
818 reg_w(gspca_dev->dev, 0x003d, &val, 1);
819/* val= 0x60; */
820/* reg_w(gspca_dev->dev, 0x00, 0x00, 0x003d, &val, 1); */
821 reg_r(gspca_dev->dev, 0x0099, &val, 1); /* ->0x07 */
822 800
823 while (cx_sensor_init[i][0]) { 801 while (cx_sensor_init[i][0]) {
824 reg_w(gspca_dev->dev, 0x00e5, cx_sensor_init[i], 1); 802 reg_w_val(gspca_dev, 0x00e5, cx_sensor_init[i][0]);
825 reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* -> 0x00 */ 803 reg_r(gspca_dev, 0x00e8, 1); /* -> 0x00 */
826 if (i == 1) { 804 if (i == 1) {
827 val = 1; 805 reg_w_val(gspca_dev, 0x00ed, 0x01);
828 reg_w(gspca_dev->dev, 0x00ed, &val, 1); 806 reg_r(gspca_dev, 0x00ed, 1); /* -> 0x01 */
829 reg_r(gspca_dev->dev, 0x00ed, &val, 1); /* -> 0x01 */
830 } 807 }
831 i++; 808 i++;
832 } 809 }
833 val = 0x00; 810 reg_w_val(gspca_dev, 0x00c3, 0x00);
834 reg_w(gspca_dev->dev, 0x00c3, &val, 1);
835} 811}
836 812
837/* this function is called at probe time */ 813/* this function is called at probe time */
@@ -880,29 +856,23 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
880static void sd_stop0(struct gspca_dev *gspca_dev) 856static void sd_stop0(struct gspca_dev *gspca_dev)
881{ 857{
882 int retry = 50; 858 int retry = 50;
883 __u8 val;
884 859
885 val = 0; 860 reg_w_val(gspca_dev, 0x0000, 0x00);
886 reg_w(gspca_dev->dev, 0x0000, &val, 1); 861 reg_r(gspca_dev, 0x0002, 1);
887 reg_r(gspca_dev->dev, 0x0002, &val, 1); 862 reg_w_val(gspca_dev, 0x0053, 0x00);
888 val = 0;
889 reg_w(gspca_dev->dev, 0x0053, &val, 1);
890 863
891 while (retry--) { 864 while (retry--) {
892/* reg_r(gspca_dev->dev, 0x0002, &val, 1);*/ 865/* reg_r(gspca_dev, 0x0002, 1);*/
893 reg_r(gspca_dev->dev, 0x0053, &val, 1); 866 reg_r(gspca_dev, 0x0053, 1);
894 if (val == 0) 867 if (gspca_dev->usb_buf[0] == 0)
895 break; 868 break;
896 } 869 }
897 val = 0; 870 reg_w_val(gspca_dev, 0x0000, 0x00);
898 reg_w(gspca_dev->dev, 0x0000, &val, 1); 871 reg_r(gspca_dev, 0x0002, 1);
899 reg_r(gspca_dev->dev, 0x0002, &val, 1); 872
900 873 reg_w_val(gspca_dev, 0x0010, 0x00);
901 val = 0; 874 reg_r(gspca_dev, 0x0033, 1);
902 reg_w(gspca_dev->dev, 0x0010, &val, 1); 875 reg_w_val(gspca_dev, 0x00fc, 0xe0);
903 reg_r(gspca_dev->dev, 0x0033, &val, 1);
904 val = 0xe0;
905 reg_w(gspca_dev->dev, 0x00fc, &val, 1);
906} 876}
907 877
908static void sd_close(struct gspca_dev *gspca_dev) 878static void sd_close(struct gspca_dev *gspca_dev)
@@ -937,22 +907,20 @@ static void setbrightness(struct gspca_dev*gspca_dev)
937 __u8 reg51c[2]; 907 __u8 reg51c[2];
938 __u8 bright; 908 __u8 bright;
939 __u8 colors; 909 __u8 colors;
940 __u8 val;
941 __u8 bufread[8];
942 910
943 bright = sd->brightness; 911 bright = sd->brightness;
944 regE5cbx[2] = bright; 912 regE5cbx[2] = bright;
945 reg_w(gspca_dev->dev, 0x00e5, regE5cbx, 8); 913 reg_w(gspca_dev, 0x00e5, regE5cbx, 8);
946 reg_r(gspca_dev->dev, 0x00e8, bufread, 8); 914 reg_r(gspca_dev, 0x00e8, 8);
947 reg_w(gspca_dev->dev, 0x00e5, regE5c, 4); 915 reg_w(gspca_dev, 0x00e5, regE5c, 4);
948 reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* 0x00 */ 916 reg_r(gspca_dev, 0x00e8, 1); /* 0x00 */
949 917
950 colors = sd->colors; 918 colors = sd->colors;
951 reg51c[0] = 0x77; 919 reg51c[0] = 0x77;
952 reg51c[1] = colors; 920 reg51c[1] = colors;
953 reg_w(gspca_dev->dev, 0x0051, reg51c, 2); 921 reg_w(gspca_dev, 0x0051, reg51c, 2);
954 reg_w(gspca_dev->dev, 0x0010, reg10, 2); 922 reg_w(gspca_dev, 0x0010, reg10, 2);
955 reg_w(gspca_dev->dev, 0x0070, &reg70, 1); 923 reg_w_val(gspca_dev, 0x0070, reg70);
956} 924}
957 925
958static void setcontrast(struct gspca_dev*gspca_dev) 926static void setcontrast(struct gspca_dev*gspca_dev)
@@ -961,16 +929,15 @@ static void setcontrast(struct gspca_dev*gspca_dev)
961 __u8 regE5acx[] = { 0x88, 0x0a, 0x0c, 0x01 }; /* seem MSB */ 929 __u8 regE5acx[] = { 0x88, 0x0a, 0x0c, 0x01 }; /* seem MSB */
962/* __u8 regE5bcx[] = { 0x88, 0x0b, 0x12, 0x01}; * LSB */ 930/* __u8 regE5bcx[] = { 0x88, 0x0b, 0x12, 0x01}; * LSB */
963 __u8 reg51c[2]; 931 __u8 reg51c[2];
964 __u8 val;
965 932
966 regE5acx[2] = sd->contrast; 933 regE5acx[2] = sd->contrast;
967 reg_w(gspca_dev->dev, 0x00e5, regE5acx, 4); 934 reg_w(gspca_dev, 0x00e5, regE5acx, 4);
968 reg_r(gspca_dev->dev, 0x00e8, &val, 1); /* 0x00 */ 935 reg_r(gspca_dev, 0x00e8, 1); /* 0x00 */
969 reg51c[0] = 0x77; 936 reg51c[0] = 0x77;
970 reg51c[1] = sd->colors; 937 reg51c[1] = sd->colors;
971 reg_w(gspca_dev->dev, 0x0051, reg51c, 2); 938 reg_w(gspca_dev, 0x0051, reg51c, 2);
972 reg_w(gspca_dev->dev, 0x0010, reg10, 2); 939 reg_w(gspca_dev, 0x0010, reg10, 2);
973 reg_w(gspca_dev->dev, 0x0070, &reg70, 1); 940 reg_w_val(gspca_dev, 0x0070, reg70);
974} 941}
975 942
976static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 943static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
diff --git a/drivers/media/video/gspca/etoms.c b/drivers/media/video/gspca/etoms.c
index 1da6a182561f..5bb8dc1adbb7 100644
--- a/drivers/media/video/gspca/etoms.c
+++ b/drivers/media/video/gspca/etoms.c
@@ -22,8 +22,8 @@
22 22
23#include "gspca.h" 23#include "gspca.h"
24 24
25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
26static const char version[] = "2.1.5"; 26static const char version[] = "2.1.7";
27 27
28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("Etoms USB Camera Driver"); 29MODULE_DESCRIPTION("Etoms USB Camera Driver");
@@ -229,201 +229,215 @@ static const __u8 I2c3[] = { 0x12, 0x05 };
229 229
230static const __u8 I2c4[] = { 0x41, 0x08 }; 230static const __u8 I2c4[] = { 0x41, 0x08 };
231 231
232static void reg_r(struct usb_device *dev, 232/* read 'len' bytes to gspca_dev->usb_buf */
233 __u16 index, __u8 *buffer, int len) 233static void reg_r(struct gspca_dev *gspca_dev,
234 __u16 index,
235 __u16 len)
234{ 236{
237 struct usb_device *dev = gspca_dev->dev;
238
239#ifdef CONFIG_VIDEO_ADV_DEBUG
240 if (len > sizeof gspca_dev->usb_buf) {
241 err("reg_r: buffer overflow");
242 return;
243 }
244#endif
235 usb_control_msg(dev, 245 usb_control_msg(dev,
236 usb_rcvctrlpipe(dev, 0), 246 usb_rcvctrlpipe(dev, 0),
237 0, 247 0,
238 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 248 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
239 0, index, buffer, len, 500); 249 0,
250 index, gspca_dev->usb_buf, len, 500);
251 PDEBUG(D_USBI, "reg read [%02x] -> %02x ..",
252 index, gspca_dev->usb_buf[0]);
240} 253}
241 254
242static void reg_w_val(struct usb_device *dev, 255static void reg_w_val(struct gspca_dev *gspca_dev,
243 __u16 index, __u8 val) 256 __u16 index,
257 __u8 val)
244{ 258{
245 __u8 data; 259 struct usb_device *dev = gspca_dev->dev;
246 260
247 data = val; 261 gspca_dev->usb_buf[0] = val;
248 usb_control_msg(dev, 262 usb_control_msg(dev,
249 usb_sndctrlpipe(dev, 0), 263 usb_sndctrlpipe(dev, 0),
250 0, 264 0,
251 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 265 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
252 0, index, &data, 1, 500); 266 0,
267 index, gspca_dev->usb_buf, 1, 500);
253} 268}
254 269
255static void reg_w(struct usb_device *dev, 270static void reg_w(struct gspca_dev *gspca_dev,
256 __u16 index, const __u8 *buffer, __u16 len) 271 __u16 index,
272 const __u8 *buffer,
273 __u16 len)
257{ 274{
258 __u8 tmpbuf[8]; 275 struct usb_device *dev = gspca_dev->dev;
259 276
260 memcpy(tmpbuf, buffer, len); 277#ifdef CONFIG_VIDEO_ADV_DEBUG
278 if (len > sizeof gspca_dev->usb_buf) {
279 err("reg_w: buffer overflow");
280 return;
281 }
282 PDEBUG(D_USBO, "reg write [%02x] = %02x..", index, *buffer);
283#endif
284 memcpy(gspca_dev->usb_buf, buffer, len);
261 usb_control_msg(dev, 285 usb_control_msg(dev,
262 usb_sndctrlpipe(dev, 0), 286 usb_sndctrlpipe(dev, 0),
263 0, 287 0,
264 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 288 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
265 0, index, tmpbuf, len, 500); 289 0, index, gspca_dev->usb_buf, len, 500);
266} 290}
267 291
268static int Et_i2cwrite(struct usb_device *dev, __u8 reg, 292static int i2c_w(struct gspca_dev *gspca_dev,
269 const __u8 *buffer, 293 __u8 reg,
270 __u16 len, __u8 mode) 294 const __u8 *buffer,
295 __u16 len, __u8 mode)
271{ 296{
272 /* buffer should be [D0..D7] */ 297 /* buffer should be [D0..D7] */
273 __u8 ptchcount; 298 __u8 ptchcount;
274 299
275 /* set the base address */ 300 /* set the base address */
276 reg_w_val(dev, ET_I2C_BASE, 0x40); /* sensor base for the pas106 */ 301 reg_w_val(gspca_dev, ET_I2C_BASE, 0x40);
302 /* sensor base for the pas106 */
277 /* set count and prefetch */ 303 /* set count and prefetch */
278 ptchcount = ((len & 0x07) << 4) | (mode & 0x03); 304 ptchcount = ((len & 0x07) << 4) | (mode & 0x03);
279 reg_w_val(dev, ET_I2C_COUNT, ptchcount); 305 reg_w_val(gspca_dev, ET_I2C_COUNT, ptchcount);
280 /* set the register base */ 306 /* set the register base */
281 reg_w_val(dev, ET_I2C_REG, reg); 307 reg_w_val(gspca_dev, ET_I2C_REG, reg);
282 while (--len >= 0) 308 while (--len >= 0)
283 reg_w_val(dev, ET_I2C_DATA0 + len, buffer[len]); 309 reg_w_val(gspca_dev, ET_I2C_DATA0 + len, buffer[len]);
284 return 0; 310 return 0;
285} 311}
286 312
287static int Et_i2cread(struct usb_device *dev, __u8 reg, 313static int i2c_r(struct gspca_dev *gspca_dev,
288 __u8 *buffer, 314 __u8 reg)
289 __u16 length, __u8 mode)
290{ 315{
291 /* buffer should be [D0..D7] */
292 int i, j;
293 __u8 ptchcount;
294
295 /* set the base address */ 316 /* set the base address */
296 reg_w_val(dev, ET_I2C_BASE, 0x40); /* sensor base for the pas106 */ 317 reg_w_val(gspca_dev, ET_I2C_BASE, 0x40);
297 /* set count and prefetch */ 318 /* sensor base for the pas106 */
298 ptchcount = ((length & 0x07) << 4) | (mode & 0x03); 319 /* set count and prefetch (cnd: 4 bits - mode: 4 bits) */
299 reg_w_val(dev, ET_I2C_COUNT, ptchcount); 320 reg_w_val(gspca_dev, ET_I2C_COUNT, 0x11);
300 /* set the register base */ 321 reg_w_val(gspca_dev, ET_I2C_REG, reg); /* set the register base */
301 reg_w_val(dev, ET_I2C_REG, reg); 322 reg_w_val(gspca_dev, ET_I2C_PREFETCH, 0x02); /* prefetch */
302 reg_w_val(dev, ET_I2C_PREFETCH, 0x02); /* prefetch */ 323 reg_w_val(gspca_dev, ET_I2C_PREFETCH, 0x00);
303 reg_w_val(dev, ET_I2C_PREFETCH, 0); 324 reg_r(gspca_dev, ET_I2C_DATA0, 1); /* read one byte */
304 j = length - 1;
305 for (i = 0; i < length; i++) {
306 reg_r(dev, (ET_I2C_DATA0 + j), &buffer[j], 1);
307 j--;
308 }
309 return 0; 325 return 0;
310} 326}
311 327
312static int Et_WaitStatus(struct usb_device *dev) 328static int Et_WaitStatus(struct gspca_dev *gspca_dev)
313{ 329{
314 __u8 bytereceived;
315 int retry = 10; 330 int retry = 10;
316 331
317 while (retry--) { 332 while (retry--) {
318 reg_r(dev, ET_ClCK, &bytereceived, 1); 333 reg_r(gspca_dev, ET_ClCK, 1);
319 if (bytereceived != 0) 334 if (gspca_dev->usb_buf[0] != 0)
320 return 1; 335 return 1;
321 } 336 }
322 return 0; 337 return 0;
323} 338}
324 339
325static int et_video(struct usb_device *dev, int on) 340static int et_video(struct gspca_dev *gspca_dev,
341 int on)
326{ 342{
327 int err; 343 int ret;
328 344
329 reg_w_val(dev, ET_GPIO_OUT, on 345 reg_w_val(gspca_dev, ET_GPIO_OUT,
330 ? 0x10 /* startvideo - set Bit5 */ 346 on ? 0x10 /* startvideo - set Bit5 */
331 : 0); /* stopvideo */ 347 : 0); /* stopvideo */
332 err = Et_WaitStatus(dev); 348 ret = Et_WaitStatus(gspca_dev);
333 if (!err) 349 if (ret != 0)
334 PDEBUG(D_ERR, "timeout video on/off"); 350 PDEBUG(D_ERR, "timeout video on/off");
335 return err; 351 return ret;
336} 352}
337 353
338static void Et_init2(struct gspca_dev *gspca_dev) 354static void Et_init2(struct gspca_dev *gspca_dev)
339{ 355{
340 struct usb_device *dev = gspca_dev->dev;
341 __u8 value; 356 __u8 value;
342 __u8 received;
343 static const __u8 FormLine[] = { 0x84, 0x03, 0x14, 0xf4, 0x01, 0x05 }; 357 static const __u8 FormLine[] = { 0x84, 0x03, 0x14, 0xf4, 0x01, 0x05 };
344 358
345 PDEBUG(D_STREAM, "Open Init2 ET"); 359 PDEBUG(D_STREAM, "Open Init2 ET");
346 reg_w_val(dev, ET_GPIO_DIR_CTRL, 0x2f); 360 reg_w_val(gspca_dev, ET_GPIO_DIR_CTRL, 0x2f);
347 reg_w_val(dev, ET_GPIO_OUT, 0x10); 361 reg_w_val(gspca_dev, ET_GPIO_OUT, 0x10);
348 reg_r(dev, ET_GPIO_IN, &received, 1); 362 reg_r(gspca_dev, ET_GPIO_IN, 1);
349 reg_w_val(dev, ET_ClCK, 0x14); /* 0x14 // 0x16 enabled pattern */ 363 reg_w_val(gspca_dev, ET_ClCK, 0x14); /* 0x14 // 0x16 enabled pattern */
350 reg_w_val(dev, ET_CTRL, 0x1b); 364 reg_w_val(gspca_dev, ET_CTRL, 0x1b);
351 365
352 /* compression et subsampling */ 366 /* compression et subsampling */
353 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) 367 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
354 value = ET_COMP_VAL1; /* 320 */ 368 value = ET_COMP_VAL1; /* 320 */
355 else 369 else
356 value = ET_COMP_VAL0; /* 640 */ 370 value = ET_COMP_VAL0; /* 640 */
357 reg_w_val(dev, ET_COMP, value); 371 reg_w_val(gspca_dev, ET_COMP, value);
358 reg_w_val(dev, ET_MAXQt, 0x1f); 372 reg_w_val(gspca_dev, ET_MAXQt, 0x1f);
359 reg_w_val(dev, ET_MINQt, 0x04); 373 reg_w_val(gspca_dev, ET_MINQt, 0x04);
360 /* undocumented registers */ 374 /* undocumented registers */
361 reg_w_val(dev, ET_REG1d, 0xff); 375 reg_w_val(gspca_dev, ET_REG1d, 0xff);
362 reg_w_val(dev, ET_REG1e, 0xff); 376 reg_w_val(gspca_dev, ET_REG1e, 0xff);
363 reg_w_val(dev, ET_REG1f, 0xff); 377 reg_w_val(gspca_dev, ET_REG1f, 0xff);
364 reg_w_val(dev, ET_REG20, 0x35); 378 reg_w_val(gspca_dev, ET_REG20, 0x35);
365 reg_w_val(dev, ET_REG21, 0x01); 379 reg_w_val(gspca_dev, ET_REG21, 0x01);
366 reg_w_val(dev, ET_REG22, 0x00); 380 reg_w_val(gspca_dev, ET_REG22, 0x00);
367 reg_w_val(dev, ET_REG23, 0xff); 381 reg_w_val(gspca_dev, ET_REG23, 0xff);
368 reg_w_val(dev, ET_REG24, 0xff); 382 reg_w_val(gspca_dev, ET_REG24, 0xff);
369 reg_w_val(dev, ET_REG25, 0x0f); 383 reg_w_val(gspca_dev, ET_REG25, 0x0f);
370 /* colors setting */ 384 /* colors setting */
371 reg_w_val(dev, 0x30, 0x11); /* 0x30 */ 385 reg_w_val(gspca_dev, 0x30, 0x11); /* 0x30 */
372 reg_w_val(dev, 0x31, 0x40); 386 reg_w_val(gspca_dev, 0x31, 0x40);
373 reg_w_val(dev, 0x32, 0x00); 387 reg_w_val(gspca_dev, 0x32, 0x00);
374 reg_w_val(dev, ET_O_RED, 0x00); /* 0x34 */ 388 reg_w_val(gspca_dev, ET_O_RED, 0x00); /* 0x34 */
375 reg_w_val(dev, ET_O_GREEN1, 0x00); 389 reg_w_val(gspca_dev, ET_O_GREEN1, 0x00);
376 reg_w_val(dev, ET_O_BLUE, 0x00); 390 reg_w_val(gspca_dev, ET_O_BLUE, 0x00);
377 reg_w_val(dev, ET_O_GREEN2, 0x00); 391 reg_w_val(gspca_dev, ET_O_GREEN2, 0x00);
378 /*************/ 392 /*************/
379 reg_w_val(dev, ET_G_RED, 0x80); /* 0x4d */ 393 reg_w_val(gspca_dev, ET_G_RED, 0x80); /* 0x4d */
380 reg_w_val(dev, ET_G_GREEN1, 0x80); 394 reg_w_val(gspca_dev, ET_G_GREEN1, 0x80);
381 reg_w_val(dev, ET_G_BLUE, 0x80); 395 reg_w_val(gspca_dev, ET_G_BLUE, 0x80);
382 reg_w_val(dev, ET_G_GREEN2, 0x80); 396 reg_w_val(gspca_dev, ET_G_GREEN2, 0x80);
383 reg_w_val(dev, ET_G_GR_H, 0x00); 397 reg_w_val(gspca_dev, ET_G_GR_H, 0x00);
384 reg_w_val(dev, ET_G_GB_H, 0x00); /* 0x52 */ 398 reg_w_val(gspca_dev, ET_G_GB_H, 0x00); /* 0x52 */
385 /* Window control registers */ 399 /* Window control registers */
386 reg_w_val(dev, 0x61, 0x80); /* use cmc_out */ 400 reg_w_val(gspca_dev, 0x61, 0x80); /* use cmc_out */
387 reg_w_val(dev, 0x62, 0x02); 401 reg_w_val(gspca_dev, 0x62, 0x02);
388 reg_w_val(dev, 0x63, 0x03); 402 reg_w_val(gspca_dev, 0x63, 0x03);
389 reg_w_val(dev, 0x64, 0x14); 403 reg_w_val(gspca_dev, 0x64, 0x14);
390 reg_w_val(dev, 0x65, 0x0e); 404 reg_w_val(gspca_dev, 0x65, 0x0e);
391 reg_w_val(dev, 0x66, 0x02); 405 reg_w_val(gspca_dev, 0x66, 0x02);
392 reg_w_val(dev, 0x67, 0x02); 406 reg_w_val(gspca_dev, 0x67, 0x02);
393 407
394 /**************************************/ 408 /**************************************/
395 reg_w_val(dev, ET_SYNCHRO, 0x8f); /* 0x68 */ 409 reg_w_val(gspca_dev, ET_SYNCHRO, 0x8f); /* 0x68 */
396 reg_w_val(dev, ET_STARTX, 0x69); /* 0x6a //0x69 */ 410 reg_w_val(gspca_dev, ET_STARTX, 0x69); /* 0x6a //0x69 */
397 reg_w_val(dev, ET_STARTY, 0x0d); /* 0x0d //0x0c */ 411 reg_w_val(gspca_dev, ET_STARTY, 0x0d); /* 0x0d //0x0c */
398 reg_w_val(dev, ET_WIDTH_LOW, 0x80); 412 reg_w_val(gspca_dev, ET_WIDTH_LOW, 0x80);
399 reg_w_val(dev, ET_HEIGTH_LOW, 0xe0); 413 reg_w_val(gspca_dev, ET_HEIGTH_LOW, 0xe0);
400 reg_w_val(dev, ET_W_H_HEIGTH, 0x60); /* 6d */ 414 reg_w_val(gspca_dev, ET_W_H_HEIGTH, 0x60); /* 6d */
401 reg_w_val(dev, ET_REG6e, 0x86); 415 reg_w_val(gspca_dev, ET_REG6e, 0x86);
402 reg_w_val(dev, ET_REG6f, 0x01); 416 reg_w_val(gspca_dev, ET_REG6f, 0x01);
403 reg_w_val(dev, ET_REG70, 0x26); 417 reg_w_val(gspca_dev, ET_REG70, 0x26);
404 reg_w_val(dev, ET_REG71, 0x7a); 418 reg_w_val(gspca_dev, ET_REG71, 0x7a);
405 reg_w_val(dev, ET_REG72, 0x01); 419 reg_w_val(gspca_dev, ET_REG72, 0x01);
406 /* Clock Pattern registers ***************** */ 420 /* Clock Pattern registers ***************** */
407 reg_w_val(dev, ET_REG73, 0x00); 421 reg_w_val(gspca_dev, ET_REG73, 0x00);
408 reg_w_val(dev, ET_REG74, 0x18); /* 0x28 */ 422 reg_w_val(gspca_dev, ET_REG74, 0x18); /* 0x28 */
409 reg_w_val(dev, ET_REG75, 0x0f); /* 0x01 */ 423 reg_w_val(gspca_dev, ET_REG75, 0x0f); /* 0x01 */
410 /**********************************************/ 424 /**********************************************/
411 reg_w_val(dev, 0x8a, 0x20); 425 reg_w_val(gspca_dev, 0x8a, 0x20);
412 reg_w_val(dev, 0x8d, 0x0f); 426 reg_w_val(gspca_dev, 0x8d, 0x0f);
413 reg_w_val(dev, 0x8e, 0x08); 427 reg_w_val(gspca_dev, 0x8e, 0x08);
414 /**************************************/ 428 /**************************************/
415 reg_w_val(dev, 0x03, 0x08); 429 reg_w_val(gspca_dev, 0x03, 0x08);
416 reg_w_val(dev, ET_PXL_CLK, 0x03); 430 reg_w_val(gspca_dev, ET_PXL_CLK, 0x03);
417 reg_w_val(dev, 0x81, 0xff); 431 reg_w_val(gspca_dev, 0x81, 0xff);
418 reg_w_val(dev, 0x80, 0x00); 432 reg_w_val(gspca_dev, 0x80, 0x00);
419 reg_w_val(dev, 0x81, 0xff); 433 reg_w_val(gspca_dev, 0x81, 0xff);
420 reg_w_val(dev, 0x80, 0x20); 434 reg_w_val(gspca_dev, 0x80, 0x20);
421 reg_w_val(dev, 0x03, 0x01); 435 reg_w_val(gspca_dev, 0x03, 0x01);
422 reg_w_val(dev, 0x03, 0x00); 436 reg_w_val(gspca_dev, 0x03, 0x00);
423 reg_w_val(dev, 0x03, 0x08); 437 reg_w_val(gspca_dev, 0x03, 0x08);
424 /********************************************/ 438 /********************************************/
425 439
426/* reg_r(dev, ET_I2C_BASE, &received, 1); 440/* reg_r(gspca_dev, ET_I2C_BASE, 1);
427 always 0x40 as the pas106 ??? */ 441 always 0x40 as the pas106 ??? */
428 /* set the sensor */ 442 /* set the sensor */
429 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) 443 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
@@ -435,25 +449,24 @@ static void Et_init2(struct gspca_dev *gspca_dev)
435 * 0x0b -> 24/(11+1) = 2 Mhz 449 * 0x0b -> 24/(11+1) = 2 Mhz
436 * 0x17 -> 24/(23+1) = 1 Mhz 450 * 0x17 -> 24/(23+1) = 1 Mhz
437 */ 451 */
438 reg_w_val(dev, ET_PXL_CLK, value); 452 reg_w_val(gspca_dev, ET_PXL_CLK, value);
439 /* now set by fifo the FormatLine setting */ 453 /* now set by fifo the FormatLine setting */
440 reg_w(dev, 0x62, FormLine, 6); 454 reg_w(gspca_dev, 0x62, FormLine, 6);
441 455
442 /* set exposure times [ 0..0x78] 0->longvalue 0x78->shortvalue */ 456 /* set exposure times [ 0..0x78] 0->longvalue 0x78->shortvalue */
443 reg_w_val(dev, 0x81, 0x47); /* 0x47; */ 457 reg_w_val(gspca_dev, 0x81, 0x47); /* 0x47; */
444 reg_w_val(dev, 0x80, 0x40); /* 0x40; */ 458 reg_w_val(gspca_dev, 0x80, 0x40); /* 0x40; */
445 /* Pedro change */ 459 /* Pedro change */
446 /* Brightness change Brith+ decrease value */ 460 /* Brightness change Brith+ decrease value */
447 /* Brigth- increase value */ 461 /* Brigth- increase value */
448 /* original value = 0x70; */ 462 /* original value = 0x70; */
449 reg_w_val(dev, 0x81, 0x30); /* 0x20; - set brightness */ 463 reg_w_val(gspca_dev, 0x81, 0x30); /* 0x20; - set brightness */
450 reg_w_val(dev, 0x80, 0x20); /* 0x20; */ 464 reg_w_val(gspca_dev, 0x80, 0x20); /* 0x20; */
451} 465}
452 466
453static void setcolors(struct gspca_dev *gspca_dev) 467static void setcolors(struct gspca_dev *gspca_dev)
454{ 468{
455 struct sd *sd = (struct sd *) gspca_dev; 469 struct sd *sd = (struct sd *) gspca_dev;
456 struct usb_device *dev = gspca_dev->dev;
457 __u8 I2cc[] = { 0x05, 0x02, 0x02, 0x05, 0x0d }; 470 __u8 I2cc[] = { 0x05, 0x02, 0x02, 0x05, 0x0d };
458 __u8 i2cflags = 0x01; 471 __u8 i2cflags = 0x01;
459 /* __u8 green = 0; */ 472 /* __u8 green = 0; */
@@ -464,8 +477,8 @@ static void setcolors(struct gspca_dev *gspca_dev)
464 /* green = 15 - ((((7*I2cc[0]) >> 2 ) + I2cc[3]) >> 1); */ 477 /* green = 15 - ((((7*I2cc[0]) >> 2 ) + I2cc[3]) >> 1); */
465 /* I2cc[1] = I2cc[2] = green; */ 478 /* I2cc[1] = I2cc[2] = green; */
466 if (sd->sensor == SENSOR_PAS106) { 479 if (sd->sensor == SENSOR_PAS106) {
467 Et_i2cwrite(dev, PAS106_REG13, &i2cflags, 1, 3); 480 i2c_w(gspca_dev, PAS106_REG13, &i2cflags, 1, 3);
468 Et_i2cwrite(dev, PAS106_REG9, I2cc, sizeof I2cc, 1); 481 i2c_w(gspca_dev, PAS106_REG9, I2cc, sizeof I2cc, 1);
469 } 482 }
470/* PDEBUG(D_CONF , "Etoms red %d blue %d green %d", 483/* PDEBUG(D_CONF , "Etoms red %d blue %d green %d",
471 I2cc[3], I2cc[0], green); */ 484 I2cc[3], I2cc[0], green); */
@@ -474,21 +487,17 @@ static void setcolors(struct gspca_dev *gspca_dev)
474static void getcolors(struct gspca_dev *gspca_dev) 487static void getcolors(struct gspca_dev *gspca_dev)
475{ 488{
476 struct sd *sd = (struct sd *) gspca_dev; 489 struct sd *sd = (struct sd *) gspca_dev;
477/* __u8 valblue; */
478 __u8 valred;
479 490
480 if (sd->sensor == SENSOR_PAS106) { 491 if (sd->sensor == SENSOR_PAS106) {
481/* Et_i2cread(gspca_dev->dev, PAS106_REG9, &valblue, 1, 1); */ 492/* i2c_r(gspca_dev, PAS106_REG9); * blue */
482 Et_i2cread(gspca_dev->dev, PAS106_REG9 + 3, &valred, 1, 1); 493 i2c_r(gspca_dev, PAS106_REG9 + 3); /* red */
483 sd->colors = valred & 0x0f; 494 sd->colors = gspca_dev->usb_buf[0] & 0x0f;
484 } 495 }
485} 496}
486 497
487static void Et_init1(struct gspca_dev *gspca_dev) 498static void Et_init1(struct gspca_dev *gspca_dev)
488{ 499{
489 struct usb_device *dev = gspca_dev->dev;
490 __u8 value; 500 __u8 value;
491 __u8 received;
492/* __u8 I2c0 [] = {0x0a, 0x12, 0x05, 0x22, 0xac, 0x00, 0x01, 0x00}; */ 501/* __u8 I2c0 [] = {0x0a, 0x12, 0x05, 0x22, 0xac, 0x00, 0x01, 0x00}; */
493 __u8 I2c0[] = { 0x0a, 0x12, 0x05, 0x6d, 0xcd, 0x00, 0x01, 0x00 }; 502 __u8 I2c0[] = { 0x0a, 0x12, 0x05, 0x6d, 0xcd, 0x00, 0x01, 0x00 };
494 /* try 1/120 0x6d 0xcd 0x40 */ 503 /* try 1/120 0x6d 0xcd 0x40 */
@@ -496,12 +505,12 @@ static void Et_init1(struct gspca_dev *gspca_dev)
496 * 1/60000 hmm ?? */ 505 * 1/60000 hmm ?? */
497 506
498 PDEBUG(D_STREAM, "Open Init1 ET"); 507 PDEBUG(D_STREAM, "Open Init1 ET");
499 reg_w_val(dev, ET_GPIO_DIR_CTRL, 7); 508 reg_w_val(gspca_dev, ET_GPIO_DIR_CTRL, 7);
500 reg_r(dev, ET_GPIO_IN, &received, 1); 509 reg_r(gspca_dev, ET_GPIO_IN, 1);
501 reg_w_val(dev, ET_RESET_ALL, 1); 510 reg_w_val(gspca_dev, ET_RESET_ALL, 1);
502 reg_w_val(dev, ET_RESET_ALL, 0); 511 reg_w_val(gspca_dev, ET_RESET_ALL, 0);
503 reg_w_val(dev, ET_ClCK, 0x10); 512 reg_w_val(gspca_dev, ET_ClCK, 0x10);
504 reg_w_val(dev, ET_CTRL, 0x19); 513 reg_w_val(gspca_dev, ET_CTRL, 0x19);
505 /* compression et subsampling */ 514 /* compression et subsampling */
506 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) 515 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv)
507 value = ET_COMP_VAL1; 516 value = ET_COMP_VAL1;
@@ -510,80 +519,79 @@ static void Et_init1(struct gspca_dev *gspca_dev)
510 PDEBUG(D_STREAM, "Open mode %d Compression %d", 519 PDEBUG(D_STREAM, "Open mode %d Compression %d",
511 gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv, 520 gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv,
512 value); 521 value);
513 reg_w_val(dev, ET_COMP, value); 522 reg_w_val(gspca_dev, ET_COMP, value);
514 reg_w_val(dev, ET_MAXQt, 0x1d); 523 reg_w_val(gspca_dev, ET_MAXQt, 0x1d);
515 reg_w_val(dev, ET_MINQt, 0x02); 524 reg_w_val(gspca_dev, ET_MINQt, 0x02);
516 /* undocumented registers */ 525 /* undocumented registers */
517 reg_w_val(dev, ET_REG1d, 0xff); 526 reg_w_val(gspca_dev, ET_REG1d, 0xff);
518 reg_w_val(dev, ET_REG1e, 0xff); 527 reg_w_val(gspca_dev, ET_REG1e, 0xff);
519 reg_w_val(dev, ET_REG1f, 0xff); 528 reg_w_val(gspca_dev, ET_REG1f, 0xff);
520 reg_w_val(dev, ET_REG20, 0x35); 529 reg_w_val(gspca_dev, ET_REG20, 0x35);
521 reg_w_val(dev, ET_REG21, 0x01); 530 reg_w_val(gspca_dev, ET_REG21, 0x01);
522 reg_w_val(dev, ET_REG22, 0x00); 531 reg_w_val(gspca_dev, ET_REG22, 0x00);
523 reg_w_val(dev, ET_REG23, 0xf7); 532 reg_w_val(gspca_dev, ET_REG23, 0xf7);
524 reg_w_val(dev, ET_REG24, 0xff); 533 reg_w_val(gspca_dev, ET_REG24, 0xff);
525 reg_w_val(dev, ET_REG25, 0x07); 534 reg_w_val(gspca_dev, ET_REG25, 0x07);
526 /* colors setting */ 535 /* colors setting */
527 reg_w_val(dev, ET_G_RED, 0x80); 536 reg_w_val(gspca_dev, ET_G_RED, 0x80);
528 reg_w_val(dev, ET_G_GREEN1, 0x80); 537 reg_w_val(gspca_dev, ET_G_GREEN1, 0x80);
529 reg_w_val(dev, ET_G_BLUE, 0x80); 538 reg_w_val(gspca_dev, ET_G_BLUE, 0x80);
530 reg_w_val(dev, ET_G_GREEN2, 0x80); 539 reg_w_val(gspca_dev, ET_G_GREEN2, 0x80);
531 reg_w_val(dev, ET_G_GR_H, 0x00); 540 reg_w_val(gspca_dev, ET_G_GR_H, 0x00);
532 reg_w_val(dev, ET_G_GB_H, 0x00); 541 reg_w_val(gspca_dev, ET_G_GB_H, 0x00);
533 /* Window control registers */ 542 /* Window control registers */
534 reg_w_val(dev, ET_SYNCHRO, 0xf0); 543 reg_w_val(gspca_dev, ET_SYNCHRO, 0xf0);
535 reg_w_val(dev, ET_STARTX, 0x56); /* 0x56 */ 544 reg_w_val(gspca_dev, ET_STARTX, 0x56); /* 0x56 */
536 reg_w_val(dev, ET_STARTY, 0x05); /* 0x04 */ 545 reg_w_val(gspca_dev, ET_STARTY, 0x05); /* 0x04 */
537 reg_w_val(dev, ET_WIDTH_LOW, 0x60); 546 reg_w_val(gspca_dev, ET_WIDTH_LOW, 0x60);
538 reg_w_val(dev, ET_HEIGTH_LOW, 0x20); 547 reg_w_val(gspca_dev, ET_HEIGTH_LOW, 0x20);
539 reg_w_val(dev, ET_W_H_HEIGTH, 0x50); 548 reg_w_val(gspca_dev, ET_W_H_HEIGTH, 0x50);
540 reg_w_val(dev, ET_REG6e, 0x86); 549 reg_w_val(gspca_dev, ET_REG6e, 0x86);
541 reg_w_val(dev, ET_REG6f, 0x01); 550 reg_w_val(gspca_dev, ET_REG6f, 0x01);
542 reg_w_val(dev, ET_REG70, 0x86); 551 reg_w_val(gspca_dev, ET_REG70, 0x86);
543 reg_w_val(dev, ET_REG71, 0x14); 552 reg_w_val(gspca_dev, ET_REG71, 0x14);
544 reg_w_val(dev, ET_REG72, 0x00); 553 reg_w_val(gspca_dev, ET_REG72, 0x00);
545 /* Clock Pattern registers */ 554 /* Clock Pattern registers */
546 reg_w_val(dev, ET_REG73, 0x00); 555 reg_w_val(gspca_dev, ET_REG73, 0x00);
547 reg_w_val(dev, ET_REG74, 0x00); 556 reg_w_val(gspca_dev, ET_REG74, 0x00);
548 reg_w_val(dev, ET_REG75, 0x0a); 557 reg_w_val(gspca_dev, ET_REG75, 0x0a);
549 reg_w_val(dev, ET_I2C_CLK, 0x04); 558 reg_w_val(gspca_dev, ET_I2C_CLK, 0x04);
550 reg_w_val(dev, ET_PXL_CLK, 0x01); 559 reg_w_val(gspca_dev, ET_PXL_CLK, 0x01);
551 /* set the sensor */ 560 /* set the sensor */
552 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { 561 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
553 I2c0[0] = 0x06; 562 I2c0[0] = 0x06;
554 Et_i2cwrite(dev, PAS106_REG2, I2c0, sizeof I2c0, 1); 563 i2c_w(gspca_dev, PAS106_REG2, I2c0, sizeof I2c0, 1);
555 Et_i2cwrite(dev, PAS106_REG9, I2c2, sizeof I2c2, 1); 564 i2c_w(gspca_dev, PAS106_REG9, I2c2, sizeof I2c2, 1);
556 value = 0x06; 565 value = 0x06;
557 Et_i2cwrite(dev, PAS106_REG2, &value, 1, 1); 566 i2c_w(gspca_dev, PAS106_REG2, &value, 1, 1);
558 Et_i2cwrite(dev, PAS106_REG3, I2c3, sizeof I2c3, 1); 567 i2c_w(gspca_dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
559 /* value = 0x1f; */ 568 /* value = 0x1f; */
560 value = 0x04; 569 value = 0x04;
561 Et_i2cwrite(dev, PAS106_REG0e, &value, 1, 1); 570 i2c_w(gspca_dev, PAS106_REG0e, &value, 1, 1);
562 } else { 571 } else {
563 I2c0[0] = 0x0a; 572 I2c0[0] = 0x0a;
564 573
565 Et_i2cwrite(dev, PAS106_REG2, I2c0, sizeof I2c0, 1); 574 i2c_w(gspca_dev, PAS106_REG2, I2c0, sizeof I2c0, 1);
566 Et_i2cwrite(dev, PAS106_REG9, I2c2, sizeof I2c2, 1); 575 i2c_w(gspca_dev, PAS106_REG9, I2c2, sizeof I2c2, 1);
567 value = 0x0a; 576 value = 0x0a;
568 577 i2c_w(gspca_dev, PAS106_REG2, &value, 1, 1);
569 Et_i2cwrite(dev, PAS106_REG2, &value, 1, 1); 578 i2c_w(gspca_dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
570 Et_i2cwrite(dev, PAS106_REG3, I2c3, sizeof I2c3, 1);
571 value = 0x04; 579 value = 0x04;
572 /* value = 0x10; */ 580 /* value = 0x10; */
573 Et_i2cwrite(dev, PAS106_REG0e, &value, 1, 1); 581 i2c_w(gspca_dev, PAS106_REG0e, &value, 1, 1);
574 /* bit 2 enable bit 1:2 select 0 1 2 3 582 /* bit 2 enable bit 1:2 select 0 1 2 3
575 value = 0x07; * curve 0 * 583 value = 0x07; * curve 0 *
576 Et_i2cwrite(dev,PAS106_REG0f,&value,1,1); 584 i2c_w(gspca_dev, PAS106_REG0f, &value, 1, 1);
577 */ 585 */
578 } 586 }
579 587
580/* value = 0x01; */ 588/* value = 0x01; */
581/* value = 0x22; */ 589/* value = 0x22; */
582/* Et_i2cwrite(dev, PAS106_REG5, &value, 1, 1); */ 590/* i2c_w(gspca_dev, PAS106_REG5, &value, 1, 1); */
583 /* magnetude and sign bit for DAC */ 591 /* magnetude and sign bit for DAC */
584 Et_i2cwrite(dev, PAS106_REG7, I2c4, sizeof I2c4, 1); 592 i2c_w(gspca_dev, PAS106_REG7, I2c4, sizeof I2c4, 1);
585 /* now set by fifo the whole colors setting */ 593 /* now set by fifo the whole colors setting */
586 reg_w(dev, ET_G_RED, GainRGBG, 6); 594 reg_w(gspca_dev, ET_G_RED, GainRGBG, 6);
587 getcolors(gspca_dev); 595 getcolors(gspca_dev);
588 setcolors(gspca_dev); 596 setcolors(gspca_dev);
589} 597}
@@ -632,14 +640,13 @@ static int sd_config(struct gspca_dev *gspca_dev,
632static int sd_open(struct gspca_dev *gspca_dev) 640static int sd_open(struct gspca_dev *gspca_dev)
633{ 641{
634 struct sd *sd = (struct sd *) gspca_dev; 642 struct sd *sd = (struct sd *) gspca_dev;
635 struct usb_device *dev = gspca_dev->dev;
636 643
637 if (sd->sensor == SENSOR_PAS106) 644 if (sd->sensor == SENSOR_PAS106)
638 Et_init1(gspca_dev); 645 Et_init1(gspca_dev);
639 else 646 else
640 Et_init2(gspca_dev); 647 Et_init2(gspca_dev);
641 reg_w_val(dev, ET_RESET_ALL, 0x08); 648 reg_w_val(gspca_dev, ET_RESET_ALL, 0x08);
642 et_video(dev, 0); /* video off */ 649 et_video(gspca_dev, 0); /* video off */
643 return 0; 650 return 0;
644} 651}
645 652
@@ -647,20 +654,19 @@ static int sd_open(struct gspca_dev *gspca_dev)
647static void sd_start(struct gspca_dev *gspca_dev) 654static void sd_start(struct gspca_dev *gspca_dev)
648{ 655{
649 struct sd *sd = (struct sd *) gspca_dev; 656 struct sd *sd = (struct sd *) gspca_dev;
650 struct usb_device *dev = gspca_dev->dev;
651 657
652 if (sd->sensor == SENSOR_PAS106) 658 if (sd->sensor == SENSOR_PAS106)
653 Et_init1(gspca_dev); 659 Et_init1(gspca_dev);
654 else 660 else
655 Et_init2(gspca_dev); 661 Et_init2(gspca_dev);
656 662
657 reg_w_val(dev, ET_RESET_ALL, 0x08); 663 reg_w_val(gspca_dev, ET_RESET_ALL, 0x08);
658 et_video(dev, 1); /* video on */ 664 et_video(gspca_dev, 1); /* video on */
659} 665}
660 666
661static void sd_stopN(struct gspca_dev *gspca_dev) 667static void sd_stopN(struct gspca_dev *gspca_dev)
662{ 668{
663 et_video(gspca_dev->dev, 0); /* video off */ 669 et_video(gspca_dev, 0); /* video off */
664} 670}
665 671
666static void sd_stop0(struct gspca_dev *gspca_dev) 672static void sd_stop0(struct gspca_dev *gspca_dev)
@@ -678,7 +684,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
678 __u8 brightness = sd->brightness; 684 __u8 brightness = sd->brightness;
679 685
680 for (i = 0; i < 4; i++) 686 for (i = 0; i < 4; i++)
681 reg_w_val(gspca_dev->dev, (ET_O_RED + i), brightness); 687 reg_w_val(gspca_dev, ET_O_RED + i, brightness);
682} 688}
683 689
684static void getbrightness(struct gspca_dev *gspca_dev) 690static void getbrightness(struct gspca_dev *gspca_dev)
@@ -686,11 +692,10 @@ static void getbrightness(struct gspca_dev *gspca_dev)
686 struct sd *sd = (struct sd *) gspca_dev; 692 struct sd *sd = (struct sd *) gspca_dev;
687 int i; 693 int i;
688 int brightness = 0; 694 int brightness = 0;
689 __u8 value;
690 695
691 for (i = 0; i < 4; i++) { 696 for (i = 0; i < 4; i++) {
692 reg_r(gspca_dev->dev, (ET_O_RED + i), &value, 1); 697 reg_r(gspca_dev, ET_O_RED + i, 1);
693 brightness += value; 698 brightness += gspca_dev->usb_buf[0];
694 } 699 }
695 sd->brightness = brightness >> 3; 700 sd->brightness = brightness >> 3;
696} 701}
@@ -701,8 +706,8 @@ static void setcontrast(struct gspca_dev *gspca_dev)
701 __u8 RGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 }; 706 __u8 RGBG[] = { 0x80, 0x80, 0x80, 0x80, 0x00, 0x00 };
702 __u8 contrast = sd->contrast; 707 __u8 contrast = sd->contrast;
703 708
704 memset(RGBG, contrast, sizeof RGBG - 2); 709 memset(RGBG, contrast, sizeof(RGBG) - 2);
705 reg_w(gspca_dev->dev, ET_G_RED, RGBG, 6); 710 reg_w(gspca_dev, ET_G_RED, RGBG, 6);
706} 711}
707 712
708static void getcontrast(struct gspca_dev *gspca_dev) 713static void getcontrast(struct gspca_dev *gspca_dev)
@@ -710,11 +715,10 @@ static void getcontrast(struct gspca_dev *gspca_dev)
710 struct sd *sd = (struct sd *) gspca_dev; 715 struct sd *sd = (struct sd *) gspca_dev;
711 int i; 716 int i;
712 int contrast = 0; 717 int contrast = 0;
713 __u8 value = 0;
714 718
715 for (i = 0; i < 4; i++) { 719 for (i = 0; i < 4; i++) {
716 reg_r(gspca_dev->dev, (ET_G_RED + i), &value, 1); 720 reg_r(gspca_dev, ET_G_RED + i, 1);
717 contrast += value; 721 contrast += gspca_dev->usb_buf[0];
718 } 722 }
719 sd->contrast = contrast >> 2; 723 sd->contrast = contrast >> 2;
720} 724}
@@ -722,12 +726,11 @@ static void getcontrast(struct gspca_dev *gspca_dev)
722static __u8 Et_getgainG(struct gspca_dev *gspca_dev) 726static __u8 Et_getgainG(struct gspca_dev *gspca_dev)
723{ 727{
724 struct sd *sd = (struct sd *) gspca_dev; 728 struct sd *sd = (struct sd *) gspca_dev;
725 __u8 value = 0;
726 729
727 if (sd->sensor == SENSOR_PAS106) { 730 if (sd->sensor == SENSOR_PAS106) {
728 Et_i2cread(gspca_dev->dev, PAS106_REG0e, &value, 1, 1); 731 i2c_r(gspca_dev, PAS106_REG0e);
729 PDEBUG(D_CONF, "Etoms gain G %d", value); 732 PDEBUG(D_CONF, "Etoms gain G %d", gspca_dev->usb_buf[0]);
730 return value; 733 return gspca_dev->usb_buf[0];
731 } 734 }
732 return 0x1f; 735 return 0x1f;
733} 736}
@@ -735,12 +738,12 @@ static __u8 Et_getgainG(struct gspca_dev *gspca_dev)
735static void Et_setgainG(struct gspca_dev *gspca_dev, __u8 gain) 738static void Et_setgainG(struct gspca_dev *gspca_dev, __u8 gain)
736{ 739{
737 struct sd *sd = (struct sd *) gspca_dev; 740 struct sd *sd = (struct sd *) gspca_dev;
738 struct usb_device *dev = gspca_dev->dev;
739 __u8 i2cflags = 0x01;
740 741
741 if (sd->sensor == SENSOR_PAS106) { 742 if (sd->sensor == SENSOR_PAS106) {
742 Et_i2cwrite(dev, PAS106_REG13, &i2cflags, 1, 3); 743 __u8 i2cflags = 0x01;
743 Et_i2cwrite(dev, PAS106_REG0e, &gain, 1, 1); 744
745 i2c_w(gspca_dev, PAS106_REG13, &i2cflags, 1, 3);
746 i2c_w(gspca_dev, PAS106_REG0e, &gain, 1, 1);
744 } 747 }
745} 748}
746 749
@@ -751,8 +754,6 @@ static void Et_setgainG(struct gspca_dev *gspca_dev, __u8 gain)
751 754
752static void setautogain(struct gspca_dev *gspca_dev) 755static void setautogain(struct gspca_dev *gspca_dev)
753{ 756{
754 struct usb_device *dev = gspca_dev->dev;
755 __u8 GRBG[] = { 0, 0, 0, 0 };
756 __u8 luma = 0; 757 __u8 luma = 0;
757 __u8 luma_mean = 128; 758 __u8 luma_mean = 128;
758 __u8 luma_delta = 20; 759 __u8 luma_delta = 20;
@@ -761,10 +762,10 @@ static void setautogain(struct gspca_dev *gspca_dev)
761 __u8 r, g, b; 762 __u8 r, g, b;
762 763
763 Gbright = Et_getgainG(gspca_dev); 764 Gbright = Et_getgainG(gspca_dev);
764 reg_r(dev, ET_LUMA_CENTER, GRBG, 4); 765 reg_r(gspca_dev, ET_LUMA_CENTER, 4);
765 g = (GRBG[0] + GRBG[3]) >> 1; 766 g = (gspca_dev->usb_buf[0] + gspca_dev->usb_buf[3]) >> 1;
766 r = GRBG[1]; 767 r = gspca_dev->usb_buf[1];
767 b = GRBG[2]; 768 b = gspca_dev->usb_buf[2];
768 r = ((r << 8) - (r << 4) - (r << 3)) >> 10; 769 r = ((r << 8) - (r << 4) - (r << 3)) >> 10;
769 b = ((b << 7) >> 10); 770 b = ((b << 7) >> 10);
770 g = ((g << 9) + (g << 7) + (g << 5)) >> 10; 771 g = ((g << 9) + (g << 7) + (g << 5)) >> 10;
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index a566fd394895..242f0fb68d6e 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -1347,9 +1347,11 @@ ok:
1347 gspca_dev->fr_i, 1347 gspca_dev->fr_i,
1348 gspca_dev->fr_o); 1348 gspca_dev->fr_o);
1349 1349
1350 if (gspca_dev->sd_desc->dq_callback) 1350 if (gspca_dev->sd_desc->dq_callback) {
1351 mutex_lock(&gspca_dev->usb_lock);
1351 gspca_dev->sd_desc->dq_callback(gspca_dev); 1352 gspca_dev->sd_desc->dq_callback(gspca_dev);
1352 1353 mutex_unlock(&gspca_dev->usb_lock);
1354 }
1353 return j; 1355 return j;
1354} 1356}
1355 1357
diff --git a/drivers/media/video/gspca/gspca.h b/drivers/media/video/gspca/gspca.h
index 78fccefcd576..3fd2c4eee204 100644
--- a/drivers/media/video/gspca/gspca.h
+++ b/drivers/media/video/gspca/gspca.h
@@ -125,6 +125,7 @@ struct gspca_dev {
125 struct cam cam; /* device information */ 125 struct cam cam; /* device information */
126 const struct sd_desc *sd_desc; /* subdriver description */ 126 const struct sd_desc *sd_desc; /* subdriver description */
127 127
128 __u8 usb_buf[8]; /* buffer for USB exchanges */
128 struct urb *urb[MAX_NURBS]; 129 struct urb *urb[MAX_NURBS];
129 130
130 __u8 *frbuf; /* buffer for nframes */ 131 __u8 *frbuf; /* buffer for nframes */
diff --git a/drivers/media/video/gspca/mars.c b/drivers/media/video/gspca/mars.c
index 23f3dba8012a..88c2b02f380a 100644
--- a/drivers/media/video/gspca/mars.c
+++ b/drivers/media/video/gspca/mars.c
@@ -24,8 +24,8 @@
24#include "gspca.h" 24#include "gspca.h"
25#include "jpeg.h" 25#include "jpeg.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.5"; 28static const char version[] = "2.1.7";
29 29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver"); 31MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver");
@@ -83,39 +83,53 @@ enum {
83 REG_HW_MI_63, 83 REG_HW_MI_63,
84 REG_HW_MI_64, 84 REG_HW_MI_64,
85 REG_HW_MI_F1 = 0xf1, 85 REG_HW_MI_F1 = 0xf1,
86 ATTR_TOTAL_MI_REG = 242 86 ATTR_TOTAL_MI_REG = 0xf2
87}; 87};
88 88
89static int pcam_reg_write(struct usb_device *dev, 89/* the bytes to write are in gspca_dev->usb_buf */
90 __u16 index, __u8 *value, int len) 90static int reg_w(struct gspca_dev *gspca_dev,
91 __u16 index, int len)
91{ 92{
92 int rc; 93 int rc;
93 94
94 rc = usb_control_msg(dev, 95 rc = usb_control_msg(gspca_dev->dev,
95 usb_sndbulkpipe(dev, 4), 96 usb_sndbulkpipe(gspca_dev->dev, 4),
96 0x12, 97 0x12,
97/* ?? 0xc8 = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_??? !? */ 98 0xc8, /* ?? */
98 0xc8,
99 0, /* value */ 99 0, /* value */
100 index, value, len, 500); 100 index, gspca_dev->usb_buf, len, 500);
101 if (rc < 0) 101 if (rc < 0)
102 PDEBUG(D_ERR, "reg write [%02x] error %d", index, rc); 102 PDEBUG(D_ERR, "reg write [%02x] error %d", index, rc);
103 return rc; 103 return rc;
104} 104}
105 105
106static void MISensor_BulkWrite(struct usb_device *dev, 106static int reg_w_buf(struct gspca_dev *gspca_dev,
107 unsigned short *pch, 107 __u16 index, __u8 *buf, int len)
108 char Address)
109{ 108{
110 __u8 data[6]; 109 int rc;
110
111 rc = usb_control_msg(gspca_dev->dev,
112 usb_sndbulkpipe(gspca_dev->dev, 4),
113 0x12,
114 0xc8, /* ?? */
115 0, /* value */
116 index, buf, len, 500);
117 if (rc < 0)
118 PDEBUG(D_ERR, "reg write [%02x] error %d", index, rc);
119 return rc;
120}
111 121
112 data[0] = 0x1f; 122static void bulk_w(struct gspca_dev *gspca_dev,
113 data[1] = 0; /* control byte */ 123 __u16 *pch,
114 data[2] = Address; 124 __u16 Address)
115 data[3] = *pch >> 8; /* high byte */ 125{
116 data[4] = *pch; /* low byte */ 126 gspca_dev->usb_buf[0] = 0x1f;
127 gspca_dev->usb_buf[1] = 0; /* control byte */
128 gspca_dev->usb_buf[2] = Address;
129 gspca_dev->usb_buf[3] = *pch >> 8; /* high byte */
130 gspca_dev->usb_buf[4] = *pch; /* low byte */
117 131
118 pcam_reg_write(dev, Address, data, 5); 132 reg_w(gspca_dev, Address, 5);
119} 133}
120 134
121/* this function is called at probe time */ 135/* this function is called at probe time */
@@ -142,33 +156,30 @@ static int sd_open(struct gspca_dev *gspca_dev)
142 156
143static void sd_start(struct gspca_dev *gspca_dev) 157static void sd_start(struct gspca_dev *gspca_dev)
144{ 158{
145 struct usb_device *dev = gspca_dev->dev;
146 int err_code; 159 int err_code;
147 __u8 data[12]; 160 __u8 *data;
148 __u16 MI_buf[242]; 161 __u16 *MI_buf;
149 int h_size, v_size; 162 int h_size, v_size;
150 int intpipe; 163 int intpipe;
151/* struct usb_device *dev = pcam->dev; */
152
153 memset(data, 0, sizeof data);
154 memset(MI_buf, 0, sizeof MI_buf);
155 164
156 PDEBUG(D_STREAM, "camera start, iface %d, alt 8", gspca_dev->iface); 165 PDEBUG(D_STREAM, "camera start, iface %d, alt 8", gspca_dev->iface);
157 if (usb_set_interface(dev, gspca_dev->iface, 8) < 0) { 166 if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 8) < 0) {
158 PDEBUG(D_ERR|D_STREAM, "Set packet size: set interface error"); 167 PDEBUG(D_ERR|D_STREAM, "Set packet size: set interface error");
159 return; 168 return;
160 } 169 }
161 170
171 data = gspca_dev->usb_buf;
162 data[0] = 0x01; /* address */ 172 data[0] = 0x01; /* address */
163 data[1] = 0x01; 173 data[1] = 0x01;
164 174
165 err_code = pcam_reg_write(dev, data[0], data, 2); 175 err_code = reg_w(gspca_dev, data[0], 2);
166 if (err_code < 0) 176 if (err_code < 0)
167 return; 177 return;
168 178
169 /* 179 /*
170 Initialize the MR97113 chip register 180 Initialize the MR97113 chip register
171 */ 181 */
182 data = kmalloc(16, GFP_KERNEL);
172 data[0] = 0x00; /* address */ 183 data[0] = 0x00; /* address */
173 data[1] = 0x0c | 0x01; /* reg 0 */ 184 data[1] = 0x0c | 0x01; /* reg 0 */
174 data[2] = 0x01; /* reg 1 */ 185 data[2] = 0x01; /* reg 1 */
@@ -181,34 +192,34 @@ static void sd_start(struct gspca_dev *gspca_dev)
181 data[6] = 4; /* reg 5, H start */ 192 data[6] = 4; /* reg 5, H start */
182 data[7] = 0xc0; /* reg 6, gamma 1.5 */ 193 data[7] = 0xc0; /* reg 6, gamma 1.5 */
183 data[8] = 3; /* reg 7, V start */ 194 data[8] = 3; /* reg 7, V start */
184/* if(h_size == 320 ) */ 195/* if (h_size == 320 ) */
185/* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */ 196/* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */
186/* else */ 197/* else */
187 data[9] = 0x52; /* reg 8, 24MHz, no scale down */ 198 data[9] = 0x52; /* reg 8, 24MHz, no scale down */
188 data[10] = 0x5d; /* reg 9, I2C device address 199 data[10] = 0x5d; /* reg 9, I2C device address
189 * [for PAS5101 (0x40)] [for MI (0x5d)] */ 200 * [for PAS5101 (0x40)] [for MI (0x5d)] */
190 201
191 err_code = pcam_reg_write(dev, data[0], data, 11); 202 err_code = reg_w_buf(gspca_dev, data[0], data, 11);
203 kfree(data);
192 if (err_code < 0) 204 if (err_code < 0)
193 return; 205 return;
194 206
207 data = gspca_dev->usb_buf;
195 data[0] = 0x23; /* address */ 208 data[0] = 0x23; /* address */
196 data[1] = 0x09; /* reg 35, append frame header */ 209 data[1] = 0x09; /* reg 35, append frame header */
197 210
198 err_code = pcam_reg_write(dev, data[0], data, 2); 211 err_code = reg_w(gspca_dev, data[0], 2);
199 if (err_code < 0) { 212 if (err_code < 0)
200 PDEBUG(D_ERR, "Register write failed");
201 return; 213 return;
202 }
203 214
204 data[0] = 0x3C; /* address */ 215 data[0] = 0x3c; /* address */
205/* if (pcam->width == 1280) */ 216/* if (gspca_dev->width == 1280) */
206/* data[1] = 200; * reg 60, pc-cam frame size 217/* data[1] = 200; * reg 60, pc-cam frame size
207 * (unit: 4KB) 800KB */ 218 * (unit: 4KB) 800KB */
208/* else */ 219/* else */
209 data[1] = 50; /* 50 reg 60, pc-cam frame size 220 data[1] = 50; /* 50 reg 60, pc-cam frame size
210 * (unit: 4KB) 200KB */ 221 * (unit: 4KB) 200KB */
211 err_code = pcam_reg_write(dev, data[0], data, 2); 222 err_code = reg_w(gspca_dev, data[0], 2);
212 if (err_code < 0) 223 if (err_code < 0)
213 return; 224 return;
214 225
@@ -250,19 +261,20 @@ static void sd_start(struct gspca_dev *gspca_dev)
250 /* auto dark-gain */ 261 /* auto dark-gain */
251 data[0] = 0x5e; /* address */ 262 data[0] = 0x5e; /* address */
252 263
253 err_code = pcam_reg_write(dev, data[0], data, 6); 264 err_code = reg_w(gspca_dev, data[0], 6);
254 if (err_code < 0) 265 if (err_code < 0)
255 return; 266 return;
256 267
257 data[0] = 0x67; 268 data[0] = 0x67;
258 data[1] = 0x13; /* reg 103, first pixel B, disable sharpness */ 269 data[1] = 0x13; /* reg 103, first pixel B, disable sharpness */
259 err_code = pcam_reg_write(dev, data[0], data, 2); 270 err_code = reg_w(gspca_dev, data[0], 2);
260 if (err_code < 0) 271 if (err_code < 0)
261 return; 272 return;
262 273
263 /* 274 /*
264 * initialize the value of MI sensor... 275 * initialize the value of MI sensor...
265 */ 276 */
277 MI_buf = kzalloc(ATTR_TOTAL_MI_REG * sizeof *MI_buf, GFP_KERNEL);
266 MI_buf[REG_HW_MI_1] = 0x000a; 278 MI_buf[REG_HW_MI_1] = 0x000a;
267 MI_buf[REG_HW_MI_2] = 0x000c; 279 MI_buf[REG_HW_MI_2] = 0x000c;
268 MI_buf[REG_HW_MI_3] = 0x0405; 280 MI_buf[REG_HW_MI_3] = 0x0405;
@@ -304,48 +316,48 @@ static void sd_start(struct gspca_dev *gspca_dev)
304 } 316 }
305 MI_buf[0x20] = 0x1104; 317 MI_buf[0x20] = 0x1104;
306 318
307 MISensor_BulkWrite(dev, MI_buf + 1, 1); 319 bulk_w(gspca_dev, MI_buf + 1, 1);
308 MISensor_BulkWrite(dev, MI_buf + 2, 2); 320 bulk_w(gspca_dev, MI_buf + 2, 2);
309 MISensor_BulkWrite(dev, MI_buf + 3, 3); 321 bulk_w(gspca_dev, MI_buf + 3, 3);
310 MISensor_BulkWrite(dev, MI_buf + 4, 4); 322 bulk_w(gspca_dev, MI_buf + 4, 4);
311 MISensor_BulkWrite(dev, MI_buf + 5, 5); 323 bulk_w(gspca_dev, MI_buf + 5, 5);
312 MISensor_BulkWrite(dev, MI_buf + 6, 6); 324 bulk_w(gspca_dev, MI_buf + 6, 6);
313 MISensor_BulkWrite(dev, MI_buf + 7, 7); 325 bulk_w(gspca_dev, MI_buf + 7, 7);
314 MISensor_BulkWrite(dev, MI_buf + 9, 9); 326 bulk_w(gspca_dev, MI_buf + 9, 9);
315 MISensor_BulkWrite(dev, MI_buf + 0x0b, 0x0b); 327 bulk_w(gspca_dev, MI_buf + 0x0b, 0x0b);
316 MISensor_BulkWrite(dev, MI_buf + 0x0c, 0x0c); 328 bulk_w(gspca_dev, MI_buf + 0x0c, 0x0c);
317 MISensor_BulkWrite(dev, MI_buf + 0x0d, 0x0d); 329 bulk_w(gspca_dev, MI_buf + 0x0d, 0x0d);
318 MISensor_BulkWrite(dev, MI_buf + 0x1e, 0x1e); 330 bulk_w(gspca_dev, MI_buf + 0x1e, 0x1e);
319 MISensor_BulkWrite(dev, MI_buf + 0x20, 0x20); 331 bulk_w(gspca_dev, MI_buf + 0x20, 0x20);
320 MISensor_BulkWrite(dev, MI_buf + 0x2b, 0x2b); 332 bulk_w(gspca_dev, MI_buf + 0x2b, 0x2b);
321 MISensor_BulkWrite(dev, MI_buf + 0x2c, 0x2c); 333 bulk_w(gspca_dev, MI_buf + 0x2c, 0x2c);
322 MISensor_BulkWrite(dev, MI_buf + 0x2d, 0x2d); 334 bulk_w(gspca_dev, MI_buf + 0x2d, 0x2d);
323 MISensor_BulkWrite(dev, MI_buf + 0x2e, 0x2e); 335 bulk_w(gspca_dev, MI_buf + 0x2e, 0x2e);
324 MISensor_BulkWrite(dev, MI_buf + 0x35, 0x35); 336 bulk_w(gspca_dev, MI_buf + 0x35, 0x35);
325 MISensor_BulkWrite(dev, MI_buf + 0x5f, 0x5f); 337 bulk_w(gspca_dev, MI_buf + 0x5f, 0x5f);
326 MISensor_BulkWrite(dev, MI_buf + 0x60, 0x60); 338 bulk_w(gspca_dev, MI_buf + 0x60, 0x60);
327 MISensor_BulkWrite(dev, MI_buf + 0x61, 0x61); 339 bulk_w(gspca_dev, MI_buf + 0x61, 0x61);
328 MISensor_BulkWrite(dev, MI_buf + 0x62, 0x62); 340 bulk_w(gspca_dev, MI_buf + 0x62, 0x62);
329 MISensor_BulkWrite(dev, MI_buf + 0x63, 0x63); 341 bulk_w(gspca_dev, MI_buf + 0x63, 0x63);
330 MISensor_BulkWrite(dev, MI_buf + 0x64, 0x64); 342 bulk_w(gspca_dev, MI_buf + 0x64, 0x64);
331 MISensor_BulkWrite(dev, MI_buf + 0xf1, 0xf1); 343 bulk_w(gspca_dev, MI_buf + 0xf1, 0xf1);
332 344 kfree(MI_buf);
333 intpipe = usb_sndintpipe(dev, 0); 345
334 err_code = usb_clear_halt(dev, intpipe); 346 intpipe = usb_sndintpipe(gspca_dev->dev, 0);
347 err_code = usb_clear_halt(gspca_dev->dev, intpipe);
335 348
336 data[0] = 0x00; 349 data[0] = 0x00;
337 data[1] = 0x4d; /* ISOC transfering enable... */ 350 data[1] = 0x4d; /* ISOC transfering enable... */
338 pcam_reg_write(dev, data[0], data, 2); 351 reg_w(gspca_dev, data[0], 2);
339} 352}
340 353
341static void sd_stopN(struct gspca_dev *gspca_dev) 354static void sd_stopN(struct gspca_dev *gspca_dev)
342{ 355{
343 int result; 356 int result;
344 __u8 data[2];
345 357
346 data[0] = 1; 358 gspca_dev->usb_buf[0] = 1;
347 data[1] = 0; 359 gspca_dev->usb_buf[1] = 0;
348 result = pcam_reg_write(gspca_dev->dev, data[0], data, 2); 360 result = reg_w(gspca_dev, gspca_dev->usb_buf[0], 2);
349 if (result < 0) 361 if (result < 0)
350 PDEBUG(D_ERR, "Camera Stop failed"); 362 PDEBUG(D_ERR, "Camera Stop failed");
351} 363}
diff --git a/drivers/media/video/gspca/ov519.c b/drivers/media/video/gspca/ov519.c
index ba245bafcd6f..08d99c3b78e2 100644
--- a/drivers/media/video/gspca/ov519.c
+++ b/drivers/media/video/gspca/ov519.c
@@ -24,8 +24,8 @@
24 24
25#include "gspca.h" 25#include "gspca.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.5"; 28static const char version[] = "2.1.7";
29 29
30MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); 30MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
31MODULE_DESCRIPTION("OV519 USB Camera Driver"); 31MODULE_DESCRIPTION("OV519 USB Camera Driver");
@@ -282,15 +282,14 @@ static unsigned char ov7670_abs_to_sm(unsigned char v)
282static int reg_w(struct sd *sd, __u16 index, __u8 value) 282static int reg_w(struct sd *sd, __u16 index, __u8 value)
283{ 283{
284 int ret; 284 int ret;
285 __u8 data;
286 285
287 data = value; 286 sd->gspca_dev.usb_buf[0] = value;
288 ret = usb_control_msg(sd->gspca_dev.dev, 287 ret = usb_control_msg(sd->gspca_dev.dev,
289 usb_sndctrlpipe(sd->gspca_dev.dev, 0), 288 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
290 1, /* REQ_IO (ov518/519) */ 289 1, /* REQ_IO (ov518/519) */
291 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 290 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
292 0, index, 291 0, index,
293 &data, 1, 500); 292 sd->gspca_dev.usb_buf, 1, 500);
294 if (ret < 0) 293 if (ret < 0)
295 PDEBUG(D_ERR, "Write reg [%02x] %02x failed", index, value); 294 PDEBUG(D_ERR, "Write reg [%02x] %02x failed", index, value);
296 return ret; 295 return ret;
@@ -301,16 +300,15 @@ static int reg_w(struct sd *sd, __u16 index, __u8 value)
301static int reg_r(struct sd *sd, __u16 index) 300static int reg_r(struct sd *sd, __u16 index)
302{ 301{
303 int ret; 302 int ret;
304 __u8 data;
305 303
306 ret = usb_control_msg(sd->gspca_dev.dev, 304 ret = usb_control_msg(sd->gspca_dev.dev,
307 usb_rcvctrlpipe(sd->gspca_dev.dev, 0), 305 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
308 1, /* REQ_IO */ 306 1, /* REQ_IO */
309 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 307 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
310 0, index, &data, 1, 500); 308 0, index, sd->gspca_dev.usb_buf, 1, 500);
311 309
312 if (ret >= 0) 310 if (ret >= 0)
313 ret = data; 311 ret = sd->gspca_dev.usb_buf[0];
314 else 312 else
315 PDEBUG(D_ERR, "Read reg [0x%02x] failed", index); 313 PDEBUG(D_ERR, "Read reg [0x%02x] failed", index);
316 return ret; 314 return ret;
@@ -321,16 +319,15 @@ static int reg_r8(struct sd *sd,
321 __u16 index) 319 __u16 index)
322{ 320{
323 int ret; 321 int ret;
324 __u8 buf[8];
325 322
326 ret = usb_control_msg(sd->gspca_dev.dev, 323 ret = usb_control_msg(sd->gspca_dev.dev,
327 usb_rcvctrlpipe(sd->gspca_dev.dev, 0), 324 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
328 1, /* REQ_IO */ 325 1, /* REQ_IO */
329 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 326 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
330 0, index, &buf[0], 8, 500); 327 0, index, sd->gspca_dev.usb_buf, 8, 500);
331 328
332 if (ret >= 0) 329 if (ret >= 0)
333 ret = buf[0]; 330 ret = sd->gspca_dev.usb_buf[0];
334 else 331 else
335 PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index); 332 PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index);
336 return ret; 333 return ret;
diff --git a/drivers/media/video/gspca/pac207.c b/drivers/media/video/gspca/pac207.c
index 5d68d3f42262..fa7abc411090 100644
--- a/drivers/media/video/gspca/pac207.c
+++ b/drivers/media/video/gspca/pac207.c
@@ -27,8 +27,8 @@
27 27
28#include "gspca.h" 28#include "gspca.h"
29 29
30#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 30#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
31static const char version[] = "2.1.5"; 31static const char version[] = "2.1.7";
32 32
33MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>"); 33MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>");
34MODULE_DESCRIPTION("Pixart PAC207"); 34MODULE_DESCRIPTION("Pixart PAC207");
@@ -187,18 +187,18 @@ static const __u8 PacReg72[] = { 0x00, 0x00, 0x36, 0x00 };
187static const unsigned char pac207_sof_marker[5] = 187static const unsigned char pac207_sof_marker[5] =
188 { 0xff, 0xff, 0x00, 0xff, 0x96 }; 188 { 0xff, 0xff, 0x00, 0xff, 0x96 };
189 189
190int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index, 190static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
191 const u8 *buffer, u16 length) 191 const u8 *buffer, u16 length)
192{ 192{
193 struct usb_device *udev = gspca_dev->dev; 193 struct usb_device *udev = gspca_dev->dev;
194 int err; 194 int err;
195 u8 kbuf[8];
196 195
197 memcpy(kbuf, buffer, length); 196 memcpy(gspca_dev->usb_buf, buffer, length);
198 197
199 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x01, 198 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x01,
200 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 199 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
201 0x00, index, kbuf, length, PAC207_CTRL_TIMEOUT); 200 0x00, index,
201 gspca_dev->usb_buf, length, PAC207_CTRL_TIMEOUT);
202 if (err < 0) 202 if (err < 0)
203 PDEBUG(D_ERR, 203 PDEBUG(D_ERR,
204 "Failed to write registers to index 0x%04X, error %d)", 204 "Failed to write registers to index 0x%04X, error %d)",
@@ -227,12 +227,12 @@ int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
227int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index) 227int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index)
228{ 228{
229 struct usb_device *udev = gspca_dev->dev; 229 struct usb_device *udev = gspca_dev->dev;
230 u8 buff;
231 int res; 230 int res;
232 231
233 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00, 232 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00,
234 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 233 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
235 0x00, index, &buff, 1, PAC207_CTRL_TIMEOUT); 234 0x00, index,
235 gspca_dev->usb_buf, 1, PAC207_CTRL_TIMEOUT);
236 if (res < 0) { 236 if (res < 0) {
237 PDEBUG(D_ERR, 237 PDEBUG(D_ERR,
238 "Failed to read a register (index 0x%04X, error %d)", 238 "Failed to read a register (index 0x%04X, error %d)",
@@ -240,10 +240,9 @@ int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index)
240 return res; 240 return res;
241 } 241 }
242 242
243 return buff; 243 return gspca_dev->usb_buf[0];
244} 244}
245 245
246
247/* this function is called at probe time */ 246/* this function is called at probe time */
248static int sd_config(struct gspca_dev *gspca_dev, 247static int sd_config(struct gspca_dev *gspca_dev,
249 const struct usb_device_id *id) 248 const struct usb_device_id *id)
diff --git a/drivers/media/video/gspca/pac7311.c b/drivers/media/video/gspca/pac7311.c
index 1a2347aa7157..5c052e31be4a 100644
--- a/drivers/media/video/gspca/pac7311.c
+++ b/drivers/media/video/gspca/pac7311.c
@@ -23,8 +23,8 @@
23 23
24#include "gspca.h" 24#include "gspca.h"
25 25
26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
27static const char version[] = "2.1.5"; 27static const char version[] = "2.1.7";
28 28
29MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li"); 29MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li");
30MODULE_DESCRIPTION("Pixart PAC7311"); 30MODULE_DESCRIPTION("Pixart PAC7311");
@@ -206,46 +206,43 @@ static const __u8 pac7311_jpeg_header[] = {
206 0x11, 0x00, 0x3f, 0x00 206 0x11, 0x00, 0x3f, 0x00
207}; 207};
208 208
209static void reg_w(struct usb_device *dev, 209static void reg_w_buf(struct gspca_dev *gspca_dev,
210 __u16 index, 210 __u16 index,
211 const char *buffer, __u16 len) 211 const char *buffer, __u16 len)
212{ 212{
213 __u8 tmpbuf[8]; 213 memcpy(gspca_dev->usb_buf, buffer, len);
214 214 usb_control_msg(gspca_dev->dev,
215 memcpy(tmpbuf, buffer, len); 215 usb_sndctrlpipe(gspca_dev->dev, 0),
216 usb_control_msg(dev,
217 usb_sndctrlpipe(dev, 0),
218 1, /* request */ 216 1, /* request */
219 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 217 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
220 0, /* value */ 218 0, /* value */
221 index, tmpbuf, len, 219 index, gspca_dev->usb_buf, len,
222 500); 220 500);
223} 221}
224 222
225static void pac7311_reg_read(struct usb_device *dev, __u16 index, 223static __u8 reg_r(struct gspca_dev *gspca_dev,
226 __u8 *buffer) 224 __u16 index)
227{ 225{
228 usb_control_msg(dev, 226 usb_control_msg(gspca_dev->dev,
229 usb_rcvctrlpipe(dev, 0), 227 usb_rcvctrlpipe(gspca_dev->dev, 0),
230 0, /* request */ 228 0, /* request */
231 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 229 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
232 0, /* value */ 230 0, /* value */
233 index, buffer, 1, 231 index, gspca_dev->usb_buf, 1,
234 500); 232 500);
233 return gspca_dev->usb_buf[0];
235} 234}
236 235
237static void pac7311_reg_write(struct usb_device *dev, 236static void reg_w(struct gspca_dev *gspca_dev,
238 __u16 index, 237 __u16 index,
239 __u8 value) 238 __u8 value)
240{ 239{
241 __u8 buf; 240 gspca_dev->usb_buf[0] = value;
242 241 usb_control_msg(gspca_dev->dev,
243 buf = value; 242 usb_sndctrlpipe(gspca_dev->dev, 0),
244 usb_control_msg(dev,
245 usb_sndctrlpipe(dev, 0),
246 0, /* request */ 243 0, /* request */
247 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 244 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
248 value, index, &buf, 1, 245 value, index, gspca_dev->usb_buf, 1,
249 500); 246 500);
250} 247}
251 248
@@ -254,20 +251,19 @@ static int sd_config(struct gspca_dev *gspca_dev,
254 const struct usb_device_id *id) 251 const struct usb_device_id *id)
255{ 252{
256 struct sd *sd = (struct sd *) gspca_dev; 253 struct sd *sd = (struct sd *) gspca_dev;
257 struct usb_device *dev = gspca_dev->dev;
258 struct cam *cam; 254 struct cam *cam;
259 255
260 PDEBUG(D_CONF, "Find Sensor PAC7311"); 256 PDEBUG(D_CONF, "Find Sensor PAC7311");
261 pac7311_reg_write(dev, 0x78, 0x40); /* Bit_0=start stream, Bit_7=LED */ 257 reg_w(gspca_dev, 0x78, 0x40); /* Bit_0=start stream, Bit_7=LED */
262 pac7311_reg_write(dev, 0x78, 0x40); /* Bit_0=start stream, Bit_7=LED */ 258 reg_w(gspca_dev, 0x78, 0x40); /* Bit_0=start stream, Bit_7=LED */
263 pac7311_reg_write(dev, 0x78, 0x44); /* Bit_0=start stream, Bit_7=LED */ 259 reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_7=LED */
264 pac7311_reg_write(dev, 0xff, 0x04); 260 reg_w(gspca_dev, 0xff, 0x04);
265 pac7311_reg_write(dev, 0x27, 0x80); 261 reg_w(gspca_dev, 0x27, 0x80);
266 pac7311_reg_write(dev, 0x28, 0xca); 262 reg_w(gspca_dev, 0x28, 0xca);
267 pac7311_reg_write(dev, 0x29, 0x53); 263 reg_w(gspca_dev, 0x29, 0x53);
268 pac7311_reg_write(dev, 0x2a, 0x0e); 264 reg_w(gspca_dev, 0x2a, 0x0e);
269 pac7311_reg_write(dev, 0xff, 0x01); 265 reg_w(gspca_dev, 0xff, 0x01);
270 pac7311_reg_write(dev, 0x3e, 0x20); 266 reg_w(gspca_dev, 0x3e, 0x20);
271 267
272 cam = &gspca_dev->cam; 268 cam = &gspca_dev->cam;
273 cam->dev_name = (char *) id->driver_info; 269 cam->dev_name = (char *) id->driver_info;
@@ -289,11 +285,11 @@ static void setbrightness(struct gspca_dev *gspca_dev)
289 285
290/*jfm: inverted?*/ 286/*jfm: inverted?*/
291 brightness = BRIGHTNESS_MAX - sd->brightness; 287 brightness = BRIGHTNESS_MAX - sd->brightness;
292 pac7311_reg_write(gspca_dev->dev, 0xff, 0x04); 288 reg_w(gspca_dev, 0xff, 0x04);
293/* pac7311_reg_write(gspca_dev->dev, 0x0e, 0x00); */ 289/* reg_w(gspca_dev, 0x0e, 0x00); */
294 pac7311_reg_write(gspca_dev->dev, 0x0f, brightness); 290 reg_w(gspca_dev, 0x0f, brightness);
295 /* load registers to sensor (Bit 0, auto clear) */ 291 /* load registers to sensor (Bit 0, auto clear) */
296 pac7311_reg_write(gspca_dev->dev, 0x11, 0x01); 292 reg_w(gspca_dev, 0x11, 0x01);
297 PDEBUG(D_CONF|D_STREAM, "brightness: %i", brightness); 293 PDEBUG(D_CONF|D_STREAM, "brightness: %i", brightness);
298} 294}
299 295
@@ -301,10 +297,10 @@ static void setcontrast(struct gspca_dev *gspca_dev)
301{ 297{
302 struct sd *sd = (struct sd *) gspca_dev; 298 struct sd *sd = (struct sd *) gspca_dev;
303 299
304 pac7311_reg_write(gspca_dev->dev, 0xff, 0x01); 300 reg_w(gspca_dev, 0xff, 0x01);
305 pac7311_reg_write(gspca_dev->dev, 0x80, sd->contrast); 301 reg_w(gspca_dev, 0x80, sd->contrast);
306 /* load registers to sensor (Bit 0, auto clear) */ 302 /* load registers to sensor (Bit 0, auto clear) */
307 pac7311_reg_write(gspca_dev->dev, 0x11, 0x01); 303 reg_w(gspca_dev, 0x11, 0x01);
308 PDEBUG(D_CONF|D_STREAM, "contrast: %i", sd->contrast); 304 PDEBUG(D_CONF|D_STREAM, "contrast: %i", sd->contrast);
309} 305}
310 306
@@ -312,94 +308,93 @@ static void setcolors(struct gspca_dev *gspca_dev)
312{ 308{
313 struct sd *sd = (struct sd *) gspca_dev; 309 struct sd *sd = (struct sd *) gspca_dev;
314 310
315 pac7311_reg_write(gspca_dev->dev, 0xff, 0x01); 311 reg_w(gspca_dev, 0xff, 0x01);
316 pac7311_reg_write(gspca_dev->dev, 0x10, sd->colors); 312 reg_w(gspca_dev, 0x10, sd->colors);
317 /* load registers to sensor (Bit 0, auto clear) */ 313 /* load registers to sensor (Bit 0, auto clear) */
318 pac7311_reg_write(gspca_dev->dev, 0x11, 0x01); 314 reg_w(gspca_dev, 0x11, 0x01);
319 PDEBUG(D_CONF|D_STREAM, "color: %i", sd->colors); 315 PDEBUG(D_CONF|D_STREAM, "color: %i", sd->colors);
320} 316}
321 317
322/* this function is called at open time */ 318/* this function is called at open time */
323static int sd_open(struct gspca_dev *gspca_dev) 319static int sd_open(struct gspca_dev *gspca_dev)
324{ 320{
325 pac7311_reg_write(gspca_dev->dev, 0x78, 0x00); /* Turn on LED */ 321 reg_w(gspca_dev, 0x78, 0x00); /* Turn on LED */
326 return 0; 322 return 0;
327} 323}
328 324
329static void sd_start(struct gspca_dev *gspca_dev) 325static void sd_start(struct gspca_dev *gspca_dev)
330{ 326{
331 struct usb_device *dev = gspca_dev->dev;
332 struct sd *sd = (struct sd *) gspca_dev; 327 struct sd *sd = (struct sd *) gspca_dev;
333 328
334 pac7311_reg_write(dev, 0xff, 0x01); 329 reg_w(gspca_dev, 0xff, 0x01);
335 reg_w(dev, 0x0002, "\x48\x0a\x40\x08\x00\x00\x08\x00", 8); 330 reg_w_buf(gspca_dev, 0x0002, "\x48\x0a\x40\x08\x00\x00\x08\x00", 8);
336 reg_w(dev, 0x000a, "\x06\xff\x11\xff\x5a\x30\x90\x4c", 8); 331 reg_w_buf(gspca_dev, 0x000a, "\x06\xff\x11\xff\x5a\x30\x90\x4c", 8);
337 reg_w(dev, 0x0012, "\x00\x07\x00\x0a\x10\x00\xa0\x10", 8); 332 reg_w_buf(gspca_dev, 0x0012, "\x00\x07\x00\x0a\x10\x00\xa0\x10", 8);
338 reg_w(dev, 0x001a, "\x02\x00\x00\x00\x00\x0b\x01\x00", 8); 333 reg_w_buf(gspca_dev, 0x001a, "\x02\x00\x00\x00\x00\x0b\x01\x00", 8);
339 reg_w(dev, 0x0022, "\x00\x00\x00\x00\x00\x00\x00\x00", 8); 334 reg_w_buf(gspca_dev, 0x0022, "\x00\x00\x00\x00\x00\x00\x00\x00", 8);
340 reg_w(dev, 0x002a, "\x00\x00\x00", 3); 335 reg_w_buf(gspca_dev, 0x002a, "\x00\x00\x00", 3);
341 reg_w(dev, 0x003e, "\x00\x00\x78\x52\x4a\x52\x78\x6e", 8); 336 reg_w_buf(gspca_dev, 0x003e, "\x00\x00\x78\x52\x4a\x52\x78\x6e", 8);
342 reg_w(dev, 0x0046, "\x48\x46\x48\x6e\x5f\x49\x42\x49", 8); 337 reg_w_buf(gspca_dev, 0x0046, "\x48\x46\x48\x6e\x5f\x49\x42\x49", 8);
343 reg_w(dev, 0x004e, "\x5f\x5f\x49\x42\x49\x5f\x6e\x48", 8); 338 reg_w_buf(gspca_dev, 0x004e, "\x5f\x5f\x49\x42\x49\x5f\x6e\x48", 8);
344 reg_w(dev, 0x0056, "\x46\x48\x6e\x78\x52\x4a\x52\x78", 8); 339 reg_w_buf(gspca_dev, 0x0056, "\x46\x48\x6e\x78\x52\x4a\x52\x78", 8);
345 reg_w(dev, 0x005e, "\x00\x00\x09\x1b\x34\x49\x5c\x9b", 8); 340 reg_w_buf(gspca_dev, 0x005e, "\x00\x00\x09\x1b\x34\x49\x5c\x9b", 8);
346 reg_w(dev, 0x0066, "\xd0\xff", 2); 341 reg_w_buf(gspca_dev, 0x0066, "\xd0\xff", 2);
347 reg_w(dev, 0x0078, "\x44\x00\xf2\x01\x01\x80", 6); 342 reg_w_buf(gspca_dev, 0x0078, "\x44\x00\xf2\x01\x01\x80", 6);
348 reg_w(dev, 0x007f, "\x2a\x1c\x00\xc8\x02\x58\x03\x84", 8); 343 reg_w_buf(gspca_dev, 0x007f, "\x2a\x1c\x00\xc8\x02\x58\x03\x84", 8);
349 reg_w(dev, 0x0087, "\x12\x00\x1a\x04\x08\x0c\x10\x14", 8); 344 reg_w_buf(gspca_dev, 0x0087, "\x12\x00\x1a\x04\x08\x0c\x10\x14", 8);
350 reg_w(dev, 0x008f, "\x18\x20", 2); 345 reg_w_buf(gspca_dev, 0x008f, "\x18\x20", 2);
351 reg_w(dev, 0x0096, "\x01\x08\x04", 3); 346 reg_w_buf(gspca_dev, 0x0096, "\x01\x08\x04", 3);
352 reg_w(dev, 0x00a0, "\x44\x44\x44\x04", 4); 347 reg_w_buf(gspca_dev, 0x00a0, "\x44\x44\x44\x04", 4);
353 reg_w(dev, 0x00f0, "\x01\x00\x00\x00\x22\x00\x20\x00", 8); 348 reg_w_buf(gspca_dev, 0x00f0, "\x01\x00\x00\x00\x22\x00\x20\x00", 8);
354 reg_w(dev, 0x00f8, "\x3f\x00\x0a\x01\x00", 5); 349 reg_w_buf(gspca_dev, 0x00f8, "\x3f\x00\x0a\x01\x00", 5);
355 350
356 pac7311_reg_write(dev, 0xff, 0x04); 351 reg_w(gspca_dev, 0xff, 0x04);
357 pac7311_reg_write(dev, 0x02, 0x04); 352 reg_w(gspca_dev, 0x02, 0x04);
358 pac7311_reg_write(dev, 0x03, 0x54); 353 reg_w(gspca_dev, 0x03, 0x54);
359 pac7311_reg_write(dev, 0x04, 0x07); 354 reg_w(gspca_dev, 0x04, 0x07);
360 pac7311_reg_write(dev, 0x05, 0x2b); 355 reg_w(gspca_dev, 0x05, 0x2b);
361 pac7311_reg_write(dev, 0x06, 0x09); 356 reg_w(gspca_dev, 0x06, 0x09);
362 pac7311_reg_write(dev, 0x07, 0x0f); 357 reg_w(gspca_dev, 0x07, 0x0f);
363 pac7311_reg_write(dev, 0x08, 0x09); 358 reg_w(gspca_dev, 0x08, 0x09);
364 pac7311_reg_write(dev, 0x09, 0x00); 359 reg_w(gspca_dev, 0x09, 0x00);
365 pac7311_reg_write(dev, 0x0c, 0x07); 360 reg_w(gspca_dev, 0x0c, 0x07);
366 pac7311_reg_write(dev, 0x0d, 0x00); 361 reg_w(gspca_dev, 0x0d, 0x00);
367 pac7311_reg_write(dev, 0x0e, 0x00); 362 reg_w(gspca_dev, 0x0e, 0x00);
368 pac7311_reg_write(dev, 0x0f, 0x62); 363 reg_w(gspca_dev, 0x0f, 0x62);
369 pac7311_reg_write(dev, 0x10, 0x08); 364 reg_w(gspca_dev, 0x10, 0x08);
370 pac7311_reg_write(dev, 0x12, 0x07); 365 reg_w(gspca_dev, 0x12, 0x07);
371 pac7311_reg_write(dev, 0x13, 0x00); 366 reg_w(gspca_dev, 0x13, 0x00);
372 pac7311_reg_write(dev, 0x14, 0x00); 367 reg_w(gspca_dev, 0x14, 0x00);
373 pac7311_reg_write(dev, 0x15, 0x00); 368 reg_w(gspca_dev, 0x15, 0x00);
374 pac7311_reg_write(dev, 0x16, 0x00); 369 reg_w(gspca_dev, 0x16, 0x00);
375 pac7311_reg_write(dev, 0x17, 0x00); 370 reg_w(gspca_dev, 0x17, 0x00);
376 pac7311_reg_write(dev, 0x18, 0x00); 371 reg_w(gspca_dev, 0x18, 0x00);
377 pac7311_reg_write(dev, 0x19, 0x00); 372 reg_w(gspca_dev, 0x19, 0x00);
378 pac7311_reg_write(dev, 0x1a, 0x00); 373 reg_w(gspca_dev, 0x1a, 0x00);
379 pac7311_reg_write(dev, 0x1b, 0x03); 374 reg_w(gspca_dev, 0x1b, 0x03);
380 pac7311_reg_write(dev, 0x1c, 0xa0); 375 reg_w(gspca_dev, 0x1c, 0xa0);
381 pac7311_reg_write(dev, 0x1d, 0x01); 376 reg_w(gspca_dev, 0x1d, 0x01);
382 pac7311_reg_write(dev, 0x1e, 0xf4); 377 reg_w(gspca_dev, 0x1e, 0xf4);
383 pac7311_reg_write(dev, 0x21, 0x00); 378 reg_w(gspca_dev, 0x21, 0x00);
384 pac7311_reg_write(dev, 0x22, 0x08); 379 reg_w(gspca_dev, 0x22, 0x08);
385 pac7311_reg_write(dev, 0x24, 0x03); 380 reg_w(gspca_dev, 0x24, 0x03);
386 pac7311_reg_write(dev, 0x26, 0x00); 381 reg_w(gspca_dev, 0x26, 0x00);
387 pac7311_reg_write(dev, 0x27, 0x01); 382 reg_w(gspca_dev, 0x27, 0x01);
388 pac7311_reg_write(dev, 0x28, 0xca); 383 reg_w(gspca_dev, 0x28, 0xca);
389 pac7311_reg_write(dev, 0x29, 0x10); 384 reg_w(gspca_dev, 0x29, 0x10);
390 pac7311_reg_write(dev, 0x2a, 0x06); 385 reg_w(gspca_dev, 0x2a, 0x06);
391 pac7311_reg_write(dev, 0x2b, 0x78); 386 reg_w(gspca_dev, 0x2b, 0x78);
392 pac7311_reg_write(dev, 0x2c, 0x00); 387 reg_w(gspca_dev, 0x2c, 0x00);
393 pac7311_reg_write(dev, 0x2d, 0x00); 388 reg_w(gspca_dev, 0x2d, 0x00);
394 pac7311_reg_write(dev, 0x2e, 0x00); 389 reg_w(gspca_dev, 0x2e, 0x00);
395 pac7311_reg_write(dev, 0x2f, 0x00); 390 reg_w(gspca_dev, 0x2f, 0x00);
396 pac7311_reg_write(dev, 0x30, 0x23); 391 reg_w(gspca_dev, 0x30, 0x23);
397 pac7311_reg_write(dev, 0x31, 0x28); 392 reg_w(gspca_dev, 0x31, 0x28);
398 pac7311_reg_write(dev, 0x32, 0x04); 393 reg_w(gspca_dev, 0x32, 0x04);
399 pac7311_reg_write(dev, 0x33, 0x11); 394 reg_w(gspca_dev, 0x33, 0x11);
400 pac7311_reg_write(dev, 0x34, 0x00); 395 reg_w(gspca_dev, 0x34, 0x00);
401 pac7311_reg_write(dev, 0x35, 0x00); 396 reg_w(gspca_dev, 0x35, 0x00);
402 pac7311_reg_write(dev, 0x11, 0x01); 397 reg_w(gspca_dev, 0x11, 0x01);
403 setcontrast(gspca_dev); 398 setcontrast(gspca_dev);
404 setbrightness(gspca_dev); 399 setbrightness(gspca_dev);
405 setcolors(gspca_dev); 400 setcolors(gspca_dev);
@@ -407,39 +402,39 @@ static void sd_start(struct gspca_dev *gspca_dev)
407 /* set correct resolution */ 402 /* set correct resolution */
408 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { 403 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
409 case 2: /* 160x120 */ 404 case 2: /* 160x120 */
410 pac7311_reg_write(dev, 0xff, 0x04); 405 reg_w(gspca_dev, 0xff, 0x04);
411 pac7311_reg_write(dev, 0x02, 0x03); 406 reg_w(gspca_dev, 0x02, 0x03);
412 pac7311_reg_write(dev, 0xff, 0x01); 407 reg_w(gspca_dev, 0xff, 0x01);
413 pac7311_reg_write(dev, 0x08, 0x09); 408 reg_w(gspca_dev, 0x08, 0x09);
414 pac7311_reg_write(dev, 0x17, 0x20); 409 reg_w(gspca_dev, 0x17, 0x20);
415 pac7311_reg_write(dev, 0x1b, 0x00); 410 reg_w(gspca_dev, 0x1b, 0x00);
416/* pac7311_reg_write(dev, 0x80, 0x69); */ 411/* reg_w(gspca_dev, 0x80, 0x69); */
417 pac7311_reg_write(dev, 0x87, 0x10); 412 reg_w(gspca_dev, 0x87, 0x10);
418 break; 413 break;
419 case 1: /* 320x240 */ 414 case 1: /* 320x240 */
420 pac7311_reg_write(dev, 0xff, 0x04); 415 reg_w(gspca_dev, 0xff, 0x04);
421 pac7311_reg_write(dev, 0x02, 0x03); 416 reg_w(gspca_dev, 0x02, 0x03);
422 pac7311_reg_write(dev, 0xff, 0x01); 417 reg_w(gspca_dev, 0xff, 0x01);
423 pac7311_reg_write(dev, 0x08, 0x09); 418 reg_w(gspca_dev, 0x08, 0x09);
424 pac7311_reg_write(dev, 0x17, 0x30); 419 reg_w(gspca_dev, 0x17, 0x30);
425/* pac7311_reg_write(dev, 0x80, 0x3f); */ 420/* reg_w(gspca_dev, 0x80, 0x3f); */
426 pac7311_reg_write(dev, 0x87, 0x11); 421 reg_w(gspca_dev, 0x87, 0x11);
427 break; 422 break;
428 case 0: /* 640x480 */ 423 case 0: /* 640x480 */
429 pac7311_reg_write(dev, 0xff, 0x04); 424 reg_w(gspca_dev, 0xff, 0x04);
430 pac7311_reg_write(dev, 0x02, 0x03); 425 reg_w(gspca_dev, 0x02, 0x03);
431 pac7311_reg_write(dev, 0xff, 0x01); 426 reg_w(gspca_dev, 0xff, 0x01);
432 pac7311_reg_write(dev, 0x08, 0x08); 427 reg_w(gspca_dev, 0x08, 0x08);
433 pac7311_reg_write(dev, 0x17, 0x00); 428 reg_w(gspca_dev, 0x17, 0x00);
434/* pac7311_reg_write(dev, 0x80, 0x1c); */ 429/* reg_w(gspca_dev, 0x80, 0x1c); */
435 pac7311_reg_write(dev, 0x87, 0x12); 430 reg_w(gspca_dev, 0x87, 0x12);
436 break; 431 break;
437 } 432 }
438 433
439 /* start stream */ 434 /* start stream */
440 pac7311_reg_write(dev, 0xff, 0x01); 435 reg_w(gspca_dev, 0xff, 0x01);
441 pac7311_reg_write(dev, 0x78, 0x04); 436 reg_w(gspca_dev, 0x78, 0x04);
442 pac7311_reg_write(dev, 0x78, 0x05); 437 reg_w(gspca_dev, 0x78, 0x05);
443 438
444 if (sd->autogain) { 439 if (sd->autogain) {
445 sd->ag_cnt = AG_CNT_START; 440 sd->ag_cnt = AG_CNT_START;
@@ -451,18 +446,16 @@ static void sd_start(struct gspca_dev *gspca_dev)
451 446
452static void sd_stopN(struct gspca_dev *gspca_dev) 447static void sd_stopN(struct gspca_dev *gspca_dev)
453{ 448{
454 struct usb_device *dev = gspca_dev->dev; 449 reg_w(gspca_dev, 0xff, 0x04);
455 450 reg_w(gspca_dev, 0x27, 0x80);
456 pac7311_reg_write(dev, 0xff, 0x04); 451 reg_w(gspca_dev, 0x28, 0xca);
457 pac7311_reg_write(dev, 0x27, 0x80); 452 reg_w(gspca_dev, 0x29, 0x53);
458 pac7311_reg_write(dev, 0x28, 0xca); 453 reg_w(gspca_dev, 0x2a, 0x0e);
459 pac7311_reg_write(dev, 0x29, 0x53); 454 reg_w(gspca_dev, 0xff, 0x01);
460 pac7311_reg_write(dev, 0x2a, 0x0e); 455 reg_w(gspca_dev, 0x3e, 0x20);
461 pac7311_reg_write(dev, 0xff, 0x01); 456 reg_w(gspca_dev, 0x78, 0x04); /* Bit_0=start stream, Bit_7=LED */
462 pac7311_reg_write(dev, 0x3e, 0x20); 457 reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_7=LED */
463 pac7311_reg_write(dev, 0x78, 0x04); /* Bit_0=start stream, Bit_7=LED */ 458 reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_7=LED */
464 pac7311_reg_write(dev, 0x78, 0x44); /* Bit_0=start stream, Bit_7=LED */
465 pac7311_reg_write(dev, 0x78, 0x44); /* Bit_0=start stream, Bit_7=LED */
466} 459}
467 460
468static void sd_stop0(struct gspca_dev *gspca_dev) 461static void sd_stop0(struct gspca_dev *gspca_dev)
@@ -472,18 +465,16 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
472/* this function is called at close time */ 465/* this function is called at close time */
473static void sd_close(struct gspca_dev *gspca_dev) 466static void sd_close(struct gspca_dev *gspca_dev)
474{ 467{
475 struct usb_device *dev = gspca_dev->dev; 468 reg_w(gspca_dev, 0xff, 0x04);
476 469 reg_w(gspca_dev, 0x27, 0x80);
477 pac7311_reg_write(dev, 0xff, 0x04); 470 reg_w(gspca_dev, 0x28, 0xca);
478 pac7311_reg_write(dev, 0x27, 0x80); 471 reg_w(gspca_dev, 0x29, 0x53);
479 pac7311_reg_write(dev, 0x28, 0xca); 472 reg_w(gspca_dev, 0x2a, 0x0e);
480 pac7311_reg_write(dev, 0x29, 0x53); 473 reg_w(gspca_dev, 0xff, 0x01);
481 pac7311_reg_write(dev, 0x2a, 0x0e); 474 reg_w(gspca_dev, 0x3e, 0x20);
482 pac7311_reg_write(dev, 0xff, 0x01); 475 reg_w(gspca_dev, 0x78, 0x04); /* Bit_0=start stream, Bit_7=LED */
483 pac7311_reg_write(dev, 0x3e, 0x20); 476 reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_7=LED */
484 pac7311_reg_write(dev, 0x78, 0x04); /* Bit_0=start stream, Bit_7=LED */ 477 reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_7=LED */
485 pac7311_reg_write(dev, 0x78, 0x44); /* Bit_0=start stream, Bit_7=LED */
486 pac7311_reg_write(dev, 0x78, 0x44); /* Bit_0=start stream, Bit_7=LED */
487} 478}
488 479
489static void setautogain(struct gspca_dev *gspca_dev, int luma) 480static void setautogain(struct gspca_dev *gspca_dev, int luma)
@@ -491,11 +482,9 @@ static void setautogain(struct gspca_dev *gspca_dev, int luma)
491 int luma_mean = 128; 482 int luma_mean = 128;
492 int luma_delta = 20; 483 int luma_delta = 20;
493 __u8 spring = 5; 484 __u8 spring = 5;
494 __u8 Pxclk;
495 int Gbright; 485 int Gbright;
496 486
497 pac7311_reg_read(gspca_dev->dev, 0x02, &Pxclk); 487 Gbright = reg_r(gspca_dev, 0x02);
498 Gbright = Pxclk;
499 PDEBUG(D_FRAM, "luma mean %d", luma); 488 PDEBUG(D_FRAM, "luma mean %d", luma);
500 if (luma < luma_mean - luma_delta || 489 if (luma < luma_mean - luma_delta ||
501 luma > luma_mean + luma_delta) { 490 luma > luma_mean + luma_delta) {
@@ -505,10 +494,10 @@ static void setautogain(struct gspca_dev *gspca_dev, int luma)
505 else if (Gbright < 4) 494 else if (Gbright < 4)
506 Gbright = 4; 495 Gbright = 4;
507 PDEBUG(D_FRAM, "gbright %d", Gbright); 496 PDEBUG(D_FRAM, "gbright %d", Gbright);
508 pac7311_reg_write(gspca_dev->dev, 0xff, 0x04); 497 reg_w(gspca_dev, 0xff, 0x04);
509 pac7311_reg_write(gspca_dev->dev, 0x0f, Gbright); 498 reg_w(gspca_dev, 0x0f, Gbright);
510 /* load registers to sensor (Bit 0, auto clear) */ 499 /* load registers to sensor (Bit 0, auto clear) */
511 pac7311_reg_write(gspca_dev->dev, 0x11, 0x01); 500 reg_w(gspca_dev, 0x11, 0x01);
512 } 501 }
513} 502}
514 503
@@ -623,11 +612,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
623 612
624static void getbrightness(struct gspca_dev *gspca_dev) 613static void getbrightness(struct gspca_dev *gspca_dev)
625{ 614{
626/* __u8 brightness = 0; 615/* sd->brightness = reg_r(gspca_dev, 0x08);
627 616 return sd->brightness; */
628 pac7311_reg_read(gspca_dev->dev, 0x0008, &brightness);
629 spca50x->brightness = brightness;
630 return spca50x->brightness; */
631/* PDEBUG(D_CONF, "Called pac7311_getbrightness: Not implemented yet"); */ 617/* PDEBUG(D_CONF, "Called pac7311_getbrightness: Not implemented yet"); */
632} 618}
633 619
diff --git a/drivers/media/video/gspca/sonixb.c b/drivers/media/video/gspca/sonixb.c
index 5d2313198807..ce8b28f504d3 100644
--- a/drivers/media/video/gspca/sonixb.c
+++ b/drivers/media/video/gspca/sonixb.c
@@ -384,64 +384,82 @@ static const __u8 tas5130_sensor_init[][8] = {
384 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10}, 384 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10},
385}; 385};
386 386
387static void reg_r(struct usb_device *dev, 387/* get one byte in gspca_dev->usb_buf */
388 __u16 value, __u8 *buffer) 388static void reg_r(struct gspca_dev *gspca_dev,
389 __u16 value)
389{ 390{
390 usb_control_msg(dev, 391 usb_control_msg(gspca_dev->dev,
391 usb_rcvctrlpipe(dev, 0), 392 usb_rcvctrlpipe(gspca_dev->dev, 0),
392 0, /* request */ 393 0, /* request */
393 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 394 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
394 value, 395 value,
395 0, /* index */ 396 0, /* index */
396 buffer, 1, 397 gspca_dev->usb_buf, 1,
397 500); 398 500);
398} 399}
399 400
400static void reg_w(struct usb_device *dev, 401static void reg_w(struct gspca_dev *gspca_dev,
401 __u16 value, 402 __u16 value,
402 const __u8 *buffer, 403 const __u8 *buffer,
403 int len) 404 int len)
404{ 405{
405 __u8 tmpbuf[48];
406
407#ifdef CONFIG_VIDEO_ADV_DEBUG 406#ifdef CONFIG_VIDEO_ADV_DEBUG
408 if (len > sizeof tmpbuf) { 407 if (len > sizeof gspca_dev->usb_buf) {
409 PDEBUG(D_ERR|D_PACK, "reg_w: buffer overflow"); 408 PDEBUG(D_ERR|D_PACK, "reg_w: buffer overflow");
410 return; 409 return;
411 } 410 }
412#endif 411#endif
412 memcpy(gspca_dev->usb_buf, buffer, len);
413 usb_control_msg(gspca_dev->dev,
414 usb_sndctrlpipe(gspca_dev->dev, 0),
415 0x08, /* request */
416 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
417 value,
418 0, /* index */
419 gspca_dev->usb_buf, len,
420 500);
421}
422
423static void reg_w_big(struct gspca_dev *gspca_dev,
424 __u16 value,
425 const __u8 *buffer,
426 int len)
427{
428 __u8 *tmpbuf;
429
430 tmpbuf = kmalloc(len, GFP_KERNEL);
413 memcpy(tmpbuf, buffer, len); 431 memcpy(tmpbuf, buffer, len);
414 usb_control_msg(dev, 432 usb_control_msg(gspca_dev->dev,
415 usb_sndctrlpipe(dev, 0), 433 usb_sndctrlpipe(gspca_dev->dev, 0),
416 0x08, /* request */ 434 0x08, /* request */
417 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 435 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
418 value, 436 value,
419 0, /* index */ 437 0, /* index */
420 tmpbuf, len, 438 tmpbuf, len,
421 500); 439 500);
440 kfree(tmpbuf);
422} 441}
423 442
424static int i2c_w(struct usb_device *dev, const __u8 *buffer) 443static int i2c_w(struct gspca_dev *gspca_dev, const __u8 *buffer)
425{ 444{
426 int retry = 60; 445 int retry = 60;
427 __u8 ByteReceive;
428 446
429 /* is i2c ready */ 447 /* is i2c ready */
430 reg_w(dev, 0x08, buffer, 8); 448 reg_w(gspca_dev, 0x08, buffer, 8);
431 while (retry--) { 449 while (retry--) {
432 msleep(10); 450 msleep(10);
433 reg_r(dev, 0x08, &ByteReceive); 451 reg_r(gspca_dev, 0x08);
434 if (ByteReceive == 4) 452 if (gspca_dev->usb_buf[0] == 4)
435 return 0; 453 return 0;
436 } 454 }
437 return -1; 455 return -1;
438} 456}
439 457
440static void i2c_w_vector(struct usb_device *dev, 458static void i2c_w_vector(struct gspca_dev *gspca_dev,
441 const __u8 buffer[][8], int len) 459 const __u8 buffer[][8], int len)
442{ 460{
443 for (;;) { 461 for (;;) {
444 reg_w(dev, 0x08, *buffer, 8); 462 reg_w(gspca_dev, 0x08, *buffer, 8);
445 len -= 8; 463 len -= 8;
446 if (len <= 0) 464 if (len <= 0)
447 break; 465 break;
@@ -460,7 +478,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
460 {0xa0, 0x60, 0x06, 0x11, 0x99, 0x04, 0x94, 0x15}; 478 {0xa0, 0x60, 0x06, 0x11, 0x99, 0x04, 0x94, 0x15};
461 479
462 i2cOV6650[3] = sd->brightness; 480 i2cOV6650[3] = sd->brightness;
463 if (i2c_w(gspca_dev->dev, i2cOV6650) < 0) 481 if (i2c_w(gspca_dev, i2cOV6650) < 0)
464 goto err; 482 goto err;
465 break; 483 break;
466 } 484 }
@@ -470,7 +488,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
470 488
471 /* change reg 0x06 */ 489 /* change reg 0x06 */
472 i2cOV[3] = sd->brightness; 490 i2cOV[3] = sd->brightness;
473 if (i2c_w(gspca_dev->dev, i2cOV) < 0) 491 if (i2c_w(gspca_dev, i2cOV) < 0)
474 goto err; 492 goto err;
475 break; 493 break;
476 } 494 }
@@ -480,11 +498,11 @@ static void setbrightness(struct gspca_dev *gspca_dev)
480 498
481 i2c1[3] = sd->brightness >> 3; 499 i2c1[3] = sd->brightness >> 3;
482 i2c1[2] = 0x0e; 500 i2c1[2] = 0x0e;
483 if (i2c_w(gspca_dev->dev, i2c1) < 0) 501 if (i2c_w(gspca_dev, i2c1) < 0)
484 goto err; 502 goto err;
485 i2c1[3] = 0x01; 503 i2c1[3] = 0x01;
486 i2c1[2] = 0x13; 504 i2c1[2] = 0x13;
487 if (i2c_w(gspca_dev->dev, i2c1) < 0) 505 if (i2c_w(gspca_dev, i2c1) < 0)
488 goto err; 506 goto err;
489 break; 507 break;
490 } 508 }
@@ -500,18 +518,18 @@ static void setbrightness(struct gspca_dev *gspca_dev)
500 518
501 /* change reg 0x10 */ 519 /* change reg 0x10 */
502 i2cpexpo[4] = 0xff - sd->brightness; 520 i2cpexpo[4] = 0xff - sd->brightness;
503/* if(i2c_w(gspca_dev->dev,i2cpexpo1) < 0) 521/* if(i2c_w(gspca_dev,i2cpexpo1) < 0)
504 goto err; */ 522 goto err; */
505/* if(i2c_w(gspca_dev->dev,i2cpdoit) < 0) 523/* if(i2c_w(gspca_dev,i2cpdoit) < 0)
506 goto err; */ 524 goto err; */
507 if (i2c_w(gspca_dev->dev, i2cpexpo) < 0) 525 if (i2c_w(gspca_dev, i2cpexpo) < 0)
508 goto err; 526 goto err;
509 if (i2c_w(gspca_dev->dev, i2cpdoit) < 0) 527 if (i2c_w(gspca_dev, i2cpdoit) < 0)
510 goto err; 528 goto err;
511 i2cp202[3] = sd->brightness >> 3; 529 i2cp202[3] = sd->brightness >> 3;
512 if (i2c_w(gspca_dev->dev, i2cp202) < 0) 530 if (i2c_w(gspca_dev, i2cp202) < 0)
513 goto err; 531 goto err;
514 if (i2c_w(gspca_dev->dev, i2cpdoit) < 0) 532 if (i2c_w(gspca_dev, i2cpdoit) < 0)
515 goto err; 533 goto err;
516 break; 534 break;
517 } 535 }
@@ -522,7 +540,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
522 value = 0xff - sd->brightness; 540 value = 0xff - sd->brightness;
523 i2c[4] = value; 541 i2c[4] = value;
524 PDEBUG(D_CONF, "brightness %d : %d", value, i2c[4]); 542 PDEBUG(D_CONF, "brightness %d : %d", value, i2c[4]);
525 if (i2c_w(gspca_dev->dev, i2c) < 0) 543 if (i2c_w(gspca_dev, i2c) < 0)
526 goto err; 544 goto err;
527 break; 545 break;
528 } 546 }
@@ -551,14 +569,14 @@ static void setsensorgain(struct gspca_dev *gspca_dev)
551 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10}; 569 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
552 570
553 i2c[4] = 255 - gain; 571 i2c[4] = 255 - gain;
554 if (i2c_w(gspca_dev->dev, i2c) < 0) 572 if (i2c_w(gspca_dev, i2c) < 0)
555 goto err; 573 goto err;
556 break; 574 break;
557 } 575 }
558 case SENSOR_OV6650: { 576 case SENSOR_OV6650: {
559 __u8 i2c[] = {0xa0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}; 577 __u8 i2c[] = {0xa0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
560 i2c[3] = gain; 578 i2c[3] = gain;
561 if (i2c_w(gspca_dev->dev, i2c) < 0) 579 if (i2c_w(gspca_dev, i2c) < 0)
562 goto err; 580 goto err;
563 break; 581 break;
564 } 582 }
@@ -578,10 +596,10 @@ static void setgain(struct gspca_dev *gspca_dev)
578 596
579 /* red and blue gain */ 597 /* red and blue gain */
580 rgb_value = gain << 4 | gain; 598 rgb_value = gain << 4 | gain;
581 reg_w(gspca_dev->dev, 0x10, &rgb_value, 1); 599 reg_w(gspca_dev, 0x10, &rgb_value, 1);
582 /* green gain */ 600 /* green gain */
583 rgb_value = gain; 601 rgb_value = gain;
584 reg_w(gspca_dev->dev, 0x11, &rgb_value, 1); 602 reg_w(gspca_dev, 0x11, &rgb_value, 1);
585 603
586 if (sd->sensor_has_gain) 604 if (sd->sensor_has_gain)
587 setsensorgain(gspca_dev); 605 setsensorgain(gspca_dev);
@@ -604,7 +622,7 @@ static void setexposure(struct gspca_dev *gspca_dev)
604 if (reg > 15) 622 if (reg > 15)
605 reg = 15; 623 reg = 15;
606 reg = (reg << 4) | 0x0b; 624 reg = (reg << 4) | 0x0b;
607 reg_w(gspca_dev->dev, 0x19, &reg, 1); 625 reg_w(gspca_dev, 0x19, &reg, 1);
608 break; 626 break;
609 } 627 }
610 case SENSOR_OV6650: { 628 case SENSOR_OV6650: {
@@ -613,7 +631,7 @@ static void setexposure(struct gspca_dev *gspca_dev)
613 if (i2c[3] > 15) 631 if (i2c[3] > 15)
614 i2c[3] = 15; 632 i2c[3] = 15;
615 i2c[3] |= 0xc0; 633 i2c[3] |= 0xc0;
616 if (i2c_w(gspca_dev->dev, i2c) < 0) 634 if (i2c_w(gspca_dev, i2c) < 0)
617 PDEBUG(D_ERR, "i2c error exposure"); 635 PDEBUG(D_ERR, "i2c error exposure");
618 break; 636 break;
619 } 637 }
@@ -721,22 +739,20 @@ static int sd_config(struct gspca_dev *gspca_dev,
721 sd->exposure = EXPOSURE_DEF; 739 sd->exposure = EXPOSURE_DEF;
722 sd->autogain = AUTOGAIN_DEF; 740 sd->autogain = AUTOGAIN_DEF;
723 if (sd->sensor == SENSOR_OV7630_3) /* jfm: from win trace */ 741 if (sd->sensor == SENSOR_OV7630_3) /* jfm: from win trace */
724 reg_w(gspca_dev->dev, 0x01, probe_ov7630, sizeof probe_ov7630); 742 reg_w(gspca_dev, 0x01, probe_ov7630, sizeof probe_ov7630);
725 return 0; 743 return 0;
726} 744}
727 745
728/* this function is called at open time */ 746/* this function is called at open time */
729static int sd_open(struct gspca_dev *gspca_dev) 747static int sd_open(struct gspca_dev *gspca_dev)
730{ 748{
731 __u8 ByteReceive; 749 reg_r(gspca_dev, 0x00);
732 750 if (gspca_dev->usb_buf[0] != 0x10)
733 reg_r(gspca_dev->dev, 0x00, &ByteReceive);
734 if (ByteReceive != 0x10)
735 return -ENODEV; 751 return -ENODEV;
736 return 0; 752 return 0;
737} 753}
738 754
739static void pas106_i2cinit(struct usb_device *dev) 755static void pas106_i2cinit(struct gspca_dev *gspca_dev)
740{ 756{
741 int i; 757 int i;
742 const __u8 *data; 758 const __u8 *data;
@@ -747,7 +763,7 @@ static void pas106_i2cinit(struct usb_device *dev)
747 while (--i >= 0) { 763 while (--i >= 0) {
748 memcpy(&i2c1[2], data, 2); 764 memcpy(&i2c1[2], data, 2);
749 /* copy 2 bytes from the template */ 765 /* copy 2 bytes from the template */
750 if (i2c_w(dev, i2c1) < 0) 766 if (i2c_w(gspca_dev, i2c1) < 0)
751 PDEBUG(D_ERR, "i2c error pas106"); 767 PDEBUG(D_ERR, "i2c error pas106");
752 data += 2; 768 data += 2;
753 } 769 }
@@ -757,7 +773,6 @@ static void pas106_i2cinit(struct usb_device *dev)
757static void sd_start(struct gspca_dev *gspca_dev) 773static void sd_start(struct gspca_dev *gspca_dev)
758{ 774{
759 struct sd *sd = (struct sd *) gspca_dev; 775 struct sd *sd = (struct sd *) gspca_dev;
760 struct usb_device *dev = gspca_dev->dev;
761 int mode, l; 776 int mode, l;
762 const __u8 *sn9c10x; 777 const __u8 *sn9c10x;
763 __u8 reg01, reg17; 778 __u8 reg01, reg17;
@@ -835,75 +850,75 @@ static void sd_start(struct gspca_dev *gspca_dev)
835 } 850 }
836 851
837 /* reg 0x01 bit 2 video transfert on */ 852 /* reg 0x01 bit 2 video transfert on */
838 reg_w(dev, 0x01, &reg01, 1); 853 reg_w(gspca_dev, 0x01, &reg01, 1);
839 /* reg 0x17 SensorClk enable inv Clk 0x60 */ 854 /* reg 0x17 SensorClk enable inv Clk 0x60 */
840 reg_w(dev, 0x17, &reg17, 1); 855 reg_w(gspca_dev, 0x17, &reg17, 1);
841/*fixme: for ov7630 102 856/*fixme: for ov7630 102
842 reg_w(dev, 0x01, {0x06, sn9c10x[1]}, 2); */ 857 reg_w(gspca_dev, 0x01, {0x06, sn9c10x[1]}, 2); */
843 /* Set the registers from the template */ 858 /* Set the registers from the template */
844 reg_w(dev, 0x01, sn9c10x, l); 859 reg_w_big(gspca_dev, 0x01, sn9c10x, l);
845 switch (sd->sensor) { 860 switch (sd->sensor) {
846 case SENSOR_HV7131R: 861 case SENSOR_HV7131R:
847 i2c_w_vector(dev, hv7131_sensor_init, 862 i2c_w_vector(gspca_dev, hv7131_sensor_init,
848 sizeof hv7131_sensor_init); 863 sizeof hv7131_sensor_init);
849 break; 864 break;
850 case SENSOR_OV6650: 865 case SENSOR_OV6650:
851 i2c_w_vector(dev, ov6650_sensor_init, 866 i2c_w_vector(gspca_dev, ov6650_sensor_init,
852 sizeof ov6650_sensor_init); 867 sizeof ov6650_sensor_init);
853 break; 868 break;
854 case SENSOR_OV7630: 869 case SENSOR_OV7630:
855 i2c_w_vector(dev, ov7630_sensor_init_com, 870 i2c_w_vector(gspca_dev, ov7630_sensor_init_com,
856 sizeof ov7630_sensor_init_com); 871 sizeof ov7630_sensor_init_com);
857 msleep(200); 872 msleep(200);
858 i2c_w_vector(dev, ov7630_sensor_init, 873 i2c_w_vector(gspca_dev, ov7630_sensor_init,
859 sizeof ov7630_sensor_init); 874 sizeof ov7630_sensor_init);
860 break; 875 break;
861 case SENSOR_OV7630_3: 876 case SENSOR_OV7630_3:
862 i2c_w_vector(dev, ov7630_sensor_init_com, 877 i2c_w_vector(gspca_dev, ov7630_sensor_init_com,
863 sizeof ov7630_sensor_init_com); 878 sizeof ov7630_sensor_init_com);
864 msleep(200); 879 msleep(200);
865 i2c_w_vector(dev, ov7630_sensor_init_3, 880 i2c_w_vector(gspca_dev, ov7630_sensor_init_3,
866 sizeof ov7630_sensor_init_3); 881 sizeof ov7630_sensor_init_3);
867 break; 882 break;
868 case SENSOR_PAS106: 883 case SENSOR_PAS106:
869 pas106_i2cinit(dev); 884 pas106_i2cinit(gspca_dev);
870 break; 885 break;
871 case SENSOR_PAS202: 886 case SENSOR_PAS202:
872 i2c_w_vector(dev, pas202_sensor_init, 887 i2c_w_vector(gspca_dev, pas202_sensor_init,
873 sizeof pas202_sensor_init); 888 sizeof pas202_sensor_init);
874 break; 889 break;
875 case SENSOR_TAS5110: 890 case SENSOR_TAS5110:
876 i2c_w_vector(dev, tas5110_sensor_init, 891 i2c_w_vector(gspca_dev, tas5110_sensor_init,
877 sizeof tas5110_sensor_init); 892 sizeof tas5110_sensor_init);
878 break; 893 break;
879 default: 894 default:
880/* case SENSOR_TAS5130CXX: */ 895/* case SENSOR_TAS5130CXX: */
881 i2c_w_vector(dev, tas5130_sensor_init, 896 i2c_w_vector(gspca_dev, tas5130_sensor_init,
882 sizeof tas5130_sensor_init); 897 sizeof tas5130_sensor_init);
883 break; 898 break;
884 } 899 }
885 /* H_size V_size 0x28, 0x1e maybe 640x480 */ 900 /* H_size V_size 0x28, 0x1e maybe 640x480 */
886 reg_w(dev, 0x15, reg15, 2); 901 reg_w(gspca_dev, 0x15, reg15, 2);
887 /* compression register */ 902 /* compression register */
888 reg_w(dev, 0x18, &reg17_19[1], 1); 903 reg_w(gspca_dev, 0x18, &reg17_19[1], 1);
889 if (sd->sensor != SENSOR_OV7630_3) { 904 if (sd->sensor != SENSOR_OV7630_3) {
890 /* H_start */ 905 /* H_start */
891 reg_w(dev, 0x12, &sn9c10x[0x12 - 1], 1); 906 reg_w(gspca_dev, 0x12, &sn9c10x[0x12 - 1], 1);
892 /* V_START */ 907 /* V_START */
893 reg_w(dev, 0x13, &sn9c10x[0x13 - 1], 1); 908 reg_w(gspca_dev, 0x13, &sn9c10x[0x13 - 1], 1);
894 } 909 }
895 /* reset 0x17 SensorClk enable inv Clk 0x60 */ 910 /* reset 0x17 SensorClk enable inv Clk 0x60 */
896 /*fixme: ov7630 [17]=68 8f (+20 if 102)*/ 911 /*fixme: ov7630 [17]=68 8f (+20 if 102)*/
897 reg_w(dev, 0x17, &reg17_19[0], 1); 912 reg_w(gspca_dev, 0x17, &reg17_19[0], 1);
898 /*MCKSIZE ->3 */ /*fixme: not ov7630*/ 913 /*MCKSIZE ->3 */ /*fixme: not ov7630*/
899 if (sd->sensor != SENSOR_OV7630_3) 914 if (sd->sensor != SENSOR_OV7630_3)
900 reg_w(dev, 0x19, &reg17_19[2], 1); 915 reg_w(gspca_dev, 0x19, &reg17_19[2], 1);
901 /* AE_STRX AE_STRY AE_ENDX AE_ENDY */ 916 /* AE_STRX AE_STRY AE_ENDX AE_ENDY */
902 reg_w(dev, 0x1c, &sn9c10x[0x1c - 1], 4); 917 reg_w(gspca_dev, 0x1c, &sn9c10x[0x1c - 1], 4);
903 /* Enable video transfert */ 918 /* Enable video transfert */
904 reg_w(dev, 0x01, &sn9c10x[0], 1); 919 reg_w(gspca_dev, 0x01, &sn9c10x[0], 1);
905 /* Compression */ 920 /* Compression */
906 reg_w(dev, 0x18, &reg17_19[1], 2); 921 reg_w(gspca_dev, 0x18, &reg17_19[1], 2);
907 msleep(20); 922 msleep(20);
908 923
909 setgain(gspca_dev); 924 setgain(gspca_dev);
@@ -919,7 +934,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
919 __u8 ByteSend; 934 __u8 ByteSend;
920 935
921 ByteSend = 0x09; /* 0X00 */ 936 ByteSend = 0x09; /* 0X00 */
922 reg_w(gspca_dev->dev, 0x01, &ByteSend, 1); 937 reg_w(gspca_dev, 0x01, &ByteSend, 1);
923} 938}
924 939
925static void sd_stop0(struct gspca_dev *gspca_dev) 940static void sd_stop0(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c
index 4cb1421b8807..30e840dca481 100644
--- a/drivers/media/video/gspca/sonixj.c
+++ b/drivers/media/video/gspca/sonixj.c
@@ -24,8 +24,8 @@
24#include "gspca.h" 24#include "gspca.h"
25#include "jpeg.h" 25#include "jpeg.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.5"; 28static const char version[] = "2.1.7";
29 29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver"); 31MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
@@ -512,42 +512,40 @@ static const __u8 qtable4[] = {
512 0x29, 0x29, 0x29, 0x29 512 0x29, 0x29, 0x29, 0x29
513}; 513};
514 514
515static void reg_r(struct usb_device *dev, 515/* read <len> bytes (len < sizeof gspca_dev->usb_buf) to gspca_dev->usb_buf */
516 __u16 value, 516static void reg_r(struct gspca_dev *gspca_dev,
517 __u8 *buffer, int len) 517 __u16 value, int len)
518{ 518{
519 usb_control_msg(dev, 519 usb_control_msg(gspca_dev->dev,
520 usb_rcvctrlpipe(dev, 0), 520 usb_rcvctrlpipe(gspca_dev->dev, 0),
521 0, 521 0,
522 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 522 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
523 value, 0, 523 value, 0,
524 buffer, len, 524 gspca_dev->usb_buf, len,
525 500); 525 500);
526} 526}
527 527
528static void reg_w(struct usb_device *dev, 528static void reg_w(struct gspca_dev *gspca_dev,
529 __u16 value, 529 __u16 value,
530 const __u8 *buffer, 530 const __u8 *buffer,
531 int len) 531 int len)
532{ 532{
533 if (len < 16) { 533 if (len <= sizeof gspca_dev->usb_buf) {
534 __u8 tmpbuf[16]; 534 memcpy(gspca_dev->usb_buf, buffer, len);
535 535 usb_control_msg(gspca_dev->dev,
536 memcpy(tmpbuf, buffer, len); 536 usb_sndctrlpipe(gspca_dev->dev, 0),
537 usb_control_msg(dev,
538 usb_sndctrlpipe(dev, 0),
539 0x08, 537 0x08,
540 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 538 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
541 value, 0, 539 value, 0,
542 tmpbuf, len, 540 gspca_dev->usb_buf, len,
543 500); 541 500);
544 } else { 542 } else {
545 __u8 *tmpbuf; 543 __u8 *tmpbuf;
546 544
547 tmpbuf = kmalloc(len, GFP_KERNEL); 545 tmpbuf = kmalloc(len, GFP_KERNEL);
548 memcpy(tmpbuf, buffer, len); 546 memcpy(tmpbuf, buffer, len);
549 usb_control_msg(dev, 547 usb_control_msg(gspca_dev->dev,
550 usb_sndctrlpipe(dev, 0), 548 usb_sndctrlpipe(gspca_dev->dev, 0),
551 0x08, 549 0x08,
552 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 550 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
553 value, 0, 551 value, 0,
@@ -557,12 +555,11 @@ static void reg_w(struct usb_device *dev,
557 } 555 }
558} 556}
559 557
560/* write 2 bytes */ 558/* I2C write 2 bytes */
561static void i2c_w2(struct gspca_dev *gspca_dev, 559static void i2c_w2(struct gspca_dev *gspca_dev,
562 const __u8 *buffer) 560 const __u8 *buffer)
563{ 561{
564 struct sd *sd = (struct sd *) gspca_dev; 562 struct sd *sd = (struct sd *) gspca_dev;
565 struct usb_device *dev = gspca_dev->dev;
566 __u8 mode[8]; 563 __u8 mode[8];
567 564
568 /* is i2c ready */ 565 /* is i2c ready */
@@ -574,22 +571,21 @@ static void i2c_w2(struct gspca_dev *gspca_dev,
574 mode[5] = 0; 571 mode[5] = 0;
575 mode[6] = 0; 572 mode[6] = 0;
576 mode[7] = 0x10; 573 mode[7] = 0x10;
577 reg_w(dev, 0x08, mode, 8); 574 reg_w(gspca_dev, 0x08, mode, 8);
578} 575}
579 576
580/* write 8 bytes */ 577/* I2C write 8 bytes */
581static void i2c_w8(struct usb_device *dev, const __u8 *buffer) 578static void i2c_w8(struct gspca_dev *gspca_dev,
579 const __u8 *buffer)
582{ 580{
583 reg_w(dev, 0x08, buffer, 8); 581 reg_w(gspca_dev, 0x08, buffer, 8);
584 msleep(1); 582 msleep(1);
585} 583}
586 584
587/* read 5 bytes */ 585/* read 5 bytes in gspca_dev->usb_buf */
588static void i2c_r5(struct gspca_dev *gspca_dev, __u8 reg, 586static void i2c_r5(struct gspca_dev *gspca_dev, __u8 reg)
589 __u8 *buffer)
590{ 587{
591 struct sd *sd = (struct sd *) gspca_dev; 588 struct sd *sd = (struct sd *) gspca_dev;
592 struct usb_device *dev = gspca_dev->dev;
593 __u8 mode[8]; 589 __u8 mode[8];
594 590
595 mode[0] = sd->i2c_ctrl_reg | 0x10; 591 mode[0] = sd->i2c_ctrl_reg | 0x10;
@@ -600,40 +596,39 @@ static void i2c_r5(struct gspca_dev *gspca_dev, __u8 reg,
600 mode[5] = 0; 596 mode[5] = 0;
601 mode[6] = 0; 597 mode[6] = 0;
602 mode[7] = 0x10; 598 mode[7] = 0x10;
603 i2c_w8(dev, mode); 599 i2c_w8(gspca_dev, mode);
604 mode[0] = sd->i2c_ctrl_reg | (5 << 4) | 0x02; 600 mode[0] = sd->i2c_ctrl_reg | (5 << 4) | 0x02;
605 mode[2] = 0; 601 mode[2] = 0;
606 i2c_w8(dev, mode); 602 i2c_w8(gspca_dev, mode);
607 reg_r(dev, 0x0a, buffer, 5); 603 reg_r(gspca_dev, 0x0a, 5);
608} 604}
609 605
610static int probesensor(struct gspca_dev *gspca_dev) 606static int probesensor(struct gspca_dev *gspca_dev)
611{ 607{
612 struct sd *sd = (struct sd *) gspca_dev; 608 struct sd *sd = (struct sd *) gspca_dev;
613 struct usb_device *dev = gspca_dev->dev;
614 __u8 reg02; 609 __u8 reg02;
615 static const __u8 datasend[] = { 2, 0 }; 610 static const __u8 datasend[] = { 2, 0 };
616 /* reg val1 val2 val3 val4 */ 611 /* reg val1 val2 val3 val4 */
617 __u8 datarecd[6];
618 612
619 i2c_w2(gspca_dev, datasend); 613 i2c_w2(gspca_dev, datasend);
620/* should write 0xa1 0x11 0x02 0x00 0x00 0x00 0x00 the 0x10 is add by i2cw */ 614/* should write 0xa1 0x11 0x02 0x00 0x00 0x00 0x00 the 0x10 is add by i2cw */
621 msleep(10); 615 msleep(10);
622 reg02 = 0x66; 616 reg02 = 0x66;
623 reg_w(dev, 0x02, &reg02, 1); /* Gpio on */ 617 reg_w(gspca_dev, 0x02, &reg02, 1); /* Gpio on */
624 msleep(10); 618 msleep(10);
625 i2c_r5(gspca_dev, 0, datarecd); /* read sensor id */ 619 i2c_r5(gspca_dev, 0); /* read sensor id */
626 if (datarecd[0] == 0x02 620 if (gspca_dev->usb_buf[0] == 0x02
627 && datarecd[1] == 0x09 621 && gspca_dev->usb_buf[1] == 0x09
628 && datarecd[2] == 0x01 622 && gspca_dev->usb_buf[2] == 0x01
629 && datarecd[3] == 0x00 623 && gspca_dev->usb_buf[3] == 0x00
630 && datarecd[4] == 0x00) { 624 && gspca_dev->usb_buf[4] == 0x00) {
631 PDEBUG(D_PROBE, "Find Sensor sn9c102P HV7131R"); 625 PDEBUG(D_PROBE, "Find Sensor sn9c102P HV7131R");
632 sd->sensor = SENSOR_HV7131R; 626 sd->sensor = SENSOR_HV7131R;
633 return SENSOR_HV7131R; 627 return SENSOR_HV7131R;
634 } 628 }
635 PDEBUG(D_PROBE, "Find Sensor %d %d %d", 629 PDEBUG(D_PROBE, "Find Sensor %d %d %d",
636 datarecd[0], datarecd[1], datarecd[2]); 630 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
631 gspca_dev->usb_buf[2]);
637 PDEBUG(D_PROBE, "Sensor sn9c102P Not found"); 632 PDEBUG(D_PROBE, "Sensor sn9c102P Not found");
638 return -ENODEV; 633 return -ENODEV;
639} 634}
@@ -642,7 +637,6 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
642 const __u8 *sn9c1xx) 637 const __u8 *sn9c1xx)
643{ 638{
644 struct sd *sd = (struct sd *) gspca_dev; 639 struct sd *sd = (struct sd *) gspca_dev;
645 struct usb_device *dev = gspca_dev->dev;
646 __u8 data; 640 __u8 data;
647 __u8 regF1; 641 __u8 regF1;
648 const __u8 *reg9a; 642 const __u8 *reg9a;
@@ -655,14 +649,15 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
655 649
656 650
657 regF1 = 0x00; 651 regF1 = 0x00;
658 reg_w(dev, 0xf1, &regF1, 1); 652 reg_w(gspca_dev, 0xf1, &regF1, 1);
659 653
660 reg_w(dev, 0x01, &sn9c1xx[0], 1); /*fixme:jfm was [1] en v1*/ 654 reg_w(gspca_dev, 0x01, &sn9c1xx[0], 1);
655 /*fixme:jfm was [1] en v1*/
661 656
662 /* configure gpio */ 657 /* configure gpio */
663 reg_w(dev, 0x01, &sn9c1xx[1], 2); 658 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
664 reg_w(dev, 0x08, &sn9c1xx[8], 2); 659 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
665 reg_w(dev, 0x17, &sn9c1xx[0x17], 3); 660 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 3);
666 switch (sd->customid) { 661 switch (sd->customid) {
667 case SN9C325: 662 case SN9C325:
668 reg9a = reg9a_sn9c325; 663 reg9a = reg9a_sn9c325;
@@ -674,37 +669,37 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
674 reg9a = reg9a_def; 669 reg9a = reg9a_def;
675 break; 670 break;
676 } 671 }
677 reg_w(dev, 0x9a, reg9a, 6); 672 reg_w(gspca_dev, 0x9a, reg9a, 6);
678 673
679 data = 0x60; /*fixme:jfm 60 00 00 (3) */ 674 data = 0x60; /*fixme:jfm 60 00 00 (3) */
680 reg_w(dev, 0xd4, &data, 1); 675 reg_w(gspca_dev, 0xd4, &data, 1);
681 676
682 reg_w(dev, 0x03, &sn9c1xx[3], 0x0f); 677 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
683 678
684 switch (sd->customid) { 679 switch (sd->customid) {
685 case SN9C120: /* from win trace */ 680 case SN9C120: /* from win trace */
686 data = 0x61; 681 data = 0x61;
687 reg_w(dev, 0x01, &data, 1); 682 reg_w(gspca_dev, 0x01, &data, 1);
688 data = 0x20; 683 data = 0x20;
689 reg_w(dev, 0x17, &data, 1); 684 reg_w(gspca_dev, 0x17, &data, 1);
690 data = 0x60; 685 data = 0x60;
691 reg_w(dev, 0x01, &data, 1); 686 reg_w(gspca_dev, 0x01, &data, 1);
692 break; 687 break;
693 case SN9C325: 688 case SN9C325:
694 data = 0x43; 689 data = 0x43;
695 reg_w(dev, 0x01, &data, 1); 690 reg_w(gspca_dev, 0x01, &data, 1);
696 data = 0xae; 691 data = 0xae;
697 reg_w(dev, 0x17, &data, 1); 692 reg_w(gspca_dev, 0x17, &data, 1);
698 data = 0x42; 693 data = 0x42;
699 reg_w(dev, 0x01, &data, 1); 694 reg_w(gspca_dev, 0x01, &data, 1);
700 break; 695 break;
701 default: 696 default:
702 data = 0x43; 697 data = 0x43;
703 reg_w(dev, 0x01, &data, 1); 698 reg_w(gspca_dev, 0x01, &data, 1);
704 data = 0x61; 699 data = 0x61;
705 reg_w(dev, 0x17, &data, 1); 700 reg_w(gspca_dev, 0x17, &data, 1);
706 data = 0x42; 701 data = 0x42;
707 reg_w(dev, 0x01, &data, 1); 702 reg_w(gspca_dev, 0x01, &data, 1);
708 } 703 }
709 704
710 if (sd->sensor == SENSOR_HV7131R) { 705 if (sd->sensor == SENSOR_HV7131R) {
@@ -717,24 +712,22 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
717static void hv7131R_InitSensor(struct gspca_dev *gspca_dev) 712static void hv7131R_InitSensor(struct gspca_dev *gspca_dev)
718{ 713{
719 int i = 0; 714 int i = 0;
720 struct usb_device *dev = gspca_dev->dev;
721 static const __u8 SetSensorClk[] = /* 0x08 Mclk */ 715 static const __u8 SetSensorClk[] = /* 0x08 Mclk */
722 { 0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 }; 716 { 0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 };
723 717
724 while (hv7131r_sensor_init[i][0]) { 718 while (hv7131r_sensor_init[i][0]) {
725 i2c_w8(dev, hv7131r_sensor_init[i]); 719 i2c_w8(gspca_dev, hv7131r_sensor_init[i]);
726 i++; 720 i++;
727 } 721 }
728 i2c_w8(dev, SetSensorClk); 722 i2c_w8(gspca_dev, SetSensorClk);
729} 723}
730 724
731static void mi0360_InitSensor(struct gspca_dev *gspca_dev) 725static void mi0360_InitSensor(struct gspca_dev *gspca_dev)
732{ 726{
733 int i = 0; 727 int i = 0;
734 struct usb_device *dev = gspca_dev->dev;
735 728
736 while (mi0360_sensor_init[i][0]) { 729 while (mi0360_sensor_init[i][0]) {
737 i2c_w8(dev, mi0360_sensor_init[i]); 730 i2c_w8(gspca_dev, mi0360_sensor_init[i]);
738 i++; 731 i++;
739 } 732 }
740} 733}
@@ -742,21 +735,19 @@ static void mi0360_InitSensor(struct gspca_dev *gspca_dev)
742static void mo4000_InitSensor(struct gspca_dev *gspca_dev) 735static void mo4000_InitSensor(struct gspca_dev *gspca_dev)
743{ 736{
744 int i = 0; 737 int i = 0;
745 struct usb_device *dev = gspca_dev->dev;
746 738
747 while (mo4000_sensor_init[i][0]) { 739 while (mo4000_sensor_init[i][0]) {
748 i2c_w8(dev, mo4000_sensor_init[i]); 740 i2c_w8(gspca_dev, mo4000_sensor_init[i]);
749 i++; 741 i++;
750 } 742 }
751} 743}
752 744
753static void ov7648_InitSensor(struct gspca_dev *gspca_dev) 745static void ov7648_InitSensor(struct gspca_dev *gspca_dev)
754{ 746{
755 struct usb_device *dev = gspca_dev->dev;
756 int i = 0; 747 int i = 0;
757 748
758 while (ov7648_sensor_init[i][0]) { 749 while (ov7648_sensor_init[i][0]) {
759 i2c_w8(dev, ov7648_sensor_init[i]); 750 i2c_w8(gspca_dev, ov7648_sensor_init[i]);
760 i++; 751 i++;
761 } 752 }
762} 753}
@@ -764,10 +755,9 @@ static void ov7648_InitSensor(struct gspca_dev *gspca_dev)
764static void ov7660_InitSensor(struct gspca_dev *gspca_dev) 755static void ov7660_InitSensor(struct gspca_dev *gspca_dev)
765{ 756{
766 int i = 0; 757 int i = 0;
767 struct usb_device *dev = gspca_dev->dev;
768 758
769 while (ov7660_sensor_init[i][0]) { 759 while (ov7660_sensor_init[i][0]) {
770 i2c_w8(dev, ov7660_sensor_init[i]); 760 i2c_w8(gspca_dev, ov7660_sensor_init[i]);
771 i++; 761 i++;
772 } 762 }
773} 763}
@@ -1005,51 +995,52 @@ static int sd_config(struct gspca_dev *gspca_dev,
1005static int sd_open(struct gspca_dev *gspca_dev) 995static int sd_open(struct gspca_dev *gspca_dev)
1006{ 996{
1007 struct sd *sd = (struct sd *) gspca_dev; 997 struct sd *sd = (struct sd *) gspca_dev;
1008 struct usb_device *dev = gspca_dev->dev;
1009/* const __u8 *sn9c1xx; */ 998/* const __u8 *sn9c1xx; */
1010 __u8 regF1; 999 __u8 regF1;
1011 __u8 regGpio[] = { 0x29, 0x74 }; 1000 __u8 regGpio[] = { 0x29, 0x74 };
1012 1001
1013 /* setup a selector by customid */ 1002 /* setup a selector by customid */
1014 regF1 = 0x01; 1003 regF1 = 0x01;
1015 reg_w(dev, 0xf1, &regF1, 1); 1004 reg_w(gspca_dev, 0xf1, &regF1, 1);
1016 reg_r(dev, 0x00, &regF1, 1); /* -> regF1 = 0x00 */ 1005 reg_r(gspca_dev, 0x00, 1); /* -> regF1 = 0x00 */
1017 reg_w(dev, 0xf1, &regF1, 1); 1006 regF1 = gspca_dev->usb_buf[0];
1018 reg_r(dev, 0x00, &regF1, 1); 1007 reg_w(gspca_dev, 0xf1, &regF1, 1);
1008 reg_r(gspca_dev, 0x00, 1);
1009 regF1 = gspca_dev->usb_buf[0];
1019 switch (sd->customid) { 1010 switch (sd->customid) {
1020 case SN9C102P: 1011 case SN9C102P:
1021 if (regF1 != 0x11) 1012 if (regF1 != 0x11)
1022 return -ENODEV; 1013 return -ENODEV;
1023 reg_w(dev, 0x02, &regGpio[1], 1); 1014 reg_w(gspca_dev, 0x02, &regGpio[1], 1);
1024 break; 1015 break;
1025 case SN9C105: 1016 case SN9C105:
1026 if (regF1 != 0x11) 1017 if (regF1 != 0x11)
1027 return -ENODEV; 1018 return -ENODEV;
1028 reg_w(dev, 0x02, regGpio, 2); 1019 reg_w(gspca_dev, 0x02, regGpio, 2);
1029 break; 1020 break;
1030 case SN9C110: 1021 case SN9C110:
1031 if (regF1 != 0x12) 1022 if (regF1 != 0x12)
1032 return -ENODEV; 1023 return -ENODEV;
1033 regGpio[1] = 0x62; 1024 regGpio[1] = 0x62;
1034 reg_w(dev, 0x02, &regGpio[1], 1); 1025 reg_w(gspca_dev, 0x02, &regGpio[1], 1);
1035 break; 1026 break;
1036 case SN9C120: 1027 case SN9C120:
1037 if (regF1 != 0x12) 1028 if (regF1 != 0x12)
1038 return -ENODEV; 1029 return -ENODEV;
1039 regGpio[1] = 0x70; 1030 regGpio[1] = 0x70;
1040 reg_w(dev, 0x02, regGpio, 2); 1031 reg_w(gspca_dev, 0x02, regGpio, 2);
1041 break; 1032 break;
1042 default: 1033 default:
1043/* case SN9C325: */ 1034/* case SN9C325: */
1044 if (regF1 != 0x12) 1035 if (regF1 != 0x12)
1045 return -ENODEV; 1036 return -ENODEV;
1046 regGpio[1] = 0x62; 1037 regGpio[1] = 0x62;
1047 reg_w(dev, 0x02, &regGpio[1], 1); 1038 reg_w(gspca_dev, 0x02, &regGpio[1], 1);
1048 break; 1039 break;
1049 } 1040 }
1050 1041
1051 regF1 = 0x01; 1042 regF1 = 0x01;
1052 reg_w(dev, 0xf1, &regF1, 1); 1043 reg_w(gspca_dev, 0xf1, &regF1, 1);
1053 1044
1054 return 0; 1045 return 0;
1055} 1046}
@@ -1073,7 +1064,7 @@ static unsigned int setexposure(struct gspca_dev *gspca_dev,
1073 Expodoit[3] = expo >> 16; 1064 Expodoit[3] = expo >> 16;
1074 Expodoit[4] = expo >> 8; 1065 Expodoit[4] = expo >> 8;
1075 Expodoit[5] = expo; 1066 Expodoit[5] = expo;
1076 i2c_w8(gspca_dev->dev, Expodoit); 1067 i2c_w8(gspca_dev, Expodoit);
1077 break; 1068 break;
1078 } 1069 }
1079 case SENSOR_MI0360: { 1070 case SENSOR_MI0360: {
@@ -1086,9 +1077,9 @@ static unsigned int setexposure(struct gspca_dev *gspca_dev,
1086 expo = 0x0001; 1077 expo = 0x0001;
1087 expoMi[3] = expo >> 8; 1078 expoMi[3] = expo >> 8;
1088 expoMi[4] = expo; 1079 expoMi[4] = expo;
1089 i2c_w8(gspca_dev->dev, expoMi); 1080 i2c_w8(gspca_dev, expoMi);
1090 i2c_w8(gspca_dev->dev, doit); 1081 i2c_w8(gspca_dev, doit);
1091 i2c_w8(gspca_dev->dev, sensorgo); 1082 i2c_w8(gspca_dev, sensorgo);
1092 break; 1083 break;
1093 } 1084 }
1094 case SENSOR_MO4000: { 1085 case SENSOR_MO4000: {
@@ -1102,11 +1093,11 @@ static unsigned int setexposure(struct gspca_dev *gspca_dev,
1102 else if (expo < 0x0001) 1093 else if (expo < 0x0001)
1103 expo = 0x0001; 1094 expo = 0x0001;
1104 expoMof[3] = (expo & 0x03fc) >> 2; 1095 expoMof[3] = (expo & 0x03fc) >> 2;
1105 i2c_w8(gspca_dev->dev, expoMof); 1096 i2c_w8(gspca_dev, expoMof);
1106 expoMo10[3] = ((expo & 0x1c00) >> 10) 1097 expoMo10[3] = ((expo & 0x1c00) >> 10)
1107 | ((expo & 0x0003) << 4); 1098 | ((expo & 0x0003) << 4);
1108 i2c_w8(gspca_dev->dev, expoMo10); 1099 i2c_w8(gspca_dev, expoMo10);
1109 i2c_w8(gspca_dev->dev, gainMo); 1100 i2c_w8(gspca_dev, gainMo);
1110 PDEBUG(D_CONF, "set exposure %d", 1101 PDEBUG(D_CONF, "set exposure %d",
1111 ((expoMo10[3] & 0x07) << 10) 1102 ((expoMo10[3] & 0x07) << 10)
1112 | (expoMof[3] << 2) 1103 | (expoMof[3] << 2)
@@ -1145,7 +1136,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1145 } 1136 }
1146 1137
1147 k2 = sd->brightness >> 10; 1138 k2 = sd->brightness >> 10;
1148 reg_w(gspca_dev->dev, 0x96, &k2, 1); 1139 reg_w(gspca_dev, 0x96, &k2, 1);
1149} 1140}
1150 1141
1151static void setcontrast(struct gspca_dev *gspca_dev) 1142static void setcontrast(struct gspca_dev *gspca_dev)
@@ -1160,7 +1151,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
1160 contrast[2] = k2; 1151 contrast[2] = k2;
1161 contrast[0] = (k2 + 1) >> 1; 1152 contrast[0] = (k2 + 1) >> 1;
1162 contrast[4] = (k2 + 1) / 5; 1153 contrast[4] = (k2 + 1) / 5;
1163 reg_w(gspca_dev->dev, 0x84, contrast, 6); 1154 reg_w(gspca_dev, 0x84, contrast, 6);
1164} 1155}
1165 1156
1166static void setcolors(struct gspca_dev *gspca_dev) 1157static void setcolors(struct gspca_dev *gspca_dev)
@@ -1174,14 +1165,13 @@ static void setcolors(struct gspca_dev *gspca_dev)
1174 data = (colour + 32) & 0x7f; /* blue */ 1165 data = (colour + 32) & 0x7f; /* blue */
1175 else 1166 else
1176 data = (-colour + 32) & 0x7f; /* red */ 1167 data = (-colour + 32) & 0x7f; /* red */
1177 reg_w(gspca_dev->dev, 0x05, &data, 1); 1168 reg_w(gspca_dev, 0x05, &data, 1);
1178} 1169}
1179 1170
1180/* -- start the camera -- */ 1171/* -- start the camera -- */
1181static void sd_start(struct gspca_dev *gspca_dev) 1172static void sd_start(struct gspca_dev *gspca_dev)
1182{ 1173{
1183 struct sd *sd = (struct sd *) gspca_dev; 1174 struct sd *sd = (struct sd *) gspca_dev;
1184 struct usb_device *dev = gspca_dev->dev;
1185 int i; 1175 int i;
1186 __u8 data; 1176 __u8 data;
1187 __u8 reg1; 1177 __u8 reg1;
@@ -1203,45 +1193,45 @@ static void sd_start(struct gspca_dev *gspca_dev)
1203/*fixme:jfm this sequence should appear at end of sd_start */ 1193/*fixme:jfm this sequence should appear at end of sd_start */
1204/* with 1194/* with
1205 data = 0x44; 1195 data = 0x44;
1206 reg_w(dev, 0x01, &data, 1); */ 1196 reg_w(gspca_dev, 0x01, &data, 1); */
1207 reg_w(dev, 0x15, &sn9c1xx[0x15], 1); 1197 reg_w(gspca_dev, 0x15, &sn9c1xx[0x15], 1);
1208 reg_w(dev, 0x16, &sn9c1xx[0x16], 1); 1198 reg_w(gspca_dev, 0x16, &sn9c1xx[0x16], 1);
1209 reg_w(dev, 0x12, &sn9c1xx[0x12], 1); 1199 reg_w(gspca_dev, 0x12, &sn9c1xx[0x12], 1);
1210 reg_w(dev, 0x13, &sn9c1xx[0x13], 1); 1200 reg_w(gspca_dev, 0x13, &sn9c1xx[0x13], 1);
1211 reg_w(dev, 0x18, &sn9c1xx[0x18], 1); 1201 reg_w(gspca_dev, 0x18, &sn9c1xx[0x18], 1);
1212 reg_w(dev, 0xd2, &DC29[0], 1); 1202 reg_w(gspca_dev, 0xd2, &DC29[0], 1);
1213 reg_w(dev, 0xd3, &DC29[1], 1); 1203 reg_w(gspca_dev, 0xd3, &DC29[1], 1);
1214 reg_w(dev, 0xc6, &DC29[2], 1); 1204 reg_w(gspca_dev, 0xc6, &DC29[2], 1);
1215 reg_w(dev, 0xc7, &DC29[3], 1); 1205 reg_w(gspca_dev, 0xc7, &DC29[3], 1);
1216 reg_w(dev, 0xc8, &DC29[4], 1); 1206 reg_w(gspca_dev, 0xc8, &DC29[4], 1);
1217 reg_w(dev, 0xc9, &DC29[5], 1); 1207 reg_w(gspca_dev, 0xc9, &DC29[5], 1);
1218/*fixme:jfm end of ending sequence */ 1208/*fixme:jfm end of ending sequence */
1219 reg_w(dev, 0x18, &sn9c1xx[0x18], 1); 1209 reg_w(gspca_dev, 0x18, &sn9c1xx[0x18], 1);
1220 if (sd->customid == SN9C325) 1210 if (sd->customid == SN9C325)
1221 data = 0xae; 1211 data = 0xae;
1222 else 1212 else
1223 data = 0x60; 1213 data = 0x60;
1224 reg_w(dev, 0x17, &data, 1); 1214 reg_w(gspca_dev, 0x17, &data, 1);
1225 reg_w(dev, 0x05, &sn9c1xx[5], 1); 1215 reg_w(gspca_dev, 0x05, &sn9c1xx[5], 1);
1226 reg_w(dev, 0x07, &sn9c1xx[7], 1); 1216 reg_w(gspca_dev, 0x07, &sn9c1xx[7], 1);
1227 reg_w(dev, 0x06, &sn9c1xx[6], 1); 1217 reg_w(gspca_dev, 0x06, &sn9c1xx[6], 1);
1228 reg_w(dev, 0x14, &sn9c1xx[0x14], 1); 1218 reg_w(gspca_dev, 0x14, &sn9c1xx[0x14], 1);
1229 if (sd->customid == SN9C325) { 1219 if (sd->customid == SN9C325) {
1230 reg_w(dev, 0x20, regsn20_sn9c325, 0x11); 1220 reg_w(gspca_dev, 0x20, regsn20_sn9c325, 0x11);
1231 for (i = 0; i < 8; i++) 1221 for (i = 0; i < 8; i++)
1232 reg_w(dev, 0x84, reg84_sn9c325, 0x15); 1222 reg_w(gspca_dev, 0x84, reg84_sn9c325, 0x15);
1233 data = 0x0a; 1223 data = 0x0a;
1234 reg_w(dev, 0x9a, &data, 1); 1224 reg_w(gspca_dev, 0x9a, &data, 1);
1235 data = 0x60; 1225 data = 0x60;
1236 reg_w(dev, 0x99, &data, 1); 1226 reg_w(gspca_dev, 0x99, &data, 1);
1237 } else { 1227 } else {
1238 reg_w(dev, 0x20, regsn20, 0x11); 1228 reg_w(gspca_dev, 0x20, regsn20, 0x11);
1239 for (i = 0; i < 8; i++) 1229 for (i = 0; i < 8; i++)
1240 reg_w(dev, 0x84, reg84, 0x15); 1230 reg_w(gspca_dev, 0x84, reg84, 0x15);
1241 data = 0x08; 1231 data = 0x08;
1242 reg_w(dev, 0x9a, &data, 1); 1232 reg_w(gspca_dev, 0x9a, &data, 1);
1243 data = 0x59; 1233 data = 0x59;
1244 reg_w(dev, 0x99, &data, 1); 1234 reg_w(gspca_dev, 0x99, &data, 1);
1245 } 1235 }
1246 1236
1247 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 1237 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
@@ -1294,38 +1284,38 @@ static void sd_start(struct gspca_dev *gspca_dev)
1294 } 1284 }
1295 break; 1285 break;
1296 } 1286 }
1297 reg_w(dev, 0xc0, C0, 6); 1287 reg_w(gspca_dev, 0xc0, C0, 6);
1298 switch (sd->customid) { 1288 switch (sd->customid) {
1299 case SN9C120: /*jfm ?? */ 1289 case SN9C120: /*jfm ?? */
1300 reg_w(dev, 0xca, CA_sn9c120, 4); 1290 reg_w(gspca_dev, 0xca, CA_sn9c120, 4);
1301 break; 1291 break;
1302 default: 1292 default:
1303 reg_w(dev, 0xca, CA, 4); 1293 reg_w(gspca_dev, 0xca, CA, 4);
1304 break; 1294 break;
1305 } 1295 }
1306 switch (sd->customid) { 1296 switch (sd->customid) {
1307 case SN9C120: /*jfm ?? */ 1297 case SN9C120: /*jfm ?? */
1308 case SN9C325: 1298 case SN9C325:
1309 reg_w(dev, 0xce, CE_sn9c325, 4); 1299 reg_w(gspca_dev, 0xce, CE_sn9c325, 4);
1310 break; 1300 break;
1311 default: 1301 default:
1312 reg_w(dev, 0xce, CE, 4); 1302 reg_w(gspca_dev, 0xce, CE, 4);
1313 /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */ 1303 /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
1314 break; 1304 break;
1315 } 1305 }
1316 1306
1317 /* here change size mode 0 -> VGA; 1 -> CIF */ 1307 /* here change size mode 0 -> VGA; 1 -> CIF */
1318 data = 0x40 | sn9c1xx[0x18] | (mode << 4); 1308 data = 0x40 | sn9c1xx[0x18] | (mode << 4);
1319 reg_w(dev, 0x18, &data, 1); 1309 reg_w(gspca_dev, 0x18, &data, 1);
1320 1310
1321 reg_w(dev, 0x100, qtable4, 0x40); 1311 reg_w(gspca_dev, 0x100, qtable4, 0x40);
1322 reg_w(dev, 0x140, qtable4 + 0x40, 0x40); 1312 reg_w(gspca_dev, 0x140, qtable4 + 0x40, 0x40);
1323 1313
1324 data = sn9c1xx[0x18] | (mode << 4); 1314 data = sn9c1xx[0x18] | (mode << 4);
1325 reg_w(dev, 0x18, &data, 1); 1315 reg_w(gspca_dev, 0x18, &data, 1);
1326 1316
1327 reg_w(dev, 0x17, &reg17, 1); 1317 reg_w(gspca_dev, 0x17, &reg17, 1);
1328 reg_w(dev, 0x01, &reg1, 1); 1318 reg_w(gspca_dev, 0x01, &reg1, 1);
1329 setbrightness(gspca_dev); 1319 setbrightness(gspca_dev);
1330 setcontrast(gspca_dev); 1320 setcontrast(gspca_dev);
1331} 1321}
@@ -1333,7 +1323,6 @@ static void sd_start(struct gspca_dev *gspca_dev)
1333static void sd_stopN(struct gspca_dev *gspca_dev) 1323static void sd_stopN(struct gspca_dev *gspca_dev)
1334{ 1324{
1335 struct sd *sd = (struct sd *) gspca_dev; 1325 struct sd *sd = (struct sd *) gspca_dev;
1336 struct usb_device *dev = gspca_dev->dev;
1337 static const __u8 stophv7131[] = 1326 static const __u8 stophv7131[] =
1338 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 }; 1327 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
1339 static const __u8 stopmi0360[] = 1328 static const __u8 stopmi0360[] =
@@ -1345,11 +1334,11 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1345 data = 0x0b; 1334 data = 0x0b;
1346 switch (sd->sensor) { 1335 switch (sd->sensor) {
1347 case SENSOR_HV7131R: 1336 case SENSOR_HV7131R:
1348 i2c_w8(dev, stophv7131); 1337 i2c_w8(gspca_dev, stophv7131);
1349 data = 0x2b; 1338 data = 0x2b;
1350 break; 1339 break;
1351 case SENSOR_MI0360: 1340 case SENSOR_MI0360:
1352 i2c_w8(dev, stopmi0360); 1341 i2c_w8(gspca_dev, stopmi0360);
1353 data = 0x29; 1342 data = 0x29;
1354 break; 1343 break;
1355 case SENSOR_MO4000: 1344 case SENSOR_MO4000:
@@ -1362,12 +1351,12 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1362 break; 1351 break;
1363 } 1352 }
1364 sn9c1xx = sn_tb[(int) sd->sensor]; 1353 sn9c1xx = sn_tb[(int) sd->sensor];
1365 reg_w(dev, 0x01, &sn9c1xx[1], 1); 1354 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 1);
1366 reg_w(dev, 0x17, &sn9c1xx[0x17], 1); 1355 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 1);
1367 reg_w(dev, 0x01, &sn9c1xx[1], 1); 1356 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 1);
1368 reg_w(dev, 0x01, &data, 1); 1357 reg_w(gspca_dev, 0x01, &data, 1);
1369 regF1 = 0x01; 1358 regF1 = 0x01;
1370 reg_w(dev, 0xf1, &regF1, 1); 1359 reg_w(gspca_dev, 0xf1, &regF1, 1);
1371} 1360}
1372 1361
1373static void sd_stop0(struct gspca_dev *gspca_dev) 1362static void sd_stop0(struct gspca_dev *gspca_dev)
@@ -1463,33 +1452,35 @@ static unsigned int getexposure(struct gspca_dev *gspca_dev)
1463{ 1452{
1464 struct sd *sd = (struct sd *) gspca_dev; 1453 struct sd *sd = (struct sd *) gspca_dev;
1465 __u8 hexpo, mexpo, lexpo; 1454 __u8 hexpo, mexpo, lexpo;
1466 __u8 expo[6];
1467 1455
1468 switch (sd->sensor) { 1456 switch (sd->sensor) {
1469 case SENSOR_HV7131R: 1457 case SENSOR_HV7131R:
1470 /* read sensor exposure */ 1458 /* read sensor exposure */
1471 i2c_r5(gspca_dev, 0x25, expo); 1459 i2c_r5(gspca_dev, 0x25);
1472 return (expo[0] << 16) | (expo[1] << 8) | expo[2]; 1460 return (gspca_dev->usb_buf[0] << 16)
1461 | (gspca_dev->usb_buf[1] << 8)
1462 | gspca_dev->usb_buf[2];
1473 case SENSOR_MI0360: 1463 case SENSOR_MI0360:
1474 /* read sensor exposure */ 1464 /* read sensor exposure */
1475 i2c_r5(gspca_dev, 0x09, expo); 1465 i2c_r5(gspca_dev, 0x09);
1476 return (expo[0] << 8) | expo[1]; 1466 return (gspca_dev->usb_buf[0] << 8)
1467 | gspca_dev->usb_buf[1];
1477 case SENSOR_MO4000: 1468 case SENSOR_MO4000:
1478 i2c_r5(gspca_dev, 0x0e, expo); 1469 i2c_r5(gspca_dev, 0x0e);
1479 hexpo = 0; /* expo[1] & 0x07; */ 1470 hexpo = 0; /* gspca_dev->usb_buf[1] & 0x07; */
1480 mexpo = 0x40; /* expo[2] &0xff; */ 1471 mexpo = 0x40; /* gspca_dev->usb_buf[2] & 0xff; */
1481 lexpo = (expo[1] & 0x30) >> 4; 1472 lexpo = (gspca_dev->usb_buf[1] & 0x30) >> 4;
1482 PDEBUG(D_CONF, "exposure %d", 1473 PDEBUG(D_CONF, "exposure %d",
1483 (hexpo << 10) | (mexpo << 2) | lexpo); 1474 (hexpo << 10) | (mexpo << 2) | lexpo);
1484 return (hexpo << 10) | (mexpo << 2) | lexpo; 1475 return (hexpo << 10) | (mexpo << 2) | lexpo;
1485 default: 1476 default:
1486/* case SENSOR_OV7660: */ 1477/* case SENSOR_OV7660: */
1487 /* read sensor exposure */ 1478 /* read sensor exposure */
1488 i2c_r5(gspca_dev, 0x04, expo); 1479 i2c_r5(gspca_dev, 0x04);
1489 hexpo = expo[3] & 0x2f; 1480 hexpo = gspca_dev->usb_buf[3] & 0x2f;
1490 lexpo = expo[0] & 0x02; 1481 lexpo = gspca_dev->usb_buf[0] & 0x02;
1491 i2c_r5(gspca_dev, 0x08, expo); 1482 i2c_r5(gspca_dev, 0x08);
1492 mexpo = expo[2]; 1483 mexpo = gspca_dev->usb_buf[2];
1493 return (hexpo << 10) | (mexpo << 2) | lexpo; 1484 return (hexpo << 10) | (mexpo << 2) | lexpo;
1494 } 1485 }
1495} 1486}
diff --git a/drivers/media/video/gspca/spca500.c b/drivers/media/video/gspca/spca500.c
index d00f0f76e0e3..156206118795 100644
--- a/drivers/media/video/gspca/spca500.c
+++ b/drivers/media/video/gspca/spca500.c
@@ -24,8 +24,8 @@
24#include "gspca.h" 24#include "gspca.h"
25#include "jpeg.h" 25#include "jpeg.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.5"; 28static const char version[] = "2.1.7";
29 29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/SPCA500 USB Camera Driver"); 31MODULE_DESCRIPTION("GSPCA/SPCA500 USB Camera Driver");
@@ -372,26 +372,27 @@ static const __u8 qtable_pocketdv[2][64] = {
372 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28} 372 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28}
373}; 373};
374 374
375static void reg_r(struct usb_device *dev, 375/* read 'len' bytes to gspca_dev->usb_buf */
376 __u16 index, 376static void reg_r(struct gspca_dev *gspca_dev,
377 __u8 *buffer, __u16 length) 377 __u16 index,
378 __u16 length)
378{ 379{
379 usb_control_msg(dev, 380 usb_control_msg(gspca_dev->dev,
380 usb_rcvctrlpipe(dev, 0), 381 usb_rcvctrlpipe(gspca_dev->dev, 0),
381 0, 382 0,
382 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 383 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
383 0, /* value */ 384 0, /* value */
384 index, buffer, length, 500); 385 index, gspca_dev->usb_buf, length, 500);
385} 386}
386 387
387static int reg_w(struct usb_device *dev, 388static int reg_w(struct gspca_dev *gspca_dev,
388 __u16 req, __u16 index, __u16 value) 389 __u16 req, __u16 index, __u16 value)
389{ 390{
390 int ret; 391 int ret;
391 392
392 PDEBUG(D_USBO, "reg write: [0x%02x] = 0x%02x", index, value); 393 PDEBUG(D_USBO, "reg write: [0x%02x] = 0x%02x", index, value);
393 ret = usb_control_msg(dev, 394 ret = usb_control_msg(gspca_dev->dev,
394 usb_sndctrlpipe(dev, 0), 395 usb_sndctrlpipe(gspca_dev->dev, 0),
395 req, 396 req,
396 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 397 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
397 value, index, NULL, 0, 500); 398 value, index, NULL, 0, 500);
@@ -401,28 +402,27 @@ static int reg_w(struct usb_device *dev,
401} 402}
402 403
403/* returns: negative is error, pos or zero is data */ 404/* returns: negative is error, pos or zero is data */
404static int reg_r_12(struct usb_device *dev, 405static int reg_r_12(struct gspca_dev *gspca_dev,
405 __u16 req, /* bRequest */ 406 __u16 req, /* bRequest */
406 __u16 index, /* wIndex */ 407 __u16 index, /* wIndex */
407 __u16 length) /* wLength (1 or 2 only) */ 408 __u16 length) /* wLength (1 or 2 only) */
408{ 409{
409 int ret; 410 int ret;
410 __u8 buf[2];
411 411
412 buf[1] = 0; 412 gspca_dev->usb_buf[1] = 0;
413 ret = usb_control_msg(dev, 413 ret = usb_control_msg(gspca_dev->dev,
414 usb_rcvctrlpipe(dev, 0), 414 usb_rcvctrlpipe(gspca_dev->dev, 0),
415 req, 415 req,
416 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 416 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
417 0, /* value */ 417 0, /* value */
418 index, 418 index,
419 buf, length, 419 gspca_dev->usb_buf, length,
420 500); /* timeout */ 420 500); /* timeout */
421 if (ret < 0) { 421 if (ret < 0) {
422 PDEBUG(D_ERR, "reg_r_12 err %d", ret); 422 PDEBUG(D_ERR, "reg_r_12 err %d", ret);
423 return -1; 423 return -1;
424 } 424 }
425 return (buf[1] << 8) + buf[0]; 425 return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
426} 426}
427 427
428/* 428/*
@@ -430,13 +430,13 @@ static int reg_r_12(struct usb_device *dev,
430 * a reg_read call. 430 * a reg_read call.
431 * Returns: negative is error or timeout, zero is success. 431 * Returns: negative is error or timeout, zero is success.
432 */ 432 */
433static int reg_r_wait(struct usb_device *dev, 433static int reg_r_wait(struct gspca_dev *gspca_dev,
434 __u16 reg, __u16 index, __u16 value) 434 __u16 reg, __u16 index, __u16 value)
435{ 435{
436 int ret, cnt = 20; 436 int ret, cnt = 20;
437 437
438 while (--cnt > 0) { 438 while (--cnt > 0) {
439 ret = reg_r_12(dev, reg, index, 1); 439 ret = reg_r_12(gspca_dev, reg, index, 1);
440 if (ret == value) 440 if (ret == value)
441 return 0; 441 return 0;
442 msleep(50); 442 msleep(50);
@@ -447,11 +447,10 @@ static int reg_r_wait(struct usb_device *dev,
447static int write_vector(struct gspca_dev *gspca_dev, 447static int write_vector(struct gspca_dev *gspca_dev,
448 const __u16 data[][3]) 448 const __u16 data[][3])
449{ 449{
450 struct usb_device *dev = gspca_dev->dev;
451 int ret, i = 0; 450 int ret, i = 0;
452 451
453 while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) { 452 while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
454 ret = reg_w(dev, data[i][0], data[i][2], data[i][1]); 453 ret = reg_w(gspca_dev, data[i][0], data[i][2], data[i][1]);
455 if (ret < 0) 454 if (ret < 0)
456 return ret; 455 return ret;
457 i++; 456 i++;
@@ -465,19 +464,18 @@ static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
465 unsigned int cbase, 464 unsigned int cbase,
466 const __u8 qtable[2][64]) 465 const __u8 qtable[2][64])
467{ 466{
468 struct usb_device *dev = gspca_dev->dev;
469 int i, err; 467 int i, err;
470 468
471 /* loop over y components */ 469 /* loop over y components */
472 for (i = 0; i < 64; i++) { 470 for (i = 0; i < 64; i++) {
473 err = reg_w(dev, request, ybase + i, qtable[0][i]); 471 err = reg_w(gspca_dev, request, ybase + i, qtable[0][i]);
474 if (err < 0) 472 if (err < 0)
475 return err; 473 return err;
476 } 474 }
477 475
478 /* loop over c components */ 476 /* loop over c components */
479 for (i = 0; i < 64; i++) { 477 for (i = 0; i < 64; i++) {
480 err = reg_w(dev, request, cbase + i, qtable[1][i]); 478 err = reg_w(gspca_dev, request, cbase + i, qtable[1][i]);
481 if (err < 0) 479 if (err < 0)
482 return err; 480 return err;
483 } 481 }
@@ -486,37 +484,33 @@ static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
486 484
487static void spca500_ping310(struct gspca_dev *gspca_dev) 485static void spca500_ping310(struct gspca_dev *gspca_dev)
488{ 486{
489 __u8 Data[2]; 487 reg_r(gspca_dev, 0x0d04, 2);
490
491 reg_r(gspca_dev->dev, 0x0d04, Data, 2);
492 PDEBUG(D_STREAM, "ClickSmart310 ping 0x0d04 0x%02x 0x%02x", 488 PDEBUG(D_STREAM, "ClickSmart310 ping 0x0d04 0x%02x 0x%02x",
493 Data[0], Data[1]); 489 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
494} 490}
495 491
496static void spca500_clksmart310_init(struct gspca_dev *gspca_dev) 492static void spca500_clksmart310_init(struct gspca_dev *gspca_dev)
497{ 493{
498 __u8 Data[2]; 494 reg_r(gspca_dev, 0x0d05, 2);
499
500 reg_r(gspca_dev->dev, 0x0d05, Data, 2);
501 PDEBUG(D_STREAM, "ClickSmart310 init 0x0d05 0x%02x 0x%02x", 495 PDEBUG(D_STREAM, "ClickSmart310 init 0x0d05 0x%02x 0x%02x",
502 Data[0], Data[1]); 496 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
503 reg_w(gspca_dev->dev, 0x00, 0x8167, 0x5a); 497 reg_w(gspca_dev, 0x00, 0x8167, 0x5a);
504 spca500_ping310(gspca_dev); 498 spca500_ping310(gspca_dev);
505 499
506 reg_w(gspca_dev->dev, 0x00, 0x8168, 0x22); 500 reg_w(gspca_dev, 0x00, 0x8168, 0x22);
507 reg_w(gspca_dev->dev, 0x00, 0x816a, 0xc0); 501 reg_w(gspca_dev, 0x00, 0x816a, 0xc0);
508 reg_w(gspca_dev->dev, 0x00, 0x816b, 0x0b); 502 reg_w(gspca_dev, 0x00, 0x816b, 0x0b);
509 reg_w(gspca_dev->dev, 0x00, 0x8169, 0x25); 503 reg_w(gspca_dev, 0x00, 0x8169, 0x25);
510 reg_w(gspca_dev->dev, 0x00, 0x8157, 0x5b); 504 reg_w(gspca_dev, 0x00, 0x8157, 0x5b);
511 reg_w(gspca_dev->dev, 0x00, 0x8158, 0x5b); 505 reg_w(gspca_dev, 0x00, 0x8158, 0x5b);
512 reg_w(gspca_dev->dev, 0x00, 0x813f, 0x03); 506 reg_w(gspca_dev, 0x00, 0x813f, 0x03);
513 reg_w(gspca_dev->dev, 0x00, 0x8151, 0x4a); 507 reg_w(gspca_dev, 0x00, 0x8151, 0x4a);
514 reg_w(gspca_dev->dev, 0x00, 0x8153, 0x78); 508 reg_w(gspca_dev, 0x00, 0x8153, 0x78);
515 reg_w(gspca_dev->dev, 0x00, 0x0d01, 0x04); 509 reg_w(gspca_dev, 0x00, 0x0d01, 0x04);
516 /* 00 for adjust shutter */ 510 /* 00 for adjust shutter */
517 reg_w(gspca_dev->dev, 0x00, 0x0d02, 0x01); 511 reg_w(gspca_dev, 0x00, 0x0d02, 0x01);
518 reg_w(gspca_dev->dev, 0x00, 0x8169, 0x25); 512 reg_w(gspca_dev, 0x00, 0x8169, 0x25);
519 reg_w(gspca_dev->dev, 0x00, 0x0d01, 0x02); 513 reg_w(gspca_dev, 0x00, 0x0d01, 0x02);
520} 514}
521 515
522static void spca500_setmode(struct gspca_dev *gspca_dev, 516static void spca500_setmode(struct gspca_dev *gspca_dev,
@@ -525,14 +519,14 @@ static void spca500_setmode(struct gspca_dev *gspca_dev,
525 int mode; 519 int mode;
526 520
527 /* set x multiplier */ 521 /* set x multiplier */
528 reg_w(gspca_dev->dev, 0, 0x8001, xmult); 522 reg_w(gspca_dev, 0, 0x8001, xmult);
529 523
530 /* set y multiplier */ 524 /* set y multiplier */
531 reg_w(gspca_dev->dev, 0, 0x8002, ymult); 525 reg_w(gspca_dev, 0, 0x8002, ymult);
532 526
533 /* use compressed mode, VGA, with mode specific subsample */ 527 /* use compressed mode, VGA, with mode specific subsample */
534 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 528 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
535 reg_w(gspca_dev->dev, 0, 0x8003, mode << 4); 529 reg_w(gspca_dev, 0, 0x8003, mode << 4);
536} 530}
537 531
538static int spca500_full_reset(struct gspca_dev *gspca_dev) 532static int spca500_full_reset(struct gspca_dev *gspca_dev)
@@ -540,18 +534,18 @@ static int spca500_full_reset(struct gspca_dev *gspca_dev)
540 int err; 534 int err;
541 535
542 /* send the reset command */ 536 /* send the reset command */
543 err = reg_w(gspca_dev->dev, 0xe0, 0x0001, 0x0000); 537 err = reg_w(gspca_dev, 0xe0, 0x0001, 0x0000);
544 if (err < 0) 538 if (err < 0)
545 return err; 539 return err;
546 540
547 /* wait for the reset to complete */ 541 /* wait for the reset to complete */
548 err = reg_r_wait(gspca_dev->dev, 0x06, 0x0000, 0x0000); 542 err = reg_r_wait(gspca_dev, 0x06, 0x0000, 0x0000);
549 if (err < 0) 543 if (err < 0)
550 return err; 544 return err;
551 err = reg_w(gspca_dev->dev, 0xe0, 0x0000, 0x0000); 545 err = reg_w(gspca_dev, 0xe0, 0x0000, 0x0000);
552 if (err < 0) 546 if (err < 0)
553 return err; 547 return err;
554 err = reg_r_wait(gspca_dev->dev, 0x06, 0, 0); 548 err = reg_r_wait(gspca_dev, 0x06, 0, 0);
555 if (err < 0) { 549 if (err < 0) {
556 PDEBUG(D_ERR, "reg_r_wait() failed"); 550 PDEBUG(D_ERR, "reg_r_wait() failed");
557 return err; 551 return err;
@@ -568,15 +562,13 @@ static int spca500_full_reset(struct gspca_dev *gspca_dev)
568/* up-port the same feature as in 2.4.x kernel */ 562/* up-port the same feature as in 2.4.x kernel */
569static int spca500_synch310(struct gspca_dev *gspca_dev) 563static int spca500_synch310(struct gspca_dev *gspca_dev)
570{ 564{
571 __u8 Data;
572
573 if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0) < 0) { 565 if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0) < 0) {
574 PDEBUG(D_ERR, "Set packet size: set interface error"); 566 PDEBUG(D_ERR, "Set packet size: set interface error");
575 goto error; 567 goto error;
576 } 568 }
577 spca500_ping310(gspca_dev); 569 spca500_ping310(gspca_dev);
578 570
579 reg_r(gspca_dev->dev, 0x0d00, &Data, 1); 571 reg_r(gspca_dev, 0x0d00, 1);
580 572
581 /* need alt setting here */ 573 /* need alt setting here */
582 PDEBUG(D_PACK, "ClickSmart310 sync alt: %d", gspca_dev->alt); 574 PDEBUG(D_PACK, "ClickSmart310 sync alt: %d", gspca_dev->alt);
@@ -600,12 +592,12 @@ static void spca500_reinit(struct gspca_dev *gspca_dev)
600 592
601 /* some unknow command from Aiptek pocket dv and family300 */ 593 /* some unknow command from Aiptek pocket dv and family300 */
602 594
603 reg_w(gspca_dev->dev, 0x00, 0x0d01, 0x01); 595 reg_w(gspca_dev, 0x00, 0x0d01, 0x01);
604 reg_w(gspca_dev->dev, 0x00, 0x0d03, 0x00); 596 reg_w(gspca_dev, 0x00, 0x0d03, 0x00);
605 reg_w(gspca_dev->dev, 0x00, 0x0d02, 0x01); 597 reg_w(gspca_dev, 0x00, 0x0d02, 0x01);
606 598
607 /* enable drop packet */ 599 /* enable drop packet */
608 reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); 600 reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
609 601
610 err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840, 602 err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840,
611 qtable_pocketdv); 603 qtable_pocketdv);
@@ -613,22 +605,23 @@ static void spca500_reinit(struct gspca_dev *gspca_dev)
613 PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed on init"); 605 PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed on init");
614 606
615 /* set qtable index */ 607 /* set qtable index */
616 reg_w(gspca_dev->dev, 0x00, 0x8880, 2); 608 reg_w(gspca_dev, 0x00, 0x8880, 2);
617 /* family cam Quicksmart stuff */ 609 /* family cam Quicksmart stuff */
618 reg_w(gspca_dev->dev, 0x00, 0x800a, 0x00); 610 reg_w(gspca_dev, 0x00, 0x800a, 0x00);
619 /* Set agc transfer: synced inbetween frames */ 611 /* Set agc transfer: synced inbetween frames */
620 reg_w(gspca_dev->dev, 0x00, 0x820f, 0x01); 612 reg_w(gspca_dev, 0x00, 0x820f, 0x01);
621 /* Init SDRAM - needed for SDRAM access */ 613 /* Init SDRAM - needed for SDRAM access */
622 reg_w(gspca_dev->dev, 0x00, 0x870a, 0x04); 614 reg_w(gspca_dev, 0x00, 0x870a, 0x04);
623 /*Start init sequence or stream */ 615 /*Start init sequence or stream */
624 616 reg_w(gspca_dev, 0, 0x8003, 0x00);
625 reg_w(gspca_dev->dev, 0, 0x8003, 0x00);
626 /* switch to video camera mode */ 617 /* switch to video camera mode */
627 reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); 618 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
628 msleep(2000); 619 msleep(2000);
629 if (reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) 620 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) {
630 reg_r(gspca_dev->dev, 0x816b, &Data, 1); 621 reg_r(gspca_dev, 0x816b, 1);
631 reg_w(gspca_dev->dev, 0x00, 0x816b, Data); 622 Data = gspca_dev->usb_buf[0];
623 reg_w(gspca_dev, 0x00, 0x816b, Data);
624 }
632} 625}
633 626
634/* this function is called at probe time */ 627/* this function is called at probe time */
@@ -785,9 +778,10 @@ static void sd_start(struct gspca_dev *gspca_dev)
785 } 778 }
786 779
787 /* is there a sensor here ? */ 780 /* is there a sensor here ? */
788 reg_r(gspca_dev->dev, 0x8a04, &Data, 1); 781 reg_r(gspca_dev, 0x8a04, 1);
789 PDEBUG(D_STREAM, "Spca500 Sensor Address 0x%02X", Data); 782 PDEBUG(D_STREAM, "Spca500 Sensor Address 0x%02x",
790 PDEBUG(D_STREAM, "Spca500 curr_mode: %d Xmult: 0x%02X, Ymult: 0x%02X", 783 gspca_dev->usb_buf[0]);
784 PDEBUG(D_STREAM, "Spca500 curr_mode: %d Xmult: 0x%02x, Ymult: 0x%02x",
791 gspca_dev->curr_mode, xmult, ymult); 785 gspca_dev->curr_mode, xmult, ymult);
792 786
793 /* setup qtable */ 787 /* setup qtable */
@@ -796,33 +790,34 @@ static void sd_start(struct gspca_dev *gspca_dev)
796 spca500_setmode(gspca_dev, xmult, ymult); 790 spca500_setmode(gspca_dev, xmult, ymult);
797 791
798 /* enable drop packet */ 792 /* enable drop packet */
799 reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); 793 reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
800 reg_w(gspca_dev->dev, 0x00, 0x8880, 3); 794 reg_w(gspca_dev, 0x00, 0x8880, 3);
801 err = spca50x_setup_qtable(gspca_dev, 795 err = spca50x_setup_qtable(gspca_dev,
802 0x00, 0x8800, 0x8840, 796 0x00, 0x8800, 0x8840,
803 qtable_creative_pccam); 797 qtable_creative_pccam);
804 if (err < 0) 798 if (err < 0)
805 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 799 PDEBUG(D_ERR, "spca50x_setup_qtable failed");
806 /* Init SDRAM - needed for SDRAM access */ 800 /* Init SDRAM - needed for SDRAM access */
807 reg_w(gspca_dev->dev, 0x00, 0x870a, 0x04); 801 reg_w(gspca_dev, 0x00, 0x870a, 0x04);
808 802
809 /* switch to video camera mode */ 803 /* switch to video camera mode */
810 reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); 804 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
811 msleep(500); 805 msleep(500);
812 if (reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) 806 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
813 PDEBUG(D_ERR, "reg_r_wait() failed"); 807 PDEBUG(D_ERR, "reg_r_wait() failed");
814 808
815 reg_r(gspca_dev->dev, 0x816b, &Data, 1); 809 reg_r(gspca_dev, 0x816b, 1);
816 reg_w(gspca_dev->dev, 0x00, 0x816b, Data); 810 Data = gspca_dev->usb_buf[0];
811 reg_w(gspca_dev, 0x00, 0x816b, Data);
817 812
818 spca500_synch310(gspca_dev); 813 spca500_synch310(gspca_dev);
819 814
820 write_vector(gspca_dev, spca500_visual_defaults); 815 write_vector(gspca_dev, spca500_visual_defaults);
821 spca500_setmode(gspca_dev, xmult, ymult); 816 spca500_setmode(gspca_dev, xmult, ymult);
822 /* enable drop packet */ 817 /* enable drop packet */
823 reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); 818 reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
824 PDEBUG(D_ERR, "failed to enable drop packet"); 819 PDEBUG(D_ERR, "failed to enable drop packet");
825 reg_w(gspca_dev->dev, 0x00, 0x8880, 3); 820 reg_w(gspca_dev, 0x00, 0x8880, 3);
826 err = spca50x_setup_qtable(gspca_dev, 821 err = spca50x_setup_qtable(gspca_dev,
827 0x00, 0x8800, 0x8840, 822 0x00, 0x8800, 0x8840,
828 qtable_creative_pccam); 823 qtable_creative_pccam);
@@ -830,16 +825,17 @@ static void sd_start(struct gspca_dev *gspca_dev)
830 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 825 PDEBUG(D_ERR, "spca50x_setup_qtable failed");
831 826
832 /* Init SDRAM - needed for SDRAM access */ 827 /* Init SDRAM - needed for SDRAM access */
833 reg_w(gspca_dev->dev, 0x00, 0x870a, 0x04); 828 reg_w(gspca_dev, 0x00, 0x870a, 0x04);
834 829
835 /* switch to video camera mode */ 830 /* switch to video camera mode */
836 reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); 831 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
837 832
838 if (reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) 833 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
839 PDEBUG(D_ERR, "reg_r_wait() failed"); 834 PDEBUG(D_ERR, "reg_r_wait() failed");
840 835
841 reg_r(gspca_dev->dev, 0x816b, &Data, 1); 836 reg_r(gspca_dev, 0x816b, 1);
842 reg_w(gspca_dev->dev, 0x00, 0x816b, Data); 837 Data = gspca_dev->usb_buf[0];
838 reg_w(gspca_dev, 0x00, 0x816b, Data);
843 break; 839 break;
844 case CreativePCCam300: /* Creative PC-CAM 300 640x480 CCD */ 840 case CreativePCCam300: /* Creative PC-CAM 300 640x480 CCD */
845 case IntelPocketPCCamera: /* FIXME: Temporary fix for 841 case IntelPocketPCCamera: /* FIXME: Temporary fix for
@@ -852,10 +848,10 @@ static void sd_start(struct gspca_dev *gspca_dev)
852 PDEBUG(D_ERR, "spca500_full_reset failed"); 848 PDEBUG(D_ERR, "spca500_full_reset failed");
853 849
854 /* enable drop packet */ 850 /* enable drop packet */
855 err = reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); 851 err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
856 if (err < 0) 852 if (err < 0)
857 PDEBUG(D_ERR, "failed to enable drop packet"); 853 PDEBUG(D_ERR, "failed to enable drop packet");
858 reg_w(gspca_dev->dev, 0x00, 0x8880, 3); 854 reg_w(gspca_dev, 0x00, 0x8880, 3);
859 err = spca50x_setup_qtable(gspca_dev, 855 err = spca50x_setup_qtable(gspca_dev,
860 0x00, 0x8800, 0x8840, 856 0x00, 0x8800, 0x8840,
861 qtable_creative_pccam); 857 qtable_creative_pccam);
@@ -863,16 +859,17 @@ static void sd_start(struct gspca_dev *gspca_dev)
863 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 859 PDEBUG(D_ERR, "spca50x_setup_qtable failed");
864 860
865 spca500_setmode(gspca_dev, xmult, ymult); 861 spca500_setmode(gspca_dev, xmult, ymult);
866 reg_w(gspca_dev->dev, 0x20, 0x0001, 0x0004); 862 reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
867 863
868 /* switch to video camera mode */ 864 /* switch to video camera mode */
869 reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); 865 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
870 866
871 if (reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) 867 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
872 PDEBUG(D_ERR, "reg_r_wait() failed"); 868 PDEBUG(D_ERR, "reg_r_wait() failed");
873 869
874 reg_r(gspca_dev->dev, 0x816b, &Data, 1); 870 reg_r(gspca_dev, 0x816b, 1);
875 reg_w(gspca_dev->dev, 0x00, 0x816b, Data); 871 Data = gspca_dev->usb_buf[0];
872 reg_w(gspca_dev, 0x00, 0x816b, Data);
876 873
877/* write_vector(gspca_dev, spca500_visual_defaults); */ 874/* write_vector(gspca_dev, spca500_visual_defaults); */
878 break; 875 break;
@@ -883,8 +880,8 @@ static void sd_start(struct gspca_dev *gspca_dev)
883 if (err < 0) 880 if (err < 0)
884 PDEBUG(D_ERR, "spca500_full_reset failed"); 881 PDEBUG(D_ERR, "spca500_full_reset failed");
885 /* enable drop packet */ 882 /* enable drop packet */
886 reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); 883 reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
887 reg_w(gspca_dev->dev, 0x00, 0x8880, 0); 884 reg_w(gspca_dev, 0x00, 0x8880, 0);
888 err = spca50x_setup_qtable(gspca_dev, 885 err = spca50x_setup_qtable(gspca_dev,
889 0x00, 0x8800, 0x8840, 886 0x00, 0x8800, 0x8840,
890 qtable_kodak_ez200); 887 qtable_kodak_ez200);
@@ -892,16 +889,17 @@ static void sd_start(struct gspca_dev *gspca_dev)
892 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 889 PDEBUG(D_ERR, "spca50x_setup_qtable failed");
893 spca500_setmode(gspca_dev, xmult, ymult); 890 spca500_setmode(gspca_dev, xmult, ymult);
894 891
895 reg_w(gspca_dev->dev, 0x20, 0x0001, 0x0004); 892 reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
896 893
897 /* switch to video camera mode */ 894 /* switch to video camera mode */
898 reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); 895 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
899 896
900 if (reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) 897 if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
901 PDEBUG(D_ERR, "reg_r_wait() failed"); 898 PDEBUG(D_ERR, "reg_r_wait() failed");
902 899
903 reg_r(gspca_dev->dev, 0x816b, &Data, 1); 900 reg_r(gspca_dev, 0x816b, 1);
904 reg_w(gspca_dev->dev, 0x00, 0x816b, Data); 901 Data = gspca_dev->usb_buf[0];
902 reg_w(gspca_dev, 0x00, 0x816b, Data);
905 903
906/* write_vector(gspca_dev, spca500_visual_defaults); */ 904/* write_vector(gspca_dev, spca500_visual_defaults); */
907 break; 905 break;
@@ -916,56 +914,58 @@ static void sd_start(struct gspca_dev *gspca_dev)
916 case ToptroIndus: 914 case ToptroIndus:
917 case AgfaCl20: 915 case AgfaCl20:
918 spca500_reinit(gspca_dev); 916 spca500_reinit(gspca_dev);
919 reg_w(gspca_dev->dev, 0x00, 0x0d01, 0x01); 917 reg_w(gspca_dev, 0x00, 0x0d01, 0x01);
920 /* enable drop packet */ 918 /* enable drop packet */
921 reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); 919 reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
922 920
923 err = spca50x_setup_qtable(gspca_dev, 921 err = spca50x_setup_qtable(gspca_dev,
924 0x00, 0x8800, 0x8840, qtable_pocketdv); 922 0x00, 0x8800, 0x8840, qtable_pocketdv);
925 if (err < 0) 923 if (err < 0)
926 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 924 PDEBUG(D_ERR, "spca50x_setup_qtable failed");
927 reg_w(gspca_dev->dev, 0x00, 0x8880, 2); 925 reg_w(gspca_dev, 0x00, 0x8880, 2);
928 926
929 /* familycam Quicksmart pocketDV stuff */ 927 /* familycam Quicksmart pocketDV stuff */
930 reg_w(gspca_dev->dev, 0x00, 0x800a, 0x00); 928 reg_w(gspca_dev, 0x00, 0x800a, 0x00);
931 /* Set agc transfer: synced inbetween frames */ 929 /* Set agc transfer: synced inbetween frames */
932 reg_w(gspca_dev->dev, 0x00, 0x820f, 0x01); 930 reg_w(gspca_dev, 0x00, 0x820f, 0x01);
933 /* Init SDRAM - needed for SDRAM access */ 931 /* Init SDRAM - needed for SDRAM access */
934 reg_w(gspca_dev->dev, 0x00, 0x870a, 0x04); 932 reg_w(gspca_dev, 0x00, 0x870a, 0x04);
935 933
936 spca500_setmode(gspca_dev, xmult, ymult); 934 spca500_setmode(gspca_dev, xmult, ymult);
937 /* switch to video camera mode */ 935 /* switch to video camera mode */
938 reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); 936 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
939 937
940 reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44); 938 reg_r_wait(gspca_dev, 0, 0x8000, 0x44);
941 939
942 reg_r(gspca_dev->dev, 0x816b, &Data, 1); 940 reg_r(gspca_dev, 0x816b, 1);
943 reg_w(gspca_dev->dev, 0x00, 0x816b, Data); 941 Data = gspca_dev->usb_buf[0];
942 reg_w(gspca_dev, 0x00, 0x816b, Data);
944 break; 943 break;
945 case LogitechTraveler: 944 case LogitechTraveler:
946 case LogitechClickSmart510: 945 case LogitechClickSmart510:
947 reg_w(gspca_dev->dev, 0x02, 0x00, 0x00); 946 reg_w(gspca_dev, 0x02, 0x00, 0x00);
948 /* enable drop packet */ 947 /* enable drop packet */
949 reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); 948 reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
950 949
951 err = spca50x_setup_qtable(gspca_dev, 950 err = spca50x_setup_qtable(gspca_dev,
952 0x00, 0x8800, 951 0x00, 0x8800,
953 0x8840, qtable_creative_pccam); 952 0x8840, qtable_creative_pccam);
954 if (err < 0) 953 if (err < 0)
955 PDEBUG(D_ERR, "spca50x_setup_qtable failed"); 954 PDEBUG(D_ERR, "spca50x_setup_qtable failed");
956 reg_w(gspca_dev->dev, 0x00, 0x8880, 3); 955 reg_w(gspca_dev, 0x00, 0x8880, 3);
957 reg_w(gspca_dev->dev, 0x00, 0x800a, 0x00); 956 reg_w(gspca_dev, 0x00, 0x800a, 0x00);
958 /* Init SDRAM - needed for SDRAM access */ 957 /* Init SDRAM - needed for SDRAM access */
959 reg_w(gspca_dev->dev, 0x00, 0x870a, 0x04); 958 reg_w(gspca_dev, 0x00, 0x870a, 0x04);
960 959
961 spca500_setmode(gspca_dev, xmult, ymult); 960 spca500_setmode(gspca_dev, xmult, ymult);
962 961
963 /* switch to video camera mode */ 962 /* switch to video camera mode */
964 reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); 963 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
965 reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44); 964 reg_r_wait(gspca_dev, 0, 0x8000, 0x44);
966 965
967 reg_r(gspca_dev->dev, 0x816b, &Data, 1); 966 reg_r(gspca_dev, 0x816b, 1);
968 reg_w(gspca_dev->dev, 0x00, 0x816b, Data); 967 Data = gspca_dev->usb_buf[0];
968 reg_w(gspca_dev, 0x00, 0x816b, Data);
969 write_vector(gspca_dev, Clicksmart510_defaults); 969 write_vector(gspca_dev, Clicksmart510_defaults);
970 break; 970 break;
971 } 971 }
@@ -973,14 +973,13 @@ static void sd_start(struct gspca_dev *gspca_dev)
973 973
974static void sd_stopN(struct gspca_dev *gspca_dev) 974static void sd_stopN(struct gspca_dev *gspca_dev)
975{ 975{
976 __u8 data; 976 reg_w(gspca_dev, 0, 0x8003, 0x00);
977
978 reg_w(gspca_dev->dev, 0, 0x8003, 0x00);
979 977
980 /* switch to video camera mode */ 978 /* switch to video camera mode */
981 reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); 979 reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
982 reg_r(gspca_dev->dev, 0x8000, &data, 1); 980 reg_r(gspca_dev, 0x8000, 1);
983 PDEBUG(D_STREAM, "stop SPCA500 done reg8000: 0x%2x", data); 981 PDEBUG(D_STREAM, "stop SPCA500 done reg8000: 0x%2x",
982 gspca_dev->usb_buf[0]);
984} 983}
985 984
986static void sd_stop0(struct gspca_dev *gspca_dev) 985static void sd_stop0(struct gspca_dev *gspca_dev)
@@ -1043,7 +1042,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1043{ 1042{
1044 struct sd *sd = (struct sd *) gspca_dev; 1043 struct sd *sd = (struct sd *) gspca_dev;
1045 1044
1046 reg_w(gspca_dev->dev, 0x00, 0x8167, 1045 reg_w(gspca_dev, 0x00, 0x8167,
1047 (__u8) (sd->brightness - 128)); 1046 (__u8) (sd->brightness - 128));
1048} 1047}
1049 1048
@@ -1052,7 +1051,7 @@ static void getbrightness(struct gspca_dev *gspca_dev)
1052 struct sd *sd = (struct sd *) gspca_dev; 1051 struct sd *sd = (struct sd *) gspca_dev;
1053 int ret; 1052 int ret;
1054 1053
1055 ret = reg_r_12(gspca_dev->dev, 0x00, 0x8167, 1); 1054 ret = reg_r_12(gspca_dev, 0x00, 0x8167, 1);
1056 if (ret >= 0) 1055 if (ret >= 0)
1057 sd->brightness = ret + 128; 1056 sd->brightness = ret + 128;
1058} 1057}
@@ -1061,7 +1060,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
1061{ 1060{
1062 struct sd *sd = (struct sd *) gspca_dev; 1061 struct sd *sd = (struct sd *) gspca_dev;
1063 1062
1064 reg_w(gspca_dev->dev, 0x00, 0x8168, sd->contrast); 1063 reg_w(gspca_dev, 0x00, 0x8168, sd->contrast);
1065} 1064}
1066 1065
1067static void getcontrast(struct gspca_dev *gspca_dev) 1066static void getcontrast(struct gspca_dev *gspca_dev)
@@ -1069,7 +1068,7 @@ static void getcontrast(struct gspca_dev *gspca_dev)
1069 struct sd *sd = (struct sd *) gspca_dev; 1068 struct sd *sd = (struct sd *) gspca_dev;
1070 int ret; 1069 int ret;
1071 1070
1072 ret = reg_r_12(gspca_dev->dev, 0x0, 0x8168, 1); 1071 ret = reg_r_12(gspca_dev, 0x0, 0x8168, 1);
1073 if (ret >= 0) 1072 if (ret >= 0)
1074 sd->contrast = ret; 1073 sd->contrast = ret;
1075} 1074}
@@ -1078,7 +1077,7 @@ static void setcolors(struct gspca_dev *gspca_dev)
1078{ 1077{
1079 struct sd *sd = (struct sd *) gspca_dev; 1078 struct sd *sd = (struct sd *) gspca_dev;
1080 1079
1081 reg_w(gspca_dev->dev, 0x00, 0x8169, sd->colors); 1080 reg_w(gspca_dev, 0x00, 0x8169, sd->colors);
1082} 1081}
1083 1082
1084static void getcolors(struct gspca_dev *gspca_dev) 1083static void getcolors(struct gspca_dev *gspca_dev)
@@ -1086,7 +1085,7 @@ static void getcolors(struct gspca_dev *gspca_dev)
1086 struct sd *sd = (struct sd *) gspca_dev; 1085 struct sd *sd = (struct sd *) gspca_dev;
1087 int ret; 1086 int ret;
1088 1087
1089 ret = reg_r_12(gspca_dev->dev, 0x0, 0x8169, 1); 1088 ret = reg_r_12(gspca_dev, 0x0, 0x8169, 1);
1090 if (ret >= 0) 1089 if (ret >= 0)
1091 sd->colors = ret; 1090 sd->colors = ret;
1092} 1091}
diff --git a/drivers/media/video/gspca/spca501.c b/drivers/media/video/gspca/spca501.c
index 2064dc008af1..8cee6748d38f 100644
--- a/drivers/media/video/gspca/spca501.c
+++ b/drivers/media/video/gspca/spca501.c
@@ -23,8 +23,8 @@
23 23
24#include "gspca.h" 24#include "gspca.h"
25 25
26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
27static const char version[] = "2.1.5"; 27static const char version[] = "2.1.7";
28 28
29MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 29MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
30MODULE_DESCRIPTION("GSPCA/SPCA501 USB Camera Driver"); 30MODULE_DESCRIPTION("GSPCA/SPCA501 USB Camera Driver");
@@ -1826,28 +1826,27 @@ static int reg_write(struct usb_device *dev,
1826} 1826}
1827 1827
1828/* returns: negative is error, pos or zero is data */ 1828/* returns: negative is error, pos or zero is data */
1829static int reg_read(struct usb_device *dev, 1829static int reg_read(struct gspca_dev *gspca_dev,
1830 __u16 req, /* bRequest */ 1830 __u16 req, /* bRequest */
1831 __u16 index, /* wIndex */ 1831 __u16 index, /* wIndex */
1832 __u16 length) /* wLength (1 or 2 only) */ 1832 __u16 length) /* wLength (1 or 2 only) */
1833{ 1833{
1834 int ret; 1834 int ret;
1835 __u8 buf[2];
1836 1835
1837 buf[1] = 0; 1836 gspca_dev->usb_buf[1] = 0;
1838 ret = usb_control_msg(dev, 1837 ret = usb_control_msg(gspca_dev->dev,
1839 usb_rcvctrlpipe(dev, 0), 1838 usb_rcvctrlpipe(gspca_dev->dev, 0),
1840 req, 1839 req,
1841 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1840 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1842 0, /* value */ 1841 0, /* value */
1843 index, 1842 index,
1844 buf, length, 1843 gspca_dev->usb_buf, length,
1845 500); /* timeout */ 1844 500); /* timeout */
1846 if (ret < 0) { 1845 if (ret < 0) {
1847 PDEBUG(D_ERR, "reg_read err %d", ret); 1846 PDEBUG(D_ERR, "reg_read err %d", ret);
1848 return -1; 1847 return -1;
1849 } 1848 }
1850 return (buf[1] << 8) + buf[0]; 1849 return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
1851} 1850}
1852 1851
1853static int write_vector(struct gspca_dev *gspca_dev, 1852static int write_vector(struct gspca_dev *gspca_dev,
@@ -1883,7 +1882,7 @@ static void getbrightness(struct gspca_dev *gspca_dev)
1883 struct sd *sd = (struct sd *) gspca_dev; 1882 struct sd *sd = (struct sd *) gspca_dev;
1884 __u16 brightness; 1883 __u16 brightness;
1885 1884
1886 brightness = reg_read(gspca_dev->dev, SPCA501_REG_CCDSP, 0x11, 2); 1885 brightness = reg_read(gspca_dev, SPCA501_REG_CCDSP, 0x11, 2);
1887 sd->brightness = brightness << 1; 1886 sd->brightness = brightness << 1;
1888} 1887}
1889 1888
@@ -1913,8 +1912,8 @@ static void getcolors(struct gspca_dev *gspca_dev)
1913{ 1912{
1914 struct sd *sd = (struct sd *) gspca_dev; 1913 struct sd *sd = (struct sd *) gspca_dev;
1915 1914
1916 sd->colors = reg_read(gspca_dev->dev, SPCA501_REG_CCDSP, 0x0c, 2); 1915 sd->colors = reg_read(gspca_dev, SPCA501_REG_CCDSP, 0x0c, 2);
1917/* sd->hue = (reg_read(gspca_dev->dev, SPCA501_REG_CCDSP, 0x13, */ 1916/* sd->hue = (reg_read(gspca_dev, SPCA501_REG_CCDSP, 0x13, */
1918/* 2) & 0xFF) << 8; */ 1917/* 2) & 0xFF) << 8; */
1919} 1918}
1920 1919
diff --git a/drivers/media/video/gspca/spca505.c b/drivers/media/video/gspca/spca505.c
index 5d28d23b8375..ddea6e140aa8 100644
--- a/drivers/media/video/gspca/spca505.c
+++ b/drivers/media/video/gspca/spca505.c
@@ -23,8 +23,8 @@
23 23
24#include "gspca.h" 24#include "gspca.h"
25 25
26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
27static const char version[] = "2.1.5"; 27static const char version[] = "2.1.7";
28 28
29MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 29MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
30MODULE_DESCRIPTION("GSPCA/SPCA505 USB Camera Driver"); 30MODULE_DESCRIPTION("GSPCA/SPCA505 USB Camera Driver");
@@ -593,29 +593,27 @@ static int reg_write(struct usb_device *dev,
593} 593}
594 594
595/* returns: negative is error, pos or zero is data */ 595/* returns: negative is error, pos or zero is data */
596static int reg_read(struct usb_device *dev, 596static int reg_read(struct gspca_dev *gspca_dev,
597 __u16 reg, /* bRequest */ 597 __u16 reg, /* bRequest */
598 __u16 index, /* wIndex */ 598 __u16 index, /* wIndex */
599 __u16 length) /* wLength (1 or 2 only) */ 599 __u16 length) /* wLength (1 or 2 only) */
600{ 600{
601 int ret; 601 int ret;
602 __u8 buf[4];
603 602
604 buf[1] = 0; 603 gspca_dev->usb_buf[1] = 0;
605 ret = usb_control_msg(dev, 604 ret = usb_control_msg(gspca_dev->dev,
606 usb_rcvctrlpipe(dev, 0), 605 usb_rcvctrlpipe(gspca_dev->dev, 0),
607 reg, 606 reg,
608 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 607 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
609 (__u16) 0, /* value */ 608 (__u16) 0, /* value */
610 (__u16) index, 609 (__u16) index,
611 buf, 610 gspca_dev->usb_buf, length,
612 length,
613 500); /* timeout */ 611 500); /* timeout */
614 if (ret < 0) { 612 if (ret < 0) {
615 PDEBUG(D_ERR, "reg_read err %d", ret); 613 PDEBUG(D_ERR, "reg_read err %d", ret);
616 return -1; 614 return -1;
617 } 615 }
618 return (buf[1] << 8) + buf[0]; 616 return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
619} 617}
620 618
621static int write_vector(struct gspca_dev *gspca_dev, 619static int write_vector(struct gspca_dev *gspca_dev,
@@ -697,7 +695,7 @@ static int sd_open(struct gspca_dev *gspca_dev)
697 write_vector(gspca_dev, spca505b_open_data_ccd); 695 write_vector(gspca_dev, spca505b_open_data_ccd);
698 else 696 else
699 write_vector(gspca_dev, spca505_open_data_ccd); 697 write_vector(gspca_dev, spca505_open_data_ccd);
700 ret = reg_read(gspca_dev->dev, 6, 0x16, 2); 698 ret = reg_read(gspca_dev, 6, 0x16, 2);
701 699
702 if (ret < 0) { 700 if (ret < 0) {
703 PDEBUG(D_ERR|D_STREAM, 701 PDEBUG(D_ERR|D_STREAM,
@@ -874,8 +872,8 @@ static void getbrightness(struct gspca_dev *gspca_dev)
874 struct sd *sd = (struct sd *) gspca_dev; 872 struct sd *sd = (struct sd *) gspca_dev;
875 873
876 sd->brightness = 255 874 sd->brightness = 255
877 - ((reg_read(gspca_dev->dev, 5, 0x01, 1) >> 2) 875 - ((reg_read(gspca_dev, 5, 0x01, 1) >> 2)
878 + (reg_read(gspca_dev->dev, 5, 0x0, 1) << 6)); 876 + (reg_read(gspca_dev, 5, 0x0, 1) << 6));
879} 877}
880 878
881static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 879static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
diff --git a/drivers/media/video/gspca/spca506.c b/drivers/media/video/gspca/spca506.c
index 2d249b00bdcd..143203c1fd9f 100644
--- a/drivers/media/video/gspca/spca506.c
+++ b/drivers/media/video/gspca/spca506.c
@@ -25,8 +25,8 @@
25 25
26#include "gspca.h" 26#include "gspca.h"
27 27
28#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 28#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
29static const char version[] = "2.1.5"; 29static const char version[] = "2.1.7";
30 30
31MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 31MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
32MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver"); 32MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver");
@@ -153,17 +153,18 @@ static struct v4l2_pix_format vga_mode[] = {
153#define SAA7113_hue 0x0d /* defaults 0x00 */ 153#define SAA7113_hue 0x0d /* defaults 0x00 */
154#define SAA7113_I2C_BASE_WRITE 0x4a 154#define SAA7113_I2C_BASE_WRITE 0x4a
155 155
156static void reg_r(struct usb_device *dev, 156/* read 'len' bytes to gspca_dev->usb_buf */
157static void reg_r(struct gspca_dev *gspca_dev,
157 __u16 req, 158 __u16 req,
158 __u16 index, 159 __u16 index,
159 __u8 *buffer, __u16 length) 160 __u16 length)
160{ 161{
161 usb_control_msg(dev, 162 usb_control_msg(gspca_dev->dev,
162 usb_rcvctrlpipe(dev, 0), 163 usb_rcvctrlpipe(gspca_dev->dev, 0),
163 req, 164 req,
164 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 165 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
165 0, /* value */ 166 0, /* value */
166 index, buffer, length, 167 index, gspca_dev->usb_buf, length,
167 500); 168 500);
168} 169}
169 170
@@ -189,13 +190,12 @@ static void spca506_WriteI2c(struct gspca_dev *gspca_dev, __u16 valeur,
189 __u16 reg) 190 __u16 reg)
190{ 191{
191 int retry = 60; 192 int retry = 60;
192 __u8 Data[2];
193 193
194 reg_w(gspca_dev->dev, 0x07, reg, 0x0001); 194 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
195 reg_w(gspca_dev->dev, 0x07, valeur, 0x0000); 195 reg_w(gspca_dev->dev, 0x07, valeur, 0x0000);
196 while (retry--) { 196 while (retry--) {
197 reg_r(gspca_dev->dev, 0x07, 0x0003, Data, 2); 197 reg_r(gspca_dev, 0x07, 0x0003, 2);
198 if ((Data[0] | Data[1]) == 0x00) 198 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
199 break; 199 break;
200 } 200 }
201} 201}
@@ -203,21 +203,19 @@ static void spca506_WriteI2c(struct gspca_dev *gspca_dev, __u16 valeur,
203static int spca506_ReadI2c(struct gspca_dev *gspca_dev, __u16 reg) 203static int spca506_ReadI2c(struct gspca_dev *gspca_dev, __u16 reg)
204{ 204{
205 int retry = 60; 205 int retry = 60;
206 __u8 Data[2];
207 __u8 value;
208 206
209 reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004); 207 reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
210 reg_w(gspca_dev->dev, 0x07, reg, 0x0001); 208 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
211 reg_w(gspca_dev->dev, 0x07, 0x01, 0x0002); 209 reg_w(gspca_dev->dev, 0x07, 0x01, 0x0002);
212 while (--retry) { 210 while (--retry) {
213 reg_r(gspca_dev->dev, 0x07, 0x0003, Data, 2); 211 reg_r(gspca_dev, 0x07, 0x0003, 2);
214 if ((Data[0] | Data[1]) == 0x00) 212 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
215 break; 213 break;
216 } 214 }
217 if (retry == 0) 215 if (retry == 0)
218 return -1; 216 return -1;
219 reg_r(gspca_dev->dev, 0x07, 0x0000, &value, 1); 217 reg_r(gspca_dev, 0x07, 0x0000, 1);
220 return value; 218 return gspca_dev->usb_buf[0];
221} 219}
222 220
223static void spca506_SetNormeInput(struct gspca_dev *gspca_dev, 221static void spca506_SetNormeInput(struct gspca_dev *gspca_dev,
@@ -437,7 +435,6 @@ static void sd_start(struct gspca_dev *gspca_dev)
437 struct usb_device *dev = gspca_dev->dev; 435 struct usb_device *dev = gspca_dev->dev;
438 __u16 norme; 436 __u16 norme;
439 __u16 channel; 437 __u16 channel;
440 __u8 Data[2];
441 438
442 /**************************************/ 439 /**************************************/
443 reg_w(dev, 0x03, 0x00, 0x0004); 440 reg_w(dev, 0x03, 0x00, 0x0004);
@@ -555,8 +552,8 @@ static void sd_start(struct gspca_dev *gspca_dev)
555 /* compress setting and size */ 552 /* compress setting and size */
556 /* set i2c luma */ 553 /* set i2c luma */
557 reg_w(dev, 0x02, 0x01, 0x0000); 554 reg_w(dev, 0x02, 0x01, 0x0000);
558 reg_w(dev, 0x03, 0x12, 0x000); 555 reg_w(dev, 0x03, 0x12, 0x0000);
559 reg_r(dev, 0x04, 0x0001, Data, 2); 556 reg_r(gspca_dev, 0x04, 0x0001, 2);
560 PDEBUG(D_STREAM, "webcam started"); 557 PDEBUG(D_STREAM, "webcam started");
561 spca506_GetNormeInput(gspca_dev, &norme, &channel); 558 spca506_GetNormeInput(gspca_dev, &norme, &channel);
562 spca506_SetNormeInput(gspca_dev, norme, channel); 559 spca506_SetNormeInput(gspca_dev, norme, channel);
diff --git a/drivers/media/video/gspca/spca508.c b/drivers/media/video/gspca/spca508.c
index 7f262f23841e..d8cd93866a4a 100644
--- a/drivers/media/video/gspca/spca508.c
+++ b/drivers/media/video/gspca/spca508.c
@@ -22,8 +22,8 @@
22 22
23#include "gspca.h" 23#include "gspca.h"
24 24
25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
26static const char version[] = "2.1.5"; 26static const char version[] = "2.1.7";
27 27
28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("GSPCA/SPCA508 USB Camera Driver"); 29MODULE_DESCRIPTION("GSPCA/SPCA508 USB Camera Driver");
@@ -1433,26 +1433,26 @@ static int reg_write(struct usb_device *dev,
1433 1433
1434/* read 1 byte */ 1434/* read 1 byte */
1435/* returns: negative is error, pos or zero is data */ 1435/* returns: negative is error, pos or zero is data */
1436static int reg_read(struct usb_device *dev, 1436static int reg_read(struct gspca_dev *gspca_dev,
1437 __u16 index) /* wIndex */ 1437 __u16 index) /* wIndex */
1438{ 1438{
1439 int ret; 1439 int ret;
1440 __u8 data;
1441 1440
1442 ret = usb_control_msg(dev, 1441 ret = usb_control_msg(gspca_dev->dev,
1443 usb_rcvctrlpipe(dev, 0), 1442 usb_rcvctrlpipe(gspca_dev->dev, 0),
1444 0, /* register */ 1443 0, /* register */
1445 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1444 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1446 (__u16) 0, /* value */ 1445 0, /* value */
1447 index, 1446 index,
1448 &data, 1, 1447 gspca_dev->usb_buf, 1,
1449 500); /* timeout */ 1448 500); /* timeout */
1450 PDEBUG(D_USBI, "reg read i:%04x --> %02x", index, data); 1449 PDEBUG(D_USBI, "reg read i:%04x --> %02x",
1450 index, gspca_dev->usb_buf[0]);
1451 if (ret < 0) { 1451 if (ret < 0) {
1452 PDEBUG(D_ERR|D_USBI, "reg_read err %d", ret); 1452 PDEBUG(D_ERR|D_USBI, "reg_read err %d", ret);
1453 return ret; 1453 return ret;
1454 } 1454 }
1455 return data; 1455 return gspca_dev->usb_buf[0];
1456} 1456}
1457 1457
1458static int write_vector(struct gspca_dev *gspca_dev, 1458static int write_vector(struct gspca_dev *gspca_dev,
@@ -1475,15 +1475,12 @@ static int sd_config(struct gspca_dev *gspca_dev,
1475 const struct usb_device_id *id) 1475 const struct usb_device_id *id)
1476{ 1476{
1477 struct sd *sd = (struct sd *) gspca_dev; 1477 struct sd *sd = (struct sd *) gspca_dev;
1478 struct usb_device *dev = gspca_dev->dev;
1479 struct cam *cam; 1478 struct cam *cam;
1480 __u16 vendor;
1481 __u16 product; 1479 __u16 product;
1482 int data1, data2; 1480 int data1, data2;
1483 1481
1484 vendor = id->idVendor;
1485 product = id->idProduct; 1482 product = id->idProduct;
1486 switch (vendor) { 1483 switch (id->idVendor) {
1487 case 0x0130: /* Clone webcam */ 1484 case 0x0130: /* Clone webcam */
1488/* switch (product) { */ 1485/* switch (product) { */
1489/* case 0x0130: */ 1486/* case 0x0130: */
@@ -1535,15 +1532,15 @@ static int sd_config(struct gspca_dev *gspca_dev,
1535 * prove that we can communicate with the device. This works, which 1532 * prove that we can communicate with the device. This works, which
1536 * confirms at we are communicating properly and that the device 1533 * confirms at we are communicating properly and that the device
1537 * is a 508. */ 1534 * is a 508. */
1538 data1 = reg_read(dev, 0x8104); 1535 data1 = reg_read(gspca_dev, 0x8104);
1539 data2 = reg_read(dev, 0x8105); 1536 data2 = reg_read(gspca_dev, 0x8105);
1540 PDEBUG(D_PROBE, "Webcam Vendor ID: 0x%02x%02x", data2, data1); 1537 PDEBUG(D_PROBE, "Webcam Vendor ID: 0x%02x%02x", data2, data1);
1541 1538
1542 data1 = reg_read(dev, 0x8106); 1539 data1 = reg_read(gspca_dev, 0x8106);
1543 data2 = reg_read(dev, 0x8107); 1540 data2 = reg_read(gspca_dev, 0x8107);
1544 PDEBUG(D_PROBE, "Webcam Product ID: 0x%02x%02x", data2, data1); 1541 PDEBUG(D_PROBE, "Webcam Product ID: 0x%02x%02x", data2, data1);
1545 1542
1546 data1 = reg_read(dev, 0x8621); 1543 data1 = reg_read(gspca_dev, 0x8621);
1547 PDEBUG(D_PROBE, "Window 1 average luminance: %d", data1); 1544 PDEBUG(D_PROBE, "Window 1 average luminance: %d", data1);
1548 1545
1549 cam = &gspca_dev->cam; 1546 cam = &gspca_dev->cam;
@@ -1711,7 +1708,7 @@ static void getbrightness(struct gspca_dev *gspca_dev)
1711{ 1708{
1712 struct sd *sd = (struct sd *) gspca_dev; 1709 struct sd *sd = (struct sd *) gspca_dev;
1713 1710
1714 sd->brightness = reg_read(gspca_dev->dev, 0x8651); 1711 sd->brightness = reg_read(gspca_dev, 0x8651);
1715} 1712}
1716 1713
1717static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 1714static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
diff --git a/drivers/media/video/gspca/spca561.c b/drivers/media/video/gspca/spca561.c
index f0770ee595d8..b659bd0f788d 100644
--- a/drivers/media/video/gspca/spca561.c
+++ b/drivers/media/video/gspca/spca561.c
@@ -24,8 +24,8 @@
24 24
25#include "gspca.h" 25#include "gspca.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.5"; 28static const char version[] = "2.1.7";
29 29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver"); 31MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver");
@@ -177,27 +177,28 @@ static void write_vector(struct gspca_dev *gspca_dev,
177 } 177 }
178} 178}
179 179
180static void reg_r(struct usb_device *dev, 180/* read 'len' bytes to gspca_dev->usb_buf */
181 __u16 index, __u8 *buffer, __u16 length) 181static void reg_r(struct gspca_dev *gspca_dev,
182 __u16 index, __u16 length)
182{ 183{
183 usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 184 usb_control_msg(gspca_dev->dev,
185 usb_rcvctrlpipe(gspca_dev->dev, 0),
184 0, /* request */ 186 0, /* request */
185 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 187 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
186 0, /* value */ 188 0, /* value */
187 index, buffer, length, 500); 189 index, gspca_dev->usb_buf, length, 500);
188} 190}
189 191
190static void reg_w_buf(struct usb_device *dev, 192static void reg_w_buf(struct gspca_dev *gspca_dev,
191 __u16 index, const __u8 *buffer, __u16 len) 193 __u16 index, const __u8 *buffer, __u16 len)
192{ 194{
193 __u8 tmpbuf[8]; 195 memcpy(gspca_dev->usb_buf, buffer, len);
194 196 usb_control_msg(gspca_dev->dev,
195 memcpy(tmpbuf, buffer, len); 197 usb_sndctrlpipe(gspca_dev->dev, 0),
196 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
197 0, /* request */ 198 0, /* request */
198 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 199 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
199 0, /* value */ 200 0, /* value */
200 index, tmpbuf, len, 500); 201 index, gspca_dev->usb_buf, len, 500);
201} 202}
202 203
203static void i2c_init(struct gspca_dev *gspca_dev, __u8 mode) 204static void i2c_init(struct gspca_dev *gspca_dev, __u8 mode)
@@ -211,7 +212,6 @@ static void i2c_write(struct gspca_dev *gspca_dev, __u16 valeur, __u16 reg)
211 int retry = 60; 212 int retry = 60;
212 __u8 DataLow; 213 __u8 DataLow;
213 __u8 DataHight; 214 __u8 DataHight;
214 __u8 Data;
215 215
216 DataLow = valeur; 216 DataLow = valeur;
217 DataHight = valeur >> 8; 217 DataHight = valeur >> 8;
@@ -219,8 +219,8 @@ static void i2c_write(struct gspca_dev *gspca_dev, __u16 valeur, __u16 reg)
219 reg_w_val(gspca_dev->dev, DataLow, 0x8805); 219 reg_w_val(gspca_dev->dev, DataLow, 0x8805);
220 reg_w_val(gspca_dev->dev, DataHight, 0x8800); 220 reg_w_val(gspca_dev->dev, DataHight, 0x8800);
221 while (retry--) { 221 while (retry--) {
222 reg_r(gspca_dev->dev, 0x8803, &Data, 1); 222 reg_r(gspca_dev, 0x8803, 1);
223 if (!Data) 223 if (!gspca_dev->usb_buf[0])
224 break; 224 break;
225 } 225 }
226} 226}
@@ -230,20 +230,21 @@ static int i2c_read(struct gspca_dev *gspca_dev, __u16 reg, __u8 mode)
230 int retry = 60; 230 int retry = 60;
231 __u8 value; 231 __u8 value;
232 __u8 vallsb; 232 __u8 vallsb;
233 __u8 Data;
234 233
235 reg_w_val(gspca_dev->dev, 0x92, 0x8804); 234 reg_w_val(gspca_dev->dev, 0x92, 0x8804);
236 reg_w_val(gspca_dev->dev, reg, 0x8801); 235 reg_w_val(gspca_dev->dev, reg, 0x8801);
237 reg_w_val(gspca_dev->dev, (mode | 0x01), 0x8802); 236 reg_w_val(gspca_dev->dev, (mode | 0x01), 0x8802);
238 while (retry--) { 237 while (retry--) {
239 reg_r(gspca_dev->dev, 0x8803, &Data, 1); 238 reg_r(gspca_dev, 0x8803, 1);
240 if (!Data) 239 if (!gspca_dev->usb_buf)
241 break; 240 break;
242 } 241 }
243 if (retry == 0) 242 if (retry == 0)
244 return -1; 243 return -1;
245 reg_r(gspca_dev->dev, 0x8800, &value, 1); 244 reg_r(gspca_dev, 0x8800, 1);
246 reg_r(gspca_dev->dev, 0x8805, &vallsb, 1); 245 value = gspca_dev->usb_buf[0];
246 reg_r(gspca_dev, 0x8805, 1);
247 vallsb = gspca_dev->usb_buf[0];
247 return ((int) value << 8) | vallsb; 248 return ((int) value << 8) | vallsb;
248} 249}
249 250
@@ -541,7 +542,7 @@ static void sensor_mapwrite(struct gspca_dev *gspca_dev,
541 while (sensormap[i][0]) { 542 while (sensormap[i][0]) {
542 usbval[0] = sensormap[i][1]; 543 usbval[0] = sensormap[i][1];
543 usbval[1] = sensormap[i][1] >> 8; 544 usbval[1] = sensormap[i][1] >> 8;
544 reg_w_buf(gspca_dev->dev, sensormap[i][0], usbval, 2); 545 reg_w_buf(gspca_dev, sensormap[i][0], usbval, 2);
545 i++; 546 i++;
546 } 547 }
547} 548}
@@ -559,7 +560,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
559 const struct usb_device_id *id) 560 const struct usb_device_id *id)
560{ 561{
561 struct sd *sd = (struct sd *) gspca_dev; 562 struct sd *sd = (struct sd *) gspca_dev;
562 struct usb_device *dev = gspca_dev->dev;
563 struct cam *cam; 563 struct cam *cam;
564 __u16 vendor, product; 564 __u16 vendor, product;
565 __u8 data1, data2; 565 __u8 data1, data2;
@@ -568,11 +568,15 @@ static int sd_config(struct gspca_dev *gspca_dev,
568 * prove that we can communicate with the device. This works, which 568 * prove that we can communicate with the device. This works, which
569 * confirms at we are communicating properly and that the device 569 * confirms at we are communicating properly and that the device
570 * is a 561. */ 570 * is a 561. */
571 reg_r(dev, 0x8104, &data1, 1); 571 reg_r(gspca_dev, 0x8104, 1);
572 reg_r(dev, 0x8105, &data2, 1); 572 data1 = gspca_dev->usb_buf[0];
573 reg_r(gspca_dev, 0x8105, 1);
574 data2 = gspca_dev->usb_buf[0];
573 vendor = (data2 << 8) | data1; 575 vendor = (data2 << 8) | data1;
574 reg_r(dev, 0x8106, &data1, 1); 576 reg_r(gspca_dev, 0x8106, 1);
575 reg_r(dev, 0x8107, &data2, 1); 577 data1 = gspca_dev->usb_buf[0];
578 reg_r(gspca_dev, 0x8107, 1);
579 data2 = gspca_dev->usb_buf[0];
576 product = (data2 << 8) | data1; 580 product = (data2 << 8) | data1;
577 if (vendor != id->idVendor || product != id->idProduct) { 581 if (vendor != id->idVendor || product != id->idProduct) {
578 PDEBUG(D_PROBE, "Bad vendor / product from device"); 582 PDEBUG(D_PROBE, "Bad vendor / product from device");
@@ -656,8 +660,8 @@ static void setcontrast(struct gspca_dev *gspca_dev)
656 Reg8391[0] = expotimes & 0xff; /* exposure */ 660 Reg8391[0] = expotimes & 0xff; /* exposure */
657 Reg8391[1] = 0x18 | (expotimes >> 8); 661 Reg8391[1] = 0x18 | (expotimes >> 8);
658 Reg8391[2] = sd->brightness; /* gain */ 662 Reg8391[2] = sd->brightness; /* gain */
659 reg_w_buf(dev, 0x8391, Reg8391, 8); 663 reg_w_buf(gspca_dev, 0x8391, Reg8391, 8);
660 reg_w_buf(dev, 0x8390, Reg8391, 8); 664 reg_w_buf(gspca_dev, 0x8390, Reg8391, 8);
661 break; 665 break;
662 } 666 }
663 } 667 }
@@ -714,10 +718,11 @@ static void sd_start(struct gspca_dev *gspca_dev)
714 * is sufficient to push raw frames at ~20fps */ 718 * is sufficient to push raw frames at ~20fps */
715 reg_w_val(dev, 0x8500, mode); 719 reg_w_val(dev, 0x8500, mode);
716 } /* -- qq@kuku.eu.org */ 720 } /* -- qq@kuku.eu.org */
717 reg_w_buf(dev, 0x8307, Reg8307, 2); 721 reg_w_buf(gspca_dev, 0x8307, Reg8307, 2);
718 reg_w_val(dev, 0x8700, Clck); /* 0x8f 0x85 0x27 clock */ 722 reg_w_val(gspca_dev->dev, 0x8700, Clck);
719 reg_w_val(dev, 0x8112, 0x1e | 0x20); 723 /* 0x8f 0x85 0x27 clock */
720 reg_w_val(dev, 0x850b, 0x03); 724 reg_w_val(gspca_dev->dev, 0x8112, 0x1e | 0x20);
725 reg_w_val(gspca_dev->dev, 0x850b, 0x03);
721 setcontrast(gspca_dev); 726 setcontrast(gspca_dev);
722 break; 727 break;
723 } 728 }
@@ -752,10 +757,14 @@ static void setautogain(struct gspca_dev *gspca_dev)
752 757
753 switch (sd->chip_revision) { 758 switch (sd->chip_revision) {
754 case Rev072A: 759 case Rev072A:
755 reg_r(gspca_dev->dev, 0x8621, &Gr, 1); 760 reg_r(gspca_dev, 0x8621, 1);
756 reg_r(gspca_dev->dev, 0x8622, &R, 1); 761 Gr = gspca_dev->usb_buf[0];
757 reg_r(gspca_dev->dev, 0x8623, &B, 1); 762 reg_r(gspca_dev, 0x8622, 1);
758 reg_r(gspca_dev->dev, 0x8624, &Gb, 1); 763 R = gspca_dev->usb_buf[0];
764 reg_r(gspca_dev, 0x8623, 1);
765 B = gspca_dev->usb_buf[0];
766 reg_r(gspca_dev, 0x8624, 1);
767 Gb = gspca_dev->usb_buf[0];
759 y = (77 * R + 75 * (Gr + Gb) + 29 * B) >> 8; 768 y = (77 * R + 75 * (Gr + Gb) + 29 * B) >> 8;
760 /* u= (128*B-(43*(Gr+Gb+R))) >> 8; */ 769 /* u= (128*B-(43*(Gr+Gb+R))) >> 8; */
761 /* v= (128*R-(53*(Gr+Gb))-21*B) >> 8; */ 770 /* v= (128*R-(53*(Gr+Gb))-21*B) >> 8; */
@@ -867,20 +876,19 @@ static void setbrightness(struct gspca_dev *gspca_dev)
867static void getbrightness(struct gspca_dev *gspca_dev) 876static void getbrightness(struct gspca_dev *gspca_dev)
868{ 877{
869 struct sd *sd = (struct sd *) gspca_dev; 878 struct sd *sd = (struct sd *) gspca_dev;
870 __u8 value;
871 __u16 tot; 879 __u16 tot;
872 880
873 switch (sd->chip_revision) { 881 switch (sd->chip_revision) {
874 case Rev072A: 882 case Rev072A:
875 tot = 0; 883 tot = 0;
876 reg_r(gspca_dev->dev, 0x8611, &value, 1); 884 reg_r(gspca_dev, 0x8611, 1);
877 tot += value; 885 tot += gspca_dev->usb_buf[0];
878 reg_r(gspca_dev->dev, 0x8612, &value, 1); 886 reg_r(gspca_dev, 0x8612, 1);
879 tot += value; 887 tot += gspca_dev->usb_buf[0];
880 reg_r(gspca_dev->dev, 0x8613, &value, 1); 888 reg_r(gspca_dev, 0x8613, 1);
881 tot += value; 889 tot += gspca_dev->usb_buf[0];
882 reg_r(gspca_dev->dev, 0x8614, &value, 1); 890 reg_r(gspca_dev, 0x8614, 1);
883 tot += value; 891 tot += gspca_dev->usb_buf[0];
884 sd->brightness = tot >> 2; 892 sd->brightness = tot >> 2;
885 break; 893 break;
886 default: 894 default:
@@ -893,20 +901,19 @@ static void getbrightness(struct gspca_dev *gspca_dev)
893static void getcontrast(struct gspca_dev *gspca_dev) 901static void getcontrast(struct gspca_dev *gspca_dev)
894{ 902{
895 struct sd *sd = (struct sd *) gspca_dev; 903 struct sd *sd = (struct sd *) gspca_dev;
896 __u8 value;
897 __u16 tot; 904 __u16 tot;
898 905
899 switch (sd->chip_revision) { 906 switch (sd->chip_revision) {
900 case Rev072A: 907 case Rev072A:
901 tot = 0; 908 tot = 0;
902 reg_r(gspca_dev->dev, 0x8651, &value, 1); 909 reg_r(gspca_dev, 0x8651, 1);
903 tot += value; 910 tot += gspca_dev->usb_buf[0];
904 reg_r(gspca_dev->dev, 0x8652, &value, 1); 911 reg_r(gspca_dev, 0x8652, 1);
905 tot += value; 912 tot += gspca_dev->usb_buf[0];
906 reg_r(gspca_dev->dev, 0x8653, &value, 1); 913 reg_r(gspca_dev, 0x8653, 1);
907 tot += value; 914 tot += gspca_dev->usb_buf[0];
908 reg_r(gspca_dev->dev, 0x8654, &value, 1); 915 reg_r(gspca_dev, 0x8654, 1);
909 tot += value; 916 tot += gspca_dev->usb_buf[0];
910 sd->contrast = tot << 6; 917 sd->contrast = tot << 6;
911 break; 918 break;
912 default: 919 default:
diff --git a/drivers/media/video/gspca/stk014.c b/drivers/media/video/gspca/stk014.c
index d676cd16aa74..c78ee0d3e59b 100644
--- a/drivers/media/video/gspca/stk014.c
+++ b/drivers/media/video/gspca/stk014.c
@@ -23,8 +23,8 @@
23#include "gspca.h" 23#include "gspca.h"
24#include "jpeg.h" 24#include "jpeg.h"
25 25
26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
27static const char version[] = "2.1.5"; 27static const char version[] = "2.1.7";
28 28
29MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); 29MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
30MODULE_DESCRIPTION("Syntek DV4000 (STK014) USB Camera Driver"); 30MODULE_DESCRIPTION("Syntek DV4000 (STK014) USB Camera Driver");
@@ -127,7 +127,7 @@ static struct v4l2_pix_format vga_mode[] = {
127 127
128/* -- read a register -- */ 128/* -- read a register -- */
129static int reg_r(struct gspca_dev *gspca_dev, 129static int reg_r(struct gspca_dev *gspca_dev,
130 __u16 index, __u8 *buf) 130 __u16 index)
131{ 131{
132 struct usb_device *dev = gspca_dev->dev; 132 struct usb_device *dev = gspca_dev->dev;
133 int ret; 133 int ret;
@@ -137,11 +137,13 @@ static int reg_r(struct gspca_dev *gspca_dev,
137 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 137 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
138 0x00, 138 0x00,
139 index, 139 index,
140 buf, 1, 140 gspca_dev->usb_buf, 1,
141 500); 141 500);
142 if (ret < 0) 142 if (ret < 0) {
143 PDEBUG(D_ERR, "reg_r err %d", ret); 143 PDEBUG(D_ERR, "reg_r err %d", ret);
144 return ret; 144 return ret;
145 }
146 return gspca_dev->usb_buf[0];
145} 147}
146 148
147/* -- write a register -- */ 149/* -- write a register -- */
@@ -164,58 +166,55 @@ static int reg_w(struct gspca_dev *gspca_dev,
164 return ret; 166 return ret;
165} 167}
166 168
167/* -- get a value -- */ 169/* -- get a bulk value (4 bytes) -- */
168static int rcv_val(struct gspca_dev *gspca_dev, 170static int rcv_val(struct gspca_dev *gspca_dev,
169 int ads, 171 int ads)
170 int len)
171{ 172{
172 struct usb_device *dev = gspca_dev->dev; 173 struct usb_device *dev = gspca_dev->dev;
173 int alen, ret; 174 int alen, ret;
174 unsigned char bulk_buf[4];
175 175
176 reg_w(gspca_dev, 0x634, (ads >> 16) & 0xff); 176 reg_w(gspca_dev, 0x634, (ads >> 16) & 0xff);
177 reg_w(gspca_dev, 0x635, (ads >> 8) & 0xff); 177 reg_w(gspca_dev, 0x635, (ads >> 8) & 0xff);
178 reg_w(gspca_dev, 0x636, ads & 0xff); 178 reg_w(gspca_dev, 0x636, ads & 0xff);
179 reg_w(gspca_dev, 0x637, 0); 179 reg_w(gspca_dev, 0x637, 0);
180 reg_w(gspca_dev, 0x638, len & 0xff); 180 reg_w(gspca_dev, 0x638, 4); /* len & 0xff */
181 reg_w(gspca_dev, 0x639, len >> 8); 181 reg_w(gspca_dev, 0x639, 0); /* len >> 8 */
182 reg_w(gspca_dev, 0x63a, 0); 182 reg_w(gspca_dev, 0x63a, 0);
183 reg_w(gspca_dev, 0x63b, 0); 183 reg_w(gspca_dev, 0x63b, 0);
184 reg_w(gspca_dev, 0x630, 5); 184 reg_w(gspca_dev, 0x630, 5);
185 if (len > sizeof bulk_buf)
186 return -1;
187 ret = usb_bulk_msg(dev, 185 ret = usb_bulk_msg(dev,
188 usb_rcvbulkpipe(dev, 5), 186 usb_rcvbulkpipe(dev, 5),
189 bulk_buf, 187 gspca_dev->usb_buf,
190 len, 188 4, /* length */
191 &alen, 189 &alen,
192 500); /* timeout in milliseconds */ 190 500); /* timeout in milliseconds */
193 return ret; 191 return ret;
194} 192}
195 193
196/* -- send a value -- */ 194/* -- send a bulk value -- */
197static int snd_val(struct gspca_dev *gspca_dev, 195static int snd_val(struct gspca_dev *gspca_dev,
198 int ads, 196 int ads,
199 unsigned int val) 197 unsigned int val)
200{ 198{
201 struct usb_device *dev = gspca_dev->dev; 199 struct usb_device *dev = gspca_dev->dev;
202 int alen, ret; 200 int alen, ret;
203 __u8 value, seq; 201 __u8 seq = 0;
204 unsigned char bulk_buf[4];
205 202
206 if (ads == 0x003f08) { 203 if (ads == 0x003f08) {
207 ret = reg_r(gspca_dev, 0x0704, &value); 204 ret = reg_r(gspca_dev, 0x0704);
208 if (ret < 0) 205 if (ret < 0)
209 goto ko; 206 goto ko;
210 ret = reg_r(gspca_dev, 0x0705, &seq); 207 ret = reg_r(gspca_dev, 0x0705);
211 if (ret < 0) 208 if (ret < 0)
212 goto ko; 209 goto ko;
213 ret = reg_r(gspca_dev, 0x0650, &value); 210 seq = ret; /* keep the sequence number */
211 ret = reg_r(gspca_dev, 0x0650);
214 if (ret < 0) 212 if (ret < 0)
215 goto ko; 213 goto ko;
216 reg_w(gspca_dev, 0x654, seq); 214 reg_w(gspca_dev, 0x654, seq);
217 } else 215 } else {
218 reg_w(gspca_dev, 0x654, (ads >> 16) & 0xff); 216 reg_w(gspca_dev, 0x654, (ads >> 16) & 0xff);
217 }
219 reg_w(gspca_dev, 0x655, (ads >> 8) & 0xff); 218 reg_w(gspca_dev, 0x655, (ads >> 8) & 0xff);
220 reg_w(gspca_dev, 0x656, ads & 0xff); 219 reg_w(gspca_dev, 0x656, ads & 0xff);
221 reg_w(gspca_dev, 0x657, 0); 220 reg_w(gspca_dev, 0x657, 0);
@@ -224,13 +223,13 @@ static int snd_val(struct gspca_dev *gspca_dev,
224 reg_w(gspca_dev, 0x65a, 0); 223 reg_w(gspca_dev, 0x65a, 0);
225 reg_w(gspca_dev, 0x65b, 0); 224 reg_w(gspca_dev, 0x65b, 0);
226 reg_w(gspca_dev, 0x650, 5); 225 reg_w(gspca_dev, 0x650, 5);
227 bulk_buf[0] = (val >> 24) & 0xff; 226 gspca_dev->usb_buf[0] = val >> 24;
228 bulk_buf[1] = (val >> 16) & 0xff; 227 gspca_dev->usb_buf[1] = val >> 16;
229 bulk_buf[2] = (val >> 8) & 0xff; 228 gspca_dev->usb_buf[2] = val >> 8;
230 bulk_buf[3] = val & 0xff; 229 gspca_dev->usb_buf[3] = val;
231 ret = usb_bulk_msg(dev, 230 ret = usb_bulk_msg(dev,
232 usb_sndbulkpipe(dev, 6), 231 usb_sndbulkpipe(dev, 6),
233 bulk_buf, 232 gspca_dev->usb_buf,
234 4, 233 4,
235 &alen, 234 &alen,
236 500); /* timeout in milliseconds */ 235 500); /* timeout in milliseconds */
@@ -303,7 +302,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
303 cam->dev_name = (char *) id->driver_info; 302 cam->dev_name = (char *) id->driver_info;
304 cam->epaddr = 0x02; 303 cam->epaddr = 0x02;
305 gspca_dev->cam.cam_mode = vga_mode; 304 gspca_dev->cam.cam_mode = vga_mode;
306 gspca_dev->cam.nmodes = sizeof vga_mode / sizeof vga_mode[0]; 305 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode);
307 sd->brightness = BRIGHTNESS_DEF; 306 sd->brightness = BRIGHTNESS_DEF;
308 sd->contrast = CONTRAST_DEF; 307 sd->contrast = CONTRAST_DEF;
309 sd->colors = COLOR_DEF; 308 sd->colors = COLOR_DEF;
@@ -314,16 +313,15 @@ static int sd_config(struct gspca_dev *gspca_dev,
314/* this function is called at open time */ 313/* this function is called at open time */
315static int sd_open(struct gspca_dev *gspca_dev) 314static int sd_open(struct gspca_dev *gspca_dev)
316{ 315{
317 __u8 value;
318 int ret; 316 int ret;
319 317
320 /* check if the device responds */ 318 /* check if the device responds */
321 usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1); 319 usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1);
322 ret = reg_r(gspca_dev, 0x0740, &value); 320 ret = reg_r(gspca_dev, 0x0740);
323 if (ret < 0) 321 if (ret < 0)
324 return ret; 322 return ret;
325 if (value != 0xff) { 323 if (ret != 0xff) {
326 PDEBUG(D_ERR|D_STREAM, "init reg: 0x%02x", value); 324 PDEBUG(D_ERR|D_STREAM, "init reg: 0x%02x", ret);
327 return -1; 325 return -1;
328 } 326 }
329 return 0; 327 return 0;
@@ -332,7 +330,6 @@ static int sd_open(struct gspca_dev *gspca_dev)
332/* -- start the camera -- */ 330/* -- start the camera -- */
333static void sd_start(struct gspca_dev *gspca_dev) 331static void sd_start(struct gspca_dev *gspca_dev)
334{ 332{
335 __u8 dum;
336 int ret, value; 333 int ret, value;
337 334
338 /* work on alternate 1 */ 335 /* work on alternate 1 */
@@ -355,11 +352,11 @@ static void sd_start(struct gspca_dev *gspca_dev)
355 gspca_dev->iface, gspca_dev->alt); 352 gspca_dev->iface, gspca_dev->alt);
356 goto out; 353 goto out;
357 } 354 }
358 ret = reg_r(gspca_dev, 0x0630, &dum); 355 ret = reg_r(gspca_dev, 0x0630);
359 if (ret < 0) 356 if (ret < 0)
360 goto out; 357 goto out;
361 rcv_val(gspca_dev, 0x000020, 4); /* << (value ff ff ff ff) */ 358 rcv_val(gspca_dev, 0x000020); /* << (value ff ff ff ff) */
362 ret = reg_r(gspca_dev, 0x0650, &dum); 359 ret = reg_r(gspca_dev, 0x0650);
363 if (ret < 0) 360 if (ret < 0)
364 goto out; 361 goto out;
365 snd_val(gspca_dev, 0x000020, 0xffffffff); 362 snd_val(gspca_dev, 0x000020, 0xffffffff);
@@ -389,14 +386,13 @@ out:
389static void sd_stopN(struct gspca_dev *gspca_dev) 386static void sd_stopN(struct gspca_dev *gspca_dev)
390{ 387{
391 struct usb_device *dev = gspca_dev->dev; 388 struct usb_device *dev = gspca_dev->dev;
392 __u8 value;
393 389
394 set_par(gspca_dev, 0x02000000); 390 set_par(gspca_dev, 0x02000000);
395 set_par(gspca_dev, 0x02000000); 391 set_par(gspca_dev, 0x02000000);
396 usb_set_interface(dev, gspca_dev->iface, 1); 392 usb_set_interface(dev, gspca_dev->iface, 1);
397 reg_r(gspca_dev, 0x0630, &value); 393 reg_r(gspca_dev, 0x0630);
398 rcv_val(gspca_dev, 0x000020, 4); /* << (value ff ff ff ff) */ 394 rcv_val(gspca_dev, 0x000020); /* << (value ff ff ff ff) */
399 reg_r(gspca_dev, 0x0650, &value); 395 reg_r(gspca_dev, 0x0650);
400 snd_val(gspca_dev, 0x000020, 0xffffffff); 396 snd_val(gspca_dev, 0x000020, 0xffffffff);
401 reg_w(gspca_dev, 0x0620, 0); 397 reg_w(gspca_dev, 0x0620, 0);
402 reg_w(gspca_dev, 0x0630, 0); 398 reg_w(gspca_dev, 0x0630, 0);
@@ -538,10 +534,10 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
538} 534}
539 535
540/* sub-driver description */ 536/* sub-driver description */
541static struct sd_desc sd_desc = { 537static const struct sd_desc sd_desc = {
542 .name = MODULE_NAME, 538 .name = MODULE_NAME,
543 .ctrls = sd_ctrls, 539 .ctrls = sd_ctrls,
544 .nctrls = sizeof sd_ctrls / sizeof sd_ctrls[0], 540 .nctrls = ARRAY_SIZE(sd_ctrls),
545 .config = sd_config, 541 .config = sd_config,
546 .open = sd_open, 542 .open = sd_open,
547 .start = sd_start, 543 .start = sd_start,
@@ -554,7 +550,7 @@ static struct sd_desc sd_desc = {
554 550
555/* -- module initialisation -- */ 551/* -- module initialisation -- */
556#define DVNM(name) .driver_info = (kernel_ulong_t) name 552#define DVNM(name) .driver_info = (kernel_ulong_t) name
557static __devinitdata struct usb_device_id device_table[] = { 553static const __devinitdata struct usb_device_id device_table[] = {
558 {USB_DEVICE(0x05e1, 0x0893), DVNM("Syntek DV4000")}, 554 {USB_DEVICE(0x05e1, 0x0893), DVNM("Syntek DV4000")},
559 {} 555 {}
560}; 556};
diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c
index f66594a113a7..acd4a077198a 100644
--- a/drivers/media/video/gspca/sunplus.c
+++ b/drivers/media/video/gspca/sunplus.c
@@ -24,8 +24,8 @@
24#include "gspca.h" 24#include "gspca.h"
25#include "jpeg.h" 25#include "jpeg.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.5"; 28static const char version[] = "2.1.7";
29 29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/SPCA5xx USB Camera Driver"); 31MODULE_DESCRIPTION("GSPCA/SPCA5xx USB Camera Driver");
@@ -452,7 +452,7 @@ static const __u8 qtable_spca504_default[2][64] = {
452 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e} 452 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
453}; 453};
454 454
455static void spca5xxRegRead(struct usb_device *dev, 455static void reg_r(struct usb_device *dev,
456 __u16 req, 456 __u16 req,
457 __u16 index, 457 __u16 index,
458 __u8 *buffer, __u16 length) 458 __u8 *buffer, __u16 length)
@@ -466,7 +466,7 @@ static void spca5xxRegRead(struct usb_device *dev,
466 500); 466 500);
467} 467}
468 468
469static void spca5xxRegWrite(struct usb_device *dev, 469static void reg_w(struct usb_device *dev,
470 __u16 req, 470 __u16 req,
471 __u16 value, 471 __u16 value,
472 __u16 index, 472 __u16 index,
@@ -480,7 +480,8 @@ static void spca5xxRegWrite(struct usb_device *dev,
480 500); 480 500);
481} 481}
482 482
483static int reg_write(struct usb_device *dev, 483/* write req / index / value */
484static int reg_w_riv(struct usb_device *dev,
484 __u16 req, __u16 index, __u16 value) 485 __u16 req, __u16 index, __u16 value)
485{ 486{
486 int ret; 487 int ret;
@@ -490,57 +491,56 @@ static int reg_write(struct usb_device *dev,
490 req, 491 req,
491 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 492 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
492 value, index, NULL, 0, 500); 493 value, index, NULL, 0, 500);
493 PDEBUG(D_PACK, "reg write: 0x%02x,0x%02x:0x%02x, 0x%x", 494 PDEBUG(D_USBO, "reg write: 0x%02x,0x%02x:0x%02x, %d",
494 req, index, value, ret); 495 req, index, value, ret);
495 if (ret < 0) 496 if (ret < 0)
496 PDEBUG(D_ERR, "reg write: error %d", ret); 497 PDEBUG(D_ERR, "reg write: error %d", ret);
497 return ret; 498 return ret;
498} 499}
499 500
500static int reg_read_info(struct usb_device *dev, 501/* read 1 byte */
502static int reg_r_1(struct gspca_dev *gspca_dev,
501 __u16 value) /* wValue */ 503 __u16 value) /* wValue */
502{ 504{
503 int ret; 505 int ret;
504 __u8 data;
505 506
506 ret = usb_control_msg(dev, 507 ret = usb_control_msg(gspca_dev->dev,
507 usb_rcvctrlpipe(dev, 0), 508 usb_rcvctrlpipe(gspca_dev->dev, 0),
508 0x20, /* request */ 509 0x20, /* request */
509 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 510 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
510 value, 511 value,
511 0, /* index */ 512 0, /* index */
512 &data, 1, 513 gspca_dev->usb_buf, 1,
513 500); /* timeout */ 514 500); /* timeout */
514 if (ret < 0) { 515 if (ret < 0) {
515 PDEBUG(D_ERR, "reg_read_info err %d", ret); 516 PDEBUG(D_ERR, "reg_r_1 err %d", ret);
516 return 0; 517 return 0;
517 } 518 }
518 return data; 519 return gspca_dev->usb_buf[0];
519} 520}
520 521
521/* returns: negative is error, pos or zero is data */ 522/* read 1 or 2 bytes - returns < 0 if error */
522static int reg_read(struct usb_device *dev, 523static int reg_r_12(struct gspca_dev *gspca_dev,
523 __u16 req, /* bRequest */ 524 __u16 req, /* bRequest */
524 __u16 index, /* wIndex */ 525 __u16 index, /* wIndex */
525 __u16 length) /* wLength (1 or 2 only) */ 526 __u16 length) /* wLength (1 or 2 only) */
526{ 527{
527 int ret; 528 int ret;
528 __u8 buf[2];
529 529
530 buf[1] = 0; 530 gspca_dev->usb_buf[1] = 0;
531 ret = usb_control_msg(dev, 531 ret = usb_control_msg(gspca_dev->dev,
532 usb_rcvctrlpipe(dev, 0), 532 usb_rcvctrlpipe(gspca_dev->dev, 0),
533 req, 533 req,
534 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 534 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
535 0, /* value */ 535 0, /* value */
536 index, 536 index,
537 buf, length, 537 gspca_dev->usb_buf, length,
538 500); 538 500);
539 if (ret < 0) { 539 if (ret < 0) {
540 PDEBUG(D_ERR, "reg_read err %d", ret); 540 PDEBUG(D_ERR, "reg_read err %d", ret);
541 return -1; 541 return -1;
542 } 542 }
543 return (buf[1] << 8) + buf[0]; 543 return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
544} 544}
545 545
546static int write_vector(struct gspca_dev *gspca_dev, 546static int write_vector(struct gspca_dev *gspca_dev,
@@ -550,7 +550,7 @@ static int write_vector(struct gspca_dev *gspca_dev,
550 int ret, i = 0; 550 int ret, i = 0;
551 551
552 while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) { 552 while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
553 ret = reg_write(dev, data[i][0], data[i][2], data[i][1]); 553 ret = reg_w_riv(dev, data[i][0], data[i][2], data[i][1]);
554 if (ret < 0) { 554 if (ret < 0) {
555 PDEBUG(D_ERR, 555 PDEBUG(D_ERR,
556 "Register write failed for 0x%x,0x%x,0x%x", 556 "Register write failed for 0x%x,0x%x,0x%x",
@@ -573,14 +573,14 @@ static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
573 573
574 /* loop over y components */ 574 /* loop over y components */
575 for (i = 0; i < 64; i++) { 575 for (i = 0; i < 64; i++) {
576 err = reg_write(dev, request, ybase + i, qtable[0][i]); 576 err = reg_w_riv(dev, request, ybase + i, qtable[0][i]);
577 if (err < 0) 577 if (err < 0)
578 return err; 578 return err;
579 } 579 }
580 580
581 /* loop over c components */ 581 /* loop over c components */
582 for (i = 0; i < 64; i++) { 582 for (i = 0; i < 64; i++) {
583 err = reg_write(dev, request, cbase + i, qtable[1][i]); 583 err = reg_w_riv(dev, request, cbase + i, qtable[1][i]);
584 if (err < 0) 584 if (err < 0)
585 return err; 585 return err;
586 } 586 }
@@ -593,14 +593,14 @@ static void spca504_acknowledged_command(struct gspca_dev *gspca_dev,
593 struct usb_device *dev = gspca_dev->dev; 593 struct usb_device *dev = gspca_dev->dev;
594 __u8 notdone; 594 __u8 notdone;
595 595
596 reg_write(dev, req, idx, val); 596 reg_w_riv(dev, req, idx, val);
597 notdone = reg_read(dev, 0x01, 0x0001, 1); 597 notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
598 reg_write(dev, req, idx, val); 598 reg_w_riv(dev, req, idx, val);
599 599
600 PDEBUG(D_FRAM, "before wait 0x%x", notdone); 600 PDEBUG(D_FRAM, "before wait 0x%x", notdone);
601 601
602 msleep(200); 602 msleep(200);
603 notdone = reg_read(dev, 0x01, 0x0001, 1); 603 notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
604 PDEBUG(D_FRAM, "after wait 0x%x", notdone); 604 PDEBUG(D_FRAM, "after wait 0x%x", notdone);
605} 605}
606 606
@@ -612,8 +612,8 @@ static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
612 __u8 status; 612 __u8 status;
613 __u8 endcode; 613 __u8 endcode;
614 614
615 reg_write(dev, req, idx, val); 615 reg_w_riv(dev, req, idx, val);
616 status = reg_read(dev, 0x01, 0x0001, 1); 616 status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
617 endcode = stat; 617 endcode = stat;
618 PDEBUG(D_FRAM, "Status 0x%x Need 0x%x", status, stat); 618 PDEBUG(D_FRAM, "Status 0x%x Need 0x%x", status, stat);
619 if (!count) 619 if (!count)
@@ -622,8 +622,8 @@ static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
622 while (--count > 0) { 622 while (--count > 0) {
623 msleep(10); 623 msleep(10);
624 /* gsmart mini2 write a each wait setting 1 ms is enought */ 624 /* gsmart mini2 write a each wait setting 1 ms is enought */
625/* reg_write(dev, req, idx, val); */ 625/* reg_w_riv(dev, req, idx, val); */
626 status = reg_read(dev, 0x01, 0x0001, 1); 626 status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
627 if (status == endcode) { 627 if (status == endcode) {
628 PDEBUG(D_FRAM, "status 0x%x after wait 0x%x", 628 PDEBUG(D_FRAM, "status 0x%x after wait 0x%x",
629 status, 200 - count); 629 status, 200 - count);
@@ -632,34 +632,31 @@ static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
632 } 632 }
633} 633}
634 634
635static int spca504B_PollingDataReady(struct usb_device *dev) 635static int spca504B_PollingDataReady(struct gspca_dev *gspca_dev)
636{ 636{
637 __u8 DataReady;
638 int count = 10; 637 int count = 10;
639 638
640 while (--count > 0) { 639 while (--count > 0) {
641 spca5xxRegRead(dev, 0x21, 0, &DataReady, 1); 640 reg_r(gspca_dev->dev, 0x21, 0, gspca_dev->usb_buf, 1);
642 if ((DataReady & 0x01) == 0) 641 if ((gspca_dev->usb_buf[0] & 0x01) == 0)
643 break; 642 break;
644 msleep(10); 643 msleep(10);
645 } 644 }
646 return DataReady; 645 return gspca_dev->usb_buf[0];
647} 646}
648 647
649static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev) 648static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
650{ 649{
651 struct usb_device *dev = gspca_dev->dev; 650 struct usb_device *dev = gspca_dev->dev;
652 __u8 DataReady;
653 int count = 50; 651 int count = 50;
654 652
655 while (--count > 0) { 653 while (--count > 0) {
656 spca5xxRegRead(dev, 0x21, 1, &DataReady, 1); 654 reg_r(dev, 0x21, 1, gspca_dev->usb_buf, 1);
657 655 if (gspca_dev->usb_buf[0] != 0) {
658 if (DataReady) { 656 gspca_dev->usb_buf[0] = 0;
659 DataReady = 0; 657 reg_w(dev, 0x21, 0, 1, gspca_dev->usb_buf, 1);
660 spca5xxRegWrite(dev, 0x21, 0, 1, &DataReady, 1); 658 reg_r(dev, 0x21, 1, gspca_dev->usb_buf, 1);
661 spca5xxRegRead(dev, 0x21, 1, &DataReady, 1); 659 spca504B_PollingDataReady(gspca_dev);
662 spca504B_PollingDataReady(dev);
663 break; 660 break;
664 } 661 }
665 msleep(10); 662 msleep(10);
@@ -669,14 +666,15 @@ static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
669static void spca50x_GetFirmware(struct gspca_dev *gspca_dev) 666static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
670{ 667{
671 struct usb_device *dev = gspca_dev->dev; 668 struct usb_device *dev = gspca_dev->dev;
672 __u8 FW[5]; 669 __u8 *data;
673 __u8 ProductInfo[64];
674 670
675 spca5xxRegRead(dev, 0x20, 0, FW, 5); 671 data = kmalloc(64, GFP_KERNEL);
672 reg_r(dev, 0x20, 0, data, 5);
676 PDEBUG(D_STREAM, "FirmWare : %d %d %d %d %d ", 673 PDEBUG(D_STREAM, "FirmWare : %d %d %d %d %d ",
677 FW[0], FW[1], FW[2], FW[3], FW[4]); 674 data[0], data[1], data[2], data[3], data[4]);
678 spca5xxRegRead(dev, 0x23, 0, ProductInfo, 64); 675 reg_r(dev, 0x23, 0, data, 64);
679 spca5xxRegRead(dev, 0x23, 1, ProductInfo, 64); 676 reg_r(dev, 0x23, 1, data, 64);
677 kfree(data);
680} 678}
681 679
682static void spca504B_SetSizeType(struct gspca_dev *gspca_dev) 680static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
@@ -691,32 +689,35 @@ static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
691 Type = 0; 689 Type = 0;
692 switch (sd->bridge) { 690 switch (sd->bridge) {
693 case BRIDGE_SPCA533: 691 case BRIDGE_SPCA533:
694 spca5xxRegWrite(dev, 0x31, 0, 0, NULL, 0); 692 reg_w(dev, 0x31, 0, 0, NULL, 0);
695 spca504B_WaitCmdStatus(gspca_dev); 693 spca504B_WaitCmdStatus(gspca_dev);
696 rc = spca504B_PollingDataReady(dev); 694 rc = spca504B_PollingDataReady(gspca_dev);
697 spca50x_GetFirmware(gspca_dev); 695 spca50x_GetFirmware(gspca_dev);
698 Type = 2; 696 gspca_dev->usb_buf[0] = 2; /* type */
699 spca5xxRegWrite(dev, 0x24, 0, 8, &Type, 1); 697 reg_w(dev, 0x24, 0, 8, gspca_dev->usb_buf, 1);
700 spca5xxRegRead(dev, 0x24, 8, &Type, 1); 698 reg_r(dev, 0x24, 8, gspca_dev->usb_buf, 1);
701 699
702 spca5xxRegWrite(dev, 0x25, 0, 4, &Size, 1); 700 gspca_dev->usb_buf[0] = Size;
703 spca5xxRegRead(dev, 0x25, 4, &Size, 1); 701 reg_w(dev, 0x25, 0, 4, gspca_dev->usb_buf, 1);
704 rc = spca504B_PollingDataReady(dev); 702 reg_r(dev, 0x25, 4, gspca_dev->usb_buf, 1); /* size */
703 rc = spca504B_PollingDataReady(gspca_dev);
705 704
706 /* Init the cam width height with some values get on init ? */ 705 /* Init the cam width height with some values get on init ? */
707 spca5xxRegWrite(dev, 0x31, 0, 4, NULL, 0); 706 reg_w(dev, 0x31, 0, 4, NULL, 0);
708 spca504B_WaitCmdStatus(gspca_dev); 707 spca504B_WaitCmdStatus(gspca_dev);
709 rc = spca504B_PollingDataReady(dev); 708 rc = spca504B_PollingDataReady(gspca_dev);
710 break; 709 break;
711 default: 710 default:
712/* case BRIDGE_SPCA504B: */ 711/* case BRIDGE_SPCA504B: */
713/* case BRIDGE_SPCA536: */ 712/* case BRIDGE_SPCA536: */
713 gspca_dev->usb_buf[0] = Size;
714 reg_w(dev, 0x25, 0, 4, gspca_dev->usb_buf, 1);
715 reg_r(dev, 0x25, 4, gspca_dev->usb_buf, 1); /* size */
714 Type = 6; 716 Type = 6;
715 spca5xxRegWrite(dev, 0x25, 0, 4, &Size, 1); 717 gspca_dev->usb_buf[0] = Type;
716 spca5xxRegRead(dev, 0x25, 4, &Size, 1); 718 reg_w(dev, 0x27, 0, 0, gspca_dev->usb_buf, 1);
717 spca5xxRegWrite(dev, 0x27, 0, 0, &Type, 1); 719 reg_r(dev, 0x27, 0, gspca_dev->usb_buf, 1); /* type */
718 spca5xxRegRead(dev, 0x27, 0, &Type, 1); 720 rc = spca504B_PollingDataReady(gspca_dev);
719 rc = spca504B_PollingDataReady(dev);
720 break; 721 break;
721 case BRIDGE_SPCA504: 722 case BRIDGE_SPCA504:
722 Size += 3; 723 Size += 3;
@@ -733,21 +734,20 @@ static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
733 break; 734 break;
734 case BRIDGE_SPCA504C: 735 case BRIDGE_SPCA504C:
735 /* capture mode */ 736 /* capture mode */
736 reg_write(dev, 0xa0, (0x0500 | (Size & 0x0f)), 0x0); 737 reg_w_riv(dev, 0xa0, (0x0500 | (Size & 0x0f)), 0x00);
737 reg_write(dev, 0x20, 0x01, 0x0500 | (Size & 0x0f)); 738 reg_w_riv(dev, 0x20, 0x01, 0x0500 | (Size & 0x0f));
738 break; 739 break;
739 } 740 }
740} 741}
741 742
742static void spca504_wait_status(struct gspca_dev *gspca_dev) 743static void spca504_wait_status(struct gspca_dev *gspca_dev)
743{ 744{
744 struct usb_device *dev = gspca_dev->dev;
745 int cnt; 745 int cnt;
746 746
747 cnt = 256; 747 cnt = 256;
748 while (--cnt > 0) { 748 while (--cnt > 0) {
749 /* With this we get the status, when return 0 it's all ok */ 749 /* With this we get the status, when return 0 it's all ok */
750 if (reg_read(dev, 0x06, 0x00, 1) == 0) 750 if (reg_r_12(gspca_dev, 0x06, 0x00, 1) == 0)
751 return; 751 return;
752 msleep(10); 752 msleep(10);
753 } 753 }
@@ -756,11 +756,11 @@ static void spca504_wait_status(struct gspca_dev *gspca_dev)
756static void spca504B_setQtable(struct gspca_dev *gspca_dev) 756static void spca504B_setQtable(struct gspca_dev *gspca_dev)
757{ 757{
758 struct usb_device *dev = gspca_dev->dev; 758 struct usb_device *dev = gspca_dev->dev;
759 __u8 Data = 3;
760 759
761 spca5xxRegWrite(dev, 0x26, 0, 0, &Data, 1); 760 gspca_dev->usb_buf[0] = 3;
762 spca5xxRegRead(dev, 0x26, 0, &Data, 1); 761 reg_w(dev, 0x26, 0, 0, gspca_dev->usb_buf, 1);
763 spca504B_PollingDataReady(dev); 762 reg_r(dev, 0x26, 0, gspca_dev->usb_buf, 1);
763 spca504B_PollingDataReady(gspca_dev);
764} 764}
765 765
766static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev) 766static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev)
@@ -777,24 +777,24 @@ static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev)
777 default: 777 default:
778/* case BRIDGE_SPCA533: */ 778/* case BRIDGE_SPCA533: */
779/* case BRIDGE_SPCA504B: */ 779/* case BRIDGE_SPCA504B: */
780 spca5xxRegWrite(dev, 0, 0, 0x21a7, NULL, 0); /* brightness */ 780 reg_w(dev, 0, 0, 0x21a7, NULL, 0); /* brightness */
781 spca5xxRegWrite(dev, 0, 0x20, 0x21a8, NULL, 0); /* contrast */ 781 reg_w(dev, 0, 0x20, 0x21a8, NULL, 0); /* contrast */
782 spca5xxRegWrite(dev, 0, 0, 0x21ad, NULL, 0); /* hue */ 782 reg_w(dev, 0, 0, 0x21ad, NULL, 0); /* hue */
783 spca5xxRegWrite(dev, 0, 1, 0x21ac, NULL, 0); /* sat/hue */ 783 reg_w(dev, 0, 1, 0x21ac, NULL, 0); /* sat/hue */
784 spca5xxRegWrite(dev, 0, 0x20, 0x21ae, NULL, 0); /* saturation */ 784 reg_w(dev, 0, 0x20, 0x21ae, NULL, 0); /* saturation */
785 spca5xxRegWrite(dev, 0, 0, 0x21a3, NULL, 0); /* gamma */ 785 reg_w(dev, 0, 0, 0x21a3, NULL, 0); /* gamma */
786 break; 786 break;
787 case BRIDGE_SPCA536: 787 case BRIDGE_SPCA536:
788 spca5xxRegWrite(dev, 0, 0, 0x20f0, NULL, 0); 788 reg_w(dev, 0, 0, 0x20f0, NULL, 0);
789 spca5xxRegWrite(dev, 0, 0x21, 0x20f1, NULL, 0); 789 reg_w(dev, 0, 0x21, 0x20f1, NULL, 0);
790 spca5xxRegWrite(dev, 0, 0x40, 0x20f5, NULL, 0); 790 reg_w(dev, 0, 0x40, 0x20f5, NULL, 0);
791 spca5xxRegWrite(dev, 0, 1, 0x20f4, NULL, 0); 791 reg_w(dev, 0, 1, 0x20f4, NULL, 0);
792 spca5xxRegWrite(dev, 0, 0x40, 0x20f6, NULL, 0); 792 reg_w(dev, 0, 0x40, 0x20f6, NULL, 0);
793 spca5xxRegWrite(dev, 0, 0, 0x2089, NULL, 0); 793 reg_w(dev, 0, 0, 0x2089, NULL, 0);
794 break; 794 break;
795 } 795 }
796 if (pollreg) 796 if (pollreg)
797 spca504B_PollingDataReady(dev); 797 spca504B_PollingDataReady(gspca_dev);
798} 798}
799 799
800/* this function is called at probe time */ 800/* this function is called at probe time */
@@ -872,7 +872,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
872 case 0x504a: 872 case 0x504a:
873/* try to get the firmware as some cam answer 2.0.1.2.2 873/* try to get the firmware as some cam answer 2.0.1.2.2
874 * and should be a spca504b then overwrite that setting */ 874 * and should be a spca504b then overwrite that setting */
875 spca5xxRegRead(dev, 0x20, 0, &fw, 1); 875 reg_r(dev, 0x20, 0, gspca_dev->usb_buf, 1);
876 fw = gspca_dev->usb_buf[0];
876 if (fw == 1) { 877 if (fw == 1) {
877 sd->subtype = AiptekMiniPenCam13; 878 sd->subtype = AiptekMiniPenCam13;
878 sd->bridge = BRIDGE_SPCA504; 879 sd->bridge = BRIDGE_SPCA504;
@@ -1048,38 +1049,37 @@ static int sd_open(struct gspca_dev *gspca_dev)
1048 struct sd *sd = (struct sd *) gspca_dev; 1049 struct sd *sd = (struct sd *) gspca_dev;
1049 struct usb_device *dev = gspca_dev->dev; 1050 struct usb_device *dev = gspca_dev->dev;
1050 int rc; 1051 int rc;
1051 __u8 Data;
1052 __u8 i; 1052 __u8 i;
1053 __u8 info[6]; 1053 __u8 info[6];
1054 int err_code; 1054 int err_code;
1055 1055
1056 switch (sd->bridge) { 1056 switch (sd->bridge) {
1057 case BRIDGE_SPCA504B: 1057 case BRIDGE_SPCA504B:
1058 spca5xxRegWrite(dev, 0x1d, 0, 0, NULL, 0); 1058 reg_w(dev, 0x1d, 0, 0, NULL, 0);
1059 spca5xxRegWrite(dev, 0, 1, 0x2306, NULL, 0); 1059 reg_w(dev, 0, 1, 0x2306, NULL, 0);
1060 spca5xxRegWrite(dev, 0, 0, 0x0d04, NULL, 0); 1060 reg_w(dev, 0, 0, 0x0d04, NULL, 0);
1061 spca5xxRegWrite(dev, 0, 0, 0x2000, NULL, 0); 1061 reg_w(dev, 0, 0, 0x2000, NULL, 0);
1062 spca5xxRegWrite(dev, 0, 0x13, 0x2301, NULL, 0); 1062 reg_w(dev, 0, 0x13, 0x2301, NULL, 0);
1063 spca5xxRegWrite(dev, 0, 0, 0x2306, NULL, 0); 1063 reg_w(dev, 0, 0, 0x2306, NULL, 0);
1064 /* fall thru */ 1064 /* fall thru */
1065 case BRIDGE_SPCA533: 1065 case BRIDGE_SPCA533:
1066 rc = spca504B_PollingDataReady(dev); 1066 rc = spca504B_PollingDataReady(gspca_dev);
1067 spca50x_GetFirmware(gspca_dev); 1067 spca50x_GetFirmware(gspca_dev);
1068 break; 1068 break;
1069 case BRIDGE_SPCA536: 1069 case BRIDGE_SPCA536:
1070 spca50x_GetFirmware(gspca_dev); 1070 spca50x_GetFirmware(gspca_dev);
1071 spca5xxRegRead(dev, 0x00, 0x5002, &Data, 1); 1071 reg_r(dev, 0x00, 0x5002, gspca_dev->usb_buf, 1);
1072 Data = 0; 1072 gspca_dev->usb_buf[0] = 0;
1073 spca5xxRegWrite(dev, 0x24, 0, 0, &Data, 1); 1073 reg_w(dev, 0x24, 0, 0, gspca_dev->usb_buf, 1);
1074 spca5xxRegRead(dev, 0x24, 0, &Data, 1); 1074 reg_r(dev, 0x24, 0, gspca_dev->usb_buf, 1);
1075 rc = spca504B_PollingDataReady(dev); 1075 rc = spca504B_PollingDataReady(gspca_dev);
1076 spca5xxRegWrite(dev, 0x34, 0, 0, NULL, 0); 1076 reg_w(dev, 0x34, 0, 0, NULL, 0);
1077 spca504B_WaitCmdStatus(gspca_dev); 1077 spca504B_WaitCmdStatus(gspca_dev);
1078 break; 1078 break;
1079 case BRIDGE_SPCA504C: /* pccam600 */ 1079 case BRIDGE_SPCA504C: /* pccam600 */
1080 PDEBUG(D_STREAM, "Opening SPCA504 (PC-CAM 600)"); 1080 PDEBUG(D_STREAM, "Opening SPCA504 (PC-CAM 600)");
1081 reg_write(dev, 0xe0, 0x0000, 0x0000); 1081 reg_w_riv(dev, 0xe0, 0x0000, 0x0000);
1082 reg_write(dev, 0xe0, 0x0000, 0x0001); /* reset */ 1082 reg_w_riv(dev, 0xe0, 0x0000, 0x0001); /* reset */
1083 spca504_wait_status(gspca_dev); 1083 spca504_wait_status(gspca_dev);
1084 if (sd->subtype == LogitechClickSmart420) 1084 if (sd->subtype == LogitechClickSmart420)
1085 write_vector(gspca_dev, 1085 write_vector(gspca_dev,
@@ -1100,7 +1100,7 @@ static int sd_open(struct gspca_dev *gspca_dev)
1100 if (sd->subtype == AiptekMiniPenCam13) { 1100 if (sd->subtype == AiptekMiniPenCam13) {
1101 /*****************************/ 1101 /*****************************/
1102 for (i = 0; i < 6; i++) 1102 for (i = 0; i < 6; i++)
1103 info[i] = reg_read_info(dev, i); 1103 info[i] = reg_r_1(gspca_dev, i);
1104 PDEBUG(D_STREAM, 1104 PDEBUG(D_STREAM,
1105 "Read info: %d %d %d %d %d %d." 1105 "Read info: %d %d %d %d %d %d."
1106 " Should be 1,0,2,2,0,0", 1106 " Should be 1,0,2,2,0,0",
@@ -1126,14 +1126,14 @@ static int sd_open(struct gspca_dev *gspca_dev)
1126 6, 0, 0x86, 1); */ 1126 6, 0, 0x86, 1); */
1127/* spca504A_acknowledged_command (gspca_dev, 0x24, 1127/* spca504A_acknowledged_command (gspca_dev, 0x24,
1128 0, 0, 0x9D, 1); */ 1128 0, 0, 0x9D, 1); */
1129 reg_write(dev, 0x0, 0x270c, 0x5); /* L92 sno1t.txt */ 1129 reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */
1130 reg_write(dev, 0x0, 0x2310, 0x5); 1130 reg_w_riv(dev, 0x0, 0x2310, 0x05);
1131 spca504A_acknowledged_command(gspca_dev, 0x01, 1131 spca504A_acknowledged_command(gspca_dev, 0x01,
1132 0x0f, 0, 0xff, 0); 1132 0x0f, 0, 0xff, 0);
1133 } 1133 }
1134 /* setup qtable */ 1134 /* setup qtable */
1135 reg_write(dev, 0, 0x2000, 0); 1135 reg_w_riv(dev, 0, 0x2000, 0);
1136 reg_write(dev, 0, 0x2883, 1); 1136 reg_w_riv(dev, 0, 0x2883, 1);
1137 err_code = spca50x_setup_qtable(gspca_dev, 1137 err_code = spca50x_setup_qtable(gspca_dev,
1138 0x00, 0x2800, 1138 0x00, 0x2800,
1139 0x2840, 1139 0x2840,
@@ -1166,20 +1166,20 @@ static void sd_start(struct gspca_dev *gspca_dev)
1166/* case BRIDGE_SPCA536: */ 1166/* case BRIDGE_SPCA536: */
1167 if (sd->subtype == MegapixV4 || 1167 if (sd->subtype == MegapixV4 ||
1168 sd->subtype == LogitechClickSmart820) { 1168 sd->subtype == LogitechClickSmart820) {
1169 spca5xxRegWrite(dev, 0xf0, 0, 0, NULL, 0); 1169 reg_w(dev, 0xf0, 0, 0, NULL, 0);
1170 spca504B_WaitCmdStatus(gspca_dev); 1170 spca504B_WaitCmdStatus(gspca_dev);
1171 spca5xxRegRead(dev, 0xf0, 4, NULL, 0); 1171 reg_r(dev, 0xf0, 4, NULL, 0);
1172 spca504B_WaitCmdStatus(gspca_dev); 1172 spca504B_WaitCmdStatus(gspca_dev);
1173 } else { 1173 } else {
1174 spca5xxRegWrite(dev, 0x31, 0, 4, NULL, 0); 1174 reg_w(dev, 0x31, 0, 4, NULL, 0);
1175 spca504B_WaitCmdStatus(gspca_dev); 1175 spca504B_WaitCmdStatus(gspca_dev);
1176 rc = spca504B_PollingDataReady(dev); 1176 rc = spca504B_PollingDataReady(gspca_dev);
1177 } 1177 }
1178 break; 1178 break;
1179 case BRIDGE_SPCA504: 1179 case BRIDGE_SPCA504:
1180 if (sd->subtype == AiptekMiniPenCam13) { 1180 if (sd->subtype == AiptekMiniPenCam13) {
1181 for (i = 0; i < 6; i++) 1181 for (i = 0; i < 6; i++)
1182 info[i] = reg_read_info(dev, i); 1182 info[i] = reg_r_1(gspca_dev, i);
1183 PDEBUG(D_STREAM, 1183 PDEBUG(D_STREAM,
1184 "Read info: %d %d %d %d %d %d." 1184 "Read info: %d %d %d %d %d %d."
1185 " Should be 1,0,2,2,0,0", 1185 " Should be 1,0,2,2,0,0",
@@ -1197,7 +1197,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
1197 } else { 1197 } else {
1198 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3); 1198 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
1199 for (i = 0; i < 6; i++) 1199 for (i = 0; i < 6; i++)
1200 info[i] = reg_read_info(dev, i); 1200 info[i] = reg_r_1(gspca_dev, i);
1201 PDEBUG(D_STREAM, 1201 PDEBUG(D_STREAM,
1202 "Read info: %d %d %d %d %d %d." 1202 "Read info: %d %d %d %d %d %d."
1203 " Should be 1,0,2,2,0,0", 1203 " Should be 1,0,2,2,0,0",
@@ -1207,8 +1207,8 @@ static void sd_start(struct gspca_dev *gspca_dev)
1207 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); 1207 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
1208 } 1208 }
1209 spca504B_SetSizeType(gspca_dev); 1209 spca504B_SetSizeType(gspca_dev);
1210 reg_write(dev, 0x0, 0x270c, 0x5); /* L92 sno1t.txt */ 1210 reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */
1211 reg_write(dev, 0x0, 0x2310, 0x5); 1211 reg_w_riv(dev, 0x0, 0x2310, 0x05);
1212 break; 1212 break;
1213 case BRIDGE_SPCA504C: 1213 case BRIDGE_SPCA504C:
1214 if (sd->subtype == LogitechClickSmart420) { 1214 if (sd->subtype == LogitechClickSmart420) {
@@ -1217,13 +1217,13 @@ static void sd_start(struct gspca_dev *gspca_dev)
1217 } else { 1217 } else {
1218 write_vector(gspca_dev, spca504_pccam600_init_data); 1218 write_vector(gspca_dev, spca504_pccam600_init_data);
1219 } 1219 }
1220 enable = (sd->autogain ? 0x4 : 0x1); 1220 enable = (sd->autogain ? 0x04 : 0x01);
1221 reg_write(dev, 0x0c, 0x0000, enable); /* auto exposure */ 1221 reg_w_riv(dev, 0x0c, 0x0000, enable); /* auto exposure */
1222 reg_write(dev, 0xb0, 0x0000, enable); /* auto whiteness */ 1222 reg_w_riv(dev, 0xb0, 0x0000, enable); /* auto whiteness */
1223 1223
1224 /* set default exposure compensation and whiteness balance */ 1224 /* set default exposure compensation and whiteness balance */
1225 reg_write(dev, 0x30, 0x0001, 800); /* ~ 20 fps */ 1225 reg_w_riv(dev, 0x30, 0x0001, 800); /* ~ 20 fps */
1226 reg_write(dev, 0x30, 0x0002, 1600); 1226 reg_w_riv(dev, 0x30, 0x0002, 1600);
1227 spca504B_SetSizeType(gspca_dev); 1227 spca504B_SetSizeType(gspca_dev);
1228 break; 1228 break;
1229 } 1229 }
@@ -1240,13 +1240,13 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1240/* case BRIDGE_SPCA533: */ 1240/* case BRIDGE_SPCA533: */
1241/* case BRIDGE_SPCA536: */ 1241/* case BRIDGE_SPCA536: */
1242/* case BRIDGE_SPCA504B: */ 1242/* case BRIDGE_SPCA504B: */
1243 spca5xxRegWrite(dev, 0x31, 0, 0, NULL, 0); 1243 reg_w(dev, 0x31, 0, 0, NULL, 0);
1244 spca504B_WaitCmdStatus(gspca_dev); 1244 spca504B_WaitCmdStatus(gspca_dev);
1245 spca504B_PollingDataReady(dev); 1245 spca504B_PollingDataReady(gspca_dev);
1246 break; 1246 break;
1247 case BRIDGE_SPCA504: 1247 case BRIDGE_SPCA504:
1248 case BRIDGE_SPCA504C: 1248 case BRIDGE_SPCA504C:
1249 reg_write(dev, 0x00, 0x2000, 0x0000); 1249 reg_w_riv(dev, 0x00, 0x2000, 0x0000);
1250 1250
1251 if (sd->subtype == AiptekMiniPenCam13) { 1251 if (sd->subtype == AiptekMiniPenCam13) {
1252 /* spca504a aiptek */ 1252 /* spca504a aiptek */
@@ -1258,7 +1258,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1258 0x0f, 0x00, 0xff, 1); 1258 0x0f, 0x00, 0xff, 1);
1259 } else { 1259 } else {
1260 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); 1260 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
1261 reg_write(dev, 0x01, 0x000f, 0x0); 1261 reg_w_riv(dev, 0x01, 0x000f, 0x00);
1262 } 1262 }
1263 break; 1263 break;
1264 } 1264 }
@@ -1383,10 +1383,10 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1383/* case BRIDGE_SPCA504B: */ 1383/* case BRIDGE_SPCA504B: */
1384/* case BRIDGE_SPCA504: */ 1384/* case BRIDGE_SPCA504: */
1385/* case BRIDGE_SPCA504C: */ 1385/* case BRIDGE_SPCA504C: */
1386 reg_write(dev, 0x0, 0x21a7, sd->brightness); 1386 reg_w_riv(dev, 0x0, 0x21a7, sd->brightness);
1387 break; 1387 break;
1388 case BRIDGE_SPCA536: 1388 case BRIDGE_SPCA536:
1389 reg_write(dev, 0x0, 0x20f0, sd->brightness); 1389 reg_w_riv(dev, 0x0, 0x20f0, sd->brightness);
1390 break; 1390 break;
1391 } 1391 }
1392} 1392}
@@ -1394,7 +1394,6 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1394static void getbrightness(struct gspca_dev *gspca_dev) 1394static void getbrightness(struct gspca_dev *gspca_dev)
1395{ 1395{
1396 struct sd *sd = (struct sd *) gspca_dev; 1396 struct sd *sd = (struct sd *) gspca_dev;
1397 struct usb_device *dev = gspca_dev->dev;
1398 __u16 brightness = 0; 1397 __u16 brightness = 0;
1399 1398
1400 switch (sd->bridge) { 1399 switch (sd->bridge) {
@@ -1403,10 +1402,10 @@ static void getbrightness(struct gspca_dev *gspca_dev)
1403/* case BRIDGE_SPCA504B: */ 1402/* case BRIDGE_SPCA504B: */
1404/* case BRIDGE_SPCA504: */ 1403/* case BRIDGE_SPCA504: */
1405/* case BRIDGE_SPCA504C: */ 1404/* case BRIDGE_SPCA504C: */
1406 brightness = reg_read(dev, 0x0, 0x21a7, 2); 1405 brightness = reg_r_12(gspca_dev, 0x00, 0x21a7, 2);
1407 break; 1406 break;
1408 case BRIDGE_SPCA536: 1407 case BRIDGE_SPCA536:
1409 brightness = reg_read(dev, 0x0, 0x20f0, 2); 1408 brightness = reg_r_12(gspca_dev, 0x00, 0x20f0, 2);
1410 break; 1409 break;
1411 } 1410 }
1412 sd->brightness = ((brightness & 0xff) - 128) % 255; 1411 sd->brightness = ((brightness & 0xff) - 128) % 255;
@@ -1423,10 +1422,10 @@ static void setcontrast(struct gspca_dev *gspca_dev)
1423/* case BRIDGE_SPCA504B: */ 1422/* case BRIDGE_SPCA504B: */
1424/* case BRIDGE_SPCA504: */ 1423/* case BRIDGE_SPCA504: */
1425/* case BRIDGE_SPCA504C: */ 1424/* case BRIDGE_SPCA504C: */
1426 reg_write(dev, 0x0, 0x21a8, sd->contrast); 1425 reg_w_riv(dev, 0x0, 0x21a8, sd->contrast);
1427 break; 1426 break;
1428 case BRIDGE_SPCA536: 1427 case BRIDGE_SPCA536:
1429 reg_write(dev, 0x0, 0x20f1, sd->contrast); 1428 reg_w_riv(dev, 0x0, 0x20f1, sd->contrast);
1430 break; 1429 break;
1431 } 1430 }
1432} 1431}
@@ -1434,7 +1433,6 @@ static void setcontrast(struct gspca_dev *gspca_dev)
1434static void getcontrast(struct gspca_dev *gspca_dev) 1433static void getcontrast(struct gspca_dev *gspca_dev)
1435{ 1434{
1436 struct sd *sd = (struct sd *) gspca_dev; 1435 struct sd *sd = (struct sd *) gspca_dev;
1437 struct usb_device *dev = gspca_dev->dev;
1438 1436
1439 switch (sd->bridge) { 1437 switch (sd->bridge) {
1440 default: 1438 default:
@@ -1442,10 +1440,10 @@ static void getcontrast(struct gspca_dev *gspca_dev)
1442/* case BRIDGE_SPCA504B: */ 1440/* case BRIDGE_SPCA504B: */
1443/* case BRIDGE_SPCA504: */ 1441/* case BRIDGE_SPCA504: */
1444/* case BRIDGE_SPCA504C: */ 1442/* case BRIDGE_SPCA504C: */
1445 sd->contrast = reg_read(dev, 0x0, 0x21a8, 2); 1443 sd->contrast = reg_r_12(gspca_dev, 0x00, 0x21a8, 2);
1446 break; 1444 break;
1447 case BRIDGE_SPCA536: 1445 case BRIDGE_SPCA536:
1448 sd->contrast = reg_read(dev, 0x0, 0x20f1, 2); 1446 sd->contrast = reg_r_12(gspca_dev, 0x00, 0x20f1, 2);
1449 break; 1447 break;
1450 } 1448 }
1451} 1449}
@@ -1461,10 +1459,10 @@ static void setcolors(struct gspca_dev *gspca_dev)
1461/* case BRIDGE_SPCA504B: */ 1459/* case BRIDGE_SPCA504B: */
1462/* case BRIDGE_SPCA504: */ 1460/* case BRIDGE_SPCA504: */
1463/* case BRIDGE_SPCA504C: */ 1461/* case BRIDGE_SPCA504C: */
1464 reg_write(dev, 0x0, 0x21ae, sd->colors); 1462 reg_w_riv(dev, 0x0, 0x21ae, sd->colors);
1465 break; 1463 break;
1466 case BRIDGE_SPCA536: 1464 case BRIDGE_SPCA536:
1467 reg_write(dev, 0x0, 0x20f6, sd->colors); 1465 reg_w_riv(dev, 0x0, 0x20f6, sd->colors);
1468 break; 1466 break;
1469 } 1467 }
1470} 1468}
@@ -1472,7 +1470,6 @@ static void setcolors(struct gspca_dev *gspca_dev)
1472static void getcolors(struct gspca_dev *gspca_dev) 1470static void getcolors(struct gspca_dev *gspca_dev)
1473{ 1471{
1474 struct sd *sd = (struct sd *) gspca_dev; 1472 struct sd *sd = (struct sd *) gspca_dev;
1475 struct usb_device *dev = gspca_dev->dev;
1476 1473
1477 switch (sd->bridge) { 1474 switch (sd->bridge) {
1478 default: 1475 default:
@@ -1480,10 +1477,10 @@ static void getcolors(struct gspca_dev *gspca_dev)
1480/* case BRIDGE_SPCA504B: */ 1477/* case BRIDGE_SPCA504B: */
1481/* case BRIDGE_SPCA504: */ 1478/* case BRIDGE_SPCA504: */
1482/* case BRIDGE_SPCA504C: */ 1479/* case BRIDGE_SPCA504C: */
1483 sd->colors = reg_read(dev, 0x0, 0x21ae, 2) >> 1; 1480 sd->colors = reg_r_12(gspca_dev, 0x00, 0x21ae, 2) >> 1;
1484 break; 1481 break;
1485 case BRIDGE_SPCA536: 1482 case BRIDGE_SPCA536:
1486 sd->colors = reg_read(dev, 0x0, 0x20f6, 2) >> 1; 1483 sd->colors = reg_r_12(gspca_dev, 0x00, 0x20f6, 2) >> 1;
1487 break; 1484 break;
1488 } 1485 }
1489} 1486}
diff --git a/drivers/media/video/gspca/t613.c b/drivers/media/video/gspca/t613.c
index 299f84584e82..00f47e463a05 100644
--- a/drivers/media/video/gspca/t613.c
+++ b/drivers/media/video/gspca/t613.c
@@ -26,8 +26,8 @@
26 26
27#define MODULE_NAME "t613" 27#define MODULE_NAME "t613"
28#include "gspca.h" 28#include "gspca.h"
29#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 29#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
30static const char version[] = "2.1.5"; 30static const char version[] = "2.1.7";
31 31
32#define MAX_GAMMA 0x10 /* 0 to 15 */ 32#define MAX_GAMMA 0x10 /* 0 to 15 */
33 33
@@ -365,48 +365,49 @@ static const __u8 tas5130a_sensor_init[][8] = {
365 {}, 365 {},
366}; 366};
367 367
368static void t16RegRead(struct usb_device *dev, 368/* read 1 byte */
369 __u16 index, __u8 *buffer, __u16 length) 369static int reg_r_1(struct gspca_dev *gspca_dev,
370 __u16 index)
370{ 371{
371 usb_control_msg(dev, 372 usb_control_msg(gspca_dev->dev,
372 usb_rcvctrlpipe(dev, 0), 373 usb_rcvctrlpipe(gspca_dev->dev, 0),
373 0, /* request */ 374 0, /* request */
374 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 375 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
375 0, /* value */ 376 0, /* value */
376 index, buffer, length, 500); 377 index,
378 gspca_dev->usb_buf, 1, 500);
379 return gspca_dev->usb_buf[0];
377} 380}
378 381
379static void t16RegWrite(struct usb_device *dev, 382static void reg_w(struct gspca_dev *gspca_dev,
380 __u16 value, 383 __u16 value,
381 __u16 index, 384 __u16 index,
382 const __u8 *buffer, __u16 len) 385 const __u8 *buffer, __u16 len)
383{ 386{
384 if (buffer == NULL) { 387 if (buffer == NULL) {
385 usb_control_msg(dev, 388 usb_control_msg(gspca_dev->dev,
386 usb_sndctrlpipe(dev, 0), 389 usb_sndctrlpipe(gspca_dev->dev, 0),
387 0, 390 0,
388 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 391 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
389 value, index, 392 value, index,
390 NULL, 0, 500); 393 NULL, 0, 500);
391 return; 394 return;
392 } 395 }
393 if (len < 16) { 396 if (len <= sizeof gspca_dev->usb_buf) {
394 __u8 tmpbuf[16]; 397 memcpy(gspca_dev->usb_buf, buffer, len);
395 398 usb_control_msg(gspca_dev->dev,
396 memcpy(tmpbuf, buffer, len); 399 usb_sndctrlpipe(gspca_dev->dev, 0),
397 usb_control_msg(dev,
398 usb_sndctrlpipe(dev, 0),
399 0, 400 0,
400 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 401 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
401 value, index, 402 value, index,
402 tmpbuf, len, 500); 403 gspca_dev->usb_buf, len, 500);
403 } else { 404 } else {
404 __u8 *tmpbuf; 405 __u8 *tmpbuf;
405 406
406 tmpbuf = kmalloc(len, GFP_KERNEL); 407 tmpbuf = kmalloc(len, GFP_KERNEL);
407 memcpy(tmpbuf, buffer, len); 408 memcpy(tmpbuf, buffer, len);
408 usb_control_msg(dev, 409 usb_control_msg(gspca_dev->dev,
409 usb_sndctrlpipe(dev, 0), 410 usb_sndctrlpipe(gspca_dev->dev, 0),
410 0, 411 0,
411 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 412 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
412 value, index, 413 value, index,
@@ -443,8 +444,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
443 444
444static int init_default_parameters(struct gspca_dev *gspca_dev) 445static int init_default_parameters(struct gspca_dev *gspca_dev)
445{ 446{
446 struct usb_device *dev = gspca_dev->dev;
447
448 /* some of this registers are not really neded, because 447 /* some of this registers are not really neded, because
449 * they are overriden by setbrigthness, setcontrast, etc, 448 * they are overriden by setbrigthness, setcontrast, etc,
450 * but wont hurt anyway, and can help someone with similar webcam 449 * but wont hurt anyway, and can help someone with similar webcam
@@ -509,49 +508,49 @@ static int init_default_parameters(struct gspca_dev *gspca_dev)
509 static const __u8 nset10[6] = 508 static const __u8 nset10[6] =
510 { 0x0c, 0x03, 0xab, 0x10, 0x81, 0x20 }; 509 { 0x0c, 0x03, 0xab, 0x10, 0x81, 0x20 };
511 510
512 t16RegWrite(dev, 0x01, 0x0000, n1, 0x06); 511 reg_w(gspca_dev, 0x01, 0x0000, n1, 0x06);
513 t16RegWrite(dev, 0x01, 0x0000, nset, 0x06); 512 reg_w(gspca_dev, 0x01, 0x0000, nset, 0x06);
514 t16RegRead(dev, 0x0063, &test_byte, 1); 513 reg_r_1(gspca_dev, 0x0063);
515 t16RegWrite(dev, 0x01, 0x0000, n2, 0x02); 514 reg_w(gspca_dev, 0x01, 0x0000, n2, 0x02);
516 515
517 while (read_indexs[i] != 0x00) { 516 while (read_indexs[i] != 0x00) {
518 t16RegRead(dev, read_indexs[i], &test_byte, 1); 517 test_byte = reg_r_1(gspca_dev, read_indexs[i]);
519 PDEBUG(D_CONF, "Reg 0x%x => 0x%x", read_indexs[i], 518 PDEBUG(D_CONF, "Reg 0x%02x => 0x%02x", read_indexs[i],
520 test_byte); 519 test_byte);
521 i++; 520 i++;
522 } 521 }
523 522
524 t16RegWrite(dev, 0x01, 0x0000, n3, 0x06); 523 reg_w(gspca_dev, 0x01, 0x0000, n3, 0x06);
525 t16RegWrite(dev, 0x01, 0x0000, n4, 0x46); 524 reg_w(gspca_dev, 0x01, 0x0000, n4, 0x46);
526 t16RegRead(dev, 0x0080, &test_byte, 1); 525 reg_r_1(gspca_dev, 0x0080);
527 t16RegWrite(dev, 0x00, 0x2c80, NULL, 0); 526 reg_w(gspca_dev, 0x00, 0x2c80, NULL, 0);
528 t16RegWrite(dev, 0x01, 0x0000, nset2, 0x14); 527 reg_w(gspca_dev, 0x01, 0x0000, nset2, 0x14);
529 t16RegWrite(dev, 0x01, 0x0000, nset3, 0x12); 528 reg_w(gspca_dev, 0x01, 0x0000, nset3, 0x12);
530 t16RegWrite(dev, 0x01, 0x0000, nset4, 0x12); 529 reg_w(gspca_dev, 0x01, 0x0000, nset4, 0x12);
531 t16RegWrite(dev, 0x00, 0x3880, NULL, 0); 530 reg_w(gspca_dev, 0x00, 0x3880, NULL, 0);
532 t16RegWrite(dev, 0x00, 0x3880, NULL, 0); 531 reg_w(gspca_dev, 0x00, 0x3880, NULL, 0);
533 t16RegWrite(dev, 0x00, 0x338e, NULL, 0); 532 reg_w(gspca_dev, 0x00, 0x338e, NULL, 0);
534 t16RegWrite(dev, 0x01, 0x0000, nset5, 0x04); 533 reg_w(gspca_dev, 0x01, 0x0000, nset5, 0x04);
535 t16RegWrite(dev, 0x00, 0x00a9, NULL, 0); 534 reg_w(gspca_dev, 0x00, 0x00a9, NULL, 0);
536 t16RegWrite(dev, 0x01, 0x0000, nset6, 0x22); 535 reg_w(gspca_dev, 0x01, 0x0000, nset6, 0x22);
537 t16RegWrite(dev, 0x00, 0x86bb, NULL, 0); 536 reg_w(gspca_dev, 0x00, 0x86bb, NULL, 0);
538 t16RegWrite(dev, 0x00, 0x4aa6, NULL, 0); 537 reg_w(gspca_dev, 0x00, 0x4aa6, NULL, 0);
539 538
540 t16RegWrite(dev, 0x01, 0x0000, missing, 0x08); 539 reg_w(gspca_dev, 0x01, 0x0000, missing, 0x08);
541 540
542 t16RegWrite(dev, 0x00, 0x2087, NULL, 0); 541 reg_w(gspca_dev, 0x00, 0x2087, NULL, 0);
543 t16RegWrite(dev, 0x00, 0x2088, NULL, 0); 542 reg_w(gspca_dev, 0x00, 0x2088, NULL, 0);
544 t16RegWrite(dev, 0x00, 0x2089, NULL, 0); 543 reg_w(gspca_dev, 0x00, 0x2089, NULL, 0);
545 544
546 t16RegWrite(dev, 0x01, 0x0000, nset7, 0x04); 545 reg_w(gspca_dev, 0x01, 0x0000, nset7, 0x04);
547 t16RegWrite(dev, 0x01, 0x0000, nset10, 0x06); 546 reg_w(gspca_dev, 0x01, 0x0000, nset10, 0x06);
548 t16RegWrite(dev, 0x01, 0x0000, nset8, 0x06); 547 reg_w(gspca_dev, 0x01, 0x0000, nset8, 0x06);
549 t16RegWrite(dev, 0x01, 0x0000, nset9, 0x04); 548 reg_w(gspca_dev, 0x01, 0x0000, nset9, 0x04);
550 549
551 t16RegWrite(dev, 0x00, 0x2880, NULL, 0); 550 reg_w(gspca_dev, 0x00, 0x2880, NULL, 0);
552 t16RegWrite(dev, 0x01, 0x0000, nset2, 0x14); 551 reg_w(gspca_dev, 0x01, 0x0000, nset2, 0x14);
553 t16RegWrite(dev, 0x01, 0x0000, nset3, 0x12); 552 reg_w(gspca_dev, 0x01, 0x0000, nset3, 0x12);
554 t16RegWrite(dev, 0x01, 0x0000, nset4, 0x12); 553 reg_w(gspca_dev, 0x01, 0x0000, nset4, 0x12);
555 554
556 return 0; 555 return 0;
557} 556}
@@ -559,7 +558,6 @@ static int init_default_parameters(struct gspca_dev *gspca_dev)
559static void setbrightness(struct gspca_dev *gspca_dev) 558static void setbrightness(struct gspca_dev *gspca_dev)
560{ 559{
561 struct sd *sd = (struct sd *) gspca_dev; 560 struct sd *sd = (struct sd *) gspca_dev;
562 struct usb_device *dev = gspca_dev->dev;
563 unsigned int brightness; 561 unsigned int brightness;
564 __u8 set6[4] = { 0x8f, 0x26, 0xc3, 0x80 }; 562 __u8 set6[4] = { 0x8f, 0x26, 0xc3, 0x80 };
565 brightness = sd->brightness; 563 brightness = sd->brightness;
@@ -571,13 +569,12 @@ static void setbrightness(struct gspca_dev *gspca_dev)
571 set6[3] = 0x00 + ((brightness - 7) * 0xa); 569 set6[3] = 0x00 + ((brightness - 7) * 0xa);
572 } 570 }
573 571
574 t16RegWrite(dev, 0x01, 0x0000, set6, 4); 572 reg_w(gspca_dev, 0x01, 0x0000, set6, 4);
575} 573}
576 574
577static void setflip(struct gspca_dev *gspca_dev) 575static void setflip(struct gspca_dev *gspca_dev)
578{ 576{
579 struct sd *sd = (struct sd *) gspca_dev; 577 struct sd *sd = (struct sd *) gspca_dev;
580 struct usb_device *dev = gspca_dev->dev;
581 578
582 __u8 flipcmd[8] = 579 __u8 flipcmd[8] =
583 { 0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09 }; 580 { 0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09 };
@@ -585,15 +582,14 @@ static void setflip(struct gspca_dev *gspca_dev)
585 if (sd->mirror == 1) 582 if (sd->mirror == 1)
586 flipcmd[3] = 0x01; 583 flipcmd[3] = 0x01;
587 584
588 t16RegWrite(dev, 0x01, 0x0000, flipcmd, 8); 585 reg_w(gspca_dev, 0x01, 0x0000, flipcmd, 8);
589} 586}
590 587
591static void seteffect(struct gspca_dev *gspca_dev) 588static void seteffect(struct gspca_dev *gspca_dev)
592{ 589{
593 struct sd *sd = (struct sd *) gspca_dev; 590 struct sd *sd = (struct sd *) gspca_dev;
594 struct usb_device *dev = gspca_dev->dev;
595 591
596 t16RegWrite(dev, 0x01, 0x0000, effects_table[sd->effect], 0x06); 592 reg_w(gspca_dev, 0x01, 0x0000, effects_table[sd->effect], 0x06);
597 if (sd->effect == 1 || sd->effect == 5) { 593 if (sd->effect == 1 || sd->effect == 5) {
598 PDEBUG(D_CONF, 594 PDEBUG(D_CONF,
599 "This effect have been disabled for webcam \"safety\""); 595 "This effect have been disabled for webcam \"safety\"");
@@ -601,15 +597,14 @@ static void seteffect(struct gspca_dev *gspca_dev)
601 } 597 }
602 598
603 if (sd->effect == 1 || sd->effect == 4) 599 if (sd->effect == 1 || sd->effect == 4)
604 t16RegWrite(dev, 0x00, 0x4aa6, NULL, 0); 600 reg_w(gspca_dev, 0x00, 0x4aa6, NULL, 0);
605 else 601 else
606 t16RegWrite(dev, 0x00, 0xfaa6, NULL, 0); 602 reg_w(gspca_dev, 0x00, 0xfaa6, NULL, 0);
607} 603}
608 604
609static void setwhitebalance(struct gspca_dev *gspca_dev) 605static void setwhitebalance(struct gspca_dev *gspca_dev)
610{ 606{
611 struct sd *sd = (struct sd *) gspca_dev; 607 struct sd *sd = (struct sd *) gspca_dev;
612 struct usb_device *dev = gspca_dev->dev;
613 608
614 __u8 white_balance[8] = 609 __u8 white_balance[8] =
615 { 0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38 }; 610 { 0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38 };
@@ -617,25 +612,23 @@ static void setwhitebalance(struct gspca_dev *gspca_dev)
617 if (sd->whitebalance == 1) 612 if (sd->whitebalance == 1)
618 white_balance[7] = 0x3c; 613 white_balance[7] = 0x3c;
619 614
620 t16RegWrite(dev, 0x01, 0x0000, white_balance, 8); 615 reg_w(gspca_dev, 0x01, 0x0000, white_balance, 8);
621} 616}
622 617
623static void setlightfreq(struct gspca_dev *gspca_dev) 618static void setlightfreq(struct gspca_dev *gspca_dev)
624{ 619{
625 struct sd *sd = (struct sd *) gspca_dev; 620 struct sd *sd = (struct sd *) gspca_dev;
626 struct usb_device *dev = gspca_dev->dev;
627 __u8 freq[4] = { 0x66, 0x40, 0xa8, 0xe8 }; 621 __u8 freq[4] = { 0x66, 0x40, 0xa8, 0xe8 };
628 622
629 if (sd->freq == 2) /* 60hz */ 623 if (sd->freq == 2) /* 60hz */
630 freq[1] = 0x00; 624 freq[1] = 0x00;
631 625
632 t16RegWrite(dev, 0x1, 0x0000, freq, 0x4); 626 reg_w(gspca_dev, 0x1, 0x0000, freq, 0x4);
633} 627}
634 628
635static void setcontrast(struct gspca_dev *gspca_dev) 629static void setcontrast(struct gspca_dev *gspca_dev)
636{ 630{
637 struct sd *sd = (struct sd *) gspca_dev; 631 struct sd *sd = (struct sd *) gspca_dev;
638 struct usb_device *dev = gspca_dev->dev;
639 unsigned int contrast = sd->contrast; 632 unsigned int contrast = sd->contrast;
640 __u16 reg_to_write = 0x00; 633 __u16 reg_to_write = 0x00;
641 634
@@ -644,17 +637,16 @@ static void setcontrast(struct gspca_dev *gspca_dev)
644 else 637 else
645 reg_to_write = (0x00a9 + ((contrast - 7) * 0x200)); 638 reg_to_write = (0x00a9 + ((contrast - 7) * 0x200));
646 639
647 t16RegWrite(dev, 0x00, reg_to_write, NULL, 0); 640 reg_w(gspca_dev, 0x00, reg_to_write, NULL, 0);
648} 641}
649 642
650static void setcolors(struct gspca_dev *gspca_dev) 643static void setcolors(struct gspca_dev *gspca_dev)
651{ 644{
652 struct sd *sd = (struct sd *) gspca_dev; 645 struct sd *sd = (struct sd *) gspca_dev;
653 struct usb_device *dev = gspca_dev->dev;
654 __u16 reg_to_write; 646 __u16 reg_to_write;
655 647
656 reg_to_write = 0xc0bb + sd->colors * 0x100; 648 reg_to_write = 0xc0bb + sd->colors * 0x100;
657 t16RegWrite(dev, 0x00, reg_to_write, NULL, 0); 649 reg_w(gspca_dev, 0x00, reg_to_write, NULL, 0);
658} 650}
659 651
660static void setgamma(struct gspca_dev *gspca_dev) 652static void setgamma(struct gspca_dev *gspca_dev)
@@ -664,12 +656,11 @@ static void setgamma(struct gspca_dev *gspca_dev)
664static void setsharpness(struct gspca_dev *gspca_dev) 656static void setsharpness(struct gspca_dev *gspca_dev)
665{ 657{
666 struct sd *sd = (struct sd *) gspca_dev; 658 struct sd *sd = (struct sd *) gspca_dev;
667 struct usb_device *dev = gspca_dev->dev;
668 __u16 reg_to_write; 659 __u16 reg_to_write;
669 660
670 reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness; 661 reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness;
671 662
672 t16RegWrite(dev, 0x00, reg_to_write, NULL, 0); 663 reg_w(gspca_dev, 0x00, reg_to_write, NULL, 0);
673} 664}
674 665
675static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 666static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
@@ -837,13 +828,12 @@ static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
837static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val) 828static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val)
838{ 829{
839 struct sd *sd = (struct sd *) gspca_dev; 830 struct sd *sd = (struct sd *) gspca_dev;
840 struct usb_device *dev = gspca_dev->dev;
841 831
842 sd->autogain = val; 832 sd->autogain = val;
843 if (val != 0) 833 if (val != 0)
844 t16RegWrite(dev, 0x00, 0xf48e, NULL, 0); 834 reg_w(gspca_dev, 0x00, 0xf48e, NULL, 0);
845 else 835 else
846 t16RegWrite(dev, 0x00, 0xb48e, NULL, 0); 836 reg_w(gspca_dev, 0x00, 0xb48e, NULL, 0);
847 return 0; 837 return 0;
848} 838}
849 839
@@ -857,9 +847,7 @@ static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val)
857 847
858static void sd_start(struct gspca_dev *gspca_dev) 848static void sd_start(struct gspca_dev *gspca_dev)
859{ 849{
860 struct usb_device *dev = gspca_dev->dev;
861 int mode; 850 int mode;
862 __u8 test_byte;
863 851
864 static const __u8 t1[] = { 0x66, 0x00, 0xa8, 0xe8 }; 852 static const __u8 t1[] = { 0x66, 0x00, 0xa8, 0xe8 };
865 __u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 }; 853 __u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
@@ -886,21 +874,21 @@ static void sd_start(struct gspca_dev *gspca_dev)
886 break; 874 break;
887 } 875 }
888 876
889 t16RegWrite(dev, 0x01, 0x0000, tas5130a_sensor_init[0], 0x8); 877 reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[0], 0x8);
890 t16RegWrite(dev, 0x01, 0x0000, tas5130a_sensor_init[1], 0x8); 878 reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[1], 0x8);
891 t16RegWrite(dev, 0x01, 0x0000, tas5130a_sensor_init[2], 0x8); 879 reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[2], 0x8);
892 t16RegWrite(dev, 0x01, 0x0000, tas5130a_sensor_init[3], 0x8); 880 reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[3], 0x8);
893 t16RegWrite(dev, 0x00, 0x3c80, NULL, 0); 881 reg_w(gspca_dev, 0x00, 0x3c80, NULL, 0);
894 /* just in case and to keep sync with logs (for mine) */ 882 /* just in case and to keep sync with logs (for mine) */
895 t16RegWrite(dev, 0x01, 0x0000, tas5130a_sensor_init[3], 0x8); 883 reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[3], 0x8);
896 t16RegWrite(dev, 0x00, 0x3c80, NULL, 0); 884 reg_w(gspca_dev, 0x00, 0x3c80, NULL, 0);
897 /* just in case and to keep sync with logs (for mine) */ 885 /* just in case and to keep sync with logs (for mine) */
898 t16RegWrite(dev, 0x01, 0x0000, t1, 4); 886 reg_w(gspca_dev, 0x01, 0x0000, t1, 4);
899 t16RegWrite(dev, 0x01, 0x0000, t2, 6); 887 reg_w(gspca_dev, 0x01, 0x0000, t2, 6);
900 t16RegRead(dev, 0x0012, &test_byte, 0x01); 888 reg_r_1(gspca_dev, 0x0012);
901 t16RegWrite(dev, 0x01, 0x0000, t3, 0x10); 889 reg_w(gspca_dev, 0x01, 0x0000, t3, 0x10);
902 t16RegWrite(dev, 0x00, 0x0013, NULL, 0); 890 reg_w(gspca_dev, 0x00, 0x0013, NULL, 0);
903 t16RegWrite(dev, 0x01, 0x0000, t4, 0x4); 891 reg_w(gspca_dev, 0x01, 0x0000, t4, 0x4);
904 /* restart on each start, just in case, sometimes regs goes wrong 892 /* restart on each start, just in case, sometimes regs goes wrong
905 * when using controls from app */ 893 * when using controls from app */
906 setbrightness(gspca_dev); 894 setbrightness(gspca_dev);
diff --git a/drivers/media/video/gspca/tv8532.c b/drivers/media/video/gspca/tv8532.c
index f9bffd67991e..0b793899095f 100644
--- a/drivers/media/video/gspca/tv8532.c
+++ b/drivers/media/video/gspca/tv8532.c
@@ -22,8 +22,8 @@
22 22
23#include "gspca.h" 23#include "gspca.h"
24 24
25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
26static const char version[] = "2.1.5"; 26static const char version[] = "2.1.7";
27 27
28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("TV8532 USB Camera Driver"); 29MODULE_DESCRIPTION("TV8532 USB Camera Driver");
@@ -168,63 +168,74 @@ static const __u32 tv_8532_eeprom_data[] = {
168 0x0c0509f1, 0 168 0x0c0509f1, 0
169}; 169};
170 170
171static void reg_r(struct usb_device *dev, 171static int reg_r(struct gspca_dev *gspca_dev,
172 __u16 index, __u8 *buffer) 172 __u16 index)
173{ 173{
174 usb_control_msg(dev, 174 usb_control_msg(gspca_dev->dev,
175 usb_rcvctrlpipe(dev, 0), 175 usb_rcvctrlpipe(gspca_dev->dev, 0),
176 TV8532_REQ_RegRead, 176 TV8532_REQ_RegRead,
177 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 177 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
178 0, /* value */ 178 0, /* value */
179 index, buffer, sizeof(__u8), 179 index, gspca_dev->usb_buf, 1,
180 500); 180 500);
181 return gspca_dev->usb_buf[0];
181} 182}
182 183
183static void reg_w(struct usb_device *dev, 184/* write 1 byte */
184 __u16 index, __u8 *buffer, __u16 length) 185static void reg_w_1(struct gspca_dev *gspca_dev,
186 __u16 index, __u8 value)
185{ 187{
186 usb_control_msg(dev, 188 gspca_dev->usb_buf[0] = value;
187 usb_sndctrlpipe(dev, 0), 189 usb_control_msg(gspca_dev->dev,
190 usb_sndctrlpipe(gspca_dev->dev, 0),
188 TV8532_REQ_RegWrite, 191 TV8532_REQ_RegWrite,
189 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 192 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
190 0, /* value */ 193 0, /* value */
191 index, buffer, length, 500); 194 index, gspca_dev->usb_buf, 1, 500);
195}
196
197/* write 2 bytes */
198static void reg_w_2(struct gspca_dev *gspca_dev,
199 __u16 index, __u8 val1, __u8 val2)
200{
201 gspca_dev->usb_buf[0] = val1;
202 gspca_dev->usb_buf[1] = val2;
203 usb_control_msg(gspca_dev->dev,
204 usb_sndctrlpipe(gspca_dev->dev, 0),
205 TV8532_REQ_RegWrite,
206 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
207 0, /* value */
208 index, gspca_dev->usb_buf, 2, 500);
192} 209}
193 210
194static void tv_8532WriteEEprom(struct gspca_dev *gspca_dev) 211static void tv_8532WriteEEprom(struct gspca_dev *gspca_dev)
195{ 212{
196 int i = 0; 213 int i = 0;
197 __u8 reg, data0, data1, data2, datacmd; 214 __u8 reg, data0, data1, data2;
198 struct usb_device *dev = gspca_dev->dev;
199 215
200 datacmd = 0xb0;; 216 reg_w_1(gspca_dev, TV8532_GPIO, 0xb0);
201 reg_w(dev, TV8532_GPIO, &datacmd, 1); 217 reg_w_1(gspca_dev, TV8532_CTRL, TV8532_CMD_EEprom_Open);
202 datacmd = TV8532_CMD_EEprom_Open;
203 reg_w(dev, TV8532_CTRL, &datacmd, 1);
204/* msleep(1); */ 218/* msleep(1); */
205 while (tv_8532_eeprom_data[i]) { 219 while (tv_8532_eeprom_data[i]) {
206 reg = (tv_8532_eeprom_data[i] & 0xff000000) >> 24; 220 reg = (tv_8532_eeprom_data[i] & 0xff000000) >> 24;
207 reg_w(dev, TV8532_EEprom_Add, &reg, 1); 221 reg_w_1(gspca_dev, TV8532_EEprom_Add, reg);
208 /* msleep(1); */ 222 /* msleep(1); */
209 data0 = (tv_8532_eeprom_data[i] & 0x000000ff); 223 data0 = (tv_8532_eeprom_data[i] & 0x000000ff);
210 reg_w(dev, TV8532_EEprom_DataL, &data0, 1); 224 reg_w_1(gspca_dev, TV8532_EEprom_DataL, data0);
211 /* msleep(1); */ 225 /* msleep(1); */
212 data1 = (tv_8532_eeprom_data[i] & 0x0000FF00) >> 8; 226 data1 = (tv_8532_eeprom_data[i] & 0x0000ff00) >> 8;
213 reg_w(dev, TV8532_EEprom_DataM, &data1, 1); 227 reg_w_1(gspca_dev, TV8532_EEprom_DataM, data1);
214 /* msleep(1); */ 228 /* msleep(1); */
215 data2 = (tv_8532_eeprom_data[i] & 0x00FF0000) >> 16; 229 data2 = (tv_8532_eeprom_data[i] & 0x00ff0000) >> 16;
216 reg_w(dev, TV8532_EEprom_DataH, &data2, 1); 230 reg_w_1(gspca_dev, TV8532_EEprom_DataH, data2);
217 /* msleep(1); */ 231 /* msleep(1); */
218 datacmd = 0; 232 reg_w_1(gspca_dev, TV8532_EEprom_Write, 0);
219 reg_w(dev, TV8532_EEprom_Write, &datacmd, 1);
220 /* msleep(10); */ 233 /* msleep(10); */
221 i++; 234 i++;
222 } 235 }
223 datacmd = i; 236 reg_w_1(gspca_dev, TV8532_EEprom_TableLength, i);
224 reg_w(dev, TV8532_EEprom_TableLength, &datacmd, 1);
225/* msleep(1); */ 237/* msleep(1); */
226 datacmd = TV8532_CMD_EEprom_Close; 238 reg_w_1(gspca_dev, TV8532_CTRL, TV8532_CMD_EEprom_Close);
227 reg_w(dev, TV8532_CTRL, &datacmd, 1);
228 msleep(10); 239 msleep(10);
229} 240}
230 241
@@ -250,154 +261,121 @@ static int sd_config(struct gspca_dev *gspca_dev,
250 261
251static void tv_8532ReadRegisters(struct gspca_dev *gspca_dev) 262static void tv_8532ReadRegisters(struct gspca_dev *gspca_dev)
252{ 263{
253 struct usb_device *dev = gspca_dev->dev;
254 __u8 data; 264 __u8 data;
255/* __u16 vid, pid; */
256 265
257 reg_r(dev, 0x0001, &data); 266 data = reg_r(gspca_dev, 0x0001);
258 PDEBUG(D_USBI, "register 0x01-> %x", data); 267 PDEBUG(D_USBI, "register 0x01-> %x", data);
259 reg_r(dev, 0x0002, &data); 268 data = reg_r(gspca_dev, 0x0002);
260 PDEBUG(D_USBI, "register 0x02-> %x", data); 269 PDEBUG(D_USBI, "register 0x02-> %x", data);
261 reg_r(dev, TV8532_ADWIDTH_L, &data); 270 reg_r(gspca_dev, TV8532_ADWIDTH_L);
262 reg_r(dev, TV8532_ADWIDTH_H, &data); 271 reg_r(gspca_dev, TV8532_ADWIDTH_H);
263 reg_r(dev, TV8532_QUANT_COMP, &data); 272 reg_r(gspca_dev, TV8532_QUANT_COMP);
264 reg_r(dev, TV8532_MODE_PACKET, &data); 273 reg_r(gspca_dev, TV8532_MODE_PACKET);
265 reg_r(dev, TV8532_SETCLK, &data); 274 reg_r(gspca_dev, TV8532_SETCLK);
266 reg_r(dev, TV8532_POINT_L, &data); 275 reg_r(gspca_dev, TV8532_POINT_L);
267 reg_r(dev, TV8532_POINT_H, &data); 276 reg_r(gspca_dev, TV8532_POINT_H);
268 reg_r(dev, TV8532_POINTB_L, &data); 277 reg_r(gspca_dev, TV8532_POINTB_L);
269 reg_r(dev, TV8532_POINTB_H, &data); 278 reg_r(gspca_dev, TV8532_POINTB_H);
270 reg_r(dev, TV8532_BUDGET_L, &data); 279 reg_r(gspca_dev, TV8532_BUDGET_L);
271 reg_r(dev, TV8532_BUDGET_H, &data); 280 reg_r(gspca_dev, TV8532_BUDGET_H);
272 reg_r(dev, TV8532_VID_L, &data); 281 reg_r(gspca_dev, TV8532_VID_L);
273 reg_r(dev, TV8532_VID_H, &data); 282 reg_r(gspca_dev, TV8532_VID_H);
274 reg_r(dev, TV8532_PID_L, &data); 283 reg_r(gspca_dev, TV8532_PID_L);
275 reg_r(dev, TV8532_PID_H, &data); 284 reg_r(gspca_dev, TV8532_PID_H);
276 reg_r(dev, TV8532_DeviceID, &data); 285 reg_r(gspca_dev, TV8532_DeviceID);
277 reg_r(dev, TV8532_AD_COLBEGIN_L, &data); 286 reg_r(gspca_dev, TV8532_AD_COLBEGIN_L);
278 reg_r(dev, TV8532_AD_COLBEGIN_H, &data); 287 reg_r(gspca_dev, TV8532_AD_COLBEGIN_H);
279 reg_r(dev, TV8532_AD_ROWBEGIN_L, &data); 288 reg_r(gspca_dev, TV8532_AD_ROWBEGIN_L);
280 reg_r(dev, TV8532_AD_ROWBEGIN_H, &data); 289 reg_r(gspca_dev, TV8532_AD_ROWBEGIN_H);
281} 290}
282 291
283static void tv_8532_setReg(struct gspca_dev *gspca_dev) 292static void tv_8532_setReg(struct gspca_dev *gspca_dev)
284{ 293{
285 struct usb_device *dev = gspca_dev->dev; 294 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_L,
286 __u8 data; 295 ADCBEGINL); /* 0x10 */
287 __u8 value[2] = { 0, 0 }; 296 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_H,
288 297 ADCBEGINH); /* also digital gain */
289 data = ADCBEGINL; 298 reg_w_1(gspca_dev, TV8532_PART_CTRL,
290 reg_w(dev, TV8532_AD_COLBEGIN_L, &data, 1); /* 0x10 */ 299 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
291 data = ADCBEGINH; /* also digital gain */ 300
292 reg_w(dev, TV8532_AD_COLBEGIN_H, &data, 1); 301 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0a);
293 data = TV8532_CMD_UPDATE;
294 reg_w(dev, TV8532_PART_CTRL, &data, 1); /* 0x00<-0x84 */
295
296 data = 0x0a;
297 reg_w(dev, TV8532_GPIO_OE, &data, 1);
298 /******************************************************/ 302 /******************************************************/
299 data = ADHEIGHL; 303 reg_w_1(gspca_dev, TV8532_ADHEIGHT_L, ADHEIGHL); /* 0e */
300 reg_w(dev, TV8532_ADHEIGHT_L, &data, 1); /* 0e */ 304 reg_w_1(gspca_dev, TV8532_ADHEIGHT_H, ADHEIGHH); /* 0f */
301 data = ADHEIGHH; 305 reg_w_2(gspca_dev, TV8532_EXPOSURE,
302 reg_w(dev, TV8532_ADHEIGHT_H, &data, 1); /* 0f */ 306 EXPOL, EXPOH); /* 350d 0x014c; 1c */
303 value[0] = EXPOL; 307 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_L,
304 value[1] = EXPOH; /* 350d 0x014c; */ 308 ADCBEGINL); /* 0x10 */
305 reg_w(dev, TV8532_EXPOSURE, value, 2); /* 1c */ 309 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_H,
306 data = ADCBEGINL; 310 ADCBEGINH); /* also digital gain */
307 reg_w(dev, TV8532_AD_COLBEGIN_L, &data, 1); /* 0x10 */ 311 reg_w_1(gspca_dev, TV8532_AD_ROWBEGIN_L,
308 data = ADCBEGINH; /* also digital gain */ 312 ADRBEGINL); /* 0x14 */
309 reg_w(dev, TV8532_AD_COLBEGIN_H, &data, 1); 313
310 data = ADRBEGINL; 314 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x00); /* 0x91 */
311 reg_w(dev, TV8532_AD_ROWBEGIN_L, &data, 1); /* 0x14 */ 315 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x02); /* 0x94 */
312 316
313 data = 0x00; 317 reg_w_1(gspca_dev, TV8532_CTRL,
314 reg_w(dev, TV8532_AD_SLOPE, &data, 1); /* 0x91 */ 318 TV8532_CMD_EEprom_Close); /* 0x01 */
315 data = 0x02; 319
316 reg_w(dev, TV8532_AD_BITCTRL, &data, 1); /* 0x94 */ 320 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x00); /* 0x91 */
317 321 reg_w_1(gspca_dev, TV8532_PART_CTRL,
318 322 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
319 data = TV8532_CMD_EEprom_Close;
320 reg_w(dev, TV8532_CTRL, &data, 1); /* 0x01 */
321
322 data = 0x00;
323 reg_w(dev, TV8532_AD_SLOPE, &data, 1); /* 0x91 */
324 data = TV8532_CMD_UPDATE;
325 reg_w(dev, TV8532_PART_CTRL, &data, 1); /* 0x00<-0x84 */
326} 323}
327 324
328static void tv_8532_PollReg(struct gspca_dev *gspca_dev) 325static void tv_8532_PollReg(struct gspca_dev *gspca_dev)
329{ 326{
330 struct usb_device *dev = gspca_dev->dev;
331 __u8 data;
332 int i; 327 int i;
333 328
334 /* strange polling from tgc */ 329 /* strange polling from tgc */
335 for (i = 0; i < 10; i++) { 330 for (i = 0; i < 10; i++) {
336 data = TESTCLK; /* 0x48; //0x08; */ 331 reg_w_1(gspca_dev, TV8532_SETCLK,
337 reg_w(dev, TV8532_SETCLK, &data, 1); /* 0x2c */ 332 TESTCLK); /* 0x48; //0x08; 0x2c */
338 data = TV8532_CMD_UPDATE; 333 reg_w_1(gspca_dev, TV8532_PART_CTRL, TV8532_CMD_UPDATE);
339 reg_w(dev, TV8532_PART_CTRL, &data, 1); 334 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */
340 data = 0x01;
341 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
342 } 335 }
343} 336}
344 337
345/* this function is called at open time */ 338/* this function is called at open time */
346static int sd_open(struct gspca_dev *gspca_dev) 339static int sd_open(struct gspca_dev *gspca_dev)
347{ 340{
348 struct usb_device *dev = gspca_dev->dev; 341 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32);
349 __u8 data; 342 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00);
350 __u8 dataStart;
351 __u8 value[2];
352
353 data = 0x32;
354 reg_w(dev, TV8532_AD_SLOPE, &data, 1);
355 data = 0;
356 reg_w(dev, TV8532_AD_BITCTRL, &data, 1);
357 tv_8532ReadRegisters(gspca_dev); 343 tv_8532ReadRegisters(gspca_dev);
358 data = 0x0b; 344 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
359 reg_w(dev, TV8532_GPIO_OE, &data, 1); 345 reg_w_2(gspca_dev, TV8532_ADHEIGHT_L, ADHEIGHL,
360 value[0] = ADHEIGHL; 346 ADHEIGHH); /* 401d 0x0169; 0e */
361 value[1] = ADHEIGHH; /* 401d 0x0169; */ 347 reg_w_2(gspca_dev, TV8532_EXPOSURE, EXPOL,
362 reg_w(dev, TV8532_ADHEIGHT_L, value, 2); /* 0e */ 348 EXPOH); /* 350d 0x014c; 1c */
363 value[0] = EXPOL; 349 reg_w_1(gspca_dev, TV8532_ADWIDTH_L, ADWIDTHL); /* 0x20; 0x0c */
364 value[1] = EXPOH; /* 350d 0x014c; */ 350 reg_w_1(gspca_dev, TV8532_ADWIDTH_H, ADWIDTHH); /* 0x0d */
365 reg_w(dev, TV8532_EXPOSURE, value, 2); /* 1c */
366 data = ADWIDTHL; /* 0x20; */
367 reg_w(dev, TV8532_ADWIDTH_L, &data, 1); /* 0x0c */
368 data = ADWIDTHH;
369 reg_w(dev, TV8532_ADWIDTH_H, &data, 1); /* 0x0d */
370 351
371 /*******************************************************************/ 352 /*******************************************************************/
372 data = TESTCOMP; /* 0x72 compressed mode */ 353 reg_w_1(gspca_dev, TV8532_QUANT_COMP,
373 reg_w(dev, TV8532_QUANT_COMP, &data, 1); /* 0x28 */ 354 TESTCOMP); /* 0x72 compressed mode 0x28 */
374 data = TESTLINE; /* 0x84; // CIF | 4 packet */ 355 reg_w_1(gspca_dev, TV8532_MODE_PACKET,
375 reg_w(dev, TV8532_MODE_PACKET, &data, 1); /* 0x29 */ 356 TESTLINE); /* 0x84; // CIF | 4 packet 0x29 */
376 357
377 /************************************************/ 358 /************************************************/
378 data = TESTCLK; /* 0x48; //0x08; */ 359 reg_w_1(gspca_dev, TV8532_SETCLK,
379 reg_w(dev, TV8532_SETCLK, &data, 1); /* 0x2c */ 360 TESTCLK); /* 0x48; //0x08; 0x2c */
380 data = TESTPTL; /* 0x38; */ 361 reg_w_1(gspca_dev, TV8532_POINT_L,
381 reg_w(dev, TV8532_POINT_L, &data, 1); /* 0x2d */ 362 TESTPTL); /* 0x38; 0x2d */
382 data = TESTPTH; /* 0x04; */ 363 reg_w_1(gspca_dev, TV8532_POINT_H,
383 reg_w(dev, TV8532_POINT_H, &data, 1); /* 0x2e */ 364 TESTPTH); /* 0x04; 0x2e */
384 dataStart = TESTPTBL; /* 0x04; */ 365 reg_w_1(gspca_dev, TV8532_POINTB_L,
385 reg_w(dev, TV8532_POINTB_L, &dataStart, 1); /* 0x2f */ 366 TESTPTBL); /* 0x04; 0x2f */
386 data = TESTPTBH; /* 0x04; */ 367 reg_w_1(gspca_dev, TV8532_POINTB_H,
387 reg_w(dev, TV8532_POINTB_H, &data, 1); /* 0x30 */ 368 TESTPTBH); /* 0x04; 0x30 */
388 data = TV8532_CMD_UPDATE; 369 reg_w_1(gspca_dev, TV8532_PART_CTRL,
389 reg_w(dev, TV8532_PART_CTRL, &data, 1); /* 0x00<-0x84 */ 370 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
390 /*************************************************/ 371 /*************************************************/
391 data = 0x01; 372 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */
392 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
393 msleep(200); 373 msleep(200);
394 data = 0x00; 374 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */
395 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
396 /*************************************************/ 375 /*************************************************/
397 tv_8532_setReg(gspca_dev); 376 tv_8532_setReg(gspca_dev);
398 /*************************************************/ 377 /*************************************************/
399 data = 0x0b; 378 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
400 reg_w(dev, TV8532_GPIO_OE, &data, 1);
401 /*************************************************/ 379 /*************************************************/
402 tv_8532_setReg(gspca_dev); 380 tv_8532_setReg(gspca_dev);
403 /*************************************************/ 381 /*************************************************/
@@ -408,94 +386,72 @@ static int sd_open(struct gspca_dev *gspca_dev)
408static void setbrightness(struct gspca_dev *gspca_dev) 386static void setbrightness(struct gspca_dev *gspca_dev)
409{ 387{
410 struct sd *sd = (struct sd *) gspca_dev; 388 struct sd *sd = (struct sd *) gspca_dev;
411 __u8 value[2];
412 __u8 data;
413 int brightness = sd->brightness; 389 int brightness = sd->brightness;
414 390
415 value[1] = (brightness >> 8) & 0xff; 391 reg_w_2(gspca_dev, TV8532_EXPOSURE,
416 value[0] = (brightness) & 0xff; 392 brightness >> 8, brightness); /* 1c */
417 reg_w(gspca_dev->dev, TV8532_EXPOSURE, value, 2); /* 1c */ 393 reg_w_1(gspca_dev, TV8532_PART_CTRL, TV8532_CMD_UPDATE);
418 data = TV8532_CMD_UPDATE;
419 reg_w(gspca_dev->dev, TV8532_PART_CTRL, &data, 1);
420} 394}
421 395
422/* -- start the camera -- */ 396/* -- start the camera -- */
423static void sd_start(struct gspca_dev *gspca_dev) 397static void sd_start(struct gspca_dev *gspca_dev)
424{ 398{
425 struct usb_device *dev = gspca_dev->dev; 399 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32);
426 __u8 data; 400 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00);
427 __u8 value[2];
428
429 data = 0x32;
430 reg_w(dev, TV8532_AD_SLOPE, &data, 1);
431 data = 0;
432 reg_w(dev, TV8532_AD_BITCTRL, &data, 1);
433 tv_8532ReadRegisters(gspca_dev); 401 tv_8532ReadRegisters(gspca_dev);
434 data = 0x0b; 402 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
435 reg_w(dev, TV8532_GPIO_OE, &data, 1); 403 reg_w_2(gspca_dev, TV8532_ADHEIGHT_L,
436 value[0] = ADHEIGHL; 404 ADHEIGHL, ADHEIGHH); /* 401d 0x0169; 0e */
437 value[1] = ADHEIGHH; /* 401d 0x0169; */ 405/* reg_w_2(gspca_dev, TV8532_EXPOSURE,
438 reg_w(dev, TV8532_ADHEIGHT_L, value, 2); /* 0e */ 406 EXPOL, EXPOH); * 350d 0x014c; 1c */
439/* value[0] = EXPOL; value[1] =EXPOH; * 350d 0x014c; */
440/* reg_w(dev,TV8532_REQ_RegWrite,0,TV8532_EXPOSURE,value,2); * 1c */
441 setbrightness(gspca_dev); 407 setbrightness(gspca_dev);
442 408
443 data = ADWIDTHL; /* 0x20; */ 409 reg_w_1(gspca_dev, TV8532_ADWIDTH_L, ADWIDTHL); /* 0x20; 0x0c */
444 reg_w(dev, TV8532_ADWIDTH_L, &data, 1); /* 0x0c */ 410 reg_w_1(gspca_dev, TV8532_ADWIDTH_H, ADWIDTHH); /* 0x0d */
445 data = ADWIDTHH;
446 reg_w(dev, TV8532_ADWIDTH_H, &data, 1); /* 0x0d */
447 411
448 /************************************************/ 412 /************************************************/
449 data = TESTCOMP; /* 0x72 compressed mode */ 413 reg_w_1(gspca_dev, TV8532_QUANT_COMP,
450 reg_w(dev, TV8532_QUANT_COMP, &data, 1); /* 0x28 */ 414 TESTCOMP); /* 0x72 compressed mode 0x28 */
451 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { 415 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
452 /* 176x144 */ 416 /* 176x144 */
453 data = QCIFLINE; /* 0x84; // CIF | 4 packet */ 417 reg_w_1(gspca_dev, TV8532_MODE_PACKET,
454 reg_w(dev, TV8532_MODE_PACKET, &data, 1); /* 0x29 */ 418 QCIFLINE); /* 0x84; // CIF | 4 packet 0x29 */
455 } else { 419 } else {
456 /* 352x288 */ 420 /* 352x288 */
457 data = TESTLINE; /* 0x84; // CIF | 4 packet */ 421 reg_w_1(gspca_dev, TV8532_MODE_PACKET,
458 reg_w(dev, TV8532_MODE_PACKET, &data, 1); /* 0x29 */ 422 TESTLINE); /* 0x84; // CIF | 4 packet 0x29 */
459 } 423 }
460 /************************************************/ 424 /************************************************/
461 data = TESTCLK; /* 0x48; //0x08; */ 425 reg_w_1(gspca_dev, TV8532_SETCLK,
462 reg_w(dev, TV8532_SETCLK, &data, 1); /* 0x2c */ 426 TESTCLK); /* 0x48; //0x08; 0x2c */
463 data = TESTPTL; /* 0x38; */ 427 reg_w_1(gspca_dev, TV8532_POINT_L,
464 reg_w(dev, TV8532_POINT_L, &data, 1); /* 0x2d */ 428 TESTPTL); /* 0x38; 0x2d */
465 data = TESTPTH; /* 0x04; */ 429 reg_w_1(gspca_dev, TV8532_POINT_H,
466 reg_w(dev, TV8532_POINT_H, &data, 1); /* 0x2e */ 430 TESTPTH); /* 0x04; 0x2e */
467 data = TESTPTBL; /* 0x04; */ 431 reg_w_1(gspca_dev, TV8532_POINTB_L,
468 reg_w(dev, TV8532_POINTB_L, &data, 1); /* 0x2f */ 432 TESTPTBL); /* 0x04; 0x2f */
469 data = TESTPTBH; /* 0x04; */ 433 reg_w_1(gspca_dev, TV8532_POINTB_H,
470 reg_w(dev, TV8532_POINTB_H, &data, 1); /* 0x30 */ 434 TESTPTBH); /* 0x04; 0x30 */
471 data = TV8532_CMD_UPDATE; 435 reg_w_1(gspca_dev, TV8532_PART_CTRL,
472 reg_w(dev, TV8532_PART_CTRL, &data, 1); /* 0x00<-0x84 */ 436 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
473 /************************************************/ 437 /************************************************/
474 data = 0x01; 438 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */
475 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
476 msleep(200); 439 msleep(200);
477 data = 0x00; 440 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */
478 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
479 /************************************************/ 441 /************************************************/
480 tv_8532_setReg(gspca_dev); 442 tv_8532_setReg(gspca_dev);
481 /************************************************/ 443 /************************************************/
482 data = 0x0b; 444 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
483 reg_w(dev, TV8532_GPIO_OE, &data, 1);
484 /************************************************/ 445 /************************************************/
485 tv_8532_setReg(gspca_dev); 446 tv_8532_setReg(gspca_dev);
486 /************************************************/ 447 /************************************************/
487 tv_8532_PollReg(gspca_dev); 448 tv_8532_PollReg(gspca_dev);
488 data = 0x00; 449 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */
489 reg_w(dev, TV8532_UDP_UPDATE, &data, 1); /* 0x31 */
490} 450}
491 451
492static void sd_stopN(struct gspca_dev *gspca_dev) 452static void sd_stopN(struct gspca_dev *gspca_dev)
493{ 453{
494 struct usb_device *dev = gspca_dev->dev; 454 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b);
495 __u8 data;
496
497 data = 0x0b;
498 reg_w(dev, TV8532_GPIO_OE, &data, 1);
499} 455}
500 456
501static void sd_stop0(struct gspca_dev *gspca_dev) 457static void sd_stop0(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c
index 668e024aaa8f..dd7c1389f38d 100644
--- a/drivers/media/video/gspca/vc032x.c
+++ b/drivers/media/video/gspca/vc032x.c
@@ -1227,17 +1227,18 @@ static const struct sensor_info sensor_info_data[] = {
1227 {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01}, 1227 {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01},
1228}; 1228};
1229 1229
1230static void reg_r(struct usb_device *dev, 1230/* read 'len' bytes in gspca_dev->usb_buf */
1231 __u16 req, 1231static void reg_r(struct gspca_dev *gspca_dev,
1232 __u16 index, 1232 __u16 req,
1233 __u8 *buffer, __u16 length) 1233 __u16 index,
1234 __u16 len)
1234{ 1235{
1235 usb_control_msg(dev, 1236 usb_control_msg(gspca_dev->dev,
1236 usb_rcvctrlpipe(dev, 0), 1237 usb_rcvctrlpipe(gspca_dev->dev, 0),
1237 req, 1238 req,
1238 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1239 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1239 1, /* value */ 1240 1, /* value */
1240 index, buffer, length, 1241 index, gspca_dev->usb_buf, len,
1241 500); 1242 500);
1242} 1243}
1243 1244
@@ -1254,55 +1255,55 @@ static void reg_w(struct usb_device *dev,
1254 500); 1255 500);
1255} 1256}
1256 1257
1257static void vc032x_read_sensor_register(struct usb_device *dev, 1258static void read_sensor_register(struct gspca_dev *gspca_dev,
1258 __u16 address, __u16 *value) 1259 __u16 address, __u16 *value)
1259{ 1260{
1261 struct usb_device *dev = gspca_dev->dev;
1260 __u8 ldata, mdata, hdata; 1262 __u8 ldata, mdata, hdata;
1261 __u8 tmpvalue = 0;
1262 int retry = 50; 1263 int retry = 50;
1263 ldata = 0; 1264
1264 mdata = 0;
1265 hdata = 0;
1266 *value = 0; 1265 *value = 0;
1267 1266
1268 reg_r(dev, 0xa1, 0xb33f, &tmpvalue, 1); 1267 reg_r(gspca_dev, 0xa1, 0xb33f, 1);
1269 /*PDEBUG(D_PROBE, " I2c Bus Busy Wait 0x%02X ", tmpvalue); */ 1268 /*PDEBUG(D_PROBE, " I2c Bus Busy Wait 0x%02X ", tmpvalue); */
1270 if (!(tmpvalue & 0x02)) { 1269 if (!(gspca_dev->usb_buf[0] & 0x02)) {
1271 PDEBUG(D_ERR, "I2c Bus Busy Wait %d", tmpvalue & 0x02); 1270 PDEBUG(D_ERR, "I2c Bus Busy Wait %d",
1271 gspca_dev->usb_buf[0] & 0x02);
1272 return; 1272 return;
1273 } 1273 }
1274 reg_w(dev, 0xa0, address, 0xb33a); 1274 reg_w(dev, 0xa0, address, 0xb33a);
1275 reg_w(dev, 0xa0, 0x02, 0xb339); 1275 reg_w(dev, 0xa0, 0x02, 0xb339);
1276 1276
1277 tmpvalue = 0; 1277 reg_r(gspca_dev, 0xa1, 0xb33b, 1);
1278 reg_r(dev, 0xa1, 0xb33b, &tmpvalue, 1); 1278 while (retry-- && gspca_dev->usb_buf[0]) {
1279 while (retry-- && tmpvalue) { 1279 reg_r(gspca_dev, 0xa1, 0xb33b, 1);
1280 reg_r(dev, 0xa1, 0xb33b, &tmpvalue, 1);
1281/* PDEBUG(D_PROBE, "Read again 0xb33b %d", tmpvalue); */ 1280/* PDEBUG(D_PROBE, "Read again 0xb33b %d", tmpvalue); */
1282 msleep(1); 1281 msleep(1);
1283 } 1282 }
1284 reg_r(dev, 0xa1, 0xb33e, &hdata, 1); 1283 reg_r(gspca_dev, 0xa1, 0xb33e, 1);
1285 reg_r(dev, 0xa1, 0xb33d, &mdata, 1); 1284 hdata = gspca_dev->usb_buf[0];
1286 reg_r(dev, 0xa1, 0xb33c, &ldata, 1); 1285 reg_r(gspca_dev, 0xa1, 0xb33d, 1);
1286 mdata = gspca_dev->usb_buf[0];
1287 reg_r(gspca_dev, 0xa1, 0xb33c, 1);
1288 ldata = gspca_dev->usb_buf[0];
1287 PDEBUG(D_PROBE, "Read Sensor h (0x%02X) m (0x%02X) l (0x%02X)", 1289 PDEBUG(D_PROBE, "Read Sensor h (0x%02X) m (0x%02X) l (0x%02X)",
1288 hdata, mdata, ldata); 1290 hdata, mdata, ldata);
1289 tmpvalue = 0; 1291 reg_r(gspca_dev, 0xa1, 0xb334, 1);
1290 reg_r(dev, 0xa1, 0xb334, &tmpvalue, 1); 1292 if (gspca_dev->usb_buf[0] == 0x02)
1291 if (tmpvalue == 0x02)
1292 *value = (ldata << 8) + mdata; 1293 *value = (ldata << 8) + mdata;
1293 else 1294 else
1294 *value = ldata; 1295 *value = ldata;
1295} 1296}
1297
1296static int vc032x_probe_sensor(struct gspca_dev *gspca_dev) 1298static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
1297{ 1299{
1298 struct usb_device *dev = gspca_dev->dev; 1300 struct usb_device *dev = gspca_dev->dev;
1299 int i; 1301 int i;
1300 __u8 data;
1301 __u16 value; 1302 __u16 value;
1302 const struct sensor_info *ptsensor_info; 1303 const struct sensor_info *ptsensor_info;
1303 1304
1304 reg_r(dev, 0xa1, 0xbfcf, &data, 1); 1305 reg_r(gspca_dev, 0xa1, 0xbfcf, 1);
1305 PDEBUG(D_PROBE, "check sensor header %d", data); 1306 PDEBUG(D_PROBE, "check sensor header %d", gspca_dev->usb_buf[0]);
1306 for (i = 0; i < ARRAY_SIZE(sensor_info_data); i++) { 1307 for (i = 0; i < ARRAY_SIZE(sensor_info_data); i++) {
1307 ptsensor_info = &sensor_info_data[i]; 1308 ptsensor_info = &sensor_info_data[i];
1308 reg_w(dev, 0xa0, 0x02, 0xb334); 1309 reg_w(dev, 0xa0, 0x02, 0xb334);
@@ -1315,7 +1316,7 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
1315 "check sensor VC032X -> %d Add -> ox%02X!", 1316 "check sensor VC032X -> %d Add -> ox%02X!",
1316 i, ptsensor_info->I2cAdd); */ 1317 i, ptsensor_info->I2cAdd); */
1317 reg_w(dev, 0xa0, ptsensor_info->op, 0xb301); 1318 reg_w(dev, 0xa0, ptsensor_info->op, 0xb301);
1318 vc032x_read_sensor_register(dev, ptsensor_info->IdAdd, &value); 1319 read_sensor_register(gspca_dev, ptsensor_info->IdAdd, &value);
1319 if (value == ptsensor_info->VpId) { 1320 if (value == ptsensor_info->VpId) {
1320/* PDEBUG(D_PROBE, "find sensor VC032X -> ox%04X!", 1321/* PDEBUG(D_PROBE, "find sensor VC032X -> ox%04X!",
1321 ptsensor_info->VpId); */ 1322 ptsensor_info->VpId); */
@@ -1325,14 +1326,14 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
1325 return -1; 1326 return -1;
1326} 1327}
1327 1328
1328static __u8 i2c_write(struct usb_device *dev, 1329static __u8 i2c_write(struct gspca_dev *gspca_dev,
1329 __u8 reg, const __u8 *val, __u8 size) 1330 __u8 reg, const __u8 *val, __u8 size)
1330{ 1331{
1331 __u8 retbyte; 1332 struct usb_device *dev = gspca_dev->dev;
1332 1333
1333 if (size > 3 || size < 1) 1334 if (size > 3 || size < 1)
1334 return -EINVAL; 1335 return -EINVAL;
1335 reg_r(dev, 0xa1, 0xb33f, &retbyte, 1); 1336 reg_r(gspca_dev, 0xa1, 0xb33f, 1);
1336 reg_w(dev, 0xa0, size, 0xb334); 1337 reg_w(dev, 0xa0, size, 0xb334);
1337 reg_w(dev, 0xa0, reg, 0xb33a); 1338 reg_w(dev, 0xa0, reg, 0xb33a);
1338 switch (size) { 1339 switch (size) {
@@ -1353,8 +1354,8 @@ static __u8 i2c_write(struct usb_device *dev,
1353 return -EINVAL; 1354 return -EINVAL;
1354 } 1355 }
1355 reg_w(dev, 0xa0, 0x01, 0xb339); 1356 reg_w(dev, 0xa0, 0x01, 0xb339);
1356 reg_r(dev, 0xa1, 0xb33b, &retbyte, 1); 1357 reg_r(gspca_dev, 0xa1, 0xb33b, 1);
1357 return retbyte == 0; 1358 return gspca_dev->usb_buf[0] == 0;
1358} 1359}
1359 1360
1360static void put_tab_to_reg(struct gspca_dev *gspca_dev, 1361static void put_tab_to_reg(struct gspca_dev *gspca_dev,
@@ -1382,10 +1383,10 @@ static void usb_exchange(struct gspca_dev *gspca_dev,
1382 ((data[i][0])<<8) | data[i][1]); 1383 ((data[i][0])<<8) | data[i][1]);
1383 break; 1384 break;
1384 case 0xaa: /* i2c op */ 1385 case 0xaa: /* i2c op */
1385 i2c_write(dev, data[i][1], &data[i][2], 1); 1386 i2c_write(gspca_dev, data[i][1], &data[i][2], 1);
1386 break; 1387 break;
1387 case 0xbb: /* i2c op */ 1388 case 0xbb: /* i2c op */
1388 i2c_write(dev, data[i][0], &data[i][1], 2); 1389 i2c_write(gspca_dev, data[i][0], &data[i][1], 2);
1389 break; 1390 break;
1390 case 0xdd: 1391 case 0xdd:
1391 msleep(data[i][2] + 10); 1392 msleep(data[i][2] + 10);
@@ -1417,7 +1418,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
1417 struct sd *sd = (struct sd *) gspca_dev; 1418 struct sd *sd = (struct sd *) gspca_dev;
1418 struct usb_device *dev = gspca_dev->dev; 1419 struct usb_device *dev = gspca_dev->dev;
1419 struct cam *cam; 1420 struct cam *cam;
1420 __u8 tmp2[4];
1421 int sensor; 1421 int sensor;
1422 __u16 product; 1422 __u16 product;
1423 1423
@@ -1488,10 +1488,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
1488 sd->lightfreq = FREQ_DEF; 1488 sd->lightfreq = FREQ_DEF;
1489 1489
1490 if (sd->bridge == BRIDGE_VC0321) { 1490 if (sd->bridge == BRIDGE_VC0321) {
1491 reg_r(dev, 0x8a, 0, tmp2, 3); 1491 reg_r(gspca_dev, 0x8a, 0, 3);
1492 reg_w(dev, 0x87, 0x00, 0x0f0f); 1492 reg_w(dev, 0x87, 0x00, 0x0f0f);
1493 1493
1494 reg_r(dev, 0x8b, 0, tmp2, 3); 1494 reg_r(gspca_dev, 0x8b, 0, 3);
1495 reg_w(dev, 0x88, 0x00, 0x0202); 1495 reg_w(dev, 0x88, 0x00, 0x0202);
1496 } 1496 }
1497 return 0; 1497 return 0;
@@ -1525,7 +1525,6 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
1525static void sd_start(struct gspca_dev *gspca_dev) 1525static void sd_start(struct gspca_dev *gspca_dev)
1526{ 1526{
1527 struct sd *sd = (struct sd *) gspca_dev; 1527 struct sd *sd = (struct sd *) gspca_dev;
1528/* __u8 tmp2; */
1529 const __u8 *GammaT = NULL; 1528 const __u8 *GammaT = NULL;
1530 const __u8 *MatrixT = NULL; 1529 const __u8 *MatrixT = NULL;
1531 int mode; 1530 int mode;
@@ -1627,7 +1626,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
1627 reg_w(gspca_dev->dev, 0xa0, 0x40, 0xb824); 1626 reg_w(gspca_dev->dev, 0xa0, 0x40, 0xb824);
1628 */ 1627 */
1629 /* Only works for HV7131R ?? 1628 /* Only works for HV7131R ??
1630 reg_r (gspca_dev->dev, 0xa1, 0xb881, &tmp2, 1); 1629 reg_r (gspca_dev, 0xa1, 0xb881, 1);
1631 reg_w(gspca_dev->dev, 0xa0, 0xfe01, 0xb881); 1630 reg_w(gspca_dev->dev, 0xa0, 0xfe01, 0xb881);
1632 reg_w(gspca_dev->dev, 0xa0, 0x79, 0xb801); 1631 reg_w(gspca_dev->dev, 0xa0, 0x79, 0xb801);
1633 */ 1632 */
diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c
index bac45a193653..548c4c8c3f33 100644
--- a/drivers/media/video/gspca/zc3xx.c
+++ b/drivers/media/video/gspca/zc3xx.c
@@ -24,8 +24,8 @@
24 24
25#include "gspca.h" 25#include "gspca.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.5"; 28static const char version[] = "2.1.7";
29 29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>, " 30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>, "
31 "Serge A. Suchkov <Serge.A.S@tochka.ru>"); 31 "Serge A. Suchkov <Serge.A.S@tochka.ru>");
@@ -6214,23 +6214,27 @@ static const struct usb_action tas5130c_vf0250_NoFlikerScale[] = {
6214 {} 6214 {}
6215}; 6215};
6216 6216
6217static void reg_r_i(struct usb_device *dev, 6217static int reg_r_i(struct gspca_dev *gspca_dev,
6218 __u16 index, __u8 *buffer) 6218 __u16 index)
6219{ 6219{
6220 usb_control_msg(dev, 6220 usb_control_msg(gspca_dev->dev,
6221 usb_rcvctrlpipe(dev, 0), 6221 usb_rcvctrlpipe(gspca_dev->dev, 0),
6222 0xa1, 6222 0xa1,
6223 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 6223 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
6224 0x01, /* value */ 6224 0x01, /* value */
6225 index, buffer, 1, 6225 index, gspca_dev->usb_buf, 1,
6226 500); 6226 500);
6227 return gspca_dev->usb_buf[0];
6227} 6228}
6228 6229
6229static void reg_r(struct usb_device *dev, 6230static int reg_r(struct gspca_dev *gspca_dev,
6230 __u16 index, __u8 *buffer) 6231 __u16 index)
6231{ 6232{
6232 reg_r_i(dev, index, buffer); 6233 int ret;
6233 PDEBUG(D_USBI, "reg r [%04x] -> %02x", index, *buffer); 6234
6235 ret = reg_r_i(gspca_dev, index);
6236 PDEBUG(D_USBI, "reg r [%04x] -> %02x", index, ret);
6237 return ret;
6234} 6238}
6235 6239
6236static void reg_w_i(struct usb_device *dev, 6240static void reg_w_i(struct usb_device *dev,
@@ -6253,55 +6257,54 @@ static void reg_w(struct usb_device *dev,
6253 reg_w_i(dev, value, index); 6257 reg_w_i(dev, value, index);
6254} 6258}
6255 6259
6256static __u16 i2c_read(struct usb_device *dev, __u8 reg) 6260static __u16 i2c_read(struct gspca_dev *gspca_dev,
6261 __u8 reg)
6257{ 6262{
6258 __u8 retbyte; 6263 __u8 retbyte;
6259 __u8 retval[2]; 6264 __u8 retval[2];
6260 6265
6261 reg_w_i(dev, reg, 0x92); 6266 reg_w_i(gspca_dev->dev, reg, 0x92);
6262 reg_w_i(dev, 0x02, 0x90); /* <- read command */ 6267 reg_w_i(gspca_dev->dev, 0x02, 0x90); /* <- read command */
6263 msleep(25); 6268 msleep(25);
6264 reg_r_i(dev, 0x0091, &retbyte); /* read status */ 6269 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */
6265 reg_r_i(dev, 0x0095, &retval[0]); /* read Lowbyte */ 6270 retval[0] = reg_r_i(gspca_dev, 0x0095); /* read Lowbyte */
6266 reg_r_i(dev, 0x0096, &retval[1]); /* read Hightbyte */ 6271 retval[1] = reg_r_i(gspca_dev, 0x0096); /* read Hightbyte */
6267 PDEBUG(D_USBO, "i2c r [%02x] -> (%02x) %02x%02x", 6272 PDEBUG(D_USBO, "i2c r [%02x] -> (%02x) %02x%02x",
6268 reg, retbyte, retval[1], retval[0]); 6273 reg, retbyte, retval[1], retval[0]);
6269 return (retval[1] << 8) | retval[0]; 6274 return (retval[1] << 8) | retval[0];
6270} 6275}
6271 6276
6272static __u8 i2c_write(struct usb_device *dev, 6277static __u8 i2c_write(struct gspca_dev *gspca_dev,
6273 __u8 reg, 6278 __u8 reg,
6274 __u8 valL, 6279 __u8 valL,
6275 __u8 valH) 6280 __u8 valH)
6276{ 6281{
6277 __u8 retbyte; 6282 __u8 retbyte;
6278 6283
6279 reg_w_i(dev, reg, 0x92); 6284 reg_w_i(gspca_dev->dev, reg, 0x92);
6280 reg_w_i(dev, valL, 0x93); 6285 reg_w_i(gspca_dev->dev, valL, 0x93);
6281 reg_w_i(dev, valH, 0x94); 6286 reg_w_i(gspca_dev->dev, valH, 0x94);
6282 reg_w_i(dev, 0x01, 0x90); /* <- write command */ 6287 reg_w_i(gspca_dev->dev, 0x01, 0x90); /* <- write command */
6283 msleep(5); 6288 msleep(5);
6284 reg_r_i(dev, 0x0091, &retbyte); /* read status */ 6289 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */
6285 PDEBUG(D_USBO, "i2c w [%02x] %02x%02x (%02x)", 6290 PDEBUG(D_USBO, "i2c w [%02x] %02x%02x (%02x)",
6286 reg, valH, valL, retbyte); 6291 reg, valH, valL, retbyte);
6287 return retbyte; 6292 return retbyte;
6288} 6293}
6289 6294
6290static void usb_exchange(struct usb_device *dev, 6295static void usb_exchange(struct gspca_dev *gspca_dev,
6291 const struct usb_action *action) 6296 const struct usb_action *action)
6292{ 6297{
6293 __u8 buffread;
6294
6295 while (action->req) { 6298 while (action->req) {
6296 switch (action->req) { 6299 switch (action->req) {
6297 case 0xa0: /* write register */ 6300 case 0xa0: /* write register */
6298 reg_w(dev, action->val, action->idx); 6301 reg_w(gspca_dev->dev, action->val, action->idx);
6299 break; 6302 break;
6300 case 0xa1: /* read status */ 6303 case 0xa1: /* read status */
6301 reg_r(dev, action->idx, &buffread); 6304 reg_r(gspca_dev, action->idx);
6302 break; 6305 break;
6303 case 0xaa: 6306 case 0xaa:
6304 i2c_write(dev, 6307 i2c_write(gspca_dev,
6305 action->val, /* reg */ 6308 action->val, /* reg */
6306 action->idx & 0xff, /* valL */ 6309 action->idx & 0xff, /* valL */
6307 action->idx >> 8); /* valH */ 6310 action->idx >> 8); /* valH */
@@ -6376,7 +6379,6 @@ static void setsharpness(struct gspca_dev *gspca_dev)
6376 struct sd *sd = (struct sd *) gspca_dev; 6379 struct sd *sd = (struct sd *) gspca_dev;
6377 struct usb_device *dev = gspca_dev->dev; 6380 struct usb_device *dev = gspca_dev->dev;
6378 int sharpness; 6381 int sharpness;
6379 __u8 retbyte;
6380 static const __u8 sharpness_tb[][2] = { 6382 static const __u8 sharpness_tb[][2] = {
6381 {0x02, 0x03}, 6383 {0x02, 0x03},
6382 {0x04, 0x07}, 6384 {0x04, 0x07},
@@ -6386,9 +6388,9 @@ static void setsharpness(struct gspca_dev *gspca_dev)
6386 6388
6387 sharpness = sd->sharpness; 6389 sharpness = sd->sharpness;
6388 reg_w(dev, sharpness_tb[sharpness][0], 0x01c6); 6390 reg_w(dev, sharpness_tb[sharpness][0], 0x01c6);
6389 reg_r(dev, 0x01c8, &retbyte); 6391 reg_r(gspca_dev, 0x01c8);
6390 reg_r(dev, 0x01c9, &retbyte); 6392 reg_r(gspca_dev, 0x01c9);
6391 reg_r(dev, 0x01ca, &retbyte); 6393 reg_r(gspca_dev, 0x01ca);
6392 reg_w(dev, sharpness_tb[sharpness][1], 0x01cb); 6394 reg_w(dev, sharpness_tb[sharpness][1], 0x01cb);
6393} 6395}
6394 6396
@@ -6398,7 +6400,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
6398 struct usb_device *dev = gspca_dev->dev; 6400 struct usb_device *dev = gspca_dev->dev;
6399 const __u8 *Tgamma, *Tgradient; 6401 const __u8 *Tgamma, *Tgradient;
6400 int g, i, k; 6402 int g, i, k;
6401 static const __u8 kgamma_tb[16] = /* delta for contrast */ 6403 static const __u8 kgamma_tb[16] = /* delta for contrast */
6402 {0x15, 0x0d, 0x0a, 0x09, 0x08, 0x08, 0x08, 0x08, 6404 {0x15, 0x0d, 0x0a, 0x09, 0x08, 0x08, 0x08, 0x08,
6403 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08}; 6405 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08};
6404 static const __u8 kgrad_tb[16] = 6406 static const __u8 kgrad_tb[16] =
@@ -6623,7 +6625,7 @@ static int setlightfreq(struct gspca_dev *gspca_dev)
6623 i++; /* 640x480 */ 6625 i++; /* 640x480 */
6624 zc3_freq = freq_tb[(int) sd->sensor][i]; 6626 zc3_freq = freq_tb[(int) sd->sensor][i];
6625 if (zc3_freq != NULL) { 6627 if (zc3_freq != NULL) {
6626 usb_exchange(gspca_dev->dev, zc3_freq); 6628 usb_exchange(gspca_dev, zc3_freq);
6627 switch (sd->sensor) { 6629 switch (sd->sensor) {
6628 case SENSOR_GC0305: 6630 case SENSOR_GC0305:
6629 if (mode /* if 320x240 */ 6631 if (mode /* if 320x240 */
@@ -6687,44 +6689,45 @@ static void start_2wr_probe(struct usb_device *dev, int sensor)
6687/* msleep(2); */ 6689/* msleep(2); */
6688} 6690}
6689 6691
6690static int sif_probe(struct usb_device *dev) 6692static int sif_probe(struct gspca_dev *gspca_dev)
6691{ 6693{
6692 __u16 checkword; 6694 __u16 checkword;
6693 6695
6694 start_2wr_probe(dev, 0x0f); /* PAS106 */ 6696 start_2wr_probe(gspca_dev->dev, 0x0f); /* PAS106 */
6695 reg_w(dev, 0x08, 0x008d); 6697 reg_w(gspca_dev->dev, 0x08, 0x008d);
6696 msleep(150); 6698 msleep(150);
6697 checkword = ((i2c_read(dev, 0x00) & 0x0f) << 4) 6699 checkword = ((i2c_read(gspca_dev, 0x00) & 0x0f) << 4)
6698 | ((i2c_read(dev, 0x01) & 0xf0) >> 4); 6700 | ((i2c_read(gspca_dev, 0x01) & 0xf0) >> 4);
6699 PDEBUG(D_PROBE, "probe sif 0x%04x", checkword); 6701 PDEBUG(D_PROBE, "probe sif 0x%04x", checkword);
6700 if (checkword == 0x0007) { 6702 if (checkword == 0x0007) {
6701 send_unknown(dev, SENSOR_PAS106); 6703 send_unknown(gspca_dev->dev, SENSOR_PAS106);
6702 return 0x0f; /* PAS106 */ 6704 return 0x0f; /* PAS106 */
6703 } 6705 }
6704 return -1; 6706 return -1;
6705} 6707}
6706 6708
6707static int vga_2wr_probe(struct usb_device *dev) 6709static int vga_2wr_probe(struct gspca_dev *gspca_dev)
6708{ 6710{
6711 struct usb_device *dev = gspca_dev->dev;
6709 __u8 retbyte; 6712 __u8 retbyte;
6710 __u16 checkword; 6713 __u16 checkword;
6711 6714
6712 start_2wr_probe(dev, 0x00); /* HV7131B */ 6715 start_2wr_probe(dev, 0x00); /* HV7131B */
6713 i2c_write(dev, 0x01, 0xaa, 0x00); 6716 i2c_write(gspca_dev, 0x01, 0xaa, 0x00);
6714 retbyte = i2c_read(dev, 0x01); 6717 retbyte = i2c_read(gspca_dev, 0x01);
6715 if (retbyte != 0) 6718 if (retbyte != 0)
6716 return 0x00; /* HV7131B */ 6719 return 0x00; /* HV7131B */
6717 6720
6718 start_2wr_probe(dev, 0x04); /* CS2102 */ 6721 start_2wr_probe(dev, 0x04); /* CS2102 */
6719 i2c_write(dev, 0x01, 0xaa, 0x00); 6722 i2c_write(gspca_dev, 0x01, 0xaa, 0x00);
6720 retbyte = i2c_read(dev, 0x01); 6723 retbyte = i2c_read(gspca_dev, 0x01);
6721 if (retbyte != 0) 6724 if (retbyte != 0)
6722 return 0x04; /* CS2102 */ 6725 return 0x04; /* CS2102 */
6723 6726
6724 start_2wr_probe(dev, 0x06); /* OmniVision */ 6727 start_2wr_probe(dev, 0x06); /* OmniVision */
6725 reg_w(dev, 0x08, 0x8d); 6728 reg_w(dev, 0x08, 0x8d);
6726 i2c_write(dev, 0x11, 0xaa, 0x00); 6729 i2c_write(gspca_dev, 0x11, 0xaa, 0x00);
6727 retbyte = i2c_read(dev, 0x11); 6730 retbyte = i2c_read(gspca_dev, 0x11);
6728 if (retbyte != 0) { 6731 if (retbyte != 0) {
6729 /* (should have returned 0xaa) --> Omnivision? */ 6732 /* (should have returned 0xaa) --> Omnivision? */
6730 /* reg_r 0x10 -> 0x06 --> */ 6733 /* reg_r 0x10 -> 0x06 --> */
@@ -6732,45 +6735,45 @@ static int vga_2wr_probe(struct usb_device *dev)
6732 } 6735 }
6733 6736
6734 start_2wr_probe(dev, 0x08); /* HDCS2020 */ 6737 start_2wr_probe(dev, 0x08); /* HDCS2020 */
6735 i2c_write(dev, 0x15, 0xaa, 0x00); 6738 i2c_write(gspca_dev, 0x15, 0xaa, 0x00);
6736 retbyte = i2c_read(dev, 0x15); 6739 retbyte = i2c_read(gspca_dev, 0x15);
6737 if (retbyte != 0) 6740 if (retbyte != 0)
6738 return 0x08; /* HDCS2020 */ 6741 return 0x08; /* HDCS2020 */
6739 6742
6740 start_2wr_probe(dev, 0x0a); /* PB0330 */ 6743 start_2wr_probe(dev, 0x0a); /* PB0330 */
6741 i2c_write(dev, 0x07, 0xaa, 0xaa); 6744 i2c_write(gspca_dev, 0x07, 0xaa, 0xaa);
6742 retbyte = i2c_read(dev, 0x07); 6745 retbyte = i2c_read(gspca_dev, 0x07);
6743 if (retbyte != 0) 6746 if (retbyte != 0)
6744 return 0x0a; /* PB0330 */ 6747 return 0x0a; /* PB0330 */
6745 retbyte = i2c_read(dev, 0x03); 6748 retbyte = i2c_read(gspca_dev, 0x03);
6746 if (retbyte != 0) 6749 if (retbyte != 0)
6747 return 0x0a; /* PB0330 ?? */ 6750 return 0x0a; /* PB0330 ?? */
6748 retbyte = i2c_read(dev, 0x04); 6751 retbyte = i2c_read(gspca_dev, 0x04);
6749 if (retbyte != 0) 6752 if (retbyte != 0)
6750 return 0x0a; /* PB0330 ?? */ 6753 return 0x0a; /* PB0330 ?? */
6751 6754
6752 start_2wr_probe(dev, 0x0c); /* ICM105A */ 6755 start_2wr_probe(dev, 0x0c); /* ICM105A */
6753 i2c_write(dev, 0x01, 0x11, 0x00); 6756 i2c_write(gspca_dev, 0x01, 0x11, 0x00);
6754 retbyte = i2c_read(dev, 0x01); 6757 retbyte = i2c_read(gspca_dev, 0x01);
6755 if (retbyte != 0) 6758 if (retbyte != 0)
6756 return 0x0c; /* ICM105A */ 6759 return 0x0c; /* ICM105A */
6757 6760
6758 start_2wr_probe(dev, 0x0e); /* PAS202BCB */ 6761 start_2wr_probe(dev, 0x0e); /* PAS202BCB */
6759 reg_w(dev, 0x08, 0x8d); 6762 reg_w(dev, 0x08, 0x8d);
6760 i2c_write(dev, 0x03, 0xaa, 0x00); 6763 i2c_write(gspca_dev, 0x03, 0xaa, 0x00);
6761 msleep(500); 6764 msleep(500);
6762 retbyte = i2c_read(dev, 0x03); 6765 retbyte = i2c_read(gspca_dev, 0x03);
6763 if (retbyte != 0) 6766 if (retbyte != 0)
6764 return 0x0e; /* PAS202BCB */ 6767 return 0x0e; /* PAS202BCB */
6765 6768
6766 start_2wr_probe(dev, 0x02); /* ?? */ 6769 start_2wr_probe(dev, 0x02); /* ?? */
6767 i2c_write(dev, 0x01, 0xaa, 0x00); 6770 i2c_write(gspca_dev, 0x01, 0xaa, 0x00);
6768 retbyte = i2c_read(dev, 0x01); 6771 retbyte = i2c_read(gspca_dev, 0x01);
6769 if (retbyte != 0) 6772 if (retbyte != 0)
6770 return 0x02; /* ?? */ 6773 return 0x02; /* ?? */
6771ov_check: 6774ov_check:
6772 reg_r(dev, 0x0010, &retbyte); /* ?? */ 6775 reg_r(gspca_dev, 0x0010); /* ?? */
6773 reg_r(dev, 0x0010, &retbyte); 6776 reg_r(gspca_dev, 0x0010);
6774 6777
6775 reg_w(dev, 0x01, 0x0000); 6778 reg_w(dev, 0x01, 0x0000);
6776 reg_w(dev, 0x01, 0x0001); 6779 reg_w(dev, 0x01, 0x0001);
@@ -6779,10 +6782,10 @@ ov_check:
6779 reg_w(dev, 0x08, 0x008d); 6782 reg_w(dev, 0x08, 0x008d);
6780 msleep(500); 6783 msleep(500);
6781 reg_w(dev, 0x01, 0x0012); 6784 reg_w(dev, 0x01, 0x0012);
6782 i2c_write(dev, 0x12, 0x80, 0x00); /* sensor reset */ 6785 i2c_write(gspca_dev, 0x12, 0x80, 0x00); /* sensor reset */
6783 retbyte = i2c_read(dev, 0x0a); 6786 retbyte = i2c_read(gspca_dev, 0x0a);
6784 checkword = retbyte << 8; 6787 checkword = retbyte << 8;
6785 retbyte = i2c_read(dev, 0x0b); 6788 retbyte = i2c_read(gspca_dev, 0x0b);
6786 checkword |= retbyte; 6789 checkword |= retbyte;
6787 PDEBUG(D_PROBE, "probe 2wr ov vga 0x%04x", checkword); 6790 PDEBUG(D_PROBE, "probe 2wr ov vga 0x%04x", checkword);
6788 switch (checkword) { 6791 switch (checkword) {
@@ -6821,7 +6824,7 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6821 6824
6822/*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/ 6825/*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/
6823 reg_w(dev, 0x02, 0x0010); 6826 reg_w(dev, 0x02, 0x0010);
6824 reg_r(dev, 0x10, &retbyte); 6827 reg_r(gspca_dev, 0x10);
6825 reg_w(dev, 0x01, 0x0000); 6828 reg_w(dev, 0x01, 0x0000);
6826 reg_w(dev, 0x00, 0x0010); 6829 reg_w(dev, 0x00, 0x0010);
6827 reg_w(dev, 0x01, 0x0001); 6830 reg_w(dev, 0x01, 0x0001);
@@ -6829,23 +6832,23 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6829 reg_w(dev, 0x03, 0x0012); 6832 reg_w(dev, 0x03, 0x0012);
6830 reg_w(dev, 0x01, 0x0012); 6833 reg_w(dev, 0x01, 0x0012);
6831 reg_w(dev, 0x05, 0x0012); 6834 reg_w(dev, 0x05, 0x0012);
6832 retbyte = i2c_read(dev, 0x14); 6835 retbyte = i2c_read(gspca_dev, 0x14);
6833 if (retbyte != 0) 6836 if (retbyte != 0)
6834 return 0x11; /* HV7131R */ 6837 return 0x11; /* HV7131R */
6835 retbyte = i2c_read(dev, 0x15); 6838 retbyte = i2c_read(gspca_dev, 0x15);
6836 if (retbyte != 0) 6839 if (retbyte != 0)
6837 return 0x11; /* HV7131R */ 6840 return 0x11; /* HV7131R */
6838 retbyte = i2c_read(dev, 0x16); 6841 retbyte = i2c_read(gspca_dev, 0x16);
6839 if (retbyte != 0) 6842 if (retbyte != 0)
6840 return 0x11; /* HV7131R */ 6843 return 0x11; /* HV7131R */
6841 6844
6842 reg_w(dev, 0x02, 0x0010); 6845 reg_w(dev, 0x02, 0x0010);
6843 reg_r(dev, 0x000b, &retbyte); 6846 retbyte = reg_r(gspca_dev, 0x000b);
6844 checkword = retbyte << 8; 6847 checkword = retbyte << 8;
6845 reg_r(dev, 0x000a, &retbyte); 6848 retbyte = reg_r(gspca_dev, 0x000a);
6846 checkword |= retbyte; 6849 checkword |= retbyte;
6847 PDEBUG(D_PROBE, "probe 3wr vga 1 0x%04x", checkword); 6850 PDEBUG(D_PROBE, "probe 3wr vga 1 0x%04x", checkword);
6848 reg_r(dev, 0x0010, &retbyte); 6851 reg_r(gspca_dev, 0x0010);
6849 /* this is tested only once anyway */ 6852 /* this is tested only once anyway */
6850 i = 0; 6853 i = 0;
6851 while (chipset_revision_sensor[i].revision) { 6854 while (chipset_revision_sensor[i].revision) {
@@ -6863,7 +6866,7 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6863 reg_w(dev, 0x0a, 0x0010); 6866 reg_w(dev, 0x0a, 0x0010);
6864 reg_w(dev, 0x03, 0x0012); 6867 reg_w(dev, 0x03, 0x0012);
6865 reg_w(dev, 0x01, 0x0012); 6868 reg_w(dev, 0x01, 0x0012);
6866 retbyte = i2c_read(dev, 0x00); 6869 retbyte = i2c_read(gspca_dev, 0x00);
6867 if (retbyte != 0) { 6870 if (retbyte != 0) {
6868 PDEBUG(D_PROBE, "probe 3wr vga type 0a ?"); 6871 PDEBUG(D_PROBE, "probe 3wr vga type 0a ?");
6869 return 0x0a; /* ?? */ 6872 return 0x0a; /* ?? */
@@ -6876,7 +6879,7 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6876 reg_w(dev, 0x03, 0x0012); 6879 reg_w(dev, 0x03, 0x0012);
6877 msleep(2); 6880 msleep(2);
6878 reg_w(dev, 0x01, 0x0012); 6881 reg_w(dev, 0x01, 0x0012);
6879 retbyte = i2c_read(dev, 0x00); 6882 retbyte = i2c_read(gspca_dev, 0x00);
6880 if (retbyte != 0) { 6883 if (retbyte != 0) {
6881 PDEBUG(D_PROBE, "probe 3wr vga type %02x", retbyte); 6884 PDEBUG(D_PROBE, "probe 3wr vga type %02x", retbyte);
6882 send_unknown(dev, SENSOR_GC0305); 6885 send_unknown(dev, SENSOR_GC0305);
@@ -6890,8 +6893,8 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6890 reg_w(dev, 0x06, 0x0010); 6893 reg_w(dev, 0x06, 0x0010);
6891 reg_w(dev, 0x01, 0x0012); 6894 reg_w(dev, 0x01, 0x0012);
6892 reg_w(dev, 0x05, 0x0012); 6895 reg_w(dev, 0x05, 0x0012);
6893 if (i2c_read(dev, 0x1c) == 0x7f /* OV7610 - manufacturer ID */ 6896 if (i2c_read(gspca_dev, 0x1c) == 0x7f /* OV7610 - manufacturer ID */
6894 && i2c_read(dev, 0x1d) == 0xa2) { 6897 && i2c_read(gspca_dev, 0x1d) == 0xa2) {
6895 send_unknown(dev, SENSOR_OV7620); 6898 send_unknown(dev, SENSOR_OV7620);
6896 return 0x06; /* OmniVision confirm ? */ 6899 return 0x06; /* OmniVision confirm ? */
6897 } 6900 }
@@ -6905,13 +6908,13 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6905/* msleep(150); */ 6908/* msleep(150); */
6906 reg_w(dev, 0x01, 0x12); 6909 reg_w(dev, 0x01, 0x12);
6907 reg_w(dev, 0x05, 0x12); 6910 reg_w(dev, 0x05, 0x12);
6908 retbyte = i2c_read(dev, 0x00); /* ID 0 */ 6911 retbyte = i2c_read(gspca_dev, 0x00); /* ID 0 */
6909 checkword = retbyte << 8; 6912 checkword = retbyte << 8;
6910 retbyte = i2c_read(dev, 0x01); /* ID 1 */ 6913 retbyte = i2c_read(gspca_dev, 0x01); /* ID 1 */
6911 checkword |= retbyte; 6914 checkword |= retbyte;
6912 PDEBUG(D_PROBE, "probe 3wr vga 2 0x%04x", checkword); 6915 PDEBUG(D_PROBE, "probe 3wr vga 2 0x%04x", checkword);
6913 if (checkword == 0x2030) { 6916 if (checkword == 0x2030) {
6914 retbyte = i2c_read(dev, 0x02); /* revision number */ 6917 retbyte = i2c_read(gspca_dev, 0x02); /* revision number */
6915 PDEBUG(D_PROBE, "sensor PO2030 rev 0x%02x", retbyte); 6918 PDEBUG(D_PROBE, "sensor PO2030 rev 0x%02x", retbyte);
6916 send_unknown(dev, SENSOR_PO2030); 6919 send_unknown(dev, SENSOR_PO2030);
6917 return checkword; 6920 return checkword;
@@ -6925,7 +6928,7 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6925 reg_w(dev, 0x01, 0x12); 6928 reg_w(dev, 0x01, 0x12);
6926 reg_w(dev, 0x05, 0x01); 6929 reg_w(dev, 0x05, 0x01);
6927 reg_w(dev, 0xd3, 0x8b); 6930 reg_w(dev, 0xd3, 0x8b);
6928 retbyte = i2c_read(dev, 0x01); 6931 retbyte = i2c_read(gspca_dev, 0x01);
6929 if (retbyte != 0) { 6932 if (retbyte != 0) {
6930 PDEBUG(D_PROBE, "probe 3wr vga type 0a ?"); 6933 PDEBUG(D_PROBE, "probe 3wr vga type 0a ?");
6931 return 0x0a; /* ?? */ 6934 return 0x0a; /* ?? */
@@ -6936,7 +6939,6 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6936static int zcxx_probeSensor(struct gspca_dev *gspca_dev) 6939static int zcxx_probeSensor(struct gspca_dev *gspca_dev)
6937{ 6940{
6938 struct sd *sd = (struct sd *) gspca_dev; 6941 struct sd *sd = (struct sd *) gspca_dev;
6939 struct usb_device *dev = gspca_dev->dev;
6940 int sensor, sensor2; 6942 int sensor, sensor2;
6941 6943
6942 switch (sd->sensor) { 6944 switch (sd->sensor) {
@@ -6944,7 +6946,7 @@ static int zcxx_probeSensor(struct gspca_dev *gspca_dev)
6944 case SENSOR_TAS5130C_VF0250: 6946 case SENSOR_TAS5130C_VF0250:
6945 return -1; /* don't probe */ 6947 return -1; /* don't probe */
6946 } 6948 }
6947 sensor = vga_2wr_probe(dev); 6949 sensor = vga_2wr_probe(gspca_dev);
6948 if (sensor >= 0) { 6950 if (sensor >= 0) {
6949 if (sensor < 0x7600) 6951 if (sensor < 0x7600)
6950 return sensor; 6952 return sensor;
@@ -6956,7 +6958,7 @@ static int zcxx_probeSensor(struct gspca_dev *gspca_dev)
6956 return sensor; 6958 return sensor;
6957 return sensor2; 6959 return sensor2;
6958 } 6960 }
6959 return sif_probe(dev); 6961 return sif_probe(gspca_dev);
6960} 6962}
6961 6963
6962/* this function is called at probe time */ 6964/* this function is called at probe time */
@@ -6966,7 +6968,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
6966 struct sd *sd = (struct sd *) gspca_dev; 6968 struct sd *sd = (struct sd *) gspca_dev;
6967 struct cam *cam; 6969 struct cam *cam;
6968 int sensor; 6970 int sensor;
6969 __u8 bsensor;
6970 int vga = 1; /* 1: vga, 0: sif */ 6971 int vga = 1; /* 1: vga, 0: sif */
6971 static const __u8 gamma[SENSOR_MAX] = { 6972 static const __u8 gamma[SENSOR_MAX] = {
6972 5, /* SENSOR_CS2102 0 */ 6973 5, /* SENSOR_CS2102 0 */
@@ -7122,7 +7123,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
7122 reg_w(gspca_dev->dev, 0x02, 0x0010); 7123 reg_w(gspca_dev->dev, 0x02, 0x0010);
7123 else 7124 else
7124 reg_w(gspca_dev->dev, sensor & 0x0f, 0x0010); 7125 reg_w(gspca_dev->dev, sensor & 0x0f, 0x0010);
7125 reg_r(gspca_dev->dev, 0x0010, &bsensor); 7126 reg_r(gspca_dev, 0x0010);
7126 } 7127 }
7127 7128
7128 cam = &gspca_dev->cam; 7129 cam = &gspca_dev->cam;
@@ -7163,7 +7164,6 @@ static void sd_start(struct gspca_dev *gspca_dev)
7163 struct usb_device *dev = gspca_dev->dev; 7164 struct usb_device *dev = gspca_dev->dev;
7164 const struct usb_action *zc3_init; 7165 const struct usb_action *zc3_init;
7165 int mode; 7166 int mode;
7166 __u8 retbyte;
7167 static const struct usb_action *init_tb[SENSOR_MAX][2] = { 7167 static const struct usb_action *init_tb[SENSOR_MAX][2] = {
7168 {cs2102_InitialScale, cs2102_Initial}, /* 0 */ 7168 {cs2102_InitialScale, cs2102_Initial}, /* 0 */
7169 {cs2102K_InitialScale, cs2102K_Initial}, /* 1 */ 7169 {cs2102K_InitialScale, cs2102K_Initial}, /* 1 */
@@ -7194,7 +7194,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
7194 zcxx_probeSensor(gspca_dev); 7194 zcxx_probeSensor(gspca_dev);
7195 break; 7195 break;
7196 case SENSOR_PAS106: 7196 case SENSOR_PAS106:
7197 usb_exchange(dev, pas106b_Initial_com); 7197 usb_exchange(gspca_dev, pas106b_Initial_com);
7198 break; 7198 break;
7199 case SENSOR_PB0330: 7199 case SENSOR_PB0330:
7200 if (mode) { 7200 if (mode) {
@@ -7210,14 +7210,14 @@ static void sd_start(struct gspca_dev *gspca_dev)
7210 } 7210 }
7211 break; 7211 break;
7212 } 7212 }
7213 usb_exchange(dev, zc3_init); 7213 usb_exchange(gspca_dev, zc3_init);
7214 7214
7215 switch (sd->sensor) { 7215 switch (sd->sensor) {
7216 case SENSOR_GC0305: 7216 case SENSOR_GC0305:
7217 case SENSOR_OV7620: 7217 case SENSOR_OV7620:
7218 case SENSOR_PO2030: 7218 case SENSOR_PO2030:
7219 msleep(100); /* ?? */ 7219 msleep(100); /* ?? */
7220 reg_r(dev, 0x0002, &retbyte); /* --> 0x40 */ 7220 reg_r(gspca_dev, 0x0002); /* --> 0x40 */
7221 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */ 7221 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */
7222 reg_w(dev, 0x15, 0x01ae); 7222 reg_w(dev, 0x15, 0x01ae);
7223 reg_w(dev, 0x0d, 0x003a); 7223 reg_w(dev, 0x0d, 0x003a);
@@ -7230,11 +7230,11 @@ static void sd_start(struct gspca_dev *gspca_dev)
7230 setbrightness(gspca_dev); 7230 setbrightness(gspca_dev);
7231 switch (sd->sensor) { 7231 switch (sd->sensor) {
7232 case SENSOR_OV7620: 7232 case SENSOR_OV7620:
7233 reg_r(dev, 0x0008, &retbyte); 7233 reg_r(gspca_dev, 0x0008);
7234 reg_w(dev, 0x00, 0x0008); 7234 reg_w(dev, 0x00, 0x0008);
7235 break; 7235 break;
7236 case SENSOR_GC0305: 7236 case SENSOR_GC0305:
7237 reg_r(dev, 0x0008, &retbyte); 7237 reg_r(gspca_dev, 0x0008);
7238 /* fall thru */ 7238 /* fall thru */
7239 case SENSOR_PO2030: 7239 case SENSOR_PO2030:
7240 reg_w(dev, 0x03, 0x0008); 7240 reg_w(dev, 0x03, 0x0008);
@@ -7259,7 +7259,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
7259 setmatrix(gspca_dev); /* one more time? */ 7259 setmatrix(gspca_dev); /* one more time? */
7260 switch (sd->sensor) { 7260 switch (sd->sensor) {
7261 case SENSOR_OV7620: 7261 case SENSOR_OV7620:
7262 reg_r(dev, 0x0180, &retbyte); /* from win */ 7262 reg_r(gspca_dev, 0x0180); /* from win */
7263 reg_w(dev, 0x00, 0x0180); 7263 reg_w(dev, 0x00, 0x0180);
7264 break; 7264 break;
7265 default: 7265 default:
@@ -7277,7 +7277,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
7277 break; 7277 break;
7278 case SENSOR_PO2030: 7278 case SENSOR_PO2030:
7279 reg_w(dev, 0x40, 0x0117); /* (from win traces) */ 7279 reg_w(dev, 0x40, 0x0117); /* (from win traces) */
7280 reg_r(dev, 0x0180, &retbyte); 7280 reg_r(gspca_dev, 0x0180);
7281 break; 7281 break;
7282 } 7282 }
7283 7283
@@ -7289,22 +7289,23 @@ static void sd_start(struct gspca_dev *gspca_dev)
7289 reg_w(dev, 0x15, 0x01ae); 7289 reg_w(dev, 0x15, 0x01ae);
7290 reg_w(dev, 0x40, 0x0180); 7290 reg_w(dev, 0x40, 0x0180);
7291 reg_w(dev, 0x40, 0x0117); 7291 reg_w(dev, 0x40, 0x0117);
7292 reg_r(dev, 0x0180, &retbyte); 7292 reg_r(gspca_dev, 0x0180);
7293 sd->autogain = 1; 7293 sd->autogain = 1;
7294 setautogain(gspca_dev); 7294 setautogain(gspca_dev);
7295 break; 7295 break;
7296 case SENSOR_OV7620: 7296 case SENSOR_OV7620:
7297 i2c_read(dev, 0x13); /*fixme: returns 0xa3 */ 7297 i2c_read(gspca_dev, 0x13); /*fixme: returns 0xa3 */
7298 i2c_write(dev, 0x13, 0xa3, 0x00); /*fixme: same to send? */ 7298 i2c_write(gspca_dev, 0x13, 0xa3, 0x00);
7299 /*fixme: returned value to send? */
7299 reg_w(dev, 0x40, 0x0117); /* (from win traces) */ 7300 reg_w(dev, 0x40, 0x0117); /* (from win traces) */
7300 reg_r(dev, 0x0180, &retbyte); 7301 reg_r(gspca_dev, 0x0180);
7301 setautogain(gspca_dev); 7302 setautogain(gspca_dev);
7302 msleep(500); 7303 msleep(500);
7303 break; 7304 break;
7304 case SENSOR_PO2030: 7305 case SENSOR_PO2030:
7305 msleep(500); 7306 msleep(500);
7306 reg_r(dev, 0x0008, &retbyte); 7307 reg_r(gspca_dev, 0x0008);
7307 reg_r(dev, 0x0007, &retbyte); 7308 reg_r(gspca_dev, 0x0007);
7308 reg_w(dev, 0x00, 0x0007); /* (from win traces) */ 7309 reg_w(dev, 0x00, 0x0007); /* (from win traces) */
7309 reg_w(dev, 0x02, 0x0008); 7310 reg_w(dev, 0x02, 0x0008);
7310 break; 7311 break;