From owner-svn-src-head@freebsd.org Mon Aug 14 00:00:25 2017 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 B56A5DB6669; Mon, 14 Aug 2017 00:00:25 +0000 (UTC) (envelope-from ian@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 8FB6A639B9; Mon, 14 Aug 2017 00:00:25 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v7E00Osu038095; Mon, 14 Aug 2017 00:00:24 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7E00OFJ038092; Mon, 14 Aug 2017 00:00:24 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201708140000.v7E00OFJ038092@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 14 Aug 2017 00:00:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r322477 - in head/sys: dev/iicbus modules/i2c modules/i2c/s35390a X-SVN-Group: head X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in head/sys: dev/iicbus modules/i2c modules/i2c/s35390a X-SVN-Commit-Revision: 322477 X-SVN-Commit-Repository: base 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: Mon, 14 Aug 2017 00:00:25 -0000 Author: ian Date: Mon Aug 14 00:00:24 2017 New Revision: 322477 URL: https://svnweb.freebsd.org/changeset/base/322477 Log: Minor fixes and enhancements for the s35390a i2c RTC driver... - Add FDT probe code. - Do i2c transfers with exclusive bus ownership. - Use config_intrhook_oneshot() to defer chip setup because some i2c busses can't do transfers without interrupts. - Add a detach() routine. - Add to module build. Added: head/sys/modules/i2c/s35390a/ head/sys/modules/i2c/s35390a/Makefile (contents, props changed) Modified: head/sys/dev/iicbus/s35390a.c head/sys/modules/i2c/Makefile Modified: head/sys/dev/iicbus/s35390a.c ============================================================================== --- head/sys/dev/iicbus/s35390a.c Sun Aug 13 22:07:42 2017 (r322476) +++ head/sys/dev/iicbus/s35390a.c Mon Aug 14 00:00:24 2017 (r322477) @@ -59,6 +59,8 @@ __FBSDID("$FreeBSD$"); * Driver for Seiko Instruments S-35390A Real-time Clock */ +#include "opt_platform.h" + #include #include #include @@ -69,6 +71,12 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef FDT +#include +#include +#include +#endif + #include "clock_if.h" #include "iicbus_if.h" @@ -159,7 +167,7 @@ s390rtc_read(device_t dev, uint8_t reg, uint8_t *buf, int i; int error; - error = iicbus_transfer(dev, msg, 1); + error = iicbus_transfer_excl(dev, msg, 1, IIC_WAIT); if (error) return (error); @@ -188,13 +196,20 @@ s390rtc_write(device_t dev, uint8_t reg, uint8_t *buf, for (i = 0; i < len; ++i) buf[i] = bitreverse(buf[i]); - return (iicbus_transfer(dev, msg, 1)); + return (iicbus_transfer_excl(dev, msg, 1, IIC_WAIT)); } static int s390rtc_probe(device_t dev) { +#ifdef FDT + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (!ofw_bus_is_compatible(dev, "sii,s35390a")) + return (ENXIO); +#else if (iicbus_get_addr(dev) != S390_ADDR) { if (bootverbose) device_printf(dev, "slave address mismatch. " @@ -202,35 +217,35 @@ s390rtc_probe(device_t dev) S390_ADDR); return (ENXIO); } - device_set_desc(dev, "Seiko Instruments S-35390A Real-time Clock"); +#endif + device_set_desc(dev, "Seiko Instruments S-35390A RTC"); - return (BUS_PROBE_SPECIFIC); + return (BUS_PROBE_DEFAULT); } -static int -s390rtc_attach(device_t dev) +static void +s390rtc_start(void *arg) { - struct s390rtc_softc *sc; + device_t dev; uint8_t reg; int error; - sc = device_get_softc(dev); - sc->sc_dev = dev; - sc->sc_addr = iicbus_get_addr(dev); + dev = arg; /* Reset the chip and turn on 24h mode, after power-off or battery. */ error = s390rtc_read(dev, S390_STATUS1, ®, 1); if (error) { device_printf(dev, "%s: cannot read status1 register\n", __func__); - return (error); + return; } if (reg & (S390_ST1_POC | S390_ST1_BLD)) { reg |= S390_ST1_24H | S390_ST1_RESET; error = s390rtc_write(dev, S390_STATUS1, ®, 1); if (error) { - device_printf(dev, "%s: cannot initialize\n", __func__); - return (error); + device_printf(dev, + "%s: cannot initialize\n", __func__); + return; } } @@ -239,7 +254,7 @@ s390rtc_attach(device_t dev) if (error) { device_printf(dev, "%s: cannot read status2 register\n", __func__); - return (error); + return; } if (reg & S390_ST2_TEST) { reg &= ~S390_ST2_TEST; @@ -247,15 +262,36 @@ s390rtc_attach(device_t dev) if (error) { device_printf(dev, "%s: cannot disable the test mode\n", __func__); - return (error); + return; } } clock_register(dev, 1000000); /* 1 second resolution */ +} + +static int +s390rtc_attach(device_t dev) +{ + struct s390rtc_softc *sc; + + sc = device_get_softc(dev); + sc->sc_dev = dev; + sc->sc_addr = iicbus_get_addr(dev); + + config_intrhook_oneshot(s390rtc_start, dev); + return (0); } static int +s390rtc_detach(device_t dev) +{ + + clock_unregister(dev); + return (0); +} + +static int s390rtc_gettime(device_t dev, struct timespec *ts) { uint8_t bcd[S390_RT1_NBYTES]; @@ -310,6 +346,7 @@ s390rtc_settime(device_t dev, struct timespec *ts) static device_method_t s390rtc_methods[] = { DEVMETHOD(device_probe, s390rtc_probe), DEVMETHOD(device_attach, s390rtc_attach), + DEVMETHOD(device_detach, s390rtc_detach), DEVMETHOD(clock_gettime, s390rtc_gettime), DEVMETHOD(clock_settime, s390rtc_settime), Modified: head/sys/modules/i2c/Makefile ============================================================================== --- head/sys/modules/i2c/Makefile Sun Aug 13 22:07:42 2017 (r322476) +++ head/sys/modules/i2c/Makefile Mon Aug 14 00:00:24 2017 (r322477) @@ -15,6 +15,7 @@ SUBDIR = \ isl12xx \ jedec_ts \ nxprtc \ + s35390a \ smb \ smbus \ Added: head/sys/modules/i2c/s35390a/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/modules/i2c/s35390a/Makefile Mon Aug 14 00:00:24 2017 (r322477) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +.PATH: ${SRCTOP}/sys/dev/iicbus +KMOD = s35390a +SRCS = s35390a.c bus_if.h clock_if.h device_if.h iicbus_if.h ofw_bus_if.h + +.include