summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorDale S. Rahn <rahnds@cvs.openbsd.org>1998-06-28 06:37:16 +0000
committerDale S. Rahn <rahnds@cvs.openbsd.org>1998-06-28 06:37:16 +0000
commit26708466d70aa1cf138b44070b2dcc110f5d469a (patch)
tree18cbf6b3c56dd2cff01b0d7d0423155ca410837f /sys/dev
parenta6c743256693bfbc47fa90e3d5760a61865403ae (diff)
make the openfirmware clock reading routine compatible with the
"typical" hardware clock read routine.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ofw/ofrtc.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/sys/dev/ofw/ofrtc.c b/sys/dev/ofw/ofrtc.c
index e05cc8061d7..b85ffcaf4c4 100644
--- a/sys/dev/ofw/ofrtc.c
+++ b/sys/dev/ofw/ofrtc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofrtc.c,v 1.2 1997/11/07 08:07:23 niklas Exp $ */
+/* $OpenBSD: ofrtc.c,v 1.3 1998/06/28 06:37:15 rahnds Exp $ */
/* $NetBSD: ofrtc.c,v 1.3 1996/10/13 01:38:14 christos Exp $ */
/*
@@ -230,6 +230,11 @@ ofrtcwrite(dev, uio, flag)
}
+
+/* powerpc expects clock_read data in BCD, discuss this if it is improper */
+#define TOBCD(x) (((x) / 10 * 16) + ((x) % 10))
+#define YEAR0 1900
+
int
OF_clock_read(int *sec, int *min, int *hour, int *day,
int *mon, int *yr)
@@ -239,11 +244,11 @@ OF_clock_read(int *sec, int *min, int *hour, int *day,
int l;
if (!(of = ofrtc_cd.cd_devs[0]))
- return 0;
+ return 1;
if ((l = OF_package_to_path(of->sc_phandle, path, sizeof path - 1)) < 0)
- return 0;
+ return 1;
if (l >= sizeof path)
- return 0;
+ return 1;
path[l] = 0;
if (!(of->sc_ihandle = OF_open(path))) {
@@ -251,11 +256,22 @@ OF_clock_read(int *sec, int *min, int *hour, int *day,
OF_close(of->sc_ihandle);
of->sc_ihandle = 0;
}
- return 0;
+ return 1;
}
if (OF_call_method("get-time", of->sc_ihandle, 0, 6,
sec, min, hour, day, mon, yr))
- return 0;
-
+ {
return 1;
+ }
+ printf("y:%d m:%d d:%d H:%d M:%d S:%d\n",
+ *yr, *mon, *day, *hour, *min, *sec);
+ *yr -= YEAR0; /* bsd expects 0 - 200, not something like 1998 */
+ *yr = TOBCD(*yr);
+ *mon = TOBCD(*mon);
+ *day = TOBCD(*day);
+ *hour = TOBCD(*hour);
+ *min = TOBCD(*min);
+ *sec = TOBCD(*sec);
+
+ return 0;
}