]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/pcmcia/pxa2xx_viper.c
PCMCIA: pxa: convert PXA socket drivers to use new irq/gpio management
[mirror_ubuntu-bionic-kernel.git] / drivers / pcmcia / pxa2xx_viper.c
CommitLineData
20f18ff3 1/*
c2de1c38 2 * Viper/Zeus PCMCIA support
20f18ff3
MZ
3 * Copyright 2004 Arcom Control Systems
4 *
5 * Maintained by Marc Zyngier <maz@misterjones.org>
20f18ff3
MZ
6 *
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
c2de1c38 28#include <mach/arcom-pcmcia.h>
20f18ff3
MZ
29
30#include "soc_common.h"
31#include "pxa2xx_base.h"
32
c2de1c38
MZ
33static struct platform_device *arcom_pcmcia_dev;
34
c2de1c38
MZ
35static inline struct arcom_pcmcia_pdata *viper_get_pdata(void)
36{
37 return arcom_pcmcia_dev->dev.platform_data;
38}
39
20f18ff3
MZ
40static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
41{
c2de1c38 42 struct arcom_pcmcia_pdata *pdata = viper_get_pdata();
20f18ff3
MZ
43 unsigned long flags;
44
a9bb5a4b
RK
45 skt->stat[SOC_STAT_CD].gpio = pdata->cd_gpio;
46 skt->stat[SOC_STAT_CD].name = "PCMCIA_CD";
47 skt->stat[SOC_STAT_RDY].gpio = pdata->rdy_gpio;
48 skt->stat[SOC_STAT_RDY].name = "CF ready";
20f18ff3 49
c2de1c38 50 if (gpio_request(pdata->pwr_gpio, "CF power"))
20f18ff3
MZ
51 goto err_request_pwr;
52
53 local_irq_save(flags);
54
a9bb5a4b 55 if (gpio_direction_output(pdata->pwr_gpio, 0)) {
20f18ff3
MZ
56 local_irq_restore(flags);
57 goto err_dir;
58 }
59
60 local_irq_restore(flags);
61
a9bb5a4b 62 return 0;
20f18ff3
MZ
63
64err_dir:
c2de1c38 65 gpio_free(pdata->pwr_gpio);
20f18ff3 66err_request_pwr:
c2de1c38 67 dev_err(&arcom_pcmcia_dev->dev, "Failed to setup PCMCIA GPIOs\n");
20f18ff3
MZ
68 return -1;
69}
70
71/*
72 * Release all resources.
73 */
74static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
75{
c2de1c38
MZ
76 struct arcom_pcmcia_pdata *pdata = viper_get_pdata();
77
c2de1c38 78 gpio_free(pdata->pwr_gpio);
20f18ff3
MZ
79}
80
81static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
82 struct pcmcia_state *state)
83{
20f18ff3
MZ
84 state->wrprot = 0;
85 state->vs_3v = 1; /* Can only apply 3.3V */
86 state->vs_Xv = 0;
87}
88
89static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
90 const socket_state_t *state)
91{
c2de1c38
MZ
92 struct arcom_pcmcia_pdata *pdata = viper_get_pdata();
93
20f18ff3 94 /* Silently ignore Vpp, output enable, speaker enable. */
c2de1c38 95 pdata->reset(state->flags & SS_RESET);
20f18ff3
MZ
96
97 /* Apply socket voltage */
98 switch (state->Vcc) {
99 case 0:
c2de1c38 100 gpio_set_value(pdata->pwr_gpio, 0);
20f18ff3
MZ
101 break;
102 case 33:
c2de1c38 103 gpio_set_value(pdata->pwr_gpio, 1);
20f18ff3
MZ
104 break;
105 default:
c2de1c38 106 dev_err(&arcom_pcmcia_dev->dev, "Unsupported Vcc:%d\n", state->Vcc);
20f18ff3
MZ
107 return -1;
108 }
109
110 return 0;
111}
112
c2de1c38 113static struct pcmcia_low_level viper_pcmcia_ops = {
20f18ff3
MZ
114 .owner = THIS_MODULE,
115 .hw_init = viper_pcmcia_hw_init,
116 .hw_shutdown = viper_pcmcia_hw_shutdown,
117 .socket_state = viper_pcmcia_socket_state,
118 .configure_socket = viper_pcmcia_configure_socket,
20f18ff3
MZ
119 .nr = 1,
120};
121
122static struct platform_device *viper_pcmcia_device;
123
c2de1c38 124static int viper_pcmcia_probe(struct platform_device *pdev)
20f18ff3
MZ
125{
126 int ret;
127
c2de1c38
MZ
128 /* I can't imagine more than one device, but you never know... */
129 if (arcom_pcmcia_dev)
130 return -EEXIST;
131
132 if (!pdev->dev.platform_data)
133 return -EINVAL;
20f18ff3
MZ
134
135 viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
136 if (!viper_pcmcia_device)
137 return -ENOMEM;
138
c2de1c38
MZ
139 arcom_pcmcia_dev = pdev;
140
141 viper_pcmcia_device->dev.parent = &pdev->dev;
142
20f18ff3
MZ
143 ret = platform_device_add_data(viper_pcmcia_device,
144 &viper_pcmcia_ops,
145 sizeof(viper_pcmcia_ops));
146
147 if (!ret)
148 ret = platform_device_add(viper_pcmcia_device);
149
c2de1c38 150 if (ret) {
20f18ff3 151 platform_device_put(viper_pcmcia_device);
c2de1c38
MZ
152 arcom_pcmcia_dev = NULL;
153 }
20f18ff3
MZ
154
155 return ret;
156}
157
c2de1c38 158static int viper_pcmcia_remove(struct platform_device *pdev)
20f18ff3
MZ
159{
160 platform_device_unregister(viper_pcmcia_device);
c2de1c38
MZ
161 arcom_pcmcia_dev = NULL;
162 return 0;
163}
164
165static struct platform_device_id viper_pcmcia_id_table[] = {
166 { .name = "viper-pcmcia", },
167 { .name = "zeus-pcmcia", },
168 { },
169};
170
171static struct platform_driver viper_pcmcia_driver = {
172 .probe = viper_pcmcia_probe,
173 .remove = viper_pcmcia_remove,
174 .driver = {
175 .name = "arcom-pcmcia",
176 .owner = THIS_MODULE,
177 },
178 .id_table = viper_pcmcia_id_table,
179};
180
181static int __init viper_pcmcia_init(void)
182{
183 return platform_driver_register(&viper_pcmcia_driver);
184}
185
186static void __exit viper_pcmcia_exit(void)
187{
188 return platform_driver_unregister(&viper_pcmcia_driver);
20f18ff3
MZ
189}
190
191module_init(viper_pcmcia_init);
192module_exit(viper_pcmcia_exit);
193
c2de1c38 194MODULE_DEVICE_TABLE(platform, viper_pcmcia_id_table);
20f18ff3 195MODULE_LICENSE("GPL");