18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/* Copyright(c) 2009-2014  Realtek Corporation.*/
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include "../wifi.h"
58c2ecf20Sopenharmony_ci#include "reg.h"
68c2ecf20Sopenharmony_ci#include "def.h"
78c2ecf20Sopenharmony_ci#include "phy.h"
88c2ecf20Sopenharmony_ci#include "rf.h"
98c2ecf20Sopenharmony_ci#include "dm.h"
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistatic bool _rtl92ee_phy_rf6052_config_parafile(struct ieee80211_hw *hw);
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_civoid rtl92ee_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth)
148c2ecf20Sopenharmony_ci{
158c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
168c2ecf20Sopenharmony_ci	struct rtl_phy *rtlphy = &rtlpriv->phy;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci	switch (bandwidth) {
198c2ecf20Sopenharmony_ci	case HT_CHANNEL_WIDTH_20:
208c2ecf20Sopenharmony_ci		rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] &
218c2ecf20Sopenharmony_ci					     0xfffff3ff) | BIT(10) | BIT(11));
228c2ecf20Sopenharmony_ci		rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
238c2ecf20Sopenharmony_ci			      rtlphy->rfreg_chnlval[0]);
248c2ecf20Sopenharmony_ci		rtl_set_rfreg(hw, RF90_PATH_B, RF_CHNLBW, RFREG_OFFSET_MASK,
258c2ecf20Sopenharmony_ci			      rtlphy->rfreg_chnlval[0]);
268c2ecf20Sopenharmony_ci		break;
278c2ecf20Sopenharmony_ci	case HT_CHANNEL_WIDTH_20_40:
288c2ecf20Sopenharmony_ci		rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] &
298c2ecf20Sopenharmony_ci					     0xfffff3ff) | BIT(10));
308c2ecf20Sopenharmony_ci		rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
318c2ecf20Sopenharmony_ci			      rtlphy->rfreg_chnlval[0]);
328c2ecf20Sopenharmony_ci		rtl_set_rfreg(hw, RF90_PATH_B, RF_CHNLBW, RFREG_OFFSET_MASK,
338c2ecf20Sopenharmony_ci			      rtlphy->rfreg_chnlval[0]);
348c2ecf20Sopenharmony_ci		break;
358c2ecf20Sopenharmony_ci	default:
368c2ecf20Sopenharmony_ci		pr_err("unknown bandwidth: %#X\n", bandwidth);
378c2ecf20Sopenharmony_ci		break;
388c2ecf20Sopenharmony_ci	}
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cibool rtl92ee_phy_rf6052_config(struct ieee80211_hw *hw)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
448c2ecf20Sopenharmony_ci	struct rtl_phy *rtlphy = &rtlpriv->phy;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	if (rtlphy->rf_type == RF_1T1R)
478c2ecf20Sopenharmony_ci		rtlphy->num_total_rfpath = 1;
488c2ecf20Sopenharmony_ci	else
498c2ecf20Sopenharmony_ci		rtlphy->num_total_rfpath = 2;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	return _rtl92ee_phy_rf6052_config_parafile(hw);
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic bool _rtl92ee_phy_rf6052_config_parafile(struct ieee80211_hw *hw)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	struct rtl_priv *rtlpriv = rtl_priv(hw);
578c2ecf20Sopenharmony_ci	struct rtl_phy *rtlphy = &rtlpriv->phy;
588c2ecf20Sopenharmony_ci	u32 u4_regvalue = 0;
598c2ecf20Sopenharmony_ci	u8 rfpath;
608c2ecf20Sopenharmony_ci	bool rtstatus = true;
618c2ecf20Sopenharmony_ci	struct bb_reg_def *pphyreg;
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
648c2ecf20Sopenharmony_ci		pphyreg = &rtlphy->phyreg_def[rfpath];
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci		switch (rfpath) {
678c2ecf20Sopenharmony_ci		case RF90_PATH_A:
688c2ecf20Sopenharmony_ci		case RF90_PATH_C:
698c2ecf20Sopenharmony_ci			u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
708c2ecf20Sopenharmony_ci						    BRFSI_RFENV);
718c2ecf20Sopenharmony_ci			break;
728c2ecf20Sopenharmony_ci		case RF90_PATH_B:
738c2ecf20Sopenharmony_ci		case RF90_PATH_D:
748c2ecf20Sopenharmony_ci			u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
758c2ecf20Sopenharmony_ci						    BRFSI_RFENV << 16);
768c2ecf20Sopenharmony_ci			break;
778c2ecf20Sopenharmony_ci		}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1);
808c2ecf20Sopenharmony_ci		udelay(1);
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1);
838c2ecf20Sopenharmony_ci		udelay(1);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfhssi_para2,
868c2ecf20Sopenharmony_ci			      B3WIREADDREAALENGTH, 0x0);
878c2ecf20Sopenharmony_ci		udelay(1);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci		rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0);
908c2ecf20Sopenharmony_ci		udelay(1);
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci		switch (rfpath) {
938c2ecf20Sopenharmony_ci		case RF90_PATH_A:
948c2ecf20Sopenharmony_ci			rtstatus = rtl92ee_phy_config_rf_with_headerfile(hw,
958c2ecf20Sopenharmony_ci						       (enum radio_path)rfpath);
968c2ecf20Sopenharmony_ci			break;
978c2ecf20Sopenharmony_ci		case RF90_PATH_B:
988c2ecf20Sopenharmony_ci			rtstatus = rtl92ee_phy_config_rf_with_headerfile(hw,
998c2ecf20Sopenharmony_ci						       (enum radio_path)rfpath);
1008c2ecf20Sopenharmony_ci			break;
1018c2ecf20Sopenharmony_ci		case RF90_PATH_C:
1028c2ecf20Sopenharmony_ci			break;
1038c2ecf20Sopenharmony_ci		case RF90_PATH_D:
1048c2ecf20Sopenharmony_ci			break;
1058c2ecf20Sopenharmony_ci		}
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci		switch (rfpath) {
1088c2ecf20Sopenharmony_ci		case RF90_PATH_A:
1098c2ecf20Sopenharmony_ci		case RF90_PATH_C:
1108c2ecf20Sopenharmony_ci			rtl_set_bbreg(hw, pphyreg->rfintfs,
1118c2ecf20Sopenharmony_ci				      BRFSI_RFENV, u4_regvalue);
1128c2ecf20Sopenharmony_ci			break;
1138c2ecf20Sopenharmony_ci		case RF90_PATH_B:
1148c2ecf20Sopenharmony_ci		case RF90_PATH_D:
1158c2ecf20Sopenharmony_ci			rtl_set_bbreg(hw, pphyreg->rfintfs,
1168c2ecf20Sopenharmony_ci				      BRFSI_RFENV << 16, u4_regvalue);
1178c2ecf20Sopenharmony_ci			break;
1188c2ecf20Sopenharmony_ci		}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci		if (!rtstatus) {
1218c2ecf20Sopenharmony_ci			rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
1228c2ecf20Sopenharmony_ci				"Radio[%d] Fail!!\n", rfpath);
1238c2ecf20Sopenharmony_ci			return false;
1248c2ecf20Sopenharmony_ci		}
1258c2ecf20Sopenharmony_ci	}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "\n");
1288c2ecf20Sopenharmony_ci	return rtstatus;
1298c2ecf20Sopenharmony_ci}
130