From owner-svn-src-head@freebsd.org Tue Feb 16 11:51:55 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D916CAA9505; Tue, 16 Feb 2016 11:51:55 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9224A1D12; Tue, 16 Feb 2016 11:51:55 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u1GBpsTZ080736; Tue, 16 Feb 2016 11:51:54 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u1GBpsfU080735; Tue, 16 Feb 2016 11:51:54 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201602161151.u1GBpsfU080735@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Tue, 16 Feb 2016 11:51:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r295658 - head/sys/arm/allwinner X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Feb 2016 11:51:55 -0000 Author: andrew Date: Tue Feb 16 11:51:54 2016 New Revision: 295658 URL: https://svnweb.freebsd.org/changeset/base/295658 Log: Add a sysctl to read the internal temperature of the AXP209 Power Management IC. Submitted by: Jared McNeill Differential Revision: https://reviews.freebsd.org/D5298 Modified: head/sys/arm/allwinner/axp209.c Modified: head/sys/arm/allwinner/axp209.c ============================================================================== --- head/sys/arm/allwinner/axp209.c Tue Feb 16 11:45:46 2016 (r295657) +++ head/sys/arm/allwinner/axp209.c Tue Feb 16 11:51:54 2016 (r295658) @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -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, 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); }