sa11xx_pcic.c revision 1.1.8.2 1 1.1.8.2 nathanw /* $NetBSD: sa11xx_pcic.c,v 1.1.8.2 2002/06/24 22:04:00 nathanw Exp $ */
2 1.1.8.2 nathanw
3 1.1.8.2 nathanw /*
4 1.1.8.2 nathanw * Copyright (c) 2001 IWAMOTO Toshihiro. All rights reserved.
5 1.1.8.2 nathanw * Copyright (c) 1997 Marc Horowitz. All rights reserved.
6 1.1.8.2 nathanw *
7 1.1.8.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.1.8.2 nathanw * modification, are permitted provided that the following conditions
9 1.1.8.2 nathanw * are met:
10 1.1.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.1.8.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.1.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.1.8.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.1.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
16 1.1.8.2 nathanw * must display the following acknowledgement:
17 1.1.8.2 nathanw * This product includes software developed by Marc Horowitz.
18 1.1.8.2 nathanw * 4. The name of the author may not be used to endorse or promote products
19 1.1.8.2 nathanw * derived from this software without specific prior written permission.
20 1.1.8.2 nathanw *
21 1.1.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1.8.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1.8.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1.8.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1.8.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1.8.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1.8.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1.8.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1.8.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1.8.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1.8.2 nathanw */
32 1.1.8.2 nathanw
33 1.1.8.2 nathanw /*
34 1.1.8.2 nathanw * Common code for SA11x0 based PCMCIA modules
35 1.1.8.2 nathanw */
36 1.1.8.2 nathanw
37 1.1.8.2 nathanw #include <sys/types.h>
38 1.1.8.2 nathanw #include <sys/param.h>
39 1.1.8.2 nathanw #include <sys/systm.h>
40 1.1.8.2 nathanw #include <sys/device.h>
41 1.1.8.2 nathanw #include <sys/callout.h>
42 1.1.8.2 nathanw #include <sys/kernel.h>
43 1.1.8.2 nathanw #include <sys/kthread.h>
44 1.1.8.2 nathanw #include <sys/malloc.h>
45 1.1.8.2 nathanw #include <uvm/uvm.h>
46 1.1.8.2 nathanw
47 1.1.8.2 nathanw #include <machine/bus.h>
48 1.1.8.2 nathanw #include <machine/intr.h>
49 1.1.8.2 nathanw
50 1.1.8.2 nathanw #include <dev/pcmcia/pcmciareg.h>
51 1.1.8.2 nathanw #include <dev/pcmcia/pcmciavar.h>
52 1.1.8.2 nathanw #include <dev/pcmcia/pcmciachip.h>
53 1.1.8.2 nathanw
54 1.1.8.2 nathanw #include <arm/sa11x0/sa11x0_reg.h>
55 1.1.8.2 nathanw #include <arm/sa11x0/sa11x0_var.h>
56 1.1.8.2 nathanw #include <arm/sa11x0/sa11xx_pcicreg.h>
57 1.1.8.2 nathanw #include <arm/sa11x0/sa11xx_pcicvar.h>
58 1.1.8.2 nathanw
59 1.1.8.2 nathanw static int sapcic_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
60 1.1.8.2 nathanw struct pcmcia_mem_handle *);
61 1.1.8.2 nathanw static void sapcic_mem_free(pcmcia_chipset_handle_t,
62 1.1.8.2 nathanw struct pcmcia_mem_handle *);
63 1.1.8.2 nathanw static int sapcic_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t,
64 1.1.8.2 nathanw bus_size_t, struct pcmcia_mem_handle *,
65 1.1.8.2 nathanw bus_addr_t *, int *);
66 1.1.8.2 nathanw static void sapcic_mem_unmap(pcmcia_chipset_handle_t, int);
67 1.1.8.2 nathanw static int sapcic_io_alloc(pcmcia_chipset_handle_t, bus_addr_t,
68 1.1.8.2 nathanw bus_size_t, bus_size_t,
69 1.1.8.2 nathanw struct pcmcia_io_handle *);
70 1.1.8.2 nathanw static void sapcic_io_free(pcmcia_chipset_handle_t,
71 1.1.8.2 nathanw struct pcmcia_io_handle *);
72 1.1.8.2 nathanw static int sapcic_io_map(pcmcia_chipset_handle_t, int,
73 1.1.8.2 nathanw bus_addr_t, bus_size_t,
74 1.1.8.2 nathanw struct pcmcia_io_handle *, int *);
75 1.1.8.2 nathanw static void sapcic_io_unmap(pcmcia_chipset_handle_t, int);
76 1.1.8.2 nathanw static void *sapcic_intr_establish(pcmcia_chipset_handle_t,
77 1.1.8.2 nathanw struct pcmcia_function *, int,
78 1.1.8.2 nathanw int (*)(void *), void *);
79 1.1.8.2 nathanw static void sapcic_intr_disestablish(pcmcia_chipset_handle_t,
80 1.1.8.2 nathanw void *);
81 1.1.8.2 nathanw static void sapcic_socket_enable(pcmcia_chipset_handle_t);
82 1.1.8.2 nathanw static void sapcic_socket_disable(pcmcia_chipset_handle_t);
83 1.1.8.2 nathanw
84 1.1.8.2 nathanw static void sapcic_event_thread(void *);
85 1.1.8.2 nathanw
86 1.1.8.2 nathanw static void sapcic_delay(int, const char *);
87 1.1.8.2 nathanw
88 1.1.8.2 nathanw #ifdef DEBUG
89 1.1.8.2 nathanw #define DPRINTF(arg) printf arg
90 1.1.8.2 nathanw #else
91 1.1.8.2 nathanw #define DPRINTF(arg)
92 1.1.8.2 nathanw #endif
93 1.1.8.2 nathanw
94 1.1.8.2 nathanw struct pcmcia_chip_functions sa11x0_pcmcia_functions = {
95 1.1.8.2 nathanw sapcic_mem_alloc,
96 1.1.8.2 nathanw sapcic_mem_free,
97 1.1.8.2 nathanw sapcic_mem_map,
98 1.1.8.2 nathanw sapcic_mem_unmap,
99 1.1.8.2 nathanw
100 1.1.8.2 nathanw sapcic_io_alloc,
101 1.1.8.2 nathanw sapcic_io_free,
102 1.1.8.2 nathanw sapcic_io_map,
103 1.1.8.2 nathanw sapcic_io_unmap,
104 1.1.8.2 nathanw
105 1.1.8.2 nathanw sapcic_intr_establish,
106 1.1.8.2 nathanw sapcic_intr_disestablish,
107 1.1.8.2 nathanw
108 1.1.8.2 nathanw sapcic_socket_enable,
109 1.1.8.2 nathanw sapcic_socket_disable,
110 1.1.8.2 nathanw };
111 1.1.8.2 nathanw
112 1.1.8.2 nathanw
113 1.1.8.2 nathanw void
114 1.1.8.2 nathanw sapcic_kthread_create(arg)
115 1.1.8.2 nathanw void *arg;
116 1.1.8.2 nathanw {
117 1.1.8.2 nathanw struct sapcic_socket *so = arg;
118 1.1.8.2 nathanw
119 1.1.8.2 nathanw /* XXX attach card if already present */
120 1.1.8.2 nathanw
121 1.1.8.2 nathanw so->laststatus =(so->pcictag->read)(so, SAPCIC_STATUS_CARD);
122 1.1.8.2 nathanw if (so->laststatus == SAPCIC_CARD_VALID) {
123 1.1.8.2 nathanw printf("%s: card present\n",
124 1.1.8.2 nathanw so->sc->sc_dev.dv_xname);
125 1.1.8.2 nathanw
126 1.1.8.2 nathanw pcmcia_card_attach(so->pcmcia);
127 1.1.8.2 nathanw }
128 1.1.8.2 nathanw
129 1.1.8.2 nathanw if (kthread_create1(sapcic_event_thread, so, &so->event_thread,
130 1.1.8.2 nathanw "%s,%d", so->sc->sc_dev.dv_xname, so->socket)) {
131 1.1.8.2 nathanw printf("%s: unable to create event thread for socket %d\n",
132 1.1.8.2 nathanw so->sc->sc_dev.dv_xname, so->socket);
133 1.1.8.2 nathanw panic("sapcic_kthread_create");
134 1.1.8.2 nathanw }
135 1.1.8.2 nathanw }
136 1.1.8.2 nathanw
137 1.1.8.2 nathanw static void
138 1.1.8.2 nathanw sapcic_event_thread(arg)
139 1.1.8.2 nathanw void *arg;
140 1.1.8.2 nathanw {
141 1.1.8.2 nathanw struct sapcic_socket *so = arg;
142 1.1.8.2 nathanw int newstatus, s;
143 1.1.8.2 nathanw
144 1.1.8.2 nathanw while (so->shutdown == 0) {
145 1.1.8.2 nathanw /*
146 1.1.8.2 nathanw * Serialize event processing on the PCIC. We may
147 1.1.8.2 nathanw * sleep while we hold this lock.
148 1.1.8.2 nathanw */
149 1.1.8.2 nathanw (void) lockmgr(&so->sc->sc_lock, LK_EXCLUSIVE, NULL);
150 1.1.8.2 nathanw
151 1.1.8.2 nathanw /* sleep .25s to be enqueued chatterling interrupts */
152 1.1.8.2 nathanw (void) tsleep((caddr_t)sapcic_event_thread, PWAIT,
153 1.1.8.2 nathanw "pcicss", hz/4);
154 1.1.8.2 nathanw
155 1.1.8.2 nathanw s = splhigh();
156 1.1.8.2 nathanw so->event = 0;
157 1.1.8.2 nathanw
158 1.1.8.2 nathanw /* we don't rely on interrupt type */
159 1.1.8.2 nathanw newstatus = (so->pcictag->read)(so, SAPCIC_STATUS_CARD);
160 1.1.8.2 nathanw splx(s);
161 1.1.8.2 nathanw
162 1.1.8.2 nathanw if (so->laststatus == newstatus) {
163 1.1.8.2 nathanw /*
164 1.1.8.2 nathanw * No events to process; release the PCIC lock.
165 1.1.8.2 nathanw */
166 1.1.8.2 nathanw (void) lockmgr(&so->sc->sc_lock, LK_RELEASE, NULL);
167 1.1.8.2 nathanw (void) tsleep(&so->event, PWAIT, "pcicev", hz);
168 1.1.8.2 nathanw continue;
169 1.1.8.2 nathanw }
170 1.1.8.2 nathanw
171 1.1.8.2 nathanw so->laststatus = newstatus;
172 1.1.8.2 nathanw switch (newstatus) {
173 1.1.8.2 nathanw case SAPCIC_CARD_VALID:
174 1.1.8.2 nathanw printf("%s: insertion event\n",
175 1.1.8.2 nathanw so->sc->sc_dev.dv_xname);
176 1.1.8.2 nathanw
177 1.1.8.2 nathanw pcmcia_card_attach(so->pcmcia);
178 1.1.8.2 nathanw break;
179 1.1.8.2 nathanw
180 1.1.8.2 nathanw case SAPCIC_CARD_INVALID:
181 1.1.8.2 nathanw printf("%s: removal event\n",
182 1.1.8.2 nathanw so->sc->sc_dev.dv_xname);
183 1.1.8.2 nathanw
184 1.1.8.2 nathanw pcmcia_card_detach(so->pcmcia, DETACH_FORCE);
185 1.1.8.2 nathanw break;
186 1.1.8.2 nathanw
187 1.1.8.2 nathanw default:
188 1.1.8.2 nathanw panic("sapcic_event_thread: unknown status %d",
189 1.1.8.2 nathanw newstatus);
190 1.1.8.2 nathanw }
191 1.1.8.2 nathanw
192 1.1.8.2 nathanw (void) lockmgr(&so->sc->sc_lock, LK_RELEASE, NULL);
193 1.1.8.2 nathanw }
194 1.1.8.2 nathanw
195 1.1.8.2 nathanw so->event_thread = NULL;
196 1.1.8.2 nathanw
197 1.1.8.2 nathanw /* In case parent is waiting for us to exit. */
198 1.1.8.2 nathanw wakeup(so->sc);
199 1.1.8.2 nathanw
200 1.1.8.2 nathanw kthread_exit(0);
201 1.1.8.2 nathanw }
202 1.1.8.2 nathanw
203 1.1.8.2 nathanw static void
204 1.1.8.2 nathanw sapcic_delay(timo, wmesg)
205 1.1.8.2 nathanw int timo; /* in milliseconds */
206 1.1.8.2 nathanw const char *wmesg;
207 1.1.8.2 nathanw {
208 1.1.8.2 nathanw #ifdef DIAGNOSTIC
209 1.1.8.2 nathanw if (curlwp == NULL)
210 1.1.8.2 nathanw panic("sapcic_delay: called in interrupt context\n");
211 1.1.8.2 nathanw #endif
212 1.1.8.2 nathanw
213 1.1.8.2 nathanw tsleep(sapcic_delay, PWAIT, wmesg, roundup(timo * hz, 1000) / 1000);
214 1.1.8.2 nathanw }
215 1.1.8.2 nathanw
216 1.1.8.2 nathanw int
217 1.1.8.2 nathanw sapcic_intr(arg)
218 1.1.8.2 nathanw void *arg;
219 1.1.8.2 nathanw {
220 1.1.8.2 nathanw struct sapcic_socket *so = arg;
221 1.1.8.2 nathanw
222 1.1.8.2 nathanw so->event++;
223 1.1.8.2 nathanw (so->pcictag->clear_intr)(so->socket);
224 1.1.8.2 nathanw wakeup(&so->event);
225 1.1.8.2 nathanw return 1;
226 1.1.8.2 nathanw }
227 1.1.8.2 nathanw
228 1.1.8.2 nathanw static int
229 1.1.8.2 nathanw sapcic_mem_alloc(pch, size, pmh)
230 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
231 1.1.8.2 nathanw bus_size_t size;
232 1.1.8.2 nathanw struct pcmcia_mem_handle *pmh;
233 1.1.8.2 nathanw {
234 1.1.8.2 nathanw struct sapcic_socket *so = pch;
235 1.1.8.2 nathanw
236 1.1.8.2 nathanw /* All we need is bus space tag */
237 1.1.8.2 nathanw memset(pmh, 0, sizeof(*pmh));
238 1.1.8.2 nathanw pmh->memt = so->sc->sc_iot;
239 1.1.8.2 nathanw return (0);
240 1.1.8.2 nathanw }
241 1.1.8.2 nathanw
242 1.1.8.2 nathanw
243 1.1.8.2 nathanw static void
244 1.1.8.2 nathanw sapcic_mem_free(pch, pmh)
245 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
246 1.1.8.2 nathanw struct pcmcia_mem_handle *pmh;
247 1.1.8.2 nathanw {
248 1.1.8.2 nathanw }
249 1.1.8.2 nathanw
250 1.1.8.2 nathanw static int
251 1.1.8.2 nathanw sapcic_mem_map(pch, kind, card_addr, size, pmh, offsetp, windowp)
252 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
253 1.1.8.2 nathanw int kind;
254 1.1.8.2 nathanw bus_addr_t card_addr;
255 1.1.8.2 nathanw bus_size_t size;
256 1.1.8.2 nathanw struct pcmcia_mem_handle *pmh;
257 1.1.8.2 nathanw bus_addr_t *offsetp;
258 1.1.8.2 nathanw int *windowp;
259 1.1.8.2 nathanw {
260 1.1.8.2 nathanw struct sapcic_socket *so = pch;
261 1.1.8.2 nathanw int error;
262 1.1.8.2 nathanw bus_addr_t pa;
263 1.1.8.2 nathanw
264 1.1.8.2 nathanw pa = trunc_page(card_addr);
265 1.1.8.2 nathanw *offsetp = card_addr - pa;
266 1.1.8.2 nathanw size = round_page(card_addr + size) - pa;
267 1.1.8.2 nathanw pmh->realsize = size;
268 1.1.8.2 nathanw
269 1.1.8.2 nathanw pa += SAPCIC_BASE_OFFSET;
270 1.1.8.2 nathanw pa += SAPCIC_SOCKET_OFFSET * so->socket;
271 1.1.8.2 nathanw
272 1.1.8.2 nathanw switch (kind & ~PCMCIA_WIDTH_MEM_MASK) {
273 1.1.8.2 nathanw case PCMCIA_MEM_ATTR:
274 1.1.8.2 nathanw pa += SAPCIC_ATTR_OFFSET;
275 1.1.8.2 nathanw break;
276 1.1.8.2 nathanw case PCMCIA_MEM_COMMON:
277 1.1.8.2 nathanw pa += SAPCIC_COMMON_OFFSET;
278 1.1.8.2 nathanw break;
279 1.1.8.2 nathanw default:
280 1.1.8.2 nathanw panic("sapcic_mem_map: bogus kind\n");
281 1.1.8.2 nathanw }
282 1.1.8.2 nathanw
283 1.1.8.2 nathanw error = bus_space_map(so->sc->sc_iot, pa, size, 0, &pmh->memh);
284 1.1.8.2 nathanw if (! error)
285 1.1.8.2 nathanw *windowp = (int)pmh->memh;
286 1.1.8.2 nathanw return (error);
287 1.1.8.2 nathanw }
288 1.1.8.2 nathanw
289 1.1.8.2 nathanw static void
290 1.1.8.2 nathanw sapcic_mem_unmap(pch, window)
291 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
292 1.1.8.2 nathanw int window;
293 1.1.8.2 nathanw {
294 1.1.8.2 nathanw struct sapcic_socket *so = pch;
295 1.1.8.2 nathanw
296 1.1.8.2 nathanw bus_space_unmap(so->sc->sc_iot, (bus_addr_t)window, 4096); /* XXX */
297 1.1.8.2 nathanw }
298 1.1.8.2 nathanw
299 1.1.8.2 nathanw static int
300 1.1.8.2 nathanw sapcic_io_alloc(pch, start, size, align, pih)
301 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
302 1.1.8.2 nathanw bus_addr_t start;
303 1.1.8.2 nathanw bus_size_t size;
304 1.1.8.2 nathanw bus_size_t align;
305 1.1.8.2 nathanw struct pcmcia_io_handle *pih;
306 1.1.8.2 nathanw {
307 1.1.8.2 nathanw struct sapcic_socket *so = pch;
308 1.1.8.2 nathanw int error;
309 1.1.8.2 nathanw bus_addr_t pa;
310 1.1.8.2 nathanw
311 1.1.8.2 nathanw memset(pih, 0, sizeof(*pih));
312 1.1.8.2 nathanw pih->iot = so->sc->sc_iot;
313 1.1.8.2 nathanw pih->addr = start;
314 1.1.8.2 nathanw pih->size = size;
315 1.1.8.2 nathanw
316 1.1.8.2 nathanw pa = pih->addr;
317 1.1.8.2 nathanw pa += SAPCIC_BASE_OFFSET;
318 1.1.8.2 nathanw pa += SAPCIC_SOCKET_OFFSET * so->socket;
319 1.1.8.2 nathanw
320 1.1.8.2 nathanw DPRINTF(("sapcic_io_alloc: %x %x\n", (unsigned int)pa,
321 1.1.8.2 nathanw (unsigned int)size));
322 1.1.8.2 nathanw /* XXX Are we ignoring alignment constraints? */
323 1.1.8.2 nathanw error = bus_space_map(so->sc->sc_iot, pa, size, 0, &pih->ioh);
324 1.1.8.2 nathanw
325 1.1.8.2 nathanw return (error);
326 1.1.8.2 nathanw }
327 1.1.8.2 nathanw
328 1.1.8.2 nathanw static void
329 1.1.8.2 nathanw sapcic_io_free(pch, pih)
330 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
331 1.1.8.2 nathanw struct pcmcia_io_handle *pih;
332 1.1.8.2 nathanw {
333 1.1.8.2 nathanw struct sapcic_socket *so = pch;
334 1.1.8.2 nathanw
335 1.1.8.2 nathanw bus_space_unmap(so->sc->sc_iot, pih->ioh, pih->size);
336 1.1.8.2 nathanw }
337 1.1.8.2 nathanw
338 1.1.8.2 nathanw static int
339 1.1.8.2 nathanw sapcic_io_map(pch, width, offset, size, pih, windowp)
340 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
341 1.1.8.2 nathanw int width;
342 1.1.8.2 nathanw bus_addr_t offset;
343 1.1.8.2 nathanw bus_size_t size;
344 1.1.8.2 nathanw struct pcmcia_io_handle *pih;
345 1.1.8.2 nathanw int *windowp;
346 1.1.8.2 nathanw {
347 1.1.8.2 nathanw return (0);
348 1.1.8.2 nathanw }
349 1.1.8.2 nathanw
350 1.1.8.2 nathanw static void sapcic_io_unmap(pch, window)
351 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
352 1.1.8.2 nathanw int window;
353 1.1.8.2 nathanw {
354 1.1.8.2 nathanw }
355 1.1.8.2 nathanw
356 1.1.8.2 nathanw static void *
357 1.1.8.2 nathanw sapcic_intr_establish(pch, pf, ipl, fct, arg)
358 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
359 1.1.8.2 nathanw struct pcmcia_function *pf;
360 1.1.8.2 nathanw int ipl;
361 1.1.8.2 nathanw int (*fct)(void *);
362 1.1.8.2 nathanw void *arg;
363 1.1.8.2 nathanw {
364 1.1.8.2 nathanw struct sapcic_socket *so = pch;
365 1.1.8.2 nathanw
366 1.1.8.2 nathanw /* XXX need to check if something should be done here */
367 1.1.8.2 nathanw
368 1.1.8.2 nathanw return ((so->pcictag->intr_establish)(so, ipl, fct, arg));
369 1.1.8.2 nathanw }
370 1.1.8.2 nathanw
371 1.1.8.2 nathanw static void
372 1.1.8.2 nathanw sapcic_intr_disestablish(pch, ih)
373 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
374 1.1.8.2 nathanw void *ih;
375 1.1.8.2 nathanw {
376 1.1.8.2 nathanw struct sapcic_socket *so = pch;
377 1.1.8.2 nathanw
378 1.1.8.2 nathanw ((so->pcictag->intr_disestablish)(so, ih));
379 1.1.8.2 nathanw }
380 1.1.8.2 nathanw
381 1.1.8.2 nathanw static void
382 1.1.8.2 nathanw sapcic_socket_enable(pch)
383 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
384 1.1.8.2 nathanw {
385 1.1.8.2 nathanw struct sapcic_socket *so = pch;
386 1.1.8.2 nathanw int i;
387 1.1.8.2 nathanw
388 1.1.8.2 nathanw #if defined(DIAGNOSTIC) && defined(notyet)
389 1.1.8.2 nathanw if (so->flags & PCIC_FLAG_ENABLED)
390 1.1.8.2 nathanw printf("sapcic_socket_enable: enabling twice\n");
391 1.1.8.2 nathanw #endif
392 1.1.8.2 nathanw
393 1.1.8.2 nathanw /* disable interrupts */
394 1.1.8.2 nathanw
395 1.1.8.2 nathanw /* power down the socket to reset it, clear the card reset pin */
396 1.1.8.2 nathanw (so->pcictag->set_power)(so, SAPCIC_POWER_OFF);
397 1.1.8.2 nathanw
398 1.1.8.2 nathanw /*
399 1.1.8.2 nathanw * wait 300ms until power fails (Tpf). Then, wait 100ms since
400 1.1.8.2 nathanw * we are changing Vcc (Toff).
401 1.1.8.2 nathanw */
402 1.1.8.2 nathanw sapcic_delay(300 + 100, "pccen0");
403 1.1.8.2 nathanw
404 1.1.8.2 nathanw /* power up the socket */
405 1.1.8.2 nathanw /* XXX voltage selection should be done in PCMCIA code */
406 1.1.8.2 nathanw if (so->power_capability & SAPCIC_POWER_5V) {
407 1.1.8.2 nathanw (so->pcictag->set_power)(so, SAPCIC_POWER_5V);
408 1.1.8.2 nathanw (so->pcictag->write)(so, SAPCIC_CONTROL_POWERSELECT,
409 1.1.8.2 nathanw SAPCIC_POWER_5V);
410 1.1.8.2 nathanw } else {
411 1.1.8.2 nathanw (so->pcictag->set_power)(so, SAPCIC_POWER_3V);
412 1.1.8.2 nathanw (so->pcictag->write)(so, SAPCIC_CONTROL_POWERSELECT,
413 1.1.8.2 nathanw SAPCIC_POWER_3V);
414 1.1.8.2 nathanw }
415 1.1.8.2 nathanw
416 1.1.8.2 nathanw /* enable PCMCIA control lines */
417 1.1.8.2 nathanw (so->pcictag->write)(so, SAPCIC_CONTROL_LINEENABLE, 1);
418 1.1.8.2 nathanw
419 1.1.8.2 nathanw /*
420 1.1.8.2 nathanw * wait 100ms until power raise (Tpr) and 20ms to become
421 1.1.8.2 nathanw * stable (Tsu(Vcc)).
422 1.1.8.2 nathanw *
423 1.1.8.2 nathanw * some machines require some more time to be settled
424 1.1.8.2 nathanw * (300ms is added here).
425 1.1.8.2 nathanw */
426 1.1.8.2 nathanw sapcic_delay(100 + 20 + 300, "pccen1");
427 1.1.8.2 nathanw
428 1.1.8.2 nathanw /* honor nWAIT signal */
429 1.1.8.2 nathanw (so->pcictag->write)(so, SAPCIC_CONTROL_WAITENABLE, 1);
430 1.1.8.2 nathanw /* now make sure we have reset# active */
431 1.1.8.2 nathanw (so->pcictag->write)(so, SAPCIC_CONTROL_RESET, 1);
432 1.1.8.2 nathanw
433 1.1.8.2 nathanw /*
434 1.1.8.2 nathanw * hold RESET at least 10us, this is a min allow for slop in
435 1.1.8.2 nathanw * delay routine.
436 1.1.8.2 nathanw */
437 1.1.8.2 nathanw delay(20);
438 1.1.8.2 nathanw
439 1.1.8.2 nathanw /* clear the reset flag */
440 1.1.8.2 nathanw (so->pcictag->write)(so, SAPCIC_CONTROL_RESET, 0);
441 1.1.8.2 nathanw
442 1.1.8.2 nathanw /* wait 20ms as per pc card standard (r2.01) section 4.3.6 */
443 1.1.8.2 nathanw sapcic_delay(20, "pccen2");
444 1.1.8.2 nathanw
445 1.1.8.2 nathanw /* wait for the chip to finish initializing */
446 1.1.8.2 nathanw sapcic_delay(10, "pccen3");
447 1.1.8.2 nathanw for(i = 100; i; i--) {
448 1.1.8.2 nathanw if ((so->pcictag->read)(so, SAPCIC_STATUS_READY))
449 1.1.8.2 nathanw break;
450 1.1.8.2 nathanw sapcic_delay(100, "pccen4");
451 1.1.8.2 nathanw }
452 1.1.8.2 nathanw DPRINTF(("sapcic_socket_enable: wait ready %d\n", 100 - i));
453 1.1.8.2 nathanw
454 1.1.8.2 nathanw /* finally enable the interrupt */
455 1.1.8.2 nathanw
456 1.1.8.2 nathanw }
457 1.1.8.2 nathanw
458 1.1.8.2 nathanw static void
459 1.1.8.2 nathanw sapcic_socket_disable(pch)
460 1.1.8.2 nathanw pcmcia_chipset_handle_t pch;
461 1.1.8.2 nathanw {
462 1.1.8.2 nathanw struct sapcic_socket *so = pch;
463 1.1.8.2 nathanw
464 1.1.8.2 nathanw /* XXX mask card interrupts */
465 1.1.8.2 nathanw
466 1.1.8.2 nathanw /* power down the card */
467 1.1.8.2 nathanw (so->pcictag->set_power)(so, SAPCIC_POWER_OFF);
468 1.1.8.2 nathanw
469 1.1.8.2 nathanw /* float controller lines */
470 1.1.8.2 nathanw (so->pcictag->write)(so, SAPCIC_CONTROL_LINEENABLE, 0);
471 1.1.8.2 nathanw }
472