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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #include <pcmcia/ss.h> |
| 17 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 18 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/hardware/sa1111.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/irq.h> |
| 21 | |
| 22 | #include "sa1111_generic.h" |
| 23 | |
| 24 | static struct pcmcia_irqs irqs[] = { |
| 25 | { 0, IRQ_S0_CD_VALID, "SA1111 PCMCIA card detect" }, |
| 26 | { 0, IRQ_S0_BVD1_STSCHG, "SA1111 PCMCIA BVD1" }, |
| 27 | { 1, IRQ_S1_CD_VALID, "SA1111 CF card detect" }, |
| 28 | { 1, IRQ_S1_BVD1_STSCHG, "SA1111 CF BVD1" }, |
| 29 | }; |
| 30 | |
Russell King - ARM Linux | dabd146 | 2009-03-29 22:35:11 +0100 | [diff] [blame] | 31 | static int sa1111_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 34 | } |
| 35 | |
Russell King - ARM Linux | dabd146 | 2009-03-29 22:35:11 +0100 | [diff] [blame] | 36 | static void sa1111_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
| 38 | soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 39 | } |
| 40 | |
| 41 | void sa1111_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state) |
| 42 | { |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 43 | struct sa1111_pcmcia_socket *s = to_skt(skt); |
| 44 | unsigned long status = sa1111_readl(s->dev->mapbase + SA1111_PCSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | switch (skt->nr) { |
| 47 | case 0: |
| 48 | state->detect = status & PCSR_S0_DETECT ? 0 : 1; |
| 49 | state->ready = status & PCSR_S0_READY ? 1 : 0; |
| 50 | state->bvd1 = status & PCSR_S0_BVD1 ? 1 : 0; |
| 51 | state->bvd2 = status & PCSR_S0_BVD2 ? 1 : 0; |
| 52 | state->wrprot = status & PCSR_S0_WP ? 1 : 0; |
| 53 | state->vs_3v = status & PCSR_S0_VS1 ? 0 : 1; |
| 54 | state->vs_Xv = status & PCSR_S0_VS2 ? 0 : 1; |
| 55 | break; |
| 56 | |
| 57 | case 1: |
| 58 | state->detect = status & PCSR_S1_DETECT ? 0 : 1; |
| 59 | state->ready = status & PCSR_S1_READY ? 1 : 0; |
| 60 | state->bvd1 = status & PCSR_S1_BVD1 ? 1 : 0; |
| 61 | state->bvd2 = status & PCSR_S1_BVD2 ? 1 : 0; |
| 62 | state->wrprot = status & PCSR_S1_WP ? 1 : 0; |
| 63 | state->vs_3v = status & PCSR_S1_VS1 ? 0 : 1; |
| 64 | state->vs_Xv = status & PCSR_S1_VS2 ? 0 : 1; |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | int sa1111_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state) |
| 70 | { |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 71 | struct sa1111_pcmcia_socket *s = to_skt(skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | unsigned int pccr_skt_mask, pccr_set_mask, val; |
| 73 | unsigned long flags; |
| 74 | |
| 75 | switch (skt->nr) { |
| 76 | case 0: |
| 77 | pccr_skt_mask = PCCR_S0_RST|PCCR_S0_FLT|PCCR_S0_PWAITEN|PCCR_S0_PSE; |
| 78 | break; |
| 79 | |
| 80 | case 1: |
| 81 | pccr_skt_mask = PCCR_S1_RST|PCCR_S1_FLT|PCCR_S1_PWAITEN|PCCR_S1_PSE; |
| 82 | break; |
| 83 | |
| 84 | default: |
| 85 | return -1; |
| 86 | } |
| 87 | |
| 88 | pccr_set_mask = 0; |
| 89 | |
| 90 | if (state->Vcc != 0) |
| 91 | pccr_set_mask |= PCCR_S0_PWAITEN|PCCR_S1_PWAITEN; |
| 92 | if (state->Vcc == 50) |
| 93 | pccr_set_mask |= PCCR_S0_PSE|PCCR_S1_PSE; |
| 94 | if (state->flags & SS_RESET) |
| 95 | pccr_set_mask |= PCCR_S0_RST|PCCR_S1_RST; |
| 96 | if (state->flags & SS_OUTPUT_ENA) |
| 97 | pccr_set_mask |= PCCR_S0_FLT|PCCR_S1_FLT; |
| 98 | |
| 99 | local_irq_save(flags); |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 100 | val = sa1111_readl(s->dev->mapbase + SA1111_PCCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | val &= ~pccr_skt_mask; |
| 102 | val |= pccr_set_mask & pccr_skt_mask; |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 103 | sa1111_writel(val, s->dev->mapbase + SA1111_PCCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | local_irq_restore(flags); |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | void sa1111_pcmcia_socket_init(struct soc_pcmcia_socket *skt) |
| 110 | { |
| 111 | soc_pcmcia_enable_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 112 | } |
| 113 | |
Russell King - ARM Linux | dabd146 | 2009-03-29 22:35:11 +0100 | [diff] [blame] | 114 | static void sa1111_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 117 | } |
| 118 | |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 119 | int sa1111_pcmcia_add(struct sa1111_dev *dev, struct pcmcia_low_level *ops, |
| 120 | int (*add)(struct soc_pcmcia_socket *)) |
| 121 | { |
| 122 | struct sa1111_pcmcia_socket *s; |
| 123 | int i, ret = 0; |
| 124 | |
Russell King - ARM Linux | dabd146 | 2009-03-29 22:35:11 +0100 | [diff] [blame] | 125 | ops->hw_init = sa1111_pcmcia_hw_init; |
| 126 | ops->hw_shutdown = sa1111_pcmcia_hw_shutdown; |
| 127 | ops->socket_state = sa1111_pcmcia_socket_state; |
| 128 | ops->socket_suspend = sa1111_pcmcia_socket_suspend; |
| 129 | |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 130 | for (i = 0; i < ops->nr; i++) { |
| 131 | s = kzalloc(sizeof(*s), GFP_KERNEL); |
| 132 | if (!s) |
| 133 | return -ENOMEM; |
| 134 | |
| 135 | s->soc.nr = ops->first + i; |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 136 | s->soc.ops = ops; |
| 137 | s->soc.socket.owner = ops->owner; |
| 138 | s->soc.socket.dev.parent = &dev->dev; |
Russell King - ARM Linux | 66024db | 2009-03-29 22:45:26 +0100 | [diff] [blame] | 139 | s->soc.socket.pci_irq = s->soc.nr ? IRQ_S1_READY_NINT : IRQ_S0_READY_NINT; |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 140 | s->dev = dev; |
| 141 | |
| 142 | ret = add(&s->soc); |
| 143 | if (ret == 0) { |
| 144 | s->next = dev_get_drvdata(&dev->dev); |
| 145 | dev_set_drvdata(&dev->dev, s); |
| 146 | } else |
| 147 | kfree(s); |
| 148 | } |
| 149 | |
| 150 | return ret; |
| 151 | } |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | static int pcmcia_probe(struct sa1111_dev *dev) |
| 154 | { |
Russell King | f339ab3 | 2005-10-28 14:29:43 +0100 | [diff] [blame] | 155 | void __iomem *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 157 | dev_set_drvdata(&dev->dev, NULL); |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | if (!request_mem_region(dev->res.start, 512, |
| 160 | SA1111_DRIVER_NAME(dev))) |
| 161 | return -EBUSY; |
| 162 | |
| 163 | base = dev->mapbase; |
| 164 | |
| 165 | /* |
| 166 | * Initialise the suspend state. |
| 167 | */ |
| 168 | sa1111_writel(PCSSR_S0_SLEEP | PCSSR_S1_SLEEP, base + SA1111_PCSSR); |
| 169 | sa1111_writel(PCCR_S0_FLT | PCCR_S1_FLT, base + SA1111_PCCR); |
| 170 | |
| 171 | #ifdef CONFIG_SA1100_BADGE4 |
| 172 | pcmcia_badge4_init(&dev->dev); |
| 173 | #endif |
| 174 | #ifdef CONFIG_SA1100_JORNADA720 |
| 175 | pcmcia_jornada720_init(&dev->dev); |
| 176 | #endif |
| 177 | #ifdef CONFIG_ARCH_LUBBOCK |
| 178 | pcmcia_lubbock_init(dev); |
| 179 | #endif |
| 180 | #ifdef CONFIG_ASSABET_NEPONSET |
| 181 | pcmcia_neponset_init(dev); |
| 182 | #endif |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static int __devexit pcmcia_remove(struct sa1111_dev *dev) |
| 187 | { |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 188 | 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] | 189 | |
| 190 | dev_set_drvdata(&dev->dev, NULL); |
| 191 | |
Russell King - ARM Linux | 701a5dc | 2009-03-29 19:42:44 +0100 | [diff] [blame] | 192 | for (; next = s->next, s; s = next) { |
| 193 | soc_pcmcia_remove_one(&s->soc); |
| 194 | kfree(s); |
| 195 | } |
Russell King - ARM Linux | be85458 | 2009-03-26 22:21:18 +0000 | [diff] [blame] | 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | release_mem_region(dev->res.start, 512); |
| 198 | return 0; |
| 199 | } |
| 200 | |
Pavel Machek | 8bf2803 | 2005-04-16 15:25:26 -0700 | [diff] [blame] | 201 | static int pcmcia_suspend(struct sa1111_dev *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Rafael J. Wysocki | 827b464 | 2009-09-29 00:10:41 +0200 | [diff] [blame] | 203 | return pcmcia_socket_dev_suspend(&dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static int pcmcia_resume(struct sa1111_dev *dev) |
| 207 | { |
| 208 | return pcmcia_socket_dev_resume(&dev->dev); |
| 209 | } |
| 210 | |
| 211 | static struct sa1111_driver pcmcia_driver = { |
| 212 | .drv = { |
| 213 | .name = "sa1111-pcmcia", |
| 214 | }, |
| 215 | .devid = SA1111_DEVID_PCMCIA, |
| 216 | .probe = pcmcia_probe, |
| 217 | .remove = __devexit_p(pcmcia_remove), |
| 218 | .suspend = pcmcia_suspend, |
| 219 | .resume = pcmcia_resume, |
| 220 | }; |
| 221 | |
| 222 | static int __init sa1111_drv_pcmcia_init(void) |
| 223 | { |
| 224 | return sa1111_driver_register(&pcmcia_driver); |
| 225 | } |
| 226 | |
| 227 | static void __exit sa1111_drv_pcmcia_exit(void) |
| 228 | { |
| 229 | sa1111_driver_unregister(&pcmcia_driver); |
| 230 | } |
| 231 | |
Richard Purdie | f36598ae | 2005-09-03 19:39:25 +0100 | [diff] [blame] | 232 | fs_initcall(sa1111_drv_pcmcia_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | module_exit(sa1111_drv_pcmcia_exit); |
| 234 | |
| 235 | MODULE_DESCRIPTION("SA1111 PCMCIA card socket driver"); |
| 236 | MODULE_LICENSE("GPL"); |