Skip to content

Commit 6a81578

Browse files
committed
hwmon: (emc1403) Add support for conversion interval configuration
The chips supported by the emc1403 driver support configurable conversion rates. Add support for it. Cc: Lars Petter Mostad <[email protected]> Tested-by: Lars Petter Mostad <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent e77b204 commit 6a81578

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

drivers/hwmon/emc1403.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/sysfs.h>
2020
#include <linux/mutex.h>
2121
#include <linux/regmap.h>
22+
#include <linux/util_macros.h>
2223

2324
#define THERMAL_PID_REG 0xfd
2425
#define THERMAL_SMSC_ID_REG 0xfe
@@ -333,6 +334,31 @@ static int emc1403_temp_read(struct thermal_data *data, u32 attr, int channel, l
333334
return ret;
334335
}
335336

337+
static int emc1403_get_convrate(struct thermal_data *data, long *val)
338+
{
339+
unsigned int convrate;
340+
int ret;
341+
342+
ret = regmap_read(data->regmap, 0x04, &convrate);
343+
if (ret < 0)
344+
return ret;
345+
if (convrate > 10)
346+
convrate = 4;
347+
348+
*val = 16000 >> convrate;
349+
return 0;
350+
}
351+
352+
static int emc1403_chip_read(struct thermal_data *data, u32 attr, long *val)
353+
{
354+
switch (attr) {
355+
case hwmon_chip_update_interval:
356+
return emc1403_get_convrate(data, val);
357+
default:
358+
return -EOPNOTSUPP;
359+
}
360+
}
361+
336362
static int emc1403_read(struct device *dev, enum hwmon_sensor_types type,
337363
u32 attr, int channel, long *val)
338364
{
@@ -341,6 +367,8 @@ static int emc1403_read(struct device *dev, enum hwmon_sensor_types type,
341367
switch (type) {
342368
case hwmon_temp:
343369
return emc1403_temp_read(data, attr, channel, val);
370+
case hwmon_chip:
371+
return emc1403_chip_read(data, attr, val);
344372
default:
345373
return -EOPNOTSUPP;
346374
}
@@ -409,6 +437,30 @@ static int emc1403_temp_write(struct thermal_data *data, u32 attr, int channel,
409437
}
410438
}
411439

440+
/* Lookup table for temperature conversion times in msec */
441+
static const u16 ina3221_conv_time[] = {
442+
16000, 8000, 4000, 2000, 1000, 500, 250, 125, 62, 31, 16
443+
};
444+
445+
static int emc1403_set_convrate(struct thermal_data *data, unsigned int interval)
446+
{
447+
int convrate;
448+
449+
convrate = find_closest_descending(interval, ina3221_conv_time,
450+
ARRAY_SIZE(ina3221_conv_time));
451+
return regmap_write(data->regmap, 0x04, convrate);
452+
}
453+
454+
static int emc1403_chip_write(struct thermal_data *data, u32 attr, long val)
455+
{
456+
switch (attr) {
457+
case hwmon_chip_update_interval:
458+
return emc1403_set_convrate(data, clamp_val(val, 0, 100000));
459+
default:
460+
return -EOPNOTSUPP;
461+
}
462+
}
463+
412464
static int emc1403_write(struct device *dev, enum hwmon_sensor_types type,
413465
u32 attr, int channel, long val)
414466
{
@@ -417,6 +469,8 @@ static int emc1403_write(struct device *dev, enum hwmon_sensor_types type,
417469
switch (type) {
418470
case hwmon_temp:
419471
return emc1403_temp_write(data, attr, channel, val);
472+
case hwmon_chip:
473+
return emc1403_chip_write(data, attr, val);
420474
default:
421475
return -EOPNOTSUPP;
422476
}
@@ -453,18 +507,31 @@ static umode_t emc1403_temp_is_visible(const void *_data, u32 attr, int channel)
453507
}
454508
}
455509

510+
static umode_t emc1403_chip_is_visible(const void *_data, u32 attr)
511+
{
512+
switch (attr) {
513+
case hwmon_chip_update_interval:
514+
return 0644;
515+
default:
516+
return 0;
517+
}
518+
}
519+
456520
static umode_t emc1403_is_visible(const void *data, enum hwmon_sensor_types type,
457521
u32 attr, int channel)
458522
{
459523
switch (type) {
460524
case hwmon_temp:
461525
return emc1403_temp_is_visible(data, attr, channel);
526+
case hwmon_chip:
527+
return emc1403_chip_is_visible(data, attr);
462528
default:
463529
return 0;
464530
}
465531
}
466532

467533
static const struct hwmon_channel_info * const emc1403_info[] = {
534+
HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL),
468535
HWMON_CHANNEL_INFO(temp,
469536
HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX |
470537
HWMON_T_CRIT | HWMON_T_MIN_HYST | HWMON_T_MAX_HYST |

0 commit comments

Comments
 (0)