i82365_isa.c revision 1.14 1 /* $NetBSD: i82365_isa.c,v 1.14 2000/06/28 16:27:53 mrg Exp $ */
2
3 #define PCICISADEBUG
4
5 /*
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 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/extent.h>
39 #include <sys/malloc.h>
40
41 #include <machine/bus.h>
42 #include <machine/intr.h>
43
44 #include <dev/isa/isareg.h>
45 #include <dev/isa/isavar.h>
46
47 #include <dev/pcmcia/pcmciareg.h>
48 #include <dev/pcmcia/pcmciavar.h>
49 #include <dev/pcmcia/pcmciachip.h>
50
51 #include <dev/ic/i82365reg.h>
52 #include <dev/ic/i82365var.h>
53 #include <dev/isa/i82365_isavar.h>
54
55 #ifdef PCICISADEBUG
56 int pcicisa_debug = 0;
57 #define DPRINTF(arg) if (pcicisa_debug) printf arg;
58 #else
59 #define DPRINTF(arg)
60 #endif
61
62 int pcic_isa_probe __P((struct device *, struct cfdata *, void *));
63 void pcic_isa_attach __P((struct device *, struct device *, void *));
64
65 struct cfattach pcic_isa_ca = {
66 sizeof(struct pcic_isa_softc), pcic_isa_probe, pcic_isa_attach
67 };
68
69 static struct pcmcia_chip_functions pcic_isa_functions = {
70 pcic_chip_mem_alloc,
71 pcic_chip_mem_free,
72 pcic_chip_mem_map,
73 pcic_chip_mem_unmap,
74
75 pcic_chip_io_alloc,
76 pcic_chip_io_free,
77 pcic_chip_io_map,
78 pcic_chip_io_unmap,
79
80 pcic_isa_chip_intr_establish,
81 pcic_isa_chip_intr_disestablish,
82
83 pcic_chip_socket_enable,
84 pcic_chip_socket_disable,
85 };
86
87 int
88 pcic_isa_probe(parent, match, aux)
89 struct device *parent;
90 struct cfdata *match;
91 void *aux;
92 {
93 struct isa_attach_args *ia = aux;
94 bus_space_tag_t iot = ia->ia_iot;
95 bus_space_handle_t ioh, memh;
96 int val, found;
97
98 /* Disallow wildcarded i/o address. */
99 if (ia->ia_iobase == ISACF_PORT_DEFAULT)
100 return (0);
101
102 if (bus_space_map(iot, ia->ia_iobase, PCIC_IOSIZE, 0, &ioh))
103 return (0);
104
105 if (ia->ia_msize == -1)
106 ia->ia_msize = PCIC_MEMSIZE;
107
108 if (bus_space_map(ia->ia_memt, ia->ia_maddr, ia->ia_msize, 0, &memh))
109 return (0);
110
111 found = 0;
112
113 /*
114 * this could be done with a loop, but it would violate the
115 * abstraction
116 */
117
118 bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SA + PCIC_IDENT);
119
120 val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
121
122 if (pcic_ident_ok(val))
123 found++;
124
125
126 bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SB + PCIC_IDENT);
127
128 val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
129
130 if (pcic_ident_ok(val))
131 found++;
132
133
134 bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SA + PCIC_IDENT);
135
136 val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
137
138 if (pcic_ident_ok(val))
139 found++;
140
141
142 bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SB + PCIC_IDENT);
143
144 val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
145
146 if (pcic_ident_ok(val))
147 found++;
148
149
150 bus_space_unmap(iot, ioh, PCIC_IOSIZE);
151 bus_space_unmap(ia->ia_memt, memh, ia->ia_msize);
152
153 if (!found)
154 return (0);
155
156 ia->ia_iosize = PCIC_IOSIZE;
157
158 return (1);
159 }
160
161 void
162 pcic_isa_attach(parent, self, aux)
163 struct device *parent, *self;
164 void *aux;
165 {
166 struct pcic_softc *sc = (void *) self;
167 struct pcic_isa_softc *isc = (void *) self;
168 struct isa_attach_args *ia = aux;
169 isa_chipset_tag_t ic = ia->ia_ic;
170 bus_space_tag_t iot = ia->ia_iot;
171 bus_space_tag_t memt = ia->ia_memt;
172 bus_space_handle_t ioh;
173 bus_space_handle_t memh;
174
175 /* Map i/o space. */
176 if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh)) {
177 printf(": can't map i/o space\n");
178 return;
179 }
180
181 /* Map mem space. */
182 if (bus_space_map(memt, ia->ia_maddr, ia->ia_msize, 0, &memh)) {
183 printf(": can't map mem space\n");
184 return;
185 }
186
187 sc->membase = ia->ia_maddr;
188 sc->subregionmask = (1 << (ia->ia_msize / PCIC_MEM_PAGESIZE)) - 1;
189
190 isc->sc_ic = ic;
191 sc->pct = (pcmcia_chipset_tag_t) & pcic_isa_functions;
192
193 sc->iot = iot;
194 sc->ioh = ioh;
195 sc->memt = memt;
196 sc->memh = memh;
197 sc->irq = ia->ia_irq;
198
199 printf("\n");
200
201 pcic_attach(sc);
202 pcic_isa_bus_width_probe(sc, iot, ioh, ia->ia_iobase, ia->ia_iosize);
203 pcic_attach_sockets(sc);
204
205 config_interrupts(self, pcic_isa_config_interrupts);
206 }
207