rf.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2010 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_txpwrlevel_origoffset[0][6]) +
  103. (rtlphy->mcs_txpwrlevel_origoffset[0][7] << 8);
  104. tx_agc[RF90_PATH_A] += tmpval;
  105. tmpval = (rtlphy->mcs_txpwrlevel_origoffset[0][14]) +
  106. (rtlphy->mcs_txpwrlevel_origoffset[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", tmpval,
  122. 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", tmpval,
  127. 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", tmpval,
  132. 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", tmpval,
  137. 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_txpwrlevel_origoffset
  215. [chnlgroup][index +
  216. (rf ? 8 : 0)] + ((index < 2) ?
  217. powerbase0[rf] :
  218. powerbase1[rf]);
  219. RTPRINT(rtlpriv, FPHY, PHY_TXPWR, ("RTK better "
  220. "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_txpwrlevel_origoffset
  235. [chnlgroup][index +
  236. (rf ? 8 : 0)] + ((index < 2) ?
  237. powerbase0[rf] :
  238. powerbase1[rf]);
  239. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  240. ("Realtek regulatory, "
  241. "20MHz, writeval(%c) = 0x%x\n",
  242. ((rf == 0) ? 'A' : 'B'),
  243. writeval));
  244. }
  245. break;
  246. case 2:
  247. writeval = ((index < 2) ? powerbase0[rf] :
  248. powerbase1[rf]);
  249. RTPRINT(rtlpriv, FPHY, PHY_TXPWR, ("Better regulatory, "
  250. "writeval(%c) = 0x%x\n",
  251. ((rf == 0) ? 'A' : 'B'), writeval));
  252. break;
  253. case 3:
  254. chnlgroup = 0;
  255. if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
  256. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  257. ("customer's limit, 40MHz rf(%c) = "
  258. "0x%x\n", ((rf == 0) ? 'A' : 'B'),
  259. rtlefuse->pwrgroup_ht40[rf]
  260. [channel - 1]));
  261. } else {
  262. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  263. ("customer's limit, 20MHz rf(%c) = "
  264. "0x%x\n", ((rf == 0) ? 'A' : 'B'),
  265. rtlefuse->pwrgroup_ht20[rf]
  266. [channel - 1]));
  267. }
  268. for (i = 0; i < 4; i++) {
  269. pwr_diff_limit[i] =
  270. (u8)((rtlphy->mcs_txpwrlevel_origoffset
  271. [chnlgroup][index + (rf ? 8 : 0)] &
  272. (0x7f << (i * 8))) >> (i * 8));
  273. if (rtlphy->current_chan_bw ==
  274. HT_CHANNEL_WIDTH_20_40) {
  275. if (pwr_diff_limit[i] >
  276. rtlefuse->pwrgroup_ht40[rf]
  277. [channel - 1])
  278. pwr_diff_limit[i] =
  279. rtlefuse->pwrgroup_ht40
  280. [rf][channel - 1];
  281. } else {
  282. if (pwr_diff_limit[i] >
  283. rtlefuse->pwrgroup_ht20[rf][
  284. channel - 1])
  285. pwr_diff_limit[i] =
  286. rtlefuse->pwrgroup_ht20[rf]
  287. [channel - 1];
  288. }
  289. }
  290. customer_limit = (pwr_diff_limit[3] << 24) |
  291. (pwr_diff_limit[2] << 16) |
  292. (pwr_diff_limit[1] << 8) |
  293. (pwr_diff_limit[0]);
  294. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  295. ("Customer's limit rf(%c) = 0x%x\n",
  296. ((rf == 0) ? 'A' : 'B'), customer_limit));
  297. writeval = customer_limit + ((index < 2) ?
  298. powerbase0[rf] : powerbase1[rf]);
  299. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  300. ("Customer, writeval rf(%c)= 0x%x\n",
  301. ((rf == 0) ? 'A' : 'B'), writeval));
  302. break;
  303. default:
  304. chnlgroup = 0;
  305. writeval = rtlphy->mcs_txpwrlevel_origoffset
  306. [chnlgroup][index +
  307. (rf ? 8 : 0)] + ((index < 2) ?
  308. powerbase0[rf] : powerbase1[rf]);
  309. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  310. ("RTK better performance, writeval "
  311. "rf(%c) = 0x%x\n",
  312. ((rf == 0) ? 'A' : 'B'), writeval));
  313. break;
  314. }
  315. *(p_outwriteval + rf) = writeval;
  316. }
  317. }
  318. static void _rtl92d_write_ofdm_power_reg(struct ieee80211_hw *hw,
  319. u8 index, u32 *pvalue)
  320. {
  321. struct rtl_priv *rtlpriv = rtl_priv(hw);
  322. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  323. static u16 regoffset_a[6] = {
  324. RTXAGC_A_RATE18_06, RTXAGC_A_RATE54_24,
  325. RTXAGC_A_MCS03_MCS00, RTXAGC_A_MCS07_MCS04,
  326. RTXAGC_A_MCS11_MCS08, RTXAGC_A_MCS15_MCS12
  327. };
  328. static u16 regoffset_b[6] = {
  329. RTXAGC_B_RATE18_06, RTXAGC_B_RATE54_24,
  330. RTXAGC_B_MCS03_MCS00, RTXAGC_B_MCS07_MCS04,
  331. RTXAGC_B_MCS11_MCS08, RTXAGC_B_MCS15_MCS12
  332. };
  333. u8 i, rf, pwr_val[4];
  334. u32 writeval;
  335. u16 regoffset;
  336. for (rf = 0; rf < 2; rf++) {
  337. writeval = pvalue[rf];
  338. for (i = 0; i < 4; i++) {
  339. pwr_val[i] = (u8) ((writeval & (0x7f <<
  340. (i * 8))) >> (i * 8));
  341. if (pwr_val[i] > RF6052_MAX_TX_PWR)
  342. pwr_val[i] = RF6052_MAX_TX_PWR;
  343. }
  344. writeval = (pwr_val[3] << 24) | (pwr_val[2] << 16) |
  345. (pwr_val[1] << 8) | pwr_val[0];
  346. if (rf == 0)
  347. regoffset = regoffset_a[index];
  348. else
  349. regoffset = regoffset_b[index];
  350. rtl_set_bbreg(hw, regoffset, BMASKDWORD, writeval);
  351. RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
  352. ("Set 0x%x = %08x\n", regoffset, writeval));
  353. if (((get_rf_type(rtlphy) == RF_2T2R) &&
  354. (regoffset == RTXAGC_A_MCS15_MCS12 ||
  355. regoffset == RTXAGC_B_MCS15_MCS12)) ||
  356. ((get_rf_type(rtlphy) != RF_2T2R) &&
  357. (regoffset == RTXAGC_A_MCS07_MCS04 ||
  358. regoffset == RTXAGC_B_MCS07_MCS04))) {
  359. writeval = pwr_val[3];
  360. if (regoffset == RTXAGC_A_MCS15_MCS12 ||
  361. regoffset == RTXAGC_A_MCS07_MCS04)
  362. regoffset = 0xc90;
  363. if (regoffset == RTXAGC_B_MCS15_MCS12 ||
  364. regoffset == RTXAGC_B_MCS07_MCS04)
  365. regoffset = 0xc98;
  366. for (i = 0; i < 3; i++) {
  367. if (i != 2)
  368. writeval = (writeval > 8) ?
  369. (writeval - 8) : 0;
  370. else
  371. writeval = (writeval > 6) ?
  372. (writeval - 6) : 0;
  373. rtl_write_byte(rtlpriv, (u32) (regoffset + i),
  374. (u8) writeval);
  375. }
  376. }
  377. }
  378. }
  379. void rtl92d_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw,
  380. u8 *ppowerlevel, u8 channel)
  381. {
  382. u32 writeval[2], powerbase0[2], powerbase1[2];
  383. u8 index;
  384. _rtl92d_phy_get_power_base(hw, ppowerlevel, channel,
  385. &powerbase0[0], &powerbase1[0]);
  386. for (index = 0; index < 6; index++) {
  387. _rtl92d_get_txpower_writeval_by_regulatory(hw,
  388. channel, index, &powerbase0[0],
  389. &powerbase1[0], &writeval[0]);
  390. _rtl92d_write_ofdm_power_reg(hw, index, &writeval[0]);
  391. }
  392. }
  393. bool rtl92d_phy_enable_anotherphy(struct ieee80211_hw *hw, bool bmac0)
  394. {
  395. struct rtl_priv *rtlpriv = rtl_priv(hw);
  396. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  397. u8 u1btmp;
  398. u8 direct = bmac0 ? BIT(3) | BIT(2) : BIT(3);
  399. u8 mac_reg = bmac0 ? REG_MAC1 : REG_MAC0;
  400. u8 mac_on_bit = bmac0 ? MAC1_ON : MAC0_ON;
  401. bool bresult = true; /* true: need to enable BB/RF power */
  402. rtlhal->during_mac0init_radiob = false;
  403. rtlhal->during_mac1init_radioa = false;
  404. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, ("===>\n"));
  405. /* MAC0 Need PHY1 load radio_b.txt . Driver use DBI to write. */
  406. u1btmp = rtl_read_byte(rtlpriv, mac_reg);
  407. if (!(u1btmp & mac_on_bit)) {
  408. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("enable BB & RF\n"));
  409. /* Enable BB and RF power */
  410. rtl92de_write_dword_dbi(hw, REG_SYS_ISO_CTRL,
  411. rtl92de_read_dword_dbi(hw, REG_SYS_ISO_CTRL, direct) |
  412. BIT(29) | BIT(16) | BIT(17), direct);
  413. } else {
  414. /* We think if MAC1 is ON,then radio_a.txt
  415. * and radio_b.txt has been load. */
  416. bresult = false;
  417. }
  418. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, ("<===\n"));
  419. return bresult;
  420. }
  421. void rtl92d_phy_powerdown_anotherphy(struct ieee80211_hw *hw, bool bmac0)
  422. {
  423. struct rtl_priv *rtlpriv = rtl_priv(hw);
  424. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  425. u8 u1btmp;
  426. u8 direct = bmac0 ? BIT(3) | BIT(2) : BIT(3);
  427. u8 mac_reg = bmac0 ? REG_MAC1 : REG_MAC0;
  428. u8 mac_on_bit = bmac0 ? MAC1_ON : MAC0_ON;
  429. rtlhal->during_mac0init_radiob = false;
  430. rtlhal->during_mac1init_radioa = false;
  431. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, ("====>\n"));
  432. /* check MAC0 enable or not again now, if
  433. * enabled, not power down radio A. */
  434. u1btmp = rtl_read_byte(rtlpriv, mac_reg);
  435. if (!(u1btmp & mac_on_bit)) {
  436. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("power down\n"));
  437. /* power down RF radio A according to YuNan's advice. */
  438. rtl92de_write_dword_dbi(hw, RFPGA0_XA_LSSIPARAMETER,
  439. 0x00000000, direct);
  440. }
  441. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, ("<====\n"));
  442. }
  443. bool rtl92d_phy_rf6052_config(struct ieee80211_hw *hw)
  444. {
  445. struct rtl_priv *rtlpriv = rtl_priv(hw);
  446. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  447. bool rtstatus = true;
  448. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  449. u32 u4_regvalue = 0;
  450. u8 rfpath;
  451. struct bb_reg_def *pphyreg;
  452. bool mac1_initradioa_first = false, mac0_initradiob_first = false;
  453. bool need_pwrdown_radioa = false, need_pwrdown_radiob = false;
  454. bool true_bpath = false;
  455. if (rtlphy->rf_type == RF_1T1R)
  456. rtlphy->num_total_rfpath = 1;
  457. else
  458. rtlphy->num_total_rfpath = 2;
  459. /* Single phy mode: use radio_a radio_b config path_A path_B */
  460. /* seperately by MAC0, and MAC1 needn't configure RF; */
  461. /* Dual PHY mode:MAC0 use radio_a config 1st phy path_A, */
  462. /* MAC1 use radio_b config 2nd PHY path_A. */
  463. /* DMDP,MAC0 on G band,MAC1 on A band. */
  464. if (rtlhal->macphymode == DUALMAC_DUALPHY) {
  465. if (rtlhal->current_bandtype == BAND_ON_2_4G &&
  466. rtlhal->interfaceindex == 0) {
  467. /* MAC0 needs PHY1 load radio_b.txt.
  468. * Driver use DBI to write. */
  469. if (rtl92d_phy_enable_anotherphy(hw, true)) {
  470. rtlphy->num_total_rfpath = 2;
  471. mac0_initradiob_first = true;
  472. } else {
  473. /* We think if MAC1 is ON,then radio_a.txt and
  474. * radio_b.txt has been load. */
  475. return rtstatus;
  476. }
  477. } else if (rtlhal->current_bandtype == BAND_ON_5G &&
  478. rtlhal->interfaceindex == 1) {
  479. /* MAC1 needs PHY0 load radio_a.txt.
  480. * Driver use DBI to write. */
  481. if (rtl92d_phy_enable_anotherphy(hw, false)) {
  482. rtlphy->num_total_rfpath = 2;
  483. mac1_initradioa_first = true;
  484. } else {
  485. /* We think if MAC0 is ON,then radio_a.txt and
  486. * radio_b.txt has been load. */
  487. return rtstatus;
  488. }
  489. } else if (rtlhal->interfaceindex == 1) {
  490. /* MAC0 enabled, only init radia B. */
  491. true_bpath = true;
  492. }
  493. }
  494. for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
  495. /* Mac1 use PHY0 write */
  496. if (mac1_initradioa_first) {
  497. if (rfpath == RF90_PATH_A) {
  498. rtlhal->during_mac1init_radioa = true;
  499. need_pwrdown_radioa = true;
  500. } else if (rfpath == RF90_PATH_B) {
  501. rtlhal->during_mac1init_radioa = false;
  502. mac1_initradioa_first = false;
  503. rfpath = RF90_PATH_A;
  504. true_bpath = true;
  505. rtlphy->num_total_rfpath = 1;
  506. }
  507. } else if (mac0_initradiob_first) {
  508. /* Mac0 use PHY1 write */
  509. if (rfpath == RF90_PATH_A)
  510. rtlhal->during_mac0init_radiob = false;
  511. if (rfpath == RF90_PATH_B) {
  512. rtlhal->during_mac0init_radiob = true;
  513. mac0_initradiob_first = false;
  514. need_pwrdown_radiob = true;
  515. rfpath = RF90_PATH_A;
  516. true_bpath = true;
  517. rtlphy->num_total_rfpath = 1;
  518. }
  519. }
  520. pphyreg = &rtlphy->phyreg_def[rfpath];
  521. switch (rfpath) {
  522. case RF90_PATH_A:
  523. case RF90_PATH_C:
  524. u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
  525. BRFSI_RFENV);
  526. break;
  527. case RF90_PATH_B:
  528. case RF90_PATH_D:
  529. u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
  530. BRFSI_RFENV << 16);
  531. break;
  532. }
  533. rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1);
  534. udelay(1);
  535. rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1);
  536. udelay(1);
  537. /* Set bit number of Address and Data for RF register */
  538. /* Set 1 to 4 bits for 8255 */
  539. rtl_set_bbreg(hw, pphyreg->rfhssi_para2,
  540. B3WIREADDRESSLENGTH, 0x0);
  541. udelay(1);
  542. /* Set 0 to 12 bits for 8255 */
  543. rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0);
  544. udelay(1);
  545. switch (rfpath) {
  546. case RF90_PATH_A:
  547. if (true_bpath)
  548. rtstatus = rtl92d_phy_config_rf_with_headerfile(
  549. hw, radiob_txt,
  550. (enum radio_path)rfpath);
  551. else
  552. rtstatus = rtl92d_phy_config_rf_with_headerfile(
  553. hw, radioa_txt,
  554. (enum radio_path)rfpath);
  555. break;
  556. case RF90_PATH_B:
  557. rtstatus =
  558. rtl92d_phy_config_rf_with_headerfile(hw, radiob_txt,
  559. (enum radio_path) rfpath);
  560. break;
  561. case RF90_PATH_C:
  562. break;
  563. case RF90_PATH_D:
  564. break;
  565. }
  566. switch (rfpath) {
  567. case RF90_PATH_A:
  568. case RF90_PATH_C:
  569. rtl_set_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV,
  570. u4_regvalue);
  571. break;
  572. case RF90_PATH_B:
  573. case RF90_PATH_D:
  574. rtl_set_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV << 16,
  575. u4_regvalue);
  576. break;
  577. }
  578. if (rtstatus != true) {
  579. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  580. ("Radio[%d] Fail!!", rfpath));
  581. goto phy_rf_cfg_fail;
  582. }
  583. }
  584. /* check MAC0 enable or not again, if enabled,
  585. * not power down radio A. */
  586. /* check MAC1 enable or not again, if enabled,
  587. * not power down radio B. */
  588. if (need_pwrdown_radioa)
  589. rtl92d_phy_powerdown_anotherphy(hw, false);
  590. else if (need_pwrdown_radiob)
  591. rtl92d_phy_powerdown_anotherphy(hw, true);
  592. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("<---\n"));
  593. return rtstatus;
  594. phy_rf_cfg_fail:
  595. return rtstatus;
  596. }