2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
36 #include <machine/bus.h>
37 #include <machine/resource.h>
41 #include <dev/kbd/kbdreg.h>
42 #include <dev/kbd/atkbdreg.h>
43 #include <dev/kbd/atkbdcreg.h>
45 #include <isa/isareg.h>
46 #include <isa/isavar.h>
49 struct resource *intr;
53 devclass_t atkbd_devclass;
55 static void atkbdidentify(driver_t *driver, device_t dev);
56 static int atkbdprobe(device_t dev);
57 static int atkbdattach(device_t dev);
58 static int atkbdresume(device_t dev);
59 static void atkbd_isa_intr(void *arg);
61 static device_method_t atkbd_methods[] = {
62 DEVMETHOD(device_identify, atkbdidentify),
63 DEVMETHOD(device_probe, atkbdprobe),
64 DEVMETHOD(device_attach, atkbdattach),
65 DEVMETHOD(device_resume, atkbdresume),
69 static driver_t atkbd_driver = {
72 sizeof(atkbd_softc_t),
76 atkbdidentify(driver_t *driver, device_t parent)
79 /* always add at least one child */
80 BUS_ADD_CHILD(parent, KBDC_RID_KBD, driver->name, device_get_unit(parent));
84 atkbdprobe(device_t dev)
91 device_set_desc(dev, "AT Keyboard");
93 /* obtain parameters */
94 flags = device_get_flags(dev);
96 /* see if IRQ is available */
98 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
99 RF_SHAREABLE | RF_ACTIVE);
102 device_printf(dev, "unable to allocate IRQ\n");
105 irq = rman_get_start(res);
106 bus_release_resource(dev, SYS_RES_IRQ, rid, res);
108 /* probe the device */
109 return atkbd_probe_unit(device_get_unit(dev),
110 device_get_unit(device_get_parent(dev)),
115 atkbdattach(device_t dev)
124 sc = device_get_softc(dev);
127 irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid);
128 flags = device_get_flags(dev);
129 error = atkbd_attach_unit(device_get_unit(dev), &kbd,
130 device_get_unit(device_get_parent(dev)),
135 /* declare our interrupt handler */
136 sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
137 RF_SHAREABLE | RF_ACTIVE);
138 if (sc->intr == NULL)
140 error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, atkbd_isa_intr,
143 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
149 atkbdresume(device_t dev)
155 sc = device_get_softc(dev);
156 kbd = kbd_get_keyboard(kbd_find_keyboard(ATKBD_DRIVER_NAME,
157 device_get_unit(dev)));
159 kbd->kb_flags &= ~KB_INITIALIZED;
160 args[0] = device_get_unit(device_get_parent(dev));
161 args[1] = rman_get_start(sc->intr);
162 (*kbdsw[kbd->kb_index]->init)(device_get_unit(dev), &kbd,
163 args, device_get_flags(dev));
164 (*kbdsw[kbd->kb_index]->clear_state)(kbd);
170 atkbd_isa_intr(void *arg)
174 kbd = (keyboard_t *)arg;
175 (*kbdsw[kbd->kb_index]->intr)(kbd, NULL);
178 DRIVER_MODULE(atkbd, atkbdc, atkbd_driver, atkbd_devclass, 0, 0);