rf.c 19 KB

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