Commit ad231314 authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (tmp464) Use multi-byte regmap operations

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

No functional changes.
Reviewed-by: default avatarTzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 4ce612b1
...@@ -147,11 +147,11 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val ...@@ -147,11 +147,11 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val
{ {
struct tmp464_data *data = dev_get_drvdata(dev); struct tmp464_data *data = dev_get_drvdata(dev);
struct regmap *regmap = data->regmap; struct regmap *regmap = data->regmap;
unsigned int regval, regval2; unsigned int regs[2];
unsigned int regval;
u16 regvals[2];
int err = 0; int err = 0;
mutex_lock(&data->update_lock);
switch (attr) { switch (attr) {
case hwmon_temp_max_alarm: case hwmon_temp_max_alarm:
err = regmap_read(regmap, TMP464_THERM_STATUS_REG, &regval); err = regmap_read(regmap, TMP464_THERM_STATUS_REG, &regval);
...@@ -172,26 +172,27 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val ...@@ -172,26 +172,27 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val
* complete. That means we have to cache the value internally * complete. That means we have to cache the value internally
* for one measurement cycle and report the cached value. * for one measurement cycle and report the cached value.
*/ */
mutex_lock(&data->update_lock);
if (!data->valid || time_after(jiffies, data->last_updated + if (!data->valid || time_after(jiffies, data->last_updated +
msecs_to_jiffies(data->update_interval))) { msecs_to_jiffies(data->update_interval))) {
err = regmap_read(regmap, TMP464_REMOTE_OPEN_REG, &regval); err = regmap_read(regmap, TMP464_REMOTE_OPEN_REG, &regval);
if (err < 0) if (err < 0)
break; goto unlock;
data->open_reg = regval; data->open_reg = regval;
data->last_updated = jiffies; data->last_updated = jiffies;
data->valid = true; data->valid = true;
} }
*val = !!(data->open_reg & BIT(channel + 7)); *val = !!(data->open_reg & BIT(channel + 7));
unlock:
mutex_unlock(&data->update_lock);
break; break;
case hwmon_temp_max_hyst: case hwmon_temp_max_hyst:
err = regmap_read(regmap, TMP464_THERM_LIMIT[channel], &regval); regs[0] = TMP464_THERM_LIMIT[channel];
if (err < 0) regs[1] = TMP464_TEMP_HYST_REG;
break; err = regmap_multi_reg_read(regmap, regs, regvals, 2);
err = regmap_read(regmap, TMP464_TEMP_HYST_REG, &regval2);
if (err < 0) if (err < 0)
break; break;
regval -= regval2; *val = temp_from_reg(regvals[0] - regvals[1]);
*val = temp_from_reg(regval);
break; break;
case hwmon_temp_max: case hwmon_temp_max:
err = regmap_read(regmap, TMP464_THERM_LIMIT[channel], &regval); err = regmap_read(regmap, TMP464_THERM_LIMIT[channel], &regval);
...@@ -200,14 +201,12 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val ...@@ -200,14 +201,12 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val
*val = temp_from_reg(regval); *val = temp_from_reg(regval);
break; break;
case hwmon_temp_crit_hyst: case hwmon_temp_crit_hyst:
err = regmap_read(regmap, TMP464_THERM2_LIMIT[channel], &regval); regs[0] = TMP464_THERM2_LIMIT[channel];
if (err < 0) regs[1] = TMP464_TEMP_HYST_REG;
break; err = regmap_multi_reg_read(regmap, regs, regvals, 2);
err = regmap_read(regmap, TMP464_TEMP_HYST_REG, &regval2);
if (err < 0) if (err < 0)
break; break;
regval -= regval2; *val = temp_from_reg(regvals[0] - regvals[1]);
*val = temp_from_reg(regval);
break; break;
case hwmon_temp_crit: case hwmon_temp_crit:
err = regmap_read(regmap, TMP464_THERM2_LIMIT[channel], &regval); err = regmap_read(regmap, TMP464_THERM2_LIMIT[channel], &regval);
...@@ -239,8 +238,6 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val ...@@ -239,8 +238,6 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val
break; break;
} }
mutex_unlock(&data->update_lock);
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