xref: /linux/drivers/net/wireless/realtek/rtw88/phy.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1e3037485SYan-Hsuan Chuang /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2e3037485SYan-Hsuan Chuang /* Copyright(c) 2018-2019  Realtek Corporation
3e3037485SYan-Hsuan Chuang  */
4e3037485SYan-Hsuan Chuang 
5e3037485SYan-Hsuan Chuang #ifndef __RTW_PHY_H_
6e3037485SYan-Hsuan Chuang #define __RTW_PHY_H_
7e3037485SYan-Hsuan Chuang 
8e3037485SYan-Hsuan Chuang #include "debug.h"
9e3037485SYan-Hsuan Chuang 
10e3037485SYan-Hsuan Chuang extern u8 rtw_cck_rates[];
11e3037485SYan-Hsuan Chuang extern u8 rtw_ofdm_rates[];
12e3037485SYan-Hsuan Chuang extern u8 rtw_ht_1s_rates[];
13e3037485SYan-Hsuan Chuang extern u8 rtw_ht_2s_rates[];
14e3037485SYan-Hsuan Chuang extern u8 rtw_vht_1s_rates[];
15e3037485SYan-Hsuan Chuang extern u8 rtw_vht_2s_rates[];
16e3037485SYan-Hsuan Chuang extern u8 *rtw_rate_section[];
17e3037485SYan-Hsuan Chuang extern u8 rtw_rate_size[];
18e3037485SYan-Hsuan Chuang 
19e3037485SYan-Hsuan Chuang void rtw_phy_init(struct rtw_dev *rtwdev);
20e3037485SYan-Hsuan Chuang void rtw_phy_dynamic_mechanism(struct rtw_dev *rtwdev);
21e3037485SYan-Hsuan Chuang u8 rtw_phy_rf_power_2_rssi(s8 *rf_power, u8 path_num);
22e3037485SYan-Hsuan Chuang u32 rtw_phy_read_rf(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
23e3037485SYan-Hsuan Chuang 		    u32 addr, u32 mask);
24e0c27cdbSPing-Ke Shih u32 rtw_phy_read_rf_sipi(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
25e0c27cdbSPing-Ke Shih 			 u32 addr, u32 mask);
26e3037485SYan-Hsuan Chuang bool rtw_phy_write_rf_reg_sipi(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
27e3037485SYan-Hsuan Chuang 			       u32 addr, u32 mask, u32 data);
28e3037485SYan-Hsuan Chuang bool rtw_phy_write_rf_reg(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
29e3037485SYan-Hsuan Chuang 			  u32 addr, u32 mask, u32 data);
30e3037485SYan-Hsuan Chuang bool rtw_phy_write_rf_reg_mix(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
31e3037485SYan-Hsuan Chuang 			      u32 addr, u32 mask, u32 data);
32e3037485SYan-Hsuan Chuang void rtw_phy_setup_phy_cond(struct rtw_dev *rtwdev, u32 pkg);
33e3037485SYan-Hsuan Chuang void rtw_parse_tbl_phy_cond(struct rtw_dev *rtwdev, const struct rtw_table *tbl);
34e3037485SYan-Hsuan Chuang void rtw_parse_tbl_bb_pg(struct rtw_dev *rtwdev, const struct rtw_table *tbl);
35e3037485SYan-Hsuan Chuang void rtw_parse_tbl_txpwr_lmt(struct rtw_dev *rtwdev, const struct rtw_table *tbl);
36e3037485SYan-Hsuan Chuang void rtw_phy_cfg_mac(struct rtw_dev *rtwdev, const struct rtw_table *tbl,
37e3037485SYan-Hsuan Chuang 		     u32 addr, u32 data);
38e3037485SYan-Hsuan Chuang void rtw_phy_cfg_agc(struct rtw_dev *rtwdev, const struct rtw_table *tbl,
39e3037485SYan-Hsuan Chuang 		     u32 addr, u32 data);
40e3037485SYan-Hsuan Chuang void rtw_phy_cfg_bb(struct rtw_dev *rtwdev, const struct rtw_table *tbl,
41e3037485SYan-Hsuan Chuang 		    u32 addr, u32 data);
42e3037485SYan-Hsuan Chuang void rtw_phy_cfg_rf(struct rtw_dev *rtwdev, const struct rtw_table *tbl,
43e3037485SYan-Hsuan Chuang 		    u32 addr, u32 data);
440d350f0aSTzu-En Huang void rtw_phy_init_tx_power(struct rtw_dev *rtwdev);
45e3037485SYan-Hsuan Chuang void rtw_phy_load_tables(struct rtw_dev *rtwdev);
46c97ee3e0STzu-En Huang u8 rtw_phy_get_tx_power_index(struct rtw_dev *rtwdev, u8 rf_path, u8 rate,
47c97ee3e0STzu-En Huang 			      enum rtw_bandwidth bw, u8 channel, u8 regd);
48e3037485SYan-Hsuan Chuang void rtw_phy_set_tx_power_level(struct rtw_dev *rtwdev, u8 channel);
49e3037485SYan-Hsuan Chuang void rtw_phy_tx_power_by_rate_config(struct rtw_hal *hal);
50e3037485SYan-Hsuan Chuang void rtw_phy_tx_power_limit_config(struct rtw_hal *hal);
51c97ee3e0STzu-En Huang void rtw_phy_pwrtrack_avg(struct rtw_dev *rtwdev, u8 thermal, u8 path);
52c97ee3e0STzu-En Huang bool rtw_phy_pwrtrack_thermal_changed(struct rtw_dev *rtwdev, u8 thermal,
53c97ee3e0STzu-En Huang 				      u8 path);
54c97ee3e0STzu-En Huang u8 rtw_phy_pwrtrack_get_delta(struct rtw_dev *rtwdev, u8 path);
55c97ee3e0STzu-En Huang s8 rtw_phy_pwrtrack_get_pwridx(struct rtw_dev *rtwdev,
56c97ee3e0STzu-En Huang 			       struct rtw_swing_table *swing_table,
57c97ee3e0STzu-En Huang 			       u8 tbl_path, u8 therm_path, u8 delta);
587ae7784eSPo-Hao Huang bool rtw_phy_pwrtrack_need_lck(struct rtw_dev *rtwdev);
59c97ee3e0STzu-En Huang bool rtw_phy_pwrtrack_need_iqk(struct rtw_dev *rtwdev);
60c97ee3e0STzu-En Huang void rtw_phy_config_swing_table(struct rtw_dev *rtwdev,
61c97ee3e0STzu-En Huang 				struct rtw_swing_table *swing_table);
627285eb96SZong-Zhe Yang void rtw_phy_set_edcca_th(struct rtw_dev *rtwdev, u8 l2h, u8 h2l);
637285eb96SZong-Zhe Yang void rtw_phy_adaptivity_set_mode(struct rtw_dev *rtwdev);
64fb8517f4SPo-Hao Huang void rtw_phy_parsing_cfo(struct rtw_dev *rtwdev,
65fb8517f4SPo-Hao Huang 			 struct rtw_rx_pkt_stat *pkt_stat);
661188301fSPo-Hao Huang void rtw_phy_tx_path_diversity(struct rtw_dev *rtwdev);
67e3037485SYan-Hsuan Chuang 
683457f86dSBrian Norris struct rtw_txpwr_lmt_cfg_pair {
693457f86dSBrian Norris 	u8 regd;
703457f86dSBrian Norris 	u8 band;
713457f86dSBrian Norris 	u8 bw;
723457f86dSBrian Norris 	u8 rs;
733457f86dSBrian Norris 	u8 ch;
743457f86dSBrian Norris 	s8 txpwr_lmt;
753457f86dSBrian Norris };
763457f86dSBrian Norris 
770b8db87dSYan-Hsuan Chuang struct rtw_phy_pg_cfg_pair {
780b8db87dSYan-Hsuan Chuang 	u32 band;
790b8db87dSYan-Hsuan Chuang 	u32 rf_path;
800b8db87dSYan-Hsuan Chuang 	u32 tx_num;
810b8db87dSYan-Hsuan Chuang 	u32 addr;
820b8db87dSYan-Hsuan Chuang 	u32 bitmask;
830b8db87dSYan-Hsuan Chuang 	u32 data;
840b8db87dSYan-Hsuan Chuang };
850b8db87dSYan-Hsuan Chuang 
86e3037485SYan-Hsuan Chuang #define RTW_DECL_TABLE_PHY_COND_CORE(name, cfg, path)	\
87e3037485SYan-Hsuan Chuang const struct rtw_table name ## _tbl = {			\
88e3037485SYan-Hsuan Chuang 	.data = name,					\
89e3037485SYan-Hsuan Chuang 	.size = ARRAY_SIZE(name),			\
90e3037485SYan-Hsuan Chuang 	.parse = rtw_parse_tbl_phy_cond,		\
91e3037485SYan-Hsuan Chuang 	.do_cfg = cfg,					\
92e3037485SYan-Hsuan Chuang 	.rf_path = path,				\
93e3037485SYan-Hsuan Chuang }
94e3037485SYan-Hsuan Chuang 
95e3037485SYan-Hsuan Chuang #define RTW_DECL_TABLE_PHY_COND(name, cfg)		\
96e3037485SYan-Hsuan Chuang 	RTW_DECL_TABLE_PHY_COND_CORE(name, cfg, 0)
97e3037485SYan-Hsuan Chuang 
98e3037485SYan-Hsuan Chuang #define RTW_DECL_TABLE_RF_RADIO(name, path)		\
99e3037485SYan-Hsuan Chuang 	RTW_DECL_TABLE_PHY_COND_CORE(name, rtw_phy_cfg_rf, RF_PATH_ ## path)
100e3037485SYan-Hsuan Chuang 
101e3037485SYan-Hsuan Chuang #define RTW_DECL_TABLE_BB_PG(name)			\
102e3037485SYan-Hsuan Chuang const struct rtw_table name ## _tbl = {			\
103e3037485SYan-Hsuan Chuang 	.data = name,					\
104e3037485SYan-Hsuan Chuang 	.size = ARRAY_SIZE(name),			\
105e3037485SYan-Hsuan Chuang 	.parse = rtw_parse_tbl_bb_pg,			\
106e3037485SYan-Hsuan Chuang }
107e3037485SYan-Hsuan Chuang 
108e3037485SYan-Hsuan Chuang #define RTW_DECL_TABLE_TXPWR_LMT(name)			\
109e3037485SYan-Hsuan Chuang const struct rtw_table name ## _tbl = {			\
110e3037485SYan-Hsuan Chuang 	.data = name,					\
111e3037485SYan-Hsuan Chuang 	.size = ARRAY_SIZE(name),			\
112e3037485SYan-Hsuan Chuang 	.parse = rtw_parse_tbl_txpwr_lmt,		\
113e3037485SYan-Hsuan Chuang }
114e3037485SYan-Hsuan Chuang 
rtw_get_rfe_def(struct rtw_dev * rtwdev)115e3037485SYan-Hsuan Chuang static inline const struct rtw_rfe_def *rtw_get_rfe_def(struct rtw_dev *rtwdev)
116e3037485SYan-Hsuan Chuang {
117*dcbf179cSPing-Ke Shih 	const struct rtw_chip_info *chip = rtwdev->chip;
118e3037485SYan-Hsuan Chuang 	struct rtw_efuse *efuse = &rtwdev->efuse;
119e3037485SYan-Hsuan Chuang 	const struct rtw_rfe_def *rfe_def = NULL;
120e3037485SYan-Hsuan Chuang 
121e3037485SYan-Hsuan Chuang 	if (chip->rfe_defs_size == 0)
122e3037485SYan-Hsuan Chuang 		return NULL;
123e3037485SYan-Hsuan Chuang 
124e3037485SYan-Hsuan Chuang 	if (efuse->rfe_option < chip->rfe_defs_size)
125e3037485SYan-Hsuan Chuang 		rfe_def = &chip->rfe_defs[efuse->rfe_option];
126e3037485SYan-Hsuan Chuang 
127e3037485SYan-Hsuan Chuang 	rtw_dbg(rtwdev, RTW_DBG_PHY, "use rfe_def[%d]\n", efuse->rfe_option);
128e3037485SYan-Hsuan Chuang 	return rfe_def;
129e3037485SYan-Hsuan Chuang }
130e3037485SYan-Hsuan Chuang 
rtw_check_supported_rfe(struct rtw_dev * rtwdev)131e3037485SYan-Hsuan Chuang static inline int rtw_check_supported_rfe(struct rtw_dev *rtwdev)
132e3037485SYan-Hsuan Chuang {
133e3037485SYan-Hsuan Chuang 	const struct rtw_rfe_def *rfe_def = rtw_get_rfe_def(rtwdev);
134e3037485SYan-Hsuan Chuang 
135e3037485SYan-Hsuan Chuang 	if (!rfe_def || !rfe_def->phy_pg_tbl || !rfe_def->txpwr_lmt_tbl) {
136e3037485SYan-Hsuan Chuang 		rtw_err(rtwdev, "rfe %d isn't supported\n",
137e3037485SYan-Hsuan Chuang 			rtwdev->efuse.rfe_option);
138e3037485SYan-Hsuan Chuang 		return -ENODEV;
139e3037485SYan-Hsuan Chuang 	}
140e3037485SYan-Hsuan Chuang 
141e3037485SYan-Hsuan Chuang 	return 0;
142e3037485SYan-Hsuan Chuang }
143e3037485SYan-Hsuan Chuang 
144e3037485SYan-Hsuan Chuang void rtw_phy_dig_write(struct rtw_dev *rtwdev, u8 igi);
145e3037485SYan-Hsuan Chuang 
146b7414222SZong-Zhe Yang struct rtw_power_params {
147b7414222SZong-Zhe Yang 	u8 pwr_base;
148b7414222SZong-Zhe Yang 	s8 pwr_offset;
149b7414222SZong-Zhe Yang 	s8 pwr_limit;
150608d2a08SPing-Ke Shih 	s8 pwr_remnant;
1518704d0beSZong-Zhe Yang 	s8 pwr_sar;
152b7414222SZong-Zhe Yang };
153b7414222SZong-Zhe Yang 
154b7414222SZong-Zhe Yang void
155b7414222SZong-Zhe Yang rtw_get_tx_power_params(struct rtw_dev *rtwdev, u8 path,
156b7414222SZong-Zhe Yang 			u8 rate, u8 bw, u8 ch, u8 regd,
157b7414222SZong-Zhe Yang 			struct rtw_power_params *pwr_param);
158b7414222SZong-Zhe Yang 
15918a0696eSTzu-En Huang enum rtw_phy_cck_pd_lv {
16018a0696eSTzu-En Huang 	CCK_PD_LV0,
16118a0696eSTzu-En Huang 	CCK_PD_LV1,
16218a0696eSTzu-En Huang 	CCK_PD_LV2,
16318a0696eSTzu-En Huang 	CCK_PD_LV3,
16418a0696eSTzu-En Huang 	CCK_PD_LV4,
16518a0696eSTzu-En Huang 	CCK_PD_LV_MAX,
16618a0696eSTzu-En Huang };
16718a0696eSTzu-En Huang 
168e3037485SYan-Hsuan Chuang #define	MASKBYTE0		0xff
169e3037485SYan-Hsuan Chuang #define	MASKBYTE1		0xff00
170e3037485SYan-Hsuan Chuang #define	MASKBYTE2		0xff0000
171e3037485SYan-Hsuan Chuang #define	MASKBYTE3		0xff000000
172e3037485SYan-Hsuan Chuang #define	MASKHWORD		0xffff0000
173e3037485SYan-Hsuan Chuang #define	MASKLWORD		0x0000ffff
174e3037485SYan-Hsuan Chuang #define	MASKDWORD		0xffffffff
175e3037485SYan-Hsuan Chuang #define RFREG_MASK		0xfffff
176e3037485SYan-Hsuan Chuang 
177e3037485SYan-Hsuan Chuang #define	MASK7BITS		0x7f
178e3037485SYan-Hsuan Chuang #define	MASK12BITS		0xfff
179e3037485SYan-Hsuan Chuang #define	MASKH4BITS		0xf0000000
180e3037485SYan-Hsuan Chuang #define	MASK20BITS		0xfffff
181e3037485SYan-Hsuan Chuang #define	MASK24BITS		0xffffff
182e3037485SYan-Hsuan Chuang 
183e3037485SYan-Hsuan Chuang #define MASKH3BYTES		0xffffff00
184e3037485SYan-Hsuan Chuang #define MASKL3BYTES		0x00ffffff
185e3037485SYan-Hsuan Chuang #define MASKBYTE2HIGHNIBBLE	0x00f00000
186e3037485SYan-Hsuan Chuang #define MASKBYTE3LOWNIBBLE	0x0f000000
187e3037485SYan-Hsuan Chuang #define	MASKL3BYTES		0x00ffffff
188e3037485SYan-Hsuan Chuang 
189479c4ee9STzu-En Huang #define CCK_FA_AVG_RESET 0xffffffff
190479c4ee9STzu-En Huang 
191e0c27cdbSPing-Ke Shih #define LSSI_READ_ADDR_MASK	0x7f800000
192e0c27cdbSPing-Ke Shih #define LSSI_READ_EDGE_MASK	0x80000000
193e0c27cdbSPing-Ke Shih #define LSSI_READ_DATA_MASK	0xfffff
194e0c27cdbSPing-Ke Shih 
19548308726SPo-Hao Huang #define RRSR_RATE_ORDER_MAX	0xfffff
19648308726SPo-Hao Huang #define RRSR_RATE_ORDER_CCK_LEN	4
19748308726SPo-Hao Huang 
198e3037485SYan-Hsuan Chuang #endif
199