Home | History | Annotate | Line # | Download | only in mvme
clmpcc_pcctwo.c revision 1.11
      1 /*	$NetBSD: clmpcc_pcctwo.c,v 1.11 2006/03/29 07:07:41 thorpej 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/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: clmpcc_pcctwo.c,v 1.11 2006/03/29 07:07:41 thorpej Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/proc.h>
     49 #include <sys/device.h>
     50 #include <sys/conf.h>
     51 #include <sys/file.h>
     52 #include <sys/ioctl.h>
     53 #include <sys/tty.h>
     54 #include <sys/time.h>
     55 #include <sys/kernel.h>
     56 #include <sys/syslog.h>
     57 
     58 #include <dev/cons.h>
     59 
     60 #include <machine/cpu.h>
     61 #include <machine/bus.h>
     62 #include <machine/intr.h>
     63 
     64 #include <dev/ic/clmpccvar.h>
     65 
     66 #include <dev/mvme/pcctwovar.h>
     67 #include <dev/mvme/pcctworeg.h>
     68 
     69 /* XXXXSCW: Fixme */
     70 #ifdef MVME68K
     71 #include <mvme68k/dev/mainbus.h>
     72 #else
     73 #error Need consiack hook
     74 #endif
     75 
     76 
     77 /* Definition of the driver for autoconfig. */
     78 int clmpcc_pcctwo_match(struct device *, struct cfdata *, void *);
     79 void clmpcc_pcctwo_attach(struct device *, struct device *, void *);
     80 void clmpcc_pcctwo_iackhook(struct clmpcc_softc *, int);
     81 void clmpcc_pcctwo_consiackhook(struct clmpcc_softc *, int);
     82 
     83 CFATTACH_DECL(clmpcc_pcctwo, sizeof(struct clmpcc_softc),
     84     clmpcc_pcctwo_match, clmpcc_pcctwo_attach, NULL, NULL);
     85 
     86 extern struct cfdriver clmpcc_cd;
     87 
     88 extern const struct cdevsw clmpcc_cdevsw;
     89 
     90 /*
     91  * For clmpcccn*()
     92  */
     93 cons_decl(clmpcc);
     94 
     95 
     96 /*
     97  * Is the CD2401 chip present?
     98  */
     99 int
    100 clmpcc_pcctwo_match(parent, cf, aux)
    101 	struct device *parent;
    102 	struct cfdata *cf;
    103 	void *aux;
    104 {
    105 	struct pcctwo_attach_args *pa;
    106 
    107 	pa = aux;
    108 
    109 	if (strcmp(pa->pa_name, clmpcc_cd.cd_name))
    110 		return (0);
    111 
    112 	pa->pa_ipl = cf->pcctwocf_ipl;
    113 
    114 	return (1);
    115 }
    116 
    117 /*
    118  * Attach a found CD2401.
    119  */
    120 void
    121 clmpcc_pcctwo_attach(parent, self, aux)
    122 	struct device *parent;
    123 	struct device *self;
    124 	void *aux;
    125 {
    126 	struct clmpcc_softc *sc;
    127 	struct pcctwo_attach_args *pa;
    128 	int level = pa->pa_ipl;
    129 
    130 	sc = device_private(self);
    131 	pa = aux;
    132 	level = pa->pa_ipl;
    133 	sc->sc_iot = pa->pa_bust;
    134 	bus_space_map(pa->pa_bust, pa->pa_offset, 0x100, 0, &sc->sc_ioh);
    135 
    136 	sc->sc_clk = 20000000;
    137 	sc->sc_byteswap = CLMPCC_BYTESWAP_LOW;
    138 	sc->sc_swaprtsdtr = 1;
    139 	sc->sc_iackhook = clmpcc_pcctwo_iackhook;
    140 	sc->sc_vector_base = PCCTWO_SCC_VECBASE;
    141 	sc->sc_rpilr = 0x03;
    142 	sc->sc_tpilr = 0x02;
    143 	sc->sc_mpilr = 0x01;
    144 	sc->sc_evcnt = pcctwointr_evcnt(level);
    145 
    146 	/* Do common parts of CD2401 configuration. */
    147 	clmpcc_attach(sc);
    148 
    149 	/* Hook the interrupts */
    150 	pcctwointr_establish(PCCTWOV_SCC_RX, clmpcc_rxintr, level, sc, NULL);
    151 	pcctwointr_establish(PCCTWOV_SCC_RX_EXCEP, clmpcc_rxintr, level, sc,
    152 	    NULL);
    153 	pcctwointr_establish(PCCTWOV_SCC_TX, clmpcc_txintr, level, sc, NULL);
    154 	pcctwointr_establish(PCCTWOV_SCC_MODEM, clmpcc_mdintr, level, sc, NULL);
    155 }
    156 
    157 void
    158 clmpcc_pcctwo_iackhook(sc, which)
    159 	struct clmpcc_softc *sc;
    160 	int which;
    161 {
    162 	bus_size_t offset;
    163 	volatile u_char foo;
    164 
    165 	switch (which) {
    166 	case CLMPCC_IACK_MODEM:
    167 		offset = PCC2REG_SCC_MODEM_PIACK;
    168 		break;
    169 
    170 	case CLMPCC_IACK_RX:
    171 		offset = PCC2REG_SCC_RX_PIACK;
    172 		break;
    173 
    174 	case CLMPCC_IACK_TX:
    175 		offset = PCC2REG_SCC_TX_PIACK;
    176 		break;
    177 	default:
    178 #ifdef DEBUG
    179 		printf("%s: Invalid IACK number '%d'\n",
    180 		    sc->sc_dev.dv_xname, which);
    181 #endif
    182 		panic("clmpcc_pcctwo_iackhook %d", which);
    183 	}
    184 
    185 	foo = pcc2_reg_read(sys_pcctwo, offset);
    186 }
    187 
    188 /*
    189  * This routine is only used prior to clmpcc_attach() being called
    190  */
    191 void
    192 clmpcc_pcctwo_consiackhook(sc, which)
    193 	struct clmpcc_softc *sc;
    194 	int which;
    195 {
    196 	bus_space_handle_t bush;
    197 	bus_size_t offset;
    198 	volatile u_char foo;
    199 
    200 	switch (which) {
    201 	case CLMPCC_IACK_MODEM:
    202 		offset = PCC2REG_SCC_MODEM_PIACK;
    203 		break;
    204 
    205 	case CLMPCC_IACK_RX:
    206 		offset = PCC2REG_SCC_RX_PIACK;
    207 		break;
    208 
    209 	case CLMPCC_IACK_TX:
    210 		offset = PCC2REG_SCC_TX_PIACK;
    211 		break;
    212 	default:
    213 #ifdef DEBUG
    214 		printf("%s: Invalid IACK number '%d'\n",
    215 		    sc->sc_dev.dv_xname, which);
    216 		panic("clmpcc_pcctwo_consiackhook");
    217 #endif
    218 		panic("clmpcc_pcctwo_iackhook %d", which);
    219 	}
    220 
    221 #ifdef MVME68K
    222 	/*
    223 	 * We need to fake the tag and handle since 'sys_pcctwo' will
    224 	 * be NULL during early system startup...
    225 	 */
    226 	bush = (bus_space_handle_t) & (intiobase[MAINBUS_PCCTWO_OFFSET +
    227 		PCCTWO_REG_OFF]);
    228 
    229 	foo = bus_space_read_1(&_mainbus_space_tag, bush, offset);
    230 #else
    231 #error Need consiack hook
    232 #endif
    233 }
    234 
    235 
    236 /****************************************************************
    237  * Console support functions (MVME PCCchip2 specific!)
    238  ****************************************************************/
    239 
    240 /*
    241  * Check for CD2401 console.
    242  */
    243 void
    244 clmpcccnprobe(cp)
    245 	struct consdev *cp;
    246 {
    247 	int maj;
    248 
    249 #if defined(MVME68K)
    250 	if (machineid != MVME_167 && machineid != MVME_177)
    251 #elif defined(MVME88K)
    252 	if (machineid != MVME_187)
    253 #endif
    254 	{
    255 		cp->cn_pri = CN_DEAD;
    256 		return;
    257 	}
    258 
    259 	/*
    260 	 * Locate the major number
    261 	 */
    262 	maj = cdevsw_lookup_major(&clmpcc_cdevsw);
    263 
    264 	/* Initialize required fields. */
    265 	cp->cn_dev = makedev(maj, 0);
    266 	cp->cn_pri = CN_NORMAL;
    267 }
    268 
    269 void
    270 clmpcccninit(cp)
    271 	struct consdev *cp;
    272 {
    273 	static struct clmpcc_softc cons_sc;
    274 
    275 	cons_sc.sc_iot = &_mainbus_space_tag;
    276 	bus_space_map(&_mainbus_space_tag,
    277 	    intiobase_phys + MAINBUS_PCCTWO_OFFSET + PCCTWO_SCC_OFF,
    278 	    PCC2REG_SIZE, 0, &cons_sc.sc_ioh);
    279 	cons_sc.sc_clk = 20000000;
    280 	cons_sc.sc_byteswap = CLMPCC_BYTESWAP_LOW;
    281 	cons_sc.sc_swaprtsdtr = 1;
    282 	cons_sc.sc_iackhook = clmpcc_pcctwo_consiackhook;
    283 	cons_sc.sc_vector_base = PCCTWO_SCC_VECBASE;
    284 	cons_sc.sc_rpilr = 0x03;
    285 	cons_sc.sc_tpilr = 0x02;
    286 	cons_sc.sc_mpilr = 0x01;
    287 
    288 	clmpcc_cnattach(&cons_sc, 0, 9600);
    289 }
    290