Commit 7d2f8dda authored by Sakari Ailus's avatar Sakari Ailus Committed by Mauro Carvalho Chehab

media: ccs: Make real to integer number conversion optional

The limit values will be raw soon, and the conversion takes place later
on. Prepare for that.
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 2989a457
...@@ -143,14 +143,23 @@ unsigned int ccs_reg_width(u32 reg) ...@@ -143,14 +143,23 @@ unsigned int ccs_reg_width(u32 reg)
return sizeof(uint8_t); return sizeof(uint8_t);
} }
u32 ccs_reg_conv(struct ccs_sensor *sensor, u32 reg, u32 val)
{
struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
if (reg & CCS_FL_FLOAT_IREAL)
val = float_to_u32_mul_1000000(client, val);
return val;
}
/* /*
* Read a 8/16/32-bit i2c register. The value is returned in 'val'. * Read a 8/16/32-bit i2c register. The value is returned in 'val'.
* Returns zero if successful, or non-zero otherwise. * Returns zero if successful, or non-zero otherwise.
*/ */
static int __ccs_read_addr(struct ccs_sensor *sensor, u32 reg, u32 *val, static int __ccs_read_addr(struct ccs_sensor *sensor, u32 reg, u32 *val,
bool only8) bool only8, bool conv)
{ {
struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
unsigned int len = ccs_reg_width(reg); unsigned int len = ccs_reg_width(reg);
int rval; int rval;
...@@ -162,14 +171,16 @@ static int __ccs_read_addr(struct ccs_sensor *sensor, u32 reg, u32 *val, ...@@ -162,14 +171,16 @@ static int __ccs_read_addr(struct ccs_sensor *sensor, u32 reg, u32 *val,
if (rval < 0) if (rval < 0)
return rval; return rval;
if (reg & CCS_FL_FLOAT_IREAL) if (!conv)
*val = float_to_u32_mul_1000000(client, *val); return 0;
*val = ccs_reg_conv(sensor, reg, *val);
return 0; return 0;
} }
static int ccs_read_addr_raw(struct ccs_sensor *sensor, u32 reg, u32 *val, static int ccs_read_addr_raw(struct ccs_sensor *sensor, u32 reg, u32 *val,
bool force8, bool quirk) bool force8, bool quirk, bool conv)
{ {
int rval; int rval;
...@@ -182,22 +193,28 @@ static int ccs_read_addr_raw(struct ccs_sensor *sensor, u32 reg, u32 *val, ...@@ -182,22 +193,28 @@ static int ccs_read_addr_raw(struct ccs_sensor *sensor, u32 reg, u32 *val,
return rval; return rval;
if (force8) if (force8)
return __ccs_read_addr(sensor, reg, val, true); return __ccs_read_addr(sensor, reg, val, true, conv);
} }
return __ccs_read_addr(sensor, reg, val, return __ccs_read_addr(sensor, reg, val,
ccs_needs_quirk(sensor, ccs_needs_quirk(sensor,
CCS_QUIRK_FLAG_8BIT_READ_ONLY)); CCS_QUIRK_FLAG_8BIT_READ_ONLY),
conv);
} }
int ccs_read_addr(struct ccs_sensor *sensor, u32 reg, u32 *val) int ccs_read_addr(struct ccs_sensor *sensor, u32 reg, u32 *val)
{ {
return ccs_read_addr_raw(sensor, reg, val, false, true); return ccs_read_addr_raw(sensor, reg, val, false, true, true);
} }
int ccs_read_addr_8only(struct ccs_sensor *sensor, u32 reg, u32 *val) int ccs_read_addr_8only(struct ccs_sensor *sensor, u32 reg, u32 *val)
{ {
return ccs_read_addr_raw(sensor, reg, val, true, true); return ccs_read_addr_raw(sensor, reg, val, true, true, true);
}
int ccs_read_addr_noconv(struct ccs_sensor *sensor, u32 reg, u32 *val)
{
return ccs_read_addr_raw(sensor, reg, val, false, true, false);
} }
int ccs_write_addr_no_quirk(struct ccs_sensor *sensor, u32 reg, u32 val) int ccs_write_addr_no_quirk(struct ccs_sensor *sensor, u32 reg, u32 val)
......
...@@ -24,10 +24,12 @@ struct ccs_sensor; ...@@ -24,10 +24,12 @@ struct ccs_sensor;
int ccs_read_addr_no_quirk(struct ccs_sensor *sensor, u32 reg, u32 *val); int ccs_read_addr_no_quirk(struct ccs_sensor *sensor, u32 reg, u32 *val);
int ccs_read_addr(struct ccs_sensor *sensor, u32 reg, u32 *val); int ccs_read_addr(struct ccs_sensor *sensor, u32 reg, u32 *val);
int ccs_read_addr_8only(struct ccs_sensor *sensor, u32 reg, u32 *val); int ccs_read_addr_8only(struct ccs_sensor *sensor, u32 reg, u32 *val);
int ccs_read_addr_noconv(struct ccs_sensor *sensor, u32 reg, u32 *val);
int ccs_write_addr_no_quirk(struct ccs_sensor *sensor, u32 reg, u32 val); int ccs_write_addr_no_quirk(struct ccs_sensor *sensor, u32 reg, u32 val);
int ccs_write_addr(struct ccs_sensor *sensor, u32 reg, u32 val); int ccs_write_addr(struct ccs_sensor *sensor, u32 reg, u32 val);
unsigned int ccs_reg_width(u32 reg); unsigned int ccs_reg_width(u32 reg);
u32 ccs_reg_conv(struct ccs_sensor *sensor, u32 reg, u32 val);
#define ccs_read(sensor, reg_name, val) \ #define ccs_read(sensor, reg_name, val) \
ccs_read_addr(sensor, CCS_R_##reg_name, val) ccs_read_addr(sensor, CCS_R_##reg_name, val)
......
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