[ARM] pxa: Gumstix Verdex PCMCIA support
[linux-2.6/verdex.git] / drivers / pcmcia / pxa2xx_viper.c
blob17871360fe99efd1247365b51d345510a82858f3
1 /*
2 * VIPER PCMCIA support
3 * Copyright 2004 Arcom Control Systems
5 * Maintained by Marc Zyngier <maz@misterjones.org>
6 * <marc.zyngier@altran.com>
8 * Based on:
9 * iPAQ h2200 PCMCIA support
10 * Copyright 2004 Koen Kooi <koen@vestingbar.nl>
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file COPYING in the main directory of this archive for
14 * more details.
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/interrupt.h>
22 #include <linux/platform_device.h>
23 #include <linux/gpio.h>
25 #include <pcmcia/ss.h>
27 #include <asm/irq.h>
29 #include <mach/viper.h>
30 #include <asm/mach-types.h>
32 #include "soc_common.h"
33 #include "pxa2xx_base.h"
35 static struct pcmcia_irqs irqs[] = {
36 { 0, gpio_to_irq(VIPER_CF_CD_GPIO), "PCMCIA_CD" }
39 static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
41 unsigned long flags;
43 skt->irq = gpio_to_irq(VIPER_CF_RDY_GPIO);
45 if (gpio_request(VIPER_CF_CD_GPIO, "CF detect"))
46 goto err_request_cd;
48 if (gpio_request(VIPER_CF_RDY_GPIO, "CF ready"))
49 goto err_request_rdy;
51 if (gpio_request(VIPER_CF_POWER_GPIO, "CF power"))
52 goto err_request_pwr;
54 local_irq_save(flags);
56 /* GPIO 82 is the CF power enable line. initially off */
57 if (gpio_direction_output(VIPER_CF_POWER_GPIO, 0) ||
58 gpio_direction_input(VIPER_CF_CD_GPIO) ||
59 gpio_direction_input(VIPER_CF_RDY_GPIO)) {
60 local_irq_restore(flags);
61 goto err_dir;
64 local_irq_restore(flags);
66 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
68 err_dir:
69 gpio_free(VIPER_CF_POWER_GPIO);
70 err_request_pwr:
71 gpio_free(VIPER_CF_RDY_GPIO);
72 err_request_rdy:
73 gpio_free(VIPER_CF_CD_GPIO);
74 err_request_cd:
75 printk(KERN_ERR "viper: Failed to setup PCMCIA GPIOs\n");
76 return -1;
80 * Release all resources.
82 static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
84 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
85 gpio_free(VIPER_CF_POWER_GPIO);
86 gpio_free(VIPER_CF_RDY_GPIO);
87 gpio_free(VIPER_CF_CD_GPIO);
90 static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
91 struct pcmcia_state *state)
93 state->detect = gpio_get_value(VIPER_CF_CD_GPIO) ? 0 : 1;
94 state->ready = gpio_get_value(VIPER_CF_RDY_GPIO) ? 1 : 0;
95 state->bvd1 = 1;
96 state->bvd2 = 1;
97 state->wrprot = 0;
98 state->vs_3v = 1; /* Can only apply 3.3V */
99 state->vs_Xv = 0;
102 static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
103 const socket_state_t *state)
105 /* Silently ignore Vpp, output enable, speaker enable. */
106 viper_cf_rst(state->flags & SS_RESET);
108 /* Apply socket voltage */
109 switch (state->Vcc) {
110 case 0:
111 gpio_set_value(VIPER_CF_POWER_GPIO, 0);
112 break;
113 case 33:
114 gpio_set_value(VIPER_CF_POWER_GPIO, 1);
115 break;
116 default:
117 printk(KERN_ERR "%s: Unsupported Vcc:%d\n",
118 __func__, state->Vcc);
119 return -1;
122 return 0;
125 static void viper_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
129 static void viper_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
133 static struct pcmcia_low_level viper_pcmcia_ops __initdata = {
134 .owner = THIS_MODULE,
135 .hw_init = viper_pcmcia_hw_init,
136 .hw_shutdown = viper_pcmcia_hw_shutdown,
137 .socket_state = viper_pcmcia_socket_state,
138 .configure_socket = viper_pcmcia_configure_socket,
139 .socket_init = viper_pcmcia_socket_init,
140 .socket_suspend = viper_pcmcia_socket_suspend,
141 .nr = 1,
144 static struct platform_device *viper_pcmcia_device;
146 static int __init viper_pcmcia_init(void)
148 int ret;
150 if (!machine_is_viper())
151 return -ENODEV;
153 viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
154 if (!viper_pcmcia_device)
155 return -ENOMEM;
157 ret = platform_device_add_data(viper_pcmcia_device,
158 &viper_pcmcia_ops,
159 sizeof(viper_pcmcia_ops));
161 if (!ret)
162 ret = platform_device_add(viper_pcmcia_device);
164 if (ret)
165 platform_device_put(viper_pcmcia_device);
167 return ret;
170 static void __exit viper_pcmcia_exit(void)
172 platform_device_unregister(viper_pcmcia_device);
175 module_init(viper_pcmcia_init);
176 module_exit(viper_pcmcia_exit);
178 MODULE_LICENSE("GPL");