162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/* Copyright(c) 2009-2012  Realtek Corporation.*/
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#include "../wifi.h"
562306a36Sopenharmony_ci#include "reg.h"
662306a36Sopenharmony_ci#include "def.h"
762306a36Sopenharmony_ci#include "phy.h"
862306a36Sopenharmony_ci#include "rf.h"
962306a36Sopenharmony_ci#include "dm.h"
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_cistatic bool _rtl92c_phy_rf6052_config_parafile(struct ieee80211_hw *hw);
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_civoid rtl92cu_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth)
1462306a36Sopenharmony_ci{
1562306a36Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
1662306a36Sopenharmony_ci	struct rtl_phy *rtlphy = &(rtlpriv->phy);
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci	switch (bandwidth) {
1962306a36Sopenharmony_ci	case HT_CHANNEL_WIDTH_20:
2062306a36Sopenharmony_ci		rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] &
2162306a36Sopenharmony_ci					     0xfffff3ff) | 0x0400);
2262306a36Sopenharmony_ci		rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
2362306a36Sopenharmony_ci			      rtlphy->rfreg_chnlval[0]);
2462306a36Sopenharmony_ci		break;
2562306a36Sopenharmony_ci	case HT_CHANNEL_WIDTH_20_40:
2662306a36Sopenharmony_ci		rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] &
2762306a36Sopenharmony_ci					     0xfffff3ff));
2862306a36Sopenharmony_ci		rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
2962306a36Sopenharmony_ci			      rtlphy->rfreg_chnlval[0]);
3062306a36Sopenharmony_ci		break;
3162306a36Sopenharmony_ci	default:
3262306a36Sopenharmony_ci		pr_err("unknown bandwidth: %#X\n", bandwidth);
3362306a36Sopenharmony_ci		break;
3462306a36Sopenharmony_ci	}
3562306a36Sopenharmony_ci}
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_civoid rtl92cu_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
3862306a36Sopenharmony_ci					u8 *ppowerlevel)
3962306a36Sopenharmony_ci{
4062306a36Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
4162306a36Sopenharmony_ci	struct rtl_phy *rtlphy = &(rtlpriv->phy);
4262306a36Sopenharmony_ci	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
4362306a36Sopenharmony_ci	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
4462306a36Sopenharmony_ci	u32 tx_agc[2] = { 0, 0 }, tmpval = 0;
4562306a36Sopenharmony_ci	u8 idx1, idx2;
4662306a36Sopenharmony_ci	u8 *ptr;
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci	if (mac->act_scanning) {
4962306a36Sopenharmony_ci		tx_agc[RF90_PATH_A] = 0x3f3f3f3f;
5062306a36Sopenharmony_ci		tx_agc[RF90_PATH_B] = 0x3f3f3f3f;
5162306a36Sopenharmony_ci		for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
5262306a36Sopenharmony_ci			tx_agc[idx1] = ppowerlevel[idx1] |
5362306a36Sopenharmony_ci			    (ppowerlevel[idx1] << 8) |
5462306a36Sopenharmony_ci			    (ppowerlevel[idx1] << 16) |
5562306a36Sopenharmony_ci			    (ppowerlevel[idx1] << 24);
5662306a36Sopenharmony_ci			if (tx_agc[idx1] > 0x20 && rtlefuse->external_pa)
5762306a36Sopenharmony_ci				tx_agc[idx1] = 0x20;
5862306a36Sopenharmony_ci		}
5962306a36Sopenharmony_ci	} else {
6062306a36Sopenharmony_ci		if (rtlpriv->dm.dynamic_txhighpower_lvl ==
6162306a36Sopenharmony_ci		    TXHIGHPWRLEVEL_LEVEL1) {
6262306a36Sopenharmony_ci			tx_agc[RF90_PATH_A] = 0x10101010;
6362306a36Sopenharmony_ci			tx_agc[RF90_PATH_B] = 0x10101010;
6462306a36Sopenharmony_ci		} else if (rtlpriv->dm.dynamic_txhighpower_lvl ==
6562306a36Sopenharmony_ci			   TXHIGHPWRLEVEL_LEVEL2) {
6662306a36Sopenharmony_ci			tx_agc[RF90_PATH_A] = 0x00000000;
6762306a36Sopenharmony_ci			tx_agc[RF90_PATH_B] = 0x00000000;
6862306a36Sopenharmony_ci		} else {
6962306a36Sopenharmony_ci			for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
7062306a36Sopenharmony_ci				tx_agc[idx1] = ppowerlevel[idx1] |
7162306a36Sopenharmony_ci				    (ppowerlevel[idx1] << 8) |
7262306a36Sopenharmony_ci				    (ppowerlevel[idx1] << 16) |
7362306a36Sopenharmony_ci				    (ppowerlevel[idx1] << 24);
7462306a36Sopenharmony_ci			}
7562306a36Sopenharmony_ci			if (rtlefuse->eeprom_regulatory == 0) {
7662306a36Sopenharmony_ci				tmpval = (rtlphy->mcs_offset[0][6]) +
7762306a36Sopenharmony_ci					(rtlphy->mcs_offset[0][7] <<  8);
7862306a36Sopenharmony_ci				tx_agc[RF90_PATH_A] += tmpval;
7962306a36Sopenharmony_ci				tmpval = (rtlphy->mcs_offset[0][14]) +
8062306a36Sopenharmony_ci					(rtlphy->mcs_offset[0][15] << 24);
8162306a36Sopenharmony_ci				tx_agc[RF90_PATH_B] += tmpval;
8262306a36Sopenharmony_ci			}
8362306a36Sopenharmony_ci		}
8462306a36Sopenharmony_ci	}
8562306a36Sopenharmony_ci	for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
8662306a36Sopenharmony_ci		ptr = (u8 *) (&(tx_agc[idx1]));
8762306a36Sopenharmony_ci		for (idx2 = 0; idx2 < 4; idx2++) {
8862306a36Sopenharmony_ci			if (*ptr > RF6052_MAX_TX_PWR)
8962306a36Sopenharmony_ci				*ptr = RF6052_MAX_TX_PWR;
9062306a36Sopenharmony_ci			ptr++;
9162306a36Sopenharmony_ci		}
9262306a36Sopenharmony_ci	}
9362306a36Sopenharmony_ci	tmpval = tx_agc[RF90_PATH_A] & 0xff;
9462306a36Sopenharmony_ci	rtl_set_bbreg(hw, RTXAGC_A_CCK1_MCS32, MASKBYTE1, tmpval);
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci	RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
9762306a36Sopenharmony_ci		"CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n",
9862306a36Sopenharmony_ci		tmpval, RTXAGC_A_CCK1_MCS32);
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci	tmpval = tx_agc[RF90_PATH_A] >> 8;
10162306a36Sopenharmony_ci	if (mac->mode == WIRELESS_MODE_B)
10262306a36Sopenharmony_ci		tmpval = tmpval & 0xff00ffff;
10362306a36Sopenharmony_ci	rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval);
10462306a36Sopenharmony_ci	RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
10562306a36Sopenharmony_ci		"CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n",
10662306a36Sopenharmony_ci		tmpval, RTXAGC_B_CCK11_A_CCK2_11);
10762306a36Sopenharmony_ci	tmpval = tx_agc[RF90_PATH_B] >> 24;
10862306a36Sopenharmony_ci	rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, MASKBYTE0, tmpval);
10962306a36Sopenharmony_ci	RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
11062306a36Sopenharmony_ci		"CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n",
11162306a36Sopenharmony_ci		tmpval, RTXAGC_B_CCK11_A_CCK2_11);
11262306a36Sopenharmony_ci	tmpval = tx_agc[RF90_PATH_B] & 0x00ffffff;
11362306a36Sopenharmony_ci	rtl_set_bbreg(hw, RTXAGC_B_CCK1_55_MCS32, 0xffffff00, tmpval);
11462306a36Sopenharmony_ci	RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
11562306a36Sopenharmony_ci		"CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n",
11662306a36Sopenharmony_ci		tmpval, RTXAGC_B_CCK1_55_MCS32);
11762306a36Sopenharmony_ci}
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_cistatic void rtl92c_phy_get_power_base(struct ieee80211_hw *hw,
12062306a36Sopenharmony_ci				      u8 *ppowerlevel, u8 channel,
12162306a36Sopenharmony_ci				      u32 *ofdmbase, u32 *mcsbase)
12262306a36Sopenharmony_ci{
12362306a36Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
12462306a36Sopenharmony_ci	struct rtl_phy *rtlphy = &(rtlpriv->phy);
12562306a36Sopenharmony_ci	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
12662306a36Sopenharmony_ci	u32 powerbase0, powerbase1;
12762306a36Sopenharmony_ci	u8 legacy_pwrdiff = 0, ht20_pwrdiff = 0;
12862306a36Sopenharmony_ci	u8 i, powerlevel[2];
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci	for (i = 0; i < 2; i++) {
13162306a36Sopenharmony_ci		powerlevel[i] = ppowerlevel[i];
13262306a36Sopenharmony_ci		legacy_pwrdiff = rtlefuse->txpwr_legacyhtdiff[i][channel - 1];
13362306a36Sopenharmony_ci		powerbase0 = powerlevel[i] + legacy_pwrdiff;
13462306a36Sopenharmony_ci		powerbase0 = (powerbase0 << 24) | (powerbase0 << 16) |
13562306a36Sopenharmony_ci		    (powerbase0 << 8) | powerbase0;
13662306a36Sopenharmony_ci		*(ofdmbase + i) = powerbase0;
13762306a36Sopenharmony_ci		RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
13862306a36Sopenharmony_ci			" [OFDM power base index rf(%c) = 0x%x]\n",
13962306a36Sopenharmony_ci			i == 0 ? 'A' : 'B', *(ofdmbase + i));
14062306a36Sopenharmony_ci	}
14162306a36Sopenharmony_ci	for (i = 0; i < 2; i++) {
14262306a36Sopenharmony_ci		if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20) {
14362306a36Sopenharmony_ci			ht20_pwrdiff = rtlefuse->txpwr_ht20diff[i][channel - 1];
14462306a36Sopenharmony_ci			powerlevel[i] += ht20_pwrdiff;
14562306a36Sopenharmony_ci		}
14662306a36Sopenharmony_ci		powerbase1 = powerlevel[i];
14762306a36Sopenharmony_ci		powerbase1 = (powerbase1 << 24) |
14862306a36Sopenharmony_ci		    (powerbase1 << 16) | (powerbase1 << 8) | powerbase1;
14962306a36Sopenharmony_ci		*(mcsbase + i) = powerbase1;
15062306a36Sopenharmony_ci		RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
15162306a36Sopenharmony_ci			" [MCS power base index rf(%c) = 0x%x]\n",
15262306a36Sopenharmony_ci			i == 0 ? 'A' : 'B', *(mcsbase + i));
15362306a36Sopenharmony_ci	}
15462306a36Sopenharmony_ci}
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_cistatic void _rtl92c_get_txpower_writeval_by_regulatory(struct ieee80211_hw *hw,
15762306a36Sopenharmony_ci						       u8 channel, u8 index,
15862306a36Sopenharmony_ci						       u32 *powerbase0,
15962306a36Sopenharmony_ci						       u32 *powerbase1,
16062306a36Sopenharmony_ci						       u32 *p_outwriteval)
16162306a36Sopenharmony_ci{
16262306a36Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
16362306a36Sopenharmony_ci	struct rtl_phy *rtlphy = &(rtlpriv->phy);
16462306a36Sopenharmony_ci	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
16562306a36Sopenharmony_ci	u8 i, chnlgroup = 0, pwr_diff_limit[4];
16662306a36Sopenharmony_ci	u32 writeval, customer_limit, rf;
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci	for (rf = 0; rf < 2; rf++) {
16962306a36Sopenharmony_ci		switch (rtlefuse->eeprom_regulatory) {
17062306a36Sopenharmony_ci		case 0:
17162306a36Sopenharmony_ci			chnlgroup = 0;
17262306a36Sopenharmony_ci			writeval = rtlphy->mcs_offset
17362306a36Sopenharmony_ci			    [chnlgroup][index + (rf ? 8 : 0)]
17462306a36Sopenharmony_ci			    + ((index < 2) ? powerbase0[rf] : powerbase1[rf]);
17562306a36Sopenharmony_ci			RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
17662306a36Sopenharmony_ci				"RTK better performance,writeval(%c) = 0x%x\n",
17762306a36Sopenharmony_ci				rf == 0 ? 'A' : 'B', writeval);
17862306a36Sopenharmony_ci			break;
17962306a36Sopenharmony_ci		case 1:
18062306a36Sopenharmony_ci			if (rtlphy->pwrgroup_cnt == 1)
18162306a36Sopenharmony_ci				chnlgroup = 0;
18262306a36Sopenharmony_ci			if (rtlphy->pwrgroup_cnt >= 3) {
18362306a36Sopenharmony_ci				if (channel <= 3)
18462306a36Sopenharmony_ci					chnlgroup = 0;
18562306a36Sopenharmony_ci				else if (channel >= 4 && channel <= 9)
18662306a36Sopenharmony_ci					chnlgroup = 1;
18762306a36Sopenharmony_ci				else if (channel > 9)
18862306a36Sopenharmony_ci					chnlgroup = 2;
18962306a36Sopenharmony_ci				if (rtlphy->current_chan_bw ==
19062306a36Sopenharmony_ci				    HT_CHANNEL_WIDTH_20)
19162306a36Sopenharmony_ci					chnlgroup++;
19262306a36Sopenharmony_ci				else
19362306a36Sopenharmony_ci					chnlgroup += 4;
19462306a36Sopenharmony_ci			}
19562306a36Sopenharmony_ci			writeval = rtlphy->mcs_offset[chnlgroup][index +
19662306a36Sopenharmony_ci					(rf ? 8 : 0)] +
19762306a36Sopenharmony_ci					((index < 2) ? powerbase0[rf] :
19862306a36Sopenharmony_ci					powerbase1[rf]);
19962306a36Sopenharmony_ci			RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
20062306a36Sopenharmony_ci				"Realtek regulatory, 20MHz, writeval(%c) = 0x%x\n",
20162306a36Sopenharmony_ci				rf == 0 ? 'A' : 'B', writeval);
20262306a36Sopenharmony_ci			break;
20362306a36Sopenharmony_ci		case 2:
20462306a36Sopenharmony_ci			writeval = ((index < 2) ? powerbase0[rf] :
20562306a36Sopenharmony_ci				   powerbase1[rf]);
20662306a36Sopenharmony_ci			RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
20762306a36Sopenharmony_ci				"Better regulatory,writeval(%c) = 0x%x\n",
20862306a36Sopenharmony_ci				rf == 0 ? 'A' : 'B', writeval);
20962306a36Sopenharmony_ci			break;
21062306a36Sopenharmony_ci		case 3:
21162306a36Sopenharmony_ci			chnlgroup = 0;
21262306a36Sopenharmony_ci			if (rtlphy->current_chan_bw ==
21362306a36Sopenharmony_ci			    HT_CHANNEL_WIDTH_20_40) {
21462306a36Sopenharmony_ci				RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
21562306a36Sopenharmony_ci					"customer's limit, 40MHzrf(%c) = 0x%x\n",
21662306a36Sopenharmony_ci					rf == 0 ? 'A' : 'B',
21762306a36Sopenharmony_ci					rtlefuse->pwrgroup_ht40[rf]
21862306a36Sopenharmony_ci					[channel - 1]);
21962306a36Sopenharmony_ci			} else {
22062306a36Sopenharmony_ci				RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
22162306a36Sopenharmony_ci					"customer's limit, 20MHz rf(%c) = 0x%x\n",
22262306a36Sopenharmony_ci					rf == 0 ? 'A' : 'B',
22362306a36Sopenharmony_ci					rtlefuse->pwrgroup_ht20[rf]
22462306a36Sopenharmony_ci					[channel - 1]);
22562306a36Sopenharmony_ci			}
22662306a36Sopenharmony_ci			for (i = 0; i < 4; i++) {
22762306a36Sopenharmony_ci				pwr_diff_limit[i] = (u8) ((rtlphy->mcs_offset
22862306a36Sopenharmony_ci				    [chnlgroup][index + (rf ? 8 : 0)]
22962306a36Sopenharmony_ci				    & (0x7f << (i * 8))) >> (i * 8));
23062306a36Sopenharmony_ci				if (rtlphy->current_chan_bw ==
23162306a36Sopenharmony_ci				    HT_CHANNEL_WIDTH_20_40) {
23262306a36Sopenharmony_ci					if (pwr_diff_limit[i] >
23362306a36Sopenharmony_ci					    rtlefuse->pwrgroup_ht40[rf]
23462306a36Sopenharmony_ci						[channel - 1])
23562306a36Sopenharmony_ci						pwr_diff_limit[i] = rtlefuse->
23662306a36Sopenharmony_ci						    pwrgroup_ht40[rf]
23762306a36Sopenharmony_ci						    [channel - 1];
23862306a36Sopenharmony_ci				} else {
23962306a36Sopenharmony_ci					if (pwr_diff_limit[i] >
24062306a36Sopenharmony_ci					    rtlefuse->pwrgroup_ht20[rf]
24162306a36Sopenharmony_ci						[channel - 1])
24262306a36Sopenharmony_ci						pwr_diff_limit[i] =
24362306a36Sopenharmony_ci						    rtlefuse->pwrgroup_ht20[rf]
24462306a36Sopenharmony_ci						    [channel - 1];
24562306a36Sopenharmony_ci				}
24662306a36Sopenharmony_ci			}
24762306a36Sopenharmony_ci			customer_limit = (pwr_diff_limit[3] << 24) |
24862306a36Sopenharmony_ci			    (pwr_diff_limit[2] << 16) |
24962306a36Sopenharmony_ci			    (pwr_diff_limit[1] << 8) | (pwr_diff_limit[0]);
25062306a36Sopenharmony_ci			RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
25162306a36Sopenharmony_ci				"Customer's limit rf(%c) = 0x%x\n",
25262306a36Sopenharmony_ci				rf == 0 ? 'A' : 'B', customer_limit);
25362306a36Sopenharmony_ci			writeval = customer_limit + ((index < 2) ?
25462306a36Sopenharmony_ci				   powerbase0[rf] : powerbase1[rf]);
25562306a36Sopenharmony_ci			RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
25662306a36Sopenharmony_ci				"Customer, writeval rf(%c)= 0x%x\n",
25762306a36Sopenharmony_ci				rf == 0 ? 'A' : 'B', writeval);
25862306a36Sopenharmony_ci			break;
25962306a36Sopenharmony_ci		default:
26062306a36Sopenharmony_ci			chnlgroup = 0;
26162306a36Sopenharmony_ci			writeval = rtlphy->mcs_offset[chnlgroup]
26262306a36Sopenharmony_ci				   [index + (rf ? 8 : 0)] + ((index < 2) ?
26362306a36Sopenharmony_ci				   powerbase0[rf] : powerbase1[rf]);
26462306a36Sopenharmony_ci			RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
26562306a36Sopenharmony_ci				"RTK better performance, writevalrf(%c) = 0x%x\n",
26662306a36Sopenharmony_ci				rf == 0 ? 'A' : 'B', writeval);
26762306a36Sopenharmony_ci			break;
26862306a36Sopenharmony_ci		}
26962306a36Sopenharmony_ci		if (rtlpriv->dm.dynamic_txhighpower_lvl ==
27062306a36Sopenharmony_ci		    TXHIGHPWRLEVEL_LEVEL1)
27162306a36Sopenharmony_ci			writeval = 0x14141414;
27262306a36Sopenharmony_ci		else if (rtlpriv->dm.dynamic_txhighpower_lvl ==
27362306a36Sopenharmony_ci			 TXHIGHPWRLEVEL_LEVEL2)
27462306a36Sopenharmony_ci			writeval = 0x00000000;
27562306a36Sopenharmony_ci		if (rtlpriv->dm.dynamic_txhighpower_lvl == TXHIGHPWRLEVEL_BT1)
27662306a36Sopenharmony_ci			writeval = writeval - 0x06060606;
27762306a36Sopenharmony_ci		*(p_outwriteval + rf) = writeval;
27862306a36Sopenharmony_ci	}
27962306a36Sopenharmony_ci}
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_cistatic void _rtl92c_write_ofdm_power_reg(struct ieee80211_hw *hw,
28262306a36Sopenharmony_ci					 u8 index, u32 *value)
28362306a36Sopenharmony_ci{
28462306a36Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
28562306a36Sopenharmony_ci	struct rtl_phy *rtlphy = &(rtlpriv->phy);
28662306a36Sopenharmony_ci	u16 regoffset_a[6] = {
28762306a36Sopenharmony_ci		RTXAGC_A_RATE18_06, RTXAGC_A_RATE54_24,
28862306a36Sopenharmony_ci		RTXAGC_A_MCS03_MCS00, RTXAGC_A_MCS07_MCS04,
28962306a36Sopenharmony_ci		RTXAGC_A_MCS11_MCS08, RTXAGC_A_MCS15_MCS12
29062306a36Sopenharmony_ci	};
29162306a36Sopenharmony_ci	u16 regoffset_b[6] = {
29262306a36Sopenharmony_ci		RTXAGC_B_RATE18_06, RTXAGC_B_RATE54_24,
29362306a36Sopenharmony_ci		RTXAGC_B_MCS03_MCS00, RTXAGC_B_MCS07_MCS04,
29462306a36Sopenharmony_ci		RTXAGC_B_MCS11_MCS08, RTXAGC_B_MCS15_MCS12
29562306a36Sopenharmony_ci	};
29662306a36Sopenharmony_ci	u8 i, rf, pwr_val[4];
29762306a36Sopenharmony_ci	u32 writeval;
29862306a36Sopenharmony_ci	u16 regoffset;
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_ci	for (rf = 0; rf < 2; rf++) {
30162306a36Sopenharmony_ci		writeval = value[rf];
30262306a36Sopenharmony_ci		for (i = 0; i < 4; i++) {
30362306a36Sopenharmony_ci			pwr_val[i] = (u8)((writeval & (0x7f << (i * 8))) >>
30462306a36Sopenharmony_ci					  (i * 8));
30562306a36Sopenharmony_ci			if (pwr_val[i] > RF6052_MAX_TX_PWR)
30662306a36Sopenharmony_ci				pwr_val[i] = RF6052_MAX_TX_PWR;
30762306a36Sopenharmony_ci		}
30862306a36Sopenharmony_ci		writeval = (pwr_val[3] << 24) | (pwr_val[2] << 16) |
30962306a36Sopenharmony_ci		    (pwr_val[1] << 8) | pwr_val[0];
31062306a36Sopenharmony_ci		if (rf == 0)
31162306a36Sopenharmony_ci			regoffset = regoffset_a[index];
31262306a36Sopenharmony_ci		else
31362306a36Sopenharmony_ci			regoffset = regoffset_b[index];
31462306a36Sopenharmony_ci		rtl_set_bbreg(hw, regoffset, MASKDWORD, writeval);
31562306a36Sopenharmony_ci		RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
31662306a36Sopenharmony_ci			"Set 0x%x = %08x\n", regoffset, writeval);
31762306a36Sopenharmony_ci		if (((get_rf_type(rtlphy) == RF_2T2R) &&
31862306a36Sopenharmony_ci		     (regoffset == RTXAGC_A_MCS15_MCS12 ||
31962306a36Sopenharmony_ci		      regoffset == RTXAGC_B_MCS15_MCS12)) ||
32062306a36Sopenharmony_ci		    ((get_rf_type(rtlphy) != RF_2T2R) &&
32162306a36Sopenharmony_ci		     (regoffset == RTXAGC_A_MCS07_MCS04 ||
32262306a36Sopenharmony_ci		      regoffset == RTXAGC_B_MCS07_MCS04))) {
32362306a36Sopenharmony_ci			writeval = pwr_val[3];
32462306a36Sopenharmony_ci			if (regoffset == RTXAGC_A_MCS15_MCS12 ||
32562306a36Sopenharmony_ci			    regoffset == RTXAGC_A_MCS07_MCS04)
32662306a36Sopenharmony_ci				regoffset = 0xc90;
32762306a36Sopenharmony_ci			if (regoffset == RTXAGC_B_MCS15_MCS12 ||
32862306a36Sopenharmony_ci			    regoffset == RTXAGC_B_MCS07_MCS04)
32962306a36Sopenharmony_ci				regoffset = 0xc98;
33062306a36Sopenharmony_ci			for (i = 0; i < 3; i++) {
33162306a36Sopenharmony_ci				if (i != 2)
33262306a36Sopenharmony_ci					writeval = (writeval > 8) ?
33362306a36Sopenharmony_ci						   (writeval - 8) : 0;
33462306a36Sopenharmony_ci				else
33562306a36Sopenharmony_ci					writeval = (writeval > 6) ?
33662306a36Sopenharmony_ci						   (writeval - 6) : 0;
33762306a36Sopenharmony_ci				rtl_write_byte(rtlpriv, (u32)(regoffset + i),
33862306a36Sopenharmony_ci					      (u8)writeval);
33962306a36Sopenharmony_ci			}
34062306a36Sopenharmony_ci		}
34162306a36Sopenharmony_ci	}
34262306a36Sopenharmony_ci}
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_civoid rtl92cu_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw,
34562306a36Sopenharmony_ci					 u8 *ppowerlevel, u8 channel)
34662306a36Sopenharmony_ci{
34762306a36Sopenharmony_ci	u32 writeval[2], powerbase0[2], powerbase1[2];
34862306a36Sopenharmony_ci	u8 index = 0;
34962306a36Sopenharmony_ci
35062306a36Sopenharmony_ci	rtl92c_phy_get_power_base(hw, ppowerlevel,
35162306a36Sopenharmony_ci				  channel, &powerbase0[0], &powerbase1[0]);
35262306a36Sopenharmony_ci	for (index = 0; index < 6; index++) {
35362306a36Sopenharmony_ci		_rtl92c_get_txpower_writeval_by_regulatory(hw,
35462306a36Sopenharmony_ci							   channel, index,
35562306a36Sopenharmony_ci							   &powerbase0[0],
35662306a36Sopenharmony_ci							   &powerbase1[0],
35762306a36Sopenharmony_ci							   &writeval[0]);
35862306a36Sopenharmony_ci		_rtl92c_write_ofdm_power_reg(hw, index, &writeval[0]);
35962306a36Sopenharmony_ci	}
36062306a36Sopenharmony_ci}
36162306a36Sopenharmony_ci
36262306a36Sopenharmony_cibool rtl92cu_phy_rf6052_config(struct ieee80211_hw *hw)
36362306a36Sopenharmony_ci{
36462306a36Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
36562306a36Sopenharmony_ci	struct rtl_phy *rtlphy = &(rtlpriv->phy);
36662306a36Sopenharmony_ci	bool rtstatus = true;
36762306a36Sopenharmony_ci	u8 b_reg_hwparafile = 1;
36862306a36Sopenharmony_ci
36962306a36Sopenharmony_ci	if (rtlphy->rf_type == RF_1T1R)
37062306a36Sopenharmony_ci		rtlphy->num_total_rfpath = 1;
37162306a36Sopenharmony_ci	else
37262306a36Sopenharmony_ci		rtlphy->num_total_rfpath = 2;
37362306a36Sopenharmony_ci	if (b_reg_hwparafile == 1)
37462306a36Sopenharmony_ci		rtstatus = _rtl92c_phy_rf6052_config_parafile(hw);
37562306a36Sopenharmony_ci	return rtstatus;
37662306a36Sopenharmony_ci}
37762306a36Sopenharmony_ci
37862306a36Sopenharmony_cistatic bool _rtl92c_phy_rf6052_config_parafile(struct ieee80211_hw *hw)
37962306a36Sopenharmony_ci{
38062306a36Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
38162306a36Sopenharmony_ci	struct rtl_phy *rtlphy = &(rtlpriv->phy);
38262306a36Sopenharmony_ci	u32 u4_regvalue = 0;
38362306a36Sopenharmony_ci	u8 rfpath;
38462306a36Sopenharmony_ci	bool rtstatus = true;
38562306a36Sopenharmony_ci	struct bb_reg_def *pphyreg;
38662306a36Sopenharmony_ci
38762306a36Sopenharmony_ci	for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
38862306a36Sopenharmony_ci		pphyreg = &rtlphy->phyreg_def[rfpath];
38962306a36Sopenharmony_ci		switch (rfpath) {
39062306a36Sopenharmony_ci		case RF90_PATH_A:
39162306a36Sopenharmony_ci		case RF90_PATH_C:
39262306a36Sopenharmony_ci			u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
39362306a36Sopenharmony_ci						    BRFSI_RFENV);
39462306a36Sopenharmony_ci			break;
39562306a36Sopenharmony_ci		case RF90_PATH_B:
39662306a36Sopenharmony_ci		case RF90_PATH_D:
39762306a36Sopenharmony_ci			u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
39862306a36Sopenharmony_ci						    BRFSI_RFENV << 16);
39962306a36Sopenharmony_ci			break;
40062306a36Sopenharmony_ci		}
40162306a36Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1);
40262306a36Sopenharmony_ci		udelay(1);
40362306a36Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1);
40462306a36Sopenharmony_ci		udelay(1);
40562306a36Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfhssi_para2,
40662306a36Sopenharmony_ci			      B3WIREADDREAALENGTH, 0x0);
40762306a36Sopenharmony_ci		udelay(1);
40862306a36Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0);
40962306a36Sopenharmony_ci		udelay(1);
41062306a36Sopenharmony_ci		switch (rfpath) {
41162306a36Sopenharmony_ci		case RF90_PATH_A:
41262306a36Sopenharmony_ci		case RF90_PATH_B:
41362306a36Sopenharmony_ci			rtstatus = rtl92cu_phy_config_rf_with_headerfile(hw,
41462306a36Sopenharmony_ci					(enum radio_path) rfpath);
41562306a36Sopenharmony_ci			break;
41662306a36Sopenharmony_ci		case RF90_PATH_C:
41762306a36Sopenharmony_ci			break;
41862306a36Sopenharmony_ci		case RF90_PATH_D:
41962306a36Sopenharmony_ci			break;
42062306a36Sopenharmony_ci		}
42162306a36Sopenharmony_ci		switch (rfpath) {
42262306a36Sopenharmony_ci		case RF90_PATH_A:
42362306a36Sopenharmony_ci		case RF90_PATH_C:
42462306a36Sopenharmony_ci			rtl_set_bbreg(hw, pphyreg->rfintfs,
42562306a36Sopenharmony_ci				      BRFSI_RFENV, u4_regvalue);
42662306a36Sopenharmony_ci			break;
42762306a36Sopenharmony_ci		case RF90_PATH_B:
42862306a36Sopenharmony_ci		case RF90_PATH_D:
42962306a36Sopenharmony_ci			rtl_set_bbreg(hw, pphyreg->rfintfs,
43062306a36Sopenharmony_ci				      BRFSI_RFENV << 16, u4_regvalue);
43162306a36Sopenharmony_ci			break;
43262306a36Sopenharmony_ci		}
43362306a36Sopenharmony_ci		if (!rtstatus) {
43462306a36Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
43562306a36Sopenharmony_ci				"Radio[%d] Fail!!\n", rfpath);
43662306a36Sopenharmony_ci			goto phy_rf_cfg_fail;
43762306a36Sopenharmony_ci		}
43862306a36Sopenharmony_ci	}
43962306a36Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "<---\n");
44062306a36Sopenharmony_ciphy_rf_cfg_fail:
44162306a36Sopenharmony_ci	return rtstatus;
44262306a36Sopenharmony_ci}
443