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 3417b38ebbSMarcelo Roberto Jimenez #include <linux/cpufreq.h> 35d9dc8787SRussell King #include <linux/gpio.h> 3645ca7536SRussell King #include <linux/gpio/consumer.h> 3717b38ebbSMarcelo Roberto Jimenez #include <linux/init.h> 3817b38ebbSMarcelo Roberto Jimenez #include <linux/interrupt.h> 3917b38ebbSMarcelo Roberto Jimenez #include <linux/io.h> 4017b38ebbSMarcelo Roberto Jimenez #include <linux/irq.h> 4117b38ebbSMarcelo Roberto Jimenez #include <linux/kernel.h> 4217b38ebbSMarcelo Roberto Jimenez #include <linux/mm.h> 431da177e4SLinus Torvalds #include <linux/module.h> 441da177e4SLinus Torvalds #include <linux/moduleparam.h> 4523d077e2SAndrew Morton #include <linux/mutex.h> 461da177e4SLinus Torvalds #include <linux/spinlock.h> 4717b38ebbSMarcelo Roberto Jimenez #include <linux/timer.h> 481da177e4SLinus Torvalds 49a09e64fbSRussell King #include <mach/hardware.h> 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds #include "soc_common.h" 521da177e4SLinus Torvalds 53d9dc8787SRussell King static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev); 54d9dc8787SRussell King 557d16b658SDominik Brodowski #ifdef CONFIG_PCMCIA_DEBUG 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds static int pc_debug; 581da177e4SLinus Torvalds module_param(pc_debug, int, 0644); 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func, 611da177e4SLinus Torvalds int lvl, const char *fmt, ...) 621da177e4SLinus Torvalds { 63106665d9SJoe Perches struct va_format vaf; 641da177e4SLinus Torvalds va_list args; 651da177e4SLinus Torvalds if (pc_debug > lvl) { 661da177e4SLinus Torvalds va_start(args, fmt); 67106665d9SJoe Perches 68106665d9SJoe Perches vaf.fmt = fmt; 69106665d9SJoe Perches vaf.va = &args; 70106665d9SJoe Perches 71106665d9SJoe Perches printk(KERN_DEBUG "skt%u: %s: %pV", skt->nr, func, &vaf); 72106665d9SJoe Perches 731da177e4SLinus Torvalds va_end(args); 741da177e4SLinus Torvalds } 751da177e4SLinus Torvalds } 76b9f515e3SMarcelo Roberto Jimenez EXPORT_SYMBOL(soc_pcmcia_debug); 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds #endif 791da177e4SLinus Torvalds 8017b38ebbSMarcelo Roberto Jimenez #define to_soc_pcmcia_socket(x) \ 8117b38ebbSMarcelo Roberto Jimenez container_of(x, struct soc_pcmcia_socket, socket) 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds static unsigned short 841da177e4SLinus Torvalds calc_speed(unsigned short *spds, int num, unsigned short dflt) 851da177e4SLinus Torvalds { 861da177e4SLinus Torvalds unsigned short speed = 0; 871da177e4SLinus Torvalds int i; 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds for (i = 0; i < num; i++) 901da177e4SLinus Torvalds if (speed < spds[i]) 911da177e4SLinus Torvalds speed = spds[i]; 921da177e4SLinus Torvalds if (speed == 0) 931da177e4SLinus Torvalds speed = dflt; 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds return speed; 961da177e4SLinus Torvalds } 971da177e4SLinus Torvalds 9817b38ebbSMarcelo Roberto Jimenez void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt, 9917b38ebbSMarcelo Roberto Jimenez struct soc_pcmcia_timing *timing) 1001da177e4SLinus Torvalds { 10117b38ebbSMarcelo Roberto Jimenez timing->io = 10217b38ebbSMarcelo Roberto Jimenez calc_speed(skt->spd_io, MAX_IO_WIN, SOC_PCMCIA_IO_ACCESS); 10317b38ebbSMarcelo Roberto Jimenez timing->mem = 10417b38ebbSMarcelo Roberto Jimenez calc_speed(skt->spd_mem, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS); 10517b38ebbSMarcelo Roberto Jimenez timing->attr = 10617b38ebbSMarcelo Roberto Jimenez calc_speed(skt->spd_attr, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS); 1071da177e4SLinus Torvalds } 1081da177e4SLinus Torvalds EXPORT_SYMBOL(soc_common_pcmcia_get_timing); 1091da177e4SLinus Torvalds 110d9dc8787SRussell King static void __soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt, 111d9dc8787SRussell King unsigned int nr) 112d9dc8787SRussell King { 113d9dc8787SRussell King unsigned int i; 114d9dc8787SRussell King 11559ecfefaSRussell King for (i = 0; i < nr; i++) 116d9dc8787SRussell King if (skt->stat[i].irq) 117d9dc8787SRussell King free_irq(skt->stat[i].irq, skt); 118d9dc8787SRussell King 119d9dc8787SRussell King if (skt->ops->hw_shutdown) 120d9dc8787SRussell King skt->ops->hw_shutdown(skt); 1210821c3bcSDmitry Eremin-Solenikov 1220821c3bcSDmitry Eremin-Solenikov clk_disable_unprepare(skt->clk); 123d9dc8787SRussell King } 124d9dc8787SRussell King 125d9dc8787SRussell King static void soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) 126d9dc8787SRussell King { 127d9dc8787SRussell King __soc_pcmcia_hw_shutdown(skt, ARRAY_SIZE(skt->stat)); 128d9dc8787SRussell King } 129d9dc8787SRussell King 13045ca7536SRussell King int soc_pcmcia_request_gpiods(struct soc_pcmcia_socket *skt) 13145ca7536SRussell King { 13245ca7536SRussell King struct device *dev = skt->socket.dev.parent; 13345ca7536SRussell King struct gpio_desc *desc; 13445ca7536SRussell King int i; 13545ca7536SRussell King 13645ca7536SRussell King for (i = 0; i < ARRAY_SIZE(skt->stat); i++) { 13745ca7536SRussell King if (!skt->stat[i].name) 13845ca7536SRussell King continue; 13945ca7536SRussell King 14045ca7536SRussell King desc = devm_gpiod_get(dev, skt->stat[i].name, GPIOD_IN); 14145ca7536SRussell King if (IS_ERR(desc)) { 14245ca7536SRussell King dev_err(dev, "Failed to get GPIO for %s: %ld\n", 14345ca7536SRussell King skt->stat[i].name, PTR_ERR(desc)); 14445ca7536SRussell King return PTR_ERR(desc); 14545ca7536SRussell King } 14645ca7536SRussell King 14745ca7536SRussell King skt->stat[i].desc = desc; 14845ca7536SRussell King } 14945ca7536SRussell King 15045ca7536SRussell King return 0; 15145ca7536SRussell King } 15245ca7536SRussell King EXPORT_SYMBOL_GPL(soc_pcmcia_request_gpiods); 15345ca7536SRussell King 154d9dc8787SRussell King static int soc_pcmcia_hw_init(struct soc_pcmcia_socket *skt) 155d9dc8787SRussell King { 156d9dc8787SRussell King int ret = 0, i; 157d9dc8787SRussell King 1580821c3bcSDmitry Eremin-Solenikov clk_prepare_enable(skt->clk); 1590821c3bcSDmitry Eremin-Solenikov 160d9dc8787SRussell King if (skt->ops->hw_init) { 161d9dc8787SRussell King ret = skt->ops->hw_init(skt); 162d9dc8787SRussell King if (ret) 163d9dc8787SRussell King return ret; 164d9dc8787SRussell King } 165d9dc8787SRussell King 166d9dc8787SRussell King for (i = 0; i < ARRAY_SIZE(skt->stat); i++) { 167d9dc8787SRussell King if (gpio_is_valid(skt->stat[i].gpio)) { 16859ecfefaSRussell King ret = devm_gpio_request_one(skt->socket.dev.parent, 16959ecfefaSRussell King skt->stat[i].gpio, GPIOF_IN, 170d9dc8787SRussell King skt->stat[i].name); 171d9dc8787SRussell King if (ret) { 172d9dc8787SRussell King __soc_pcmcia_hw_shutdown(skt, i); 173d9dc8787SRussell King return ret; 174d9dc8787SRussell King } 175d9dc8787SRussell King 17645ca7536SRussell King skt->stat[i].desc = gpio_to_desc(skt->stat[i].gpio); 17745ca7536SRussell King } 17845ca7536SRussell King 17945ca7536SRussell King if (skt->stat[i].desc) { 18045ca7536SRussell King int irq = gpiod_to_irq(skt->stat[i].desc); 181d9dc8787SRussell King 182*a4941191SRussell King if (irq > 0) { 183d9dc8787SRussell King if (i == SOC_STAT_RDY) 184d9dc8787SRussell King skt->socket.pci_irq = irq; 185d9dc8787SRussell King else 186d9dc8787SRussell King skt->stat[i].irq = irq; 187d9dc8787SRussell King } 188*a4941191SRussell King } 189d9dc8787SRussell King 190d9dc8787SRussell King if (skt->stat[i].irq) { 191d9dc8787SRussell King ret = request_irq(skt->stat[i].irq, 192d9dc8787SRussell King soc_common_pcmcia_interrupt, 193d9dc8787SRussell King IRQF_TRIGGER_NONE, 194d9dc8787SRussell King skt->stat[i].name, skt); 195d9dc8787SRussell King if (ret) { 196d9dc8787SRussell King __soc_pcmcia_hw_shutdown(skt, i); 197d9dc8787SRussell King return ret; 198d9dc8787SRussell King } 199d9dc8787SRussell King } 200d9dc8787SRussell King } 201d9dc8787SRussell King 202d9dc8787SRussell King return ret; 203d9dc8787SRussell King } 204d9dc8787SRussell King 205d9dc8787SRussell King static void soc_pcmcia_hw_enable(struct soc_pcmcia_socket *skt) 206d9dc8787SRussell King { 207d9dc8787SRussell King int i; 208d9dc8787SRussell King 209d9dc8787SRussell King for (i = 0; i < ARRAY_SIZE(skt->stat); i++) 210d9dc8787SRussell King if (skt->stat[i].irq) { 211d9dc8787SRussell King irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_EDGE_RISING); 212d9dc8787SRussell King irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_EDGE_BOTH); 213d9dc8787SRussell King } 214d9dc8787SRussell King } 215d9dc8787SRussell King 216d9dc8787SRussell King static void soc_pcmcia_hw_disable(struct soc_pcmcia_socket *skt) 217d9dc8787SRussell King { 218d9dc8787SRussell King int i; 219d9dc8787SRussell King 220d9dc8787SRussell King for (i = 0; i < ARRAY_SIZE(skt->stat); i++) 221d9dc8787SRussell King if (skt->stat[i].irq) 222d9dc8787SRussell King irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_NONE); 223d9dc8787SRussell King } 224d9dc8787SRussell King 2251da177e4SLinus Torvalds static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt) 2261da177e4SLinus Torvalds { 2271da177e4SLinus Torvalds struct pcmcia_state state; 2281da177e4SLinus Torvalds unsigned int stat; 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds memset(&state, 0, sizeof(struct pcmcia_state)); 2311da177e4SLinus Torvalds 232d9dc8787SRussell King /* Make battery voltage state report 'good' */ 233d9dc8787SRussell King state.bvd1 = 1; 234d9dc8787SRussell King state.bvd2 = 1; 235d9dc8787SRussell King 236d9dc8787SRussell King /* CD is active low by default */ 23745ca7536SRussell King if (skt->stat[SOC_STAT_CD].desc) 23845ca7536SRussell King state.detect = !gpiod_get_raw_value(skt->stat[SOC_STAT_CD].desc); 239d9dc8787SRussell King 240d9dc8787SRussell King /* RDY and BVD are active high by default */ 24145ca7536SRussell King if (skt->stat[SOC_STAT_RDY].desc) 24245ca7536SRussell King state.ready = !!gpiod_get_value(skt->stat[SOC_STAT_RDY].desc); 24345ca7536SRussell King if (skt->stat[SOC_STAT_BVD1].desc) 24445ca7536SRussell King state.bvd1 = !!gpiod_get_value(skt->stat[SOC_STAT_BVD1].desc); 24545ca7536SRussell King if (skt->stat[SOC_STAT_BVD2].desc) 24645ca7536SRussell King state.bvd2 = !!gpiod_get_value(skt->stat[SOC_STAT_BVD2].desc); 247d9dc8787SRussell King 2481da177e4SLinus Torvalds skt->ops->socket_state(skt, &state); 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds stat = state.detect ? SS_DETECT : 0; 2511da177e4SLinus Torvalds stat |= state.ready ? SS_READY : 0; 2521da177e4SLinus Torvalds stat |= state.wrprot ? SS_WRPROT : 0; 2531da177e4SLinus Torvalds stat |= state.vs_3v ? SS_3VCARD : 0; 2541da177e4SLinus Torvalds stat |= state.vs_Xv ? SS_XVCARD : 0; 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds /* The power status of individual sockets is not available 2571da177e4SLinus Torvalds * explicitly from the hardware, so we just remember the state 2581da177e4SLinus Torvalds * and regurgitate it upon request: 2591da177e4SLinus Torvalds */ 2601da177e4SLinus Torvalds stat |= skt->cs_state.Vcc ? SS_POWERON : 0; 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds if (skt->cs_state.flags & SS_IOCARD) 263a466ebd2SRussell King stat |= state.bvd1 ? 0 : SS_STSCHG; 2641da177e4SLinus Torvalds else { 2651da177e4SLinus Torvalds if (state.bvd1 == 0) 2661da177e4SLinus Torvalds stat |= SS_BATDEAD; 2671da177e4SLinus Torvalds else if (state.bvd2 == 0) 2681da177e4SLinus Torvalds stat |= SS_BATWARN; 2691da177e4SLinus Torvalds } 2701da177e4SLinus Torvalds return stat; 2711da177e4SLinus Torvalds } 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds /* 2741da177e4SLinus Torvalds * soc_common_pcmcia_config_skt 2751da177e4SLinus Torvalds * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2761da177e4SLinus Torvalds * 2771da177e4SLinus Torvalds * Convert PCMCIA socket state to our socket configure structure. 2781da177e4SLinus Torvalds */ 27917b38ebbSMarcelo Roberto Jimenez static int soc_common_pcmcia_config_skt( 28017b38ebbSMarcelo Roberto Jimenez struct soc_pcmcia_socket *skt, socket_state_t *state) 2811da177e4SLinus Torvalds { 2821da177e4SLinus Torvalds int ret; 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds ret = skt->ops->configure_socket(skt, state); 2851da177e4SLinus Torvalds if (ret == 0) { 2861da177e4SLinus Torvalds /* 2871da177e4SLinus Torvalds * This really needs a better solution. The IRQ 2881da177e4SLinus Torvalds * may or may not be claimed by the driver. 2891da177e4SLinus Torvalds */ 2901da177e4SLinus Torvalds if (skt->irq_state != 1 && state->io_irq) { 2911da177e4SLinus Torvalds skt->irq_state = 1; 292dced35aeSThomas Gleixner irq_set_irq_type(skt->socket.pci_irq, 29317b38ebbSMarcelo Roberto Jimenez IRQ_TYPE_EDGE_FALLING); 2941da177e4SLinus Torvalds } else if (skt->irq_state == 1 && state->io_irq == 0) { 2951da177e4SLinus Torvalds skt->irq_state = 0; 296dced35aeSThomas Gleixner irq_set_irq_type(skt->socket.pci_irq, IRQ_TYPE_NONE); 2971da177e4SLinus Torvalds } 2981da177e4SLinus Torvalds 2991da177e4SLinus Torvalds skt->cs_state = *state; 3001da177e4SLinus Torvalds } 3011da177e4SLinus Torvalds 3021da177e4SLinus Torvalds if (ret < 0) 3031da177e4SLinus Torvalds printk(KERN_ERR "soc_common_pcmcia: unable to configure " 3041da177e4SLinus Torvalds "socket %d\n", skt->nr); 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvalds return ret; 3071da177e4SLinus Torvalds } 3081da177e4SLinus Torvalds 3091da177e4SLinus Torvalds /* soc_common_pcmcia_sock_init() 3101da177e4SLinus Torvalds * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 3111da177e4SLinus Torvalds * 3121da177e4SLinus Torvalds * (Re-)Initialise the socket, turning on status interrupts 3131da177e4SLinus Torvalds * and PCMCIA bus. This must wait for power to stabilise 3141da177e4SLinus Torvalds * so that the card status signals report correctly. 3151da177e4SLinus Torvalds * 3161da177e4SLinus Torvalds * Returns: 0 3171da177e4SLinus Torvalds */ 3181da177e4SLinus Torvalds static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock) 3191da177e4SLinus Torvalds { 3201da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds debug(skt, 2, "initializing socket\n"); 323a747ce83SJonathan Cameron if (skt->ops->socket_init) 3241da177e4SLinus Torvalds skt->ops->socket_init(skt); 325d9dc8787SRussell King soc_pcmcia_hw_enable(skt); 3261da177e4SLinus Torvalds return 0; 3271da177e4SLinus Torvalds } 3281da177e4SLinus Torvalds 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds /* 3311da177e4SLinus Torvalds * soc_common_pcmcia_suspend() 3321da177e4SLinus Torvalds * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 3331da177e4SLinus Torvalds * 3341da177e4SLinus Torvalds * Remove power on the socket, disable IRQs from the card. 3351da177e4SLinus Torvalds * Turn off status interrupts, and disable the PCMCIA bus. 3361da177e4SLinus Torvalds * 3371da177e4SLinus Torvalds * Returns: 0 3381da177e4SLinus Torvalds */ 3391da177e4SLinus Torvalds static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock) 3401da177e4SLinus Torvalds { 3411da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 3421da177e4SLinus Torvalds 3431da177e4SLinus Torvalds debug(skt, 2, "suspending socket\n"); 3441da177e4SLinus Torvalds 345d9dc8787SRussell King soc_pcmcia_hw_disable(skt); 346a747ce83SJonathan Cameron if (skt->ops->socket_suspend) 3471da177e4SLinus Torvalds skt->ops->socket_suspend(skt); 3481da177e4SLinus Torvalds 3491da177e4SLinus Torvalds return 0; 3501da177e4SLinus Torvalds } 3511da177e4SLinus Torvalds 3521da177e4SLinus Torvalds static DEFINE_SPINLOCK(status_lock); 3531da177e4SLinus Torvalds 3541da177e4SLinus Torvalds static void soc_common_check_status(struct soc_pcmcia_socket *skt) 3551da177e4SLinus Torvalds { 3561da177e4SLinus Torvalds unsigned int events; 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds debug(skt, 4, "entering PCMCIA monitoring thread\n"); 3591da177e4SLinus Torvalds 3601da177e4SLinus Torvalds do { 3611da177e4SLinus Torvalds unsigned int status; 3621da177e4SLinus Torvalds unsigned long flags; 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds status = soc_common_pcmcia_skt_state(skt); 3651da177e4SLinus Torvalds 3661da177e4SLinus Torvalds spin_lock_irqsave(&status_lock, flags); 3671da177e4SLinus Torvalds events = (status ^ skt->status) & skt->cs_state.csc_mask; 3681da177e4SLinus Torvalds skt->status = status; 3691da177e4SLinus Torvalds spin_unlock_irqrestore(&status_lock, flags); 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds debug(skt, 4, "events: %s%s%s%s%s%s\n", 3721da177e4SLinus Torvalds events == 0 ? "<NONE>" : "", 3731da177e4SLinus Torvalds events & SS_DETECT ? "DETECT " : "", 3741da177e4SLinus Torvalds events & SS_READY ? "READY " : "", 3751da177e4SLinus Torvalds events & SS_BATDEAD ? "BATDEAD " : "", 3761da177e4SLinus Torvalds events & SS_BATWARN ? "BATWARN " : "", 3771da177e4SLinus Torvalds events & SS_STSCHG ? "STSCHG " : ""); 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds if (events) 3801da177e4SLinus Torvalds pcmcia_parse_events(&skt->socket, events); 3811da177e4SLinus Torvalds } while (events); 3821da177e4SLinus Torvalds } 3831da177e4SLinus Torvalds 3841da177e4SLinus Torvalds /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */ 3851da177e4SLinus Torvalds static void soc_common_pcmcia_poll_event(unsigned long dummy) 3861da177e4SLinus Torvalds { 3871da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy; 3881da177e4SLinus Torvalds debug(skt, 4, "polling for events\n"); 3891da177e4SLinus Torvalds 3901da177e4SLinus Torvalds mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD); 3911da177e4SLinus Torvalds 3921da177e4SLinus Torvalds soc_common_check_status(skt); 3931da177e4SLinus Torvalds } 3941da177e4SLinus Torvalds 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds /* 3971da177e4SLinus Torvalds * Service routine for socket driver interrupts (requested by the 3981da177e4SLinus Torvalds * low-level PCMCIA init() operation via soc_common_pcmcia_thread()). 3991da177e4SLinus Torvalds * The actual interrupt-servicing work is performed by 4001da177e4SLinus Torvalds * soc_common_pcmcia_thread(), largely because the Card Services event- 4011da177e4SLinus Torvalds * handling code performs scheduling operations which cannot be 4021da177e4SLinus Torvalds * executed from within an interrupt context. 4031da177e4SLinus Torvalds */ 4047d12e780SDavid Howells static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev) 4051da177e4SLinus Torvalds { 4061da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = dev; 4071da177e4SLinus Torvalds 4081da177e4SLinus Torvalds debug(skt, 3, "servicing IRQ %d\n", irq); 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds soc_common_check_status(skt); 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvalds return IRQ_HANDLED; 4131da177e4SLinus Torvalds } 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds 4161da177e4SLinus Torvalds /* 4171da177e4SLinus Torvalds * Implements the get_status() operation for the in-kernel PCMCIA 4181da177e4SLinus Torvalds * service (formerly SS_GetStatus in Card Services). Essentially just 4191da177e4SLinus Torvalds * fills in bits in `status' according to internal driver state or 4201da177e4SLinus Torvalds * the value of the voltage detect chipselect register. 4211da177e4SLinus Torvalds * 4221da177e4SLinus Torvalds * As a debugging note, during card startup, the PCMCIA core issues 4231da177e4SLinus Torvalds * three set_socket() commands in a row the first with RESET deasserted, 4241da177e4SLinus Torvalds * the second with RESET asserted, and the last with RESET deasserted 4251da177e4SLinus Torvalds * again. Following the third set_socket(), a get_status() command will 4261da177e4SLinus Torvalds * be issued. The kernel is looking for the SS_READY flag (see 4271da177e4SLinus Torvalds * setup_socket(), reset_socket(), and unreset_socket() in cs.c). 4281da177e4SLinus Torvalds * 4291da177e4SLinus Torvalds * Returns: 0 4301da177e4SLinus Torvalds */ 4311da177e4SLinus Torvalds static int 4321da177e4SLinus Torvalds soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status) 4331da177e4SLinus Torvalds { 4341da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds skt->status = soc_common_pcmcia_skt_state(skt); 4371da177e4SLinus Torvalds *status = skt->status; 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds return 0; 4401da177e4SLinus Torvalds } 4411da177e4SLinus Torvalds 4421da177e4SLinus Torvalds 4431da177e4SLinus Torvalds /* 4441da177e4SLinus Torvalds * Implements the set_socket() operation for the in-kernel PCMCIA 4451da177e4SLinus Torvalds * service (formerly SS_SetSocket in Card Services). We more or 4461da177e4SLinus Torvalds * less punt all of this work and let the kernel handle the details 4471da177e4SLinus Torvalds * of power configuration, reset, &c. We also record the value of 4481da177e4SLinus Torvalds * `state' in order to regurgitate it to the PCMCIA core later. 4491da177e4SLinus Torvalds */ 45017b38ebbSMarcelo Roberto Jimenez static int soc_common_pcmcia_set_socket( 45117b38ebbSMarcelo Roberto Jimenez struct pcmcia_socket *sock, socket_state_t *state) 4521da177e4SLinus Torvalds { 4531da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 4541da177e4SLinus Torvalds 4551da177e4SLinus Torvalds debug(skt, 2, "mask: %s%s%s%s%s%s flags: %s%s%s%s%s%s Vcc %d Vpp %d irq %d\n", 4561da177e4SLinus Torvalds (state->csc_mask == 0) ? "<NONE> " : "", 4571da177e4SLinus Torvalds (state->csc_mask & SS_DETECT) ? "DETECT " : "", 4581da177e4SLinus Torvalds (state->csc_mask & SS_READY) ? "READY " : "", 4591da177e4SLinus Torvalds (state->csc_mask & SS_BATDEAD) ? "BATDEAD " : "", 4601da177e4SLinus Torvalds (state->csc_mask & SS_BATWARN) ? "BATWARN " : "", 4611da177e4SLinus Torvalds (state->csc_mask & SS_STSCHG) ? "STSCHG " : "", 4621da177e4SLinus Torvalds (state->flags == 0) ? "<NONE> " : "", 4631da177e4SLinus Torvalds (state->flags & SS_PWR_AUTO) ? "PWR_AUTO " : "", 4641da177e4SLinus Torvalds (state->flags & SS_IOCARD) ? "IOCARD " : "", 4651da177e4SLinus Torvalds (state->flags & SS_RESET) ? "RESET " : "", 4661da177e4SLinus Torvalds (state->flags & SS_SPKR_ENA) ? "SPKR_ENA " : "", 4671da177e4SLinus Torvalds (state->flags & SS_OUTPUT_ENA) ? "OUTPUT_ENA " : "", 4681da177e4SLinus Torvalds state->Vcc, state->Vpp, state->io_irq); 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds return soc_common_pcmcia_config_skt(skt, state); 4711da177e4SLinus Torvalds } 4721da177e4SLinus Torvalds 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds /* 4751da177e4SLinus Torvalds * Implements the set_io_map() operation for the in-kernel PCMCIA 4761da177e4SLinus Torvalds * service (formerly SS_SetIOMap in Card Services). We configure 4771da177e4SLinus Torvalds * the map speed as requested, but override the address ranges 4781da177e4SLinus Torvalds * supplied by Card Services. 4791da177e4SLinus Torvalds * 4801da177e4SLinus Torvalds * Returns: 0 on success, -1 on error 4811da177e4SLinus Torvalds */ 48217b38ebbSMarcelo Roberto Jimenez static int soc_common_pcmcia_set_io_map( 48317b38ebbSMarcelo Roberto Jimenez struct pcmcia_socket *sock, struct pccard_io_map *map) 4841da177e4SLinus Torvalds { 4851da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 4861da177e4SLinus Torvalds unsigned short speed = map->speed; 4871da177e4SLinus Torvalds 4885f784336SWolfram Sang debug(skt, 2, "map %u speed %u start 0x%08llx stop 0x%08llx\n", 4895f784336SWolfram Sang map->map, map->speed, (unsigned long long)map->start, 4905f784336SWolfram Sang (unsigned long long)map->stop); 4911da177e4SLinus Torvalds debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n", 4921da177e4SLinus Torvalds (map->flags == 0) ? "<NONE>" : "", 4931da177e4SLinus Torvalds (map->flags & MAP_ACTIVE) ? "ACTIVE " : "", 4941da177e4SLinus Torvalds (map->flags & MAP_16BIT) ? "16BIT " : "", 4951da177e4SLinus Torvalds (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "", 4961da177e4SLinus Torvalds (map->flags & MAP_0WS) ? "0WS " : "", 4971da177e4SLinus Torvalds (map->flags & MAP_WRPROT) ? "WRPROT " : "", 4981da177e4SLinus Torvalds (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : "", 4991da177e4SLinus Torvalds (map->flags & MAP_PREFETCH) ? "PREFETCH " : ""); 5001da177e4SLinus Torvalds 5011da177e4SLinus Torvalds if (map->map >= MAX_IO_WIN) { 5022e11cb4cSHarvey Harrison printk(KERN_ERR "%s(): map (%d) out of range\n", __func__, 5031da177e4SLinus Torvalds map->map); 5041da177e4SLinus Torvalds return -1; 5051da177e4SLinus Torvalds } 5061da177e4SLinus Torvalds 5071da177e4SLinus Torvalds if (map->flags & MAP_ACTIVE) { 5081da177e4SLinus Torvalds if (speed == 0) 5091da177e4SLinus Torvalds speed = SOC_PCMCIA_IO_ACCESS; 5101da177e4SLinus Torvalds } else { 5111da177e4SLinus Torvalds speed = 0; 5121da177e4SLinus Torvalds } 5131da177e4SLinus Torvalds 5141da177e4SLinus Torvalds skt->spd_io[map->map] = speed; 5151da177e4SLinus Torvalds skt->ops->set_timing(skt); 5161da177e4SLinus Torvalds 5171da177e4SLinus Torvalds if (map->stop == 1) 5181da177e4SLinus Torvalds map->stop = PAGE_SIZE-1; 5191da177e4SLinus Torvalds 5201da177e4SLinus Torvalds map->stop -= map->start; 5211da177e4SLinus Torvalds map->stop += skt->socket.io_offset; 5221da177e4SLinus Torvalds map->start = skt->socket.io_offset; 5231da177e4SLinus Torvalds 5241da177e4SLinus Torvalds return 0; 5251da177e4SLinus Torvalds } 5261da177e4SLinus Torvalds 5271da177e4SLinus Torvalds 5281da177e4SLinus Torvalds /* 5291da177e4SLinus Torvalds * Implements the set_mem_map() operation for the in-kernel PCMCIA 5301da177e4SLinus Torvalds * service (formerly SS_SetMemMap in Card Services). We configure 5311da177e4SLinus Torvalds * the map speed as requested, but override the address ranges 5321da177e4SLinus Torvalds * supplied by Card Services. 5331da177e4SLinus Torvalds * 5344846d017SPavel Machek * Returns: 0 on success, -ERRNO on error 5351da177e4SLinus Torvalds */ 53617b38ebbSMarcelo Roberto Jimenez static int soc_common_pcmcia_set_mem_map( 53717b38ebbSMarcelo Roberto Jimenez struct pcmcia_socket *sock, struct pccard_mem_map *map) 5381da177e4SLinus Torvalds { 5391da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 5401da177e4SLinus Torvalds struct resource *res; 5411da177e4SLinus Torvalds unsigned short speed = map->speed; 5421da177e4SLinus Torvalds 5431da177e4SLinus Torvalds debug(skt, 2, "map %u speed %u card_start %08x\n", 5441da177e4SLinus Torvalds map->map, map->speed, map->card_start); 5451da177e4SLinus Torvalds debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n", 5461da177e4SLinus Torvalds (map->flags == 0) ? "<NONE>" : "", 5471da177e4SLinus Torvalds (map->flags & MAP_ACTIVE) ? "ACTIVE " : "", 5481da177e4SLinus Torvalds (map->flags & MAP_16BIT) ? "16BIT " : "", 5491da177e4SLinus Torvalds (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "", 5501da177e4SLinus Torvalds (map->flags & MAP_0WS) ? "0WS " : "", 5511da177e4SLinus Torvalds (map->flags & MAP_WRPROT) ? "WRPROT " : "", 5521da177e4SLinus Torvalds (map->flags & MAP_ATTRIB) ? "ATTRIB " : "", 5531da177e4SLinus Torvalds (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : ""); 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds if (map->map >= MAX_WIN) 5561da177e4SLinus Torvalds return -EINVAL; 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds if (map->flags & MAP_ACTIVE) { 5591da177e4SLinus Torvalds if (speed == 0) 5601da177e4SLinus Torvalds speed = 300; 5611da177e4SLinus Torvalds } else { 5621da177e4SLinus Torvalds speed = 0; 5631da177e4SLinus Torvalds } 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds if (map->flags & MAP_ATTRIB) { 5661da177e4SLinus Torvalds res = &skt->res_attr; 5671da177e4SLinus Torvalds skt->spd_attr[map->map] = speed; 5681da177e4SLinus Torvalds skt->spd_mem[map->map] = 0; 5691da177e4SLinus Torvalds } else { 5701da177e4SLinus Torvalds res = &skt->res_mem; 5711da177e4SLinus Torvalds skt->spd_attr[map->map] = 0; 5721da177e4SLinus Torvalds skt->spd_mem[map->map] = speed; 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds skt->ops->set_timing(skt); 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds map->static_start = res->start + map->card_start; 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds return 0; 5801da177e4SLinus Torvalds } 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvalds struct bittbl { 5831da177e4SLinus Torvalds unsigned int mask; 5841da177e4SLinus Torvalds const char *name; 5851da177e4SLinus Torvalds }; 5861da177e4SLinus Torvalds 5871da177e4SLinus Torvalds static struct bittbl status_bits[] = { 5881da177e4SLinus Torvalds { SS_WRPROT, "SS_WRPROT" }, 5891da177e4SLinus Torvalds { SS_BATDEAD, "SS_BATDEAD" }, 5901da177e4SLinus Torvalds { SS_BATWARN, "SS_BATWARN" }, 5911da177e4SLinus Torvalds { SS_READY, "SS_READY" }, 5921da177e4SLinus Torvalds { SS_DETECT, "SS_DETECT" }, 5931da177e4SLinus Torvalds { SS_POWERON, "SS_POWERON" }, 5941da177e4SLinus Torvalds { SS_STSCHG, "SS_STSCHG" }, 5951da177e4SLinus Torvalds { SS_3VCARD, "SS_3VCARD" }, 5961da177e4SLinus Torvalds { SS_XVCARD, "SS_XVCARD" }, 5971da177e4SLinus Torvalds }; 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds static struct bittbl conf_bits[] = { 6001da177e4SLinus Torvalds { SS_PWR_AUTO, "SS_PWR_AUTO" }, 6011da177e4SLinus Torvalds { SS_IOCARD, "SS_IOCARD" }, 6021da177e4SLinus Torvalds { SS_RESET, "SS_RESET" }, 6031da177e4SLinus Torvalds { SS_DMA_MODE, "SS_DMA_MODE" }, 6041da177e4SLinus Torvalds { SS_SPKR_ENA, "SS_SPKR_ENA" }, 6051da177e4SLinus Torvalds { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" }, 6061da177e4SLinus Torvalds }; 6071da177e4SLinus Torvalds 60817b38ebbSMarcelo Roberto Jimenez static void dump_bits(char **p, const char *prefix, 60917b38ebbSMarcelo Roberto Jimenez unsigned int val, struct bittbl *bits, int sz) 6101da177e4SLinus Torvalds { 6111da177e4SLinus Torvalds char *b = *p; 6121da177e4SLinus Torvalds int i; 6131da177e4SLinus Torvalds 6141da177e4SLinus Torvalds b += sprintf(b, "%-9s:", prefix); 6151da177e4SLinus Torvalds for (i = 0; i < sz; i++) 6161da177e4SLinus Torvalds if (val & bits[i].mask) 6171da177e4SLinus Torvalds b += sprintf(b, " %s", bits[i].name); 6181da177e4SLinus Torvalds *b++ = '\n'; 6191da177e4SLinus Torvalds *p = b; 6201da177e4SLinus Torvalds } 6211da177e4SLinus Torvalds 6221da177e4SLinus Torvalds /* 6231da177e4SLinus Torvalds * Implements the /sys/class/pcmcia_socket/??/status file. 6241da177e4SLinus Torvalds * 6251da177e4SLinus Torvalds * Returns: the number of characters added to the buffer 6261da177e4SLinus Torvalds */ 62717b38ebbSMarcelo Roberto Jimenez static ssize_t show_status( 62817b38ebbSMarcelo Roberto Jimenez struct device *dev, struct device_attribute *attr, char *buf) 6291da177e4SLinus Torvalds { 6301da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = 63187373318SGreg Kroah-Hartman container_of(dev, struct soc_pcmcia_socket, socket.dev); 6321da177e4SLinus Torvalds char *p = buf; 6331da177e4SLinus Torvalds 6341da177e4SLinus Torvalds p += sprintf(p, "slot : %d\n", skt->nr); 6351da177e4SLinus Torvalds 6361da177e4SLinus Torvalds dump_bits(&p, "status", skt->status, 6371da177e4SLinus Torvalds status_bits, ARRAY_SIZE(status_bits)); 6381da177e4SLinus Torvalds dump_bits(&p, "csc_mask", skt->cs_state.csc_mask, 6391da177e4SLinus Torvalds status_bits, ARRAY_SIZE(status_bits)); 6401da177e4SLinus Torvalds dump_bits(&p, "cs_flags", skt->cs_state.flags, 6411da177e4SLinus Torvalds conf_bits, ARRAY_SIZE(conf_bits)); 6421da177e4SLinus Torvalds 6431da177e4SLinus Torvalds p += sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc); 6441da177e4SLinus Torvalds p += sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp); 64566024db5SRussell King - ARM Linux p += sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq, 64666024db5SRussell King - ARM Linux skt->socket.pci_irq); 6471da177e4SLinus Torvalds if (skt->ops->show_timing) 6481da177e4SLinus Torvalds p += skt->ops->show_timing(skt, p); 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds return p-buf; 6511da177e4SLinus Torvalds } 652e4a3c3f0SAlexey Dobriyan static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds 6551da177e4SLinus Torvalds static struct pccard_operations soc_common_pcmcia_operations = { 6561da177e4SLinus Torvalds .init = soc_common_pcmcia_sock_init, 6571da177e4SLinus Torvalds .suspend = soc_common_pcmcia_suspend, 6581da177e4SLinus Torvalds .get_status = soc_common_pcmcia_get_status, 6591da177e4SLinus Torvalds .set_socket = soc_common_pcmcia_set_socket, 6601da177e4SLinus Torvalds .set_io_map = soc_common_pcmcia_set_io_map, 6611da177e4SLinus Torvalds .set_mem_map = soc_common_pcmcia_set_mem_map, 6621da177e4SLinus Torvalds }; 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvalds 665097e296dSRussell King - ARM Linux static LIST_HEAD(soc_pcmcia_sockets); 66623d077e2SAndrew Morton static DEFINE_MUTEX(soc_pcmcia_sockets_lock); 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds #ifdef CONFIG_CPU_FREQ 6691da177e4SLinus Torvalds static int 6701da177e4SLinus Torvalds soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data) 6711da177e4SLinus Torvalds { 6721da177e4SLinus Torvalds struct soc_pcmcia_socket *skt; 6731da177e4SLinus Torvalds struct cpufreq_freqs *freqs = data; 6741da177e4SLinus Torvalds int ret = 0; 6751da177e4SLinus Torvalds 67623d077e2SAndrew Morton mutex_lock(&soc_pcmcia_sockets_lock); 6771da177e4SLinus Torvalds list_for_each_entry(skt, &soc_pcmcia_sockets, node) 6781da177e4SLinus Torvalds if (skt->ops->frequency_change) 6791da177e4SLinus Torvalds ret += skt->ops->frequency_change(skt, val, freqs); 68023d077e2SAndrew Morton mutex_unlock(&soc_pcmcia_sockets_lock); 6811da177e4SLinus Torvalds 6821da177e4SLinus Torvalds return ret; 6831da177e4SLinus Torvalds } 6841da177e4SLinus Torvalds 6851da177e4SLinus Torvalds static struct notifier_block soc_pcmcia_notifier_block = { 6861da177e4SLinus Torvalds .notifier_call = soc_pcmcia_notifier 6871da177e4SLinus Torvalds }; 6881da177e4SLinus Torvalds 6891da177e4SLinus Torvalds static int soc_pcmcia_cpufreq_register(void) 6901da177e4SLinus Torvalds { 6911da177e4SLinus Torvalds int ret; 6921da177e4SLinus Torvalds 6931da177e4SLinus Torvalds ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block, 6941da177e4SLinus Torvalds CPUFREQ_TRANSITION_NOTIFIER); 6951da177e4SLinus Torvalds if (ret < 0) 6961da177e4SLinus Torvalds printk(KERN_ERR "Unable to register CPU frequency change " 6971da177e4SLinus Torvalds "notifier for PCMCIA (%d)\n", ret); 6981da177e4SLinus Torvalds return ret; 6991da177e4SLinus Torvalds } 7000f767de6SRussell King - ARM Linux fs_initcall(soc_pcmcia_cpufreq_register); 7011da177e4SLinus Torvalds 7021da177e4SLinus Torvalds static void soc_pcmcia_cpufreq_unregister(void) 7031da177e4SLinus Torvalds { 70417b38ebbSMarcelo Roberto Jimenez cpufreq_unregister_notifier(&soc_pcmcia_notifier_block, 70517b38ebbSMarcelo Roberto Jimenez CPUFREQ_TRANSITION_NOTIFIER); 7061da177e4SLinus Torvalds } 7070f767de6SRussell King - ARM Linux module_exit(soc_pcmcia_cpufreq_unregister); 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds #endif 7101da177e4SLinus Torvalds 711e0d21178SRussell King void soc_pcmcia_init_one(struct soc_pcmcia_socket *skt, 712e0d21178SRussell King struct pcmcia_low_level *ops, struct device *dev) 713e0d21178SRussell King { 714d9dc8787SRussell King int i; 715d9dc8787SRussell King 716e0d21178SRussell King skt->ops = ops; 717e0d21178SRussell King skt->socket.owner = ops->owner; 718e0d21178SRussell King skt->socket.dev.parent = dev; 719e0d21178SRussell King skt->socket.pci_irq = NO_IRQ; 720d9dc8787SRussell King 721d9dc8787SRussell King for (i = 0; i < ARRAY_SIZE(skt->stat); i++) 722d9dc8787SRussell King skt->stat[i].gpio = -EINVAL; 723e0d21178SRussell King } 724e0d21178SRussell King EXPORT_SYMBOL(soc_pcmcia_init_one); 725e0d21178SRussell King 726097e296dSRussell King - ARM Linux void soc_pcmcia_remove_one(struct soc_pcmcia_socket *skt) 7271da177e4SLinus Torvalds { 72823d077e2SAndrew Morton mutex_lock(&soc_pcmcia_sockets_lock); 729097e296dSRussell King - ARM Linux del_timer_sync(&skt->poll_timer); 7301da177e4SLinus Torvalds 731097e296dSRussell King - ARM Linux pcmcia_unregister_socket(&skt->socket); 7321da177e4SLinus Torvalds 733d9dc8787SRussell King soc_pcmcia_hw_shutdown(skt); 734097e296dSRussell King - ARM Linux 735d9dc8787SRussell King /* should not be required; violates some lowlevel drivers */ 736097e296dSRussell King - ARM Linux soc_common_pcmcia_config_skt(skt, &dead_socket); 737097e296dSRussell King - ARM Linux 738097e296dSRussell King - ARM Linux list_del(&skt->node); 739097e296dSRussell King - ARM Linux mutex_unlock(&soc_pcmcia_sockets_lock); 740097e296dSRussell King - ARM Linux 741097e296dSRussell King - ARM Linux iounmap(skt->virt_io); 742097e296dSRussell King - ARM Linux skt->virt_io = NULL; 743097e296dSRussell King - ARM Linux release_resource(&skt->res_attr); 744097e296dSRussell King - ARM Linux release_resource(&skt->res_mem); 745097e296dSRussell King - ARM Linux release_resource(&skt->res_io); 746097e296dSRussell King - ARM Linux release_resource(&skt->res_skt); 747097e296dSRussell King - ARM Linux } 748097e296dSRussell King - ARM Linux EXPORT_SYMBOL(soc_pcmcia_remove_one); 749097e296dSRussell King - ARM Linux 750097e296dSRussell King - ARM Linux int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt) 751097e296dSRussell King - ARM Linux { 752097e296dSRussell King - ARM Linux int ret; 7531da177e4SLinus Torvalds 754dae6cdabSVaishali Thakkar setup_timer(&skt->poll_timer, soc_common_pcmcia_poll_event, 755dae6cdabSVaishali Thakkar (unsigned long)skt); 7561da177e4SLinus Torvalds skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD; 7571da177e4SLinus Torvalds 7581da177e4SLinus Torvalds ret = request_resource(&iomem_resource, &skt->res_skt); 7591da177e4SLinus Torvalds if (ret) 7601da177e4SLinus Torvalds goto out_err_1; 7611da177e4SLinus Torvalds 7621da177e4SLinus Torvalds ret = request_resource(&skt->res_skt, &skt->res_io); 7631da177e4SLinus Torvalds if (ret) 7641da177e4SLinus Torvalds goto out_err_2; 7651da177e4SLinus Torvalds 7661da177e4SLinus Torvalds ret = request_resource(&skt->res_skt, &skt->res_mem); 7671da177e4SLinus Torvalds if (ret) 7681da177e4SLinus Torvalds goto out_err_3; 7691da177e4SLinus Torvalds 7701da177e4SLinus Torvalds ret = request_resource(&skt->res_skt, &skt->res_attr); 7711da177e4SLinus Torvalds if (ret) 7721da177e4SLinus Torvalds goto out_err_4; 7731da177e4SLinus Torvalds 7741da177e4SLinus Torvalds skt->virt_io = ioremap(skt->res_io.start, 0x10000); 7751da177e4SLinus Torvalds if (skt->virt_io == NULL) { 7761da177e4SLinus Torvalds ret = -ENOMEM; 7771da177e4SLinus Torvalds goto out_err_5; 7781da177e4SLinus Torvalds } 7791da177e4SLinus Torvalds 780097e296dSRussell King - ARM Linux mutex_lock(&soc_pcmcia_sockets_lock); 781097e296dSRussell King - ARM Linux 7821da177e4SLinus Torvalds list_add(&skt->node, &soc_pcmcia_sockets); 7831da177e4SLinus Torvalds 7841da177e4SLinus Torvalds /* 7851da177e4SLinus Torvalds * We initialize default socket timing here, because 7861da177e4SLinus Torvalds * we are not guaranteed to see a SetIOMap operation at 7871da177e4SLinus Torvalds * runtime. 7881da177e4SLinus Torvalds */ 789097e296dSRussell King - ARM Linux skt->ops->set_timing(skt); 7901da177e4SLinus Torvalds 791d9dc8787SRussell King ret = soc_pcmcia_hw_init(skt); 7921da177e4SLinus Torvalds if (ret) 7931da177e4SLinus Torvalds goto out_err_6; 7941da177e4SLinus Torvalds 795097e296dSRussell King - ARM Linux skt->socket.ops = &soc_common_pcmcia_operations; 7961da177e4SLinus Torvalds skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD; 7971da177e4SLinus Torvalds skt->socket.resource_ops = &pccard_static_ops; 7981da177e4SLinus Torvalds skt->socket.irq_mask = 0; 7991da177e4SLinus Torvalds skt->socket.map_size = PAGE_SIZE; 8001da177e4SLinus Torvalds skt->socket.io_offset = (unsigned long)skt->virt_io; 8011da177e4SLinus Torvalds 8021da177e4SLinus Torvalds skt->status = soc_common_pcmcia_skt_state(skt); 8031da177e4SLinus Torvalds 8041da177e4SLinus Torvalds ret = pcmcia_register_socket(&skt->socket); 8051da177e4SLinus Torvalds if (ret) 8061da177e4SLinus Torvalds goto out_err_7; 8071da177e4SLinus Torvalds 8081da177e4SLinus Torvalds add_timer(&skt->poll_timer); 8091da177e4SLinus Torvalds 810097e296dSRussell King - ARM Linux mutex_unlock(&soc_pcmcia_sockets_lock); 811097e296dSRussell King - ARM Linux 812632480eaSJürgen Schindele ret = device_create_file(&skt->socket.dev, &dev_attr_status); 813632480eaSJürgen Schindele if (ret) 814632480eaSJürgen Schindele goto out_err_8; 8151da177e4SLinus Torvalds 816097e296dSRussell King - ARM Linux return ret; 8171da177e4SLinus Torvalds 818632480eaSJürgen Schindele out_err_8: 819097e296dSRussell King - ARM Linux mutex_lock(&soc_pcmcia_sockets_lock); 8201da177e4SLinus Torvalds del_timer_sync(&skt->poll_timer); 8211da177e4SLinus Torvalds pcmcia_unregister_socket(&skt->socket); 8221da177e4SLinus Torvalds 8231da177e4SLinus Torvalds out_err_7: 824d9dc8787SRussell King soc_pcmcia_hw_shutdown(skt); 8251da177e4SLinus Torvalds out_err_6: 8261da177e4SLinus Torvalds list_del(&skt->node); 827097e296dSRussell King - ARM Linux mutex_unlock(&soc_pcmcia_sockets_lock); 8281da177e4SLinus Torvalds iounmap(skt->virt_io); 8291da177e4SLinus Torvalds out_err_5: 8301da177e4SLinus Torvalds release_resource(&skt->res_attr); 8311da177e4SLinus Torvalds out_err_4: 8321da177e4SLinus Torvalds release_resource(&skt->res_mem); 8331da177e4SLinus Torvalds out_err_3: 8341da177e4SLinus Torvalds release_resource(&skt->res_io); 8351da177e4SLinus Torvalds out_err_2: 8361da177e4SLinus Torvalds release_resource(&skt->res_skt); 8371da177e4SLinus Torvalds out_err_1: 8381da177e4SLinus Torvalds 839097e296dSRussell King - ARM Linux return ret; 840097e296dSRussell King - ARM Linux } 841097e296dSRussell King - ARM Linux EXPORT_SYMBOL(soc_pcmcia_add_one); 842097e296dSRussell King - ARM Linux 8430f767de6SRussell King - ARM Linux MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>"); 8440f767de6SRussell King - ARM Linux MODULE_DESCRIPTION("Linux PCMCIA Card Services: Common SoC support"); 8450f767de6SRussell King - ARM Linux MODULE_LICENSE("Dual MPL/GPL"); 846