Skip to content

Commit e77b204

Browse files
committed
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@appear.net> Tested-by: Lars Petter Mostad <lars.petter.mostad@appear.net> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 1094360 commit e77b204

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

drivers/hwmon/emc1403.c

+52-3
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,52 @@ static u8 emc1403_temp_regs[][4] = {
178178
},
179179
};
180180

181+
static s8 emc1403_temp_regs_low[][4] = {
182+
[0] = {
183+
[temp_min] = -1,
184+
[temp_max] = -1,
185+
[temp_crit] = -1,
186+
[temp_input] = 0x29,
187+
},
188+
[1] = {
189+
[temp_min] = 0x14,
190+
[temp_max] = 0x13,
191+
[temp_crit] = -1,
192+
[temp_input] = 0x10,
193+
},
194+
[2] = {
195+
[temp_min] = 0x18,
196+
[temp_max] = 0x17,
197+
[temp_crit] = -1,
198+
[temp_input] = 0x24,
199+
},
200+
[3] = {
201+
[temp_min] = 0x2f,
202+
[temp_max] = 0x2e,
203+
[temp_crit] = -1,
204+
[temp_input] = 0x2b,
205+
},
206+
};
207+
181208
static int __emc1403_get_temp(struct thermal_data *data, int channel,
182209
enum emc1403_reg_map map, long *val)
183210
{
184211
unsigned int regval;
185212
int ret;
213+
s8 reg;
186214

187215
ret = regmap_read(data->regmap, emc1403_temp_regs[channel][map], &regval);
188216
if (ret < 0)
189217
return ret;
190218
*val = regval * 1000;
191219

220+
reg = emc1403_temp_regs_low[channel][map];
221+
if (reg >= 0) {
222+
ret = regmap_read(data->regmap, reg, &regval);
223+
if (ret < 0)
224+
return ret;
225+
*val += (regval >> 5) * 125;
226+
}
192227
return 0;
193228
}
194229

@@ -336,12 +371,26 @@ static int emc1403_set_temp(struct thermal_data *data, int channel,
336371
{
337372
unsigned int regval;
338373
int ret;
374+
u8 regh;
375+
s8 regl;
339376

340-
val = clamp_val(val, 0, 255000);
377+
regh = emc1403_temp_regs[channel][map];
378+
regl = emc1403_temp_regs_low[channel][map];
341379

342380
mutex_lock(&data->mutex);
343-
regval = DIV_ROUND_CLOSEST(val, 1000);
344-
ret = regmap_write(data->regmap, emc1403_temp_regs[channel][map], regval);
381+
if (regl >= 0) {
382+
val = clamp_val(val, 0, 255875);
383+
regval = DIV_ROUND_CLOSEST(val, 125);
384+
ret = regmap_write(data->regmap, regh, regval >> 3);
385+
if (ret < 0)
386+
goto unlock;
387+
ret = regmap_write(data->regmap, regl, (regval & 0x07) << 5);
388+
} else {
389+
val = clamp_val(val, 0, 255000);
390+
regval = DIV_ROUND_CLOSEST(val, 1000);
391+
ret = regmap_write(data->regmap, regh, regval);
392+
}
393+
unlock:
345394
mutex_unlock(&data->mutex);
346395
return ret;
347396
}

0 commit comments

Comments
 (0)