1 /* $NetBSD: com_eumb.c,v 1.12 2021/03/25 05:35:50 rin Exp $ */ 2 3 /*- 4 * Copyright (c) 2007 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Tohru Nishimura. 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: com_eumb.c,v 1.12 2021/03/25 05:35:50 rin Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/device.h> 37 #include <sys/tty.h> 38 #include <sys/systm.h> 39 40 #include <sys/bus.h> 41 #include <machine/intr.h> 42 43 #include <dev/ic/comreg.h> 44 #include <dev/ic/comvar.h> 45 46 #include <sandpoint/sandpoint/eumbvar.h> 47 #include "locators.h" 48 49 static int com_eumb_match(device_t, cfdata_t , void *); 50 static void com_eumb_attach(device_t, device_t, void *); 51 52 CFATTACH_DECL_NEW(com_eumb, sizeof(struct com_softc), 53 com_eumb_match, com_eumb_attach, NULL, NULL); 54 55 static int found; 56 static struct com_regs cnregs; 57 58 /* 59 * There are two different UART configurations: single 4-wire UART 60 * and dual 2-wire. The DCR register selects one of the two operating 61 * modes. A certain group of NAS boxes uses the 2nd UART as system 62 * console while using the 1st to communicate with the power management 63 * satellite processor. The "unit" locator helps to reverse the two. 64 * Default is a single 4-wire UART as console. 65 */ 66 int 67 com_eumb_match(device_t parent, cfdata_t cf, void *aux) 68 { 69 struct eumb_attach_args *eaa = aux; 70 int unit = eaa->eumb_unit; 71 72 if (unit == EUMBCF_UNIT_DEFAULT && found == 0) 73 return 1; 74 if (unit == 0 || unit == 1) 75 return 1; 76 return 0; 77 } 78 79 void 80 com_eumb_attach(device_t parent, device_t self, void *aux) 81 { 82 struct com_softc *sc = device_private(self); 83 struct eumb_attach_args *eaa = aux; 84 int comaddr, epicirq; 85 bus_space_handle_t ioh; 86 extern u_long ticks_per_sec; 87 88 sc->sc_dev = self; 89 found = 1; 90 91 comaddr = (eaa->eumb_unit == 1) ? 0x4600 : 0x4500; 92 if (com_is_console(eaa->eumb_bt, comaddr, &ioh)) { 93 cnregs.cr_ioh = ioh; 94 sc->sc_regs = cnregs; 95 } else { 96 bus_space_map(eaa->eumb_bt, comaddr, COM_NPORTS, 0, &ioh); 97 com_init_regs(&sc->sc_regs, eaa->eumb_bt, ioh, comaddr); 98 } 99 sc->sc_frequency = 4 * ticks_per_sec; 100 epicirq = (eaa->eumb_unit == 1) ? 25 : 24; 101 102 /* 103 * XXX 104 * At least KuroBox Classic and HG seem to have a hardware bug, by 105 * which ETXRDY interrupt is sometimes, say, once per few hours, 106 * lost; output stalls until next input arrives. In order to work 107 * around this problem, push TX queue manually by low-rate. 108 */ 109 #define COM_EUMB_FLAG_BROKEN_ETXRDY __BIT(0) 110 if (device_cfdata(self)->cf_flags & COM_EUMB_FLAG_BROKEN_ETXRDY) { 111 SET(sc->sc_hwflags, COM_HW_BROKEN_ETXRDY); 112 sc->sc_poll_ticks = 10 * hz; /* once per 10 sec */ 113 } 114 115 com_attach_subr(sc); 116 117 intr_establish_xname(epicirq + I8259_ICU, IST_LEVEL, IPL_SERIAL, 118 comintr, sc, device_xname(self)); 119 aprint_normal_dev(self, "interrupting at irq %d\n", 120 epicirq + I8259_ICU); 121 } 122 123 int 124 eumbcnattach(bus_space_tag_t tag, 125 int conaddr, int conspeed, int confreq, int contype, int conmode) 126 { 127 static int attached = 0; 128 bus_space_handle_t dummy_bsh; /* XXX see com.c:comcnattach() */ 129 130 memset(&dummy_bsh, 0, sizeof(dummy_bsh)); 131 132 if (attached) 133 return 0; 134 attached = 1; 135 136 cnregs.cr_iot = tag; 137 cnregs.cr_iobase = conaddr; 138 cnregs.cr_nports = COM_NPORTS; 139 com_init_regs(&cnregs, tag, dummy_bsh, conaddr); 140 return comcnattach1(&cnregs, conspeed, confreq, contype, conmode); 141 } 142