[ARM] 5142/1: pxa: move move zaurus declarations to proper place
[linux-2.6.git] / drivers / pcmcia / pxa2xx_cm_x270.c
blobf123fce65f2e19e736fa54cf48958ce34fa8ca14
1 /*
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>
21 #include <asm/mach-types.h>
23 #include <asm/arch/pxa-regs.h>
24 #include <asm/arch/pxa2xx-gpio.h>
25 #include <asm/arch/cm-x270.h>
27 #include "soc_common.h"
29 static struct pcmcia_irqs irqs[] = {
30 { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" },
31 { 1, PCMCIA_S1_CD_VALID, "PCMCIA1 CD" },
34 static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
36 GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) |
37 GPIO_bit(GPIO49_nPWE) |
38 GPIO_bit(GPIO50_nPIOR) |
39 GPIO_bit(GPIO51_nPIOW) |
40 GPIO_bit(GPIO85_nPCE_1) |
41 GPIO_bit(GPIO54_nPCE_2);
43 pxa_gpio_mode(GPIO48_nPOE_MD);
44 pxa_gpio_mode(GPIO49_nPWE_MD);
45 pxa_gpio_mode(GPIO50_nPIOR_MD);
46 pxa_gpio_mode(GPIO51_nPIOW_MD);
47 pxa_gpio_mode(GPIO85_nPCE_1_MD);
48 pxa_gpio_mode(GPIO54_nPCE_2_MD);
49 pxa_gpio_mode(GPIO55_nPREG_MD);
50 pxa_gpio_mode(GPIO56_nPWAIT_MD);
51 pxa_gpio_mode(GPIO57_nIOIS16_MD);
53 /* Reset signal */
54 pxa_gpio_mode(GPIO53_nPCE_2 | GPIO_OUT);
55 GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
57 set_irq_type(PCMCIA_S0_CD_VALID, IRQ_TYPE_EDGE_BOTH);
58 set_irq_type(PCMCIA_S1_CD_VALID, IRQ_TYPE_EDGE_BOTH);
60 /* irq's for slots: */
61 set_irq_type(PCMCIA_S0_RDYINT, IRQ_TYPE_EDGE_FALLING);
62 set_irq_type(PCMCIA_S1_RDYINT, IRQ_TYPE_EDGE_FALLING);
64 skt->irq = (skt->nr == 0) ? PCMCIA_S0_RDYINT : PCMCIA_S1_RDYINT;
65 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
68 static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
70 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
72 set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_CD_VALID), IRQ_TYPE_NONE);
73 set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_CD_VALID), IRQ_TYPE_NONE);
75 set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_RDYINT), IRQ_TYPE_NONE);
76 set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_RDYINT), IRQ_TYPE_NONE);
80 static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
81 struct pcmcia_state *state)
83 state->detect = (PCC_DETECT(skt->nr) == 0) ? 1 : 0;
84 state->ready = (PCC_READY(skt->nr) == 0) ? 0 : 1;
85 state->bvd1 = 1;
86 state->bvd2 = 1;
87 state->vs_3v = 0;
88 state->vs_Xv = 0;
89 state->wrprot = 0; /* not available */
93 static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
94 const socket_state_t *state)
96 GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
97 pxa_gpio_mode(GPIO49_nPWE | GPIO_OUT);
99 switch (skt->nr) {
100 case 0:
101 if (state->flags & SS_RESET) {
102 GPCR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
103 GPSR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
104 udelay(10);
105 GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
106 GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
108 break;
109 case 1:
110 if (state->flags & SS_RESET) {
111 GPCR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
112 GPSR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
113 udelay(10);
114 GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
115 GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
117 break;
120 pxa_gpio_mode(GPIO49_nPWE_MD);
122 return 0;
125 static void cmx270_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
129 static void cmx270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
134 static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = {
135 .owner = THIS_MODULE,
136 .hw_init = cmx270_pcmcia_hw_init,
137 .hw_shutdown = cmx270_pcmcia_shutdown,
138 .socket_state = cmx270_pcmcia_socket_state,
139 .configure_socket = cmx270_pcmcia_configure_socket,
140 .socket_init = cmx270_pcmcia_socket_init,
141 .socket_suspend = cmx270_pcmcia_socket_suspend,
142 .nr = 2,
145 static struct platform_device *cmx270_pcmcia_device;
147 static int __init cmx270_pcmcia_init(void)
149 int ret;
151 if (!machine_is_armcore())
152 return -ENODEV;
154 cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
156 if (!cmx270_pcmcia_device)
157 return -ENOMEM;
159 ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops,
160 sizeof(cmx270_pcmcia_ops));
162 if (ret == 0) {
163 printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
164 ret = platform_device_add(cmx270_pcmcia_device);
167 if (ret)
168 platform_device_put(cmx270_pcmcia_device);
170 return ret;
173 static void __exit cmx270_pcmcia_exit(void)
175 platform_device_unregister(cmx270_pcmcia_device);
178 module_init(cmx270_pcmcia_init);
179 module_exit(cmx270_pcmcia_exit);
181 MODULE_LICENSE("GPL");
182 MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
183 MODULE_DESCRIPTION("CM-x270 PCMCIA driver");