1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2001 by Thomas Moestl <[email protected]>.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/bus.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37
38 #include <dev/ofw/ofw_bus.h>
39
40 #include <machine/bus.h>
41 #include <sys/rman.h>
42 #include <machine/resource.h>
43 #include <machine/ver.h>
44
45 #include <dev/uart/uart.h>
46 #include <dev/uart/uart_bus.h>
47 #include <dev/uart/uart_cpu.h>
48
49 static int uart_ebus_probe(device_t dev);
50
51 static device_method_t uart_ebus_methods[] = {
52 /* Device interface */
53 DEVMETHOD(device_probe, uart_ebus_probe),
54 DEVMETHOD(device_attach, uart_bus_attach),
55 DEVMETHOD(device_detach, uart_bus_detach),
56 { 0, 0 }
57 };
58
59 static driver_t uart_ebus_driver = {
60 uart_driver_name,
61 uart_ebus_methods,
62 sizeof(struct uart_softc),
63 };
64
65 static int
uart_ebus_probe(device_t dev)66 uart_ebus_probe(device_t dev)
67 {
68 const char *nm, *cmpt;
69 struct uart_softc *sc;
70 struct uart_devinfo dummy;
71
72 sc = device_get_softc(dev);
73 sc->sc_class = NULL;
74
75 nm = ofw_bus_get_name(dev);
76 cmpt = ofw_bus_get_compat(dev);
77 if (cmpt == NULL)
78 cmpt = "";
79 if (!strcmp(nm, "lom-console") || !strcmp(nm, "su") ||
80 !strcmp(nm, "su_pnp") || !strcmp(cmpt, "rsc-console") ||
81 !strcmp(cmpt, "rsc-control") || !strcmp(cmpt, "su") ||
82 !strcmp(cmpt, "su16550") || !strcmp(cmpt, "su16552")) {
83 /*
84 * On AXi and AXmp boards the NS16550 (used to connect
85 * keyboard/mouse) share their IRQ lines with the i8042.
86 * Any IRQ activity (typically during attach) of the
87 * NS16550 used to connect the keyboard when actually the
88 * PS/2 keyboard is selected in OFW causes interaction
89 * with the OBP i8042 driver resulting in a hang and vice
90 * versa. As RS232 keyboards and mice obviously aren't
91 * meant to be used in parallel with PS/2 ones on these
92 * boards don't attach to the NS16550 in case the RS232
93 * keyboard isn't selected in order to prevent such hangs.
94 */
95 if ((!strcmp(sparc64_model, "SUNW,UltraAX-MP") ||
96 !strcmp(sparc64_model, "SUNW,UltraSPARC-IIi-Engine")) &&
97 uart_cpu_getdev(UART_DEV_KEYBOARD, &dummy)) {
98 device_disable(dev);
99 return (ENXIO);
100 }
101 sc->sc_class = &uart_ns8250_class;
102 return (uart_bus_probe(dev, 0, 0, 0, 0, 0, 0));
103 }
104
105 return (ENXIO);
106 }
107
108 DRIVER_MODULE(uart, ebus, uart_ebus_driver, uart_devclass, 0, 0);
109