From owner-svn-src-head@freebsd.org Thu Jun 8 16:46:39 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 4742FC0A123; Thu, 8 Jun 2017 16:46:39 +0000 (UTC) (envelope-from zbb@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 217C5642BD; Thu, 8 Jun 2017 16:46:39 +0000 (UTC) (envelope-from zbb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v58GkcY9078043; Thu, 8 Jun 2017 16:46:38 GMT (envelope-from zbb@FreeBSD.org) Received: (from zbb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v58Gkc5w078042; Thu, 8 Jun 2017 16:46:38 GMT (envelope-from zbb@FreeBSD.org) Message-Id: <201706081646.v58Gkc5w078042@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: zbb set sender to zbb@FreeBSD.org using -f From: Zbigniew Bodek Date: Thu, 8 Jun 2017 16:46:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319703 - head/sys/arm/mv/armada38x 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: Thu, 08 Jun 2017 16:46:39 -0000 Author: zbb Date: Thu Jun 8 16:46:38 2017 New Revision: 319703 URL: https://svnweb.freebsd.org/changeset/base/319703 Log: Add reset capability to mv_rtc driver This commit enables optional reset of the RTC, in case its registers' contents did not sustain the reboot or power-off/on sequence. Without it, further usage of RTC is impossible (e.g. writing values to RTC_TIME register will not succeed). The reset is performed only if Clock Correction register does not comprise RTC_NOMINAL_TIMING, what helps to distinguish, whether the software configured RTC before or it comprises the default value. Submitted by: Bartosz Szczepanek Obtained from: Semihalf Sponsored by: Stormshield Differential revision: https://reviews.freebsd.org/D10900 Modified: head/sys/arm/mv/armada38x/rtc.c Modified: head/sys/arm/mv/armada38x/rtc.c ============================================================================== --- head/sys/arm/mv/armada38x/rtc.c Thu Jun 8 16:18:41 2017 (r319702) +++ head/sys/arm/mv/armada38x/rtc.c Thu Jun 8 16:46:38 2017 (r319703) @@ -56,7 +56,19 @@ __FBSDID("$FreeBSD$"); #define RTC_STATUS 0x0 #define RTC_TIME 0xC +#define RTC_TEST_CONFIG 0x1C +#define RTC_IRQ_1_CONFIG 0x4 +#define RTC_IRQ_2_CONFIG 0x8 +#define RTC_ALARM_1 0x10 +#define RTC_ALARM_2 0x14 +#define RTC_CLOCK_CORR 0x18 +#define RTC_NOMINAL_TIMING 0x2000 +#define RTC_NOMINAL_TIMING_MASK 0x7fff + +#define RTC_STATUS_ALARM1_MASK 0x1 +#define RTC_STATUS_ALARM2_MASK 0x2 + #define MV_RTC_LOCK(sc) mtx_lock(&(sc)->mutex) #define MV_RTC_UNLOCK(sc) mtx_unlock(&(sc)->mutex) @@ -103,6 +115,43 @@ static devclass_t mv_rtc_devclass; DRIVER_MODULE(mv_rtc, simplebus, mv_rtc_driver, mv_rtc_devclass, 0, 0); +static void +mv_rtc_reset(device_t dev) +{ + struct mv_rtc_softc *sc; + + sc = device_get_softc(dev); + + /* Reset Test register */ + mv_rtc_reg_write(sc, RTC_TEST_CONFIG, 0); + DELAY(500000); + + /* Reset Time register */ + mv_rtc_reg_write(sc, RTC_TIME, 0); + DELAY(62); + + /* Reset Status register */ + mv_rtc_reg_write(sc, RTC_STATUS, (RTC_STATUS_ALARM1_MASK | RTC_STATUS_ALARM2_MASK)); + DELAY(62); + + /* Turn off Int1 and Int2 sources & clear the Alarm count */ + mv_rtc_reg_write(sc, RTC_IRQ_1_CONFIG, 0); + mv_rtc_reg_write(sc, RTC_IRQ_2_CONFIG, 0); + mv_rtc_reg_write(sc, RTC_ALARM_1, 0); + mv_rtc_reg_write(sc, RTC_ALARM_2, 0); + + /* Setup nominal register access timing */ + mv_rtc_reg_write(sc, RTC_CLOCK_CORR, RTC_NOMINAL_TIMING); + + /* Reset Time register */ + mv_rtc_reg_write(sc, RTC_TIME, 0); + DELAY(10); + + /* Reset Status register */ + mv_rtc_reg_write(sc, RTC_STATUS, (RTC_STATUS_ALARM1_MASK | RTC_STATUS_ALARM2_MASK)); + DELAY(50); +} + static int mv_rtc_probe(device_t dev) { @@ -197,6 +246,12 @@ mv_rtc_settime(device_t dev, struct timespec *ts) ts->tv_nsec = 0; MV_RTC_LOCK(sc); + + if ((mv_rtc_reg_read(sc, RTC_CLOCK_CORR) & RTC_NOMINAL_TIMING_MASK) != + RTC_NOMINAL_TIMING) { + /* RTC was not resetted yet */ + mv_rtc_reset(dev); + } /* * According to errata FE-3124064, Write to RTC TIME register