xfrm: Check for esn buffer len in xfrm_new_ae
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / pcmcia / soc_common.c
blob5a9a392eacdf18d1ba9de1237f11f0a3efefbf7d
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/init.h>
36 #include <linux/interrupt.h>
37 #include <linux/io.h>
38 #include <linux/irq.h>
39 #include <linux/kernel.h>
40 #include <linux/mm.h>
41 #include <linux/module.h>
42 #include <linux/moduleparam.h>
43 #include <linux/mutex.h>
44 #include <linux/spinlock.h>
45 #include <linux/timer.h>
47 #include <mach/hardware.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 struct va_format vaf;
61 va_list args;
62 if (pc_debug > lvl) {
63 va_start(args, fmt);
65 vaf.fmt = fmt;
66 vaf.va = &args;
68 printk(KERN_DEBUG "skt%u: %s: %pV", skt->nr, func, &vaf);
70 va_end(args);
73 EXPORT_SYMBOL(soc_pcmcia_debug);
75 #endif
77 #define to_soc_pcmcia_socket(x) \
78 container_of(x, struct soc_pcmcia_socket, socket)
80 static unsigned short
81 calc_speed(unsigned short *spds, int num, unsigned short dflt)
83 unsigned short speed = 0;
84 int i;
86 for (i = 0; i < num; i++)
87 if (speed < spds[i])
88 speed = spds[i];
89 if (speed == 0)
90 speed = dflt;
92 return speed;
95 void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt,
96 struct soc_pcmcia_timing *timing)
98 timing->io =
99 calc_speed(skt->spd_io, MAX_IO_WIN, SOC_PCMCIA_IO_ACCESS);
100 timing->mem =
101 calc_speed(skt->spd_mem, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
102 timing->attr =
103 calc_speed(skt->spd_attr, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
105 EXPORT_SYMBOL(soc_common_pcmcia_get_timing);
107 static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt)
109 struct pcmcia_state state;
110 unsigned int stat;
112 memset(&state, 0, sizeof(struct pcmcia_state));
114 skt->ops->socket_state(skt, &state);
116 stat = state.detect ? SS_DETECT : 0;
117 stat |= state.ready ? SS_READY : 0;
118 stat |= state.wrprot ? SS_WRPROT : 0;
119 stat |= state.vs_3v ? SS_3VCARD : 0;
120 stat |= state.vs_Xv ? SS_XVCARD : 0;
122 /* The power status of individual sockets is not available
123 * explicitly from the hardware, so we just remember the state
124 * and regurgitate it upon request:
126 stat |= skt->cs_state.Vcc ? SS_POWERON : 0;
128 if (skt->cs_state.flags & SS_IOCARD)
129 stat |= state.bvd1 ? SS_STSCHG : 0;
130 else {
131 if (state.bvd1 == 0)
132 stat |= SS_BATDEAD;
133 else if (state.bvd2 == 0)
134 stat |= SS_BATWARN;
136 return stat;
140 * soc_common_pcmcia_config_skt
141 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143 * Convert PCMCIA socket state to our socket configure structure.
145 static int soc_common_pcmcia_config_skt(
146 struct soc_pcmcia_socket *skt, socket_state_t *state)
148 int ret;
150 ret = skt->ops->configure_socket(skt, state);
151 if (ret == 0) {
153 * This really needs a better solution. The IRQ
154 * may or may not be claimed by the driver.
156 if (skt->irq_state != 1 && state->io_irq) {
157 skt->irq_state = 1;
158 set_irq_type(skt->socket.pci_irq,
159 IRQ_TYPE_EDGE_FALLING);
160 } else if (skt->irq_state == 1 && state->io_irq == 0) {
161 skt->irq_state = 0;
162 set_irq_type(skt->socket.pci_irq, IRQ_TYPE_NONE);
165 skt->cs_state = *state;
168 if (ret < 0)
169 printk(KERN_ERR "soc_common_pcmcia: unable to configure "
170 "socket %d\n", skt->nr);
172 return ret;
175 /* soc_common_pcmcia_sock_init()
176 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
178 * (Re-)Initialise the socket, turning on status interrupts
179 * and PCMCIA bus. This must wait for power to stabilise
180 * so that the card status signals report correctly.
182 * Returns: 0
184 static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock)
186 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
188 debug(skt, 2, "initializing socket\n");
190 skt->ops->socket_init(skt);
191 return 0;
196 * soc_common_pcmcia_suspend()
197 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
199 * Remove power on the socket, disable IRQs from the card.
200 * Turn off status interrupts, and disable the PCMCIA bus.
202 * Returns: 0
204 static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock)
206 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
208 debug(skt, 2, "suspending socket\n");
210 skt->ops->socket_suspend(skt);
212 return 0;
215 static DEFINE_SPINLOCK(status_lock);
217 static void soc_common_check_status(struct soc_pcmcia_socket *skt)
219 unsigned int events;
221 debug(skt, 4, "entering PCMCIA monitoring thread\n");
223 do {
224 unsigned int status;
225 unsigned long flags;
227 status = soc_common_pcmcia_skt_state(skt);
229 spin_lock_irqsave(&status_lock, flags);
230 events = (status ^ skt->status) & skt->cs_state.csc_mask;
231 skt->status = status;
232 spin_unlock_irqrestore(&status_lock, flags);
234 debug(skt, 4, "events: %s%s%s%s%s%s\n",
235 events == 0 ? "<NONE>" : "",
236 events & SS_DETECT ? "DETECT " : "",
237 events & SS_READY ? "READY " : "",
238 events & SS_BATDEAD ? "BATDEAD " : "",
239 events & SS_BATWARN ? "BATWARN " : "",
240 events & SS_STSCHG ? "STSCHG " : "");
242 if (events)
243 pcmcia_parse_events(&skt->socket, events);
244 } while (events);
247 /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */
248 static void soc_common_pcmcia_poll_event(unsigned long dummy)
250 struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy;
251 debug(skt, 4, "polling for events\n");
253 mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD);
255 soc_common_check_status(skt);
260 * Service routine for socket driver interrupts (requested by the
261 * low-level PCMCIA init() operation via soc_common_pcmcia_thread()).
262 * The actual interrupt-servicing work is performed by
263 * soc_common_pcmcia_thread(), largely because the Card Services event-
264 * handling code performs scheduling operations which cannot be
265 * executed from within an interrupt context.
267 static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev)
269 struct soc_pcmcia_socket *skt = dev;
271 debug(skt, 3, "servicing IRQ %d\n", irq);
273 soc_common_check_status(skt);
275 return IRQ_HANDLED;
280 * Implements the get_status() operation for the in-kernel PCMCIA
281 * service (formerly SS_GetStatus in Card Services). Essentially just
282 * fills in bits in `status' according to internal driver state or
283 * the value of the voltage detect chipselect register.
285 * As a debugging note, during card startup, the PCMCIA core issues
286 * three set_socket() commands in a row the first with RESET deasserted,
287 * the second with RESET asserted, and the last with RESET deasserted
288 * again. Following the third set_socket(), a get_status() command will
289 * be issued. The kernel is looking for the SS_READY flag (see
290 * setup_socket(), reset_socket(), and unreset_socket() in cs.c).
292 * Returns: 0
294 static int
295 soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status)
297 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
299 skt->status = soc_common_pcmcia_skt_state(skt);
300 *status = skt->status;
302 return 0;
307 * Implements the set_socket() operation for the in-kernel PCMCIA
308 * service (formerly SS_SetSocket in Card Services). We more or
309 * less punt all of this work and let the kernel handle the details
310 * of power configuration, reset, &c. We also record the value of
311 * `state' in order to regurgitate it to the PCMCIA core later.
313 static int soc_common_pcmcia_set_socket(
314 struct pcmcia_socket *sock, socket_state_t *state)
316 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
318 debug(skt, 2, "mask: %s%s%s%s%s%s flags: %s%s%s%s%s%s Vcc %d Vpp %d irq %d\n",
319 (state->csc_mask == 0) ? "<NONE> " : "",
320 (state->csc_mask & SS_DETECT) ? "DETECT " : "",
321 (state->csc_mask & SS_READY) ? "READY " : "",
322 (state->csc_mask & SS_BATDEAD) ? "BATDEAD " : "",
323 (state->csc_mask & SS_BATWARN) ? "BATWARN " : "",
324 (state->csc_mask & SS_STSCHG) ? "STSCHG " : "",
325 (state->flags == 0) ? "<NONE> " : "",
326 (state->flags & SS_PWR_AUTO) ? "PWR_AUTO " : "",
327 (state->flags & SS_IOCARD) ? "IOCARD " : "",
328 (state->flags & SS_RESET) ? "RESET " : "",
329 (state->flags & SS_SPKR_ENA) ? "SPKR_ENA " : "",
330 (state->flags & SS_OUTPUT_ENA) ? "OUTPUT_ENA " : "",
331 state->Vcc, state->Vpp, state->io_irq);
333 return soc_common_pcmcia_config_skt(skt, state);
338 * Implements the set_io_map() operation for the in-kernel PCMCIA
339 * service (formerly SS_SetIOMap in Card Services). We configure
340 * the map speed as requested, but override the address ranges
341 * supplied by Card Services.
343 * Returns: 0 on success, -1 on error
345 static int soc_common_pcmcia_set_io_map(
346 struct pcmcia_socket *sock, struct pccard_io_map *map)
348 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
349 unsigned short speed = map->speed;
351 debug(skt, 2, "map %u speed %u start 0x%08llx stop 0x%08llx\n",
352 map->map, map->speed, (unsigned long long)map->start,
353 (unsigned long long)map->stop);
354 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
355 (map->flags == 0) ? "<NONE>" : "",
356 (map->flags & MAP_ACTIVE) ? "ACTIVE " : "",
357 (map->flags & MAP_16BIT) ? "16BIT " : "",
358 (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "",
359 (map->flags & MAP_0WS) ? "0WS " : "",
360 (map->flags & MAP_WRPROT) ? "WRPROT " : "",
361 (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : "",
362 (map->flags & MAP_PREFETCH) ? "PREFETCH " : "");
364 if (map->map >= MAX_IO_WIN) {
365 printk(KERN_ERR "%s(): map (%d) out of range\n", __func__,
366 map->map);
367 return -1;
370 if (map->flags & MAP_ACTIVE) {
371 if (speed == 0)
372 speed = SOC_PCMCIA_IO_ACCESS;
373 } else {
374 speed = 0;
377 skt->spd_io[map->map] = speed;
378 skt->ops->set_timing(skt);
380 if (map->stop == 1)
381 map->stop = PAGE_SIZE-1;
383 map->stop -= map->start;
384 map->stop += skt->socket.io_offset;
385 map->start = skt->socket.io_offset;
387 return 0;
392 * Implements the set_mem_map() operation for the in-kernel PCMCIA
393 * service (formerly SS_SetMemMap in Card Services). We configure
394 * the map speed as requested, but override the address ranges
395 * supplied by Card Services.
397 * Returns: 0 on success, -ERRNO on error
399 static int soc_common_pcmcia_set_mem_map(
400 struct pcmcia_socket *sock, struct pccard_mem_map *map)
402 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
403 struct resource *res;
404 unsigned short speed = map->speed;
406 debug(skt, 2, "map %u speed %u card_start %08x\n",
407 map->map, map->speed, map->card_start);
408 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
409 (map->flags == 0) ? "<NONE>" : "",
410 (map->flags & MAP_ACTIVE) ? "ACTIVE " : "",
411 (map->flags & MAP_16BIT) ? "16BIT " : "",
412 (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "",
413 (map->flags & MAP_0WS) ? "0WS " : "",
414 (map->flags & MAP_WRPROT) ? "WRPROT " : "",
415 (map->flags & MAP_ATTRIB) ? "ATTRIB " : "",
416 (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : "");
418 if (map->map >= MAX_WIN)
419 return -EINVAL;
421 if (map->flags & MAP_ACTIVE) {
422 if (speed == 0)
423 speed = 300;
424 } else {
425 speed = 0;
428 if (map->flags & MAP_ATTRIB) {
429 res = &skt->res_attr;
430 skt->spd_attr[map->map] = speed;
431 skt->spd_mem[map->map] = 0;
432 } else {
433 res = &skt->res_mem;
434 skt->spd_attr[map->map] = 0;
435 skt->spd_mem[map->map] = speed;
438 skt->ops->set_timing(skt);
440 map->static_start = res->start + map->card_start;
442 return 0;
445 struct bittbl {
446 unsigned int mask;
447 const char *name;
450 static struct bittbl status_bits[] = {
451 { SS_WRPROT, "SS_WRPROT" },
452 { SS_BATDEAD, "SS_BATDEAD" },
453 { SS_BATWARN, "SS_BATWARN" },
454 { SS_READY, "SS_READY" },
455 { SS_DETECT, "SS_DETECT" },
456 { SS_POWERON, "SS_POWERON" },
457 { SS_STSCHG, "SS_STSCHG" },
458 { SS_3VCARD, "SS_3VCARD" },
459 { SS_XVCARD, "SS_XVCARD" },
462 static struct bittbl conf_bits[] = {
463 { SS_PWR_AUTO, "SS_PWR_AUTO" },
464 { SS_IOCARD, "SS_IOCARD" },
465 { SS_RESET, "SS_RESET" },
466 { SS_DMA_MODE, "SS_DMA_MODE" },
467 { SS_SPKR_ENA, "SS_SPKR_ENA" },
468 { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" },
471 static void dump_bits(char **p, const char *prefix,
472 unsigned int val, struct bittbl *bits, int sz)
474 char *b = *p;
475 int i;
477 b += sprintf(b, "%-9s:", prefix);
478 for (i = 0; i < sz; i++)
479 if (val & bits[i].mask)
480 b += sprintf(b, " %s", bits[i].name);
481 *b++ = '\n';
482 *p = b;
486 * Implements the /sys/class/pcmcia_socket/??/status file.
488 * Returns: the number of characters added to the buffer
490 static ssize_t show_status(
491 struct device *dev, struct device_attribute *attr, char *buf)
493 struct soc_pcmcia_socket *skt =
494 container_of(dev, struct soc_pcmcia_socket, socket.dev);
495 char *p = buf;
497 p += sprintf(p, "slot : %d\n", skt->nr);
499 dump_bits(&p, "status", skt->status,
500 status_bits, ARRAY_SIZE(status_bits));
501 dump_bits(&p, "csc_mask", skt->cs_state.csc_mask,
502 status_bits, ARRAY_SIZE(status_bits));
503 dump_bits(&p, "cs_flags", skt->cs_state.flags,
504 conf_bits, ARRAY_SIZE(conf_bits));
506 p += sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc);
507 p += sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp);
508 p += sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq,
509 skt->socket.pci_irq);
510 if (skt->ops->show_timing)
511 p += skt->ops->show_timing(skt, p);
513 return p-buf;
515 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
518 static struct pccard_operations soc_common_pcmcia_operations = {
519 .init = soc_common_pcmcia_sock_init,
520 .suspend = soc_common_pcmcia_suspend,
521 .get_status = soc_common_pcmcia_get_status,
522 .set_socket = soc_common_pcmcia_set_socket,
523 .set_io_map = soc_common_pcmcia_set_io_map,
524 .set_mem_map = soc_common_pcmcia_set_mem_map,
528 int soc_pcmcia_request_irqs(struct soc_pcmcia_socket *skt,
529 struct pcmcia_irqs *irqs, int nr)
531 int i, res = 0;
533 for (i = 0; i < nr; i++) {
534 if (irqs[i].sock != skt->nr)
535 continue;
536 res = request_irq(irqs[i].irq, soc_common_pcmcia_interrupt,
537 IRQF_DISABLED, irqs[i].str, skt);
538 if (res)
539 break;
540 set_irq_type(irqs[i].irq, IRQ_TYPE_NONE);
543 if (res) {
544 printk(KERN_ERR "PCMCIA: request for IRQ%d failed (%d)\n",
545 irqs[i].irq, res);
547 while (i--)
548 if (irqs[i].sock == skt->nr)
549 free_irq(irqs[i].irq, skt);
551 return res;
553 EXPORT_SYMBOL(soc_pcmcia_request_irqs);
555 void soc_pcmcia_free_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 free_irq(irqs[i].irq, skt);
564 EXPORT_SYMBOL(soc_pcmcia_free_irqs);
566 void soc_pcmcia_disable_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, IRQ_TYPE_NONE);
575 EXPORT_SYMBOL(soc_pcmcia_disable_irqs);
577 void soc_pcmcia_enable_irqs(struct soc_pcmcia_socket *skt,
578 struct pcmcia_irqs *irqs, int nr)
580 int i;
582 for (i = 0; i < nr; i++)
583 if (irqs[i].sock == skt->nr) {
584 set_irq_type(irqs[i].irq, IRQ_TYPE_EDGE_RISING);
585 set_irq_type(irqs[i].irq, IRQ_TYPE_EDGE_BOTH);
588 EXPORT_SYMBOL(soc_pcmcia_enable_irqs);
591 static LIST_HEAD(soc_pcmcia_sockets);
592 static DEFINE_MUTEX(soc_pcmcia_sockets_lock);
594 #ifdef CONFIG_CPU_FREQ
595 static int
596 soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data)
598 struct soc_pcmcia_socket *skt;
599 struct cpufreq_freqs *freqs = data;
600 int ret = 0;
602 mutex_lock(&soc_pcmcia_sockets_lock);
603 list_for_each_entry(skt, &soc_pcmcia_sockets, node)
604 if (skt->ops->frequency_change)
605 ret += skt->ops->frequency_change(skt, val, freqs);
606 mutex_unlock(&soc_pcmcia_sockets_lock);
608 return ret;
611 static struct notifier_block soc_pcmcia_notifier_block = {
612 .notifier_call = soc_pcmcia_notifier
615 static int soc_pcmcia_cpufreq_register(void)
617 int ret;
619 ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block,
620 CPUFREQ_TRANSITION_NOTIFIER);
621 if (ret < 0)
622 printk(KERN_ERR "Unable to register CPU frequency change "
623 "notifier for PCMCIA (%d)\n", ret);
624 return ret;
626 fs_initcall(soc_pcmcia_cpufreq_register);
628 static void soc_pcmcia_cpufreq_unregister(void)
630 cpufreq_unregister_notifier(&soc_pcmcia_notifier_block,
631 CPUFREQ_TRANSITION_NOTIFIER);
633 module_exit(soc_pcmcia_cpufreq_unregister);
635 #endif
637 void soc_pcmcia_remove_one(struct soc_pcmcia_socket *skt)
639 mutex_lock(&soc_pcmcia_sockets_lock);
640 del_timer_sync(&skt->poll_timer);
642 pcmcia_unregister_socket(&skt->socket);
644 skt->ops->hw_shutdown(skt);
646 soc_common_pcmcia_config_skt(skt, &dead_socket);
648 list_del(&skt->node);
649 mutex_unlock(&soc_pcmcia_sockets_lock);
651 iounmap(skt->virt_io);
652 skt->virt_io = NULL;
653 release_resource(&skt->res_attr);
654 release_resource(&skt->res_mem);
655 release_resource(&skt->res_io);
656 release_resource(&skt->res_skt);
658 EXPORT_SYMBOL(soc_pcmcia_remove_one);
660 int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt)
662 int ret;
664 init_timer(&skt->poll_timer);
665 skt->poll_timer.function = soc_common_pcmcia_poll_event;
666 skt->poll_timer.data = (unsigned long)skt;
667 skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD;
669 ret = request_resource(&iomem_resource, &skt->res_skt);
670 if (ret)
671 goto out_err_1;
673 ret = request_resource(&skt->res_skt, &skt->res_io);
674 if (ret)
675 goto out_err_2;
677 ret = request_resource(&skt->res_skt, &skt->res_mem);
678 if (ret)
679 goto out_err_3;
681 ret = request_resource(&skt->res_skt, &skt->res_attr);
682 if (ret)
683 goto out_err_4;
685 skt->virt_io = ioremap(skt->res_io.start, 0x10000);
686 if (skt->virt_io == NULL) {
687 ret = -ENOMEM;
688 goto out_err_5;
691 mutex_lock(&soc_pcmcia_sockets_lock);
693 list_add(&skt->node, &soc_pcmcia_sockets);
696 * We initialize default socket timing here, because
697 * we are not guaranteed to see a SetIOMap operation at
698 * runtime.
700 skt->ops->set_timing(skt);
702 ret = skt->ops->hw_init(skt);
703 if (ret)
704 goto out_err_6;
706 skt->socket.ops = &soc_common_pcmcia_operations;
707 skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD;
708 skt->socket.resource_ops = &pccard_static_ops;
709 skt->socket.irq_mask = 0;
710 skt->socket.map_size = PAGE_SIZE;
711 skt->socket.io_offset = (unsigned long)skt->virt_io;
713 skt->status = soc_common_pcmcia_skt_state(skt);
715 ret = pcmcia_register_socket(&skt->socket);
716 if (ret)
717 goto out_err_7;
719 add_timer(&skt->poll_timer);
721 mutex_unlock(&soc_pcmcia_sockets_lock);
723 ret = device_create_file(&skt->socket.dev, &dev_attr_status);
724 if (ret)
725 goto out_err_8;
727 return ret;
729 out_err_8:
730 mutex_lock(&soc_pcmcia_sockets_lock);
731 del_timer_sync(&skt->poll_timer);
732 pcmcia_unregister_socket(&skt->socket);
734 out_err_7:
735 skt->ops->hw_shutdown(skt);
736 out_err_6:
737 list_del(&skt->node);
738 mutex_unlock(&soc_pcmcia_sockets_lock);
739 iounmap(skt->virt_io);
740 out_err_5:
741 release_resource(&skt->res_attr);
742 out_err_4:
743 release_resource(&skt->res_mem);
744 out_err_3:
745 release_resource(&skt->res_io);
746 out_err_2:
747 release_resource(&skt->res_skt);
748 out_err_1:
750 return ret;
752 EXPORT_SYMBOL(soc_pcmcia_add_one);
754 MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
755 MODULE_DESCRIPTION("Linux PCMCIA Card Services: Common SoC support");
756 MODULE_LICENSE("Dual MPL/GPL");