IPv6: fix Routing Header Type 0 handling thinko
[linux-2.6/mini2440.git] / drivers / pcmcia / soc_common.c
blobaa7779d89752681a05e5d10d0aa76c19ff08a648
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/interrupt.h>
41 #include <linux/irq.h>
42 #include <linux/spinlock.h>
43 #include <linux/cpufreq.h>
45 #include <asm/hardware.h>
46 #include <asm/io.h>
47 #include <asm/system.h>
49 #include "soc_common.h"
51 /* FIXME: platform dependent resource declaration has to move out of this file */
52 #ifdef CONFIG_ARCH_PXA
53 #include <asm/arch/pxa-regs.h>
54 #endif
56 #ifdef DEBUG
58 static int pc_debug;
59 module_param(pc_debug, int, 0644);
61 void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
62 int lvl, const char *fmt, ...)
64 va_list args;
65 if (pc_debug > lvl) {
66 printk(KERN_DEBUG "skt%u: %s: ", skt->nr, func);
67 va_start(args, fmt);
68 vprintk(fmt, args);
69 va_end(args);
73 #endif
75 #define to_soc_pcmcia_socket(x) container_of(x, struct soc_pcmcia_socket, socket)
77 static unsigned short
78 calc_speed(unsigned short *spds, int num, unsigned short dflt)
80 unsigned short speed = 0;
81 int i;
83 for (i = 0; i < num; i++)
84 if (speed < spds[i])
85 speed = spds[i];
86 if (speed == 0)
87 speed = dflt;
89 return speed;
92 void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt, struct soc_pcmcia_timing *timing)
94 timing->io = calc_speed(skt->spd_io, MAX_IO_WIN, SOC_PCMCIA_IO_ACCESS);
95 timing->mem = calc_speed(skt->spd_mem, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
96 timing->attr = calc_speed(skt->spd_attr, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
98 EXPORT_SYMBOL(soc_common_pcmcia_get_timing);
100 static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt)
102 struct pcmcia_state state;
103 unsigned int stat;
105 memset(&state, 0, sizeof(struct pcmcia_state));
107 skt->ops->socket_state(skt, &state);
109 stat = state.detect ? SS_DETECT : 0;
110 stat |= state.ready ? SS_READY : 0;
111 stat |= state.wrprot ? SS_WRPROT : 0;
112 stat |= state.vs_3v ? SS_3VCARD : 0;
113 stat |= state.vs_Xv ? SS_XVCARD : 0;
115 /* The power status of individual sockets is not available
116 * explicitly from the hardware, so we just remember the state
117 * and regurgitate it upon request:
119 stat |= skt->cs_state.Vcc ? SS_POWERON : 0;
121 if (skt->cs_state.flags & SS_IOCARD)
122 stat |= state.bvd1 ? SS_STSCHG : 0;
123 else {
124 if (state.bvd1 == 0)
125 stat |= SS_BATDEAD;
126 else if (state.bvd2 == 0)
127 stat |= SS_BATWARN;
129 return stat;
133 * soc_common_pcmcia_config_skt
134 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
136 * Convert PCMCIA socket state to our socket configure structure.
138 static int
139 soc_common_pcmcia_config_skt(struct soc_pcmcia_socket *skt, socket_state_t *state)
141 int ret;
143 ret = skt->ops->configure_socket(skt, state);
144 if (ret == 0) {
146 * This really needs a better solution. The IRQ
147 * may or may not be claimed by the driver.
149 if (skt->irq_state != 1 && state->io_irq) {
150 skt->irq_state = 1;
151 set_irq_type(skt->irq, IRQT_FALLING);
152 } else if (skt->irq_state == 1 && state->io_irq == 0) {
153 skt->irq_state = 0;
154 set_irq_type(skt->irq, IRQT_NOEDGE);
157 skt->cs_state = *state;
160 if (ret < 0)
161 printk(KERN_ERR "soc_common_pcmcia: unable to configure "
162 "socket %d\n", skt->nr);
164 return ret;
167 /* soc_common_pcmcia_sock_init()
168 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
170 * (Re-)Initialise the socket, turning on status interrupts
171 * and PCMCIA bus. This must wait for power to stabilise
172 * so that the card status signals report correctly.
174 * Returns: 0
176 static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock)
178 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
180 debug(skt, 2, "initializing socket\n");
182 skt->ops->socket_init(skt);
183 return 0;
188 * soc_common_pcmcia_suspend()
189 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
191 * Remove power on the socket, disable IRQs from the card.
192 * Turn off status interrupts, and disable the PCMCIA bus.
194 * Returns: 0
196 static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock)
198 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
200 debug(skt, 2, "suspending socket\n");
202 skt->ops->socket_suspend(skt);
204 return 0;
207 static DEFINE_SPINLOCK(status_lock);
209 static void soc_common_check_status(struct soc_pcmcia_socket *skt)
211 unsigned int events;
213 debug(skt, 4, "entering PCMCIA monitoring thread\n");
215 do {
216 unsigned int status;
217 unsigned long flags;
219 status = soc_common_pcmcia_skt_state(skt);
221 spin_lock_irqsave(&status_lock, flags);
222 events = (status ^ skt->status) & skt->cs_state.csc_mask;
223 skt->status = status;
224 spin_unlock_irqrestore(&status_lock, flags);
226 debug(skt, 4, "events: %s%s%s%s%s%s\n",
227 events == 0 ? "<NONE>" : "",
228 events & SS_DETECT ? "DETECT " : "",
229 events & SS_READY ? "READY " : "",
230 events & SS_BATDEAD ? "BATDEAD " : "",
231 events & SS_BATWARN ? "BATWARN " : "",
232 events & SS_STSCHG ? "STSCHG " : "");
234 if (events)
235 pcmcia_parse_events(&skt->socket, events);
236 } while (events);
239 /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */
240 static void soc_common_pcmcia_poll_event(unsigned long dummy)
242 struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy;
243 debug(skt, 4, "polling for events\n");
245 mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD);
247 soc_common_check_status(skt);
252 * Service routine for socket driver interrupts (requested by the
253 * low-level PCMCIA init() operation via soc_common_pcmcia_thread()).
254 * The actual interrupt-servicing work is performed by
255 * soc_common_pcmcia_thread(), largely because the Card Services event-
256 * handling code performs scheduling operations which cannot be
257 * executed from within an interrupt context.
259 static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev)
261 struct soc_pcmcia_socket *skt = dev;
263 debug(skt, 3, "servicing IRQ %d\n", irq);
265 soc_common_check_status(skt);
267 return IRQ_HANDLED;
272 * Implements the get_status() operation for the in-kernel PCMCIA
273 * service (formerly SS_GetStatus in Card Services). Essentially just
274 * fills in bits in `status' according to internal driver state or
275 * the value of the voltage detect chipselect register.
277 * As a debugging note, during card startup, the PCMCIA core issues
278 * three set_socket() commands in a row the first with RESET deasserted,
279 * the second with RESET asserted, and the last with RESET deasserted
280 * again. Following the third set_socket(), a get_status() command will
281 * be issued. The kernel is looking for the SS_READY flag (see
282 * setup_socket(), reset_socket(), and unreset_socket() in cs.c).
284 * Returns: 0
286 static int
287 soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status)
289 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
291 skt->status = soc_common_pcmcia_skt_state(skt);
292 *status = skt->status;
294 return 0;
299 * Implements the set_socket() operation for the in-kernel PCMCIA
300 * service (formerly SS_SetSocket in Card Services). We more or
301 * less punt all of this work and let the kernel handle the details
302 * of power configuration, reset, &c. We also record the value of
303 * `state' in order to regurgitate it to the PCMCIA core later.
305 static int
306 soc_common_pcmcia_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
308 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
310 debug(skt, 2, "mask: %s%s%s%s%s%sflags: %s%s%s%s%s%sVcc %d Vpp %d irq %d\n",
311 (state->csc_mask==0)?"<NONE> ":"",
312 (state->csc_mask&SS_DETECT)?"DETECT ":"",
313 (state->csc_mask&SS_READY)?"READY ":"",
314 (state->csc_mask&SS_BATDEAD)?"BATDEAD ":"",
315 (state->csc_mask&SS_BATWARN)?"BATWARN ":"",
316 (state->csc_mask&SS_STSCHG)?"STSCHG ":"",
317 (state->flags==0)?"<NONE> ":"",
318 (state->flags&SS_PWR_AUTO)?"PWR_AUTO ":"",
319 (state->flags&SS_IOCARD)?"IOCARD ":"",
320 (state->flags&SS_RESET)?"RESET ":"",
321 (state->flags&SS_SPKR_ENA)?"SPKR_ENA ":"",
322 (state->flags&SS_OUTPUT_ENA)?"OUTPUT_ENA ":"",
323 state->Vcc, state->Vpp, state->io_irq);
325 return soc_common_pcmcia_config_skt(skt, state);
330 * Implements the set_io_map() operation for the in-kernel PCMCIA
331 * service (formerly SS_SetIOMap in Card Services). We configure
332 * the map speed as requested, but override the address ranges
333 * supplied by Card Services.
335 * Returns: 0 on success, -1 on error
337 static int
338 soc_common_pcmcia_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *map)
340 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
341 unsigned short speed = map->speed;
343 debug(skt, 2, "map %u speed %u start 0x%08x stop 0x%08x\n",
344 map->map, map->speed, map->start, map->stop);
345 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
346 (map->flags==0)?"<NONE>":"",
347 (map->flags&MAP_ACTIVE)?"ACTIVE ":"",
348 (map->flags&MAP_16BIT)?"16BIT ":"",
349 (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"",
350 (map->flags&MAP_0WS)?"0WS ":"",
351 (map->flags&MAP_WRPROT)?"WRPROT ":"",
352 (map->flags&MAP_USE_WAIT)?"USE_WAIT ":"",
353 (map->flags&MAP_PREFETCH)?"PREFETCH ":"");
355 if (map->map >= MAX_IO_WIN) {
356 printk(KERN_ERR "%s(): map (%d) out of range\n", __FUNCTION__,
357 map->map);
358 return -1;
361 if (map->flags & MAP_ACTIVE) {
362 if (speed == 0)
363 speed = SOC_PCMCIA_IO_ACCESS;
364 } else {
365 speed = 0;
368 skt->spd_io[map->map] = speed;
369 skt->ops->set_timing(skt);
371 if (map->stop == 1)
372 map->stop = PAGE_SIZE-1;
374 map->stop -= map->start;
375 map->stop += skt->socket.io_offset;
376 map->start = skt->socket.io_offset;
378 return 0;
383 * Implements the set_mem_map() operation for the in-kernel PCMCIA
384 * service (formerly SS_SetMemMap in Card Services). We configure
385 * the map speed as requested, but override the address ranges
386 * supplied by Card Services.
388 * Returns: 0 on success, -ERRNO on error
390 static int
391 soc_common_pcmcia_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *map)
393 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
394 struct resource *res;
395 unsigned short speed = map->speed;
397 debug(skt, 2, "map %u speed %u card_start %08x\n",
398 map->map, map->speed, map->card_start);
399 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
400 (map->flags==0)?"<NONE>":"",
401 (map->flags&MAP_ACTIVE)?"ACTIVE ":"",
402 (map->flags&MAP_16BIT)?"16BIT ":"",
403 (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"",
404 (map->flags&MAP_0WS)?"0WS ":"",
405 (map->flags&MAP_WRPROT)?"WRPROT ":"",
406 (map->flags&MAP_ATTRIB)?"ATTRIB ":"",
407 (map->flags&MAP_USE_WAIT)?"USE_WAIT ":"");
409 if (map->map >= MAX_WIN)
410 return -EINVAL;
412 if (map->flags & MAP_ACTIVE) {
413 if (speed == 0)
414 speed = 300;
415 } else {
416 speed = 0;
419 if (map->flags & MAP_ATTRIB) {
420 res = &skt->res_attr;
421 skt->spd_attr[map->map] = speed;
422 skt->spd_mem[map->map] = 0;
423 } else {
424 res = &skt->res_mem;
425 skt->spd_attr[map->map] = 0;
426 skt->spd_mem[map->map] = speed;
429 skt->ops->set_timing(skt);
431 map->static_start = res->start + map->card_start;
433 return 0;
436 struct bittbl {
437 unsigned int mask;
438 const char *name;
441 static struct bittbl status_bits[] = {
442 { SS_WRPROT, "SS_WRPROT" },
443 { SS_BATDEAD, "SS_BATDEAD" },
444 { SS_BATWARN, "SS_BATWARN" },
445 { SS_READY, "SS_READY" },
446 { SS_DETECT, "SS_DETECT" },
447 { SS_POWERON, "SS_POWERON" },
448 { SS_STSCHG, "SS_STSCHG" },
449 { SS_3VCARD, "SS_3VCARD" },
450 { SS_XVCARD, "SS_XVCARD" },
453 static struct bittbl conf_bits[] = {
454 { SS_PWR_AUTO, "SS_PWR_AUTO" },
455 { SS_IOCARD, "SS_IOCARD" },
456 { SS_RESET, "SS_RESET" },
457 { SS_DMA_MODE, "SS_DMA_MODE" },
458 { SS_SPKR_ENA, "SS_SPKR_ENA" },
459 { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" },
462 static void
463 dump_bits(char **p, const char *prefix, unsigned int val, struct bittbl *bits, int sz)
465 char *b = *p;
466 int i;
468 b += sprintf(b, "%-9s:", prefix);
469 for (i = 0; i < sz; i++)
470 if (val & bits[i].mask)
471 b += sprintf(b, " %s", bits[i].name);
472 *b++ = '\n';
473 *p = b;
477 * Implements the /sys/class/pcmcia_socket/??/status file.
479 * Returns: the number of characters added to the buffer
481 static ssize_t show_status(struct device *dev, struct device_attribute *attr, char *buf)
483 struct soc_pcmcia_socket *skt =
484 container_of(dev, struct soc_pcmcia_socket, socket.dev);
485 char *p = buf;
487 p+=sprintf(p, "slot : %d\n", skt->nr);
489 dump_bits(&p, "status", skt->status,
490 status_bits, ARRAY_SIZE(status_bits));
491 dump_bits(&p, "csc_mask", skt->cs_state.csc_mask,
492 status_bits, ARRAY_SIZE(status_bits));
493 dump_bits(&p, "cs_flags", skt->cs_state.flags,
494 conf_bits, ARRAY_SIZE(conf_bits));
496 p+=sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc);
497 p+=sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp);
498 p+=sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq, skt->irq);
499 if (skt->ops->show_timing)
500 p+=skt->ops->show_timing(skt, p);
502 return p-buf;
504 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
507 static struct pccard_operations soc_common_pcmcia_operations = {
508 .init = soc_common_pcmcia_sock_init,
509 .suspend = soc_common_pcmcia_suspend,
510 .get_status = soc_common_pcmcia_get_status,
511 .set_socket = soc_common_pcmcia_set_socket,
512 .set_io_map = soc_common_pcmcia_set_io_map,
513 .set_mem_map = soc_common_pcmcia_set_mem_map,
517 int soc_pcmcia_request_irqs(struct soc_pcmcia_socket *skt,
518 struct pcmcia_irqs *irqs, int nr)
520 int i, res = 0;
522 for (i = 0; i < nr; i++) {
523 if (irqs[i].sock != skt->nr)
524 continue;
525 res = request_irq(irqs[i].irq, soc_common_pcmcia_interrupt,
526 IRQF_DISABLED, irqs[i].str, skt);
527 if (res)
528 break;
529 set_irq_type(irqs[i].irq, IRQT_NOEDGE);
532 if (res) {
533 printk(KERN_ERR "PCMCIA: request for IRQ%d failed (%d)\n",
534 irqs[i].irq, res);
536 while (i--)
537 if (irqs[i].sock == skt->nr)
538 free_irq(irqs[i].irq, skt);
540 return res;
542 EXPORT_SYMBOL(soc_pcmcia_request_irqs);
544 void soc_pcmcia_free_irqs(struct soc_pcmcia_socket *skt,
545 struct pcmcia_irqs *irqs, int nr)
547 int i;
549 for (i = 0; i < nr; i++)
550 if (irqs[i].sock == skt->nr)
551 free_irq(irqs[i].irq, skt);
553 EXPORT_SYMBOL(soc_pcmcia_free_irqs);
555 void soc_pcmcia_disable_irqs(struct soc_pcmcia_socket *skt,
556 struct pcmcia_irqs *irqs, int nr)
558 int i;
560 for (i = 0; i < nr; i++)
561 if (irqs[i].sock == skt->nr)
562 set_irq_type(irqs[i].irq, IRQT_NOEDGE);
564 EXPORT_SYMBOL(soc_pcmcia_disable_irqs);
566 void soc_pcmcia_enable_irqs(struct soc_pcmcia_socket *skt,
567 struct pcmcia_irqs *irqs, int nr)
569 int i;
571 for (i = 0; i < nr; i++)
572 if (irqs[i].sock == skt->nr) {
573 set_irq_type(irqs[i].irq, IRQT_RISING);
574 set_irq_type(irqs[i].irq, IRQT_BOTHEDGE);
577 EXPORT_SYMBOL(soc_pcmcia_enable_irqs);
580 LIST_HEAD(soc_pcmcia_sockets);
581 DECLARE_MUTEX(soc_pcmcia_sockets_lock);
583 static const char *skt_names[] = {
584 "PCMCIA socket 0",
585 "PCMCIA socket 1",
588 struct skt_dev_info {
589 int nskt;
590 struct soc_pcmcia_socket skt[0];
593 #define SKT_DEV_INFO_SIZE(n) \
594 (sizeof(struct skt_dev_info) + (n)*sizeof(struct soc_pcmcia_socket))
596 #ifdef CONFIG_CPU_FREQ
597 static int
598 soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data)
600 struct soc_pcmcia_socket *skt;
601 struct cpufreq_freqs *freqs = data;
602 int ret = 0;
604 down(&soc_pcmcia_sockets_lock);
605 list_for_each_entry(skt, &soc_pcmcia_sockets, node)
606 if ( skt->ops->frequency_change )
607 ret += skt->ops->frequency_change(skt, val, freqs);
608 up(&soc_pcmcia_sockets_lock);
610 return ret;
613 static struct notifier_block soc_pcmcia_notifier_block = {
614 .notifier_call = soc_pcmcia_notifier
617 static int soc_pcmcia_cpufreq_register(void)
619 int ret;
621 ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block,
622 CPUFREQ_TRANSITION_NOTIFIER);
623 if (ret < 0)
624 printk(KERN_ERR "Unable to register CPU frequency change "
625 "notifier for PCMCIA (%d)\n", ret);
626 return ret;
629 static void soc_pcmcia_cpufreq_unregister(void)
631 cpufreq_unregister_notifier(&soc_pcmcia_notifier_block, CPUFREQ_TRANSITION_NOTIFIER);
634 #else
635 static int soc_pcmcia_cpufreq_register(void) { return 0; }
636 static void soc_pcmcia_cpufreq_unregister(void) {}
637 #endif
639 int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops, int first, int nr)
641 struct skt_dev_info *sinfo;
642 struct soc_pcmcia_socket *skt;
643 int ret, i;
645 down(&soc_pcmcia_sockets_lock);
647 sinfo = kzalloc(SKT_DEV_INFO_SIZE(nr), GFP_KERNEL);
648 if (!sinfo) {
649 ret = -ENOMEM;
650 goto out;
653 sinfo->nskt = nr;
656 * Initialise the per-socket structure.
658 for (i = 0; i < nr; i++) {
659 skt = &sinfo->skt[i];
661 skt->socket.ops = &soc_common_pcmcia_operations;
662 skt->socket.owner = ops->owner;
663 skt->socket.dev.parent = dev;
665 init_timer(&skt->poll_timer);
666 skt->poll_timer.function = soc_common_pcmcia_poll_event;
667 skt->poll_timer.data = (unsigned long)skt;
668 skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD;
670 skt->nr = first + i;
671 skt->irq = NO_IRQ;
672 skt->dev = dev;
673 skt->ops = ops;
675 skt->res_skt.start = _PCMCIA(skt->nr);
676 skt->res_skt.end = _PCMCIA(skt->nr) + PCMCIASp - 1;
677 skt->res_skt.name = skt_names[skt->nr];
678 skt->res_skt.flags = IORESOURCE_MEM;
680 ret = request_resource(&iomem_resource, &skt->res_skt);
681 if (ret)
682 goto out_err_1;
684 skt->res_io.start = _PCMCIAIO(skt->nr);
685 skt->res_io.end = _PCMCIAIO(skt->nr) + PCMCIAIOSp - 1;
686 skt->res_io.name = "io";
687 skt->res_io.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
689 ret = request_resource(&skt->res_skt, &skt->res_io);
690 if (ret)
691 goto out_err_2;
693 skt->res_mem.start = _PCMCIAMem(skt->nr);
694 skt->res_mem.end = _PCMCIAMem(skt->nr) + PCMCIAMemSp - 1;
695 skt->res_mem.name = "memory";
696 skt->res_mem.flags = IORESOURCE_MEM;
698 ret = request_resource(&skt->res_skt, &skt->res_mem);
699 if (ret)
700 goto out_err_3;
702 skt->res_attr.start = _PCMCIAAttr(skt->nr);
703 skt->res_attr.end = _PCMCIAAttr(skt->nr) + PCMCIAAttrSp - 1;
704 skt->res_attr.name = "attribute";
705 skt->res_attr.flags = IORESOURCE_MEM;
707 ret = request_resource(&skt->res_skt, &skt->res_attr);
708 if (ret)
709 goto out_err_4;
711 skt->virt_io = ioremap(skt->res_io.start, 0x10000);
712 if (skt->virt_io == NULL) {
713 ret = -ENOMEM;
714 goto out_err_5;
717 if (list_empty(&soc_pcmcia_sockets))
718 soc_pcmcia_cpufreq_register();
720 list_add(&skt->node, &soc_pcmcia_sockets);
723 * We initialize default socket timing here, because
724 * we are not guaranteed to see a SetIOMap operation at
725 * runtime.
727 ops->set_timing(skt);
729 ret = ops->hw_init(skt);
730 if (ret)
731 goto out_err_6;
733 skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD;
734 skt->socket.resource_ops = &pccard_static_ops;
735 skt->socket.irq_mask = 0;
736 skt->socket.map_size = PAGE_SIZE;
737 skt->socket.pci_irq = skt->irq;
738 skt->socket.io_offset = (unsigned long)skt->virt_io;
740 skt->status = soc_common_pcmcia_skt_state(skt);
742 ret = pcmcia_register_socket(&skt->socket);
743 if (ret)
744 goto out_err_7;
746 WARN_ON(skt->socket.sock != i);
748 add_timer(&skt->poll_timer);
750 device_create_file(&skt->socket.dev, &dev_attr_status);
753 dev_set_drvdata(dev, sinfo);
754 ret = 0;
755 goto out;
757 do {
758 skt = &sinfo->skt[i];
760 del_timer_sync(&skt->poll_timer);
761 pcmcia_unregister_socket(&skt->socket);
763 out_err_7:
764 flush_scheduled_work();
766 ops->hw_shutdown(skt);
767 out_err_6:
768 list_del(&skt->node);
769 iounmap(skt->virt_io);
770 out_err_5:
771 release_resource(&skt->res_attr);
772 out_err_4:
773 release_resource(&skt->res_mem);
774 out_err_3:
775 release_resource(&skt->res_io);
776 out_err_2:
777 release_resource(&skt->res_skt);
778 out_err_1:
779 i--;
780 } while (i > 0);
782 kfree(sinfo);
784 out:
785 up(&soc_pcmcia_sockets_lock);
786 return ret;
789 int soc_common_drv_pcmcia_remove(struct device *dev)
791 struct skt_dev_info *sinfo = dev_get_drvdata(dev);
792 int i;
794 dev_set_drvdata(dev, NULL);
796 down(&soc_pcmcia_sockets_lock);
797 for (i = 0; i < sinfo->nskt; i++) {
798 struct soc_pcmcia_socket *skt = &sinfo->skt[i];
800 del_timer_sync(&skt->poll_timer);
802 pcmcia_unregister_socket(&skt->socket);
804 flush_scheduled_work();
806 skt->ops->hw_shutdown(skt);
808 soc_common_pcmcia_config_skt(skt, &dead_socket);
810 list_del(&skt->node);
811 iounmap(skt->virt_io);
812 skt->virt_io = NULL;
813 release_resource(&skt->res_attr);
814 release_resource(&skt->res_mem);
815 release_resource(&skt->res_io);
816 release_resource(&skt->res_skt);
818 if (list_empty(&soc_pcmcia_sockets))
819 soc_pcmcia_cpufreq_unregister();
821 up(&soc_pcmcia_sockets_lock);
823 kfree(sinfo);
825 return 0;
827 EXPORT_SYMBOL(soc_common_drv_pcmcia_remove);