diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-01-23 03:00:01 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-01-23 03:00:01 +0000 |
commit | a091de1afc90058e032f89f47a25ec4a7a8af3ed (patch) | |
tree | f8a2fcb6fccd8f2cede66e8b5b0da7b374cfc64f /sys | |
parent | 77083991ddb93783a12ad1c8e746eea5cd72aae6 (diff) |
Use information from nvmem (provided by sxisid(4)) to calibrate the
temperature sensors.
ok patrick@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/fdt/sxitemp.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/sys/dev/fdt/sxitemp.c b/sys/dev/fdt/sxitemp.c index ab2995602ea..fcb36dd53ce 100644 --- a/sys/dev/fdt/sxitemp.c +++ b/sys/dev/fdt/sxitemp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sxitemp.c,v 1.5 2019/09/21 15:36:57 kettenis Exp $ */ +/* $OpenBSD: sxitemp.c,v 1.6 2020/01/23 03:00:00 kettenis Exp $ */ /* * Copyright (c) 2017 Mark Kettenis <kettenis@openbsd.org> * @@ -43,7 +43,9 @@ #define THS_INT_CTRL_THERMAL_PER(x) (((x) & 0xfffff) << 12) #define THS_FILTER 0x0070 #define THS_FILTER_EN (1 << 2) -#define THS_FILTER_TYPE(x) ((x) & 0x3) +#define THS_FILTER_TYPE(x) ((x) & 0x3) +#define THS0_1_CDATA 0x0074 +#define THS2_CDATA 0x0078 #define THS0_DATA 0x0080 #define THS1_DATA 0x0084 #define THS2_DATA 0x0088 @@ -79,6 +81,7 @@ struct cfdriver sxitemp_cd = { NULL, "sxitemp", DV_DULL }; +void sxitemp_setup_calib(struct sxitemp_softc *, int); uint64_t sxitemp_h3_calc_temp(int64_t); uint64_t sxitemp_r40_calc_temp(int64_t); uint64_t sxitemp_a64_calc_temp(int64_t); @@ -144,6 +147,8 @@ sxitemp_attach(struct device *parent, struct device *self, void *aux) enable = THS_CTRL2_SENSE0_EN | THS_CTRL2_SENSE1_EN; } + sxitemp_setup_calib(sc, node); + /* Start data acquisition. */ HWRITE4(sc, THS_FILTER, THS_FILTER_EN | THS_FILTER_TYPE(1)); HWRITE4(sc, THS_INT_CTRL, THS_INT_CTRL_THERMAL_PER(800)); @@ -183,6 +188,29 @@ sxitemp_attach(struct device *parent, struct device *self, void *aux) thermal_sensor_register(&sc->sc_ts); } +void +sxitemp_setup_calib(struct sxitemp_softc *sc, int node) +{ + uint32_t calib[2]; + bus_size_t size = sizeof(calib); + + /* + * The size of the calibration data depends on the number of + * sensors. Instead of trying to be clever, just try the + * possible sizes. + */ + while (size > 0) { + if (nvmem_read_cell(node, "calibration", &calib, size) == 0) + break; + size -= sizeof(calib[0]); + } + + if (size > 0) + HWRITE4(sc, THS0_1_CDATA, calib[0]); + if (size > 4) + HWRITE4(sc, THS2_CDATA, calib[1]); +} + uint64_t sxitemp_h3_calc_temp(int64_t data) { |