From owner-svn-src-stable@freebsd.org Sat Jan 6 23:04:15 2018 Return-Path: Delivered-To: svn-src-stable@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 6FA1DDF8643; Sat, 6 Jan 2018 23:04:15 +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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49CC63D24; Sat, 6 Jan 2018 23:04:15 +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 6189718D80; Sat, 6 Jan 2018 23:04:14 +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 w06N4E9q005848; Sat, 6 Jan 2018 23:04:14 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w06N4EFI005847; Sat, 6 Jan 2018 23:04:14 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201801062304.w06N4EFI005847@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sat, 6 Jan 2018 23:04:14 +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: r327653 - stable/11/sys/dev/iicbus X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/dev/iicbus X-SVN-Commit-Revision: 327653 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Jan 2018 23:04:15 -0000 Author: ian Date: Sat Jan 6 23:04:14 2018 New Revision: 327653 URL: https://svnweb.freebsd.org/changeset/base/327653 Log: MFC r326750: Do not give up if writing to the chip's control and status registers fails during startup. When a brand new chip leaves the factory, it is in a special power-saving mode that disables most functions on the chip to save battery power. The chip is stuck in this mode until the first write to the time registers, which automatically clears the special power-saving mode and starts the oscillator. Also, the day-of-week register in this chip counts 1-7, not 0-6, so write the values accordingly. These changes are based on the patch submitted by Brian Scott, but I elimated warnings since this condition is expected, and added some comments, and so in general blame me for any mistakes. PR: 223642 Modified: stable/11/sys/dev/iicbus/ds3231.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/iicbus/ds3231.c ============================================================================== --- stable/11/sys/dev/iicbus/ds3231.c Sat Jan 6 22:59:10 2018 (r327652) +++ stable/11/sys/dev/iicbus/ds3231.c Sat Jan 6 23:04:14 2018 (r327653) @@ -427,13 +427,19 @@ ds3231_start(void *xdev) device_printf(sc->sc_dev, "WARNING: RTC clock stopped, check the battery.\n"); } - /* Ack any pending alarm interrupt. */ - if (ds3231_status_write(sc, 1, 1) != 0) - return; - /* Always enable the oscillator. */ - if (ds3231_ctrl_write(sc) != 0) - return; + /* + * Ack any pending alarm interrupts and clear the EOSC bit to ensure the + * clock runs even when on battery power. Do not give up if these + * writes fail, because a factory-fresh chip is in a special mode that + * disables much of the chip to save battery power, and the only thing + * that gets it out of that mode is writing to the time registers. In + * these pristine chips, the EOSC and alarm bits are zero already, so + * the first valid write of time will get everything running properly. + */ + ds3231_status_write(sc, 1, 1); + ds3231_ctrl_write(sc); + /* Temperature. */ SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "temperature", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, @@ -568,7 +574,7 @@ ds3231_settime(device_t dev, struct timespec *ts) data[DS3231_MINS] = TOBCD(ct.min); data[DS3231_HOUR] = TOBCD(ct.hour) | pmflags; data[DS3231_DATE] = TOBCD(ct.day); - data[DS3231_WEEKDAY] = ct.dow; + data[DS3231_WEEKDAY] = ct.dow + 1; data[DS3231_MONTH] = TOBCD(ct.mon); data[DS3231_YEAR] = TOBCD(ct.year % 100); if (sc->sc_last_c)