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.
24 * $FreeBSD: src/sys/pccard/pcic_isa.c,v 1.13.2.8 2003/02/26 18:42:00 imp Exp $
25 * $DragonFly: src/sys/bus/pccard/Attic/pcic_isa.c,v 1.2 2003/06/17 04:28:55 dillon Exp $
28 #include <sys/param.h>
30 #include <sys/kernel.h>
31 #include <sys/module.h>
32 #include <sys/sysctl.h>
33 #include <sys/systm.h>
35 #include <pccard/i82365.h>
36 #include <pccard/cardinfo.h>
37 #include <pccard/slot.h>
38 #include <pccard/pcicvar.h>
41 #include <isa/isavar.h>
42 #include <dev/pcic/i82365reg.h>
44 #include <dev/pccard/pccardvar.h>
47 static struct isa_pnp_id pcic_ids[] = {
48 {PCIC_PNP_ACTIONTEC, NULL}, /* AEI0218 */
49 {PCIC_PNP_IBM3765, NULL}, /* IBM3765 */
50 {PCIC_PNP_82365, NULL}, /* PNP0E00 */
51 {PCIC_PNP_CL_PD6720, NULL}, /* PNP0E01 */
52 {PCIC_PNP_VLSI_82C146, NULL}, /* PNP0E02 */
53 {PCIC_PNP_82365_CARDBUS, NULL}, /* PNP0E03 */
54 {PCIC_PNP_SCM_SWAPBOX, NULL}, /* SCM0469 */
55 {PCIC_NEC_PC9801_102, NULL}, /* NEC8091 */
56 {PCIC_NEC_PC9821RA_E01, NULL}, /* NEC8121 */
64 { "Intel i82365SL-A/B", PCIC_AB_POWER},
65 { "IBM PCIC", PCIC_AB_POWER},
66 { "VLSI 82C146", PCIC_AB_POWER},
67 { "Cirrus logic 6722", PCIC_PD_POWER},
68 { "Cirrus logic 6710", PCIC_PD_POWER},
69 { "Vadem 365", PCIC_VG_POWER},
70 { "Vadem 465", PCIC_VG_POWER},
71 { "Vadem 468", PCIC_VG_POWER},
72 { "Vadem 469", PCIC_VG_POWER},
73 { "Ricoh RF5C296", PCIC_RICOH_POWER},
74 { "Ricoh RF5C396", PCIC_RICOH_POWER},
75 { "IBM KING", PCIC_KING_POWER},
76 { "Intel i82365SL-DF", PCIC_DF_POWER}
79 static pcic_intr_way_t pcic_isa_intr_way;
80 static pcic_init_t pcic_isa_init;
82 struct pcic_chip pcic_isa_chip = {
90 * Look for an Intel PCIC (or compatible).
91 * For each available slot, allocate a PC-CARD slot.
94 pcic_isa_probe(device_t dev)
96 int slotnum, validslots = 0;
98 struct pcic_slot *sp0;
99 struct pcic_slot *sp1;
100 struct pcic_slot spsave;
104 struct pcic_softc *sc;
107 /* Check isapnp ids */
108 error = ISA_PNP_PROBE(device_get_parent(dev), dev, pcic_ids);
112 if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0)
113 bus_set_resource(dev, SYS_RES_IOPORT, 0, PCIC_PORT_0,
116 r = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
119 device_printf(dev, "Cannot get I/O range\n");
123 sc = (struct pcic_softc *) device_get_softc(dev);
126 for (slotnum = 0; slotnum < PCIC_CARD_SLOTS; slotnum++, sp++) {
128 * Initialise the PCIC slot table.
130 sp->getb = pcic_getb_io;
131 sp->putb = pcic_putb_io;
132 sp->bst = rman_get_bustag(r);
133 sp->bsh = rman_get_bushandle(r);
134 sp->offset = slotnum * PCIC_SLOT_SIZE;
139 * Prescan for the broken VLSI chips.
141 * According to the Linux PCMCIA code from David Hinds,
142 * working chipsets return 0x84 from their (correct) ID ports,
143 * while the broken ones would need to be probed at the new
144 * offset we set after we assume it's broken.
146 * Note: because of this, we may incorrectly detect a single
147 * slot vlsi chip as an i82365sl step D. I cannot find a
148 * datasheet for the affected chip, so that's the best we can
153 if (sp0->getb(sp0, PCIC_ID_REV) == PCIC_VLSI82C146 &&
154 sp1->getb(sp1, PCIC_ID_REV) != PCIC_VLSI82C146) {
157 sp1->offset = PCIC_SLOT_SIZE << 1;
158 if (sp1->getb(sp1, PCIC_ID_REV) != PCIC_VLSI82C146) {
161 sp0->controller = PCIC_VLSI;
162 sp1->controller = PCIC_VLSI;
167 * Look for normal chipsets here.
170 for (slotnum = 0; slotnum < PCIC_CARD_SLOTS; slotnum++, sp++) {
172 * see if there's a PCMCIA controller here
173 * Intel PCMCIA controllers use 0x82 and 0x83
174 * IBM clone chips use 0x88 and 0x89, apparently
176 c = sp->getb(sp, PCIC_ID_REV);
184 sp->controller = PCIC_I82365;
185 sp->revision = c & 1;
187 * Check for Vadem chips by unlocking their extra
188 * registers and looking for valid ID. Bit 3 in
189 * the ID register is normally 0, except when
190 * PCIC_VADEMREV is set. Other bridges appear
191 * to ignore this frobbing.
193 bus_space_write_1(sp->bst, sp->bsh, PCIC_INDEX, 0x0E);
194 bus_space_write_1(sp->bst, sp->bsh, PCIC_INDEX, 0x37);
195 pcic_setb(sp, PCIC_VMISC, PCIC_VADEMREV);
196 c = sp->getb(sp, PCIC_ID_REV);
198 switch (sp->revision = c & 7) {
200 sp->controller = PCIC_VG365;
203 sp->controller = PCIC_VG465;
206 sp->controller = PCIC_VG468;
209 sp->controller = PCIC_VG469;
212 pcic_clrb(sp, PCIC_VMISC, PCIC_VADEMREV);
216 * Check for RICOH RF5C[23]96 PCMCIA Controller
218 c = sp->getb(sp, PCIC_RICOH_ID);
219 if (c == PCIC_RID_396)
220 sp->controller = PCIC_RF5C396;
221 else if (c == PCIC_RID_296)
222 sp->controller = PCIC_RF5C296;
226 * Intel i82365sl-DF step or maybe a vlsi 82c146
227 * we detected the vlsi case earlier, so if the controller
228 * isn't set, we know it is an i82365sl step D.
231 if (sp->controller == -1)
232 sp->controller = PCIC_I82365SL_DF;
236 sp->controller = PCIC_IBM;
237 sp->revision = c & 1;
240 sp->controller = PCIC_IBM_KING;
241 sp->revision = c & 1;
247 * Check for Cirrus logic chips.
249 sp->putb(sp, PCIC_CLCHIP, 0);
250 c = sp->getb(sp, PCIC_CLCHIP);
251 if ((c & PCIC_CLC_TOGGLE) == PCIC_CLC_TOGGLE) {
252 c = sp->getb(sp, PCIC_CLCHIP);
253 if ((c & PCIC_CLC_TOGGLE) == 0) {
254 if (c & PCIC_CLC_DUAL)
255 sp->controller = PCIC_PD6722;
257 sp->controller = PCIC_PD6710;
258 sp->revision = 8 - ((c & 0x1F) >> 2);
261 device_set_desc(dev, bridges[(int) sp->controller].name);
262 sc->flags = bridges[(int) sp->controller].flags;
264 * OK it seems we have a PCIC or lookalike.
265 * Allocate a slot and initialise the data structures.
268 sp->slt = (struct slot *) 1;
270 * Modem cards send the speaker audio (dialing noises)
271 * to the host's speaker. Cirrus Logic PCIC chips must
272 * enable this. There is also a Low Power Dynamic Mode bit
273 * that claims to reduce power consumption by 30%, so
274 * enable it and hope for the best.
276 if (sp->controller == PCIC_PD6722) {
277 pcic_setb(sp, PCIC_MISC1, PCIC_MISC1_SPEAKER);
278 pcic_setb(sp, PCIC_MISC2, PCIC_LPDM_EN);
281 bus_release_resource(dev, SYS_RES_IOPORT, rid, r);
282 return (validslots ? 0 : ENXIO);
286 pcic_isa_attach(device_t dev)
288 struct pcic_softc *sc;
294 sc = device_get_softc(dev);
296 r = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
303 sc->csc_route = pcic_iw_isa;
304 sc->func_route = pcic_iw_isa;
305 sc->chip = &pcic_isa_chip;
309 r = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE);
310 if (r == NULL && pcic_override_irq != 0) {
311 irq = pcic_override_irq;
312 r = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, irq, irq, 1,
315 if (r && ((1 << (rman_get_start(r))) & PCIC_INT_MASK_ALLOWED) == 0) {
317 "Hardware does not support irq %d, trying polling.\n",
319 bus_release_resource(dev, SYS_RES_IRQ, rid, r);
327 error = bus_setup_intr(dev, r, INTR_TYPE_MISC,
328 pcic_isa_intr, (void *) sc, &sc->ih);
333 irq = rman_get_start(r);
334 device_printf(dev, "management irq %d\n", irq);
338 sc->slot_poll = pcic_timeout;
339 sc->timeout_ch = timeout(sc->slot_poll, (void *) sc, hz/2);
340 device_printf(dev, "Polling mode\n");
343 return (pcic_attach(dev));
347 * ISA cards can only do ISA interrupts. There's no need to do
348 * anything but check args for sanity.
351 pcic_isa_intr_way(struct pcic_slot *sp, enum pcic_intr_way iw)
353 if (iw != pcic_iw_isa)
359 * No speicial initialization is necesary for ISA cards.
362 pcic_isa_init(device_t dev)
366 static device_method_t pcic_methods[] = {
367 /* Device interface */
368 DEVMETHOD(device_probe, pcic_isa_probe),
369 DEVMETHOD(device_attach, pcic_isa_attach),
370 DEVMETHOD(device_detach, bus_generic_detach),
371 DEVMETHOD(device_shutdown, bus_generic_shutdown),
372 DEVMETHOD(device_suspend, bus_generic_suspend),
373 DEVMETHOD(device_resume, bus_generic_resume),
376 DEVMETHOD(bus_print_child, bus_generic_print_child),
377 DEVMETHOD(bus_alloc_resource, pcic_alloc_resource),
378 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
379 DEVMETHOD(bus_activate_resource, pcic_activate_resource),
380 DEVMETHOD(bus_deactivate_resource, pcic_deactivate_resource),
381 DEVMETHOD(bus_setup_intr, pcic_setup_intr),
382 DEVMETHOD(bus_teardown_intr, pcic_teardown_intr),
385 DEVMETHOD(card_set_res_flags, pcic_set_res_flags),
386 DEVMETHOD(card_get_res_flags, pcic_get_res_flags),
387 DEVMETHOD(card_set_memory_offset, pcic_set_memory_offset),
388 DEVMETHOD(card_get_memory_offset, pcic_get_memory_offset),
393 static driver_t pcic_driver = {
396 sizeof(struct pcic_softc)
399 DRIVER_MODULE(pcic, isa, pcic_driver, pcic_devclass, 0, 0);