aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-05-16 07:49:10 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-07-30 17:32:20 -0400
commited5cd6bbde5569538f328ce931943cdce4a6db86 (patch)
tree7e4f7c52dd750dd4036bce1e4521b8e2486f3382
parent74dec797143ea2624f829758ef2fb92f7c470a2d (diff)
[media] sunplus: 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>
-rw-r--r--drivers/media/video/gspca/sunplus.c237
1 files changed, 71 insertions, 166 deletions
diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c
index c80f0c0c75b6..530652dcbfb2 100644
--- a/drivers/media/video/gspca/sunplus.c
+++ b/drivers/media/video/gspca/sunplus.c
@@ -34,15 +34,13 @@ MODULE_LICENSE("GPL");
34struct sd { 34struct sd {
35 struct gspca_dev gspca_dev; /* !! must be the first item */ 35 struct gspca_dev gspca_dev; /* !! must be the first item */
36 36
37 s8 brightness; 37 struct v4l2_ctrl *jpegqual;
38 u8 contrast;
39 u8 colors;
40 u8 autogain;
41 u8 quality;
42#define QUALITY_MIN 70 38#define QUALITY_MIN 70
43#define QUALITY_MAX 95 39#define QUALITY_MAX 95
44#define QUALITY_DEF 85 40#define QUALITY_DEF 85
45 41
42 bool autogain;
43
46 u8 bridge; 44 u8 bridge;
47#define BRIDGE_SPCA504 0 45#define BRIDGE_SPCA504 0
48#define BRIDGE_SPCA504B 1 46#define BRIDGE_SPCA504B 1
@@ -59,75 +57,6 @@ struct sd {
59 u8 jpeg_hdr[JPEG_HDR_SZ]; 57 u8 jpeg_hdr[JPEG_HDR_SZ];
60}; 58};
61 59
62/* V4L2 controls supported by the driver */
63static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
64static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
65static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
66static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
67static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
68static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
69static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
70static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
71
72static const struct ctrl sd_ctrls[] = {
73 {
74 {
75 .id = V4L2_CID_BRIGHTNESS,
76 .type = V4L2_CTRL_TYPE_INTEGER,
77 .name = "Brightness",
78 .minimum = -128,
79 .maximum = 127,
80 .step = 1,
81#define BRIGHTNESS_DEF 0
82 .default_value = BRIGHTNESS_DEF,
83 },
84 .set = sd_setbrightness,
85 .get = sd_getbrightness,
86 },
87 {
88 {
89 .id = V4L2_CID_CONTRAST,
90 .type = V4L2_CTRL_TYPE_INTEGER,
91 .name = "Contrast",
92 .minimum = 0,
93 .maximum = 0xff,
94 .step = 1,
95#define CONTRAST_DEF 0x20
96 .default_value = CONTRAST_DEF,
97 },
98 .set = sd_setcontrast,
99 .get = sd_getcontrast,
100 },
101 {
102 {
103 .id = V4L2_CID_SATURATION,
104 .type = V4L2_CTRL_TYPE_INTEGER,
105 .name = "Color",
106 .minimum = 0,
107 .maximum = 0xff,
108 .step = 1,
109#define COLOR_DEF 0x1a
110 .default_value = COLOR_DEF,
111 },
112 .set = sd_setcolors,
113 .get = sd_getcolors,
114 },
115 {
116 {
117 .id = V4L2_CID_AUTOGAIN,
118 .type = V4L2_CTRL_TYPE_BOOLEAN,
119 .name = "Auto Gain",
120 .minimum = 0,
121 .maximum = 1,
122 .step = 1,
123#define AUTOGAIN_DEF 1
124 .default_value = AUTOGAIN_DEF,
125 },
126 .set = sd_setautogain,
127 .get = sd_getautogain,
128 },
129};
130
131static const struct v4l2_pix_format vga_mode[] = { 60static const struct v4l2_pix_format vga_mode[] = {
132 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 61 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
133 .bytesperline = 320, 62 .bytesperline = 320,
@@ -597,31 +526,31 @@ static void spca504B_setQtable(struct gspca_dev *gspca_dev)
597 spca504B_PollingDataReady(gspca_dev); 526 spca504B_PollingDataReady(gspca_dev);
598} 527}
599 528
600static void setbrightness(struct gspca_dev *gspca_dev) 529static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
601{ 530{
602 struct sd *sd = (struct sd *) gspca_dev; 531 struct sd *sd = (struct sd *) gspca_dev;
603 u16 reg; 532 u16 reg;
604 533
605 reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f0 : 0x21a7; 534 reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f0 : 0x21a7;
606 reg_w_riv(gspca_dev, 0x00, reg, sd->brightness); 535 reg_w_riv(gspca_dev, 0x00, reg, val);
607} 536}
608 537
609static void setcontrast(struct gspca_dev *gspca_dev) 538static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
610{ 539{
611 struct sd *sd = (struct sd *) gspca_dev; 540 struct sd *sd = (struct sd *) gspca_dev;
612 u16 reg; 541 u16 reg;
613 542
614 reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f1 : 0x21a8; 543 reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f1 : 0x21a8;
615 reg_w_riv(gspca_dev, 0x00, reg, sd->contrast); 544 reg_w_riv(gspca_dev, 0x00, reg, val);
616} 545}
617 546
618static void setcolors(struct gspca_dev *gspca_dev) 547static void setcolors(struct gspca_dev *gspca_dev, s32 val)
619{ 548{
620 struct sd *sd = (struct sd *) gspca_dev; 549 struct sd *sd = (struct sd *) gspca_dev;
621 u16 reg; 550 u16 reg;
622 551
623 reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f6 : 0x21ae; 552 reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f6 : 0x21ae;
624 reg_w_riv(gspca_dev, 0x00, reg, sd->colors); 553 reg_w_riv(gspca_dev, 0x00, reg, val);
625} 554}
626 555
627static void init_ctl_reg(struct gspca_dev *gspca_dev) 556static void init_ctl_reg(struct gspca_dev *gspca_dev)
@@ -629,9 +558,7 @@ static void init_ctl_reg(struct gspca_dev *gspca_dev)
629 struct sd *sd = (struct sd *) gspca_dev; 558 struct sd *sd = (struct sd *) gspca_dev;
630 int pollreg = 1; 559 int pollreg = 1;
631 560
632 setbrightness(gspca_dev); 561 v4l2_ctrl_handler_setup(&gspca_dev->ctrl_handler);
633 setcontrast(gspca_dev);
634 setcolors(gspca_dev);
635 562
636 switch (sd->bridge) { 563 switch (sd->bridge) {
637 case BRIDGE_SPCA504: 564 case BRIDGE_SPCA504:
@@ -704,11 +631,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
704 cam->nmodes = ARRAY_SIZE(vga_mode2); 631 cam->nmodes = ARRAY_SIZE(vga_mode2);
705 break; 632 break;
706 } 633 }
707 sd->brightness = BRIGHTNESS_DEF;
708 sd->contrast = CONTRAST_DEF;
709 sd->colors = COLOR_DEF;
710 sd->autogain = AUTOGAIN_DEF;
711 sd->quality = QUALITY_DEF;
712 return 0; 634 return 0;
713} 635}
714 636
@@ -807,7 +729,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
807 /* create the JPEG header */ 729 /* create the JPEG header */
808 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 730 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
809 0x22); /* JPEG 411 */ 731 0x22); /* JPEG 411 */
810 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 732 jpeg_set_qual(sd->jpeg_hdr, v4l2_ctrl_g_ctrl(sd->jpegqual));
811 733
812 if (sd->bridge == BRIDGE_SPCA504B) 734 if (sd->bridge == BRIDGE_SPCA504B)
813 spca504B_setQtable(gspca_dev); 735 spca504B_setQtable(gspca_dev);
@@ -1012,111 +934,94 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1012 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 934 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1013} 935}
1014 936
1015static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 937static int sd_set_jcomp(struct gspca_dev *gspca_dev,
1016{ 938 struct v4l2_jpegcompression *jcomp)
1017 struct sd *sd = (struct sd *) gspca_dev;
1018
1019 sd->brightness = val;
1020 if (gspca_dev->streaming)
1021 setbrightness(gspca_dev);
1022 return gspca_dev->usb_err;
1023}
1024
1025static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1026{
1027 struct sd *sd = (struct sd *) gspca_dev;
1028
1029 *val = sd->brightness;
1030 return 0;
1031}
1032
1033static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1034{
1035 struct sd *sd = (struct sd *) gspca_dev;
1036
1037 sd->contrast = val;
1038 if (gspca_dev->streaming)
1039 setcontrast(gspca_dev);
1040 return gspca_dev->usb_err;
1041}
1042
1043static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1044{
1045 struct sd *sd = (struct sd *) gspca_dev;
1046
1047 *val = sd->contrast;
1048 return 0;
1049}
1050
1051static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
1052{
1053 struct sd *sd = (struct sd *) gspca_dev;
1054
1055 sd->colors = val;
1056 if (gspca_dev->streaming)
1057 setcolors(gspca_dev);
1058 return gspca_dev->usb_err;
1059}
1060
1061static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
1062{ 939{
1063 struct sd *sd = (struct sd *) gspca_dev; 940 struct sd *sd = (struct sd *) gspca_dev;
1064 941
1065 *val = sd->colors; 942 v4l2_ctrl_s_ctrl(sd->jpegqual, jcomp->quality);
1066 return 0; 943 return 0;
1067} 944}
1068 945
1069static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) 946static int sd_get_jcomp(struct gspca_dev *gspca_dev,
947 struct v4l2_jpegcompression *jcomp)
1070{ 948{
1071 struct sd *sd = (struct sd *) gspca_dev; 949 struct sd *sd = (struct sd *) gspca_dev;
1072 950
1073 sd->autogain = val; 951 memset(jcomp, 0, sizeof *jcomp);
952 jcomp->quality = v4l2_ctrl_g_ctrl(sd->jpegqual);
953 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
954 | V4L2_JPEG_MARKER_DQT;
1074 return 0; 955 return 0;
1075} 956}
1076 957
1077static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) 958static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
1078{ 959{
1079 struct sd *sd = (struct sd *) gspca_dev; 960 struct gspca_dev *gspca_dev =
961 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
962 struct sd *sd = (struct sd *)gspca_dev;
1080 963
1081 *val = sd->autogain; 964 gspca_dev->usb_err = 0;
1082 return 0;
1083}
1084 965
1085static int sd_set_jcomp(struct gspca_dev *gspca_dev, 966 if (!gspca_dev->streaming)
1086 struct v4l2_jpegcompression *jcomp) 967 return 0;
1087{
1088 struct sd *sd = (struct sd *) gspca_dev;
1089 968
1090 if (jcomp->quality < QUALITY_MIN) 969 switch (ctrl->id) {
1091 sd->quality = QUALITY_MIN; 970 case V4L2_CID_BRIGHTNESS:
1092 else if (jcomp->quality > QUALITY_MAX) 971 setbrightness(gspca_dev, ctrl->val);
1093 sd->quality = QUALITY_MAX; 972 break;
1094 else 973 case V4L2_CID_CONTRAST:
1095 sd->quality = jcomp->quality; 974 setcontrast(gspca_dev, ctrl->val);
1096 if (gspca_dev->streaming) 975 break;
1097 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 976 case V4L2_CID_SATURATION:
977 setcolors(gspca_dev, ctrl->val);
978 break;
979 case V4L2_CID_AUTOGAIN:
980 sd->autogain = ctrl->val;
981 break;
982 case V4L2_CID_JPEG_COMPRESSION_QUALITY:
983 jpeg_set_qual(sd->jpeg_hdr, ctrl->val);
984 break;
985 }
1098 return gspca_dev->usb_err; 986 return gspca_dev->usb_err;
1099} 987}
1100 988
1101static int sd_get_jcomp(struct gspca_dev *gspca_dev, 989static const struct v4l2_ctrl_ops sd_ctrl_ops = {
1102 struct v4l2_jpegcompression *jcomp) 990 .s_ctrl = sd_s_ctrl,
1103{ 991};
1104 struct sd *sd = (struct sd *) gspca_dev;
1105 992
1106 memset(jcomp, 0, sizeof *jcomp); 993static int sd_init_controls(struct gspca_dev *gspca_dev)
1107 jcomp->quality = sd->quality; 994{
1108 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT 995 struct sd *sd = (struct sd *)gspca_dev;
1109 | V4L2_JPEG_MARKER_DQT; 996 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
997
998 gspca_dev->vdev.ctrl_handler = hdl;
999 v4l2_ctrl_handler_init(hdl, 5);
1000 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1001 V4L2_CID_BRIGHTNESS, -128, 127, 1, 0);
1002 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1003 V4L2_CID_CONTRAST, 0, 255, 1, 0x20);
1004 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1005 V4L2_CID_SATURATION, 0, 255, 1, 0x1a);
1006 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1007 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
1008 sd->jpegqual = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1009 V4L2_CID_JPEG_COMPRESSION_QUALITY,
1010 QUALITY_MIN, QUALITY_MAX, 1, QUALITY_DEF);
1011
1012 if (hdl->error) {
1013 pr_err("Could not initialize controls\n");
1014 return hdl->error;
1015 }
1110 return 0; 1016 return 0;
1111} 1017}
1112 1018
1113/* sub-driver description */ 1019/* sub-driver description */
1114static const struct sd_desc sd_desc = { 1020static const struct sd_desc sd_desc = {
1115 .name = MODULE_NAME, 1021 .name = MODULE_NAME,
1116 .ctrls = sd_ctrls,
1117 .nctrls = ARRAY_SIZE(sd_ctrls),
1118 .config = sd_config, 1022 .config = sd_config,
1119 .init = sd_init, 1023 .init = sd_init,
1024 .init_controls = sd_init_controls,
1120 .start = sd_start, 1025 .start = sd_start,
1121 .stopN = sd_stopN, 1026 .stopN = sd_stopN,
1122 .pkt_scan = sd_pkt_scan, 1027 .pkt_scan = sd_pkt_scan,