xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8188fu/hal/rtl8188f/rtl8188f_dm.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 _RTL8188F_DM_C_
23 
24 /*============================================================ */
25 /* include files */
26 /*============================================================ */
27 #include <rtl8188f_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", __func__, 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, 0xff000fa0);/* 0x306:Rx, 0x307:Tx */
130 			pHalData->bInterruptMigration = IntMtToSet;
131 		} else {
132 			/* Reset all interrupt migration settings. */
133 			rtw_write32(Adapter, REG_INT_MIG, 0);
134 			pHalData->bInterruptMigration = IntMtToSet;
135 		}
136 	}
137 
138 #if 0 /* mask */
139 	if (bCurrentACIntDisable != ACIntToSet) {
140 		RTW_INFO("%s(): Update AC interrupt(%d)\n", __func__, ACIntToSet);
141 		if (ACIntToSet) { /* Disable four ACs interrupts. */
142 			/* */
143 			/* <Roger_Notes> Disable VO, VI, BE and BK four AC interrupts to gain more efficient CPU utilization. */
144 			/* When extremely highly Rx OK occurs, we will disable Tx interrupts. */
145 			/* 2010.03.05. */
146 			/* */
147 			UpdateInterruptMask8192CE(Adapter, 0, RT_AC_INT_MASKS);
148 			pHalData->bDisableTxInt = ACIntToSet;
149 		} else { /* Enable four ACs interrupts. */
150 			UpdateInterruptMask8192CE(Adapter, RT_AC_INT_MASKS, 0);
151 			pHalData->bDisableTxInt = ACIntToSet;
152 		}
153 	}
154 #endif
155 
156 }
157 
158 #endif
159 
160 /* */
161 /* Initialize GPIO setting registers */
162 /* */
163 #ifdef CONFIG_USB_HCI
164 static void
dm_InitGPIOSetting(PADAPTER Adapter)165 dm_InitGPIOSetting(
166 		PADAPTER	Adapter
167 )
168 {
169 	PHAL_DATA_TYPE		pHalData = GET_HAL_DATA(Adapter);
170 
171 	u8	tmp1byte;
172 
173 	tmp1byte = rtw_read8(Adapter, REG_GPIO_MUXCFG);
174 	tmp1byte &= (GPIOSEL_GPIO | ~GPIOSEL_ENBT);
175 
176 	rtw_write8(Adapter, REG_GPIO_MUXCFG, tmp1byte);
177 }
178 #endif
179 /*============================================================ */
180 /* functions */
181 /*============================================================ */
Init_ODM_ComInfo_8188f(PADAPTER Adapter)182 static void Init_ODM_ComInfo_8188f(PADAPTER	Adapter)
183 {
184 	PHAL_DATA_TYPE	pHalData = GET_HAL_DATA(Adapter);
185 	struct dm_struct		*pDM_Odm = &(pHalData->odmpriv);
186 	u8	cut_ver, fab_ver;
187 
188 	Init_ODM_ComInfo(Adapter);
189 
190 	odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_PACKAGE_TYPE, pHalData->PackageType);
191 
192 	fab_ver = ODM_TSMC;
193 	cut_ver = GET_CVID_CUT_VERSION(pHalData->version_id);
194 
195 	RTW_INFO("%s(): Fv=%d Cv=%d\n", __func__, fab_ver, cut_ver);
196 	odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_FAB_VER, fab_ver);
197 	odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_CUT_VER, cut_ver);
198 }
199 
200 void
rtl8188f_InitHalDm(PADAPTER Adapter)201 rtl8188f_InitHalDm(
202 		PADAPTER	Adapter
203 )
204 {
205 	PHAL_DATA_TYPE	pHalData = GET_HAL_DATA(Adapter);
206 	struct dm_struct		*pDM_Odm = &(pHalData->odmpriv);
207 
208 #ifdef CONFIG_USB_HCI
209 	dm_InitGPIOSetting(Adapter);
210 #endif
211 	rtw_phydm_init(Adapter);
212 }
213 
214 
215 void
rtl8188f_HalDmWatchDog(PADAPTER Adapter)216 rtl8188f_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 (Adapter->registrypriv.mp_mode == 1 && Adapter->mppriv.mp_dm == 0) /* for MP power tracking */
228 		return;
229 #endif
230 
231 	if (!rtw_is_hw_init_completed(Adapter))
232 		goto skip_dm;
233 
234 #ifdef CONFIG_LPS
235 	bFwCurrentInPSMode = pwrpriv->bFwCurrentInPSMode;
236 	rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, &bFwPSAwake);
237 #endif
238 
239 #ifdef CONFIG_P2P
240 	/* Fw is under p2p powersaving mode, driver should stop dynamic mechanism. */
241 	/* modifed by thomas. 2011.06.11. */
242 	if (Adapter->wdinfo.p2p_ps_mode)
243 		bFwPSAwake = _FALSE;
244 #endif /*CONFIG_P2P */
245 
246 	if ((rtw_is_hw_init_completed(Adapter))
247 	    && ((!bFwCurrentInPSMode) && bFwPSAwake)) {
248 
249 		rtw_hal_check_rxfifo_full(Adapter);
250 		/* */
251 		/* Dynamically switch RTS/CTS protection. */
252 		/* */
253 
254 #ifdef CONFIG_PCI_HCI
255 		/* 20100630 Joseph: Disable Interrupt Migration mechanism temporarily because it degrades Rx throughput. */
256 		/* Tx Migration settings. */
257 		/*dm_InterruptMigration(Adapter); */
258 
259 		/*if(Adapter->HalFunc.TxCheckStuckHandler(Adapter)) */
260 		/*	PlatformScheduleWorkItem(&(GET_HAL_DATA(Adapter)->HalResetWorkItem)); */
261 #endif
262 	}
263 
264 #ifdef CONFIG_DISABLE_ODM
265 	goto skip_dm;
266 #endif
267 
268 #ifdef CONFIG_LPS
269 	if (pwrpriv->bLeisurePs && bFwCurrentInPSMode && pwrpriv->pwr_mode != PS_MODE_ACTIVE)
270 		in_lps = _TRUE;
271 #endif
272 
273 	rtw_phydm_watchdog(Adapter, in_lps);
274 
275 skip_dm:
276 
277 	/* Check GPIO to determine current RF on/off and Pbc status. */
278 	/* Check Hardware Radio ON/OFF or not */
279 	/*if(Adapter->MgntInfo.PowerSaveControl.bGpioRfSw) */
280 	/*{ */
281 	/*RTPRINT(FPWR, PWRHW, ("dm_CheckRfCtrlGPIO\n")); */
282 	/*	dm_CheckRfCtrlGPIO(Adapter); */
283 	/*} */
284 #ifdef CONFIG_SUPPORT_HW_WPS_PBC
285 	dm_CheckPbcGPIO(Adapter);
286 #endif
287 	return;
288 }
289 
rtl8188f_init_dm_priv(PADAPTER Adapter)290 void rtl8188f_init_dm_priv(PADAPTER Adapter)
291 {
292 	PHAL_DATA_TYPE	pHalData = GET_HAL_DATA(Adapter);
293 	struct dm_struct		*podmpriv = &pHalData->odmpriv;
294 	Init_ODM_ComInfo_8188f(Adapter);
295 	odm_init_all_timers(podmpriv);
296 
297 }
298 
rtl8188f_deinit_dm_priv(PADAPTER Adapter)299 void rtl8188f_deinit_dm_priv(PADAPTER Adapter)
300 {
301 	PHAL_DATA_TYPE	pHalData = GET_HAL_DATA(Adapter);
302 	struct dm_struct		*podmpriv = &pHalData->odmpriv;
303 
304 	odm_cancel_all_timers(podmpriv);
305 
306 }
307