sfc: Don't use enums as a bitmask.
[zen-stable.git] / drivers / pcmcia / pxa2xx_vpac270.c
blob435002dfc3caef7a418944e9e967af8a27c6b822
1 /*
2 * linux/drivers/pcmcia/pxa2xx_vpac270.c
4 * Driver for Voipac PXA270 PCMCIA and CF sockets
6 * Copyright (C) 2010-2011 Marek Vasut <marek.vasut@gmail.com>
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.
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
17 #include <asm/mach-types.h>
19 #include <mach/gpio.h>
20 #include <mach/vpac270.h>
22 #include "soc_common.h"
24 static 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" },
31 static 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" },
37 static struct pcmcia_irqs cd_irqs[] = {
39 .sock = 0,
40 .irq = IRQ_GPIO(GPIO84_VPAC270_PCMCIA_CD),
41 .str = "PCMCIA CD"
44 .sock = 1,
45 .irq = IRQ_GPIO(GPIO17_VPAC270_CF_CD),
46 .str = "CF CD"
50 static int vpac270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
52 int ret;
54 if (skt->nr == 0) {
55 ret = gpio_request_array(vpac270_pcmcia_gpios,
56 ARRAY_SIZE(vpac270_pcmcia_gpios));
58 skt->socket.pci_irq = gpio_to_irq(GPIO35_VPAC270_PCMCIA_RDY);
60 if (!ret)
61 ret = soc_pcmcia_request_irqs(skt, &cd_irqs[0], 1);
62 } else {
63 ret = gpio_request_array(vpac270_cf_gpios,
64 ARRAY_SIZE(vpac270_cf_gpios));
66 skt->socket.pci_irq = gpio_to_irq(GPIO12_VPAC270_CF_RDY);
68 if (!ret)
69 ret = soc_pcmcia_request_irqs(skt, &cd_irqs[1], 1);
72 return ret;
75 static void vpac270_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
77 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));
85 static void vpac270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
86 struct pcmcia_state *state)
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);
95 state->bvd1 = 1;
96 state->bvd2 = 1;
97 state->wrprot = 0;
98 state->vs_3v = 1;
99 state->vs_Xv = 0;
102 static int
103 vpac270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
104 const socket_state_t *state)
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));
116 return 0;
119 static void vpac270_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
123 static void vpac270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
127 static struct pcmcia_low_level vpac270_pcmcia_ops = {
128 .owner = THIS_MODULE,
130 .first = 0,
131 .nr = 2,
133 .hw_init = vpac270_pcmcia_hw_init,
134 .hw_shutdown = vpac270_pcmcia_hw_shutdown,
136 .socket_state = vpac270_pcmcia_socket_state,
137 .configure_socket = vpac270_pcmcia_configure_socket,
139 .socket_init = vpac270_pcmcia_socket_init,
140 .socket_suspend = vpac270_pcmcia_socket_suspend,
143 static struct platform_device *vpac270_pcmcia_device;
145 static int __init vpac270_pcmcia_init(void)
147 int ret;
149 if (!machine_is_vpac270())
150 return -ENODEV;
152 vpac270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
153 if (!vpac270_pcmcia_device)
154 return -ENOMEM;
156 ret = platform_device_add_data(vpac270_pcmcia_device,
157 &vpac270_pcmcia_ops, sizeof(vpac270_pcmcia_ops));
159 if (!ret)
160 ret = platform_device_add(vpac270_pcmcia_device);
162 if (ret)
163 platform_device_put(vpac270_pcmcia_device);
165 return ret;
168 static void __exit vpac270_pcmcia_exit(void)
170 platform_device_unregister(vpac270_pcmcia_device);
173 module_init(vpac270_pcmcia_init);
174 module_exit(vpac270_pcmcia_exit);
176 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
177 MODULE_DESCRIPTION("PCMCIA support for Voipac PXA270");
178 MODULE_ALIAS("platform:pxa2xx-pcmcia");
179 MODULE_LICENSE("GPL");