2 * Viper/Zeus PCMCIA support
3 * Copyright 2004 Arcom Control Systems
5 * Maintained by Marc Zyngier <maz@misterjones.org>
8 * iPAQ h2200 PCMCIA support
9 * Copyright 2004 Koen Kooi <koen@vestingbar.nl>
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file COPYING in the main directory of this archive for
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/interrupt.h>
21 #include <linux/platform_device.h>
22 #include <linux/gpio.h>
24 #include <pcmcia/ss.h>
28 #include <mach/arcom-pcmcia.h>
30 #include "soc_common.h"
31 #include "pxa2xx_base.h"
33 static struct platform_device
*arcom_pcmcia_dev
;
35 static struct pcmcia_irqs irqs
[] = {
42 static inline struct arcom_pcmcia_pdata
*viper_get_pdata(void)
44 return arcom_pcmcia_dev
->dev
.platform_data
;
47 static int viper_pcmcia_hw_init(struct soc_pcmcia_socket
*skt
)
49 struct arcom_pcmcia_pdata
*pdata
= viper_get_pdata();
52 skt
->socket
.pci_irq
= gpio_to_irq(pdata
->rdy_gpio
);
53 irqs
[0].irq
= gpio_to_irq(pdata
->cd_gpio
);
55 if (gpio_request(pdata
->cd_gpio
, "CF detect"))
58 if (gpio_request(pdata
->rdy_gpio
, "CF ready"))
61 if (gpio_request(pdata
->pwr_gpio
, "CF power"))
64 local_irq_save(flags
);
66 if (gpio_direction_output(pdata
->pwr_gpio
, 0) ||
67 gpio_direction_input(pdata
->cd_gpio
) ||
68 gpio_direction_input(pdata
->rdy_gpio
)) {
69 local_irq_restore(flags
);
73 local_irq_restore(flags
);
75 return soc_pcmcia_request_irqs(skt
, irqs
, ARRAY_SIZE(irqs
));
78 gpio_free(pdata
->pwr_gpio
);
80 gpio_free(pdata
->rdy_gpio
);
82 gpio_free(pdata
->cd_gpio
);
84 dev_err(&arcom_pcmcia_dev
->dev
, "Failed to setup PCMCIA GPIOs\n");
89 * Release all resources.
91 static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket
*skt
)
93 struct arcom_pcmcia_pdata
*pdata
= viper_get_pdata();
95 soc_pcmcia_free_irqs(skt
, irqs
, ARRAY_SIZE(irqs
));
96 gpio_free(pdata
->pwr_gpio
);
97 gpio_free(pdata
->rdy_gpio
);
98 gpio_free(pdata
->cd_gpio
);
101 static void viper_pcmcia_socket_state(struct soc_pcmcia_socket
*skt
,
102 struct pcmcia_state
*state
)
104 struct arcom_pcmcia_pdata
*pdata
= viper_get_pdata();
106 state
->detect
= !gpio_get_value(pdata
->cd_gpio
);
107 state
->ready
= !!gpio_get_value(pdata
->rdy_gpio
);
111 state
->vs_3v
= 1; /* Can only apply 3.3V */
115 static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket
*skt
,
116 const socket_state_t
*state
)
118 struct arcom_pcmcia_pdata
*pdata
= viper_get_pdata();
120 /* Silently ignore Vpp, output enable, speaker enable. */
121 pdata
->reset(state
->flags
& SS_RESET
);
123 /* Apply socket voltage */
124 switch (state
->Vcc
) {
126 gpio_set_value(pdata
->pwr_gpio
, 0);
129 gpio_set_value(pdata
->pwr_gpio
, 1);
132 dev_err(&arcom_pcmcia_dev
->dev
, "Unsupported Vcc:%d\n", state
->Vcc
);
139 static void viper_pcmcia_socket_init(struct soc_pcmcia_socket
*skt
)
143 static void viper_pcmcia_socket_suspend(struct soc_pcmcia_socket
*skt
)
147 static struct pcmcia_low_level viper_pcmcia_ops
= {
148 .owner
= THIS_MODULE
,
149 .hw_init
= viper_pcmcia_hw_init
,
150 .hw_shutdown
= viper_pcmcia_hw_shutdown
,
151 .socket_state
= viper_pcmcia_socket_state
,
152 .configure_socket
= viper_pcmcia_configure_socket
,
153 .socket_init
= viper_pcmcia_socket_init
,
154 .socket_suspend
= viper_pcmcia_socket_suspend
,
158 static struct platform_device
*viper_pcmcia_device
;
160 static int viper_pcmcia_probe(struct platform_device
*pdev
)
164 /* I can't imagine more than one device, but you never know... */
165 if (arcom_pcmcia_dev
)
168 if (!pdev
->dev
.platform_data
)
171 viper_pcmcia_device
= platform_device_alloc("pxa2xx-pcmcia", -1);
172 if (!viper_pcmcia_device
)
175 arcom_pcmcia_dev
= pdev
;
177 viper_pcmcia_device
->dev
.parent
= &pdev
->dev
;
179 ret
= platform_device_add_data(viper_pcmcia_device
,
181 sizeof(viper_pcmcia_ops
));
184 ret
= platform_device_add(viper_pcmcia_device
);
187 platform_device_put(viper_pcmcia_device
);
188 arcom_pcmcia_dev
= NULL
;
194 static int viper_pcmcia_remove(struct platform_device
*pdev
)
196 platform_device_unregister(viper_pcmcia_device
);
197 arcom_pcmcia_dev
= NULL
;
201 static struct platform_device_id viper_pcmcia_id_table
[] = {
202 { .name
= "viper-pcmcia", },
203 { .name
= "zeus-pcmcia", },
207 static struct platform_driver viper_pcmcia_driver
= {
208 .probe
= viper_pcmcia_probe
,
209 .remove
= viper_pcmcia_remove
,
211 .name
= "arcom-pcmcia",
212 .owner
= THIS_MODULE
,
214 .id_table
= viper_pcmcia_id_table
,
217 static int __init
viper_pcmcia_init(void)
219 return platform_driver_register(&viper_pcmcia_driver
);
222 static void __exit
viper_pcmcia_exit(void)
224 return platform_driver_unregister(&viper_pcmcia_driver
);
227 module_init(viper_pcmcia_init
);
228 module_exit(viper_pcmcia_exit
);
230 MODULE_DEVICE_TABLE(platform
, viper_pcmcia_id_table
);
231 MODULE_LICENSE("GPL");