xref: /netbsd-src/sys/arch/alpha/tc/mcclock_ioasic.c (revision d0fed6c87ddc40a8bffa6f99e7433ddfc864dd83)
1 /* $NetBSD: mcclock_ioasic.c,v 1.6 1997/04/07 23:40:54 cgd 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@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 <machine/options.h>		/* Config options headers */
31 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
32 
33 __KERNEL_RCSID(0, "$NetBSD: mcclock_ioasic.c,v 1.6 1997/04/07 23:40:54 cgd Exp $");
34 
35 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 
40 #include <alpha/alpha/clockvar.h>
41 #include <alpha/alpha/mcclockvar.h>
42 #include <dev/ic/mc146818reg.h>
43 #include <dev/tc/tcreg.h>
44 #include <dev/tc/tcvar.h>
45 #include <dev/tc/ioasicvar.h>                   /* XXX */
46 
47 struct mcclock_ioasic_clockdatum {
48 	u_char	datum;
49 	char	pad[3];
50 };
51 
52 struct mcclock_ioasic_softc {
53 	struct mcclock_softc	sc_mcclock;
54 
55 	struct mcclock_ioasic_clockdatum *sc_dp;
56 };
57 
58 int	mcclock_ioasic_match __P((struct device *, struct cfdata *, void *));
59 void	mcclock_ioasic_attach __P((struct device *, struct device *, void *));
60 
61 struct cfattach mcclock_ioasic_ca = {
62 	sizeof (struct mcclock_ioasic_softc), mcclock_ioasic_match,
63 	    mcclock_ioasic_attach,
64 };
65 
66 void	mcclock_ioasic_write __P((struct mcclock_softc *, u_int, u_int));
67 u_int	mcclock_ioasic_read __P((struct mcclock_softc *, u_int));
68 
69 const struct mcclock_busfns mcclock_ioasic_busfns = {
70 	mcclock_ioasic_write, mcclock_ioasic_read,
71 };
72 
73 int
74 mcclock_ioasic_match(parent, match, aux)
75 	struct device *parent;
76 	struct cfdata *match;
77 	void *aux;
78 {
79 	struct ioasicdev_attach_args *d = aux;
80 
81 	if (strncmp("TOY_RTC ", d->iada_modname, TC_ROM_LLEN))
82 		return (0);
83 
84 	return (1);
85 }
86 
87 void
88 mcclock_ioasic_attach(parent, self, aux)
89 	struct device *parent, *self;
90 	void *aux;
91 {
92 	struct ioasicdev_attach_args *ioasicdev = aux;
93 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)self;
94 
95 	sc->sc_dp = (struct mcclock_ioasic_clockdatum *)ioasicdev->iada_addr;
96 
97 	mcclock_attach(&sc->sc_mcclock, &mcclock_ioasic_busfns);
98 }
99 
100 void
101 mcclock_ioasic_write(dev, reg, datum)
102 	struct mcclock_softc *dev;
103 	u_int reg, datum;
104 {
105 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;
106 
107 	sc->sc_dp[reg].datum = datum;
108 }
109 
110 u_int
111 mcclock_ioasic_read(dev, reg)
112 	struct mcclock_softc *dev;
113 	u_int reg;
114 {
115 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;
116 
117 	return (sc->sc_dp[reg].datum);
118 }
119