2 * linux/drivers/pcmcia/pxa/pxa_cm_x270.c
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * Compulab Ltd., 2003, 2007
9 * Mike Rapoport <mike@compulab.co.il>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/platform_device.h>
16 #include <linux/irq.h>
17 #include <linux/delay.h>
19 #include <pcmcia/ss.h>
20 #include <asm/hardware.h>
22 #include <asm/arch/pxa-regs.h>
23 #include <asm/arch/pxa2xx-gpio.h>
24 #include <asm/arch/cm-x270.h>
26 #include "soc_common.h"
28 static struct pcmcia_irqs irqs
[] = {
29 { 0, PCMCIA_S0_CD_VALID
, "PCMCIA0 CD" },
30 { 1, PCMCIA_S1_CD_VALID
, "PCMCIA1 CD" },
33 static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket
*skt
)
35 GPSR(GPIO48_nPOE
) = GPIO_bit(GPIO48_nPOE
) |
36 GPIO_bit(GPIO49_nPWE
) |
37 GPIO_bit(GPIO50_nPIOR
) |
38 GPIO_bit(GPIO51_nPIOW
) |
39 GPIO_bit(GPIO85_nPCE_1
) |
40 GPIO_bit(GPIO54_nPCE_2
);
42 pxa_gpio_mode(GPIO48_nPOE_MD
);
43 pxa_gpio_mode(GPIO49_nPWE_MD
);
44 pxa_gpio_mode(GPIO50_nPIOR_MD
);
45 pxa_gpio_mode(GPIO51_nPIOW_MD
);
46 pxa_gpio_mode(GPIO85_nPCE_1_MD
);
47 pxa_gpio_mode(GPIO54_nPCE_2_MD
);
48 pxa_gpio_mode(GPIO55_nPREG_MD
);
49 pxa_gpio_mode(GPIO56_nPWAIT_MD
);
50 pxa_gpio_mode(GPIO57_nIOIS16_MD
);
53 pxa_gpio_mode(GPIO53_nPCE_2
| GPIO_OUT
);
54 GPCR(GPIO53_nPCE_2
) = GPIO_bit(GPIO53_nPCE_2
);
56 set_irq_type(PCMCIA_S0_CD_VALID
, IRQ_TYPE_EDGE_BOTH
);
57 set_irq_type(PCMCIA_S1_CD_VALID
, IRQ_TYPE_EDGE_BOTH
);
59 /* irq's for slots: */
60 set_irq_type(PCMCIA_S0_RDYINT
, IRQ_TYPE_EDGE_FALLING
);
61 set_irq_type(PCMCIA_S1_RDYINT
, IRQ_TYPE_EDGE_FALLING
);
63 skt
->irq
= (skt
->nr
== 0) ? PCMCIA_S0_RDYINT
: PCMCIA_S1_RDYINT
;
64 return soc_pcmcia_request_irqs(skt
, irqs
, ARRAY_SIZE(irqs
));
67 static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket
*skt
)
69 soc_pcmcia_free_irqs(skt
, irqs
, ARRAY_SIZE(irqs
));
71 set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_CD_VALID
), IRQ_TYPE_NONE
);
72 set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_CD_VALID
), IRQ_TYPE_NONE
);
74 set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_RDYINT
), IRQ_TYPE_NONE
);
75 set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_RDYINT
), IRQ_TYPE_NONE
);
79 static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket
*skt
,
80 struct pcmcia_state
*state
)
82 state
->detect
= (PCC_DETECT(skt
->nr
) == 0) ? 1 : 0;
83 state
->ready
= (PCC_READY(skt
->nr
) == 0) ? 0 : 1;
88 state
->wrprot
= 0; /* not available */
92 static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket
*skt
,
93 const socket_state_t
*state
)
95 GPSR(GPIO49_nPWE
) = GPIO_bit(GPIO49_nPWE
);
96 pxa_gpio_mode(GPIO49_nPWE
| GPIO_OUT
);
100 if (state
->flags
& SS_RESET
) {
101 GPCR(GPIO49_nPWE
) = GPIO_bit(GPIO49_nPWE
);
102 GPSR(GPIO53_nPCE_2
) = GPIO_bit(GPIO53_nPCE_2
);
104 GPCR(GPIO53_nPCE_2
) = GPIO_bit(GPIO53_nPCE_2
);
105 GPSR(GPIO49_nPWE
) = GPIO_bit(GPIO49_nPWE
);
109 if (state
->flags
& SS_RESET
) {
110 GPCR(GPIO49_nPWE
) = GPIO_bit(GPIO49_nPWE
);
111 GPSR(GPIO53_nPCE_2
) = GPIO_bit(GPIO53_nPCE_2
);
113 GPCR(GPIO53_nPCE_2
) = GPIO_bit(GPIO53_nPCE_2
);
114 GPSR(GPIO49_nPWE
) = GPIO_bit(GPIO49_nPWE
);
119 pxa_gpio_mode(GPIO49_nPWE_MD
);
124 static void cmx270_pcmcia_socket_init(struct soc_pcmcia_socket
*skt
)
128 static void cmx270_pcmcia_socket_suspend(struct soc_pcmcia_socket
*skt
)
133 static struct pcmcia_low_level cmx270_pcmcia_ops
= {
134 .owner
= THIS_MODULE
,
135 .hw_init
= cmx270_pcmcia_hw_init
,
136 .hw_shutdown
= cmx270_pcmcia_shutdown
,
137 .socket_state
= cmx270_pcmcia_socket_state
,
138 .configure_socket
= cmx270_pcmcia_configure_socket
,
139 .socket_init
= cmx270_pcmcia_socket_init
,
140 .socket_suspend
= cmx270_pcmcia_socket_suspend
,
144 static struct platform_device
*cmx270_pcmcia_device
;
146 static int __init
cmx270_pcmcia_init(void)
150 cmx270_pcmcia_device
= platform_device_alloc("pxa2xx-pcmcia", -1);
152 if (!cmx270_pcmcia_device
)
155 cmx270_pcmcia_device
->dev
.platform_data
= &cmx270_pcmcia_ops
;
157 printk(KERN_INFO
"Registering cm-x270 PCMCIA interface.\n");
158 ret
= platform_device_add(cmx270_pcmcia_device
);
161 platform_device_put(cmx270_pcmcia_device
);
166 static void __exit
cmx270_pcmcia_exit(void)
168 platform_device_unregister(cmx270_pcmcia_device
);
171 module_init(cmx270_pcmcia_init
);
172 module_exit(cmx270_pcmcia_exit
);
174 MODULE_LICENSE("GPL");
175 MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
176 MODULE_DESCRIPTION("CM-x270 PCMCIA driver");