Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /*====================================================================== |
| 2 | |
| 3 | Device driver for the PCMCIA control functionality of PXA2xx |
| 4 | microprocessors. |
| 5 | |
| 6 | The contents of this file may be used under the |
| 7 | terms of the GNU Public License version 2 (the "GPL") |
| 8 | |
| 9 | (c) Ian Molton (spyro@f2s.com) 2003 |
| 10 | (c) Stefan Eletzhofer (stefan.eletzhofer@inquant.de) 2003,4 |
| 11 | |
| 12 | derived from sa11xx_base.c |
| 13 | |
| 14 | Portions created by John G. Dorsey are |
| 15 | Copyright (C) 1999 John G. Dorsey. |
| 16 | |
| 17 | ======================================================================*/ |
| 18 | |
| 19 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/cpufreq.h> |
| 23 | #include <linux/ioport.h> |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/spinlock.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 26 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 28 | #include <mach/hardware.h> |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 29 | #include <mach/smemc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/io.h> |
| 31 | #include <asm/irq.h> |
| 32 | #include <asm/system.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 33 | #include <mach/pxa2xx-regs.h> |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 34 | #include <asm/mach-types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <pcmcia/ss.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <pcmcia/cistpl.h> |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "soc_common.h" |
| 40 | #include "pxa2xx_base.h" |
| 41 | |
Eric Miao | b393c69 | 2009-01-19 17:34:27 +0800 | [diff] [blame] | 42 | /* |
| 43 | * Personal Computer Memory Card International Association (PCMCIA) sockets |
| 44 | */ |
| 45 | |
| 46 | #define PCMCIAPrtSp 0x04000000 /* PCMCIA Partition Space [byte] */ |
| 47 | #define PCMCIASp (4*PCMCIAPrtSp) /* PCMCIA Space [byte] */ |
| 48 | #define PCMCIAIOSp PCMCIAPrtSp /* PCMCIA I/O Space [byte] */ |
| 49 | #define PCMCIAAttrSp PCMCIAPrtSp /* PCMCIA Attribute Space [byte] */ |
| 50 | #define PCMCIAMemSp PCMCIAPrtSp /* PCMCIA Memory Space [byte] */ |
| 51 | |
| 52 | #define PCMCIA0Sp PCMCIASp /* PCMCIA 0 Space [byte] */ |
| 53 | #define PCMCIA0IOSp PCMCIAIOSp /* PCMCIA 0 I/O Space [byte] */ |
| 54 | #define PCMCIA0AttrSp PCMCIAAttrSp /* PCMCIA 0 Attribute Space [byte] */ |
| 55 | #define PCMCIA0MemSp PCMCIAMemSp /* PCMCIA 0 Memory Space [byte] */ |
| 56 | |
| 57 | #define PCMCIA1Sp PCMCIASp /* PCMCIA 1 Space [byte] */ |
| 58 | #define PCMCIA1IOSp PCMCIAIOSp /* PCMCIA 1 I/O Space [byte] */ |
| 59 | #define PCMCIA1AttrSp PCMCIAAttrSp /* PCMCIA 1 Attribute Space [byte] */ |
| 60 | #define PCMCIA1MemSp PCMCIAMemSp /* PCMCIA 1 Memory Space [byte] */ |
| 61 | |
| 62 | #define _PCMCIA(Nb) /* PCMCIA [0..1] */ \ |
| 63 | (0x20000000 + (Nb) * PCMCIASp) |
| 64 | #define _PCMCIAIO(Nb) _PCMCIA(Nb) /* PCMCIA I/O [0..1] */ |
| 65 | #define _PCMCIAAttr(Nb) /* PCMCIA Attribute [0..1] */ \ |
| 66 | (_PCMCIA(Nb) + 2 * PCMCIAPrtSp) |
| 67 | #define _PCMCIAMem(Nb) /* PCMCIA Memory [0..1] */ \ |
| 68 | (_PCMCIA(Nb) + 3 * PCMCIAPrtSp) |
| 69 | |
| 70 | #define _PCMCIA0 _PCMCIA(0) /* PCMCIA 0 */ |
| 71 | #define _PCMCIA0IO _PCMCIAIO(0) /* PCMCIA 0 I/O */ |
| 72 | #define _PCMCIA0Attr _PCMCIAAttr(0) /* PCMCIA 0 Attribute */ |
| 73 | #define _PCMCIA0Mem _PCMCIAMem(0) /* PCMCIA 0 Memory */ |
| 74 | |
| 75 | #define _PCMCIA1 _PCMCIA(1) /* PCMCIA 1 */ |
| 76 | #define _PCMCIA1IO _PCMCIAIO(1) /* PCMCIA 1 I/O */ |
| 77 | #define _PCMCIA1Attr _PCMCIAAttr(1) /* PCMCIA 1 Attribute */ |
| 78 | #define _PCMCIA1Mem _PCMCIAMem(1) /* PCMCIA 1 Memory */ |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | #define MCXX_SETUP_MASK (0x7f) |
| 82 | #define MCXX_ASST_MASK (0x1f) |
| 83 | #define MCXX_HOLD_MASK (0x3f) |
| 84 | #define MCXX_SETUP_SHIFT (0) |
| 85 | #define MCXX_ASST_SHIFT (7) |
| 86 | #define MCXX_HOLD_SHIFT (14) |
| 87 | |
| 88 | static inline u_int pxa2xx_mcxx_hold(u_int pcmcia_cycle_ns, |
| 89 | u_int mem_clk_10khz) |
| 90 | { |
| 91 | u_int code = pcmcia_cycle_ns * mem_clk_10khz; |
| 92 | return (code / 300000) + ((code % 300000) ? 1 : 0) - 1; |
| 93 | } |
| 94 | |
| 95 | static inline u_int pxa2xx_mcxx_asst(u_int pcmcia_cycle_ns, |
| 96 | u_int mem_clk_10khz) |
| 97 | { |
| 98 | u_int code = pcmcia_cycle_ns * mem_clk_10khz; |
Milan Plzik | 24d6572 | 2007-10-16 01:23:49 -0700 | [diff] [blame] | 99 | return (code / 300000) + ((code % 300000) ? 1 : 0) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | static inline u_int pxa2xx_mcxx_setup(u_int pcmcia_cycle_ns, |
| 103 | u_int mem_clk_10khz) |
| 104 | { |
| 105 | u_int code = pcmcia_cycle_ns * mem_clk_10khz; |
| 106 | return (code / 100000) + ((code % 100000) ? 1 : 0) - 1; |
| 107 | } |
| 108 | |
| 109 | /* This function returns the (approximate) command assertion period, in |
| 110 | * nanoseconds, for a given CPU clock frequency and MCXX_ASST value: |
| 111 | */ |
| 112 | static inline u_int pxa2xx_pcmcia_cmd_time(u_int mem_clk_10khz, |
| 113 | u_int pcmcia_mcxx_asst) |
| 114 | { |
| 115 | return (300000 * (pcmcia_mcxx_asst + 1) / mem_clk_10khz); |
| 116 | } |
| 117 | |
| 118 | static int pxa2xx_pcmcia_set_mcmem( int sock, int speed, int clock ) |
| 119 | { |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 120 | uint32_t val; |
| 121 | |
| 122 | val = ((pxa2xx_mcxx_setup(speed, clock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | & MCXX_SETUP_MASK) << MCXX_SETUP_SHIFT) |
| 124 | | ((pxa2xx_mcxx_asst(speed, clock) |
| 125 | & MCXX_ASST_MASK) << MCXX_ASST_SHIFT) |
| 126 | | ((pxa2xx_mcxx_hold(speed, clock) |
| 127 | & MCXX_HOLD_MASK) << MCXX_HOLD_SHIFT); |
| 128 | |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 129 | __raw_writel(val, MCMEM(sock)); |
| 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static int pxa2xx_pcmcia_set_mcio( int sock, int speed, int clock ) |
| 135 | { |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 136 | uint32_t val; |
| 137 | |
| 138 | val = ((pxa2xx_mcxx_setup(speed, clock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | & MCXX_SETUP_MASK) << MCXX_SETUP_SHIFT) |
| 140 | | ((pxa2xx_mcxx_asst(speed, clock) |
| 141 | & MCXX_ASST_MASK) << MCXX_ASST_SHIFT) |
| 142 | | ((pxa2xx_mcxx_hold(speed, clock) |
| 143 | & MCXX_HOLD_MASK) << MCXX_HOLD_SHIFT); |
| 144 | |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 145 | __raw_writel(val, MCIO(sock)); |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | static int pxa2xx_pcmcia_set_mcatt( int sock, int speed, int clock ) |
| 151 | { |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 152 | uint32_t val; |
| 153 | |
| 154 | val = ((pxa2xx_mcxx_setup(speed, clock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | & MCXX_SETUP_MASK) << MCXX_SETUP_SHIFT) |
| 156 | | ((pxa2xx_mcxx_asst(speed, clock) |
| 157 | & MCXX_ASST_MASK) << MCXX_ASST_SHIFT) |
| 158 | | ((pxa2xx_mcxx_hold(speed, clock) |
| 159 | & MCXX_HOLD_MASK) << MCXX_HOLD_SHIFT); |
| 160 | |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 161 | __raw_writel(val, MCATT(sock)); |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static int pxa2xx_pcmcia_set_mcxx(struct soc_pcmcia_socket *skt, unsigned int clk) |
| 167 | { |
| 168 | struct soc_pcmcia_timing timing; |
| 169 | int sock = skt->nr; |
| 170 | |
| 171 | soc_common_pcmcia_get_timing(skt, &timing); |
| 172 | |
| 173 | pxa2xx_pcmcia_set_mcmem(sock, timing.mem, clk); |
| 174 | pxa2xx_pcmcia_set_mcatt(sock, timing.attr, clk); |
| 175 | pxa2xx_pcmcia_set_mcio(sock, timing.io, clk); |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int pxa2xx_pcmcia_set_timing(struct soc_pcmcia_socket *skt) |
| 181 | { |
Eric Miao | 2a125dd | 2010-11-22 22:48:49 +0800 | [diff] [blame] | 182 | unsigned long clk = clk_get_rate(skt->clk); |
| 183 | return pxa2xx_pcmcia_set_mcxx(skt, clk / 10000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | #ifdef CONFIG_CPU_FREQ |
| 187 | |
| 188 | static int |
| 189 | pxa2xx_pcmcia_frequency_change(struct soc_pcmcia_socket *skt, |
| 190 | unsigned long val, |
| 191 | struct cpufreq_freqs *freqs) |
| 192 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | switch (val) { |
| 194 | case CPUFREQ_PRECHANGE: |
| 195 | if (freqs->new > freqs->old) { |
| 196 | debug(skt, 2, "new frequency %u.%uMHz > %u.%uMHz, " |
| 197 | "pre-updating\n", |
| 198 | freqs->new / 1000, (freqs->new / 100) % 10, |
| 199 | freqs->old / 1000, (freqs->old / 100) % 10); |
Marek Vasut | d344a21 | 2010-06-18 07:48:54 +0200 | [diff] [blame] | 200 | pxa2xx_pcmcia_set_timing(skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
| 202 | break; |
| 203 | |
| 204 | case CPUFREQ_POSTCHANGE: |
| 205 | if (freqs->new < freqs->old) { |
| 206 | debug(skt, 2, "new frequency %u.%uMHz < %u.%uMHz, " |
| 207 | "post-updating\n", |
| 208 | freqs->new / 1000, (freqs->new / 100) % 10, |
| 209 | freqs->old / 1000, (freqs->old / 100) % 10); |
Marek Vasut | d344a21 | 2010-06-18 07:48:54 +0200 | [diff] [blame] | 210 | pxa2xx_pcmcia_set_timing(skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | break; |
| 213 | } |
| 214 | return 0; |
| 215 | } |
| 216 | #endif |
| 217 | |
Pavel Machek | 5b70368 | 2011-02-04 09:03:43 +0100 | [diff] [blame] | 218 | void pxa2xx_configure_sockets(struct device *dev) |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 219 | { |
| 220 | struct pcmcia_low_level *ops = dev->platform_data; |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 221 | /* |
| 222 | * We have at least one socket, so set MECR:CIT |
| 223 | * (Card Is There) |
| 224 | */ |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 225 | uint32_t mecr = MECR_CIT; |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 226 | |
| 227 | /* Set MECR:NOS (Number Of Sockets) */ |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 228 | if ((ops->first + ops->nr) > 1 || |
| 229 | machine_is_viper() || machine_is_arcom_zeus()) |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 230 | mecr |= MECR_NOS; |
| 231 | |
| 232 | __raw_writel(mecr, MECR); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 233 | } |
Russell King | d5240df | 2011-10-27 11:33:15 +0100 | [diff] [blame] | 234 | EXPORT_SYMBOL(pxa2xx_configure_sockets); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 235 | |
Eric Miao | b393c69 | 2009-01-19 17:34:27 +0800 | [diff] [blame] | 236 | static const char *skt_names[] = { |
| 237 | "PCMCIA socket 0", |
| 238 | "PCMCIA socket 1", |
| 239 | }; |
| 240 | |
| 241 | #define SKT_DEV_INFO_SIZE(n) \ |
| 242 | (sizeof(struct skt_dev_info) + (n)*sizeof(struct soc_pcmcia_socket)) |
| 243 | |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 244 | int pxa2xx_drv_pcmcia_add_one(struct soc_pcmcia_socket *skt) |
Russell King - ARM Linux | da4f007 | 2009-03-29 19:23:42 +0100 | [diff] [blame] | 245 | { |
| 246 | skt->res_skt.start = _PCMCIA(skt->nr); |
| 247 | skt->res_skt.end = _PCMCIA(skt->nr) + PCMCIASp - 1; |
| 248 | skt->res_skt.name = skt_names[skt->nr]; |
| 249 | skt->res_skt.flags = IORESOURCE_MEM; |
| 250 | |
| 251 | skt->res_io.start = _PCMCIAIO(skt->nr); |
| 252 | skt->res_io.end = _PCMCIAIO(skt->nr) + PCMCIAIOSp - 1; |
| 253 | skt->res_io.name = "io"; |
| 254 | skt->res_io.flags = IORESOURCE_MEM | IORESOURCE_BUSY; |
| 255 | |
| 256 | skt->res_mem.start = _PCMCIAMem(skt->nr); |
| 257 | skt->res_mem.end = _PCMCIAMem(skt->nr) + PCMCIAMemSp - 1; |
| 258 | skt->res_mem.name = "memory"; |
| 259 | skt->res_mem.flags = IORESOURCE_MEM; |
| 260 | |
| 261 | skt->res_attr.start = _PCMCIAAttr(skt->nr); |
| 262 | skt->res_attr.end = _PCMCIAAttr(skt->nr) + PCMCIAAttrSp - 1; |
| 263 | skt->res_attr.name = "attribute"; |
| 264 | skt->res_attr.flags = IORESOURCE_MEM; |
| 265 | |
| 266 | return soc_pcmcia_add_one(skt); |
| 267 | } |
Russell King | d0d26c3 | 2009-12-12 10:07:34 +0000 | [diff] [blame] | 268 | EXPORT_SYMBOL(pxa2xx_drv_pcmcia_add_one); |
Russell King - ARM Linux | da4f007 | 2009-03-29 19:23:42 +0100 | [diff] [blame] | 269 | |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 270 | void pxa2xx_drv_pcmcia_ops(struct pcmcia_low_level *ops) |
| 271 | { |
| 272 | /* Provide our PXA2xx specific timing routines. */ |
| 273 | ops->set_timing = pxa2xx_pcmcia_set_timing; |
| 274 | #ifdef CONFIG_CPU_FREQ |
| 275 | ops->frequency_change = pxa2xx_pcmcia_frequency_change; |
| 276 | #endif |
| 277 | } |
Russell King | d0d26c3 | 2009-12-12 10:07:34 +0000 | [diff] [blame] | 278 | EXPORT_SYMBOL(pxa2xx_drv_pcmcia_ops); |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 279 | |
Russell King | d0d26c3 | 2009-12-12 10:07:34 +0000 | [diff] [blame] | 280 | static int pxa2xx_drv_pcmcia_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 282 | int i, ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | struct pcmcia_low_level *ops; |
Eric Miao | b393c69 | 2009-01-19 17:34:27 +0800 | [diff] [blame] | 284 | struct skt_dev_info *sinfo; |
| 285 | struct soc_pcmcia_socket *skt; |
Eric Miao | 2a125dd | 2010-11-22 22:48:49 +0800 | [diff] [blame] | 286 | struct clk *clk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Russell King | d0d26c3 | 2009-12-12 10:07:34 +0000 | [diff] [blame] | 288 | ops = (struct pcmcia_low_level *)dev->dev.platform_data; |
Marek Vasut | a4257af | 2010-11-03 16:26:42 +0100 | [diff] [blame] | 289 | if (!ops) { |
| 290 | ret = -ENODEV; |
| 291 | goto err0; |
| 292 | } |
| 293 | |
| 294 | if (cpu_is_pxa320() && ops->nr > 1) { |
| 295 | dev_err(&dev->dev, "pxa320 supports only one pcmcia slot"); |
| 296 | ret = -EINVAL; |
| 297 | goto err0; |
| 298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Eric Miao | 2a125dd | 2010-11-22 22:48:49 +0800 | [diff] [blame] | 300 | clk = clk_get(&dev->dev, NULL); |
| 301 | if (!clk) |
| 302 | return -ENODEV; |
| 303 | |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 304 | pxa2xx_drv_pcmcia_ops(ops); |
Russell King - ARM Linux | da4f007 | 2009-03-29 19:23:42 +0100 | [diff] [blame] | 305 | |
Eric Miao | b393c69 | 2009-01-19 17:34:27 +0800 | [diff] [blame] | 306 | sinfo = kzalloc(SKT_DEV_INFO_SIZE(ops->nr), GFP_KERNEL); |
Eric Miao | 2a125dd | 2010-11-22 22:48:49 +0800 | [diff] [blame] | 307 | if (!sinfo) { |
| 308 | clk_put(clk); |
Eric Miao | b393c69 | 2009-01-19 17:34:27 +0800 | [diff] [blame] | 309 | return -ENOMEM; |
Eric Miao | 2a125dd | 2010-11-22 22:48:49 +0800 | [diff] [blame] | 310 | } |
Eric Miao | b393c69 | 2009-01-19 17:34:27 +0800 | [diff] [blame] | 311 | |
| 312 | sinfo->nskt = ops->nr; |
Eric Miao | 2a125dd | 2010-11-22 22:48:49 +0800 | [diff] [blame] | 313 | sinfo->clk = clk; |
Eric Miao | b393c69 | 2009-01-19 17:34:27 +0800 | [diff] [blame] | 314 | |
| 315 | /* Initialize processor specific parameters */ |
| 316 | for (i = 0; i < ops->nr; i++) { |
| 317 | skt = &sinfo->skt[i]; |
| 318 | |
Russell King - ARM Linux | da4f007 | 2009-03-29 19:23:42 +0100 | [diff] [blame] | 319 | skt->nr = ops->first + i; |
Eric Miao | 2a125dd | 2010-11-22 22:48:49 +0800 | [diff] [blame] | 320 | skt->clk = clk; |
Russell King - ARM Linux | da4f007 | 2009-03-29 19:23:42 +0100 | [diff] [blame] | 321 | skt->ops = ops; |
| 322 | skt->socket.owner = ops->owner; |
Marc Zyngier | a7a5ac5 | 2009-12-15 21:11:21 +0100 | [diff] [blame] | 323 | skt->socket.dev.parent = &dev->dev; |
Russell King - ARM Linux | 66024db | 2009-03-29 22:45:26 +0100 | [diff] [blame] | 324 | skt->socket.pci_irq = NO_IRQ; |
Eric Miao | b393c69 | 2009-01-19 17:34:27 +0800 | [diff] [blame] | 325 | |
Russell King - ARM Linux | da4f007 | 2009-03-29 19:23:42 +0100 | [diff] [blame] | 326 | ret = pxa2xx_drv_pcmcia_add_one(skt); |
| 327 | if (ret) |
Marek Vasut | a4257af | 2010-11-03 16:26:42 +0100 | [diff] [blame] | 328 | goto err1; |
Eric Miao | b393c69 | 2009-01-19 17:34:27 +0800 | [diff] [blame] | 329 | } |
| 330 | |
Russell King - ARM Linux | da4f007 | 2009-03-29 19:23:42 +0100 | [diff] [blame] | 331 | if (ret) { |
| 332 | while (--i >= 0) |
| 333 | soc_pcmcia_remove_one(&sinfo->skt[i]); |
| 334 | kfree(sinfo); |
Eric Miao | 2a125dd | 2010-11-22 22:48:49 +0800 | [diff] [blame] | 335 | clk_put(clk); |
Russell King - ARM Linux | da4f007 | 2009-03-29 19:23:42 +0100 | [diff] [blame] | 336 | } else { |
Marc Zyngier | a7a5ac5 | 2009-12-15 21:11:21 +0100 | [diff] [blame] | 337 | pxa2xx_configure_sockets(&dev->dev); |
| 338 | dev_set_drvdata(&dev->dev, sinfo); |
Russell King - ARM Linux | da4f007 | 2009-03-29 19:23:42 +0100 | [diff] [blame] | 339 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Marek Vasut | a4257af | 2010-11-03 16:26:42 +0100 | [diff] [blame] | 341 | return 0; |
| 342 | |
| 343 | err1: |
| 344 | while (--i >= 0) |
| 345 | soc_pcmcia_remove_one(&sinfo->skt[i]); |
| 346 | kfree(sinfo); |
| 347 | err0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | return ret; |
| 349 | } |
Russell King | 9468613 | 2006-10-28 22:42:56 +0100 | [diff] [blame] | 350 | |
| 351 | static int pxa2xx_drv_pcmcia_remove(struct platform_device *dev) |
| 352 | { |
Russell King - ARM Linux | be85458 | 2009-03-26 22:21:18 +0000 | [diff] [blame] | 353 | struct skt_dev_info *sinfo = platform_get_drvdata(dev); |
| 354 | int i; |
| 355 | |
| 356 | platform_set_drvdata(dev, NULL); |
| 357 | |
| 358 | for (i = 0; i < sinfo->nskt; i++) |
| 359 | soc_pcmcia_remove_one(&sinfo->skt[i]); |
| 360 | |
Eric Miao | 2a125dd | 2010-11-22 22:48:49 +0800 | [diff] [blame] | 361 | clk_put(sinfo->clk); |
Russell King - ARM Linux | be85458 | 2009-03-26 22:21:18 +0000 | [diff] [blame] | 362 | kfree(sinfo); |
| 363 | return 0; |
Russell King | 9468613 | 2006-10-28 22:42:56 +0100 | [diff] [blame] | 364 | } |
| 365 | |
Mike Rapoport | 85c6102 | 2009-07-29 11:59:25 +0300 | [diff] [blame] | 366 | static int pxa2xx_drv_pcmcia_resume(struct device *dev) |
Russell King | 9468613 | 2006-10-28 22:42:56 +0100 | [diff] [blame] | 367 | { |
Mike Rapoport | 85c6102 | 2009-07-29 11:59:25 +0300 | [diff] [blame] | 368 | pxa2xx_configure_sockets(dev); |
Dominik Brodowski | d7646f7 | 2010-03-15 21:46:34 +0100 | [diff] [blame] | 369 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 372 | static const struct dev_pm_ops pxa2xx_drv_pcmcia_pm_ops = { |
Mike Rapoport | 85c6102 | 2009-07-29 11:59:25 +0300 | [diff] [blame] | 373 | .resume = pxa2xx_drv_pcmcia_resume, |
| 374 | }; |
| 375 | |
Russell King | 9468613 | 2006-10-28 22:42:56 +0100 | [diff] [blame] | 376 | static struct platform_driver pxa2xx_pcmcia_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | .probe = pxa2xx_drv_pcmcia_probe, |
Russell King | 9468613 | 2006-10-28 22:42:56 +0100 | [diff] [blame] | 378 | .remove = pxa2xx_drv_pcmcia_remove, |
Russell King | 9468613 | 2006-10-28 22:42:56 +0100 | [diff] [blame] | 379 | .driver = { |
| 380 | .name = "pxa2xx-pcmcia", |
Kay Sievers | 12c2c01 | 2008-04-15 14:34:34 -0700 | [diff] [blame] | 381 | .owner = THIS_MODULE, |
Mike Rapoport | 85c6102 | 2009-07-29 11:59:25 +0300 | [diff] [blame] | 382 | .pm = &pxa2xx_drv_pcmcia_pm_ops, |
Russell King | 9468613 | 2006-10-28 22:42:56 +0100 | [diff] [blame] | 383 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | }; |
| 385 | |
| 386 | static int __init pxa2xx_pcmcia_init(void) |
| 387 | { |
Russell King | 9468613 | 2006-10-28 22:42:56 +0100 | [diff] [blame] | 388 | return platform_driver_register(&pxa2xx_pcmcia_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static void __exit pxa2xx_pcmcia_exit(void) |
| 392 | { |
Russell King | 9468613 | 2006-10-28 22:42:56 +0100 | [diff] [blame] | 393 | platform_driver_unregister(&pxa2xx_pcmcia_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Richard Purdie | f36598ae | 2005-09-03 19:39:25 +0100 | [diff] [blame] | 396 | fs_initcall(pxa2xx_pcmcia_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | module_exit(pxa2xx_pcmcia_exit); |
| 398 | |
| 399 | MODULE_AUTHOR("Stefan Eletzhofer <stefan.eletzhofer@inquant.de> and Ian Molton <spyro@f2s.com>"); |
| 400 | MODULE_DESCRIPTION("Linux PCMCIA Card Services: PXA2xx core socket driver"); |
| 401 | MODULE_LICENSE("GPL"); |
Kay Sievers | 12c2c01 | 2008-04-15 14:34:34 -0700 | [diff] [blame] | 402 | MODULE_ALIAS("platform:pxa2xx-pcmcia"); |