1 /* $NetBSD: pcctwo_68k.c,v 1.8 2008/01/12 09:54:24 tsutsui Exp $ */
4 * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
33 * PCCchip2 and MCchip Mvme68k Front End Driver
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: pcctwo_68k.c,v 1.8 2008/01/12 09:54:24 tsutsui Exp $");
39 #include <sys/param.h>
40 #include <sys/kernel.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
44 #include <machine/cpu.h>
45 #include <machine/bus.h>
47 #include <mvme68k/dev/mainbus.h>
48 #include <mvme68k/mvme68k/isr.h>
50 #include <dev/mvme/pcctworeg.h>
51 #include <dev/mvme/pcctwovar.h>
56 * Autoconfiguration stuff.
58 void pcctwoattach(struct device
*, struct device
*, void *);
59 int pcctwomatch(struct device
*, struct cfdata
*, void *);
61 CFATTACH_DECL(pcctwo
, sizeof(struct pcctwo_softc
),
62 pcctwomatch
, pcctwoattach
, NULL
, NULL
);
65 #if defined(MVME167) || defined(MVME177)
67 * Devices that live on the PCCchip2, attached in this order.
69 static const struct pcctwo_device pcctwo_devices
[] = {
71 {"clmpcc", PCCTWO_SCC_OFF
},
72 {"ie", PCCTWO_IE_OFF
},
73 {"osiop", PCCTWO_NCRSC_OFF
},
74 {"lpt", PCCTWO_LPT_OFF
},
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
),
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)
98 #if defined(MVME162) || defined(MVME172)
100 * Devices that live on the MCchip, attached in this order.
102 static const struct pcctwo_device mcchip_devices
[] = {
104 {"zsc", MCCHIP_ZS0_OFF
},
105 {"zsc", MCCHIP_ZS1_OFF
},
106 {"ie", PCCTWO_IE_OFF
},
107 {"osiop", PCCTWO_NCRSC_OFF
},
111 static int pcctwo_vec2icsr_1x2
[] = {
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
),
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
),
130 static int pcctwoabortintr(void *);
131 void pcctwosoftintrinit(void);
132 static int pcctwosoftintr(void *);
134 static void pcctwosoftintrassert(void);
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);
146 pcctwomatch(struct device
*parent
, struct cfdata
*cf
, void *args
)
148 struct mainbus_attach_args
*ma
;
149 bus_space_handle_t bh
;
154 /* There can be only one. */
155 if (sys_pcctwo
|| strcmp(ma
->ma_name
, pcctwo_cd
.cd_name
))
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
);
166 #if defined(MVME167) || defined(MVME177)
167 if ((machineid
== MVME_167
|| machineid
== MVME_177
) &&
168 cid
== PCCTWO_CHIP_ID_PCC2
)
171 #if defined(MVME162) || defined(MVME172)
172 if ((machineid
== MVME_162
|| machineid
== MVME_172
) &&
173 cid
== PCCTWO_CHIP_ID_MCCHIP
)
182 pcctwoattach(struct device
*parent
, struct device
*self
, void *args
)
184 struct mainbus_attach_args
*ma
;
185 struct pcctwo_softc
*sc
;
186 const struct pcctwo_device
*pd
= NULL
;
190 sc
= sys_pcctwo
= (struct pcctwo_softc
*)self
;
192 /* Get a handle to the PCCChip2's registers */
193 sc
->sc_bust
= ma
->ma_bust
;
194 sc
->sc_dmat
= ma
->ma_dmat
;
195 bus_space_map(sc
->sc_bust
, PCCTWO_REG_OFF
+ ma
->ma_offset
,
196 PCC2REG_SIZE
, 0, &sc
->sc_bush
);
198 sc
->sc_vecbase
= PCCTWO_VECBASE
;
199 sc
->sc_isrlink
= pcctwoisrlink
;
200 sc
->sc_isrevcnt
= pcctwoisrevcnt
;
201 sc
->sc_isrunlink
= pcctwoisrunlink
;
203 cid
= pcc2_reg_read(sc
, PCC2REG_CHIP_ID
);
205 #if defined(MVME167) || defined(MVME177)
206 if (cid
== PCCTWO_CHIP_ID_PCC2
) {
208 sc
->sc_vec2icsr
= pcctwo_vec2icsr_1x7
;
211 #if defined(MVME162) || defined(MVME172)
212 if (cid
== PCCTWO_CHIP_ID_MCCHIP
) {
214 sc
->sc_vec2icsr
= pcctwo_vec2icsr_1x2
;
218 /* Finish initialisation in common code */
219 pcctwo_init(sc
, pd
, ma
->ma_offset
);
221 #if defined(MVME162) || defined(MVME172)
222 if (cid
== PCCTWO_CHIP_ID_MCCHIP
) {
223 evcnt_attach_dynamic(&sc
->sc_evcnt
, EVCNT_TYPE_INTR
,
224 isrlink_evcnt(7), "nmi", "abort sw");
225 pcctwointr_establish(MCCHIPV_ABORT
, pcctwoabortintr
, 7, NULL
,
233 pcctwoisrlink(void *cookie
, int (*fn
)(void *), void *arg
, int ipl
, int vec
,
237 isrlink_vectored(fn
, arg
, ipl
, vec
, evcnt
);
242 pcctwoisrunlink(void *cookie
, int vec
)
245 isrunlink_vectored(vec
);
249 static struct evcnt
*
250 pcctwoisrevcnt(void *cookie
, int ipl
)
253 return isrlink_evcnt(ipl
);
256 #if defined(MVME162) || defined(MVME172)
258 pcctwoabortintr(void *frame
)
261 pcc2_reg_write(sys_pcctwo
, MCCHIPREG_ABORT_ICSR
, PCCTWO_ICR_ICLR
|
262 pcc2_reg_read(sys_pcctwo
, MCCHIPREG_ABORT_ICSR
));
264 return nmihand(frame
);
268 pcctwosoftintrinit(void)
272 * Since the VMEChip2 is normally used to generate
273 * software interrupts to the CPU, we have to deal
274 * with 162/172 boards which have the "No VMEChip2"
277 * When such a board is found, the VMEChip2 probe code
278 * calls this function to implement software interrupts
279 * the hard way; using tick timer 4 ...
281 pcctwointr_establish(MCCHIPV_TIMER4
, pcctwosoftintr
,
282 1, sys_pcctwo
, &sys_pcctwo
->sc_evcnt
);
283 pcc2_reg_write(sys_pcctwo
, MCCHIPREG_TIMER4_CTRL
, 0);
284 pcc2_reg_write32(sys_pcctwo
, MCCHIPREG_TIMER4_COMP
, 1);
285 pcc2_reg_write32(sys_pcctwo
, MCCHIPREG_TIMER4_CNTR
, 0);
287 _softintr_chipset_assert
= pcctwosoftintrassert
;
292 pcctwosoftintr(void *arg
)
294 struct pcctwo_softc
*sc
= arg
;
296 pcc2_reg_write32(sc
, MCCHIPREG_TIMER4_CNTR
, 0);
297 pcc2_reg_write(sc
, MCCHIPREG_TIMER4_CTRL
, 0);
298 pcc2_reg_write(sc
, MCCHIPREG_TIMER4_ICSR
,
299 PCCTWO_ICR_ICLR
| PCCTWO_ICR_IEN
| 1);
310 pcctwosoftintrassert(void)
314 * Schedule a timer interrupt to happen in ~1uS.
315 * This is more than adequate on any available m68k platform
316 * for simulating software interrupts.
318 pcc2_reg_write(sys_pcctwo
, MCCHIPREG_TIMER4_CTRL
, PCCTWO_TT_CTRL_CEN
);