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