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> 46*ac61b600SRussell King #include <linux/regulator/consumer.h> 471da177e4SLinus Torvalds #include <linux/spinlock.h> 4817b38ebbSMarcelo Roberto Jimenez #include <linux/timer.h> 491da177e4SLinus Torvalds 50a09e64fbSRussell King #include <mach/hardware.h> 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds #include "soc_common.h" 531da177e4SLinus Torvalds 54d9dc8787SRussell King static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev); 55d9dc8787SRussell King 567d16b658SDominik Brodowski #ifdef CONFIG_PCMCIA_DEBUG 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds static int pc_debug; 591da177e4SLinus Torvalds module_param(pc_debug, int, 0644); 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func, 621da177e4SLinus Torvalds int lvl, const char *fmt, ...) 631da177e4SLinus Torvalds { 64106665d9SJoe Perches struct va_format vaf; 651da177e4SLinus Torvalds va_list args; 661da177e4SLinus Torvalds if (pc_debug > lvl) { 671da177e4SLinus Torvalds va_start(args, fmt); 68106665d9SJoe Perches 69106665d9SJoe Perches vaf.fmt = fmt; 70106665d9SJoe Perches vaf.va = &args; 71106665d9SJoe Perches 72106665d9SJoe Perches printk(KERN_DEBUG "skt%u: %s: %pV", skt->nr, func, &vaf); 73106665d9SJoe Perches 741da177e4SLinus Torvalds va_end(args); 751da177e4SLinus Torvalds } 761da177e4SLinus Torvalds } 77b9f515e3SMarcelo Roberto Jimenez EXPORT_SYMBOL(soc_pcmcia_debug); 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds #endif 801da177e4SLinus Torvalds 8117b38ebbSMarcelo Roberto Jimenez #define to_soc_pcmcia_socket(x) \ 8217b38ebbSMarcelo Roberto Jimenez container_of(x, struct soc_pcmcia_socket, socket) 831da177e4SLinus Torvalds 84*ac61b600SRussell King int soc_pcmcia_regulator_set(struct soc_pcmcia_socket *skt, 85*ac61b600SRussell King struct soc_pcmcia_regulator *r, int v) 86*ac61b600SRussell King { 87*ac61b600SRussell King bool on; 88*ac61b600SRussell King int ret; 89*ac61b600SRussell King 90*ac61b600SRussell King if (!r->reg) 91*ac61b600SRussell King return 0; 92*ac61b600SRussell King 93*ac61b600SRussell King on = v != 0; 94*ac61b600SRussell King if (r->on == on) 95*ac61b600SRussell King return 0; 96*ac61b600SRussell King 97*ac61b600SRussell King if (on) { 98*ac61b600SRussell King ret = regulator_set_voltage(r->reg, v * 100000, v * 100000); 99*ac61b600SRussell King if (ret) { 100*ac61b600SRussell King int vout = regulator_get_voltage(r->reg) / 100000; 101*ac61b600SRussell King 102*ac61b600SRussell King dev_warn(&skt->socket.dev, 103*ac61b600SRussell King "CS requested %s=%u.%uV, applying %u.%uV\n", 104*ac61b600SRussell King r == &skt->vcc ? "Vcc" : "Vpp", 105*ac61b600SRussell King v / 10, v % 10, vout / 10, vout % 10); 106*ac61b600SRussell King } 107*ac61b600SRussell King 108*ac61b600SRussell King ret = regulator_enable(r->reg); 109*ac61b600SRussell King } else { 110*ac61b600SRussell King regulator_disable(r->reg); 111*ac61b600SRussell King } 112*ac61b600SRussell King if (ret == 0) 113*ac61b600SRussell King r->on = on; 114*ac61b600SRussell King 115*ac61b600SRussell King return ret; 116*ac61b600SRussell King } 117*ac61b600SRussell King EXPORT_SYMBOL_GPL(soc_pcmcia_regulator_set); 118*ac61b600SRussell King 1191da177e4SLinus Torvalds static unsigned short 1201da177e4SLinus Torvalds calc_speed(unsigned short *spds, int num, unsigned short dflt) 1211da177e4SLinus Torvalds { 1221da177e4SLinus Torvalds unsigned short speed = 0; 1231da177e4SLinus Torvalds int i; 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds for (i = 0; i < num; i++) 1261da177e4SLinus Torvalds if (speed < spds[i]) 1271da177e4SLinus Torvalds speed = spds[i]; 1281da177e4SLinus Torvalds if (speed == 0) 1291da177e4SLinus Torvalds speed = dflt; 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds return speed; 1321da177e4SLinus Torvalds } 1331da177e4SLinus Torvalds 13417b38ebbSMarcelo Roberto Jimenez void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt, 13517b38ebbSMarcelo Roberto Jimenez struct soc_pcmcia_timing *timing) 1361da177e4SLinus Torvalds { 13717b38ebbSMarcelo Roberto Jimenez timing->io = 13817b38ebbSMarcelo Roberto Jimenez calc_speed(skt->spd_io, MAX_IO_WIN, SOC_PCMCIA_IO_ACCESS); 13917b38ebbSMarcelo Roberto Jimenez timing->mem = 14017b38ebbSMarcelo Roberto Jimenez calc_speed(skt->spd_mem, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS); 14117b38ebbSMarcelo Roberto Jimenez timing->attr = 14217b38ebbSMarcelo Roberto Jimenez calc_speed(skt->spd_attr, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS); 1431da177e4SLinus Torvalds } 1441da177e4SLinus Torvalds EXPORT_SYMBOL(soc_common_pcmcia_get_timing); 1451da177e4SLinus Torvalds 146d9dc8787SRussell King static void __soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt, 147d9dc8787SRussell King unsigned int nr) 148d9dc8787SRussell King { 149d9dc8787SRussell King unsigned int i; 150d9dc8787SRussell King 15159ecfefaSRussell King for (i = 0; i < nr; i++) 152d9dc8787SRussell King if (skt->stat[i].irq) 153d9dc8787SRussell King free_irq(skt->stat[i].irq, skt); 154d9dc8787SRussell King 155d9dc8787SRussell King if (skt->ops->hw_shutdown) 156d9dc8787SRussell King skt->ops->hw_shutdown(skt); 1570821c3bcSDmitry Eremin-Solenikov 1580821c3bcSDmitry Eremin-Solenikov clk_disable_unprepare(skt->clk); 159d9dc8787SRussell King } 160d9dc8787SRussell King 161d9dc8787SRussell King static void soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) 162d9dc8787SRussell King { 163d9dc8787SRussell King __soc_pcmcia_hw_shutdown(skt, ARRAY_SIZE(skt->stat)); 164d9dc8787SRussell King } 165d9dc8787SRussell King 16645ca7536SRussell King int soc_pcmcia_request_gpiods(struct soc_pcmcia_socket *skt) 16745ca7536SRussell King { 16845ca7536SRussell King struct device *dev = skt->socket.dev.parent; 16945ca7536SRussell King struct gpio_desc *desc; 17045ca7536SRussell King int i; 17145ca7536SRussell King 17245ca7536SRussell King for (i = 0; i < ARRAY_SIZE(skt->stat); i++) { 17345ca7536SRussell King if (!skt->stat[i].name) 17445ca7536SRussell King continue; 17545ca7536SRussell King 17645ca7536SRussell King desc = devm_gpiod_get(dev, skt->stat[i].name, GPIOD_IN); 17745ca7536SRussell King if (IS_ERR(desc)) { 17845ca7536SRussell King dev_err(dev, "Failed to get GPIO for %s: %ld\n", 17945ca7536SRussell King skt->stat[i].name, PTR_ERR(desc)); 18045ca7536SRussell King return PTR_ERR(desc); 18145ca7536SRussell King } 18245ca7536SRussell King 18345ca7536SRussell King skt->stat[i].desc = desc; 18445ca7536SRussell King } 18545ca7536SRussell King 18645ca7536SRussell King return 0; 18745ca7536SRussell King } 18845ca7536SRussell King EXPORT_SYMBOL_GPL(soc_pcmcia_request_gpiods); 18945ca7536SRussell King 190d9dc8787SRussell King static int soc_pcmcia_hw_init(struct soc_pcmcia_socket *skt) 191d9dc8787SRussell King { 192d9dc8787SRussell King int ret = 0, i; 193d9dc8787SRussell King 1940821c3bcSDmitry Eremin-Solenikov clk_prepare_enable(skt->clk); 1950821c3bcSDmitry Eremin-Solenikov 196d9dc8787SRussell King if (skt->ops->hw_init) { 197d9dc8787SRussell King ret = skt->ops->hw_init(skt); 198d9dc8787SRussell King if (ret) 199d9dc8787SRussell King return ret; 200d9dc8787SRussell King } 201d9dc8787SRussell King 202d9dc8787SRussell King for (i = 0; i < ARRAY_SIZE(skt->stat); i++) { 203d9dc8787SRussell King if (gpio_is_valid(skt->stat[i].gpio)) { 2047bfe4978SRussell King unsigned long flags = GPIOF_IN; 2057bfe4978SRussell King 2067bfe4978SRussell King /* CD is active low by default */ 2077bfe4978SRussell King if (i == SOC_STAT_CD) 2087bfe4978SRussell King flags |= GPIOF_ACTIVE_LOW; 2097bfe4978SRussell King 21059ecfefaSRussell King ret = devm_gpio_request_one(skt->socket.dev.parent, 2117bfe4978SRussell King skt->stat[i].gpio, flags, 212d9dc8787SRussell King skt->stat[i].name); 213d9dc8787SRussell King if (ret) { 214d9dc8787SRussell King __soc_pcmcia_hw_shutdown(skt, i); 215d9dc8787SRussell King return ret; 216d9dc8787SRussell King } 217d9dc8787SRussell King 21845ca7536SRussell King skt->stat[i].desc = gpio_to_desc(skt->stat[i].gpio); 21945ca7536SRussell King } 22045ca7536SRussell King 22145ca7536SRussell King if (skt->stat[i].desc) { 22245ca7536SRussell King int irq = gpiod_to_irq(skt->stat[i].desc); 223d9dc8787SRussell King 224a4941191SRussell King if (irq > 0) { 225d9dc8787SRussell King if (i == SOC_STAT_RDY) 226d9dc8787SRussell King skt->socket.pci_irq = irq; 227d9dc8787SRussell King else 228d9dc8787SRussell King skt->stat[i].irq = irq; 229d9dc8787SRussell King } 230a4941191SRussell King } 231d9dc8787SRussell King 232d9dc8787SRussell King if (skt->stat[i].irq) { 233d9dc8787SRussell King ret = request_irq(skt->stat[i].irq, 234d9dc8787SRussell King soc_common_pcmcia_interrupt, 235d9dc8787SRussell King IRQF_TRIGGER_NONE, 236d9dc8787SRussell King skt->stat[i].name, skt); 237d9dc8787SRussell King if (ret) { 238d9dc8787SRussell King __soc_pcmcia_hw_shutdown(skt, i); 239d9dc8787SRussell King return ret; 240d9dc8787SRussell King } 241d9dc8787SRussell King } 242d9dc8787SRussell King } 243d9dc8787SRussell King 244d9dc8787SRussell King return ret; 245d9dc8787SRussell King } 246d9dc8787SRussell King 247d9dc8787SRussell King static void soc_pcmcia_hw_enable(struct soc_pcmcia_socket *skt) 248d9dc8787SRussell King { 249d9dc8787SRussell King int i; 250d9dc8787SRussell King 251d9dc8787SRussell King for (i = 0; i < ARRAY_SIZE(skt->stat); i++) 252d9dc8787SRussell King if (skt->stat[i].irq) { 253d9dc8787SRussell King irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_EDGE_RISING); 254d9dc8787SRussell King irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_EDGE_BOTH); 255d9dc8787SRussell King } 256d9dc8787SRussell King } 257d9dc8787SRussell King 258d9dc8787SRussell King static void soc_pcmcia_hw_disable(struct soc_pcmcia_socket *skt) 259d9dc8787SRussell King { 260d9dc8787SRussell King int i; 261d9dc8787SRussell King 262d9dc8787SRussell King for (i = 0; i < ARRAY_SIZE(skt->stat); i++) 263d9dc8787SRussell King if (skt->stat[i].irq) 264d9dc8787SRussell King irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_NONE); 265d9dc8787SRussell King } 266d9dc8787SRussell King 267a1d05002SRussell King /* 268a1d05002SRussell King * The CF 3.0 specification says that cards tie VS1 to ground and leave 269a1d05002SRussell King * VS2 open. Many implementations do not wire up the VS signals, so we 270a1d05002SRussell King * provide hard-coded values as per the CF 3.0 spec. 271a1d05002SRussell King */ 272a1d05002SRussell King void soc_common_cf_socket_state(struct soc_pcmcia_socket *skt, 273a1d05002SRussell King struct pcmcia_state *state) 274a1d05002SRussell King { 275a1d05002SRussell King state->vs_3v = 1; 276a1d05002SRussell King } 277a1d05002SRussell King EXPORT_SYMBOL_GPL(soc_common_cf_socket_state); 278a1d05002SRussell King 2791da177e4SLinus Torvalds static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt) 2801da177e4SLinus Torvalds { 2811da177e4SLinus Torvalds struct pcmcia_state state; 2821da177e4SLinus Torvalds unsigned int stat; 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds memset(&state, 0, sizeof(struct pcmcia_state)); 2851da177e4SLinus Torvalds 286d9dc8787SRussell King /* Make battery voltage state report 'good' */ 287d9dc8787SRussell King state.bvd1 = 1; 288d9dc8787SRussell King state.bvd2 = 1; 289d9dc8787SRussell King 29045ca7536SRussell King if (skt->stat[SOC_STAT_CD].desc) 2917bfe4978SRussell King state.detect = !!gpiod_get_value(skt->stat[SOC_STAT_CD].desc); 29245ca7536SRussell King if (skt->stat[SOC_STAT_RDY].desc) 29345ca7536SRussell King state.ready = !!gpiod_get_value(skt->stat[SOC_STAT_RDY].desc); 29445ca7536SRussell King if (skt->stat[SOC_STAT_BVD1].desc) 29545ca7536SRussell King state.bvd1 = !!gpiod_get_value(skt->stat[SOC_STAT_BVD1].desc); 29645ca7536SRussell King if (skt->stat[SOC_STAT_BVD2].desc) 29745ca7536SRussell King state.bvd2 = !!gpiod_get_value(skt->stat[SOC_STAT_BVD2].desc); 298d9dc8787SRussell King 2991da177e4SLinus Torvalds skt->ops->socket_state(skt, &state); 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvalds stat = state.detect ? SS_DETECT : 0; 3021da177e4SLinus Torvalds stat |= state.ready ? SS_READY : 0; 3031da177e4SLinus Torvalds stat |= state.wrprot ? SS_WRPROT : 0; 3041da177e4SLinus Torvalds stat |= state.vs_3v ? SS_3VCARD : 0; 3051da177e4SLinus Torvalds stat |= state.vs_Xv ? SS_XVCARD : 0; 3061da177e4SLinus Torvalds 3071da177e4SLinus Torvalds /* The power status of individual sockets is not available 3081da177e4SLinus Torvalds * explicitly from the hardware, so we just remember the state 3091da177e4SLinus Torvalds * and regurgitate it upon request: 3101da177e4SLinus Torvalds */ 3111da177e4SLinus Torvalds stat |= skt->cs_state.Vcc ? SS_POWERON : 0; 3121da177e4SLinus Torvalds 3131da177e4SLinus Torvalds if (skt->cs_state.flags & SS_IOCARD) 314a466ebd2SRussell King stat |= state.bvd1 ? 0 : SS_STSCHG; 3151da177e4SLinus Torvalds else { 3161da177e4SLinus Torvalds if (state.bvd1 == 0) 3171da177e4SLinus Torvalds stat |= SS_BATDEAD; 3181da177e4SLinus Torvalds else if (state.bvd2 == 0) 3191da177e4SLinus Torvalds stat |= SS_BATWARN; 3201da177e4SLinus Torvalds } 3211da177e4SLinus Torvalds return stat; 3221da177e4SLinus Torvalds } 3231da177e4SLinus Torvalds 3241da177e4SLinus Torvalds /* 3251da177e4SLinus Torvalds * soc_common_pcmcia_config_skt 3261da177e4SLinus Torvalds * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 3271da177e4SLinus Torvalds * 3281da177e4SLinus Torvalds * Convert PCMCIA socket state to our socket configure structure. 3291da177e4SLinus Torvalds */ 33017b38ebbSMarcelo Roberto Jimenez static int soc_common_pcmcia_config_skt( 33117b38ebbSMarcelo Roberto Jimenez struct soc_pcmcia_socket *skt, socket_state_t *state) 3321da177e4SLinus Torvalds { 3331da177e4SLinus Torvalds int ret; 3341da177e4SLinus Torvalds 3351da177e4SLinus Torvalds ret = skt->ops->configure_socket(skt, state); 3366ac95d82SRussell King if (ret < 0) { 3376ac95d82SRussell King pr_err("soc_common_pcmcia: unable to configure socket %d\n", 3386ac95d82SRussell King skt->nr); 3396ac95d82SRussell King /* restore the previous state */ 3406ac95d82SRussell King WARN_ON(skt->ops->configure_socket(skt, &skt->cs_state)); 3416ac95d82SRussell King return ret; 3426ac95d82SRussell King } 3436ac95d82SRussell King 3441da177e4SLinus Torvalds if (ret == 0) { 345535e0abcSRussell King struct gpio_desc *descs[2]; 346535e0abcSRussell King int values[2], n = 0; 347535e0abcSRussell King 348535e0abcSRussell King if (skt->gpio_reset) { 349535e0abcSRussell King descs[n] = skt->gpio_reset; 350535e0abcSRussell King values[n++] = !!(state->flags & SS_RESET); 351535e0abcSRussell King } 352535e0abcSRussell King if (skt->gpio_bus_enable) { 353535e0abcSRussell King descs[n] = skt->gpio_bus_enable; 354535e0abcSRussell King values[n++] = !!(state->flags & SS_OUTPUT_ENA); 355535e0abcSRussell King } 356535e0abcSRussell King 357535e0abcSRussell King if (n) 358535e0abcSRussell King gpiod_set_array_value_cansleep(n, descs, values); 359535e0abcSRussell King 3601da177e4SLinus Torvalds /* 3611da177e4SLinus Torvalds * This really needs a better solution. The IRQ 3621da177e4SLinus Torvalds * may or may not be claimed by the driver. 3631da177e4SLinus Torvalds */ 3641da177e4SLinus Torvalds if (skt->irq_state != 1 && state->io_irq) { 3651da177e4SLinus Torvalds skt->irq_state = 1; 366dced35aeSThomas Gleixner irq_set_irq_type(skt->socket.pci_irq, 36717b38ebbSMarcelo Roberto Jimenez IRQ_TYPE_EDGE_FALLING); 3681da177e4SLinus Torvalds } else if (skt->irq_state == 1 && state->io_irq == 0) { 3691da177e4SLinus Torvalds skt->irq_state = 0; 370dced35aeSThomas Gleixner irq_set_irq_type(skt->socket.pci_irq, IRQ_TYPE_NONE); 3711da177e4SLinus Torvalds } 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds skt->cs_state = *state; 3741da177e4SLinus Torvalds } 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds return ret; 3771da177e4SLinus Torvalds } 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds /* soc_common_pcmcia_sock_init() 3801da177e4SLinus Torvalds * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 3811da177e4SLinus Torvalds * 3821da177e4SLinus Torvalds * (Re-)Initialise the socket, turning on status interrupts 3831da177e4SLinus Torvalds * and PCMCIA bus. This must wait for power to stabilise 3841da177e4SLinus Torvalds * so that the card status signals report correctly. 3851da177e4SLinus Torvalds * 3861da177e4SLinus Torvalds * Returns: 0 3871da177e4SLinus Torvalds */ 3881da177e4SLinus Torvalds static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock) 3891da177e4SLinus Torvalds { 3901da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 3911da177e4SLinus Torvalds 3921da177e4SLinus Torvalds debug(skt, 2, "initializing socket\n"); 393a747ce83SJonathan Cameron if (skt->ops->socket_init) 3941da177e4SLinus Torvalds skt->ops->socket_init(skt); 395d9dc8787SRussell King soc_pcmcia_hw_enable(skt); 3961da177e4SLinus Torvalds return 0; 3971da177e4SLinus Torvalds } 3981da177e4SLinus Torvalds 3991da177e4SLinus Torvalds 4001da177e4SLinus Torvalds /* 4011da177e4SLinus Torvalds * soc_common_pcmcia_suspend() 4021da177e4SLinus Torvalds * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4031da177e4SLinus Torvalds * 4041da177e4SLinus Torvalds * Remove power on the socket, disable IRQs from the card. 4051da177e4SLinus Torvalds * Turn off status interrupts, and disable the PCMCIA bus. 4061da177e4SLinus Torvalds * 4071da177e4SLinus Torvalds * Returns: 0 4081da177e4SLinus Torvalds */ 4091da177e4SLinus Torvalds static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock) 4101da177e4SLinus Torvalds { 4111da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 4121da177e4SLinus Torvalds 4131da177e4SLinus Torvalds debug(skt, 2, "suspending socket\n"); 4141da177e4SLinus Torvalds 415d9dc8787SRussell King soc_pcmcia_hw_disable(skt); 416a747ce83SJonathan Cameron if (skt->ops->socket_suspend) 4171da177e4SLinus Torvalds skt->ops->socket_suspend(skt); 4181da177e4SLinus Torvalds 4191da177e4SLinus Torvalds return 0; 4201da177e4SLinus Torvalds } 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds static DEFINE_SPINLOCK(status_lock); 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds static void soc_common_check_status(struct soc_pcmcia_socket *skt) 4251da177e4SLinus Torvalds { 4261da177e4SLinus Torvalds unsigned int events; 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds debug(skt, 4, "entering PCMCIA monitoring thread\n"); 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds do { 4311da177e4SLinus Torvalds unsigned int status; 4321da177e4SLinus Torvalds unsigned long flags; 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds status = soc_common_pcmcia_skt_state(skt); 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds spin_lock_irqsave(&status_lock, flags); 4371da177e4SLinus Torvalds events = (status ^ skt->status) & skt->cs_state.csc_mask; 4381da177e4SLinus Torvalds skt->status = status; 4391da177e4SLinus Torvalds spin_unlock_irqrestore(&status_lock, flags); 4401da177e4SLinus Torvalds 4411da177e4SLinus Torvalds debug(skt, 4, "events: %s%s%s%s%s%s\n", 4421da177e4SLinus Torvalds events == 0 ? "<NONE>" : "", 4431da177e4SLinus Torvalds events & SS_DETECT ? "DETECT " : "", 4441da177e4SLinus Torvalds events & SS_READY ? "READY " : "", 4451da177e4SLinus Torvalds events & SS_BATDEAD ? "BATDEAD " : "", 4461da177e4SLinus Torvalds events & SS_BATWARN ? "BATWARN " : "", 4471da177e4SLinus Torvalds events & SS_STSCHG ? "STSCHG " : ""); 4481da177e4SLinus Torvalds 4491da177e4SLinus Torvalds if (events) 4501da177e4SLinus Torvalds pcmcia_parse_events(&skt->socket, events); 4511da177e4SLinus Torvalds } while (events); 4521da177e4SLinus Torvalds } 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */ 4551da177e4SLinus Torvalds static void soc_common_pcmcia_poll_event(unsigned long dummy) 4561da177e4SLinus Torvalds { 4571da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy; 4581da177e4SLinus Torvalds debug(skt, 4, "polling for events\n"); 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD); 4611da177e4SLinus Torvalds 4621da177e4SLinus Torvalds soc_common_check_status(skt); 4631da177e4SLinus Torvalds } 4641da177e4SLinus Torvalds 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds /* 4671da177e4SLinus Torvalds * Service routine for socket driver interrupts (requested by the 4681da177e4SLinus Torvalds * low-level PCMCIA init() operation via soc_common_pcmcia_thread()). 4691da177e4SLinus Torvalds * The actual interrupt-servicing work is performed by 4701da177e4SLinus Torvalds * soc_common_pcmcia_thread(), largely because the Card Services event- 4711da177e4SLinus Torvalds * handling code performs scheduling operations which cannot be 4721da177e4SLinus Torvalds * executed from within an interrupt context. 4731da177e4SLinus Torvalds */ 4747d12e780SDavid Howells static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev) 4751da177e4SLinus Torvalds { 4761da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = dev; 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds debug(skt, 3, "servicing IRQ %d\n", irq); 4791da177e4SLinus Torvalds 4801da177e4SLinus Torvalds soc_common_check_status(skt); 4811da177e4SLinus Torvalds 4821da177e4SLinus Torvalds return IRQ_HANDLED; 4831da177e4SLinus Torvalds } 4841da177e4SLinus Torvalds 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds /* 4871da177e4SLinus Torvalds * Implements the get_status() operation for the in-kernel PCMCIA 4881da177e4SLinus Torvalds * service (formerly SS_GetStatus in Card Services). Essentially just 4891da177e4SLinus Torvalds * fills in bits in `status' according to internal driver state or 4901da177e4SLinus Torvalds * the value of the voltage detect chipselect register. 4911da177e4SLinus Torvalds * 4921da177e4SLinus Torvalds * As a debugging note, during card startup, the PCMCIA core issues 4931da177e4SLinus Torvalds * three set_socket() commands in a row the first with RESET deasserted, 4941da177e4SLinus Torvalds * the second with RESET asserted, and the last with RESET deasserted 4951da177e4SLinus Torvalds * again. Following the third set_socket(), a get_status() command will 4961da177e4SLinus Torvalds * be issued. The kernel is looking for the SS_READY flag (see 4971da177e4SLinus Torvalds * setup_socket(), reset_socket(), and unreset_socket() in cs.c). 4981da177e4SLinus Torvalds * 4991da177e4SLinus Torvalds * Returns: 0 5001da177e4SLinus Torvalds */ 5011da177e4SLinus Torvalds static int 5021da177e4SLinus Torvalds soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status) 5031da177e4SLinus Torvalds { 5041da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 5051da177e4SLinus Torvalds 5061da177e4SLinus Torvalds skt->status = soc_common_pcmcia_skt_state(skt); 5071da177e4SLinus Torvalds *status = skt->status; 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds return 0; 5101da177e4SLinus Torvalds } 5111da177e4SLinus Torvalds 5121da177e4SLinus Torvalds 5131da177e4SLinus Torvalds /* 5141da177e4SLinus Torvalds * Implements the set_socket() operation for the in-kernel PCMCIA 5151da177e4SLinus Torvalds * service (formerly SS_SetSocket in Card Services). We more or 5161da177e4SLinus Torvalds * less punt all of this work and let the kernel handle the details 5171da177e4SLinus Torvalds * of power configuration, reset, &c. We also record the value of 5181da177e4SLinus Torvalds * `state' in order to regurgitate it to the PCMCIA core later. 5191da177e4SLinus Torvalds */ 52017b38ebbSMarcelo Roberto Jimenez static int soc_common_pcmcia_set_socket( 52117b38ebbSMarcelo Roberto Jimenez struct pcmcia_socket *sock, socket_state_t *state) 5221da177e4SLinus Torvalds { 5231da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 5241da177e4SLinus Torvalds 5251da177e4SLinus 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", 5261da177e4SLinus Torvalds (state->csc_mask == 0) ? "<NONE> " : "", 5271da177e4SLinus Torvalds (state->csc_mask & SS_DETECT) ? "DETECT " : "", 5281da177e4SLinus Torvalds (state->csc_mask & SS_READY) ? "READY " : "", 5291da177e4SLinus Torvalds (state->csc_mask & SS_BATDEAD) ? "BATDEAD " : "", 5301da177e4SLinus Torvalds (state->csc_mask & SS_BATWARN) ? "BATWARN " : "", 5311da177e4SLinus Torvalds (state->csc_mask & SS_STSCHG) ? "STSCHG " : "", 5321da177e4SLinus Torvalds (state->flags == 0) ? "<NONE> " : "", 5331da177e4SLinus Torvalds (state->flags & SS_PWR_AUTO) ? "PWR_AUTO " : "", 5341da177e4SLinus Torvalds (state->flags & SS_IOCARD) ? "IOCARD " : "", 5351da177e4SLinus Torvalds (state->flags & SS_RESET) ? "RESET " : "", 5361da177e4SLinus Torvalds (state->flags & SS_SPKR_ENA) ? "SPKR_ENA " : "", 5371da177e4SLinus Torvalds (state->flags & SS_OUTPUT_ENA) ? "OUTPUT_ENA " : "", 5381da177e4SLinus Torvalds state->Vcc, state->Vpp, state->io_irq); 5391da177e4SLinus Torvalds 5401da177e4SLinus Torvalds return soc_common_pcmcia_config_skt(skt, state); 5411da177e4SLinus Torvalds } 5421da177e4SLinus Torvalds 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds /* 5451da177e4SLinus Torvalds * Implements the set_io_map() operation for the in-kernel PCMCIA 5461da177e4SLinus Torvalds * service (formerly SS_SetIOMap in Card Services). We configure 5471da177e4SLinus Torvalds * the map speed as requested, but override the address ranges 5481da177e4SLinus Torvalds * supplied by Card Services. 5491da177e4SLinus Torvalds * 5501da177e4SLinus Torvalds * Returns: 0 on success, -1 on error 5511da177e4SLinus Torvalds */ 55217b38ebbSMarcelo Roberto Jimenez static int soc_common_pcmcia_set_io_map( 55317b38ebbSMarcelo Roberto Jimenez struct pcmcia_socket *sock, struct pccard_io_map *map) 5541da177e4SLinus Torvalds { 5551da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 5561da177e4SLinus Torvalds unsigned short speed = map->speed; 5571da177e4SLinus Torvalds 5585f784336SWolfram Sang debug(skt, 2, "map %u speed %u start 0x%08llx stop 0x%08llx\n", 5595f784336SWolfram Sang map->map, map->speed, (unsigned long long)map->start, 5605f784336SWolfram Sang (unsigned long long)map->stop); 5611da177e4SLinus Torvalds debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n", 5621da177e4SLinus Torvalds (map->flags == 0) ? "<NONE>" : "", 5631da177e4SLinus Torvalds (map->flags & MAP_ACTIVE) ? "ACTIVE " : "", 5641da177e4SLinus Torvalds (map->flags & MAP_16BIT) ? "16BIT " : "", 5651da177e4SLinus Torvalds (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "", 5661da177e4SLinus Torvalds (map->flags & MAP_0WS) ? "0WS " : "", 5671da177e4SLinus Torvalds (map->flags & MAP_WRPROT) ? "WRPROT " : "", 5681da177e4SLinus Torvalds (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : "", 5691da177e4SLinus Torvalds (map->flags & MAP_PREFETCH) ? "PREFETCH " : ""); 5701da177e4SLinus Torvalds 5711da177e4SLinus Torvalds if (map->map >= MAX_IO_WIN) { 5722e11cb4cSHarvey Harrison printk(KERN_ERR "%s(): map (%d) out of range\n", __func__, 5731da177e4SLinus Torvalds map->map); 5741da177e4SLinus Torvalds return -1; 5751da177e4SLinus Torvalds } 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds if (map->flags & MAP_ACTIVE) { 5781da177e4SLinus Torvalds if (speed == 0) 5791da177e4SLinus Torvalds speed = SOC_PCMCIA_IO_ACCESS; 5801da177e4SLinus Torvalds } else { 5811da177e4SLinus Torvalds speed = 0; 5821da177e4SLinus Torvalds } 5831da177e4SLinus Torvalds 5841da177e4SLinus Torvalds skt->spd_io[map->map] = speed; 5851da177e4SLinus Torvalds skt->ops->set_timing(skt); 5861da177e4SLinus Torvalds 5871da177e4SLinus Torvalds if (map->stop == 1) 5881da177e4SLinus Torvalds map->stop = PAGE_SIZE-1; 5891da177e4SLinus Torvalds 5901da177e4SLinus Torvalds map->stop -= map->start; 5911da177e4SLinus Torvalds map->stop += skt->socket.io_offset; 5921da177e4SLinus Torvalds map->start = skt->socket.io_offset; 5931da177e4SLinus Torvalds 5941da177e4SLinus Torvalds return 0; 5951da177e4SLinus Torvalds } 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds 5981da177e4SLinus Torvalds /* 5991da177e4SLinus Torvalds * Implements the set_mem_map() operation for the in-kernel PCMCIA 6001da177e4SLinus Torvalds * service (formerly SS_SetMemMap in Card Services). We configure 6011da177e4SLinus Torvalds * the map speed as requested, but override the address ranges 6021da177e4SLinus Torvalds * supplied by Card Services. 6031da177e4SLinus Torvalds * 6044846d017SPavel Machek * Returns: 0 on success, -ERRNO on error 6051da177e4SLinus Torvalds */ 60617b38ebbSMarcelo Roberto Jimenez static int soc_common_pcmcia_set_mem_map( 60717b38ebbSMarcelo Roberto Jimenez struct pcmcia_socket *sock, struct pccard_mem_map *map) 6081da177e4SLinus Torvalds { 6091da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 6101da177e4SLinus Torvalds struct resource *res; 6111da177e4SLinus Torvalds unsigned short speed = map->speed; 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds debug(skt, 2, "map %u speed %u card_start %08x\n", 6141da177e4SLinus Torvalds map->map, map->speed, map->card_start); 6151da177e4SLinus Torvalds debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n", 6161da177e4SLinus Torvalds (map->flags == 0) ? "<NONE>" : "", 6171da177e4SLinus Torvalds (map->flags & MAP_ACTIVE) ? "ACTIVE " : "", 6181da177e4SLinus Torvalds (map->flags & MAP_16BIT) ? "16BIT " : "", 6191da177e4SLinus Torvalds (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "", 6201da177e4SLinus Torvalds (map->flags & MAP_0WS) ? "0WS " : "", 6211da177e4SLinus Torvalds (map->flags & MAP_WRPROT) ? "WRPROT " : "", 6221da177e4SLinus Torvalds (map->flags & MAP_ATTRIB) ? "ATTRIB " : "", 6231da177e4SLinus Torvalds (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : ""); 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds if (map->map >= MAX_WIN) 6261da177e4SLinus Torvalds return -EINVAL; 6271da177e4SLinus Torvalds 6281da177e4SLinus Torvalds if (map->flags & MAP_ACTIVE) { 6291da177e4SLinus Torvalds if (speed == 0) 6301da177e4SLinus Torvalds speed = 300; 6311da177e4SLinus Torvalds } else { 6321da177e4SLinus Torvalds speed = 0; 6331da177e4SLinus Torvalds } 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds if (map->flags & MAP_ATTRIB) { 6361da177e4SLinus Torvalds res = &skt->res_attr; 6371da177e4SLinus Torvalds skt->spd_attr[map->map] = speed; 6381da177e4SLinus Torvalds skt->spd_mem[map->map] = 0; 6391da177e4SLinus Torvalds } else { 6401da177e4SLinus Torvalds res = &skt->res_mem; 6411da177e4SLinus Torvalds skt->spd_attr[map->map] = 0; 6421da177e4SLinus Torvalds skt->spd_mem[map->map] = speed; 6431da177e4SLinus Torvalds } 6441da177e4SLinus Torvalds 6451da177e4SLinus Torvalds skt->ops->set_timing(skt); 6461da177e4SLinus Torvalds 6471da177e4SLinus Torvalds map->static_start = res->start + map->card_start; 6481da177e4SLinus Torvalds 6491da177e4SLinus Torvalds return 0; 6501da177e4SLinus Torvalds } 6511da177e4SLinus Torvalds 6521da177e4SLinus Torvalds struct bittbl { 6531da177e4SLinus Torvalds unsigned int mask; 6541da177e4SLinus Torvalds const char *name; 6551da177e4SLinus Torvalds }; 6561da177e4SLinus Torvalds 6571da177e4SLinus Torvalds static struct bittbl status_bits[] = { 6581da177e4SLinus Torvalds { SS_WRPROT, "SS_WRPROT" }, 6591da177e4SLinus Torvalds { SS_BATDEAD, "SS_BATDEAD" }, 6601da177e4SLinus Torvalds { SS_BATWARN, "SS_BATWARN" }, 6611da177e4SLinus Torvalds { SS_READY, "SS_READY" }, 6621da177e4SLinus Torvalds { SS_DETECT, "SS_DETECT" }, 6631da177e4SLinus Torvalds { SS_POWERON, "SS_POWERON" }, 6641da177e4SLinus Torvalds { SS_STSCHG, "SS_STSCHG" }, 6651da177e4SLinus Torvalds { SS_3VCARD, "SS_3VCARD" }, 6661da177e4SLinus Torvalds { SS_XVCARD, "SS_XVCARD" }, 6671da177e4SLinus Torvalds }; 6681da177e4SLinus Torvalds 6691da177e4SLinus Torvalds static struct bittbl conf_bits[] = { 6701da177e4SLinus Torvalds { SS_PWR_AUTO, "SS_PWR_AUTO" }, 6711da177e4SLinus Torvalds { SS_IOCARD, "SS_IOCARD" }, 6721da177e4SLinus Torvalds { SS_RESET, "SS_RESET" }, 6731da177e4SLinus Torvalds { SS_DMA_MODE, "SS_DMA_MODE" }, 6741da177e4SLinus Torvalds { SS_SPKR_ENA, "SS_SPKR_ENA" }, 6751da177e4SLinus Torvalds { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" }, 6761da177e4SLinus Torvalds }; 6771da177e4SLinus Torvalds 67817b38ebbSMarcelo Roberto Jimenez static void dump_bits(char **p, const char *prefix, 67917b38ebbSMarcelo Roberto Jimenez unsigned int val, struct bittbl *bits, int sz) 6801da177e4SLinus Torvalds { 6811da177e4SLinus Torvalds char *b = *p; 6821da177e4SLinus Torvalds int i; 6831da177e4SLinus Torvalds 6841da177e4SLinus Torvalds b += sprintf(b, "%-9s:", prefix); 6851da177e4SLinus Torvalds for (i = 0; i < sz; i++) 6861da177e4SLinus Torvalds if (val & bits[i].mask) 6871da177e4SLinus Torvalds b += sprintf(b, " %s", bits[i].name); 6881da177e4SLinus Torvalds *b++ = '\n'; 6891da177e4SLinus Torvalds *p = b; 6901da177e4SLinus Torvalds } 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds /* 6931da177e4SLinus Torvalds * Implements the /sys/class/pcmcia_socket/??/status file. 6941da177e4SLinus Torvalds * 6951da177e4SLinus Torvalds * Returns: the number of characters added to the buffer 6961da177e4SLinus Torvalds */ 69717b38ebbSMarcelo Roberto Jimenez static ssize_t show_status( 69817b38ebbSMarcelo Roberto Jimenez struct device *dev, struct device_attribute *attr, char *buf) 6991da177e4SLinus Torvalds { 7001da177e4SLinus Torvalds struct soc_pcmcia_socket *skt = 70187373318SGreg Kroah-Hartman container_of(dev, struct soc_pcmcia_socket, socket.dev); 7021da177e4SLinus Torvalds char *p = buf; 7031da177e4SLinus Torvalds 7041da177e4SLinus Torvalds p += sprintf(p, "slot : %d\n", skt->nr); 7051da177e4SLinus Torvalds 7061da177e4SLinus Torvalds dump_bits(&p, "status", skt->status, 7071da177e4SLinus Torvalds status_bits, ARRAY_SIZE(status_bits)); 7081da177e4SLinus Torvalds dump_bits(&p, "csc_mask", skt->cs_state.csc_mask, 7091da177e4SLinus Torvalds status_bits, ARRAY_SIZE(status_bits)); 7101da177e4SLinus Torvalds dump_bits(&p, "cs_flags", skt->cs_state.flags, 7111da177e4SLinus Torvalds conf_bits, ARRAY_SIZE(conf_bits)); 7121da177e4SLinus Torvalds 7131da177e4SLinus Torvalds p += sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc); 7141da177e4SLinus Torvalds p += sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp); 71566024db5SRussell King - ARM Linux p += sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq, 71666024db5SRussell King - ARM Linux skt->socket.pci_irq); 7171da177e4SLinus Torvalds if (skt->ops->show_timing) 7181da177e4SLinus Torvalds p += skt->ops->show_timing(skt, p); 7191da177e4SLinus Torvalds 7201da177e4SLinus Torvalds return p-buf; 7211da177e4SLinus Torvalds } 722e4a3c3f0SAlexey Dobriyan static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); 7231da177e4SLinus Torvalds 7241da177e4SLinus Torvalds 7251da177e4SLinus Torvalds static struct pccard_operations soc_common_pcmcia_operations = { 7261da177e4SLinus Torvalds .init = soc_common_pcmcia_sock_init, 7271da177e4SLinus Torvalds .suspend = soc_common_pcmcia_suspend, 7281da177e4SLinus Torvalds .get_status = soc_common_pcmcia_get_status, 7291da177e4SLinus Torvalds .set_socket = soc_common_pcmcia_set_socket, 7301da177e4SLinus Torvalds .set_io_map = soc_common_pcmcia_set_io_map, 7311da177e4SLinus Torvalds .set_mem_map = soc_common_pcmcia_set_mem_map, 7321da177e4SLinus Torvalds }; 7331da177e4SLinus Torvalds 7341da177e4SLinus Torvalds 735097e296dSRussell King - ARM Linux static LIST_HEAD(soc_pcmcia_sockets); 73623d077e2SAndrew Morton static DEFINE_MUTEX(soc_pcmcia_sockets_lock); 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds #ifdef CONFIG_CPU_FREQ 7391da177e4SLinus Torvalds static int 7401da177e4SLinus Torvalds soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data) 7411da177e4SLinus Torvalds { 7421da177e4SLinus Torvalds struct soc_pcmcia_socket *skt; 7431da177e4SLinus Torvalds struct cpufreq_freqs *freqs = data; 7441da177e4SLinus Torvalds int ret = 0; 7451da177e4SLinus Torvalds 74623d077e2SAndrew Morton mutex_lock(&soc_pcmcia_sockets_lock); 7471da177e4SLinus Torvalds list_for_each_entry(skt, &soc_pcmcia_sockets, node) 7481da177e4SLinus Torvalds if (skt->ops->frequency_change) 7491da177e4SLinus Torvalds ret += skt->ops->frequency_change(skt, val, freqs); 75023d077e2SAndrew Morton mutex_unlock(&soc_pcmcia_sockets_lock); 7511da177e4SLinus Torvalds 7521da177e4SLinus Torvalds return ret; 7531da177e4SLinus Torvalds } 7541da177e4SLinus Torvalds 7551da177e4SLinus Torvalds static struct notifier_block soc_pcmcia_notifier_block = { 7561da177e4SLinus Torvalds .notifier_call = soc_pcmcia_notifier 7571da177e4SLinus Torvalds }; 7581da177e4SLinus Torvalds 7591da177e4SLinus Torvalds static int soc_pcmcia_cpufreq_register(void) 7601da177e4SLinus Torvalds { 7611da177e4SLinus Torvalds int ret; 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block, 7641da177e4SLinus Torvalds CPUFREQ_TRANSITION_NOTIFIER); 7651da177e4SLinus Torvalds if (ret < 0) 7661da177e4SLinus Torvalds printk(KERN_ERR "Unable to register CPU frequency change " 7671da177e4SLinus Torvalds "notifier for PCMCIA (%d)\n", ret); 7681da177e4SLinus Torvalds return ret; 7691da177e4SLinus Torvalds } 7700f767de6SRussell King - ARM Linux fs_initcall(soc_pcmcia_cpufreq_register); 7711da177e4SLinus Torvalds 7721da177e4SLinus Torvalds static void soc_pcmcia_cpufreq_unregister(void) 7731da177e4SLinus Torvalds { 77417b38ebbSMarcelo Roberto Jimenez cpufreq_unregister_notifier(&soc_pcmcia_notifier_block, 77517b38ebbSMarcelo Roberto Jimenez CPUFREQ_TRANSITION_NOTIFIER); 7761da177e4SLinus Torvalds } 7770f767de6SRussell King - ARM Linux module_exit(soc_pcmcia_cpufreq_unregister); 7781da177e4SLinus Torvalds 7791da177e4SLinus Torvalds #endif 7801da177e4SLinus Torvalds 781e0d21178SRussell King void soc_pcmcia_init_one(struct soc_pcmcia_socket *skt, 782e0d21178SRussell King struct pcmcia_low_level *ops, struct device *dev) 783e0d21178SRussell King { 784d9dc8787SRussell King int i; 785d9dc8787SRussell King 786e0d21178SRussell King skt->ops = ops; 787e0d21178SRussell King skt->socket.owner = ops->owner; 788e0d21178SRussell King skt->socket.dev.parent = dev; 789e0d21178SRussell King skt->socket.pci_irq = NO_IRQ; 790d9dc8787SRussell King 791d9dc8787SRussell King for (i = 0; i < ARRAY_SIZE(skt->stat); i++) 792d9dc8787SRussell King skt->stat[i].gpio = -EINVAL; 793e0d21178SRussell King } 794e0d21178SRussell King EXPORT_SYMBOL(soc_pcmcia_init_one); 795e0d21178SRussell King 796097e296dSRussell King - ARM Linux void soc_pcmcia_remove_one(struct soc_pcmcia_socket *skt) 7971da177e4SLinus Torvalds { 79823d077e2SAndrew Morton mutex_lock(&soc_pcmcia_sockets_lock); 799097e296dSRussell King - ARM Linux del_timer_sync(&skt->poll_timer); 8001da177e4SLinus Torvalds 801097e296dSRussell King - ARM Linux pcmcia_unregister_socket(&skt->socket); 8021da177e4SLinus Torvalds 803d9dc8787SRussell King soc_pcmcia_hw_shutdown(skt); 804097e296dSRussell King - ARM Linux 805d9dc8787SRussell King /* should not be required; violates some lowlevel drivers */ 806097e296dSRussell King - ARM Linux soc_common_pcmcia_config_skt(skt, &dead_socket); 807097e296dSRussell King - ARM Linux 808097e296dSRussell King - ARM Linux list_del(&skt->node); 809097e296dSRussell King - ARM Linux mutex_unlock(&soc_pcmcia_sockets_lock); 810097e296dSRussell King - ARM Linux 811097e296dSRussell King - ARM Linux iounmap(skt->virt_io); 812097e296dSRussell King - ARM Linux skt->virt_io = NULL; 813097e296dSRussell King - ARM Linux release_resource(&skt->res_attr); 814097e296dSRussell King - ARM Linux release_resource(&skt->res_mem); 815097e296dSRussell King - ARM Linux release_resource(&skt->res_io); 816097e296dSRussell King - ARM Linux release_resource(&skt->res_skt); 817097e296dSRussell King - ARM Linux } 818097e296dSRussell King - ARM Linux EXPORT_SYMBOL(soc_pcmcia_remove_one); 819097e296dSRussell King - ARM Linux 820097e296dSRussell King - ARM Linux int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt) 821097e296dSRussell King - ARM Linux { 822097e296dSRussell King - ARM Linux int ret; 8231da177e4SLinus Torvalds 8246ac95d82SRussell King skt->cs_state = dead_socket; 8256ac95d82SRussell King 826dae6cdabSVaishali Thakkar setup_timer(&skt->poll_timer, soc_common_pcmcia_poll_event, 827dae6cdabSVaishali Thakkar (unsigned long)skt); 8281da177e4SLinus Torvalds skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD; 8291da177e4SLinus Torvalds 8301da177e4SLinus Torvalds ret = request_resource(&iomem_resource, &skt->res_skt); 8311da177e4SLinus Torvalds if (ret) 8321da177e4SLinus Torvalds goto out_err_1; 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds ret = request_resource(&skt->res_skt, &skt->res_io); 8351da177e4SLinus Torvalds if (ret) 8361da177e4SLinus Torvalds goto out_err_2; 8371da177e4SLinus Torvalds 8381da177e4SLinus Torvalds ret = request_resource(&skt->res_skt, &skt->res_mem); 8391da177e4SLinus Torvalds if (ret) 8401da177e4SLinus Torvalds goto out_err_3; 8411da177e4SLinus Torvalds 8421da177e4SLinus Torvalds ret = request_resource(&skt->res_skt, &skt->res_attr); 8431da177e4SLinus Torvalds if (ret) 8441da177e4SLinus Torvalds goto out_err_4; 8451da177e4SLinus Torvalds 8461da177e4SLinus Torvalds skt->virt_io = ioremap(skt->res_io.start, 0x10000); 8471da177e4SLinus Torvalds if (skt->virt_io == NULL) { 8481da177e4SLinus Torvalds ret = -ENOMEM; 8491da177e4SLinus Torvalds goto out_err_5; 8501da177e4SLinus Torvalds } 8511da177e4SLinus Torvalds 852097e296dSRussell King - ARM Linux mutex_lock(&soc_pcmcia_sockets_lock); 853097e296dSRussell King - ARM Linux 8541da177e4SLinus Torvalds list_add(&skt->node, &soc_pcmcia_sockets); 8551da177e4SLinus Torvalds 8561da177e4SLinus Torvalds /* 8571da177e4SLinus Torvalds * We initialize default socket timing here, because 8581da177e4SLinus Torvalds * we are not guaranteed to see a SetIOMap operation at 8591da177e4SLinus Torvalds * runtime. 8601da177e4SLinus Torvalds */ 861097e296dSRussell King - ARM Linux skt->ops->set_timing(skt); 8621da177e4SLinus Torvalds 863d9dc8787SRussell King ret = soc_pcmcia_hw_init(skt); 8641da177e4SLinus Torvalds if (ret) 8651da177e4SLinus Torvalds goto out_err_6; 8661da177e4SLinus Torvalds 867097e296dSRussell King - ARM Linux skt->socket.ops = &soc_common_pcmcia_operations; 8681da177e4SLinus Torvalds skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD; 8691da177e4SLinus Torvalds skt->socket.resource_ops = &pccard_static_ops; 8701da177e4SLinus Torvalds skt->socket.irq_mask = 0; 8711da177e4SLinus Torvalds skt->socket.map_size = PAGE_SIZE; 8721da177e4SLinus Torvalds skt->socket.io_offset = (unsigned long)skt->virt_io; 8731da177e4SLinus Torvalds 8741da177e4SLinus Torvalds skt->status = soc_common_pcmcia_skt_state(skt); 8751da177e4SLinus Torvalds 8761da177e4SLinus Torvalds ret = pcmcia_register_socket(&skt->socket); 8771da177e4SLinus Torvalds if (ret) 8781da177e4SLinus Torvalds goto out_err_7; 8791da177e4SLinus Torvalds 8801da177e4SLinus Torvalds add_timer(&skt->poll_timer); 8811da177e4SLinus Torvalds 882097e296dSRussell King - ARM Linux mutex_unlock(&soc_pcmcia_sockets_lock); 883097e296dSRussell King - ARM Linux 884632480eaSJürgen Schindele ret = device_create_file(&skt->socket.dev, &dev_attr_status); 885632480eaSJürgen Schindele if (ret) 886632480eaSJürgen Schindele goto out_err_8; 8871da177e4SLinus Torvalds 888097e296dSRussell King - ARM Linux return ret; 8891da177e4SLinus Torvalds 890632480eaSJürgen Schindele out_err_8: 891097e296dSRussell King - ARM Linux mutex_lock(&soc_pcmcia_sockets_lock); 8921da177e4SLinus Torvalds del_timer_sync(&skt->poll_timer); 8931da177e4SLinus Torvalds pcmcia_unregister_socket(&skt->socket); 8941da177e4SLinus Torvalds 8951da177e4SLinus Torvalds out_err_7: 896d9dc8787SRussell King soc_pcmcia_hw_shutdown(skt); 8971da177e4SLinus Torvalds out_err_6: 8981da177e4SLinus Torvalds list_del(&skt->node); 899097e296dSRussell King - ARM Linux mutex_unlock(&soc_pcmcia_sockets_lock); 9001da177e4SLinus Torvalds iounmap(skt->virt_io); 9011da177e4SLinus Torvalds out_err_5: 9021da177e4SLinus Torvalds release_resource(&skt->res_attr); 9031da177e4SLinus Torvalds out_err_4: 9041da177e4SLinus Torvalds release_resource(&skt->res_mem); 9051da177e4SLinus Torvalds out_err_3: 9061da177e4SLinus Torvalds release_resource(&skt->res_io); 9071da177e4SLinus Torvalds out_err_2: 9081da177e4SLinus Torvalds release_resource(&skt->res_skt); 9091da177e4SLinus Torvalds out_err_1: 9101da177e4SLinus Torvalds 911097e296dSRussell King - ARM Linux return ret; 912097e296dSRussell King - ARM Linux } 913097e296dSRussell King - ARM Linux EXPORT_SYMBOL(soc_pcmcia_add_one); 914097e296dSRussell King - ARM Linux 9150f767de6SRussell King - ARM Linux MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>"); 9160f767de6SRussell King - ARM Linux MODULE_DESCRIPTION("Linux PCMCIA Card Services: Common SoC support"); 9170f767de6SRussell King - ARM Linux MODULE_LICENSE("Dual MPL/GPL"); 918