18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Copyright(c) 2009-2013  Realtek Corporation.*/
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef	__RTL88E_DM_H__
58c2ecf20Sopenharmony_ci#define __RTL88E_DM_H__
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#define	MAIN_ANT					0
88c2ecf20Sopenharmony_ci#define	AUX_ANT						1
98c2ecf20Sopenharmony_ci#define	MAIN_ANT_CG_TRX					1
108c2ecf20Sopenharmony_ci#define	AUX_ANT_CG_TRX					0
118c2ecf20Sopenharmony_ci#define	MAIN_ANT_CGCS_RX				0
128c2ecf20Sopenharmony_ci#define	AUX_ANT_CGCS_RX					1
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/*RF REG LIST*/
158c2ecf20Sopenharmony_ci#define	DM_REG_RF_MODE_11N				0x00
168c2ecf20Sopenharmony_ci#define	DM_REG_RF_0B_11N				0x0B
178c2ecf20Sopenharmony_ci#define	DM_REG_CHNBW_11N				0x18
188c2ecf20Sopenharmony_ci#define	DM_REG_T_METER_11N				0x24
198c2ecf20Sopenharmony_ci#define	DM_REG_RF_25_11N				0x25
208c2ecf20Sopenharmony_ci#define	DM_REG_RF_26_11N				0x26
218c2ecf20Sopenharmony_ci#define	DM_REG_RF_27_11N				0x27
228c2ecf20Sopenharmony_ci#define	DM_REG_RF_2B_11N				0x2B
238c2ecf20Sopenharmony_ci#define	DM_REG_RF_2C_11N				0x2C
248c2ecf20Sopenharmony_ci#define	DM_REG_RXRF_A3_11N				0x3C
258c2ecf20Sopenharmony_ci#define	DM_REG_T_METER_92D_11N				0x42
268c2ecf20Sopenharmony_ci#define	DM_REG_T_METER_88E_11N				0x42
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/*BB REG LIST*/
298c2ecf20Sopenharmony_ci/*PAGE 8 */
308c2ecf20Sopenharmony_ci#define	DM_REG_BB_CTRL_11N				0x800
318c2ecf20Sopenharmony_ci#define	DM_REG_RF_PIN_11N				0x804
328c2ecf20Sopenharmony_ci#define	DM_REG_PSD_CTRL_11N				0x808
338c2ecf20Sopenharmony_ci#define	DM_REG_TX_ANT_CTRL_11N				0x80C
348c2ecf20Sopenharmony_ci#define	DM_REG_BB_PWR_SAV5_11N				0x818
358c2ecf20Sopenharmony_ci#define	DM_REG_CCK_RPT_FORMAT_11N			0x824
368c2ecf20Sopenharmony_ci#define	DM_REG_RX_DEFAULT_A_11N				0x858
378c2ecf20Sopenharmony_ci#define	DM_REG_RX_DEFAULT_B_11N				0x85A
388c2ecf20Sopenharmony_ci#define	DM_REG_BB_PWR_SAV3_11N				0x85C
398c2ecf20Sopenharmony_ci#define	DM_REG_ANTSEL_CTRL_11N				0x860
408c2ecf20Sopenharmony_ci#define	DM_REG_RX_ANT_CTRL_11N				0x864
418c2ecf20Sopenharmony_ci#define	DM_REG_PIN_CTRL_11N				0x870
428c2ecf20Sopenharmony_ci#define	DM_REG_BB_PWR_SAV1_11N				0x874
438c2ecf20Sopenharmony_ci#define	DM_REG_ANTSEL_PATH_11N				0x878
448c2ecf20Sopenharmony_ci#define	DM_REG_BB_3WIRE_11N				0x88C
458c2ecf20Sopenharmony_ci#define	DM_REG_SC_CNT_11N				0x8C4
468c2ecf20Sopenharmony_ci#define	DM_REG_PSD_DATA_11N				0x8B4
478c2ecf20Sopenharmony_ci/*PAGE 9*/
488c2ecf20Sopenharmony_ci#define	DM_REG_ANT_MAPPING1_11N				0x914
498c2ecf20Sopenharmony_ci#define	DM_REG_ANT_MAPPING2_11N				0x918
508c2ecf20Sopenharmony_ci/*PAGE A*/
518c2ecf20Sopenharmony_ci#define	DM_REG_CCK_ANTDIV_PARA1_11N			0xA00
528c2ecf20Sopenharmony_ci#define	DM_REG_CCK_CCA_11N				0xA0A
538c2ecf20Sopenharmony_ci#define	DM_REG_CCK_ANTDIV_PARA2_11N			0xA0C
548c2ecf20Sopenharmony_ci#define	DM_REG_CCK_ANTDIV_PARA3_11N			0xA10
558c2ecf20Sopenharmony_ci#define	DM_REG_CCK_ANTDIV_PARA4_11N			0xA14
568c2ecf20Sopenharmony_ci#define	DM_REG_CCK_FILTER_PARA1_11N			0xA22
578c2ecf20Sopenharmony_ci#define	DM_REG_CCK_FILTER_PARA2_11N			0xA23
588c2ecf20Sopenharmony_ci#define	DM_REG_CCK_FILTER_PARA3_11N			0xA24
598c2ecf20Sopenharmony_ci#define	DM_REG_CCK_FILTER_PARA4_11N			0xA25
608c2ecf20Sopenharmony_ci#define	DM_REG_CCK_FILTER_PARA5_11N			0xA26
618c2ecf20Sopenharmony_ci#define	DM_REG_CCK_FILTER_PARA6_11N			0xA27
628c2ecf20Sopenharmony_ci#define	DM_REG_CCK_FILTER_PARA7_11N			0xA28
638c2ecf20Sopenharmony_ci#define	DM_REG_CCK_FILTER_PARA8_11N			0xA29
648c2ecf20Sopenharmony_ci#define	DM_REG_CCK_FA_RST_11N				0xA2C
658c2ecf20Sopenharmony_ci#define	DM_REG_CCK_FA_MSB_11N				0xA58
668c2ecf20Sopenharmony_ci#define	DM_REG_CCK_FA_LSB_11N				0xA5C
678c2ecf20Sopenharmony_ci#define	DM_REG_CCK_CCA_CNT_11N				0xA60
688c2ecf20Sopenharmony_ci#define	DM_REG_BB_PWR_SAV4_11N				0xA74
698c2ecf20Sopenharmony_ci/*PAGE B */
708c2ecf20Sopenharmony_ci#define	DM_REG_LNA_SWITCH_11N				0xB2C
718c2ecf20Sopenharmony_ci#define	DM_REG_PATH_SWITCH_11N				0xB30
728c2ecf20Sopenharmony_ci#define	DM_REG_RSSI_CTRL_11N				0xB38
738c2ecf20Sopenharmony_ci#define	DM_REG_CONFIG_ANTA_11N				0xB68
748c2ecf20Sopenharmony_ci#define	DM_REG_RSSI_BT_11N				0xB9C
758c2ecf20Sopenharmony_ci/*PAGE C */
768c2ecf20Sopenharmony_ci#define	DM_REG_OFDM_FA_HOLDC_11N			0xC00
778c2ecf20Sopenharmony_ci#define	DM_REG_RX_PATH_11N				0xC04
788c2ecf20Sopenharmony_ci#define	DM_REG_TRMUX_11N				0xC08
798c2ecf20Sopenharmony_ci#define	DM_REG_OFDM_FA_RSTC_11N				0xC0C
808c2ecf20Sopenharmony_ci#define	DM_REG_RXIQI_MATRIX_11N				0xC14
818c2ecf20Sopenharmony_ci#define	DM_REG_TXIQK_MATRIX_LSB1_11N			0xC4C
828c2ecf20Sopenharmony_ci#define	DM_REG_IGI_A_11N				0xC50
838c2ecf20Sopenharmony_ci#define	DM_REG_ANTDIV_PARA2_11N				0xC54
848c2ecf20Sopenharmony_ci#define	DM_REG_IGI_B_11N				0xC58
858c2ecf20Sopenharmony_ci#define	DM_REG_ANTDIV_PARA3_11N				0xC5C
868c2ecf20Sopenharmony_ci#define	DM_REG_BB_PWR_SAV2_11N				0xC70
878c2ecf20Sopenharmony_ci#define	DM_REG_RX_OFF_11N				0xC7C
888c2ecf20Sopenharmony_ci#define	DM_REG_TXIQK_MATRIXA_11N			0xC80
898c2ecf20Sopenharmony_ci#define	DM_REG_TXIQK_MATRIXB_11N			0xC88
908c2ecf20Sopenharmony_ci#define	DM_REG_TXIQK_MATRIXA_LSB2_11N			0xC94
918c2ecf20Sopenharmony_ci#define	DM_REG_TXIQK_MATRIXB_LSB2_11N			0xC9C
928c2ecf20Sopenharmony_ci#define	DM_REG_RXIQK_MATRIX_LSB_11N			0xCA0
938c2ecf20Sopenharmony_ci#define	DM_REG_ANTDIV_PARA1_11N				0xCA4
948c2ecf20Sopenharmony_ci#define	DM_REG_OFDM_FA_TYPE1_11N			0xCF0
958c2ecf20Sopenharmony_ci/*PAGE D */
968c2ecf20Sopenharmony_ci#define	DM_REG_OFDM_FA_RSTD_11N				0xD00
978c2ecf20Sopenharmony_ci#define	DM_REG_OFDM_FA_TYPE2_11N			0xDA0
988c2ecf20Sopenharmony_ci#define	DM_REG_OFDM_FA_TYPE3_11N			0xDA4
998c2ecf20Sopenharmony_ci#define	DM_REG_OFDM_FA_TYPE4_11N			0xDA8
1008c2ecf20Sopenharmony_ci/*PAGE E */
1018c2ecf20Sopenharmony_ci#define	DM_REG_TXAGC_A_6_18_11N				0xE00
1028c2ecf20Sopenharmony_ci#define	DM_REG_TXAGC_A_24_54_11N			0xE04
1038c2ecf20Sopenharmony_ci#define	DM_REG_TXAGC_A_1_MCS32_11N			0xE08
1048c2ecf20Sopenharmony_ci#define	DM_REG_TXAGC_A_MCS0_3_11N			0xE10
1058c2ecf20Sopenharmony_ci#define	DM_REG_TXAGC_A_MCS4_7_11N			0xE14
1068c2ecf20Sopenharmony_ci#define	DM_REG_TXAGC_A_MCS8_11_11N			0xE18
1078c2ecf20Sopenharmony_ci#define	DM_REG_TXAGC_A_MCS12_15_11N			0xE1C
1088c2ecf20Sopenharmony_ci#define	DM_REG_FPGA0_IQK_11N				0xE28
1098c2ecf20Sopenharmony_ci#define	DM_REG_TXIQK_TONE_A_11N				0xE30
1108c2ecf20Sopenharmony_ci#define	DM_REG_RXIQK_TONE_A_11N				0xE34
1118c2ecf20Sopenharmony_ci#define	DM_REG_TXIQK_PI_A_11N				0xE38
1128c2ecf20Sopenharmony_ci#define	DM_REG_RXIQK_PI_A_11N				0xE3C
1138c2ecf20Sopenharmony_ci#define	DM_REG_TXIQK_11N				0xE40
1148c2ecf20Sopenharmony_ci#define	DM_REG_RXIQK_11N				0xE44
1158c2ecf20Sopenharmony_ci#define	DM_REG_IQK_AGC_PTS_11N				0xE48
1168c2ecf20Sopenharmony_ci#define	DM_REG_IQK_AGC_RSP_11N				0xE4C
1178c2ecf20Sopenharmony_ci#define	DM_REG_BLUETOOTH_11N				0xE6C
1188c2ecf20Sopenharmony_ci#define	DM_REG_RX_WAIT_CCA_11N				0xE70
1198c2ecf20Sopenharmony_ci#define	DM_REG_TX_CCK_RFON_11N				0xE74
1208c2ecf20Sopenharmony_ci#define	DM_REG_TX_CCK_BBON_11N				0xE78
1218c2ecf20Sopenharmony_ci#define	DM_REG_OFDM_RFON_11N				0xE7C
1228c2ecf20Sopenharmony_ci#define	DM_REG_OFDM_BBON_11N				0xE80
1238c2ecf20Sopenharmony_ci#define DM_REG_TX2RX_11N				0xE84
1248c2ecf20Sopenharmony_ci#define	DM_REG_TX2TX_11N				0xE88
1258c2ecf20Sopenharmony_ci#define	DM_REG_RX_CCK_11N				0xE8C
1268c2ecf20Sopenharmony_ci#define	DM_REG_RX_OFDM_11N				0xED0
1278c2ecf20Sopenharmony_ci#define	DM_REG_RX_WAIT_RIFS_11N				0xED4
1288c2ecf20Sopenharmony_ci#define	DM_REG_RX2RX_11N				0xED8
1298c2ecf20Sopenharmony_ci#define	DM_REG_STANDBY_11N				0xEDC
1308c2ecf20Sopenharmony_ci#define	DM_REG_SLEEP_11N				0xEE0
1318c2ecf20Sopenharmony_ci#define	DM_REG_PMPD_ANAEN_11N				0xEEC
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/*MAC REG LIST*/
1348c2ecf20Sopenharmony_ci#define	DM_REG_BB_RST_11N				0x02
1358c2ecf20Sopenharmony_ci#define	DM_REG_ANTSEL_PIN_11N				0x4C
1368c2ecf20Sopenharmony_ci#define	DM_REG_EARLY_MODE_11N				0x4D0
1378c2ecf20Sopenharmony_ci#define	DM_REG_RSSI_MONITOR_11N				0x4FE
1388c2ecf20Sopenharmony_ci#define	DM_REG_EDCA_VO_11N				0x500
1398c2ecf20Sopenharmony_ci#define	DM_REG_EDCA_VI_11N				0x504
1408c2ecf20Sopenharmony_ci#define	DM_REG_EDCA_BE_11N				0x508
1418c2ecf20Sopenharmony_ci#define	DM_REG_EDCA_BK_11N				0x50C
1428c2ecf20Sopenharmony_ci#define	DM_REG_TXPAUSE_11N				0x522
1438c2ecf20Sopenharmony_ci#define	DM_REG_RESP_TX_11N				0x6D8
1448c2ecf20Sopenharmony_ci#define	DM_REG_ANT_TRAIN_PARA1_11N			0x7b0
1458c2ecf20Sopenharmony_ci#define	DM_REG_ANT_TRAIN_PARA2_11N			0x7b4
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci/*DIG Related*/
1498c2ecf20Sopenharmony_ci#define	DM_BIT_IGI_11N					0x0000007F
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci#define HAL_DM_DIG_DISABLE				BIT(0)
1528c2ecf20Sopenharmony_ci#define HAL_DM_HIPWR_DISABLE				BIT(1)
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci#define OFDM_TABLE_LENGTH				43
1558c2ecf20Sopenharmony_ci#define CCK_TABLE_LENGTH				33
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci#define OFDM_TABLE_SIZE					43
1588c2ecf20Sopenharmony_ci#define CCK_TABLE_SIZE					33
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#define BW_AUTO_SWITCH_HIGH_LOW				25
1618c2ecf20Sopenharmony_ci#define BW_AUTO_SWITCH_LOW_HIGH				30
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci#define DM_DIG_FA_UPPER					0x3e
1648c2ecf20Sopenharmony_ci#define DM_DIG_FA_LOWER					0x1e
1658c2ecf20Sopenharmony_ci#define DM_DIG_FA_TH0					0x200
1668c2ecf20Sopenharmony_ci#define DM_DIG_FA_TH1					0x300
1678c2ecf20Sopenharmony_ci#define DM_DIG_FA_TH2					0x400
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci#define RXPATHSELECTION_SS_TH_W				30
1708c2ecf20Sopenharmony_ci#define RXPATHSELECTION_DIFF_TH				18
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#define DM_RATR_STA_INIT				0
1738c2ecf20Sopenharmony_ci#define DM_RATR_STA_HIGH				1
1748c2ecf20Sopenharmony_ci#define DM_RATR_STA_MIDDLE				2
1758c2ecf20Sopenharmony_ci#define DM_RATR_STA_LOW					3
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci#define CTS2SELF_THVAL					30
1788c2ecf20Sopenharmony_ci#define REGC38_TH					20
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci#define WAIOTTHVAL					25
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci#define TXHIGHPWRLEVEL_NORMAL				0
1838c2ecf20Sopenharmony_ci#define TXHIGHPWRLEVEL_LEVEL1				1
1848c2ecf20Sopenharmony_ci#define TXHIGHPWRLEVEL_LEVEL2				2
1858c2ecf20Sopenharmony_ci#define TXHIGHPWRLEVEL_BT1				3
1868c2ecf20Sopenharmony_ci#define TXHIGHPWRLEVEL_BT2				4
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#define DM_TYPE_BYFW					0
1898c2ecf20Sopenharmony_ci#define DM_TYPE_BYDRIVER				1
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci#define TX_POWER_NEAR_FIELD_THRESH_LVL2			74
1928c2ecf20Sopenharmony_ci#define TX_POWER_NEAR_FIELD_THRESH_LVL1			67
1938c2ecf20Sopenharmony_ci#define TXPWRTRACK_MAX_IDX				 6
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_cistruct swat_t {
1968c2ecf20Sopenharmony_ci	u8 failure_cnt;
1978c2ecf20Sopenharmony_ci	u8 try_flag;
1988c2ecf20Sopenharmony_ci	u8 stop_trying;
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	long pre_rssi;
2018c2ecf20Sopenharmony_ci	long trying_threshold;
2028c2ecf20Sopenharmony_ci	u8 cur_antenna;
2038c2ecf20Sopenharmony_ci	u8 pre_antenna;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci};
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cienum FAT_STATE {
2088c2ecf20Sopenharmony_ci	FAT_NORMAL_STATE = 0,
2098c2ecf20Sopenharmony_ci	FAT_TRAINING_STATE = 1,
2108c2ecf20Sopenharmony_ci};
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_cienum tag_dynamic_init_gain_operation_type_definition {
2138c2ecf20Sopenharmony_ci	DIG_TYPE_THRESH_HIGH = 0,
2148c2ecf20Sopenharmony_ci	DIG_TYPE_THRESH_LOW = 1,
2158c2ecf20Sopenharmony_ci	DIG_TYPE_BACKOFF = 2,
2168c2ecf20Sopenharmony_ci	DIG_TYPE_RX_GAIN_MIN = 3,
2178c2ecf20Sopenharmony_ci	DIG_TYPE_RX_GAIN_MAX = 4,
2188c2ecf20Sopenharmony_ci	DIG_TYPE_ENABLE = 5,
2198c2ecf20Sopenharmony_ci	DIG_TYPE_DISABLE = 6,
2208c2ecf20Sopenharmony_ci	DIG_OP_TYPE_MAX
2218c2ecf20Sopenharmony_ci};
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_cienum dm_1r_cca_e {
2248c2ecf20Sopenharmony_ci	CCA_1R = 0,
2258c2ecf20Sopenharmony_ci	CCA_2R = 1,
2268c2ecf20Sopenharmony_ci	CCA_MAX = 2,
2278c2ecf20Sopenharmony_ci};
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_cienum dm_rf_e {
2308c2ecf20Sopenharmony_ci	RF_SAVE = 0,
2318c2ecf20Sopenharmony_ci	RF_NORMAL = 1,
2328c2ecf20Sopenharmony_ci	RF_MAX = 2,
2338c2ecf20Sopenharmony_ci};
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_cienum dm_sw_ant_switch_e {
2368c2ecf20Sopenharmony_ci	ANS_ANTENNA_B = 1,
2378c2ecf20Sopenharmony_ci	ANS_ANTENNA_A = 2,
2388c2ecf20Sopenharmony_ci	ANS_ANTENNA_MAX = 3,
2398c2ecf20Sopenharmony_ci};
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cienum pwr_track_control_method {
2428c2ecf20Sopenharmony_ci	BBSWING,
2438c2ecf20Sopenharmony_ci	TXAGC
2448c2ecf20Sopenharmony_ci};
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_civoid rtl88e_dm_set_tx_ant_by_tx_info(struct ieee80211_hw *hw,
2478c2ecf20Sopenharmony_ci				     u8 *pdesc, u32 mac_id);
2488c2ecf20Sopenharmony_civoid rtl88e_dm_ant_sel_statistics(struct ieee80211_hw *hw,
2498c2ecf20Sopenharmony_ci				  u8 antsel_tr_mux, u32 mac_id,
2508c2ecf20Sopenharmony_ci				  u32 rx_pwdb_all);
2518c2ecf20Sopenharmony_civoid rtl88e_dm_fast_antenna_training_callback(struct timer_list *t);
2528c2ecf20Sopenharmony_civoid rtl88e_dm_init(struct ieee80211_hw *hw);
2538c2ecf20Sopenharmony_civoid rtl88e_dm_watchdog(struct ieee80211_hw *hw);
2548c2ecf20Sopenharmony_civoid rtl88e_dm_write_dig(struct ieee80211_hw *hw);
2558c2ecf20Sopenharmony_civoid rtl88e_dm_init_edca_turbo(struct ieee80211_hw *hw);
2568c2ecf20Sopenharmony_civoid rtl88e_dm_check_txpower_tracking(struct ieee80211_hw *hw);
2578c2ecf20Sopenharmony_civoid rtl88e_dm_init_rate_adaptive_mask(struct ieee80211_hw *hw);
2588c2ecf20Sopenharmony_civoid rtl88e_dm_txpower_track_adjust(struct ieee80211_hw *hw,
2598c2ecf20Sopenharmony_ci	u8 type, u8 *pdirection, u32 *poutwrite_val);
2608c2ecf20Sopenharmony_ci#endif
261