]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/isa/atkbd_isa.c
Merge the cons.c and cons.h to the best of my ability. alpha may or
[FreeBSD/FreeBSD.git] / sys / isa / atkbd_isa.c
1 /*-
2  * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
14  *
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.
25  *
26  * $Id: atkbd_isa.c,v 1.3 1999/04/16 21:22:34 peter Exp $
27  */
28
29 #include "atkbd.h"
30 #include "opt_kbd.h"
31
32 #if NATKBD > 0
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/conf.h>
38 #include <sys/tty.h>
39 #include <sys/bus.h>
40 #include <machine/bus.h>
41 #include <sys/rman.h>
42
43 #include <machine/resource.h>
44
45 #include <dev/kbd/kbdreg.h>
46 #include <dev/kbd/atkbdreg.h>
47 #include <dev/kbd/atkbdcreg.h>
48
49 #include <isa/isareg.h>
50 #include <isa/isavar.h>
51
52 devclass_t      atkbd_devclass;
53
54 static int      atkbdprobe(device_t dev);
55 static int      atkbdattach(device_t dev);
56 static void     atkbd_isa_intr(void *arg);
57
58 static device_method_t atkbd_methods[] = {
59         DEVMETHOD(device_probe,         atkbdprobe),
60         DEVMETHOD(device_attach,        atkbdattach),
61         { 0, 0 }
62 };
63
64 static driver_t atkbd_driver = {
65         ATKBD_DRIVER_NAME,
66         atkbd_methods,
67         sizeof(atkbd_softc_t),
68 };
69
70 static int
71 atkbdprobe(device_t dev)
72 {
73         uintptr_t port;
74         uintptr_t irq;
75         uintptr_t flags;
76
77         device_set_desc(dev, "AT Keyboard");
78
79         /* obtain parameters */
80         BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_PORT, &port);
81         BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq);
82         BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags);
83
84         /* probe the device */
85         return atkbd_probe_unit(device_get_unit(dev), port, irq, flags);
86 }
87
88 static int
89 atkbdattach(device_t dev)
90 {
91         atkbd_softc_t *sc;
92         uintptr_t port;
93         uintptr_t irq;
94         uintptr_t flags;
95         struct resource *res;
96         void *ih;
97         int zero = 0;
98         int error;
99
100         sc = (atkbd_softc_t *)device_get_softc(dev);
101
102         BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_PORT, &port);
103         BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq);
104         BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags);
105
106         error = atkbd_attach_unit(device_get_unit(dev), sc, port, irq, flags);
107         if (error)
108                 return error;
109
110         /* declare our interrupt handler */
111         res = bus_alloc_resource(dev, SYS_RES_IRQ, &zero, irq, irq, 1,
112                                  RF_SHAREABLE | RF_ACTIVE);
113         BUS_SETUP_INTR(device_get_parent(dev), dev, res, INTR_TYPE_TTY,
114                        atkbd_isa_intr, sc, &ih);
115
116         return 0;
117 }
118
119 static void
120 atkbd_isa_intr(void *arg)
121 {
122         atkbd_softc_t *sc;
123
124         sc = (atkbd_softc_t *)arg;
125         (*kbdsw[sc->kbd->kb_index]->intr)(sc->kbd, NULL);
126 }
127
128 DRIVER_MODULE(atkbd, atkbdc, atkbd_driver, atkbd_devclass, 0, 0);
129
130 #endif /* NATKBD > 0 */