]> git.ipfire.org Git - people/ms/linux.git/commitdiff
hwmon: (lm83) Replace temperature conversion macros with standard functions
authorGuenter Roeck <linux@roeck-us.net>
Thu, 23 Dec 2021 03:03:04 +0000 (19:03 -0800)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 28 Feb 2022 01:03:16 +0000 (17:03 -0800)
Replace TEMP_FROM_REG with direct calculation and TEMP_TO_REG
with standard functions/macros.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/lm83.c

index c9605957e400e1967c75935e357854dc44dc9c09..434bd5b903d2a6622ae50266fbdc06d5b2b988dc 100644 (file)
@@ -66,17 +66,6 @@ enum chips { lm83, lm82 };
 #define LM83_REG_R_TCRIT               0x42
 #define LM83_REG_W_TCRIT               0x5A
 
-/*
- * Conversions and various macros
- * The LM83 uses signed 8-bit values with LSB = 1 degree Celsius.
- */
-
-#define TEMP_FROM_REG(val)     ((val) * 1000)
-#define TEMP_TO_REG(val)       ((val) <= -128000 ? -128 : \
-                                (val) >= 127000 ? 127 : \
-                                (val) < 0 ? ((val) - 500) / 1000 : \
-                                ((val) + 500) / 1000)
-
 static const u8 LM83_REG_TEMP[] = {
        LM83_REG_R_LOCAL_TEMP,
        LM83_REG_R_REMOTE1_TEMP,
@@ -181,7 +170,7 @@ static ssize_t temp_show(struct device *dev, struct device_attribute *devattr,
        if (ret)
                return ret;
 
-       return sprintf(buf, "%d\n", TEMP_FROM_REG((s8)regval));
+       return sprintf(buf, "%d\n", (s8)regval * 1000);
 }
 
 static ssize_t temp_store(struct device *dev,
@@ -198,7 +187,7 @@ static ssize_t temp_store(struct device *dev,
        if (err < 0)
                return err;
 
-       regval = TEMP_TO_REG(val);
+       regval = DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000);
        err = regmap_write(data->regmap, LM83_REG_TEMP[attr->index], regval);
        return err ? : count;
 }