rf.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 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. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * wlanfae <wlanfae@realtek.com>
  23. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  24. * Hsinchu 300, Taiwan.
  25. *
  26. * Larry Finger <Larry.Finger@lwfinger.net>
  27. *
  28. *****************************************************************************/
  29. #include "../wifi.h"
  30. #include "reg.h"
  31. #include "def.h"
  32. #include "phy.h"
  33. #include "rf.h"
  34. #include "dm.h"
  35. #include "hw.h"
  36. void rtl92d_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth)
  37. {
  38. struct rtl_priv *rtlpriv = rtl_priv(hw);
  39. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  40. u8 rfpath;
  41. switch (bandwidth) {
  42. case HT_CHANNEL_WIDTH_20:
  43. for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
  44. rtlphy->rfreg_chnlval[rfpath] = ((rtlphy->rfreg_chnlval
  45. [rfpath] & 0xfffff3ff) | 0x0400);
  46. rtl_set_rfreg(hw, rfpath, RF_CHNLBW, BIT(10) |
  47. BIT(11), 0x01);
  48. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD,
  49. "20M RF 0x18 = 0x%x\n",
  50. rtlphy->rfreg_chnlval[rfpath]);
  51. }
  52. break;
  53. case HT_CHANNEL_WIDTH_20_40:
  54. for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
  55. rtlphy->rfreg_chnlval[rfpath] =
  56. ((rtlphy->rfreg_chnlval[rfpath] & 0xfffff3ff));
  57. rtl_set_rfreg(hw, rfpath, RF_CHNLBW, BIT(10) | BIT(11),
  58. 0x00);
  59. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD,
  60. "40M RF 0x18 = 0x%x\n",
  61. rtlphy->rfreg_chnlval[rfpath]);
  62. }
  63. break;
  64. default:
  65. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  66. "unknown bandwidth: %#X\n", bandwidth);
  67. break;
  68. }
  69. }
  70. void rtl92d_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
  71. u8 *ppowerlevel)
  72. {
  73. struct rtl_priv *rtlpriv = rtl_priv(hw);
  74. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  75. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  76. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  77. u32 tx_agc[2] = {0, 0}, tmpval;
  78. bool turbo_scanoff = false;
  79. u8 idx1, idx2;
  80. u8 *ptr;
  81. if (rtlefuse->eeprom_regulatory != 0)
  82. turbo_scanoff = true;
  83. if (mac->act_scanning) {
  84. tx_agc[RF90_PATH_A] = 0x3f3f3f3f;
  85. tx_agc[RF90_PATH_B] = 0x3f3f3f3f;
  86. if (turbo_scanoff) {
  87. for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
  88. tx_agc[idx1] = ppowerlevel[idx1] |
  89. (ppowerlevel[idx1] << 8) |
  90. (ppowerlevel[idx1] << 16) |
  91. (ppowerlevel[idx1] << 24);
  92. }
  93. }
  94. } else {
  95. for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
  96. tx_agc[idx1] = ppowerlevel[idx1] |
  97. (ppowerlevel[idx1] << 8) |
  98. (ppowerlevel[idx1] << 16) |
  99. (ppowerlevel[idx1] << 24);
  100. }
  101. if (rtlefuse->eeprom_regulatory == 0) {
  102. tmpval = (rtlphy->mcs_offset[0][6]) +
  103. (rtlphy->mcs_offset[0][7] << 8);
  104. tx_agc[RF90_PATH_A] += tmpval;
  105. tmpval = (rtlphy->mcs_offset[0][14]) +
  106. (rtlphy->mcs_offset[0][15] << 24);
  107. tx_agc[RF90_PATH_B] += tmpval;
  108. }
  109. }
  110. for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
  111. ptr = (u8 *) (&(tx_agc[idx1]));
  112. for (idx2 = 0; idx2 < 4; idx2++) {
  113. if (*ptr > RF6052_MAX_TX_PWR)
  114. *ptr = RF6052_MAX_TX_PWR;
  115. ptr++;
  116. }
  117. }
  118. tmpval = tx_agc[RF90_PATH_A] & 0xff;
  119. rtl_set_bbreg(hw, RTXAGC_A_CCK1_MCS32, BMASKBYTE1, tmpval);
  120. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  121. "CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n",
  122. tmpval, RTXAGC_A_CCK1_MCS32);
  123. tmpval = tx_agc[RF90_PATH_A] >> 8;
  124. rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval);
  125. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  126. "CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n",
  127. tmpval, RTXAGC_B_CCK11_A_CCK2_11);
  128. tmpval = tx_agc[RF90_PATH_B] >> 24;
  129. rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, BMASKBYTE0, tmpval);
  130. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  131. "CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n",
  132. tmpval, RTXAGC_B_CCK11_A_CCK2_11);
  133. tmpval = tx_agc[RF90_PATH_B] & 0x00ffffff;
  134. rtl_set_bbreg(hw, RTXAGC_B_CCK1_55_MCS32, 0xffffff00, tmpval);
  135. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  136. "CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n",
  137. tmpval, RTXAGC_B_CCK1_55_MCS32);
  138. }
  139. static void _rtl92d_phy_get_power_base(struct ieee80211_hw *hw,
  140. u8 *ppowerlevel, u8 channel,
  141. u32 *ofdmbase, u32 *mcsbase)
  142. {
  143. struct rtl_priv *rtlpriv = rtl_priv(hw);
  144. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  145. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  146. u32 powerbase0, powerbase1;
  147. u8 legacy_pwrdiff, ht20_pwrdiff;
  148. u8 i, powerlevel[2];
  149. for (i = 0; i < 2; i++) {
  150. powerlevel[i] = ppowerlevel[i];
  151. legacy_pwrdiff = rtlefuse->txpwr_legacyhtdiff[i][channel - 1];
  152. powerbase0 = powerlevel[i] + legacy_pwrdiff;
  153. powerbase0 = (powerbase0 << 24) | (powerbase0 << 16) |
  154. (powerbase0 << 8) | powerbase0;
  155. *(ofdmbase + i) = powerbase0;
  156. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  157. " [OFDM power base index rf(%c) = 0x%x]\n",
  158. i == 0 ? 'A' : 'B', *(ofdmbase + i));
  159. }
  160. for (i = 0; i < 2; i++) {
  161. if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20) {
  162. ht20_pwrdiff = rtlefuse->txpwr_ht20diff[i][channel - 1];
  163. powerlevel[i] += ht20_pwrdiff;
  164. }
  165. powerbase1 = powerlevel[i];
  166. powerbase1 = (powerbase1 << 24) | (powerbase1 << 16) |
  167. (powerbase1 << 8) | powerbase1;
  168. *(mcsbase + i) = powerbase1;
  169. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  170. " [MCS power base index rf(%c) = 0x%x]\n",
  171. i == 0 ? 'A' : 'B', *(mcsbase + i));
  172. }
  173. }
  174. static u8 _rtl92d_phy_get_chnlgroup_bypg(u8 chnlindex)
  175. {
  176. u8 group;
  177. u8 channel_info[59] = {
  178. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  179. 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
  180. 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
  181. 114, 116, 118, 120, 122, 124, 126, 128, 130, 132,
  182. 134, 136, 138, 140, 149, 151, 153, 155, 157, 159,
  183. 161, 163, 165
  184. };
  185. if (channel_info[chnlindex] <= 3) /* Chanel 1-3 */
  186. group = 0;
  187. else if (channel_info[chnlindex] <= 9) /* Channel 4-9 */
  188. group = 1;
  189. else if (channel_info[chnlindex] <= 14) /* Channel 10-14 */
  190. group = 2;
  191. else if (channel_info[chnlindex] <= 64)
  192. group = 6;
  193. else if (channel_info[chnlindex] <= 140)
  194. group = 7;
  195. else
  196. group = 8;
  197. return group;
  198. }
  199. static void _rtl92d_get_txpower_writeval_by_regulatory(struct ieee80211_hw *hw,
  200. u8 channel, u8 index,
  201. u32 *powerbase0,
  202. u32 *powerbase1,
  203. u32 *p_outwriteval)
  204. {
  205. struct rtl_priv *rtlpriv = rtl_priv(hw);
  206. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  207. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  208. u8 i, chnlgroup = 0, pwr_diff_limit[4];
  209. u32 writeval = 0, customer_limit, rf;
  210. for (rf = 0; rf < 2; rf++) {
  211. switch (rtlefuse->eeprom_regulatory) {
  212. case 0:
  213. chnlgroup = 0;
  214. writeval = rtlphy->mcs_offset
  215. [chnlgroup][index +
  216. (rf ? 8 : 0)] + ((index < 2) ?
  217. powerbase0[rf] :
  218. powerbase1[rf]);
  219. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  220. "RTK better performance, writeval(%c) = 0x%x\n",
  221. rf == 0 ? 'A' : 'B', writeval);
  222. break;
  223. case 1:
  224. if (rtlphy->pwrgroup_cnt == 1)
  225. chnlgroup = 0;
  226. if (rtlphy->pwrgroup_cnt >= MAX_PG_GROUP) {
  227. chnlgroup = _rtl92d_phy_get_chnlgroup_bypg(
  228. channel - 1);
  229. if (rtlphy->current_chan_bw ==
  230. HT_CHANNEL_WIDTH_20)
  231. chnlgroup++;
  232. else
  233. chnlgroup += 4;
  234. writeval = rtlphy->mcs_offset
  235. [chnlgroup][index +
  236. (rf ? 8 : 0)] + ((index < 2) ?
  237. powerbase0[rf] :
  238. powerbase1[rf]);
  239. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  240. "Realtek regulatory, 20MHz, writeval(%c) = 0x%x\n",
  241. rf == 0 ? 'A' : 'B', writeval);
  242. }
  243. break;
  244. case 2:
  245. writeval = ((index < 2) ? powerbase0[rf] :
  246. powerbase1[rf]);
  247. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  248. "Better regulatory, writeval(%c) = 0x%x\n",
  249. rf == 0 ? 'A' : 'B', writeval);
  250. break;
  251. case 3:
  252. chnlgroup = 0;
  253. if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
  254. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  255. "customer's limit, 40MHz rf(%c) = 0x%x\n",
  256. rf == 0 ? 'A' : 'B',
  257. rtlefuse->pwrgroup_ht40[rf]
  258. [channel - 1]);
  259. } else {
  260. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  261. "customer's limit, 20MHz rf(%c) = 0x%x\n",
  262. rf == 0 ? 'A' : 'B',
  263. rtlefuse->pwrgroup_ht20[rf]
  264. [channel - 1]);
  265. }
  266. for (i = 0; i < 4; i++) {
  267. pwr_diff_limit[i] = (u8)((rtlphy->mcs_offset
  268. [chnlgroup][index + (rf ? 8 : 0)] &
  269. (0x7f << (i * 8))) >> (i * 8));
  270. if (rtlphy->current_chan_bw ==
  271. HT_CHANNEL_WIDTH_20_40) {
  272. if (pwr_diff_limit[i] >
  273. rtlefuse->pwrgroup_ht40[rf]
  274. [channel - 1])
  275. pwr_diff_limit[i] =
  276. rtlefuse->pwrgroup_ht40
  277. [rf][channel - 1];
  278. } else {
  279. if (pwr_diff_limit[i] >
  280. rtlefuse->pwrgroup_ht20[rf][
  281. channel - 1])
  282. pwr_diff_limit[i] =
  283. rtlefuse->pwrgroup_ht20[rf]
  284. [channel - 1];
  285. }
  286. }
  287. customer_limit = (pwr_diff_limit[3] << 24) |
  288. (pwr_diff_limit[2] << 16) |
  289. (pwr_diff_limit[1] << 8) |
  290. (pwr_diff_limit[0]);
  291. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  292. "Customer's limit rf(%c) = 0x%x\n",
  293. rf == 0 ? 'A' : 'B', customer_limit);
  294. writeval = customer_limit + ((index < 2) ?
  295. powerbase0[rf] : powerbase1[rf]);
  296. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  297. "Customer, writeval rf(%c)= 0x%x\n",
  298. rf == 0 ? 'A' : 'B', writeval);
  299. break;
  300. default:
  301. chnlgroup = 0;
  302. writeval = rtlphy->mcs_offset[chnlgroup][index +
  303. (rf ? 8 : 0)] + ((index < 2) ?
  304. powerbase0[rf] : powerbase1[rf]);
  305. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  306. "RTK better performance, writeval rf(%c) = 0x%x\n",
  307. rf == 0 ? 'A' : 'B', writeval);
  308. break;
  309. }
  310. *(p_outwriteval + rf) = writeval;
  311. }
  312. }
  313. static void _rtl92d_write_ofdm_power_reg(struct ieee80211_hw *hw,
  314. u8 index, u32 *pvalue)
  315. {
  316. struct rtl_priv *rtlpriv = rtl_priv(hw);
  317. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  318. static u16 regoffset_a[6] = {
  319. RTXAGC_A_RATE18_06, RTXAGC_A_RATE54_24,
  320. RTXAGC_A_MCS03_MCS00, RTXAGC_A_MCS07_MCS04,
  321. RTXAGC_A_MCS11_MCS08, RTXAGC_A_MCS15_MCS12
  322. };
  323. static u16 regoffset_b[6] = {
  324. RTXAGC_B_RATE18_06, RTXAGC_B_RATE54_24,
  325. RTXAGC_B_MCS03_MCS00, RTXAGC_B_MCS07_MCS04,
  326. RTXAGC_B_MCS11_MCS08, RTXAGC_B_MCS15_MCS12
  327. };
  328. u8 i, rf, pwr_val[4];
  329. u32 writeval;
  330. u16 regoffset;
  331. for (rf = 0; rf < 2; rf++) {
  332. writeval = pvalue[rf];
  333. for (i = 0; i < 4; i++) {
  334. pwr_val[i] = (u8) ((writeval & (0x7f <<
  335. (i * 8))) >> (i * 8));
  336. if (pwr_val[i] > RF6052_MAX_TX_PWR)
  337. pwr_val[i] = RF6052_MAX_TX_PWR;
  338. }
  339. writeval = (pwr_val[3] << 24) | (pwr_val[2] << 16) |
  340. (pwr_val[1] << 8) | pwr_val[0];
  341. if (rf == 0)
  342. regoffset = regoffset_a[index];
  343. else
  344. regoffset = regoffset_b[index];
  345. rtl_set_bbreg(hw, regoffset, BMASKDWORD, writeval);
  346. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  347. "Set 0x%x = %08x\n", regoffset, writeval);
  348. if (((get_rf_type(rtlphy) == RF_2T2R) &&
  349. (regoffset == RTXAGC_A_MCS15_MCS12 ||
  350. regoffset == RTXAGC_B_MCS15_MCS12)) ||
  351. ((get_rf_type(rtlphy) != RF_2T2R) &&
  352. (regoffset == RTXAGC_A_MCS07_MCS04 ||
  353. regoffset == RTXAGC_B_MCS07_MCS04))) {
  354. writeval = pwr_val[3];
  355. if (regoffset == RTXAGC_A_MCS15_MCS12 ||
  356. regoffset == RTXAGC_A_MCS07_MCS04)
  357. regoffset = 0xc90;
  358. if (regoffset == RTXAGC_B_MCS15_MCS12 ||
  359. regoffset == RTXAGC_B_MCS07_MCS04)
  360. regoffset = 0xc98;
  361. for (i = 0; i < 3; i++) {
  362. if (i != 2)
  363. writeval = (writeval > 8) ?
  364. (writeval - 8) : 0;
  365. else
  366. writeval = (writeval > 6) ?
  367. (writeval - 6) : 0;
  368. rtl_write_byte(rtlpriv, (u32) (regoffset + i),
  369. (u8) writeval);
  370. }
  371. }
  372. }
  373. }
  374. void rtl92d_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw,
  375. u8 *ppowerlevel, u8 channel)
  376. {
  377. u32 writeval[2], powerbase0[2], powerbase1[2];
  378. u8 index;
  379. _rtl92d_phy_get_power_base(hw, ppowerlevel, channel,
  380. &powerbase0[0], &powerbase1[0]);
  381. for (index = 0; index < 6; index++) {
  382. _rtl92d_get_txpower_writeval_by_regulatory(hw,
  383. channel, index, &powerbase0[0],
  384. &powerbase1[0], &writeval[0]);
  385. _rtl92d_write_ofdm_power_reg(hw, index, &writeval[0]);
  386. }
  387. }
  388. bool rtl92d_phy_enable_anotherphy(struct ieee80211_hw *hw, bool bmac0)
  389. {
  390. struct rtl_priv *rtlpriv = rtl_priv(hw);
  391. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  392. u8 u1btmp;
  393. u8 direct = bmac0 ? BIT(3) | BIT(2) : BIT(3);
  394. u8 mac_reg = bmac0 ? REG_MAC1 : REG_MAC0;
  395. u8 mac_on_bit = bmac0 ? MAC1_ON : MAC0_ON;
  396. bool bresult = true; /* true: need to enable BB/RF power */
  397. rtlhal->during_mac0init_radiob = false;
  398. rtlhal->during_mac1init_radioa = false;
  399. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, "===>\n");
  400. /* MAC0 Need PHY1 load radio_b.txt . Driver use DBI to write. */
  401. u1btmp = rtl_read_byte(rtlpriv, mac_reg);
  402. if (!(u1btmp & mac_on_bit)) {
  403. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "enable BB & RF\n");
  404. /* Enable BB and RF power */
  405. rtl92de_write_dword_dbi(hw, REG_SYS_ISO_CTRL,
  406. rtl92de_read_dword_dbi(hw, REG_SYS_ISO_CTRL, direct) |
  407. BIT(29) | BIT(16) | BIT(17), direct);
  408. } else {
  409. /* We think if MAC1 is ON,then radio_a.txt
  410. * and radio_b.txt has been load. */
  411. bresult = false;
  412. }
  413. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, "<===\n");
  414. return bresult;
  415. }
  416. void rtl92d_phy_powerdown_anotherphy(struct ieee80211_hw *hw, bool bmac0)
  417. {
  418. struct rtl_priv *rtlpriv = rtl_priv(hw);
  419. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  420. u8 u1btmp;
  421. u8 direct = bmac0 ? BIT(3) | BIT(2) : BIT(3);
  422. u8 mac_reg = bmac0 ? REG_MAC1 : REG_MAC0;
  423. u8 mac_on_bit = bmac0 ? MAC1_ON : MAC0_ON;
  424. rtlhal->during_mac0init_radiob = false;
  425. rtlhal->during_mac1init_radioa = false;
  426. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, "====>\n");
  427. /* check MAC0 enable or not again now, if
  428. * enabled, not power down radio A. */
  429. u1btmp = rtl_read_byte(rtlpriv, mac_reg);
  430. if (!(u1btmp & mac_on_bit)) {
  431. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "power down\n");
  432. /* power down RF radio A according to YuNan's advice. */
  433. rtl92de_write_dword_dbi(hw, RFPGA0_XA_LSSIPARAMETER,
  434. 0x00000000, direct);
  435. }
  436. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, "<====\n");
  437. }
  438. bool rtl92d_phy_rf6052_config(struct ieee80211_hw *hw)
  439. {
  440. struct rtl_priv *rtlpriv = rtl_priv(hw);
  441. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  442. bool rtstatus = true;
  443. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  444. u32 u4_regvalue = 0;
  445. u8 rfpath;
  446. struct bb_reg_def *pphyreg;
  447. bool mac1_initradioa_first = false, mac0_initradiob_first = false;
  448. bool need_pwrdown_radioa = false, need_pwrdown_radiob = false;
  449. bool true_bpath = false;
  450. if (rtlphy->rf_type == RF_1T1R)
  451. rtlphy->num_total_rfpath = 1;
  452. else
  453. rtlphy->num_total_rfpath = 2;
  454. /* Single phy mode: use radio_a radio_b config path_A path_B */
  455. /* seperately by MAC0, and MAC1 needn't configure RF; */
  456. /* Dual PHY mode:MAC0 use radio_a config 1st phy path_A, */
  457. /* MAC1 use radio_b config 2nd PHY path_A. */
  458. /* DMDP,MAC0 on G band,MAC1 on A band. */
  459. if (rtlhal->macphymode == DUALMAC_DUALPHY) {
  460. if (rtlhal->current_bandtype == BAND_ON_2_4G &&
  461. rtlhal->interfaceindex == 0) {
  462. /* MAC0 needs PHY1 load radio_b.txt.
  463. * Driver use DBI to write. */
  464. if (rtl92d_phy_enable_anotherphy(hw, true)) {
  465. rtlphy->num_total_rfpath = 2;
  466. mac0_initradiob_first = true;
  467. } else {
  468. /* We think if MAC1 is ON,then radio_a.txt and
  469. * radio_b.txt has been load. */
  470. return rtstatus;
  471. }
  472. } else if (rtlhal->current_bandtype == BAND_ON_5G &&
  473. rtlhal->interfaceindex == 1) {
  474. /* MAC1 needs PHY0 load radio_a.txt.
  475. * Driver use DBI to write. */
  476. if (rtl92d_phy_enable_anotherphy(hw, false)) {
  477. rtlphy->num_total_rfpath = 2;
  478. mac1_initradioa_first = true;
  479. } else {
  480. /* We think if MAC0 is ON,then radio_a.txt and
  481. * radio_b.txt has been load. */
  482. return rtstatus;
  483. }
  484. } else if (rtlhal->interfaceindex == 1) {
  485. /* MAC0 enabled, only init radia B. */
  486. true_bpath = true;
  487. }
  488. }
  489. for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
  490. /* Mac1 use PHY0 write */
  491. if (mac1_initradioa_first) {
  492. if (rfpath == RF90_PATH_A) {
  493. rtlhal->during_mac1init_radioa = true;
  494. need_pwrdown_radioa = true;
  495. } else if (rfpath == RF90_PATH_B) {
  496. rtlhal->during_mac1init_radioa = false;
  497. mac1_initradioa_first = false;
  498. rfpath = RF90_PATH_A;
  499. true_bpath = true;
  500. rtlphy->num_total_rfpath = 1;
  501. }
  502. } else if (mac0_initradiob_first) {
  503. /* Mac0 use PHY1 write */
  504. if (rfpath == RF90_PATH_A)
  505. rtlhal->during_mac0init_radiob = false;
  506. if (rfpath == RF90_PATH_B) {
  507. rtlhal->during_mac0init_radiob = true;
  508. mac0_initradiob_first = false;
  509. need_pwrdown_radiob = true;
  510. rfpath = RF90_PATH_A;
  511. true_bpath = true;
  512. rtlphy->num_total_rfpath = 1;
  513. }
  514. }
  515. pphyreg = &rtlphy->phyreg_def[rfpath];
  516. switch (rfpath) {
  517. case RF90_PATH_A:
  518. case RF90_PATH_C:
  519. u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
  520. BRFSI_RFENV);
  521. break;
  522. case RF90_PATH_B:
  523. case RF90_PATH_D:
  524. u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
  525. BRFSI_RFENV << 16);
  526. break;
  527. }
  528. rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1);
  529. udelay(1);
  530. rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1);
  531. udelay(1);
  532. /* Set bit number of Address and Data for RF register */
  533. /* Set 1 to 4 bits for 8255 */
  534. rtl_set_bbreg(hw, pphyreg->rfhssi_para2,
  535. B3WIREADDRESSLENGTH, 0x0);
  536. udelay(1);
  537. /* Set 0 to 12 bits for 8255 */
  538. rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0);
  539. udelay(1);
  540. switch (rfpath) {
  541. case RF90_PATH_A:
  542. if (true_bpath)
  543. rtstatus = rtl92d_phy_config_rf_with_headerfile(
  544. hw, radiob_txt,
  545. (enum radio_path)rfpath);
  546. else
  547. rtstatus = rtl92d_phy_config_rf_with_headerfile(
  548. hw, radioa_txt,
  549. (enum radio_path)rfpath);
  550. break;
  551. case RF90_PATH_B:
  552. rtstatus =
  553. rtl92d_phy_config_rf_with_headerfile(hw, radiob_txt,
  554. (enum radio_path) rfpath);
  555. break;
  556. case RF90_PATH_C:
  557. break;
  558. case RF90_PATH_D:
  559. break;
  560. }
  561. switch (rfpath) {
  562. case RF90_PATH_A:
  563. case RF90_PATH_C:
  564. rtl_set_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV,
  565. u4_regvalue);
  566. break;
  567. case RF90_PATH_B:
  568. case RF90_PATH_D:
  569. rtl_set_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV << 16,
  570. u4_regvalue);
  571. break;
  572. }
  573. if (!rtstatus) {
  574. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  575. "Radio[%d] Fail!!", rfpath);
  576. goto phy_rf_cfg_fail;
  577. }
  578. }
  579. /* check MAC0 enable or not again, if enabled,
  580. * not power down radio A. */
  581. /* check MAC1 enable or not again, if enabled,
  582. * not power down radio B. */
  583. if (need_pwrdown_radioa)
  584. rtl92d_phy_powerdown_anotherphy(hw, false);
  585. else if (need_pwrdown_radiob)
  586. rtl92d_phy_powerdown_anotherphy(hw, true);
  587. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "<---\n");
  588. return rtstatus;
  589. phy_rf_cfg_fail:
  590. return rtstatus;
  591. }