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, 2008
9 * Mike Rapoport <mike@compulab.co.il>
13 #include <linux/platform_device.h>
14 #include <linux/irq.h>
15 #include <linux/delay.h>
16 #include <linux/gpio.h>
18 #include <asm/mach-types.h>
20 #include "soc_common.h"
22 #define GPIO_PCMCIA_S0_CD_VALID (84)
23 #define GPIO_PCMCIA_S0_RDYINT (82)
24 #define GPIO_PCMCIA_RESET (53)
26 #define PCMCIA_S0_CD_VALID IRQ_GPIO(GPIO_PCMCIA_S0_CD_VALID)
27 #define PCMCIA_S0_RDYINT IRQ_GPIO(GPIO_PCMCIA_S0_RDYINT)
30 static struct pcmcia_irqs irqs[] = {
31 { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" },
34 static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
36 int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset");
39 gpio_direction_output(GPIO_PCMCIA_RESET, 0);
41 skt->irq = PCMCIA_S0_RDYINT;
42 ret = soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
44 gpio_free(GPIO_PCMCIA_RESET);
49 static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
51 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
52 gpio_free(GPIO_PCMCIA_RESET);
56 static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
57 struct pcmcia_state *state)
59 state->detect = (gpio_get_value(GPIO_PCMCIA_S0_CD_VALID) == 0) ? 1 : 0;
60 state->ready = (gpio_get_value(GPIO_PCMCIA_S0_RDYINT) == 0) ? 0 : 1;
65 state->wrprot = 0; /* not available */
69 static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
70 const socket_state_t *state)
74 if (state->flags & SS_RESET) {
75 gpio_set_value(GPIO_PCMCIA_RESET, 1);
77 gpio_set_value(GPIO_PCMCIA_RESET, 0);
85 static void cmx270_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
89 static void cmx270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
94 static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = {
96 .hw_init = cmx270_pcmcia_hw_init,
97 .hw_shutdown = cmx270_pcmcia_shutdown,
98 .socket_state = cmx270_pcmcia_socket_state,
99 .configure_socket = cmx270_pcmcia_configure_socket,
100 .socket_init = cmx270_pcmcia_socket_init,
101 .socket_suspend = cmx270_pcmcia_socket_suspend,
105 static struct platform_device *cmx270_pcmcia_device;
107 int __init cmx270_pcmcia_init(void)
111 cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
113 if (!cmx270_pcmcia_device)
116 ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops,
117 sizeof(cmx270_pcmcia_ops));
120 printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
121 ret = platform_device_add(cmx270_pcmcia_device);
125 platform_device_put(cmx270_pcmcia_device);
130 void __exit cmx270_pcmcia_exit(void)
132 platform_device_unregister(cmx270_pcmcia_device);