rf.c 18 KB

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