uart_bus_at91usart.c revision 187602
1155324Simp/*- 2155324Simp * Copyright (c) 2005 Olivier Houchard. All rights reserved. 3155324Simp * 4155324Simp * Redistribution and use in source and binary forms, with or without 5155324Simp * modification, are permitted provided that the following conditions 6155324Simp * are met: 7155324Simp * 1. Redistributions of source code must retain the above copyright 8155324Simp * notice, this list of conditions and the following disclaimer. 9155324Simp * 2. Redistributions in binary form must reproduce the above copyright 10155324Simp * notice, this list of conditions and the following disclaimer in the 11155324Simp * documentation and/or other materials provided with the distribution. 12155324Simp * 13185265Simp * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14185265Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15185265Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16185265Simp * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 17185265Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18185265Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19185265Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20185265Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21185265Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22185265Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23185265Simp * SUCH DAMAGE. 24155324Simp */ 25155324Simp 26155324Simp#include "opt_uart.h" 27155324Simp 28155324Simp#include <sys/cdefs.h> 29155324Simp__FBSDID("$FreeBSD: head/sys/arm/at91/uart_bus_at91usart.c 187602 2009-01-22 21:56:41Z imp $"); 30155324Simp 31155324Simp#include <sys/param.h> 32155324Simp#include <sys/systm.h> 33155324Simp#include <sys/bus.h> 34155324Simp#include <sys/conf.h> 35155324Simp#include <sys/kernel.h> 36155324Simp#include <sys/module.h> 37155324Simp#include <machine/bus.h> 38155324Simp#include <sys/rman.h> 39155324Simp#include <machine/resource.h> 40155324Simp 41155324Simp#include <dev/uart/uart.h> 42155324Simp#include <dev/uart/uart_bus.h> 43155324Simp#include <dev/uart/uart_cpu.h> 44155324Simp 45155324Simp#include <arm/at91/at91rm92reg.h> 46187602Simp#include <arm/at91/at91var.h> 47155324Simp 48155324Simp#include "uart_if.h" 49155324Simp 50155324Simpstatic int usart_at91rm92_probe(device_t dev); 51155324Simp 52155324Simpextern struct uart_class at91_usart_class; 53155324Simp 54155324Simpstatic device_method_t usart_at91rm92_methods[] = { 55155324Simp /* Device interface */ 56155324Simp DEVMETHOD(device_probe, usart_at91rm92_probe), 57155324Simp DEVMETHOD(device_attach, uart_bus_attach), 58155324Simp DEVMETHOD(device_detach, uart_bus_detach), 59155324Simp { 0, 0 } 60155324Simp}; 61155324Simp 62155324Simpstatic driver_t usart_at91rm92_driver = { 63155324Simp uart_driver_name, 64155324Simp usart_at91rm92_methods, 65155324Simp sizeof(struct uart_softc), 66155324Simp}; 67155324Simp 68155324Simpextern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs; 69155324Simp 70155324Simpstatic int 71155324Simpusart_at91rm92_probe(device_t dev) 72155324Simp{ 73155324Simp struct uart_softc *sc; 74155324Simp 75155324Simp sc = device_get_softc(dev); 76155324Simp switch (device_get_unit(dev)) 77155324Simp { 78155324Simp case 0: 79158531Scognet#ifdef SKYEYE_WORKAROUNDS 80158531Scognet device_set_desc(dev, "USART0"); 81158531Scognet#else 82155324Simp device_set_desc(dev, "DBGU"); 83158531Scognet#endif 84155324Simp /* 85155324Simp * Setting sc_sysdev makes this device a 'system device' and 86155324Simp * indirectly makes it the system console. 87155324Simp */ 88155324Simp sc->sc_sysdev = SLIST_FIRST(&uart_sysdevs); 89155324Simp bcopy(&sc->sc_sysdev->bas, &sc->sc_bas, sizeof(sc->sc_bas)); 90155324Simp break; 91155324Simp case 1: 92155324Simp device_set_desc(dev, "USART0"); 93155324Simp break; 94155324Simp case 2: 95155324Simp device_set_desc(dev, "USART1"); 96155324Simp break; 97155324Simp case 3: 98155324Simp device_set_desc(dev, "USART2"); 99155324Simp break; 100155324Simp case 4: 101155324Simp device_set_desc(dev, "USART3"); 102155324Simp break; 103155324Simp } 104155324Simp sc->sc_class = &at91_usart_class; 105187602Simp if (sc->sc_class->uc_rclk == 0) 106187602Simp sc->sc_class->uc_rclk = at91_master_clock; 107158531Scognet return (uart_bus_probe(dev, 0, 0, 0, device_get_unit(dev))); 108155324Simp} 109155324Simp 110155324Simp 111155324SimpDRIVER_MODULE(uart, atmelarm, usart_at91rm92_driver, uart_devclass, 0, 0); 112