blob: 69ae2fd22400a7b9db6f59420f90b9c29dfd5ade [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Kingd052d1b2005-10-29 19:07:23 +010019#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Pavel Machek77bb86a2005-10-30 23:39:02 +000021#include <asm/mach-types.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010022#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/hardware/scoop.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include "soc_common.h"
27
28#define NO_KEEP_VS 0x0001
Richard Purdiea63ae442005-11-08 19:15:43 +000029#define SCOOP_DEV platform_scoop_config->devs
30
Richard Purdie945b9572006-01-05 20:44:57 +000031static void sharpsl_pcmcia_init_reset(struct soc_pcmcia_socket *skt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Richard Purdie945b9572006-01-05 20:44:57 +000033 struct scoop_pcmcia_dev *scoopdev = &SCOOP_DEV[skt->nr];
34
Richard Purdie0ce76252005-09-05 20:49:54 +010035 reset_scoop(scoopdev->dev);
Richard Purdie945b9572006-01-05 20:44:57 +000036
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 Purdie0ce76252005-09-05 20:49:54 +010043 scoopdev->keep_vs = NO_KEEP_VS;
44 scoopdev->keep_rd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
47static int sharpsl_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
48{
49 int ret;
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 /* Register interrupts */
Richard Purdiea63ae442005-11-08 19:15:43 +000052 if (SCOOP_DEV[skt->nr].cd_irq >= 0) {
Richard Purdie0ce76252005-09-05 20:49:54 +010053 struct pcmcia_irqs cd_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Richard Purdie0ce76252005-09-05 20:49:54 +010055 cd_irq.sock = skt->nr;
Richard Purdiea63ae442005-11-08 19:15:43 +000056 cd_irq.irq = SCOOP_DEV[skt->nr].cd_irq;
57 cd_irq.str = SCOOP_DEV[skt->nr].cd_irq_str;
Richard Purdie0ce76252005-09-05 20:49:54 +010058 ret = soc_pcmcia_request_irqs(skt, &cd_irq, 1);
59
60 if (ret) {
61 printk(KERN_ERR "Request for Compact Flash IRQ failed\n");
62 return ret;
63 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 }
65
Russell King - ARM Linux66024db2009-03-29 22:45:26 +010066 skt->socket.pci_irq = SCOOP_DEV[skt->nr].irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 return 0;
69}
70
71static void sharpsl_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
72{
Richard Purdiea63ae442005-11-08 19:15:43 +000073 if (SCOOP_DEV[skt->nr].cd_irq >= 0) {
Richard Purdie0ce76252005-09-05 20:49:54 +010074 struct pcmcia_irqs cd_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Richard Purdie0ce76252005-09-05 20:49:54 +010076 cd_irq.sock = skt->nr;
Richard Purdiea63ae442005-11-08 19:15:43 +000077 cd_irq.irq = SCOOP_DEV[skt->nr].cd_irq;
78 cd_irq.str = SCOOP_DEV[skt->nr].cd_irq_str;
Richard Purdie0ce76252005-09-05 20:49:54 +010079 soc_pcmcia_free_irqs(skt, &cd_irq, 1);
80 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
83
84static void sharpsl_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
85 struct pcmcia_state *state)
86{
87 unsigned short cpr, csr;
Richard Purdiea63ae442005-11-08 19:15:43 +000088 struct device *scoop = SCOOP_DEV[skt->nr].dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Richard Purdiea63ae442005-11-08 19:15:43 +000090 cpr = read_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_CPR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Richard Purdie0ce76252005-09-05 20:49:54 +010092 write_scoop_reg(scoop, SCOOP_IRM, 0x00FF);
93 write_scoop_reg(scoop, SCOOP_ISR, 0x0000);
94 write_scoop_reg(scoop, SCOOP_IRM, 0x0000);
95 csr = read_scoop_reg(scoop, SCOOP_CSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 if (csr & 0x0004) {
97 /* card eject */
Richard Purdie0ce76252005-09-05 20:49:54 +010098 write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
Richard Purdiea63ae442005-11-08 19:15:43 +000099 SCOOP_DEV[skt->nr].keep_vs = NO_KEEP_VS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 }
Richard Purdiea63ae442005-11-08 19:15:43 +0000101 else if (!(SCOOP_DEV[skt->nr].keep_vs & NO_KEEP_VS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 /* keep vs1,vs2 */
Richard Purdie0ce76252005-09-05 20:49:54 +0100103 write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
Richard Purdiea63ae442005-11-08 19:15:43 +0000104 csr |= SCOOP_DEV[skt->nr].keep_vs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 }
106 else if (cpr & 0x0003) {
107 /* power on */
Richard Purdie0ce76252005-09-05 20:49:54 +0100108 write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
Richard Purdiea63ae442005-11-08 19:15:43 +0000109 SCOOP_DEV[skt->nr].keep_vs = (csr & 0x00C0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 }
111 else {
112 /* card detect */
Richard Purdiea63ae442005-11-08 19:15:43 +0000113 if ((machine_is_spitz() || machine_is_borzoi()) && skt->nr == 1) {
114 write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
115 } else {
116 write_scoop_reg(scoop, SCOOP_CDR, 0x0002);
117 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119
120 state->detect = (csr & 0x0004) ? 0 : 1;
121 state->ready = (csr & 0x0002) ? 1 : 0;
122 state->bvd1 = (csr & 0x0010) ? 1 : 0;
123 state->bvd2 = (csr & 0x0020) ? 1 : 0;
124 state->wrprot = (csr & 0x0008) ? 1 : 0;
125 state->vs_3v = (csr & 0x0040) ? 0 : 1;
126 state->vs_Xv = (csr & 0x0080) ? 0 : 1;
127
128 if ((cpr & 0x0080) && ((cpr & 0x8040) != 0x8040)) {
129 printk(KERN_ERR "sharpsl_pcmcia_socket_state(): CPR=%04X, Low voltage!\n", cpr);
130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
133
134static int sharpsl_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
135 const socket_state_t *state)
136{
137 unsigned long flags;
Richard Purdiea63ae442005-11-08 19:15:43 +0000138 struct device *scoop = SCOOP_DEV[skt->nr].dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 unsigned short cpr, ncpr, ccr, nccr, mcr, nmcr, imr, nimr;
141
142 switch (state->Vcc) {
143 case 0: break;
144 case 33: break;
145 case 50: break;
146 default:
147 printk(KERN_ERR "sharpsl_pcmcia_configure_socket(): bad Vcc %u\n", state->Vcc);
148 return -1;
149 }
150
151 if ((state->Vpp!=state->Vcc) && (state->Vpp!=0)) {
152 printk(KERN_ERR "CF slot cannot support Vpp %u\n", state->Vpp);
153 return -1;
154 }
155
156 local_irq_save(flags);
157
Richard Purdie0ce76252005-09-05 20:49:54 +0100158 nmcr = (mcr = read_scoop_reg(scoop, SCOOP_MCR)) & ~0x0010;
159 ncpr = (cpr = read_scoop_reg(scoop, SCOOP_CPR)) & ~0x0083;
160 nccr = (ccr = read_scoop_reg(scoop, SCOOP_CCR)) & ~0x0080;
161 nimr = (imr = read_scoop_reg(scoop, SCOOP_IMR)) & ~0x003E;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Richard Purdiea63ae442005-11-08 19:15:43 +0000163 if ((machine_is_spitz() || machine_is_borzoi() || machine_is_akita()) && skt->nr == 0) {
164 ncpr |= (state->Vcc == 33) ? 0x0002 :
165 (state->Vcc == 50) ? 0x0002 : 0;
166 } else {
167 ncpr |= (state->Vcc == 33) ? 0x0001 :
168 (state->Vcc == 50) ? 0x0002 : 0;
169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 nmcr |= (state->flags&SS_IOCARD) ? 0x0010 : 0;
171 ncpr |= (state->flags&SS_OUTPUT_ENA) ? 0x0080 : 0;
172 nccr |= (state->flags&SS_RESET)? 0x0080: 0;
173 nimr |= ((skt->status&SS_DETECT) ? 0x0004 : 0)|
174 ((skt->status&SS_READY) ? 0x0002 : 0)|
175 ((skt->status&SS_BATDEAD)? 0x0010 : 0)|
176 ((skt->status&SS_BATWARN)? 0x0020 : 0)|
177 ((skt->status&SS_STSCHG) ? 0x0010 : 0)|
178 ((skt->status&SS_WRPROT) ? 0x0008 : 0);
179
180 if (!(ncpr & 0x0003)) {
Richard Purdiea63ae442005-11-08 19:15:43 +0000181 SCOOP_DEV[skt->nr].keep_rd = 0;
182 } else if (!SCOOP_DEV[skt->nr].keep_rd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 if (nccr & 0x0080)
Richard Purdiea63ae442005-11-08 19:15:43 +0000184 SCOOP_DEV[skt->nr].keep_rd = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 else
186 nccr |= 0x0080;
187 }
188
189 if (mcr != nmcr)
Richard Purdie0ce76252005-09-05 20:49:54 +0100190 write_scoop_reg(scoop, SCOOP_MCR, nmcr);
Richard Purdiea63ae442005-11-08 19:15:43 +0000191 if (cpr != ncpr) {
192 if (platform_scoop_config->power_ctrl)
193 platform_scoop_config->power_ctrl(scoop, ncpr , skt->nr);
194 else
195 write_scoop_reg(scoop, SCOOP_CPR, ncpr);
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 if (ccr != nccr)
Richard Purdie0ce76252005-09-05 20:49:54 +0100198 write_scoop_reg(scoop, SCOOP_CCR, nccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if (imr != nimr)
Richard Purdie0ce76252005-09-05 20:49:54 +0100200 write_scoop_reg(scoop, SCOOP_IMR, nimr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 local_irq_restore(flags);
203
204 return 0;
205}
206
207static void sharpsl_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
208{
Richard Purdie945b9572006-01-05 20:44:57 +0000209 sharpsl_pcmcia_init_reset(skt);
Richard Purdie0ce76252005-09-05 20:49:54 +0100210
211 /* Enable interrupt */
Richard Purdiea63ae442005-11-08 19:15:43 +0000212 write_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_IMR, 0x00C0);
213 write_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_MCR, 0x0101);
214 SCOOP_DEV[skt->nr].keep_vs = NO_KEEP_VS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
217static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
218{
Richard Purdie945b9572006-01-05 20:44:57 +0000219 sharpsl_pcmcia_init_reset(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
221
Russell King4e5e8de2008-04-24 15:28:11 +0100222static struct pcmcia_low_level sharpsl_pcmcia_ops __initdata = {
Richard Purdiea63ae442005-11-08 19:15:43 +0000223 .owner = THIS_MODULE,
224 .hw_init = sharpsl_pcmcia_hw_init,
225 .hw_shutdown = sharpsl_pcmcia_hw_shutdown,
226 .socket_state = sharpsl_pcmcia_socket_state,
227 .configure_socket = sharpsl_pcmcia_configure_socket,
228 .socket_init = sharpsl_pcmcia_socket_init,
229 .socket_suspend = sharpsl_pcmcia_socket_suspend,
230 .first = 0,
231 .nr = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232};
233
Pavel Machek77bb86a2005-10-30 23:39:02 +0000234#ifdef CONFIG_SA1100_COLLIE
Richard Purdiea63ae442005-11-08 19:15:43 +0000235#include "sa11xx_base.h"
236
Uwe Kleine-König5b85e042010-11-04 10:46:14 +0100237int __devinit pcmcia_collie_init(struct device *dev)
Pavel Machek77bb86a2005-10-30 23:39:02 +0000238{
239 int ret = -ENODEV;
240
241 if (machine_is_collie())
242 ret = sa11xx_drv_pcmcia_probe(dev, &sharpsl_pcmcia_ops, 0, 1);
243
244 return ret;
245}
246
247#else
248
Richard Purdiea63ae442005-11-08 19:15:43 +0000249static struct platform_device *sharpsl_pcmcia_device;
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251static int __init sharpsl_pcmcia_init(void)
252{
253 int ret;
254
Dmitry Baryshkovae1036a2009-04-20 17:48:28 +0100255 if (!platform_scoop_config)
256 return -ENODEV;
257
Richard Purdieb0164502006-01-10 17:16:12 +0000258 sharpsl_pcmcia_ops.nr = platform_scoop_config->num_devs;
259 sharpsl_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 if (!sharpsl_pcmcia_device)
262 return -ENOMEM;
Richard Purdie0ce76252005-09-05 20:49:54 +0100263
Russell King4e5e8de2008-04-24 15:28:11 +0100264 ret = platform_device_add_data(sharpsl_pcmcia_device,
265 &sharpsl_pcmcia_ops, sizeof(sharpsl_pcmcia_ops));
266 if (ret == 0) {
267 sharpsl_pcmcia_device->dev.parent = platform_scoop_config->devs[0].dev;
268 ret = platform_device_add(sharpsl_pcmcia_device);
269 }
Richard Purdieb0164502006-01-10 17:16:12 +0000270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 if (ret)
Richard Purdieb0164502006-01-10 17:16:12 +0000272 platform_device_put(sharpsl_pcmcia_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 return ret;
275}
276
277static void __exit sharpsl_pcmcia_exit(void)
278{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 platform_device_unregister(sharpsl_pcmcia_device);
280}
281
Richard Purdief36598ae2005-09-03 19:39:25 +0100282fs_initcall(sharpsl_pcmcia_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283module_exit(sharpsl_pcmcia_exit);
Pavel Machek77bb86a2005-10-30 23:39:02 +0000284#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286MODULE_DESCRIPTION("Sharp SL Series PCMCIA Support");
287MODULE_LICENSE("GPL");
Kay Sievers43cc71e2007-08-18 04:40:39 +0200288MODULE_ALIAS("platform:pxa2xx-pcmcia");