x86, mrst: use a temporary variable for SFI irq
[linux-btrfs-devel.git] / drivers / pcmcia / pxa2xx_trizeps4.c
blob57ddb969d888508c68cb701fd1252e16c6d00ada
1 /*
2 * linux/drivers/pcmcia/pxa2xx_trizeps4.c
4 * TRIZEPS PCMCIA specific routines.
6 * Author: Jürgen Schindele
7 * Created: 20 02, 2006
8 * Copyright: Jürgen Schindele
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/gpio.h>
19 #include <linux/interrupt.h>
20 #include <linux/platform_device.h>
22 #include <asm/mach-types.h>
23 #include <asm/irq.h>
25 #include <mach/pxa2xx-regs.h>
26 #include <mach/trizeps4.h>
28 #include "soc_common.h"
30 extern void board_pcmcia_power(int power);
32 static struct pcmcia_irqs irqs[] = {
33 { 0, IRQ_GPIO(GPIO_PCD), "cs0_cd" }
34 /* on other baseboards we can have more inputs */
37 static int trizeps_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
39 int ret, i;
40 /* we dont have voltage/card/ready detection
41 * so we dont need interrupts for it
43 switch (skt->nr) {
44 case 0:
45 if (gpio_request(GPIO_PRDY, "cf_irq") < 0) {
46 pr_err("%s: sock %d unable to request gpio %d\n", __func__,
47 skt->nr, GPIO_PRDY);
48 return -EBUSY;
50 if (gpio_direction_input(GPIO_PRDY) < 0) {
51 pr_err("%s: sock %d unable to set input gpio %d\n", __func__,
52 skt->nr, GPIO_PRDY);
53 gpio_free(GPIO_PRDY);
54 return -EINVAL;
56 skt->socket.pci_irq = IRQ_GPIO(GPIO_PRDY);
57 break;
58 default:
59 break;
61 /* release the reset of this card */
62 pr_debug("%s: sock %d irq %d\n", __func__, skt->nr, skt->socket.pci_irq);
64 /* supplementory irqs for the socket */
65 for (i = 0; i < ARRAY_SIZE(irqs); i++) {
66 if (irqs[i].sock != skt->nr)
67 continue;
68 if (gpio_request(irq_to_gpio(irqs[i].irq), irqs[i].str) < 0) {
69 pr_err("%s: sock %d unable to request gpio %d\n",
70 __func__, skt->nr, irq_to_gpio(irqs[i].irq));
71 ret = -EBUSY;
72 goto error;
74 if (gpio_direction_input(irq_to_gpio(irqs[i].irq)) < 0) {
75 pr_err("%s: sock %d unable to set input gpio %d\n",
76 __func__, skt->nr, irq_to_gpio(irqs[i].irq));
77 ret = -EINVAL;
78 goto error;
81 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
83 error:
84 for (; i >= 0; i--) {
85 gpio_free(irq_to_gpio(irqs[i].irq));
87 return (ret);
90 static void trizeps_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
92 int i;
93 /* free allocated gpio's */
94 gpio_free(GPIO_PRDY);
95 for (i = 0; i < ARRAY_SIZE(irqs); i++)
96 gpio_free(irq_to_gpio(irqs[i].irq));
99 static unsigned long trizeps_pcmcia_status[2];
101 static void trizeps_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
102 struct pcmcia_state *state)
104 unsigned short status = 0, change;
105 status = CFSR_readw();
106 change = (status ^ trizeps_pcmcia_status[skt->nr]) &
107 ConXS_CFSR_BVD_MASK;
108 if (change) {
109 trizeps_pcmcia_status[skt->nr] = status;
110 if (status & ConXS_CFSR_BVD1) {
111 /* enable_irq empty */
112 } else {
113 /* disable_irq empty */
117 switch (skt->nr) {
118 case 0:
119 /* just fill in fix states */
120 state->detect = gpio_get_value(GPIO_PCD) ? 0 : 1;
121 state->ready = gpio_get_value(GPIO_PRDY) ? 1 : 0;
122 state->bvd1 = (status & ConXS_CFSR_BVD1) ? 1 : 0;
123 state->bvd2 = (status & ConXS_CFSR_BVD2) ? 1 : 0;
124 state->vs_3v = (status & ConXS_CFSR_VS1) ? 0 : 1;
125 state->vs_Xv = (status & ConXS_CFSR_VS2) ? 0 : 1;
126 state->wrprot = 0; /* not available */
127 break;
129 #ifndef CONFIG_MACH_TRIZEPS_CONXS
130 /* on ConXS we only have one slot. Second is inactive */
131 case 1:
132 state->detect = 0;
133 state->ready = 0;
134 state->bvd1 = 0;
135 state->bvd2 = 0;
136 state->vs_3v = 0;
137 state->vs_Xv = 0;
138 state->wrprot = 0;
139 break;
141 #endif
145 static int trizeps_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
146 const socket_state_t *state)
148 int ret = 0;
149 unsigned short power = 0;
151 /* we do nothing here just check a bit */
152 switch (state->Vcc) {
153 case 0: power &= 0xfc; break;
154 case 33: power |= ConXS_BCR_S0_VCC_3V3; break;
155 case 50:
156 pr_err("%s(): Vcc 5V not supported in socket\n", __func__);
157 break;
158 default:
159 pr_err("%s(): bad Vcc %u\n", __func__, state->Vcc);
160 ret = -1;
163 switch (state->Vpp) {
164 case 0: power &= 0xf3; break;
165 case 33: power |= ConXS_BCR_S0_VPP_3V3; break;
166 case 120:
167 pr_err("%s(): Vpp 12V not supported in socket\n", __func__);
168 break;
169 default:
170 if (state->Vpp != state->Vcc) {
171 pr_err("%s(): bad Vpp %u\n", __func__, state->Vpp);
172 ret = -1;
176 switch (skt->nr) {
177 case 0: /* we only have 3.3V */
178 board_pcmcia_power(power);
179 break;
181 #ifndef CONFIG_MACH_TRIZEPS_CONXS
182 /* on ConXS we only have one slot. Second is inactive */
183 case 1:
184 #endif
185 default:
186 break;
189 return ret;
192 static void trizeps_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
194 /* default is on */
195 board_pcmcia_power(0x9);
198 static void trizeps_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
200 board_pcmcia_power(0x0);
203 static struct pcmcia_low_level trizeps_pcmcia_ops = {
204 .owner = THIS_MODULE,
205 .hw_init = trizeps_pcmcia_hw_init,
206 .hw_shutdown = trizeps_pcmcia_hw_shutdown,
207 .socket_state = trizeps_pcmcia_socket_state,
208 .configure_socket = trizeps_pcmcia_configure_socket,
209 .socket_init = trizeps_pcmcia_socket_init,
210 .socket_suspend = trizeps_pcmcia_socket_suspend,
211 #ifdef CONFIG_MACH_TRIZEPS_CONXS
212 .nr = 1,
213 #else
214 .nr = 2,
215 #endif
216 .first = 0,
219 static struct platform_device *trizeps_pcmcia_device;
221 static int __init trizeps_pcmcia_init(void)
223 int ret;
225 if (!machine_is_trizeps4() && !machine_is_trizeps4wl())
226 return -ENODEV;
228 trizeps_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
229 if (!trizeps_pcmcia_device)
230 return -ENOMEM;
232 ret = platform_device_add_data(trizeps_pcmcia_device,
233 &trizeps_pcmcia_ops, sizeof(trizeps_pcmcia_ops));
235 if (ret == 0)
236 ret = platform_device_add(trizeps_pcmcia_device);
238 if (ret)
239 platform_device_put(trizeps_pcmcia_device);
241 return ret;
244 static void __exit trizeps_pcmcia_exit(void)
246 platform_device_unregister(trizeps_pcmcia_device);
249 fs_initcall(trizeps_pcmcia_init);
250 module_exit(trizeps_pcmcia_exit);
252 MODULE_LICENSE("GPL");
253 MODULE_AUTHOR("Juergen Schindele");
254 MODULE_ALIAS("platform:pxa2xx-pcmcia");