uart_bus_ebus.c revision 146974
1275970Scy/*-
2275970Scy * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
3275970Scy * All rights reserved.
4275970Scy *
5275970Scy * Redistribution and use in source and binary forms, with or without
6275970Scy * modification, are permitted provided that the following conditions
7275970Scy * are met:
8275970Scy * 1. Redistributions of source code must retain the above copyright
9275970Scy *    notice, this list of conditions and the following disclaimer.
10275970Scy * 2. Redistributions in binary form must reproduce the above copyright
11275970Scy *    notice, this list of conditions and the following disclaimer in the
12275970Scy *    documentation and/or other materials provided with the distribution.
13275970Scy *
14275970Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15275970Scy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16275970Scy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17275970Scy * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18275970Scy * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19275970Scy * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20275970Scy * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21275970Scy * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22275970Scy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23275970Scy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24275970Scy * SUCH DAMAGE.
25275970Scy */
26275970Scy
27275970Scy#include <sys/cdefs.h>
28275970Scy__FBSDID("$FreeBSD: head/sys/dev/uart/uart_bus_ebus.c 146974 2005-06-04 21:52:56Z marius $");
29275970Scy
30275970Scy#include <sys/param.h>
31275970Scy#include <sys/systm.h>
32275970Scy#include <sys/bus.h>
33275970Scy#include <sys/kernel.h>
34330567Sgordon#include <sys/module.h>
35275970Scy
36275970Scy#include <dev/ofw/ofw_bus.h>
37275970Scy
38275970Scy#include <machine/bus.h>
39275970Scy#include <sys/rman.h>
40275970Scy#include <machine/resource.h>
41275970Scy#include <machine/ver.h>
42275970Scy
43275970Scy#include <dev/uart/uart.h>
44275970Scy#include <dev/uart/uart_bus.h>
45275970Scy#include <dev/uart/uart_cpu.h>
46275970Scy
47275970Scystatic int uart_ebus_probe(device_t dev);
48275970Scy
49275970Scystatic device_method_t uart_ebus_methods[] = {
50275970Scy	/* Device interface */
51275970Scy	DEVMETHOD(device_probe,		uart_ebus_probe),
52275970Scy	DEVMETHOD(device_attach,	uart_bus_attach),
53275970Scy	DEVMETHOD(device_detach,	uart_bus_detach),
54275970Scy	{ 0, 0 }
55275970Scy};
56275970Scy
57275970Scystatic driver_t uart_ebus_driver = {
58275970Scy	uart_driver_name,
59275970Scy	uart_ebus_methods,
60275970Scy	sizeof(struct uart_softc),
61275970Scy};
62275970Scy
63275970Scystatic int
64275970Scyuart_ebus_probe(device_t dev)
65275970Scy{
66275970Scy	const char *nm, *cmpt;
67275970Scy	struct uart_softc *sc;
68275970Scy	struct uart_devinfo dummy;
69275970Scy	int error;
70275970Scy
71275970Scy	sc = device_get_softc(dev);
72275970Scy	sc->sc_class = NULL;
73275970Scy
74275970Scy	nm = ofw_bus_get_name(dev);
75275970Scy	cmpt = ofw_bus_get_compat(dev);
76275970Scy	if (!strcmp(nm, "su") || !strcmp(nm, "su_pnp") || (cmpt != NULL &&
77275970Scy	    (!strcmp(cmpt, "su") || !strcmp(cmpt, "su16550")))) {
78275970Scy		/*
79275970Scy		 * On AXi and AXmp boards the NS16550 (used to connect
80275970Scy		 * keyboard/mouse) share their IRQ lines with the i8042.
81275970Scy		 * Any IRQ activity (typically during attach) of the
82275970Scy		 * NS16550 used to connect the keyboard when actually the
83275970Scy		 * PS/2 keyboard is selected in OFW causes interaction
84275970Scy		 * with the OBP i8042 driver resulting in a hang and vice
85275970Scy		 * versa. As RS232 keyboards and mice obviously aren't
86275970Scy		 * meant to be used in parallel with PS/2 ones on these
87275970Scy		 * boards don't attach to the NS16550 in case the RS232
88275970Scy		 * keyboard isn't selected in order to prevent such hangs.
89275970Scy		 */
90275970Scy		if ((!strcmp(sparc64_model, "SUNW,UltraAX-MP") ||
91275970Scy		    !strcmp(sparc64_model, "SUNW,UltraSPARC-IIi-Engine")) &&
92330567Sgordon		    uart_cpu_getdev(UART_DEV_KEYBOARD, &dummy)) {
93275970Scy				device_disable(dev);
94275970Scy				return (ENXIO);
95275970Scy		}
96275970Scy		sc->sc_class = &uart_ns8250_class;
97275970Scy		return (uart_bus_probe(dev, 0, 0, 0, 0));
98275970Scy	}
99275970Scy	if (!strcmp(nm, "se")) {
100275970Scy		sc->sc_class = &uart_sab82532_class;
101275970Scy		error = uart_bus_probe(dev, 0, 0, 0, 1);
102275970Scy		return ((error) ? error : -1);
103275970Scy	}
104275970Scy
105275970Scy	return (ENXIO);
106275970Scy}
107275970Scy
108275970ScyDRIVER_MODULE(uart, ebus, uart_ebus_driver, uart_devclass, 0, 0);
109275970Scy