diff options
author | andrew <andrew@FreeBSD.org> | 2016-02-16 11:51:54 +0000 |
---|---|---|
committer | andrew <andrew@FreeBSD.org> | 2016-02-16 11:51:54 +0000 |
commit | 6d3e4032b7ddd93d54912c3a73b2d5b7dc65e791 (patch) | |
tree | 18de6120a69f85332bba309ec068f2fc4c6d7c42 /sys/arm | |
parent | 6c6cf5cd1a1472d5aef2d6fdd1301e3397e6965f (diff) | |
download | FreeBSD-src-6d3e4032b7ddd93d54912c3a73b2d5b7dc65e791.zip FreeBSD-src-6d3e4032b7ddd93d54912c3a73b2d5b7dc65e791.tar.gz |
Add a sysctl to read the internal temperature of the AXP209 Power
Management IC.
Submitted by: Jared McNeill <jmcneill@invisible.ca>
Differential Revision: https://reviews.freebsd.org/D5298
Diffstat (limited to 'sys/arm')
-rw-r--r-- | sys/arm/allwinner/axp209.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/sys/arm/allwinner/axp209.c b/sys/arm/allwinner/axp209.c index 1ede8e8..3a9753f 100644 --- a/sys/arm/allwinner/axp209.c +++ b/sys/arm/allwinner/axp209.c @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include <sys/reboot.h> #include <sys/resource.h> #include <sys/rman.h> +#include <sys/sysctl.h> #include <dev/iicbus/iicbus.h> #include <dev/iicbus/iiconf.h> @@ -62,11 +63,23 @@ __FBSDID("$FreeBSD$"); #define AXP209_SHUTBAT 0x32 #define AXP209_SHUTBAT_SHUTDOWN 0x80 +/* Temperature monitor */ +#define AXP209_TEMPMON 0x5e +#define AXP209_TEMPMON_H(a) ((a) << 4) +#define AXP209_TEMPMON_L(a) ((a) & 0xf) +#define AXP209_TEMPMON_MIN 1447 /* -144.7C */ + +#define AXP209_0C_TO_K 2732 + struct axp209_softc { uint32_t addr; struct intr_config_hook enum_hook; }; +enum axp209_sensor { + AXP209_TEMP +}; + static int axp209_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size) { @@ -104,6 +117,28 @@ axp209_write(device_t dev, uint8_t reg, uint8_t data) return (iicbus_transfer(dev, &msg, 1)); } +static int +axp209_sysctl(SYSCTL_HANDLER_ARGS) +{ + device_t dev = arg1; + enum axp209_sensor sensor = arg2; + uint8_t data[2]; + int val, error; + + if (sensor != AXP209_TEMP) + return (ENOENT); + + error = axp209_read(dev, AXP209_TEMPMON, data, 2); + if (error != 0) + return (error); + + /* Temperature is between -144.7C and 264.8C, step +0.1C */ + val = (AXP209_TEMPMON_H(data[0]) | AXP209_TEMPMON_L(data[1])) - + AXP209_TEMPMON_MIN + AXP209_0C_TO_K; + + return sysctl_handle_opaque(oidp, &val, sizeof(val), req); +} + static void axp209_shutdown(void *devp, int howto) { @@ -163,6 +198,12 @@ axp209_attach(device_t dev) EVENTHANDLER_REGISTER(shutdown_final, axp209_shutdown, dev, SHUTDOWN_PRI_LAST); + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "temp", + CTLTYPE_INT | CTLFLAG_RD, + dev, AXP209_TEMP, axp209_sysctl, "IK", "Internal temperature"); + return (0); } |