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 unchanged lines hidden (view full) --- 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/atkbdc_isa.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#include <sys/malloc.h> |
36#include <machine/bus_pio.h> |
37#include <machine/bus.h> 38#include <machine/resource.h> 39#include <sys/rman.h> 40 41#include <dev/kbd/atkbdcreg.h> 42 43#include <isa/isareg.h> 44#include <isa/isavar.h> --- 38 unchanged lines hidden (view full) --- 83}; 84 85static driver_t atkbdc_driver = { 86 ATKBDC_DRIVER_NAME, 87 atkbdc_methods, 88 sizeof(atkbdc_softc_t *), 89}; 90 |
91static struct isa_pnp_id atkbdc_ids[] = { 92 { 0x0303d041, "Keyboard controller (i8042)" }, /* PNP0303 */ 93 { 0 } 94}; 95 |
96static int 97atkbdc_probe(device_t dev) 98{ |
99 struct resource *port0; 100 struct resource *port1; 101 int error; 102 int rid; |
103 |
104 /* check PnP IDs */ 105 if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO) 106 return ENXIO; |
107 |
108 device_set_desc(dev, "Keyboard controller (i8042)"); 109 |
110 rid = 0; |
111 port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, 112 RF_ACTIVE); 113 if (port0 == NULL) |
114 return ENXIO; |
115 /* XXX */ 116 if (bus_get_resource_start(dev, SYS_RES_IOPORT, 1) <= 0) { 117 bus_set_resource(dev, SYS_RES_IOPORT, 1, 118 rman_get_start(port0) + KBD_STATUS_PORT, 1); 119 } 120 rid = 1; 121 port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, 122 RF_ACTIVE); 123 if (port1 == NULL) { 124 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); 125 return ENXIO; 126 } 127 128 error = atkbdc_probe_unit(device_get_unit(dev), port0, port1); 129 130 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); 131 bus_release_resource(dev, SYS_RES_IOPORT, 1, port1); 132 |
133 return error; 134} 135 136static void 137atkbdc_add_device(device_t dev, const char *name, int unit) 138{ |
139 atkbdc_device_t *kdev; 140 device_t child; 141 int t; 142 143 if (resource_int_value(name, unit, "disabled", &t) == 0 && t != 0) 144 return; 145 146 kdev = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV, M_NOWAIT); 147 if (!kdev) 148 return; 149 bzero(kdev, sizeof *kdev); 150 |
151 if (resource_int_value(name, unit, "irq", &t) == 0) 152 kdev->irq = t; 153 else 154 kdev->irq = -1; 155 156 if (resource_int_value(name, unit, "flags", &t) == 0) 157 kdev->flags = t; 158 else 159 kdev->flags = 0; 160 161 child = device_add_child(dev, name, unit); 162 device_set_ivars(child, kdev); 163} 164 165static int 166atkbdc_attach(device_t dev) 167{ 168 atkbdc_softc_t *sc; |
169 int unit; 170 int error; 171 int rid; 172 int i; 173 174 unit = device_get_unit(dev); 175 sc = *(atkbdc_softc_t **)device_get_softc(dev); 176 if (sc == NULL) { --- 4 unchanged lines hidden (view full) --- 181 * kbdc_soft[] contains the default entry for that purpose. 182 * See atkbdc.c. XXX 183 */ 184 sc = atkbdc_get_softc(unit); 185 if (sc == NULL) 186 return ENOMEM; 187 } 188 |
189 rid = 0; |
190 sc->port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, 191 RF_ACTIVE); 192 if (sc->port0 == NULL) |
193 return ENXIO; |
194 rid = 1; 195 sc->port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, 196 RF_ACTIVE); 197 if (sc->port1 == NULL) { 198 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0); 199 return ENXIO; 200 } 201 202 error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1); 203 if (error) { 204 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0); 205 bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1); |
206 return error; |
207 } |
208 *(atkbdc_softc_t **)device_get_softc(dev) = sc; 209 210 /* 211 * Add all devices configured to be attached to atkbdc0. 212 */ 213 for (i = resource_query_string(-1, "at", "atkbdc0"); 214 i != -1; 215 i = resource_query_string(i, "at", "atkbdc0")) { --- 82 unchanged lines hidden --- |