diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/i2c/abx80x.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/sys/dev/i2c/abx80x.c b/sys/dev/i2c/abx80x.c index ad143b7176c..7f55e24d2fc 100644 --- a/sys/dev/i2c/abx80x.c +++ b/sys/dev/i2c/abx80x.c @@ -1,4 +1,4 @@ -/* $OpenBSD: abx80x.c,v 1.3 2020/04/29 15:52:25 patrick Exp $ */ +/* $OpenBSD: abx80x.c,v 1.4 2020/04/29 18:44:28 patrick Exp $ */ /* * Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org> * Copyright (c) 2018 Patrick Wildt <patrick@blueri.se> @@ -211,7 +211,7 @@ abcrtc_reg_write(struct abcrtc_softc *sc, int reg, uint8_t data) int abcrtc_clock_read(struct abcrtc_softc *sc, struct clock_ymdhms *dt) { - uint8_t regs[ABX8XX_NRTC_REGS+1]; + uint8_t regs[ABX8XX_NRTC_REGS]; uint8_t cmd = ABX8XX_HTH; int error; @@ -233,13 +233,13 @@ abcrtc_clock_read(struct abcrtc_softc *sc, struct clock_ymdhms *dt) /* * Convert the ABX8XX's register values into something useable. */ - dt->dt_sec = FROMBCD(regs[2] & 0x7f); - dt->dt_min = FROMBCD(regs[3] & 0x7f); - dt->dt_hour = FROMBCD(regs[4] & 0x3f); - dt->dt_day = FROMBCD(regs[5] & 0x3f); - dt->dt_mon = FROMBCD(regs[6] & 0x1f); - dt->dt_year = FROMBCD(regs[7]) + 2000; - dt->dt_wday = regs[8] & 0x7; + dt->dt_sec = FROMBCD(regs[1] & 0x7f); + dt->dt_min = FROMBCD(regs[2] & 0x7f); + dt->dt_hour = FROMBCD(regs[3] & 0x3f); + dt->dt_day = FROMBCD(regs[4] & 0x3f); + dt->dt_mon = FROMBCD(regs[5] & 0x1f); + dt->dt_year = FROMBCD(regs[6]) + 2000; + dt->dt_wday = regs[7] & 0x7; return 0; } @@ -247,7 +247,7 @@ abcrtc_clock_read(struct abcrtc_softc *sc, struct clock_ymdhms *dt) int abcrtc_clock_write(struct abcrtc_softc *sc, struct clock_ymdhms *dt) { - uint8_t regs[ABX8XX_NRTC_REGS+1]; + uint8_t regs[ABX8XX_NRTC_REGS]; uint8_t cmd = ABX8XX_HTH; uint8_t reg; int error; @@ -256,15 +256,14 @@ abcrtc_clock_write(struct abcrtc_softc *sc, struct clock_ymdhms *dt) * Convert our time representation into something the ABX8XX * can understand. */ - regs[0] = ABX8XX_NRTC_REGS; - regs[1] = 0; - regs[2] = TOBCD(dt->dt_sec); - regs[3] = TOBCD(dt->dt_min); - regs[4] = TOBCD(dt->dt_hour); - regs[5] = TOBCD(dt->dt_day); - regs[6] = TOBCD(dt->dt_mon); - regs[7] = TOBCD(dt->dt_year - 2000); - regs[8] = dt->dt_wday; + regs[0] = 0; + regs[1] = TOBCD(dt->dt_sec); + regs[2] = TOBCD(dt->dt_min); + regs[3] = TOBCD(dt->dt_hour); + regs[4] = TOBCD(dt->dt_day); + regs[5] = TOBCD(dt->dt_mon); + regs[6] = TOBCD(dt->dt_year - 2000); + regs[7] = dt->dt_wday; iic_acquire_bus(sc->sc_tag, I2C_F_POLL); error = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, |