Commit 051781b3 authored by Erik Andr?n's avatar Erik Andr?n Committed by Mauro Carvalho Chehab

V4L/DVB (11405): gspca - m5602: Simplify error handling

Simplfy error handling by replacing goto statements with return equivalents.
Signed-off-by: default avatarErik Andr?n <erik.andren@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent ad567ec2
...@@ -92,29 +92,29 @@ int m5602_read_sensor(struct sd *sd, const u8 address, ...@@ -92,29 +92,29 @@ int m5602_read_sensor(struct sd *sd, const u8 address,
err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data); err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
} while ((*i2c_data & I2C_BUSY) && !err); } while ((*i2c_data & I2C_BUSY) && !err);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR, err = m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
sd->sensor->i2c_slave_id); sd->sensor->i2c_slave_id);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address); err = m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
if (err < 0) if (err < 0)
goto out; return err;
if (sd->sensor->i2c_regW == 1) { if (sd->sensor->i2c_regW == 1) {
err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, len); err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, len);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x08); err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x08);
if (err < 0) if (err < 0)
goto out; return err;
} else { } else {
err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x18 + len); err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x18 + len);
if (err < 0) if (err < 0)
goto out; return err;
} }
for (i = 0; (i < len) && !err; i++) { for (i = 0; (i < len) && !err; i++) {
...@@ -123,7 +123,6 @@ int m5602_read_sensor(struct sd *sd, const u8 address, ...@@ -123,7 +123,6 @@ int m5602_read_sensor(struct sd *sd, const u8 address,
PDEBUG(D_CONF, "Reading sensor register " PDEBUG(D_CONF, "Reading sensor register "
"0x%x containing 0x%x ", address, *i2c_data); "0x%x containing 0x%x ", address, *i2c_data);
} }
out:
return err; return err;
} }
......
...@@ -125,16 +125,15 @@ int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -125,16 +125,15 @@ int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
/* Set the correct page map */ /* Set the correct page map */
err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2); err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2); err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
if (err < 0) if (err < 0)
goto out; return err;
data[0] = (data[0] & 0xfe) | val; data[0] = (data[0] & 0xfe) | val;
err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
data, 2); data, 2);
out:
return err; return err;
} }
...@@ -163,16 +162,15 @@ int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -163,16 +162,15 @@ int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
/* Set the correct page map */ /* Set the correct page map */
err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2); err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2); err = m5602_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
if (err < 0) if (err < 0)
goto out; return err;
data[0] = (data[0] & 0xfd) | ((val << 1) & 0x02); data[0] = (data[0] & 0xfd) | ((val << 1) & 0x02);
err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, err = m5602_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
data, 2); data, 2);
out:
return err; return err;
} }
...@@ -204,7 +202,7 @@ int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val) ...@@ -204,7 +202,7 @@ int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val)
/* Set the correct page map */ /* Set the correct page map */
err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2); err = m5602_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
if (err < 0) if (err < 0)
goto out; return err;
if (val >= INITIAL_MAX_GAIN * 2 * 2 * 2) if (val >= INITIAL_MAX_GAIN * 2 * 2 * 2)
return -EINVAL; return -EINVAL;
...@@ -229,7 +227,7 @@ int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val) ...@@ -229,7 +227,7 @@ int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val)
err = m5602_write_sensor(sd, MT9M111_SC_GLOBAL_GAIN, err = m5602_write_sensor(sd, MT9M111_SC_GLOBAL_GAIN,
data, 2); data, 2);
out:
return err; return err;
} }
......
...@@ -222,21 +222,21 @@ int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -222,21 +222,21 @@ int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
err = m5602_read_sensor(sd, OV9650_COM1, &i2c_data, 1); err = m5602_read_sensor(sd, OV9650_COM1, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
*val = i2c_data & 0x03; *val = i2c_data & 0x03;
err = m5602_read_sensor(sd, OV9650_AECH, &i2c_data, 1); err = m5602_read_sensor(sd, OV9650_AECH, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
*val |= (i2c_data << 2); *val |= (i2c_data << 2);
err = m5602_read_sensor(sd, OV9650_AECHM, &i2c_data, 1); err = m5602_read_sensor(sd, OV9650_AECHM, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
*val |= (i2c_data & 0x3f) << 10; *val |= (i2c_data & 0x3f) << 10;
PDEBUG(D_V4L2, "Read exposure %d", *val); PDEBUG(D_V4L2, "Read exposure %d", *val);
out:
return err; return err;
} }
...@@ -254,20 +254,19 @@ int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val) ...@@ -254,20 +254,19 @@ int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
err = m5602_write_sensor(sd, OV9650_AECHM, err = m5602_write_sensor(sd, OV9650_AECHM,
&i2c_data, 1); &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
/* The 8 middle bits */ /* The 8 middle bits */
i2c_data = (val >> 2) & 0xff; i2c_data = (val >> 2) & 0xff;
err = m5602_write_sensor(sd, OV9650_AECH, err = m5602_write_sensor(sd, OV9650_AECH,
&i2c_data, 1); &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
/* The 2 LSBs */ /* The 2 LSBs */
i2c_data = val & 0x03; i2c_data = val & 0x03;
err = m5602_write_sensor(sd, OV9650_COM1, &i2c_data, 1); err = m5602_write_sensor(sd, OV9650_COM1, &i2c_data, 1);
out:
return err; return err;
} }
...@@ -390,7 +389,7 @@ int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -390,7 +389,7 @@ int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
PDEBUG(D_V4L2, "Set horizontal flip to %d", val); PDEBUG(D_V4L2, "Set horizontal flip to %d", val);
err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1); err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
if (dmi_check_system(ov9650_flip_dmi_table)) if (dmi_check_system(ov9650_flip_dmi_table))
i2c_data = ((i2c_data & 0xdf) | i2c_data = ((i2c_data & 0xdf) |
...@@ -400,7 +399,7 @@ int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -400,7 +399,7 @@ int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
((val & 0x01) << 5)); ((val & 0x01) << 5));
err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1); err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
out:
return err; return err;
} }
...@@ -429,7 +428,7 @@ int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -429,7 +428,7 @@ int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
PDEBUG(D_V4L2, "Set vertical flip to %d", val); PDEBUG(D_V4L2, "Set vertical flip to %d", val);
err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1); err = m5602_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
if (dmi_check_system(ov9650_flip_dmi_table)) if (dmi_check_system(ov9650_flip_dmi_table))
i2c_data = ((i2c_data & 0xef) | i2c_data = ((i2c_data & 0xef) |
...@@ -439,7 +438,7 @@ int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -439,7 +438,7 @@ int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
((val & 0x01) << 4)); ((val & 0x01) << 4));
err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1); err = m5602_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
out:
return err; return err;
} }
...@@ -451,13 +450,13 @@ int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -451,13 +450,13 @@ int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1); err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
*val = (i2c_data & 0x03) << 8; *val = (i2c_data & 0x03) << 8;
err = m5602_read_sensor(sd, OV9650_GAIN, &i2c_data, 1); err = m5602_read_sensor(sd, OV9650_GAIN, &i2c_data, 1);
*val |= i2c_data; *val |= i2c_data;
PDEBUG(D_V4L2, "Read gain %d", *val); PDEBUG(D_V4L2, "Read gain %d", *val);
out:
return err; return err;
} }
...@@ -473,19 +472,18 @@ int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val) ...@@ -473,19 +472,18 @@ int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
corrupting the VREF high and low bits */ corrupting the VREF high and low bits */
err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1); err = m5602_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
/* Mask away all uninteresting bits */ /* Mask away all uninteresting bits */
i2c_data = ((val & 0x0300) >> 2) | (i2c_data & 0x3F); i2c_data = ((val & 0x0300) >> 2) | (i2c_data & 0x3F);
err = m5602_write_sensor(sd, OV9650_VREF, &i2c_data, 1); err = m5602_write_sensor(sd, OV9650_VREF, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
/* The 8 LSBs */ /* The 8 LSBs */
i2c_data = val & 0xff; i2c_data = val & 0xff;
err = m5602_write_sensor(sd, OV9650_GAIN, &i2c_data, 1); err = m5602_write_sensor(sd, OV9650_GAIN, &i2c_data, 1);
out:
return err; return err;
} }
...@@ -511,11 +509,11 @@ int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val) ...@@ -511,11 +509,11 @@ int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val)
PDEBUG(D_V4L2, "Set auto white balance to %d", val); PDEBUG(D_V4L2, "Set auto white balance to %d", val);
err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1); err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
i2c_data = ((i2c_data & 0xfd) | ((val & 0x01) << 1)); i2c_data = ((i2c_data & 0xfd) | ((val & 0x01) << 1));
err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1); err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
out:
return err; return err;
} }
...@@ -541,11 +539,11 @@ int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val) ...@@ -541,11 +539,11 @@ int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
PDEBUG(D_V4L2, "Set auto gain control to %d", val); PDEBUG(D_V4L2, "Set auto gain control to %d", val);
err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1); err = m5602_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
i2c_data = ((i2c_data & 0xfb) | ((val & 0x01) << 2)); i2c_data = ((i2c_data & 0xfb) | ((val & 0x01) << 2));
err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1); err = m5602_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
out:
return err; return err;
} }
......
...@@ -108,7 +108,7 @@ int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -108,7 +108,7 @@ int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
err = m5602_read_sensor(sd, PO1030_REG_INTEGLINES_H, err = m5602_read_sensor(sd, PO1030_REG_INTEGLINES_H,
&i2c_data, 1); &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
*val = (i2c_data << 8); *val = (i2c_data << 8);
err = m5602_read_sensor(sd, PO1030_REG_INTEGLINES_M, 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,7 +116,7 @@ int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
*val |= i2c_data; *val |= i2c_data;
PDEBUG(D_V4L2, "Exposure read as %d", *val); PDEBUG(D_V4L2, "Exposure read as %d", *val);
out:
return err; return err;
} }
...@@ -135,7 +135,7 @@ int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val) ...@@ -135,7 +135,7 @@ int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
err = m5602_write_sensor(sd, PO1030_REG_INTEGLINES_H, err = m5602_write_sensor(sd, PO1030_REG_INTEGLINES_H,
&i2c_data, 1); &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
i2c_data = (val & 0xff); i2c_data = (val & 0xff);
PDEBUG(D_V4L2, "Set exposure to low byte to 0x%x", 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,7 +143,6 @@ int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
err = m5602_write_sensor(sd, PO1030_REG_INTEGLINES_M, err = m5602_write_sensor(sd, PO1030_REG_INTEGLINES_M,
&i2c_data, 1); &i2c_data, 1);
out:
return err; return err;
} }
...@@ -186,14 +185,13 @@ int po1030_set_hflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -186,14 +185,13 @@ int po1030_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
PDEBUG(D_V4L2, "Set hflip %d", val); PDEBUG(D_V4L2, "Set hflip %d", val);
err = m5602_read_sensor(sd, PO1030_REG_CONTROL2, &i2c_data, 1); err = m5602_read_sensor(sd, PO1030_REG_CONTROL2, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
i2c_data = (0x7f & i2c_data) | ((val & 0x01) << 7); i2c_data = (0x7f & i2c_data) | ((val & 0x01) << 7);
err = m5602_write_sensor(sd, PO1030_REG_CONTROL2, err = m5602_write_sensor(sd, PO1030_REG_CONTROL2,
&i2c_data, 1); &i2c_data, 1);
out:
return err; return err;
} }
...@@ -222,14 +220,13 @@ int po1030_set_vflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -222,14 +220,13 @@ int po1030_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
PDEBUG(D_V4L2, "Set vflip %d", val); PDEBUG(D_V4L2, "Set vflip %d", val);
err = m5602_read_sensor(sd, PO1030_REG_CONTROL2, &i2c_data, 1); err = m5602_read_sensor(sd, PO1030_REG_CONTROL2, &i2c_data, 1);
if (err < 0) if (err < 0)
goto out; return err;
i2c_data = (i2c_data & 0xbf) | ((val & 0x01) << 6); i2c_data = (i2c_data & 0xbf) | ((val & 0x01) << 6);
err = m5602_write_sensor(sd, PO1030_REG_CONTROL2, err = m5602_write_sensor(sd, PO1030_REG_CONTROL2,
&i2c_data, 1); &i2c_data, 1);
out:
return err; return err;
} }
......
...@@ -237,17 +237,17 @@ int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -237,17 +237,17 @@ int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_read_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1); err = m5602_read_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
*val = data << 8; *val = data << 8;
err = m5602_read_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1); err = m5602_read_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1);
*val |= data; *val |= data;
PDEBUG(D_V4L2, "Read exposure %d", *val); PDEBUG(D_V4L2, "Read exposure %d", *val);
out:
return err; return err;
} }
...@@ -260,14 +260,14 @@ int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val) ...@@ -260,14 +260,14 @@ int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
PDEBUG(D_V4L2, "Set exposure to %d", val); PDEBUG(D_V4L2, "Set exposure to %d", val);
err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
data = (val >> 8) & 0xff; data = (val >> 8) & 0xff;
err = m5602_write_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1); err = m5602_write_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
data = val & 0xff; data = val & 0xff;
err = m5602_write_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1); err = m5602_write_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1);
out:
return err; return err;
} }
...@@ -279,13 +279,12 @@ int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -279,13 +279,12 @@ int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); err = m5602_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
*val = (data & S5K4AA_RM_V_FLIP) >> 7; *val = (data & S5K4AA_RM_V_FLIP) >> 7;
PDEBUG(D_V4L2, "Read vertical flip %d", *val); PDEBUG(D_V4L2, "Read vertical flip %d", *val);
out:
return err; return err;
} }
...@@ -298,32 +297,32 @@ int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -298,32 +297,32 @@ int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
PDEBUG(D_V4L2, "Set vertical flip to %d", val); PDEBUG(D_V4L2, "Set vertical flip to %d", val);
err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1); err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
data = ((data & ~S5K4AA_RM_V_FLIP) data = ((data & ~S5K4AA_RM_V_FLIP)
| ((val & 0x01) << 7)); | ((val & 0x01) << 7));
err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1); err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
if (val) { if (val) {
err = m5602_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1); err = m5602_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
data++; data++;
err = m5602_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1); err = m5602_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
} else { } else {
err = m5602_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1); err = m5602_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
data--; data--;
err = m5602_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1); err = m5602_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
} }
out:
return err; return err;
} }
...@@ -335,12 +334,12 @@ int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -335,12 +334,12 @@ int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); err = m5602_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
*val = (data & S5K4AA_RM_H_FLIP) >> 6; *val = (data & S5K4AA_RM_H_FLIP) >> 6;
PDEBUG(D_V4L2, "Read horizontal flip %d", *val); PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
out:
return err; return err;
} }
...@@ -354,32 +353,32 @@ int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -354,32 +353,32 @@ int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
val); val);
err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1); err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
data = ((data & ~S5K4AA_RM_H_FLIP) | ((val & 0x01) << 6)); data = ((data & ~S5K4AA_RM_H_FLIP) | ((val & 0x01) << 6));
err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1); err = m5602_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
if (val) { if (val) {
err = m5602_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1); err = m5602_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
data++; data++;
err = m5602_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1); err = m5602_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
} else { } else {
err = m5602_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1); err = m5602_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
data--; data--;
err = m5602_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1); err = m5602_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
} }
out:
return err; return err;
} }
...@@ -391,13 +390,12 @@ int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -391,13 +390,12 @@ int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_read_sensor(sd, S5K4AA_GAIN_2, &data, 1); err = m5602_read_sensor(sd, S5K4AA_GAIN_2, &data, 1);
*val = data; *val = data;
PDEBUG(D_V4L2, "Read gain %d", *val); PDEBUG(D_V4L2, "Read gain %d", *val);
out:
return err; return err;
} }
...@@ -410,12 +408,11 @@ int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val) ...@@ -410,12 +408,11 @@ int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val)
PDEBUG(D_V4L2, "Set gain to %d", val); PDEBUG(D_V4L2, "Set gain to %d", val);
err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1); err = m5602_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
data = val & 0xff; data = val & 0xff;
err = m5602_write_sensor(sd, S5K4AA_GAIN_2, &data, 1); err = m5602_write_sensor(sd, S5K4AA_GAIN_2, &data, 1);
out:
return err; return err;
} }
......
...@@ -163,12 +163,11 @@ int s5k83a_get_brightness(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -163,12 +163,11 @@ int s5k83a_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
err = m5602_read_sensor(sd, S5K83A_BRIGHTNESS, data, 2); err = m5602_read_sensor(sd, S5K83A_BRIGHTNESS, data, 2);
if (err < 0) if (err < 0)
goto out; return err;
data[1] = data[1] << 1; data[1] = data[1] << 1;
*val = data[1]; *val = data[1];
out:
return err; return err;
} }
...@@ -182,13 +181,13 @@ int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val) ...@@ -182,13 +181,13 @@ int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
data[1] = 0x20; data[1] = 0x20;
err = m5602_write_sensor(sd, 0x14, data, 2); err = m5602_write_sensor(sd, 0x14, data, 2);
if (err < 0) if (err < 0)
goto out; return err;
data[0] = 0x01; data[0] = 0x01;
data[1] = 0x00; data[1] = 0x00;
err = m5602_write_sensor(sd, 0x0d, data, 2); err = m5602_write_sensor(sd, 0x0d, data, 2);
if (err < 0) if (err < 0)
goto out; return err;
/* FIXME: This is not sane, we need to figure out the composition /* FIXME: This is not sane, we need to figure out the composition
of these registers */ of these registers */
...@@ -196,7 +195,6 @@ int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val) ...@@ -196,7 +195,6 @@ int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
data[1] = val >> 1; /* brightness, high 7 bits */ data[1] = val >> 1; /* brightness, high 7 bits */
err = m5602_write_sensor(sd, S5K83A_BRIGHTNESS, data, 2); err = m5602_write_sensor(sd, S5K83A_BRIGHTNESS, data, 2);
out:
return err; return err;
} }
...@@ -208,11 +206,10 @@ int s5k83a_get_whiteness(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -208,11 +206,10 @@ int s5k83a_get_whiteness(struct gspca_dev *gspca_dev, __s32 *val)
err = m5602_read_sensor(sd, S5K83A_WHITENESS, &data, 1); err = m5602_read_sensor(sd, S5K83A_WHITENESS, &data, 1);
if (err < 0) if (err < 0)
goto out; return err;
*val = data; *val = data;
out:
return err; return err;
} }
...@@ -236,7 +233,7 @@ int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -236,7 +233,7 @@ int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
err = m5602_read_sensor(sd, S5K83A_GAIN, data, 2); err = m5602_read_sensor(sd, S5K83A_GAIN, data, 2);
if (err < 0) if (err < 0)
goto out; return err;
data[1] = data[1] & 0x3f; data[1] = data[1] & 0x3f;
if (data[1] > S5K83A_MAXIMUM_GAIN) if (data[1] > S5K83A_MAXIMUM_GAIN)
...@@ -244,7 +241,6 @@ int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -244,7 +241,6 @@ int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
*val = data[1]; *val = data[1];
out:
return err; return err;
} }
...@@ -269,12 +265,11 @@ int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -269,12 +265,11 @@ int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
data[0] = 0x05; data[0] = 0x05;
err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1); err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1);
*val = (data[0] | 0x40) ? 1 : 0; *val = (data[0] | 0x40) ? 1 : 0;
out:
return err; return err;
} }
...@@ -287,23 +282,22 @@ int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -287,23 +282,22 @@ int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
data[0] = 0x05; data[0] = 0x05;
err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1); err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1);
if (err < 0) if (err < 0)
goto out; return err;
/* set or zero six bit, seven is hflip */ /* set or zero six bit, seven is hflip */
data[0] = (val) ? (data[0] & 0x80) | 0x40 | S5K83A_FLIP_MASK data[0] = (val) ? (data[0] & 0x80) | 0x40 | S5K83A_FLIP_MASK
: (data[0] & 0x80) | S5K83A_FLIP_MASK; : (data[0] & 0x80) | S5K83A_FLIP_MASK;
err = m5602_write_sensor(sd, S5K83A_FLIP, data, 1); err = m5602_write_sensor(sd, S5K83A_FLIP, data, 1);
if (err < 0) if (err < 0)
goto out; return err;
data[0] = (val) ? 0x0b : 0x0a; data[0] = (val) ? 0x0b : 0x0a;
err = m5602_write_sensor(sd, S5K83A_VFLIP_TUNE, data, 1); err = m5602_write_sensor(sd, S5K83A_VFLIP_TUNE, data, 1);
out:
return err; return err;
} }
...@@ -316,12 +310,11 @@ int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -316,12 +310,11 @@ int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
data[0] = 0x05; data[0] = 0x05;
err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1); err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1);
*val = (data[0] | 0x80) ? 1 : 0; *val = (data[0] | 0x80) ? 1 : 0;
out:
return err; return err;
} }
...@@ -334,21 +327,21 @@ int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val) ...@@ -334,21 +327,21 @@ int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
data[0] = 0x05; data[0] = 0x05;
err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1); err = m5602_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
if (err < 0) if (err < 0)
goto out; return err;
err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1); err = m5602_read_sensor(sd, S5K83A_FLIP, data, 1);
if (err < 0) if (err < 0)
goto out; return err;
/* set or zero seven bit, six is vflip */ /* set or zero seven bit, six is vflip */
data[0] = (val) ? (data[0] & 0x40) | 0x80 | S5K83A_FLIP_MASK data[0] = (val) ? (data[0] & 0x40) | 0x80 | S5K83A_FLIP_MASK
: (data[0] & 0x40) | S5K83A_FLIP_MASK; : (data[0] & 0x40) | S5K83A_FLIP_MASK;
err = m5602_write_sensor(sd, S5K83A_FLIP, data, 1); err = m5602_write_sensor(sd, S5K83A_FLIP, data, 1);
if (err < 0) if (err < 0)
goto out; return err;
data[0] = (val) ? 0x0a : 0x0b; data[0] = (val) ? 0x0a : 0x0b;
err = m5602_write_sensor(sd, S5K83A_HFLIP_TUNE, data, 1); err = m5602_write_sensor(sd, S5K83A_HFLIP_TUNE, data, 1);
out:
return err; return err;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment