Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/i2c initialize CS1/CS2 regs, honour century flag, re...
details: https://anonhg.NetBSD.org/src/rev/3eb44da2e383
branches: trunk
changeset: 335526:3eb44da2e383
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Sun Jan 11 18:05:36 2015 +0000
description:
initialize CS1/CS2 regs, honour century flag, return an error on read if voltage low bit is set
diffstat:
sys/dev/i2c/pcf8563.c | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
diffs (62 lines):
diff -r 2bbd93f32f5c -r 3eb44da2e383 sys/dev/i2c/pcf8563.c
--- a/sys/dev/i2c/pcf8563.c Sun Jan 11 17:56:21 2015 +0000
+++ b/sys/dev/i2c/pcf8563.c Sun Jan 11 18:05:36 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcf8563.c,v 1.4 2014/11/20 16:34:26 christos Exp $ */
+/* $NetBSD: pcf8563.c,v 1.5 2015/01/11 18:05:36 jmcneill Exp $ */
/*
* Copyright (c) 2011 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcf8563.c,v 1.4 2014/11/20 16:34:26 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcf8563.c,v 1.5 2015/01/11 18:05:36 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -91,6 +91,13 @@
sc->sc_todr.todr_settime_ymdhms = pcf8563rtc_settime;
sc->sc_todr.todr_setwen = NULL;
+ iic_acquire_bus(sc->sc_tag, I2C_F_POLL);
+ iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, PCF8563_R_CS1, 0,
+ I2C_F_POLL);
+ iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, PCF8563_R_CS2, 0,
+ I2C_F_POLL);
+ iic_release_bus(sc->sc_tag, I2C_F_POLL);
+
todr_attach(&sc->sc_todr);
}
@@ -136,13 +143,18 @@
iic_release_bus(sc->sc_tag, I2C_F_POLL);
+ if (bcd[PCF8563_R_SECOND] & PCF8563_M_VL)
+ return 0;
+
dt->dt_sec = bcdtobin(bcd[PCF8563_R_SECOND] & PCF8563_M_SECOND);
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_mon = bcdtobin(bcd[PCF8563_R_MONTH] & PCF8563_M_MONTH);
- dt->dt_year = bcdtobin(bcd[PCF8563_R_YEAR] & PCF8563_M_YEAR);
- dt->dt_year += 2000;
+ dt->dt_year = 1900 +
+ (bcdtobin(bcd[PCF8563_R_YEAR] & PCF8563_M_YEAR) % 100);
+ if (bcd[PCF8563_R_MONTH] & PCF8563_M_CENTURY)
+ dt->dt_year += 100;
return 1;
}
@@ -160,6 +172,8 @@
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)
+ bcd[PCF8563_R_MONTH] |= PCF8563_M_CENTURY;
if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) {
device_printf(sc->sc_dev, "acquire bus for write failed\n");
Home |
Main Index |
Thread Index |
Old Index