diff options
author | Jean-François Moine <moinejf@free.fr> | 2010-12-28 05:09:34 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-12-29 05:17:20 -0500 |
commit | 49fb5e60f7e907126aac10af6577fac6fde684f6 (patch) | |
tree | d4bdbd2e90a17fc0ce99cf80bffa7468176ffef6 | |
parent | 7d55a84b0af47b2ec55e16c6dbc8df62a72ac749 (diff) |
[media] gspca - zc3xx: Use the new video control mechanism
Signed-off-by: Jean-François Moine <moinejf@free.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/gspca/zc3xx.c | 228 |
1 files changed, 52 insertions, 176 deletions
diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c index 6ab23844ce24..48b880283b63 100644 --- a/drivers/media/video/gspca/zc3xx.c +++ b/drivers/media/video/gspca/zc3xx.c | |||
@@ -35,16 +35,23 @@ static int force_sensor = -1; | |||
35 | #define QUANT_VAL 1 /* quantization table */ | 35 | #define QUANT_VAL 1 /* quantization table */ |
36 | #include "zc3xx-reg.h" | 36 | #include "zc3xx-reg.h" |
37 | 37 | ||
38 | /* controls */ | ||
39 | enum e_ctrl { | ||
40 | BRIGHTNESS, | ||
41 | CONTRAST, | ||
42 | GAMMA, | ||
43 | AUTOGAIN, | ||
44 | LIGHTFREQ, | ||
45 | SHARPNESS, | ||
46 | NCTRLS /* number of controls */ | ||
47 | }; | ||
48 | |||
38 | /* specific webcam descriptor */ | 49 | /* specific webcam descriptor */ |
39 | struct sd { | 50 | struct sd { |
40 | struct gspca_dev gspca_dev; /* !! must be the first item */ | 51 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
41 | 52 | ||
42 | u8 brightness; | 53 | struct gspca_ctrl ctrls[NCTRLS]; |
43 | u8 contrast; | 54 | |
44 | u8 gamma; | ||
45 | u8 autogain; | ||
46 | u8 lightfreq; | ||
47 | u8 sharpness; | ||
48 | u8 quality; /* image quality */ | 55 | u8 quality; /* image quality */ |
49 | #define QUALITY_MIN 50 | 56 | #define QUALITY_MIN 50 |
50 | #define QUALITY_MAX 80 | 57 | #define QUALITY_MAX 80 |
@@ -84,21 +91,13 @@ enum sensors { | |||
84 | }; | 91 | }; |
85 | 92 | ||
86 | /* V4L2 controls supported by the driver */ | 93 | /* V4L2 controls supported by the driver */ |
87 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); | 94 | static void setcontrast(struct gspca_dev *gspca_dev); |
88 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); | 95 | static void setautogain(struct gspca_dev *gspca_dev); |
89 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); | 96 | static void setlightfreq(struct gspca_dev *gspca_dev); |
90 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); | 97 | static void setsharpness(struct gspca_dev *gspca_dev); |
91 | static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); | 98 | |
92 | static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); | 99 | static const struct ctrl sd_ctrls[NCTRLS] = { |
93 | static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val); | 100 | [BRIGHTNESS] = { |
94 | static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val); | ||
95 | static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); | ||
96 | static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); | ||
97 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); | ||
98 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); | ||
99 | |||
100 | static const struct ctrl sd_ctrls[] = { | ||
101 | { | ||
102 | { | 101 | { |
103 | .id = V4L2_CID_BRIGHTNESS, | 102 | .id = V4L2_CID_BRIGHTNESS, |
104 | .type = V4L2_CTRL_TYPE_INTEGER, | 103 | .type = V4L2_CTRL_TYPE_INTEGER, |
@@ -106,13 +105,11 @@ static const struct ctrl sd_ctrls[] = { | |||
106 | .minimum = 0, | 105 | .minimum = 0, |
107 | .maximum = 255, | 106 | .maximum = 255, |
108 | .step = 1, | 107 | .step = 1, |
109 | #define BRIGHTNESS_DEF 128 | 108 | .default_value = 128, |
110 | .default_value = BRIGHTNESS_DEF, | ||
111 | }, | 109 | }, |
112 | .set = sd_setbrightness, | 110 | .set_control = setcontrast |
113 | .get = sd_getbrightness, | ||
114 | }, | 111 | }, |
115 | { | 112 | [CONTRAST] = { |
116 | { | 113 | { |
117 | .id = V4L2_CID_CONTRAST, | 114 | .id = V4L2_CID_CONTRAST, |
118 | .type = V4L2_CTRL_TYPE_INTEGER, | 115 | .type = V4L2_CTRL_TYPE_INTEGER, |
@@ -120,13 +117,11 @@ static const struct ctrl sd_ctrls[] = { | |||
120 | .minimum = 0, | 117 | .minimum = 0, |
121 | .maximum = 255, | 118 | .maximum = 255, |
122 | .step = 1, | 119 | .step = 1, |
123 | #define CONTRAST_DEF 128 | 120 | .default_value = 128, |
124 | .default_value = CONTRAST_DEF, | ||
125 | }, | 121 | }, |
126 | .set = sd_setcontrast, | 122 | .set_control = setcontrast |
127 | .get = sd_getcontrast, | ||
128 | }, | 123 | }, |
129 | { | 124 | [GAMMA] = { |
130 | { | 125 | { |
131 | .id = V4L2_CID_GAMMA, | 126 | .id = V4L2_CID_GAMMA, |
132 | .type = V4L2_CTRL_TYPE_INTEGER, | 127 | .type = V4L2_CTRL_TYPE_INTEGER, |
@@ -136,10 +131,9 @@ static const struct ctrl sd_ctrls[] = { | |||
136 | .step = 1, | 131 | .step = 1, |
137 | .default_value = 4, | 132 | .default_value = 4, |
138 | }, | 133 | }, |
139 | .set = sd_setgamma, | 134 | .set_control = setcontrast |
140 | .get = sd_getgamma, | ||
141 | }, | 135 | }, |
142 | { | 136 | [AUTOGAIN] = { |
143 | { | 137 | { |
144 | .id = V4L2_CID_AUTOGAIN, | 138 | .id = V4L2_CID_AUTOGAIN, |
145 | .type = V4L2_CTRL_TYPE_BOOLEAN, | 139 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
@@ -147,14 +141,11 @@ static const struct ctrl sd_ctrls[] = { | |||
147 | .minimum = 0, | 141 | .minimum = 0, |
148 | .maximum = 1, | 142 | .maximum = 1, |
149 | .step = 1, | 143 | .step = 1, |
150 | #define AUTOGAIN_DEF 1 | 144 | .default_value = 1, |
151 | .default_value = AUTOGAIN_DEF, | ||
152 | }, | 145 | }, |
153 | .set = sd_setautogain, | 146 | .set_control = setautogain |
154 | .get = sd_getautogain, | ||
155 | }, | 147 | }, |
156 | #define LIGHTFREQ_IDX 4 | 148 | [LIGHTFREQ] = { |
157 | { | ||
158 | { | 149 | { |
159 | .id = V4L2_CID_POWER_LINE_FREQUENCY, | 150 | .id = V4L2_CID_POWER_LINE_FREQUENCY, |
160 | .type = V4L2_CTRL_TYPE_MENU, | 151 | .type = V4L2_CTRL_TYPE_MENU, |
@@ -162,13 +153,11 @@ static const struct ctrl sd_ctrls[] = { | |||
162 | .minimum = 0, | 153 | .minimum = 0, |
163 | .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ | 154 | .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ |
164 | .step = 1, | 155 | .step = 1, |
165 | #define FREQ_DEF 0 | 156 | .default_value = 0, |
166 | .default_value = FREQ_DEF, | ||
167 | }, | 157 | }, |
168 | .set = sd_setfreq, | 158 | .set_control = setlightfreq |
169 | .get = sd_getfreq, | ||
170 | }, | 159 | }, |
171 | { | 160 | [SHARPNESS] = { |
172 | { | 161 | { |
173 | .id = V4L2_CID_SHARPNESS, | 162 | .id = V4L2_CID_SHARPNESS, |
174 | .type = V4L2_CTRL_TYPE_INTEGER, | 163 | .type = V4L2_CTRL_TYPE_INTEGER, |
@@ -176,11 +165,9 @@ static const struct ctrl sd_ctrls[] = { | |||
176 | .minimum = 0, | 165 | .minimum = 0, |
177 | .maximum = 3, | 166 | .maximum = 3, |
178 | .step = 1, | 167 | .step = 1, |
179 | #define SHARPNESS_DEF 2 | 168 | .default_value = 2, |
180 | .default_value = SHARPNESS_DEF, | ||
181 | }, | 169 | }, |
182 | .set = sd_setsharpness, | 170 | .set_control = setsharpness |
183 | .get = sd_getsharpness, | ||
184 | }, | 171 | }, |
185 | }; | 172 | }; |
186 | 173 | ||
@@ -5875,7 +5862,7 @@ static void setsharpness(struct gspca_dev *gspca_dev) | |||
5875 | {0x10, 0x1e} | 5862 | {0x10, 0x1e} |
5876 | }; | 5863 | }; |
5877 | 5864 | ||
5878 | sharpness = sd->sharpness; | 5865 | sharpness = sd->ctrls[SHARPNESS].val; |
5879 | reg_w(gspca_dev, sharpness_tb[sharpness][0], 0x01c6); | 5866 | reg_w(gspca_dev, sharpness_tb[sharpness][0], 0x01c6); |
5880 | reg_r(gspca_dev, 0x01c8); | 5867 | reg_r(gspca_dev, 0x01c8); |
5881 | reg_r(gspca_dev, 0x01c9); | 5868 | reg_r(gspca_dev, 0x01c9); |
@@ -5910,10 +5897,10 @@ static void setcontrast(struct gspca_dev *gspca_dev) | |||
5910 | 0xe0, 0xeb, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff}, | 5897 | 0xe0, 0xeb, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff}, |
5911 | }; | 5898 | }; |
5912 | 5899 | ||
5913 | Tgamma = gamma_tb[sd->gamma - 1]; | 5900 | Tgamma = gamma_tb[sd->ctrls[GAMMA].val - 1]; |
5914 | 5901 | ||
5915 | contrast = ((int) sd->contrast - 128); /* -128 / 127 */ | 5902 | contrast = ((int) sd->ctrls[CONTRAST].val - 128); /* -128 / 127 */ |
5916 | brightness = ((int) sd->brightness - 128); /* -128 / 92 */ | 5903 | brightness = ((int) sd->ctrls[BRIGHTNESS].val - 128); /* -128 / 92 */ |
5917 | adj = 0; | 5904 | adj = 0; |
5918 | gp1 = gp2 = 0; | 5905 | gp1 = gp2 = 0; |
5919 | for (i = 0; i < 16; i++) { | 5906 | for (i = 0; i < 16; i++) { |
@@ -6060,8 +6047,8 @@ static void setlightfreq(struct gspca_dev *gspca_dev) | |||
6060 | tas5130c_vf0250_60HZ, tas5130c_vf0250_60HZScale}, | 6047 | tas5130c_vf0250_60HZ, tas5130c_vf0250_60HZScale}, |
6061 | }; | 6048 | }; |
6062 | 6049 | ||
6063 | i = sd->lightfreq * 2; | 6050 | i = sd->ctrls[LIGHTFREQ].val * 2; |
6064 | mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; | 6051 | mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; |
6065 | if (mode) | 6052 | if (mode) |
6066 | i++; /* 320x240 */ | 6053 | i++; /* 320x240 */ |
6067 | zc3_freq = freq_tb[sd->sensor][i]; | 6054 | zc3_freq = freq_tb[sd->sensor][i]; |
@@ -6070,14 +6057,14 @@ static void setlightfreq(struct gspca_dev *gspca_dev) | |||
6070 | usb_exchange(gspca_dev, zc3_freq); | 6057 | usb_exchange(gspca_dev, zc3_freq); |
6071 | switch (sd->sensor) { | 6058 | switch (sd->sensor) { |
6072 | case SENSOR_GC0305: | 6059 | case SENSOR_GC0305: |
6073 | if (mode /* if 320x240 */ | 6060 | if (mode /* if 320x240 */ |
6074 | && sd->lightfreq == 1) /* and 50Hz */ | 6061 | && sd->ctrls[LIGHTFREQ].val == 1) /* and 50Hz */ |
6075 | reg_w(gspca_dev, 0x85, 0x018d); | 6062 | reg_w(gspca_dev, 0x85, 0x018d); |
6076 | /* win: 0x80, 0x018d */ | 6063 | /* win: 0x80, 0x018d */ |
6077 | break; | 6064 | break; |
6078 | case SENSOR_OV7620: | 6065 | case SENSOR_OV7620: |
6079 | if (!mode) { /* if 640x480 */ | 6066 | if (!mode) { /* if 640x480 */ |
6080 | if (sd->lightfreq != 0) /* and 50 or 60 Hz */ | 6067 | if (sd->ctrls[LIGHTFREQ].val != 0) /* and filter */ |
6081 | reg_w(gspca_dev, 0x40, 0x0002); | 6068 | reg_w(gspca_dev, 0x40, 0x0002); |
6082 | else | 6069 | else |
6083 | reg_w(gspca_dev, 0x44, 0x0002); | 6070 | reg_w(gspca_dev, 0x44, 0x0002); |
@@ -6094,7 +6081,7 @@ static void setautogain(struct gspca_dev *gspca_dev) | |||
6094 | struct sd *sd = (struct sd *) gspca_dev; | 6081 | struct sd *sd = (struct sd *) gspca_dev; |
6095 | u8 autoval; | 6082 | u8 autoval; |
6096 | 6083 | ||
6097 | if (sd->autogain) | 6084 | if (sd->ctrls[AUTOGAIN].val) |
6098 | autoval = 0x42; | 6085 | autoval = 0x42; |
6099 | else | 6086 | else |
6100 | autoval = 0x02; | 6087 | autoval = 0x02; |
@@ -6421,11 +6408,7 @@ static int sd_config(struct gspca_dev *gspca_dev, | |||
6421 | /* define some sensors from the vendor/product */ | 6408 | /* define some sensors from the vendor/product */ |
6422 | sd->sensor = id->driver_info; | 6409 | sd->sensor = id->driver_info; |
6423 | 6410 | ||
6424 | sd->sharpness = SHARPNESS_DEF; | 6411 | gspca_dev->cam.ctrls = sd->ctrls; |
6425 | sd->brightness = BRIGHTNESS_DEF; | ||
6426 | sd->contrast = CONTRAST_DEF; | ||
6427 | sd->autogain = AUTOGAIN_DEF; | ||
6428 | sd->lightfreq = FREQ_DEF; | ||
6429 | sd->quality = QUALITY_DEF; | 6412 | sd->quality = QUALITY_DEF; |
6430 | 6413 | ||
6431 | return 0; | 6414 | return 0; |
@@ -6588,7 +6571,7 @@ static int sd_init(struct gspca_dev *gspca_dev) | |||
6588 | case 0x2030: | 6571 | case 0x2030: |
6589 | PDEBUG(D_PROBE, "Find Sensor PO2030"); | 6572 | PDEBUG(D_PROBE, "Find Sensor PO2030"); |
6590 | sd->sensor = SENSOR_PO2030; | 6573 | sd->sensor = SENSOR_PO2030; |
6591 | sd->sharpness = 0; /* from win traces */ | 6574 | sd->ctrls[SHARPNESS].def = 0; /* from win traces */ |
6592 | break; | 6575 | break; |
6593 | case 0x7620: | 6576 | case 0x7620: |
6594 | PDEBUG(D_PROBE, "Find Sensor OV7620"); | 6577 | PDEBUG(D_PROBE, "Find Sensor OV7620"); |
@@ -6629,11 +6612,12 @@ static int sd_init(struct gspca_dev *gspca_dev) | |||
6629 | cam->nmodes = ARRAY_SIZE(broken_vga_mode); | 6612 | cam->nmodes = ARRAY_SIZE(broken_vga_mode); |
6630 | break; | 6613 | break; |
6631 | } | 6614 | } |
6632 | sd->gamma = gamma[sd->sensor]; | 6615 | |
6616 | sd->ctrls[GAMMA].def = gamma[sd->sensor]; | ||
6633 | 6617 | ||
6634 | switch (sd->sensor) { | 6618 | switch (sd->sensor) { |
6635 | case SENSOR_OV7630C: | 6619 | case SENSOR_OV7630C: |
6636 | gspca_dev->ctrl_dis = (1 << LIGHTFREQ_IDX); | 6620 | gspca_dev->ctrl_dis = (1 << LIGHTFREQ); |
6637 | break; | 6621 | break; |
6638 | } | 6622 | } |
6639 | 6623 | ||
@@ -6843,114 +6827,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, | |||
6843 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); | 6827 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
6844 | } | 6828 | } |
6845 | 6829 | ||
6846 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) | ||
6847 | { | ||
6848 | struct sd *sd = (struct sd *) gspca_dev; | ||
6849 | |||
6850 | sd->brightness = val; | ||
6851 | if (gspca_dev->streaming) | ||
6852 | setcontrast(gspca_dev); | ||
6853 | return gspca_dev->usb_err; | ||
6854 | } | ||
6855 | |||
6856 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) | ||
6857 | { | ||
6858 | struct sd *sd = (struct sd *) gspca_dev; | ||
6859 | |||
6860 | *val = sd->brightness; | ||
6861 | return 0; | ||
6862 | } | ||
6863 | |||
6864 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) | ||
6865 | { | ||
6866 | struct sd *sd = (struct sd *) gspca_dev; | ||
6867 | |||
6868 | sd->contrast = val; | ||
6869 | if (gspca_dev->streaming) | ||
6870 | setcontrast(gspca_dev); | ||
6871 | return gspca_dev->usb_err; | ||
6872 | } | ||
6873 | |||
6874 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) | ||
6875 | { | ||
6876 | struct sd *sd = (struct sd *) gspca_dev; | ||
6877 | |||
6878 | *val = sd->contrast; | ||
6879 | return 0; | ||
6880 | } | ||
6881 | |||
6882 | static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) | ||
6883 | { | ||
6884 | struct sd *sd = (struct sd *) gspca_dev; | ||
6885 | |||
6886 | sd->autogain = val; | ||
6887 | if (gspca_dev->streaming) | ||
6888 | setautogain(gspca_dev); | ||
6889 | return gspca_dev->usb_err; | ||
6890 | } | ||
6891 | |||
6892 | static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) | ||
6893 | { | ||
6894 | struct sd *sd = (struct sd *) gspca_dev; | ||
6895 | |||
6896 | *val = sd->autogain; | ||
6897 | return 0; | ||
6898 | } | ||
6899 | |||
6900 | static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val) | ||
6901 | { | ||
6902 | struct sd *sd = (struct sd *) gspca_dev; | ||
6903 | |||
6904 | sd->gamma = val; | ||
6905 | if (gspca_dev->streaming) | ||
6906 | setcontrast(gspca_dev); | ||
6907 | return gspca_dev->usb_err; | ||
6908 | } | ||
6909 | |||
6910 | static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val) | ||
6911 | { | ||
6912 | struct sd *sd = (struct sd *) gspca_dev; | ||
6913 | |||
6914 | *val = sd->gamma; | ||
6915 | return 0; | ||
6916 | } | ||
6917 | |||
6918 | static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val) | ||
6919 | { | ||
6920 | struct sd *sd = (struct sd *) gspca_dev; | ||
6921 | |||
6922 | sd->lightfreq = val; | ||
6923 | if (gspca_dev->streaming) | ||
6924 | setlightfreq(gspca_dev); | ||
6925 | return gspca_dev->usb_err; | ||
6926 | } | ||
6927 | |||
6928 | static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val) | ||
6929 | { | ||
6930 | struct sd *sd = (struct sd *) gspca_dev; | ||
6931 | |||
6932 | *val = sd->lightfreq; | ||
6933 | return 0; | ||
6934 | } | ||
6935 | |||
6936 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) | ||
6937 | { | ||
6938 | struct sd *sd = (struct sd *) gspca_dev; | ||
6939 | |||
6940 | sd->sharpness = val; | ||
6941 | if (gspca_dev->streaming) | ||
6942 | setsharpness(gspca_dev); | ||
6943 | return gspca_dev->usb_err; | ||
6944 | } | ||
6945 | |||
6946 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) | ||
6947 | { | ||
6948 | struct sd *sd = (struct sd *) gspca_dev; | ||
6949 | |||
6950 | *val = sd->sharpness; | ||
6951 | return 0; | ||
6952 | } | ||
6953 | |||
6954 | static int sd_querymenu(struct gspca_dev *gspca_dev, | 6830 | static int sd_querymenu(struct gspca_dev *gspca_dev, |
6955 | struct v4l2_querymenu *menu) | 6831 | struct v4l2_querymenu *menu) |
6956 | { | 6832 | { |