Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c add options DSRTC_YEAR_START_2K for machines whi...



details:   https://anonhg.NetBSD.org/src/rev/2154cb070420
branches:  trunk
changeset: 837675:2154cb070420
user:      macallan <macallan%NetBSD.org@localhost>
date:      Fri Dec 14 22:05:36 2018 +0000

description:
add options DSRTC_YEAR_START_2K for machines which use 2000 and not 1970
as base to count years from, like Iyonix.
While there apply the offset when writing to the clock as well.

diffstat:

 sys/dev/i2c/ds1307.c  |  23 ++++++++++++++++++-----
 sys/dev/i2c/files.i2c |   3 ++-
 2 files changed, 20 insertions(+), 6 deletions(-)

diffs (89 lines):

diff -r 9b7d06a113bb -r 2154cb070420 sys/dev/i2c/ds1307.c
--- a/sys/dev/i2c/ds1307.c      Fri Dec 14 22:00:26 2018 +0000
+++ b/sys/dev/i2c/ds1307.c      Fri Dec 14 22:05:36 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ds1307.c,v 1.29 2018/06/26 06:03:57 thorpej Exp $      */
+/*     $NetBSD: ds1307.c,v 1.30 2018/12/14 22:05:36 macallan Exp $     */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.29 2018/06/26 06:03:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.30 2018/12/14 22:05:36 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -54,6 +54,7 @@
 #include <dev/sysmon/sysmonvar.h>
 
 #include "ioconf.h"
+#include "opt_dsrtc.h"
 
 struct dsrtc_model {
        const i2c_addr_t *dm_valid_addrs;
@@ -316,6 +317,7 @@
        sc->sc_dev = self;
        sc->sc_open = 0;
        sc->sc_todr.cookie = sc;
+       
        if (dm->dm_flags & DSRTC_FLAG_BCD) {
                sc->sc_todr.todr_gettime_ymdhms = dsrtc_gettime_ymdhms;
                sc->sc_todr.todr_settime_ymdhms = dsrtc_settime_ymdhms;
@@ -325,6 +327,10 @@
        }
        sc->sc_todr.todr_setwen = NULL;
 
+#ifdef DSRTC_YEAR_START_2K
+       sc->sc_model.dm_flags |= DSRTC_FLAG_YEAR_START_2K;
+#endif
+
        todr_attach(&sc->sc_todr);
        if ((sc->sc_model.dm_flags & DSRTC_FLAG_TEMP) != 0) {
                int error;
@@ -571,7 +577,7 @@
 {
        struct dsrtc_model * const dm = &sc->sc_model;
        uint8_t bcd[DSXXXX_RTC_SIZE], cmdbuf[2];
-       int error;
+       int error, offset;
 
        KASSERT(DSXXXX_RTC_SIZE >= dm->dm_rtc_size);
 
@@ -585,8 +591,15 @@
        bcd[DSXXXX_DATE] = bintobcd(dt->dt_day);
        bcd[DSXXXX_DAY] = bintobcd(dt->dt_wday);
        bcd[DSXXXX_MONTH] = bintobcd(dt->dt_mon);
-       bcd[DSXXXX_YEAR] = bintobcd((dt->dt_year - POSIX_BASE_YEAR) % 100);
-       if (dt->dt_year - POSIX_BASE_YEAR >= 100)
+       
+       if (sc->sc_model.dm_flags & DSRTC_FLAG_YEAR_START_2K) {
+               offset = 2000;
+       } else {
+               offset = POSIX_BASE_YEAR;
+       }
+
+       bcd[DSXXXX_YEAR] = bintobcd((dt->dt_year - offset) % 100);
+       if (dt->dt_year - offset >= 100)
                bcd[DSXXXX_MONTH] |= DSXXXX_MONTH_CENTURY;
 
        if ((error = iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) != 0) {
diff -r 9b7d06a113bb -r 2154cb070420 sys/dev/i2c/files.i2c
--- a/sys/dev/i2c/files.i2c     Fri Dec 14 22:00:26 2018 +0000
+++ b/sys/dev/i2c/files.i2c     Fri Dec 14 22:05:36 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.i2c,v 1.96 2018/09/02 01:16:58 jmcneill Exp $
+#      $NetBSD: files.i2c,v 1.97 2018/12/14 22:05:36 macallan Exp $
 
 obsolete defflag       opt_i2cbus.h            I2C_SCAN
 define i2cbus { }
@@ -123,6 +123,7 @@
 device dsrtc: sysmon_envsys
 attach dsrtc at iic
 file   dev/i2c/ds1307.c                        dsrtc
+defflag opt_dsrtc.h                            DSRTC_YEAR_START_2K
 
 # Xicor X1226 Real Time Clock
 device xrtc



Home | Main Index | Thread Index | Old Index