4 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer as
12 * the first lines of this file unmodified.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * $FreeBSD: src/sys/isa/atkbd_isa.c,v 1.7.2.3 2001/08/01 10:42:28 yokota Exp $
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
38 #include <sys/thread.h>
39 #include <sys/machintr.h>
42 #include <dev/misc/kbd/kbdreg.h>
43 #include <dev/misc/kbd/atkbdreg.h>
44 #include <dev/misc/kbd/atkbdcreg.h>
46 #include <bus/isa/isareg.h>
47 #include <bus/isa/isavar.h>
50 #define lwkt_gettoken(x)
51 #define lwkt_reltoken(x)
55 struct resource *intr;
59 devclass_t atkbd_devclass;
61 static int atkbdprobe(device_t dev);
62 static int atkbdattach(device_t dev);
63 static int atkbdresume(device_t dev);
64 static void atkbd_isa_intr(void *arg);
66 static device_method_t atkbd_methods[] = {
67 DEVMETHOD(device_probe, atkbdprobe),
68 DEVMETHOD(device_attach, atkbdattach),
69 DEVMETHOD(device_resume, atkbdresume),
73 static driver_t atkbd_driver = {
76 sizeof(atkbd_softc_t),
80 atkbdprobe(device_t dev)
85 device_set_desc(dev, "AT Keyboard");
87 /* obtain parameters */
88 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq);
89 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags);
91 /* probe the device */
92 return atkbd_probe_unit(device_get_unit(dev),
93 device_get_unit(device_get_parent(dev)),
98 atkbdattach(device_t dev)
107 sc = device_get_softc(dev);
109 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq);
110 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags);
112 error = atkbd_attach_unit(device_get_unit(dev), &kbd,
113 device_get_unit(device_get_parent(dev)),
118 /* declare our interrupt handler */
120 sc->intr = bus_alloc_legacy_irq_resource(dev, &rid, irq, RF_ACTIVE);
121 BUS_SETUP_INTR(device_get_parent(dev), dev, sc->intr, INTR_MPSAFE,
122 atkbd_isa_intr, kbd, &sc->ih, NULL, NULL);
128 atkbdresume(device_t dev)
134 lwkt_gettoken(&tty_token);
135 sc = device_get_softc(dev);
136 kbd = kbd_get_keyboard(kbd_find_keyboard(ATKBD_DRIVER_NAME,
137 device_get_unit(dev)));
139 kbd->kb_flags &= ~KB_INITIALIZED;
140 args[0] = device_get_unit(device_get_parent(dev));
141 args[1] = rman_get_start(sc->intr);
142 sw_init(kbdsw[kbd->kb_index], device_get_unit(dev), &kbd,
143 args, device_get_flags(dev));
144 kbd_clear_state(kbd);
147 lwkt_reltoken(&tty_token);
152 atkbd_isa_intr(void *arg)
156 lwkt_gettoken(&tty_token);
157 kbd = (keyboard_t *)arg;
159 lwkt_reltoken(&tty_token);
162 DRIVER_MODULE(atkbd, atkbdc, atkbd_driver, atkbd_devclass, NULL, NULL);