net: wireless: rockchip_wlan: add rtl8723ds support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723ds / platform / platform_ARM_SUNxI_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 #include <drv_types.h>
21
22 #ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
23 #ifdef CONFIG_WITS_EVB_V13
24         #define SDIOID  0
25 #else /* !CONFIG_WITS_EVB_V13 */
26         #define SDIOID (CONFIG_CHIP_ID == 1123 ? 3 : 1)
27 #endif /* !CONFIG_WITS_EVB_V13 */
28
29 #define SUNXI_SDIO_WIFI_NUM_RTL8189ES  10
30 extern void sunximmc_rescan_card(unsigned id, unsigned insert);
31 extern int mmc_pm_get_mod_type(void);
32 extern int mmc_pm_gpio_ctrl(char *name, int level);
33 /*
34  *      rtl8189es_shdn  = port:PH09<1><default><default><0>
35  *      rtl8189es_wakeup        = port:PH10<1><default><default><1>
36  *      rtl8189es_vdd_en  = port:PH11<1><default><default><0>
37  *      rtl8189es_vcc_en  = port:PH12<1><default><default><0>
38  */
39
40 int rtl8189es_sdio_powerup(void)
41 {
42         mmc_pm_gpio_ctrl("rtl8189es_vdd_en", 1);
43         udelay(100);
44         mmc_pm_gpio_ctrl("rtl8189es_vcc_en", 1);
45         udelay(50);
46         mmc_pm_gpio_ctrl("rtl8189es_shdn", 1);
47         return 0;
48 }
49
50 int rtl8189es_sdio_poweroff(void)
51 {
52         mmc_pm_gpio_ctrl("rtl8189es_shdn", 0);
53         mmc_pm_gpio_ctrl("rtl8189es_vcc_en", 0);
54         mmc_pm_gpio_ctrl("rtl8189es_vdd_en", 0);
55         return 0;
56 }
57 #endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
58
59 /*
60  * Return:
61  *      0:      power on successfully
62  *      others: power on failed
63  */
64 int platform_wifi_power_on(void)
65 {
66         int ret = 0;
67 #ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
68         unsigned int mod_sel = mmc_pm_get_mod_type();
69 #endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
70
71
72 #ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
73         if (mod_sel == SUNXI_SDIO_WIFI_NUM_RTL8189ES) {
74                 rtl8189es_sdio_powerup();
75                 sunximmc_rescan_card(SDIOID, 1);
76                 printk("[rtl8189es] %s: power up, rescan card.\n", __FUNCTION__);
77         } else {
78                 ret = -1;
79                 printk("[rtl8189es] %s: mod_sel = %d is incorrect.\n", __FUNCTION__, mod_sel);
80         }
81 #endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
82
83         return ret;
84 }
85
86 void platform_wifi_power_off(void)
87 {
88 #ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
89         sunximmc_rescan_card(SDIOID, 0);
90 #ifdef CONFIG_RTL8188E
91         rtl8189es_sdio_poweroff();
92         printk("[rtl8189es] %s: remove card, power off.\n", __FUNCTION__);
93 #endif /* CONFIG_RTL8188E */
94 #endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
95 }