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 * $FreeBSD: src/sys/isa/atkbd_isa.c,v 1.7.2.3 2001/08/01 10:42:28 yokota Exp $ 27 * $DragonFly: src/sys/dev/misc/atkbd/atkbd_isa.c,v 1.3 2003/08/07 21:16:55 dillon Exp $ 28 */ 29 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/misc/kbd/kbdreg.h> 43 #include <dev/misc/kbd/atkbdreg.h> 44 #include <dev/misc/kbd/atkbdcreg.h> 45 46 #include <bus/isa/isareg.h> 47 #include <bus/isa/isavar.h> 48 49 typedef struct { 50 struct resource *intr; 51 void *ih; 52 } atkbd_softc_t; 53 54 devclass_t atkbd_devclass; 55 56 static int atkbdprobe(device_t dev); 57 static int atkbdattach(device_t dev); 58 static int atkbdresume(device_t dev); 59 static void atkbd_isa_intr(void *arg); 60 61 static device_method_t atkbd_methods[] = { 62 DEVMETHOD(device_probe, atkbdprobe), 63 DEVMETHOD(device_attach, atkbdattach), 64 DEVMETHOD(device_resume, atkbdresume), 65 { 0, 0 } 66 }; 67 68 static driver_t atkbd_driver = { 69 ATKBD_DRIVER_NAME, 70 atkbd_methods, 71 sizeof(atkbd_softc_t), 72 }; 73 74 static int 75 atkbdprobe(device_t dev) 76 { 77 uintptr_t irq; 78 uintptr_t flags; 79 80 device_set_desc(dev, "AT Keyboard"); 81 82 /* obtain parameters */ 83 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq); 84 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags); 85 86 /* probe the device */ 87 return atkbd_probe_unit(device_get_unit(dev), 88 device_get_unit(device_get_parent(dev)), 89 irq, flags); 90 } 91 92 static int 93 atkbdattach(device_t dev) 94 { 95 atkbd_softc_t *sc; 96 keyboard_t *kbd; 97 uintptr_t irq; 98 uintptr_t flags; 99 int rid; 100 int error; 101 102 sc = device_get_softc(dev); 103 104 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq); 105 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags); 106 107 error = atkbd_attach_unit(device_get_unit(dev), &kbd, 108 device_get_unit(device_get_parent(dev)), 109 irq, flags); 110 if (error) 111 return error; 112 113 /* declare our interrupt handler */ 114 rid = 0; 115 sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, irq, irq, 1, 116 RF_SHAREABLE | RF_ACTIVE); 117 BUS_SETUP_INTR(device_get_parent(dev), dev, sc->intr, INTR_TYPE_TTY, 118 atkbd_isa_intr, kbd, &sc->ih); 119 120 return 0; 121 } 122 123 static int 124 atkbdresume(device_t dev) 125 { 126 keyboard_t *kbd; 127 128 kbd = kbd_get_keyboard(kbd_find_keyboard(ATKBD_DRIVER_NAME, 129 device_get_unit(dev))); 130 if (kbd) 131 (*kbdsw[kbd->kb_index]->clear_state)(kbd); 132 return 0; 133 } 134 135 static void 136 atkbd_isa_intr(void *arg) 137 { 138 keyboard_t *kbd; 139 140 kbd = (keyboard_t *)arg; 141 (*kbdsw[kbd->kb_index]->intr)(kbd, NULL); 142 } 143 144 DRIVER_MODULE(atkbd, atkbdc, atkbd_driver, atkbd_devclass, 0, 0); 145