11da177e4SLinus Torvalds /*====================================================================== 21da177e4SLinus Torvalds 31da177e4SLinus Torvalds Common support code for the PCMCIA control functionality of 41da177e4SLinus Torvalds integrated SOCs like the SA-11x0 and PXA2xx microprocessors. 51da177e4SLinus Torvalds 61da177e4SLinus Torvalds The contents of this file are subject to the Mozilla Public 71da177e4SLinus Torvalds License Version 1.1 (the "License"); you may not use this file 81da177e4SLinus Torvalds except in compliance with the License. You may obtain a copy of 91da177e4SLinus Torvalds the License at http://www.mozilla.org/MPL/ 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds Software distributed under the License is distributed on an "AS 121da177e4SLinus Torvalds IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 131da177e4SLinus Torvalds implied. See the License for the specific language governing 141da177e4SLinus Torvalds rights and limitations under the License. 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds The initial developer of the original code is John G. Dorsey 171da177e4SLinus Torvalds <john+@cs.cmu.edu>. Portions created by John G. Dorsey are 181da177e4SLinus Torvalds Copyright (C) 1999 John G. Dorsey. All Rights Reserved. 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds Alternatively, the contents of this file may be used under the 211da177e4SLinus Torvalds terms of the GNU Public License version 2 (the "GPL"), in which 221da177e4SLinus Torvalds case the provisions of the GPL are applicable instead of the 231da177e4SLinus Torvalds above. If you wish to allow the use of your version of this file 241da177e4SLinus Torvalds only under the terms of the GPL and not to allow others to use 251da177e4SLinus Torvalds your version of this file under the MPL, indicate your decision 261da177e4SLinus Torvalds by deleting the provisions above and replace them with the notice 271da177e4SLinus Torvalds and other provisions required by the GPL. If you do not delete 281da177e4SLinus Torvalds the provisions above, a recipient may use your version of this 291da177e4SLinus Torvalds file under either the MPL or the GPL. 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds ======================================================================*/ 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds #include <linux/module.h> 351da177e4SLinus Torvalds #include <linux/moduleparam.h> 361da177e4SLinus Torvalds #include <linux/init.h> 371da177e4SLinus Torvalds #include <linux/kernel.h> 381da177e4SLinus Torvalds #include <linux/timer.h> 391da177e4SLinus Torvalds #include <linux/mm.h> 4023d077e2SAndrew Morton #include <linux/mutex.h> 411da177e4SLinus Torvalds #include <linux/interrupt.h> 42ff632054SThomas Gleixner #include <linux/irq.h> 431da177e4SLinus Torvalds #include <linux/spinlock.h> 441da177e4SLinus Torvalds #include <linux/cpufreq.h> 451da177e4SLinus Torvalds 46a09e64fbSRussell King #include <mach/hardware.h> 471da177e4SLinus Torvalds #include <asm/io.h> 481da177e4SLinus Torvalds #include <asm/system.h> 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds #include "soc_common.h" 511da177e4SLinus Torvalds 527d16b658SDominik Brodowski #ifdef CONFIG_PCMCIA_DEBUG 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds static int pc_debug; 551da177e4SLinus Torvalds module_param(pc_debug, int, 0644); 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func, 581da177e4SLinus Torvalds int lvl, const char *fmt, ...) 591da177e4SLinus Torvalds { 601da177e4SLinus Torvalds va_list args; 611da177e4SLinus Torvalds if (pc_debug > lvl) { 621da177e4SLinus Torvalds printk(KERN_DEBUG "skt%u: %s: ", skt->nr, func); 631da177e4SLinus Torvalds va_start(args, fmt); 644846d017SPavel Machek vprintk(fmt, args); 651da177e4SLinus Torvalds va_end(args); 661da177e4SLinus Torvalds } 671da177e4SLinus Torvalds } 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds #endif 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds #define to_soc_pcmcia_socket(x) container_of(x, struct soc_pcmcia_socket, socket) 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds static unsigned short 741da177e4SLinus Torvalds calc_speed(unsigned short *spds, int num, unsigned short dflt) 751da177e4SLinus Torvalds { 761da177e4SLinus Torvalds unsigned short speed = 0; 771da177e4SLinus Torvalds int i; 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds for (i = 0; i < num; i++) 801da177e4SLinus Torvalds if (speed < spds[i]) 811da177e4SLinus Torvalds speed = spds[i]; 821da177e4SLinus Torvalds if (speed == 0) 831da177e4SLinus Torvalds speed = dflt; 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds return speed; 861da177e4SLinus Torvalds } 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt, struct soc_pcmcia_timing *timing) 891da177e4SLinus Torvalds { 901da177e4SLinus Torvalds timing->io = calc_speed(skt->spd_io, MAX_IO_WIN, SOC_PCMCIA_IO_ACCESS); 911da177e4SLinus Torvalds timing->mem = calc_speed(skt->spd_mem, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS); 921da177e4SLinus Torvalds timing->attr = calc_speed(skt->spd_attr, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS); 931da177e4SLinus Torvalds } 941da177e4SLinus Torvalds EXPORT_SYMBOL(soc_common_pcmcia_get_timing); 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt) 971da177e4SLinus Torvalds { 981da177e4SLinus Torvalds struct pcmcia_state state; 991da177e4SLinus Torvalds unsigned int stat; 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds memset(&state, 0, sizeof(struct pcmcia_state)); 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds skt->ops->socket_state(skt, &state); 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds stat = state.detect ? SS_DETECT : 0; 1061da177e4SLinus Torvalds stat |= state.ready ? SS_READY : 0; 1071da177e4SLinus Torvalds stat |= state.wrprot ? SS_WRPROT : 0; 1081da177e4SLinus Torvalds stat |= state.vs_3v ? SS_3VCARD : 0; 1091da177e4SLinus Torvalds stat |= state.vs_Xv ? SS_XVCARD : 0; 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds /* The power status of individual sockets is not available 1121da177e4SLinus Torvalds * explicitly from the hardware, so we just remember the state 1131da177e4SLinus Torvalds * and regurgitate it upon request: 1141da177e4SLinus Torvalds */ 1151da177e4SLinus Torvalds stat |= skt->cs_state.Vcc ? SS_POWERON : 0; 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds if (skt->cs_state.flags & SS_IOCARD) 1181da177e4SLinus Torvalds stat |= state.bvd1 ? SS_STSCHG : 0; 1191da177e4SLinus Torvalds else { 1201da177e4SLinus Torvalds if (state.bvd1 == 0) 1211da177e4SLinus Torvalds stat |= SS_BATDEAD; 1221da177e4SLinus Torvalds else if (state.bvd2 == 0) 1231da177e4SLinus Torvalds stat |= SS_BATWARN; 1241da177e4SLinus Torvalds } 1251da177e4SLinus Torvalds return stat; 1261da177e4SLinus Torvalds } 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds /* 1291da177e4SLinus Torvalds * soc_common_pcmcia_config_skt 1301da177e4SLinus Torvalds * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1311da177e4SLinus Torvalds * 1321da177e4SLinus Torvalds * Convert PCMCIA socket state to our socket configure structure. 1331da177e4SLinus Torvalds */ 1341da177e4SLinus Torvalds static int 1351da177e4SLinus Torvalds soc_common_pcmcia_config_skt(struct soc_pcmcia_socket *skt, socket_state_t *state) 1361da177e4SLinus Torvalds { 1371da177e4SLinus Torvalds int ret; 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds ret = skt->ops->configure_socket(skt, state); 1401da177e4SLinus Torvalds if (ret == 0) { 1411da177e4SLinus Torvalds /* 1421da177e4SLinus Torvalds * This really needs a better solution. The IRQ 1431da177e4SLinus Torvalds * may or may not be claimed by the driver. 1441da177e4SLinus Torvalds */ 1451da177e4SLinus Torvalds if (skt->irq_state != 1 && state->io_irq) { 1461da177e4SLinus Torvalds skt->irq_state = 1; 1476cab4860SDmitry Baryshkov set_irq_type(skt->irq, IRQ_TYPE_EDGE_FALLING); 1481da177e4SLinus Torvalds } else if (skt->irq_state == 1 && state->io_irq == 0) { 1491da177e4SLinus Torvalds skt->irq_state = 0; 1506cab4860SDmitry Baryshkov set_irq_type(skt->irq, IRQ_TYPE_NONE); 1511da177e4SLinus Torvalds } 1521da177e4SLinus Torvalds 1531da177e4SLinus Torvalds skt->cs_state = *state; 1541da177e4SLinus Torvalds } 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds if (ret < 0) 1571da177e4SLinus Torvalds printk(KERN_ERR "soc_common_pcmcia: unable to configure " 1581da177e4SLinus Torvalds "socket %d\n", skt->nr); 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds return ret; 1611da177e4SLinus Torvalds } 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds /* soc_common_pcmcia_sock_init() 1641da177e4SLinus Torvalds * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1651da177e4SLinus Torvalds * 1661da177e4SLinus Torvalds * (Re-)Initialise the socket, turning on status interrupts 1671da177e4SLinus Torvalds * and PCMCIA bus. This must wait for power to stabilise 1681da177e4SLinus Torvalds * so that the card status signals report correctly. 1691da177e4SLinus Torvalds * 1701da177e4SLinus Torvalds * Returns: 0 1711da177e4SLinus Torvalds */ 1721da177e4SLinus Torvalds static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock) 1731da177e4SLinus Torvalds { 1741da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 1751da177e4SLinus Torvalds 1761da177e4SLinus Torvalds debug(skt, 2, "initializing socket\n"); 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds skt->ops->socket_init(skt); 1791da177e4SLinus Torvalds return 0; 1801da177e4SLinus Torvalds } 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds /* 1841da177e4SLinus Torvalds * soc_common_pcmcia_suspend() 1851da177e4SLinus Torvalds * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1861da177e4SLinus Torvalds * 1871da177e4SLinus Torvalds * Remove power on the socket, disable IRQs from the card. 1881da177e4SLinus Torvalds * Turn off status interrupts, and disable the PCMCIA bus. 1891da177e4SLinus Torvalds * 1901da177e4SLinus Torvalds * Returns: 0 1911da177e4SLinus Torvalds */ 1921da177e4SLinus Torvalds static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock) 1931da177e4SLinus Torvalds { 1941da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds debug(skt, 2, "suspending socket\n"); 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds skt->ops->socket_suspend(skt); 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds return 0; 2011da177e4SLinus Torvalds } 2021da177e4SLinus Torvalds 2031da177e4SLinus Torvalds static DEFINE_SPINLOCK(status_lock); 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds static void soc_common_check_status(struct soc_pcmcia_socket *skt) 2061da177e4SLinus Torvalds { 2071da177e4SLinus Torvalds unsigned int events; 2081da177e4SLinus Torvalds 2091da177e4SLinus Torvalds debug(skt, 4, "entering PCMCIA monitoring thread\n"); 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds do { 2121da177e4SLinus Torvalds unsigned int status; 2131da177e4SLinus Torvalds unsigned long flags; 2141da177e4SLinus Torvalds 2151da177e4SLinus Torvalds status = soc_common_pcmcia_skt_state(skt); 2161da177e4SLinus Torvalds 2171da177e4SLinus Torvalds spin_lock_irqsave(&status_lock, flags); 2181da177e4SLinus Torvalds events = (status ^ skt->status) & skt->cs_state.csc_mask; 2191da177e4SLinus Torvalds skt->status = status; 2201da177e4SLinus Torvalds spin_unlock_irqrestore(&status_lock, flags); 2211da177e4SLinus Torvalds 2221da177e4SLinus Torvalds debug(skt, 4, "events: %s%s%s%s%s%s\n", 2231da177e4SLinus Torvalds events == 0 ? "<NONE>" : "", 2241da177e4SLinus Torvalds events & SS_DETECT ? "DETECT " : "", 2251da177e4SLinus Torvalds events & SS_READY ? "READY " : "", 2261da177e4SLinus Torvalds events & SS_BATDEAD ? "BATDEAD " : "", 2271da177e4SLinus Torvalds events & SS_BATWARN ? "BATWARN " : "", 2281da177e4SLinus Torvalds events & SS_STSCHG ? "STSCHG " : ""); 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds if (events) 2311da177e4SLinus Torvalds pcmcia_parse_events(&skt->socket, events); 2321da177e4SLinus Torvalds } while (events); 2331da177e4SLinus Torvalds } 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */ 2361da177e4SLinus Torvalds static void soc_common_pcmcia_poll_event(unsigned long dummy) 2371da177e4SLinus Torvalds { 2381da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy; 2391da177e4SLinus Torvalds debug(skt, 4, "polling for events\n"); 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD); 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds soc_common_check_status(skt); 2441da177e4SLinus Torvalds } 2451da177e4SLinus Torvalds 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds /* 2481da177e4SLinus Torvalds * Service routine for socket driver interrupts (requested by the 2491da177e4SLinus Torvalds * low-level PCMCIA init() operation via soc_common_pcmcia_thread()). 2501da177e4SLinus Torvalds * The actual interrupt-servicing work is performed by 2511da177e4SLinus Torvalds * soc_common_pcmcia_thread(), largely because the Card Services event- 2521da177e4SLinus Torvalds * handling code performs scheduling operations which cannot be 2531da177e4SLinus Torvalds * executed from within an interrupt context. 2541da177e4SLinus Torvalds */ 2557d12e780SDavid Howells static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev) 2561da177e4SLinus Torvalds { 2571da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = dev; 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds debug(skt, 3, "servicing IRQ %d\n", irq); 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvalds soc_common_check_status(skt); 2621da177e4SLinus Torvalds 2631da177e4SLinus Torvalds return IRQ_HANDLED; 2641da177e4SLinus Torvalds } 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds /* 2681da177e4SLinus Torvalds * Implements the get_status() operation for the in-kernel PCMCIA 2691da177e4SLinus Torvalds * service (formerly SS_GetStatus in Card Services). Essentially just 2701da177e4SLinus Torvalds * fills in bits in `status' according to internal driver state or 2711da177e4SLinus Torvalds * the value of the voltage detect chipselect register. 2721da177e4SLinus Torvalds * 2731da177e4SLinus Torvalds * As a debugging note, during card startup, the PCMCIA core issues 2741da177e4SLinus Torvalds * three set_socket() commands in a row the first with RESET deasserted, 2751da177e4SLinus Torvalds * the second with RESET asserted, and the last with RESET deasserted 2761da177e4SLinus Torvalds * again. Following the third set_socket(), a get_status() command will 2771da177e4SLinus Torvalds * be issued. The kernel is looking for the SS_READY flag (see 2781da177e4SLinus Torvalds * setup_socket(), reset_socket(), and unreset_socket() in cs.c). 2791da177e4SLinus Torvalds * 2801da177e4SLinus Torvalds * Returns: 0 2811da177e4SLinus Torvalds */ 2821da177e4SLinus Torvalds static int 2831da177e4SLinus Torvalds soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status) 2841da177e4SLinus Torvalds { 2851da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 2861da177e4SLinus Torvalds 2871da177e4SLinus Torvalds skt->status = soc_common_pcmcia_skt_state(skt); 2881da177e4SLinus Torvalds *status = skt->status; 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds return 0; 2911da177e4SLinus Torvalds } 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvalds /* 2951da177e4SLinus Torvalds * Implements the set_socket() operation for the in-kernel PCMCIA 2961da177e4SLinus Torvalds * service (formerly SS_SetSocket in Card Services). We more or 2971da177e4SLinus Torvalds * less punt all of this work and let the kernel handle the details 2981da177e4SLinus Torvalds * of power configuration, reset, &c. We also record the value of 2991da177e4SLinus Torvalds * `state' in order to regurgitate it to the PCMCIA core later. 3001da177e4SLinus Torvalds */ 3011da177e4SLinus Torvalds static int 3021da177e4SLinus Torvalds soc_common_pcmcia_set_socket(struct pcmcia_socket *sock, socket_state_t *state) 3031da177e4SLinus Torvalds { 3041da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvalds debug(skt, 2, "mask: %s%s%s%s%s%sflags: %s%s%s%s%s%sVcc %d Vpp %d irq %d\n", 3071da177e4SLinus Torvalds (state->csc_mask==0)?"<NONE> ":"", 3081da177e4SLinus Torvalds (state->csc_mask&SS_DETECT)?"DETECT ":"", 3091da177e4SLinus Torvalds (state->csc_mask&SS_READY)?"READY ":"", 3101da177e4SLinus Torvalds (state->csc_mask&SS_BATDEAD)?"BATDEAD ":"", 3111da177e4SLinus Torvalds (state->csc_mask&SS_BATWARN)?"BATWARN ":"", 3121da177e4SLinus Torvalds (state->csc_mask&SS_STSCHG)?"STSCHG ":"", 3131da177e4SLinus Torvalds (state->flags==0)?"<NONE> ":"", 3141da177e4SLinus Torvalds (state->flags&SS_PWR_AUTO)?"PWR_AUTO ":"", 3151da177e4SLinus Torvalds (state->flags&SS_IOCARD)?"IOCARD ":"", 3161da177e4SLinus Torvalds (state->flags&SS_RESET)?"RESET ":"", 3171da177e4SLinus Torvalds (state->flags&SS_SPKR_ENA)?"SPKR_ENA ":"", 3181da177e4SLinus Torvalds (state->flags&SS_OUTPUT_ENA)?"OUTPUT_ENA ":"", 3191da177e4SLinus Torvalds state->Vcc, state->Vpp, state->io_irq); 3201da177e4SLinus Torvalds 3211da177e4SLinus Torvalds return soc_common_pcmcia_config_skt(skt, state); 3221da177e4SLinus Torvalds } 3231da177e4SLinus Torvalds 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvalds /* 3261da177e4SLinus Torvalds * Implements the set_io_map() operation for the in-kernel PCMCIA 3271da177e4SLinus Torvalds * service (formerly SS_SetIOMap in Card Services). We configure 3281da177e4SLinus Torvalds * the map speed as requested, but override the address ranges 3291da177e4SLinus Torvalds * supplied by Card Services. 3301da177e4SLinus Torvalds * 3311da177e4SLinus Torvalds * Returns: 0 on success, -1 on error 3321da177e4SLinus Torvalds */ 3331da177e4SLinus Torvalds static int 3341da177e4SLinus Torvalds soc_common_pcmcia_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *map) 3351da177e4SLinus Torvalds { 3361da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 3371da177e4SLinus Torvalds unsigned short speed = map->speed; 3381da177e4SLinus Torvalds 3395f784336SWolfram Sang debug(skt, 2, "map %u speed %u start 0x%08llx stop 0x%08llx\n", 3405f784336SWolfram Sang map->map, map->speed, (unsigned long long)map->start, 3415f784336SWolfram Sang (unsigned long long)map->stop); 3421da177e4SLinus Torvalds debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n", 3431da177e4SLinus Torvalds (map->flags==0)?"<NONE>":"", 3441da177e4SLinus Torvalds (map->flags&MAP_ACTIVE)?"ACTIVE ":"", 3451da177e4SLinus Torvalds (map->flags&MAP_16BIT)?"16BIT ":"", 3461da177e4SLinus Torvalds (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"", 3471da177e4SLinus Torvalds (map->flags&MAP_0WS)?"0WS ":"", 3481da177e4SLinus Torvalds (map->flags&MAP_WRPROT)?"WRPROT ":"", 3491da177e4SLinus Torvalds (map->flags&MAP_USE_WAIT)?"USE_WAIT ":"", 3501da177e4SLinus Torvalds (map->flags&MAP_PREFETCH)?"PREFETCH ":""); 3511da177e4SLinus Torvalds 3521da177e4SLinus Torvalds if (map->map >= MAX_IO_WIN) { 3532e11cb4cSHarvey Harrison printk(KERN_ERR "%s(): map (%d) out of range\n", __func__, 3541da177e4SLinus Torvalds map->map); 3551da177e4SLinus Torvalds return -1; 3561da177e4SLinus Torvalds } 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds if (map->flags & MAP_ACTIVE) { 3591da177e4SLinus Torvalds if (speed == 0) 3601da177e4SLinus Torvalds speed = SOC_PCMCIA_IO_ACCESS; 3611da177e4SLinus Torvalds } else { 3621da177e4SLinus Torvalds speed = 0; 3631da177e4SLinus Torvalds } 3641da177e4SLinus Torvalds 3651da177e4SLinus Torvalds skt->spd_io[map->map] = speed; 3661da177e4SLinus Torvalds skt->ops->set_timing(skt); 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvalds if (map->stop == 1) 3691da177e4SLinus Torvalds map->stop = PAGE_SIZE-1; 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds map->stop -= map->start; 3721da177e4SLinus Torvalds map->stop += skt->socket.io_offset; 3731da177e4SLinus Torvalds map->start = skt->socket.io_offset; 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds return 0; 3761da177e4SLinus Torvalds } 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds /* 3801da177e4SLinus Torvalds * Implements the set_mem_map() operation for the in-kernel PCMCIA 3811da177e4SLinus Torvalds * service (formerly SS_SetMemMap in Card Services). We configure 3821da177e4SLinus Torvalds * the map speed as requested, but override the address ranges 3831da177e4SLinus Torvalds * supplied by Card Services. 3841da177e4SLinus Torvalds * 3854846d017SPavel Machek * Returns: 0 on success, -ERRNO on error 3861da177e4SLinus Torvalds */ 3871da177e4SLinus Torvalds static int 3881da177e4SLinus Torvalds soc_common_pcmcia_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *map) 3891da177e4SLinus Torvalds { 3901da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 3911da177e4SLinus Torvalds struct resource *res; 3921da177e4SLinus Torvalds unsigned short speed = map->speed; 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds debug(skt, 2, "map %u speed %u card_start %08x\n", 3951da177e4SLinus Torvalds map->map, map->speed, map->card_start); 3961da177e4SLinus Torvalds debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n", 3971da177e4SLinus Torvalds (map->flags==0)?"<NONE>":"", 3981da177e4SLinus Torvalds (map->flags&MAP_ACTIVE)?"ACTIVE ":"", 3991da177e4SLinus Torvalds (map->flags&MAP_16BIT)?"16BIT ":"", 4001da177e4SLinus Torvalds (map->flags&MAP_AUTOSZ)?"AUTOSZ ":"", 4011da177e4SLinus Torvalds (map->flags&MAP_0WS)?"0WS ":"", 4021da177e4SLinus Torvalds (map->flags&MAP_WRPROT)?"WRPROT ":"", 4031da177e4SLinus Torvalds (map->flags&MAP_ATTRIB)?"ATTRIB ":"", 4041da177e4SLinus Torvalds (map->flags&MAP_USE_WAIT)?"USE_WAIT ":""); 4051da177e4SLinus Torvalds 4061da177e4SLinus Torvalds if (map->map >= MAX_WIN) 4071da177e4SLinus Torvalds return -EINVAL; 4081da177e4SLinus Torvalds 4091da177e4SLinus Torvalds if (map->flags & MAP_ACTIVE) { 4101da177e4SLinus Torvalds if (speed == 0) 4111da177e4SLinus Torvalds speed = 300; 4121da177e4SLinus Torvalds } else { 4131da177e4SLinus Torvalds speed = 0; 4141da177e4SLinus Torvalds } 4151da177e4SLinus Torvalds 4161da177e4SLinus Torvalds if (map->flags & MAP_ATTRIB) { 4171da177e4SLinus Torvalds res = &skt->res_attr; 4181da177e4SLinus Torvalds skt->spd_attr[map->map] = speed; 4191da177e4SLinus Torvalds skt->spd_mem[map->map] = 0; 4201da177e4SLinus Torvalds } else { 4211da177e4SLinus Torvalds res = &skt->res_mem; 4221da177e4SLinus Torvalds skt->spd_attr[map->map] = 0; 4231da177e4SLinus Torvalds skt->spd_mem[map->map] = speed; 4241da177e4SLinus Torvalds } 4251da177e4SLinus Torvalds 4261da177e4SLinus Torvalds skt->ops->set_timing(skt); 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds map->static_start = res->start + map->card_start; 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds return 0; 4311da177e4SLinus Torvalds } 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvalds struct bittbl { 4341da177e4SLinus Torvalds unsigned int mask; 4351da177e4SLinus Torvalds const char *name; 4361da177e4SLinus Torvalds }; 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds static struct bittbl status_bits[] = { 4391da177e4SLinus Torvalds { SS_WRPROT, "SS_WRPROT" }, 4401da177e4SLinus Torvalds { SS_BATDEAD, "SS_BATDEAD" }, 4411da177e4SLinus Torvalds { SS_BATWARN, "SS_BATWARN" }, 4421da177e4SLinus Torvalds { SS_READY, "SS_READY" }, 4431da177e4SLinus Torvalds { SS_DETECT, "SS_DETECT" }, 4441da177e4SLinus Torvalds { SS_POWERON, "SS_POWERON" }, 4451da177e4SLinus Torvalds { SS_STSCHG, "SS_STSCHG" }, 4461da177e4SLinus Torvalds { SS_3VCARD, "SS_3VCARD" }, 4471da177e4SLinus Torvalds { SS_XVCARD, "SS_XVCARD" }, 4481da177e4SLinus Torvalds }; 4491da177e4SLinus Torvalds 4501da177e4SLinus Torvalds static struct bittbl conf_bits[] = { 4511da177e4SLinus Torvalds { SS_PWR_AUTO, "SS_PWR_AUTO" }, 4521da177e4SLinus Torvalds { SS_IOCARD, "SS_IOCARD" }, 4531da177e4SLinus Torvalds { SS_RESET, "SS_RESET" }, 4541da177e4SLinus Torvalds { SS_DMA_MODE, "SS_DMA_MODE" }, 4551da177e4SLinus Torvalds { SS_SPKR_ENA, "SS_SPKR_ENA" }, 4561da177e4SLinus Torvalds { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" }, 4571da177e4SLinus Torvalds }; 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds static void 4601da177e4SLinus Torvalds dump_bits(char **p, const char *prefix, unsigned int val, struct bittbl *bits, int sz) 4611da177e4SLinus Torvalds { 4621da177e4SLinus Torvalds char *b = *p; 4631da177e4SLinus Torvalds int i; 4641da177e4SLinus Torvalds 4651da177e4SLinus Torvalds b += sprintf(b, "%-9s:", prefix); 4661da177e4SLinus Torvalds for (i = 0; i < sz; i++) 4671da177e4SLinus Torvalds if (val & bits[i].mask) 4681da177e4SLinus Torvalds b += sprintf(b, " %s", bits[i].name); 4691da177e4SLinus Torvalds *b++ = '\n'; 4701da177e4SLinus Torvalds *p = b; 4711da177e4SLinus Torvalds } 4721da177e4SLinus Torvalds 4731da177e4SLinus Torvalds /* 4741da177e4SLinus Torvalds * Implements the /sys/class/pcmcia_socket/??/status file. 4751da177e4SLinus Torvalds * 4761da177e4SLinus Torvalds * Returns: the number of characters added to the buffer 4771da177e4SLinus Torvalds */ 478e4a3c3f0SAlexey Dobriyan static ssize_t show_status(struct device *dev, struct device_attribute *attr, char *buf) 4791da177e4SLinus Torvalds { 4801da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = 48187373318SGreg Kroah-Hartman container_of(dev, struct soc_pcmcia_socket, socket.dev); 4821da177e4SLinus Torvalds char *p = buf; 4831da177e4SLinus Torvalds 4841da177e4SLinus Torvalds p+=sprintf(p, "slot : %d\n", skt->nr); 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds dump_bits(&p, "status", skt->status, 4871da177e4SLinus Torvalds status_bits, ARRAY_SIZE(status_bits)); 4881da177e4SLinus Torvalds dump_bits(&p, "csc_mask", skt->cs_state.csc_mask, 4891da177e4SLinus Torvalds status_bits, ARRAY_SIZE(status_bits)); 4901da177e4SLinus Torvalds dump_bits(&p, "cs_flags", skt->cs_state.flags, 4911da177e4SLinus Torvalds conf_bits, ARRAY_SIZE(conf_bits)); 4921da177e4SLinus Torvalds 4931da177e4SLinus Torvalds p+=sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc); 4941da177e4SLinus Torvalds p+=sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp); 4951da177e4SLinus Torvalds p+=sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq, skt->irq); 4961da177e4SLinus Torvalds if (skt->ops->show_timing) 4971da177e4SLinus Torvalds p+=skt->ops->show_timing(skt, p); 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds return p-buf; 5001da177e4SLinus Torvalds } 501e4a3c3f0SAlexey Dobriyan static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); 5021da177e4SLinus Torvalds 5031da177e4SLinus Torvalds 5041da177e4SLinus Torvalds static struct pccard_operations soc_common_pcmcia_operations = { 5051da177e4SLinus Torvalds .init = soc_common_pcmcia_sock_init, 5061da177e4SLinus Torvalds .suspend = soc_common_pcmcia_suspend, 5071da177e4SLinus Torvalds .get_status = soc_common_pcmcia_get_status, 5081da177e4SLinus Torvalds .set_socket = soc_common_pcmcia_set_socket, 5091da177e4SLinus Torvalds .set_io_map = soc_common_pcmcia_set_io_map, 5101da177e4SLinus Torvalds .set_mem_map = soc_common_pcmcia_set_mem_map, 5111da177e4SLinus Torvalds }; 5121da177e4SLinus Torvalds 5131da177e4SLinus Torvalds 5141da177e4SLinus Torvalds int soc_pcmcia_request_irqs(struct soc_pcmcia_socket *skt, 5151da177e4SLinus Torvalds struct pcmcia_irqs *irqs, int nr) 5161da177e4SLinus Torvalds { 5171da177e4SLinus Torvalds int i, res = 0; 5181da177e4SLinus Torvalds 5191da177e4SLinus Torvalds for (i = 0; i < nr; i++) { 5201da177e4SLinus Torvalds if (irqs[i].sock != skt->nr) 5211da177e4SLinus Torvalds continue; 5221da177e4SLinus Torvalds res = request_irq(irqs[i].irq, soc_common_pcmcia_interrupt, 523dace1453SThomas Gleixner IRQF_DISABLED, irqs[i].str, skt); 5241da177e4SLinus Torvalds if (res) 5251da177e4SLinus Torvalds break; 5266cab4860SDmitry Baryshkov set_irq_type(irqs[i].irq, IRQ_TYPE_NONE); 5271da177e4SLinus Torvalds } 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds if (res) { 5301da177e4SLinus Torvalds printk(KERN_ERR "PCMCIA: request for IRQ%d failed (%d)\n", 5311da177e4SLinus Torvalds irqs[i].irq, res); 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds while (i--) 5341da177e4SLinus Torvalds if (irqs[i].sock == skt->nr) 5351da177e4SLinus Torvalds free_irq(irqs[i].irq, skt); 5361da177e4SLinus Torvalds } 5371da177e4SLinus Torvalds return res; 5381da177e4SLinus Torvalds } 5391da177e4SLinus Torvalds EXPORT_SYMBOL(soc_pcmcia_request_irqs); 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds void soc_pcmcia_free_irqs(struct soc_pcmcia_socket *skt, 5421da177e4SLinus Torvalds struct pcmcia_irqs *irqs, int nr) 5431da177e4SLinus Torvalds { 5441da177e4SLinus Torvalds int i; 5451da177e4SLinus Torvalds 5461da177e4SLinus Torvalds for (i = 0; i < nr; i++) 5471da177e4SLinus Torvalds if (irqs[i].sock == skt->nr) 5481da177e4SLinus Torvalds free_irq(irqs[i].irq, skt); 5491da177e4SLinus Torvalds } 5501da177e4SLinus Torvalds EXPORT_SYMBOL(soc_pcmcia_free_irqs); 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds void soc_pcmcia_disable_irqs(struct soc_pcmcia_socket *skt, 5531da177e4SLinus Torvalds struct pcmcia_irqs *irqs, int nr) 5541da177e4SLinus Torvalds { 5551da177e4SLinus Torvalds int i; 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds for (i = 0; i < nr; i++) 5581da177e4SLinus Torvalds if (irqs[i].sock == skt->nr) 5596cab4860SDmitry Baryshkov set_irq_type(irqs[i].irq, IRQ_TYPE_NONE); 5601da177e4SLinus Torvalds } 5611da177e4SLinus Torvalds EXPORT_SYMBOL(soc_pcmcia_disable_irqs); 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds void soc_pcmcia_enable_irqs(struct soc_pcmcia_socket *skt, 5641da177e4SLinus Torvalds struct pcmcia_irqs *irqs, int nr) 5651da177e4SLinus Torvalds { 5661da177e4SLinus Torvalds int i; 5671da177e4SLinus Torvalds 5681da177e4SLinus Torvalds for (i = 0; i < nr; i++) 5691da177e4SLinus Torvalds if (irqs[i].sock == skt->nr) { 5706cab4860SDmitry Baryshkov set_irq_type(irqs[i].irq, IRQ_TYPE_EDGE_RISING); 5716cab4860SDmitry Baryshkov set_irq_type(irqs[i].irq, IRQ_TYPE_EDGE_BOTH); 5721da177e4SLinus Torvalds } 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds EXPORT_SYMBOL(soc_pcmcia_enable_irqs); 5751da177e4SLinus Torvalds 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds LIST_HEAD(soc_pcmcia_sockets); 57823d077e2SAndrew Morton static DEFINE_MUTEX(soc_pcmcia_sockets_lock); 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds #ifdef CONFIG_CPU_FREQ 5811da177e4SLinus Torvalds static int 5821da177e4SLinus Torvalds soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data) 5831da177e4SLinus Torvalds { 5841da177e4SLinus Torvalds struct soc_pcmcia_socket *skt; 5851da177e4SLinus Torvalds struct cpufreq_freqs *freqs = data; 5861da177e4SLinus Torvalds int ret = 0; 5871da177e4SLinus Torvalds 58823d077e2SAndrew Morton mutex_lock(&soc_pcmcia_sockets_lock); 5891da177e4SLinus Torvalds list_for_each_entry(skt, &soc_pcmcia_sockets, node) 5901da177e4SLinus Torvalds if ( skt->ops->frequency_change ) 5911da177e4SLinus Torvalds ret += skt->ops->frequency_change(skt, val, freqs); 59223d077e2SAndrew Morton mutex_unlock(&soc_pcmcia_sockets_lock); 5931da177e4SLinus Torvalds 5941da177e4SLinus Torvalds return ret; 5951da177e4SLinus Torvalds } 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds static struct notifier_block soc_pcmcia_notifier_block = { 5981da177e4SLinus Torvalds .notifier_call = soc_pcmcia_notifier 5991da177e4SLinus Torvalds }; 6001da177e4SLinus Torvalds 6011da177e4SLinus Torvalds static int soc_pcmcia_cpufreq_register(void) 6021da177e4SLinus Torvalds { 6031da177e4SLinus Torvalds int ret; 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block, 6061da177e4SLinus Torvalds CPUFREQ_TRANSITION_NOTIFIER); 6071da177e4SLinus Torvalds if (ret < 0) 6081da177e4SLinus Torvalds printk(KERN_ERR "Unable to register CPU frequency change " 6091da177e4SLinus Torvalds "notifier for PCMCIA (%d)\n", ret); 6101da177e4SLinus Torvalds return ret; 6111da177e4SLinus Torvalds } 612*0f767de6SRussell King - ARM Linux fs_initcall(soc_pcmcia_cpufreq_register); 6131da177e4SLinus Torvalds 6141da177e4SLinus Torvalds static void soc_pcmcia_cpufreq_unregister(void) 6151da177e4SLinus Torvalds { 6161da177e4SLinus Torvalds cpufreq_unregister_notifier(&soc_pcmcia_notifier_block, CPUFREQ_TRANSITION_NOTIFIER); 6171da177e4SLinus Torvalds } 618*0f767de6SRussell King - ARM Linux module_exit(soc_pcmcia_cpufreq_unregister); 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds #endif 6211da177e4SLinus Torvalds 622b393c696SEric Miao int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops, 623b393c696SEric Miao struct skt_dev_info *sinfo) 6241da177e4SLinus Torvalds { 6251da177e4SLinus Torvalds struct soc_pcmcia_socket *skt; 6261da177e4SLinus Torvalds int ret, i; 6271da177e4SLinus Torvalds 62823d077e2SAndrew Morton mutex_lock(&soc_pcmcia_sockets_lock); 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds /* 6311da177e4SLinus Torvalds * Initialise the per-socket structure. 6321da177e4SLinus Torvalds */ 633b393c696SEric Miao for (i = 0; i < sinfo->nskt; i++) { 6341da177e4SLinus Torvalds skt = &sinfo->skt[i]; 6351da177e4SLinus Torvalds 6361da177e4SLinus Torvalds skt->socket.ops = &soc_common_pcmcia_operations; 6371da177e4SLinus Torvalds skt->socket.owner = ops->owner; 638e4a3c3f0SAlexey Dobriyan skt->socket.dev.parent = dev; 6391da177e4SLinus Torvalds 6401da177e4SLinus Torvalds init_timer(&skt->poll_timer); 6411da177e4SLinus Torvalds skt->poll_timer.function = soc_common_pcmcia_poll_event; 6421da177e4SLinus Torvalds skt->poll_timer.data = (unsigned long)skt; 6431da177e4SLinus Torvalds skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD; 6441da177e4SLinus Torvalds 6451da177e4SLinus Torvalds skt->dev = dev; 6461da177e4SLinus Torvalds skt->ops = ops; 6471da177e4SLinus Torvalds 6481da177e4SLinus Torvalds ret = request_resource(&iomem_resource, &skt->res_skt); 6491da177e4SLinus Torvalds if (ret) 6501da177e4SLinus Torvalds goto out_err_1; 6511da177e4SLinus Torvalds 6521da177e4SLinus Torvalds ret = request_resource(&skt->res_skt, &skt->res_io); 6531da177e4SLinus Torvalds if (ret) 6541da177e4SLinus Torvalds goto out_err_2; 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds ret = request_resource(&skt->res_skt, &skt->res_mem); 6571da177e4SLinus Torvalds if (ret) 6581da177e4SLinus Torvalds goto out_err_3; 6591da177e4SLinus Torvalds 6601da177e4SLinus Torvalds ret = request_resource(&skt->res_skt, &skt->res_attr); 6611da177e4SLinus Torvalds if (ret) 6621da177e4SLinus Torvalds goto out_err_4; 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvalds skt->virt_io = ioremap(skt->res_io.start, 0x10000); 6651da177e4SLinus Torvalds if (skt->virt_io == NULL) { 6661da177e4SLinus Torvalds ret = -ENOMEM; 6671da177e4SLinus Torvalds goto out_err_5; 6681da177e4SLinus Torvalds } 6691da177e4SLinus Torvalds 6701da177e4SLinus Torvalds list_add(&skt->node, &soc_pcmcia_sockets); 6711da177e4SLinus Torvalds 6721da177e4SLinus Torvalds /* 6731da177e4SLinus Torvalds * We initialize default socket timing here, because 6741da177e4SLinus Torvalds * we are not guaranteed to see a SetIOMap operation at 6751da177e4SLinus Torvalds * runtime. 6761da177e4SLinus Torvalds */ 6771da177e4SLinus Torvalds ops->set_timing(skt); 6781da177e4SLinus Torvalds 6791da177e4SLinus Torvalds ret = ops->hw_init(skt); 6801da177e4SLinus Torvalds if (ret) 6811da177e4SLinus Torvalds goto out_err_6; 6821da177e4SLinus Torvalds 6831da177e4SLinus Torvalds skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD; 6841da177e4SLinus Torvalds skt->socket.resource_ops = &pccard_static_ops; 6851da177e4SLinus Torvalds skt->socket.irq_mask = 0; 6861da177e4SLinus Torvalds skt->socket.map_size = PAGE_SIZE; 6871da177e4SLinus Torvalds skt->socket.pci_irq = skt->irq; 6881da177e4SLinus Torvalds skt->socket.io_offset = (unsigned long)skt->virt_io; 6891da177e4SLinus Torvalds 6901da177e4SLinus Torvalds skt->status = soc_common_pcmcia_skt_state(skt); 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds ret = pcmcia_register_socket(&skt->socket); 6931da177e4SLinus Torvalds if (ret) 6941da177e4SLinus Torvalds goto out_err_7; 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds WARN_ON(skt->socket.sock != i); 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds add_timer(&skt->poll_timer); 6991da177e4SLinus Torvalds 700632480eaSJürgen Schindele ret = device_create_file(&skt->socket.dev, &dev_attr_status); 701632480eaSJürgen Schindele if (ret) 702632480eaSJürgen Schindele goto out_err_8; 7031da177e4SLinus Torvalds } 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds dev_set_drvdata(dev, sinfo); 7061da177e4SLinus Torvalds ret = 0; 7071da177e4SLinus Torvalds goto out; 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds do { 7101da177e4SLinus Torvalds skt = &sinfo->skt[i]; 7111da177e4SLinus Torvalds 712632480eaSJürgen Schindele device_remove_file(&skt->socket.dev, &dev_attr_status); 713632480eaSJürgen Schindele out_err_8: 7141da177e4SLinus Torvalds del_timer_sync(&skt->poll_timer); 7151da177e4SLinus Torvalds pcmcia_unregister_socket(&skt->socket); 7161da177e4SLinus Torvalds 7171da177e4SLinus Torvalds out_err_7: 7181da177e4SLinus Torvalds flush_scheduled_work(); 7191da177e4SLinus Torvalds 7201da177e4SLinus Torvalds ops->hw_shutdown(skt); 7211da177e4SLinus Torvalds out_err_6: 7221da177e4SLinus Torvalds list_del(&skt->node); 7231da177e4SLinus Torvalds iounmap(skt->virt_io); 7241da177e4SLinus Torvalds out_err_5: 7251da177e4SLinus Torvalds release_resource(&skt->res_attr); 7261da177e4SLinus Torvalds out_err_4: 7271da177e4SLinus Torvalds release_resource(&skt->res_mem); 7281da177e4SLinus Torvalds out_err_3: 7291da177e4SLinus Torvalds release_resource(&skt->res_io); 7301da177e4SLinus Torvalds out_err_2: 7311da177e4SLinus Torvalds release_resource(&skt->res_skt); 7321da177e4SLinus Torvalds out_err_1: 7331da177e4SLinus Torvalds i--; 7341da177e4SLinus Torvalds } while (i > 0); 7351da177e4SLinus Torvalds 7361da177e4SLinus Torvalds kfree(sinfo); 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds out: 73923d077e2SAndrew Morton mutex_unlock(&soc_pcmcia_sockets_lock); 7401da177e4SLinus Torvalds return ret; 7411da177e4SLinus Torvalds } 742*0f767de6SRussell King - ARM Linux EXPORT_SYMBOL(soc_common_drv_pcmcia_probe); 7431da177e4SLinus Torvalds 7441da177e4SLinus Torvalds int soc_common_drv_pcmcia_remove(struct device *dev) 7451da177e4SLinus Torvalds { 7461da177e4SLinus Torvalds struct skt_dev_info *sinfo = dev_get_drvdata(dev); 7471da177e4SLinus Torvalds int i; 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds dev_set_drvdata(dev, NULL); 7501da177e4SLinus Torvalds 75123d077e2SAndrew Morton mutex_lock(&soc_pcmcia_sockets_lock); 7521da177e4SLinus Torvalds for (i = 0; i < sinfo->nskt; i++) { 7531da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = &sinfo->skt[i]; 7541da177e4SLinus Torvalds 7551da177e4SLinus Torvalds del_timer_sync(&skt->poll_timer); 7561da177e4SLinus Torvalds 7571da177e4SLinus Torvalds pcmcia_unregister_socket(&skt->socket); 7581da177e4SLinus Torvalds 7591da177e4SLinus Torvalds flush_scheduled_work(); 7601da177e4SLinus Torvalds 7611da177e4SLinus Torvalds skt->ops->hw_shutdown(skt); 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds soc_common_pcmcia_config_skt(skt, &dead_socket); 7641da177e4SLinus Torvalds 7651da177e4SLinus Torvalds list_del(&skt->node); 7661da177e4SLinus Torvalds iounmap(skt->virt_io); 7671da177e4SLinus Torvalds skt->virt_io = NULL; 7681da177e4SLinus Torvalds release_resource(&skt->res_attr); 7691da177e4SLinus Torvalds release_resource(&skt->res_mem); 7701da177e4SLinus Torvalds release_resource(&skt->res_io); 7711da177e4SLinus Torvalds release_resource(&skt->res_skt); 7721da177e4SLinus Torvalds } 77323d077e2SAndrew Morton mutex_unlock(&soc_pcmcia_sockets_lock); 7741da177e4SLinus Torvalds 7751da177e4SLinus Torvalds kfree(sinfo); 7761da177e4SLinus Torvalds 7771da177e4SLinus Torvalds return 0; 7781da177e4SLinus Torvalds } 77926aaa3c2SJonathan McDowell EXPORT_SYMBOL(soc_common_drv_pcmcia_remove); 780*0f767de6SRussell King - ARM Linux 781*0f767de6SRussell King - ARM Linux MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>"); 782*0f767de6SRussell King - ARM Linux MODULE_DESCRIPTION("Linux PCMCIA Card Services: Common SoC support"); 783*0f767de6SRussell King - ARM Linux MODULE_LICENSE("Dual MPL/GPL"); 784