1179595Sbenno/*- 2179595Sbenno * Copyright (c) 2006 Benno Rice. All rights reserved. 3179595Sbenno * 4179595Sbenno * Redistribution and use in source and binary forms, with or without 5179595Sbenno * modification, are permitted provided that the following conditions 6179595Sbenno * are met: 7179595Sbenno * 1. Redistributions of source code must retain the above copyright 8179595Sbenno * notice, this list of conditions and the following disclaimer. 9179595Sbenno * 2. Redistributions in binary form must reproduce the above copyright 10179595Sbenno * notice, this list of conditions and the following disclaimer in the 11179595Sbenno * documentation and/or other materials provided with the distribution. 12179595Sbenno * 13179595Sbenno * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14179595Sbenno * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15179595Sbenno * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16179595Sbenno * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17179595Sbenno * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18179595Sbenno * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19179595Sbenno * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20179595Sbenno * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21179595Sbenno * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22179595Sbenno * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23179595Sbenno */ 24179595Sbenno 25179595Sbenno#include <sys/cdefs.h> 26179595Sbenno__FBSDID("$FreeBSD$"); 27179595Sbenno 28179595Sbenno#include <sys/param.h> 29179595Sbenno#include <sys/systm.h> 30179595Sbenno#include <sys/bus.h> 31179595Sbenno#include <sys/conf.h> 32179595Sbenno#include <sys/kernel.h> 33179595Sbenno#include <sys/module.h> 34179595Sbenno#include <machine/bus.h> 35179595Sbenno#include <sys/rman.h> 36179595Sbenno#include <machine/resource.h> 37179595Sbenno 38179595Sbenno#include <dev/pci/pcivar.h> 39179595Sbenno 40179595Sbenno#include <dev/uart/uart.h> 41179595Sbenno#include <dev/uart/uart_bus.h> 42179595Sbenno#include <dev/uart/uart_cpu.h> 43179595Sbenno 44179595Sbenno#include <dev/ic/ns16550.h> 45179595Sbenno 46179595Sbenno#include <arm/xscale/pxa/pxavar.h> 47179595Sbenno#include <arm/xscale/pxa/pxareg.h> 48179595Sbenno 49179595Sbenno#include "uart_if.h" 50179595Sbenno 51179595Sbenno#define PXA_UART_UUE 0x40 /* UART Unit Enable */ 52179595Sbenno 53179595Sbennostatic int uart_pxa_probe(device_t dev); 54179595Sbenno 55179595Sbennostatic device_method_t uart_pxa_methods[] = { 56179595Sbenno /* Device interface */ 57179595Sbenno DEVMETHOD(device_probe, uart_pxa_probe), 58179595Sbenno DEVMETHOD(device_attach, uart_bus_attach), 59179595Sbenno DEVMETHOD(device_detach, uart_bus_detach), 60179595Sbenno { 0, 0 } 61179595Sbenno}; 62179595Sbenno 63179595Sbennostatic driver_t uart_pxa_driver = { 64179595Sbenno uart_driver_name, 65179595Sbenno uart_pxa_methods, 66179595Sbenno sizeof(struct uart_softc), 67179595Sbenno}; 68179595Sbenno 69179595Sbennostatic int 70179595Sbennouart_pxa_probe(device_t dev) 71179595Sbenno{ 72179595Sbenno bus_space_handle_t base; 73179595Sbenno struct uart_softc *sc; 74179595Sbenno 75234004Sstas base = (bus_space_handle_t)pxa_get_base(dev); 76234004Sstas#ifdef QEMU_WORKAROUNDS 77234004Sstas /* 78234004Sstas * QEMU really exposes only the first uart unless 79234004Sstas * you specify several of them in the configuration. 80234004Sstas * Otherwise all the rest of UARTs stay unconnected, 81234004Sstas * which causes problems in the ns16550 attach routine. 82234004Sstas * Unfortunately, even if you provide qemu with 4 uarts 83234004Sstas * on the command line, it has a bug where it segfaults 84234004Sstas * trying to enable bluetooth on the HWUART. So we just 85234004Sstas * allow the FFUART to be attached. 86234004Sstas * Also, don't check the UUE (UART Unit Enable) bit, as 87234004Sstas * the gumstix bootloader doesn't set it. 88234004Sstas */ 89234004Sstas if (base != PXA2X0_FFUART_BASE) 90234004Sstas return (ENXIO); 91234004Sstas#else 92179595Sbenno /* Check to see if the enable bit's on. */ 93179595Sbenno if ((bus_space_read_4(obio_tag, base, 94179595Sbenno (REG_IER << 2)) & PXA_UART_UUE) == 0) 95179595Sbenno return (ENXIO); 96234004Sstas#endif 97179595Sbenno sc = device_get_softc(dev); 98179595Sbenno sc->sc_class = &uart_ns8250_class; 99179595Sbenno 100179595Sbenno return(uart_bus_probe(dev, 2, PXA2X0_COM_FREQ, 0, 0)); 101179595Sbenno} 102179595Sbenno 103179595SbennoDRIVER_MODULE(uart, pxa, uart_pxa_driver, uart_devclass, 0, 0); 104