2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
33 #include "opt_evdev.h"
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
41 #include <machine/bus.h>
42 #include <machine/resource.h>
46 #include <dev/kbd/kbdreg.h>
47 #include <dev/atkbdc/atkbdreg.h>
48 #include <dev/atkbdc/atkbdcreg.h>
51 struct resource *intr;
55 static devclass_t atkbd_devclass;
57 static void atkbdidentify(driver_t *driver, device_t dev);
58 static int atkbdprobe(device_t dev);
59 static int atkbdattach(device_t dev);
60 static int atkbdresume(device_t dev);
61 static void atkbdintr(void *arg);
63 static device_method_t atkbd_methods[] = {
64 DEVMETHOD(device_identify, atkbdidentify),
65 DEVMETHOD(device_probe, atkbdprobe),
66 DEVMETHOD(device_attach, atkbdattach),
67 DEVMETHOD(device_resume, atkbdresume),
71 static driver_t atkbd_driver = {
74 sizeof(atkbd_softc_t),
78 atkbdidentify(driver_t *driver, device_t parent)
81 /* always add at least one child */
82 BUS_ADD_CHILD(parent, KBDC_RID_KBD, driver->name, device_get_unit(parent));
86 atkbdprobe(device_t dev)
93 device_set_desc(dev, "AT Keyboard");
95 /* obtain parameters */
96 flags = device_get_flags(dev);
98 /* see if IRQ is available */
100 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
103 device_printf(dev, "unable to allocate IRQ\n");
106 irq = rman_get_start(res);
107 bus_release_resource(dev, SYS_RES_IRQ, rid, res);
109 /* probe the device */
110 return atkbd_probe_unit(dev, irq, flags);
114 atkbdattach(device_t dev)
123 sc = device_get_softc(dev);
126 irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid);
127 flags = device_get_flags(dev);
128 error = atkbd_attach_unit(dev, &kbd, irq, flags);
132 /* declare our interrupt handler */
133 sc->intr = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
134 if (sc->intr == NULL)
136 error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, NULL, atkbdintr,
139 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
145 atkbdresume(device_t dev)
151 sc = device_get_softc(dev);
152 kbd = kbd_get_keyboard(kbd_find_keyboard(ATKBD_DRIVER_NAME,
153 device_get_unit(dev)));
155 kbd->kb_flags &= ~KB_INITIALIZED;
156 args[0] = device_get_unit(device_get_parent(dev));
157 args[1] = rman_get_start(sc->intr);
158 kbdd_init(kbd, device_get_unit(dev), &kbd, args,
159 device_get_flags(dev));
160 kbdd_clear_state(kbd);
170 kbd = (keyboard_t *)arg;
171 kbdd_intr(kbd, NULL);
174 DRIVER_MODULE(atkbd, atkbdc, atkbd_driver, atkbd_devclass, 0, 0);
176 MODULE_DEPEND(atkbd, evdev, 1, 1, 1);