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 <rtl8723d_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 /*CONFIG_RF_SHADOW_RW*/
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
62 *
63 * Output: NONE
64 *
65 * Return: NONE
66 *
67 * Note: For RF type 0222D
68 *---------------------------------------------------------------------------*/
69 void
PHY_RF6052SetBandwidth8723D(PADAPTER padapter,enum channel_width Bandwidth)70 PHY_RF6052SetBandwidth8723D(
71 PADAPTER padapter,
72 enum channel_width Bandwidth) /* 20M or 40M */
73 {
74 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
75
76 switch (Bandwidth) {
77 case CHANNEL_WIDTH_20:
78 /*
79 RF_A_reg 0x18[11:10]=2'b11
80 RF_A_reg 0x18[9:0]
81 */
82 pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff) | BIT(10) | BIT(11));
83 phy_set_rf_reg(padapter, RF_PATH_A, 0x18, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]); /* RF TRX_BW */
84 break;
85 case CHANNEL_WIDTH_40:
86 /*
87 RF_A_reg 0x18[11:10]=2'b01
88 RF_A_reg 0x18[9:0]
89 */
90 pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff) | BIT(10));
91 phy_set_rf_reg(padapter, RF_PATH_A, 0x18, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]); /* RF TRX_BW */
92 break;
93 default:
94 break;
95 }
96 }
97
98 static int
phy_RF6052_Config_ParaFile(PADAPTER Adapter)99 phy_RF6052_Config_ParaFile(
100 PADAPTER Adapter
101 )
102 {
103 u32 u4RegValue = 0;
104 enum rf_path eRFPath;
105 BB_REGISTER_DEFINITION_T *pPhyReg;
106
107 int rtStatus = _SUCCESS;
108 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
109 struct hal_spec_t *hal_spec = GET_HAL_SPEC(Adapter);
110
111 /* 3//----------------------------------------------------------------- */
112 /* 3// <2> Initialize RF */
113 /* 3//----------------------------------------------------------------- */
114 for (eRFPath = RF_PATH_A; eRFPath < hal_spec->rf_reg_path_num; eRFPath++) {
115
116 pPhyReg = &pHalData->PHYRegDef[eRFPath];
117
118 /*----Store original RFENV control type----*/
119 switch (eRFPath) {
120 case RF_PATH_A:
121 case RF_PATH_C:
122 u4RegValue = phy_query_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV);
123 break;
124 case RF_PATH_B:
125 case RF_PATH_D:
126 u4RegValue = phy_query_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV << 16);
127 break;
128 default:
129 RTW_ERR("Invalid rf_path:%d\n", eRFPath);
130 break;
131 }
132
133 /*----Set RF_ENV enable----*/
134 phy_set_bb_reg(Adapter, pPhyReg->rfintfe, bRFSI_RFENV << 16, 0x1);
135 rtw_udelay_os(1);/* PlatformStallExecution(1); */
136
137 /*----Set RF_ENV output high----*/
138 phy_set_bb_reg(Adapter, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
139 rtw_udelay_os(1);/* PlatformStallExecution(1); */
140
141 /* Set bit number of Address and Data for RF register */
142 phy_set_bb_reg(Adapter, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); /* Set 1 to 4 bits for 8255 */
143 rtw_udelay_os(1);/* PlatformStallExecution(1); */
144
145 phy_set_bb_reg(Adapter, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); /* Set 0 to 12 bits for 8255 */
146 rtw_udelay_os(1);/* PlatformStallExecution(1); */
147
148 /*----Initialize RF fom connfiguration file----*/
149 switch (eRFPath) {
150 case RF_PATH_A:
151 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
152 if (PHY_ConfigRFWithParaFile(Adapter, PHY_FILE_RADIO_A, eRFPath) == _FAIL)
153 #endif
154 {
155 #ifdef CONFIG_EMBEDDED_FWIMG
156 if (odm_config_rf_with_header_file(&pHalData->odmpriv, CONFIG_RF_RADIO, eRFPath) == HAL_STATUS_FAILURE)
157 rtStatus = _FAIL;
158 #endif
159 }
160 break;
161 case RF_PATH_B:
162 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
163 if (PHY_ConfigRFWithParaFile(Adapter, PHY_FILE_RADIO_B, eRFPath) == _FAIL)
164 #endif
165 {
166 #ifdef CONFIG_EMBEDDED_FWIMG
167 if (odm_config_rf_with_header_file(&pHalData->odmpriv, CONFIG_RF_RADIO, eRFPath) == HAL_STATUS_FAILURE)
168 rtStatus = _FAIL;
169 #endif
170 }
171 break;
172 case RF_PATH_C:
173 break;
174 case RF_PATH_D:
175 break;
176 default:
177 RTW_ERR("Invalid rf_path:%d\n", eRFPath);
178 break;
179 }
180
181 /*----Restore RFENV control type----*/;
182 switch (eRFPath) {
183 case RF_PATH_A:
184 case RF_PATH_C:
185 phy_set_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue);
186 break;
187 case RF_PATH_B:
188 case RF_PATH_D:
189 phy_set_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV << 16, u4RegValue);
190 break;
191 default:
192 RTW_ERR("Invalid rf_path:%d\n", eRFPath);
193 break;
194 }
195
196 if (rtStatus != _SUCCESS) {
197 goto phy_RF6052_Config_ParaFile_Fail;
198 }
199
200 }
201
202 /* 3 ----------------------------------------------------------------- */
203 /* 3 Configuration of Tx Power Tracking */
204 /* 3 ----------------------------------------------------------------- */
205
206 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
207 if (PHY_ConfigRFWithTxPwrTrackParaFile(Adapter, PHY_FILE_TXPWR_TRACK) == _FAIL)
208 #endif
209 {
210 #ifdef CONFIG_EMBEDDED_FWIMG
211 odm_config_rf_with_tx_pwr_track_header_file(&pHalData->odmpriv);
212 #endif
213 }
214
215 return rtStatus;
216
217 phy_RF6052_Config_ParaFile_Fail:
218 return rtStatus;
219 }
220
221
222 int
PHY_RF6052_Config8723D(PADAPTER Adapter)223 PHY_RF6052_Config8723D(
224 PADAPTER Adapter)
225 {
226 int rtStatus = _SUCCESS;
227
228 /* */
229 /* Config BB and RF */
230 /* */
231 rtStatus = phy_RF6052_Config_ParaFile(Adapter);
232 return rtStatus;
233 }
234
235 /* End of HalRf6052.c */
236