rf.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2014 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. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. #include "../wifi.h"
  26. #include "reg.h"
  27. #include "def.h"
  28. #include "phy.h"
  29. #include "rf.h"
  30. #include "dm.h"
  31. static bool _rtl92ee_phy_rf6052_config_parafile(struct ieee80211_hw *hw);
  32. void rtl92ee_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth)
  33. {
  34. struct rtl_priv *rtlpriv = rtl_priv(hw);
  35. struct rtl_phy *rtlphy = &rtlpriv->phy;
  36. switch (bandwidth) {
  37. case HT_CHANNEL_WIDTH_20:
  38. rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] &
  39. 0xfffff3ff) | BIT(10) | BIT(11));
  40. rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
  41. rtlphy->rfreg_chnlval[0]);
  42. rtl_set_rfreg(hw, RF90_PATH_B, RF_CHNLBW, RFREG_OFFSET_MASK,
  43. rtlphy->rfreg_chnlval[0]);
  44. break;
  45. case HT_CHANNEL_WIDTH_20_40:
  46. rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] &
  47. 0xfffff3ff) | BIT(10));
  48. rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
  49. rtlphy->rfreg_chnlval[0]);
  50. rtl_set_rfreg(hw, RF90_PATH_B, RF_CHNLBW, RFREG_OFFSET_MASK,
  51. rtlphy->rfreg_chnlval[0]);
  52. break;
  53. default:
  54. pr_err("unknown bandwidth: %#X\n", bandwidth);
  55. break;
  56. }
  57. }
  58. bool rtl92ee_phy_rf6052_config(struct ieee80211_hw *hw)
  59. {
  60. struct rtl_priv *rtlpriv = rtl_priv(hw);
  61. struct rtl_phy *rtlphy = &rtlpriv->phy;
  62. if (rtlphy->rf_type == RF_1T1R)
  63. rtlphy->num_total_rfpath = 1;
  64. else
  65. rtlphy->num_total_rfpath = 2;
  66. return _rtl92ee_phy_rf6052_config_parafile(hw);
  67. }
  68. static bool _rtl92ee_phy_rf6052_config_parafile(struct ieee80211_hw *hw)
  69. {
  70. struct rtl_priv *rtlpriv = rtl_priv(hw);
  71. struct rtl_phy *rtlphy = &rtlpriv->phy;
  72. u32 u4_regvalue = 0;
  73. u8 rfpath;
  74. bool rtstatus = true;
  75. struct bb_reg_def *pphyreg;
  76. for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
  77. pphyreg = &rtlphy->phyreg_def[rfpath];
  78. switch (rfpath) {
  79. case RF90_PATH_A:
  80. case RF90_PATH_C:
  81. u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
  82. BRFSI_RFENV);
  83. break;
  84. case RF90_PATH_B:
  85. case RF90_PATH_D:
  86. u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
  87. BRFSI_RFENV << 16);
  88. break;
  89. }
  90. rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1);
  91. udelay(1);
  92. rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1);
  93. udelay(1);
  94. rtl_set_bbreg(hw, pphyreg->rfhssi_para2,
  95. B3WIREADDREAALENGTH, 0x0);
  96. udelay(1);
  97. rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0);
  98. udelay(1);
  99. switch (rfpath) {
  100. case RF90_PATH_A:
  101. rtstatus = rtl92ee_phy_config_rf_with_headerfile(hw,
  102. (enum radio_path)rfpath);
  103. break;
  104. case RF90_PATH_B:
  105. rtstatus = rtl92ee_phy_config_rf_with_headerfile(hw,
  106. (enum radio_path)rfpath);
  107. break;
  108. case RF90_PATH_C:
  109. break;
  110. case RF90_PATH_D:
  111. break;
  112. }
  113. switch (rfpath) {
  114. case RF90_PATH_A:
  115. case RF90_PATH_C:
  116. rtl_set_bbreg(hw, pphyreg->rfintfs,
  117. BRFSI_RFENV, u4_regvalue);
  118. break;
  119. case RF90_PATH_B:
  120. case RF90_PATH_D:
  121. rtl_set_bbreg(hw, pphyreg->rfintfs,
  122. BRFSI_RFENV << 16, u4_regvalue);
  123. break;
  124. }
  125. if (!rtstatus) {
  126. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  127. "Radio[%d] Fail!!\n", rfpath);
  128. return false;
  129. }
  130. }
  131. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "\n");
  132. return rtstatus;
  133. }