Date: Thu, 8 Jun 2017 16:46:38 +0000 (UTC) From: Zbigniew Bodek <zbb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319703 - head/sys/arm/mv/armada38x Message-ID: <201706081646.v58Gkc5w078042@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <bsz@semihalf.com> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201706081646.v58Gkc5w078042>