-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifi_pwr_on.c
176 lines (140 loc) · 3.95 KB
/
wifi_pwr_on.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* Copyright (C) 2019 MediaTek Inc.
*
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/module.h>
#include <linux/uaccess.h>
#include <linux/time.h>
#include <linux/delay.h>
#include <linux/string.h>
#include <linux/kthread.h>
#include "wifi_pwr_on.h"
MODULE_LICENSE("Dual BSD/GPL");
#define PFX "[WIFI-FW] "
#define WIFI_FW_LOG_DBG 3
#define WIFI_FW_LOG_INFO 2
#define WIFI_FW_LOG_WARN 1
#define WIFI_FW_LOG_ERR 0
uint32_t DbgLevel = WIFI_FW_LOG_DBG;
#define WIFI_DBG_FUNC(fmt, arg...) \
do { \
if (DbgLevel >= WIFI_FW_LOG_DBG) \
pr_info(PFX "%s[D]: " fmt, __func__, ##arg); \
} while (0)
#define WIFI_INFO_FUNC(fmt, arg...) \
do { \
if (DbgLevel >= WIFI_FW_LOG_INFO) \
pr_info(PFX "%s[I]: " fmt, __func__, ##arg); \
} while (0)
#define WIFI_INFO_FUNC_LIMITED(fmt, arg...) \
do { \
if (DbgLevel >= WIFI_FW_LOG_INFO) \
pr_info_ratelimited(PFX "%s[L]: " fmt, __func__, ##arg); \
} while (0)
#define WIFI_WARN_FUNC(fmt, arg...) \
do { \
if (DbgLevel >= WIFI_FW_LOG_WARN) \
pr_info(PFX "%s[W]: " fmt, __func__, ##arg); \
} while (0)
#define WIFI_ERR_FUNC(fmt, arg...) \
do { \
if (DbgLevel >= WIFI_FW_LOG_ERR) \
pr_info(PFX "%s[E]: " fmt, __func__, ##arg); \
} while (0)
wlan_probe_cb mtk_wlan_probe_function;
wlan_remove_cb mtk_wlan_remove_function;
struct completion wlan_pendComp;
int g_opId;
int g_data;
static int mtk_wland_thread(void *pvData);
int wifi_pwr_on_init(void)
{
int result = 0;
init_completion(&wlan_pendComp);
WIFI_INFO_FUNC("Do wifi_pwr_on_init.\n");
return result;
}
EXPORT_SYMBOL(wifi_pwr_on_init);
int wifi_pwr_on_deinit(void)
{
return 0;
}
EXPORT_SYMBOL(wifi_pwr_on_deinit);
int mtk_wcn_wlan_reg(struct MTK_WCN_WLAN_CB_INFO *pWlanCbInfo)
{
if (!pWlanCbInfo) {
WIFI_ERR_FUNC("wlan cb info in null!\n");
return -1;
}
WIFI_INFO_FUNC("wmt wlan cb register\n");
mtk_wlan_probe_function = pWlanCbInfo->wlan_probe_cb;
mtk_wlan_remove_function = pWlanCbInfo->wlan_remove_cb;
return 0;
}
EXPORT_SYMBOL(mtk_wcn_wlan_reg);
int mtk_wcn_wlan_unreg(void)
{
WIFI_INFO_FUNC("wmt wlan cb unregister\n");
mtk_wlan_probe_function = NULL;
mtk_wlan_remove_function = NULL;
return 0;
}
EXPORT_SYMBOL(mtk_wcn_wlan_unreg);
static int mtk_wland_thread(void *pvData)
{
g_data = -1;
switch (g_opId) {
case WLAN_OPID_FUNC_ON:
if (mtk_wlan_probe_function != NULL) {
g_data = (*mtk_wlan_probe_function)();
} else {
WIFI_ERR_FUNC("Invalid pointer\n");
complete(&wlan_pendComp);
}
break;
case WLAN_OPID_FUNC_OFF:
if (mtk_wlan_remove_function != NULL) {
g_data = (*mtk_wlan_remove_function)();
} else {
WIFI_ERR_FUNC("Invalid pointer\n");
complete(&wlan_pendComp);
}
break;
default:
WIFI_ERR_FUNC("Unknown opid\n");
break;
}
complete(&wlan_pendComp);
return 0;
}
struct task_struct *wland_thread;
static int data;
#define WIFI_PWR_ON_TIMEOUT 4000
int mtk_wcn_wlan_func_ctrl(enum ENUM_WLAN_OPID opId)
{
bool bRet = MTK_WCN_BOOL_TRUE;
uint32_t waitRet = 0;
g_opId = opId;
wland_thread = kthread_run(mtk_wland_thread, &data, "wland_thread");
waitRet = wait_for_completion_timeout(&wlan_pendComp, MSEC_TO_JIFFIES(WIFI_PWR_ON_TIMEOUT));
if (waitRet > 0) {
/* Case 1: No timeout. */
if (g_data != 0)
bRet = MTK_WCN_BOOL_FALSE;
} else {
/* Case 2: timeout */
WIFI_ERR_FUNC("WiFi on/off takes more than 4 seconds\n");
bRet = MTK_WCN_BOOL_FALSE;
}
return bRet;
}
EXPORT_SYMBOL(mtk_wcn_wlan_func_ctrl);