Merge branch 'mini2440-dev-unlikely' into mini2440-dev
[linux-2.6/mini2440.git] / drivers / pcmcia / soc_common.c
blobef7e9e58782b2328c66ab14d4b563656ee3a84a2
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 <mach/hardware.h>
47 #include <asm/io.h>
48 #include <asm/system.h>
50 #include "soc_common.h"
52 #ifdef CONFIG_PCMCIA_DEBUG
54 static int pc_debug;
55 module_param(pc_debug, int, 0644);
57 void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
58 int lvl, const char *fmt, ...)
60 va_list args;
61 if (pc_debug > lvl) {
62 printk(KERN_DEBUG "skt%u: %s: ", skt->nr, func);
63 va_start(args, fmt);
64 vprintk(fmt, args);
65 va_end(args);
69 #endif
71 #define to_soc_pcmcia_socket(x) container_of(x, struct soc_pcmcia_socket, socket)
73 static unsigned short
74 calc_speed(unsigned short *spds, int num, unsigned short dflt)
76 unsigned short speed = 0;
77 int i;
79 for (i = 0; i < num; i++)
80 if (speed < spds[i])
81 speed = spds[i];
82 if (speed == 0)
83 speed = dflt;
85 return speed;
88 void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt, struct soc_pcmcia_timing *timing)
90 timing->io = calc_speed(skt->spd_io, MAX_IO_WIN, SOC_PCMCIA_IO_ACCESS);
91 timing->mem = calc_speed(skt->spd_mem, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
92 timing->attr = calc_speed(skt->spd_attr, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
94 EXPORT_SYMBOL(soc_common_pcmcia_get_timing);
96 static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt)
98 struct pcmcia_state state;
99 unsigned int stat;
101 memset(&state, 0, sizeof(struct pcmcia_state));
103 skt->ops->socket_state(skt, &state);
105 stat = state.detect ? SS_DETECT : 0;
106 stat |= state.ready ? SS_READY : 0;
107 stat |= state.wrprot ? SS_WRPROT : 0;
108 stat |= state.vs_3v ? SS_3VCARD : 0;
109 stat |= state.vs_Xv ? SS_XVCARD : 0;
111 /* The power status of individual sockets is not available
112 * explicitly from the hardware, so we just remember the state
113 * and regurgitate it upon request:
115 stat |= skt->cs_state.Vcc ? SS_POWERON : 0;
117 if (skt->cs_state.flags & SS_IOCARD)
118 stat |= state.bvd1 ? SS_STSCHG : 0;
119 else {
120 if (state.bvd1 == 0)
121 stat |= SS_BATDEAD;
122 else if (state.bvd2 == 0)
123 stat |= SS_BATWARN;
125 return stat;
129 * soc_common_pcmcia_config_skt
130 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132 * Convert PCMCIA socket state to our socket configure structure.
134 static int
135 soc_common_pcmcia_config_skt(struct soc_pcmcia_socket *skt, socket_state_t *state)
137 int ret;
139 ret = skt->ops->configure_socket(skt, state);
140 if (ret == 0) {
142 * This really needs a better solution. The IRQ
143 * may or may not be claimed by the driver.
145 if (skt->irq_state != 1 && state->io_irq) {
146 skt->irq_state = 1;
147 set_irq_type(skt->irq, IRQ_TYPE_EDGE_FALLING);
148 } else if (skt->irq_state == 1 && state->io_irq == 0) {
149 skt->irq_state = 0;
150 set_irq_type(skt->irq, IRQ_TYPE_NONE);
153 skt->cs_state = *state;
156 if (ret < 0)
157 printk(KERN_ERR "soc_common_pcmcia: unable to configure "
158 "socket %d\n", skt->nr);
160 return ret;
163 /* soc_common_pcmcia_sock_init()
164 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
166 * (Re-)Initialise the socket, turning on status interrupts
167 * and PCMCIA bus. This must wait for power to stabilise
168 * so that the card status signals report correctly.
170 * Returns: 0
172 static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock)
174 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
176 debug(skt, 2, "initializing socket\n");
178 skt->ops->socket_init(skt);
179 return 0;
184 * soc_common_pcmcia_suspend()
185 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
187 * Remove power on the socket, disable IRQs from the card.
188 * Turn off status interrupts, and disable the PCMCIA bus.
190 * Returns: 0
192 static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock)
194 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
196 debug(skt, 2, "suspending socket\n");
198 skt->ops->socket_suspend(skt);
200 return 0;
203 static DEFINE_SPINLOCK(status_lock);
205 static void soc_common_check_status(struct soc_pcmcia_socket *skt)
207 unsigned int events;
209 debug(skt, 4, "entering PCMCIA monitoring thread\n");
211 do {
212 unsigned int status;
213 unsigned long flags;
215 status = soc_common_pcmcia_skt_state(skt);
217 spin_lock_irqsave(&status_lock, flags);
218 events = (status ^ skt->status) & skt->cs_state.csc_mask;
219 skt->status = status;
220 spin_unlock_irqrestore(&status_lock, flags);
222 debug(skt, 4, "events: %s%s%s%s%s%s\n",
223 events == 0 ? "<NONE>" : "",
224 events & SS_DETECT ? "DETECT " : "",
225 events & SS_READY ? "READY " : "",
226 events & SS_BATDEAD ? "BATDEAD " : "",
227 events & SS_BATWARN ? "BATWARN " : "",
228 events & SS_STSCHG ? "STSCHG " : "");
230 if (events)
231 pcmcia_parse_events(&skt->socket, events);
232 } while (events);
235 /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */
236 static void soc_common_pcmcia_poll_event(unsigned long dummy)
238 struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy;
239 debug(skt, 4, "polling for events\n");
241 mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD);
243 soc_common_check_status(skt);
248 * Service routine for socket driver interrupts (requested by the
249 * low-level PCMCIA init() operation via soc_common_pcmcia_thread()).
250 * The actual interrupt-servicing work is performed by
251 * soc_common_pcmcia_thread(), largely because the Card Services event-
252 * handling code performs scheduling operations which cannot be
253 * executed from within an interrupt context.
255 static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev)
257 struct soc_pcmcia_socket *skt = dev;
259 debug(skt, 3, "servicing IRQ %d\n", irq);
261 soc_common_check_status(skt);
263 return IRQ_HANDLED;
268 * Implements the get_status() operation for the in-kernel PCMCIA
269 * service (formerly SS_GetStatus in Card Services). Essentially just
270 * fills in bits in `status' according to internal driver state or
271 * the value of the voltage detect chipselect register.
273 * As a debugging note, during card startup, the PCMCIA core issues
274 * three set_socket() commands in a row the first with RESET deasserted,
275 * the second with RESET asserted, and the last with RESET deasserted
276 * again. Following the third set_socket(), a get_status() command will
277 * be issued. The kernel is looking for the SS_READY flag (see
278 * setup_socket(), reset_socket(), and unreset_socket() in cs.c).
280 * Returns: 0
282 static int
283 soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status)
285 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
287 skt->status = soc_common_pcmcia_skt_state(skt);
288 *status = skt->status;
290 return 0;
295 * Implements the set_socket() operation for the in-kernel PCMCIA
296 * service (formerly SS_SetSocket in Card Services). We more or
297 * less punt all of this work and let the kernel handle the details
298 * of power configuration, reset, &c. We also record the value of
299 * `state' in order to regurgitate it to the PCMCIA core later.
301 static int
302 soc_common_pcmcia_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
304 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
306 debug(skt, 2, "mask: %s%s%s%s%s%sflags: %s%s%s%s%s%sVcc %d Vpp %d irq %d\n",
307 (state->csc_mask==0)?"<NONE> ":"",
308 (state->csc_mask&SS_DETECT)?"DETECT ":"",
309 (state->csc_mask&SS_READY)?"READY ":"",
310 (state->csc_mask&SS_BATDEAD)?"BATDEAD ":"",
311 (state->csc_mask&SS_BATWARN)?"BATWARN ":"",
312 (state->csc_mask&SS_STSCHG)?"STSCHG ":"",
313 (state->flags==0)?"<NONE> ":"",
314 (state->flags&SS_PWR_AUTO)?"PWR_AUTO ":"",
315 (state->flags&SS_IOCARD)?"IOCARD ":"",
316 (state->flags&SS_RESET)?"RESET ":"",
317 (state->flags&SS_SPKR_ENA)?"SPKR_ENA ":"",
318 (state->flags&SS_OUTPUT_ENA)?"OUTPUT_ENA ":"",
319 state->Vcc, state->Vpp, state->io_irq);
321 return soc_common_pcmcia_config_skt(skt, state);
326 * Implements the set_io_map() operation for the in-kernel PCMCIA
327 * service (formerly SS_SetIOMap in Card Services). We configure
328 * the map speed as requested, but override the address ranges
329 * supplied by Card Services.
331 * Returns: 0 on success, -1 on error
333 static int
334 soc_common_pcmcia_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *map)
336 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
337 unsigned short speed = map->speed;
339 debug(skt, 2, "map %u speed %u start 0x%08llx stop 0x%08llx\n",
340 map->map, map->speed, (unsigned long long)map->start,
341 (unsigned long long)map->stop);
342 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
343 (map->flags==0)?"<NONE>":"",
344 (map->flags&MAP_ACTIVE)?"ACTIVE ":"",
345 (map->flags&MAP_16BIT)?"16BIT ":"",
346 (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"",
347 (map->flags&MAP_0WS)?"0WS ":"",
348 (map->flags&MAP_WRPROT)?"WRPROT ":"",
349 (map->flags&MAP_USE_WAIT)?"USE_WAIT ":"",
350 (map->flags&MAP_PREFETCH)?"PREFETCH ":"");
352 if (map->map >= MAX_IO_WIN) {
353 printk(KERN_ERR "%s(): map (%d) out of range\n", __func__,
354 map->map);
355 return -1;
358 if (map->flags & MAP_ACTIVE) {
359 if (speed == 0)
360 speed = SOC_PCMCIA_IO_ACCESS;
361 } else {
362 speed = 0;
365 skt->spd_io[map->map] = speed;
366 skt->ops->set_timing(skt);
368 if (map->stop == 1)
369 map->stop = PAGE_SIZE-1;
371 map->stop -= map->start;
372 map->stop += skt->socket.io_offset;
373 map->start = skt->socket.io_offset;
375 return 0;
380 * Implements the set_mem_map() operation for the in-kernel PCMCIA
381 * service (formerly SS_SetMemMap in Card Services). We configure
382 * the map speed as requested, but override the address ranges
383 * supplied by Card Services.
385 * Returns: 0 on success, -ERRNO on error
387 static int
388 soc_common_pcmcia_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *map)
390 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
391 struct resource *res;
392 unsigned short speed = map->speed;
394 debug(skt, 2, "map %u speed %u card_start %08x\n",
395 map->map, map->speed, map->card_start);
396 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
397 (map->flags==0)?"<NONE>":"",
398 (map->flags&MAP_ACTIVE)?"ACTIVE ":"",
399 (map->flags&MAP_16BIT)?"16BIT ":"",
400 (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"",
401 (map->flags&MAP_0WS)?"0WS ":"",
402 (map->flags&MAP_WRPROT)?"WRPROT ":"",
403 (map->flags&MAP_ATTRIB)?"ATTRIB ":"",
404 (map->flags&MAP_USE_WAIT)?"USE_WAIT ":"");
406 if (map->map >= MAX_WIN)
407 return -EINVAL;
409 if (map->flags & MAP_ACTIVE) {
410 if (speed == 0)
411 speed = 300;
412 } else {
413 speed = 0;
416 if (map->flags & MAP_ATTRIB) {
417 res = &skt->res_attr;
418 skt->spd_attr[map->map] = speed;
419 skt->spd_mem[map->map] = 0;
420 } else {
421 res = &skt->res_mem;
422 skt->spd_attr[map->map] = 0;
423 skt->spd_mem[map->map] = speed;
426 skt->ops->set_timing(skt);
428 map->static_start = res->start + map->card_start;
430 return 0;
433 struct bittbl {
434 unsigned int mask;
435 const char *name;
438 static struct bittbl status_bits[] = {
439 { SS_WRPROT, "SS_WRPROT" },
440 { SS_BATDEAD, "SS_BATDEAD" },
441 { SS_BATWARN, "SS_BATWARN" },
442 { SS_READY, "SS_READY" },
443 { SS_DETECT, "SS_DETECT" },
444 { SS_POWERON, "SS_POWERON" },
445 { SS_STSCHG, "SS_STSCHG" },
446 { SS_3VCARD, "SS_3VCARD" },
447 { SS_XVCARD, "SS_XVCARD" },
450 static struct bittbl conf_bits[] = {
451 { SS_PWR_AUTO, "SS_PWR_AUTO" },
452 { SS_IOCARD, "SS_IOCARD" },
453 { SS_RESET, "SS_RESET" },
454 { SS_DMA_MODE, "SS_DMA_MODE" },
455 { SS_SPKR_ENA, "SS_SPKR_ENA" },
456 { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" },
459 static void
460 dump_bits(char **p, const char *prefix, unsigned int val, struct bittbl *bits, int sz)
462 char *b = *p;
463 int i;
465 b += sprintf(b, "%-9s:", prefix);
466 for (i = 0; i < sz; i++)
467 if (val & bits[i].mask)
468 b += sprintf(b, " %s", bits[i].name);
469 *b++ = '\n';
470 *p = b;
474 * Implements the /sys/class/pcmcia_socket/??/status file.
476 * Returns: the number of characters added to the buffer
478 static ssize_t show_status(struct device *dev, struct device_attribute *attr, char *buf)
480 struct soc_pcmcia_socket *skt =
481 container_of(dev, struct soc_pcmcia_socket, socket.dev);
482 char *p = buf;
484 p+=sprintf(p, "slot : %d\n", skt->nr);
486 dump_bits(&p, "status", skt->status,
487 status_bits, ARRAY_SIZE(status_bits));
488 dump_bits(&p, "csc_mask", skt->cs_state.csc_mask,
489 status_bits, ARRAY_SIZE(status_bits));
490 dump_bits(&p, "cs_flags", skt->cs_state.flags,
491 conf_bits, ARRAY_SIZE(conf_bits));
493 p+=sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc);
494 p+=sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp);
495 p+=sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq, skt->irq);
496 if (skt->ops->show_timing)
497 p+=skt->ops->show_timing(skt, p);
499 return p-buf;
501 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
504 static struct pccard_operations soc_common_pcmcia_operations = {
505 .init = soc_common_pcmcia_sock_init,
506 .suspend = soc_common_pcmcia_suspend,
507 .get_status = soc_common_pcmcia_get_status,
508 .set_socket = soc_common_pcmcia_set_socket,
509 .set_io_map = soc_common_pcmcia_set_io_map,
510 .set_mem_map = soc_common_pcmcia_set_mem_map,
514 int soc_pcmcia_request_irqs(struct soc_pcmcia_socket *skt,
515 struct pcmcia_irqs *irqs, int nr)
517 int i, res = 0;
519 for (i = 0; i < nr; i++) {
520 if (irqs[i].sock != skt->nr)
521 continue;
522 res = request_irq(irqs[i].irq, soc_common_pcmcia_interrupt,
523 IRQF_DISABLED, irqs[i].str, skt);
524 if (res)
525 break;
526 set_irq_type(irqs[i].irq, IRQ_TYPE_NONE);
529 if (res) {
530 printk(KERN_ERR "PCMCIA: request for IRQ%d failed (%d)\n",
531 irqs[i].irq, res);
533 while (i--)
534 if (irqs[i].sock == skt->nr)
535 free_irq(irqs[i].irq, skt);
537 return res;
539 EXPORT_SYMBOL(soc_pcmcia_request_irqs);
541 void soc_pcmcia_free_irqs(struct soc_pcmcia_socket *skt,
542 struct pcmcia_irqs *irqs, int nr)
544 int i;
546 for (i = 0; i < nr; i++)
547 if (irqs[i].sock == skt->nr)
548 free_irq(irqs[i].irq, skt);
550 EXPORT_SYMBOL(soc_pcmcia_free_irqs);
552 void soc_pcmcia_disable_irqs(struct soc_pcmcia_socket *skt,
553 struct pcmcia_irqs *irqs, int nr)
555 int i;
557 for (i = 0; i < nr; i++)
558 if (irqs[i].sock == skt->nr)
559 set_irq_type(irqs[i].irq, IRQ_TYPE_NONE);
561 EXPORT_SYMBOL(soc_pcmcia_disable_irqs);
563 void soc_pcmcia_enable_irqs(struct soc_pcmcia_socket *skt,
564 struct pcmcia_irqs *irqs, int nr)
566 int i;
568 for (i = 0; i < nr; i++)
569 if (irqs[i].sock == skt->nr) {
570 set_irq_type(irqs[i].irq, IRQ_TYPE_EDGE_RISING);
571 set_irq_type(irqs[i].irq, IRQ_TYPE_EDGE_BOTH);
574 EXPORT_SYMBOL(soc_pcmcia_enable_irqs);
577 LIST_HEAD(soc_pcmcia_sockets);
578 static DEFINE_MUTEX(soc_pcmcia_sockets_lock);
580 #ifdef CONFIG_CPU_FREQ
581 static int
582 soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data)
584 struct soc_pcmcia_socket *skt;
585 struct cpufreq_freqs *freqs = data;
586 int ret = 0;
588 mutex_lock(&soc_pcmcia_sockets_lock);
589 list_for_each_entry(skt, &soc_pcmcia_sockets, node)
590 if ( skt->ops->frequency_change )
591 ret += skt->ops->frequency_change(skt, val, freqs);
592 mutex_unlock(&soc_pcmcia_sockets_lock);
594 return ret;
597 static struct notifier_block soc_pcmcia_notifier_block = {
598 .notifier_call = soc_pcmcia_notifier
601 static int soc_pcmcia_cpufreq_register(void)
603 int ret;
605 ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block,
606 CPUFREQ_TRANSITION_NOTIFIER);
607 if (ret < 0)
608 printk(KERN_ERR "Unable to register CPU frequency change "
609 "notifier for PCMCIA (%d)\n", ret);
610 return ret;
613 static void soc_pcmcia_cpufreq_unregister(void)
615 cpufreq_unregister_notifier(&soc_pcmcia_notifier_block, CPUFREQ_TRANSITION_NOTIFIER);
618 #else
619 static int soc_pcmcia_cpufreq_register(void) { return 0; }
620 static void soc_pcmcia_cpufreq_unregister(void) {}
621 #endif
623 int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops,
624 struct skt_dev_info *sinfo)
626 struct soc_pcmcia_socket *skt;
627 int ret, i;
629 mutex_lock(&soc_pcmcia_sockets_lock);
632 * Initialise the per-socket structure.
634 for (i = 0; i < sinfo->nskt; i++) {
635 skt = &sinfo->skt[i];
637 skt->socket.ops = &soc_common_pcmcia_operations;
638 skt->socket.owner = ops->owner;
639 skt->socket.dev.parent = dev;
641 init_timer(&skt->poll_timer);
642 skt->poll_timer.function = soc_common_pcmcia_poll_event;
643 skt->poll_timer.data = (unsigned long)skt;
644 skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD;
646 skt->dev = dev;
647 skt->ops = ops;
649 ret = request_resource(&iomem_resource, &skt->res_skt);
650 if (ret)
651 goto out_err_1;
653 ret = request_resource(&skt->res_skt, &skt->res_io);
654 if (ret)
655 goto out_err_2;
657 ret = request_resource(&skt->res_skt, &skt->res_mem);
658 if (ret)
659 goto out_err_3;
661 ret = request_resource(&skt->res_skt, &skt->res_attr);
662 if (ret)
663 goto out_err_4;
665 skt->virt_io = ioremap(skt->res_io.start, 0x10000);
666 if (skt->virt_io == NULL) {
667 ret = -ENOMEM;
668 goto out_err_5;
671 if (list_empty(&soc_pcmcia_sockets))
672 soc_pcmcia_cpufreq_register();
674 list_add(&skt->node, &soc_pcmcia_sockets);
677 * We initialize default socket timing here, because
678 * we are not guaranteed to see a SetIOMap operation at
679 * runtime.
681 ops->set_timing(skt);
683 ret = ops->hw_init(skt);
684 if (ret)
685 goto out_err_6;
687 skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD;
688 skt->socket.resource_ops = &pccard_static_ops;
689 skt->socket.irq_mask = 0;
690 skt->socket.map_size = PAGE_SIZE;
691 skt->socket.pci_irq = skt->irq;
692 skt->socket.io_offset = (unsigned long)skt->virt_io;
694 skt->status = soc_common_pcmcia_skt_state(skt);
696 ret = pcmcia_register_socket(&skt->socket);
697 if (ret)
698 goto out_err_7;
700 WARN_ON(skt->socket.sock != i);
702 add_timer(&skt->poll_timer);
704 ret = device_create_file(&skt->socket.dev, &dev_attr_status);
705 if (ret)
706 goto out_err_8;
709 dev_set_drvdata(dev, sinfo);
710 ret = 0;
711 goto out;
713 do {
714 skt = &sinfo->skt[i];
716 device_remove_file(&skt->socket.dev, &dev_attr_status);
717 out_err_8:
718 del_timer_sync(&skt->poll_timer);
719 pcmcia_unregister_socket(&skt->socket);
721 out_err_7:
722 flush_scheduled_work();
724 ops->hw_shutdown(skt);
725 out_err_6:
726 list_del(&skt->node);
727 iounmap(skt->virt_io);
728 out_err_5:
729 release_resource(&skt->res_attr);
730 out_err_4:
731 release_resource(&skt->res_mem);
732 out_err_3:
733 release_resource(&skt->res_io);
734 out_err_2:
735 release_resource(&skt->res_skt);
736 out_err_1:
737 i--;
738 } while (i > 0);
740 kfree(sinfo);
742 out:
743 mutex_unlock(&soc_pcmcia_sockets_lock);
744 return ret;
747 int soc_common_drv_pcmcia_remove(struct device *dev)
749 struct skt_dev_info *sinfo = dev_get_drvdata(dev);
750 int i;
752 dev_set_drvdata(dev, NULL);
754 mutex_lock(&soc_pcmcia_sockets_lock);
755 for (i = 0; i < sinfo->nskt; i++) {
756 struct soc_pcmcia_socket *skt = &sinfo->skt[i];
758 del_timer_sync(&skt->poll_timer);
760 pcmcia_unregister_socket(&skt->socket);
762 flush_scheduled_work();
764 skt->ops->hw_shutdown(skt);
766 soc_common_pcmcia_config_skt(skt, &dead_socket);
768 list_del(&skt->node);
769 iounmap(skt->virt_io);
770 skt->virt_io = NULL;
771 release_resource(&skt->res_attr);
772 release_resource(&skt->res_mem);
773 release_resource(&skt->res_io);
774 release_resource(&skt->res_skt);
776 if (list_empty(&soc_pcmcia_sockets))
777 soc_pcmcia_cpufreq_unregister();
779 mutex_unlock(&soc_pcmcia_sockets_lock);
781 kfree(sinfo);
783 return 0;
785 EXPORT_SYMBOL(soc_common_drv_pcmcia_remove);