aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJean-François Moine <moinejf@free.fr>2011-05-17 04:32:39 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-05-21 08:36:15 -0400
commitcf25220677b3f10468a74278130fe224f73632a6 (patch)
tree682af16f4011a04fa31639441a4f03e4af0077e0 /drivers
parentbd62bbcd31f36db2ffb08a9f32743b2595d12613 (diff)
[media] gspca - sunplus: Fix some warnings and simplify code
This patch removes warnings due to GSPCA_DEBUG unsetting. It implied a simplification of the code. Signed-off-by: Jean-François Moine <moinejf@free.fr> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/gspca/sunplus.c99
1 files changed, 33 insertions, 66 deletions
diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c
index 543542af2720..b089c0d3ee9f 100644
--- a/drivers/media/video/gspca/sunplus.c
+++ b/drivers/media/video/gspca/sunplus.c
@@ -396,57 +396,6 @@ static void reg_w_riv(struct gspca_dev *gspca_dev,
396 req, index, value); 396 req, index, value);
397} 397}
398 398
399/* read 1 byte */
400static u8 reg_r_1(struct gspca_dev *gspca_dev,
401 u16 value) /* wValue */
402{
403 int ret;
404
405 if (gspca_dev->usb_err < 0)
406 return 0;
407 ret = usb_control_msg(gspca_dev->dev,
408 usb_rcvctrlpipe(gspca_dev->dev, 0),
409 0x20, /* request */
410 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
411 value,
412 0, /* index */
413 gspca_dev->usb_buf, 1,
414 500); /* timeout */
415 if (ret < 0) {
416 err("reg_r_1 err %d", ret);
417 gspca_dev->usb_err = ret;
418 return 0;
419 }
420 return gspca_dev->usb_buf[0];
421}
422
423/* read 1 or 2 bytes */
424static u16 reg_r_12(struct gspca_dev *gspca_dev,
425 u8 req, /* bRequest */
426 u16 index, /* wIndex */
427 u16 length) /* wLength (1 or 2 only) */
428{
429 int ret;
430
431 if (gspca_dev->usb_err < 0)
432 return 0;
433 gspca_dev->usb_buf[1] = 0;
434 ret = usb_control_msg(gspca_dev->dev,
435 usb_rcvctrlpipe(gspca_dev->dev, 0),
436 req,
437 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
438 0, /* value */
439 index,
440 gspca_dev->usb_buf, length,
441 500);
442 if (ret < 0) {
443 err("reg_r_12 err %d", ret);
444 gspca_dev->usb_err = ret;
445 return 0;
446 }
447 return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
448}
449
450static void write_vector(struct gspca_dev *gspca_dev, 399static void write_vector(struct gspca_dev *gspca_dev,
451 const struct cmd *data, int ncmds) 400 const struct cmd *data, int ncmds)
452{ 401{
@@ -473,44 +422,46 @@ static void setup_qtable(struct gspca_dev *gspca_dev,
473static void spca504_acknowledged_command(struct gspca_dev *gspca_dev, 422static void spca504_acknowledged_command(struct gspca_dev *gspca_dev,
474 u8 req, u16 idx, u16 val) 423 u8 req, u16 idx, u16 val)
475{ 424{
476 u16 notdone;
477
478 reg_w_riv(gspca_dev, req, idx, val); 425 reg_w_riv(gspca_dev, req, idx, val);
479 notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1); 426 reg_r(gspca_dev, 0x01, 0x0001, 1);
427 PDEBUG(D_FRAM, "before wait 0x%04x", gspca_dev->usb_buf[0]);
480 reg_w_riv(gspca_dev, req, idx, val); 428 reg_w_riv(gspca_dev, req, idx, val);
481 429
482 PDEBUG(D_FRAM, "before wait 0x%04x", notdone);
483
484 msleep(200); 430 msleep(200);
485 notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1); 431 reg_r(gspca_dev, 0x01, 0x0001, 1);
486 PDEBUG(D_FRAM, "after wait 0x%04x", notdone); 432 PDEBUG(D_FRAM, "after wait 0x%04x", gspca_dev->usb_buf[0]);
487} 433}
488 434
435#ifdef GSPCA_DEBUG
489static void spca504_read_info(struct gspca_dev *gspca_dev) 436static void spca504_read_info(struct gspca_dev *gspca_dev)
490{ 437{
491 int i; 438 int i;
492 u8 info[6]; 439 u8 info[6];
493 440
494 for (i = 0; i < 6; i++) 441 for (i = 0; i < 6; i++) {
495 info[i] = reg_r_1(gspca_dev, i); 442 reg_r(gspca_dev, 0, i, 1);
443 info[i] = gspca_dev->usb_buf[0];
444 }
496 PDEBUG(D_STREAM, 445 PDEBUG(D_STREAM,
497 "Read info: %d %d %d %d %d %d." 446 "Read info: %d %d %d %d %d %d."
498 " Should be 1,0,2,2,0,0", 447 " Should be 1,0,2,2,0,0",
499 info[0], info[1], info[2], 448 info[0], info[1], info[2],
500 info[3], info[4], info[5]); 449 info[3], info[4], info[5]);
501} 450}
451#endif
502 452
503static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev, 453static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
504 u8 req, 454 u8 req,
505 u16 idx, u16 val, u16 endcode, u8 count) 455 u16 idx, u16 val, u8 endcode, u8 count)
506{ 456{
507 u16 status; 457 u16 status;
508 458
509 reg_w_riv(gspca_dev, req, idx, val); 459 reg_w_riv(gspca_dev, req, idx, val);
510 status = reg_r_12(gspca_dev, 0x01, 0x0001, 1); 460 reg_r(gspca_dev, 0x01, 0x0001, 1);
511 if (gspca_dev->usb_err < 0) 461 if (gspca_dev->usb_err < 0)
512 return; 462 return;
513 PDEBUG(D_FRAM, "Status 0x%04x Need 0x%04x", status, endcode); 463 PDEBUG(D_FRAM, "Status 0x%02x Need 0x%02x",
464 gspca_dev->usb_buf[0], endcode);
514 if (!count) 465 if (!count)
515 return; 466 return;
516 count = 200; 467 count = 200;
@@ -518,7 +469,8 @@ static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
518 msleep(10); 469 msleep(10);
519 /* gsmart mini2 write a each wait setting 1 ms is enough */ 470 /* gsmart mini2 write a each wait setting 1 ms is enough */
520/* reg_w_riv(gspca_dev, req, idx, val); */ 471/* reg_w_riv(gspca_dev, req, idx, val); */
521 status = reg_r_12(gspca_dev, 0x01, 0x0001, 1); 472 reg_r(gspca_dev, 0x01, 0x0001, 1);
473 status = gspca_dev->usb_buf[0];
522 if (status == endcode) { 474 if (status == endcode) {
523 PDEBUG(D_FRAM, "status 0x%04x after wait %d", 475 PDEBUG(D_FRAM, "status 0x%04x after wait %d",
524 status, 200 - count); 476 status, 200 - count);
@@ -555,17 +507,19 @@ static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
555 } 507 }
556} 508}
557 509
510#ifdef GSPCA_DEBUG
558static void spca50x_GetFirmware(struct gspca_dev *gspca_dev) 511static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
559{ 512{
560 u8 *data; 513 u8 *data;
561 514
562 data = gspca_dev->usb_buf; 515 data = gspca_dev->usb_buf;
563 reg_r(gspca_dev, 0x20, 0, 5); 516 reg_r(gspca_dev, 0x20, 0, 5);
564 PDEBUG(D_STREAM, "FirmWare : %d %d %d %d %d ", 517 PDEBUG(D_STREAM, "FirmWare: %d %d %d %d %d",
565 data[0], data[1], data[2], data[3], data[4]); 518 data[0], data[1], data[2], data[3], data[4]);
566 reg_r(gspca_dev, 0x23, 0, 64); 519 reg_r(gspca_dev, 0x23, 0, 64);
567 reg_r(gspca_dev, 0x23, 1, 64); 520 reg_r(gspca_dev, 0x23, 1, 64);
568} 521}
522#endif
569 523
570static void spca504B_SetSizeType(struct gspca_dev *gspca_dev) 524static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
571{ 525{
@@ -578,7 +532,9 @@ static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
578 reg_w_riv(gspca_dev, 0x31, 0, 0); 532 reg_w_riv(gspca_dev, 0x31, 0, 0);
579 spca504B_WaitCmdStatus(gspca_dev); 533 spca504B_WaitCmdStatus(gspca_dev);
580 spca504B_PollingDataReady(gspca_dev); 534 spca504B_PollingDataReady(gspca_dev);
535#ifdef GSPCA_DEBUG
581 spca50x_GetFirmware(gspca_dev); 536 spca50x_GetFirmware(gspca_dev);
537#endif
582 reg_w_1(gspca_dev, 0x24, 0, 8, 2); /* type */ 538 reg_w_1(gspca_dev, 0x24, 0, 8, 2); /* type */
583 reg_r(gspca_dev, 0x24, 8, 1); 539 reg_r(gspca_dev, 0x24, 8, 1);
584 540
@@ -628,7 +584,8 @@ static void spca504_wait_status(struct gspca_dev *gspca_dev)
628 cnt = 256; 584 cnt = 256;
629 while (--cnt > 0) { 585 while (--cnt > 0) {
630 /* With this we get the status, when return 0 it's all ok */ 586 /* With this we get the status, when return 0 it's all ok */
631 if (reg_r_12(gspca_dev, 0x06, 0x00, 1) == 0) 587 reg_r(gspca_dev, 0x06, 0x00, 1);
588 if (gspca_dev->usb_buf[0] == 0)
632 return; 589 return;
633 msleep(10); 590 msleep(10);
634 } 591 }
@@ -772,10 +729,14 @@ static int sd_init(struct gspca_dev *gspca_dev)
772 /* fall thru */ 729 /* fall thru */
773 case BRIDGE_SPCA533: 730 case BRIDGE_SPCA533:
774 spca504B_PollingDataReady(gspca_dev); 731 spca504B_PollingDataReady(gspca_dev);
732#ifdef GSPCA_DEBUG
775 spca50x_GetFirmware(gspca_dev); 733 spca50x_GetFirmware(gspca_dev);
734#endif
776 break; 735 break;
777 case BRIDGE_SPCA536: 736 case BRIDGE_SPCA536:
737#ifdef GSPCA_DEBUG
778 spca50x_GetFirmware(gspca_dev); 738 spca50x_GetFirmware(gspca_dev);
739#endif
779 reg_r(gspca_dev, 0x00, 0x5002, 1); 740 reg_r(gspca_dev, 0x00, 0x5002, 1);
780 reg_w_1(gspca_dev, 0x24, 0, 0, 0); 741 reg_w_1(gspca_dev, 0x24, 0, 0, 0);
781 reg_r(gspca_dev, 0x24, 0, 1); 742 reg_r(gspca_dev, 0x24, 0, 1);
@@ -801,7 +762,9 @@ static int sd_init(struct gspca_dev *gspca_dev)
801/* case BRIDGE_SPCA504: */ 762/* case BRIDGE_SPCA504: */
802 PDEBUG(D_STREAM, "Opening SPCA504"); 763 PDEBUG(D_STREAM, "Opening SPCA504");
803 if (sd->subtype == AiptekMiniPenCam13) { 764 if (sd->subtype == AiptekMiniPenCam13) {
765#ifdef GSPCA_DEBUG
804 spca504_read_info(gspca_dev); 766 spca504_read_info(gspca_dev);
767#endif
805 768
806 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */ 769 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
807 spca504A_acknowledged_command(gspca_dev, 0x24, 770 spca504A_acknowledged_command(gspca_dev, 0x24,
@@ -873,7 +836,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
873 break; 836 break;
874 case BRIDGE_SPCA504: 837 case BRIDGE_SPCA504:
875 if (sd->subtype == AiptekMiniPenCam13) { 838 if (sd->subtype == AiptekMiniPenCam13) {
839#ifdef GSPCA_DEBUG
876 spca504_read_info(gspca_dev); 840 spca504_read_info(gspca_dev);
841#endif
877 842
878 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */ 843 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
879 spca504A_acknowledged_command(gspca_dev, 0x24, 844 spca504A_acknowledged_command(gspca_dev, 0x24,
@@ -885,7 +850,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
885 0, 0, 0x9d, 1); 850 0, 0, 0x9d, 1);
886 } else { 851 } else {
887 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3); 852 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
853#ifdef GSPCA_DEBUG
888 spca504_read_info(gspca_dev); 854 spca504_read_info(gspca_dev);
855#endif
889 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3); 856 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
890 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); 857 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
891 } 858 }