summaryrefslogtreecommitdiff
path: root/drivers/hwmon/lm95234.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2024-07-10 17:37:54 -0700
committerGuenter Roeck <linux@roeck-us.net>2024-07-31 10:43:52 -0700
commit3ec621cd6fcac82c1d8b3a40f774cd984a7fe55b (patch)
treefcd561f69658b6bda4af1e764f45812694a80bec /drivers/hwmon/lm95234.c
parent280220236bf53a6eaa3c53653b649366228c4689 (diff)
hwmon: (lm95234) Use multi-byte regmap operations
Use multi-byte regmap operations to simplify the code and to reduce dependency on locking. No functional change. Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/lm95234.c')
-rw-r--r--drivers/hwmon/lm95234.c45
1 files changed, 18 insertions, 27 deletions
diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c
index d3d4b1d82899..7da6c8f07332 100644
--- a/drivers/hwmon/lm95234.c
+++ b/drivers/hwmon/lm95234.c
@@ -60,54 +60,45 @@ struct lm95234_data {
static int lm95234_read_temp(struct regmap *regmap, int index, long *t)
{
+ unsigned int regs[2];
int temp = 0, ret;
- u32 val;
+ u8 regvals[2];
if (index) {
- ret = regmap_read(regmap, LM95234_REG_UTEMPH(index - 1), &val);
+ regs[0] = LM95234_REG_UTEMPH(index - 1);
+ regs[1] = LM95234_REG_UTEMPL(index - 1);
+ ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
if (ret)
return ret;
- temp = val << 8;
- ret = regmap_read(regmap, LM95234_REG_UTEMPL(index - 1), &val);
- if (ret)
- return ret;
- temp |= val;
+ temp = (regvals[0] << 8) | regvals[1];
}
/*
* Read signed temperature if unsigned temperature is 0,
* or if this is the local sensor.
*/
if (!temp) {
- ret = regmap_read(regmap, LM95234_REG_TEMPH(index), &val);
+ regs[0] = LM95234_REG_TEMPH(index);
+ regs[1] = LM95234_REG_TEMPL(index);
+ ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
if (ret)
return ret;
- temp = val << 8;
- ret = regmap_read(regmap, LM95234_REG_TEMPL(index), &val);
- if (ret)
- return ret;
- temp = sign_extend32(temp | val, 15);
+ temp = (regvals[0] << 8) | regvals[1];
+ temp = sign_extend32(temp, 15);
}
*t = DIV_ROUND_CLOSEST(temp * 125, 32);
return 0;
}
-static int lm95234_hyst_get(struct lm95234_data *data, int reg, long *val)
+static int lm95234_hyst_get(struct regmap *regmap, int reg, long *val)
{
- u32 thyst, tcrit;
+ unsigned int regs[2] = {reg, LM95234_REG_TCRIT_HYST};
+ u8 regvals[2];
int ret;
- mutex_lock(&data->update_lock);
- ret = regmap_read(data->regmap, reg, &tcrit);
- if (ret)
- goto unlock;
- ret = regmap_read(data->regmap, LM95234_REG_TCRIT_HYST, &thyst);
-unlock:
- mutex_unlock(&data->update_lock);
+ ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
if (ret)
return ret;
-
- /* Result can be negative, so be careful with unsigned operands */
- *val = ((int)tcrit - (int)thyst) * 1000;
+ *val = (regvals[0] - regvals[1]) * 1000;
return 0;
}
@@ -209,7 +200,7 @@ static int lm95234_temp_read(struct device *dev, u32 attr, int channel, long *va
*val = !!(regval & BIT(channel));
break;
case hwmon_temp_crit_hyst:
- return lm95234_hyst_get(data, LM95234_REG_TCRIT1(channel), val);
+ return lm95234_hyst_get(regmap, LM95234_REG_TCRIT1(channel), val);
case hwmon_temp_type:
ret = regmap_read(regmap, LM95234_REG_REM_MODEL, &regval);
if (ret)
@@ -236,7 +227,7 @@ static int lm95234_temp_read(struct device *dev, u32 attr, int channel, long *va
*val = regval * 1000;
break;
case hwmon_temp_max_hyst:
- return lm95234_hyst_get(data, lm95234_crit_reg(channel), val);
+ return lm95234_hyst_get(regmap, lm95234_crit_reg(channel), val);
case hwmon_temp_crit:
ret = regmap_read(regmap, LM95234_REG_TCRIT1(channel), &regval);
if (ret)