hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/******************************************************************************
 *
 * Copyright(c) 2015 - 2019 Realtek Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License 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.
 *
 *****************************************************************************/
#define _RTL8822BS_HALINIT_C_
 
#include <drv_types.h>        /* PADAPTER, basic_types.h and etc. */
#include <hal_data.h>        /* HAL_DATA_TYPE */
#include "../../hal_halmac.h"    /* rtw_halmac_query_tx_page_num() */
#include "../rtl8822b.h"    /* rtl8822b_hal_init(), rtl8822b_phy_init_haldm() and etc. */
 
 
#ifdef CONFIG_FWLPS_IN_IPS
static u8 fw_ips_leave(struct _ADAPTER *a)
{
   struct sreset_priv *psrtpriv = &GET_HAL_DATA(a)->srestpriv;
   struct debug_priv *pdbgpriv = &adapter_to_dvobj(a)->drv_dbg;
   struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(a);
   systime start_time;
   u8 cpwm_orig, cpwm_now, rpwm;
   u8 bMacPwrCtrlOn = _TRUE;
 
 
   if ((pwrctl->bips_processing == _FALSE)
       || (psrtpriv->silent_reset_inprogress == _TRUE)
       || (GET_HAL_DATA(a)->bFWReady == _FALSE)
       || (pwrctl->pre_ips_type != 0))
       return _FAIL;
 
   RTW_INFO("%s: Leaving FW_IPS\n", __func__);
 
   /* for polling cpwm */
   cpwm_orig = 0;
   rtw_hal_get_hwreg(a, HW_VAR_CPWM, &cpwm_orig);
 
   /* set rpwm */
#if 1
   rtw_hal_get_hwreg(a, HW_VAR_RPWM_TOG, &rpwm);
   rpwm += 0x80;
#else
   rpwm = pwrctl->tog;
#endif
   rpwm |= PS_ACK;
   rtw_hal_set_hwreg(a, HW_VAR_SET_RPWM, (u8 *)(&rpwm));
   RTW_INFO("%s: write rpwm=%02x\n", __FUNCTION__, rpwm);
 
   pwrctl->tog = (rpwm + 0x80) & 0x80;
 
   /* do polling cpwm */
   start_time = rtw_get_current_time();
   do {
       rtw_mdelay_os(1);
 
       rtw_hal_get_hwreg(a, HW_VAR_CPWM, &cpwm_now);
       if ((cpwm_orig ^ cpwm_now) & 0x80) {
#ifdef DBG_CHECK_FW_PS_STATE
           RTW_INFO("%s: polling cpwm ok when leaving IPS in FWLPS state,"
                " cost %d ms,"
                " cpwm_orig=0x%02x, cpwm_now=0x%02x, 0x100=0x%x\n",
                __FUNCTION__,
                rtw_get_passing_time_ms(start_time),
                cpwm_orig, cpwm_now, rtw_read8(a, REG_CR_8822B));
#endif /* DBG_CHECK_FW_PS_STATE */
           break;
       }
 
       if (rtw_get_passing_time_ms(start_time) > 100) {
           RTW_ERR("%s: polling cpwm timeout when leaving IPS in FWLPS state\n", __FUNCTION__);
           break;
       }
   } while (1);
 
   rtl8822b_set_FwPwrModeInIPS_cmd(a, 0);
 
   rtw_hal_set_hwreg(a, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
 
#ifdef DBG_CHECK_FW_PS_STATE
   if (rtw_fw_ps_state(a) == _FAIL) {
       RTW_INFO("after hal init, fw ps state in 32k\n");
       pdbgpriv->dbg_ips_drvopen_fail_cnt++;
   }
#endif /* DBG_CHECK_FW_PS_STATE */
 
   return _SUCCESS;
}
 
static u8 fw_ips_enter(struct _ADAPTER *a)
{
   struct sreset_priv *psrtpriv = &GET_HAL_DATA(a)->srestpriv;
   struct debug_priv *pdbgpriv = &adapter_to_dvobj(a)->drv_dbg;
   struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(a);
   systime start_time;
   int cnt = 0;
   u8 val8 = 0, rpwm;
 
 
   if ((pwrctl->bips_processing == _FALSE)
       || (psrtpriv->silent_reset_inprogress == _TRUE)
       || (GET_HAL_DATA(a)->bFWReady == _FALSE)
       || (a->netif_up == _FALSE)) {
       pdbgpriv->dbg_carddisable_cnt++;
       pwrctl->pre_ips_type = 1;
 
       return _FAIL;
   }
 
   RTW_INFO("%s: issue H2C to FW when entering IPS\n", __FUNCTION__);
   rtl8822b_set_FwPwrModeInIPS_cmd(a, 0x1);
 
   /*
    * poll 0x1cc to make sure H2C command already finished by FW;
    * MAC_0x1cc=0 means H2C done by FW.
    */
   start_time = rtw_get_current_time();
   do {
       rtw_mdelay_os(10);
       val8 = rtw_read8(a, REG_HMETFR_8822B);
       cnt++;
       if (!val8)
           break;
 
       if (rtw_get_passing_time_ms(start_time) > 100) {
           RTW_ERR("%s: fail to wait H2C, REG_HMETFR=0x%x, cnt=%d\n",
               __FUNCTION__, val8, cnt);
#ifdef DBG_CHECK_FW_PS_STATE
           RTW_WARN("MAC_1C0=0x%08x, MAC_1C4=0x%08x, MAC_1C8=0x%08x, MAC_1CC=0x%08x\n",
                rtw_read32(a, 0x1c0), rtw_read32(a, 0x1c4),
                rtw_read32(a, 0x1c8), rtw_read32(a, REG_HMETFR_8822B));
#endif /* DBG_CHECK_FW_PS_STATE */
           goto exit;
       }
   } while (1);
 
   /* H2C done, enter 32k */
   /* set rpwm to enter 32k */
#if 1
   rtw_hal_get_hwreg(a, HW_VAR_RPWM_TOG, &rpwm);
   rpwm += 0x80;
#else
   rpwm = pwrctl->tog;
#endif
   rpwm |= PS_STATE_S0;
   rtw_hal_set_hwreg(a, HW_VAR_SET_RPWM, &rpwm);
   RTW_INFO("%s: write rpwm=%02x\n", __FUNCTION__, rpwm);
   pwrctl->tog = (rpwm + 0x80) & 0x80;
 
   cnt = val8 = 0;
   start_time = rtw_get_current_time();
   do {
       val8 = rtw_read8(a, REG_CR_8822B);
       cnt++;
       RTW_INFO("%s: polling 0x100=0x%x, cnt=%d\n",
            __FUNCTION__, val8, cnt);
       if (val8 == 0xEA) {
           RTW_INFO("%s: polling 0x100=0xEA, cnt=%d, cost %d ms\n",
                __FUNCTION__, cnt,
                rtw_get_passing_time_ms(start_time));
           break;
       }
 
       if (rtw_get_passing_time_ms(start_time) > 100) {
           RTW_ERR("%s: polling polling 0x100=0xEA timeout! cnt=%d\n",
               __FUNCTION__, cnt);
#ifdef DBG_CHECK_FW_PS_STATE
           RTW_WARN("MAC_1C0=0x%08x, MAC_1C4=0x%08x, MAC_1C8=0x%08x, MAC_1CC=0x%08x\n",
                rtw_read32(a, 0x1c0), rtw_read32(a, 0x1c4),
                rtw_read32(a, 0x1c8), rtw_read32(a, REG_HMETFR_8822B));
#endif /* DBG_CHECK_FW_PS_STATE */
           break;
       }
 
       rtw_mdelay_os(10);
   } while (1);
 
exit:
   RTW_INFO("polling done when entering IPS, check result: 0x100=0x%02x, cnt=%d, MAC_1cc=0x%02x\n",
        rtw_read8(a, REG_CR_8822B), cnt, rtw_read8(a, REG_HMETFR_8822B));
 
   pwrctl->pre_ips_type = 0;
 
   return _SUCCESS;
}
#endif /* CONFIG_FWLPS_IN_IPS */
 
u32 rtl8822bs_init(PADAPTER adapter)
{
   u8 ok = _TRUE;
   PHAL_DATA_TYPE hal;
 
 
   hal = GET_HAL_DATA(adapter);
 
#ifdef CONFIG_FWLPS_IN_IPS
   if (fw_ips_leave(adapter) == _SUCCESS)
       return _SUCCESS;
#endif
   ok = rtl8822b_hal_init(adapter);
   if (_FALSE == ok)
       return _FAIL;
 
   rtw_halmac_query_tx_page_num(adapter_to_dvobj(adapter));
 
   rtl8822b_mac_verify(adapter);
 
   rtl8822b_phy_init_haldm(adapter);
#ifdef CONFIG_BEAMFORMING
   rtl8822b_phy_bf_init(adapter);
#endif
 
#ifdef CONFIG_FW_MULTI_PORT_SUPPORT
   /*HW /FW init*/
   rtw_hal_set_default_port_id_cmd(adapter, 0);
#endif
 
#ifdef CONFIG_BT_COEXIST
   /* Init BT hw config. */
   if (hal->EEPROMBluetoothCoexist == _TRUE) {
       rtw_btcoex_HAL_Initialize(adapter, _FALSE);
       #ifdef CONFIG_FW_MULTI_PORT_SUPPORT
       rtw_hal_set_wifi_btc_port_id_cmd(adapter);
       #endif
   } else
#endif /* CONFIG_BT_COEXIST */
       rtw_btcoex_wifionly_hw_config(adapter);
 
   rtl8822b_init_misc(adapter);
 
   return _SUCCESS;
}
 
u32 rtl8822bs_deinit(PADAPTER adapter)
{
#ifdef CONFIG_FWLPS_IN_IPS
   if (fw_ips_enter(adapter) == _SUCCESS)
       return _SUCCESS;
#endif
 
   return rtl8822b_deinit(adapter);
}
 
void rtl8822bs_init_default_value(PADAPTER adapter)
{
   PHAL_DATA_TYPE hal;
 
 
   hal = GET_HAL_DATA(adapter);
 
   rtl8822b_init_default_value(adapter);
 
   /* interface related variable */
   hal->SdioRxFIFOCnt = 0;
}