jazzio.c revision 1.9 1 1.9 tsutsui /* $NetBSD: jazzio.c,v 1.9 2003/02/10 11:43:29 tsutsui Exp $ */
2 1.1 ur /* $OpenBSD: picabus.c,v 1.11 1999/01/11 05:11:10 millert Exp $ */
3 1.1 ur /* NetBSD: tc.c,v 1.2 1995/03/08 00:39:05 cgd Exp */
4 1.1 ur
5 1.1 ur /*
6 1.1 ur * Copyright (c) 1994, 1995 Carnegie-Mellon University.
7 1.1 ur * All rights reserved.
8 1.1 ur *
9 1.1 ur * Author: Chris G. Demetriou
10 1.1 ur * Author: Per Fogelstrom. (Mips R4x00)
11 1.1 ur *
12 1.1 ur * Permission to use, copy, modify and distribute this software and
13 1.1 ur * its documentation is hereby granted, provided that both the copyright
14 1.1 ur * notice and this permission notice appear in all copies of the
15 1.1 ur * software, derivative works or modified versions, and any portions
16 1.1 ur * thereof, and that both notices appear in supporting documentation.
17 1.1 ur *
18 1.1 ur * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
19 1.1 ur * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
20 1.1 ur * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
21 1.1 ur *
22 1.1 ur * Carnegie Mellon requests users of this software to return to
23 1.1 ur *
24 1.1 ur * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
25 1.1 ur * School of Computer Science
26 1.1 ur * Carnegie Mellon University
27 1.1 ur * Pittsburgh PA 15213-3890
28 1.1 ur *
29 1.1 ur * any improvements or extensions that they make and grant Carnegie the
30 1.1 ur * rights to redistribute these changes.
31 1.1 ur */
32 1.1 ur
33 1.1 ur #include <sys/param.h>
34 1.1 ur #include <sys/systm.h>
35 1.1 ur #include <sys/device.h>
36 1.1 ur
37 1.1 ur #include <machine/bus.h>
38 1.1 ur #include <machine/pio.h>
39 1.1 ur #include <machine/autoconf.h>
40 1.5 soda #include <machine/platform.h>
41 1.1 ur
42 1.1 ur #include <arc/jazz/jazziovar.h>
43 1.1 ur #include <arc/jazz/pica.h>
44 1.1 ur #include <arc/jazz/jazzdmatlbreg.h>
45 1.9 tsutsui #include <arc/jazz/jazzdmatlbvar.h>
46 1.1 ur #include <arc/jazz/dma.h>
47 1.5 soda #include <arc/jazz/pckbc_jazzioreg.h>
48 1.5 soda
49 1.5 soda void arc_sysreset __P((bus_addr_t, bus_size_t));
50 1.1 ur
51 1.1 ur struct jazzio_softc {
52 1.1 ur struct device sc_dv;
53 1.1 ur struct abus sc_bus;
54 1.1 ur struct arc_bus_dma_tag sc_dmat;
55 1.1 ur struct pica_dev *sc_devs;
56 1.1 ur };
57 1.1 ur
58 1.1 ur /* Definition of the driver for autoconfig. */
59 1.1 ur int jazziomatch(struct device *, struct cfdata *, void *);
60 1.1 ur void jazzioattach(struct device *, struct device *, void *);
61 1.1 ur int jazzioprint(void *, const char *);
62 1.1 ur
63 1.7 thorpej CFATTACH_DECL(jazzio, sizeof(struct jazzio_softc),
64 1.7 thorpej jazziomatch, jazzioattach, NULL, NULL);
65 1.1 ur extern struct cfdriver jazzio_cd;
66 1.1 ur
67 1.1 ur void jazzio_intr_establish(int, int (*)(void *), void *);
68 1.1 ur void jazzio_intr_disestablish(int);
69 1.5 soda int jazzio_intr(unsigned, struct clockframe *);
70 1.5 soda int jazzio_no_handler __P((void *));
71 1.1 ur
72 1.1 ur /*
73 1.5 soda * Interrupt dispatch table for jazz i/o bus.
74 1.1 ur */
75 1.5 soda struct jazzio_intr_registry {
76 1.5 soda intr_handler_t int_hand; /* Interrupt handler */
77 1.5 soda void *param; /* Parameter to send to handler */
78 1.5 soda };
79 1.5 soda
80 1.5 soda struct jazzio_intr_registry jazzio_intrtab[] = {
81 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 0 */
82 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 1 */
83 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 2 */
84 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 3 */
85 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 4 */
86 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 5 */
87 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 6 */
88 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 7 */
89 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 8 */
90 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 9 */
91 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 10 */
92 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 11 */
93 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 12 */
94 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 13 */
95 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 14 */
96 1.5 soda { jazzio_no_handler, (void *)NULL, }, /* 15 */
97 1.1 ur };
98 1.1 ur
99 1.1 ur
100 1.5 soda struct jazzio_config *jazzio_conf = NULL;
101 1.5 soda struct pica_dev *jazzio_devconfig = NULL;
102 1.1 ur int jazzio_found = 0;
103 1.5 soda int jazzio_int_mask = 0; /* jazz i/o interrupt enable mask */
104 1.1 ur
105 1.5 soda struct arc_bus_space jazzio_bus;
106 1.1 ur
107 1.1 ur int
108 1.1 ur jazziomatch(parent, match, aux)
109 1.1 ur struct device *parent;
110 1.1 ur struct cfdata *match;
111 1.1 ur void *aux;
112 1.1 ur {
113 1.1 ur struct confargs *ca = aux;
114 1.1 ur
115 1.5 soda /* Make sure that we're looking for a jazzio bus. */
116 1.1 ur if (strcmp(ca->ca_name, jazzio_cd.cd_name) != 0)
117 1.1 ur return (0);
118 1.1 ur
119 1.1 ur return (1);
120 1.1 ur }
121 1.1 ur
122 1.1 ur void
123 1.1 ur jazzioattach(parent, self, aux)
124 1.1 ur struct device *parent;
125 1.1 ur struct device *self;
126 1.1 ur void *aux;
127 1.1 ur {
128 1.1 ur struct jazzio_softc *sc = (struct jazzio_softc *)self;
129 1.1 ur struct jazzio_attach_args ja;
130 1.1 ur int i;
131 1.1 ur
132 1.5 soda if (jazzio_conf == NULL)
133 1.5 soda panic("jazzio_conf isn't initialized");
134 1.5 soda if (jazzio_devconfig == NULL)
135 1.5 soda panic("jazzio_devconfig isn't initialized");
136 1.1 ur
137 1.1 ur jazzio_found = 1;
138 1.1 ur
139 1.5 soda printf("\n");
140 1.5 soda
141 1.1 ur /* keep our CPU device description handy */
142 1.5 soda sc->sc_devs = jazzio_devconfig;
143 1.1 ur
144 1.1 ur /* set up interrupt handlers */
145 1.5 soda (*platform->set_intr)(MIPS_INT_MASK_1, jazzio_intr, 2);
146 1.1 ur
147 1.1 ur sc->sc_bus.ab_dv = (struct device *)sc;
148 1.1 ur
149 1.9 tsutsui /* Initialize jazzio dma mapping register area and pool */
150 1.9 tsutsui jazz_dmatlb_init(&jazzio_bus, jazzio_conf->jc_dmatlbreg);
151 1.1 ur
152 1.1 ur /* Create bus_dma_tag */
153 1.1 ur jazz_bus_dma_tag_init(&sc->sc_dmat);
154 1.1 ur
155 1.5 soda /* Try to configure each jazzio attached device */
156 1.5 soda for (i = 0; sc->sc_devs[i].ps_ca.ca_name != NULL; i++) {
157 1.1 ur
158 1.1 ur ja.ja_name = sc->sc_devs[i].ps_ca.ca_name;
159 1.1 ur ja.ja_bus = &sc->sc_bus;
160 1.5 soda ja.ja_bust = &jazzio_bus;
161 1.1 ur ja.ja_dmat = &sc->sc_dmat;
162 1.1 ur ja.ja_addr = (bus_addr_t)sc->sc_devs[i].ps_base;
163 1.1 ur ja.ja_intr = sc->sc_devs[i].ps_ca.ca_slot;
164 1.1 ur ja.ja_dma = 0;
165 1.1 ur
166 1.1 ur /* Tell the autoconfig machinery we've found the hardware. */
167 1.1 ur config_found(self, &ja, jazzioprint);
168 1.1 ur }
169 1.1 ur }
170 1.1 ur
171 1.1 ur int
172 1.1 ur jazzioprint(aux, pnp)
173 1.1 ur void *aux;
174 1.1 ur const char *pnp;
175 1.1 ur {
176 1.1 ur struct jazzio_attach_args *ja = aux;
177 1.1 ur
178 1.5 soda if (pnp)
179 1.8 thorpej aprint_normal("%s at %s", ja->ja_name, pnp);
180 1.8 thorpej aprint_normal(" addr 0x%lx", ja->ja_addr);
181 1.5 soda if (ja->ja_intr != -1)
182 1.8 thorpej aprint_normal(" intr %d", ja->ja_intr);
183 1.5 soda return (UNCONF);
184 1.1 ur }
185 1.1 ur
186 1.1 ur void
187 1.5 soda jazzio_intr_establish(intr, handler, val)
188 1.5 soda int intr;
189 1.1 ur intr_handler_t handler;
190 1.1 ur void *val;
191 1.1 ur {
192 1.5 soda if (intr < 0 ||
193 1.5 soda intr >= sizeof(jazzio_intrtab)/sizeof(jazzio_intrtab[0])) {
194 1.5 soda panic("jazzio intr %d out of range", intr);
195 1.5 soda } else if (jazzio_intrtab[intr].int_hand != jazzio_no_handler) {
196 1.5 soda panic("jazzio intr %d already set to %p", intr,
197 1.5 soda jazzio_intrtab[intr].int_hand);
198 1.4 tsutsui } else {
199 1.5 soda jazzio_int_mask |= 1 << intr;
200 1.5 soda jazzio_intrtab[intr].int_hand = handler;
201 1.5 soda jazzio_intrtab[intr].param = val;
202 1.1 ur }
203 1.1 ur
204 1.5 soda (*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask);
205 1.1 ur }
206 1.1 ur
207 1.1 ur void
208 1.5 soda jazzio_intr_disestablish(intr)
209 1.5 soda int intr;
210 1.1 ur {
211 1.5 soda jazzio_int_mask &= ~(1 << intr);
212 1.5 soda jazzio_intrtab[intr].int_hand = jazzio_no_handler;
213 1.5 soda jazzio_intrtab[intr].param = (void *)NULL;
214 1.1 ur
215 1.5 soda (*jazzio_conf->jc_set_iointr_mask)(jazzio_int_mask);
216 1.1 ur }
217 1.1 ur
218 1.1 ur int
219 1.5 soda jazzio_no_handler(arg)
220 1.5 soda void *arg;
221 1.1 ur {
222 1.5 soda panic("uncaught jazzio interrupt with arg %p", arg);
223 1.1 ur }
224 1.1 ur
225 1.1 ur /*
226 1.5 soda * Handle jazz i/o interrupt.
227 1.1 ur */
228 1.1 ur int
229 1.5 soda jazzio_intr(mask, cf)
230 1.1 ur unsigned mask;
231 1.1 ur struct clockframe *cf;
232 1.1 ur {
233 1.5 soda unsigned int vector;
234 1.5 soda struct jazzio_intr_registry *jirp;
235 1.1 ur
236 1.5 soda while ((vector = inb(jazzio_conf->jc_iointr_status_reg)) != 0) {
237 1.5 soda jirp = &jazzio_intrtab[(vector >> 2) - 1];
238 1.5 soda (*jirp->int_hand)(jirp->param);
239 1.1 ur }
240 1.4 tsutsui return (~0); /* Dont reenable */
241 1.1 ur }
242 1.1 ur
243 1.5 soda void
244 1.5 soda jazzio_reset()
245 1.1 ur {
246 1.5 soda arc_sysreset(PICA_SYS_KBD, JAZZIO_KBCMDP);
247 1.1 ur }
248