1 1.14 thorpej /* $NetBSD: pxa2x0_com.c,v 1.14 2018/12/08 17:46:10 thorpej Exp $ */ 2 1.1 scw 3 1.1 scw /* 4 1.1 scw * Copyright 2003 Wasabi Systems, Inc. 5 1.1 scw * All rights reserved. 6 1.1 scw * 7 1.1 scw * Written by Steve C. Woodford for Wasabi Systems, Inc. 8 1.1 scw * 9 1.1 scw * Redistribution and use in source and binary forms, with or without 10 1.1 scw * modification, are permitted provided that the following conditions 11 1.1 scw * are met: 12 1.1 scw * 1. Redistributions of source code must retain the above copyright 13 1.1 scw * notice, this list of conditions and the following disclaimer. 14 1.1 scw * 2. Redistributions in binary form must reproduce the above copyright 15 1.1 scw * notice, this list of conditions and the following disclaimer in the 16 1.1 scw * documentation and/or other materials provided with the distribution. 17 1.1 scw * 3. All advertising materials mentioning features or use of this software 18 1.1 scw * must display the following acknowledgement: 19 1.1 scw * This product includes software developed for the NetBSD Project by 20 1.1 scw * Wasabi Systems, Inc. 21 1.1 scw * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 1.1 scw * or promote products derived from this software without specific prior 23 1.1 scw * written permission. 24 1.1 scw * 25 1.1 scw * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 1.1 scw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 1.1 scw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 1.1 scw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 1.1 scw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 1.1 scw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 1.1 scw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 1.1 scw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 1.1 scw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 1.1 scw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 1.1 scw * POSSIBILITY OF SUCH DAMAGE. 36 1.1 scw */ 37 1.4 lukem 38 1.4 lukem #include <sys/cdefs.h> 39 1.14 thorpej __KERNEL_RCSID(0, "$NetBSD: pxa2x0_com.c,v 1.14 2018/12/08 17:46:10 thorpej Exp $"); 40 1.1 scw 41 1.1 scw #include "opt_com.h" 42 1.1 scw 43 1.1 scw #ifndef COM_PXA2X0 44 1.1 scw #error "You must use options COM_PXA2X0 to get PXA2x0 serial port support" 45 1.1 scw #endif 46 1.1 scw 47 1.1 scw #include <sys/param.h> 48 1.1 scw #include <sys/systm.h> 49 1.1 scw #include <sys/device.h> 50 1.1 scw #include <sys/termios.h> 51 1.1 scw 52 1.1 scw #include <machine/intr.h> 53 1.13 dyoung #include <sys/bus.h> 54 1.1 scw 55 1.1 scw #include <dev/ic/comreg.h> 56 1.1 scw #include <dev/ic/comvar.h> 57 1.1 scw 58 1.8 kiyohara #include <arm/xscale/pxa2x0cpu.h> 59 1.1 scw #include <arm/xscale/pxa2x0reg.h> 60 1.1 scw #include <arm/xscale/pxa2x0var.h> 61 1.8 kiyohara #include <arm/xscale/pxa2x0_gpio.h> 62 1.1 scw 63 1.1 scw #include "locators.h" 64 1.1 scw 65 1.10 cube static int pxauart_match(device_t, cfdata_t , void *); 66 1.10 cube static void pxauart_attach(device_t, device_t, void *); 67 1.1 scw 68 1.10 cube CFATTACH_DECL_NEW(pxauart, sizeof(struct com_softc), 69 1.1 scw pxauart_match, pxauart_attach, NULL, NULL); 70 1.1 scw 71 1.1 scw static int 72 1.10 cube pxauart_match(device_t parent, cfdata_t cf, void *aux) 73 1.1 scw { 74 1.1 scw struct pxaip_attach_args *pxa = aux; 75 1.1 scw bus_space_tag_t bt = &pxa2x0_a4x_bs_tag; /* XXX: This sucks */ 76 1.1 scw bus_space_handle_t bh; 77 1.8 kiyohara struct pxa2x0_gpioconf *gpioconf; 78 1.8 kiyohara u_int gpio; 79 1.8 kiyohara int rv, i; 80 1.1 scw 81 1.1 scw switch (pxa->pxa_addr) { 82 1.1 scw case PXA2X0_FFUART_BASE: 83 1.1 scw if (pxa->pxa_intr != PXA2X0_INT_FFUART) 84 1.1 scw return (0); 85 1.8 kiyohara gpioconf = CPU_IS_PXA250 ? pxa25x_com_ffuart_gpioconf : 86 1.8 kiyohara pxa27x_com_ffuart_gpioconf; 87 1.1 scw break; 88 1.1 scw 89 1.1 scw case PXA2X0_STUART_BASE: 90 1.1 scw if (pxa->pxa_intr != PXA2X0_INT_STUART) 91 1.1 scw return (0); 92 1.8 kiyohara gpioconf = CPU_IS_PXA250 ? pxa25x_com_stuart_gpioconf : 93 1.8 kiyohara pxa27x_com_stuart_gpioconf; 94 1.1 scw break; 95 1.1 scw 96 1.1 scw case PXA2X0_BTUART_BASE: /* XXX: Config file option ... */ 97 1.1 scw if (pxa->pxa_intr != PXA2X0_INT_BTUART) 98 1.1 scw return (0); 99 1.8 kiyohara gpioconf = CPU_IS_PXA250 ? pxa25x_com_btuart_gpioconf : 100 1.8 kiyohara pxa27x_com_btuart_gpioconf; 101 1.1 scw break; 102 1.1 scw 103 1.7 kiyohara case PXA2X0_HWUART_BASE: 104 1.7 kiyohara if (pxa->pxa_intr != PXA2X0_INT_HWUART) 105 1.7 kiyohara return (0); 106 1.11 kiyohara if (CPU_IS_PXA270) 107 1.11 kiyohara return (0); 108 1.11 kiyohara gpioconf = pxa25x_com_hwuart_gpioconf; 109 1.7 kiyohara break; 110 1.7 kiyohara 111 1.1 scw default: 112 1.1 scw return (0); 113 1.1 scw } 114 1.8 kiyohara for (i = 0; gpioconf[i].pin != -1; i++) { 115 1.8 kiyohara gpio = pxa2x0_gpio_get_function(gpioconf[i].pin); 116 1.8 kiyohara if (GPIO_FN(gpio) != GPIO_FN(gpioconf[i].value) || 117 1.8 kiyohara GPIO_FN_IS_OUT(gpio) != GPIO_FN_IS_OUT(gpioconf[i].value)) 118 1.8 kiyohara return (0); 119 1.8 kiyohara } 120 1.1 scw 121 1.1 scw pxa->pxa_size = 0x20; 122 1.1 scw 123 1.1 scw if (com_is_console(bt, pxa->pxa_addr, NULL)) 124 1.1 scw return (1); 125 1.1 scw 126 1.1 scw if (bus_space_map(bt, pxa->pxa_addr, pxa->pxa_size, 0, &bh)) 127 1.1 scw return (0); 128 1.1 scw 129 1.1 scw /* Make sure the UART is enabled */ 130 1.1 scw bus_space_write_1(bt, bh, com_ier, IER_EUART); 131 1.1 scw 132 1.1 scw rv = comprobe1(bt, bh); 133 1.1 scw bus_space_unmap(bt, bh, pxa->pxa_size); 134 1.1 scw 135 1.1 scw return (rv); 136 1.1 scw } 137 1.1 scw 138 1.1 scw static void 139 1.10 cube pxauart_attach(device_t parent, device_t self, void *aux) 140 1.1 scw { 141 1.10 cube struct com_softc *sc = device_private(self); 142 1.1 scw struct pxaip_attach_args *pxa = aux; 143 1.6 gdamore bus_space_tag_t iot; 144 1.6 gdamore bus_space_handle_t ioh; 145 1.6 gdamore bus_addr_t iobase; 146 1.12 kiyohara int cken = 0; 147 1.1 scw 148 1.10 cube sc->sc_dev = self; 149 1.6 gdamore iot = &pxa2x0_a4x_bs_tag; /* XXX: This sucks */ 150 1.6 gdamore iobase = pxa->pxa_addr; 151 1.1 scw sc->sc_frequency = PXA2X0_COM_FREQ; 152 1.2 thorpej sc->sc_type = COM_TYPE_PXA2x0; 153 1.1 scw 154 1.6 gdamore if (com_is_console(iot, iobase, &ioh) == 0 && 155 1.6 gdamore bus_space_map(iot, iobase, pxa->pxa_size, 0, &ioh)) { 156 1.10 cube aprint_error(": can't map registers\n"); 157 1.1 scw return; 158 1.1 scw } 159 1.14 thorpej com_init_regs(&sc->sc_regs, iot, ioh, iobase); 160 1.1 scw 161 1.12 kiyohara switch (pxa->pxa_addr) { 162 1.12 kiyohara case PXA2X0_FFUART_BASE: cken = CKEN_FFUART; break; 163 1.12 kiyohara case PXA2X0_STUART_BASE: cken = CKEN_STUART; break; 164 1.12 kiyohara case PXA2X0_BTUART_BASE: cken = CKEN_BTUART; break; 165 1.12 kiyohara case PXA2X0_HWUART_BASE: cken = CKEN_HWUART; break; 166 1.12 kiyohara } 167 1.12 kiyohara pxa2x0_clkman_config(cken, 1); 168 1.12 kiyohara 169 1.1 scw com_attach_subr(sc); 170 1.1 scw 171 1.1 scw pxa2x0_intr_establish(pxa->pxa_intr, IPL_SERIAL, comintr, sc); 172 1.1 scw } 173