Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ic Handle BCD mode properly.
details: https://anonhg.NetBSD.org/src/rev/67db5a1f99fb
branches: trunk
changeset: 555651:67db5a1f99fb
user: tsutsui <tsutsui%NetBSD.org@localhost>
date: Mon Nov 24 06:20:40 2003 +0000
description:
Handle BCD mode properly.
diffstat:
sys/dev/ic/mc146818.c | 40 ++++++++++++++++++++++++----------------
sys/dev/ic/mc146818var.h | 4 +++-
2 files changed, 27 insertions(+), 17 deletions(-)
diffs (98 lines):
diff -r 1e057c6b9c4b -r 67db5a1f99fb sys/dev/ic/mc146818.c
--- a/sys/dev/ic/mc146818.c Mon Nov 24 06:11:56 2003 +0000
+++ b/sys/dev/ic/mc146818.c Mon Nov 24 06:20:40 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mc146818.c,v 1.3 2003/11/01 21:58:43 tsutsui Exp $ */
+/* $NetBSD: mc146818.c,v 1.4 2003/11/24 06:20:40 tsutsui Exp $ */
/*
* Copyright (c) 2003 Izumi Tsutsui. All rights reserved.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mc146818.c,v 1.3 2003/11/01 21:58:43 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mc146818.c,v 1.4 2003/11/24 06:20:40 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -103,18 +103,22 @@
}
}
- dt.dt_sec = (*sc->sc_mcread)(sc, MC_SEC);
- dt.dt_min = (*sc->sc_mcread)(sc, MC_MIN);
- dt.dt_hour = (*sc->sc_mcread)(sc, MC_HOUR);
- dt.dt_wday = (*sc->sc_mcread)(sc, MC_DOW);
- dt.dt_day = (*sc->sc_mcread)(sc, MC_DOM);
- dt.dt_mon = (*sc->sc_mcread)(sc, MC_MONTH);
- year = (*sc->sc_mcread)(sc, MC_YEAR);
+#define FROMREG(x) ((sc->sc_flag & MC146818_BCD) ? FROMBCD(x) : (x))
+
+ dt.dt_sec = FROMREG((*sc->sc_mcread)(sc, MC_SEC));
+ dt.dt_min = FROMREG((*sc->sc_mcread)(sc, MC_MIN));
+ dt.dt_hour = FROMREG((*sc->sc_mcread)(sc, MC_HOUR));
+ dt.dt_wday = FROMREG((*sc->sc_mcread)(sc, MC_DOW));
+ dt.dt_day = FROMREG((*sc->sc_mcread)(sc, MC_DOM));
+ dt.dt_mon = FROMREG((*sc->sc_mcread)(sc, MC_MONTH));
+ year = FROMREG((*sc->sc_mcread)(sc, MC_YEAR));
if (sc->sc_getcent) {
cent = (*sc->sc_getcent)(sc);
year += cent * 100;
}
+#undef FROMREG
+
year += sc->sc_year0;
if (year < POSIX_BASE_YEAR &&
(sc->sc_flag & MC146818_NO_CENT_ADJUST) == 0)
@@ -168,12 +172,14 @@
}
}
- (*sc->sc_mcwrite)(sc, MC_SEC, dt.dt_sec);
- (*sc->sc_mcwrite)(sc, MC_MIN, dt.dt_min);
- (*sc->sc_mcwrite)(sc, MC_HOUR, dt.dt_hour);
- (*sc->sc_mcwrite)(sc, MC_DOW, dt.dt_wday);
- (*sc->sc_mcwrite)(sc, MC_DOM, dt.dt_day);
- (*sc->sc_mcwrite)(sc, MC_MONTH, dt.dt_mon);
+#define TOREG(x) ((sc->sc_flag & MC146818_BCD) ? TOBCD(x) : (x))
+
+ (*sc->sc_mcwrite)(sc, MC_SEC, TOREG(dt.dt_sec));
+ (*sc->sc_mcwrite)(sc, MC_MIN, TOREG(dt.dt_min));
+ (*sc->sc_mcwrite)(sc, MC_HOUR, TOREG(dt.dt_hour));
+ (*sc->sc_mcwrite)(sc, MC_DOW, TOREG(dt.dt_wday));
+ (*sc->sc_mcwrite)(sc, MC_DOM, TOREG(dt.dt_day));
+ (*sc->sc_mcwrite)(sc, MC_MONTH, TOREG(dt.dt_mon));
year = dt.dt_year - sc->sc_year0;
if (sc->sc_setcent) {
@@ -184,7 +190,9 @@
if (year > 99 &&
(sc->sc_flag & MC146818_NO_CENT_ADJUST) == 0)
year -= 100;
- (*sc->sc_mcwrite)(sc, MC_YEAR, year);
+ (*sc->sc_mcwrite)(sc, MC_YEAR, TOREG(year));
+
+#undef TOREG
todr_wenable(handle, 0);
diff -r 1e057c6b9c4b -r 67db5a1f99fb sys/dev/ic/mc146818var.h
--- a/sys/dev/ic/mc146818var.h Mon Nov 24 06:11:56 2003 +0000
+++ b/sys/dev/ic/mc146818var.h Mon Nov 24 06:20:40 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mc146818var.h,v 1.2 2003/11/01 21:58:43 tsutsui Exp $ */
+/* $NetBSD: mc146818var.h,v 1.3 2003/11/24 06:20:40 tsutsui Exp $ */
/*
* Copyright (c) 2003 Izumi Tsutsui. All rights reserved.
@@ -36,6 +36,8 @@
u_int sc_year0; /* year counter offset */
u_int sc_flag; /* MD flags */
#define MC146818_NO_CENT_ADJUST 0x0001 /* don't adjust century */
+#define MC146818_BCD 0x0002 /* use BCD mode */
+#define MC146818_12HR 0x0004 /* use AM/PM mode */
/* MD chip register read/write functions */
u_int (*sc_mcread)(struct mc146818_softc *, u_int);
Home |
Main Index |
Thread Index |
Old Index