2 * linux/drivers/pcmcia/pxa2xx_trizeps4.c
4 * TRIZEPS PCMCIA specific routines.
6 * Author: Jürgen Schindele
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>
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)
40 /* we dont have voltage/card/ready detection
41 * so we dont need interrupts for it
45 if (gpio_request(GPIO_PRDY, "cf_irq") < 0) {
46 pr_err("%s: sock %d unable to request gpio %d\n", __func__,
50 if (gpio_direction_input(GPIO_PRDY) < 0) {
51 pr_err("%s: sock %d unable to set input gpio %d\n", __func__,
56 skt->irq = IRQ_GPIO(GPIO_PRDY);
59 #ifndef CONFIG_MACH_TRIZEPS_CONXS
65 /* release the reset of this card */
66 pr_debug("%s: sock %d irq %d\n", __func__, skt->nr, skt->irq);
68 /* supplementory irqs for the socket */
69 for (i = 0; i < ARRAY_SIZE(irqs); i++) {
70 if (irqs[i].sock != skt->nr)
72 if (gpio_request(IRQ_TO_GPIO(irqs[i].irq), irqs[i].str) < 0) {
73 pr_err("%s: sock %d unable to request gpio %d\n",
74 __func__, skt->nr, IRQ_TO_GPIO(irqs[i].irq));
78 if (gpio_direction_input(IRQ_TO_GPIO(irqs[i].irq)) < 0) {
79 pr_err("%s: sock %d unable to set input gpio %d\n",
80 __func__, skt->nr, IRQ_TO_GPIO(irqs[i].irq));
85 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
89 gpio_free(IRQ_TO_GPIO(irqs[i].irq));
94 static void trizeps_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
97 /* free allocated gpio's */
99 for (i = 0; i < ARRAY_SIZE(irqs); i++)
100 gpio_free(IRQ_TO_GPIO(irqs[i].irq));
103 static unsigned long trizeps_pcmcia_status[2];
105 static void trizeps_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
106 struct pcmcia_state *state)
108 unsigned short status = 0, change;
109 status = CFSR_readw();
110 change = (status ^ trizeps_pcmcia_status[skt->nr]) &
113 trizeps_pcmcia_status[skt->nr] = status;
114 if (status & ConXS_CFSR_BVD1) {
115 /* enable_irq empty */
117 /* disable_irq empty */
123 /* just fill in fix states */
124 state->detect = gpio_get_value(GPIO_PCD) ? 0 : 1;
125 state->ready = gpio_get_value(GPIO_PRDY) ? 1 : 0;
126 state->bvd1 = (status & ConXS_CFSR_BVD1) ? 1 : 0;
127 state->bvd2 = (status & ConXS_CFSR_BVD2) ? 1 : 0;
128 state->vs_3v = (status & ConXS_CFSR_VS1) ? 0 : 1;
129 state->vs_Xv = (status & ConXS_CFSR_VS2) ? 0 : 1;
130 state->wrprot = 0; /* not available */
133 #ifndef CONFIG_MACH_TRIZEPS_CONXS
134 /* on ConXS we only have one slot. Second is inactive */
149 static int trizeps_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
150 const socket_state_t *state)
153 unsigned short power = 0;
155 /* we do nothing here just check a bit */
156 switch (state->Vcc) {
157 case 0: power &= 0xfc; break;
158 case 33: power |= ConXS_BCR_S0_VCC_3V3; break;
160 pr_err("%s(): Vcc 5V not supported in socket\n", __func__);
163 pr_err("%s(): bad Vcc %u\n", __func__, state->Vcc);
167 switch (state->Vpp) {
168 case 0: power &= 0xf3; break;
169 case 33: power |= ConXS_BCR_S0_VPP_3V3; break;
171 pr_err("%s(): Vpp 12V not supported in socket\n", __func__);
174 if (state->Vpp != state->Vcc) {
175 pr_err("%s(): bad Vpp %u\n", __func__, state->Vpp);
181 case 0: /* we only have 3.3V */
182 board_pcmcia_power(power);
185 #ifndef CONFIG_MACH_TRIZEPS_CONXS
186 /* on ConXS we only have one slot. Second is inactive */
196 static void trizeps_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
199 board_pcmcia_power(0x9);
202 static void trizeps_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
204 board_pcmcia_power(0x0);
207 static struct pcmcia_low_level trizeps_pcmcia_ops = {
208 .owner = THIS_MODULE,
209 .hw_init = trizeps_pcmcia_hw_init,
210 .hw_shutdown = trizeps_pcmcia_hw_shutdown,
211 .socket_state = trizeps_pcmcia_socket_state,
212 .configure_socket = trizeps_pcmcia_configure_socket,
213 .socket_init = trizeps_pcmcia_socket_init,
214 .socket_suspend = trizeps_pcmcia_socket_suspend,
215 #ifdef CONFIG_MACH_TRIZEPS_CONXS
223 static struct platform_device *trizeps_pcmcia_device;
225 static int __init trizeps_pcmcia_init(void)
229 trizeps_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
230 if (!trizeps_pcmcia_device)
233 ret = platform_device_add_data(trizeps_pcmcia_device,
234 &trizeps_pcmcia_ops, sizeof(trizeps_pcmcia_ops));
237 ret = platform_device_add(trizeps_pcmcia_device);
240 platform_device_put(trizeps_pcmcia_device);
245 static void __exit trizeps_pcmcia_exit(void)
247 platform_device_unregister(trizeps_pcmcia_device);
250 fs_initcall(trizeps_pcmcia_init);
251 module_exit(trizeps_pcmcia_exit);
253 MODULE_LICENSE("GPL");
254 MODULE_AUTHOR("Juergen Schindele");
255 MODULE_ALIAS("platform:pxa2xx-pcmcia");