Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm/ep93xx do things the todr(9) way
details: https://anonhg.NetBSD.org/src/rev/8e71813c18b2
branches: trunk
changeset: 572239:8e71813c18b2
user: joff <joff%NetBSD.org@localhost>
date: Mon Dec 27 02:46:22 2004 +0000
description:
do things the todr(9) way
diffstat:
sys/arch/arm/ep93xx/epclk.c | 93 ++++++++++++++++++++++++++++++++++++++++----
1 files changed, 84 insertions(+), 9 deletions(-)
diffs (123 lines):
diff -r 474ca3f76786 -r 8e71813c18b2 sys/arch/arm/ep93xx/epclk.c
--- a/sys/arch/arm/ep93xx/epclk.c Mon Dec 27 02:44:38 2004 +0000
+++ b/sys/arch/arm/ep93xx/epclk.c Mon Dec 27 02:46:22 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: epclk.c,v 1.1 2004/12/22 19:09:29 joff Exp $ */
+/* $NetBSD: epclk.c,v 1.2 2004/12/27 02:46:22 joff Exp $ */
/*
* Copyright (c) 2004 Jesse Off
@@ -47,7 +47,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: epclk.c,v 1.1 2004/12/22 19:09:29 joff Exp $");
+__KERNEL_RCSID(0, "$NetBSD: epclk.c,v 1.2 2004/12/27 02:46:22 joff Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -64,6 +64,7 @@
#include <arm/ep93xx/epsocvar.h>
#include <arm/ep93xx/epclkreg.h>
#include <arm/ep93xx/ep93xxvar.h>
+#include <dev/clock_subr.h>
static int epclk_match(struct device *, struct cfdata *, void *);
static void epclk_attach(struct device *, struct device *, void *);
@@ -296,15 +297,89 @@
}
}
+todr_chip_handle_t todr_handle;
+
+/*
+ * todr_attach:
+ *
+ * Set the specified time-of-day register as the system real-time clock.
+ */
+void
+todr_attach(todr_chip_handle_t todr)
+{
+
+ if (todr_handle)
+ panic("todr_attach: rtc already configured");
+ todr_handle = todr;
+}
+
+/*
+ * inittodr:
+ *
+ * Initialize time from the time-of-day register.
+ */
+#define MINYEAR 2003 /* minimum plausible year */
+void
+inittodr(time_t base)
+{
+ time_t deltat;
+ int badbase;
+
+ if (base < (MINYEAR - 1970) * SECYR) {
+ printf("WARNING: preposterous time in file system");
+ /* read the system clock anyway */
+ base = (MINYEAR - 1970) * SECYR;
+ badbase = 1;
+ } else
+ badbase = 0;
+
+ if (todr_handle == NULL ||
+ todr_gettime(todr_handle, (struct timeval *)&time) != 0 ||
+ time.tv_sec == 0) {
+ /*
+ * Believe the time in the file system for lack of
+ * anything better, resetting the TODR.
+ */
+ time.tv_sec = base;
+ time.tv_usec = 0;
+ if (todr_handle != NULL && !badbase) {
+ printf("WARNING: preposterous clock chip time\n");
+ resettodr();
+ }
+ goto bad;
+ }
+
+ if (!badbase) {
+ /*
+ * See if we tained/lost two or more days; if
+ * so, assume something is amiss.
+ */
+ deltat = time.tv_sec - base;
+ if (deltat < 0)
+ deltat = -deltat;
+ if (deltat < 2 * SECDAY)
+ return; /* all is well */
+ printf("WARNING: clock %s %ld days\n",
+ time.tv_sec < base ? "lost" : "gained",
+ (long)deltat / SECDAY);
+ }
+ bad:
+ printf("WARNING: CHECK AND RESET THE DATE!\n");
+}
+
+/*
+ * resettodr:
+ *
+ * Reset the time-of-day register with the current time.
+ */
void
resettodr(void)
{
-}
+
+ if (time.tv_sec == 0)
+ return;
-void
-inittodr(time_t base)
-{
-
- time.tv_sec = base;
- time.tv_usec = 0;
+ if (todr_handle != NULL &&
+ todr_settime(todr_handle, (struct timeval *)&time) != 0)
+ printf("resettodr: failed to set time\n");
}
Home |
Main Index |
Thread Index |
Old Index