1 /*- 2 * Copyright (c) 2002-2004 M. Warner Losh. 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. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: src/sys/dev/pccbb/pccbb_isa.c,v 1.4 2005/01/11 05:33:18 imp Exp $ 27 */ 28 29 /* 30 * Driver for ISA to PCMCIA bridges compliant with the Intel ExCA 31 * specification. 32 */ 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/proc.h> 37 #include <sys/errno.h> 38 #include <sys/kernel.h> 39 #include <sys/lock.h> 40 #include <sys/malloc.h> 41 #include <sys/module.h> 42 #include <sys/sysctl.h> 43 #include <sys/kthread.h> 44 #include <sys/bus.h> 45 #include <sys/rman.h> 46 47 #include <bus/isa/isavar.h> 48 49 #include <bus/pccard/pccardreg.h> 50 #include <bus/pccard/pccardvar.h> 51 52 #include <dev/pccard/exca/excareg.h> 53 #include <dev/pccard/exca/excavar.h> 54 55 #include <dev/pccard/pccbb/pccbbreg.h> 56 #include <dev/pccard/pccbb/pccbbvar.h> 57 58 #include "power_if.h" 59 #include "card_if.h" 60 61 /***************************************************************************** 62 * Configurable parameters. 63 *****************************************************************************/ 64 65 /* sysctl vars */ 66 SYSCTL_NODE(_hw, OID_AUTO, pcic, CTLFLAG_RD, 0, "PCIC parameters"); 67 68 static int isa_intr_mask = EXCA_INT_MASK_ALLOWED; 69 TUNABLE_INT("hw.cbb.intr_mask", &isa_intr_mask); 70 SYSCTL_INT(_hw_pcic, OID_AUTO, intr_mask, CTLFLAG_RD, &isa_intr_mask, 0, 71 "Mask of allowable interrupts for this laptop. The default is generally" 72 " correct, but some laptops do not route all the IRQ pins to the bridge to" 73 " save wires. Sometimes you need a more restrictive mask because some of" 74 " the hardware in your laptop may not have a driver so its IRQ might not be" 75 " allocated."); 76 77 /***************************************************************************** 78 * End of configurable parameters. 79 *****************************************************************************/ 80 81 #define DPRINTF(x) do { if (cbb_debug) kprintf x; } while (0) 82 #define DEVPRINTF(x) do { if (cbb_debug) device_printf x; } while (0) 83 84 static struct isa_pnp_id pcic_ids[] = { 85 {EXCA_PNP_ACTIONTEC, NULL}, /* AEI0218 */ 86 {EXCA_PNP_IBM3765, NULL}, /* IBM3765 */ 87 {EXCA_PNP_82365, NULL}, /* PNP0E00 */ 88 {EXCA_PNP_CL_PD6720, NULL}, /* PNP0E01 */ 89 {EXCA_PNP_VLSI_82C146, NULL}, /* PNP0E02 */ 90 {EXCA_PNP_82365_CARDBUS, NULL}, /* PNP0E03 */ 91 {EXCA_PNP_SCM_SWAPBOX, NULL}, /* SCM0469 */ 92 {0} 93 }; 94 95 /************************************************************************/ 96 /* Probe/Attach */ 97 /************************************************************************/ 98 99 #if 0 100 struct resource *res; 101 int rid; 102 int i; 103 104 /* A little bogus, but go ahead and get the irq for CSC events */ 105 rid = 0; 106 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); 107 if (res == NULL) { 108 /* 109 * No IRQ specified, find one. This can be due to the PnP 110 * data not specifying any IRQ, or the default kernel not 111 * assinging an IRQ. 112 */ 113 for (i = 0; i < 16; i++) { 114 if (((1 << i) & isa_intr_mask) == 0) 115 continue; 116 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, i, i, 117 1, RF_ACTIVE); 118 if (res != NULL) 119 break; 120 } 121 if (res == NULL) 122 return (ENXIO); 123 bus_release_resource(dev, SYS_RES_IRQ, rid, res); 124 bus_set_resource(dev, SYS_RES_IRQ, 0, i, 1); 125 } else { 126 bus_release_resource(dev, SYS_RES_IRQ, rid, res); 127 } 128 if (res == NULL) { 129 device_printf(dev, "Cannot allocate mem\n"); 130 return (ENOMEM); 131 } 132 #endif 133 134 static int 135 cbb_isa_activate(device_t dev) 136 { 137 return (ENOMEM); 138 } 139 140 static void 141 cbb_isa_deactivate(device_t dev) 142 { 143 } 144 145 static int 146 cbb_isa_probe(device_t dev) 147 { 148 int error; 149 struct cbb_softc *sc = device_get_softc(dev); 150 151 /* Check isapnp ids */ 152 error = ISA_PNP_PROBE(device_get_parent(dev), dev, pcic_ids); 153 if (error != 0 && error != ENOENT) 154 return (error); 155 156 error = cbb_isa_activate(dev); 157 if (error != 0) 158 return (error); 159 160 /* Check to make sure that we have actual hardware */ 161 error = exca_probe_slots(dev, &sc->exca[0], sc->bst, sc->bsh); 162 cbb_isa_deactivate(dev); 163 return (error); 164 } 165 166 static int 167 cbb_isa_attach(device_t dev) 168 { 169 return (ENOMEM); 170 } 171 172 static device_method_t cbb_methods[] = { 173 /* Device interface */ 174 DEVMETHOD(device_probe, cbb_isa_probe), 175 DEVMETHOD(device_attach, cbb_isa_attach), 176 DEVMETHOD(device_detach, cbb_detach), 177 DEVMETHOD(device_shutdown, cbb_shutdown), 178 DEVMETHOD(device_suspend, cbb_suspend), 179 DEVMETHOD(device_resume, cbb_resume), 180 181 /* bus methods */ 182 DEVMETHOD(bus_print_child, bus_generic_print_child), 183 DEVMETHOD(bus_read_ivar, cbb_read_ivar), 184 DEVMETHOD(bus_write_ivar, cbb_write_ivar), 185 DEVMETHOD(bus_alloc_resource, cbb_alloc_resource), 186 DEVMETHOD(bus_release_resource, cbb_release_resource), 187 DEVMETHOD(bus_activate_resource, cbb_activate_resource), 188 DEVMETHOD(bus_deactivate_resource, cbb_deactivate_resource), 189 DEVMETHOD(bus_driver_added, cbb_driver_added), 190 DEVMETHOD(bus_child_detached, cbb_child_detached), 191 DEVMETHOD(bus_setup_intr, cbb_setup_intr), 192 DEVMETHOD(bus_teardown_intr, cbb_teardown_intr), 193 DEVMETHOD(bus_child_present, cbb_child_present), 194 195 /* 16-bit card interface */ 196 DEVMETHOD(card_set_res_flags, cbb_pcic_set_res_flags), 197 DEVMETHOD(card_set_memory_offset, cbb_pcic_set_memory_offset), 198 199 /* power interface */ 200 DEVMETHOD(power_enable_socket, cbb_power_enable_socket), 201 DEVMETHOD(power_disable_socket, cbb_power_disable_socket), 202 203 DEVMETHOD_END 204 }; 205 206 static driver_t cbb_isa_driver = { 207 "cbb", 208 cbb_methods, 209 sizeof(struct cbb_softc) 210 }; 211 212 DRIVER_MODULE(cbb, isa, cbb_isa_driver, cbb_devclass, NULL, NULL); 213 MODULE_DEPEND(cbb, exca, 1, 1, 1); 214