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> |
| 19 | #include <linux/device.h> |
| 20 | |
| 21 | #include <asm/hardware.h> |
| 22 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/hardware/scoop.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/arch/pxa-regs.h> |
| 25 | |
| 26 | #include "soc_common.h" |
| 27 | |
| 28 | #define NO_KEEP_VS 0x0001 |
| 29 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 30 | static void sharpsl_pcmcia_init_reset(struct scoop_pcmcia_dev *scoopdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 32 | reset_scoop(scoopdev->dev); |
| 33 | scoopdev->keep_vs = NO_KEEP_VS; |
| 34 | scoopdev->keep_rd = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static int sharpsl_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 38 | { |
| 39 | int ret; |
| 40 | |
| 41 | /* |
| 42 | * Setup default state of GPIO outputs |
| 43 | * before we enable them as outputs. |
| 44 | */ |
| 45 | GPSR(GPIO48_nPOE) = |
| 46 | GPIO_bit(GPIO48_nPOE) | |
| 47 | GPIO_bit(GPIO49_nPWE) | |
| 48 | GPIO_bit(GPIO50_nPIOR) | |
| 49 | GPIO_bit(GPIO51_nPIOW) | |
| 50 | GPIO_bit(GPIO52_nPCE_1) | |
| 51 | GPIO_bit(GPIO53_nPCE_2); |
| 52 | |
| 53 | pxa_gpio_mode(GPIO48_nPOE_MD); |
| 54 | pxa_gpio_mode(GPIO49_nPWE_MD); |
| 55 | pxa_gpio_mode(GPIO50_nPIOR_MD); |
| 56 | pxa_gpio_mode(GPIO51_nPIOW_MD); |
| 57 | pxa_gpio_mode(GPIO52_nPCE_1_MD); |
| 58 | pxa_gpio_mode(GPIO53_nPCE_2_MD); |
| 59 | pxa_gpio_mode(GPIO54_pSKTSEL_MD); |
| 60 | pxa_gpio_mode(GPIO55_nPREG_MD); |
| 61 | pxa_gpio_mode(GPIO56_nPWAIT_MD); |
| 62 | pxa_gpio_mode(GPIO57_nIOIS16_MD); |
| 63 | |
| 64 | /* Register interrupts */ |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 65 | if (scoop_devs[skt->nr].cd_irq >= 0) { |
| 66 | struct pcmcia_irqs cd_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 68 | cd_irq.sock = skt->nr; |
| 69 | cd_irq.irq = scoop_devs[skt->nr].cd_irq; |
| 70 | cd_irq.str = scoop_devs[skt->nr].cd_irq_str; |
| 71 | ret = soc_pcmcia_request_irqs(skt, &cd_irq, 1); |
| 72 | |
| 73 | if (ret) { |
| 74 | printk(KERN_ERR "Request for Compact Flash IRQ failed\n"); |
| 75 | return ret; |
| 76 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 79 | skt->irq = scoop_devs[skt->nr].irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static void sharpsl_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
| 85 | { |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 86 | if (scoop_devs[skt->nr].cd_irq >= 0) { |
| 87 | struct pcmcia_irqs cd_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 89 | cd_irq.sock = skt->nr; |
| 90 | cd_irq.irq = scoop_devs[skt->nr].cd_irq; |
| 91 | cd_irq.str = scoop_devs[skt->nr].cd_irq_str; |
| 92 | soc_pcmcia_free_irqs(skt, &cd_irq, 1); |
| 93 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | |
| 97 | static void sharpsl_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 98 | struct pcmcia_state *state) |
| 99 | { |
| 100 | unsigned short cpr, csr; |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 101 | struct device *scoop = scoop_devs[skt->nr].dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 103 | cpr = read_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_CPR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 105 | write_scoop_reg(scoop, SCOOP_IRM, 0x00FF); |
| 106 | write_scoop_reg(scoop, SCOOP_ISR, 0x0000); |
| 107 | write_scoop_reg(scoop, SCOOP_IRM, 0x0000); |
| 108 | csr = read_scoop_reg(scoop, SCOOP_CSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | if (csr & 0x0004) { |
| 110 | /* card eject */ |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 111 | write_scoop_reg(scoop, SCOOP_CDR, 0x0000); |
| 112 | scoop_devs[skt->nr].keep_vs = NO_KEEP_VS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 114 | else if (!(scoop_devs[skt->nr].keep_vs & NO_KEEP_VS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /* keep vs1,vs2 */ |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 116 | write_scoop_reg(scoop, SCOOP_CDR, 0x0000); |
| 117 | csr |= scoop_devs[skt->nr].keep_vs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | else if (cpr & 0x0003) { |
| 120 | /* power on */ |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 121 | write_scoop_reg(scoop, SCOOP_CDR, 0x0000); |
| 122 | scoop_devs[skt->nr].keep_vs = (csr & 0x00C0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | else { |
| 125 | /* card detect */ |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 126 | write_scoop_reg(scoop, SCOOP_CDR, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | state->detect = (csr & 0x0004) ? 0 : 1; |
| 130 | state->ready = (csr & 0x0002) ? 1 : 0; |
| 131 | state->bvd1 = (csr & 0x0010) ? 1 : 0; |
| 132 | state->bvd2 = (csr & 0x0020) ? 1 : 0; |
| 133 | state->wrprot = (csr & 0x0008) ? 1 : 0; |
| 134 | state->vs_3v = (csr & 0x0040) ? 0 : 1; |
| 135 | state->vs_Xv = (csr & 0x0080) ? 0 : 1; |
| 136 | |
| 137 | if ((cpr & 0x0080) && ((cpr & 0x8040) != 0x8040)) { |
| 138 | printk(KERN_ERR "sharpsl_pcmcia_socket_state(): CPR=%04X, Low voltage!\n", cpr); |
| 139 | } |
| 140 | |
| 141 | } |
| 142 | |
| 143 | |
| 144 | static int sharpsl_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 145 | const socket_state_t *state) |
| 146 | { |
| 147 | unsigned long flags; |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 148 | struct device *scoop = scoop_devs[skt->nr].dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | unsigned short cpr, ncpr, ccr, nccr, mcr, nmcr, imr, nimr; |
| 151 | |
| 152 | switch (state->Vcc) { |
| 153 | case 0: break; |
| 154 | case 33: break; |
| 155 | case 50: break; |
| 156 | default: |
| 157 | printk(KERN_ERR "sharpsl_pcmcia_configure_socket(): bad Vcc %u\n", state->Vcc); |
| 158 | return -1; |
| 159 | } |
| 160 | |
| 161 | if ((state->Vpp!=state->Vcc) && (state->Vpp!=0)) { |
| 162 | printk(KERN_ERR "CF slot cannot support Vpp %u\n", state->Vpp); |
| 163 | return -1; |
| 164 | } |
| 165 | |
| 166 | local_irq_save(flags); |
| 167 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 168 | nmcr = (mcr = read_scoop_reg(scoop, SCOOP_MCR)) & ~0x0010; |
| 169 | ncpr = (cpr = read_scoop_reg(scoop, SCOOP_CPR)) & ~0x0083; |
| 170 | nccr = (ccr = read_scoop_reg(scoop, SCOOP_CCR)) & ~0x0080; |
| 171 | nimr = (imr = read_scoop_reg(scoop, SCOOP_IMR)) & ~0x003E; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | ncpr |= (state->Vcc == 33) ? 0x0001 : |
| 174 | (state->Vcc == 50) ? 0x0002 : 0; |
| 175 | nmcr |= (state->flags&SS_IOCARD) ? 0x0010 : 0; |
| 176 | ncpr |= (state->flags&SS_OUTPUT_ENA) ? 0x0080 : 0; |
| 177 | nccr |= (state->flags&SS_RESET)? 0x0080: 0; |
| 178 | nimr |= ((skt->status&SS_DETECT) ? 0x0004 : 0)| |
| 179 | ((skt->status&SS_READY) ? 0x0002 : 0)| |
| 180 | ((skt->status&SS_BATDEAD)? 0x0010 : 0)| |
| 181 | ((skt->status&SS_BATWARN)? 0x0020 : 0)| |
| 182 | ((skt->status&SS_STSCHG) ? 0x0010 : 0)| |
| 183 | ((skt->status&SS_WRPROT) ? 0x0008 : 0); |
| 184 | |
| 185 | if (!(ncpr & 0x0003)) { |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 186 | scoop_devs[skt->nr].keep_rd = 0; |
| 187 | } else if (!scoop_devs[skt->nr].keep_rd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | if (nccr & 0x0080) |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 189 | scoop_devs[skt->nr].keep_rd = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | else |
| 191 | nccr |= 0x0080; |
| 192 | } |
| 193 | |
| 194 | if (mcr != nmcr) |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 195 | write_scoop_reg(scoop, SCOOP_MCR, nmcr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | if (cpr != ncpr) |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 197 | write_scoop_reg(scoop, SCOOP_CPR, ncpr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (ccr != nccr) |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 199 | write_scoop_reg(scoop, SCOOP_CCR, nccr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | if (imr != nimr) |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 201 | write_scoop_reg(scoop, SCOOP_IMR, nimr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | local_irq_restore(flags); |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | static void sharpsl_pcmcia_socket_init(struct soc_pcmcia_socket *skt) |
| 209 | { |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 210 | sharpsl_pcmcia_init_reset(&scoop_devs[skt->nr]); |
| 211 | |
| 212 | /* Enable interrupt */ |
| 213 | write_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_IMR, 0x00C0); |
| 214 | write_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_MCR, 0x0101); |
| 215 | scoop_devs[skt->nr].keep_vs = NO_KEEP_VS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) |
| 219 | { |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 220 | /* CF_BUS_OFF */ |
| 221 | sharpsl_pcmcia_init_reset(&scoop_devs[skt->nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static struct pcmcia_low_level sharpsl_pcmcia_ops = { |
| 225 | .owner = THIS_MODULE, |
| 226 | .hw_init = sharpsl_pcmcia_hw_init, |
| 227 | .hw_shutdown = sharpsl_pcmcia_hw_shutdown, |
| 228 | .socket_state = sharpsl_pcmcia_socket_state, |
| 229 | .configure_socket = sharpsl_pcmcia_configure_socket, |
| 230 | .socket_init = sharpsl_pcmcia_socket_init, |
| 231 | .socket_suspend = sharpsl_pcmcia_socket_suspend, |
| 232 | .first = 0, |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 233 | .nr = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | static struct platform_device *sharpsl_pcmcia_device; |
| 237 | |
| 238 | static int __init sharpsl_pcmcia_init(void) |
| 239 | { |
| 240 | int ret; |
| 241 | |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 242 | sharpsl_pcmcia_ops.nr=scoop_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | sharpsl_pcmcia_device = kmalloc(sizeof(*sharpsl_pcmcia_device), GFP_KERNEL); |
| 244 | if (!sharpsl_pcmcia_device) |
| 245 | return -ENOMEM; |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | memset(sharpsl_pcmcia_device, 0, sizeof(*sharpsl_pcmcia_device)); |
| 248 | sharpsl_pcmcia_device->name = "pxa2xx-pcmcia"; |
| 249 | sharpsl_pcmcia_device->dev.platform_data = &sharpsl_pcmcia_ops; |
Richard Purdie | 0ce7625 | 2005-09-05 20:49:54 +0100 | [diff] [blame] | 250 | sharpsl_pcmcia_device->dev.parent=scoop_devs[0].dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | ret = platform_device_register(sharpsl_pcmcia_device); |
| 253 | if (ret) |
| 254 | kfree(sharpsl_pcmcia_device); |
| 255 | |
| 256 | return ret; |
| 257 | } |
| 258 | |
| 259 | static void __exit sharpsl_pcmcia_exit(void) |
| 260 | { |
| 261 | /* |
| 262 | * This call is supposed to free our sharpsl_pcmcia_device. |
| 263 | * Unfortunately platform_device don't have a free method, and |
| 264 | * we can't assume it's free of any reference at this point so we |
| 265 | * can't free it either. |
| 266 | */ |
| 267 | platform_device_unregister(sharpsl_pcmcia_device); |
| 268 | } |
| 269 | |
Richard Purdie | f36598ae | 2005-09-03 19:39:25 +0100 | [diff] [blame] | 270 | fs_initcall(sharpsl_pcmcia_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | module_exit(sharpsl_pcmcia_exit); |
| 272 | |
| 273 | MODULE_DESCRIPTION("Sharp SL Series PCMCIA Support"); |
| 274 | MODULE_LICENSE("GPL"); |