r8190_rtl8256.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. This is part of the rtl8192 driver
  3. released under the GPL (See file COPYING for details).
  4. This files contains programming code for the rtl8256
  5. radio frontend.
  6. *Many* thanks to Realtek Corp. for their great support!
  7. */
  8. #include "r8192U.h"
  9. #include "r8192U_hw.h"
  10. #include "r819xU_phyreg.h"
  11. #include "r819xU_phy.h"
  12. #include "r8190_rtl8256.h"
  13. /*--------------------------------------------------------------------------
  14. * Overview: set RF band width (20M or 40M)
  15. * Input: struct net_device* dev
  16. * WIRELESS_BANDWIDTH_E Bandwidth //20M or 40M
  17. * Output: NONE
  18. * Return: NONE
  19. * Note: 8226 support both 20M and 40 MHz
  20. *---------------------------------------------------------------------------*/
  21. void PHY_SetRF8256Bandwidth(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth)
  22. {
  23. u8 eRFPath;
  24. struct r8192_priv *priv = ieee80211_priv(dev);
  25. /* for(eRFPath = RF90_PATH_A; eRFPath <pHalData->NumTotalRFPath;
  26. * eRFPath++)
  27. */
  28. for (eRFPath = 0; eRFPath < RF90_PATH_MAX; eRFPath++) {
  29. if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
  30. continue;
  31. switch (Bandwidth) {
  32. case HT_CHANNEL_WIDTH_20:
  33. if (priv->card_8192_version == VERSION_819xU_A
  34. || priv->card_8192_version
  35. == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */
  36. rtl8192_phy_SetRFReg(dev,
  37. (RF90_RADIO_PATH_E)eRFPath,
  38. 0x0b, bMask12Bits, 0x100); /* phy para:1ba */
  39. rtl8192_phy_SetRFReg(dev,
  40. (RF90_RADIO_PATH_E)eRFPath,
  41. 0x2c, bMask12Bits, 0x3d7);
  42. rtl8192_phy_SetRFReg(dev,
  43. (RF90_RADIO_PATH_E)eRFPath,
  44. 0x0e, bMask12Bits, 0x021);
  45. rtl8192_phy_SetRFReg(dev,
  46. (RF90_RADIO_PATH_E)eRFPath,
  47. 0x14, bMask12Bits, 0x5ab);
  48. } else {
  49. RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
  50. }
  51. break;
  52. case HT_CHANNEL_WIDTH_20_40:
  53. if (priv->card_8192_version == VERSION_819xU_A || priv->card_8192_version == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */
  54. rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0b, bMask12Bits, 0x300); /* phy para:3ba */
  55. rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x2c, bMask12Bits, 0x3df);
  56. rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x0e, bMask12Bits, 0x0a1);
  57. if (priv->chan == 3 || priv->chan == 9)
  58. /* I need to set priv->chan whenever current channel changes */
  59. rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x59b);
  60. else
  61. rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x5ab);
  62. } else {
  63. RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
  64. }
  65. break;
  66. default:
  67. RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown Bandwidth: %#X\n", Bandwidth);
  68. break;
  69. }
  70. }
  71. }
  72. /*--------------------------------------------------------------------------
  73. * Overview: Interface to config 8256
  74. * Input: struct net_device* dev
  75. * Output: NONE
  76. * Return: NONE
  77. *---------------------------------------------------------------------------*/
  78. void PHY_RF8256_Config(struct net_device *dev)
  79. {
  80. struct r8192_priv *priv = ieee80211_priv(dev);
  81. /* Initialize general global value
  82. *
  83. * TODO: Extend RF_PATH_C and RF_PATH_D in the future
  84. */
  85. priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH;
  86. /* Config BB and RF */
  87. phy_RF8256_Config_ParaFile(dev);
  88. }
  89. /*--------------------------------------------------------------------------
  90. * Overview: Interface to config 8256
  91. * Input: struct net_device* dev
  92. * Output: NONE
  93. * Return: NONE
  94. *---------------------------------------------------------------------------*/
  95. void phy_RF8256_Config_ParaFile(struct net_device *dev)
  96. {
  97. u32 u4RegValue = 0;
  98. u8 eRFPath;
  99. BB_REGISTER_DEFINITION_T *pPhyReg;
  100. struct r8192_priv *priv = ieee80211_priv(dev);
  101. u32 RegOffSetToBeCheck = 0x3;
  102. u32 RegValueToBeCheck = 0x7f1;
  103. u32 RF3_Final_Value = 0;
  104. u8 ConstRetryTimes = 5, RetryTimes = 5;
  105. u8 ret = 0;
  106. /* Initialize RF */
  107. for (eRFPath = (RF90_RADIO_PATH_E)RF90_PATH_A; eRFPath < priv->NumTotalRFPath; eRFPath++) {
  108. if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
  109. continue;
  110. pPhyReg = &priv->PHYRegDef[eRFPath];
  111. /* Joseph test for shorten RF config
  112. * pHalData->RfReg0Value[eRFPath] = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, rGlobalCtrl, bMaskDWord);
  113. * ----Store original RFENV control type
  114. */
  115. switch (eRFPath) {
  116. case RF90_PATH_A:
  117. case RF90_PATH_C:
  118. u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV);
  119. break;
  120. case RF90_PATH_B:
  121. case RF90_PATH_D:
  122. u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16);
  123. break;
  124. }
  125. /*----Set RF_ENV enable----*/
  126. rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1);
  127. /*----Set RF_ENV output high----*/
  128. rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
  129. /* Set bit number of Address and Data for RF register */
  130. rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); /* Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258 */
  131. rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); /* Set 0 to 12 bits for Z-serial and 8258, and set 1 to 14 bits for ??? */
  132. rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E) eRFPath, 0x0, bMask12Bits, 0xbf);
  133. /* Check RF block (for FPGA platform only)----
  134. * TODO: this function should be removed on ASIC , Emily 2007.2.2
  135. */
  136. if (rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF, (RF90_RADIO_PATH_E)eRFPath)) {
  137. RT_TRACE(COMP_ERR, "PHY_RF8256_Config():Check Radio[%d] Fail!!\n", eRFPath);
  138. goto phy_RF8256_Config_ParaFile_Fail;
  139. }
  140. RetryTimes = ConstRetryTimes;
  141. RF3_Final_Value = 0;
  142. /*----Initialize RF fom connfiguration file----*/
  143. switch (eRFPath) {
  144. case RF90_PATH_A:
  145. while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
  146. ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
  147. RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
  148. RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
  149. RetryTimes--;
  150. }
  151. break;
  152. case RF90_PATH_B:
  153. while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
  154. ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
  155. RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
  156. RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
  157. RetryTimes--;
  158. }
  159. break;
  160. case RF90_PATH_C:
  161. while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
  162. ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
  163. RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
  164. RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
  165. RetryTimes--;
  166. }
  167. break;
  168. case RF90_PATH_D:
  169. while (RF3_Final_Value != RegValueToBeCheck && RetryTimes != 0) {
  170. ret = rtl8192_phy_ConfigRFWithHeaderFile(dev, (RF90_RADIO_PATH_E)eRFPath);
  171. RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, RegOffSetToBeCheck, bMask12Bits);
  172. RT_TRACE(COMP_RF, "RF %d %d register final value: %x\n", eRFPath, RegOffSetToBeCheck, RF3_Final_Value);
  173. RetryTimes--;
  174. }
  175. break;
  176. }
  177. /*----Restore RFENV control type----*/;
  178. switch (eRFPath) {
  179. case RF90_PATH_A:
  180. case RF90_PATH_C:
  181. rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue);
  182. break;
  183. case RF90_PATH_B:
  184. case RF90_PATH_D:
  185. rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16, u4RegValue);
  186. break;
  187. }
  188. if (ret) {
  189. RT_TRACE(COMP_ERR, "phy_RF8256_Config_ParaFile():Radio[%d] Fail!!", eRFPath);
  190. goto phy_RF8256_Config_ParaFile_Fail;
  191. }
  192. }
  193. RT_TRACE(COMP_PHY, "PHY Initialization Success\n");
  194. return;
  195. phy_RF8256_Config_ParaFile_Fail:
  196. RT_TRACE(COMP_ERR, "PHY Initialization failed\n");
  197. }
  198. void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel)
  199. {
  200. u32 TxAGC = 0;
  201. struct r8192_priv *priv = ieee80211_priv(dev);
  202. TxAGC = powerlevel;
  203. if (priv->bDynamicTxLowPower) {
  204. if (priv->CustomerID == RT_CID_819x_Netcore)
  205. TxAGC = 0x22;
  206. else
  207. TxAGC += priv->CckPwEnl;
  208. }
  209. if (TxAGC > 0x24)
  210. TxAGC = 0x24;
  211. rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
  212. }
  213. void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel)
  214. {
  215. struct r8192_priv *priv = ieee80211_priv(dev);
  216. /* Joseph TxPower for 8192 testing */
  217. u32 writeVal, powerBase0, powerBase1, writeVal_tmp;
  218. u8 index = 0;
  219. u16 RegOffset[6] = {0xe00, 0xe04, 0xe10, 0xe14, 0xe18, 0xe1c};
  220. u8 byte0, byte1, byte2, byte3;
  221. powerBase0 = powerlevel + priv->TxPowerDiff; /* OFDM rates */
  222. powerBase0 = (powerBase0<<24) | (powerBase0<<16) | (powerBase0<<8) | powerBase0;
  223. powerBase1 = powerlevel; /* MCS rates */
  224. powerBase1 = (powerBase1<<24) | (powerBase1<<16) | (powerBase1<<8) | powerBase1;
  225. for (index = 0; index < 6; index++) {
  226. writeVal = priv->MCSTxPowerLevelOriginalOffset[index] + ((index < 2)?powerBase0:powerBase1);
  227. byte0 = (u8)(writeVal & 0x7f);
  228. byte1 = (u8)((writeVal & 0x7f00)>>8);
  229. byte2 = (u8)((writeVal & 0x7f0000)>>16);
  230. byte3 = (u8)((writeVal & 0x7f000000)>>24);
  231. if (byte0 > 0x24)
  232. /* Max power index = 0x24 */
  233. byte0 = 0x24;
  234. if (byte1 > 0x24)
  235. byte1 = 0x24;
  236. if (byte2 > 0x24)
  237. byte2 = 0x24;
  238. if (byte3 > 0x24)
  239. byte3 = 0x24;
  240. /* for tx power track */
  241. if (index == 3) {
  242. writeVal_tmp = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0;
  243. priv->Pwr_Track = writeVal_tmp;
  244. }
  245. if (priv->bDynamicTxHighPower) {
  246. /*Add by Jacken 2008/03/06
  247. *Emily, 20080613. Set low tx power for both MCS and legacy OFDM
  248. */
  249. writeVal = 0x03030303;
  250. } else {
  251. writeVal = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0;
  252. }
  253. rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal);
  254. }
  255. return;
  256. }