diff options
Diffstat (limited to 'drivers/pcmcia/soc_common.c')
-rw-r--r-- | drivers/pcmcia/soc_common.c | 850 |
1 files changed, 850 insertions, 0 deletions
diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c new file mode 100644 index 000000000000..888b70e6a484 --- /dev/null +++ b/drivers/pcmcia/soc_common.c | |||
@@ -0,0 +1,850 @@ | |||
1 | /*====================================================================== | ||
2 | |||
3 | Common support code for the PCMCIA control functionality of | ||
4 | integrated SOCs like the SA-11x0 and PXA2xx microprocessors. | ||
5 | |||
6 | The contents of this file are subject to the Mozilla Public | ||
7 | License Version 1.1 (the "License"); you may not use this file | ||
8 | except in compliance with the License. You may obtain a copy of | ||
9 | the License at http://www.mozilla.org/MPL/ | ||
10 | |||
11 | Software distributed under the License is distributed on an "AS | ||
12 | IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
13 | implied. See the License for the specific language governing | ||
14 | rights and limitations under the License. | ||
15 | |||
16 | The initial developer of the original code is John G. Dorsey | ||
17 | <john+@cs.cmu.edu>. Portions created by John G. Dorsey are | ||
18 | Copyright (C) 1999 John G. Dorsey. All Rights Reserved. | ||
19 | |||
20 | Alternatively, the contents of this file may be used under the | ||
21 | terms of the GNU Public License version 2 (the "GPL"), in which | ||
22 | case the provisions of the GPL are applicable instead of the | ||
23 | above. If you wish to allow the use of your version of this file | ||
24 | only under the terms of the GPL and not to allow others to use | ||
25 | your version of this file under the MPL, indicate your decision | ||
26 | by deleting the provisions above and replace them with the notice | ||
27 | and other provisions required by the GPL. If you do not delete | ||
28 | the provisions above, a recipient may use your version of this | ||
29 | file under either the MPL or the GPL. | ||
30 | |||
31 | ======================================================================*/ | ||
32 | |||
33 | |||
34 | #include <linux/config.h> | ||
35 | #include <linux/module.h> | ||
36 | #include <linux/moduleparam.h> | ||
37 | #include <linux/init.h> | ||
38 | #include <linux/kernel.h> | ||
39 | #include <linux/timer.h> | ||
40 | #include <linux/mm.h> | ||
41 | #include <linux/interrupt.h> | ||
42 | #include <linux/spinlock.h> | ||
43 | #include <linux/cpufreq.h> | ||
44 | |||
45 | #include <asm/hardware.h> | ||
46 | #include <asm/io.h> | ||
47 | #include <asm/irq.h> | ||
48 | #include <asm/system.h> | ||
49 | |||
50 | #include "soc_common.h" | ||
51 | |||
52 | /* FIXME: platform dependent resource declaration has to move out of this file */ | ||
53 | #ifdef CONFIG_ARCH_PXA | ||
54 | #include <asm/arch/pxa-regs.h> | ||
55 | #endif | ||
56 | |||
57 | #ifdef DEBUG | ||
58 | |||
59 | static int pc_debug; | ||
60 | module_param(pc_debug, int, 0644); | ||
61 | |||
62 | void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func, | ||
63 | int lvl, const char *fmt, ...) | ||
64 | { | ||
65 | va_list args; | ||
66 | if (pc_debug > lvl) { | ||
67 | printk(KERN_DEBUG "skt%u: %s: ", skt->nr, func); | ||
68 | va_start(args, fmt); | ||
69 | printk(fmt, args); | ||
70 | va_end(args); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | #endif | ||
75 | |||
76 | #define to_soc_pcmcia_socket(x) container_of(x, struct soc_pcmcia_socket, socket) | ||
77 | |||
78 | static unsigned short | ||
79 | calc_speed(unsigned short *spds, int num, unsigned short dflt) | ||
80 | { | ||
81 | unsigned short speed = 0; | ||
82 | int i; | ||
83 | |||
84 | for (i = 0; i < num; i++) | ||
85 | if (speed < spds[i]) | ||
86 | speed = spds[i]; | ||
87 | if (speed == 0) | ||
88 | speed = dflt; | ||
89 | |||
90 | return speed; | ||
91 | } | ||
92 | |||
93 | void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt, struct soc_pcmcia_timing *timing) | ||
94 | { | ||
95 | timing->io = calc_speed(skt->spd_io, MAX_IO_WIN, SOC_PCMCIA_IO_ACCESS); | ||
96 | timing->mem = calc_speed(skt->spd_mem, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS); | ||
97 | timing->attr = calc_speed(skt->spd_attr, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS); | ||
98 | } | ||
99 | EXPORT_SYMBOL(soc_common_pcmcia_get_timing); | ||
100 | |||
101 | static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt) | ||
102 | { | ||
103 | struct pcmcia_state state; | ||
104 | unsigned int stat; | ||
105 | |||
106 | memset(&state, 0, sizeof(struct pcmcia_state)); | ||
107 | |||
108 | skt->ops->socket_state(skt, &state); | ||
109 | |||
110 | stat = state.detect ? SS_DETECT : 0; | ||
111 | stat |= state.ready ? SS_READY : 0; | ||
112 | stat |= state.wrprot ? SS_WRPROT : 0; | ||
113 | stat |= state.vs_3v ? SS_3VCARD : 0; | ||
114 | stat |= state.vs_Xv ? SS_XVCARD : 0; | ||
115 | |||
116 | /* The power status of individual sockets is not available | ||
117 | * explicitly from the hardware, so we just remember the state | ||
118 | * and regurgitate it upon request: | ||
119 | */ | ||
120 | stat |= skt->cs_state.Vcc ? SS_POWERON : 0; | ||
121 | |||
122 | if (skt->cs_state.flags & SS_IOCARD) | ||
123 | stat |= state.bvd1 ? SS_STSCHG : 0; | ||
124 | else { | ||
125 | if (state.bvd1 == 0) | ||
126 | stat |= SS_BATDEAD; | ||
127 | else if (state.bvd2 == 0) | ||
128 | stat |= SS_BATWARN; | ||
129 | } | ||
130 | return stat; | ||
131 | } | ||
132 | |||
133 | /* | ||
134 | * soc_common_pcmcia_config_skt | ||
135 | * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
136 | * | ||
137 | * Convert PCMCIA socket state to our socket configure structure. | ||
138 | */ | ||
139 | static int | ||
140 | soc_common_pcmcia_config_skt(struct soc_pcmcia_socket *skt, socket_state_t *state) | ||
141 | { | ||
142 | int ret; | ||
143 | |||
144 | ret = skt->ops->configure_socket(skt, state); | ||
145 | if (ret == 0) { | ||
146 | /* | ||
147 | * This really needs a better solution. The IRQ | ||
148 | * may or may not be claimed by the driver. | ||
149 | */ | ||
150 | if (skt->irq_state != 1 && state->io_irq) { | ||
151 | skt->irq_state = 1; | ||
152 | set_irq_type(skt->irq, IRQT_FALLING); | ||
153 | } else if (skt->irq_state == 1 && state->io_irq == 0) { | ||
154 | skt->irq_state = 0; | ||
155 | set_irq_type(skt->irq, IRQT_NOEDGE); | ||
156 | } | ||
157 | |||
158 | skt->cs_state = *state; | ||
159 | } | ||
160 | |||
161 | if (ret < 0) | ||
162 | printk(KERN_ERR "soc_common_pcmcia: unable to configure " | ||
163 | "socket %d\n", skt->nr); | ||
164 | |||
165 | return ret; | ||
166 | } | ||
167 | |||
168 | /* soc_common_pcmcia_sock_init() | ||
169 | * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
170 | * | ||
171 | * (Re-)Initialise the socket, turning on status interrupts | ||
172 | * and PCMCIA bus. This must wait for power to stabilise | ||
173 | * so that the card status signals report correctly. | ||
174 | * | ||
175 | * Returns: 0 | ||
176 | */ | ||
177 | static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock) | ||
178 | { | ||
179 | struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); | ||
180 | |||
181 | debug(skt, 2, "initializing socket\n"); | ||
182 | |||
183 | skt->ops->socket_init(skt); | ||
184 | return 0; | ||
185 | } | ||
186 | |||
187 | |||
188 | /* | ||
189 | * soc_common_pcmcia_suspend() | ||
190 | * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
191 | * | ||
192 | * Remove power on the socket, disable IRQs from the card. | ||
193 | * Turn off status interrupts, and disable the PCMCIA bus. | ||
194 | * | ||
195 | * Returns: 0 | ||
196 | */ | ||
197 | static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock) | ||
198 | { | ||
199 | struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); | ||
200 | |||
201 | debug(skt, 2, "suspending socket\n"); | ||
202 | |||
203 | skt->ops->socket_suspend(skt); | ||
204 | |||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | static DEFINE_SPINLOCK(status_lock); | ||
209 | |||
210 | static void soc_common_check_status(struct soc_pcmcia_socket *skt) | ||
211 | { | ||
212 | unsigned int events; | ||
213 | |||
214 | debug(skt, 4, "entering PCMCIA monitoring thread\n"); | ||
215 | |||
216 | do { | ||
217 | unsigned int status; | ||
218 | unsigned long flags; | ||
219 | |||
220 | status = soc_common_pcmcia_skt_state(skt); | ||
221 | |||
222 | spin_lock_irqsave(&status_lock, flags); | ||
223 | events = (status ^ skt->status) & skt->cs_state.csc_mask; | ||
224 | skt->status = status; | ||
225 | spin_unlock_irqrestore(&status_lock, flags); | ||
226 | |||
227 | debug(skt, 4, "events: %s%s%s%s%s%s\n", | ||
228 | events == 0 ? "<NONE>" : "", | ||
229 | events & SS_DETECT ? "DETECT " : "", | ||
230 | events & SS_READY ? "READY " : "", | ||
231 | events & SS_BATDEAD ? "BATDEAD " : "", | ||
232 | events & SS_BATWARN ? "BATWARN " : "", | ||
233 | events & SS_STSCHG ? "STSCHG " : ""); | ||
234 | |||
235 | if (events) | ||
236 | pcmcia_parse_events(&skt->socket, events); | ||
237 | } while (events); | ||
238 | } | ||
239 | |||
240 | /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */ | ||
241 | static void soc_common_pcmcia_poll_event(unsigned long dummy) | ||
242 | { | ||
243 | struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy; | ||
244 | debug(skt, 4, "polling for events\n"); | ||
245 | |||
246 | mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD); | ||
247 | |||
248 | soc_common_check_status(skt); | ||
249 | } | ||
250 | |||
251 | |||
252 | /* | ||
253 | * Service routine for socket driver interrupts (requested by the | ||
254 | * low-level PCMCIA init() operation via soc_common_pcmcia_thread()). | ||
255 | * The actual interrupt-servicing work is performed by | ||
256 | * soc_common_pcmcia_thread(), largely because the Card Services event- | ||
257 | * handling code performs scheduling operations which cannot be | ||
258 | * executed from within an interrupt context. | ||
259 | */ | ||
260 | static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev, struct pt_regs *regs) | ||
261 | { | ||
262 | struct soc_pcmcia_socket *skt = dev; | ||
263 | |||
264 | debug(skt, 3, "servicing IRQ %d\n", irq); | ||
265 | |||
266 | soc_common_check_status(skt); | ||
267 | |||
268 | return IRQ_HANDLED; | ||
269 | } | ||
270 | |||
271 | |||
272 | /* | ||
273 | * Implements the get_status() operation for the in-kernel PCMCIA | ||
274 | * service (formerly SS_GetStatus in Card Services). Essentially just | ||
275 | * fills in bits in `status' according to internal driver state or | ||
276 | * the value of the voltage detect chipselect register. | ||
277 | * | ||
278 | * As a debugging note, during card startup, the PCMCIA core issues | ||
279 | * three set_socket() commands in a row the first with RESET deasserted, | ||
280 | * the second with RESET asserted, and the last with RESET deasserted | ||
281 | * again. Following the third set_socket(), a get_status() command will | ||
282 | * be issued. The kernel is looking for the SS_READY flag (see | ||
283 | * setup_socket(), reset_socket(), and unreset_socket() in cs.c). | ||
284 | * | ||
285 | * Returns: 0 | ||
286 | */ | ||
287 | static int | ||
288 | soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status) | ||
289 | { | ||
290 | struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); | ||
291 | |||
292 | skt->status = soc_common_pcmcia_skt_state(skt); | ||
293 | *status = skt->status; | ||
294 | |||
295 | return 0; | ||
296 | } | ||
297 | |||
298 | |||
299 | /* | ||
300 | * Implements the get_socket() operation for the in-kernel PCMCIA | ||
301 | * service (formerly SS_GetSocket in Card Services). Not a very | ||
302 | * exciting routine. | ||
303 | * | ||
304 | * Returns: 0 | ||
305 | */ | ||
306 | static int | ||
307 | soc_common_pcmcia_get_socket(struct pcmcia_socket *sock, socket_state_t *state) | ||
308 | { | ||
309 | struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); | ||
310 | |||
311 | debug(skt, 2, "\n"); | ||
312 | |||
313 | *state = skt->cs_state; | ||
314 | |||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | /* | ||
319 | * Implements the set_socket() operation for the in-kernel PCMCIA | ||
320 | * service (formerly SS_SetSocket in Card Services). We more or | ||
321 | * less punt all of this work and let the kernel handle the details | ||
322 | * of power configuration, reset, &c. We also record the value of | ||
323 | * `state' in order to regurgitate it to the PCMCIA core later. | ||
324 | * | ||
325 | * Returns: 0 | ||
326 | */ | ||
327 | static int | ||
328 | soc_common_pcmcia_set_socket(struct pcmcia_socket *sock, socket_state_t *state) | ||
329 | { | ||
330 | struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); | ||
331 | |||
332 | debug(skt, 2, "mask: %s%s%s%s%s%sflags: %s%s%s%s%s%sVcc %d Vpp %d irq %d\n", | ||
333 | (state->csc_mask==0)?"<NONE> ":"", | ||
334 | (state->csc_mask&SS_DETECT)?"DETECT ":"", | ||
335 | (state->csc_mask&SS_READY)?"READY ":"", | ||
336 | (state->csc_mask&SS_BATDEAD)?"BATDEAD ":"", | ||
337 | (state->csc_mask&SS_BATWARN)?"BATWARN ":"", | ||
338 | (state->csc_mask&SS_STSCHG)?"STSCHG ":"", | ||
339 | (state->flags==0)?"<NONE> ":"", | ||
340 | (state->flags&SS_PWR_AUTO)?"PWR_AUTO ":"", | ||
341 | (state->flags&SS_IOCARD)?"IOCARD ":"", | ||
342 | (state->flags&SS_RESET)?"RESET ":"", | ||
343 | (state->flags&SS_SPKR_ENA)?"SPKR_ENA ":"", | ||
344 | (state->flags&SS_OUTPUT_ENA)?"OUTPUT_ENA ":"", | ||
345 | state->Vcc, state->Vpp, state->io_irq); | ||
346 | |||
347 | return soc_common_pcmcia_config_skt(skt, state); | ||
348 | } | ||
349 | |||
350 | |||
351 | /* | ||
352 | * Implements the set_io_map() operation for the in-kernel PCMCIA | ||
353 | * service (formerly SS_SetIOMap in Card Services). We configure | ||
354 | * the map speed as requested, but override the address ranges | ||
355 | * supplied by Card Services. | ||
356 | * | ||
357 | * Returns: 0 on success, -1 on error | ||
358 | */ | ||
359 | static int | ||
360 | soc_common_pcmcia_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *map) | ||
361 | { | ||
362 | struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); | ||
363 | unsigned short speed = map->speed; | ||
364 | |||
365 | debug(skt, 2, "map %u speed %u start 0x%08x stop 0x%08x\n", | ||
366 | map->map, map->speed, map->start, map->stop); | ||
367 | debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n", | ||
368 | (map->flags==0)?"<NONE>":"", | ||
369 | (map->flags&MAP_ACTIVE)?"ACTIVE ":"", | ||
370 | (map->flags&MAP_16BIT)?"16BIT ":"", | ||
371 | (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"", | ||
372 | (map->flags&MAP_0WS)?"0WS ":"", | ||
373 | (map->flags&MAP_WRPROT)?"WRPROT ":"", | ||
374 | (map->flags&MAP_USE_WAIT)?"USE_WAIT ":"", | ||
375 | (map->flags&MAP_PREFETCH)?"PREFETCH ":""); | ||
376 | |||
377 | if (map->map >= MAX_IO_WIN) { | ||
378 | printk(KERN_ERR "%s(): map (%d) out of range\n", __FUNCTION__, | ||
379 | map->map); | ||
380 | return -1; | ||
381 | } | ||
382 | |||
383 | if (map->flags & MAP_ACTIVE) { | ||
384 | if (speed == 0) | ||
385 | speed = SOC_PCMCIA_IO_ACCESS; | ||
386 | } else { | ||
387 | speed = 0; | ||
388 | } | ||
389 | |||
390 | skt->spd_io[map->map] = speed; | ||
391 | skt->ops->set_timing(skt); | ||
392 | |||
393 | if (map->stop == 1) | ||
394 | map->stop = PAGE_SIZE-1; | ||
395 | |||
396 | map->stop -= map->start; | ||
397 | map->stop += skt->socket.io_offset; | ||
398 | map->start = skt->socket.io_offset; | ||
399 | |||
400 | return 0; | ||
401 | } | ||
402 | |||
403 | |||
404 | /* | ||
405 | * Implements the set_mem_map() operation for the in-kernel PCMCIA | ||
406 | * service (formerly SS_SetMemMap in Card Services). We configure | ||
407 | * the map speed as requested, but override the address ranges | ||
408 | * supplied by Card Services. | ||
409 | * | ||
410 | * Returns: 0 on success, -1 on error | ||
411 | */ | ||
412 | static int | ||
413 | soc_common_pcmcia_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *map) | ||
414 | { | ||
415 | struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); | ||
416 | struct resource *res; | ||
417 | unsigned short speed = map->speed; | ||
418 | |||
419 | debug(skt, 2, "map %u speed %u card_start %08x\n", | ||
420 | map->map, map->speed, map->card_start); | ||
421 | debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n", | ||
422 | (map->flags==0)?"<NONE>":"", | ||
423 | (map->flags&MAP_ACTIVE)?"ACTIVE ":"", | ||
424 | (map->flags&MAP_16BIT)?"16BIT ":"", | ||
425 | (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"", | ||
426 | (map->flags&MAP_0WS)?"0WS ":"", | ||
427 | (map->flags&MAP_WRPROT)?"WRPROT ":"", | ||
428 | (map->flags&MAP_ATTRIB)?"ATTRIB ":"", | ||
429 | (map->flags&MAP_USE_WAIT)?"USE_WAIT ":""); | ||
430 | |||
431 | if (map->map >= MAX_WIN) | ||
432 | return -EINVAL; | ||
433 | |||
434 | if (map->flags & MAP_ACTIVE) { | ||
435 | if (speed == 0) | ||
436 | speed = 300; | ||
437 | } else { | ||
438 | speed = 0; | ||
439 | } | ||
440 | |||
441 | if (map->flags & MAP_ATTRIB) { | ||
442 | res = &skt->res_attr; | ||
443 | skt->spd_attr[map->map] = speed; | ||
444 | skt->spd_mem[map->map] = 0; | ||
445 | } else { | ||
446 | res = &skt->res_mem; | ||
447 | skt->spd_attr[map->map] = 0; | ||
448 | skt->spd_mem[map->map] = speed; | ||
449 | } | ||
450 | |||
451 | skt->ops->set_timing(skt); | ||
452 | |||
453 | map->static_start = res->start + map->card_start; | ||
454 | |||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | struct bittbl { | ||
459 | unsigned int mask; | ||
460 | const char *name; | ||
461 | }; | ||
462 | |||
463 | static struct bittbl status_bits[] = { | ||
464 | { SS_WRPROT, "SS_WRPROT" }, | ||
465 | { SS_BATDEAD, "SS_BATDEAD" }, | ||
466 | { SS_BATWARN, "SS_BATWARN" }, | ||
467 | { SS_READY, "SS_READY" }, | ||
468 | { SS_DETECT, "SS_DETECT" }, | ||
469 | { SS_POWERON, "SS_POWERON" }, | ||
470 | { SS_STSCHG, "SS_STSCHG" }, | ||
471 | { SS_3VCARD, "SS_3VCARD" }, | ||
472 | { SS_XVCARD, "SS_XVCARD" }, | ||
473 | }; | ||
474 | |||
475 | static struct bittbl conf_bits[] = { | ||
476 | { SS_PWR_AUTO, "SS_PWR_AUTO" }, | ||
477 | { SS_IOCARD, "SS_IOCARD" }, | ||
478 | { SS_RESET, "SS_RESET" }, | ||
479 | { SS_DMA_MODE, "SS_DMA_MODE" }, | ||
480 | { SS_SPKR_ENA, "SS_SPKR_ENA" }, | ||
481 | { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" }, | ||
482 | }; | ||
483 | |||
484 | static void | ||
485 | dump_bits(char **p, const char *prefix, unsigned int val, struct bittbl *bits, int sz) | ||
486 | { | ||
487 | char *b = *p; | ||
488 | int i; | ||
489 | |||
490 | b += sprintf(b, "%-9s:", prefix); | ||
491 | for (i = 0; i < sz; i++) | ||
492 | if (val & bits[i].mask) | ||
493 | b += sprintf(b, " %s", bits[i].name); | ||
494 | *b++ = '\n'; | ||
495 | *p = b; | ||
496 | } | ||
497 | |||
498 | /* | ||
499 | * Implements the /sys/class/pcmcia_socket/??/status file. | ||
500 | * | ||
501 | * Returns: the number of characters added to the buffer | ||
502 | */ | ||
503 | static ssize_t show_status(struct class_device *class_dev, char *buf) | ||
504 | { | ||
505 | struct soc_pcmcia_socket *skt = | ||
506 | container_of(class_dev, struct soc_pcmcia_socket, socket.dev); | ||
507 | char *p = buf; | ||
508 | |||
509 | p+=sprintf(p, "slot : %d\n", skt->nr); | ||
510 | |||
511 | dump_bits(&p, "status", skt->status, | ||
512 | status_bits, ARRAY_SIZE(status_bits)); | ||
513 | dump_bits(&p, "csc_mask", skt->cs_state.csc_mask, | ||
514 | status_bits, ARRAY_SIZE(status_bits)); | ||
515 | dump_bits(&p, "cs_flags", skt->cs_state.flags, | ||
516 | conf_bits, ARRAY_SIZE(conf_bits)); | ||
517 | |||
518 | p+=sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc); | ||
519 | p+=sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp); | ||
520 | p+=sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq, skt->irq); | ||
521 | if (skt->ops->show_timing) | ||
522 | p+=skt->ops->show_timing(skt, p); | ||
523 | |||
524 | return p-buf; | ||
525 | } | ||
526 | static CLASS_DEVICE_ATTR(status, S_IRUGO, show_status, NULL); | ||
527 | |||
528 | |||
529 | static struct pccard_operations soc_common_pcmcia_operations = { | ||
530 | .init = soc_common_pcmcia_sock_init, | ||
531 | .suspend = soc_common_pcmcia_suspend, | ||
532 | .get_status = soc_common_pcmcia_get_status, | ||
533 | .get_socket = soc_common_pcmcia_get_socket, | ||
534 | .set_socket = soc_common_pcmcia_set_socket, | ||
535 | .set_io_map = soc_common_pcmcia_set_io_map, | ||
536 | .set_mem_map = soc_common_pcmcia_set_mem_map, | ||
537 | }; | ||
538 | |||
539 | |||
540 | int soc_pcmcia_request_irqs(struct soc_pcmcia_socket *skt, | ||
541 | struct pcmcia_irqs *irqs, int nr) | ||
542 | { | ||
543 | int i, res = 0; | ||
544 | |||
545 | for (i = 0; i < nr; i++) { | ||
546 | if (irqs[i].sock != skt->nr) | ||
547 | continue; | ||
548 | res = request_irq(irqs[i].irq, soc_common_pcmcia_interrupt, | ||
549 | SA_INTERRUPT, irqs[i].str, skt); | ||
550 | if (res) | ||
551 | break; | ||
552 | set_irq_type(irqs[i].irq, IRQT_NOEDGE); | ||
553 | } | ||
554 | |||
555 | if (res) { | ||
556 | printk(KERN_ERR "PCMCIA: request for IRQ%d failed (%d)\n", | ||
557 | irqs[i].irq, res); | ||
558 | |||
559 | while (i--) | ||
560 | if (irqs[i].sock == skt->nr) | ||
561 | free_irq(irqs[i].irq, skt); | ||
562 | } | ||
563 | return res; | ||
564 | } | ||
565 | EXPORT_SYMBOL(soc_pcmcia_request_irqs); | ||
566 | |||
567 | void soc_pcmcia_free_irqs(struct soc_pcmcia_socket *skt, | ||
568 | struct pcmcia_irqs *irqs, int nr) | ||
569 | { | ||
570 | int i; | ||
571 | |||
572 | for (i = 0; i < nr; i++) | ||
573 | if (irqs[i].sock == skt->nr) | ||
574 | free_irq(irqs[i].irq, skt); | ||
575 | } | ||
576 | EXPORT_SYMBOL(soc_pcmcia_free_irqs); | ||
577 | |||
578 | void soc_pcmcia_disable_irqs(struct soc_pcmcia_socket *skt, | ||
579 | struct pcmcia_irqs *irqs, int nr) | ||
580 | { | ||
581 | int i; | ||
582 | |||
583 | for (i = 0; i < nr; i++) | ||
584 | if (irqs[i].sock == skt->nr) | ||
585 | set_irq_type(irqs[i].irq, IRQT_NOEDGE); | ||
586 | } | ||
587 | EXPORT_SYMBOL(soc_pcmcia_disable_irqs); | ||
588 | |||
589 | void soc_pcmcia_enable_irqs(struct soc_pcmcia_socket *skt, | ||
590 | struct pcmcia_irqs *irqs, int nr) | ||
591 | { | ||
592 | int i; | ||
593 | |||
594 | for (i = 0; i < nr; i++) | ||
595 | if (irqs[i].sock == skt->nr) { | ||
596 | set_irq_type(irqs[i].irq, IRQT_RISING); | ||
597 | set_irq_type(irqs[i].irq, IRQT_BOTHEDGE); | ||
598 | } | ||
599 | } | ||
600 | EXPORT_SYMBOL(soc_pcmcia_enable_irqs); | ||
601 | |||
602 | |||
603 | LIST_HEAD(soc_pcmcia_sockets); | ||
604 | DECLARE_MUTEX(soc_pcmcia_sockets_lock); | ||
605 | |||
606 | static const char *skt_names[] = { | ||
607 | "PCMCIA socket 0", | ||
608 | "PCMCIA socket 1", | ||
609 | }; | ||
610 | |||
611 | struct skt_dev_info { | ||
612 | int nskt; | ||
613 | struct soc_pcmcia_socket skt[0]; | ||
614 | }; | ||
615 | |||
616 | #define SKT_DEV_INFO_SIZE(n) \ | ||
617 | (sizeof(struct skt_dev_info) + (n)*sizeof(struct soc_pcmcia_socket)) | ||
618 | |||
619 | #ifdef CONFIG_CPU_FREQ | ||
620 | static int | ||
621 | soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data) | ||
622 | { | ||
623 | struct soc_pcmcia_socket *skt; | ||
624 | struct cpufreq_freqs *freqs = data; | ||
625 | int ret = 0; | ||
626 | |||
627 | down(&soc_pcmcia_sockets_lock); | ||
628 | list_for_each_entry(skt, &soc_pcmcia_sockets, node) | ||
629 | if ( skt->ops->frequency_change ) | ||
630 | ret += skt->ops->frequency_change(skt, val, freqs); | ||
631 | up(&soc_pcmcia_sockets_lock); | ||
632 | |||
633 | return ret; | ||
634 | } | ||
635 | |||
636 | static struct notifier_block soc_pcmcia_notifier_block = { | ||
637 | .notifier_call = soc_pcmcia_notifier | ||
638 | }; | ||
639 | |||
640 | static int soc_pcmcia_cpufreq_register(void) | ||
641 | { | ||
642 | int ret; | ||
643 | |||
644 | ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block, | ||
645 | CPUFREQ_TRANSITION_NOTIFIER); | ||
646 | if (ret < 0) | ||
647 | printk(KERN_ERR "Unable to register CPU frequency change " | ||
648 | "notifier for PCMCIA (%d)\n", ret); | ||
649 | return ret; | ||
650 | } | ||
651 | |||
652 | static void soc_pcmcia_cpufreq_unregister(void) | ||
653 | { | ||
654 | cpufreq_unregister_notifier(&soc_pcmcia_notifier_block, CPUFREQ_TRANSITION_NOTIFIER); | ||
655 | } | ||
656 | |||
657 | #else | ||
658 | #define soc_pcmcia_cpufreq_register() | ||
659 | #define soc_pcmcia_cpufreq_unregister() | ||
660 | #endif | ||
661 | |||
662 | int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops, int first, int nr) | ||
663 | { | ||
664 | struct skt_dev_info *sinfo; | ||
665 | struct soc_pcmcia_socket *skt; | ||
666 | int ret, i; | ||
667 | |||
668 | down(&soc_pcmcia_sockets_lock); | ||
669 | |||
670 | sinfo = kmalloc(SKT_DEV_INFO_SIZE(nr), GFP_KERNEL); | ||
671 | if (!sinfo) { | ||
672 | ret = -ENOMEM; | ||
673 | goto out; | ||
674 | } | ||
675 | |||
676 | memset(sinfo, 0, SKT_DEV_INFO_SIZE(nr)); | ||
677 | sinfo->nskt = nr; | ||
678 | |||
679 | /* | ||
680 | * Initialise the per-socket structure. | ||
681 | */ | ||
682 | for (i = 0; i < nr; i++) { | ||
683 | skt = &sinfo->skt[i]; | ||
684 | |||
685 | skt->socket.ops = &soc_common_pcmcia_operations; | ||
686 | skt->socket.owner = ops->owner; | ||
687 | skt->socket.dev.dev = dev; | ||
688 | |||
689 | init_timer(&skt->poll_timer); | ||
690 | skt->poll_timer.function = soc_common_pcmcia_poll_event; | ||
691 | skt->poll_timer.data = (unsigned long)skt; | ||
692 | skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD; | ||
693 | |||
694 | skt->nr = first + i; | ||
695 | skt->irq = NO_IRQ; | ||
696 | skt->dev = dev; | ||
697 | skt->ops = ops; | ||
698 | |||
699 | skt->res_skt.start = _PCMCIA(skt->nr); | ||
700 | skt->res_skt.end = _PCMCIA(skt->nr) + PCMCIASp - 1; | ||
701 | skt->res_skt.name = skt_names[skt->nr]; | ||
702 | skt->res_skt.flags = IORESOURCE_MEM; | ||
703 | |||
704 | ret = request_resource(&iomem_resource, &skt->res_skt); | ||
705 | if (ret) | ||
706 | goto out_err_1; | ||
707 | |||
708 | skt->res_io.start = _PCMCIAIO(skt->nr); | ||
709 | skt->res_io.end = _PCMCIAIO(skt->nr) + PCMCIAIOSp - 1; | ||
710 | skt->res_io.name = "io"; | ||
711 | skt->res_io.flags = IORESOURCE_MEM | IORESOURCE_BUSY; | ||
712 | |||
713 | ret = request_resource(&skt->res_skt, &skt->res_io); | ||
714 | if (ret) | ||
715 | goto out_err_2; | ||
716 | |||
717 | skt->res_mem.start = _PCMCIAMem(skt->nr); | ||
718 | skt->res_mem.end = _PCMCIAMem(skt->nr) + PCMCIAMemSp - 1; | ||
719 | skt->res_mem.name = "memory"; | ||
720 | skt->res_mem.flags = IORESOURCE_MEM; | ||
721 | |||
722 | ret = request_resource(&skt->res_skt, &skt->res_mem); | ||
723 | if (ret) | ||
724 | goto out_err_3; | ||
725 | |||
726 | skt->res_attr.start = _PCMCIAAttr(skt->nr); | ||
727 | skt->res_attr.end = _PCMCIAAttr(skt->nr) + PCMCIAAttrSp - 1; | ||
728 | skt->res_attr.name = "attribute"; | ||
729 | skt->res_attr.flags = IORESOURCE_MEM; | ||
730 | |||
731 | ret = request_resource(&skt->res_skt, &skt->res_attr); | ||
732 | if (ret) | ||
733 | goto out_err_4; | ||
734 | |||
735 | skt->virt_io = ioremap(skt->res_io.start, 0x10000); | ||
736 | if (skt->virt_io == NULL) { | ||
737 | ret = -ENOMEM; | ||
738 | goto out_err_5; | ||
739 | } | ||
740 | |||
741 | if ( list_empty(&soc_pcmcia_sockets) ) | ||
742 | soc_pcmcia_cpufreq_register(); | ||
743 | |||
744 | list_add(&skt->node, &soc_pcmcia_sockets); | ||
745 | |||
746 | /* | ||
747 | * We initialize default socket timing here, because | ||
748 | * we are not guaranteed to see a SetIOMap operation at | ||
749 | * runtime. | ||
750 | */ | ||
751 | ops->set_timing(skt); | ||
752 | |||
753 | ret = ops->hw_init(skt); | ||
754 | if (ret) | ||
755 | goto out_err_6; | ||
756 | |||
757 | skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD; | ||
758 | skt->socket.resource_ops = &pccard_static_ops; | ||
759 | skt->socket.irq_mask = 0; | ||
760 | skt->socket.map_size = PAGE_SIZE; | ||
761 | skt->socket.pci_irq = skt->irq; | ||
762 | skt->socket.io_offset = (unsigned long)skt->virt_io; | ||
763 | |||
764 | skt->status = soc_common_pcmcia_skt_state(skt); | ||
765 | |||
766 | ret = pcmcia_register_socket(&skt->socket); | ||
767 | if (ret) | ||
768 | goto out_err_7; | ||
769 | |||
770 | WARN_ON(skt->socket.sock != i); | ||
771 | |||
772 | add_timer(&skt->poll_timer); | ||
773 | |||
774 | class_device_create_file(&skt->socket.dev, &class_device_attr_status); | ||
775 | } | ||
776 | |||
777 | dev_set_drvdata(dev, sinfo); | ||
778 | ret = 0; | ||
779 | goto out; | ||
780 | |||
781 | do { | ||
782 | skt = &sinfo->skt[i]; | ||
783 | |||
784 | del_timer_sync(&skt->poll_timer); | ||
785 | pcmcia_unregister_socket(&skt->socket); | ||
786 | |||
787 | out_err_7: | ||
788 | flush_scheduled_work(); | ||
789 | |||
790 | ops->hw_shutdown(skt); | ||
791 | out_err_6: | ||
792 | list_del(&skt->node); | ||
793 | iounmap(skt->virt_io); | ||
794 | out_err_5: | ||
795 | release_resource(&skt->res_attr); | ||
796 | out_err_4: | ||
797 | release_resource(&skt->res_mem); | ||
798 | out_err_3: | ||
799 | release_resource(&skt->res_io); | ||
800 | out_err_2: | ||
801 | release_resource(&skt->res_skt); | ||
802 | out_err_1: | ||
803 | i--; | ||
804 | } while (i > 0); | ||
805 | |||
806 | kfree(sinfo); | ||
807 | |||
808 | out: | ||
809 | up(&soc_pcmcia_sockets_lock); | ||
810 | return ret; | ||
811 | } | ||
812 | |||
813 | int soc_common_drv_pcmcia_remove(struct device *dev) | ||
814 | { | ||
815 | struct skt_dev_info *sinfo = dev_get_drvdata(dev); | ||
816 | int i; | ||
817 | |||
818 | dev_set_drvdata(dev, NULL); | ||
819 | |||
820 | down(&soc_pcmcia_sockets_lock); | ||
821 | for (i = 0; i < sinfo->nskt; i++) { | ||
822 | struct soc_pcmcia_socket *skt = &sinfo->skt[i]; | ||
823 | |||
824 | del_timer_sync(&skt->poll_timer); | ||
825 | |||
826 | pcmcia_unregister_socket(&skt->socket); | ||
827 | |||
828 | flush_scheduled_work(); | ||
829 | |||
830 | skt->ops->hw_shutdown(skt); | ||
831 | |||
832 | soc_common_pcmcia_config_skt(skt, &dead_socket); | ||
833 | |||
834 | list_del(&skt->node); | ||
835 | iounmap(skt->virt_io); | ||
836 | skt->virt_io = NULL; | ||
837 | release_resource(&skt->res_attr); | ||
838 | release_resource(&skt->res_mem); | ||
839 | release_resource(&skt->res_io); | ||
840 | release_resource(&skt->res_skt); | ||
841 | } | ||
842 | if ( list_empty(&soc_pcmcia_sockets) ) | ||
843 | soc_pcmcia_cpufreq_unregister(); | ||
844 | |||
845 | up(&soc_pcmcia_sockets_lock); | ||
846 | |||
847 | kfree(sinfo); | ||
848 | |||
849 | return 0; | ||
850 | } | ||