Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/pcmcia/sa1111_generic.c |
| 3 | * |
| 4 | * We implement the generic parts of a SA1111 PCMCIA driver. This |
| 5 | * basically means we handle everything except controlling the |
| 6 | * power. Power is machine specific... |
| 7 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/module.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/ioport.h> |
| 11 | #include <linux/device.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/init.h> |
Russell King | 9973022 | 2009-03-25 10:21:35 +0000 | [diff] [blame] | 14 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #include <pcmcia/ss.h> |
| 18 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 19 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/hardware/sa1111.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/irq.h> |
| 22 | |
| 23 | #include "sa1111_generic.h" |
| 24 | |
Russell King | ea8c00a | 2012-01-16 11:32:09 +0000 | [diff] [blame] | 25 | /* |
| 26 | * These are offsets from the above base. |
| 27 | */ |
| 28 | #define PCCR 0x0000 |
| 29 | #define PCSSR 0x0004 |
| 30 | #define PCSR 0x0008 |
| 31 | |
| 32 | #define PCSR_S0_READY (1<<0) |
| 33 | #define PCSR_S1_READY (1<<1) |
| 34 | #define PCSR_S0_DETECT (1<<2) |
| 35 | #define PCSR_S1_DETECT (1<<3) |
| 36 | #define PCSR_S0_VS1 (1<<4) |
| 37 | #define PCSR_S0_VS2 (1<<5) |
| 38 | #define PCSR_S1_VS1 (1<<6) |
| 39 | #define PCSR_S1_VS2 (1<<7) |
| 40 | #define PCSR_S0_WP (1<<8) |
| 41 | #define PCSR_S1_WP (1<<9) |
| 42 | #define PCSR_S0_BVD1 (1<<10) |
| 43 | #define PCSR_S0_BVD2 (1<<11) |
| 44 | #define PCSR_S1_BVD1 (1<<12) |
| 45 | #define PCSR_S1_BVD2 (1<<13) |
| 46 | |
| 47 | #define PCCR_S0_RST (1<<0) |
| 48 | #define PCCR_S1_RST (1<<1) |
| 49 | #define PCCR_S0_FLT (1<<2) |
| 50 | #define PCCR_S1_FLT (1<<3) |
| 51 | #define PCCR_S0_PWAITEN (1<<4) |
| 52 | #define PCCR_S1_PWAITEN (1<<5) |
| 53 | #define PCCR_S0_PSE (1<<6) |
| 54 | #define PCCR_S1_PSE (1<<7) |
| 55 | |
| 56 | #define PCSSR_S0_SLEEP (1<<0) |
| 57 | #define PCSSR_S1_SLEEP (1<<1) |
| 58 | |
Eric Miao | 08fa159 | 2009-12-26 12:32:38 +0800 | [diff] [blame] | 59 | #define IDX_IRQ_S0_READY_NINT (0) |
| 60 | #define IDX_IRQ_S0_CD_VALID (1) |
| 61 | #define IDX_IRQ_S0_BVD1_STSCHG (2) |
| 62 | #define IDX_IRQ_S1_READY_NINT (3) |
| 63 | #define IDX_IRQ_S1_CD_VALID (4) |
| 64 | #define IDX_IRQ_S1_BVD1_STSCHG (5) |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | void sa1111_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state) |
| 67 | { |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 68 | struct sa1111_pcmcia_socket *s = to_skt(skt); |
Russell King | ea8c00a | 2012-01-16 11:32:09 +0000 | [diff] [blame] | 69 | unsigned long status = sa1111_readl(s->dev->mapbase + PCSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | switch (skt->nr) { |
| 72 | case 0: |
| 73 | state->detect = status & PCSR_S0_DETECT ? 0 : 1; |
| 74 | state->ready = status & PCSR_S0_READY ? 1 : 0; |
| 75 | state->bvd1 = status & PCSR_S0_BVD1 ? 1 : 0; |
| 76 | state->bvd2 = status & PCSR_S0_BVD2 ? 1 : 0; |
| 77 | state->wrprot = status & PCSR_S0_WP ? 1 : 0; |
| 78 | state->vs_3v = status & PCSR_S0_VS1 ? 0 : 1; |
| 79 | state->vs_Xv = status & PCSR_S0_VS2 ? 0 : 1; |
| 80 | break; |
| 81 | |
| 82 | case 1: |
| 83 | state->detect = status & PCSR_S1_DETECT ? 0 : 1; |
| 84 | state->ready = status & PCSR_S1_READY ? 1 : 0; |
| 85 | state->bvd1 = status & PCSR_S1_BVD1 ? 1 : 0; |
| 86 | state->bvd2 = status & PCSR_S1_BVD2 ? 1 : 0; |
| 87 | state->wrprot = status & PCSR_S1_WP ? 1 : 0; |
| 88 | state->vs_3v = status & PCSR_S1_VS1 ? 0 : 1; |
| 89 | state->vs_Xv = status & PCSR_S1_VS2 ? 0 : 1; |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | int sa1111_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state) |
| 95 | { |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 96 | struct sa1111_pcmcia_socket *s = to_skt(skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | unsigned int pccr_skt_mask, pccr_set_mask, val; |
| 98 | unsigned long flags; |
| 99 | |
| 100 | switch (skt->nr) { |
| 101 | case 0: |
| 102 | pccr_skt_mask = PCCR_S0_RST|PCCR_S0_FLT|PCCR_S0_PWAITEN|PCCR_S0_PSE; |
| 103 | break; |
| 104 | |
| 105 | case 1: |
| 106 | pccr_skt_mask = PCCR_S1_RST|PCCR_S1_FLT|PCCR_S1_PWAITEN|PCCR_S1_PSE; |
| 107 | break; |
| 108 | |
| 109 | default: |
| 110 | return -1; |
| 111 | } |
| 112 | |
| 113 | pccr_set_mask = 0; |
| 114 | |
| 115 | if (state->Vcc != 0) |
| 116 | pccr_set_mask |= PCCR_S0_PWAITEN|PCCR_S1_PWAITEN; |
| 117 | if (state->Vcc == 50) |
| 118 | pccr_set_mask |= PCCR_S0_PSE|PCCR_S1_PSE; |
| 119 | if (state->flags & SS_RESET) |
| 120 | pccr_set_mask |= PCCR_S0_RST|PCCR_S1_RST; |
| 121 | if (state->flags & SS_OUTPUT_ENA) |
| 122 | pccr_set_mask |= PCCR_S0_FLT|PCCR_S1_FLT; |
| 123 | |
| 124 | local_irq_save(flags); |
Russell King | ea8c00a | 2012-01-16 11:32:09 +0000 | [diff] [blame] | 125 | val = sa1111_readl(s->dev->mapbase + PCCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | val &= ~pccr_skt_mask; |
| 127 | val |= pccr_set_mask & pccr_skt_mask; |
Russell King | ea8c00a | 2012-01-16 11:32:09 +0000 | [diff] [blame] | 128 | sa1111_writel(val, s->dev->mapbase + PCCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | local_irq_restore(flags); |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 134 | int sa1111_pcmcia_add(struct sa1111_dev *dev, struct pcmcia_low_level *ops, |
| 135 | int (*add)(struct soc_pcmcia_socket *)) |
| 136 | { |
| 137 | struct sa1111_pcmcia_socket *s; |
| 138 | int i, ret = 0; |
| 139 | |
Russell King - ARM Linux | dabd146 | 2009-03-29 22:35:11 +0100 | [diff] [blame] | 140 | ops->socket_state = sa1111_pcmcia_socket_state; |
Russell King - ARM Linux | dabd146 | 2009-03-29 22:35:11 +0100 | [diff] [blame] | 141 | |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 142 | for (i = 0; i < ops->nr; i++) { |
| 143 | s = kzalloc(sizeof(*s), GFP_KERNEL); |
| 144 | if (!s) |
| 145 | return -ENOMEM; |
| 146 | |
| 147 | s->soc.nr = ops->first + i; |
Dmitry Eremin-Solenikov | b02cba8 | 2014-12-03 18:42:13 +0100 | [diff] [blame] | 148 | s->soc.clk = clk_get(&dev->dev, NULL); |
| 149 | if (IS_ERR(s->soc.clk)) { |
| 150 | ret = PTR_ERR(s->soc.clk); |
| 151 | kfree(s); |
| 152 | return ret; |
| 153 | } |
Russell King | e0d2117 | 2011-12-19 14:07:31 +0000 | [diff] [blame] | 154 | soc_pcmcia_init_one(&s->soc, ops, &dev->dev); |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 155 | s->dev = dev; |
Russell King | 81f33c6 | 2011-12-19 23:04:22 +0000 | [diff] [blame] | 156 | if (s->soc.nr) { |
| 157 | s->soc.socket.pci_irq = dev->irq[IDX_IRQ_S1_READY_NINT]; |
| 158 | s->soc.stat[SOC_STAT_CD].irq = dev->irq[IDX_IRQ_S1_CD_VALID]; |
| 159 | s->soc.stat[SOC_STAT_CD].name = "SA1111 CF card detect"; |
| 160 | s->soc.stat[SOC_STAT_BVD1].irq = dev->irq[IDX_IRQ_S1_BVD1_STSCHG]; |
| 161 | s->soc.stat[SOC_STAT_BVD1].name = "SA1111 CF BVD1"; |
| 162 | } else { |
| 163 | s->soc.socket.pci_irq = dev->irq[IDX_IRQ_S0_READY_NINT]; |
| 164 | s->soc.stat[SOC_STAT_CD].irq = dev->irq[IDX_IRQ_S0_CD_VALID]; |
| 165 | s->soc.stat[SOC_STAT_CD].name = "SA1111 PCMCIA card detect"; |
| 166 | s->soc.stat[SOC_STAT_BVD1].irq = dev->irq[IDX_IRQ_S0_BVD1_STSCHG]; |
| 167 | s->soc.stat[SOC_STAT_BVD1].name = "SA1111 PCMCIA BVD1"; |
| 168 | } |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 169 | |
| 170 | ret = add(&s->soc); |
| 171 | if (ret == 0) { |
| 172 | s->next = dev_get_drvdata(&dev->dev); |
| 173 | dev_set_drvdata(&dev->dev, s); |
| 174 | } else |
| 175 | kfree(s); |
| 176 | } |
| 177 | |
| 178 | return ret; |
| 179 | } |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | static int pcmcia_probe(struct sa1111_dev *dev) |
| 182 | { |
Russell King | f339ab3 | 2005-10-28 14:29:43 +0100 | [diff] [blame] | 183 | void __iomem *base; |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 184 | int ret; |
| 185 | |
| 186 | ret = sa1111_enable_device(dev); |
| 187 | if (ret) |
| 188 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 190 | dev_set_drvdata(&dev->dev, NULL); |
| 191 | |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 192 | if (!request_mem_region(dev->res.start, 512, SA1111_DRIVER_NAME(dev))) { |
| 193 | sa1111_disable_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | return -EBUSY; |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 195 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | base = dev->mapbase; |
| 198 | |
| 199 | /* |
| 200 | * Initialise the suspend state. |
| 201 | */ |
Russell King | ea8c00a | 2012-01-16 11:32:09 +0000 | [diff] [blame] | 202 | sa1111_writel(PCSSR_S0_SLEEP | PCSSR_S1_SLEEP, base + PCSSR); |
| 203 | sa1111_writel(PCCR_S0_FLT | PCCR_S1_FLT, base + PCCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | #ifdef CONFIG_SA1100_BADGE4 |
Dmitry Eremin-Solenikov | cfd1f00 | 2014-10-21 00:29:23 +0400 | [diff] [blame] | 206 | pcmcia_badge4_init(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | #endif |
| 208 | #ifdef CONFIG_SA1100_JORNADA720 |
Dmitry Eremin-Solenikov | 4bc9ef2 | 2014-10-21 00:29:24 +0400 | [diff] [blame] | 209 | pcmcia_jornada720_init(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | #endif |
| 211 | #ifdef CONFIG_ARCH_LUBBOCK |
| 212 | pcmcia_lubbock_init(dev); |
| 213 | #endif |
| 214 | #ifdef CONFIG_ASSABET_NEPONSET |
| 215 | pcmcia_neponset_init(dev); |
| 216 | #endif |
| 217 | return 0; |
| 218 | } |
| 219 | |
Bill Pemberton | e765a02 | 2012-11-19 13:26:05 -0500 | [diff] [blame] | 220 | static int pcmcia_remove(struct sa1111_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 222 | struct sa1111_pcmcia_socket *next, *s = dev_get_drvdata(&dev->dev); |
Russell King - ARM Linux | be85458 | 2009-03-26 22:21:18 +0000 | [diff] [blame] | 223 | |
| 224 | dev_set_drvdata(&dev->dev, NULL); |
| 225 | |
Russell King | 171cf94 | 2012-01-24 21:33:26 +0000 | [diff] [blame] | 226 | for (; s; s = next) { |
| 227 | next = s->next; |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 228 | soc_pcmcia_remove_one(&s->soc); |
Dmitry Eremin-Solenikov | b02cba8 | 2014-12-03 18:42:13 +0100 | [diff] [blame] | 229 | clk_put(s->soc.clk); |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 230 | kfree(s); |
| 231 | } |
Russell King - ARM Linux | be85458 | 2009-03-26 22:21:18 +0000 | [diff] [blame] | 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | release_mem_region(dev->res.start, 512); |
Russell King | ae99ddb | 2012-01-26 13:25:47 +0000 | [diff] [blame] | 234 | sa1111_disable_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | return 0; |
| 236 | } |
| 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | static struct sa1111_driver pcmcia_driver = { |
| 239 | .drv = { |
| 240 | .name = "sa1111-pcmcia", |
| 241 | }, |
| 242 | .devid = SA1111_DEVID_PCMCIA, |
| 243 | .probe = pcmcia_probe, |
Bill Pemberton | 96364e3 | 2012-11-19 13:20:38 -0500 | [diff] [blame] | 244 | .remove = pcmcia_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | static int __init sa1111_drv_pcmcia_init(void) |
| 248 | { |
| 249 | return sa1111_driver_register(&pcmcia_driver); |
| 250 | } |
| 251 | |
| 252 | static void __exit sa1111_drv_pcmcia_exit(void) |
| 253 | { |
| 254 | sa1111_driver_unregister(&pcmcia_driver); |
| 255 | } |
| 256 | |
Richard Purdie | f36598ae | 2005-09-03 19:39:25 +0100 | [diff] [blame] | 257 | fs_initcall(sa1111_drv_pcmcia_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | module_exit(sa1111_drv_pcmcia_exit); |
| 259 | |
| 260 | MODULE_DESCRIPTION("SA1111 PCMCIA card socket driver"); |
| 261 | MODULE_LICENSE("GPL"); |