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>
39 #include <linux/irq.h>
40 #include <linux/kernel.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
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
, ...)
70 printk(KERN_DEBUG
"skt%u: %s: %pV", skt
->nr
, func
, &vaf
);
75 EXPORT_SYMBOL(soc_pcmcia_debug
);
79 #define to_soc_pcmcia_socket(x) \
80 container_of(x, struct soc_pcmcia_socket, socket)
83 calc_speed(unsigned short *spds
, int num
, unsigned short dflt
)
85 unsigned short speed
= 0;
88 for (i
= 0; i
< num
; i
++)
97 void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket
*skt
,
98 struct soc_pcmcia_timing
*timing
)
101 calc_speed(skt
->spd_io
, MAX_IO_WIN
, SOC_PCMCIA_IO_ACCESS
);
103 calc_speed(skt
->spd_mem
, MAX_WIN
, SOC_PCMCIA_3V_MEM_ACCESS
);
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
,
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
);
124 clk_disable_unprepare(skt
->clk
);
127 static void soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket
*skt
)
129 __soc_pcmcia_hw_shutdown(skt
, ARRAY_SIZE(skt
->stat
));
132 static int soc_pcmcia_hw_init(struct soc_pcmcia_socket
*skt
)
136 clk_prepare_enable(skt
->clk
);
138 if (skt
->ops
->hw_init
) {
139 ret
= skt
->ops
->hw_init(skt
);
144 for (i
= 0; i
< ARRAY_SIZE(skt
->stat
); i
++) {
145 if (gpio_is_valid(skt
->stat
[i
].gpio
)) {
148 ret
= gpio_request_one(skt
->stat
[i
].gpio
, GPIOF_IN
,
151 __soc_pcmcia_hw_shutdown(skt
, i
);
155 irq
= gpio_to_irq(skt
->stat
[i
].gpio
);
157 if (i
== SOC_STAT_RDY
)
158 skt
->socket
.pci_irq
= irq
;
160 skt
->stat
[i
].irq
= irq
;
163 if (skt
->stat
[i
].irq
) {
164 ret
= request_irq(skt
->stat
[i
].irq
,
165 soc_common_pcmcia_interrupt
,
167 skt
->stat
[i
].name
, skt
);
169 if (gpio_is_valid(skt
->stat
[i
].gpio
))
170 gpio_free(skt
->stat
[i
].gpio
);
171 __soc_pcmcia_hw_shutdown(skt
, i
);
180 static void soc_pcmcia_hw_enable(struct soc_pcmcia_socket
*skt
)
184 for (i
= 0; i
< ARRAY_SIZE(skt
->stat
); i
++)
185 if (skt
->stat
[i
].irq
) {
186 irq_set_irq_type(skt
->stat
[i
].irq
, IRQ_TYPE_EDGE_RISING
);
187 irq_set_irq_type(skt
->stat
[i
].irq
, IRQ_TYPE_EDGE_BOTH
);
191 static void soc_pcmcia_hw_disable(struct soc_pcmcia_socket
*skt
)
195 for (i
= 0; i
< ARRAY_SIZE(skt
->stat
); i
++)
196 if (skt
->stat
[i
].irq
)
197 irq_set_irq_type(skt
->stat
[i
].irq
, IRQ_TYPE_NONE
);
200 static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket
*skt
)
202 struct pcmcia_state state
;
205 memset(&state
, 0, sizeof(struct pcmcia_state
));
207 /* Make battery voltage state report 'good' */
211 /* CD is active low by default */
212 if (gpio_is_valid(skt
->stat
[SOC_STAT_CD
].gpio
))
213 state
.detect
= !gpio_get_value(skt
->stat
[SOC_STAT_CD
].gpio
);
215 /* RDY and BVD are active high by default */
216 if (gpio_is_valid(skt
->stat
[SOC_STAT_RDY
].gpio
))
217 state
.ready
= !!gpio_get_value(skt
->stat
[SOC_STAT_RDY
].gpio
);
218 if (gpio_is_valid(skt
->stat
[SOC_STAT_BVD1
].gpio
))
219 state
.bvd1
= !!gpio_get_value(skt
->stat
[SOC_STAT_BVD1
].gpio
);
220 if (gpio_is_valid(skt
->stat
[SOC_STAT_BVD2
].gpio
))
221 state
.bvd2
= !!gpio_get_value(skt
->stat
[SOC_STAT_BVD2
].gpio
);
223 skt
->ops
->socket_state(skt
, &state
);
225 stat
= state
.detect
? SS_DETECT
: 0;
226 stat
|= state
.ready
? SS_READY
: 0;
227 stat
|= state
.wrprot
? SS_WRPROT
: 0;
228 stat
|= state
.vs_3v
? SS_3VCARD
: 0;
229 stat
|= state
.vs_Xv
? SS_XVCARD
: 0;
231 /* The power status of individual sockets is not available
232 * explicitly from the hardware, so we just remember the state
233 * and regurgitate it upon request:
235 stat
|= skt
->cs_state
.Vcc
? SS_POWERON
: 0;
237 if (skt
->cs_state
.flags
& SS_IOCARD
)
238 stat
|= state
.bvd1
? SS_STSCHG
: 0;
242 else if (state
.bvd2
== 0)
249 * soc_common_pcmcia_config_skt
250 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
252 * Convert PCMCIA socket state to our socket configure structure.
254 static int soc_common_pcmcia_config_skt(
255 struct soc_pcmcia_socket
*skt
, socket_state_t
*state
)
259 ret
= skt
->ops
->configure_socket(skt
, state
);
262 * This really needs a better solution. The IRQ
263 * may or may not be claimed by the driver.
265 if (skt
->irq_state
!= 1 && state
->io_irq
) {
267 irq_set_irq_type(skt
->socket
.pci_irq
,
268 IRQ_TYPE_EDGE_FALLING
);
269 } else if (skt
->irq_state
== 1 && state
->io_irq
== 0) {
271 irq_set_irq_type(skt
->socket
.pci_irq
, IRQ_TYPE_NONE
);
274 skt
->cs_state
= *state
;
278 printk(KERN_ERR
"soc_common_pcmcia: unable to configure "
279 "socket %d\n", skt
->nr
);
284 /* soc_common_pcmcia_sock_init()
285 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287 * (Re-)Initialise the socket, turning on status interrupts
288 * and PCMCIA bus. This must wait for power to stabilise
289 * so that the card status signals report correctly.
293 static int soc_common_pcmcia_sock_init(struct pcmcia_socket
*sock
)
295 struct soc_pcmcia_socket
*skt
= to_soc_pcmcia_socket(sock
);
297 debug(skt
, 2, "initializing socket\n");
298 if (skt
->ops
->socket_init
)
299 skt
->ops
->socket_init(skt
);
300 soc_pcmcia_hw_enable(skt
);
306 * soc_common_pcmcia_suspend()
307 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
309 * Remove power on the socket, disable IRQs from the card.
310 * Turn off status interrupts, and disable the PCMCIA bus.
314 static int soc_common_pcmcia_suspend(struct pcmcia_socket
*sock
)
316 struct soc_pcmcia_socket
*skt
= to_soc_pcmcia_socket(sock
);
318 debug(skt
, 2, "suspending socket\n");
320 soc_pcmcia_hw_disable(skt
);
321 if (skt
->ops
->socket_suspend
)
322 skt
->ops
->socket_suspend(skt
);
327 static DEFINE_SPINLOCK(status_lock
);
329 static void soc_common_check_status(struct soc_pcmcia_socket
*skt
)
333 debug(skt
, 4, "entering PCMCIA monitoring thread\n");
339 status
= soc_common_pcmcia_skt_state(skt
);
341 spin_lock_irqsave(&status_lock
, flags
);
342 events
= (status
^ skt
->status
) & skt
->cs_state
.csc_mask
;
343 skt
->status
= status
;
344 spin_unlock_irqrestore(&status_lock
, flags
);
346 debug(skt
, 4, "events: %s%s%s%s%s%s\n",
347 events
== 0 ? "<NONE>" : "",
348 events
& SS_DETECT
? "DETECT " : "",
349 events
& SS_READY
? "READY " : "",
350 events
& SS_BATDEAD
? "BATDEAD " : "",
351 events
& SS_BATWARN
? "BATWARN " : "",
352 events
& SS_STSCHG
? "STSCHG " : "");
355 pcmcia_parse_events(&skt
->socket
, events
);
359 /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */
360 static void soc_common_pcmcia_poll_event(unsigned long dummy
)
362 struct soc_pcmcia_socket
*skt
= (struct soc_pcmcia_socket
*)dummy
;
363 debug(skt
, 4, "polling for events\n");
365 mod_timer(&skt
->poll_timer
, jiffies
+ SOC_PCMCIA_POLL_PERIOD
);
367 soc_common_check_status(skt
);
372 * Service routine for socket driver interrupts (requested by the
373 * low-level PCMCIA init() operation via soc_common_pcmcia_thread()).
374 * The actual interrupt-servicing work is performed by
375 * soc_common_pcmcia_thread(), largely because the Card Services event-
376 * handling code performs scheduling operations which cannot be
377 * executed from within an interrupt context.
379 static irqreturn_t
soc_common_pcmcia_interrupt(int irq
, void *dev
)
381 struct soc_pcmcia_socket
*skt
= dev
;
383 debug(skt
, 3, "servicing IRQ %d\n", irq
);
385 soc_common_check_status(skt
);
392 * Implements the get_status() operation for the in-kernel PCMCIA
393 * service (formerly SS_GetStatus in Card Services). Essentially just
394 * fills in bits in `status' according to internal driver state or
395 * the value of the voltage detect chipselect register.
397 * As a debugging note, during card startup, the PCMCIA core issues
398 * three set_socket() commands in a row the first with RESET deasserted,
399 * the second with RESET asserted, and the last with RESET deasserted
400 * again. Following the third set_socket(), a get_status() command will
401 * be issued. The kernel is looking for the SS_READY flag (see
402 * setup_socket(), reset_socket(), and unreset_socket() in cs.c).
407 soc_common_pcmcia_get_status(struct pcmcia_socket
*sock
, unsigned int *status
)
409 struct soc_pcmcia_socket
*skt
= to_soc_pcmcia_socket(sock
);
411 skt
->status
= soc_common_pcmcia_skt_state(skt
);
412 *status
= skt
->status
;
419 * Implements the set_socket() operation for the in-kernel PCMCIA
420 * service (formerly SS_SetSocket in Card Services). We more or
421 * less punt all of this work and let the kernel handle the details
422 * of power configuration, reset, &c. We also record the value of
423 * `state' in order to regurgitate it to the PCMCIA core later.
425 static int soc_common_pcmcia_set_socket(
426 struct pcmcia_socket
*sock
, socket_state_t
*state
)
428 struct soc_pcmcia_socket
*skt
= to_soc_pcmcia_socket(sock
);
430 debug(skt
, 2, "mask: %s%s%s%s%s%s flags: %s%s%s%s%s%s Vcc %d Vpp %d irq %d\n",
431 (state
->csc_mask
== 0) ? "<NONE> " : "",
432 (state
->csc_mask
& SS_DETECT
) ? "DETECT " : "",
433 (state
->csc_mask
& SS_READY
) ? "READY " : "",
434 (state
->csc_mask
& SS_BATDEAD
) ? "BATDEAD " : "",
435 (state
->csc_mask
& SS_BATWARN
) ? "BATWARN " : "",
436 (state
->csc_mask
& SS_STSCHG
) ? "STSCHG " : "",
437 (state
->flags
== 0) ? "<NONE> " : "",
438 (state
->flags
& SS_PWR_AUTO
) ? "PWR_AUTO " : "",
439 (state
->flags
& SS_IOCARD
) ? "IOCARD " : "",
440 (state
->flags
& SS_RESET
) ? "RESET " : "",
441 (state
->flags
& SS_SPKR_ENA
) ? "SPKR_ENA " : "",
442 (state
->flags
& SS_OUTPUT_ENA
) ? "OUTPUT_ENA " : "",
443 state
->Vcc
, state
->Vpp
, state
->io_irq
);
445 return soc_common_pcmcia_config_skt(skt
, state
);
450 * Implements the set_io_map() operation for the in-kernel PCMCIA
451 * service (formerly SS_SetIOMap in Card Services). We configure
452 * the map speed as requested, but override the address ranges
453 * supplied by Card Services.
455 * Returns: 0 on success, -1 on error
457 static int soc_common_pcmcia_set_io_map(
458 struct pcmcia_socket
*sock
, struct pccard_io_map
*map
)
460 struct soc_pcmcia_socket
*skt
= to_soc_pcmcia_socket(sock
);
461 unsigned short speed
= map
->speed
;
463 debug(skt
, 2, "map %u speed %u start 0x%08llx stop 0x%08llx\n",
464 map
->map
, map
->speed
, (unsigned long long)map
->start
,
465 (unsigned long long)map
->stop
);
466 debug(skt
, 2, "flags: %s%s%s%s%s%s%s%s\n",
467 (map
->flags
== 0) ? "<NONE>" : "",
468 (map
->flags
& MAP_ACTIVE
) ? "ACTIVE " : "",
469 (map
->flags
& MAP_16BIT
) ? "16BIT " : "",
470 (map
->flags
& MAP_AUTOSZ
) ? "AUTOSZ " : "",
471 (map
->flags
& MAP_0WS
) ? "0WS " : "",
472 (map
->flags
& MAP_WRPROT
) ? "WRPROT " : "",
473 (map
->flags
& MAP_USE_WAIT
) ? "USE_WAIT " : "",
474 (map
->flags
& MAP_PREFETCH
) ? "PREFETCH " : "");
476 if (map
->map
>= MAX_IO_WIN
) {
477 printk(KERN_ERR
"%s(): map (%d) out of range\n", __func__
,
482 if (map
->flags
& MAP_ACTIVE
) {
484 speed
= SOC_PCMCIA_IO_ACCESS
;
489 skt
->spd_io
[map
->map
] = speed
;
490 skt
->ops
->set_timing(skt
);
493 map
->stop
= PAGE_SIZE
-1;
495 map
->stop
-= map
->start
;
496 map
->stop
+= skt
->socket
.io_offset
;
497 map
->start
= skt
->socket
.io_offset
;
504 * Implements the set_mem_map() operation for the in-kernel PCMCIA
505 * service (formerly SS_SetMemMap in Card Services). We configure
506 * the map speed as requested, but override the address ranges
507 * supplied by Card Services.
509 * Returns: 0 on success, -ERRNO on error
511 static int soc_common_pcmcia_set_mem_map(
512 struct pcmcia_socket
*sock
, struct pccard_mem_map
*map
)
514 struct soc_pcmcia_socket
*skt
= to_soc_pcmcia_socket(sock
);
515 struct resource
*res
;
516 unsigned short speed
= map
->speed
;
518 debug(skt
, 2, "map %u speed %u card_start %08x\n",
519 map
->map
, map
->speed
, map
->card_start
);
520 debug(skt
, 2, "flags: %s%s%s%s%s%s%s%s\n",
521 (map
->flags
== 0) ? "<NONE>" : "",
522 (map
->flags
& MAP_ACTIVE
) ? "ACTIVE " : "",
523 (map
->flags
& MAP_16BIT
) ? "16BIT " : "",
524 (map
->flags
& MAP_AUTOSZ
) ? "AUTOSZ " : "",
525 (map
->flags
& MAP_0WS
) ? "0WS " : "",
526 (map
->flags
& MAP_WRPROT
) ? "WRPROT " : "",
527 (map
->flags
& MAP_ATTRIB
) ? "ATTRIB " : "",
528 (map
->flags
& MAP_USE_WAIT
) ? "USE_WAIT " : "");
530 if (map
->map
>= MAX_WIN
)
533 if (map
->flags
& MAP_ACTIVE
) {
540 if (map
->flags
& MAP_ATTRIB
) {
541 res
= &skt
->res_attr
;
542 skt
->spd_attr
[map
->map
] = speed
;
543 skt
->spd_mem
[map
->map
] = 0;
546 skt
->spd_attr
[map
->map
] = 0;
547 skt
->spd_mem
[map
->map
] = speed
;
550 skt
->ops
->set_timing(skt
);
552 map
->static_start
= res
->start
+ map
->card_start
;
562 static struct bittbl status_bits
[] = {
563 { SS_WRPROT
, "SS_WRPROT" },
564 { SS_BATDEAD
, "SS_BATDEAD" },
565 { SS_BATWARN
, "SS_BATWARN" },
566 { SS_READY
, "SS_READY" },
567 { SS_DETECT
, "SS_DETECT" },
568 { SS_POWERON
, "SS_POWERON" },
569 { SS_STSCHG
, "SS_STSCHG" },
570 { SS_3VCARD
, "SS_3VCARD" },
571 { SS_XVCARD
, "SS_XVCARD" },
574 static struct bittbl conf_bits
[] = {
575 { SS_PWR_AUTO
, "SS_PWR_AUTO" },
576 { SS_IOCARD
, "SS_IOCARD" },
577 { SS_RESET
, "SS_RESET" },
578 { SS_DMA_MODE
, "SS_DMA_MODE" },
579 { SS_SPKR_ENA
, "SS_SPKR_ENA" },
580 { SS_OUTPUT_ENA
, "SS_OUTPUT_ENA" },
583 static void dump_bits(char **p
, const char *prefix
,
584 unsigned int val
, struct bittbl
*bits
, int sz
)
589 b
+= sprintf(b
, "%-9s:", prefix
);
590 for (i
= 0; i
< sz
; i
++)
591 if (val
& bits
[i
].mask
)
592 b
+= sprintf(b
, " %s", bits
[i
].name
);
598 * Implements the /sys/class/pcmcia_socket/??/status file.
600 * Returns: the number of characters added to the buffer
602 static ssize_t
show_status(
603 struct device
*dev
, struct device_attribute
*attr
, char *buf
)
605 struct soc_pcmcia_socket
*skt
=
606 container_of(dev
, struct soc_pcmcia_socket
, socket
.dev
);
609 p
+= sprintf(p
, "slot : %d\n", skt
->nr
);
611 dump_bits(&p
, "status", skt
->status
,
612 status_bits
, ARRAY_SIZE(status_bits
));
613 dump_bits(&p
, "csc_mask", skt
->cs_state
.csc_mask
,
614 status_bits
, ARRAY_SIZE(status_bits
));
615 dump_bits(&p
, "cs_flags", skt
->cs_state
.flags
,
616 conf_bits
, ARRAY_SIZE(conf_bits
));
618 p
+= sprintf(p
, "Vcc : %d\n", skt
->cs_state
.Vcc
);
619 p
+= sprintf(p
, "Vpp : %d\n", skt
->cs_state
.Vpp
);
620 p
+= sprintf(p
, "IRQ : %d (%d)\n", skt
->cs_state
.io_irq
,
621 skt
->socket
.pci_irq
);
622 if (skt
->ops
->show_timing
)
623 p
+= skt
->ops
->show_timing(skt
, p
);
627 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
630 static struct pccard_operations soc_common_pcmcia_operations
= {
631 .init
= soc_common_pcmcia_sock_init
,
632 .suspend
= soc_common_pcmcia_suspend
,
633 .get_status
= soc_common_pcmcia_get_status
,
634 .set_socket
= soc_common_pcmcia_set_socket
,
635 .set_io_map
= soc_common_pcmcia_set_io_map
,
636 .set_mem_map
= soc_common_pcmcia_set_mem_map
,
640 static LIST_HEAD(soc_pcmcia_sockets
);
641 static DEFINE_MUTEX(soc_pcmcia_sockets_lock
);
643 #ifdef CONFIG_CPU_FREQ
645 soc_pcmcia_notifier(struct notifier_block
*nb
, unsigned long val
, void *data
)
647 struct soc_pcmcia_socket
*skt
;
648 struct cpufreq_freqs
*freqs
= data
;
651 mutex_lock(&soc_pcmcia_sockets_lock
);
652 list_for_each_entry(skt
, &soc_pcmcia_sockets
, node
)
653 if (skt
->ops
->frequency_change
)
654 ret
+= skt
->ops
->frequency_change(skt
, val
, freqs
);
655 mutex_unlock(&soc_pcmcia_sockets_lock
);
660 static struct notifier_block soc_pcmcia_notifier_block
= {
661 .notifier_call
= soc_pcmcia_notifier
664 static int soc_pcmcia_cpufreq_register(void)
668 ret
= cpufreq_register_notifier(&soc_pcmcia_notifier_block
,
669 CPUFREQ_TRANSITION_NOTIFIER
);
671 printk(KERN_ERR
"Unable to register CPU frequency change "
672 "notifier for PCMCIA (%d)\n", ret
);
675 fs_initcall(soc_pcmcia_cpufreq_register
);
677 static void soc_pcmcia_cpufreq_unregister(void)
679 cpufreq_unregister_notifier(&soc_pcmcia_notifier_block
,
680 CPUFREQ_TRANSITION_NOTIFIER
);
682 module_exit(soc_pcmcia_cpufreq_unregister
);
686 void soc_pcmcia_init_one(struct soc_pcmcia_socket
*skt
,
687 struct pcmcia_low_level
*ops
, struct device
*dev
)
692 skt
->socket
.owner
= ops
->owner
;
693 skt
->socket
.dev
.parent
= dev
;
694 skt
->socket
.pci_irq
= NO_IRQ
;
696 for (i
= 0; i
< ARRAY_SIZE(skt
->stat
); i
++)
697 skt
->stat
[i
].gpio
= -EINVAL
;
699 EXPORT_SYMBOL(soc_pcmcia_init_one
);
701 void soc_pcmcia_remove_one(struct soc_pcmcia_socket
*skt
)
703 mutex_lock(&soc_pcmcia_sockets_lock
);
704 del_timer_sync(&skt
->poll_timer
);
706 pcmcia_unregister_socket(&skt
->socket
);
708 soc_pcmcia_hw_shutdown(skt
);
710 /* should not be required; violates some lowlevel drivers */
711 soc_common_pcmcia_config_skt(skt
, &dead_socket
);
713 list_del(&skt
->node
);
714 mutex_unlock(&soc_pcmcia_sockets_lock
);
716 iounmap(skt
->virt_io
);
718 release_resource(&skt
->res_attr
);
719 release_resource(&skt
->res_mem
);
720 release_resource(&skt
->res_io
);
721 release_resource(&skt
->res_skt
);
723 EXPORT_SYMBOL(soc_pcmcia_remove_one
);
725 int soc_pcmcia_add_one(struct soc_pcmcia_socket
*skt
)
729 setup_timer(&skt
->poll_timer
, soc_common_pcmcia_poll_event
,
731 skt
->poll_timer
.expires
= jiffies
+ SOC_PCMCIA_POLL_PERIOD
;
733 ret
= request_resource(&iomem_resource
, &skt
->res_skt
);
737 ret
= request_resource(&skt
->res_skt
, &skt
->res_io
);
741 ret
= request_resource(&skt
->res_skt
, &skt
->res_mem
);
745 ret
= request_resource(&skt
->res_skt
, &skt
->res_attr
);
749 skt
->virt_io
= ioremap(skt
->res_io
.start
, 0x10000);
750 if (skt
->virt_io
== NULL
) {
755 mutex_lock(&soc_pcmcia_sockets_lock
);
757 list_add(&skt
->node
, &soc_pcmcia_sockets
);
760 * We initialize default socket timing here, because
761 * we are not guaranteed to see a SetIOMap operation at
764 skt
->ops
->set_timing(skt
);
766 ret
= soc_pcmcia_hw_init(skt
);
770 skt
->socket
.ops
= &soc_common_pcmcia_operations
;
771 skt
->socket
.features
= SS_CAP_STATIC_MAP
|SS_CAP_PCCARD
;
772 skt
->socket
.resource_ops
= &pccard_static_ops
;
773 skt
->socket
.irq_mask
= 0;
774 skt
->socket
.map_size
= PAGE_SIZE
;
775 skt
->socket
.io_offset
= (unsigned long)skt
->virt_io
;
777 skt
->status
= soc_common_pcmcia_skt_state(skt
);
779 ret
= pcmcia_register_socket(&skt
->socket
);
783 add_timer(&skt
->poll_timer
);
785 mutex_unlock(&soc_pcmcia_sockets_lock
);
787 ret
= device_create_file(&skt
->socket
.dev
, &dev_attr_status
);
794 mutex_lock(&soc_pcmcia_sockets_lock
);
795 del_timer_sync(&skt
->poll_timer
);
796 pcmcia_unregister_socket(&skt
->socket
);
799 soc_pcmcia_hw_shutdown(skt
);
801 list_del(&skt
->node
);
802 mutex_unlock(&soc_pcmcia_sockets_lock
);
803 iounmap(skt
->virt_io
);
805 release_resource(&skt
->res_attr
);
807 release_resource(&skt
->res_mem
);
809 release_resource(&skt
->res_io
);
811 release_resource(&skt
->res_skt
);
816 EXPORT_SYMBOL(soc_pcmcia_add_one
);
818 MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
819 MODULE_DESCRIPTION("Linux PCMCIA Card Services: Common SoC support");
820 MODULE_LICENSE("Dual MPL/GPL");