pcctwo_68k.c revision 1.4 1 1.4 lukem /* $NetBSD: pcctwo_68k.c,v 1.4 2003/07/15 02:43:47 lukem Exp $ */
2 1.1 scw
3 1.1 scw /*-
4 1.1 scw * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
5 1.1 scw * All rights reserved.
6 1.1 scw *
7 1.1 scw * This code is derived from software contributed to The NetBSD Foundation
8 1.1 scw * by Steve C. Woodford.
9 1.1 scw *
10 1.1 scw * Redistribution and use in source and binary forms, with or without
11 1.1 scw * modification, are permitted provided that the following conditions
12 1.1 scw * are met:
13 1.1 scw * 1. Redistributions of source code must retain the above copyright
14 1.1 scw * notice, this list of conditions and the following disclaimer.
15 1.1 scw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 scw * notice, this list of conditions and the following disclaimer in the
17 1.1 scw * documentation and/or other materials provided with the distribution.
18 1.1 scw * 3. All advertising materials mentioning features or use of this software
19 1.1 scw * must display the following acknowledgement:
20 1.1 scw * This product includes software developed by the NetBSD
21 1.1 scw * Foundation, Inc. and its contributors.
22 1.1 scw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 scw * contributors may be used to endorse or promote products derived
24 1.1 scw * from this software without specific prior written permission.
25 1.1 scw *
26 1.1 scw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 scw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 scw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 scw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 scw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 scw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 scw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 scw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 scw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 scw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 scw * POSSIBILITY OF SUCH DAMAGE.
37 1.1 scw */
38 1.1 scw
39 1.1 scw /*
40 1.1 scw * PCCchip2 and MCchip Mvme68k Front End Driver
41 1.1 scw */
42 1.4 lukem
43 1.4 lukem #include <sys/cdefs.h>
44 1.4 lukem __KERNEL_RCSID(0, "$NetBSD: pcctwo_68k.c,v 1.4 2003/07/15 02:43:47 lukem Exp $");
45 1.1 scw
46 1.1 scw #include <sys/param.h>
47 1.1 scw #include <sys/kernel.h>
48 1.1 scw #include <sys/systm.h>
49 1.1 scw #include <sys/device.h>
50 1.1 scw
51 1.1 scw #include <machine/cpu.h>
52 1.1 scw #include <machine/bus.h>
53 1.1 scw
54 1.1 scw #include <mvme68k/dev/mainbus.h>
55 1.1 scw #include <mvme68k/mvme68k/isr.h>
56 1.1 scw
57 1.1 scw #include <dev/mvme/pcctworeg.h>
58 1.1 scw #include <dev/mvme/pcctwovar.h>
59 1.1 scw
60 1.1 scw /*
61 1.1 scw * Autoconfiguration stuff.
62 1.1 scw */
63 1.1 scw void pcctwoattach(struct device *, struct device *, void *);
64 1.1 scw int pcctwomatch(struct device *, struct cfdata *, void *);
65 1.1 scw
66 1.3 thorpej CFATTACH_DECL(pcctwo, sizeof(struct pcctwo_softc),
67 1.3 thorpej pcctwomatch, pcctwoattach, NULL, NULL);
68 1.1 scw
69 1.1 scw extern struct cfdriver pcctwo_cd;
70 1.1 scw
71 1.1 scw
72 1.1 scw #if defined(MVME167) || defined(MVME177)
73 1.1 scw /*
74 1.1 scw * Devices that live on the PCCchip2, attached in this order.
75 1.1 scw */
76 1.1 scw static struct pcctwo_device pcctwo_devices[] = {
77 1.1 scw {"clock", 0},
78 1.1 scw {"clmpcc", PCCTWO_SCC_OFF},
79 1.1 scw {"ie", PCCTWO_IE_OFF},
80 1.1 scw {"osiop", PCCTWO_NCRSC_OFF},
81 1.1 scw {"lpt", PCCTWO_LPT_OFF},
82 1.1 scw {NULL, 0}
83 1.1 scw };
84 1.1 scw
85 1.1 scw static int pcctwo_vec2icsr_1x7[] = {
86 1.1 scw VEC2ICSR(PCC2REG_PRT_BUSY_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
87 1.1 scw VEC2ICSR(PCC2REG_PRT_PE_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
88 1.1 scw VEC2ICSR(PCC2REG_PRT_SEL_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
89 1.1 scw VEC2ICSR(PCC2REG_PRT_FAULT_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
90 1.1 scw VEC2ICSR(PCC2REG_PRT_ACK_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
91 1.1 scw VEC2ICSR(PCC2REG_SCSI_ICSR, 0),
92 1.1 scw VEC2ICSR(PCC2REG_ETH_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
93 1.1 scw VEC2ICSR(PCC2REG_ETH_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
94 1.1 scw VEC2ICSR(PCC2REG_TIMER2_ICSR, PCCTWO_ICR_ICLR),
95 1.1 scw VEC2ICSR(PCC2REG_TIMER1_ICSR, PCCTWO_ICR_ICLR),
96 1.1 scw VEC2ICSR(PCC2REG_GPIO_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
97 1.1 scw -1,
98 1.1 scw VEC2ICSR(PCC2REG_SCC_RX_ICSR, 0),
99 1.1 scw VEC2ICSR(PCC2REG_SCC_MODEM_ICSR, 0),
100 1.1 scw VEC2ICSR(PCC2REG_SCC_TX_ICSR, 0),
101 1.1 scw VEC2ICSR(PCC2REG_SCC_RX_ICSR, 0)
102 1.1 scw };
103 1.1 scw #endif
104 1.1 scw
105 1.1 scw #if defined(MVME162) || defined(MVME172)
106 1.1 scw /*
107 1.1 scw * Devices that live on the MCchip, attached in this order.
108 1.1 scw */
109 1.1 scw static struct pcctwo_device mcchip_devices[] = {
110 1.1 scw {"clock", 0},
111 1.1 scw {"zsc", MCCHIP_ZS0_OFF},
112 1.1 scw {"zsc", MCCHIP_ZS1_OFF},
113 1.1 scw {"ie", PCCTWO_IE_OFF},
114 1.1 scw {"osiop", PCCTWO_NCRSC_OFF},
115 1.1 scw {NULL, 0}
116 1.1 scw };
117 1.1 scw
118 1.1 scw static int pcctwo_vec2icsr_1x2[] = {
119 1.1 scw -1,
120 1.1 scw -1,
121 1.1 scw -1,
122 1.1 scw VEC2ICSR(MCCHIPREG_TIMER4_ICSR, PCCTWO_ICR_ICLR),
123 1.1 scw VEC2ICSR(MCCHIPREG_TIMER3_ICSR, PCCTWO_ICR_ICLR),
124 1.1 scw VEC2ICSR(PCC2REG_SCSI_ICSR, 0),
125 1.1 scw VEC2ICSR(PCC2REG_ETH_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
126 1.1 scw VEC2ICSR(PCC2REG_ETH_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
127 1.1 scw VEC2ICSR(PCC2REG_TIMER2_ICSR, PCCTWO_ICR_ICLR),
128 1.1 scw VEC2ICSR(PCC2REG_TIMER1_ICSR, PCCTWO_ICR_ICLR),
129 1.1 scw -1,
130 1.1 scw VEC2ICSR(MCCHIPREG_PARERR_ICSR, PCCTWO_ICR_ICLR),
131 1.1 scw VEC2ICSR(MCCHIPREG_SCC_ICSR, 0),
132 1.1 scw VEC2ICSR(MCCHIPREG_SCC_ICSR, 0),
133 1.1 scw VEC2ICSR(MCCHIPREG_ABORT_ICSR, PCCTWO_ICR_ICLR),
134 1.1 scw -1
135 1.1 scw };
136 1.1 scw
137 1.1 scw static int pcctwoabortintr(void *);
138 1.1 scw void pcctwosoftintrinit(void);
139 1.1 scw static int pcctwosoftintr(void *);
140 1.1 scw static void pcctwosoftintrassert(void);
141 1.1 scw #endif
142 1.1 scw
143 1.1 scw static void pcctwoisrlink(void *, int (*)(void *), void *,
144 1.1 scw int, int, struct evcnt *);
145 1.1 scw static void pcctwoisrunlink(void *, int);
146 1.1 scw static struct evcnt *pcctwoisrevcnt(void *, int);
147 1.1 scw
148 1.1 scw
149 1.1 scw /* ARGSUSED */
150 1.1 scw int
151 1.1 scw pcctwomatch(parent, cf, args)
152 1.1 scw struct device *parent;
153 1.1 scw struct cfdata *cf;
154 1.1 scw void *args;
155 1.1 scw {
156 1.1 scw struct mainbus_attach_args *ma;
157 1.1 scw bus_space_handle_t bh;
158 1.1 scw u_int8_t cid;
159 1.1 scw
160 1.1 scw ma = args;
161 1.1 scw
162 1.1 scw /* There can be only one. */
163 1.1 scw if (sys_pcctwo || strcmp(ma->ma_name, pcctwo_cd.cd_name))
164 1.1 scw return (0);
165 1.1 scw
166 1.1 scw /*
167 1.1 scw * Grab the Chip's ID
168 1.1 scw */
169 1.1 scw bus_space_map(ma->ma_bust, PCCTWO_REG_OFF + ma->ma_offset,
170 1.1 scw PCC2REG_SIZE, 0, &bh);
171 1.1 scw cid = bus_space_read_1(ma->ma_bust, bh, PCC2REG_CHIP_ID);
172 1.1 scw bus_space_unmap(ma->ma_bust, bh, PCC2REG_SIZE);
173 1.1 scw
174 1.1 scw #if defined(MVME167) || defined(MVME177)
175 1.1 scw if ((machineid == MVME_167 || machineid == MVME_177) &&
176 1.1 scw cid == PCCTWO_CHIP_ID_PCC2)
177 1.1 scw return (1);
178 1.1 scw #endif
179 1.1 scw #if defined(MVME162) || defined(MVME172)
180 1.1 scw if ((machineid == MVME_162 || machineid == MVME_172) &&
181 1.1 scw cid == PCCTWO_CHIP_ID_MCCHIP)
182 1.1 scw return (1);
183 1.1 scw #endif
184 1.1 scw
185 1.1 scw return (0);
186 1.1 scw }
187 1.1 scw
188 1.1 scw /* ARGSUSED */
189 1.1 scw void
190 1.1 scw pcctwoattach(parent, self, args)
191 1.1 scw struct device *parent;
192 1.1 scw struct device *self;
193 1.1 scw void *args;
194 1.1 scw {
195 1.1 scw struct mainbus_attach_args *ma;
196 1.1 scw struct pcctwo_softc *sc;
197 1.1 scw struct pcctwo_device *pd = NULL;
198 1.1 scw u_int8_t cid;
199 1.1 scw
200 1.1 scw ma = args;
201 1.1 scw sc = sys_pcctwo = (struct pcctwo_softc *) self;
202 1.1 scw
203 1.1 scw /* Get a handle to the PCCChip2's registers */
204 1.1 scw sc->sc_bust = ma->ma_bust;
205 1.1 scw sc->sc_dmat = ma->ma_dmat;
206 1.1 scw bus_space_map(sc->sc_bust, PCCTWO_REG_OFF + ma->ma_offset,
207 1.1 scw PCC2REG_SIZE, 0, &sc->sc_bush);
208 1.1 scw
209 1.1 scw sc->sc_vecbase = PCCTWO_VECBASE;
210 1.1 scw sc->sc_isrlink = pcctwoisrlink;
211 1.1 scw sc->sc_isrevcnt = pcctwoisrevcnt;
212 1.1 scw sc->sc_isrunlink = pcctwoisrunlink;
213 1.1 scw
214 1.1 scw cid = pcc2_reg_read(sc, PCC2REG_CHIP_ID);
215 1.1 scw
216 1.1 scw #if defined(MVME167) || defined(MVME177)
217 1.1 scw if (cid == PCCTWO_CHIP_ID_PCC2) {
218 1.1 scw pd = pcctwo_devices;
219 1.1 scw sc->sc_vec2icsr = pcctwo_vec2icsr_1x7;
220 1.1 scw }
221 1.1 scw #endif
222 1.1 scw #if defined(MVME162) || defined(MVME172)
223 1.1 scw if (cid == PCCTWO_CHIP_ID_MCCHIP) {
224 1.1 scw pd = mcchip_devices;
225 1.1 scw sc->sc_vec2icsr = pcctwo_vec2icsr_1x2;
226 1.1 scw }
227 1.1 scw #endif
228 1.1 scw
229 1.1 scw /* Finish initialisation in common code */
230 1.1 scw pcctwo_init(sc, pd, ma->ma_offset);
231 1.1 scw
232 1.1 scw #if defined(MVME162) || defined(MVME172)
233 1.1 scw if (cid == PCCTWO_CHIP_ID_MCCHIP) {
234 1.1 scw evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR,
235 1.1 scw isrlink_evcnt(7), "nmi", "abort sw");
236 1.1 scw pcctwointr_establish(MCCHIPV_ABORT, pcctwoabortintr, 7, NULL,
237 1.1 scw &sc->sc_evcnt);
238 1.1 scw }
239 1.1 scw #endif
240 1.1 scw }
241 1.1 scw
242 1.1 scw /* ARGSUSED */
243 1.1 scw static void
244 1.1 scw pcctwoisrlink(cookie, fn, arg, ipl, vec, evcnt)
245 1.1 scw void *cookie;
246 1.1 scw int (*fn)(void *);
247 1.1 scw void *arg;
248 1.1 scw int ipl, vec;
249 1.1 scw struct evcnt *evcnt;
250 1.1 scw {
251 1.1 scw
252 1.1 scw isrlink_vectored(fn, arg, ipl, vec, evcnt);
253 1.1 scw }
254 1.1 scw
255 1.1 scw /* ARGSUSED */
256 1.1 scw static void
257 1.1 scw pcctwoisrunlink(cookie, vec)
258 1.1 scw void *cookie;
259 1.1 scw int vec;
260 1.1 scw {
261 1.1 scw
262 1.1 scw isrunlink_vectored(vec);
263 1.1 scw }
264 1.1 scw
265 1.1 scw /* ARGSUSED */
266 1.1 scw static struct evcnt *
267 1.1 scw pcctwoisrevcnt(cookie, ipl)
268 1.1 scw void *cookie;
269 1.1 scw int ipl;
270 1.1 scw {
271 1.1 scw
272 1.1 scw return (isrlink_evcnt(ipl));
273 1.1 scw }
274 1.1 scw
275 1.1 scw #if defined(MVME162) || defined(MVME172)
276 1.1 scw static int
277 1.1 scw pcctwoabortintr(void *frame)
278 1.1 scw {
279 1.1 scw
280 1.1 scw pcc2_reg_write(sys_pcctwo, MCCHIPREG_ABORT_ICSR, PCCTWO_ICR_ICLR |
281 1.1 scw pcc2_reg_read(sys_pcctwo, MCCHIPREG_ABORT_ICSR));
282 1.1 scw
283 1.1 scw return (nmihand(frame));
284 1.1 scw }
285 1.1 scw
286 1.1 scw void
287 1.1 scw pcctwosoftintrinit(void)
288 1.1 scw {
289 1.1 scw
290 1.1 scw /*
291 1.1 scw * Since the VMEChip2 is normally used to generate
292 1.1 scw * software interrupts to the CPU, we have to deal
293 1.1 scw * with 162/172 boards which have the "No VMEChip2"
294 1.1 scw * build option.
295 1.1 scw *
296 1.1 scw * When such a board is found, the VMEChip2 probe code
297 1.1 scw * calls this function to implement software interrupts
298 1.1 scw * the hard way; using tick timer 4 ...
299 1.1 scw */
300 1.1 scw pcctwointr_establish(MCCHIPV_TIMER4, pcctwosoftintr,
301 1.1 scw 1, sys_pcctwo, &sys_pcctwo->sc_evcnt);
302 1.1 scw pcc2_reg_write(sys_pcctwo, MCCHIPREG_TIMER4_CTRL, 0);
303 1.1 scw pcc2_reg_write32(sys_pcctwo, MCCHIPREG_TIMER4_COMP, 1);
304 1.1 scw pcc2_reg_write32(sys_pcctwo, MCCHIPREG_TIMER4_CNTR, 0);
305 1.1 scw _softintr_chipset_assert = pcctwosoftintrassert;
306 1.1 scw }
307 1.1 scw
308 1.1 scw static int
309 1.1 scw pcctwosoftintr(void *arg)
310 1.1 scw {
311 1.1 scw struct pcctwo_softc *sc = arg;
312 1.1 scw
313 1.1 scw pcc2_reg_write32(sc, MCCHIPREG_TIMER4_CNTR, 0);
314 1.1 scw pcc2_reg_write(sc, MCCHIPREG_TIMER4_CTRL, 0);
315 1.1 scw pcc2_reg_write(sc, MCCHIPREG_TIMER4_ICSR,
316 1.1 scw PCCTWO_ICR_ICLR | PCCTWO_ICR_IEN | 1);
317 1.1 scw
318 1.1 scw softintr_dispatch();
319 1.1 scw
320 1.1 scw return (1);
321 1.1 scw }
322 1.1 scw
323 1.1 scw static void
324 1.1 scw pcctwosoftintrassert(void)
325 1.1 scw {
326 1.1 scw
327 1.1 scw /*
328 1.1 scw * Schedule a timer interrupt to happen in ~1uS.
329 1.1 scw * This is more than adequate on any available m68k platform
330 1.1 scw * for simulating software interrupts.
331 1.1 scw */
332 1.1 scw pcc2_reg_write(sys_pcctwo, MCCHIPREG_TIMER4_CTRL, PCCTWO_TT_CTRL_CEN);
333 1.1 scw }
334 1.1 scw #endif
335