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
This commit is contained in:
parent
4bd7e351f1
commit
054beaac09
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=319703
@ -56,6 +56,18 @@ __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)
|
||||
{
|
||||
@ -198,6 +247,12 @@ mv_rtc_settime(device_t dev, struct timespec *ts)
|
||||
|
||||
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
|
||||
* may fail. As a workaround, before writing to RTC TIME register,
|
||||
|
Loading…
Reference in New Issue
Block a user