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