1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2017 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 /* ************************************************************
16 * Description:
17 *
18 * This file is for 92CE/92CU dynamic mechanism only
19 *
20 *
21 * ************************************************************ */
22 #define _RTL8723D_DM_C_
23
24 /* ************************************************************
25 * include files
26 * ************************************************************ */
27 #include <rtl8723d_hal.h>
28
29 /* ************************************************************
30 * Global var
31 * ************************************************************ */
32 #ifdef CONFIG_SUPPORT_HW_WPS_PBC
dm_CheckPbcGPIO(_adapter * padapter)33 static void dm_CheckPbcGPIO(_adapter *padapter)
34 {
35 u8 tmp1byte;
36 u8 bPbcPressed = _FALSE;
37
38 if (!padapter->registrypriv.hw_wps_pbc)
39 return;
40
41 #ifdef CONFIG_USB_HCI
42 tmp1byte = rtw_read8(padapter, GPIO_IO_SEL);
43 tmp1byte |= (HAL_8192C_HW_GPIO_WPS_BIT);
44 rtw_write8(padapter, GPIO_IO_SEL, tmp1byte); /* enable GPIO[2] as output mode */
45
46 tmp1byte &= ~(HAL_8192C_HW_GPIO_WPS_BIT);
47 rtw_write8(padapter, GPIO_IN, tmp1byte); /* reset the floating voltage level */
48
49 tmp1byte = rtw_read8(padapter, GPIO_IO_SEL);
50 tmp1byte &= ~(HAL_8192C_HW_GPIO_WPS_BIT);
51 rtw_write8(padapter, GPIO_IO_SEL, tmp1byte); /* enable GPIO[2] as input mode */
52
53 tmp1byte = rtw_read8(padapter, GPIO_IN);
54
55 if (tmp1byte == 0xff)
56 return;
57
58 if (tmp1byte & HAL_8192C_HW_GPIO_WPS_BIT)
59 bPbcPressed = _TRUE;
60 #else
61 tmp1byte = rtw_read8(padapter, GPIO_IN);
62
63 if (tmp1byte == 0xff || padapter->init_adpt_in_progress)
64 return;
65
66 if ((tmp1byte & HAL_8192C_HW_GPIO_WPS_BIT) == 0)
67 bPbcPressed = _TRUE;
68 #endif
69
70 if (_TRUE == bPbcPressed) {
71 /* Here we only set bPbcPressed to true */
72 /* After trigger PBC, the variable will be set to false */
73 RTW_INFO("CheckPbcGPIO - PBC is pressed\n");
74 rtw_request_wps_pbc_event(padapter);
75 }
76 }
77 #endif /* #ifdef CONFIG_SUPPORT_HW_WPS_PBC */
78
79
80 #ifdef CONFIG_PCI_HCI
81 /*
82 * Description:
83 * Perform interrupt migration dynamically to reduce CPU utilization.
84 *
85 * Assumption:
86 * 1. Do not enable migration under WIFI test.
87 *
88 * Created by Roger, 2010.03.05.
89 * */
90 void
dm_InterruptMigration(PADAPTER Adapter)91 dm_InterruptMigration(
92 PADAPTER Adapter
93 )
94 {
95 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
96 struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
97 BOOLEAN bCurrentIntMt, bCurrentACIntDisable;
98 BOOLEAN IntMtToSet = _FALSE;
99 BOOLEAN ACIntToSet = _FALSE;
100
101
102 /* Retrieve current interrupt migration and Tx four ACs IMR settings first. */
103 bCurrentIntMt = pHalData->bInterruptMigration;
104 bCurrentACIntDisable = pHalData->bDisableTxInt;
105
106 /* */
107 /* <Roger_Notes> Currently we use busy traffic for reference instead of RxIntOK counts to prevent non-linear Rx statistics */
108 /* when interrupt migration is set before. 2010.03.05. */
109 /* */
110 if (!Adapter->registrypriv.wifi_spec &&
111 (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) &&
112 pmlmepriv->LinkDetectInfo.bHigherBusyTraffic) {
113 IntMtToSet = _TRUE;
114
115 /* To check whether we should disable Tx interrupt or not. */
116 if (pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic)
117 ACIntToSet = _TRUE;
118 }
119
120 /* Update current settings. */
121 if (bCurrentIntMt != IntMtToSet) {
122 RTW_INFO("%s(): Update interrupt migration(%d)\n", __FUNCTION__, IntMtToSet);
123 if (IntMtToSet) {
124 /* */
125 /* <Roger_Notes> Set interrupt migration timer and corresponging Tx/Rx counter. */
126 /* timer 25ns*0xfa0=100us for 0xf packets. */
127 /* 2010.03.05. */
128 /* */
129 rtw_write32(Adapter, REG_INT_MIG_8723D, 0xff000fa0);/* 0x306:Rx, 0x307:Tx */
130 pHalData->bInterruptMigration = IntMtToSet;
131 } else {
132 /* Reset all interrupt migration settings. */
133 rtw_write32(Adapter, REG_INT_MIG_8723D, 0);
134 pHalData->bInterruptMigration = IntMtToSet;
135 }
136 }
137
138 /*if( bCurrentACIntDisable != ACIntToSet ){
139 RTW_INFO("%s(): Update AC interrupt(%d)\n",__FUNCTION__,ACIntToSet);
140 if(ACIntToSet)
141 {
142
143
144
145
146
147 UpdateInterruptMask8192CE( Adapter, 0, RT_AC_INT_MASKS );
148 pHalData->bDisableTxInt = ACIntToSet;
149 }
150 else
151 {
152 UpdateInterruptMask8192CE( Adapter, RT_AC_INT_MASKS, 0 );
153 pHalData->bDisableTxInt = ACIntToSet;
154 }
155 }*/
156
157 }
158
159 #endif
160
161 /*
162 * Initialize GPIO setting registers
163 * */
164 #ifdef CONFIG_USB_HCI
165 static void
dm_InitGPIOSetting(PADAPTER Adapter)166 dm_InitGPIOSetting(
167 PADAPTER Adapter
168 )
169 {
170 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
171
172 u8 tmp1byte;
173
174 tmp1byte = rtw_read8(Adapter, REG_GPIO_MUXCFG);
175 tmp1byte &= (GPIOSEL_GPIO | ~GPIOSEL_ENBT);
176
177 rtw_write8(Adapter, REG_GPIO_MUXCFG, tmp1byte);
178 }
179 #endif
180 /* ************************************************************
181 * functions
182 * ************************************************************ */
Init_ODM_ComInfo_8723d(PADAPTER Adapter)183 static void Init_ODM_ComInfo_8723d(PADAPTER Adapter)
184 {
185 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
186 struct dm_struct *pDM_Odm = &(pHalData->odmpriv);
187 u8 cut_ver, fab_ver;
188
189 Init_ODM_ComInfo(Adapter);
190
191 odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_PACKAGE_TYPE, pHalData->PackageType);
192
193 fab_ver = ODM_TSMC;
194 cut_ver = GET_CVID_CUT_VERSION(pHalData->version_id);
195
196 RTW_INFO("%s(): Fv=%d Cv=%d\n", __func__, fab_ver, cut_ver);
197 odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_FAB_VER, fab_ver);
198 odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_CUT_VER, cut_ver);
199 }
200
201 void
rtl8723d_InitHalDm(PADAPTER Adapter)202 rtl8723d_InitHalDm(
203 PADAPTER Adapter
204 )
205 {
206 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
207 struct dm_struct *pDM_Odm = &(pHalData->odmpriv);
208
209 #ifdef CONFIG_USB_HCI
210 dm_InitGPIOSetting(Adapter);
211 #endif
212 rtw_phydm_init(Adapter);
213 }
214
215 void
rtl8723d_HalDmWatchDog(PADAPTER Adapter)216 rtl8723d_HalDmWatchDog(
217 PADAPTER Adapter
218 )
219 {
220 BOOLEAN bFwCurrentInPSMode = _FALSE;
221 u8 bFwPSAwake = _TRUE;
222 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
223 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(Adapter);
224 u8 in_lps = _FALSE;
225
226 #ifdef CONFIG_MP_INCLUDED
227 /* #if MP_DRIVER */
228 if (Adapter->registrypriv.mp_mode == 1 && Adapter->mppriv.mp_dm == 0) /* for MP power tracking */
229 return;
230 /* #endif */
231 #endif
232
233 if (!rtw_is_hw_init_completed(Adapter))
234 goto skip_dm;
235
236 #ifdef CONFIG_LPS
237 bFwCurrentInPSMode = pwrpriv->bFwCurrentInPSMode;
238 rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, &bFwPSAwake);
239 #endif
240
241 #ifdef CONFIG_P2P
242 /* Fw is under p2p powersaving mode, driver should stop dynamic mechanism. */
243 /* modifed by thomas. 2011.06.11. */
244 if (Adapter->wdinfo.p2p_ps_mode)
245 bFwPSAwake = _FALSE;
246 #endif /* CONFIG_P2P */
247
248
249 if ((rtw_is_hw_init_completed(Adapter))
250 && ((!bFwCurrentInPSMode) && bFwPSAwake)) {
251
252 rtw_hal_check_rxfifo_full(Adapter);
253 /* */
254 /* Dynamically switch RTS/CTS protection. */
255 /* */
256
257 #ifdef CONFIG_PCI_HCI
258 /* 20100630 Joseph: Disable Interrupt Migration mechanism temporarily because it degrades Rx throughput. */
259 /* Tx Migration settings. */
260 /* dm_InterruptMigration(Adapter); */
261
262 /* if(Adapter->HalFunc.TxCheckStuckHandler(Adapter)) */
263 /* PlatformScheduleWorkItem(&(GET_HAL_DATA(Adapter)->HalResetWorkItem)); */
264 #endif
265 }
266
267 #ifdef CONFIG_DISABLE_ODM
268 goto skip_dm;
269 #endif
270
271 #ifdef CONFIG_LPS
272 if (pwrpriv->bLeisurePs && bFwCurrentInPSMode && pwrpriv->pwr_mode != PS_MODE_ACTIVE)
273 in_lps = _TRUE;
274 #endif
275
276 rtw_phydm_watchdog(Adapter, in_lps);
277
278 skip_dm:
279
280 /* Check GPIO to determine current RF on/off and Pbc status. */
281 /* Check Hardware Radio ON/OFF or not */
282 /* if(Adapter->MgntInfo.PowerSaveControl.bGpioRfSw) */
283 /* { */
284 /* RTPRINT(FPWR, PWRHW, ("dm_CheckRfCtrlGPIO\n")); */
285 /* dm_CheckRfCtrlGPIO(Adapter); */
286 /* } */
287 #ifdef CONFIG_SUPPORT_HW_WPS_PBC
288 dm_CheckPbcGPIO(Adapter);
289 #endif
290 return;
291 }
292
rtl8723d_init_dm_priv(PADAPTER Adapter)293 void rtl8723d_init_dm_priv(PADAPTER Adapter)
294 {
295 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
296 struct dm_struct *podmpriv = &pHalData->odmpriv;
297
298 Init_ODM_ComInfo_8723d(Adapter);
299 odm_init_all_timers(podmpriv);
300
301 }
302
rtl8723d_deinit_dm_priv(PADAPTER Adapter)303 void rtl8723d_deinit_dm_priv(PADAPTER Adapter)
304 {
305 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
306 struct dm_struct *podmpriv = &pHalData->odmpriv;
307
308 odm_cancel_all_timers(podmpriv);
309
310 }
311