diff options
author | Erik Andrén <erik.andren@gmail.com> | 2008-11-20 12:11:58 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-12-30 06:39:48 -0500 |
commit | 7b2cd079ec8dcc65cdca6621245cfa5e30a8ef9f (patch) | |
tree | 0bfdd4a20dc0ce6ab85a062341b1cb07ecfb18a1 /drivers/media/video/gspca/m5602 | |
parent | bac79f37be2944f7a1db7585b347ca57628d57e2 (diff) |
V4L/DVB (10007): gspca - m5602: Refactor the error handling in the s5k83a
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/gspca/m5602')
-rw-r--r-- | drivers/media/video/gspca/m5602/m5602_s5k83a.c | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k83a.c b/drivers/media/video/gspca/m5602/m5602_s5k83a.c index 0f2addd9802b..00f0964e04ce 100644 --- a/drivers/media/video/gspca/m5602/m5602_s5k83a.c +++ b/drivers/media/video/gspca/m5602/m5602_s5k83a.c | |||
@@ -89,15 +89,11 @@ int s5k83a_read_sensor(struct sd *sd, const u8 address, | |||
89 | goto out; | 89 | goto out; |
90 | 90 | ||
91 | err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x18 + len); | 91 | err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x18 + len); |
92 | if (err < 0) | ||
93 | goto out; | ||
94 | 92 | ||
95 | do { | 93 | do { |
96 | err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data); | 94 | err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data); |
97 | } while ((*i2c_data & I2C_BUSY) && !err); | 95 | } while ((*i2c_data & I2C_BUSY) && !err); |
98 | 96 | ||
99 | if (err < 0) | ||
100 | goto out; | ||
101 | for (i = 0; i < len && !len; i++) { | 97 | for (i = 0; i < len && !len; i++) { |
102 | err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i])); | 98 | err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i])); |
103 | 99 | ||
@@ -245,10 +241,14 @@ int s5k83a_get_brightness(struct gspca_dev *gspca_dev, __s32 *val) | |||
245 | struct sd *sd = (struct sd *) gspca_dev; | 241 | struct sd *sd = (struct sd *) gspca_dev; |
246 | 242 | ||
247 | err = s5k83a_read_sensor(sd, S5K83A_BRIGHTNESS, data, 2); | 243 | err = s5k83a_read_sensor(sd, S5K83A_BRIGHTNESS, data, 2); |
244 | if (err < 0) | ||
245 | goto out; | ||
246 | |||
248 | data[1] = data[1] << 1; | 247 | data[1] = data[1] << 1; |
249 | *val = data[1]; | 248 | *val = data[1]; |
250 | 249 | ||
251 | return (err < 0) ? err : 0; | 250 | out: |
251 | return err; | ||
252 | } | 252 | } |
253 | 253 | ||
254 | int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val) | 254 | int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val) |
@@ -261,13 +261,13 @@ int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val) | |||
261 | data[1] = 0x20; | 261 | data[1] = 0x20; |
262 | err = s5k83a_write_sensor(sd, 0x14, data, 2); | 262 | err = s5k83a_write_sensor(sd, 0x14, data, 2); |
263 | if (err < 0) | 263 | if (err < 0) |
264 | return err; | 264 | goto out; |
265 | 265 | ||
266 | data[0] = 0x01; | 266 | data[0] = 0x01; |
267 | data[1] = 0x00; | 267 | data[1] = 0x00; |
268 | err = s5k83a_write_sensor(sd, 0x0d, data, 2); | 268 | err = s5k83a_write_sensor(sd, 0x0d, data, 2); |
269 | if (err < 0) | 269 | if (err < 0) |
270 | return err; | 270 | goto out; |
271 | 271 | ||
272 | /* FIXME: This is not sane, we need to figure out the composition | 272 | /* FIXME: This is not sane, we need to figure out the composition |
273 | of these registers */ | 273 | of these registers */ |
@@ -275,7 +275,8 @@ int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val) | |||
275 | data[1] = val >> 1; /* brightness, high 7 bits */ | 275 | data[1] = val >> 1; /* brightness, high 7 bits */ |
276 | err = s5k83a_write_sensor(sd, S5K83A_BRIGHTNESS, data, 2); | 276 | err = s5k83a_write_sensor(sd, S5K83A_BRIGHTNESS, data, 2); |
277 | 277 | ||
278 | return (err < 0) ? err : 0; | 278 | out: |
279 | return err; | ||
279 | } | 280 | } |
280 | 281 | ||
281 | int s5k83a_get_whiteness(struct gspca_dev *gspca_dev, __s32 *val) | 282 | int s5k83a_get_whiteness(struct gspca_dev *gspca_dev, __s32 *val) |
@@ -285,9 +286,13 @@ int s5k83a_get_whiteness(struct gspca_dev *gspca_dev, __s32 *val) | |||
285 | struct sd *sd = (struct sd *) gspca_dev; | 286 | struct sd *sd = (struct sd *) gspca_dev; |
286 | 287 | ||
287 | err = s5k83a_read_sensor(sd, S5K83A_WHITENESS, &data, 1); | 288 | err = s5k83a_read_sensor(sd, S5K83A_WHITENESS, &data, 1); |
289 | if (err < 0) | ||
290 | goto out; | ||
288 | 291 | ||
289 | *val = data; | 292 | *val = data; |
290 | return (err < 0) ? err : 0; | 293 | |
294 | out: | ||
295 | return err; | ||
291 | } | 296 | } |
292 | 297 | ||
293 | int s5k83a_set_whiteness(struct gspca_dev *gspca_dev, __s32 val) | 298 | int s5k83a_set_whiteness(struct gspca_dev *gspca_dev, __s32 val) |
@@ -299,7 +304,7 @@ int s5k83a_set_whiteness(struct gspca_dev *gspca_dev, __s32 val) | |||
299 | data[0] = val; | 304 | data[0] = val; |
300 | err = s5k83a_write_sensor(sd, S5K83A_WHITENESS, data, 1); | 305 | err = s5k83a_write_sensor(sd, S5K83A_WHITENESS, data, 1); |
301 | 306 | ||
302 | return (err < 0) ? err : 0; | 307 | return err; |
303 | } | 308 | } |
304 | 309 | ||
305 | int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val) | 310 | int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val) |
@@ -309,6 +314,8 @@ int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val) | |||
309 | struct sd *sd = (struct sd *) gspca_dev; | 314 | struct sd *sd = (struct sd *) gspca_dev; |
310 | 315 | ||
311 | err = s5k83a_read_sensor(sd, S5K83A_GAIN, data, 2); | 316 | err = s5k83a_read_sensor(sd, S5K83A_GAIN, data, 2); |
317 | if (err < 0) | ||
318 | goto out; | ||
312 | 319 | ||
313 | data[1] = data[1] & 0x3f; | 320 | data[1] = data[1] & 0x3f; |
314 | if (data[1] > S5K83A_MAXIMUM_GAIN) | 321 | if (data[1] > S5K83A_MAXIMUM_GAIN) |
@@ -316,7 +323,8 @@ int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val) | |||
316 | 323 | ||
317 | *val = data[1]; | 324 | *val = data[1]; |
318 | 325 | ||
319 | return (err < 0) ? err : 0; | 326 | out: |
327 | return err; | ||
320 | } | 328 | } |
321 | 329 | ||
322 | int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val) | 330 | int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val) |
@@ -328,8 +336,7 @@ int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val) | |||
328 | data[0] = 0; | 336 | data[0] = 0; |
329 | data[1] = val; | 337 | data[1] = val; |
330 | err = s5k83a_write_sensor(sd, S5K83A_GAIN, data, 2); | 338 | err = s5k83a_write_sensor(sd, S5K83A_GAIN, data, 2); |
331 | 339 | return err; | |
332 | return (err < 0) ? err : 0; | ||
333 | } | 340 | } |
334 | 341 | ||
335 | int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) | 342 | int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) |
@@ -341,12 +348,13 @@ int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) | |||
341 | data[0] = 0x05; | 348 | data[0] = 0x05; |
342 | err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); | 349 | err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); |
343 | if (err < 0) | 350 | if (err < 0) |
344 | return err; | 351 | goto out; |
345 | 352 | ||
346 | err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1); | 353 | err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1); |
347 | *val = (data[0] | 0x40) ? 1 : 0; | 354 | *val = (data[0] | 0x40) ? 1 : 0; |
348 | 355 | ||
349 | return (err < 0) ? err : 0; | 356 | out: |
357 | return err; | ||
350 | } | 358 | } |
351 | 359 | ||
352 | int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val) | 360 | int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val) |
@@ -358,23 +366,24 @@ int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val) | |||
358 | data[0] = 0x05; | 366 | data[0] = 0x05; |
359 | err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); | 367 | err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); |
360 | if (err < 0) | 368 | if (err < 0) |
361 | return err; | 369 | goto out; |
362 | 370 | ||
363 | err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1); | 371 | err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1); |
364 | if (err < 0) | 372 | if (err < 0) |
365 | return err; | 373 | goto out; |
366 | 374 | ||
367 | /* set or zero six bit, seven is hflip */ | 375 | /* set or zero six bit, seven is hflip */ |
368 | data[0] = (val) ? (data[0] & 0x80) | 0x40 | S5K83A_FLIP_MASK | 376 | data[0] = (val) ? (data[0] & 0x80) | 0x40 | S5K83A_FLIP_MASK |
369 | : (data[0] & 0x80) | S5K83A_FLIP_MASK; | 377 | : (data[0] & 0x80) | S5K83A_FLIP_MASK; |
370 | err = s5k83a_write_sensor(sd, S5K83A_FLIP, data, 1); | 378 | err = s5k83a_write_sensor(sd, S5K83A_FLIP, data, 1); |
371 | if (err < 0) | 379 | if (err < 0) |
372 | return err; | 380 | goto out; |
373 | 381 | ||
374 | data[0] = (val) ? 0x0b : 0x0a; | 382 | data[0] = (val) ? 0x0b : 0x0a; |
375 | err = s5k83a_write_sensor(sd, S5K83A_VFLIP_TUNE, data, 1); | 383 | err = s5k83a_write_sensor(sd, S5K83A_VFLIP_TUNE, data, 1); |
376 | 384 | ||
377 | return (err < 0) ? err : 0; | 385 | out: |
386 | return err; | ||
378 | } | 387 | } |
379 | 388 | ||
380 | int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) | 389 | int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) |
@@ -386,12 +395,13 @@ int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) | |||
386 | data[0] = 0x05; | 395 | data[0] = 0x05; |
387 | err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); | 396 | err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); |
388 | if (err < 0) | 397 | if (err < 0) |
389 | return err; | 398 | goto out; |
390 | 399 | ||
391 | err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1); | 400 | err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1); |
392 | *val = (data[0] | 0x80) ? 1 : 0; | 401 | *val = (data[0] | 0x80) ? 1 : 0; |
393 | 402 | ||
394 | return (err < 0) ? err : 0; | 403 | out: |
404 | return err; | ||
395 | } | 405 | } |
396 | 406 | ||
397 | int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val) | 407 | int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val) |
@@ -403,21 +413,21 @@ int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val) | |||
403 | data[0] = 0x05; | 413 | data[0] = 0x05; |
404 | err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); | 414 | err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); |
405 | if (err < 0) | 415 | if (err < 0) |
406 | return err; | 416 | goto out; |
407 | 417 | ||
408 | err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1); | 418 | err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1); |
409 | if (err < 0) | 419 | if (err < 0) |
410 | return err; | 420 | goto out; |
411 | 421 | ||
412 | /* set or zero seven bit, six is vflip */ | 422 | /* set or zero seven bit, six is vflip */ |
413 | data[0] = (val) ? (data[0] & 0x40) | 0x80 | S5K83A_FLIP_MASK | 423 | data[0] = (val) ? (data[0] & 0x40) | 0x80 | S5K83A_FLIP_MASK |
414 | : (data[0] & 0x40) | S5K83A_FLIP_MASK; | 424 | : (data[0] & 0x40) | S5K83A_FLIP_MASK; |
415 | err = s5k83a_write_sensor(sd, S5K83A_FLIP, data, 1); | 425 | err = s5k83a_write_sensor(sd, S5K83A_FLIP, data, 1); |
416 | if (err < 0) | 426 | if (err < 0) |
417 | return err; | 427 | goto out; |
418 | 428 | ||
419 | data[0] = (val) ? 0x0a : 0x0b; | 429 | data[0] = (val) ? 0x0a : 0x0b; |
420 | err = s5k83a_write_sensor(sd, S5K83A_HFLIP_TUNE, data, 1); | 430 | err = s5k83a_write_sensor(sd, S5K83A_HFLIP_TUNE, data, 1); |
421 | 431 | out: | |
422 | return (err < 0) ? err : 0; | 432 | return err; |
423 | } | 433 | } |