1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/pcmcia/sa1111_generic.c
5 * We implement the generic parts of a SA1111 PCMCIA driver. This
6 * basically means we handle everything except controlling the
7 * power. Power is machine specific...
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/ioport.h>
12 #include <linux/device.h>
13 #include <linux/interrupt.h>
14 #include <linux/init.h>
16 #include <linux/slab.h>
18 #include <pcmcia/ss.h>
20 #include <asm/hardware/sa1111.h>
21 #include <asm/mach-types.h>
24 #include "sa1111_generic.h"
27 * These are offsets from the above base.
33 #define PCSR_S0_READY (1<<0)
34 #define PCSR_S1_READY (1<<1)
35 #define PCSR_S0_DETECT (1<<2)
36 #define PCSR_S1_DETECT (1<<3)
37 #define PCSR_S0_VS1 (1<<4)
38 #define PCSR_S0_VS2 (1<<5)
39 #define PCSR_S1_VS1 (1<<6)
40 #define PCSR_S1_VS2 (1<<7)
41 #define PCSR_S0_WP (1<<8)
42 #define PCSR_S1_WP (1<<9)
43 #define PCSR_S0_BVD1 (1<<10)
44 #define PCSR_S0_BVD2 (1<<11)
45 #define PCSR_S1_BVD1 (1<<12)
46 #define PCSR_S1_BVD2 (1<<13)
48 #define PCCR_S0_RST (1<<0)
49 #define PCCR_S1_RST (1<<1)
50 #define PCCR_S0_FLT (1<<2)
51 #define PCCR_S1_FLT (1<<3)
52 #define PCCR_S0_PWAITEN (1<<4)
53 #define PCCR_S1_PWAITEN (1<<5)
54 #define PCCR_S0_PSE (1<<6)
55 #define PCCR_S1_PSE (1<<7)
57 #define PCSSR_S0_SLEEP (1<<0)
58 #define PCSSR_S1_SLEEP (1<<1)
60 #define IDX_IRQ_S0_READY_NINT (0)
61 #define IDX_IRQ_S0_CD_VALID (1)
62 #define IDX_IRQ_S0_BVD1_STSCHG (2)
63 #define IDX_IRQ_S1_READY_NINT (3)
64 #define IDX_IRQ_S1_CD_VALID (4)
65 #define IDX_IRQ_S1_BVD1_STSCHG (5)
68 void sa1111_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
70 struct sa1111_pcmcia_socket *s = to_skt(skt);
71 u32 status = readl_relaxed(s->dev->mapbase + PCSR);
75 state->detect = status & PCSR_S0_DETECT ? 0 : 1;
76 state->ready = status & PCSR_S0_READY ? 1 : 0;
77 state->bvd1 = status & PCSR_S0_BVD1 ? 1 : 0;
78 state->bvd2 = status & PCSR_S0_BVD2 ? 1 : 0;
79 state->wrprot = status & PCSR_S0_WP ? 1 : 0;
80 state->vs_3v = status & PCSR_S0_VS1 ? 0 : 1;
81 state->vs_Xv = status & PCSR_S0_VS2 ? 0 : 1;
85 state->detect = status & PCSR_S1_DETECT ? 0 : 1;
86 state->ready = status & PCSR_S1_READY ? 1 : 0;
87 state->bvd1 = status & PCSR_S1_BVD1 ? 1 : 0;
88 state->bvd2 = status & PCSR_S1_BVD2 ? 1 : 0;
89 state->wrprot = status & PCSR_S1_WP ? 1 : 0;
90 state->vs_3v = status & PCSR_S1_VS1 ? 0 : 1;
91 state->vs_Xv = status & PCSR_S1_VS2 ? 0 : 1;
96 int sa1111_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
98 struct sa1111_pcmcia_socket *s = to_skt(skt);
99 u32 pccr_skt_mask, pccr_set_mask, val;
104 pccr_skt_mask = PCCR_S0_RST|PCCR_S0_FLT|PCCR_S0_PWAITEN|PCCR_S0_PSE;
108 pccr_skt_mask = PCCR_S1_RST|PCCR_S1_FLT|PCCR_S1_PWAITEN|PCCR_S1_PSE;
118 pccr_set_mask |= PCCR_S0_PWAITEN|PCCR_S1_PWAITEN;
119 if (state->Vcc == 50)
120 pccr_set_mask |= PCCR_S0_PSE|PCCR_S1_PSE;
121 if (state->flags & SS_RESET)
122 pccr_set_mask |= PCCR_S0_RST|PCCR_S1_RST;
123 if (state->flags & SS_OUTPUT_ENA)
124 pccr_set_mask |= PCCR_S0_FLT|PCCR_S1_FLT;
126 local_irq_save(flags);
127 val = readl_relaxed(s->dev->mapbase + PCCR);
128 val &= ~pccr_skt_mask;
129 val |= pccr_set_mask & pccr_skt_mask;
130 writel_relaxed(val, s->dev->mapbase + PCCR);
131 local_irq_restore(flags);
136 int sa1111_pcmcia_add(struct sa1111_dev *dev, struct pcmcia_low_level *ops,
137 int (*add)(struct soc_pcmcia_socket *))
139 struct sa1111_pcmcia_socket *s;
141 int i, ret = 0, irqs[NUM_IRQS];
143 clk = devm_clk_get(&dev->dev, NULL);
147 for (i = 0; i < NUM_IRQS; i++) {
148 irqs[i] = sa1111_get_irq(dev, i);
150 return irqs[i] ? : -ENXIO;
153 ops->socket_state = sa1111_pcmcia_socket_state;
155 for (i = 0; i < ops->nr; i++) {
156 s = kzalloc(sizeof(*s), GFP_KERNEL);
160 s->soc.nr = ops->first + i;
163 soc_pcmcia_init_one(&s->soc, ops, &dev->dev);
166 s->soc.socket.pci_irq = irqs[IDX_IRQ_S1_READY_NINT];
167 s->soc.stat[SOC_STAT_CD].irq = irqs[IDX_IRQ_S1_CD_VALID];
168 s->soc.stat[SOC_STAT_CD].name = "SA1111 CF card detect";
169 s->soc.stat[SOC_STAT_BVD1].irq = irqs[IDX_IRQ_S1_BVD1_STSCHG];
170 s->soc.stat[SOC_STAT_BVD1].name = "SA1111 CF BVD1";
172 s->soc.socket.pci_irq = irqs[IDX_IRQ_S0_READY_NINT];
173 s->soc.stat[SOC_STAT_CD].irq = irqs[IDX_IRQ_S0_CD_VALID];
174 s->soc.stat[SOC_STAT_CD].name = "SA1111 PCMCIA card detect";
175 s->soc.stat[SOC_STAT_BVD1].irq = irqs[IDX_IRQ_S0_BVD1_STSCHG];
176 s->soc.stat[SOC_STAT_BVD1].name = "SA1111 PCMCIA BVD1";
181 s->next = dev_get_drvdata(&dev->dev);
182 dev_set_drvdata(&dev->dev, s);
190 static int pcmcia_probe(struct sa1111_dev *dev)
195 ret = sa1111_enable_device(dev);
199 dev_set_drvdata(&dev->dev, NULL);
201 if (!request_mem_region(dev->res.start, 512, SA1111_DRIVER_NAME(dev))) {
202 sa1111_disable_device(dev);
209 * Initialise the suspend state.
211 writel_relaxed(PCSSR_S0_SLEEP | PCSSR_S1_SLEEP, base + PCSSR);
212 writel_relaxed(PCCR_S0_FLT | PCCR_S1_FLT, base + PCCR);
215 #ifdef CONFIG_SA1100_JORNADA720
216 if (machine_is_jornada720())
217 ret = pcmcia_jornada720_init(dev);
219 #ifdef CONFIG_ASSABET_NEPONSET
220 if (machine_is_assabet())
221 ret = pcmcia_neponset_init(dev);
225 release_mem_region(dev->res.start, 512);
226 sa1111_disable_device(dev);
232 static void pcmcia_remove(struct sa1111_dev *dev)
234 struct sa1111_pcmcia_socket *next, *s = dev_get_drvdata(&dev->dev);
236 dev_set_drvdata(&dev->dev, NULL);
238 for (; s; s = next) {
240 soc_pcmcia_remove_one(&s->soc);
244 release_mem_region(dev->res.start, 512);
245 sa1111_disable_device(dev);
248 static struct sa1111_driver pcmcia_driver = {
250 .name = "sa1111-pcmcia",
252 .devid = SA1111_DEVID_PCMCIA,
253 .probe = pcmcia_probe,
254 .remove = pcmcia_remove,
257 static int __init sa1111_drv_pcmcia_init(void)
259 return sa1111_driver_register(&pcmcia_driver);
262 static void __exit sa1111_drv_pcmcia_exit(void)
264 sa1111_driver_unregister(&pcmcia_driver);
267 fs_initcall(sa1111_drv_pcmcia_init);
268 module_exit(sa1111_drv_pcmcia_exit);
270 MODULE_DESCRIPTION("SA1111 PCMCIA card socket driver");
271 MODULE_LICENSE("GPL");