diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2012-05-16 06:45:59 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-07-30 17:29:33 -0400 |
commit | de687ecf5d02c7732f6f5bac9ccf7924178a3a7d (patch) | |
tree | 6b8383df962c9ebeaf673347e338b10b7cadf7e8 /drivers | |
parent | 2aed6c1b7702359b7964a3367417e6dca9a29582 (diff) |
[media] spca506: convert to the control framework
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/video/gspca/spca506.c | 208 |
1 files changed, 51 insertions, 157 deletions
diff --git a/drivers/media/video/gspca/spca506.c b/drivers/media/video/gspca/spca506.c index 54eed87672d2..7b54f63e9542 100644 --- a/drivers/media/video/gspca/spca506.c +++ b/drivers/media/video/gspca/spca506.c | |||
@@ -33,83 +33,10 @@ MODULE_LICENSE("GPL"); | |||
33 | struct sd { | 33 | struct sd { |
34 | struct gspca_dev gspca_dev; /* !! must be the first item */ | 34 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
35 | 35 | ||
36 | unsigned char brightness; | ||
37 | unsigned char contrast; | ||
38 | unsigned char colors; | ||
39 | unsigned char hue; | ||
40 | char norme; | 36 | char norme; |
41 | char channel; | 37 | char channel; |
42 | }; | 38 | }; |
43 | 39 | ||
44 | /* V4L2 controls supported by the driver */ | ||
45 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); | ||
46 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); | ||
47 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); | ||
48 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); | ||
49 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); | ||
50 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); | ||
51 | static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val); | ||
52 | static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val); | ||
53 | |||
54 | static const struct ctrl sd_ctrls[] = { | ||
55 | #define SD_BRIGHTNESS 0 | ||
56 | { | ||
57 | { | ||
58 | .id = V4L2_CID_BRIGHTNESS, | ||
59 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
60 | .name = "Brightness", | ||
61 | .minimum = 0, | ||
62 | .maximum = 0xff, | ||
63 | .step = 1, | ||
64 | .default_value = 0x80, | ||
65 | }, | ||
66 | .set = sd_setbrightness, | ||
67 | .get = sd_getbrightness, | ||
68 | }, | ||
69 | #define SD_CONTRAST 1 | ||
70 | { | ||
71 | { | ||
72 | .id = V4L2_CID_CONTRAST, | ||
73 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
74 | .name = "Contrast", | ||
75 | .minimum = 0, | ||
76 | .maximum = 0xff, | ||
77 | .step = 1, | ||
78 | .default_value = 0x47, | ||
79 | }, | ||
80 | .set = sd_setcontrast, | ||
81 | .get = sd_getcontrast, | ||
82 | }, | ||
83 | #define SD_COLOR 2 | ||
84 | { | ||
85 | { | ||
86 | .id = V4L2_CID_SATURATION, | ||
87 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
88 | .name = "Saturation", | ||
89 | .minimum = 0, | ||
90 | .maximum = 0xff, | ||
91 | .step = 1, | ||
92 | .default_value = 0x40, | ||
93 | }, | ||
94 | .set = sd_setcolors, | ||
95 | .get = sd_getcolors, | ||
96 | }, | ||
97 | #define SD_HUE 3 | ||
98 | { | ||
99 | { | ||
100 | .id = V4L2_CID_HUE, | ||
101 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
102 | .name = "Hue", | ||
103 | .minimum = 0, | ||
104 | .maximum = 0xff, | ||
105 | .step = 1, | ||
106 | .default_value = 0, | ||
107 | }, | ||
108 | .set = sd_sethue, | ||
109 | .get = sd_gethue, | ||
110 | }, | ||
111 | }; | ||
112 | |||
113 | static const struct v4l2_pix_format vga_mode[] = { | 40 | static const struct v4l2_pix_format vga_mode[] = { |
114 | {160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE, | 41 | {160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE, |
115 | .bytesperline = 160, | 42 | .bytesperline = 160, |
@@ -281,16 +208,11 @@ static void spca506_Setsize(struct gspca_dev *gspca_dev, __u16 code, | |||
281 | static int sd_config(struct gspca_dev *gspca_dev, | 208 | static int sd_config(struct gspca_dev *gspca_dev, |
282 | const struct usb_device_id *id) | 209 | const struct usb_device_id *id) |
283 | { | 210 | { |
284 | struct sd *sd = (struct sd *) gspca_dev; | ||
285 | struct cam *cam; | 211 | struct cam *cam; |
286 | 212 | ||
287 | cam = &gspca_dev->cam; | 213 | cam = &gspca_dev->cam; |
288 | cam->cam_mode = vga_mode; | 214 | cam->cam_mode = vga_mode; |
289 | cam->nmodes = ARRAY_SIZE(vga_mode); | 215 | cam->nmodes = ARRAY_SIZE(vga_mode); |
290 | sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; | ||
291 | sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; | ||
292 | sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value; | ||
293 | sd->hue = sd_ctrls[SD_HUE].qctrl.default_value; | ||
294 | return 0; | 216 | return 0; |
295 | } | 217 | } |
296 | 218 | ||
@@ -564,121 +486,93 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, | |||
564 | } | 486 | } |
565 | } | 487 | } |
566 | 488 | ||
567 | static void setbrightness(struct gspca_dev *gspca_dev) | 489 | static void setbrightness(struct gspca_dev *gspca_dev, s32 val) |
568 | { | 490 | { |
569 | struct sd *sd = (struct sd *) gspca_dev; | ||
570 | |||
571 | spca506_Initi2c(gspca_dev); | 491 | spca506_Initi2c(gspca_dev); |
572 | spca506_WriteI2c(gspca_dev, sd->brightness, SAA7113_bright); | 492 | spca506_WriteI2c(gspca_dev, val, SAA7113_bright); |
573 | spca506_WriteI2c(gspca_dev, 0x01, 0x09); | 493 | spca506_WriteI2c(gspca_dev, 0x01, 0x09); |
574 | } | 494 | } |
575 | 495 | ||
576 | static void setcontrast(struct gspca_dev *gspca_dev) | 496 | static void setcontrast(struct gspca_dev *gspca_dev, s32 val) |
577 | { | 497 | { |
578 | struct sd *sd = (struct sd *) gspca_dev; | ||
579 | |||
580 | spca506_Initi2c(gspca_dev); | 498 | spca506_Initi2c(gspca_dev); |
581 | spca506_WriteI2c(gspca_dev, sd->contrast, SAA7113_contrast); | 499 | spca506_WriteI2c(gspca_dev, val, SAA7113_contrast); |
582 | spca506_WriteI2c(gspca_dev, 0x01, 0x09); | 500 | spca506_WriteI2c(gspca_dev, 0x01, 0x09); |
583 | } | 501 | } |
584 | 502 | ||
585 | static void setcolors(struct gspca_dev *gspca_dev) | 503 | static void setcolors(struct gspca_dev *gspca_dev, s32 val) |
586 | { | 504 | { |
587 | struct sd *sd = (struct sd *) gspca_dev; | ||
588 | |||
589 | spca506_Initi2c(gspca_dev); | 505 | spca506_Initi2c(gspca_dev); |
590 | spca506_WriteI2c(gspca_dev, sd->colors, SAA7113_saturation); | 506 | spca506_WriteI2c(gspca_dev, val, SAA7113_saturation); |
591 | spca506_WriteI2c(gspca_dev, 0x01, 0x09); | 507 | spca506_WriteI2c(gspca_dev, 0x01, 0x09); |
592 | } | 508 | } |
593 | 509 | ||
594 | static void sethue(struct gspca_dev *gspca_dev) | 510 | static void sethue(struct gspca_dev *gspca_dev, s32 val) |
595 | { | 511 | { |
596 | struct sd *sd = (struct sd *) gspca_dev; | ||
597 | |||
598 | spca506_Initi2c(gspca_dev); | 512 | spca506_Initi2c(gspca_dev); |
599 | spca506_WriteI2c(gspca_dev, sd->hue, SAA7113_hue); | 513 | spca506_WriteI2c(gspca_dev, val, SAA7113_hue); |
600 | spca506_WriteI2c(gspca_dev, 0x01, 0x09); | 514 | spca506_WriteI2c(gspca_dev, 0x01, 0x09); |
601 | } | 515 | } |
602 | 516 | ||
603 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) | 517 | static int sd_s_ctrl(struct v4l2_ctrl *ctrl) |
604 | { | ||
605 | struct sd *sd = (struct sd *) gspca_dev; | ||
606 | |||
607 | sd->brightness = val; | ||
608 | if (gspca_dev->streaming) | ||
609 | setbrightness(gspca_dev); | ||
610 | return 0; | ||
611 | } | ||
612 | |||
613 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) | ||
614 | { | ||
615 | struct sd *sd = (struct sd *) gspca_dev; | ||
616 | |||
617 | *val = sd->brightness; | ||
618 | return 0; | ||
619 | } | ||
620 | |||
621 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) | ||
622 | { | 518 | { |
623 | struct sd *sd = (struct sd *) gspca_dev; | 519 | struct gspca_dev *gspca_dev = |
520 | container_of(ctrl->handler, struct gspca_dev, ctrl_handler); | ||
624 | 521 | ||
625 | sd->contrast = val; | 522 | gspca_dev->usb_err = 0; |
626 | if (gspca_dev->streaming) | ||
627 | setcontrast(gspca_dev); | ||
628 | return 0; | ||
629 | } | ||
630 | 523 | ||
631 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) | 524 | if (!gspca_dev->streaming) |
632 | { | 525 | return 0; |
633 | struct sd *sd = (struct sd *) gspca_dev; | ||
634 | 526 | ||
635 | *val = sd->contrast; | 527 | switch (ctrl->id) { |
636 | return 0; | 528 | case V4L2_CID_BRIGHTNESS: |
637 | } | 529 | setbrightness(gspca_dev, ctrl->val); |
638 | 530 | break; | |
639 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val) | 531 | case V4L2_CID_CONTRAST: |
640 | { | 532 | setcontrast(gspca_dev, ctrl->val); |
641 | struct sd *sd = (struct sd *) gspca_dev; | 533 | break; |
642 | 534 | case V4L2_CID_SATURATION: | |
643 | sd->colors = val; | 535 | setcolors(gspca_dev, ctrl->val); |
644 | if (gspca_dev->streaming) | 536 | break; |
645 | setcolors(gspca_dev); | 537 | case V4L2_CID_HUE: |
646 | return 0; | 538 | sethue(gspca_dev, ctrl->val); |
647 | } | 539 | break; |
648 | 540 | } | |
649 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) | 541 | return gspca_dev->usb_err; |
650 | { | ||
651 | struct sd *sd = (struct sd *) gspca_dev; | ||
652 | |||
653 | *val = sd->colors; | ||
654 | return 0; | ||
655 | } | 542 | } |
656 | 543 | ||
657 | static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val) | 544 | static const struct v4l2_ctrl_ops sd_ctrl_ops = { |
658 | { | 545 | .s_ctrl = sd_s_ctrl, |
659 | struct sd *sd = (struct sd *) gspca_dev; | 546 | }; |
660 | |||
661 | sd->hue = val; | ||
662 | if (gspca_dev->streaming) | ||
663 | sethue(gspca_dev); | ||
664 | return 0; | ||
665 | } | ||
666 | 547 | ||
667 | static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val) | 548 | static int sd_init_controls(struct gspca_dev *gspca_dev) |
668 | { | 549 | { |
669 | struct sd *sd = (struct sd *) gspca_dev; | 550 | struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; |
670 | 551 | ||
671 | *val = sd->hue; | 552 | gspca_dev->vdev.ctrl_handler = hdl; |
553 | v4l2_ctrl_handler_init(hdl, 4); | ||
554 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, | ||
555 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); | ||
556 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, | ||
557 | V4L2_CID_CONTRAST, 0, 255, 1, 0x47); | ||
558 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, | ||
559 | V4L2_CID_SATURATION, 0, 255, 1, 0x40); | ||
560 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, | ||
561 | V4L2_CID_HUE, 0, 255, 1, 0); | ||
562 | |||
563 | if (hdl->error) { | ||
564 | pr_err("Could not initialize controls\n"); | ||
565 | return hdl->error; | ||
566 | } | ||
672 | return 0; | 567 | return 0; |
673 | } | 568 | } |
674 | 569 | ||
675 | /* sub-driver description */ | 570 | /* sub-driver description */ |
676 | static const struct sd_desc sd_desc = { | 571 | static const struct sd_desc sd_desc = { |
677 | .name = MODULE_NAME, | 572 | .name = MODULE_NAME, |
678 | .ctrls = sd_ctrls, | ||
679 | .nctrls = ARRAY_SIZE(sd_ctrls), | ||
680 | .config = sd_config, | 573 | .config = sd_config, |
681 | .init = sd_init, | 574 | .init = sd_init, |
575 | .init_controls = sd_init_controls, | ||
682 | .start = sd_start, | 576 | .start = sd_start, |
683 | .stopN = sd_stopN, | 577 | .stopN = sd_stopN, |
684 | .pkt_scan = sd_pkt_scan, | 578 | .pkt_scan = sd_pkt_scan, |