arm: tegra: ardbeg: Add wifi edp client
[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 #if defined(CONFIG_BCMDHD_EDP_SUPPORT)
46 #define ON 1020 /* 1019.16mW */
47 #define OFF 0
48 static unsigned int wifi_states[] = {ON, OFF};
49 #endif
50
51 #define ARDBEG_SD_CD    TEGRA_GPIO_PV2
52
53 static void (*wifi_status_cb)(int card_present, void *dev_id);
54 static void *wifi_status_cb_devid;
55 static int ardbeg_wifi_status_register(void (*callback)(int , void *), void *);
56
57 static int ardbeg_wifi_reset(int on);
58 static int ardbeg_wifi_power(int on);
59 static int ardbeg_wifi_set_carddetect(int val);
60
61 static struct wifi_platform_data ardbeg_wifi_control = {
62         .set_power      = ardbeg_wifi_power,
63         .set_reset      = ardbeg_wifi_reset,
64         .set_carddetect = ardbeg_wifi_set_carddetect,
65 #if defined (CONFIG_BCMDHD_EDP_SUPPORT)
66         /* wifi edp client information */
67         .client_info    = {
68                 .name           = "wifi_edp_client",
69                 .states         = wifi_states,
70                 .num_states     = ARRAY_SIZE(wifi_states),
71                 .e0_index       = 0,
72                 .priority       = EDP_MAX_PRIO,
73         },
74 #endif
75 };
76
77 static struct resource wifi_resource[] = {
78         [0] = {
79                 .name   = "bcm4329_wlan_irq",
80                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL
81                                 | IORESOURCE_IRQ_SHAREABLE,
82         },
83 };
84
85 static struct platform_device ardbeg_wifi_device = {
86         .name           = "bcm4329_wlan",
87         .id             = 1,
88         .num_resources  = 1,
89         .resource       = wifi_resource,
90         .dev            = {
91                 .platform_data = &ardbeg_wifi_control,
92         },
93 };
94
95 static struct resource mrvl_wifi_resource[] = {
96         [0] = {
97                 .name   = "mrvl_wlan_irq",
98                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL | IORESOURCE_IRQ_SHAREABLE,
99         },
100 };
101
102 static struct platform_device marvell_wifi_device = {
103         .name           = "mrvl_wlan",
104         .id             = 1,
105         .num_resources  = 1,
106         .resource       = mrvl_wifi_resource,
107         .dev            = {
108                 .platform_data = &ardbeg_wifi_control,
109         },
110 };
111
112 static struct resource sdhci_resource0[] = {
113         [0] = {
114                 .start  = INT_SDMMC1,
115                 .end    = INT_SDMMC1,
116                 .flags  = IORESOURCE_IRQ,
117         },
118         [1] = {
119                 .start  = TEGRA_SDMMC1_BASE,
120                 .end    = TEGRA_SDMMC1_BASE + TEGRA_SDMMC1_SIZE-1,
121                 .flags  = IORESOURCE_MEM,
122         },
123 };
124
125 static struct resource sdhci_resource2[] = {
126         [0] = {
127                 .start  = INT_SDMMC3,
128                 .end    = INT_SDMMC3,
129                 .flags  = IORESOURCE_IRQ,
130         },
131         [1] = {
132                 .start  = TEGRA_SDMMC3_BASE,
133                 .end    = TEGRA_SDMMC3_BASE + TEGRA_SDMMC3_SIZE-1,
134                 .flags  = IORESOURCE_MEM,
135         },
136 };
137
138 static struct resource sdhci_resource3[] = {
139         [0] = {
140                 .start  = INT_SDMMC4,
141                 .end    = INT_SDMMC4,
142                 .flags  = IORESOURCE_IRQ,
143         },
144         [1] = {
145                 .start  = TEGRA_SDMMC4_BASE,
146                 .end    = TEGRA_SDMMC4_BASE + TEGRA_SDMMC4_SIZE-1,
147                 .flags  = IORESOURCE_MEM,
148         },
149 };
150
151 #ifdef CONFIG_MMC_EMBEDDED_SDIO
152 static struct embedded_sdio_data embedded_sdio_data0 = {
153         .cccr   = {
154                 .sdio_vsn       = 2,
155                 .multi_block    = 1,
156                 .low_speed      = 0,
157                 .wide_bus       = 0,
158                 .high_power     = 1,
159                 .high_speed     = 1,
160         },
161         .cis  = {
162                 .vendor  = 0x02d0,
163                 .device  = 0x4329,
164         },
165 };
166 #endif
167
168 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data0 = {
169         .mmc_data = {
170                 .register_status_notify = ardbeg_wifi_status_register,
171 #ifdef CONFIG_MMC_EMBEDDED_SDIO
172                 .embedded_sdio = &embedded_sdio_data0,
173 #endif
174                 .built_in = 0,
175                 .ocr_mask = MMC_OCR_1V8_MASK,
176         },
177         .cd_gpio = -1,
178         .wp_gpio = -1,
179         .power_gpio = -1,
180         .tap_delay = 0,
181         .trim_delay = 0x2,
182         .ddr_clk_limit = 41000000,
183         .uhs_mask = MMC_UHS_MASK_SDR104 | MMC_UHS_MASK_DDR50 |
184                 MMC_UHS_MASK_SDR50,
185         .calib_3v3_offsets = 0x7676,
186         .calib_1v8_offsets = 0x7676,
187 };
188
189 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data2 = {
190         .cd_gpio = ARDBEG_SD_CD,
191         .wp_gpio = -1,
192         .power_gpio = -1,
193         .tap_delay = 0,
194         .trim_delay = 0x3,
195         .uhs_mask = MMC_UHS_MASK_DDR50 | MMC_UHS_MASK_SDR50,
196         .calib_3v3_offsets = 0x7676,
197         .calib_1v8_offsets = 0x7676,
198 };
199
200 static struct tegra_sdhci_platform_data tegra_sdhci_platform_data3 = {
201         .cd_gpio = -1,
202         .wp_gpio = -1,
203         .power_gpio = -1,
204         .is_8bit = 1,
205         .tap_delay = 0x4,
206         .trim_delay = 0x4,
207         .ddr_trim_delay = 0x0,
208         .mmc_data = {
209                 .built_in = 1,
210                 .ocr_mask = MMC_OCR_1V8_MASK,
211         },
212         .ddr_clk_limit = 51000000,
213         .max_clk_limit = 102000000,
214         .calib_3v3_offsets = 0x0202,
215         .calib_1v8_offsets = 0x0202,
216 };
217
218 static struct platform_device tegra_sdhci_device0 = {
219         .name           = "sdhci-tegra",
220         .id             = 0,
221         .resource       = sdhci_resource0,
222         .num_resources  = ARRAY_SIZE(sdhci_resource0),
223         .dev = {
224                 .platform_data = &tegra_sdhci_platform_data0,
225         },
226 };
227
228 static struct platform_device tegra_sdhci_device2 = {
229         .name           = "sdhci-tegra",
230         .id             = 2,
231         .resource       = sdhci_resource2,
232         .num_resources  = ARRAY_SIZE(sdhci_resource2),
233         .dev = {
234                 .platform_data = &tegra_sdhci_platform_data2,
235         },
236 };
237
238 static struct platform_device tegra_sdhci_device3 = {
239         .name           = "sdhci-tegra",
240         .id             = 3,
241         .resource       = sdhci_resource3,
242         .num_resources  = ARRAY_SIZE(sdhci_resource3),
243         .dev = {
244                 .platform_data = &tegra_sdhci_platform_data3,
245         },
246 };
247
248 static int ardbeg_wifi_status_register(
249                 void (*callback)(int card_present, void *dev_id),
250                 void *dev_id)
251 {
252         if (wifi_status_cb)
253                 return -EAGAIN;
254         wifi_status_cb = callback;
255         wifi_status_cb_devid = dev_id;
256         return 0;
257 }
258
259 static int ardbeg_wifi_set_carddetect(int val)
260 {
261         pr_debug("%s: %d\n", __func__, val);
262         if (wifi_status_cb)
263                 wifi_status_cb(val, wifi_status_cb_devid);
264         else
265                 pr_warn("%s: Nobody to notify\n", __func__);
266         return 0;
267 }
268
269 static int ardbeg_wifi_power(int on)
270 {
271         pr_err("%s: %d\n", __func__, on);
272
273         gpio_set_value(ARDBEG_WLAN_PWR, on);
274         gpio_set_value(ARDBEG_WLAN_RST, on);
275         mdelay(100);
276
277         return 0;
278 }
279
280 static int ardbeg_wifi_reset(int on)
281 {
282         pr_debug("%s: do nothing\n", __func__);
283         return 0;
284 }
285
286 static int __init ardbeg_wifi_init(void)
287 {
288         int rc;
289
290         rc = gpio_request(ARDBEG_WLAN_PWR, "wlan_power");
291         if (rc)
292                 pr_err("WLAN_PWR gpio request failed:%d\n", rc);
293         rc = gpio_request(ARDBEG_WLAN_RST, "wlan_rst");
294         if (rc)
295                 pr_err("WLAN_RST gpio request failed:%d\n", rc);
296         rc = gpio_request(ARDBEG_WLAN_WOW, "bcmsdh_sdmmc");
297         if (rc)
298                 pr_err("WLAN_WOW gpio request failed:%d\n", rc);
299
300         rc = gpio_direction_output(ARDBEG_WLAN_PWR, 0);
301         if (rc)
302                 pr_err("WLAN_PWR gpio direction configuration failed:%d\n", rc);
303         rc = gpio_direction_output(ARDBEG_WLAN_RST, 0);
304         if (rc)
305                 pr_err("WLAN_RST gpio direction configuration failed:%d\n", rc);
306
307         rc = gpio_direction_input(ARDBEG_WLAN_WOW);
308         if (rc)
309                 pr_err("WLAN_WOW gpio direction configuration failed:%d\n", rc);
310
311         wifi_resource[0].start = wifi_resource[0].end =
312                 gpio_to_irq(ARDBEG_WLAN_WOW);
313
314         platform_device_register(&ardbeg_wifi_device);
315
316         mrvl_wifi_resource[0].start = mrvl_wifi_resource[0].end =
317                 gpio_to_irq(ARDBEG_WLAN_WOW);
318         platform_device_register(&marvell_wifi_device);
319
320         return 0;
321 }
322
323 #ifdef CONFIG_TEGRA_PREPOWER_WIFI
324 static int __init ardbeg_wifi_prepower(void)
325 {
326         if (!of_machine_is_compatible("nvidia,ardbeg") &&
327                 !of_machine_is_compatible("nvidia,laguna") &&
328                 !of_machine_is_compatible("nvidia,tn8"))
329                 return 0;
330         ardbeg_wifi_power(1);
331
332         return 0;
333 }
334
335 subsys_initcall_sync(ardbeg_wifi_prepower);
336 #endif
337
338 int __init ardbeg_sdhci_init(void)
339 {
340         int nominal_core_mv;
341         int min_vcore_override_mv;
342         int boot_vcore_mv;
343         struct board_info board_info;
344
345         nominal_core_mv =
346                 tegra_dvfs_rail_get_nominal_millivolts(tegra_core_rail);
347         if (nominal_core_mv) {
348                 tegra_sdhci_platform_data0.nominal_vcore_mv = nominal_core_mv;
349                 tegra_sdhci_platform_data2.nominal_vcore_mv = nominal_core_mv;
350                 tegra_sdhci_platform_data3.nominal_vcore_mv = nominal_core_mv;
351         }
352         min_vcore_override_mv =
353                 tegra_dvfs_rail_get_override_floor(tegra_core_rail);
354         if (min_vcore_override_mv) {
355                 tegra_sdhci_platform_data0.min_vcore_override_mv =
356                         min_vcore_override_mv;
357                 tegra_sdhci_platform_data2.min_vcore_override_mv =
358                         min_vcore_override_mv;
359                 tegra_sdhci_platform_data3.min_vcore_override_mv =
360                         min_vcore_override_mv;
361         }
362         boot_vcore_mv = tegra_dvfs_rail_get_boot_level(tegra_core_rail);
363         if (boot_vcore_mv) {
364                 tegra_sdhci_platform_data0.boot_vcore_mv = boot_vcore_mv;
365                 tegra_sdhci_platform_data2.boot_vcore_mv = boot_vcore_mv;
366                 tegra_sdhci_platform_data3.boot_vcore_mv = boot_vcore_mv;
367         }
368
369         tegra_get_board_info(&board_info);
370         if (board_info.board_id == BOARD_E1780) {
371                 tegra_sdhci_platform_data3.max_clk_limit = 200000000;
372                 tegra_sdhci_platform_data2.max_clk_limit = 204000000;
373         } else {
374                 tegra_sdhci_platform_data3.uhs_mask = MMC_MASK_HS200;
375         }
376
377         platform_device_register(&tegra_sdhci_device3);
378         platform_device_register(&tegra_sdhci_device2);
379         platform_device_register(&tegra_sdhci_device0);
380         ardbeg_wifi_init();
381
382         return 0;
383 }