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