From owner-svn-src-all@freebsd.org Mon Apr 22 05:00:31 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 976E6158F12B; Mon, 22 Apr 2019 05:00:31 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3A5F17160F; Mon, 22 Apr 2019 05:00:31 +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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1608A805C; Mon, 22 Apr 2019 05:00:31 +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 x3M50UUL031155; Mon, 22 Apr 2019 05:00:30 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3M50UQ4031150; Mon, 22 Apr 2019 05:00:30 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904220500.x3M50UQ4031150@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 22 Apr 2019 05:00:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r346526 - in stable/11: share/man/man4/man4.arm sys/arm/freescale/imx sys/modules/imx sys/modules/imx/imx6_snvs X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11: share/man/man4/man4.arm sys/arm/freescale/imx sys/modules/imx sys/modules/imx/imx6_snvs X-SVN-Commit-Revision: 346526 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 3A5F17160F X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.976,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2019 05:00:31 -0000 Author: ian Date: Mon Apr 22 05:00:29 2019 New Revision: 346526 URL: https://svnweb.freebsd.org/changeset/base/346526 Log: MFC r336094, r336096 r336094: Catch up with improvements in RTC handling... It's no longer necessary to ignore the timestamp passed in to settime() due to inaccuracy, the core routines now pass in a nanosecond-accurate time freshly-obtained before calling each driver's settime() method. Also, add calls to the new debugging output helpers. r336096: Make the imx6_snvs driver usable as a module, add pnp info. Add a manpage. Added: stable/11/share/man/man4/man4.arm/imx6_snvs.4 - copied unchanged from r336096, head/share/man/man4/man4.arm/imx6_snvs.4 stable/11/sys/modules/imx/imx6_snvs/ - copied from r336096, head/sys/modules/imx/imx6_snvs/ Modified: stable/11/share/man/man4/man4.arm/Makefile stable/11/sys/arm/freescale/imx/imx6_snvs.c stable/11/sys/modules/imx/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/share/man/man4/man4.arm/Makefile ============================================================================== --- stable/11/share/man/man4/man4.arm/Makefile Mon Apr 22 04:58:01 2019 (r346525) +++ stable/11/share/man/man4/man4.arm/Makefile Mon Apr 22 05:00:29 2019 (r346526) @@ -5,6 +5,7 @@ PACKAGE=runtime-manuals MAN= cgem.4 \ devcfg.4 \ imx6_ahci.4 \ + imx6_snvs.4 \ imx_wdog.4 \ mge.4 \ npe.4 \ Copied: stable/11/share/man/man4/man4.arm/imx6_snvs.4 (from r336096, head/share/man/man4/man4.arm/imx6_snvs.4) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/share/man/man4/man4.arm/imx6_snvs.4 Mon Apr 22 05:00:29 2019 (r346526, copy of r336096, head/share/man/man4/man4.arm/imx6_snvs.4) @@ -0,0 +1,78 @@ +.\" +.\" Copyright (c) 2018 Ian Lepore +.\" 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 July 8, 2018 +.Dt IMX6_SNVS 4 +.Os +.Sh NAME +.Nm imx6_snvs +.Nd device driver for the NXP i.MX6 on-chip Realtime Clock +.Sh SYNOPSIS +To compile this driver into the kernel, +place the following line in your +kernel configuration file: +.Bd -ragged -offset indent +.Cd "device imx6_snvs" +.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 +imx6_snvs_load="YES" +.Ed +.Sh DESCRIPTION +The +.Nm +driver provides +support for the i.MX6 on-chip realtime clock. +It provides the time of day with a resolution of approximately +30 microseconds. +.Pp +.Sq SNVS +stands for Secure Non-Volatile Storage, and refers to the subsystem +within the chip that (optionally) remains powered by a battery when +the rest of the system is powered down. +The on-chip realtime clock is part of that subsystem. +Other features of the SNVS subsystem are related to security, tamper +monitoring, and power control; the +.Nm +driver does not currently support those features. +.Pp +Many i.MX6 systems do not use a battery to provide power to the SNVS +due to its relatively high power draw. In such systems, this driver +is able to provide a very accurate time following a reboot, but cannot +provide time at all if the power is cycled. If the system provides an +i2c or other type of alternate realtime clock with lower resolution, +there is value in configuring both clock drivers. +Doing so allows SNVS to provide accurate time after a reboot, while the +external clock provides approximate time after power cycling. +.Sh HISTORY +The +.Nm +driver first appeared in +.Fx 12.0 . Modified: stable/11/sys/arm/freescale/imx/imx6_snvs.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx6_snvs.c Mon Apr 22 04:58:01 2019 (r346525) +++ stable/11/sys/arm/freescale/imx/imx6_snvs.c Mon Apr 22 05:00:29 2019 (r346526) @@ -137,36 +137,34 @@ snvs_gettime(device_t dev, struct timespec *ts) *ts = sbttots(counter1); + clock_dbgprint_ts(sc->dev, CLOCK_DBG_READ, ts); + return (0); } static int -snvs_settime(device_t dev, struct timespec *unused) +snvs_settime(device_t dev, struct timespec *ts) { struct snvs_softc *sc; - struct bintime bt; sbintime_t sbt; sc = device_get_softc(dev); /* - * Ignore the inaccurate time passed in from the common clock code and - * obtain a time worthy of our 30us accuracy. + * The hardware format is the same as sbt (with fewer fractional bits), + * so first convert the time to sbt. It takes two clock cycles for the + * counter to start after setting the enable bit, so add two SBT_LSBs to + * what we're about to set. */ - bintime(&bt); - bt.sec -= utc_offset(); - sbt = bttosbt(bt); - - /* - * It takes two clock cycles for the counter to start after setting the - * enable bit, so add two SBT_LSBs to what we're about to set. - */ + sbt = tstosbt(*ts); sbt += 2 << SBT_LSB; snvs_rtc_enable(sc, false); WR4(sc, SNVS_LPSRTCMR, (uint32_t)(sbt >> (SBT_LSB + 32))); WR4(sc, SNVS_LPSRTCLR, (uint32_t)(sbt >> (SBT_LSB))); snvs_rtc_enable(sc, true); + clock_dbgprint_ts(sc->dev, CLOCK_DBG_WRITE, ts); + return (0); } @@ -206,9 +204,21 @@ snvs_attach(device_t dev) return (0); } +static int +snvs_detach(device_t dev) +{ + struct snvs_softc *sc; + + sc = device_get_softc(dev); + clock_unregister(sc->dev); + bus_release_resource(sc->dev, SYS_RES_MEMORY, 0, sc->memres); + return (0); +} + static device_method_t snvs_methods[] = { DEVMETHOD(device_probe, snvs_probe), DEVMETHOD(device_attach, snvs_attach), + DEVMETHOD(device_detach, snvs_detach), /* clock_if methods */ DEVMETHOD(clock_gettime, snvs_gettime), @@ -226,3 +236,4 @@ static driver_t snvs_driver = { static devclass_t snvs_devclass; DRIVER_MODULE(snvs, simplebus, snvs_driver, snvs_devclass, 0, 0); +SIMPLEBUS_PNP_INFO(compat_data); Modified: stable/11/sys/modules/imx/Makefile ============================================================================== --- stable/11/sys/modules/imx/Makefile Mon Apr 22 04:58:01 2019 (r346525) +++ stable/11/sys/modules/imx/Makefile Mon Apr 22 05:00:29 2019 (r346526) @@ -4,6 +4,7 @@ SUBDIR = \ ../ffec \ imx6_ahci \ + imx6_snvs \ imx_i2c \ imx_spi \ imx_wdog \