aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/gspca/m5602/m5602_ov9650.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/gspca/m5602/m5602_ov9650.c')
-rw-r--r--drivers/media/video/gspca/m5602/m5602_ov9650.c316
1 files changed, 176 insertions, 140 deletions
diff --git a/drivers/media/video/gspca/m5602/m5602_ov9650.c b/drivers/media/video/gspca/m5602/m5602_ov9650.c
index 837c7e47661c..c908a8d6970a 100644
--- a/drivers/media/video/gspca/m5602/m5602_ov9650.c
+++ b/drivers/media/video/gspca/m5602/m5602_ov9650.c
@@ -18,77 +18,57 @@
18 18
19#include "m5602_ov9650.h" 19#include "m5602_ov9650.h"
20 20
21int ov9650_read_sensor(struct sd *sd, const u8 address, 21/* Vertically and horizontally flips the image if matched, needed for machines
22 u8 *i2c_data, const u8 len) 22 where the sensor is mounted upside down */
23{ 23static
24 int err, i; 24 const
25 25 struct dmi_system_id ov9650_flip_dmi_table[] = {
26 /* The ov9650 registers have a max depth of one byte */ 26 {
27 if (len > 1 || !len) 27 .ident = "ASUS A6VC",
28 return -EINVAL; 28 .matches = {
29 29 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
30 do { 30 DMI_MATCH(DMI_PRODUCT_NAME, "A6VC")
31 err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data); 31 }
32 } while ((*i2c_data & I2C_BUSY) && !err); 32 },
33 33 {
34 m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR, 34 .ident = "ASUS A6VM",
35 ov9650.i2c_slave_id); 35 .matches = {
36 m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address); 36 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
37 m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x10 + len); 37 DMI_MATCH(DMI_PRODUCT_NAME, "A6VM")
38 m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x08); 38 }
39 39 },
40 for (i = 0; i < len; i++) { 40 {
41 err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i])); 41 .ident = "ASUS A6JC",
42 42 .matches = {
43 PDEBUG(D_CONF, "Reading sensor register " 43 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
44 "0x%x containing 0x%x ", address, *i2c_data); 44 DMI_MATCH(DMI_PRODUCT_NAME, "A6JC")
45 } 45 }
46 return (err < 0) ? err : 0; 46 },
47} 47 {
48 48 .ident = "ASUS A6Ja",
49int ov9650_write_sensor(struct sd *sd, const u8 address, 49 .matches = {
50 u8 *i2c_data, const u8 len) 50 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
51{ 51 DMI_MATCH(DMI_PRODUCT_NAME, "A6J")
52 int err, i; 52 }
53 u8 *p; 53 },
54 struct usb_device *udev = sd->gspca_dev.dev; 54 {
55 __u8 *buf = sd->gspca_dev.usb_buf; 55 .ident = "ASUS A6Kt",
56 56 .matches = {
57 /* The ov9650 only supports one byte writes */ 57 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
58 if (len > 1 || !len) 58 DMI_MATCH(DMI_PRODUCT_NAME, "A6Kt")
59 return -EINVAL; 59 }
60 60 },
61 memcpy(buf, sensor_urb_skeleton, 61 {
62 sizeof(sensor_urb_skeleton)); 62 .ident = "Alienware Aurora m9700",
63 63 .matches = {
64 buf[11] = sd->sensor->i2c_slave_id; 64 DMI_MATCH(DMI_SYS_VENDOR, "alienware"),
65 buf[15] = address; 65 DMI_MATCH(DMI_PRODUCT_NAME, "Aurora m9700")
66 66 }
67 /* Special case larger sensor writes */ 67 },
68 p = buf + 16; 68 { }
69 69};
70 /* Copy a four byte write sequence for each byte to be written to */
71 for (i = 0; i < len; i++) {
72 memcpy(p, sensor_urb_skeleton + 16, 4);
73 p[3] = i2c_data[i];
74 p += 4;
75 PDEBUG(D_CONF, "Writing sensor register 0x%x with 0x%x",
76 address, i2c_data[i]);
77 }
78
79 /* Copy the tailer */
80 memcpy(p, sensor_urb_skeleton + 20, 4);
81
82 /* Set the total length */
83 p[3] = 0x10 + len;
84
85 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
86 0x04, 0x40, 0x19,
87 0x0000, buf,
88 20 + len * 4, M5602_URB_MSG_TIMEOUT);
89 70
90 return (err < 0) ? err : 0; 71static void ov9650_dump_registers(struct sd *sd);
91}
92 72
93int ov9650_probe(struct sd *sd) 73int ov9650_probe(struct sd *sd)
94{ 74{
@@ -110,16 +90,16 @@ int ov9650_probe(struct sd *sd)
110 for (i = 0; i < ARRAY_SIZE(preinit_ov9650); i++) { 90 for (i = 0; i < ARRAY_SIZE(preinit_ov9650); i++) {
111 u8 data = preinit_ov9650[i][2]; 91 u8 data = preinit_ov9650[i][2];
112 if (preinit_ov9650[i][0] == SENSOR) 92 if (preinit_ov9650[i][0] == SENSOR)
113 ov9650_write_sensor(sd, 93 m5602_write_sensor(sd,
114 preinit_ov9650[i][1], &data, 1); 94 preinit_ov9650[i][1], &data, 1);
115 else 95 else
116 m5602_write_bridge(sd, preinit_ov9650[i][1], data); 96 m5602_write_bridge(sd, preinit_ov9650[i][1], data);
117 } 97 }
118 98
119 if (ov9650_read_sensor(sd, OV9650_PID, &prod_id, 1)) 99 if (m5602_read_sensor(sd, OV9650_PID, &prod_id, 1))
120 return -ENODEV; 100 return -ENODEV;
121 101
122 if (ov9650_read_sensor(sd, OV9650_VER, &ver_id, 1)) 102 if (m5602_read_sensor(sd, OV9650_VER, &ver_id, 1))
123 return -ENODEV; 103 return -ENODEV;
124 104
125 if ((prod_id == 0x96) && (ver_id == 0x52)) { 105 if ((prod_id == 0x96) && (ver_id == 0x52)) {
@@ -148,34 +128,90 @@ int ov9650_init(struct sd *sd)
148 for (i = 0; i < ARRAY_SIZE(init_ov9650) && !err; i++) { 128 for (i = 0; i < ARRAY_SIZE(init_ov9650) && !err; i++) {
149 data = init_ov9650[i][2]; 129 data = init_ov9650[i][2];
150 if (init_ov9650[i][0] == SENSOR) 130 if (init_ov9650[i][0] == SENSOR)
151 err = ov9650_write_sensor(sd, init_ov9650[i][1], 131 err = m5602_write_sensor(sd, init_ov9650[i][1],
152 &data, 1); 132 &data, 1);
153 else 133 else
154 err = m5602_write_bridge(sd, init_ov9650[i][1], data); 134 err = m5602_write_bridge(sd, init_ov9650[i][1], data);
155 } 135 }
156 136
157 if (!err && dmi_check_system(ov9650_flip_dmi_table)) { 137 if (dmi_check_system(ov9650_flip_dmi_table) && !err) {
158 info("vflip quirk active"); 138 info("vflip quirk active");
159 data = 0x30; 139 data = 0x30;
160 err = ov9650_write_sensor(sd, OV9650_MVFP, &data, 1); 140 err = m5602_write_sensor(sd, OV9650_MVFP, &data, 1);
161 } 141 }
142 return err;
143}
144
145int ov9650_start(struct sd *sd)
146{
147 int i, err = 0;
148 struct cam *cam = &sd->gspca_dev.cam;
162 149
163 return (err < 0) ? err : 0; 150 for (i = 0; i < ARRAY_SIZE(res_init_ov9650) && !err; i++) {
151 u8 data = res_init_ov9650[i][1];
152 err = m5602_write_bridge(sd, res_init_ov9650[i][0], data);
153 }
154 if (err < 0)
155 return err;
156
157 switch (cam->cam_mode[sd->gspca_dev.curr_mode].width)
158 {
159 case 640:
160 PDEBUG(D_V4L2, "Configuring camera for VGA mode");
161
162 for (i = 0; i < ARRAY_SIZE(VGA_ov9650) && !err; i++) {
163 u8 data = VGA_ov9650[i][2];
164 if (VGA_ov9650[i][0] == SENSOR)
165 err = m5602_write_sensor(sd,
166 VGA_ov9650[i][1], &data, 1);
167 else
168 err = m5602_write_bridge(sd, VGA_ov9650[i][1], data);
169 }
170 break;
171
172 case 352:
173 PDEBUG(D_V4L2, "Configuring camera for CIF mode");
174
175 for (i = 0; i < ARRAY_SIZE(CIF_ov9650) && !err; i++) {
176 u8 data = CIF_ov9650[i][2];
177 if (CIF_ov9650[i][0] == SENSOR)
178 err = m5602_write_sensor(sd,
179 CIF_ov9650[i][1], &data, 1);
180 else
181 err = m5602_write_bridge(sd, CIF_ov9650[i][1], data);
182 }
183 break;
184
185 case 320:
186 PDEBUG(D_V4L2, "Configuring camera for QVGA mode");
187
188 for (i = 0; i < ARRAY_SIZE(QVGA_ov9650) && !err; i++) {
189 u8 data = QVGA_ov9650[i][2];
190 if (QVGA_ov9650[i][0] == SENSOR)
191 err = m5602_write_sensor(sd,
192 QVGA_ov9650[i][1], &data, 1);
193 else
194 err = m5602_write_bridge(sd, QVGA_ov9650[i][1], data);
195 }
196 break;
197 }
198 return err;
164} 199}
165 200
166int ov9650_power_down(struct sd *sd) 201int ov9650_power_down(struct sd *sd)
167{ 202{
168 int i; 203 int i, err = 0;
169 for (i = 0; i < ARRAY_SIZE(power_down_ov9650); i++) { 204 for (i = 0; i < ARRAY_SIZE(power_down_ov9650) && !err; i++) {
170 u8 data = power_down_ov9650[i][2]; 205 u8 data = power_down_ov9650[i][2];
171 if (power_down_ov9650[i][0] == SENSOR) 206 if (power_down_ov9650[i][0] == SENSOR)
172 ov9650_write_sensor(sd, 207 err = m5602_write_sensor(sd,
173 power_down_ov9650[i][1], &data, 1); 208 power_down_ov9650[i][1], &data, 1);
174 else 209 else
175 m5602_write_bridge(sd, power_down_ov9650[i][1], data); 210 err = m5602_write_bridge(sd, power_down_ov9650[i][1],
211 data);
176 } 212 }
177 213
178 return 0; 214 return err;
179} 215}
180 216
181int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val) 217int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
@@ -184,24 +220,24 @@ int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
184 u8 i2c_data; 220 u8 i2c_data;
185 int err; 221 int err;
186 222
187 err = ov9650_read_sensor(sd, OV9650_COM1, &i2c_data, 1); 223 err = m5602_read_sensor(sd, OV9650_COM1, &i2c_data, 1);
188 if (err < 0) 224 if (err < 0)
189 goto out; 225 goto out;
190 *val = i2c_data & 0x03; 226 *val = i2c_data & 0x03;
191 227
192 err = ov9650_read_sensor(sd, OV9650_AECH, &i2c_data, 1); 228 err = m5602_read_sensor(sd, OV9650_AECH, &i2c_data, 1);
193 if (err < 0) 229 if (err < 0)
194 goto out; 230 goto out;
195 *val |= (i2c_data << 2); 231 *val |= (i2c_data << 2);
196 232
197 err = ov9650_read_sensor(sd, OV9650_AECHM, &i2c_data, 1); 233 err = m5602_read_sensor(sd, OV9650_AECHM, &i2c_data, 1);
198 if (err < 0) 234 if (err < 0)
199 goto out; 235 goto out;
200 *val |= (i2c_data & 0x3f) << 10; 236 *val |= (i2c_data & 0x3f) << 10;
201 237
202 PDEBUG(D_V4L2, "Read exposure %d", *val); 238 PDEBUG(D_V4L2, "Read exposure %d", *val);
203out: 239out:
204 return (err < 0) ? err : 0; 240 return err;
205} 241}
206 242
207int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val) 243int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
@@ -215,24 +251,24 @@ int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
215 251
216 /* The 6 MSBs */ 252 /* The 6 MSBs */
217 i2c_data = (val >> 10) & 0x3f; 253 i2c_data = (val >> 10) & 0x3f;
218 err = ov9650_write_sensor(sd, OV9650_AECHM, 254 err = m5602_write_sensor(sd, OV9650_AECHM,
219 &i2c_data, 1); 255 &i2c_data, 1);
220 if (err < 0) 256 if (err < 0)
221 goto out; 257 goto out;
222 258
223 /* The 8 middle bits */ 259 /* The 8 middle bits */
224 i2c_data = (val >> 2) & 0xff; 260 i2c_data = (val >> 2) & 0xff;
225 err = ov9650_write_sensor(sd, OV9650_AECH, 261 err = m5602_write_sensor(sd, OV9650_AECH,
226 &i2c_data, 1); 262 &i2c_data, 1);
227 if (err < 0) 263 if (err < 0)
228 goto out; 264 goto out;
229 265
230 /* The 2 LSBs */ 266 /* The 2 LSBs */
231 i2c_data = val & 0x03; 267 i2c_data = val & 0x03;
232 err = ov9650_write_sensor(sd, OV9650_COM1, &i2c_data, 1); 268 err = m5602_write_sensor(sd, OV9650_COM1, &i2c_data, 1);
233 269
234out: 270out:
235 return (err < 0) ? err : 0; 271 return err;
236} 272}
237 273
238int ov9650_get_gain(struct gspca_dev *gspca_dev, __s32 *val) 274int ov9650_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
@@ -241,13 +277,13 @@ int ov9650_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
241 u8 i2c_data; 277 u8 i2c_data;
242 struct sd *sd = (struct sd *) gspca_dev; 278 struct sd *sd = (struct sd *) gspca_dev;
243 279
244 ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1); 280 m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
245 *val = (i2c_data & 0x03) << 8; 281 *val = (i2c_data & 0x03) << 8;
246 282
247 err = ov9650_read_sensor(sd, OV9650_GAIN, &i2c_data, 1); 283 err = m5602_read_sensor(sd, OV9650_GAIN, &i2c_data, 1);
248 *val |= i2c_data; 284 *val |= i2c_data;
249 PDEBUG(D_V4L2, "Read gain %d", *val); 285 PDEBUG(D_V4L2, "Read gain %d", *val);
250 return (err < 0) ? err : 0; 286 return err;
251} 287}
252 288
253int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val) 289int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val)
@@ -259,16 +295,16 @@ int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val)
259 /* The 2 MSB */ 295 /* The 2 MSB */
260 /* Read the OV9650_VREF register first to avoid 296 /* Read the OV9650_VREF register first to avoid
261 corrupting the VREF high and low bits */ 297 corrupting the VREF high and low bits */
262 ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1); 298 m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
263 /* Mask away all uninteresting bits */ 299 /* Mask away all uninteresting bits */
264 i2c_data = ((val & 0x0300) >> 2) | 300 i2c_data = ((val & 0x0300) >> 2) |
265 (i2c_data & 0x3F); 301 (i2c_data & 0x3F);
266 err = ov9650_write_sensor(sd, OV9650_VREF, &i2c_data, 1); 302 err = m5602_write_sensor(sd, OV9650_VREF, &i2c_data, 1);
267 303
268 /* The 8 LSBs */ 304 /* The 8 LSBs */
269 i2c_data = val & 0xff; 305 i2c_data = val & 0xff;
270 err = ov9650_write_sensor(sd, OV9650_GAIN, &i2c_data, 1); 306 err = m5602_write_sensor(sd, OV9650_GAIN, &i2c_data, 1);
271 return (err < 0) ? err : 0; 307 return err;
272} 308}
273 309
274int ov9650_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val) 310int ov9650_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val)
@@ -277,12 +313,12 @@ int ov9650_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val)
277 u8 i2c_data; 313 u8 i2c_data;
278 struct sd *sd = (struct sd *) gspca_dev; 314 struct sd *sd = (struct sd *) gspca_dev;
279 315
280 err = ov9650_read_sensor(sd, OV9650_RED, &i2c_data, 1); 316 err = m5602_read_sensor(sd, OV9650_RED, &i2c_data, 1);
281 *val = i2c_data; 317 *val = i2c_data;
282 318
283 PDEBUG(D_V4L2, "Read red gain %d", *val); 319 PDEBUG(D_V4L2, "Read red gain %d", *val);
284 320
285 return (err < 0) ? err : 0; 321 return err;
286} 322}
287 323
288int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val) 324int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
@@ -295,9 +331,9 @@ int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
295 val & 0xff); 331 val & 0xff);
296 332
297 i2c_data = val & 0xff; 333 i2c_data = val & 0xff;
298 err = ov9650_write_sensor(sd, OV9650_RED, &i2c_data, 1); 334 err = m5602_write_sensor(sd, OV9650_RED, &i2c_data, 1);
299 335
300 return (err < 0) ? err : 0; 336 return err;
301} 337}
302 338
303int ov9650_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val) 339int ov9650_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val)
@@ -306,12 +342,12 @@ int ov9650_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val)
306 u8 i2c_data; 342 u8 i2c_data;
307 struct sd *sd = (struct sd *) gspca_dev; 343 struct sd *sd = (struct sd *) gspca_dev;
308 344
309 err = ov9650_read_sensor(sd, OV9650_BLUE, &i2c_data, 1); 345 err = m5602_read_sensor(sd, OV9650_BLUE, &i2c_data, 1);
310 *val = i2c_data; 346 *val = i2c_data;
311 347
312 PDEBUG(D_V4L2, "Read blue gain %d", *val); 348 PDEBUG(D_V4L2, "Read blue gain %d", *val);
313 349
314 return (err < 0) ? err : 0; 350 return err;
315} 351}
316 352
317int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val) 353int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
@@ -324,9 +360,9 @@ int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
324 val & 0xff); 360 val & 0xff);
325 361
326 i2c_data = val & 0xff; 362 i2c_data = val & 0xff;
327 err = ov9650_write_sensor(sd, OV9650_BLUE, &i2c_data, 1); 363 err = m5602_write_sensor(sd, OV9650_BLUE, &i2c_data, 1);
328 364
329 return (err < 0) ? err : 0; 365 return err;
330} 366}
331 367
332int ov9650_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) 368int ov9650_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
@@ -335,14 +371,14 @@ int ov9650_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
335 u8 i2c_data; 371 u8 i2c_data;
336 struct sd *sd = (struct sd *) gspca_dev; 372 struct sd *sd = (struct sd *) gspca_dev;
337 373
338 err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1); 374 err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
339 if (dmi_check_system(ov9650_flip_dmi_table)) 375 if (dmi_check_system(ov9650_flip_dmi_table))
340 *val = ((i2c_data & OV9650_HFLIP) >> 5) ? 0 : 1; 376 *val = ((i2c_data & OV9650_HFLIP) >> 5) ? 0 : 1;
341 else 377 else
342 *val = (i2c_data & OV9650_HFLIP) >> 5; 378 *val = (i2c_data & OV9650_HFLIP) >> 5;
343 PDEBUG(D_V4L2, "Read horizontal flip %d", *val); 379 PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
344 380
345 return (err < 0) ? err : 0; 381 return err;
346} 382}
347 383
348int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val) 384int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
@@ -352,20 +388,20 @@ int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
352 struct sd *sd = (struct sd *) gspca_dev; 388 struct sd *sd = (struct sd *) gspca_dev;
353 389
354 PDEBUG(D_V4L2, "Set horizontal flip to %d", val); 390 PDEBUG(D_V4L2, "Set horizontal flip to %d", val);
355 err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1); 391 err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
356 if (err < 0) 392 if (err < 0)
357 goto out; 393 goto out;
358 394
359 if (dmi_check_system(ov9650_flip_dmi_table)) 395 if (dmi_check_system(ov9650_flip_dmi_table))
360 i2c_data = ((i2c_data & 0xdf) | 396 i2c_data = ((i2c_data & 0xdf) |
361 (((val ? 0 : 1) & 0x01) << 5)); 397 (((val ? 0 : 1) & 0x01) << 5));
362 else 398 else
363 i2c_data = ((i2c_data & 0xdf) | 399 i2c_data = ((i2c_data & 0xdf) |
364 ((val & 0x01) << 5)); 400 ((val & 0x01) << 5));
365 401
366 err = ov9650_write_sensor(sd, OV9650_MVFP, &i2c_data, 1); 402 err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
367out: 403out:
368 return (err < 0) ? err : 0; 404 return err;
369} 405}
370 406
371int ov9650_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) 407int ov9650_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
@@ -374,14 +410,14 @@ int ov9650_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
374 u8 i2c_data; 410 u8 i2c_data;
375 struct sd *sd = (struct sd *) gspca_dev; 411 struct sd *sd = (struct sd *) gspca_dev;
376 412
377 err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1); 413 err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
378 if (dmi_check_system(ov9650_flip_dmi_table)) 414 if (dmi_check_system(ov9650_flip_dmi_table))
379 *val = ((i2c_data & 0x10) >> 4) ? 0 : 1; 415 *val = ((i2c_data & 0x10) >> 4) ? 0 : 1;
380 else 416 else
381 *val = (i2c_data & 0x10) >> 4; 417 *val = (i2c_data & 0x10) >> 4;
382 PDEBUG(D_V4L2, "Read vertical flip %d", *val); 418 PDEBUG(D_V4L2, "Read vertical flip %d", *val);
383 419
384 return (err < 0) ? err : 0; 420 return err;
385} 421}
386 422
387int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val) 423int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
@@ -391,7 +427,7 @@ int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
391 struct sd *sd = (struct sd *) gspca_dev; 427 struct sd *sd = (struct sd *) gspca_dev;
392 428
393 PDEBUG(D_V4L2, "Set vertical flip to %d", val); 429 PDEBUG(D_V4L2, "Set vertical flip to %d", val);
394 err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1); 430 err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
395 if (err < 0) 431 if (err < 0)
396 goto out; 432 goto out;
397 433
@@ -402,9 +438,9 @@ int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
402 i2c_data = ((i2c_data & 0xef) | 438 i2c_data = ((i2c_data & 0xef) |
403 ((val & 0x01) << 4)); 439 ((val & 0x01) << 4));
404 440
405 err = ov9650_write_sensor(sd, OV9650_MVFP, &i2c_data, 1); 441 err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
406out: 442out:
407 return (err < 0) ? err : 0; 443 return err;
408} 444}
409 445
410int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val) 446int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
@@ -413,16 +449,16 @@ int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
413 u8 i2c_data; 449 u8 i2c_data;
414 struct sd *sd = (struct sd *) gspca_dev; 450 struct sd *sd = (struct sd *) gspca_dev;
415 451
416 err = ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1); 452 err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
417 if (err < 0) 453 if (err < 0)
418 goto out; 454 goto out;
419 *val = (i2c_data & 0x03) << 8; 455 *val = (i2c_data & 0x03) << 8;
420 456
421 err = ov9650_read_sensor(sd, OV9650_GAIN, &i2c_data, 1); 457 err = m5602_read_sensor(sd, OV9650_GAIN, &i2c_data, 1);
422 *val |= i2c_data; 458 *val |= i2c_data;
423 PDEBUG(D_V4L2, "Read gain %d", *val); 459 PDEBUG(D_V4L2, "Read gain %d", *val);
424out: 460out:
425 return (err < 0) ? err : 0; 461 return err;
426} 462}
427 463
428int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val) 464int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
@@ -435,22 +471,22 @@ int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
435 471
436 /* Read the OV9650_VREF register first to avoid 472 /* Read the OV9650_VREF register first to avoid
437 corrupting the VREF high and low bits */ 473 corrupting the VREF high and low bits */
438 err = ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1); 474 err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
439 if (err < 0) 475 if (err < 0)
440 goto out; 476 goto out;
441 477
442 /* Mask away all uninteresting bits */ 478 /* Mask away all uninteresting bits */
443 i2c_data = ((val & 0x0300) >> 2) | (i2c_data & 0x3F); 479 i2c_data = ((val & 0x0300) >> 2) | (i2c_data & 0x3F);
444 err = ov9650_write_sensor(sd, OV9650_VREF, &i2c_data, 1); 480 err = m5602_write_sensor(sd, OV9650_VREF, &i2c_data, 1);
445 if (err < 0) 481 if (err < 0)
446 goto out; 482 goto out;
447 483
448 /* The 8 LSBs */ 484 /* The 8 LSBs */
449 i2c_data = val & 0xff; 485 i2c_data = val & 0xff;
450 err = ov9650_write_sensor(sd, OV9650_GAIN, &i2c_data, 1); 486 err = m5602_write_sensor(sd, OV9650_GAIN, &i2c_data, 1);
451 487
452out: 488out:
453 return (err < 0) ? err : 0; 489 return err;
454} 490}
455 491
456int ov9650_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val) 492int ov9650_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val)
@@ -459,11 +495,11 @@ int ov9650_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val)
459 u8 i2c_data; 495 u8 i2c_data;
460 struct sd *sd = (struct sd *) gspca_dev; 496 struct sd *sd = (struct sd *) gspca_dev;
461 497
462 err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1); 498 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
463 *val = (i2c_data & OV9650_AWB_EN) >> 1; 499 *val = (i2c_data & OV9650_AWB_EN) >> 1;
464 PDEBUG(D_V4L2, "Read auto white balance %d", *val); 500 PDEBUG(D_V4L2, "Read auto white balance %d", *val);
465 501
466 return (err < 0) ? err : 0; 502 return err;
467} 503}
468 504
469int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val) 505int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val)
@@ -473,14 +509,14 @@ int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val)
473 struct sd *sd = (struct sd *) gspca_dev; 509 struct sd *sd = (struct sd *) gspca_dev;
474 510
475 PDEBUG(D_V4L2, "Set auto white balance to %d", val); 511 PDEBUG(D_V4L2, "Set auto white balance to %d", val);
476 err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1); 512 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
477 if (err < 0) 513 if (err < 0)
478 goto out; 514 goto out;
479 515
480 i2c_data = ((i2c_data & 0xfd) | ((val & 0x01) << 1)); 516 i2c_data = ((i2c_data & 0xfd) | ((val & 0x01) << 1));
481 err = ov9650_write_sensor(sd, OV9650_COM8, &i2c_data, 1); 517 err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
482out: 518out:
483 return (err < 0) ? err : 0; 519 return err;
484} 520}
485 521
486int ov9650_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val) 522int ov9650_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val)
@@ -489,11 +525,11 @@ int ov9650_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val)
489 u8 i2c_data; 525 u8 i2c_data;
490 struct sd *sd = (struct sd *) gspca_dev; 526 struct sd *sd = (struct sd *) gspca_dev;
491 527
492 err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1); 528 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
493 *val = (i2c_data & OV9650_AGC_EN) >> 2; 529 *val = (i2c_data & OV9650_AGC_EN) >> 2;
494 PDEBUG(D_V4L2, "Read auto gain control %d", *val); 530 PDEBUG(D_V4L2, "Read auto gain control %d", *val);
495 531
496 return (err < 0) ? err : 0; 532 return err;
497} 533}
498 534
499int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val) 535int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
@@ -503,23 +539,23 @@ int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
503 struct sd *sd = (struct sd *) gspca_dev; 539 struct sd *sd = (struct sd *) gspca_dev;
504 540
505 PDEBUG(D_V4L2, "Set auto gain control to %d", val); 541 PDEBUG(D_V4L2, "Set auto gain control to %d", val);
506 err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1); 542 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
507 if (err < 0) 543 if (err < 0)
508 goto out; 544 goto out;
509 545
510 i2c_data = ((i2c_data & 0xfb) | ((val & 0x01) << 2)); 546 i2c_data = ((i2c_data & 0xfb) | ((val & 0x01) << 2));
511 err = ov9650_write_sensor(sd, OV9650_COM8, &i2c_data, 1); 547 err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
512out: 548out:
513 return (err < 0) ? err : 0; 549 return err;
514} 550}
515 551
516void ov9650_dump_registers(struct sd *sd) 552static void ov9650_dump_registers(struct sd *sd)
517{ 553{
518 int address; 554 int address;
519 info("Dumping the ov9650 register state"); 555 info("Dumping the ov9650 register state");
520 for (address = 0; address < 0xa9; address++) { 556 for (address = 0; address < 0xa9; address++) {
521 u8 value; 557 u8 value;
522 ov9650_read_sensor(sd, address, &value, 1); 558 m5602_read_sensor(sd, address, &value, 1);
523 info("register 0x%x contains 0x%x", 559 info("register 0x%x contains 0x%x",
524 address, value); 560 address, value);
525 } 561 }
@@ -531,9 +567,9 @@ void ov9650_dump_registers(struct sd *sd)
531 u8 old_value, ctrl_value; 567 u8 old_value, ctrl_value;
532 u8 test_value[2] = {0xff, 0xff}; 568 u8 test_value[2] = {0xff, 0xff};
533 569
534 ov9650_read_sensor(sd, address, &old_value, 1); 570 m5602_read_sensor(sd, address, &old_value, 1);
535 ov9650_write_sensor(sd, address, test_value, 1); 571 m5602_write_sensor(sd, address, test_value, 1);
536 ov9650_read_sensor(sd, address, &ctrl_value, 1); 572 m5602_read_sensor(sd, address, &ctrl_value, 1);
537 573
538 if (ctrl_value == test_value[0]) 574 if (ctrl_value == test_value[0])
539 info("register 0x%x is writeable", address); 575 info("register 0x%x is writeable", address);
@@ -541,6 +577,6 @@ void ov9650_dump_registers(struct sd *sd)
541 info("register 0x%x is read only", address); 577 info("register 0x%x is read only", address);
542 578
543 /* Restore original value */ 579 /* Restore original value */
544 ov9650_write_sensor(sd, address, &old_value, 1); 580 m5602_write_sensor(sd, address, &old_value, 1);
545 } 581 }
546} 582}