net: OpenFirmware GPIO based MDIO bitbang driver
[zen-stable.git] / drivers / pcmcia / soc_common.c
blob420a77540f412758979e72b300d7aeac1801b145
1 /*======================================================================
3 Common support code for the PCMCIA control functionality of
4 integrated SOCs like the SA-11x0 and PXA2xx microprocessors.
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/
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.
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.
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.
31 ======================================================================*/
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/timer.h>
39 #include <linux/mm.h>
40 #include <linux/mutex.h>
41 #include <linux/interrupt.h>
42 #include <linux/irq.h>
43 #include <linux/spinlock.h>
44 #include <linux/cpufreq.h>
46 #include <asm/hardware.h>
47 #include <asm/io.h>
48 #include <asm/system.h>
50 #include "soc_common.h"
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
57 #ifdef DEBUG
59 static int pc_debug;
60 module_param(pc_debug, int, 0644);
62 void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
63 int lvl, const char *fmt, ...)
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 vprintk(fmt, args);
70 va_end(args);
74 #endif
76 #define to_soc_pcmcia_socket(x) container_of(x, struct soc_pcmcia_socket, socket)
78 static unsigned short
79 calc_speed(unsigned short *spds, int num, unsigned short dflt)
81 unsigned short speed = 0;
82 int i;
84 for (i = 0; i < num; i++)
85 if (speed < spds[i])
86 speed = spds[i];
87 if (speed == 0)
88 speed = dflt;
90 return speed;
93 void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt, struct soc_pcmcia_timing *timing)
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);
99 EXPORT_SYMBOL(soc_common_pcmcia_get_timing);
101 static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt)
103 struct pcmcia_state state;
104 unsigned int stat;
106 memset(&state, 0, sizeof(struct pcmcia_state));
108 skt->ops->socket_state(skt, &state);
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;
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:
120 stat |= skt->cs_state.Vcc ? SS_POWERON : 0;
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;
130 return stat;
134 * soc_common_pcmcia_config_skt
135 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
137 * Convert PCMCIA socket state to our socket configure structure.
139 static int
140 soc_common_pcmcia_config_skt(struct soc_pcmcia_socket *skt, socket_state_t *state)
142 int ret;
144 ret = skt->ops->configure_socket(skt, state);
145 if (ret == 0) {
147 * This really needs a better solution. The IRQ
148 * may or may not be claimed by the driver.
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);
158 skt->cs_state = *state;
161 if (ret < 0)
162 printk(KERN_ERR "soc_common_pcmcia: unable to configure "
163 "socket %d\n", skt->nr);
165 return ret;
168 /* soc_common_pcmcia_sock_init()
169 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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.
175 * Returns: 0
177 static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock)
179 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
181 debug(skt, 2, "initializing socket\n");
183 skt->ops->socket_init(skt);
184 return 0;
189 * soc_common_pcmcia_suspend()
190 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
192 * Remove power on the socket, disable IRQs from the card.
193 * Turn off status interrupts, and disable the PCMCIA bus.
195 * Returns: 0
197 static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock)
199 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
201 debug(skt, 2, "suspending socket\n");
203 skt->ops->socket_suspend(skt);
205 return 0;
208 static DEFINE_SPINLOCK(status_lock);
210 static void soc_common_check_status(struct soc_pcmcia_socket *skt)
212 unsigned int events;
214 debug(skt, 4, "entering PCMCIA monitoring thread\n");
216 do {
217 unsigned int status;
218 unsigned long flags;
220 status = soc_common_pcmcia_skt_state(skt);
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);
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 " : "");
235 if (events)
236 pcmcia_parse_events(&skt->socket, events);
237 } while (events);
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)
243 struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy;
244 debug(skt, 4, "polling for events\n");
246 mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD);
248 soc_common_check_status(skt);
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.
260 static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev)
262 struct soc_pcmcia_socket *skt = dev;
264 debug(skt, 3, "servicing IRQ %d\n", irq);
266 soc_common_check_status(skt);
268 return IRQ_HANDLED;
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.
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).
285 * Returns: 0
287 static int
288 soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status)
290 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
292 skt->status = soc_common_pcmcia_skt_state(skt);
293 *status = skt->status;
295 return 0;
300 * Implements the set_socket() operation for the in-kernel PCMCIA
301 * service (formerly SS_SetSocket in Card Services). We more or
302 * less punt all of this work and let the kernel handle the details
303 * of power configuration, reset, &c. We also record the value of
304 * `state' in order to regurgitate it to the PCMCIA core later.
306 static int
307 soc_common_pcmcia_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
309 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
311 debug(skt, 2, "mask: %s%s%s%s%s%sflags: %s%s%s%s%s%sVcc %d Vpp %d irq %d\n",
312 (state->csc_mask==0)?"<NONE> ":"",
313 (state->csc_mask&SS_DETECT)?"DETECT ":"",
314 (state->csc_mask&SS_READY)?"READY ":"",
315 (state->csc_mask&SS_BATDEAD)?"BATDEAD ":"",
316 (state->csc_mask&SS_BATWARN)?"BATWARN ":"",
317 (state->csc_mask&SS_STSCHG)?"STSCHG ":"",
318 (state->flags==0)?"<NONE> ":"",
319 (state->flags&SS_PWR_AUTO)?"PWR_AUTO ":"",
320 (state->flags&SS_IOCARD)?"IOCARD ":"",
321 (state->flags&SS_RESET)?"RESET ":"",
322 (state->flags&SS_SPKR_ENA)?"SPKR_ENA ":"",
323 (state->flags&SS_OUTPUT_ENA)?"OUTPUT_ENA ":"",
324 state->Vcc, state->Vpp, state->io_irq);
326 return soc_common_pcmcia_config_skt(skt, state);
331 * Implements the set_io_map() operation for the in-kernel PCMCIA
332 * service (formerly SS_SetIOMap in Card Services). We configure
333 * the map speed as requested, but override the address ranges
334 * supplied by Card Services.
336 * Returns: 0 on success, -1 on error
338 static int
339 soc_common_pcmcia_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *map)
341 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
342 unsigned short speed = map->speed;
344 debug(skt, 2, "map %u speed %u start 0x%08x stop 0x%08x\n",
345 map->map, map->speed, map->start, map->stop);
346 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
347 (map->flags==0)?"<NONE>":"",
348 (map->flags&MAP_ACTIVE)?"ACTIVE ":"",
349 (map->flags&MAP_16BIT)?"16BIT ":"",
350 (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"",
351 (map->flags&MAP_0WS)?"0WS ":"",
352 (map->flags&MAP_WRPROT)?"WRPROT ":"",
353 (map->flags&MAP_USE_WAIT)?"USE_WAIT ":"",
354 (map->flags&MAP_PREFETCH)?"PREFETCH ":"");
356 if (map->map >= MAX_IO_WIN) {
357 printk(KERN_ERR "%s(): map (%d) out of range\n", __func__,
358 map->map);
359 return -1;
362 if (map->flags & MAP_ACTIVE) {
363 if (speed == 0)
364 speed = SOC_PCMCIA_IO_ACCESS;
365 } else {
366 speed = 0;
369 skt->spd_io[map->map] = speed;
370 skt->ops->set_timing(skt);
372 if (map->stop == 1)
373 map->stop = PAGE_SIZE-1;
375 map->stop -= map->start;
376 map->stop += skt->socket.io_offset;
377 map->start = skt->socket.io_offset;
379 return 0;
384 * Implements the set_mem_map() operation for the in-kernel PCMCIA
385 * service (formerly SS_SetMemMap in Card Services). We configure
386 * the map speed as requested, but override the address ranges
387 * supplied by Card Services.
389 * Returns: 0 on success, -ERRNO on error
391 static int
392 soc_common_pcmcia_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *map)
394 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
395 struct resource *res;
396 unsigned short speed = map->speed;
398 debug(skt, 2, "map %u speed %u card_start %08x\n",
399 map->map, map->speed, map->card_start);
400 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
401 (map->flags==0)?"<NONE>":"",
402 (map->flags&MAP_ACTIVE)?"ACTIVE ":"",
403 (map->flags&MAP_16BIT)?"16BIT ":"",
404 (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"",
405 (map->flags&MAP_0WS)?"0WS ":"",
406 (map->flags&MAP_WRPROT)?"WRPROT ":"",
407 (map->flags&MAP_ATTRIB)?"ATTRIB ":"",
408 (map->flags&MAP_USE_WAIT)?"USE_WAIT ":"");
410 if (map->map >= MAX_WIN)
411 return -EINVAL;
413 if (map->flags & MAP_ACTIVE) {
414 if (speed == 0)
415 speed = 300;
416 } else {
417 speed = 0;
420 if (map->flags & MAP_ATTRIB) {
421 res = &skt->res_attr;
422 skt->spd_attr[map->map] = speed;
423 skt->spd_mem[map->map] = 0;
424 } else {
425 res = &skt->res_mem;
426 skt->spd_attr[map->map] = 0;
427 skt->spd_mem[map->map] = speed;
430 skt->ops->set_timing(skt);
432 map->static_start = res->start + map->card_start;
434 return 0;
437 struct bittbl {
438 unsigned int mask;
439 const char *name;
442 static struct bittbl status_bits[] = {
443 { SS_WRPROT, "SS_WRPROT" },
444 { SS_BATDEAD, "SS_BATDEAD" },
445 { SS_BATWARN, "SS_BATWARN" },
446 { SS_READY, "SS_READY" },
447 { SS_DETECT, "SS_DETECT" },
448 { SS_POWERON, "SS_POWERON" },
449 { SS_STSCHG, "SS_STSCHG" },
450 { SS_3VCARD, "SS_3VCARD" },
451 { SS_XVCARD, "SS_XVCARD" },
454 static struct bittbl conf_bits[] = {
455 { SS_PWR_AUTO, "SS_PWR_AUTO" },
456 { SS_IOCARD, "SS_IOCARD" },
457 { SS_RESET, "SS_RESET" },
458 { SS_DMA_MODE, "SS_DMA_MODE" },
459 { SS_SPKR_ENA, "SS_SPKR_ENA" },
460 { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" },
463 static void
464 dump_bits(char **p, const char *prefix, unsigned int val, struct bittbl *bits, int sz)
466 char *b = *p;
467 int i;
469 b += sprintf(b, "%-9s:", prefix);
470 for (i = 0; i < sz; i++)
471 if (val & bits[i].mask)
472 b += sprintf(b, " %s", bits[i].name);
473 *b++ = '\n';
474 *p = b;
478 * Implements the /sys/class/pcmcia_socket/??/status file.
480 * Returns: the number of characters added to the buffer
482 static ssize_t show_status(struct device *dev, struct device_attribute *attr, char *buf)
484 struct soc_pcmcia_socket *skt =
485 container_of(dev, struct soc_pcmcia_socket, socket.dev);
486 char *p = buf;
488 p+=sprintf(p, "slot : %d\n", skt->nr);
490 dump_bits(&p, "status", skt->status,
491 status_bits, ARRAY_SIZE(status_bits));
492 dump_bits(&p, "csc_mask", skt->cs_state.csc_mask,
493 status_bits, ARRAY_SIZE(status_bits));
494 dump_bits(&p, "cs_flags", skt->cs_state.flags,
495 conf_bits, ARRAY_SIZE(conf_bits));
497 p+=sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc);
498 p+=sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp);
499 p+=sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq, skt->irq);
500 if (skt->ops->show_timing)
501 p+=skt->ops->show_timing(skt, p);
503 return p-buf;
505 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
508 static struct pccard_operations soc_common_pcmcia_operations = {
509 .init = soc_common_pcmcia_sock_init,
510 .suspend = soc_common_pcmcia_suspend,
511 .get_status = soc_common_pcmcia_get_status,
512 .set_socket = soc_common_pcmcia_set_socket,
513 .set_io_map = soc_common_pcmcia_set_io_map,
514 .set_mem_map = soc_common_pcmcia_set_mem_map,
518 int soc_pcmcia_request_irqs(struct soc_pcmcia_socket *skt,
519 struct pcmcia_irqs *irqs, int nr)
521 int i, res = 0;
523 for (i = 0; i < nr; i++) {
524 if (irqs[i].sock != skt->nr)
525 continue;
526 res = request_irq(irqs[i].irq, soc_common_pcmcia_interrupt,
527 IRQF_DISABLED, irqs[i].str, skt);
528 if (res)
529 break;
530 set_irq_type(irqs[i].irq, IRQT_NOEDGE);
533 if (res) {
534 printk(KERN_ERR "PCMCIA: request for IRQ%d failed (%d)\n",
535 irqs[i].irq, res);
537 while (i--)
538 if (irqs[i].sock == skt->nr)
539 free_irq(irqs[i].irq, skt);
541 return res;
543 EXPORT_SYMBOL(soc_pcmcia_request_irqs);
545 void soc_pcmcia_free_irqs(struct soc_pcmcia_socket *skt,
546 struct pcmcia_irqs *irqs, int nr)
548 int i;
550 for (i = 0; i < nr; i++)
551 if (irqs[i].sock == skt->nr)
552 free_irq(irqs[i].irq, skt);
554 EXPORT_SYMBOL(soc_pcmcia_free_irqs);
556 void soc_pcmcia_disable_irqs(struct soc_pcmcia_socket *skt,
557 struct pcmcia_irqs *irqs, int nr)
559 int i;
561 for (i = 0; i < nr; i++)
562 if (irqs[i].sock == skt->nr)
563 set_irq_type(irqs[i].irq, IRQT_NOEDGE);
565 EXPORT_SYMBOL(soc_pcmcia_disable_irqs);
567 void soc_pcmcia_enable_irqs(struct soc_pcmcia_socket *skt,
568 struct pcmcia_irqs *irqs, int nr)
570 int i;
572 for (i = 0; i < nr; i++)
573 if (irqs[i].sock == skt->nr) {
574 set_irq_type(irqs[i].irq, IRQT_RISING);
575 set_irq_type(irqs[i].irq, IRQT_BOTHEDGE);
578 EXPORT_SYMBOL(soc_pcmcia_enable_irqs);
581 LIST_HEAD(soc_pcmcia_sockets);
582 static DEFINE_MUTEX(soc_pcmcia_sockets_lock);
584 static const char *skt_names[] = {
585 "PCMCIA socket 0",
586 "PCMCIA socket 1",
589 struct skt_dev_info {
590 int nskt;
591 struct soc_pcmcia_socket skt[0];
594 #define SKT_DEV_INFO_SIZE(n) \
595 (sizeof(struct skt_dev_info) + (n)*sizeof(struct soc_pcmcia_socket))
597 #ifdef CONFIG_CPU_FREQ
598 static int
599 soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data)
601 struct soc_pcmcia_socket *skt;
602 struct cpufreq_freqs *freqs = data;
603 int ret = 0;
605 mutex_lock(&soc_pcmcia_sockets_lock);
606 list_for_each_entry(skt, &soc_pcmcia_sockets, node)
607 if ( skt->ops->frequency_change )
608 ret += skt->ops->frequency_change(skt, val, freqs);
609 mutex_unlock(&soc_pcmcia_sockets_lock);
611 return ret;
614 static struct notifier_block soc_pcmcia_notifier_block = {
615 .notifier_call = soc_pcmcia_notifier
618 static int soc_pcmcia_cpufreq_register(void)
620 int ret;
622 ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block,
623 CPUFREQ_TRANSITION_NOTIFIER);
624 if (ret < 0)
625 printk(KERN_ERR "Unable to register CPU frequency change "
626 "notifier for PCMCIA (%d)\n", ret);
627 return ret;
630 static void soc_pcmcia_cpufreq_unregister(void)
632 cpufreq_unregister_notifier(&soc_pcmcia_notifier_block, CPUFREQ_TRANSITION_NOTIFIER);
635 #else
636 static int soc_pcmcia_cpufreq_register(void) { return 0; }
637 static void soc_pcmcia_cpufreq_unregister(void) {}
638 #endif
640 int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops, int first, int nr)
642 struct skt_dev_info *sinfo;
643 struct soc_pcmcia_socket *skt;
644 int ret, i;
646 mutex_lock(&soc_pcmcia_sockets_lock);
648 sinfo = kzalloc(SKT_DEV_INFO_SIZE(nr), GFP_KERNEL);
649 if (!sinfo) {
650 ret = -ENOMEM;
651 goto out;
654 sinfo->nskt = nr;
657 * Initialise the per-socket structure.
659 for (i = 0; i < nr; i++) {
660 skt = &sinfo->skt[i];
662 skt->socket.ops = &soc_common_pcmcia_operations;
663 skt->socket.owner = ops->owner;
664 skt->socket.dev.parent = dev;
666 init_timer(&skt->poll_timer);
667 skt->poll_timer.function = soc_common_pcmcia_poll_event;
668 skt->poll_timer.data = (unsigned long)skt;
669 skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD;
671 skt->nr = first + i;
672 skt->irq = NO_IRQ;
673 skt->dev = dev;
674 skt->ops = ops;
676 skt->res_skt.start = _PCMCIA(skt->nr);
677 skt->res_skt.end = _PCMCIA(skt->nr) + PCMCIASp - 1;
678 skt->res_skt.name = skt_names[skt->nr];
679 skt->res_skt.flags = IORESOURCE_MEM;
681 ret = request_resource(&iomem_resource, &skt->res_skt);
682 if (ret)
683 goto out_err_1;
685 skt->res_io.start = _PCMCIAIO(skt->nr);
686 skt->res_io.end = _PCMCIAIO(skt->nr) + PCMCIAIOSp - 1;
687 skt->res_io.name = "io";
688 skt->res_io.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
690 ret = request_resource(&skt->res_skt, &skt->res_io);
691 if (ret)
692 goto out_err_2;
694 skt->res_mem.start = _PCMCIAMem(skt->nr);
695 skt->res_mem.end = _PCMCIAMem(skt->nr) + PCMCIAMemSp - 1;
696 skt->res_mem.name = "memory";
697 skt->res_mem.flags = IORESOURCE_MEM;
699 ret = request_resource(&skt->res_skt, &skt->res_mem);
700 if (ret)
701 goto out_err_3;
703 skt->res_attr.start = _PCMCIAAttr(skt->nr);
704 skt->res_attr.end = _PCMCIAAttr(skt->nr) + PCMCIAAttrSp - 1;
705 skt->res_attr.name = "attribute";
706 skt->res_attr.flags = IORESOURCE_MEM;
708 ret = request_resource(&skt->res_skt, &skt->res_attr);
709 if (ret)
710 goto out_err_4;
712 skt->virt_io = ioremap(skt->res_io.start, 0x10000);
713 if (skt->virt_io == NULL) {
714 ret = -ENOMEM;
715 goto out_err_5;
718 if (list_empty(&soc_pcmcia_sockets))
719 soc_pcmcia_cpufreq_register();
721 list_add(&skt->node, &soc_pcmcia_sockets);
724 * We initialize default socket timing here, because
725 * we are not guaranteed to see a SetIOMap operation at
726 * runtime.
728 ops->set_timing(skt);
730 ret = ops->hw_init(skt);
731 if (ret)
732 goto out_err_6;
734 skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD;
735 skt->socket.resource_ops = &pccard_static_ops;
736 skt->socket.irq_mask = 0;
737 skt->socket.map_size = PAGE_SIZE;
738 skt->socket.pci_irq = skt->irq;
739 skt->socket.io_offset = (unsigned long)skt->virt_io;
741 skt->status = soc_common_pcmcia_skt_state(skt);
743 ret = pcmcia_register_socket(&skt->socket);
744 if (ret)
745 goto out_err_7;
747 WARN_ON(skt->socket.sock != i);
749 add_timer(&skt->poll_timer);
751 device_create_file(&skt->socket.dev, &dev_attr_status);
754 dev_set_drvdata(dev, sinfo);
755 ret = 0;
756 goto out;
758 do {
759 skt = &sinfo->skt[i];
761 del_timer_sync(&skt->poll_timer);
762 pcmcia_unregister_socket(&skt->socket);
764 out_err_7:
765 flush_scheduled_work();
767 ops->hw_shutdown(skt);
768 out_err_6:
769 list_del(&skt->node);
770 iounmap(skt->virt_io);
771 out_err_5:
772 release_resource(&skt->res_attr);
773 out_err_4:
774 release_resource(&skt->res_mem);
775 out_err_3:
776 release_resource(&skt->res_io);
777 out_err_2:
778 release_resource(&skt->res_skt);
779 out_err_1:
780 i--;
781 } while (i > 0);
783 kfree(sinfo);
785 out:
786 mutex_unlock(&soc_pcmcia_sockets_lock);
787 return ret;
790 int soc_common_drv_pcmcia_remove(struct device *dev)
792 struct skt_dev_info *sinfo = dev_get_drvdata(dev);
793 int i;
795 dev_set_drvdata(dev, NULL);
797 mutex_lock(&soc_pcmcia_sockets_lock);
798 for (i = 0; i < sinfo->nskt; i++) {
799 struct soc_pcmcia_socket *skt = &sinfo->skt[i];
801 del_timer_sync(&skt->poll_timer);
803 pcmcia_unregister_socket(&skt->socket);
805 flush_scheduled_work();
807 skt->ops->hw_shutdown(skt);
809 soc_common_pcmcia_config_skt(skt, &dead_socket);
811 list_del(&skt->node);
812 iounmap(skt->virt_io);
813 skt->virt_io = NULL;
814 release_resource(&skt->res_attr);
815 release_resource(&skt->res_mem);
816 release_resource(&skt->res_io);
817 release_resource(&skt->res_skt);
819 if (list_empty(&soc_pcmcia_sockets))
820 soc_pcmcia_cpufreq_unregister();
822 mutex_unlock(&soc_pcmcia_sockets_lock);
824 kfree(sinfo);
826 return 0;
828 EXPORT_SYMBOL(soc_common_drv_pcmcia_remove);