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.
| 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.
|
29#include "opt_kbd.h" 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/kernel.h> 34#include <sys/bus.h> 35 36#include <machine/bus.h> 37#include <machine/resource.h> 38#include <sys/rman.h> 39 40#include <sys/kbio.h> 41#include <dev/kbd/kbdreg.h> 42#include <dev/kbd/atkbdreg.h> 43#include <dev/kbd/atkbdcreg.h> 44 45#include <isa/isareg.h> 46#include <isa/isavar.h> 47 48typedef struct { 49 struct resource *intr; 50 void *ih; 51} atkbd_softc_t; 52 53static devclass_t atkbd_devclass; 54 55static void atkbdidentify(driver_t *driver, device_t dev); 56static int atkbdprobe(device_t dev); 57static int atkbdattach(device_t dev); 58static int atkbdresume(device_t dev); 59static void atkbd_isa_intr(void *arg); 60 61static 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), 66 { 0, 0 } 67}; 68 69static driver_t atkbd_driver = { 70 ATKBD_DRIVER_NAME, 71 atkbd_methods, 72 sizeof(atkbd_softc_t), 73}; 74 75static void 76atkbdidentify(driver_t *driver, device_t parent) 77{ 78 79 /* always add at least one child */ 80 BUS_ADD_CHILD(parent, KBDC_RID_KBD, driver->name, device_get_unit(parent)); 81} 82 83static int 84atkbdprobe(device_t dev) 85{ 86 struct resource *res; 87 u_long irq; 88 int flags; 89 int rid; 90 91 device_set_desc(dev, "AT Keyboard"); 92 93 /* obtain parameters */ 94 flags = device_get_flags(dev); 95 96 /* see if IRQ is available */ 97 rid = KBDC_RID_KBD; 98 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 99 RF_SHAREABLE | RF_ACTIVE); 100 if (res == NULL) { 101 if (bootverbose) 102 device_printf(dev, "unable to allocate IRQ\n"); 103 return ENXIO; 104 } 105 irq = rman_get_start(res); 106 bus_release_resource(dev, SYS_RES_IRQ, rid, res); 107 108 /* probe the device */ 109 return atkbd_probe_unit(device_get_unit(dev), 110 device_get_unit(device_get_parent(dev)), 111 irq, flags); 112} 113 114static int 115atkbdattach(device_t dev) 116{ 117 atkbd_softc_t *sc; 118 keyboard_t *kbd; 119 u_long irq; 120 int flags; 121 int rid; 122 int error; 123 124 sc = device_get_softc(dev); 125 126 rid = KBDC_RID_KBD; 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)), 131 irq, flags); 132 if (error) 133 return error; 134 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) 139 return ENXIO; 140 error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, atkbd_isa_intr, 141 kbd, &sc->ih); 142 if (error) 143 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr); 144 145 return error; 146} 147 148static int 149atkbdresume(device_t dev) 150{ 151 atkbd_softc_t *sc; 152 keyboard_t *kbd; 153 int args[2]; 154 155 sc = device_get_softc(dev); 156 kbd = kbd_get_keyboard(kbd_find_keyboard(ATKBD_DRIVER_NAME, 157 device_get_unit(dev))); 158 if (kbd) { 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); 165 } 166 return 0; 167} 168 169static void 170atkbd_isa_intr(void *arg) 171{ 172 keyboard_t *kbd; 173 174 kbd = (keyboard_t *)arg; 175 (*kbdsw[kbd->kb_index]->intr)(kbd, NULL); 176} 177 178DRIVER_MODULE(atkbd, atkbdc, atkbd_driver, atkbd_devclass, 0, 0);
| 30#include "opt_kbd.h" 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> 35#include <sys/bus.h> 36 37#include <machine/bus.h> 38#include <machine/resource.h> 39#include <sys/rman.h> 40 41#include <sys/kbio.h> 42#include <dev/kbd/kbdreg.h> 43#include <dev/kbd/atkbdreg.h> 44#include <dev/kbd/atkbdcreg.h> 45 46#include <isa/isareg.h> 47#include <isa/isavar.h> 48 49typedef struct { 50 struct resource *intr; 51 void *ih; 52} atkbd_softc_t; 53 54static devclass_t atkbd_devclass; 55 56static void atkbdidentify(driver_t *driver, device_t dev); 57static int atkbdprobe(device_t dev); 58static int atkbdattach(device_t dev); 59static int atkbdresume(device_t dev); 60static void atkbd_isa_intr(void *arg); 61 62static device_method_t atkbd_methods[] = { 63 DEVMETHOD(device_identify, atkbdidentify), 64 DEVMETHOD(device_probe, atkbdprobe), 65 DEVMETHOD(device_attach, atkbdattach), 66 DEVMETHOD(device_resume, atkbdresume), 67 { 0, 0 } 68}; 69 70static driver_t atkbd_driver = { 71 ATKBD_DRIVER_NAME, 72 atkbd_methods, 73 sizeof(atkbd_softc_t), 74}; 75 76static void 77atkbdidentify(driver_t *driver, device_t parent) 78{ 79 80 /* always add at least one child */ 81 BUS_ADD_CHILD(parent, KBDC_RID_KBD, driver->name, device_get_unit(parent)); 82} 83 84static int 85atkbdprobe(device_t dev) 86{ 87 struct resource *res; 88 u_long irq; 89 int flags; 90 int rid; 91 92 device_set_desc(dev, "AT Keyboard"); 93 94 /* obtain parameters */ 95 flags = device_get_flags(dev); 96 97 /* see if IRQ is available */ 98 rid = KBDC_RID_KBD; 99 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 100 RF_SHAREABLE | RF_ACTIVE); 101 if (res == NULL) { 102 if (bootverbose) 103 device_printf(dev, "unable to allocate IRQ\n"); 104 return ENXIO; 105 } 106 irq = rman_get_start(res); 107 bus_release_resource(dev, SYS_RES_IRQ, rid, res); 108 109 /* probe the device */ 110 return atkbd_probe_unit(device_get_unit(dev), 111 device_get_unit(device_get_parent(dev)), 112 irq, flags); 113} 114 115static int 116atkbdattach(device_t dev) 117{ 118 atkbd_softc_t *sc; 119 keyboard_t *kbd; 120 u_long irq; 121 int flags; 122 int rid; 123 int error; 124 125 sc = device_get_softc(dev); 126 127 rid = KBDC_RID_KBD; 128 irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid); 129 flags = device_get_flags(dev); 130 error = atkbd_attach_unit(device_get_unit(dev), &kbd, 131 device_get_unit(device_get_parent(dev)), 132 irq, flags); 133 if (error) 134 return error; 135 136 /* declare our interrupt handler */ 137 sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 138 RF_SHAREABLE | RF_ACTIVE); 139 if (sc->intr == NULL) 140 return ENXIO; 141 error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, atkbd_isa_intr, 142 kbd, &sc->ih); 143 if (error) 144 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr); 145 146 return error; 147} 148 149static int 150atkbdresume(device_t dev) 151{ 152 atkbd_softc_t *sc; 153 keyboard_t *kbd; 154 int args[2]; 155 156 sc = device_get_softc(dev); 157 kbd = kbd_get_keyboard(kbd_find_keyboard(ATKBD_DRIVER_NAME, 158 device_get_unit(dev))); 159 if (kbd) { 160 kbd->kb_flags &= ~KB_INITIALIZED; 161 args[0] = device_get_unit(device_get_parent(dev)); 162 args[1] = rman_get_start(sc->intr); 163 (*kbdsw[kbd->kb_index]->init)(device_get_unit(dev), &kbd, 164 args, device_get_flags(dev)); 165 (*kbdsw[kbd->kb_index]->clear_state)(kbd); 166 } 167 return 0; 168} 169 170static void 171atkbd_isa_intr(void *arg) 172{ 173 keyboard_t *kbd; 174 175 kbd = (keyboard_t *)arg; 176 (*kbdsw[kbd->kb_index]->intr)(kbd, NULL); 177} 178 179DRIVER_MODULE(atkbd, atkbdc, atkbd_driver, atkbd_devclass, 0, 0);
|