Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/platform/platform_hisilicon_hi3798_sdio.c
1307 views
1
/******************************************************************************
2
*
3
* Copyright(c) 2017 - 2018 Realtek Corporation.
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
*****************************************************************************/
15
#include <linux/delay.h> /* mdelay() */
16
#include <mach/hardware.h> /* __io_address(), readl(), writel() */
17
#include "platform_hisilicon_hi3798_sdio.h" /* HI_S32() and etc. */
18
19
typedef enum hi_GPIO_DIR_E {
20
HI_DIR_OUT = 0,
21
HI_DIR_IN = 1,
22
} HI_GPIO_DIR_E;
23
24
#define RTL_REG_ON_GPIO (4*8 + 3)
25
26
#define REG_BASE_CTRL __io_address(0xf8a20008)
27
28
int gpio_wlan_reg_on = RTL_REG_ON_GPIO;
29
#if 0
30
module_param(gpio_wlan_reg_on, uint, 0644);
31
MODULE_PARM_DESC(gpio_wlan_reg_on, "wlan reg_on gpio num (default:gpio4_3)");
32
#endif
33
34
static int hi_gpio_set_value(u32 gpio, u32 value)
35
{
36
HI_S32 s32Status;
37
38
s32Status = HI_DRV_GPIO_SetDirBit(gpio, HI_DIR_OUT);
39
if (s32Status != HI_SUCCESS) {
40
pr_err("gpio(%d) HI_DRV_GPIO_SetDirBit HI_DIR_OUT failed\n",
41
gpio);
42
return -1;
43
}
44
45
s32Status = HI_DRV_GPIO_WriteBit(gpio, value);
46
if (s32Status != HI_SUCCESS) {
47
pr_err("gpio(%d) HI_DRV_GPIO_WriteBit value(%d) failed\n",
48
gpio, value);
49
return -1;
50
}
51
52
return 0;
53
}
54
55
static int hisi_wlan_set_carddetect(bool present)
56
{
57
u32 regval;
58
u32 mask;
59
60
61
#ifndef CONFIG_HISI_SDIO_ID
62
return;
63
#endif
64
pr_info("SDIO ID=%d\n", CONFIG_HISI_SDIO_ID);
65
#if (CONFIG_HISI_SDIO_ID == 1)
66
mask = 1;
67
#elif (CONFIG_HISI_SDIO_ID == 0)
68
mask = 2;
69
#endif
70
71
regval = readl(REG_BASE_CTRL);
72
if (present) {
73
pr_info("====== Card detection to detect SDIO card! ======\n");
74
/* set card_detect low to detect card */
75
regval |= mask;
76
} else {
77
pr_info("====== Card detection to remove SDIO card! ======\n");
78
/* set card_detect high to remove card */
79
regval &= ~(mask);
80
}
81
writel(regval, REG_BASE_CTRL);
82
83
return 0;
84
}
85
86
/*
87
* Return:
88
* 0: power on successfully
89
* others: power on failed
90
*/
91
int platform_wifi_power_on(void)
92
{
93
int ret = 0;
94
95
96
hi_gpio_set_value(gpio_wlan_reg_on, 1);
97
mdelay(100);
98
hisi_wlan_set_carddetect(1);
99
mdelay(2000);
100
pr_info("======== set_carddetect delay 2s! ========\n");
101
102
return ret;
103
}
104
105
void platform_wifi_power_off(void)
106
{
107
hisi_wlan_set_carddetect(0);
108
mdelay(100);
109
hi_gpio_set_value(gpio_wlan_reg_on, 0);
110
}
111
112