From owner-svn-src-head@freebsd.org Sat Oct 22 08:00:48 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 6B496C1CE2B; Sat, 22 Oct 2016 08:00:48 +0000 (UTC) (envelope-from avg@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 4533AF2E; Sat, 22 Oct 2016 08:00:48 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u9M80lJB017293; Sat, 22 Oct 2016 08:00:47 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u9M80knZ017287; Sat, 22 Oct 2016 08:00:46 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201610220800.u9M80knZ017287@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Sat, 22 Oct 2016 08:00:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r307768 - in head: share/man/man4 sys/conf sys/dev/jedec_ts sys/modules/i2c sys/modules/i2c/jedec_ts 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.23 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: Sat, 22 Oct 2016 08:00:48 -0000 Author: avg Date: Sat Oct 22 08:00:46 2016 New Revision: 307768 URL: https://svnweb.freebsd.org/changeset/base/307768 Log: jedec_ts: a driver for thermal sensors on memory modules The driver currently supports chips that are fully compliant with the JEDEC SPD / EEPROM / TS standard (JEDEC Standard 21-C, TSE2002 Specification, frequenlty referred to as JEDEC JC 42.4). Additionally some chips from STMicroelectronics are supported as well. They are compliant except for their Device ID pattern. Given the continued lack of any common sensor infrastructure, the driver uses an ad-hoc sysctl to report the temperature. Reviewed by: wblock (documentation) MFC after: 2 weeks Relnotes: yes Differential Revision: https://reviews.freebsd.org/D8174 Added: head/share/man/man4/jedec_ts.4 (contents, props changed) head/sys/dev/jedec_ts/ head/sys/dev/jedec_ts/jedec_ts.c (contents, props changed) head/sys/modules/i2c/jedec_ts/ head/sys/modules/i2c/jedec_ts/Makefile (contents, props changed) Modified: head/sys/conf/NOTES head/sys/conf/files head/sys/modules/i2c/Makefile Added: head/share/man/man4/jedec_ts.4 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/share/man/man4/jedec_ts.4 Sat Oct 22 08:00:46 2016 (r307768) @@ -0,0 +1,130 @@ +.\" +.\" Copyright (c) 2016 Andriy Gapon +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd October 13, 2016 +.Dt JEDEC_TS 4 +.Os +.Sh NAME +.Nm jedec_ts +.Nd driver for temperature sensors on memory modules +.Sh SYNOPSIS +.Bd -ragged -offset indent +.Cd "device jedec_ts" +.Cd "device smbus" +.Ed +.Pp +Alternatively, to load the driver as a +module at boot time, place the following line in +.Xr loader.conf 5 : +.Bd -literal -offset indent +jedec_ts_load="YES" +.Ed +.Pp +In +.Pa /boot/device.hints : +.Bd -literal -offset indent +.Cd hint.jedec_ts.0.at="smbus0" +.Cd hint.jedec_ts.0.addr="0x30" +.Cd hint.jedec_ts.1.at="smbus0" +.Cd hint.jedec_ts.1.addr="0x32" +.Cd hint.jedec_ts.2.at="smbus0" +.Cd hint.jedec_ts.2.addr="0x34" +.Cd hint.jedec_ts.3.at="smbus0" +.Cd hint.jedec_ts.3.addr="0x36" +.Cd hint.jedec_ts.4.at="smbus0" +.Cd hint.jedec_ts.4.addr="0x38" +.Cd hint.jedec_ts.5.at="smbus0" +.Cd hint.jedec_ts.5.addr="0x3A" +.Cd hint.jedec_ts.6.at="smbus0" +.Cd hint.jedec_ts.6.addr="0x3C" +.Cd hint.jedec_ts.7.at="smbus0" +.Cd hint.jedec_ts.7.addr="0x3E" +.Ed +.Sh DESCRIPTION +The +.Nm +driver provides access to sensor data over the +.Xr smbus 4 . +The driver supports temperature sensors on memory modules that conform +to JEDEC Standard 21-C, TSE2002 Specification. +.Pp +The access to +.Nm +data is made via the +.Xr sysctl 8 +interface: +.Bl -tag -width "dev.jedec_ts.%d.temp" +.It Va dev.jedec_ts.%d.temp +read-only value of the current temperature read by the sensor. +.El +.Pp +On a system using +.Xr device.hints 5 , +these values are configurable for +.Nm : +.Bl -tag -width "hint.jedec_ts.%d.addr" +.It Va hint.jedec_ts.%d.at +target +.Xr smbus 4 . +.It Va hint.jedec_ts.%d.addr +.Nm +SMBus address on the +.Xr smbus 4 . +.El +.Pp +.Nm +temperature sensors can be wired to eight different addresses, +allowing up to eight sensors on the same +.Xr smbus 4 . +.Pp +If the sensors are on an I2C bus behind an +.Xr iicbus 4 +controller, then the +.Xr iicsmb 4 +bridge driver can be used to attach the +.Xr smbus 4 . +.Sh EXAMPLES +.Ss Sensor read out for two memory modules: +.Bd -literal +dev.jedec_ts.0.temp: 40.2500C +dev.jedec_ts.1.temp: 40.7500C +.Ed +.Sh SEE ALSO +.Xr iicbus 4 , +.Xr iicsmb 4 , +.Xr smbus 4 , +.Xr sysctl 8 +.Sh HISTORY +The +.Nm +driver first appeared in +.Fx 12.0 . +.Sh AUTHORS +.An -nosplit +The +.Nm +driver and this manual page were written by +.An Andriy Gapon Aq Mt avg@FreeBSD.org . Modified: head/sys/conf/NOTES ============================================================================== --- head/sys/conf/NOTES Sat Oct 22 02:37:59 2016 (r307767) +++ head/sys/conf/NOTES Sat Oct 22 08:00:46 2016 (r307768) @@ -2527,7 +2527,12 @@ device ismt device smb +# SMBus peripheral devices # +# jedec_ts Temperature Sensor compliant with JEDEC Standard 21-C +# +device jedec_ts + # I2C Bus # # Philips i2c bus support is provided by the `iicbus' device. Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Sat Oct 22 02:37:59 2016 (r307767) +++ head/sys/conf/files Sat Oct 22 08:00:46 2016 (r307768) @@ -2062,6 +2062,7 @@ dev/ixgbe/ixgbe_dcb_82598.c optional ix compile-with "${NORMAL_C} -I$S/dev/ixgbe" dev/ixgbe/ixgbe_dcb_82599.c optional ix inet | ixv inet \ compile-with "${NORMAL_C} -I$S/dev/ixgbe" +dev/jedec_ts/jedec_ts.c optional jedec_ts smbus dev/jme/if_jme.c optional jme pci dev/joy/joy.c optional joy dev/joy/joy_isa.c optional joy isa Added: head/sys/dev/jedec_ts/jedec_ts.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/jedec_ts/jedec_ts.c Sat Oct 22 08:00:46 2016 (r307768) @@ -0,0 +1,179 @@ +/*- + * Copyright (c) 2016 Andriy Gapon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "smbus_if.h" + + +/* + * SMBus specification defines little-endian byte order, + * but it seems that the JEDEC devices expect it to + * be big-endian. + */ +static int +ts_readw_be(device_t dev, uint8_t reg, uint16_t *val) +{ + device_t bus = device_get_parent(dev); + uint8_t addr = smbus_get_addr(dev); + int err; + + err = smbus_readw(bus, addr, reg, val); + if (err != 0) + return (err); + *val = be16toh(*val); + return (0); +} + +static int +ts_temp_sysctl(SYSCTL_HANDLER_ARGS) +{ + device_t dev = arg1; + int err; + int temp; + uint16_t val; + + err = ts_readw_be(dev, 5, &val); + if (err != 0) + return (EIO); + + /* + * Convert the reading to temperature in 0.0001 Kelvins. + * Three most significant bits are flags, the next + * most significant bit is a sign bit. + * Each step is 0.0625 degrees. + */ + temp = val & 0xfff; + if ((val & 0x1000) != 0) + temp = -temp; + temp = temp * 625 + 2731500; + err = sysctl_handle_int(oidp, &temp, 0, req); + return (err); +} + +static int +ts_probe(device_t dev) +{ + device_set_desc(dev, "DIMM memory sensor"); + return (BUS_PROBE_DEFAULT); +} + +static int +ts_attach(device_t dev) +{ + struct sysctl_ctx_list *ctx; + struct sysctl_oid_list *tree; + int err; + uint16_t vendorid; + uint16_t devid; + uint8_t addr; + + addr = smbus_get_addr(dev); + if ((addr & 0x30) != 0x30) { + /* Up to 8 slave devices starting at 0x30. */ + return (ENXIO); + } + + err = ts_readw_be(dev, 6, &vendorid); + if (err != 0) { + device_printf(dev, "failed to read Manufacturer ID\n"); + return (ENXIO); + } + err = ts_readw_be(dev, 6, &devid); + if (err != 0) { + device_printf(dev, "failed to read Device ID\n"); + return (ENXIO); + } + if ((devid & 0xff00) == 0x2200) { + /* + * Defined by JEDEC Standard No. 21-C, Release 26, + * Page 4.1.6 – 24 + */ + } else if (vendorid == 0x104a) { + /* + * STMicroelectronics datasheets say that + * device ID and revision can vary. + * E.g. STT424E02, Doc ID 13448 Rev 8, + * section 4.6, page 26. + */ + } else { + if (bootverbose) { + device_printf(dev, "Unknown Manufacturer and Device IDs" + ", 0x%x and 0x%x\n", vendorid, devid); + } + return (ENXIO); + } + + ctx = device_get_sysctl_ctx(dev); + tree = SYSCTL_CHILDREN(device_get_sysctl_tree(dev)); + + SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "temp", + CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, 0, + ts_temp_sysctl, "IK4", "Current temperature"); + + return (0); +} + +static int +ts_detach(device_t dev) +{ + return (0); +} + + +static device_method_t jedec_ts_methods[] = { + /* Methods from the device interface */ + DEVMETHOD(device_probe, ts_probe), + DEVMETHOD(device_attach, ts_attach), + DEVMETHOD(device_detach, ts_detach), + + /* Terminate method list */ + { 0, 0 } +}; + +static driver_t jedec_ts_driver = { + "jedec_ts", + jedec_ts_methods, + 0 /* no softc */ +}; + +static devclass_t jedec_ts_devclass; + +DRIVER_MODULE(jedec_ts, smbus, jedec_ts_driver, jedec_ts_devclass, 0, 0); +MODULE_DEPEND(jedec_ts, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER); +MODULE_VERSION(jedec_ts, 1); Modified: head/sys/modules/i2c/Makefile ============================================================================== --- head/sys/modules/i2c/Makefile Sat Oct 22 02:37:59 2016 (r307767) +++ head/sys/modules/i2c/Makefile Sat Oct 22 08:00:46 2016 (r307768) @@ -1,6 +1,6 @@ # $FreeBSD$ SUBDIR = -SUBDIR += controllers if_ic smbus iicbus iicbb iicsmb iic cyapa smb isl +SUBDIR += controllers if_ic smbus iicbus iicbb iicsmb iic cyapa smb isl jedec_ts .include Added: head/sys/modules/i2c/jedec_ts/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/modules/i2c/jedec_ts/Makefile Sat Oct 22 08:00:46 2016 (r307768) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../../dev/jedec_ts +KMOD = jedec_ts +SRCS = jedec_ts.c bus_if.h device_if.h smbus_if.h + +.include