uart_bus_at91usart.c revision 340145
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: stable/11/sys/arm/at91/uart_bus_at91usart.c 340145 2018-11-04 23:28:56Z mmacy $"); 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 45187602Simp#include <arm/at91/at91var.h> 46155324Simp 47155324Simp#include "uart_if.h" 48155324Simp 49279724Sianextern struct uart_class at91_usart_class; 50238325Simpstatic int usart_at91_probe(device_t dev); 51155324Simp 52238325Simpstatic device_method_t usart_at91_methods[] = { 53155324Simp /* Device interface */ 54238325Simp DEVMETHOD(device_probe, usart_at91_probe), 55155324Simp DEVMETHOD(device_attach, uart_bus_attach), 56155324Simp DEVMETHOD(device_detach, uart_bus_detach), 57155324Simp { 0, 0 } 58155324Simp}; 59155324Simp 60238325Simpstatic driver_t usart_at91_driver = { 61155324Simp uart_driver_name, 62238325Simp usart_at91_methods, 63155324Simp sizeof(struct uart_softc), 64155324Simp}; 65155324Simp 66155324Simpextern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs; 67155324Simp 68155324Simpstatic int 69238325Simpusart_at91_probe(device_t dev) 70155324Simp{ 71155324Simp struct uart_softc *sc; 72155324Simp 73155324Simp sc = device_get_softc(dev); 74155324Simp switch (device_get_unit(dev)) 75155324Simp { 76155324Simp case 0: 77155324Simp device_set_desc(dev, "DBGU"); 78155324Simp /* 79155324Simp * Setting sc_sysdev makes this device a 'system device' and 80155324Simp * indirectly makes it the system console. 81155324Simp */ 82155324Simp sc->sc_sysdev = SLIST_FIRST(&uart_sysdevs); 83155324Simp bcopy(&sc->sc_sysdev->bas, &sc->sc_bas, sizeof(sc->sc_bas)); 84155324Simp break; 85155324Simp case 1: 86155324Simp device_set_desc(dev, "USART0"); 87155324Simp break; 88155324Simp case 2: 89155324Simp device_set_desc(dev, "USART1"); 90155324Simp break; 91155324Simp case 3: 92155324Simp device_set_desc(dev, "USART2"); 93155324Simp break; 94155324Simp case 4: 95155324Simp device_set_desc(dev, "USART3"); 96155324Simp break; 97238787Simp case 5: 98238787Simp device_set_desc(dev, "USART4"); 99238787Simp break; 100238787Simp case 6: 101238787Simp device_set_desc(dev, "USART5"); 102238787Simp 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; 107340145Smmacy return (uart_bus_probe(dev, 0, 0, 0, 0, device_get_unit(dev), 0)); 108155324Simp} 109155324Simp 110155324Simp 111238325SimpDRIVER_MODULE(uart, atmelarm, usart_at91_driver, uart_devclass, 0, 0); 112