1 /* $NetBSD: com_obio.c,v 1.19 2006/07/13 22:56:02 gdamore 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. Neither the name of the University nor the names of its contributors 52 * may be used to endorse or promote products derived from this software 53 * without specific prior written permission. 54 * 55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 65 * SUCH DAMAGE. 66 * 67 * @(#)com.c 7.5 (Berkeley) 5/16/91 68 */ 69 70 #include <sys/cdefs.h> 71 __KERNEL_RCSID(0, "$NetBSD: com_obio.c,v 1.19 2006/07/13 22:56:02 gdamore Exp $"); 72 73 #include <sys/param.h> 74 #include <sys/systm.h> 75 #include <sys/ioctl.h> 76 #include <sys/select.h> 77 #include <sys/tty.h> 78 #include <sys/proc.h> 79 #include <sys/user.h> 80 #include <sys/conf.h> 81 #include <sys/file.h> 82 #include <sys/uio.h> 83 #include <sys/kernel.h> 84 #include <sys/syslog.h> 85 #include <sys/types.h> 86 #include <sys/device.h> 87 #include <sys/termios.h> 88 89 #include <machine/bus.h> 90 #include <machine/autoconf.h> 91 #include <machine/intr.h> 92 93 #include <dev/ic/comreg.h> 94 #include <dev/ic/comvar.h> 95 96 #include <sparc/sparc/auxreg.h> 97 98 struct com_obio_softc { 99 struct com_softc osc_com; /* real "com" softc */ 100 101 int osc_tadpole; /* is this on a tadpole */ 102 /* OBIO-specific goo. */ 103 struct evcnt osc_intrcnt; /* interrupt counting */ 104 }; 105 106 static int com_obio_match(struct device *, struct cfdata *, void *); 107 static void com_obio_attach(struct device *, struct device *, void *); 108 109 CFATTACH_DECL(com_obio, sizeof(struct com_obio_softc), 110 com_obio_match, com_obio_attach, NULL, NULL); 111 112 static int 113 com_obio_match(struct device *parent, struct cfdata *cf, void *aux) 114 { 115 union obio_attach_args *uoba = aux; 116 struct sbus_attach_args *sa = &uoba->uoba_sbus; 117 int tadpole = 0; 118 int need_probe = 0; 119 int rv = 0; 120 uint8_t auxregval = 0; 121 122 if (uoba->uoba_isobio4 != 0) { 123 return (0); 124 } 125 126 /* 127 * Tadpole 3GX/3GS uses "modem" for a 16450 port 128 * (We need to enable it before probing) 129 */ 130 if (strcmp("modem", sa->sa_name) == 0) { 131 auxregval = *AUXIO4M_REG; 132 *AUXIO4M_REG = auxregval | (AUXIO4M_LED|AUXIO4M_LTE); 133 DELAY(100); 134 tadpole = 1; 135 need_probe = 1; 136 } 137 138 /* 139 * Sun JavaStation 1 uses "su" for a 16550 port 140 */ 141 if (strcmp("su", sa->sa_name) == 0) { 142 need_probe = 1; 143 } 144 145 if (need_probe) { 146 bus_space_handle_t ioh; 147 148 if (sbus_bus_map(sa->sa_bustag, 149 sa->sa_slot, sa->sa_offset, sa->sa_size, 150 BUS_SPACE_MAP_LINEAR, &ioh) == 0) { 151 rv = comprobe1(sa->sa_bustag, ioh); 152 #if 0 153 printf("modem: probe: lcr=0x%02x iir=0x%02x\n", 154 bus_space_read_1(sa->sa_bustag, ioh, 3), 155 bus_space_read_1(sa->sa_bustag, ioh, 2)); 156 #endif 157 bus_space_unmap(sa->sa_bustag, ioh, sa->sa_size); 158 } 159 } 160 161 /* Disable the com port if tadpole */ 162 if (tadpole) 163 *AUXIO4M_REG = auxregval; 164 165 return (rv); 166 } 167 168 static void 169 com_obio_attach(struct device *parent, struct device *self, void *aux) 170 { 171 struct com_obio_softc *osc = (void *)self; 172 struct com_softc *sc = &osc->osc_com; 173 union obio_attach_args *uoba = aux; 174 struct sbus_attach_args *sa = &uoba->uoba_sbus; 175 bus_space_handle_t ioh; 176 bus_space_tag_t iot; 177 bus_addr_t iobase; 178 179 if (strcmp("modem", sa->sa_name) == 0) { 180 osc->osc_tadpole = 1; 181 } 182 183 /* 184 * We're living on an obio that looks like an sbus slot. 185 */ 186 iot = sa->sa_bustag; 187 iobase = sa->sa_offset; 188 sc->sc_frequency = COM_FREQ; 189 190 /* 191 * XXX: It would be nice to be able to split console input and 192 * output to different devices. For now switch to serial 193 * console if PROM stdin is on serial (so that we can use DDB). 194 */ 195 if (prom_instance_to_package(prom_stdin()) == sa->sa_node) 196 comcnattach(iot, iobase, B9600, sc->sc_frequency, 197 COM_TYPE_NORMAL, (CLOCAL | CREAD | CS8)); 198 199 if (!com_is_console(iot, iobase, &ioh) && 200 sbus_bus_map(iot, sa->sa_slot, iobase, sa->sa_size, 201 BUS_SPACE_MAP_LINEAR, &ioh) != 0) { 202 printf(": can't map registers\n"); 203 return; 204 } 205 206 COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase); 207 208 if (osc->osc_tadpole) { 209 *AUXIO4M_REG |= (AUXIO4M_LED|AUXIO4M_LTE); 210 do { 211 DELAY(100); 212 } while (!com_probe_subr(&sc->sc_regs)); 213 #if 0 214 printf("modem: attach: lcr=0x%02x iir=0x%02x\n", 215 bus_space_read_1(sc->sc_regs.iot, sc->sc_regs.ioh, 3), 216 bus_space_read_1(sc->sc_regs.iot, sc->sc_regs.ioh, 2)); 217 #endif 218 } 219 220 com_attach_subr(sc); 221 222 if (sa->sa_nintr != 0) { 223 (void)bus_intr_establish(sc->sc_regs.cr_iot, sa->sa_pri, 224 IPL_SERIAL, comintr, sc); 225 evcnt_attach_dynamic(&osc->osc_intrcnt, EVCNT_TYPE_INTR, NULL, 226 osc->osc_com.sc_dev.dv_xname, "intr"); 227 } 228 229 /* 230 * Shutdown hook for buggy BIOSs that don't recognize the UART 231 * without a disabled FIFO. 232 */ 233 if (shutdownhook_establish(com_cleanup, sc) == NULL) { 234 panic("com_obio_attach: could not establish shutdown hook"); 235 } 236 } 237