blob: 5fdd25a9e28eea6e7c7be7aac7329260cf4507d4 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Sharp SL-C7xx Series PCMCIA routines
4 *
5 * Copyright (c) 2004-2005 Richard Purdie
6 *
7 * Based on Sharp's 2.4 kernel patches and pxa2xx_mainstone.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/interrupt.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010015#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Pavel Machek77bb86a2005-10-30 23:39:02 +000017#include <asm/mach-types.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010018#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/hardware/scoop.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include "soc_common.h"
23
24#define NO_KEEP_VS 0x0001
Richard Purdiea63ae442005-11-08 19:15:43 +000025#define SCOOP_DEV platform_scoop_config->devs
26
Richard Purdie945b9572006-01-05 20:44:57 +000027static void sharpsl_pcmcia_init_reset(struct soc_pcmcia_socket *skt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
Richard Purdie945b9572006-01-05 20:44:57 +000029 struct scoop_pcmcia_dev *scoopdev = &SCOOP_DEV[skt->nr];
30
Richard Purdie0ce76252005-09-05 20:49:54 +010031 reset_scoop(scoopdev->dev);
Richard Purdie945b9572006-01-05 20:44:57 +000032
33 /* Shared power controls need to be handled carefully */
34 if (platform_scoop_config->power_ctrl)
35 platform_scoop_config->power_ctrl(scoopdev->dev, 0x0000, skt->nr);
36 else
37 write_scoop_reg(scoopdev->dev, SCOOP_CPR, 0x0000);
38
Richard Purdie0ce76252005-09-05 20:49:54 +010039 scoopdev->keep_vs = NO_KEEP_VS;
40 scoopdev->keep_rd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
43static int sharpsl_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
44{
Richard Purdiea63ae442005-11-08 19:15:43 +000045 if (SCOOP_DEV[skt->nr].cd_irq >= 0) {
Russell Kinga9bb5a42012-01-13 22:56:32 +000046 skt->stat[SOC_STAT_CD].irq = SCOOP_DEV[skt->nr].cd_irq;
47 skt->stat[SOC_STAT_CD].name = SCOOP_DEV[skt->nr].cd_irq_str;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 }
49
Russell King - ARM Linux66024db2009-03-29 22:45:26 +010050 skt->socket.pci_irq = SCOOP_DEV[skt->nr].irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52 return 0;
53}
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055static void sharpsl_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
56 struct pcmcia_state *state)
57{
58 unsigned short cpr, csr;
Richard Purdiea63ae442005-11-08 19:15:43 +000059 struct device *scoop = SCOOP_DEV[skt->nr].dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Richard Purdiea63ae442005-11-08 19:15:43 +000061 cpr = read_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_CPR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Richard Purdie0ce76252005-09-05 20:49:54 +010063 write_scoop_reg(scoop, SCOOP_IRM, 0x00FF);
64 write_scoop_reg(scoop, SCOOP_ISR, 0x0000);
65 write_scoop_reg(scoop, SCOOP_IRM, 0x0000);
66 csr = read_scoop_reg(scoop, SCOOP_CSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 if (csr & 0x0004) {
68 /* card eject */
Richard Purdie0ce76252005-09-05 20:49:54 +010069 write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
Richard Purdiea63ae442005-11-08 19:15:43 +000070 SCOOP_DEV[skt->nr].keep_vs = NO_KEEP_VS;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 }
Richard Purdiea63ae442005-11-08 19:15:43 +000072 else if (!(SCOOP_DEV[skt->nr].keep_vs & NO_KEEP_VS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 /* keep vs1,vs2 */
Richard Purdie0ce76252005-09-05 20:49:54 +010074 write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
Richard Purdiea63ae442005-11-08 19:15:43 +000075 csr |= SCOOP_DEV[skt->nr].keep_vs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 }
77 else if (cpr & 0x0003) {
78 /* power on */
Richard Purdie0ce76252005-09-05 20:49:54 +010079 write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
Richard Purdiea63ae442005-11-08 19:15:43 +000080 SCOOP_DEV[skt->nr].keep_vs = (csr & 0x00C0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
82 else {
83 /* card detect */
Richard Purdiea63ae442005-11-08 19:15:43 +000084 if ((machine_is_spitz() || machine_is_borzoi()) && skt->nr == 1) {
85 write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
86 } else {
87 write_scoop_reg(scoop, SCOOP_CDR, 0x0002);
88 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
90
91 state->detect = (csr & 0x0004) ? 0 : 1;
92 state->ready = (csr & 0x0002) ? 1 : 0;
93 state->bvd1 = (csr & 0x0010) ? 1 : 0;
94 state->bvd2 = (csr & 0x0020) ? 1 : 0;
95 state->wrprot = (csr & 0x0008) ? 1 : 0;
96 state->vs_3v = (csr & 0x0040) ? 0 : 1;
97 state->vs_Xv = (csr & 0x0080) ? 0 : 1;
98
99 if ((cpr & 0x0080) && ((cpr & 0x8040) != 0x8040)) {
100 printk(KERN_ERR "sharpsl_pcmcia_socket_state(): CPR=%04X, Low voltage!\n", cpr);
101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
104
105static int sharpsl_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
106 const socket_state_t *state)
107{
108 unsigned long flags;
Richard Purdiea63ae442005-11-08 19:15:43 +0000109 struct device *scoop = SCOOP_DEV[skt->nr].dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 unsigned short cpr, ncpr, ccr, nccr, mcr, nmcr, imr, nimr;
112
113 switch (state->Vcc) {
114 case 0: break;
115 case 33: break;
116 case 50: break;
117 default:
118 printk(KERN_ERR "sharpsl_pcmcia_configure_socket(): bad Vcc %u\n", state->Vcc);
119 return -1;
120 }
121
122 if ((state->Vpp!=state->Vcc) && (state->Vpp!=0)) {
123 printk(KERN_ERR "CF slot cannot support Vpp %u\n", state->Vpp);
124 return -1;
125 }
126
127 local_irq_save(flags);
128
Richard Purdie0ce76252005-09-05 20:49:54 +0100129 nmcr = (mcr = read_scoop_reg(scoop, SCOOP_MCR)) & ~0x0010;
130 ncpr = (cpr = read_scoop_reg(scoop, SCOOP_CPR)) & ~0x0083;
131 nccr = (ccr = read_scoop_reg(scoop, SCOOP_CCR)) & ~0x0080;
132 nimr = (imr = read_scoop_reg(scoop, SCOOP_IMR)) & ~0x003E;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Richard Purdiea63ae442005-11-08 19:15:43 +0000134 if ((machine_is_spitz() || machine_is_borzoi() || machine_is_akita()) && skt->nr == 0) {
135 ncpr |= (state->Vcc == 33) ? 0x0002 :
136 (state->Vcc == 50) ? 0x0002 : 0;
137 } else {
138 ncpr |= (state->Vcc == 33) ? 0x0001 :
139 (state->Vcc == 50) ? 0x0002 : 0;
140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 nmcr |= (state->flags&SS_IOCARD) ? 0x0010 : 0;
142 ncpr |= (state->flags&SS_OUTPUT_ENA) ? 0x0080 : 0;
143 nccr |= (state->flags&SS_RESET)? 0x0080: 0;
144 nimr |= ((skt->status&SS_DETECT) ? 0x0004 : 0)|
145 ((skt->status&SS_READY) ? 0x0002 : 0)|
146 ((skt->status&SS_BATDEAD)? 0x0010 : 0)|
147 ((skt->status&SS_BATWARN)? 0x0020 : 0)|
148 ((skt->status&SS_STSCHG) ? 0x0010 : 0)|
149 ((skt->status&SS_WRPROT) ? 0x0008 : 0);
150
151 if (!(ncpr & 0x0003)) {
Richard Purdiea63ae442005-11-08 19:15:43 +0000152 SCOOP_DEV[skt->nr].keep_rd = 0;
153 } else if (!SCOOP_DEV[skt->nr].keep_rd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 if (nccr & 0x0080)
Richard Purdiea63ae442005-11-08 19:15:43 +0000155 SCOOP_DEV[skt->nr].keep_rd = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 else
157 nccr |= 0x0080;
158 }
159
160 if (mcr != nmcr)
Richard Purdie0ce76252005-09-05 20:49:54 +0100161 write_scoop_reg(scoop, SCOOP_MCR, nmcr);
Richard Purdiea63ae442005-11-08 19:15:43 +0000162 if (cpr != ncpr) {
163 if (platform_scoop_config->power_ctrl)
164 platform_scoop_config->power_ctrl(scoop, ncpr , skt->nr);
165 else
166 write_scoop_reg(scoop, SCOOP_CPR, ncpr);
167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 if (ccr != nccr)
Richard Purdie0ce76252005-09-05 20:49:54 +0100169 write_scoop_reg(scoop, SCOOP_CCR, nccr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 if (imr != nimr)
Richard Purdie0ce76252005-09-05 20:49:54 +0100171 write_scoop_reg(scoop, SCOOP_IMR, nimr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 local_irq_restore(flags);
174
175 return 0;
176}
177
178static void sharpsl_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
179{
Richard Purdie945b9572006-01-05 20:44:57 +0000180 sharpsl_pcmcia_init_reset(skt);
Richard Purdie0ce76252005-09-05 20:49:54 +0100181
182 /* Enable interrupt */
Richard Purdiea63ae442005-11-08 19:15:43 +0000183 write_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_IMR, 0x00C0);
184 write_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_MCR, 0x0101);
185 SCOOP_DEV[skt->nr].keep_vs = NO_KEEP_VS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}
187
188static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
189{
Richard Purdie945b9572006-01-05 20:44:57 +0000190 sharpsl_pcmcia_init_reset(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
192
Arnd Bergmannfdc858a462012-04-30 13:50:56 +0000193static struct pcmcia_low_level sharpsl_pcmcia_ops = {
Richard Purdiea63ae442005-11-08 19:15:43 +0000194 .owner = THIS_MODULE,
195 .hw_init = sharpsl_pcmcia_hw_init,
Richard Purdiea63ae442005-11-08 19:15:43 +0000196 .socket_state = sharpsl_pcmcia_socket_state,
197 .configure_socket = sharpsl_pcmcia_configure_socket,
198 .socket_init = sharpsl_pcmcia_socket_init,
199 .socket_suspend = sharpsl_pcmcia_socket_suspend,
200 .first = 0,
201 .nr = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202};
203
Pavel Machek77bb86a2005-10-30 23:39:02 +0000204#ifdef CONFIG_SA1100_COLLIE
Richard Purdiea63ae442005-11-08 19:15:43 +0000205#include "sa11xx_base.h"
206
Bill Pemberton34cdf252012-11-19 13:23:12 -0500207int pcmcia_collie_init(struct device *dev)
Pavel Machek77bb86a2005-10-30 23:39:02 +0000208{
209 int ret = -ENODEV;
210
211 if (machine_is_collie())
212 ret = sa11xx_drv_pcmcia_probe(dev, &sharpsl_pcmcia_ops, 0, 1);
213
214 return ret;
215}
216
217#else
218
Richard Purdiea63ae442005-11-08 19:15:43 +0000219static struct platform_device *sharpsl_pcmcia_device;
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static int __init sharpsl_pcmcia_init(void)
222{
223 int ret;
224
Dmitry Baryshkovae1036a2009-04-20 17:48:28 +0100225 if (!platform_scoop_config)
226 return -ENODEV;
227
Richard Purdieb0164502006-01-10 17:16:12 +0000228 sharpsl_pcmcia_ops.nr = platform_scoop_config->num_devs;
229 sharpsl_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 if (!sharpsl_pcmcia_device)
232 return -ENOMEM;
Richard Purdie0ce76252005-09-05 20:49:54 +0100233
Russell King4e5e8de2008-04-24 15:28:11 +0100234 ret = platform_device_add_data(sharpsl_pcmcia_device,
235 &sharpsl_pcmcia_ops, sizeof(sharpsl_pcmcia_ops));
236 if (ret == 0) {
237 sharpsl_pcmcia_device->dev.parent = platform_scoop_config->devs[0].dev;
238 ret = platform_device_add(sharpsl_pcmcia_device);
239 }
Richard Purdieb0164502006-01-10 17:16:12 +0000240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 if (ret)
Richard Purdieb0164502006-01-10 17:16:12 +0000242 platform_device_put(sharpsl_pcmcia_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 return ret;
245}
246
247static void __exit sharpsl_pcmcia_exit(void)
248{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 platform_device_unregister(sharpsl_pcmcia_device);
250}
251
Richard Purdief36598ae2005-09-03 19:39:25 +0100252fs_initcall(sharpsl_pcmcia_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253module_exit(sharpsl_pcmcia_exit);
Pavel Machek77bb86a2005-10-30 23:39:02 +0000254#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256MODULE_DESCRIPTION("Sharp SL Series PCMCIA Support");
257MODULE_LICENSE("GPL");
Kay Sievers43cc71e2007-08-18 04:40:39 +0200258MODULE_ALIAS("platform:pxa2xx-pcmcia");