Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/i2c dont read cs1/cs2 regs when reading clock, only ...



details:   https://anonhg.NetBSD.org/src/rev/75ff07a8b41e
branches:  trunk
changeset: 335528:75ff07a8b41e
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Jan 11 18:58:09 2015 +0000

description:
dont read cs1/cs2 regs when reading clock, only use polling mode when cold, invert logic for century flag (1 means 1900, 0 means 2000), set dt_wday when reading clock

diffstat:

 sys/dev/i2c/pcf8563.c |  29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diffs (95 lines):

diff -r e6c3318ddc10 -r 75ff07a8b41e sys/dev/i2c/pcf8563.c
--- a/sys/dev/i2c/pcf8563.c     Sun Jan 11 18:56:54 2015 +0000
+++ b/sys/dev/i2c/pcf8563.c     Sun Jan 11 18:58:09 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcf8563.c,v 1.5 2015/01/11 18:05:36 jmcneill Exp $     */
+/*     $NetBSD: pcf8563.c,v 1.6 2015/01/11 18:58:09 jmcneill Exp $     */
 
 /*
  * Copyright (c) 2011 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcf8563.c,v 1.5 2015/01/11 18:05:36 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcf8563.c,v 1.6 2015/01/11 18:58:09 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -127,21 +127,22 @@
 pcf8563rtc_clock_read(struct pcf8563rtc_softc *sc, struct clock_ymdhms *dt)
 {
        uint8_t bcd[PCF8563_NREGS];
-       uint8_t reg = PCF8563_R_CS1;
+       uint8_t reg = PCF8563_R_SECOND;
+       const int flags = cold ? I2C_F_POLL : 0;
 
-       if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) {
+       if (iic_acquire_bus(sc->sc_tag, flags)) {
                device_printf(sc->sc_dev, "acquire bus for read failed\n");
                return 0;
        }
 
        if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, &reg, 1,
-                    &bcd[reg], PCF8563_R_YEAR - reg + 1, I2C_F_POLL)) {
-               iic_release_bus(sc->sc_tag, I2C_F_POLL);
+                    &bcd[reg], PCF8563_R_YEAR - reg + 1, flags)) {
+               iic_release_bus(sc->sc_tag, flags);
                device_printf(sc->sc_dev, "read failed\n");
                return 0;
        }
 
-       iic_release_bus(sc->sc_tag, I2C_F_POLL);
+       iic_release_bus(sc->sc_tag, flags);
 
        if (bcd[PCF8563_R_SECOND] & PCF8563_M_VL)
                return 0;
@@ -150,10 +151,11 @@
        dt->dt_min = bcdtobin(bcd[PCF8563_R_MINUTE] & PCF8563_M_MINUTE);
        dt->dt_hour = bcdtobin(bcd[PCF8563_R_HOUR] & PCF8563_M_HOUR);
        dt->dt_day = bcdtobin(bcd[PCF8563_R_DAY] & PCF8563_M_DAY);
+       dt->dt_wday = bcdtobin(bcd[PCF8563_R_WEEKDAY] & PCF8563_M_WEEKDAY);
        dt->dt_mon = bcdtobin(bcd[PCF8563_R_MONTH] & PCF8563_M_MONTH);
        dt->dt_year = 1900 +
            (bcdtobin(bcd[PCF8563_R_YEAR] & PCF8563_M_YEAR) % 100);
-       if (bcd[PCF8563_R_MONTH] & PCF8563_M_CENTURY)
+       if ((bcd[PCF8563_R_MONTH] & PCF8563_M_CENTURY) == 0)
                dt->dt_year += 100;
 
        return 1;
@@ -164,6 +166,7 @@
 {
        uint8_t bcd[PCF8563_NREGS];
        uint8_t reg = PCF8563_R_SECOND;
+       const int flags = cold ? I2C_F_POLL : 0;
 
        bcd[PCF8563_R_SECOND] = bintobcd(dt->dt_sec);
        bcd[PCF8563_R_MINUTE] = bintobcd(dt->dt_min);
@@ -172,22 +175,22 @@
        bcd[PCF8563_R_WEEKDAY] = bintobcd(dt->dt_wday);
        bcd[PCF8563_R_MONTH] = bintobcd(dt->dt_mon);
        bcd[PCF8563_R_YEAR] = bintobcd(dt->dt_year % 100);
-       if (dt->dt_year >= 2000)
+       if (dt->dt_year < 2000)
                bcd[PCF8563_R_MONTH] |= PCF8563_M_CENTURY;
 
-       if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) {
+       if (iic_acquire_bus(sc->sc_tag, flags)) {
                device_printf(sc->sc_dev, "acquire bus for write failed\n");
                return 0;
        }
 
        if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, &reg, 1,
-                    &bcd[reg], PCF8563_R_YEAR - reg + 1, I2C_F_POLL)) {
-               iic_release_bus(sc->sc_tag, I2C_F_POLL);
+                    &bcd[reg], PCF8563_R_YEAR - reg + 1, flags)) {
+               iic_release_bus(sc->sc_tag, flags);
                device_printf(sc->sc_dev, "write failed\n");
                return 0;
        }
 
-       iic_release_bus(sc->sc_tag, I2C_F_POLL);
+       iic_release_bus(sc->sc_tag, flags);
 
        return 1;
 }



Home | Main Index | Thread Index | Old Index