aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video
diff options
context:
space:
mode:
authorErik Andr?n <erik.andren@gmail.com>2008-12-27 10:28:00 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-04-06 20:44:35 -0400
commit051781b3a8ea31f1834fddb916607a3088a28f71 (patch)
treea8f7f4732467b73508257ef5090dec2292468986 /drivers/media/video
parentad567ec23501dfdf00dcc8915709a1fda556b6f4 (diff)
V4L/DVB (11405): gspca - m5602: Simplify error handling
Simplfy error handling by replacing goto statements with return equivalents. Signed-off-by: Erik Andr?n <erik.andren@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video')
-rw-r--r--drivers/media/video/gspca/m5602/m5602_core.c13
-rw-r--r--drivers/media/video/gspca/m5602/m5602_mt9m111.c14
-rw-r--r--drivers/media/video/gspca/m5602/m5602_ov9650.c38
-rw-r--r--drivers/media/video/gspca/m5602/m5602_po1030.c13
-rw-r--r--drivers/media/video/gspca/m5602/m5602_s5k4aa.c51
-rw-r--r--drivers/media/video/gspca/m5602/m5602_s5k83a.c35
6 files changed, 73 insertions, 91 deletions
diff --git a/drivers/media/video/gspca/m5602/m5602_core.c b/drivers/media/video/gspca/m5602/m5602_core.c
index b35e4838a6e5..9f833b4ec525 100644
--- a/drivers/media/video/gspca/m5602/m5602_core.c
+++ b/drivers/media/video/gspca/m5602/m5602_core.c
@@ -92,29 +92,29 @@ int m5602_read_sensor(struct sd *sd, const u8 address,
92 err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data); 92 err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
93 } while ((*i2c_data & I2C_BUSY) && !err); 93 } while ((*i2c_data & I2C_BUSY) && !err);
94 if (err < 0) 94 if (err < 0)
95 goto out; 95 return err;
96 96
97 err = m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR, 97 err = m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
98 sd->sensor->i2c_slave_id); 98 sd->sensor->i2c_slave_id);
99 if (err < 0) 99 if (err < 0)
100 goto out; 100 return err;
101 101
102 err = m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address); 102 err = m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
103 if (err < 0) 103 if (err < 0)
104 goto out; 104 return err;
105 105
106 if (sd->sensor->i2c_regW == 1) { 106 if (sd->sensor->i2c_regW == 1) {
107 err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, len); 107 err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, len);
108 if (err < 0) 108 if (err < 0)
109 goto out; 109 return err;
110 110
111 err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x08); 111 err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x08);
112 if (err < 0) 112 if (err < 0)
113 goto out; 113 return err;
114 } else { 114 } else {
115 err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x18 + len); 115 err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x18 + len);
116 if (err < 0) 116 if (err < 0)
117 goto out; 117 return err;
118 } 118 }
119 119
120 for (i = 0; (i < len) && !err; i++) { 120 for (i = 0; (i < len) && !err; i++) {
@@ -123,7 +123,6 @@ int m5602_read_sensor(struct sd *sd, const u8 address,
123 PDEBUG(D_CONF, "Reading sensor register " 123 PDEBUG(D_CONF, "Reading sensor register "
124 "0x%x containing 0x%x ", address, *i2c_data); 124 "0x%x containing 0x%x ", address, *i2c_data);
125 } 125 }
126out:
127 return err; 126 return err;
128} 127}
129 128
diff --git a/drivers/media/video/gspca/m5602/m5602_mt9m111.c b/drivers/media/video/gspca/m5602/m5602_mt9m111.c
index c0e71c331454..f3e9d8f0efe9 100644
--- a/drivers/media/video/gspca/m5602/m5602_mt9m111.c
+++ b/drivers/media/video/gspca/m5602/m5602_mt9m111.c
@@ -125,16 +125,15 @@ int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
125 /* Set the correct page map */ 125 /* Set the correct page map */
126 err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2); 126 err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
127 if (err < 0) 127 if (err < 0)
128 goto out; 128 return err;
129 129
130 err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2); 130 err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
131 if (err < 0) 131 if (err < 0)
132 goto out; 132 return err;
133 133
134 data[0] = (data[0] & 0xfe) | val; 134 data[0] = (data[0] & 0xfe) | val;
135 err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, 135 err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
136 data, 2); 136 data, 2);
137out:
138 return err; 137 return err;
139} 138}
140 139
@@ -163,16 +162,15 @@ int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
163 /* Set the correct page map */ 162 /* Set the correct page map */
164 err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2); 163 err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
165 if (err < 0) 164 if (err < 0)
166 goto out; 165 return err;
167 166
168 err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2); 167 err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
169 if (err < 0) 168 if (err < 0)
170 goto out; 169 return err;
171 170
172 data[0] = (data[0] & 0xfd) | ((val << 1) & 0x02); 171 data[0] = (data[0] & 0xfd) | ((val << 1) & 0x02);
173 err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, 172 err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
174 data, 2); 173 data, 2);
175out:
176 return err; 174 return err;
177} 175}
178 176
@@ -204,7 +202,7 @@ int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val)
204 /* Set the correct page map */ 202 /* Set the correct page map */
205 err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2); 203 err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
206 if (err < 0) 204 if (err < 0)
207 goto out; 205 return err;
208 206
209 if (val >= INITIAL_MAX_GAIN * 2 * 2 * 2) 207 if (val >= INITIAL_MAX_GAIN * 2 * 2 * 2)
210 return -EINVAL; 208 return -EINVAL;
@@ -229,7 +227,7 @@ int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val)
229 227
230 err = m5602_write_sensor(sd, MT9M111_SC_GLOBAL_GAIN, 228 err = m5602_write_sensor(sd, MT9M111_SC_GLOBAL_GAIN,
231 data, 2); 229 data, 2);
232out: 230
233 return err; 231 return err;
234} 232}
235 233
diff --git a/drivers/media/video/gspca/m5602/m5602_ov9650.c b/drivers/media/video/gspca/m5602/m5602_ov9650.c
index c908a8d6970a..81e5d1d3bdbc 100644
--- a/drivers/media/video/gspca/m5602/m5602_ov9650.c
+++ b/drivers/media/video/gspca/m5602/m5602_ov9650.c
@@ -222,21 +222,21 @@ int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
222 222
223 err = m5602_read_sensor(sd, OV9650_COM1, &i2c_data, 1); 223 err = m5602_read_sensor(sd, OV9650_COM1, &i2c_data, 1);
224 if (err < 0) 224 if (err < 0)
225 goto out; 225 return err;
226 *val = i2c_data & 0x03; 226 *val = i2c_data & 0x03;
227 227
228 err = m5602_read_sensor(sd, OV9650_AECH, &i2c_data, 1); 228 err = m5602_read_sensor(sd, OV9650_AECH, &i2c_data, 1);
229 if (err < 0) 229 if (err < 0)
230 goto out; 230 return err;
231 *val |= (i2c_data << 2); 231 *val |= (i2c_data << 2);
232 232
233 err = m5602_read_sensor(sd, OV9650_AECHM, &i2c_data, 1); 233 err = m5602_read_sensor(sd, OV9650_AECHM, &i2c_data, 1);
234 if (err < 0) 234 if (err < 0)
235 goto out; 235 return err;
236 *val |= (i2c_data & 0x3f) << 10; 236 *val |= (i2c_data & 0x3f) << 10;
237 237
238 PDEBUG(D_V4L2, "Read exposure %d", *val); 238 PDEBUG(D_V4L2, "Read exposure %d", *val);
239out: 239
240 return err; 240 return err;
241} 241}
242 242
@@ -254,20 +254,19 @@ int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
254 err = m5602_write_sensor(sd, OV9650_AECHM, 254 err = m5602_write_sensor(sd, OV9650_AECHM,
255 &i2c_data, 1); 255 &i2c_data, 1);
256 if (err < 0) 256 if (err < 0)
257 goto out; 257 return err;
258 258
259 /* The 8 middle bits */ 259 /* The 8 middle bits */
260 i2c_data = (val >> 2) & 0xff; 260 i2c_data = (val >> 2) & 0xff;
261 err = m5602_write_sensor(sd, OV9650_AECH, 261 err = m5602_write_sensor(sd, OV9650_AECH,
262 &i2c_data, 1); 262 &i2c_data, 1);
263 if (err < 0) 263 if (err < 0)
264 goto out; 264 return err;
265 265
266 /* The 2 LSBs */ 266 /* The 2 LSBs */
267 i2c_data = val & 0x03; 267 i2c_data = val & 0x03;
268 err = m5602_write_sensor(sd, OV9650_COM1, &i2c_data, 1); 268 err = m5602_write_sensor(sd, OV9650_COM1, &i2c_data, 1);
269 269
270out:
271 return err; 270 return err;
272} 271}
273 272
@@ -390,7 +389,7 @@ int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
390 PDEBUG(D_V4L2, "Set horizontal flip to %d", val); 389 PDEBUG(D_V4L2, "Set horizontal flip to %d", val);
391 err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1); 390 err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
392 if (err < 0) 391 if (err < 0)
393 goto out; 392 return err;
394 393
395 if (dmi_check_system(ov9650_flip_dmi_table)) 394 if (dmi_check_system(ov9650_flip_dmi_table))
396 i2c_data = ((i2c_data & 0xdf) | 395 i2c_data = ((i2c_data & 0xdf) |
@@ -400,7 +399,7 @@ int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
400 ((val & 0x01) << 5)); 399 ((val & 0x01) << 5));
401 400
402 err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1); 401 err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
403out: 402
404 return err; 403 return err;
405} 404}
406 405
@@ -429,7 +428,7 @@ int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
429 PDEBUG(D_V4L2, "Set vertical flip to %d", val); 428 PDEBUG(D_V4L2, "Set vertical flip to %d", val);
430 err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1); 429 err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
431 if (err < 0) 430 if (err < 0)
432 goto out; 431 return err;
433 432
434 if (dmi_check_system(ov9650_flip_dmi_table)) 433 if (dmi_check_system(ov9650_flip_dmi_table))
435 i2c_data = ((i2c_data & 0xef) | 434 i2c_data = ((i2c_data & 0xef) |
@@ -439,7 +438,7 @@ int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
439 ((val & 0x01) << 4)); 438 ((val & 0x01) << 4));
440 439
441 err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1); 440 err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
442out: 441
443 return err; 442 return err;
444} 443}
445 444
@@ -451,13 +450,13 @@ int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
451 450
452 err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1); 451 err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
453 if (err < 0) 452 if (err < 0)
454 goto out; 453 return err;
455 *val = (i2c_data & 0x03) << 8; 454 *val = (i2c_data & 0x03) << 8;
456 455
457 err = m5602_read_sensor(sd, OV9650_GAIN, &i2c_data, 1); 456 err = m5602_read_sensor(sd, OV9650_GAIN, &i2c_data, 1);
458 *val |= i2c_data; 457 *val |= i2c_data;
459 PDEBUG(D_V4L2, "Read gain %d", *val); 458 PDEBUG(D_V4L2, "Read gain %d", *val);
460out: 459
461 return err; 460 return err;
462} 461}
463 462
@@ -473,19 +472,18 @@ int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
473 corrupting the VREF high and low bits */ 472 corrupting the VREF high and low bits */
474 err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1); 473 err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
475 if (err < 0) 474 if (err < 0)
476 goto out; 475 return err;
477 476
478 /* Mask away all uninteresting bits */ 477 /* Mask away all uninteresting bits */
479 i2c_data = ((val & 0x0300) >> 2) | (i2c_data & 0x3F); 478 i2c_data = ((val & 0x0300) >> 2) | (i2c_data & 0x3F);
480 err = m5602_write_sensor(sd, OV9650_VREF, &i2c_data, 1); 479 err = m5602_write_sensor(sd, OV9650_VREF, &i2c_data, 1);
481 if (err < 0) 480 if (err < 0)
482 goto out; 481 return err;
483 482
484 /* The 8 LSBs */ 483 /* The 8 LSBs */
485 i2c_data = val & 0xff; 484 i2c_data = val & 0xff;
486 err = m5602_write_sensor(sd, OV9650_GAIN, &i2c_data, 1); 485 err = m5602_write_sensor(sd, OV9650_GAIN, &i2c_data, 1);
487 486
488out:
489 return err; 487 return err;
490} 488}
491 489
@@ -511,11 +509,11 @@ int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val)
511 PDEBUG(D_V4L2, "Set auto white balance to %d", val); 509 PDEBUG(D_V4L2, "Set auto white balance to %d", val);
512 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1); 510 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
513 if (err < 0) 511 if (err < 0)
514 goto out; 512 return err;
515 513
516 i2c_data = ((i2c_data & 0xfd) | ((val & 0x01) << 1)); 514 i2c_data = ((i2c_data & 0xfd) | ((val & 0x01) << 1));
517 err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1); 515 err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
518out: 516
519 return err; 517 return err;
520} 518}
521 519
@@ -541,11 +539,11 @@ int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
541 PDEBUG(D_V4L2, "Set auto gain control to %d", val); 539 PDEBUG(D_V4L2, "Set auto gain control to %d", val);
542 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1); 540 err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
543 if (err < 0) 541 if (err < 0)
544 goto out; 542 return err;
545 543
546 i2c_data = ((i2c_data & 0xfb) | ((val & 0x01) << 2)); 544 i2c_data = ((i2c_data & 0xfb) | ((val & 0x01) << 2));
547 err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1); 545 err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
548out: 546
549 return err; 547 return err;
550} 548}
551 549
diff --git a/drivers/media/video/gspca/m5602/m5602_po1030.c b/drivers/media/video/gspca/m5602/m5602_po1030.c
index 2e7fb91673cf..d509330f5f51 100644
--- a/drivers/media/video/gspca/m5602/m5602_po1030.c
+++ b/drivers/media/video/gspca/m5602/m5602_po1030.c
@@ -108,7 +108,7 @@ int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
108 err = m5602_read_sensor(sd, PO1030_REG_INTEGLINES_H, 108 err = m5602_read_sensor(sd, PO1030_REG_INTEGLINES_H,
109 &i2c_data, 1); 109 &i2c_data, 1);
110 if (err < 0) 110 if (err < 0)
111 goto out; 111 return err;
112 *val = (i2c_data << 8); 112 *val = (i2c_data << 8);
113 113
114 err = m5602_read_sensor(sd, PO1030_REG_INTEGLINES_M, 114 err = m5602_read_sensor(sd, PO1030_REG_INTEGLINES_M,
@@ -116,7 +116,7 @@ int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
116 *val |= i2c_data; 116 *val |= i2c_data;
117 117
118 PDEBUG(D_V4L2, "Exposure read as %d", *val); 118 PDEBUG(D_V4L2, "Exposure read as %d", *val);
119out: 119
120 return err; 120 return err;
121} 121}
122 122
@@ -135,7 +135,7 @@ int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
135 err = m5602_write_sensor(sd, PO1030_REG_INTEGLINES_H, 135 err = m5602_write_sensor(sd, PO1030_REG_INTEGLINES_H,
136 &i2c_data, 1); 136 &i2c_data, 1);
137 if (err < 0) 137 if (err < 0)
138 goto out; 138 return err;
139 139
140 i2c_data = (val & 0xff); 140 i2c_data = (val & 0xff);
141 PDEBUG(D_V4L2, "Set exposure to low byte to 0x%x", 141 PDEBUG(D_V4L2, "Set exposure to low byte to 0x%x",
@@ -143,7 +143,6 @@ int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
143 err = m5602_write_sensor(sd, PO1030_REG_INTEGLINES_M, 143 err = m5602_write_sensor(sd, PO1030_REG_INTEGLINES_M,
144 &i2c_data, 1); 144 &i2c_data, 1);
145 145
146out:
147 return err; 146 return err;
148} 147}
149 148
@@ -186,14 +185,13 @@ int po1030_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
186 PDEBUG(D_V4L2, "Set hflip %d", val); 185 PDEBUG(D_V4L2, "Set hflip %d", val);
187 err = m5602_read_sensor(sd, PO1030_REG_CONTROL2, &i2c_data, 1); 186 err = m5602_read_sensor(sd, PO1030_REG_CONTROL2, &i2c_data, 1);
188 if (err < 0) 187 if (err < 0)
189 goto out; 188 return err;
190 189
191 i2c_data = (0x7f & i2c_data) | ((val & 0x01) << 7); 190 i2c_data = (0x7f & i2c_data) | ((val & 0x01) << 7);
192 191
193 err = m5602_write_sensor(sd, PO1030_REG_CONTROL2, 192 err = m5602_write_sensor(sd, PO1030_REG_CONTROL2,
194 &i2c_data, 1); 193 &i2c_data, 1);
195 194
196out:
197 return err; 195 return err;
198} 196}
199 197
@@ -222,14 +220,13 @@ int po1030_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
222 PDEBUG(D_V4L2, "Set vflip %d", val); 220 PDEBUG(D_V4L2, "Set vflip %d", val);
223 err = m5602_read_sensor(sd, PO1030_REG_CONTROL2, &i2c_data, 1); 221 err = m5602_read_sensor(sd, PO1030_REG_CONTROL2, &i2c_data, 1);
224 if (err < 0) 222 if (err < 0)
225 goto out; 223 return err;
226 224
227 i2c_data = (i2c_data & 0xbf) | ((val & 0x01) << 6); 225 i2c_data = (i2c_data & 0xbf) | ((val & 0x01) << 6);
228 226
229 err = m5602_write_sensor(sd, PO1030_REG_CONTROL2, 227 err = m5602_write_sensor(sd, PO1030_REG_CONTROL2,
230 &i2c_data, 1); 228 &i2c_data, 1);
231 229
232out:
233 return err; 230 return err;
234} 231}
235 232
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k4aa.c b/drivers/media/video/gspca/m5602/m5602_s5k4aa.c
index 41ae7f0b959f..921d009e02c4 100644
--- a/drivers/media/video/gspca/m5602/m5602_s5k4aa.c
+++ b/drivers/media/video/gspca/m5602/m5602_s5k4aa.c
@@ -237,17 +237,17 @@ int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
237 237
238 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 238 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
239 if (err < 0) 239 if (err < 0)
240 goto out; 240 return err;
241 241
242 err = m5602_read_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1); 242 err = m5602_read_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1);
243 if (err < 0) 243 if (err < 0)
244 goto out; 244 return err;
245 245
246 *val = data << 8; 246 *val = data << 8;
247 err = m5602_read_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1); 247 err = m5602_read_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1);
248 *val |= data; 248 *val |= data;
249 PDEBUG(D_V4L2, "Read exposure %d", *val); 249 PDEBUG(D_V4L2, "Read exposure %d", *val);
250out: 250
251 return err; 251 return err;
252} 252}
253 253
@@ -260,14 +260,14 @@ int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
260 PDEBUG(D_V4L2, "Set exposure to %d", val); 260 PDEBUG(D_V4L2, "Set exposure to %d", val);
261 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 261 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
262 if (err < 0) 262 if (err < 0)
263 goto out; 263 return err;
264 data = (val >> 8) & 0xff; 264 data = (val >> 8) & 0xff;
265 err = m5602_write_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1); 265 err = m5602_write_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1);
266 if (err < 0) 266 if (err < 0)
267 goto out; 267 return err;
268 data = val & 0xff; 268 data = val & 0xff;
269 err = m5602_write_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1); 269 err = m5602_write_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1);
270out: 270
271 return err; 271 return err;
272} 272}
273 273
@@ -279,13 +279,12 @@ int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
279 279
280 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 280 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
281 if (err < 0) 281 if (err < 0)
282 goto out; 282 return err;
283 283
284 err = m5602_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 284 err = m5602_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
285 *val = (data & S5K4AA_RM_V_FLIP) >> 7; 285 *val = (data & S5K4AA_RM_V_FLIP) >> 7;
286 PDEBUG(D_V4L2, "Read vertical flip %d", *val); 286 PDEBUG(D_V4L2, "Read vertical flip %d", *val);
287 287
288out:
289 return err; 288 return err;
290} 289}
291 290
@@ -298,32 +297,32 @@ int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
298 PDEBUG(D_V4L2, "Set vertical flip to %d", val); 297 PDEBUG(D_V4L2, "Set vertical flip to %d", val);
299 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 298 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
300 if (err < 0) 299 if (err < 0)
301 goto out; 300 return err;
302 err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1); 301 err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
303 if (err < 0) 302 if (err < 0)
304 goto out; 303 return err;
305 data = ((data & ~S5K4AA_RM_V_FLIP) 304 data = ((data & ~S5K4AA_RM_V_FLIP)
306 | ((val & 0x01) << 7)); 305 | ((val & 0x01) << 7));
307 err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1); 306 err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
308 if (err < 0) 307 if (err < 0)
309 goto out; 308 return err;
310 309
311 if (val) { 310 if (val) {
312 err = m5602_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1); 311 err = m5602_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
313 if (err < 0) 312 if (err < 0)
314 goto out; 313 return err;
315 314
316 data++; 315 data++;
317 err = m5602_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1); 316 err = m5602_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
318 } else { 317 } else {
319 err = m5602_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1); 318 err = m5602_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
320 if (err < 0) 319 if (err < 0)
321 goto out; 320 return err;
322 321
323 data--; 322 data--;
324 err = m5602_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1); 323 err = m5602_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
325 } 324 }
326out: 325
327 return err; 326 return err;
328} 327}
329 328
@@ -335,12 +334,12 @@ int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
335 334
336 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 335 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
337 if (err < 0) 336 if (err < 0)
338 goto out; 337 return err;
339 338
340 err = m5602_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 339 err = m5602_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
341 *val = (data & S5K4AA_RM_H_FLIP) >> 6; 340 *val = (data & S5K4AA_RM_H_FLIP) >> 6;
342 PDEBUG(D_V4L2, "Read horizontal flip %d", *val); 341 PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
343out: 342
344 return err; 343 return err;
345} 344}
346 345
@@ -354,32 +353,32 @@ int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
354 val); 353 val);
355 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 354 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
356 if (err < 0) 355 if (err < 0)
357 goto out; 356 return err;
358 err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1); 357 err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
359 if (err < 0) 358 if (err < 0)
360 goto out; 359 return err;
361 360
362 data = ((data & ~S5K4AA_RM_H_FLIP) | ((val & 0x01) << 6)); 361 data = ((data & ~S5K4AA_RM_H_FLIP) | ((val & 0x01) << 6));
363 err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1); 362 err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
364 if (err < 0) 363 if (err < 0)
365 goto out; 364 return err;
366 365
367 if (val) { 366 if (val) {
368 err = m5602_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1); 367 err = m5602_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
369 if (err < 0) 368 if (err < 0)
370 goto out; 369 return err;
371 data++; 370 data++;
372 err = m5602_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1); 371 err = m5602_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
373 if (err < 0) 372 if (err < 0)
374 goto out; 373 return err;
375 } else { 374 } else {
376 err = m5602_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1); 375 err = m5602_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
377 if (err < 0) 376 if (err < 0)
378 goto out; 377 return err;
379 data--; 378 data--;
380 err = m5602_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1); 379 err = m5602_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
381 } 380 }
382out: 381
383 return err; 382 return err;
384} 383}
385 384
@@ -391,13 +390,12 @@ int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
391 390
392 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 391 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
393 if (err < 0) 392 if (err < 0)
394 goto out; 393 return err;
395 394
396 err = m5602_read_sensor(sd, S5K4AA_GAIN_2, &data, 1); 395 err = m5602_read_sensor(sd, S5K4AA_GAIN_2, &data, 1);
397 *val = data; 396 *val = data;
398 PDEBUG(D_V4L2, "Read gain %d", *val); 397 PDEBUG(D_V4L2, "Read gain %d", *val);
399 398
400out:
401 return err; 399 return err;
402} 400}
403 401
@@ -410,12 +408,11 @@ int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val)
410 PDEBUG(D_V4L2, "Set gain to %d", val); 408 PDEBUG(D_V4L2, "Set gain to %d", val);
411 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); 409 err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
412 if (err < 0) 410 if (err < 0)
413 goto out; 411 return err;
414 412
415 data = val & 0xff; 413 data = val & 0xff;
416 err = m5602_write_sensor(sd, S5K4AA_GAIN_2, &data, 1); 414 err = m5602_write_sensor(sd, S5K4AA_GAIN_2, &data, 1);
417 415
418out:
419 return err; 416 return err;
420} 417}
421 418
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k83a.c b/drivers/media/video/gspca/m5602/m5602_s5k83a.c
index ccea4a758464..9bea347b9ef1 100644
--- a/drivers/media/video/gspca/m5602/m5602_s5k83a.c
+++ b/drivers/media/video/gspca/m5602/m5602_s5k83a.c
@@ -163,12 +163,11 @@ int s5k83a_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
163 163
164 err = m5602_read_sensor(sd, S5K83A_BRIGHTNESS, data, 2); 164 err = m5602_read_sensor(sd, S5K83A_BRIGHTNESS, data, 2);
165 if (err < 0) 165 if (err < 0)
166 goto out; 166 return err;
167 167
168 data[1] = data[1] << 1; 168 data[1] = data[1] << 1;
169 *val = data[1]; 169 *val = data[1];
170 170
171out:
172 return err; 171 return err;
173} 172}
174 173
@@ -182,13 +181,13 @@ int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
182 data[1] = 0x20; 181 data[1] = 0x20;
183 err = m5602_write_sensor(sd, 0x14, data, 2); 182 err = m5602_write_sensor(sd, 0x14, data, 2);
184 if (err < 0) 183 if (err < 0)
185 goto out; 184 return err;
186 185
187 data[0] = 0x01; 186 data[0] = 0x01;
188 data[1] = 0x00; 187 data[1] = 0x00;
189 err = m5602_write_sensor(sd, 0x0d, data, 2); 188 err = m5602_write_sensor(sd, 0x0d, data, 2);
190 if (err < 0) 189 if (err < 0)
191 goto out; 190 return err;
192 191
193 /* FIXME: This is not sane, we need to figure out the composition 192 /* FIXME: This is not sane, we need to figure out the composition
194 of these registers */ 193 of these registers */
@@ -196,7 +195,6 @@ int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
196 data[1] = val >> 1; /* brightness, high 7 bits */ 195 data[1] = val >> 1; /* brightness, high 7 bits */
197 err = m5602_write_sensor(sd, S5K83A_BRIGHTNESS, data, 2); 196 err = m5602_write_sensor(sd, S5K83A_BRIGHTNESS, data, 2);
198 197
199out:
200 return err; 198 return err;
201} 199}
202 200
@@ -208,11 +206,10 @@ int s5k83a_get_whiteness(struct gspca_dev *gspca_dev, __s32 *val)
208 206
209 err = m5602_read_sensor(sd, S5K83A_WHITENESS, &data, 1); 207 err = m5602_read_sensor(sd, S5K83A_WHITENESS, &data, 1);
210 if (err < 0) 208 if (err < 0)
211 goto out; 209 return err;
212 210
213 *val = data; 211 *val = data;
214 212
215out:
216 return err; 213 return err;
217} 214}
218 215
@@ -236,7 +233,7 @@ int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
236 233
237 err = m5602_read_sensor(sd, S5K83A_GAIN, data, 2); 234 err = m5602_read_sensor(sd, S5K83A_GAIN, data, 2);
238 if (err < 0) 235 if (err < 0)
239 goto out; 236 return err;
240 237
241 data[1] = data[1] & 0x3f; 238 data[1] = data[1] & 0x3f;
242 if (data[1] > S5K83A_MAXIMUM_GAIN) 239 if (data[1] > S5K83A_MAXIMUM_GAIN)
@@ -244,7 +241,6 @@ int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
244 241
245 *val = data[1]; 242 *val = data[1];
246 243
247out:
248 return err; 244 return err;
249} 245}
250 246
@@ -269,12 +265,11 @@ int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
269 data[0] = 0x05; 265 data[0] = 0x05;
270 err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); 266 err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
271 if (err < 0) 267 if (err < 0)
272 goto out; 268 return err;
273 269
274 err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1); 270 err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1);
275 *val = (data[0] | 0x40) ? 1 : 0; 271 *val = (data[0] | 0x40) ? 1 : 0;
276 272
277out:
278 return err; 273 return err;
279} 274}
280 275
@@ -287,23 +282,22 @@ int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
287 data[0] = 0x05; 282 data[0] = 0x05;
288 err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); 283 err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
289 if (err < 0) 284 if (err < 0)
290 goto out; 285 return err;
291 286
292 err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1); 287 err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1);
293 if (err < 0) 288 if (err < 0)
294 goto out; 289 return err;
295 290
296 /* set or zero six bit, seven is hflip */ 291 /* set or zero six bit, seven is hflip */
297 data[0] = (val) ? (data[0] & 0x80) | 0x40 | S5K83A_FLIP_MASK 292 data[0] = (val) ? (data[0] & 0x80) | 0x40 | S5K83A_FLIP_MASK
298 : (data[0] & 0x80) | S5K83A_FLIP_MASK; 293 : (data[0] & 0x80) | S5K83A_FLIP_MASK;
299 err = m5602_write_sensor(sd, S5K83A_FLIP, data, 1); 294 err = m5602_write_sensor(sd, S5K83A_FLIP, data, 1);
300 if (err < 0) 295 if (err < 0)
301 goto out; 296 return err;
302 297
303 data[0] = (val) ? 0x0b : 0x0a; 298 data[0] = (val) ? 0x0b : 0x0a;
304 err = m5602_write_sensor(sd, S5K83A_VFLIP_TUNE, data, 1); 299 err = m5602_write_sensor(sd, S5K83A_VFLIP_TUNE, data, 1);
305 300
306out:
307 return err; 301 return err;
308} 302}
309 303
@@ -316,12 +310,11 @@ int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
316 data[0] = 0x05; 310 data[0] = 0x05;
317 err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); 311 err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
318 if (err < 0) 312 if (err < 0)
319 goto out; 313 return err;
320 314
321 err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1); 315 err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1);
322 *val = (data[0] | 0x80) ? 1 : 0; 316 *val = (data[0] | 0x80) ? 1 : 0;
323 317
324out:
325 return err; 318 return err;
326} 319}
327 320
@@ -334,21 +327,21 @@ int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
334 data[0] = 0x05; 327 data[0] = 0x05;
335 err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); 328 err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
336 if (err < 0) 329 if (err < 0)
337 goto out; 330 return err;
338 331
339 err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1); 332 err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1);
340 if (err < 0) 333 if (err < 0)
341 goto out; 334 return err;
342 335
343 /* set or zero seven bit, six is vflip */ 336 /* set or zero seven bit, six is vflip */
344 data[0] = (val) ? (data[0] & 0x40) | 0x80 | S5K83A_FLIP_MASK 337 data[0] = (val) ? (data[0] & 0x40) | 0x80 | S5K83A_FLIP_MASK
345 : (data[0] & 0x40) | S5K83A_FLIP_MASK; 338 : (data[0] & 0x40) | S5K83A_FLIP_MASK;
346 err = m5602_write_sensor(sd, S5K83A_FLIP, data, 1); 339 err = m5602_write_sensor(sd, S5K83A_FLIP, data, 1);
347 if (err < 0) 340 if (err < 0)
348 goto out; 341 return err;
349 342
350 data[0] = (val) ? 0x0a : 0x0b; 343 data[0] = (val) ? 0x0a : 0x0b;
351 err = m5602_write_sensor(sd, S5K83A_HFLIP_TUNE, data, 1); 344 err = m5602_write_sensor(sd, S5K83A_HFLIP_TUNE, data, 1);
352out: 345
353 return err; 346 return err;
354} 347}