mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-28 16:56:26 +00:00
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: Tzung-Bi Shih <tzungbi@kernel.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
a0a16d960f
commit
717c04cf43
@ -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 regmap *regmap = data->regmap;
|
||||
int ret, regl, regh, regvall, regvalh;
|
||||
unsigned int regs[2];
|
||||
unsigned int regval;
|
||||
u8 regvals[2];
|
||||
int ret;
|
||||
|
||||
switch (attr) {
|
||||
case hwmon_temp_input:
|
||||
regl = channel ? LM95245_REG_R_REMOTE_TEMPL_S :
|
||||
LM95245_REG_R_LOCAL_TEMPL_S;
|
||||
regh = channel ? LM95245_REG_R_REMOTE_TEMPH_S :
|
||||
LM95245_REG_R_LOCAL_TEMPH_S;
|
||||
ret = regmap_read(regmap, regl, ®vall);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
ret = regmap_read(regmap, regh, ®valh);
|
||||
regs[0] = channel ? LM95245_REG_R_REMOTE_TEMPL_S :
|
||||
LM95245_REG_R_LOCAL_TEMPL_S;
|
||||
regs[1] = channel ? LM95245_REG_R_REMOTE_TEMPH_S :
|
||||
LM95245_REG_R_LOCAL_TEMPH_S;
|
||||
ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
/*
|
||||
@ -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
|
||||
* or if reported temperature is below signed limit.
|
||||
*/
|
||||
if (!channel || (regvalh & 0x80) || regvalh < 0x7f) {
|
||||
*val = temp_from_reg_signed(regvalh, regvall);
|
||||
if (!channel || (regvals[1] & 0x80) || regvals[1] < 0x7f) {
|
||||
*val = temp_from_reg_signed(regvals[1], regvals[0]);
|
||||
return 0;
|
||||
}
|
||||
ret = regmap_read(regmap, LM95245_REG_R_REMOTE_TEMPL_U,
|
||||
®vall);
|
||||
if (ret < 0)
|
||||
ret = regmap_bulk_read(regmap, LM95245_REG_R_REMOTE_TEMPH_U, regvals, 2);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = regmap_read(regmap, LM95245_REG_R_REMOTE_TEMPH_U,
|
||||
®valh);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = temp_from_reg_unsigned(regvalh, regvall);
|
||||
*val = temp_from_reg_unsigned(regvals[0], regvals[1]);
|
||||
return 0;
|
||||
case hwmon_temp_max:
|
||||
ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OS_LIMIT,
|
||||
®valh);
|
||||
®val);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = regvalh * 1000;
|
||||
*val = regval * 1000;
|
||||
return 0;
|
||||
case hwmon_temp_crit:
|
||||
regh = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT :
|
||||
LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT;
|
||||
ret = regmap_read(regmap, regh, ®valh);
|
||||
regs[0] = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT :
|
||||
LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT;
|
||||
ret = regmap_read(regmap, regs[0], ®val);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = regvalh * 1000;
|
||||
*val = regval * 1000;
|
||||
return 0;
|
||||
case hwmon_temp_max_hyst:
|
||||
ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OS_LIMIT,
|
||||
®valh);
|
||||
regs[0] = LM95245_REG_RW_REMOTE_OS_LIMIT;
|
||||
regs[1] = LM95245_REG_RW_COMMON_HYSTERESIS;
|
||||
ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
ret = regmap_read(regmap, LM95245_REG_RW_COMMON_HYSTERESIS,
|
||||
®vall);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = (regvalh - regvall) * 1000;
|
||||
*val = (regvals[0] - regvals[1]) * 1000;
|
||||
return 0;
|
||||
case hwmon_temp_crit_hyst:
|
||||
regh = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT :
|
||||
LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT;
|
||||
ret = regmap_read(regmap, regh, ®valh);
|
||||
regs[0] = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT :
|
||||
LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT;
|
||||
regs[1] = LM95245_REG_RW_COMMON_HYSTERESIS;
|
||||
|
||||
ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
ret = regmap_read(regmap, LM95245_REG_RW_COMMON_HYSTERESIS,
|
||||
®vall);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = (regvalh - regvall) * 1000;
|
||||
*val = (regvals[0] - regvals[1]) * 1000;
|
||||
return 0;
|
||||
case hwmon_temp_type:
|
||||
ret = regmap_read(regmap, LM95245_REG_RW_CONFIG2, ®valh);
|
||||
ret = regmap_read(regmap, LM95245_REG_RW_CONFIG2, ®val);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = (regvalh & CFG2_REMOTE_TT) ? 1 : 2;
|
||||
*val = (regval & CFG2_REMOTE_TT) ? 1 : 2;
|
||||
return 0;
|
||||
case hwmon_temp_offset:
|
||||
ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OFFL,
|
||||
®vall);
|
||||
ret = regmap_bulk_read(regmap, LM95245_REG_RW_REMOTE_OFFH, regvals, 2);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OFFH,
|
||||
®valh);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = temp_from_reg_signed(regvalh, regvall);
|
||||
*val = temp_from_reg_signed(regvals[0], regvals[1]);
|
||||
return 0;
|
||||
case hwmon_temp_max_alarm:
|
||||
ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®valh);
|
||||
ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®val);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = !!(regvalh & STATUS1_ROS);
|
||||
*val = !!(regval & STATUS1_ROS);
|
||||
return 0;
|
||||
case hwmon_temp_crit_alarm:
|
||||
ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®valh);
|
||||
ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®val);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = !!(regvalh & (channel ? STATUS1_RTCRIT : STATUS1_LOC));
|
||||
*val = !!(regval & (channel ? STATUS1_RTCRIT : STATUS1_LOC));
|
||||
return 0;
|
||||
case hwmon_temp_fault:
|
||||
ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®valh);
|
||||
ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®val);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*val = !!(regvalh & STATUS1_DIODE_FAULT);
|
||||
*val = !!(regval & STATUS1_DIODE_FAULT);
|
||||
return 0;
|
||||
default:
|
||||
return -EOPNOTSUPP;
|
||||
@ -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 regmap *regmap = data->regmap;
|
||||
unsigned int regval;
|
||||
u8 regvals[2];
|
||||
int ret, reg;
|
||||
|
||||
switch (attr) {
|
||||
@ -311,16 +297,10 @@ static int lm95245_write_temp(struct device *dev, u32 attr, int channel,
|
||||
case hwmon_temp_offset:
|
||||
val = clamp_val(val, -128000, 127875);
|
||||
val = val * 256 / 1000;
|
||||
mutex_lock(&data->update_lock);
|
||||
ret = regmap_write(regmap, LM95245_REG_RW_REMOTE_OFFL,
|
||||
val & 0xe0);
|
||||
if (ret < 0) {
|
||||
mutex_unlock(&data->update_lock);
|
||||
return ret;
|
||||
}
|
||||
ret = regmap_write(regmap, LM95245_REG_RW_REMOTE_OFFH,
|
||||
(val >> 8) & 0xff);
|
||||
mutex_unlock(&data->update_lock);
|
||||
regvals[0] = val >> 8;
|
||||
regvals[1] = val & 0xe0;
|
||||
|
||||
ret = regmap_bulk_write(regmap, LM95245_REG_RW_REMOTE_OFFH, regvals, 2);
|
||||
return ret;
|
||||
case hwmon_temp_type:
|
||||
if (val != 1 && val != 2)
|
||||
|
Loading…
Reference in New Issue
Block a user