Home | History | Annotate | Line # | Download | only in dev
com_supio.c revision 1.3.2.4
      1 /*	$NetBSD: com_supio.c,v 1.3.2.4 1997/10/16 01:07:48 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1993, 1994, 1995, 1996
      5  *	Charles M. Hannum.  All rights reserved.
      6  * Copyright (c) 1991 The Regents of the University of California.
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by the University of
     20  *	California, Berkeley and its contributors.
     21  * 4. Neither the name of the University nor the names of its contributors
     22  *    may be used to endorse or promote products derived from this software
     23  *    without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     38  */
     39 
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/ioctl.h>
     43 #include <sys/select.h>
     44 #include <sys/tty.h>
     45 #include <sys/proc.h>
     46 #include <sys/user.h>
     47 #include <sys/conf.h>
     48 #include <sys/file.h>
     49 #include <sys/uio.h>
     50 #include <sys/kernel.h>
     51 #include <sys/syslog.h>
     52 #include <sys/types.h>
     53 #include <sys/device.h>
     54 
     55 #include <machine/intr.h>
     56 #include <machine/bus.h>
     57 
     58 /*#include <dev/isa/isavar.h>*/
     59 #include <dev/ic/comreg.h>
     60 #include <dev/ic/comvar.h>
     61 
     62 #include <amiga/dev/supio.h>
     63 
     64 struct comsupio_softc {
     65 	struct com_softc sc_com;
     66 	struct isr sc_isr;
     67 };
     68 
     69 int com_supio_match __P((struct device *, struct cfdata *, void *));
     70 void com_supio_attach __P((struct device *, struct device *, void *));
     71 void com_supio_cleanup __P((void *));
     72 
     73 static int      comconsaddr;
     74 static bus_space_handle_t comconsioh;
     75 #if 0
     76 static int      comconsattached;
     77 static bus_space_tag_t comconstag;
     78 static int comconsrate;
     79 static tcflag_t comconscflag;
     80 #endif
     81 
     82 struct cfattach com_supio_ca = {
     83 	sizeof(struct comsupio_softc), com_supio_match, com_supio_attach
     84 };
     85 
     86 int
     87 com_supio_match(parent, match, aux)
     88 	struct device *parent;
     89 	struct cfdata *match;
     90 	void *aux;
     91 {
     92 	bus_space_tag_t iot;
     93 	int iobase;
     94 	int rv = 1;
     95 	struct supio_attach_args *supa = aux;
     96 
     97 	iot = supa->supio_iot;
     98 	iobase = supa->supio_iobase;
     99 
    100 	if (strcmp(supa->supio_name,"com"))
    101 		return 0;
    102 #if 0
    103 	/* if it's in use as console, it's there. */
    104 	if (iobase != comconsaddr || comconsattached) {
    105 		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    106 			return 0;
    107 		}
    108 		rv = comprobe1(iot, ioh, iobase);
    109 		bus_space_unmap(iot, ioh, COM_NPORTS);
    110 	}
    111 #endif
    112 	return (rv);
    113 }
    114 
    115 void
    116 com_supio_attach(parent, self, aux)
    117 	struct device *parent, *self;
    118 	void *aux;
    119 {
    120 	struct comsupio_softc *sc = (void *)self;
    121 	struct com_softc *csc = &sc->sc_com;
    122 	int iobase;
    123 	bus_space_tag_t iot;
    124 	struct supio_attach_args *supa = aux;
    125 	u_int16_t needpsl;
    126 
    127 	/*
    128 	 * We're living on a superio chip.
    129 	 */
    130 	iobase = csc->sc_iobase = supa->supio_iobase;
    131 	iot = csc->sc_iot = supa->supio_iot;
    132         if (iobase != comconsaddr) {
    133                 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &csc->sc_ioh))
    134 			panic("comattach: io mapping failed");
    135 	} else
    136                 csc->sc_ioh = comconsioh;
    137 
    138 	csc->sc_frequency = supa->supio_arg;
    139 
    140 	printf(" port 0x%x", iobase);
    141 	com_attach_subr(csc);
    142 
    143 	/* XXX this should be really in the interupt stuff */
    144 	needpsl = PSL_S | (supa->supio_ipl << 8);
    145 
    146 	if (amiga_ttyspl < needpsl) {
    147 		printf("%s: raising amiga_ttyspl from 0x%x to 0x%x\n",
    148 		    csc->sc_dev.dv_xname, amiga_ttyspl, needpsl);
    149 		amiga_ttyspl = needpsl;
    150 	}
    151 	sc->sc_isr.isr_intr = comintr;
    152 	sc->sc_isr.isr_arg = csc;
    153 	sc->sc_isr.isr_ipl = supa->supio_ipl;
    154 	add_isr(&sc->sc_isr);
    155 
    156 	/*
    157 	 * Shutdown hook for buggy BIOSs that don't recognize the UART
    158 	 * without a disabled FIFO.
    159 	 */
    160 	if (shutdownhook_establish(com_supio_cleanup, csc) == NULL)
    161 		panic("comsupio: could not establish shutdown hook");
    162 }
    163 
    164 void
    165 com_supio_cleanup(arg)
    166 	void *arg;
    167 {
    168 	struct com_softc *sc = arg;
    169 
    170 	if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
    171 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_fifo, 0);
    172 }
    173