162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 262306a36Sopenharmony_ci/* Copyright(c) 2018-2019 Realtek Corporation 362306a36Sopenharmony_ci */ 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#ifndef __RTW_PHY_H_ 662306a36Sopenharmony_ci#define __RTW_PHY_H_ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include "debug.h" 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciextern u8 rtw_cck_rates[]; 1162306a36Sopenharmony_ciextern u8 rtw_ofdm_rates[]; 1262306a36Sopenharmony_ciextern u8 rtw_ht_1s_rates[]; 1362306a36Sopenharmony_ciextern u8 rtw_ht_2s_rates[]; 1462306a36Sopenharmony_ciextern u8 rtw_vht_1s_rates[]; 1562306a36Sopenharmony_ciextern u8 rtw_vht_2s_rates[]; 1662306a36Sopenharmony_ciextern u8 *rtw_rate_section[]; 1762306a36Sopenharmony_ciextern u8 rtw_rate_size[]; 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_civoid rtw_phy_init(struct rtw_dev *rtwdev); 2062306a36Sopenharmony_civoid rtw_phy_dynamic_mechanism(struct rtw_dev *rtwdev); 2162306a36Sopenharmony_ciu8 rtw_phy_rf_power_2_rssi(s8 *rf_power, u8 path_num); 2262306a36Sopenharmony_ciu32 rtw_phy_read_rf(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path, 2362306a36Sopenharmony_ci u32 addr, u32 mask); 2462306a36Sopenharmony_ciu32 rtw_phy_read_rf_sipi(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path, 2562306a36Sopenharmony_ci u32 addr, u32 mask); 2662306a36Sopenharmony_cibool rtw_phy_write_rf_reg_sipi(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path, 2762306a36Sopenharmony_ci u32 addr, u32 mask, u32 data); 2862306a36Sopenharmony_cibool rtw_phy_write_rf_reg(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path, 2962306a36Sopenharmony_ci u32 addr, u32 mask, u32 data); 3062306a36Sopenharmony_cibool rtw_phy_write_rf_reg_mix(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path, 3162306a36Sopenharmony_ci u32 addr, u32 mask, u32 data); 3262306a36Sopenharmony_civoid rtw_phy_setup_phy_cond(struct rtw_dev *rtwdev, u32 pkg); 3362306a36Sopenharmony_civoid rtw_parse_tbl_phy_cond(struct rtw_dev *rtwdev, const struct rtw_table *tbl); 3462306a36Sopenharmony_civoid rtw_parse_tbl_bb_pg(struct rtw_dev *rtwdev, const struct rtw_table *tbl); 3562306a36Sopenharmony_civoid rtw_parse_tbl_txpwr_lmt(struct rtw_dev *rtwdev, const struct rtw_table *tbl); 3662306a36Sopenharmony_civoid rtw_phy_cfg_mac(struct rtw_dev *rtwdev, const struct rtw_table *tbl, 3762306a36Sopenharmony_ci u32 addr, u32 data); 3862306a36Sopenharmony_civoid rtw_phy_cfg_agc(struct rtw_dev *rtwdev, const struct rtw_table *tbl, 3962306a36Sopenharmony_ci u32 addr, u32 data); 4062306a36Sopenharmony_civoid rtw_phy_cfg_bb(struct rtw_dev *rtwdev, const struct rtw_table *tbl, 4162306a36Sopenharmony_ci u32 addr, u32 data); 4262306a36Sopenharmony_civoid rtw_phy_cfg_rf(struct rtw_dev *rtwdev, const struct rtw_table *tbl, 4362306a36Sopenharmony_ci u32 addr, u32 data); 4462306a36Sopenharmony_civoid rtw_phy_init_tx_power(struct rtw_dev *rtwdev); 4562306a36Sopenharmony_civoid rtw_phy_load_tables(struct rtw_dev *rtwdev); 4662306a36Sopenharmony_ciu8 rtw_phy_get_tx_power_index(struct rtw_dev *rtwdev, u8 rf_path, u8 rate, 4762306a36Sopenharmony_ci enum rtw_bandwidth bw, u8 channel, u8 regd); 4862306a36Sopenharmony_civoid rtw_phy_set_tx_power_level(struct rtw_dev *rtwdev, u8 channel); 4962306a36Sopenharmony_civoid rtw_phy_tx_power_by_rate_config(struct rtw_hal *hal); 5062306a36Sopenharmony_civoid rtw_phy_tx_power_limit_config(struct rtw_hal *hal); 5162306a36Sopenharmony_civoid rtw_phy_pwrtrack_avg(struct rtw_dev *rtwdev, u8 thermal, u8 path); 5262306a36Sopenharmony_cibool rtw_phy_pwrtrack_thermal_changed(struct rtw_dev *rtwdev, u8 thermal, 5362306a36Sopenharmony_ci u8 path); 5462306a36Sopenharmony_ciu8 rtw_phy_pwrtrack_get_delta(struct rtw_dev *rtwdev, u8 path); 5562306a36Sopenharmony_cis8 rtw_phy_pwrtrack_get_pwridx(struct rtw_dev *rtwdev, 5662306a36Sopenharmony_ci struct rtw_swing_table *swing_table, 5762306a36Sopenharmony_ci u8 tbl_path, u8 therm_path, u8 delta); 5862306a36Sopenharmony_cibool rtw_phy_pwrtrack_need_lck(struct rtw_dev *rtwdev); 5962306a36Sopenharmony_cibool rtw_phy_pwrtrack_need_iqk(struct rtw_dev *rtwdev); 6062306a36Sopenharmony_civoid rtw_phy_config_swing_table(struct rtw_dev *rtwdev, 6162306a36Sopenharmony_ci struct rtw_swing_table *swing_table); 6262306a36Sopenharmony_civoid rtw_phy_set_edcca_th(struct rtw_dev *rtwdev, u8 l2h, u8 h2l); 6362306a36Sopenharmony_civoid rtw_phy_adaptivity_set_mode(struct rtw_dev *rtwdev); 6462306a36Sopenharmony_civoid rtw_phy_parsing_cfo(struct rtw_dev *rtwdev, 6562306a36Sopenharmony_ci struct rtw_rx_pkt_stat *pkt_stat); 6662306a36Sopenharmony_civoid rtw_phy_tx_path_diversity(struct rtw_dev *rtwdev); 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_cistruct rtw_txpwr_lmt_cfg_pair { 6962306a36Sopenharmony_ci u8 regd; 7062306a36Sopenharmony_ci u8 band; 7162306a36Sopenharmony_ci u8 bw; 7262306a36Sopenharmony_ci u8 rs; 7362306a36Sopenharmony_ci u8 ch; 7462306a36Sopenharmony_ci s8 txpwr_lmt; 7562306a36Sopenharmony_ci}; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_cistruct rtw_phy_pg_cfg_pair { 7862306a36Sopenharmony_ci u32 band; 7962306a36Sopenharmony_ci u32 rf_path; 8062306a36Sopenharmony_ci u32 tx_num; 8162306a36Sopenharmony_ci u32 addr; 8262306a36Sopenharmony_ci u32 bitmask; 8362306a36Sopenharmony_ci u32 data; 8462306a36Sopenharmony_ci}; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci#define RTW_DECL_TABLE_PHY_COND_CORE(name, cfg, path) \ 8762306a36Sopenharmony_ciconst struct rtw_table name ## _tbl = { \ 8862306a36Sopenharmony_ci .data = name, \ 8962306a36Sopenharmony_ci .size = ARRAY_SIZE(name), \ 9062306a36Sopenharmony_ci .parse = rtw_parse_tbl_phy_cond, \ 9162306a36Sopenharmony_ci .do_cfg = cfg, \ 9262306a36Sopenharmony_ci .rf_path = path, \ 9362306a36Sopenharmony_ci} 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci#define RTW_DECL_TABLE_PHY_COND(name, cfg) \ 9662306a36Sopenharmony_ci RTW_DECL_TABLE_PHY_COND_CORE(name, cfg, 0) 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci#define RTW_DECL_TABLE_RF_RADIO(name, path) \ 9962306a36Sopenharmony_ci RTW_DECL_TABLE_PHY_COND_CORE(name, rtw_phy_cfg_rf, RF_PATH_ ## path) 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#define RTW_DECL_TABLE_BB_PG(name) \ 10262306a36Sopenharmony_ciconst struct rtw_table name ## _tbl = { \ 10362306a36Sopenharmony_ci .data = name, \ 10462306a36Sopenharmony_ci .size = ARRAY_SIZE(name), \ 10562306a36Sopenharmony_ci .parse = rtw_parse_tbl_bb_pg, \ 10662306a36Sopenharmony_ci} 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci#define RTW_DECL_TABLE_TXPWR_LMT(name) \ 10962306a36Sopenharmony_ciconst struct rtw_table name ## _tbl = { \ 11062306a36Sopenharmony_ci .data = name, \ 11162306a36Sopenharmony_ci .size = ARRAY_SIZE(name), \ 11262306a36Sopenharmony_ci .parse = rtw_parse_tbl_txpwr_lmt, \ 11362306a36Sopenharmony_ci} 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_cistatic inline const struct rtw_rfe_def *rtw_get_rfe_def(struct rtw_dev *rtwdev) 11662306a36Sopenharmony_ci{ 11762306a36Sopenharmony_ci const struct rtw_chip_info *chip = rtwdev->chip; 11862306a36Sopenharmony_ci struct rtw_efuse *efuse = &rtwdev->efuse; 11962306a36Sopenharmony_ci const struct rtw_rfe_def *rfe_def = NULL; 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci if (chip->rfe_defs_size == 0) 12262306a36Sopenharmony_ci return NULL; 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci if (efuse->rfe_option < chip->rfe_defs_size) 12562306a36Sopenharmony_ci rfe_def = &chip->rfe_defs[efuse->rfe_option]; 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci rtw_dbg(rtwdev, RTW_DBG_PHY, "use rfe_def[%d]\n", efuse->rfe_option); 12862306a36Sopenharmony_ci return rfe_def; 12962306a36Sopenharmony_ci} 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_cistatic inline int rtw_check_supported_rfe(struct rtw_dev *rtwdev) 13262306a36Sopenharmony_ci{ 13362306a36Sopenharmony_ci const struct rtw_rfe_def *rfe_def = rtw_get_rfe_def(rtwdev); 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci if (!rfe_def || !rfe_def->phy_pg_tbl || !rfe_def->txpwr_lmt_tbl) { 13662306a36Sopenharmony_ci rtw_err(rtwdev, "rfe %d isn't supported\n", 13762306a36Sopenharmony_ci rtwdev->efuse.rfe_option); 13862306a36Sopenharmony_ci return -ENODEV; 13962306a36Sopenharmony_ci } 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci return 0; 14262306a36Sopenharmony_ci} 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_civoid rtw_phy_dig_write(struct rtw_dev *rtwdev, u8 igi); 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_cistruct rtw_power_params { 14762306a36Sopenharmony_ci u8 pwr_base; 14862306a36Sopenharmony_ci s8 pwr_offset; 14962306a36Sopenharmony_ci s8 pwr_limit; 15062306a36Sopenharmony_ci s8 pwr_remnant; 15162306a36Sopenharmony_ci s8 pwr_sar; 15262306a36Sopenharmony_ci}; 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_civoid 15562306a36Sopenharmony_cirtw_get_tx_power_params(struct rtw_dev *rtwdev, u8 path, 15662306a36Sopenharmony_ci u8 rate, u8 bw, u8 ch, u8 regd, 15762306a36Sopenharmony_ci struct rtw_power_params *pwr_param); 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_cienum rtw_phy_cck_pd_lv { 16062306a36Sopenharmony_ci CCK_PD_LV0, 16162306a36Sopenharmony_ci CCK_PD_LV1, 16262306a36Sopenharmony_ci CCK_PD_LV2, 16362306a36Sopenharmony_ci CCK_PD_LV3, 16462306a36Sopenharmony_ci CCK_PD_LV4, 16562306a36Sopenharmony_ci CCK_PD_LV_MAX, 16662306a36Sopenharmony_ci}; 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ci#define MASKBYTE0 0xff 16962306a36Sopenharmony_ci#define MASKBYTE1 0xff00 17062306a36Sopenharmony_ci#define MASKBYTE2 0xff0000 17162306a36Sopenharmony_ci#define MASKBYTE3 0xff000000 17262306a36Sopenharmony_ci#define MASKHWORD 0xffff0000 17362306a36Sopenharmony_ci#define MASKLWORD 0x0000ffff 17462306a36Sopenharmony_ci#define MASKDWORD 0xffffffff 17562306a36Sopenharmony_ci#define RFREG_MASK 0xfffff 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci#define MASK7BITS 0x7f 17862306a36Sopenharmony_ci#define MASK12BITS 0xfff 17962306a36Sopenharmony_ci#define MASKH4BITS 0xf0000000 18062306a36Sopenharmony_ci#define MASK20BITS 0xfffff 18162306a36Sopenharmony_ci#define MASK24BITS 0xffffff 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci#define MASKH3BYTES 0xffffff00 18462306a36Sopenharmony_ci#define MASKL3BYTES 0x00ffffff 18562306a36Sopenharmony_ci#define MASKBYTE2HIGHNIBBLE 0x00f00000 18662306a36Sopenharmony_ci#define MASKBYTE3LOWNIBBLE 0x0f000000 18762306a36Sopenharmony_ci#define MASKL3BYTES 0x00ffffff 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci#define CCK_FA_AVG_RESET 0xffffffff 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci#define LSSI_READ_ADDR_MASK 0x7f800000 19262306a36Sopenharmony_ci#define LSSI_READ_EDGE_MASK 0x80000000 19362306a36Sopenharmony_ci#define LSSI_READ_DATA_MASK 0xfffff 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ci#define RRSR_RATE_ORDER_MAX 0xfffff 19662306a36Sopenharmony_ci#define RRSR_RATE_ORDER_CCK_LEN 4 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci#endif 199