Home | History | Annotate | Line # | Download | only in jazz
com_jazzio.c revision 1.5
      1 /*	$NetBSD: com_jazzio.c,v 1.5 2003/07/15 00:04:49 lukem Exp $	*/
      2 /*	$OpenBSD: com_lbus.c,v 1.7 1998/03/16 09:38:41 pefo Exp $	*/
      3 /*	NetBSD: com_isa.c,v 1.12 1998/08/15 17:47:17 mycroft Exp 	*/
      4 
      5 /*-
      6  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      7  * All rights reserved.
      8  *
      9  * This code is derived from software contributed to The NetBSD Foundation
     10  * by Charles M. Hannum.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *        This product includes software developed by the NetBSD
     23  *        Foundation, Inc. and its contributors.
     24  * 4. Neither the name of The NetBSD Foundation nor the names of its
     25  *    contributors may be used to endorse or promote products derived
     26  *    from this software without specific prior written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     29  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     38  * POSSIBILITY OF SUCH DAMAGE.
     39  */
     40 
     41 /*-
     42  * Copyright (c) 1991 The Regents of the University of California.
     43  * All rights reserved.
     44  *
     45  * Redistribution and use in source and binary forms, with or without
     46  * modification, are permitted provided that the following conditions
     47  * are met:
     48  * 1. Redistributions of source code must retain the above copyright
     49  *    notice, this list of conditions and the following disclaimer.
     50  * 2. Redistributions in binary form must reproduce the above copyright
     51  *    notice, this list of conditions and the following disclaimer in the
     52  *    documentation and/or other materials provided with the distribution.
     53  * 3. All advertising materials mentioning features or use of this software
     54  *    must display the following acknowledgement:
     55  *	This product includes software developed by the University of
     56  *	California, Berkeley and its contributors.
     57  * 4. Neither the name of the University nor the names of its contributors
     58  *    may be used to endorse or promote products derived from this software
     59  *    without specific prior written permission.
     60  *
     61  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     62  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     63  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     64  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     65  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     66  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     67  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     68  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     69  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     70  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     71  * SUCH DAMAGE.
     72  *
     73  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     74  */
     75 
     76 #include <sys/cdefs.h>
     77 __KERNEL_RCSID(0, "$NetBSD: com_jazzio.c,v 1.5 2003/07/15 00:04:49 lukem Exp $");
     78 
     79 #include <sys/param.h>
     80 #include <sys/systm.h>
     81 #include <sys/device.h>
     82 #include <sys/tty.h>
     83 
     84 #include <machine/autoconf.h>
     85 #include <machine/bus.h>
     86 #include <machine/intr.h>
     87 
     88 #include <arc/jazz/jazziovar.h>
     89 
     90 #include <dev/isa/isavar.h>	/* XXX for isa_chipset_tag_t in com_softc */
     91 
     92 #include <dev/ic/comreg.h>
     93 #include <dev/ic/comvar.h>
     94 #include <dev/ic/ns16550reg.h>
     95 
     96 extern int com_freq;
     97 
     98 int	com_jazzio_probe __P((struct device *, struct cfdata *, void *));
     99 void	com_jazzio_attach __P((struct device *, struct device *, void *));
    100 
    101 CFATTACH_DECL(com_jazzio, sizeof(struct com_softc),
    102     com_jazzio_probe, com_jazzio_attach, NULL, NULL);
    103 
    104 int
    105 com_jazzio_probe(parent, match, aux)
    106 	struct device *parent;
    107 	struct cfdata *match;
    108 	void *aux;
    109 {
    110 	struct jazzio_attach_args *ja = aux;
    111 	bus_space_tag_t iot;
    112 	bus_space_handle_t ioh;
    113 	int iobase;
    114 	int rv = 1;
    115 
    116 	if (strcmp(ja->ja_name, "COM1") != 0 &&
    117 	    strcmp(ja->ja_name, "COM2") != 0)
    118 		return (0);
    119 
    120 	iot = ja->ja_bust;
    121 	iobase = ja->ja_addr;
    122 
    123 	/* if it's in use as console, it's there. */
    124 	if (!com_is_console(iot, iobase, 0)) {
    125 		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    126 			return 0;
    127 		}
    128 		rv = comprobe1(iot, ioh);
    129 		bus_space_unmap(iot, ioh, COM_NPORTS);
    130 	}
    131 	return (rv);
    132 }
    133 
    134 void
    135 com_jazzio_attach(parent, self, aux)
    136 	struct device *parent, *self;
    137 	void *aux;
    138 {
    139 	struct jazzio_attach_args *ja = aux;
    140 	struct com_softc *sc = (void *)self;
    141 	int iobase;
    142 	bus_space_tag_t iot;
    143 
    144 	sc->sc_iobase = iobase = ja->ja_addr;
    145 	sc->sc_iot = iot = ja->ja_bust;
    146 
    147 	if (!com_is_console(iot, iobase, &sc->sc_ioh) &&
    148 	    bus_space_map(iot, iobase, COM_NPORTS, 0, &sc->sc_ioh)) {
    149 		printf(": can't map i/o space\n");
    150 		return;
    151 	}
    152 
    153 	sc->sc_frequency = com_freq;
    154 	SET(sc->sc_hwflags, COM_HW_TXFIFO_DISABLE); /* XXX - NEC M403 */
    155 	jazzio_intr_establish(ja->ja_intr, comintr, sc);
    156 
    157 	com_attach_subr(sc);
    158 }
    159