diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-04-27 12:36:04 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-04-27 12:36:04 +0000 |
commit | 1e6d54d54710577de6ab12305e34ad89cafce940 (patch) | |
tree | 0eb599485fec5b03aae920b83dfa18c846185972 /sys/dev/i2c | |
parent | d9ccb4b55cb6c649b0e29191c1f738f4fdc5c3fd (diff) |
Don't clear OSF flag when we attach such that we can reject the RTC clock
time if the flag is set. Instead clear the flag when we set the time.
This way we don't use the clock time if the oscillator has been interrupted.
This happens for example when the battery is dead.
ok sthen@
Diffstat (limited to 'sys/dev/i2c')
-rw-r--r-- | sys/dev/i2c/pcf8523.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/sys/dev/i2c/pcf8523.c b/sys/dev/i2c/pcf8523.c index 31819e53b3e..8aca00ae1b7 100644 --- a/sys/dev/i2c/pcf8523.c +++ b/sys/dev/i2c/pcf8523.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcf8523.c,v 1.3 2016/05/20 20:33:53 kettenis Exp $ */ +/* $OpenBSD: pcf8523.c,v 1.4 2020/04/27 12:36:03 kettenis Exp $ */ /* * Copyright (c) 2005 Kimihiro Nonaka @@ -165,13 +165,6 @@ pcfrtc_attach(struct device *parent, struct device *self, void *arg) /* Report battery status. */ reg = pcfrtc_reg_read(sc, PCF8523_CONTROL3); printf(": battery %s\n", (reg & PCF8523_CONTROL3_BLF) ? "low" : "ok"); - - /* Clear OS flag. */ - reg = pcfrtc_reg_read(sc, PCF8523_SECONDS); - if (reg & PCF8523_SECONDS_OS) { - reg &= ~PCF8523_SECONDS_OS; - pcfrtc_reg_write(sc, PCF8523_SECONDS, reg); - } } int @@ -194,11 +187,19 @@ pcfrtc_settime(struct todr_chip_handle *ch, struct timeval *tv) { struct pcfrtc_softc *sc = ch->cookie; struct clock_ymdhms dt; + uint8_t reg; clock_secs_to_ymdhms(tv->tv_sec, &dt); - if (pcfrtc_clock_write(sc, &dt) == 0) return (-1); + + /* Clear OS flag. */ + reg = pcfrtc_reg_read(sc, PCF8523_SECONDS); + if (reg & PCF8523_SECONDS_OS) { + reg &= ~PCF8523_SECONDS_OS; + pcfrtc_reg_write(sc, PCF8523_SECONDS, reg); + } + return (0); } |