diff options
author | Guenter Roeck <linux@roeck-us.net> | 2021-12-23 06:03:04 +0300 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2022-02-28 04:03:16 +0300 |
commit | 362c5663e8760b145a67adb3a7704de401f6ceab (patch) | |
tree | 79ba9631f16588deb7ed6743ea2be59fa338c8bf | |
parent | 719af4f1a40bdf46cab7e4db216af7084a70897b (diff) | |
download | linux-362c5663e8760b145a67adb3a7704de401f6ceab.tar.xz |
hwmon: (lm83) Replace temperature conversion macros with standard functions
Replace TEMP_FROM_REG with direct calculation and TEMP_TO_REG
with standard functions/macros.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/lm83.c | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c index c9605957e400..434bd5b903d2 100644 --- a/drivers/hwmon/lm83.c +++ b/drivers/hwmon/lm83.c @@ -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; } |