uart_bus_ebus.c revision 120452
1119815Smarcel/*-
2119815Smarcel * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
3119815Smarcel * All rights reserved.
4119815Smarcel *
5119815Smarcel * Redistribution and use in source and binary forms, with or without
6119815Smarcel * modification, are permitted provided that the following conditions
7119815Smarcel * are met:
8119815Smarcel * 1. Redistributions of source code must retain the above copyright
9119815Smarcel *    notice, this list of conditions and the following disclaimer.
10119815Smarcel * 2. Redistributions in binary form must reproduce the above copyright
11119815Smarcel *    notice, this list of conditions and the following disclaimer in the
12119815Smarcel *    documentation and/or other materials provided with the distribution.
13119815Smarcel *
14119815Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15119815Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16119815Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17119815Smarcel * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18119815Smarcel * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19119815Smarcel * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20119815Smarcel * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21119815Smarcel * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22119815Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23119815Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24119815Smarcel * SUCH DAMAGE.
25119815Smarcel */
26119815Smarcel
27119815Smarcel#include <sys/cdefs.h>
28119815Smarcel__FBSDID("$FreeBSD: head/sys/dev/uart/uart_bus_ebus.c 120452 2003-09-26 05:14:56Z marcel $");
29119815Smarcel
30119815Smarcel#include <sys/param.h>
31119815Smarcel#include <sys/systm.h>
32119815Smarcel#include <sys/bus.h>
33119815Smarcel#include <sys/kernel.h>
34119815Smarcel#include <machine/bus.h>
35119815Smarcel#include <sys/rman.h>
36119815Smarcel#include <machine/resource.h>
37119815Smarcel
38119815Smarcel#include <dev/ofw/openfirm.h>
39119815Smarcel#include <sparc64/ebus/ebusvar.h>
40119815Smarcel
41119815Smarcel#include <dev/uart/uart.h>
42119815Smarcel#include <dev/uart/uart_bus.h>
43119815Smarcel#include <dev/uart/uart_cpu.h>
44119815Smarcel
45119815Smarcelstatic int uart_ebus_probe(device_t dev);
46119815Smarcel
47119815Smarcelstatic device_method_t uart_ebus_methods[] = {
48119815Smarcel	/* Device interface */
49119815Smarcel	DEVMETHOD(device_probe,		uart_ebus_probe),
50119815Smarcel	DEVMETHOD(device_attach,	uart_bus_attach),
51119815Smarcel	DEVMETHOD(device_detach,	uart_bus_detach),
52119815Smarcel	{ 0, 0 }
53119815Smarcel};
54119815Smarcel
55119815Smarcelstatic driver_t uart_ebus_driver = {
56119815Smarcel	uart_driver_name,
57119815Smarcel	uart_ebus_methods,
58119815Smarcel	sizeof(struct uart_softc),
59119815Smarcel};
60119815Smarcel
61119815Smarcelstatic int
62119815Smarceluart_ebus_probe(device_t dev)
63119815Smarcel{
64119815Smarcel	const char *nm;
65119815Smarcel	struct uart_softc *sc;
66119815Smarcel	int error;
67119815Smarcel
68119815Smarcel	sc = device_get_softc(dev);
69119815Smarcel	sc->sc_class = NULL;
70119815Smarcel
71119815Smarcel	nm = ebus_get_name(dev);
72119815Smarcel	if (!strcmp(nm, "su")) {
73119815Smarcel		sc->sc_class = &uart_ns8250_class;
74120452Smarcel		return (uart_bus_probe(dev, 0, 0, 0, 0));
75119815Smarcel	}
76119815Smarcel	if (!strcmp(nm, "se")) {
77119815Smarcel		sc->sc_class = &uart_sab82532_class;
78120452Smarcel		error = uart_bus_probe(dev, 0, 0, 0, 1);
79119815Smarcel		return ((error) ? error : -1);
80119815Smarcel	}
81119815Smarcel
82119815Smarcel	return (ENXIO);
83119815Smarcel}
84119815Smarcel
85119815SmarcelDRIVER_MODULE(uart, ebus, uart_ebus_driver, uart_devclass, 0, 0);
86