Commit 717c04cf authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (lm95245) Use multi-byte regmap operations

Use multi-byte regmap operations where possible to reduce code size
and the need for mutex protection.

No functional change.
Reviewed-by: default avatarTzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent a0a16d96
...@@ -161,18 +161,18 @@ static int lm95245_read_temp(struct device *dev, u32 attr, int channel, ...@@ -161,18 +161,18 @@ static int lm95245_read_temp(struct device *dev, u32 attr, int channel,
{ {
struct lm95245_data *data = dev_get_drvdata(dev); struct lm95245_data *data = dev_get_drvdata(dev);
struct regmap *regmap = data->regmap; struct regmap *regmap = data->regmap;
int ret, regl, regh, regvall, regvalh; unsigned int regs[2];
unsigned int regval;
u8 regvals[2];
int ret;
switch (attr) { switch (attr) {
case hwmon_temp_input: case hwmon_temp_input:
regl = channel ? LM95245_REG_R_REMOTE_TEMPL_S : regs[0] = channel ? LM95245_REG_R_REMOTE_TEMPL_S :
LM95245_REG_R_LOCAL_TEMPL_S; LM95245_REG_R_LOCAL_TEMPL_S;
regh = channel ? LM95245_REG_R_REMOTE_TEMPH_S : regs[1] = channel ? LM95245_REG_R_REMOTE_TEMPH_S :
LM95245_REG_R_LOCAL_TEMPH_S; LM95245_REG_R_LOCAL_TEMPH_S;
ret = regmap_read(regmap, regl, &regvall); ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
if (ret < 0)
return ret;
ret = regmap_read(regmap, regh, &regvalh);
if (ret < 0) if (ret < 0)
return ret; return ret;
/* /*
...@@ -181,92 +181,77 @@ static int lm95245_read_temp(struct device *dev, u32 attr, int channel, ...@@ -181,92 +181,77 @@ static int lm95245_read_temp(struct device *dev, u32 attr, int channel,
* Use signed calculation for remote if signed bit is set * Use signed calculation for remote if signed bit is set
* or if reported temperature is below signed limit. * or if reported temperature is below signed limit.
*/ */
if (!channel || (regvalh & 0x80) || regvalh < 0x7f) { if (!channel || (regvals[1] & 0x80) || regvals[1] < 0x7f) {
*val = temp_from_reg_signed(regvalh, regvall); *val = temp_from_reg_signed(regvals[1], regvals[0]);
return 0; return 0;
} }
ret = regmap_read(regmap, LM95245_REG_R_REMOTE_TEMPL_U, ret = regmap_bulk_read(regmap, LM95245_REG_R_REMOTE_TEMPH_U, regvals, 2);
&regvall); if (ret)
if (ret < 0)
return ret;
ret = regmap_read(regmap, LM95245_REG_R_REMOTE_TEMPH_U,
&regvalh);
if (ret < 0)
return ret; return ret;
*val = temp_from_reg_unsigned(regvalh, regvall); *val = temp_from_reg_unsigned(regvals[0], regvals[1]);
return 0; return 0;
case hwmon_temp_max: case hwmon_temp_max:
ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OS_LIMIT, ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OS_LIMIT,
&regvalh); &regval);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = regvalh * 1000; *val = regval * 1000;
return 0; return 0;
case hwmon_temp_crit: case hwmon_temp_crit:
regh = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT : regs[0] = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT :
LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT; LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT;
ret = regmap_read(regmap, regh, &regvalh); ret = regmap_read(regmap, regs[0], &regval);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = regvalh * 1000; *val = regval * 1000;
return 0; return 0;
case hwmon_temp_max_hyst: case hwmon_temp_max_hyst:
ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OS_LIMIT, regs[0] = LM95245_REG_RW_REMOTE_OS_LIMIT;
&regvalh); regs[1] = LM95245_REG_RW_COMMON_HYSTERESIS;
ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = regmap_read(regmap, LM95245_REG_RW_COMMON_HYSTERESIS, *val = (regvals[0] - regvals[1]) * 1000;
&regvall);
if (ret < 0)
return ret;
*val = (regvalh - regvall) * 1000;
return 0; return 0;
case hwmon_temp_crit_hyst: case hwmon_temp_crit_hyst:
regh = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT : regs[0] = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT :
LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT; LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT;
ret = regmap_read(regmap, regh, &regvalh); regs[1] = LM95245_REG_RW_COMMON_HYSTERESIS;
if (ret < 0)
return ret; ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
ret = regmap_read(regmap, LM95245_REG_RW_COMMON_HYSTERESIS,
&regvall);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = (regvalh - regvall) * 1000; *val = (regvals[0] - regvals[1]) * 1000;
return 0; return 0;
case hwmon_temp_type: case hwmon_temp_type:
ret = regmap_read(regmap, LM95245_REG_RW_CONFIG2, &regvalh); ret = regmap_read(regmap, LM95245_REG_RW_CONFIG2, &regval);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = (regvalh & CFG2_REMOTE_TT) ? 1 : 2; *val = (regval & CFG2_REMOTE_TT) ? 1 : 2;
return 0; return 0;
case hwmon_temp_offset: case hwmon_temp_offset:
ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OFFL, ret = regmap_bulk_read(regmap, LM95245_REG_RW_REMOTE_OFFH, regvals, 2);
&regvall);
if (ret < 0)
return ret;
ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OFFH,
&regvalh);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = temp_from_reg_signed(regvalh, regvall); *val = temp_from_reg_signed(regvals[0], regvals[1]);
return 0; return 0;
case hwmon_temp_max_alarm: case hwmon_temp_max_alarm:
ret = regmap_read(regmap, LM95245_REG_R_STATUS1, &regvalh); ret = regmap_read(regmap, LM95245_REG_R_STATUS1, &regval);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = !!(regvalh & STATUS1_ROS); *val = !!(regval & STATUS1_ROS);
return 0; return 0;
case hwmon_temp_crit_alarm: case hwmon_temp_crit_alarm:
ret = regmap_read(regmap, LM95245_REG_R_STATUS1, &regvalh); ret = regmap_read(regmap, LM95245_REG_R_STATUS1, &regval);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = !!(regvalh & (channel ? STATUS1_RTCRIT : STATUS1_LOC)); *val = !!(regval & (channel ? STATUS1_RTCRIT : STATUS1_LOC));
return 0; return 0;
case hwmon_temp_fault: case hwmon_temp_fault:
ret = regmap_read(regmap, LM95245_REG_R_STATUS1, &regvalh); ret = regmap_read(regmap, LM95245_REG_R_STATUS1, &regval);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = !!(regvalh & STATUS1_DIODE_FAULT); *val = !!(regval & STATUS1_DIODE_FAULT);
return 0; return 0;
default: default:
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -279,6 +264,7 @@ static int lm95245_write_temp(struct device *dev, u32 attr, int channel, ...@@ -279,6 +264,7 @@ static int lm95245_write_temp(struct device *dev, u32 attr, int channel,
struct lm95245_data *data = dev_get_drvdata(dev); struct lm95245_data *data = dev_get_drvdata(dev);
struct regmap *regmap = data->regmap; struct regmap *regmap = data->regmap;
unsigned int regval; unsigned int regval;
u8 regvals[2];
int ret, reg; int ret, reg;
switch (attr) { switch (attr) {
...@@ -311,16 +297,10 @@ static int lm95245_write_temp(struct device *dev, u32 attr, int channel, ...@@ -311,16 +297,10 @@ static int lm95245_write_temp(struct device *dev, u32 attr, int channel,
case hwmon_temp_offset: case hwmon_temp_offset:
val = clamp_val(val, -128000, 127875); val = clamp_val(val, -128000, 127875);
val = val * 256 / 1000; val = val * 256 / 1000;
mutex_lock(&data->update_lock); regvals[0] = val >> 8;
ret = regmap_write(regmap, LM95245_REG_RW_REMOTE_OFFL, regvals[1] = val & 0xe0;
val & 0xe0);
if (ret < 0) { ret = regmap_bulk_write(regmap, LM95245_REG_RW_REMOTE_OFFH, regvals, 2);
mutex_unlock(&data->update_lock);
return ret;
}
ret = regmap_write(regmap, LM95245_REG_RW_REMOTE_OFFH,
(val >> 8) & 0xff);
mutex_unlock(&data->update_lock);
return ret; return ret;
case hwmon_temp_type: case hwmon_temp_type:
if (val != 1 && val != 2) if (val != 1 && val != 2)
......
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