blob: a51f2077644a5f80cdb4e9688947e046ce42a0e7 [file] [log] [blame]
Marc Zyngier20f18ff2008-08-19 12:15:53 +02001/*
Marc Zyngierc2de1c382009-11-14 13:39:13 +01002 * Viper/Zeus PCMCIA support
Marc Zyngier20f18ff2008-08-19 12:15:53 +02003 * Copyright 2004 Arcom Control Systems
4 *
5 * Maintained by Marc Zyngier <maz@misterjones.org>
Marc Zyngier20f18ff2008-08-19 12:15:53 +02006 *
7 * Based on:
8 * iPAQ h2200 PCMCIA support
9 * Copyright 2004 Koen Kooi <koen@vestingbar.nl>
10 *
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
13 * more details.
14 */
15
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>
23
24#include <pcmcia/ss.h>
25
26#include <asm/irq.h>
27
Marc Zyngierc2de1c382009-11-14 13:39:13 +010028#include <mach/arcom-pcmcia.h>
Marc Zyngier20f18ff2008-08-19 12:15:53 +020029
30#include "soc_common.h"
31#include "pxa2xx_base.h"
32
Marc Zyngierc2de1c382009-11-14 13:39:13 +010033static struct platform_device *arcom_pcmcia_dev;
34
Marc Zyngier20f18ff2008-08-19 12:15:53 +020035static struct pcmcia_irqs irqs[] = {
Marc Zyngierc2de1c382009-11-14 13:39:13 +010036 {
37 .sock = 0,
38 .str = "PCMCIA_CD",
39 },
Marc Zyngier20f18ff2008-08-19 12:15:53 +020040};
41
Marc Zyngierc2de1c382009-11-14 13:39:13 +010042static inline struct arcom_pcmcia_pdata *viper_get_pdata(void)
43{
44 return arcom_pcmcia_dev->dev.platform_data;
45}
46
Marc Zyngier20f18ff2008-08-19 12:15:53 +020047static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
48{
Marc Zyngierc2de1c382009-11-14 13:39:13 +010049 struct arcom_pcmcia_pdata *pdata = viper_get_pdata();
Marc Zyngier20f18ff2008-08-19 12:15:53 +020050 unsigned long flags;
51
Marc Zyngierc2de1c382009-11-14 13:39:13 +010052 skt->socket.pci_irq = gpio_to_irq(pdata->rdy_gpio);
53 irqs[0].irq = gpio_to_irq(pdata->cd_gpio);
Marc Zyngier20f18ff2008-08-19 12:15:53 +020054
Marc Zyngierc2de1c382009-11-14 13:39:13 +010055 if (gpio_request(pdata->cd_gpio, "CF detect"))
Marc Zyngier20f18ff2008-08-19 12:15:53 +020056 goto err_request_cd;
57
Marc Zyngierc2de1c382009-11-14 13:39:13 +010058 if (gpio_request(pdata->rdy_gpio, "CF ready"))
Marc Zyngier20f18ff2008-08-19 12:15:53 +020059 goto err_request_rdy;
60
Marc Zyngierc2de1c382009-11-14 13:39:13 +010061 if (gpio_request(pdata->pwr_gpio, "CF power"))
Marc Zyngier20f18ff2008-08-19 12:15:53 +020062 goto err_request_pwr;
63
64 local_irq_save(flags);
65
Marc Zyngierc2de1c382009-11-14 13:39:13 +010066 if (gpio_direction_output(pdata->pwr_gpio, 0) ||
67 gpio_direction_input(pdata->cd_gpio) ||
68 gpio_direction_input(pdata->rdy_gpio)) {
Marc Zyngier20f18ff2008-08-19 12:15:53 +020069 local_irq_restore(flags);
70 goto err_dir;
71 }
72
73 local_irq_restore(flags);
74
75 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
76
77err_dir:
Marc Zyngierc2de1c382009-11-14 13:39:13 +010078 gpio_free(pdata->pwr_gpio);
Marc Zyngier20f18ff2008-08-19 12:15:53 +020079err_request_pwr:
Marc Zyngierc2de1c382009-11-14 13:39:13 +010080 gpio_free(pdata->rdy_gpio);
Marc Zyngier20f18ff2008-08-19 12:15:53 +020081err_request_rdy:
Marc Zyngierc2de1c382009-11-14 13:39:13 +010082 gpio_free(pdata->cd_gpio);
Marc Zyngier20f18ff2008-08-19 12:15:53 +020083err_request_cd:
Marc Zyngierc2de1c382009-11-14 13:39:13 +010084 dev_err(&arcom_pcmcia_dev->dev, "Failed to setup PCMCIA GPIOs\n");
Marc Zyngier20f18ff2008-08-19 12:15:53 +020085 return -1;
86}
87
88/*
89 * Release all resources.
90 */
91static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
92{
Marc Zyngierc2de1c382009-11-14 13:39:13 +010093 struct arcom_pcmcia_pdata *pdata = viper_get_pdata();
94
Marc Zyngier20f18ff2008-08-19 12:15:53 +020095 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
Marc Zyngierc2de1c382009-11-14 13:39:13 +010096 gpio_free(pdata->pwr_gpio);
97 gpio_free(pdata->rdy_gpio);
98 gpio_free(pdata->cd_gpio);
Marc Zyngier20f18ff2008-08-19 12:15:53 +020099}
100
101static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
102 struct pcmcia_state *state)
103{
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100104 struct arcom_pcmcia_pdata *pdata = viper_get_pdata();
105
106 state->detect = !gpio_get_value(pdata->cd_gpio);
107 state->ready = !!gpio_get_value(pdata->rdy_gpio);
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200108 state->bvd1 = 1;
109 state->bvd2 = 1;
110 state->wrprot = 0;
111 state->vs_3v = 1; /* Can only apply 3.3V */
112 state->vs_Xv = 0;
113}
114
115static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
116 const socket_state_t *state)
117{
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100118 struct arcom_pcmcia_pdata *pdata = viper_get_pdata();
119
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200120 /* Silently ignore Vpp, output enable, speaker enable. */
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100121 pdata->reset(state->flags & SS_RESET);
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200122
123 /* Apply socket voltage */
124 switch (state->Vcc) {
125 case 0:
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100126 gpio_set_value(pdata->pwr_gpio, 0);
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200127 break;
128 case 33:
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100129 gpio_set_value(pdata->pwr_gpio, 1);
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200130 break;
131 default:
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100132 dev_err(&arcom_pcmcia_dev->dev, "Unsupported Vcc:%d\n", state->Vcc);
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200133 return -1;
134 }
135
136 return 0;
137}
138
139static void viper_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
140{
141}
142
143static void viper_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
144{
145}
146
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100147static struct pcmcia_low_level viper_pcmcia_ops = {
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200148 .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,
155 .nr = 1,
156};
157
158static struct platform_device *viper_pcmcia_device;
159
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100160static int viper_pcmcia_probe(struct platform_device *pdev)
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200161{
162 int ret;
163
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100164 /* I can't imagine more than one device, but you never know... */
165 if (arcom_pcmcia_dev)
166 return -EEXIST;
167
168 if (!pdev->dev.platform_data)
169 return -EINVAL;
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200170
171 viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
172 if (!viper_pcmcia_device)
173 return -ENOMEM;
174
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100175 arcom_pcmcia_dev = pdev;
176
177 viper_pcmcia_device->dev.parent = &pdev->dev;
178
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200179 ret = platform_device_add_data(viper_pcmcia_device,
180 &viper_pcmcia_ops,
181 sizeof(viper_pcmcia_ops));
182
183 if (!ret)
184 ret = platform_device_add(viper_pcmcia_device);
185
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100186 if (ret) {
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200187 platform_device_put(viper_pcmcia_device);
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100188 arcom_pcmcia_dev = NULL;
189 }
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200190
191 return ret;
192}
193
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100194static int viper_pcmcia_remove(struct platform_device *pdev)
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200195{
196 platform_device_unregister(viper_pcmcia_device);
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100197 arcom_pcmcia_dev = NULL;
198 return 0;
199}
200
201static struct platform_device_id viper_pcmcia_id_table[] = {
202 { .name = "viper-pcmcia", },
203 { .name = "zeus-pcmcia", },
204 { },
205};
206
207static struct platform_driver viper_pcmcia_driver = {
208 .probe = viper_pcmcia_probe,
209 .remove = viper_pcmcia_remove,
210 .driver = {
211 .name = "arcom-pcmcia",
212 .owner = THIS_MODULE,
213 },
214 .id_table = viper_pcmcia_id_table,
215};
216
217static int __init viper_pcmcia_init(void)
218{
219 return platform_driver_register(&viper_pcmcia_driver);
220}
221
222static void __exit viper_pcmcia_exit(void)
223{
224 return platform_driver_unregister(&viper_pcmcia_driver);
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200225}
226
227module_init(viper_pcmcia_init);
228module_exit(viper_pcmcia_exit);
229
Marc Zyngierc2de1c382009-11-14 13:39:13 +0100230MODULE_DEVICE_TABLE(platform, viper_pcmcia_id_table);
Marc Zyngier20f18ff2008-08-19 12:15:53 +0200231MODULE_LICENSE("GPL");