arm: tegra: Correct tap delay for all T30 sdhci controllers
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-sdhci.c
1 /*
2  * arch/arm/mach-tegra/board-harmony-sdhci.c
3  *
4  * Copyright (C) 2010 Google, Inc.
5  * Copyright (C) 2011-2012 NVIDIA Corporation.
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17
18 #include <linux/resource.h>
19 #include <linux/platform_device.h>
20 #include <linux/wlan_plat.h>
21 #include <linux/delay.h>
22 #include <linux/gpio.h>
23 #include <linux/clk.h>
24 #include <linux/err.h>
25 #include <linux/mmc/host.h>
26
27 #include <asm/mach-types.h>
28 #include <mach/irqs.h>
29 #include <mach/iomap.h>
30 #include <mach/sdhci.h>
31
32 #include "gpio-names.h"
33 #include "board.h"
34 #include "board-cardhu.h"
35
36 #define CARDHU_WLAN_PWR TEGRA_GPIO_PD4
37 #define CARDHU_WLAN_RST TEGRA_GPIO_PD3
38 #define CARDHU_WLAN_WOW TEGRA_GPIO_PO4
39 #define CARDHU_SD_CD TEGRA_GPIO_PI5
40 #define CARDHU_SD_WP TEGRA_GPIO_PT3
41 #define PM269_SD_WP -1
42
43 static void (*wifi_status_cb)(int card_present, void *dev_id);
44 static void *wifi_status_cb_devid;
45 static int cardhu_wifi_status_register(void (*callback)(int , void *), void *);
46
47 static int cardhu_wifi_reset(int on);
48 static int cardhu_wifi_power(int on);
49 static int cardhu_wifi_set_carddetect(int val);
50
51 static struct wifi_platform_data cardhu_wifi_control = {
52         .set_power      = cardhu_wifi_power,
53         .set_reset      = cardhu_wifi_reset,
54         .set_carddetect = cardhu_wifi_set_carddetect,
55 };
56
57 static struct resource wifi_resource[] = {
58         [0] = {
59                 .name   = "bcm4329_wlan_irq",
60                 .start  = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PO4),
61                 .end    = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PO4),
62                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL | IORESOURCE_IRQ_SHAREABLE,
63         },
64 };
65
66 static struct platform_device broadcom_wifi_device = {
67         .name           = "bcm4329_wlan",
68         .id             = 1,
69         .num_resources  = 1,
70         .resource       = wifi_resource,
71         .dev            = {
72                 .platform_data = &cardhu_wifi_control,
73         },
74 };
75
76 static struct platform_device marvell_wifi_device = {
77         .name           = "mrvl8797_wlan",
78         .id             = 1,
79         .num_resources  = 0,
80         .dev            = {
81                 .platform_data = &cardhu_wifi_control,
82         },
83 };
84
85 static struct resource sdhci_resource0[] = {
86         [0] = {
87                 .start  = INT_SDMMC1,
88                 .end    = INT_SDMMC1,
89                 .flags  = IORESOURCE_IRQ,
90         },
91         [1] = {
92                 .start  = TEGRA_SDMMC1_BASE,
93                 .end    = TEGRA_SDMMC1_BASE + TEGRA_SDMMC1_SIZE-1,
94                 .flags  = IORESOURCE_MEM,
95         },
96 };
97
98 static struct resource sdhci_resource2[] = {
99         [0] = {
100                 .start  = INT_SDMMC3,
101                 .end    = INT_SDMMC3,
102                 .flags  = IORESOURCE_IRQ,
103         },
104         [1] = {
105                 .start  = TEGRA_SDMMC3_BASE,
106                 .end    = TEGRA_SDMMC3_BASE + TEGRA_SDMMC3_SIZE-1,
107                 .flags  = IORESOURCE_MEM,
108         },
109 };
110
111 static struct resource sdhci_resource3[] = {
112         [0] = {
113                 .start  = INT_SDMMC4,
114                 .end    = INT_SDMMC4,
115                 .flags  = IORESOURCE_IRQ,
116         },
117         [1] = {
118                 .start  = TEGRA_SDMMC4_BASE,
119                 .end    = TEGRA_SDMMC4_BASE + TEGRA_SDMMC4_SIZE-1,
120                 .flags  = IORESOURCE_MEM,
121         },
122 };
123
124 #ifdef CONFIG_MMC_EMBEDDED_SDIO
125 static struct embedded_sdio_data embedded_sdio_data2 = {
126         .cccr   = {
127                 .sdio_vsn       = 2,
128                 .multi_block    = 1,
129                 .low_speed      = 0,
130                 .wide_bus       = 0,
131                 .high_power     = 1,
132                 .high_speed     = 1,
133         },
134         .cis  = {
135                 .vendor         = 0x02d0,
136                 .device         = 0x4329,
137         },
138 };
139 #endif
140
141 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data2 = {
142         .mmc_data = {
143                 .register_status_notify = cardhu_wifi_status_register,
144 #ifdef CONFIG_MMC_EMBEDDED_SDIO
145                 .embedded_sdio = &embedded_sdio_data2,
146 #endif
147                 .built_in = 0,
148         },
149 #ifndef CONFIG_MMC_EMBEDDED_SDIO
150         .pm_flags = MMC_PM_KEEP_POWER,
151 #endif
152         .cd_gpio = -1,
153         .wp_gpio = -1,
154         .power_gpio = -1,
155         .tap_delay = 0x0F,
156 /*      .is_voltage_switch_supported = false,
157         .vdd_rail_name = NULL,
158         .slot_rail_name = NULL,
159         .vdd_max_uv = -1,
160         .vdd_min_uv = -1,
161         .max_clk = 0,
162         .is_8bit_supported = false, */
163 };
164
165 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data0 = {
166         .cd_gpio = CARDHU_SD_CD,
167         .wp_gpio = CARDHU_SD_WP,
168         .power_gpio = -1,
169         .tap_delay = 0x0F,
170 /*      .is_voltage_switch_supported = true,
171         .vdd_rail_name = "vddio_sdmmc1",
172         .slot_rail_name = "vddio_sd_slot",
173         .vdd_max_uv = 3320000,
174         .vdd_min_uv = 3280000,
175         .max_clk = 208000000,
176         .is_8bit_supported = false, */
177 };
178
179 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data3 = {
180         .cd_gpio = -1,
181         .wp_gpio = -1,
182         .power_gpio = -1,
183         .is_8bit = 1,
184         .tap_delay = 0x0F,
185         .mmc_data = {
186                 .built_in = 1,
187         }
188 /*      .tap_delay = 6,
189         .is_voltage_switch_supported = false,
190         .vdd_rail_name = NULL,
191         .slot_rail_name = NULL,
192         .vdd_max_uv = -1,
193         .vdd_min_uv = -1,
194         .max_clk = 48000000,
195         .is_8bit_supported = true, */
196 };
197
198 static struct platform_device tegra_sdhci_device0 = {
199         .name           = "sdhci-tegra",
200         .id             = 0,
201         .resource       = sdhci_resource0,
202         .num_resources  = ARRAY_SIZE(sdhci_resource0),
203         .dev = {
204                 .platform_data = &tegra_sdhci_platform_data0,
205         },
206 };
207
208 static struct platform_device tegra_sdhci_device2 = {
209         .name           = "sdhci-tegra",
210         .id             = 2,
211         .resource       = sdhci_resource2,
212         .num_resources  = ARRAY_SIZE(sdhci_resource2),
213         .dev = {
214                 .platform_data = &tegra_sdhci_platform_data2,
215         },
216 };
217
218 static struct platform_device tegra_sdhci_device3 = {
219         .name           = "sdhci-tegra",
220         .id             = 3,
221         .resource       = sdhci_resource3,
222         .num_resources  = ARRAY_SIZE(sdhci_resource3),
223         .dev = {
224                 .platform_data = &tegra_sdhci_platform_data3,
225         },
226 };
227
228 static int cardhu_wifi_status_register(
229                 void (*callback)(int card_present, void *dev_id),
230                 void *dev_id)
231 {
232         if (wifi_status_cb)
233                 return -EAGAIN;
234         wifi_status_cb = callback;
235         wifi_status_cb_devid = dev_id;
236         return 0;
237 }
238
239 static int cardhu_wifi_set_carddetect(int val)
240 {
241         pr_debug("%s: %d\n", __func__, val);
242         if (wifi_status_cb)
243                 wifi_status_cb(val, wifi_status_cb_devid);
244         else
245                 pr_warning("%s: Nobody to notify\n", __func__);
246         return 0;
247 }
248
249 static int cardhu_wifi_power(int on)
250 {
251         pr_debug("%s: %d\n", __func__, on);
252         gpio_set_value(CARDHU_WLAN_PWR, on);
253         mdelay(100);
254         gpio_set_value(CARDHU_WLAN_RST, on);
255         mdelay(200);
256
257         return 0;
258 }
259
260 static int cardhu_wifi_reset(int on)
261 {
262         pr_debug("%s: do nothing\n", __func__);
263         return 0;
264 }
265
266 static int __init cardhu_wifi_init(void)
267 {
268         int rc;
269         int commchip_id = tegra_get_commchip_id();
270
271         rc = gpio_request(CARDHU_WLAN_PWR, "wlan_power");
272         if (rc)
273                 pr_err("WLAN_PWR gpio request failed:%d\n", rc);
274         rc = gpio_request(CARDHU_WLAN_RST, "wlan_rst");
275         if (rc)
276                 pr_err("WLAN_RST gpio request failed:%d\n", rc);
277         rc = gpio_request(CARDHU_WLAN_WOW, "bcmsdh_sdmmc");
278         if (rc)
279                 pr_err("WLAN_WOW gpio request failed:%d\n", rc);
280
281         tegra_gpio_enable(CARDHU_WLAN_PWR);
282         tegra_gpio_enable(CARDHU_WLAN_RST);
283         tegra_gpio_enable(CARDHU_WLAN_WOW);
284
285         rc = gpio_direction_output(CARDHU_WLAN_PWR, 0);
286         if (rc)
287                 pr_err("WLAN_PWR gpio direction configuration failed:%d\n", rc);
288         gpio_direction_output(CARDHU_WLAN_RST, 0);
289         if (rc)
290                 pr_err("WLAN_RST gpio direction configuration failed:%d\n", rc);
291         rc = gpio_direction_input(CARDHU_WLAN_WOW);
292         if (rc)
293                 pr_err("WLAN_WOW gpio direction configuration failed:%d\n", rc);
294
295         if (commchip_id == COMMCHIP_MARVELL_SD8797)
296                 platform_device_register(&marvell_wifi_device);
297         else
298                 platform_device_register(&broadcom_wifi_device);
299
300         return 0;
301 }
302
303 #ifdef CONFIG_TEGRA_PREPOWER_WIFI
304 static int __init cardhu_wifi_prepower(void)
305 {
306         if (!machine_is_cardhu())
307                 return 0;
308
309         cardhu_wifi_power(1);
310
311         return 0;
312 }
313
314 subsys_initcall_sync(cardhu_wifi_prepower);
315 #endif
316
317 int __init cardhu_sdhci_init(void)
318 {
319         struct board_info board_info;
320         tegra_get_board_info(&board_info);
321         if ((board_info.board_id == BOARD_PM269) ||
322                 (board_info.board_id == BOARD_E1257) ||
323                 (board_info.board_id == BOARD_PM305) ||
324                 (board_info.board_id == BOARD_PM311)) {
325                         tegra_sdhci_platform_data0.wp_gpio = PM269_SD_WP;
326                         tegra_sdhci_platform_data2.max_clk_limit = 12000000;
327         }
328
329         platform_device_register(&tegra_sdhci_device3);
330         platform_device_register(&tegra_sdhci_device2);
331         platform_device_register(&tegra_sdhci_device0);
332
333         cardhu_wifi_init();
334         return 0;
335 }