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/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
)
43 skt
->irq
= gpio_to_irq(VIPER_CF_RDY_GPIO
);
45 if (gpio_request(VIPER_CF_CD_GPIO
, "CF detect"))
48 if (gpio_request(VIPER_CF_RDY_GPIO
, "CF ready"))
51 if (gpio_request(VIPER_CF_POWER_GPIO
, "CF power"))
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
);
64 local_irq_restore(flags
);
66 return soc_pcmcia_request_irqs(skt
, irqs
, ARRAY_SIZE(irqs
));
69 gpio_free(VIPER_CF_POWER_GPIO
);
71 gpio_free(VIPER_CF_RDY_GPIO
);
73 gpio_free(VIPER_CF_CD_GPIO
);
75 printk(KERN_ERR
"viper: Failed to setup PCMCIA GPIOs\n");
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;
98 state
->vs_3v
= 1; /* Can only apply 3.3V */
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
) {
111 gpio_set_value(VIPER_CF_POWER_GPIO
, 0);
114 gpio_set_value(VIPER_CF_POWER_GPIO
, 1);
117 printk(KERN_ERR
"%s: Unsupported Vcc:%d\n",
118 __func__
, state
->Vcc
);
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
,
144 static struct platform_device
*viper_pcmcia_device
;
146 static int __init
viper_pcmcia_init(void)
150 if (!machine_is_viper())
153 viper_pcmcia_device
= platform_device_alloc("pxa2xx-pcmcia", -1);
154 if (!viper_pcmcia_device
)
157 ret
= platform_device_add_data(viper_pcmcia_device
,
159 sizeof(viper_pcmcia_ops
));
162 ret
= platform_device_add(viper_pcmcia_device
);
165 platform_device_put(viper_pcmcia_device
);
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");