atkbd_atkbdc.c revision 58271
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: head/sys/dev/atkbdc/atkbd_atkbdc.c 58271 2000-03-19 03:25:13Z yokota $ 27 */ 28 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 <dev/kbd/kbdreg.h> 41#include <dev/kbd/atkbdreg.h> 42#include <dev/kbd/atkbdcreg.h> 43 44#include <isa/isareg.h> 45#include <isa/isavar.h> 46 47typedef struct { 48 struct resource *intr; 49 void *ih; 50} atkbd_softc_t; 51 52devclass_t atkbd_devclass; 53 54static int atkbdprobe(device_t dev); 55static int atkbdattach(device_t dev); 56static void atkbd_isa_intr(void *arg); 57 58static device_method_t atkbd_methods[] = { 59 DEVMETHOD(device_probe, atkbdprobe), 60 DEVMETHOD(device_attach, atkbdattach), 61 { 0, 0 } 62}; 63 64static driver_t atkbd_driver = { 65 ATKBD_DRIVER_NAME, 66 atkbd_methods, 67 sizeof(atkbd_softc_t), 68}; 69 70static int 71atkbdprobe(device_t dev) 72{ 73 uintptr_t irq; 74 uintptr_t flags; 75 76 device_set_desc(dev, "AT Keyboard"); 77 78 /* obtain parameters */ 79 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq); 80 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags); 81 82 /* probe the device */ 83 return atkbd_probe_unit(device_get_unit(dev), 84 device_get_unit(device_get_parent(dev)), 85 irq, flags); 86} 87 88static int 89atkbdattach(device_t dev) 90{ 91 atkbd_softc_t *sc; 92 keyboard_t *kbd; 93 uintptr_t irq; 94 uintptr_t flags; 95 int rid; 96 int error; 97 98 sc = device_get_softc(dev); 99 100 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq); 101 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags); 102 103 error = atkbd_attach_unit(device_get_unit(dev), &kbd, 104 device_get_unit(device_get_parent(dev)), 105 irq, flags); 106 if (error) 107 return error; 108 109 /* declare our interrupt handler */ 110 rid = 0; 111 sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, irq, irq, 1, 112 RF_SHAREABLE | RF_ACTIVE); 113 BUS_SETUP_INTR(device_get_parent(dev), dev, sc->intr, INTR_TYPE_TTY, 114 atkbd_isa_intr, kbd, &sc->ih); 115 116 return 0; 117} 118 119static void 120atkbd_isa_intr(void *arg) 121{ 122 keyboard_t *kbd; 123 124 kbd = (keyboard_t *)arg; 125 (*kbdsw[kbd->kb_index]->intr)(kbd, NULL); 126} 127 128DRIVER_MODULE(atkbd, atkbdc, atkbd_driver, atkbd_devclass, 0, 0); 129