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>
41 #include <dev/misc/kbd/kbdreg.h>
42 #include <dev/misc/kbd/atkbdreg.h>
43 #include <dev/misc/kbd/atkbdcreg.h>
45 #include <bus/isa/isareg.h>
46 #include <bus/isa/isavar.h>
49 #define lwkt_gettoken(x)
50 #define lwkt_reltoken(x)
54 struct resource *intr;
58 devclass_t atkbd_devclass;
60 static int atkbdprobe(device_t dev);
61 static int atkbdattach(device_t dev);
62 static int atkbdresume(device_t dev);
63 static void atkbd_isa_intr(void *arg);
65 static device_method_t atkbd_methods[] = {
66 DEVMETHOD(device_probe, atkbdprobe),
67 DEVMETHOD(device_attach, atkbdattach),
68 DEVMETHOD(device_resume, atkbdresume),
72 static driver_t atkbd_driver = {
75 sizeof(atkbd_softc_t),
79 atkbdprobe(device_t dev)
84 device_set_desc(dev, "AT Keyboard");
86 /* obtain parameters */
87 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq);
88 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags);
90 /* probe the device */
91 return atkbd_probe_unit(device_get_unit(dev),
92 device_get_unit(device_get_parent(dev)),
97 atkbdattach(device_t dev)
106 sc = device_get_softc(dev);
108 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq);
109 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags);
111 error = atkbd_attach_unit(device_get_unit(dev), &kbd,
112 device_get_unit(device_get_parent(dev)),
117 /* declare our interrupt handler */
119 sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, irq, irq, 1,
120 RF_SHAREABLE | RF_ACTIVE);
121 BUS_SETUP_INTR(device_get_parent(dev), dev, sc->intr, INTR_MPSAFE,
122 atkbd_isa_intr, kbd, &sc->ih, 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);