uart_bus_ixp425.c revision 164426
1164426Ssam/*- 2164426Ssam * Copyright (c) 2006 Kevin Lo. All rights reserved. 3164426Ssam * 4164426Ssam * Redistribution and use in source and binary forms, with or without 5164426Ssam * modification, are permitted provided that the following conditions 6164426Ssam * are met: 7164426Ssam * 1. Redistributions of source code must retain the above copyright 8164426Ssam * notice, this list of conditions and the following disclaimer. 9164426Ssam * 2. Redistributions in binary form must reproduce the above copyright 10164426Ssam * notice, this list of conditions and the following disclaimer in the 11164426Ssam * documentation and/or other materials provided with the distribution. 12164426Ssam * 13164426Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14164426Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15164426Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16164426Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17164426Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18164426Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19164426Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20164426Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21164426Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22164426Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23164426Ssam */ 24164426Ssam 25164426Ssam#include <sys/cdefs.h> 26164426Ssam__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/uart_bus_ixp425.c 164426 2006-11-19 23:55:23Z sam $"); 27164426Ssam 28164426Ssam#include <sys/param.h> 29164426Ssam#include <sys/systm.h> 30164426Ssam#include <sys/bus.h> 31164426Ssam#include <sys/conf.h> 32164426Ssam#include <sys/kernel.h> 33164426Ssam#include <sys/module.h> 34164426Ssam#include <machine/bus.h> 35164426Ssam#include <sys/rman.h> 36164426Ssam#include <machine/resource.h> 37164426Ssam 38164426Ssam#include <dev/pci/pcivar.h> 39164426Ssam#include <dev/ic/ns16550.h> 40164426Ssam 41164426Ssam#include <dev/uart/uart.h> 42164426Ssam#include <dev/uart/uart_bus.h> 43164426Ssam#include <dev/uart/uart_cpu.h> 44164426Ssam 45164426Ssam#include <arm/xscale/ixp425/ixp425reg.h> 46164426Ssam#include <arm/xscale/ixp425/ixp425var.h> 47164426Ssam 48164426Ssam#include "uart_if.h" 49164426Ssam 50164426Ssamstatic int uart_ixp425_probe(device_t dev); 51164426Ssam 52164426Ssamstatic device_method_t uart_ixp425_methods[] = { 53164426Ssam /* Device interface */ 54164426Ssam DEVMETHOD(device_probe, uart_ixp425_probe), 55164426Ssam DEVMETHOD(device_attach, uart_bus_attach), 56164426Ssam DEVMETHOD(device_detach, uart_bus_detach), 57164426Ssam { 0, 0 } 58164426Ssam}; 59164426Ssam 60164426Ssamstatic driver_t uart_ixp425_driver = { 61164426Ssam uart_driver_name, 62164426Ssam uart_ixp425_methods, 63164426Ssam sizeof(struct uart_softc), 64164426Ssam}; 65164426Ssam 66164426Ssamextern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs; 67164426Ssamstatic int 68164426Ssamuart_ixp425_probe(device_t dev) 69164426Ssam{ 70164426Ssam struct uart_softc *sc; 71164426Ssam 72164426Ssam sc = device_get_softc(dev); 73164426Ssam sc->sc_sysdev = SLIST_FIRST(&uart_sysdevs); 74164426Ssam sc->sc_class = &uart_ns8250_class; 75164426Ssam bcopy(&sc->sc_sysdev->bas, &sc->sc_bas, sizeof(sc->sc_bas)); 76164426Ssam /* 77164426Ssam * XXX set UART Unit Enable (0x40) AND 78164426Ssam * receiver timeout int enable (0x10). 79164426Ssam * The first turns on the UART. The second is necessary to get 80164426Ssam * interrupts when the FIFO has data but is not full. Note that 81164426Ssam * uart_ns8250 carefully avoids touching these bits so we can 82164426Ssam * just set them here and proceed. But this is fragile... 83164426Ssam */ 84164426Ssam bus_space_write_4(&ixp425_a4x_bs_tag, 85164426Ssam device_get_unit(dev) == 0 ? IXP425_UART0_VBASE : IXP425_UART1_VBASE, 86164426Ssam IXP425_UART_IER, IXP425_UART_IER_UUE | IXP425_UART_IER_RTOIE); 87164426Ssam return(uart_bus_probe(dev, 0, IXP425_UART_FREQ, 0, 0)); 88164426Ssam} 89164426Ssam 90164426Ssam 91164426SsamDRIVER_MODULE(uart, ixp, uart_ixp425_driver, uart_devclass, 0, 0); 92