1 /* $NetBSD: com_ebus.c,v 1.30 2010/01/03 17:02:03 jdc Exp $ */ 2 3 /* 4 * Copyright (c) 1999, 2000 Matthew R. Green 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 /* 30 * NS Super I/O PC87332VLJ "com" to ebus attachment 31 */ 32 33 #include <sys/cdefs.h> 34 __KERNEL_RCSID(0, "$NetBSD: com_ebus.c,v 1.30 2010/01/03 17:02:03 jdc Exp $"); 35 36 #include <sys/types.h> 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/device.h> 40 #include <sys/tty.h> 41 #include <sys/conf.h> 42 43 #include <machine/bus.h> 44 #include <machine/autoconf.h> 45 #include <machine/openfirm.h> 46 47 #include <dev/ebus/ebusreg.h> 48 #include <dev/ebus/ebusvar.h> 49 50 #include <dev/cons.h> 51 #include <dev/ic/comvar.h> 52 #include <dev/sun/kbd_ms_ttyvar.h> 53 54 #include "kbd.h" 55 #include "ms.h" 56 57 int com_ebus_match(device_t, cfdata_t , void *); 58 void com_ebus_attach(device_t, device_t, void *); 59 60 CFATTACH_DECL_NEW(com_ebus, sizeof(struct com_softc), 61 com_ebus_match, com_ebus_attach, NULL, NULL); 62 63 static const char *com_names[] = { 64 "su", 65 "su_pnp", 66 "rsc-console", 67 NULL 68 }; 69 70 int 71 com_ebus_match(device_t parent, cfdata_t match, void *aux) 72 { 73 struct ebus_attach_args *ea = aux; 74 int i; 75 76 for (i = 0; com_names[i]; i++) 77 if (strcmp(ea->ea_name, com_names[i]) == 0) 78 return (1); 79 80 if (strcmp(ea->ea_name, "serial") == 0) { 81 char *compat; 82 83 /* Could be anything. */ 84 compat = prom_getpropstring(ea->ea_node, "compatible"); 85 if (strcmp(compat, "su16550") == 0 || 86 strcmp(compat, "su") == 0) { 87 return (1); 88 } 89 } 90 return (0); 91 } 92 93 #define BAUD_BASE (1846200) 94 95 void 96 com_ebus_attach(device_t parent, device_t self, void *aux) 97 { 98 struct com_softc *sc = device_private(self); 99 struct ebus_attach_args *ea = aux; 100 struct kbd_ms_tty_attach_args kma; 101 #if (NKBD > 0) || (NMS > 0) 102 int maj; 103 extern const struct cdevsw com_cdevsw; 104 #endif 105 int i; 106 int com_is_input; 107 int com_is_output; 108 bus_space_handle_t ioh; 109 bus_space_tag_t iot; 110 bus_addr_t iobase; 111 112 sc->sc_dev = self; 113 iot = ea->ea_bustag; 114 iobase = EBUS_ADDR_FROM_REG(&ea->ea_reg[0]); 115 116 /* 117 * Addresses that should be supplied by the prom: 118 * - normal com registers 119 * - ns873xx configuration registers 120 * - DMA space 121 * The `com' driver does not use DMA accesses, so we can 122 * ignore that for now. We should enable the com port in 123 * the ns873xx registers here. XXX 124 * 125 * Use the prom address if there. 126 */ 127 128 if (ea->ea_nvaddr) 129 sparc_promaddr_to_handle(iot, ea->ea_vaddr[0], 130 &ioh); 131 else if (bus_space_map(iot, iobase, 132 ea->ea_reg[0].size, 0, &ioh) != 0) { 133 aprint_error(": can't map register space\n"); 134 return; 135 } 136 COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase); 137 138 sc->sc_hwflags = 0; 139 sc->sc_frequency = BAUD_BASE; 140 141 for (i = 0; i < ea->ea_nintr; i++) 142 bus_intr_establish(ea->ea_bustag, ea->ea_intr[i], 143 IPL_SERIAL, comintr, sc); 144 145 kma.kmta_consdev = NULL; 146 147 /* Figure out if we're the console. */ 148 com_is_input = (ea->ea_node == prom_instance_to_package(prom_stdin())); 149 com_is_output = (ea->ea_node == prom_instance_to_package(prom_stdout())); 150 151 if (com_is_input || com_is_output) { 152 struct consdev *cn_orig; 153 154 /* Record some info to attach console. */ 155 if (strcmp(ea->ea_name, "rsc-console") == 0) 156 kma.kmta_baud = 115200; 157 else 158 kma.kmta_baud = 9600; 159 kma.kmta_cflag = (CREAD | CS8 | HUPCL); 160 161 /* Attach com as the console. */ 162 cn_orig = cn_tab; 163 if (comcnattach(iot, iobase, kma.kmta_baud, 164 sc->sc_frequency, COM_TYPE_NORMAL, kma.kmta_cflag)) { 165 aprint_error("Error: comcnattach failed\n"); 166 } 167 if (com_is_input) { 168 cn_orig->cn_dev = cn_tab->cn_dev; 169 cn_orig->cn_probe = cn_tab->cn_probe; 170 cn_orig->cn_init = cn_tab->cn_init; 171 cn_orig->cn_getc = cn_tab->cn_getc; 172 cn_orig->cn_pollc = cn_tab->cn_pollc; 173 } 174 if (com_is_output) { 175 cn_orig->cn_putc = cn_tab->cn_putc; 176 } 177 cn_tab = cn_orig; 178 kma.kmta_consdev = cn_tab; 179 } 180 /* Now attach the driver */ 181 com_attach_subr(sc); 182 183 #if (NKBD > 0) || (NMS > 0) 184 kma.kmta_tp = sc->sc_tty; 185 /* If we figure out we're the console we should point this to our consdev */ 186 187 /* locate the major number */ 188 maj = cdevsw_lookup_major(&com_cdevsw); 189 190 kma.kmta_dev = makedev(maj, device_unit(sc->sc_dev)); 191 192 /* Attach 'em if we got 'em. */ 193 #if (NKBD > 0) 194 kma.kmta_name = "keyboard"; 195 if (prom_getproplen(ea->ea_node, kma.kmta_name) == 0) { 196 config_found(self, (void *)&kma, NULL); 197 } 198 #endif 199 #if (NMS > 0) 200 kma.kmta_name = "mouse"; 201 if (prom_getproplen(ea->ea_node, kma.kmta_name) == 0) { 202 config_found(self, (void *)&kma, NULL); 203 } 204 #endif 205 #endif 206 if (kma.kmta_consdev) { 207 /* 208 * If we're the keyboard then we need the original 209 * cn_tab w/prom I/O, which sunkbd copied into kma. 210 * Otherwise we want conscom which we copied into 211 * kma.kmta_consdev. 212 */ 213 cn_tab = kma.kmta_consdev; 214 } 215 } 216