Module Name: src Committed By: jmcneill Date: Sun Jan 11 18:05:36 UTC 2015
Modified Files: src/sys/dev/i2c: pcf8563.c Log Message: initialize CS1/CS2 regs, honour century flag, return an error on read if voltage low bit is set To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/pcf8563.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/i2c/pcf8563.c diff -u src/sys/dev/i2c/pcf8563.c:1.4 src/sys/dev/i2c/pcf8563.c:1.5 --- src/sys/dev/i2c/pcf8563.c:1.4 Thu Nov 20 16:34:26 2014 +++ src/sys/dev/i2c/pcf8563.c Sun Jan 11 18:05:36 2015 @@ -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 @@ pcf8563rtc_attach(device_t parent, devic 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 @@ pcf8563rtc_clock_read(struct pcf8563rtc_ 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 @@ pcf8563rtc_clock_write(struct pcf8563rtc 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");