3 * Copyright 2004 Arcom Control Systems
5 * Maintained by Marc Zyngier <maz@misterjones.org>
6 * <marc.zyngier@altran.com>
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
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>
29 #include <mach/pxa-regs.h>
30 #include <mach/viper.h>
31 #include <asm/mach-types.h>
33 #include "soc_common.h"
34 #include "pxa2xx_base.h"
36 static struct pcmcia_irqs irqs[] = {
37 { 0, gpio_to_irq(VIPER_CF_CD_GPIO), "PCMCIA_CD" }
40 static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
44 skt->irq = gpio_to_irq(VIPER_CF_RDY_GPIO);
46 if (gpio_request(VIPER_CF_CD_GPIO, "CF detect"))
49 if (gpio_request(VIPER_CF_RDY_GPIO, "CF ready"))
52 if (gpio_request(VIPER_CF_POWER_GPIO, "CF power"))
55 local_irq_save(flags);
57 /* GPIO 82 is the CF power enable line. initially off */
58 if (gpio_direction_output(VIPER_CF_POWER_GPIO, 0) ||
59 gpio_direction_input(VIPER_CF_CD_GPIO) ||
60 gpio_direction_input(VIPER_CF_RDY_GPIO)) {
61 local_irq_restore(flags);
65 local_irq_restore(flags);
67 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
70 gpio_free(VIPER_CF_POWER_GPIO);
72 gpio_free(VIPER_CF_RDY_GPIO);
74 gpio_free(VIPER_CF_CD_GPIO);
76 printk(KERN_ERR "viper: Failed to setup PCMCIA GPIOs\n");
81 * Release all resources.
83 static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
85 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
86 gpio_free(VIPER_CF_POWER_GPIO);
87 gpio_free(VIPER_CF_RDY_GPIO);
88 gpio_free(VIPER_CF_CD_GPIO);
91 static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
92 struct pcmcia_state *state)
94 state->detect = gpio_get_value(VIPER_CF_CD_GPIO) ? 0 : 1;
95 state->ready = gpio_get_value(VIPER_CF_RDY_GPIO) ? 1 : 0;
99 state->vs_3v = 1; /* Can only apply 3.3V */
103 static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
104 const socket_state_t *state)
106 /* Silently ignore Vpp, output enable, speaker enable. */
107 viper_cf_rst(state->flags & SS_RESET);
109 /* Apply socket voltage */
110 switch (state->Vcc) {
112 gpio_set_value(VIPER_CF_POWER_GPIO, 0);
115 gpio_set_value(VIPER_CF_POWER_GPIO, 1);
118 printk(KERN_ERR "%s: Unsupported Vcc:%d\n",
119 __func__, state->Vcc);
126 static void viper_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
130 static void viper_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
134 static struct pcmcia_low_level viper_pcmcia_ops __initdata = {
135 .owner = THIS_MODULE,
136 .hw_init = viper_pcmcia_hw_init,
137 .hw_shutdown = viper_pcmcia_hw_shutdown,
138 .socket_state = viper_pcmcia_socket_state,
139 .configure_socket = viper_pcmcia_configure_socket,
140 .socket_init = viper_pcmcia_socket_init,
141 .socket_suspend = viper_pcmcia_socket_suspend,
145 static struct platform_device *viper_pcmcia_device;
147 static int __init viper_pcmcia_init(void)
151 if (!machine_is_viper())
154 viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
155 if (!viper_pcmcia_device)
158 ret = platform_device_add_data(viper_pcmcia_device,
160 sizeof(viper_pcmcia_ops));
163 ret = platform_device_add(viper_pcmcia_device);
166 platform_device_put(viper_pcmcia_device);
171 static void __exit viper_pcmcia_exit(void)
173 platform_device_unregister(viper_pcmcia_device);
176 module_init(viper_pcmcia_init);
177 module_exit(viper_pcmcia_exit);
179 MODULE_LICENSE("GPL");