rf.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  55. "unknown bandwidth: %#X\n", bandwidth);
  56. break;
  57. }
  58. }
  59. bool rtl92ee_phy_rf6052_config(struct ieee80211_hw *hw)
  60. {
  61. struct rtl_priv *rtlpriv = rtl_priv(hw);
  62. struct rtl_phy *rtlphy = &rtlpriv->phy;
  63. if (rtlphy->rf_type == RF_1T1R)
  64. rtlphy->num_total_rfpath = 1;
  65. else
  66. rtlphy->num_total_rfpath = 2;
  67. return _rtl92ee_phy_rf6052_config_parafile(hw);
  68. }
  69. static bool _rtl92ee_phy_rf6052_config_parafile(struct ieee80211_hw *hw)
  70. {
  71. struct rtl_priv *rtlpriv = rtl_priv(hw);
  72. struct rtl_phy *rtlphy = &rtlpriv->phy;
  73. u32 u4_regvalue = 0;
  74. u8 rfpath;
  75. bool rtstatus = true;
  76. struct bb_reg_def *pphyreg;
  77. for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
  78. pphyreg = &rtlphy->phyreg_def[rfpath];
  79. switch (rfpath) {
  80. case RF90_PATH_A:
  81. case RF90_PATH_C:
  82. u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
  83. BRFSI_RFENV);
  84. break;
  85. case RF90_PATH_B:
  86. case RF90_PATH_D:
  87. u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
  88. BRFSI_RFENV << 16);
  89. break;
  90. }
  91. rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1);
  92. udelay(1);
  93. rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1);
  94. udelay(1);
  95. rtl_set_bbreg(hw, pphyreg->rfhssi_para2,
  96. B3WIREADDREAALENGTH, 0x0);
  97. udelay(1);
  98. rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0);
  99. udelay(1);
  100. switch (rfpath) {
  101. case RF90_PATH_A:
  102. rtstatus = rtl92ee_phy_config_rf_with_headerfile(hw,
  103. (enum radio_path)rfpath);
  104. break;
  105. case RF90_PATH_B:
  106. rtstatus = rtl92ee_phy_config_rf_with_headerfile(hw,
  107. (enum radio_path)rfpath);
  108. break;
  109. case RF90_PATH_C:
  110. break;
  111. case RF90_PATH_D:
  112. break;
  113. }
  114. switch (rfpath) {
  115. case RF90_PATH_A:
  116. case RF90_PATH_C:
  117. rtl_set_bbreg(hw, pphyreg->rfintfs,
  118. BRFSI_RFENV, u4_regvalue);
  119. break;
  120. case RF90_PATH_B:
  121. case RF90_PATH_D:
  122. rtl_set_bbreg(hw, pphyreg->rfintfs,
  123. BRFSI_RFENV << 16, u4_regvalue);
  124. break;
  125. }
  126. if (!rtstatus) {
  127. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  128. "Radio[%d] Fail!!", rfpath);
  129. return false;
  130. }
  131. }
  132. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "\n");
  133. return rtstatus;
  134. }