2 * linux/drivers/pcmcia/sa1111_generic.c
4 * We implement the generic parts of a SA1111 PCMCIA driver. This
5 * basically means we handle everything except controlling the
6 * power. Power is machine specific...
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/ioport.h>
11 #include <linux/device.h>
12 #include <linux/interrupt.h>
13 #include <linux/init.h>
15 #include <linux/slab.h>
17 #include <pcmcia/ss.h>
19 #include <mach/hardware.h>
20 #include <asm/hardware/sa1111.h>
23 #include "sa1111_generic.h"
25 #define IDX_IRQ_S0_READY_NINT (0)
26 #define IDX_IRQ_S0_CD_VALID (1)
27 #define IDX_IRQ_S0_BVD1_STSCHG (2)
28 #define IDX_IRQ_S1_READY_NINT (3)
29 #define IDX_IRQ_S1_CD_VALID (4)
30 #define IDX_IRQ_S1_BVD1_STSCHG (5)
32 static struct pcmcia_irqs irqs
[] = {
33 { 0, NO_IRQ
, "SA1111 PCMCIA card detect" },
34 { 0, NO_IRQ
, "SA1111 PCMCIA BVD1" },
35 { 1, NO_IRQ
, "SA1111 CF card detect" },
36 { 1, NO_IRQ
, "SA1111 CF BVD1" },
39 static int sa1111_pcmcia_hw_init(struct soc_pcmcia_socket
*skt
)
41 return soc_pcmcia_request_irqs(skt
, irqs
, ARRAY_SIZE(irqs
));
44 static void sa1111_pcmcia_hw_shutdown(struct soc_pcmcia_socket
*skt
)
46 soc_pcmcia_free_irqs(skt
, irqs
, ARRAY_SIZE(irqs
));
49 void sa1111_pcmcia_socket_state(struct soc_pcmcia_socket
*skt
, struct pcmcia_state
*state
)
51 struct sa1111_pcmcia_socket
*s
= to_skt(skt
);
52 unsigned long status
= sa1111_readl(s
->dev
->mapbase
+ SA1111_PCSR
);
56 state
->detect
= status
& PCSR_S0_DETECT
? 0 : 1;
57 state
->ready
= status
& PCSR_S0_READY
? 1 : 0;
58 state
->bvd1
= status
& PCSR_S0_BVD1
? 1 : 0;
59 state
->bvd2
= status
& PCSR_S0_BVD2
? 1 : 0;
60 state
->wrprot
= status
& PCSR_S0_WP
? 1 : 0;
61 state
->vs_3v
= status
& PCSR_S0_VS1
? 0 : 1;
62 state
->vs_Xv
= status
& PCSR_S0_VS2
? 0 : 1;
66 state
->detect
= status
& PCSR_S1_DETECT
? 0 : 1;
67 state
->ready
= status
& PCSR_S1_READY
? 1 : 0;
68 state
->bvd1
= status
& PCSR_S1_BVD1
? 1 : 0;
69 state
->bvd2
= status
& PCSR_S1_BVD2
? 1 : 0;
70 state
->wrprot
= status
& PCSR_S1_WP
? 1 : 0;
71 state
->vs_3v
= status
& PCSR_S1_VS1
? 0 : 1;
72 state
->vs_Xv
= status
& PCSR_S1_VS2
? 0 : 1;
77 int sa1111_pcmcia_configure_socket(struct soc_pcmcia_socket
*skt
, const socket_state_t
*state
)
79 struct sa1111_pcmcia_socket
*s
= to_skt(skt
);
80 unsigned int pccr_skt_mask
, pccr_set_mask
, val
;
85 pccr_skt_mask
= PCCR_S0_RST
|PCCR_S0_FLT
|PCCR_S0_PWAITEN
|PCCR_S0_PSE
;
89 pccr_skt_mask
= PCCR_S1_RST
|PCCR_S1_FLT
|PCCR_S1_PWAITEN
|PCCR_S1_PSE
;
99 pccr_set_mask
|= PCCR_S0_PWAITEN
|PCCR_S1_PWAITEN
;
100 if (state
->Vcc
== 50)
101 pccr_set_mask
|= PCCR_S0_PSE
|PCCR_S1_PSE
;
102 if (state
->flags
& SS_RESET
)
103 pccr_set_mask
|= PCCR_S0_RST
|PCCR_S1_RST
;
104 if (state
->flags
& SS_OUTPUT_ENA
)
105 pccr_set_mask
|= PCCR_S0_FLT
|PCCR_S1_FLT
;
107 local_irq_save(flags
);
108 val
= sa1111_readl(s
->dev
->mapbase
+ SA1111_PCCR
);
109 val
&= ~pccr_skt_mask
;
110 val
|= pccr_set_mask
& pccr_skt_mask
;
111 sa1111_writel(val
, s
->dev
->mapbase
+ SA1111_PCCR
);
112 local_irq_restore(flags
);
117 void sa1111_pcmcia_socket_init(struct soc_pcmcia_socket
*skt
)
119 soc_pcmcia_enable_irqs(skt
, irqs
, ARRAY_SIZE(irqs
));
122 static void sa1111_pcmcia_socket_suspend(struct soc_pcmcia_socket
*skt
)
124 soc_pcmcia_disable_irqs(skt
, irqs
, ARRAY_SIZE(irqs
));
127 int sa1111_pcmcia_add(struct sa1111_dev
*dev
, struct pcmcia_low_level
*ops
,
128 int (*add
)(struct soc_pcmcia_socket
*))
130 struct sa1111_pcmcia_socket
*s
;
133 ops
->hw_init
= sa1111_pcmcia_hw_init
;
134 ops
->hw_shutdown
= sa1111_pcmcia_hw_shutdown
;
135 ops
->socket_state
= sa1111_pcmcia_socket_state
;
136 ops
->socket_suspend
= sa1111_pcmcia_socket_suspend
;
138 for (i
= 0; i
< ops
->nr
; i
++) {
139 s
= kzalloc(sizeof(*s
), GFP_KERNEL
);
143 s
->soc
.nr
= ops
->first
+ i
;
145 s
->soc
.socket
.owner
= ops
->owner
;
146 s
->soc
.socket
.dev
.parent
= &dev
->dev
;
147 s
->soc
.socket
.pci_irq
= s
->soc
.nr
?
148 dev
->irq
[IDX_IRQ_S0_READY_NINT
] :
149 dev
->irq
[IDX_IRQ_S1_READY_NINT
];
154 s
->next
= dev_get_drvdata(&dev
->dev
);
155 dev_set_drvdata(&dev
->dev
, s
);
163 static int pcmcia_probe(struct sa1111_dev
*dev
)
167 dev_set_drvdata(&dev
->dev
, NULL
);
169 if (!request_mem_region(dev
->res
.start
, 512,
170 SA1111_DRIVER_NAME(dev
)))
175 /* Initialize PCMCIA IRQs */
176 irqs
[0].irq
= dev
->irq
[IDX_IRQ_S0_CD_VALID
];
177 irqs
[1].irq
= dev
->irq
[IDX_IRQ_S0_BVD1_STSCHG
];
178 irqs
[2].irq
= dev
->irq
[IDX_IRQ_S1_CD_VALID
];
179 irqs
[3].irq
= dev
->irq
[IDX_IRQ_S1_BVD1_STSCHG
];
182 * Initialise the suspend state.
184 sa1111_writel(PCSSR_S0_SLEEP
| PCSSR_S1_SLEEP
, base
+ SA1111_PCSSR
);
185 sa1111_writel(PCCR_S0_FLT
| PCCR_S1_FLT
, base
+ SA1111_PCCR
);
187 #ifdef CONFIG_SA1100_BADGE4
188 pcmcia_badge4_init(&dev
->dev
);
190 #ifdef CONFIG_SA1100_JORNADA720
191 pcmcia_jornada720_init(&dev
->dev
);
193 #ifdef CONFIG_ARCH_LUBBOCK
194 pcmcia_lubbock_init(dev
);
196 #ifdef CONFIG_ASSABET_NEPONSET
197 pcmcia_neponset_init(dev
);
202 static int __devexit
pcmcia_remove(struct sa1111_dev
*dev
)
204 struct sa1111_pcmcia_socket
*next
, *s
= dev_get_drvdata(&dev
->dev
);
206 dev_set_drvdata(&dev
->dev
, NULL
);
208 for (; s
; s
= next
) {
210 soc_pcmcia_remove_one(&s
->soc
);
214 release_mem_region(dev
->res
.start
, 512);
218 static struct sa1111_driver pcmcia_driver
= {
220 .name
= "sa1111-pcmcia",
222 .devid
= SA1111_DEVID_PCMCIA
,
223 .probe
= pcmcia_probe
,
224 .remove
= __devexit_p(pcmcia_remove
),
227 static int __init
sa1111_drv_pcmcia_init(void)
229 return sa1111_driver_register(&pcmcia_driver
);
232 static void __exit
sa1111_drv_pcmcia_exit(void)
234 sa1111_driver_unregister(&pcmcia_driver
);
237 fs_initcall(sa1111_drv_pcmcia_init
);
238 module_exit(sa1111_drv_pcmcia_exit
);
240 MODULE_DESCRIPTION("SA1111 PCMCIA card socket driver");
241 MODULE_LICENSE("GPL");