d384141eba0c8112870087e8deebb666e26f27ee
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / platform / platform_ARM_SUNnI_sdio.c
1 /******************************************************************************\r
2  *\r
3  * Copyright(c) 2013 Realtek Corporation. All rights reserved.\r
4  *\r
5  * This program is free software; you can redistribute it and/or modify it\r
6  * under the terms of version 2 of the GNU General Public License as\r
7  * published by the Free Software Foundation.\r
8  *\r
9  * This program is distributed in the hope that it will be useful, but WITHOUT\r
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
12  * more details.\r
13  *\r
14  * You should have received a copy of the GNU General Public License along with\r
15  * this program; if not, write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA\r
17  *\r
18  *\r
19  ******************************************************************************/\r
20 /*\r
21  * Description:\r
22  *      This file can be applied to following platforms:\r
23  *      CONFIG_PLATFORM_ARM_SUN6I\r
24  *      CONFIG_PLATFORM_ARM_SUN7I\r
25  *      CONFIG_PLATFORM_ARM_SUN8I\r
26  */\r
27 #include <drv_types.h>\r
28 #include <mach/sys_config.h>\r
29 #ifdef CONFIG_GPIO_WAKEUP\r
30 #include <linux/gpio.h>\r
31 #endif\r
32 \r
33 #ifdef CONFIG_MMC\r
34 static int sdc_id = -1;\r
35 static signed int gpio_eint_wlan = -1;\r
36 static u32 eint_wlan_handle = 0;\r
37 #if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)\r
38 extern void sw_mci_rescan_card(unsigned id, unsigned insert);\r
39 #elif defined(CONFIG_PLATFORM_ARM_SUN8I)\r
40 extern void sunxi_mci_rescan_card(unsigned id, unsigned insert);\r
41 #endif\r
42 extern int wifi_pm_get_mod_type(void);\r
43 extern void wifi_pm_power(int on);\r
44 #ifdef CONFIG_GPIO_WAKEUP\r
45 extern unsigned int oob_irq;\r
46 #endif\r
47 #endif // CONFIG_MMC\r
48 \r
49 /*\r
50  * Return:\r
51  *      0:      power on successfully\r
52  *      others: power on failed\r
53  */\r
54 int platform_wifi_power_on(void)\r
55 {\r
56         int ret = 0;\r
57 \r
58 #ifdef CONFIG_MMC\r
59 {\r
60         script_item_u val;\r
61         script_item_value_type_e type;\r
62 \r
63         unsigned int mod_sel = wifi_pm_get_mod_type();\r
64 \r
65         type = script_get_item("wifi_para", "wifi_sdc_id", &val);\r
66         if (SCIRPT_ITEM_VALUE_TYPE_INT!=type) {\r
67                 DBG_871X("get wifi_sdc_id failed\n");\r
68                 ret = -1;\r
69         } else {\r
70                 sdc_id = val.val;\r
71                 DBG_871X("----- %s sdc_id: %d, mod_sel: %d\n", __FUNCTION__, sdc_id, mod_sel);\r
72 \r
73 #if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)\r
74                 sw_mci_rescan_card(sdc_id, 1);\r
75 #elif defined(CONFIG_PLATFORM_ARM_SUN8I)\r
76                 sunxi_mci_rescan_card(sdc_id, 1);\r
77 #endif\r
78                 mdelay(100);\r
79                 wifi_pm_power(1);\r
80 \r
81                 DBG_871X("%s: power up, rescan card.\n", __FUNCTION__);\r
82         }\r
83 \r
84 #ifdef CONFIG_GPIO_WAKEUP\r
85 #ifdef CONFIG_RTL8723B\r
86         type = script_get_item("wifi_para", "rtl8723bs_wl_host_wake", &val);\r
87 #endif\r
88 #ifdef CONFIG_RTL8188E\r
89         type = script_get_item("wifi_para", "rtl8189es_host_wake", &val);\r
90 #endif\r
91         if (SCIRPT_ITEM_VALUE_TYPE_PIO != type) {\r
92                 DBG_871X("No definition of wake up host PIN\n");\r
93                 ret = -1;\r
94         } else {\r
95                 gpio_eint_wlan = val.gpio.gpio;\r
96 #ifdef CONFIG_PLATFORM_ARM_SUN8I\r
97                 oob_irq = gpio_to_irq(gpio_eint_wlan);\r
98 #endif\r
99         }\r
100 #endif // CONFIG_GPIO_WAKEUP\r
101 }\r
102 #endif // CONFIG_MMC\r
103 \r
104         return ret;\r
105 }\r
106 \r
107 void platform_wifi_power_off(void)\r
108 {\r
109 #ifdef CONFIG_MMC\r
110 #if defined(CONFIG_PLATFORM_ARM_SUN6I) ||defined(CONFIG_PLATFORM_ARM_SUN7I)\r
111         sw_mci_rescan_card(sdc_id, 0);\r
112 #elif defined(CONFIG_PLATFORM_ARM_SUN8I)\r
113         sunxi_mci_rescan_card(sdc_id, 0);\r
114 #endif\r
115         mdelay(100);\r
116         wifi_pm_power(0);\r
117 \r
118         DBG_871X("%s: remove card, power off.\n", __FUNCTION__);\r
119 #endif // CONFIG_MMC\r
120 }\r