Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
[linux/fpc-iii.git] / drivers / pcmcia / soc_common.c
bloba2bc6ee1702e14f2c722b510c304863c7b9d0060
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/cpufreq.h>
35 #include <linux/gpio.h>
36 #include <linux/init.h>
37 #include <linux/interrupt.h>
38 #include <linux/io.h>
39 #include <linux/irq.h>
40 #include <linux/kernel.h>
41 #include <linux/mm.h>
42 #include <linux/module.h>
43 #include <linux/moduleparam.h>
44 #include <linux/mutex.h>
45 #include <linux/spinlock.h>
46 #include <linux/timer.h>
48 #include <mach/hardware.h>
50 #include "soc_common.h"
52 static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev);
54 #ifdef CONFIG_PCMCIA_DEBUG
56 static int pc_debug;
57 module_param(pc_debug, int, 0644);
59 void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
60 int lvl, const char *fmt, ...)
62 struct va_format vaf;
63 va_list args;
64 if (pc_debug > lvl) {
65 va_start(args, fmt);
67 vaf.fmt = fmt;
68 vaf.va = &args;
70 printk(KERN_DEBUG "skt%u: %s: %pV", skt->nr, func, &vaf);
72 va_end(args);
75 EXPORT_SYMBOL(soc_pcmcia_debug);
77 #endif
79 #define to_soc_pcmcia_socket(x) \
80 container_of(x, struct soc_pcmcia_socket, socket)
82 static unsigned short
83 calc_speed(unsigned short *spds, int num, unsigned short dflt)
85 unsigned short speed = 0;
86 int i;
88 for (i = 0; i < num; i++)
89 if (speed < spds[i])
90 speed = spds[i];
91 if (speed == 0)
92 speed = dflt;
94 return speed;
97 void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt,
98 struct soc_pcmcia_timing *timing)
100 timing->io =
101 calc_speed(skt->spd_io, MAX_IO_WIN, SOC_PCMCIA_IO_ACCESS);
102 timing->mem =
103 calc_speed(skt->spd_mem, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
104 timing->attr =
105 calc_speed(skt->spd_attr, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
107 EXPORT_SYMBOL(soc_common_pcmcia_get_timing);
109 static void __soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt,
110 unsigned int nr)
112 unsigned int i;
114 for (i = 0; i < nr; i++) {
115 if (skt->stat[i].irq)
116 free_irq(skt->stat[i].irq, skt);
117 if (gpio_is_valid(skt->stat[i].gpio))
118 gpio_free(skt->stat[i].gpio);
121 if (skt->ops->hw_shutdown)
122 skt->ops->hw_shutdown(skt);
125 static void soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
127 __soc_pcmcia_hw_shutdown(skt, ARRAY_SIZE(skt->stat));
130 static int soc_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
132 int ret = 0, i;
134 if (skt->ops->hw_init) {
135 ret = skt->ops->hw_init(skt);
136 if (ret)
137 return ret;
140 for (i = 0; i < ARRAY_SIZE(skt->stat); i++) {
141 if (gpio_is_valid(skt->stat[i].gpio)) {
142 int irq;
144 ret = gpio_request_one(skt->stat[i].gpio, GPIOF_IN,
145 skt->stat[i].name);
146 if (ret) {
147 __soc_pcmcia_hw_shutdown(skt, i);
148 return ret;
151 irq = gpio_to_irq(skt->stat[i].gpio);
153 if (i == SOC_STAT_RDY)
154 skt->socket.pci_irq = irq;
155 else
156 skt->stat[i].irq = irq;
159 if (skt->stat[i].irq) {
160 ret = request_irq(skt->stat[i].irq,
161 soc_common_pcmcia_interrupt,
162 IRQF_TRIGGER_NONE,
163 skt->stat[i].name, skt);
164 if (ret) {
165 if (gpio_is_valid(skt->stat[i].gpio))
166 gpio_free(skt->stat[i].gpio);
167 __soc_pcmcia_hw_shutdown(skt, i);
168 return ret;
173 return ret;
176 static void soc_pcmcia_hw_enable(struct soc_pcmcia_socket *skt)
178 int i;
180 for (i = 0; i < ARRAY_SIZE(skt->stat); i++)
181 if (skt->stat[i].irq) {
182 irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_EDGE_RISING);
183 irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_EDGE_BOTH);
187 static void soc_pcmcia_hw_disable(struct soc_pcmcia_socket *skt)
189 int i;
191 for (i = 0; i < ARRAY_SIZE(skt->stat); i++)
192 if (skt->stat[i].irq)
193 irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_NONE);
196 static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt)
198 struct pcmcia_state state;
199 unsigned int stat;
201 memset(&state, 0, sizeof(struct pcmcia_state));
203 /* Make battery voltage state report 'good' */
204 state.bvd1 = 1;
205 state.bvd2 = 1;
207 /* CD is active low by default */
208 if (gpio_is_valid(skt->stat[SOC_STAT_CD].gpio))
209 state.detect = !gpio_get_value(skt->stat[SOC_STAT_CD].gpio);
211 /* RDY and BVD are active high by default */
212 if (gpio_is_valid(skt->stat[SOC_STAT_RDY].gpio))
213 state.ready = !!gpio_get_value(skt->stat[SOC_STAT_RDY].gpio);
214 if (gpio_is_valid(skt->stat[SOC_STAT_BVD1].gpio))
215 state.bvd1 = !!gpio_get_value(skt->stat[SOC_STAT_BVD1].gpio);
216 if (gpio_is_valid(skt->stat[SOC_STAT_BVD2].gpio))
217 state.bvd2 = !!gpio_get_value(skt->stat[SOC_STAT_BVD2].gpio);
219 skt->ops->socket_state(skt, &state);
221 stat = state.detect ? SS_DETECT : 0;
222 stat |= state.ready ? SS_READY : 0;
223 stat |= state.wrprot ? SS_WRPROT : 0;
224 stat |= state.vs_3v ? SS_3VCARD : 0;
225 stat |= state.vs_Xv ? SS_XVCARD : 0;
227 /* The power status of individual sockets is not available
228 * explicitly from the hardware, so we just remember the state
229 * and regurgitate it upon request:
231 stat |= skt->cs_state.Vcc ? SS_POWERON : 0;
233 if (skt->cs_state.flags & SS_IOCARD)
234 stat |= state.bvd1 ? SS_STSCHG : 0;
235 else {
236 if (state.bvd1 == 0)
237 stat |= SS_BATDEAD;
238 else if (state.bvd2 == 0)
239 stat |= SS_BATWARN;
241 return stat;
245 * soc_common_pcmcia_config_skt
246 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
248 * Convert PCMCIA socket state to our socket configure structure.
250 static int soc_common_pcmcia_config_skt(
251 struct soc_pcmcia_socket *skt, socket_state_t *state)
253 int ret;
255 ret = skt->ops->configure_socket(skt, state);
256 if (ret == 0) {
258 * This really needs a better solution. The IRQ
259 * may or may not be claimed by the driver.
261 if (skt->irq_state != 1 && state->io_irq) {
262 skt->irq_state = 1;
263 irq_set_irq_type(skt->socket.pci_irq,
264 IRQ_TYPE_EDGE_FALLING);
265 } else if (skt->irq_state == 1 && state->io_irq == 0) {
266 skt->irq_state = 0;
267 irq_set_irq_type(skt->socket.pci_irq, IRQ_TYPE_NONE);
270 skt->cs_state = *state;
273 if (ret < 0)
274 printk(KERN_ERR "soc_common_pcmcia: unable to configure "
275 "socket %d\n", skt->nr);
277 return ret;
280 /* soc_common_pcmcia_sock_init()
281 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
283 * (Re-)Initialise the socket, turning on status interrupts
284 * and PCMCIA bus. This must wait for power to stabilise
285 * so that the card status signals report correctly.
287 * Returns: 0
289 static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock)
291 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
293 debug(skt, 2, "initializing socket\n");
294 if (skt->ops->socket_init)
295 skt->ops->socket_init(skt);
296 soc_pcmcia_hw_enable(skt);
297 return 0;
302 * soc_common_pcmcia_suspend()
303 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
305 * Remove power on the socket, disable IRQs from the card.
306 * Turn off status interrupts, and disable the PCMCIA bus.
308 * Returns: 0
310 static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock)
312 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
314 debug(skt, 2, "suspending socket\n");
316 soc_pcmcia_hw_disable(skt);
317 if (skt->ops->socket_suspend)
318 skt->ops->socket_suspend(skt);
320 return 0;
323 static DEFINE_SPINLOCK(status_lock);
325 static void soc_common_check_status(struct soc_pcmcia_socket *skt)
327 unsigned int events;
329 debug(skt, 4, "entering PCMCIA monitoring thread\n");
331 do {
332 unsigned int status;
333 unsigned long flags;
335 status = soc_common_pcmcia_skt_state(skt);
337 spin_lock_irqsave(&status_lock, flags);
338 events = (status ^ skt->status) & skt->cs_state.csc_mask;
339 skt->status = status;
340 spin_unlock_irqrestore(&status_lock, flags);
342 debug(skt, 4, "events: %s%s%s%s%s%s\n",
343 events == 0 ? "<NONE>" : "",
344 events & SS_DETECT ? "DETECT " : "",
345 events & SS_READY ? "READY " : "",
346 events & SS_BATDEAD ? "BATDEAD " : "",
347 events & SS_BATWARN ? "BATWARN " : "",
348 events & SS_STSCHG ? "STSCHG " : "");
350 if (events)
351 pcmcia_parse_events(&skt->socket, events);
352 } while (events);
355 /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */
356 static void soc_common_pcmcia_poll_event(unsigned long dummy)
358 struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy;
359 debug(skt, 4, "polling for events\n");
361 mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD);
363 soc_common_check_status(skt);
368 * Service routine for socket driver interrupts (requested by the
369 * low-level PCMCIA init() operation via soc_common_pcmcia_thread()).
370 * The actual interrupt-servicing work is performed by
371 * soc_common_pcmcia_thread(), largely because the Card Services event-
372 * handling code performs scheduling operations which cannot be
373 * executed from within an interrupt context.
375 static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev)
377 struct soc_pcmcia_socket *skt = dev;
379 debug(skt, 3, "servicing IRQ %d\n", irq);
381 soc_common_check_status(skt);
383 return IRQ_HANDLED;
388 * Implements the get_status() operation for the in-kernel PCMCIA
389 * service (formerly SS_GetStatus in Card Services). Essentially just
390 * fills in bits in `status' according to internal driver state or
391 * the value of the voltage detect chipselect register.
393 * As a debugging note, during card startup, the PCMCIA core issues
394 * three set_socket() commands in a row the first with RESET deasserted,
395 * the second with RESET asserted, and the last with RESET deasserted
396 * again. Following the third set_socket(), a get_status() command will
397 * be issued. The kernel is looking for the SS_READY flag (see
398 * setup_socket(), reset_socket(), and unreset_socket() in cs.c).
400 * Returns: 0
402 static int
403 soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status)
405 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
407 skt->status = soc_common_pcmcia_skt_state(skt);
408 *status = skt->status;
410 return 0;
415 * Implements the set_socket() operation for the in-kernel PCMCIA
416 * service (formerly SS_SetSocket in Card Services). We more or
417 * less punt all of this work and let the kernel handle the details
418 * of power configuration, reset, &c. We also record the value of
419 * `state' in order to regurgitate it to the PCMCIA core later.
421 static int soc_common_pcmcia_set_socket(
422 struct pcmcia_socket *sock, socket_state_t *state)
424 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
426 debug(skt, 2, "mask: %s%s%s%s%s%s flags: %s%s%s%s%s%s Vcc %d Vpp %d irq %d\n",
427 (state->csc_mask == 0) ? "<NONE> " : "",
428 (state->csc_mask & SS_DETECT) ? "DETECT " : "",
429 (state->csc_mask & SS_READY) ? "READY " : "",
430 (state->csc_mask & SS_BATDEAD) ? "BATDEAD " : "",
431 (state->csc_mask & SS_BATWARN) ? "BATWARN " : "",
432 (state->csc_mask & SS_STSCHG) ? "STSCHG " : "",
433 (state->flags == 0) ? "<NONE> " : "",
434 (state->flags & SS_PWR_AUTO) ? "PWR_AUTO " : "",
435 (state->flags & SS_IOCARD) ? "IOCARD " : "",
436 (state->flags & SS_RESET) ? "RESET " : "",
437 (state->flags & SS_SPKR_ENA) ? "SPKR_ENA " : "",
438 (state->flags & SS_OUTPUT_ENA) ? "OUTPUT_ENA " : "",
439 state->Vcc, state->Vpp, state->io_irq);
441 return soc_common_pcmcia_config_skt(skt, state);
446 * Implements the set_io_map() operation for the in-kernel PCMCIA
447 * service (formerly SS_SetIOMap in Card Services). We configure
448 * the map speed as requested, but override the address ranges
449 * supplied by Card Services.
451 * Returns: 0 on success, -1 on error
453 static int soc_common_pcmcia_set_io_map(
454 struct pcmcia_socket *sock, struct pccard_io_map *map)
456 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
457 unsigned short speed = map->speed;
459 debug(skt, 2, "map %u speed %u start 0x%08llx stop 0x%08llx\n",
460 map->map, map->speed, (unsigned long long)map->start,
461 (unsigned long long)map->stop);
462 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
463 (map->flags == 0) ? "<NONE>" : "",
464 (map->flags & MAP_ACTIVE) ? "ACTIVE " : "",
465 (map->flags & MAP_16BIT) ? "16BIT " : "",
466 (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "",
467 (map->flags & MAP_0WS) ? "0WS " : "",
468 (map->flags & MAP_WRPROT) ? "WRPROT " : "",
469 (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : "",
470 (map->flags & MAP_PREFETCH) ? "PREFETCH " : "");
472 if (map->map >= MAX_IO_WIN) {
473 printk(KERN_ERR "%s(): map (%d) out of range\n", __func__,
474 map->map);
475 return -1;
478 if (map->flags & MAP_ACTIVE) {
479 if (speed == 0)
480 speed = SOC_PCMCIA_IO_ACCESS;
481 } else {
482 speed = 0;
485 skt->spd_io[map->map] = speed;
486 skt->ops->set_timing(skt);
488 if (map->stop == 1)
489 map->stop = PAGE_SIZE-1;
491 map->stop -= map->start;
492 map->stop += skt->socket.io_offset;
493 map->start = skt->socket.io_offset;
495 return 0;
500 * Implements the set_mem_map() operation for the in-kernel PCMCIA
501 * service (formerly SS_SetMemMap in Card Services). We configure
502 * the map speed as requested, but override the address ranges
503 * supplied by Card Services.
505 * Returns: 0 on success, -ERRNO on error
507 static int soc_common_pcmcia_set_mem_map(
508 struct pcmcia_socket *sock, struct pccard_mem_map *map)
510 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
511 struct resource *res;
512 unsigned short speed = map->speed;
514 debug(skt, 2, "map %u speed %u card_start %08x\n",
515 map->map, map->speed, map->card_start);
516 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
517 (map->flags == 0) ? "<NONE>" : "",
518 (map->flags & MAP_ACTIVE) ? "ACTIVE " : "",
519 (map->flags & MAP_16BIT) ? "16BIT " : "",
520 (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "",
521 (map->flags & MAP_0WS) ? "0WS " : "",
522 (map->flags & MAP_WRPROT) ? "WRPROT " : "",
523 (map->flags & MAP_ATTRIB) ? "ATTRIB " : "",
524 (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : "");
526 if (map->map >= MAX_WIN)
527 return -EINVAL;
529 if (map->flags & MAP_ACTIVE) {
530 if (speed == 0)
531 speed = 300;
532 } else {
533 speed = 0;
536 if (map->flags & MAP_ATTRIB) {
537 res = &skt->res_attr;
538 skt->spd_attr[map->map] = speed;
539 skt->spd_mem[map->map] = 0;
540 } else {
541 res = &skt->res_mem;
542 skt->spd_attr[map->map] = 0;
543 skt->spd_mem[map->map] = speed;
546 skt->ops->set_timing(skt);
548 map->static_start = res->start + map->card_start;
550 return 0;
553 struct bittbl {
554 unsigned int mask;
555 const char *name;
558 static struct bittbl status_bits[] = {
559 { SS_WRPROT, "SS_WRPROT" },
560 { SS_BATDEAD, "SS_BATDEAD" },
561 { SS_BATWARN, "SS_BATWARN" },
562 { SS_READY, "SS_READY" },
563 { SS_DETECT, "SS_DETECT" },
564 { SS_POWERON, "SS_POWERON" },
565 { SS_STSCHG, "SS_STSCHG" },
566 { SS_3VCARD, "SS_3VCARD" },
567 { SS_XVCARD, "SS_XVCARD" },
570 static struct bittbl conf_bits[] = {
571 { SS_PWR_AUTO, "SS_PWR_AUTO" },
572 { SS_IOCARD, "SS_IOCARD" },
573 { SS_RESET, "SS_RESET" },
574 { SS_DMA_MODE, "SS_DMA_MODE" },
575 { SS_SPKR_ENA, "SS_SPKR_ENA" },
576 { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" },
579 static void dump_bits(char **p, const char *prefix,
580 unsigned int val, struct bittbl *bits, int sz)
582 char *b = *p;
583 int i;
585 b += sprintf(b, "%-9s:", prefix);
586 for (i = 0; i < sz; i++)
587 if (val & bits[i].mask)
588 b += sprintf(b, " %s", bits[i].name);
589 *b++ = '\n';
590 *p = b;
594 * Implements the /sys/class/pcmcia_socket/??/status file.
596 * Returns: the number of characters added to the buffer
598 static ssize_t show_status(
599 struct device *dev, struct device_attribute *attr, char *buf)
601 struct soc_pcmcia_socket *skt =
602 container_of(dev, struct soc_pcmcia_socket, socket.dev);
603 char *p = buf;
605 p += sprintf(p, "slot : %d\n", skt->nr);
607 dump_bits(&p, "status", skt->status,
608 status_bits, ARRAY_SIZE(status_bits));
609 dump_bits(&p, "csc_mask", skt->cs_state.csc_mask,
610 status_bits, ARRAY_SIZE(status_bits));
611 dump_bits(&p, "cs_flags", skt->cs_state.flags,
612 conf_bits, ARRAY_SIZE(conf_bits));
614 p += sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc);
615 p += sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp);
616 p += sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq,
617 skt->socket.pci_irq);
618 if (skt->ops->show_timing)
619 p += skt->ops->show_timing(skt, p);
621 return p-buf;
623 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
626 static struct pccard_operations soc_common_pcmcia_operations = {
627 .init = soc_common_pcmcia_sock_init,
628 .suspend = soc_common_pcmcia_suspend,
629 .get_status = soc_common_pcmcia_get_status,
630 .set_socket = soc_common_pcmcia_set_socket,
631 .set_io_map = soc_common_pcmcia_set_io_map,
632 .set_mem_map = soc_common_pcmcia_set_mem_map,
636 static LIST_HEAD(soc_pcmcia_sockets);
637 static DEFINE_MUTEX(soc_pcmcia_sockets_lock);
639 #ifdef CONFIG_CPU_FREQ
640 static int
641 soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data)
643 struct soc_pcmcia_socket *skt;
644 struct cpufreq_freqs *freqs = data;
645 int ret = 0;
647 mutex_lock(&soc_pcmcia_sockets_lock);
648 list_for_each_entry(skt, &soc_pcmcia_sockets, node)
649 if (skt->ops->frequency_change)
650 ret += skt->ops->frequency_change(skt, val, freqs);
651 mutex_unlock(&soc_pcmcia_sockets_lock);
653 return ret;
656 static struct notifier_block soc_pcmcia_notifier_block = {
657 .notifier_call = soc_pcmcia_notifier
660 static int soc_pcmcia_cpufreq_register(void)
662 int ret;
664 ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block,
665 CPUFREQ_TRANSITION_NOTIFIER);
666 if (ret < 0)
667 printk(KERN_ERR "Unable to register CPU frequency change "
668 "notifier for PCMCIA (%d)\n", ret);
669 return ret;
671 fs_initcall(soc_pcmcia_cpufreq_register);
673 static void soc_pcmcia_cpufreq_unregister(void)
675 cpufreq_unregister_notifier(&soc_pcmcia_notifier_block,
676 CPUFREQ_TRANSITION_NOTIFIER);
678 module_exit(soc_pcmcia_cpufreq_unregister);
680 #endif
682 void soc_pcmcia_init_one(struct soc_pcmcia_socket *skt,
683 struct pcmcia_low_level *ops, struct device *dev)
685 int i;
687 skt->ops = ops;
688 skt->socket.owner = ops->owner;
689 skt->socket.dev.parent = dev;
690 skt->socket.pci_irq = NO_IRQ;
692 for (i = 0; i < ARRAY_SIZE(skt->stat); i++)
693 skt->stat[i].gpio = -EINVAL;
695 EXPORT_SYMBOL(soc_pcmcia_init_one);
697 void soc_pcmcia_remove_one(struct soc_pcmcia_socket *skt)
699 mutex_lock(&soc_pcmcia_sockets_lock);
700 del_timer_sync(&skt->poll_timer);
702 pcmcia_unregister_socket(&skt->socket);
704 soc_pcmcia_hw_shutdown(skt);
706 /* should not be required; violates some lowlevel drivers */
707 soc_common_pcmcia_config_skt(skt, &dead_socket);
709 list_del(&skt->node);
710 mutex_unlock(&soc_pcmcia_sockets_lock);
712 iounmap(skt->virt_io);
713 skt->virt_io = NULL;
714 release_resource(&skt->res_attr);
715 release_resource(&skt->res_mem);
716 release_resource(&skt->res_io);
717 release_resource(&skt->res_skt);
719 EXPORT_SYMBOL(soc_pcmcia_remove_one);
721 int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt)
723 int ret;
725 init_timer(&skt->poll_timer);
726 skt->poll_timer.function = soc_common_pcmcia_poll_event;
727 skt->poll_timer.data = (unsigned long)skt;
728 skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD;
730 ret = request_resource(&iomem_resource, &skt->res_skt);
731 if (ret)
732 goto out_err_1;
734 ret = request_resource(&skt->res_skt, &skt->res_io);
735 if (ret)
736 goto out_err_2;
738 ret = request_resource(&skt->res_skt, &skt->res_mem);
739 if (ret)
740 goto out_err_3;
742 ret = request_resource(&skt->res_skt, &skt->res_attr);
743 if (ret)
744 goto out_err_4;
746 skt->virt_io = ioremap(skt->res_io.start, 0x10000);
747 if (skt->virt_io == NULL) {
748 ret = -ENOMEM;
749 goto out_err_5;
752 mutex_lock(&soc_pcmcia_sockets_lock);
754 list_add(&skt->node, &soc_pcmcia_sockets);
757 * We initialize default socket timing here, because
758 * we are not guaranteed to see a SetIOMap operation at
759 * runtime.
761 skt->ops->set_timing(skt);
763 ret = soc_pcmcia_hw_init(skt);
764 if (ret)
765 goto out_err_6;
767 skt->socket.ops = &soc_common_pcmcia_operations;
768 skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD;
769 skt->socket.resource_ops = &pccard_static_ops;
770 skt->socket.irq_mask = 0;
771 skt->socket.map_size = PAGE_SIZE;
772 skt->socket.io_offset = (unsigned long)skt->virt_io;
774 skt->status = soc_common_pcmcia_skt_state(skt);
776 ret = pcmcia_register_socket(&skt->socket);
777 if (ret)
778 goto out_err_7;
780 add_timer(&skt->poll_timer);
782 mutex_unlock(&soc_pcmcia_sockets_lock);
784 ret = device_create_file(&skt->socket.dev, &dev_attr_status);
785 if (ret)
786 goto out_err_8;
788 return ret;
790 out_err_8:
791 mutex_lock(&soc_pcmcia_sockets_lock);
792 del_timer_sync(&skt->poll_timer);
793 pcmcia_unregister_socket(&skt->socket);
795 out_err_7:
796 soc_pcmcia_hw_shutdown(skt);
797 out_err_6:
798 list_del(&skt->node);
799 mutex_unlock(&soc_pcmcia_sockets_lock);
800 iounmap(skt->virt_io);
801 out_err_5:
802 release_resource(&skt->res_attr);
803 out_err_4:
804 release_resource(&skt->res_mem);
805 out_err_3:
806 release_resource(&skt->res_io);
807 out_err_2:
808 release_resource(&skt->res_skt);
809 out_err_1:
811 return ret;
813 EXPORT_SYMBOL(soc_pcmcia_add_one);
815 MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
816 MODULE_DESCRIPTION("Linux PCMCIA Card Services: Common SoC support");
817 MODULE_LICENSE("Dual MPL/GPL");