162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/* Copyright(c) 2009-2014  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 _rtl92ee_phy_rf6052_config_parafile(struct ieee80211_hw *hw);
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_civoid rtl92ee_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) | BIT(10) | BIT(11));
2262306a36Sopenharmony_ci		rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
2362306a36Sopenharmony_ci			      rtlphy->rfreg_chnlval[0]);
2462306a36Sopenharmony_ci		rtl_set_rfreg(hw, RF90_PATH_B, RF_CHNLBW, RFREG_OFFSET_MASK,
2562306a36Sopenharmony_ci			      rtlphy->rfreg_chnlval[0]);
2662306a36Sopenharmony_ci		break;
2762306a36Sopenharmony_ci	case HT_CHANNEL_WIDTH_20_40:
2862306a36Sopenharmony_ci		rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] &
2962306a36Sopenharmony_ci					     0xfffff3ff) | BIT(10));
3062306a36Sopenharmony_ci		rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
3162306a36Sopenharmony_ci			      rtlphy->rfreg_chnlval[0]);
3262306a36Sopenharmony_ci		rtl_set_rfreg(hw, RF90_PATH_B, RF_CHNLBW, RFREG_OFFSET_MASK,
3362306a36Sopenharmony_ci			      rtlphy->rfreg_chnlval[0]);
3462306a36Sopenharmony_ci		break;
3562306a36Sopenharmony_ci	default:
3662306a36Sopenharmony_ci		pr_err("unknown bandwidth: %#X\n", bandwidth);
3762306a36Sopenharmony_ci		break;
3862306a36Sopenharmony_ci	}
3962306a36Sopenharmony_ci}
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_cibool rtl92ee_phy_rf6052_config(struct ieee80211_hw *hw)
4262306a36Sopenharmony_ci{
4362306a36Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
4462306a36Sopenharmony_ci	struct rtl_phy *rtlphy = &rtlpriv->phy;
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci	if (rtlphy->rf_type == RF_1T1R)
4762306a36Sopenharmony_ci		rtlphy->num_total_rfpath = 1;
4862306a36Sopenharmony_ci	else
4962306a36Sopenharmony_ci		rtlphy->num_total_rfpath = 2;
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci	return _rtl92ee_phy_rf6052_config_parafile(hw);
5262306a36Sopenharmony_ci}
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistatic bool _rtl92ee_phy_rf6052_config_parafile(struct ieee80211_hw *hw)
5562306a36Sopenharmony_ci{
5662306a36Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
5762306a36Sopenharmony_ci	struct rtl_phy *rtlphy = &rtlpriv->phy;
5862306a36Sopenharmony_ci	u32 u4_regvalue = 0;
5962306a36Sopenharmony_ci	u8 rfpath;
6062306a36Sopenharmony_ci	bool rtstatus = true;
6162306a36Sopenharmony_ci	struct bb_reg_def *pphyreg;
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci	for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
6462306a36Sopenharmony_ci		pphyreg = &rtlphy->phyreg_def[rfpath];
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci		switch (rfpath) {
6762306a36Sopenharmony_ci		case RF90_PATH_A:
6862306a36Sopenharmony_ci		case RF90_PATH_C:
6962306a36Sopenharmony_ci			u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
7062306a36Sopenharmony_ci						    BRFSI_RFENV);
7162306a36Sopenharmony_ci			break;
7262306a36Sopenharmony_ci		case RF90_PATH_B:
7362306a36Sopenharmony_ci		case RF90_PATH_D:
7462306a36Sopenharmony_ci			u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
7562306a36Sopenharmony_ci						    BRFSI_RFENV << 16);
7662306a36Sopenharmony_ci			break;
7762306a36Sopenharmony_ci		}
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1);
8062306a36Sopenharmony_ci		udelay(1);
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1);
8362306a36Sopenharmony_ci		udelay(1);
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfhssi_para2,
8662306a36Sopenharmony_ci			      B3WIREADDREAALENGTH, 0x0);
8762306a36Sopenharmony_ci		udelay(1);
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0);
9062306a36Sopenharmony_ci		udelay(1);
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci		switch (rfpath) {
9362306a36Sopenharmony_ci		case RF90_PATH_A:
9462306a36Sopenharmony_ci			rtstatus = rtl92ee_phy_config_rf_with_headerfile(hw,
9562306a36Sopenharmony_ci						       (enum radio_path)rfpath);
9662306a36Sopenharmony_ci			break;
9762306a36Sopenharmony_ci		case RF90_PATH_B:
9862306a36Sopenharmony_ci			rtstatus = rtl92ee_phy_config_rf_with_headerfile(hw,
9962306a36Sopenharmony_ci						       (enum radio_path)rfpath);
10062306a36Sopenharmony_ci			break;
10162306a36Sopenharmony_ci		case RF90_PATH_C:
10262306a36Sopenharmony_ci			break;
10362306a36Sopenharmony_ci		case RF90_PATH_D:
10462306a36Sopenharmony_ci			break;
10562306a36Sopenharmony_ci		}
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci		switch (rfpath) {
10862306a36Sopenharmony_ci		case RF90_PATH_A:
10962306a36Sopenharmony_ci		case RF90_PATH_C:
11062306a36Sopenharmony_ci			rtl_set_bbreg(hw, pphyreg->rfintfs,
11162306a36Sopenharmony_ci				      BRFSI_RFENV, u4_regvalue);
11262306a36Sopenharmony_ci			break;
11362306a36Sopenharmony_ci		case RF90_PATH_B:
11462306a36Sopenharmony_ci		case RF90_PATH_D:
11562306a36Sopenharmony_ci			rtl_set_bbreg(hw, pphyreg->rfintfs,
11662306a36Sopenharmony_ci				      BRFSI_RFENV << 16, u4_regvalue);
11762306a36Sopenharmony_ci			break;
11862306a36Sopenharmony_ci		}
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci		if (!rtstatus) {
12162306a36Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
12262306a36Sopenharmony_ci				"Radio[%d] Fail!!\n", rfpath);
12362306a36Sopenharmony_ci			return false;
12462306a36Sopenharmony_ci		}
12562306a36Sopenharmony_ci	}
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "\n");
12862306a36Sopenharmony_ci	return rtstatus;
12962306a36Sopenharmony_ci}
130