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