Merge tag 'iwlwifi-next-for-kalle-2014-12-30' of https://git.kernel.org/pub/scm/linux...
[cascardo/linux.git] / drivers / pcmcia / pxa2xx_colibri.c
1 /*
2  * linux/drivers/pcmcia/pxa2xx_colibri.c
3  *
4  * Driver for Toradex Colibri PXA270 CF socket
5  *
6  * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
7  *
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 #include <linux/delay.h>
17 #include <linux/gpio.h>
18
19 #include <asm/mach-types.h>
20
21 #include "soc_common.h"
22
23 #define COLIBRI270_RESET_GPIO   53
24 #define COLIBRI270_PPEN_GPIO    107
25 #define COLIBRI270_BVD1_GPIO    83
26 #define COLIBRI270_BVD2_GPIO    82
27 #define COLIBRI270_DETECT_GPIO  84
28 #define COLIBRI270_READY_GPIO   1
29
30 #define COLIBRI320_RESET_GPIO   77
31 #define COLIBRI320_PPEN_GPIO    57
32 #define COLIBRI320_BVD1_GPIO    53
33 #define COLIBRI320_BVD2_GPIO    79
34 #define COLIBRI320_DETECT_GPIO  81
35 #define COLIBRI320_READY_GPIO   29
36
37 enum {
38         DETECT = 0,
39         READY = 1,
40         BVD1 = 2,
41         BVD2 = 3,
42         PPEN = 4,
43         RESET = 5,
44 };
45
46 /* Contents of this array are configured on-the-fly in init function */
47 static struct gpio colibri_pcmcia_gpios[] = {
48         { 0,    GPIOF_IN,       "PCMCIA Detect" },
49         { 0,    GPIOF_IN,       "PCMCIA Ready" },
50         { 0,    GPIOF_IN,       "PCMCIA BVD1" },
51         { 0,    GPIOF_IN,       "PCMCIA BVD2" },
52         { 0,    GPIOF_INIT_LOW, "PCMCIA PPEN" },
53         { 0,    GPIOF_INIT_HIGH,"PCMCIA Reset" },
54 };
55
56 static int colibri_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
57 {
58         int ret;
59
60         ret = gpio_request_array(colibri_pcmcia_gpios,
61                                 ARRAY_SIZE(colibri_pcmcia_gpios));
62         if (ret)
63                 goto err1;
64
65         skt->socket.pci_irq = gpio_to_irq(colibri_pcmcia_gpios[READY].gpio);
66         skt->stat[SOC_STAT_CD].irq = gpio_to_irq(colibri_pcmcia_gpios[DETECT].gpio);
67         skt->stat[SOC_STAT_CD].name = "PCMCIA CD";
68
69 err1:
70         return ret;
71 }
72
73 static void colibri_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
74 {
75         gpio_free_array(colibri_pcmcia_gpios,
76                         ARRAY_SIZE(colibri_pcmcia_gpios));
77 }
78
79 static void colibri_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
80                                         struct pcmcia_state *state)
81 {
82
83         state->detect = !!gpio_get_value(colibri_pcmcia_gpios[DETECT].gpio);
84         state->ready  = !!gpio_get_value(colibri_pcmcia_gpios[READY].gpio);
85         state->bvd1   = !!gpio_get_value(colibri_pcmcia_gpios[BVD1].gpio);
86         state->bvd2   = !!gpio_get_value(colibri_pcmcia_gpios[BVD2].gpio);
87         state->vs_3v  = 1;
88         state->vs_Xv  = 0;
89 }
90
91 static int
92 colibri_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
93                                 const socket_state_t *state)
94 {
95         gpio_set_value(colibri_pcmcia_gpios[PPEN].gpio,
96                         !(state->Vcc == 33 && state->Vpp < 50));
97         gpio_set_value(colibri_pcmcia_gpios[RESET].gpio,
98                         state->flags & SS_RESET);
99         return 0;
100 }
101
102 static struct pcmcia_low_level colibri_pcmcia_ops = {
103         .owner                  = THIS_MODULE,
104
105         .first                  = 0,
106         .nr                     = 1,
107
108         .hw_init                = colibri_pcmcia_hw_init,
109         .hw_shutdown            = colibri_pcmcia_hw_shutdown,
110
111         .socket_state           = colibri_pcmcia_socket_state,
112         .configure_socket       = colibri_pcmcia_configure_socket,
113 };
114
115 static struct platform_device *colibri_pcmcia_device;
116
117 static int __init colibri_pcmcia_init(void)
118 {
119         int ret;
120
121         if (!machine_is_colibri() && !machine_is_colibri320())
122                 return -ENODEV;
123
124         colibri_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
125         if (!colibri_pcmcia_device)
126                 return -ENOMEM;
127
128         /* Colibri PXA270 */
129         if (machine_is_colibri()) {
130                 colibri_pcmcia_gpios[RESET].gpio        = COLIBRI270_RESET_GPIO;
131                 colibri_pcmcia_gpios[PPEN].gpio         = COLIBRI270_PPEN_GPIO;
132                 colibri_pcmcia_gpios[BVD1].gpio         = COLIBRI270_BVD1_GPIO;
133                 colibri_pcmcia_gpios[BVD2].gpio         = COLIBRI270_BVD2_GPIO;
134                 colibri_pcmcia_gpios[DETECT].gpio       = COLIBRI270_DETECT_GPIO;
135                 colibri_pcmcia_gpios[READY].gpio        = COLIBRI270_READY_GPIO;
136         /* Colibri PXA320 */
137         } else if (machine_is_colibri320()) {
138                 colibri_pcmcia_gpios[RESET].gpio        = COLIBRI320_RESET_GPIO;
139                 colibri_pcmcia_gpios[PPEN].gpio         = COLIBRI320_PPEN_GPIO;
140                 colibri_pcmcia_gpios[BVD1].gpio         = COLIBRI320_BVD1_GPIO;
141                 colibri_pcmcia_gpios[BVD2].gpio         = COLIBRI320_BVD2_GPIO;
142                 colibri_pcmcia_gpios[DETECT].gpio       = COLIBRI320_DETECT_GPIO;
143                 colibri_pcmcia_gpios[READY].gpio        = COLIBRI320_READY_GPIO;
144         }
145
146         ret = platform_device_add_data(colibri_pcmcia_device,
147                 &colibri_pcmcia_ops, sizeof(colibri_pcmcia_ops));
148
149         if (!ret)
150                 ret = platform_device_add(colibri_pcmcia_device);
151
152         if (ret)
153                 platform_device_put(colibri_pcmcia_device);
154
155         return ret;
156 }
157
158 static void __exit colibri_pcmcia_exit(void)
159 {
160         platform_device_unregister(colibri_pcmcia_device);
161 }
162
163 module_init(colibri_pcmcia_init);
164 module_exit(colibri_pcmcia_exit);
165
166 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
167 MODULE_DESCRIPTION("PCMCIA support for Toradex Colibri PXA270/PXA320");
168 MODULE_ALIAS("platform:pxa2xx-pcmcia");
169 MODULE_LICENSE("GPL");