uart_bus_ebus.c revision 119815
1184610Salfred/*-
2184610Salfred * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
3184610Salfred * All rights reserved.
4184610Salfred *
5184610Salfred * Redistribution and use in source and binary forms, with or without
6184610Salfred * modification, are permitted provided that the following conditions
7184610Salfred * are met:
8184610Salfred * 1. Redistributions of source code must retain the above copyright
9184610Salfred *    notice, this list of conditions and the following disclaimer.
10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright
11184610Salfred *    notice, this list of conditions and the following disclaimer in the
12184610Salfred *    documentation and/or other materials provided with the distribution.
13184610Salfred *
14184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15184610Salfred * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16184610Salfred * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17184610Salfred * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18184610Salfred * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19184610Salfred * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20184610Salfred * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21184610Salfred * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24184610Salfred * SUCH DAMAGE.
25184610Salfred */
26184610Salfred
27184610Salfred#include <sys/cdefs.h>
28184610Salfred__FBSDID("$FreeBSD: head/sys/dev/uart/uart_bus_ebus.c 119815 2003-09-06 23:13:47Z marcel $");
29184610Salfred
30184610Salfred#include <sys/param.h>
31184610Salfred#include <sys/systm.h>
32184610Salfred#include <sys/bus.h>
33184610Salfred#include <sys/kernel.h>
34184610Salfred#include <machine/bus.h>
35184610Salfred#include <sys/rman.h>
36184610Salfred#include <machine/resource.h>
37184610Salfred
38184610Salfred#include <dev/ofw/openfirm.h>
39184610Salfred#include <sparc64/ebus/ebusvar.h>
40184610Salfred
41184610Salfred#include <dev/uart/uart.h>
42184610Salfred#include <dev/uart/uart_bus.h>
43184610Salfred#include <dev/uart/uart_cpu.h>
44184610Salfred
45184610Salfredstatic int uart_ebus_probe(device_t dev);
46184610Salfred
47184610Salfredstatic device_method_t uart_ebus_methods[] = {
48184610Salfred	/* Device interface */
49184610Salfred	DEVMETHOD(device_probe,		uart_ebus_probe),
50194677Sthompsa	DEVMETHOD(device_attach,	uart_bus_attach),
51194677Sthompsa	DEVMETHOD(device_detach,	uart_bus_detach),
52194677Sthompsa	{ 0, 0 }
53194677Sthompsa};
54194677Sthompsa
55194677Sthompsastatic driver_t uart_ebus_driver = {
56194677Sthompsa	uart_driver_name,
57194677Sthompsa	uart_ebus_methods,
58194677Sthompsa	sizeof(struct uart_softc),
59194677Sthompsa};
60194677Sthompsa
61194677Sthompsastatic int
62194677Sthompsauart_ebus_probe(device_t dev)
63194677Sthompsa{
64194677Sthompsa	const char *nm;
65194677Sthompsa	struct uart_softc *sc;
66194677Sthompsa	int error;
67194677Sthompsa
68194677Sthompsa	sc = device_get_softc(dev);
69194677Sthompsa	sc->sc_class = NULL;
70194677Sthompsa
71194677Sthompsa	nm = ebus_get_name(dev);
72188746Sthompsa	if (!strcmp(nm, "su")) {
73184610Salfred		sc->sc_class = &uart_ns8250_class;
74184610Salfred		return (uart_bus_probe(dev, 0, 0, 0));
75188942Sthompsa	}
76188942Sthompsa	if (!strcmp(nm, "se")) {
77184610Salfred		sc->sc_class = &uart_sab82532_class;
78188942Sthompsa		error = uart_bus_probe(dev, 0, 0, 0);
79184610Salfred		return ((error) ? error : -1);
80207077Sthompsa	}
81184610Salfred
82184610Salfred	return (ENXIO);
83227309Sed}
84276701Shselasky
85184610SalfredDRIVER_MODULE(uart, ebus, uart_ebus_driver, uart_devclass, 0, 0);
86184610Salfred