uart_bus_at91usart.c revision 238325
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 238325 2012-07-10 01:13:00Z 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
45187602Simp#include <arm/at91/at91var.h>
46155324Simp
47155324Simp#include "uart_if.h"
48155324Simp
49238325Simpstatic int usart_at91_probe(device_t dev);
50155324Simp
51155324Simpextern struct uart_class at91_usart_class;
52155324Simp
53238325Simpstatic device_method_t usart_at91_methods[] = {
54155324Simp	/* Device interface */
55238325Simp	DEVMETHOD(device_probe,		usart_at91_probe),
56155324Simp	DEVMETHOD(device_attach,	uart_bus_attach),
57155324Simp	DEVMETHOD(device_detach,	uart_bus_detach),
58155324Simp	{ 0, 0 }
59155324Simp};
60155324Simp
61238325Simpstatic driver_t usart_at91_driver = {
62155324Simp	uart_driver_name,
63238325Simp	usart_at91_methods,
64155324Simp	sizeof(struct uart_softc),
65155324Simp};
66155324Simp
67155324Simpextern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs;
68155324Simp
69155324Simpstatic int
70238325Simpusart_at91_probe(device_t dev)
71155324Simp{
72155324Simp	struct uart_softc *sc;
73155324Simp
74155324Simp	sc = device_get_softc(dev);
75155324Simp	switch (device_get_unit(dev))
76155324Simp	{
77155324Simp	case 0:
78155324Simp		device_set_desc(dev, "DBGU");
79155324Simp		/*
80155324Simp		 * Setting sc_sysdev makes this device a 'system device' and
81155324Simp		 * indirectly makes it the system console.
82155324Simp		 */
83155324Simp		sc->sc_sysdev = SLIST_FIRST(&uart_sysdevs);
84155324Simp		bcopy(&sc->sc_sysdev->bas, &sc->sc_bas, sizeof(sc->sc_bas));
85155324Simp		break;
86155324Simp	case 1:
87155324Simp		device_set_desc(dev, "USART0");
88155324Simp		break;
89155324Simp	case 2:
90155324Simp		device_set_desc(dev, "USART1");
91155324Simp		break;
92155324Simp	case 3:
93155324Simp		device_set_desc(dev, "USART2");
94155324Simp		break;
95155324Simp	case 4:
96155324Simp		device_set_desc(dev, "USART3");
97155324Simp		break;
98155324Simp	}
99155324Simp	sc->sc_class = &at91_usart_class;
100187602Simp	if (sc->sc_class->uc_rclk == 0)
101187602Simp		sc->sc_class->uc_rclk = at91_master_clock;
102158531Scognet	return (uart_bus_probe(dev, 0, 0, 0, device_get_unit(dev)));
103155324Simp}
104155324Simp
105155324Simp
106238325SimpDRIVER_MODULE(uart, atmelarm, usart_at91_driver, uart_devclass, 0, 0);
107