Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/evbarm/tsarm Add support for TS-5620 daughter card RTC
details: https://anonhg.NetBSD.org/src/rev/6c753da094aa
branches: trunk
changeset: 572236:6c753da094aa
user: joff <joff%NetBSD.org@localhost>
date: Mon Dec 27 02:41:54 2004 +0000
description:
Add support for TS-5620 daughter card RTC
diffstat:
sys/arch/evbarm/tsarm/tsarmreg.h | 14 +-
sys/arch/evbarm/tsarm/tsrtc.c | 163 +++++++++++++++++++++++++++++++++++++++
2 files changed, 170 insertions(+), 7 deletions(-)
diffs (212 lines):
diff -r b96c0880f660 -r 6c753da094aa sys/arch/evbarm/tsarm/tsarmreg.h
--- a/sys/arch/evbarm/tsarm/tsarmreg.h Mon Dec 27 01:57:58 2004 +0000
+++ b/sys/arch/evbarm/tsarm/tsarmreg.h Mon Dec 27 02:41:54 2004 +0000
@@ -1,11 +1,9 @@
-/* $NetBSD: tsarmreg.h,v 1.1 2004/12/23 04:29:38 joff Exp $ */
+/* $NetBSD: tsarmreg.h,v 1.2 2004/12/27 02:41:54 joff Exp $ */
/*
- * Copyright (c) 2002 Wasabi Systems, Inc.
+ * Copyright (c) 2004 Jesse Off
* All rights reserved.
*
- * Based on code written by Jason R. Thorpe for Wasabi Systems, Inc.
- *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -35,8 +33,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef _TS7XXXREG_H_
-#define _TS7XXXREG_H_
+#ifndef _TSARMREG_H_
+#define _TSARMREG_H_
/*
* Memory map and register definitions for the TS-7200 single board computer
@@ -46,8 +44,10 @@
#define TS7XXX_IO8_HWBASE 0x10000000UL
#define TS7XXX_IO8_SIZE 0x04000000UL
#define TS7XXX_STATUS1 0x00800000UL
+#define TS7XXX_RTCIDX 0x00b00000UL
#define TS7XXX_CFREGS1 0x01000001UL
#define TS7XXX_CFREGS2 0x01040006UL
+#define TS7XXX_RTCDAT 0x01700000UL
#define TS7XXX_IO16_VBASE (TS7XXX_IO8_VBASE + TS7XXX_IO8_SIZE)
#define TS7XXX_IO16_HWBASE 0x20000000UL
#define TS7XXX_IO16_SIZE 0x04000000UL
@@ -61,4 +61,4 @@
#define TS7XXX_WDOGCTRL 0x03800000UL
#define TS7XXX_WDOGFEED 0x03c00000UL
-#endif /* _TS7XXXREG_H_ */
+#endif /* _TSARMREG_H_ */
diff -r b96c0880f660 -r 6c753da094aa sys/arch/evbarm/tsarm/tsrtc.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/evbarm/tsarm/tsrtc.c Mon Dec 27 02:41:54 2004 +0000
@@ -0,0 +1,163 @@
+/* $NetBSD: tsrtc.c,v 1.1 2004/12/27 02:41:54 joff Exp $ */
+
+/*
+ * Copyright (c) 1995, 1996 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution%CS.CMU.EDU@localhost
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: tsrtc.c,v 1.1 2004/12/27 02:41:54 joff Exp $");
+
+#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+
+#include <machine/bus.h>
+
+#include <dev/clock_subr.h>
+#include <dev/ic/mc146818reg.h>
+#include <dev/ic/mc146818var.h>
+
+#include <evbarm/tsarm/tspldvar.h>
+#include <evbarm/tsarm/tsarmreg.h>
+
+int tsrtc_match __P((struct device *, struct cfdata *, void *));
+void tsrtc_attach __P((struct device *, struct device *, void *));
+
+struct tsrtc_softc {
+ struct mc146818_softc sc_mc;
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_dath;
+ bus_space_handle_t sc_idxh;
+};
+
+CFATTACH_DECL(tsrtc, sizeof (struct tsrtc_softc),
+ tsrtc_match, tsrtc_attach, NULL, NULL);
+
+void tsrtc_write __P((struct mc146818_softc *, u_int, u_int));
+u_int tsrtc_read __P((struct mc146818_softc *, u_int));
+
+
+int
+tsrtc_match(parent, match, aux)
+ struct device *parent;
+ struct cfdata *match;
+ void *aux;
+{
+ struct tspld_attach_args *aa = aux;
+ struct tsrtc_softc tsrtc, *sc;
+ unsigned int t1, t2;
+ static int found = -1;
+
+ if (found != -1) return found;
+
+ sc = &tsrtc;
+ sc->sc_iot = aa->ta_iot;
+ if (bus_space_map(sc->sc_iot, TS7XXX_IO8_HWBASE + TS7XXX_RTCIDX, 1, 0,
+ &sc->sc_idxh))
+ return (0);
+ if (bus_space_map(sc->sc_iot, TS7XXX_IO8_HWBASE + TS7XXX_RTCDAT, 1, 0,
+ &sc->sc_dath))
+ return (0);
+
+ /* Read from the seconds counter. */
+ t1 = FROMBCD(tsrtc_read((struct mc146818_softc *)sc, MC_SEC));
+ if (t1 > 59)
+ goto unmap;
+
+ /* Wait, then look again. */
+ DELAY(1100000);
+ t2 = FROMBCD(tsrtc_read((struct mc146818_softc *)sc, MC_SEC));
+ if (t2 > 59)
+ goto unmap;
+
+ /* If [1,2) seconds have passed since, call it a clock. */
+ if ((t1 + 1) % 60 == t2 || (t1 + 2) % 60 == t2)
+ found = 1;
+
+ unmap:
+ bus_space_unmap(sc->sc_iot, sc->sc_idxh, 1);
+ bus_space_unmap(sc->sc_iot, sc->sc_dath, 1);
+
+ return (found);
+}
+
+void
+tsrtc_attach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+{
+ struct tsrtc_softc *sc = (void *)self;
+ struct tspld_attach_args *aa = aux;
+
+ sc->sc_iot = aa->ta_iot;
+ if (bus_space_map(sc->sc_iot, TS7XXX_IO8_HWBASE + TS7XXX_RTCIDX,
+ 1, 0, &sc->sc_idxh))
+ panic("tsrtc_attach: couldn't map clock I/O space");
+ if (bus_space_map(sc->sc_iot, TS7XXX_IO8_HWBASE + TS7XXX_RTCDAT,
+ 1, 0, &sc->sc_dath))
+ panic("tsrtc_attach: couldn't map clock I/O space");
+
+ sc->sc_mc.sc_year0 = 2000;
+ sc->sc_mc.sc_mcread = tsrtc_read;
+ sc->sc_mc.sc_mcwrite = tsrtc_write;
+ sc->sc_mc.sc_flag = MC146818_BCD;
+ mc146818_attach(&sc->sc_mc);
+
+ printf("\n");
+
+ (*sc->sc_mc.sc_mcwrite)((struct mc146818_softc *)sc, MC_REGB,
+ MC_REGB_24HR);
+
+ todr_attach(&sc->sc_mc.sc_handle);
+}
+
+void
+tsrtc_write(mc_sc, reg, datum)
+ struct mc146818_softc *mc_sc;
+ u_int reg, datum;
+{
+ struct tsrtc_softc *sc = (struct tsrtc_softc *)mc_sc;
+
+ bus_space_write_1(sc->sc_iot, sc->sc_idxh, 0, reg);
+ bus_space_write_1(sc->sc_iot, sc->sc_dath, 0, datum);
+}
+
+u_int
+tsrtc_read(mc_sc, reg)
+ struct mc146818_softc *mc_sc;
+ u_int reg;
+{
+ struct tsrtc_softc *sc = (struct tsrtc_softc *)mc_sc;
+ u_int datum;
+
+ bus_space_write_1(sc->sc_iot, sc->sc_idxh, 0, reg);
+ datum = bus_space_read_1(sc->sc_iot, sc->sc_dath, 0);
+
+ return (datum);
+}
Home |
Main Index |
Thread Index |
Old Index