xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8723cs/hal/rtl8703b/rtl8703b_rf6052.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  *
17  *
18  * Module:	rtl8192c_rf6052.c	( Source C File)
19  *
20  * Note:	Provide RF 6052 series relative API.
21  *
22  * Function:
23  *
24  * Export:
25  *
26  * Abbrev:
27  *
28  * History:
29  * Data			Who		Remark
30  *
31  * 09/25/2008	MHC		Create initial version.
32  * 11/05/2008	MHC		Add API for tw power setting.
33  *
34  *
35 ******************************************************************************/
36 
37 #include <rtl8703b_hal.h>
38 
39 /*---------------------------Define Local Constant---------------------------*/
40 /*---------------------------Define Local Constant---------------------------*/
41 
42 
43 /*------------------------Define global variable-----------------------------*/
44 /*------------------------Define global variable-----------------------------*/
45 
46 
47 /*------------------------Define local variable------------------------------*/
48 #ifdef CONFIG_RF_SHADOW_RW
49 /* 2008/11/20 MH For Debug only, RF
50  * static	RF_SHADOW_T	RF_Shadow[RF6052_MAX_PATH][RF6052_MAX_REG] = {0}; */
51 static	RF_SHADOW_T	RF_Shadow[RF6052_MAX_PATH][RF6052_MAX_REG];
52 #endif
53 /*------------------------Define local variable------------------------------*/
54 
55 /*-----------------------------------------------------------------------------
56  * Function:    PHY_RF6052SetBandwidth()
57  *
58  * Overview:    This function is called by SetBWModeCallback8190Pci() only
59  *
60  * Input:       PADAPTER				Adapter
61  *			WIRELESS_BANDWIDTH_E	Bandwidth	//20M or 40M
62  *
63  * Output:      NONE
64  *
65  * Return:      NONE
66  *
67  * Note:		For RF type 0222D
68  *---------------------------------------------------------------------------*/
69 void
PHY_RF6052SetBandwidth8703B(PADAPTER Adapter,enum channel_width Bandwidth)70 PHY_RF6052SetBandwidth8703B(
71 		PADAPTER				Adapter,
72 		enum channel_width		Bandwidth)	/* 20M or 40M */
73 {
74 	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(Adapter);
75 
76 	switch (Bandwidth) {
77 	case CHANNEL_WIDTH_20:
78 		pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff) | BIT10 | BIT11);
79 		phy_set_rf_reg(Adapter, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]);
80 		phy_set_rf_reg(Adapter, RF_PATH_B, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]);
81 		break;
82 
83 	case CHANNEL_WIDTH_40:
84 		pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff) | BIT10);
85 		phy_set_rf_reg(Adapter, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]);
86 		phy_set_rf_reg(Adapter, RF_PATH_B, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]);
87 		break;
88 
89 	default:
90 		break;
91 	}
92 
93 }
94 
95 static int
phy_RF6052_Config_ParaFile(PADAPTER Adapter)96 phy_RF6052_Config_ParaFile(
97 		PADAPTER		Adapter
98 )
99 {
100 	u32					u4RegValue = 0;
101 	enum rf_path			eRFPath;
102 	BB_REGISTER_DEFINITION_T	*pPhyReg;
103 
104 	int					rtStatus = _SUCCESS;
105 	HAL_DATA_TYPE		*pHalData = GET_HAL_DATA(Adapter);
106 	struct hal_spec_t *hal_spec = GET_HAL_SPEC(Adapter);
107 
108 	/* 3 */ /* ----------------------------------------------------------------- */
109 	/* 3 */ /* <2> Initialize RF */
110 	/* 3 */ /* ----------------------------------------------------------------- */
111 	for (eRFPath = RF_PATH_A; eRFPath < hal_spec->rf_reg_path_num; eRFPath++) {
112 
113 		pPhyReg = &pHalData->PHYRegDef[eRFPath];
114 
115 		/*----Store original RFENV control type----*/
116 		switch (eRFPath) {
117 		case RF_PATH_A:
118 		case RF_PATH_C:
119 			u4RegValue = phy_query_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV);
120 			break;
121 		case RF_PATH_B:
122 		case RF_PATH_D:
123 			u4RegValue = phy_query_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV << 16);
124 			break;
125 		default:
126 			RTW_ERR("Invalid rf_path:%d\n", eRFPath);
127 			break;
128 		}
129 
130 		/*----Set RF_ENV enable----*/
131 		phy_set_bb_reg(Adapter, pPhyReg->rfintfe, bRFSI_RFENV << 16, 0x1);
132 		rtw_udelay_os(1);/* PlatformStallExecution(1); */
133 
134 		/*----Set RF_ENV output high----*/
135 		phy_set_bb_reg(Adapter, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
136 		rtw_udelay_os(1);/* PlatformStallExecution(1); */
137 
138 		/* Set bit number of Address and Data for RF register */
139 		phy_set_bb_reg(Adapter, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0);	/* Set 1 to 4 bits for 8255 */
140 		rtw_udelay_os(1);/* PlatformStallExecution(1); */
141 
142 		phy_set_bb_reg(Adapter, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0);	/* Set 0 to 12  bits for 8255 */
143 		rtw_udelay_os(1);/* PlatformStallExecution(1); */
144 
145 		/*----Initialize RF fom connfiguration file----*/
146 		switch (eRFPath) {
147 		case RF_PATH_A:
148 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
149 			if (PHY_ConfigRFWithParaFile(Adapter, PHY_FILE_RADIO_A, eRFPath) == _FAIL)
150 #endif
151 			{
152 #ifdef CONFIG_EMBEDDED_FWIMG
153 				if (odm_config_rf_with_header_file(&pHalData->odmpriv, CONFIG_RF_RADIO, eRFPath) == HAL_STATUS_FAILURE)
154 					rtStatus = _FAIL;
155 #endif
156 			}
157 			break;
158 		case RF_PATH_B:
159 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
160 			if (PHY_ConfigRFWithParaFile(Adapter, PHY_FILE_RADIO_B, eRFPath) == _FAIL)
161 #endif
162 			{
163 #ifdef CONFIG_EMBEDDED_FWIMG
164 				if (odm_config_rf_with_header_file(&pHalData->odmpriv, CONFIG_RF_RADIO, eRFPath) == HAL_STATUS_FAILURE)
165 					rtStatus = _FAIL;
166 #endif
167 			}
168 			break;
169 		case RF_PATH_C:
170 			break;
171 		case RF_PATH_D:
172 			break;
173 		default:
174 			RTW_ERR("Invalid rf_path:%d\n", eRFPath);
175 			break;
176 		}
177 
178 		/*----Restore RFENV control type----*/;
179 		switch (eRFPath) {
180 		case RF_PATH_A:
181 		case RF_PATH_C:
182 			phy_set_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue);
183 			break;
184 		case RF_PATH_B:
185 		case RF_PATH_D:
186 			phy_set_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV << 16, u4RegValue);
187 			break;
188 		default:
189 			RTW_ERR("Invalid rf_path:%d\n", eRFPath);
190 			break;
191 		}
192 
193 		if (rtStatus != _SUCCESS) {
194 			goto phy_RF6052_Config_ParaFile_Fail;
195 		}
196 
197 	}
198 
199 	/* 3 ----------------------------------------------------------------- */
200 	/* 3 Configuration of Tx Power Tracking */
201 	/* 3 ----------------------------------------------------------------- */
202 
203 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
204 	if (PHY_ConfigRFWithTxPwrTrackParaFile(Adapter, PHY_FILE_TXPWR_TRACK) == _FAIL)
205 #endif
206 	{
207 #ifdef CONFIG_EMBEDDED_FWIMG
208 		odm_config_rf_with_tx_pwr_track_header_file(&pHalData->odmpriv);
209 #endif
210 	}
211 
212 	return rtStatus;
213 
214 phy_RF6052_Config_ParaFile_Fail:
215 	return rtStatus;
216 }
217 
218 
219 int
PHY_RF6052_Config8703B(PADAPTER Adapter)220 PHY_RF6052_Config8703B(
221 		PADAPTER		Adapter)
222 {
223 	int					rtStatus = _SUCCESS;
224 
225 	/*  */
226 	/* Config BB and RF */
227 	/*  */
228 	rtStatus = phy_RF6052_Config_ParaFile(Adapter);
229 	return rtStatus;
230 }
231 
232 /* End of HalRf6052.c */
233