uart_bus_at91usart.c revision 279724
1192886Sedwin/*-
2192886Sedwin * Copyright (c) 2005 Olivier Houchard.  All rights reserved.
364499Swollman *
4273719Sedwin * Redistribution and use in source and binary forms, with or without
52742Swollman * modification, are permitted provided that the following conditions
6273719Sedwin * are met:
7273719Sedwin * 1. Redistributions of source code must retain the above copyright
82742Swollman *    notice, this list of conditions and the following disclaimer.
9158421Swollman * 2. Redistributions in binary form must reproduce the above copyright
102742Swollman *    notice, this list of conditions and the following disclaimer in the
11158421Swollman *    documentation and/or other materials provided with the distribution.
12158421Swollman *
132742Swollman * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14248307Sedwin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15273719Sedwin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16273719Sedwin * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17248307Sedwin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1886222Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1920094Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2020094Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2120094Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2220094Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2320094Swollman * SUCH DAMAGE.
24158421Swollman */
25158421Swollman
2620094Swollman#include "opt_uart.h"
2719878Swollman
2819878Swollman#include <sys/cdefs.h>
2919878Swollman__FBSDID("$FreeBSD: head/sys/arm/at91/uart_bus_at91usart.c 279724 2015-03-07 15:24:15Z ian $");
3019878Swollman
3119878Swollman#include <sys/param.h>
3219878Swollman#include <sys/systm.h>
33270817Spluknet#include <sys/bus.h>
3419878Swollman#include <sys/conf.h>
3558787Sru#include <sys/kernel.h>
3658787Sru#include <sys/module.h>
3758787Sru#include <machine/bus.h>
38270817Spluknet#include <sys/rman.h>
3958787Sru#include <machine/resource.h>
4058787Sru
41270817Spluknet#include <dev/uart/uart.h>
42270817Spluknet#include <dev/uart/uart_bus.h>
43270817Spluknet#include <dev/uart/uart_cpu.h>
4458787Sru
4558787Sru#include <arm/at91/at91var.h>
4658787Sru
4758787Sru#include "uart_if.h"
4858787Sru
4958787Sruextern struct uart_class at91_usart_class;
50270817Spluknetstatic int usart_at91_probe(device_t dev);
5158787Sru
5258787Srustatic device_method_t usart_at91_methods[] = {
532742Swollman	/* Device interface */
542742Swollman	DEVMETHOD(device_probe,		usart_at91_probe),
552742Swollman	DEVMETHOD(device_attach,	uart_bus_attach),
562742Swollman	DEVMETHOD(device_detach,	uart_bus_detach),
572742Swollman	{ 0, 0 }
582742Swollman};
592742Swollman
6019878Swollmanstatic driver_t usart_at91_driver = {
612742Swollman	uart_driver_name,
622742Swollman	usart_at91_methods,
632742Swollman	sizeof(struct uart_softc),
64270817Spluknet};
652742Swollman
662742Swollmanextern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs;
67149514Swollman
6821217Swollmanstatic int
699908Swollmanusart_at91_probe(device_t dev)
709908Swollman{
712742Swollman	struct uart_softc *sc;
7219878Swollman
7319878Swollman	sc = device_get_softc(dev);
7419878Swollman	switch (device_get_unit(dev))
7519878Swollman	{
7619878Swollman	case 0:
7719878Swollman		device_set_desc(dev, "DBGU");
7819878Swollman		/*
7919878Swollman		 * Setting sc_sysdev makes this device a 'system device' and
8019878Swollman		 * indirectly makes it the system console.
8119878Swollman		 */
8219878Swollman		sc->sc_sysdev = SLIST_FIRST(&uart_sysdevs);
8319878Swollman		bcopy(&sc->sc_sysdev->bas, &sc->sc_bas, sizeof(sc->sc_bas));
8419878Swollman		break;
8519878Swollman	case 1:
8619878Swollman		device_set_desc(dev, "USART0");
8719878Swollman		break;
8893799Swollman	case 2:
8958787Sru		device_set_desc(dev, "USART1");
9058787Sru		break;
9119878Swollman	case 3:
9219878Swollman		device_set_desc(dev, "USART2");
9319878Swollman		break;
949908Swollman	case 4:
95149514Swollman		device_set_desc(dev, "USART3");
969908Swollman		break;
979908Swollman	case 5:
98270817Spluknet		device_set_desc(dev, "USART4");
9921217Swollman		break;
10019878Swollman	case 6:
10119878Swollman		device_set_desc(dev, "USART5");
1029908Swollman		break;
103149514Swollman	}
1049908Swollman	sc->sc_class = &at91_usart_class;
1059908Swollman	if (sc->sc_class->uc_rclk == 0)
1069908Swollman		sc->sc_class->uc_rclk = at91_master_clock;
1079908Swollman	return (uart_bus_probe(dev, 0, 0, 0, device_get_unit(dev)));
10858787Sru}
10958787Sru
11058787Sru
11164499SwollmanDRIVER_MODULE(uart, atmelarm, usart_at91_driver, uart_devclass, 0, 0);
11264499Swollman