aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/gspca/ov519.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/gspca/ov519.c')
-rw-r--r--drivers/media/video/gspca/ov519.c389
1 files changed, 106 insertions, 283 deletions
diff --git a/drivers/media/video/gspca/ov519.c b/drivers/media/video/gspca/ov519.c
index 2b2cbdbf03fe..6cf6855aa506 100644
--- a/drivers/media/video/gspca/ov519.c
+++ b/drivers/media/video/gspca/ov519.c
@@ -57,10 +57,24 @@ static int frame_rate;
57 * are getting "Failed to read sensor ID..." */ 57 * are getting "Failed to read sensor ID..." */
58static int i2c_detect_tries = 10; 58static int i2c_detect_tries = 10;
59 59
60/* controls */
61enum e_ctrl {
62 BRIGHTNESS,
63 CONTRAST,
64 COLORS,
65 HFLIP,
66 VFLIP,
67 AUTOBRIGHT,
68 FREQ,
69 NCTRL /* number of controls */
70};
71
60/* ov519 device descriptor */ 72/* ov519 device descriptor */
61struct sd { 73struct sd {
62 struct gspca_dev gspca_dev; /* !! must be the first item */ 74 struct gspca_dev gspca_dev; /* !! must be the first item */
63 75
76 struct gspca_ctrl ctrls[NCTRL];
77
64 __u8 packet_nr; 78 __u8 packet_nr;
65 79
66 char bridge; 80 char bridge;
@@ -82,13 +96,6 @@ struct sd {
82 /* Determined by sensor type */ 96 /* Determined by sensor type */
83 __u8 sif; 97 __u8 sif;
84 98
85 __u8 brightness;
86 __u8 contrast;
87 __u8 colors;
88 __u8 hflip;
89 __u8 vflip;
90 __u8 autobrightness;
91 __u8 freq;
92 __u8 quality; 99 __u8 quality;
93#define QUALITY_MIN 50 100#define QUALITY_MIN 50
94#define QUALITY_MAX 70 101#define QUALITY_MAX 70
@@ -130,29 +137,16 @@ struct sd {
130#include "w996Xcf.c" 137#include "w996Xcf.c"
131 138
132/* V4L2 controls supported by the driver */ 139/* V4L2 controls supported by the driver */
133static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
134static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
135static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
136static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
137static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
138static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
139static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
140static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
141static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
142static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
143static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val);
144static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val);
145static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
146static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
147static void setbrightness(struct gspca_dev *gspca_dev); 140static void setbrightness(struct gspca_dev *gspca_dev);
148static void setcontrast(struct gspca_dev *gspca_dev); 141static void setcontrast(struct gspca_dev *gspca_dev);
149static void setcolors(struct gspca_dev *gspca_dev); 142static void setcolors(struct gspca_dev *gspca_dev);
150static void setautobrightness(struct sd *sd); 143static void sethvflip(struct gspca_dev *gspca_dev);
151static void setfreq(struct sd *sd); 144static void setautobright(struct gspca_dev *gspca_dev);
145static void setfreq(struct gspca_dev *gspca_dev);
146static void setfreq_i(struct sd *sd);
152 147
153static const struct ctrl sd_ctrls[] = { 148static const struct ctrl sd_ctrls[] = {
154#define BRIGHTNESS_IDX 0 149[BRIGHTNESS] = {
155 {
156 { 150 {
157 .id = V4L2_CID_BRIGHTNESS, 151 .id = V4L2_CID_BRIGHTNESS,
158 .type = V4L2_CTRL_TYPE_INTEGER, 152 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -160,14 +154,11 @@ static const struct ctrl sd_ctrls[] = {
160 .minimum = 0, 154 .minimum = 0,
161 .maximum = 255, 155 .maximum = 255,
162 .step = 1, 156 .step = 1,
163#define BRIGHTNESS_DEF 127 157 .default_value = 127,
164 .default_value = BRIGHTNESS_DEF,
165 }, 158 },
166 .set = sd_setbrightness, 159 .set_control = setbrightness,
167 .get = sd_getbrightness,
168 }, 160 },
169#define CONTRAST_IDX 1 161[CONTRAST] = {
170 {
171 { 162 {
172 .id = V4L2_CID_CONTRAST, 163 .id = V4L2_CID_CONTRAST,
173 .type = V4L2_CTRL_TYPE_INTEGER, 164 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -175,14 +166,11 @@ static const struct ctrl sd_ctrls[] = {
175 .minimum = 0, 166 .minimum = 0,
176 .maximum = 255, 167 .maximum = 255,
177 .step = 1, 168 .step = 1,
178#define CONTRAST_DEF 127 169 .default_value = 127,
179 .default_value = CONTRAST_DEF,
180 }, 170 },
181 .set = sd_setcontrast, 171 .set_control = setcontrast,
182 .get = sd_getcontrast,
183 }, 172 },
184#define COLOR_IDX 2 173[COLORS] = {
185 {
186 { 174 {
187 .id = V4L2_CID_SATURATION, 175 .id = V4L2_CID_SATURATION,
188 .type = V4L2_CTRL_TYPE_INTEGER, 176 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -190,15 +178,12 @@ static const struct ctrl sd_ctrls[] = {
190 .minimum = 0, 178 .minimum = 0,
191 .maximum = 255, 179 .maximum = 255,
192 .step = 1, 180 .step = 1,
193#define COLOR_DEF 127 181 .default_value = 127,
194 .default_value = COLOR_DEF,
195 }, 182 },
196 .set = sd_setcolors, 183 .set_control = setcolors,
197 .get = sd_getcolors,
198 }, 184 },
199/* The flip controls work with ov7670 only */ 185/* The flip controls work with ov7670 only */
200#define HFLIP_IDX 3 186[HFLIP] = {
201 {
202 { 187 {
203 .id = V4L2_CID_HFLIP, 188 .id = V4L2_CID_HFLIP,
204 .type = V4L2_CTRL_TYPE_BOOLEAN, 189 .type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -206,14 +191,11 @@ static const struct ctrl sd_ctrls[] = {
206 .minimum = 0, 191 .minimum = 0,
207 .maximum = 1, 192 .maximum = 1,
208 .step = 1, 193 .step = 1,
209#define HFLIP_DEF 0 194 .default_value = 0,
210 .default_value = HFLIP_DEF,
211 }, 195 },
212 .set = sd_sethflip, 196 .set_control = sethvflip,
213 .get = sd_gethflip,
214 }, 197 },
215#define VFLIP_IDX 4 198[VFLIP] = {
216 {
217 { 199 {
218 .id = V4L2_CID_VFLIP, 200 .id = V4L2_CID_VFLIP,
219 .type = V4L2_CTRL_TYPE_BOOLEAN, 201 .type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -221,14 +203,11 @@ static const struct ctrl sd_ctrls[] = {
221 .minimum = 0, 203 .minimum = 0,
222 .maximum = 1, 204 .maximum = 1,
223 .step = 1, 205 .step = 1,
224#define VFLIP_DEF 0 206 .default_value = 0,
225 .default_value = VFLIP_DEF,
226 }, 207 },
227 .set = sd_setvflip, 208 .set_control = sethvflip,
228 .get = sd_getvflip,
229 }, 209 },
230#define AUTOBRIGHT_IDX 5 210[AUTOBRIGHT] = {
231 {
232 { 211 {
233 .id = V4L2_CID_AUTOBRIGHTNESS, 212 .id = V4L2_CID_AUTOBRIGHTNESS,
234 .type = V4L2_CTRL_TYPE_BOOLEAN, 213 .type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -236,14 +215,11 @@ static const struct ctrl sd_ctrls[] = {
236 .minimum = 0, 215 .minimum = 0,
237 .maximum = 1, 216 .maximum = 1,
238 .step = 1, 217 .step = 1,
239#define AUTOBRIGHT_DEF 1 218 .default_value = 1,
240 .default_value = AUTOBRIGHT_DEF,
241 }, 219 },
242 .set = sd_setautobrightness, 220 .set_control = setautobright,
243 .get = sd_getautobrightness,
244 }, 221 },
245#define FREQ_IDX 6 222[FREQ] = {
246 {
247 { 223 {
248 .id = V4L2_CID_POWER_LINE_FREQUENCY, 224 .id = V4L2_CID_POWER_LINE_FREQUENCY,
249 .type = V4L2_CTRL_TYPE_MENU, 225 .type = V4L2_CTRL_TYPE_MENU,
@@ -251,26 +227,9 @@ static const struct ctrl sd_ctrls[] = {
251 .minimum = 0, 227 .minimum = 0,
252 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ 228 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
253 .step = 1, 229 .step = 1,
254#define FREQ_DEF 0 230 .default_value = 0,
255 .default_value = FREQ_DEF,
256 },
257 .set = sd_setfreq,
258 .get = sd_getfreq,
259 },
260#define OV7670_FREQ_IDX 7
261 {
262 {
263 .id = V4L2_CID_POWER_LINE_FREQUENCY,
264 .type = V4L2_CTRL_TYPE_MENU,
265 .name = "Light frequency filter",
266 .minimum = 0,
267 .maximum = 3, /* 0: 0, 1: 50Hz, 2:60Hz 3: Auto Hz */
268 .step = 1,
269#define OV7670_FREQ_DEF 3
270 .default_value = OV7670_FREQ_DEF,
271 }, 231 },
272 .set = sd_setfreq, 232 .set_control = setfreq,
273 .get = sd_getfreq,
274 }, 233 },
275}; 234};
276 235
@@ -456,10 +415,10 @@ static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
456 415
457/* Registers common to OV511 / OV518 */ 416/* Registers common to OV511 / OV518 */
458#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */ 417#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
459#define R51x_SYS_RESET 0x50 418#define R51x_SYS_RESET 0x50
460 /* Reset type flags */ 419 /* Reset type flags */
461 #define OV511_RESET_OMNICE 0x08 420 #define OV511_RESET_OMNICE 0x08
462#define R51x_SYS_INIT 0x53 421#define R51x_SYS_INIT 0x53
463#define R51x_SYS_SNAP 0x52 422#define R51x_SYS_SNAP 0x52
464#define R51x_SYS_CUST_ID 0x5F 423#define R51x_SYS_CUST_ID 0x5F
465#define R51x_COMP_LUT_BEGIN 0x80 424#define R51x_COMP_LUT_BEGIN 0x80
@@ -644,13 +603,11 @@ struct ov_i2c_regvals {
644}; 603};
645 604
646/* Settings for OV2610 camera chip */ 605/* Settings for OV2610 camera chip */
647static const struct ov_i2c_regvals norm_2610[] = 606static const struct ov_i2c_regvals norm_2610[] = {
648{
649 { 0x12, 0x80 }, /* reset */ 607 { 0x12, 0x80 }, /* reset */
650}; 608};
651 609
652static const struct ov_i2c_regvals norm_3620b[] = 610static const struct ov_i2c_regvals norm_3620b[] = {
653{
654 /* 611 /*
655 * From the datasheet: "Note that after writing to register COMH 612 * From the datasheet: "Note that after writing to register COMH
656 * (0x12) to change the sensor mode, registers related to the 613 * (0x12) to change the sensor mode, registers related to the
@@ -1900,7 +1857,7 @@ static int reg_w(struct sd *sd, __u16 index, __u16 value)
1900 sd->gspca_dev.usb_buf, 1, 500); 1857 sd->gspca_dev.usb_buf, 1, 500);
1901leave: 1858leave:
1902 if (ret < 0) { 1859 if (ret < 0) {
1903 PDEBUG(D_ERR, "Write reg 0x%04x -> [0x%02x] failed", 1860 err("Write reg 0x%04x -> [0x%02x] failed",
1904 value, index); 1861 value, index);
1905 return ret; 1862 return ret;
1906 } 1863 }
@@ -1938,7 +1895,7 @@ static int reg_r(struct sd *sd, __u16 index)
1938 ret = sd->gspca_dev.usb_buf[0]; 1895 ret = sd->gspca_dev.usb_buf[0];
1939 PDEBUG(D_USBI, "Read reg [0x%02X] -> 0x%04X", index, ret); 1896 PDEBUG(D_USBI, "Read reg [0x%02X] -> 0x%04X", index, ret);
1940 } else 1897 } else
1941 PDEBUG(D_ERR, "Read reg [0x%02x] failed", index); 1898 err("Read reg [0x%02x] failed", index);
1942 1899
1943 return ret; 1900 return ret;
1944} 1901}
@@ -1958,7 +1915,7 @@ static int reg_r8(struct sd *sd,
1958 if (ret >= 0) 1915 if (ret >= 0)
1959 ret = sd->gspca_dev.usb_buf[0]; 1916 ret = sd->gspca_dev.usb_buf[0];
1960 else 1917 else
1961 PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index); 1918 err("Read reg 8 [0x%02x] failed", index);
1962 1919
1963 return ret; 1920 return ret;
1964} 1921}
@@ -2006,7 +1963,7 @@ static int ov518_reg_w32(struct sd *sd, __u16 index, u32 value, int n)
2006 0, index, 1963 0, index,
2007 sd->gspca_dev.usb_buf, n, 500); 1964 sd->gspca_dev.usb_buf, n, 500);
2008 if (ret < 0) { 1965 if (ret < 0) {
2009 PDEBUG(D_ERR, "Write reg32 [%02x] %08x failed", index, value); 1966 err("Write reg32 [%02x] %08x failed", index, value);
2010 return ret; 1967 return ret;
2011 } 1968 }
2012 1969
@@ -2203,7 +2160,7 @@ static int ovfx2_i2c_w(struct sd *sd, __u8 reg, __u8 value)
2203 (__u16)value, (__u16)reg, NULL, 0, 500); 2160 (__u16)value, (__u16)reg, NULL, 0, 500);
2204 2161
2205 if (ret < 0) { 2162 if (ret < 0) {
2206 PDEBUG(D_ERR, "i2c 0x%02x -> [0x%02x] failed", value, reg); 2163 err("i2c 0x%02x -> [0x%02x] failed", value, reg);
2207 return ret; 2164 return ret;
2208 } 2165 }
2209 2166
@@ -2225,7 +2182,7 @@ static int ovfx2_i2c_r(struct sd *sd, __u8 reg)
2225 ret = sd->gspca_dev.usb_buf[0]; 2182 ret = sd->gspca_dev.usb_buf[0];
2226 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, ret); 2183 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, ret);
2227 } else 2184 } else
2228 PDEBUG(D_ERR, "i2c read [0x%02x] failed", reg); 2185 err("i2c read [0x%02x] failed", reg);
2229 2186
2230 return ret; 2187 return ret;
2231} 2188}
@@ -2481,7 +2438,7 @@ static int ov_hires_configure(struct sd *sd)
2481 int high, low; 2438 int high, low;
2482 2439
2483 if (sd->bridge != BRIDGE_OVFX2) { 2440 if (sd->bridge != BRIDGE_OVFX2) {
2484 PDEBUG(D_ERR, "error hires sensors only supported with ovfx2"); 2441 err("error hires sensors only supported with ovfx2");
2485 return -1; 2442 return -1;
2486 } 2443 }
2487 2444
@@ -2498,7 +2455,7 @@ static int ov_hires_configure(struct sd *sd)
2498 PDEBUG(D_PROBE, "Sensor is an OV3610"); 2455 PDEBUG(D_PROBE, "Sensor is an OV3610");
2499 sd->sensor = SEN_OV3610; 2456 sd->sensor = SEN_OV3610;
2500 } else { 2457 } else {
2501 PDEBUG(D_ERR, "Error unknown sensor type: 0x%02x%02x", 2458 err("Error unknown sensor type: 0x%02x%02x",
2502 high, low); 2459 high, low);
2503 return -1; 2460 return -1;
2504 } 2461 }
@@ -2526,7 +2483,7 @@ static int ov8xx0_configure(struct sd *sd)
2526 if ((rc & 3) == 1) { 2483 if ((rc & 3) == 1) {
2527 sd->sensor = SEN_OV8610; 2484 sd->sensor = SEN_OV8610;
2528 } else { 2485 } else {
2529 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3); 2486 err("Unknown image sensor version: %d", rc & 3);
2530 return -1; 2487 return -1;
2531 } 2488 }
2532 2489
@@ -2589,9 +2546,8 @@ static int ov7xx0_configure(struct sd *sd)
2589 if (high == 0x76) { 2546 if (high == 0x76) {
2590 switch (low) { 2547 switch (low) {
2591 case 0x30: 2548 case 0x30:
2592 PDEBUG(D_PROBE, "Sensor is an OV7630/OV7635"); 2549 err("Sensor is an OV7630/OV7635");
2593 PDEBUG(D_ERR, 2550 err("7630 is not supported by this driver");
2594 "7630 is not supported by this driver");
2595 return -1; 2551 return -1;
2596 case 0x40: 2552 case 0x40:
2597 PDEBUG(D_PROBE, "Sensor is an OV7645"); 2553 PDEBUG(D_PROBE, "Sensor is an OV7645");
@@ -2614,7 +2570,7 @@ static int ov7xx0_configure(struct sd *sd)
2614 sd->sensor = SEN_OV7620; 2570 sd->sensor = SEN_OV7620;
2615 } 2571 }
2616 } else { 2572 } else {
2617 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3); 2573 err("Unknown image sensor version: %d", rc & 3);
2618 return -1; 2574 return -1;
2619 } 2575 }
2620 2576
@@ -2641,9 +2597,8 @@ static int ov6xx0_configure(struct sd *sd)
2641 switch (rc) { 2597 switch (rc) {
2642 case 0x00: 2598 case 0x00:
2643 sd->sensor = SEN_OV6630; 2599 sd->sensor = SEN_OV6630;
2644 PDEBUG(D_ERR, 2600 warn("WARNING: Sensor is an OV66308. Your camera may have");
2645 "WARNING: Sensor is an OV66308. Your camera may have"); 2601 warn("been misdetected in previous driver versions.");
2646 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
2647 break; 2602 break;
2648 case 0x01: 2603 case 0x01:
2649 sd->sensor = SEN_OV6620; 2604 sd->sensor = SEN_OV6620;
@@ -2659,12 +2614,11 @@ static int ov6xx0_configure(struct sd *sd)
2659 break; 2614 break;
2660 case 0x90: 2615 case 0x90:
2661 sd->sensor = SEN_OV6630; 2616 sd->sensor = SEN_OV6630;
2662 PDEBUG(D_ERR, 2617 warn("WARNING: Sensor is an OV66307. Your camera may have");
2663 "WARNING: Sensor is an OV66307. Your camera may have"); 2618 warn("been misdetected in previous driver versions.");
2664 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
2665 break; 2619 break;
2666 default: 2620 default:
2667 PDEBUG(D_ERR, "FATAL: Unknown sensor version: 0x%02x", rc); 2621 err("FATAL: Unknown sensor version: 0x%02x", rc);
2668 return -1; 2622 return -1;
2669 } 2623 }
2670 2624
@@ -2823,7 +2777,7 @@ static int ov511_configure(struct gspca_dev *gspca_dev)
2823 }; 2777 };
2824 2778
2825 const struct ov_regvals norm_511[] = { 2779 const struct ov_regvals norm_511[] = {
2826 { R511_DRAM_FLOW_CTL, 0x01 }, 2780 { R511_DRAM_FLOW_CTL, 0x01 },
2827 { R51x_SYS_SNAP, 0x00 }, 2781 { R51x_SYS_SNAP, 0x00 },
2828 { R51x_SYS_SNAP, 0x02 }, 2782 { R51x_SYS_SNAP, 0x02 },
2829 { R51x_SYS_SNAP, 0x00 }, 2783 { R51x_SYS_SNAP, 0x00 },
@@ -2907,7 +2861,7 @@ static int ov518_configure(struct gspca_dev *gspca_dev)
2907 const struct ov_regvals norm_518[] = { 2861 const struct ov_regvals norm_518[] = {
2908 { R51x_SYS_SNAP, 0x02 }, /* Reset */ 2862 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2909 { R51x_SYS_SNAP, 0x01 }, /* Enable */ 2863 { R51x_SYS_SNAP, 0x01 }, /* Enable */
2910 { 0x31, 0x0f }, 2864 { 0x31, 0x0f },
2911 { 0x5d, 0x03 }, 2865 { 0x5d, 0x03 },
2912 { 0x24, 0x9f }, 2866 { 0x24, 0x9f },
2913 { 0x25, 0x90 }, 2867 { 0x25, 0x90 },
@@ -2920,7 +2874,7 @@ static int ov518_configure(struct gspca_dev *gspca_dev)
2920 const struct ov_regvals norm_518_p[] = { 2874 const struct ov_regvals norm_518_p[] = {
2921 { R51x_SYS_SNAP, 0x02 }, /* Reset */ 2875 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2922 { R51x_SYS_SNAP, 0x01 }, /* Enable */ 2876 { R51x_SYS_SNAP, 0x01 }, /* Enable */
2923 { 0x31, 0x0f }, 2877 { 0x31, 0x0f },
2924 { 0x5d, 0x03 }, 2878 { 0x5d, 0x03 },
2925 { 0x24, 0x9f }, 2879 { 0x24, 0x9f },
2926 { 0x25, 0x90 }, 2880 { 0x25, 0x90 },
@@ -3082,7 +3036,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
3082 goto error; 3036 goto error;
3083 } 3037 }
3084 } else { 3038 } else {
3085 PDEBUG(D_ERR, "Can't determine sensor slave IDs"); 3039 err("Can't determine sensor slave IDs");
3086 goto error; 3040 goto error;
3087 } 3041 }
3088 3042
@@ -3142,36 +3096,23 @@ static int sd_config(struct gspca_dev *gspca_dev,
3142 goto error; 3096 goto error;
3143 break; 3097 break;
3144 } 3098 }
3145 sd->brightness = BRIGHTNESS_DEF; 3099 gspca_dev->cam.ctrls = sd->ctrls;
3146 if (sd->sensor == SEN_OV6630 || sd->sensor == SEN_OV66308AF) 3100 if (sd->sensor == SEN_OV7670)
3147 sd->contrast = 200; /* The default is too low for the ov6630 */ 3101 gspca_dev->ctrl_dis = 1 << COLORS;
3148 else 3102 else
3149 sd->contrast = CONTRAST_DEF; 3103 gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP);
3150 sd->colors = COLOR_DEF;
3151 sd->hflip = HFLIP_DEF;
3152 sd->vflip = VFLIP_DEF;
3153 sd->autobrightness = AUTOBRIGHT_DEF;
3154 if (sd->sensor == SEN_OV7670) {
3155 sd->freq = OV7670_FREQ_DEF;
3156 gspca_dev->ctrl_dis = (1 << FREQ_IDX) | (1 << COLOR_IDX);
3157 } else {
3158 sd->freq = FREQ_DEF;
3159 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) |
3160 (1 << OV7670_FREQ_IDX);
3161 }
3162 sd->quality = QUALITY_DEF; 3104 sd->quality = QUALITY_DEF;
3163 if (sd->sensor == SEN_OV7640 || 3105 if (sd->sensor == SEN_OV7640 ||
3164 sd->sensor == SEN_OV7648) 3106 sd->sensor == SEN_OV7648)
3165 gspca_dev->ctrl_dis |= (1 << AUTOBRIGHT_IDX) | 3107 gspca_dev->ctrl_dis |= (1 << AUTOBRIGHT) | (1 << CONTRAST);
3166 (1 << CONTRAST_IDX);
3167 if (sd->sensor == SEN_OV7670) 3108 if (sd->sensor == SEN_OV7670)
3168 gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT_IDX; 3109 gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT;
3169 /* OV8610 Frequency filter control should work but needs testing */ 3110 /* OV8610 Frequency filter control should work but needs testing */
3170 if (sd->sensor == SEN_OV8610) 3111 if (sd->sensor == SEN_OV8610)
3171 gspca_dev->ctrl_dis |= 1 << FREQ_IDX; 3112 gspca_dev->ctrl_dis |= 1 << FREQ;
3172 /* No controls for the OV2610/OV3610 */ 3113 /* No controls for the OV2610/OV3610 */
3173 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610) 3114 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
3174 gspca_dev->ctrl_dis |= 0xFF; 3115 gspca_dev->ctrl_dis |= (1 << NCTRL) - 1;
3175 3116
3176 return 0; 3117 return 0;
3177error: 3118error:
@@ -3206,6 +3147,8 @@ static int sd_init(struct gspca_dev *gspca_dev)
3206 break; 3147 break;
3207 case SEN_OV6630: 3148 case SEN_OV6630:
3208 case SEN_OV66308AF: 3149 case SEN_OV66308AF:
3150 sd->ctrls[CONTRAST].def = 200;
3151 /* The default is too low for the ov6630 */
3209 if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30))) 3152 if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30)))
3210 return -EIO; 3153 return -EIO;
3211 break; 3154 break;
@@ -3228,6 +3171,8 @@ static int sd_init(struct gspca_dev *gspca_dev)
3228 return -EIO; 3171 return -EIO;
3229 break; 3172 break;
3230 case SEN_OV7670: 3173 case SEN_OV7670:
3174 sd->ctrls[FREQ].max = 3; /* auto */
3175 sd->ctrls[FREQ].def = 3;
3231 if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670))) 3176 if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670)))
3232 return -EIO; 3177 return -EIO;
3233 break; 3178 break;
@@ -3253,7 +3198,7 @@ static int ov511_mode_init_regs(struct sd *sd)
3253 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface); 3198 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3254 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); 3199 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3255 if (!alt) { 3200 if (!alt) {
3256 PDEBUG(D_ERR, "Couldn't get altsetting"); 3201 err("Couldn't get altsetting");
3257 return -EIO; 3202 return -EIO;
3258 } 3203 }
3259 3204
@@ -3377,7 +3322,7 @@ static int ov518_mode_init_regs(struct sd *sd)
3377 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface); 3322 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3378 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); 3323 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3379 if (!alt) { 3324 if (!alt) {
3380 PDEBUG(D_ERR, "Couldn't get altsetting"); 3325 err("Couldn't get altsetting");
3381 return -EIO; 3326 return -EIO;
3382 } 3327 }
3383 3328
@@ -3706,7 +3651,7 @@ static int mode_init_ov_sensor_regs(struct sd *sd)
3706 break; 3651 break;
3707 case SEN_OV7610: 3652 case SEN_OV7610:
3708 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); 3653 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3709 i2c_w(sd, 0x35, qvga?0x1e:0x9e); 3654 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
3710 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */ 3655 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3711 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */ 3656 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3712 break; 3657 break;
@@ -3798,15 +3743,17 @@ static int mode_init_ov_sensor_regs(struct sd *sd)
3798 return 0; 3743 return 0;
3799} 3744}
3800 3745
3801static void sethvflip(struct sd *sd) 3746static void sethvflip(struct gspca_dev *gspca_dev)
3802{ 3747{
3748 struct sd *sd = (struct sd *) gspca_dev;
3749
3803 if (sd->sensor != SEN_OV7670) 3750 if (sd->sensor != SEN_OV7670)
3804 return; 3751 return;
3805 if (sd->gspca_dev.streaming) 3752 if (sd->gspca_dev.streaming)
3806 ov51x_stop(sd); 3753 ov51x_stop(sd);
3807 i2c_w_mask(sd, OV7670_REG_MVFP, 3754 i2c_w_mask(sd, OV7670_REG_MVFP,
3808 OV7670_MVFP_MIRROR * sd->hflip 3755 OV7670_MVFP_MIRROR * sd->ctrls[HFLIP].val
3809 | OV7670_MVFP_VFLIP * sd->vflip, 3756 | OV7670_MVFP_VFLIP * sd->ctrls[VFLIP].val,
3810 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP); 3757 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
3811 if (sd->gspca_dev.streaming) 3758 if (sd->gspca_dev.streaming)
3812 ov51x_restart(sd); 3759 ov51x_restart(sd);
@@ -3957,9 +3904,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
3957 setcontrast(gspca_dev); 3904 setcontrast(gspca_dev);
3958 setbrightness(gspca_dev); 3905 setbrightness(gspca_dev);
3959 setcolors(gspca_dev); 3906 setcolors(gspca_dev);
3960 sethvflip(sd); 3907 sethvflip(gspca_dev);
3961 setautobrightness(sd); 3908 setautobright(gspca_dev);
3962 setfreq(sd); 3909 setfreq_i(sd);
3963 3910
3964 /* Force clear snapshot state in case the snapshot button was 3911 /* Force clear snapshot state in case the snapshot button was
3965 pressed while we weren't streaming */ 3912 pressed while we weren't streaming */
@@ -4000,7 +3947,7 @@ static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state)
4000 struct sd *sd = (struct sd *) gspca_dev; 3947 struct sd *sd = (struct sd *) gspca_dev;
4001 3948
4002 if (sd->snapshot_pressed != state) { 3949 if (sd->snapshot_pressed != state) {
4003#ifdef CONFIG_INPUT 3950#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
4004 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state); 3951 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
4005 input_sync(gspca_dev->input_dev); 3952 input_sync(gspca_dev->input_dev);
4006#endif 3953#endif
@@ -4214,7 +4161,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
4214 struct sd *sd = (struct sd *) gspca_dev; 4161 struct sd *sd = (struct sd *) gspca_dev;
4215 int val; 4162 int val;
4216 4163
4217 val = sd->brightness; 4164 val = sd->ctrls[BRIGHTNESS].val;
4218 switch (sd->sensor) { 4165 switch (sd->sensor) {
4219 case SEN_OV8610: 4166 case SEN_OV8610:
4220 case SEN_OV7610: 4167 case SEN_OV7610:
@@ -4229,7 +4176,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
4229 case SEN_OV7620: 4176 case SEN_OV7620:
4230 case SEN_OV7620AE: 4177 case SEN_OV7620AE:
4231 /* 7620 doesn't like manual changes when in auto mode */ 4178 /* 7620 doesn't like manual changes when in auto mode */
4232 if (!sd->autobrightness) 4179 if (!sd->ctrls[AUTOBRIGHT].val)
4233 i2c_w(sd, OV7610_REG_BRT, val); 4180 i2c_w(sd, OV7610_REG_BRT, val);
4234 break; 4181 break;
4235 case SEN_OV7670: 4182 case SEN_OV7670:
@@ -4245,7 +4192,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
4245 struct sd *sd = (struct sd *) gspca_dev; 4192 struct sd *sd = (struct sd *) gspca_dev;
4246 int val; 4193 int val;
4247 4194
4248 val = sd->contrast; 4195 val = sd->ctrls[CONTRAST].val;
4249 switch (sd->sensor) { 4196 switch (sd->sensor) {
4250 case SEN_OV7610: 4197 case SEN_OV7610:
4251 case SEN_OV6620: 4198 case SEN_OV6620:
@@ -4287,7 +4234,7 @@ static void setcolors(struct gspca_dev *gspca_dev)
4287 struct sd *sd = (struct sd *) gspca_dev; 4234 struct sd *sd = (struct sd *) gspca_dev;
4288 int val; 4235 int val;
4289 4236
4290 val = sd->colors; 4237 val = sd->ctrls[COLORS].val;
4291 switch (sd->sensor) { 4238 switch (sd->sensor) {
4292 case SEN_OV8610: 4239 case SEN_OV8610:
4293 case SEN_OV7610: 4240 case SEN_OV7610:
@@ -4317,23 +4264,25 @@ static void setcolors(struct gspca_dev *gspca_dev)
4317 } 4264 }
4318} 4265}
4319 4266
4320static void setautobrightness(struct sd *sd) 4267static void setautobright(struct gspca_dev *gspca_dev)
4321{ 4268{
4269 struct sd *sd = (struct sd *) gspca_dev;
4270
4322 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7648 || 4271 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7648 ||
4323 sd->sensor == SEN_OV7670 || 4272 sd->sensor == SEN_OV7670 ||
4324 sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610) 4273 sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
4325 return; 4274 return;
4326 4275
4327 i2c_w_mask(sd, 0x2d, sd->autobrightness ? 0x10 : 0x00, 0x10); 4276 i2c_w_mask(sd, 0x2d, sd->ctrls[AUTOBRIGHT].val ? 0x10 : 0x00, 0x10);
4328} 4277}
4329 4278
4330static void setfreq(struct sd *sd) 4279static void setfreq_i(struct sd *sd)
4331{ 4280{
4332 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610) 4281 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
4333 return; 4282 return;
4334 4283
4335 if (sd->sensor == SEN_OV7670) { 4284 if (sd->sensor == SEN_OV7670) {
4336 switch (sd->freq) { 4285 switch (sd->ctrls[FREQ].val) {
4337 case 0: /* Banding filter disabled */ 4286 case 0: /* Banding filter disabled */
4338 i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_BFILT); 4287 i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_BFILT);
4339 break; 4288 break;
@@ -4355,7 +4304,7 @@ static void setfreq(struct sd *sd)
4355 break; 4304 break;
4356 } 4305 }
4357 } else { 4306 } else {
4358 switch (sd->freq) { 4307 switch (sd->ctrls[FREQ].val) {
4359 case 0: /* Banding filter disabled */ 4308 case 0: /* Banding filter disabled */
4360 i2c_w_mask(sd, 0x2d, 0x00, 0x04); 4309 i2c_w_mask(sd, 0x2d, 0x00, 0x04);
4361 i2c_w_mask(sd, 0x2a, 0x00, 0x80); 4310 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
@@ -4387,135 +4336,15 @@ static void setfreq(struct sd *sd)
4387 } 4336 }
4388 } 4337 }
4389} 4338}
4390 4339static void setfreq(struct gspca_dev *gspca_dev)
4391static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
4392{
4393 struct sd *sd = (struct sd *) gspca_dev;
4394
4395 sd->brightness = val;
4396 if (gspca_dev->streaming)
4397 setbrightness(gspca_dev);
4398 return 0;
4399}
4400
4401static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
4402{
4403 struct sd *sd = (struct sd *) gspca_dev;
4404
4405 *val = sd->brightness;
4406 return 0;
4407}
4408
4409static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
4410{
4411 struct sd *sd = (struct sd *) gspca_dev;
4412
4413 sd->contrast = val;
4414 if (gspca_dev->streaming)
4415 setcontrast(gspca_dev);
4416 return 0;
4417}
4418
4419static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
4420{
4421 struct sd *sd = (struct sd *) gspca_dev;
4422
4423 *val = sd->contrast;
4424 return 0;
4425}
4426
4427static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
4428{
4429 struct sd *sd = (struct sd *) gspca_dev;
4430
4431 sd->colors = val;
4432 if (gspca_dev->streaming)
4433 setcolors(gspca_dev);
4434 return 0;
4435}
4436
4437static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
4438{
4439 struct sd *sd = (struct sd *) gspca_dev;
4440
4441 *val = sd->colors;
4442 return 0;
4443}
4444
4445static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
4446{
4447 struct sd *sd = (struct sd *) gspca_dev;
4448
4449 sd->hflip = val;
4450 if (gspca_dev->streaming)
4451 sethvflip(sd);
4452 return 0;
4453}
4454
4455static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
4456{
4457 struct sd *sd = (struct sd *) gspca_dev;
4458
4459 *val = sd->hflip;
4460 return 0;
4461}
4462
4463static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
4464{
4465 struct sd *sd = (struct sd *) gspca_dev;
4466
4467 sd->vflip = val;
4468 if (gspca_dev->streaming)
4469 sethvflip(sd);
4470 return 0;
4471}
4472
4473static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
4474{
4475 struct sd *sd = (struct sd *) gspca_dev;
4476
4477 *val = sd->vflip;
4478 return 0;
4479}
4480
4481static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val)
4482{
4483 struct sd *sd = (struct sd *) gspca_dev;
4484
4485 sd->autobrightness = val;
4486 if (gspca_dev->streaming)
4487 setautobrightness(sd);
4488 return 0;
4489}
4490
4491static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val)
4492{
4493 struct sd *sd = (struct sd *) gspca_dev;
4494
4495 *val = sd->autobrightness;
4496 return 0;
4497}
4498
4499static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
4500{ 4340{
4501 struct sd *sd = (struct sd *) gspca_dev; 4341 struct sd *sd = (struct sd *) gspca_dev;
4502 4342
4503 sd->freq = val; 4343 setfreq_i(sd);
4504 if (gspca_dev->streaming) {
4505 setfreq(sd);
4506 /* Ugly but necessary */
4507 if (sd->bridge == BRIDGE_W9968CF)
4508 w9968cf_set_crop_window(sd);
4509 }
4510 return 0;
4511}
4512
4513static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
4514{
4515 struct sd *sd = (struct sd *) gspca_dev;
4516 4344
4517 *val = sd->freq; 4345 /* Ugly but necessary */
4518 return 0; 4346 if (sd->bridge == BRIDGE_W9968CF)
4347 w9968cf_set_crop_window(sd);
4519} 4348}
4520 4349
4521static int sd_querymenu(struct gspca_dev *gspca_dev, 4350static int sd_querymenu(struct gspca_dev *gspca_dev,
@@ -4601,7 +4430,7 @@ static const struct sd_desc sd_desc = {
4601 .querymenu = sd_querymenu, 4430 .querymenu = sd_querymenu,
4602 .get_jcomp = sd_get_jcomp, 4431 .get_jcomp = sd_get_jcomp,
4603 .set_jcomp = sd_set_jcomp, 4432 .set_jcomp = sd_set_jcomp,
4604#ifdef CONFIG_INPUT 4433#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
4605 .other_input = 1, 4434 .other_input = 1,
4606#endif 4435#endif
4607}; 4436};
@@ -4663,17 +4492,11 @@ static struct usb_driver sd_driver = {
4663/* -- module insert / remove -- */ 4492/* -- module insert / remove -- */
4664static int __init sd_mod_init(void) 4493static int __init sd_mod_init(void)
4665{ 4494{
4666 int ret; 4495 return usb_register(&sd_driver);
4667 ret = usb_register(&sd_driver);
4668 if (ret < 0)
4669 return ret;
4670 PDEBUG(D_PROBE, "registered");
4671 return 0;
4672} 4496}
4673static void __exit sd_mod_exit(void) 4497static void __exit sd_mod_exit(void)
4674{ 4498{
4675 usb_deregister(&sd_driver); 4499 usb_deregister(&sd_driver);
4676 PDEBUG(D_PROBE, "deregistered");
4677} 4500}
4678 4501
4679module_init(sd_mod_init); 4502module_init(sd_mod_init);