Tue Jul 26 22:21:03 2011 UTC ()
Don't set the iobase and iosize members of pcmciabus_attach_args because
they're not used in any meaningful way.


(dyoung)
diff -r1.113 -r1.114 src/sys/dev/ic/i82365.c
diff -r1.35 -r1.36 src/sys/dev/ic/tcic2.c

cvs diff -r1.113 -r1.114 src/sys/dev/ic/i82365.c (switch to unified diff)

--- src/sys/dev/ic/i82365.c 2010/04/19 18:24:26 1.113
+++ src/sys/dev/ic/i82365.c 2011/07/26 22:21:02 1.114
@@ -1,1410 +1,1408 @@ @@ -1,1410 +1,1408 @@
1/* $NetBSD: i82365.c,v 1.113 2010/04/19 18:24:26 dyoung Exp $ */ 1/* $NetBSD: i82365.c,v 1.114 2011/07/26 22:21:02 dyoung Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2004 Charles M. Hannum. All rights reserved. 4 * Copyright (c) 2004 Charles M. Hannum. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software 14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement: 15 * must display the following acknowledgement:
16 * This product includes software developed by Charles M. Hannum. 16 * This product includes software developed by Charles M. Hannum.
17 * 4. The name of the author may not be used to endorse or promote products 17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission. 18 * derived from this software without specific prior written permission.
19 */ 19 */
20 20
21/* 21/*
22 * Copyright (c) 2000 Christian E. Hopps. All rights reserved. 22 * Copyright (c) 2000 Christian E. Hopps. All rights reserved.
23 * Copyright (c) 1997 Marc Horowitz. All rights reserved. 23 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
24 * 24 *
25 * Redistribution and use in source and binary forms, with or without 25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions 26 * modification, are permitted provided that the following conditions
27 * are met: 27 * are met:
28 * 1. Redistributions of source code must retain the above copyright 28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer. 29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright 30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the 31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution. 32 * documentation and/or other materials provided with the distribution.
33 * 3. All advertising materials mentioning features or use of this software 33 * 3. All advertising materials mentioning features or use of this software
34 * must display the following acknowledgement: 34 * must display the following acknowledgement:
35 * This product includes software developed by Marc Horowitz. 35 * This product includes software developed by Marc Horowitz.
36 * 4. The name of the author may not be used to endorse or promote products 36 * 4. The name of the author may not be used to endorse or promote products
37 * derived from this software without specific prior written permission. 37 * derived from this software without specific prior written permission.
38 * 38 *
39 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 39 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
40 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 40 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 41 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 42 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
43 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 43 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 45 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 46 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 47 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
48 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 48 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 */ 49 */
50 50
51#include <sys/cdefs.h> 51#include <sys/cdefs.h>
52__KERNEL_RCSID(0, "$NetBSD: i82365.c,v 1.113 2010/04/19 18:24:26 dyoung Exp $"); 52__KERNEL_RCSID(0, "$NetBSD: i82365.c,v 1.114 2011/07/26 22:21:02 dyoung Exp $");
53 53
54#define PCICDEBUG 54#define PCICDEBUG
55 55
56#include <sys/param.h> 56#include <sys/param.h>
57#include <sys/systm.h> 57#include <sys/systm.h>
58#include <sys/device.h> 58#include <sys/device.h>
59#include <sys/extent.h> 59#include <sys/extent.h>
60#include <sys/kernel.h> 60#include <sys/kernel.h>
61#include <sys/malloc.h> 61#include <sys/malloc.h>
62#include <sys/kthread.h> 62#include <sys/kthread.h>
63 63
64#include <sys/bus.h> 64#include <sys/bus.h>
65#include <sys/intr.h> 65#include <sys/intr.h>
66 66
67#include <dev/pcmcia/pcmciareg.h> 67#include <dev/pcmcia/pcmciareg.h>
68#include <dev/pcmcia/pcmciavar.h> 68#include <dev/pcmcia/pcmciavar.h>
69 69
70#include <dev/ic/i82365reg.h> 70#include <dev/ic/i82365reg.h>
71#include <dev/ic/i82365var.h> 71#include <dev/ic/i82365var.h>
72 72
73#include "locators.h" 73#include "locators.h"
74 74
75#ifdef PCICDEBUG 75#ifdef PCICDEBUG
76int pcic_debug = 0; 76int pcic_debug = 0;
77#define DPRINTF(arg) if (pcic_debug) printf arg; 77#define DPRINTF(arg) if (pcic_debug) printf arg;
78#else 78#else
79#define DPRINTF(arg) 79#define DPRINTF(arg)
80#endif 80#endif
81 81
82/* 82/*
83 * Individual drivers will allocate their own memory and io regions. Memory 83 * Individual drivers will allocate their own memory and io regions. Memory
84 * regions must be a multiple of 4k, aligned on a 4k boundary. 84 * regions must be a multiple of 4k, aligned on a 4k boundary.
85 */ 85 */
86 86
87#define PCIC_MEM_ALIGN PCIC_MEM_PAGESIZE 87#define PCIC_MEM_ALIGN PCIC_MEM_PAGESIZE
88 88
89void pcic_attach_socket(struct pcic_handle *); 89void pcic_attach_socket(struct pcic_handle *);
90void pcic_attach_socket_finish(struct pcic_handle *); 90void pcic_attach_socket_finish(struct pcic_handle *);
91 91
92int pcic_print (void *arg, const char *pnp); 92int pcic_print (void *arg, const char *pnp);
93int pcic_intr_socket(struct pcic_handle *); 93int pcic_intr_socket(struct pcic_handle *);
94void pcic_poll_intr(void *); 94void pcic_poll_intr(void *);
95 95
96void pcic_attach_card(struct pcic_handle *); 96void pcic_attach_card(struct pcic_handle *);
97void pcic_detach_card(struct pcic_handle *, int); 97void pcic_detach_card(struct pcic_handle *, int);
98void pcic_deactivate_card(struct pcic_handle *); 98void pcic_deactivate_card(struct pcic_handle *);
99 99
100void pcic_chip_do_mem_map(struct pcic_handle *, int); 100void pcic_chip_do_mem_map(struct pcic_handle *, int);
101void pcic_chip_do_io_map(struct pcic_handle *, int); 101void pcic_chip_do_io_map(struct pcic_handle *, int);
102 102
103void pcic_event_thread(void *); 103void pcic_event_thread(void *);
104 104
105void pcic_queue_event(struct pcic_handle *, int); 105void pcic_queue_event(struct pcic_handle *, int);
106void pcic_power(int, void *); 106void pcic_power(int, void *);
107 107
108static int pcic_wait_ready(struct pcic_handle *); 108static int pcic_wait_ready(struct pcic_handle *);
109static void pcic_delay(struct pcic_handle *, int, const char *); 109static void pcic_delay(struct pcic_handle *, int, const char *);
110 110
111static uint8_t st_pcic_read(struct pcic_handle *, int); 111static uint8_t st_pcic_read(struct pcic_handle *, int);
112static void st_pcic_write(struct pcic_handle *, int, uint8_t); 112static void st_pcic_write(struct pcic_handle *, int, uint8_t);
113 113
114int 114int
115pcic_ident_ok(int ident) 115pcic_ident_ok(int ident)
116{ 116{
117 117
118 /* this is very empirical and heuristic */ 118 /* this is very empirical and heuristic */
119 119
120 if ((ident == 0) || (ident == 0xff) || (ident & PCIC_IDENT_ZERO)) 120 if ((ident == 0) || (ident == 0xff) || (ident & PCIC_IDENT_ZERO))
121 return 0; 121 return 0;
122 122
123 if ((ident & PCIC_IDENT_REV_MASK) == 0) 123 if ((ident & PCIC_IDENT_REV_MASK) == 0)
124 return 0; 124 return 0;
125 125
126 if ((ident & PCIC_IDENT_IFTYPE_MASK) != PCIC_IDENT_IFTYPE_MEM_AND_IO) { 126 if ((ident & PCIC_IDENT_IFTYPE_MASK) != PCIC_IDENT_IFTYPE_MEM_AND_IO) {
127#ifdef DIAGNOSTIC 127#ifdef DIAGNOSTIC
128 printf("pcic: does not support memory and I/O cards, " 128 printf("pcic: does not support memory and I/O cards, "
129 "ignored (ident=%0x)\n", ident); 129 "ignored (ident=%0x)\n", ident);
130#endif 130#endif
131 return 0; 131 return 0;
132 } 132 }
133 133
134 return 1; 134 return 1;
135} 135}
136 136
137int 137int
138pcic_vendor(struct pcic_handle *h) 138pcic_vendor(struct pcic_handle *h)
139{ 139{
140 int reg; 140 int reg;
141 int vendor; 141 int vendor;
142 142
143 reg = pcic_read(h, PCIC_IDENT); 143 reg = pcic_read(h, PCIC_IDENT);
144 144
145 if ((reg & PCIC_IDENT_REV_MASK) == 0) 145 if ((reg & PCIC_IDENT_REV_MASK) == 0)
146 return PCIC_VENDOR_NONE; 146 return PCIC_VENDOR_NONE;
147 147
148 switch (reg) { 148 switch (reg) {
149 case 0x00: 149 case 0x00:
150 case 0xff: 150 case 0xff:
151 return PCIC_VENDOR_NONE; 151 return PCIC_VENDOR_NONE;
152 case PCIC_IDENT_ID_INTEL0: 152 case PCIC_IDENT_ID_INTEL0:
153 vendor = PCIC_VENDOR_I82365SLR0; 153 vendor = PCIC_VENDOR_I82365SLR0;
154 break; 154 break;
155 case PCIC_IDENT_ID_INTEL1: 155 case PCIC_IDENT_ID_INTEL1:
156 vendor = PCIC_VENDOR_I82365SLR1; 156 vendor = PCIC_VENDOR_I82365SLR1;
157 break; 157 break;
158 case PCIC_IDENT_ID_INTEL2: 158 case PCIC_IDENT_ID_INTEL2:
159 vendor = PCIC_VENDOR_I82365SL_DF; 159 vendor = PCIC_VENDOR_I82365SL_DF;
160 break; 160 break;
161 case PCIC_IDENT_ID_IBM1: 161 case PCIC_IDENT_ID_IBM1:
162 case PCIC_IDENT_ID_IBM2: 162 case PCIC_IDENT_ID_IBM2:
163 vendor = PCIC_VENDOR_IBM; 163 vendor = PCIC_VENDOR_IBM;
164 break; 164 break;
165 case PCIC_IDENT_ID_IBM3: 165 case PCIC_IDENT_ID_IBM3:
166 vendor = PCIC_VENDOR_IBM_KING; 166 vendor = PCIC_VENDOR_IBM_KING;
167 break; 167 break;
168 default: 168 default:
169 vendor = PCIC_VENDOR_UNKNOWN; 169 vendor = PCIC_VENDOR_UNKNOWN;
170 break; 170 break;
171 } 171 }
172 172
173 if (vendor == PCIC_VENDOR_I82365SLR0 || 173 if (vendor == PCIC_VENDOR_I82365SLR0 ||
174 vendor == PCIC_VENDOR_I82365SLR1) { 174 vendor == PCIC_VENDOR_I82365SLR1) {
175 /* 175 /*
176 * Check for Cirrus PD67xx. 176 * Check for Cirrus PD67xx.
177 * the chip_id of the cirrus toggles between 11 and 00 after a 177 * the chip_id of the cirrus toggles between 11 and 00 after a
178 * write. weird. 178 * write. weird.
179 */ 179 */
180 pcic_write(h, PCIC_CIRRUS_CHIP_INFO, 0); 180 pcic_write(h, PCIC_CIRRUS_CHIP_INFO, 0);
181 reg = pcic_read(h, -1); 181 reg = pcic_read(h, -1);
182 if ((reg & PCIC_CIRRUS_CHIP_INFO_CHIP_ID) == 182 if ((reg & PCIC_CIRRUS_CHIP_INFO_CHIP_ID) ==
183 PCIC_CIRRUS_CHIP_INFO_CHIP_ID) { 183 PCIC_CIRRUS_CHIP_INFO_CHIP_ID) {
184 reg = pcic_read(h, -1); 184 reg = pcic_read(h, -1);
185 if ((reg & PCIC_CIRRUS_CHIP_INFO_CHIP_ID) == 0) 185 if ((reg & PCIC_CIRRUS_CHIP_INFO_CHIP_ID) == 0)
186 return PCIC_VENDOR_CIRRUS_PD67XX; 186 return PCIC_VENDOR_CIRRUS_PD67XX;
187 } 187 }
188 188
189 /* 189 /*
190 * check for Ricoh RF5C[23]96 190 * check for Ricoh RF5C[23]96
191 */ 191 */
192 reg = pcic_read(h, PCIC_RICOH_REG_CHIP_ID); 192 reg = pcic_read(h, PCIC_RICOH_REG_CHIP_ID);
193 switch (reg) { 193 switch (reg) {
194 case PCIC_RICOH_CHIP_ID_5C296: 194 case PCIC_RICOH_CHIP_ID_5C296:
195 return PCIC_VENDOR_RICOH_5C296; 195 return PCIC_VENDOR_RICOH_5C296;
196 case PCIC_RICOH_CHIP_ID_5C396: 196 case PCIC_RICOH_CHIP_ID_5C396:
197 return PCIC_VENDOR_RICOH_5C396; 197 return PCIC_VENDOR_RICOH_5C396;
198 } 198 }
199 } 199 }
200 200
201 return vendor; 201 return vendor;
202} 202}
203 203
204const char * 204const char *
205pcic_vendor_to_string(int vendor) 205pcic_vendor_to_string(int vendor)
206{ 206{
207 207
208 switch (vendor) { 208 switch (vendor) {
209 case PCIC_VENDOR_I82365SLR0: 209 case PCIC_VENDOR_I82365SLR0:
210 return "Intel 82365SL Revision 0"; 210 return "Intel 82365SL Revision 0";
211 case PCIC_VENDOR_I82365SLR1: 211 case PCIC_VENDOR_I82365SLR1:
212 return "Intel 82365SL Revision 1"; 212 return "Intel 82365SL Revision 1";
213 case PCIC_VENDOR_CIRRUS_PD67XX: 213 case PCIC_VENDOR_CIRRUS_PD67XX:
214 return "Cirrus PD6710/2X"; 214 return "Cirrus PD6710/2X";
215 case PCIC_VENDOR_I82365SL_DF: 215 case PCIC_VENDOR_I82365SL_DF:
216 return "Intel 82365SL-DF"; 216 return "Intel 82365SL-DF";
217 case PCIC_VENDOR_RICOH_5C296: 217 case PCIC_VENDOR_RICOH_5C296:
218 return "Ricoh RF5C296"; 218 return "Ricoh RF5C296";
219 case PCIC_VENDOR_RICOH_5C396: 219 case PCIC_VENDOR_RICOH_5C396:
220 return "Ricoh RF5C396"; 220 return "Ricoh RF5C396";
221 case PCIC_VENDOR_IBM: 221 case PCIC_VENDOR_IBM:
222 return "IBM PCIC"; 222 return "IBM PCIC";
223 case PCIC_VENDOR_IBM_KING: 223 case PCIC_VENDOR_IBM_KING:
224 return "IBM KING"; 224 return "IBM KING";
225 } 225 }
226 226
227 return "Unknown controller"; 227 return "Unknown controller";
228} 228}
229 229
230void 230void
231pcic_attach(struct pcic_softc *sc) 231pcic_attach(struct pcic_softc *sc)
232{ 232{
233 int i, reg, chip, socket; 233 int i, reg, chip, socket;
234 struct pcic_handle *h; 234 struct pcic_handle *h;
235 device_t self; 235 device_t self;
236 236
237 DPRINTF(("pcic ident regs:")); 237 DPRINTF(("pcic ident regs:"));
238 238
239 self = &sc->dev; 239 self = &sc->dev;
240 mutex_init(&sc->sc_pcic_lock, MUTEX_DEFAULT, IPL_NONE); 240 mutex_init(&sc->sc_pcic_lock, MUTEX_DEFAULT, IPL_NONE);
241 241
242 /* find and configure for the available sockets */ 242 /* find and configure for the available sockets */
243 for (i = 0; i < __arraycount(sc->handle); i++) { 243 for (i = 0; i < __arraycount(sc->handle); i++) {
244 h = &sc->handle[i]; 244 h = &sc->handle[i];
245 chip = i / 2; 245 chip = i / 2;
246 socket = i % 2; 246 socket = i % 2;
247 247
248 h->ph_parent = self; 248 h->ph_parent = self;
249 h->chip = chip; 249 h->chip = chip;
250 h->socket = socket; 250 h->socket = socket;
251 h->sock = chip * PCIC_CHIP_OFFSET + socket * PCIC_SOCKET_OFFSET; 251 h->sock = chip * PCIC_CHIP_OFFSET + socket * PCIC_SOCKET_OFFSET;
252 h->laststate = PCIC_LASTSTATE_EMPTY; 252 h->laststate = PCIC_LASTSTATE_EMPTY;
253 /* initialize pcic_read and pcic_write functions */ 253 /* initialize pcic_read and pcic_write functions */
254 h->ph_read = st_pcic_read; 254 h->ph_read = st_pcic_read;
255 h->ph_write = st_pcic_write; 255 h->ph_write = st_pcic_write;
256 h->ph_bus_t = sc->iot; 256 h->ph_bus_t = sc->iot;
257 h->ph_bus_h = sc->ioh; 257 h->ph_bus_h = sc->ioh;
258 h->flags = 0; 258 h->flags = 0;
259 259
260 /* need to read vendor -- for cirrus to report no xtra chip */ 260 /* need to read vendor -- for cirrus to report no xtra chip */
261 if (socket == 0) { 261 if (socket == 0) {
262 h->vendor = pcic_vendor(h); 262 h->vendor = pcic_vendor(h);
263 if (i < __arraycount(sc->handle) - 1) 263 if (i < __arraycount(sc->handle) - 1)
264 (h + 1)->vendor = h->vendor; 264 (h + 1)->vendor = h->vendor;
265 } 265 }
266 266
267 switch (h->vendor) { 267 switch (h->vendor) {
268 case PCIC_VENDOR_NONE: 268 case PCIC_VENDOR_NONE:
269 /* no chip */ 269 /* no chip */
270 continue; 270 continue;
271 case PCIC_VENDOR_CIRRUS_PD67XX: 271 case PCIC_VENDOR_CIRRUS_PD67XX:
272 reg = pcic_read(h, PCIC_CIRRUS_CHIP_INFO); 272 reg = pcic_read(h, PCIC_CIRRUS_CHIP_INFO);
273 if (socket == 0 || 273 if (socket == 0 ||
274 (reg & PCIC_CIRRUS_CHIP_INFO_SLOTS)) 274 (reg & PCIC_CIRRUS_CHIP_INFO_SLOTS))
275 h->flags = PCIC_FLAG_SOCKETP; 275 h->flags = PCIC_FLAG_SOCKETP;
276 break; 276 break;
277 default: 277 default:
278 /* 278 /*
279 * During the socket probe, read the ident register 279 * During the socket probe, read the ident register
280 * twice. I don't understand why, but sometimes the 280 * twice. I don't understand why, but sometimes the
281 * clone chips in hpcmips boxes read all-0s the first 281 * clone chips in hpcmips boxes read all-0s the first
282 * time. -- mycroft 282 * time. -- mycroft
283 */ 283 */
284 reg = pcic_read(h, PCIC_IDENT); 284 reg = pcic_read(h, PCIC_IDENT);
285 DPRINTF(("socket %d ident reg 0x%02x\n", i, reg)); 285 DPRINTF(("socket %d ident reg 0x%02x\n", i, reg));
286 reg = pcic_read(h, PCIC_IDENT); 286 reg = pcic_read(h, PCIC_IDENT);
287 DPRINTF(("socket %d ident reg 0x%02x\n", i, reg)); 287 DPRINTF(("socket %d ident reg 0x%02x\n", i, reg));
288 if (pcic_ident_ok(reg)) 288 if (pcic_ident_ok(reg))
289 h->flags = PCIC_FLAG_SOCKETP; 289 h->flags = PCIC_FLAG_SOCKETP;
290 break; 290 break;
291 } 291 }
292 } 292 }
293 293
294 for (i = 0; i < __arraycount(sc->handle); i++) { 294 for (i = 0; i < __arraycount(sc->handle); i++) {
295 h = &sc->handle[i]; 295 h = &sc->handle[i];
296 296
297 if (h->flags & PCIC_FLAG_SOCKETP) { 297 if (h->flags & PCIC_FLAG_SOCKETP) {
298 SIMPLEQ_INIT(&h->events); 298 SIMPLEQ_INIT(&h->events);
299 299
300 /* disable interrupts and leave socket in reset */ 300 /* disable interrupts and leave socket in reset */
301 pcic_write(h, PCIC_INTR, 0); 301 pcic_write(h, PCIC_INTR, 0);
302 302
303 /* zero out the address windows */ 303 /* zero out the address windows */
304 pcic_write(h, PCIC_ADDRWIN_ENABLE, 0); 304 pcic_write(h, PCIC_ADDRWIN_ENABLE, 0);
305 305
306 /* power down the socket */ 306 /* power down the socket */
307 pcic_write(h, PCIC_PWRCTL, 0); 307 pcic_write(h, PCIC_PWRCTL, 0);
308 308
309 pcic_write(h, PCIC_CSC_INTR, 0); 309 pcic_write(h, PCIC_CSC_INTR, 0);
310 (void) pcic_read(h, PCIC_CSC); 310 (void) pcic_read(h, PCIC_CSC);
311 } 311 }
312 } 312 }
313 313
314 /* print detected info */ 314 /* print detected info */
315 for (i = 0; i < __arraycount(sc->handle) - 1; i += 2) { 315 for (i = 0; i < __arraycount(sc->handle) - 1; i += 2) {
316 h = &sc->handle[i]; 316 h = &sc->handle[i];
317 chip = i / 2; 317 chip = i / 2;
318 318
319 if (h->vendor == PCIC_VENDOR_NONE) 319 if (h->vendor == PCIC_VENDOR_NONE)
320 continue; 320 continue;
321 321
322 aprint_normal_dev(self, "controller %d (%s) has ", 322 aprint_normal_dev(self, "controller %d (%s) has ",
323 chip, pcic_vendor_to_string(sc->handle[i].vendor)); 323 chip, pcic_vendor_to_string(sc->handle[i].vendor));
324 324
325 if ((h->flags & PCIC_FLAG_SOCKETP) && 325 if ((h->flags & PCIC_FLAG_SOCKETP) &&
326 ((h + 1)->flags & PCIC_FLAG_SOCKETP)) 326 ((h + 1)->flags & PCIC_FLAG_SOCKETP))
327 aprint_normal("sockets A and B\n"); 327 aprint_normal("sockets A and B\n");
328 else if (h->flags & PCIC_FLAG_SOCKETP) 328 else if (h->flags & PCIC_FLAG_SOCKETP)
329 aprint_normal("socket A only\n"); 329 aprint_normal("socket A only\n");
330 else if ((h + 1)->flags & PCIC_FLAG_SOCKETP) 330 else if ((h + 1)->flags & PCIC_FLAG_SOCKETP)
331 aprint_normal("socket B only\n"); 331 aprint_normal("socket B only\n");
332 else 332 else
333 aprint_normal("no sockets\n"); 333 aprint_normal("no sockets\n");
334 } 334 }
335} 335}
336 336
337/* 337/*
338 * attach the sockets before we know what interrupts we have 338 * attach the sockets before we know what interrupts we have
339 */ 339 */
340void 340void
341pcic_attach_sockets(struct pcic_softc *sc) 341pcic_attach_sockets(struct pcic_softc *sc)
342{ 342{
343 int i; 343 int i;
344 344
345 for (i = 0; i < __arraycount(sc->handle); i++) 345 for (i = 0; i < __arraycount(sc->handle); i++)
346 if (sc->handle[i].flags & PCIC_FLAG_SOCKETP) 346 if (sc->handle[i].flags & PCIC_FLAG_SOCKETP)
347 pcic_attach_socket(&sc->handle[i]); 347 pcic_attach_socket(&sc->handle[i]);
348} 348}
349 349
350void 350void
351pcic_power(int why, void *arg) 351pcic_power(int why, void *arg)
352{ 352{
353 struct pcic_handle *h = arg; 353 struct pcic_handle *h = arg;
354 struct pcic_softc *sc = device_private(h->ph_parent); 354 struct pcic_softc *sc = device_private(h->ph_parent);
355 int reg; 355 int reg;
356 356
357 DPRINTF(("%s: power: why %d\n", device_xname(h->ph_parent), why)); 357 DPRINTF(("%s: power: why %d\n", device_xname(h->ph_parent), why));
358 358
359 if (h->flags & PCIC_FLAG_SOCKETP) { 359 if (h->flags & PCIC_FLAG_SOCKETP) {
360 if ((why == PWR_RESUME) && 360 if ((why == PWR_RESUME) &&
361 (pcic_read(h, PCIC_CSC_INTR) == 0)) { 361 (pcic_read(h, PCIC_CSC_INTR) == 0)) {
362#ifdef PCICDEBUG 362#ifdef PCICDEBUG
363 char bitbuf[64]; 363 char bitbuf[64];
364#endif 364#endif
365 reg = PCIC_CSC_INTR_CD_ENABLE; 365 reg = PCIC_CSC_INTR_CD_ENABLE;
366 if (sc->irq != -1) 366 if (sc->irq != -1)
367 reg |= sc->irq << PCIC_CSC_INTR_IRQ_SHIFT; 367 reg |= sc->irq << PCIC_CSC_INTR_IRQ_SHIFT;
368 pcic_write(h, PCIC_CSC_INTR, reg); 368 pcic_write(h, PCIC_CSC_INTR, reg);
369#ifdef PCICDEBUG 369#ifdef PCICDEBUG
370 snprintb(bitbuf, sizeof(bitbuf), PCIC_CSC_INTR_FORMAT, 370 snprintb(bitbuf, sizeof(bitbuf), PCIC_CSC_INTR_FORMAT,
371 pcic_read(h, PCIC_CSC_INTR)); 371 pcic_read(h, PCIC_CSC_INTR));
372#endif 372#endif
373 DPRINTF(("%s: CSC_INTR was zero; reset to %s\n", 373 DPRINTF(("%s: CSC_INTR was zero; reset to %s\n",
374 device_xname(&sc->dev), bitbuf)); 374 device_xname(&sc->dev), bitbuf));
375 } 375 }
376 376
377 /* 377 /*
378 * check for card insertion or removal during suspend period. 378 * check for card insertion or removal during suspend period.
379 * XXX: the code can't cope with card swap (remove then insert). 379 * XXX: the code can't cope with card swap (remove then insert).
380 * how can we detect such situation? 380 * how can we detect such situation?
381 */ 381 */
382 if (why == PWR_RESUME) 382 if (why == PWR_RESUME)
383 (void)pcic_intr_socket(h); 383 (void)pcic_intr_socket(h);
384 } 384 }
385} 385}
386 386
387 387
388/* 388/*
389 * attach a socket -- we don't know about irqs yet 389 * attach a socket -- we don't know about irqs yet
390 */ 390 */
391void 391void
392pcic_attach_socket(struct pcic_handle *h) 392pcic_attach_socket(struct pcic_handle *h)
393{ 393{
394 struct pcmciabus_attach_args paa; 394 struct pcmciabus_attach_args paa;
395 struct pcic_softc *sc = device_private(h->ph_parent); 395 struct pcic_softc *sc = device_private(h->ph_parent);
396 int locs[PCMCIABUSCF_NLOCS]; 396 int locs[PCMCIABUSCF_NLOCS];
397 397
398 /* initialize the rest of the handle */ 398 /* initialize the rest of the handle */
399 399
400 h->shutdown = 0; 400 h->shutdown = 0;
401 h->memalloc = 0; 401 h->memalloc = 0;
402 h->ioalloc = 0; 402 h->ioalloc = 0;
403 h->ih_irq = 0; 403 h->ih_irq = 0;
404 404
405 /* now, config one pcmcia device per socket */ 405 /* now, config one pcmcia device per socket */
406 406
407 paa.paa_busname = "pcmcia"; 407 paa.paa_busname = "pcmcia";
408 paa.pct = (pcmcia_chipset_tag_t) sc->pct; 408 paa.pct = (pcmcia_chipset_tag_t) sc->pct;
409 paa.pch = (pcmcia_chipset_handle_t) h; 409 paa.pch = (pcmcia_chipset_handle_t) h;
410 paa.iobase = sc->iobase; 
411 paa.iosize = sc->iosize; 
412 410
413 locs[PCMCIABUSCF_CONTROLLER] = h->chip; 411 locs[PCMCIABUSCF_CONTROLLER] = h->chip;
414 locs[PCMCIABUSCF_SOCKET] = h->socket; 412 locs[PCMCIABUSCF_SOCKET] = h->socket;
415 413
416 h->pcmcia = config_found_sm_loc(&sc->dev, "pcmciabus", locs, &paa, 414 h->pcmcia = config_found_sm_loc(&sc->dev, "pcmciabus", locs, &paa,
417 pcic_print, config_stdsubmatch); 415 pcic_print, config_stdsubmatch);
418 if (h->pcmcia == NULL) { 416 if (h->pcmcia == NULL) {
419 h->flags &= ~PCIC_FLAG_SOCKETP; 417 h->flags &= ~PCIC_FLAG_SOCKETP;
420 return; 418 return;
421 } 419 }
422 420
423} 421}
424 422
425/* 423/*
426 * now finish attaching the sockets, we are ready to allocate 424 * now finish attaching the sockets, we are ready to allocate
427 * interrupts 425 * interrupts
428 */ 426 */
429void 427void
430pcic_attach_sockets_finish(struct pcic_softc *sc) 428pcic_attach_sockets_finish(struct pcic_softc *sc)
431{ 429{
432 int i; 430 int i;
433 431
434 for (i = 0; i < __arraycount(sc->handle); i++) 432 for (i = 0; i < __arraycount(sc->handle); i++)
435 if (sc->handle[i].flags & PCIC_FLAG_SOCKETP) 433 if (sc->handle[i].flags & PCIC_FLAG_SOCKETP)
436 pcic_attach_socket_finish(&sc->handle[i]); 434 pcic_attach_socket_finish(&sc->handle[i]);
437} 435}
438 436
439/* 437/*
440 * finishing attaching the socket. Interrupts may now be on 438 * finishing attaching the socket. Interrupts may now be on
441 * if so expects the pcic interrupt to be blocked 439 * if so expects the pcic interrupt to be blocked
442 */ 440 */
443void 441void
444pcic_attach_socket_finish(struct pcic_handle *h) 442pcic_attach_socket_finish(struct pcic_handle *h)
445{ 443{
446 struct pcic_softc *sc = device_private(h->ph_parent); 444 struct pcic_softc *sc = device_private(h->ph_parent);
447 int reg; 445 int reg;
448 char cs[4]; 446 char cs[4];
449 447
450 DPRINTF(("%s: attach finish socket %ld\n", device_xname(h->ph_parent), 448 DPRINTF(("%s: attach finish socket %ld\n", device_xname(h->ph_parent),
451 (long) (h - &sc->handle[0]))); 449 (long) (h - &sc->handle[0])));
452 450
453 /* 451 /*
454 * Set up a powerhook to ensure it continues to interrupt on 452 * Set up a powerhook to ensure it continues to interrupt on
455 * card detect even after suspend. 453 * card detect even after suspend.
456 * (this works around a bug seen in suspend-to-disk on the 454 * (this works around a bug seen in suspend-to-disk on the
457 * Sony VAIO Z505; on resume, the CSC_INTR state is not preserved). 455 * Sony VAIO Z505; on resume, the CSC_INTR state is not preserved).
458 */ 456 */
459 powerhook_establish(device_xname(h->ph_parent), pcic_power, h); 457 powerhook_establish(device_xname(h->ph_parent), pcic_power, h);
460 458
461 /* enable interrupts on card detect, poll for them if no irq avail */ 459 /* enable interrupts on card detect, poll for them if no irq avail */
462 reg = PCIC_CSC_INTR_CD_ENABLE; 460 reg = PCIC_CSC_INTR_CD_ENABLE;
463 if (sc->irq == -1) { 461 if (sc->irq == -1) {
464 if (sc->poll_established == 0) { 462 if (sc->poll_established == 0) {
465 callout_init(&sc->poll_ch, 0); 463 callout_init(&sc->poll_ch, 0);
466 callout_reset(&sc->poll_ch, hz / 2, pcic_poll_intr, sc); 464 callout_reset(&sc->poll_ch, hz / 2, pcic_poll_intr, sc);
467 sc->poll_established = 1; 465 sc->poll_established = 1;
468 } 466 }
469 } else 467 } else
470 reg |= sc->irq << PCIC_CSC_INTR_IRQ_SHIFT; 468 reg |= sc->irq << PCIC_CSC_INTR_IRQ_SHIFT;
471 pcic_write(h, PCIC_CSC_INTR, reg); 469 pcic_write(h, PCIC_CSC_INTR, reg);
472 470
473 /* steer above mgmt interrupt to configured place */ 471 /* steer above mgmt interrupt to configured place */
474 if (sc->irq == 0) 472 if (sc->irq == 0)
475 pcic_write(h, PCIC_INTR, PCIC_INTR_ENABLE); 473 pcic_write(h, PCIC_INTR, PCIC_INTR_ENABLE);
476 474
477 /* clear possible card detect interrupt */ 475 /* clear possible card detect interrupt */
478 (void) pcic_read(h, PCIC_CSC); 476 (void) pcic_read(h, PCIC_CSC);
479 477
480 DPRINTF(("%s: attach finish vendor 0x%02x\n", 478 DPRINTF(("%s: attach finish vendor 0x%02x\n",
481 device_xname(h->ph_parent), h->vendor)); 479 device_xname(h->ph_parent), h->vendor));
482 480
483 /* unsleep the cirrus controller */ 481 /* unsleep the cirrus controller */
484 if (h->vendor == PCIC_VENDOR_CIRRUS_PD67XX) { 482 if (h->vendor == PCIC_VENDOR_CIRRUS_PD67XX) {
485 reg = pcic_read(h, PCIC_CIRRUS_MISC_CTL_2); 483 reg = pcic_read(h, PCIC_CIRRUS_MISC_CTL_2);
486 if (reg & PCIC_CIRRUS_MISC_CTL_2_SUSPEND) { 484 if (reg & PCIC_CIRRUS_MISC_CTL_2_SUSPEND) {
487 DPRINTF(("%s: socket %02x was suspended\n", 485 DPRINTF(("%s: socket %02x was suspended\n",
488 device_xname(h->ph_parent), h->sock)); 486 device_xname(h->ph_parent), h->sock));
489 reg &= ~PCIC_CIRRUS_MISC_CTL_2_SUSPEND; 487 reg &= ~PCIC_CIRRUS_MISC_CTL_2_SUSPEND;
490 pcic_write(h, PCIC_CIRRUS_MISC_CTL_2, reg); 488 pcic_write(h, PCIC_CIRRUS_MISC_CTL_2, reg);
491 } 489 }
492 } 490 }
493 491
494 /* if there's a card there, then attach it. */ 492 /* if there's a card there, then attach it. */
495 reg = pcic_read(h, PCIC_IF_STATUS); 493 reg = pcic_read(h, PCIC_IF_STATUS);
496 if ((reg & PCIC_IF_STATUS_CARDDETECT_MASK) == 494 if ((reg & PCIC_IF_STATUS_CARDDETECT_MASK) ==
497 PCIC_IF_STATUS_CARDDETECT_PRESENT) { 495 PCIC_IF_STATUS_CARDDETECT_PRESENT) {
498 pcic_queue_event(h, PCIC_EVENT_INSERTION); 496 pcic_queue_event(h, PCIC_EVENT_INSERTION);
499 h->laststate = PCIC_LASTSTATE_PRESENT; 497 h->laststate = PCIC_LASTSTATE_PRESENT;
500 } else { 498 } else {
501 h->laststate = PCIC_LASTSTATE_EMPTY; 499 h->laststate = PCIC_LASTSTATE_EMPTY;
502 } 500 }
503 501
504 /* 502 /*
505 * queue creation of a kernel thread to handle insert/removal events. 503 * queue creation of a kernel thread to handle insert/removal events.
506 */ 504 */
507#ifdef DIAGNOSTIC 505#ifdef DIAGNOSTIC
508 if (h->event_thread != NULL) 506 if (h->event_thread != NULL)
509 panic("pcic_attach_socket: event thread"); 507 panic("pcic_attach_socket: event thread");
510#endif 508#endif
511 config_pending_incr(); 509 config_pending_incr();
512 snprintf(cs, sizeof(cs), "%d,%d", h->chip, h->socket); 510 snprintf(cs, sizeof(cs), "%d,%d", h->chip, h->socket);
513 511
514 if (kthread_create(PRI_NONE, 0, NULL, pcic_event_thread, h, 512 if (kthread_create(PRI_NONE, 0, NULL, pcic_event_thread, h,
515 &h->event_thread, "%s,%s", device_xname(h->ph_parent), cs)) { 513 &h->event_thread, "%s,%s", device_xname(h->ph_parent), cs)) {
516 aprint_error_dev(h->ph_parent, 514 aprint_error_dev(h->ph_parent,
517 "unable to create event thread for sock 0x%02x\n", h->sock); 515 "unable to create event thread for sock 0x%02x\n", h->sock);
518 panic("pcic_attach_socket"); 516 panic("pcic_attach_socket");
519 } 517 }
520} 518}
521 519
522void 520void
523pcic_event_thread(void *arg) 521pcic_event_thread(void *arg)
524{ 522{
525 struct pcic_handle *h = arg; 523 struct pcic_handle *h = arg;
526 struct pcic_event *pe; 524 struct pcic_event *pe;
527 int s, first = 1; 525 int s, first = 1;
528 struct pcic_softc *sc = device_private(h->ph_parent); 526 struct pcic_softc *sc = device_private(h->ph_parent);
529 527
530 while (h->shutdown == 0) { 528 while (h->shutdown == 0) {
531 /* 529 /*
532 * Serialize event processing on the PCIC. We may 530 * Serialize event processing on the PCIC. We may
533 * sleep while we hold this lock. 531 * sleep while we hold this lock.
534 */ 532 */
535 mutex_enter(&sc->sc_pcic_lock); 533 mutex_enter(&sc->sc_pcic_lock);
536 534
537 s = splhigh(); 535 s = splhigh();
538 if ((pe = SIMPLEQ_FIRST(&h->events)) == NULL) { 536 if ((pe = SIMPLEQ_FIRST(&h->events)) == NULL) {
539 splx(s); 537 splx(s);
540 if (first) { 538 if (first) {
541 first = 0; 539 first = 0;
542 config_pending_decr(); 540 config_pending_decr();
543 } 541 }
544 /* 542 /*
545 * No events to process; release the PCIC lock. 543 * No events to process; release the PCIC lock.
546 */ 544 */
547 (void) mutex_exit(&sc->sc_pcic_lock); 545 (void) mutex_exit(&sc->sc_pcic_lock);
548 (void) tsleep(&h->events, PWAIT, "pcicev", 0); 546 (void) tsleep(&h->events, PWAIT, "pcicev", 0);
549 continue; 547 continue;
550 } else { 548 } else {
551 splx(s); 549 splx(s);
552 /* sleep .25s to be enqueued chatterling interrupts */ 550 /* sleep .25s to be enqueued chatterling interrupts */
553 (void) tsleep((void *)pcic_event_thread, PWAIT, 551 (void) tsleep((void *)pcic_event_thread, PWAIT,
554 "pcicss", hz / 4); 552 "pcicss", hz / 4);
555 } 553 }
556 s = splhigh(); 554 s = splhigh();
557 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q); 555 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
558 splx(s); 556 splx(s);
559 557
560 switch (pe->pe_type) { 558 switch (pe->pe_type) {
561 case PCIC_EVENT_INSERTION: 559 case PCIC_EVENT_INSERTION:
562 s = splhigh(); 560 s = splhigh();
563 for (;;) { 561 for (;;) {
564 struct pcic_event *pe1, *pe2; 562 struct pcic_event *pe1, *pe2;
565 563
566 if ((pe1 = SIMPLEQ_FIRST(&h->events)) == NULL) 564 if ((pe1 = SIMPLEQ_FIRST(&h->events)) == NULL)
567 break; 565 break;
568 if (pe1->pe_type != PCIC_EVENT_REMOVAL) 566 if (pe1->pe_type != PCIC_EVENT_REMOVAL)
569 break; 567 break;
570 if ((pe2 = SIMPLEQ_NEXT(pe1, pe_q)) == NULL) 568 if ((pe2 = SIMPLEQ_NEXT(pe1, pe_q)) == NULL)
571 break; 569 break;
572 if (pe2->pe_type == PCIC_EVENT_INSERTION) { 570 if (pe2->pe_type == PCIC_EVENT_INSERTION) {
573 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q); 571 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
574 free(pe1, M_TEMP); 572 free(pe1, M_TEMP);
575 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q); 573 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
576 free(pe2, M_TEMP); 574 free(pe2, M_TEMP);
577 } 575 }
578 } 576 }
579 splx(s); 577 splx(s);
580 578
581 DPRINTF(("%s: insertion event\n", 579 DPRINTF(("%s: insertion event\n",
582 device_xname(h->ph_parent))); 580 device_xname(h->ph_parent)));
583 pcic_attach_card(h); 581 pcic_attach_card(h);
584 break; 582 break;
585 583
586 case PCIC_EVENT_REMOVAL: 584 case PCIC_EVENT_REMOVAL:
587 s = splhigh(); 585 s = splhigh();
588 for (;;) { 586 for (;;) {
589 struct pcic_event *pe1, *pe2; 587 struct pcic_event *pe1, *pe2;
590 588
591 if ((pe1 = SIMPLEQ_FIRST(&h->events)) == NULL) 589 if ((pe1 = SIMPLEQ_FIRST(&h->events)) == NULL)
592 break; 590 break;
593 if (pe1->pe_type != PCIC_EVENT_INSERTION) 591 if (pe1->pe_type != PCIC_EVENT_INSERTION)
594 break; 592 break;
595 if ((pe2 = SIMPLEQ_NEXT(pe1, pe_q)) == NULL) 593 if ((pe2 = SIMPLEQ_NEXT(pe1, pe_q)) == NULL)
596 break; 594 break;
597 if (pe2->pe_type == PCIC_EVENT_REMOVAL) { 595 if (pe2->pe_type == PCIC_EVENT_REMOVAL) {
598 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q); 596 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
599 free(pe1, M_TEMP); 597 free(pe1, M_TEMP);
600 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q); 598 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
601 free(pe2, M_TEMP); 599 free(pe2, M_TEMP);
602 } 600 }
603 } 601 }
604 splx(s); 602 splx(s);
605 603
606 DPRINTF(("%s: removal event\n", 604 DPRINTF(("%s: removal event\n",
607 device_xname(h->ph_parent))); 605 device_xname(h->ph_parent)));
608 pcic_detach_card(h, DETACH_FORCE); 606 pcic_detach_card(h, DETACH_FORCE);
609 break; 607 break;
610 608
611 default: 609 default:
612 panic("pcic_event_thread: unknown event %d", 610 panic("pcic_event_thread: unknown event %d",
613 pe->pe_type); 611 pe->pe_type);
614 } 612 }
615 free(pe, M_TEMP); 613 free(pe, M_TEMP);
616 614
617 mutex_exit(&sc->sc_pcic_lock); 615 mutex_exit(&sc->sc_pcic_lock);
618 } 616 }
619 617
620 h->event_thread = NULL; 618 h->event_thread = NULL;
621 619
622 /* In case parent is waiting for us to exit. */ 620 /* In case parent is waiting for us to exit. */
623 wakeup(sc); 621 wakeup(sc);
624 622
625 kthread_exit(0); 623 kthread_exit(0);
626} 624}
627 625
628int 626int
629pcic_print(void *arg, const char *pnp) 627pcic_print(void *arg, const char *pnp)
630{ 628{
631 struct pcmciabus_attach_args *paa = arg; 629 struct pcmciabus_attach_args *paa = arg;
632 struct pcic_handle *h = (struct pcic_handle *) paa->pch; 630 struct pcic_handle *h = (struct pcic_handle *) paa->pch;
633 631
634 /* Only "pcmcia"s can attach to "pcic"s... easy. */ 632 /* Only "pcmcia"s can attach to "pcic"s... easy. */
635 if (pnp) 633 if (pnp)
636 aprint_normal("pcmcia at %s", pnp); 634 aprint_normal("pcmcia at %s", pnp);
637 635
638 aprint_normal(" controller %d socket %d", h->chip, h->socket); 636 aprint_normal(" controller %d socket %d", h->chip, h->socket);
639 637
640 return UNCONF; 638 return UNCONF;
641} 639}
642 640
643void 641void
644pcic_poll_intr(void *arg) 642pcic_poll_intr(void *arg)
645{ 643{
646 struct pcic_softc *sc; 644 struct pcic_softc *sc;
647 int i, s; 645 int i, s;
648 646
649 s = spltty(); 647 s = spltty();
650 sc = arg; 648 sc = arg;
651 for (i = 0; i < __arraycount(sc->handle); i++) 649 for (i = 0; i < __arraycount(sc->handle); i++)
652 if (sc->handle[i].flags & PCIC_FLAG_SOCKETP) 650 if (sc->handle[i].flags & PCIC_FLAG_SOCKETP)
653 (void)pcic_intr_socket(&sc->handle[i]); 651 (void)pcic_intr_socket(&sc->handle[i]);
654 callout_reset(&sc->poll_ch, hz / 2, pcic_poll_intr, sc); 652 callout_reset(&sc->poll_ch, hz / 2, pcic_poll_intr, sc);
655 splx(s); 653 splx(s);
656} 654}
657 655
658int 656int
659pcic_intr(void *arg) 657pcic_intr(void *arg)
660{ 658{
661 struct pcic_softc *sc = arg; 659 struct pcic_softc *sc = arg;
662 int i, ret = 0; 660 int i, ret = 0;
663 661
664 DPRINTF(("%s: intr\n", device_xname(&sc->dev))); 662 DPRINTF(("%s: intr\n", device_xname(&sc->dev)));
665 663
666 for (i = 0; i < __arraycount(sc->handle); i++) 664 for (i = 0; i < __arraycount(sc->handle); i++)
667 if (sc->handle[i].flags & PCIC_FLAG_SOCKETP) 665 if (sc->handle[i].flags & PCIC_FLAG_SOCKETP)
668 ret += pcic_intr_socket(&sc->handle[i]); 666 ret += pcic_intr_socket(&sc->handle[i]);
669 667
670 return ret ? 1 : 0; 668 return ret ? 1 : 0;
671} 669}
672 670
673int 671int
674pcic_intr_socket(struct pcic_handle *h) 672pcic_intr_socket(struct pcic_handle *h)
675{ 673{
676 int cscreg; 674 int cscreg;
677 675
678 cscreg = pcic_read(h, PCIC_CSC); 676 cscreg = pcic_read(h, PCIC_CSC);
679 677
680 cscreg &= (PCIC_CSC_GPI | 678 cscreg &= (PCIC_CSC_GPI |
681 PCIC_CSC_CD | 679 PCIC_CSC_CD |
682 PCIC_CSC_READY | 680 PCIC_CSC_READY |
683 PCIC_CSC_BATTWARN | 681 PCIC_CSC_BATTWARN |
684 PCIC_CSC_BATTDEAD); 682 PCIC_CSC_BATTDEAD);
685 683
686 if (cscreg & PCIC_CSC_GPI) { 684 if (cscreg & PCIC_CSC_GPI) {
687 DPRINTF(("%s: %02x GPI\n", 685 DPRINTF(("%s: %02x GPI\n",
688 device_xname(h->ph_parent), h->sock)); 686 device_xname(h->ph_parent), h->sock));
689 } 687 }
690 if (cscreg & PCIC_CSC_CD) { 688 if (cscreg & PCIC_CSC_CD) {
691 int statreg; 689 int statreg;
692 690
693 statreg = pcic_read(h, PCIC_IF_STATUS); 691 statreg = pcic_read(h, PCIC_IF_STATUS);
694 692
695 DPRINTF(("%s: %02x CD %x\n", device_xname(h->ph_parent), 693 DPRINTF(("%s: %02x CD %x\n", device_xname(h->ph_parent),
696 h->sock, statreg)); 694 h->sock, statreg));
697 695
698 if ((statreg & PCIC_IF_STATUS_CARDDETECT_MASK) == 696 if ((statreg & PCIC_IF_STATUS_CARDDETECT_MASK) ==
699 PCIC_IF_STATUS_CARDDETECT_PRESENT) { 697 PCIC_IF_STATUS_CARDDETECT_PRESENT) {
700 if (h->laststate != PCIC_LASTSTATE_PRESENT) { 698 if (h->laststate != PCIC_LASTSTATE_PRESENT) {
701 DPRINTF(("%s: enqueing INSERTION event\n", 699 DPRINTF(("%s: enqueing INSERTION event\n",
702 device_xname(h->ph_parent))); 700 device_xname(h->ph_parent)));
703 pcic_queue_event(h, PCIC_EVENT_INSERTION); 701 pcic_queue_event(h, PCIC_EVENT_INSERTION);
704 } 702 }
705 h->laststate = PCIC_LASTSTATE_PRESENT; 703 h->laststate = PCIC_LASTSTATE_PRESENT;
706 } else { 704 } else {
707 if (h->laststate == PCIC_LASTSTATE_PRESENT) { 705 if (h->laststate == PCIC_LASTSTATE_PRESENT) {
708 /* Deactivate the card now. */ 706 /* Deactivate the card now. */
709 DPRINTF(("%s: deactivating card\n", 707 DPRINTF(("%s: deactivating card\n",
710 device_xname(h->ph_parent))); 708 device_xname(h->ph_parent)));
711 pcic_deactivate_card(h); 709 pcic_deactivate_card(h);
712 710
713 DPRINTF(("%s: enqueing REMOVAL event\n", 711 DPRINTF(("%s: enqueing REMOVAL event\n",
714 device_xname(h->ph_parent))); 712 device_xname(h->ph_parent)));
715 pcic_queue_event(h, PCIC_EVENT_REMOVAL); 713 pcic_queue_event(h, PCIC_EVENT_REMOVAL);
716 } 714 }
717 h->laststate = PCIC_LASTSTATE_EMPTY; 715 h->laststate = PCIC_LASTSTATE_EMPTY;
718 } 716 }
719 } 717 }
720 if (cscreg & PCIC_CSC_READY) { 718 if (cscreg & PCIC_CSC_READY) {
721 DPRINTF(("%s: %02x READY\n", device_xname(h->ph_parent), 719 DPRINTF(("%s: %02x READY\n", device_xname(h->ph_parent),
722 h->sock)); 720 h->sock));
723 /* shouldn't happen */ 721 /* shouldn't happen */
724 } 722 }
725 if (cscreg & PCIC_CSC_BATTWARN) { 723 if (cscreg & PCIC_CSC_BATTWARN) {
726 DPRINTF(("%s: %02x BATTWARN\n", device_xname(h->ph_parent), 724 DPRINTF(("%s: %02x BATTWARN\n", device_xname(h->ph_parent),
727 h->sock)); 725 h->sock));
728 } 726 }
729 if (cscreg & PCIC_CSC_BATTDEAD) { 727 if (cscreg & PCIC_CSC_BATTDEAD) {
730 DPRINTF(("%s: %02x BATTDEAD\n", device_xname(h->ph_parent), 728 DPRINTF(("%s: %02x BATTDEAD\n", device_xname(h->ph_parent),
731 h->sock)); 729 h->sock));
732 } 730 }
733 return cscreg ? 1 : 0; 731 return cscreg ? 1 : 0;
734} 732}
735 733
736void 734void
737pcic_queue_event(struct pcic_handle *h, int event) 735pcic_queue_event(struct pcic_handle *h, int event)
738{ 736{
739 struct pcic_event *pe; 737 struct pcic_event *pe;
740 int s; 738 int s;
741 739
742 pe = malloc(sizeof(*pe), M_TEMP, M_NOWAIT); 740 pe = malloc(sizeof(*pe), M_TEMP, M_NOWAIT);
743 if (pe == NULL) 741 if (pe == NULL)
744 panic("pcic_queue_event: can't allocate event"); 742 panic("pcic_queue_event: can't allocate event");
745 743
746 pe->pe_type = event; 744 pe->pe_type = event;
747 s = splhigh(); 745 s = splhigh();
748 SIMPLEQ_INSERT_TAIL(&h->events, pe, pe_q); 746 SIMPLEQ_INSERT_TAIL(&h->events, pe, pe_q);
749 splx(s); 747 splx(s);
750 wakeup(&h->events); 748 wakeup(&h->events);
751} 749}
752 750
753void 751void
754pcic_attach_card(struct pcic_handle *h) 752pcic_attach_card(struct pcic_handle *h)
755{ 753{
756 754
757 if ((h->flags & PCIC_FLAG_CARDP) == 0) { 755 if ((h->flags & PCIC_FLAG_CARDP) == 0) {
758 /* call the MI attach function */ 756 /* call the MI attach function */
759 pcmcia_card_attach(h->pcmcia); 757 pcmcia_card_attach(h->pcmcia);
760 758
761 h->flags |= PCIC_FLAG_CARDP; 759 h->flags |= PCIC_FLAG_CARDP;
762 } else { 760 } else {
763 DPRINTF(("pcic_attach_card: already attached")); 761 DPRINTF(("pcic_attach_card: already attached"));
764 } 762 }
765} 763}
766 764
767void 765void
768pcic_detach_card(struct pcic_handle *h, int flags) 766pcic_detach_card(struct pcic_handle *h, int flags)
769 /* flags: DETACH_* */ 767 /* flags: DETACH_* */
770{ 768{
771 769
772 if (h->flags & PCIC_FLAG_CARDP) { 770 if (h->flags & PCIC_FLAG_CARDP) {
773 h->flags &= ~PCIC_FLAG_CARDP; 771 h->flags &= ~PCIC_FLAG_CARDP;
774 772
775 /* call the MI detach function */ 773 /* call the MI detach function */
776 pcmcia_card_detach(h->pcmcia, flags); 774 pcmcia_card_detach(h->pcmcia, flags);
777 } else { 775 } else {
778 DPRINTF(("pcic_detach_card: already detached")); 776 DPRINTF(("pcic_detach_card: already detached"));
779 } 777 }
780} 778}
781 779
782void 780void
783pcic_deactivate_card(struct pcic_handle *h) 781pcic_deactivate_card(struct pcic_handle *h)
784{ 782{
785 int intr; 783 int intr;
786 784
787 /* call the MI deactivate function */ 785 /* call the MI deactivate function */
788 pcmcia_card_deactivate(h->pcmcia); 786 pcmcia_card_deactivate(h->pcmcia);
789 787
790 /* reset the socket */ 788 /* reset the socket */
791 intr = pcic_read(h, PCIC_INTR); 789 intr = pcic_read(h, PCIC_INTR);
792 intr &= PCIC_INTR_ENABLE; 790 intr &= PCIC_INTR_ENABLE;
793 pcic_write(h, PCIC_INTR, intr); 791 pcic_write(h, PCIC_INTR, intr);
794 792
795 /* power down the socket */ 793 /* power down the socket */
796 pcic_write(h, PCIC_PWRCTL, 0); 794 pcic_write(h, PCIC_PWRCTL, 0);
797} 795}
798 796
799int 797int
800pcic_chip_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size, 798pcic_chip_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size,
801 struct pcmcia_mem_handle *pcmhp) 799 struct pcmcia_mem_handle *pcmhp)
802{ 800{
803 struct pcic_handle *h = (struct pcic_handle *) pch; 801 struct pcic_handle *h = (struct pcic_handle *) pch;
804 bus_space_handle_t memh; 802 bus_space_handle_t memh;
805 bus_addr_t addr; 803 bus_addr_t addr;
806 bus_size_t sizepg; 804 bus_size_t sizepg;
807 int i, mask, mhandle; 805 int i, mask, mhandle;
808 struct pcic_softc *sc = device_private(h->ph_parent); 806 struct pcic_softc *sc = device_private(h->ph_parent);
809 807
810 /* out of sc->memh, allocate as many pages as necessary */ 808 /* out of sc->memh, allocate as many pages as necessary */
811 809
812 /* convert size to PCIC pages */ 810 /* convert size to PCIC pages */
813 sizepg = (size + (PCIC_MEM_ALIGN - 1)) / PCIC_MEM_ALIGN; 811 sizepg = (size + (PCIC_MEM_ALIGN - 1)) / PCIC_MEM_ALIGN;
814 if (sizepg > PCIC_MAX_MEM_PAGES) 812 if (sizepg > PCIC_MAX_MEM_PAGES)
815 return 1; 813 return 1;
816 814
817 mask = (1 << sizepg) - 1; 815 mask = (1 << sizepg) - 1;
818 816
819 addr = 0; /* XXX gcc -Wuninitialized */ 817 addr = 0; /* XXX gcc -Wuninitialized */
820 mhandle = 0; /* XXX gcc -Wuninitialized */ 818 mhandle = 0; /* XXX gcc -Wuninitialized */
821 819
822 for (i = 0; i <= PCIC_MAX_MEM_PAGES - sizepg; i++) { 820 for (i = 0; i <= PCIC_MAX_MEM_PAGES - sizepg; i++) {
823 if ((sc->subregionmask & (mask << i)) == (mask << i)) { 821 if ((sc->subregionmask & (mask << i)) == (mask << i)) {
824 if (bus_space_subregion(sc->memt, sc->memh, 822 if (bus_space_subregion(sc->memt, sc->memh,
825 i * PCIC_MEM_PAGESIZE, 823 i * PCIC_MEM_PAGESIZE,
826 sizepg * PCIC_MEM_PAGESIZE, &memh)) 824 sizepg * PCIC_MEM_PAGESIZE, &memh))
827 return 1; 825 return 1;
828 mhandle = mask << i; 826 mhandle = mask << i;
829 addr = sc->membase + (i * PCIC_MEM_PAGESIZE); 827 addr = sc->membase + (i * PCIC_MEM_PAGESIZE);
830 sc->subregionmask &= ~(mhandle); 828 sc->subregionmask &= ~(mhandle);
831 pcmhp->memt = sc->memt; 829 pcmhp->memt = sc->memt;
832 pcmhp->memh = memh; 830 pcmhp->memh = memh;
833 pcmhp->addr = addr; 831 pcmhp->addr = addr;
834 pcmhp->size = size; 832 pcmhp->size = size;
835 pcmhp->mhandle = mhandle; 833 pcmhp->mhandle = mhandle;
836 pcmhp->realsize = sizepg * PCIC_MEM_PAGESIZE; 834 pcmhp->realsize = sizepg * PCIC_MEM_PAGESIZE;
837 return 0; 835 return 0;
838 } 836 }
839 } 837 }
840 838
841 return 1; 839 return 1;
842} 840}
843 841
844void 842void
845pcic_chip_mem_free(pcmcia_chipset_handle_t pch, struct pcmcia_mem_handle *pcmhp) 843pcic_chip_mem_free(pcmcia_chipset_handle_t pch, struct pcmcia_mem_handle *pcmhp)
846{ 844{
847 struct pcic_handle *h = (struct pcic_handle *) pch; 845 struct pcic_handle *h = (struct pcic_handle *) pch;
848 struct pcic_softc *sc = device_private(h->ph_parent); 846 struct pcic_softc *sc = device_private(h->ph_parent);
849 847
850 sc->subregionmask |= pcmhp->mhandle; 848 sc->subregionmask |= pcmhp->mhandle;
851} 849}
852 850
853static const struct mem_map_index_st { 851static const struct mem_map_index_st {
854 int sysmem_start_lsb; 852 int sysmem_start_lsb;
855 int sysmem_start_msb; 853 int sysmem_start_msb;
856 int sysmem_stop_lsb; 854 int sysmem_stop_lsb;
857 int sysmem_stop_msb; 855 int sysmem_stop_msb;
858 int cardmem_lsb; 856 int cardmem_lsb;
859 int cardmem_msb; 857 int cardmem_msb;
860 int memenable; 858 int memenable;
861} mem_map_index[] = { 859} mem_map_index[] = {
862 { 860 {
863 PCIC_SYSMEM_ADDR0_START_LSB, 861 PCIC_SYSMEM_ADDR0_START_LSB,
864 PCIC_SYSMEM_ADDR0_START_MSB, 862 PCIC_SYSMEM_ADDR0_START_MSB,
865 PCIC_SYSMEM_ADDR0_STOP_LSB, 863 PCIC_SYSMEM_ADDR0_STOP_LSB,
866 PCIC_SYSMEM_ADDR0_STOP_MSB, 864 PCIC_SYSMEM_ADDR0_STOP_MSB,
867 PCIC_CARDMEM_ADDR0_LSB, 865 PCIC_CARDMEM_ADDR0_LSB,
868 PCIC_CARDMEM_ADDR0_MSB, 866 PCIC_CARDMEM_ADDR0_MSB,
869 PCIC_ADDRWIN_ENABLE_MEM0, 867 PCIC_ADDRWIN_ENABLE_MEM0,
870 }, 868 },
871 { 869 {
872 PCIC_SYSMEM_ADDR1_START_LSB, 870 PCIC_SYSMEM_ADDR1_START_LSB,
873 PCIC_SYSMEM_ADDR1_START_MSB, 871 PCIC_SYSMEM_ADDR1_START_MSB,
874 PCIC_SYSMEM_ADDR1_STOP_LSB, 872 PCIC_SYSMEM_ADDR1_STOP_LSB,
875 PCIC_SYSMEM_ADDR1_STOP_MSB, 873 PCIC_SYSMEM_ADDR1_STOP_MSB,
876 PCIC_CARDMEM_ADDR1_LSB, 874 PCIC_CARDMEM_ADDR1_LSB,
877 PCIC_CARDMEM_ADDR1_MSB, 875 PCIC_CARDMEM_ADDR1_MSB,
878 PCIC_ADDRWIN_ENABLE_MEM1, 876 PCIC_ADDRWIN_ENABLE_MEM1,
879 }, 877 },
880 { 878 {
881 PCIC_SYSMEM_ADDR2_START_LSB, 879 PCIC_SYSMEM_ADDR2_START_LSB,
882 PCIC_SYSMEM_ADDR2_START_MSB, 880 PCIC_SYSMEM_ADDR2_START_MSB,
883 PCIC_SYSMEM_ADDR2_STOP_LSB, 881 PCIC_SYSMEM_ADDR2_STOP_LSB,
884 PCIC_SYSMEM_ADDR2_STOP_MSB, 882 PCIC_SYSMEM_ADDR2_STOP_MSB,
885 PCIC_CARDMEM_ADDR2_LSB, 883 PCIC_CARDMEM_ADDR2_LSB,
886 PCIC_CARDMEM_ADDR2_MSB, 884 PCIC_CARDMEM_ADDR2_MSB,
887 PCIC_ADDRWIN_ENABLE_MEM2, 885 PCIC_ADDRWIN_ENABLE_MEM2,
888 }, 886 },
889 { 887 {
890 PCIC_SYSMEM_ADDR3_START_LSB, 888 PCIC_SYSMEM_ADDR3_START_LSB,
891 PCIC_SYSMEM_ADDR3_START_MSB, 889 PCIC_SYSMEM_ADDR3_START_MSB,
892 PCIC_SYSMEM_ADDR3_STOP_LSB, 890 PCIC_SYSMEM_ADDR3_STOP_LSB,
893 PCIC_SYSMEM_ADDR3_STOP_MSB, 891 PCIC_SYSMEM_ADDR3_STOP_MSB,
894 PCIC_CARDMEM_ADDR3_LSB, 892 PCIC_CARDMEM_ADDR3_LSB,
895 PCIC_CARDMEM_ADDR3_MSB, 893 PCIC_CARDMEM_ADDR3_MSB,
896 PCIC_ADDRWIN_ENABLE_MEM3, 894 PCIC_ADDRWIN_ENABLE_MEM3,
897 }, 895 },
898 { 896 {
899 PCIC_SYSMEM_ADDR4_START_LSB, 897 PCIC_SYSMEM_ADDR4_START_LSB,
900 PCIC_SYSMEM_ADDR4_START_MSB, 898 PCIC_SYSMEM_ADDR4_START_MSB,
901 PCIC_SYSMEM_ADDR4_STOP_LSB, 899 PCIC_SYSMEM_ADDR4_STOP_LSB,
902 PCIC_SYSMEM_ADDR4_STOP_MSB, 900 PCIC_SYSMEM_ADDR4_STOP_MSB,
903 PCIC_CARDMEM_ADDR4_LSB, 901 PCIC_CARDMEM_ADDR4_LSB,
904 PCIC_CARDMEM_ADDR4_MSB, 902 PCIC_CARDMEM_ADDR4_MSB,
905 PCIC_ADDRWIN_ENABLE_MEM4, 903 PCIC_ADDRWIN_ENABLE_MEM4,
906 }, 904 },
907}; 905};
908 906
909void 907void
910pcic_chip_do_mem_map(struct pcic_handle *h, int win) 908pcic_chip_do_mem_map(struct pcic_handle *h, int win)
911{ 909{
912 int reg; 910 int reg;
913 int kind = h->mem[win].kind & ~PCMCIA_WIDTH_MEM_MASK; 911 int kind = h->mem[win].kind & ~PCMCIA_WIDTH_MEM_MASK;
914 int mem8 = 912 int mem8 =
915 (h->mem[win].kind & PCMCIA_WIDTH_MEM_MASK) == PCMCIA_WIDTH_MEM8 913 (h->mem[win].kind & PCMCIA_WIDTH_MEM_MASK) == PCMCIA_WIDTH_MEM8
916 || (kind == PCMCIA_MEM_ATTR); 914 || (kind == PCMCIA_MEM_ATTR);
917 915
918 DPRINTF(("mem8 %d\n", mem8)); 916 DPRINTF(("mem8 %d\n", mem8));
919 /* mem8 = 1; */ 917 /* mem8 = 1; */
920 918
921 pcic_write(h, mem_map_index[win].sysmem_start_lsb, 919 pcic_write(h, mem_map_index[win].sysmem_start_lsb,
922 (h->mem[win].addr >> PCIC_SYSMEM_ADDRX_SHIFT) & 0xff); 920 (h->mem[win].addr >> PCIC_SYSMEM_ADDRX_SHIFT) & 0xff);
923 pcic_write(h, mem_map_index[win].sysmem_start_msb, 921 pcic_write(h, mem_map_index[win].sysmem_start_msb,
924 ((h->mem[win].addr >> (PCIC_SYSMEM_ADDRX_SHIFT + 8)) & 922 ((h->mem[win].addr >> (PCIC_SYSMEM_ADDRX_SHIFT + 8)) &
925 PCIC_SYSMEM_ADDRX_START_MSB_ADDR_MASK) | 923 PCIC_SYSMEM_ADDRX_START_MSB_ADDR_MASK) |
926 (mem8 ? 0 : PCIC_SYSMEM_ADDRX_START_MSB_DATASIZE_16BIT)); 924 (mem8 ? 0 : PCIC_SYSMEM_ADDRX_START_MSB_DATASIZE_16BIT));
927 925
928 pcic_write(h, mem_map_index[win].sysmem_stop_lsb, 926 pcic_write(h, mem_map_index[win].sysmem_stop_lsb,
929 ((h->mem[win].addr + h->mem[win].size) >> 927 ((h->mem[win].addr + h->mem[win].size) >>
930 PCIC_SYSMEM_ADDRX_SHIFT) & 0xff); 928 PCIC_SYSMEM_ADDRX_SHIFT) & 0xff);
931 pcic_write(h, mem_map_index[win].sysmem_stop_msb, 929 pcic_write(h, mem_map_index[win].sysmem_stop_msb,
932 (((h->mem[win].addr + h->mem[win].size) >> 930 (((h->mem[win].addr + h->mem[win].size) >>
933 (PCIC_SYSMEM_ADDRX_SHIFT + 8)) & 931 (PCIC_SYSMEM_ADDRX_SHIFT + 8)) &
934 PCIC_SYSMEM_ADDRX_STOP_MSB_ADDR_MASK) | 932 PCIC_SYSMEM_ADDRX_STOP_MSB_ADDR_MASK) |
935 PCIC_SYSMEM_ADDRX_STOP_MSB_WAIT2); 933 PCIC_SYSMEM_ADDRX_STOP_MSB_WAIT2);
936 934
937 pcic_write(h, mem_map_index[win].cardmem_lsb, 935 pcic_write(h, mem_map_index[win].cardmem_lsb,
938 (h->mem[win].offset >> PCIC_CARDMEM_ADDRX_SHIFT) & 0xff); 936 (h->mem[win].offset >> PCIC_CARDMEM_ADDRX_SHIFT) & 0xff);
939 pcic_write(h, mem_map_index[win].cardmem_msb, 937 pcic_write(h, mem_map_index[win].cardmem_msb,
940 ((h->mem[win].offset >> (PCIC_CARDMEM_ADDRX_SHIFT + 8)) & 938 ((h->mem[win].offset >> (PCIC_CARDMEM_ADDRX_SHIFT + 8)) &
941 PCIC_CARDMEM_ADDRX_MSB_ADDR_MASK) | 939 PCIC_CARDMEM_ADDRX_MSB_ADDR_MASK) |
942 ((kind == PCMCIA_MEM_ATTR) ? 940 ((kind == PCMCIA_MEM_ATTR) ?
943 PCIC_CARDMEM_ADDRX_MSB_REGACTIVE_ATTR : 0)); 941 PCIC_CARDMEM_ADDRX_MSB_REGACTIVE_ATTR : 0));
944 942
945 reg = pcic_read(h, PCIC_ADDRWIN_ENABLE); 943 reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
946 reg |= (mem_map_index[win].memenable | PCIC_ADDRWIN_ENABLE_MEMCS16); 944 reg |= (mem_map_index[win].memenable | PCIC_ADDRWIN_ENABLE_MEMCS16);
947 pcic_write(h, PCIC_ADDRWIN_ENABLE, reg); 945 pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
948 946
949 delay(100); 947 delay(100);
950 948
951#ifdef PCICDEBUG 949#ifdef PCICDEBUG
952 { 950 {
953 int r1, r2, r3, r4, r5, r6; 951 int r1, r2, r3, r4, r5, r6;
954 952
955 r1 = pcic_read(h, mem_map_index[win].sysmem_start_msb); 953 r1 = pcic_read(h, mem_map_index[win].sysmem_start_msb);
956 r2 = pcic_read(h, mem_map_index[win].sysmem_start_lsb); 954 r2 = pcic_read(h, mem_map_index[win].sysmem_start_lsb);
957 r3 = pcic_read(h, mem_map_index[win].sysmem_stop_msb); 955 r3 = pcic_read(h, mem_map_index[win].sysmem_stop_msb);
958 r4 = pcic_read(h, mem_map_index[win].sysmem_stop_lsb); 956 r4 = pcic_read(h, mem_map_index[win].sysmem_stop_lsb);
959 r5 = pcic_read(h, mem_map_index[win].cardmem_msb); 957 r5 = pcic_read(h, mem_map_index[win].cardmem_msb);
960 r6 = pcic_read(h, mem_map_index[win].cardmem_lsb); 958 r6 = pcic_read(h, mem_map_index[win].cardmem_lsb);
961 959
962 DPRINTF(("pcic_chip_do_mem_map window %d: %02x%02x %02x%02x " 960 DPRINTF(("pcic_chip_do_mem_map window %d: %02x%02x %02x%02x "
963 "%02x%02x\n", win, r1, r2, r3, r4, r5, r6)); 961 "%02x%02x\n", win, r1, r2, r3, r4, r5, r6));
964 } 962 }
965#endif 963#endif
966} 964}
967 965
968int 966int
969pcic_chip_mem_map(pcmcia_chipset_handle_t pch, int kind, bus_addr_t card_addr, 967pcic_chip_mem_map(pcmcia_chipset_handle_t pch, int kind, bus_addr_t card_addr,
970 bus_size_t size, struct pcmcia_mem_handle *pcmhp, bus_size_t *offsetp, 968 bus_size_t size, struct pcmcia_mem_handle *pcmhp, bus_size_t *offsetp,
971 int *windowp) 969 int *windowp)
972{ 970{
973 struct pcic_handle *h = (struct pcic_handle *) pch; 971 struct pcic_handle *h = (struct pcic_handle *) pch;
974 bus_addr_t busaddr; 972 bus_addr_t busaddr;
975 long card_offset; 973 long card_offset;
976 int i, win; 974 int i, win;
977 975
978 win = -1; 976 win = -1;
979 for (i = 0; i < (sizeof(mem_map_index) / sizeof(mem_map_index[0])); 977 for (i = 0; i < (sizeof(mem_map_index) / sizeof(mem_map_index[0]));
980 i++) { 978 i++) {
981 if ((h->memalloc & (1 << i)) == 0) { 979 if ((h->memalloc & (1 << i)) == 0) {
982 win = i; 980 win = i;
983 h->memalloc |= (1 << i); 981 h->memalloc |= (1 << i);
984 break; 982 break;
985 } 983 }
986 } 984 }
987 985
988 if (win == -1) 986 if (win == -1)
989 return 1; 987 return 1;
990 988
991 *windowp = win; 989 *windowp = win;
992 990
993 /* XXX this is pretty gross */ 991 /* XXX this is pretty gross */
994 992
995{ 993{
996 struct pcic_softc *sc = device_private(h->ph_parent); 994 struct pcic_softc *sc = device_private(h->ph_parent);
997 if (!bus_space_is_equal(sc->memt, pcmhp->memt)) 995 if (!bus_space_is_equal(sc->memt, pcmhp->memt))
998 panic("pcic_chip_mem_map memt is bogus"); 996 panic("pcic_chip_mem_map memt is bogus");
999} 997}
1000 998
1001 busaddr = pcmhp->addr; 999 busaddr = pcmhp->addr;
1002 1000
1003 /* 1001 /*
1004 * compute the address offset to the pcmcia address space for the 1002 * compute the address offset to the pcmcia address space for the
1005 * pcic. this is intentionally signed. The masks and shifts below 1003 * pcic. this is intentionally signed. The masks and shifts below
1006 * will cause TRT to happen in the pcic registers. Deal with making 1004 * will cause TRT to happen in the pcic registers. Deal with making
1007 * sure the address is aligned, and return the alignment offset. 1005 * sure the address is aligned, and return the alignment offset.
1008 */ 1006 */
1009 1007
1010 *offsetp = card_addr % PCIC_MEM_ALIGN; 1008 *offsetp = card_addr % PCIC_MEM_ALIGN;
1011 card_addr -= *offsetp; 1009 card_addr -= *offsetp;
1012 1010
1013 DPRINTF(("pcic_chip_mem_map window %d bus %lx+%lx+%lx at card addr " 1011 DPRINTF(("pcic_chip_mem_map window %d bus %lx+%lx+%lx at card addr "
1014 "%lx\n", win, (u_long) busaddr, (u_long) * offsetp, (u_long) size, 1012 "%lx\n", win, (u_long) busaddr, (u_long) * offsetp, (u_long) size,
1015 (u_long) card_addr)); 1013 (u_long) card_addr));
1016 1014
1017 /* 1015 /*
1018 * include the offset in the size, and decrement size by one, since 1016 * include the offset in the size, and decrement size by one, since
1019 * the hw wants start/stop 1017 * the hw wants start/stop
1020 */ 1018 */
1021 size += *offsetp - 1; 1019 size += *offsetp - 1;
1022 1020
1023 card_offset = (((long) card_addr) - ((long) busaddr)); 1021 card_offset = (((long) card_addr) - ((long) busaddr));
1024 1022
1025 h->mem[win].addr = busaddr; 1023 h->mem[win].addr = busaddr;
1026 h->mem[win].size = size; 1024 h->mem[win].size = size;
1027 h->mem[win].offset = card_offset; 1025 h->mem[win].offset = card_offset;
1028 h->mem[win].kind = kind; 1026 h->mem[win].kind = kind;
1029 1027
1030 pcic_chip_do_mem_map(h, win); 1028 pcic_chip_do_mem_map(h, win);
1031 1029
1032 return 0; 1030 return 0;
1033} 1031}
1034 1032
1035void 1033void
1036pcic_chip_mem_unmap(pcmcia_chipset_handle_t pch, int window) 1034pcic_chip_mem_unmap(pcmcia_chipset_handle_t pch, int window)
1037{ 1035{
1038 struct pcic_handle *h = (struct pcic_handle *) pch; 1036 struct pcic_handle *h = (struct pcic_handle *) pch;
1039 int reg; 1037 int reg;
1040 1038
1041 if (window >= (sizeof(mem_map_index) / sizeof(mem_map_index[0]))) 1039 if (window >= (sizeof(mem_map_index) / sizeof(mem_map_index[0])))
1042 panic("pcic_chip_mem_unmap: window out of range"); 1040 panic("pcic_chip_mem_unmap: window out of range");
1043 1041
1044 reg = pcic_read(h, PCIC_ADDRWIN_ENABLE); 1042 reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
1045 reg &= ~mem_map_index[window].memenable; 1043 reg &= ~mem_map_index[window].memenable;
1046 pcic_write(h, PCIC_ADDRWIN_ENABLE, reg); 1044 pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
1047 1045
1048 h->memalloc &= ~(1 << window); 1046 h->memalloc &= ~(1 << window);
1049} 1047}
1050 1048
1051int 1049int
1052pcic_chip_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start, 1050pcic_chip_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start,
1053 bus_size_t size, bus_size_t align, struct pcmcia_io_handle *pcihp) 1051 bus_size_t size, bus_size_t align, struct pcmcia_io_handle *pcihp)
1054{ 1052{
1055 struct pcic_handle *h = (struct pcic_handle *) pch; 1053 struct pcic_handle *h = (struct pcic_handle *) pch;
1056 bus_space_tag_t iot; 1054 bus_space_tag_t iot;
1057 bus_space_handle_t ioh; 1055 bus_space_handle_t ioh;
1058 bus_addr_t ioaddr; 1056 bus_addr_t ioaddr;
1059 int flags = 0; 1057 int flags = 0;
1060 struct pcic_softc *sc = device_private(h->ph_parent); 1058 struct pcic_softc *sc = device_private(h->ph_parent);
1061 1059
1062 /* 1060 /*
1063 * Allocate some arbitrary I/O space. 1061 * Allocate some arbitrary I/O space.
1064 */ 1062 */
1065 1063
1066 iot = sc->iot; 1064 iot = sc->iot;
1067 1065
1068 if (start) { 1066 if (start) {
1069 ioaddr = start; 1067 ioaddr = start;
1070 if (bus_space_map(iot, start, size, 0, &ioh)) 1068 if (bus_space_map(iot, start, size, 0, &ioh))
1071 return 1; 1069 return 1;
1072 DPRINTF(("pcic_chip_io_alloc map port %lx+%lx\n", 1070 DPRINTF(("pcic_chip_io_alloc map port %lx+%lx\n",
1073 (u_long) ioaddr, (u_long) size)); 1071 (u_long) ioaddr, (u_long) size));
1074 } else { 1072 } else {
1075 flags |= PCMCIA_IO_ALLOCATED; 1073 flags |= PCMCIA_IO_ALLOCATED;
1076 if (bus_space_alloc(iot, sc->iobase, 1074 if (bus_space_alloc(iot, sc->iobase,
1077 sc->iobase + sc->iosize, size, align, 0, 0, 1075 sc->iobase + sc->iosize, size, align, 0, 0,
1078 &ioaddr, &ioh)) 1076 &ioaddr, &ioh))
1079 return 1; 1077 return 1;
1080 DPRINTF(("pcic_chip_io_alloc alloc port %lx+%lx\n", 1078 DPRINTF(("pcic_chip_io_alloc alloc port %lx+%lx\n",
1081 (u_long) ioaddr, (u_long) size)); 1079 (u_long) ioaddr, (u_long) size));
1082 } 1080 }
1083 1081
1084 pcihp->iot = iot; 1082 pcihp->iot = iot;
1085 pcihp->ioh = ioh; 1083 pcihp->ioh = ioh;
1086 pcihp->addr = ioaddr; 1084 pcihp->addr = ioaddr;
1087 pcihp->size = size; 1085 pcihp->size = size;
1088 pcihp->flags = flags; 1086 pcihp->flags = flags;
1089 1087
1090 return 0; 1088 return 0;
1091} 1089}
1092 1090
1093void 1091void
1094pcic_chip_io_free(pcmcia_chipset_handle_t pch, struct pcmcia_io_handle *pcihp) 1092pcic_chip_io_free(pcmcia_chipset_handle_t pch, struct pcmcia_io_handle *pcihp)
1095{ 1093{
1096 bus_space_tag_t iot = pcihp->iot; 1094 bus_space_tag_t iot = pcihp->iot;
1097 bus_space_handle_t ioh = pcihp->ioh; 1095 bus_space_handle_t ioh = pcihp->ioh;
1098 bus_size_t size = pcihp->size; 1096 bus_size_t size = pcihp->size;
1099 1097
1100 if (pcihp->flags & PCMCIA_IO_ALLOCATED) 1098 if (pcihp->flags & PCMCIA_IO_ALLOCATED)
1101 bus_space_free(iot, ioh, size); 1099 bus_space_free(iot, ioh, size);
1102 else 1100 else
1103 bus_space_unmap(iot, ioh, size); 1101 bus_space_unmap(iot, ioh, size);
1104} 1102}
1105 1103
1106 1104
1107static const struct io_map_index_st { 1105static const struct io_map_index_st {
1108 int start_lsb; 1106 int start_lsb;
1109 int start_msb; 1107 int start_msb;
1110 int stop_lsb; 1108 int stop_lsb;
1111 int stop_msb; 1109 int stop_msb;
1112 int ioenable; 1110 int ioenable;
1113 int ioctlmask; 1111 int ioctlmask;
1114 int ioctlbits[3]; /* indexed by PCMCIA_WIDTH_* */ 1112 int ioctlbits[3]; /* indexed by PCMCIA_WIDTH_* */
1115} io_map_index[] = { 1113} io_map_index[] = {
1116 { 1114 {
1117 PCIC_IOADDR0_START_LSB, 1115 PCIC_IOADDR0_START_LSB,
1118 PCIC_IOADDR0_START_MSB, 1116 PCIC_IOADDR0_START_MSB,
1119 PCIC_IOADDR0_STOP_LSB, 1117 PCIC_IOADDR0_STOP_LSB,
1120 PCIC_IOADDR0_STOP_MSB, 1118 PCIC_IOADDR0_STOP_MSB,
1121 PCIC_ADDRWIN_ENABLE_IO0, 1119 PCIC_ADDRWIN_ENABLE_IO0,
1122 PCIC_IOCTL_IO0_WAITSTATE | PCIC_IOCTL_IO0_ZEROWAIT | 1120 PCIC_IOCTL_IO0_WAITSTATE | PCIC_IOCTL_IO0_ZEROWAIT |
1123 PCIC_IOCTL_IO0_IOCS16SRC_MASK | PCIC_IOCTL_IO0_DATASIZE_MASK, 1121 PCIC_IOCTL_IO0_IOCS16SRC_MASK | PCIC_IOCTL_IO0_DATASIZE_MASK,
1124 { 1122 {
1125 PCIC_IOCTL_IO0_IOCS16SRC_CARD, 1123 PCIC_IOCTL_IO0_IOCS16SRC_CARD,
1126 PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE | 1124 PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE |
1127 PCIC_IOCTL_IO0_DATASIZE_8BIT, 1125 PCIC_IOCTL_IO0_DATASIZE_8BIT,
1128 PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE | 1126 PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE |
1129 PCIC_IOCTL_IO0_DATASIZE_16BIT, 1127 PCIC_IOCTL_IO0_DATASIZE_16BIT,
1130 }, 1128 },
1131 }, 1129 },
1132 { 1130 {
1133 PCIC_IOADDR1_START_LSB, 1131 PCIC_IOADDR1_START_LSB,
1134 PCIC_IOADDR1_START_MSB, 1132 PCIC_IOADDR1_START_MSB,
1135 PCIC_IOADDR1_STOP_LSB, 1133 PCIC_IOADDR1_STOP_LSB,
1136 PCIC_IOADDR1_STOP_MSB, 1134 PCIC_IOADDR1_STOP_MSB,
1137 PCIC_ADDRWIN_ENABLE_IO1, 1135 PCIC_ADDRWIN_ENABLE_IO1,
1138 PCIC_IOCTL_IO1_WAITSTATE | PCIC_IOCTL_IO1_ZEROWAIT | 1136 PCIC_IOCTL_IO1_WAITSTATE | PCIC_IOCTL_IO1_ZEROWAIT |
1139 PCIC_IOCTL_IO1_IOCS16SRC_MASK | PCIC_IOCTL_IO1_DATASIZE_MASK, 1137 PCIC_IOCTL_IO1_IOCS16SRC_MASK | PCIC_IOCTL_IO1_DATASIZE_MASK,
1140 { 1138 {
1141 PCIC_IOCTL_IO1_IOCS16SRC_CARD, 1139 PCIC_IOCTL_IO1_IOCS16SRC_CARD,
1142 PCIC_IOCTL_IO1_IOCS16SRC_DATASIZE | 1140 PCIC_IOCTL_IO1_IOCS16SRC_DATASIZE |
1143 PCIC_IOCTL_IO1_DATASIZE_8BIT, 1141 PCIC_IOCTL_IO1_DATASIZE_8BIT,
1144 PCIC_IOCTL_IO1_IOCS16SRC_DATASIZE | 1142 PCIC_IOCTL_IO1_IOCS16SRC_DATASIZE |
1145 PCIC_IOCTL_IO1_DATASIZE_16BIT, 1143 PCIC_IOCTL_IO1_DATASIZE_16BIT,
1146 }, 1144 },
1147 }, 1145 },
1148}; 1146};
1149 1147
1150void 1148void
1151pcic_chip_do_io_map(struct pcic_handle *h, int win) 1149pcic_chip_do_io_map(struct pcic_handle *h, int win)
1152{ 1150{
1153 int reg; 1151 int reg;
1154 1152
1155 DPRINTF(("pcic_chip_do_io_map win %d addr %lx size %lx width %d\n", 1153 DPRINTF(("pcic_chip_do_io_map win %d addr %lx size %lx width %d\n",
1156 win, (long) h->io[win].addr, (long) h->io[win].size, 1154 win, (long) h->io[win].addr, (long) h->io[win].size,
1157 h->io[win].width * 8)); 1155 h->io[win].width * 8));
1158 1156
1159 pcic_write(h, io_map_index[win].start_lsb, h->io[win].addr & 0xff); 1157 pcic_write(h, io_map_index[win].start_lsb, h->io[win].addr & 0xff);
1160 pcic_write(h, io_map_index[win].start_msb, 1158 pcic_write(h, io_map_index[win].start_msb,
1161 (h->io[win].addr >> 8) & 0xff); 1159 (h->io[win].addr >> 8) & 0xff);
1162 1160
1163 pcic_write(h, io_map_index[win].stop_lsb, 1161 pcic_write(h, io_map_index[win].stop_lsb,
1164 (h->io[win].addr + h->io[win].size - 1) & 0xff); 1162 (h->io[win].addr + h->io[win].size - 1) & 0xff);
1165 pcic_write(h, io_map_index[win].stop_msb, 1163 pcic_write(h, io_map_index[win].stop_msb,
1166 ((h->io[win].addr + h->io[win].size - 1) >> 8) & 0xff); 1164 ((h->io[win].addr + h->io[win].size - 1) >> 8) & 0xff);
1167 1165
1168 reg = pcic_read(h, PCIC_IOCTL); 1166 reg = pcic_read(h, PCIC_IOCTL);
1169 reg &= ~io_map_index[win].ioctlmask; 1167 reg &= ~io_map_index[win].ioctlmask;
1170 reg |= io_map_index[win].ioctlbits[h->io[win].width]; 1168 reg |= io_map_index[win].ioctlbits[h->io[win].width];
1171 pcic_write(h, PCIC_IOCTL, reg); 1169 pcic_write(h, PCIC_IOCTL, reg);
1172 1170
1173 reg = pcic_read(h, PCIC_ADDRWIN_ENABLE); 1171 reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
1174 reg |= io_map_index[win].ioenable; 1172 reg |= io_map_index[win].ioenable;
1175 pcic_write(h, PCIC_ADDRWIN_ENABLE, reg); 1173 pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
1176} 1174}
1177 1175
1178int 1176int
1179pcic_chip_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset, 1177pcic_chip_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset,
1180 bus_size_t size, struct pcmcia_io_handle *pcihp, int *windowp) 1178 bus_size_t size, struct pcmcia_io_handle *pcihp, int *windowp)
1181{ 1179{
1182 struct pcic_handle *h = (struct pcic_handle *) pch; 1180 struct pcic_handle *h = (struct pcic_handle *) pch;
1183 bus_addr_t ioaddr = pcihp->addr + offset; 1181 bus_addr_t ioaddr = pcihp->addr + offset;
1184 int i, win; 1182 int i, win;
1185#ifdef PCICDEBUG 1183#ifdef PCICDEBUG
1186 static const char *width_names[] = { "auto", "io8", "io16" }; 1184 static const char *width_names[] = { "auto", "io8", "io16" };
1187#endif 1185#endif
1188 struct pcic_softc *sc = device_private(h->ph_parent); 1186 struct pcic_softc *sc = device_private(h->ph_parent);
1189 1187
1190 /* XXX Sanity check offset/size. */ 1188 /* XXX Sanity check offset/size. */
1191 1189
1192 win = -1; 1190 win = -1;
1193 for (i = 0; i < (sizeof(io_map_index) / sizeof(io_map_index[0])); i++) { 1191 for (i = 0; i < (sizeof(io_map_index) / sizeof(io_map_index[0])); i++) {
1194 if ((h->ioalloc & (1 << i)) == 0) { 1192 if ((h->ioalloc & (1 << i)) == 0) {
1195 win = i; 1193 win = i;
1196 h->ioalloc |= (1 << i); 1194 h->ioalloc |= (1 << i);
1197 break; 1195 break;
1198 } 1196 }
1199 } 1197 }
1200 1198
1201 if (win == -1) 1199 if (win == -1)
1202 return 1; 1200 return 1;
1203 1201
1204 *windowp = win; 1202 *windowp = win;
1205 1203
1206 /* XXX this is pretty gross */ 1204 /* XXX this is pretty gross */
1207 1205
1208 if (!bus_space_is_equal(sc->iot, pcihp->iot)) 1206 if (!bus_space_is_equal(sc->iot, pcihp->iot))
1209 panic("pcic_chip_io_map iot is bogus"); 1207 panic("pcic_chip_io_map iot is bogus");
1210 1208
1211 DPRINTF(("pcic_chip_io_map window %d %s port %lx+%lx\n", 1209 DPRINTF(("pcic_chip_io_map window %d %s port %lx+%lx\n",
1212 win, width_names[width], (u_long) ioaddr, (u_long) size)); 1210 win, width_names[width], (u_long) ioaddr, (u_long) size));
1213 1211
1214 /* XXX wtf is this doing here? */ 1212 /* XXX wtf is this doing here? */
1215 1213
1216 printf("%s: port 0x%lx", device_xname(&sc->dev), (u_long) ioaddr); 1214 printf("%s: port 0x%lx", device_xname(&sc->dev), (u_long) ioaddr);
1217 if (size > 1) 1215 if (size > 1)
1218 printf("-0x%lx", (u_long) ioaddr + (u_long) size - 1); 1216 printf("-0x%lx", (u_long) ioaddr + (u_long) size - 1);
1219 printf("\n"); 1217 printf("\n");
1220 1218
1221 h->io[win].addr = ioaddr; 1219 h->io[win].addr = ioaddr;
1222 h->io[win].size = size; 1220 h->io[win].size = size;
1223 h->io[win].width = width; 1221 h->io[win].width = width;
1224 1222
1225 pcic_chip_do_io_map(h, win); 1223 pcic_chip_do_io_map(h, win);
1226 1224
1227 return 0; 1225 return 0;
1228} 1226}
1229 1227
1230void 1228void
1231pcic_chip_io_unmap(pcmcia_chipset_handle_t pch, int window) 1229pcic_chip_io_unmap(pcmcia_chipset_handle_t pch, int window)
1232{ 1230{
1233 struct pcic_handle *h = (struct pcic_handle *) pch; 1231 struct pcic_handle *h = (struct pcic_handle *) pch;
1234 int reg; 1232 int reg;
1235 1233
1236 if (window >= (sizeof(io_map_index) / sizeof(io_map_index[0]))) 1234 if (window >= (sizeof(io_map_index) / sizeof(io_map_index[0])))
1237 panic("pcic_chip_io_unmap: window out of range"); 1235 panic("pcic_chip_io_unmap: window out of range");
1238 1236
1239 reg = pcic_read(h, PCIC_ADDRWIN_ENABLE); 1237 reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
1240 reg &= ~io_map_index[window].ioenable; 1238 reg &= ~io_map_index[window].ioenable;
1241 pcic_write(h, PCIC_ADDRWIN_ENABLE, reg); 1239 pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
1242 1240
1243 h->ioalloc &= ~(1 << window); 1241 h->ioalloc &= ~(1 << window);
1244} 1242}
1245 1243
1246static int 1244static int
1247pcic_wait_ready(struct pcic_handle *h) 1245pcic_wait_ready(struct pcic_handle *h)
1248{ 1246{
1249 uint8_t stat; 1247 uint8_t stat;
1250 int i; 1248 int i;
1251 1249
1252 /* wait an initial 10ms for quick cards */ 1250 /* wait an initial 10ms for quick cards */
1253 stat = pcic_read(h, PCIC_IF_STATUS); 1251 stat = pcic_read(h, PCIC_IF_STATUS);
1254 if (stat & PCIC_IF_STATUS_READY) 1252 if (stat & PCIC_IF_STATUS_READY)
1255 return 0; 1253 return 0;
1256 pcic_delay(h, 10, "pccwr0"); 1254 pcic_delay(h, 10, "pccwr0");
1257 for (i = 0; i < 50; i++) { 1255 for (i = 0; i < 50; i++) {
1258 stat = pcic_read(h, PCIC_IF_STATUS); 1256 stat = pcic_read(h, PCIC_IF_STATUS);
1259 if (stat & PCIC_IF_STATUS_READY) 1257 if (stat & PCIC_IF_STATUS_READY)
1260 return 0; 1258 return 0;
1261 if ((stat & PCIC_IF_STATUS_CARDDETECT_MASK) != 1259 if ((stat & PCIC_IF_STATUS_CARDDETECT_MASK) !=
1262 PCIC_IF_STATUS_CARDDETECT_PRESENT) 1260 PCIC_IF_STATUS_CARDDETECT_PRESENT)
1263 return ENXIO; 1261 return ENXIO;
1264 /* wait .1s (100ms) each iteration now */ 1262 /* wait .1s (100ms) each iteration now */
1265 pcic_delay(h, 100, "pccwr1"); 1263 pcic_delay(h, 100, "pccwr1");
1266 } 1264 }
1267 1265
1268 printf("pcic_wait_ready: ready never happened, status=%02x\n", stat); 1266 printf("pcic_wait_ready: ready never happened, status=%02x\n", stat);
1269 return EWOULDBLOCK; 1267 return EWOULDBLOCK;
1270} 1268}
1271 1269
1272/* 1270/*
1273 * Perform long (msec order) delay. 1271 * Perform long (msec order) delay.
1274 */ 1272 */
1275static void 1273static void
1276pcic_delay(struct pcic_handle *h, int timo, const char *wmesg) 1274pcic_delay(struct pcic_handle *h, int timo, const char *wmesg)
1277 /* timo: in ms. must not be zero */ 1275 /* timo: in ms. must not be zero */
1278{ 1276{
1279 1277
1280#ifdef DIAGNOSTIC 1278#ifdef DIAGNOSTIC
1281 if (timo <= 0) 1279 if (timo <= 0)
1282 panic("pcic_delay: called with timeout %d", timo); 1280 panic("pcic_delay: called with timeout %d", timo);
1283 if (!curlwp) 1281 if (!curlwp)
1284 panic("pcic_delay: called in interrupt context"); 1282 panic("pcic_delay: called in interrupt context");
1285 if (!h->event_thread) 1283 if (!h->event_thread)
1286 panic("pcic_delay: no event thread"); 1284 panic("pcic_delay: no event thread");
1287#endif 1285#endif
1288 DPRINTF(("pcic_delay: \"%s\" %p, sleep %d ms\n", 1286 DPRINTF(("pcic_delay: \"%s\" %p, sleep %d ms\n",
1289 wmesg, h->event_thread, timo)); 1287 wmesg, h->event_thread, timo));
1290 if (doing_shutdown) 1288 if (doing_shutdown)
1291 delay(timo * 1000); 1289 delay(timo * 1000);
1292 else 1290 else
1293 tsleep(pcic_delay, PWAIT, wmesg, 1291 tsleep(pcic_delay, PWAIT, wmesg,
1294 roundup(timo * hz, 1000) / 1000); 1292 roundup(timo * hz, 1000) / 1000);
1295} 1293}
1296 1294
1297void 1295void
1298pcic_chip_socket_enable(pcmcia_chipset_handle_t pch) 1296pcic_chip_socket_enable(pcmcia_chipset_handle_t pch)
1299{ 1297{
1300 struct pcic_handle *h = (struct pcic_handle *) pch; 1298 struct pcic_handle *h = (struct pcic_handle *) pch;
1301 int win; 1299 int win;
1302 uint8_t power, intr; 1300 uint8_t power, intr;
1303#ifdef DIAGNOSTIC 1301#ifdef DIAGNOSTIC
1304 int reg; 1302 int reg;
1305#endif 1303#endif
1306 1304
1307#ifdef DIAGNOSTIC 1305#ifdef DIAGNOSTIC
1308 if (h->flags & PCIC_FLAG_ENABLED) 1306 if (h->flags & PCIC_FLAG_ENABLED)
1309 printf("pcic_chip_socket_enable: enabling twice\n"); 1307 printf("pcic_chip_socket_enable: enabling twice\n");
1310#endif 1308#endif
1311 1309
1312 /* disable interrupts; assert RESET */ 1310 /* disable interrupts; assert RESET */
1313 intr = pcic_read(h, PCIC_INTR); 1311 intr = pcic_read(h, PCIC_INTR);
1314 intr &= PCIC_INTR_ENABLE; 1312 intr &= PCIC_INTR_ENABLE;
1315 pcic_write(h, PCIC_INTR, intr); 1313 pcic_write(h, PCIC_INTR, intr);
1316 1314
1317 /* zero out the address windows */ 1315 /* zero out the address windows */
1318 pcic_write(h, PCIC_ADDRWIN_ENABLE, 0); 1316 pcic_write(h, PCIC_ADDRWIN_ENABLE, 0);
1319 1317
1320 /* power off; assert output enable bit */ 1318 /* power off; assert output enable bit */
1321 power = PCIC_PWRCTL_OE; 1319 power = PCIC_PWRCTL_OE;
1322 pcic_write(h, PCIC_PWRCTL, power); 1320 pcic_write(h, PCIC_PWRCTL, power);
1323 1321
1324 /* 1322 /*
1325 * power hack for RICOH RF5C[23]96 1323 * power hack for RICOH RF5C[23]96
1326 */ 1324 */
1327 switch (h->vendor) { 1325 switch (h->vendor) {
1328 case PCIC_VENDOR_RICOH_5C296: 1326 case PCIC_VENDOR_RICOH_5C296:
1329 case PCIC_VENDOR_RICOH_5C396: 1327 case PCIC_VENDOR_RICOH_5C396:
1330 { 1328 {
1331 int regtmp; 1329 int regtmp;
1332 regtmp = pcic_read(h, PCIC_RICOH_REG_MCR2); 1330 regtmp = pcic_read(h, PCIC_RICOH_REG_MCR2);
1333#ifdef RICOH_POWER_HACK 1331#ifdef RICOH_POWER_HACK
1334 regtmp |= PCIC_RICOH_MCR2_VCC_DIRECT; 1332 regtmp |= PCIC_RICOH_MCR2_VCC_DIRECT;
1335#else 1333#else
1336 regtmp &= 1334 regtmp &=
1337 ~(PCIC_RICOH_MCR2_VCC_DIRECT|PCIC_RICOH_MCR2_VCC_SEL_3V); 1335 ~(PCIC_RICOH_MCR2_VCC_DIRECT|PCIC_RICOH_MCR2_VCC_SEL_3V);
1338#endif 1336#endif
1339 pcic_write(h, PCIC_RICOH_REG_MCR2, regtmp); 1337 pcic_write(h, PCIC_RICOH_REG_MCR2, regtmp);
1340 } 1338 }
1341 break; 1339 break;
1342 default: 1340 default:
1343 break; 1341 break;
1344 } 1342 }
1345 1343
1346#ifdef VADEM_POWER_HACK 1344#ifdef VADEM_POWER_HACK
1347 bus_space_write_1(sc->iot, sc->ioh, PCIC_REG_INDEX, 0x0e); 1345 bus_space_write_1(sc->iot, sc->ioh, PCIC_REG_INDEX, 0x0e);
1348 bus_space_write_1(sc->iot, sc->ioh, PCIC_REG_INDEX, 0x37); 1346 bus_space_write_1(sc->iot, sc->ioh, PCIC_REG_INDEX, 0x37);
1349 printf("prcr = %02x\n", pcic_read(h, 0x02)); 1347 printf("prcr = %02x\n", pcic_read(h, 0x02));
1350 printf("cvsr = %02x\n", pcic_read(h, 0x2f)); 1348 printf("cvsr = %02x\n", pcic_read(h, 0x2f));
1351 printf("DANGER WILL ROBINSON! Changing voltage select!\n"); 1349 printf("DANGER WILL ROBINSON! Changing voltage select!\n");
1352 pcic_write(h, 0x2f, pcic_read(h, 0x2f) & ~0x03); 1350 pcic_write(h, 0x2f, pcic_read(h, 0x2f) & ~0x03);
1353 printf("cvsr = %02x\n", pcic_read(h, 0x2f)); 1351 printf("cvsr = %02x\n", pcic_read(h, 0x2f));
1354#endif 1352#endif
1355 1353
1356 /* power up the socket */ 1354 /* power up the socket */
1357 power |= PCIC_PWRCTL_PWR_ENABLE | PCIC_PWRCTL_VPP1_VCC; 1355 power |= PCIC_PWRCTL_PWR_ENABLE | PCIC_PWRCTL_VPP1_VCC;
1358 pcic_write(h, PCIC_PWRCTL, power); 1356 pcic_write(h, PCIC_PWRCTL, power);
1359 1357
1360 /* 1358 /*
1361 * Table 4-18 and figure 4-6 of the PC Card specifiction say: 1359 * Table 4-18 and figure 4-6 of the PC Card specifiction say:
1362 * Vcc Rising Time (Tpr) = 100ms 1360 * Vcc Rising Time (Tpr) = 100ms
1363 * RESET Width (Th (Hi-z RESET)) = 1ms 1361 * RESET Width (Th (Hi-z RESET)) = 1ms
1364 * RESET Width (Tw (RESET)) = 10us 1362 * RESET Width (Tw (RESET)) = 10us
1365 * 1363 *
1366 * some machines require some more time to be settled 1364 * some machines require some more time to be settled
1367 * (100ms is added here). 1365 * (100ms is added here).
1368 */ 1366 */
1369 pcic_delay(h, 200 + 1, "pccen1"); 1367 pcic_delay(h, 200 + 1, "pccen1");
1370 1368
1371 /* negate RESET */ 1369 /* negate RESET */
1372 intr |= PCIC_INTR_RESET; 1370 intr |= PCIC_INTR_RESET;
1373 pcic_write(h, PCIC_INTR, intr); 1371 pcic_write(h, PCIC_INTR, intr);
1374 1372
1375 /* 1373 /*
1376 * RESET Setup Time (Tsu (RESET)) = 20ms 1374 * RESET Setup Time (Tsu (RESET)) = 20ms
1377 */ 1375 */
1378 pcic_delay(h, 20, "pccen2"); 1376 pcic_delay(h, 20, "pccen2");
1379 1377
1380#ifdef DIAGNOSTIC 1378#ifdef DIAGNOSTIC
1381 reg = pcic_read(h, PCIC_IF_STATUS); 1379 reg = pcic_read(h, PCIC_IF_STATUS);
1382 if ((reg & PCIC_IF_STATUS_POWERACTIVE) == 0) 1380 if ((reg & PCIC_IF_STATUS_POWERACTIVE) == 0)
1383 printf("pcic_chip_socket_enable: no power, status=%x\n", reg); 1381 printf("pcic_chip_socket_enable: no power, status=%x\n", reg);
1384#endif 1382#endif
1385 1383
1386 /* wait for the chip to finish initializing */ 1384 /* wait for the chip to finish initializing */
1387 if (pcic_wait_ready(h)) { 1385 if (pcic_wait_ready(h)) {
1388 /* XXX return a failure status?? */ 1386 /* XXX return a failure status?? */
1389 pcic_write(h, PCIC_PWRCTL, 0); 1387 pcic_write(h, PCIC_PWRCTL, 0);
1390 return; 1388 return;
1391 } 1389 }
1392 1390
1393 /* reinstall all the memory and io mappings */ 1391 /* reinstall all the memory and io mappings */
1394 for (win = 0; win < PCIC_MEM_WINS; win++) 1392 for (win = 0; win < PCIC_MEM_WINS; win++)
1395 if (h->memalloc & (1 << win)) 1393 if (h->memalloc & (1 << win))
1396 pcic_chip_do_mem_map(h, win); 1394 pcic_chip_do_mem_map(h, win);
1397 for (win = 0; win < PCIC_IO_WINS; win++) 1395 for (win = 0; win < PCIC_IO_WINS; win++)
1398 if (h->ioalloc & (1 << win)) 1396 if (h->ioalloc & (1 << win))
1399 pcic_chip_do_io_map(h, win); 1397 pcic_chip_do_io_map(h, win);
1400 1398
1401 h->flags |= PCIC_FLAG_ENABLED; 1399 h->flags |= PCIC_FLAG_ENABLED;
1402} 1400}
1403 1401
1404void 1402void
1405pcic_chip_socket_disable(pcmcia_chipset_handle_t pch) 1403pcic_chip_socket_disable(pcmcia_chipset_handle_t pch)
1406{ 1404{
1407 struct pcic_handle *h = (struct pcic_handle *) pch; 1405 struct pcic_handle *h = (struct pcic_handle *) pch;
1408 uint8_t intr; 1406 uint8_t intr;
1409 1407
1410 DPRINTF(("pcic_chip_socket_disable\n")); 1408 DPRINTF(("pcic_chip_socket_disable\n"));

cvs diff -r1.35 -r1.36 src/sys/dev/ic/tcic2.c (switch to unified diff)

--- src/sys/dev/ic/tcic2.c 2010/04/19 18:24:26 1.35
+++ src/sys/dev/ic/tcic2.c 2011/07/26 22:21:02 1.36
@@ -1,1292 +1,1290 @@ @@ -1,1292 +1,1290 @@
1/* $NetBSD: tcic2.c,v 1.35 2010/04/19 18:24:26 dyoung Exp $ */ 1/* $NetBSD: tcic2.c,v 1.36 2011/07/26 22:21:02 dyoung Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 1999 Christoph Badura. All rights reserved. 4 * Copyright (c) 1998, 1999 Christoph Badura. All rights reserved.
5 * Copyright (c) 1997 Marc Horowitz. All rights reserved. 5 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement: 16 * must display the following acknowledgement:
17 * This product includes software developed by Marc Horowitz. 17 * This product includes software developed by Marc Horowitz.
18 * 4. The name of the author may not be used to endorse or promote products 18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission. 19 * derived from this software without specific prior written permission.
20 * 20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: tcic2.c,v 1.35 2010/04/19 18:24:26 dyoung Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: tcic2.c,v 1.36 2011/07/26 22:21:02 dyoung Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/device.h> 38#include <sys/device.h>
39#include <sys/extent.h> 39#include <sys/extent.h>
40#include <sys/malloc.h> 40#include <sys/malloc.h>
41#include <sys/kthread.h> 41#include <sys/kthread.h>
42 42
43#include <sys/bus.h> 43#include <sys/bus.h>
44#include <sys/intr.h> 44#include <sys/intr.h>
45 45
46#include <dev/pcmcia/pcmciareg.h> 46#include <dev/pcmcia/pcmciareg.h>
47#include <dev/pcmcia/pcmciavar.h> 47#include <dev/pcmcia/pcmciavar.h>
48 48
49#include <dev/ic/tcic2reg.h> 49#include <dev/ic/tcic2reg.h>
50#include <dev/ic/tcic2var.h> 50#include <dev/ic/tcic2var.h>
51 51
52#include "locators.h" 52#include "locators.h"
53 53
54#ifdef TCICDEBUG 54#ifdef TCICDEBUG
55int tcic_debug = 1; 55int tcic_debug = 1;
56#define DPRINTF(arg) if (tcic_debug) printf arg; 56#define DPRINTF(arg) if (tcic_debug) printf arg;
57#else 57#else
58#define DPRINTF(arg) 58#define DPRINTF(arg)
59#endif 59#endif
60 60
61/* 61/*
62 * Individual drivers will allocate their own memory and io regions. Memory 62 * Individual drivers will allocate their own memory and io regions. Memory
63 * regions must be a multiple of 4k, aligned on a 4k boundary. 63 * regions must be a multiple of 4k, aligned on a 4k boundary.
64 */ 64 */
65 65
66#define TCIC_MEM_ALIGN TCIC_MEM_PAGESIZE 66#define TCIC_MEM_ALIGN TCIC_MEM_PAGESIZE
67 67
68void tcic_attach_socket(struct tcic_handle *); 68void tcic_attach_socket(struct tcic_handle *);
69void tcic_init_socket(struct tcic_handle *); 69void tcic_init_socket(struct tcic_handle *);
70 70
71int tcic_print(void *arg, const char *pnp); 71int tcic_print(void *arg, const char *pnp);
72int tcic_intr_socket(struct tcic_handle *); 72int tcic_intr_socket(struct tcic_handle *);
73 73
74void tcic_attach_card(struct tcic_handle *); 74void tcic_attach_card(struct tcic_handle *);
75void tcic_detach_card(struct tcic_handle *, int); 75void tcic_detach_card(struct tcic_handle *, int);
76void tcic_deactivate_card(struct tcic_handle *); 76void tcic_deactivate_card(struct tcic_handle *);
77 77
78void tcic_chip_do_mem_map(struct tcic_handle *, int); 78void tcic_chip_do_mem_map(struct tcic_handle *, int);
79void tcic_chip_do_io_map(struct tcic_handle *, int); 79void tcic_chip_do_io_map(struct tcic_handle *, int);
80 80
81void tcic_create_event_thread(void *); 81void tcic_create_event_thread(void *);
82void tcic_event_thread(void *); 82void tcic_event_thread(void *);
83 83
84void tcic_queue_event(struct tcic_handle *, int); 84void tcic_queue_event(struct tcic_handle *, int);
85 85
86/* Map between irq numbers and internal representation */ 86/* Map between irq numbers and internal representation */
87#if 1 87#if 1
88int tcic_irqmap[] = 88int tcic_irqmap[] =
89 { 0, 0, 0, 3, 4, 5, 6, 7, 0, 0, 10, 1, 0, 0, 14, 0 }; 89 { 0, 0, 0, 3, 4, 5, 6, 7, 0, 0, 10, 1, 0, 0, 14, 0 };
90int tcic_valid_irqs = 0x4cf8; 90int tcic_valid_irqs = 0x4cf8;
91#else 91#else
92int tcic_irqmap[] = /* irqs 9 and 6 switched, some ISA cards */ 92int tcic_irqmap[] = /* irqs 9 and 6 switched, some ISA cards */
93 { 0, 0, 0, 3, 4, 5, 0, 7, 0, 6, 10, 1, 0, 0, 14, 0 }; 93 { 0, 0, 0, 3, 4, 5, 0, 7, 0, 6, 10, 1, 0, 0, 14, 0 };
94int tcic_valid_irqs = 0x4eb8; 94int tcic_valid_irqs = 0x4eb8;
95#endif 95#endif
96 96
97int tcic_mem_speed = 250; /* memory access time in nanoseconds */ 97int tcic_mem_speed = 250; /* memory access time in nanoseconds */
98int tcic_io_speed = 165; /* io access time in nanoseconds */ 98int tcic_io_speed = 165; /* io access time in nanoseconds */
99 99
100/* 100/*
101 * Check various reserved and otherwise in their value restricted bits. 101 * Check various reserved and otherwise in their value restricted bits.
102 */ 102 */
103int 103int
104tcic_check_reserved_bits(bus_space_tag_t iot, bus_space_handle_t ioh) 104tcic_check_reserved_bits(bus_space_tag_t iot, bus_space_handle_t ioh)
105{ 105{
106 int val, auxreg; 106 int val, auxreg;
107 107
108 DPRINTF(("tcic: chkrsvd 1\n")); 108 DPRINTF(("tcic: chkrsvd 1\n"));
109 /* R_ADDR bit 30:28 have a restricted range. */ 109 /* R_ADDR bit 30:28 have a restricted range. */
110 val = (bus_space_read_2(iot, ioh, TCIC_R_ADDR2) & TCIC_SS_MASK) 110 val = (bus_space_read_2(iot, ioh, TCIC_R_ADDR2) & TCIC_SS_MASK)
111 >> TCIC_SS_SHIFT; 111 >> TCIC_SS_SHIFT;
112 if (val > 1) 112 if (val > 1)
113 return 0; 113 return 0;
114 114
115 DPRINTF(("tcic: chkrsvd 2\n")); 115 DPRINTF(("tcic: chkrsvd 2\n"));
116 /* R_SCTRL bits 6,2,1 are reserved. */ 116 /* R_SCTRL bits 6,2,1 are reserved. */
117 val = bus_space_read_1(iot, ioh, TCIC_R_SCTRL); 117 val = bus_space_read_1(iot, ioh, TCIC_R_SCTRL);
118 if (val & TCIC_SCTRL_RSVD) 118 if (val & TCIC_SCTRL_RSVD)
119 return 0; 119 return 0;
120 120
121 DPRINTF(("tcic: chkrsvd 3\n")); 121 DPRINTF(("tcic: chkrsvd 3\n"));
122 /* R_ICSR bit 2 must be same as bit 3. */ 122 /* R_ICSR bit 2 must be same as bit 3. */
123 val = bus_space_read_1(iot, ioh, TCIC_R_ICSR); 123 val = bus_space_read_1(iot, ioh, TCIC_R_ICSR);
124 if (((val >> 1) & 1) != ((val >> 2) & 1)) 124 if (((val >> 1) & 1) != ((val >> 2) & 1))
125 return 0; 125 return 0;
126 126
127 DPRINTF(("tcic: chkrsvd 4\n")); 127 DPRINTF(("tcic: chkrsvd 4\n"));
128 /* R_IENA bits 7,2 are reserverd. */ 128 /* R_IENA bits 7,2 are reserverd. */
129 val = bus_space_read_1(iot, ioh, TCIC_R_IENA); 129 val = bus_space_read_1(iot, ioh, TCIC_R_IENA);
130 if (val & TCIC_IENA_RSVD) 130 if (val & TCIC_IENA_RSVD)
131 return 0; 131 return 0;
132 132
133 DPRINTF(("tcic: chkrsvd 5\n")); 133 DPRINTF(("tcic: chkrsvd 5\n"));
134 /* Some aux registers have reserved bits. */ 134 /* Some aux registers have reserved bits. */
135 /* Which are we looking at? */ 135 /* Which are we looking at? */
136 auxreg = bus_space_read_1(iot, ioh, TCIC_R_MODE) 136 auxreg = bus_space_read_1(iot, ioh, TCIC_R_MODE)
137 & TCIC_AR_MASK; 137 & TCIC_AR_MASK;
138 val = bus_space_read_2(iot, ioh, TCIC_R_AUX); 138 val = bus_space_read_2(iot, ioh, TCIC_R_AUX);
139 DPRINTF(("tcic: auxreg 0x%02x val 0x%04x\n", auxreg, val)); 139 DPRINTF(("tcic: auxreg 0x%02x val 0x%04x\n", auxreg, val));
140 switch (auxreg) { 140 switch (auxreg) {
141 case TCIC_AR_SYSCFG: 141 case TCIC_AR_SYSCFG:
142 if (INVALID_AR_SYSCFG(val)) 142 if (INVALID_AR_SYSCFG(val))
143 return 0; 143 return 0;
144 break; 144 break;
145 case TCIC_AR_ILOCK: 145 case TCIC_AR_ILOCK:
146 if (INVALID_AR_ILOCK(val)) 146 if (INVALID_AR_ILOCK(val))
147 return 0; 147 return 0;
148 break; 148 break;
149 case TCIC_AR_TEST: 149 case TCIC_AR_TEST:
150 if (INVALID_AR_TEST(val)) 150 if (INVALID_AR_TEST(val))
151 return 0; 151 return 0;
152 break; 152 break;
153 } 153 }
154 154
155 DPRINTF(("tcic: chkrsvd 6\n")); 155 DPRINTF(("tcic: chkrsvd 6\n"));
156 /* XXX fails if pcmcia bios is enabled. */ 156 /* XXX fails if pcmcia bios is enabled. */
157 /* Various bits set or not depending if in RESET mode. */ 157 /* Various bits set or not depending if in RESET mode. */
158 val = bus_space_read_1(iot, ioh, TCIC_R_SCTRL); 158 val = bus_space_read_1(iot, ioh, TCIC_R_SCTRL);
159 if (val & TCIC_SCTRL_RESET) { 159 if (val & TCIC_SCTRL_RESET) {
160 DPRINTF(("tcic: chkrsvd 7\n")); 160 DPRINTF(("tcic: chkrsvd 7\n"));
161 /* Address bits must be 0 */ 161 /* Address bits must be 0 */
162 val = bus_space_read_2(iot, ioh, TCIC_R_ADDR); 162 val = bus_space_read_2(iot, ioh, TCIC_R_ADDR);
163 if (val != 0) 163 if (val != 0)
164 return 0; 164 return 0;
165 val = bus_space_read_2(iot, ioh, TCIC_R_ADDR2); 165 val = bus_space_read_2(iot, ioh, TCIC_R_ADDR2);
166 if (val != 0) 166 if (val != 0)
167 return 0; 167 return 0;
168 DPRINTF(("tcic: chkrsvd 8\n")); 168 DPRINTF(("tcic: chkrsvd 8\n"));
169 /* EDC bits must be 0 */ 169 /* EDC bits must be 0 */
170 val = bus_space_read_2(iot, ioh, TCIC_R_EDC); 170 val = bus_space_read_2(iot, ioh, TCIC_R_EDC);
171 if (val != 0) 171 if (val != 0)
172 return 0; 172 return 0;
173 /* We're OK, so take it out of reset. XXX -chb */ 173 /* We're OK, so take it out of reset. XXX -chb */
174 bus_space_write_1(iot, ioh, TCIC_R_SCTRL, 0); 174 bus_space_write_1(iot, ioh, TCIC_R_SCTRL, 0);
175 } 175 }
176 else { /* not in RESET mode */ 176 else { /* not in RESET mode */
177 int omode; 177 int omode;
178 int val1, val2; 178 int val1, val2;
179 DPRINTF(("tcic: chkrsvd 9\n")); 179 DPRINTF(("tcic: chkrsvd 9\n"));
180 /* Programming timers must have expired. */ 180 /* Programming timers must have expired. */
181 val = bus_space_read_1(iot, ioh, TCIC_R_SSTAT); 181 val = bus_space_read_1(iot, ioh, TCIC_R_SSTAT);
182 if ((val & (TCIC_SSTAT_6US|TCIC_SSTAT_10US|TCIC_SSTAT_PROGTIME)) 182 if ((val & (TCIC_SSTAT_6US|TCIC_SSTAT_10US|TCIC_SSTAT_PROGTIME))
183 != (TCIC_SSTAT_6US|TCIC_SSTAT_10US|TCIC_SSTAT_PROGTIME)) 183 != (TCIC_SSTAT_6US|TCIC_SSTAT_10US|TCIC_SSTAT_PROGTIME))
184 return 0; 184 return 0;
185 DPRINTF(("tcic: chkrsvd 10\n")); 185 DPRINTF(("tcic: chkrsvd 10\n"));
186 /* 186 /*
187 * EDC bits should change on read from data space 187 * EDC bits should change on read from data space
188 * as long as either EDC or the data are nonzero. 188 * as long as either EDC or the data are nonzero.
189 */ 189 */
190 if ((bus_space_read_2(iot, ioh, TCIC_R_ADDR2) 190 if ((bus_space_read_2(iot, ioh, TCIC_R_ADDR2)
191 & TCIC_ADDR2_INDREG) != 0) { 191 & TCIC_ADDR2_INDREG) != 0) {
192 val1 = bus_space_read_2(iot, ioh, TCIC_R_EDC); 192 val1 = bus_space_read_2(iot, ioh, TCIC_R_EDC);
193 val2 = bus_space_read_2(iot, ioh, TCIC_R_DATA); 193 val2 = bus_space_read_2(iot, ioh, TCIC_R_DATA);
194 if (val1 | val2) { 194 if (val1 | val2) {
195 val1 = bus_space_read_2(iot, ioh, TCIC_R_EDC); 195 val1 = bus_space_read_2(iot, ioh, TCIC_R_EDC);
196 if (val1 == val2) 196 if (val1 == val2)
197 return 0; 197 return 0;
198 } 198 }
199 } 199 }
200 DPRINTF(("tcic: chkrsvd 11\n")); 200 DPRINTF(("tcic: chkrsvd 11\n"));
201 /* XXX what does this check? -chb */ 201 /* XXX what does this check? -chb */
202 omode = bus_space_read_1(iot, ioh, TCIC_R_MODE); 202 omode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
203 val1 = omode ^ TCIC_AR_MASK; 203 val1 = omode ^ TCIC_AR_MASK;
204 bus_space_write_1(iot, ioh, TCIC_R_MODE, val1); 204 bus_space_write_1(iot, ioh, TCIC_R_MODE, val1);
205 val2 = bus_space_read_1(iot, ioh, TCIC_R_MODE); 205 val2 = bus_space_read_1(iot, ioh, TCIC_R_MODE);
206 bus_space_write_1(iot, ioh, TCIC_R_MODE, omode); 206 bus_space_write_1(iot, ioh, TCIC_R_MODE, omode);
207 if ( val1 != val2) 207 if ( val1 != val2)
208 return 0; 208 return 0;
209 } 209 }
210 /* All tests passed */ 210 /* All tests passed */
211 return 1; 211 return 1;
212} 212}
213 213
214/* 214/*
215 * Read chip ID from AR_ILOCK in test mode. 215 * Read chip ID from AR_ILOCK in test mode.
216 */ 216 */
217int 217int
218tcic_chipid(bus_space_tag_t iot, bus_space_handle_t ioh) 218tcic_chipid(bus_space_tag_t iot, bus_space_handle_t ioh)
219{ 219{
220 unsigned id, otest; 220 unsigned id, otest;
221 221
222 otest = tcic_read_aux_2(iot, ioh, TCIC_AR_TEST); 222 otest = tcic_read_aux_2(iot, ioh, TCIC_AR_TEST);
223 tcic_write_aux_2(iot, ioh, TCIC_AR_TEST, TCIC_TEST_DIAG); 223 tcic_write_aux_2(iot, ioh, TCIC_AR_TEST, TCIC_TEST_DIAG);
224 id = tcic_read_aux_2(iot, ioh, TCIC_AR_ILOCK); 224 id = tcic_read_aux_2(iot, ioh, TCIC_AR_ILOCK);
225 tcic_write_aux_2(iot, ioh, TCIC_AR_TEST, otest); 225 tcic_write_aux_2(iot, ioh, TCIC_AR_TEST, otest);
226 id &= TCIC_ILOCKTEST_ID_MASK; 226 id &= TCIC_ILOCKTEST_ID_MASK;
227 id >>= TCIC_ILOCKTEST_ID_SHFT; 227 id >>= TCIC_ILOCKTEST_ID_SHFT;
228 228
229 /* clear up IRQs inside tcic. XXX -chb */ 229 /* clear up IRQs inside tcic. XXX -chb */
230 while (bus_space_read_1(iot, ioh, TCIC_R_ICSR)) 230 while (bus_space_read_1(iot, ioh, TCIC_R_ICSR))
231 bus_space_write_1(iot, ioh, TCIC_R_ICSR, TCIC_ICSR_JAM); 231 bus_space_write_1(iot, ioh, TCIC_R_ICSR, TCIC_ICSR_JAM);
232 232
233 return id; 233 return id;
234} 234}
235/* 235/*
236 * Indicate whether the driver can handle the chip. 236 * Indicate whether the driver can handle the chip.
237 */ 237 */
238int 238int
239tcic_chipid_known(int id) 239tcic_chipid_known(int id)
240{ 240{
241 /* XXX only know how to handle DB86082 -chb */ 241 /* XXX only know how to handle DB86082 -chb */
242 switch (id) { 242 switch (id) {
243 case TCIC_CHIPID_DB86082_1: 243 case TCIC_CHIPID_DB86082_1:
244 case TCIC_CHIPID_DB86082A: 244 case TCIC_CHIPID_DB86082A:
245 case TCIC_CHIPID_DB86082B_ES: 245 case TCIC_CHIPID_DB86082B_ES:
246 case TCIC_CHIPID_DB86082B: 246 case TCIC_CHIPID_DB86082B:
247 case TCIC_CHIPID_DB86084_1: 247 case TCIC_CHIPID_DB86084_1:
248 case TCIC_CHIPID_DB86084A: 248 case TCIC_CHIPID_DB86084A:
249 case TCIC_CHIPID_DB86184_1: 249 case TCIC_CHIPID_DB86184_1:
250 case TCIC_CHIPID_DB86072_1_ES: 250 case TCIC_CHIPID_DB86072_1_ES:
251 case TCIC_CHIPID_DB86072_1: 251 case TCIC_CHIPID_DB86072_1:
252 return 1; 252 return 1;
253 } 253 }
254 254
255 return 0; 255 return 0;
256} 256}
257 257
258const char * 258const char *
259tcic_chipid_to_string(int id) 259tcic_chipid_to_string(int id)
260{ 260{
261 switch (id) { 261 switch (id) {
262 case TCIC_CHIPID_DB86082_1: 262 case TCIC_CHIPID_DB86082_1:
263 return ("Databook DB86082"); 263 return ("Databook DB86082");
264 case TCIC_CHIPID_DB86082A: 264 case TCIC_CHIPID_DB86082A:
265 return ("Databook DB86082A"); 265 return ("Databook DB86082A");
266 case TCIC_CHIPID_DB86082B_ES: 266 case TCIC_CHIPID_DB86082B_ES:
267 return ("Databook DB86082B-es"); 267 return ("Databook DB86082B-es");
268 case TCIC_CHIPID_DB86082B: 268 case TCIC_CHIPID_DB86082B:
269 return ("Databook DB86082B"); 269 return ("Databook DB86082B");
270 case TCIC_CHIPID_DB86084_1: 270 case TCIC_CHIPID_DB86084_1:
271 return ("Databook DB86084"); 271 return ("Databook DB86084");
272 case TCIC_CHIPID_DB86084A: 272 case TCIC_CHIPID_DB86084A:
273 return ("Databook DB86084A"); 273 return ("Databook DB86084A");
274 case TCIC_CHIPID_DB86184_1: 274 case TCIC_CHIPID_DB86184_1:
275 return ("Databook DB86184"); 275 return ("Databook DB86184");
276 case TCIC_CHIPID_DB86072_1_ES: 276 case TCIC_CHIPID_DB86072_1_ES:
277 return ("Databook DB86072-es"); 277 return ("Databook DB86072-es");
278 case TCIC_CHIPID_DB86072_1: 278 case TCIC_CHIPID_DB86072_1:
279 return ("Databook DB86072"); 279 return ("Databook DB86072");
280 } 280 }
281 281
282 return ("Unknown controller"); 282 return ("Unknown controller");
283} 283}
284/* 284/*
285 * Return bitmask of IRQs that the chip can handle. 285 * Return bitmask of IRQs that the chip can handle.
286 * XXX should be table driven. 286 * XXX should be table driven.
287 */ 287 */
288int 288int
289tcic_validirqs(int chipid) 289tcic_validirqs(int chipid)
290{ 290{
291 switch (chipid) { 291 switch (chipid) {
292 case TCIC_CHIPID_DB86082_1: 292 case TCIC_CHIPID_DB86082_1:
293 case TCIC_CHIPID_DB86082A: 293 case TCIC_CHIPID_DB86082A:
294 case TCIC_CHIPID_DB86082B_ES: 294 case TCIC_CHIPID_DB86082B_ES:
295 case TCIC_CHIPID_DB86082B: 295 case TCIC_CHIPID_DB86082B:
296 case TCIC_CHIPID_DB86084_1: 296 case TCIC_CHIPID_DB86084_1:
297 case TCIC_CHIPID_DB86084A: 297 case TCIC_CHIPID_DB86084A:
298 case TCIC_CHIPID_DB86184_1: 298 case TCIC_CHIPID_DB86184_1:
299 case TCIC_CHIPID_DB86072_1_ES: 299 case TCIC_CHIPID_DB86072_1_ES:
300 case TCIC_CHIPID_DB86072_1: 300 case TCIC_CHIPID_DB86072_1:
301 return tcic_valid_irqs; 301 return tcic_valid_irqs;
302 } 302 }
303 return 0; 303 return 0;
304} 304}
305 305
306void 306void
307tcic_attach(struct tcic_softc *sc) 307tcic_attach(struct tcic_softc *sc)
308{ 308{
309 int i, reg; 309 int i, reg;
310 310
311 /* set more chipset dependent parameters in the softc. */ 311 /* set more chipset dependent parameters in the softc. */
312 switch (sc->chipid) { 312 switch (sc->chipid) {
313 case TCIC_CHIPID_DB86084_1: 313 case TCIC_CHIPID_DB86084_1:
314 case TCIC_CHIPID_DB86084A: 314 case TCIC_CHIPID_DB86084A:
315 case TCIC_CHIPID_DB86184_1: 315 case TCIC_CHIPID_DB86184_1:
316 sc->pwrena = TCIC_PWR_ENA; 316 sc->pwrena = TCIC_PWR_ENA;
317 break; 317 break;
318 default: 318 default:
319 sc->pwrena = 0; 319 sc->pwrena = 0;
320 break; 320 break;
321 } 321 }
322 322
323 /* set up global config registers */ 323 /* set up global config registers */
324 reg = TCIC_WAIT_SYNC | TCIC_WAIT_CCLK | TCIC_WAIT_RISING; 324 reg = TCIC_WAIT_SYNC | TCIC_WAIT_CCLK | TCIC_WAIT_RISING;
325 reg |= (tcic_ns2wscnt(250) & TCIC_WAIT_COUNT_MASK); 325 reg |= (tcic_ns2wscnt(250) & TCIC_WAIT_COUNT_MASK);
326 tcic_write_aux_1(sc->iot, sc->ioh, TCIC_AR_WCTL, TCIC_R_WCTL_WAIT, reg); 326 tcic_write_aux_1(sc->iot, sc->ioh, TCIC_AR_WCTL, TCIC_R_WCTL_WAIT, reg);
327 reg = TCIC_SYSCFG_MPSEL_RI | TCIC_SYSCFG_MCSFULL; 327 reg = TCIC_SYSCFG_MPSEL_RI | TCIC_SYSCFG_MCSFULL;
328 tcic_write_aux_2(sc->iot, sc->ioh, TCIC_AR_SYSCFG, reg); 328 tcic_write_aux_2(sc->iot, sc->ioh, TCIC_AR_SYSCFG, reg);
329 reg = tcic_read_aux_2(sc->iot, sc->ioh, TCIC_AR_ILOCK); 329 reg = tcic_read_aux_2(sc->iot, sc->ioh, TCIC_AR_ILOCK);
330 reg |= TCIC_ILOCK_HOLD_CCLK; 330 reg |= TCIC_ILOCK_HOLD_CCLK;
331 tcic_write_aux_2(sc->iot, sc->ioh, TCIC_AR_ILOCK, reg); 331 tcic_write_aux_2(sc->iot, sc->ioh, TCIC_AR_ILOCK, reg);
332 332
333 /* the TCIC has two sockets */ 333 /* the TCIC has two sockets */
334 /* XXX should i check for actual presence of sockets? -chb */ 334 /* XXX should i check for actual presence of sockets? -chb */
335 for (i = 0; i < TCIC_NSLOTS; i++) { 335 for (i = 0; i < TCIC_NSLOTS; i++) {
336 sc->handle[i].sc = sc; 336 sc->handle[i].sc = sc;
337 sc->handle[i].sock = i; 337 sc->handle[i].sock = i;
338 sc->handle[i].flags = TCIC_FLAG_SOCKETP; 338 sc->handle[i].flags = TCIC_FLAG_SOCKETP;
339 sc->handle[i].memwins 339 sc->handle[i].memwins
340 = sc->chipid == TCIC_CHIPID_DB86082_1 ? 4 : 5; 340 = sc->chipid == TCIC_CHIPID_DB86082_1 ? 4 : 5;
341 } 341 }
342 342
343 /* establish the interrupt */ 343 /* establish the interrupt */
344 reg = tcic_read_1(&sc->handle[0], TCIC_R_IENA); 344 reg = tcic_read_1(&sc->handle[0], TCIC_R_IENA);
345 tcic_write_1(&sc->handle[0], TCIC_R_IENA, 345 tcic_write_1(&sc->handle[0], TCIC_R_IENA,
346 (reg & ~TCIC_IENA_CFG_MASK) | TCIC_IENA_CFG_HIGH); 346 (reg & ~TCIC_IENA_CFG_MASK) | TCIC_IENA_CFG_HIGH);
347 reg = tcic_read_aux_2(sc->iot, sc->ioh, TCIC_AR_SYSCFG); 347 reg = tcic_read_aux_2(sc->iot, sc->ioh, TCIC_AR_SYSCFG);
348 tcic_write_aux_2(sc->iot, sc->ioh, TCIC_AR_SYSCFG, 348 tcic_write_aux_2(sc->iot, sc->ioh, TCIC_AR_SYSCFG,
349 (reg & ~TCIC_SYSCFG_IRQ_MASK) | tcic_irqmap[sc->irq]); 349 (reg & ~TCIC_SYSCFG_IRQ_MASK) | tcic_irqmap[sc->irq]);
350 350
351 /* XXX block interrupts? */ 351 /* XXX block interrupts? */
352 352
353 for (i = 0; i < TCIC_NSLOTS; i++) { 353 for (i = 0; i < TCIC_NSLOTS; i++) {
354 /* XXX make more clear what happens here -chb */ 354 /* XXX make more clear what happens here -chb */
355 tcic_sel_sock(&sc->handle[i]); 355 tcic_sel_sock(&sc->handle[i]);
356 tcic_write_ind_2(&sc->handle[i], TCIC_IR_SCF1_N(i), 0); 356 tcic_write_ind_2(&sc->handle[i], TCIC_IR_SCF1_N(i), 0);
357 tcic_write_ind_2(&sc->handle[i], TCIC_IR_SCF2_N(i), 357 tcic_write_ind_2(&sc->handle[i], TCIC_IR_SCF2_N(i),
358 (TCIC_SCF2_MCD|TCIC_SCF2_MWP|TCIC_SCF2_MRDY 358 (TCIC_SCF2_MCD|TCIC_SCF2_MWP|TCIC_SCF2_MRDY
359#if 1 /* XXX explain byte routing issue */ 359#if 1 /* XXX explain byte routing issue */
360 |TCIC_SCF2_MLBAT2|TCIC_SCF2_MLBAT1|TCIC_SCF2_IDBR)); 360 |TCIC_SCF2_MLBAT2|TCIC_SCF2_MLBAT1|TCIC_SCF2_IDBR));
361#else 361#else
362 |TCIC_SCF2_MLBAT2|TCIC_SCF2_MLBAT1)); 362 |TCIC_SCF2_MLBAT2|TCIC_SCF2_MLBAT1));
363#endif 363#endif
364 tcic_write_1(&sc->handle[i], TCIC_R_MODE, 0); 364 tcic_write_1(&sc->handle[i], TCIC_R_MODE, 0);
365 reg = tcic_read_aux_2(sc->iot, sc->ioh, TCIC_AR_SYSCFG); 365 reg = tcic_read_aux_2(sc->iot, sc->ioh, TCIC_AR_SYSCFG);
366 reg &= ~TCIC_SYSCFG_AUTOBUSY; 366 reg &= ~TCIC_SYSCFG_AUTOBUSY;
367 tcic_write_aux_2(sc->iot, sc->ioh, TCIC_AR_SYSCFG, reg); 367 tcic_write_aux_2(sc->iot, sc->ioh, TCIC_AR_SYSCFG, reg);
368 SIMPLEQ_INIT(&sc->handle[i].events); 368 SIMPLEQ_INIT(&sc->handle[i].events);
369 } 369 }
370 370
371 if ((sc->handle[0].flags & TCIC_FLAG_SOCKETP) || 371 if ((sc->handle[0].flags & TCIC_FLAG_SOCKETP) ||
372 (sc->handle[1].flags & TCIC_FLAG_SOCKETP)) { 372 (sc->handle[1].flags & TCIC_FLAG_SOCKETP)) {
373 printf("%s: %s has ", device_xname(&sc->dev), 373 printf("%s: %s has ", device_xname(&sc->dev),
374 tcic_chipid_to_string(sc->chipid)); 374 tcic_chipid_to_string(sc->chipid));
375 375
376 if ((sc->handle[0].flags & TCIC_FLAG_SOCKETP) && 376 if ((sc->handle[0].flags & TCIC_FLAG_SOCKETP) &&
377 (sc->handle[1].flags & TCIC_FLAG_SOCKETP)) 377 (sc->handle[1].flags & TCIC_FLAG_SOCKETP))
378 printf("sockets A and B\n"); 378 printf("sockets A and B\n");
379 else if (sc->handle[0].flags & TCIC_FLAG_SOCKETP) 379 else if (sc->handle[0].flags & TCIC_FLAG_SOCKETP)
380 printf("socket A only\n"); 380 printf("socket A only\n");
381 else 381 else
382 printf("socket B only\n"); 382 printf("socket B only\n");
383 383
384 } 384 }
385} 385}
386 386
387void 387void
388tcic_attach_sockets(struct tcic_softc *sc) 388tcic_attach_sockets(struct tcic_softc *sc)
389{ 389{
390 int i; 390 int i;
391 391
392 for (i = 0; i < TCIC_NSLOTS; i++) 392 for (i = 0; i < TCIC_NSLOTS; i++)
393 if (sc->handle[i].flags & TCIC_FLAG_SOCKETP) 393 if (sc->handle[i].flags & TCIC_FLAG_SOCKETP)
394 tcic_attach_socket(&sc->handle[i]); 394 tcic_attach_socket(&sc->handle[i]);
395} 395}
396 396
397void 397void
398tcic_attach_socket(struct tcic_handle *h) 398tcic_attach_socket(struct tcic_handle *h)
399{ 399{
400 struct pcmciabus_attach_args paa; 400 struct pcmciabus_attach_args paa;
401 int locs[PCMCIABUSCF_NLOCS]; 401 int locs[PCMCIABUSCF_NLOCS];
402 402
403 /* initialize the rest of the handle */ 403 /* initialize the rest of the handle */
404 404
405 h->shutdown = 0; 405 h->shutdown = 0;
406 h->memalloc = 0; 406 h->memalloc = 0;
407 h->ioalloc = 0; 407 h->ioalloc = 0;
408 h->ih_irq = 0; 408 h->ih_irq = 0;
409 409
410 /* now, config one pcmcia device per socket */ 410 /* now, config one pcmcia device per socket */
411 411
412 paa.paa_busname = "pcmcia"; 412 paa.paa_busname = "pcmcia";
413 paa.pct = (pcmcia_chipset_tag_t) h->sc->pct; 413 paa.pct = (pcmcia_chipset_tag_t) h->sc->pct;
414 paa.pch = (pcmcia_chipset_handle_t) h; 414 paa.pch = (pcmcia_chipset_handle_t) h;
415 paa.iobase = h->sc->iobase; 
416 paa.iosize = h->sc->iosize; 
417 415
418 locs[PCMCIABUSCF_CONTROLLER] = 0; 416 locs[PCMCIABUSCF_CONTROLLER] = 0;
419 locs[PCMCIABUSCF_SOCKET] = h->sock; 417 locs[PCMCIABUSCF_SOCKET] = h->sock;
420 418
421 h->pcmcia = config_found_sm_loc(&h->sc->dev, "pcmciabus", locs, &paa, 419 h->pcmcia = config_found_sm_loc(&h->sc->dev, "pcmciabus", locs, &paa,
422 tcic_print, config_stdsubmatch); 420 tcic_print, config_stdsubmatch);
423 421
424 /* if there's actually a pcmcia device attached, initialize the slot */ 422 /* if there's actually a pcmcia device attached, initialize the slot */
425 423
426 if (h->pcmcia) 424 if (h->pcmcia)
427 tcic_init_socket(h); 425 tcic_init_socket(h);
428} 426}
429 427
430void 428void
431tcic_create_event_thread(void *arg) 429tcic_create_event_thread(void *arg)
432{ 430{
433 struct tcic_handle *h = arg; 431 struct tcic_handle *h = arg;
434 const char *cs; 432 const char *cs;
435 433
436 switch (h->sock) { 434 switch (h->sock) {
437 case 0: 435 case 0:
438 cs = "0"; 436 cs = "0";
439 break; 437 break;
440 case 1: 438 case 1:
441 cs = "1"; 439 cs = "1";
442 break; 440 break;
443 default: 441 default:
444 panic("tcic_create_event_thread: unknown tcic socket"); 442 panic("tcic_create_event_thread: unknown tcic socket");
445 } 443 }
446 444
447 if (kthread_create(PRI_NONE, 0, NULL, tcic_event_thread, h, 445 if (kthread_create(PRI_NONE, 0, NULL, tcic_event_thread, h,
448 &h->event_thread, "%s,%s", device_xname(&h->sc->dev), cs)) { 446 &h->event_thread, "%s,%s", device_xname(&h->sc->dev), cs)) {
449 aprint_error_dev(&h->sc->dev, "unable to create event thread for sock 0x%02x\n", h->sock); 447 aprint_error_dev(&h->sc->dev, "unable to create event thread for sock 0x%02x\n", h->sock);
450 panic("tcic_create_event_thread"); 448 panic("tcic_create_event_thread");
451 } 449 }
452} 450}
453 451
454void 452void
455tcic_event_thread(void *arg) 453tcic_event_thread(void *arg)
456{ 454{
457 struct tcic_handle *h = arg; 455 struct tcic_handle *h = arg;
458 struct tcic_event *pe; 456 struct tcic_event *pe;
459 int s; 457 int s;
460 458
461 while (h->shutdown == 0) { 459 while (h->shutdown == 0) {
462 s = splhigh(); 460 s = splhigh();
463 if ((pe = SIMPLEQ_FIRST(&h->events)) == NULL) { 461 if ((pe = SIMPLEQ_FIRST(&h->events)) == NULL) {
464 splx(s); 462 splx(s);
465 (void) tsleep(&h->events, PWAIT, "tcicev", 0); 463 (void) tsleep(&h->events, PWAIT, "tcicev", 0);
466 continue; 464 continue;
467 } 465 }
468 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q); 466 SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
469 splx(s); 467 splx(s);
470 468
471 switch (pe->pe_type) { 469 switch (pe->pe_type) {
472 case TCIC_EVENT_INSERTION: 470 case TCIC_EVENT_INSERTION:
473 DPRINTF(("%s: insertion event\n", device_xname(&h->sc->dev))); 471 DPRINTF(("%s: insertion event\n", device_xname(&h->sc->dev)));
474 tcic_attach_card(h); 472 tcic_attach_card(h);
475 break; 473 break;
476 474
477 case TCIC_EVENT_REMOVAL: 475 case TCIC_EVENT_REMOVAL:
478 DPRINTF(("%s: removal event\n", device_xname(&h->sc->dev))); 476 DPRINTF(("%s: removal event\n", device_xname(&h->sc->dev)));
479 tcic_detach_card(h, DETACH_FORCE); 477 tcic_detach_card(h, DETACH_FORCE);
480 break; 478 break;
481 479
482 default: 480 default:
483 panic("tcic_event_thread: unknown event %d", 481 panic("tcic_event_thread: unknown event %d",
484 pe->pe_type); 482 pe->pe_type);
485 } 483 }
486 free(pe, M_TEMP); 484 free(pe, M_TEMP);
487 } 485 }
488 486
489 h->event_thread = NULL; 487 h->event_thread = NULL;
490 488
491 /* In case parent is waiting for us to exit. */ 489 /* In case parent is waiting for us to exit. */
492 wakeup(h->sc); 490 wakeup(h->sc);
493 491
494 kthread_exit(0); 492 kthread_exit(0);
495} 493}
496 494
497 495
498void 496void
499tcic_init_socket(struct tcic_handle *h) 497tcic_init_socket(struct tcic_handle *h)
500{ 498{
501 int reg; 499 int reg;
502 500
503 /* select this socket's config registers */ 501 /* select this socket's config registers */
504 tcic_sel_sock(h); 502 tcic_sel_sock(h);
505 503
506 /* set up the socket to interrupt on card detect */ 504 /* set up the socket to interrupt on card detect */
507 reg = tcic_read_ind_2(h, TCIC_IR_SCF2_N(h->sock)); 505 reg = tcic_read_ind_2(h, TCIC_IR_SCF2_N(h->sock));
508 tcic_write_ind_2(h, TCIC_IR_SCF2_N(h->sock), reg & ~TCIC_SCF2_MCD); 506 tcic_write_ind_2(h, TCIC_IR_SCF2_N(h->sock), reg & ~TCIC_SCF2_MCD);
509 507
510 /* enable CD irq in R_IENA */ 508 /* enable CD irq in R_IENA */
511 reg = tcic_read_2(h, TCIC_R_IENA); 509 reg = tcic_read_2(h, TCIC_R_IENA);
512 tcic_write_2(h, TCIC_R_IENA, reg |= TCIC_IENA_CDCHG); 510 tcic_write_2(h, TCIC_R_IENA, reg |= TCIC_IENA_CDCHG);
513 511
514 /* if there's a card there, then attach it. also save sstat */ 512 /* if there's a card there, then attach it. also save sstat */
515 h->sstat = reg = tcic_read_1(h, TCIC_R_SSTAT) & TCIC_SSTAT_STAT_MASK; 513 h->sstat = reg = tcic_read_1(h, TCIC_R_SSTAT) & TCIC_SSTAT_STAT_MASK;
516 if (reg & TCIC_SSTAT_CD) 514 if (reg & TCIC_SSTAT_CD)
517 tcic_attach_card(h); 515 tcic_attach_card(h);
518} 516}
519 517
520int 518int
521tcic_print(void *arg, const char *pnp) 519tcic_print(void *arg, const char *pnp)
522{ 520{
523 struct pcmciabus_attach_args *paa = arg; 521 struct pcmciabus_attach_args *paa = arg;
524 struct tcic_handle *h = (struct tcic_handle *) paa->pch; 522 struct tcic_handle *h = (struct tcic_handle *) paa->pch;
525 523
526 /* Only "pcmcia"s can attach to "tcic"s... easy. */ 524 /* Only "pcmcia"s can attach to "tcic"s... easy. */
527 if (pnp) 525 if (pnp)
528 aprint_normal("pcmcia at %s", pnp); 526 aprint_normal("pcmcia at %s", pnp);
529 527
530 aprint_normal(" socket %d", h->sock); 528 aprint_normal(" socket %d", h->sock);
531 529
532 return (UNCONF); 530 return (UNCONF);
533} 531}
534 532
535int 533int
536tcic_intr(void *arg) 534tcic_intr(void *arg)
537{ 535{
538 struct tcic_softc *sc = arg; 536 struct tcic_softc *sc = arg;
539 int i, ret = 0; 537 int i, ret = 0;
540 538
541 DPRINTF(("%s: intr\n", device_xname(&sc->dev))); 539 DPRINTF(("%s: intr\n", device_xname(&sc->dev)));
542 540
543 for (i = 0; i < TCIC_NSLOTS; i++) 541 for (i = 0; i < TCIC_NSLOTS; i++)
544 if (sc->handle[i].flags & TCIC_FLAG_SOCKETP) 542 if (sc->handle[i].flags & TCIC_FLAG_SOCKETP)
545 ret += tcic_intr_socket(&sc->handle[i]); 543 ret += tcic_intr_socket(&sc->handle[i]);
546 544
547 return (ret ? 1 : 0); 545 return (ret ? 1 : 0);
548} 546}
549 547
550int 548int
551tcic_intr_socket(struct tcic_handle *h) 549tcic_intr_socket(struct tcic_handle *h)
552{ 550{
553 int icsr, rv; 551 int icsr, rv;
554 552
555 rv = 0; 553 rv = 0;
556 tcic_sel_sock(h); 554 tcic_sel_sock(h);
557 icsr = tcic_read_1(h, TCIC_R_ICSR); 555 icsr = tcic_read_1(h, TCIC_R_ICSR);
558 556
559 DPRINTF(("%s: %d icsr: 0x%02x \n", device_xname(&h->sc->dev), h->sock, icsr)); 557 DPRINTF(("%s: %d icsr: 0x%02x \n", device_xname(&h->sc->dev), h->sock, icsr));
560 558
561 /* XXX or should the next three be handled in tcic_intr? -chb */ 559 /* XXX or should the next three be handled in tcic_intr? -chb */
562 if (icsr & TCIC_ICSR_PROGTIME) { 560 if (icsr & TCIC_ICSR_PROGTIME) {
563 DPRINTF(("%s: %02x PROGTIME\n", device_xname(&h->sc->dev), h->sock)); 561 DPRINTF(("%s: %02x PROGTIME\n", device_xname(&h->sc->dev), h->sock));
564 rv = 1; 562 rv = 1;
565 } 563 }
566 if (icsr & TCIC_ICSR_ILOCK) { 564 if (icsr & TCIC_ICSR_ILOCK) {
567 DPRINTF(("%s: %02x ILOCK\n", device_xname(&h->sc->dev), h->sock)); 565 DPRINTF(("%s: %02x ILOCK\n", device_xname(&h->sc->dev), h->sock));
568 rv = 1; 566 rv = 1;
569 } 567 }
570 if (icsr & TCIC_ICSR_ERR) { 568 if (icsr & TCIC_ICSR_ERR) {
571 DPRINTF(("%s: %02x ERR\n", device_xname(&h->sc->dev), h->sock)); 569 DPRINTF(("%s: %02x ERR\n", device_xname(&h->sc->dev), h->sock));
572 rv = 1; 570 rv = 1;
573 } 571 }
574 if (icsr & TCIC_ICSR_CDCHG) { 572 if (icsr & TCIC_ICSR_CDCHG) {
575 int sstat, delta; 573 int sstat, delta;
576 574
577 /* compute what changed since last interrupt */ 575 /* compute what changed since last interrupt */
578 sstat = tcic_read_aux_1(h->sc->iot, h->sc->ioh, 576 sstat = tcic_read_aux_1(h->sc->iot, h->sc->ioh,
579 TCIC_AR_WCTL, TCIC_R_WCTL_XCSR) & TCIC_XCSR_STAT_MASK; 577 TCIC_AR_WCTL, TCIC_R_WCTL_XCSR) & TCIC_XCSR_STAT_MASK;
580 delta = h->sstat ^ sstat; 578 delta = h->sstat ^ sstat;
581 h->sstat = sstat; 579 h->sstat = sstat;
582 580
583 if (delta) 581 if (delta)
584 rv = 1; 582 rv = 1;
585 583
586 DPRINTF(("%s: %02x CDCHG %x\n", device_xname(&h->sc->dev), h->sock, 584 DPRINTF(("%s: %02x CDCHG %x\n", device_xname(&h->sc->dev), h->sock,
587 delta)); 585 delta));
588 586
589 /* 587 /*
590 * XXX This should probably schedule something to happen 588 * XXX This should probably schedule something to happen
591 * after the interrupt handler completes 589 * after the interrupt handler completes
592 */ 590 */
593 591
594 if (delta & TCIC_SSTAT_CD) { 592 if (delta & TCIC_SSTAT_CD) {
595 if (sstat & TCIC_SSTAT_CD) { 593 if (sstat & TCIC_SSTAT_CD) {
596 if (!(h->flags & TCIC_FLAG_CARDP)) { 594 if (!(h->flags & TCIC_FLAG_CARDP)) {
597 DPRINTF(("%s: enqueing INSERTION event\n", 595 DPRINTF(("%s: enqueing INSERTION event\n",
598 device_xname(&h->sc->dev))); 596 device_xname(&h->sc->dev)));
599 tcic_queue_event(h, TCIC_EVENT_INSERTION); 597 tcic_queue_event(h, TCIC_EVENT_INSERTION);
600 } 598 }
601 } else { 599 } else {
602 if (h->flags & TCIC_FLAG_CARDP) { 600 if (h->flags & TCIC_FLAG_CARDP) {
603 /* Deactivate the card now. */ 601 /* Deactivate the card now. */
604 DPRINTF(("%s: deactivating card\n", 602 DPRINTF(("%s: deactivating card\n",
605 device_xname(&h->sc->dev))); 603 device_xname(&h->sc->dev)));
606 tcic_deactivate_card(h); 604 tcic_deactivate_card(h);
607 605
608 DPRINTF(("%s: enqueing REMOVAL event\n", 606 DPRINTF(("%s: enqueing REMOVAL event\n",
609 device_xname(&h->sc->dev))); 607 device_xname(&h->sc->dev)));
610 tcic_queue_event(h, TCIC_EVENT_REMOVAL); 608 tcic_queue_event(h, TCIC_EVENT_REMOVAL);
611 } 609 }
612 } 610 }
613 } 611 }
614 if (delta & TCIC_SSTAT_RDY) { 612 if (delta & TCIC_SSTAT_RDY) {
615 DPRINTF(("%s: %02x READY\n", device_xname(&h->sc->dev), h->sock)); 613 DPRINTF(("%s: %02x READY\n", device_xname(&h->sc->dev), h->sock));
616 /* shouldn't happen */ 614 /* shouldn't happen */
617 } 615 }
618 if (delta & TCIC_SSTAT_LBAT1) { 616 if (delta & TCIC_SSTAT_LBAT1) {
619 DPRINTF(("%s: %02x LBAT1\n", device_xname(&h->sc->dev), h->sock)); 617 DPRINTF(("%s: %02x LBAT1\n", device_xname(&h->sc->dev), h->sock));
620 } 618 }
621 if (delta & TCIC_SSTAT_LBAT2) { 619 if (delta & TCIC_SSTAT_LBAT2) {
622 DPRINTF(("%s: %02x LBAT2\n", device_xname(&h->sc->dev), h->sock)); 620 DPRINTF(("%s: %02x LBAT2\n", device_xname(&h->sc->dev), h->sock));
623 } 621 }
624 if (delta & TCIC_SSTAT_WP) { 622 if (delta & TCIC_SSTAT_WP) {
625 DPRINTF(("%s: %02x WP\n", device_xname(&h->sc->dev), h->sock)); 623 DPRINTF(("%s: %02x WP\n", device_xname(&h->sc->dev), h->sock));
626 } 624 }
627 } 625 }
628 return rv; 626 return rv;
629} 627}
630 628
631void 629void
632tcic_queue_event(struct tcic_handle *h, int event) 630tcic_queue_event(struct tcic_handle *h, int event)
633{ 631{
634 struct tcic_event *pe; 632 struct tcic_event *pe;
635 int s; 633 int s;
636 634
637 pe = malloc(sizeof(*pe), M_TEMP, M_NOWAIT); 635 pe = malloc(sizeof(*pe), M_TEMP, M_NOWAIT);
638 if (pe == NULL) 636 if (pe == NULL)
639 panic("tcic_queue_event: can't allocate event"); 637 panic("tcic_queue_event: can't allocate event");
640 638
641 pe->pe_type = event; 639 pe->pe_type = event;
642 s = splhigh(); 640 s = splhigh();
643 SIMPLEQ_INSERT_TAIL(&h->events, pe, pe_q); 641 SIMPLEQ_INSERT_TAIL(&h->events, pe, pe_q);
644 splx(s); 642 splx(s);
645 wakeup(&h->events); 643 wakeup(&h->events);
646} 644}
647void 645void
648tcic_attach_card(struct tcic_handle *h) 646tcic_attach_card(struct tcic_handle *h)
649{ 647{
650 DPRINTF(("tcic_attach_card\n")); 648 DPRINTF(("tcic_attach_card\n"));
651 649
652 if (h->flags & TCIC_FLAG_CARDP) 650 if (h->flags & TCIC_FLAG_CARDP)
653 panic("tcic_attach_card: already attached"); 651 panic("tcic_attach_card: already attached");
654 652
655 /* call the MI attach function */ 653 /* call the MI attach function */
656 654
657 pcmcia_card_attach(h->pcmcia); 655 pcmcia_card_attach(h->pcmcia);
658 656
659 h->flags |= TCIC_FLAG_CARDP; 657 h->flags |= TCIC_FLAG_CARDP;
660} 658}
661 659
662void 660void
663tcic_detach_card(struct tcic_handle *h, int flags) 661tcic_detach_card(struct tcic_handle *h, int flags)
664 /* flags: DETACH_* */ 662 /* flags: DETACH_* */
665{ 663{
666 DPRINTF(("tcic_detach_card\n")); 664 DPRINTF(("tcic_detach_card\n"));
667 665
668 if (!(h->flags & TCIC_FLAG_CARDP)) 666 if (!(h->flags & TCIC_FLAG_CARDP))
669 panic("tcic_detach_card: already detached"); 667 panic("tcic_detach_card: already detached");
670 668
671 h->flags &= ~TCIC_FLAG_CARDP; 669 h->flags &= ~TCIC_FLAG_CARDP;
672 670
673 /* call the MI detach function */ 671 /* call the MI detach function */
674 672
675 pcmcia_card_detach(h->pcmcia, flags); 673 pcmcia_card_detach(h->pcmcia, flags);
676 674
677} 675}
678 676
679void 677void
680tcic_deactivate_card(struct tcic_handle *h) 678tcic_deactivate_card(struct tcic_handle *h)
681{ 679{
682 int val, reg; 680 int val, reg;
683 681
684 if (!(h->flags & TCIC_FLAG_CARDP)) 682 if (!(h->flags & TCIC_FLAG_CARDP))
685 panic("tcic_deactivate_card: already detached"); 683 panic("tcic_deactivate_card: already detached");
686 684
687 /* call the MI deactivate function */ 685 /* call the MI deactivate function */
688 pcmcia_card_deactivate(h->pcmcia); 686 pcmcia_card_deactivate(h->pcmcia);
689 687
690 tcic_sel_sock(h); 688 tcic_sel_sock(h);
691 689
692 /* XXX disable card detect resume and configuration reset??? */ 690 /* XXX disable card detect resume and configuration reset??? */
693 691
694 /* power down the socket */ 692 /* power down the socket */
695 tcic_write_1(h, TCIC_R_PWR, 0); 693 tcic_write_1(h, TCIC_R_PWR, 0);
696 694
697 /* reset the card XXX ? -chb */ 695 /* reset the card XXX ? -chb */
698 696
699 /* turn off irq's for this socket */ 697 /* turn off irq's for this socket */
700 reg = TCIC_IR_SCF1_N(h->sock); 698 reg = TCIC_IR_SCF1_N(h->sock);
701 val = tcic_read_ind_2(h, reg); 699 val = tcic_read_ind_2(h, reg);
702 tcic_write_ind_2(h, reg, (val & ~TCIC_SCF1_IRQ_MASK)|TCIC_SCF1_IRQOFF); 700 tcic_write_ind_2(h, reg, (val & ~TCIC_SCF1_IRQ_MASK)|TCIC_SCF1_IRQOFF);
703 reg = TCIC_IR_SCF2_N(h->sock); 701 reg = TCIC_IR_SCF2_N(h->sock);
704 val = tcic_read_ind_2(h, reg); 702 val = tcic_read_ind_2(h, reg);
705 tcic_write_ind_2(h, reg, 703 tcic_write_ind_2(h, reg,
706 (val | (TCIC_SCF2_MLBAT1|TCIC_SCF2_MLBAT2|TCIC_SCF2_MRDY 704 (val | (TCIC_SCF2_MLBAT1|TCIC_SCF2_MLBAT2|TCIC_SCF2_MRDY
707 |TCIC_SCF2_MWP|TCIC_SCF2_MCD))); 705 |TCIC_SCF2_MWP|TCIC_SCF2_MCD)));
708} 706}
709 707
710/* XXX the following routine may need to be rewritten. -chb */ 708/* XXX the following routine may need to be rewritten. -chb */
711int 709int
712tcic_chip_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size, struct pcmcia_mem_handle *pcmhp) 710tcic_chip_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size, struct pcmcia_mem_handle *pcmhp)
713{ 711{
714 struct tcic_handle *h = (struct tcic_handle *) pch; 712 struct tcic_handle *h = (struct tcic_handle *) pch;
715 bus_space_handle_t memh; 713 bus_space_handle_t memh;
716 bus_addr_t addr; 714 bus_addr_t addr;
717 bus_size_t sizepg; 715 bus_size_t sizepg;
718 int i, mask, mhandle, got = 0; 716 int i, mask, mhandle, got = 0;
719 717
720 /* out of sc->memh, allocate as many pages as necessary */ 718 /* out of sc->memh, allocate as many pages as necessary */
721 719
722 /* 720 /*
723 * The TCIC can map memory only in sizes that are 721 * The TCIC can map memory only in sizes that are
724 * powers of two, aligned at the natural boundary for the size. 722 * powers of two, aligned at the natural boundary for the size.
725 */ 723 */
726 i = tcic_log2((u_int)size); 724 i = tcic_log2((u_int)size);
727 if ((1<<i) < size) 725 if ((1<<i) < size)
728 i++; 726 i++;
729 sizepg = max(i, TCIC_MEM_SHIFT) - (TCIC_MEM_SHIFT-1); 727 sizepg = max(i, TCIC_MEM_SHIFT) - (TCIC_MEM_SHIFT-1);
730 728
731 DPRINTF(("tcic_chip_mem_alloc: size %ld sizepg %ld\n", (u_long)size, 729 DPRINTF(("tcic_chip_mem_alloc: size %ld sizepg %ld\n", (u_long)size,
732 (u_long)sizepg)); 730 (u_long)sizepg));
733 731
734 /* can't allocate that much anyway */ 732 /* can't allocate that much anyway */
735 if (sizepg > TCIC_MEM_PAGES) /* XXX -chb */ 733 if (sizepg > TCIC_MEM_PAGES) /* XXX -chb */
736 return 1; 734 return 1;
737 735
738 mask = (1 << sizepg) - 1; 736 mask = (1 << sizepg) - 1;
739 737
740 addr = 0; /* XXX gcc -Wuninitialized */ 738 addr = 0; /* XXX gcc -Wuninitialized */
741 mhandle = 0; /* XXX gcc -Wuninitialized */ 739 mhandle = 0; /* XXX gcc -Wuninitialized */
742 740
743 /* XXX i should be initialised to always lay on boundary. -chb */ 741 /* XXX i should be initialised to always lay on boundary. -chb */
744 for (i = 0; i < (TCIC_MEM_PAGES + 1 - sizepg); i += sizepg) { 742 for (i = 0; i < (TCIC_MEM_PAGES + 1 - sizepg); i += sizepg) {
745 if ((h->sc->subregionmask & (mask << i)) == (mask << i)) { 743 if ((h->sc->subregionmask & (mask << i)) == (mask << i)) {
746 if (bus_space_subregion(h->sc->memt, h->sc->memh, 744 if (bus_space_subregion(h->sc->memt, h->sc->memh,
747 i * TCIC_MEM_PAGESIZE, 745 i * TCIC_MEM_PAGESIZE,
748 sizepg * TCIC_MEM_PAGESIZE, &memh)) 746 sizepg * TCIC_MEM_PAGESIZE, &memh))
749 return (1); 747 return (1);
750 mhandle = mask << i; 748 mhandle = mask << i;
751 addr = h->sc->membase + (i * TCIC_MEM_PAGESIZE); 749 addr = h->sc->membase + (i * TCIC_MEM_PAGESIZE);
752 h->sc->subregionmask &= ~(mhandle); 750 h->sc->subregionmask &= ~(mhandle);
753 got = 1; 751 got = 1;
754 break; 752 break;
755 } 753 }
756 } 754 }
757 755
758 if (got == 0) 756 if (got == 0)
759 return (1); 757 return (1);
760 758
761 DPRINTF(("tcic_chip_mem_alloc bus addr 0x%lx+0x%lx\n", (u_long) addr, 759 DPRINTF(("tcic_chip_mem_alloc bus addr 0x%lx+0x%lx\n", (u_long) addr,
762 (u_long) size)); 760 (u_long) size));
763 761
764 pcmhp->memt = h->sc->memt; 762 pcmhp->memt = h->sc->memt;
765 pcmhp->memh = memh; 763 pcmhp->memh = memh;
766 pcmhp->addr = addr; 764 pcmhp->addr = addr;
767 pcmhp->size = size; 765 pcmhp->size = size;
768 pcmhp->mhandle = mhandle; 766 pcmhp->mhandle = mhandle;
769 pcmhp->realsize = sizepg * TCIC_MEM_PAGESIZE; 767 pcmhp->realsize = sizepg * TCIC_MEM_PAGESIZE;
770 768
771 return (0); 769 return (0);
772} 770}
773 771
774/* XXX the following routine may need to be rewritten. -chb */ 772/* XXX the following routine may need to be rewritten. -chb */
775void 773void
776tcic_chip_mem_free(pcmcia_chipset_handle_t pch, struct pcmcia_mem_handle *pcmhp) 774tcic_chip_mem_free(pcmcia_chipset_handle_t pch, struct pcmcia_mem_handle *pcmhp)
777{ 775{
778 struct tcic_handle *h = (struct tcic_handle *) pch; 776 struct tcic_handle *h = (struct tcic_handle *) pch;
779 777
780 h->sc->subregionmask |= pcmhp->mhandle; 778 h->sc->subregionmask |= pcmhp->mhandle;
781} 779}
782 780
783void 781void
784tcic_chip_do_mem_map(struct tcic_handle *h, int win) 782tcic_chip_do_mem_map(struct tcic_handle *h, int win)
785{ 783{
786 int reg, hwwin, wscnt; 784 int reg, hwwin, wscnt;
787 785
788 int kind = h->mem[win].kind & ~PCMCIA_WIDTH_MEM_MASK; 786 int kind = h->mem[win].kind & ~PCMCIA_WIDTH_MEM_MASK;
789 int mem8 = (h->mem[win].kind & PCMCIA_WIDTH_MEM_MASK) == PCMCIA_WIDTH_MEM8; 787 int mem8 = (h->mem[win].kind & PCMCIA_WIDTH_MEM_MASK) == PCMCIA_WIDTH_MEM8;
790 DPRINTF(("tcic_chip_do_mem_map window %d: 0x%lx+0x%lx 0x%lx\n", 788 DPRINTF(("tcic_chip_do_mem_map window %d: 0x%lx+0x%lx 0x%lx\n",
791 win, (u_long)h->mem[win].addr, (u_long)h->mem[win].size, 789 win, (u_long)h->mem[win].addr, (u_long)h->mem[win].size,
792 (u_long)h->mem[win].offset)); 790 (u_long)h->mem[win].offset));
793 /* 791 /*
794 * the even windows are used for socket 0, 792 * the even windows are used for socket 0,
795 * the odd ones for socket 1. 793 * the odd ones for socket 1.
796 */ 794 */
797 hwwin = (win << 1) + h->sock; 795 hwwin = (win << 1) + h->sock;
798 796
799 /* the WR_MEXT register is MBZ */ 797 /* the WR_MEXT register is MBZ */
800 tcic_write_ind_2(h, TCIC_WR_MEXT_N(hwwin), 0); 798 tcic_write_ind_2(h, TCIC_WR_MEXT_N(hwwin), 0);
801 799
802 /* set the host base address and window size */ 800 /* set the host base address and window size */
803 if (h->mem[win].size2 <= 1) { 801 if (h->mem[win].size2 <= 1) {
804 reg = ((h->mem[win].addr >> TCIC_MEM_SHIFT) & 802 reg = ((h->mem[win].addr >> TCIC_MEM_SHIFT) &
805 TCIC_MBASE_ADDR_MASK) | TCIC_MBASE_4K; 803 TCIC_MBASE_ADDR_MASK) | TCIC_MBASE_4K;
806 } else { 804 } else {
807 reg = ((h->mem[win].addr >> TCIC_MEM_SHIFT) & 805 reg = ((h->mem[win].addr >> TCIC_MEM_SHIFT) &
808 TCIC_MBASE_ADDR_MASK) | (h->mem[win].size2 >> 1); 806 TCIC_MBASE_ADDR_MASK) | (h->mem[win].size2 >> 1);
809 } 807 }
810 tcic_write_ind_2(h, TCIC_WR_MBASE_N(hwwin), reg); 808 tcic_write_ind_2(h, TCIC_WR_MBASE_N(hwwin), reg);
811 809
812 /* set the card address and address space */ 810 /* set the card address and address space */
813 reg = 0; 811 reg = 0;
814 reg = ((h->mem[win].offset >> TCIC_MEM_SHIFT) & TCIC_MMAP_ADDR_MASK); 812 reg = ((h->mem[win].offset >> TCIC_MEM_SHIFT) & TCIC_MMAP_ADDR_MASK);
815 reg |= (kind == PCMCIA_MEM_ATTR) ? TCIC_MMAP_ATTR : 0; 813 reg |= (kind == PCMCIA_MEM_ATTR) ? TCIC_MMAP_ATTR : 0;
816 DPRINTF(("tcic_chip_do_map_mem window %d(%d) mmap 0x%04x\n", 814 DPRINTF(("tcic_chip_do_map_mem window %d(%d) mmap 0x%04x\n",
817 win, hwwin, reg)); 815 win, hwwin, reg));
818 tcic_write_ind_2(h, TCIC_WR_MMAP_N(hwwin), reg); 816 tcic_write_ind_2(h, TCIC_WR_MMAP_N(hwwin), reg);
819 817
820 /* set the MCTL register */ 818 /* set the MCTL register */
821 /* must save WSCNT field in case this is a DB86082 rev 0 */ 819 /* must save WSCNT field in case this is a DB86082 rev 0 */
822 /* XXX why can't I do the following two in one statement? */ 820 /* XXX why can't I do the following two in one statement? */
823 reg = tcic_read_ind_2(h, TCIC_WR_MCTL_N(hwwin)) & TCIC_MCTL_WSCNT_MASK; 821 reg = tcic_read_ind_2(h, TCIC_WR_MCTL_N(hwwin)) & TCIC_MCTL_WSCNT_MASK;
824 reg |= TCIC_MCTL_ENA|TCIC_MCTL_QUIET; 822 reg |= TCIC_MCTL_ENA|TCIC_MCTL_QUIET;
825 reg |= mem8 ? TCIC_MCTL_B8 : 0; 823 reg |= mem8 ? TCIC_MCTL_B8 : 0;
826 reg |= (h->sock << TCIC_MCTL_SS_SHIFT) & TCIC_MCTL_SS_MASK; 824 reg |= (h->sock << TCIC_MCTL_SS_SHIFT) & TCIC_MCTL_SS_MASK;
827#ifdef notyet /* XXX must get speed from CIS somehow. -chb */ 825#ifdef notyet /* XXX must get speed from CIS somehow. -chb */
828 wscnt = tcic_ns2wscnt(h->mem[win].speed); 826 wscnt = tcic_ns2wscnt(h->mem[win].speed);
829#else 827#else
830 wscnt = tcic_ns2wscnt(tcic_mem_speed); /* 300 is "save" default for CIS memory */ 828 wscnt = tcic_ns2wscnt(tcic_mem_speed); /* 300 is "save" default for CIS memory */
831#endif 829#endif
832 if (h->sc->chipid == TCIC_CHIPID_DB86082_1) { 830 if (h->sc->chipid == TCIC_CHIPID_DB86082_1) {
833 /* 831 /*
834 * this chip has the wait state count in window 832 * this chip has the wait state count in window
835 * register 7 - hwwin. 833 * register 7 - hwwin.
836 */ 834 */
837 int reg2; 835 int reg2;
838 reg2 = tcic_read_ind_2(h, TCIC_WR_MCTL_N(7-hwwin)); 836 reg2 = tcic_read_ind_2(h, TCIC_WR_MCTL_N(7-hwwin));
839 reg2 &= ~TCIC_MCTL_WSCNT_MASK; 837 reg2 &= ~TCIC_MCTL_WSCNT_MASK;
840 reg2 |= wscnt & TCIC_MCTL_WSCNT_MASK; 838 reg2 |= wscnt & TCIC_MCTL_WSCNT_MASK;
841 tcic_write_ind_2(h, TCIC_WR_MCTL_N(7-hwwin), reg2); 839 tcic_write_ind_2(h, TCIC_WR_MCTL_N(7-hwwin), reg2);
842 } else { 840 } else {
843 reg |= wscnt & TCIC_MCTL_WSCNT_MASK; 841 reg |= wscnt & TCIC_MCTL_WSCNT_MASK;
844 } 842 }
845 tcic_write_ind_2(h, TCIC_WR_MCTL_N(hwwin), reg); 843 tcic_write_ind_2(h, TCIC_WR_MCTL_N(hwwin), reg);
846 844
847#ifdef TCICDEBUG 845#ifdef TCICDEBUG
848 { 846 {
849 int r1, r2, r3; 847 int r1, r2, r3;
850 848
851 r1 = tcic_read_ind_2(h, TCIC_WR_MBASE_N(hwwin)); 849 r1 = tcic_read_ind_2(h, TCIC_WR_MBASE_N(hwwin));
852 r2 = tcic_read_ind_2(h, TCIC_WR_MMAP_N(hwwin)); 850 r2 = tcic_read_ind_2(h, TCIC_WR_MMAP_N(hwwin));
853 r3 = tcic_read_ind_2(h, TCIC_WR_MCTL_N(hwwin)); 851 r3 = tcic_read_ind_2(h, TCIC_WR_MCTL_N(hwwin));
854 852
855 DPRINTF(("tcic_chip_do_mem_map window %d(%d): %04x %04x %04x\n", 853 DPRINTF(("tcic_chip_do_mem_map window %d(%d): %04x %04x %04x\n",
856 win, hwwin, r1, r2, r3)); 854 win, hwwin, r1, r2, r3));
857 } 855 }
858#endif 856#endif
859} 857}
860 858
861/* XXX needs work */ 859/* XXX needs work */
862int 860int
863tcic_chip_mem_map(pcmcia_chipset_handle_t pch, int kind, bus_addr_t card_addr, bus_size_t size, struct pcmcia_mem_handle *pcmhp, bus_size_t *offsetp, int *windowp) 861tcic_chip_mem_map(pcmcia_chipset_handle_t pch, int kind, bus_addr_t card_addr, bus_size_t size, struct pcmcia_mem_handle *pcmhp, bus_size_t *offsetp, int *windowp)
864{ 862{
865 struct tcic_handle *h = (struct tcic_handle *) pch; 863 struct tcic_handle *h = (struct tcic_handle *) pch;
866 bus_addr_t busaddr; 864 bus_addr_t busaddr;
867 long card_offset; 865 long card_offset;
868 int i, win; 866 int i, win;
869 867
870 win = -1; 868 win = -1;
871 for (i = 0; i < h->memwins; i++) { 869 for (i = 0; i < h->memwins; i++) {
872 if ((h->memalloc & (1 << i)) == 0) { 870 if ((h->memalloc & (1 << i)) == 0) {
873 win = i; 871 win = i;
874 h->memalloc |= (1 << i); 872 h->memalloc |= (1 << i);
875 break; 873 break;
876 } 874 }
877 } 875 }
878 876
879 if (win == -1) 877 if (win == -1)
880 return (1); 878 return (1);
881 879
882 *windowp = win; 880 *windowp = win;
883 881
884 /* XXX this is pretty gross */ 882 /* XXX this is pretty gross */
885 883
886 if (!bus_space_is_equal(h->sc->memt, pcmhp->memt)) 884 if (!bus_space_is_equal(h->sc->memt, pcmhp->memt))
887 panic("tcic_chip_mem_map memt is bogus"); 885 panic("tcic_chip_mem_map memt is bogus");
888 886
889 busaddr = pcmhp->addr; 887 busaddr = pcmhp->addr;
890 888
891 /* 889 /*
892 * compute the address offset to the pcmcia address space for the 890 * compute the address offset to the pcmcia address space for the
893 * tcic. this is intentionally signed. The masks and shifts below 891 * tcic. this is intentionally signed. The masks and shifts below
894 * will cause TRT to happen in the tcic registers. Deal with making 892 * will cause TRT to happen in the tcic registers. Deal with making
895 * sure the address is aligned, and return the alignment offset. 893 * sure the address is aligned, and return the alignment offset.
896 */ 894 */
897 895
898 *offsetp = card_addr % TCIC_MEM_ALIGN; 896 *offsetp = card_addr % TCIC_MEM_ALIGN;
899 card_addr -= *offsetp; 897 card_addr -= *offsetp;
900 898
901 DPRINTF(("tcic_chip_mem_map window %d bus %lx+%lx+%lx at card addr " 899 DPRINTF(("tcic_chip_mem_map window %d bus %lx+%lx+%lx at card addr "
902 "%lx\n", win, (u_long) busaddr, (u_long) * offsetp, (u_long) size, 900 "%lx\n", win, (u_long) busaddr, (u_long) * offsetp, (u_long) size,
903 (u_long) card_addr)); 901 (u_long) card_addr));
904 902
905 /* XXX we can't use size. -chb */ 903 /* XXX we can't use size. -chb */
906 /* 904 /*
907 * include the offset in the size, and decrement size by one, since 905 * include the offset in the size, and decrement size by one, since
908 * the hw wants start/stop 906 * the hw wants start/stop
909 */ 907 */
910 size += *offsetp - 1; 908 size += *offsetp - 1;
911 909
912 card_offset = (((long) card_addr) - ((long) busaddr)); 910 card_offset = (((long) card_addr) - ((long) busaddr));
913 911
914 DPRINTF(("tcic_chip_mem_map window %d card_offset 0x%lx\n", 912 DPRINTF(("tcic_chip_mem_map window %d card_offset 0x%lx\n",
915 win, (u_long)card_offset)); 913 win, (u_long)card_offset));
916 914
917 h->mem[win].addr = busaddr; 915 h->mem[win].addr = busaddr;
918 h->mem[win].size = size; 916 h->mem[win].size = size;
919 h->mem[win].size2 = tcic_log2((u_int)pcmhp->realsize) - TCIC_MEM_SHIFT; 917 h->mem[win].size2 = tcic_log2((u_int)pcmhp->realsize) - TCIC_MEM_SHIFT;
920 h->mem[win].offset = card_offset; 918 h->mem[win].offset = card_offset;
921 h->mem[win].kind = kind; 919 h->mem[win].kind = kind;
922 920
923 tcic_chip_do_mem_map(h, win); 921 tcic_chip_do_mem_map(h, win);
924 922
925 return (0); 923 return (0);
926} 924}
927 925
928void 926void
929tcic_chip_mem_unmap(pcmcia_chipset_handle_t pch, int window) 927tcic_chip_mem_unmap(pcmcia_chipset_handle_t pch, int window)
930{ 928{
931 struct tcic_handle *h = (struct tcic_handle *) pch; 929 struct tcic_handle *h = (struct tcic_handle *) pch;
932 int hwwin; 930 int hwwin;
933 931
934 if (window >= h->memwins) 932 if (window >= h->memwins)
935 panic("tcic_chip_mem_unmap: window out of range"); 933 panic("tcic_chip_mem_unmap: window out of range");
936 934
937 hwwin = (window << 1) + h->sock; 935 hwwin = (window << 1) + h->sock;
938 tcic_write_ind_2(h, TCIC_WR_MCTL_N(hwwin), 0); 936 tcic_write_ind_2(h, TCIC_WR_MCTL_N(hwwin), 0);
939 937
940 h->memalloc &= ~(1 << window); 938 h->memalloc &= ~(1 << window);
941} 939}
942 940
943int 941int
944tcic_chip_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start, bus_size_t size, bus_size_t align, struct pcmcia_io_handle *pcihp) 942tcic_chip_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start, bus_size_t size, bus_size_t align, struct pcmcia_io_handle *pcihp)
945{ 943{
946 struct tcic_handle *h = (struct tcic_handle *) pch; 944 struct tcic_handle *h = (struct tcic_handle *) pch;
947 bus_space_tag_t iot; 945 bus_space_tag_t iot;
948 bus_space_handle_t ioh; 946 bus_space_handle_t ioh;
949 bus_addr_t ioaddr; 947 bus_addr_t ioaddr;
950 int size2, flags = 0; 948 int size2, flags = 0;
951 949
952 /* 950 /*
953 * Allocate some arbitrary I/O space. 951 * Allocate some arbitrary I/O space.
954 */ 952 */
955 953
956 DPRINTF(("tcic_chip_io_alloc req 0x%lx %ld %ld\n", 954 DPRINTF(("tcic_chip_io_alloc req 0x%lx %ld %ld\n",
957 (u_long) start, (u_long) size, (u_long) align)); 955 (u_long) start, (u_long) size, (u_long) align));
958 /* 956 /*
959 * The TCIC can map I/O space only in sizes that are 957 * The TCIC can map I/O space only in sizes that are
960 * powers of two, aligned at the natural boundary for the size. 958 * powers of two, aligned at the natural boundary for the size.
961 */ 959 */
962 size2 = tcic_log2((u_int)size); 960 size2 = tcic_log2((u_int)size);
963 if ((1 << size2) < size) 961 if ((1 << size2) < size)
964 size2++; 962 size2++;
965 /* can't allocate that much anyway */ 963 /* can't allocate that much anyway */
966 if (size2 > 16) /* XXX 64K -chb */ 964 if (size2 > 16) /* XXX 64K -chb */
967 return 1; 965 return 1;
968 if (align) { 966 if (align) {
969 if ((1 << size2) != align) 967 if ((1 << size2) != align)
970 return 1; /* not suitably aligned */ 968 return 1; /* not suitably aligned */
971 } else { 969 } else {
972 align = 1 << size2; /* no alignment given, make it natural */ 970 align = 1 << size2; /* no alignment given, make it natural */
973 } 971 }
974 if (start & (align - 1)) 972 if (start & (align - 1))
975 return 1; /* not suitably aligned */ 973 return 1; /* not suitably aligned */
976 974
977 iot = h->sc->iot; 975 iot = h->sc->iot;
978 976
979 if (start) { 977 if (start) {
980 ioaddr = start; 978 ioaddr = start;
981 if (bus_space_map(iot, start, size, 0, &ioh)) 979 if (bus_space_map(iot, start, size, 0, &ioh))
982 return (1); 980 return (1);
983 DPRINTF(("tcic_chip_io_alloc map port %lx+%lx\n", 981 DPRINTF(("tcic_chip_io_alloc map port %lx+%lx\n",
984 (u_long) ioaddr, (u_long) size)); 982 (u_long) ioaddr, (u_long) size));
985 } else { 983 } else {
986 flags |= PCMCIA_IO_ALLOCATED; 984 flags |= PCMCIA_IO_ALLOCATED;
987 if (bus_space_alloc(iot, h->sc->iobase, 985 if (bus_space_alloc(iot, h->sc->iobase,
988 h->sc->iobase + h->sc->iosize, size, align, 0, 0, 986 h->sc->iobase + h->sc->iosize, size, align, 0, 0,
989 &ioaddr, &ioh)) 987 &ioaddr, &ioh))
990 return (1); 988 return (1);
991 DPRINTF(("tcic_chip_io_alloc alloc port %lx+%lx\n", 989 DPRINTF(("tcic_chip_io_alloc alloc port %lx+%lx\n",
992 (u_long) ioaddr, (u_long) size)); 990 (u_long) ioaddr, (u_long) size));
993 } 991 }
994 992
995 pcihp->iot = iot; 993 pcihp->iot = iot;
996 pcihp->ioh = ioh; 994 pcihp->ioh = ioh;
997 pcihp->addr = ioaddr; 995 pcihp->addr = ioaddr;
998 pcihp->size = size; 996 pcihp->size = size;
999 pcihp->flags = flags; 997 pcihp->flags = flags;
1000 998
1001 return (0); 999 return (0);
1002} 1000}
1003 1001
1004void 1002void
1005tcic_chip_io_free(pcmcia_chipset_handle_t pch, 1003tcic_chip_io_free(pcmcia_chipset_handle_t pch,
1006 struct pcmcia_io_handle *pcihp) 1004 struct pcmcia_io_handle *pcihp)
1007{ 1005{
1008 bus_space_tag_t iot = pcihp->iot; 1006 bus_space_tag_t iot = pcihp->iot;
1009 bus_space_handle_t ioh = pcihp->ioh; 1007 bus_space_handle_t ioh = pcihp->ioh;
1010 bus_size_t size = pcihp->size; 1008 bus_size_t size = pcihp->size;
1011 1009
1012 if (pcihp->flags & PCMCIA_IO_ALLOCATED) 1010 if (pcihp->flags & PCMCIA_IO_ALLOCATED)
1013 bus_space_free(iot, ioh, size); 1011 bus_space_free(iot, ioh, size);
1014 else 1012 else
1015 bus_space_unmap(iot, ioh, size); 1013 bus_space_unmap(iot, ioh, size);
1016} 1014}
1017 1015
1018static int tcic_iowidth_map[] = 1016static int tcic_iowidth_map[] =
1019 { TCIC_ICTL_AUTOSZ, TCIC_ICTL_B8, TCIC_ICTL_B16 }; 1017 { TCIC_ICTL_AUTOSZ, TCIC_ICTL_B8, TCIC_ICTL_B16 };
1020 1018
1021void 1019void
1022tcic_chip_do_io_map(struct tcic_handle *h, int win) 1020tcic_chip_do_io_map(struct tcic_handle *h, int win)
1023{ 1021{
1024 int reg, size2, iotiny, wbase, hwwin, wscnt; 1022 int reg, size2, iotiny, wbase, hwwin, wscnt;
1025 1023
1026 DPRINTF(("tcic_chip_do_io_map win %d addr %lx size %lx width %d\n", 1024 DPRINTF(("tcic_chip_do_io_map win %d addr %lx size %lx width %d\n",
1027 win, (long) h->io[win].addr, (long) h->io[win].size, 1025 win, (long) h->io[win].addr, (long) h->io[win].size,
1028 h->io[win].width * 8)); 1026 h->io[win].width * 8));
1029 1027
1030 /* 1028 /*
1031 * the even windows are used for socket 0, 1029 * the even windows are used for socket 0,
1032 * the odd ones for socket 1. 1030 * the odd ones for socket 1.
1033 */ 1031 */
1034 hwwin = (win << 1) + h->sock; 1032 hwwin = (win << 1) + h->sock;
1035 1033
1036 /* set the WR_BASE register */ 1034 /* set the WR_BASE register */
1037 /* XXX what if size isn't power of 2? -chb */ 1035 /* XXX what if size isn't power of 2? -chb */
1038 size2 = tcic_log2((u_int)h->io[win].size); 1036 size2 = tcic_log2((u_int)h->io[win].size);
1039 DPRINTF(("tcic_chip_do_io_map win %d size2 %d\n", win, size2)); 1037 DPRINTF(("tcic_chip_do_io_map win %d size2 %d\n", win, size2));
1040 if (size2 < 1) { 1038 if (size2 < 1) {
1041 iotiny = TCIC_ICTL_TINY; 1039 iotiny = TCIC_ICTL_TINY;
1042 wbase = h->io[win].addr; 1040 wbase = h->io[win].addr;
1043 } else { 1041 } else {
1044 iotiny = 0; 1042 iotiny = 0;
1045 /* XXX we should do better -chb */ 1043 /* XXX we should do better -chb */
1046 wbase = h->io[win].addr | (1 << (size2 - 1)); 1044 wbase = h->io[win].addr | (1 << (size2 - 1));
1047 } 1045 }
1048 tcic_write_ind_2(h, TCIC_WR_IBASE_N(hwwin), wbase); 1046 tcic_write_ind_2(h, TCIC_WR_IBASE_N(hwwin), wbase);
1049 1047
1050 /* set the WR_ICTL register */ 1048 /* set the WR_ICTL register */
1051 reg = TCIC_ICTL_ENA | TCIC_ICTL_QUIET; 1049 reg = TCIC_ICTL_ENA | TCIC_ICTL_QUIET;
1052 reg |= (h->sock << TCIC_ICTL_SS_SHIFT) & TCIC_ICTL_SS_MASK; 1050 reg |= (h->sock << TCIC_ICTL_SS_SHIFT) & TCIC_ICTL_SS_MASK;
1053 reg |= iotiny | tcic_iowidth_map[h->io[win].width]; 1051 reg |= iotiny | tcic_iowidth_map[h->io[win].width];
1054 if (h->sc->chipid != TCIC_CHIPID_DB86082_1) 1052 if (h->sc->chipid != TCIC_CHIPID_DB86082_1)
1055 reg |= TCIC_ICTL_PASS16; 1053 reg |= TCIC_ICTL_PASS16;
1056#ifdef notyet /* XXX must get speed from CIS somehow. -chb */ 1054#ifdef notyet /* XXX must get speed from CIS somehow. -chb */
1057 wscnt = tcic_ns2wscnt(h->io[win].speed); 1055 wscnt = tcic_ns2wscnt(h->io[win].speed);
1058#else 1056#else
1059 wscnt = tcic_ns2wscnt(tcic_io_speed); /* linux uses 0 as default */ 1057 wscnt = tcic_ns2wscnt(tcic_io_speed); /* linux uses 0 as default */
1060#endif 1058#endif
1061 reg |= wscnt & TCIC_ICTL_WSCNT_MASK; 1059 reg |= wscnt & TCIC_ICTL_WSCNT_MASK;
1062 tcic_write_ind_2(h, TCIC_WR_ICTL_N(hwwin), reg); 1060 tcic_write_ind_2(h, TCIC_WR_ICTL_N(hwwin), reg);
1063 1061
1064#ifdef TCICDEBUG 1062#ifdef TCICDEBUG
1065 { 1063 {
1066 int r1, r2; 1064 int r1, r2;
1067 1065
1068 r1 = tcic_read_ind_2(h, TCIC_WR_IBASE_N(hwwin)); 1066 r1 = tcic_read_ind_2(h, TCIC_WR_IBASE_N(hwwin));
1069 r2 = tcic_read_ind_2(h, TCIC_WR_ICTL_N(hwwin)); 1067 r2 = tcic_read_ind_2(h, TCIC_WR_ICTL_N(hwwin));
1070 1068
1071 DPRINTF(("tcic_chip_do_io_map window %d(%d): %04x %04x\n", 1069 DPRINTF(("tcic_chip_do_io_map window %d(%d): %04x %04x\n",
1072 win, hwwin, r1, r2)); 1070 win, hwwin, r1, r2));
1073 } 1071 }
1074#endif 1072#endif
1075} 1073}
1076 1074
1077int 1075int
1078tcic_chip_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset, bus_size_t size, struct pcmcia_io_handle *pcihp, int *windowp) 1076tcic_chip_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset, bus_size_t size, struct pcmcia_io_handle *pcihp, int *windowp)
1079{ 1077{
1080 struct tcic_handle *h = (struct tcic_handle *) pch; 1078 struct tcic_handle *h = (struct tcic_handle *) pch;
1081 bus_addr_t ioaddr = pcihp->addr + offset; 1079 bus_addr_t ioaddr = pcihp->addr + offset;
1082 int i, win; 1080 int i, win;
1083#ifdef TCICDEBUG 1081#ifdef TCICDEBUG
1084 static const char *width_names[] = { "auto", "io8", "io16" }; 1082 static const char *width_names[] = { "auto", "io8", "io16" };
1085#endif 1083#endif
1086 1084
1087 /* XXX Sanity check offset/size. */ 1085 /* XXX Sanity check offset/size. */
1088 1086
1089 win = -1; 1087 win = -1;
1090 for (i = 0; i < TCIC_IO_WINS; i++) { 1088 for (i = 0; i < TCIC_IO_WINS; i++) {
1091 if ((h->ioalloc & (1 << i)) == 0) { 1089 if ((h->ioalloc & (1 << i)) == 0) {
1092 win = i; 1090 win = i;
1093 h->ioalloc |= (1 << i); 1091 h->ioalloc |= (1 << i);
1094 break; 1092 break;
1095 } 1093 }
1096 } 1094 }
1097 1095
1098 if (win == -1) 1096 if (win == -1)
1099 return (1); 1097 return (1);
1100 1098
1101 *windowp = win; 1099 *windowp = win;
1102 1100
1103 /* XXX this is pretty gross */ 1101 /* XXX this is pretty gross */
1104 1102
1105 if (!bus_space_is_equal(h->sc->iot, pcihp->iot)) 1103 if (!bus_space_is_equal(h->sc->iot, pcihp->iot))
1106 panic("tcic_chip_io_map iot is bogus"); 1104 panic("tcic_chip_io_map iot is bogus");
1107 1105
1108 DPRINTF(("tcic_chip_io_map window %d %s port %lx+%lx\n", 1106 DPRINTF(("tcic_chip_io_map window %d %s port %lx+%lx\n",
1109 win, width_names[width], (u_long) ioaddr, (u_long) size)); 1107 win, width_names[width], (u_long) ioaddr, (u_long) size));
1110 1108
1111 /* XXX wtf is this doing here? */ 1109 /* XXX wtf is this doing here? */
1112 1110
1113 printf("%s: port 0x%lx", device_xname(&h->sc->dev), (u_long) ioaddr); 1111 printf("%s: port 0x%lx", device_xname(&h->sc->dev), (u_long) ioaddr);
1114 if (size > 1) 1112 if (size > 1)
1115 printf("-0x%lx", (u_long) ioaddr + (u_long) size - 1); 1113 printf("-0x%lx", (u_long) ioaddr + (u_long) size - 1);
1116 printf("\n"); 1114 printf("\n");
1117 1115
1118 h->io[win].addr = ioaddr; 1116 h->io[win].addr = ioaddr;
1119 h->io[win].size = size; 1117 h->io[win].size = size;
1120 h->io[win].width = width; 1118 h->io[win].width = width;
1121 1119
1122 tcic_chip_do_io_map(h, win); 1120 tcic_chip_do_io_map(h, win);
1123 1121
1124 return (0); 1122 return (0);
1125} 1123}
1126 1124
1127void 1125void
1128tcic_chip_io_unmap(pcmcia_chipset_handle_t pch, int window) 1126tcic_chip_io_unmap(pcmcia_chipset_handle_t pch, int window)
1129{ 1127{
1130 struct tcic_handle *h = (struct tcic_handle *) pch; 1128 struct tcic_handle *h = (struct tcic_handle *) pch;
1131 int hwwin; 1129 int hwwin;
1132 1130
1133 if (window >= TCIC_IO_WINS) 1131 if (window >= TCIC_IO_WINS)
1134 panic("tcic_chip_io_unmap: window out of range"); 1132 panic("tcic_chip_io_unmap: window out of range");
1135 1133
1136 hwwin = (window << 1) + h->sock; 1134 hwwin = (window << 1) + h->sock;
1137 tcic_write_ind_2(h, TCIC_WR_ICTL_N(hwwin), 0); 1135 tcic_write_ind_2(h, TCIC_WR_ICTL_N(hwwin), 0);
1138 1136
1139 h->ioalloc &= ~(1 << window); 1137 h->ioalloc &= ~(1 << window);
1140} 1138}
1141 1139
1142void 1140void
1143tcic_chip_socket_enable(pcmcia_chipset_handle_t pch) 1141tcic_chip_socket_enable(pcmcia_chipset_handle_t pch)
1144{ 1142{
1145 struct tcic_handle *h = (struct tcic_handle *) pch; 1143 struct tcic_handle *h = (struct tcic_handle *) pch;
1146 int reg, win; 1144 int reg, win;
1147 1145
1148 tcic_sel_sock(h); 1146 tcic_sel_sock(h);
1149 1147
1150 /* 1148 /*
1151 * power down the socket to reset it. 1149 * power down the socket to reset it.
1152 * put card reset into high-z, put chip outputs to card into high-z 1150 * put card reset into high-z, put chip outputs to card into high-z
1153 */ 1151 */
1154 1152
1155 tcic_write_1(h, TCIC_R_PWR, 0); 1153 tcic_write_1(h, TCIC_R_PWR, 0);
1156 reg = tcic_read_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK); 1154 reg = tcic_read_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK);
1157 reg |= TCIC_ILOCK_CWAIT; 1155 reg |= TCIC_ILOCK_CWAIT;
1158 reg &= ~(TCIC_ILOCK_CRESET|TCIC_ILOCK_CRESENA); 1156 reg &= ~(TCIC_ILOCK_CRESET|TCIC_ILOCK_CRESENA);
1159 tcic_write_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK, reg); 1157 tcic_write_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK, reg);
1160 tcic_write_1(h, TCIC_R_SCTRL, 0); /* clear TCIC_SCTRL_ENA */ 1158 tcic_write_1(h, TCIC_R_SCTRL, 0); /* clear TCIC_SCTRL_ENA */
1161 1159
1162 /* zero out the address windows */ 1160 /* zero out the address windows */
1163 1161
1164 tcic_write_ind_2(h, TCIC_IR_SCF1_N(h->sock), 0); 1162 tcic_write_ind_2(h, TCIC_IR_SCF1_N(h->sock), 0);
1165 /* writing to WR_MBASE_N disables the window */ 1163 /* writing to WR_MBASE_N disables the window */
1166 for (win = 0; win < h->memwins; win++) { 1164 for (win = 0; win < h->memwins; win++) {
1167 tcic_write_ind_2(h, TCIC_WR_MBASE_N((win << 1) + h->sock), 0); 1165 tcic_write_ind_2(h, TCIC_WR_MBASE_N((win << 1) + h->sock), 0);
1168 } 1166 }
1169 /* writing to WR_IBASE_N disables the window */ 1167 /* writing to WR_IBASE_N disables the window */
1170 for (win = 0; win < TCIC_IO_WINS; win++) { 1168 for (win = 0; win < TCIC_IO_WINS; win++) {
1171 tcic_write_ind_2(h, TCIC_WR_IBASE_N((win << 1) + h->sock), 0); 1169 tcic_write_ind_2(h, TCIC_WR_IBASE_N((win << 1) + h->sock), 0);
1172 } 1170 }
1173 1171
1174 /* power up the socket */ 1172 /* power up the socket */
1175 1173
1176 /* turn on VCC, turn of VPP */ 1174 /* turn on VCC, turn of VPP */
1177 reg = TCIC_PWR_VCC_N(h->sock) | TCIC_PWR_VPP_N(h->sock) | h->sc->pwrena; 1175 reg = TCIC_PWR_VCC_N(h->sock) | TCIC_PWR_VPP_N(h->sock) | h->sc->pwrena;
1178 if (h->sc->pwrena) /* this is a '84 type chip */ 1176 if (h->sc->pwrena) /* this is a '84 type chip */
1179 reg |= TCIC_PWR_VCC5V; 1177 reg |= TCIC_PWR_VCC5V;
1180 tcic_write_1(h, TCIC_R_PWR, reg); 1178 tcic_write_1(h, TCIC_R_PWR, reg);
1181 delay(10000); 1179 delay(10000);
1182 1180
1183 /* enable reset and wiggle it to reset the card */ 1181 /* enable reset and wiggle it to reset the card */
1184 reg = tcic_read_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK); 1182 reg = tcic_read_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK);
1185 reg |= TCIC_ILOCK_CRESENA; 1183 reg |= TCIC_ILOCK_CRESENA;
1186 tcic_write_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK, reg); 1184 tcic_write_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK, reg);
1187 /* XXX need bus_space_barrier here */ 1185 /* XXX need bus_space_barrier here */
1188 reg |= TCIC_ILOCK_CRESET; 1186 reg |= TCIC_ILOCK_CRESET;
1189 tcic_write_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK, reg); 1187 tcic_write_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK, reg);
1190 /* enable card signals */ 1188 /* enable card signals */
1191 tcic_write_1(h, TCIC_R_SCTRL, TCIC_SCTRL_ENA); 1189 tcic_write_1(h, TCIC_R_SCTRL, TCIC_SCTRL_ENA);
1192 delay(10); /* wait 10 us */ 1190 delay(10); /* wait 10 us */
1193 1191
1194 /* clear the reset flag */ 1192 /* clear the reset flag */
1195 reg = tcic_read_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK); 1193 reg = tcic_read_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK);
1196 reg &= ~(TCIC_ILOCK_CRESET); 1194 reg &= ~(TCIC_ILOCK_CRESET);
1197 tcic_write_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK, reg); 1195 tcic_write_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK, reg);
1198 1196
1199 /* wait 20ms as per pc card standard (r2.01) section 4.3.6 */ 1197 /* wait 20ms as per pc card standard (r2.01) section 4.3.6 */
1200 delay(20000); 1198 delay(20000);
1201 1199
1202 /* wait for the chip to finish initializing */ 1200 /* wait for the chip to finish initializing */
1203 tcic_wait_ready(h); 1201 tcic_wait_ready(h);
1204 1202
1205 /* WWW */ 1203 /* WWW */
1206 1204
1207 /* reinstall all the memory and io mappings */ 1205 /* reinstall all the memory and io mappings */
1208 1206
1209 for (win = 0; win < h->memwins; win++) 1207 for (win = 0; win < h->memwins; win++)
1210 if (h->memalloc & (1 << win)) 1208 if (h->memalloc & (1 << win))
1211 tcic_chip_do_mem_map(h, win); 1209 tcic_chip_do_mem_map(h, win);
1212 1210
1213 for (win = 0; win < TCIC_IO_WINS; win++) 1211 for (win = 0; win < TCIC_IO_WINS; win++)
1214 if (h->ioalloc & (1 << win)) 1212 if (h->ioalloc & (1 << win))
1215 tcic_chip_do_io_map(h, win); 1213 tcic_chip_do_io_map(h, win);
1216} 1214}
1217 1215
1218void 1216void
1219tcic_chip_socket_settype(pcmcia_chipset_handle_t pch, int type) 1217tcic_chip_socket_settype(pcmcia_chipset_handle_t pch, int type)
1220{ 1218{
1221 struct tcic_handle *h = (struct tcic_handle *) pch; 1219 struct tcic_handle *h = (struct tcic_handle *) pch;
1222 int reg; 1220 int reg;
1223 1221
1224 tcic_sel_sock(h); 1222 tcic_sel_sock(h);
1225 1223
1226 /* set the card type */ 1224 /* set the card type */
1227 1225
1228 reg = 0; 1226 reg = 0;
1229 if (type == PCMCIA_IFTYPE_IO) { 1227 if (type == PCMCIA_IFTYPE_IO) {
1230 reg |= TCIC_SCF1_IOSTS; 1228 reg |= TCIC_SCF1_IOSTS;
1231 reg |= tcic_irqmap[h->ih_irq]; /* enable interrupts */ 1229 reg |= tcic_irqmap[h->ih_irq]; /* enable interrupts */
1232 } 1230 }
1233 tcic_write_ind_2(h, TCIC_IR_SCF1_N(h->sock), reg); 1231 tcic_write_ind_2(h, TCIC_IR_SCF1_N(h->sock), reg);
1234 1232
1235 DPRINTF(("%s: tcic_chip_socket_enable %d cardtype %s 0x%02x\n", 1233 DPRINTF(("%s: tcic_chip_socket_enable %d cardtype %s 0x%02x\n",
1236 device_xname(&h->sc->dev), h->sock, 1234 device_xname(&h->sc->dev), h->sock,
1237 ((type == PCMCIA_IFTYPE_IO) ? "io" : "mem"), reg)); 1235 ((type == PCMCIA_IFTYPE_IO) ? "io" : "mem"), reg));
1238} 1236}
1239 1237
1240void 1238void
1241tcic_chip_socket_disable(pcmcia_chipset_handle_t pch) 1239tcic_chip_socket_disable(pcmcia_chipset_handle_t pch)
1242{ 1240{
1243 struct tcic_handle *h = (struct tcic_handle *) pch; 1241 struct tcic_handle *h = (struct tcic_handle *) pch;
1244 int val; 1242 int val;
1245 1243
1246 DPRINTF(("tcic_chip_socket_disable\n")); 1244 DPRINTF(("tcic_chip_socket_disable\n"));
1247 1245
1248 tcic_sel_sock(h); 1246 tcic_sel_sock(h);
1249 1247
1250 /* disable interrupts */ 1248 /* disable interrupts */
1251 val = tcic_read_ind_2(h, TCIC_IR_SCF1_N(h->sock)); 1249 val = tcic_read_ind_2(h, TCIC_IR_SCF1_N(h->sock));
1252 val &= TCIC_SCF1_IRQ_MASK; 1250 val &= TCIC_SCF1_IRQ_MASK;
1253 tcic_write_ind_2(h, TCIC_IR_SCF1_N(h->sock), val); 1251 tcic_write_ind_2(h, TCIC_IR_SCF1_N(h->sock), val);
1254 1252
1255 /* disable the output signals */ 1253 /* disable the output signals */
1256 tcic_write_1(h, TCIC_R_SCTRL, 0); 1254 tcic_write_1(h, TCIC_R_SCTRL, 0);
1257 val = tcic_read_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK); 1255 val = tcic_read_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK);
1258 val &= ~TCIC_ILOCK_CRESENA; 1256 val &= ~TCIC_ILOCK_CRESENA;
1259 tcic_write_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK, val); 1257 tcic_write_aux_2(h->sc->iot, h->sc->ioh, TCIC_AR_ILOCK, val);
1260 1258
1261 /* power down the socket */ 1259 /* power down the socket */
1262 tcic_write_1(h, TCIC_R_PWR, 0); 1260 tcic_write_1(h, TCIC_R_PWR, 0);
1263} 1261}
1264 1262
1265/* 1263/*
1266 * XXX The following is Linux driver but doesn't match the table 1264 * XXX The following is Linux driver but doesn't match the table
1267 * in the manual. 1265 * in the manual.
1268 */ 1266 */
1269int 1267int
1270tcic_ns2wscnt(int ns) 1268tcic_ns2wscnt(int ns)
1271{ 1269{
1272 if (ns < 14) { 1270 if (ns < 14) {
1273 return 0; 1271 return 0;
1274 } else { 1272 } else {
1275 return (2*(ns-14))/70; /* XXX assumes 14.31818 MHz clock. */ 1273 return (2*(ns-14))/70; /* XXX assumes 14.31818 MHz clock. */
1276 } 1274 }
1277} 1275}
1278 1276
1279int 1277int
1280tcic_log2(u_int val) 1278tcic_log2(u_int val)
1281{ 1279{
1282 int i, l2; 1280 int i, l2;
1283 1281
1284 l2 = i = 0; 1282 l2 = i = 0;
1285 while (val) { 1283 while (val) {
1286 if (val & 1) 1284 if (val & 1)
1287 l2 = i; 1285 l2 = i;
1288 i++; 1286 i++;
1289 val >>= 1; 1287 val >>= 1;
1290 } 1288 }
1291 return l2; 1289 return l2;
1292} 1290}