[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240503154324.517246-3-linux@roeck-us.net>
Date: Fri, 3 May 2024 08:43:23 -0700
From: Guenter Roeck <linux@...ck-us.net>
To: linux-hwmon@...r.kernel.org
Cc: linux-kernel@...r.kernel.org,
Guenter Roeck <linux@...ck-us.net>,
Lars Petter Mostad <lars.petter.mostad@...ear.net>
Subject: [PATCH v2 2/3] hwmon: (emc1403) Support 11 bit accuracy
Various temperature and limit registers support 11 bit accuracy.
Add support for it.
Cc: Lars Petter Mostad <lars.petter.mostad@...ear.net>
Signed-off-by: Guenter Roeck <linux@...ck-us.net>
---
v2: Added patch
drivers/hwmon/emc1403.c | 55 ++++++++++++++++++++++++++++++++++++++---
1 file changed, 52 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c
index e656f0432a57..e53bb4d8bc1b 100644
--- a/drivers/hwmon/emc1403.c
+++ b/drivers/hwmon/emc1403.c
@@ -178,17 +178,52 @@ static u8 emc1403_temp_regs[][4] = {
},
};
+static s8 emc1403_temp_regs_low[][4] = {
+ [0] = {
+ [temp_min] = -1,
+ [temp_max] = -1,
+ [temp_crit] = -1,
+ [temp_input] = 0x29,
+ },
+ [1] = {
+ [temp_min] = 0x14,
+ [temp_max] = 0x13,
+ [temp_crit] = -1,
+ [temp_input] = 0x10,
+ },
+ [2] = {
+ [temp_min] = 0x18,
+ [temp_max] = 0x17,
+ [temp_crit] = -1,
+ [temp_input] = 0x24,
+ },
+ [3] = {
+ [temp_min] = 0x2f,
+ [temp_max] = 0x2e,
+ [temp_crit] = -1,
+ [temp_input] = 0x2b,
+ },
+};
+
static int __emc1403_get_temp(struct thermal_data *data, int channel,
enum emc1403_reg_map map, long *val)
{
unsigned int regval;
int ret;
+ s8 reg;
ret = regmap_read(data->regmap, emc1403_temp_regs[channel][map], ®val);
if (ret < 0)
return ret;
*val = regval * 1000;
+ reg = emc1403_temp_regs_low[channel][map];
+ if (reg >= 0) {
+ ret = regmap_read(data->regmap, reg, ®val);
+ if (ret < 0)
+ return ret;
+ *val += (regval >> 5) * 125;
+ }
return 0;
}
@@ -336,12 +371,26 @@ static int emc1403_set_temp(struct thermal_data *data, int channel,
{
unsigned int regval;
int ret;
+ u8 regh;
+ s8 regl;
- val = clamp_val(val, 0, 255000);
+ regh = emc1403_temp_regs[channel][map];
+ regl = emc1403_temp_regs_low[channel][map];
mutex_lock(&data->mutex);
- regval = DIV_ROUND_CLOSEST(val, 1000);
- ret = regmap_write(data->regmap, emc1403_temp_regs[channel][map], regval);
+ if (regl >= 0) {
+ val = clamp_val(val, 0, 255875);
+ regval = DIV_ROUND_CLOSEST(val, 125);
+ ret = regmap_write(data->regmap, regh, regval >> 3);
+ if (ret < 0)
+ goto unlock;
+ ret = regmap_write(data->regmap, regl, (regval & 0x07) << 5);
+ } else {
+ val = clamp_val(val, 0, 255000);
+ regval = DIV_ROUND_CLOSEST(val, 1000);
+ ret = regmap_write(data->regmap, regh, regval);
+ }
+unlock:
mutex_unlock(&data->mutex);
return ret;
}
--
2.39.2
Powered by blists - more mailing lists