blob: d733fb2ade9169d4b7e9759f68ec76efe90f7442 [file] [log] [blame]
Jerry Chuang8fc85982009-11-03 07:17:11 -02001/*
Gavin Thomas Claugus64b389c2015-12-10 21:35:35 -05002* This is part of the rtl8192 driver
3* released under the GPL (See file COPYING for details).
4*
5* This files contains programming code for the rtl8256
6* radio frontend.
7*
8* *Many* thanks to Realtek Corp. for their great support!
Jerry Chuang8fc85982009-11-03 07:17:11 -02009*/
10
11#include "r8192U.h"
12#include "r8192U_hw.h"
13#include "r819xU_phyreg.h"
14#include "r819xU_phy.h"
15#include "r8190_rtl8256.h"
16
17/*--------------------------------------------------------------------------
Sebastian Hahn35997ff2012-12-05 21:40:18 +010018 * Overview: set RF band width (20M or 40M)
Jerry Chuang8fc85982009-11-03 07:17:11 -020019 * Input: struct net_device* dev
Sebastian Hahn35997ff2012-12-05 21:40:18 +010020 * WIRELESS_BANDWIDTH_E Bandwidth //20M or 40M
Jerry Chuang8fc85982009-11-03 07:17:11 -020021 * Output: NONE
22 * Return: NONE
23 * Note: 8226 support both 20M and 40 MHz
Gavin Thomas Claugus64b389c2015-12-10 21:35:35 -050024 *--------------------------------------------------------------------------
25 */
Mohammad Jamal683a6862014-12-16 21:57:44 +053026void PHY_SetRF8256Bandwidth(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth)
Jerry Chuang8fc85982009-11-03 07:17:11 -020027{
28 u8 eRFPath;
29 struct r8192_priv *priv = ieee80211_priv(dev);
30
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +053031 /* for(eRFPath = RF90_PATH_A; eRFPath <pHalData->NumTotalRFPath;
32 * eRFPath++)
33 */
34 for (eRFPath = 0; eRFPath < RF90_PATH_MAX; eRFPath++) {
Jerry Chuang8fc85982009-11-03 07:17:11 -020035 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
Loïc Pellegrinoa8d0df22014-04-06 14:03:39 +010036 continue;
Jerry Chuang8fc85982009-11-03 07:17:11 -020037
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +053038 switch (Bandwidth) {
39 case HT_CHANNEL_WIDTH_20:
40 if (priv->card_8192_version == VERSION_819xU_A
41 || priv->card_8192_version
42 == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */
43 rtl8192_phy_SetRFReg(dev,
44 (RF90_RADIO_PATH_E)eRFPath,
45 0x0b, bMask12Bits, 0x100); /* phy para:1ba */
46 rtl8192_phy_SetRFReg(dev,
47 (RF90_RADIO_PATH_E)eRFPath,
48 0x2c, bMask12Bits, 0x3d7);
49 rtl8192_phy_SetRFReg(dev,
50 (RF90_RADIO_PATH_E)eRFPath,
51 0x0e, bMask12Bits, 0x021);
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +053052 rtl8192_phy_SetRFReg(dev,
53 (RF90_RADIO_PATH_E)eRFPath,
54 0x14, bMask12Bits, 0x5ab);
55 } else {
Jerry Chuang8fc85982009-11-03 07:17:11 -020056 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +053057 }
Jerry Chuang8fc85982009-11-03 07:17:11 -020058 break;
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +053059 case HT_CHANNEL_WIDTH_20_40:
60 if (priv->card_8192_version == VERSION_819xU_A || priv->card_8192_version == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */
Sanjeev Sharma93a9f052014-09-09 09:58:48 +053061 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0b, bMask12Bits, 0x300); /* phy para:3ba */
Jerry Chuang8fc85982009-11-03 07:17:11 -020062 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x2c, bMask12Bits, 0x3df);
63 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0e, bMask12Bits, 0x0a1);
64
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +053065 if (priv->chan == 3 || priv->chan == 9)
Sanjeev Sharma93a9f052014-09-09 09:58:48 +053066 /* I need to set priv->chan whenever current channel changes */
Jerry Chuang8fc85982009-11-03 07:17:11 -020067 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x59b);
68 else
69 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x5ab);
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +053070 } else {
Jerry Chuang8fc85982009-11-03 07:17:11 -020071 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +053072 }
Jerry Chuang8fc85982009-11-03 07:17:11 -020073 break;
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +053074 default:
75 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown Bandwidth: %#X\n", Bandwidth);
Jerry Chuang8fc85982009-11-03 07:17:11 -020076 break;
77
78 }
79 }
Jerry Chuang8fc85982009-11-03 07:17:11 -020080}
81/*--------------------------------------------------------------------------
82 * Overview: Interface to config 8256
83 * Input: struct net_device* dev
84 * Output: NONE
85 * Return: NONE
Gavin Thomas Claugus64b389c2015-12-10 21:35:35 -050086 *--------------------------------------------------------------------------
87 */
Xenia Ragiadakou959674e2013-05-11 17:22:23 +030088void PHY_RF8256_Config(struct net_device *dev)
Jerry Chuang8fc85982009-11-03 07:17:11 -020089{
90 struct r8192_priv *priv = ieee80211_priv(dev);
Sanjeev Sharma93a9f052014-09-09 09:58:48 +053091 /* Initialize general global value
92 *
93 * TODO: Extend RF_PATH_C and RF_PATH_D in the future
94 */
Jerry Chuang8fc85982009-11-03 07:17:11 -020095 priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH;
Sanjeev Sharma93a9f052014-09-09 09:58:48 +053096 /* Config BB and RF */
Jerry Chuang8fc85982009-11-03 07:17:11 -020097 phy_RF8256_Config_ParaFile(dev);
Jerry Chuang8fc85982009-11-03 07:17:11 -020098}
99/*--------------------------------------------------------------------------
100 * Overview: Interface to config 8256
101 * Input: struct net_device* dev
102 * Output: NONE
103 * Return: NONE
Gavin Thomas Claugus64b389c2015-12-10 21:35:35 -0500104 *--------------------------------------------------------------------------
105 */
Xenia Ragiadakou959674e2013-05-11 17:22:23 +0300106void phy_RF8256_Config_ParaFile(struct net_device *dev)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200107{
Sebastian Hahn35997ff2012-12-05 21:40:18 +0100108 u32 u4RegValue = 0;
Sebastian Hahn35997ff2012-12-05 21:40:18 +0100109 u8 eRFPath;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200110 BB_REGISTER_DEFINITION_T *pPhyReg;
111 struct r8192_priv *priv = ieee80211_priv(dev);
112 u32 RegOffSetToBeCheck = 0x3;
Sebastian Hahn35997ff2012-12-05 21:40:18 +0100113 u32 RegValueToBeCheck = 0x7f1;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200114 u32 RF3_Final_Value = 0;
115 u8 ConstRetryTimes = 5, RetryTimes = 5;
116 u8 ret = 0;
Sanjeev Sharma93a9f052014-09-09 09:58:48 +0530117 /* Initialize RF */
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530118 for (eRFPath = (RF90_RADIO_PATH_E)RF90_PATH_A; eRFPath < priv->NumTotalRFPath; eRFPath++) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200119 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
Loïc Pellegrinoa8d0df22014-04-06 14:03:39 +0100120 continue;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200121
122 pPhyReg = &priv->PHYRegDef[eRFPath];
123
Sanjeev Sharma93a9f052014-09-09 09:58:48 +0530124 /* Joseph test for shorten RF config
125 * pHalData->RfReg0Value[eRFPath] = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, rGlobalCtrl, bMaskDWord);
126 * ----Store original RFENV control type
127 */
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530128 switch (eRFPath) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200129 case RF90_PATH_A:
130 case RF90_PATH_C:
131 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV);
132 break;
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530133 case RF90_PATH_B:
Jerry Chuang8fc85982009-11-03 07:17:11 -0200134 case RF90_PATH_D:
135 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16);
136 break;
137 }
138
139 /*----Set RF_ENV enable----*/
140 rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1);
141
142 /*----Set RF_ENV output high----*/
143 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
144
145 /* Set bit number of Address and Data for RF register */
Sanjeev Sharma93a9f052014-09-09 09:58:48 +0530146 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); /* Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258 */
147 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); /* Set 0 to 12 bits for Z-serial and 8258, and set 1 to 14 bits for ??? */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200148
149 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E) eRFPath, 0x0, bMask12Bits, 0xbf);
150
Sanjeev Sharma93a9f052014-09-09 09:58:48 +0530151 /* Check RF block (for FPGA platform only)----
152 * TODO: this function should be removed on ASIC , Emily 2007.2.2
153 */
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530154 if (rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF, (RF90_RADIO_PATH_E)eRFPath)) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200155 RT_TRACE(COMP_ERR, "PHY_RF8256_Config():Check Radio[%d] Fail!!\n", eRFPath);
156 goto phy_RF8256_Config_ParaFile_Fail;
157 }
158
159 RetryTimes = ConstRetryTimes;
160 RF3_Final_Value = 0;
161 /*----Initialize RF fom connfiguration file----*/
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530162 switch (eRFPath) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200163 case RF90_PATH_A:
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530164 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
165 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200166 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
167 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
168 RetryTimes--;
169 }
170 break;
171 case RF90_PATH_B:
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530172 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
173 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200174 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
175 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
176 RetryTimes--;
177 }
178 break;
179 case RF90_PATH_C:
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530180 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
181 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200182 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
183 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
184 RetryTimes--;
185 }
186 break;
187 case RF90_PATH_D:
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530188 while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
189 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200190 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
191 RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
192 RetryTimes--;
193 }
194 break;
195 }
196
Sandhya Bankar46347b32016-03-18 09:15:45 +0530197 /*----Restore RFENV control type----*/
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530198 switch (eRFPath) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200199 case RF90_PATH_A:
200 case RF90_PATH_C:
201 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue);
202 break;
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530203 case RF90_PATH_B:
Jerry Chuang8fc85982009-11-03 07:17:11 -0200204 case RF90_PATH_D:
205 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16, u4RegValue);
206 break;
207 }
208
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530209 if (ret) {
Jerry Chuang8fc85982009-11-03 07:17:11 -0200210 RT_TRACE(COMP_ERR, "phy_RF8256_Config_ParaFile():Radio[%d] Fail!!", eRFPath);
211 goto phy_RF8256_Config_ParaFile_Fail;
212 }
213
214 }
215
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530216 RT_TRACE(COMP_PHY, "PHY Initialization Success\n");
217 return;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200218
219phy_RF8256_Config_ParaFile_Fail:
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530220 RT_TRACE(COMP_ERR, "PHY Initialization failed\n");
Jerry Chuang8fc85982009-11-03 07:17:11 -0200221}
222
223
Xenia Ragiadakou959674e2013-05-11 17:22:23 +0300224void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200225{
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530226 u32 TxAGC = 0;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200227 struct r8192_priv *priv = ieee80211_priv(dev);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200228 TxAGC = powerlevel;
229
Ksenija Stanojevic72b16fe2015-02-24 21:54:08 +0100230 if (priv->bDynamicTxLowPower) {
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530231 if (priv->CustomerID == RT_CID_819x_Netcore)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200232 TxAGC = 0x22;
233 else
Loïc Pellegrinoa8d0df22014-04-06 14:03:39 +0100234 TxAGC += priv->CckPwEnl;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200235 }
236
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530237 if (TxAGC > 0x24)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200238 TxAGC = 0x24;
239 rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
240}
241
242
Xenia Ragiadakou959674e2013-05-11 17:22:23 +0300243void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200244{
245 struct r8192_priv *priv = ieee80211_priv(dev);
Sanjeev Sharma93a9f052014-09-09 09:58:48 +0530246 /* Joseph TxPower for 8192 testing */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200247 u32 writeVal, powerBase0, powerBase1, writeVal_tmp;
248 u8 index = 0;
249 u16 RegOffset[6] = {0xe00, 0xe04, 0xe10, 0xe14, 0xe18, 0xe1c};
250 u8 byte0, byte1, byte2, byte3;
251
Sanjeev Sharma93a9f052014-09-09 09:58:48 +0530252 powerBase0 = powerlevel + priv->TxPowerDiff; /* OFDM rates */
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530253 powerBase0 = (powerBase0<<24) | (powerBase0<<16) | (powerBase0<<8) | powerBase0;
Sanjeev Sharma93a9f052014-09-09 09:58:48 +0530254 powerBase1 = powerlevel; /* MCS rates */
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530255 powerBase1 = (powerBase1<<24) | (powerBase1<<16) | (powerBase1<<8) | powerBase1;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200256
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530257 for (index = 0; index < 6; index++) {
258 writeVal = priv->MCSTxPowerLevelOriginalOffset[index] + ((index < 2)?powerBase0:powerBase1);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200259 byte0 = (u8)(writeVal & 0x7f);
260 byte1 = (u8)((writeVal & 0x7f00)>>8);
261 byte2 = (u8)((writeVal & 0x7f0000)>>16);
262 byte3 = (u8)((writeVal & 0x7f000000)>>24);
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530263
264 if (byte0 > 0x24)
265 /* Max power index = 0x24 */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200266 byte0 = 0x24;
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530267 if (byte1 > 0x24)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200268 byte1 = 0x24;
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530269 if (byte2 > 0x24)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200270 byte2 = 0x24;
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530271 if (byte3 > 0x24)
Jerry Chuang8fc85982009-11-03 07:17:11 -0200272 byte3 = 0x24;
273
Sanjeev Sharma93a9f052014-09-09 09:58:48 +0530274 /* for tx power track */
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530275 if (index == 3) {
276 writeVal_tmp = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0;
Jerry Chuang8fc85982009-11-03 07:17:11 -0200277 priv->Pwr_Track = writeVal_tmp;
278 }
279
Ksenija Stanojevic72b16fe2015-02-24 21:54:08 +0100280 if (priv->bDynamicTxHighPower) {
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530281 /*Add by Jacken 2008/03/06
282 *Emily, 20080613. Set low tx power for both MCS and legacy OFDM
283 */
Jerry Chuang8fc85982009-11-03 07:17:11 -0200284 writeVal = 0x03030303;
Sanjeev Sharma104cb5c2014-07-31 11:13:31 +0530285 } else {
286 writeVal = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0;
287 }
288 rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal);
Jerry Chuang8fc85982009-11-03 07:17:11 -0200289 }
290 return;
291
292}