2 * Copyright (c) 2001 M. Warner Losh. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/param.h>
29 #include <sys/kernel.h>
30 #include <sys/module.h>
31 #include <sys/sysctl.h>
32 #include <sys/systm.h>
34 #include <pccard/i82365.h>
35 #include <pccard/cardinfo.h>
36 #include <pccard/slot.h>
37 #include <pccard/pcicvar.h>
40 #include <isa/isavar.h>
41 #include <dev/pcic/i82365reg.h>
43 #include <dev/pccard/pccardvar.h>
46 static struct isa_pnp_id pcic_ids[] = {
47 {PCIC_PNP_ACTIONTEC, NULL}, /* AEI0218 */
48 {PCIC_PNP_IBM3765, NULL}, /* IBM3765 */
49 {PCIC_PNP_82365, NULL}, /* PNP0E00 */
50 {PCIC_PNP_CL_PD6720, NULL}, /* PNP0E01 */
51 {PCIC_PNP_VLSI_82C146, NULL}, /* PNP0E02 */
52 {PCIC_PNP_82365_CARDBUS, NULL}, /* PNP0E03 */
53 {PCIC_PNP_SCM_SWAPBOX, NULL}, /* SCM0469 */
54 {PCIC_NEC_PC9801_102, NULL}, /* NEC8091 */
55 {PCIC_NEC_PC9821RA_E01, NULL}, /* NEC8121 */
63 { "Intel i82365SL-A/B", PCIC_AB_POWER},
64 { "IBM PCIC", PCIC_AB_POWER},
65 { "VLSI 82C146", PCIC_AB_POWER},
66 { "Cirrus logic 6722", PCIC_PD_POWER},
67 { "Cirrus logic 6710", PCIC_PD_POWER},
68 { "Vadem 365", PCIC_VG_POWER},
69 { "Vadem 465", PCIC_VG_POWER},
70 { "Vadem 468", PCIC_VG_POWER},
71 { "Vadem 469", PCIC_VG_POWER},
72 { "Ricoh RF5C296", PCIC_RICOH_POWER},
73 { "Ricoh RF5C396", PCIC_RICOH_POWER},
74 { "IBM KING", PCIC_KING_POWER},
75 { "Intel i82365SL-DF", PCIC_DF_POWER}
78 static pcic_intr_way_t pcic_isa_intr_way;
79 static pcic_init_t pcic_isa_init;
81 struct pcic_chip pcic_isa_chip = {
89 * Look for an Intel PCIC (or compatible).
90 * For each available slot, allocate a PC-CARD slot.
93 pcic_isa_probe(device_t dev)
95 int slotnum, validslots = 0;
97 struct pcic_slot *sp0;
98 struct pcic_slot *sp1;
99 struct pcic_slot spsave;
103 struct pcic_softc *sc;
106 /* Check isapnp ids */
107 error = ISA_PNP_PROBE(device_get_parent(dev), dev, pcic_ids);
111 if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0)
112 bus_set_resource(dev, SYS_RES_IOPORT, 0, PCIC_PORT_0,
115 r = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
118 device_printf(dev, "Cannot get I/O range\n");
122 sc = (struct pcic_softc *) device_get_softc(dev);
125 for (slotnum = 0; slotnum < PCIC_CARD_SLOTS; slotnum++, sp++) {
127 * Initialise the PCIC slot table.
129 sp->getb = pcic_getb_io;
130 sp->putb = pcic_putb_io;
131 sp->bst = rman_get_bustag(r);
132 sp->bsh = rman_get_bushandle(r);
133 sp->offset = slotnum * PCIC_SLOT_SIZE;
138 * Prescan for the broken VLSI chips.
140 * According to the Linux PCMCIA code from David Hinds,
141 * working chipsets return 0x84 from their (correct) ID ports,
142 * while the broken ones would need to be probed at the new
143 * offset we set after we assume it's broken.
145 * Note: because of this, we may incorrectly detect a single
146 * slot vlsi chip as a i82365sl step D. I cannot find a
147 * datasheet for the affected chip, so that's the best we can
152 if (sp0->getb(sp0, PCIC_ID_REV) == PCIC_VLSI82C146 &&
153 sp1->getb(sp1, PCIC_ID_REV) != PCIC_VLSI82C146) {
156 sp1->offset = PCIC_SLOT_SIZE << 1;
157 if (sp1->getb(sp1, PCIC_ID_REV) != PCIC_VLSI82C146) {
160 sp0->controller = PCIC_VLSI;
161 sp1->controller = PCIC_VLSI;
166 * Look for normal chipsets here.
169 for (slotnum = 0; slotnum < PCIC_CARD_SLOTS; slotnum++, sp++) {
171 * see if there's a PCMCIA controller here
172 * Intel PCMCIA controllers use 0x82 and 0x83
173 * IBM clone chips use 0x88 and 0x89, apparently
175 c = sp->getb(sp, PCIC_ID_REV);
183 sp->controller = PCIC_I82365;
184 sp->revision = c & 1;
186 * Check for Vadem chips by unlocking their extra
187 * registers and looking for valid ID. Bit 3 in
188 * the ID register is normally 0, except when
189 * PCIC_VADEMREV is set. Other bridges appear
190 * to ignore this frobbing.
192 bus_space_write_1(sp->bst, sp->bsh, PCIC_INDEX, 0x0E);
193 bus_space_write_1(sp->bst, sp->bsh, PCIC_INDEX, 0x37);
194 pcic_setb(sp, PCIC_VMISC, PCIC_VADEMREV);
195 c = sp->getb(sp, PCIC_ID_REV);
197 switch (sp->revision = c & 7) {
199 sp->controller = PCIC_VG365;
202 sp->controller = PCIC_VG465;
205 sp->controller = PCIC_VG468;
208 sp->controller = PCIC_VG469;
211 pcic_clrb(sp, PCIC_VMISC, PCIC_VADEMREV);
215 * Check for RICOH RF5C[23]96 PCMCIA Controller
217 c = sp->getb(sp, PCIC_RICOH_ID);
218 if (c == PCIC_RID_396)
219 sp->controller = PCIC_RF5C396;
220 else if (c == PCIC_RID_296)
221 sp->controller = PCIC_RF5C296;
225 * Intel i82365sl-DF step or maybe a vlsi 82c146
226 * we detected the vlsi case earlier, so if the controller
227 * isn't set, we know it is a i82365sl step D.
230 if (sp->controller == -1)
231 sp->controller = PCIC_I82365SL_DF;
235 sp->controller = PCIC_IBM;
236 sp->revision = c & 1;
239 sp->controller = PCIC_IBM_KING;
240 sp->revision = c & 1;
246 * Check for Cirrus logic chips.
248 sp->putb(sp, PCIC_CLCHIP, 0);
249 c = sp->getb(sp, PCIC_CLCHIP);
250 if ((c & PCIC_CLC_TOGGLE) == PCIC_CLC_TOGGLE) {
251 c = sp->getb(sp, PCIC_CLCHIP);
252 if ((c & PCIC_CLC_TOGGLE) == 0) {
253 if (c & PCIC_CLC_DUAL)
254 sp->controller = PCIC_PD6722;
256 sp->controller = PCIC_PD6710;
257 sp->revision = 8 - ((c & 0x1F) >> 2);
260 device_set_desc(dev, bridges[(int) sp->controller].name);
261 sc->flags = bridges[(int) sp->controller].flags;
263 * OK it seems we have a PCIC or lookalike.
264 * Allocate a slot and initialise the data structures.
267 sp->slt = (struct slot *) 1;
269 * Modem cards send the speaker audio (dialing noises)
270 * to the host's speaker. Cirrus Logic PCIC chips must
271 * enable this. There is also a Low Power Dynamic Mode bit
272 * that claims to reduce power consumption by 30%, so
273 * enable it and hope for the best.
275 if (sp->controller == PCIC_PD6722) {
276 pcic_setb(sp, PCIC_MISC1, PCIC_MISC1_SPEAKER);
277 pcic_setb(sp, PCIC_MISC2, PCIC_LPDM_EN);
280 bus_release_resource(dev, SYS_RES_IOPORT, rid, r);
281 return (validslots ? 0 : ENXIO);
285 pcic_isa_attach(device_t dev)
287 struct pcic_softc *sc;
293 sc = device_get_softc(dev);
295 r = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
302 sc->csc_route = pcic_iw_isa;
303 sc->func_route = pcic_iw_isa;
304 sc->chip = &pcic_isa_chip;
308 r = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE);
309 if (r == NULL && pcic_override_irq != 0) {
310 irq = pcic_override_irq;
311 r = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, irq, irq, 1,
314 if (r && ((1 << (rman_get_start(r))) & PCIC_INT_MASK_ALLOWED) == 0) {
316 "Hardware does not support irq %d, trying polling.\n",
318 bus_release_resource(dev, SYS_RES_IRQ, rid, r);
326 error = bus_setup_intr(dev, r, INTR_TYPE_MISC,
327 pcic_isa_intr, (void *) sc, &sc->ih);
332 irq = rman_get_start(r);
333 device_printf(dev, "management irq %d\n", irq);
337 sc->slot_poll = pcic_timeout;
338 sc->timeout_ch = timeout(sc->slot_poll, (void *) sc, hz/2);
339 device_printf(dev, "Polling mode\n");
342 return (pcic_attach(dev));
346 * ISA cards can only do ISA interrupts. There's no need to do
347 * anything but check args for sanity.
350 pcic_isa_intr_way(struct pcic_slot *sp, enum pcic_intr_way iw)
352 if (iw != pcic_iw_isa)
358 * No speicial initialization is necesary for ISA cards.
361 pcic_isa_init(device_t dev)
365 static device_method_t pcic_methods[] = {
366 /* Device interface */
367 DEVMETHOD(device_probe, pcic_isa_probe),
368 DEVMETHOD(device_attach, pcic_isa_attach),
369 DEVMETHOD(device_detach, bus_generic_detach),
370 DEVMETHOD(device_shutdown, bus_generic_shutdown),
371 DEVMETHOD(device_suspend, bus_generic_suspend),
372 DEVMETHOD(device_resume, bus_generic_resume),
375 DEVMETHOD(bus_print_child, bus_generic_print_child),
376 DEVMETHOD(bus_alloc_resource, pcic_alloc_resource),
377 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
378 DEVMETHOD(bus_activate_resource, pcic_activate_resource),
379 DEVMETHOD(bus_deactivate_resource, pcic_deactivate_resource),
380 DEVMETHOD(bus_setup_intr, pcic_setup_intr),
381 DEVMETHOD(bus_teardown_intr, pcic_teardown_intr),
384 DEVMETHOD(card_set_res_flags, pcic_set_res_flags),
385 DEVMETHOD(card_get_res_flags, pcic_get_res_flags),
386 DEVMETHOD(card_set_memory_offset, pcic_set_memory_offset),
387 DEVMETHOD(card_get_memory_offset, pcic_get_memory_offset),
392 static driver_t pcic_driver = {
395 sizeof(struct pcic_softc)
398 DRIVER_MODULE(pcic, isa, pcic_driver, pcic_devclass, 0, 0);