Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Sharp SL-C7xx Series PCMCIA routines |
| 3 | * |
| 4 | * Copyright (c) 2004-2005 Richard Purdie |
| 5 | * |
| 6 | * Based on Sharp's 2.4 kernel patches and pxa2xx_mainstone.c |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/interrupt.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Pavel Machek | 77bb86a | 2005-10-30 23:39:02 +0000 | [diff] [blame] | 21 | #include <asm/mach-types.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 22 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/hardware/scoop.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include "soc_common.h" |
| 27 | |
| 28 | #define NO_KEEP_VS 0x0001 |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 29 | #define SCOOP_DEV platform_scoop_config->devs |
| 30 | |
Richard Purdie | 945b957 | 2006-01-05 20:44:57 +0000 | [diff] [blame] | 31 | static void sharpsl_pcmcia_init_reset(struct soc_pcmcia_socket *skt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
Richard Purdie | 945b957 | 2006-01-05 20:44:57 +0000 | [diff] [blame] | 33 | struct scoop_pcmcia_dev *scoopdev = &SCOOP_DEV[skt->nr]; |
| 34 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 35 | reset_scoop(scoopdev->dev); |
Richard Purdie | 945b957 | 2006-01-05 20:44:57 +0000 | [diff] [blame] | 36 | |
| 37 | /* Shared power controls need to be handled carefully */ |
| 38 | if (platform_scoop_config->power_ctrl) |
| 39 | platform_scoop_config->power_ctrl(scoopdev->dev, 0x0000, skt->nr); |
| 40 | else |
| 41 | write_scoop_reg(scoopdev->dev, SCOOP_CPR, 0x0000); |
| 42 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 43 | scoopdev->keep_vs = NO_KEEP_VS; |
| 44 | scoopdev->keep_rd = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static int sharpsl_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 48 | { |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 49 | if (SCOOP_DEV[skt->nr].cd_irq >= 0) { |
Russell King | a9bb5a4 | 2012-01-13 22:56:32 +0000 | [diff] [blame] | 50 | skt->stat[SOC_STAT_CD].irq = SCOOP_DEV[skt->nr].cd_irq; |
| 51 | skt->stat[SOC_STAT_CD].name = SCOOP_DEV[skt->nr].cd_irq_str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Russell King - ARM Linux | 66024db | 2009-03-29 22:45:26 +0100 | [diff] [blame] | 54 | skt->socket.pci_irq = SCOOP_DEV[skt->nr].irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | static void sharpsl_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 60 | struct pcmcia_state *state) |
| 61 | { |
| 62 | unsigned short cpr, csr; |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 63 | struct device *scoop = SCOOP_DEV[skt->nr].dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 65 | cpr = read_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_CPR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 67 | write_scoop_reg(scoop, SCOOP_IRM, 0x00FF); |
| 68 | write_scoop_reg(scoop, SCOOP_ISR, 0x0000); |
| 69 | write_scoop_reg(scoop, SCOOP_IRM, 0x0000); |
| 70 | csr = read_scoop_reg(scoop, SCOOP_CSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | if (csr & 0x0004) { |
| 72 | /* card eject */ |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 73 | write_scoop_reg(scoop, SCOOP_CDR, 0x0000); |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 74 | SCOOP_DEV[skt->nr].keep_vs = NO_KEEP_VS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 76 | else if (!(SCOOP_DEV[skt->nr].keep_vs & NO_KEEP_VS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | /* keep vs1,vs2 */ |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 78 | write_scoop_reg(scoop, SCOOP_CDR, 0x0000); |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 79 | csr |= SCOOP_DEV[skt->nr].keep_vs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | else if (cpr & 0x0003) { |
| 82 | /* power on */ |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 83 | write_scoop_reg(scoop, SCOOP_CDR, 0x0000); |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 84 | SCOOP_DEV[skt->nr].keep_vs = (csr & 0x00C0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | else { |
| 87 | /* card detect */ |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 88 | if ((machine_is_spitz() || machine_is_borzoi()) && skt->nr == 1) { |
| 89 | write_scoop_reg(scoop, SCOOP_CDR, 0x0000); |
| 90 | } else { |
| 91 | write_scoop_reg(scoop, SCOOP_CDR, 0x0002); |
| 92 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | state->detect = (csr & 0x0004) ? 0 : 1; |
| 96 | state->ready = (csr & 0x0002) ? 1 : 0; |
| 97 | state->bvd1 = (csr & 0x0010) ? 1 : 0; |
| 98 | state->bvd2 = (csr & 0x0020) ? 1 : 0; |
| 99 | state->wrprot = (csr & 0x0008) ? 1 : 0; |
| 100 | state->vs_3v = (csr & 0x0040) ? 0 : 1; |
| 101 | state->vs_Xv = (csr & 0x0080) ? 0 : 1; |
| 102 | |
| 103 | if ((cpr & 0x0080) && ((cpr & 0x8040) != 0x8040)) { |
| 104 | printk(KERN_ERR "sharpsl_pcmcia_socket_state(): CPR=%04X, Low voltage!\n", cpr); |
| 105 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | |
| 109 | static int sharpsl_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 110 | const socket_state_t *state) |
| 111 | { |
| 112 | unsigned long flags; |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 113 | struct device *scoop = SCOOP_DEV[skt->nr].dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | unsigned short cpr, ncpr, ccr, nccr, mcr, nmcr, imr, nimr; |
| 116 | |
| 117 | switch (state->Vcc) { |
| 118 | case 0: break; |
| 119 | case 33: break; |
| 120 | case 50: break; |
| 121 | default: |
| 122 | printk(KERN_ERR "sharpsl_pcmcia_configure_socket(): bad Vcc %u\n", state->Vcc); |
| 123 | return -1; |
| 124 | } |
| 125 | |
| 126 | if ((state->Vpp!=state->Vcc) && (state->Vpp!=0)) { |
| 127 | printk(KERN_ERR "CF slot cannot support Vpp %u\n", state->Vpp); |
| 128 | return -1; |
| 129 | } |
| 130 | |
| 131 | local_irq_save(flags); |
| 132 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 133 | nmcr = (mcr = read_scoop_reg(scoop, SCOOP_MCR)) & ~0x0010; |
| 134 | ncpr = (cpr = read_scoop_reg(scoop, SCOOP_CPR)) & ~0x0083; |
| 135 | nccr = (ccr = read_scoop_reg(scoop, SCOOP_CCR)) & ~0x0080; |
| 136 | nimr = (imr = read_scoop_reg(scoop, SCOOP_IMR)) & ~0x003E; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 138 | if ((machine_is_spitz() || machine_is_borzoi() || machine_is_akita()) && skt->nr == 0) { |
| 139 | ncpr |= (state->Vcc == 33) ? 0x0002 : |
| 140 | (state->Vcc == 50) ? 0x0002 : 0; |
| 141 | } else { |
| 142 | ncpr |= (state->Vcc == 33) ? 0x0001 : |
| 143 | (state->Vcc == 50) ? 0x0002 : 0; |
| 144 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | nmcr |= (state->flags&SS_IOCARD) ? 0x0010 : 0; |
| 146 | ncpr |= (state->flags&SS_OUTPUT_ENA) ? 0x0080 : 0; |
| 147 | nccr |= (state->flags&SS_RESET)? 0x0080: 0; |
| 148 | nimr |= ((skt->status&SS_DETECT) ? 0x0004 : 0)| |
| 149 | ((skt->status&SS_READY) ? 0x0002 : 0)| |
| 150 | ((skt->status&SS_BATDEAD)? 0x0010 : 0)| |
| 151 | ((skt->status&SS_BATWARN)? 0x0020 : 0)| |
| 152 | ((skt->status&SS_STSCHG) ? 0x0010 : 0)| |
| 153 | ((skt->status&SS_WRPROT) ? 0x0008 : 0); |
| 154 | |
| 155 | if (!(ncpr & 0x0003)) { |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 156 | SCOOP_DEV[skt->nr].keep_rd = 0; |
| 157 | } else if (!SCOOP_DEV[skt->nr].keep_rd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | if (nccr & 0x0080) |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 159 | SCOOP_DEV[skt->nr].keep_rd = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | else |
| 161 | nccr |= 0x0080; |
| 162 | } |
| 163 | |
| 164 | if (mcr != nmcr) |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 165 | write_scoop_reg(scoop, SCOOP_MCR, nmcr); |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 166 | if (cpr != ncpr) { |
| 167 | if (platform_scoop_config->power_ctrl) |
| 168 | platform_scoop_config->power_ctrl(scoop, ncpr , skt->nr); |
| 169 | else |
| 170 | write_scoop_reg(scoop, SCOOP_CPR, ncpr); |
| 171 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | if (ccr != nccr) |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 173 | write_scoop_reg(scoop, SCOOP_CCR, nccr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | if (imr != nimr) |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 175 | write_scoop_reg(scoop, SCOOP_IMR, nimr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | local_irq_restore(flags); |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | static void sharpsl_pcmcia_socket_init(struct soc_pcmcia_socket *skt) |
| 183 | { |
Richard Purdie | 945b957 | 2006-01-05 20:44:57 +0000 | [diff] [blame] | 184 | sharpsl_pcmcia_init_reset(skt); |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 185 | |
| 186 | /* Enable interrupt */ |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 187 | write_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_IMR, 0x00C0); |
| 188 | write_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_MCR, 0x0101); |
| 189 | SCOOP_DEV[skt->nr].keep_vs = NO_KEEP_VS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) |
| 193 | { |
Richard Purdie | 945b957 | 2006-01-05 20:44:57 +0000 | [diff] [blame] | 194 | sharpsl_pcmcia_init_reset(skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Russell King | 4e5e8de | 2008-04-24 15:28:11 +0100 | [diff] [blame] | 197 | static struct pcmcia_low_level sharpsl_pcmcia_ops __initdata = { |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 198 | .owner = THIS_MODULE, |
| 199 | .hw_init = sharpsl_pcmcia_hw_init, |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 200 | .socket_state = sharpsl_pcmcia_socket_state, |
| 201 | .configure_socket = sharpsl_pcmcia_configure_socket, |
| 202 | .socket_init = sharpsl_pcmcia_socket_init, |
| 203 | .socket_suspend = sharpsl_pcmcia_socket_suspend, |
| 204 | .first = 0, |
| 205 | .nr = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
Pavel Machek | 77bb86a | 2005-10-30 23:39:02 +0000 | [diff] [blame] | 208 | #ifdef CONFIG_SA1100_COLLIE |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 209 | #include "sa11xx_base.h" |
| 210 | |
Uwe Kleine-König | 5b85e04 | 2010-11-04 10:46:14 +0100 | [diff] [blame] | 211 | int __devinit pcmcia_collie_init(struct device *dev) |
Pavel Machek | 77bb86a | 2005-10-30 23:39:02 +0000 | [diff] [blame] | 212 | { |
| 213 | int ret = -ENODEV; |
| 214 | |
| 215 | if (machine_is_collie()) |
| 216 | ret = sa11xx_drv_pcmcia_probe(dev, &sharpsl_pcmcia_ops, 0, 1); |
| 217 | |
| 218 | return ret; |
| 219 | } |
| 220 | |
| 221 | #else |
| 222 | |
Richard Purdie | a63ae44 | 2005-11-08 19:15:43 +0000 | [diff] [blame] | 223 | static struct platform_device *sharpsl_pcmcia_device; |
| 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | static int __init sharpsl_pcmcia_init(void) |
| 226 | { |
| 227 | int ret; |
| 228 | |
Dmitry Baryshkov | ae1036a | 2009-04-20 17:48:28 +0100 | [diff] [blame] | 229 | if (!platform_scoop_config) |
| 230 | return -ENODEV; |
| 231 | |
Richard Purdie | b016450 | 2006-01-10 17:16:12 +0000 | [diff] [blame] | 232 | sharpsl_pcmcia_ops.nr = platform_scoop_config->num_devs; |
| 233 | sharpsl_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
| 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | if (!sharpsl_pcmcia_device) |
| 236 | return -ENOMEM; |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 237 | |
Russell King | 4e5e8de | 2008-04-24 15:28:11 +0100 | [diff] [blame] | 238 | ret = platform_device_add_data(sharpsl_pcmcia_device, |
| 239 | &sharpsl_pcmcia_ops, sizeof(sharpsl_pcmcia_ops)); |
| 240 | if (ret == 0) { |
| 241 | sharpsl_pcmcia_device->dev.parent = platform_scoop_config->devs[0].dev; |
| 242 | ret = platform_device_add(sharpsl_pcmcia_device); |
| 243 | } |
Richard Purdie | b016450 | 2006-01-10 17:16:12 +0000 | [diff] [blame] | 244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | if (ret) |
Richard Purdie | b016450 | 2006-01-10 17:16:12 +0000 | [diff] [blame] | 246 | platform_device_put(sharpsl_pcmcia_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | static void __exit sharpsl_pcmcia_exit(void) |
| 252 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | platform_device_unregister(sharpsl_pcmcia_device); |
| 254 | } |
| 255 | |
Richard Purdie | f36598a | 2005-09-03 19:39:25 +0100 | [diff] [blame] | 256 | fs_initcall(sharpsl_pcmcia_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | module_exit(sharpsl_pcmcia_exit); |
Pavel Machek | 77bb86a | 2005-10-30 23:39:02 +0000 | [diff] [blame] | 258 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | MODULE_DESCRIPTION("Sharp SL Series PCMCIA Support"); |
| 261 | MODULE_LICENSE("GPL"); |
Kay Sievers | 43cc71e | 2007-08-18 04:40:39 +0200 | [diff] [blame] | 262 | MODULE_ALIAS("platform:pxa2xx-pcmcia"); |