hwmon: (max31827) Update bits with shutdown_write()
authorDaniel Matyas <daniel.matyas@analog.com>
Tue, 31 Oct 2023 18:21:55 +0000 (20:21 +0200)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 11 Dec 2023 14:42:50 +0000 (06:42 -0800)
Added 'mask' parameter to the shutdown_write() function. Now it can
either write or update bits, depending on the value of mask. This is
needed, because for alarms a write is necessary, but for resolution only
the resolution bits should be updated.

Signed-off-by: Daniel Matyas <daniel.matyas@analog.com>
Link: https://lore.kernel.org/r/20231031182158.124608-3-daniel.matyas@analog.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/max31827.c

index e42d5bce8a577422c35d6f3ab025adc5a11211bf..3b38fdf0ebb2dfa363eb9d331e6bac3787c88c6c 100644 (file)
@@ -81,7 +81,7 @@ static const struct regmap_config max31827_regmap = {
 };
 
 static int shutdown_write(struct max31827_state *st, unsigned int reg,
-                         unsigned int val)
+                         unsigned int mask, unsigned int val)
 {
        unsigned int cfg;
        unsigned int cnv_rate;
@@ -98,7 +98,10 @@ static int shutdown_write(struct max31827_state *st, unsigned int reg,
        mutex_lock(&st->lock);
 
        if (!st->enable) {
-               ret = regmap_write(st->regmap, reg, val);
+               if (!mask)
+                       ret = regmap_write(st->regmap, reg, val);
+               else
+                       ret = regmap_update_bits(st->regmap, reg, mask, val);
                goto unlock;
        }
 
@@ -113,7 +116,11 @@ static int shutdown_write(struct max31827_state *st, unsigned int reg,
        if (ret)
                goto unlock;
 
-       ret = regmap_write(st->regmap, reg, val);
+       if (!mask)
+               ret = regmap_write(st->regmap, reg, val);
+       else
+               ret = regmap_update_bits(st->regmap, reg, mask, val);
+
        if (ret)
                goto unlock;
 
@@ -131,7 +138,7 @@ static int write_alarm_val(struct max31827_state *st, unsigned int reg,
 {
        val = MAX31827_M_DGR_TO_16_BIT(val);
 
-       return shutdown_write(st, reg, val);
+       return shutdown_write(st, reg, 0, val);
 }
 
 static umode_t max31827_is_visible(const void *state,