ARM: tegra: ardbeg: Enable HS200 mode for eMMC
[linux-3.10.git] / arch / arm / mach-tegra / board-ardbeg-sdhci.c
1 /*
2  * arch/arm/mach-tegra/board-ardbeg-sdhci.c
3  *
4  * Copyright (c) 2013, NVIDIA CORPORATION.  All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <linux/resource.h>
20 #include <linux/platform_device.h>
21 #include <linux/wlan_plat.h>
22 #include <linux/delay.h>
23 #include <linux/gpio.h>
24 #include <linux/clk.h>
25 #include <linux/err.h>
26 #include <linux/mmc/host.h>
27 #include <linux/wl12xx.h>
28 #include <linux/platform_data/mmc-sdhci-tegra.h>
29 #include <linux/mfd/max77660/max77660-core.h>
30
31 #include <asm/mach-types.h>
32 #include <mach/irqs.h>
33 #include <mach/gpio-tegra.h>
34
35 #include "gpio-names.h"
36 #include "board.h"
37 #include "board-ardbeg.h"
38 #include "dvfs.h"
39 #include "iomap.h"
40 #include "tegra-board-id.h"
41
42 #define ARDBEG_WLAN_RST TEGRA_GPIO_PCC5
43 #define ARDBEG_WLAN_PWR TEGRA_GPIO_PX7
44 #define ARDBEG_WLAN_WOW TEGRA_GPIO_PU5
45
46 #define ARDBEG_SD_CD    TEGRA_GPIO_PV2
47
48 static void (*wifi_status_cb)(int card_present, void *dev_id);
49 static void *wifi_status_cb_devid;
50 static int ardbeg_wifi_status_register(void (*callback)(int , void *), void *);
51
52 static int ardbeg_wifi_reset(int on);
53 static int ardbeg_wifi_power(int on);
54 static int ardbeg_wifi_set_carddetect(int val);
55
56 static struct wifi_platform_data ardbeg_wifi_control = {
57         .set_power      = ardbeg_wifi_power,
58         .set_reset      = ardbeg_wifi_reset,
59         .set_carddetect = ardbeg_wifi_set_carddetect,
60 };
61
62 static struct resource wifi_resource[] = {
63         [0] = {
64                 .name   = "bcm4329_wlan_irq",
65                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL
66                                 | IORESOURCE_IRQ_SHAREABLE,
67         },
68 };
69
70 static struct platform_device ardbeg_wifi_device = {
71         .name           = "bcm4329_wlan",
72         .id             = 1,
73         .num_resources  = 1,
74         .resource       = wifi_resource,
75         .dev            = {
76                 .platform_data = &ardbeg_wifi_control,
77         },
78 };
79
80 static struct resource sdhci_resource0[] = {
81         [0] = {
82                 .start  = INT_SDMMC1,
83                 .end    = INT_SDMMC1,
84                 .flags  = IORESOURCE_IRQ,
85         },
86         [1] = {
87                 .start  = TEGRA_SDMMC1_BASE,
88                 .end    = TEGRA_SDMMC1_BASE + TEGRA_SDMMC1_SIZE-1,
89                 .flags  = IORESOURCE_MEM,
90         },
91 };
92
93 static struct resource sdhci_resource2[] = {
94         [0] = {
95                 .start  = INT_SDMMC3,
96                 .end    = INT_SDMMC3,
97                 .flags  = IORESOURCE_IRQ,
98         },
99         [1] = {
100                 .start  = TEGRA_SDMMC3_BASE,
101                 .end    = TEGRA_SDMMC3_BASE + TEGRA_SDMMC3_SIZE-1,
102                 .flags  = IORESOURCE_MEM,
103         },
104 };
105
106 static struct resource sdhci_resource3[] = {
107         [0] = {
108                 .start  = INT_SDMMC4,
109                 .end    = INT_SDMMC4,
110                 .flags  = IORESOURCE_IRQ,
111         },
112         [1] = {
113                 .start  = TEGRA_SDMMC4_BASE,
114                 .end    = TEGRA_SDMMC4_BASE + TEGRA_SDMMC4_SIZE-1,
115                 .flags  = IORESOURCE_MEM,
116         },
117 };
118
119 #ifdef CONFIG_MMC_EMBEDDED_SDIO
120 static struct embedded_sdio_data embedded_sdio_data0 = {
121         .cccr   = {
122                 .sdio_vsn       = 2,
123                 .multi_block    = 1,
124                 .low_speed      = 0,
125                 .wide_bus       = 0,
126                 .high_power     = 1,
127                 .high_speed     = 1,
128         },
129         .cis  = {
130                 .vendor  = 0x02d0,
131                 .device  = 0x4329,
132         },
133 };
134 #endif
135
136 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data0 = {
137         .mmc_data = {
138                 .register_status_notify = ardbeg_wifi_status_register,
139 #ifdef CONFIG_MMC_EMBEDDED_SDIO
140                 .embedded_sdio = &embedded_sdio_data0,
141 #endif
142                 .built_in = 0,
143                 .ocr_mask = MMC_OCR_1V8_MASK,
144         },
145         .cd_gpio = -1,
146         .wp_gpio = -1,
147         .power_gpio = -1,
148         .tap_delay = 0,
149         .trim_delay = 0x2,
150         .ddr_clk_limit = 41000000,
151 /*FIXME: Enable UHS modes for WiFI */
152         .uhs_mask = MMC_UHS_MASK_SDR104 | MMC_UHS_MASK_SDR12 | MMC_UHS_MASK_SDR25 |
153                 MMC_UHS_MASK_DDR50 | MMC_UHS_MASK_SDR50,
154         .calib_3v3_offsets = 0x7676,
155         .calib_1v8_offsets = 0x7676,
156         .calib_1v8_offsets_uhs_modes = MMC_1V8_CALIB_OFFSET_DDR50,
157 };
158
159 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data2 = {
160         .cd_gpio = ARDBEG_SD_CD,
161         .wp_gpio = -1,
162         .power_gpio = -1,
163         .tap_delay = 0,
164         .trim_delay = 0x3,
165 /*FIXME: Enable UHS modes for SD */
166         .uhs_mask = MMC_UHS_MASK_SDR12 | MMC_UHS_MASK_SDR25 |
167                 MMC_UHS_MASK_SDR104 |
168                 MMC_UHS_MASK_DDR50 | MMC_UHS_MASK_SDR50,
169         .calib_3v3_offsets = 0x7676,
170         .calib_1v8_offsets = 0x7676,
171         .calib_1v8_offsets_uhs_modes = MMC_1V8_CALIB_OFFSET_DDR50,
172 };
173
174 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data3 = {
175         .cd_gpio = -1,
176         .wp_gpio = -1,
177         .power_gpio = -1,
178         .is_8bit = 1,
179         .tap_delay = 0x4,
180         .trim_delay = 0x4,
181         .ddr_trim_delay = 0x4,
182         .mmc_data = {
183                 .built_in = 1,
184                 .ocr_mask = MMC_OCR_1V8_MASK,
185         },
186         .ddr_clk_limit = 51000000,
187         .max_clk_limit = 102000000,
188         .calib_3v3_offsets = 0x0202,
189         .calib_1v8_offsets = 0x0202,
190         .calib_1v8_offsets_uhs_modes = MMC_1V8_CALIB_OFFSET_DDR50 |
191                 MMC_1V8_CALIB_OFFSET_HS200,
192 };
193
194 static struct platform_device tegra_sdhci_device0 = {
195         .name           = "sdhci-tegra",
196         .id             = 0,
197         .resource       = sdhci_resource0,
198         .num_resources  = ARRAY_SIZE(sdhci_resource0),
199         .dev = {
200                 .platform_data = &tegra_sdhci_platform_data0,
201         },
202 };
203
204 static struct platform_device tegra_sdhci_device2 = {
205         .name           = "sdhci-tegra",
206         .id             = 2,
207         .resource       = sdhci_resource2,
208         .num_resources  = ARRAY_SIZE(sdhci_resource2),
209         .dev = {
210                 .platform_data = &tegra_sdhci_platform_data2,
211         },
212 };
213
214 static struct platform_device tegra_sdhci_device3 = {
215         .name           = "sdhci-tegra",
216         .id             = 3,
217         .resource       = sdhci_resource3,
218         .num_resources  = ARRAY_SIZE(sdhci_resource3),
219         .dev = {
220                 .platform_data = &tegra_sdhci_platform_data3,
221         },
222 };
223
224 static int ardbeg_wifi_status_register(
225                 void (*callback)(int card_present, void *dev_id),
226                 void *dev_id)
227 {
228         if (wifi_status_cb)
229                 return -EAGAIN;
230         wifi_status_cb = callback;
231         wifi_status_cb_devid = dev_id;
232         return 0;
233 }
234
235 static int ardbeg_wifi_set_carddetect(int val)
236 {
237         pr_debug("%s: %d\n", __func__, val);
238         if (wifi_status_cb)
239                 wifi_status_cb(val, wifi_status_cb_devid);
240         else
241                 pr_warn("%s: Nobody to notify\n", __func__);
242         return 0;
243 }
244
245 static int ardbeg_wifi_power(int on)
246 {
247         pr_err("%s: %d\n", __func__, on);
248
249         gpio_set_value(ARDBEG_WLAN_PWR, on);
250         gpio_set_value(ARDBEG_WLAN_RST, on);
251         mdelay(100);
252
253         return 0;
254 }
255
256 static int ardbeg_wifi_reset(int on)
257 {
258         pr_debug("%s: do nothing\n", __func__);
259         return 0;
260 }
261
262 static int __init ardbeg_wifi_init(void)
263 {
264         int rc;
265
266         rc = gpio_request(ARDBEG_WLAN_PWR, "wlan_power");
267         if (rc)
268                 pr_err("WLAN_PWR gpio request failed:%d\n", rc);
269         rc = gpio_request(ARDBEG_WLAN_RST, "wlan_rst");
270         if (rc)
271                 pr_err("WLAN_RST gpio request failed:%d\n", rc);
272         rc = gpio_request(ARDBEG_WLAN_WOW, "bcmsdh_sdmmc");
273         if (rc)
274                 pr_err("WLAN_WOW gpio request failed:%d\n", rc);
275
276         rc = gpio_direction_output(ARDBEG_WLAN_PWR, 0);
277         if (rc)
278                 pr_err("WLAN_PWR gpio direction configuration failed:%d\n", rc);
279         rc = gpio_direction_output(ARDBEG_WLAN_RST, 0);
280         if (rc)
281                 pr_err("WLAN_RST gpio direction configuration failed:%d\n", rc);
282
283         rc = gpio_direction_input(ARDBEG_WLAN_WOW);
284         if (rc)
285                 pr_err("WLAN_WOW gpio direction configuration failed:%d\n", rc);
286
287         wifi_resource[0].start = wifi_resource[0].end =
288                 gpio_to_irq(ARDBEG_WLAN_WOW);
289
290         platform_device_register(&ardbeg_wifi_device);
291         return 0;
292 }
293
294 #ifdef CONFIG_TEGRA_PREPOWER_WIFI
295 static int __init ardbeg_wifi_prepower(void)
296 {
297         if (!of_machine_is_compatible("nvidia,ardbeg") &&
298                 !of_machine_is_compatible("nvidia,laguna") &&
299                 !of_machine_is_compatible("nvidia,tn8"))
300                 return 0;
301         ardbeg_wifi_power(1);
302
303         return 0;
304 }
305
306 subsys_initcall_sync(ardbeg_wifi_prepower);
307 #endif
308
309 int __init ardbeg_sdhci_init(void)
310 {
311         int nominal_core_mv;
312         int min_vcore_override_mv;
313         int boot_vcore_mv;
314         struct board_info board_info;
315
316         nominal_core_mv =
317                 tegra_dvfs_rail_get_nominal_millivolts(tegra_core_rail);
318         if (nominal_core_mv) {
319                 tegra_sdhci_platform_data0.nominal_vcore_mv = nominal_core_mv;
320                 tegra_sdhci_platform_data2.nominal_vcore_mv = nominal_core_mv;
321                 tegra_sdhci_platform_data3.nominal_vcore_mv = nominal_core_mv;
322         }
323         min_vcore_override_mv =
324                 tegra_dvfs_rail_get_override_floor(tegra_core_rail);
325         if (min_vcore_override_mv) {
326                 tegra_sdhci_platform_data0.min_vcore_override_mv =
327                         min_vcore_override_mv;
328                 tegra_sdhci_platform_data2.min_vcore_override_mv =
329                         min_vcore_override_mv;
330                 tegra_sdhci_platform_data3.min_vcore_override_mv =
331                         min_vcore_override_mv;
332         }
333         boot_vcore_mv = tegra_dvfs_rail_get_boot_level(tegra_core_rail);
334         if (boot_vcore_mv) {
335                 tegra_sdhci_platform_data0.boot_vcore_mv = boot_vcore_mv;
336                 tegra_sdhci_platform_data2.boot_vcore_mv = boot_vcore_mv;
337                 tegra_sdhci_platform_data3.boot_vcore_mv = boot_vcore_mv;
338         }
339
340         tegra_get_board_info(&board_info);
341         if (board_info.board_id == BOARD_E1780)
342                 tegra_sdhci_platform_data3.max_clk_limit = 200000000;
343         else
344                 tegra_sdhci_platform_data3.uhs_mask = MMC_MASK_HS200;
345
346         platform_device_register(&tegra_sdhci_device3);
347         platform_device_register(&tegra_sdhci_device2);
348         platform_device_register(&tegra_sdhci_device0);
349         ardbeg_wifi_init();
350
351         return 0;
352 }