1 /* $OpenBSD: i82365_isapnp.c,v 1.6 2005/01/27 17:03:23 millert Exp $ */ 2 /* $NetBSD: i82365_isapnp.c,v 1.8 2000/02/23 17:22:11 soren Exp $ */ 3 4 /* 5 * Copyright (c) 1998 Bill Sommerfeld. All rights reserved. 6 * Copyright (c) 1997 Marc Horowitz. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Marc Horowitz. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 35 #include <sys/types.h> 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/kernel.h> 39 #include <sys/device.h> 40 #include <sys/extent.h> 41 #include <sys/malloc.h> 42 43 #include <machine/bus.h> 44 #include <machine/intr.h> 45 46 #include <dev/isa/isareg.h> 47 #include <dev/isa/isavar.h> 48 49 #include <dev/isa/isapnpreg.h> 50 51 #include <dev/pcmcia/pcmciareg.h> 52 #include <dev/pcmcia/pcmciavar.h> 53 #include <dev/pcmcia/pcmciachip.h> 54 55 #include <dev/ic/i82365reg.h> 56 #include <dev/ic/i82365var.h> 57 #include <dev/isa/i82365_isavar.h> 58 59 #undef DPRINTF 60 #ifdef PCICISADEBUG 61 int pcicisapnp_debug = 0 /* XXX */ ; 62 #define DPRINTF(arg) if (pcicisapnp_debug) printf arg; 63 #else 64 #define DPRINTF(arg) 65 #endif 66 67 int pcic_isapnp_match(struct device *, void *, void *); 68 void pcic_isapnp_attach(struct device *, struct device *, void *); 69 70 struct cfattach pcic_isapnp_ca = { 71 sizeof(struct pcic_softc), pcic_isapnp_match, pcic_isapnp_attach 72 }; 73 74 static struct pcmcia_chip_functions pcic_isa_functions = { 75 pcic_chip_mem_alloc, 76 pcic_chip_mem_free, 77 pcic_chip_mem_map, 78 pcic_chip_mem_unmap, 79 80 pcic_chip_io_alloc, 81 pcic_chip_io_free, 82 pcic_chip_io_map, 83 pcic_chip_io_unmap, 84 85 pcic_isa_chip_intr_establish, 86 pcic_isa_chip_intr_disestablish, 87 pcic_isa_chip_intr_string, 88 89 pcic_chip_socket_enable, 90 pcic_chip_socket_disable, 91 }; 92 93 int 94 pcic_isapnp_match(parent, match, aux) 95 struct device *parent; 96 void *match; 97 void *aux; 98 { 99 return (1); 100 } 101 102 void 103 pcic_isapnp_attach(parent, self, aux) 104 struct device *parent, *self; 105 void *aux; 106 { 107 struct pcic_softc *sc = (void *) self; 108 struct pcic_handle *h; 109 struct isa_attach_args *ipa = aux; 110 isa_chipset_tag_t ic = ipa->ia_ic; 111 bus_space_tag_t iot = ipa->ia_iot; 112 bus_space_tag_t memt = ipa->ia_memt; 113 bus_space_handle_t ioh; 114 bus_space_handle_t memh; 115 int tmp1, i; 116 117 printf("\n"); 118 119 if (isapnp_config(iot, memt, ipa)) { 120 printf("%s: error in region allocation\n", sc->dev.dv_xname); 121 return; 122 } 123 124 printf("%s: %s %s", sc->dev.dv_xname, ipa->ipa_devident, 125 ipa->ipa_devclass); 126 127 /* sanity check that we get at least one hunk of IO space.. */ 128 if (ipa->ipa_nio < 1) { 129 printf("%s: failed to get one chunk of i/o space\n", 130 sc->dev.dv_xname); 131 return; 132 } 133 134 /* Find i/o space. */ 135 ioh = ipa->ipa_io[0].h; 136 137 /* sanity check to make sure we have a real PCIC there.. */ 138 bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SA + PCIC_IDENT); 139 tmp1 = bus_space_read_1(iot, ioh, PCIC_REG_DATA); 140 printf("(ident 0x%x", tmp1); 141 if (pcic_ident_ok(tmp1)) { 142 printf(" OK)"); 143 } else { 144 printf(" Not OK)\n"); 145 return; 146 } 147 148 if (bus_space_map(memt, ipa->ia_maddr, ipa->ia_msize, 0, &memh)) { 149 printf(": can't map mem space\n"); 150 return; 151 } 152 153 sc->membase = ipa->ia_maddr; 154 sc->subregionmask = (1 << (ipa->ia_msize / PCIC_MEM_PAGESIZE)) - 1; 155 156 sc->intr_est = ic; 157 sc->pct = (pcmcia_chipset_tag_t) & pcic_isa_functions; 158 159 sc->iot = iot; 160 sc->ioh = ioh; 161 sc->memt = memt; 162 sc->memh = memh; 163 164 printf("\n"); 165 166 pcic_attach(sc); 167 pcic_isa_bus_width_probe(sc, iot, ioh, ipa->ipa_io[0].base, 168 ipa->ipa_io[0].length); 169 pcic_attach_sockets(sc); 170 171 /* 172 * allocate an irq. it will be used by both controllers. I could 173 * use two different interrupts, but interrupts are relatively 174 * scarce, shareable, and for PCIC controllers, very infrequent. 175 */ 176 177 if (ipa->ipa_nirq > 0) 178 sc->irq = ipa->ipa_irq[0].num; 179 else 180 sc->irq = IRQUNK; 181 182 if (sc->irq == IRQUNK) 183 sc->irq = pcic_intr_find(sc, IST_EDGE); 184 185 if (sc->irq) { 186 sc->ih = isa_intr_establish(ic, sc->irq, IST_EDGE, IPL_TTY, 187 pcic_intr, sc, sc->dev.dv_xname); 188 if (!sc->ih) 189 sc->irq = 0; 190 } 191 192 if (sc->irq) { 193 printf("%s: irq %d, ", sc->dev.dv_xname, sc->irq); 194 195 /* Set up the pcic to interrupt on card detect. */ 196 for (i = 0; i < PCIC_NSLOTS; i++) { 197 h = &sc->handle[i]; 198 if (h->flags & PCIC_FLAG_SOCKETP) { 199 pcic_write(h, PCIC_CSC_INTR, 200 (sc->irq << PCIC_CSC_INTR_IRQ_SHIFT) | 201 PCIC_CSC_INTR_CD_ENABLE); 202 powerhook_establish(pcic_power, h); 203 } 204 } 205 } else 206 printf("%s: no irq, ", sc->dev.dv_xname); 207 208 printf("polling enabled\n"); 209 if (sc->poll_established == 0) { 210 timeout_set(&sc->poll_timeout, pcic_poll_intr, sc); 211 timeout_add(&sc->poll_timeout, hz / 2); 212 sc->poll_established = 1; 213 } 214 } 215