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