From owner-svn-src-head@freebsd.org Mon Jul 15 21:47:41 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7FE9AC4C51; Mon, 15 Jul 2019 21:47:41 +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 617EE811FF; Mon, 15 Jul 2019 21:47:41 +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 3A5EC23DCF; Mon, 15 Jul 2019 21:47:41 +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 x6FLlfaF068415; Mon, 15 Jul 2019 21:47:41 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x6FLlfID068413; Mon, 15 Jul 2019 21:47:41 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201907152147.x6FLlfID068413@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 15 Jul 2019 21:47:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r350016 - head/sys/dev/iicbus X-SVN-Group: head X-SVN-Commit-Author: ian X-SVN-Commit-Paths: head/sys/dev/iicbus X-SVN-Commit-Revision: 350016 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 617EE811FF X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.96)[-0.963,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 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, 15 Jul 2019 21:47:41 -0000 Author: ian Date: Mon Jul 15 21:47:40 2019 New Revision: 350016 URL: https://svnweb.freebsd.org/changeset/base/350016 Log: In nxprtc(4), use the countdown timer for better timekeeping resolution on PCx2129 chips too. The datasheet for the PCx2129 chips says that there is only a watchdog timer, no countdown timer. It turns out the countdown timer hardware is there and works just the same as it does on a PCx2127 chip, except that you can't use it to trigger an interrupt or toggle an output pin. We don't need interrupts or output pins, we only need to read the timer register to get sub-second resolution. So start treating the 2129 chips the same as 2127. Modified: head/sys/dev/iicbus/nxprtc.c Modified: head/sys/dev/iicbus/nxprtc.c ============================================================================== --- head/sys/dev/iicbus/nxprtc.c Mon Jul 15 21:40:58 2019 (r350015) +++ head/sys/dev/iicbus/nxprtc.c Mon Jul 15 21:47:40 2019 (r350016) @@ -33,8 +33,8 @@ __FBSDID("$FreeBSD$"); * - PCA8565 = like PCF8563, automotive temperature range * - PCF8523 = low power, countdown timer, oscillator freq tuning, 2 timers * - PCF2127 = like PCF8523, industrial, tcxo, tamper/ts, i2c & spi, 512B ram - * - PCA2129 = like PCF8523, automotive, tcxo, tamper/ts, i2c & spi, no timer - * - PCF2129 = like PCF8523, industrial, tcxo, tamper/ts, i2c & spi, no timer + * - PCA2129 = like PCF8523, automotive, tcxo, tamper/ts, i2c & spi, (note 1) + * - PCF2129 = like PCF8523, industrial, tcxo, tamper/ts, i2c & spi, (note 1) * * Most chips have a countdown timer, ostensibly intended to generate periodic * interrupt signals on an output pin. The timer is driven from the same @@ -42,6 +42,13 @@ __FBSDID("$FreeBSD$"); * in sync when the STOP bit is cleared after the time and timer registers are * set. The timer register can also be read on the fly, so we use it to count * fractional seconds and get a resolution of ~15ms. + * + * [1] Note that the datasheets for the PCx2129 chips state that they have only + * a watchdog timer, not a countdown timer. Empirical testing shows that the + * countdown timer is actually there and it works fine, except that it can't + * trigger an interrupt or toggle an output pin like it can on other chips. We + * don't care about interrupts and output pins, we just read the timer register + * to get better resolution. */ #include "opt_platform.h" @@ -471,7 +478,13 @@ pcf2127_start_timer(struct nxprtc_softc *sc) int err; uint8_t stdctl, tmrctl; - /* See comment in pcf8523_start_timer(). */ + /* + * Set up timer if it's not already in the mode we normally run it. See + * the comment in pcf8523_start_timer() for more details. + * + * Note that the PCF2129 datasheet says it has no countdown timer, but + * empirical testing shows that it works just fine for our purposes. + */ if ((err = read_reg(sc, PCF2127_R_TMR_CTL, &tmrctl)) != 0) return (err); @@ -521,10 +534,6 @@ nxprtc_start(void *dev) switch (sc->chiptype) { case TYPE_PCA2129: case TYPE_PCF2129: - if (pcf8523_start(sc) != 0) - return; - /* No timer to start */ - break; case TYPE_PCF2127: if (pcf8523_start(sc) != 0) return; @@ -796,10 +805,6 @@ nxprtc_attach(device_t dev) switch (sc->chiptype) { case TYPE_PCA2129: case TYPE_PCF2129: - sc->secaddr = PCF8523_R_SECOND; - sc->tmcaddr = 0; - sc->use_timer = false; - break; case TYPE_PCF2127: case TYPE_PCF8523: sc->secaddr = PCF8523_R_SECOND;