blob: 435002dfc3caef7a418944e9e967af8a27c6b822 [file] [log] [blame]
Marek Vasutaddff0f2010-03-10 04:16:28 +01001/*
2 * linux/drivers/pcmcia/pxa2xx_vpac270.c
3 *
4 * Driver for Voipac PXA270 PCMCIA and CF sockets
5 *
Marek Vasut9ed3fbf2011-01-15 19:22:19 +01006 * Copyright (C) 2010-2011 Marek Vasut <marek.vasut@gmail.com>
Marek Vasutaddff0f2010-03-10 04:16:28 +01007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/platform_device.h>
16
17#include <asm/mach-types.h>
18
19#include <mach/gpio.h>
20#include <mach/vpac270.h>
21
22#include "soc_common.h"
23
Marek Vasute27af7e2011-01-15 19:11:16 +010024static struct gpio vpac270_pcmcia_gpios[] = {
25 { GPIO84_VPAC270_PCMCIA_CD, GPIOF_IN, "PCMCIA Card Detect" },
26 { GPIO35_VPAC270_PCMCIA_RDY, GPIOF_IN, "PCMCIA Ready" },
27 { GPIO107_VPAC270_PCMCIA_PPEN, GPIOF_INIT_LOW, "PCMCIA PPEN" },
28 { GPIO11_VPAC270_PCMCIA_RESET, GPIOF_INIT_LOW, "PCMCIA Reset" },
29};
30
31static struct gpio vpac270_cf_gpios[] = {
32 { GPIO17_VPAC270_CF_CD, GPIOF_IN, "CF Card Detect" },
33 { GPIO12_VPAC270_CF_RDY, GPIOF_IN, "CF Ready" },
34 { GPIO16_VPAC270_CF_RESET, GPIOF_INIT_LOW, "CF Reset" },
35};
36
Marek Vasutaddff0f2010-03-10 04:16:28 +010037static struct pcmcia_irqs cd_irqs[] = {
38 {
39 .sock = 0,
40 .irq = IRQ_GPIO(GPIO84_VPAC270_PCMCIA_CD),
41 .str = "PCMCIA CD"
42 },
43 {
44 .sock = 1,
45 .irq = IRQ_GPIO(GPIO17_VPAC270_CF_CD),
46 .str = "CF CD"
47 },
48};
49
50static int vpac270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
51{
52 int ret;
53
54 if (skt->nr == 0) {
Marek Vasute27af7e2011-01-15 19:11:16 +010055 ret = gpio_request_array(vpac270_pcmcia_gpios,
56 ARRAY_SIZE(vpac270_pcmcia_gpios));
Marek Vasutaddff0f2010-03-10 04:16:28 +010057
58 skt->socket.pci_irq = gpio_to_irq(GPIO35_VPAC270_PCMCIA_RDY);
59
Marek Vasute27af7e2011-01-15 19:11:16 +010060 if (!ret)
61 ret = soc_pcmcia_request_irqs(skt, &cd_irqs[0], 1);
Marek Vasutaddff0f2010-03-10 04:16:28 +010062 } else {
Marek Vasute27af7e2011-01-15 19:11:16 +010063 ret = gpio_request_array(vpac270_cf_gpios,
64 ARRAY_SIZE(vpac270_cf_gpios));
Marek Vasutaddff0f2010-03-10 04:16:28 +010065
66 skt->socket.pci_irq = gpio_to_irq(GPIO12_VPAC270_CF_RDY);
67
Marek Vasute27af7e2011-01-15 19:11:16 +010068 if (!ret)
69 ret = soc_pcmcia_request_irqs(skt, &cd_irqs[1], 1);
Marek Vasutaddff0f2010-03-10 04:16:28 +010070 }
Marek Vasute27af7e2011-01-15 19:11:16 +010071
72 return ret;
Marek Vasutaddff0f2010-03-10 04:16:28 +010073}
74
75static void vpac270_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
76{
Marek Vasute27af7e2011-01-15 19:11:16 +010077 if (skt->nr == 0)
78 gpio_request_array(vpac270_pcmcia_gpios,
79 ARRAY_SIZE(vpac270_pcmcia_gpios));
80 else
81 gpio_request_array(vpac270_cf_gpios,
82 ARRAY_SIZE(vpac270_cf_gpios));
Marek Vasutaddff0f2010-03-10 04:16:28 +010083}
84
85static void vpac270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
86 struct pcmcia_state *state)
87{
88 if (skt->nr == 0) {
89 state->detect = !gpio_get_value(GPIO84_VPAC270_PCMCIA_CD);
90 state->ready = !!gpio_get_value(GPIO35_VPAC270_PCMCIA_RDY);
91 } else {
92 state->detect = !gpio_get_value(GPIO17_VPAC270_CF_CD);
93 state->ready = !!gpio_get_value(GPIO12_VPAC270_CF_RDY);
94 }
95 state->bvd1 = 1;
96 state->bvd2 = 1;
97 state->wrprot = 0;
98 state->vs_3v = 1;
99 state->vs_Xv = 0;
100}
101
102static int
103vpac270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
104 const socket_state_t *state)
105{
106 if (skt->nr == 0) {
107 gpio_set_value(GPIO11_VPAC270_PCMCIA_RESET,
108 (state->flags & SS_RESET));
109 gpio_set_value(GPIO107_VPAC270_PCMCIA_PPEN,
110 !(state->Vcc == 33 || state->Vcc == 50));
111 } else {
112 gpio_set_value(GPIO16_VPAC270_CF_RESET,
113 (state->flags & SS_RESET));
114 }
115
116 return 0;
117}
118
119static void vpac270_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
120{
121}
122
123static void vpac270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
124{
125}
126
127static struct pcmcia_low_level vpac270_pcmcia_ops = {
128 .owner = THIS_MODULE,
129
130 .first = 0,
131 .nr = 2,
132
133 .hw_init = vpac270_pcmcia_hw_init,
134 .hw_shutdown = vpac270_pcmcia_hw_shutdown,
135
136 .socket_state = vpac270_pcmcia_socket_state,
137 .configure_socket = vpac270_pcmcia_configure_socket,
138
139 .socket_init = vpac270_pcmcia_socket_init,
140 .socket_suspend = vpac270_pcmcia_socket_suspend,
141};
142
143static struct platform_device *vpac270_pcmcia_device;
144
145static int __init vpac270_pcmcia_init(void)
146{
147 int ret;
148
149 if (!machine_is_vpac270())
150 return -ENODEV;
151
152 vpac270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
153 if (!vpac270_pcmcia_device)
154 return -ENOMEM;
155
156 ret = platform_device_add_data(vpac270_pcmcia_device,
157 &vpac270_pcmcia_ops, sizeof(vpac270_pcmcia_ops));
158
159 if (!ret)
160 ret = platform_device_add(vpac270_pcmcia_device);
161
162 if (ret)
163 platform_device_put(vpac270_pcmcia_device);
164
165 return ret;
166}
167
168static void __exit vpac270_pcmcia_exit(void)
169{
170 platform_device_unregister(vpac270_pcmcia_device);
171}
172
173module_init(vpac270_pcmcia_init);
174module_exit(vpac270_pcmcia_exit);
175
176MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
177MODULE_DESCRIPTION("PCMCIA support for Voipac PXA270");
178MODULE_ALIAS("platform:pxa2xx-pcmcia");
179MODULE_LICENSE("GPL");