MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / pcmcia / soc_common.c
bloba45fee3f43550fec3968ebd1a1ff584f5ded1adb
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/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>
45 #include <asm/hardware.h>
46 #include <asm/io.h>
47 #include <asm/irq.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 printk(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);
200 int ret;
202 debug(skt, 2, "suspending socket\n");
204 ret = soc_common_pcmcia_config_skt(skt, &dead_socket);
205 if (ret == 0)
206 skt->ops->socket_suspend(skt);
208 return ret;
211 static spinlock_t status_lock = SPIN_LOCK_UNLOCKED;
213 static void soc_common_check_status(struct soc_pcmcia_socket *skt)
215 unsigned int events;
217 debug(skt, 4, "entering PCMCIA monitoring thread\n");
219 do {
220 unsigned int status;
221 unsigned long flags;
223 status = soc_common_pcmcia_skt_state(skt);
225 spin_lock_irqsave(&status_lock, flags);
226 events = (status ^ skt->status) & skt->cs_state.csc_mask;
227 skt->status = status;
228 spin_unlock_irqrestore(&status_lock, flags);
230 debug(skt, 4, "events: %s%s%s%s%s%s\n",
231 events == 0 ? "<NONE>" : "",
232 events & SS_DETECT ? "DETECT " : "",
233 events & SS_READY ? "READY " : "",
234 events & SS_BATDEAD ? "BATDEAD " : "",
235 events & SS_BATWARN ? "BATWARN " : "",
236 events & SS_STSCHG ? "STSCHG " : "");
238 if (events)
239 pcmcia_parse_events(&skt->socket, events);
240 } while (events);
243 /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */
244 static void soc_common_pcmcia_poll_event(unsigned long dummy)
246 struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy;
247 debug(skt, 4, "polling for events\n");
249 mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD);
251 soc_common_check_status(skt);
256 * Service routine for socket driver interrupts (requested by the
257 * low-level PCMCIA init() operation via soc_common_pcmcia_thread()).
258 * The actual interrupt-servicing work is performed by
259 * soc_common_pcmcia_thread(), largely because the Card Services event-
260 * handling code performs scheduling operations which cannot be
261 * executed from within an interrupt context.
263 static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev, struct pt_regs *regs)
265 struct soc_pcmcia_socket *skt = dev;
267 debug(skt, 3, "servicing IRQ %d\n", irq);
269 soc_common_check_status(skt);
271 return IRQ_HANDLED;
276 * Implements the get_status() operation for the in-kernel PCMCIA
277 * service (formerly SS_GetStatus in Card Services). Essentially just
278 * fills in bits in `status' according to internal driver state or
279 * the value of the voltage detect chipselect register.
281 * As a debugging note, during card startup, the PCMCIA core issues
282 * three set_socket() commands in a row the first with RESET deasserted,
283 * the second with RESET asserted, and the last with RESET deasserted
284 * again. Following the third set_socket(), a get_status() command will
285 * be issued. The kernel is looking for the SS_READY flag (see
286 * setup_socket(), reset_socket(), and unreset_socket() in cs.c).
288 * Returns: 0
290 static int
291 soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status)
293 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
295 skt->status = soc_common_pcmcia_skt_state(skt);
296 *status = skt->status;
298 return 0;
303 * Implements the get_socket() operation for the in-kernel PCMCIA
304 * service (formerly SS_GetSocket in Card Services). Not a very
305 * exciting routine.
307 * Returns: 0
309 static int
310 soc_common_pcmcia_get_socket(struct pcmcia_socket *sock, socket_state_t *state)
312 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
314 debug(skt, 2, "\n");
316 *state = skt->cs_state;
318 return 0;
322 * Implements the set_socket() operation for the in-kernel PCMCIA
323 * service (formerly SS_SetSocket in Card Services). We more or
324 * less punt all of this work and let the kernel handle the details
325 * of power configuration, reset, &c. We also record the value of
326 * `state' in order to regurgitate it to the PCMCIA core later.
328 * Returns: 0
330 static int
331 soc_common_pcmcia_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
333 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
335 debug(skt, 2, "mask: %s%s%s%s%s%sflags: %s%s%s%s%s%sVcc %d Vpp %d irq %d\n",
336 (state->csc_mask==0)?"<NONE> ":"",
337 (state->csc_mask&SS_DETECT)?"DETECT ":"",
338 (state->csc_mask&SS_READY)?"READY ":"",
339 (state->csc_mask&SS_BATDEAD)?"BATDEAD ":"",
340 (state->csc_mask&SS_BATWARN)?"BATWARN ":"",
341 (state->csc_mask&SS_STSCHG)?"STSCHG ":"",
342 (state->flags==0)?"<NONE> ":"",
343 (state->flags&SS_PWR_AUTO)?"PWR_AUTO ":"",
344 (state->flags&SS_IOCARD)?"IOCARD ":"",
345 (state->flags&SS_RESET)?"RESET ":"",
346 (state->flags&SS_SPKR_ENA)?"SPKR_ENA ":"",
347 (state->flags&SS_OUTPUT_ENA)?"OUTPUT_ENA ":"",
348 state->Vcc, state->Vpp, state->io_irq);
350 return soc_common_pcmcia_config_skt(skt, state);
355 * Implements the set_io_map() operation for the in-kernel PCMCIA
356 * service (formerly SS_SetIOMap in Card Services). We configure
357 * the map speed as requested, but override the address ranges
358 * supplied by Card Services.
360 * Returns: 0 on success, -1 on error
362 static int
363 soc_common_pcmcia_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *map)
365 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
366 unsigned short speed = map->speed;
368 debug(skt, 2, "map %u speed %u start 0x%08x stop 0x%08x\n",
369 map->map, map->speed, map->start, map->stop);
370 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
371 (map->flags==0)?"<NONE>":"",
372 (map->flags&MAP_ACTIVE)?"ACTIVE ":"",
373 (map->flags&MAP_16BIT)?"16BIT ":"",
374 (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"",
375 (map->flags&MAP_0WS)?"0WS ":"",
376 (map->flags&MAP_WRPROT)?"WRPROT ":"",
377 (map->flags&MAP_USE_WAIT)?"USE_WAIT ":"",
378 (map->flags&MAP_PREFETCH)?"PREFETCH ":"");
380 if (map->map >= MAX_IO_WIN) {
381 printk(KERN_ERR "%s(): map (%d) out of range\n", __FUNCTION__,
382 map->map);
383 return -1;
386 if (map->flags & MAP_ACTIVE) {
387 if (speed == 0)
388 speed = SOC_PCMCIA_IO_ACCESS;
389 } else {
390 speed = 0;
393 skt->spd_io[map->map] = speed;
394 skt->ops->set_timing(skt);
396 if (map->stop == 1)
397 map->stop = PAGE_SIZE-1;
399 map->stop -= map->start;
400 map->stop += (unsigned long)skt->virt_io;
401 map->start = (unsigned long)skt->virt_io;
403 return 0;
408 * Implements the set_mem_map() operation for the in-kernel PCMCIA
409 * service (formerly SS_SetMemMap in Card Services). We configure
410 * the map speed as requested, but override the address ranges
411 * supplied by Card Services.
413 * Returns: 0 on success, -1 on error
415 static int
416 soc_common_pcmcia_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *map)
418 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
419 struct resource *res;
420 unsigned short speed = map->speed;
422 debug(skt, 2, "map %u speed %u card_start %08x\n",
423 map->map, map->speed, map->card_start);
424 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
425 (map->flags==0)?"<NONE>":"",
426 (map->flags&MAP_ACTIVE)?"ACTIVE ":"",
427 (map->flags&MAP_16BIT)?"16BIT ":"",
428 (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"",
429 (map->flags&MAP_0WS)?"0WS ":"",
430 (map->flags&MAP_WRPROT)?"WRPROT ":"",
431 (map->flags&MAP_ATTRIB)?"ATTRIB ":"",
432 (map->flags&MAP_USE_WAIT)?"USE_WAIT ":"");
434 if (map->map >= MAX_WIN)
435 return -EINVAL;
437 if (map->flags & MAP_ACTIVE) {
438 if (speed == 0)
439 speed = 300;
440 } else {
441 speed = 0;
444 if (map->flags & MAP_ATTRIB) {
445 res = &skt->res_attr;
446 skt->spd_attr[map->map] = speed;
447 skt->spd_mem[map->map] = 0;
448 } else {
449 res = &skt->res_mem;
450 skt->spd_attr[map->map] = 0;
451 skt->spd_mem[map->map] = speed;
454 skt->ops->set_timing(skt);
456 map->static_start = res->start + map->card_start;
458 return 0;
461 struct bittbl {
462 unsigned int mask;
463 const char *name;
466 static struct bittbl status_bits[] = {
467 { SS_WRPROT, "SS_WRPROT" },
468 { SS_BATDEAD, "SS_BATDEAD" },
469 { SS_BATWARN, "SS_BATWARN" },
470 { SS_READY, "SS_READY" },
471 { SS_DETECT, "SS_DETECT" },
472 { SS_POWERON, "SS_POWERON" },
473 { SS_STSCHG, "SS_STSCHG" },
474 { SS_3VCARD, "SS_3VCARD" },
475 { SS_XVCARD, "SS_XVCARD" },
478 static struct bittbl conf_bits[] = {
479 { SS_PWR_AUTO, "SS_PWR_AUTO" },
480 { SS_IOCARD, "SS_IOCARD" },
481 { SS_RESET, "SS_RESET" },
482 { SS_DMA_MODE, "SS_DMA_MODE" },
483 { SS_SPKR_ENA, "SS_SPKR_ENA" },
484 { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" },
487 static void
488 dump_bits(char **p, const char *prefix, unsigned int val, struct bittbl *bits, int sz)
490 char *b = *p;
491 int i;
493 b += sprintf(b, "%-9s:", prefix);
494 for (i = 0; i < sz; i++)
495 if (val & bits[i].mask)
496 b += sprintf(b, " %s", bits[i].name);
497 *b++ = '\n';
498 *p = b;
502 * Implements the /sys/class/pcmcia_socket/??/status file.
504 * Returns: the number of characters added to the buffer
506 static ssize_t show_status(struct class_device *class_dev, char *buf)
508 struct soc_pcmcia_socket *skt =
509 container_of(class_dev, struct soc_pcmcia_socket, socket.dev);
510 char *p = buf;
512 p+=sprintf(p, "slot : %d\n", skt->nr);
514 dump_bits(&p, "status", skt->status,
515 status_bits, ARRAY_SIZE(status_bits));
516 dump_bits(&p, "csc_mask", skt->cs_state.csc_mask,
517 status_bits, ARRAY_SIZE(status_bits));
518 dump_bits(&p, "cs_flags", skt->cs_state.flags,
519 conf_bits, ARRAY_SIZE(conf_bits));
521 p+=sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc);
522 p+=sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp);
523 p+=sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq, skt->irq);
524 if (skt->ops->show_timing)
525 p+=skt->ops->show_timing(skt, p);
527 return p-buf;
529 static CLASS_DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
532 static struct pccard_operations soc_common_pcmcia_operations = {
533 .init = soc_common_pcmcia_sock_init,
534 .suspend = soc_common_pcmcia_suspend,
535 .get_status = soc_common_pcmcia_get_status,
536 .get_socket = soc_common_pcmcia_get_socket,
537 .set_socket = soc_common_pcmcia_set_socket,
538 .set_io_map = soc_common_pcmcia_set_io_map,
539 .set_mem_map = soc_common_pcmcia_set_mem_map,
543 int soc_pcmcia_request_irqs(struct soc_pcmcia_socket *skt,
544 struct pcmcia_irqs *irqs, int nr)
546 int i, res = 0;
548 for (i = 0; i < nr; i++) {
549 if (irqs[i].sock != skt->nr)
550 continue;
551 res = request_irq(irqs[i].irq, soc_common_pcmcia_interrupt,
552 SA_INTERRUPT, irqs[i].str, skt);
553 if (res)
554 break;
555 set_irq_type(irqs[i].irq, IRQT_NOEDGE);
558 if (res) {
559 printk(KERN_ERR "PCMCIA: request for IRQ%d failed (%d)\n",
560 irqs[i].irq, res);
562 while (i--)
563 if (irqs[i].sock == skt->nr)
564 free_irq(irqs[i].irq, skt);
566 return res;
568 EXPORT_SYMBOL(soc_pcmcia_request_irqs);
570 void soc_pcmcia_free_irqs(struct soc_pcmcia_socket *skt,
571 struct pcmcia_irqs *irqs, int nr)
573 int i;
575 for (i = 0; i < nr; i++)
576 if (irqs[i].sock == skt->nr)
577 free_irq(irqs[i].irq, skt);
579 EXPORT_SYMBOL(soc_pcmcia_free_irqs);
581 void soc_pcmcia_disable_irqs(struct soc_pcmcia_socket *skt,
582 struct pcmcia_irqs *irqs, int nr)
584 int i;
586 for (i = 0; i < nr; i++)
587 if (irqs[i].sock == skt->nr)
588 set_irq_type(irqs[i].irq, IRQT_NOEDGE);
590 EXPORT_SYMBOL(soc_pcmcia_disable_irqs);
592 void soc_pcmcia_enable_irqs(struct soc_pcmcia_socket *skt,
593 struct pcmcia_irqs *irqs, int nr)
595 int i;
597 for (i = 0; i < nr; i++)
598 if (irqs[i].sock == skt->nr) {
599 set_irq_type(irqs[i].irq, IRQT_RISING);
600 set_irq_type(irqs[i].irq, IRQT_BOTHEDGE);
603 EXPORT_SYMBOL(soc_pcmcia_enable_irqs);
606 LIST_HEAD(soc_pcmcia_sockets);
607 DECLARE_MUTEX(soc_pcmcia_sockets_lock);
609 static const char *skt_names[] = {
610 "PCMCIA socket 0",
611 "PCMCIA socket 1",
614 struct skt_dev_info {
615 int nskt;
616 struct soc_pcmcia_socket skt[0];
619 #define SKT_DEV_INFO_SIZE(n) \
620 (sizeof(struct skt_dev_info) + (n)*sizeof(struct soc_pcmcia_socket))
622 #ifdef CONFIG_CPU_FREQ
623 static int
624 soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data)
626 struct soc_pcmcia_socket *skt;
627 struct cpufreq_freqs *freqs = data;
628 int ret = 0;
630 down(&soc_pcmcia_sockets_lock);
631 list_for_each_entry(skt, &soc_pcmcia_sockets, node)
632 if ( skt->ops->frequency_change )
633 ret += skt->ops->frequency_change(skt, val, freqs);
634 up(&soc_pcmcia_sockets_lock);
636 return ret;
639 static struct notifier_block soc_pcmcia_notifier_block = {
640 .notifier_call = soc_pcmcia_notifier
643 static int soc_pcmcia_cpufreq_register(void)
645 int ret;
647 ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block,
648 CPUFREQ_TRANSITION_NOTIFIER);
649 if (ret < 0)
650 printk(KERN_ERR "Unable to register CPU frequency change "
651 "notifier for PCMCIA (%d)\n", ret);
652 return ret;
655 static void soc_pcmcia_cpufreq_unregister(void)
657 cpufreq_unregister_notifier(&soc_pcmcia_notifier_block, CPUFREQ_TRANSITION_NOTIFIER);
660 #else
661 #define soc_pcmcia_cpufreq_register()
662 #define soc_pcmcia_cpufreq_unregister()
663 #endif
665 int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops, int first, int nr)
667 struct skt_dev_info *sinfo;
668 struct soc_pcmcia_socket *skt;
669 int ret, i;
671 down(&soc_pcmcia_sockets_lock);
673 sinfo = kmalloc(SKT_DEV_INFO_SIZE(nr), GFP_KERNEL);
674 if (!sinfo) {
675 ret = -ENOMEM;
676 goto out;
679 memset(sinfo, 0, SKT_DEV_INFO_SIZE(nr));
680 sinfo->nskt = nr;
683 * Initialise the per-socket structure.
685 for (i = 0; i < nr; i++) {
686 skt = &sinfo->skt[i];
688 skt->socket.ops = &soc_common_pcmcia_operations;
689 skt->socket.owner = ops->owner;
690 skt->socket.dev.dev = dev;
692 init_timer(&skt->poll_timer);
693 skt->poll_timer.function = soc_common_pcmcia_poll_event;
694 skt->poll_timer.data = (unsigned long)skt;
695 skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD;
697 skt->nr = first + i;
698 skt->irq = NO_IRQ;
699 skt->dev = dev;
700 skt->ops = ops;
702 skt->res_skt.start = _PCMCIA(skt->nr);
703 skt->res_skt.end = _PCMCIA(skt->nr) + PCMCIASp - 1;
704 skt->res_skt.name = skt_names[skt->nr];
705 skt->res_skt.flags = IORESOURCE_MEM;
707 ret = request_resource(&iomem_resource, &skt->res_skt);
708 if (ret)
709 goto out_err_1;
711 skt->res_io.start = _PCMCIAIO(skt->nr);
712 skt->res_io.end = _PCMCIAIO(skt->nr) + PCMCIAIOSp - 1;
713 skt->res_io.name = "io";
714 skt->res_io.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
716 ret = request_resource(&skt->res_skt, &skt->res_io);
717 if (ret)
718 goto out_err_2;
720 skt->res_mem.start = _PCMCIAMem(skt->nr);
721 skt->res_mem.end = _PCMCIAMem(skt->nr) + PCMCIAMemSp - 1;
722 skt->res_mem.name = "memory";
723 skt->res_mem.flags = IORESOURCE_MEM;
725 ret = request_resource(&skt->res_skt, &skt->res_mem);
726 if (ret)
727 goto out_err_3;
729 skt->res_attr.start = _PCMCIAAttr(skt->nr);
730 skt->res_attr.end = _PCMCIAAttr(skt->nr) + PCMCIAAttrSp - 1;
731 skt->res_attr.name = "attribute";
732 skt->res_attr.flags = IORESOURCE_MEM;
734 ret = request_resource(&skt->res_skt, &skt->res_attr);
735 if (ret)
736 goto out_err_4;
738 skt->virt_io = ioremap(skt->res_io.start, 0x10000);
739 if (skt->virt_io == NULL) {
740 ret = -ENOMEM;
741 goto out_err_5;
744 if ( list_empty(&soc_pcmcia_sockets) )
745 soc_pcmcia_cpufreq_register();
747 list_add(&skt->node, &soc_pcmcia_sockets);
750 * We initialize default socket timing here, because
751 * we are not guaranteed to see a SetIOMap operation at
752 * runtime.
754 ops->set_timing(skt);
756 ret = ops->hw_init(skt);
757 if (ret)
758 goto out_err_6;
760 skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD;
761 skt->socket.irq_mask = 0;
762 skt->socket.map_size = PAGE_SIZE;
763 skt->socket.pci_irq = skt->irq;
764 skt->socket.io_offset = (unsigned long)skt->virt_io;
766 skt->status = soc_common_pcmcia_skt_state(skt);
768 ret = pcmcia_register_socket(&skt->socket);
769 if (ret)
770 goto out_err_7;
772 WARN_ON(skt->socket.sock != i);
774 add_timer(&skt->poll_timer);
776 class_device_create_file(&skt->socket.dev, &class_device_attr_status);
779 dev_set_drvdata(dev, sinfo);
780 ret = 0;
781 goto out;
783 do {
784 skt = &sinfo->skt[i];
786 del_timer_sync(&skt->poll_timer);
787 pcmcia_unregister_socket(&skt->socket);
789 out_err_7:
790 flush_scheduled_work();
792 ops->hw_shutdown(skt);
793 out_err_6:
794 list_del(&skt->node);
795 iounmap(skt->virt_io);
796 out_err_5:
797 release_resource(&skt->res_attr);
798 out_err_4:
799 release_resource(&skt->res_mem);
800 out_err_3:
801 release_resource(&skt->res_io);
802 out_err_2:
803 release_resource(&skt->res_skt);
804 out_err_1:
805 i--;
806 } while (i > 0);
808 kfree(sinfo);
810 out:
811 up(&soc_pcmcia_sockets_lock);
812 return ret;
815 int soc_common_drv_pcmcia_remove(struct device *dev)
817 struct skt_dev_info *sinfo = dev_get_drvdata(dev);
818 int i;
820 dev_set_drvdata(dev, NULL);
822 down(&soc_pcmcia_sockets_lock);
823 for (i = 0; i < sinfo->nskt; i++) {
824 struct soc_pcmcia_socket *skt = &sinfo->skt[i];
826 del_timer_sync(&skt->poll_timer);
828 pcmcia_unregister_socket(&skt->socket);
830 flush_scheduled_work();
832 skt->ops->hw_shutdown(skt);
834 soc_common_pcmcia_config_skt(skt, &dead_socket);
836 list_del(&skt->node);
837 iounmap(skt->virt_io);
838 skt->virt_io = NULL;
839 release_resource(&skt->res_attr);
840 release_resource(&skt->res_mem);
841 release_resource(&skt->res_io);
842 release_resource(&skt->res_skt);
844 if ( list_empty(&soc_pcmcia_sockets) )
845 soc_pcmcia_cpufreq_unregister();
847 up(&soc_pcmcia_sockets_lock);
849 kfree(sinfo);
851 return 0;