Home | History | Annotate | Line # | Download | only in mvme
clmpcc_pcctwo.c revision 1.2
      1 /*	$NetBSD: clmpcc_pcctwo.c,v 1.2 2002/09/06 13:18:43 gehenna 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  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Cirrus Logic CD2401 4-channel serial chip. PCCchip2 Front-end.
     41  */
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/proc.h>
     46 #include <sys/device.h>
     47 #include <sys/conf.h>
     48 #include <sys/file.h>
     49 #include <sys/ioctl.h>
     50 #include <sys/tty.h>
     51 #include <sys/time.h>
     52 #include <sys/kernel.h>
     53 #include <sys/syslog.h>
     54 
     55 #include <dev/cons.h>
     56 
     57 #include <machine/cpu.h>
     58 #include <machine/bus.h>
     59 #include <machine/intr.h>
     60 
     61 #include <dev/ic/clmpccvar.h>
     62 
     63 #include <dev/mvme/pcctwovar.h>
     64 #include <dev/mvme/pcctworeg.h>
     65 
     66 /* XXXXSCW: Fixme */
     67 #ifdef MVME68K
     68 #include <mvme68k/dev/mainbus.h>
     69 #else
     70 #error Need consiack hook
     71 #endif
     72 
     73 
     74 /* Definition of the driver for autoconfig. */
     75 int clmpcc_pcctwo_match __P((struct device *, struct cfdata *, void *));
     76 void clmpcc_pcctwo_attach __P((struct device *, struct device *, void *));
     77 void clmpcc_pcctwo_iackhook __P((struct clmpcc_softc *, int));
     78 void clmpcc_pcctwo_consiackhook __P((struct clmpcc_softc *, int));
     79 
     80 struct cfattach clmpcc_pcctwo_ca = {
     81 	sizeof(struct clmpcc_softc), clmpcc_pcctwo_match, clmpcc_pcctwo_attach
     82 };
     83 
     84 extern struct cfdriver clmpcc_cd;
     85 
     86 extern const struct cdevsw clmpcc_cdevsw;
     87 
     88 /*
     89  * For clmpcccn*()
     90  */
     91 cons_decl(clmpcc);
     92 
     93 
     94 /*
     95  * Is the CD2401 chip present?
     96  */
     97 int
     98 clmpcc_pcctwo_match(parent, cf, aux)
     99 	struct device *parent;
    100 	struct cfdata *cf;
    101 	void *aux;
    102 {
    103 	struct pcctwo_attach_args *pa;
    104 
    105 	pa = aux;
    106 
    107 	if (strcmp(pa->pa_name, clmpcc_cd.cd_name))
    108 		return (0);
    109 
    110 	pa->pa_ipl = cf->pcctwocf_ipl;
    111 
    112 	return (1);
    113 }
    114 
    115 /*
    116  * Attach a found CD2401.
    117  */
    118 void
    119 clmpcc_pcctwo_attach(parent, self, aux)
    120 	struct device *parent;
    121 	struct device *self;
    122 	void *aux;
    123 {
    124 	struct clmpcc_softc *sc;
    125 	struct pcctwo_attach_args *pa;
    126 	int level = pa->pa_ipl;
    127 
    128 	sc = (struct clmpcc_softc *)self;
    129 	pa = aux;
    130 	level = pa->pa_ipl;
    131 	sc->sc_iot = pa->pa_bust;
    132 	bus_space_map(pa->pa_bust, pa->pa_offset, 0x100, 0, &sc->sc_ioh);
    133 
    134 	sc->sc_clk = 20000000;
    135 	sc->sc_byteswap = CLMPCC_BYTESWAP_LOW;
    136 	sc->sc_swaprtsdtr = 1;
    137 	sc->sc_iackhook = clmpcc_pcctwo_iackhook;
    138 	sc->sc_vector_base = PCCTWO_SCC_VECBASE;
    139 	sc->sc_rpilr = 0x03;
    140 	sc->sc_tpilr = 0x02;
    141 	sc->sc_mpilr = 0x01;
    142 	sc->sc_evcnt = pcctwointr_evcnt(level);
    143 
    144 	/* Do common parts of CD2401 configuration. */
    145 	clmpcc_attach(sc);
    146 
    147 	/* Hook the interrupts */
    148 	pcctwointr_establish(PCCTWOV_SCC_RX, clmpcc_rxintr, level, sc, NULL);
    149 	pcctwointr_establish(PCCTWOV_SCC_RX_EXCEP, clmpcc_rxintr, level, sc,
    150 	    NULL);
    151 	pcctwointr_establish(PCCTWOV_SCC_TX, clmpcc_txintr, level, sc, NULL);
    152 	pcctwointr_establish(PCCTWOV_SCC_MODEM, clmpcc_mdintr, level, sc, NULL);
    153 }
    154 
    155 void
    156 clmpcc_pcctwo_iackhook(sc, which)
    157 	struct clmpcc_softc *sc;
    158 	int which;
    159 {
    160 	bus_size_t offset;
    161 	volatile u_char foo;
    162 
    163 	switch (which) {
    164 	case CLMPCC_IACK_MODEM:
    165 		offset = PCC2REG_SCC_MODEM_PIACK;
    166 		break;
    167 
    168 	case CLMPCC_IACK_RX:
    169 		offset = PCC2REG_SCC_RX_PIACK;
    170 		break;
    171 
    172 	case CLMPCC_IACK_TX:
    173 		offset = PCC2REG_SCC_TX_PIACK;
    174 		break;
    175 #ifdef DEBUG
    176 	default:
    177 		printf("%s: Invalid IACK number '%d'\n",
    178 		    sc->sc_dev.dv_xname, which);
    179 		panic("clmpcc_pcctwo_iackhook");
    180 #endif
    181 	}
    182 
    183 	foo = pcc2_reg_read(sys_pcctwo, offset);
    184 }
    185 
    186 /*
    187  * This routine is only used prior to clmpcc_attach() being called
    188  */
    189 void
    190 clmpcc_pcctwo_consiackhook(sc, which)
    191 	struct clmpcc_softc *sc;
    192 	int which;
    193 {
    194 	bus_space_handle_t bush;
    195 	bus_size_t offset;
    196 	volatile u_char foo;
    197 
    198 	switch (which) {
    199 	case CLMPCC_IACK_MODEM:
    200 		offset = PCC2REG_SCC_MODEM_PIACK;
    201 		break;
    202 
    203 	case CLMPCC_IACK_RX:
    204 		offset = PCC2REG_SCC_RX_PIACK;
    205 		break;
    206 
    207 	case CLMPCC_IACK_TX:
    208 		offset = PCC2REG_SCC_TX_PIACK;
    209 		break;
    210 #ifdef DEBUG
    211 	default:
    212 		printf("%s: Invalid IACK number '%d'\n",
    213 		    sc->sc_dev.dv_xname, which);
    214 		panic("clmpcc_pcctwo_consiackhook");
    215 #endif
    216 	}
    217 
    218 #ifdef MVME68K
    219 	/*
    220 	 * We need to fake the tag and handle since 'sys_pcctwo' will
    221 	 * be NULL during early system startup...
    222 	 */
    223 	bush = (bus_space_handle_t) & (intiobase[MAINBUS_PCCTWO_OFFSET +
    224 		PCCTWO_REG_OFF]);
    225 
    226 	foo = bus_space_read_1(&_mainbus_space_tag, bush, offset);
    227 #else
    228 #error Need consiack hook
    229 #endif
    230 }
    231 
    232 
    233 /****************************************************************
    234  * Console support functions (MVME PCCchip2 specific!)
    235  ****************************************************************/
    236 
    237 /*
    238  * Check for CD2401 console.
    239  */
    240 void
    241 clmpcccnprobe(cp)
    242 	struct consdev *cp;
    243 {
    244 	int maj;
    245 
    246 #if defined(MVME68K)
    247 	if (machineid != MVME_167 && machineid != MVME_177)
    248 #elif defined(MVME88K)
    249 	if (machineid != MVME_187)
    250 #endif
    251 	{
    252 		cp->cn_pri = CN_DEAD;
    253 		return;
    254 	}
    255 
    256 	/*
    257 	 * Locate the major number
    258 	 */
    259 	maj = cdevsw_lookup_major(&clmpcc_cdevsw);
    260 
    261 	/* Initialize required fields. */
    262 	cp->cn_dev = makedev(maj, 0);
    263 	cp->cn_pri = CN_NORMAL;
    264 }
    265 
    266 void
    267 clmpcccninit(cp)
    268 	struct consdev *cp;
    269 {
    270 	static struct clmpcc_softc cons_sc;
    271 
    272 	cons_sc.sc_iot = &_mainbus_space_tag;
    273 	bus_space_map(&_mainbus_space_tag,
    274 	    intiobase_phys + MAINBUS_PCCTWO_OFFSET + PCCTWO_SCC_OFF,
    275 	    PCC2REG_SIZE, 0, &cons_sc.sc_ioh);
    276 	cons_sc.sc_clk = 20000000;
    277 	cons_sc.sc_byteswap = CLMPCC_BYTESWAP_LOW;
    278 	cons_sc.sc_swaprtsdtr = 1;
    279 	cons_sc.sc_iackhook = clmpcc_pcctwo_consiackhook;
    280 	cons_sc.sc_vector_base = PCCTWO_SCC_VECBASE;
    281 	cons_sc.sc_rpilr = 0x03;
    282 	cons_sc.sc_tpilr = 0x02;
    283 	cons_sc.sc_mpilr = 0x01;
    284 
    285 	clmpcc_cnattach(&cons_sc, 0, 9600);
    286 }
    287