Home | History | Annotate | Line # | Download | only in jazz
com_jazzio.c revision 1.7
      1 /*	$NetBSD: com_jazzio.c,v 1.7 2005/01/22 07:35:34 tsutsui 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. Neither the name of the University nor the names of its contributors
     54  *    may be used to endorse or promote products derived from this software
     55  *    without specific prior written permission.
     56  *
     57  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     58  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     59  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     60  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     61  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     62  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     63  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     64  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     65  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     66  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     67  * SUCH DAMAGE.
     68  *
     69  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     70  */
     71 
     72 #include <sys/cdefs.h>
     73 __KERNEL_RCSID(0, "$NetBSD: com_jazzio.c,v 1.7 2005/01/22 07:35:34 tsutsui Exp $");
     74 
     75 #include <sys/param.h>
     76 #include <sys/systm.h>
     77 #include <sys/device.h>
     78 #include <sys/tty.h>
     79 
     80 #include <machine/autoconf.h>
     81 #include <machine/bus.h>
     82 #include <machine/intr.h>
     83 
     84 #include <arc/jazz/jazziovar.h>
     85 
     86 #include <dev/isa/isavar.h>	/* XXX for isa_chipset_tag_t in com_softc */
     87 
     88 #include <dev/ic/comreg.h>
     89 #include <dev/ic/comvar.h>
     90 #include <dev/ic/ns16550reg.h>
     91 
     92 extern int com_freq;
     93 
     94 int	com_jazzio_probe(struct device *, struct cfdata *, void *);
     95 void	com_jazzio_attach(struct device *, struct device *, void *);
     96 
     97 CFATTACH_DECL(com_jazzio, sizeof(struct com_softc),
     98     com_jazzio_probe, com_jazzio_attach, NULL, NULL);
     99 
    100 int
    101 com_jazzio_probe(struct device *parent, struct cfdata *match, void *aux)
    102 {
    103 	struct jazzio_attach_args *ja = aux;
    104 	bus_space_tag_t iot;
    105 	bus_space_handle_t ioh;
    106 	int iobase;
    107 	int rv = 1;
    108 
    109 	if (strcmp(ja->ja_name, "COM1") != 0 &&
    110 	    strcmp(ja->ja_name, "COM2") != 0)
    111 		return 0;
    112 
    113 	iot = ja->ja_bust;
    114 	iobase = ja->ja_addr;
    115 
    116 	/* if it's in use as console, it's there. */
    117 	if (!com_is_console(iot, iobase, 0)) {
    118 		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    119 			return 0;
    120 		}
    121 		rv = comprobe1(iot, ioh);
    122 		bus_space_unmap(iot, ioh, COM_NPORTS);
    123 	}
    124 	return rv;
    125 }
    126 
    127 void
    128 com_jazzio_attach(struct device *parent, struct device *self, void *aux)
    129 {
    130 	struct jazzio_attach_args *ja = aux;
    131 	struct com_softc *sc = (void *)self;
    132 	int iobase;
    133 	bus_space_tag_t iot;
    134 
    135 	sc->sc_iobase = iobase = ja->ja_addr;
    136 	sc->sc_iot = iot = ja->ja_bust;
    137 
    138 	if (!com_is_console(iot, iobase, &sc->sc_ioh) &&
    139 	    bus_space_map(iot, iobase, COM_NPORTS, 0, &sc->sc_ioh)) {
    140 		printf(": can't map i/o space\n");
    141 		return;
    142 	}
    143 
    144 	sc->sc_frequency = com_freq;
    145 	SET(sc->sc_hwflags, COM_HW_TXFIFO_DISABLE); /* XXX - NEC M403 */
    146 	jazzio_intr_establish(ja->ja_intr, comintr, sc);
    147 
    148 	com_attach_subr(sc);
    149 }
    150