xref: /netbsd-src/sys/arch/pmax/tc/mcclock_ioasic.c (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1 /* $NetBSD: mcclock_ioasic.c,v 1.4 1997/08/06 12:03:39 jonathan 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 <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
31 
32 __KERNEL_RCSID(0, "$NetBSD: mcclock_ioasic.c,v 1.4 1997/08/06 12:03:39 jonathan 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/autoconf.h>
40 #include <dev/dec/clockvar.h>
41 #include <dev/dec/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), (void *)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 
74 int
75 mcclock_ioasic_match(parent, match, aux)
76 	struct device *parent;
77 	struct cfdata *match;
78 	void *aux;
79 {
80 #define	CFMATCH(cf,x) !strcmp((cf)->dv_cfdata->cf_driver->cd_name,(x))
81 	char *name;
82 	vm_offset_t addr;
83 
84 	if (CFMATCH(parent, "mainbus")) {
85 		struct confargs *ca = aux;
86 		addr = (vm_offset_t)ca->ca_addr;
87 		name = ca->ca_name;
88 	}
89 	else
90 	if (CFMATCH(parent, "asic")) {
91 		struct ioasicdev_attach_args *d = aux;
92 		addr = d->iada_addr;
93 		name = d->iada_modname;
94 	}
95 	else {
96 		/*panic("clock must be attached with mainbus or ioasic\n");*/
97 		printf("clock on %s: must be attached at mainbus or ioasic\n",
98 		       parent->dv_cfdata->cf_driver->cd_name);
99 		return(0);
100 	}
101 	if (strcmp("mc146818", name))
102 		return (0);
103 	return (1);
104 #undef	CFMATCH
105 }
106 
107 void
108 mcclock_ioasic_attach(parent, self, aux)
109 	struct device *parent, *self;
110 	void *aux;
111 {
112 	struct ioasicdev_attach_args *ioasicdev = aux;
113 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)self;
114 
115 	sc->sc_dp = (struct mcclock_ioasic_clockdatum *)ioasicdev->iada_addr;
116 
117 	mcclock_attach(&sc->sc_mcclock, &mcclock_ioasic_busfns);
118 }
119 
120 void
121 mcclock_ioasic_write(dev, reg, datum)
122 	struct mcclock_softc *dev;
123 	u_int reg, datum;
124 {
125 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;
126 
127 	sc->sc_dp[reg].datum = datum;
128 }
129 
130 u_int
131 mcclock_ioasic_read(dev, reg)
132 	struct mcclock_softc *dev;
133 	u_int reg;
134 {
135 	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;
136 
137 	return (sc->sc_dp[reg].datum);
138 }
139 
140 /*XXX*/
141 /*
142  * Wait "n" microseconds. (scsi code needs this).
143  */
144 void
145 delay(n)
146         int n;
147 {
148         DELAY(n);
149 }
150