pcctwo_68k.c revision 1.8 1 1.8 tsutsui /* $NetBSD: pcctwo_68k.c,v 1.8 2008/01/12 09:54:24 tsutsui 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.8 tsutsui __KERNEL_RCSID(0, "$NetBSD: pcctwo_68k.c,v 1.8 2008/01/12 09:54:24 tsutsui 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.8 tsutsui #include "ioconf.h"
61 1.8 tsutsui
62 1.1 scw /*
63 1.1 scw * Autoconfiguration stuff.
64 1.1 scw */
65 1.1 scw void pcctwoattach(struct device *, struct device *, void *);
66 1.1 scw int pcctwomatch(struct device *, struct cfdata *, void *);
67 1.1 scw
68 1.3 thorpej CFATTACH_DECL(pcctwo, sizeof(struct pcctwo_softc),
69 1.3 thorpej pcctwomatch, pcctwoattach, NULL, NULL);
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.5 scw static const 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.5 scw static const 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.7 ad #ifdef notyet
141 1.1 scw static void pcctwosoftintrassert(void);
142 1.1 scw #endif
143 1.7 ad #endif
144 1.1 scw
145 1.1 scw static void pcctwoisrlink(void *, int (*)(void *), void *,
146 1.1 scw int, int, struct evcnt *);
147 1.1 scw static void pcctwoisrunlink(void *, int);
148 1.1 scw static struct evcnt *pcctwoisrevcnt(void *, int);
149 1.1 scw
150 1.1 scw
151 1.1 scw /* ARGSUSED */
152 1.1 scw int
153 1.8 tsutsui pcctwomatch(struct device *parent, struct cfdata *cf, void *args)
154 1.1 scw {
155 1.1 scw struct mainbus_attach_args *ma;
156 1.1 scw bus_space_handle_t bh;
157 1.8 tsutsui uint8_t cid;
158 1.1 scw
159 1.1 scw ma = args;
160 1.1 scw
161 1.1 scw /* There can be only one. */
162 1.1 scw if (sys_pcctwo || strcmp(ma->ma_name, pcctwo_cd.cd_name))
163 1.8 tsutsui return 0;
164 1.1 scw
165 1.1 scw /*
166 1.1 scw * Grab the Chip's ID
167 1.1 scw */
168 1.1 scw bus_space_map(ma->ma_bust, PCCTWO_REG_OFF + ma->ma_offset,
169 1.1 scw PCC2REG_SIZE, 0, &bh);
170 1.1 scw cid = bus_space_read_1(ma->ma_bust, bh, PCC2REG_CHIP_ID);
171 1.1 scw bus_space_unmap(ma->ma_bust, bh, PCC2REG_SIZE);
172 1.1 scw
173 1.1 scw #if defined(MVME167) || defined(MVME177)
174 1.1 scw if ((machineid == MVME_167 || machineid == MVME_177) &&
175 1.1 scw cid == PCCTWO_CHIP_ID_PCC2)
176 1.8 tsutsui return 1;
177 1.1 scw #endif
178 1.1 scw #if defined(MVME162) || defined(MVME172)
179 1.1 scw if ((machineid == MVME_162 || machineid == MVME_172) &&
180 1.1 scw cid == PCCTWO_CHIP_ID_MCCHIP)
181 1.8 tsutsui return 1;
182 1.1 scw #endif
183 1.1 scw
184 1.8 tsutsui return 0;
185 1.1 scw }
186 1.1 scw
187 1.1 scw /* ARGSUSED */
188 1.1 scw void
189 1.8 tsutsui pcctwoattach(struct device *parent, struct device *self, void *args)
190 1.1 scw {
191 1.1 scw struct mainbus_attach_args *ma;
192 1.1 scw struct pcctwo_softc *sc;
193 1.5 scw const struct pcctwo_device *pd = NULL;
194 1.8 tsutsui uint8_t cid;
195 1.1 scw
196 1.1 scw ma = args;
197 1.8 tsutsui sc = sys_pcctwo = (struct pcctwo_softc *)self;
198 1.1 scw
199 1.1 scw /* Get a handle to the PCCChip2's registers */
200 1.1 scw sc->sc_bust = ma->ma_bust;
201 1.1 scw sc->sc_dmat = ma->ma_dmat;
202 1.1 scw bus_space_map(sc->sc_bust, PCCTWO_REG_OFF + ma->ma_offset,
203 1.1 scw PCC2REG_SIZE, 0, &sc->sc_bush);
204 1.1 scw
205 1.1 scw sc->sc_vecbase = PCCTWO_VECBASE;
206 1.1 scw sc->sc_isrlink = pcctwoisrlink;
207 1.1 scw sc->sc_isrevcnt = pcctwoisrevcnt;
208 1.1 scw sc->sc_isrunlink = pcctwoisrunlink;
209 1.1 scw
210 1.1 scw cid = pcc2_reg_read(sc, PCC2REG_CHIP_ID);
211 1.1 scw
212 1.1 scw #if defined(MVME167) || defined(MVME177)
213 1.1 scw if (cid == PCCTWO_CHIP_ID_PCC2) {
214 1.1 scw pd = pcctwo_devices;
215 1.1 scw sc->sc_vec2icsr = pcctwo_vec2icsr_1x7;
216 1.1 scw }
217 1.1 scw #endif
218 1.1 scw #if defined(MVME162) || defined(MVME172)
219 1.1 scw if (cid == PCCTWO_CHIP_ID_MCCHIP) {
220 1.1 scw pd = mcchip_devices;
221 1.1 scw sc->sc_vec2icsr = pcctwo_vec2icsr_1x2;
222 1.1 scw }
223 1.1 scw #endif
224 1.1 scw
225 1.1 scw /* Finish initialisation in common code */
226 1.1 scw pcctwo_init(sc, pd, ma->ma_offset);
227 1.1 scw
228 1.1 scw #if defined(MVME162) || defined(MVME172)
229 1.1 scw if (cid == PCCTWO_CHIP_ID_MCCHIP) {
230 1.1 scw evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR,
231 1.1 scw isrlink_evcnt(7), "nmi", "abort sw");
232 1.1 scw pcctwointr_establish(MCCHIPV_ABORT, pcctwoabortintr, 7, NULL,
233 1.1 scw &sc->sc_evcnt);
234 1.1 scw }
235 1.1 scw #endif
236 1.1 scw }
237 1.1 scw
238 1.1 scw /* ARGSUSED */
239 1.1 scw static void
240 1.8 tsutsui pcctwoisrlink(void *cookie, int (*fn)(void *), void *arg, int ipl, int vec,
241 1.8 tsutsui struct evcnt *evcnt)
242 1.1 scw {
243 1.1 scw
244 1.1 scw isrlink_vectored(fn, arg, ipl, vec, evcnt);
245 1.1 scw }
246 1.1 scw
247 1.1 scw /* ARGSUSED */
248 1.1 scw static void
249 1.8 tsutsui pcctwoisrunlink(void *cookie, int vec)
250 1.1 scw {
251 1.1 scw
252 1.1 scw isrunlink_vectored(vec);
253 1.1 scw }
254 1.1 scw
255 1.1 scw /* ARGSUSED */
256 1.1 scw static struct evcnt *
257 1.8 tsutsui pcctwoisrevcnt(void *cookie, int ipl)
258 1.1 scw {
259 1.1 scw
260 1.8 tsutsui return isrlink_evcnt(ipl);
261 1.1 scw }
262 1.1 scw
263 1.1 scw #if defined(MVME162) || defined(MVME172)
264 1.1 scw static int
265 1.1 scw pcctwoabortintr(void *frame)
266 1.1 scw {
267 1.1 scw
268 1.1 scw pcc2_reg_write(sys_pcctwo, MCCHIPREG_ABORT_ICSR, PCCTWO_ICR_ICLR |
269 1.1 scw pcc2_reg_read(sys_pcctwo, MCCHIPREG_ABORT_ICSR));
270 1.1 scw
271 1.8 tsutsui return nmihand(frame);
272 1.1 scw }
273 1.1 scw
274 1.1 scw void
275 1.1 scw pcctwosoftintrinit(void)
276 1.1 scw {
277 1.1 scw
278 1.1 scw /*
279 1.1 scw * Since the VMEChip2 is normally used to generate
280 1.1 scw * software interrupts to the CPU, we have to deal
281 1.1 scw * with 162/172 boards which have the "No VMEChip2"
282 1.1 scw * build option.
283 1.1 scw *
284 1.1 scw * When such a board is found, the VMEChip2 probe code
285 1.1 scw * calls this function to implement software interrupts
286 1.1 scw * the hard way; using tick timer 4 ...
287 1.1 scw */
288 1.1 scw pcctwointr_establish(MCCHIPV_TIMER4, pcctwosoftintr,
289 1.1 scw 1, sys_pcctwo, &sys_pcctwo->sc_evcnt);
290 1.1 scw pcc2_reg_write(sys_pcctwo, MCCHIPREG_TIMER4_CTRL, 0);
291 1.1 scw pcc2_reg_write32(sys_pcctwo, MCCHIPREG_TIMER4_COMP, 1);
292 1.1 scw pcc2_reg_write32(sys_pcctwo, MCCHIPREG_TIMER4_CNTR, 0);
293 1.7 ad #ifdef notyet
294 1.1 scw _softintr_chipset_assert = pcctwosoftintrassert;
295 1.7 ad #endif
296 1.1 scw }
297 1.1 scw
298 1.1 scw static int
299 1.1 scw pcctwosoftintr(void *arg)
300 1.1 scw {
301 1.1 scw struct pcctwo_softc *sc = arg;
302 1.1 scw
303 1.1 scw pcc2_reg_write32(sc, MCCHIPREG_TIMER4_CNTR, 0);
304 1.1 scw pcc2_reg_write(sc, MCCHIPREG_TIMER4_CTRL, 0);
305 1.1 scw pcc2_reg_write(sc, MCCHIPREG_TIMER4_ICSR,
306 1.1 scw PCCTWO_ICR_ICLR | PCCTWO_ICR_IEN | 1);
307 1.1 scw
308 1.7 ad #ifdef notyet
309 1.1 scw softintr_dispatch();
310 1.7 ad #endif
311 1.1 scw
312 1.8 tsutsui return 1;
313 1.1 scw }
314 1.1 scw
315 1.7 ad #ifdef notyet
316 1.1 scw static void
317 1.1 scw pcctwosoftintrassert(void)
318 1.1 scw {
319 1.1 scw
320 1.1 scw /*
321 1.1 scw * Schedule a timer interrupt to happen in ~1uS.
322 1.1 scw * This is more than adequate on any available m68k platform
323 1.1 scw * for simulating software interrupts.
324 1.1 scw */
325 1.1 scw pcc2_reg_write(sys_pcctwo, MCCHIPREG_TIMER4_CTRL, PCCTWO_TT_CTRL_CEN);
326 1.1 scw }
327 1.1 scw #endif
328 1.7 ad #endif
329