net: wireless: rockchip_wlan: add rtl8188eu support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8188eu / 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 \r
38 #if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)\r
39 extern void sw_mci_rescan_card(unsigned id, unsigned insert);\r
40 #elif defined(CONFIG_PLATFORM_ARM_SUN8I)\r
41 extern void sunxi_mci_rescan_card(unsigned id, unsigned insert);\r
42 #endif\r
43 \r
44 #ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1\r
45 extern int get_rf_mod_type(void);\r
46 #else\r
47 extern int wifi_pm_get_mod_type(void);\r
48 #endif\r
49 \r
50 extern void wifi_pm_power(int on);\r
51 #ifdef CONFIG_GPIO_WAKEUP\r
52 extern unsigned int oob_irq;\r
53 #endif\r
54 #endif // CONFIG_MMC\r
55 \r
56 /*\r
57  * Return:\r
58  *      0:      power on successfully\r
59  *      others: power on failed\r
60  */\r
61 int platform_wifi_power_on(void)\r
62 {\r
63         int ret = 0;\r
64 \r
65 #ifdef CONFIG_MMC\r
66 {\r
67         script_item_u val;\r
68         script_item_value_type_e type;\r
69 \r
70 #ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1\r
71         unsigned int mod_sel = get_rf_mod_type();\r
72 #else\r
73         unsigned int mod_sel = wifi_pm_get_mod_type();\r
74 #endif\r
75 \r
76         type = script_get_item("wifi_para", "wifi_sdc_id", &val);\r
77         if (SCIRPT_ITEM_VALUE_TYPE_INT!=type) {\r
78                 DBG_871X("get wifi_sdc_id failed\n");\r
79                 ret = -1;\r
80         } else {\r
81                 sdc_id = val.val;\r
82                 DBG_871X("----- %s sdc_id: %d, mod_sel: %d\n", __FUNCTION__, sdc_id, mod_sel);\r
83 \r
84 #if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)\r
85                 sw_mci_rescan_card(sdc_id, 1);\r
86 #elif defined(CONFIG_PLATFORM_ARM_SUN8I)\r
87                 sunxi_mci_rescan_card(sdc_id, 1);\r
88 #endif\r
89                 mdelay(100);\r
90                 wifi_pm_power(1);\r
91 \r
92                 DBG_871X("%s: power up, rescan card.\n", __FUNCTION__);\r
93         }\r
94 \r
95 #ifdef CONFIG_GPIO_WAKEUP\r
96 #ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1\r
97         type = script_get_item("wifi_para", "wl_host_wake", &val);\r
98 #else\r
99 #ifdef CONFIG_RTL8723B\r
100         type = script_get_item("wifi_para", "rtl8723bs_wl_host_wake", &val);\r
101 #endif\r
102 #ifdef CONFIG_RTL8188E\r
103         type = script_get_item("wifi_para", "rtl8189es_host_wake", &val);\r
104 #endif\r
105 #endif /* CONFIG_PLATFORM_ARM_SUN8I_W5P1 */\r
106         if (SCIRPT_ITEM_VALUE_TYPE_PIO != type) {\r
107                 DBG_871X("No definition of wake up host PIN\n");\r
108                 ret = -1;\r
109         } else {\r
110                 gpio_eint_wlan = val.gpio.gpio;\r
111 #ifdef CONFIG_PLATFORM_ARM_SUN8I\r
112                 oob_irq = gpio_to_irq(gpio_eint_wlan);\r
113 #endif\r
114         }\r
115 #endif // CONFIG_GPIO_WAKEUP\r
116 }\r
117 #endif // CONFIG_MMC\r
118 \r
119         return ret;\r
120 }\r
121 \r
122 void platform_wifi_power_off(void)\r
123 {\r
124 #ifdef CONFIG_MMC\r
125 #if defined(CONFIG_PLATFORM_ARM_SUN6I) ||defined(CONFIG_PLATFORM_ARM_SUN7I)\r
126         sw_mci_rescan_card(sdc_id, 0);\r
127 #elif defined(CONFIG_PLATFORM_ARM_SUN8I)\r
128         sunxi_mci_rescan_card(sdc_id, 0);\r
129 #endif\r
130         mdelay(100);\r
131         wifi_pm_power(0);\r
132 \r
133         DBG_871X("%s: remove card, power off.\n", __FUNCTION__);\r
134 #endif // CONFIG_MMC\r
135 }\r