FreeBSD/Linux Kernel Cross Reference
sys/pccard/pcic_isa.c
1 /*
2 * Copyright (c) 2001 M. Warner Losh. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
23 *
24 * $FreeBSD: releng/5.3/sys/pccard/pcic_isa.c 133632 2004-08-13 06:57:31Z imp $
25 */
26
27 #define OBSOLETE_IN_6
28
29 #include <sys/param.h>
30 #include <sys/bus.h>
31 #include <sys/kernel.h>
32 #include <sys/module.h>
33 #include <sys/sysctl.h>
34 #include <sys/systm.h>
35
36 #include <pccard/i82365.h>
37 #include <pccard/cardinfo.h>
38 #include <pccard/slot.h>
39 #include <pccard/pcicvar.h>
40
41 /* Get pnp IDs */
42 #include <isa/isavar.h>
43
44 #include <dev/pccard/pccardvar.h>
45 #include "card_if.h"
46
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 */
57 {0}
58 };
59
60 static struct {
61 const char *name;
62 u_int32_t flags;
63 } bridges[] = {
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}
77 };
78
79 static pcic_intr_way_t pcic_isa_intr_way;
80 static pcic_init_t pcic_isa_init;
81
82 struct pcic_chip pcic_isa_chip = {
83 pcic_isa_intr_way,
84 pcic_isa_intr_way,
85 pcic_isa_mapirq,
86 pcic_isa_init
87 };
88
89 /*
90 * Look for an Intel PCIC (or compatible).
91 * For each available slot, allocate a PC-CARD slot.
92 */
93 static int
94 pcic_isa_probe(device_t dev)
95 {
96 int slotnum, validslots = 0;
97 struct pcic_slot *sp;
98 struct pcic_slot *sp0;
99 struct pcic_slot *sp1;
100 struct pcic_slot spsave;
101 unsigned char c;
102 struct resource *r;
103 int rid;
104 struct pcic_softc *sc;
105 int error;
106
107 /* Check isapnp ids */
108 error = ISA_PNP_PROBE(device_get_parent(dev), dev, pcic_ids);
109 if (error == ENXIO)
110 return (ENXIO);
111
112 if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0)
113 bus_set_resource(dev, SYS_RES_IOPORT, 0, PCIC_PORT_0,
114 PCIC_NPORT);
115 rid = 0;
116 r = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
117 if (!r) {
118 if (bootverbose)
119 device_printf(dev, "Cannot get I/O range\n");
120 return (ENOMEM);
121 }
122
123 sc = (struct pcic_softc *) device_get_softc(dev);
124 sc->dev = dev;
125 sp = &sc->slots[0];
126 for (slotnum = 0; slotnum < PCIC_CARD_SLOTS; slotnum++, sp++) {
127 /*
128 * Initialise the PCIC slot table.
129 */
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;
135 sp->controller = -1;
136 }
137
138 /*
139 * Prescan for the broken VLSI chips.
140 *
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.
145 *
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
149 * do for now.
150 */
151 sp0 = &sc->slots[0];
152 sp1 = &sc->slots[1];
153 if (sp0->getb(sp0, PCIC_ID_REV) == PCIC_VLSI82C146 &&
154 sp1->getb(sp1, PCIC_ID_REV) != PCIC_VLSI82C146) {
155 spsave = *sp1;
156 sp1->bsh += 4;
157 sp1->offset = PCIC_SLOT_SIZE << 1;
158 if (sp1->getb(sp1, PCIC_ID_REV) != PCIC_VLSI82C146) {
159 *sp1 = spsave;
160 } else {
161 sp0->controller = PCIC_VLSI;
162 sp1->controller = PCIC_VLSI;
163 }
164 }
165
166 /*
167 * Look for normal chipsets here.
168 */
169 sp = &sc->slots[0];
170 for (slotnum = 0; slotnum < PCIC_CARD_SLOTS; slotnum++, sp++) {
171 /*
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
175 */
176 c = sp->getb(sp, PCIC_ID_REV);
177 sp->revision = -1;
178 switch(c) {
179 /*
180 * 82365 or clones.
181 */
182 case PCIC_INTEL0:
183 case PCIC_INTEL1:
184 sp->controller = PCIC_I82365;
185 sp->revision = c & 1;
186 /*
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.
192 */
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);
197 if (c & 0x08) {
198 switch (sp->revision = c & 7) {
199 case 1:
200 sp->controller = PCIC_VG365;
201 break;
202 case 2:
203 sp->controller = PCIC_VG465;
204 break;
205 case 3:
206 sp->controller = PCIC_VG468;
207 break;
208 default:
209 sp->controller = PCIC_VG469;
210 break;
211 }
212 pcic_clrb(sp, PCIC_VMISC, PCIC_VADEMREV);
213 }
214
215 /*
216 * Check for RICOH RF5C[23]96 PCMCIA Controller
217 */
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;
223
224 break;
225 /*
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.
229 */
230 case PCIC_INTEL2:
231 if (sp->controller == -1)
232 sp->controller = PCIC_I82365SL_DF;
233 break;
234 case PCIC_IBM1:
235 case PCIC_IBM2:
236 sp->controller = PCIC_IBM;
237 sp->revision = c & 1;
238 break;
239 case PCIC_IBM3:
240 sp->controller = PCIC_IBM_KING;
241 sp->revision = c & 1;
242 break;
243 default:
244 continue;
245 }
246 /*
247 * Check for Cirrus logic chips.
248 */
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;
256 else
257 sp->controller = PCIC_PD6710;
258 sp->revision = 8 - ((c & 0x1F) >> 2);
259 }
260 }
261 device_set_desc(dev, bridges[(int) sp->controller].name);
262 sc->flags = bridges[(int) sp->controller].flags;
263 /*
264 * OK it seems we have a PCIC or lookalike.
265 * Allocate a slot and initialise the data structures.
266 */
267 validslots++;
268 sp->slt = (struct slot *) 1;
269 /*
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.
275 */
276 if (sp->controller == PCIC_PD6722) {
277 pcic_setb(sp, PCIC_MISC1, PCIC_MISC1_SPEAKER);
278 pcic_setb(sp, PCIC_MISC2, PCIC_LPDM_EN);
279 }
280 }
281 bus_release_resource(dev, SYS_RES_IOPORT, rid, r);
282 return (validslots ? 0 : ENXIO);
283 }
284
285 static int
286 pcic_isa_attach(device_t dev)
287 {
288 struct pcic_softc *sc;
289 int rid;
290 struct resource *r;
291 int irq = 0;
292 int error;
293
294 sc = device_get_softc(dev);
295 rid = 0;
296 r = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
297 if (!r) {
298 pcic_dealloc(dev);
299 return (ENXIO);
300 }
301 sc->iorid = rid;
302 sc->iores = r;
303 sc->csc_route = pcic_iw_isa;
304 sc->func_route = pcic_iw_isa;
305 sc->chip = &pcic_isa_chip;
306
307 rid = 0;
308 r = NULL;
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,
313 RF_ACTIVE);
314 }
315 if (r && ((1 << (rman_get_start(r))) & PCIC_INT_MASK_ALLOWED) == 0) {
316 device_printf(dev,
317 "Hardware does not support irq %d, trying polling.\n",
318 irq);
319 bus_release_resource(dev, SYS_RES_IRQ, rid, r);
320 irq = 0;
321 r = NULL;
322 }
323 sc->irqrid = rid;
324 sc->irqres = r;
325 irq = 0;
326 if (r != NULL) {
327 error = bus_setup_intr(dev, r, INTR_TYPE_MISC,
328 pcic_isa_intr, (void *) sc, &sc->ih);
329 if (error) {
330 pcic_dealloc(dev);
331 return (error);
332 }
333 irq = rman_get_start(r);
334 device_printf(dev, "management irq %d\n", irq);
335 }
336 sc->irq = irq;
337 if (irq == 0) {
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");
341 }
342
343 return (pcic_attach(dev));
344 }
345
346 /*
347 * ISA cards can only do ISA interrupts. There's no need to do
348 * anything but check args for sanity.
349 */
350 static int
351 pcic_isa_intr_way(struct pcic_slot *sp, enum pcic_intr_way iw)
352 {
353 if (iw != pcic_iw_isa)
354 return (EINVAL);
355 return (0);
356 }
357
358 /*
359 * No speicial initialization is necesary for ISA cards.
360 */
361 static void
362 pcic_isa_init(device_t dev)
363 {
364 }
365
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),
374
375 /* Bus interface */
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),
383
384 /* Card interface */
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),
389
390 { 0, 0 }
391 };
392
393 static driver_t pcic_driver = {
394 "pcic",
395 pcic_methods,
396 sizeof(struct pcic_softc)
397 };
398
399 DRIVER_MODULE(pcic, isa, pcic_driver, pcic_devclass, 0, 0);
Cache object: 0176e4c8a398335504266c80c3e63e8a
|