imx_pcic.c revision 1.1.20.1 1 1.1.20.1 mjf /* $Id: imx_pcic.c,v 1.1.20.1 2008/06/02 13:21:53 mjf Exp $ */
2 1.1.20.1 mjf
3 1.1.20.1 mjf /*
4 1.1.20.1 mjf * IMX CF interface to pcic/pcmcia
5 1.1.20.1 mjf * derived from pxa2x0_pcic
6 1.1.20.1 mjf * Sun Apr 1 21:42:37 PDT 2007
7 1.1.20.1 mjf */
8 1.1.20.1 mjf
9 1.1.20.1 mjf /* $NetBSD: imx_pcic.c,v 1.1.20.1 2008/06/02 13:21:53 mjf Exp $ */
10 1.1.20.1 mjf /* $OpenBSD: pxa2x0_pcic.c,v 1.17 2005/12/14 15:08:51 uwe Exp $ */
11 1.1.20.1 mjf
12 1.1.20.1 mjf /*
13 1.1.20.1 mjf * Copyright (c) 2005 Dale Rahn <drahn (at) openbsd.org>
14 1.1.20.1 mjf *
15 1.1.20.1 mjf * Permission to use, copy, modify, and distribute this software for any
16 1.1.20.1 mjf * purpose with or without fee is hereby granted, provided that the above
17 1.1.20.1 mjf * copyright notice and this permission notice appear in all copies.
18 1.1.20.1 mjf *
19 1.1.20.1 mjf * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
20 1.1.20.1 mjf * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
21 1.1.20.1 mjf * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
22 1.1.20.1 mjf * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
23 1.1.20.1 mjf * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
24 1.1.20.1 mjf * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
25 1.1.20.1 mjf * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 1.1.20.1 mjf */
27 1.1.20.1 mjf
28 1.1.20.1 mjf #include <sys/cdefs.h>
29 1.1.20.1 mjf __KERNEL_RCSID(0, "$Id: imx_pcic.c,v 1.1.20.1 2008/06/02 13:21:53 mjf Exp $");
30 1.1.20.1 mjf
31 1.1.20.1 mjf #include <sys/param.h>
32 1.1.20.1 mjf #include <sys/systm.h>
33 1.1.20.1 mjf #include <sys/device.h>
34 1.1.20.1 mjf #include <sys/kernel.h>
35 1.1.20.1 mjf #include <sys/kthread.h>
36 1.1.20.1 mjf #include <sys/malloc.h>
37 1.1.20.1 mjf
38 1.1.20.1 mjf #include <uvm/uvm.h>
39 1.1.20.1 mjf
40 1.1.20.1 mjf #include <machine/bus.h>
41 1.1.20.1 mjf #include <machine/intr.h>
42 1.1.20.1 mjf
43 1.1.20.1 mjf #include <dev/pcmcia/pcmciareg.h>
44 1.1.20.1 mjf #include <dev/pcmcia/pcmciavar.h>
45 1.1.20.1 mjf #include <dev/pcmcia/pcmciachip.h>
46 1.1.20.1 mjf
47 1.1.20.1 mjf #ifdef NOTYET
48 1.1.20.1 mjf #include <arm/imx/imx_gpio.h>
49 1.1.20.1 mjf #endif
50 1.1.20.1 mjf #include <arm/imx/imx_pcic.h>
51 1.1.20.1 mjf
52 1.1.20.1 mjf static int imx_pcic_print(void *, const char *);
53 1.1.20.1 mjf
54 1.1.20.1 mjf static void imx_pcic_event_thread(void *);
55 1.1.20.1 mjf #ifdef NOTYET
56 1.1.20.1 mjf static void imx_pcic_event_process(struct imx_pcic_socket *);
57 1.1.20.1 mjf static void imx_pcic_attach_card(struct imx_pcic_socket *);
58 1.1.20.1 mjf #endif
59 1.1.20.1 mjf #ifdef NOTYET
60 1.1.20.1 mjf static void imx_pcic_detach_card(struct imx_pcic_socket *, int);
61 1.1.20.1 mjf #endif
62 1.1.20.1 mjf
63 1.1.20.1 mjf static int imx_pcic_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
64 1.1.20.1 mjf struct pcmcia_mem_handle *);
65 1.1.20.1 mjf static void imx_pcic_mem_free(pcmcia_chipset_handle_t,
66 1.1.20.1 mjf struct pcmcia_mem_handle *);
67 1.1.20.1 mjf static int imx_pcic_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t,
68 1.1.20.1 mjf bus_size_t, struct pcmcia_mem_handle *, bus_size_t *, int *);
69 1.1.20.1 mjf static void imx_pcic_mem_unmap(pcmcia_chipset_handle_t, int);
70 1.1.20.1 mjf
71 1.1.20.1 mjf static int imx_pcic_io_alloc(pcmcia_chipset_handle_t, bus_addr_t,
72 1.1.20.1 mjf bus_size_t, bus_size_t, struct pcmcia_io_handle *);
73 1.1.20.1 mjf static void imx_pcic_io_free(pcmcia_chipset_handle_t,
74 1.1.20.1 mjf struct pcmcia_io_handle *);
75 1.1.20.1 mjf static int imx_pcic_io_map(pcmcia_chipset_handle_t, int,
76 1.1.20.1 mjf bus_addr_t, bus_size_t, struct pcmcia_io_handle *, int *);
77 1.1.20.1 mjf static void imx_pcic_io_unmap(pcmcia_chipset_handle_t, int);
78 1.1.20.1 mjf
79 1.1.20.1 mjf static void *imx_pcic_intr_establish(pcmcia_chipset_handle_t,
80 1.1.20.1 mjf struct pcmcia_function *, int, int (*)(void *), void *);
81 1.1.20.1 mjf static void imx_pcic_intr_disestablish(pcmcia_chipset_handle_t, void *);
82 1.1.20.1 mjf
83 1.1.20.1 mjf static void imx_pcic_socket_enable(pcmcia_chipset_handle_t);
84 1.1.20.1 mjf static void imx_pcic_socket_disable(pcmcia_chipset_handle_t);
85 1.1.20.1 mjf static void imx_pcic_socket_settype(pcmcia_chipset_handle_t, int);
86 1.1.20.1 mjf
87 1.1.20.1 mjf /*
88 1.1.20.1 mjf * PCMCIA chipset methods
89 1.1.20.1 mjf */
90 1.1.20.1 mjf static struct pcmcia_chip_functions imx_pcic_pcmcia_functions = {
91 1.1.20.1 mjf imx_pcic_mem_alloc,
92 1.1.20.1 mjf imx_pcic_mem_free,
93 1.1.20.1 mjf imx_pcic_mem_map,
94 1.1.20.1 mjf imx_pcic_mem_unmap,
95 1.1.20.1 mjf
96 1.1.20.1 mjf imx_pcic_io_alloc,
97 1.1.20.1 mjf imx_pcic_io_free,
98 1.1.20.1 mjf imx_pcic_io_map,
99 1.1.20.1 mjf imx_pcic_io_unmap,
100 1.1.20.1 mjf
101 1.1.20.1 mjf imx_pcic_intr_establish,
102 1.1.20.1 mjf imx_pcic_intr_disestablish,
103 1.1.20.1 mjf
104 1.1.20.1 mjf imx_pcic_socket_enable,
105 1.1.20.1 mjf imx_pcic_socket_disable,
106 1.1.20.1 mjf imx_pcic_socket_settype,
107 1.1.20.1 mjf };
108 1.1.20.1 mjf
109 1.1.20.1 mjf #define IMX_MEMCTL_BASE 0x08000000 /* XXX */
110 1.1.20.1 mjf #define IMX_MEMCTL_SIZE 0x00000010 /* XXX */
111 1.1.20.1 mjf #define IMX_PCIC_SOCKET_BASE 0x08009000 /* XXX */
112 1.1.20.1 mjf #define IMX_PCIC_SOCKET_OFFSET 0x00000000 /* XXX */
113 1.1.20.1 mjf #define IMX_PCIC_ATTR_OFFSET 0x00000800 /* XXX 5912 */
114 1.1.20.1 mjf #define IMX_PCIC_COMMON_OFFSET 0x00000000 /* XXX 5912 */
115 1.1.20.1 mjf
116 1.1.20.1 mjf
117 1.1.20.1 mjf
118 1.1.20.1 mjf /*
119 1.1.20.1 mjf * PCMCIA Helpers
120 1.1.20.1 mjf */
121 1.1.20.1 mjf static int
122 1.1.20.1 mjf imx_pcic_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size,
123 1.1.20.1 mjf struct pcmcia_mem_handle *pmh)
124 1.1.20.1 mjf {
125 1.1.20.1 mjf struct imx_pcic_socket *so = (struct imx_pcic_socket *)pch;
126 1.1.20.1 mjf
127 1.1.20.1 mjf /* All we need is the bus space tag */
128 1.1.20.1 mjf memset(pmh, 0, sizeof(*pmh));
129 1.1.20.1 mjf pmh->memt = so->sc->sc_iot;
130 1.1.20.1 mjf
131 1.1.20.1 mjf return 0;
132 1.1.20.1 mjf }
133 1.1.20.1 mjf
134 1.1.20.1 mjf static void
135 1.1.20.1 mjf imx_pcic_mem_free(pcmcia_chipset_handle_t pch, struct pcmcia_mem_handle *pmh)
136 1.1.20.1 mjf {
137 1.1.20.1 mjf
138 1.1.20.1 mjf /* Nothing to do */
139 1.1.20.1 mjf }
140 1.1.20.1 mjf
141 1.1.20.1 mjf static int
142 1.1.20.1 mjf imx_pcic_mem_map(pcmcia_chipset_handle_t pch, int kind, bus_addr_t card_addr,
143 1.1.20.1 mjf bus_size_t size, struct pcmcia_mem_handle *pmh, bus_size_t *offsetp,
144 1.1.20.1 mjf int *windowp)
145 1.1.20.1 mjf {
146 1.1.20.1 mjf struct imx_pcic_socket *so = (struct imx_pcic_socket *)pch;
147 1.1.20.1 mjf int error;
148 1.1.20.1 mjf bus_addr_t pa;
149 1.1.20.1 mjf
150 1.1.20.1 mjf printf("%s: card_addr %lx\n", __FUNCTION__, card_addr);
151 1.1.20.1 mjf pa = trunc_page(card_addr);
152 1.1.20.1 mjf *offsetp = card_addr - pa;
153 1.1.20.1 mjf printf("%s: offset %lx\n", __FUNCTION__, *offsetp);
154 1.1.20.1 mjf size = round_page(card_addr + size) - pa;
155 1.1.20.1 mjf pmh->realsize = size;
156 1.1.20.1 mjf
157 1.1.20.1 mjf pa += IMX_PCIC_SOCKET_BASE;
158 1.1.20.1 mjf pa += IMX_PCIC_SOCKET_OFFSET * so->socket;
159 1.1.20.1 mjf printf("%s: pa %lx\n", __FUNCTION__, pa);
160 1.1.20.1 mjf printf("%s: kind %x\n", __FUNCTION__, kind);
161 1.1.20.1 mjf
162 1.1.20.1 mjf switch (kind & ~PCMCIA_WIDTH_MEM_MASK) {
163 1.1.20.1 mjf case PCMCIA_MEM_ATTR:
164 1.1.20.1 mjf pa += IMX_PCIC_ATTR_OFFSET;
165 1.1.20.1 mjf break;
166 1.1.20.1 mjf case PCMCIA_MEM_COMMON:
167 1.1.20.1 mjf pa += IMX_PCIC_COMMON_OFFSET;
168 1.1.20.1 mjf break;
169 1.1.20.1 mjf default:
170 1.1.20.1 mjf panic("imx_pcic_mem_map: bogus kind");
171 1.1.20.1 mjf }
172 1.1.20.1 mjf
173 1.1.20.1 mjf printf("%s: pa %lx\n", __FUNCTION__, pa);
174 1.1.20.1 mjf Debugger();
175 1.1.20.1 mjf error = bus_space_map(so->sc->sc_iot, pa, size, 0, &pmh->memh);
176 1.1.20.1 mjf if (error)
177 1.1.20.1 mjf return error;
178 1.1.20.1 mjf
179 1.1.20.1 mjf *windowp = (int)pmh->memh;
180 1.1.20.1 mjf return 0;
181 1.1.20.1 mjf }
182 1.1.20.1 mjf
183 1.1.20.1 mjf static void
184 1.1.20.1 mjf imx_pcic_mem_unmap(pcmcia_chipset_handle_t pch, int window)
185 1.1.20.1 mjf {
186 1.1.20.1 mjf struct imx_pcic_socket *so = (struct imx_pcic_socket *)pch;
187 1.1.20.1 mjf
188 1.1.20.1 mjf bus_space_unmap(so->sc->sc_iot, (bus_addr_t)window, 4096); /* XXX */
189 1.1.20.1 mjf }
190 1.1.20.1 mjf
191 1.1.20.1 mjf static int
192 1.1.20.1 mjf imx_pcic_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start,
193 1.1.20.1 mjf bus_size_t size, bus_size_t align, struct pcmcia_io_handle *pih)
194 1.1.20.1 mjf {
195 1.1.20.1 mjf struct imx_pcic_socket *so = (struct imx_pcic_socket *)pch;
196 1.1.20.1 mjf bus_addr_t pa;
197 1.1.20.1 mjf int error;
198 1.1.20.1 mjf
199 1.1.20.1 mjf memset(pih, 0, sizeof(*pih));
200 1.1.20.1 mjf pih->iot = so->sc->sc_iot;
201 1.1.20.1 mjf pih->addr = start;
202 1.1.20.1 mjf pih->size = size;
203 1.1.20.1 mjf
204 1.1.20.1 mjf pa = pih->addr;
205 1.1.20.1 mjf pa += IMX_PCIC_SOCKET_BASE;
206 1.1.20.1 mjf pa += IMX_PCIC_SOCKET_OFFSET * so->socket;
207 1.1.20.1 mjf
208 1.1.20.1 mjf /* XXX Are we ignoring alignment constraints? */
209 1.1.20.1 mjf error = bus_space_map(so->sc->sc_iot, pa, size, 0, &pih->ioh);
210 1.1.20.1 mjf
211 1.1.20.1 mjf return error;
212 1.1.20.1 mjf }
213 1.1.20.1 mjf
214 1.1.20.1 mjf static void
215 1.1.20.1 mjf imx_pcic_io_free(pcmcia_chipset_handle_t pch, struct pcmcia_io_handle *pih)
216 1.1.20.1 mjf {
217 1.1.20.1 mjf struct imx_pcic_socket *so = (struct imx_pcic_socket *)pch;
218 1.1.20.1 mjf
219 1.1.20.1 mjf bus_space_unmap(so->sc->sc_iot, pih->ioh, pih->size);
220 1.1.20.1 mjf }
221 1.1.20.1 mjf
222 1.1.20.1 mjf static int
223 1.1.20.1 mjf imx_pcic_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset,
224 1.1.20.1 mjf bus_size_t size, struct pcmcia_io_handle *pih, int *windowp)
225 1.1.20.1 mjf {
226 1.1.20.1 mjf
227 1.1.20.1 mjf return 0;
228 1.1.20.1 mjf }
229 1.1.20.1 mjf
230 1.1.20.1 mjf static void
231 1.1.20.1 mjf imx_pcic_io_unmap(pcmcia_chipset_handle_t pch, int window)
232 1.1.20.1 mjf {
233 1.1.20.1 mjf
234 1.1.20.1 mjf /* Nothing to do */
235 1.1.20.1 mjf }
236 1.1.20.1 mjf
237 1.1.20.1 mjf static void *
238 1.1.20.1 mjf imx_pcic_intr_establish(pcmcia_chipset_handle_t pch,
239 1.1.20.1 mjf struct pcmcia_function *pf, int ipl, int (*fct)(void *), void *arg)
240 1.1.20.1 mjf {
241 1.1.20.1 mjf struct imx_pcic_socket *so = (struct imx_pcic_socket *)pch;
242 1.1.20.1 mjf /* XXX need to check if something should be done here */
243 1.1.20.1 mjf
244 1.1.20.1 mjf return (*so->pcictag->intr_establish)(so, ipl, fct, arg);
245 1.1.20.1 mjf }
246 1.1.20.1 mjf
247 1.1.20.1 mjf static void
248 1.1.20.1 mjf imx_pcic_intr_disestablish(pcmcia_chipset_handle_t pch, void *ih)
249 1.1.20.1 mjf {
250 1.1.20.1 mjf struct imx_pcic_socket *so = (struct imx_pcic_socket *)pch;
251 1.1.20.1 mjf
252 1.1.20.1 mjf (*so->pcictag->intr_disestablish)(so, ih);
253 1.1.20.1 mjf }
254 1.1.20.1 mjf
255 1.1.20.1 mjf static void
256 1.1.20.1 mjf imx_pcic_socket_enable(pcmcia_chipset_handle_t pch)
257 1.1.20.1 mjf {
258 1.1.20.1 mjf #ifdef NOTYET
259 1.1.20.1 mjf struct imx_pcic_socket *so = (struct imx_pcic_socket *)pch;
260 1.1.20.1 mjf int i;
261 1.1.20.1 mjf
262 1.1.20.1 mjf /* Power down the card and socket before setting the voltage. */
263 1.1.20.1 mjf (*so->pcictag->write)(so, IMX_PCIC_CARD_POWER, IMX_PCIC_POWER_OFF);
264 1.1.20.1 mjf (*so->pcictag->set_power)(so, IMX_PCIC_POWER_OFF);
265 1.1.20.1 mjf
266 1.1.20.1 mjf /*
267 1.1.20.1 mjf * Wait 300ms until power fails (Tpf). Then, wait 100ms since
268 1.1.20.1 mjf * we are changing Vcc (Toff).
269 1.1.20.1 mjf */
270 1.1.20.1 mjf delay((300 + 100) * 1000);
271 1.1.20.1 mjf
272 1.1.20.1 mjf /* Power up the socket and card at appropriate voltage. */
273 1.1.20.1 mjf if (so->power_capability & IMX_PCIC_POWER_5V) {
274 1.1.20.1 mjf (*so->pcictag->set_power)(so, IMX_PCIC_POWER_5V);
275 1.1.20.1 mjf (*so->pcictag->write)(so, IMX_PCIC_CARD_POWER,
276 1.1.20.1 mjf IMX_PCIC_POWER_5V);
277 1.1.20.1 mjf } else {
278 1.1.20.1 mjf (*so->pcictag->set_power)(so, IMX_PCIC_POWER_3V);
279 1.1.20.1 mjf (*so->pcictag->write)(so, IMX_PCIC_CARD_POWER,
280 1.1.20.1 mjf IMX_PCIC_POWER_3V);
281 1.1.20.1 mjf }
282 1.1.20.1 mjf
283 1.1.20.1 mjf /*
284 1.1.20.1 mjf * Wait 100ms until power raise (Tpr) and 20ms to become
285 1.1.20.1 mjf * stable (Tsu(Vcc)).
286 1.1.20.1 mjf *
287 1.1.20.1 mjf * Some machines require some more time to be settled
288 1.1.20.1 mjf * (another 200ms is added here).
289 1.1.20.1 mjf */
290 1.1.20.1 mjf delay((100 + 20 + 200) * 1000);
291 1.1.20.1 mjf
292 1.1.20.1 mjf /* Hold RESET at least 10us. */
293 1.1.20.1 mjf (*so->pcictag->write)(so, IMX_PCIC_CARD_RESET, 1);
294 1.1.20.1 mjf delay(10);
295 1.1.20.1 mjf /* XXX wrong, but lets TE-CF100 cards work for some reason. */
296 1.1.20.1 mjf delay(3000);
297 1.1.20.1 mjf (*so->pcictag->write)(so, IMX_PCIC_CARD_RESET, 0);
298 1.1.20.1 mjf
299 1.1.20.1 mjf /* Wait 20ms as per PC Card standard (r2.01) section 4.3.6. */
300 1.1.20.1 mjf delay(20 * 1000);
301 1.1.20.1 mjf
302 1.1.20.1 mjf /* Wait for the card to become ready. */
303 1.1.20.1 mjf for (i = 0; i < 10000; i++) {
304 1.1.20.1 mjf if ((*so->pcictag->read)(so, IMX_PCIC_CARD_READY))
305 1.1.20.1 mjf break;
306 1.1.20.1 mjf delay(500);
307 1.1.20.1 mjf }
308 1.1.20.1 mjf #else
309 1.1.20.1 mjf printf("%s: (stubbed)\n", __FUNCTION__);
310 1.1.20.1 mjf #endif /* NOTYET */
311 1.1.20.1 mjf }
312 1.1.20.1 mjf
313 1.1.20.1 mjf static void
314 1.1.20.1 mjf imx_pcic_socket_disable(pcmcia_chipset_handle_t pch)
315 1.1.20.1 mjf {
316 1.1.20.1 mjf #ifdef NOTYET
317 1.1.20.1 mjf struct imx_pcic_socket *so = (struct imx_pcic_socket *)pch;
318 1.1.20.1 mjf
319 1.1.20.1 mjf #ifdef PCICDEBUG
320 1.1.20.1 mjf printf("imx_pcic_socket_disable: socket %d\n", so->socket);
321 1.1.20.1 mjf #endif
322 1.1.20.1 mjf
323 1.1.20.1 mjf /* Power down the card and socket. */
324 1.1.20.1 mjf (*so->pcictag->write)(so, IMX_PCIC_CARD_POWER, IMX_PCIC_POWER_OFF);
325 1.1.20.1 mjf (*so->pcictag->set_power)(so, IMX_PCIC_POWER_OFF);
326 1.1.20.1 mjf #endif /* NOTYET */
327 1.1.20.1 mjf }
328 1.1.20.1 mjf
329 1.1.20.1 mjf static void
330 1.1.20.1 mjf imx_pcic_socket_settype(pcmcia_chipset_handle_t pch, int type)
331 1.1.20.1 mjf {
332 1.1.20.1 mjf
333 1.1.20.1 mjf #ifdef PCICDEBUG
334 1.1.20.1 mjf printf("imx_pcic_socket_settype: type=%d",type);
335 1.1.20.1 mjf
336 1.1.20.1 mjf switch (type) {
337 1.1.20.1 mjf case PCMCIA_IFTYPE_MEMORY:
338 1.1.20.1 mjf printf("(Memory)\n");
339 1.1.20.1 mjf break;
340 1.1.20.1 mjf case PCMCIA_IFTYPE_IO:
341 1.1.20.1 mjf printf("(I/O)\n");
342 1.1.20.1 mjf break;
343 1.1.20.1 mjf default:
344 1.1.20.1 mjf printf("(unknown)\n");
345 1.1.20.1 mjf break;
346 1.1.20.1 mjf }
347 1.1.20.1 mjf #endif
348 1.1.20.1 mjf }
349 1.1.20.1 mjf
350 1.1.20.1 mjf /*
351 1.1.20.1 mjf * Attachment and initialization
352 1.1.20.1 mjf */
353 1.1.20.1 mjf static int
354 1.1.20.1 mjf imx_pcic_print(void *aux, const char *name)
355 1.1.20.1 mjf {
356 1.1.20.1 mjf
357 1.1.20.1 mjf return UNCONF;
358 1.1.20.1 mjf }
359 1.1.20.1 mjf
360 1.1.20.1 mjf void
361 1.1.20.1 mjf imx_pcic_attach_common(struct imx_pcic_softc *sc,
362 1.1.20.1 mjf void (*socket_setup_hook)(struct imx_pcic_socket *))
363 1.1.20.1 mjf {
364 1.1.20.1 mjf struct pcmciabus_attach_args paa;
365 1.1.20.1 mjf struct imx_pcic_socket *so;
366 1.1.20.1 mjf int s[IMX_PCIC_NSLOT];
367 1.1.20.1 mjf int i;
368 1.1.20.1 mjf
369 1.1.20.1 mjf printf(": %d slot%s\n", sc->sc_nslots, sc->sc_nslots < 2 ? "" : "s");
370 1.1.20.1 mjf
371 1.1.20.1 mjf if (sc->sc_nslots == 0) {
372 1.1.20.1 mjf aprint_error("%s: can't attach\n", sc->sc_dev.dv_xname);
373 1.1.20.1 mjf return;
374 1.1.20.1 mjf }
375 1.1.20.1 mjf
376 1.1.20.1 mjf if (bus_space_map(sc->sc_iot, IMX_MEMCTL_BASE, IMX_MEMCTL_SIZE,
377 1.1.20.1 mjf 0, &sc->sc_memctl_ioh)) {
378 1.1.20.1 mjf aprint_error("%s: failed to map MEMCTL\n", sc->sc_dev.dv_xname);
379 1.1.20.1 mjf return;
380 1.1.20.1 mjf }
381 1.1.20.1 mjf
382 1.1.20.1 mjf #if 0
383 1.1.20.1 mjf /* Clear CIT (card present) and set NOS correctly. */
384 1.1.20.1 mjf bus_space_write_4(sc->sc_iot, sc->sc_memctl_ioh, MEMCTL_MECR,
385 1.1.20.1 mjf (sc->sc_nslots == 2) ? MECR_NOS : 0);
386 1.1.20.1 mjf #endif
387 1.1.20.1 mjf
388 1.1.20.1 mjf if (sc->sc_flags & PPF_REVERSE_ORDER) {
389 1.1.20.1 mjf for (i = 0; i < sc->sc_nslots; i++) {
390 1.1.20.1 mjf s[i] = sc->sc_nslots - 1 - i;
391 1.1.20.1 mjf }
392 1.1.20.1 mjf } else {
393 1.1.20.1 mjf for (i = 0; i < sc->sc_nslots; i++) {
394 1.1.20.1 mjf s[i] = i;
395 1.1.20.1 mjf }
396 1.1.20.1 mjf }
397 1.1.20.1 mjf
398 1.1.20.1 mjf for (i = 0; i < sc->sc_nslots; i++) {
399 1.1.20.1 mjf so = &sc->sc_socket[s[i]];
400 1.1.20.1 mjf so->sc = sc;
401 1.1.20.1 mjf so->socket = s[i];
402 1.1.20.1 mjf so->flags = 0;
403 1.1.20.1 mjf
404 1.1.20.1 mjf (*socket_setup_hook)(so);
405 1.1.20.1 mjf
406 1.1.20.1 mjf paa.paa_busname = "pcmcia";
407 1.1.20.1 mjf paa.pct = (pcmcia_chipset_tag_t)&imx_pcic_pcmcia_functions;
408 1.1.20.1 mjf paa.pch = (pcmcia_chipset_handle_t)so;
409 1.1.20.1 mjf printf("%s: sc_pa %lx\n", __FUNCTION__, sc->sc_pa);
410 1.1.20.1 mjf paa.iobase = sc->sc_pa;
411 1.1.20.1 mjf paa.iosize = 0x2000;
412 1.1.20.1 mjf
413 1.1.20.1 mjf so->pcmcia = config_found_ia(&sc->sc_dev, "pcmciabus", &paa,
414 1.1.20.1 mjf imx_pcic_print);
415 1.1.20.1 mjf
416 1.1.20.1 mjf #ifdef NOTYET
417 1.1.20.1 mjf imx_gpio_set_direction(sc->sc_irqpin[s[i]], GPIO_IN);
418 1.1.20.1 mjf imx_gpio_set_direction(sc->sc_irqcfpin[s[i]], GPIO_IN);
419 1.1.20.1 mjf
420 1.1.20.1 mjf /* Card slot interrupt */
421 1.1.20.1 mjf so->irq = imx_gpio_intr_establish(sc->sc_irqcfpin[s[i]],
422 1.1.20.1 mjf IST_EDGE_BOTH, IPL_BIO /* XXX */, "pcic",
423 1.1.20.1 mjf imx_pcic_intr, so);
424 1.1.20.1 mjf
425 1.1.20.1 mjf /* GPIO pin for interrupt */
426 1.1.20.1 mjf so->irqpin = sc->sc_irqpin[s[i]];
427 1.1.20.1 mjf #else
428 1.1.20.1 mjf so->irqpin = sc->sc_irqpin[s[i]];
429 1.1.20.1 mjf printf("%s: slot %d, irqpin %d\n", __FUNCTION__, s[i], sc->sc_irqpin[s[i]]);
430 1.1.20.1 mjf #endif /* NOTYET */
431 1.1.20.1 mjf
432 1.1.20.1 mjf if (kthread_create(PRI_NONE, 0, NULL,
433 1.1.20.1 mjf imx_pcic_event_thread, so, &so->event_thread,
434 1.1.20.1 mjf "%s,%d", sc->sc_dev.dv_xname, so->socket) != 0) {
435 1.1.20.1 mjf printf("%s: unable to create event thread for %d\n",
436 1.1.20.1 mjf sc->sc_dev.dv_xname, so->socket);
437 1.1.20.1 mjf }
438 1.1.20.1 mjf }
439 1.1.20.1 mjf }
440 1.1.20.1 mjf
441 1.1.20.1 mjf /*
442 1.1.20.1 mjf * Card slot interrupt handling
443 1.1.20.1 mjf */
444 1.1.20.1 mjf int
445 1.1.20.1 mjf imx_pcic_intr(void *arg)
446 1.1.20.1 mjf {
447 1.1.20.1 mjf struct imx_pcic_socket *so = (struct imx_pcic_socket *)arg;
448 1.1.20.1 mjf
449 1.1.20.1 mjf (*so->pcictag->clear_intr)(so);
450 1.1.20.1 mjf wakeup(so);
451 1.1.20.1 mjf
452 1.1.20.1 mjf return 1;
453 1.1.20.1 mjf }
454 1.1.20.1 mjf
455 1.1.20.1 mjf static void
456 1.1.20.1 mjf imx_pcic_event_thread(void *arg)
457 1.1.20.1 mjf {
458 1.1.20.1 mjf #ifdef NOTYET
459 1.1.20.1 mjf struct imx_pcic_socket *sock = (struct imx_pcic_socket *)arg;
460 1.1.20.1 mjf u_int cs;
461 1.1.20.1 mjf int present;
462 1.1.20.1 mjf
463 1.1.20.1 mjf while (sock->sc->sc_shutdown == 0) {
464 1.1.20.1 mjf (void) tsleep(sock, PWAIT, "imx_pcicev", 0);
465 1.1.20.1 mjf
466 1.1.20.1 mjf /* sleep .25s to avoid chattering interrupts */
467 1.1.20.1 mjf (void) tsleep((void *)sock, PWAIT, "imx_pcicss", hz/4);
468 1.1.20.1 mjf
469 1.1.20.1 mjf cs = (*sock->pcictag->read)(sock, IMX_PCIC_CARD_STATUS);
470 1.1.20.1 mjf present = sock->flags & IMX_PCIC_FLAG_CARDP;
471 1.1.20.1 mjf if ((cs == IMX_PCIC_CARD_VALID) == (present == 1)) {
472 1.1.20.1 mjf continue; /* state unchanged */
473 1.1.20.1 mjf }
474 1.1.20.1 mjf
475 1.1.20.1 mjf /* XXX Do both? */
476 1.1.20.1 mjf imx_pcic_event_process(sock);
477 1.1.20.1 mjf }
478 1.1.20.1 mjf sock->event_thread = NULL;
479 1.1.20.1 mjf
480 1.1.20.1 mjf /* In case parent is waiting for us to exit. */
481 1.1.20.1 mjf wakeup(sock->sc);
482 1.1.20.1 mjf kthread_exit(0);
483 1.1.20.1 mjf #endif /* NOTYET */
484 1.1.20.1 mjf }
485 1.1.20.1 mjf
486 1.1.20.1 mjf #ifdef NOTYET
487 1.1.20.1 mjf static void
488 1.1.20.1 mjf imx_pcic_event_process(struct imx_pcic_socket *sock)
489 1.1.20.1 mjf {
490 1.1.20.1 mjf u_int cs;
491 1.1.20.1 mjf
492 1.1.20.1 mjf cs = (*sock->pcictag->read)(sock, IMX_PCIC_CARD_STATUS);
493 1.1.20.1 mjf if (cs == IMX_PCIC_CARD_VALID) {
494 1.1.20.1 mjf if (!(sock->flags & IMX_PCIC_FLAG_CARDP)) {
495 1.1.20.1 mjf imx_pcic_attach_card(sock);
496 1.1.20.1 mjf }
497 1.1.20.1 mjf } else {
498 1.1.20.1 mjf if ((sock->flags & IMX_PCIC_FLAG_CARDP)) {
499 1.1.20.1 mjf imx_pcic_detach_card(sock, DETACH_FORCE);
500 1.1.20.1 mjf }
501 1.1.20.1 mjf }
502 1.1.20.1 mjf }
503 1.1.20.1 mjf
504 1.1.20.1 mjf static void
505 1.1.20.1 mjf imx_pcic_attach_card(struct imx_pcic_socket *h)
506 1.1.20.1 mjf {
507 1.1.20.1 mjf
508 1.1.20.1 mjf if (h->flags & IMX_PCIC_FLAG_CARDP)
509 1.1.20.1 mjf panic("pcic_attach_card: already attached");
510 1.1.20.1 mjf h->flags |= IMX_PCIC_FLAG_CARDP;
511 1.1.20.1 mjf
512 1.1.20.1 mjf
513 1.1.20.1 mjf /* call the MI attach function */
514 1.1.20.1 mjf pcmcia_card_attach(h->pcmcia);
515 1.1.20.1 mjf }
516 1.1.20.1 mjf #endif /* NOTYET */
517 1.1.20.1 mjf
518 1.1.20.1 mjf #ifdef NOTYET
519 1.1.20.1 mjf static void
520 1.1.20.1 mjf imx_pcic_detach_card(struct imx_pcic_socket *h, int flags)
521 1.1.20.1 mjf {
522 1.1.20.1 mjf struct imx_pcic_softc *sc = h->sc;
523 1.1.20.1 mjf int i;
524 1.1.20.1 mjf
525 1.1.20.1 mjf if (h->flags & IMX_PCIC_FLAG_CARDP) {
526 1.1.20.1 mjf h->flags &= ~IMX_PCIC_FLAG_CARDP;
527 1.1.20.1 mjf
528 1.1.20.1 mjf /* call the MI detach function */
529 1.1.20.1 mjf pcmcia_card_detach(h->pcmcia, flags);
530 1.1.20.1 mjf }
531 1.1.20.1 mjf
532 1.1.20.1 mjf /* Clear CIT if no other card is present. */
533 1.1.20.1 mjf for (i = 0; i < sc->sc_nslots; i++) {
534 1.1.20.1 mjf if (sc->sc_socket[i].flags & IMX_PCIC_FLAG_CARDP) {
535 1.1.20.1 mjf return;
536 1.1.20.1 mjf }
537 1.1.20.1 mjf }
538 1.1.20.1 mjf }
539 1.1.20.1 mjf #endif /* NOTYET */
540