Home | History | Annotate | Line # | Download | only in dev
      1  1.25  thorpej /*	$NetBSD: com_obio.c,v 1.25 2018/12/08 17:46:13 thorpej Exp $	*/
      2   1.1     matt 
      3   1.1     matt /*-
      4   1.1     matt  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5   1.1     matt  * All rights reserved.
      6   1.1     matt  *
      7   1.1     matt  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1     matt  * by Charles M. Hannum.
      9   1.1     matt  *
     10   1.1     matt  * Redistribution and use in source and binary forms, with or without
     11   1.1     matt  * modification, are permitted provided that the following conditions
     12   1.1     matt  * are met:
     13   1.1     matt  * 1. Redistributions of source code must retain the above copyright
     14   1.1     matt  *    notice, this list of conditions and the following disclaimer.
     15   1.1     matt  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1     matt  *    notice, this list of conditions and the following disclaimer in the
     17   1.1     matt  *    documentation and/or other materials provided with the distribution.
     18   1.1     matt  *
     19   1.1     matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1     matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1     matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1     matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1     matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1     matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1     matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1     matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1     matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1     matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1     matt  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1     matt  */
     31   1.1     matt 
     32   1.1     matt /*-
     33   1.1     matt  * Copyright (c) 1991 The Regents of the University of California.
     34   1.1     matt  * All rights reserved.
     35   1.1     matt  *
     36   1.1     matt  * Redistribution and use in source and binary forms, with or without
     37   1.1     matt  * modification, are permitted provided that the following conditions
     38   1.1     matt  * are met:
     39   1.1     matt  * 1. Redistributions of source code must retain the above copyright
     40   1.1     matt  *    notice, this list of conditions and the following disclaimer.
     41   1.1     matt  * 2. Redistributions in binary form must reproduce the above copyright
     42   1.1     matt  *    notice, this list of conditions and the following disclaimer in the
     43   1.1     matt  *    documentation and/or other materials provided with the distribution.
     44  1.16      agc  * 3. Neither the name of the University nor the names of its contributors
     45   1.1     matt  *    may be used to endorse or promote products derived from this software
     46   1.1     matt  *    without specific prior written permission.
     47   1.1     matt  *
     48   1.1     matt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     49   1.1     matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     50   1.1     matt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     51   1.1     matt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     52   1.1     matt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     53   1.1     matt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     54   1.1     matt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     55   1.1     matt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     56   1.1     matt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     57   1.1     matt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     58   1.1     matt  * SUCH DAMAGE.
     59   1.1     matt  *
     60   1.1     matt  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     61   1.1     matt  */
     62  1.15    lukem 
     63  1.15    lukem #include <sys/cdefs.h>
     64  1.25  thorpej __KERNEL_RCSID(0, "$NetBSD: com_obio.c,v 1.25 2018/12/08 17:46:13 thorpej Exp $");
     65   1.1     matt 
     66   1.1     matt #include <sys/param.h>
     67   1.1     matt #include <sys/systm.h>
     68   1.1     matt #include <sys/ioctl.h>
     69   1.1     matt #include <sys/select.h>
     70   1.1     matt #include <sys/tty.h>
     71   1.1     matt #include <sys/proc.h>
     72   1.1     matt #include <sys/conf.h>
     73   1.1     matt #include <sys/file.h>
     74   1.1     matt #include <sys/uio.h>
     75   1.1     matt #include <sys/kernel.h>
     76   1.1     matt #include <sys/syslog.h>
     77   1.1     matt #include <sys/types.h>
     78   1.1     matt #include <sys/device.h>
     79   1.8      uwe #include <sys/termios.h>
     80   1.1     matt 
     81  1.24   dyoung #include <sys/bus.h>
     82   1.1     matt #include <machine/autoconf.h>
     83   1.6       pk #include <machine/intr.h>
     84   1.1     matt 
     85   1.1     matt #include <dev/ic/comreg.h>
     86   1.1     matt #include <dev/ic/comvar.h>
     87   1.1     matt 
     88   1.3     matt #include <sparc/sparc/auxreg.h>
     89   1.3     matt 
     90   1.1     matt struct com_obio_softc {
     91   1.1     matt 	struct com_softc osc_com;	/* real "com" softc */
     92   1.1     matt 
     93   1.7     matt 	int osc_tadpole;		/* is this on a tadpole */
     94   1.1     matt 	/* OBIO-specific goo. */
     95   1.1     matt 	struct evcnt osc_intrcnt;	/* interrupt counting */
     96   1.1     matt };
     97   1.1     matt 
     98  1.21     cube static int com_obio_match(device_t, cfdata_t , void *);
     99  1.21     cube static void com_obio_attach(device_t, device_t, void *);
    100   1.1     matt 
    101  1.21     cube CFATTACH_DECL_NEW(com_obio, sizeof(struct com_obio_softc),
    102  1.12  thorpej     com_obio_match, com_obio_attach, NULL, NULL);
    103   1.1     matt 
    104   1.1     matt static int
    105  1.21     cube com_obio_match(device_t parent, cfdata_t cf, void *aux)
    106   1.1     matt {
    107   1.1     matt 	union obio_attach_args *uoba = aux;
    108   1.1     matt 	struct sbus_attach_args *sa = &uoba->uoba_sbus;
    109   1.7     matt 	int tadpole = 0;
    110   1.7     matt 	int need_probe = 0;
    111   1.7     matt 	int rv = 0;
    112  1.17      chs 	uint8_t auxregval = 0;
    113   1.1     matt 
    114   1.1     matt 	if (uoba->uoba_isobio4 != 0) {
    115   1.1     matt 		return (0);
    116   1.1     matt 	}
    117   1.1     matt 
    118  1.17      chs 	/*
    119  1.17      chs 	 * Tadpole 3GX/3GS uses "modem" for a 16450 port
    120   1.7     matt 	 * (We need to enable it before probing)
    121   1.1     matt 	 */
    122   1.1     matt 	if (strcmp("modem", sa->sa_name) == 0) {
    123   1.7     matt 		auxregval = *AUXIO4M_REG;
    124   1.7     matt 		*AUXIO4M_REG = auxregval | (AUXIO4M_LED|AUXIO4M_LTE);
    125   1.7     matt 		DELAY(100);
    126   1.7     matt 		tadpole = 1;
    127   1.7     matt 		need_probe = 1;
    128   1.7     matt 	}
    129   1.7     matt 
    130  1.17      chs 	/*
    131  1.17      chs 	 * Sun JavaStation 1 uses "su" for a 16550 port
    132   1.7     matt 	 */
    133   1.7     matt 	if (strcmp("su", sa->sa_name) == 0) {
    134   1.7     matt 		need_probe = 1;
    135   1.7     matt 	}
    136   1.7     matt 
    137   1.7     matt 	if (need_probe) {
    138   1.2     matt 		bus_space_handle_t ioh;
    139   1.7     matt 
    140   1.9       pk 		if (sbus_bus_map(sa->sa_bustag,
    141   1.9       pk 				 sa->sa_slot, sa->sa_offset, sa->sa_size,
    142   1.9       pk 				 BUS_SPACE_MAP_LINEAR, &ioh) == 0) {
    143   1.2     matt 			rv = comprobe1(sa->sa_bustag, ioh);
    144   1.3     matt #if 0
    145   1.3     matt 			printf("modem: probe: lcr=0x%02x iir=0x%02x\n",
    146   1.3     matt 				bus_space_read_1(sa->sa_bustag, ioh, 3),
    147   1.3     matt 				bus_space_read_1(sa->sa_bustag, ioh, 2));
    148   1.3     matt #endif
    149   1.3     matt 			bus_space_unmap(sa->sa_bustag, ioh, sa->sa_size);
    150   1.2     matt 		}
    151   1.7     matt 	}
    152   1.7     matt 
    153   1.7     matt 	/* Disable the com port if tadpole */
    154   1.7     matt 	if (tadpole)
    155   1.3     matt 		*AUXIO4M_REG = auxregval;
    156   1.7     matt 
    157   1.7     matt 	return (rv);
    158   1.1     matt }
    159   1.1     matt 
    160   1.1     matt static void
    161  1.21     cube com_obio_attach(device_t parent, device_t self, void *aux)
    162   1.1     matt {
    163  1.21     cube 	struct com_obio_softc *osc = device_private(self);
    164   1.1     matt 	struct com_softc *sc = &osc->osc_com;
    165   1.1     matt 	union obio_attach_args *uoba = aux;
    166   1.1     matt 	struct sbus_attach_args *sa = &uoba->uoba_sbus;
    167  1.19  gdamore 	bus_space_handle_t ioh;
    168  1.19  gdamore 	bus_space_tag_t iot;
    169  1.19  gdamore 	bus_addr_t iobase;
    170   1.1     matt 
    171  1.21     cube 	sc->sc_dev = self;
    172  1.21     cube 
    173   1.7     matt 	if (strcmp("modem", sa->sa_name) == 0) {
    174   1.7     matt 		osc->osc_tadpole = 1;
    175   1.7     matt 	}
    176   1.7     matt 
    177   1.1     matt 	/*
    178   1.3     matt 	 * We're living on an obio that looks like an sbus slot.
    179   1.1     matt 	 */
    180  1.19  gdamore 	iot = sa->sa_bustag;
    181  1.19  gdamore 	iobase = sa->sa_offset;
    182   1.8      uwe 	sc->sc_frequency = COM_FREQ;
    183   1.8      uwe 
    184   1.8      uwe 	/*
    185   1.8      uwe 	 * XXX: It would be nice to be able to split console input and
    186   1.8      uwe 	 * output to different devices.  For now switch to serial
    187   1.8      uwe 	 * console if PROM stdin is on serial (so that we can use DDB).
    188   1.8      uwe 	 */
    189   1.8      uwe 	if (prom_instance_to_package(prom_stdin()) == sa->sa_node)
    190  1.19  gdamore 		comcnattach(iot, iobase, B9600, sc->sc_frequency,
    191  1.19  gdamore 		    COM_TYPE_NORMAL, (CLOCAL | CREAD | CS8));
    192  1.19  gdamore 
    193  1.19  gdamore 	if (!com_is_console(iot, iobase, &ioh) &&
    194  1.19  gdamore 	    sbus_bus_map(iot, sa->sa_slot, iobase, sa->sa_size,
    195  1.19  gdamore 			 BUS_SPACE_MAP_LINEAR, &ioh) != 0) {
    196  1.21     cube 		aprint_error(": can't map registers\n");
    197   1.1     matt 		return;
    198   1.1     matt 	}
    199   1.1     matt 
    200  1.25  thorpej 	com_init_regs(&sc->sc_regs, iot, ioh, iobase);
    201  1.19  gdamore 
    202   1.7     matt 	if (osc->osc_tadpole) {
    203   1.7     matt 		*AUXIO4M_REG |= (AUXIO4M_LED|AUXIO4M_LTE);
    204   1.7     matt 		do {
    205   1.7     matt 			DELAY(100);
    206  1.19  gdamore 		} while (!com_probe_subr(&sc->sc_regs));
    207   1.3     matt #if 0
    208   1.7     matt 		printf("modem: attach: lcr=0x%02x iir=0x%02x\n",
    209  1.19  gdamore 			bus_space_read_1(sc->sc_regs.iot, sc->sc_regs.ioh, 3),
    210  1.19  gdamore 			bus_space_read_1(sc->sc_regs.iot, sc->sc_regs.ioh, 2));
    211   1.3     matt #endif
    212   1.7     matt 	}
    213   1.3     matt 
    214   1.1     matt 	com_attach_subr(sc);
    215   1.1     matt 
    216   1.4       pk 	if (sa->sa_nintr != 0) {
    217  1.19  gdamore 		(void)bus_intr_establish(sc->sc_regs.cr_iot, sa->sa_pri,
    218  1.19  gdamore 		    IPL_SERIAL, comintr, sc);
    219   1.5      cgd 		evcnt_attach_dynamic(&osc->osc_intrcnt, EVCNT_TYPE_INTR, NULL,
    220  1.21     cube 		    device_xname(self), "intr");
    221   1.4       pk 	}
    222   1.1     matt 
    223  1.20   dyoung 	if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) {
    224  1.21     cube 		aprint_error_dev(self, "could not establish shutdown hook");
    225   1.1     matt 	}
    226   1.1     matt }
    227