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