2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer as
11 * the first lines of this file unmodified.
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * from: FreeBSD: src/sys/isa/atkbdc_isa.c,v 1.31 2005/05/29 04:42:28 nyan
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
41 #include <sys/malloc.h>
43 #include <dev/ofw/ofw_bus.h>
45 #include <machine/resource.h>
46 #include <machine/ver.h>
50 #include <dev/kbd/kbdreg.h>
51 #include <dev/atkbdc/atkbdreg.h>
52 #include <dev/atkbdc/atkbdc_subr.h>
53 #include <dev/atkbdc/atkbdcreg.h>
54 #include <dev/atkbdc/psm.h>
56 static device_probe_t atkbdc_ebus_probe;
57 static device_attach_t atkbdc_ebus_attach;
59 static device_method_t atkbdc_ebus_methods[] = {
60 DEVMETHOD(device_probe, atkbdc_ebus_probe),
61 DEVMETHOD(device_attach, atkbdc_ebus_attach),
62 DEVMETHOD(device_suspend, bus_generic_suspend),
63 DEVMETHOD(device_resume, bus_generic_resume),
65 DEVMETHOD(bus_print_child, atkbdc_print_child),
66 DEVMETHOD(bus_read_ivar, atkbdc_read_ivar),
67 DEVMETHOD(bus_write_ivar, atkbdc_write_ivar),
68 DEVMETHOD(bus_get_resource_list,atkbdc_get_resource_list),
69 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource),
70 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
71 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
72 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
73 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
74 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
75 DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource),
76 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
77 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
82 static driver_t atkbdc_ebus_driver = {
85 sizeof(atkbdc_softc_t *),
88 DRIVER_MODULE(atkbdc, ebus, atkbdc_ebus_driver, atkbdc_devclass, 0, 0);
91 atkbdc_ebus_probe(device_t dev)
93 struct resource *port0, *port1;
94 rman_res_t count, start;
97 if (strcmp(ofw_bus_get_name(dev), "8042") != 0)
101 * On AXi and AXmp boards the NS16550 (used to connect keyboard/
102 * mouse) share their IRQ lines with the i8042. Any IRQ activity
103 * (typically during attach) of the NS16550 used to connect the
104 * keyboard when actually the PS/2 keyboard is selected in OFW
105 * causes interaction with the OBP i8042 driver resulting in a
106 * hang and vice versa. As RS232 keyboards and mice obviously
107 * aren't meant to be used in parallel with PS/2 ones on these
108 * boards don't attach to the i8042 in case the PS/2 keyboard
109 * isn't selected in order to prevent such hangs.
110 * Note that it's not sufficient here to rely on the '8042' node
111 * only showing up when a PS/2 keyboard is actually connected as
112 * the user still might have adjusted the 'keyboard' alias to
113 * point to the RS232 keyboard.
115 if ((!strcmp(sparc64_model, "SUNW,UltraAX-MP") ||
116 !strcmp(sparc64_model, "SUNW,UltraSPARC-IIi-Engine")) &&
117 OF_finddevice("keyboard") != ofw_bus_get_node(dev)) {
122 device_set_desc(dev, "Keyboard controller (i8042)");
125 * The '8042' node has two identical 8 addresses wide resources
126 * which are apparently meant to be used one for the keyboard
127 * half and the other one for the mouse half. To simplify matters
128 * we use one for the command/data port resource and the other
129 * one for the status port resource as the atkbdc(4) back-end
130 * expects two struct resource rather than two bus space handles.
133 if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count) != 0) {
135 "cannot determine command/data port resource\n");
138 port0 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, start, 1,
142 "cannot allocate command/data port resource\n");
147 if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count) != 0) {
148 device_printf(dev, "cannot determine status port resource\n");
152 start += KBD_STATUS_PORT;
153 port1 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, start, 1,
156 device_printf(dev, "cannot allocate status port resource\n");
161 error = atkbdc_probe_unit(device_get_unit(dev), port0, port1);
163 device_printf(dev, "atkbdc_porbe_unit failed\n");
165 bus_release_resource(dev, SYS_RES_MEMORY, 1, port1);
167 bus_release_resource(dev, SYS_RES_MEMORY, 0, port0);
173 atkbdc_ebus_attach(device_t dev)
176 atkbdc_device_t *adi;
179 rman_res_t count, intr, start;
180 int children, error, rid, unit;
183 unit = device_get_unit(dev);
184 sc = *(atkbdc_softc_t **)device_get_softc(dev);
187 * We have to maintain two copies of the kbdc_softc struct,
188 * as the low-level console needs to have access to the
189 * keyboard controller before kbdc is probed and attached.
190 * kbdc_soft[] contains the default entry for that purpose.
193 sc = atkbdc_get_softc(unit);
196 device_set_softc(dev, sc);
200 if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count) != 0) {
202 "cannot determine command/data port resource\n");
206 sc->port0 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, start,
208 if (sc->port0 == NULL) {
210 "cannot allocate command/data port resource\n");
215 if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count) != 0) {
216 device_printf(dev, "cannot determine status port resource\n");
220 start += KBD_STATUS_PORT;
221 sc->port1 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, start,
223 if (sc->port1 == NULL) {
224 device_printf(dev, "cannot allocate status port resource\n");
229 error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1);
231 device_printf(dev, "atkbdc_attach_unit failed\n");
235 /* Attach children. */
237 for (child = OF_child(ofw_bus_get_node(dev)); child != 0;
238 child = OF_peer(child)) {
239 if ((OF_getprop_alloc(child, "name", 1, (void **)&cname)) == -1)
243 "<%s>: only two children per 8042 supported\n",
245 free(cname, M_OFWPROP);
248 adi = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV,
251 device_printf(dev, "<%s>: malloc failed\n", cname);
252 free(cname, M_OFWPROP);
255 if (strcmp(cname, "kb_ps2") == 0) {
256 adi->rid = KBDC_RID_KBD;
257 dname = ATKBD_DRIVER_NAME;
258 } else if (strcmp(cname, "kdmouse") == 0) {
259 adi->rid = KBDC_RID_AUX;
260 dname = PSM_DRIVER_NAME;
262 device_printf(dev, "<%s>: unknown device\n", cname);
263 free(adi, M_ATKBDDEV);
264 free(cname, M_OFWPROP);
267 intr = bus_get_resource_start(dev, SYS_RES_IRQ, adi->rid);
270 "<%s>: cannot determine interrupt resource\n",
272 free(adi, M_ATKBDDEV);
273 free(cname, M_OFWPROP);
276 resource_list_init(&adi->resources);
277 resource_list_add(&adi->resources, SYS_RES_IRQ, adi->rid,
279 if ((cdev = device_add_child(dev, dname, -1)) == NULL) {
280 device_printf(dev, "<%s>: device_add_child failed\n",
282 resource_list_free(&adi->resources);
283 free(adi, M_ATKBDDEV);
284 free(cname, M_OFWPROP);
287 device_set_ivars(cdev, adi);
291 error = bus_generic_attach(dev);
293 device_printf(dev, "bus_generic_attach failed\n");
300 bus_release_resource(dev, SYS_RES_MEMORY, 1, sc->port1);
302 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->port0);