mcclock_ioasic.c revision 1.12 1 /* $NetBSD: mcclock_ioasic.c,v 1.12 2007/07/21 11:59:57 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
31
32 __KERNEL_RCSID(0, "$NetBSD: mcclock_ioasic.c,v 1.12 2007/07/21 11:59:57 tsutsui Exp $");
33
34 #include <sys/param.h>
35 #include <sys/kernel.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38
39 #include <machine/bus.h>
40
41 #include <dev/clock_subr.h>
42
43 #include <dev/ic/mc146818reg.h>
44 #include <dev/ic/mc146818var.h>
45 #include <dev/tc/tcvar.h>
46 #include <dev/tc/ioasicvar.h> /* XXX */
47
48 #include <alpha/alpha/mcclockvar.h>
49
50 struct mcclock_ioasic_clockdatum {
51 u_char datum;
52 char pad[3];
53 };
54
55 struct mcclock_ioasic_softc {
56 struct mc146818_softc sc_mc146818;
57
58 struct mcclock_ioasic_clockdatum *sc_dp;
59 };
60
61 int mcclock_ioasic_match(struct device *, struct cfdata *, void *);
62 void mcclock_ioasic_attach(struct device *, struct device *, void *);
63
64 CFATTACH_DECL(mcclock_ioasic, sizeof(struct mcclock_ioasic_softc),
65 mcclock_ioasic_match, mcclock_ioasic_attach, NULL, NULL);
66
67 void mcclock_ioasic_write(struct mc146818_softc *, u_int, u_int);
68 u_int mcclock_ioasic_read(struct mc146818_softc *, u_int);
69
70 int
71 mcclock_ioasic_match(struct device *parent, struct cfdata *match, void *aux)
72 {
73 struct ioasicdev_attach_args *d = aux;
74
75 if (strncmp("TOY_RTC ", d->iada_modname, TC_ROM_LLEN))
76 return (0);
77
78 return (1);
79 }
80
81 void
82 mcclock_ioasic_attach(struct device *parent, struct device *self, void *aux)
83 {
84 struct ioasicdev_attach_args *ioasicdev = aux;
85 struct mcclock_ioasic_softc *isc = (void *)self;
86 struct mc146818_softc *sc = &isc->sc_mc146818;
87
88 /* XXX no bus_space(9) for TURBOchannel yet */
89 isc->sc_dp = (void *)ioasicdev->iada_addr;
90
91 sc->sc_mcread = mcclock_ioasic_read;
92 sc->sc_mcwrite = mcclock_ioasic_write;
93
94 /* call alpha common mcclock attachment */
95 mcclock_attach(sc);
96 }
97
98 void
99 mcclock_ioasic_write(struct mc146818_softc *sc, u_int reg, u_int datum)
100 {
101 struct mcclock_ioasic_softc *isc = (void *)sc;
102
103 isc->sc_dp[reg].datum = datum;
104 }
105
106 u_int
107 mcclock_ioasic_read(struct mc146818_softc *sc, u_int reg)
108 {
109 struct mcclock_ioasic_softc *isc = (void *)sc;
110
111 return isc->sc_dp[reg].datum;
112 }
113