Home | History | Annotate | Line # | Download | only in dev
pcctwo_68k.c revision 1.1
      1  1.1  scw /*	$NetBSD: pcctwo_68k.c,v 1.1 2002/02/12 20:38:25 scw 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.1  scw 
     43  1.1  scw #include <sys/param.h>
     44  1.1  scw #include <sys/kernel.h>
     45  1.1  scw #include <sys/systm.h>
     46  1.1  scw #include <sys/device.h>
     47  1.1  scw 
     48  1.1  scw #include <machine/cpu.h>
     49  1.1  scw #include <machine/bus.h>
     50  1.1  scw 
     51  1.1  scw #include <mvme68k/dev/mainbus.h>
     52  1.1  scw #include <mvme68k/mvme68k/isr.h>
     53  1.1  scw 
     54  1.1  scw #include <dev/mvme/pcctworeg.h>
     55  1.1  scw #include <dev/mvme/pcctwovar.h>
     56  1.1  scw 
     57  1.1  scw /*
     58  1.1  scw  * Autoconfiguration stuff.
     59  1.1  scw  */
     60  1.1  scw void pcctwoattach(struct device *, struct device *, void *);
     61  1.1  scw int pcctwomatch(struct device *, struct cfdata *, void *);
     62  1.1  scw 
     63  1.1  scw struct cfattach pcctwo_ca = {
     64  1.1  scw 	sizeof(struct pcctwo_softc), pcctwomatch, pcctwoattach
     65  1.1  scw };
     66  1.1  scw 
     67  1.1  scw extern struct cfdriver pcctwo_cd;
     68  1.1  scw 
     69  1.1  scw 
     70  1.1  scw #if defined(MVME167) || defined(MVME177)
     71  1.1  scw /*
     72  1.1  scw  * Devices that live on the PCCchip2, attached in this order.
     73  1.1  scw  */
     74  1.1  scw static struct pcctwo_device pcctwo_devices[] = {
     75  1.1  scw 	{"clock", 0},
     76  1.1  scw 	{"clmpcc", PCCTWO_SCC_OFF},
     77  1.1  scw 	{"ie", PCCTWO_IE_OFF},
     78  1.1  scw 	{"osiop", PCCTWO_NCRSC_OFF},
     79  1.1  scw 	{"lpt", PCCTWO_LPT_OFF},
     80  1.1  scw 	{NULL, 0}
     81  1.1  scw };
     82  1.1  scw 
     83  1.1  scw static int pcctwo_vec2icsr_1x7[] = {
     84  1.1  scw 	VEC2ICSR(PCC2REG_PRT_BUSY_ICSR,  PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     85  1.1  scw 	VEC2ICSR(PCC2REG_PRT_PE_ICSR,    PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     86  1.1  scw 	VEC2ICSR(PCC2REG_PRT_SEL_ICSR,   PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     87  1.1  scw 	VEC2ICSR(PCC2REG_PRT_FAULT_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     88  1.1  scw 	VEC2ICSR(PCC2REG_PRT_ACK_ICSR,   PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     89  1.1  scw 	VEC2ICSR(PCC2REG_SCSI_ICSR,      0),
     90  1.1  scw 	VEC2ICSR(PCC2REG_ETH_ICSR,       PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     91  1.1  scw 	VEC2ICSR(PCC2REG_ETH_ICSR,       PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     92  1.1  scw 	VEC2ICSR(PCC2REG_TIMER2_ICSR,    PCCTWO_ICR_ICLR),
     93  1.1  scw 	VEC2ICSR(PCC2REG_TIMER1_ICSR,    PCCTWO_ICR_ICLR),
     94  1.1  scw 	VEC2ICSR(PCC2REG_GPIO_ICSR,      PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     95  1.1  scw 	-1,
     96  1.1  scw 	VEC2ICSR(PCC2REG_SCC_RX_ICSR,    0),
     97  1.1  scw 	VEC2ICSR(PCC2REG_SCC_MODEM_ICSR, 0),
     98  1.1  scw 	VEC2ICSR(PCC2REG_SCC_TX_ICSR,    0),
     99  1.1  scw 	VEC2ICSR(PCC2REG_SCC_RX_ICSR,    0)
    100  1.1  scw };
    101  1.1  scw #endif
    102  1.1  scw 
    103  1.1  scw #if defined(MVME162) || defined(MVME172)
    104  1.1  scw /*
    105  1.1  scw  * Devices that live on the MCchip, attached in this order.
    106  1.1  scw  */
    107  1.1  scw static struct pcctwo_device mcchip_devices[] = {
    108  1.1  scw 	{"clock", 0},
    109  1.1  scw 	{"zsc", MCCHIP_ZS0_OFF},
    110  1.1  scw 	{"zsc", MCCHIP_ZS1_OFF},
    111  1.1  scw 	{"ie", PCCTWO_IE_OFF},
    112  1.1  scw 	{"osiop", PCCTWO_NCRSC_OFF},
    113  1.1  scw 	{NULL, 0}
    114  1.1  scw };
    115  1.1  scw 
    116  1.1  scw static int pcctwo_vec2icsr_1x2[] = {
    117  1.1  scw 	-1,
    118  1.1  scw 	-1,
    119  1.1  scw 	-1,
    120  1.1  scw 	VEC2ICSR(MCCHIPREG_TIMER4_ICSR, PCCTWO_ICR_ICLR),
    121  1.1  scw 	VEC2ICSR(MCCHIPREG_TIMER3_ICSR, PCCTWO_ICR_ICLR),
    122  1.1  scw 	VEC2ICSR(PCC2REG_SCSI_ICSR,     0),
    123  1.1  scw 	VEC2ICSR(PCC2REG_ETH_ICSR,      PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
    124  1.1  scw 	VEC2ICSR(PCC2REG_ETH_ICSR,      PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
    125  1.1  scw 	VEC2ICSR(PCC2REG_TIMER2_ICSR,   PCCTWO_ICR_ICLR),
    126  1.1  scw 	VEC2ICSR(PCC2REG_TIMER1_ICSR,   PCCTWO_ICR_ICLR),
    127  1.1  scw 	-1,
    128  1.1  scw 	VEC2ICSR(MCCHIPREG_PARERR_ICSR, PCCTWO_ICR_ICLR),
    129  1.1  scw 	VEC2ICSR(MCCHIPREG_SCC_ICSR,    0),
    130  1.1  scw 	VEC2ICSR(MCCHIPREG_SCC_ICSR,    0),
    131  1.1  scw 	VEC2ICSR(MCCHIPREG_ABORT_ICSR,  PCCTWO_ICR_ICLR),
    132  1.1  scw 	-1
    133  1.1  scw };
    134  1.1  scw 
    135  1.1  scw static	int pcctwoabortintr(void *);
    136  1.1  scw void	pcctwosoftintrinit(void);
    137  1.1  scw static	int pcctwosoftintr(void *);
    138  1.1  scw static	void pcctwosoftintrassert(void);
    139  1.1  scw #endif
    140  1.1  scw 
    141  1.1  scw static void pcctwoisrlink(void *, int (*)(void *), void *,
    142  1.1  scw 		int, int, struct evcnt *);
    143  1.1  scw static void pcctwoisrunlink(void *, int);
    144  1.1  scw static struct evcnt *pcctwoisrevcnt(void *, int);
    145  1.1  scw 
    146  1.1  scw 
    147  1.1  scw /* ARGSUSED */
    148  1.1  scw int
    149  1.1  scw pcctwomatch(parent, cf, args)
    150  1.1  scw 	struct device *parent;
    151  1.1  scw 	struct cfdata *cf;
    152  1.1  scw 	void *args;
    153  1.1  scw {
    154  1.1  scw 	struct mainbus_attach_args *ma;
    155  1.1  scw 	bus_space_handle_t bh;
    156  1.1  scw 	u_int8_t cid;
    157  1.1  scw 
    158  1.1  scw 	ma = args;
    159  1.1  scw 
    160  1.1  scw 	/* There can be only one. */
    161  1.1  scw 	if (sys_pcctwo || strcmp(ma->ma_name, pcctwo_cd.cd_name))
    162  1.1  scw 		return (0);
    163  1.1  scw 
    164  1.1  scw 	/*
    165  1.1  scw 	 * Grab the Chip's ID
    166  1.1  scw 	 */
    167  1.1  scw 	bus_space_map(ma->ma_bust, PCCTWO_REG_OFF + ma->ma_offset,
    168  1.1  scw 	    PCC2REG_SIZE, 0, &bh);
    169  1.1  scw 	cid = bus_space_read_1(ma->ma_bust, bh, PCC2REG_CHIP_ID);
    170  1.1  scw 	bus_space_unmap(ma->ma_bust, bh, PCC2REG_SIZE);
    171  1.1  scw 
    172  1.1  scw #if defined(MVME167) || defined(MVME177)
    173  1.1  scw 	if ((machineid == MVME_167 || machineid == MVME_177) &&
    174  1.1  scw 	    cid == PCCTWO_CHIP_ID_PCC2)
    175  1.1  scw 		return (1);
    176  1.1  scw #endif
    177  1.1  scw #if defined(MVME162) || defined(MVME172)
    178  1.1  scw 	if ((machineid == MVME_162 || machineid == MVME_172) &&
    179  1.1  scw 	    cid == PCCTWO_CHIP_ID_MCCHIP)
    180  1.1  scw 		return (1);
    181  1.1  scw #endif
    182  1.1  scw 
    183  1.1  scw 	return (0);
    184  1.1  scw }
    185  1.1  scw 
    186  1.1  scw /* ARGSUSED */
    187  1.1  scw void
    188  1.1  scw pcctwoattach(parent, self, args)
    189  1.1  scw 	struct device *parent;
    190  1.1  scw 	struct device *self;
    191  1.1  scw 	void *args;
    192  1.1  scw {
    193  1.1  scw 	struct mainbus_attach_args *ma;
    194  1.1  scw 	struct pcctwo_softc *sc;
    195  1.1  scw 	struct pcctwo_device *pd = NULL;
    196  1.1  scw 	u_int8_t cid;
    197  1.1  scw 
    198  1.1  scw 	ma = args;
    199  1.1  scw 	sc = sys_pcctwo = (struct pcctwo_softc *) self;
    200  1.1  scw 
    201  1.1  scw 	/* Get a handle to the PCCChip2's registers */
    202  1.1  scw 	sc->sc_bust = ma->ma_bust;
    203  1.1  scw 	sc->sc_dmat = ma->ma_dmat;
    204  1.1  scw 	bus_space_map(sc->sc_bust, PCCTWO_REG_OFF + ma->ma_offset,
    205  1.1  scw 	    PCC2REG_SIZE, 0, &sc->sc_bush);
    206  1.1  scw 
    207  1.1  scw 	sc->sc_vecbase = PCCTWO_VECBASE;
    208  1.1  scw 	sc->sc_isrlink = pcctwoisrlink;
    209  1.1  scw 	sc->sc_isrevcnt = pcctwoisrevcnt;
    210  1.1  scw 	sc->sc_isrunlink = pcctwoisrunlink;
    211  1.1  scw 
    212  1.1  scw 	cid = pcc2_reg_read(sc, PCC2REG_CHIP_ID);
    213  1.1  scw 
    214  1.1  scw #if defined(MVME167) || defined(MVME177)
    215  1.1  scw 	if (cid == PCCTWO_CHIP_ID_PCC2) {
    216  1.1  scw 		pd = pcctwo_devices;
    217  1.1  scw 		sc->sc_vec2icsr = pcctwo_vec2icsr_1x7;
    218  1.1  scw 	}
    219  1.1  scw #endif
    220  1.1  scw #if defined(MVME162) || defined(MVME172)
    221  1.1  scw 	if (cid == PCCTWO_CHIP_ID_MCCHIP) {
    222  1.1  scw 		pd = mcchip_devices;
    223  1.1  scw 		sc->sc_vec2icsr = pcctwo_vec2icsr_1x2;
    224  1.1  scw 	}
    225  1.1  scw #endif
    226  1.1  scw 
    227  1.1  scw 	/* Finish initialisation in common code */
    228  1.1  scw 	pcctwo_init(sc, pd, ma->ma_offset);
    229  1.1  scw 
    230  1.1  scw #if defined(MVME162) || defined(MVME172)
    231  1.1  scw 	if (cid == PCCTWO_CHIP_ID_MCCHIP) {
    232  1.1  scw 		evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR,
    233  1.1  scw 		    isrlink_evcnt(7), "nmi", "abort sw");
    234  1.1  scw 		pcctwointr_establish(MCCHIPV_ABORT, pcctwoabortintr, 7, NULL,
    235  1.1  scw 		    &sc->sc_evcnt);
    236  1.1  scw 	}
    237  1.1  scw #endif
    238  1.1  scw }
    239  1.1  scw 
    240  1.1  scw /* ARGSUSED */
    241  1.1  scw static void
    242  1.1  scw pcctwoisrlink(cookie, fn, arg, ipl, vec, evcnt)
    243  1.1  scw 	void *cookie;
    244  1.1  scw 	int (*fn)(void *);
    245  1.1  scw 	void *arg;
    246  1.1  scw 	int ipl, vec;
    247  1.1  scw 	struct evcnt *evcnt;
    248  1.1  scw {
    249  1.1  scw 
    250  1.1  scw 	isrlink_vectored(fn, arg, ipl, vec, evcnt);
    251  1.1  scw }
    252  1.1  scw 
    253  1.1  scw /* ARGSUSED */
    254  1.1  scw static void
    255  1.1  scw pcctwoisrunlink(cookie, vec)
    256  1.1  scw 	void *cookie;
    257  1.1  scw 	int vec;
    258  1.1  scw {
    259  1.1  scw 
    260  1.1  scw 	isrunlink_vectored(vec);
    261  1.1  scw }
    262  1.1  scw 
    263  1.1  scw /* ARGSUSED */
    264  1.1  scw static struct evcnt *
    265  1.1  scw pcctwoisrevcnt(cookie, ipl)
    266  1.1  scw 	void *cookie;
    267  1.1  scw 	int ipl;
    268  1.1  scw {
    269  1.1  scw 
    270  1.1  scw 	return (isrlink_evcnt(ipl));
    271  1.1  scw }
    272  1.1  scw 
    273  1.1  scw #if defined(MVME162) || defined(MVME172)
    274  1.1  scw static int
    275  1.1  scw pcctwoabortintr(void *frame)
    276  1.1  scw {
    277  1.1  scw 
    278  1.1  scw 	pcc2_reg_write(sys_pcctwo, MCCHIPREG_ABORT_ICSR, PCCTWO_ICR_ICLR |
    279  1.1  scw 	    pcc2_reg_read(sys_pcctwo, MCCHIPREG_ABORT_ICSR));
    280  1.1  scw 
    281  1.1  scw 	return (nmihand(frame));
    282  1.1  scw }
    283  1.1  scw 
    284  1.1  scw void
    285  1.1  scw pcctwosoftintrinit(void)
    286  1.1  scw {
    287  1.1  scw 
    288  1.1  scw 	/*
    289  1.1  scw 	 * Since the VMEChip2 is normally used to generate
    290  1.1  scw 	 * software interrupts to the CPU, we have to deal
    291  1.1  scw 	 * with 162/172 boards which have the "No VMEChip2"
    292  1.1  scw 	 * build option.
    293  1.1  scw 	 *
    294  1.1  scw 	 * When such a board is found, the VMEChip2 probe code
    295  1.1  scw 	 * calls this function to implement software interrupts
    296  1.1  scw 	 * the hard way; using tick timer 4 ...
    297  1.1  scw 	 */
    298  1.1  scw 	pcctwointr_establish(MCCHIPV_TIMER4, pcctwosoftintr,
    299  1.1  scw 	    1, sys_pcctwo, &sys_pcctwo->sc_evcnt);
    300  1.1  scw 	pcc2_reg_write(sys_pcctwo, MCCHIPREG_TIMER4_CTRL, 0);
    301  1.1  scw 	pcc2_reg_write32(sys_pcctwo, MCCHIPREG_TIMER4_COMP, 1);
    302  1.1  scw 	pcc2_reg_write32(sys_pcctwo, MCCHIPREG_TIMER4_CNTR, 0);
    303  1.1  scw 	_softintr_chipset_assert = pcctwosoftintrassert;
    304  1.1  scw }
    305  1.1  scw 
    306  1.1  scw static int
    307  1.1  scw pcctwosoftintr(void *arg)
    308  1.1  scw {
    309  1.1  scw 	struct pcctwo_softc *sc = arg;
    310  1.1  scw 
    311  1.1  scw 	pcc2_reg_write32(sc, MCCHIPREG_TIMER4_CNTR, 0);
    312  1.1  scw 	pcc2_reg_write(sc, MCCHIPREG_TIMER4_CTRL, 0);
    313  1.1  scw 	pcc2_reg_write(sc, MCCHIPREG_TIMER4_ICSR,
    314  1.1  scw 	    PCCTWO_ICR_ICLR | PCCTWO_ICR_IEN | 1);
    315  1.1  scw 
    316  1.1  scw 	softintr_dispatch();
    317  1.1  scw 
    318  1.1  scw 	return (1);
    319  1.1  scw }
    320  1.1  scw 
    321  1.1  scw static void
    322  1.1  scw pcctwosoftintrassert(void)
    323  1.1  scw {
    324  1.1  scw 
    325  1.1  scw 	/*
    326  1.1  scw 	 * Schedule a timer interrupt to happen in ~1uS.
    327  1.1  scw 	 * This is more than adequate on any available m68k platform
    328  1.1  scw 	 * for simulating software interrupts.
    329  1.1  scw 	 */
    330  1.1  scw 	pcc2_reg_write(sys_pcctwo, MCCHIPREG_TIMER4_CTRL, PCCTWO_TT_CTRL_CEN);
    331  1.1  scw }
    332  1.1  scw #endif
    333