From 820cb500ad4b4fd09954f4f8e67b069185943c88 Mon Sep 17 00:00:00 2001 From: ivanovborislav <81085106+ivanovborislav@users.noreply.github.com> Date: Sun, 21 Nov 2021 14:41:10 +0200 Subject: [PATCH] Add files via upload --- hal/phydm/halrf/halphyrf_ap.c | 1674 ++++++++ hal/phydm/halrf/halphyrf_ap.h | 170 + hal/phydm/halrf/halphyrf_ce.c | 1180 ++++++ hal/phydm/halrf/halphyrf_ce.h | 123 + hal/phydm/halrf/halphyrf_iot.c | 664 +++ hal/phydm/halrf/halphyrf_iot.h | 137 + hal/phydm/halrf/halphyrf_win.c | 1113 +++++ hal/phydm/halrf/halphyrf_win.h | 132 + hal/phydm/halrf/halrf.c | 4427 ++++++++++++++++++++ hal/phydm/halrf/halrf.h | 814 ++++ hal/phydm/halrf/halrf_debug.c | 395 ++ hal/phydm/halrf/halrf_debug.h | 140 + hal/phydm/halrf/halrf_dpk.h | 163 + hal/phydm/halrf/halrf_features.h | 43 + hal/phydm/halrf/halrf_iqk.h | 157 + hal/phydm/halrf/halrf_kfree.c | 3958 +++++++++++++++++ hal/phydm/halrf/halrf_kfree.h | 296 ++ hal/phydm/halrf/halrf_powertracking.c | 200 + hal/phydm/halrf/halrf_powertracking.h | 43 + hal/phydm/halrf/halrf_powertracking_ap.c | 1290 ++++++ hal/phydm/halrf/halrf_powertracking_ap.h | 407 ++ hal/phydm/halrf/halrf_powertracking_ce.c | 969 +++++ hal/phydm/halrf/halrf_powertracking_ce.h | 331 ++ hal/phydm/halrf/halrf_powertracking_iot.c | 1004 +++++ hal/phydm/halrf/halrf_powertracking_iot.h | 372 ++ hal/phydm/halrf/halrf_powertracking_win.c | 936 +++++ hal/phydm/halrf/halrf_powertracking_win.h | 306 ++ hal/phydm/halrf/halrf_psd.c | 647 +++ hal/phydm/halrf/halrf_psd.h | 60 + hal/phydm/halrf/halrf_txgapcal.c | 300 ++ hal/phydm/halrf/halrf_txgapcal.h | 31 + hal/phydm/halrf/rtl8188e/halrf_8188e_ap.c | 1257 ++++++ hal/phydm/halrf/rtl8188e/halrf_8188e_ap.h | 104 + hal/phydm/halrf/rtl8188e/halrf_8188e_ce.c | 1600 +++++++ hal/phydm/halrf/rtl8188e/halrf_8188e_ce.h | 59 + hal/phydm/halrf/rtl8188e/halrf_8188e_win.c | 1799 ++++++++ hal/phydm/halrf/rtl8188e/halrf_8188e_win.h | 136 + 37 files changed, 27437 insertions(+) create mode 100644 hal/phydm/halrf/halphyrf_ap.c create mode 100644 hal/phydm/halrf/halphyrf_ap.h create mode 100644 hal/phydm/halrf/halphyrf_ce.c create mode 100644 hal/phydm/halrf/halphyrf_ce.h create mode 100644 hal/phydm/halrf/halphyrf_iot.c create mode 100644 hal/phydm/halrf/halphyrf_iot.h create mode 100644 hal/phydm/halrf/halphyrf_win.c create mode 100644 hal/phydm/halrf/halphyrf_win.h create mode 100644 hal/phydm/halrf/halrf.c create mode 100644 hal/phydm/halrf/halrf.h create mode 100644 hal/phydm/halrf/halrf_debug.c create mode 100644 hal/phydm/halrf/halrf_debug.h create mode 100644 hal/phydm/halrf/halrf_dpk.h create mode 100644 hal/phydm/halrf/halrf_features.h create mode 100644 hal/phydm/halrf/halrf_iqk.h create mode 100644 hal/phydm/halrf/halrf_kfree.c create mode 100644 hal/phydm/halrf/halrf_kfree.h create mode 100644 hal/phydm/halrf/halrf_powertracking.c create mode 100644 hal/phydm/halrf/halrf_powertracking.h create mode 100644 hal/phydm/halrf/halrf_powertracking_ap.c create mode 100644 hal/phydm/halrf/halrf_powertracking_ap.h create mode 100644 hal/phydm/halrf/halrf_powertracking_ce.c create mode 100644 hal/phydm/halrf/halrf_powertracking_ce.h create mode 100644 hal/phydm/halrf/halrf_powertracking_iot.c create mode 100644 hal/phydm/halrf/halrf_powertracking_iot.h create mode 100644 hal/phydm/halrf/halrf_powertracking_win.c create mode 100644 hal/phydm/halrf/halrf_powertracking_win.h create mode 100644 hal/phydm/halrf/halrf_psd.c create mode 100644 hal/phydm/halrf/halrf_psd.h create mode 100644 hal/phydm/halrf/halrf_txgapcal.c create mode 100644 hal/phydm/halrf/halrf_txgapcal.h create mode 100644 hal/phydm/halrf/rtl8188e/halrf_8188e_ap.c create mode 100644 hal/phydm/halrf/rtl8188e/halrf_8188e_ap.h create mode 100644 hal/phydm/halrf/rtl8188e/halrf_8188e_ce.c create mode 100644 hal/phydm/halrf/rtl8188e/halrf_8188e_ce.h create mode 100644 hal/phydm/halrf/rtl8188e/halrf_8188e_win.c create mode 100644 hal/phydm/halrf/rtl8188e/halrf_8188e_win.h diff --git a/hal/phydm/halrf/halphyrf_ap.c b/hal/phydm/halrf/halphyrf_ap.c new file mode 100644 index 0000000..857f019 --- /dev/null +++ b/hal/phydm/halrf/halphyrf_ap.c @@ -0,0 +1,1674 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#include "mp_precomp.h" +#include "phydm_precomp.h" + +#ifndef index_mapping_NUM_88E + #define index_mapping_NUM_88E 15 +#endif + +/* #if(DM_ODM_SUPPORT_TYPE & ODM_WIN) */ + +#define CALCULATE_SWINGTALBE_OFFSET(_offset, _direction, _size, _delta_thermal) \ + do {\ + for (_offset = 0; _offset < _size; _offset++) { \ + \ + if (_delta_thermal < thermal_threshold[_direction][_offset]) { \ + \ + if (_offset != 0)\ + _offset--;\ + break;\ + } \ + } \ + if (_offset >= _size)\ + _offset = _size-1;\ + } while (0) + +void odm_clear_txpowertracking_state( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct rtl8192cd_priv *priv = dm->priv; + + u8 i; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "===>%s\n", __func__); + + for (i = 0; i < MAX_RF_PATH; i++) { + cali_info->absolute_ofdm_swing_idx[i] = 0; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "cali_info->absolute_ofdm_swing_idx[%d]=%d\n", + i, cali_info->absolute_ofdm_swing_idx[i]); + } + + dm->rf_calibrate_info.thermal_value = 0; + dm->rf_calibrate_info.thermal_value_lck = 0; + dm->rf_calibrate_info.thermal_value_iqk = 0; +} + +void configure_txpower_track( + void *dm_void, + struct txpwrtrack_cfg *config +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; +#if RTL8812A_SUPPORT +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + /* if (IS_HARDWARE_TYPE_8812(dm->adapter)) */ + if (dm->support_ic_type == ODM_RTL8812) + configure_txpower_track_8812a(config); + /* else */ +#endif +#endif + +#if RTL8814A_SUPPORT + if (dm->support_ic_type == ODM_RTL8814A) + configure_txpower_track_8814a(config); +#endif + + +#if RTL8188E_SUPPORT + if (dm->support_ic_type == ODM_RTL8188E) + configure_txpower_track_8188e(config); +#endif + +#if RTL8197F_SUPPORT + if (dm->support_ic_type == ODM_RTL8197F) + configure_txpower_track_8197f(config); +#endif + +#if RTL8822B_SUPPORT + if (dm->support_ic_type == ODM_RTL8822B) + configure_txpower_track_8822b(config); +#endif + +#if RTL8192F_SUPPORT + if (dm->support_ic_type == ODM_RTL8192F) + configure_txpower_track_8192f(config); +#endif + +#if RTL8198F_SUPPORT + if (dm->support_ic_type == ODM_RTL8198F) + configure_txpower_track_8198f(config); +#endif + +#if RTL8814B_SUPPORT + if (dm->support_ic_type == ODM_RTL8814B) + configure_txpower_track_8814b(config); +#endif + +#if RTL8812F_SUPPORT + if (dm->support_ic_type == ODM_RTL8812F) + configure_txpower_track_8812f(config); +#endif + +#if RTL8197G_SUPPORT + if (dm->support_ic_type == ODM_RTL8197G) + configure_txpower_track_8197g(config); +#endif + +} + +#if (RTL8192E_SUPPORT == 1) +void +odm_txpowertracking_callback_thermal_meter_92e( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + u8 thermal_value = 0, delta, delta_IQK, delta_LCK, channel, is_decrease, rf_mimo_mode; + u8 thermal_value_avg_count = 0; + u8 OFDM_min_index = 10; /* OFDM BB Swing should be less than +2.5dB, which is required by Arthur */ + s8 OFDM_index[2], index ; + u32 thermal_value_avg = 0, reg0x18; + u32 i = 0, j = 0, rf; + s32 value32, CCK_index = 0, ele_A, ele_D, ele_C, X, Y; + struct rtl8192cd_priv *priv = dm->priv; + + rf_mimo_mode = dm->rf_type; + /* RF_DBG(dm,DBG_RF_TX_PWR_TRACK,"%s:%d rf_mimo_mode:%d\n", __FUNCTION__, __LINE__, rf_mimo_mode); */ + +#ifdef MP_TEST + if ((OPMODE & WIFI_MP_STATE) || *(dm->mp_mode)) { + channel = priv->pshare->working_channel; + if (priv->pshare->mp_txpwr_tracking == false) + return; + } else +#endif + { + channel = (priv->pmib->dot11RFEntry.dot11channel); + } + + thermal_value = (unsigned char)odm_get_rf_reg(dm, RF_PATH_A, ODM_RF_T_METER_92E, 0xfc00); /* 0x42: RF Reg[15:10] 88E */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "\nReadback Thermal Meter = 0x%x pre thermal meter 0x%x EEPROMthermalmeter 0x%x\n", thermal_value, priv->pshare->thermal_value, priv->pmib->dot11RFEntry.ther); + + + switch (rf_mimo_mode) { + case RF_1T1R: + rf = 1; + break; + case RF_2T2R: + rf = 2; + break; + default: + rf = 2; + break; + } + + /* Query OFDM path A default setting Bit[31:21] */ + ele_D = phy_query_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKOFDM_D); + for (i = 0; i < OFDM_TABLE_SIZE_92E; i++) { + if (ele_D == (ofdm_swing_table_92e[i] >> 22)) { + OFDM_index[0] = (unsigned char)i; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "PathA 0xC80[31:22] = 0x%x, OFDM_index=%d\n", ele_D, OFDM_index[0]); + break; + } + } + + /* Query OFDM path B default setting */ + if (rf_mimo_mode == RF_2T2R) { + ele_D = phy_query_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKOFDM_D); + for (i = 0; i < OFDM_TABLE_SIZE_92E; i++) { + if (ele_D == (ofdm_swing_table_92e[i] >> 22)) { + OFDM_index[1] = (unsigned char)i; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "PathB 0xC88[31:22] = 0x%x, OFDM_index=%d\n", ele_D, OFDM_index[1]); + break; + } + } + } + + /* calculate average thermal meter */ + { + priv->pshare->thermal_value_avg_88xx[priv->pshare->thermal_value_avg_index_88xx] = thermal_value; + priv->pshare->thermal_value_avg_index_88xx++; + if (priv->pshare->thermal_value_avg_index_88xx == AVG_THERMAL_NUM_88XX) + priv->pshare->thermal_value_avg_index_88xx = 0; + + for (i = 0; i < AVG_THERMAL_NUM_88XX; i++) { + if (priv->pshare->thermal_value_avg_88xx[i]) { + thermal_value_avg += priv->pshare->thermal_value_avg_88xx[i]; + thermal_value_avg_count++; + } + } + + if (thermal_value_avg_count) { + thermal_value = (unsigned char)(thermal_value_avg / thermal_value_avg_count); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "AVG Thermal Meter = 0x%x\n", thermal_value); + } + } + + /* Initialize */ + if (!priv->pshare->thermal_value) { + priv->pshare->thermal_value = priv->pmib->dot11RFEntry.ther; + priv->pshare->thermal_value_iqk = thermal_value; + priv->pshare->thermal_value_lck = thermal_value; + } + + if (thermal_value != priv->pshare->thermal_value) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "\n******** START POWER TRACKING ********\n"); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "\nReadback Thermal Meter = 0x%x pre thermal meter 0x%x EEPROMthermalmeter 0x%x\n", thermal_value, priv->pshare->thermal_value, priv->pmib->dot11RFEntry.ther); + + delta = RTL_ABS(thermal_value, priv->pmib->dot11RFEntry.ther); + delta_IQK = RTL_ABS(thermal_value, priv->pshare->thermal_value_iqk); + delta_LCK = RTL_ABS(thermal_value, priv->pshare->thermal_value_lck); + is_decrease = ((thermal_value < priv->pmib->dot11RFEntry.ther) ? 1 : 0); + +#ifdef _TRACKING_TABLE_FILE + if (priv->pshare->rf_ft_var.pwr_track_file) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "diff: (%s)%d ==> get index from table : %d)\n", (is_decrease ? "-" : "+"), delta, get_tx_tracking_index(priv, channel, i, delta, is_decrease, 0)); + + if (is_decrease) { + for (i = 0; i < rf; i++) { + OFDM_index[i] = priv->pshare->OFDM_index0[i] + get_tx_tracking_index(priv, channel, i, delta, is_decrease, 0); + OFDM_index[i] = ((OFDM_index[i] > (OFDM_TABLE_SIZE_92E- 1)) ? (OFDM_TABLE_SIZE_92E - 1) : OFDM_index[i]); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, ">>> decrese power ---> new OFDM_INDEX:%d (%d + %d)\n", OFDM_index[i], priv->pshare->OFDM_index0[i], get_tx_tracking_index(priv, channel, i, delta, is_decrease, 0)); + CCK_index = priv->pshare->CCK_index0 + get_tx_tracking_index(priv, channel, i, delta, is_decrease, 1); + CCK_index = ((CCK_index > (CCK_TABLE_SIZE_92E - 1)) ? (CCK_TABLE_SIZE_92E - 1) : CCK_index); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, ">>> Decrese power ---> new CCK_INDEX:%d (%d + %d)\n", CCK_index, priv->pshare->CCK_index0, get_tx_tracking_index(priv, channel, i, delta, is_decrease, 1)); + } + } else { + for (i = 0; i < rf; i++) { + OFDM_index[i] = priv->pshare->OFDM_index0[i] - get_tx_tracking_index(priv, channel, i, delta, is_decrease, 0); + OFDM_index[i] = ((OFDM_index[i] < OFDM_min_index) ? OFDM_min_index : OFDM_index[i]); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, ">>> Increse power ---> new OFDM_INDEX:%d (%d - %d)\n", OFDM_index[i], priv->pshare->OFDM_index0[i], get_tx_tracking_index(priv, channel, i, delta, is_decrease, 0)); + CCK_index = priv->pshare->CCK_index0 - get_tx_tracking_index(priv, channel, i, delta, is_decrease, 1); + CCK_index = ((CCK_index < 0) ? 0 : CCK_index); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, ">>> Increse power ---> new CCK_INDEX:%d (%d - %d)\n", CCK_index, priv->pshare->CCK_index0, get_tx_tracking_index(priv, channel, i, delta, is_decrease, 1)); + } + } + } +#endif /* CFG_TRACKING_TABLE_FILE */ + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "ofdm_swing_table_92e[(unsigned int)OFDM_index[0]] = %x\n", ofdm_swing_table_92e[(unsigned int)OFDM_index[0]]); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "ofdm_swing_table_92e[(unsigned int)OFDM_index[1]] = %x\n", ofdm_swing_table_92e[(unsigned int)OFDM_index[1]]); + + /* Adujst OFDM Ant_A according to IQK result */ + ele_D = (ofdm_swing_table_92e[(unsigned int)OFDM_index[0]] & 0xFFC00000) >> 22; + X = priv->pshare->rege94; + Y = priv->pshare->rege9c; + + if (X != 0) { + if ((X & 0x00000200) != 0) + X = X | 0xFFFFFC00; + ele_A = ((X * ele_D) >> 8) & 0x000003FF; + + /* new element C = element D x Y */ + if ((Y & 0x00000200) != 0) + Y = Y | 0xFFFFFC00; + ele_C = ((Y * ele_D) >> 8) & 0x000003FF; + + /* wirte new elements A, C, D to regC80 and regC94, element B is always 0 */ + value32 = (ele_D << 22) | ((ele_C & 0x3F) << 16) | ele_A; + phy_set_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD, value32); + + value32 = (ele_C & 0x000003C0) >> 6; + phy_set_bb_reg(priv, REG_OFDM_0_XC_TX_AFE, MASKH4BITS, value32); + + value32 = ((X * ele_D) >> 7) & 0x01; + phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), value32); + } else { + phy_set_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD, ofdm_swing_table_92e[(unsigned int)OFDM_index[0]]); + phy_set_bb_reg(priv, REG_OFDM_0_XC_TX_AFE, MASKH4BITS, 0x00); + phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), 0x00); + } + + set_CCK_swing_index(priv, CCK_index); + + if (rf == 2) { + ele_D = (ofdm_swing_table_92e[(unsigned int)OFDM_index[1]] & 0xFFC00000) >> 22; + X = priv->pshare->regeb4; + Y = priv->pshare->regebc; + + if (X != 0) { + if ((X & 0x00000200) != 0) /* consider minus */ + X = X | 0xFFFFFC00; + ele_A = ((X * ele_D) >> 8) & 0x000003FF; + + /* new element C = element D x Y */ + if ((Y & 0x00000200) != 0) + Y = Y | 0xFFFFFC00; + ele_C = ((Y * ele_D) >> 8) & 0x00003FF; + + /* wirte new elements A, C, D to regC88 and regC9C, element B is always 0 */ + value32 = (ele_D << 22) | ((ele_C & 0x3F) << 16) | ele_A; + phy_set_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD, value32); + + value32 = (ele_C & 0x000003C0) >> 6; + phy_set_bb_reg(priv, REG_OFDM_0_XD_TX_AFE, MASKH4BITS, value32); + + value32 = ((X * ele_D) >> 7) & 0x01; + phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), value32); + } else { + phy_set_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD, ofdm_swing_table_92e[(unsigned int)OFDM_index[1]]); + phy_set_bb_reg(priv, REG_OFDM_0_XD_TX_AFE, MASKH4BITS, 0x00); + phy_set_bb_reg(priv, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), 0x00); + } + + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "0xc80 = 0x%x\n", phy_query_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD)); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "0xc88 = 0x%x\n", phy_query_bb_reg(priv, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD)); + + if ((delta_IQK > 3) && (!iqk_info->rfk_forbidden)) { + priv->pshare->thermal_value_iqk = thermal_value; +#ifdef MP_TEST +#endif if (!(*(dm->mp_mode) && (OPMODE & (WIFI_MP_CTX_BACKGROUND | WIFI_MP_CTX_PACKET)))) + + halrf_iqk_trigger(dm, false); + } + + if ((delta_LCK > 8) && (!iqk_info->rfk_forbidden)) { + RTL_W8(0x522, 0xff); + reg0x18 = phy_query_rf_reg(priv, RF_PATH_A, 0x18, MASK20BITS, 1); + phy_set_rf_reg(priv, RF_PATH_A, 0xB4, BIT(14), 1); + phy_set_rf_reg(priv, RF_PATH_A, 0x18, BIT(15), 1); + delay_ms(1); + phy_set_rf_reg(priv, RF_PATH_A, 0xB4, BIT(14), 0); + phy_set_rf_reg(priv, RF_PATH_A, 0x18, MASK20BITS, reg0x18); + RTL_W8(0x522, 0x0); + priv->pshare->thermal_value_lck = thermal_value; + } + } + + /* update thermal meter value */ + priv->pshare->thermal_value = thermal_value; + for (i = 0 ; i < rf ; i++) + priv->pshare->OFDM_index[i] = OFDM_index[i]; + priv->pshare->CCK_index = CCK_index; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "\n******** END:%s() ********\n", __FUNCTION__); +} +#endif + +#if (RTL8814B_SUPPORT == 1 || RTL8812F_SUPPORT == 1 || RTL8822C_SUPPORT == 1 || RTL8197G_SUPPORT == 1) +void +odm_txpowertracking_callback_thermal_meter_jaguar_series4(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct dm_iqk_info *iqk_info = &dm->IQK_info; + struct _hal_rf_ *rf = &dm->rf_table; + struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data; + struct rtl8192cd_priv *priv = dm->priv; + struct txpwrtrack_cfg c; + + if (!(rf->rf_supportability & HAL_RF_TX_PWR_TRACK)) + return; + + u8 thermal_value[MAX_RF_PATH] = {0}, delta[MAX_RF_PATH] = {0}; + u8 delta_swing_table_idx_tup[DELTA_SWINGIDX_SIZE] = {0}; + u8 delta_swing_table_idx_tdown[DELTA_SWINGIDX_SIZE] = {0}; + u8 delta_LCK = 0, delta_IQK = 0, i = 0, j = 0, p; + u8 thermal_value_avg_count[MAX_RF_PATH] = {0}; + u32 thermal_value_avg[MAX_RF_PATH] = {0}; + s8 thermal_value_temp[MAX_RF_PATH] = {0}; + + u8 *pwrtrk_tab_up_a = NULL; + u8 *pwrtrk_tab_down_a = NULL; + u8 *pwrtrk_tab_up_b = NULL; + u8 *pwrtrk_tab_down_b = NULL; + u8 *pwrtrk_tab_up_c = NULL; + u8 *pwrtrk_tab_down_c = NULL; + u8 *pwrtrk_tab_up_d = NULL; + u8 *pwrtrk_tab_down_d = NULL; + u8 tracking_method = MIX_MODE; + + configure_txpower_track(dm, &c); + + (*c.get_delta_swing_table)(dm, + (u8 **)&pwrtrk_tab_up_a, (u8 **)&pwrtrk_tab_down_a, + (u8 **)&pwrtrk_tab_up_b, (u8 **)&pwrtrk_tab_down_b); + + if (GET_CHIP_VER(priv) == VERSION_8814B) { + (*c.get_delta_swing_table8814only)(dm, + (u8 **)&pwrtrk_tab_up_c, (u8 **)&pwrtrk_tab_down_c, + (u8 **)&pwrtrk_tab_up_d, (u8 **)&pwrtrk_tab_down_d); + } + + cali_info->txpowertracking_callback_cnt++; + cali_info->is_txpowertracking_init = true; + + /* Initialize */ + if (!dm->rf_calibrate_info.thermal_value) + dm->rf_calibrate_info.thermal_value = + priv->pmib->dot11RFEntry.thermal[RF_PATH_A]; + + if (!dm->rf_calibrate_info.thermal_value_lck) + dm->rf_calibrate_info.thermal_value_lck = + priv->pmib->dot11RFEntry.thermal[RF_PATH_A]; + + if (!dm->rf_calibrate_info.thermal_value_iqk) + dm->rf_calibrate_info.thermal_value_iqk = + priv->pmib->dot11RFEntry.thermal[RF_PATH_A]; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "===>odm_txpowertracking_callback_thermal_meter\n cali_info->bb_swing_idx_cck_base: %d, cali_info->bb_swing_idx_ofdm_base[A]: %d, cali_info->default_ofdm_index: %d\n", + cali_info->bb_swing_idx_cck_base, cali_info->bb_swing_idx_ofdm_base_path[RF_PATH_A], cali_info->default_ofdm_index); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->txpowertrack_control=%d\n", cali_info->txpowertrack_control); + + for (i = 0; i < c.rf_path_count; i++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "PGthermal[%d]=0x%x(%d)\n", i, + priv->pmib->dot11RFEntry.thermal[i], + priv->pmib->dot11RFEntry.thermal[i]); + + if (priv->pmib->dot11RFEntry.thermal[i] == 0xff || + priv->pmib->dot11RFEntry.thermal[i] == 0x0) + return; + } + if (dm->support_ic_type & (ODM_RTL8822C | ODM_RTL8812F)) { + for (i = 0; i < c.rf_path_count; i++) + thermal_value[i] = (u8)odm_get_rf_reg(dm, i, c.thermal_reg_addr, 0x7e); /* 0x42: RF Reg[6:1] Thermal Trim*/ + } else if (dm->support_ic_type == ODM_RTL8197G) { + for (i = 0; i < c.rf_path_count; i++) + thermal_value[i] = (u8)odm_get_rf_reg(dm, i, RF_0xf6, 0x7E000); + } else { + for (i = 0; i < c.rf_path_count; i++) { + thermal_value[i] = (u8)odm_get_rf_reg(dm, i, c.thermal_reg_addr, 0xfc00); /* 0x42: RF Reg[15:10] 88E */ + + if (dm->support_ic_type == ODM_RTL8814B) { + thermal_value_temp[i] = (s8)thermal_value[i] + phydm_get_multi_thermal_offset(dm, i); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "thermal_value_temp[%d](%d) = thermal_value[%d](%d) + multi_thermal_trim(%d)\n", i, thermal_value_temp[i], i, thermal_value[i], phydm_get_multi_thermal_offset(dm, i)); + } else { + thermal_value_temp[i] = (s8)thermal_value[i] + phydm_get_thermal_offset(dm); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "thermal_value_temp[%d](%d) = thermal_value[%d](%d) + thermal_trim(%d)\n", i, thermal_value_temp[i], i, thermal_value[i], phydm_get_thermal_offset(dm)); + } + + if (thermal_value_temp[i] > 63) + thermal_value[i] = 63; + else if (thermal_value_temp[i] < 0) + thermal_value[i] = 0; + else + thermal_value[i] = thermal_value_temp[i]; + } + } + + for (j = 0; j < c.rf_path_count; j++) { + cali_info->thermal_value_avg_path[j][cali_info->thermal_value_avg_index_path[j]] = thermal_value[j]; + cali_info->thermal_value_avg_index_path[j]++; + if (cali_info->thermal_value_avg_index_path[j] == c.average_thermal_num) /*Average times = c.average_thermal_num*/ + cali_info->thermal_value_avg_index_path[j] = 0; + + + for (i = 0; i < c.average_thermal_num; i++) { + if (cali_info->thermal_value_avg_path[j][i]) { + thermal_value_avg[j] += cali_info->thermal_value_avg_path[j][i]; + thermal_value_avg_count[j]++; + } + } + + if (thermal_value_avg_count[j]) { /* Calculate Average thermal_value after average enough times */ + thermal_value[j] = (u8)(thermal_value_avg[j] / thermal_value_avg_count[j]); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "PGthermal[%d] = 0x%x(%d), AVG Thermal Meter = 0x%x(%d)\n", j, + priv->pmib->dot11RFEntry.thermal[j], + priv->pmib->dot11RFEntry.thermal[j], + thermal_value[j], + thermal_value[j]); + } + /* 4 5. Calculate delta, delta_LCK, delta_IQK. */ + + /* "delta" here is used to determine whether thermal value changes or not. */ + delta[j] = RTL_ABS(thermal_value[j], priv->pmib->dot11RFEntry.thermal[j]); + delta_LCK = RTL_ABS(thermal_value[RF_PATH_A], dm->rf_calibrate_info.thermal_value_lck); + delta_IQK = RTL_ABS(thermal_value[RF_PATH_A], dm->rf_calibrate_info.thermal_value_iqk); + } + + /*4 6. If necessary, do LCK.*/ + for (i = 0; i < c.rf_path_count; i++) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "(delta[%d], delta_LCK, delta_IQK) = (%d, %d, %d)\n", i, delta[i], delta_LCK, delta_IQK); + + /* Wait sacn to do LCK by RF Jenyu*/ + if( (*dm->is_scan_in_process == false) && (!iqk_info->rfk_forbidden)) { + /* Delta temperature is equal to or larger than 20 centigrade.*/ + if (delta_LCK >= c.threshold_iqk) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_LCK(%d) >= threshold_iqk(%d)\n", delta_LCK, c.threshold_iqk); + cali_info->thermal_value_lck = thermal_value[RF_PATH_A]; + + /*Use RTLCK, so close power tracking driver LCK*/ + if ((!(dm->support_ic_type & ODM_RTL8814A)) && (!(dm->support_ic_type & ODM_RTL8822B))) { + if (c.phy_lc_calibrate) + (*c.phy_lc_calibrate)(dm); + } else + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Do not do LCK\n"); + } + } + + /*3 7. If necessary, move the index of swing table to adjust Tx power.*/ +#ifdef _TRACKING_TABLE_FILE + for (i = 0; i < c.rf_path_count; i++) { + if (i == RF_PATH_B) { + odm_move_memory(dm, delta_swing_table_idx_tup, pwrtrk_tab_up_b, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, pwrtrk_tab_down_b, DELTA_SWINGIDX_SIZE); + } else if (i == RF_PATH_C) { + odm_move_memory(dm, delta_swing_table_idx_tup, pwrtrk_tab_up_c, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, pwrtrk_tab_down_c, DELTA_SWINGIDX_SIZE); + } else if (i == RF_PATH_D) { + odm_move_memory(dm, delta_swing_table_idx_tup, pwrtrk_tab_up_d, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, pwrtrk_tab_down_d, DELTA_SWINGIDX_SIZE); + } else { + odm_move_memory(dm, delta_swing_table_idx_tup, pwrtrk_tab_up_a, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, pwrtrk_tab_down_a, DELTA_SWINGIDX_SIZE); + } + + cali_info->delta_power_index_last_path[i] = cali_info->delta_power_index_path[i]; /*recording poer index offset*/ + delta[i] = thermal_value[i] > priv->pmib->dot11RFEntry.thermal[i] ? (thermal_value[i] - priv->pmib->dot11RFEntry.thermal[i]) : (priv->pmib->dot11RFEntry.thermal[i] - thermal_value[i]); + + if (delta[i] >= TXPWR_TRACK_TABLE_SIZE) + delta[i] = TXPWR_TRACK_TABLE_SIZE - 1; + + if (thermal_value[i] > priv->pmib->dot11RFEntry.thermal[i]) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tup[%d]=%d Path=%d\n", delta[i], delta_swing_table_idx_tup[delta[i]], i); + + cali_info->delta_power_index_path[i] = delta_swing_table_idx_tup[delta[i]]; + cali_info->absolute_ofdm_swing_idx[i] = delta_swing_table_idx_tup[delta[i]]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher and cali_info->absolute_ofdm_swing_idx[%d]=%d Path=%d\n", delta[i], cali_info->absolute_ofdm_swing_idx[i], i); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tdown[%d]=%d Path=%d\n", delta[i], delta_swing_table_idx_tdown[delta[i]], i); + cali_info->delta_power_index_path[i] = -1 * delta_swing_table_idx_tdown[delta[i]]; + cali_info->absolute_ofdm_swing_idx[i] = -1 * delta_swing_table_idx_tdown[delta[i]]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower and cali_info->absolute_ofdm_swing_idx[%d]=%d Path=%d\n", delta[i], cali_info->absolute_ofdm_swing_idx[i], i); + } + } + +#endif + + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + if (cali_info->delta_power_index_path[p] == cali_info->delta_power_index_last_path[p]) /*If Thermal value changes but lookup table value still the same*/ + cali_info->power_index_offset_path[p] = 0; + else + cali_info->power_index_offset_path[p] = cali_info->delta_power_index_path[p] - cali_info->delta_power_index_last_path[p]; /*Power index diff between 2 times Power Tracking*/ + } + +#if 0 + if (dm->support_ic_type == ODM_RTL8814B) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking BBSWING_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, BBSWING, p, 0); + } +#else + if (*dm->mp_mode == 1) { + if (cali_info->txpowertrack_control == 1) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + tracking_method = MIX_MODE; + } else if (cali_info->txpowertrack_control == 3) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking TSSI_MODE**********\n"); + tracking_method = TSSI_MODE; + } + } else { + if (dm->priv->pmib->dot11RFEntry.tssi_enable == 0) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + tracking_method = MIX_MODE; + } else if (dm->priv->pmib->dot11RFEntry.tssi_enable == 1) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking TSSI_MODE**********\n"); + tracking_method = TSSI_MODE; + } + } + + if (dm->support_ic_type == ODM_RTL8822C || dm->support_ic_type == ODM_RTL8812F || + dm->support_ic_type == ODM_RTL8814B || dm->support_ic_type == ODM_RTL8197G) + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, tracking_method, p, 0); + +#endif + /* Wait sacn to do IQK by RF Jenyu*/ + if ((*dm->is_scan_in_process == false) && (!iqk_info->rfk_forbidden) && (dm->is_linked || *dm->mp_mode)) { + /*Delta temperature is equal to or larger than 20 centigrade (When threshold is 8).*/ + if (delta_IQK >= c.threshold_iqk) { + cali_info->thermal_value_iqk = thermal_value[RF_PATH_A]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_IQK(%d) >= threshold_iqk(%d)\n", delta_IQK, c.threshold_iqk); + + /*if (!cali_info->is_iqk_in_progress)*/ + /* (*c.do_iqk)(dm, delta_IQK, thermal_value[RF_PATH_A], 8);*/ + /*RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Do IQK\n");*/ + + /*if (!cali_info->is_iqk_in_progress)*/ + /* (*c.do_tssi_dck)(dm, true);*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Do TSSI DCK\n"); + } + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "<===%s\n", __func__); + + cali_info->tx_powercount = 0; +} +#endif + +#if (RTL8197F_SUPPORT == 1 || RTL8192F_SUPPORT == 1 || RTL8822B_SUPPORT == 1 ||\ + RTL8821C_SUPPORT == 1 || RTL8198F_SUPPORT == 1) +void +odm_txpowertracking_callback_thermal_meter_jaguar_series3( + void *dm_void +) +{ +#if 1 + struct dm_struct *dm = (struct dm_struct *)dm_void; + u8 thermal_value = 0, delta, delta_LCK, delta_IQK, channel, is_increase; + u8 thermal_value_avg_count = 0, p = 0, i = 0; + u32 thermal_value_avg = 0; + struct rtl8192cd_priv *priv = dm->priv; + struct txpwrtrack_cfg c; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct dm_iqk_info *iqk_info = &dm->IQK_info; + struct _hal_rf_ *rf = &dm->rf_table; + /*The following tables decide the final index of OFDM/CCK swing table.*/ + u8 *pwrtrk_tab_up_a = NULL, *pwrtrk_tab_down_a = NULL; + u8 *pwrtrk_tab_up_b = NULL, *pwrtrk_tab_down_b = NULL; + u8 *pwrtrk_tab_up_cck_a = NULL, *pwrtrk_tab_down_cck_a = NULL; + u8 *pwrtrk_tab_up_cck_b = NULL, *pwrtrk_tab_down_cck_b = NULL; + /*for 8814 add by Yu Chen*/ + u8 *pwrtrk_tab_up_c = NULL, *pwrtrk_tab_down_c = NULL; + u8 *pwrtrk_tab_up_d = NULL, *pwrtrk_tab_down_d = NULL; + u8 *pwrtrk_tab_up_cck_c = NULL, *pwrtrk_tab_down_cck_c = NULL; + u8 *pwrtrk_tab_up_cck_d = NULL, *pwrtrk_tab_down_cck_d = NULL; + s8 thermal_value_temp = 0; + +#ifdef MP_TEST + if ((OPMODE & WIFI_MP_STATE) || *(dm->mp_mode)) { + channel = priv->pshare->working_channel; + if (priv->pshare->mp_txpwr_tracking == false) + return; + } else +#endif + { + channel = (priv->pmib->dot11RFEntry.dot11channel); + } + + configure_txpower_track(dm, &c); + + (*c.get_delta_all_swing_table)(dm, + (u8 **)&pwrtrk_tab_up_a, (u8 **)&pwrtrk_tab_down_a, + (u8 **)&pwrtrk_tab_up_b, (u8 **)&pwrtrk_tab_down_b, + (u8 **)&pwrtrk_tab_up_cck_a, (u8 **)&pwrtrk_tab_down_cck_a, + (u8 **)&pwrtrk_tab_up_cck_b, (u8 **)&pwrtrk_tab_down_cck_b); + + if (GET_CHIP_VER(priv) == VERSION_8198F) { + (*c.get_delta_all_swing_table_ex)(dm, + (u8 **)&pwrtrk_tab_up_c, (u8 **)&pwrtrk_tab_down_c, + (u8 **)&pwrtrk_tab_up_d, (u8 **)&pwrtrk_tab_down_d, + (u8 **)&pwrtrk_tab_up_cck_c, (u8 **)&pwrtrk_tab_down_cck_c, + (u8 **)&pwrtrk_tab_up_cck_d, (u8 **)&pwrtrk_tab_down_cck_d); + } + /*0x42: RF Reg[15:10] 88E*/ + thermal_value = (u8)odm_get_rf_reg(dm, RF_PATH_A, c.thermal_reg_addr, 0xfc00); +#ifdef THER_TRIM + if (GET_CHIP_VER(priv) == VERSION_8197F) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"orig thermal_value=%d, ther_trim_val=%d\n", thermal_value, priv->pshare->rf_ft_var.ther_trim_val); + + thermal_value += priv->pshare->rf_ft_var.ther_trim_val; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"after thermal trim, thermal_value=%d\n", thermal_value); + } + + if (GET_CHIP_VER(priv) == VERSION_8198F) { + thermal_value_temp = thermal_value + phydm_get_thermal_offset(dm); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "thermal_value_temp(%d) = ther_value(%d) + ther_trim_ther(%d)\n", + thermal_value_temp, thermal_value, phydm_get_thermal_offset(dm)); + + if (thermal_value_temp > 63) + thermal_value = 63; + else if (thermal_value_temp < 0) + thermal_value = 0; + else + thermal_value = thermal_value_temp; + } +#endif + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"\n\n\nCurrent Thermal = 0x%x(%d) EEPROMthermalmeter 0x%x(%d)\n" + , thermal_value, thermal_value, priv->pmib->dot11RFEntry.ther, priv->pmib->dot11RFEntry.ther); + + /* Initialize */ + if (!dm->rf_calibrate_info.thermal_value) + dm->rf_calibrate_info.thermal_value = priv->pmib->dot11RFEntry.ther; + + if (!dm->rf_calibrate_info.thermal_value_lck) + dm->rf_calibrate_info.thermal_value_lck = priv->pmib->dot11RFEntry.ther; + + if (!dm->rf_calibrate_info.thermal_value_iqk) + dm->rf_calibrate_info.thermal_value_iqk = priv->pmib->dot11RFEntry.ther; + + /* calculate average thermal meter */ + dm->rf_calibrate_info.thermal_value_avg[dm->rf_calibrate_info.thermal_value_avg_index] = thermal_value; + dm->rf_calibrate_info.thermal_value_avg_index++; + + if (dm->rf_calibrate_info.thermal_value_avg_index == c.average_thermal_num) /*Average times = c.average_thermal_num*/ + dm->rf_calibrate_info.thermal_value_avg_index = 0; + + for (i = 0; i < c.average_thermal_num; i++) { + if (dm->rf_calibrate_info.thermal_value_avg[i]) { + thermal_value_avg += dm->rf_calibrate_info.thermal_value_avg[i]; + thermal_value_avg_count++; + } + } + + if (thermal_value_avg_count) {/*Calculate Average thermal_value after average enough times*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"thermal_value_avg=0x%x(%d) thermal_value_avg_count = %d\n" + , thermal_value_avg, thermal_value_avg, thermal_value_avg_count); + + thermal_value = (u8)(thermal_value_avg / thermal_value_avg_count); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"AVG Thermal Meter = 0x%X(%d), EEPROMthermalmeter = 0x%X(%d)\n", thermal_value, thermal_value, priv->pmib->dot11RFEntry.ther, priv->pmib->dot11RFEntry.ther); + } + + /*4 Calculate delta, delta_LCK, delta_IQK.*/ + delta = RTL_ABS(thermal_value, priv->pmib->dot11RFEntry.ther); + delta_LCK = RTL_ABS(thermal_value, dm->rf_calibrate_info.thermal_value_lck); + delta_IQK = RTL_ABS(thermal_value, dm->rf_calibrate_info.thermal_value_iqk); + is_increase = ((thermal_value < priv->pmib->dot11RFEntry.ther) ? 0 : 1); + + if (delta > 29) { /* power track table index(thermal diff.) upper bound*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta(%d) > 29, set delta to 29\n", delta); + delta = 29; + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "(delta, delta_LCK, delta_IQK) = (%d, %d, %d)\n", delta, delta_LCK, delta_IQK); + + /*4 if necessary, do LCK.*/ + if ((delta_LCK >= c.threshold_iqk) && (!iqk_info->rfk_forbidden)) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_LCK(%d) >= threshold_iqk(%d)\n", delta_LCK, c.threshold_iqk); + dm->rf_calibrate_info.thermal_value_lck = thermal_value; +#if (RTL8822B_SUPPORT != 1) + if (!(dm->support_ic_type & ODM_RTL8822B)) { + if (c.phy_lc_calibrate) + (*c.phy_lc_calibrate)(dm); + } +#endif + } + + if (!priv->pmib->dot11RFEntry.ther) /*Don't do power tracking since no calibrated thermal value*/ + return; + + /*4 Do Power Tracking*/ + + if (thermal_value != dm->rf_calibrate_info.thermal_value) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******** START POWER TRACKING ********\n"); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"Readback Thermal Meter = 0x%x pre thermal meter 0x%x EEPROMthermalmeter 0x%x\n", + thermal_value, dm->rf_calibrate_info.thermal_value, priv->pmib->dot11RFEntry.ther); + +#ifdef _TRACKING_TABLE_FILE + if (priv->pshare->rf_ft_var.pwr_track_file) { + if (is_increase) { /*thermal is higher than base*/ + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + switch (p) { + case RF_PATH_B: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"pwrtrk_tab_up_b[%d] = %d pwrtrk_tab_up_cck_b[%d] = %d\n", delta, pwrtrk_tab_up_b[delta], delta, pwrtrk_tab_up_cck_b[delta]); + cali_info->absolute_ofdm_swing_idx[p] = pwrtrk_tab_up_b[delta]; + cali_info->absolute_cck_swing_idx[p] = pwrtrk_tab_up_cck_b[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is higher and pRF->absolute_ofdm_swing_idx[RF_PATH_B] = %d pRF->absolute_cck_swing_idx[RF_PATH_B] = %d\n", cali_info->absolute_ofdm_swing_idx[p], cali_info->absolute_cck_swing_idx[p]); + break; + + case RF_PATH_C: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"pwrtrk_tab_up_c[%d] = %d pwrtrk_tab_up_cck_c[%d] = %d\n", delta, pwrtrk_tab_up_c[delta], delta, pwrtrk_tab_up_cck_c[delta]); + cali_info->absolute_ofdm_swing_idx[p] = pwrtrk_tab_up_c[delta]; + cali_info->absolute_cck_swing_idx[p] = pwrtrk_tab_up_cck_c[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is higher and pRF->absolute_ofdm_swing_idx[RF_PATH_C] = %d pRF->absolute_cck_swing_idx[RF_PATH_C] = %d\n", cali_info->absolute_ofdm_swing_idx[p], cali_info->absolute_cck_swing_idx[p]); + break; + + case RF_PATH_D: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"pwrtrk_tab_up_d[%d] = %d pwrtrk_tab_up_cck_d[%d] = %d\n", delta, pwrtrk_tab_up_d[delta], delta, pwrtrk_tab_up_cck_d[delta]); + cali_info->absolute_ofdm_swing_idx[p] = pwrtrk_tab_up_d[delta]; + cali_info->absolute_cck_swing_idx[p] = pwrtrk_tab_up_cck_d[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is higher and pRF->absolute_ofdm_swing_idx[RF_PATH_D] = %d pRF->absolute_cck_swing_idx[RF_PATH_D] = %d\n", cali_info->absolute_ofdm_swing_idx[p], cali_info->absolute_cck_swing_idx[p]); + break; + default: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"pwrtrk_tab_up_a[%d] = %d pwrtrk_tab_up_cck_a[%d] = %d\n", delta, pwrtrk_tab_up_a[delta], delta, pwrtrk_tab_up_cck_a[delta]); + cali_info->absolute_ofdm_swing_idx[p] = pwrtrk_tab_up_a[delta]; + cali_info->absolute_cck_swing_idx[p] = pwrtrk_tab_up_cck_a[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is higher and pRF->absolute_ofdm_swing_idx[RF_PATH_A] = %d pRF->absolute_cck_swing_idx[RF_PATH_A] = %d\n", cali_info->absolute_ofdm_swing_idx[p], cali_info->absolute_cck_swing_idx[p]); + break; + } + } + } else { /* thermal is lower than base*/ + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + switch (p) { + case RF_PATH_B: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"pwrtrk_tab_down_b[%d] = %d pwrtrk_tab_down_cck_b[%d] = %d\n", delta, pwrtrk_tab_down_b[delta], delta, pwrtrk_tab_down_cck_b[delta]); + cali_info->absolute_ofdm_swing_idx[p] = -1 * pwrtrk_tab_down_b[delta]; + cali_info->absolute_cck_swing_idx[p] = -1 * pwrtrk_tab_down_cck_b[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is lower and pRF->absolute_ofdm_swing_idx[RF_PATH_B] = %d pRF->absolute_cck_swing_idx[RF_PATH_B] = %d\n", cali_info->absolute_ofdm_swing_idx[p], cali_info->absolute_cck_swing_idx[p]); + break; + + case RF_PATH_C: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"pwrtrk_tab_down_c[%d] = %d pwrtrk_tab_down_cck_c[%d] = %d\n", delta, pwrtrk_tab_down_c[delta], delta, pwrtrk_tab_down_cck_c[delta]); + cali_info->absolute_ofdm_swing_idx[p] = -1 * pwrtrk_tab_down_c[delta]; + cali_info->absolute_cck_swing_idx[p] = -1 * pwrtrk_tab_down_cck_c[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is lower and pRF->absolute_ofdm_swing_idx[RF_PATH_C] = %d pRF->absolute_cck_swing_idx[RF_PATH_C] = %d\n", cali_info->absolute_ofdm_swing_idx[p], cali_info->absolute_cck_swing_idx[p]); + break; + + case RF_PATH_D: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"pwrtrk_tab_down_d[%d] = %d pwrtrk_tab_down_cck_d[%d] = %d\n", delta, pwrtrk_tab_down_d[delta], delta, pwrtrk_tab_down_cck_d[delta]); + cali_info->absolute_ofdm_swing_idx[p] = -1 * pwrtrk_tab_down_d[delta]; + cali_info->absolute_cck_swing_idx[p] = -1 * pwrtrk_tab_down_cck_d[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is lower and pRF->absolute_ofdm_swing_idx[RF_PATH_D] = %d pRF->absolute_cck_swing_idx[RF_PATH_D] = %d\n", cali_info->absolute_ofdm_swing_idx[p], cali_info->absolute_cck_swing_idx[p]); + break; + + default: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"pwrtrk_tab_down_a[%d] = %d pwrtrk_tab_down_cck_a[%d] = %d\n", delta, pwrtrk_tab_down_a[delta], delta, pwrtrk_tab_down_cck_a[delta]); + cali_info->absolute_ofdm_swing_idx[p] = -1 * pwrtrk_tab_down_a[delta]; + cali_info->absolute_cck_swing_idx[p] = -1 * pwrtrk_tab_down_cck_a[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is lower and pRF->absolute_ofdm_swing_idx[RF_PATH_A] = %d pRF->absolute_cck_swing_idx[RF_PATH_A] = %d\n", cali_info->absolute_ofdm_swing_idx[p], cali_info->absolute_cck_swing_idx[p]); + break; + } + } + } + + if (is_increase) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, ">>> increse power --->\n"); + if (GET_CHIP_VER(priv) == VERSION_8197F) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, BBSWING, p, 0); + } else if (GET_CHIP_VER(priv) == VERSION_8192F) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else if (GET_CHIP_VER(priv) == VERSION_8822B) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else if (GET_CHIP_VER(priv) == VERSION_8821C) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else if (GET_CHIP_VER(priv) == VERSION_8198F) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else if (GET_CHIP_VER(priv) == VERSION_8192F) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, ">>> decrese power --->\n"); + if (GET_CHIP_VER(priv) == VERSION_8197F) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, BBSWING, p, 0); + } else if (GET_CHIP_VER(priv) == VERSION_8192F) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else if (GET_CHIP_VER(priv) == VERSION_8822B) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else if (GET_CHIP_VER(priv) == VERSION_8821C) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else if (GET_CHIP_VER(priv) == VERSION_8198F) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else if (GET_CHIP_VER(priv) == VERSION_8192F) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } + } + } +#endif + + if (GET_CHIP_VER(priv) != VERSION_8198F) { + if ((delta_IQK >= c.threshold_iqk) && (!iqk_info->rfk_forbidden) && dm->is_linked) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_IQK(%d) >= threshold_iqk(%d)\n", delta_IQK, c.threshold_iqk); + dm->rf_calibrate_info.thermal_value_iqk = thermal_value; + if (!(dm->support_ic_type & ODM_RTL8197F)) { + if (c.do_iqk) + (*c.do_iqk)(dm, false, thermal_value, 0); + } + } + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "\n******** END:%s() ********\n\n", __func__); + /*update thermal meter value*/ + dm->rf_calibrate_info.thermal_value = thermal_value; + + } + +#endif +} +#endif + +/*#if (RTL8814A_SUPPORT == 1)*/ +#if (RTL8814A_SUPPORT == 1) + +void +odm_txpowertracking_callback_thermal_meter_jaguar_series2( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u8 thermal_value = 0, delta, delta_LCK, delta_IQK, channel, is_increase; + u8 thermal_value_avg_count = 0, p = 0, i = 0; + u32 thermal_value_avg = 0, reg0x18; + u32 bb_swing_reg[4] = {REG_A_TX_SCALE_JAGUAR, REG_B_TX_SCALE_JAGUAR, REG_C_TX_SCALE_JAGUAR2, REG_D_TX_SCALE_JAGUAR2}; + s32 ele_D; + u32 bb_swing_idx; + struct rtl8192cd_priv *priv = dm->priv; + struct txpwrtrack_cfg c; + boolean is_tssi_enable = false; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + /* 4 1. The following TWO tables decide the final index of OFDM/CCK swing table. */ + u8 *delta_swing_table_idx_tup_a = NULL, *delta_swing_table_idx_tdown_a = NULL; + u8 *delta_swing_table_idx_tup_b = NULL, *delta_swing_table_idx_tdown_b = NULL; + /* for 8814 add by Yu Chen */ + u8 *delta_swing_table_idx_tup_c = NULL, *delta_swing_table_idx_tdown_c = NULL; + u8 *delta_swing_table_idx_tup_d = NULL, *delta_swing_table_idx_tdown_d = NULL; + +#ifdef MP_TEST + if ((OPMODE & WIFI_MP_STATE) || *(dm->mp_mode)) { + channel = priv->pshare->working_channel; + if (priv->pshare->mp_txpwr_tracking == false) + return; + } else +#endif + { + channel = (priv->pmib->dot11RFEntry.dot11channel); + } + + configure_txpower_track(dm, &c); + cali_info->default_ofdm_index = priv->pshare->OFDM_index0[RF_PATH_A]; + + (*c.get_delta_swing_table)(dm, (u8 **)&delta_swing_table_idx_tup_a, (u8 **)&delta_swing_table_idx_tdown_a, + (u8 **)&delta_swing_table_idx_tup_b, (u8 **)&delta_swing_table_idx_tdown_b); + + if (dm->support_ic_type & ODM_RTL8814A) /* for 8814 path C & D */ + (*c.get_delta_swing_table8814only)(dm, (u8 **)&delta_swing_table_idx_tup_c, (u8 **)&delta_swing_table_idx_tdown_c, + (u8 **)&delta_swing_table_idx_tup_d, (u8 **)&delta_swing_table_idx_tdown_d); + + thermal_value = (u8)odm_get_rf_reg(dm, RF_PATH_A, c.thermal_reg_addr, 0xfc00); /* 0x42: RF Reg[15:10] 88E */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"\nReadback Thermal Meter = 0x%x, pre thermal meter 0x%x, EEPROMthermalmeter 0x%x\n", thermal_value, dm->rf_calibrate_info.thermal_value, priv->pmib->dot11RFEntry.ther); + + /* Initialize */ + if (!dm->rf_calibrate_info.thermal_value) + dm->rf_calibrate_info.thermal_value = priv->pmib->dot11RFEntry.ther; + + if (!dm->rf_calibrate_info.thermal_value_lck) + dm->rf_calibrate_info.thermal_value_lck = priv->pmib->dot11RFEntry.ther; + + if (!dm->rf_calibrate_info.thermal_value_iqk) + dm->rf_calibrate_info.thermal_value_iqk = priv->pmib->dot11RFEntry.ther; + + is_tssi_enable = (boolean)odm_get_rf_reg(dm, RF_PATH_A, REG_RF_TX_GAIN_OFFSET, BIT(7)); /* check TSSI enable */ + + /* 4 Query OFDM BB swing default setting Bit[31:21] */ + for (p = RF_PATH_A ; p < c.rf_path_count ; p++) { + ele_D = odm_get_bb_reg(dm, bb_swing_reg[p], 0xffe00000); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"0x%x:0x%x ([31:21] = 0x%x)\n", bb_swing_reg[p], odm_get_bb_reg(dm, bb_swing_reg[p], MASKDWORD), ele_D); + + for (bb_swing_idx = 0; bb_swing_idx < TXSCALE_TABLE_SIZE; bb_swing_idx++) {/* 4 */ + if (ele_D == tx_scaling_table_jaguar[bb_swing_idx]) { + dm->rf_calibrate_info.OFDM_index[p] = (u8)bb_swing_idx; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"OFDM_index[%d]=%d\n", p, dm->rf_calibrate_info.OFDM_index[p]); + break; + } + } + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "kfree_offset[%d]=%d\n", p, cali_info->kfree_offset[p]); + + } + + /* calculate average thermal meter */ + dm->rf_calibrate_info.thermal_value_avg[dm->rf_calibrate_info.thermal_value_avg_index] = thermal_value; + dm->rf_calibrate_info.thermal_value_avg_index++; + if (dm->rf_calibrate_info.thermal_value_avg_index == c.average_thermal_num) /* Average times = c.average_thermal_num */ + dm->rf_calibrate_info.thermal_value_avg_index = 0; + + for (i = 0; i < c.average_thermal_num; i++) { + if (dm->rf_calibrate_info.thermal_value_avg[i]) { + thermal_value_avg += dm->rf_calibrate_info.thermal_value_avg[i]; + thermal_value_avg_count++; + } + } + + if (thermal_value_avg_count) { /* Calculate Average thermal_value after average enough times */ + thermal_value = (u8)(thermal_value_avg / thermal_value_avg_count); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"AVG Thermal Meter = 0x%X, EEPROMthermalmeter = 0x%X\n", thermal_value, priv->pmib->dot11RFEntry.ther); + } + + /* 4 Calculate delta, delta_LCK, delta_IQK. */ + delta = RTL_ABS(thermal_value, priv->pmib->dot11RFEntry.ther); + delta_LCK = RTL_ABS(thermal_value, dm->rf_calibrate_info.thermal_value_lck); + delta_IQK = RTL_ABS(thermal_value, dm->rf_calibrate_info.thermal_value_iqk); + is_increase = ((thermal_value < priv->pmib->dot11RFEntry.ther) ? 0 : 1); + + /* 4 if necessary, do LCK. */ + if (!(dm->support_ic_type & ODM_RTL8821)) { + if ((delta_LCK > c.threshold_iqk) && (!iqk_info->rfk_forbidden)) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_LCK(%d) >= threshold_iqk(%d)\n", delta_LCK, c.threshold_iqk); + dm->rf_calibrate_info.thermal_value_lck = thermal_value; + + /*Use RTLCK, so close power tracking driver LCK*/ +#if (RTL8814A_SUPPORT != 1) + if (!(dm->support_ic_type & ODM_RTL8814A)) { + if (c.phy_lc_calibrate) + (*c.phy_lc_calibrate)(dm); + } +#endif + } + } + + if ((delta_IQK > c.threshold_iqk) && (!iqk_info->rfk_forbidden)) { + panic_printk("%s(%d)\n", __FUNCTION__, __LINE__); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_IQK(%d) >= threshold_iqk(%d)\n", delta_IQK, c.threshold_iqk); + dm->rf_calibrate_info.thermal_value_iqk = thermal_value; + if (c.do_iqk) + (*c.do_iqk)(dm, true, 0, 0); + } + + if (!priv->pmib->dot11RFEntry.ther) /*Don't do power tracking since no calibrated thermal value*/ + return; + + /* 4 Do Power Tracking */ + + if (is_tssi_enable == true) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter PURE TSSI MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, TSSI_MODE, p, 0); + } else if (thermal_value != dm->rf_calibrate_info.thermal_value) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"\n******** START POWER TRACKING ********\n"); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"\nReadback Thermal Meter = 0x%x pre thermal meter 0x%x EEPROMthermalmeter 0x%x\n", thermal_value, dm->rf_calibrate_info.thermal_value, priv->pmib->dot11RFEntry.ther); + +#ifdef _TRACKING_TABLE_FILE + if (priv->pshare->rf_ft_var.pwr_track_file) { + if (is_increase) { /* thermal is higher than base */ + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + switch (p) { + case RF_PATH_B: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"delta_swing_table_idx_tup_b[%d] = %d\n", delta, delta_swing_table_idx_tup_b[delta]); + cali_info->absolute_ofdm_swing_idx[p] = delta_swing_table_idx_tup_b[delta]; /* Record delta swing for mix mode power tracking */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is higher and dm->absolute_ofdm_swing_idx[RF_PATH_B] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_C: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"delta_swing_table_idx_tup_c[%d] = %d\n", delta, delta_swing_table_idx_tup_c[delta]); + cali_info->absolute_ofdm_swing_idx[p] = delta_swing_table_idx_tup_c[delta]; /* Record delta swing for mix mode power tracking */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is higher and dm->absolute_ofdm_swing_idx[RF_PATH_C] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_D: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"delta_swing_table_idx_tup_d[%d] = %d\n", delta, delta_swing_table_idx_tup_d[delta]); + cali_info->absolute_ofdm_swing_idx[p] = delta_swing_table_idx_tup_d[delta]; /* Record delta swing for mix mode power tracking */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is higher and dm->absolute_ofdm_swing_idx[RF_PATH_D] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + default: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"delta_swing_table_idx_tup_a[%d] = %d\n", delta, delta_swing_table_idx_tup_a[delta]); + cali_info->absolute_ofdm_swing_idx[p] = delta_swing_table_idx_tup_a[delta]; /* Record delta swing for mix mode power tracking */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is higher and dm->absolute_ofdm_swing_idx[RF_PATH_A] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + } + } + } else { /* thermal is lower than base */ + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + switch (p) { + case RF_PATH_B: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"delta_swing_table_idx_tdown_b[%d] = %d\n", delta, delta_swing_table_idx_tdown_b[delta]); + cali_info->absolute_ofdm_swing_idx[p] = -1 * delta_swing_table_idx_tdown_b[delta]; /* Record delta swing for mix mode power tracking */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is lower and dm->absolute_ofdm_swing_idx[RF_PATH_B] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_C: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"delta_swing_table_idx_tdown_c[%d] = %d\n", delta, delta_swing_table_idx_tdown_c[delta]); + cali_info->absolute_ofdm_swing_idx[p] = -1 * delta_swing_table_idx_tdown_c[delta]; /* Record delta swing for mix mode power tracking */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is lower and dm->absolute_ofdm_swing_idx[RF_PATH_C] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_D: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"delta_swing_table_idx_tdown_d[%d] = %d\n", delta, delta_swing_table_idx_tdown_d[delta]); + cali_info->absolute_ofdm_swing_idx[p] = -1 * delta_swing_table_idx_tdown_d[delta]; /* Record delta swing for mix mode power tracking */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is lower and dm->absolute_ofdm_swing_idx[RF_PATH_D] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + default: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"delta_swing_table_idx_tdown_a[%d] = %d\n", delta, delta_swing_table_idx_tdown_a[delta]); + cali_info->absolute_ofdm_swing_idx[p] = -1 * delta_swing_table_idx_tdown_a[delta]; /* Record delta swing for mix mode power tracking */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"******Temp is lower and dm->absolute_ofdm_swing_idx[RF_PATH_A] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + } + } + } + + if (is_increase) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, ">>> increse power --->\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, ">>> decrese power --->\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } + } +#endif + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "\n******** END:%s() ********\n", __FUNCTION__); + /* update thermal meter value */ + dm->rf_calibrate_info.thermal_value = thermal_value; + + } +} +#endif + +#if (RTL8812A_SUPPORT == 1 || RTL8881A_SUPPORT == 1) +void +odm_txpowertracking_callback_thermal_meter_jaguar_series( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + unsigned char thermal_value = 0, delta, delta_LCK, channel, is_decrease; + unsigned char thermal_value_avg_count = 0; + unsigned int thermal_value_avg = 0, reg0x18; + unsigned int bb_swing_reg[4] = {0xc1c, 0xe1c, 0x181c, 0x1a1c}; + int ele_D, value32; + char OFDM_index[2], index; + unsigned int i = 0, j = 0, rf_path, max_rf_path = 2, rf; + struct rtl8192cd_priv *priv = dm->priv; + unsigned char OFDM_min_index = 7; /* OFDM BB Swing should be less than +2.5dB, which is required by Arthur and Mimic */ + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + +#ifdef MP_TEST + if ((OPMODE & WIFI_MP_STATE) || *(dm->mp_mode)) { + channel = priv->pshare->working_channel; + if (priv->pshare->mp_txpwr_tracking == false) + return; + } else +#endif + { + channel = (priv->pmib->dot11RFEntry.dot11channel); + } + +#if RTL8881A_SUPPORT + if (dm->support_ic_type == ODM_RTL8881A) { + max_rf_path = 1; + if ((get_bonding_type_8881A() == BOND_8881AM || get_bonding_type_8881A() == BOND_8881AN) + && priv->pshare->rf_ft_var.use_intpa8881A && (*dm->band_type == ODM_BAND_2_4G)) + OFDM_min_index = 6; /* intPA - upper bond set to +3 dB (base: -2 dB)ot11RFEntry.phy_band_select == PHY_BAND_2G)) */ + else + OFDM_min_index = 10; /* OFDM BB Swing should be less than +1dB, which is required by Arthur and Mimic */ + } +#endif + + + thermal_value = (unsigned char)phy_query_rf_reg(priv, RF_PATH_A, 0x42, 0xfc00, 1); /* 0x42: RF Reg[15:10] 88E */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "\nReadback Thermal Meter = 0x%x pre thermal meter 0x%x EEPROMthermalmeter 0x%x\n", thermal_value, priv->pshare->thermal_value, priv->pmib->dot11RFEntry.ther); + + + /* 4 Query OFDM BB swing default setting Bit[31:21] */ + for (rf_path = 0 ; rf_path < max_rf_path ; rf_path++) { + ele_D = phy_query_bb_reg(priv, bb_swing_reg[rf_path], 0xffe00000); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "0x%x:0x%x ([31:21] = 0x%x)\n", bb_swing_reg[rf_path], phy_query_bb_reg(priv, bb_swing_reg[rf_path], MASKDWORD), ele_D); + for (i = 0; i < OFDM_TABLE_SIZE_8812; i++) {/* 4 */ + if (ele_D == ofdm_swing_table_8812[i]) { + OFDM_index[rf_path] = (unsigned char)i; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "OFDM_index[%d]=%d\n", rf_path, OFDM_index[rf_path]); + break; + } + } + } +#if 0 + /* Query OFDM path A default setting Bit[31:21] */ + ele_D = phy_query_bb_reg(priv, 0xc1c, 0xffe00000); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "0xc1c:0x%x ([31:21] = 0x%x)\n", phy_query_bb_reg(priv, 0xc1c, MASKDWORD), ele_D); + for (i = 0; i < OFDM_TABLE_SIZE_8812; i++) {/* 4 */ + if (ele_D == ofdm_swing_table_8812[i]) { + OFDM_index[0] = (unsigned char)i; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "OFDM_index[0]=%d\n", OFDM_index[0]); + break; + } + } + /* Query OFDM path B default setting */ + if (rf == 2) { + ele_D = phy_query_bb_reg(priv, 0xe1c, 0xffe00000); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "0xe1c:0x%x ([32:21] = 0x%x)\n", phy_query_bb_reg(priv, 0xe1c, MASKDWORD), ele_D); + for (i = 0; i < OFDM_TABLE_SIZE_8812; i++) { + if (ele_D == ofdm_swing_table_8812[i]) { + OFDM_index[1] = (unsigned char)i; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "OFDM_index[1]=%d\n", OFDM_index[1]); + break; + } + } + } +#endif + /* Initialize */ + if (!priv->pshare->thermal_value) { + priv->pshare->thermal_value = priv->pmib->dot11RFEntry.ther; + priv->pshare->thermal_value_lck = thermal_value; + } + + /* calculate average thermal meter */ + { + priv->pshare->thermal_value_avg_8812[priv->pshare->thermal_value_avg_index_8812] = thermal_value; + priv->pshare->thermal_value_avg_index_8812++; + if (priv->pshare->thermal_value_avg_index_8812 == AVG_THERMAL_NUM_8812) + priv->pshare->thermal_value_avg_index_8812 = 0; + + for (i = 0; i < AVG_THERMAL_NUM_8812; i++) { + if (priv->pshare->thermal_value_avg_8812[i]) { + thermal_value_avg += priv->pshare->thermal_value_avg_8812[i]; + thermal_value_avg_count++; + } + } + + if (thermal_value_avg_count) { + thermal_value = (unsigned char)(thermal_value_avg / thermal_value_avg_count); + /* printk("AVG Thermal Meter = 0x%x\n", thermal_value); */ + } + } + + + /* 4 If necessary, do power tracking */ + + if (!priv->pmib->dot11RFEntry.ther) /*Don't do power tracking since no calibrated thermal value*/ + return; + + if (thermal_value != priv->pshare->thermal_value) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "\n******** START POWER TRACKING ********\n"); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "\nReadback Thermal Meter = 0x%x pre thermal meter 0x%x EEPROMthermalmeter 0x%x\n", thermal_value, priv->pshare->thermal_value, priv->pmib->dot11RFEntry.ther); + delta = RTL_ABS(thermal_value, priv->pmib->dot11RFEntry.ther); + delta_LCK = RTL_ABS(thermal_value, priv->pshare->thermal_value_lck); + is_decrease = ((thermal_value < priv->pmib->dot11RFEntry.ther) ? 1 : 0); + /* if (*dm->band_type == ODM_BAND_5G) */ + { +#ifdef _TRACKING_TABLE_FILE + if (priv->pshare->rf_ft_var.pwr_track_file) { + for (rf_path = 0; rf_path < max_rf_path; rf_path++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "diff: (%s)%d ==> get index from table : %d)\n", (is_decrease ? "-" : "+"), delta, get_tx_tracking_index(priv, channel, rf_path, delta, is_decrease, 0)); + if (is_decrease) { + OFDM_index[rf_path] = priv->pshare->OFDM_index0[rf_path] + get_tx_tracking_index(priv, channel, rf_path, delta, is_decrease, 0); + OFDM_index[rf_path] = ((OFDM_index[rf_path] > (OFDM_TABLE_SIZE_8812 - 1)) ? (OFDM_TABLE_SIZE_8812 - 1) : OFDM_index[rf_path]); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, ">>> decrese power ---> new OFDM_INDEX:%d (%d + %d)\n", OFDM_index[rf_path], priv->pshare->OFDM_index0[rf_path], get_tx_tracking_index(priv, channel, rf_path, delta, is_decrease, 0)); +#if 0/* RTL8881A_SUPPORT */ + if (dm->support_ic_type == ODM_RTL8881A) { + if (priv->pshare->rf_ft_var.pwrtrk_tx_agc_enable) { + if (priv->pshare->add_tx_agc) { /* tx_agc has been added */ + add_tx_power88xx_ac(priv, 0); + priv->pshare->add_tx_agc = 0; + priv->pshare->add_tx_agc_index = 0; + } + } + } +#endif + } else { + + OFDM_index[rf_path] = priv->pshare->OFDM_index0[rf_path] - get_tx_tracking_index(priv, channel, rf_path, delta, is_decrease, 0); +#if 0/* RTL8881A_SUPPORT */ + if (dm->support_ic_type == ODM_RTL8881A) { + if (priv->pshare->rf_ft_var.pwrtrk_tx_agc_enable) { + if (OFDM_index[i] < OFDM_min_index) { + priv->pshare->add_tx_agc_index = (OFDM_min_index - OFDM_index[i]) / 2; /* Calculate Remnant tx_agc value, 2 index for 1 tx_agc */ + add_tx_power88xx_ac(priv, priv->pshare->add_tx_agc_index); + priv->pshare->add_tx_agc = 1; /* add_tx_agc Flag = 1 */ + OFDM_index[i] = OFDM_min_index; + } else { + if (priv->pshare->add_tx_agc) { /* tx_agc been added */ + priv->pshare->add_tx_agc = 0; + priv->pshare->add_tx_agc_index = 0; + add_tx_power88xx_ac(priv, 0); /* minus the added TPI */ + } + } + } + } +#else + OFDM_index[rf_path] = ((OFDM_index[rf_path] < OFDM_min_index) ? OFDM_min_index : OFDM_index[rf_path]); +#endif + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, ">>> increse power ---> new OFDM_INDEX:%d (%d - %d)\n", OFDM_index[rf_path], priv->pshare->OFDM_index0[rf_path], get_tx_tracking_index(priv, channel, rf_path, delta, is_decrease, 0)); + } + } + } +#endif + /* 4 Set new BB swing index */ + for (rf_path = 0; rf_path < max_rf_path; rf_path++) { + phy_set_bb_reg(priv, bb_swing_reg[rf_path], 0xffe00000, ofdm_swing_table_8812[(unsigned int)OFDM_index[rf_path]]); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Readback 0x%x[31:21] = 0x%x, OFDM_index:%d\n", bb_swing_reg[rf_path], phy_query_bb_reg(priv, bb_swing_reg[rf_path], 0xffe00000), OFDM_index[rf_path]); + } + + } + if ((delta_LCK > 8) && (!iqk_info->rfk_forbidden)) { + RTL_W8(0x522, 0xff); + reg0x18 = phy_query_rf_reg(priv, RF_PATH_A, 0x18, MASK20BITS, 1); + phy_set_rf_reg(priv, RF_PATH_A, 0xB4, BIT(14), 1); + phy_set_rf_reg(priv, RF_PATH_A, 0x18, BIT(15), 1); + delay_ms(200); /* frequency deviation */ + phy_set_rf_reg(priv, RF_PATH_A, 0xB4, BIT(14), 0); + phy_set_rf_reg(priv, RF_PATH_A, 0x18, MASK20BITS, reg0x18); +#ifdef CONFIG_RTL_8812_SUPPORT + if (GET_CHIP_VER(priv) == VERSION_8812E) + update_bbrf_val8812(priv, priv->pmib->dot11RFEntry.dot11channel); +#endif + RTL_W8(0x522, 0x0); + priv->pshare->thermal_value_lck = thermal_value; + } + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "\n******** END:%s() ********\n", __FUNCTION__); + + /* update thermal meter value */ + priv->pshare->thermal_value = thermal_value; + for (rf_path = 0; rf_path < max_rf_path; rf_path++) + priv->pshare->OFDM_index[rf_path] = OFDM_index[rf_path]; + } +} + +#endif + + +void +odm_txpowertracking_callback_thermal_meter( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + +#if (RTL8814B_SUPPORT == 1 || RTL8812F_SUPPORT == 1 || RTL8822C_SUPPORT == 1 || RTL8197G_SUPPORT == 1) + if (dm->support_ic_type & (ODM_RTL8814B | ODM_RTL8812F | ODM_RTL8822C | ODM_RTL8197G)) { + odm_txpowertracking_callback_thermal_meter_jaguar_series4(dm); + return; + } +#endif +#if (RTL8197F_SUPPORT == 1 ||RTL8192F_SUPPORT == 1 || RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1 || RTL8198F_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8197F || dm->support_ic_type == ODM_RTL8192F || dm->support_ic_type == ODM_RTL8822B + || dm->support_ic_type == ODM_RTL8821C || dm->support_ic_type == ODM_RTL8198F) { + odm_txpowertracking_callback_thermal_meter_jaguar_series3(dm); + return; + } +#endif +#if (RTL8814A_SUPPORT == 1) /*use this function to do power tracking after 8814 by YuChen*/ + if (dm->support_ic_type & ODM_RTL8814A) { + odm_txpowertracking_callback_thermal_meter_jaguar_series2(dm); + return; + } +#endif +#if (RTL8881A_SUPPORT || RTL8812A_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8812 || dm->support_ic_type & ODM_RTL8881A) { + odm_txpowertracking_callback_thermal_meter_jaguar_series(dm); + return; + } +#endif + +#if (RTL8192E_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8192E) { + odm_txpowertracking_callback_thermal_meter_92e(dm); + return; + } +#endif + +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + /* PMGNT_INFO mgnt_info = &adapter->mgnt_info; */ +#endif + + + u8 thermal_value = 0, delta, delta_LCK, delta_IQK, offset; + u8 thermal_value_avg_count = 0; + u32 thermal_value_avg = 0; + /* s32 ele_A=0, ele_D, TempCCk, X, value32; + * s32 Y, ele_C=0; + * s8 OFDM_index[2], CCK_index=0, OFDM_index_old[2]={0,0}, CCK_index_old=0, index; + * s8 deltaPowerIndex = 0; */ + u32 i = 0;/* , j = 0; */ + boolean is2T = false; + /* bool bInteralPA = false; */ + + u8 OFDM_max_index = 34, rf = (is2T) ? 2 : 1; /* OFDM BB Swing should be less than +3.0dB, which is required by Arthur */ + u8 indexforchannel = 0;/*get_right_chnl_place_for_iqk(hal_data->current_channel)*/ + enum _POWER_DEC_INC { POWER_DEC, POWER_INC }; + + struct txpwrtrack_cfg c; + + + /* 4 1. The following TWO tables decide the final index of OFDM/CCK swing table. */ + s8 delta_swing_table_idx[2][index_mapping_NUM_88E] = { + /* {{Power decreasing(lower temperature)}, {Power increasing(higher temperature)}} */ + {0, 0, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 10, 11}, {0, 0, 1, 2, 3, 4, 4, 4, 4, 5, 7, 8, 9, 9, 10} + }; + u8 thermal_threshold[2][index_mapping_NUM_88E] = { + /* {{Power decreasing(lower temperature)}, {Power increasing(higher temperature)}} */ + {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 27}, {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 25, 25} + }; + +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + struct rtl8192cd_priv *priv = dm->priv; +#endif + + /* 4 2. Initilization ( 7 steps in total ) */ + + configure_txpower_track(dm, &c); + + dm->rf_calibrate_info.txpowertracking_callback_cnt++; /* cosa add for debug */ + dm->rf_calibrate_info.is_txpowertracking_init = true; + +#if (MP_DRIVER == 1) + dm->rf_calibrate_info.txpowertrack_control = hal_data->txpowertrack_control; /* We should keep updating the control variable according to HalData. + * rf_calibrate_info.rega24 will be initialized when ODM HW configuring, but MP configures with para files. */ + dm->rf_calibrate_info.rega24 = 0x090e1317; +#endif + +#if (DM_ODM_SUPPORT_TYPE == ODM_AP) && defined(MP_TEST) + if ((OPMODE & WIFI_MP_STATE) || *(dm->mp_mode)) { + if (dm->priv->pshare->mp_txpwr_tracking == false) + return; + } +#endif + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "===>odm_txpowertracking_callback_thermal_meter_8188e, dm->bb_swing_idx_cck_base: %d, dm->bb_swing_idx_ofdm_base: %d\n", cali_info->bb_swing_idx_cck_base, cali_info->bb_swing_idx_ofdm_base); + /* + if (!dm->rf_calibrate_info.tm_trigger) { + odm_set_rf_reg(dm, RF_PATH_A, c.thermal_reg_addr, BIT(17) | BIT(16), 0x3); + dm->rf_calibrate_info.tm_trigger = 1; + return; + } + */ + thermal_value = (u8)odm_get_rf_reg(dm, RF_PATH_A, c.thermal_reg_addr, 0xfc00); /* 0x42: RF Reg[15:10] 88E */ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + if (!thermal_value || !dm->rf_calibrate_info.txpowertrack_control) +#else + if (!dm->rf_calibrate_info.txpowertrack_control) +#endif + return; + + /* 4 3. Initialize ThermalValues of rf_calibrate_info */ + + if (!dm->rf_calibrate_info.thermal_value) { + dm->rf_calibrate_info.thermal_value_lck = thermal_value; + dm->rf_calibrate_info.thermal_value_iqk = thermal_value; + } + + if (dm->rf_calibrate_info.is_reloadtxpowerindex) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "reload ofdm index for band switch\n"); + + /* 4 4. Calculate average thermal meter */ + + dm->rf_calibrate_info.thermal_value_avg[dm->rf_calibrate_info.thermal_value_avg_index] = thermal_value; + dm->rf_calibrate_info.thermal_value_avg_index++; + if (dm->rf_calibrate_info.thermal_value_avg_index == c.average_thermal_num) + dm->rf_calibrate_info.thermal_value_avg_index = 0; + + for (i = 0; i < c.average_thermal_num; i++) { + if (dm->rf_calibrate_info.thermal_value_avg[i]) { + thermal_value_avg += dm->rf_calibrate_info.thermal_value_avg[i]; + thermal_value_avg_count++; + } + } + + if (thermal_value_avg_count) { + /* Give the new thermo value a weighting */ + thermal_value_avg += (thermal_value * 4); + + thermal_value = (u8)(thermal_value_avg / (thermal_value_avg_count + 4)); + cali_info->thermal_value_delta = thermal_value - priv->pmib->dot11RFEntry.ther; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "AVG Thermal Meter = 0x%x\n", thermal_value); + } + + /* 4 5. Calculate delta, delta_LCK, delta_IQK. */ + + delta = (thermal_value > dm->rf_calibrate_info.thermal_value) ? (thermal_value - dm->rf_calibrate_info.thermal_value) : (dm->rf_calibrate_info.thermal_value - thermal_value); + delta_LCK = (thermal_value > dm->rf_calibrate_info.thermal_value_lck) ? (thermal_value - dm->rf_calibrate_info.thermal_value_lck) : (dm->rf_calibrate_info.thermal_value_lck - thermal_value); + delta_IQK = (thermal_value > dm->rf_calibrate_info.thermal_value_iqk) ? (thermal_value - dm->rf_calibrate_info.thermal_value_iqk) : (dm->rf_calibrate_info.thermal_value_iqk - thermal_value); + + /* 4 6. If necessary, do LCK. */ + if (!(dm->support_ic_type & ODM_RTL8821)) { + /*if((delta_LCK > hal_data->delta_lck) && (hal_data->delta_lck != 0))*/ + if ((delta_LCK >= c.threshold_iqk) && (!iqk_info->rfk_forbidden)) { + /*Delta temperature is equal to or larger than 20 centigrade.*/ + dm->rf_calibrate_info.thermal_value_lck = thermal_value; + (*c.phy_lc_calibrate)(dm); + } + } + + /* 3 7. If necessary, move the index of swing table to adjust Tx power. */ + + if (delta > 0 && dm->rf_calibrate_info.txpowertrack_control) { + + delta = (thermal_value > dm->priv->pmib->dot11RFEntry.ther) ? (thermal_value - dm->priv->pmib->dot11RFEntry.ther) : (dm->priv->pmib->dot11RFEntry.ther - thermal_value); + + /* 4 7.1 The Final Power index = BaseIndex + power_index_offset */ + + if (thermal_value > dm->priv->pmib->dot11RFEntry.ther) { + CALCULATE_SWINGTALBE_OFFSET(offset, POWER_INC, index_mapping_NUM_88E, delta); + dm->rf_calibrate_info.delta_power_index_last = dm->rf_calibrate_info.delta_power_index; + dm->rf_calibrate_info.delta_power_index = delta_swing_table_idx[POWER_INC][offset]; + + } else { + + CALCULATE_SWINGTALBE_OFFSET(offset, POWER_DEC, index_mapping_NUM_88E, delta); + dm->rf_calibrate_info.delta_power_index_last = dm->rf_calibrate_info.delta_power_index; + dm->rf_calibrate_info.delta_power_index = (-1) * delta_swing_table_idx[POWER_DEC][offset]; + } + + if (dm->rf_calibrate_info.delta_power_index == dm->rf_calibrate_info.delta_power_index_last) + dm->rf_calibrate_info.power_index_offset = 0; + else + dm->rf_calibrate_info.power_index_offset = dm->rf_calibrate_info.delta_power_index - dm->rf_calibrate_info.delta_power_index_last; + + for (i = 0; i < rf; i++) + dm->rf_calibrate_info.OFDM_index[i] = cali_info->bb_swing_idx_ofdm_base + dm->rf_calibrate_info.power_index_offset; + dm->rf_calibrate_info.CCK_index = cali_info->bb_swing_idx_cck_base + dm->rf_calibrate_info.power_index_offset; + + cali_info->bb_swing_idx_cck = dm->rf_calibrate_info.CCK_index; + cali_info->bb_swing_idx_ofdm[RF_PATH_A] = dm->rf_calibrate_info.OFDM_index[RF_PATH_A]; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "The 'CCK' final index(%d) = BaseIndex(%d) + power_index_offset(%d)\n", cali_info->bb_swing_idx_cck, cali_info->bb_swing_idx_cck_base, dm->rf_calibrate_info.power_index_offset); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "The 'OFDM' final index(%d) = BaseIndex(%d) + power_index_offset(%d)\n", cali_info->bb_swing_idx_ofdm[RF_PATH_A], cali_info->bb_swing_idx_ofdm_base, dm->rf_calibrate_info.power_index_offset); + + /* 4 7.1 Handle boundary conditions of index. */ + + + for (i = 0; i < rf; i++) { + if (dm->rf_calibrate_info.OFDM_index[i] > OFDM_max_index) + dm->rf_calibrate_info.OFDM_index[i] = OFDM_max_index; + else if (dm->rf_calibrate_info.OFDM_index[i] < 0) + dm->rf_calibrate_info.OFDM_index[i] = 0; + } + + if (dm->rf_calibrate_info.CCK_index > c.swing_table_size_cck - 1) + dm->rf_calibrate_info.CCK_index = c.swing_table_size_cck - 1; + else if (dm->rf_calibrate_info.CCK_index < 0) + dm->rf_calibrate_info.CCK_index = 0; + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"The thermal meter is unchanged or TxPowerTracking OFF: thermal_value: %d, dm->rf_calibrate_info.thermal_value: %d)\n", thermal_value, dm->rf_calibrate_info.thermal_value); + dm->rf_calibrate_info.power_index_offset = 0; + } + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"TxPowerTracking: [CCK] Swing Current index: %d, Swing base index: %d\n", dm->rf_calibrate_info.CCK_index, cali_info->bb_swing_idx_cck_base); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK,"TxPowerTracking: [OFDM] Swing Current index: %d, Swing base index: %d\n", dm->rf_calibrate_info.OFDM_index[RF_PATH_A], cali_info->bb_swing_idx_ofdm_base); + + if (dm->rf_calibrate_info.power_index_offset != 0 && dm->rf_calibrate_info.txpowertrack_control) { + /* 4 7.2 Configure the Swing Table to adjust Tx Power. */ + + dm->rf_calibrate_info.is_tx_power_changed = true; /* Always true after Tx Power is adjusted by power tracking. */ + /* */ + /* 2012/04/23 MH According to Luke's suggestion, we can not write BB digital */ + /* to increase TX power. Otherwise, EVM will be bad. */ + /* */ + /* 2012/04/25 MH Add for tx power tracking to set tx power in tx agc for 88E. */ + if (thermal_value > dm->rf_calibrate_info.thermal_value) { + /* RF_DBG(dm,DBG_RF_TX_PWR_TRACK, */ + /* "Temperature Increasing: delta_pi: %d, delta_t: %d, Now_t: %d, EFUSE_t: %d, Last_t: %d\n", */ + /* dm->rf_calibrate_info.power_index_offset, delta, thermal_value, hal_data->eeprom_thermal_meter, dm->rf_calibrate_info.thermal_value); */ + } else if (thermal_value < dm->rf_calibrate_info.thermal_value) { /* Low temperature */ + /* RF_DBG(dm,DBG_RF_TX_PWR_TRACK, */ + /* "Temperature Decreasing: delta_pi: %d, delta_t: %d, Now_t: %d, EFUSE_t: %d, Last_t: %d\n", */ + /* dm->rf_calibrate_info.power_index_offset, delta, thermal_value, hal_data->eeprom_thermal_meter, dm->rf_calibrate_info.thermal_value); */ + } + if (thermal_value > dm->priv->pmib->dot11RFEntry.ther) + { + /* RF_DBG(dm,DBG_RF_TX_PWR_TRACK,"Temperature(%d) hugher than PG value(%d), increases the power by tx_agc\n", thermal_value, hal_data->eeprom_thermal_meter); */ + (*c.odm_tx_pwr_track_set_pwr)(dm, TXAGC, 0, 0); + } else { + /* RF_DBG(dm,DBG_RF_TX_PWR_TRACK,"Temperature(%d) lower than PG value(%d), increases the power by tx_agc\n", thermal_value, hal_data->eeprom_thermal_meter); */ + (*c.odm_tx_pwr_track_set_pwr)(dm, BBSWING, RF_PATH_A, indexforchannel); + if (is2T) + (*c.odm_tx_pwr_track_set_pwr)(dm, BBSWING, RF_PATH_B, indexforchannel); + } + + cali_info->bb_swing_idx_cck_base = cali_info->bb_swing_idx_cck; + cali_info->bb_swing_idx_ofdm_base = cali_info->bb_swing_idx_ofdm[RF_PATH_A]; + dm->rf_calibrate_info.thermal_value = thermal_value; + + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "<===dm_TXPowerTrackingCallback_ThermalMeter_8188E\n"); + + dm->rf_calibrate_info.tx_powercount = 0; +} + +/* 3============================================================ + * 3 IQ Calibration + * 3============================================================ */ + +void +odm_reset_iqk_result( + void *dm_void +) +{ + return; +} +#if 1/* !(DM_ODM_SUPPORT_TYPE & ODM_AP) */ +u8 odm_get_right_chnl_place_for_iqk(u8 chnl) +{ + u8 channel_all[ODM_TARGET_CHNL_NUM_2G_5G] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 149, 151, 153, 155, 157, 159, 161, 163, 165 + }; + u8 place = chnl; + + + if (chnl > 14) { + for (place = 14; place < sizeof(channel_all); place++) { + if (channel_all[place] == chnl) + return place - 13; + } + } + return 0; + +} +#endif + +void +odm_iq_calibrate( + struct dm_struct *dm +) +{ + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + if ((dm->is_linked) && (!iqk_info->rfk_forbidden)) { + if ((*dm->channel != dm->pre_channel) && (!*dm->is_scan_in_process)) { + dm->pre_channel = *dm->channel; + dm->linked_interval = 0; + } + + if (dm->linked_interval < 3) + dm->linked_interval++; + + if (dm->linked_interval == 2) + halrf_iqk_trigger(dm, false); + } else + dm->linked_interval = 0; + +} + +void phydm_rf_init(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + odm_txpowertracking_init(dm); + +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) +#if (RTL8814A_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814A) + phy_iq_calibrate_8814a_init(dm); +#endif +#endif + +} + +void phydm_rf_watchdog(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + odm_txpowertracking_check(dm); +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + if (dm->support_ic_type & ODM_IC_11AC_SERIES) + odm_iq_calibrate(dm); +#endif +} diff --git a/hal/phydm/halrf/halphyrf_ap.h b/hal/phydm/halrf/halphyrf_ap.h new file mode 100644 index 0000000..8cc2797 --- /dev/null +++ b/hal/phydm/halrf/halphyrf_ap.h @@ -0,0 +1,170 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#ifndef __HALPHYRF_H__ +#define __HALPHYRF_H__ + +#include "halrf/halrf_powertracking_ap.h" +#include "halrf/halrf_kfree.h" + +#if (RTL8814A_SUPPORT == 1) + #include "halrf/rtl8814a/halrf_iqk_8814a.h" +#endif + +#if (RTL8822B_SUPPORT == 1) + #include "halrf/rtl8822b/halrf_iqk_8822b.h" +#endif + +#if (RTL8821C_SUPPORT == 1) + #include "halrf/rtl8821c/halrf_iqk_8821c.h" +#endif + +#if (RTL8195B_SUPPORT == 1) +// #include "halrf/rtl8195b/halrf.h" + #include "halrf/rtl8195b/halrf_iqk_8195b.h" + #include "halrf/rtl8195b/halrf_txgapk_8195b.h" + #include "halrf/rtl8195b/halrf_dpk_8195b.h" +#endif + +#if (RTL8198F_SUPPORT == 1) + #include "halrf/rtl8198f/halrf_iqk_8198f.h" + #include "halrf/rtl8198f/halrf_dpk_8198f.h" +#endif + +#if (RTL8812F_SUPPORT == 1) + #include "halrf/rtl8812f/halrf_iqk_8812f.h" + #include "halrf/rtl8812f/halrf_dpk_8812f.h" + #include "halrf/rtl8812f/halrf_tssi_8812f.h" +#endif + +#if (RTL8814B_SUPPORT == 1) + #include "halrf/rtl8814b/halrf_iqk_8814b.h" + #include "halrf/rtl8814b/halrf_dpk_8814b.h" + #include "halrf/rtl8814b/halrf_txgapk_8814b.h" +#endif + +#if (RTL8197G_SUPPORT == 1) + #include "halrf/rtl8197g/halrf_iqk_8197g.h" + #include "halrf/rtl8197g/halrf_dpk_8197g.h" + #include "halrf/rtl8197g/halrf_tssi_8197g.h" +#endif + +enum pwrtrack_method { + BBSWING, + TXAGC, + MIX_MODE, + TSSI_MODE, + MIX_2G_TSSI_5G_MODE, + MIX_5G_TSSI_2G_MODE, + CLEAN_MODE +}; + +typedef void (*func_set_pwr)(void *, enum pwrtrack_method, u8, u8); +typedef void(*func_iqk)(void *, u8, u8, u8); +typedef void (*func_lck)(void *); +typedef void (*func_tssi_dck)(void *, u8); +/* refine by YuChen for 8814A */ +typedef void (*func_swing)(void *, u8 **, u8 **, u8 **, u8 **); +typedef void (*func_swing8814only)(void *, u8 **, u8 **, u8 **, u8 **); +typedef void (*func_all_swing)(void *, u8 **, u8 **, u8 **, u8 **, u8 **, u8 **, u8 **, u8 **); +typedef void (*func_all_swing_ex)(void *, u8 **, u8 **, u8 **, u8 **, u8 **, u8 **, u8 **, u8 **); + +struct txpwrtrack_cfg { + u8 swing_table_size_cck; + u8 swing_table_size_ofdm; + u8 threshold_iqk; + u8 threshold_dpk; + u8 average_thermal_num; + u8 rf_path_count; + u32 thermal_reg_addr; + func_set_pwr odm_tx_pwr_track_set_pwr; + func_iqk do_iqk; + func_lck phy_lc_calibrate; + func_tssi_dck do_tssi_dck; + func_swing get_delta_swing_table; + func_swing8814only get_delta_swing_table8814only; + func_all_swing get_delta_all_swing_table; + func_all_swing_ex get_delta_all_swing_table_ex; +}; + +void +odm_clear_txpowertracking_state( + void *dm_void +); + +void +configure_txpower_track( + void *dm_void, + struct txpwrtrack_cfg *config +); + + +void +odm_txpowertracking_callback_thermal_meter( + void *dm_void +); + +#if (RTL8192E_SUPPORT == 1) +void +odm_txpowertracking_callback_thermal_meter_92e( + void *dm_void +); +#endif + +#if (RTL8814A_SUPPORT == 1) +void +odm_txpowertracking_callback_thermal_meter_jaguar_series2( + void *dm_void +); + +#elif ODM_IC_11AC_SERIES_SUPPORT +void +odm_txpowertracking_callback_thermal_meter_jaguar_series( + void *dm_void +); + +#elif (RTL8197F_SUPPORT == 1 || RTL8192F_SUPPORT == 1 || RTL8822B_SUPPORT == 1 ||\ + RTL8821C_SUPPORT == 1 || RTL8198F_SUPPORT == 1) +void +odm_txpowertracking_callback_thermal_meter_jaguar_series3( + void *dm_void +); + +#elif (RTL8814B_SUPPORT == 1 || RTL8812F_SUPPORT == 1 || RTL8822C_SUPPORT == 1 || RTL8197G_SUPPORT == 1) +void +odm_txpowertracking_callback_thermal_meter_jaguar_series4( + void *dm_void +); + +#endif + +#define IS_CCK_RATE(_rate) (ODM_MGN_1M == _rate || _rate == ODM_MGN_2M || _rate == ODM_MGN_5_5M || _rate == ODM_MGN_11M) + +#define ODM_TARGET_CHNL_NUM_2G_5G 59 + + +void +odm_reset_iqk_result( + void *dm_void +); +u8 +odm_get_right_chnl_place_for_iqk( + u8 chnl +); + +void phydm_rf_init(void *dm_void); +void phydm_rf_watchdog(void *dm_void); + +#endif /*#ifndef __HALPHYRF_H__*/ diff --git a/hal/phydm/halrf/halphyrf_ce.c b/hal/phydm/halrf/halphyrf_ce.c new file mode 100644 index 0000000..6ba9606 --- /dev/null +++ b/hal/phydm/halrf/halphyrf_ce.c @@ -0,0 +1,1180 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#include "mp_precomp.h" +#include "phydm_precomp.h" + +#define CALCULATE_SWINGTALBE_OFFSET(_offset, _direction, _size, _delta_thermal)\ + do { \ + u32 __offset = (u32)_offset; \ + u32 __size = (u32)_size; \ + for (__offset = 0; __offset < __size; __offset++) { \ + if (_delta_thermal < \ + thermal_threshold[_direction][__offset]) { \ + if (__offset != 0) \ + __offset--; \ + break; \ + } \ + } \ + if (__offset >= __size) \ + __offset = __size - 1; \ + } while (0) + +void configure_txpower_track(void *dm_void, struct txpwrtrack_cfg *config) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if RTL8192E_SUPPORT + if (dm->support_ic_type == ODM_RTL8192E) + configure_txpower_track_8192e(config); +#endif +#if RTL8821A_SUPPORT + if (dm->support_ic_type == ODM_RTL8821) + configure_txpower_track_8821a(config); +#endif +#if RTL8812A_SUPPORT + if (dm->support_ic_type == ODM_RTL8812) + configure_txpower_track_8812a(config); +#endif +#if RTL8188E_SUPPORT + if (dm->support_ic_type == ODM_RTL8188E) + configure_txpower_track_8188e(config); +#endif + +#if RTL8723B_SUPPORT + if (dm->support_ic_type == ODM_RTL8723B) + configure_txpower_track_8723b(config); +#endif + +#if RTL8814A_SUPPORT + if (dm->support_ic_type == ODM_RTL8814A) + configure_txpower_track_8814a(config); +#endif + +#if RTL8703B_SUPPORT + if (dm->support_ic_type == ODM_RTL8703B) + configure_txpower_track_8703b(config); +#endif + +#if RTL8188F_SUPPORT + if (dm->support_ic_type == ODM_RTL8188F) + configure_txpower_track_8188f(config); +#endif +#if RTL8723D_SUPPORT + if (dm->support_ic_type == ODM_RTL8723D) + configure_txpower_track_8723d(config); +#endif +/*@ JJ ADD 20161014 */ +#if RTL8710B_SUPPORT + if (dm->support_ic_type == ODM_RTL8710B) + configure_txpower_track_8710b(config); +#endif +#if RTL8822B_SUPPORT + if (dm->support_ic_type == ODM_RTL8822B) + configure_txpower_track_8822b(config); +#endif +#if RTL8821C_SUPPORT + if (dm->support_ic_type == ODM_RTL8821C) + configure_txpower_track_8821c(config); +#endif + +#if RTL8192F_SUPPORT + if (dm->support_ic_type == ODM_RTL8192F) + configure_txpower_track_8192f(config); +#endif + +#if RTL8822C_SUPPORT + if (dm->support_ic_type == ODM_RTL8822C) + configure_txpower_track_8822c(config); +#endif + +#if RTL8814B_SUPPORT + if (dm->support_ic_type == ODM_RTL8814B) + configure_txpower_track_8814b(config); +#endif + +#if RTL8723F_SUPPORT + if (dm->support_ic_type == ODM_RTL8723F) + configure_txpower_track_8723f(config); +#endif + +} + +/*@ ********************************************************************** + * <20121113, Kordan> This function should be called when tx_agc changed. + * Otherwise the previous compensation is gone, because we record the + * delta of temperature between two TxPowerTracking watch dogs. + * + * NOTE: If Tx BB swing or Tx scaling is varified during run-time, still + * need to call this function. + * ********************************************************************** + */ +void odm_clear_txpowertracking_state(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + u8 p = 0; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + + cali_info->bb_swing_idx_cck_base = cali_info->default_cck_index; + cali_info->bb_swing_idx_cck = cali_info->default_cck_index; + dm->rf_calibrate_info.CCK_index = 0; + + for (p = RF_PATH_A; p < MAX_RF_PATH; ++p) { + cali_info->bb_swing_idx_ofdm_base[p] + = cali_info->default_ofdm_index; + cali_info->bb_swing_idx_ofdm[p] = cali_info->default_ofdm_index; + cali_info->OFDM_index[p] = cali_info->default_ofdm_index; + + cali_info->power_index_offset[p] = 0; + cali_info->delta_power_index[p] = 0; + cali_info->delta_power_index_last[p] = 0; + + /* Initial Mix mode power tracking*/ + cali_info->absolute_ofdm_swing_idx[p] = 0; + cali_info->remnant_ofdm_swing_idx[p] = 0; + cali_info->kfree_offset[p] = 0; + } + /* Initial Mix mode power tracking*/ + cali_info->modify_tx_agc_flag_path_a = false; + cali_info->modify_tx_agc_flag_path_b = false; + cali_info->modify_tx_agc_flag_path_c = false; + cali_info->modify_tx_agc_flag_path_d = false; + cali_info->remnant_cck_swing_idx = 0; + cali_info->thermal_value = rf->eeprom_thermal; + cali_info->modify_tx_agc_value_cck = 0; + cali_info->modify_tx_agc_value_ofdm = 0; +} + +void odm_get_tracking_table(void *dm_void, u8 thermal_value, u8 delta) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + struct _hal_rf_ *rf = &dm->rf_table; + struct txpwrtrack_cfg c = {0}; + + u8 p; + /* 4 1. TWO tables decide the final index of OFDM/CCK swing table. */ + u8 *pwrtrk_tab_up_a = NULL; + u8 *pwrtrk_tab_down_a = NULL; + u8 *pwrtrk_tab_up_b = NULL; + u8 *pwrtrk_tab_down_b = NULL; + /*for 8814 add by Yu Chen*/ + u8 *pwrtrk_tab_up_c = NULL; + u8 *pwrtrk_tab_down_c = NULL; + u8 *pwrtrk_tab_up_d = NULL; + u8 *pwrtrk_tab_down_d = NULL; + /*for Xtal Offset by James.Tung*/ + s8 *xtal_tab_up = NULL; + s8 *xtal_tab_down = NULL; + + configure_txpower_track(dm, &c); + + (*c.get_delta_swing_table)(dm, + (u8 **)&pwrtrk_tab_up_a, + (u8 **)&pwrtrk_tab_down_a, + (u8 **)&pwrtrk_tab_up_b, + (u8 **)&pwrtrk_tab_down_b); + + if (dm->support_ic_type & ODM_RTL8814A) /*for 8814 path C & D*/ + (*c.get_delta_swing_table8814only)(dm, + (u8 **)&pwrtrk_tab_up_c, + (u8 **)&pwrtrk_tab_down_c, + (u8 **)&pwrtrk_tab_up_d, + (u8 **)&pwrtrk_tab_down_d); + /*for Xtal Offset*/ + if (dm->support_ic_type & + (ODM_RTL8703B | ODM_RTL8723D | ODM_RTL8710B | ODM_RTL8192F)) + (*c.get_delta_swing_xtal_table)(dm, + (s8 **)&xtal_tab_up, + (s8 **)&xtal_tab_down); + + if (thermal_value > rf->eeprom_thermal) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + /*recording power index offset*/ + cali_info->delta_power_index_last[p] = + cali_info->delta_power_index[p]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher******\n"); + switch (p) { + case RF_PATH_B: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "pwrtrk_tab_up_b[%d] = %d\n", delta, + pwrtrk_tab_up_b[delta]); + + cali_info->delta_power_index[p] = + pwrtrk_tab_up_b[delta]; + cali_info->absolute_ofdm_swing_idx[p] = + pwrtrk_tab_up_b[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "absolute_ofdm_swing_idx[PATH_B] = %d\n", + cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_C: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "pwrtrk_tab_up_c[%d] = %d\n", delta, + pwrtrk_tab_up_c[delta]); + + cali_info->delta_power_index[p] = + pwrtrk_tab_up_c[delta]; + cali_info->absolute_ofdm_swing_idx[p] = + pwrtrk_tab_up_c[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "absolute_ofdm_swing_idx[PATH_C] = %d\n", + cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_D: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "pwrtrk_tab_up_d[%d] = %d\n", delta, + pwrtrk_tab_up_d[delta]); + + cali_info->delta_power_index[p] = + pwrtrk_tab_up_d[delta]; + cali_info->absolute_ofdm_swing_idx[p] = + pwrtrk_tab_up_d[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "absolute_ofdm_swing_idx[PATH_D] = %d\n", + cali_info->absolute_ofdm_swing_idx[p]); + break; + + default: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "pwrtrk_tab_up_a[%d] = %d\n", delta, + pwrtrk_tab_up_a[delta]); + + cali_info->delta_power_index[p] = + pwrtrk_tab_up_a[delta]; + cali_info->absolute_ofdm_swing_idx[p] = + pwrtrk_tab_up_a[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "absolute_ofdm_swing_idx[PATH_A] = %d\n", + cali_info->absolute_ofdm_swing_idx[p]); + break; + } + } + /* @JJ ADD 20161014 */ + /*Save xtal_offset from Xtal table*/ + if (dm->support_ic_type & + (ODM_RTL8703B | ODM_RTL8723D | ODM_RTL8710B | + ODM_RTL8192F)) { + /*recording last Xtal offset*/ + cali_info->xtal_offset_last = cali_info->xtal_offset; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[Xtal] xtal_tab_up[%d] = %d\n", + delta, xtal_tab_up[delta]); + cali_info->xtal_offset = xtal_tab_up[delta]; + if (cali_info->xtal_offset_last != xtal_tab_up[delta]) + cali_info->xtal_offset_eanble = 1; + } + } else { + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + /*recording power index offset*/ + cali_info->delta_power_index_last[p] = + cali_info->delta_power_index[p]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower******\n"); + switch (p) { + case RF_PATH_B: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "pwrtrk_tab_down_b[%d] = %d\n", delta, + pwrtrk_tab_down_b[delta]); + cali_info->delta_power_index[p] = + -1 * pwrtrk_tab_down_b[delta]; + cali_info->absolute_ofdm_swing_idx[p] = + -1 * pwrtrk_tab_down_b[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "absolute_ofdm_swing_idx[PATH_B] = %d\n", + cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_C: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "pwrtrk_tab_down_c[%d] = %d\n", delta, + pwrtrk_tab_down_c[delta]); + cali_info->delta_power_index[p] = + -1 * pwrtrk_tab_down_c[delta]; + cali_info->absolute_ofdm_swing_idx[p] = + -1 * pwrtrk_tab_down_c[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "absolute_ofdm_swing_idx[PATH_C] = %d\n", + cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_D: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "pwrtrk_tab_down_d[%d] = %d\n", delta, + pwrtrk_tab_down_d[delta]); + cali_info->delta_power_index[p] = + -1 * pwrtrk_tab_down_d[delta]; + cali_info->absolute_ofdm_swing_idx[p] = + -1 * pwrtrk_tab_down_d[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "absolute_ofdm_swing_idx[PATH_D] = %d\n", + cali_info->absolute_ofdm_swing_idx[p]); + break; + + default: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "pwrtrk_tab_down_a[%d] = %d\n", delta, + pwrtrk_tab_down_a[delta]); + cali_info->delta_power_index[p] = + -1 * pwrtrk_tab_down_a[delta]; + cali_info->absolute_ofdm_swing_idx[p] = + -1 * pwrtrk_tab_down_a[delta]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "absolute_ofdm_swing_idx[PATH_A] = %d\n", + cali_info->absolute_ofdm_swing_idx[p]); + break; + } + } + /* @JJ ADD 20161014 */ + if (dm->support_ic_type & + (ODM_RTL8703B | ODM_RTL8723D | ODM_RTL8710B | + ODM_RTL8192F)) { + /*recording last Xtal offset*/ + cali_info->xtal_offset_last = cali_info->xtal_offset; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[Xtal] xtal_tab_down[%d] = %d\n", delta, + xtal_tab_down[delta]); + /*Save xtal_offset from Xtal table*/ + cali_info->xtal_offset = xtal_tab_down[delta]; + if (cali_info->xtal_offset_last != xtal_tab_down[delta]) + cali_info->xtal_offset_eanble = 1; + } + } +} + +void odm_pwrtrk_method(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u8 p, idxforchnl = 0; + + struct txpwrtrack_cfg c = {0}; + + configure_txpower_track(dm, &c); + + if (dm->support_ic_type & + (ODM_RTL8188E | ODM_RTL8192E | ODM_RTL8821 | ODM_RTL8812 | + ODM_RTL8723B | ODM_RTL8814A | ODM_RTL8703B | ODM_RTL8188F | + ODM_RTL8822B | ODM_RTL8821C | ODM_RTL8710B | + ODM_RTL8192F)) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "***Enter PwrTrk MIX_MODE***\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else if (dm->support_ic_type & ODM_RTL8723D) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "***Enter PwrTrk MIX_MODE***\n"); + p = (u8)odm_get_bb_reg(dm, R_0x948, 0x00000080); + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + /*if open ant_div 0x948=140,do 2 path pwr_track*/ + if (odm_get_bb_reg(dm, R_0x948, 0x00000040)) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, 1, 0); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "***Enter PwrTrk BBSWING_MODE***\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr) + (dm, BBSWING, p, idxforchnl); + } +} + +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) +void odm_txpowertracking_callback_thermal_meter(struct dm_struct *dm) +#elif (DM_ODM_SUPPORT_TYPE == ODM_CE) +void odm_txpowertracking_callback_thermal_meter(void *dm_void) +#else +void odm_txpowertracking_callback_thermal_meter(void *adapter) +#endif +{ +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + struct dm_struct *dm = &hal_data->DM_OutSrc; +#elif (DM_ODM_SUPPORT_TYPE == ODM_CE) + struct dm_struct *dm = (struct dm_struct *)dm_void; +#endif + + struct _hal_rf_ *rf = &dm->rf_table; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + u8 thermal_value = 0, delta, delta_lck, delta_iqk, p = 0, i = 0; + u8 thermal_value_avg_count = 0; + u32 thermal_value_avg = 0, regc80, regcd0, regcd4, regab4; + + /* OFDM BB Swing should be less than +3.0dB, required by Arthur */ +#if 0 + u8 OFDM_min_index = 0; +#endif +#if 0 + /* get_right_chnl_place_for_iqk(hal_data->current_channel) */ +#endif + u8 power_tracking_type = rf->pwt_type; + s8 thermal_value_temp = 0; + + struct txpwrtrack_cfg c = {0}; + + /* @4 2. Initialization ( 7 steps in total ) */ + + configure_txpower_track(dm, &c); + + cali_info->txpowertracking_callback_cnt++; + cali_info->is_txpowertracking_init = true; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "\n\n\n===>%s bbsw_idx_cck_base=%d\n", + __func__, cali_info->bb_swing_idx_cck_base); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "bbsw_idx_ofdm_base[A]=%d default_ofdm_idx=%d\n", + cali_info->bb_swing_idx_ofdm_base[RF_PATH_A], + cali_info->default_ofdm_index); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->txpowertrack_control=%d, rf->eeprom_thermal %d\n", + cali_info->txpowertrack_control, rf->eeprom_thermal); + + /* 0x42: RF Reg[15:10] 88E */ + thermal_value = + (u8)odm_get_rf_reg(dm, RF_PATH_A, c.thermal_reg_addr, 0xfc00); + + thermal_value_temp = thermal_value + phydm_get_thermal_offset(dm); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "thermal_value_temp(%d) = ther_value(%d) + pwr_trim_ther(%d)\n", + thermal_value_temp, thermal_value, + phydm_get_thermal_offset(dm)); + + if (thermal_value_temp > 63) + thermal_value = 63; + else if (thermal_value_temp < 0) + thermal_value = 0; + else + thermal_value = thermal_value_temp; + + /*@add log by zhao he, check c80/c94/c14/ca0 value*/ + if (dm->support_ic_type & + (ODM_RTL8723D | ODM_RTL8710B)) { + regc80 = odm_get_bb_reg(dm, R_0xc80, MASKDWORD); + regcd0 = odm_get_bb_reg(dm, R_0xcd0, MASKDWORD); + regcd4 = odm_get_bb_reg(dm, R_0xcd4, MASKDWORD); + regab4 = odm_get_bb_reg(dm, R_0xab4, 0x000007FF); + RF_DBG(dm, DBG_RF_IQK, + "0xc80 = 0x%x 0xcd0 = 0x%x 0xcd4 = 0x%x 0xab4 = 0x%x\n", + regc80, regcd0, regcd4, regab4); + } + + if (!cali_info->txpowertrack_control) + return; + + if (rf->eeprom_thermal == 0xff) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "no pg, hal_data->eeprom_thermal_meter = 0x%x\n", + rf->eeprom_thermal); + return; + } + + /*@4 3. Initialize ThermalValues of rf_calibrate_info*/ + + if (cali_info->is_reloadtxpowerindex) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "reload ofdm index for band switch\n"); + + /*@4 4. Calculate average thermal meter*/ + + cali_info->thermal_value_avg[cali_info->thermal_value_avg_index] + = thermal_value; + + cali_info->thermal_value_avg_index++; + /*Average times = c.average_thermal_num*/ + if (cali_info->thermal_value_avg_index == c.average_thermal_num) + cali_info->thermal_value_avg_index = 0; + + for (i = 0; i < c.average_thermal_num; i++) { + if (cali_info->thermal_value_avg[i]) { + thermal_value_avg += cali_info->thermal_value_avg[i]; + thermal_value_avg_count++; + } + } + + /* Calculate Average thermal_value after average enough times */ + if (thermal_value_avg_count) { + thermal_value = + (u8)(thermal_value_avg / thermal_value_avg_count); + cali_info->thermal_value_delta + = thermal_value - rf->eeprom_thermal; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "AVG Thermal Meter = 0x%X, EFUSE Thermal base = 0x%X\n", + thermal_value, rf->eeprom_thermal); + } + + /* @4 5. Calculate delta, delta_lck, delta_iqk. */ + /* "delta" here is used to determine thermal value changes or not. */ + if (thermal_value > cali_info->thermal_value) + delta = thermal_value - cali_info->thermal_value; + else + delta = cali_info->thermal_value - thermal_value; + + if (thermal_value > cali_info->thermal_value_lck) + delta_lck = thermal_value - cali_info->thermal_value_lck; + else + delta_lck = cali_info->thermal_value_lck - thermal_value; + + if (thermal_value > cali_info->thermal_value_iqk) + delta_iqk = thermal_value - cali_info->thermal_value_iqk; + else + delta_iqk = cali_info->thermal_value_iqk - thermal_value; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "(delta, delta_lck, delta_iqk) = (%d, %d, %d)\n", delta, + delta_lck, delta_iqk); + + /*@4 6. If necessary, do LCK.*/ + /* Wait sacn to do LCK by RF Jenyu*/ + if (!(*dm->is_scan_in_process) && !iqk_info->rfk_forbidden) { + /* Delta temperature is equal to or larger than 20 centigrade.*/ + if (delta_lck >= c.threshold_iqk) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_lck(%d) >= threshold_iqk(%d)\n", + delta_lck, c.threshold_iqk); + cali_info->thermal_value_lck = thermal_value; + + /*Use RTLCK, close power tracking driver LCK*/ + /*8821 don't do LCK*/ + if (!(dm->support_ic_type & + (ODM_RTL8821 | ODM_RTL8814A | ODM_RTL8822B)) && + c.phy_lc_calibrate) { + (*c.phy_lc_calibrate)(dm); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "do pwrtrk lck\n"); + } + } + } + + /*@3 7. If necessary, move the index of swing table to adjust Tx power.*/ + /* "delta" here is used to record the absolute value of difference. */ + if (delta > 0 && cali_info->txpowertrack_control) { + if (thermal_value > rf->eeprom_thermal) + delta = thermal_value - rf->eeprom_thermal; + else + delta = rf->eeprom_thermal - thermal_value; + + if (delta >= TXPWR_TRACK_TABLE_SIZE) + delta = TXPWR_TRACK_TABLE_SIZE - 1; + + odm_get_tracking_table(dm, thermal_value, delta); + + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "\n[path-%d] Calculate pwr_idx_offset\n", p); + + /*If Thermal value changes but table value is the same*/ + if (cali_info->delta_power_index[p] == + cali_info->delta_power_index_last[p]) + cali_info->power_index_offset[p] = 0; + else + cali_info->power_index_offset[p] = + cali_info->delta_power_index[p] - + cali_info->delta_power_index_last[p]; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "path-%d pwridx_diff%d=pwr_idx%d - last_idx%d\n", + p, cali_info->power_index_offset[p], + cali_info->delta_power_index[p], + cali_info->delta_power_index_last[p]); +#if 0 + + cali_info->OFDM_index[p] = cali_info->bb_swing_idx_ofdm_base[p] + cali_info->power_index_offset[p]; + cali_info->CCK_index = cali_info->bb_swing_idx_cck_base + cali_info->power_index_offset[p]; + + cali_info->bb_swing_idx_cck = cali_info->CCK_index; + cali_info->bb_swing_idx_ofdm[p] = cali_info->OFDM_index[p]; + + /*************Print BB Swing base and index Offset*************/ + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "The 'CCK' final index(%d) = BaseIndex(%d) + power_index_offset(%d)\n", + cali_info->bb_swing_idx_cck, + cali_info->bb_swing_idx_cck_base, + cali_info->power_index_offset[p]); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "The 'OFDM' final index(%d) = BaseIndex[%d](%d) + power_index_offset(%d)\n", + cali_info->bb_swing_idx_ofdm[p], p, + cali_info->bb_swing_idx_ofdm_base[p], + cali_info->power_index_offset[p]); + + /*4 7.1 Handle boundary conditions of index.*/ + + if (cali_info->OFDM_index[p] > c.swing_table_size_ofdm - 1) + cali_info->OFDM_index[p] = c.swing_table_size_ofdm - 1; + else if (cali_info->OFDM_index[p] <= OFDM_min_index) + cali_info->OFDM_index[p] = OFDM_min_index; +#endif + } +#if 0 + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "\n\n========================================================================================================\n"); + + if (cali_info->CCK_index > c.swing_table_size_cck - 1) + cali_info->CCK_index = c.swing_table_size_cck - 1; + else if (cali_info->CCK_index <= 0) + cali_info->CCK_index = 0; +#endif + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Thermal is unchanged thermal=%d last_thermal=%d\n", + thermal_value, + cali_info->thermal_value); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + cali_info->power_index_offset[p] = 0; + } + +#if 0 + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "TxPowerTracking: [CCK] Swing Current index: %d, Swing base index: %d\n", + cali_info->CCK_index, + cali_info->bb_swing_idx_cck_base); /*Print Swing base & current*/ + + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "TxPowerTracking: [OFDM] Swing Current index: %d, Swing base index[%d]: %d\n", + cali_info->OFDM_index[p], p, + cali_info->bb_swing_idx_ofdm_base[p]); + } +#endif + + if ((dm->support_ic_type & ODM_RTL8814A)) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "power_tracking_type=%d\n", + power_tracking_type); + + if (power_tracking_type == 0) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "***Enter PwrTrk MIX_MODE***\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr) + (dm, MIX_MODE, p, 0); + } else if (power_tracking_type == 1) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "***Enter PwrTrk MIX(2G) TSSI(5G) MODE***\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr) + (dm, MIX_2G_TSSI_5G_MODE, p, 0); + } else if (power_tracking_type == 2) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "***Enter PwrTrk MIX(5G) TSSI(2G)MODE***\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr) + (dm, MIX_5G_TSSI_2G_MODE, p, 0); + } else if (power_tracking_type == 3) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "***Enter PwrTrk TSSI MODE***\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr) + (dm, TSSI_MODE, p, 0); + } + } else if ((cali_info->power_index_offset[RF_PATH_A] != 0 || + cali_info->power_index_offset[RF_PATH_B] != 0 || + cali_info->power_index_offset[RF_PATH_C] != 0 || + cali_info->power_index_offset[RF_PATH_D] != 0)) { +#if 0 + /* 4 7.2 Configure the Swing Table to adjust Tx Power. */ + /*Always true after Tx Power is adjusted by power tracking.*/ + + cali_info->is_tx_power_changed = true; + /* 2012/04/23 MH According to Luke's suggestion, we can not write BB digital + * to increase TX power. Otherwise, EVM will be bad. + * + * 2012/04/25 MH Add for tx power tracking to set tx power in tx agc for 88E. + */ + if (thermal_value > cali_info->thermal_value) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature Increasing(%d): delta_pi: %d, delta_t: %d, Now_t: %d, EFUSE_t: %d, Last_t: %d\n", + p, cali_info->power_index_offset[p], + delta, thermal_value, rf->eeprom_thermal, + cali_info->thermal_value); + } + } else if (thermal_value < cali_info->thermal_value) { /*Low temperature*/ + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature Decreasing(%d): delta_pi: %d, delta_t: %d, Now_t: %d, EFUSE_t: %d, Last_t: %d\n", + p, cali_info->power_index_offset[p], + delta, thermal_value, rf->eeprom_thermal, + cali_info->thermal_value); + } + } +#endif + +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + if (thermal_value > rf->eeprom_thermal) { +#else + if (thermal_value > dm->priv->pmib->dot11RFEntry.ther) { +#endif + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) higher than PG value(%d)\n", + thermal_value, rf->eeprom_thermal); + + odm_pwrtrk_method(dm); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) lower than PG value(%d)\n", + thermal_value, rf->eeprom_thermal); + + odm_pwrtrk_method(dm); + } + +#if 0 + /*Record last time Power Tracking result as base.*/ + cali_info->bb_swing_idx_cck_base = cali_info->bb_swing_idx_cck; + for (p = RF_PATH_A; p < c.rf_path_count; p++) + cali_info->bb_swing_idx_ofdm_base[p] = cali_info->bb_swing_idx_ofdm[p]; +#endif + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->thermal_value = %d thermal_value= %d\n", + cali_info->thermal_value, thermal_value); + } + /*Record last Power Tracking Thermal value*/ + cali_info->thermal_value = thermal_value; + + if (dm->support_ic_type & + (ODM_RTL8703B | ODM_RTL8723D | ODM_RTL8192F | ODM_RTL8710B)) { + if (cali_info->xtal_offset_eanble != 0 && + cali_info->txpowertrack_control && + rf->eeprom_thermal != 0xff) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "**********Enter Xtal Tracking**********\n"); + +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + if (thermal_value > rf->eeprom_thermal) { +#else + if (thermal_value > dm->priv->pmib->dot11RFEntry.ther) { +#endif + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) higher than PG (%d)\n", + thermal_value, rf->eeprom_thermal); + (*c.odm_txxtaltrack_set_xtal)(dm); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) lower than PG (%d)\n", + thermal_value, rf->eeprom_thermal); + (*c.odm_txxtaltrack_set_xtal)(dm); + } + } + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "**********End Xtal Tracking**********\n"); + } + +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + + /* Wait sacn to do IQK by RF Jenyu*/ + if (!(*dm->is_scan_in_process) && !iqk_info->rfk_forbidden && + !cali_info->is_iqk_in_progress && dm->is_linked) { + if (!(dm->support_ic_type & ODM_RTL8723B)) { + /*Delta temperature is equal or larger than 20 Celsius*/ + /*When threshold is 8*/ + if (delta_iqk >= c.threshold_iqk) { + cali_info->thermal_value_iqk = thermal_value; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_iqk(%d) >= threshold_iqk(%d)\n", + delta_iqk, c.threshold_iqk); + (*c.do_iqk)(dm, delta_iqk, thermal_value, 8); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "do pwrtrk iqk\n"); + } + } + } + +#if 0 + if (cali_info->dpk_thermal[RF_PATH_A] != 0) { + if (diff_DPK[RF_PATH_A] >= c.threshold_dpk) { + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xcc4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), (diff_DPK[RF_PATH_A] / c.threshold_dpk)); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } else if ((diff_DPK[RF_PATH_A] <= -1 * c.threshold_dpk)) { + s32 value = 0x20 + (diff_DPK[RF_PATH_A] / c.threshold_dpk); + + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xcc4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), value); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } else { + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xcc4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), 0); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } + } + if (cali_info->dpk_thermal[RF_PATH_B] != 0) { + if (diff_DPK[RF_PATH_B] >= c.threshold_dpk) { + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xec4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), (diff_DPK[RF_PATH_B] / c.threshold_dpk)); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } else if ((diff_DPK[RF_PATH_B] <= -1 * c.threshold_dpk)) { + s32 value = 0x20 + (diff_DPK[RF_PATH_B] / c.threshold_dpk); + + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xec4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), value); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } else { + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xec4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), 0); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } + } +#endif + +#endif + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "<===%s\n", __func__); + + cali_info->tx_powercount = 0; +} + +#if (RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1 || RTL8723F_SUPPORT == 1) +void +odm_txpowertracking_new_callback_thermal_meter(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct dm_iqk_info *iqk_info = &dm->IQK_info; + struct _hal_rf_ *rf = &dm->rf_table; + struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data; + u8 thermal_value[MAX_RF_PATH] = {0}, delta[MAX_RF_PATH] = {0}; + u8 delta_swing_table_idx_tup[DELTA_SWINGIDX_SIZE] = {0}; + u8 delta_swing_table_idx_tdown[DELTA_SWINGIDX_SIZE] = {0}; + u8 delta_LCK = 0, delta_IQK = 0, i = 0, j = 0, p; + u8 thermal_value_avg_count[MAX_RF_PATH] = {0}; + u32 thermal_value_avg[MAX_RF_PATH] = {0}; + s8 thermal_value_temp[MAX_RF_PATH] = {0}; + u8 tracking_method = MIX_MODE; + + struct txpwrtrack_cfg c; + + u8 *delta_swing_table_idx_tup_a = NULL; + u8 *delta_swing_table_idx_tdown_a = NULL; + u8 *delta_swing_table_idx_tup_b = NULL; + u8 *delta_swing_table_idx_tdown_b = NULL; + u8 *delta_swing_table_idx_tup_c = NULL; + u8 *delta_swing_table_idx_tdown_c = NULL; + u8 *delta_swing_table_idx_tup_d = NULL; + u8 *delta_swing_table_idx_tdown_d = NULL; + + configure_txpower_track(dm, &c); + + (*c.get_delta_swing_table)(dm, (u8 **)&delta_swing_table_idx_tup_a, (u8 **)&delta_swing_table_idx_tdown_a, + (u8 **)&delta_swing_table_idx_tup_b, (u8 **)&delta_swing_table_idx_tdown_b); + + if (dm->support_ic_type == ODM_RTL8814B) { + (*c.get_delta_swing_table)(dm, (u8 **)&delta_swing_table_idx_tup_c, (u8 **)&delta_swing_table_idx_tdown_c, + (u8 **)&delta_swing_table_idx_tup_d, (u8 **)&delta_swing_table_idx_tdown_d); + } + + cali_info->txpowertracking_callback_cnt++; + cali_info->is_txpowertracking_init = true; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "===>odm_txpowertracking_callback_thermal_meter\n cali_info->bb_swing_idx_cck_base: %d, cali_info->bb_swing_idx_ofdm_base[A]: %d, cali_info->default_ofdm_index: %d\n", + cali_info->bb_swing_idx_cck_base, cali_info->bb_swing_idx_ofdm_base[RF_PATH_A], cali_info->default_ofdm_index); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->txpowertrack_control=%d, tssi->thermal[RF_PATH_A]=%d tssi->thermal[RF_PATH_B]=%d\n", + cali_info->txpowertrack_control, tssi->thermal[RF_PATH_A], tssi->thermal[RF_PATH_B]); + + if (dm->support_ic_type == ODM_RTL8822C) { + for (i = 0; i < c.rf_path_count; i++) + thermal_value[i] = (u8)odm_get_rf_reg(dm, i, c.thermal_reg_addr, 0x7e); /* 0x42: RF Reg[6:1] Thermal Trim*/ + } else { + for (i = 0; i < c.rf_path_count; i++) { + thermal_value[i] = (u8)odm_get_rf_reg(dm, i, c.thermal_reg_addr, 0xfc00); /* 0x42: RF Reg[15:10] 88E */ + + if (dm->support_ic_type == ODM_RTL8814B) { + thermal_value_temp[i] = (s8)thermal_value[i] + phydm_get_multi_thermal_offset(dm, i); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "thermal_value_temp[%d](%d) = thermal_value[%d](%d) + multi_thermal_trim(%d)\n", i, thermal_value_temp[i], i, thermal_value[i], phydm_get_multi_thermal_offset(dm, i)); + } else { + thermal_value_temp[i] = (s8)thermal_value[i] + phydm_get_thermal_offset(dm); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "thermal_value_temp[%d](%d) = thermal_value[%d](%d) + thermal_trim(%d)\n", i, thermal_value_temp[i], i, thermal_value[i], phydm_get_thermal_offset(dm)); + } + + if (thermal_value_temp[i] > 63) + thermal_value[i] = 63; + else if (thermal_value_temp[i] < 0) + thermal_value[i] = 0; + else + thermal_value[i] = thermal_value_temp[i]; + } + } + + if ((tssi->thermal[RF_PATH_A] == 0xff || tssi->thermal[RF_PATH_B] == 0xff) && + cali_info->txpowertrack_control != 3) { + for (i = 0; i < c.rf_path_count; i++) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "no pg, tssi->thermal[%d] = 0x%x\n", + i, tssi->thermal[i]); + return; + } + + for (j = 0; j < c.rf_path_count; j++) { + cali_info->thermal_value_avg_path[j][cali_info->thermal_value_avg_index_path[j]] = thermal_value[j]; + cali_info->thermal_value_avg_index_path[j]++; + if (cali_info->thermal_value_avg_index_path[j] == c.average_thermal_num) /*Average times = c.average_thermal_num*/ + cali_info->thermal_value_avg_index_path[j] = 0; + + + for (i = 0; i < c.average_thermal_num; i++) { + if (cali_info->thermal_value_avg_path[j][i]) { + thermal_value_avg[j] += cali_info->thermal_value_avg_path[j][i]; + thermal_value_avg_count[j]++; + } + } + + if (thermal_value_avg_count[j]) { /* Calculate Average thermal_value after average enough times */ + thermal_value[j] = (u8)(thermal_value_avg[j] / thermal_value_avg_count[j]); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "AVG Thermal Meter = 0x%X, tssi->thermal[%d] = 0x%x\n", + thermal_value[j], j, tssi->thermal[j]); + } + /* 4 5. Calculate delta, delta_LCK, delta_IQK. */ + + /* "delta" here is used to determine whether thermal value changes or not. */ + delta[j] = (thermal_value[j] > cali_info->thermal_value_path[j]) ? (thermal_value[j] - cali_info->thermal_value_path[j]) : (cali_info->thermal_value_path[j] - thermal_value[j]); + delta_LCK = (thermal_value[0] > cali_info->thermal_value_lck) ? (thermal_value[0] - cali_info->thermal_value_lck) : (cali_info->thermal_value_lck - thermal_value[0]); + delta_IQK = (thermal_value[0] > cali_info->thermal_value_iqk) ? (thermal_value[0] - cali_info->thermal_value_iqk) : (cali_info->thermal_value_iqk - thermal_value[0]); + } + + /*4 6. If necessary, do LCK.*/ + + for (i = 0; i < c.rf_path_count; i++) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "(delta[%d], delta_LCK, delta_IQK) = (%d, %d, %d)\n", i, delta[i], delta_LCK, delta_IQK); + + /* Wait sacn to do LCK by RF Jenyu*/ + if( (*dm->is_scan_in_process == false) && (!iqk_info->rfk_forbidden)) { + /* Delta temperature is equal to or larger than 20 centigrade.*/ + if (delta_LCK >= c.threshold_iqk) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_LCK(%d) >= threshold_iqk(%d)\n", delta_LCK, c.threshold_iqk); + cali_info->thermal_value_lck = thermal_value[RF_PATH_A]; + + /*Use RTLCK, so close power tracking driver LCK*/ + if ((!(dm->support_ic_type & ODM_RTL8814A)) && (!(dm->support_ic_type & ODM_RTL8822B))) { + if (c.phy_lc_calibrate) + (*c.phy_lc_calibrate)(dm); + } else + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Do not do LCK\n"); + } + } + + /*3 7. If necessary, move the index of swing table to adjust Tx power.*/ + for (i = 0; i < c.rf_path_count; i++) { + if (i == RF_PATH_B) { + odm_move_memory(dm, delta_swing_table_idx_tup, delta_swing_table_idx_tup_b, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, delta_swing_table_idx_tdown_b, DELTA_SWINGIDX_SIZE); + } else if (i == RF_PATH_C) { + odm_move_memory(dm, delta_swing_table_idx_tup, delta_swing_table_idx_tup_c, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, delta_swing_table_idx_tdown_c, DELTA_SWINGIDX_SIZE); + } else if (i == RF_PATH_D) { + odm_move_memory(dm, delta_swing_table_idx_tup, delta_swing_table_idx_tup_d, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, delta_swing_table_idx_tdown_d, DELTA_SWINGIDX_SIZE); + } else { + odm_move_memory(dm, delta_swing_table_idx_tup, delta_swing_table_idx_tup_a, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, delta_swing_table_idx_tdown_a, DELTA_SWINGIDX_SIZE); + } + + cali_info->delta_power_index_last[i] = cali_info->delta_power_index[i]; /*recording poer index offset*/ + delta[i] = thermal_value[i] > tssi->thermal[i] ? (thermal_value[i] - tssi->thermal[i]) : (tssi->thermal[i] - thermal_value[i]); + + if (delta[i] >= TXPWR_TRACK_TABLE_SIZE) + delta[i] = TXPWR_TRACK_TABLE_SIZE - 1; + + if (thermal_value[i] > tssi->thermal[i]) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tup[%d]=%d Path=%d\n", delta[i], delta_swing_table_idx_tup[delta[i]], i); + + cali_info->delta_power_index[i] = delta_swing_table_idx_tup[delta[i]]; + cali_info->absolute_ofdm_swing_idx[i] = delta_swing_table_idx_tup[delta[i]]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher and cali_info->absolute_ofdm_swing_idx[%d]=%d Path=%d\n", delta[i], cali_info->absolute_ofdm_swing_idx[i], i); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tdown[%d]=%d Path=%d\n", delta[i], delta_swing_table_idx_tdown[delta[i]], i); + cali_info->delta_power_index[i] = -1 * delta_swing_table_idx_tdown[delta[i]]; + cali_info->absolute_ofdm_swing_idx[i] = -1 * delta_swing_table_idx_tdown[delta[i]]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower and cali_info->absolute_ofdm_swing_idx[%d]=%d Path=%d\n", delta[i], cali_info->absolute_ofdm_swing_idx[i], i); + } + } + + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + if (cali_info->delta_power_index[p] == cali_info->delta_power_index_last[p]) /*If Thermal value changes but lookup table value still the same*/ + cali_info->power_index_offset[p] = 0; + else + cali_info->power_index_offset[p] = cali_info->delta_power_index[p] - cali_info->delta_power_index_last[p]; /*Power index diff between 2 times Power Tracking*/ + } + +#if 0 + if (dm->support_ic_type == ODM_RTL8822C) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking BBSWING_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, BBSWING, p, 0); + } +#endif + if (*dm->mp_mode == 1) { + if (cali_info->txpowertrack_control == 1) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + tracking_method = MIX_MODE; + } else if (cali_info->txpowertrack_control == 3) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking TSSI_MODE**********\n"); + tracking_method = TSSI_MODE; + } + } else { + if (rf->power_track_type >= 0 && rf->power_track_type <= 3) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + tracking_method = MIX_MODE; + } else if (rf->power_track_type >= 4 && rf->power_track_type <= 7) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking TSSI_MODE**********\n"); + tracking_method = TSSI_MODE; + } + } + + if (dm->support_ic_type == ODM_RTL8822C || dm->support_ic_type == ODM_RTL8814B) + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, tracking_method, p, 0); + + /* Wait sacn to do IQK by RF Jenyu*/ + if ((*dm->is_scan_in_process == false) && (!iqk_info->rfk_forbidden) && (dm->is_linked || *dm->mp_mode)) { + /*Delta temperature is equal to or larger than 20 centigrade (When threshold is 8).*/ + if (delta_IQK >= c.threshold_iqk) { + cali_info->thermal_value_iqk = thermal_value[RF_PATH_A]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_IQK(%d) >= threshold_iqk(%d)\n", delta_IQK, c.threshold_iqk); + /*if (!cali_info->is_iqk_in_progress)*/ + /* (*c.do_iqk)(dm, delta_IQK, thermal_value[RF_PATH_A], 8);*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Do IQK\n"); + + /*if (!cali_info->is_iqk_in_progress)*/ + /* (*c.do_tssi_dck)(dm, true);*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Do TSSI DCK\n"); + } + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "<===%s\n", __func__); + + cali_info->tx_powercount = 0; +} +#endif + +/*@3============================================================ + * 3 IQ Calibration + * 3============================================================ + */ + +void odm_reset_iqk_result(void *dm_void) +{ +} + +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) +u8 odm_get_right_chnl_place_for_iqk(u8 chnl) +{ + u8 channel_all[ODM_TARGET_CHNL_NUM_2G_5G] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, + 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, + 124, 126, 128, 130, 132, 134, 136, 138, 140, + 149, 151, 153, 155, 157, 159, 161, 163, 165}; + u8 place = chnl; + + if (chnl > 14) { + for (place = 14; place < sizeof(channel_all); place++) { + if (channel_all[place] == chnl) + return place - 13; + } + } + return 0; +} +#endif + +void odm_iq_calibrate(struct dm_struct *dm) +{ + void *adapter = dm->adapter; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + if (*dm->is_fcs_mode_enable) + return; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_CE)) + if (IS_HARDWARE_TYPE_8812AU(adapter)) + return; +#endif + + if (dm->is_linked && !iqk_info->rfk_forbidden) { + if ((*dm->channel != dm->pre_channel) && + (!*dm->is_scan_in_process)) { + dm->pre_channel = *dm->channel; + dm->linked_interval = 0; + } + + if (dm->linked_interval < 3) + dm->linked_interval++; + + if (dm->linked_interval == 2) + halrf_iqk_trigger(dm, false); + } else { + dm->linked_interval = 0; + } +} + +void phydm_rf_init(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + odm_txpowertracking_init(dm); + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + odm_clear_txpowertracking_state(dm); +#endif +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) +#if (RTL8814A_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814A) + phy_iq_calibrate_8814a_init(dm); +#endif +#endif +} + +void phydm_rf_watchdog(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + odm_txpowertracking_check(dm); +#if 0 +/*if (dm->support_ic_type & ODM_IC_11AC_SERIES)*/ +/*odm_iq_calibrate(dm);*/ +#endif +#endif +} diff --git a/hal/phydm/halrf/halphyrf_ce.h b/hal/phydm/halrf/halphyrf_ce.h new file mode 100644 index 0000000..dcded1e --- /dev/null +++ b/hal/phydm/halrf/halphyrf_ce.h @@ -0,0 +1,123 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALPHYRF_H__ +#define __HALPHYRF_H__ + +#include "halrf/halrf_kfree.h" +#if (RTL8814A_SUPPORT == 1) +#include "halrf/rtl8814a/halrf_iqk_8814a.h" +#endif + +#if (RTL8822B_SUPPORT == 1) +#include "halrf/rtl8822b/halrf_iqk_8822b.h" +#endif + +#if (RTL8821C_SUPPORT == 1) +#include "halrf/rtl8821c/halrf_iqk_8821c.h" +#endif + +#if (RTL8195B_SUPPORT == 1) +/* #include "halrf/rtl8195b/halrf.h" */ +#include "halrf/rtl8195b/halrf_iqk_8195b.h" +#include "halrf/rtl8195b/halrf_txgapk_8195b.h" +#include "halrf/rtl8195b/halrf_dpk_8195b.h" +#endif + +#if (RTL8814B_SUPPORT == 1) + #include "halrf/rtl8814b/halrf_iqk_8814b.h" + #include "halrf/rtl8814b/halrf_dpk_8814b.h" + #include "halrf/rtl8814b/halrf_txgapk_8814b.h" +#endif + +#include "halrf/halrf_powertracking_ce.h" + +enum spur_cal_method { + PLL_RESET, + AFE_PHASE_SEL +}; + +enum pwrtrack_method { + BBSWING, + TXAGC, + MIX_MODE, + TSSI_MODE, + MIX_2G_TSSI_5G_MODE, + MIX_5G_TSSI_2G_MODE, + CLEAN_MODE +}; + +typedef void (*func_set_pwr)(void *, enum pwrtrack_method, u8, u8); +typedef void (*func_iqk)(void *, u8, u8, u8); +typedef void (*func_lck)(void *); +typedef void (*func_tssi_dck)(void *, u8); +typedef void (*func_swing)(void *, u8 **, u8 **, u8 **, u8 **); +typedef void (*func_swing8814only)(void *, u8 **, u8 **, u8 **, u8 **); +typedef void (*func_swing_xtal)(void *, s8 **, s8 **); +typedef void (*func_set_xtal)(void *); + +struct txpwrtrack_cfg { + u8 swing_table_size_cck; + u8 swing_table_size_ofdm; + u8 threshold_iqk; + u8 threshold_dpk; + u8 average_thermal_num; + u8 rf_path_count; + u32 thermal_reg_addr; + func_set_pwr odm_tx_pwr_track_set_pwr; + func_iqk do_iqk; + func_lck phy_lc_calibrate; + func_tssi_dck do_tssi_dck; + func_swing get_delta_swing_table; + func_swing8814only get_delta_swing_table8814only; + func_swing_xtal get_delta_swing_xtal_table; + func_set_xtal odm_txxtaltrack_set_xtal; +}; + +void configure_txpower_track(void *dm_void, struct txpwrtrack_cfg *config); + +void odm_clear_txpowertracking_state(void *dm_void); + +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) +void odm_txpowertracking_callback_thermal_meter(void *dm_void); +#elif (DM_ODM_SUPPORT_TYPE & ODM_CE) +void odm_txpowertracking_callback_thermal_meter(void *dm); +#else +void odm_txpowertracking_callback_thermal_meter(void *adapter); +#endif + +#if (RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1) +void odm_txpowertracking_new_callback_thermal_meter(void *dm_void); +#endif + +#define ODM_TARGET_CHNL_NUM_2G_5G 59 + +void odm_reset_iqk_result(void *dm_void); +u8 odm_get_right_chnl_place_for_iqk(u8 chnl); + +void phydm_rf_init(void *dm_void); +void phydm_rf_watchdog(void *dm_void); + +#endif /*__HALPHYRF_H__*/ diff --git a/hal/phydm/halrf/halphyrf_iot.c b/hal/phydm/halrf/halphyrf_iot.c new file mode 100644 index 0000000..16d9084 --- /dev/null +++ b/hal/phydm/halrf/halphyrf_iot.c @@ -0,0 +1,664 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#include "mp_precomp.h" +#include "phydm_precomp.h" + +#define CALCULATE_SWINGTALBE_OFFSET(_offset, _direction, _size, _delta_thermal) \ + do {\ + for (_offset = 0; _offset < _size; _offset++) { \ + if (_delta_thermal < thermal_threshold[_direction][_offset]) { \ + if (_offset != 0)\ + _offset--;\ + break;\ + } \ + } \ + if (_offset >= _size)\ + _offset = _size-1;\ + } while (0) + +void configure_txpower_track( + void *dm_void, + struct txpwrtrack_cfg *config +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; +#if RTL8195B_SUPPORT + if (dm->support_ic_type == ODM_RTL8195B) + configure_txpower_track_8195b(config); +#endif +#if RTL8710C_SUPPORT + if (dm->support_ic_type == ODM_RTL8710C) + configure_txpower_track_8710c(config); +#endif +#if RTL8721D_SUPPORT + if (dm->support_ic_type == ODM_RTL8721D) + configure_txpower_track_8721d(config); +#endif + +} + +/* ********************************************************************** + * <20121113, Kordan> This function should be called when tx_agc changed. + * Otherwise the previous compensation is gone, because we record the + * delta of temperature between two TxPowerTracking watch dogs. + * + * NOTE: If Tx BB swing or Tx scaling is varified during run-time, still + * need to call this function. + * ********************************************************************** */ +void +odm_clear_txpowertracking_state( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + u8 p = 0; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + + cali_info->bb_swing_idx_cck_base = cali_info->default_cck_index; + cali_info->bb_swing_idx_cck = cali_info->default_cck_index; + dm->rf_calibrate_info.CCK_index = 0; + + for (p = RF_PATH_A; p < MAX_RF_PATH; ++p) { + cali_info->bb_swing_idx_ofdm_base[p] = cali_info->default_ofdm_index; + cali_info->bb_swing_idx_ofdm[p] = cali_info->default_ofdm_index; + cali_info->OFDM_index[p] = cali_info->default_ofdm_index; + + cali_info->power_index_offset[p] = 0; + cali_info->delta_power_index[p] = 0; + cali_info->delta_power_index_last[p] = 0; + + cali_info->absolute_ofdm_swing_idx[p] = 0; + cali_info->remnant_ofdm_swing_idx[p] = 0; + cali_info->kfree_offset[p] = 0; + } + + cali_info->modify_tx_agc_flag_path_a = false; + cali_info->modify_tx_agc_flag_path_b = false; + cali_info->modify_tx_agc_flag_path_c = false; + cali_info->modify_tx_agc_flag_path_d = false; + cali_info->remnant_cck_swing_idx = 0; + cali_info->thermal_value = rf->eeprom_thermal; + cali_info->modify_tx_agc_value_cck = 0; + cali_info->modify_tx_agc_value_ofdm = 0; +} + +void +odm_txpowertracking_callback_thermal_meter( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + u8 thermal_value = 0, delta, delta_LCK, delta_IQK, p = 0, i = 0; + u8 thermal_value_avg_count = 0; + u32 thermal_value_avg = 0, regc80, regcd0, regcd4, regab4; + + u8 OFDM_min_index = 0; /* OFDM BB Swing should be less than +3.0dB, which is required by Arthur */ + u8 indexforchannel = 0; /* get_right_chnl_place_for_iqk(hal_data->current_channel) */ + u8 power_tracking_type = rf->pwt_type; + u8 xtal_offset_eanble = 0; + s8 thermal_value_temp = 0; + u8 xtal_track_efuse = 0; + + struct txpwrtrack_cfg c = {0}; + + /* 4 1. The following TWO tables decide the final index of OFDM/CCK swing table. */ + u8 *delta_swing_table_idx_tup_a = NULL; + u8 *delta_swing_table_idx_tdown_a = NULL; + u8 *delta_swing_table_idx_tup_b = NULL; + u8 *delta_swing_table_idx_tdown_b = NULL; +#if (RTL8721D_SUPPORT == 1) + u8 *delta_swing_table_idx_tup_a_cck = NULL; + u8 *delta_swing_table_idx_tdown_a_cck = NULL; + u8 *delta_swing_table_idx_tup_b_cck = NULL; + u8 *delta_swing_table_idx_tdown_b_cck = NULL; +#endif + /*for Xtal Offset by James.Tung*/ + s8 *delta_swing_table_xtal_up = NULL; + s8 *delta_swing_table_xtal_down = NULL; + + /* 4 2. Initialization ( 7 steps in total ) */ + indexforchannel = odm_get_right_chnl_place_for_iqk(*dm->channel); + configure_txpower_track(dm, &c); +#if (RTL8721D_SUPPORT == 1) + (*c.get_delta_swing_table)(dm, (u8 **)&delta_swing_table_idx_tup_a, (u8 **)&delta_swing_table_idx_tdown_a, + (u8 **)&delta_swing_table_idx_tup_b, (u8 **)&delta_swing_table_idx_tdown_b, + (u8 **)&delta_swing_table_idx_tup_a_cck, (u8 **)&delta_swing_table_idx_tdown_a_cck, + (u8 **)&delta_swing_table_idx_tup_b_cck, (u8 **)&delta_swing_table_idx_tdown_b_cck); +#else + (*c.get_delta_swing_table)(dm, (u8 **)&delta_swing_table_idx_tup_a, (u8 **)&delta_swing_table_idx_tdown_a, + (u8 **)&delta_swing_table_idx_tup_b, (u8 **)&delta_swing_table_idx_tdown_b); +#endif + + /*for Xtal Offset*/ + odm_efuse_one_byte_read(dm, 0xf7, &xtal_track_efuse, false); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Read efuse 0xf7=0x%x\n", xtal_track_efuse); + xtal_track_efuse = xtal_track_efuse & 0x3; + if (dm->support_ic_type == ODM_RTL8195B || + dm->support_ic_type == ODM_RTL8721D || + (dm->support_ic_type == ODM_RTL8710C && xtal_track_efuse == 0x2)) + (*c.get_delta_swing_xtal_table)(dm, + (s8 **)&delta_swing_table_xtal_up, + (s8 **)&delta_swing_table_xtal_down); + + cali_info->txpowertracking_callback_cnt++; /*cosa add for debug*/ + cali_info->is_txpowertracking_init = true; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "===>odm_txpowertracking_callback_thermal_meter\n cali_info->bb_swing_idx_cck_base: %d, cali_info->bb_swing_idx_ofdm_base[A]: %d, cali_info->default_ofdm_index: %d\n", + cali_info->bb_swing_idx_cck_base, + cali_info->bb_swing_idx_ofdm_base[RF_PATH_A], + cali_info->default_ofdm_index); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->txpowertrack_control = %d, hal_data->eeprom_thermal_meter %d\n", + cali_info->txpowertrack_control, rf->eeprom_thermal); + + if (dm->support_ic_type == ODM_RTL8721D + || dm->support_ic_type == ODM_RTL8710C) + thermal_value = (u8)odm_get_rf_reg(dm, RF_PATH_A, + c.thermal_reg_addr, 0x7e0); + /* 0x42: RF Reg[10:5] 8721D */ + else + thermal_value = (u8)odm_get_rf_reg(dm, RF_PATH_A, + c.thermal_reg_addr, 0xfc00); + /* 0x42: RF Reg[15:10] 88E */ + + thermal_value_temp = thermal_value + phydm_get_thermal_offset(dm); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "thermal_value_temp(%d) = thermal_value(%d) + power_trim_thermal(%d)\n", thermal_value_temp, thermal_value, phydm_get_thermal_offset(dm)); + + if (thermal_value_temp > 63) + thermal_value = 63; + else if (thermal_value_temp < 0) + thermal_value = 0; + else + thermal_value = thermal_value_temp; + + if (!cali_info->txpowertrack_control) + return; + + if (rf->eeprom_thermal == 0xff) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "no pg, hal_data->eeprom_thermal_meter = 0x%x\n", rf->eeprom_thermal); + return; + } +#if 0 + /*4 3. Initialize ThermalValues of rf_calibrate_info*/ + //if (cali_info->is_reloadtxpowerindex) + // RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "reload ofdm index for band switch\n"); +#endif + /*4 4. Calculate average thermal meter*/ + + cali_info->thermal_value_avg[cali_info->thermal_value_avg_index] = thermal_value; + cali_info->thermal_value_avg_index++; + if (cali_info->thermal_value_avg_index == c.average_thermal_num) /*Average times = c.average_thermal_num*/ + cali_info->thermal_value_avg_index = 0; + + for (i = 0; i < c.average_thermal_num; i++) { + if (cali_info->thermal_value_avg[i]) { + thermal_value_avg += cali_info->thermal_value_avg[i]; + thermal_value_avg_count++; + } + } + + if (thermal_value_avg_count) { /* Calculate Average thermal_value after average enough times */ + thermal_value = (u8)(thermal_value_avg / thermal_value_avg_count); + cali_info->thermal_value_delta = thermal_value - rf->eeprom_thermal; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "AVG Thermal Meter = 0x%X, EFUSE Thermal base = 0x%X\n", thermal_value, rf->eeprom_thermal); + } + + /* 4 5. Calculate delta, delta_LCK, delta_IQK. */ + /* "delta" here is used to determine whether thermal value changes or not. */ + delta = (thermal_value > cali_info->thermal_value) ? (thermal_value - cali_info->thermal_value) : (cali_info->thermal_value - thermal_value); + delta_LCK = (thermal_value > cali_info->thermal_value_lck) ? (thermal_value - cali_info->thermal_value_lck) : (cali_info->thermal_value_lck - thermal_value); + delta_IQK = (thermal_value > cali_info->thermal_value_iqk) ? (thermal_value - cali_info->thermal_value_iqk) : (cali_info->thermal_value_iqk - thermal_value); + + /*4 6. If necessary, do LCK.*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "(delta, delta_LCK, delta_IQK) = (%d, %d, %d)\n", delta, delta_LCK, delta_IQK); + + /* Wait sacn to do LCK by RF Jenyu*/ + if ((!*dm->is_scan_in_process) && !iqk_info->rfk_forbidden && + (!*dm->is_tdma)) { + /* Delta temperature is equal to or larger than 20 centigrade.*/ + if (delta_LCK >= c.threshold_iqk) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_LCK(%d) >= threshold_iqk(%d)\n", delta_LCK, c.threshold_iqk); + cali_info->thermal_value_lck = thermal_value; + + /*Use RTLCK, so close power tracking driver LCK*/ + (*c.phy_lc_calibrate)(dm); + } + } + + /*3 7. If necessary, move the index of swing table to adjust Tx power.*/ + if (delta > 0 && cali_info->txpowertrack_control) { + /* "delta" here is used to record the absolute value of difference. */ + delta = thermal_value > rf->eeprom_thermal ? (thermal_value - rf->eeprom_thermal) : (rf->eeprom_thermal - thermal_value); + + if (delta >= TXPWR_TRACK_TABLE_SIZE) + delta = TXPWR_TRACK_TABLE_SIZE - 1; + + /*4 7.1 The Final Power index = BaseIndex + power_index_offset*/ + if (thermal_value > rf->eeprom_thermal) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + cali_info->delta_power_index_last[p] = cali_info->delta_power_index[p]; /*recording poer index offset*/ + switch (p) { + case RF_PATH_B: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tup_b[%d] = %d\n", delta, delta_swing_table_idx_tup_b[delta]); +#if (RTL8721D_SUPPORT == 1) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tup_b_cck[%d] = %d\n", delta, delta_swing_table_idx_tup_b_cck[delta]); + + cali_info->absolute_cck_swing_idx[p] = delta_swing_table_idx_tup_b_cck[delta]; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher and cali_info->absolute_cck_swing_idx[RF_PATH_B] = %d\n", + cali_info->absolute_cck_swing_idx[p]); +#endif + cali_info->delta_power_index[p] = + delta_swing_table_idx_tup_b + [delta]; + cali_info->absolute_ofdm_swing_idx[p] = + delta_swing_table_idx_tup_b + [delta]; + /*Record delta swing for mix mode*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher and cali_info->absolute_ofdm_swing_idx[RF_PATH_B] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + default: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tup_a[%d] = %d\n", delta, delta_swing_table_idx_tup_a[delta]); +#if (RTL8721D_SUPPORT == 1) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tup_a_cck[%d] = %d\n", delta, delta_swing_table_idx_tup_a_cck[delta]); + + cali_info->absolute_cck_swing_idx[p] = delta_swing_table_idx_tup_a_cck[delta]; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher and cali_info->absolute_cck_swing_idx[RF_PATH_A] = %d\n", cali_info->absolute_cck_swing_idx[p]); +#endif + cali_info->delta_power_index[p] = delta_swing_table_idx_tup_a[delta]; + cali_info->absolute_ofdm_swing_idx[p] = + delta_swing_table_idx_tup_a[delta]; + /*Record delta swing*/ + /*for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher and cali_info->absolute_ofdm_swing_idx[RF_PATH_A] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + } + } + /* JJ ADD 20161014 */ + if (dm->support_ic_type == ODM_RTL8195B || + dm->support_ic_type == ODM_RTL8721D || + (dm->support_ic_type == ODM_RTL8710C && xtal_track_efuse == 0x2)) { + /*Save xtal_offset from Xtal table*/ + cali_info->xtal_offset_last = cali_info->xtal_offset; /*recording last Xtal offset*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[Xtal] delta_swing_table_xtal_up[%d] = %d\n", delta, delta_swing_table_xtal_up[delta]); + cali_info->xtal_offset = delta_swing_table_xtal_up[delta]; + xtal_offset_eanble = (cali_info->xtal_offset_last != cali_info->xtal_offset); + } + + } else { + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + cali_info->delta_power_index_last[p] = cali_info->delta_power_index[p]; /*recording poer index offset*/ + + switch (p) { + case RF_PATH_B: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tdown_b[%d] = %d\n", delta, delta_swing_table_idx_tdown_b[delta]); +#if (RTL8721D_SUPPORT == 1) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tdown_b_cck[%d] = %d\n", delta, delta_swing_table_idx_tdown_b_cck[delta]); + + cali_info->absolute_cck_swing_idx[p] = -1 * delta_swing_table_idx_tdown_b_cck[delta]; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower and cali_info->absolute_cck_swing_idx[RF_PATH_B] = %d\n", cali_info->absolute_cck_swing_idx[p]); +#endif + cali_info->delta_power_index[p] = -1 * delta_swing_table_idx_tdown_b[delta]; + cali_info->absolute_ofdm_swing_idx[p] = -1 * delta_swing_table_idx_tdown_b[delta]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower and cali_info->absolute_ofdm_swing_idx[RF_PATH_B] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + default: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tdown_a[%d] = %d\n", delta, delta_swing_table_idx_tdown_a[delta]); +#if (RTL8721D_SUPPORT == 1) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tdown_a_cck[%d] = %d\n", delta, delta_swing_table_idx_tdown_a_cck[delta]); + + cali_info->absolute_cck_swing_idx[p] = -1 * delta_swing_table_idx_tdown_a_cck[delta]; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower and cali_info->absolute_cck_swing_idx[RF_PATH_A] = %d\n", cali_info->absolute_cck_swing_idx[p]); +#endif + cali_info->delta_power_index[p] = -1 * delta_swing_table_idx_tdown_a[delta]; + cali_info->absolute_ofdm_swing_idx[p] = -1 * delta_swing_table_idx_tdown_a[delta]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower and cali_info->absolute_ofdm_swing_idx[RF_PATH_A] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + } + } + /* JJ ADD 20161014 */ + + if (dm->support_ic_type == ODM_RTL8195B || + dm->support_ic_type == ODM_RTL8721D || + (dm->support_ic_type == ODM_RTL8710C && xtal_track_efuse == 0x2)) { + /*Save xtal_offset from Xtal table*/ + cali_info->xtal_offset_last = cali_info->xtal_offset; /*recording last Xtal offset*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[Xtal] delta_swing_table_xtal_down[%d] = %d\n", delta, delta_swing_table_xtal_down[delta]); + cali_info->xtal_offset = delta_swing_table_xtal_down[delta]; + xtal_offset_eanble = (cali_info->xtal_offset_last != cali_info->xtal_offset); + } + } +#if 0 + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "\n\n=========================== [path-%d] Calculating power_index_offset===========================\n", p); + + if (cali_info->delta_power_index[p] == cali_info->delta_power_index_last[p]) /*If Thermal value changes but lookup table value still the same*/ + cali_info->power_index_offset[p] = 0; + else + cali_info->power_index_offset[p] = cali_info->delta_power_index[p] - cali_info->delta_power_index_last[p]; /*Power index diff between 2 times Power Tracking*/ + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[path-%d] power_index_offset(%d) = delta_power_index(%d) - delta_power_index_last(%d)\n", p, cali_info->power_index_offset[p], cali_info->delta_power_index[p], cali_info->delta_power_index_last[p]); + + cali_info->OFDM_index[p] = cali_info->bb_swing_idx_ofdm_base[p] + cali_info->power_index_offset[p]; + cali_info->CCK_index = cali_info->bb_swing_idx_cck_base + cali_info->power_index_offset[p]; + + cali_info->bb_swing_idx_cck = cali_info->CCK_index; + cali_info->bb_swing_idx_ofdm[p] = cali_info->OFDM_index[p]; + + /*************Print BB Swing base and index Offset*************/ + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "The 'CCK' final index(%d) = BaseIndex(%d) + power_index_offset(%d)\n", cali_info->bb_swing_idx_cck, cali_info->bb_swing_idx_cck_base, cali_info->power_index_offset[p]); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "The 'OFDM' final index(%d) = BaseIndex[%d](%d) + power_index_offset(%d)\n", cali_info->bb_swing_idx_ofdm[p], p, cali_info->bb_swing_idx_ofdm_base[p], cali_info->power_index_offset[p]); + + /*4 7.1 Handle boundary conditions of index.*/ + + if (cali_info->OFDM_index[p] > c.swing_table_size_ofdm - 1) + cali_info->OFDM_index[p] = c.swing_table_size_ofdm - 1; + else if (cali_info->OFDM_index[p] <= OFDM_min_index) + cali_info->OFDM_index[p] = OFDM_min_index; + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "\n\n========================================================================================================\n"); + + if (cali_info->CCK_index > c.swing_table_size_cck - 1) + cali_info->CCK_index = c.swing_table_size_cck - 1; + else if (cali_info->CCK_index <= 0) + cali_info->CCK_index = 0; +#endif + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "The thermal meter is unchanged or TxPowerTracking OFF(%d): thermal_value: %d, cali_info->thermal_value: %d\n", + cali_info->txpowertrack_control, thermal_value, cali_info->thermal_value); + + for (p = RF_PATH_A; p < c.rf_path_count; p++) + cali_info->power_index_offset[p] = 0; + } +#if 0 + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "TxPowerTracking: [CCK] Swing Current index: %d, Swing base index: %d\n", + cali_info->CCK_index, cali_info->bb_swing_idx_cck_base); /*Print Swing base & current*/ + + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "TxPowerTracking: [OFDM] Swing Current index: %d, Swing base index[%d]: %d\n", + cali_info->OFDM_index[p], p, cali_info->bb_swing_idx_ofdm_base[p]); + } +#endif + +#if (RTL8721D_SUPPORT == 1) + if (thermal_value != cali_info->thermal_value) { + if (thermal_value > rf->eeprom_thermal) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) higher than PG value(%d)\n", + thermal_value, rf->eeprom_thermal); + else if (thermal_value < rf->eeprom_thermal) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) lower than PG value(%d)\n", + thermal_value, rf->eeprom_thermal); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "**********Enter POWER Tracking MIX_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, + indexforchannel); + + /*Record last time Power Tracking result as base.*/ + cali_info->bb_swing_idx_cck_base = cali_info->bb_swing_idx_cck; + for (p = RF_PATH_A; p < c.rf_path_count; p++) + cali_info->bb_swing_idx_ofdm_base[p] = + cali_info->bb_swing_idx_ofdm[p]; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->thermal_value = %d thermal_value= %d\n", + cali_info->thermal_value, thermal_value); + /*Record last Power Tracking Thermal value*/ + cali_info->thermal_value = thermal_value; + } + +#else + if (thermal_value > rf->eeprom_thermal) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) higher than PG value(%d)\n", thermal_value, rf->eeprom_thermal); + + if (dm->support_ic_type == ODM_RTL8188E || + dm->support_ic_type == ODM_RTL8192E || + dm->support_ic_type == ODM_RTL8821 || + dm->support_ic_type == ODM_RTL8812 || + dm->support_ic_type == ODM_RTL8723B || + dm->support_ic_type == ODM_RTL8814A || + dm->support_ic_type == ODM_RTL8703B || + dm->support_ic_type == ODM_RTL8188F || + dm->support_ic_type == ODM_RTL8822B || + dm->support_ic_type == ODM_RTL8723D || + dm->support_ic_type == ODM_RTL8821C || + dm->support_ic_type == ODM_RTL8710B || + dm->support_ic_type == ODM_RTL8192F || + dm->support_ic_type == ODM_RTL8195B || + dm->support_ic_type == ODM_RTL8710C){ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking BBSWING_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, BBSWING, p, indexforchannel); + } + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) lower than PG value(%d)\n", thermal_value, rf->eeprom_thermal); + + if (dm->support_ic_type == ODM_RTL8188E || + dm->support_ic_type == ODM_RTL8192E || + dm->support_ic_type == ODM_RTL8821 || + dm->support_ic_type == ODM_RTL8812 || + dm->support_ic_type == ODM_RTL8723B || + dm->support_ic_type == ODM_RTL8814A || + dm->support_ic_type == ODM_RTL8703B || + dm->support_ic_type == ODM_RTL8188F || + dm->support_ic_type == ODM_RTL8822B || + dm->support_ic_type == ODM_RTL8723D || + dm->support_ic_type == ODM_RTL8821C || + dm->support_ic_type == ODM_RTL8710B || + dm->support_ic_type == ODM_RTL8192F || + dm->support_ic_type == ODM_RTL8195B || + dm->support_ic_type == ODM_RTL8710C) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, indexforchannel); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking BBSWING_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, BBSWING, p, indexforchannel); + } + + cali_info->bb_swing_idx_cck_base = cali_info->bb_swing_idx_cck; /*Record last time Power Tracking result as base.*/ + for (p = RF_PATH_A; p < c.rf_path_count; p++) + cali_info->bb_swing_idx_ofdm_base[p] = cali_info->bb_swing_idx_ofdm[p]; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->thermal_value = %d thermal_value= %d\n", cali_info->thermal_value, thermal_value); + + cali_info->thermal_value = thermal_value; /*Record last Power Tracking Thermal value*/ + } +#endif + /* JJ ADD 20161014 */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->xtal_offset_last=%d cali_info->xtal_offset=%d\n", + cali_info->xtal_offset_last, cali_info->xtal_offset); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "xtal_offset_eanble=%d cali_info->txpowertrack_control=%d rf->eeprom_thermal=%d xtal_track_efuse=%d\n", + xtal_offset_eanble, cali_info->txpowertrack_control, rf->eeprom_thermal, xtal_track_efuse); + + if (dm->support_ic_type == ODM_RTL8195B || + dm->support_ic_type == ODM_RTL8721D || + (dm->support_ic_type == ODM_RTL8710C && xtal_track_efuse == 0x2)) { + if (xtal_offset_eanble != 0 && cali_info->txpowertrack_control && (rf->eeprom_thermal != 0xff)) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter Xtal Tracking**********\n"); + + if (thermal_value > rf->eeprom_thermal) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) higher than PG value(%d)\n", thermal_value, rf->eeprom_thermal); + (*c.odm_txxtaltrack_set_xtal)(dm); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) lower than PG value(%d)\n", thermal_value, rf->eeprom_thermal); + (*c.odm_txxtaltrack_set_xtal)(dm); + } + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********End Xtal Tracking**********\n"); + } + } +#if (!RTL8721D_SUPPORT) + /* Wait sacn to do IQK by RF Jenyu*/ + if ((!*dm->is_scan_in_process) && (!iqk_info->rfk_forbidden) && (dm->is_linked || *dm->mp_mode)) { + /*Delta temperature is equal to or larger than 20 centigrade (When threshold is 8).*/ + if (delta_IQK >= c.threshold_iqk) { + cali_info->thermal_value_iqk = thermal_value; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_IQK(%d) >= threshold_iqk(%d)\n", delta_IQK, c.threshold_iqk); + if (!cali_info->is_iqk_in_progress) + (*c.do_iqk)(dm, delta_IQK, thermal_value, 8); + } + } +#endif + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "<===odm_txpowertracking_callback_thermal_meter\n"); + + cali_info->tx_powercount = 0; +} + +/* 3============================================================ + * 3 IQ Calibration + * 3============================================================ + */ + +void +odm_reset_iqk_result( + void *dm_void +) +{ + return; +} + +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) +u8 odm_get_right_chnl_place_for_iqk(u8 chnl) +{ + u8 channel_all[ODM_TARGET_CHNL_NUM_2G_5G] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, + 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, + 124, 126, 128, 130, 132, 134, 136, 138, 140, + 149, 151, 153, 155, 157, 159, 161, 163, 165}; + u8 place = chnl; + + if (chnl > 14) { + for (place = 14; place < sizeof(channel_all); place++) { + if (channel_all[place] == chnl) + return place - 13; + } + } + return 0; +} +#endif + +void +odm_rf_calibrate(struct dm_struct *dm) +{ +#if (RTL8721D_SUPPORT == 1) + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + if (dm->is_linked && !iqk_info->rfk_forbidden) { + if ((*dm->channel != dm->pre_channel) && + (!*dm->is_scan_in_process)) { + dm->pre_channel = *dm->channel; + dm->linked_interval = 0; + } + + if (dm->linked_interval < 3) + dm->linked_interval++; + + if (dm->linked_interval == 2) + halrf_rf_k_connect_trigger(dm, 0, SEGMENT_FREE); + } else { + dm->linked_interval = 0; + } +#endif +} + +void phydm_rf_init(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + odm_txpowertracking_init(dm); + + odm_clear_txpowertracking_state(dm); +} + +void phydm_rf_watchdog(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + odm_txpowertracking_check(dm); +#if (RTL8721D_SUPPORT == 1) + odm_rf_calibrate(dm); +#endif +} diff --git a/hal/phydm/halrf/halphyrf_iot.h b/hal/phydm/halrf/halphyrf_iot.h new file mode 100644 index 0000000..8d4395a --- /dev/null +++ b/hal/phydm/halrf/halphyrf_iot.h @@ -0,0 +1,137 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALPHYRF_H__ +#define __HALPHYRF_H__ + +#include "halrf/halrf_kfree.h" + +#if (RTL8821C_SUPPORT == 1) + #include "halrf/rtl8821c/halrf_iqk_8821c.h" +#endif + +#if (RTL8195B_SUPPORT == 1) +// #include "halrf/rtl8195b/halrf.h" + #include "halrf/rtl8195b/halrf_iqk_8195b.h" + #include "halrf/rtl8195b/halrf_txgapk_8195b.h" + #include "halrf/rtl8195b/halrf_dpk_8195b.h" +#endif + +#if (RTL8710C_SUPPORT == 1) +// #include "halrf/rtl8710c/halrf.h" + #include "halrf/rtl8710c/halrf_iqk_8710c.h" +// #include "halrf/rtl8710c/halrf_txgapk_8710c.h" +// #include "halrf/rtl8710c/halrf_dpk_8710c.h" +#endif + +#include "halrf/halrf_powertracking_iot.h" + + +enum spur_cal_method { + PLL_RESET, + AFE_PHASE_SEL +}; + +enum pwrtrack_method { + BBSWING, + TXAGC, + MIX_MODE, + TSSI_MODE, + MIX_2G_TSSI_5G_MODE, + MIX_5G_TSSI_2G_MODE, + CLEAN_MODE +}; + +typedef void (*func_set_pwr)(void *, enum pwrtrack_method, u8, u8); +typedef void(*func_iqk)(void *, u8, u8, u8); +typedef void (*func_lck)(void *); +#if (RTL8721D_SUPPORT == 1) + typedef void (*func_swing)(void *, u8 **, u8 **, u8 **, u8 **, + u8 **, u8 **, u8 **, u8 **); +#else + typedef void (*func_swing)(void *, u8 **, u8 **, u8 **, u8 **); +#endif +typedef void (*func_swing8814only)(void *, u8 **, u8 **, u8 **, u8 **); +typedef void(*func_swing_xtal)(void *, s8 **, s8 **); +typedef void(*func_set_xtal)(void *); + +struct txpwrtrack_cfg { + u8 swing_table_size_cck; + u8 swing_table_size_ofdm; + u8 threshold_iqk; + u8 threshold_dpk; + u8 average_thermal_num; + u8 rf_path_count; + u32 thermal_reg_addr; + func_set_pwr odm_tx_pwr_track_set_pwr; + func_iqk do_iqk; + func_lck phy_lc_calibrate; + func_swing get_delta_swing_table; + func_swing8814only get_delta_swing_table8814only; + func_swing_xtal get_delta_swing_xtal_table; + func_set_xtal odm_txxtaltrack_set_xtal; +}; + +void +configure_txpower_track( + void *dm_void, + struct txpwrtrack_cfg *config +); + + +void +odm_clear_txpowertracking_state( + void *dm_void +); + +void +odm_txpowertracking_callback_thermal_meter( +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + void *dm_void +#elif (DM_ODM_SUPPORT_TYPE & ODM_CE) + void *dm +#else + void *adapter +#endif +); + + + +#define ODM_TARGET_CHNL_NUM_2G_5G 59 + + +void +odm_reset_iqk_result( + void *dm_void +); +u8 +odm_get_right_chnl_place_for_iqk( + u8 chnl +); + +void phydm_rf_init(void *dm_void); +void phydm_rf_watchdog(void *dm_void); + +#endif /*#ifndef __HALPHYRF_H__*/ diff --git a/hal/phydm/halrf/halphyrf_win.c b/hal/phydm/halrf/halphyrf_win.c new file mode 100644 index 0000000..ff1b856 --- /dev/null +++ b/hal/phydm/halrf/halphyrf_win.c @@ -0,0 +1,1113 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#include "mp_precomp.h" +#include "phydm_precomp.h" + +#define CALCULATE_SWINGTALBE_OFFSET(_offset, _direction, _size, _delta_thermal) \ + do {\ + for (_offset = 0; _offset < _size; _offset++) { \ + \ + if (_delta_thermal < thermal_threshold[_direction][_offset]) { \ + \ + if (_offset != 0)\ + _offset--;\ + break;\ + } \ + } \ + if (_offset >= _size)\ + _offset = _size-1;\ + } while (0) + +void configure_txpower_track( + struct dm_struct *dm, + struct txpwrtrack_cfg *config +) +{ +#if RTL8192E_SUPPORT + if (dm->support_ic_type == ODM_RTL8192E) + configure_txpower_track_8192e(config); +#endif +#if RTL8821A_SUPPORT + if (dm->support_ic_type == ODM_RTL8821) + configure_txpower_track_8821a(config); +#endif +#if RTL8812A_SUPPORT + if (dm->support_ic_type == ODM_RTL8812) + configure_txpower_track_8812a(config); +#endif +#if RTL8188E_SUPPORT + if (dm->support_ic_type == ODM_RTL8188E) + configure_txpower_track_8188e(config); +#endif + +#if RTL8188F_SUPPORT + if (dm->support_ic_type == ODM_RTL8188F) + configure_txpower_track_8188f(config); +#endif + +#if RTL8723B_SUPPORT + if (dm->support_ic_type == ODM_RTL8723B) + configure_txpower_track_8723b(config); +#endif + +#if RTL8814A_SUPPORT + if (dm->support_ic_type == ODM_RTL8814A) + configure_txpower_track_8814a(config); +#endif + +#if RTL8703B_SUPPORT + if (dm->support_ic_type == ODM_RTL8703B) + configure_txpower_track_8703b(config); +#endif + +#if RTL8822B_SUPPORT + if (dm->support_ic_type == ODM_RTL8822B) + configure_txpower_track_8822b(config); +#endif + +#if RTL8723D_SUPPORT + if (dm->support_ic_type == ODM_RTL8723D) + configure_txpower_track_8723d(config); +#endif + +/* JJ ADD 20161014 */ +#if RTL8710B_SUPPORT + if (dm->support_ic_type == ODM_RTL8710B) + configure_txpower_track_8710b(config); +#endif + +#if RTL8821C_SUPPORT + if (dm->support_ic_type == ODM_RTL8821C) + configure_txpower_track_8821c(config); +#endif + +#if RTL8192F_SUPPORT + if (dm->support_ic_type == ODM_RTL8192F) + configure_txpower_track_8192f(config); +#endif + +#if RTL8822C_SUPPORT + if (dm->support_ic_type == ODM_RTL8822C) + configure_txpower_track_8822c(config); +#endif + +#if RTL8814B_SUPPORT + if (dm->support_ic_type == ODM_RTL8814B) + configure_txpower_track_8814b(config); +#endif + +#if RTL8723F_SUPPORT + if (dm->support_ic_type == ODM_RTL8723F) + configure_txpower_track_8723f(config); +#endif + +} + +/* ********************************************************************** + * <20121113, Kordan> This function should be called when tx_agc changed. + * Otherwise the previous compensation is gone, because we record the + * delta of temperature between two TxPowerTracking watch dogs. + * + * NOTE: If Tx BB swing or Tx scaling is varified during run-time, still + * need to call this function. + * ********************************************************************** */ +void +odm_clear_txpowertracking_state( + struct dm_struct *dm +) +{ + PHAL_DATA_TYPE hal_data = GET_HAL_DATA((PADAPTER)(dm->adapter)); + u8 p = 0; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + + cali_info->bb_swing_idx_cck_base = cali_info->default_cck_index; + cali_info->bb_swing_idx_cck = cali_info->default_cck_index; + cali_info->CCK_index = 0; + + for (p = RF_PATH_A; p < MAX_RF_PATH; ++p) { + cali_info->bb_swing_idx_ofdm_base[p] = cali_info->default_ofdm_index; + cali_info->bb_swing_idx_ofdm[p] = cali_info->default_ofdm_index; + cali_info->OFDM_index[p] = cali_info->default_ofdm_index; + + cali_info->power_index_offset[p] = 0; + cali_info->delta_power_index[p] = 0; + cali_info->delta_power_index_last[p] = 0; + + cali_info->absolute_ofdm_swing_idx[p] = 0; /* Initial Mix mode power tracking*/ + cali_info->remnant_ofdm_swing_idx[p] = 0; + cali_info->kfree_offset[p] = 0; + } + + cali_info->modify_tx_agc_flag_path_a = false; /*Initial at Modify Tx Scaling mode*/ + cali_info->modify_tx_agc_flag_path_b = false; /*Initial at Modify Tx Scaling mode*/ + cali_info->modify_tx_agc_flag_path_c = false; /*Initial at Modify Tx Scaling mode*/ + cali_info->modify_tx_agc_flag_path_d = false; /*Initial at Modify Tx Scaling mode*/ + cali_info->remnant_cck_swing_idx = 0; + cali_info->thermal_value = hal_data->eeprom_thermal_meter; + + cali_info->modify_tx_agc_value_cck = 0; /* modify by Mingzhi.Guo */ + cali_info->modify_tx_agc_value_ofdm = 0; /* modify by Mingzhi.Guo */ + +} + +void +odm_txpowertracking_callback_thermal_meter( +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + struct dm_struct *dm +#else + void *adapter +#endif +) +{ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + struct dm_struct *dm = &hal_data->DM_OutSrc; +#elif (DM_ODM_SUPPORT_TYPE == ODM_CE) + struct dm_struct *dm = &hal_data->odmpriv; +#endif +#endif + + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct dm_iqk_info *iqk_info = &dm->IQK_info; + struct _hal_rf_ *rf = &(dm->rf_table); + u8 thermal_value = 0, delta, delta_LCK, delta_IQK, p = 0, i = 0; + s8 diff_DPK[4] = {0}; + u8 thermal_value_avg_count = 0; + u32 thermal_value_avg = 0, regc80, regcd0, regcd4, regab4, regc88, rege14, reg848,reg838, reg86c; + + u8 OFDM_min_index = 0; /* OFDM BB Swing should be less than +3.0dB, which is required by Arthur */ + u8 indexforchannel = 0; /* get_right_chnl_place_for_iqk(hal_data->current_channel) */ + u8 power_tracking_type = hal_data->RfPowerTrackingType; + u8 xtal_offset_eanble = 0; + s8 thermal_value_temp = 0; + + struct txpwrtrack_cfg c; + + /* 4 1. The following TWO tables decide the final index of OFDM/CCK swing table. */ + u8 *delta_swing_table_idx_tup_a = NULL; + u8 *delta_swing_table_idx_tdown_a = NULL; + u8 *delta_swing_table_idx_tup_b = NULL; + u8 *delta_swing_table_idx_tdown_b = NULL; + /*for 8814 add by Yu Chen*/ + u8 *delta_swing_table_idx_tup_c = NULL; + u8 *delta_swing_table_idx_tdown_c = NULL; + u8 *delta_swing_table_idx_tup_d = NULL; + u8 *delta_swing_table_idx_tdown_d = NULL; + /*for Xtal Offset by James.Tung*/ + s8 *delta_swing_table_xtal_up = NULL; + s8 *delta_swing_table_xtal_down = NULL; + + /* 4 2. Initilization ( 7 steps in total ) */ + + configure_txpower_track(dm, &c); + + (*c.get_delta_swing_table)(dm, (u8 **)&delta_swing_table_idx_tup_a, (u8 **)&delta_swing_table_idx_tdown_a, + (u8 **)&delta_swing_table_idx_tup_b, (u8 **)&delta_swing_table_idx_tdown_b); + + if (dm->support_ic_type & (ODM_RTL8814A | ODM_RTL8814B)) /*for 8814 path C & D*/ + (*c.get_delta_swing_table8814only)(dm, (u8 **)&delta_swing_table_idx_tup_c, (u8 **)&delta_swing_table_idx_tdown_c, + (u8 **)&delta_swing_table_idx_tup_d, (u8 **)&delta_swing_table_idx_tdown_d); + /* JJ ADD 20161014 */ + if (dm->support_ic_type & (ODM_RTL8703B | ODM_RTL8723D | ODM_RTL8710B | ODM_RTL8192F)) /*for Xtal Offset*/ + (*c.get_delta_swing_xtal_table)(dm, (s8 **)&delta_swing_table_xtal_up, (s8 **)&delta_swing_table_xtal_down); + + + cali_info->txpowertracking_callback_cnt++; /*cosa add for debug*/ + cali_info->is_txpowertracking_init = true; + + /*cali_info->txpowertrack_control = hal_data->txpowertrack_control; + We should keep updating the control variable according to HalData. + rf_calibrate_info.rega24 will be initialized when ODM HW configuring, but MP configures with para files. */ +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) +#if (MP_DRIVER == 1) +#ifndef RTL8723F_SUPPORT + cali_info->rega24 = 0x090e1317; +#endif +#endif + +#elif (DM_ODM_SUPPORT_TYPE & ODM_CE) + if (*(dm->mp_mode) == true) + cali_info->rega24 = 0x090e1317; +#endif + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "===>odm_txpowertracking_callback_thermal_meter\n cali_info->bb_swing_idx_cck_base: %d, cali_info->bb_swing_idx_ofdm_base[A]: %d, cali_info->default_ofdm_index: %d\n", + cali_info->bb_swing_idx_cck_base, cali_info->bb_swing_idx_ofdm_base[RF_PATH_A], cali_info->default_ofdm_index); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->txpowertrack_control=%d, hal_data->eeprom_thermal_meter %d\n", cali_info->txpowertrack_control, hal_data->eeprom_thermal_meter); + thermal_value = (u8)odm_get_rf_reg(dm, RF_PATH_A, c.thermal_reg_addr, 0xfc00); /* 0x42: RF Reg[15:10] 88E */ + + thermal_value_temp = thermal_value + phydm_get_thermal_offset(dm); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "thermal_value_temp(%d) = thermal_value(%d) + power_time_thermal(%d)\n", thermal_value_temp, thermal_value, phydm_get_thermal_offset(dm)); + + if (thermal_value_temp > 63) + thermal_value = 63; + else if (thermal_value_temp < 0) + thermal_value = 0; + else + thermal_value = thermal_value_temp; + + /*add log by zhao he, check c80/c94/c14/ca0 value*/ + if (dm->support_ic_type == ODM_RTL8723D) { + regc80 = odm_get_bb_reg(dm, R_0xc80, MASKDWORD); + regcd0 = odm_get_bb_reg(dm, R_0xcd0, MASKDWORD); + regcd4 = odm_get_bb_reg(dm, R_0xcd4, MASKDWORD); + regab4 = odm_get_bb_reg(dm, R_0xab4, 0x000007FF); + RF_DBG(dm, DBG_RF_IQK, "0xc80 = 0x%x 0xcd0 = 0x%x 0xcd4 = 0x%x 0xab4 = 0x%x\n", regc80, regcd0, regcd4, regab4); + } + + /* JJ ADD 20161014 */ + if (dm->support_ic_type == ODM_RTL8710B) { + regc80 = odm_get_bb_reg(dm, R_0xc80, MASKDWORD); + regcd0 = odm_get_bb_reg(dm, R_0xcd0, MASKDWORD); + regcd4 = odm_get_bb_reg(dm, R_0xcd4, MASKDWORD); + regab4 = odm_get_bb_reg(dm, R_0xab4, 0x000007FF); + RF_DBG(dm, DBG_RF_IQK, "0xc80 = 0x%x 0xcd0 = 0x%x 0xcd4 = 0x%x 0xab4 = 0x%x\n", regc80, regcd0, regcd4, regab4); + } + /* Winnita add 20171205 */ + if (dm->support_ic_type == ODM_RTL8192F) { + regc80 = odm_get_bb_reg(dm, R_0xc80, MASKDWORD); + regc88 = odm_get_bb_reg(dm, R_0xc88, MASKDWORD); + regab4 = odm_get_bb_reg(dm, R_0xab4, MASKDWORD); + rege14 = odm_get_bb_reg(dm, R_0xe14, MASKDWORD); + reg848 = odm_get_bb_reg(dm, R_0x848, MASKDWORD); + reg838 = odm_get_bb_reg(dm, R_0x838, MASKDWORD); + reg86c = odm_get_bb_reg(dm, R_0x86c, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xc80 = 0x%x 0xc88 = 0x%x 0xab4 = 0x%x 0xe14 = 0x%x\n", regc80, regc88, regab4, rege14); + RF_DBG(dm, DBG_RF_IQK, "0x848 = 0x%x 0x838 = 0x%x 0x86c = 0x%x\n", reg848, reg838, reg86c); + } + + if (!cali_info->txpowertrack_control) + return; + + if (hal_data->eeprom_thermal_meter == 0xff) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "no pg, hal_data->eeprom_thermal_meter = 0x%x\n", hal_data->eeprom_thermal_meter); + return; + } + + /*4 3. Initialize ThermalValues of rf_calibrate_info*/ + + if (cali_info->is_reloadtxpowerindex) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "reload ofdm index for band switch\n"); + + /*4 4. Calculate average thermal meter*/ + + cali_info->thermal_value_avg[cali_info->thermal_value_avg_index] = thermal_value; + cali_info->thermal_value_avg_index++; + if (cali_info->thermal_value_avg_index == c.average_thermal_num) /*Average times = c.average_thermal_num*/ + cali_info->thermal_value_avg_index = 0; + + for (i = 0; i < c.average_thermal_num; i++) { + if (cali_info->thermal_value_avg[i]) { + thermal_value_avg += cali_info->thermal_value_avg[i]; + thermal_value_avg_count++; + } + } + + if (thermal_value_avg_count) { /* Calculate Average thermal_value after average enough times */ + thermal_value = (u8)(thermal_value_avg / thermal_value_avg_count); + cali_info->thermal_value_delta = thermal_value - hal_data->eeprom_thermal_meter; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "AVG Thermal Meter = 0x%X, EFUSE Thermal base = 0x%X\n", thermal_value, hal_data->eeprom_thermal_meter); + } + + /* 4 5. Calculate delta, delta_LCK, delta_IQK. */ + + /* "delta" here is used to determine whether thermal value changes or not. */ + delta = (thermal_value > cali_info->thermal_value) ? (thermal_value - cali_info->thermal_value) : (cali_info->thermal_value - thermal_value); + delta_LCK = (thermal_value > cali_info->thermal_value_lck) ? (thermal_value - cali_info->thermal_value_lck) : (cali_info->thermal_value_lck - thermal_value); + delta_IQK = (thermal_value > cali_info->thermal_value_iqk) ? (thermal_value - cali_info->thermal_value_iqk) : (cali_info->thermal_value_iqk - thermal_value); + + if (cali_info->thermal_value_iqk == 0xff) { /*no PG, use thermal value for IQK*/ + cali_info->thermal_value_iqk = thermal_value; + delta_IQK = (thermal_value > cali_info->thermal_value_iqk) ? (thermal_value - cali_info->thermal_value_iqk) : (cali_info->thermal_value_iqk - thermal_value); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "no PG, use thermal_value for IQK\n"); + } + + for (p = RF_PATH_A; p < c.rf_path_count; p++) + diff_DPK[p] = (s8)thermal_value - (s8)cali_info->dpk_thermal[p]; + + /*4 6. If necessary, do LCK.*/ + + if (!(dm->support_ic_type & ODM_RTL8821)) { /*no PG, do LCK at initial status*/ + if (cali_info->thermal_value_lck == 0xff) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "no PG, do LCK\n"); + cali_info->thermal_value_lck = thermal_value; + + /*Use RTLCK, so close power tracking driver LCK*/ + if ((!(dm->support_ic_type & ODM_RTL8814A)) && (!(dm->support_ic_type & ODM_RTL8822B))) { + if (c.phy_lc_calibrate) + (*c.phy_lc_calibrate)(dm); + } + + delta_LCK = (thermal_value > cali_info->thermal_value_lck) ? (thermal_value - cali_info->thermal_value_lck) : (cali_info->thermal_value_lck - thermal_value); + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "(delta, delta_LCK, delta_IQK) = (%d, %d, %d)\n", delta, delta_LCK, delta_IQK); + + /* Wait sacn to do LCK by RF Jenyu*/ + if( (*dm->is_scan_in_process == false) && (!iqk_info->rfk_forbidden)) { + /* Delta temperature is equal to or larger than 20 centigrade.*/ + if (delta_LCK >= c.threshold_iqk) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_LCK(%d) >= threshold_iqk(%d)\n", delta_LCK, c.threshold_iqk); + cali_info->thermal_value_lck = thermal_value; + + /*Use RTLCK, so close power tracking driver LCK*/ + if ((!(dm->support_ic_type & ODM_RTL8814A)) && (!(dm->support_ic_type & ODM_RTL8822B))) { + if (c.phy_lc_calibrate) + (*c.phy_lc_calibrate)(dm); + } + } + } + } + + /*3 7. If necessary, move the index of swing table to adjust Tx power.*/ + + if (delta > 0 && cali_info->txpowertrack_control) { + /* "delta" here is used to record the absolute value of differrence. */ +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + delta = thermal_value > hal_data->eeprom_thermal_meter ? (thermal_value - hal_data->eeprom_thermal_meter) : (hal_data->eeprom_thermal_meter - thermal_value); +#else + delta = (thermal_value > dm->priv->pmib->dot11RFEntry.ther) ? (thermal_value - dm->priv->pmib->dot11RFEntry.ther) : (dm->priv->pmib->dot11RFEntry.ther - thermal_value); +#endif + if (delta >= TXPWR_TRACK_TABLE_SIZE) + delta = TXPWR_TRACK_TABLE_SIZE - 1; + + /*4 7.1 The Final Power index = BaseIndex + power_index_offset*/ + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + if (thermal_value > hal_data->eeprom_thermal_meter) { +#else + if (thermal_value > dm->priv->pmib->dot11RFEntry.ther) { +#endif + + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + cali_info->delta_power_index_last[p] = cali_info->delta_power_index[p]; /*recording poer index offset*/ + switch (p) { + case RF_PATH_B: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tup_b[%d] = %d\n", delta, delta_swing_table_idx_tup_b[delta]); + + cali_info->delta_power_index[p] = delta_swing_table_idx_tup_b[delta]; + cali_info->absolute_ofdm_swing_idx[p] = delta_swing_table_idx_tup_b[delta]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher and cali_info->absolute_ofdm_swing_idx[RF_PATH_B] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_C: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tup_c[%d] = %d\n", delta, delta_swing_table_idx_tup_c[delta]); + + cali_info->delta_power_index[p] = delta_swing_table_idx_tup_c[delta]; + cali_info->absolute_ofdm_swing_idx[p] = delta_swing_table_idx_tup_c[delta]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher and cali_info->absolute_ofdm_swing_idx[RF_PATH_C] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_D: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tup_d[%d] = %d\n", delta, delta_swing_table_idx_tup_d[delta]); + + cali_info->delta_power_index[p] = delta_swing_table_idx_tup_d[delta]; + cali_info->absolute_ofdm_swing_idx[p] = delta_swing_table_idx_tup_d[delta]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher and cali_info->absolute_ofdm_swing_idx[RF_PATH_D] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + default: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tup_a[%d] = %d\n", delta, delta_swing_table_idx_tup_a[delta]); + + cali_info->delta_power_index[p] = delta_swing_table_idx_tup_a[delta]; + cali_info->absolute_ofdm_swing_idx[p] = delta_swing_table_idx_tup_a[delta]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher and cali_info->absolute_ofdm_swing_idx[RF_PATH_A] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + } + } + /* JJ ADD 20161014 */ + if (dm->support_ic_type & (ODM_RTL8703B | ODM_RTL8723D | ODM_RTL8710B | ODM_RTL8192F)) { + /*Save xtal_offset from Xtal table*/ + cali_info->xtal_offset_last = cali_info->xtal_offset; /*recording last Xtal offset*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[Xtal] delta_swing_table_xtal_up[%d] = %d\n", delta, delta_swing_table_xtal_up[delta]); + cali_info->xtal_offset = delta_swing_table_xtal_up[delta]; + + if (cali_info->xtal_offset_last == cali_info->xtal_offset) + xtal_offset_eanble = 0; + else + xtal_offset_eanble = 1; + } + + } else { + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + cali_info->delta_power_index_last[p] = cali_info->delta_power_index[p]; /*recording poer index offset*/ + + switch (p) { + case RF_PATH_B: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tdown_b[%d] = %d\n", delta, delta_swing_table_idx_tdown_b[delta]); + cali_info->delta_power_index[p] = -1 * delta_swing_table_idx_tdown_b[delta]; + cali_info->absolute_ofdm_swing_idx[p] = -1 * delta_swing_table_idx_tdown_b[delta]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower and cali_info->absolute_ofdm_swing_idx[RF_PATH_B] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_C: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tdown_c[%d] = %d\n", delta, delta_swing_table_idx_tdown_c[delta]); + cali_info->delta_power_index[p] = -1 * delta_swing_table_idx_tdown_c[delta]; + cali_info->absolute_ofdm_swing_idx[p] = -1 * delta_swing_table_idx_tdown_c[delta]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower and cali_info->absolute_ofdm_swing_idx[RF_PATH_C] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + case RF_PATH_D: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tdown_d[%d] = %d\n", delta, delta_swing_table_idx_tdown_d[delta]); + cali_info->delta_power_index[p] = -1 * delta_swing_table_idx_tdown_d[delta]; + cali_info->absolute_ofdm_swing_idx[p] = -1 * delta_swing_table_idx_tdown_d[delta]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower and cali_info->absolute_ofdm_swing_idx[RF_PATH_D] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + + default: + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tdown_a[%d] = %d\n", delta, delta_swing_table_idx_tdown_a[delta]); + cali_info->delta_power_index[p] = -1 * delta_swing_table_idx_tdown_a[delta]; + cali_info->absolute_ofdm_swing_idx[p] = -1 * delta_swing_table_idx_tdown_a[delta]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower and cali_info->absolute_ofdm_swing_idx[RF_PATH_A] = %d\n", cali_info->absolute_ofdm_swing_idx[p]); + break; + } + } + /* JJ ADD 20161014 */ + if (dm->support_ic_type & (ODM_RTL8703B | ODM_RTL8723D | ODM_RTL8710B | ODM_RTL8192F)) { + /*Save xtal_offset from Xtal table*/ + cali_info->xtal_offset_last = cali_info->xtal_offset; /*recording last Xtal offset*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[Xtal] delta_swing_table_xtal_down[%d] = %d\n", delta, delta_swing_table_xtal_down[delta]); + cali_info->xtal_offset = delta_swing_table_xtal_down[delta]; + + if (cali_info->xtal_offset_last == cali_info->xtal_offset) + xtal_offset_eanble = 0; + else + xtal_offset_eanble = 1; + } + + } + + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "\n\n=========================== [path-%d] Calculating power_index_offset===========================\n", p); + + if (cali_info->delta_power_index[p] == cali_info->delta_power_index_last[p]) /*If Thermal value changes but lookup table value still the same*/ + cali_info->power_index_offset[p] = 0; + else + cali_info->power_index_offset[p] = cali_info->delta_power_index[p] - cali_info->delta_power_index_last[p]; /*Power index diff between 2 times Power Tracking*/ + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[path-%d] power_index_offset(%d) = delta_power_index(%d) - delta_power_index_last(%d)\n", p, cali_info->power_index_offset[p], cali_info->delta_power_index[p], cali_info->delta_power_index_last[p]); + + cali_info->OFDM_index[p] = cali_info->bb_swing_idx_ofdm_base[p] + cali_info->power_index_offset[p]; + cali_info->CCK_index = cali_info->bb_swing_idx_cck_base + cali_info->power_index_offset[p]; + + cali_info->bb_swing_idx_cck = cali_info->CCK_index; + cali_info->bb_swing_idx_ofdm[p] = cali_info->OFDM_index[p]; + + /*************Print BB Swing base and index Offset*************/ + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "The 'CCK' final index(%d) = BaseIndex(%d) + power_index_offset(%d)\n", cali_info->bb_swing_idx_cck, cali_info->bb_swing_idx_cck_base, cali_info->power_index_offset[p]); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "The 'OFDM' final index(%d) = BaseIndex[%d](%d) + power_index_offset(%d)\n", cali_info->bb_swing_idx_ofdm[p], p, cali_info->bb_swing_idx_ofdm_base[p], cali_info->power_index_offset[p]); + + /*4 7.1 Handle boundary conditions of index.*/ + + if (cali_info->OFDM_index[p] > c.swing_table_size_ofdm - 1) + cali_info->OFDM_index[p] = c.swing_table_size_ofdm - 1; + else if (cali_info->OFDM_index[p] <= OFDM_min_index) + cali_info->OFDM_index[p] = OFDM_min_index; + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "\n\n========================================================================================================\n"); + + if (cali_info->CCK_index > c.swing_table_size_cck - 1) + cali_info->CCK_index = c.swing_table_size_cck - 1; + else if (cali_info->CCK_index <= 0) + cali_info->CCK_index = 0; + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "The thermal meter is unchanged or TxPowerTracking OFF(%d): thermal_value: %d, cali_info->thermal_value: %d\n", + cali_info->txpowertrack_control, thermal_value, cali_info->thermal_value); + + for (p = RF_PATH_A; p < c.rf_path_count; p++) + cali_info->power_index_offset[p] = 0; + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "TxPowerTracking: [CCK] Swing Current index: %d, Swing base index: %d\n", + cali_info->CCK_index, cali_info->bb_swing_idx_cck_base); /*Print Swing base & current*/ + + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "TxPowerTracking: [OFDM] Swing Current index: %d, Swing base index[%d]: %d\n", + cali_info->OFDM_index[p], p, cali_info->bb_swing_idx_ofdm_base[p]); + } + + if (dm->support_ic_type & ODM_RTL8814B) + power_tracking_type = TSSI_MODE; + + if (dm->support_ic_type & (ODM_RTL8814A | ODM_RTL8814B)) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "power_tracking_type=%d\n", power_tracking_type); + + if (power_tracking_type == 0) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else if (power_tracking_type == 1) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX(2G) TSSI(5G) MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_2G_TSSI_5G_MODE, p, 0); + } else if (power_tracking_type == 2) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX(5G) TSSI(2G)MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_5G_TSSI_2G_MODE, p, 0); + } else if (power_tracking_type == 3) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking TSSI MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, TSSI_MODE, p, 0); + } + cali_info->thermal_value = thermal_value; /*Record last Power Tracking Thermal value*/ + + } else if ((cali_info->power_index_offset[RF_PATH_A] != 0 || + cali_info->power_index_offset[RF_PATH_B] != 0 || + cali_info->power_index_offset[RF_PATH_C] != 0 || + cali_info->power_index_offset[RF_PATH_D] != 0) && + cali_info->txpowertrack_control && (hal_data->eeprom_thermal_meter != 0xff)) { + /* 4 7.2 Configure the Swing Table to adjust Tx Power. */ + + cali_info->is_tx_power_changed = true; /*Always true after Tx Power is adjusted by power tracking.*/ + /* */ + /* 2012/04/23 MH According to Luke's suggestion, we can not write BB digital */ + /* to increase TX power. Otherwise, EVM will be bad. */ + /* */ + /* 2012/04/25 MH Add for tx power tracking to set tx power in tx agc for 88E. */ + if (thermal_value > cali_info->thermal_value) { + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature Increasing(%d): delta_pi: %d, delta_t: %d, Now_t: %d, EFUSE_t: %d, Last_t: %d\n", + p, cali_info->power_index_offset[p], delta, thermal_value, hal_data->eeprom_thermal_meter, cali_info->thermal_value); + } + } else if (thermal_value < cali_info->thermal_value) { /*Low temperature*/ + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature Decreasing(%d): delta_pi: %d, delta_t: %d, Now_t: %d, EFUSE_t: %d, Last_t: %d\n", + p, cali_info->power_index_offset[p], delta, thermal_value, hal_data->eeprom_thermal_meter, cali_info->thermal_value); + } + } + +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + if (thermal_value > hal_data->eeprom_thermal_meter) +#else + if (thermal_value > dm->priv->pmib->dot11RFEntry.ther) +#endif + { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) higher than PG value(%d)\n", thermal_value, hal_data->eeprom_thermal_meter); + + if (dm->support_ic_type == ODM_RTL8188E || dm->support_ic_type == ODM_RTL8192E || dm->support_ic_type == ODM_RTL8821 || + dm->support_ic_type == ODM_RTL8812 || dm->support_ic_type == ODM_RTL8723B || dm->support_ic_type == ODM_RTL8814A || + dm->support_ic_type == ODM_RTL8703B || dm->support_ic_type == ODM_RTL8188F || dm->support_ic_type == ODM_RTL8822B || + dm->support_ic_type == ODM_RTL8723D || dm->support_ic_type == ODM_RTL8821C || dm->support_ic_type == ODM_RTL8710B || + dm->support_ic_type == ODM_RTL8192F) { + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking BBSWING_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, BBSWING, p, indexforchannel); + } + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) lower than PG value(%d)\n", thermal_value, hal_data->eeprom_thermal_meter); + + if (dm->support_ic_type == ODM_RTL8188E || dm->support_ic_type == ODM_RTL8192E || dm->support_ic_type == ODM_RTL8821 || + dm->support_ic_type == ODM_RTL8812 || dm->support_ic_type == ODM_RTL8723B || dm->support_ic_type == ODM_RTL8814A || + dm->support_ic_type == ODM_RTL8703B || dm->support_ic_type == ODM_RTL8188F || dm->support_ic_type == ODM_RTL8822B || + dm->support_ic_type == ODM_RTL8723D || dm->support_ic_type == ODM_RTL8821C || dm->support_ic_type == ODM_RTL8710B || + dm->support_ic_type == ODM_RTL8192F) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, indexforchannel); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking BBSWING_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, BBSWING, p, indexforchannel); + } + + } + + cali_info->bb_swing_idx_cck_base = cali_info->bb_swing_idx_cck; /*Record last time Power Tracking result as base.*/ + for (p = RF_PATH_A; p < c.rf_path_count; p++) + cali_info->bb_swing_idx_ofdm_base[p] = cali_info->bb_swing_idx_ofdm[p]; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->thermal_value = %d thermal_value= %d\n", cali_info->thermal_value, thermal_value); + + cali_info->thermal_value = thermal_value; /*Record last Power Tracking Thermal value*/ + + } + + + if (dm->support_ic_type == ODM_RTL8703B || dm->support_ic_type == ODM_RTL8723D || + dm->support_ic_type == ODM_RTL8192F || dm->support_ic_type == ODM_RTL8710B) {/* JJ ADD 20161014 */ + + if (xtal_offset_eanble != 0 && cali_info->txpowertrack_control && (hal_data->eeprom_thermal_meter != 0xff)) { + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter Xtal Tracking**********\n"); + +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + if (thermal_value > hal_data->eeprom_thermal_meter) { +#else + if (thermal_value > dm->priv->pmib->dot11RFEntry.ther) { +#endif + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) higher than PG value(%d)\n", thermal_value, hal_data->eeprom_thermal_meter); + (*c.odm_txxtaltrack_set_xtal)(dm); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "Temperature(%d) lower than PG value(%d)\n", thermal_value, hal_data->eeprom_thermal_meter); + (*c.odm_txxtaltrack_set_xtal)(dm); + } + } + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********End Xtal Tracking**********\n"); + } + +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + + /* Wait sacn to do IQK by RF Jenyu*/ + if ((*dm->is_scan_in_process == false) && (!iqk_info->rfk_forbidden) && dm->is_linked) { + if (!IS_HARDWARE_TYPE_8723B(adapter)) { + /*Delta temperature is equal to or larger than 20 centigrade (When threshold is 8).*/ + if (delta_IQK >= c.threshold_iqk) { + cali_info->thermal_value_iqk = thermal_value; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_IQK(%d) >= threshold_iqk(%d)\n", delta_IQK, c.threshold_iqk); + if (!cali_info->is_iqk_in_progress) + (*c.do_iqk)(dm, delta_IQK, thermal_value, 8); + } + } + } + if (cali_info->dpk_thermal[RF_PATH_A] != 0) { + if (diff_DPK[RF_PATH_A] >= c.threshold_dpk) { + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xcc4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), (diff_DPK[RF_PATH_A] / c.threshold_dpk)); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } else if ((diff_DPK[RF_PATH_A] <= -1 * c.threshold_dpk)) { + s32 value = 0x20 + (diff_DPK[RF_PATH_A] / c.threshold_dpk); + + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xcc4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), value); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } else { + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xcc4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), 0); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } + } + if (cali_info->dpk_thermal[RF_PATH_B] != 0) { + if (diff_DPK[RF_PATH_B] >= c.threshold_dpk) { + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xec4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), (diff_DPK[RF_PATH_B] / c.threshold_dpk)); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } else if ((diff_DPK[RF_PATH_B] <= -1 * c.threshold_dpk)) { + s32 value = 0x20 + (diff_DPK[RF_PATH_B] / c.threshold_dpk); + + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xec4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), value); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } else { + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0xec4, BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10), 0); + odm_set_bb_reg(dm, R_0x82c, BIT(31), 0x0); + } + } + +#endif + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "<===odm_txpowertracking_callback_thermal_meter\n"); + + cali_info->tx_powercount = 0; +} + +#if (RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1 || RTL8723F_SUPPORT == 1) +void +odm_txpowertracking_new_callback_thermal_meter(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct dm_iqk_info *iqk_info = &dm->IQK_info; + struct _hal_rf_ *rf = &dm->rf_table; + struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data; + u8 thermal_value[MAX_RF_PATH] = {0}, delta[MAX_RF_PATH] = {0}; + u8 delta_swing_table_idx_tup[DELTA_SWINGIDX_SIZE] = {0}; + u8 delta_swing_table_idx_tdown[DELTA_SWINGIDX_SIZE] = {0}; + u8 delta_LCK = 0, delta_IQK = 0, i = 0, j = 0, p; + u8 thermal_value_avg_count[MAX_RF_PATH] = {0}; + u32 thermal_value_avg[MAX_RF_PATH] = {0}; + s8 thermal_value_temp[MAX_RF_PATH] = {0}; + u8 tracking_method = MIX_MODE; + + struct txpwrtrack_cfg c; + + u8 *delta_swing_table_idx_tup_a = NULL; + u8 *delta_swing_table_idx_tdown_a = NULL; + u8 *delta_swing_table_idx_tup_b = NULL; + u8 *delta_swing_table_idx_tdown_b = NULL; + u8 *delta_swing_table_idx_tup_c = NULL; + u8 *delta_swing_table_idx_tdown_c = NULL; + u8 *delta_swing_table_idx_tup_d = NULL; + u8 *delta_swing_table_idx_tdown_d = NULL; + + configure_txpower_track(dm, &c); + + (*c.get_delta_swing_table)(dm, (u8 **)&delta_swing_table_idx_tup_a, (u8 **)&delta_swing_table_idx_tdown_a, + (u8 **)&delta_swing_table_idx_tup_b, (u8 **)&delta_swing_table_idx_tdown_b); + + if (dm->support_ic_type == ODM_RTL8814B) { + (*c.get_delta_swing_table)(dm, (u8 **)&delta_swing_table_idx_tup_c, (u8 **)&delta_swing_table_idx_tdown_c, + (u8 **)&delta_swing_table_idx_tup_d, (u8 **)&delta_swing_table_idx_tdown_d); + } + + cali_info->txpowertracking_callback_cnt++; + cali_info->is_txpowertracking_init = true; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "===>odm_txpowertracking_callback_thermal_meter\n cali_info->bb_swing_idx_cck_base: %d, cali_info->bb_swing_idx_ofdm_base[A]: %d, cali_info->default_ofdm_index: %d\n", + cali_info->bb_swing_idx_cck_base, cali_info->bb_swing_idx_ofdm_base[RF_PATH_A], cali_info->default_ofdm_index); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->txpowertrack_control=%d, tssi->thermal[RF_PATH_A]=%d tssi->thermal[RF_PATH_B]=%d\n", + cali_info->txpowertrack_control, tssi->thermal[RF_PATH_A], tssi->thermal[RF_PATH_B]); + + if (dm->support_ic_type == ODM_RTL8822C) { + for (i = 0; i < c.rf_path_count; i++) + thermal_value[i] = (u8)odm_get_rf_reg(dm, i, c.thermal_reg_addr, 0x7e); /* 0x42: RF Reg[6:1] Thermal Trim*/ + } else { + for (i = 0; i < c.rf_path_count; i++) { + thermal_value[i] = (u8)odm_get_rf_reg(dm, i, c.thermal_reg_addr, 0xfc00); /* 0x42: RF Reg[15:10] 88E */ + + if (dm->support_ic_type == ODM_RTL8814B) { + thermal_value_temp[i] = (s8)thermal_value[i] + phydm_get_multi_thermal_offset(dm, i); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "thermal_value_temp[%d](%d) = thermal_value[%d](%d) + multi_thermal_trim(%d)\n", i, thermal_value_temp[i], i, thermal_value[i], phydm_get_multi_thermal_offset(dm, i)); + } else { + thermal_value_temp[i] = (s8)thermal_value[i] + phydm_get_thermal_offset(dm); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "thermal_value_temp[%d](%d) = thermal_value[%d](%d) + thermal_trim(%d)\n", i, thermal_value_temp[i], i, thermal_value[i], phydm_get_thermal_offset(dm)); + } + + if (thermal_value_temp[i] > 63) + thermal_value[i] = 63; + else if (thermal_value_temp[i] < 0) + thermal_value[i] = 0; + else + thermal_value[i] = thermal_value_temp[i]; + } + } + + if ((tssi->thermal[RF_PATH_A] == 0xff || tssi->thermal[RF_PATH_B] == 0xff)) { + for (i = 0; i < c.rf_path_count; i++) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "no pg, tssi->thermal[%d] = 0x%x\n", + i, tssi->thermal[i]); + return; + } + + for (j = 0; j < c.rf_path_count; j++) { + cali_info->thermal_value_avg_path[j][cali_info->thermal_value_avg_index_path[j]] = thermal_value[j]; + cali_info->thermal_value_avg_index_path[j]++; + if (cali_info->thermal_value_avg_index_path[j] == c.average_thermal_num) /*Average times = c.average_thermal_num*/ + cali_info->thermal_value_avg_index_path[j] = 0; + + + for (i = 0; i < c.average_thermal_num; i++) { + if (cali_info->thermal_value_avg_path[j][i]) { + thermal_value_avg[j] += cali_info->thermal_value_avg_path[j][i]; + thermal_value_avg_count[j]++; + } + } + + if (thermal_value_avg_count[j]) { /* Calculate Average thermal_value after average enough times */ + thermal_value[j] = (u8)(thermal_value_avg[j] / thermal_value_avg_count[j]); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "AVG Thermal Meter = 0x%X, tssi->thermal[%d] = 0x%x\n", + thermal_value[j], j, tssi->thermal[j]); + } + /* 4 5. Calculate delta, delta_LCK, delta_IQK. */ + + /* "delta" here is used to determine whether thermal value changes or not. */ + delta[j] = (thermal_value[j] > cali_info->thermal_value_path[j]) ? (thermal_value[j] - cali_info->thermal_value_path[j]) : (cali_info->thermal_value_path[j] - thermal_value[j]); + delta_LCK = (thermal_value[0] > cali_info->thermal_value_lck) ? (thermal_value[0] - cali_info->thermal_value_lck) : (cali_info->thermal_value_lck - thermal_value[0]); + delta_IQK = (thermal_value[0] > cali_info->thermal_value_iqk) ? (thermal_value[0] - cali_info->thermal_value_iqk) : (cali_info->thermal_value_iqk - thermal_value[0]); + } + + /*4 6. If necessary, do LCK.*/ + + for (i = 0; i < c.rf_path_count; i++) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "(delta[%d], delta_LCK, delta_IQK) = (%d, %d, %d)\n", i, delta[i], delta_LCK, delta_IQK); + + /* Wait sacn to do LCK by RF Jenyu*/ + if( (*dm->is_scan_in_process == false) && (!iqk_info->rfk_forbidden)) { + /* Delta temperature is equal to or larger than 20 centigrade.*/ + if (delta_LCK >= c.threshold_iqk) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_LCK(%d) >= threshold_iqk(%d)\n", delta_LCK, c.threshold_iqk); + cali_info->thermal_value_lck = thermal_value[RF_PATH_A]; + + /*Use RTLCK, so close power tracking driver LCK*/ + if ((!(dm->support_ic_type & ODM_RTL8814A)) && + (!(dm->support_ic_type & ODM_RTL8822B)) && + (!(dm->support_ic_type & ODM_RTL8723F))) { + if (c.phy_lc_calibrate) + (*c.phy_lc_calibrate)(dm); + } else + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Do not do LCK\n"); + } + } + + /*3 7. If necessary, move the index of swing table to adjust Tx power.*/ + for (i = 0; i < c.rf_path_count; i++) { + if (i == RF_PATH_B) { + odm_move_memory(dm, delta_swing_table_idx_tup, delta_swing_table_idx_tup_b, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, delta_swing_table_idx_tdown_b, DELTA_SWINGIDX_SIZE); + } else if (i == RF_PATH_C) { + odm_move_memory(dm, delta_swing_table_idx_tup, delta_swing_table_idx_tup_c, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, delta_swing_table_idx_tdown_c, DELTA_SWINGIDX_SIZE); + } else if (i == RF_PATH_D) { + odm_move_memory(dm, delta_swing_table_idx_tup, delta_swing_table_idx_tup_d, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, delta_swing_table_idx_tdown_d, DELTA_SWINGIDX_SIZE); + } else { + odm_move_memory(dm, delta_swing_table_idx_tup, delta_swing_table_idx_tup_a, DELTA_SWINGIDX_SIZE); + odm_move_memory(dm, delta_swing_table_idx_tdown, delta_swing_table_idx_tdown_a, DELTA_SWINGIDX_SIZE); + } + + cali_info->delta_power_index_last[i] = cali_info->delta_power_index[i]; /*recording poer index offset*/ + delta[i] = thermal_value[i] > tssi->thermal[i] ? (thermal_value[i] - tssi->thermal[i]) : (tssi->thermal[i] - thermal_value[i]); + + if (delta[i] >= TXPWR_TRACK_TABLE_SIZE) + delta[i] = TXPWR_TRACK_TABLE_SIZE - 1; + + if (thermal_value[i] > tssi->thermal[i]) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tup[%d]=%d Path=%d\n", delta[i], delta_swing_table_idx_tup[delta[i]], i); + + cali_info->delta_power_index[i] = delta_swing_table_idx_tup[delta[i]]; + cali_info->absolute_ofdm_swing_idx[i] = delta_swing_table_idx_tup[delta[i]]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is higher and cali_info->absolute_ofdm_swing_idx[%d]=%d Path=%d\n", delta[i], cali_info->absolute_ofdm_swing_idx[i], i); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "delta_swing_table_idx_tdown[%d]=%d Path=%d\n", delta[i], delta_swing_table_idx_tdown[delta[i]], i); + cali_info->delta_power_index[i] = -1 * delta_swing_table_idx_tdown[delta[i]]; + cali_info->absolute_ofdm_swing_idx[i] = -1 * delta_swing_table_idx_tdown[delta[i]]; /*Record delta swing for mix mode power tracking*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Temp is lower and cali_info->absolute_ofdm_swing_idx[%d]=%d Path=%d\n", delta[i], cali_info->absolute_ofdm_swing_idx[i], i); + } + } + + for (p = RF_PATH_A; p < c.rf_path_count; p++) { + if (cali_info->delta_power_index[p] == cali_info->delta_power_index_last[p]) /*If Thermal value changes but lookup table value still the same*/ + cali_info->power_index_offset[p] = 0; + else + cali_info->power_index_offset[p] = cali_info->delta_power_index[p] - cali_info->delta_power_index_last[p]; /*Power index diff between 2 times Power Tracking*/ + } + +#if 0 + if (dm->support_ic_type == ODM_RTL8822C) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, MIX_MODE, p, 0); + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking BBSWING_MODE**********\n"); + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, BBSWING, p, 0); + } +#endif + if (*dm->mp_mode == 1) { + if (cali_info->txpowertrack_control == 1) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + tracking_method = MIX_MODE; + } else if (cali_info->txpowertrack_control == 3) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking TSSI_MODE**********\n"); + tracking_method = TSSI_MODE; + } + } else { + if (rf->power_track_type >= 0 && rf->power_track_type <= 3) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking MIX_MODE**********\n"); + tracking_method = MIX_MODE; + } else if (rf->power_track_type >= 4 && rf->power_track_type <= 7) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter POWER Tracking TSSI_MODE**********\n"); + tracking_method = TSSI_MODE; + } + } + + if (dm->support_ic_type == ODM_RTL8822C || dm->support_ic_type == ODM_RTL8814B) + for (p = RF_PATH_A; p < c.rf_path_count; p++) + (*c.odm_tx_pwr_track_set_pwr)(dm, tracking_method, p, 0); + + /* Wait sacn to do IQK by RF Jenyu*/ + if ((*dm->is_scan_in_process == false) && (!iqk_info->rfk_forbidden) && (dm->is_linked || *dm->mp_mode)) { + /*Delta temperature is equal to or larger than 20 centigrade (When threshold is 8).*/ + if (delta_IQK >= c.threshold_iqk) { + cali_info->thermal_value_iqk = thermal_value[RF_PATH_A]; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "delta_IQK(%d) >= threshold_iqk(%d)\n", delta_IQK, c.threshold_iqk); + /*if (!cali_info->is_iqk_in_progress)*/ + /* (*c.do_iqk)(dm, delta_IQK, thermal_value[RF_PATH_A], 8);*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Do IQK\n"); + + /*if (!cali_info->is_iqk_in_progress)*/ + /* (*c.do_tssi_dck)(dm, true);*/ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Do TSSI DCK\n"); + } + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "<===%s\n", __func__); + + cali_info->tx_powercount = 0; +} +#endif + +/* 3============================================================ + * 3 IQ Calibration + * 3============================================================ */ + +void +odm_reset_iqk_result( + struct dm_struct *dm +) +{ + return; +} +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) +u8 odm_get_right_chnl_place_for_iqk(u8 chnl) +{ + u8 channel_all[ODM_TARGET_CHNL_NUM_2G_5G] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 149, 151, 153, 155, 157, 159, 161, 163, 165 + }; + u8 place = chnl; + + + if (chnl > 14) { + for (place = 14; place < sizeof(channel_all); place++) { + if (channel_all[place] == chnl) + return place - 13; + } + } + return 0; + +} +#endif + +void +odm_iq_calibrate( + struct dm_struct *dm +) +{ + void *adapter = dm->adapter; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + RF_DBG(dm, DBG_RF_IQK, "=>%s\n",__FUNCTION__); + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + if (*dm->is_fcs_mode_enable) + return; +#endif + if (dm->is_linked) { + RF_DBG(dm, DBG_RF_IQK, + "interval=%d ch=%d prech=%d scan=%s rfk_f =%s\n", + dm->linked_interval, *dm->channel, dm->pre_channel, + *dm->is_scan_in_process == TRUE ? "TRUE":"FALSE", + iqk_info->rfk_forbidden == TRUE ? "TRUE":"FALSE"); + + if (iqk_info->rfk_forbidden) { + RF_DBG(dm, DBG_RF_IQK, "return by rfk_forbidden\n"); + return; + } + + if (*dm->is_scan_in_process) { + RF_DBG(dm, DBG_RF_IQK, "return by is_scan_in_process\n"); + return; + } + + if (*dm->channel != dm->pre_channel) { + dm->pre_channel = *dm->channel; + dm->linked_interval = 0; + } + + if (dm->linked_interval < 3) + dm->linked_interval++; + + if (dm->linked_interval == 2) + PHY_IQCalibrate(adapter, false); + } else { + dm->linked_interval = 0; + RF_DBG(dm, DBG_RF_IQK, "is_linked =%s, interval =%d\n", + dm->is_linked == TRUE ? "TRUE":"FALSE", + dm->linked_interval); + } +} + +void phydm_rf_init(struct dm_struct *dm) +{ + + odm_txpowertracking_init(dm); + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + odm_clear_txpowertracking_state(dm); +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) +#if (RTL8814A_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814A) + phy_iq_calibrate_8814a_init(dm); +#endif +#endif + +} + +void phydm_rf_watchdog(struct dm_struct *dm) +{ +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) + FunctionIn(COMP_MLME); + + if (*dm->mp_mode == 1) { +#if (MP_DRIVER == 1) + odm_txpowertracking_check(dm); +#endif + } else { + odm_txpowertracking_check(dm); + + if (dm->support_ic_type & (ODM_IC_11AC_SERIES | ODM_IC_JGR3_SERIES)) + odm_iq_calibrate(dm); + } +#endif +} diff --git a/hal/phydm/halrf/halphyrf_win.h b/hal/phydm/halrf/halphyrf_win.h new file mode 100644 index 0000000..3769d60 --- /dev/null +++ b/hal/phydm/halrf/halphyrf_win.h @@ -0,0 +1,132 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#ifndef __HALPHYRF_H__ +#define __HALPHYRF_H__ + +#if (RTL8814A_SUPPORT == 1) + #include "halrf/rtl8814a/halrf_iqk_8814a.h" +#endif + +#if (RTL8822B_SUPPORT == 1) + #include "halrf/rtl8822b/halrf_iqk_8822b.h" + #include "../mac/Halmac_type.h" +#endif +#include "halrf/halrf_powertracking_win.h" +#include "halrf/halrf_kfree.h" +#include "halrf/halrf_txgapcal.h" +#if (RTL8821C_SUPPORT == 1) + #include "halrf/rtl8821c/halrf_iqk_8821c.h" +#endif + +#if (RTL8195B_SUPPORT == 1) +// #include "halrf/rtl8195b/halrf.h" + #include "halrf/rtl8195b/halrf_iqk_8195b.h" + #include "halrf/rtl8195b/halrf_txgapk_8195b.h" + #include "halrf/rtl8195b/halrf_dpk_8195b.h" +#endif + +#if (RTL8814B_SUPPORT == 1) + #include "halrf/rtl8814b/halrf_iqk_8814b.h" + #include "halrf/rtl8814b/halrf_txgapk_8814b.h" +#endif + +enum spur_cal_method { + PLL_RESET, + AFE_PHASE_SEL +}; + +enum pwrtrack_method { + BBSWING, + TXAGC, + MIX_MODE, + TSSI_MODE, + MIX_2G_TSSI_5G_MODE, + MIX_5G_TSSI_2G_MODE, + CLEAN_MODE +}; + +typedef void(*func_set_pwr)(void *, enum pwrtrack_method, u8, u8); +typedef void(*func_iqk)(void *, u8, u8, u8); +typedef void(*func_lck)(void *); +typedef void(*func_tssi_dck)(void *, u8); +typedef void(*func_swing)(void *, u8 **, u8 **, u8 **, u8 **); +typedef void(*func_swing8814only)(void *, u8 **, u8 **, u8 **, u8 **); +typedef void (*func_swing_xtal)(void *, s8 **, s8 **); +typedef void (*func_set_xtal)(void *); +typedef void(*func_all_swing)(void *, u8 **, u8 **, u8 **, u8 **, u8 **, u8 **, u8 **, u8 **); + +struct txpwrtrack_cfg { + u8 swing_table_size_cck; + u8 swing_table_size_ofdm; + u8 threshold_iqk; + u8 threshold_dpk; + u8 average_thermal_num; + u8 rf_path_count; + u32 thermal_reg_addr; + func_set_pwr odm_tx_pwr_track_set_pwr; + func_iqk do_iqk; + func_lck phy_lc_calibrate; + func_tssi_dck do_tssi_dck; + func_swing get_delta_swing_table; + func_swing8814only get_delta_swing_table8814only; + func_swing_xtal get_delta_swing_xtal_table; + func_set_xtal odm_txxtaltrack_set_xtal; + func_all_swing get_delta_all_swing_table; +}; + +void +configure_txpower_track( + struct dm_struct *dm, + struct txpwrtrack_cfg *config +); + + +void +odm_clear_txpowertracking_state( + struct dm_struct *dm +); + +void +odm_txpowertracking_callback_thermal_meter( +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + struct dm_struct *dm +#else + void *adapter +#endif +); + +#if (RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1) +void +odm_txpowertracking_new_callback_thermal_meter(void *dm_void); +#endif + +#define ODM_TARGET_CHNL_NUM_2G_5G 59 + + +void +odm_reset_iqk_result( + struct dm_struct *dm +); +u8 +odm_get_right_chnl_place_for_iqk( + u8 chnl +); + +void odm_iq_calibrate(struct dm_struct *dm); +void phydm_rf_init(struct dm_struct *dm); +void phydm_rf_watchdog(struct dm_struct *dm); + +#endif /*#ifndef __HALPHYRF_H__*/ diff --git a/hal/phydm/halrf/halrf.c b/hal/phydm/halrf/halrf.c new file mode 100644 index 0000000..3d82225 --- /dev/null +++ b/hal/phydm/halrf/halrf.c @@ -0,0 +1,4427 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +/*@************************************************************ + * include files + * ************************************************************ + */ + +#include "mp_precomp.h" +#include "phydm_precomp.h" + +#if (RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1 ||\ + RTL8195B_SUPPORT == 1 || RTL8198F_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1 || RTL8822C_SUPPORT == 1 ||\ + RTL8812F_SUPPORT == 1 || RTL8710C_SUPPORT == 1 ||\ + RTL8197G_SUPPORT == 1) + +void _iqk_check_if_reload(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + iqk_info->is_reload = (boolean)odm_get_bb_reg(dm, R_0x1bf0, BIT(16)); +} + +void _iqk_page_switch(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + if (dm->support_ic_type == ODM_RTL8821C) + odm_write_4byte(dm, 0x1b00, 0xf8000008); + else + odm_write_4byte(dm, 0x1b00, 0xf800000a); +} + +u32 halrf_psd_log2base(u32 val) +{ + u8 j; + u32 tmp, tmp2, val_integerd_b = 0, tindex, shiftcount = 0; + u32 result, val_fractiond_b = 0; + u32 table_fraction[21] = { + 0, 432, 332, 274, 232, 200, 174, 151, 132, 115, + 100, 86, 74, 62, 51, 42, 32, 23, 15, 7, 0}; + + if (val == 0) + return 0; + + tmp = val; + + while (1) { + if (tmp == 1) + break; + + tmp = (tmp >> 1); + shiftcount++; + } + + val_integerd_b = shiftcount + 1; + + tmp2 = 1; + for (j = 1; j <= val_integerd_b; j++) + tmp2 = tmp2 * 2; + + tmp = (val * 100) / tmp2; + tindex = tmp / 5; + + if (tindex > 20) + tindex = 20; + + val_fractiond_b = table_fraction[tindex]; + + result = val_integerd_b * 100 - val_fractiond_b; + + return result; +} +#if (RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1 || RTL8822C_SUPPORT == 1) +void halrf_iqk_xym_enable(struct dm_struct *dm, u8 xym_enable) +{ + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + if (xym_enable == 0) + iqk_info->xym_read = false; + else + iqk_info->xym_read = true; + + RF_DBG(dm, DBG_RF_IQK, "[IQK]%-20s %s\n", "xym_read = ", + (iqk_info->xym_read ? "true" : "false")); +} + +/*xym_type => 0: rx_sym; 1: tx_xym; 2:gs1_xym; 3:gs2_sym; 4: rxk1_xym*/ +void halrf_iqk_xym_read(void *dm_void, u8 path, u8 xym_type) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + u8 i, start, num; + u32 tmp1, tmp2; + + if (!iqk_info->xym_read) + return; + + if (*dm->band_width == 0) { + start = 3; + num = 4; + } else if (*dm->band_width == 1) { + start = 2; + num = 6; + } else { + start = 0; + num = 10; + } + + odm_write_4byte(dm, 0x1b00, 0xf8000008); + tmp1 = odm_read_4byte(dm, 0x1b1c); + odm_write_4byte(dm, 0x1b1c, 0xa2193c32); + + odm_write_4byte(dm, 0x1b00, 0xf800000a); + tmp2 = odm_read_4byte(dm, 0x1b1c); + odm_write_4byte(dm, 0x1b1c, 0xa2193c32); + + for (path = 0; path < 2; path++) { + odm_write_4byte(dm, 0x1b00, 0xf8000008 | path << 1); + switch (xym_type) { + case 0: + for (i = 0; i < num; i++) { + odm_write_4byte(dm, 0x1b14, 0xe6 + start + i); + odm_write_4byte(dm, 0x1b14, 0x0); + iqk_info->rx_xym[path][i] = + odm_read_4byte(dm, 0x1b38); + } + break; + case 1: + for (i = 0; i < num; i++) { + odm_write_4byte(dm, 0x1b14, 0xe6 + start + i); + odm_write_4byte(dm, 0x1b14, 0x0); + iqk_info->tx_xym[path][i] = + odm_read_4byte(dm, 0x1b38); + } + break; + case 2: + for (i = 0; i < 6; i++) { + odm_write_4byte(dm, 0x1b14, 0xe0 + i); + odm_write_4byte(dm, 0x1b14, 0x0); + iqk_info->gs1_xym[path][i] = + odm_read_4byte(dm, 0x1b38); + } + break; + case 3: + for (i = 0; i < 6; i++) { + odm_write_4byte(dm, 0x1b14, 0xe0 + i); + odm_write_4byte(dm, 0x1b14, 0x0); + iqk_info->gs2_xym[path][i] = + odm_read_4byte(dm, 0x1b38); + } + break; + case 4: + for (i = 0; i < 6; i++) { + odm_write_4byte(dm, 0x1b14, 0xe0 + i); + odm_write_4byte(dm, 0x1b14, 0x0); + iqk_info->rxk1_xym[path][i] = + odm_read_4byte(dm, 0x1b38); + } + break; + } + odm_write_4byte(dm, 0x1b38, 0x20000000); + odm_write_4byte(dm, 0x1b00, 0xf8000008); + odm_write_4byte(dm, 0x1b1c, tmp1); + odm_write_4byte(dm, 0x1b00, 0xf800000a); + odm_write_4byte(dm, 0x1b1c, tmp2); + _iqk_page_switch(dm); + } +} + +/*xym_type => 0: rx_sym; 1: tx_xym; 2:gs1_xym; 3:gs2_sym; 4: rxk1_xym*/ +void halrf_iqk_xym_show(struct dm_struct *dm, u8 xym_type) +{ + u8 num, path, path_num, i; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + if (dm->rf_type == RF_1T1R) + path_num = 0x1; + else if (dm->rf_type == RF_2T2R) + path_num = 0x2; + else + path_num = 0x4; + + if (*dm->band_width == CHANNEL_WIDTH_20) + num = 4; + else if (*dm->band_width == CHANNEL_WIDTH_40) + num = 6; + else + num = 10; + + for (path = 0; path < path_num; path++) { + switch (xym_type) { + case 0: + for (i = 0; i < num; i++) + RF_DBG(dm, DBG_RF_IQK, + "[IQK]%-20s %-2d: 0x%x\n", + (path == 0) ? "PATH A RX-XYM " : + "PATH B RX-XYM", i, + iqk_info->rx_xym[path][i]); + break; + case 1: + for (i = 0; i < num; i++) + RF_DBG(dm, DBG_RF_IQK, + "[IQK]%-20s %-2d: 0x%x\n", + (path == 0) ? "PATH A TX-XYM " : + "PATH B TX-XYM", i, + iqk_info->tx_xym[path][i]); + break; + case 2: + for (i = 0; i < 6; i++) + RF_DBG(dm, DBG_RF_IQK, + "[IQK]%-20s %-2d: 0x%x\n", + (path == 0) ? "PATH A GS1-XYM " : + "PATH B GS1-XYM", i, + iqk_info->gs1_xym[path][i]); + break; + case 3: + for (i = 0; i < 6; i++) + RF_DBG(dm, DBG_RF_IQK, + "[IQK]%-20s %-2d: 0x%x\n", + (path == 0) ? "PATH A GS2-XYM " : + "PATH B GS2-XYM", i, + iqk_info->gs2_xym[path][i]); + break; + case 4: + for (i = 0; i < 6; i++) + RF_DBG(dm, DBG_RF_IQK, + "[IQK]%-20s %-2d: 0x%x\n", + (path == 0) ? "PATH A RXK1-XYM " : + "PATH B RXK1-XYM", i, + iqk_info->rxk1_xym[path][i]); + break; + } + } +} + +void halrf_iqk_xym_dump(void *dm_void) +{ + u32 tmp1, tmp2; + struct dm_struct *dm = (struct dm_struct *)dm_void; + + odm_write_4byte(dm, 0x1b00, 0xf8000008); + tmp1 = odm_read_4byte(dm, 0x1b1c); + odm_write_4byte(dm, 0x1b00, 0xf800000a); + tmp2 = odm_read_4byte(dm, 0x1b1c); +#if 0 + /*halrf_iqk_xym_read(dm, xym_type);*/ +#endif + odm_write_4byte(dm, 0x1b00, 0xf8000008); + odm_write_4byte(dm, 0x1b1c, tmp1); + odm_write_4byte(dm, 0x1b00, 0xf800000a); + odm_write_4byte(dm, 0x1b1c, tmp2); + _iqk_page_switch(dm); +} +#endif +void halrf_iqk_info_dump(void *dm_void, u32 *_used, char *output, u32 *_out_len) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 used = *_used; + u32 out_len = *_out_len; + u8 rf_path, j, reload_iqk = 0; + u32 tmp; + /*two channel, PATH, TX/RX, 0:pass 1 :fail*/ + boolean iqk_result[2][NUM][2]; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + if (!(dm->support_ic_type & (ODM_RTL8822B | ODM_RTL8821C))) + return; + + /* IQK INFO */ + PDM_SNPF(out_len, used, output + used, out_len - used, "%-20s\n", + "% IQK Info %"); + PDM_SNPF(out_len, used, output + used, out_len - used, "%-20s\n", + (dm->fw_offload_ability & PHYDM_RF_IQK_OFFLOAD) ? "FW-IQK" : + "Driver-IQK"); + + reload_iqk = (u8)odm_get_bb_reg(dm, R_0x1bf0, BIT(16)); + PDM_SNPF(out_len, used, output + used, out_len - used, "%-20s: %s\n", + "reload", (reload_iqk) ? "True" : "False"); + + PDM_SNPF(out_len, used, output + used, out_len - used, "%-20s: %s\n", + "rfk_forbidden", (iqk_info->rfk_forbidden) ? "True" : "False"); +#if (RTL8814A_SUPPORT == 1 || RTL8822B_SUPPORT == 1 || \ + RTL8821C_SUPPORT == 1 || RTL8195B_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1 || RTL8822C_SUPPORT == 1) + PDM_SNPF(out_len, used, output + used, out_len - used, "%-20s: %s\n", + "segment_iqk", (iqk_info->segment_iqk) ? "True" : "False"); +#endif + + PDM_SNPF(out_len, used, output + used, out_len - used, "%-20s:%d %d\n", + "iqk count / fail count", dm->n_iqk_cnt, dm->n_iqk_fail_cnt); + + PDM_SNPF(out_len, used, output + used, out_len - used, "%-20s: %d\n", + "channel", *dm->channel); + + if (*dm->band_width == CHANNEL_WIDTH_20) + PDM_SNPF(out_len, used, output + used, out_len - used, + "%-20s: %s\n", "bandwidth", "BW_20"); + else if (*dm->band_width == CHANNEL_WIDTH_40) + PDM_SNPF(out_len, used, output + used, out_len - used, + "%-20s: %s\n", "bandwidth", "BW_40"); + else if (*dm->band_width == CHANNEL_WIDTH_80) + PDM_SNPF(out_len, used, output + used, out_len - used, + "%-20s: %s\n", "bandwidth", "BW_80"); + else if (*dm->band_width == CHANNEL_WIDTH_160) + PDM_SNPF(out_len, used, output + used, out_len - used, + "%-20s: %s\n", "bandwidth", "BW_160"); + else if (*dm->band_width == CHANNEL_WIDTH_80_80) + PDM_SNPF(out_len, used, output + used, out_len - used, + "%-20s: %s\n", "bandwidth", "BW_80_80"); + else + PDM_SNPF(out_len, used, output + used, out_len - used, + "%-20s: %s\n", "bandwidth", "BW_UNKNOWN"); + + PDM_SNPF(out_len, used, output + used, out_len - used, + "%-20s: %llu %s\n", "progressing_time", + dm->rf_calibrate_info.iqk_total_progressing_time, "(ms)"); + + tmp = odm_read_4byte(dm, 0x1bf0); + for (rf_path = RF_PATH_A; rf_path <= RF_PATH_B; rf_path++) + for (j = 0; j < 2; j++) + iqk_result[0][rf_path][j] = (boolean) + (tmp & (BIT(rf_path + (j * 4)) >> (rf_path + (j * 4)))); + + PDM_SNPF(out_len, used, output + used, out_len - used, + "%-20s: 0x%08x\n", "Reg0x1bf0", tmp); + PDM_SNPF(out_len, used, output + used, out_len - used, "%-20s: %s\n", + "PATH_A-Tx result", + (iqk_result[0][RF_PATH_A][0]) ? "Fail" : "Pass"); + PDM_SNPF(out_len, used, output + used, out_len - used, "%-20s: %s\n", + "PATH_A-Rx result", + (iqk_result[0][RF_PATH_A][1]) ? "Fail" : "Pass"); +#if (RTL8822B_SUPPORT == 1) + PDM_SNPF(out_len, used, output + used, out_len - used, "%-20s: %s\n", + "PATH_B-Tx result", + (iqk_result[0][RF_PATH_B][0]) ? "Fail" : "Pass"); + PDM_SNPF(out_len, used, output + used, out_len - used, "%-20s: %s\n", + "PATH_B-Rx result", + (iqk_result[0][RF_PATH_B][1]) ? "Fail" : "Pass"); +#endif + *_used = used; + *_out_len = out_len; +} + +void halrf_get_fw_version(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + rf->fw_ver = (dm->fw_version << 16) | dm->fw_sub_version; +} + +void halrf_iqk_dbg(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u8 rf_path, j; + u32 tmp; + /*two channel, PATH, TX/RX, 0:pass 1 :fail*/ + boolean iqk_result[2][NUM][2]; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + struct _hal_rf_ *rf = &dm->rf_table; + + /* IQK INFO */ + RF_DBG(dm, DBG_RF_IQK, "%-20s\n", "====== IQK Info ======"); + + RF_DBG(dm, DBG_RF_IQK, "%-20s\n", + (dm->fw_offload_ability & PHYDM_RF_IQK_OFFLOAD) ? "FW-IQK" : + "Driver-IQK"); + + if (dm->fw_offload_ability & PHYDM_RF_IQK_OFFLOAD) { + halrf_get_fw_version(dm); + RF_DBG(dm, DBG_RF_IQK, "%-20s: 0x%x\n", "FW_VER", rf->fw_ver); + } else { + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "IQK_VER", HALRF_IQK_VER); + } + + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "reload", + (iqk_info->is_reload) ? "True" : "False"); + + RF_DBG(dm, DBG_RF_IQK, "%-20s: %d %d\n", "iqk count / fail count", + dm->n_iqk_cnt, dm->n_iqk_fail_cnt); + + RF_DBG(dm, DBG_RF_IQK, "%-20s: %d\n", "channel", *dm->channel); + + if (*dm->band_width == CHANNEL_WIDTH_20) + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "bandwidth", "BW_20"); + else if (*dm->band_width == CHANNEL_WIDTH_40) + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "bandwidth", "BW_40"); + else if (*dm->band_width == CHANNEL_WIDTH_80) + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "bandwidth", "BW_80"); + else if (*dm->band_width == CHANNEL_WIDTH_160) + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "bandwidth", "BW_160"); + else if (*dm->band_width == CHANNEL_WIDTH_80_80) + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "bandwidth", "BW_80_80"); + else + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "bandwidth", + "BW_UNKNOWN"); +#if 0 +/* + * RF_DBG(dm, DBG_RF_IQK, "%-20s: %llu %s\n", + * "progressing_time", + * dm->rf_calibrate_info.iqk_total_progressing_time, "(ms)"); + */ +#endif + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "rfk_forbidden", + (iqk_info->rfk_forbidden) ? "True" : "False"); +#if (RTL8814A_SUPPORT == 1 || RTL8822B_SUPPORT == 1 || \ + RTL8821C_SUPPORT == 1 || RTL8195B_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1 || RTL8822C_SUPPORT == 1) + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "segment_iqk", + (iqk_info->segment_iqk) ? "True" : "False"); +#endif + + RF_DBG(dm, DBG_RF_IQK, "%-20s: %llu %s\n", "progressing_time", + dm->rf_calibrate_info.iqk_progressing_time, "(ms)"); + + tmp = odm_read_4byte(dm, 0x1bf0); + for (rf_path = RF_PATH_A; rf_path <= RF_PATH_B; rf_path++) + for (j = 0; j < 2; j++) + iqk_result[0][rf_path][j] = (boolean) + (tmp & (BIT(rf_path + (j * 4)) >> (rf_path + (j * 4)))); + + RF_DBG(dm, DBG_RF_IQK, "%-20s: 0x%08x\n", "Reg0x1bf0", tmp); + RF_DBG(dm, DBG_RF_IQK, "%-20s: 0x%08x\n", "Reg0x1be8", + odm_read_4byte(dm, 0x1be8)); + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "PATH_A-Tx result", + (iqk_result[0][RF_PATH_A][0]) ? "Fail" : "Pass"); + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "PATH_A-Rx result", + (iqk_result[0][RF_PATH_A][1]) ? "Fail" : "Pass"); +#if (RTL8822B_SUPPORT == 1) + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "PATH_B-Tx result", + (iqk_result[0][RF_PATH_B][0]) ? "Fail" : "Pass"); + RF_DBG(dm, DBG_RF_IQK, "%-20s: %s\n", "PATH_B-Rx result", + (iqk_result[0][RF_PATH_B][1]) ? "Fail" : "Pass"); +#endif +} + +void halrf_lck_dbg(struct dm_struct *dm) +{ + RF_DBG(dm, DBG_RF_IQK, "%-20s\n", "====== LCK Info ======"); +#if 0 + /*RF_DBG(dm, DBG_RF_IQK, "%-20s\n", + * (dm->fw_offload_ability & PHYDM_RF_IQK_OFFLOAD) ? "LCK" : "RTK")); + */ +#endif + RF_DBG(dm, DBG_RF_IQK, "%-20s: %llu %s\n", "progressing_time", + dm->rf_calibrate_info.lck_progressing_time, "(ms)"); +} +void phydm_get_iqk_cfir(void *dm_void, u8 idx, u8 path, boolean debug) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + switch (dm->support_ic_type) { +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + phy_get_iqk_cfir_8822b(dm, idx, path, debug); + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + phy_get_iqk_cfir_8822c(dm, idx, path, debug); + break; +#endif +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + phy_get_iqk_cfir_8814b(dm, idx, path, debug); + break; +#endif + default: + break; + } +} + + +void halrf_iqk_dbg_cfir_backup(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + u8 path, idx, i; + + switch (dm->support_ic_type) { +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + phy_iqk_dbg_cfir_backup_8822b(dm); + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + phy_iqk_dbg_cfir_backup_8822c(dm); + break; +#endif +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + phy_iqk_dbg_cfir_backup_8814b(dm); + break; +#endif + default: + break; + } + +} + +void halrf_iqk_dbg_cfir_backup_update(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk = &dm->IQK_info; + u8 i, path, idx; + u32 bmask13_12 = BIT(13) | BIT(12); + u32 bmask20_16 = BIT(20) | BIT(19) | BIT(18) | BIT(17) | BIT(16); + u32 data; + + switch (dm->support_ic_type) { +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + phy_iqk_dbg_cfir_backup_update_8822b(dm); + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + phy_iqk_dbg_cfir_backup_update_8822c(dm); + break; +#endif + default: + break; + } +} + +void halrf_iqk_dbg_cfir_reload(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk = &dm->IQK_info; + u8 i, path, idx; + u32 bmask13_12 = BIT(13) | BIT(12); + u32 bmask20_16 = BIT(20) | BIT(19) | BIT(18) | BIT(17) | BIT(16); + u32 data; + + switch (dm->support_ic_type) { +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + phy_iqk_dbg_cfir_reload_8822b(dm); + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + phy_iqk_dbg_cfir_reload_8822c(dm); + break; +#endif + default: + break; + } +} + +void halrf_iqk_dbg_cfir_write(void *dm_void, u8 type, u32 path, u32 idx, + u32 i, u32 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + switch (dm->support_ic_type) { +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + phy_iqk_dbg_cfir_write_8822b(dm, type, path, idx, i, data); + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + phy_iqk_dbg_cfir_write_8822c(dm, type, path, idx, i, data); + break; +#endif + default: + break; + } +} + +void halrf_iqk_dbg_cfir_backup_show(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + u8 path, idx, i; + + switch (dm->support_ic_type) { +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + phy_iqk_dbg_cfir_backup_8822b(dm); + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + phy_iqk_dbg_cfir_backup_8822c(dm); + break; +#endif + default: + break; + } +} + +void halrf_do_imr_test(void *dm_void, u8 flag_imr_test) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + if (flag_imr_test != 0x0) + switch (dm->support_ic_type) { +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + do_imr_test_8822b(dm); + break; +#endif +#if (RTL8821C_SUPPORT == 1) + case ODM_RTL8821C: + do_imr_test_8821c(dm); + break; +#endif + default: + break; + } +} + +#if (RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1 || RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1) +void halrf_iqk_debug(void *dm_void, u32 *const dm_value, u32 *_used, + char *output, u32 *_out_len) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if 0 + /*dm_value[0]=0x0: backup from SRAM & show*/ + /*dm_value[0]=0x1: write backup CFIR to SRAM*/ + /*dm_value[0]=0x2: reload default CFIR to SRAM*/ + /*dm_value[0]=0x3: show backup*/ + /*dm_value[0]=0x10: write backup CFIR real part*/ + /*--> dm_value[1]:path, dm_value[2]:tx/rx, dm_value[3]:index, dm_value[4]:data*/ + /*dm_value[0]=0x11: write backup CFIR imag*/ + /*--> dm_value[1]:path, dm_value[2]:tx/rx, dm_value[3]:index, dm_value[4]:data*/ + /*dm_value[0]=0x20 :xym_read enable*/ + /*--> dm_value[1]:0:disable, 1:enable*/ + /*if dm_value[0]=0x20 = enable, */ + /*0x1:show rx_sym; 0x2: tx_xym; 0x3:gs1_xym; 0x4:gs2_sym; 0x5:rxk1_xym*/ +#endif + if (dm_value[0] == 0x0) + halrf_iqk_dbg_cfir_backup(dm); + else if (dm_value[0] == 0x1) + halrf_iqk_dbg_cfir_backup_update(dm); + else if (dm_value[0] == 0x2) + halrf_iqk_dbg_cfir_reload(dm); + else if (dm_value[0] == 0x3) + halrf_iqk_dbg_cfir_backup_show(dm); + else if (dm_value[0] == 0x10) + halrf_iqk_dbg_cfir_write(dm, 0, dm_value[1], dm_value[2], + dm_value[3], dm_value[4]); + else if (dm_value[0] == 0x11) + halrf_iqk_dbg_cfir_write(dm, 1, dm_value[1], dm_value[2], + dm_value[3], dm_value[4]); + else if (dm_value[0] == 0x20) + halrf_iqk_xym_enable(dm, (u8)dm_value[1]); + else if (dm_value[0] == 0x21) + halrf_iqk_xym_show(dm, (u8)dm_value[1]); + else if (dm_value[0] == 0x30) + halrf_do_imr_test(dm, (u8)dm_value[1]); +} +#endif + +void halrf_iqk_hwtx_check(void *dm_void, boolean is_check) +{ +#if 0 + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + u32 tmp_b04; + + if (is_check) { + iqk_info->is_hwtx = (boolean)odm_get_bb_reg(dm, R_0xb00, BIT(8)); + } else { + if (iqk_info->is_hwtx) { + tmp_b04 = odm_read_4byte(dm, 0xb04); + odm_set_bb_reg(dm, R_0xb04, BIT(3) | BIT(2), 0x0); + odm_write_4byte(dm, 0xb04, tmp_b04); + } + } +#endif +} +#endif + +u8 halrf_match_iqk_version(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + u32 iqk_version = 0; + char temp[10] = {0}; + + odm_move_memory(dm, temp, HALRF_IQK_VER, sizeof(temp)); + PHYDM_SSCANF(temp + 2, DCMD_HEX, &iqk_version); + + if (dm->support_ic_type == ODM_RTL8822B) { + if (iqk_version >= 0x24 && (odm_get_hw_img_version(dm) >= 72)) + return 1; + else if ((iqk_version <= 0x23) && + (odm_get_hw_img_version(dm) <= 71)) + return 1; + else + return 0; + } + + if (dm->support_ic_type == ODM_RTL8821C) { + if (iqk_version >= 0x18 && (odm_get_hw_img_version(dm) >= 37)) + return 1; + else + return 0; + } + + return 1; +} + +void halrf_rf_lna_setting(void *dm_void, enum halrf_lna_set type) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + switch (dm->support_ic_type) { +#if (RTL8188E_SUPPORT == 1) + case ODM_RTL8188E: + halrf_rf_lna_setting_8188e(dm, type); + break; +#endif +#if (RTL8192E_SUPPORT == 1) + case ODM_RTL8192E: + halrf_rf_lna_setting_8192e(dm, type); + break; +#endif +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + halrf_rf_lna_setting_8192f(dm, type); + break; +#endif + +#if (RTL8723B_SUPPORT == 1) + case ODM_RTL8723B: + halrf_rf_lna_setting_8723b(dm, type); + break; +#endif +#if (RTL8812A_SUPPORT == 1) + case ODM_RTL8812: + halrf_rf_lna_setting_8812a(dm, type); + break; +#endif +#if ((RTL8821A_SUPPORT == 1) || (RTL8881A_SUPPORT == 1)) + case ODM_RTL8881A: + case ODM_RTL8821: + halrf_rf_lna_setting_8821a(dm, type); + break; +#endif +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + halrf_rf_lna_setting_8822b(dm_void, type); + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + halrf_rf_lna_setting_8822c(dm_void, type); + break; +#endif +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + halrf_rf_lna_setting_8812f(dm_void, type); + break; +#endif +#if (RTL8821C_SUPPORT == 1) + case ODM_RTL8821C: + halrf_rf_lna_setting_8821c(dm_void, type); + break; +#endif +#if (RTL8710C_SUPPORT == 1) + case ODM_RTL8710C: + halrf_rf_lna_setting_8710c(dm_void, type); + break; +#endif +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + halrf_rf_lna_setting_8721d(dm, type); + break; +#endif +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + break; +#endif + default: + break; + } +} + +void halrf_support_ability_debug(void *dm_void, char input[][16], u32 *_used, + char *output, u32 *_out_len) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + u32 dm_value[10] = {0}; + u32 used = *_used; + u32 out_len = *_out_len; + u8 i; + + for (i = 0; i < 5; i++) + if (input[i + 1]) + PHYDM_SSCANF(input[i + 2], DCMD_DECIMAL, &dm_value[i]); + + if (dm_value[0] == 100) { + PDM_SNPF(out_len, used, output + used, out_len - used, + "\n[RF Supportability]\n"); + PDM_SNPF(out_len, used, output + used, out_len - used, + "00. (( %s ))Power Tracking\n", + ((rf->rf_supportability & HAL_RF_TX_PWR_TRACK) ? + ("V") : ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "01. (( %s ))IQK\n", + ((rf->rf_supportability & HAL_RF_IQK) ? ("V") : + ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "02. (( %s ))LCK\n", + ((rf->rf_supportability & HAL_RF_LCK) ? ("V") : + ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "03. (( %s ))DPK\n", + ((rf->rf_supportability & HAL_RF_DPK) ? ("V") : + ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "04. (( %s ))HAL_RF_TXGAPK\n", + ((rf->rf_supportability & HAL_RF_TXGAPK) ? ("V") : + ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "05. (( %s ))HAL_RF_DACK\n", + ((rf->rf_supportability & HAL_RF_DACK) ? ("V") : + ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "06. (( %s ))DPK_TRACK\n", + ((rf->rf_supportability & HAL_RF_DPK_TRACK) ? ("V") : + ("."))); +#ifdef CONFIG_2G_BAND_SHIFT + PDM_SNPF(out_len, used, output + used, out_len - used, + "07. (( %s ))HAL_2GBAND_SHIFT\n", + ((rf->rf_supportability & HAL_2GBAND_SHIFT) ? ("V") : + ("."))); +#endif + PDM_SNPF(out_len, used, output + used, out_len - used, + "08. (( %s ))HAL_RF_RXDCK\n", + ((rf->rf_supportability & HAL_RF_RXDCK) ? ("V") : + ("."))); + + } else { + if (dm_value[1] == 1) /* enable */ + rf->rf_supportability |= BIT(dm_value[0]); + else if (dm_value[1] == 2) /* disable */ + rf->rf_supportability &= ~(BIT(dm_value[0])); + else + PDM_SNPF(out_len, used, output + used, out_len - used, + "[Warning!!!] 1:enable, 2:disable\n"); + } + PDM_SNPF(out_len, used, output + used, out_len - used, + "\nCurr-RF_supportability = 0x%x\n\n", rf->rf_supportability); + + *_used = used; + *_out_len = out_len; +} + +#ifdef CONFIG_2G_BAND_SHIFT +void halrf_support_band_shift_debug(void *dm_void, char input[][16], u32 *_used, + char *output, u32 *_out_len) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + //u32 band_value[2] = {00}; + u32 dm_value[10] = {0}; + u32 used = *_used; + u32 out_len = *_out_len; + u8 i; + +#if (RTL8192F_SUPPORT == 1) + for (i = 0; i < 7; i++) + if (input[i + 1]) + PHYDM_SSCANF(input[i + 2], DCMD_DECIMAL, &dm_value[i]); + + if (!(rf->rf_supportability & HAL_2GBAND_SHIFT)) { + PDM_SNPF(out_len, used, output + used, out_len - used, + "\nCurr-RF_supportability[07. (( . ))HAL_2GBAND_SHIFT]\nNo RF Band Shift,default: 2.4G!\n"); + } else { + if (dm_value[0] == 01) { + rf->rf_shift_band = HAL_RF_2P3; + halrf_lck_trigger(dm); + PDM_SNPF(out_len, used, output + used, out_len - used, + "\n[rf_shift_band] = %d\nRF Band Shift to 2.3G!\n", + rf->rf_shift_band); + } else if (dm_value[0] == 02) { + rf->rf_shift_band = HAL_RF_2P5; + halrf_lck_trigger(dm); + PDM_SNPF(out_len, used, output + used, out_len - used, + "\n[rf_shift_band] = %d\nRF Band Shift to 2.5G!\n", + rf->rf_shift_band); + } else { + rf->rf_shift_band = HAL_RF_2P4; + halrf_lck_trigger(dm); + PDM_SNPF(out_len, used, output + used, out_len - used, + "\n[rf_shift_band] = %d\nNo RF Band Shift,default: 2.4G!\n", + rf->rf_shift_band); + } + } + *_used = used; + *_out_len = out_len; +#endif +} +#endif + +void halrf_cmn_info_init(void *dm_void, enum halrf_cmninfo_init cmn_info, + u32 value) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + switch (cmn_info) { + case HALRF_CMNINFO_EEPROM_THERMAL_VALUE: + rf->eeprom_thermal = (u8)value; + break; + case HALRF_CMNINFO_PWT_TYPE: + rf->pwt_type = (u8)value; + break; + case HALRF_CMNINFO_MP_POWER_TRACKING_TYPE: + rf->mp_pwt_type = (u8)value; + break; + default: + break; + } +} + +void halrf_cmn_info_hook(void *dm_void, enum halrf_cmninfo_hook cmn_info, + void *value) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + switch (cmn_info) { + case HALRF_CMNINFO_CON_TX: + rf->is_con_tx = (boolean *)value; + break; + case HALRF_CMNINFO_SINGLE_TONE: + rf->is_single_tone = (boolean *)value; + break; + case HALRF_CMNINFO_CARRIER_SUPPRESSION: + rf->is_carrier_suppresion = (boolean *)value; + break; + case HALRF_CMNINFO_MP_RATE_INDEX: + rf->mp_rate_index = (u8 *)value; + break; + case HALRF_CMNINFO_MANUAL_RF_SUPPORTABILITY: + rf->manual_rf_supportability = (u32 *)value; + break; + default: + /*do nothing*/ + break; + } +} + +void halrf_cmn_info_set(void *dm_void, u32 cmn_info, u64 value) +{ + /* This init variable may be changed in run time. */ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + struct _hal_rf_ *rf = &dm->rf_table; + + switch (cmn_info) { + case HALRF_CMNINFO_ABILITY: + rf->rf_supportability = (u32)value; + break; + + case HALRF_CMNINFO_DPK_EN: + rf->dpk_en = (u8)value; + break; + case HALRF_CMNINFO_RFK_FORBIDDEN: + dm->IQK_info.rfk_forbidden = (boolean)value; + break; +#if (RTL8814A_SUPPORT == 1 || RTL8822B_SUPPORT == 1 || \ + RTL8821C_SUPPORT == 1 || RTL8195B_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1 || RTL8822C_SUPPORT == 1) + case HALRF_CMNINFO_IQK_SEGMENT: + dm->IQK_info.segment_iqk = (boolean)value; + break; +#endif + case HALRF_CMNINFO_RATE_INDEX: + rf->p_rate_index = (u32)value; + break; +#if !(DM_ODM_SUPPORT_TYPE & ODM_IOT) + case HALRF_CMNINFO_MP_PSD_POINT: + rf->halrf_psd_data.point = (u32)value; + break; + case HALRF_CMNINFO_MP_PSD_START_POINT: + rf->halrf_psd_data.start_point = (u32)value; + break; + case HALRF_CMNINFO_MP_PSD_STOP_POINT: + rf->halrf_psd_data.stop_point = (u32)value; + break; + case HALRF_CMNINFO_MP_PSD_AVERAGE: + rf->halrf_psd_data.average = (u32)value; + break; +#endif + case HALRF_CMNINFO_POWER_TRACK_CONTROL: + cali_info->txpowertrack_control = (u8)value; + break; + default: + /* do nothing */ + break; + } +} + +u64 halrf_cmn_info_get(void *dm_void, u32 cmn_info) +{ + /* This init variable may be changed in run time. */ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + u64 return_value = 0; + + switch (cmn_info) { + case HALRF_CMNINFO_ABILITY: + return_value = (u32)rf->rf_supportability; + break; + case HALRF_CMNINFO_RFK_FORBIDDEN: + return_value = dm->IQK_info.rfk_forbidden; + break; +#if (RTL8814A_SUPPORT == 1 || RTL8822B_SUPPORT == 1 || \ + RTL8821C_SUPPORT == 1 || RTL8195B_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1 || RTL8822C_SUPPORT == 1) + case HALRF_CMNINFO_IQK_SEGMENT: + return_value = dm->IQK_info.segment_iqk; + break; + case HALRF_CMNINFO_IQK_TIMES: + return_value = dm->IQK_info.iqk_times; + break; +#endif + default: + /* do nothing */ + break; + } + + return return_value; +} + +void halrf_supportability_init_mp(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + switch (dm->support_ic_type) { + case ODM_RTL8814B: +#if (RTL8814B_SUPPORT == 1) + rf->rf_supportability = + /*HAL_RF_TX_PWR_TRACK |*/ + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + HAL_RF_DACK | + /*HAL_RF_TXGAPK |*/ + HAL_RF_DPK_TRACK | + 0; +#endif + break; +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + rf->rf_supportability = + /*HAL_RF_TX_PWR_TRACK |*/ + HAL_RF_IQK | + HAL_RF_LCK | + /*@HAL_RF_DPK |*/ + 0; + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + rf->rf_supportability = + /*HAL_RF_TX_PWR_TRACK |*/ + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + HAL_RF_DACK | + HAL_RF_DPK_TRACK | + HAL_RF_RXDCK | + HAL_RF_TXGAPK | + 0; + break; +#endif +#if (RTL8821C_SUPPORT == 1) + case ODM_RTL8821C: + rf->rf_supportability = + /*HAL_RF_TX_PWR_TRACK |*/ + HAL_RF_IQK | + HAL_RF_LCK | + /*@HAL_RF_DPK |*/ + /*@HAL_RF_TXGAPK |*/ + 0; + break; +#endif +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + rf->rf_supportability = + /*HAL_RF_TX_PWR_TRACK |*/ + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + /*HAL_RF_TXGAPK |*/ + HAL_RF_DPK_TRACK | + 0; + break; +#endif +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + rf->rf_supportability = + /*HAL_RF_TX_PWR_TRACK |*/ + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + HAL_RF_DACK | + HAL_RF_DPK_TRACK | + 0; + break; +#endif + +#if (RTL8198F_SUPPORT == 1) + case ODM_RTL8198F: + rf->rf_supportability = + /*HAL_RF_TX_PWR_TRACK |*/ + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + /*@HAL_RF_TXGAPK |*/ + 0; + break; +#endif + +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + rf->rf_supportability = + /*HAL_RF_TX_PWR_TRACK |*/ + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + /*@HAL_RF_TXGAPK |*/ +#ifdef CONFIG_2G_BAND_SHIFT + /*@HAL_2GBAND_SHIFT |*/ +#endif + 0; + break; +#endif + +#if (RTL8197F_SUPPORT == 1) + case ODM_RTL8197F: + rf->rf_supportability = + /*HAL_RF_TX_PWR_TRACK |*/ + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + /*@HAL_RF_TXGAPK |*/ + 0; + break; +#endif +#if (RTL8197G_SUPPORT == 1) + case ODM_RTL8197G: + rf->rf_supportability = + /*HAL_RF_TX_PWR_TRACK |*/ + HAL_RF_IQK | + /*HAL_RF_LCK |*/ + HAL_RF_DPK | + /*@HAL_RF_TXGAPK |*/ + HAL_RF_DPK_TRACK | + 0; + break; +#endif +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + HAL_RF_DPK_TRACK | + /*@HAL_RF_TXGAPK |*/ + 0; + break; +#endif +#if (RTL8723F_SUPPORT == 1) + case ODM_RTL8723F: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + HAL_RF_TXGAPK | + HAL_RF_DPK_TRACK | + 0; + break; +#endif + + default: + rf->rf_supportability = + /*HAL_RF_TX_PWR_TRACK |*/ + HAL_RF_IQK | + HAL_RF_LCK | + /*@HAL_RF_DPK |*/ + /*@HAL_RF_TXGAPK |*/ + 0; + break; + } + + RF_DBG(dm, DBG_RF_INIT, + "IC = ((0x%x)), RF_Supportability Init MP = ((0x%x))\n", + dm->support_ic_type, rf->rf_supportability); +} + +void halrf_supportability_init(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + switch (dm->support_ic_type) { + case ODM_RTL8814B: +#if (RTL8814B_SUPPORT == 1) + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + HAL_RF_DACK | + HAL_RF_DPK_TRACK | + 0; +#endif + break; +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + /*@HAL_RF_DPK |*/ + 0; + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + HAL_RF_DACK | + HAL_RF_DPK_TRACK | + HAL_RF_RXDCK | + HAL_RF_TXGAPK | + 0; + break; +#endif +#if (RTL8821C_SUPPORT == 1) + case ODM_RTL8821C: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + /*@HAL_RF_DPK |*/ + /*@HAL_RF_TXGAPK |*/ + 0; + break; +#endif +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + /*HAL_RF_TXGAPK |*/ + HAL_RF_DPK_TRACK | + 0; + break; +#endif +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + HAL_RF_DACK | + HAL_RF_DPK_TRACK | + 0; + break; +#endif + +#if (RTL8198F_SUPPORT == 1) + case ODM_RTL8198F: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + /*@HAL_RF_TXGAPK |*/ + 0; + break; +#endif + +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + /*@HAL_RF_TXGAPK |*/ +#ifdef CONFIG_2G_BAND_SHIFT + /*@HAL_2GBAND_SHIFT |*/ +#endif + 0; + break; +#endif + +#if (RTL8197F_SUPPORT == 1) + case ODM_RTL8197F: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + /*@HAL_RF_TXGAPK |*/ + 0; + break; +#endif +#if (RTL8197G_SUPPORT == 1) + case ODM_RTL8197G: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + /*HAL_RF_LCK |*/ + HAL_RF_DPK | + /*@HAL_RF_TXGAPK |*/ + HAL_RF_DPK_TRACK | +#ifdef CONFIG_2G_BAND_SHIFT + HAL_2GBAND_SHIFT | +#endif + 0; + break; +#endif +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + HAL_RF_DPK_TRACK | + /*@HAL_RF_TXGAPK |*/ + 0; + break; +#endif +#if (RTL8723F_SUPPORT == 1) + case ODM_RTL8723F: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + HAL_RF_DPK | + HAL_RF_TXGAPK | + HAL_RF_DPK_TRACK | + 0; + break; +#endif + + default: + rf->rf_supportability = + HAL_RF_TX_PWR_TRACK | + HAL_RF_IQK | + HAL_RF_LCK | + /*@HAL_RF_DPK |*/ + 0; + break; + } + + RF_DBG(dm, DBG_RF_INIT, + "IC = ((0x%x)), RF_Supportability Init = ((0x%x))\n", + dm->support_ic_type, rf->rf_supportability); +} + +void halrf_watchdog(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; +#if 0 + /*RF_DBG(dm, DBG_RF_TMP, "%s\n", __func__);*/ +#endif + + if (rf->is_dpk_in_progress || dm->rf_calibrate_info.is_iqk_in_progress || + rf->is_tssi_in_progress) + return; +#if !(RTL8723F_SUPPORT == 1) + phydm_rf_watchdog(dm); +#endif + halrf_dpk_track(dm); +#if (RTL8723F_SUPPORT == 1) + halrf_xtal_thermal_track(dm); +#endif + +} + +#if 0 +void +halrf_iqk_init( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + switch (dm->support_ic_type) { +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + break; +#endif +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + _iq_calibrate_8822b_init(dm); + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + _iq_calibrate_8822c_init(dm); + break; +#endif +#if (RTL8821C_SUPPORT == 1) + case ODM_RTL8821C: + break; +#endif + + default: + break; + } +} +#endif + +void halrf_rfk_power_save(void *dm_void, boolean is_power_save) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + halrf_rfk_power_save_8822c(dm, is_power_save); + break; +#endif + +#if (RTL8723F_SUPPORT == 1) + case ODM_RTL8723F: + halrf_rfk_power_save_8723f(dm, is_power_save); + break; +#endif + + default: + break; + } +} + + + +void halrf_reload_iqk(void *dm_void, boolean reset) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + u8 i, ch; + u32 tmp; + u32 bit_mask_20_16 = BIT(20) | BIT(19) | BIT(18) | BIT(17) | BIT(16); + + halrf_rfk_power_save(dm, false); + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + iqk_reload_iqk_8822c(dm, reset); + break; +#endif +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + iqk_reload_iqk_8195b(dm, reset); + break; +#endif + + default: + break; + } + halrf_rfk_power_save(dm, true); +} + +void halrf_rfk_handshake(void *dm_void, boolean is_before_k) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + if (!dm->mp_mode) + return; + + if (*dm->mp_mode) + return; + + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + halrf_rfk_handshake_8822c(dm, is_before_k); + break; +#endif +#if (RTL8710C_SUPPORT == 1) + case ODM_RTL8710C: + halrf_rfk_handshake_8710c(dm, is_before_k); + break; +#endif +#if (RTL8723F_SUPPORT == 1) + case ODM_RTL8723F: + halrf_rfk_handshake_8723f(dm, is_before_k); + break; +#endif + default: + break; + } +} + +void halrf_bbreset(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + + switch (dm->support_ic_type) { +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + phydm_bb_reset_8814b(dm); + break; +#endif + default: + break; + } +} + +void halrf_rf_k_connect_trigger(void *dm_void, boolean is_recovery, + enum halrf_k_segment_time seg_time) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + struct _hal_rf_ *rf = &dm->rf_table; + + if (!dm->mp_mode) + return; + + if (dm->mp_mode && rf->is_con_tx && rf->is_single_tone && + rf->is_carrier_suppresion) { + if (*dm->mp_mode & + (*rf->is_con_tx || *rf->is_single_tone || + *rf->is_carrier_suppresion)) + return; + } + + /*[TX GAP K]*/ + halrf_txgapk_trigger(dm); + + /*[LOK, IQK]*/ + halrf_segment_iqk_trigger(dm, true, seg_time); + + /*[TSSI Trk]*/ + halrf_tssi_trigger(dm); + /*[DPK]*/ +#if 1 + if(dpk_info->is_dpk_by_channel == true) + halrf_dpk_trigger(dm); + else + halrf_dpk_reload(dm); +#endif + //ADDA restore to MP_UI setting; + config_halrf_path_adda_setting_trigger(dm); + +#if (RTL8723F_SUPPORT == 1) + halrf_spur_compensation_8723f(dm); +#endif + halrf_bbreset(dm); +} + +void config_halrf_path_adda_setting_trigger(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) + config_phydm_path_adda_setting_8814b(dm); +#endif + +} + +void halrf_dack_restore(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + if (!(rf->rf_supportability & HAL_RF_DACK)) + return; + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + halrf_dack_restore_8822c(dm); + break; +#endif + default: + break; + } +} +void halrf_dack_trigger(void *dm_void, boolean force) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + u64 start_time; + + if (!(rf->rf_supportability & HAL_RF_DACK)) + return; + + start_time = odm_get_current_time(dm); + + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + halrf_dac_cal_8822c(dm, force); + break; +#endif +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + halrf_dac_cal_8812f(dm); + break; +#endif +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + halrf_dac_cal_8814b(dm); + break; +#endif + default: + break; + } + rf->dpk_progressing_time = odm_get_progressing_time(dm, start_time); + RF_DBG(dm, DBG_RF_DACK, "[DACK]DACK progressing_time = %lld ms\n", + rf->dpk_progressing_time); +} + + +void halrf_dack_dbg(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + u64 start_time; + + if (!(rf->rf_supportability & HAL_RF_DACK)) + return; + + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + halrf_dack_dbg_8822c(dm); + break; +#endif + default: + break; + } +} + + +void halrf_segment_iqk_trigger(void *dm_void, boolean clear, + boolean segment_iqk) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + struct _hal_rf_ *rf = &dm->rf_table; + u64 start_time; + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN)) + if (odm_check_power_status(dm) == false) + return; +#endif + + if (!dm->mp_mode) + return; + + if (dm->mp_mode && rf->is_con_tx && rf->is_single_tone && + rf->is_carrier_suppresion) { + if (*dm->mp_mode & + (*rf->is_con_tx || *rf->is_single_tone || + *rf->is_carrier_suppresion)) + return; + } + + if (!(rf->rf_supportability & HAL_RF_IQK)) + return; + +#if DISABLE_BB_RF + return; +#endif + if (iqk_info->rfk_forbidden) + return; + + rf->rfk_type = RF01_IQK; + halrf_rfk_handshake(dm, true); + + if (!dm->rf_calibrate_info.is_iqk_in_progress) { + odm_acquire_spin_lock(dm, RT_IQK_SPINLOCK); + dm->rf_calibrate_info.is_iqk_in_progress = true; + odm_release_spin_lock(dm, RT_IQK_SPINLOCK); + start_time = odm_get_current_time(dm); + dm->IQK_info.segment_iqk = segment_iqk; + + halrf_rfk_power_save(dm, false); + switch (dm->support_ic_type) { +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + phy_iq_calibrate_8822b(dm, clear, segment_iqk); + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + phy_iq_calibrate_8822c(dm, clear, segment_iqk); + break; +#endif +#if (RTL8821C_SUPPORT == 1) + case ODM_RTL8821C: + phy_iq_calibrate_8821c(dm, clear, segment_iqk); + break; +#endif +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + phy_iq_calibrate_8814b(dm, clear, segment_iqk); + break; +#endif +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + phy_iq_calibrate_8195b(dm, clear, segment_iqk); + break; +#endif +#if (RTL8710C_SUPPORT == 1) + case ODM_RTL8710C: + phy_iq_calibrate_8710c(dm, clear, segment_iqk); + break; +#endif +#if (RTL8198F_SUPPORT == 1) + case ODM_RTL8198F: + phy_iq_calibrate_8198f(dm, clear, segment_iqk); + break; +#endif +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + phy_iq_calibrate_8812f(dm, clear, segment_iqk); + break; +#endif +#if (RTL8197G_SUPPORT == 1) + case ODM_RTL8197G: + phy_iq_calibrate_8197g(dm, clear, segment_iqk); + break; +#endif +#if (RTL8188E_SUPPORT == 1) + case ODM_RTL8188E: + phy_iq_calibrate_8188e(dm, false); + break; +#endif +#if (RTL8188F_SUPPORT == 1) + case ODM_RTL8188F: + phy_iq_calibrate_8188f(dm, false); + break; +#endif +#if (RTL8192E_SUPPORT == 1) + case ODM_RTL8192E: + phy_iq_calibrate_8192e(dm, false); + break; +#endif +#if (RTL8197F_SUPPORT == 1) + case ODM_RTL8197F: + phy_iq_calibrate_8197f(dm, false); + break; +#endif +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + phy_iq_calibrate_8192f(dm, false); + break; +#endif +#if (RTL8703B_SUPPORT == 1) + case ODM_RTL8703B: + phy_iq_calibrate_8703b(dm, false); + break; +#endif +#if (RTL8710B_SUPPORT == 1) + case ODM_RTL8710B: + phy_iq_calibrate_8710b(dm, false); + break; +#endif +#if (RTL8723B_SUPPORT == 1) + case ODM_RTL8723B: + phy_iq_calibrate_8723b(dm, false); + break; +#endif +#if (RTL8723D_SUPPORT == 1) + case ODM_RTL8723D: + phy_iq_calibrate_8723d(dm, false); + break; +#endif +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + phy_iq_calibrate_8721d(dm, false); + break; +#endif +#if (RTL8812A_SUPPORT == 1) + case ODM_RTL8812: + phy_iq_calibrate_8812a(dm, false); + break; +#endif +#if (RTL8821A_SUPPORT == 1) + case ODM_RTL8821: + phy_iq_calibrate_8821a(dm, false); + break; +#endif +#if (RTL8814A_SUPPORT == 1) + case ODM_RTL8814A: + phy_iq_calibrate_8814a(dm, false); + break; +#endif +#if (RTL8723F_SUPPORT == 1) + case ODM_RTL8723F: + phy_iq_calibrate_8723f(dm, false); + break; +#endif + + default: + break; + } + + halrf_rfk_power_save(dm, true); + dm->rf_calibrate_info.iqk_progressing_time = + odm_get_progressing_time(dm, start_time); + RF_DBG(dm, DBG_RF_IQK, "[IQK]IQK progressing_time = %lld ms\n", + dm->rf_calibrate_info.iqk_progressing_time); + + odm_acquire_spin_lock(dm, RT_IQK_SPINLOCK); + dm->rf_calibrate_info.is_iqk_in_progress = false; + odm_release_spin_lock(dm, RT_IQK_SPINLOCK); + + halrf_rfk_handshake(dm, false); + } else { + RF_DBG(dm, DBG_RF_IQK, + "== Return the IQK CMD, because RFKs in Progress ==\n"); + } +} + + +void halrf_iqk_trigger(void *dm_void, boolean is_recovery) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + struct _hal_rf_ *rf = &dm->rf_table; + u64 start_time; + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN)) + if (odm_check_power_status(dm) == false) + return; +#endif + + if (!dm->mp_mode) + return; + + if (dm->mp_mode && rf->is_con_tx && rf->is_single_tone && + rf->is_carrier_suppresion) { + if (*dm->mp_mode & + (*rf->is_con_tx || *rf->is_single_tone || + *rf->is_carrier_suppresion)) + return; + } + + if (!(rf->rf_supportability & HAL_RF_IQK)) + return; + +#if DISABLE_BB_RF + return; +#endif + + if (iqk_info->rfk_forbidden) + return; + + rf->rfk_type = RF01_IQK; + halrf_rfk_handshake(dm, true); + + if (!dm->rf_calibrate_info.is_iqk_in_progress) { + odm_acquire_spin_lock(dm, RT_IQK_SPINLOCK); + dm->rf_calibrate_info.is_iqk_in_progress = true; + odm_release_spin_lock(dm, RT_IQK_SPINLOCK); + start_time = odm_get_current_time(dm); + halrf_rfk_power_save(dm, false); + switch (dm->support_ic_type) { +#if (RTL8188E_SUPPORT == 1) + case ODM_RTL8188E: + phy_iq_calibrate_8188e(dm, is_recovery); + break; +#endif +#if (RTL8188F_SUPPORT == 1) + case ODM_RTL8188F: + phy_iq_calibrate_8188f(dm, is_recovery); + break; +#endif +#if (RTL8192E_SUPPORT == 1) + case ODM_RTL8192E: + phy_iq_calibrate_8192e(dm, is_recovery); + break; +#endif +#if (RTL8197F_SUPPORT == 1) + case ODM_RTL8197F: + phy_iq_calibrate_8197f(dm, is_recovery); + break; +#endif +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + phy_iq_calibrate_8192f(dm, is_recovery); + break; +#endif +#if (RTL8703B_SUPPORT == 1) + case ODM_RTL8703B: + phy_iq_calibrate_8703b(dm, is_recovery); + break; +#endif +#if (RTL8710B_SUPPORT == 1) + case ODM_RTL8710B: + phy_iq_calibrate_8710b(dm, is_recovery); + break; +#endif +#if (RTL8723B_SUPPORT == 1) + case ODM_RTL8723B: + phy_iq_calibrate_8723b(dm, is_recovery); + break; +#endif +#if (RTL8723D_SUPPORT == 1) + case ODM_RTL8723D: + phy_iq_calibrate_8723d(dm, is_recovery); + break; +#endif +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + phy_iq_calibrate_8721d(dm, is_recovery); + break; +#endif +#if (RTL8812A_SUPPORT == 1) + case ODM_RTL8812: + phy_iq_calibrate_8812a(dm, is_recovery); + break; +#endif +#if (RTL8821A_SUPPORT == 1) + case ODM_RTL8821: + phy_iq_calibrate_8821a(dm, is_recovery); + break; +#endif +#if (RTL8814A_SUPPORT == 1) + case ODM_RTL8814A: + phy_iq_calibrate_8814a(dm, is_recovery); + break; +#endif +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + phy_iq_calibrate_8822b(dm, false, false); + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + phy_iq_calibrate_8822c(dm, false, false); + break; +#endif +#if (RTL8821C_SUPPORT == 1) + case ODM_RTL8821C: + phy_iq_calibrate_8821c(dm, false, false); + break; +#endif +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + phy_iq_calibrate_8814b(dm, false, false); + break; +#endif +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + phy_iq_calibrate_8195b(dm, false, false); + break; +#endif +#if (RTL8710C_SUPPORT == 1) + case ODM_RTL8710C: + phy_iq_calibrate_8710c(dm, false, false); + break; +#endif +#if (RTL8198F_SUPPORT == 1) + case ODM_RTL8198F: + phy_iq_calibrate_8198f(dm, false, false); + break; +#endif +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + phy_iq_calibrate_8812f(dm, false, false); + break; +#endif +#if (RTL8197G_SUPPORT == 1) + case ODM_RTL8197G: + phy_iq_calibrate_8197g(dm, false, false); + break; +#endif +#if (RTL8723F_SUPPORT == 1) + case ODM_RTL8723F: + phy_iq_calibrate_8723f(dm, is_recovery); + break; +#endif + + default: + break; + } + + halrf_rfk_power_save(dm, true); + rf->iqk_progressing_time = odm_get_progressing_time(dm, start_time); + RF_DBG(dm, DBG_RF_LCK, "[IQK]Trigger IQK progressing_time = %lld ms\n", + rf->iqk_progressing_time); + odm_acquire_spin_lock(dm, RT_IQK_SPINLOCK); + dm->rf_calibrate_info.is_iqk_in_progress = false; + odm_release_spin_lock(dm, RT_IQK_SPINLOCK); + + halrf_rfk_handshake(dm, false); + } else { + RF_DBG(dm, DBG_RF_IQK, + "== Return the IQK CMD, because RFKs in Progress ==\n"); + } +} + +void halrf_lck_trigger(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + struct _hal_rf_ *rf = &dm->rf_table; + u64 start_time; + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN)) + if (odm_check_power_status(dm) == false) + return; +#endif + + if (!dm->mp_mode) + return; + + if (dm->mp_mode && rf->is_con_tx && rf->is_single_tone && + rf->is_carrier_suppresion) { + if (*dm->mp_mode & + (*rf->is_con_tx || *rf->is_single_tone || + *rf->is_carrier_suppresion)) + return; + } + + if (!(rf->rf_supportability & HAL_RF_LCK)) + return; + +#if DISABLE_BB_RF + return; +#endif + if (iqk_info->rfk_forbidden) + return; + while (*dm->is_scan_in_process) { + RF_DBG(dm, DBG_RF_LCK, "[LCK]scan is in process, bypass LCK\n"); + return; + } + + if (!dm->rf_calibrate_info.is_lck_in_progress) { + odm_acquire_spin_lock(dm, RT_IQK_SPINLOCK); + dm->rf_calibrate_info.is_lck_in_progress = true; + odm_release_spin_lock(dm, RT_IQK_SPINLOCK); + start_time = odm_get_current_time(dm); + switch (dm->support_ic_type) { +#if (RTL8188E_SUPPORT == 1) + case ODM_RTL8188E: + phy_lc_calibrate_8188e(dm); + break; +#endif +#if (RTL8188F_SUPPORT == 1) + case ODM_RTL8188F: + phy_lc_calibrate_8188f(dm); + break; +#endif +#if (RTL8192E_SUPPORT == 1) + case ODM_RTL8192E: + phy_lc_calibrate_8192e(dm); + break; +#endif +#if (RTL8197F_SUPPORT == 1) + case ODM_RTL8197F: + phy_lc_calibrate_8197f(dm); + break; +#endif +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + phy_lc_calibrate_8192f(dm); + break; +#endif +#if (RTL8703B_SUPPORT == 1) + case ODM_RTL8703B: + phy_lc_calibrate_8703b(dm); + break; +#endif +#if (RTL8710B_SUPPORT == 1) + case ODM_RTL8710B: + phy_lc_calibrate_8710b(dm); + break; +#endif +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + phy_lc_calibrate_8721d(dm); + break; +#endif +#if (RTL8723B_SUPPORT == 1) + case ODM_RTL8723B: + phy_lc_calibrate_8723b(dm); + break; +#endif +#if (RTL8723D_SUPPORT == 1) + case ODM_RTL8723D: + phy_lc_calibrate_8723d(dm); + break; +#endif +#if (RTL8812A_SUPPORT == 1) + case ODM_RTL8812: + phy_lc_calibrate_8812a(dm); + break; +#endif +#if (RTL8821A_SUPPORT == 1) + case ODM_RTL8821: + phy_lc_calibrate_8821a(dm); + break; +#endif +#if (RTL8814A_SUPPORT == 1) + case ODM_RTL8814A: + phy_lc_calibrate_8814a(dm); + break; +#endif +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: + phy_lc_calibrate_8822b(dm); + break; +#endif +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + phy_lc_calibrate_8822c(dm); + break; +#endif +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + phy_lc_calibrate_8812f(dm); + break; +#endif +#if (RTL8821C_SUPPORT == 1) + case ODM_RTL8821C: + phy_lc_calibrate_8821c(dm); + break; +#endif +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + phy_lc_calibrate_8814b(dm); + break; +#endif +#if (RTL8197G_SUPPORT == 1) + case ODM_RTL8197G: + phy_lc_calibrate_8197g(dm); + break; +#endif +#if (RTL8198F_SUPPORT == 1) + case ODM_RTL8198F: + phy_lc_calibrate_8198f(dm); + break; +#endif +#if (RTL8710C_SUPPORT == 1) + case ODM_RTL8710C: + phy_lc_calibrate_8710c(dm); + break; +#endif +#if (RTL8723F_SUPPORT == 1) + case ODM_RTL8723F: + phy_lc_calibrate_8723f(dm); + break; +#endif + + default: + break; + } + dm->rf_calibrate_info.lck_progressing_time = + odm_get_progressing_time(dm, start_time); + RF_DBG(dm, DBG_RF_LCK, "[LCK]LCK progressing_time = %lld ms\n", + dm->rf_calibrate_info.lck_progressing_time); +#if (RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1) + halrf_lck_dbg(dm); +#endif + odm_acquire_spin_lock(dm, RT_IQK_SPINLOCK); + dm->rf_calibrate_info.is_lck_in_progress = false; + odm_release_spin_lock(dm, RT_IQK_SPINLOCK); + } else { + RF_DBG(dm, DBG_RF_LCK, + "[LCK]= Return the LCK CMD, because RFK is in Progress =\n"); + } +} + +void halrf_aac_check(struct dm_struct *dm) +{ + switch (dm->support_ic_type) { +#if (RTL8821C_SUPPORT == 1) + case ODM_RTL8821C: +#if 0 + aac_check_8821c(dm); +#endif + break; +#endif +#if (RTL8822B_SUPPORT == 1) + case ODM_RTL8822B: +#if 1 + aac_check_8822b(dm); +#endif + break; +#endif + default: + break; + } +} + +void halrf_rxdck(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + if (!(rf->rf_supportability & HAL_RF_RXDCK)) + return; + + switch (dm->support_ic_type) { + case ODM_RTL8822C: +#if (RTL8822C_SUPPORT == 1) + halrf_rxdck_8822c(dm); + break; +#endif + default: + break; + } +} + +void halrf_x2k_check(struct dm_struct *dm) +{ + + switch (dm->support_ic_type) { + case ODM_RTL8821C: +#if (RTL8821C_SUPPORT == 1) +#endif + break; + case ODM_RTL8822C: +#if (RTL8822C_SUPPORT == 1) + phy_x2_check_8822c(dm); + break; +#endif + case ODM_RTL8812F: +#if (RTL8812F_SUPPORT == 1) + phy_x2_check_8812f(dm); + break; +#endif + case ODM_RTL8723F: +#if (RTL8723F_SUPPORT == 1) + phy_x2_check_8723f(dm); + break; +#endif + + default: + break; + } +} + +void halrf_set_rfsupportability(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + if (!dm->mp_mode) + return; + + if (rf->manual_rf_supportability && + *rf->manual_rf_supportability != 0xffffffff) { + rf->rf_supportability = *rf->manual_rf_supportability; + } else if (*dm->mp_mode) { + halrf_supportability_init_mp(dm); + } else { + halrf_supportability_init(dm); + } +} + +void halrf_rfe_definition(struct dm_struct *dm) +{ + struct _hal_rf_ *rf = &dm->rf_table; + + switch (dm->support_ic_type) { + case ODM_RTL8822C: +#if (RTL8822C_SUPPORT == 1) + if (dm->rfe_type == 21 || dm->rfe_type == 22) { + rf->ext_pa_5g = 1; + rf->ext_lna_5g = 1; + } + break; +#endif + default: + break; + } +} + +void halrf_init(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + RF_DBG(dm, DBG_RF_INIT, "HALRF_Init\n"); + rf->aac_checked = false; + halrf_init_debug_setting(dm); + halrf_set_rfsupportability(dm); + halrf_rfe_definition(dm); +#if 1 + /*Init all RF funciton*/ + halrf_aac_check(dm); + halrf_dack_trigger(dm, false); + halrf_x2k_check(dm); +#endif + + /*power trim, thrmal trim, pa bias*/ + phydm_config_new_kfree(dm); + + /*TSSI Init*/ + halrf_tssi_dck(dm, true); + halrf_tssi_get_efuse(dm); + halrf_tssi_set_de(dm); +#if (RTL8723F_SUPPORT == 1) + halrf_do_tssi(dm); + halrf_rx_port_ctl_8723f(dm); +#endif + + /*TX Gap K*/ + halrf_txgapk_write_gain_table(dm); +} + +void halrf_dpk_trigger(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + u64 start_time; + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN)) + if (odm_check_power_status(dm) == false) + return; +#endif + + if (!dm->mp_mode) + return; + + if (dm->mp_mode && rf->is_con_tx && rf->is_single_tone && + rf->is_carrier_suppresion) { + if (*dm->mp_mode & + (*rf->is_con_tx || *rf->is_single_tone || + *rf->is_carrier_suppresion)) + return; + } + + if (!(rf->rf_supportability & HAL_RF_DPK)) + return; + +#if DISABLE_BB_RF + return; +#endif + + if (iqk_info->rfk_forbidden) + return; + + rf->rfk_type = RF03_DPK; + halrf_rfk_handshake(dm, true); + + if (!rf->is_dpk_in_progress) { + odm_acquire_spin_lock(dm, RT_IQK_SPINLOCK); + rf->is_dpk_in_progress = true; + odm_release_spin_lock(dm, RT_IQK_SPINLOCK); + start_time = odm_get_current_time(dm); + halrf_rfk_power_save(dm, false); + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + do_dpk_8822c(dm); + break; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) +#if (RTL8197F_SUPPORT == 1) + case ODM_RTL8197F: + do_dpk_8197f(dm); + break; +#endif +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + do_dpk_8192f(dm); + break; +#endif + +#if (RTL8198F_SUPPORT == 1) + case ODM_RTL8198F: + do_dpk_8198f(dm); + break; +#endif +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + do_dpk_8812f(dm); + break; +#endif +#if (RTL8197G_SUPPORT == 1) + case ODM_RTL8197G: + do_dpk_8197g(dm); + break; +#endif + +#endif + +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + do_dpk_8814b(dm); + break; +#endif +#if (RTL8723F_SUPPORT == 1) + case ODM_RTL8723F: + do_dpk_8723f(dm); + break; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_IOT)) +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + do_dpk_8195b(dm); + break; +#endif +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + do_dpk_8721d(dm); + break; +#endif +#endif + default: + break; + } + halrf_rfk_power_save(dm, true); + rf->dpk_progressing_time = odm_get_progressing_time(dm, start_time); + RF_DBG(dm, DBG_RF_DPK, "[DPK]DPK progressing_time = %lld ms\n", + rf->dpk_progressing_time); + + odm_acquire_spin_lock(dm, RT_IQK_SPINLOCK); + rf->is_dpk_in_progress = false; + odm_release_spin_lock(dm, RT_IQK_SPINLOCK); + + halrf_rfk_handshake(dm, false); + } else { + RF_DBG(dm, DBG_RF_DPK, + "== Return the DPK CMD, because RFKs in Progress ==\n"); + } +} + +void halrf_set_dpkbychannel(void *dm_void, boolean dpk_by_ch) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + + switch (dm->support_ic_type) { +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + dpk_set_dpkbychannel_8814b(dm, dpk_by_ch); + break; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_IOT)) +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + dpk_set_dpkbychannel_8195b(dm,dpk_by_ch); + break; +#endif +#endif + default: + if (dpk_by_ch) + dpk_info->is_dpk_by_channel = 1; + else + dpk_info->is_dpk_by_channel = 0; + break; + } + +} + +void halrf_set_dpkenable(void *dm_void, boolean is_dpk_enable) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + + + switch (dm->support_ic_type) { +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + dpk_set_is_dpk_enable_8814b(dm, is_dpk_enable); + break; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_IOT)) +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + dpk_set_is_dpk_enable_8195b(dm, is_dpk_enable); + break; +#endif + +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + dpk_set_is_dpk_enable_8721d(dm, is_dpk_enable); + break; +#endif + +#endif + default: + break; + } + +} +boolean halrf_get_dpkbychannel(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + boolean is_dpk_by_channel = true; + + switch (dm->support_ic_type) { +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + is_dpk_by_channel = dpk_get_dpkbychannel_8814b(dm); + break; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_IOT)) +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + is_dpk_by_channel = dpk_get_dpkbychannel_8195b(dm); + break; +#endif +#endif + + default: + break; + } + return is_dpk_by_channel; + +} + + +boolean halrf_get_dpkenable(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + struct dm_iqk_info *iqk_info = &dm->IQK_info; + boolean is_dpk_enable = true; + + + switch (dm->support_ic_type) { +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + is_dpk_enable = dpk_get_is_dpk_enable_8814b(dm); + break; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_IOT)) +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + is_dpk_enable = dpk_get_is_dpk_enable_8195b(dm); + break; +#endif +#endif + default: + break; + } + return is_dpk_enable; + +} + +u8 halrf_dpk_result_check(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + + u8 result = 0; + + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + if (dpk_info->dpk_path_ok == 0x3) + result = 1; + else + result = 0; + break; +#endif + +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + if (dpk_info->dpk_path_ok == 0x1) + result = 1; + else + result = 0; + break; +#endif + +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + if (dpk_info->dpk_path_ok == 0x1) + result = 1; + else + result = 0; + break; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + +#if (RTL8197F_SUPPORT == 1) + case ODM_RTL8197F: + if (dpk_info->dpk_path_ok == 0x3) + result = 1; + else + result = 0; + break; +#endif + +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + if (dpk_info->dpk_path_ok == 0x3) + result = 1; + else + result = 0; + break; +#endif + +#if (RTL8198F_SUPPORT == 1) + case ODM_RTL8198F: + if (dpk_info->dpk_path_ok == 0xf) + result = 1; + else + result = 0; + break; +#endif + +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + if (dpk_info->dpk_path_ok == 0xf) + result = 1; + else + result = 0; + break; +#endif + +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + if (dpk_info->dpk_path_ok == 0x3) + result = 1; + else + result = 0; + break; +#endif + +#if (RTL8197G_SUPPORT == 1) + case ODM_RTL8197G: + if (dpk_info->dpk_path_ok == 0x3) + result = 1; + else + result = 0; + break; +#endif + +#endif + default: + break; + } + return result; +} + +void halrf_dpk_sram_read(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + u8 path, group; + + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + dpk_coef_read_8822c(dm); + break; +#endif + +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + dpk_sram_read_8195b(dm); + break; +#endif + +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + dpk_sram_read_8721d(dm); + break; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + +#if (RTL8197F_SUPPORT == 1) + case ODM_RTL8197F: + dpk_sram_read_8197f(dm); + break; +#endif + +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + dpk_sram_read_8192f(dm); + break; +#endif + +#if (RTL8198F_SUPPORT == 1) + case ODM_RTL8198F: + dpk_sram_read_8198f(dm); + break; +#endif + +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + dpk_sram_read_8814b(dm); + break; +#endif + +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + dpk_coef_read_8812f(dm); + break; +#endif + +#if (RTL8197G_SUPPORT == 1) + case ODM_RTL8197G: + dpk_sram_read_8197g(dm); + break; +#endif + +#endif + default: + break; + } +} + +void halrf_dpk_enable_disable(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + if (!(rf->rf_supportability & HAL_RF_DPK)) + return; + + if (!rf->is_dpk_in_progress) { + odm_acquire_spin_lock(dm, RT_IQK_SPINLOCK); + rf->is_dpk_in_progress = true; + odm_release_spin_lock(dm, RT_IQK_SPINLOCK); + + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + dpk_enable_disable_8822c(dm); + break; +#endif +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + dpk_enable_disable_8195b(dm); + break; +#endif +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + phy_dpk_enable_disable_8721d(dm); + break; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + +#if (RTL8197F_SUPPORT == 1) + case ODM_RTL8197F: + phy_dpk_enable_disable_8197f(dm); + break; +#endif +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + phy_dpk_enable_disable_8192f(dm); + break; +#endif + +#if (RTL8198F_SUPPORT == 1) + case ODM_RTL8198F: + dpk_enable_disable_8198f(dm); + break; +#endif + +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + dpk_enable_disable_8814b(dm); + break; +#endif + +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + dpk_enable_disable_8812f(dm); + break; +#endif + +#if (RTL8197G_SUPPORT == 1) + case ODM_RTL8197G: + dpk_enable_disable_8197g(dm); + break; +#endif + +#if (RTL8723F_SUPPORT == 1) + case ODM_RTL8723F: + dpk_enable_disable_8723f(dm); + break; +#endif + +#endif + default: + break; + } + + odm_acquire_spin_lock(dm, RT_IQK_SPINLOCK); + rf->is_dpk_in_progress = false; + odm_release_spin_lock(dm, RT_IQK_SPINLOCK); + } else { + RF_DBG(dm, DBG_RF_DPK, + "== Return the DPK CMD, because RFKs in Progress ==\n"); + } +} + +void halrf_dpk_track(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + struct _hal_rf_ *rf = &dm->rf_table; + + if (rf->is_dpk_in_progress || dm->rf_calibrate_info.is_iqk_in_progress || + dm->is_psd_in_process || (dpk_info->dpk_path_ok == 0) || + !(rf->rf_supportability & HAL_RF_DPK_TRACK) || rf->is_tssi_in_progress + || rf->is_txgapk_in_progress) + return; + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + if (*dm->is_fcs_mode_enable) + return; +#endif + + switch (dm->support_ic_type) { +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + dpk_track_8814b(dm); + break; +#endif + +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + dpk_track_8822c(dm); + break; +#endif + +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + dpk_track_8195b(dm); + break; +#endif + +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + phy_dpk_track_8721d(dm); + break; +#endif + +#if (RTL8723F_SUPPORT == 1) + case ODM_RTL8723F: + dpk_track_8723f(dm); + break; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + +#if (RTL8197F_SUPPORT == 1) + case ODM_RTL8197F: + phy_dpk_track_8197f(dm); + break; +#endif + +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + phy_dpk_track_8192f(dm); + break; +#endif + +#if (RTL8198F_SUPPORT == 1) + case ODM_RTL8198F: + dpk_track_8198f(dm); + break; +#endif + +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + dpk_track_8812f(dm); + break; +#endif + +#if (RTL8197G_SUPPORT == 1) + case ODM_RTL8197G: + dpk_track_8197g(dm); + break; +#endif + +#endif + default: + break; + } +} + +void halrf_set_dpk_track(void *dm_void, u8 enable) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &(dm->rf_table); + + if (enable) + rf->rf_supportability = rf->rf_supportability | HAL_RF_DPK_TRACK; + else + rf->rf_supportability = rf->rf_supportability & ~HAL_RF_DPK_TRACK; +} + +void halrf_dpk_reload(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + + switch (dm->support_ic_type) { +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + if (dpk_info->dpk_path_ok > 0) + dpk_reload_8195b(dm); + break; +#endif +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + if (dpk_info->dpk_path_ok > 0) + dpk_reload_8721d(dm); + break; +#endif + +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + +#if (RTL8197F_SUPPORT == 1) + case ODM_RTL8197F: + if (dpk_info->dpk_path_ok > 0) + dpk_reload_8197f(dm); + break; +#endif + +#if (RTL8192F_SUPPORT == 1) + case ODM_RTL8192F: + if (dpk_info->dpk_path_ok > 0) + dpk_reload_8192f(dm); + + break; +#endif + +#if (RTL8198F_SUPPORT == 1) + case ODM_RTL8198F: + if (dpk_info->dpk_path_ok > 0) + dpk_reload_8198f(dm); + break; +#endif + +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + if (dpk_info->dpk_path_ok > 0) + dpk_reload_8814b(dm); + break; +#endif + +#endif + default: + break; + } +} + +void halrf_dpk_switch(void *dm_void, u8 enable) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + struct _hal_rf_ *rf = &dm->rf_table; + + if (enable) { + rf->rf_supportability = rf->rf_supportability | HAL_RF_DPK; + dpk_info->is_dpk_enable = true; + halrf_dpk_enable_disable(dm); + halrf_dpk_trigger(dm); + halrf_set_dpk_track(dm, 1); + } else { + halrf_set_dpk_track(dm, 0); + dpk_info->is_dpk_enable = false; + halrf_dpk_enable_disable(dm); + rf->rf_supportability = rf->rf_supportability & ~HAL_RF_DPK; + } +} + +void _halrf_dpk_info_by_chip(void *dm_void, u32 *_used, char *output, u32 *_out_len) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + u32 used = *_used; + u32 out_len = *_out_len; + + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + dpk_info_by_8822c(dm, &used, output, &out_len); + break; +#endif + +#if (RTL8812F_SUPPORT == 1) + case ODM_RTL8812F: + dpk_info_by_8812f(dm, &used, output, &out_len); + break; +#endif + +#if (RTL8197G_SUPPORT == 1) + case ODM_RTL8197G: + dpk_info_by_8197g(dm, &used, output, &out_len); + break; +#endif + + default: + break; + } + + *_used = used; + *_out_len = out_len; +} + +void _halrf_display_dpk_info(void *dm_void, u32 *_used, char *output, u32 *_out_len) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + struct _hal_rf_ *rf = &(dm->rf_table); + + u32 used = *_used; + u32 out_len = *_out_len; + char *ic_name = NULL; + u8 path; + + switch (dm->support_ic_type) { + +#if (RTL8822C_SUPPORT) + case ODM_RTL8822C: + ic_name = "8822C"; + break; +#endif + +#if (RTL8814B_SUPPORT) + case ODM_RTL8814B: + ic_name = "8814B"; + break; +#endif + +#if (RTL8812F_SUPPORT) + case ODM_RTL8812F: + ic_name = "8812F"; + break; +#endif + +#if (RTL8198F_SUPPORT) + case ODM_RTL8198F: + ic_name = "8198F"; + break; +#endif + +#if (RTL8197F_SUPPORT) + case ODM_RTL8197F: + ic_name = "8197F"; + break; +#endif + +#if (RTL8192F_SUPPORT) + case ODM_RTL8192F: + ic_name = "8192F"; + break; +#endif + +#if (RTL8197G_SUPPORT) + case ODM_RTL8197G: + ic_name = "8197G"; + break; +#endif + +#if (RTL8710B_SUPPORT) + case ODM_RTL8721D: + ic_name = "8721D"; + break; +#endif + +#if (RTL8195B_SUPPORT) + case ODM_RTL8195B: + ic_name = "8195B"; + break; +#endif + } + + PDM_SNPF(out_len, used, output + used, out_len - used, + "\n===============[ DPK info %s ]===============\n", ic_name); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %s %s\n", + "DPK type", (dm->fw_offload_ability & PHYDM_RF_DPK_OFFLOAD) ? "FW" : "Driver", + (dpk_info->is_dpk_by_channel) ? "(By channel)" : "(By group)"); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %d (%d)\n", + "FW Ver (Sub Ver)", dm->fw_version, dm->fw_sub_version); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %s\n", + "DPK Ver", HALRF_DPK_VER); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %s\n", + "RFK init ver", HALRF_RFK_INIT_VER); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %d / %d (RFE type:%d)\n", + "Ext_PA 2G / 5G", dm->ext_pa, dm->ext_pa_5g, dm->rfe_type); + + if ((dpk_info->dpk_ch == 0) && (dpk_info->thermal_dpk[0] == 0)) { + PDM_SNPF(out_len, used, output + used, out_len - used, "\n %-25s\n", + "No DPK had been done before!!!"); + return; + } + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %d / %d / %d\n", + "DPK Cal / OK / Reload", dpk_info->dpk_cal_cnt, dpk_info->dpk_ok_cnt, + dpk_info->dpk_reload_cnt); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %s\n", + "RFK H2C timeout", (rf->is_rfk_h2c_timeout) ? "Yes" : "No"); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %s\n", + "DPD Reload", (dpk_info->dpk_status & BIT(0)) ? "Yes" : "No"); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %s\n", + "DPD status", dpk_info->is_dpk_enable ? "Enable" : "Disable"); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %s\n", + "DPD track status", (rf->rf_supportability & HAL_RF_DPK_TRACK) ? "Enable" : "Disable"); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %s / %s / %d / %s\n", + "TSSI / Band / CH / BW", dpk_info->is_tssi_mode == 1 ? "On" : "Off", + dpk_info->dpk_band == 0 ? "2G" : "5G", dpk_info->dpk_ch, + dpk_info->dpk_bw == 3 ? "20M" : (dpk_info->dpk_bw == 2 ? "40M" : "80M")); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %s / %s / %s / %s\n", + "DPK result (path)", dpk_info->dpk_path_ok & BIT(0) ? "OK" : "Fail", + (dm->support_ic_type & ODM_IC_2SS) ? ((dpk_info->dpk_path_ok & BIT(1)) >> 1 ? "OK" : "Fail") : "NA", + (dm->support_ic_type & ODM_IC_3SS) ? ((dpk_info->dpk_path_ok & BIT(2)) >> 2 ? "OK" : "Fail") : "NA", + (dm->support_ic_type & ODM_IC_4SS) ? ((dpk_info->dpk_path_ok & BIT(3)) >> 3 ? "OK" : "Fail") : "NA"); +#if 0 + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = %d / %d / %d / %d\n", + "DPK thermal (path)", dpk_info->thermal_dpk[0], dpk_info->thermal_dpk[1], + dpk_info->thermal_dpk[2], dpk_info->thermal_dpk[3]); +#endif + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = ", + "DPK thermal (path)"); + for (path = 0; path < KPATH; path++) { + PDM_SNPF(out_len, used, output + used, out_len - used, + path == (KPATH - 1) ? "%d\n" : "%d / ", + dpk_info->thermal_dpk[path]); + } + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = 0x%x\n", + "DPK bkup GNT control", dpk_info->gnt_control); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-25s = 0x%x\n", + "DPK bkup GNT value", dpk_info->gnt_value); + + _halrf_dpk_info_by_chip(dm, &used, output, &out_len); + + *_used = used; + *_out_len = out_len; +} + +void halrf_dpk_debug_cmd(void *dm_void, char input[][16], u32 *_used, + char *output, u32 *_out_len) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + struct _hal_rf_ *rf = &(dm->rf_table); + + char *cmd[5] = {"-h", "on", "off", "info", "switch"}; + u32 used = *_used; + u32 out_len = *_out_len; + u8 i; + + if ((strcmp(input[2], cmd[4]) != 0)) { + if (!(rf->rf_supportability & HAL_RF_DPK)) { + PDM_SNPF(out_len, used, output + used, out_len - used, + "DPK is Unsupported!!!\n"); + return; + } + } + + if ((strcmp(input[2], cmd[0]) == 0)) { + for (i = 1; i < 4; i++) { + PDM_SNPF(out_len, used, output + used, out_len - used, + " %s\n", cmd[i]); + } + } else if ((strcmp(input[2], cmd[1]) == 0)) { + PDM_SNPF(out_len, used, output + used, out_len - used, + "DPK is Enabled!!\n"); + dpk_info->is_dpk_enable = true; + halrf_dpk_enable_disable(dm); + } else if ((strcmp(input[2], cmd[2]) == 0)){ + PDM_SNPF(out_len, used, output + used, out_len - used, + "DPK is Disabled!!\n"); + dpk_info->is_dpk_enable = false; + halrf_dpk_enable_disable(dm); + } else if ((strcmp(input[2], cmd[3]) == 0)) + _halrf_display_dpk_info(dm, &used, output, &out_len); + else if ((strcmp(input[2], cmd[4]) == 0) && (strcmp(input[3], cmd[1]) == 0)) { + PDM_SNPF(out_len, used, output + used, out_len - used, + "DPK Switch on!!\n"); + halrf_dpk_switch(dm, 1); + } else if ((strcmp(input[2], cmd[4]) == 0) && (strcmp(input[3], cmd[2]) == 0)) { + PDM_SNPF(out_len, used, output + used, out_len - used, + "DPK Switch off!!\n"); + halrf_dpk_switch(dm, 0); + } else { + PDM_SNPF(out_len, used, output + used, out_len - used, + "DPK Trigger start!!\n"); + halrf_dpk_trigger(dm); + PDM_SNPF(out_len, used, output + used, out_len - used, + "DPK Trigger finish!!\n"); + } +} + +void halrf_dpk_c2h_report_transfer(void *dm_void, boolean is_ok, u8 *buf, u8 buf_size) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + + if (!(rf->rf_supportability & HAL_RF_DPK)) + return; + + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + dpk_c2h_report_transfer_8822c(dm, is_ok, buf, buf_size); + break; +#endif + default: + break; + } +} + +void halrf_dpk_info_rsvd_page(void *dm_void, u8 *buf, u32 *buf_size) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + struct dm_dpk_info *dpk_info = &dm->dpk_info; + + if (!(rf->rf_supportability & HAL_RF_DPK) || rf->is_dpk_in_progress) + return; + + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + dpk_info_rsvd_page_8822c(dm, buf, buf_size); + break; +#endif + default: + break; + } +} + +void halrf_iqk_info_rsvd_page(void *dm_void, u8 *buf, u32 *buf_size) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + if (!(rf->rf_supportability & HAL_RF_IQK)) + return; + + if (dm->rf_calibrate_info.is_iqk_in_progress) + return; + + switch (dm->support_ic_type) { +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + iqk_info_rsvd_page_8822c(dm, buf, buf_size); + break; +#endif +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + iqk_info_rsvd_page_8195b(dm, buf, buf_size); + break; +#endif + + default: + break; + } +} + +enum hal_status +halrf_config_rfk_with_header_file(void *dm_void, u32 config_type) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + enum hal_status result = HAL_STATUS_SUCCESS; +#if 0 +#if (RTL8822B_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8822B) { + if (config_type == CONFIG_BB_RF_CAL_INIT) + odm_read_and_config_mp_8822b_cal_init(dm); + } +#endif +#endif +#if (RTL8197G_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8197G) { + if (config_type == CONFIG_BB_RF_CAL_INIT) + odm_read_and_config_mp_8197g_cal_init(dm); + } +#endif +#if (RTL8198F_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8198F) { + if (config_type == CONFIG_BB_RF_CAL_INIT) + odm_read_and_config_mp_8198f_cal_init(dm); + } +#endif +#if (RTL8812F_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8812F) { + if (config_type == CONFIG_BB_RF_CAL_INIT) + odm_read_and_config_mp_8812f_cal_init(dm); + } +#endif +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8822C) { + if (config_type == CONFIG_BB_RF_CAL_INIT) + odm_read_and_config_mp_8822c_cal_init(dm); + } +#endif +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8814B) { + if (config_type == CONFIG_BB_RF_CAL_INIT) + odm_read_and_config_mp_8814b_cal_init(dm); + } +#endif +#if (RTL8195B_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8195B) { + if (config_type == CONFIG_BB_RF_CAL_INIT) + odm_read_and_config_mp_8195b_cal_init(dm); + } +#endif +#if (RTL8721D_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8721D) { + if (config_type == CONFIG_BB_RF_CAL_INIT) + odm_read_and_config_mp_8721d_cal_init(dm); + } +#endif +#if (RTL8723F_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8723F) { + if (config_type == CONFIG_BB_RF_CAL_INIT) + odm_read_and_config_mp_8723f_cal_init(dm); + } +#endif + +#if 1 + if (dm->fw_offload_ability & PHYDM_PHY_PARAM_OFFLOAD) { + result = phydm_set_reg_by_fw(dm, PHYDM_HALMAC_CMD_END, 0, 0, 0, (enum rf_path)0, 0); + RF_DBG(dm, DBG_RF_IQK,"phy param offload end!result = %d", result); + } +#endif + return result; +} + +void halrf_txgapk_trigger(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + u64 start_time = 0x0; + + if (!(rf->rf_supportability & HAL_RF_TXGAPK)) + return; + + rf->rfk_type = RF04_TXGAPK; + halrf_rfk_handshake(dm, true); + + start_time = odm_get_current_time(dm); + rf->is_txgapk_in_progress = true; + halrf_rfk_power_save(dm, false); + + switch (dm->support_ic_type) { +#if (DM_ODM_SUPPORT_TYPE & (ODM_IOT)) +#if (RTL8195B_SUPPORT == 1) + case ODM_RTL8195B: + /*phy_txgap_calibrate_8195b(dm, false);*/ + break; +#endif +#if (RTL8721D_SUPPORT == 1) + case ODM_RTL8721D: + /*phy_txgap_calibrate_8721d(dm, false);*/ + break; +#endif + +#endif + +#if (RTL8814B_SUPPORT == 1) + case ODM_RTL8814B: + /*phy_txgap_calibrate_8814b(dm, false);*/ + break; +#endif + +#if (RTL8822C_SUPPORT == 1) + case ODM_RTL8822C: + halrf_txgapk_8822c(dm); + break; +#endif + +#if (RTL8723F_SUPPORT == 1) + case ODM_RTL8723F: + halrf_txgapk_8723f(dm); + break; +#endif + + default: + break; + } + halrf_rfk_power_save(dm, true); + rf->is_txgapk_in_progress = false; + + halrf_rfk_handshake(dm, false); + + rf->dpk_progressing_time = + odm_get_progressing_time(dm_void, start_time); + RF_DBG(dm, DBG_RF_TXGAPK, "[TGGC]TXGAPK progressing_time = %lld ms\n", + rf->dpk_progressing_time); +} + +void halrf_tssi_get_efuse(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) { + halrf_tssi_get_efuse_8822c(dm); + halrf_get_efuse_thermal_pwrtype_8822c(dm); + } +#endif + +#if (RTL8812F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8812F) { + halrf_tssi_get_efuse_8812f(dm); + } +#endif + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) { + halrf_tssi_get_efuse_8814b(dm); + halrf_get_efuse_thermal_pwrtype_8814b(dm); + } +#endif + +#if (RTL8197G_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8197G) { + halrf_tssi_get_efuse_8197g(dm); + } +#endif + +#if (RTL8723F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8723F) { + halrf_tssi_get_efuse_8723f(dm); + } +#endif + +} + +void halrf_do_rxbb_dck(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8814B) + halrf_do_rxbb_dck_8814b(dm); +#endif + +} + +void halrf_do_tssi(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8822C) + halrf_do_tssi_8822c(dm); +#endif + +#if (RTL8812F_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8812F) + halrf_do_tssi_8812f(dm); +#endif + +#if (RTL8197G_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8197G) + halrf_do_tssi_8197g(dm); +#endif + +#if (RTL8723F_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8723F) + halrf_rfk_power_save(dm, false); + halrf_do_tssi_8723f(dm); + halrf_rfk_power_save(dm, true); +#endif + +} + +void halrf_set_tssi_enable(void *dm_void, boolean enable) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &(dm->rf_table); + + if (enable == 1) { + rf->power_track_type = 4; + odm_set_bb_reg(dm, R_0x1e7c, 0x40000000, 0x1); + } else { + rf->power_track_type = 0; + odm_set_bb_reg(dm, R_0x1e7c, 0x40000000, 0x0); + } +} + + +void halrf_do_thermal(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + halrf_do_thermal_8822c(dm); +#endif +} + + + +u32 halrf_set_tssi_value(void *dm_void, u32 tssi_value) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + return halrf_set_tssi_value_8822c(dm, tssi_value); +#endif + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) + return halrf_set_tssi_value_8814b(dm, tssi_value); +#endif +#if (RTL8723F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8723F) + return halrf_tssi_set_de_8723f(dm, tssi_value); +#endif + + return 0; +} + +void halrf_set_tssi_power(void *dm_void, s8 power) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + /*halrf_set_tssi_poewr_8822c(dm, power);*/ +#endif +} + +void halrf_tssi_set_de_for_tx_verify(void *dm_void, u32 tssi_de, u8 path) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + halrf_tssi_set_de_for_tx_verify_8822c(dm, tssi_de, path); +#endif + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) + halrf_tssi_set_de_for_tx_verify_8814b(dm, tssi_de, path); +#endif + +#if (RTL8812F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8812F) + halrf_tssi_set_de_for_tx_verify_8812f(dm, tssi_de, path); +#endif + +#if (RTL8197G_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8197G) + halrf_tssi_set_de_for_tx_verify_8197g(dm, tssi_de, path); +#endif + +#if (RTL8723F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8723F) + halrf_tssi_set_de_for_tx_verify_8723f(dm, tssi_de, path); +#endif +} + +u32 halrf_query_tssi_value(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + return halrf_query_tssi_value_8822c(dm); +#endif + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) + return halrf_query_tssi_value_8814b(dm); +#endif + return 0; +} + +void halrf_tssi_cck(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + /*halrf_tssi_cck_8822c(dm);*/ + if (dm->support_ic_type & ODM_RTL8822C) + halrf_thermal_cck_8822c(dm); +#endif + +} + +void halrf_thermal_cck(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + halrf_thermal_cck_8822c(dm); +#endif + +} + +void halrf_tssi_set_de(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) + halrf_tssi_set_de_8814b(dm); +#endif +} + +void halrf_tssi_dck(void *dm_void, u8 direct_do) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + halrf_rfk_handshake(dm, true); + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) { +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + if (dm->rfe_type == 1 || dm->rfe_type == 4 || dm->rfe_type == 5) + return; +#else + if (dm->rfe_type == 1 || dm->rfe_type == 6) + return; +#endif + halrf_tssi_dck_8814b(dm, direct_do); + } +#endif + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + halrf_tssi_dck_8822c(dm); +#endif + +#if (RTL8812F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8812F) + halrf_tssi_dck_8812f(dm); +#endif + +#if (RTL8197G_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8197G) + halrf_tssi_dck_8197g(dm); +#endif + + halrf_rfk_handshake(dm, false); + +} + +void halrf_calculate_tssi_codeword(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) + halrf_calculate_tssi_codeword_8814b(dm, RF_PATH_A); +#endif + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + halrf_calculate_tssi_codeword_8822c(dm); +#endif +} + +void halrf_set_tssi_codeword(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; +#if !(DM_ODM_SUPPORT_TYPE & ODM_IOT) + struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data; +#endif + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) + halrf_set_tssi_codeword_8814b(dm, tssi->tssi_codeword); +#endif + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + halrf_set_tssi_codeword_8822c(dm, tssi->tssi_codeword); +#endif + +} + +u8 halrf_get_tssi_codeword_for_txindex(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) { +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + return 80; +#else + return 60; +#endif + } +#endif + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + return 64; +#endif + +#if (RTL8812F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8812F) + return 100; +#endif + +#if (RTL8197G_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8197G) + return 100; +#endif + + return 60; +} + +void halrf_tssi_clean_de( + void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8812F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8812F) + halrf_tssi_clean_de_8812f(dm); +#endif + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) + halrf_tssi_clean_de_8814b(dm); +#endif + +#if (RTL8197G_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8197G) + halrf_tssi_clean_de_8197g(dm); +#endif + +} + +u32 halrf_tssi_trigger_de(void *dm_void, u8 path) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8812F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8812F) + return halrf_tssi_trigger_de_8812f(dm, path); +#endif + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) + return halrf_tssi_trigger_de_8814b(dm, path); +#endif + +#if (RTL8197G_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8197G) + return halrf_tssi_trigger_de_8197g(dm, path); +#endif + return 0; +} + +u32 halrf_tssi_get_de(void *dm_void, u8 path) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + return halrf_tssi_get_de_8822c(dm, path); +#endif + +#if (RTL8812F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8812F) + return halrf_tssi_get_de_8812f(dm, path); +#endif + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) + return halrf_tssi_get_de_8814b(dm, path); +#endif + +#if (RTL8197G_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8197G) + return halrf_tssi_get_de_8197g(dm, path); +#endif + + return 0; +} + +u32 halrf_get_online_tssi_de(void *dm_void, u8 path, s32 pout) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8723F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8723F) + return halrf_get_online_tssi_de_8723f(dm, path, pout); +#endif + return 0; +} + +void halrf_tssi_trigger(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct _hal_rf_ *rf = &(dm->rf_table); + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + if (*dm->mp_mode == 1) { + if (cali_info->txpowertrack_control == 0 || + cali_info->txpowertrack_control == 1) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[TSSI]======>%s MP Mode UI chose thermal tracking. return !!!\n", __func__); + return; + } + } else { + if (rf->power_track_type >= 0 && rf->power_track_type <= 3) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[TSSI]======>%s Normal Mode efues is thermal tracking. return !!!\n", __func__); + return; + } + } +#endif + + halrf_calculate_tssi_codeword(dm); + halrf_set_tssi_codeword(dm); + halrf_tssi_dck(dm, false); +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + halrf_tssi_get_efuse(dm); +#endif + halrf_tssi_set_de(dm); + halrf_do_tssi(dm); +} + +void halrf_txgapk_write_gain_table(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + halrf_txgapk_save_all_tx_gain_table_8822c(dm); +#endif +} + +void halrf_txgapk_reload_tx_gain(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (RTL8822C_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8822C) + halrf_txgapk_reload_tx_gain_8822c(dm); +#endif +} + +void halrf_txgap_enable_disable(void *dm_void, u8 enable) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &(dm->rf_table); + + if (enable) { + rf->rf_supportability = rf->rf_supportability | HAL_RF_TXGAPK; + halrf_txgapk_trigger(dm); + } else { + rf->rf_supportability = rf->rf_supportability & ~HAL_RF_TXGAPK; + halrf_txgapk_reload_tx_gain(dm); + } +} + +#if (RTL8723F_SUPPORT == 1) +void halrf_xtal_thermal_track(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + s8 *delta_swing_table_xtal_up = NULL; + u8 xtal_offset_eanble = 0, i =0; + s8 thermal_value = 0, thermal_detla = 0; + u8 thermal_base = 0; + s8 xtal_table_up[DELTA_SWINGIDX_SIZE] = {0}; + s8 xtal_table_down[DELTA_SWINGIDX_SIZE] = {0}; + u32 reg_val = 0, crystal_cap = 0; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][xtal] ======>%s\n", __func__); + + if ( dm->support_ic_type == ODM_RTL8723F) { + if (rf->is_dpk_in_progress || dm->rf_calibrate_info.is_iqk_in_progress || + dm->is_psd_in_process || rf->is_tssi_in_progress || + !(rf->rf_supportability & HAL_RF_DPK_TRACK) || + rf->is_txgapk_in_progress) + return; + + if(tssi->thermal[0] == 0xff) { + //RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "[RF][xtal] thermal 0xFF, return!\n"); + return; + } else { + thermal_base = tssi->thermal[0]; + //RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "[RF][xtal] thermal_base = 0x%x\n", thermal_base); + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "[RF][xtal] thermal_base = 0x%x\n", thermal_base); + + thermal_value = (s8)odm_get_rf_reg(dm, RF_PATH_A, RF_0x42, 0xfc00); /* 0x42: RF Reg[15:10]*/ + + thermal_detla = (s8)(thermal_value - thermal_base); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "[RF][xtal] cali_info->xtal_offset = 0x%x\n", cali_info->xtal_offset); + + cali_info->xtal_offset_last = cali_info->xtal_offset; + /* + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][Xtal] cali_info->delta_swing_table_xtal_p = %d\n", cali_info->delta_swing_table_xtal_p[2]); + */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][Xtal] thermal_value = 0x%x, thermal_detla = 0x%x, xtal_offset_last = 0x%x\n", + thermal_value, thermal_detla, cali_info->xtal_offset_last); + odm_move_memory(dm, xtal_table_up, cali_info->delta_swing_table_xtal_p, sizeof(xtal_table_up));//(void *) + odm_move_memory(dm, xtal_table_down, cali_info->delta_swing_table_xtal_n, sizeof(xtal_table_down)); + /* + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][Xtal] xtal_table_up[1] = %d\n", xtal_table_up[1]);*/ + if(thermal_detla < 0) { + + if (thermal_detla < -29) + i = 29; + else + i = (u8)(-1 * thermal_detla); + cali_info->xtal_offset = xtal_table_down[i]; + } else { + + if (thermal_detla >= 30) + i = 29; + else + i = thermal_detla; + + cali_info->xtal_offset = xtal_table_up[i]; + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][Xtal] xtal_offset = %d\n", cali_info->xtal_offset); + if (cali_info->xtal_offset_last == cali_info->xtal_offset) + xtal_offset_eanble = 0; + else + xtal_offset_eanble = 1; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][Xtal] xtal_offset_eanble = %d\n", xtal_offset_eanble); + if (xtal_offset_eanble != 0) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********Enter Xtal Tracking**********\n"); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][Xtal] R_0x103c[16:10] = 0x%x\n", odm_get_mac_reg(dm, R_0x103c, 0x0001FC00)); + + crystal_cap = dm->dm_cfo_track.crystal_cap_default & 0x7F; + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][Xtal] DEFAULT crystal_cap = 0x%x\n", crystal_cap); + reg_val = crystal_cap + cali_info->xtal_offset; + //reg_val = (u32)(odm_get_mac_reg(dm, R_0x103c, 0x0001FC00) + cali_info->xtal_offset); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][Xtal] reg_val = 0x%x\n", reg_val); + /* write 0x103c[23:17] = 0x103c[16:10] = crystal_cap */ + crystal_cap = reg_val | (reg_val << 7); + odm_set_mac_reg(dm, R_0x103c, 0x00FFFC00, crystal_cap); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][Xtal] R_0x103c[16:10] = 0x%x\n", odm_get_mac_reg(dm, R_0x103c, 0x0001FC00)); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][Xtal] R_0x103c[23:17] = 0x%x\n", odm_get_mac_reg(dm, R_0x103c, 0x00FE0000)); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "**********End Xtal Tracking**********\n"); + } + odm_set_rf_reg(dm, RF_PATH_A, RF_0x42, 0x30000, 0x3); + //delay + } + /*RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "[RF][xtal] <======%s\n", __func__);*/ +} +#endif + +void _halrf_dump_subpage(void *dm_void, u32 *_used, char *output, u32 *_out_len, u8 page) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + u32 used = *_used; + u32 out_len = *_out_len; + u32 addr; + + PDM_SNPF(out_len, used, output + used, out_len - used, + "\n===============[ Subpage_%d start]===============\n", page); + + RF_DBG(dm, DBG_RF_RFK, " ===============[ Subpage_%d start]===============\n", page); + + odm_set_bb_reg(dm, R_0x1b00, BIT(2) | BIT(1), page); + + for (addr = 0x1b00; addr < 0x1c00; addr += 0x10) { + PDM_SNPF(out_len, used, output + used, out_len - used, + " 0x%x : 0x%08x 0x%08x 0x%08x 0x%08x\n", addr, + odm_get_bb_reg(dm, addr, MASKDWORD), + odm_get_bb_reg(dm, addr + 0x4, MASKDWORD), + odm_get_bb_reg(dm, addr + 0x8, MASKDWORD), + odm_get_bb_reg(dm, addr + 0xc, MASKDWORD)); + RF_DBG(dm, DBG_RF_RFK, " 0x%x : 0x%08x 0x%08x 0x%08x 0x%08x\n", addr, + odm_get_bb_reg(dm, addr, MASKDWORD), + odm_get_bb_reg(dm, addr + 0x4, MASKDWORD), + odm_get_bb_reg(dm, addr + 0x8, MASKDWORD), + odm_get_bb_reg(dm, addr + 0xc, MASKDWORD)); + } + + *_used = used; + *_out_len = out_len; +} + +void halrf_dump_rfk_reg(void *dm_void, char input[][16], u32 *_used, + char *output, u32 *_out_len) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + char help[] = "-h"; + u32 var1[10] = {0}; + u32 used = *_used; + u32 out_len = *_out_len; + u32 reg_1b00, supportability; + u8 page; + + if (!(dm->support_ic_type & (ODM_IC_11AC_SERIES | ODM_IC_JGR3_SERIES))) { + PDM_SNPF(out_len, used, output + used, out_len - used, + "CMD is Unsupported due to IC type!!!\n"); + RF_DBG(dm, DBG_RF_RFK, "[RFK] CMD is Unsupported due to IC type!!!\n"); + return; + } else if (rf->is_dpk_in_progress || dm->rf_calibrate_info.is_iqk_in_progress || + dm->is_psd_in_process || rf->is_tssi_in_progress || rf->is_txgapk_in_progress) { + PDM_SNPF(out_len, used, output + used, out_len - used, + "Bypass CMD due to RFK is doing!!!\n"); + RF_DBG(dm, DBG_RF_RFK, "[RFK] Bypass CMD due to RFK is doing!!!\n"); + return; + } + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + if (*dm->is_fcs_mode_enable) { + PDM_SNPF(out_len, used, output + used, out_len - used, + "Bypass CMD due to FCS mode!!!\n"); + RF_DBG(dm, DBG_RF_RFK, "[RFK] Bypass CMD due to FCS mode!!!\n"); + return; + } +#endif + supportability = rf->rf_supportability; + + /*to avoid DPK track interruption*/ + rf->rf_supportability = rf->rf_supportability & ~HAL_RF_DPK_TRACK; + + reg_1b00 = odm_get_bb_reg(dm, R_0x1b00, MASKDWORD); + + if (input[2]) + PHYDM_SSCANF(input[2], DCMD_DECIMAL, &var1[0]); + + if ((strcmp(input[2], help) == 0)) + PDM_SNPF(out_len, used, output + used, out_len - used, + "dump subpage {0:Page0, 1:Page1, 2:Page2, 3:Page3, 4:all}\n"); + else if (var1[0] > 4) + PDM_SNPF(out_len, used, output + used, out_len - used, + "Wrong subpage number!!\n"); + else if (var1[0] == 4) { + for (page = 0; page < 4; page++) + _halrf_dump_subpage(dm, &used, output, &out_len, page); + } else + _halrf_dump_subpage(dm, &used, output, &out_len, (u8)var1[0]); + + odm_set_bb_reg(dm, R_0x1b00, MASKDWORD, reg_1b00); + + rf->rf_supportability = supportability; + + *_used = used; + *_out_len = out_len; +} + +/*Golbal function*/ +void halrf_reload_bp(void *dm_void, u32 *bp_reg, u32 *bp, u32 num) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 i; + + for (i = 0; i < num; i++) + odm_write_4byte(dm, bp_reg[i], bp[i]); +} + +void halrf_reload_bprf(void *dm_void, u32 *bp_reg, u32 bp[][4], u32 num, + u8 ss) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 i, path; + + for (i = 0; i < num; i++) { + for (path = 0; path < ss; path++) + odm_set_rf_reg(dm, (enum rf_path)path, bp_reg[i], + MASK20BITS, bp[i][path]); + } +} + +void halrf_bp(void *dm_void, u32 *bp_reg, u32 *bp, u32 num) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 i; + + for (i = 0; i < num; i++) + bp[i] = odm_read_4byte(dm, bp_reg[i]); +} + +void halrf_bprf(void *dm_void, u32 *bp_reg, u32 bp[][4], u32 num, u8 ss) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 i, path; + + for (i = 0; i < num; i++) { + for (path = 0; path < ss; path++) { + bp[i][path] = + odm_get_rf_reg(dm, (enum rf_path)path, + bp_reg[i], MASK20BITS); + } + } +} + +void halrf_swap(void *dm_void, u32 *v1, u32 *v2) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 temp; + + temp = *v1; + *v1 = *v2; + *v2 = temp; +} + +void halrf_bubble(void *dm_void, u32 *v1, u32 *v2) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 temp; + + if (*v1 >= 0x200 && *v2 >= 0x200) { + if (*v1 > *v2) + halrf_swap(dm, v1, v2); + } else if (*v1 < 0x200 && *v2 < 0x200) { + if (*v1 > *v2) + halrf_swap(dm, v1, v2); + } else if (*v1 < 0x200 && *v2 >= 0x200) { + halrf_swap(dm, v1, v2); + } +} + +void halrf_b_sort(void *dm_void, u32 *iv, u32 *qv) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 temp; + u32 i, j; + + RF_DBG(dm, DBG_RF_DACK, "[DACK]bubble!!!!!!!!!!!!"); + for (i = 0; i < SN - 1; i++) { + for (j = 0; j < (SN - 1 - i) ; j++) { + halrf_bubble(dm, &iv[j], &iv[j + 1]); + halrf_bubble(dm, &qv[j], &qv[j + 1]); + } + } +} + +void halrf_minmax_compare(void *dm_void, u32 value, u32 *min, + u32 *max) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + if (value >= 0x200) { + if (*min >= 0x200) { + if (*min > value) + *min = value; + } else { + *min = value; + } + if (*max >= 0x200) { + if (*max < value) + *max = value; + } + } else { + if (*min < 0x200) { + if (*min > value) + *min = value; + } + + if (*max >= 0x200) { + *max = value; + } else { + if (*max < value) + *max = value; + } + } +} + +u32 halrf_delta(void *dm_void, u32 v1, u32 v2) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + if (v1 >= 0x200 && v2 >= 0x200) { + if (v1 > v2) + return v1 - v2; + else + return v2 - v1; + } else if (v1 >= 0x200 && v2 < 0x200) { + return v2 + (0x400 - v1); + } else if (v1 < 0x200 && v2 >= 0x200) { + return v1 + (0x400 - v2); + } + + if (v1 > v2) + return v1 - v2; + else + return v2 - v1; +} + +boolean halrf_compare(void *dm_void, u32 value) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + boolean fail = false; + + if (value >= 0x200 && (0x400 - value) > 0x64) + fail = true; + else if (value < 0x200 && value > 0x64) + fail = true; + + if (fail) + RF_DBG(dm, DBG_RF_DACK, "[DACK]overflow!!!!!!!!!!!!!!!"); + return fail; +} + +void halrf_mode(void *dm_void, u32 *i_value, u32 *q_value) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 iv[SN], qv[SN], im[SN], qm[SN], temp, temp1, temp2; + u32 p, m, t; + u32 i_max = 0, q_max = 0, i_min = 0x0, q_min = 0x0, c = 0x0; + u32 i_delta, q_delta; + u8 i, j, ii = 0, qi = 0; + boolean fail = false; + + ODM_delay_ms(10); + for (i = 0; i < SN; i++) { + im[i] = 0; + qm[i] = 0; + } + i = 0; + c = 0; + while (i < SN && c < 1000) { + c++; + temp = odm_get_bb_reg(dm, 0x2dbc, 0x3fffff); + iv[i] = (temp & 0x3ff000) >> 12; + qv[i] = temp & 0x3ff; + + fail = false; + if (halrf_compare(dm, iv[i])) + fail = true; + if (halrf_compare(dm, qv[i])) + fail = true; + if (!fail) + i++; + } + c = 0; + do { + c++; + i_min = iv[0]; + i_max = iv[0]; + q_min = qv[0]; + q_max = qv[0]; + for (i = 0; i < SN; i++) { + halrf_minmax_compare(dm, iv[i], &i_min, &i_max); + halrf_minmax_compare(dm, qv[i], &q_min, &q_max); + } + RF_DBG(dm, DBG_RF_DACK, "[DACK]i_min=0x%x, i_max=0x%x", + i_min, i_max); + RF_DBG(dm, DBG_RF_DACK, "[DACK]q_min=0x%x, q_max=0x%x", + q_min, q_max); + if (i_max < 0x200 && i_min < 0x200) + i_delta = i_max - i_min; + else if (i_max >= 0x200 && i_min >= 0x200) + i_delta = i_max - i_min; + else + i_delta = i_max + (0x400 - i_min); + + if (q_max < 0x200 && q_min < 0x200) + q_delta = q_max - q_min; + else if (q_max >= 0x200 && q_min >= 0x200) + q_delta = q_max - q_min; + else + q_delta = q_max + (0x400 - q_min); + RF_DBG(dm, DBG_RF_DACK, "[DACK]i_delta=0x%x, q_delta=0x%x", + i_delta, q_delta); + halrf_b_sort(dm, iv, qv); + if (i_delta > 5 || q_delta > 5) { + temp = odm_get_bb_reg(dm, 0x2dbc, 0x3fffff); + iv[0] = (temp & 0x3ff000) >> 12; + qv[0] = temp & 0x3ff; + temp = odm_get_bb_reg(dm, 0x2dbc, 0x3fffff); + iv[SN - 1] = (temp & 0x3ff000) >> 12; + qv[SN - 1] = temp & 0x3ff; + } else { + break; + } + } while (c < 100); +#if 1 +#if 0 + for (i = 0; i < SN; i++) + RF_DBG(dm, DBG_RF_DACK, "[DACK]iv[%d] = 0x%x\n", i, iv[i]); + for (i = 0; i < SN; i++) + RF_DBG(dm, DBG_RF_DACK, "[DACK]qv[%d] = 0x%x\n", i, qv[i]); +#endif + /*i*/ + m = 0; + p = 0; + for (i = 10; i < SN - 10; i++) { + if (iv[i] > 0x200) + m = (0x400 - iv[i]) + m; + else + p = iv[i] + p; + } + + if (p > m) { + t = p - m; + t = t / (SN - 20); + } else { + t = m - p; + t = t / (SN - 20); + if (t != 0x0) + t = 0x400 - t; + } + *i_value = t; + /*q*/ + m = 0; + p = 0; + for (i = 10; i < SN - 10; i++) { + if (qv[i] > 0x200) + m = (0x400 - qv[i]) + m; + else + p = qv[i] + p; + } + if (p > m) { + t = p - m; + t = t / (SN - 20); + } else { + t = m - p; + t = t / (SN - 20); + if (t != 0x0) + t = 0x400 - t; + } + *q_value = t; +#endif +} +void halrf_delay_10us(u16 v1) +{ + u16 i = 0; + + for (i = 0; i < v1; i++) + ODM_delay_us(10); +} + diff --git a/hal/phydm/halrf/halrf.h b/hal/phydm/halrf/halrf.h new file mode 100644 index 0000000..33fbf9b --- /dev/null +++ b/hal/phydm/halrf/halrf.h @@ -0,0 +1,814 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALRF_H__ +#define __HALRF_H__ + +/*@============================================================*/ +/*@include files*/ +/*@============================================================*/ +#include "halrf/halrf_psd.h" +#if (RTL8822B_SUPPORT == 1) +#include "halrf/rtl8822b/halrf_rfk_init_8822b.h" +#endif +#if (RTL8822C_SUPPORT == 1) +#include "halrf/rtl8822c/halrf_rfk_init_8822c.h" +#include "halrf/rtl8822c/halrf_iqk_8822c.h" +#include "halrf/rtl8822c/halrf_tssi_8822c.h" +#include "halrf/rtl8822c/halrf_dpk_8822c.h" +#include "halrf/rtl8822c/halrf_txgapk_8822c.h" +#endif + +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) +#if (RTL8197G_SUPPORT == 1) +#include "halrf/rtl8197g/halrf_rfk_init_8197g.h" +#endif +#if (RTL8198F_SUPPORT == 1) +#include "halrf/rtl8198f/halrf_rfk_init_8198f.h" +#endif +#if (RTL8812F_SUPPORT == 1) +#include "halrf/rtl8812f/halrf_rfk_init_8812f.h" +#endif + +#endif + +#if (RTL8814B_SUPPORT == 1) +#include "halrf/rtl8814b/halrf_rfk_init_8814b.h" +#include "halrf/rtl8814b/halrf_iqk_8814b.h" +#include "halrf/rtl8814b/halrf_dpk_8814b.h" +#include "halrf/rtl8814b/halrf_txgapk_8814b.h" +#endif + +/*@============================================================*/ +/*@Definition */ +/*@============================================================*/ +/*IQK version*/ +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN)) +#define IQK_VER_8188E "0x14" +#define IQK_VER_8192E "0x01" +#define IQK_VER_8192F "0x01" +#define IQK_VER_8723B "0x1e" +#define IQK_VER_8812A "0x02" +#define IQK_VER_8821A "0x02" +#elif (DM_ODM_SUPPORT_TYPE & (ODM_CE)) +#define IQK_VER_8188E "0x01" +#define IQK_VER_8192E "0x01" +#define IQK_VER_8192F "0x01" +#define IQK_VER_8723B "0x1f" +#define IQK_VER_8812A "0x01" +#define IQK_VER_8821A "0x01" +#elif (DM_ODM_SUPPORT_TYPE & (ODM_AP)) +#define IQK_VER_8188E "0x01" +#define IQK_VER_8192E "0x01" +#define IQK_VER_8192F "0x01" +#define IQK_VER_8723B "0x1e" +#define IQK_VER_8812A "0x01" +#define IQK_VER_8821A "0x01" +#elif (DM_ODM_SUPPORT_TYPE & (ODM_IOT)) +#define IQK_VER_8188E "0x01" +#define IQK_VER_8192E "0x01" +#define IQK_VER_8192F "0x01" +#define IQK_VER_8723B "0x1e" +#define IQK_VER_8812A "0x01" +#define IQK_VER_8821A "0x01" +#endif +#define IQK_VER_8814A "0x0f" +#define IQK_VER_8188F "0x01" +#define IQK_VER_8197F "0x1d" +#define IQK_VER_8703B "0x05" +#define IQK_VER_8710B "0x01" +#define IQK_VER_8723D "0x02" +#define IQK_VER_8822B "0x32" +#define IQK_VER_8822C "0x14" +#define IQK_VER_8821C "0x23" +#define IQK_VER_8198F "0x0b" +#define IQK_VER_8814B "0x15" +#define IQK_VER_8812F "0x0c" +#define IQK_VER_8710C "0x0a" +#define IQK_VER_8197G "0x03" +#define IQK_VER_8723F "0x00" + + +/*LCK version*/ +#define LCK_VER_8188E "0x02" +#define LCK_VER_8192E "0x02" +#define LCK_VER_8192F "0x01" +#define LCK_VER_8723B "0x02" +#define LCK_VER_8812A "0x01" +#define LCK_VER_8821A "0x01" +#define LCK_VER_8814A "0x01" +#define LCK_VER_8188F "0x01" +#define LCK_VER_8197F "0x01" +#define LCK_VER_8703B "0x01" +#define LCK_VER_8710B "0x01" +#define LCK_VER_8723D "0x01" +#define LCK_VER_8822B "0x02" +#define LCK_VER_8822C "0x00" +#define LCK_VER_8821C "0x03" +#define LCK_VER_8814B "0x02" +#define LCK_VER_8195B "0x02" +#define LCK_VER_8710C "0x02" +#define LCK_VER_8197G "0x01" +#define LCK_VER_8198F "0x01" + +/*power tracking version*/ +#define PWRTRK_VER_8188E "0x01" +#define PWRTRK_VER_8192E "0x01" +#define PWRTRK_VER_8192F "0x01" +#define PWRTRK_VER_8723B "0x01" +#define PWRTRK_VER_8812A "0x01" +#define PWRTRK_VER_8821A "0x01" +#define PWRTRK_VER_8814A "0x01" +#define PWRTRK_VER_8188F "0x01" +#define PWRTRK_VER_8197F "0x01" +#define PWRTRK_VER_8703B "0x01" +#define PWRTRK_VER_8710B "0x01" +#define PWRTRK_VER_8723D "0x01" +#define PWRTRK_VER_8822B "0x01" +#define PWRTRK_VER_8822C "0x00" +#define PWRTRK_VER_8821C "0x01" +#define PWRTRK_VER_8814B "0x00" +#define PWRTRK_VER_8197G "0x00" + +/*DPK version*/ +#define DPK_VER_8188E "NONE" +#define DPK_VER_8192E "NONE" +#define DPK_VER_8723B "NONE" +#define DPK_VER_8812A "NONE" +#define DPK_VER_8821A "NONE" +#define DPK_VER_8814A "NONE" +#define DPK_VER_8188F "NONE" +#define DPK_VER_8197F "0x08" +#define DPK_VER_8703B "NONE" +#define DPK_VER_8710B "NONE" +#define DPK_VER_8723D "NONE" +#define DPK_VER_8822B "NONE" +#define DPK_VER_8822C "0x20" +#define DPK_VER_8821C "NONE" +#define DPK_VER_8192F "0x11" +#define DPK_VER_8198F "0x0e" +#define DPK_VER_8814B "0x0f" +#define DPK_VER_8195B "0x0c" +#define DPK_VER_8812F "0x0a" +#define DPK_VER_8197G "0x09" + +/*RFK_INIT version*/ +#define RFK_INIT_VER_8822B "0x8" +#define RFK_INIT_VER_8822C "0x8" +#define RFK_INIT_VER_8195B "0x1" +#define RFK_INIT_VER_8198F "0x8" +#define RFK_INIT_VER_8814B "0xa" +#define RFK_INIT_VER_8812F "0x4" +#define RFK_INIT_VER_8197G "0x4" + +/*DACK version*/ +#define DACK_VER_8822C "0xa" +#define DACK_VER_8814B "0x4" + +/*TXGAPK version*/ +#define TXGAPK_VER_8814B "0x1" +#define TXGAPK_VER_8195B "0x2" + +/*Kfree tracking version*/ +#define KFREE_VER_8188E \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8192E \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8192F \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8723B \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8812A \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8821A \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8814A \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8188F \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8197F \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8703B \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8710B \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8723D \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8822B \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8822C \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8821C \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8814B \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" +#define KFREE_VER_8197G \ + (dm->power_trim_data.flag & KFREE_FLAG_ON) ? "0x01" : "NONE" + +#define TSSI_VER_8812F "0x1" +#define TSSI_VER_8822C "0x1" +#define TSSI_VER_8821C "0x1" +#define TSSI_VER_8814B "0x1" +#define TSSI_VER_8197G "0x1" +#define TSSI_VER_8723F "0x1" + +/*PA Bias Calibration version*/ +#define PABIASK_VER_8188E \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8192E \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8192F \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8723B \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8812A \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8821A \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8814A \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8188F \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8197F \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8703B \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8710B \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8723D \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8822B \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8822C \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8821C \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8814B \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" +#define PABIASK_VER_8197G \ + (dm->power_trim_data.pa_bias_flag & PA_BIAS_FLAG_ON) ? "0x01" : "NONE" + +#define HALRF_IQK_VER \ + (dm->support_ic_type == ODM_RTL8188E) ? IQK_VER_8188E : \ + (dm->support_ic_type == ODM_RTL8192E) ? IQK_VER_8192E : \ + (dm->support_ic_type == ODM_RTL8192F) ? IQK_VER_8192F : \ + (dm->support_ic_type == ODM_RTL8723B) ? IQK_VER_8723B : \ + (dm->support_ic_type == ODM_RTL8812) ? IQK_VER_8812A : \ + (dm->support_ic_type == ODM_RTL8821) ? IQK_VER_8821A : \ + (dm->support_ic_type == ODM_RTL8814A) ? IQK_VER_8814A : \ + (dm->support_ic_type == ODM_RTL8188F) ? IQK_VER_8188F : \ + (dm->support_ic_type == ODM_RTL8197F) ? IQK_VER_8197F : \ + (dm->support_ic_type == ODM_RTL8703B) ? IQK_VER_8703B : \ + (dm->support_ic_type == ODM_RTL8710B) ? IQK_VER_8710B : \ + (dm->support_ic_type == ODM_RTL8723D) ? IQK_VER_8723D : \ + (dm->support_ic_type == ODM_RTL8822B) ? IQK_VER_8822B : \ + (dm->support_ic_type == ODM_RTL8822C) ? IQK_VER_8822C : \ + (dm->support_ic_type == ODM_RTL8821C) ? IQK_VER_8821C : \ + (dm->support_ic_type == ODM_RTL8814B) ? IQK_VER_8814B : \ + (dm->support_ic_type == ODM_RTL8710C) ? IQK_VER_8710C : \ + (dm->support_ic_type == ODM_RTL8723F) ? IQK_VER_8723F : \ + (dm->support_ic_type == ODM_RTL8197G) ? IQK_VER_8197G : "unknown" + +#define HALRF_LCK_VER \ + (dm->support_ic_type == ODM_RTL8188E) ? LCK_VER_8188E : \ + (dm->support_ic_type == ODM_RTL8192E) ? LCK_VER_8192E : \ + (dm->support_ic_type == ODM_RTL8192F) ? LCK_VER_8192F : \ + (dm->support_ic_type == ODM_RTL8723B) ? LCK_VER_8723B : \ + (dm->support_ic_type == ODM_RTL8812) ? LCK_VER_8812A : \ + (dm->support_ic_type == ODM_RTL8821) ? LCK_VER_8821A : \ + (dm->support_ic_type == ODM_RTL8814A) ? LCK_VER_8814A : \ + (dm->support_ic_type == ODM_RTL8188F) ? LCK_VER_8188F : \ + (dm->support_ic_type == ODM_RTL8197F) ? LCK_VER_8197F : \ + (dm->support_ic_type == ODM_RTL8703B) ? LCK_VER_8703B : \ + (dm->support_ic_type == ODM_RTL8710B) ? LCK_VER_8710B : \ + (dm->support_ic_type == ODM_RTL8723D) ? LCK_VER_8723D : \ + (dm->support_ic_type == ODM_RTL8822B) ? LCK_VER_8822B : \ + (dm->support_ic_type == ODM_RTL8822C) ? LCK_VER_8822C : \ + (dm->support_ic_type == ODM_RTL8821C) ? LCK_VER_8821C : \ + (dm->support_ic_type == ODM_RTL8814B) ? LCK_VER_8814B : \ + (dm->support_ic_type == ODM_RTL8710C) ? LCK_VER_8710C : \ + (dm->support_ic_type == ODM_RTL8710C) ? LCK_VER_8710C : "unknown" +#define HALRF_POWRTRACKING_VER \ + (dm->support_ic_type == ODM_RTL8188E) ? PWRTRK_VER_8188E : \ + (dm->support_ic_type == ODM_RTL8192E) ? PWRTRK_VER_8192E : \ + (dm->support_ic_type == ODM_RTL8192F) ? PWRTRK_VER_8192F : \ + (dm->support_ic_type == ODM_RTL8723B) ? PWRTRK_VER_8723B : \ + (dm->support_ic_type == ODM_RTL8812) ? PWRTRK_VER_8812A : \ + (dm->support_ic_type == ODM_RTL8821) ? PWRTRK_VER_8821A : \ + (dm->support_ic_type == ODM_RTL8814A) ? PWRTRK_VER_8814A : \ + (dm->support_ic_type == ODM_RTL8188F) ? PWRTRK_VER_8188F : \ + (dm->support_ic_type == ODM_RTL8197F) ? PWRTRK_VER_8197F : \ + (dm->support_ic_type == ODM_RTL8703B) ? PWRTRK_VER_8703B : \ + (dm->support_ic_type == ODM_RTL8710B) ? PWRTRK_VER_8710B : \ + (dm->support_ic_type == ODM_RTL8723D) ? PWRTRK_VER_8723D : \ + (dm->support_ic_type == ODM_RTL8822B) ? PWRTRK_VER_8822B : \ + (dm->support_ic_type == ODM_RTL8822C) ? PWRTRK_VER_8822C : \ + (dm->support_ic_type == ODM_RTL8821C) ? PWRTRK_VER_8821C : \ + (dm->support_ic_type == ODM_RTL8197G) ? PWRTRK_VER_8197G : "unknown" + +#define HALRF_DPK_VER \ + (dm->support_ic_type == ODM_RTL8188E) ? DPK_VER_8188E : \ + (dm->support_ic_type == ODM_RTL8192E) ? DPK_VER_8192E : \ + (dm->support_ic_type == ODM_RTL8192F) ? DPK_VER_8192F : \ + (dm->support_ic_type == ODM_RTL8723B) ? DPK_VER_8723B : \ + (dm->support_ic_type == ODM_RTL8812) ? DPK_VER_8812A : \ + (dm->support_ic_type == ODM_RTL8821) ? DPK_VER_8821A : \ + (dm->support_ic_type == ODM_RTL8814A) ? DPK_VER_8814A : \ + (dm->support_ic_type == ODM_RTL8188F) ? DPK_VER_8188F : \ + (dm->support_ic_type == ODM_RTL8197F) ? DPK_VER_8197F : \ + (dm->support_ic_type == ODM_RTL8198F) ? DPK_VER_8198F : \ + (dm->support_ic_type == ODM_RTL8703B) ? DPK_VER_8703B : \ + (dm->support_ic_type == ODM_RTL8710B) ? DPK_VER_8710B : \ + (dm->support_ic_type == ODM_RTL8723D) ? DPK_VER_8723D : \ + (dm->support_ic_type == ODM_RTL8822B) ? DPK_VER_8822B : \ + (dm->support_ic_type == ODM_RTL8822C) ? DPK_VER_8822C : \ + (dm->support_ic_type == ODM_RTL8812F) ? DPK_VER_8812F : \ + (dm->support_ic_type == ODM_RTL8821C) ? DPK_VER_8821C : \ + (dm->support_ic_type == ODM_RTL8814B) ? DPK_VER_8814B : \ + (dm->support_ic_type == ODM_RTL8197G) ? DPK_VER_8197G : "unknown" + +#define HALRF_KFREE_VER \ + (dm->support_ic_type == ODM_RTL8188E) ? KFREE_VER_8188E : \ + (dm->support_ic_type == ODM_RTL8192E) ? KFREE_VER_8192E : \ + (dm->support_ic_type == ODM_RTL8192F) ? KFREE_VER_8192F : \ + (dm->support_ic_type == ODM_RTL8723B) ? KFREE_VER_8723B : \ + (dm->support_ic_type == ODM_RTL8812) ? KFREE_VER_8812A : \ + (dm->support_ic_type == ODM_RTL8821) ? KFREE_VER_8821A : \ + (dm->support_ic_type == ODM_RTL8814A) ? KFREE_VER_8814A : \ + (dm->support_ic_type == ODM_RTL8188F) ? KFREE_VER_8188F : \ + (dm->support_ic_type == ODM_RTL8197F) ? KFREE_VER_8197F : \ + (dm->support_ic_type == ODM_RTL8703B) ? KFREE_VER_8703B : \ + (dm->support_ic_type == ODM_RTL8710B) ? KFREE_VER_8710B : \ + (dm->support_ic_type == ODM_RTL8723D) ? KFREE_VER_8723D : \ + (dm->support_ic_type == ODM_RTL8822B) ? KFREE_VER_8822B : \ + (dm->support_ic_type == ODM_RTL8822C) ? KFREE_VER_8822C : \ + (dm->support_ic_type == ODM_RTL8821C) ? KFREE_VER_8821C : \ + (dm->support_ic_type == ODM_RTL8814B) ? KFREE_VER_8814B : \ + (dm->support_ic_type == ODM_RTL8197G) ? KFREE_VER_8197G : "unknown" + +#define HALRF_TSSI_VER \ + (dm->support_ic_type == ODM_RTL8812F) ? TSSI_VER_8812F : \ + (dm->support_ic_type == ODM_RTL8822C) ? TSSI_VER_8822C : \ + (dm->support_ic_type == ODM_RTL8821C) ? TSSI_VER_8821C : \ + (dm->support_ic_type == ODM_RTL8814B) ? TSSI_VER_8814B : \ + (dm->support_ic_type == ODM_RTL8197G) ? TSSI_VER_8197G : \ + (dm->support_ic_type == ODM_RTL8723F) ? TSSI_VER_8723F : "unknown" + +#define HALRF_PABIASK_VER \ + (dm->support_ic_type == ODM_RTL8188E) ? PABIASK_VER_8188E : \ + (dm->support_ic_type == ODM_RTL8192E) ? PABIASK_VER_8192E : \ + (dm->support_ic_type == ODM_RTL8192F) ? PABIASK_VER_8192F : \ + (dm->support_ic_type == ODM_RTL8723B) ? PABIASK_VER_8723B : \ + (dm->support_ic_type == ODM_RTL8812) ? PABIASK_VER_8812A : \ + (dm->support_ic_type == ODM_RTL8821) ? PABIASK_VER_8821A : \ + (dm->support_ic_type == ODM_RTL8814A) ? PABIASK_VER_8814A : \ + (dm->support_ic_type == ODM_RTL8188F) ? PABIASK_VER_8188F : \ + (dm->support_ic_type == ODM_RTL8197F) ? PABIASK_VER_8197F : \ + (dm->support_ic_type == ODM_RTL8703B) ? PABIASK_VER_8703B : \ + (dm->support_ic_type == ODM_RTL8710B) ? PABIASK_VER_8710B : \ + (dm->support_ic_type == ODM_RTL8723D) ? PABIASK_VER_8723D : \ + (dm->support_ic_type == ODM_RTL8822B) ? PABIASK_VER_8822B : \ + (dm->support_ic_type == ODM_RTL8822C) ? PABIASK_VER_8822C : \ + (dm->support_ic_type == ODM_RTL8821C) ? PABIASK_VER_8821C : \ + (dm->support_ic_type == ODM_RTL8814B) ? PABIASK_VER_8814B : \ + (dm->support_ic_type == ODM_RTL8197G) ? PABIASK_VER_8197G : "unknown" + +#define HALRF_RFK_INIT_VER \ + (dm->support_ic_type == ODM_RTL8822B) ? RFK_INIT_VER_8822B : \ + (dm->support_ic_type == ODM_RTL8822C) ? RFK_INIT_VER_8822C : \ + (dm->support_ic_type == ODM_RTL8812F) ? RFK_INIT_VER_8812F : \ + (dm->support_ic_type == ODM_RTL8198F) ? RFK_INIT_VER_8198F : \ + (dm->support_ic_type == ODM_RTL8814B) ? RFK_INIT_VER_8814B : \ + (dm->support_ic_type == ODM_RTL8197G) ? RFK_INIT_VER_8197G : "unknown" + +#define HALRF_DACK_VER \ + (dm->support_ic_type == ODM_RTL8822C) ? DACK_VER_8822C : \ + (dm->support_ic_type == ODM_RTL8814B) ? DACK_VER_8814B : "unknown" + +#define IQK_THRESHOLD 8 +#define DPK_THRESHOLD 4 +#define HALRF_ABS(a,b) ((a>b) ? (a-b) : (b-a)) +#define SN 100 + +#define CCK_TSSI_NUM 6 +#define OFDM_2G_TSSI_NUM 5 +#define OFDM_5G_TSSI_NUM 14 + + + +/*@===========================================================*/ +/*AGC RX High Power mode*/ +/*@===========================================================*/ +#define lna_low_gain_1 0x64 +#define lna_low_gain_2 0x5A +#define lna_low_gain_3 0x58 + +/*@============================================================*/ +/*@ enumeration */ +/*@============================================================*/ + +enum halrf_func_idx { /*F_XXX = PHYDM XXX function*/ + RF00_PWR_TRK = 0, /*Pow_trk, TSSI_trk*/ + RF01_IQK = 1, /*LOK, IQK*/ + RF02_LCK = 2, + RF03_DPK = 3, + RF04_TXGAPK = 4, + RF05_DACK = 5, + RF06_DPK_TRK = 6, + RF07_2GBAND_SHIFT = 7, + RF08_RXDCK = 8, + RF09_RFK = 9 +}; + +enum halrf_ability { + HAL_RF_TX_PWR_TRACK = BIT(RF00_PWR_TRK), + HAL_RF_IQK = BIT(RF01_IQK), + HAL_RF_LCK = BIT(RF02_LCK), + HAL_RF_DPK = BIT(RF03_DPK), + HAL_RF_TXGAPK = BIT(RF04_TXGAPK), + HAL_RF_DACK = BIT(RF05_DACK), + HAL_RF_DPK_TRACK = BIT(RF06_DPK_TRK), + HAL_2GBAND_SHIFT = BIT(RF07_2GBAND_SHIFT), + HAL_RF_RXDCK = BIT(RF08_RXDCK) +}; + +enum halrf_shift_band { + HAL_RF_2P4 = 0, + HAL_RF_2P3 = 1, + HAL_RF_2P5 = 2 +}; + +enum halrf_dbg_comp { + DBG_RF_TX_PWR_TRACK = BIT(RF00_PWR_TRK), + DBG_RF_IQK = BIT(RF01_IQK), + DBG_RF_LCK = BIT(RF02_LCK), + DBG_RF_DPK = BIT(RF03_DPK), + DBG_RF_TXGAPK = BIT(RF04_TXGAPK), + DBG_RF_DACK = BIT(RF05_DACK), + DBG_RF_DPK_TRACK = BIT(RF06_DPK_TRK), + DBG_RF_RFK = BIT(RF09_RFK), + DBG_RF_MP = BIT(29), + DBG_RF_TMP = BIT(30), + DBG_RF_INIT = BIT(31) +}; + +enum halrf_cmninfo_init { + HALRF_CMNINFO_ABILITY = 0, + HALRF_CMNINFO_DPK_EN = 1, + HALRF_CMNINFO_EEPROM_THERMAL_VALUE, + HALRF_CMNINFO_RFK_FORBIDDEN, + HALRF_CMNINFO_IQK_SEGMENT, + HALRF_CMNINFO_RATE_INDEX, + HALRF_CMNINFO_PWT_TYPE, + HALRF_CMNINFO_MP_PSD_POINT, + HALRF_CMNINFO_MP_PSD_START_POINT, + HALRF_CMNINFO_MP_PSD_STOP_POINT, + HALRF_CMNINFO_MP_PSD_AVERAGE, + HALRF_CMNINFO_IQK_TIMES, + HALRF_CMNINFO_MP_POWER_TRACKING_TYPE, + HALRF_CMNINFO_POWER_TRACK_CONTROL +}; + +enum halrf_cmninfo_hook { + HALRF_CMNINFO_CON_TX, + HALRF_CMNINFO_SINGLE_TONE, + HALRF_CMNINFO_CARRIER_SUPPRESSION, + HALRF_CMNINFO_MP_RATE_INDEX, + HALRF_CMNINFO_MANUAL_RF_SUPPORTABILITY +}; + +enum halrf_lna_set { + HALRF_LNA_DISABLE = 0, + HALRF_LNA_ENABLE = 1, +}; + +enum halrf_k_segment_time { + SEGMENT_FREE = 0, + SEGMENT_10MS = 10, /*10ms*/ + SEGMENT_30MS = 30, /*30ms*/ + SEGMENT_50MS = 50, /*50ms*/ +}; + +#define POWER_INDEX_DIFF 4 +#define TSSI_TXAGC_DIFF 2 + +#define TSSI_CODE_NUM 84 + +#define TSSI_SLOPE_2G 8 +#define TSSI_SLOPE_5G 5 + +#define TSSI_EFUSE_NUM 25 +#define TSSI_EFUSE_KFREE_NUM 4 +#define TSSI_DE_DIFF_EFUSE_NUM 10 + +struct _halrf_tssi_data { + s32 cck_offset_patha; + s32 cck_offset_pathb; + s32 tssi_trk_txagc_offset[PHYDM_MAX_RF_PATH]; + s32 delta_tssi_txagc_offset[PHYDM_MAX_RF_PATH]; + s16 txagc_codeword[TSSI_CODE_NUM]; + u16 tssi_codeword[TSSI_CODE_NUM]; + s8 tssi_efuse[PHYDM_MAX_RF_PATH][TSSI_EFUSE_NUM]; + s8 tssi_de_diff_efuse[PHYDM_MAX_RF_PATH][TSSI_DE_DIFF_EFUSE_NUM]; + s8 tssi_kfree_efuse[PHYDM_MAX_RF_PATH][TSSI_EFUSE_KFREE_NUM]; + u8 thermal[PHYDM_MAX_RF_PATH]; + u32 index[PHYDM_MAX_RF_PATH][14]; + u8 do_tssi; + u8 get_thermal; + u8 tssi_finish_bit[PHYDM_MAX_RF_PATH]; + u8 thermal_trigger; + s8 tssi_de; +}; + +struct _halrf_txgapk_info { + u32 txgapk_rf3f_bp[5][12][PHYDM_MAX_RF_PATH]; /* band(2Gcck/2GOFDM/5GL/5GM/5GH)/idx/path */ + boolean txgapk_bp_done; + s8 offset[12][PHYDM_MAX_RF_PATH]; + s8 fianl_offset[12][PHYDM_MAX_RF_PATH]; + u8 read_txgain; +}; + + +/*@============================================================*/ +/*@ structure */ +/*@============================================================*/ + +struct _hal_rf_ { + /*hook*/ + u8 *test1; + + /*update*/ + u32 rf_supportability; + u8 rf_shift_band; + /*u32 halrf_tssi_data;*/ + + u8 eeprom_thermal; + u8 dpk_en; /*Enable Function DPK OFF/ON = 0/1*/ + boolean dpk_done; + u64 dpk_progressing_time; + u64 iqk_progressing_time; + u32 fw_ver; + + boolean *is_con_tx; + boolean *is_single_tone; + boolean *is_carrier_suppresion; + boolean is_dpk_in_progress; + boolean is_tssi_in_progress; + boolean is_bt_iqk_timeout; + boolean is_rfk_h2c_timeout; + boolean aac_checked; + boolean is_txgapk_in_progress; + + u8 *mp_rate_index; + u32 *manual_rf_supportability; + u32 p_rate_index; + u8 pwt_type; + u32 rf_dbg_comp; + u8 rfk_type; + u32 gnt_control; + + u8 ext_lna; /*@with 2G external LNA NO/Yes = 0/1*/ + u8 ext_lna_5g; /*@with 5G external LNA NO/Yes = 0/1*/ + u8 ext_pa; /*@with 2G external PNA NO/Yes = 0/1*/ + u8 ext_pa_5g; /*@with 5G external PNA NO/Yes = 0/1*/ +#if !(DM_ODM_SUPPORT_TYPE & ODM_IOT) + struct _halrf_psd_data halrf_psd_data; + struct _halrf_tssi_data halrf_tssi_data; +#endif + struct _halrf_txgapk_info halrf_txgapk_info; + u8 power_track_type; + u8 mp_pwt_type; + u8 pre_band_type; +}; + +/*@============================================================*/ +/*@ function prototype */ +/*@============================================================*/ + +#if (RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1 ||\ + RTL8195B_SUPPORT == 1 || RTL8198F_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1 || RTL8822C_SUPPORT == 1 ||\ + RTL8812F_SUPPORT == 1 || RTL8710C_SUPPORT == 1 ||\ + RTL8197G_SUPPORT == 1) +void halrf_iqk_info_dump(void *dm_void, u32 *_used, char *output, + u32 *_out_len); + +void halrf_iqk_hwtx_check(void *dm_void, boolean is_check); +#endif + +u8 halrf_match_iqk_version(void *dm_void); + +void halrf_support_ability_debug(void *dm_void, char input[][16], u32 *_used, + char *output, u32 *_out_len); +#ifdef CONFIG_2G_BAND_SHIFT +void halrf_support_band_shift_debug(void *dm_void, char input[][16], u32 *_used, + char *output, u32 *_out_len); +#endif +void halrf_cmn_info_init(void *dm_void, enum halrf_cmninfo_init cmn_info, + u32 value); + +void halrf_cmn_info_hook(void *dm_void, enum halrf_cmninfo_hook cmn_info, + void *value); + +void halrf_cmn_info_set(void *dm_void, u32 cmn_info, u64 value); + +u64 halrf_cmn_info_get(void *dm_void, u32 cmn_info); + +void halrf_watchdog(void *dm_void); + +void halrf_supportability_init(void *dm_void); + +void halrf_init(void *dm_void); + +void halrf_iqk_trigger(void *dm_void, boolean is_recovery); + +void halrf_rfk_handshake(void *dm_void, boolean is_before_k); + +void halrf_rf_k_connect_trigger(void *dm_void, boolean is_recovery, + enum halrf_k_segment_time seg_time); + +void halrf_segment_iqk_trigger(void *dm_void, boolean clear, + boolean segment_iqk); + +void halrf_lck_trigger(void *dm_void); + +void halrf_iqk_debug(void *dm_void, u32 *const dm_value, u32 *_used, + char *output, u32 *_out_len); + +void phydm_get_iqk_cfir(void *dm_void, u8 idx, u8 path, boolean debug); + +void halrf_iqk_xym_read(void *dm_void, u8 path, u8 xym_type); + +void halrf_rf_lna_setting(void *dm_void, enum halrf_lna_set type); + +void halrf_do_imr_test(void *dm_void, u8 data); + +u32 halrf_psd_log2base(u32 val); + +void halrf_dpk_trigger(void *dm_void); + +void halrf_txgapk_trigger(void *dm_void); + +u8 halrf_dpk_result_check(void *dm_void); + +void halrf_dpk_sram_read(void *dm_void); + +void halrf_dpk_enable_disable(void *dm_void); + +void halrf_dpk_track(void *dm_void); + +void halrf_dpk_reload(void *dm_void); + +void halrf_dpk_switch(void *dm_void, u8 enable); + +void halrf_dpk_debug_cmd(void *dm_void, char input[][16], u32 *_used, + char *output, u32 *_out_len); + +void halrf_dpk_c2h_report_transfer(void *dm_void, boolean is_ok, u8 *buf, u8 buf_size); + +void halrf_dpk_info_rsvd_page(void *dm_void, u8 *buf, u32 *buf_size); + +/*Global function*/ + +void halrf_reload_bp(void *dm_void, u32 *bp_reg, u32 *bp, u32 num); + +void halrf_reload_bprf(void *dm_void, u32 *bp_reg, u32 bp[][4], u32 num, + u8 ss); + +void halrf_bp(void *dm_void, u32 *bp_reg, u32 *bp, u32 num); + +void halrf_bprf(void *dm_void, u32 *bp_reg, u32 bp[][4], u32 num, u8 ss); + +void halrf_mode(void *dm_void, u32 *i_value, u32 *q_value); + +boolean halrf_compare(void *dm_void, u32 value); + +u32 halrf_delta(void *dm_void, u32 v1, u32 v2); + +void halrf_minmax_compare(void *dm_void, u32 value, u32 *min, u32 *max); + +void halrf_b_sort(void *dm_void, u32 *iv, u32 *qv); + +void halrf_bubble(void *dm_void, u32 *v1, u32 *v2); + +void halrf_swap(void *dm_void, u32 *v1, u32 *v2); + +enum hal_status +halrf_config_rfk_with_header_file(void *dm_void, u32 config_type); + +#if (RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1 ||\ + RTL8195B_SUPPORT == 1 || RTL8198F_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1 || RTL8822C_SUPPORT == 1 ||\ + RTL8812F_SUPPORT == 1 || RTL8710C_SUPPORT == 1 ||\ + RTL8197G_SUPPORT == 1) +void halrf_iqk_dbg(void *dm_void); +#endif + +void halrf_tssi_get_efuse(void *dm_void); + +void halrf_do_tssi(void *dm_void); + +void halrf_set_tssi_enable(void *dm_void, boolean enable); + +void halrf_do_thermal(void *dm_void); + +u32 halrf_set_tssi_value(void *dm_void, u32 tssi_value); + +void halrf_set_tssi_power(void *dm_void, s8 power); + +void halrf_tssi_set_de_for_tx_verify(void *dm_void, u32 tssi_de, u8 path); + +u32 halrf_query_tssi_value(void *dm_void); + +void halrf_tssi_cck(void *dm_void); + +void halrf_thermal_cck(void *dm_void); + +void halrf_tssi_set_de(void *dm_void); + +void halrf_tssi_dck(void *dm_void, u8 direct_do); + +void halrf_calculate_tssi_codeword(void *dm_void); + +void halrf_set_tssi_codeword(void *dm_void); + +u8 halrf_get_tssi_codeword_for_txindex(void *dm_void); + +void halrf_tssi_clean_de(void *dm_void); + +u32 halrf_tssi_trigger_de(void *dm_void, u8 path); + +u32 halrf_tssi_get_de(void *dm_void, u8 path); + +u32 halrf_get_online_tssi_de(void *dm_void, u8 path, s32 pout); + +void halrf_tssi_trigger(void *dm_void); + +void halrf_txgapk_write_gain_table(void *dm_void); + +void halrf_txgapk_reload_tx_gain(void *dm_void); + +void halrf_txgap_enable_disable(void *dm_void, u8 enable); + +void halrf_set_dpk_track(void *dm_void, u8 enable); + +void halrf_set_dpkbychannel(void *dm_void, boolean dpk_by_ch); + +void halrf_set_dpkenable(void *dm_void, boolean is_dpk_enable); + +boolean halrf_get_dpkbychannel(void *dm_void); + +boolean halrf_get_dpkenable(void *dm_void); + +void _iqk_check_if_reload(void *dm_void); + +void halrf_do_rxbb_dck(void *dm_void); + +void config_halrf_path_adda_setting_trigger(void *dm_void); + +void halrf_reload_iqk(void *dm_void, boolean reset); + +void halrf_dack_dbg(void *dm_void); + +void halrf_dack_trigger(void *dm_void, boolean force); + +void halrf_dack_restore(void *dm_void); + +void halrf_iqk_info_rsvd_page(void *dm_void, u8 *buf, u32 *buf_size); + +void halrf_set_rfsupportability(void *dm_void); + +void halrf_rxdck(void *dm_void); + +void halrf_delay_10us(u16 v1); + +void halrf_dump_rfk_reg(void *dm_void, char input[][16], u32 *_used, + char *output, u32 *_out_len); + +void halrf_xtal_thermal_track(void *dm_void); + +void halrf_rfk_power_save(void *dm_void, boolean is_power_save); + +#endif /*__HALRF_H__*/ diff --git a/hal/phydm/halrf/halrf_debug.c b/hal/phydm/halrf/halrf_debug.c new file mode 100644 index 0000000..3f2d142 --- /dev/null +++ b/hal/phydm/halrf/halrf_debug.c @@ -0,0 +1,395 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +/*@************************************************************ + * include files + * ************************************************************ + */ + +#include "mp_precomp.h" +#include "phydm_precomp.h" + +void halrf_basic_profile(void *dm_void, u32 *_used, char *output, u32 *_out_len) +{ +#ifdef CONFIG_PHYDM_DEBUG_FUNCTION + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 used = *_used; + u32 out_len = *_out_len; + u32 rf_release_ver = 0; + + switch (dm->support_ic_type) { +#if (RTL8814A_SUPPORT) + case ODM_RTL8814A: + rf_release_ver = RF_RELEASE_VERSION_8814A; + break; +#endif + +#if (RTL8821C_SUPPORT) + case ODM_RTL8821C: + rf_release_ver = RF_RELEASE_VERSION_8821C; + break; +#endif + +#if (RTL8822B_SUPPORT) + case ODM_RTL8822B: + rf_release_ver = RF_RELEASE_VERSION_8822B; + break; +#endif + +#if (RTL8822C_SUPPORT) + case ODM_RTL8822C: + rf_release_ver = RF_RELEASE_VERSION_8822C; + break; +#endif + +#if (RTL8814B_SUPPORT) + case ODM_RTL8814B: + rf_release_ver = RF_RELEASE_VERSION_8814B; + break; +#endif + +#if (RTL8812F_SUPPORT) + case ODM_RTL8812F: + rf_release_ver = RF_RELEASE_VERSION_8812F; + break; +#endif + +#if (RTL8198F_SUPPORT) + case ODM_RTL8198F: + rf_release_ver = RF_RELEASE_VERSION_8198F; + break; +#endif + +#if (RTL8197F_SUPPORT) + case ODM_RTL8197F: + rf_release_ver = RF_RELEASE_VERSION_8197F; + break; +#endif + +#if (RTL8192F_SUPPORT) + case ODM_RTL8192F: + rf_release_ver = RF_RELEASE_VERSION_8192F; + break; +#endif + +#if (RTL8710B_SUPPORT) + case ODM_RTL8710B: + rf_release_ver = RF_RELEASE_VERSION_8710B; + break; +#endif + +#if (RTL8195B_SUPPORT) + case ODM_RTL8195B: + rf_release_ver = RF_RELEASE_VERSION_8195B; + break; +#endif + } + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-35s: %d\n", + "RF Para Release Ver", rf_release_ver); + + /* HAL RF version List */ + PDM_SNPF(out_len, used, output + used, out_len - used, "%-35s\n", + "% HAL RF version %"); + PDM_SNPF(out_len, used, output + used, out_len - used, " %-35s: %s\n", + "Power Tracking", HALRF_POWRTRACKING_VER); + PDM_SNPF(out_len, used, output + used, out_len - used, + " %-35s: %s %s\n", "IQK", + (dm->fw_offload_ability & PHYDM_RF_IQK_OFFLOAD) ? "FW" : + HALRF_IQK_VER, + (halrf_match_iqk_version(dm_void)) ? "(match)" : "(mismatch)"); + + PDM_SNPF(out_len, used, output + used, out_len - used, " %-35s: %s\n", + "LCK", HALRF_LCK_VER); + PDM_SNPF(out_len, used, output + used, out_len - used, " %-35s: %s\n", + "DPK", HALRF_DPK_VER); + PDM_SNPF(out_len, used, output + used, out_len - used, " %-35s: %s\n", + "TSSI", HALRF_TSSI_VER); + PDM_SNPF(out_len, used, output + used, out_len - used, " %-35s: %s\n", + "KFREE", HALRF_KFREE_VER); + PDM_SNPF(out_len, used, output + used, out_len - used, " %-35s: %s\n", + "TX 2G Current Calibration", HALRF_PABIASK_VER); + PDM_SNPF(out_len, used, output + used, out_len - used, " %-35s: %s\n", + "RFK Init. Parameter", HALRF_RFK_INIT_VER); + + *_used = used; + *_out_len = out_len; +#endif +} + +void halrf_debug_trace(void *dm_void, char input[][16], u32 *_used, + char *output, u32 *_out_len) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + u32 one = 1; + u32 used = *_used; + u32 out_len = *_out_len; + u32 rf_var[10] = {0}; + u8 i; + + for (i = 0; i < 5; i++) + if (input[i + 1]) + PHYDM_SSCANF(input[i + 2], DCMD_DECIMAL, &rf_var[i]); + + if (rf_var[0] == 100) { + PDM_SNPF(out_len, used, output + used, out_len - used, + "\n[DBG MSG] RF Selection\n"); + PDM_SNPF(out_len, used, output + used, out_len - used, + "00. (( %s ))TX_PWR_TRACK\n", + ((rf->rf_dbg_comp & DBG_RF_TX_PWR_TRACK) ? ("V") : + ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "01. (( %s ))IQK\n", + ((rf->rf_dbg_comp & DBG_RF_IQK) ? ("V") : ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "02. (( %s ))LCK\n", + ((rf->rf_dbg_comp & DBG_RF_LCK) ? ("V") : ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "03. (( %s ))DPK\n", + ((rf->rf_dbg_comp & DBG_RF_DPK) ? ("V") : ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "04. (( %s ))TXGAPK\n", + ((rf->rf_dbg_comp & DBG_RF_TXGAPK) ? ("V") : ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "06. (( %s ))DPK_TRACK\n", + ((rf->rf_dbg_comp & DBG_RF_DPK_TRACK) ? ("V") : ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "29. (( %s ))MP\n", + ((rf->rf_dbg_comp & DBG_RF_MP) ? ("V") : ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "30. (( %s ))TMP\n", + ((rf->rf_dbg_comp & DBG_RF_TMP) ? ("V") : ("."))); + PDM_SNPF(out_len, used, output + used, out_len - used, + "31. (( %s ))INIT\n", + ((rf->rf_dbg_comp & DBG_RF_INIT) ? ("V") : ("."))); + + } else if (rf_var[0] == 101) { + rf->rf_dbg_comp = 0; + PDM_SNPF(out_len, used, output + used, out_len - used, + "Disable all DBG COMP\n"); + } else { + if (rf_var[1] == 1) /*enable*/ + rf->rf_dbg_comp |= (one << rf_var[0]); + else if (rf_var[1] == 2) /*disable*/ + rf->rf_dbg_comp &= ~(one << rf_var[0]); + } + PDM_SNPF(out_len, used, output + used, out_len - used, + "\nCurr-RF_Dbg_Comp = 0x%x\n", rf->rf_dbg_comp); + + *_used = used; + *_out_len = out_len; +} + +void halrf_dack_debug_cmd(void *dm_void, char input[][16]) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + u32 dm_value[10] = {0}; + u8 i; + + for (i = 0; i < 7; i++) + if (input[i + 1]) + PHYDM_SSCANF(input[i + 2], DCMD_DECIMAL, &dm_value[i]); + + if (dm_value[0] == 1) + halrf_dack_trigger(dm, true); + else + halrf_dack_trigger(dm, false); +} + +struct halrf_command { + char name[16]; + u8 id; +}; + +enum halrf_CMD_ID { + HALRF_HELP, + HALRF_SUPPORTABILITY, + HALRF_DBG_COMP, + HALRF_PROFILE, + HALRF_IQK_INFO, + HALRF_IQK, + HALRF_IQK_DEBUG, + HALRF_DPK, + HALRF_DACK, + HALRF_DACK_DEBUG, + HALRF_DUMP_RFK_REG, +#ifdef CONFIG_2G_BAND_SHIFT + HAL_BAND_SHIFT, +#endif +}; + +struct halrf_command halrf_cmd_ary[] = { + {"-h", HALRF_HELP}, + {"ability", HALRF_SUPPORTABILITY}, + {"dbg", HALRF_DBG_COMP}, + {"profile", HALRF_PROFILE}, + {"iqk_info", HALRF_IQK_INFO}, + {"iqk", HALRF_IQK}, + {"iqk_dbg", HALRF_IQK_DEBUG}, + {"dpk", HALRF_DPK}, + {"dack", HALRF_DACK}, + {"dack_dbg", HALRF_DACK_DEBUG}, + {"dump_rfk_reg", HALRF_DUMP_RFK_REG}, +#ifdef CONFIG_2G_BAND_SHIFT + {"band_shift", HAL_BAND_SHIFT}, +#endif +}; + +void halrf_cmd_parser(void *dm_void, char input[][16], u32 *_used, char *output, + u32 *_out_len, u32 input_num) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; +#ifdef CONFIG_PHYDM_DEBUG_FUNCTION + u8 id = 0; + u32 rf_var[10] = {0}; + u32 i, input_idx = 0; + u32 halrf_ary_size = + sizeof(halrf_cmd_ary) / sizeof(struct halrf_command); + u32 used = *_used; + u32 out_len = *_out_len; + + /* Parsing Cmd ID */ + for (i = 0; i < halrf_ary_size; i++) { + if (strcmp(halrf_cmd_ary[i].name, input[1]) == 0) { + id = halrf_cmd_ary[i].id; + break; + } + } + + if (i == halrf_ary_size) { + PDM_SNPF(out_len, used, output + used, out_len - used, + "RF Cmd not found\n"); + return; + } + + switch (id) { + case HALRF_HELP: + PDM_SNPF(out_len, used, output + used, out_len - used, + "RF cmd ==>\n"); + + for (i = 0; i < halrf_ary_size - 1; i++) { + PDM_SNPF(out_len, used, output + used, out_len - used, + " %-5d: %s\n", i, halrf_cmd_ary[i + 1].name); + } + break; + case HALRF_SUPPORTABILITY: + halrf_support_ability_debug(dm, &input[0], &used, output, + &out_len); + break; +#ifdef CONFIG_2G_BAND_SHIFT + case HAL_BAND_SHIFT: + halrf_support_band_shift_debug(dm, &input[0], &used, output, + &out_len); + break; +#endif + case HALRF_DBG_COMP: + halrf_debug_trace(dm, &input[0], &used, output, &out_len); + break; + case HALRF_PROFILE: + halrf_basic_profile(dm, &used, output, &out_len); + break; + case HALRF_IQK_INFO: +#if (RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1) + halrf_iqk_info_dump(dm, &used, output, &out_len); +#endif + break; + case HALRF_IQK: + PDM_SNPF(out_len, used, output + used, out_len - used, + "TRX IQK Trigger\n"); + halrf_iqk_trigger(dm, false); +#if (RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1) + halrf_iqk_info_dump(dm, &used, output, &out_len); +#endif + break; + case HALRF_IQK_DEBUG: + PDM_SNPF(out_len, used, output + used, out_len - used, + "IQK DEBUG!!!!!\n"); + for (i = 0; i < 5; i++) { + if (input[i + 1]) { + PHYDM_SSCANF(input[i + 2], DCMD_HEX, + &rf_var[i]); + input_idx++; + } + } + + if (input_idx >= 1) { +#if (RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1 || RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & (ODM_RTL8822B | ODM_RTL8821C | ODM_RTL8822C | ODM_RTL8814B)) + halrf_iqk_debug(dm, (u32 *)rf_var, &used, + output, &out_len); +#endif + } + break; + case HALRF_DPK: + halrf_dpk_debug_cmd(dm, input, &used, output, &out_len); + break; + case HALRF_DACK: + PDM_SNPF(out_len, used, output + used, out_len - used, + "DACK Trigger\n"); + halrf_dack_debug_cmd(dm, &input[0]); + break; + case HALRF_DACK_DEBUG: + PDM_SNPF(out_len, used, output + used, out_len - used, + "DACK DEBUG\n"); + halrf_dack_dbg(dm); + break; + case HALRF_DUMP_RFK_REG: + halrf_dump_rfk_reg(dm, input, &used, output, &out_len); + break; + default: + break; + } + + *_used = used; + *_out_len = out_len; +#endif +} + +void halrf_init_debug_setting(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + rf->rf_dbg_comp = + + DBG_RF_RFK | +#if DBG +#if 1 + /*DBG_RF_TX_PWR_TRACK | */ + /*DBG_RF_IQK | */ + /*DBG_RF_LCK | */ + /*DBG_RF_DPK | */ + /*DBG_RF_TXGAPK | */ + /*DBG_RF_DACK | */ + /*DBG_RF_DPK_TRACK | */ + /*DBG_RF_MP | */ + /*DBG_RF_TMP | */ + /*DBG_RF_INIT | */ +#endif +#endif + 0; +} diff --git a/hal/phydm/halrf/halrf_debug.h b/hal/phydm/halrf/halrf_debug.h new file mode 100644 index 0000000..c13f3c5 --- /dev/null +++ b/hal/phydm/halrf/halrf_debug.h @@ -0,0 +1,140 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALRF_DEBUG_H__ +#define __HALRF_DEBUG_H__ + +/*@============================================================*/ +/*@include files*/ +/*@============================================================*/ + +/*@============================================================*/ +/*@Definition */ +/*@============================================================*/ + +#if DBG + +#if (DM_ODM_SUPPORT_TYPE == ODM_AP) +#define RF_DBG(dm, comp, fmt, args...) \ + do { \ + if ((comp) & dm->rf_table.rf_dbg_comp) { \ + pr_debug("[RF] "); \ + RT_PRINTK(fmt, ##args); \ + } \ + } while (0) + +#elif (DM_ODM_SUPPORT_TYPE == ODM_WIN) + +static __inline void RF_DBG(PDM_ODM_T dm, int comp, char *fmt, ...) +{ + RT_STATUS rt_status; + va_list args; + char buf[PRINT_MAX_SIZE] = {0}; + + if ((comp & dm->rf_table.rf_dbg_comp) == 0) + return; + + if (fmt == NULL) + return; + + va_start(args, fmt); + rt_status = (RT_STATUS)RtlStringCbVPrintfA(buf, PRINT_MAX_SIZE, fmt, args); + va_end(args); + + if (rt_status != RT_STATUS_SUCCESS) { + DbgPrint("Failed (%d) to print message to buffer\n", rt_status); + return; + } + + DbgPrint("[RF] %s", buf); +} + +#elif (DM_ODM_SUPPORT_TYPE == ODM_IOT) + +#define RF_DBG(dm, comp, fmt, args...) \ + do { \ + if ((comp) & dm->rf_table.rf_dbg_comp) { \ + RT_DEBUG(COMP_PHYDM, DBG_DMESG, "[RF] " fmt, ##args); \ + } \ + } while (0) + +#else +#define RF_DBG(dm, comp, fmt, args...) \ + do { \ + struct dm_struct *__dm = dm; \ + if ((comp) & __dm->rf_table.rf_dbg_comp) { \ + RT_TRACE(((struct rtl_priv *)__dm->adapter), \ + COMP_PHYDM, DBG_DMESG, "[RF] " fmt, ##args); \ + } \ + } while (0) +#endif + +#else /*#if DBG*/ + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) +static __inline void RF_DBG(struct dm_struct *dm, int comp, char *fmt, ...) +{ +#if 0 + RT_STATUS rt_status; + va_list args; + char buf[128] = {0};/*PRINT_MAX_SIZE*/ + + if ((comp & dm->rf_table.rf_dbg_comp) == 0) + return; + + if (NULL != fmt) { + va_start(args, fmt); + rt_status = (RT_STATUS)RtlStringCbVPrintfA(buf, sizeof(buf), fmt, args); + va_end(args); + if (rt_status == RT_STATUS_SUCCESS) { + halrf_rt_trace(buf); + } + } +#endif +} +#else +#define RF_DBG(dm, comp, fmt, args...) +#endif + +#endif /*#if DBG*/ + +/*@============================================================*/ +/*@ enumeration */ +/*@============================================================*/ + +/*@============================================================*/ +/*@ structure */ +/*@============================================================*/ + +/*@============================================================*/ +/*@ function prototype */ +/*@============================================================*/ + +void halrf_cmd_parser(void *dm_void, char input[][16], u32 *_used, char *output, + u32 *_out_len, u32 input_num); + +void halrf_init_debug_setting(void *dm_void); + +#endif /*__HALRF_H__*/ diff --git a/hal/phydm/halrf/halrf_dpk.h b/hal/phydm/halrf/halrf_dpk.h new file mode 100644 index 0000000..cb7dc4e --- /dev/null +++ b/hal/phydm/halrf/halrf_dpk.h @@ -0,0 +1,163 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALRF_DPK_H__ +#define __HALRF_DPK_H__ + +/*@--------------------------Define Parameters-------------------------------*/ +#define GAIN_LOSS 1 +#define DO_DPK 2 +#define DPK_ON 3 +#define GAIN_LOSS_PULSE 4 +#define DPK_PAS 5 +#define DPK_LMS 6 +#define DPK_LOK 4 +#define DPK_TXK 5 +#define DAGC 4 +#define LOSS_CHK 0 +#define GAIN_CHK 1 +#define PAS_READ 2 +#define AVG_THERMAL_NUM 8 +#define AVG_THERMAL_NUM_DPK 8 +#define THERMAL_DPK_AVG_NUM 4 + +/*define RF path numer*/ +#if (RTL8198F_SUPPORT == 1 || RTL8814B_SUPPORT == 1) +#define KPATH 4 +#elif (RTL8192F_SUPPORT == 1 || RTL8197F_SUPPORT == 1 ||RTL8197G_SUPPORT == 1 ||\ + RTL8822C_SUPPORT == 1 || RTL8812F_SUPPORT == 1 || RTL8723F_SUPPORT == 1) +#define KPATH 2 +#else +#define KPATH 1 +#endif + +#if (RTL8814B_SUPPORT == 1 || RTL8721D_SUPPORT == 1) +#define GROUP_5G 6 +#elif (RTL8195B_SUPPORT == 1) +#define GROUP_5G 13 +#endif + +/*@---------------------------End Define Parameters---------------------------*/ + +struct dm_dpk_info { + + boolean is_dpk_enable; + boolean is_dpk_pwr_on; + boolean is_dpk_by_channel; + boolean is_tssi_mode; + u8 dpk_status; /*bit[0]:reload;bit[1]:cal;bit[2]:cal_ok*/ + u16 dpk_path_ok; + /*@BIT(15)~BIT(12) : 5G reserved, BIT(11)~BIT(8) 5G_S3~5G_S0*/ + /*@BIT(7)~BIT(4) : 2G reserved, BIT(3)~BIT(0) 2G_S3~2G_S0*/ + u8 thermal_dpk[KPATH]; /*path*/ + u8 thermal_dpk_avg[KPATH][AVG_THERMAL_NUM_DPK]; /*path*/ + u8 pre_pwsf[KPATH]; + u8 thermal_dpk_avg_index; + u32 gnt_control; + u32 gnt_value; + u8 dpk_ch; + u8 dpk_band; + u8 dpk_bw; + u32 dpk_rf18[2]; + u32 dpk_cal_cnt; + u32 dpk_ok_cnt; + u32 dpk_reload_cnt; + +#if (RTL8822C_SUPPORT == 1 || RTL8812F_SUPPORT == 1 || RTL8197G_SUPPORT == 1) + u16 dc_i[2]; /*MDPD DC I path*/ + u16 dc_q[2]; /*MDPD DC Q path*/ + u8 corr_val[2]; /*Corr value path*/ + u8 corr_idx[2]; /*Corr index path*/ +#endif + +#if (RTL8822C_SUPPORT == 1 || RTL8812F_SUPPORT == 1) + u8 result[2]; /*path*/ + u8 dpk_txagc[2]; /*path*/ + u32 coef[2][20]; /*path/MDPD coefficient*/ + u16 dpk_gs[2]; /*MDPD coef gs*/ + u8 thermal_dpk_delta[2]; /*path*/ +#endif + +#if (RTL8198F_SUPPORT == 1 || RTL8192F_SUPPORT == 1 || RTL8197F_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1 || RTL8197G_SUPPORT == 1) + /*2G DPK data*/ + u8 dpk_result[KPATH][3]; /*path/group*/ + u8 pwsf_2g[KPATH][3]; /*path/group*/ + u32 lut_2g_even[KPATH][3][64]; /*path/group/LUT data*/ + u32 lut_2g_odd[KPATH][3][64]; /*path/group/LUT data*/ + s16 tmp_pas_i[32]; /*PAScan I data*/ + s16 tmp_pas_q[32]; /*PAScan Q data*/ +#endif + +#if (RTL8814B_SUPPORT == 1) + /*5G DPK data*/ + u8 dpk_5g_result[KPATH][GROUP_5G]; /*path/group*/ + u8 pwsf_5g[KPATH][GROUP_5G]; /*path/group*/ + u32 lut_5g[KPATH][GROUP_5G][64]; /*path/group/LUT data*/ + u32 lut_2g[KPATH][3][64]; /*path/group/LUT data*/ + u8 rxbb[4]; /*path/group*/ + u8 txbb[4]; /*path/group*/ + u8 tx_gain; +#endif + +#if (RTL8195B_SUPPORT == 1 || RTL8721D_SUPPORT == 1) + u8 dpk_txagc; + /*2G DPK data*/ + u8 dpk_2g_result[KPATH][3]; /*path/group*/ + u8 pwsf_2g[KPATH][3]; /*path/group*/ + u32 lut_2g_even[KPATH][3][16]; /*path/group/LUT data*/ + u32 lut_2g_odd[KPATH][3][16]; /*path/group/LUT data*/ + /*5G DPK data*/ + u8 dpk_5g_result[KPATH][GROUP_5G]; /*path/group*/ + u8 pwsf_5g[KPATH][GROUP_5G]; /*path/group*/ + u32 lut_5g_even[KPATH][GROUP_5G][16]; /*path/group/LUT data*/ + u32 lut_5g_odd[KPATH][GROUP_5G][16]; /*path/group/LUT data*/ +#endif + +#if(RTL8723F_SUPPORT == 1) + u8 one_shot_cnt; + u8 dpk_current_path; + u8 thermal_init[KPATH]; + u8 dpk_delta_thermal[KPATH]; /*path*/ + s8 last_offset[KPATH]; /*path*/ + u8 txagc[KPATH]; /*path*/ + u8 tssi_txagc[KPATH][2]; /*path/0:txagc_rf,1:tssi_offset*/ + u16 digital_bbgain[KPATH]; /*path*/ + u16 pwsf[KPATH]; /*path*/ + +#endif +}; + +#if (RTL8822C_SUPPORT == 1) +struct dm_dpk_c2h_report { + u8 result[2]; /*ch0_result/ch1_result*/ + u8 therm[2][2]; /*therm0_s0/therm0_s1/therm1_s0/therm1_s1*/ + u8 therm_delta[2][2]; /*therm_delta0_s0/therm_delta0_s1/therm_delta1_s0/therm_delta1_s1*/ + u32 dpk_rf18[2]; /*dpk_ch0/dpk_ch1*/ + u8 dpk_status; /*dpk_status*/ +}; +#endif + +#endif /*__HALRF_DPK_H__*/ diff --git a/hal/phydm/halrf/halrf_features.h b/hal/phydm/halrf/halrf_features.h new file mode 100644 index 0000000..da97614 --- /dev/null +++ b/hal/phydm/halrf/halrf_features.h @@ -0,0 +1,43 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALRF_FEATURES_H__ +#define __HALRF_FEATURES_H__ + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + +#define CONFIG_HALRF_POWERTRACKING 1 + +#elif (DM_ODM_SUPPORT_TYPE == ODM_AP) + +#define CONFIG_HALRF_POWERTRACKING 1 + +#elif (DM_ODM_SUPPORT_TYPE == ODM_CE) + +#define CONFIG_HALRF_POWERTRACKING 1 + +#endif + +#endif /*#ifndef __HALRF_FEATURES_H__*/ diff --git a/hal/phydm/halrf/halrf_iqk.h b/hal/phydm/halrf/halrf_iqk.h new file mode 100644 index 0000000..8a37d01 --- /dev/null +++ b/hal/phydm/halrf/halrf_iqk.h @@ -0,0 +1,157 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALRF_IQK_H__ +#define __HALRF_IQK_H__ + +/*@--------------------------Define Parameters-------------------------------*/ +#define LOK_delay 1 +#define WBIQK_delay 10 +#define TX_IQK 0 +#define RX_IQK 1 +#define TXIQK 0 +#define RXIQK1 1 +#define RXIQK2 2 +#define kcount_limit_80m 2 +#define kcount_limit_others 4 +#define rxiqk_gs_limit 6 +#define TXWBIQK_EN 1 +#define RXWBIQK_EN 1 +#if (RTL8814A_SUPPORT == 1 || RTL8198F_SUPPORT == 1 ||\ + RTL8814B_SUPPORT) +#define NUM 4 +#elif (RTL8822B_SUPPORT == 1 || RTL8822C_SUPPORT == 1 ||\ + RTL8812F_SUPPORT == 1 || RTL8197G_SUPPORT == 1 ||\ + RTL8723F_SUPPORT == 1) +#define NUM 2 +#else +#define NUM 1 +#endif + +/*@-----------------------End Define Parameters-----------------------*/ + +struct dm_dack_info { + boolean dack_en; + u16 msbk_d[2][2][15]; + u8 dck_d[2][2][2]; + u16 biask_d[2][2]; +}; + +struct dm_iqk_info { + boolean lok_fail[NUM]; + boolean iqk_fail[2][NUM]; + u32 iqc_matrix[2][NUM]; + u8 iqk_times; + u32 rf_reg18; + u32 rf_reg08; + u32 lna_idx; + u8 iqk_step; + u8 rxiqk_step; + u8 tmp1bcc; + u8 txgain; + u32 txgain56; + u8 kcount; + u8 rfk_ing; /*bit0:IQKing, bit1:LCKing, bit2:DPKing*/ + boolean rfk_forbidden; + u8 rxbb; + u32 rf_reg58; + boolean segment_iqk; + boolean is_tssi_mode; + u8 iqk_band; + u8 iqk_ch; + u8 iqk_bw; +#if (RTL8814A_SUPPORT == 1 || RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1 ||\ + RTL8195B_SUPPORT == 1 || RTL8198F_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1 || RTL8822C_SUPPORT == 1 ||\ + RTL8812F_SUPPORT == 1 || RTL8197G_SUPPORT == 1 ||\ + RTL8710C_SUPPORT == 1 || RTL8723F_SUPPORT == 1) + u32 iqk_channel[2]; + boolean iqk_fail_report[2][NUM][2]; /*channel/path/TRX(TX:0, RX:1) */ + /*channel / path / TRX(TX:0, RX:1) / CFIR_real*/ + /*channel index = 2 is just for debug*/ +#if (RTL8814B_SUPPORT == 1) + u16 iqk_cfir_real[3][NUM][2][19]; + u16 iqk_cfir_imag[3][NUM][2][19]; +#elif (RTL8812F_SUPPORT == 1 || RTL8822C_SUPPORT == 1 ) + u16 iqk_cfir_real[3][2][2][17]; + /*channel / path / TRX(TX:0, RX:1) / CFIR_imag*/ + /*channel index = 2 is just for debug*/ + u16 iqk_cfir_imag[3][2][2][17]; + /*times/path*/ +#elif (RTL8195B_SUPPORT == 1) + u32 iqk_cfir_real[3][NUM][2][9]; + u32 iqk_cfir_imag[3][NUM][2][9]; + /*channel / path / TRX(TX:0, RX:1) / CFIR_imag*/ + /*channel index = 2 is just for debug*/ +#else + u32 iqk_cfir_real[3][NUM][2][8]; + /*channel / path / TRX(TX:0, RX:1) / CFIR_imag*/ + /*channel index = 2 is just for debug*/ + u32 iqk_cfir_imag[3][NUM][2][8]; +#endif + +#if (RTL8812F_SUPPORT == 1 || RTL8822C_SUPPORT == 1 ) + u32 rx_cfir_real[2][2][17]; + u32 rx_cfir_imag[2][2][17]; + u32 rx_cfir[2][2]; +#endif + u8 retry_count[2][NUM][3]; /* channel / path / (TXK:0, RXK1:1, RXK2:2) */ + u8 gs_retry_count[2][NUM][2]; /* channel / path / (GSRXK1:0, GSRXK2:1) */ + /* channel / path 0:SRXK1 fail, 1:RXK1 fail 2:RXK2 fail */ + u8 rxiqk_fail_code[2][NUM]; + u32 lok_idac[2][NUM]; /*channel / path*/ + u16 rxiqk_agc[2][NUM]; /*channel / path*/ + u32 bypass_iqk[2][NUM]; /*channel / 0xc94/0xe94*/ + u32 txgap_result[8]; /*txagpK result */ + u32 tmp_gntwl; + boolean is_btg; + boolean isbnd; + boolean is_reload; + boolean is_hwtx; + boolean xym_read; + boolean trximr_enable; +#if (RTL8822B_SUPPORT == 1 || RTL8821C_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1 || RTL8822C_SUPPORT == 1) + u32 rx_xym[2][10]; + u32 tx_xym[2][10]; + u32 gs1_xym[2][6]; + u32 gs2_xym[2][6]; + u32 rxk1_xym[2][6]; + u32 nbtxk_1b38[2]; + u32 nbrxk_1b3c[2]; +#endif +#if (RTL8710C_SUPPORT == 1 || RTL8197G_SUPPORT == 1 ) + u32 txxy[2][2]; + u32 rxxy[2][2]; +#endif +#if (RTL8723F_SUPPORT == 1) + u32 txxy[2][2]; + u32 rxxy[2][2][2]; +#endif + +#endif +}; + +#endif /*__HALRF_IQK_H__*/ diff --git a/hal/phydm/halrf/halrf_kfree.c b/hal/phydm/halrf/halrf_kfree.c new file mode 100644 index 0000000..71a49dd --- /dev/null +++ b/hal/phydm/halrf/halrf_kfree.c @@ -0,0 +1,3958 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +/*@============================================================*/ +/*@include files*/ +/*@============================================================*/ +#include "mp_precomp.h" +#include "phydm_precomp.h" + +/*@ Add for KFree Feature Requested by RF David.*/ +/*@This is a phydm API*/ + +void phydm_set_kfree_to_rf_8814a(void *dm_void, u8 e_rf_path, u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + boolean is_odd; + u32 tx_gain_bitmask = (BIT(17) | BIT(16) | BIT(15)); + + if ((data % 2) != 0) { /*odd->positive*/ + data = data - 1; + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(19), 1); + is_odd = true; + } else { /*even->negative*/ + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(19), 0); + is_odd = false; + } + RF_DBG(dm, DBG_RF_MP, "phy_ConfigKFree8814A(): RF_0x55[19]= %d\n", + is_odd); + switch (data) { + case 0: + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(14), 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, tx_gain_bitmask, 0); + cali_info->kfree_offset[e_rf_path] = 0; + break; + case 2: + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(14), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, tx_gain_bitmask, 0); + cali_info->kfree_offset[e_rf_path] = 0; + break; + case 4: + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(14), 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, tx_gain_bitmask, 1); + cali_info->kfree_offset[e_rf_path] = 1; + break; + case 6: + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(14), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, tx_gain_bitmask, 1); + cali_info->kfree_offset[e_rf_path] = 1; + break; + case 8: + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(14), 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, tx_gain_bitmask, 2); + cali_info->kfree_offset[e_rf_path] = 2; + break; + case 10: + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(14), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, tx_gain_bitmask, 2); + cali_info->kfree_offset[e_rf_path] = 2; + break; + case 12: + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(14), 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, tx_gain_bitmask, 3); + cali_info->kfree_offset[e_rf_path] = 3; + break; + case 14: + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(14), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, tx_gain_bitmask, 3); + cali_info->kfree_offset[e_rf_path] = 3; + break; + case 16: + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(14), 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, tx_gain_bitmask, 4); + cali_info->kfree_offset[e_rf_path] = 4; + break; + case 18: + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(14), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, tx_gain_bitmask, 4); + cali_info->kfree_offset[e_rf_path] = 4; + break; + case 20: + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(14), 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, tx_gain_bitmask, 5); + cali_info->kfree_offset[e_rf_path] = 5; + break; + + default: + break; + } + + if (!is_odd) { + /*that means Kfree offset is negative, we need to record it.*/ + cali_info->kfree_offset[e_rf_path] = + (-1) * cali_info->kfree_offset[e_rf_path]; + RF_DBG(dm, DBG_RF_MP, + "phy_ConfigKFree8814A(): kfree_offset = %d\n", + cali_info->kfree_offset[e_rf_path]); + } else { + RF_DBG(dm, DBG_RF_MP, + "phy_ConfigKFree8814A(): kfree_offset = %d\n", + cali_info->kfree_offset[e_rf_path]); + } +} + +void phydm_get_thermal_trim_offset_8821c(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0xff; + + odm_efuse_one_byte_read(dm, PPG_THERMAL_OFFSET_21C, &pg_therm, false); + + if (pg_therm != 0xff) { + pg_therm = pg_therm & 0x1f; + if ((pg_therm & BIT(0)) == 0) + power_trim_info->thermal = (-1 * (pg_therm >> 1)); + else + power_trim_info->thermal = (pg_therm >> 1); + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8821c thermal trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8821c thermal:%d\n", + power_trim_info->thermal); +} + +void phydm_get_power_trim_offset_8821c(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_power = 0xff, i; + + odm_efuse_one_byte_read(dm, PPG_2G_TXAB_21C, &pg_power, false); + + if (pg_power != 0xff) { + power_trim_info->bb_gain[0][0] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_21C, &pg_power, false); + power_trim_info->bb_gain[1][0] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GL2_TXA_21C, &pg_power, false); + power_trim_info->bb_gain[2][0] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GM1_TXA_21C, &pg_power, false); + power_trim_info->bb_gain[3][0] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GM2_TXA_21C, &pg_power, false); + power_trim_info->bb_gain[4][0] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GH1_TXA_21C, &pg_power, false); + power_trim_info->bb_gain[5][0] = pg_power; + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | + KFREE_FLAG_ON_2G | KFREE_FLAG_ON_5G; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8821c power trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8821c pwr_trim->bb_gain[%d][0]=0x%X\n", + i, power_trim_info->bb_gain[i][0]); + } +} + +void phydm_set_kfree_to_rf_8821c(void *dm_void, u8 e_rf_path, boolean wlg_btg, + u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u8 wlg, btg; + u32 gain_bmask = (BIT(18) | BIT(17) | BIT(16) | BIT(15) | BIT(14)); + u32 s_gain_bmask = (BIT(19) | BIT(18) | BIT(17) | + BIT(16) | BIT(15) | BIT(14)); + + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(0), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(5), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(6), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x65, BIT(6), 1); + + if (wlg_btg) { + wlg = data & 0xf; + btg = (data & 0xf0) >> 4; + + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(19), (wlg & BIT(0))); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, gain_bmask, (wlg >> 1)); + + odm_set_rf_reg(dm, e_rf_path, RF_0x65, BIT(19), (btg & BIT(0))); + odm_set_rf_reg(dm, e_rf_path, RF_0x65, gain_bmask, (btg >> 1)); + } else { + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(19), data & BIT(0)); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, gain_bmask, + ((data & 0x1f) >> 1)); + } + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8821c 0x55[19:14]=0x%X 0x65[19:14]=0x%X\n", + odm_get_rf_reg(dm, e_rf_path, RF_0x55, s_gain_bmask), + odm_get_rf_reg(dm, e_rf_path, RF_0x65, s_gain_bmask)); +} + +void phydm_clear_kfree_to_rf_8821c(void *dm_void, u8 e_rf_path, u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 gain_bmask = (BIT(18) | BIT(17) | BIT(16) | BIT(15) | BIT(14)); + u32 s_gain_bmask = (BIT(19) | BIT(18) | BIT(17) | + BIT(16) | BIT(15) | BIT(14)); + + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(0), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(5), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(6), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x65, BIT(6), 1); + + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(19), (data & BIT(0))); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, gain_bmask, (data >> 1)); + + odm_set_rf_reg(dm, e_rf_path, RF_0x65, BIT(19), (data & BIT(0))); + odm_set_rf_reg(dm, e_rf_path, RF_0x65, gain_bmask, (data >> 1)); + + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(0), 0); + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(5), 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(6), 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x65, BIT(6), 0); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8821c 0x55[19:14]=0x%X 0x65[19:14]=0x%X\n", + odm_get_rf_reg(dm, e_rf_path, RF_0x55, s_gain_bmask), + odm_get_rf_reg(dm, e_rf_path, RF_0x65, s_gain_bmask)); +} + +void phydm_get_thermal_trim_offset_8822b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0xff; + + odm_efuse_one_byte_read(dm, PPG_THERMAL_OFFSET_22B, &pg_therm, false); + + if (pg_therm != 0xff) { + pg_therm = pg_therm & 0x1f; + if ((pg_therm & BIT(0)) == 0) + power_trim_info->thermal = (-1 * (pg_therm >> 1)); + else + power_trim_info->thermal = (pg_therm >> 1); + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822b thermal trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822b thermal:%d\n", + power_trim_info->thermal); +} + +void phydm_get_power_trim_offset_8822b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_power = 0xff, i, j; + + odm_efuse_one_byte_read(dm, PPG_2G_TXAB_22B, &pg_power, false); + + if (pg_power != 0xff) { + /*Path A*/ + odm_efuse_one_byte_read(dm, PPG_2G_TXAB_22B, &pg_power, false); + power_trim_info->bb_gain[0][0] = (pg_power & 0xf); + + /*Path B*/ + odm_efuse_one_byte_read(dm, PPG_2G_TXAB_22B, &pg_power, false); + power_trim_info->bb_gain[0][1] = ((pg_power & 0xf0) >> 4); + + power_trim_info->flag |= KFREE_FLAG_ON_2G; + power_trim_info->flag |= KFREE_FLAG_ON; + } + + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_22B, &pg_power, false); + + if (pg_power != 0xff) { + /*Path A*/ + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_22B, &pg_power, false); + power_trim_info->bb_gain[1][0] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GL2_TXA_22B, &pg_power, false); + power_trim_info->bb_gain[2][0] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GM1_TXA_22B, &pg_power, false); + power_trim_info->bb_gain[3][0] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GM2_TXA_22B, &pg_power, false); + power_trim_info->bb_gain[4][0] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GH1_TXA_22B, &pg_power, false); + power_trim_info->bb_gain[5][0] = pg_power; + + /*Path B*/ + odm_efuse_one_byte_read(dm, PPG_5GL1_TXB_22B, &pg_power, false); + power_trim_info->bb_gain[1][1] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GL2_TXB_22B, &pg_power, false); + power_trim_info->bb_gain[2][1] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GM1_TXB_22B, &pg_power, false); + power_trim_info->bb_gain[3][1] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GM2_TXB_22B, &pg_power, false); + power_trim_info->bb_gain[4][1] = pg_power; + odm_efuse_one_byte_read(dm, PPG_5GH1_TXB_22B, &pg_power, false); + power_trim_info->bb_gain[5][1] = pg_power; + + power_trim_info->flag |= KFREE_FLAG_ON_5G; + power_trim_info->flag |= KFREE_FLAG_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822b power trim flag:0x%02x\n", + power_trim_info->flag); + + if (!(power_trim_info->flag & KFREE_FLAG_ON)) + return; + + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < 2; j++) + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8822b PwrTrim->bb_gain[%d][%d]=0x%X\n", + i, j, power_trim_info->bb_gain[i][j]); + } +} + +void phydm_set_pa_bias_to_rf_8822b(void *dm_void, u8 e_rf_path, s8 tx_pa_bias) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 rf_reg_51 = 0, rf_reg_52 = 0, rf_reg_3f = 0; + u32 tx_pa_bias_bmask = (BIT(12) | BIT(11) | BIT(10) | BIT(9)); + + rf_reg_51 = odm_get_rf_reg(dm, e_rf_path, RF_0x51, RFREGOFFSETMASK); + rf_reg_52 = odm_get_rf_reg(dm, e_rf_path, RF_0x52, RFREGOFFSETMASK); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8822b 2g rf(0x51)=0x%X rf(0x52)=0x%X path=%d\n", + rf_reg_51, rf_reg_52, e_rf_path); + +#if 0 + /*rf3f => rf52[19:17] = rf3f[2:0] rf52[16:15] = rf3f[4:3] rf52[3:0] = rf3f[8:5]*/ + /*rf3f => rf51[6:3] = rf3f[12:9] rf52[13] = rf3f[13]*/ +#endif + rf_reg_3f = ((rf_reg_52 & 0xe0000) >> 17) | + (((rf_reg_52 & 0x18000) >> 15) << 3) | + ((rf_reg_52 & 0xf) << 5) | + (((rf_reg_51 & 0x78) >> 3) << 9) | + (((rf_reg_52 & 0x2000) >> 13) << 13); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8822b 2g original pa_bias=%d rf_reg_3f=0x%X path=%d\n", + tx_pa_bias, rf_reg_3f, e_rf_path); + + tx_pa_bias = (s8)((rf_reg_3f & tx_pa_bias_bmask) >> 9) + tx_pa_bias; + + if (tx_pa_bias < 0) + tx_pa_bias = 0; + else if (tx_pa_bias > 7) + tx_pa_bias = 7; + + rf_reg_3f = ((rf_reg_3f & 0xfe1ff) | (tx_pa_bias << 9)); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8822b 2g 0x%X 0x%X pa_bias=%d rfreg_3f=0x%X path=%d\n", + PPG_PABIAS_2GA_22B, PPG_PABIAS_2GB_22B, + tx_pa_bias, rf_reg_3f, e_rf_path); + + odm_set_rf_reg(dm, e_rf_path, RF_0xef, BIT(10), 0x1); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x0); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, rf_reg_3f); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, BIT(0), 0x1); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, rf_reg_3f); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, BIT(1), 0x1); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, rf_reg_3f); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, (BIT(1) | BIT(0)), 0x3); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, rf_reg_3f); + odm_set_rf_reg(dm, e_rf_path, RF_0xef, BIT(10), 0x0); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8822b 2g tx pa bias rf_0x3f(0x%X) path=%d\n", + odm_get_rf_reg(dm, e_rf_path, RF_0x3f, + (BIT(12) | BIT(11) | BIT(10) | BIT(9))), + e_rf_path); +} + +void phydm_get_pa_bias_offset_8822b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_pa_bias = 0xff, e_rf_path = 0; + s8 tx_pa_bias[2] = {0}; + + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GA_22B, &pg_pa_bias, false); + + if (pg_pa_bias != 0xff) { + /*paht a*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GA_22B, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + if ((pg_pa_bias & BIT(0)) == 0) + tx_pa_bias[0] = (-1 * (pg_pa_bias >> 1)); + else + tx_pa_bias[0] = (pg_pa_bias >> 1); + + /*paht b*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GB_22B, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + if ((pg_pa_bias & BIT(0)) == 0) + tx_pa_bias[1] = (-1 * (pg_pa_bias >> 1)); + else + tx_pa_bias[1] = (pg_pa_bias >> 1); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8822b 2g PathA_pa_bias:%d PathB_pa_bias:%d\n", + tx_pa_bias[0], tx_pa_bias[1]); + + for (e_rf_path = RF_PATH_A; e_rf_path < 2; e_rf_path++) + phydm_set_pa_bias_to_rf_8822b(dm, e_rf_path, + tx_pa_bias[e_rf_path]); + + power_trim_info->pa_bias_flag |= PA_BIAS_FLAG_ON; + } else { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822b 2g tx pa bias no pg\n"); + } +} + +void phydm_set_kfree_to_rf_8822b(void *dm_void, u8 e_rf_path, u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 gain_bmask = (BIT(18) | BIT(17) | BIT(16) | BIT(15) | BIT(14)); + + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(0), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(4), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x65, MASKLWORD, 0x9000); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(5), 1); + + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(19), (data & BIT(0))); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, gain_bmask, + ((data & 0x1f) >> 1)); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822b 0x55[19:14]=0x%X path=%d\n", + odm_get_rf_reg(dm, e_rf_path, RF_0x55, + (BIT(19) | BIT(18) | BIT(17) | BIT(16) | + BIT(15) | BIT(14))), e_rf_path); +} + +void phydm_clear_kfree_to_rf_8822b(void *dm_void, u8 e_rf_path, u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 gain_bmask = (BIT(18) | BIT(17) | BIT(16) | BIT(15) | BIT(14)); + + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(0), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(4), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x65, MASKLWORD, 0x9000); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(5), 1); + + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(19), (data & BIT(0))); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, gain_bmask, + ((data & 0x1f) >> 1)); + + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(0), 0); + odm_set_rf_reg(dm, e_rf_path, RF_0xde, BIT(4), 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x65, MASKLWORD, 0x9000); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(5), 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(7), 0); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8822b clear power trim 0x55[19:14]=0x%X path=%d\n", + odm_get_rf_reg(dm, e_rf_path, RF_0x55, + (BIT(19) | BIT(18) | BIT(17) | BIT(16) | + BIT(15) | BIT(14))), e_rf_path); +} + +void phydm_get_thermal_trim_offset_8710b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0xff; + + odm_efuse_one_byte_read(dm, 0x0EF, &pg_therm, false); + + if (pg_therm != 0xff) { + pg_therm = pg_therm & 0x1f; + if ((pg_therm & BIT(0)) == 0) + power_trim_info->thermal = (-1 * (pg_therm >> 1)); + else + power_trim_info->thermal = (pg_therm >> 1); + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8710b thermal trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8710b thermal:%d\n", + power_trim_info->thermal); +} + +void phydm_get_power_trim_offset_8710b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_power = 0xff; + + odm_efuse_one_byte_read(dm, 0xEE, &pg_power, false); + + if (pg_power != 0xff) { + /*Path A*/ + odm_efuse_one_byte_read(dm, 0xEE, &pg_power, false); + power_trim_info->bb_gain[0][0] = (pg_power & 0xf); + + power_trim_info->flag |= KFREE_FLAG_ON_2G; + power_trim_info->flag |= KFREE_FLAG_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8710b power trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_ON) + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8710b power_trim_data->bb_gain[0][0]=0x%X\n", + power_trim_info->bb_gain[0][0]); +} + +void phydm_set_kfree_to_rf_8710b(void *dm_void, u8 e_rf_path, u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 gain_bmask = (BIT(18) | BIT(17) | BIT(16) | BIT(15)); + + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(19), (data & BIT(0))); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, gain_bmask, ((data & 0xf) >> 1)); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8710b 0x55[19:14]=0x%X path=%d\n", + odm_get_rf_reg(dm, e_rf_path, RF_0x55, + (BIT(19) | BIT(18) | BIT(17) | BIT(16) | + BIT(15) | BIT(14))), e_rf_path); +} + +void phydm_clear_kfree_to_rf_8710b(void *dm_void, u8 e_rf_path, u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u32 gain_bmask = (BIT(18) | BIT(17) | BIT(16) | BIT(15) | BIT(14)); + + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(19), (data & BIT(0))); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, gain_bmask, + ((data & 0x1f) >> 1)); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8710b clear power trim 0x55[19:14]=0x%X path=%d\n", + odm_get_rf_reg(dm, e_rf_path, RF_0x55, + (BIT(19) | BIT(18) | BIT(17) | BIT(16) | + BIT(15) | BIT(14))), e_rf_path); +} + +void phydm_get_thermal_trim_offset_8192f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0xff; + + odm_efuse_one_byte_read(dm, 0x1EF, &pg_therm, false); + + if (pg_therm != 0xff) { + pg_therm = pg_therm & 0x1f; + if ((pg_therm & BIT(0)) == 0) + power_trim_info->thermal = (-1 * (pg_therm >> 1)); + else + power_trim_info->thermal = (pg_therm >> 1); + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8192f thermal trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8192f thermal:%d\n", + power_trim_info->thermal); +} + +void phydm_get_power_trim_offset_8192f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_power1 = 0xff, pg_power2 = 0xff, pg_power3 = 0xff, i, j; + + odm_efuse_one_byte_read(dm, 0x1EE, &pg_power1, false); /*CH4-9*/ + + if (pg_power1 != 0xff) { + /*Path A*/ + odm_efuse_one_byte_read(dm, 0x1EE, &pg_power1, false); + power_trim_info->bb_gain[1][0] = (pg_power1 & 0xf); + /*Path B*/ + odm_efuse_one_byte_read(dm, 0x1EE, &pg_power1, false); + power_trim_info->bb_gain[1][1] = ((pg_power1 & 0xf0) >> 4); + + power_trim_info->flag |= KFREE_FLAG_ON_2G; + power_trim_info->flag |= KFREE_FLAG_ON; + } + + odm_efuse_one_byte_read(dm, 0x1EC, &pg_power2, false); /*CH1-3*/ + + if (pg_power2 != 0xff) { + /*Path A*/ + odm_efuse_one_byte_read(dm, 0x1EC, &pg_power2, false); + power_trim_info->bb_gain[0][0] = (pg_power2 & 0xf); + /*Path B*/ + odm_efuse_one_byte_read(dm, 0x1EC, &pg_power2, false); + power_trim_info->bb_gain[0][1] = ((pg_power2 & 0xf0) >> 4); + + power_trim_info->flag |= KFREE_FLAG_ON_2G; + power_trim_info->flag |= KFREE_FLAG_ON; + } else { + power_trim_info->bb_gain[0][0] = (pg_power1 & 0xf); + power_trim_info->bb_gain[0][1] = ((pg_power1 & 0xf0) >> 4); + } + + odm_efuse_one_byte_read(dm, 0x1EA, &pg_power3, false); /*CH10-14*/ + + if (pg_power3 != 0xff) { + /*Path A*/ + odm_efuse_one_byte_read(dm, 0x1EA, &pg_power3, false); + power_trim_info->bb_gain[2][0] = (pg_power3 & 0xf); + /*Path B*/ + odm_efuse_one_byte_read(dm, 0x1EA, &pg_power3, false); + power_trim_info->bb_gain[2][1] = ((pg_power3 & 0xf0) >> 4); + + power_trim_info->flag |= KFREE_FLAG_ON_2G; + power_trim_info->flag |= KFREE_FLAG_ON; + } else { + power_trim_info->bb_gain[2][0] = (pg_power1 & 0xf); + power_trim_info->bb_gain[2][1] = ((pg_power1 & 0xf0) >> 4); + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8192F power trim flag:0x%02x\n", + power_trim_info->flag); + + if (!(power_trim_info->flag & KFREE_FLAG_ON)) + return; + + for (i = 0; i < KFREE_CH_NUM; i++) { + for (j = 0; j < 2; j++) + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8192F PwrTrim->bb_gain[%d][%d]=0x%X\n", + i, j, power_trim_info->bb_gain[i][j]); + } +} + +void phydm_set_kfree_to_rf_8192f(void *dm_void, u8 e_rf_path, u8 channel_idx, + u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + /*power_trim based on 55[19:14]*/ + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(5), 1); + /*enable 55[14] for 0.5db step*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xf5, BIT(18), 1); + /*enter power_trim debug mode*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xdf, BIT(7), 1); + /*write enable*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xef, BIT(7), 1); + + if (e_rf_path == 0) { + if (channel_idx == 0) { + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 0); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 1); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + + } else if (channel_idx == 1) { + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 2); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 3); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + } else if (channel_idx == 2) { + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 4); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 5); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + } + } else if (e_rf_path == 1) { + if (channel_idx == 0) { + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 0); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 1); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + } else if (channel_idx == 1) { + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 2); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 3); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + } else if (channel_idx == 2) { + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 4); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 5); + odm_set_rf_reg(dm, e_rf_path, 0x33, 0x3F, data); + } + } + + /*leave power_trim debug mode*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xdf, BIT(7), 0); + /*write disable*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xef, BIT(7), 0); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8192F 0x55[19:14]=0x%X path=%d channel=%d\n", + odm_get_rf_reg(dm, e_rf_path, RF_0x55, + (BIT(19) | BIT(18) | BIT(17) | BIT(16) | + BIT(15) | BIT(14))), e_rf_path, channel_idx); +} + +#if 0 +/* +void phydm_clear_kfree_to_rf_8192f(void *dm_void, u8 e_rf_path, u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(19), (data & BIT(0))); + odm_set_rf_reg(dm, e_rf_path, RF_0x55, (BIT(18) | BIT(17) | BIT(16) | BIT(15) | BIT(14)), ((data & 0x1f) >> 1)); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8192F clear power trim 0x55[19:14]=0x%X path=%d\n", + odm_get_rf_reg(dm, e_rf_path, RF_0x55, (BIT(19) | BIT(18) | BIT(17) | BIT(16) | BIT(15) | BIT(14))), + e_rf_path + ); +} +*/ +#endif + +void phydm_get_thermal_trim_offset_8198f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0; + + odm_efuse_one_byte_read(dm, PPG_THERMAL_OFFSET_98F, &pg_therm, false); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8198f efuse thermal trim 0x%X=0x%X\n", + PPG_THERMAL_OFFSET_98F, pg_therm); + + if (pg_therm != 0) { + pg_therm = pg_therm & 0x1f; + if ((pg_therm & BIT(0)) == 0) + power_trim_info->thermal = (-1 * (pg_therm >> 1)); + else + power_trim_info->thermal = (pg_therm >> 1); + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8198f thermal trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8198f thermal:%d\n", + power_trim_info->thermal); +} + +void phydm_get_power_trim_offset_8198f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 i, j; + u8 power_trim[6] = {0}; + + odm_efuse_one_byte_read(dm, PPG_2GL_TXAB_98F, &power_trim[0], false); + odm_efuse_one_byte_read(dm, PPG_2GL_TXCD_98F, &power_trim[1], false); + odm_efuse_one_byte_read(dm, PPG_2GM_TXAB_98F, &power_trim[2], false); + odm_efuse_one_byte_read(dm, PPG_2GM_TXCD_98F, &power_trim[3], false); + odm_efuse_one_byte_read(dm, PPG_2GH_TXAB_98F, &power_trim[4], false); + odm_efuse_one_byte_read(dm, PPG_2GH_TXCD_98F, &power_trim[5], false); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8198f efuse Power Trim 0x%X=0x%X 0x%X=0x%X 0x%X=0x%X 0x%X=0x%X 0x%X=0x%X 0x%X=0x%X\n", + PPG_2GL_TXAB_98F, power_trim[0], + PPG_2GL_TXCD_98F, power_trim[1], + PPG_2GM_TXAB_98F, power_trim[2], + PPG_2GM_TXCD_98F, power_trim[3], + PPG_2GH_TXAB_98F, power_trim[4], + PPG_2GH_TXCD_98F, power_trim[5] + ); + + j = 0; + for (i = 0; i < 6; i++) { + if (power_trim[i] == 0x0) + j++; + } + + if (j == 6) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8198f Power Trim no pg\n"); + } else { + power_trim_info->bb_gain[0][0] = power_trim[0] & 0xf; + power_trim_info->bb_gain[0][1] = (power_trim[0] & 0xf0) >> 4; + + power_trim_info->bb_gain[0][2] = power_trim[1] & 0xf; + power_trim_info->bb_gain[0][3] = (power_trim[1] & 0xf0) >> 4; + + power_trim_info->bb_gain[1][0] = power_trim[2] & 0xf; + power_trim_info->bb_gain[1][1] = (power_trim[2] & 0xf0) >> 4; + + power_trim_info->bb_gain[1][2] = power_trim[3] & 0xf; + power_trim_info->bb_gain[1][3] = (power_trim[3] & 0xf0) >> 4; + + power_trim_info->bb_gain[2][0] = power_trim[4] & 0xf; + power_trim_info->bb_gain[2][1] = (power_trim[4] & 0xf0) >> 4; + + power_trim_info->bb_gain[2][2] = power_trim[5] & 0xf; + power_trim_info->bb_gain[2][3] = (power_trim[5] & 0xf0) >> 4; + + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | KFREE_FLAG_ON_2G; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8198f power trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < MAX_RF_PATH; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8198f pwr_trim->bb_gain[%d][%d]=0x%X\n", + i, j, power_trim_info->bb_gain[i][j]); + } + } + } +} + +void phydm_get_pa_bias_offset_8198f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 i, j; + u8 pa_bias[2] = {0}; + u8 tx_pa_bias[4] = {0}; + + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GAB_98F, &pa_bias[0], false); + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GCD_98F, &pa_bias[1], false); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8198f efuse Tx PA Bias 0x%X=0x%X 0x%X=0x%X\n", + PPG_PABIAS_2GAB_98F, pa_bias[0], PPG_PABIAS_2GCD_98F, pa_bias[1]); + + j = 0; + for (i = 0; i < 2; i++) { + if (pa_bias[i] == 0x0) + j++; + } + + if (j == 2) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8198f Tx PA Bias no pg\n"); + } else { + /*paht ab*/ + tx_pa_bias[0] = pa_bias[0] & 0xf; + tx_pa_bias[1] = ((pa_bias[0] & 0xf0) >> 4); + + /*paht cd*/ + tx_pa_bias[2] = pa_bias[1] & 0xf; + tx_pa_bias[3] = ((pa_bias[1] & 0xf0) >> 4); + + for (i = RF_PATH_A; i < 4; i++) { + if ((tx_pa_bias[i] & 0x1) == 1) + tx_pa_bias[i] = tx_pa_bias[i] & 0xe; + else + tx_pa_bias[i] = tx_pa_bias[i] | 0x1; + } + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8198f PathA_pa_bias:0x%x PathB_pa_bias:0x%x\n", + tx_pa_bias[0], tx_pa_bias[1]); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8198f PathC_pa_bias:0x%x PathD_pa_bias:0x%x\n", + tx_pa_bias[2], tx_pa_bias[3]); + + for (i = RF_PATH_A; i < 4; i++) + odm_set_rf_reg(dm, i, 0x60, 0x0000f000, tx_pa_bias[i]); + + power_trim_info->pa_bias_flag |= PA_BIAS_FLAG_ON; + } +} + +void phydm_get_set_lna_offset_8198f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 i, j; + u8 lna_trim[4] = {0}; + u8 cg[4] = {0}, cs[4] = {0}; + u32 rf_reg; + + odm_efuse_one_byte_read(dm, PPG_LNA_2GA_98F, &lna_trim[0], false); + odm_efuse_one_byte_read(dm, PPG_LNA_2GB_98F, &lna_trim[1], false); + odm_efuse_one_byte_read(dm, PPG_LNA_2GC_98F, &lna_trim[2], false); + odm_efuse_one_byte_read(dm, PPG_LNA_2GD_98F, &lna_trim[3], false); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8198f efuse LNA Trim 0x%X=0x%X 0x%X=0x%X 0x%X=0x%X 0x%X=0x%X\n", + PPG_LNA_2GA_98F, lna_trim[0], + PPG_LNA_2GB_98F, lna_trim[1], + PPG_LNA_2GC_98F, lna_trim[2], + PPG_LNA_2GD_98F, lna_trim[3] + ); + + j = 0; + for (i = 0; i < 4; i++) { + if (lna_trim[i] == 0x0) + j++; + } + + if (j == 4) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8198f LNA no pg\n"); + } else { + + for (i = 0; i < 4; i++) { + cg[i] = (lna_trim[i] & 0xc) >> 2; + cs[i] = lna_trim[i] & 0x3; + } + + for (i = RF_PATH_A; i <= RF_PATH_D; i++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8198f lna cg[%d]=0x%x cs[%d]=0x%x\n", + i, cg[i], i, cs[i]); + odm_set_rf_reg(dm, i, 0xdf, RFREGOFFSETMASK, 0x2); + + if (cg[i] == 0x3) { + rf_reg = odm_get_rf_reg(dm, i, 0x86, (BIT(19) | BIT(18))); + rf_reg = rf_reg + 1; + if (rf_reg >= 0x3) + rf_reg = 0x3; + odm_set_rf_reg(dm, i, 0x86, (BIT(19) | BIT(18)), rf_reg); + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8198f lna CG set rf 0x86 [19:18]=0x%x path=%d\n", rf_reg, i); + } + if (cs[i] == 0x3) { + rf_reg = odm_get_rf_reg(dm, i, 0x86, (BIT(17) | BIT(16))); + rf_reg = rf_reg + 1; + if (rf_reg >= 0x3) + rf_reg = 0x3; + odm_set_rf_reg(dm, i, 0x86, (BIT(17) | BIT(16)), rf_reg); + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8198f lna CS set rf 0x86 [17:16]=0x%x path=%d\n", rf_reg, i); + } + } + + power_trim_info->lna_flag |= LNA_FLAG_ON; + } +} + + +void phydm_set_kfree_to_rf_8198f(void *dm_void, u8 e_rf_path, u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + u32 i; + s8 pwr_offset[3]; + + RF_DBG(dm, DBG_RF_MP, + "[kfree] %s:Set kfree to rf 0x33\n", __func__); + + /*power_trim based on 55[19:14]*/ + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(5), 1); + /*enable 55[14] for 0.5db step*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xf5, BIT(18), 1); + /*enter power_trim debug mode*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xdf, BIT(7), 0); + /*write enable*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xef, BIT(7), 1); + + for (i =0; i < 3; i++) + pwr_offset[i] = power_trim_info->bb_gain[i][e_rf_path]; + + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, pwr_offset[0]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, pwr_offset[0]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 2); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, pwr_offset[1]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 3); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, pwr_offset[1]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 4); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, pwr_offset[2]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 5); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, pwr_offset[2]); + + /*leave power_trim debug mode*/ + /*odm_set_rf_reg(dm, e_rf_path, RF_0xdf, BIT(7), 0);*/ + /*write disable*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xef, BIT(7), 0); + +} + +void phydm_clear_kfree_to_rf_8198f(void *dm_void, u8 e_rf_path, u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; +#if 0 + + RF_DBG(dm, DBG_RF_MP, + "[kfree] %s:Clear kfree to rf 0x55\n", __func__); + + /*power_trim based on 55[19:14]*/ + odm_set_rf_reg(dm, e_rf_path, RF_0x55, BIT(5), 1); + /*enable 55[14] for 0.5db step*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xf5, BIT(18), 1); + /*enter power_trim debug mode*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xdf, BIT(7), 0); + /*write enable*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xef, BIT(7), 1); + + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, data); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, data); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 2); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, data); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 3); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, data); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 4); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, data); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x70000, 5); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, data); + + /*leave power_trim debug mode*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xdf, BIT(7), 0); + /*enable 55[14] for 0.5db step*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xf5, BIT(18), 0); + /*write disable*/ + odm_set_rf_reg(dm, e_rf_path, RF_0xef, BIT(7), 0); + + odm_set_rf_reg(dm, e_rf_path, RF_0xdf, BIT(7), 1); + /*odm_set_rf_reg(dm, e_rf_path, RF_0xf5, BIT(18), 0);*/ + +#endif + +} + +void phydm_get_set_thermal_trim_offset_8822c(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0xff, thermal[2] = {0}; + + odm_efuse_one_byte_read(dm, PPG_THERMAL_A_OFFSET_22C, &pg_therm, false); + + if (pg_therm != 0xff) { + /*s0*/ + pg_therm = pg_therm & 0x1f; + + thermal[RF_PATH_A] = + ((pg_therm & 0x1) << 3) | ((pg_therm >> 1) & 0x7); + + odm_set_rf_reg(dm, RF_PATH_A, RF_0x43, 0x000f0000, thermal[RF_PATH_A]); + + /*s1*/ + odm_efuse_one_byte_read(dm, PPG_THERMAL_B_OFFSET_22C, &pg_therm, false); + + pg_therm = pg_therm & 0x1f; + + thermal[RF_PATH_B] = ((pg_therm & 0x1) << 3) | ((pg_therm >> 1) & 0x7); + + odm_set_rf_reg(dm, RF_PATH_B, RF_0x43, 0x000f0000, thermal[RF_PATH_B]); + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822c thermal trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822c thermalA:%d thermalB:%d\n", + thermal[RF_PATH_A], + thermal[RF_PATH_B]); +} + +void phydm_set_power_trim_offset_8822c(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + u8 e_rf_path; + + for (e_rf_path = RF_PATH_A; e_rf_path < 2; e_rf_path++) + { + odm_set_rf_reg(dm, e_rf_path, RF_0xee, BIT(19), 1); + + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x0); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[0][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x1); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[1][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x2); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[2][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x3); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[2][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x4); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[3][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x5); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[4][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x6); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[5][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x7); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[6][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x8); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[7][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x9); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[3][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xa); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[4][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xb); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[5][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xc); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[6][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xd); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[7][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xe); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[7][e_rf_path]); + + odm_set_rf_reg(dm, e_rf_path, RF_0xee, BIT(19), 0); + } +} + +void phydm_get_set_power_trim_offset_8822c(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_power = 0xff, i, j; + u8 pg_power1, pg_power2 , pg_power3, pg_power4, pg_power5; + + odm_efuse_one_byte_read(dm, PPG_2GL_TXAB_22C, &pg_power1, false); + odm_efuse_one_byte_read(dm, PPG_2GM_TXAB_22C, &pg_power2, false); + odm_efuse_one_byte_read(dm, PPG_2GH_TXAB_22C, &pg_power3, false); + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_22C, &pg_power4, false); + odm_efuse_one_byte_read(dm, PPG_5GL1_TXB_22C, &pg_power5, false); + + if (pg_power1 != 0xff || pg_power2 != 0xff || pg_power3 != 0xff || + pg_power4 != 0xff || pg_power5 != 0xff) { + odm_efuse_one_byte_read(dm, PPG_2GL_TXAB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[0][0] = pg_power & 0xf; + power_trim_info->bb_gain[0][1] = (pg_power & 0xf0) >> 4; + + odm_efuse_one_byte_read(dm, PPG_2GM_TXAB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[1][0] = pg_power & 0xf; + power_trim_info->bb_gain[1][1] = (pg_power & 0xf0) >> 4; + + odm_efuse_one_byte_read(dm, PPG_2GH_TXAB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[2][0] = pg_power & 0xf; + power_trim_info->bb_gain[2][1] = (pg_power & 0xf0) >> 4; + + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[3][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GL1_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[3][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GL2_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[4][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GL2_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[4][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GM1_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[5][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GM1_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[5][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GM2_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[6][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GM2_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[6][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GH1_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[7][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GH1_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[7][1] = pg_power & 0x1f; + + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | + KFREE_FLAG_ON_2G | + KFREE_FLAG_ON_5G; + + phydm_set_power_trim_offset_8822c(dm); + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822c power trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < 2; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8822c pwr_trim->bb_gain[%d][%d]=0x%X\n", + i, j, power_trim_info->bb_gain[i][j]); + } + } + } +} + +void phydm_get_tssi_trim_offset_8822c(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 i, j; + u8 pg_power[16] = {0}; + + odm_efuse_one_byte_read(dm, TSSI_2GM_TXA_22C, &pg_power[0], false); + odm_efuse_one_byte_read(dm, TSSI_2GM_TXB_22C, &pg_power[1], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXA_22C, &pg_power[2], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXB_22C, &pg_power[3], false); + odm_efuse_one_byte_read(dm, TSSI_5GL1_TXA_22C, &pg_power[4], false); + odm_efuse_one_byte_read(dm, TSSI_5GL1_TXB_22C, &pg_power[5], false); + odm_efuse_one_byte_read(dm, TSSI_5GL2_TXA_22C, &pg_power[6], false); + odm_efuse_one_byte_read(dm, TSSI_5GL2_TXB_22C, &pg_power[7], false); + odm_efuse_one_byte_read(dm, TSSI_5GM1_TXA_22C, &pg_power[8], false); + odm_efuse_one_byte_read(dm, TSSI_5GM1_TXB_22C, &pg_power[9], false); + odm_efuse_one_byte_read(dm, TSSI_5GM2_TXA_22C, &pg_power[10], false); + odm_efuse_one_byte_read(dm, TSSI_5GM2_TXB_22C, &pg_power[11], false); + odm_efuse_one_byte_read(dm, TSSI_5GH1_TXA_22C, &pg_power[12], false); + odm_efuse_one_byte_read(dm, TSSI_5GH1_TXB_22C, &pg_power[13], false); + odm_efuse_one_byte_read(dm, TSSI_5GH2_TXA_22C, &pg_power[14], false); + odm_efuse_one_byte_read(dm, TSSI_5GH2_TXB_22C, &pg_power[15], false); + + j = 0; + for (i = 0; i < 16; i++) { + if (pg_power[i] == 0xff) + j++; + } + + if (j == 16) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822c tssi trim no PG\n"); + } else { + power_trim_info->tssi_trim[0][0] = (s8)pg_power[0]; + power_trim_info->tssi_trim[0][1] = (s8)pg_power[1]; + power_trim_info->tssi_trim[1][0] = (s8)pg_power[0]; + power_trim_info->tssi_trim[1][1] = (s8)pg_power[1]; + power_trim_info->tssi_trim[2][0] = (s8)pg_power[2]; + power_trim_info->tssi_trim[2][1] = (s8)pg_power[3]; + power_trim_info->tssi_trim[3][0] = (s8)pg_power[4]; + power_trim_info->tssi_trim[3][1] = (s8)pg_power[5]; + power_trim_info->tssi_trim[4][0] = (s8)pg_power[6]; + power_trim_info->tssi_trim[4][1] = (s8)pg_power[7]; + power_trim_info->tssi_trim[5][0] = (s8)pg_power[8]; + power_trim_info->tssi_trim[5][1] = (s8)pg_power[9]; + power_trim_info->tssi_trim[6][0] = (s8)pg_power[10]; + power_trim_info->tssi_trim[6][1] = (s8)pg_power[11]; + power_trim_info->tssi_trim[7][0] = (s8)pg_power[12]; + power_trim_info->tssi_trim[7][1] = (s8)pg_power[13]; + power_trim_info->tssi_trim[8][0] = (s8)pg_power[14]; + power_trim_info->tssi_trim[8][1] = (s8)pg_power[15]; + + power_trim_info->flag = + power_trim_info->flag | TSSI_TRIM_FLAG_ON; + + if (power_trim_info->flag & TSSI_TRIM_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < 2; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8822c tssi_trim[%d][%d]=0x%X\n", + i, j, power_trim_info->tssi_trim[i][j]); + } + } + } + } +} + +s8 phydm_get_tssi_trim_de_8822c(void *dm_void, u8 path) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 channel = *dm->channel, group = 0; + + if (channel >= 1 && channel <= 3) + group = 0; + else if (channel >= 4 && channel <= 9) + group = 1; + else if (channel >= 10 && channel <= 14) + group = 2; + else if (channel >= 36 && channel <= 50) + group = 3; + else if (channel >= 52 && channel <= 64) + group = 4; + else if (channel >= 100 && channel <= 118) + group = 5; + else if (channel >= 120 && channel <= 144) + group = 6; + else if (channel >= 149 && channel <= 165) + group = 7; + else if (channel >= 167 && channel <= 177) + group = 8; + else { + RF_DBG(dm, DBG_RF_MP, "[kfree] Channel(%d) is not exist in Group\n", + channel); + return 0; + } + + return power_trim_info->tssi_trim[group][path]; +} + + + +void phydm_get_set_pa_bias_offset_8822c(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_pa_bias = 0xff; + + RF_DBG(dm, DBG_RF_MP, "======>%s\n", __func__); + + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GA_22C, &pg_pa_bias, false); + + if (pg_pa_bias != 0xff) { + /*2G s0*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GA_22C, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 2G s0 pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_A, 0x60, 0x0000f000, pg_pa_bias); + + /*2G s1*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GB_22C, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 2G s1 pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_B, 0x60, 0x0000f000, pg_pa_bias); + + /*5G s0*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_5GA_22C, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 5G s0 pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_A, 0x60, 0x000f0000, pg_pa_bias); + + /*5G s1*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_5GB_22C, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 5G s1 pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_B, 0x60, 0x000f0000, pg_pa_bias); + + power_trim_info->pa_bias_flag |= PA_BIAS_FLAG_ON; + } else { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822c tx pa bias no pg\n"); + } + +} + +void phydm_get_set_thermal_trim_offset_8812f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0xff, thermal[2] = {0}; + + odm_efuse_one_byte_read(dm, PPG_THERMAL_A_OFFSET_22C, &pg_therm, false); + + if (pg_therm != 0xff && pg_therm != 0x0) { + /*s0*/ + pg_therm = pg_therm & 0x1f; + + thermal[RF_PATH_A] = + ((pg_therm & 0x1) << 3) | ((pg_therm >> 1) & 0x7); + + odm_set_rf_reg(dm, RF_PATH_A, RF_0x43, 0x000f0000, thermal[RF_PATH_A]); + + /*s1*/ + odm_efuse_one_byte_read(dm, PPG_THERMAL_B_OFFSET_22C, &pg_therm, false); + + pg_therm = pg_therm & 0x1f; + + thermal[RF_PATH_B] = ((pg_therm & 0x1) << 3) | ((pg_therm >> 1) & 0x7); + + odm_set_rf_reg(dm, RF_PATH_B, RF_0x43, 0x000f0000, thermal[RF_PATH_B]); + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8812f thermal trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8812f thermalA:%d thermalB:%d\n", + thermal[RF_PATH_A], + thermal[RF_PATH_B]); +} + +void phydm_set_power_trim_offset_8812f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + u8 e_rf_path; + + for (e_rf_path = RF_PATH_A; e_rf_path < 2; e_rf_path++) + { + odm_set_rf_reg(dm, e_rf_path, RF_0xee, BIT(19), 1); + +#if 0 + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x0); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[0][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x1); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[1][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x2); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[2][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x3); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[2][e_rf_path]); +#endif + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x4); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[3][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x5); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[4][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x6); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[5][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x7); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[6][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x8); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[7][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x9); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[3][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xa); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[4][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xb); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[5][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xc); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[6][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xd); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[7][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xe); + odm_set_rf_reg(dm, e_rf_path, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[7][e_rf_path]); + + odm_set_rf_reg(dm, e_rf_path, RF_0xee, BIT(19), 0); + } +} + +void phydm_get_set_power_trim_offset_8812f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_power = 0xff, i, j; + u8 pg_power1 = 0, pg_power2 = 0, pg_power3 = 0; + u8 pg_power4 = 0, pg_power5 = 0; + + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_22C, &pg_power1, false); + odm_efuse_one_byte_read(dm, PPG_5GL1_TXB_22C, &pg_power2, false); + odm_efuse_one_byte_read(dm, PPG_5GL2_TXA_22C, &pg_power3, false); + odm_efuse_one_byte_read(dm, PPG_5GL2_TXB_22C, &pg_power4, false); + odm_efuse_one_byte_read(dm, PPG_5GM1_TXA_22C, &pg_power5, false); + + if ((pg_power1 != 0xff || pg_power2 != 0xff || pg_power3 != 0xff || + pg_power4 != 0xff || pg_power5 != 0xff) && + (pg_power1 != 0x0 || pg_power2 != 0x0 || pg_power3 != 0x0 || + pg_power4 != 0x0 || pg_power5 != 0x0)) { +#if 0 + odm_efuse_one_byte_read(dm, PPG_2GL_TXAB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[0][0] = pg_power & 0xf; + power_trim_info->bb_gain[0][1] = (pg_power & 0xf0) >> 4; + + odm_efuse_one_byte_read(dm, PPG_2GM_TXAB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[1][0] = pg_power & 0xf; + power_trim_info->bb_gain[1][1] = (pg_power & 0xf0) >> 4; + + odm_efuse_one_byte_read(dm, PPG_2GH_TXAB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[2][0] = pg_power & 0xf; + power_trim_info->bb_gain[2][1] = (pg_power & 0xf0) >> 4; +#endif + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[3][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GL1_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[3][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GL2_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[4][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GL2_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[4][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GM1_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[5][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GM1_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[5][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GM2_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[6][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GM2_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[6][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GH1_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[7][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GH1_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[7][1] = pg_power & 0x1f; + + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | KFREE_FLAG_ON_5G; + + phydm_set_power_trim_offset_8812f(dm); + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8812f power trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < 2; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8812f pwr_trim->bb_gain[%d][%d]=0x%X\n", + i, j, power_trim_info->bb_gain[i][j]); + } + } + } +} + +void phydm_get_tssi_trim_offset_8812f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 i, j ; + u8 pg_power[16] = {0}; + +#if 0 + odm_efuse_one_byte_read(dm, TSSI_2GM_TXA_22C, &pg_power[0], false); + odm_efuse_one_byte_read(dm, TSSI_2GM_TXB_22C, &pg_power[1], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXA_22C, &pg_power[2], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXB_22C, &pg_power[3], false); +#endif + odm_efuse_one_byte_read(dm, TSSI_5GL1_TXA_22C, &pg_power[4], false); + odm_efuse_one_byte_read(dm, TSSI_5GL1_TXB_22C, &pg_power[5], false); + odm_efuse_one_byte_read(dm, TSSI_5GL2_TXA_22C, &pg_power[6], false); + odm_efuse_one_byte_read(dm, TSSI_5GL2_TXB_22C, &pg_power[7], false); + odm_efuse_one_byte_read(dm, TSSI_5GM1_TXA_22C, &pg_power[8], false); + odm_efuse_one_byte_read(dm, TSSI_5GM1_TXB_22C, &pg_power[9], false); + odm_efuse_one_byte_read(dm, TSSI_5GM2_TXA_22C, &pg_power[10], false); + odm_efuse_one_byte_read(dm, TSSI_5GM2_TXB_22C, &pg_power[11], false); + odm_efuse_one_byte_read(dm, TSSI_5GH1_TXA_22C, &pg_power[12], false); + odm_efuse_one_byte_read(dm, TSSI_5GH1_TXB_22C, &pg_power[13], false); + odm_efuse_one_byte_read(dm, TSSI_5GH2_TXA_22C, &pg_power[14], false); + odm_efuse_one_byte_read(dm, TSSI_5GH2_TXB_22C, &pg_power[15], false); + + j = 0; + for (i = 4; i < 16; i++) { + if (pg_power[i] == 0xff || pg_power[i] == 0x0) + j++; + } + + if (j == 12) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8812f tssi trim no PG\n"); + } else { +#if 0 + power_trim_info->tssi_trim[0][0] = (s8)pg_power[0]; + power_trim_info->tssi_trim[0][1] = (s8)pg_power[1]; + power_trim_info->tssi_trim[1][0] = (s8)pg_power[0]; + power_trim_info->tssi_trim[1][1] = (s8)pg_power[1]; + power_trim_info->tssi_trim[2][0] = (s8)pg_power[2]; + power_trim_info->tssi_trim[2][1] = (s8)pg_power[3]; +#endif + power_trim_info->tssi_trim[3][0] = (s8)pg_power[4]; + power_trim_info->tssi_trim[3][1] = (s8)pg_power[5]; + power_trim_info->tssi_trim[4][0] = (s8)pg_power[6]; + power_trim_info->tssi_trim[4][1] = (s8)pg_power[7]; + power_trim_info->tssi_trim[5][0] = (s8)pg_power[8]; + power_trim_info->tssi_trim[5][1] = (s8)pg_power[9]; + power_trim_info->tssi_trim[6][0] = (s8)pg_power[10]; + power_trim_info->tssi_trim[6][1] = (s8)pg_power[11]; + power_trim_info->tssi_trim[7][0] = (s8)pg_power[12]; + power_trim_info->tssi_trim[7][1] = (s8)pg_power[13]; + power_trim_info->tssi_trim[8][0] = (s8)pg_power[14]; + power_trim_info->tssi_trim[8][1] = (s8)pg_power[15]; + + power_trim_info->flag = + power_trim_info->flag | TSSI_TRIM_FLAG_ON; + + if (power_trim_info->flag & TSSI_TRIM_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < 2; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8812f tssi_trim[%d][%d]=0x%X\n", + i, j, power_trim_info->tssi_trim[i][j]); + } + } + } + } +} + +s8 phydm_get_tssi_trim_de_8812f(void *dm_void, u8 path) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 channel = *dm->channel, group = 0; + + if (channel >= 1 && channel <= 3) + group = 0; + else if (channel >= 4 && channel <= 9) + group = 1; + else if (channel >= 10 && channel <= 14) + group = 2; + else if (channel >= 36 && channel <= 50) + group = 3; + else if (channel >= 52 && channel <= 64) + group = 4; + else if (channel >= 100 && channel <= 118) + group = 5; + else if (channel >= 120 && channel <= 144) + group = 6; + else if (channel >= 149 && channel <= 165) + group = 7; + else if (channel >= 167 && channel <= 177) + group = 8; + else { + RF_DBG(dm, DBG_RF_MP, "[kfree] Channel(%d) is not exist in Group\n", + channel); + return 0; + } + + return power_trim_info->tssi_trim[group][path]; +} + +void phydm_get_set_pa_bias_offset_8812f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_pa_bias = 0xff; + + RF_DBG(dm, DBG_RF_MP, "======>%s\n", __func__); + + odm_efuse_one_byte_read(dm, PPG_PABIAS_5GA_22C, &pg_pa_bias, false); + + if (pg_pa_bias != 0xff && pg_pa_bias != 0x0) { +#if 0 + /*2G s0*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GA_22C, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 2G s0 pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_A, 0x60, 0x0000f000, pg_pa_bias); + + /*2G s1*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GB_22C, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 2G s1 pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_B, 0x60, 0x0000f000, pg_pa_bias); +#endif + + /*5G s0*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_5GA_22C, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 5G s0 pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_A, 0x60, 0x000f0000, pg_pa_bias); + + /*5G s1*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_5GB_22C, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 5G s1 pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_B, 0x60, 0x000f0000, pg_pa_bias); + + power_trim_info->pa_bias_flag |= PA_BIAS_FLAG_ON; + } else { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8812f tx pa bias no pg\n"); + } + +} + +void phydm_get_thermal_trim_offset_8195b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0xff; + + odm_efuse_one_byte_read(dm, PPG_THERMAL_OFFSET_95B, &pg_therm, false); + + if (pg_therm != 0xff) { + pg_therm = pg_therm & 0x1f; + if ((pg_therm & BIT(0)) == 0) + power_trim_info->thermal = (-1 * (pg_therm >> 1)); + else + power_trim_info->thermal = (pg_therm >> 1); + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8195b thermal trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8195b thermal:%d\n", + power_trim_info->thermal); +} + +void phydm_set_power_trim_rf_8195b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + RF_DBG(dm, DBG_RF_MP, + "[kfree] %s:Set kfree to rf 0x33\n", __func__); + + if (power_trim_info->flag & KFREE_FLAG_ON) { + odm_set_rf_reg(dm, RF_PATH_A, RF_0xee, BIT(19), 1); + + if (power_trim_info->flag & KFREE_FLAG_ON_2G) { + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x0); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[0][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x1); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[1][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x2); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[2][RF_PATH_A]); + } + + if (power_trim_info->flag & KFREE_FLAG_ON_5G) { + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x4); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[3][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x5); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[4][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x6); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[5][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x7); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[6][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x8); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[7][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0xe); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[7][RF_PATH_A]); + } + + odm_set_rf_reg(dm, RF_PATH_A, RF_0xee, BIT(19), 0); + } + +} + +void phydm_get_set_power_trim_offset_8195b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_power = 0xff, i, j; + + odm_efuse_one_byte_read(dm, PPG_2GL_TXA_95B, &pg_power, false); + + if (pg_power != 0xff) { + odm_efuse_one_byte_read(dm, PPG_2GL_TXA_95B, &pg_power, false); + power_trim_info->bb_gain[0][0] = pg_power & 0xf; + + odm_efuse_one_byte_read(dm, PPG_2GM_TXA_95B, &pg_power, false); + power_trim_info->bb_gain[1][0] = pg_power & 0xf; + + odm_efuse_one_byte_read(dm, PPG_2GH_TXA_95B, &pg_power, false); + power_trim_info->bb_gain[2][0] = pg_power & 0xf; + + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | KFREE_FLAG_ON_2G; + } + + pg_power = 0xff; + + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_95B, &pg_power, false); + + if (pg_power != 0xff) { + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_95B, &pg_power, false); + power_trim_info->bb_gain[3][0] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GL2_TXA_95B, &pg_power, false); + power_trim_info->bb_gain[4][0] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GM1_TXA_95B, &pg_power, false); + power_trim_info->bb_gain[5][0] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GM2_TXA_95B, &pg_power, false); + power_trim_info->bb_gain[6][0] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GH1_TXA_95B, &pg_power, false); + power_trim_info->bb_gain[7][0] = pg_power & 0x1f; + + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | KFREE_FLAG_ON_5G; + } + + phydm_set_power_trim_rf_8195b(dm); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8195b power trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < 1; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8195b pwr_trim->bb_gain[%d][%d]=0x%X\n", + i, j, power_trim_info->bb_gain[i][j]); + } + } + } +} + +void phydm_get_set_pa_bias_offset_8195b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_pa_bias = 0xff; + + RF_DBG(dm, DBG_RF_MP, "======>%s\n", __func__); + + /*2G*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GA_95B, &pg_pa_bias, false); + + if (pg_pa_bias != 0xff) { + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GA_95B, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 2G pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_A, 0x60, 0x0000f000, pg_pa_bias); + } else { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8195b 2G tx pa bias no pg\n"); + } + + /*5G*/ + pg_pa_bias = 0xff; + + odm_efuse_one_byte_read(dm, PPG_PABIAS_5GA_95B, &pg_pa_bias, false); + + if (pg_pa_bias != 0xff) { + odm_efuse_one_byte_read(dm, PPG_PABIAS_5GA_95B, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 5G pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_A, 0x60, 0x000f0000, pg_pa_bias); + + power_trim_info->pa_bias_flag |= PA_BIAS_FLAG_ON; + } else { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8195b 5G tx pa bias no pg\n"); + } +} + +void phydm_get_thermal_trim_offset_8721d(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0xff; + + odm_efuse_one_byte_read(dm, PPG_THERMAL_OFFSET_8721D, &pg_therm, false); + + if (pg_therm != 0xff) { + pg_therm = pg_therm & 0x1f; + if ((pg_therm & BIT(0)) == 0) + power_trim_info->thermal = (-1 * (pg_therm >> 1)); + else + power_trim_info->thermal = (pg_therm >> 1); + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8721d thermal trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8721d thermal:%d\n", + power_trim_info->thermal); +} + +void phydm_set_power_trim_rf_8721d(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + RF_DBG(dm, DBG_RF_MP, "[kfree] %s:Set kfree to rf 0x33\n", __func__); + + odm_set_rf_reg(dm, RF_PATH_A, RF_0xee, BIT(19), 1); + + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x0); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[0][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x1); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[1][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x2); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[2][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x3); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[2][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x4); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[3][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x5); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[4][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x6); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[5][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x7); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[6][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x8); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x0000003f, + power_trim_info->bb_gain[7][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0x9); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[3][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0xa); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[4][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0xb); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[5][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0xc); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[6][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0xd); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[7][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0xe); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, RFREGOFFSETMASK, + power_trim_info->bb_gain[7][RF_PATH_A]); + + odm_set_rf_reg(dm, RF_PATH_A, RF_0xee, BIT(19), 0); +} + +void phydm_get_set_power_trim_offset_8721d(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_power = 0xff, i, j; + u8 pg_power1, pg_power2, pg_power3, pg_power4, pg_power5, pg_power6; + + odm_efuse_one_byte_read(dm, PPG_2G_TXA_8721D, &pg_power1, false); + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_8721D, &pg_power2, false); + odm_efuse_one_byte_read(dm, PPG_5GL2_TXA_8721D, &pg_power3, false); + odm_efuse_one_byte_read(dm, PPG_5GM1_TXA_8721D, &pg_power4, false); + odm_efuse_one_byte_read(dm, PPG_5GM2_TXA_8721D, &pg_power5, false); + odm_efuse_one_byte_read(dm, PPG_5GH1_TXA_8721D, &pg_power6, false); + + if (pg_power1 != 0xff || pg_power2 != 0xff || pg_power3 != 0xff || + pg_power4 != 0xff || pg_power5 != 0xff || pg_power6 != 0xff) { + odm_efuse_one_byte_read(dm, PPG_2G_TXA_8721D, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[0][0] = pg_power & 0xf; + power_trim_info->bb_gain[1][0] = pg_power & 0xf; + power_trim_info->bb_gain[2][0] = pg_power & 0xf; + + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_8721D, + &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[3][0] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GL2_TXA_8721D, + &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[4][0] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GM1_TXA_8721D, + &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[5][0] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GM2_TXA_8721D, + &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[6][0] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GH1_TXA_8721D, + &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[7][0] = pg_power & 0x1f; + + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | + KFREE_FLAG_ON_2G | + KFREE_FLAG_ON_5G; + + phydm_set_power_trim_rf_8721d(dm); + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8721d power trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < 1; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8721d pwr_trim->bb_gain[%d][%d]=0x%X\n", + i, j, power_trim_info->bb_gain[i][j]); + } + } + } +} + +void phydm_get_set_pa_bias_offset_8721d(void *dm_void) +{ +#if 0 + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_pa_bias = 0xff; + + RF_DBG(dm, DBG_RF_MP, "======>%s\n", __func__); + + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GA_95B, &pg_pa_bias, false); + + if (pg_pa_bias != 0xff) { + /*2G*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GA_95B, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 2G pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_A, 0x60, 0x0000f000, pg_pa_bias); + + /*5G*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_5GA_95B, + &pg_pa_bias, false); + pg_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, "[kfree] 5G pa_bias=0x%x\n", pg_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_A, 0x60, 0x000f0000, pg_pa_bias); + + power_trim_info->pa_bias_flag |= PA_BIAS_FLAG_ON; + } else { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8721d tx pa bias no pg\n"); + } +#endif +} + +void phydm_get_thermal_trim_offset_8197g(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0xff, i; + + odm_efuse_one_byte_read(dm, PPG_THERMAL_A_OFFSET_97G, &pg_therm, false); + + if (pg_therm != 0x0) { + for (i = 0; i < 2; i++) { + if (i == 0) + odm_efuse_one_byte_read(dm, PPG_THERMAL_A_OFFSET_97G, &pg_therm, false); + else if (i == 1) + odm_efuse_one_byte_read(dm, PPG_THERMAL_B_OFFSET_97G, &pg_therm, false); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g Efuse thermal S%d:0x%x\n", i, pg_therm); + + pg_therm = pg_therm & 0x1f; + if ((pg_therm & BIT(0)) == 0) + power_trim_info->multi_thermal[i] = (-1 * (pg_therm >> 1)); + else + power_trim_info->multi_thermal[i] = (pg_therm >> 1); + } + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g thermal trim flag:0x%02x\n", + power_trim_info->flag); + + for (i = 0; i < 2; i++) { + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g thermal S%d:%d\n", + i ,power_trim_info->multi_thermal[i]); + } +} + +void phydm_set_power_trim_offset_8197g(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + u8 e_rf_path; + + for (e_rf_path = RF_PATH_A; e_rf_path < 2; e_rf_path++) + { + odm_set_rf_reg(dm, e_rf_path, RF_0xef, BIT(7), 1); + + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x1c000, 0); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, + power_trim_info->bb_gain[0][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x1c000, 1); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, + power_trim_info->bb_gain[0][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x1c000, 2); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, + power_trim_info->bb_gain[1][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x1c000, 3); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, + power_trim_info->bb_gain[1][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x1c000, 4); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, + power_trim_info->bb_gain[2][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x1c000, 5); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, 0x3F, + power_trim_info->bb_gain[2][e_rf_path]); + + odm_set_rf_reg(dm, e_rf_path, RF_0xef, BIT(7), 0); + } + +} + +void phydm_get_set_power_trim_offset_8197g(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_power = 0, i, j; + + odm_efuse_one_byte_read(dm, PPG_2GL_TXAB_97G, &pg_power, false); + + if (pg_power != 0) { + power_trim_info->bb_gain[0][0] = pg_power & 0xf; + power_trim_info->bb_gain[0][1] = (pg_power & 0xf0) >> 4; + + odm_efuse_one_byte_read(dm, PPG_2GM_TXAB_97G, &pg_power, false); + power_trim_info->bb_gain[1][0] = pg_power & 0xf; + power_trim_info->bb_gain[1][1] = (pg_power & 0xf0) >> 4; + + odm_efuse_one_byte_read(dm, PPG_2GH_TXAB_97G, &pg_power, false); + power_trim_info->bb_gain[2][0] = pg_power & 0xf; + power_trim_info->bb_gain[2][1] = (pg_power & 0xf0) >> 4; + + phydm_set_power_trim_offset_8197g(dm); + + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | KFREE_FLAG_ON_2G; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g power trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < MAX_RF_PATH; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8197g pwr_trim->bb_gain[%d][%d]=0x%X\n", + i, j, power_trim_info->bb_gain[i][j]); + } + } + } +} + +void phydm_get_tssi_trim_offset_8197g(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 i, j; + u8 pg_power[4] = {0}; + + odm_efuse_one_byte_read(dm, TSSI_2GL_TXA_97G, &pg_power[0], false); + odm_efuse_one_byte_read(dm, TSSI_2GL_TXB_97G, &pg_power[1], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXA_97G, &pg_power[2], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXB_97G, &pg_power[3], false); + + j = 0; + for (i = 0; i < 4; i++) { + if (pg_power[i] == 0x0) + j++; + } + + if (j == 4) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g tssi trim no PG\n"); + } else { + power_trim_info->tssi_trim[0][0] = (s8)pg_power[0]; + power_trim_info->tssi_trim[0][1] = (s8)pg_power[1]; + power_trim_info->tssi_trim[1][0] = (s8)pg_power[0]; + power_trim_info->tssi_trim[1][1] = (s8)pg_power[1]; + power_trim_info->tssi_trim[2][0] = (s8)pg_power[2]; + power_trim_info->tssi_trim[2][1] = (s8)pg_power[3]; + + power_trim_info->flag = + power_trim_info->flag | TSSI_TRIM_FLAG_ON; + + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < MAX_PATH_NUM_8197G; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8197g tssi_trim[%d][%d]=0x%X\n", + i, j, power_trim_info->tssi_trim[i][j]); + } + } + } +} + +s8 phydm_get_tssi_trim_de_8197g(void *dm_void, u8 path) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 channel = *dm->channel, group = 0; + + if (channel >= 1 && channel <= 3) + group = 0; + else if (channel >= 4 && channel <= 9) + group = 1; + else if (channel >= 10 && channel <= 14) + group = 2; + else { + RF_DBG(dm, DBG_RF_MP, "[kfree] Channel(%d) is not exist in Group\n", + channel); + return 0; + } + + return power_trim_info->tssi_trim[group][path]; +} + +void phydm_get_set_pa_bias_offset_8197g(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_pa_bias = 0xff, i; + u8 tx_pa_bias[4] = {0}; + + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GAB_97G, &pg_pa_bias, false); + + if (pg_pa_bias != 0x0) { + /*paht ab*/ + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GAB_97G, + &pg_pa_bias, false); + tx_pa_bias[0] = pg_pa_bias & 0xf; + tx_pa_bias[1] = ((pg_pa_bias & 0xf0) >> 4); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8197g PathA_pa_bias:0x%x PathB_pa_bias:0x%x\n", + tx_pa_bias[0], tx_pa_bias[1]); + + for (i = RF_PATH_A; i < 2; i++) + odm_set_rf_reg(dm, i, 0x60, 0x0000f000, tx_pa_bias[i]); + + power_trim_info->pa_bias_flag |= PA_BIAS_FLAG_ON; + } else { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g tx pa bias no pg\n"); + } +} + +void phydm_get_set_lna_offset_8197g(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_lna[2] = {0}, i, pg_lna_tmp = 0; + u32 lna_trim_addr[2] = {0x1884, 0x4184}; + + odm_efuse_one_byte_read(dm, PPG_LNA_2GA_97G, &pg_lna_tmp, false); + + if (pg_lna_tmp != 0) { + odm_efuse_one_byte_read(dm, PPG_LNA_2GA_97G, + &pg_lna[RF_PATH_A], false); + power_trim_info->lna_trim[RF_PATH_A] = (s8)pg_lna[RF_PATH_A]; + + odm_efuse_one_byte_read(dm, PPG_LNA_2GB_97G, + &pg_lna[RF_PATH_B], false); + power_trim_info->lna_trim[RF_PATH_B] = (s8)pg_lna[RF_PATH_B]; + + for (i = RF_PATH_A; i < 2; i++) { + if (odm_get_bb_reg(dm, lna_trim_addr[i], 0x00c00000) == 0x2) { + odm_set_rf_reg(dm, i, 0x88, 0x00000f00, (pg_lna[i] & 0xf)); + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g lna trim CG 0x%x path=%d\n", (pg_lna[i] & 0xf), i); + } else if (odm_get_bb_reg(dm, lna_trim_addr[i], 0x00c00000) == 0x3) { + odm_set_rf_reg(dm, i, 0x88, 0x00000f00, ((pg_lna[i] & 0xf0) >> 4)); + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g lna trim CS 0x%x path=%d\n", ((pg_lna[i] & 0xf0) >> 4), i); + } + } + + power_trim_info->lna_flag |= LNA_FLAG_ON; + } else { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g lna trim no pg\n"); + } +} + +void phydm_set_lna_trim_offset_8197g(void *dm_void, u8 path, u8 cg_cs, u8 enable) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *trim = &dm->power_trim_data; + + u8 i; + + if (enable == 0) { + for (i = RF_PATH_A; i < 2; i++) { + odm_set_rf_reg(dm, i, 0x88, 0x00000f00, 0x0); + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g diversity lna trim disable\n"); + } + return; + } + + /*cg*/ + if (cg_cs == 0) { + odm_set_rf_reg(dm, path, 0x88, 0x00000f00, (trim->lna_trim[path] & 0xf)); + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g diversity lna trim CG 0x%x path=%d\n", + (trim->lna_trim[path] & 0xf), path); + } else if (cg_cs == 1) { /*cs*/ + odm_set_rf_reg(dm, path, 0x88, 0x00000f00, ((trim->lna_trim[path] & 0xf0) >> 4)); + RF_DBG(dm, DBG_RF_MP, "[kfree] 8197g diversity lna trim CS 0x%x path=%d\n", + ((trim->lna_trim[path] & 0xf0) >> 4), path); + } +} + + +void phydm_get_thermal_trim_offset_8710c(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0; + + odm_efuse_one_byte_read(dm, PPG_THERMAL_OFFSET_10C, &pg_therm, false); + RF_DBG(dm, DBG_RF_MP, "[kfree] 8710c Efuse thermal:0x%x\n", pg_therm); + + if (pg_therm != 0xff) { + pg_therm = pg_therm & 0x1f; + if ((pg_therm & BIT(0)) == 0) + power_trim_info->thermal = (-1 * (pg_therm >> 1)); + else + power_trim_info->thermal = (pg_therm >> 1); + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8710c thermal trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8710c thermal:%d\n", + power_trim_info->thermal); +} + +void phydm_set_power_trim_offset_8710c(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, BIT(18), 1); + + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 0); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x3f, + power_trim_info->bb_gain[0][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 1); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x3f, + power_trim_info->bb_gain[1][RF_PATH_A]); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x33, RFREGOFFSETMASK, 2); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x3f, 0x3f, + power_trim_info->bb_gain[2][RF_PATH_A]); + + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, BIT(18), 0); +} + +void phydm_get_set_power_trim_offset_8710c(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_power = 0, i, j; + + odm_efuse_one_byte_read(dm, PPG_2GL_TX_10C, &pg_power, false); + + if (pg_power != 0xff) { + power_trim_info->bb_gain[0][RF_PATH_A] = pg_power & 0xf; + + odm_efuse_one_byte_read(dm, PPG_2GM_TX_10C, &pg_power, false); + power_trim_info->bb_gain[1][RF_PATH_A] = pg_power & 0xf; + + odm_efuse_one_byte_read(dm, PPG_2GH_TX_10C, &pg_power, false); + power_trim_info->bb_gain[2][RF_PATH_A] = pg_power & 0xf; + + phydm_set_power_trim_offset_8710c(dm); + + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | KFREE_FLAG_ON_2G; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8710c power trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < MAX_RF_PATH; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8710c pwr_trim->bb_gain[%d][%d]=0x%X\n", + i, j, power_trim_info->bb_gain[i][j]); + } + } + } +} + +void phydm_get_set_pa_bias_offset_8710c(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_pa_bias = 0xff; + u8 tx_pa_bias = 0; + + odm_efuse_one_byte_read(dm, PPG_PABIAS_10C, &pg_pa_bias, false); + + if (pg_pa_bias != 0xff) { + tx_pa_bias = pg_pa_bias & 0xf; + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8710c PathA_pa_bias:0x%x\n", tx_pa_bias); + + odm_set_rf_reg(dm, RF_PATH_A, 0x60, 0x0000f000, tx_pa_bias); + + power_trim_info->pa_bias_flag |= PA_BIAS_FLAG_ON; + } else { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8710c tx pa bias no pg\n"); + } +} + +void phydm_set_power_trim_offset_8814b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + u8 e_rf_path; + + for (e_rf_path = RF_PATH_A; e_rf_path < MAX_PATH_NUM_8814B; e_rf_path++) + { + if (power_trim_info->flag & KFREE_FLAG_ON) { + odm_set_rf_reg(dm, e_rf_path, RF_0xee, BIT(19), 1); + + if (power_trim_info->flag & KFREE_FLAG_ON_2G) { + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x0); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[0][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x1); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[0][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x2); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[0][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x3); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[0][e_rf_path]); + } + + if (power_trim_info->flag & KFREE_FLAG_ON_5G) { + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x4); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[3][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x5); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[4][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x6); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[5][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x7); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[6][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x8); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[7][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0x9); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[3][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xa); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[4][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xb); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[5][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xc); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[6][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xd); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[7][e_rf_path]); + odm_set_rf_reg(dm, e_rf_path, RF_0x33, RFREGOFFSETMASK, 0xe); + odm_set_rf_reg(dm, e_rf_path, RF_0x30, RFREGOFFSETMASK, + power_trim_info->bb_gain[7][e_rf_path]); + } + + odm_set_rf_reg(dm, e_rf_path, RF_0xee, BIT(19), 0); + } + } +} + +void phydm_get_set_power_trim_offset_8814b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 i, j; + u8 pg_power1, pg_power2; + u8 pg_power_2g[2] = {0}, pg_power_5g[20] = {0}; + + odm_efuse_one_byte_read(dm, PPG_2GL_TXAB_14B, &pg_power_2g[0], false); + odm_efuse_one_byte_read(dm, PPG_2GL_TXCD_14B, &pg_power_2g[1], false); + + j = 0; + for (i = 0; i < 2; i++) { + if (pg_power_2g[i] == 0xff) + j++; + } + + if (j == 2) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b 2G power trim no PG\n"); + } else { + power_trim_info->bb_gain[0][RF_PATH_A] = pg_power_2g[0] & 0xf; + power_trim_info->bb_gain[0][RF_PATH_B] = (pg_power_2g[0] & 0xf0) >> 4; + + power_trim_info->bb_gain[0][RF_PATH_C] = pg_power_2g[1] & 0xf; + power_trim_info->bb_gain[0][RF_PATH_D] = (pg_power_2g[1] & 0xf0) >> 4; + + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | KFREE_FLAG_ON_2G; + } + + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_14B, &pg_power_5g[0], false); + odm_efuse_one_byte_read(dm, PPG_5GL1_TXB_14B, &pg_power_5g[1], false); + odm_efuse_one_byte_read(dm, PPG_5GL1_TXC_14B, &pg_power_5g[2], false); + odm_efuse_one_byte_read(dm, PPG_5GL1_TXD_14B, &pg_power_5g[3], false); + odm_efuse_one_byte_read(dm, PPG_5GL2_TXA_14B, &pg_power_5g[4], false); + odm_efuse_one_byte_read(dm, PPG_5GL2_TXB_14B, &pg_power_5g[5], false); + odm_efuse_one_byte_read(dm, PPG_5GL2_TXC_14B, &pg_power_5g[6], false); + odm_efuse_one_byte_read(dm, PPG_5GL2_TXD_14B, &pg_power_5g[7], false); + odm_efuse_one_byte_read(dm, PPG_5GM1_TXA_14B, &pg_power_5g[8], false); + odm_efuse_one_byte_read(dm, PPG_5GM1_TXB_14B, &pg_power_5g[9], false); + odm_efuse_one_byte_read(dm, PPG_5GM1_TXC_14B, &pg_power_5g[10], false); + odm_efuse_one_byte_read(dm, PPG_5GM1_TXD_14B, &pg_power_5g[11], false); + odm_efuse_one_byte_read(dm, PPG_5GM2_TXA_14B, &pg_power_5g[12], false); + odm_efuse_one_byte_read(dm, PPG_5GM2_TXB_14B, &pg_power_5g[13], false); + odm_efuse_one_byte_read(dm, PPG_5GM2_TXC_14B, &pg_power_5g[14], false); + odm_efuse_one_byte_read(dm, PPG_5GM2_TXD_14B, &pg_power_5g[15], false); + odm_efuse_one_byte_read(dm, PPG_5GH1_TXA_14B, &pg_power_5g[16], false); + odm_efuse_one_byte_read(dm, PPG_5GH1_TXB_14B, &pg_power_5g[17], false); + odm_efuse_one_byte_read(dm, PPG_5GH1_TXC_14B, &pg_power_5g[18], false); + odm_efuse_one_byte_read(dm, PPG_5GH1_TXD_14B, &pg_power_5g[19], false); + + j = 0; + for (i = 0; i < 20; i++) { + if (pg_power_5g[i] == 0xff) + j++; + } + + if (j == 20) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b 5G power trim no PG\n"); + } else { + power_trim_info->bb_gain[3][RF_PATH_A] = pg_power_5g[0] & 0x1f; + power_trim_info->bb_gain[3][RF_PATH_B] = pg_power_5g[1] & 0x1f; + power_trim_info->bb_gain[3][RF_PATH_C] = pg_power_5g[2] & 0x1f; + power_trim_info->bb_gain[3][RF_PATH_D] = pg_power_5g[3] & 0x1f; + + power_trim_info->bb_gain[4][RF_PATH_A] = pg_power_5g[4] & 0x1f; + power_trim_info->bb_gain[4][RF_PATH_B] = pg_power_5g[5] & 0x1f; + power_trim_info->bb_gain[4][RF_PATH_C] = pg_power_5g[6] & 0x1f; + power_trim_info->bb_gain[4][RF_PATH_D] = pg_power_5g[7] & 0x1f; + + power_trim_info->bb_gain[5][RF_PATH_A] = pg_power_5g[8] & 0x1f; + power_trim_info->bb_gain[5][RF_PATH_B] = pg_power_5g[9] & 0x1f; + power_trim_info->bb_gain[5][RF_PATH_C] = pg_power_5g[10] & 0x1f; + power_trim_info->bb_gain[5][RF_PATH_D] = pg_power_5g[11] & 0x1f; + + power_trim_info->bb_gain[6][RF_PATH_A] = pg_power_5g[12] & 0x1f; + power_trim_info->bb_gain[6][RF_PATH_B] = pg_power_5g[13] & 0x1f; + power_trim_info->bb_gain[6][RF_PATH_C] = pg_power_5g[14] & 0x1f; + power_trim_info->bb_gain[6][RF_PATH_D] = pg_power_5g[15] & 0x1f; + + power_trim_info->bb_gain[7][RF_PATH_A] = pg_power_5g[16] & 0x1f; + power_trim_info->bb_gain[7][RF_PATH_B] = pg_power_5g[17] & 0x1f; + power_trim_info->bb_gain[7][RF_PATH_C] = pg_power_5g[18] & 0x1f; + power_trim_info->bb_gain[7][RF_PATH_D] = pg_power_5g[19] & 0x1f; + + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | KFREE_FLAG_ON_5G; + + } + + phydm_set_power_trim_offset_8814b(dm); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b power trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < MAX_PATH_NUM_8814B; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b pwr_trim->bb_gain[%d][%d]=0x%X\n", + i, j, power_trim_info->bb_gain[i][j]); + } + } + } +} + +void phydm_get_tssi_trim_offset_8814b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 i, j; + u8 tssi_trim_2g[8] = {0}, tssi_trim_5g[24] = {0}; + + odm_efuse_one_byte_read(dm, TSSI_2GM_TXA_14B, &tssi_trim_2g[0], false); + odm_efuse_one_byte_read(dm, TSSI_2GM_TXB_14B, &tssi_trim_2g[1], false); + odm_efuse_one_byte_read(dm, TSSI_2GM_TXC_14B, &tssi_trim_2g[2], false); + odm_efuse_one_byte_read(dm, TSSI_2GM_TXD_14B, &tssi_trim_2g[3], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXA_14B, &tssi_trim_2g[4], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXB_14B, &tssi_trim_2g[5], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXC_14B, &tssi_trim_2g[6], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXD_14B, &tssi_trim_2g[7], false); + + j = 0; + for (i = 0; i < 8; i++) { + if (tssi_trim_2g[i] == 0xff) + j++; + } + + if (j == 8) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b 2g tssi trim no PG\n"); + } else { + power_trim_info->tssi_trim[0][RF_PATH_A] = (s8)tssi_trim_2g[0]; + power_trim_info->tssi_trim[0][RF_PATH_B] = (s8)tssi_trim_2g[1]; + power_trim_info->tssi_trim[0][RF_PATH_C] = (s8)tssi_trim_2g[2]; + power_trim_info->tssi_trim[0][RF_PATH_D] = (s8)tssi_trim_2g[3]; + power_trim_info->tssi_trim[1][RF_PATH_A] = (s8)tssi_trim_2g[0]; + power_trim_info->tssi_trim[1][RF_PATH_B] = (s8)tssi_trim_2g[1]; + power_trim_info->tssi_trim[1][RF_PATH_C] = (s8)tssi_trim_2g[2]; + power_trim_info->tssi_trim[1][RF_PATH_D] = (s8)tssi_trim_2g[3]; + power_trim_info->tssi_trim[2][RF_PATH_A] = (s8)tssi_trim_2g[4]; + power_trim_info->tssi_trim[2][RF_PATH_B] = (s8)tssi_trim_2g[5]; + power_trim_info->tssi_trim[2][RF_PATH_C] = (s8)tssi_trim_2g[6]; + power_trim_info->tssi_trim[2][RF_PATH_D] = (s8)tssi_trim_2g[7]; + + power_trim_info->flag = + power_trim_info->flag | TSSI_TRIM_FLAG_ON | KFREE_FLAG_ON_2G; + + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < MAX_PATH_NUM_8814B; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 2g tssi_trim[%d][%d]=0x%X\n", + i, j, power_trim_info->tssi_trim[i][j]); + } + } + } + + odm_efuse_one_byte_read(dm, TSSI_5GL1_TXA_14B, &tssi_trim_5g[0], false); + odm_efuse_one_byte_read(dm, TSSI_5GL1_TXB_14B, &tssi_trim_5g[1], false); + odm_efuse_one_byte_read(dm, TSSI_5GL1_TXC_14B, &tssi_trim_5g[2], false); + odm_efuse_one_byte_read(dm, TSSI_5GL1_TXD_14B, &tssi_trim_5g[3], false); + odm_efuse_one_byte_read(dm, TSSI_5GL2_TXA_14B, &tssi_trim_5g[4], false); + odm_efuse_one_byte_read(dm, TSSI_5GL2_TXB_14B, &tssi_trim_5g[5], false); + odm_efuse_one_byte_read(dm, TSSI_5GL2_TXC_14B, &tssi_trim_5g[6], false); + odm_efuse_one_byte_read(dm, TSSI_5GL2_TXD_14B, &tssi_trim_5g[7], false); + odm_efuse_one_byte_read(dm, TSSI_5GM1_TXA_14B, &tssi_trim_5g[8], false); + odm_efuse_one_byte_read(dm, TSSI_5GM1_TXB_14B, &tssi_trim_5g[9], false); + odm_efuse_one_byte_read(dm, TSSI_5GM1_TXC_14B, &tssi_trim_5g[10], false); + odm_efuse_one_byte_read(dm, TSSI_5GM1_TXD_14B, &tssi_trim_5g[11], false); + odm_efuse_one_byte_read(dm, TSSI_5GM2_TXA_14B, &tssi_trim_5g[12], false); + odm_efuse_one_byte_read(dm, TSSI_5GM2_TXB_14B, &tssi_trim_5g[13], false); + odm_efuse_one_byte_read(dm, TSSI_5GM2_TXC_14B, &tssi_trim_5g[14], false); + odm_efuse_one_byte_read(dm, TSSI_5GM2_TXD_14B, &tssi_trim_5g[15], false); + odm_efuse_one_byte_read(dm, TSSI_5GH1_TXA_14B, &tssi_trim_5g[16], false); + odm_efuse_one_byte_read(dm, TSSI_5GH1_TXB_14B, &tssi_trim_5g[17], false); + odm_efuse_one_byte_read(dm, TSSI_5GH1_TXC_14B, &tssi_trim_5g[18], false); + odm_efuse_one_byte_read(dm, TSSI_5GH1_TXD_14B, &tssi_trim_5g[19], false); + odm_efuse_one_byte_read(dm, TSSI_5GH2_TXA_14B, &tssi_trim_5g[20], false); + odm_efuse_one_byte_read(dm, TSSI_5GH2_TXB_14B, &tssi_trim_5g[21], false); + odm_efuse_one_byte_read(dm, TSSI_5GH2_TXC_14B, &tssi_trim_5g[22], false); + odm_efuse_one_byte_read(dm, TSSI_5GH2_TXD_14B, &tssi_trim_5g[23], false); + + j = 0; + for (i = 0; i < 24; i++) { + if (tssi_trim_5g[i] == 0xff) + j++; + } + + if (j == 24) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b 5g tssi trim no PG\n"); + } else { + power_trim_info->tssi_trim[3][RF_PATH_A] = (s8)tssi_trim_5g[0]; + power_trim_info->tssi_trim[3][RF_PATH_B] = (s8)tssi_trim_5g[1]; + power_trim_info->tssi_trim[3][RF_PATH_C] = (s8)tssi_trim_5g[2]; + power_trim_info->tssi_trim[3][RF_PATH_D] = (s8)tssi_trim_5g[3]; + power_trim_info->tssi_trim[4][RF_PATH_A] = (s8)tssi_trim_5g[4]; + power_trim_info->tssi_trim[4][RF_PATH_B] = (s8)tssi_trim_5g[5]; + power_trim_info->tssi_trim[4][RF_PATH_C] = (s8)tssi_trim_5g[6]; + power_trim_info->tssi_trim[4][RF_PATH_D] = (s8)tssi_trim_5g[7]; + power_trim_info->tssi_trim[5][RF_PATH_A] = (s8)tssi_trim_5g[8]; + power_trim_info->tssi_trim[5][RF_PATH_B] = (s8)tssi_trim_5g[9]; + power_trim_info->tssi_trim[5][RF_PATH_C] = (s8)tssi_trim_5g[10]; + power_trim_info->tssi_trim[5][RF_PATH_D] = (s8)tssi_trim_5g[11]; + power_trim_info->tssi_trim[6][RF_PATH_A] = (s8)tssi_trim_5g[12]; + power_trim_info->tssi_trim[6][RF_PATH_B] = (s8)tssi_trim_5g[13]; + power_trim_info->tssi_trim[6][RF_PATH_C] = (s8)tssi_trim_5g[14]; + power_trim_info->tssi_trim[6][RF_PATH_D] = (s8)tssi_trim_5g[15]; + power_trim_info->tssi_trim[7][RF_PATH_A] = (s8)tssi_trim_5g[16]; + power_trim_info->tssi_trim[7][RF_PATH_B] = (s8)tssi_trim_5g[17]; + power_trim_info->tssi_trim[7][RF_PATH_C] = (s8)tssi_trim_5g[18]; + power_trim_info->tssi_trim[7][RF_PATH_D] = (s8)tssi_trim_5g[19]; + power_trim_info->tssi_trim[8][RF_PATH_A] = (s8)tssi_trim_5g[20]; + power_trim_info->tssi_trim[8][RF_PATH_B] = (s8)tssi_trim_5g[21]; + power_trim_info->tssi_trim[8][RF_PATH_C] = (s8)tssi_trim_5g[22]; + power_trim_info->tssi_trim[8][RF_PATH_D] = (s8)tssi_trim_5g[23]; + + power_trim_info->flag = + power_trim_info->flag | TSSI_TRIM_FLAG_ON | KFREE_FLAG_ON_5G; + + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < MAX_PATH_NUM_8814B; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 5g tssi_trim[%d][%d]=0x%X\n", + i, j, power_trim_info->tssi_trim[i][j]); + } + } + } +} + +s8 phydm_get_tssi_trim_de_8814b(void *dm_void, u8 path) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 channel = *dm->channel, group = 0; + + if (channel >= 1 && channel <= 3) + group = 0; + else if (channel >= 4 && channel <= 9) + group = 1; + else if (channel >= 10 && channel <= 14) + group = 2; + else if (channel >= 36 && channel <= 50) + group = 3; + else if (channel >= 52 && channel <= 64) + group = 4; + else if (channel >= 100 && channel <= 118) + group = 5; + else if (channel >= 120 && channel <= 144) + group = 6; + else if (channel >= 149 && channel <= 165) + group = 7; + else if (channel >= 167 && channel <= 177) + group = 8; + else { + RF_DBG(dm, DBG_RF_MP, "[kfree] Channel(%d) is not exist in Group\n", + channel); + return 0; + } + + return power_trim_info->tssi_trim[group][path]; +} + +void phydm_set_pabias_bandedge_2g_rf_8814b(void *dm_void) +{ +#if 0 + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u32 rf_reg_51 = 0, rf_reg_52 = 0, rf_reg_53 = 0, rf_reg_3f = 0; + u8 i, j; + s32 pa_bias_tmp, bandedge_tmp, reg_tmp; + +#if 0 + /*2.4G bias*/ + /*rf3f == rf53*/ +#endif + for (i = 0; i < MAX_PATH_NUM_8814B; i++) { + rf_reg_51 = odm_get_rf_reg(dm, i, RF_0x51, RFREGOFFSETMASK); + rf_reg_52 = odm_get_rf_reg(dm, i, RF_0x52, RFREGOFFSETMASK); + rf_reg_53 = odm_get_rf_reg(dm, i, RF_0x53, RFREGOFFSETMASK); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 2g rf(0x51)=0x%X rf(0x52)=0x%X rf(0x53)=0x%X path=%d\n", + rf_reg_51, rf_reg_52, rf_reg_53, i); + + /*2.4G bias*/ + rf_reg_3f = rf_reg_53; + pa_bias_tmp = rf_reg_3f & 0xf; + + reg_tmp = pa_bias_tmp + power_trim_info->pa_bias_trim[0][i]; + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 2g pa bias reg_tmp(%d) = pa_bias_tmp(%d) + power_trim_info->pa_bias_trim[0][%d](%d)\n", + reg_tmp, pa_bias_tmp, i, power_trim_info->pa_bias_trim[0][i]); + +#if 0 + if (reg_tmp < 0) { + reg_tmp = 0; + RF_DBG(dm, DBG_RF_MP, + "[kfree] 2g pa bias reg_tmp < 0. Set 0 path=%d\n", i); + } else if (reg_tmp > 7) { + reg_tmp = 7; + RF_DBG(dm, DBG_RF_MP, + "[kfree] 2g pa bias reg_tmp > 7. Set 7 path=%d\n", i); + } +#endif + + rf_reg_3f = ((rf_reg_3f & 0xffff0) | reg_tmp); + rf_reg_3f = ((rf_reg_3f & 0x0ffff) | 0x10000); + + odm_set_rf_reg(dm, i, RF_0xef, BIT(10), 0x1); + for (j = 0; j <= 0xf; j++) { + odm_set_rf_reg(dm, i, RF_0x30, RFREGOFFSETMASK, (j << 16)); + odm_set_rf_reg(dm, i, RF_0x3f, RFREGOFFSETMASK, rf_reg_3f); + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 2G pa bias write RF_0x30=0x%05x RF_0x3f=0x%x path=%d\n", + (j << 16), rf_reg_3f, i); + } + odm_set_rf_reg(dm, i, RF_0xef, BIT(10), 0x0); + +#if 0 + /*2.4G bandedge*/ + /*rf3f =>*/ + /*rf51[3:1] = rf3f[17:15]*/ + /*rf52[2:0] = rf3f[14:12]*/ + /*rf52[18] = rf3f[11]*/ + /*rf51[6:4] = rf3f[10:8]*/ + /*rf51[11:8] = rf3f[7:4]*/ + /*rf51[16:13] = rf3f[3:0]*/ +#endif + /*2.4G bandedge*/ + rf_reg_3f = (((rf_reg_51 & 0xe) >> 1) << 15) | + ((rf_reg_52 & 0x7) << 12) | + (((rf_reg_52 & 0x40000) >> 18) << 11) | + (((rf_reg_51 & 0x70) >> 4) << 8) | + (((rf_reg_51 & 0xf00) >> 8) << 4) | + ((rf_reg_51 & 0x1e000) >> 13); + + bandedge_tmp = rf_reg_3f & 0xf; + + reg_tmp = bandedge_tmp + power_trim_info->pa_bias_trim[0][i]; + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 2g bandedge reg_tmp(%d) = bandedge_tmp(%d) + power_trim_info->pa_bias_trim[0][%d](%d)\n", + reg_tmp, bandedge_tmp, i, power_trim_info->pa_bias_trim[0][i]); + +#if 0 + if (reg_tmp < 0) { + reg_tmp = 0; + RF_DBG(dm, DBG_RF_MP, + "[kfree] 2g bandedge reg_tmp < 0. Set 0 path=%d\n", i); + } else if (reg_tmp > 7) { + reg_tmp = 7; + RF_DBG(dm, DBG_RF_MP, + "[kfree] 2g bandedge reg_tmp > 7. Set 7 path=%d\n", i); + } +#endif + + rf_reg_3f = ((rf_reg_3f & 0xffff0) | reg_tmp); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 2G bandedge RF_0x30=0x%05X RF_0x3f=0x%x path=%d\n", + 0x00001, rf_reg_3f, i); + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 2G bandedge RF_0x30=0x%05X RF_0x3f=0x%x path=%d\n", + 0x0000b, rf_reg_3f, i); + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 2G bandedge RF_0x30=0x%05X RF_0x3f=0x%x path=%d\n", + 0x00023, rf_reg_3f, i); + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 2G bandedge RF_0x30=0x%05X RF_0x3f=0x%x path=%d\n", + 0x00029, rf_reg_3f, i); + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 2G bandedge RF_0x30=0x%05X RF_0x3f=0x%x path=%d\n", + 0x0002a, rf_reg_3f, i); + + odm_set_rf_reg(dm, i, RF_0xef, BIT(8), 0x1); + odm_set_rf_reg(dm, i, RF_0x33, RFREGOFFSETMASK, 0x00001); + odm_set_rf_reg(dm, i, RF_0x3f, RFREGOFFSETMASK, rf_reg_3f); + odm_set_rf_reg(dm, i, RF_0x33, RFREGOFFSETMASK, 0x0000b); + odm_set_rf_reg(dm, i, RF_0x3f, RFREGOFFSETMASK, rf_reg_3f); + odm_set_rf_reg(dm, i, RF_0x33, RFREGOFFSETMASK, 0x00023); + odm_set_rf_reg(dm, i, RF_0x3f, RFREGOFFSETMASK, rf_reg_3f); + odm_set_rf_reg(dm, i, RF_0x33, RFREGOFFSETMASK, 0x00029); + odm_set_rf_reg(dm, i, RF_0x3f, RFREGOFFSETMASK, rf_reg_3f); + odm_set_rf_reg(dm, i, RF_0x33, RFREGOFFSETMASK, 0x0002a); + odm_set_rf_reg(dm, i, RF_0x3f, RFREGOFFSETMASK, rf_reg_3f); + odm_set_rf_reg(dm, i, RF_0xef, BIT(8), 0x0); + + } +#endif +} + +void phydm_set_pabias_bandedge_5g_rf_8814b(void *dm_void) +{ +#if 0 + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u32 rf_reg_18[MAX_PATH_NUM_8814B] = {0}, + rf_reg_61[15][MAX_PATH_NUM_8814B] = {0}, + rf_reg_62[3][MAX_PATH_NUM_8814B] = {0}; + u8 i, j; + u32 bandedge[15][MAX_PATH_NUM_8814B] = {0}, + pa_bias[3][MAX_PATH_NUM_8814B] = {0}; + + s32 pa_bias_tmp, reg_tmp; + + + for (i = 0; i < MAX_PATH_NUM_8814B; i++) { + rf_reg_18[i] = odm_get_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK); + + for (j = 0; j < 3; j++) { + if (j == 0) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x10d24); + else if (j == 1) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x30d64); + else if (j == 2) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x50da9); + + rf_reg_62[j][i] = odm_get_rf_reg(dm, i, 0x62, RFREGOFFSETMASK); + +#if 0 + /*5G bias*/ + /*rf62[19:16] == rf30[11:8]*/ + /*rf62[15:12] == rf30[7:4]*/ + /*rf62[11:8] == rf3030[3:0]*/ +#endif + pa_bias[j][i] = (((rf_reg_62[j][i] & 0xf0000) >> 16) << 8) | + (((rf_reg_62[j][i] & 0xf000) >> 12) << 4) | + ((rf_reg_62[j][i] & 0xf00) >> 8); + } + + for (j = 0; j < 15; j++) { + if (j == 0) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x10d24);/*ch36*/ + else if (j == 1) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x11926);/*ch38*/ + else if (j == 2) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x1252a);/*ch42*/ + else if (j == 3) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x1253a);/*ch58*/ + else if (j == 4) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x1193e);/*ch62*/ + else if (j == 5) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x10d40);/*ch64*/ + else if (j == 6) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x30d64);/*ch100*/ + else if (j == 7) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x31966);/*ch102*/ + else if (j == 8) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x3256a);/*ch106*/ + else if (j == 9) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x3257a);/*ch122*/ + else if (j == 10) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x31986);/*ch134*/ + else if (j == 11) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x30d8c);/*ch140*/ + else if (j == 12) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x50d95);/*ch149*/ + else if (j == 13) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x51997);/*ch151*/ + else if (j == 14) + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, 0x5259b);/*ch155*/ + + + rf_reg_61[j][i] = odm_get_rf_reg(dm, i, RF_0x61, RFREGOFFSETMASK); +#if 0 + /*5G bandedge*/ + /*rf61[11:8] == rf30[11:8]*/ + /*rf61[7:4] == rf30[7:4]*/ + /*rf61[3:0] == rf3030[3:0]*/ +#endif + bandedge[j][i] = rf_reg_61[j][i] & 0xfff; + } + + odm_set_rf_reg(dm, i, RF_0x18, RFREGOFFSETMASK, rf_reg_18[i]); + } + + for (i = 0; i < MAX_PATH_NUM_8814B; i++) { + for (j = 0; j < 3; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] pa_bias[%d][%d]=0x%x\n", j, i, pa_bias[j][i]); + } + } + + for (i = 0; i < MAX_PATH_NUM_8814B; i++) { + for (j = 0; j < 15; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] bandedge[%d][%d]=0x%x\n", j, i, bandedge[j][i]); + } + } + + /*5G bias*/ + for (i = 0; i < MAX_PATH_NUM_8814B; i++) { + odm_set_rf_reg(dm, i, RF_0xee, BIT(8), 0x1); + for (j = 0; j <= 0xb; j++) { + + if (j >= 0 && j <= 3) + pa_bias_tmp = pa_bias[0][i] & 0xf; + else if (j >= 4 && j <= 0x7) + pa_bias_tmp = pa_bias[1][i] & 0xf; + else if (j >= 0x8 && j <= 0xb) + pa_bias_tmp = pa_bias[2][i] & 0xf; + + reg_tmp = pa_bias_tmp + power_trim_info->pa_bias_trim[1][i]; + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 5g pa bias reg_tmp(%d) = pa_bias_tmp(%d) + power_trim_info->pa_bias_trim[1][%d](%d)\n", + reg_tmp, pa_bias_tmp, i, power_trim_info->pa_bias_trim[1][i]); +#if 0 + if (reg_tmp < 0) { + reg_tmp = 0; + RF_DBG(dm, DBG_RF_MP, + "[kfree] 5g pa bias reg_tmp < 0. Set 0 path=%d\n", i); + } else if (reg_tmp > 7) { + reg_tmp = 7; + RF_DBG(dm, DBG_RF_MP, + "[kfree] 5g pa bias reg_tmp > 7. Set 7 path=%d\n", i); + } +#endif + if (j >= 0 && j <= 3) + reg_tmp = ((pa_bias[0][i] & 0xffff0) | reg_tmp | (j << 12)); + else if (j >= 4 && j <= 0x7) + reg_tmp = ((pa_bias[1][i] & 0xffff0) | reg_tmp | (j << 12)); + else if (j >= 0x8 && j <= 0xb) + reg_tmp = ((pa_bias[2][i] & 0xffff0) | reg_tmp | (j << 12)); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b write RF_0x30=0x%05x path=%d\n", + reg_tmp, i); + + odm_set_rf_reg(dm, i, RF_0x30, RFREGOFFSETMASK, reg_tmp); + } + odm_set_rf_reg(dm, i, RF_0xee, BIT(8), 0x0); + } + + /*5G bandedge*/ + for (i = 0; i < MAX_PATH_NUM_8814B; i++) { + odm_set_rf_reg(dm, i, RF_0xee, BIT(9), 0x1); + for (j = 0; j <= 0xe; j++) { + reg_tmp = bandedge[j][i] + power_trim_info->pa_bias_trim[1][i]; + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b 5g bandedge reg_tmp(%d)(0x%X) = bandedge_org(%d) + power_trim_info->pa_bias_trim[1][%d](%d)\n", + reg_tmp, reg_tmp, bandedge[j][i], i, power_trim_info->pa_bias_trim[1][i]); +#if 0 + if (reg_tmp < 0) { + reg_tmp = 0; + RF_DBG(dm, DBG_RF_MP, + "[kfree] 5g bandedge reg_tmp < 0. Set 0 path=%d\n", i); + } else if (reg_tmp > 7) { + reg_tmp = 7; + RF_DBG(dm, DBG_RF_MP, + "[kfree] 5g bandedge reg_tmp > 7. Set 7 path=%d\n", i); + } +#endif + + reg_tmp = ((bandedge[j][i] & 0xffff0) | reg_tmp | (j << 12)); + + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8814b write RF_0x30=0x%05x path=%d\n", + reg_tmp, i); + + odm_set_rf_reg(dm, i, RF_0x30, RFREGOFFSETMASK, reg_tmp); + } + odm_set_rf_reg(dm, i, RF_0xee, BIT(9), 0x0); + } + +#endif +} + + +void phydm_get_pa_bias_offset_8814b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 i, j, k; + u8 tssi_pa_bias_2g[2] = {0}, tssi_pa_bias_5g[2] = {0}; + + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GAC_14B, &tssi_pa_bias_2g[0], false); + odm_efuse_one_byte_read(dm, PPG_PABIAS_2GBD_14B, &tssi_pa_bias_2g[1], false); + + j = 0; + for (i = 0; i < 2; i++) { + if (tssi_pa_bias_2g[i] == 0xff) + j++; + } + + if (j == 2) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b 2g PA Bias K no PG\n"); + } else { + power_trim_info->pa_bias_trim[0][RF_PATH_A] = tssi_pa_bias_2g[0] & 0xf; + power_trim_info->pa_bias_trim[0][RF_PATH_C] = (tssi_pa_bias_2g[0] & 0xf0) >> 4; + power_trim_info->pa_bias_trim[0][RF_PATH_B] = tssi_pa_bias_2g[1] & 0xf; + power_trim_info->pa_bias_trim[0][RF_PATH_D] = (tssi_pa_bias_2g[1] & 0xf0) >> 4; + + for (k = 0; k < MAX_PATH_NUM_8814B; k++) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b 2g PA Bias K efuse:0x%x path=%d\n", + power_trim_info->pa_bias_trim[0][k], k); + odm_set_rf_reg(dm, k, 0x60, 0x0000f000, power_trim_info->pa_bias_trim[0][k]); + } + +#if 0 + for (k = 0; k < MAX_PATH_NUM_8814B; k++) { + if ((power_trim_info->pa_bias_trim[0][k] & BIT(0)) == 0) + power_trim_info->pa_bias_trim[0][k] = (-1 * (power_trim_info->pa_bias_trim[0][k] >> 1)); + else + power_trim_info->pa_bias_trim[0][k] = (power_trim_info->pa_bias_trim[0][k] >> 1); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b 2g PA Bias K power_trim_info->pa_bias_trim[0][%d]=0x%x\n", + k, power_trim_info->pa_bias_trim[0][k]); + } + + phydm_set_pabias_bandedge_2g_rf_8814b(dm); +#endif + } + + odm_efuse_one_byte_read(dm, PPG_PABIAS_5GAC_14B, &tssi_pa_bias_5g[0], false); + odm_efuse_one_byte_read(dm, PPG_PABIAS_5GBD_14B, &tssi_pa_bias_5g[1], false); + + j = 0; + for (i = 0; i < 2; i++) { + if (tssi_pa_bias_5g[i] == 0xff) + j++; + } + + if (j == 2) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b 5g PA Bias K no PG\n"); + } else { + power_trim_info->pa_bias_trim[1][RF_PATH_A] = tssi_pa_bias_5g[0] & 0xf; + power_trim_info->pa_bias_trim[1][RF_PATH_C] = (tssi_pa_bias_5g[0] & 0xf0) >> 4; + power_trim_info->pa_bias_trim[1][RF_PATH_B] = tssi_pa_bias_5g[1] & 0xf; + power_trim_info->pa_bias_trim[1][RF_PATH_D] = (tssi_pa_bias_5g[1] & 0xf0) >> 4; + + for (k = 0; k < MAX_PATH_NUM_8814B; k++) { + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b 5g PA Bias K efuse:0x%x path=%d\n", + power_trim_info->pa_bias_trim[1][k], k); + + odm_set_rf_reg(dm, k, 0x60, 0x000f0000, power_trim_info->pa_bias_trim[1][k]); + } +#if 0 + for (k = 0; k < MAX_PATH_NUM_8814B; k++) { + if ((power_trim_info->pa_bias_trim[1][k] & BIT(0)) == 0) + power_trim_info->pa_bias_trim[1][k] = (-1 * (power_trim_info->pa_bias_trim[1][k] >> 1)); + else + power_trim_info->pa_bias_trim[1][k] = (power_trim_info->pa_bias_trim[1][k] >> 1); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b 5g PA Bias K power_trim_info->pa_bias_trim[1][%d]=0x%x\n", + k, power_trim_info->pa_bias_trim[1][k]); + } + + phydm_set_pabias_bandedge_5g_rf_8814b(dm); +#endif + } + + +} + +void phydm_get_thermal_trim_offset_8814b(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + u8 pg_therm = 0xff, i; + + odm_efuse_one_byte_read(dm, PPG_THERMAL_A_OFFSET_14B, &pg_therm, false); + + if (pg_therm != 0xff) { + for (i = 0; i < MAX_PATH_NUM_8814B; i++) { + if (i == 0) + odm_efuse_one_byte_read(dm, PPG_THERMAL_A_OFFSET_14B, &pg_therm, false); + else if (i == 1) + odm_efuse_one_byte_read(dm, PPG_THERMAL_B_OFFSET_14B, &pg_therm, false); + else if (i == 2) + odm_efuse_one_byte_read(dm, PPG_THERMAL_C_OFFSET_14B, &pg_therm, false); + else if (i == 3) + odm_efuse_one_byte_read(dm, PPG_THERMAL_D_OFFSET_14B, &pg_therm, false); + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b Efuse thermal S%d:0x%x\n", i, pg_therm); + pg_therm = pg_therm & 0x1f; + if ((pg_therm & BIT(0)) == 0) + power_trim_info->multi_thermal[i] = (-1 * (pg_therm >> 1)); + else + power_trim_info->multi_thermal[i] = (pg_therm >> 1); + } + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b thermal trim flag:0x%02x\n", + power_trim_info->flag); + + for (i = 0; i < MAX_RF_PATH; i++) { + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8814b thermal S%d:%d\n", + i ,power_trim_info->multi_thermal[i]); + } +} + +void phydm_get_thermal_trim_offset_8723f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + u8 pg_therm = 0xff, thermal[2] = {0}; +#if 0 + odm_efuse_one_byte_read(dm, PPG_THERMAL_A_OFFSET_22C, &pg_therm, false); + + if (pg_therm != 0xff) { + /*s0*/ + pg_therm = pg_therm & 0x1f; + + thermal[RF_PATH_A] = + ((pg_therm & 0x1) << 3) | ((pg_therm >> 1) & 0x7); + + odm_set_rf_reg(dm, RF_PATH_A, RF_0x43, 0x000f0000, thermal[RF_PATH_A]); + + /*s1*/ + odm_efuse_one_byte_read(dm, PPG_THERMAL_B_OFFSET_22C, &pg_therm, false); + + pg_therm = pg_therm & 0x1f; + + thermal[RF_PATH_B] = ((pg_therm & 0x1) << 3) | ((pg_therm >> 1) & 0x7); + + odm_set_rf_reg(dm, RF_PATH_B, RF_0x43, 0x000f0000, thermal[RF_PATH_B]); + + power_trim_info->flag |= KFREE_FLAG_THERMAL_K_ON; + + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822c thermal trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822c thermalA:%d thermalB:%d\n", + thermal[RF_PATH_A], + thermal[RF_PATH_B]); +#endif +} + +void phydm_get_set_power_trim_offset_8723f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + u8 pg_power = 0xff, i, j; + u8 pg_power1, pg_power2 , pg_power3, pg_power4, pg_power5; +#if 0 + odm_efuse_one_byte_read(dm, PPG_2GL_TXAB_22C, &pg_power1, false); + odm_efuse_one_byte_read(dm, PPG_2GM_TXAB_22C, &pg_power2, false); + odm_efuse_one_byte_read(dm, PPG_2GH_TXAB_22C, &pg_power3, false); + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_22C, &pg_power4, false); + odm_efuse_one_byte_read(dm, PPG_5GL1_TXB_22C, &pg_power5, false); + + if (pg_power1 != 0xff || pg_power2 != 0xff || pg_power3 != 0xff || + pg_power4 != 0xff || pg_power5 != 0xff) { + odm_efuse_one_byte_read(dm, PPG_2GL_TXAB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[0][0] = pg_power & 0xf; + power_trim_info->bb_gain[0][1] = (pg_power & 0xf0) >> 4; + + odm_efuse_one_byte_read(dm, PPG_2GM_TXAB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[1][0] = pg_power & 0xf; + power_trim_info->bb_gain[1][1] = (pg_power & 0xf0) >> 4; + + odm_efuse_one_byte_read(dm, PPG_2GH_TXAB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[2][0] = pg_power & 0xf; + power_trim_info->bb_gain[2][1] = (pg_power & 0xf0) >> 4; + + odm_efuse_one_byte_read(dm, PPG_5GL1_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[3][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GL1_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[3][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GL2_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[4][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GL2_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[4][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GM1_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[5][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GM1_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[5][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GM2_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[6][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GM2_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[6][1] = pg_power & 0x1f; + + odm_efuse_one_byte_read(dm, PPG_5GH1_TXA_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[7][0] = pg_power & 0x1f; + odm_efuse_one_byte_read(dm, PPG_5GH1_TXB_22C, &pg_power, false); + if (pg_power == 0xff) + pg_power = 0; + power_trim_info->bb_gain[7][1] = pg_power & 0x1f; + + power_trim_info->flag = + power_trim_info->flag | KFREE_FLAG_ON | + KFREE_FLAG_ON_2G | + KFREE_FLAG_ON_5G; + + phydm_set_power_trim_offset_8822c(dm); + } + + RF_DBG(dm, DBG_RF_MP, "[kfree] 8822c power trim flag:0x%02x\n", + power_trim_info->flag); + + if (power_trim_info->flag & KFREE_FLAG_ON) { + for (i = 0; i < KFREE_BAND_NUM; i++) { + for (j = 0; j < 2; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8822c pwr_trim->bb_gain[%d][%d]=0x%X\n", + i, j, power_trim_info->bb_gain[i][j]); + } + } + } +#endif +} + +void phydm_get_tssi_trim_offset_8723f(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + u8 i, j, k; + u8 pg_power[16] = {0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff}; +#if 1 + odm_efuse_one_byte_read(dm, TSSI_2GM_TXA_22C, &pg_power[0], false); + odm_efuse_one_byte_read(dm, TSSI_2GM_TXB_22C, &pg_power[1], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXA_22C, &pg_power[2], false); + odm_efuse_one_byte_read(dm, TSSI_2GH_TXB_22C, &pg_power[3], false); + odm_efuse_one_byte_read(dm, TSSI_5GL1_TXA_22C, &pg_power[4], false); + //odm_efuse_one_byte_read(dm, TSSI_5GL1_TXB_22C, &pg_power[5], false); + odm_efuse_one_byte_read(dm, TSSI_5GL2_TXA_22C, &pg_power[6], false); + //odm_efuse_one_byte_read(dm, TSSI_5GL2_TXB_22C, &pg_power[7], false); + odm_efuse_one_byte_read(dm, TSSI_5GM1_TXA_22C, &pg_power[8], false); + //odm_efuse_one_byte_read(dm, TSSI_5GM1_TXB_22C, &pg_power[9], false); + odm_efuse_one_byte_read(dm, TSSI_5GM2_TXA_22C, &pg_power[10], false); + //odm_efuse_one_byte_read(dm, TSSI_5GM2_TXB_22C, &pg_power[11], false); + odm_efuse_one_byte_read(dm, TSSI_5GH1_TXA_22C, &pg_power[12], false); + //odm_efuse_one_byte_read(dm, TSSI_5GH1_TXB_22C, &pg_power[13], false); + odm_efuse_one_byte_read(dm, TSSI_5GH2_TXA_22C, &pg_power[14], false); + //odm_efuse_one_byte_read(dm, TSSI_5GH2_TXB_22C, &pg_power[15], false); + + j = 0; + for (i = 0; i < 16; i++) { + if ((pg_power[i] & 0xff) == 0xff) + j++; + } + + if (j == 16) { + for (i = 0; i < 9; i++) + for(k = 0; i < 2; i++) + power_trim_info->tssi_trim[i][k] = 0; + RF_DBG(dm, DBG_RF_MP, "[kfree] 8723F tssi trim no PG\n"); + } else { + //power_trim_info->tssi_trim[0][0] = (s8)pg_power[0]; + //power_trim_info->tssi_trim[0][1] = (s8)pg_power[1]; + power_trim_info->tssi_trim[0][0] = (s8)pg_power[0]; + power_trim_info->tssi_trim[0][1] = (s8)pg_power[1]; + power_trim_info->tssi_trim[1][0] = (s8)pg_power[2]; + power_trim_info->tssi_trim[1][1] = (s8)pg_power[3]; + power_trim_info->tssi_trim[2][0] = (s8)pg_power[4]; + power_trim_info->tssi_trim[2][1] = (s8)pg_power[5]; + power_trim_info->tssi_trim[3][0] = (s8)pg_power[6]; + power_trim_info->tssi_trim[3][1] = (s8)pg_power[7]; + power_trim_info->tssi_trim[4][0] = (s8)pg_power[8]; + power_trim_info->tssi_trim[4][1] = (s8)pg_power[9]; + power_trim_info->tssi_trim[5][0] = (s8)pg_power[10]; + power_trim_info->tssi_trim[5][1] = (s8)pg_power[11]; + power_trim_info->tssi_trim[6][0] = (s8)pg_power[12]; + power_trim_info->tssi_trim[6][1] = (s8)pg_power[13]; + power_trim_info->tssi_trim[7][0] = (s8)pg_power[14]; + power_trim_info->tssi_trim[7][1] = (s8)pg_power[15]; + + power_trim_info->flag = + power_trim_info->flag | TSSI_TRIM_FLAG_ON; + + if (power_trim_info->flag & TSSI_TRIM_FLAG_ON) { + for (i = 0; i < 8; i++) { //KFREE_BAND_NUM + for (j = 0; j < 2; j++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] 8723F tssi_trim[%d][%d]=0x%X\n", + i, j, power_trim_info->tssi_trim[i][j]); + } + } + } + } +#endif +} + +s8 phydm_get_tssi_trim_de_8723f(void *dm_void, u8 path) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + u8 channel = *dm->channel, group = 0; + + if (channel >= 1 && channel <= 7) { + group = 0; + } else if (channel >= 8 && channel <= 14) { + group = 1; + } else if (channel >= 36 && channel <= 50) { + group = 2; + } else if (channel >= 52 && channel <= 64) { + group = 3; + } else if (channel >= 100 && channel <= 128) { + group = 4; + } else if (channel >= 129 && channel <= 144) { + group = 5; + } else if (channel >= 149 && channel <= 163) { + group = 6; + } else if (channel >= 164 && channel <= 177) { + group = 7; + } else { + RF_DBG(dm, DBG_RF_MP, "[kfree] Channel(%d) is not exist in Group\n", channel); + return 0; + } + + return power_trim_info->tssi_trim[group][path]; +} + +s8 phydm_get_tssi_trim_de(void *dm_void, u8 path) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + if (dm->support_ic_type & ODM_RTL8822C) + return phydm_get_tssi_trim_de_8822c(dm, path); + else if (dm->support_ic_type & ODM_RTL8812F) + return phydm_get_tssi_trim_de_8812f(dm, path); + else if (dm->support_ic_type & ODM_RTL8197G) + return phydm_get_tssi_trim_de_8197g(dm, path); + else if (dm->support_ic_type & ODM_RTL8814B) + return phydm_get_tssi_trim_de_8814b(dm, path); + else if (dm->support_ic_type & ODM_RTL8723F) + return phydm_get_tssi_trim_de_8723f(dm, path); + else + return 0; +} + +void phydm_do_new_kfree(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + if (dm->support_ic_type & ODM_RTL8822C) { + phydm_get_set_thermal_trim_offset_8822c(dm); + phydm_get_set_power_trim_offset_8822c(dm); + phydm_get_set_pa_bias_offset_8822c(dm); + phydm_get_tssi_trim_offset_8822c(dm); + } + + if (dm->support_ic_type & ODM_RTL8812F) { + phydm_get_set_thermal_trim_offset_8812f(dm); + phydm_get_set_power_trim_offset_8812f(dm); + phydm_get_set_pa_bias_offset_8812f(dm); + phydm_get_tssi_trim_offset_8812f(dm); + } + + if (dm->support_ic_type & ODM_RTL8195B) { + phydm_get_thermal_trim_offset_8195b(dm); + phydm_get_set_power_trim_offset_8195b(dm); + phydm_get_set_pa_bias_offset_8195b(dm); + } + + if (dm->support_ic_type & ODM_RTL8721D) { + phydm_get_thermal_trim_offset_8721d(dm); + phydm_get_set_power_trim_offset_8721d(dm); + /*phydm_get_set_pa_bias_offset_8721d(dm);*/ + } + + if (dm->support_ic_type & ODM_RTL8198F) { + phydm_get_pa_bias_offset_8198f(dm); + phydm_get_set_lna_offset_8198f(dm); + } + + if (dm->support_ic_type & ODM_RTL8197G) { + phydm_get_thermal_trim_offset_8197g(dm); + phydm_get_set_power_trim_offset_8197g(dm); + phydm_get_set_pa_bias_offset_8197g(dm); + phydm_get_tssi_trim_offset_8197g(dm); + phydm_get_set_lna_offset_8197g(dm); + } + + if (dm->support_ic_type & ODM_RTL8710C) { + phydm_get_thermal_trim_offset_8710c(dm); + phydm_get_set_power_trim_offset_8710c(dm); + phydm_get_set_pa_bias_offset_8710c(dm); + } + + if (dm->support_ic_type & ODM_RTL8814B) { + phydm_get_thermal_trim_offset_8814b(dm); + phydm_get_set_power_trim_offset_8814b(dm); + phydm_get_pa_bias_offset_8814b(dm); + phydm_get_tssi_trim_offset_8814b(dm); + } + if (dm->support_ic_type & ODM_RTL8723F) { + phydm_get_thermal_trim_offset_8723f(dm); + phydm_get_set_power_trim_offset_8723f(dm); + //phydm_get_set_pa_bias_offset_8723f(dm); + phydm_get_tssi_trim_offset_8723f(dm); + } +} + +void phydm_set_kfree_to_rf(void *dm_void, u8 e_rf_path, u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + if (dm->support_ic_type & ODM_RTL8814A) + phydm_set_kfree_to_rf_8814a(dm, e_rf_path, data); + + if ((dm->support_ic_type & ODM_RTL8821C) && + (*dm->band_type == ODM_BAND_2_4G)) + phydm_set_kfree_to_rf_8821c(dm, e_rf_path, true, data); + else if (dm->support_ic_type & ODM_RTL8821C) + phydm_set_kfree_to_rf_8821c(dm, e_rf_path, false, data); + + if (dm->support_ic_type & ODM_RTL8822B) + phydm_set_kfree_to_rf_8822b(dm, e_rf_path, data); + + if (dm->support_ic_type & ODM_RTL8710B) + phydm_set_kfree_to_rf_8710b(dm, e_rf_path, data); + + if (dm->support_ic_type & ODM_RTL8198F) + phydm_set_kfree_to_rf_8198f(dm, e_rf_path, data); +} + +void phydm_clear_kfree_to_rf(void *dm_void, u8 e_rf_path, u8 data) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + if (dm->support_ic_type & ODM_RTL8822B) + phydm_clear_kfree_to_rf_8822b(dm, e_rf_path, 1); + + if (dm->support_ic_type & ODM_RTL8821C) + phydm_clear_kfree_to_rf_8821c(dm, e_rf_path, 1); + + if (dm->support_ic_type & ODM_RTL8198F) + phydm_clear_kfree_to_rf_8198f(dm, e_rf_path, 0); +} + +void phydm_get_thermal_trim_offset(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) + void *adapter = dm->adapter; + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + PEFUSE_HAL pEfuseHal = &hal_data->EfuseHal; + u1Byte eFuseContent[DCMD_EFUSE_MAX_SECTION_NUM * EFUSE_MAX_WORD_UNIT * 2]; + + if (HAL_MAC_Dump_EFUSE(&GET_HAL_MAC_INFO((PADAPTER)adapter), EFUSE_WIFI, eFuseContent, pEfuseHal->PhysicalLen_WiFi, HAL_MAC_EFUSE_PHYSICAL, HAL_MAC_EFUSE_PARSE_DRV) != RT_STATUS_SUCCESS) + RF_DBG(dm, DBG_RF_MP, "[kfree] dump efuse fail !!!\n"); +#endif + + if (dm->support_ic_type & ODM_RTL8821C) + phydm_get_thermal_trim_offset_8821c(dm_void); + else if (dm->support_ic_type & ODM_RTL8822B) + phydm_get_thermal_trim_offset_8822b(dm_void); + else if (dm->support_ic_type & ODM_RTL8710B) + phydm_get_thermal_trim_offset_8710b(dm_void); + else if (dm->support_ic_type & ODM_RTL8192F) + phydm_get_thermal_trim_offset_8192f(dm_void); + else if (dm->support_ic_type & ODM_RTL8198F) + phydm_get_thermal_trim_offset_8198f(dm_void); +} + +void phydm_get_power_trim_offset(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if 0 //(DM_ODM_SUPPORT_TYPE & ODM_WIN) // 2017 MH DM Should use the same code.s + void *adapter = dm->adapter; + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + PEFUSE_HAL pEfuseHal = &hal_data->EfuseHal; + u1Byte eFuseContent[DCMD_EFUSE_MAX_SECTION_NUM * EFUSE_MAX_WORD_UNIT * 2]; + + if (HAL_MAC_Dump_EFUSE(&GET_HAL_MAC_INFO(adapter), EFUSE_WIFI, eFuseContent, pEfuseHal->PhysicalLen_WiFi, HAL_MAC_EFUSE_PHYSICAL, HAL_MAC_EFUSE_PARSE_DRV) != RT_STATUS_SUCCESS) + RF_DBG(dm, DBG_RF_MP, "[kfree] dump efuse fail !!!\n"); +#endif + + if (dm->support_ic_type & ODM_RTL8821C) + phydm_get_power_trim_offset_8821c(dm_void); + else if (dm->support_ic_type & ODM_RTL8822B) + phydm_get_power_trim_offset_8822b(dm_void); + else if (dm->support_ic_type & ODM_RTL8710B) + phydm_get_power_trim_offset_8710b(dm_void); + else if (dm->support_ic_type & ODM_RTL8192F) + phydm_get_power_trim_offset_8192f(dm_void); + else if (dm->support_ic_type & ODM_RTL8198F) + phydm_get_power_trim_offset_8198f(dm_void); +} + +void phydm_get_pa_bias_offset(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) + void *adapter = dm->adapter; + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + PEFUSE_HAL pEfuseHal = &hal_data->EfuseHal; + u1Byte eFuseContent[DCMD_EFUSE_MAX_SECTION_NUM * EFUSE_MAX_WORD_UNIT * 2]; + + if (HAL_MAC_Dump_EFUSE(&GET_HAL_MAC_INFO((PADAPTER)adapter), EFUSE_WIFI, eFuseContent, pEfuseHal->PhysicalLen_WiFi, HAL_MAC_EFUSE_PHYSICAL, HAL_MAC_EFUSE_PARSE_DRV) != RT_STATUS_SUCCESS) + RF_DBG(dm, DBG_RF_MP, "[kfree] dump efuse fail !!!\n"); +#endif + + if (dm->support_ic_type & ODM_RTL8822B) + phydm_get_pa_bias_offset_8822b(dm_void); +} + +s8 phydm_get_thermal_offset(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + return power_trim_info->thermal; + else + return 0; +} + +s8 phydm_get_multi_thermal_offset(void *dm_void, u8 path) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *power_trim_info = &dm->power_trim_data; + + if (power_trim_info->flag & KFREE_FLAG_THERMAL_K_ON) + return power_trim_info->multi_thermal[path]; + else + return 0; +} + +void phydm_do_kfree(void *dm_void, u8 channel_to_sw) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct odm_power_trim_data *pwrtrim = &dm->power_trim_data; + u8 channel_idx = 0, rfpath = 0, max_path = 0, kfree_band_num = 0; + u8 i, j; + s8 bb_gain; + + if (dm->support_ic_type & ODM_RTL8814A) + max_path = 4; /*0~3*/ + else if (dm->support_ic_type & + (ODM_RTL8812 | ODM_RTL8822B | ODM_RTL8192F)) { + max_path = 2; /*0~1*/ + kfree_band_num = KFREE_BAND_NUM; + } else if (dm->support_ic_type & ODM_RTL8821C) { + max_path = 1; + kfree_band_num = KFREE_BAND_NUM; + } else if (dm->support_ic_type & ODM_RTL8710B) { + max_path = 1; + kfree_band_num = 1; + } else if (dm->support_ic_type & ODM_RTL8198F) { + max_path = 4; + kfree_band_num = 3; + } + + if (dm->support_ic_type & + (ODM_RTL8192F | ODM_RTL8822B | ODM_RTL8821C | + ODM_RTL8814A | ODM_RTL8710B)) { + for (i = 0; i < kfree_band_num; i++) { + for (j = 0; j < max_path; j++) + RF_DBG(dm, DBG_RF_MP, + "[kfree] PwrTrim->gain[%d][%d]=0x%X\n", + i, j, pwrtrim->bb_gain[i][j]); + } + } + if (*dm->band_type == ODM_BAND_2_4G && + pwrtrim->flag & KFREE_FLAG_ON_2G) { + if (!(dm->support_ic_type & ODM_RTL8192F)) { + if (channel_to_sw >= 1 && channel_to_sw <= 14) + channel_idx = PHYDM_2G; + for (rfpath = RF_PATH_A; rfpath < max_path; rfpath++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] %s:chnl=%d PATH=%d gain:0x%X\n", + __func__, channel_to_sw, rfpath, + pwrtrim->bb_gain[channel_idx][rfpath]); + bb_gain = pwrtrim->bb_gain[channel_idx][rfpath]; + phydm_set_kfree_to_rf(dm, rfpath, bb_gain); + } + } else if (dm->support_ic_type & ODM_RTL8192F) { + if (channel_to_sw >= 1 && channel_to_sw <= 3) + channel_idx = 0; + if (channel_to_sw >= 4 && channel_to_sw <= 9) + channel_idx = 1; + if (channel_to_sw >= 10 && channel_to_sw <= 14) + channel_idx = 2; + for (rfpath = RF_PATH_A; rfpath < max_path; rfpath++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] %s:chnl=%d PATH=%d gain:0x%X\n", + __func__, channel_to_sw, rfpath, + pwrtrim->bb_gain[channel_idx][rfpath]); + bb_gain = pwrtrim->bb_gain[channel_idx][rfpath]; + phydm_set_kfree_to_rf_8192f(dm, rfpath, + channel_idx, + bb_gain); + } + } + } else if (*dm->band_type == ODM_BAND_5G && + pwrtrim->flag & KFREE_FLAG_ON_5G) { + if (channel_to_sw >= 36 && channel_to_sw <= 48) + channel_idx = PHYDM_5GLB1; + if (channel_to_sw >= 52 && channel_to_sw <= 64) + channel_idx = PHYDM_5GLB2; + if (channel_to_sw >= 100 && channel_to_sw <= 120) + channel_idx = PHYDM_5GMB1; + if (channel_to_sw >= 122 && channel_to_sw <= 144) + channel_idx = PHYDM_5GMB2; + if (channel_to_sw >= 149 && channel_to_sw <= 177) + channel_idx = PHYDM_5GHB; + + for (rfpath = RF_PATH_A; rfpath < max_path; rfpath++) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] %s: channel=%d PATH=%d bb_gain:0x%X\n", + __func__, channel_to_sw, rfpath, + pwrtrim->bb_gain[channel_idx][rfpath]); + bb_gain = pwrtrim->bb_gain[channel_idx][rfpath]; + phydm_set_kfree_to_rf(dm, rfpath, bb_gain); + } + } else { + RF_DBG(dm, DBG_RF_MP, "[kfree] Set default Register\n"); + if (!(dm->support_ic_type & ODM_RTL8192F)) { + for (rfpath = RF_PATH_A; rfpath < max_path; rfpath++) { + bb_gain = pwrtrim->bb_gain[channel_idx][rfpath]; + phydm_clear_kfree_to_rf(dm, rfpath, bb_gain); + } + } +#if 0 + /*else if(dm->support_ic_type & ODM_RTL8192F){ + if (channel_to_sw >= 1 && channel_to_sw <= 3) + channel_idx = 0; + if (channel_to_sw >= 4 && channel_to_sw <= 9) + channel_idx = 1; + if (channel_to_sw >= 9 && channel_to_sw <= 14) + channel_idx = 2; + for (rfpath = RF_PATH_A; rfpath < max_path; rfpath++) + phydm_clear_kfree_to_rf_8192f(dm, rfpath, pwrtrim->bb_gain[channel_idx][rfpath]); + }*/ +#endif + } +} + +void phydm_config_new_kfree(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + + if (cali_info->reg_rf_kfree_enable == 2) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] %s: reg_rf_kfree_enable == 2, Disable\n", + __func__); + return; + } else if (cali_info->reg_rf_kfree_enable == 1 || + cali_info->reg_rf_kfree_enable == 0) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] %s: reg_rf_kfree_enable == true\n", __func__); + + phydm_do_new_kfree(dm); + } +} + +void phydm_config_kfree(void *dm_void, u8 channel_to_sw) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + struct odm_power_trim_data *pwrtrim = &dm->power_trim_data; + + RF_DBG(dm, DBG_RF_MP, "===>[kfree] phy_ConfigKFree()\n"); + + if (cali_info->reg_rf_kfree_enable == 2) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] %s: reg_rf_kfree_enable == 2, Disable\n", + __func__); + return; + } else if (cali_info->reg_rf_kfree_enable == 1 || + cali_info->reg_rf_kfree_enable == 0) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] %s: reg_rf_kfree_enable == true\n", __func__); + /*Make sure the targetval is defined*/ + if (!(pwrtrim->flag & KFREE_FLAG_ON)) { + RF_DBG(dm, DBG_RF_MP, + "[kfree] %s: efuse is 0xff, KFree not work\n", + __func__); + return; + } +#if 0 + /*if kfree_table[0] == 0xff, means no Kfree*/ +#endif + phydm_do_kfree(dm, channel_to_sw); + } + RF_DBG(dm, DBG_RF_MP, "<===[kfree] phy_ConfigKFree()\n"); +} + +void phydm_set_lna_trim_offset (void *dm_void, u8 path, u8 cg_cs, u8 enable) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + if (dm->support_ic_type & ODM_RTL8197G) + phydm_set_lna_trim_offset_8197g(dm, path, cg_cs, enable); +} + diff --git a/hal/phydm/halrf/halrf_kfree.h b/hal/phydm/halrf/halrf_kfree.h new file mode 100644 index 0000000..2de6b6b --- /dev/null +++ b/hal/phydm/halrf/halrf_kfree.h @@ -0,0 +1,296 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALRF_KFREE_H__ +#define __HALRF_KFREE_H__ + +#define KFREE_VERSION "1.0" + +#define KFREE_BAND_NUM 9 +#define KFREE_CH_NUM 3 + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_AP)) + +#define BB_GAIN_NUM 6 + +#endif + +#define KFREE_FLAG_ON BIT(0) +#define KFREE_FLAG_THERMAL_K_ON BIT(1) + +#define KFREE_FLAG_ON_2G BIT(2) +#define KFREE_FLAG_ON_5G BIT(3) + +#define PA_BIAS_FLAG_ON BIT(4) + +#define TSSI_TRIM_FLAG_ON BIT(5) + +#define LNA_FLAG_ON BIT(6) + + +#define PPG_THERMAL_OFFSET_98F 0x50 +#define PPG_2GM_TXAB_98F 0x51 +#define PPG_2GM_TXCD_98F 0x52 +#define PPG_2GL_TXAB_98F 0x53 +#define PPG_2GL_TXCD_98F 0x54 +#define PPG_2GH_TXAB_98F 0x55 +#define PPG_2GH_TXCD_98F 0x56 + +#define PPG_PABIAS_2GAB_98F 0x57 +#define PPG_PABIAS_2GCD_98F 0x58 + +#define PPG_LNA_2GA_98F 0x59 +#define PPG_LNA_2GB_98F 0x5a +#define PPG_LNA_2GC_98F 0x5b +#define PPG_LNA_2GD_98F 0x5c + +#define PPG_THERMAL_OFFSET_21C 0x1EF +#define PPG_2G_TXAB_21C 0x1EE +#define PPG_5GL1_TXA_21C 0x1EC +#define PPG_5GL2_TXA_21C 0x1E8 +#define PPG_5GM1_TXA_21C 0x1E4 +#define PPG_5GM2_TXA_21C 0x1E0 +#define PPG_5GH1_TXA_21C 0x1DC + +#define PPG_THERMAL_OFFSET_22B 0x3EF +#define PPG_2G_TXAB_22B 0x3EE +#define PPG_2G_TXCD_22B 0x3ED +#define PPG_5GL1_TXA_22B 0x3EC +#define PPG_5GL1_TXB_22B 0x3EB +#define PPG_5GL1_TXC_22B 0x3EA +#define PPG_5GL1_TXD_22B 0x3E9 +#define PPG_5GL2_TXA_22B 0x3E8 +#define PPG_5GL2_TXB_22B 0x3E7 +#define PPG_5GL2_TXC_22B 0x3E6 +#define PPG_5GL2_TXD_22B 0x3E5 +#define PPG_5GM1_TXA_22B 0x3E4 +#define PPG_5GM1_TXB_22B 0x3E3 +#define PPG_5GM1_TXC_22B 0x3E2 +#define PPG_5GM1_TXD_22B 0x3E1 +#define PPG_5GM2_TXA_22B 0x3E0 +#define PPG_5GM2_TXB_22B 0x3DF +#define PPG_5GM2_TXC_22B 0x3DE +#define PPG_5GM2_TXD_22B 0x3DD +#define PPG_5GH1_TXA_22B 0x3DC +#define PPG_5GH1_TXB_22B 0x3DB +#define PPG_5GH1_TXC_22B 0x3DA +#define PPG_5GH1_TXD_22B 0x3D9 + +#define PPG_PABIAS_2GA_22B 0x3D5 +#define PPG_PABIAS_2GB_22B 0x3D6 + +#define PPG_THERMAL_A_OFFSET_22C 0x1ef +#define PPG_THERMAL_B_OFFSET_22C 0x1b0 +#define PPG_2GL_TXAB_22C 0x1d4 +#define PPG_2GM_TXAB_22C 0x1ee +#define PPG_2GH_TXAB_22C 0x1d2 +#define PPG_5GL1_TXA_22C 0x1ec +#define PPG_5GL1_TXB_22C 0x1eb +#define PPG_5GL2_TXA_22C 0x1e8 +#define PPG_5GL2_TXB_22C 0x1e7 +#define PPG_5GM1_TXA_22C 0x1e4 +#define PPG_5GM1_TXB_22C 0x1e3 +#define PPG_5GM2_TXA_22C 0x1e0 +#define PPG_5GM2_TXB_22C 0x1df +#define PPG_5GH1_TXA_22C 0x1dc +#define PPG_5GH1_TXB_22C 0x1db + +#define PPG_PABIAS_2GA_22C 0x1d6 +#define PPG_PABIAS_2GB_22C 0x1d5 +#define PPG_PABIAS_5GA_22C 0x1d8 +#define PPG_PABIAS_5GB_22C 0x1d7 + +#define TSSI_2GM_TXA_22C 0x1c0 +#define TSSI_2GM_TXB_22C 0x1bf +#define TSSI_2GH_TXA_22C 0x1be +#define TSSI_2GH_TXB_22C 0x1bd +#define TSSI_5GL1_TXA_22C 0x1bc +#define TSSI_5GL1_TXB_22C 0x1bb +#define TSSI_5GL2_TXA_22C 0x1ba +#define TSSI_5GL2_TXB_22C 0x1b9 +#define TSSI_5GM1_TXA_22C 0x1b8 +#define TSSI_5GM1_TXB_22C 0x1b7 +#define TSSI_5GM2_TXA_22C 0x1b6 +#define TSSI_5GM2_TXB_22C 0x1b5 +#define TSSI_5GH1_TXA_22C 0x1b4 +#define TSSI_5GH1_TXB_22C 0x1b3 +#define TSSI_5GH2_TXA_22C 0x1b2 +#define TSSI_5GH2_TXB_22C 0x1b1 + +/*8195B*/ +#define PPG_THERMAL_OFFSET_95B 0x1ef +#define PPG_2GL_TXA_95B 0x1d4 +#define PPG_2GM_TXA_95B 0x1ee +#define PPG_2GH_TXA_95B 0x1d2 +#define PPG_5GL1_TXA_95B 0x1ec +#define PPG_5GL2_TXA_95B 0x1e8 +#define PPG_5GM1_TXA_95B 0x1e4 +#define PPG_5GM2_TXA_95B 0x1e0 +#define PPG_5GH1_TXA_95B 0x1dc + +#define PPG_PABIAS_2GA_95B 0x1d6 +#define PPG_PABIAS_5GA_95B 0x1d8 + +/*8721D*/ +/*#define KFREE_BAND_NUM_8721D 6*/ +#define PPG_THERMAL_OFFSET_8721D 0x1EF +#define PPG_2G_TXA_8721D 0x1EE +#define PPG_5GL1_TXA_8721D 0x1ED +#define PPG_5GL2_TXA_8721D 0x1EC +#define PPG_5GM1_TXA_8721D 0x1EB +#define PPG_5GM2_TXA_8721D 0x1EA +#define PPG_5GH1_TXA_8721D 0x1E9 + +/*8197G*/ +#define PPG_THERMAL_A_OFFSET_97G 0x50 +#define PPG_THERMAL_B_OFFSET_97G 0x27 +#define PPG_2GM_TXAB_97G 0x51 +#define PPG_2GL_TXAB_97G 0x53 +#define PPG_2GH_TXAB_97G 0x55 +#define TSSI_2GL_TXA_97G 0x1c +#define TSSI_2GL_TXB_97G 0x1d +#define TSSI_2GH_TXA_97G 0x1e +#define TSSI_2GH_TXB_97G 0x1f +#define PPG_PABIAS_2GAB_97G 0x57 +#define PPG_LNA_2GA_97G 0x21 +#define PPG_LNA_2GB_97G 0x22 + +/*8710C Ameba Z2*/ +#define PPG_THERMAL_OFFSET_10C 0x1EF +#define PPG_2GL_TX_10C 0x1D4 +#define PPG_2GM_TX_10C 0x1EE +#define PPG_2GH_TX_10C 0x1D2 +#define PPG_PABIAS_10C 0x1D6 +#define PPG_LNA_10C 0x1D0 + +/*8814B*/ +#define PPG_2GL_TXAB_14B 0x3ee +#define PPG_2GL_TXCD_14B 0x3ed +#define PPG_5GL1_TXA_14B 0x3ec +#define PPG_5GL1_TXB_14B 0x3eb +#define PPG_5GL1_TXC_14B 0x3ea +#define PPG_5GL1_TXD_14B 0x3e9 +#define PPG_5GL2_TXA_14B 0x3e8 +#define PPG_5GL2_TXB_14B 0x3e7 +#define PPG_5GL2_TXC_14B 0x3e6 +#define PPG_5GL2_TXD_14B 0x3e5 +#define PPG_5GM1_TXA_14B 0x3e4 +#define PPG_5GM1_TXB_14B 0x3e3 +#define PPG_5GM1_TXC_14B 0x3e2 +#define PPG_5GM1_TXD_14B 0x3e1 +#define PPG_5GM2_TXA_14B 0x3e0 +#define PPG_5GM2_TXB_14B 0x3df +#define PPG_5GM2_TXC_14B 0x3de +#define PPG_5GM2_TXD_14B 0x3dd +#define PPG_5GH1_TXA_14B 0x3dc +#define PPG_5GH1_TXB_14B 0x3db +#define PPG_5GH1_TXC_14B 0x3da +#define PPG_5GH1_TXD_14B 0x3d9 +#define PPG_PABIAS_5GAC_14B 0x3d8 +#define PPG_PABIAS_5GBD_14B 0x3d7 +#define PPG_PABIAS_2GAC_14B 0x3d6 +#define PPG_PABIAS_2GBD_14B 0x3d5 + +#define PPG_THERMAL_A_OFFSET_14B 0x3D4 +#define PPG_THERMAL_B_OFFSET_14B 0x3D3 +#define PPG_THERMAL_C_OFFSET_14B 0x3D2 +#define PPG_THERMAL_D_OFFSET_14B 0x3D1 + +#define TSSI_2GM_TXA_14B 0x3c0 +#define TSSI_2GM_TXB_14B 0x3bf +#define TSSI_2GM_TXC_14B 0x3be +#define TSSI_2GM_TXD_14B 0x3bd +#define TSSI_2GH_TXA_14B 0x3bc +#define TSSI_2GH_TXB_14B 0x3bb +#define TSSI_2GH_TXC_14B 0x3ba +#define TSSI_2GH_TXD_14B 0x3b9 +#define TSSI_5GL1_TXA_14B 0x3b8 +#define TSSI_5GL1_TXB_14B 0x3b7 +#define TSSI_5GL1_TXC_14B 0x3b6 +#define TSSI_5GL1_TXD_14B 0x3b5 +#define TSSI_5GL2_TXA_14B 0x3b4 +#define TSSI_5GL2_TXB_14B 0x3b3 +#define TSSI_5GL2_TXC_14B 0x3b2 +#define TSSI_5GL2_TXD_14B 0x3b1 +#define TSSI_5GM1_TXA_14B 0x3b0 +#define TSSI_5GM1_TXB_14B 0x3af +#define TSSI_5GM1_TXC_14B 0x3ae +#define TSSI_5GM1_TXD_14B 0x3ad +#define TSSI_5GM2_TXA_14B 0x3ac +#define TSSI_5GM2_TXB_14B 0x3ab +#define TSSI_5GM2_TXC_14B 0x3aa +#define TSSI_5GM2_TXD_14B 0x3a9 +#define TSSI_5GH1_TXA_14B 0x3a8 +#define TSSI_5GH1_TXB_14B 0x3a7 +#define TSSI_5GH1_TXC_14B 0x3a6 +#define TSSI_5GH1_TXD_14B 0x3a5 +#define TSSI_5GH2_TXA_14B 0x3a4 +#define TSSI_5GH2_TXB_14B 0x3a3 +#define TSSI_5GH2_TXC_14B 0x3a2 +#define TSSI_5GH2_TXD_14B 0x3a1 + + +struct odm_power_trim_data { + u8 flag; + u8 pa_bias_flag; + u8 lna_flag; + s8 bb_gain[KFREE_BAND_NUM][MAX_RF_PATH]; + s8 tssi_trim[KFREE_BAND_NUM][MAX_RF_PATH]; + s8 pa_bias_trim[KFREE_BAND_NUM][MAX_RF_PATH]; + s8 lna_trim[MAX_RF_PATH]; + s8 thermal; + s8 multi_thermal[MAX_RF_PATH]; +}; + +enum phydm_kfree_channeltosw { + PHYDM_2G = 0, + PHYDM_5GLB1 = 1, + PHYDM_5GLB2 = 2, + PHYDM_5GMB1 = 3, + PHYDM_5GMB2 = 4, + PHYDM_5GHB = 5, +}; + +void phydm_get_thermal_trim_offset(void *dm_void); + +void phydm_get_power_trim_offset(void *dm_void); + +void phydm_get_pa_bias_offset(void *dm_void); + +s8 phydm_get_thermal_offset(void *dm_void); + +s8 phydm_get_multi_thermal_offset(void *dm_void, u8 path); + +void phydm_clear_kfree_to_rf(void *dm_void, u8 e_rf_path, u8 data); + +void phydm_config_new_kfree(void *dm_void); + +s8 phydm_get_tssi_trim_de(void *dm_void, u8 path); + +void phydm_config_kfree(void *dm_void, u8 channel_to_sw); + +void phydm_set_lna_trim_offset (void *dm_void, u8 path, u8 cg_cs, u8 enable); + +#endif /*__HALRF_KFREE_H__*/ diff --git a/hal/phydm/halrf/halrf_powertracking.c b/hal/phydm/halrf/halrf_powertracking.c new file mode 100644 index 0000000..648e085 --- /dev/null +++ b/hal/phydm/halrf/halrf_powertracking.c @@ -0,0 +1,200 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +/*@************************************************************ + * include files + * ************************************************************ + */ +#include "mp_precomp.h" +#include "phydm_precomp.h" + +boolean +odm_check_power_status(void *dm_void) +{ +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + struct dm_struct *dm = (struct dm_struct *)dm_void; + PADAPTER *adapter = dm->adapter; + + RT_RF_POWER_STATE rt_state; + MGNT_INFO *mgnt_info = &((PADAPTER)adapter)->MgntInfo; + + /* 2011/07/27 MH We are not testing ready~~!! We may fail to get correct value when init sequence. */ + if (mgnt_info->init_adpt_in_progress == true) { + RF_DBG(dm, DBG_RF_INIT, + "check_pow_status Return true, due to initadapter\n"); + return true; + } + + /* + * 2011/07/19 MH We can not execute tx pwoer tracking/ LLC calibrate or IQK. + */ + ((PADAPTER)adapter)->HalFunc.GetHwRegHandler((PADAPTER)adapter, HW_VAR_RF_STATE, (u8 *)(&rt_state)); + if (((PADAPTER)adapter)->bDriverStopped || ((PADAPTER)adapter)->bDriverIsGoingToPnpSetPowerSleep || rt_state == eRfOff) { + RF_DBG(dm, DBG_RF_INIT, + "check_pow_status Return false, due to %d/%d/%d\n", + ((PADAPTER)adapter)->bDriverStopped, + ((PADAPTER)adapter)->bDriverIsGoingToPnpSetPowerSleep, + rt_state); + return false; + } +#endif + return true; +} + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) +void halrf_update_pwr_track(void *dm_void, u8 rate) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + u8 path_idx = 0; +#endif + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Pwr Track Get rate=0x%x\n", rate); + + dm->tx_rate = rate; + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) +#if DEV_BUS_TYPE == RT_PCI_INTERFACE +#if USE_WORKITEM + odm_schedule_work_item(&dm->ra_rpt_workitem); +#else + if (dm->support_ic_type == ODM_RTL8821) { +#if (RTL8821A_SUPPORT == 1) + odm_tx_pwr_track_set_pwr8821a(dm, MIX_MODE, RF_PATH_A, 0); +#endif + } else if (dm->support_ic_type == ODM_RTL8812) { + for (path_idx = RF_PATH_A; path_idx < MAX_PATH_NUM_8812A; path_idx++) { +#if (RTL8812A_SUPPORT == 1) + odm_tx_pwr_track_set_pwr8812a(dm, MIX_MODE, path_idx, 0); +#endif + } + } else if (dm->support_ic_type == ODM_RTL8723B) { +#if (RTL8723B_SUPPORT == 1) + odm_tx_pwr_track_set_pwr_8723b(dm, MIX_MODE, RF_PATH_A, 0); +#endif + } else if (dm->support_ic_type == ODM_RTL8192E) { + for (path_idx = RF_PATH_A; path_idx < MAX_PATH_NUM_8192E; path_idx++) { +#if (RTL8192E_SUPPORT == 1) + odm_tx_pwr_track_set_pwr92_e(dm, MIX_MODE, path_idx, 0); +#endif + } + } else if (dm->support_ic_type == ODM_RTL8188E) { +#if (RTL8188E_SUPPORT == 1) + odm_tx_pwr_track_set_pwr88_e(dm, MIX_MODE, RF_PATH_A, 0); +#endif + } +#endif +#else + odm_schedule_work_item(&dm->ra_rpt_workitem); +#endif +#endif +} + +#endif + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) +void halrf_update_init_rate_work_item_callback( + void *context) +{ + void *adapter = (void *)context; + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + struct dm_struct *dm = &hal_data->DM_OutSrc; + u8 p = 0; + + if (dm->support_ic_type == ODM_RTL8821) { +#if (RTL8821A_SUPPORT == 1) + odm_tx_pwr_track_set_pwr8821a(dm, MIX_MODE, RF_PATH_A, 0); +#endif + } else if (dm->support_ic_type == ODM_RTL8812) { +#if (RTL8812A_SUPPORT == 1) + /*Don't know how to include &c*/ + for (p = RF_PATH_A; p < MAX_PATH_NUM_8812A; p++) + odm_tx_pwr_track_set_pwr8812a(dm, MIX_MODE, p, 0); +#endif + } else if (dm->support_ic_type == ODM_RTL8723B) { +#if (RTL8723B_SUPPORT == 1) + odm_tx_pwr_track_set_pwr_8723b(dm, MIX_MODE, RF_PATH_A, 0); +#endif + } else if (dm->support_ic_type == ODM_RTL8192E) { +#if (RTL8192E_SUPPORT == 1) + /*Don't know how to include &c*/ + for (p = RF_PATH_A; p < MAX_PATH_NUM_8192E; p++) + odm_tx_pwr_track_set_pwr92_e(dm, MIX_MODE, p, 0); +#endif + } else if (dm->support_ic_type == ODM_RTL8188E) { +#if (RTL8188E_SUPPORT == 1) + odm_tx_pwr_track_set_pwr88_e(dm, MIX_MODE, RF_PATH_A, 0); +#endif + } +} +#endif + +void halrf_set_pwr_track(void *dm_void, u8 enable) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + struct _hal_rf_ *rf = &(dm->rf_table); + struct txpwrtrack_cfg c; + u8 i; + + configure_txpower_track(dm, &c); + if (enable) { + rf->rf_supportability = rf->rf_supportability | HAL_RF_TX_PWR_TRACK; +#if !(RTL8723F_SUPPORT == 1) + if (cali_info->txpowertrack_control == 1 || cali_info->txpowertrack_control == 3) + halrf_do_tssi(dm); +#else + halrf_tssi_get_efuse(dm); + halrf_do_tssi(dm); +#endif + + } else { + rf->rf_supportability = rf->rf_supportability & ~HAL_RF_TX_PWR_TRACK; + odm_clear_txpowertracking_state(dm); + halrf_do_tssi(dm); + halrf_calculate_tssi_codeword(dm); + halrf_set_tssi_codeword(dm); + +//#if !(RTL8723F_SUPPORT == 1) + for (i = 0; i < c.rf_path_count; i++) + (*c.odm_tx_pwr_track_set_pwr)(dm, CLEAN_MODE, i, 0); +//#endif + } + +#if (RTL8723F_SUPPORT == 1) + if (dm->mp_mode) { + if (*dm->mp_mode) + /*Re-do dpk when tssi mode is changed*/ + halrf_dpk_trigger(dm); + } +#endif + + if (cali_info->txpowertrack_control == 2 || + cali_info->txpowertrack_control == 3 || + cali_info->txpowertrack_control == 4 || + cali_info->txpowertrack_control == 5) + halrf_txgapk_reload_tx_gain(dm); +} + diff --git a/hal/phydm/halrf/halrf_powertracking.h b/hal/phydm/halrf/halrf_powertracking.h new file mode 100644 index 0000000..c81f252 --- /dev/null +++ b/hal/phydm/halrf/halrf_powertracking.h @@ -0,0 +1,43 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALRF_POWER_TRACKING_H__ +#define __HALRF_POWER_TRACKING_H__ + +boolean +odm_check_power_status(void *dm_void); + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) +void halrf_update_pwr_track(void *dm_void, u8 rate); +#endif + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) +void halrf_update_init_rate_work_item_callback( + void *context); +#endif + +void halrf_set_pwr_track(void *dm_void, u8 enable); + +#endif /*#ifndef __HALRF_POWERTRACKING_H__*/ diff --git a/hal/phydm/halrf/halrf_powertracking_ap.c b/hal/phydm/halrf/halrf_powertracking_ap.c new file mode 100644 index 0000000..28a8091 --- /dev/null +++ b/hal/phydm/halrf/halrf_powertracking_ap.c @@ -0,0 +1,1290 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +/* ************************************************************ + * include files + * ************************************************************ */ +#include "mp_precomp.h" +#include "phydm_precomp.h" + +#if !defined(_OUTSRC_COEXIST) +/* ************************************************************ + * Global var + * ************************************************************ */ + + +u32 ofdm_swing_table_new[OFDM_TABLE_SIZE_92D] = { + 0x0b40002d, /* 0, -15.0dB */ + 0x0c000030, /* 1, -14.5dB */ + 0x0cc00033, /* 2, -14.0dB */ + 0x0d800036, /* 3, -13.5dB */ + 0x0e400039, /* 4, -13.0dB */ + 0x0f00003c, /* 5, -12.5dB */ + 0x10000040, /* 6, -12.0dB */ + 0x11000044, /* 7, -11.5dB */ + 0x12000048, /* 8, -11.0dB */ + 0x1300004c, /* 9, -10.5dB */ + 0x14400051, /* 10, -10.0dB */ + 0x15800056, /* 11, -9.5dB */ + 0x16c0005b, /* 12, -9.0dB */ + 0x18000060, /* 13, -8.5dB */ + 0x19800066, /* 14, -8.0dB */ + 0x1b00006c, /* 15, -7.5dB */ + 0x1c800072, /* 16, -7.0dB */ + 0x1e400079, /* 17, -6.5dB */ + 0x20000080, /* 18, -6.0dB */ + 0x22000088, /* 19, -5.5dB */ + 0x24000090, /* 20, -5.0dB */ + 0x26000098, /* 21, -4.5dB */ + 0x288000a2, /* 22, -4.0dB */ + 0x2ac000ab, /* 23, -3.5dB */ + 0x2d4000b5, /* 24, -3.0dB */ + 0x300000c0, /* 25, -2.5dB */ + 0x32c000cb, /* 26, -2.0dB */ + 0x35c000d7, /* 27, -1.5dB */ + 0x390000e4, /* 28, -1.0dB */ + 0x3c8000f2, /* 29, -0.5dB */ + 0x40000100, /* 30, +0dB */ + 0x43c0010f, /* 31, +0.5dB */ + 0x47c0011f, /* 32, +1.0dB */ + 0x4c000130, /* 33, +1.5dB */ + 0x50800142, /* 34, +2.0dB */ + 0x55400155, /* 35, +2.5dB */ + 0x5a400169, /* 36, +3.0dB */ + 0x5fc0017f, /* 37, +3.5dB */ + 0x65400195, /* 38, +4.0dB */ + 0x6b8001ae, /* 39, +4.5dB */ + 0x71c001c7, /* 40, +5.0dB */ + 0x788001e2, /* 41, +5.5dB */ + 0x7f8001fe /* 42, +6.0dB */ +}; + +u8 cck_swing_table_ch1_ch13_new[CCK_TABLE_SIZE][8] = { + {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, /* 0, -16.0dB */ + {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 1, -15.5dB */ + {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 2, -15.0dB */ + {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 3, -14.5dB */ + {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 4, -14.0dB */ + {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 5, -13.5dB */ + {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 6, -13.0dB */ + {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 7, -12.5dB */ + {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 8, -12.0dB */ + {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 9, -11.5dB */ + {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 10, -11.0dB */ + {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 11, -10.5dB */ + {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 12, -10.0dB */ + {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 13, -9.5dB */ + {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 15, -8.5dB */ + {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 17, -7.5dB */ + {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 19, -6.5dB */ + {0x1c, 0x1a, 0x18, 0x12, 0x0e, 0x08, 0x04, 0x02}, /* 20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 21, -5.5dB */ + {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 23, -4.5dB */ + {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 25, -3.5dB */ + {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 26, -3.0dB */ + {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 27, -2.5dB */ + {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 29, -1.5dB */ + {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 30, -1.0dB */ + {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 31, -0.5dB */ + {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04} /* 32, +0dB */ +}; + + +u8 cck_swing_table_ch14_new[CCK_TABLE_SIZE][8] = { + {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, /* 0, -16.0dB */ + {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 1, -15.5dB */ + {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 2, -15.0dB */ + {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 3, -14.5dB */ + {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 4, -14.0dB */ + {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 5, -13.5dB */ + {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 6, -13.0dB */ + {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 7, -12.5dB */ + {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 8, -12.0dB */ + {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 9, -11.5dB */ + {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 10, -11.0dB */ + {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 11, -10.5dB */ + {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 12, -10.0dB */ + {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 13, -9.5dB */ + {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 15, -8.5dB */ + {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 17, -7.5dB */ + {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 19, -6.5dB */ + {0x1c, 0x1a, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 21, -5.5dB */ + {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 23, -4.5dB */ + {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 25, -3.5dB */ + {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 26, -3.0dB */ + {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 27, -2.5dB */ + {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 29, -1.5dB */ + {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 30, -1.0dB */ + {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 31, -0.5dB */ + {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00} /* 32, +0dB */ +}; + +u32 ofdm_swing_table[OFDM_TABLE_SIZE_92D] = { + 0x0b40002d, /* 0, -15.0dB */ + 0x0c000030, /* 1, -14.5dB */ + 0x0cc00033, /* 2, -14.0dB */ + 0x0d800036, /* 3, -13.5dB */ + 0x0e400039, /* 4, -13.0dB */ + 0x0f00003c, /* 5, -12.5dB */ + 0x10000040, /* 6, -12.0dB */ + 0x11000044, /* 7, -11.5dB */ + 0x12000048, /* 8, -11.0dB */ + 0x1300004c, /* 9, -10.5dB */ + 0x14400051, /* 10, -10.0dB */ + 0x15800056, /* 11, -9.5dB */ + 0x16c0005b, /* 12, -9.0dB */ + 0x18000060, /* 13, -8.5dB */ + 0x19800066, /* 14, -8.0dB */ + 0x1b00006c, /* 15, -7.5dB */ + 0x1c800072, /* 16, -7.0dB */ + 0x1e400079, /* 17, -6.5dB */ + 0x20000080, /* 18, -6.0dB */ + 0x22000088, /* 19, -5.5dB */ + 0x24000090, /* 20, -5.0dB */ + 0x26000098, /* 21, -4.5dB */ + 0x288000a2, /* 22, -4.0dB */ + 0x2ac000ab, /* 23, -3.5dB */ + 0x2d4000b5, /* 24, -3.0dB */ + 0x300000c0, /* 25, -2.5dB */ + 0x32c000cb, /* 26, -2.0dB */ + 0x35c000d7, /* 27, -1.5dB */ + 0x390000e4, /* 28, -1.0dB */ + 0x3c8000f2, /* 29, -0.5dB */ + 0x40000100, /* 30, +0dB */ + 0x43c0010f, /* 31, +0.5dB */ + 0x47c0011f, /* 32, +1.0dB */ + 0x4c000130, /* 33, +1.5dB */ + 0x50800142, /* 34, +2.0dB */ + 0x55400155, /* 35, +2.5dB */ + 0x5a400169, /* 36, +3.0dB */ + 0x5fc0017f, /* 37, +3.5dB */ + 0x65400195, /* 38, +4.0dB */ + 0x6b8001ae, /* 39, +4.5dB */ + 0x71c001c7, /* 40, +5.0dB */ + 0x788001e2, /* 41, +5.5dB */ + 0x7f8001fe /* 42, +6.0dB */ +}; + + +u8 cck_swing_table_ch1_ch13[CCK_TABLE_SIZE][8] = { + {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, /* 0, -16.0dB */ + {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 1, -15.5dB */ + {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 2, -15.0dB */ + {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 3, -14.5dB */ + {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 4, -14.0dB */ + {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 5, -13.5dB */ + {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 6, -13.0dB */ + {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 7, -12.5dB */ + {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 8, -12.0dB */ + {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 9, -11.5dB */ + {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 10, -11.0dB */ + {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 11, -10.5dB */ + {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 12, -10.0dB */ + {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 13, -9.5dB */ + {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 15, -8.5dB */ + {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 17, -7.5dB */ + {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 19, -6.5dB */ + {0x1c, 0x1a, 0x18, 0x12, 0x0e, 0x08, 0x04, 0x02}, /* 20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 21, -5.5dB */ + {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 23, -4.5dB */ + {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 25, -3.5dB */ + {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 26, -3.0dB */ + {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 27, -2.5dB */ + {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 29, -1.5dB */ + {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 30, -1.0dB */ + {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 31, -0.5dB */ + {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04} /* 32, +0dB */ +}; + + +u8 cck_swing_table_ch14[CCK_TABLE_SIZE][8] = { + {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, /* 0, -16.0dB */ + {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 1, -15.5dB */ + {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 2, -15.0dB */ + {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 3, -14.5dB */ + {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 4, -14.0dB */ + {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 5, -13.5dB */ + {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 6, -13.0dB */ + {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 7, -12.5dB */ + {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 8, -12.0dB */ + {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 9, -11.5dB */ + {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 10, -11.0dB */ + {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 11, -10.5dB */ + {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 12, -10.0dB */ + {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 13, -9.5dB */ + {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 15, -8.5dB */ + {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 17, -7.5dB */ + {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 19, -6.5dB */ + {0x1c, 0x1a, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 21, -5.5dB */ + {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 23, -4.5dB */ + {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 25, -3.5dB */ + {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 26, -3.0dB */ + {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 27, -2.5dB */ + {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 29, -1.5dB */ + {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 30, -1.0dB */ + {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 31, -0.5dB */ + {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00} /* 32, +0dB */ +}; + +u8 cck_swing_table_ch1_ch14_88f[CCK_TABLE_SIZE_88F][16] = { + {0x16, 0x15, 0x13, 0x10, 0xD, 0x9, 0x6, 0x3, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 0 -16dB */ + {0x18, 0x17, 0x15, 0x12, 0xE, 0xA, 0x7, 0x4, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 1 -15.5dB */ + {0x1B, 0x1A, 0x18, 0x14, 0x10, 0xB, 0x7, 0x4, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 2 -15dB */ + {0x1F, 0x1E, 0x1B, 0x17, 0x12, 0xD, 0x8, 0x5, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 3 -14.5dB */ + {0x22, 0x21, 0x1E, 0x19, 0x14, 0xE, 0x9, 0x5, 0x3, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 4 -14dB */ + {0x26, 0x25, 0x22, 0x1C, 0x16, 0x10, 0xA, 0x6, 0x3, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 5 -13.5dB */ + {0x2B, 0x2A, 0x26, 0x20, 0x19, 0x12, 0xC, 0x7, 0x3, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 6 -13dB */ + {0x30, 0x2F, 0x2A, 0x24, 0x1C, 0x14, 0xD, 0x8, 0x4, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 7 -12.5dB */ + {0x36, 0x34, 0x2F, 0x28, 0x1F, 0x17, 0xF, 0x9, 0x4, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 8 -12dB */ + {0x3D, 0x3B, 0x35, 0x2D, 0x23, 0x19, 0x11, 0xA, 0x5, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 9 -11.5dB */ + {0x44, 0x42, 0x3C, 0x33, 0x28, 0x1C, 0x13, 0xB, 0x5, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 10 -11dB */ + {0x4D, 0x4A, 0x43, 0x39, 0x2C, 0x20, 0x15, 0xC, 0x6, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 11 -10.5dB */ + {0x56, 0x53, 0x4B, 0x40, 0x32, 0x24, 0x17, 0xE, 0x6, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 12 -10dB */ + {0x60, 0x5D, 0x54, 0x47, 0x38, 0x28, 0x1A, 0xF, 0x7, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 13 -9.5dB */ + {0x6C, 0x69, 0x5F, 0x50, 0x3F, 0x2D, 0x1E, 0x11, 0x8, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 14 -9dB */ + {0x79, 0x76, 0x6A, 0x5A, 0x46, 0x33, 0x21, 0x13, 0x9, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 15 -8.5dB */ + {0x88, 0x84, 0x77, 0x65, 0x4F, 0x39, 0x25, 0x15, 0xA, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 16 -8dB */ + {0x99, 0x94, 0x86, 0x71, 0x58, 0x40, 0x2A, 0x18, 0xB, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 17 -7.5dB */ + {0xAC, 0xA6, 0x96, 0x7F, 0x63, 0x47, 0x2F, 0x1B, 0xD, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 18 -7dB */ + {0xC1, 0xBA, 0xA8, 0x8F, 0x6F, 0x50, 0x35, 0x1E, 0xE, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 19 -6.5dB */ + {0xD8, 0xD1, 0xBD, 0xA0, 0x7D, 0x5A, 0x3B, 0x22, 0x10, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} /* 20 -6dB */ +}; + + +u8 cck_swing_table_ch1_ch13_88f[CCK_TABLE_SIZE_88F][16] = { + {0x16, 0x15, 0x13, 0x10, 0xD, 0x9, 0x6, 0x3, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 0 -16dB */ + {0x18, 0x17, 0x15, 0x12, 0xE, 0xA, 0x7, 0x4, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 1 -15.5dB */ + {0x1B, 0x1A, 0x18, 0x14, 0x10, 0xB, 0x7, 0x4, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 2 -15dB */ + {0x1F, 0x1E, 0x1B, 0x17, 0x12, 0xD, 0x8, 0x5, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 3 -14.5dB */ + {0x22, 0x21, 0x1E, 0x19, 0x14, 0xE, 0x9, 0x5, 0x3, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 4 -14dB */ + {0x26, 0x25, 0x22, 0x1C, 0x16, 0x10, 0xA, 0x6, 0x3, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 5 -13.5dB */ + {0x2B, 0x2A, 0x26, 0x20, 0x19, 0x12, 0xC, 0x7, 0x3, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 6 -13dB */ + {0x30, 0x2F, 0x2A, 0x24, 0x1C, 0x14, 0xD, 0x8, 0x4, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 7 -12.5dB */ + {0x36, 0x34, 0x2F, 0x28, 0x1F, 0x17, 0xF, 0x9, 0x4, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 8 -12dB */ + {0x3D, 0x3B, 0x35, 0x2D, 0x23, 0x19, 0x11, 0xA, 0x5, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 9 -11.5dB */ + {0x44, 0x42, 0x3C, 0x33, 0x28, 0x1C, 0x13, 0xB, 0x5, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 10 -11dB */ + {0x4D, 0x4A, 0x43, 0x39, 0x2C, 0x20, 0x15, 0xC, 0x6, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 11 -10.5dB */ + {0x56, 0x53, 0x4B, 0x40, 0x32, 0x24, 0x17, 0xE, 0x6, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 12 -10dB */ + {0x60, 0x5D, 0x54, 0x47, 0x38, 0x28, 0x1A, 0xF, 0x7, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 13 -9.5dB */ + {0x6C, 0x69, 0x5F, 0x50, 0x3F, 0x2D, 0x1E, 0x11, 0x8, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 14 -9dB */ + {0x79, 0x76, 0x6A, 0x5A, 0x46, 0x33, 0x21, 0x13, 0x9, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 15 -8.5dB */ + {0x88, 0x84, 0x77, 0x65, 0x4F, 0x39, 0x25, 0x15, 0xA, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 16 -8dB */ + {0x99, 0x94, 0x86, 0x71, 0x58, 0x40, 0x2A, 0x18, 0xB, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 17 -7.5dB */ + {0xAC, 0xA6, 0x96, 0x7F, 0x63, 0x47, 0x2F, 0x1B, 0xD, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 18 -7dB */ + {0xC1, 0xBA, 0xA8, 0x8F, 0x6F, 0x50, 0x35, 0x1E, 0xE, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* 19 -6.5dB */ + {0xD8, 0xD1, 0xBD, 0xA0, 0x7D, 0x5A, 0x3B, 0x22, 0x10, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} /* 20 -6dB */ +}; + + +u8 cck_swing_table_ch14_88f[CCK_TABLE_SIZE_88F][16] = { + {0x44, 0x42, 0x3C, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-16dB*/ + {0x48, 0x46, 0x3F, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15.5dB*/ + {0x4D, 0x4A, 0x43, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15dB*/ + {0x51, 0x4F, 0x47, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14.5dB*/ + {0x56, 0x53, 0x4B, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14dB*/ + {0x5B, 0x58, 0x50, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13.5dB*/ + {0x60, 0x5D, 0x54, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13dB*/ + {0x66, 0x63, 0x59, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12.5dB*/ + {0x6C, 0x69, 0x5F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12dB*/ + {0x73, 0x6F, 0x64, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11.5dB*/ + {0x79, 0x76, 0x6A, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11dB*/ + {0x81, 0x7C, 0x71, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10.5dB*/ + {0x88, 0x84, 0x77, 0x4F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10dB*/ + {0x90, 0x8C, 0x7E, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9.5dB*/ + {0x99, 0x94, 0x86, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9dB*/ + {0xA2, 0x9D, 0x8E, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8.5dB*/ + {0xAC, 0xA6, 0x96, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8dB*/ + {0xB6, 0xB0, 0x9F, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7.5dB*/ + {0xC1, 0xBA, 0xA8, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7dB*/ + {0xCC, 0xC5, 0xB2, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-6.5dB*/ + {0xD8, 0xD1, 0xBD, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /*-6dB*/ +}; + +/* Winnita ADD 20171113 PathA 0xAB4[10:0],PathB 0xAB4[21:11]*/ +u32 cck_swing_table_ch1_ch14_8192f[CCK_TABLE_SIZE_8192F] = { + 0x0CD, /*0 , -20dB*/ + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, /*19*/ + 0x287, /*20*/ + 0x2AE, /*21*/ + 0x2D6, /*22*/ + 0x301, /*23*/ + 0x32F, /*24*/ + 0x35F, /*25*/ + 0x392, /*26*/ + 0x3C9, /*27*/ + 0x402, /*28*/ + 0x43F, /*29*/ + 0x47F, /*30*/ + 0x4C3, /*31*/ + 0x50C, /*32*/ + 0x558, /*33*/ + 0x5A9, /*34*/ + 0x5FF, /*35*/ + 0x65A, /*36*/ + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + + +#if 0 +u32 ofdm_swing_table_92e[OFDM_TABLE_SIZE_92E] = { + /* Index0 6 dB */ 0x7fc001ff, + /* Index1 5.7dB */ 0x7b4001ed, + /* Index2 5.4dB */ 0x774001dd, + /* Index3 5.1dB */ 0x734001cd, + /* Index4 4.8dB */ 0x6f4001bd, + /* Index5 4.5dB */ 0x6b8001ae, + /* Index6 4.2dB */ 0x67c0019f, + /* Index7 3.9dB */ 0x64400191, + /* Index8 3.6dB */ 0x60c00183, + /* Index9 3.3dB */ 0x5d800176, + /* Index10 3 dB */ 0x5a80016a, + /* Index11 2.7dB */ 0x5740015d, + /* Index12 2.4dB */ 0x54400151, + /* Index13 2.1dB */ 0x51800146, + /* Index14 1.8dB */ 0x4ec0013b, + /* Index15 1.5dB */ 0x4c000130, + /* Index16 1.2dB */ 0x49800126, + /* Index17 0.9dB */ 0x4700011c, + /* Index18 0.6dB */ 0x44800112, + /* Index19 0.3dB */ 0x42000108, + /* Index20 0 dB */ 0x40000100, /* 20 This is OFDM base index */ + /* Index21 -0.3dB */ 0x3dc000f7, + /* Index22 -0.6dB */ 0x3bc000ef, + /* Index23 -0.9dB */ 0x39c000e7, + /* Index24 -1.2dB */ 0x37c000df, + /* Index25 -1.5dB */ 0x35c000d7, + /* Index26 -1.8dB */ 0x340000d0, + /* Index27 -2.1dB */ 0x324000c9, + /* Index28 -2.4dB */ 0x308000c2, + /* Index29 -2.7dB */ 0x2f0000bc, + /* Index30 -3 dB */ 0x2d4000b5, + /* Index31 -3.3dB */ 0x2bc000af, + /* Index32 -3.6dB */ 0x2a4000a9, + /* Index33 -3.9dB */ 0x28c000a3, + /* Index34 -4.2dB */ 0x2780009e, + /* Index35 -4.5dB */ 0x26000098, + /* Index36 -4.8dB */ 0x24c00093, + /* Index37 -5.1dB */ 0x2380008e, + /* Index38 -5.4dB */ 0x22400089, + /* Index39 -5.7dB */ 0x21400085, + /* Index40 -6 dB */ 0x20000080, + /* Index41 -6.3dB */ 0x1f00007c, + /* Index42 -6.6dB */ 0x1e000078, + /* Index43 -6.9dB */ 0x1d000074, + /* Index44 -7.2dB */ 0x1c000070, + /* Index45 -7.5dB */ 0x1b00006c, + /* Index46 -7.8dB */ 0x1a000068, + /* Index47 -8.1dB */ 0x19400065, + /* Index48 -8.4dB */ 0x18400061, + /* Index49 -8.7dB */ 0x1780005e, + /* Index50 -9 dB */ 0x16c0005b, + /* Index51 -9.3dB */ 0x16000058, + /* Index52 -9.6dB */ 0x15400055, + /* Index53 -9.9dB */ 0x14800052 +}; +u8 cck_swing_table_ch1_ch13_92e[CCK_TABLE_SIZE_92E][8] = { + /* Index0 0 dB */ {0x36, 0x34, 0x2E, 0x26, 0x1C, 0x12, 0x08, 0x04}, + /* Index1 -0.3dB */ {0x34, 0x32, 0x2C, 0x25, 0x1B, 0x11, 0x08, 0x04}, + /* Index2 -0.6dB */ {0x32, 0x30, 0x2B, 0x23, 0x1A, 0x11, 0x07, 0x04}, + /* Index3 -0.9dB */ {0x31, 0x2F, 0x29, 0x22, 0x19, 0x10, 0x07, 0x04}, + /* Index4 -1.2dB */ {0x2F, 0x2D, 0x28, 0x21, 0x18, 0x10, 0x07, 0x03}, + /* Index5 -1.5dB */ {0x2D, 0x2C, 0x27, 0x20, 0x18, 0x0F, 0x07, 0x03}, + /* Index6 -1.8dB */ {0x2C, 0x2A, 0x25, 0x1F, 0x17, 0x0F, 0x06, 0x03}, + /* Index7 -2.1dB */ {0x2A, 0x29, 0x24, 0x1E, 0x16, 0x0E, 0x06, 0x03}, + /* Index8 -2.4dB */ {0x29, 0x27, 0x23, 0x1D, 0x15, 0x0E, 0x06, 0x03}, + /* Index9 -2.7dB */ {0x27, 0x26, 0x22, 0x1C, 0x14, 0x0D, 0x06, 0x03}, + /* Index10 -3 dB */ {0x26, 0x25, 0x20, 0x1B, 0x14, 0x0D, 0x06, 0x03}, + /* Index11 -3.3dB */ {0x25, 0x23, 0x1F, 0x1A, 0x13, 0x0C, 0x05, 0x03}, + /* Index12 -3.6dB */ {0x24, 0x22, 0x1E, 0x19, 0x12, 0x0C, 0x05, 0x03}, + /* Index13 -3.9dB */ {0x22, 0x21, 0x1D, 0x18, 0x12, 0x0B, 0x05, 0x03}, + /* Index14 -4.2dB */ {0x21, 0x20, 0x1C, 0x17, 0x11, 0x0B, 0x05, 0x02}, + /* Index15 -4.5dB */ {0x20, 0x1F, 0x1B, 0x17, 0x11, 0x0B, 0x05, 0x02}, + /* Index16 -4.8dB */ {0x1F, 0x1E, 0x1A, 0x16, 0x10, 0x0A, 0x05, 0x02}, + /* Index17 -5.1dB */ {0x1E, 0x1D, 0x1A, 0x15, 0x10, 0x0A, 0x04, 0x02}, + /* Index18 -5.4dB */ {0x1D, 0x1C, 0x19, 0x14, 0x0F, 0x0A, 0x04, 0x02}, + /* Index19 -5.7dB */ {0x1C, 0x1B, 0x18, 0x14, 0x0E, 0x09, 0x04, 0x02}, + /* Index20 -6.0dB */ {0x1B, 0x1A, 0x17, 0x13, 0x0E, 0x09, 0x04, 0x02}, /* 20 This is CCK base index */ + /* Index21 -6.3dB */ {0x1A, 0x19, 0x16, 0x12, 0x0E, 0x09, 0x04, 0x02}, + /* Index22 -6.6dB */ {0x19, 0x18, 0x15, 0x12, 0x0D, 0x08, 0x04, 0x02}, + /* Index23 -6.9dB */ {0x18, 0x17, 0x15, 0x11, 0x0D, 0x08, 0x04, 0x02}, + /* Index24 -7.2dB */ {0x18, 0x17, 0x14, 0x11, 0x0C, 0x08, 0x03, 0x02}, + /* Index25 -7.5dB */ {0x17, 0x16, 0x13, 0x10, 0x0C, 0x08, 0x03, 0x02}, + /* Index26 -7.8dB */ {0x16, 0x15, 0x13, 0x0F, 0x0B, 0x07, 0x03, 0x02}, + /* Index27 -8.1dB */ {0x15, 0x14, 0x12, 0x0F, 0x0B, 0x07, 0x03, 0x02}, + /* Index28 -8.4dB */ {0x14, 0x14, 0x11, 0x0E, 0x0B, 0x07, 0x03, 0x02}, + /* Index29 -8.7dB */ {0x14, 0x13, 0x11, 0x0E, 0x0A, 0x07, 0x03, 0x01}, + /* Index30 -9.0dB */ {0x13, 0x12, 0x10, 0x0D, 0x0A, 0x06, 0x03, 0x01}, /* 30 This is hp CCK base index */ + /* Index31 -9.3dB */ {0x12, 0x12, 0x0F, 0x0D, 0x0A, 0x06, 0x03, 0x01}, + /* Index32 -9.6dB */ {0x12, 0x11, 0x0F, 0x0D, 0x09, 0x06, 0x03, 0x01}, + /* Index33 -9.9dB */ {0x11, 0x11, 0x0F, 0x0C, 0x09, 0x06, 0x03, 0x01}, + /* Index34 -10.2dB */ {0x11, 0x11, 0x0E, 0x0C, 0x09, 0x06, 0x02, 0x01}, + /* Index35 -10.5dB */ {0x10, 0x0F, 0x0E, 0x0B, 0x08, 0x05, 0x02, 0x01}, + /* Index36 -10.8dB */ {0x10, 0x0F, 0x0D, 0x0B, 0x08, 0x05, 0x02, 0x01}, + /* Index37 -11.1dB */ {0x0F, 0x0E, 0x0D, 0x0A, 0x08, 0x05, 0x02, 0x01}, + /* Index38 -11.4dB */ {0x0E, 0x0E, 0x0C, 0x0A, 0x07, 0x05, 0x02, 0x01}, + /* Index39 -11.7dB */ {0x0E, 0x0D, 0x0C, 0x0A, 0x07, 0x05, 0x02, 0x01}, + /* Index40 -12 dB */ {0x0E, 0x0D, 0x0C, 0x0A, 0x07, 0x05, 0x02, 0x01}, + /* Index41 -12.3dB */ {0x0D, 0x0D, 0x0B, 0x09, 0x07, 0x04, 0x02, 0x01}, + /* Index42 -12.6dB */ {0x0D, 0x0C, 0x0B, 0x09, 0x07, 0x04, 0x02, 0x01}, + /* Index43 -12.9dB */ {0x0C, 0x0C, 0x0A, 0x09, 0x06, 0x04, 0x02, 0x01}, + /* Index44 -13.2dB */ {0x0C, 0x0B, 0x0A, 0x08, 0x06, 0x04, 0x02, 0x01}, + /* Index45 -13.5dB */ {0x0B, 0x0B, 0x0A, 0x08, 0x06, 0x04, 0x02, 0x01}, + /* Index46 -13.8dB */ {0x0B, 0x0B, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, + /* Index47 -14.1dB */ {0x0B, 0x0A, 0x09, 0x07, 0x06, 0x04, 0x02, 0x01}, + /* Index48 -14.4dB */ {0x0A, 0x0A, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, + /* Index49 -14.7dB */ {0x0A, 0x0A, 0x08, 0x07, 0x05, 0x03, 0x01, 0x01}, + /* Index50 -15 dB */ {0x0A, 0x09, 0x08, 0x07, 0x05, 0x03, 0x01, 0x01}, + /* Index51 -15.3dB */ {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, + /* Index52 -15.6dB */ {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, + /* Index53 -15.9dB */ {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01} +}; +u8 cck_swing_table_ch14_92e[CCK_TABLE_SIZE_92E][8] = { + /* Index0 0 dB */ {0x36, 0x34, 0x2E, 0x26, 0x00, 0x00, 0x00, 0x00}, + /* Index1 -0.3dB */ {0x34, 0x32, 0x2C, 0x25, 0x00, 0x00, 0x00, 0x00}, + /* Index2 -0.6dB */ {0x32, 0x30, 0x2B, 0x23, 0x00, 0x00, 0x00, 0x00}, + /* Index3 -0.9dB */ {0x31, 0x2F, 0x29, 0x22, 0x00, 0x00, 0x00, 0x00}, + /* Index4 -1.2dB */ {0x2F, 0x2D, 0x28, 0x21, 0x00, 0x00, 0x00, 0x00}, + /* Index5 -1.5dB */ {0x2D, 0x2C, 0x27, 0x20, 0x00, 0x00, 0x00, 0x00}, + /* Index6 -1.8dB */ {0x2C, 0x2A, 0x25, 0x1F, 0x00, 0x00, 0x00, 0x00}, + /* Index7 -2.1dB */ {0x2A, 0x29, 0x24, 0x1E, 0x00, 0x00, 0x00, 0x00}, + /* Index8 -2.4dB */ {0x29, 0x27, 0x23, 0x1D, 0x00, 0x00, 0x00, 0x00}, + /* Index9 -2.7dB */ {0x27, 0x26, 0x22, 0x1C, 0x00, 0x00, 0x00, 0x00}, + /* Index10 -3 dB */ {0x26, 0x25, 0x20, 0x1B, 0x00, 0x00, 0x00, 0x00}, + /* Index11 -3.3dB */ {0x25, 0x23, 0x1F, 0x1A, 0x00, 0x00, 0x00, 0x00}, + /* Index12 -3.6dB */ {0x24, 0x22, 0x1E, 0x19, 0x00, 0x00, 0x00, 0x00}, + /* Index13 -3.9dB */ {0x22, 0x21, 0x1D, 0x18, 0x00, 0x00, 0x00, 0x00}, + /* Index14 -4.2dB */ {0x21, 0x20, 0x1C, 0x17, 0x00, 0x00, 0x00, 0x00}, + /* Index15 -4.5dB */ {0x20, 0x1F, 0x1B, 0x17, 0x00, 0x00, 0x00, 0x00}, + /* Index16 -4.8dB */ {0x1F, 0x1E, 0x1A, 0x16, 0x00, 0x00, 0x00, 0x00}, + /* Index17 -5.1dB */ {0x1E, 0x1D, 0x1A, 0x15, 0x00, 0x00, 0x00, 0x00}, + /* Index18 -5.4dB */ {0x1D, 0x1C, 0x19, 0x14, 0x00, 0x00, 0x00, 0x00}, + /* Index19 -5.7dB */ {0x1C, 0x1B, 0x18, 0x14, 0x00, 0x00, 0x00, 0x00}, + /* Index20 -6 dB */ {0x1B, 0x1A, 0x17, 0x13, 0x00, 0x00, 0x00, 0x00}, + /* Index21 -6.3dB */ {0x1A, 0x19, 0x16, 0x12, 0x00, 0x00, 0x00, 0x00}, + /* Index22 -6.6dB */ {0x19, 0x18, 0x15, 0x12, 0x00, 0x00, 0x00, 0x00}, + /* Index23 -6.9dB */ {0x18, 0x17, 0x15, 0x11, 0x00, 0x00, 0x00, 0x00}, + /* Index24 -7.2dB */ {0x18, 0x17, 0x14, 0x11, 0x00, 0x00, 0x00, 0x00}, + /* Index25 -7.5dB */ {0x17, 0x16, 0x13, 0x10, 0x00, 0x00, 0x00, 0x00}, + /* Index26 -7.8dB */ {0x16, 0x15, 0x13, 0x0F, 0x00, 0x00, 0x00, 0x00}, + /* Index27 -8.1dB */ {0x15, 0x14, 0x12, 0x0F, 0x00, 0x00, 0x00, 0x00}, + /* Index28 -8.4dB */ {0x14, 0x14, 0x11, 0x0E, 0x00, 0x00, 0x00, 0x00}, + /* Index29 -8.7dB */ {0x14, 0x13, 0x11, 0x0E, 0x00, 0x00, 0x00, 0x00}, + /* Index30 -9 dB */ {0x13, 0x12, 0x10, 0x0D, 0x00, 0x00, 0x00, 0x00}, + /* Index31 -9.3dB */ {0x12, 0x12, 0x0F, 0x0D, 0x00, 0x00, 0x00, 0x00}, + /* Index32 -9.6dB */ {0x12, 0x11, 0x0F, 0x0D, 0x00, 0x00, 0x00, 0x00}, + /* Index33 -9.9dB */ {0x11, 0x11, 0x0F, 0x0C, 0x00, 0x00, 0x00, 0x00}, + /* Index34 -10.2dB */ {0x11, 0x11, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00}, + /* Index35 -10.5dB */ {0x10, 0x0F, 0x0E, 0x0B, 0x00, 0x00, 0x00, 0x00}, + /* Index36 -10.8dB */ {0x10, 0x0F, 0x0D, 0x0B, 0x00, 0x00, 0x00, 0x00}, + /* Index37 -11.1dB */ {0x0F, 0x0E, 0x0D, 0x0A, 0x00, 0x00, 0x00, 0x00}, + /* Index38 -11.4dB */ {0x0E, 0x0E, 0x0C, 0x0A, 0x00, 0x00, 0x00, 0x00}, + /* Index39 -11.7dB */ {0x0E, 0x0D, 0x0C, 0x0A, 0x00, 0x00, 0x00, 0x00}, + /* Index40 -12 dB */ {0x0E, 0x0D, 0x0C, 0x0A, 0x00, 0x00, 0x00, 0x00}, + /* Index41 -12.3dB */ {0x0D, 0x0D, 0x0B, 0x09, 0x00, 0x00, 0x00, 0x00}, + /* Index42 -12.6dB */ {0x0D, 0x0C, 0x0B, 0x09, 0x00, 0x00, 0x00, 0x00}, + /* Index43 -12.9dB */ {0x0C, 0x0C, 0x0A, 0x09, 0x00, 0x00, 0x00, 0x00}, + /* Index44 -13.2dB */ {0x0C, 0x0B, 0x0A, 0x08, 0x00, 0x00, 0x00, 0x00}, + /* Index45 -13.5dB */ {0x0B, 0x0B, 0x0A, 0x08, 0x00, 0x00, 0x00, 0x00}, + /* Index46 -13.8dB */ {0x0B, 0x0B, 0x09, 0x08, 0x00, 0x00, 0x00, 0x00}, + /* Index47 -14.1dB */ {0x0B, 0x0A, 0x09, 0x07, 0x00, 0x00, 0x00, 0x00}, + /* Index48 -14.4dB */ {0x0A, 0x0A, 0x09, 0x07, 0x00, 0x00, 0x00, 0x00}, + /* Index49 -14.7dB */ {0x0A, 0x0A, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00}, + /* Index50 -15 dB */ {0x0A, 0x09, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00}, + /* Index51 -15.3dB */ {0x09, 0x09, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00}, + /* Index52 -15.6dB */ {0x09, 0x09, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00}, + /* Index53 -15.9dB */ {0x09, 0x08, 0x07, 0x06, 0x00, 0x00, 0x00, 0x00} +}; +#endif +#endif + + +u8 delta_swing_table_idx_2ga_p_default[DELTA_SWINGIDX_SIZE] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3 + , 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9 + }; +u8 delta_swing_table_idx_2ga_n_default[DELTA_SWINGIDX_SIZE] = {0, 0, 0, 2, 2, 3, 3, 4, 4, 4 + , 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11 + }; + + +#ifdef CONFIG_WLAN_HAL_8192EE +u32 ofdm_swing_table_92e[OFDM_TABLE_SIZE_92E] = { + /* Index0 6 dB */ 0x7fc001ff, + /* Index1 5.7dB */ 0x7b4001ed, + /* Index2 5.4dB */ 0x774001dd, + /* Index3 5.1dB */ 0x734001cd, + /* Index4 4.8dB */ 0x6f4001bd, + /* Index5 4.5dB */ 0x6b8001ae, + /* Index6 4.2dB */ 0x67c0019f, + /* Index7 3.9dB */ 0x64400191, + /* Index8 3.6dB */ 0x60c00183, + /* Index9 3.3dB */ 0x5d800176, + /* Index10 3 dB */ 0x5a80016a, + /* Index11 2.7dB */ 0x5740015d, + /* Index12 2.4dB */ 0x54400151, + /* Index13 2.1dB */ 0x51800146, + /* Index14 1.8dB */ 0x4ec0013b, + /* Index15 1.5dB */ 0x4c000130, + /* Index16 1.2dB */ 0x49800126, + /* Index17 0.9dB */ 0x4700011c, + /* Index18 0.6dB */ 0x44800112, + /* Index19 0.3dB */ 0x42000108, + /* Index20 0 dB */ 0x40000100, /* 20 This is OFDM base index */ + /* Index21 -0.3dB */ 0x3dc000f7, + /* Index22 -0.6dB */ 0x3bc000ef, + /* Index23 -0.9dB */ 0x39c000e7, + /* Index24 -1.2dB */ 0x37c000df, + /* Index25 -1.5dB */ 0x35c000d7, + /* Index26 -1.8dB */ 0x340000d0, + /* Index27 -2.1dB */ 0x324000c9, + /* Index28 -2.4dB */ 0x308000c2, + /* Index29 -2.7dB */ 0x2f0000bc, + /* Index30 -3 dB */ 0x2d4000b5, + /* Index31 -3.3dB */ 0x2bc000af, + /* Index32 -3.6dB */ 0x2a4000a9, + /* Index33 -3.9dB */ 0x28c000a3, + /* Index34 -4.2dB */ 0x2780009e, + /* Index35 -4.5dB */ 0x26000098, + /* Index36 -4.8dB */ 0x24c00093, + /* Index37 -5.1dB */ 0x2380008e, + /* Index38 -5.4dB */ 0x22400089, + /* Index39 -5.7dB */ 0x21400085, + /* Index40 -6 dB */ 0x20000080, + /* Index41 -6.3dB */ 0x1f00007c, + /* Index42 -6.6dB */ 0x1e000078, + /* Index43 -6.9dB */ 0x1d000074, + /* Index44 -7.2dB */ 0x1c000070, + /* Index45 -7.5dB */ 0x1b00006c, + /* Index46 -7.8dB */ 0x1a000068, + /* Index47 -8.1dB */ 0x19400065, + /* Index48 -8.4dB */ 0x18400061, + /* Index49 -8.7dB */ 0x1780005e, + /* Index50 -9 dB */ 0x16c0005b, + /* Index51 -9.3dB */ 0x16000058, + /* Index52 -9.6dB */ 0x15400055, + /* Index53 -9.9dB */ 0x14800052 +}; +u8 cck_swing_table_ch1_ch13_92e[CCK_TABLE_SIZE_92E][8] = { + /* Index0 0 dB */ {0x36, 0x34, 0x2E, 0x26, 0x1C, 0x12, 0x08, 0x04}, + /* Index1 -0.3dB */ {0x34, 0x32, 0x2C, 0x25, 0x1B, 0x11, 0x08, 0x04}, + /* Index2 -0.6dB */ {0x32, 0x30, 0x2B, 0x23, 0x1A, 0x11, 0x07, 0x04}, + /* Index3 -0.9dB */ {0x31, 0x2F, 0x29, 0x22, 0x19, 0x10, 0x07, 0x04}, + /* Index4 -1.2dB */ {0x2F, 0x2D, 0x28, 0x21, 0x18, 0x10, 0x07, 0x03}, + /* Index5 -1.5dB */ {0x2D, 0x2C, 0x27, 0x20, 0x18, 0x0F, 0x07, 0x03}, + /* Index6 -1.8dB */ {0x2C, 0x2A, 0x25, 0x1F, 0x17, 0x0F, 0x06, 0x03}, + /* Index7 -2.1dB */ {0x2A, 0x29, 0x24, 0x1E, 0x16, 0x0E, 0x06, 0x03}, + /* Index8 -2.4dB */ {0x29, 0x27, 0x23, 0x1D, 0x15, 0x0E, 0x06, 0x03}, + /* Index9 -2.7dB */ {0x27, 0x26, 0x22, 0x1C, 0x14, 0x0D, 0x06, 0x03}, + /* Index10 -3 dB */ {0x26, 0x25, 0x20, 0x1B, 0x14, 0x0D, 0x06, 0x03}, + /* Index11 -3.3dB */ {0x25, 0x23, 0x1F, 0x1A, 0x13, 0x0C, 0x05, 0x03}, + /* Index12 -3.6dB */ {0x24, 0x22, 0x1E, 0x19, 0x12, 0x0C, 0x05, 0x03}, + /* Index13 -3.9dB */ {0x22, 0x21, 0x1D, 0x18, 0x12, 0x0B, 0x05, 0x03}, + /* Index14 -4.2dB */ {0x21, 0x20, 0x1C, 0x17, 0x11, 0x0B, 0x05, 0x02}, + /* Index15 -4.5dB */ {0x20, 0x1F, 0x1B, 0x17, 0x11, 0x0B, 0x05, 0x02}, + /* Index16 -4.8dB */ {0x1F, 0x1E, 0x1A, 0x16, 0x10, 0x0A, 0x05, 0x02}, + /* Index17 -5.1dB */ {0x1E, 0x1D, 0x1A, 0x15, 0x10, 0x0A, 0x04, 0x02}, + /* Index18 -5.4dB */ {0x1D, 0x1C, 0x19, 0x14, 0x0F, 0x0A, 0x04, 0x02}, + /* Index19 -5.7dB */ {0x1C, 0x1B, 0x18, 0x14, 0x0E, 0x09, 0x04, 0x02}, + /* Index20 -6.0dB */ {0x1B, 0x1A, 0x17, 0x13, 0x0E, 0x09, 0x04, 0x02}, /* 20 This is CCK base index */ + /* Index21 -6.3dB */ {0x1A, 0x19, 0x16, 0x12, 0x0E, 0x09, 0x04, 0x02}, + /* Index22 -6.6dB */ {0x19, 0x18, 0x15, 0x12, 0x0D, 0x08, 0x04, 0x02}, + /* Index23 -6.9dB */ {0x18, 0x17, 0x15, 0x11, 0x0D, 0x08, 0x04, 0x02}, + /* Index24 -7.2dB */ {0x18, 0x17, 0x14, 0x11, 0x0C, 0x08, 0x03, 0x02}, + /* Index25 -7.5dB */ {0x17, 0x16, 0x13, 0x10, 0x0C, 0x08, 0x03, 0x02}, + /* Index26 -7.8dB */ {0x16, 0x15, 0x13, 0x0F, 0x0B, 0x07, 0x03, 0x02}, + /* Index27 -8.1dB */ {0x15, 0x14, 0x12, 0x0F, 0x0B, 0x07, 0x03, 0x02}, + /* Index28 -8.4dB */ {0x14, 0x14, 0x11, 0x0E, 0x0B, 0x07, 0x03, 0x02}, + /* Index29 -8.7dB */ {0x14, 0x13, 0x11, 0x0E, 0x0A, 0x07, 0x03, 0x01}, + /* Index30 -9.0dB */ {0x13, 0x12, 0x10, 0x0D, 0x0A, 0x06, 0x03, 0x01}, /* 30 This is hp CCK base index */ + /* Index31 -9.3dB */ {0x12, 0x12, 0x0F, 0x0D, 0x0A, 0x06, 0x03, 0x01}, + /* Index32 -9.6dB */ {0x12, 0x11, 0x0F, 0x0D, 0x09, 0x06, 0x03, 0x01}, + /* Index33 -9.9dB */ {0x11, 0x11, 0x0F, 0x0C, 0x09, 0x06, 0x03, 0x01}, + /* Index34 -10.2dB */ {0x11, 0x11, 0x0E, 0x0C, 0x09, 0x06, 0x02, 0x01}, + /* Index35 -10.5dB */ {0x10, 0x0F, 0x0E, 0x0B, 0x08, 0x05, 0x02, 0x01}, + /* Index36 -10.8dB */ {0x10, 0x0F, 0x0D, 0x0B, 0x08, 0x05, 0x02, 0x01}, + /* Index37 -11.1dB */ {0x0F, 0x0E, 0x0D, 0x0A, 0x08, 0x05, 0x02, 0x01}, + /* Index38 -11.4dB */ {0x0E, 0x0E, 0x0C, 0x0A, 0x07, 0x05, 0x02, 0x01}, + /* Index39 -11.7dB */ {0x0E, 0x0D, 0x0C, 0x0A, 0x07, 0x05, 0x02, 0x01}, + /* Index40 -12 dB */ {0x0E, 0x0D, 0x0C, 0x0A, 0x07, 0x05, 0x02, 0x01}, + /* Index41 -12.3dB */ {0x0D, 0x0D, 0x0B, 0x09, 0x07, 0x04, 0x02, 0x01}, + /* Index42 -12.6dB */ {0x0D, 0x0C, 0x0B, 0x09, 0x07, 0x04, 0x02, 0x01}, + /* Index43 -12.9dB */ {0x0C, 0x0C, 0x0A, 0x09, 0x06, 0x04, 0x02, 0x01}, + /* Index44 -13.2dB */ {0x0C, 0x0B, 0x0A, 0x08, 0x06, 0x04, 0x02, 0x01}, + /* Index45 -13.5dB */ {0x0B, 0x0B, 0x0A, 0x08, 0x06, 0x04, 0x02, 0x01}, + /* Index46 -13.8dB */ {0x0B, 0x0B, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, + /* Index47 -14.1dB */ {0x0B, 0x0A, 0x09, 0x07, 0x06, 0x04, 0x02, 0x01}, + /* Index48 -14.4dB */ {0x0A, 0x0A, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, + /* Index49 -14.7dB */ {0x0A, 0x0A, 0x08, 0x07, 0x05, 0x03, 0x01, 0x01}, + /* Index50 -15 dB */ {0x0A, 0x09, 0x08, 0x07, 0x05, 0x03, 0x01, 0x01}, + /* Index51 -15.3dB */ {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, + /* Index52 -15.6dB */ {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, + /* Index53 -15.9dB */ {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01} +}; +u8 cck_swing_table_ch14_92e[CCK_TABLE_SIZE_92E][8] = { + /* Index0 0 dB */ {0x36, 0x34, 0x2E, 0x26, 0x00, 0x00, 0x00, 0x00}, + /* Index1 -0.3dB */ {0x34, 0x32, 0x2C, 0x25, 0x00, 0x00, 0x00, 0x00}, + /* Index2 -0.6dB */ {0x32, 0x30, 0x2B, 0x23, 0x00, 0x00, 0x00, 0x00}, + /* Index3 -0.9dB */ {0x31, 0x2F, 0x29, 0x22, 0x00, 0x00, 0x00, 0x00}, + /* Index4 -1.2dB */ {0x2F, 0x2D, 0x28, 0x21, 0x00, 0x00, 0x00, 0x00}, + /* Index5 -1.5dB */ {0x2D, 0x2C, 0x27, 0x20, 0x00, 0x00, 0x00, 0x00}, + /* Index6 -1.8dB */ {0x2C, 0x2A, 0x25, 0x1F, 0x00, 0x00, 0x00, 0x00}, + /* Index7 -2.1dB */ {0x2A, 0x29, 0x24, 0x1E, 0x00, 0x00, 0x00, 0x00}, + /* Index8 -2.4dB */ {0x29, 0x27, 0x23, 0x1D, 0x00, 0x00, 0x00, 0x00}, + /* Index9 -2.7dB */ {0x27, 0x26, 0x22, 0x1C, 0x00, 0x00, 0x00, 0x00}, + /* Index10 -3 dB */ {0x26, 0x25, 0x20, 0x1B, 0x00, 0x00, 0x00, 0x00}, + /* Index11 -3.3dB */ {0x25, 0x23, 0x1F, 0x1A, 0x00, 0x00, 0x00, 0x00}, + /* Index12 -3.6dB */ {0x24, 0x22, 0x1E, 0x19, 0x00, 0x00, 0x00, 0x00}, + /* Index13 -3.9dB */ {0x22, 0x21, 0x1D, 0x18, 0x00, 0x00, 0x00, 0x00}, + /* Index14 -4.2dB */ {0x21, 0x20, 0x1C, 0x17, 0x00, 0x00, 0x00, 0x00}, + /* Index15 -4.5dB */ {0x20, 0x1F, 0x1B, 0x17, 0x00, 0x00, 0x00, 0x00}, + /* Index16 -4.8dB */ {0x1F, 0x1E, 0x1A, 0x16, 0x00, 0x00, 0x00, 0x00}, + /* Index17 -5.1dB */ {0x1E, 0x1D, 0x1A, 0x15, 0x00, 0x00, 0x00, 0x00}, + /* Index18 -5.4dB */ {0x1D, 0x1C, 0x19, 0x14, 0x00, 0x00, 0x00, 0x00}, + /* Index19 -5.7dB */ {0x1C, 0x1B, 0x18, 0x14, 0x00, 0x00, 0x00, 0x00}, + /* Index20 -6 dB */ {0x1B, 0x1A, 0x17, 0x13, 0x00, 0x00, 0x00, 0x00}, + /* Index21 -6.3dB */ {0x1A, 0x19, 0x16, 0x12, 0x00, 0x00, 0x00, 0x00}, + /* Index22 -6.6dB */ {0x19, 0x18, 0x15, 0x12, 0x00, 0x00, 0x00, 0x00}, + /* Index23 -6.9dB */ {0x18, 0x17, 0x15, 0x11, 0x00, 0x00, 0x00, 0x00}, + /* Index24 -7.2dB */ {0x18, 0x17, 0x14, 0x11, 0x00, 0x00, 0x00, 0x00}, + /* Index25 -7.5dB */ {0x17, 0x16, 0x13, 0x10, 0x00, 0x00, 0x00, 0x00}, + /* Index26 -7.8dB */ {0x16, 0x15, 0x13, 0x0F, 0x00, 0x00, 0x00, 0x00}, + /* Index27 -8.1dB */ {0x15, 0x14, 0x12, 0x0F, 0x00, 0x00, 0x00, 0x00}, + /* Index28 -8.4dB */ {0x14, 0x14, 0x11, 0x0E, 0x00, 0x00, 0x00, 0x00}, + /* Index29 -8.7dB */ {0x14, 0x13, 0x11, 0x0E, 0x00, 0x00, 0x00, 0x00}, + /* Index30 -9 dB */ {0x13, 0x12, 0x10, 0x0D, 0x00, 0x00, 0x00, 0x00}, + /* Index31 -9.3dB */ {0x12, 0x12, 0x0F, 0x0D, 0x00, 0x00, 0x00, 0x00}, + /* Index32 -9.6dB */ {0x12, 0x11, 0x0F, 0x0D, 0x00, 0x00, 0x00, 0x00}, + /* Index33 -9.9dB */ {0x11, 0x11, 0x0F, 0x0C, 0x00, 0x00, 0x00, 0x00}, + /* Index34 -10.2dB */ {0x11, 0x11, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00}, + /* Index35 -10.5dB */ {0x10, 0x0F, 0x0E, 0x0B, 0x00, 0x00, 0x00, 0x00}, + /* Index36 -10.8dB */ {0x10, 0x0F, 0x0D, 0x0B, 0x00, 0x00, 0x00, 0x00}, + /* Index37 -11.1dB */ {0x0F, 0x0E, 0x0D, 0x0A, 0x00, 0x00, 0x00, 0x00}, + /* Index38 -11.4dB */ {0x0E, 0x0E, 0x0C, 0x0A, 0x00, 0x00, 0x00, 0x00}, + /* Index39 -11.7dB */ {0x0E, 0x0D, 0x0C, 0x0A, 0x00, 0x00, 0x00, 0x00}, + /* Index40 -12 dB */ {0x0E, 0x0D, 0x0C, 0x0A, 0x00, 0x00, 0x00, 0x00}, + /* Index41 -12.3dB */ {0x0D, 0x0D, 0x0B, 0x09, 0x00, 0x00, 0x00, 0x00}, + /* Index42 -12.6dB */ {0x0D, 0x0C, 0x0B, 0x09, 0x00, 0x00, 0x00, 0x00}, + /* Index43 -12.9dB */ {0x0C, 0x0C, 0x0A, 0x09, 0x00, 0x00, 0x00, 0x00}, + /* Index44 -13.2dB */ {0x0C, 0x0B, 0x0A, 0x08, 0x00, 0x00, 0x00, 0x00}, + /* Index45 -13.5dB */ {0x0B, 0x0B, 0x0A, 0x08, 0x00, 0x00, 0x00, 0x00}, + /* Index46 -13.8dB */ {0x0B, 0x0B, 0x09, 0x08, 0x00, 0x00, 0x00, 0x00}, + /* Index47 -14.1dB */ {0x0B, 0x0A, 0x09, 0x07, 0x00, 0x00, 0x00, 0x00}, + /* Index48 -14.4dB */ {0x0A, 0x0A, 0x09, 0x07, 0x00, 0x00, 0x00, 0x00}, + /* Index49 -14.7dB */ {0x0A, 0x0A, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00}, + /* Index50 -15 dB */ {0x0A, 0x09, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00}, + /* Index51 -15.3dB */ {0x09, 0x09, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00}, + /* Index52 -15.6dB */ {0x09, 0x09, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00}, + /* Index53 -15.9dB */ {0x09, 0x08, 0x07, 0x06, 0x00, 0x00, 0x00, 0x00} +}; +#endif + +#if (RTL8814A_SUPPORT == 1 || RTL8822B_SUPPORT == 1 ||\ + RTL8821C_SUPPORT == 1 || RTL8198F_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1) +u32 tx_scaling_table_jaguar[TXSCALE_TABLE_SIZE] = { + 0x081, /* 0, -12.0dB */ + 0x088, /* 1, -11.5dB */ + 0x090, /* 2, -11.0dB */ + 0x099, /* 3, -10.5dB */ + 0x0A2, /* 4, -10.0dB */ + 0x0AC, /* 5, -9.5dB */ + 0x0B6, /* 6, -9.0dB */ + 0x0C0, /* 7, -8.5dB */ + 0x0CC, /* 8, -8.0dB */ + 0x0D8, /* 9, -7.5dB */ + 0x0E5, /* 10, -7.0dB */ + 0x0F2, /* 11, -6.5dB */ + 0x101, /* 12, -6.0dB */ + 0x110, /* 13, -5.5dB */ + 0x120, /* 14, -5.0dB */ + 0x131, /* 15, -4.5dB */ + 0x143, /* 16, -4.0dB */ + 0x156, /* 17, -3.5dB */ + 0x16A, /* 18, -3.0dB */ + 0x180, /* 19, -2.5dB */ + 0x197, /* 20, -2.0dB */ + 0x1AF, /* 21, -1.5dB */ + 0x1C8, /* 22, -1.0dB */ + 0x1E3, /* 23, -0.5dB */ + 0x200, /* 24, +0 dB */ + 0x21E, /* 25, +0.5dB */ + 0x23E, /* 26, +1.0dB */ + 0x261, /* 27, +1.5dB */ + 0x285, /* 28, +2.0dB */ + 0x2AB, /* 29, +2.5dB */ + 0x2D3, /* 30, +3.0dB */ + 0x2FE, /* 31, +3.5dB */ + 0x32B, /* 32, +4.0dB */ + 0x35C, /* 33, +4.5dB */ + 0x38E, /* 34, +5.0dB */ + 0x3C4, /* 35, +5.5dB */ + 0x3FE /* 36, +6.0dB */ +}; +#elif(ODM_IC_11AC_SERIES_SUPPORT) +u32 ofdm_swing_table_8812[OFDM_TABLE_SIZE_8812] = { + 0x3FE, /* 0, (6dB) */ + 0x3C4, /* 1, (5.5dB) */ + 0x38E, /* 2, (5dB) */ + 0x35C, /* 3, (4.5dB) */ + 0x32B, /* 4, (4dB) */ + 0x2FE, /* 5, (3.5dB) */ + 0x2D3, /* 6, (3dB) */ + 0x2AB, /* 7, (2.5dB) */ + 0x285, /* 8, (2dB) */ + 0x261, /* 9, (1.5dB */ + 0x23E, /* 10, (1dB) */ + 0x21E, /* 11, (0.5dB) */ + 0x200, /* 12, (0dB) 8814 int PA 2G default */ + 0x1E3, /* 13, (-0.5dB) */ + 0x1C8, /* 14, (-1dB) */ + 0x1AF, /* 15, (-1.5dB) */ + 0x197, /* 16, (-2dB) */ + 0x180, /* 17, (-2.5dB) */ + 0x16A, /* 18, (-3dB) 8812 / 8814 int PA 5G / 8814 ext PA 2G5G default */ + 0x156, /* 19, (-3.5dB) */ + 0x143, /* 20, (-4dB) 8812 HP default */ + 0x131, /* 21, (-4.5dB) */ + 0x120, /* 22, (-5dB) */ + 0x110, /* 23, (-5.5dB) */ + 0x101, /* 24, (-6dB) */ + 0x0F2, /* 25, (-6.5dB) */ + 0x0E5, /* 26, (-7dB) */ + 0x0D8, /* 27, (-7.5dB) */ + 0x0CC, /* 28, (-8dB) */ + 0x0C0, /* 29, (-8.5dB) */ + 0x0B6, /* 30, (-9dB) */ + 0x0AC, /* 31, (-9.5dB) */ + 0x0A2, /* 32, (-10dB) */ + 0x099, /* 33, (-10.5dB) */ + 0x090, /* 34, (-11dB) */ + 0x088, /* 35, (-11.5dB) */ + 0x081, /* 36, (-12dB) */ + 0x079, /* 37, (-12.5dB) */ + 0x072, /* 38, (-13dB) */ + 0x06c, /* 39, (-13.5dB) */ + 0x066, /* 40, (-14dB) */ + 0x060, /* 41, (-14.5dB) */ + 0x05B /* 42, (-15dB) */ +}; +#endif + +u32 cck_swing_table_ch1_ch14_8723d[CCK_TABLE_SIZE_8723D] = { + 0x0CD, + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, + 0x287, + 0x2AE, + 0x2D6, + 0x301, + 0x32F, + 0x35F, + 0x392, + 0x3C9, + 0x402, + 0x43F, + 0x47F, + 0x4C3, + 0x50C, + 0x558, + 0x5A9, + 0x5FF, + 0x65A, + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; +/* JJ ADD 20161014 */ +u32 cck_swing_table_ch1_ch14_8710b[CCK_TABLE_SIZE_8710B] = { + 0x0CD, + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, + 0x287, + 0x2AE, + 0x2D6, + 0x301, + 0x32F, + 0x35F, + 0x392, + 0x3C9, + 0x402, + 0x43F, + 0x47F, + 0x4C3, + 0x50C, + 0x558, + 0x5A9, + 0x5FF, + 0x65A, + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + + +/* #endif */ +/* 3============================================================ + * 3 Tx Power Tracking + * 3============================================================ */ + +void +odm_txpowertracking_init( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + if (!(dm->support_ic_type & (ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8814B | ODM_IC_11N_SERIES))) + return; +#endif + + odm_txpowertracking_thermal_meter_init(dm); +} + + +u8 +get_swing_index( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u8 i = 0, bb_swing_mask = 0; + u32 bb_swing = 0; + u32 swing_table_size = 0; + u32 *swing_table = 0; + struct rtl8192cd_priv *priv = dm->priv; + +#if (RTL8197F_SUPPORT == 1) + if (GET_CHIP_VER(priv) == VERSION_8197F) { + bb_swing = phy_query_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKOFDM_D); + swing_table = ofdm_swing_table_new; + swing_table_size = OFDM_TABLE_SIZE_92D; + bb_swing_mask = 22; + } +#endif + +#if (RTL8192F_SUPPORT == 1) + if (GET_CHIP_VER(priv) == VERSION_8192F) { + bb_swing = phy_query_bb_reg(priv, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKOFDM_D); + swing_table = ofdm_swing_table_new; + swing_table_size = OFDM_TABLE_SIZE_92D; + bb_swing_mask = 22; + } +#endif + +#if (RTL8822B_SUPPORT == 1) + if (GET_CHIP_VER(priv) == VERSION_8822B) { + bb_swing = phy_query_bb_reg(priv, REG_A_TX_SCALE_JAGUAR, 0xFFE00000); + swing_table = tx_scaling_table_jaguar; + swing_table_size = TXSCALE_TABLE_SIZE; + bb_swing_mask = 0; + } +#endif + + for (i = 0; i < swing_table_size - 1; i++) { + u32 table_value = swing_table[i] >> bb_swing_mask; + + if (bb_swing == table_value) + break; + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "bb_swing=0x%x bbswing_index=%d\n", bb_swing, i); + + + return i; +} + +s8 +get_txagc_default_index( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + s8 tmp; + +#if RTL8814B_SUPPORT + if (dm->support_ic_type == ODM_RTL8814B) { + tmp = (s8)(odm_get_bb_reg(dm, R_0x18a0, 0x7f) & 0xff); + if (tmp & BIT(6)) + tmp = tmp | 0x80; + return tmp; + } else + return 0; +#endif +} + +void +odm_txpowertracking_thermal_meter_init( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct _hal_rf_ *rf = &dm->rf_table; + struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data; + struct rtl8192cd_priv *priv = dm->priv; + u8 p; + u8 default_swing_index; + u8 i; +#if (RTL8197F_SUPPORT == 1 || RTL8822B_SUPPORT == 1 || RTL8192F_SUPPORT == 1) + if ((GET_CHIP_VER(priv) == VERSION_8197F) || (GET_CHIP_VER(priv) == VERSION_8822B) ||(GET_CHIP_VER(priv) == VERSION_8192F)) + default_swing_index = get_swing_index(dm); +#endif + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + void *adapter = dm->adapter; + PMGNT_INFO mgnt_info = &adapter->MgntInfo; + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + + mgnt_info->is_txpowertracking = true; + hal_data->tx_powercount = 0; + hal_data->is_txpowertracking_init = false; + + if (*(dm->mp_mode) == false) + hal_data->txpowertrack_control = true; + RF_DBG(dm, COMP_POWER_TRACKING, "mgnt_info->is_txpowertracking = %d\n", mgnt_info->is_txpowertracking); +#elif (DM_ODM_SUPPORT_TYPE == ODM_CE) +#ifdef CONFIG_RTL8188E + { + dm->rf_calibrate_info.is_txpowertracking = true; + dm->rf_calibrate_info.tx_powercount = 0; + dm->rf_calibrate_info.is_txpowertracking_init = false; + + if (*(dm->mp_mode) == false) + dm->rf_calibrate_info.txpowertrack_control = true; + + MSG_8192C("dm txpowertrack_control = %d\n", dm->rf_calibrate_info.txpowertrack_control); + } +#else + { + void *adapter = dm->adapter; + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + struct dm_priv *pdmpriv = &hal_data->dmpriv; + + pdmpriv->is_txpowertracking = true; + pdmpriv->tx_powercount = 0; + pdmpriv->is_txpowertracking_init = false; + + if (*(dm->mp_mode) == false) /* for mp driver, turn off txpwrtracking as default */ + pdmpriv->txpowertrack_control = true; + + MSG_8192C("pdmpriv->txpowertrack_control = %d\n", pdmpriv->txpowertrack_control); + + } +#endif/* endif (CONFIG_RTL8188E==1) */ +#elif (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + +#ifdef RTL8188E_SUPPORT + { + dm->rf_calibrate_info.is_txpowertracking = true; + dm->rf_calibrate_info.tx_powercount = 0; + dm->rf_calibrate_info.is_txpowertracking_init = false; + dm->rf_calibrate_info.txpowertrack_control = true; + dm->rf_calibrate_info.tm_trigger = 0; + } +#endif +#endif + + dm->rf_calibrate_info.txpowertrack_control = true; + dm->rf_calibrate_info.delta_power_index = 0; + dm->rf_calibrate_info.delta_power_index_last = 0; + dm->rf_calibrate_info.power_index_offset = 0; + dm->rf_calibrate_info.thermal_value = 0; + cali_info->default_ofdm_index = 28; + +#if (RTL8197F_SUPPORT == 1) + if (GET_CHIP_VER(priv) == VERSION_8197F) { + cali_info->default_ofdm_index = (default_swing_index >= (OFDM_TABLE_SIZE_92D - 1)) ? 30 : default_swing_index; + cali_info->default_cck_index = 28; + } +#endif + +#if (RTL8192F_SUPPORT == 1) + if (GET_CHIP_VER(priv) == VERSION_8192F) { + cali_info->default_ofdm_index = (default_swing_index >= (OFDM_TABLE_SIZE_92D - 1)) ? 30 : default_swing_index; + cali_info->default_cck_index = 28; + } +#endif + +#if (RTL8822B_SUPPORT == 1) + if (GET_CHIP_VER(priv) == VERSION_8822B) { + cali_info->default_ofdm_index = (default_swing_index >= (TXSCALE_TABLE_SIZE - 1)) ? 24 : default_swing_index; + cali_info->default_cck_index = 20; + } +#endif + + +#if RTL8188E_SUPPORT + if (GET_CHIP_VER(priv) == VERSION_8188E) { + cali_info->default_cck_index = 20; /* -6 dB */ + } +#endif + +#if RTL8192E_SUPPORT + if (GET_CHIP_VER(priv) == VERSION_8192E) { + cali_info->default_cck_index = 8; /* -12 dB */ + } +#endif + +#if RTL8814B_SUPPORT + if (GET_CHIP_VER(priv) == VERSION_8814B) { + cali_info->default_txagc_index = get_txagc_default_index(dm); + + for (i = 0; i < MAX_PATH_NUM_8814B; i++) + tssi->tssi_trk_txagc_offset[i] = + cali_info->default_txagc_index; + } +#endif + + cali_info->bb_swing_idx_ofdm_base = cali_info->default_ofdm_index; + cali_info->bb_swing_idx_cck_base = cali_info->default_cck_index; + dm->rf_calibrate_info.CCK_index = cali_info->default_cck_index; + + for (p = 0; p < MAX_RF_PATH; p++) { + dm->rf_calibrate_info.OFDM_index[p] = cali_info->default_ofdm_index; + cali_info->bb_swing_idx_ofdm[p] = cali_info->default_ofdm_index; + cali_info->kfree_offset[p] = 0; /* for 8814 kfree*/ + } + cali_info->bb_swing_idx_cck = cali_info->default_cck_index; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "cali_info->default_ofdm_index=%d cali_info->default_cck_index=%d\n", cali_info->default_ofdm_index, cali_info->default_cck_index); + + cali_info->tm_trigger = 0; +} + + +void +odm_txpowertracking_check( + void *dm_void +) +{ + /* */ + /* For AP/ADSL use struct rtl8192cd_priv* */ + /* For CE/NIC use struct void* */ + /* */ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &(dm->rf_table); + + if (!(rf->rf_supportability & HAL_RF_TX_PWR_TRACK)) + return; + + /* */ + /* 2011/09/29 MH In HW integration first stage, we provide 4 different handle to operate */ + /* at the same time. In the stage2/3, we need to prive universal interface and merge all */ + /* HW dynamic mechanism. */ + /* */ + switch (dm->support_platform) { + case ODM_WIN: + odm_txpowertracking_check_mp(dm); + break; + + case ODM_CE: + odm_txpowertracking_check_ce(dm); + break; + + case ODM_AP: + odm_txpowertracking_check_ap(dm); + break; + } + +} + +void +odm_txpowertracking_check_ce( + void *dm_void +) +{ +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) + struct dm_struct *dm = (struct dm_struct *)dm_void; + void *adapter = dm->adapter; + struct _hal_rf_ *rf = &(dm->rf_table); + +#if (RTL8188E_SUPPORT == 1) + + /* if(!mgnt_info->is_txpowertracking || (!pdmpriv->txpowertrack_control && pdmpriv->is_ap_kdone)) */ + + if (!(rf->rf_supportability & HAL_RF_TX_PWR_TRACK)) + return; + + if (!dm->rf_calibrate_info.tm_trigger) { /* at least delay 1 sec */ + /* hal_data->TxPowerCheckCnt++; */ /* cosa add for debug */ + odm_set_rf_reg(dm, RF_PATH_A, RF_T_METER, RFREGOFFSETMASK, 0x60); + /* DBG_8192C("Trigger 92C Thermal Meter!!\n"); */ + + dm->rf_calibrate_info.tm_trigger = 1; + return; + + } else { + /* DBG_8192C("Schedule TxPowerTracking direct call!!\n"); */ + odm_txpowertracking_callback_thermal_meter_8188e(adapter); + dm->rf_calibrate_info.tm_trigger = 0; + } +#endif + +#endif +} + +void +odm_txpowertracking_check_mp( + void *dm_void +) +{ +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + struct dm_struct *dm = (struct dm_struct *)dm_void; + void *adapter = dm->adapter; + + if (odm_check_power_status(adapter) == false) + return; + + if (!adapter->is_slave_of_dmsp || adapter->dual_mac_smart_concurrent == false) + odm_txpowertracking_thermal_meter_check(adapter); +#endif + +} + + +void +odm_txpowertracking_check_ap( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data; + +#if ((RTL8188E_SUPPORT == 1) || (RTL8192E_SUPPORT == 1) || (RTL8812A_SUPPORT == 1) || (RTL8881A_SUPPORT == 1) || (RTL8814A_SUPPORT == 1) || (RTL8197F_SUPPORT == 1) || (RTL8192F_SUPPORT == 1) || (RTL8198F_SUPPORT == 1) || (RTL8814B_SUPPORT == 1) || (RTL8812F_SUPPORT == 1) || (RTL8197G_SUPPORT == 1)) + if (!dm->rf_calibrate_info.tm_trigger) { + if (dm->support_ic_type & (ODM_RTL8188E | ODM_RTL8192E | ODM_RTL8812 | ODM_RTL8881A | ODM_RTL8814A | ODM_RTL8197F | ODM_RTL8822B | ODM_RTL8821C | ODM_RTL8192F | ODM_RTL8198F)) { + odm_set_rf_reg(dm, RF_PATH_A, 0x42, (BIT(17) | BIT(16)), 0x3); + } else if (dm->support_ic_type & ODM_RTL8812F) { + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x01); + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x00); + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x01); + + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x01); + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x00); + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x01); + } else if (dm->support_ic_type & ODM_RTL8814B) { + odm_set_rf_reg(dm, RF_PATH_A, 0x42, BIT(17), 0x1); + odm_set_rf_reg(dm, RF_PATH_B, 0x42, BIT(17), 0x1); + odm_set_rf_reg(dm, RF_PATH_C, 0x42, BIT(17), 0x1); + odm_set_rf_reg(dm, RF_PATH_D, 0x42, BIT(17), 0x1); + } else if (dm->support_ic_type & ODM_RTL8197G) { + odm_set_rf_reg(dm, RF_PATH_A, RF_0x42, BIT(17), 0x1); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x42, BIT(17), 0x0); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x42, BIT(17), 0x1); + + odm_set_rf_reg(dm, RF_PATH_B, RF_0x42, BIT(17), 0x1); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x42, BIT(17), 0x0); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x42, BIT(17), 0x1); + } + + if (dm->support_ic_type & ODM_RTL8814B) { + ODM_delay_us(300); + odm_txpowertracking_callback_thermal_meter(dm); + tssi->thermal_trigger = 1; + } + + dm->rf_calibrate_info.tm_trigger = 1; + } else { + odm_txpowertracking_callback_thermal_meter(dm); + if (dm->support_ic_type & ODM_RTL8814B) + tssi->thermal_trigger = 0; + dm->rf_calibrate_info.tm_trigger = 0; + } +#endif + +} diff --git a/hal/phydm/halrf/halrf_powertracking_ap.h b/hal/phydm/halrf/halrf_powertracking_ap.h new file mode 100644 index 0000000..098e284 --- /dev/null +++ b/hal/phydm/halrf/halrf_powertracking_ap.h @@ -0,0 +1,407 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#ifndef __HALRF_POWERTRACKING_H__ +#define __HALRF_POWERTRACKING_H__ + +#if (DM_ODM_SUPPORT_TYPE == ODM_AP) + #ifdef RTK_AC_SUPPORT + #define ODM_IC_11AC_SERIES_SUPPORT 1 + #else + #define ODM_IC_11AC_SERIES_SUPPORT 0 + #endif +#else + #define ODM_IC_11AC_SERIES_SUPPORT 1 +#endif + +#define DPK_DELTA_MAPPING_NUM 13 +#define index_mapping_HP_NUM 15 +#define DELTA_SWINGIDX_SIZE 30 +#define DELTA_SWINTSSI_SIZE 61 +#define BAND_NUM 3 +#define MAX_RF_PATH 4 +#define TXSCALE_TABLE_SIZE 37 +#define CCK_TABLE_SIZE_8723D 41 +/* JJ ADD 20161014 */ +#define CCK_TABLE_SIZE_8710B 41 + +#define IQK_MAC_REG_NUM 4 +#define IQK_ADDA_REG_NUM 16 +#define IQK_BB_REG_NUM_MAX 10 + +#define IQK_BB_REG_NUM 9 + +#define AVG_THERMAL_NUM 8 +#define AVG_THERMAL_NUM_DPK 8 +#define THERMAL_DPK_AVG_NUM 4 + +#define iqk_matrix_reg_num 8 +/* #define IQK_MATRIX_SETTINGS_NUM 1+24+21 */ +#define IQK_MATRIX_SETTINGS_NUM (14+24+21) /* Channels_2_4G_NUM + Channels_5G_20M_NUM + Channels_5G */ + +#if !defined(_OUTSRC_COEXIST) + #define OFDM_TABLE_SIZE_92D 43 + #define OFDM_TABLE_SIZE 37 + #define CCK_TABLE_SIZE 33 + #define CCK_TABLE_SIZE_88F 21 + #define CCK_TABLE_SIZE_8192F 41 + + + + /* #define OFDM_TABLE_SIZE_92E 54 */ + /* #define CCK_TABLE_SIZE_92E 54 */ + extern u32 ofdm_swing_table[OFDM_TABLE_SIZE_92D]; + extern u8 cck_swing_table_ch1_ch13[CCK_TABLE_SIZE][8]; + extern u8 cck_swing_table_ch14[CCK_TABLE_SIZE][8]; + + + extern u32 ofdm_swing_table_new[OFDM_TABLE_SIZE_92D]; + extern u8 cck_swing_table_ch1_ch13_new[CCK_TABLE_SIZE][8]; + extern u8 cck_swing_table_ch14_new[CCK_TABLE_SIZE][8]; + extern u8 cck_swing_table_ch1_ch14_88f[CCK_TABLE_SIZE_88F][16]; + extern u8 cck_swing_table_ch1_ch13_88f[CCK_TABLE_SIZE_88F][16]; + extern u8 cck_swing_table_ch14_88f[CCK_TABLE_SIZE_88F][16]; + extern u32 cck_swing_table_ch1_ch14_8192f[CCK_TABLE_SIZE_8192F]; + +#endif + +#define ODM_OFDM_TABLE_SIZE 37 +#define ODM_CCK_TABLE_SIZE 33 +#define TXPWR_TRACK_TABLE_SIZE 30 +/* <20140613, YuChen> In case fail to read TxPowerTrack.txt, we use the table of 88E as the default table. */ +extern u8 delta_swing_table_idx_2ga_p_default[DELTA_SWINGIDX_SIZE]; +extern u8 delta_swing_table_idx_2ga_n_default[DELTA_SWINGIDX_SIZE]; + +static u8 delta_swing_table_idx_2ga_p_8188e[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9}; +static u8 delta_swing_table_idx_2ga_n_8188e[] = {0, 0, 0, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11}; + +/* extern u32 ofdm_swing_table_92e[OFDM_TABLE_SIZE_92E]; + * extern u8 cck_swing_table_ch1_ch13_92e[CCK_TABLE_SIZE_92E][8]; + * extern u8 cck_swing_table_ch14_92e[CCK_TABLE_SIZE_92E][8]; */ + +#ifdef CONFIG_WLAN_HAL_8192EE + #define OFDM_TABLE_SIZE_92E 54 + #define CCK_TABLE_SIZE_92E 54 + extern u32 ofdm_swing_table_92e[OFDM_TABLE_SIZE_92E]; + extern u8 cck_swing_table_ch1_ch13_92e[CCK_TABLE_SIZE_92E][8]; + extern u8 cck_swing_table_ch14_92e[CCK_TABLE_SIZE_92E][8]; +#endif + +#define OFDM_TABLE_SIZE_8812 43 +#define AVG_THERMAL_NUM_8812 4 + +#if (RTL8814A_SUPPORT == 1 || RTL8822B_SUPPORT == 1 ||\ + RTL8821C_SUPPORT == 1 || RTL8198F_SUPPORT == 1 ||\ + RTL8814B_SUPPORT == 1) + extern u32 tx_scaling_table_jaguar[TXSCALE_TABLE_SIZE]; + #elif(ODM_IC_11AC_SERIES_SUPPORT) + extern unsigned int ofdm_swing_table_8812[OFDM_TABLE_SIZE_8812]; +#endif + +extern u32 cck_swing_table_ch1_ch14_8723d[CCK_TABLE_SIZE_8723D]; +/* JJ ADD 20161014 */ +extern u32 cck_swing_table_ch1_ch14_8710b[CCK_TABLE_SIZE_8710B]; + +#define dm_check_txpowertracking odm_txpowertracking_check + +struct iqk_matrix_regs_setting { + boolean is_iqk_done; + s32 value[1][iqk_matrix_reg_num]; +}; + +struct dm_rf_calibration_struct { + /* for tx power tracking */ + + u32 rega24; /* for TempCCK */ + s32 rege94; + s32 rege9c; + s32 regeb4; + s32 regebc; + + /* u8 is_txpowertracking; */ + u8 tx_powercount; + boolean is_txpowertracking_init; + boolean is_txpowertracking; + u8 txpowertrack_control; /* for mp mode, turn off txpwrtracking as default */ + u8 tm_trigger; + u8 internal_pa_5g[2]; /* pathA / pathB */ + + u8 thermal_meter[2]; /* thermal_meter, index 0 for RFIC0, and 1 for RFIC1 */ + u8 thermal_value; + u8 thermal_value_path[MAX_RF_PATH]; + u8 thermal_value_lck; + u8 thermal_value_iqk; + s8 thermal_value_delta; /* delta of thermal_value and efuse thermal */ + u8 thermal_value_avg[AVG_THERMAL_NUM]; + u8 thermal_value_avg_path[MAX_RF_PATH][AVG_THERMAL_NUM]; + u8 thermal_value_avg_index; + u8 thermal_value_avg_index_path[MAX_RF_PATH]; + s8 power_index_offset_path[MAX_RF_PATH]; + + u8 thermal_value_rx_gain; + u8 thermal_value_crystal; + u8 thermal_value_dpk_store; + u8 thermal_value_dpk_track; + boolean txpowertracking_in_progress; + + + boolean is_reloadtxpowerindex; + u8 is_rf_pi_enable; + u32 txpowertracking_callback_cnt; /* cosa add for debug */ + + u8 is_cck_in_ch14; + u8 CCK_index; + u8 OFDM_index[MAX_RF_PATH]; + s8 power_index_offset; + s8 delta_power_index; + s8 delta_power_index_path[MAX_RF_PATH]; + s8 delta_power_index_last; + s8 delta_power_index_last_path[MAX_RF_PATH]; + boolean is_tx_power_changed; + + struct iqk_matrix_regs_setting iqk_matrix_reg_setting[IQK_MATRIX_SETTINGS_NUM]; + u8 delta_lck; + u8 delta_swing_table_idx_2g_cck_a_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_a_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_b_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_b_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_c_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_c_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_d_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_d_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gb_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gb_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gc_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gc_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gd_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gd_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5ga_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5ga_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gb_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gb_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gc_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gc_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gd_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gd_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_tssi_table_2g_cck_a[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_b[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_c[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_d[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2ga[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gb[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gc[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gd[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5ga[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gb[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gc[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gd[BAND_NUM][DELTA_SWINTSSI_SIZE]; + s8 delta_swing_table_xtal_p[DELTA_SWINGIDX_SIZE]; + s8 delta_swing_table_xtal_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_p_8188e[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_n_8188e[DELTA_SWINGIDX_SIZE]; + + u8 bb_swing_idx_ofdm[MAX_RF_PATH]; + u8 bb_swing_idx_ofdm_current; +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + u8 bb_swing_idx_ofdm_base[MAX_RF_PATH]; +#else + u8 bb_swing_idx_ofdm_base; + u8 bb_swing_idx_ofdm_base_path[MAX_RF_PATH]; +#endif + boolean bb_swing_flag_ofdm; + u8 bb_swing_idx_cck; + u8 bb_swing_idx_cck_current; + u8 bb_swing_idx_cck_base; + u8 default_ofdm_index; + u8 default_cck_index; + s8 default_txagc_index; + boolean bb_swing_flag_cck; + + s8 absolute_ofdm_swing_idx[MAX_RF_PATH]; + s8 remnant_ofdm_swing_idx[MAX_RF_PATH]; + s8 absolute_cck_swing_idx[MAX_RF_PATH]; + s8 remnant_cck_swing_idx; + s8 modify_tx_agc_value; /*Remnat compensate value at tx_agc */ + boolean modify_tx_agc_flag_path_a; + boolean modify_tx_agc_flag_path_b; + boolean modify_tx_agc_flag_path_c; + boolean modify_tx_agc_flag_path_d; + boolean modify_tx_agc_flag_path_a_cck; + boolean modify_tx_agc_flag_path_b_cck; + + s8 kfree_offset[MAX_RF_PATH]; + + /* -------------------------------------------------------------------- */ + + /* for IQK */ + u32 regc04; + u32 reg874; + u32 regc08; + u32 regb68; + u32 regb6c; + u32 reg870; + u32 reg860; + u32 reg864; + + boolean is_iqk_initialized; + boolean is_lck_in_progress; + boolean is_antenna_detected; + boolean is_need_iqk; + boolean is_iqk_in_progress; + boolean is_iqk_pa_off; + u8 delta_iqk; + u32 ADDA_backup[IQK_ADDA_REG_NUM]; + u32 IQK_MAC_backup[IQK_MAC_REG_NUM]; + u32 IQK_BB_backup_recover[9]; + u32 IQK_BB_backup[IQK_BB_REG_NUM]; + u32 tx_iqc_8723b[2][3][2]; /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}} */ + u32 rx_iqc_8723b[2][2][2]; /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}} */ + u32 tx_iqc_8703b[3][2]; /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}}*/ + u32 rx_iqc_8703b[2][2]; /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}}*/ + + u64 iqk_start_time; + u64 iqk_total_progressing_time; + u64 iqk_progressing_time; + u64 lck_progressing_time; + u32 lok_result; + u8 iqk_step; + u8 kcount; + u8 retry_count[4][2]; /* [4]: path ABCD, [2] TXK, RXK */ + boolean is_mp_mode; + + /* for APK */ + u32 ap_koutput[2][2]; /* path A/B; output1_1a/output1_2a */ + u8 is_ap_kdone; + u8 is_apk_thermal_meter_ignore; + u8 is_dp_done; +#if 0 /*move below members to halrf_dpk.h*/ + u8 is_dp_path_aok; + u8 is_dp_path_bok; + u8 is_dp_path_cok; + u8 is_dp_path_dok; + u8 dp_path_a_result[3]; + u8 dp_path_b_result[3]; + u8 dp_path_c_result[3]; + u8 dp_path_d_result[3]; + boolean is_dpk_enable; + u32 txrate[11]; + u8 pwsf_2g_a[3]; + u8 pwsf_2g_b[3]; + u8 pwsf_2g_c[3]; + u8 pwsf_2g_d[3]; + u32 lut_2g_even_a[3][64]; + u32 lut_2g_odd_a[3][64]; + u32 lut_2g_even_b[3][64]; + u32 lut_2g_odd_b[3][64]; + u32 lut_2g_even_c[3][64]; + u32 lut_2g_odd_c[3][64]; + u32 lut_2g_even_d[3][64]; + u32 lut_2g_odd_d[3][64]; + u1Byte is_5g_pdk_a_ok; + u1Byte is_5g_pdk_b_ok; + u1Byte is_5g_pdk_c_ok; + u1Byte is_5g_pdk_d_ok; + u1Byte pwsf_5g_a[9]; + u1Byte pwsf_5g_b[9]; + u1Byte pwsf_5g_c[9]; + u1Byte pwsf_5g_d[9]; + u4Byte lut_5g_even_a[9][16]; + u4Byte lut_5g_odd_a[9][16]; + u4Byte lut_5g_even_b[9][16]; + u4Byte lut_5g_odd_b[9][16]; + u4Byte lut_5g_even_c[9][16]; + u4Byte lut_5g_odd_c[9][16]; + u4Byte lut_5g_even_d[9][16]; + u4Byte lut_5g_odd_d[9][16]; + u8 thermal_value_dpk; + u8 thermal_value_dpk_avg[AVG_THERMAL_NUM_DPK]; + u8 thermal_value_dpk_avg_index; +#endif + s8 modify_tx_agc_value_ofdm; + s8 modify_tx_agc_value_cck; + + /*Add by Yuchen for Kfree Phydm*/ + u8 reg_rf_kfree_enable; /*for registry*/ + u8 rf_kfree_enable; /*for efuse enable check*/ + u32 tx_lok[2]; +}; + +void +odm_txpowertracking_check_ap( + void *dm_void +); + +void +odm_txpowertracking_check( + void *dm_void +); + + +void +odm_txpowertracking_thermal_meter_init( + void *dm_void +); + +void +odm_txpowertracking_init( + void *dm_void +); + +void +odm_txpowertracking_check_mp( + void *dm_void +); + + +void +odm_txpowertracking_check_ce( + void *dm_void +); + + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN)) + +void +odm_txpowertracking_callback_thermal_meter92c( + void *adapter +); + +void +odm_txpowertracking_callback_rx_gain_thermal_meter92d( + void *adapter +); + +void +odm_txpowertracking_callback_thermal_meter92d( + void *adapter +); + +void +odm_txpowertracking_direct_call92c( + void *adapter +); + +void +odm_txpowertracking_thermal_meter_check( + void *adapter +); + +#endif + + + +#endif /*#ifndef __HALRF_POWER_TRACKING_H__*/ diff --git a/hal/phydm/halrf/halrf_powertracking_ce.c b/hal/phydm/halrf/halrf_powertracking_ce.c new file mode 100644 index 0000000..4fd3de0 --- /dev/null +++ b/hal/phydm/halrf/halrf_powertracking_ce.c @@ -0,0 +1,969 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +/*@=========================================================== + * include files + *============================================================ + */ + +#include "mp_precomp.h" +#include "phydm_precomp.h" + +/*@************************************************************ + * Global var + * ************************************************************ + */ + +u32 ofdm_swing_table[OFDM_TABLE_SIZE] = { + 0x7f8001fe, /* 0, +6.0dB */ + 0x788001e2, /* 1, +5.5dB */ + 0x71c001c7, /* 2, +5.0dB*/ + 0x6b8001ae, /* 3, +4.5dB*/ + 0x65400195, /* 4, +4.0dB*/ + 0x5fc0017f, /* 5, +3.5dB*/ + 0x5a400169, /* 6, +3.0dB*/ + 0x55400155, /* 7, +2.5dB*/ + 0x50800142, /* 8, +2.0dB*/ + 0x4c000130, /* 9, +1.5dB*/ + 0x47c0011f, /* 10, +1.0dB*/ + 0x43c0010f, /* 11, +0.5dB*/ + 0x40000100, /* 12, +0dB*/ + 0x3c8000f2, /* 13, -0.5dB*/ + 0x390000e4, /* 14, -1.0dB*/ + 0x35c000d7, /* 15, -1.5dB*/ + 0x32c000cb, /* 16, -2.0dB*/ + 0x300000c0, /* 17, -2.5dB*/ + 0x2d4000b5, /* 18, -3.0dB*/ + 0x2ac000ab, /* 19, -3.5dB*/ + 0x288000a2, /* 20, -4.0dB*/ + 0x26000098, /* 21, -4.5dB*/ + 0x24000090, /* 22, -5.0dB*/ + 0x22000088, /* 23, -5.5dB*/ + 0x20000080, /* 24, -6.0dB*/ + 0x1e400079, /* 25, -6.5dB*/ + 0x1c800072, /* 26, -7.0dB*/ + 0x1b00006c, /* 27. -7.5dB*/ + 0x19800066, /* 28, -8.0dB*/ + 0x18000060, /* 29, -8.5dB*/ + 0x16c0005b, /* 30, -9.0dB*/ + 0x15800056, /* 31, -9.5dB*/ + 0x14400051, /* 32, -10.0dB*/ + 0x1300004c, /* 33, -10.5dB*/ + 0x12000048, /* 34, -11.0dB*/ + 0x11000044, /* 35, -11.5dB*/ + 0x10000040, /* 36, -12.0dB*/ +}; + +u8 cck_swing_table_ch1_ch13[CCK_TABLE_SIZE][8] = { + {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, /* 0, +0dB */ + {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 1, -0.5dB */ + {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 2, -1.0dB */ + {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 3, -1.5dB */ + {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 4, -2.0dB */ + {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 5, -2.5dB */ + {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 6, -3.0dB */ + {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 7, -3.5dB */ + {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 8, -4.0dB */ + {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 9, -4.5dB */ + {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 10, -5.0dB */ + {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 11, -5.5dB */ + {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 12, -6.0 default*/ + {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 13, -6.5dB */ + {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 14, -7.0dB */ + {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 15, -7.5dB */ + {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */ + {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 17, -8.5dB */ + {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 18, -9.0dB */ + {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 19, -9.5dB */ + {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 20, -10.0dB */ + {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 21, -10.5dB */ + {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 22, -11.0dB */ + {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 23, -11.5dB */ + {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 24, -12.0dB */ + {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 25, -12.5dB */ + {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 26, -13.0dB */ + {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 27, -13.5dB */ + {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 28, -14.0dB */ + {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 29, -14.5dB */ + {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 30, -15.0dB */ + {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 31, -15.5dB */ + {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01} /* 32, -16.0dB */ +}; + +u8 cck_swing_table_ch14[CCK_TABLE_SIZE][8] = { + {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, /* 0, +0dB */ + {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 1, -0.5dB */ + {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 2, -1.0dB */ + {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 3, -1.5dB */ + {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 4, -2.0dB */ + {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 5, -2.5dB */ + {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 6, -3.0dB */ + {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 7, -3.5dB */ + {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 8, -4.0dB */ + {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 9, -4.5dB */ + {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 10, -5.0dB */ + {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 11, -5.5dB */ + {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 12, -6.0 default*/ + {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 13, -6.5dB */ + {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 14, -7.0dB */ + {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 15, -7.5dB */ + {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */ + {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 17, -8.5dB */ + {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 18, -9.0dB */ + {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 19, -9.5dB */ + {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 20, -10.0dB */ + {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 21, -10.5dB */ + {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 22, -11.0dB */ + {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 23, -11.5dB */ + {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 24, -12.0dB */ + {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 25, -12.5dB */ + {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 26, -13.0dB */ + {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 27, -13.5dB */ + {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 28, -14.0dB */ + {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 29, -14.5dB */ + {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 30, -15.0dB */ + {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 31, -15.5dB */ + {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00} /* 32, -16.0dB */ +}; + +u32 ofdm_swing_table_new[OFDM_TABLE_SIZE] = { + 0x0b40002d, /* 0, -15.0dB */ + 0x0c000030, /* 1, -14.5dB */ + 0x0cc00033, /* 2, -14.0dB */ + 0x0d800036, /* 3, -13.5dB */ + 0x0e400039, /* 4, -13.0dB */ + 0x0f00003c, /* 5, -12.5dB */ + 0x10000040, /* 6, -12.0dB */ + 0x11000044, /* 7, -11.5dB */ + 0x12000048, /* 8, -11.0dB */ + 0x1300004c, /* 9, -10.5dB */ + 0x14400051, /* 10, -10.0dB */ + 0x15800056, /* 11, -9.5dB */ + 0x16c0005b, /* 12, -9.0dB */ + 0x18000060, /* 13, -8.5dB */ + 0x19800066, /* 14, -8.0dB */ + 0x1b00006c, /* 15, -7.5dB */ + 0x1c800072, /* 16, -7.0dB */ + 0x1e400079, /* 17, -6.5dB */ + 0x20000080, /* 18, -6.0dB */ + 0x22000088, /* 19, -5.5dB */ + 0x24000090, /* 20, -5.0dB */ + 0x26000098, /* 21, -4.5dB */ + 0x288000a2, /* 22, -4.0dB */ + 0x2ac000ab, /* 23, -3.5dB */ + 0x2d4000b5, /* 24, -3.0dB */ + 0x300000c0, /* 25, -2.5dB */ + 0x32c000cb, /* 26, -2.0dB */ + 0x35c000d7, /* 27, -1.5dB */ + 0x390000e4, /* 28, -1.0dB */ + 0x3c8000f2, /* 29, -0.5dB */ + 0x40000100, /* 30, +0dB */ + 0x43c0010f, /* 31, +0.5dB */ + 0x47c0011f, /* 32, +1.0dB */ + 0x4c000130, /* 33, +1.5dB */ + 0x50800142, /* 34, +2.0dB */ + 0x55400155, /* 35, +2.5dB */ + 0x5a400169, /* 36, +3.0dB */ + 0x5fc0017f, /* 37, +3.5dB */ + 0x65400195, /* 38, +4.0dB */ + 0x6b8001ae, /* 39, +4.5dB */ + 0x71c001c7, /* 40, +5.0dB */ + 0x788001e2, /* 41, +5.5dB */ + 0x7f8001fe /* 42, +6.0dB */ +}; + +u8 cck_swing_table_ch1_ch14_88f[CCK_TABLE_SIZE_88F][16] = { + {0x44, 0x42, 0x3C, 0x33, 0x28, 0x1C, 0x13, 0x0B, 0x05, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-16dB*/ + {0x48, 0x46, 0x3F, 0x36, 0x2A, 0x1E, 0x14, 0x0B, 0x05, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15.5dB*/ + {0x4D, 0x4A, 0x43, 0x39, 0x2C, 0x20, 0x15, 0x0C, 0x06, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15dB*/ + {0x51, 0x4F, 0x47, 0x3C, 0x2F, 0x22, 0x16, 0x0D, 0x06, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14.5dB*/ + {0x56, 0x53, 0x4B, 0x40, 0x32, 0x24, 0x17, 0x0E, 0x06, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14dB*/ + {0x5B, 0x58, 0x50, 0x43, 0x35, 0x26, 0x19, 0x0E, 0x07, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13.5dB*/ + {0x60, 0x5D, 0x54, 0x47, 0x38, 0x28, 0x1A, 0x0F, 0x07, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13dB*/ + {0x66, 0x63, 0x59, 0x4C, 0x3B, 0x2B, 0x1C, 0x10, 0x08, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12.5dB*/ + {0x6C, 0x69, 0x5F, 0x50, 0x3F, 0x2D, 0x1E, 0x11, 0x08, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12dB*/ + {0x73, 0x6F, 0x64, 0x55, 0x42, 0x30, 0x1F, 0x12, 0x08, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11.5dB*/ + {0x79, 0x76, 0x6A, 0x5A, 0x46, 0x33, 0x21, 0x13, 0x09, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11dB*/ + {0x81, 0x7C, 0x71, 0x5F, 0x4A, 0x36, 0x23, 0x14, 0x0A, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10.5dB*/ + {0x88, 0x84, 0x77, 0x65, 0x4F, 0x39, 0x25, 0x15, 0x0A, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10dB*/ + {0x90, 0x8C, 0x7E, 0x6B, 0x54, 0x3C, 0x27, 0x17, 0x0B, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9.5dB*/ + {0x99, 0x94, 0x86, 0x71, 0x58, 0x40, 0x2A, 0x18, 0x0B, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9dB*/ + {0xA2, 0x9D, 0x8E, 0x78, 0x5E, 0x43, 0x2C, 0x19, 0x0C, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8.5dB*/ + {0xAC, 0xA6, 0x96, 0x7F, 0x63, 0x47, 0x2F, 0x1B, 0x0D, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8dB*/ + {0xB6, 0xB0, 0x9F, 0x87, 0x69, 0x4C, 0x32, 0x1D, 0x0D, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7.5dB*/ + {0xC1, 0xBA, 0xA8, 0x8F, 0x6F, 0x50, 0x35, 0x1E, 0x0E, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7dB*/ + {0xCC, 0xC5, 0xB2, 0x97, 0x76, 0x55, 0x38, 0x20, 0x0F, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-6.5dB*/ + {0xD8, 0xD1, 0xBD, 0xA0, 0x7D, 0x5A, 0x3B, 0x22, 0x10, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /*-6dB*/ +}; + +u8 cck_swing_table_ch1_ch13_88f[CCK_TABLE_SIZE_88F][16] = { + {0x44, 0x42, 0x3C, 0x33, 0x28, 0x1C, 0x13, 0x0B, 0x05, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-16dB*/ + {0x48, 0x46, 0x3F, 0x36, 0x2A, 0x1E, 0x14, 0x0B, 0x05, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15.5dB*/ + {0x4D, 0x4A, 0x43, 0x39, 0x2C, 0x20, 0x15, 0x0C, 0x06, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15dB*/ + {0x51, 0x4F, 0x47, 0x3C, 0x2F, 0x22, 0x16, 0x0D, 0x06, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14.5dB*/ + {0x56, 0x53, 0x4B, 0x40, 0x32, 0x24, 0x17, 0x0E, 0x06, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14dB*/ + {0x5B, 0x58, 0x50, 0x43, 0x35, 0x26, 0x19, 0x0E, 0x07, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13.5dB*/ + {0x60, 0x5D, 0x54, 0x47, 0x38, 0x28, 0x1A, 0x0F, 0x07, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13dB*/ + {0x66, 0x63, 0x59, 0x4C, 0x3B, 0x2B, 0x1C, 0x10, 0x08, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12.5dB*/ + {0x6C, 0x69, 0x5F, 0x50, 0x3F, 0x2D, 0x1E, 0x11, 0x08, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12dB*/ + {0x73, 0x6F, 0x64, 0x55, 0x42, 0x30, 0x1F, 0x12, 0x08, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11.5dB*/ + {0x79, 0x76, 0x6A, 0x5A, 0x46, 0x33, 0x21, 0x13, 0x09, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11dB*/ + {0x81, 0x7C, 0x71, 0x5F, 0x4A, 0x36, 0x23, 0x14, 0x0A, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10.5dB*/ + {0x88, 0x84, 0x77, 0x65, 0x4F, 0x39, 0x25, 0x15, 0x0A, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10dB*/ + {0x90, 0x8C, 0x7E, 0x6B, 0x54, 0x3C, 0x27, 0x17, 0x0B, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9.5dB*/ + {0x99, 0x94, 0x86, 0x71, 0x58, 0x40, 0x2A, 0x18, 0x0B, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9dB*/ + {0xA2, 0x9D, 0x8E, 0x78, 0x5E, 0x43, 0x2C, 0x19, 0x0C, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8.5dB*/ + {0xAC, 0xA6, 0x96, 0x7F, 0x63, 0x47, 0x2F, 0x1B, 0x0D, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8dB*/ + {0xB6, 0xB0, 0x9F, 0x87, 0x69, 0x4C, 0x32, 0x1D, 0x0D, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7.5dB*/ + {0xC1, 0xBA, 0xA8, 0x8F, 0x6F, 0x50, 0x35, 0x1E, 0x0E, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7dB*/ + {0xCC, 0xC5, 0xB2, 0x97, 0x76, 0x55, 0x38, 0x20, 0x0F, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-6.5dB*/ + {0xD8, 0xD1, 0xBD, 0xA0, 0x7D, 0x5A, 0x3B, 0x22, 0x10, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /*-6dB*/ +}; + +u8 cck_swing_table_ch14_88f[CCK_TABLE_SIZE_88F][16] = { + {0x44, 0x42, 0x3C, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-16dB*/ + {0x48, 0x46, 0x3F, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15.5dB*/ + {0x4D, 0x4A, 0x43, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15dB*/ + {0x51, 0x4F, 0x47, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14.5dB*/ + {0x56, 0x53, 0x4B, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14dB*/ + {0x5B, 0x58, 0x50, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13.5dB*/ + {0x60, 0x5D, 0x54, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13dB*/ + {0x66, 0x63, 0x59, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12.5dB*/ + {0x6C, 0x69, 0x5F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12dB*/ + {0x73, 0x6F, 0x64, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11.5dB*/ + {0x79, 0x76, 0x6A, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11dB*/ + {0x81, 0x7C, 0x71, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10.5dB*/ + {0x88, 0x84, 0x77, 0x4F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10dB*/ + {0x90, 0x8C, 0x7E, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9.5dB*/ + {0x99, 0x94, 0x86, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9dB*/ + {0xA2, 0x9D, 0x8E, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8.5dB*/ + {0xAC, 0xA6, 0x96, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8dB*/ + {0xB6, 0xB0, 0x9F, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7.5dB*/ + {0xC1, 0xBA, 0xA8, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7dB*/ + {0xCC, 0xC5, 0xB2, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-6.5dB*/ + {0xD8, 0xD1, 0xBD, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /*-6dB*/ +}; + +u8 cck_swing_table_ch1_ch13_new[CCK_TABLE_SIZE][8] = { + {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, /* 0, -16.0dB*/ + {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 1, -15.5dB*/ + {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 2, -15.0dB*/ + {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 3, -14.5dB*/ + {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 4, -14.0dB*/ + {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 5, -13.5dB*/ + {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 6, -13.0dB*/ + {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 7, -12.5dB*/ + {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 8, -12.0dB*/ + {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 9, -11.5dB*/ + {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 10, -11.0dB*/ + {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 11, -10.5dB*/ + {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 12, -10.0dB*/ + {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 13, -9.5dB*/ + {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 15, -8.5dB*/ + {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 17, -7.5dB*/ + {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 19, -6.5dB*/ + {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 21, -5.5dB*/ + {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 23, -4.5dB*/ + {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 25, -3.5dB*/ + {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 26, -3.0dB*/ + {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 27, -2.5dB*/ + {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 29, -1.5dB*/ + {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 30, -1.0dB*/ + {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 31, -0.5dB*/ + {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04} /* 32, +0dB*/ +}; + +u8 cck_swing_table_ch14_new[CCK_TABLE_SIZE][8] = { + {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, /* 0, -16.0dB*/ + {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 1, -15.5dB*/ + {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 2, -15.0dB*/ + {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 3, -14.5dB*/ + {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 4, -14.0dB*/ + {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /*5, -13.5dB*/ + {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 6, -13.0dB*/ + {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 7, -12.5dB*/ + {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 8, -12.0dB*/ + {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 9, -11.5dB*/ + {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 10, -11.0dB*/ + {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /*11, -10.5dB*/ + {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 12, -10.0dB*/ + {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 13, -9.5dB*/ + {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /*14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 15, -8.5dB*/ + {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 17, -7.5dB*/ + {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 19, -6.5dB */ + {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 21, -5.5dB*/ + {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /*23, -4.5dB*/ + {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 25, -3.5dB */ + {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 26, -3.0dB */ + {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /*27, -2.5dB*/ + {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /*29, -1.5dB*/ + {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 30, -1.0dB */ + {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 31, -0.5dB */ + {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00} /* 32, +0dB */ +}; + +u32 cck_swing_table_ch1_ch14_8723d[CCK_TABLE_SIZE_8723D] = { + 0x0CD, /*0 , -20dB*/ + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, + 0x287, + 0x2AE, + 0x2D6, + 0x301, + 0x32F, + 0x35F, + 0x392, + 0x3C9, + 0x402, + 0x43F, + 0x47F, + 0x4C3, + 0x50C, + 0x558, + 0x5A9, + 0x5FF, + 0x65A, + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + +/*@JJ ADD 20161014 */ +u32 cck_swing_table_ch1_ch14_8710b[CCK_TABLE_SIZE_8710B] = { + 0x0CD, /*0 , -20dB*/ + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, + 0x287, + 0x2AE, + 0x2D6, + 0x301, + 0x32F, + 0x35F, + 0x392, + 0x3C9, + 0x402, + 0x43F, + 0x47F, + 0x4C3, + 0x50C, + 0x558, + 0x5A9, + 0x5FF, + 0x65A, + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + +/*@Winnita ADD 20171116 PathA 0xAB4[10:0],PathB 0xAB4[21:11]*/ +u32 cck_swing_table_ch1_ch14_8192f[CCK_TABLE_SIZE_8192F] = { + 0x0CD, /*0 , -20dB*/ + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, /*19*/ + 0x287, /*20*/ + 0x2AE, /*21*/ + 0x2D6, /*22*/ + 0x301, /*23*/ + 0x32F, /*24*/ + 0x35F, /*25*/ + 0x392, /*26*/ + 0x3C9, /*27*/ + 0x402, /*28*/ + 0x43F, /*29*/ + 0x47F, /*30*/ + 0x4C3, /*31*/ + 0x50C, /*32*/ + 0x558, /*33*/ + 0x5A9, /*34*/ + 0x5FF, /*35*/ + 0x65A, /*36*/ + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + +u32 tx_scaling_table_jaguar[TXSCALE_TABLE_SIZE] = { + 0x081, /* 0, -12.0dB*/ + 0x088, /* 1, -11.5dB*/ + 0x090, /* 2, -11.0dB*/ + 0x099, /* 3, -10.5dB*/ + 0x0A2, /* 4, -10.0dB*/ + 0x0AC, /* 5, -9.5dB*/ + 0x0B6, /* 6, -9.0dB*/ + 0x0C0, /*7, -8.5dB*/ + 0x0CC, /* 8, -8.0dB*/ + 0x0D8, /* 9, -7.5dB*/ + 0x0E5, /* 10, -7.0dB*/ + 0x0F2, /* 11, -6.5dB*/ + 0x101, /* 12, -6.0dB*/ + 0x110, /* 13, -5.5dB*/ + 0x120, /* 14, -5.0dB*/ + 0x131, /* 15, -4.5dB*/ + 0x143, /* 16, -4.0dB*/ + 0x156, /* 17, -3.5dB*/ + 0x16A, /* 18, -3.0dB*/ + 0x180, /* 19, -2.5dB*/ + 0x197, /* 20, -2.0dB*/ + 0x1AF, /* 21, -1.5dB*/ + 0x1C8, /* 22, -1.0dB*/ + 0x1E3, /* 23, -0.5dB*/ + 0x200, /* 24, +0 dB*/ + 0x21E, /* 25, +0.5dB*/ + 0x23E, /* 26, +1.0dB*/ + 0x261, /* 27, +1.5dB*/ + 0x285, /* 28, +2.0dB*/ + 0x2AB, /* 29, +2.5dB*/ + 0x2D3, /*30, +3.0dB*/ + 0x2FE, /* 31, +3.5dB*/ + 0x32B, /* 32, +4.0dB*/ + 0x35C, /* 33, +4.5dB*/ + 0x38E, /* 34, +5.0dB*/ + 0x3C4, /* 35, +5.5dB*/ + 0x3FE /* 36, +6.0dB */ +}; + +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) && defined(DM_ODM_CE_MAC80211) +#else +u8 delta_swing_table_idx_2ga_p_8188e[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, + 7, 7, 8, 8, 8, 9, 9, 9, 9, 9}; +u8 delta_swing_table_idx_2ga_n_8188e[] = {0, 0, 0, 2, 2, 3, 3, 4, 4, 4, + 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, + 8, 9, 9, 10, 10, 10, 11, 11, 11, 11}; +#endif + +void odm_txpowertracking_init(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + odm_txpowertracking_thermal_meter_init(dm); +} + +u8 get_swing_index(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; +#if ((RTL8812A_SUPPORT == 1) || (RTL8821A_SUPPORT == 1)) + void *adapter = dm->adapter; + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter); +#endif + u8 i = 0; + u32 bb_swing, table_value; + + if (dm->support_ic_type & + (ODM_RTL8188E | ODM_RTL8723B | ODM_RTL8192E | + ODM_RTL8188F | ODM_RTL8703B | ODM_RTL8723D | + ODM_RTL8710B)) { + + bb_swing = odm_get_bb_reg(dm, R_0xc80, 0xFFC00000); + + for (i = 0; i < OFDM_TABLE_SIZE; i++) { + table_value = ofdm_swing_table_new[i]; + + if (table_value >= 0x100000) + table_value >>= 22; + if (bb_swing == table_value) + break; + } + } else { +#if ((RTL8812A_SUPPORT == 1) || (RTL8821A_SUPPORT == 1)) + bb_swing = + phy_get_tx_bb_swing_8812a(adapter, + hal_data->current_band_type, + RF_PATH_A); +#else + bb_swing = odm_get_bb_reg(dm, R_0xc1c, 0xFFE00000); +#endif + for (i = 0; i < TXSCALE_TABLE_SIZE; i++) { + table_value = tx_scaling_table_jaguar[i]; + + if (bb_swing == table_value) + break; + } + } + + return i; +} + +u8 get_cck_swing_index(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + u8 i = 0; + u32 bb_cck_swing; + + if (dm->support_ic_type & + (ODM_RTL8188E | ODM_RTL8723B | ODM_RTL8192E)) { + bb_cck_swing = odm_read_1byte(dm, 0xa22); + + for (i = 0; i < CCK_TABLE_SIZE; i++) { + if (bb_cck_swing == cck_swing_table_ch1_ch13_new[i][0]) + break; + } + } else if (dm->support_ic_type & ODM_RTL8703B) { + bb_cck_swing = odm_read_1byte(dm, 0xa22); + + for (i = 0; i < CCK_TABLE_SIZE_88F; i++) { + if (bb_cck_swing == cck_swing_table_ch1_ch14_88f[i][0]) + break; + } + } + + return i; +} + +s8 +get_txagc_default_index( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + s8 tmp; + + if (dm->support_ic_type == ODM_RTL8814B) { + tmp = (s8)(odm_get_bb_reg(dm, R_0x18a0, 0x7f) & 0xff); + if (tmp & BIT(6)) + tmp = tmp | 0x80; + return tmp; + } else + return 0; +} + +void odm_txpowertracking_thermal_meter_init(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + struct _hal_rf_ *rf = &dm->rf_table; + struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data; + + u8 swing_idx = get_swing_index(dm); + u8 cckswing_idx = get_cck_swing_index(dm); + u8 p = 0; + + cali_info->is_txpowertracking = true; + cali_info->tx_powercount = 0; + cali_info->is_txpowertracking_init = false; + + if (!(*dm->mp_mode)) + cali_info->txpowertrack_control = true; + else + cali_info->txpowertrack_control = false; + + if (!(*dm->mp_mode)) + cali_info->txpowertrack_control = true; + + RF_DBG(dm, DBG_RF_IQK, "dm txpowertrack_control = %d\n", + cali_info->txpowertrack_control); +#if 0 + /* dm->rf_calibrate_info.txpowertrack_control = true; */ +#endif + cali_info->thermal_value = rf->eeprom_thermal; + cali_info->thermal_value_iqk = rf->eeprom_thermal; + cali_info->thermal_value_lck = rf->eeprom_thermal; + +#if (RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1 || RTL8723F_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8822C || + dm->support_ic_type == ODM_RTL8723F) { + cali_info->thermal_value_path[RF_PATH_A] = tssi->thermal[RF_PATH_A]; + cali_info->thermal_value_path[RF_PATH_B] = tssi->thermal[RF_PATH_B]; + cali_info->thermal_value_iqk = tssi->thermal[RF_PATH_A]; + cali_info->thermal_value_lck = tssi->thermal[RF_PATH_A]; + } + + if (dm->support_ic_type == ODM_RTL8814B) { + cali_info->thermal_value_path[RF_PATH_A] = tssi->thermal[RF_PATH_A]; + cali_info->thermal_value_path[RF_PATH_B] = tssi->thermal[RF_PATH_B]; + cali_info->thermal_value_path[RF_PATH_C] = tssi->thermal[RF_PATH_C]; + cali_info->thermal_value_path[RF_PATH_D] = tssi->thermal[RF_PATH_D]; + cali_info->thermal_value_iqk = tssi->thermal[RF_PATH_A]; + cali_info->thermal_value_lck = tssi->thermal[RF_PATH_A]; + } +#endif + + if (!cali_info->default_bb_swing_index_flag) { + if (dm->support_ic_type & + (ODM_RTL8188E | ODM_RTL8723B | ODM_RTL8192E | + ODM_RTL8703B | ODM_RTL8821)) { + if (swing_idx >= OFDM_TABLE_SIZE) + cali_info->default_ofdm_index = 30; + else + cali_info->default_ofdm_index = swing_idx; + + if (cckswing_idx >= CCK_TABLE_SIZE) + cali_info->default_cck_index = 20; + else + cali_info->default_cck_index = cckswing_idx; + /*@add by Mingzhi.Guo 2015-03-23*/ + } else if (dm->support_ic_type == ODM_RTL8188F) { + cali_info->default_ofdm_index = 28; /*OFDM: -1dB*/ + cali_info->default_cck_index = 20; /*CCK:-6dB*/ + /*@add by zhaohe 2015-10-27*/ + } else if (dm->support_ic_type == ODM_RTL8723D) { + cali_info->default_ofdm_index = 28; /*OFDM: -1dB*/ + cali_info->default_cck_index = 28; /*CCK: -6dB*/ + /*@JJ ADD 20161014 */ + } else if (dm->support_ic_type == ODM_RTL8710B) { + cali_info->default_ofdm_index = 28; /*OFDM: -1dB*/ + cali_info->default_cck_index = 28; /*CCK: -6dB*/ + } else if (dm->support_ic_type == ODM_RTL8192F) { + cali_info->default_ofdm_index = 30;/*OFDM: 0dB*/ + cali_info->default_cck_index = 28; /*CCK: -6dB*/ + } else { + if (swing_idx >= TXSCALE_TABLE_SIZE) + cali_info->default_ofdm_index = 24; + else + cali_info->default_ofdm_index = swing_idx; + + cali_info->default_txagc_index = get_txagc_default_index(dm); + + cali_info->default_cck_index = 24; + } + cali_info->default_bb_swing_index_flag = true; + } + + cali_info->bb_swing_idx_cck_base = cali_info->default_cck_index; + cali_info->CCK_index = cali_info->default_cck_index; + + for (p = RF_PATH_A; p < MAX_RF_PATH; ++p) { + cali_info->bb_swing_idx_ofdm_base[p] = + cali_info->default_ofdm_index; + cali_info->OFDM_index[p] = cali_info->default_ofdm_index; + cali_info->delta_power_index[p] = 0; + cali_info->delta_power_index_last[p] = 0; + cali_info->power_index_offset[p] = 0; + } + cali_info->modify_tx_agc_value_ofdm = 0; + cali_info->modify_tx_agc_value_cck = 0; + cali_info->tm_trigger = 0; +} + +void odm_txpowertracking_check(void *dm_void) +{ + /*@2011/09/29 MH In HW integration first stage + * we provide 4 different handle to operate at the same time. + * In the stage2/3, we need to prive universal interface and merge all + * HW dynamic mechanism. + */ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + switch (dm->support_platform) { + case ODM_WIN: + odm_txpowertracking_check_mp(dm); + break; + + case ODM_CE: + odm_txpowertracking_check_ce(dm); + break; + + case ODM_AP: + odm_txpowertracking_check_ap(dm); + break; + + default: + break; + } +} + +void odm_txpowertracking_check_ce(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data; + +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) + if (!(rf->rf_supportability & HAL_RF_TX_PWR_TRACK)) + return; +#if (RTL8723F_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8723F) { + /*RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "[RF][TSSI] Pwrtrack return!\n");*/ + return; + } +#endif + + if ((rf->power_track_type & 0xf0) >> 4 != 0) { + if (dm->support_ic_type & ODM_RTL8822C) { + /*halrf_tssi_cck(dm);*/ + /*halrf_thermal_cck(dm);*/ + return; + } + } + + if (!dm->rf_calibrate_info.tm_trigger) { + if (dm->support_ic_type & + (ODM_RTL8188E | ODM_RTL8188F | ODM_RTL8192E | + ODM_RTL8723B | ODM_RTL8812 | ODM_RTL8821 | + ODM_RTL8814A | ODM_RTL8703B | ODM_RTL8723D | + ODM_RTL8822B | ODM_RTL8821C | ODM_RTL8710B | + ODM_RTL8192F)) + odm_set_rf_reg(dm, RF_PATH_A, RF_T_METER_NEW, + (BIT(17) | BIT(16)), 0x03); + else if (dm->support_ic_type & ODM_RTL8822C) { + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x01); + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x00); + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x01); + + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x01); + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x00); + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x01); + } else if (dm->support_ic_type & ODM_RTL8814B) { + odm_set_rf_reg(dm, RF_PATH_A, 0x42, BIT(17), 0x1); + odm_set_rf_reg(dm, RF_PATH_B, 0x42, BIT(17), 0x1); + odm_set_rf_reg(dm, RF_PATH_C, 0x42, BIT(17), 0x1); + odm_set_rf_reg(dm, RF_PATH_D, 0x42, BIT(17), 0x1); + } else + odm_set_rf_reg(dm, RF_PATH_A, RF_T_METER_OLD, + RFREGOFFSETMASK, 0x60); + +#if (RTL8814B_SUPPORT == 1) + if (dm->support_ic_type & ODM_RTL8814B) { + ODM_delay_us(300); + odm_txpowertracking_new_callback_thermal_meter(dm); + tssi->thermal_trigger = 1; + } +#endif + dm->rf_calibrate_info.tm_trigger = 1; + return; + } + + if (dm->support_ic_type & (ODM_RTL8822C | ODM_RTL8814B)) { +#if (RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1) + odm_txpowertracking_new_callback_thermal_meter(dm); + if (dm->support_ic_type & ODM_RTL8814B) + tssi->thermal_trigger = 0; +#endif + } else + odm_txpowertracking_callback_thermal_meter(dm); + dm->rf_calibrate_info.tm_trigger = 0; +#endif +} + +void +odm_txpowertracking_direct_ce(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) + + if (!(rf->rf_supportability & HAL_RF_TX_PWR_TRACK)) + return; + if (dm->support_ic_type & ODM_RTL8723F) { +#if (RTL8723F_SUPPORT == 1) + /*RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "[RF]===>%s 8723F TSSI, return!\n", __func__);*/ + return; +#endif + } + + if (dm->support_ic_type & ODM_RTL8822C) { + /*halrf_tssi_cck(dm);*/ + /*halrf_thermal_cck(dm);*/ + return; + } + + if (dm->support_ic_type & + (ODM_RTL8188E | ODM_RTL8188F | ODM_RTL8192E | + ODM_RTL8723B | ODM_RTL8812 | ODM_RTL8821 | + ODM_RTL8814A | ODM_RTL8703B | ODM_RTL8723D | + ODM_RTL8822B | ODM_RTL8821C | ODM_RTL8710B | + ODM_RTL8192F | ODM_RTL8814B)) + odm_set_rf_reg(dm, RF_PATH_A, RF_T_METER_NEW, (BIT(17) | BIT(16)), 0x03); + else if (dm->support_ic_type & ODM_RTL8822C) { + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x01); + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x00); + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x01); + + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x01); + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x00); + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x01); + } else + odm_set_rf_reg(dm, RF_PATH_A, RF_T_METER_OLD, RFREGOFFSETMASK, 0x60); + + if (dm->support_ic_type & (ODM_RTL8822C | ODM_RTL8814B)) { +#if (RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1) + odm_txpowertracking_new_callback_thermal_meter(dm); +#endif + } else + odm_txpowertracking_callback_thermal_meter(dm); +#endif + +} + + +void odm_txpowertracking_check_mp(void *dm_void) +{ +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + struct dm_struct *dm = (struct dm_struct *)dm_void; + void *adapter = dm->adapter; + + if (odm_check_power_status(adapter) == false) { + RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD, + ("check_pow_status, return false\n")); + return; + } + + odm_txpowertracking_thermal_meter_check(adapter); +#endif +} + +void odm_txpowertracking_check_ap(void *dm_void) +{ +#if (DM_ODM_SUPPORT_TYPE == ODM_AP) + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct rtl8192cd_priv *priv = dm->priv; + + return; + +#endif +} diff --git a/hal/phydm/halrf/halrf_powertracking_ce.h b/hal/phydm/halrf/halrf_powertracking_ce.h new file mode 100644 index 0000000..3fec1ab --- /dev/null +++ b/hal/phydm/halrf/halrf_powertracking_ce.h @@ -0,0 +1,331 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALRF_POWERTRACKING_H__ +#define __HALRF_POWERTRACKING_H__ + +#define DPK_DELTA_MAPPING_NUM 13 +#define index_mapping_HP_NUM 15 +#define OFDM_TABLE_SIZE 43 +#define CCK_TABLE_SIZE 33 +#define CCK_TABLE_SIZE_88F 21 +#define TXSCALE_TABLE_SIZE 37 +#define CCK_TABLE_SIZE_8723D 41 +/*@JJ ADD 20161014 */ +#define CCK_TABLE_SIZE_8710B 41 +#define CCK_TABLE_SIZE_8192F 41 + +#define TXPWR_TRACK_TABLE_SIZE 30 +#define DELTA_SWINGIDX_SIZE 30 +#define DELTA_SWINTSSI_SIZE 61 +#define BAND_NUM 4 + +#define AVG_THERMAL_NUM 8 +#define IQK_MAC_REG_NUM 4 +#define IQK_ADDA_REG_NUM 16 +#define IQK_BB_REG_NUM_MAX 10 + +#define IQK_BB_REG_NUM 9 + +#define iqk_matrix_reg_num 8 +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) && defined(DM_ODM_CE_MAC80211) +#else +/* Channels_2_4G_NUM + Channels_5G_20M_NUM + Channels_5G */ +#define IQK_MATRIX_SETTINGS_NUM (14 + 24 + 21) +#endif + +extern u32 ofdm_swing_table[OFDM_TABLE_SIZE]; +extern u8 cck_swing_table_ch1_ch13[CCK_TABLE_SIZE][8]; +extern u8 cck_swing_table_ch14[CCK_TABLE_SIZE][8]; + +extern u32 ofdm_swing_table_new[OFDM_TABLE_SIZE]; +extern u8 cck_swing_table_ch1_ch13_new[CCK_TABLE_SIZE][8]; +extern u8 cck_swing_table_ch14_new[CCK_TABLE_SIZE][8]; +extern u8 cck_swing_table_ch1_ch14_88f[CCK_TABLE_SIZE_88F][16]; +extern u8 cck_swing_table_ch1_ch13_88f[CCK_TABLE_SIZE_88F][16]; +extern u8 cck_swing_table_ch14_88f[CCK_TABLE_SIZE_88F][16]; +extern u32 cck_swing_table_ch1_ch14_8723d[CCK_TABLE_SIZE_8723D]; +/*@JJ ADD 20161014 */ +extern u32 cck_swing_table_ch1_ch14_8710b[CCK_TABLE_SIZE_8710B]; +extern u32 cck_swing_table_ch1_ch14_8192f[CCK_TABLE_SIZE_8192F]; + +extern u32 tx_scaling_table_jaguar[TXSCALE_TABLE_SIZE]; + +/*@<20121018, Kordan> In case fail to read TxPowerTrack.txt */ +/* we use the table of 88E as the default table. */ +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) && defined(DM_ODM_CE_MAC80211) +#else +extern u8 delta_swing_table_idx_2ga_p_8188e[]; +extern u8 delta_swing_table_idx_2ga_n_8188e[]; +#endif + +#define dm_check_txpowertracking odm_txpowertracking_check + +struct iqk_matrix_regs_setting { + boolean is_iqk_done; + s32 value[3][iqk_matrix_reg_num]; + boolean is_bw_iqk_result_saved[3]; +}; + +struct dm_rf_calibration_struct { + /* for tx power tracking */ + + u32 rega24; /* for TempCCK */ + s32 rege94; + s32 rege9c; + s32 regeb4; + s32 regebc; + + u8 tx_powercount; + boolean is_txpowertracking_init; + boolean is_txpowertracking; + /* for mp mode, turn off txpwrtracking as default */ + u8 txpowertrack_control; + u8 tm_trigger; + u8 internal_pa_5g[2]; /* pathA / pathB */ + + /* thermal_meter, index 0 for RFIC0, and 1 for RFIC1 */ + u8 thermal_meter[2]; + u8 thermal_value; + u8 thermal_value_path[MAX_RF_PATH]; + u8 thermal_value_lck; + u8 thermal_value_iqk; + s8 thermal_value_delta; /* delta of thermal_value and efuse thermal */ + u8 thermal_value_dpk; + u8 thermal_value_avg[AVG_THERMAL_NUM]; + u8 thermal_value_avg_path[MAX_RF_PATH][AVG_THERMAL_NUM]; + u8 thermal_value_avg_index; + u8 thermal_value_avg_index_path[MAX_RF_PATH]; + u8 thermal_value_rx_gain; + u8 thermal_value_crystal; + u8 thermal_value_dpk_store; + u8 thermal_value_dpk_track; + boolean txpowertracking_in_progress; + + boolean is_reloadtxpowerindex; + u8 is_rf_pi_enable; + u32 txpowertracking_callback_cnt; /* cosa add for debug */ + + /*@---------------------- Tx power Tracking ---------------------- */ + u8 is_cck_in_ch14; + u8 CCK_index; + u8 OFDM_index[MAX_RF_PATH]; + s8 power_index_offset[MAX_RF_PATH]; + s8 delta_power_index[MAX_RF_PATH]; + s8 delta_power_index_last[MAX_RF_PATH]; + boolean is_tx_power_changed; + s8 xtal_offset; + s8 xtal_offset_last; + u8 xtal_offset_eanble; + + struct iqk_matrix_regs_setting + iqk_matrix_reg_setting[IQK_MATRIX_SETTINGS_NUM]; + u8 delta_lck; + s8 bb_swing_diff_2g, bb_swing_diff_5g; /* Unit: dB */ + u8 delta_swing_table_idx_2g_cck_a_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_a_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_b_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_b_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_c_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_c_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_d_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_d_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gb_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gb_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gc_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gc_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gd_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gd_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5ga_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5ga_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gb_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gb_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gc_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gc_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gd_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gd_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_tssi_table_2g_cck_a[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_b[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_c[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_d[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2ga[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gb[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gc[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gd[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5ga[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gb[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gc[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gd[BAND_NUM][DELTA_SWINTSSI_SIZE]; + s8 delta_swing_table_xtal_p[DELTA_SWINGIDX_SIZE]; + s8 delta_swing_table_xtal_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_p_8188e[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_n_8188e[DELTA_SWINGIDX_SIZE]; + + u8 bb_swing_idx_ofdm[MAX_RF_PATH]; + u8 bb_swing_idx_ofdm_current; +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + u8 bb_swing_idx_ofdm_base[MAX_RF_PATH]; +#else + u8 bb_swing_idx_ofdm_base; +#endif + boolean default_bb_swing_index_flag; + boolean bb_swing_flag_ofdm; + u8 bb_swing_idx_cck; + u8 bb_swing_idx_cck_current; + u8 bb_swing_idx_cck_base; + u8 default_ofdm_index; + u8 default_cck_index; + s8 default_txagc_index; + boolean bb_swing_flag_cck; + + s8 absolute_ofdm_swing_idx[MAX_RF_PATH]; + s8 remnant_ofdm_swing_idx[MAX_RF_PATH]; + s8 absolute_cck_swing_idx[MAX_RF_PATH]; + s8 remnant_cck_swing_idx; + s8 modify_tx_agc_value; /*Remnat compensate value at tx_agc */ + boolean modify_tx_agc_flag_path_a; + boolean modify_tx_agc_flag_path_b; + boolean modify_tx_agc_flag_path_c; + boolean modify_tx_agc_flag_path_d; + boolean modify_tx_agc_flag_path_a_cck; + boolean modify_tx_agc_flag_path_b_cck; + + s8 kfree_offset[MAX_RF_PATH]; + + /*@----------------------------------------------------------------- */ + + /* for IQK */ + u32 regc04; + u32 reg874; + u32 regc08; + u32 regb68; + u32 regb6c; + u32 reg870; + u32 reg860; + u32 reg864; + + boolean is_iqk_initialized; + boolean is_lck_in_progress; + boolean is_antenna_detected; + boolean is_need_iqk; + boolean is_iqk_in_progress; + boolean is_iqk_pa_off; + u8 delta_iqk; + u32 ADDA_backup[IQK_ADDA_REG_NUM]; + u32 IQK_MAC_backup[IQK_MAC_REG_NUM]; + u32 IQK_BB_backup_recover[9]; + u32 IQK_BB_backup[IQK_BB_REG_NUM]; + /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}} */ + u32 tx_iqc_8723b[2][3][2]; + /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}} */ + u32 rx_iqc_8723b[2][2][2]; + /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}} */ + u32 tx_iqc_8703b[3][2]; + /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}} */ + u32 rx_iqc_8703b[2][2]; + /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}} */ + u32 tx_iqc_8723d[2][3][2]; + /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}} */ + u32 rx_iqc_8723d[2][2][2]; + /* JJ ADD 20161014 */ + /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}} */ + u32 tx_iqc_8710b[2][3][2]; + /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}} */ + u32 rx_iqc_8710b[2][2][2]; + + u8 iqk_step; + u8 kcount; + u8 retry_count[4][2]; /* [4]: path ABCD, [2] TXK, RXK */ + boolean is_mp_mode; + + /*@ IQK time measurement */ + u64 iqk_start_time; + u64 iqk_progressing_time; + u64 iqk_total_progressing_time; + u64 lck_progressing_time; + + u32 lok_result; + + /* for APK */ + u32 ap_koutput[2][2]; /* path A/B; output1_1a/output1_2a */ + u8 is_ap_kdone; + u8 is_apk_thermal_meter_ignore; + + /* DPK */ + boolean is_dpk_fail; + u8 is_dp_done; + u8 is_dp_path_aok; + u8 is_dp_path_bok; + + u32 tx_lok[2]; + u32 dpk_tx_agc; + s32 dpk_gain; + u32 dpk_thermal[4]; + s8 modify_tx_agc_value_ofdm; + s8 modify_tx_agc_value_cck; + + /*@Add by Yuchen for Kfree Phydm*/ + u8 reg_rf_kfree_enable; /*for registry*/ + u8 rf_kfree_enable; /*for efuse enable check*/ +}; + +void odm_txpowertracking_check(void *dm_void); + +void odm_txpowertracking_init(void *dm_void); + +void odm_txpowertracking_check_ap(void *dm_void); + +void odm_txpowertracking_thermal_meter_init(void *dm_void); + +void odm_txpowertracking_init(void *dm_void); + +void odm_txpowertracking_check_mp(void *dm_void); + +void odm_txpowertracking_check_ce(void *dm_void); + +void odm_txpowertracking_direct_ce(void *dm_void); + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN)) + +void odm_txpowertracking_callback_thermal_meter92c( + void *adapter); + +void odm_txpowertracking_callback_rx_gain_thermal_meter92d( + void *adapter); + +void odm_txpowertracking_callback_thermal_meter92d( + void *adapter); + +void odm_txpowertracking_direct_call92c( + void *adapter); + +void odm_txpowertracking_thermal_meter_check( + void *adapter); + +#endif + +#endif /*__HALRF_POWER_TRACKING_H__*/ diff --git a/hal/phydm/halrf/halrf_powertracking_iot.c b/hal/phydm/halrf/halrf_powertracking_iot.c new file mode 100644 index 0000000..494fdec --- /dev/null +++ b/hal/phydm/halrf/halrf_powertracking_iot.c @@ -0,0 +1,1004 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +/*============================================================ */ +/* include files */ +/*============================================================ */ +#include "mp_precomp.h" +#include "phydm_precomp.h" + +/* ************************************************************ + * Global var + * ************************************************************ + */ + +const u32 ofdm_swing_table[OFDM_TABLE_SIZE] = { + 0x7f8001fe, /* 0, +6.0dB */ + 0x788001e2, /* 1, +5.5dB */ + 0x71c001c7, /* 2, +5.0dB*/ + 0x6b8001ae, /* 3, +4.5dB*/ + 0x65400195, /* 4, +4.0dB*/ + 0x5fc0017f, /* 5, +3.5dB*/ + 0x5a400169, /* 6, +3.0dB*/ + 0x55400155, /* 7, +2.5dB*/ + 0x50800142, /* 8, +2.0dB*/ + 0x4c000130, /* 9, +1.5dB*/ + 0x47c0011f, /* 10, +1.0dB*/ + 0x43c0010f, /* 11, +0.5dB*/ + 0x40000100, /* 12, +0dB*/ + 0x3c8000f2, /* 13, -0.5dB*/ + 0x390000e4, /* 14, -1.0dB*/ + 0x35c000d7, /* 15, -1.5dB*/ + 0x32c000cb, /* 16, -2.0dB*/ + 0x300000c0, /* 17, -2.5dB*/ + 0x2d4000b5, /* 18, -3.0dB*/ + 0x2ac000ab, /* 19, -3.5dB*/ + 0x288000a2, /* 20, -4.0dB*/ + 0x26000098, /* 21, -4.5dB*/ + 0x24000090, /* 22, -5.0dB*/ + 0x22000088, /* 23, -5.5dB*/ + 0x20000080, /* 24, -6.0dB*/ + 0x1e400079, /* 25, -6.5dB*/ + 0x1c800072, /* 26, -7.0dB*/ + 0x1b00006c, /* 27. -7.5dB*/ + 0x19800066, /* 28, -8.0dB*/ + 0x18000060, /* 29, -8.5dB*/ + 0x16c0005b, /* 30, -9.0dB*/ + 0x15800056, /* 31, -9.5dB*/ + 0x14400051, /* 32, -10.0dB*/ + 0x1300004c, /* 33, -10.5dB*/ + 0x12000048, /* 34, -11.0dB*/ + 0x11000044, /* 35, -11.5dB*/ + 0x10000040, /* 36, -12.0dB*/ +}; + +const u8 cck_swing_table_ch1_ch13[CCK_TABLE_SIZE][8] = { + {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, /* 0, +0dB */ + {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 1, -0.5dB */ + {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 2, -1.0dB*/ + {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 3, -1.5dB*/ + {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 4, -2.0dB */ + {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 5, -2.5dB*/ + {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 6, -3.0dB*/ + {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 7, -3.5dB*/ + {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 8, -4.0dB */ + {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 9, -4.5dB*/ + {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 10, -5.0dB */ + {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 11, -5.5dB*/ + {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 12, -6.0dB <== default */ + {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 13, -6.5dB*/ + {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 14, -7.0dB */ + {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 15, -7.5dB*/ + {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */ + {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 17, -8.5dB*/ + {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 18, -9.0dB */ + {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 19, -9.5dB*/ + {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 20, -10.0dB*/ + {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 21, -10.5dB*/ + {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 22, -11.0dB*/ + {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 23, -11.5dB*/ + {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 24, -12.0dB*/ + {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 25, -12.5dB*/ + {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 26, -13.0dB*/ + {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 27, -13.5dB*/ + {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 28, -14.0dB*/ + {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 29, -14.5dB*/ + {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 30, -15.0dB*/ + {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 31, -15.5dB*/ + {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01} /* 32, -16.0dB*/ +}; + +const u8 cck_swing_table_ch14[CCK_TABLE_SIZE][8] = { + {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, /* 0, +0dB */ + {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 1, -0.5dB */ + {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 2, -1.0dB */ + {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 3, -1.5dB*/ + {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 4, -2.0dB */ + {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 5, -2.5dB*/ + {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 6, -3.0dB */ + {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 7, -3.5dB */ + {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 8, -4.0dB */ + {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 9, -4.5dB*/ + {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 10, -5.0dB */ + {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 11, -5.5dB*/ + {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 12, -6.0dB <== default*/ + {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 13, -6.5dB */ + {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 14, -7.0dB */ + {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 15, -7.5dB*/ + {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */ + {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 17, -8.5dB*/ + {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 18, -9.0dB */ + {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 19, -9.5dB*/ + {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 20, -10.0dB*/ + {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 21, -10.5dB*/ + {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 22, -11.0dB*/ + {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 23, -11.5dB*/ + {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 24, -12.0dB*/ + {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 25, -12.5dB*/ + {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 26, -13.0dB*/ + {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 27, -13.5dB*/ + {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 28, -14.0dB*/ + {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 29, -14.5dB*/ + {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 30, -15.0dB*/ + {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 31, -15.5dB*/ + {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00} /* 32, -16.0dB*/ +}; + +const u32 ofdm_swing_table_new[OFDM_TABLE_SIZE] = { + 0x0b40002d, /* 0, -15.0dB */ + 0x0c000030, /* 1, -14.5dB*/ + 0x0cc00033, /* 2, -14.0dB*/ + 0x0d800036, /* 3, -13.5dB*/ + 0x0e400039, /* 4, -13.0dB */ + 0x0f00003c, /* 5, -12.5dB*/ + 0x10000040, /* 6, -12.0dB*/ + 0x11000044, /* 7, -11.5dB*/ + 0x12000048, /* 8, -11.0dB*/ + 0x1300004c, /* 9, -10.5dB*/ + 0x14400051, /* 10, -10.0dB*/ + 0x15800056, /* 11, -9.5dB*/ + 0x16c0005b, /* 12, -9.0dB*/ + 0x18000060, /* 13, -8.5dB*/ + 0x19800066, /* 14, -8.0dB*/ + 0x1b00006c, /* 15, -7.5dB*/ + 0x1c800072, /* 16, -7.0dB*/ + 0x1e400079, /* 17, -6.5dB*/ + 0x20000080, /* 18, -6.0dB*/ + 0x22000088, /* 19, -5.5dB*/ + 0x24000090, /* 20, -5.0dB*/ + 0x26000098, /* 21, -4.5dB*/ + 0x288000a2, /* 22, -4.0dB*/ + 0x2ac000ab, /* 23, -3.5dB*/ + 0x2d4000b5, /* 24, -3.0dB*/ + 0x300000c0, /* 25, -2.5dB*/ + 0x32c000cb, /* 26, -2.0dB*/ + 0x35c000d7, /* 27, -1.5dB*/ + 0x390000e4, /* 28, -1.0dB*/ + 0x3c8000f2, /* 29, -0.5dB*/ + 0x40000100, /* 30, +0dB*/ + 0x43c0010f, /* 31, +0.5dB*/ + 0x47c0011f, /* 32, +1.0dB*/ + 0x4c000130, /* 33, +1.5dB*/ + 0x50800142, /* 34, +2.0dB*/ + 0x55400155, /* 35, +2.5dB*/ + 0x5a400169, /* 36, +3.0dB*/ + 0x5fc0017f, /* 37, +3.5dB*/ + 0x65400195, /* 38, +4.0dB*/ + 0x6b8001ae, /* 39, +4.5dB*/ + 0x71c001c7, /* 40, +5.0dB*/ + 0x788001e2, /* 41, +5.5dB*/ + 0x7f8001fe /* 42, +6.0dB*/ +}; + +const u8 cck_swing_table_ch1_ch14_88f[CCK_TABLE_SIZE_88F][16] = { + {0x44, 0x42, 0x3C, 0x33, 0x28, 0x1C, 0x13, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-16dB*/ + {0x48, 0x46, 0x3F, 0x36, 0x2A, 0x1E, 0x14, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15.5dB*/ + {0x4D, 0x4A, 0x43, 0x39, 0x2C, 0x20, 0x15, 0x0C, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15dB*/ + {0x51, 0x4F, 0x47, 0x3C, 0x2F, 0x22, 0x16, 0x0D, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14.5dB*/ + {0x56, 0x53, 0x4B, 0x40, 0x32, 0x24, 0x17, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14dB*/ + {0x5B, 0x58, 0x50, 0x43, 0x35, 0x26, 0x19, 0x0E, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13.5dB*/ + {0x60, 0x5D, 0x54, 0x47, 0x38, 0x28, 0x1A, 0x0F, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13dB*/ + {0x66, 0x63, 0x59, 0x4C, 0x3B, 0x2B, 0x1C, 0x10, 0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12.5dB*/ + {0x6C, 0x69, 0x5F, 0x50, 0x3F, 0x2D, 0x1E, 0x11, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12dB*/ + {0x73, 0x6F, 0x64, 0x55, 0x42, 0x30, 0x1F, 0x12, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11.5dB*/ + {0x79, 0x76, 0x6A, 0x5A, 0x46, 0x33, 0x21, 0x13, 0x09, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11dB*/ + {0x81, 0x7C, 0x71, 0x5F, 0x4A, 0x36, 0x23, 0x14, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10.5dB*/ + {0x88, 0x84, 0x77, 0x65, 0x4F, 0x39, 0x25, 0x15, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10dB*/ + {0x90, 0x8C, 0x7E, 0x6B, 0x54, 0x3C, 0x27, 0x17, 0x0B, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9.5dB*/ + {0x99, 0x94, 0x86, 0x71, 0x58, 0x40, 0x2A, 0x18, 0x0B, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9dB*/ + {0xA2, 0x9D, 0x8E, 0x78, 0x5E, 0x43, 0x2C, 0x19, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8.5dB*/ + {0xAC, 0xA6, 0x96, 0x7F, 0x63, 0x47, 0x2F, 0x1B, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8dB*/ + {0xB6, 0xB0, 0x9F, 0x87, 0x69, 0x4C, 0x32, 0x1D, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7.5dB*/ + {0xC1, 0xBA, 0xA8, 0x8F, 0x6F, 0x50, 0x35, 0x1E, 0x0E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7dB*/ + {0xCC, 0xC5, 0xB2, 0x97, 0x76, 0x55, 0x38, 0x20, 0x0F, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-6.5dB*/ + {0xD8, 0xD1, 0xBD, 0xA0, 0x7D, 0x5A, 0x3B, 0x22, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /*-6dB*/ +}; + +const u8 cck_swing_table_ch1_ch13_88f[CCK_TABLE_SIZE_88F][16] = { + {0x44, 0x42, 0x3C, 0x33, 0x28, 0x1C, 0x13, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-16dB*/ + {0x48, 0x46, 0x3F, 0x36, 0x2A, 0x1E, 0x14, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15.5dB*/ + {0x4D, 0x4A, 0x43, 0x39, 0x2C, 0x20, 0x15, 0x0C, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15dB*/ + {0x51, 0x4F, 0x47, 0x3C, 0x2F, 0x22, 0x16, 0x0D, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14.5dB*/ + {0x56, 0x53, 0x4B, 0x40, 0x32, 0x24, 0x17, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14dB*/ + {0x5B, 0x58, 0x50, 0x43, 0x35, 0x26, 0x19, 0x0E, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13.5dB*/ + {0x60, 0x5D, 0x54, 0x47, 0x38, 0x28, 0x1A, 0x0F, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13dB*/ + {0x66, 0x63, 0x59, 0x4C, 0x3B, 0x2B, 0x1C, 0x10, 0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12.5dB*/ + {0x6C, 0x69, 0x5F, 0x50, 0x3F, 0x2D, 0x1E, 0x11, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12dB*/ + {0x73, 0x6F, 0x64, 0x55, 0x42, 0x30, 0x1F, 0x12, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11.5dB*/ + {0x79, 0x76, 0x6A, 0x5A, 0x46, 0x33, 0x21, 0x13, 0x09, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11dB*/ + {0x81, 0x7C, 0x71, 0x5F, 0x4A, 0x36, 0x23, 0x14, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10.5dB*/ + {0x88, 0x84, 0x77, 0x65, 0x4F, 0x39, 0x25, 0x15, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10dB*/ + {0x90, 0x8C, 0x7E, 0x6B, 0x54, 0x3C, 0x27, 0x17, 0x0B, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9.5dB*/ + {0x99, 0x94, 0x86, 0x71, 0x58, 0x40, 0x2A, 0x18, 0x0B, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9dB*/ + {0xA2, 0x9D, 0x8E, 0x78, 0x5E, 0x43, 0x2C, 0x19, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8.5dB*/ + {0xAC, 0xA6, 0x96, 0x7F, 0x63, 0x47, 0x2F, 0x1B, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8dB*/ + {0xB6, 0xB0, 0x9F, 0x87, 0x69, 0x4C, 0x32, 0x1D, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7.5dB*/ + {0xC1, 0xBA, 0xA8, 0x8F, 0x6F, 0x50, 0x35, 0x1E, 0x0E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7dB*/ + {0xCC, 0xC5, 0xB2, 0x97, 0x76, 0x55, 0x38, 0x20, 0x0F, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-6.5dB*/ + {0xD8, 0xD1, 0xBD, 0xA0, 0x7D, 0x5A, 0x3B, 0x22, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /*-6dB*/ +}; + +const u8 cck_swing_table_ch14_88f[CCK_TABLE_SIZE_88F][16] = { + {0x44, 0x42, 0x3C, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-16dB*/ + {0x48, 0x46, 0x3F, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15.5dB*/ + {0x4D, 0x4A, 0x43, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15dB*/ + {0x51, 0x4F, 0x47, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14.5dB*/ + {0x56, 0x53, 0x4B, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14dB*/ + {0x5B, 0x58, 0x50, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13.5dB*/ + {0x60, 0x5D, 0x54, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13dB*/ + {0x66, 0x63, 0x59, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12.5dB*/ + {0x6C, 0x69, 0x5F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12dB*/ + {0x73, 0x6F, 0x64, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11.5dB*/ + {0x79, 0x76, 0x6A, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11dB*/ + {0x81, 0x7C, 0x71, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10.5dB*/ + {0x88, 0x84, 0x77, 0x4F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10dB*/ + {0x90, 0x8C, 0x7E, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9.5dB*/ + {0x99, 0x94, 0x86, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9dB*/ + {0xA2, 0x9D, 0x8E, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8.5dB*/ + {0xAC, 0xA6, 0x96, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8dB*/ + {0xB6, 0xB0, 0x9F, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7.5dB*/ + {0xC1, 0xBA, 0xA8, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7dB*/ + {0xCC, 0xC5, 0xB2, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-6.5dB*/ + {0xD8, 0xD1, 0xBD, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /*-6dB*/ +}; + +const u8 cck_swing_table_ch1_ch13_new[CCK_TABLE_SIZE][8] = { + {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, /* 0, -16.0dB*/ + {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 1, -15.5dB*/ + {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 2, -15.0dB*/ + {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 3, -14.5dB*/ + {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 4, -14.0dB*/ + {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 5, -13.5dB*/ + {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 6, -13.0dB*/ + {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 7, -12.5dB*/ + {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 8, -12.0dB*/ + {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 9, -11.5dB*/ + {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 10, -11.0dB*/ + {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 11, -10.5dB*/ + {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 12, -10.0dB*/ + {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 13, -9.5dB*/ + {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 15, -8.5dB*/ + {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 17, -7.5dB*/ + {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 19, -6.5dB*/ + {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /*20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 21, -5.5dB*/ + {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 23, -4.5dB*/ + {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 25, -3.5dB*/ + {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 26, -3.0dB*/ + {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 27, -2.5dB*/ + {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 29, -1.5dB*/ + {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 30, -1.0dB*/ + {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 31, -0.5dB*/ + {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04} /* 32, +0dB*/ +}; + +const u8 cck_swing_table_ch14_new[CCK_TABLE_SIZE][8] = { + {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, /* 0, -16.0dB*/ + {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 1, -15.5dB*/ + {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 2, -15.0dB*/ + {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 3, -14.5dB*/ + {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 4, -14.0dB*/ + {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /*5, -13.5dB*/ + {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 6, -13.0dB*/ + {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 7, -12.5dB*/ + {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 8, -12.0dB*/ + {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 9, -11.5dB*/ + {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 10, -11.0dB*/ + {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /*11, -10.5dB*/ + {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 12, -10.0dB*/ + {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 13, -9.5dB*/ + {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /*14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 15, -8.5dB*/ + {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 17, -7.5dB*/ + {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 19, -6.5dB */ + {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 21, -5.5dB*/ + {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /*23, -4.5dB*/ + {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 25, -3.5dB */ + {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 26, -3.0dB */ + {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /*27, -2.5dB*/ + {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /*29, -1.5dB*/ + {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 30, -1.0dB */ + {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 31, -0.5dB */ + {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00} /* 32, +0dB */ +}; + +const u32 cck_swing_table_ch1_ch14_8723d[CCK_TABLE_SIZE_8723D] = { + 0x0CD, /*0 , -20dB*/ + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, + 0x287, + 0x2AE, + 0x2D6, + 0x301, + 0x32F, + 0x35F, + 0x392, + 0x3C9, + 0x402, + 0x43F, + 0x47F, + 0x4C3, + 0x50C, + 0x558, + 0x5A9, + 0x5FF, + 0x65A, + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + +/* JJ ADD 20161014 */ +const u32 cck_swing_table_ch1_ch14_8710b[CCK_TABLE_SIZE_8710B] = { + 0x0CD, /*0 , -20dB*/ + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, + 0x287, + 0x2AE, + 0x2D6, + 0x301, + 0x32F, + 0x35F, + 0x392, + 0x3C9, + 0x402, + 0x43F, + 0x47F, + 0x4C3, + 0x50C, + 0x558, + 0x5A9, + 0x5FF, + 0x65A, + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + +/* Winnita ADD 20171116 PathA 0xAB4[10:0],PathB 0xAB4[21:11]*/ +const u32 cck_swing_table_ch1_ch14_8192f[CCK_TABLE_SIZE_8192F] = { + 0x0CD, /*0 , -20dB*/ + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, /*19*/ + 0x287, /*20*/ + 0x2AE, /*21*/ + 0x2D6, /*22*/ + 0x301, /*23*/ + 0x32F, /*24*/ + 0x35F, /*25*/ + 0x392, /*26*/ + 0x3C9, /*27*/ + 0x402, /*28*/ + 0x43F, /*29*/ + 0x47F, /*30*/ + 0x4C3, /*31*/ + 0x50C, /*32*/ + 0x558, /*33*/ + 0x5A9, /*34*/ + 0x5FF, /*35*/ + 0x65A, /*36*/ + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + +/* Winnita ADD 201805 PathA 0xAB4[10:0]*/ +const u32 cck_swing_table_ch1_ch14_8721d[CCK_TABLE_SIZE_8721D] = { + 0x0CD, /*0 , -20dB*/ + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, /*19*/ + 0x287, /*20*/ + 0x2AE, /*21*/ + 0x2D6, /*22*/ + 0x301, /*23*/ + 0x32F, /*24*/ + 0x35F, /*25*/ + 0x392, /*26*/ + 0x3C9, /*27*/ + 0x402, /*28*/ + 0x43F, /*29*/ + 0x47F, /*30*/ + 0x4C3, /*31*/ + 0x50C, /*32*/ + 0x558, /*33*/ + 0x5A9, /*34*/ + 0x5FF, /*35*/ + 0x65A, /*36*/ + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + +const u32 cck_swing_table_ch1_ch14_8710c[CCK_TABLE_SIZE_8710C] = { + 0x0CD, /*0 , -20dB*/ + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, + 0x287, + 0x2AE, + 0x2D6, + 0x301, + 0x32F, + 0x35F, + 0x392, + 0x3C9, + 0x402, + 0x43F, + 0x47F, + 0x4C3, + 0x50C, + 0x558, + 0x5A9, + 0x5FF, + 0x65A, + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + +const u32 cck_swing_table_03db_ch1_ch14_8710c[CCK_03DB_TABLE_SIZE_8710C] = { + 0x143, /*0 , -4dB*/ + 0x14C, /*1 , -3.75dB*/ + 0x156, /*2 , -3.5dB*/ + 0x160, + 0x16A, + 0x175, + 0x17F, + 0x18B, + 0x196, + 0x1A2, + 0x1AE, + 0x1BB, + 0x1C8, + 0x1D5, + 0x1E3, + 0x1F1, + 0x200, + 0x20F, + 0x21E, + 0x22F, + 0x23F, + 0x250, + 0x261, + 0x273, + 0x285, + 0x298, + 0x2AB, + 0x2BF, + 0x2D6, + 0x2E9, + 0x2FF, + 0x315, + 0x32C, + 0x344, + 0x35C, + 0x375, + 0x390, + 0x3AA, + 0x3C5, + 0x3E1, + 0x402, /*40 , +6dB default*/ + 0x41C, + 0x43B, + 0x45A, + 0x47C, + 0x49C, + 0x4BF, + 0x4E2, + 0x510, + 0x52C, + 0x553, + 0x57B, + 0x5A5, + 0x5CE, + 0x5F9, + 0x626, + 0x655, + 0x683, + 0x6B5, + 0x6E6, + 0x71E, + 0x74E, + 0x786, + 0x7BD, + 0x7F9, + 0x832, + 0x871, + 0x8AF, + 0x8F2, + 0x932, + 0x977, + 0x9BE, + 0xA0E, + 0xA52, + 0xAA1, + 0xAEE, + 0xB54, + 0xB95, + 0xBEB, + 0xC43, + 0xCA3 /*80 , +16dB*/ +}; + +const u32 ofdm_swing_table_03DB_8710c[OFDM_03DB_TABLE_SIZE_8710C] = { + 0xE4, /*0 , -7dB*/ + 0xEB, /*1 , -6.75dB*/ + 0xF2, /*2 , -6.5dB*/ + 0xF9, + 0x100, + 0x108, + 0x110, + 0x118, + 0x11F, + 0x128, + 0x131, + 0x13A, + 0x143, + 0x14C, + 0x156, + 0x160, + 0x16A, + 0x175, + 0x180, + 0x18B, + 0x196, + 0x1A2, + 0x1AE, + 0x1BB, + 0x1C8, + 0x1D5, + 0x1E3, + 0x1F1, + 0x200, + 0x20F, + 0x21F, + 0x22F, + 0x23F, + 0x250, + 0x261, + 0x273, + 0x286, + 0x298, + 0x2AB, + 0x2BF, + 0x2D6, /*40 , +3dB default*/ + 0x2E9, + 0x2FF, + 0x315, + 0x32C, + 0x344, + 0x35C, + 0x375, + 0x390, + 0x3AA, + 0x3C5, + 0x3E1, + 0x3FF, + 0x41C, + 0x43B, + 0x45A, + 0x47B, + 0x49C, + 0x4BF, + 0x4E2, + 0x507, + 0x52C, + 0x553, + 0x57B, + 0x5A4, + 0x5CE, + 0x5F9, + 0x626, + 0x654, + 0x683, + 0x6B4, + 0x6E6, + 0x71B, + 0x74E, + 0x785, + 0x7BD, + 0x7F7, + 0x832, + 0x870, + 0x8AF, + 0x8F0 /*80 , +13dB*/ +}; + + + +const u32 tx_scaling_table_jaguar[TXSCALE_TABLE_SIZE] = { + 0x081, /* 0, -12.0dB*/ + 0x088, /* 1, -11.5dB*/ + 0x090, /* 2, -11.0dB*/ + 0x099, /* 3, -10.5dB*/ + 0x0A2, /* 4, -10.0dB*/ + 0x0AC, /* 5, -9.5dB*/ + 0x0B6, /* 6, -9.0dB*/ + 0x0C0, /*7, -8.5dB*/ + 0x0CC, /* 8, -8.0dB*/ + 0x0D8, /* 9, -7.5dB*/ + 0x0E5, /* 10, -7.0dB*/ + 0x0F2, /* 11, -6.5dB*/ + 0x101, /* 12, -6.0dB*/ + 0x110, /* 13, -5.5dB*/ + 0x120, /* 14, -5.0dB*/ + 0x131, /* 15, -4.5dB*/ + 0x143, /* 16, -4.0dB*/ + 0x156, /* 17, -3.5dB*/ + 0x16A, /* 18, -3.0dB*/ + 0x180, /* 19, -2.5dB*/ + 0x197, /* 20, -2.0dB*/ + 0x1AF, /* 21, -1.5dB*/ + 0x1C8, /* 22, -1.0dB*/ + 0x1E3, /* 23, -0.5dB*/ + 0x200, /* 24, +0 dB*/ + 0x21E, /* 25, +0.5dB*/ + 0x23E, /* 26, +1.0dB*/ + 0x261, /* 27, +1.5dB*/ + 0x285,/* 28, +2.0dB*/ + 0x2AB, /* 29, +2.5dB*/ + 0x2D3, /*30, +3.0dB*/ + 0x2FE, /* 31, +3.5dB*/ + 0x32B, /* 32, +4.0dB*/ + 0x35C, /* 33, +4.5dB*/ + 0x38E, /* 34, +5.0dB*/ + 0x3C4, /* 35, +5.5dB*/ + 0x3FE /* 36, +6.0dB */ +}; + +void +odm_txpowertracking_init( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + odm_txpowertracking_thermal_meter_init(dm); +} + +u8 +get_swing_index( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + u8 i = 0; + u32 bb_swing; + u32 swing_table_size; + u32 *swing_table; + u32 table_value; + +#if (RTL8710C_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8710C) { + bb_swing = odm_get_bb_reg(dm, R_0xcc8, 0x000007ff); + + for (i = 0; i < OFDM_03DB_TABLE_SIZE_8710C; i++) { + if (bb_swing == ofdm_swing_table_03DB_8710c[i]) + break; + } + } +#elif (RTL8195B_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8195B) { + bb_swing = odm_get_bb_reg(dm, R_0xc1c, 0xFFE00000); + swing_table = (u32*)tx_scaling_table_jaguar; + swing_table_size = TXSCALE_TABLE_SIZE; + + for (i = 0; i < swing_table_size; i++) { + table_value = swing_table[i]; + + table_value = table_value; + if (bb_swing == table_value) + break; + } + } +#endif + return i; +} + +u8 +get_cck_swing_index( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + u8 i = 0; + u32 bb_cck_swing; + +#if (RTL8188E_SUPPORT == 1 || RTL8723B_SUPPORT == 1 || RTL8192E_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8188E || dm->support_ic_type == ODM_RTL8723B || + dm->support_ic_type == ODM_RTL8192E) { + bb_cck_swing = odm_read_1byte(dm, 0xa22); + + for (i = 0; i < CCK_TABLE_SIZE; i++) { + if (bb_cck_swing == cck_swing_table_ch1_ch13_new[i][0]) + break; + } + } +#elif (RTL8703B_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8703B) { + bb_cck_swing = odm_read_1byte(dm, 0xa22); + + for (i = 0; i < CCK_TABLE_SIZE_88F; i++) { + if (bb_cck_swing == cck_swing_table_ch1_ch14_88f[i][0]) + break; + } + } +#elif (RTL8710C_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8710C) { + bb_cck_swing = odm_get_bb_reg(dm, R_0xab4, 0x7ff); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "bb_cck_swing = 0x%x\n", bb_cck_swing); + + for (i = 0; i < CCK_03DB_TABLE_SIZE_8710C; i++) { + if (bb_cck_swing == cck_swing_table_03db_ch1_ch14_8710c[i]) + break; + } + } +#endif + + return i; +} + +s8 +get_txagc_default_index( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + s8 tmp; + + if (dm->support_ic_type == ODM_RTL8814B) { + tmp = (s8)(odm_get_bb_reg(dm, R_0x18a0, 0x7f) & 0xff); + if (tmp & BIT(6)) + tmp = tmp | 0x80; + return tmp; + } else + return 0; +} + +void +odm_txpowertracking_thermal_meter_init( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u8 default_swing_index; + u8 p = 0; + struct dm_rf_calibration_struct *cali_info = &dm->rf_calibrate_info; + struct _hal_rf_ *rf = &dm->rf_table; + + if (!(*dm->mp_mode)) + cali_info->txpowertrack_control = true; + else + cali_info->txpowertrack_control = false; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "dm txpowertrack_control = %d\n", cali_info->txpowertrack_control); + + /* dm->rf_calibrate_info.txpowertrack_control = true; */ + cali_info->thermal_value = rf->eeprom_thermal; + cali_info->thermal_value_iqk = rf->eeprom_thermal; + cali_info->thermal_value_lck = rf->eeprom_thermal; + + if (!cali_info->default_bb_swing_index_flag) { + if (dm->support_ic_type == ODM_RTL8195B) { + default_swing_index = get_swing_index(dm); + cali_info->default_ofdm_index = (default_swing_index >= TXSCALE_TABLE_SIZE) ? 24 : default_swing_index; + cali_info->default_cck_index = 24; + } else if (dm->support_ic_type == ODM_RTL8721D) { + cali_info->default_ofdm_index = 28; /*OFDM: -1dB*/ + cali_info->default_cck_index = 28; /*CCK: -6dB*/ + } else if (dm->support_ic_type == ODM_RTL8710C) { + cali_info->default_ofdm_index = get_swing_index(dm); + cali_info->default_cck_index = get_cck_swing_index(dm); + } + cali_info->default_bb_swing_index_flag = true; + } + + cali_info->bb_swing_idx_cck_base = cali_info->default_cck_index; + cali_info->CCK_index = cali_info->default_cck_index; + + for (p = RF_PATH_A; p < MAX_RF_PATH; ++p) { + cali_info->bb_swing_idx_ofdm_base[p] = cali_info->default_ofdm_index; + cali_info->OFDM_index[p] = cali_info->default_ofdm_index; + cali_info->delta_power_index[p] = 0; + cali_info->delta_power_index_last[p] = 0; + cali_info->power_index_offset[p] = 0; + } + cali_info->modify_tx_agc_value_ofdm = 0; + cali_info->modify_tx_agc_value_cck = 0; + cali_info->tm_trigger = 0; +} + +void +odm_txpowertracking_check( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + odm_txpowertracking_check_iot(dm); +} + +void +odm_txpowertracking_check_iot( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &dm->rf_table; + + if (!(rf->rf_supportability & HAL_RF_TX_PWR_TRACK)) + return; + + if (!dm->rf_calibrate_info.tm_trigger) { + if (dm->support_ic_type == ODM_RTL8195B) + odm_set_rf_reg(dm, RF_PATH_A, RF_T_METER_NEW, (BIT(17) | BIT(16)), 0x03); + else if (dm->support_ic_type == ODM_RTL8721D || + dm->support_ic_type == ODM_RTL8710C) + odm_set_rf_reg(dm, RF_PATH_A, RF_T_METER_NEW, + (BIT(12) | BIT(11)), 0x03); + + dm->rf_calibrate_info.tm_trigger = 1; + return; + } + odm_txpowertracking_callback_thermal_meter(dm); + dm->rf_calibrate_info.tm_trigger = 0; +} + +void +odm_txpowertracking_check_mp( + void *dm_void +) +{ +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + struct dm_struct *dm = (struct dm_struct *)dm_void; + void *adapter = dm->adapter; + + if (odm_check_power_status(adapter) == false) { + RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD, ("check_pow_status, return false\n")); + return; + } + + odm_txpowertracking_thermal_meter_check(adapter); +#endif +} + +void +odm_txpowertracking_check_ap( + void *dm_void +) +{ +#if (DM_ODM_SUPPORT_TYPE == ODM_AP) + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct rtl8192cd_priv *priv = dm->priv; + + return; + +#endif +} diff --git a/hal/phydm/halrf/halrf_powertracking_iot.h b/hal/phydm/halrf/halrf_powertracking_iot.h new file mode 100644 index 0000000..431890b --- /dev/null +++ b/hal/phydm/halrf/halrf_powertracking_iot.h @@ -0,0 +1,372 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALRF_POWERTRACKING_H__ +#define __HALRF_POWERTRACKING_H__ + +#define DPK_DELTA_MAPPING_NUM 13 +#define index_mapping_HP_NUM 15 +#define OFDM_TABLE_SIZE 43 +#define CCK_TABLE_SIZE 33 +#define CCK_TABLE_SIZE_88F 21 +#define TXSCALE_TABLE_SIZE 37 +#define CCK_TABLE_SIZE_8723D 41 +/* JJ ADD 20161014 */ +#define CCK_TABLE_SIZE_8710B 41 +#define CCK_TABLE_SIZE_8192F 41 +#define CCK_TABLE_SIZE_8721D 41 +#define CCK_TABLE_SIZE_8710C 41 +#define CCK_03DB_TABLE_SIZE_8710C 81 +#define OFDM_03DB_TABLE_SIZE_8710C 81 + + +#define TXPWR_TRACK_TABLE_SIZE 30 +#define DELTA_SWINGIDX_SIZE 30 +#define DELTA_SWINTSSI_SIZE 61 +#define BAND_NUM 4 + +#define AVG_THERMAL_NUM 8 +#define IQK_MAC_REG_NUM 4 +#define IQK_ADDA_REG_NUM 16 +#define IQK_BB_REG_NUM_MAX 10 + +#define IQK_BB_REG_NUM 9 + + + +#define iqk_matrix_reg_num 8 +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) && defined(DM_ODM_CE_MAC80211) +#else +#define IQK_MATRIX_SETTINGS_NUM (14+24+21) /* Channels_2_4G_NUM + Channels_5G_20M_NUM + Channels_5G */ +#endif + +extern const u32 ofdm_swing_table[OFDM_TABLE_SIZE]; +extern const u8 cck_swing_table_ch1_ch13[CCK_TABLE_SIZE][8]; +extern const u8 cck_swing_table_ch14[CCK_TABLE_SIZE][8]; + +extern const u32 ofdm_swing_table_new[OFDM_TABLE_SIZE]; +extern const u8 cck_swing_table_ch1_ch13_new[CCK_TABLE_SIZE][8]; +extern const u8 cck_swing_table_ch14_new[CCK_TABLE_SIZE][8]; +extern const u8 cck_swing_table_ch1_ch14_88f[CCK_TABLE_SIZE_88F][16]; +extern const u8 cck_swing_table_ch1_ch13_88f[CCK_TABLE_SIZE_88F][16]; +extern const u8 cck_swing_table_ch14_88f[CCK_TABLE_SIZE_88F][16]; +extern const u32 cck_swing_table_ch1_ch14_8723d[CCK_TABLE_SIZE_8723D]; +/* JJ ADD 20161014 */ +extern const u32 cck_swing_table_ch1_ch14_8710b[CCK_TABLE_SIZE_8710B]; +extern const u32 cck_swing_table_ch1_ch14_8192f[CCK_TABLE_SIZE_8192F]; +extern const u32 cck_swing_table_ch1_ch14_8721d[CCK_TABLE_SIZE_8721D]; +extern const u32 cck_swing_table_ch1_ch14_8710c[CCK_TABLE_SIZE_8710C]; +extern const u32 cck_swing_table_03db_ch1_ch14_8710c[CCK_03DB_TABLE_SIZE_8710C]; +extern const u32 ofdm_swing_table_03DB_8710c[OFDM_03DB_TABLE_SIZE_8710C]; + +extern const u32 tx_scaling_table_jaguar[TXSCALE_TABLE_SIZE]; + +/* <20121018, Kordan> In case fail to read TxPowerTrack.txt, we use the table of 88E as the default table. */ +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) && defined(DM_ODM_CE_MAC80211) +#else +static u8 delta_swing_table_idx_2ga_p_8188e[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9}; +static u8 delta_swing_table_idx_2ga_n_8188e[] = {0, 0, 0, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11}; +#endif + +void +odm_txpowertracking_init( + void *dm_void +); + +#define dm_check_txpowertracking odm_txpowertracking_check + +struct iqk_matrix_regs_setting { + boolean is_iqk_done; + s32 value[3][iqk_matrix_reg_num]; + boolean is_bw_iqk_result_saved[3]; +}; + +struct dm_rf_calibration_struct { + /* for tx power tracking */ + + u32 rega24; /* for TempCCK */ + s32 rege94; + s32 rege9c; + s32 regeb4; + s32 regebc; + + u8 tx_powercount; + boolean is_txpowertracking_init; + boolean is_txpowertracking; + u8 txpowertrack_control; /* for mp mode, turn off txpwrtracking as default */ + u8 tm_trigger; + u8 internal_pa_5g[2]; /* pathA / pathB */ + + u8 thermal_meter[2]; /* thermal_meter, index 0 for RFIC0, and 1 for RFIC1 */ + u8 thermal_value; + u8 thermal_value_lck; + u8 thermal_value_iqk; + s8 thermal_value_delta; /* delta of thermal_value and efuse thermal */ + u8 thermal_value_dpk; + u8 thermal_value_avg[AVG_THERMAL_NUM]; + u8 thermal_value_avg_index; + u8 thermal_value_rx_gain; + u8 thermal_value_crystal; + u8 thermal_value_dpk_store; + u8 thermal_value_dpk_track; + boolean txpowertracking_in_progress; + + boolean is_reloadtxpowerindex; + u8 is_rf_pi_enable; + u32 txpowertracking_callback_cnt; /* cosa add for debug */ + + + /* ------------------------- Tx power Tracking ------------------------- */ + u8 is_cck_in_ch14; + u8 CCK_index; + u8 OFDM_index[MAX_RF_PATH]; + s8 power_index_offset[MAX_RF_PATH]; + s8 delta_power_index[MAX_RF_PATH]; + s8 delta_power_index_last[MAX_RF_PATH]; + boolean is_tx_power_changed; + s8 xtal_offset; + s8 xtal_offset_last; + +#if (RTL8710B_SUPPORT == 1 || RTL8721D_SUPPORT == 1) + struct iqk_matrix_regs_setting iqk_matrix_reg_setting[IQK_MATRIX_SETTINGS_NUM]; +#endif + u8 delta_lck; + s8 bb_swing_diff_2g, bb_swing_diff_5g; /* Unit: dB */ + u8 delta_swing_table_idx_2g_cck_a_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_a_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_b_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_b_n[DELTA_SWINGIDX_SIZE]; +#if !(DM_ODM_SUPPORT_TYPE & ODM_IOT) + u8 delta_swing_table_idx_2g_cck_c_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_c_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_d_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_d_n[DELTA_SWINGIDX_SIZE]; +#endif + u8 delta_swing_table_idx_2ga_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gb_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gb_n[DELTA_SWINGIDX_SIZE]; +#if !(DM_ODM_SUPPORT_TYPE & ODM_IOT) + u8 delta_swing_table_idx_2gc_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gc_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gd_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gd_n[DELTA_SWINGIDX_SIZE]; +#endif + +#if (RTL8195B_SUPPORT == 1) + u8 delta_swing_table_idx_5ga_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5ga_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gb_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gb_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; +#endif + +#if !(DM_ODM_SUPPORT_TYPE & ODM_IOT) + u8 delta_swing_table_idx_5gc_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gc_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gd_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gd_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; +#endif +#if !(DM_ODM_SUPPORT_TYPE & ODM_IOT) + u8 delta_swing_tssi_table_2g_cck_a[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_b[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_c[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_d[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2ga[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gb[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gc[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gd[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5ga[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gb[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gc[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gd[BAND_NUM][DELTA_SWINTSSI_SIZE]; +#endif + s8 delta_swing_table_xtal_p[DELTA_SWINGIDX_SIZE]; + s8 delta_swing_table_xtal_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_p_8188e[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_n_8188e[DELTA_SWINGIDX_SIZE]; + + u8 bb_swing_idx_ofdm[MAX_RF_PATH]; + u8 bb_swing_idx_ofdm_current; +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE | ODM_IOT)) + u8 bb_swing_idx_ofdm_base[MAX_RF_PATH]; +#else + u8 bb_swing_idx_ofdm_base; +#endif + boolean default_bb_swing_index_flag; + boolean bb_swing_flag_ofdm; + u8 bb_swing_idx_cck; + u8 bb_swing_idx_cck_current; + u8 bb_swing_idx_cck_base; + u8 default_ofdm_index; + u8 default_cck_index; + s8 default_txagc_index; + boolean bb_swing_flag_cck; + + s8 absolute_ofdm_swing_idx[MAX_RF_PATH]; + s8 remnant_ofdm_swing_idx[MAX_RF_PATH]; + s8 absolute_cck_swing_idx[MAX_RF_PATH]; + s8 remnant_cck_swing_idx; + s8 modify_tx_agc_value; /*Remnat compensate value at tx_agc */ + boolean modify_tx_agc_flag_path_a; + boolean modify_tx_agc_flag_path_b; + boolean modify_tx_agc_flag_path_c; + boolean modify_tx_agc_flag_path_d; + boolean modify_tx_agc_flag_path_a_cck; + boolean modify_tx_agc_flag_path_b_cck; + + s8 kfree_offset[MAX_RF_PATH]; + + /* -------------------------------------------------------------------- */ + + /* for IQK */ + u32 regc04; + u32 reg874; + u32 regc08; + u32 regb68; + u32 regb6c; + u32 reg870; + u32 reg860; + u32 reg864; + + boolean is_iqk_initialized; + boolean is_lck_in_progress; + boolean is_antenna_detected; + boolean is_need_iqk; + boolean is_iqk_in_progress; + boolean is_iqk_pa_off; + u8 delta_iqk; + u32 ADDA_backup[IQK_ADDA_REG_NUM]; + u32 IQK_MAC_backup[IQK_MAC_REG_NUM]; + u32 IQK_BB_backup_recover[9]; + u32 IQK_BB_backup[IQK_BB_REG_NUM]; +#if !(DM_ODM_SUPPORT_TYPE & ODM_IOT) + u32 tx_iqc_8723b[2][3][2]; /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}} */ + u32 rx_iqc_8723b[2][2][2]; /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}} */ + u32 tx_iqc_8703b[3][2]; /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}}*/ + u32 rx_iqc_8703b[2][2]; /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}}*/ + u32 tx_iqc_8723d[2][3][2]; /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}}*/ + u32 rx_iqc_8723d[2][2][2]; /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}}*/ +#endif + /* JJ ADD 20161014 */ + u32 tx_iqc_8710b[2][3][2]; /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}}*/ + u32 rx_iqc_8710b[2][2][2]; /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}}*/ + + u8 iqk_step; + u8 kcount; + u8 retry_count[4][2]; /* [4]: path ABCD, [2] TXK, RXK */ + boolean is_mp_mode; + + + + /* IQK time measurement */ + u32 iqk_start_time; + u32 iqk_progressing_time; + u32 iqk_total_progressing_time; + u32 lck_progressing_time; + + u32 lok_result; + + /* for APK */ + u32 ap_koutput[2][2]; /* path A/B; output1_1a/output1_2a */ + u8 is_ap_kdone; + u8 is_apk_thermal_meter_ignore; + + /* DPK */ + boolean is_dpk_fail; + u8 is_dp_done; + u8 is_dp_path_aok; + u8 is_dp_path_bok; + + u32 tx_lok[2]; + u32 dpk_tx_agc; + s32 dpk_gain; + u32 dpk_thermal[4]; + s8 modify_tx_agc_value_ofdm; + s8 modify_tx_agc_value_cck; + + /*Add by Yuchen for Kfree Phydm*/ + u8 reg_rf_kfree_enable; /*for registry*/ + u8 rf_kfree_enable; /*for efuse enable check*/ + +}; + + +void +odm_txpowertracking_check( + void *dm_void +); + +void +odm_txpowertracking_check_ap( + void *dm_void +); + +void +odm_txpowertracking_thermal_meter_init( + void *dm_void +); + + +void +odm_txpowertracking_check_mp( + void *dm_void +); + + +void +odm_txpowertracking_check_iot( + void *dm_void +); + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN)) + +void +odm_txpowertracking_callback_thermal_meter92c( + void *adapter +); + +void +odm_txpowertracking_callback_rx_gain_thermal_meter92d( + void *adapter +); + +void +odm_txpowertracking_callback_thermal_meter92d( + void *adapter +); + +void +odm_txpowertracking_direct_call92c( + void *adapter +); + +void +odm_txpowertracking_thermal_meter_check( + void *adapter +); + +#endif + +#endif /*#ifndef __HALRF_POWER_TRACKING_H__*/ diff --git a/hal/phydm/halrf/halrf_powertracking_win.c b/hal/phydm/halrf/halrf_powertracking_win.c new file mode 100644 index 0000000..d53c3a8 --- /dev/null +++ b/hal/phydm/halrf/halrf_powertracking_win.c @@ -0,0 +1,936 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +/*============================================================ */ +/* include files */ +/*============================================================ */ +#include "mp_precomp.h" +#include "phydm_precomp.h" + +/* ************************************************************ + * Global var + * ************************************************************ */ + +u32 ofdm_swing_table[OFDM_TABLE_SIZE] = { + 0x7f8001fe, /* 0, +6.0dB */ + 0x788001e2, /* 1, +5.5dB */ + 0x71c001c7, /* 2, +5.0dB */ + 0x6b8001ae, /* 3, +4.5dB */ + 0x65400195, /* 4, +4.0dB */ + 0x5fc0017f, /* 5, +3.5dB */ + 0x5a400169, /* 6, +3.0dB */ + 0x55400155, /* 7, +2.5dB */ + 0x50800142, /* 8, +2.0dB */ + 0x4c000130, /* 9, +1.5dB */ + 0x47c0011f, /* 10, +1.0dB */ + 0x43c0010f, /* 11, +0.5dB */ + 0x40000100, /* 12, +0dB */ + 0x3c8000f2, /* 13, -0.5dB */ + 0x390000e4, /* 14, -1.0dB */ + 0x35c000d7, /* 15, -1.5dB */ + 0x32c000cb, /* 16, -2.0dB */ + 0x300000c0, /* 17, -2.5dB */ + 0x2d4000b5, /* 18, -3.0dB */ + 0x2ac000ab, /* 19, -3.5dB */ + 0x288000a2, /* 20, -4.0dB */ + 0x26000098, /* 21, -4.5dB */ + 0x24000090, /* 22, -5.0dB */ + 0x22000088, /* 23, -5.5dB */ + 0x20000080, /* 24, -6.0dB */ + 0x1e400079, /* 25, -6.5dB */ + 0x1c800072, /* 26, -7.0dB */ + 0x1b00006c, /* 27. -7.5dB */ + 0x19800066, /* 28, -8.0dB */ + 0x18000060, /* 29, -8.5dB */ + 0x16c0005b, /* 30, -9.0dB */ + 0x15800056, /* 31, -9.5dB */ + 0x14400051, /* 32, -10.0dB */ + 0x1300004c, /* 33, -10.5dB */ + 0x12000048, /* 34, -11.0dB */ + 0x11000044, /* 35, -11.5dB */ + 0x10000040, /* 36, -12.0dB */ +}; + +u8 cck_swing_table_ch1_ch13[CCK_TABLE_SIZE][8] = { + {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, /* 0, +0dB */ + {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 1, -0.5dB */ + {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 2, -1.0dB */ + {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 3, -1.5dB */ + {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 4, -2.0dB */ + {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 5, -2.5dB */ + {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 6, -3.0dB */ + {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 7, -3.5dB */ + {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 8, -4.0dB */ + {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 9, -4.5dB */ + {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 10, -5.0dB */ + {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 11, -5.5dB */ + {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 12, -6.0dB <== default */ + {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 13, -6.5dB */ + {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 14, -7.0dB */ + {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 15, -7.5dB */ + {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */ + {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 17, -8.5dB */ + {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 18, -9.0dB */ + {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 19, -9.5dB */ + {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 20, -10.0dB */ + {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 21, -10.5dB */ + {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 22, -11.0dB */ + {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 23, -11.5dB */ + {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 24, -12.0dB */ + {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 25, -12.5dB */ + {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 26, -13.0dB */ + {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 27, -13.5dB */ + {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 28, -14.0dB */ + {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 29, -14.5dB */ + {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 30, -15.0dB */ + {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 31, -15.5dB */ + {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01} /* 32, -16.0dB */ +}; + + +u8 cck_swing_table_ch14[CCK_TABLE_SIZE][8] = { + {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, /* 0, +0dB */ + {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 1, -0.5dB */ + {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 2, -1.0dB */ + {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 3, -1.5dB */ + {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 4, -2.0dB */ + {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 5, -2.5dB */ + {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 6, -3.0dB */ + {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 7, -3.5dB */ + {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 8, -4.0dB */ + {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 9, -4.5dB */ + {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 10, -5.0dB */ + {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 11, -5.5dB */ + {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 12, -6.0dB <== default */ + {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 13, -6.5dB */ + {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 14, -7.0dB */ + {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 15, -7.5dB */ + {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */ + {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 17, -8.5dB */ + {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 18, -9.0dB */ + {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 19, -9.5dB */ + {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 20, -10.0dB */ + {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 21, -10.5dB */ + {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 22, -11.0dB */ + {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 23, -11.5dB */ + {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 24, -12.0dB */ + {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 25, -12.5dB */ + {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 26, -13.0dB */ + {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 27, -13.5dB */ + {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 28, -14.0dB */ + {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 29, -14.5dB */ + {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 30, -15.0dB */ + {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 31, -15.5dB */ + {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00} /* 32, -16.0dB */ +}; + + +u32 ofdm_swing_table_new[OFDM_TABLE_SIZE] = { + 0x0b40002d, /* 0, -15.0dB */ + 0x0c000030, /* 1, -14.5dB */ + 0x0cc00033, /* 2, -14.0dB */ + 0x0d800036, /* 3, -13.5dB */ + 0x0e400039, /* 4, -13.0dB */ + 0x0f00003c, /* 5, -12.5dB */ + 0x10000040, /* 6, -12.0dB */ + 0x11000044, /* 7, -11.5dB */ + 0x12000048, /* 8, -11.0dB */ + 0x1300004c, /* 9, -10.5dB */ + 0x14400051, /* 10, -10.0dB */ + 0x15800056, /* 11, -9.5dB */ + 0x16c0005b, /* 12, -9.0dB */ + 0x18000060, /* 13, -8.5dB */ + 0x19800066, /* 14, -8.0dB */ + 0x1b00006c, /* 15, -7.5dB */ + 0x1c800072, /* 16, -7.0dB */ + 0x1e400079, /* 17, -6.5dB */ + 0x20000080, /* 18, -6.0dB */ + 0x22000088, /* 19, -5.5dB */ + 0x24000090, /* 20, -5.0dB */ + 0x26000098, /* 21, -4.5dB */ + 0x288000a2, /* 22, -4.0dB */ + 0x2ac000ab, /* 23, -3.5dB */ + 0x2d4000b5, /* 24, -3.0dB */ + 0x300000c0, /* 25, -2.5dB */ + 0x32c000cb, /* 26, -2.0dB */ + 0x35c000d7, /* 27, -1.5dB */ + 0x390000e4, /* 28, -1.0dB */ + 0x3c8000f2, /* 29, -0.5dB */ + 0x40000100, /* 30, +0dB */ + 0x43c0010f, /* 31, +0.5dB */ + 0x47c0011f, /* 32, +1.0dB */ + 0x4c000130, /* 33, +1.5dB */ + 0x50800142, /* 34, +2.0dB */ + 0x55400155, /* 35, +2.5dB */ + 0x5a400169, /* 36, +3.0dB */ + 0x5fc0017f, /* 37, +3.5dB */ + 0x65400195, /* 38, +4.0dB */ + 0x6b8001ae, /* 39, +4.5dB */ + 0x71c001c7, /* 40, +5.0dB */ + 0x788001e2, /* 41, +5.5dB */ + 0x7f8001fe /* 42, +6.0dB */ +}; + + +u8 cck_swing_table_ch1_ch14_88f[CCK_TABLE_SIZE_88F][16] = { + {0x44, 0x42, 0x3C, 0x33, 0x28, 0x1C, 0x13, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-16dB*/ + {0x48, 0x46, 0x3F, 0x36, 0x2A, 0x1E, 0x14, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15.5dB*/ + {0x4D, 0x4A, 0x43, 0x39, 0x2C, 0x20, 0x15, 0x0C, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15dB*/ + {0x51, 0x4F, 0x47, 0x3C, 0x2F, 0x22, 0x16, 0x0D, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14.5dB*/ + {0x56, 0x53, 0x4B, 0x40, 0x32, 0x24, 0x17, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14dB*/ + {0x5B, 0x58, 0x50, 0x43, 0x35, 0x26, 0x19, 0x0E, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13.5dB*/ + {0x60, 0x5D, 0x54, 0x47, 0x38, 0x28, 0x1A, 0x0F, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13dB*/ + {0x66, 0x63, 0x59, 0x4C, 0x3B, 0x2B, 0x1C, 0x10, 0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12.5dB*/ + {0x6C, 0x69, 0x5F, 0x50, 0x3F, 0x2D, 0x1E, 0x11, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12dB*/ + {0x73, 0x6F, 0x64, 0x55, 0x42, 0x30, 0x1F, 0x12, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11.5dB*/ + {0x79, 0x76, 0x6A, 0x5A, 0x46, 0x33, 0x21, 0x13, 0x09, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11dB*/ + {0x81, 0x7C, 0x71, 0x5F, 0x4A, 0x36, 0x23, 0x14, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10.5dB*/ + {0x88, 0x84, 0x77, 0x65, 0x4F, 0x39, 0x25, 0x15, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10dB*/ + {0x90, 0x8C, 0x7E, 0x6B, 0x54, 0x3C, 0x27, 0x17, 0x0B, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9.5dB*/ + {0x99, 0x94, 0x86, 0x71, 0x58, 0x40, 0x2A, 0x18, 0x0B, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9dB*/ + {0xA2, 0x9D, 0x8E, 0x78, 0x5E, 0x43, 0x2C, 0x19, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8.5dB*/ + {0xAC, 0xA6, 0x96, 0x7F, 0x63, 0x47, 0x2F, 0x1B, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8dB*/ + {0xB6, 0xB0, 0x9F, 0x87, 0x69, 0x4C, 0x32, 0x1D, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7.5dB*/ + {0xC1, 0xBA, 0xA8, 0x8F, 0x6F, 0x50, 0x35, 0x1E, 0x0E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7dB*/ + {0xCC, 0xC5, 0xB2, 0x97, 0x76, 0x55, 0x38, 0x20, 0x0F, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-6.5dB*/ + {0xD8, 0xD1, 0xBD, 0xA0, 0x7D, 0x5A, 0x3B, 0x22, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /*-6dB*/ +}; + + +u8 cck_swing_table_ch1_ch13_88f[CCK_TABLE_SIZE_88F][16] = { + {0x44, 0x42, 0x3C, 0x33, 0x28, 0x1C, 0x13, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-16dB*/ + {0x48, 0x46, 0x3F, 0x36, 0x2A, 0x1E, 0x14, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15.5dB*/ + {0x4D, 0x4A, 0x43, 0x39, 0x2C, 0x20, 0x15, 0x0C, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15dB*/ + {0x51, 0x4F, 0x47, 0x3C, 0x2F, 0x22, 0x16, 0x0D, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14.5dB*/ + {0x56, 0x53, 0x4B, 0x40, 0x32, 0x24, 0x17, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14dB*/ + {0x5B, 0x58, 0x50, 0x43, 0x35, 0x26, 0x19, 0x0E, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13.5dB*/ + {0x60, 0x5D, 0x54, 0x47, 0x38, 0x28, 0x1A, 0x0F, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13dB*/ + {0x66, 0x63, 0x59, 0x4C, 0x3B, 0x2B, 0x1C, 0x10, 0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12.5dB*/ + {0x6C, 0x69, 0x5F, 0x50, 0x3F, 0x2D, 0x1E, 0x11, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12dB*/ + {0x73, 0x6F, 0x64, 0x55, 0x42, 0x30, 0x1F, 0x12, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11.5dB*/ + {0x79, 0x76, 0x6A, 0x5A, 0x46, 0x33, 0x21, 0x13, 0x09, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11dB*/ + {0x81, 0x7C, 0x71, 0x5F, 0x4A, 0x36, 0x23, 0x14, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10.5dB*/ + {0x88, 0x84, 0x77, 0x65, 0x4F, 0x39, 0x25, 0x15, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10dB*/ + {0x90, 0x8C, 0x7E, 0x6B, 0x54, 0x3C, 0x27, 0x17, 0x0B, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9.5dB*/ + {0x99, 0x94, 0x86, 0x71, 0x58, 0x40, 0x2A, 0x18, 0x0B, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9dB*/ + {0xA2, 0x9D, 0x8E, 0x78, 0x5E, 0x43, 0x2C, 0x19, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8.5dB*/ + {0xAC, 0xA6, 0x96, 0x7F, 0x63, 0x47, 0x2F, 0x1B, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8dB*/ + {0xB6, 0xB0, 0x9F, 0x87, 0x69, 0x4C, 0x32, 0x1D, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7.5dB*/ + {0xC1, 0xBA, 0xA8, 0x8F, 0x6F, 0x50, 0x35, 0x1E, 0x0E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7dB*/ + {0xCC, 0xC5, 0xB2, 0x97, 0x76, 0x55, 0x38, 0x20, 0x0F, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-6.5dB*/ + {0xD8, 0xD1, 0xBD, 0xA0, 0x7D, 0x5A, 0x3B, 0x22, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /*-6dB*/ +}; + + +u8 cck_swing_table_ch14_88f[CCK_TABLE_SIZE_88F][16] = { + {0x44, 0x42, 0x3C, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-16dB*/ + {0x48, 0x46, 0x3F, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15.5dB*/ + {0x4D, 0x4A, 0x43, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-15dB*/ + {0x51, 0x4F, 0x47, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14.5dB*/ + {0x56, 0x53, 0x4B, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-14dB*/ + {0x5B, 0x58, 0x50, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13.5dB*/ + {0x60, 0x5D, 0x54, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-13dB*/ + {0x66, 0x63, 0x59, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12.5dB*/ + {0x6C, 0x69, 0x5F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-12dB*/ + {0x73, 0x6F, 0x64, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11.5dB*/ + {0x79, 0x76, 0x6A, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-11dB*/ + {0x81, 0x7C, 0x71, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10.5dB*/ + {0x88, 0x84, 0x77, 0x4F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-10dB*/ + {0x90, 0x8C, 0x7E, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9.5dB*/ + {0x99, 0x94, 0x86, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-9dB*/ + {0xA2, 0x9D, 0x8E, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8.5dB*/ + {0xAC, 0xA6, 0x96, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-8dB*/ + {0xB6, 0xB0, 0x9F, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7.5dB*/ + {0xC1, 0xBA, 0xA8, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-7dB*/ + {0xCC, 0xC5, 0xB2, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*-6.5dB*/ + {0xD8, 0xD1, 0xBD, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /*-6dB*/ +}; + + +u8 cck_swing_table_ch1_ch13_new[CCK_TABLE_SIZE][8] = { + {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, /* 0, -16.0dB */ + {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 1, -15.5dB */ + {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 2, -15.0dB */ + {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 3, -14.5dB */ + {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 4, -14.0dB */ + {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 5, -13.5dB */ + {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 6, -13.0dB */ + {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 7, -12.5dB */ + {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 8, -12.0dB */ + {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 9, -11.5dB */ + {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 10, -11.0dB */ + {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 11, -10.5dB */ + {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 12, -10.0dB */ + {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 13, -9.5dB */ + {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 15, -8.5dB */ + {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 17, -7.5dB */ + {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 19, -6.5dB */ + {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 21, -5.5dB */ + {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 23, -4.5dB */ + {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 25, -3.5dB */ + {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 26, -3.0dB */ + {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 27, -2.5dB */ + {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 29, -1.5dB */ + {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 30, -1.0dB */ + {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 31, -0.5dB */ + {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04} /* 32, +0dB */ +}; + + +u8 cck_swing_table_ch14_new[CCK_TABLE_SIZE][8] = { + {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, /* 0, -16.0dB */ + {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 1, -15.5dB */ + {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 2, -15.0dB */ + {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 3, -14.5dB */ + {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 4, -14.0dB */ + {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 5, -13.5dB */ + {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 6, -13.0dB */ + {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 7, -12.5dB */ + {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 8, -12.0dB */ + {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 9, -11.5dB */ + {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 10, -11.0dB */ + {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 11, -10.5dB */ + {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 12, -10.0dB */ + {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 13, -9.5dB */ + {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 14, -9.0dB */ + {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 15, -8.5dB */ + {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */ + {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 17, -7.5dB */ + {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 18, -7.0dB */ + {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 19, -6.5dB */ + {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 20, -6.0dB */ + {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 21, -5.5dB */ + {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 22, -5.0dB */ + {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 23, -4.5dB */ + {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 24, -4.0dB */ + {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 25, -3.5dB */ + {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 26, -3.0dB */ + {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 27, -2.5dB */ + {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 28, -2.0dB */ + {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 29, -1.5dB */ + {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 30, -1.0dB */ + {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 31, -0.5dB */ + {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00} /* 32, +0dB */ +}; +u32 cck_swing_table_ch1_ch14_8723d[CCK_TABLE_SIZE_8723D] = { + 0x0CD, + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, + 0x287, + 0x2AE, + 0x2D6, + 0x301, + 0x32F, + 0x35F, + 0x392, + 0x3C9, + 0x402, + 0x43F, + 0x47F, + 0x4C3, + 0x50C, + 0x558, + 0x5A9, + 0x5FF, + 0x65A, + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; +/* JJ ADD 20161014 */ +u32 cck_swing_table_ch1_ch14_8710b[CCK_TABLE_SIZE_8710B] = { + 0x0CD, /*0 , -20dB*/ + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, /*19*/ + 0x287, /*20*/ + 0x2AE, /*21*/ + 0x2D6, /*22*/ + 0x301, /*23*/ + 0x32F, /*24*/ + 0x35F, /*25*/ + 0x392, /*26*/ + 0x3C9, /*27*/ + 0x402, /*28*/ + 0x43F, /*29*/ + 0x47F, /*30*/ + 0x4C3, /*31*/ + 0x50C, /*32*/ + 0x558, /*33*/ + 0x5A9, /*34*/ + 0x5FF, /*35*/ + 0x65A, /*36*/ + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + +/* Winnita ADD 20170828 PathA 0xAB4[10:0],PathB 0xAB4[21:11]*/ +u32 cck_swing_table_ch1_ch14_8192f[CCK_TABLE_SIZE_8192F] = { + 0x0CD, /*0 , -20dB*/ + 0x0D9, + 0x0E6, + 0x0F3, + 0x102, + 0x111, + 0x121, + 0x132, + 0x144, + 0x158, + 0x16C, + 0x182, + 0x198, + 0x1B1, + 0x1CA, + 0x1E5, + 0x202, + 0x221, + 0x241, + 0x263, /*19*/ + 0x287, /*20*/ + 0x2AE, /*21*/ + 0x2D6, /*22*/ + 0x301, /*23*/ + 0x32F, /*24*/ + 0x35F, /*25*/ + 0x392, /*26*/ + 0x3C9, /*27*/ + 0x402, /*28*/ + 0x43F, /*29*/ + 0x47F, /*30*/ + 0x4C3, /*31*/ + 0x50C, /*32*/ + 0x558, /*33*/ + 0x5A9, /*34*/ + 0x5FF, /*35*/ + 0x65A, /*36*/ + 0x6BA, + 0x720, + 0x78C, + 0x7FF, +}; + +u32 tx_scaling_table_jaguar[TXSCALE_TABLE_SIZE] = { + 0x081, /* 0, -12.0dB */ + 0x088, /* 1, -11.5dB */ + 0x090, /* 2, -11.0dB */ + 0x099, /* 3, -10.5dB */ + 0x0A2, /* 4, -10.0dB */ + 0x0AC, /* 5, -9.5dB */ + 0x0B6, /* 6, -9.0dB */ + 0x0C0, /* 7, -8.5dB */ + 0x0CC, /* 8, -8.0dB */ + 0x0D8, /* 9, -7.5dB */ + 0x0E5, /* 10, -7.0dB */ + 0x0F2, /* 11, -6.5dB */ + 0x101, /* 12, -6.0dB */ + 0x110, /* 13, -5.5dB */ + 0x120, /* 14, -5.0dB */ + 0x131, /* 15, -4.5dB */ + 0x143, /* 16, -4.0dB */ + 0x156, /* 17, -3.5dB */ + 0x16A, /* 18, -3.0dB */ + 0x180, /* 19, -2.5dB */ + 0x197, /* 20, -2.0dB */ + 0x1AF, /* 21, -1.5dB */ + 0x1C8, /* 22, -1.0dB */ + 0x1E3, /* 23, -0.5dB */ + 0x200, /* 24, +0 dB */ + 0x21E, /* 25, +0.5dB */ + 0x23E, /* 26, +1.0dB */ + 0x261, /* 27, +1.5dB */ + 0x285, /* 28, +2.0dB */ + 0x2AB, /* 29, +2.5dB */ + 0x2D3, /* 30, +3.0dB */ + 0x2FE, /* 31, +3.5dB */ + 0x32B, /* 32, +4.0dB */ + 0x35C, /* 33, +4.5dB */ + 0x38E, /* 34, +5.0dB */ + 0x3C4, /* 35, +5.5dB */ + 0x3FE /* 36, +6.0dB */ +}; + +void +odm_txpowertracking_init( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + if (!(dm->support_ic_type & (ODM_RTL8814A | ODM_IC_11N_SERIES | ODM_RTL8822B))) + return; +#endif + + odm_txpowertracking_thermal_meter_init(dm); +} + +u8 +get_swing_index( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + void *adapter = dm->adapter; + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + u8 i = 0; + u32 bb_swing, table_value; + + if (dm->support_ic_type == ODM_RTL8188E || dm->support_ic_type == ODM_RTL8723B || + dm->support_ic_type == ODM_RTL8192E || dm->support_ic_type == ODM_RTL8188F || + dm->support_ic_type == ODM_RTL8703B || dm->support_ic_type == ODM_RTL8723D || + dm->support_ic_type == ODM_RTL8192F || dm->support_ic_type == ODM_RTL8710B) { + bb_swing = odm_get_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 0xFFC00000); + + for (i = 0; i < OFDM_TABLE_SIZE; i++) { + table_value = ofdm_swing_table_new[i]; + + if (table_value >= 0x100000) + table_value >>= 22; + if (bb_swing == table_value) + break; + } + } else { + bb_swing = PHY_GetTxBBSwing_8812A(adapter, hal_data->CurrentBandType, RF_PATH_A); + + for (i = 0; i < TXSCALE_TABLE_SIZE; i++) { + table_value = tx_scaling_table_jaguar[i]; + + if (bb_swing == table_value) + break; + } + } + + return i; +} + +u8 +get_cck_swing_index( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + u8 i = 0; + u32 bb_cck_swing; + + if (dm->support_ic_type == ODM_RTL8188E || dm->support_ic_type == ODM_RTL8723B || + dm->support_ic_type == ODM_RTL8192E) { + bb_cck_swing = odm_read_1byte(dm, 0xa22); + + for (i = 0; i < CCK_TABLE_SIZE; i++) { + if (bb_cck_swing == cck_swing_table_ch1_ch13_new[i][0]) + break; + } + } else if (dm->support_ic_type == ODM_RTL8703B) { + bb_cck_swing = odm_read_1byte(dm, 0xa22); + + for (i = 0; i < CCK_TABLE_SIZE_88F; i++) { + if (bb_cck_swing == cck_swing_table_ch1_ch14_88f[i][0]) + break; + } + } + + return i; +} + +s8 +get_txagc_default_index( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + s8 tmp; + + if (dm->support_ic_type == ODM_RTL8814B) { + tmp = (s8)(odm_get_bb_reg(dm, R_0x18a0, 0x7f) & 0xff); + if (tmp & BIT(6)) + tmp = tmp | 0x80; + return tmp; + } else + return 0; +} + +void +odm_txpowertracking_thermal_meter_init( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u8 default_swing_index = get_swing_index(dm); + u8 default_cck_swing_index = get_cck_swing_index(dm); + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct _hal_rf_ *rf = &dm->rf_table; + struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data; + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + void *adapter = dm->adapter; + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + u8 p = 0; + + if (*(dm->mp_mode) == false) + cali_info->txpowertrack_control = true; +#elif (DM_ODM_SUPPORT_TYPE == ODM_CE) +#ifdef CONFIG_RTL8188E + { + cali_info->is_txpowertracking = true; + cali_info->tx_powercount = 0; + cali_info->is_txpowertracking_init = false; + + if (*(dm->mp_mode) == false) + cali_info->txpowertrack_control = true; + + MSG_8192C("dm txpowertrack_control = %d\n", cali_info->txpowertrack_control); + } +#else + { + void *adapter = dm->adapter; + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + struct dm_priv *pdmpriv = &hal_data->dmpriv; + + pdmpriv->is_txpowertracking = true; + pdmpriv->tx_powercount = 0; + pdmpriv->is_txpowertracking_init = false; + + if (*(dm->mp_mode) == false) + pdmpriv->txpowertrack_control = true; + + MSG_8192C("pdmpriv->txpowertrack_control = %d\n", pdmpriv->txpowertrack_control); + + } +#endif +#elif (DM_ODM_SUPPORT_TYPE & (ODM_AP)) +#ifdef RTL8188E_SUPPORT + { + cali_info->is_txpowertracking = true; + cali_info->tx_powercount = 0; + cali_info->is_txpowertracking_init = false; + cali_info->txpowertrack_control = true; + } +#endif +#endif + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) +#if (MP_DRIVER == 1) + cali_info->txpowertrack_control = false; +#else + cali_info->txpowertrack_control = true; +#endif +#else + cali_info->txpowertrack_control = true; +#endif + + cali_info->thermal_value = hal_data->eeprom_thermal_meter; + cali_info->thermal_value_iqk = hal_data->eeprom_thermal_meter; + cali_info->thermal_value_lck = hal_data->eeprom_thermal_meter; + +#if (RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1 || RTL8723F_SUPPORT == 1) + if (dm->support_ic_type == ODM_RTL8822C || + dm->support_ic_type == ODM_RTL8723F) { + cali_info->thermal_value_path[RF_PATH_A] = tssi->thermal[RF_PATH_A]; + cali_info->thermal_value_path[RF_PATH_B] = tssi->thermal[RF_PATH_B]; + cali_info->thermal_value_iqk = tssi->thermal[RF_PATH_A]; + cali_info->thermal_value_lck = tssi->thermal[RF_PATH_A]; + } + + if (dm->support_ic_type == ODM_RTL8814B) { + cali_info->thermal_value_path[RF_PATH_A] = tssi->thermal[RF_PATH_A]; + cali_info->thermal_value_path[RF_PATH_B] = tssi->thermal[RF_PATH_B]; + cali_info->thermal_value_path[RF_PATH_C] = tssi->thermal[RF_PATH_C]; + cali_info->thermal_value_path[RF_PATH_D] = tssi->thermal[RF_PATH_D]; + cali_info->thermal_value_iqk = tssi->thermal[RF_PATH_A]; + cali_info->thermal_value_lck = tssi->thermal[RF_PATH_A]; + } +#endif + + if (cali_info->default_bb_swing_index_flag != true) { + /*The index of "0 dB" in SwingTable.*/ + if (dm->support_ic_type == ODM_RTL8188E || dm->support_ic_type == ODM_RTL8723B || + dm->support_ic_type == ODM_RTL8192E || dm->support_ic_type == ODM_RTL8703B) { + cali_info->default_ofdm_index = (default_swing_index >= OFDM_TABLE_SIZE) ? 30 : default_swing_index; + cali_info->default_cck_index = (default_cck_swing_index >= CCK_TABLE_SIZE) ? 20 : default_cck_swing_index; + } else if (dm->support_ic_type == ODM_RTL8188F) { /*add by Mingzhi.Guo 2015-03-23*/ + cali_info->default_ofdm_index = 28; /*OFDM: -1dB*/ + cali_info->default_cck_index = 20; /*CCK:-6dB*/ + } else if (dm->support_ic_type == ODM_RTL8723D) { /*add by zhaohe 2015-10-27*/ + cali_info->default_ofdm_index = 28; /*OFDM: -1dB*/ + cali_info->default_cck_index = 28; /*CCK: -6dB*/ + /* JJ ADD 20161014 */ + } else if (dm->support_ic_type == ODM_RTL8710B) { + cali_info->default_ofdm_index = 28; /*OFDM: -1dB*/ + cali_info->default_cck_index = 28; /*CCK: -6dB*/ + /*Winnita add 20170828*/ + } else if (dm->support_ic_type == ODM_RTL8192F) { + cali_info->default_ofdm_index = 30; /*OFDM: 0dB*/ + cali_info->default_cck_index = 28; /*CCK: -6dB*/ + } else { + cali_info->default_ofdm_index = (default_swing_index >= TXSCALE_TABLE_SIZE) ? 24 : default_swing_index; + cali_info->default_cck_index = 24; + cali_info->default_txagc_index = get_txagc_default_index(dm); + } + cali_info->default_bb_swing_index_flag = true; + } + + cali_info->bb_swing_idx_cck_base = cali_info->default_cck_index; + cali_info->CCK_index = cali_info->default_cck_index; + + for (p = RF_PATH_A; p < MAX_RF_PATH; ++p) { + cali_info->bb_swing_idx_ofdm_base[p] = cali_info->default_ofdm_index; + cali_info->OFDM_index[p] = cali_info->default_ofdm_index; + cali_info->delta_power_index[p] = 0; + cali_info->delta_power_index_last[p] = 0; + cali_info->power_index_offset[p] = 0; + cali_info->kfree_offset[p] = 0; + } + cali_info->modify_tx_agc_value_ofdm = 0; + cali_info->modify_tx_agc_value_cck = 0; + cali_info->tm_trigger = 0; +} + + +void +odm_txpowertracking_check( + void *dm_void +) +{ + +#if 0 + /* 2011/09/29 MH In HW integration first stage, we provide 4 different handle to operate */ + /* at the same time. In the stage2/3, we need to prive universal interface and merge all */ + /* HW dynamic mechanism. */ +#endif + + struct dm_struct *dm = (struct dm_struct *)dm_void; + switch (dm->support_platform) { + case ODM_WIN: + odm_txpowertracking_check_mp(dm); + break; + + case ODM_CE: + odm_txpowertracking_check_ce(dm); + break; + + case ODM_AP: + odm_txpowertracking_check_ap(dm); + break; + + default: + break; + } + +} + +void +odm_txpowertracking_check_ce( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &(dm->rf_table); +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) + void *adapter = dm->adapter; +#if ((RTL8188F_SUPPORT == 1)) + rtl8192c_odm_check_txpowertracking(adapter); +#endif + +#if (RTL8188E_SUPPORT == 1) + + if (!(rf->rf_supportability & HAL_RF_TX_PWR_TRACK)) + return; + + if (!cali_info->tm_trigger) { + odm_set_rf_reg(dm, RF_PATH_A, RF_T_METER, RFREGOFFSETMASK, 0x60); + /*DBG_8192C("Trigger 92C Thermal Meter!!\n");*/ + + cali_info->tm_trigger = 1; + return; + + } else { + /*DBG_8192C("Schedule TxPowerTracking direct call!!\n");*/ + odm_txpowertracking_callback_thermal_meter_8188e(adapter); + cali_info->tm_trigger = 0; + } +#endif +#endif +} + +void +odm_txpowertracking_check_mp( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + void *adapter = dm->adapter; + + if (*dm->is_fcs_mode_enable) + return; + + if (odm_check_power_status(dm) == false) { + RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD, ("check_pow_status return false\n")); + return; + } + + if (IS_HARDWARE_TYPE_8821B(adapter)) /* TODO: Don't Do PowerTracking*/ + return; + + odm_txpowertracking_thermal_meter_check(adapter); + + +#endif + +} + + +void +odm_txpowertracking_check_ap( + void *dm_void +) +{ + return; + +} + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + +void +odm_txpowertracking_direct_call( + void *adapter +) +{ + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + struct dm_struct *dm = &hal_data->DM_OutSrc; + + if (dm->support_ic_type & ODM_RTL8723F) { +#if (RTL8723F_SUPPORT == 1) + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "[RF]===>%s 8723F TSSI, return!\n", __func__); + return; +#endif + } + if (dm->support_ic_type & (ODM_RTL8822C | ODM_RTL8814B)) { +#if (RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1) + odm_txpowertracking_new_callback_thermal_meter(dm); +#endif + } else + odm_txpowertracking_callback_thermal_meter(adapter); +} + +void +odm_txpowertracking_thermal_meter_check( + void *adapter +) +{ + static u8 tm_trigger = 0; + HAL_DATA_TYPE *pHalData = GET_HAL_DATA(((PADAPTER)adapter)); + struct dm_struct *dm = &(pHalData->DM_OutSrc); + struct _hal_rf_ *rf = &(dm->rf_table); + struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data; + + if (!(rf->rf_supportability & HAL_RF_TX_PWR_TRACK)) { + RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD, + ("===>odm_txpowertracking_thermal_meter_check(),mgnt_info->is_txpowertracking is false, return!!\n")); + return; + } + + if (!tm_trigger) { + if (IS_HARDWARE_TYPE_8188E(adapter) || IS_HARDWARE_TYPE_JAGUAR(adapter) || IS_HARDWARE_TYPE_8192E(adapter) || IS_HARDWARE_TYPE_8192F(adapter) + ||IS_HARDWARE_TYPE_8723B(adapter) || IS_HARDWARE_TYPE_8814A(adapter) || IS_HARDWARE_TYPE_8188F(adapter) || IS_HARDWARE_TYPE_8703B(adapter) + || IS_HARDWARE_TYPE_8822B(adapter) || IS_HARDWARE_TYPE_8723D(adapter) || IS_HARDWARE_TYPE_8821C(adapter) || IS_HARDWARE_TYPE_8710B(adapter) + )/* JJ ADD 20161014 */ + PHY_SetRFReg(adapter, RF_PATH_A, RF_T_METER_88E, BIT(17) | BIT(16), 0x03); + else if (IS_HARDWARE_TYPE_8822C(adapter)) { + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x01); + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x00); + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x01); + + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x01); + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x00); + odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x01); + } else if (IS_HARDWARE_TYPE_8814B(adapter)) { + odm_set_rf_reg(dm, RF_PATH_A, 0x42, BIT(17), 0x1); + odm_set_rf_reg(dm, RF_PATH_B, 0x42, BIT(17), 0x1); + odm_set_rf_reg(dm, RF_PATH_C, 0x42, BIT(17), 0x1); + odm_set_rf_reg(dm, RF_PATH_D, 0x42, BIT(17), 0x1); + } else if (IS_HARDWARE_TYPE_8723F(adapter)) { + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(16), 0x01); + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(16), 0x00); + odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(16), 0x01); + } + else + PHY_SetRFReg(adapter, RF_PATH_A, RF_T_METER, RFREGOFFSETMASK, 0x60); + + if (dm->support_ic_type & ODM_RTL8814B) { + ODM_delay_us(300); + odm_txpowertracking_direct_call(adapter); + tssi->thermal_trigger = 1; + } + + RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD, ("Trigger Thermal Meter!!\n")); + + tm_trigger = 1; + return; + } else { + RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD, ("Schedule TxPowerTracking direct call!!\n")); + odm_txpowertracking_direct_call(adapter); + + if (dm->support_ic_type & ODM_RTL8814B) + tssi->thermal_trigger = 0; + + tm_trigger = 0; + } +} + +#endif diff --git a/hal/phydm/halrf/halrf_powertracking_win.h b/hal/phydm/halrf/halrf_powertracking_win.h new file mode 100644 index 0000000..f84d440 --- /dev/null +++ b/hal/phydm/halrf/halrf_powertracking_win.h @@ -0,0 +1,306 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#ifndef __HALRF_POWERTRACKING_H__ +#define __HALRF_POWERTRACKING_H__ + +#define DPK_DELTA_MAPPING_NUM 13 +#define index_mapping_HP_NUM 15 +#define TXSCALE_TABLE_SIZE 37 +#define OFDM_TABLE_SIZE 43 +#define CCK_TABLE_SIZE 33 +#define CCK_TABLE_SIZE_8723D 41 +#define TXPWR_TRACK_TABLE_SIZE 30 +#define DELTA_SWINGIDX_SIZE 30 +#define DELTA_SWINTSSI_SIZE 61 +#define BAND_NUM 3 +#define MAX_RF_PATH 4 +#define CCK_TABLE_SIZE_88F 21 +/* JJ ADD 20161014 */ +#define CCK_TABLE_SIZE_8710B 41 +#define CCK_TABLE_SIZE_8192F 41 + + +#define dm_check_txpowertracking odm_txpowertracking_check + +#define IQK_MATRIX_SETTINGS_NUM (14+24+21) /* Channels_2_4G_NUM + Channels_5G_20M_NUM + Channels_5G */ +#define AVG_THERMAL_NUM 8 +#define iqk_matrix_reg_num 8 +#define IQK_MAC_REG_NUM 4 +#define IQK_ADDA_REG_NUM 16 + +#define IQK_BB_REG_NUM 9 + + +extern u32 ofdm_swing_table[OFDM_TABLE_SIZE]; +extern u8 cck_swing_table_ch1_ch13[CCK_TABLE_SIZE][8]; +extern u8 cck_swing_table_ch14[CCK_TABLE_SIZE][8]; + +extern u32 ofdm_swing_table_new[OFDM_TABLE_SIZE]; +extern u8 cck_swing_table_ch1_ch13_new[CCK_TABLE_SIZE][8]; +extern u8 cck_swing_table_ch14_new[CCK_TABLE_SIZE][8]; +extern u8 cck_swing_table_ch1_ch14_88f[CCK_TABLE_SIZE_88F][16]; +extern u8 cck_swing_table_ch1_ch13_88f[CCK_TABLE_SIZE_88F][16]; +extern u8 cck_swing_table_ch14_88f[CCK_TABLE_SIZE_88F][16]; +extern u32 cck_swing_table_ch1_ch14_8723d[CCK_TABLE_SIZE_8723D]; +/* JJ ADD 20161014 */ +extern u32 cck_swing_table_ch1_ch14_8710b[CCK_TABLE_SIZE_8710B]; +extern u32 cck_swing_table_ch1_ch14_8192f[CCK_TABLE_SIZE_8192F]; + +extern u32 tx_scaling_table_jaguar[TXSCALE_TABLE_SIZE]; + +/* <20121018, Kordan> In case fail to read TxPowerTrack.txt, we use the table of 88E as the default table. */ +static u8 delta_swing_table_idx_2ga_p_8188e[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9}; +static u8 delta_swing_table_idx_2ga_n_8188e[] = {0, 0, 0, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11}; + +void +odm_txpowertracking_check( + void *dm_void +); + +void +odm_txpowertracking_check_ap( + void *dm_void +); + +void +odm_txpowertracking_thermal_meter_init( + void *dm_void +); + +void +odm_txpowertracking_init( + void *dm_void +); + +void +odm_txpowertracking_check_mp( + void *dm_void +); + + +void +odm_txpowertracking_check_ce( + void *dm_void +); + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN)) + + +void +odm_txpowertracking_thermal_meter_check( + void *adapter +); + +#endif + +struct iqk_matrix_regs_setting { + boolean is_iqk_done; + s32 value[3][iqk_matrix_reg_num]; + boolean is_bw_iqk_result_saved[3]; +}; + +struct dm_rf_calibration_struct { + /* for tx power tracking */ + + u32 rega24; /* for TempCCK */ + s32 rege94; + s32 rege9c; + s32 regeb4; + s32 regebc; + /* u8 is_txpowertracking; */ + u8 tx_powercount; + boolean is_txpowertracking_init; + boolean is_txpowertracking; + u8 txpowertrack_control; /* for mp mode, turn off txpwrtracking as default */ + u8 tm_trigger; + u8 internal_pa_5g[2]; /* pathA / pathB */ + + u8 thermal_meter[2]; /* thermal_meter, index 0 for RFIC0, and 1 for RFIC1 */ + u8 thermal_value; + u8 thermal_value_path[MAX_RF_PATH]; + u8 thermal_value_lck; + u8 thermal_value_iqk; + u8 thermal_value_dpk; + s8 thermal_value_delta; /* delta of thermal_value and efuse thermal */ + u8 thermal_value_avg[AVG_THERMAL_NUM]; + u8 thermal_value_avg_path[MAX_RF_PATH][AVG_THERMAL_NUM]; + u8 thermal_value_avg_index; + u8 thermal_value_avg_index_path[MAX_RF_PATH]; + u8 thermal_value_rx_gain; + + + boolean is_reloadtxpowerindex; + u8 is_rf_pi_enable; + u32 txpowertracking_callback_cnt; /* cosa add for debug */ + + + /* ------------------------- Tx power Tracking ------------------------- */ + u8 is_cck_in_ch14; + u8 CCK_index; + u8 OFDM_index[MAX_RF_PATH]; + s8 power_index_offset[MAX_RF_PATH]; + s8 delta_power_index[MAX_RF_PATH]; + s8 delta_power_index_last[MAX_RF_PATH]; + boolean is_tx_power_changed; + s8 xtal_offset; + s8 xtal_offset_last; + + struct iqk_matrix_regs_setting iqk_matrix_reg_setting[IQK_MATRIX_SETTINGS_NUM]; + u8 delta_lck; + s8 bb_swing_diff_2g, bb_swing_diff_5g; /* Unit: dB */ + u8 delta_swing_table_idx_2g_cck_a_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_a_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_b_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_b_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_c_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_c_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_d_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2g_cck_d_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gb_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gb_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gc_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gc_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gd_p[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2gd_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5ga_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5ga_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gb_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gb_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gc_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gc_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gd_p[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_5gd_n[BAND_NUM][DELTA_SWINGIDX_SIZE]; + u8 delta_swing_tssi_table_2g_cck_a[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_b[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_c[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2g_cck_d[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2ga[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gb[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gc[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_2gd[DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5ga[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gb[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gc[BAND_NUM][DELTA_SWINTSSI_SIZE]; + u8 delta_swing_tssi_table_5gd[BAND_NUM][DELTA_SWINTSSI_SIZE]; + s8 delta_swing_table_xtal_p[DELTA_SWINGIDX_SIZE]; + s8 delta_swing_table_xtal_n[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_p_8188e[DELTA_SWINGIDX_SIZE]; + u8 delta_swing_table_idx_2ga_n_8188e[DELTA_SWINGIDX_SIZE]; + + u8 bb_swing_idx_ofdm[MAX_RF_PATH]; + u8 bb_swing_idx_ofdm_current; +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + u8 bb_swing_idx_ofdm_base[MAX_RF_PATH]; +#else + u8 bb_swing_idx_ofdm_base; +#endif + boolean default_bb_swing_index_flag; + boolean bb_swing_flag_ofdm; + u8 bb_swing_idx_cck; + u8 bb_swing_idx_cck_current; + u8 bb_swing_idx_cck_base; + u8 default_ofdm_index; + u8 default_cck_index; + s8 default_txagc_index; + boolean bb_swing_flag_cck; + + s8 absolute_ofdm_swing_idx[MAX_RF_PATH]; + s8 remnant_ofdm_swing_idx[MAX_RF_PATH]; + s8 absolute_cck_swing_idx[MAX_RF_PATH]; + s8 remnant_cck_swing_idx; + s8 modify_tx_agc_value; /*Remnat compensate value at tx_agc */ + boolean modify_tx_agc_flag_path_a; + boolean modify_tx_agc_flag_path_b; + boolean modify_tx_agc_flag_path_c; + boolean modify_tx_agc_flag_path_d; + boolean modify_tx_agc_flag_path_a_cck; + boolean modify_tx_agc_flag_path_b_cck; + + s8 kfree_offset[MAX_RF_PATH]; + + /* -------------------------------------------------------------------- */ + + /* for IQK */ + u32 regc04; + u32 reg874; + u32 regc08; + u32 regb68; + u32 regb6c; + u32 reg870; + u32 reg860; + u32 reg864; + + boolean is_iqk_initialized; + boolean is_lck_in_progress; + boolean is_antenna_detected; + boolean is_need_iqk; + boolean is_iqk_in_progress; + boolean is_iqk_pa_off; + u8 delta_iqk; + u32 ADDA_backup[IQK_ADDA_REG_NUM]; + u32 IQK_MAC_backup[IQK_MAC_REG_NUM]; + u32 IQK_BB_backup_recover[9]; + u32 IQK_BB_backup[IQK_BB_REG_NUM]; + u32 tx_iqc_8723b[2][3][2]; /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}} */ + u32 rx_iqc_8723b[2][2][2]; /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}} */ + u32 tx_iqc_8703b[3][2]; /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}}*/ + u32 rx_iqc_8703b[2][2]; /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}}*/ + u32 tx_iqc_8723d[2][3][2]; /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}}*/ + u32 rx_iqc_8723d[2][2][2]; /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}}*/ + /* JJ ADD 20161014 */ + u32 tx_iqc_8710b[2][3][2]; /* { {S1: 0xc94, 0xc80, 0xc4c} , {S0: 0xc9c, 0xc88, 0xc4c}}*/ + u32 rx_iqc_8710b[2][2][2]; /* { {S1: 0xc14, 0xca0} , {S0: 0xc14, 0xca0}}*/ + + u64 iqk_start_time; + u64 iqk_total_progressing_time; + u64 iqk_progressing_time; + u64 lck_progressing_time; + u32 lok_result; + u8 iqk_step; + u8 kcount; + u8 retry_count[4][2]; /* [4]: path ABCD, [2] TXK, RXK */ + boolean is_mp_mode; + + /* for APK */ + u32 ap_koutput[2][2]; /* path A/B; output1_1a/output1_2a */ + u8 is_ap_kdone; + u8 is_apk_thermal_meter_ignore; + + /* DPK */ + boolean is_dpk_fail; + u8 is_dp_done; + u8 is_dp_path_aok; + u8 is_dp_path_bok; + + u32 tx_lok[2]; + u32 dpk_tx_agc; + s32 dpk_gain; + u32 dpk_thermal[4]; + + s8 modify_tx_agc_value_ofdm; + s8 modify_tx_agc_value_cck; + + /*Add by Yuchen for Kfree Phydm*/ + u8 reg_rf_kfree_enable; /*for registry*/ + u8 rf_kfree_enable; /*for efuse enable check*/ +}; + + + + +#endif /*#ifndef __HALRF_POWER_TRACKING_H__*/ diff --git a/hal/phydm/halrf/halrf_psd.c b/hal/phydm/halrf/halrf_psd.c new file mode 100644 index 0000000..445c910 --- /dev/null +++ b/hal/phydm/halrf/halrf_psd.c @@ -0,0 +1,647 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +/*@=========================================================== + * include files + *============================================================ + */ +#include "mp_precomp.h" +#include "phydm_precomp.h" + +u64 _sqrt(u64 x) +{ + u64 i = 0; + u64 j = (x >> 1) + 1; + + while (i <= j) { + u64 mid = (i + j) >> 1; + + u64 sq = mid * mid; + + if (sq == x) + return mid; + else if (sq < x) + i = mid + 1; + else + j = mid - 1; + } + + return j; +} + +u32 halrf_get_psd_data( + struct dm_struct *dm, + u32 point) +{ + struct _hal_rf_ *rf = &(dm->rf_table); + struct _halrf_psd_data *psd = &(rf->halrf_psd_data); + u32 psd_val = 0, psd_reg, psd_report, psd_point, psd_start, i, delay_time = 0; + +#if (DEV_BUS_TYPE == RT_USB_INTERFACE) || (DEV_BUS_TYPE == RT_SDIO_INTERFACE) + if (dm->support_interface == ODM_ITRF_USB || dm->support_interface == ODM_ITRF_SDIO) { + if (psd->average == 0) + delay_time = 100; + else + delay_time = 0; + } +#endif +#if (DEV_BUS_TYPE == RT_PCI_INTERFACE) + if (dm->support_interface == ODM_ITRF_PCIE) { + if (psd->average == 0) + delay_time = 1000; + else + delay_time = 100; + } +#endif + + if (dm->support_ic_type & (ODM_RTL8812 | ODM_RTL8821 | ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8821C)) { + psd_reg = R_0x910; + psd_report = R_0xf44; + } else { + psd_reg = R_0x808; + psd_report = R_0x8b4; + } + + if (dm->support_ic_type & ODM_RTL8710B) { + psd_point = 0xeffffc00; + psd_start = 0x10000000; + } else { + psd_point = 0xffbffc00; + psd_start = 0x00400000; + } + + psd_val = odm_get_bb_reg(dm, psd_reg, MASKDWORD); + + psd_val &= psd_point; + psd_val |= point; + + odm_set_bb_reg(dm, psd_reg, MASKDWORD, psd_val); + + psd_val |= psd_start; + + odm_set_bb_reg(dm, psd_reg, MASKDWORD, psd_val); + + for (i = 0; i < delay_time; i++) + ODM_delay_us(1); + + psd_val = odm_get_bb_reg(dm, psd_report, MASKDWORD); + + if (dm->support_ic_type & (ODM_RTL8821C | ODM_RTL8710B)) { + psd_val &= MASKL3BYTES; + psd_val = psd_val / 32; + } else { + psd_val &= MASKLWORD; + } + + return psd_val; +} + +void halrf_psd( + struct dm_struct *dm, + u32 point, + u32 start_point, + u32 stop_point, + u32 average) +{ + struct _hal_rf_ *rf = &(dm->rf_table); + struct _halrf_psd_data *psd = &(rf->halrf_psd_data); + + u32 i = 0, j = 0, k = 0; + u32 psd_reg, avg_org, point_temp, average_tmp, mode; + u64 data_tatal = 0, data_temp[64] = {0}; + + psd->buf_size = 256; + + mode = average >> 16; + + if (mode == 2) + average_tmp = 1; + else + average_tmp = average & 0xffff; + + if (dm->support_ic_type & (ODM_RTL8812 | ODM_RTL8821 | ODM_RTL8814A | ODM_RTL8822B | ODM_RTL8821C)) + psd_reg = R_0x910; + else + psd_reg = R_0x808; + +#if 0 + dbg_print("[PSD]point=%d, start_point=%d, stop_point=%d, average=%d, average_tmp=%d, buf_size=%d\n", + point, start_point, stop_point, average, average_tmp, psd->buf_size); +#endif + + for (i = 0; i < psd->buf_size; i++) + psd->psd_data[i] = 0; + + if (dm->support_ic_type & ODM_RTL8710B) + avg_org = odm_get_bb_reg(dm, psd_reg, 0x30000); + else + avg_org = odm_get_bb_reg(dm, psd_reg, 0x3000); + + if (mode == 1) { + if (dm->support_ic_type & ODM_RTL8710B) + odm_set_bb_reg(dm, psd_reg, 0x30000, 0x1); + else + odm_set_bb_reg(dm, psd_reg, 0x3000, 0x1); + } + +#if 0 + if (avg_temp == 0) + avg = 1; + else if (avg_temp == 1) + avg = 8; + else if (avg_temp == 2) + avg = 16; + else if (avg_temp == 3) + avg = 32; +#endif + + i = start_point; + while (i < stop_point) { + data_tatal = 0; + + if (i >= point) + point_temp = i - point; + else + point_temp = i; + + for (k = 0; k < average_tmp; k++) { + data_temp[k] = halrf_get_psd_data(dm, point_temp); + data_tatal = data_tatal + (data_temp[k] * data_temp[k]); + +#if 0 + if ((k % 20) == 0) + dbg_print("\n "); + + dbg_print("0x%x ", data_temp[k]); +#endif + } +#if 0 + /*dbg_print("\n");*/ +#endif + + data_tatal = phydm_division64((data_tatal * 100), average_tmp); + psd->psd_data[j] = (u32)_sqrt(data_tatal); + + i++; + j++; + } + +#if 0 + for (i = 0; i < psd->buf_size; i++) { + if ((i % 20) == 0) + dbg_print("\n "); + + dbg_print("0x%x ", psd->psd_data[i]); + } + dbg_print("\n\n"); +#endif + + if (dm->support_ic_type & ODM_RTL8710B) + odm_set_bb_reg(dm, psd_reg, 0x30000, avg_org); + else + odm_set_bb_reg(dm, psd_reg, 0x3000, avg_org); +} + +void backup_bb_register(struct dm_struct *dm, u32 *bb_backup, u32 *backup_bb_reg, u32 counter) +{ + u32 i ; + + for (i = 0; i < counter; i++) + bb_backup[i] = odm_get_bb_reg(dm, backup_bb_reg[i], MASKDWORD); +} + +void restore_bb_register(struct dm_struct *dm, u32 *bb_backup, u32 *backup_bb_reg, u32 counter) +{ + u32 i ; + + for (i = 0; i < counter; i++) + odm_set_bb_reg(dm, backup_bb_reg[i], MASKDWORD, bb_backup[i]); +} + + + +void _halrf_psd_iqk_init(struct dm_struct *dm) +{ + odm_set_bb_reg(dm, 0x1b04, MASKDWORD, 0x0); + odm_set_bb_reg(dm, 0x1b08, MASKDWORD, 0x80); + odm_set_bb_reg(dm, 0x1b0c, 0xc00, 0x3); + odm_set_bb_reg(dm, 0x1b14, MASKDWORD, 0x0); + odm_set_bb_reg(dm, 0x1b18, BIT(0), 0x1); + + if (dm->support_ic_type & ODM_RTL8197G) + odm_set_bb_reg(dm, 0x1b20, MASKDWORD, 0x00040008); + if (dm->support_ic_type & ODM_RTL8198F) + odm_set_bb_reg(dm, 0x1b20, MASKDWORD, 0x00000000); + + if (dm->support_ic_type & (ODM_RTL8197G | ODM_RTL8198F)) { + odm_set_bb_reg(dm, 0x1b24, MASKDWORD, 0x00030000); + odm_set_bb_reg(dm, 0x1b28, MASKDWORD, 0x00000000); + odm_set_bb_reg(dm, 0x1b2c, MASKDWORD, 0x00180018); + odm_set_bb_reg(dm, 0x1b30, MASKDWORD, 0x20000000); + /*odm_set_bb_reg(dm, 0x1b38, MASKDWORD, 0x20000000);*/ + /*odm_set_bb_reg(dm, 0x1b3c, MASKDWORD, 0x20000000);*/ + } + + odm_set_bb_reg(dm, 0x1b1c, 0xfff, 0xd21); + odm_set_bb_reg(dm, 0x1b1c, 0xfff00000, 0x821); + odm_set_bb_reg(dm, 0x1b28, MASKDWORD, 0x0); + odm_set_bb_reg(dm, 0x1bcc, 0x3f, 0x3f); +} + +void _halrf_iqk_psd_init_8723f(void *dm_void, boolean onoff) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + u8 s; + + s = (u8)odm_get_bb_reg(dm, 0x1884, BIT(20)); + + if (onoff) { + /*01_8723F_AFE_ON_BB_settings.txt*/ + odm_set_bb_reg(dm, 0x1c38, MASKDWORD, 0x0); + odm_set_bb_reg(dm, R_0x1830, BIT(30), 0x0); + odm_set_bb_reg(dm, R_0x1860, 0xF0000000, 0xf); + odm_set_bb_reg(dm, R_0x1860, 0x0FFFF000, 0x0041); + odm_set_bb_reg(dm, 0x09f0, 0x0000FFFF, 0xbbbb); + odm_set_bb_reg(dm, 0x1d40, BIT(3), 0x1); + odm_set_bb_reg(dm, 0x1d40, 0x00000007, 0x3); + odm_set_bb_reg(dm, 0x09b4, 0x00000700, 0x3); + odm_set_bb_reg(dm, 0x09b4, 0x00003800, 0x3); + odm_set_bb_reg(dm, 0x09b4, 0x0001C000, 0x3); + odm_set_bb_reg(dm, 0x09b4, 0x000E0000, 0x3); + odm_set_bb_reg(dm, R_0x1c20, BIT(5), 0x1); + odm_set_bb_reg(dm, R_0x1e24, BIT(31), 0x0); + odm_set_bb_reg(dm, R_0x1e28, 0x0000000F, 0x1); + odm_set_bb_reg(dm, R_0x824, 0x000F0000, 0x1); + odm_set_bb_reg(dm, R_0x1cd0, 0xF0000000, 0x7); + odm_set_bb_reg(dm, R_0x2a24, BIT(13), 0x1); + odm_set_bb_reg(dm, R_0x1c68, BIT(24), 0x1); + odm_set_bb_reg(dm, R_0x1864, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0x180c, BIT(27), 0x1); + odm_set_bb_reg(dm, R_0x180c, BIT(30), 0x1); + odm_set_bb_reg(dm, R_0x1e24, BIT(17), 0x1); + odm_set_bb_reg(dm, R_0x1880, BIT(21), 0x0); + odm_set_bb_reg(dm, R_0x1c38, MASKDWORD, 0xffffffff); + /*02_IQK_Preset.txt*/ + //odm_set_rf_reg(dm, RF_PATH_A, 0x05, BIT(0), 0x0); + //odm_set_rf_reg(dm, RF_PATH_B, 0x05, BIT(0), 0x0); + odm_set_bb_reg(dm, R_0x1b08, MASKDWORD, 0x00000080); + //odm_set_bb_reg(dm, R_0x1bd8, MASKDWORD, 0x00000002); + //switch path 10 od 0x1b38 0x1/0x3 [1:0] + if (s == 0) + odm_set_bb_reg(dm, R_0x1b00, MASKDWORD, 0x00000008); + else + odm_set_bb_reg(dm, R_0x1b00, MASKDWORD, 0x0000000a); + + odm_set_bb_reg(dm, R_0x1b18, MASKDWORD, 0x40010101); + odm_set_bb_reg(dm, R_0x1b14, MASKDWORD, 0x40010100); + //odm_set_bb_reg(dm, R_0x1b1c, MASKDWORD, 0xA2103C00); + odm_set_bb_reg(dm, R_0x1b0c, 0x00000C00, 0x2); + odm_set_bb_reg(dm, R_0x1bcc, 0x0000003F, 0x3f); + //DbgPrint("[PSD][8723F]iqkpsd init!\n"); + } else { + /*10_IQK_Reg_PSD_Restore.txt*/ + //odm_set_bb_reg(dm, R_0x1b1c, MASKDWORD, 0xA2103C00); + odm_set_bb_reg(dm, R_0x1b08, MASKDWORD, 0x00000000); + odm_set_bb_reg(dm, R_0x1b38, BIT(0), 0x0); + odm_set_bb_reg(dm, R_0x1bcc, 0x0000003F, 0x0); + //odm_set_rf_reg(dm, RF_PATH_A, 0x05, BIT(0), 0x1); + //odm_set_rf_reg(dm, RF_PATH_B, 0x05, BIT(0), 0x1); + /*11_8723F_restore_AFE_BB_settings.txt*/ + odm_set_bb_reg(dm, 0x1c38, MASKDWORD, 0x0); + odm_set_bb_reg(dm, R_0x1830, BIT(30), 0x1); + odm_set_bb_reg(dm, R_0x1e24, BIT(31), 0x1); + odm_set_bb_reg(dm, R_0x2a24, BIT(13), 0x0); + odm_set_bb_reg(dm, R_0x1c68, BIT(24), 0x0); + odm_set_bb_reg(dm, R_0x1864, BIT(31), 0x0); + odm_set_bb_reg(dm, R_0x180c, BIT(27), 0x0); + odm_set_bb_reg(dm, R_0x180c, BIT(30), 0x0); + odm_set_bb_reg(dm, R_0x1880, BIT(21), 0x0); + odm_set_bb_reg(dm, R_0x1c38, MASKDWORD, 0xffa1005e); + //DbgPrint("[PSD][8723F]iqkpsd resotre!\n"); + } +} + +u64 halrf_get_iqk_psd_data(void *dm_void, u32 point) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &(dm->rf_table); + struct _halrf_psd_data *psd = &(rf->halrf_psd_data); + u64 psd_val, psd_val1, psd_val2; + u32 psd_point, i, delay_time = 0; + +#if (DEV_BUS_TYPE == RT_USB_INTERFACE) || (DEV_BUS_TYPE == RT_SDIO_INTERFACE) + if (dm->support_interface == ODM_ITRF_USB || dm->support_interface == ODM_ITRF_SDIO) { + if (dm->support_ic_type & ODM_RTL8822C) + delay_time = 1000; + else if (dm->support_ic_type & ODM_RTL8723F) + delay_time = 1000; + else + delay_time = 0; + } +#endif +#if (DEV_BUS_TYPE == RT_PCI_INTERFACE) + if (dm->support_interface == ODM_ITRF_PCIE) { + if (dm->support_ic_type & ODM_RTL8822C) + delay_time = 1000; + else + delay_time = 150; + } +#endif + psd_point = odm_get_bb_reg(dm, R_0x1b2c, MASKDWORD); + + psd_point &= 0xF000FFFF; + + point &= 0xFFF; + + psd_point = psd_point | (point << 16); + + odm_set_bb_reg(dm, R_0x1b2c, MASKDWORD, psd_point); + + odm_set_bb_reg(dm, R_0x1b34, BIT(0), 0x1); + + odm_set_bb_reg(dm, R_0x1b34, BIT(0), 0x0); + + for (i = 0; i < delay_time; i++) + ODM_delay_us(1); + + if (dm->support_ic_type & (ODM_RTL8197G | ODM_RTL8198F)) { + if (dm->support_ic_type & ODM_RTL8197G) + odm_set_bb_reg(dm, R_0x1bd4, MASKDWORD, 0x001a0001); + else + odm_set_bb_reg(dm, R_0x1bd4, MASKDWORD, 0x00250001); + + psd_val1 = odm_get_bb_reg(dm, R_0x1bfc, MASKDWORD); + + psd_val1 = (psd_val1 & 0x001f0000) >> 16; + + if (dm->support_ic_type & ODM_RTL8197G) + odm_set_bb_reg(dm, R_0x1bd4, MASKDWORD, 0x001b0001); + else + odm_set_bb_reg(dm, R_0x1bd4, MASKDWORD, 0x002e0001); + + psd_val2 = odm_get_bb_reg(dm, R_0x1bfc, MASKDWORD); + + psd_val = (psd_val1 << 27) + (psd_val2 >> 5); + } else if (dm->support_ic_type & ODM_RTL8723F) { + odm_set_bb_reg(dm, R_0x1bd4, MASKDWORD, 0x00210001); + psd_val1 = odm_get_bb_reg(dm, R_0x1bfc, MASKDWORD); + psd_val1 = (psd_val1 & 0x00FF0000) >> 16; + odm_set_bb_reg(dm, R_0x1bd4, MASKDWORD, 0x00220001); + psd_val2 = odm_get_bb_reg(dm, R_0x1bfc, MASKDWORD); + //psd_val = (psd_val1 << 27) + (psd_val2 >> 5); + psd_val = (psd_val1 << 32) + psd_val2; + } else { + odm_set_bb_reg(dm, R_0x1bd4, MASKDWORD, 0x00250001); + + psd_val1 = odm_get_bb_reg(dm, R_0x1bfc, MASKDWORD); + + psd_val1 = (psd_val1 & 0x07FF0000) >> 16; + + odm_set_bb_reg(dm, R_0x1bd4, MASKDWORD, 0x002e0001); + + psd_val2 = odm_get_bb_reg(dm, R_0x1bfc, MASKDWORD); + + psd_val = (psd_val1 << 21) + (psd_val2 >> 11); + } + + return psd_val; +} + +void halrf_iqk_psd( + struct dm_struct *dm, + u32 point, + u32 start_point, + u32 stop_point, + u32 average) +{ + struct _hal_rf_ *rf = &(dm->rf_table); + struct _halrf_psd_data *psd = &(rf->halrf_psd_data); + + u32 i = 0, j = 0, k = 0; + u32 psd_reg, avg_org, point_temp, average_tmp = 32, mode, reg_tmp = 5; + u64 data_tatal = 0, data_temp[64] = {0}; + s32 s_point_tmp; + + psd->buf_size = 256; + + mode = average >> 16; + + if (mode == 2) { + if (dm->support_ic_type & (ODM_RTL8822C | ODM_RTL8723F)) + average_tmp = 1; //HW average + else { + reg_tmp = odm_get_bb_reg(dm, R_0x1b1c, 0x000e0000); + if (reg_tmp == 0) + average_tmp = 1; + else if (reg_tmp == 3) + average_tmp = 8; + else if (reg_tmp == 4) + average_tmp = 16; + else if (reg_tmp == 5) + average_tmp = 32; + odm_set_bb_reg(dm, R_0x1b1c, 0x000e0000, 0x0); + } + } else { + reg_tmp = odm_get_bb_reg(dm, R_0x1b1c, 0x000e0000); + if (reg_tmp == 0) + average_tmp = 1; + else if (reg_tmp == 3) + average_tmp = 8; + else if (reg_tmp == 4) + average_tmp = 16; + else if (reg_tmp == 5) + average_tmp = 32; +#ifndef RTL8723F_SUPPORT + odm_set_bb_reg(dm, R_0x1b1c, 0x000e0000, 0x0); +#endif + } + +#if 0 + DbgPrint("[PSD]point=%d, start_point=%d, stop_point=%d, average=0x%x, average_tmp=%d, buf_size=%d, mode=%d\n", + point, start_point, stop_point, average, average_tmp, psd->buf_size, mode); +#endif + + for (i = 0; i < psd->buf_size; i++) + psd->psd_data[i] = 0; + + i = start_point; + +#ifndef RTL8723F_SUPPORT + while (i < stop_point) { + data_tatal = 0; + + if (i >= point) + point_temp = i - point; + else + { + if (dm->support_ic_type & ODM_RTL8814B) + { + s_point_tmp = i - point - 1; + point_temp = s_point_tmp & 0xfff; + } + else + point_temp = i; + } + + for (k = 0; k < average_tmp; k++) { + data_temp[k] = halrf_get_iqk_psd_data(dm, point_temp); + /*data_tatal = data_tatal + (data_temp[k] * data_temp[k]);*/ + data_tatal = data_tatal + data_temp[k]; + +#if 0 + if ((k % 20) == 0) + DbgPrint("\n "); + + DbgPrint("0x%x ", data_temp[k]); +#endif + } + + data_tatal = phydm_division64((data_tatal * 10), average_tmp); + psd->psd_data[j] = (u32)data_tatal; + + i++; + j++; + } + + if (dm->support_ic_type & (ODM_RTL8814B | ODM_RTL8198F | ODM_RTL8197G)) + odm_set_bb_reg(dm, R_0x1b1c, 0x000e0000, reg_tmp); +#else + while (i < stop_point) { + data_tatal = 0; + + if (i >= point) + point_temp = i - point; + else + point_temp = i + 0xB00; + //-640:0xD80,640:0x280,0x280+0xB00 =0xD80 + //point_temp = i + 0xC00; + //-512:0xE00,512:0x200,0x200+0xC00 = 0xE00 + + data_temp[k] = halrf_get_iqk_psd_data(dm, point_temp); + data_tatal = data_temp[k]; + psd->psd_data[j] = (u32)data_tatal; + i++; + j++; + } + +#endif +#if 0 + DbgPrint("\n [iqk psd]psd result:\n"); + + for (i = 0; i < psd->buf_size; i++) { + if ((i % 20) == 0) + DbgPrint("\n "); + + DbgPrint("0x%x ", psd->psd_data[i]); + } + DbgPrint("\n\n"); +#endif +} + + +u32 +halrf_psd_init( + void *dm_void) +{ + enum rt_status ret_status = RT_STATUS_SUCCESS; + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &(dm->rf_table); + struct _halrf_psd_data *psd = &(rf->halrf_psd_data); +#ifndef RTL8723F_SUPPORT +#if 0 + u32 bb_backup[12]; + u32 backup_bb_reg[12] = {0x1b04, 0x1b08, 0x1b0c, 0x1b14, 0x1b18, + 0x1b1c, 0x1b28, 0x1bcc, 0x1b2c, 0x1b34, + 0x1bd4, 0x1bfc}; +#endif +#else + u32 bb_backup[11]; + u32 backup_bb_reg[11] = {0x09f0, 0x09b4, 0x1c38, 0x1860, 0x1cd0, + 0x824, 0x2a24, 0x1d40, 0x1c20, 0x1880, 0x180c}; +#endif + if (psd->psd_progress) { + ret_status = RT_STATUS_PENDING; + } else { + psd->psd_progress = 1; + if (dm->support_ic_type & ODM_RTL8723F) { + backup_bb_register(dm, bb_backup, backup_bb_reg, 11); + _halrf_iqk_psd_init_8723f(dm, true); + halrf_iqk_psd(dm, psd->point, psd->start_point, psd->stop_point, psd->average); + _halrf_iqk_psd_init_8723f(dm, false); + restore_bb_register(dm, bb_backup, backup_bb_reg, 11); + } else if (dm->support_ic_type & + (ODM_RTL8822C | ODM_RTL8814B | ODM_RTL8198F | ODM_RTL8197G)) { + /*backup_bb_register(dm, bb_backup, backup_bb_reg, 12);*/ + _halrf_psd_iqk_init(dm); + halrf_iqk_psd(dm, psd->point, psd->start_point, psd->stop_point, psd->average); + /*restore_bb_register(dm, bb_backup, backup_bb_reg, 12);*/ + } else + halrf_psd(dm, psd->point, psd->start_point, psd->stop_point, psd->average); + psd->psd_progress = 0; + } + return ret_status; +} + +u32 +halrf_psd_query( + void *dm_void, + u32 *outbuf, + u32 buf_size) +{ + enum rt_status ret_status = RT_STATUS_SUCCESS; + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &(dm->rf_table); + struct _halrf_psd_data *psd = &(rf->halrf_psd_data); + + if (psd->psd_progress) + ret_status = RT_STATUS_PENDING; + else + odm_move_memory(dm, outbuf, psd->psd_data, + sizeof(u32) * psd->buf_size); + + return ret_status; +} + +u32 +halrf_psd_init_query( + void *dm_void, + u32 *outbuf, + u32 point, + u32 start_point, + u32 stop_point, + u32 average, + u32 buf_size) +{ + enum rt_status ret_status = RT_STATUS_SUCCESS; + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _hal_rf_ *rf = &(dm->rf_table); + struct _halrf_psd_data *psd = &(rf->halrf_psd_data); + + psd->point = point; + psd->start_point = start_point; + psd->stop_point = stop_point; + psd->average = average; + + if (psd->psd_progress) { + ret_status = RT_STATUS_PENDING; + } else { + psd->psd_progress = 1; + halrf_psd(dm, psd->point, psd->start_point, psd->stop_point, psd->average); + odm_move_memory(dm, outbuf, psd->psd_data, 0x400); + psd->psd_progress = 0; + } + + return ret_status; +} diff --git a/hal/phydm/halrf/halrf_psd.h b/hal/phydm/halrf/halrf_psd.h new file mode 100644 index 0000000..d714a56 --- /dev/null +++ b/hal/phydm/halrf/halrf_psd.h @@ -0,0 +1,60 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#ifndef __HALRF_PSD_H__ +#define __HALRF_PSD_H__ + + +struct _halrf_psd_data { + u32 point; + u32 start_point; + u32 stop_point; + u32 average; + u32 buf_size; + u32 psd_data[256]; + u32 psd_progress; +}; + +u32 +halrf_psd_init( + void *dm_void); + +void +_halrf_iqk_psd_init_8723f( + void *dm_void, + boolean onoff); + +u64 +halrf_get_iqk_psd_data( + void *dm_void, + u32 point); + +u32 +halrf_psd_query( + void *dm_void, + u32 *outbuf, + u32 buf_size); + +u32 +halrf_psd_init_query( + void *dm_void, + u32 *outbuf, + u32 point, + u32 start_point, + u32 stop_point, + u32 average, + u32 buf_size); + +#endif /*#__HALRF_PSD_H__*/ diff --git a/hal/phydm/halrf/halrf_txgapcal.c b/hal/phydm/halrf/halrf_txgapcal.c new file mode 100644 index 0000000..0cc4497 --- /dev/null +++ b/hal/phydm/halrf/halrf_txgapcal.c @@ -0,0 +1,300 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ +#include "mp_precomp.h" +#include "phydm_precomp.h" + +void odm_bub_sort(u32 *data, u32 n) +{ + int i, j, temp, sp; + + for (i = n - 1; i >= 0; i--) { + sp = 1; + for (j = 0; j < i; j++) { + if (data[j] < data[j + 1]) { + temp = data[j]; + data[j] = data[j + 1]; + data[j + 1] = temp; + sp = 0; + } + } + if (sp == 1) + break; + } +} + +#if (RTL8197F_SUPPORT == 1) + +u4Byte +odm_tx_gain_gap_psd_8197f( + void *dm_void, + u1Byte rf_path, + u4Byte rf56) +{ + PDM_ODM_T dm = (PDM_ODM_T)dm_void; + + u1Byte i, j; + u4Byte psd_vaule[5], psd_avg_time = 5, psd_vaule_temp; + + u4Byte iqk_ctl_addr[2][6] = {{0xe30, 0xe34, 0xe50, 0xe54, 0xe38, 0xe3c}, + {0xe50, 0xe54, 0xe30, 0xe34, 0xe58, 0xe5c}}; + + u4Byte psd_finish_bit[2] = {0x04000000, 0x20000000}; + u4Byte psd_fail_bit[2] = {0x08000000, 0x40000000}; + + u4Byte psd_cntl_value[2][2] = {{0x38008c1c, 0x10008c1c}, + {0x38008c2c, 0x10008c2c}}; + + u4Byte psd_report_addr[2] = {0xea0, 0xec0}; + + odm_set_rf_reg(dm, rf_path, RF_0xdf, bRFRegOffsetMask, 0x00e02); + + ODM_delay_us(100); + + odm_set_bb_reg(dm, R_0xe28, 0xffffffff, 0x0); + + odm_set_rf_reg(dm, rf_path, RF_0x56, 0xfff, rf56); + while (rf56 != (odm_get_rf_reg(dm, rf_path, RF_0x56, 0xfff))) + odm_set_rf_reg(dm, rf_path, RF_0x56, 0xfff, rf56); + + odm_set_bb_reg(dm, R_0xd94, 0xffffffff, 0x44FFBB44); + odm_set_bb_reg(dm, R_0xe70, 0xffffffff, 0x00400040); + odm_set_bb_reg(dm, R_0xc04, 0xffffffff, 0x6f005403); + odm_set_bb_reg(dm, R_0xc08, 0xffffffff, 0x000804e4); + odm_set_bb_reg(dm, R_0x874, 0xffffffff, 0x04203400); + odm_set_bb_reg(dm, R_0xe28, 0xffffffff, 0x80800000); + + odm_set_bb_reg(dm, iqk_ctl_addr[rf_path][0], 0xffffffff, psd_cntl_value[rf_path][0]); + odm_set_bb_reg(dm, iqk_ctl_addr[rf_path][1], 0xffffffff, psd_cntl_value[rf_path][1]); + odm_set_bb_reg(dm, iqk_ctl_addr[rf_path][2], 0xffffffff, psd_cntl_value[rf_path][0]); + odm_set_bb_reg(dm, iqk_ctl_addr[rf_path][3], 0xffffffff, psd_cntl_value[rf_path][0]); + odm_set_bb_reg(dm, iqk_ctl_addr[rf_path][4], 0xffffffff, 0x8215001F); + odm_set_bb_reg(dm, iqk_ctl_addr[rf_path][5], 0xffffffff, 0x2805001F); + + odm_set_bb_reg(dm, R_0xe40, 0xffffffff, 0x81007C00); + odm_set_bb_reg(dm, R_0xe44, 0xffffffff, 0x81004800); + odm_set_bb_reg(dm, R_0xe4c, 0xffffffff, 0x0046a8d0); + + for (i = 0; i < psd_avg_time; i++) { + for (j = 0; j < 1000; j++) { + odm_set_bb_reg(dm, R_0xe48, 0xffffffff, 0xfa005800); + odm_set_bb_reg(dm, R_0xe48, 0xffffffff, 0xf8005800); + + while (!odm_get_bb_reg(dm, R_0xeac, psd_finish_bit[rf_path])) + ; /*wait finish bit*/ + + if (!odm_get_bb_reg(dm, R_0xeac, psd_fail_bit[rf_path])) { /*check fail bit*/ + + psd_vaule[i] = odm_get_bb_reg(dm, psd_report_addr[rf_path], 0xffffffff); + + if (psd_vaule[i] > 0xffff) + break; + } + } + + RF_DBG(dm, DBG_RF_IQK, + "[TGGC] rf0=0x%x rf56=0x%x rf56_reg=0x%x time=%d psd_vaule=0x%x\n", + odm_get_rf_reg(dm, rf_path, RF_0x0, 0xff), rf56, + odm_get_rf_reg(dm, rf_path, RF_0x56, 0xfff), j, + psd_vaule[i]); + } + + odm_bub_sort(psd_vaule, psd_avg_time); + + psd_vaule_temp = psd_vaule[(UINT)(psd_avg_time / 2)]; + + odm_set_bb_reg(dm, R_0xd94, 0xffffffff, 0x44BBBB44); + odm_set_bb_reg(dm, R_0xe70, 0xffffffff, 0x80408040); + odm_set_bb_reg(dm, R_0xc04, 0xffffffff, 0x6f005433); + odm_set_bb_reg(dm, R_0xc08, 0xffffffff, 0x000004e4); + odm_set_bb_reg(dm, R_0x874, 0xffffffff, 0x04003400); + odm_set_bb_reg(dm, R_0xe28, 0xffffffff, 0x00000000); + + RF_DBG(dm, DBG_RF_IQK, + "[TGGC] rf0=0x%x rf56=0x%x rf56_reg=0x%x psd_vaule_temp=0x%x\n", + odm_get_rf_reg(dm, rf_path, RF_0x0, 0xff), rf56, + odm_get_rf_reg(dm, rf_path, RF_0x56, 0xfff), psd_vaule_temp); + + odm_set_rf_reg(dm, rf_path, RF_0xdf, bRFRegOffsetMask, 0x00602); + + return psd_vaule_temp; +} + +void odm_tx_gain_gap_calibration_8197f( + void *dm_void) +{ + PDM_ODM_T dm = (PDM_ODM_T)dm_void; + + u1Byte rf_path, rf0_idx, rf0_idx_current, rf0_idx_next, i, delta_gain_retry = 3; + + s1Byte delta_gain_gap_pre, delta_gain_gap[2][11]; + u4Byte rf56_current, rf56_next, psd_value_current, psd_value_next; + u4Byte psd_gap, rf56_current_temp[2][11]; + s4Byte rf33[2][11]; + + memset(rf33, 0x0, sizeof(rf33)); + + for (rf_path = RF_PATH_A; rf_path <= RF_PATH_B; rf_path++) { + if (rf_path == RF_PATH_A) + odm_set_bb_reg(dm, R_0x88c, (BIT(21) | BIT(20)), 0x3); /*disable 3-wire*/ + else if (rf_path == RF_PATH_B) + odm_set_bb_reg(dm, R_0x88c, (BIT(23) | BIT(22)), 0x3); /*disable 3-wire*/ + + ODM_delay_us(100); + + for (rf0_idx = 1; rf0_idx <= 10; rf0_idx++) { + rf0_idx_current = 3 * (rf0_idx - 1) + 1; + odm_set_rf_reg(dm, rf_path, RF_0x0, 0xff, rf0_idx_current); + ODM_delay_us(100); + rf56_current_temp[rf_path][rf0_idx] = odm_get_rf_reg(dm, rf_path, RF_0x56, 0xfff); + rf56_current = rf56_current_temp[rf_path][rf0_idx]; + + rf0_idx_next = 3 * rf0_idx + 1; + odm_set_rf_reg(dm, rf_path, RF_0x0, 0xff, rf0_idx_next); + ODM_delay_us(100); + rf56_next = odm_get_rf_reg(dm, rf_path, RF_0x56, 0xfff); + + RF_DBG(dm, DBG_RF_IQK, + "[TGGC] rf56_current[%d][%d]=0x%x rf56_next[%d][%d]=0x%x\n", + rf_path, rf0_idx, rf56_current, rf_path, rf0_idx, + rf56_next); + + if ((rf56_current >> 5) == (rf56_next >> 5)) { + delta_gain_gap[rf_path][rf0_idx] = 0; + + RF_DBG(dm, DBG_RF_IQK, + "[TGGC] rf56_current[11:5] == rf56_next[%d][%d][11:5]=0x%x delta_gain_gap[%d][%d]=%d\n", + rf_path, rf0_idx, (rf56_next >> 5), + rf_path, rf0_idx, + delta_gain_gap[rf_path][rf0_idx]); + + continue; + } + + RF_DBG(dm, DBG_RF_IQK, + "[TGGC] rf56_current[%d][%d][11:5]=0x%x != rf56_next[%d][%d][11:5]=0x%x\n", + rf_path, rf0_idx, (rf56_current >> 5), rf_path, + rf0_idx, (rf56_next >> 5)); + + for (i = 0; i < delta_gain_retry; i++) { + psd_value_current = odm_tx_gain_gap_psd_8197f(dm, rf_path, rf56_current); + + psd_value_next = odm_tx_gain_gap_psd_8197f(dm, rf_path, rf56_next - 2); + + psd_gap = psd_value_next / (psd_value_current / 1000); + +#if 0 + if (psd_gap > 1413) + delta_gain_gap[rf_path][rf0_idx] = 1; + else if (psd_gap > 1122) + delta_gain_gap[rf_path][rf0_idx] = 0; + else + delta_gain_gap[rf_path][rf0_idx] = -1; +#endif + + if (psd_gap > 1445) + delta_gain_gap[rf_path][rf0_idx] = 1; + else if (psd_gap > 1096) + delta_gain_gap[rf_path][rf0_idx] = 0; + else + delta_gain_gap[rf_path][rf0_idx] = -1; + + if (i == 0) + delta_gain_gap_pre = delta_gain_gap[rf_path][rf0_idx]; + + RF_DBG(dm, DBG_RF_IQK, + "[TGGC] psd_value_current=0x%x psd_value_next=0x%x psd_value_next/psd_value_current=%d delta_gain_gap[%d][%d]=%d\n", + psd_value_current, psd_value_next, + psd_gap, rf_path, rf0_idx, + delta_gain_gap[rf_path][rf0_idx]); + + if (i == 0 && delta_gain_gap[rf_path][rf0_idx] == 0) + break; + + if (delta_gain_gap_pre != delta_gain_gap[rf_path][rf0_idx]) { + delta_gain_gap[rf_path][rf0_idx] = 0; + + RF_DBG(dm, DBG_RF_IQK, "[TGGC] delta_gain_gap_pre(%d) != delta_gain_gap[%d][%d](%d) time=%d\n", + delta_gain_gap_pre, rf_path, rf0_idx, delta_gain_gap[rf_path][rf0_idx], i); + + break; + } + + RF_DBG(dm, DBG_RF_IQK, + "[TGGC] delta_gain_gap_pre(%d) == delta_gain_gap[%d][%d](%d) time=%d\n", + delta_gain_gap_pre, rf_path, rf0_idx, + delta_gain_gap[rf_path][rf0_idx], i); + } + } + + if (rf_path == RF_PATH_A) + odm_set_bb_reg(dm, R_0x88c, (BIT(21) | BIT(20)), 0x0); /*enable 3-wire*/ + else if (rf_path == RF_PATH_B) + odm_set_bb_reg(dm, R_0x88c, (BIT(23) | BIT(22)), 0x0); /*enable 3-wire*/ + + ODM_delay_us(100); + } + +#if 0 + /*odm_set_bb_reg(dm, R_0x88c, (BIT(23) | BIT(22) | BIT(21) | BIT(20)), 0x0);*/ /*enable 3-wire*/ +#endif + + for (rf_path = RF_PATH_A; rf_path <= RF_PATH_B; rf_path++) { + odm_set_rf_reg(dm, rf_path, RF_0xef, bRFRegOffsetMask, 0x00100); + + for (rf0_idx = 1; rf0_idx <= 10; rf0_idx++) { + rf33[rf_path][rf0_idx] = rf33[rf_path][rf0_idx] + (rf56_current_temp[rf_path][rf0_idx] & 0x1f); + + for (i = rf0_idx; i <= 10; i++) + rf33[rf_path][rf0_idx] = rf33[rf_path][rf0_idx] + delta_gain_gap[rf_path][i]; + + if (rf33[rf_path][rf0_idx] >= 0x1d) + rf33[rf_path][rf0_idx] = 0x1d; + else if (rf33[rf_path][rf0_idx] <= 0x2) + rf33[rf_path][rf0_idx] = 0x2; + + rf33[rf_path][rf0_idx] = rf33[rf_path][rf0_idx] + ((rf0_idx - 1) * 0x4000) + (rf56_current_temp[rf_path][rf0_idx] & 0xfffe0); + + RF_DBG(dm, DBG_RF_IQK, + "[TGGC] rf56[%d][%d]=0x%05x rf33[%d][%d]=0x%05x\n", + rf_path, rf0_idx, + rf56_current_temp[rf_path][rf0_idx], rf_path, + rf0_idx, rf33[rf_path][rf0_idx]); + + odm_set_rf_reg(dm, rf_path, RF_0x33, bRFRegOffsetMask, rf33[rf_path][rf0_idx]); + } + + odm_set_rf_reg(dm, rf_path, RF_0xef, bRFRegOffsetMask, 0x00000); + } +} +#endif + +void odm_tx_gain_gap_calibration(void *dm_void) +{ + PDM_ODM_T dm = (PDM_ODM_T)dm_void; +#if (RTL8197F_SUPPORT == 1) + if (dm->SupportICType & ODM_RTL8197F) + odm_tx_gain_gap_calibration_8197f(dm_void); +#endif +} diff --git a/hal/phydm/halrf/halrf_txgapcal.h b/hal/phydm/halrf/halrf_txgapcal.h new file mode 100644 index 0000000..09651cb --- /dev/null +++ b/hal/phydm/halrf/halrf_txgapcal.h @@ -0,0 +1,31 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * wlanfae + * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, + * Hsinchu 300, Taiwan. + * + * Larry Finger + * + *****************************************************************************/ + +#ifndef __HALRF_TXGAPCAL_H__ +#define __HALRF_TXGAPCAL_H__ + +void odm_tx_gain_gap_calibration(void *dm_void); + +#endif /*__HALRF_TXGAPCAL_H__*/ diff --git a/hal/phydm/halrf/rtl8188e/halrf_8188e_ap.c b/hal/phydm/halrf/rtl8188e/halrf_8188e_ap.c new file mode 100644 index 0000000..19500ab --- /dev/null +++ b/hal/phydm/halrf/rtl8188e/halrf_8188e_ap.c @@ -0,0 +1,1257 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#include "mp_precomp.h" +#include "../../phydm_precomp.h" + + + +/*---------------------------Define Local Constant---------------------------*/ +/* 2010/04/25 MH Define the max tx power tracking tx agc power. */ +#define ODM_TXPWRTRACK_MAX_IDX_88E 6 + +/*---------------------------Define Local Constant---------------------------*/ + + +/* 3============================================================ + * 3 Tx Power Tracking + * 3============================================================ */ + + +void halrf_rf_lna_setting_8188e( + struct dm_struct *dm, + enum halrf_lna_set type +) +{ +/*phydm_disable_lna*/ + if (type == HALRF_LNA_DISABLE) { + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x30, 0xfffff, 0x18000); /*select Rx mode*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x32, 0xfffff, 0x37f82); /*disable LNA*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x0); + if (dm->rf_type > RF_1T1R) { + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x30, 0xfffff, 0x18000); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x32, 0xfffff, 0x37f82); + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x0); + } + } else if (type == HALRF_LNA_ENABLE) { + /*phydm_enable_lna*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x30, 0xfffff, 0x18000); /*select Rx mode*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x32, 0xfffff, 0x77f82); /*back to normal*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x0); + if (dm->rf_type > RF_1T1R) { + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x30, 0xfffff, 0x18000); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x32, 0xfffff, 0x77f82); + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x0); + } + + } +} + +void set_iqk_matrix_8188e( + struct dm_struct *dm, + u8 OFDM_index, + u8 rf_path, + s32 iqk_result_x, + s32 iqk_result_y +) +{ + s32 ele_A = 0, ele_D, ele_C = 0, /*TempCCk,*/ value32; + + ele_D = (ofdm_swing_table_new[OFDM_index] & 0xFFC00000) >> 22; + + /* new element A = element D x X */ + if ((iqk_result_x != 0) && (*(dm->band_type) == ODM_BAND_2_4G)) { + if ((iqk_result_x & 0x00000200) != 0) /* consider minus */ + iqk_result_x = iqk_result_x | 0xFFFFFC00; + ele_A = ((iqk_result_x * ele_D) >> 8) & 0x000003FF; + + /* new element C = element D x Y */ + if ((iqk_result_y & 0x00000200) != 0) + iqk_result_y = iqk_result_y | 0xFFFFFC00; + ele_C = ((iqk_result_y * ele_D) >> 8) & 0x000003FF; + + if (rf_path == RF_PATH_A) + switch (rf_path) { + case RF_PATH_A: + /* wirte new elements A, C, D to regC80 and regC94, element B is always 0 */ + value32 = (ele_D << 22) | ((ele_C & 0x3F) << 16) | ele_A; + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD, value32); + + value32 = (ele_C & 0x000003C0) >> 6; + odm_set_bb_reg(dm, REG_OFDM_0_XC_TX_AFE, MASKH4BITS, value32); + + value32 = ((iqk_result_x * ele_D) >> 7) & 0x01; + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), value32); + break; + case RF_PATH_B: + /* wirte new elements A, C, D to regC88 and regC9C, element B is always 0 */ + value32 = (ele_D << 22) | ((ele_C & 0x3F) << 16) | ele_A; + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD, value32); + + value32 = (ele_C & 0x000003C0) >> 6; + odm_set_bb_reg(dm, REG_OFDM_0_XD_TX_AFE, MASKH4BITS, value32); + + value32 = ((iqk_result_x * ele_D) >> 7) & 0x01; + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), value32); + + break; + default: + break; + } + } else { + switch (rf_path) { + case RF_PATH_A: + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD, ofdm_swing_table_new[OFDM_index]); + odm_set_bb_reg(dm, REG_OFDM_0_XC_TX_AFE, MASKH4BITS, 0x00); + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), 0x00); + break; + + case RF_PATH_B: + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD, ofdm_swing_table_new[OFDM_index]); + odm_set_bb_reg(dm, REG_OFDM_0_XD_TX_AFE, MASKH4BITS, 0x00); + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), 0x00); + break; + + default: + break; + } + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "TxPwrTracking path B: X = 0x%x, Y = 0x%x ele_A = 0x%x ele_C = 0x%x ele_D = 0x%x 0xeb4 = 0x%x 0xebc = 0x%x\n", + (u32)iqk_result_x, (u32)iqk_result_y, (u32)ele_A, (u32)ele_C, (u32)ele_D, (u32)iqk_result_x, (u32)iqk_result_y); +} + +void do_iqk_8188e( + void *dm_void, + u8 delta_thermal_index, + u8 thermal_value, + u8 threshold +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + odm_reset_iqk_result(dm); + + dm->rf_calibrate_info.thermal_value_iqk = thermal_value; + halrf_iqk_trigger(dm, false); +} + +/*----------------------------------------------------------------------------- + * Function: odm_TxPwrTrackSetPwr88E() + * + * Overview: 88E change all channel tx power accordign to flag. + * OFDM & CCK are all different. + * + * Input: NONE + * + * Output: NONE + * + * Return: NONE + * + * Revised History: + * When Who Remark + * 04/23/2012 MHC Create version 0. + * + *---------------------------------------------------------------------------*/ +void +odm_tx_pwr_track_set_pwr88_e( + struct dm_struct *dm, + enum pwrtrack_method method, + u8 rf_path, + u8 channel_mapped_index +) +{ + if (method == TXAGC) { + /* u8 cck_power_level[MAX_TX_COUNT], ofdm_power_level[MAX_TX_COUNT]; + * u8 bw20_power_level[MAX_TX_COUNT], bw40_power_level[MAX_TX_COUNT]; + * u8 rf = 0; */ + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "odm_TxPwrTrackSetPwr88E CH=%d\n", *(dm->channel)); +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + phy_rf6052_set_cck_tx_power(dm->priv, *(dm->channel)); + phy_rf6052_set_ofdm_tx_power(dm->priv, *(dm->channel)); +#endif + + } else if (method == BBSWING) { + /* Adjust BB swing by OFDM IQ matrix */ + if (rf_path == RF_PATH_A) { + set_iqk_matrix_8188e(dm, dm->rf_calibrate_info.bb_swing_idx_ofdm[RF_PATH_A], RF_PATH_A, + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][0], + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][1]); + } else if (rf_path == RF_PATH_B) { + set_iqk_matrix_8188e(dm, dm->rf_calibrate_info.bb_swing_idx_ofdm[RF_PATH_B], RF_PATH_B, + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][4], + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][5]); + } + /*Adjust BB swing by CCK filter coefficient*/ + if (*dm->channel != 14) { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch1_ch13_new[dm->rf_calibrate_info.bb_swing_idx_cck][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch1_ch13_new[dm->rf_calibrate_info.bb_swing_idx_cck][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch1_ch13_new[dm->rf_calibrate_info.bb_swing_idx_cck][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch1_ch13_new[dm->rf_calibrate_info.bb_swing_idx_cck][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch1_ch13_new[dm->rf_calibrate_info.bb_swing_idx_cck][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch1_ch13_new[dm->rf_calibrate_info.bb_swing_idx_cck][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch1_ch13_new[dm->rf_calibrate_info.bb_swing_idx_cck][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch1_ch13_new[dm->rf_calibrate_info.bb_swing_idx_cck][7]); + } else { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch14_new[dm->rf_calibrate_info.bb_swing_idx_cck][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch14_new[dm->rf_calibrate_info.bb_swing_idx_cck][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch14_new[dm->rf_calibrate_info.bb_swing_idx_cck][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch14_new[dm->rf_calibrate_info.bb_swing_idx_cck][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch14_new[dm->rf_calibrate_info.bb_swing_idx_cck][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch14_new[dm->rf_calibrate_info.bb_swing_idx_cck][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch14_new[dm->rf_calibrate_info.bb_swing_idx_cck][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch14_new[dm->rf_calibrate_info.bb_swing_idx_cck][7]); + } + } else + return; + + + + +} /* odm_TxPwrTrackSetPwr88E */ + +void configure_txpower_track_8188e( + struct txpwrtrack_cfg *config +) +{ + config->swing_table_size_cck = CCK_TABLE_SIZE; + config->swing_table_size_ofdm = OFDM_TABLE_SIZE_92D; + config->threshold_iqk = 8; + config->average_thermal_num = AVG_THERMAL_NUM_88E; + config->rf_path_count = 1; + config->thermal_reg_addr = RF_T_METER_88E; + + config->odm_tx_pwr_track_set_pwr = odm_tx_pwr_track_set_pwr88_e; + config->do_iqk = do_iqk_8188e; + config->phy_lc_calibrate = halrf_lck_trigger; +} + +/* 1 7. IQK */ +#define MAX_TOLERANCE 5 +#define IQK_DELAY_TIME 1 /* ms */ + +u8 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ +phy_path_a_iqk_8188e( + struct dm_struct *dm, + boolean config_path_b +) +{ + u32 reg_eac, reg_e94, reg_e9c, reg_ea4; + u8 result = 0x00; + + RF_DBG(dm, DBG_RF_IQK, "path A IQK!\n"); + /* 1 Tx IQK */ + /* path-A IQK setting */ + RF_DBG(dm, DBG_RF_IQK, "path-A IQK setting!\n"); + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x10008c1c); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x30008c1c); + odm_set_bb_reg(dm, REG_TX_IQK_PI_A, MASKDWORD, 0x8214032a); + odm_set_bb_reg(dm, REG_RX_IQK_PI_A, MASKDWORD, 0x28160000); + + /* LO calibration setting */ + RF_DBG(dm, DBG_RF_IQK, "LO calibration setting!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_RSP, MASKDWORD, 0x00462911); + + /* One shot, path A LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf9000000); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf8000000); + + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path A LOK & IQK.\n", IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E); + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_e94 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe94 = 0x%x\n", reg_e94); + reg_e9c = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe9c = 0x%x\n", reg_e9c); + reg_ea4 = odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xea4 = 0x%x\n", reg_ea4); + + if (!(reg_eac & BIT(28)) && + (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && + (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + /* else */ /* if Tx not OK, ignore Rx */ + /* return result; */ +#if 0 + if (!(reg_eac & BIT(27)) && /* if Tx is OK, check whether Rx is OK */ + (((reg_ea4 & 0x03FF0000) >> 16) != 0x132) && + (((reg_eac & 0x03FF0000) >> 16) != 0x36)) + result |= 0x02; + else + RTPRINT(FINIT, INIT_IQK, ("path A Rx IQK fail!!\n")); +#endif + + return result; + + +} + +u8 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ +phy_path_a_rx_iqk( + struct dm_struct *dm, + boolean config_path_b +) +{ + u32 reg_eac, reg_e94, reg_e9c, reg_ea4, u4tmp; + u8 result = 0x00; + + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK!\n"); + + /* 1 Get TXIMR setting */ + /* modify RXIQK mode table */ + RF_DBG(dm, DBG_RF_IQK, "path-A Rx IQK modify RXIQK mode table!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0); + odm_set_rf_reg(dm, RF_PATH_A, RF_WE_LUT, RFREGOFFSETMASK, 0x800a0); + odm_set_rf_reg(dm, RF_PATH_A, RF_RCK_OS, RFREGOFFSETMASK, 0x30000); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G1, RFREGOFFSETMASK, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G2, RFREGOFFSETMASK, 0xf117B); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x808000); + + /* IQK setting */ + odm_set_bb_reg(dm, REG_TX_IQK, MASKDWORD, 0x01007c00); + odm_set_bb_reg(dm, REG_RX_IQK, MASKDWORD, 0x81004800); + + /* path-A IQK setting */ + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x10008c1c); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x30008c1c); + odm_set_bb_reg(dm, REG_TX_IQK_PI_A, MASKDWORD, 0x82160804); + odm_set_bb_reg(dm, REG_RX_IQK_PI_A, MASKDWORD, 0x28160000); + + /* LO calibration setting */ + RF_DBG(dm, DBG_RF_IQK, "LO calibration setting!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_RSP, MASKDWORD, 0x0046a911); + + /* One shot, path A LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf9000000); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf8000000); + + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path A LOK & IQK.\n", IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E); + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_e94 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe94 = 0x%x\n", reg_e94); + reg_e9c = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe9c = 0x%x\n", reg_e9c); + + if (!(reg_eac & BIT(28)) && + (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && + (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + else { /* if Tx not OK, ignore Rx */ + return result; + } + + u4tmp = 0x80007C00 | (reg_e94 & 0x3FF0000) | ((reg_e9c & 0x3FF0000) >> 16); + odm_set_bb_reg(dm, REG_TX_IQK, MASKDWORD, u4tmp); + RF_DBG(dm, DBG_RF_IQK, "0xe40 = 0x%x u4tmp = 0x%x\n", odm_get_bb_reg(dm, REG_TX_IQK, MASKDWORD), u4tmp); + + + /* 1 RX IQK */ + /* modify RXIQK mode table */ + RF_DBG(dm, DBG_RF_IQK, "path-A Rx IQK modify RXIQK mode table 2!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0); + odm_set_rf_reg(dm, RF_PATH_A, RF_WE_LUT, RFREGOFFSETMASK, 0x800a0); + odm_set_rf_reg(dm, RF_PATH_A, RF_RCK_OS, RFREGOFFSETMASK, 0x30000); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G1, RFREGOFFSETMASK, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G2, RFREGOFFSETMASK, 0xf7ffa); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x808000); + + /* IQK setting */ + odm_set_bb_reg(dm, REG_RX_IQK, MASKDWORD, 0x01004800); + + /* path-A IQK setting */ + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x30008c1c); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x10008c1c); + odm_set_bb_reg(dm, REG_TX_IQK_PI_A, MASKDWORD, 0x82160c05); + odm_set_bb_reg(dm, REG_RX_IQK_PI_A, MASKDWORD, 0x28160c05); + + /* LO calibration setting */ + RF_DBG(dm, DBG_RF_IQK, "LO calibration setting!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_RSP, MASKDWORD, 0x0046a911); + + /* One shot, path A LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf9000000); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf8000000); + + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path A LOK & IQK.\n", IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + + ODM_delay_ms(IQK_DELAY_TIME_88E); + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_e94 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe94 = 0x%x\n", reg_e94); + reg_e9c = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe9c = 0x%x\n", reg_e9c); + reg_ea4 = odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xea4 = 0x%x\n", reg_ea4); + +#if 0 + if (!(reg_eac & BIT(28)) && + (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && + (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + else /* if Tx not OK, ignore Rx */ + return result; +#endif + + if (!(reg_eac & BIT(27)) && /* if Tx is OK, check whether Rx is OK */ + (((reg_ea4 & 0x03FF0000) >> 16) != 0x132) && + (((reg_eac & 0x03FF0000) >> 16) != 0x36)) + result |= 0x02; + else + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK fail!!\n"); + + return result; + + +} + +u8 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ +phy_path_b_iqk_8188e( + struct dm_struct *dm +) +{ + u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc; + u8 result = 0x00; + RF_DBG(dm, DBG_RF_IQK, "path B IQK!\n"); + + /* One shot, path B LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_CONT, MASKDWORD, 0x00000002); + odm_set_bb_reg(dm, REG_IQK_AGC_CONT, MASKDWORD, 0x00000000); + + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path B LOK & IQK.\n", IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E); + + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_eb4 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_B, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeb4 = 0x%x\n", reg_eb4); + reg_ebc = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_B, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xebc = 0x%x\n", reg_ebc); + reg_ec4 = odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_B_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xec4 = 0x%x\n", reg_ec4); + reg_ecc = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_B_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xecc = 0x%x\n", reg_ecc); + + if (!(reg_eac & BIT(31)) && + (((reg_eb4 & 0x03FF0000) >> 16) != 0x142) && + (((reg_ebc & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + else + return result; + + if (!(reg_eac & BIT(30)) && + (((reg_ec4 & 0x03FF0000) >> 16) != 0x132) && + (((reg_ecc & 0x03FF0000) >> 16) != 0x36)) + result |= 0x02; + else + RF_DBG(dm, DBG_RF_IQK, "path B Rx IQK fail!!\n"); + + + return result; + +} + +void +_phy_path_a_fill_iqk_matrix( + struct dm_struct *dm, + boolean is_iqk_ok, + s32 result[][8], + u8 final_candidate, + boolean is_tx_only +) +{ + u32 oldval_0, X, TX0_A, reg; + s32 Y, TX0_C; + RF_DBG(dm, DBG_RF_IQK, "path A IQ Calibration %s !\n", (is_iqk_ok) ? "Success" : "Failed"); + + if (final_candidate == 0xFF) + return; + + else if (is_iqk_ok) { + oldval_0 = (odm_get_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD) >> 22) & 0x3FF; + + X = result[final_candidate][0]; + if ((X & 0x00000200) != 0) + X = X | 0xFFFFFC00; + TX0_A = (X * oldval_0) >> 8; + RF_DBG(dm, DBG_RF_IQK, "X = 0x%x, TX0_A = 0x%x, oldval_0 0x%x\n", X, TX0_A, oldval_0); + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 0x3FF, TX0_A); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(31), ((X * oldval_0 >> 7) & 0x1)); + + Y = result[final_candidate][1]; + if ((Y & 0x00000200) != 0) + Y = Y | 0xFFFFFC00; + + + TX0_C = (Y * oldval_0) >> 8; + RF_DBG(dm, DBG_RF_IQK, "Y = 0x%x, TX = 0x%x\n", Y, TX0_C); + odm_set_bb_reg(dm, REG_OFDM_0_XC_TX_AFE, 0xF0000000, ((TX0_C & 0x3C0) >> 6)); + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 0x003F0000, (TX0_C & 0x3F)); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(29), ((Y * oldval_0 >> 7) & 0x1)); + + if (is_tx_only) { + RF_DBG(dm, DBG_RF_IQK, "_phy_path_a_fill_iqk_matrix only Tx OK\n"); + return; + } + + reg = result[final_candidate][2]; +#if (DM_ODM_SUPPORT_TYPE == ODM_AP) + if (RTL_ABS(reg, 0x100) >= 16) + reg = 0x100; +#endif + odm_set_bb_reg(dm, REG_OFDM_0_XA_RX_IQ_IMBALANCE, 0x3FF, reg); + + reg = result[final_candidate][3] & 0x3F; + odm_set_bb_reg(dm, REG_OFDM_0_XA_RX_IQ_IMBALANCE, 0xFC00, reg); + + reg = (result[final_candidate][3] >> 6) & 0xF; + odm_set_bb_reg(dm, REG_OFDM_0_RX_IQ_EXT_ANTA, 0xF0000000, reg); + } +} + +void +_phy_path_b_fill_iqk_matrix( + struct dm_struct *dm, + boolean is_iqk_ok, + s32 result[][8], + u8 final_candidate, + boolean is_tx_only /* do Tx only */ +) +{ + u32 oldval_1, X, TX1_A, reg; + s32 Y, TX1_C; + RF_DBG(dm, DBG_RF_IQK, "path B IQ Calibration %s !\n", (is_iqk_ok) ? "Success" : "Failed"); + + if (final_candidate == 0xFF) + return; + + else if (is_iqk_ok) { + oldval_1 = (odm_get_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD) >> 22) & 0x3FF; + + X = result[final_candidate][4]; + if ((X & 0x00000200) != 0) + X = X | 0xFFFFFC00; + TX1_A = (X * oldval_1) >> 8; + RF_DBG(dm, DBG_RF_IQK, "X = 0x%x, TX1_A = 0x%x\n", X, TX1_A); + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, 0x3FF, TX1_A); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(27), ((X * oldval_1 >> 7) & 0x1)); + + Y = result[final_candidate][5]; + if ((Y & 0x00000200) != 0) + Y = Y | 0xFFFFFC00; + + TX1_C = (Y * oldval_1) >> 8; + RF_DBG(dm, DBG_RF_IQK, "Y = 0x%x, TX1_C = 0x%x\n", Y, TX1_C); + odm_set_bb_reg(dm, REG_OFDM_0_XD_TX_AFE, 0xF0000000, ((TX1_C & 0x3C0) >> 6)); + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, 0x003F0000, (TX1_C & 0x3F)); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(25), ((Y * oldval_1 >> 7) & 0x1)); + + if (is_tx_only) + return; + + reg = result[final_candidate][6]; + odm_set_bb_reg(dm, REG_OFDM_0_XB_RX_IQ_IMBALANCE, 0x3FF, reg); + + reg = result[final_candidate][7] & 0x3F; + odm_set_bb_reg(dm, REG_OFDM_0_XB_RX_IQ_IMBALANCE, 0xFC00, reg); + + reg = (result[final_candidate][7] >> 6) & 0xF; + odm_set_bb_reg(dm, REG_OFDM_0_AGC_RSSI_TABLE, 0x0000F000, reg); + } +} + +void +_phy_save_adda_registers( + struct dm_struct *dm, + u32 *adda_reg, + u32 *adda_backup, + u32 register_num +) +{ + u32 i; + + RF_DBG(dm, DBG_RF_IQK, "Save ADDA parameters.\n"); + for (i = 0 ; i < register_num ; i++) + adda_backup[i] = odm_get_bb_reg(dm, adda_reg[i], MASKDWORD); +} + + +void +_phy_save_mac_registers( + struct dm_struct *dm, + u32 *mac_reg, + u32 *mac_backup +) +{ + u32 i; + RF_DBG(dm, DBG_RF_IQK, "Save MAC parameters.\n"); + for (i = 0 ; i < (IQK_MAC_REG_NUM - 1); i++) + mac_backup[i] = odm_read_1byte(dm, mac_reg[i]); + mac_backup[i] = odm_read_4byte(dm, mac_reg[i]); + +} + + +void +_phy_reload_adda_registers( + struct dm_struct *dm, + u32 *adda_reg, + u32 *adda_backup, + u32 regiester_num +) +{ + u32 i; + RF_DBG(dm, DBG_RF_IQK, "Reload ADDA power saving parameters !\n"); + for (i = 0 ; i < regiester_num; i++) + odm_set_bb_reg(dm, adda_reg[i], MASKDWORD, adda_backup[i]); +} + +void +_phy_reload_mac_registers( + struct dm_struct *dm, + u32 *mac_reg, + u32 *mac_backup +) +{ + u32 i; + RF_DBG(dm, DBG_RF_IQK, "Reload MAC parameters !\n"); + for (i = 0 ; i < (IQK_MAC_REG_NUM - 1); i++) + odm_write_1byte(dm, mac_reg[i], (u8)mac_backup[i]); + odm_write_4byte(dm, mac_reg[i], mac_backup[i]); +} + + +void +_phy_path_adda_on( + struct dm_struct *dm, + u32 *adda_reg, + boolean is_path_a_on, + boolean is2T +) +{ + u32 path_on; + u32 i; + RF_DBG(dm, DBG_RF_IQK, "ADDA ON.\n"); + + path_on = is_path_a_on ? 0x04db25a4 : 0x0b1b25a4; + if (false == is2T) { + path_on = 0x0bdb25a0; + odm_set_bb_reg(dm, adda_reg[0], MASKDWORD, 0x0b1b25a0); + } else + odm_set_bb_reg(dm, adda_reg[0], MASKDWORD, path_on); + + for (i = 1 ; i < IQK_ADDA_REG_NUM ; i++) + odm_set_bb_reg(dm, adda_reg[i], MASKDWORD, path_on); + +} + +void +_phy_mac_setting_calibration( + struct dm_struct *dm, + u32 *mac_reg, + u32 *mac_backup +) +{ + u32 i = 0; + RF_DBG(dm, DBG_RF_IQK, "MAC settings for Calibration.\n"); + + odm_write_1byte(dm, mac_reg[i], 0x3F); + + for (i = 1 ; i < (IQK_MAC_REG_NUM - 1); i++) + odm_write_1byte(dm, mac_reg[i], (u8)(mac_backup[i] & (~BIT(3)))); + odm_write_1byte(dm, mac_reg[i], (u8)(mac_backup[i] & (~BIT(5)))); + +} + +void +_phy_path_a_stand_by( + struct dm_struct *dm +) +{ + RF_DBG(dm, DBG_RF_IQK, "path-A standby mode!\n"); + + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x0); + odm_set_bb_reg(dm, R_0x840, MASKDWORD, 0x00010000); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x808000); +} + +void +_phy_pi_mode_switch( + struct dm_struct *dm, + boolean pi_mode +) +{ + u32 mode; + RF_DBG(dm, DBG_RF_IQK, "BB Switch to %s mode!\n", (pi_mode ? "PI" : "SI")); + + mode = pi_mode ? 0x01000100 : 0x01000000; + odm_set_bb_reg(dm, REG_FPGA0_XA_HSSI_PARAMETER1, MASKDWORD, mode); + odm_set_bb_reg(dm, REG_FPGA0_XB_HSSI_PARAMETER1, MASKDWORD, mode); +} + +boolean +phy_simularity_compare_8188e( + struct dm_struct *dm, + s32 result[][8], + u8 c1, + u8 c2 +) +{ + u32 i, j, diff, simularity_bit_map, bound = 0; + u8 final_candidate[2] = {0xFF, 0xFF}; /* for path A and path B */ + boolean is_result = true; + boolean is2T = 0; + + if (is2T) + bound = 8; + else + bound = 4; + + RF_DBG(dm, DBG_RF_IQK, "===> IQK:phy_simularity_compare_8188e c1 %d c2 %d!!!\n", c1, c2); + + + simularity_bit_map = 0; + + for (i = 0; i < bound; i++) { + diff = (result[c1][i] > result[c2][i]) ? (result[c1][i] - result[c2][i]) : (result[c2][i] - result[c1][i]); + if (diff > MAX_TOLERANCE) { + RF_DBG(dm, DBG_RF_IQK, "IQK:phy_simularity_compare_8188e differnece overflow index %d compare1 0x%x compare2 0x%x!!!\n", i, result[c1][i], result[c2][i]); + + if ((i == 2 || i == 6) && !simularity_bit_map) { + if (result[c1][i] + result[c1][i + 1] == 0) + final_candidate[(i / 4)] = c2; + else if (result[c2][i] + result[c2][i + 1] == 0) + final_candidate[(i / 4)] = c1; + else + simularity_bit_map = simularity_bit_map | (1 << i); + } else + simularity_bit_map = simularity_bit_map | (1 << i); + } + } + + RF_DBG(dm, DBG_RF_IQK, "IQK:phy_simularity_compare_8188e simularity_bit_map %d !!!\n", simularity_bit_map); + + if (simularity_bit_map == 0) { + for (i = 0; i < (bound / 4); i++) { + if (final_candidate[i] != 0xFF) { + for (j = i * 4; j < (i + 1) * 4 - 2; j++) + result[3][j] = result[final_candidate[i]][j]; + is_result = false; + } + } + return is_result; + } else if (!(simularity_bit_map & 0x0F)) { /* path A OK */ + for (i = 0; i < 4; i++) + result[3][i] = result[c1][i]; + return false; + } else if (!(simularity_bit_map & 0xF0) && is2T) { /* path B OK */ + for (i = 4; i < 8; i++) + result[3][i] = result[c1][i]; + return false; + } else + return false; + +} + + + +void +_phy_iq_calibrate_8188e( + struct dm_struct *dm, + s32 result[][8], + u8 t, + boolean is2T +) +{ + u32 i; + u8 path_aok, path_bok; + u32 ADDA_REG[IQK_ADDA_REG_NUM] = { + REG_FPGA0_XCD_SWITCH_CONTROL, REG_BLUE_TOOTH, + REG_RX_WAIT_CCA, REG_TX_CCK_RFON, + REG_TX_CCK_BBON, REG_TX_OFDM_RFON, + REG_TX_OFDM_BBON, REG_TX_TO_RX, + REG_TX_TO_TX, REG_RX_CCK, + REG_RX_OFDM, REG_RX_WAIT_RIFS, + REG_RX_TO_RX, REG_STANDBY, + REG_SLEEP, REG_PMPD_ANAEN + }; + u32 IQK_MAC_REG[IQK_MAC_REG_NUM] = { + REG_TXPAUSE, REG_BCN_CTRL, + REG_BCN_CTRL_1, REG_GPIO_MUXCFG + }; + + /* since 92C & 92D have the different define in IQK_BB_REG */ + u32 IQK_BB_REG_92C[IQK_BB_REG_NUM] = { + REG_OFDM_0_TRX_PATH_ENABLE, REG_OFDM_0_TR_MUX_PAR, + REG_FPGA0_XCD_RF_INTERFACE_SW, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B, + REG_FPGA0_XAB_RF_INTERFACE_SW, REG_FPGA0_XA_RF_INTERFACE_OE, + REG_FPGA0_XB_RF_INTERFACE_OE, /*REG_FPGA0_RFMOD*/ REG_CCK_0_AFE_SETTING + }; + + u32 retry_count = 2; + /* Note: IQ calibration must be performed after loading */ + /* PHY_REG.txt , and radio_a, radio_b.txt */ + + /* u32 bbvalue; */ + + if (*(dm->mp_mode)) + retry_count = 9; + + if (t == 0) { + /* bbvalue = odm_get_bb_reg(dm, REG_FPGA0_RFMOD, MASKDWORD); + * RTPRINT(FINIT, INIT_IQK, ("_phy_iq_calibrate_8188e()==>0x%08x\n",bbvalue)); */ + + RF_DBG(dm, DBG_RF_IQK, "IQ Calibration for %s for %d times\n", (is2T ? "2T2R" : "1T1R"), t); + + /* Save ADDA parameters, turn path A ADDA on */ + _phy_save_adda_registers(dm, ADDA_REG, dm->rf_calibrate_info.ADDA_backup, IQK_ADDA_REG_NUM); + _phy_save_mac_registers(dm, IQK_MAC_REG, dm->rf_calibrate_info.IQK_MAC_backup); + _phy_save_adda_registers(dm, IQK_BB_REG_92C, dm->rf_calibrate_info.IQK_BB_backup, IQK_BB_REG_NUM); + } + RF_DBG(dm, DBG_RF_IQK, "IQ Calibration for %s for %d times\n", (is2T ? "2T2R" : "1T1R"), t); + + _phy_path_adda_on(dm, ADDA_REG, true, is2T); + + if (t == 0) + dm->rf_calibrate_info.is_rf_pi_enable = (u8)odm_get_bb_reg(dm, REG_FPGA0_XA_HSSI_PARAMETER1, BIT(8)); + + if (!dm->rf_calibrate_info.is_rf_pi_enable) { + /* Switch BB to PI mode to do IQ Calibration. */ + _phy_pi_mode_switch(dm, true); + } + + /* MAC settings */ + _phy_mac_setting_calibration(dm, IQK_MAC_REG, dm->rf_calibrate_info.IQK_MAC_backup); + + /* BB setting */ + /* odm_set_bb_reg(dm, REG_FPGA0_RFMOD, BIT24, 0x00); */ + odm_set_bb_reg(dm, REG_CCK_0_AFE_SETTING, MASKDWORD, (0x0f000000 | (odm_get_bb_reg(dm, REG_CCK_0_AFE_SETTING, MASKDWORD)))); + odm_set_bb_reg(dm, REG_OFDM_0_TRX_PATH_ENABLE, MASKDWORD, 0x03a05600); + odm_set_bb_reg(dm, REG_OFDM_0_TR_MUX_PAR, MASKDWORD, 0x000800e4); + odm_set_bb_reg(dm, REG_FPGA0_XCD_RF_INTERFACE_SW, MASKDWORD, 0x22204000); + + + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_INTERFACE_SW, BIT(10), 0x01); + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_INTERFACE_SW, BIT(26), 0x01); + odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(10), 0x00); + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(10), 0x00); + + + if (is2T) { + odm_set_bb_reg(dm, REG_FPGA0_XA_LSSI_PARAMETER, MASKDWORD, 0x00010000); + odm_set_bb_reg(dm, REG_FPGA0_XB_LSSI_PARAMETER, MASKDWORD, 0x00010000); + } + + /* Page B init */ + /* AP or IQK */ + odm_set_bb_reg(dm, REG_CONFIG_ANT_A, MASKDWORD, 0x0f600000); + + if (is2T) + odm_set_bb_reg(dm, REG_CONFIG_ANT_B, MASKDWORD, 0x0f600000); + + /* IQ calibration setting */ + RF_DBG(dm, DBG_RF_IQK, "IQK setting!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x808000); + odm_set_bb_reg(dm, REG_TX_IQK, MASKDWORD, 0x01007c00); + odm_set_bb_reg(dm, REG_RX_IQK, MASKDWORD, 0x81004800); + + for (i = 0 ; i < retry_count ; i++) { + path_aok = phy_path_a_iqk_8188e(dm, is2T); + /* if(path_aok == 0x03){ */ + if (path_aok == 0x01) { + RF_DBG(dm, DBG_RF_IQK, "path A Tx IQK Success!!\n"); + result[t][0] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + result[t][1] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + break; + } +#if 0 + else if (i == (retry_count - 1) && path_aok == 0x01) { /* Tx IQK OK */ + RTPRINT(FINIT, INIT_IQK, ("path A IQK Only Tx Success!!\n")); + + result[t][0] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + result[t][1] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + } +#endif + } + + for (i = 0 ; i < retry_count ; i++) { + path_aok = phy_path_a_rx_iqk(dm, is2T); + if (path_aok == 0x03) { + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK Success!!\n"); + /* result[t][0] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD)&0x3FF0000)>>16; + * result[t][1] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD)&0x3FF0000)>>16; */ + result[t][2] = (odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_A_2, MASKDWORD) & 0x3FF0000) >> 16; + result[t][3] = (odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD) & 0x3FF0000) >> 16; + break; + } else + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK Fail!!\n"); + } + + if (0x00 == path_aok) + RF_DBG(dm, DBG_RF_IQK, "path A IQK failed!!\n"); + + if (is2T) { + _phy_path_a_stand_by(dm); + + /* Turn path B ADDA on */ + _phy_path_adda_on(dm, ADDA_REG, false, is2T); + + for (i = 0 ; i < retry_count ; i++) { + path_bok = phy_path_b_iqk_8188e(dm); + if (path_bok == 0x03) { + RF_DBG(dm, DBG_RF_IQK, "path B IQK Success!!\n"); + result[t][4] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + result[t][5] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + result[t][6] = (odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_B_2, MASKDWORD) & 0x3FF0000) >> 16; + result[t][7] = (odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_B_2, MASKDWORD) & 0x3FF0000) >> 16; + break; + } else if (i == (retry_count - 1) && path_bok == 0x01) { /* Tx IQK OK */ + RF_DBG(dm, DBG_RF_IQK, "path B Only Tx IQK Success!!\n"); + result[t][4] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + result[t][5] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + } + } + + if (0x00 == path_bok) + RF_DBG(dm, DBG_RF_IQK, "path B IQK failed!!\n"); + } + + /* Back to BB mode, load original value */ + RF_DBG(dm, DBG_RF_IQK, "IQK:Back to BB mode, load original value!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0); + + if (t != 0) { + if (!dm->rf_calibrate_info.is_rf_pi_enable) { + /* Switch back BB to SI mode after finish IQ Calibration. */ + _phy_pi_mode_switch(dm, false); + } + /* Reload ADDA power saving parameters */ + _phy_reload_adda_registers(dm, ADDA_REG, dm->rf_calibrate_info.ADDA_backup, IQK_ADDA_REG_NUM); + + /* Reload MAC parameters */ + _phy_reload_mac_registers(dm, IQK_MAC_REG, dm->rf_calibrate_info.IQK_MAC_backup); + + _phy_reload_adda_registers(dm, IQK_BB_REG_92C, dm->rf_calibrate_info.IQK_BB_backup, IQK_BB_REG_NUM); + + /* Restore RX initial gain */ + odm_set_bb_reg(dm, REG_FPGA0_XA_LSSI_PARAMETER, MASKDWORD, 0x00032ed3); + if (is2T) + odm_set_bb_reg(dm, REG_FPGA0_XB_LSSI_PARAMETER, MASKDWORD, 0x00032ed3); + + /* load 0xe30 IQC default value */ + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x01008c00); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x01008c00); + + } + RF_DBG(dm, DBG_RF_IQK, "_phy_iq_calibrate_8188e() <==\n"); +} + + +void +_phy_lc_calibrate_8188e( + struct dm_struct *dm, + boolean is2T +) +{ + u8 tmp_reg; + u32 rf_amode = 0, rf_bmode = 0, lc_cal, cnt; + + /* Check continuous TX and Packet TX */ + tmp_reg = odm_read_1byte(dm, 0xd03); + + if ((tmp_reg & 0x70) != 0) /* Deal with contisuous TX case */ + ;/* odm_write_1byte(dm, 0xd03, tmp_reg&0x8F); */ /* disable all continuous TX */ + else /* Deal with Packet TX case */ + odm_write_1byte(dm, REG_TXPAUSE, 0xFF); /* block all queues */ + + if ((tmp_reg & 0x70) != 0) { + /* 1. Read original RF mode */ + /* path-A */ + + rf_amode = odm_get_rf_reg(dm, RF_PATH_A, RF_AC, MASK20BITS); + + /* path-B */ + if (is2T) + rf_bmode = odm_get_rf_reg(dm, RF_PATH_B, RF_AC, MASK12BITS); + + /* 2. Set RF mode = standby mode */ + /* path-A */ + odm_set_rf_reg(dm, RF_PATH_A, RF_AC, MASK20BITS, (rf_amode & 0x8FFFF) | 0x10000); + + /* path-B */ + if (is2T) + odm_set_rf_reg(dm, RF_PATH_B, RF_AC, MASK20BITS, (rf_bmode & 0x8FFFF) | 0x10000); + } + + /* 3. Read RF reg18 */ + lc_cal = odm_get_rf_reg(dm, RF_PATH_A, RF_CHNLBW, MASK20BITS); + + /* 4. Set LC calibration begin bit15 */ + odm_set_rf_reg(dm, RF_PATH_A, RF_CHNLBW, MASK20BITS, lc_cal | 0x08000); + ODM_delay_ms(100); + for (cnt = 0; cnt < 5; cnt++) { + if (odm_get_rf_reg(dm, RF_PATH_A, RF_CHNLBW, 0x8000) != 0x1) + break; + ODM_delay_ms(10); + } + if (cnt == 5) + RF_DBG(dm, DBG_RF_LCK, "LCK time out\n"); + + /*recover channel number*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_CHNLBW, MASK20BITS, lc_cal); + + /* Restore original situation */ + if ((tmp_reg & 0x70) != 0) { /* Deal with contisuous TX case */ + /* path-A */ + /* odm_write_1byte(dm, 0xd03, tmp_reg); */ + odm_set_rf_reg(dm, RF_PATH_A, RF_AC, MASK20BITS, rf_amode); + + /* path-B */ + if (is2T) + odm_set_rf_reg(dm, RF_PATH_B, RF_AC, MASK20BITS, rf_bmode); + } else /* Deal with Packet TX case */ + odm_write_1byte(dm, REG_TXPAUSE, 0x00); +} + +void +phy_iq_calibrate_8188e( + struct dm_struct *dm, + boolean is_recovery +) +{ + struct dm_iqk_info *iqk_info = &dm->IQK_info; + s32 result[4][8]; /* last is final result */ + u8 i, final_candidate, indexforchannel; + /* u8 channel_to_iqk = 7; */ + boolean is_patha_ok, is_pathb_ok; + s32 rege94, rege9c, regea4, regeac, regeb4, regebc, regec4, regecc, reg_tmp = 0; + boolean is12simular, is13simular, is23simular; + u32 IQK_BB_REG_92C[IQK_BB_REG_NUM] = { + REG_OFDM_0_XA_RX_IQ_IMBALANCE, REG_OFDM_0_XB_RX_IQ_IMBALANCE, + REG_OFDM_0_ECCA_THRESHOLD, REG_OFDM_0_AGC_RSSI_TABLE, + REG_OFDM_0_XA_TX_IQ_IMBALANCE, REG_OFDM_0_XB_TX_IQ_IMBALANCE, + REG_OFDM_0_XC_TX_AFE, REG_OFDM_0_XD_TX_AFE, + REG_OFDM_0_RX_IQ_EXT_ANTA + }; + + if (is_recovery) { + RF_DBG(dm, DBG_RF_INIT, "phy_iq_calibrate_8188e: Return due to is_recovery!\n"); + _phy_reload_adda_registers(dm, IQK_BB_REG_92C, dm->rf_calibrate_info.IQK_BB_backup_recover, 9); + return; + } + RF_DBG(dm, DBG_RF_IQK, "IQK:Start!!!\n"); + iqk_info->iqk_times++; + /*priv->pshare->IQK_total_cnt++;*/ + + for (i = 0; i < 8; i++) { + result[0][i] = 0; + result[1][i] = 0; + result[2][i] = 0; + result[3][i] = 0; + } + final_candidate = 0xff; + is_patha_ok = false; + is_pathb_ok = false; + is12simular = false; + is23simular = false; + is13simular = false; + + for (i = 0; i < 3; i++) { + /* For 88C 1T1R */ + _phy_iq_calibrate_8188e(dm, result, i, false); + if (i == 1) { + is12simular = phy_simularity_compare_8188e(dm, result, 0, 1); + if (is12simular) { + final_candidate = 0; + RF_DBG(dm, DBG_RF_IQK, "IQK: is12simular final_candidate is %x\n", final_candidate); + break; + } + } + if (i == 2) { + is13simular = phy_simularity_compare_8188e(dm, result, 0, 2); + if (is13simular) { + final_candidate = 0; + RF_DBG(dm, DBG_RF_IQK, "IQK: is13simular final_candidate is %x\n", final_candidate); + break; + } + is23simular = phy_simularity_compare_8188e(dm, result, 1, 2); + if (is23simular) { + final_candidate = 1; + RF_DBG(dm, DBG_RF_IQK, "IQK: is23simular final_candidate is %x\n", final_candidate); + } else { + for (i = 0; i < 8; i++) + reg_tmp += result[3][i]; + + if (reg_tmp != 0) + final_candidate = 3; + else + final_candidate = 0xFF; + } + } + } + /* RT_TRACE(COMP_INIT,DBG_LOUD,("Release Mutex in IQCalibrate\n")); */ + for (i = 0; i < 4; i++) { + rege94 = result[i][0]; + rege9c = result[i][1]; + regea4 = result[i][2]; + regeac = result[i][3]; + regeb4 = result[i][4]; + regebc = result[i][5]; + regec4 = result[i][6]; + regecc = result[i][7]; + RF_DBG(dm, DBG_RF_IQK, "IQK: rege94=%x rege9c=%x regea4=%x regeac=%x regeb4=%x regebc=%x regec4=%x regecc=%x\n ", rege94, rege9c, regea4, regeac, regeb4, regebc, regec4, regecc); + } + if (final_candidate != 0xff) { + dm->rf_calibrate_info.rege94 = rege94 = result[final_candidate][0]; + dm->rf_calibrate_info.rege9c = rege9c = result[final_candidate][1]; + regea4 = result[final_candidate][2]; + regeac = result[final_candidate][3]; + dm->rf_calibrate_info.regeb4 = regeb4 = result[final_candidate][4]; + dm->rf_calibrate_info.regebc = regebc = result[final_candidate][5]; + regec4 = result[final_candidate][6]; + regecc = result[final_candidate][7]; + RF_DBG(dm, DBG_RF_IQK, "IQK: final_candidate is %x\n", final_candidate); + RF_DBG(dm, DBG_RF_IQK, "IQK: rege94=%x rege9c=%x regea4=%x regeac=%x regeb4=%x regebc=%x regec4=%x regecc=%x\n ", rege94, rege9c, regea4, regeac, regeb4, regebc, regec4, regecc); + is_patha_ok = is_pathb_ok = true; + } else { + RF_DBG(dm, DBG_RF_IQK, "IQK: FAIL use default value\n"); + + dm->rf_calibrate_info.rege94 = dm->rf_calibrate_info.regeb4 = 0x100; /* X default value */ + dm->rf_calibrate_info.rege9c = dm->rf_calibrate_info.regebc = 0x0; /* Y default value */ + /*priv->pshare->IQK_fail_cnt++;*/ + } + + if ((rege94 != 0)/*&&(regea4 != 0)*/) + _phy_path_a_fill_iqk_matrix(dm, is_patha_ok, result, final_candidate, (regea4 == 0)); + + indexforchannel = 0; + + /* To Fix BSOD when final_candidate is 0xff + * by sherry 20120321 */ + if (final_candidate < 4) { + for (i = 0; i < iqk_matrix_reg_num; i++) + dm->rf_calibrate_info.iqk_matrix_reg_setting[indexforchannel].value[0][i] = result[final_candidate][i]; + dm->rf_calibrate_info.iqk_matrix_reg_setting[indexforchannel].is_iqk_done = true; + } + /* RTPRINT(FINIT, INIT_IQK, ("\nIQK OK indexforchannel %d.\n", indexforchannel)); */ + RF_DBG(dm, DBG_RF_IQK, "\nIQK OK indexforchannel %d.\n", indexforchannel); + _phy_save_adda_registers(dm, IQK_BB_REG_92C, dm->rf_calibrate_info.IQK_BB_backup_recover, IQK_BB_REG_NUM); + + RF_DBG(dm, DBG_RF_IQK, "IQK finished\n"); +#if 0 /* Suggested by Edlu,120413 */ + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + adapter->hal_func.sw_chnl_by_timer_handler(adapter, origin_channel); +#elif (DM_ODM_SUPPORT_TYPE == ODM_CE) + adapter->hal_func.set_channel_handler(adapter, origin_channel); +#endif +#endif +} + + +void +phy_lc_calibrate_8188e( + struct dm_struct *dm +) +{ + _phy_lc_calibrate_8188e(dm, false); +} + + +void _phy_set_rf_path_switch_8188e( + struct dm_struct *dm, + boolean is_main, + boolean is2T +) +{ + if (is2T) { /* 92C */ + if (is_main) + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(6), 0x1); /* 92C_Path_A */ + else + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(6), 0x2); /* BT */ + } else { /* 88C */ + + /* <20120504, Kordan> [8188E] We should make AntDiversity controlled by HW (0x870[9:8] = 0), */ + /* otherwise the following action has no effect. (0x860[9:8] has the effect only if AntDiversity controlled by SW) */ + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_INTERFACE_SW, BIT(8) | BIT(9), 0x0); + odm_set_bb_reg(dm, R_0x914, MASKLWORD, 0x0201); /* Set up the ant mapping table */ + + if (is_main) { + /* odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(8)|BIT9, 0x2); */ /* Tx Main (SW control)(The right antenna) */ + /* 4 [ Tx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(14) | BIT(13) | BIT(12), 0x1); /* Tx Main (HW control)(The right antenna) */ + + /* 4 [ Rx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(4) | BIT(3), 0x1); /* ant_div_type = TRDiv, right antenna */ + if (dm->ant_div_type == CGCS_RX_HW_ANTDIV) + odm_set_bb_reg(dm, R_0xb2c, BIT(31), 0x1); /* RxCG, Default is RxCG. ant_div_type = 2RDiv, left antenna */ + + } else { + /* odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(8)|BIT9, 0x1); */ /* Tx Aux (SW control)(The left antenna) */ + /* 4 [ Tx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(14) | BIT(13) | BIT(12), 0x0); /* Tx Aux (HW control)(The left antenna) */ + + /* 4 [ Rx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(4) | BIT(3), 0x0); /* ant_div_type = TRDiv, left antenna */ + if (dm->ant_div_type == CGCS_RX_HW_ANTDIV) + odm_set_bb_reg(dm, R_0xb2c, BIT(31), 0x0); /* RxCS, ant_div_type = 2RDiv, right antenna */ + } + + } +} +void phy_set_rf_path_switch_8188e( + struct dm_struct *dm, + boolean is_main +) +{ +#ifdef DISABLE_BB_RF + return; +#endif + + { + /* For 88C 1T1R */ + _phy_set_rf_path_switch_8188e(dm, is_main, false); + } +} diff --git a/hal/phydm/halrf/rtl8188e/halrf_8188e_ap.h b/hal/phydm/halrf/rtl8188e/halrf_8188e_ap.h new file mode 100644 index 0000000..10ecd2d --- /dev/null +++ b/hal/phydm/halrf/rtl8188e/halrf_8188e_ap.h @@ -0,0 +1,104 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#ifndef __HALRF_8188E_H__ +#define __HALRF_8188E_H__ + +/*--------------------------Define Parameters-------------------------------*/ +#define IQK_DELAY_TIME_88E 10 /* ms */ +#define index_mapping_NUM_88E 15 +#define AVG_THERMAL_NUM_88E 4 + +#include "../halphyrf_ap.h" + +void configure_txpower_track_8188e( + struct txpwrtrack_cfg *config +); + +void do_iqk_8188e( + void *dm_void, + u8 delta_thermal_index, + u8 thermal_value, + u8 threshold +); + +void +odm_tx_pwr_track_set_pwr88_e( + struct dm_struct *dm, + enum pwrtrack_method method, + u8 rf_path, + u8 channel_mapped_index +); + +/* 1 7. IQK */ + +void +phy_iq_calibrate_8188e( + struct dm_struct *dm, + boolean is_recovery); + + +/* + * LC calibrate + * */ +void +phy_lc_calibrate_8188e( + struct dm_struct *dm +); + +/* + * AP calibrate + * */ +void +phy_ap_calibrate_8188e( + struct dm_struct *dm, + s8 delta); + +void +_phy_save_adda_registers( + struct dm_struct *dm, + u32 *adda_reg, + u32 *adda_backup, + u32 register_num +); + +void +_phy_path_adda_on( + struct dm_struct *dm, + u32 *adda_reg, + boolean is_path_a_on, + boolean is2T +); + +void +_phy_mac_setting_calibration( + struct dm_struct *dm, + u32 *mac_reg, + u32 *mac_backup +); + + +void +_phy_path_a_stand_by( + struct dm_struct *dm +); + +void +halrf_rf_lna_setting_8188e( + struct dm_struct *dm, + enum halrf_lna_set type +); + +#endif /*#ifndef __HALRF_8188E_H__*/ diff --git a/hal/phydm/halrf/rtl8188e/halrf_8188e_ce.c b/hal/phydm/halrf/rtl8188e/halrf_8188e_ce.c new file mode 100644 index 0000000..6f01ff6 --- /dev/null +++ b/hal/phydm/halrf/rtl8188e/halrf_8188e_ce.c @@ -0,0 +1,1600 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#include "mp_precomp.h" +#include "../../phydm_precomp.h" + +/*---------------------------Define Local Constant---------------------------*/ +/* 2010/04/25 MH Define the max tx power tracking tx agc power. */ +#define ODM_TXPWRTRACK_MAX_IDX_88E 6 + +/*---------------------------Define Local Constant---------------------------*/ + +/* 3============================================================ + * 3 Tx Power Tracking + * 3============================================================ */ + +void halrf_rf_lna_setting_8188e(struct dm_struct *dm, enum halrf_lna_set type) +{ + /*phydm_disable_lna*/ + if (type == HALRF_LNA_DISABLE) { + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x30, 0xfffff, 0x18000); /*select Rx mode*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x32, 0xfffff, 0x37f82); /*disable LNA*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x0); + if (dm->rf_type > RF_1T1R) { + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x30, 0xfffff, 0x18000); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x32, 0xfffff, 0x37f82); + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x0); + } + } else if (type == HALRF_LNA_ENABLE) { + /*phydm_enable_lna*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x30, 0xfffff, 0x18000); /*select Rx mode*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x32, 0xfffff, 0x77f82); /*back to normal*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x0); + if (dm->rf_type > RF_1T1R) { + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x30, 0xfffff, 0x18000); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x32, 0xfffff, 0x77f82); + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x0); + } + } +} + +void set_iqk_matrix_8188e(struct dm_struct *dm, u8 OFDM_index, u8 rf_path, + s32 iqk_result_x, s32 iqk_result_y) +{ + s32 ele_A = 0, ele_D, ele_C = 0, value32; + + ele_D = (ofdm_swing_table_new[OFDM_index] & 0xFFC00000) >> 22; + + /* new element A = element D x X */ + if (iqk_result_x != 0 && (*dm->band_type == ODM_BAND_2_4G)) { + if ((iqk_result_x & 0x00000200) != 0) /* consider minus */ + iqk_result_x = iqk_result_x | 0xFFFFFC00; + ele_A = ((iqk_result_x * ele_D) >> 8) & 0x000003FF; + + /* new element C = element D x Y */ + if ((iqk_result_y & 0x00000200) != 0) + iqk_result_y = iqk_result_y | 0xFFFFFC00; + ele_C = ((iqk_result_y * ele_D) >> 8) & 0x000003FF; + + /* if (rf_path == RF_PATH_A) */ + switch (rf_path) { + case RF_PATH_A: + /* wirte new elements A, C, D to regC80 and regC94, element B is always 0 */ + value32 = (ele_D << 22) | ((ele_C & 0x3F) << 16) | ele_A; + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD, value32); + + value32 = (ele_C & 0x000003C0) >> 6; + odm_set_bb_reg(dm, REG_OFDM_0_XC_TX_AFE, MASKH4BITS, value32); + + value32 = ((iqk_result_x * ele_D) >> 7) & 0x01; + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), value32); + break; + case RF_PATH_B: + /* wirte new elements A, C, D to regC88 and regC9C, element B is always 0 */ + value32 = (ele_D << 22) | ((ele_C & 0x3F) << 16) | ele_A; + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD, value32); + + value32 = (ele_C & 0x000003C0) >> 6; + odm_set_bb_reg(dm, REG_OFDM_0_XD_TX_AFE, MASKH4BITS, value32); + + value32 = ((iqk_result_x * ele_D) >> 7) & 0x01; + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), value32); + + break; + default: + break; + } + } else { + switch (rf_path) { + case RF_PATH_A: + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD, ofdm_swing_table_new[OFDM_index]); + odm_set_bb_reg(dm, REG_OFDM_0_XC_TX_AFE, MASKH4BITS, 0x00); + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), 0x00); + break; + + case RF_PATH_B: + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD, ofdm_swing_table_new[OFDM_index]); + odm_set_bb_reg(dm, REG_OFDM_0_XD_TX_AFE, MASKH4BITS, 0x00); + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), 0x00); + break; + + default: + break; + } + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "TxPwrTracking path B: X = 0x%x, Y = 0x%x ele_A = 0x%x ele_C = 0x%x ele_D = 0x%x 0xeb4 = 0x%x 0xebc = 0x%x\n", + (u32)iqk_result_x, (u32)iqk_result_y, (u32)ele_A, (u32)ele_C, + (u32)ele_D, (u32)iqk_result_x, (u32)iqk_result_y); +} + +void do_iqk_8188e(void *dm_void, u8 delta_thermal_index, u8 thermal_value, + u8 threshold) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + odm_reset_iqk_result(dm); + dm->rf_calibrate_info.thermal_value_iqk = thermal_value; + halrf_iqk_trigger(dm, false); +} + +/*----------------------------------------------------------------------------- + * Function: odm_TxPwrTrackSetPwr88E() + * + * Overview: 88E change all channel tx power accordign to flag. + * OFDM & CCK are all different. + * + * Input: NONE + * + * Output: NONE + * + * Return: NONE + * + * Revised History: + * When Who Remark + * 04/23/2012 MHC Create version 0. + * + *---------------------------------------------------------------------------*/ +void odm_tx_pwr_track_set_pwr88_e(void *dm_void, enum pwrtrack_method method, + u8 rf_path, u8 channel_mapped_index) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _ADAPTER *adapter = dm->adapter; + PHAL_DATA_TYPE hal_data = GET_HAL_DATA(adapter); + u8 pwr_tracking_limit_ofdm = 30; /* +0dB */ + u8 pwr_tracking_limit_cck = 28; /* -2dB */ + u8 tx_rate = 0xFF; + u8 final_ofdm_swing_index = 0; + u8 final_cck_swing_index = 0; + u8 i = 0; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct _hal_rf_ *rf = &(dm->rf_table); + + if (*dm->mp_mode == true) { +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) +#if (MP_DRIVER == 1) + PMPT_CONTEXT p_mpt_ctx = &(adapter->mpt_ctx); + + tx_rate = mpt_to_mgnt_rate(p_mpt_ctx->mpt_rate_index); +#endif +#elif (DM_ODM_SUPPORT_TYPE & ODM_CE) +#ifdef CONFIG_MP_INCLUDED + PMPT_CONTEXT p_mpt_ctx = &(adapter->mppriv.mpt_ctx); + + tx_rate = mpt_to_mgnt_rate(p_mpt_ctx->mpt_rate_index); +#endif +#endif +#endif + } else { + u16 rate = *(dm->forced_data_rate); + + if (!rate) { /*auto rate*/ +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) + tx_rate = adapter->HalFunc.GetHwRateFromMRateHandler(dm->tx_rate); +#elif (DM_ODM_SUPPORT_TYPE & ODM_CE) + if (dm->number_linked_client != 0) + tx_rate = hw_rate_to_m_rate(dm->tx_rate); + else + tx_rate = rf->p_rate_index; +#endif + } else /*force rate*/ + tx_rate = (u8)rate; + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Power Tracking tx_rate=0x%X\n", + tx_rate); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "===>ODM_TxPwrTrackSetPwr8188E\n"); + + if (tx_rate != 0xFF) { + /* 2 CCK */ + if ((tx_rate >= MGN_1M && tx_rate <= MGN_5_5M) || tx_rate == MGN_11M) + pwr_tracking_limit_cck = 28; /* -2dB */ + /* 2 OFDM */ + else if ((tx_rate >= MGN_6M) && (tx_rate <= MGN_48M)) + pwr_tracking_limit_ofdm = 36; /* +3dB */ + else if (tx_rate == MGN_54M) + pwr_tracking_limit_ofdm = 34; /* +2dB */ + + /* 2 HT */ + else if ((tx_rate >= MGN_MCS0) && (tx_rate <= MGN_MCS2)) /* QPSK/BPSK */ + pwr_tracking_limit_ofdm = 38; /* +4dB */ + else if ((tx_rate >= MGN_MCS3) && (tx_rate <= MGN_MCS4)) /* 16QAM */ + pwr_tracking_limit_ofdm = 36; /* +3dB */ + else if ((tx_rate >= MGN_MCS5) && (tx_rate <= MGN_MCS7)) /* 64QAM */ + pwr_tracking_limit_ofdm = 34; /* +2dB */ + + else + pwr_tracking_limit_ofdm = cali_info->default_ofdm_index; /*Default OFDM index = 30*/ + } + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "tx_rate=0x%x, pwr_tracking_limit=%d\n", + tx_rate, pwr_tracking_limit_ofdm); + + if (method == TXAGC) { + u32 pwr = 0, tx_agc = 0; + void *adapter = dm->adapter; + + cali_info->remnant_ofdm_swing_idx[rf_path] = cali_info->absolute_ofdm_swing_idx[rf_path]; /*Remnant index equal to aboslute compensate value.*/ + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "odm_TxPwrTrackSetPwr88E CH=%d\n", *(dm->channel)); + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + + if (*dm->mp_mode == true) { + pwr = phy_query_bb_reg(adapter, REG_TX_AGC_A_RATE18_06, 0xFF); + pwr += dm->rf_calibrate_info.power_index_offset[RF_PATH_A]; + phy_set_bb_reg(adapter, REG_TX_AGC_A_CCK_1_MCS32, MASKBYTE1, pwr); + tx_agc = (pwr << 16) | (pwr << 8) | (pwr); + phy_set_bb_reg(adapter, REG_TX_AGC_B_CCK_11_A_CCK_2_11, MASKH3BYTES, tx_agc); + /* RT_DISP(FPHY, PHY_TXPWR, ("odm_tx_pwr_track_set_pwr88_e: CCK Tx-rf(A) Power = 0x%x\n", tx_agc)); */ + + pwr = phy_query_bb_reg(adapter, REG_TX_AGC_A_RATE18_06, 0xFF); + pwr += (cali_info->bb_swing_idx_ofdm[RF_PATH_A] - cali_info->bb_swing_idx_ofdm_base[RF_PATH_A]); + tx_agc |= ((pwr << 24) | (pwr << 16) | (pwr << 8) | pwr); + phy_set_bb_reg(adapter, REG_TX_AGC_A_RATE18_06, MASKDWORD, tx_agc); + phy_set_bb_reg(adapter, REG_TX_AGC_A_RATE54_24, MASKDWORD, tx_agc); + phy_set_bb_reg(adapter, REG_TX_AGC_A_MCS03_MCS00, MASKDWORD, tx_agc); + phy_set_bb_reg(adapter, REG_TX_AGC_A_MCS07_MCS04, MASKDWORD, tx_agc); + phy_set_bb_reg(adapter, REG_TX_AGC_A_MCS11_MCS08, MASKDWORD, tx_agc); + phy_set_bb_reg(adapter, REG_TX_AGC_A_MCS15_MCS12, MASKDWORD, tx_agc); + /* RT_DISP(FPHY, PHY_TXPWR, ("odm_tx_pwr_track_set_pwr88_e: OFDM Tx-rf(A) Power = 0x%x\n", tx_agc)); */ + } else { + /* phy_set_tx_power_level8188e(dm->adapter, *dm->channel); */ + cali_info->modify_tx_agc_flag_path_a = true; + cali_info->modify_tx_agc_flag_path_a_cck = true; + + if (rf_path == RF_PATH_A) { + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, CCK); + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, OFDM); + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, HT_MCS0_MCS7); + } + } + +#endif +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) +/* phy_rf6052_set_cck_tx_power(dm->priv, *(dm->channel)); */ +/* phy_rf6052_set_ofdm_tx_power(dm->priv, *(dm->channel)); */ +#endif + + } else if (method == BBSWING) { + final_ofdm_swing_index = cali_info->default_ofdm_index + cali_info->absolute_ofdm_swing_idx[rf_path]; + final_cck_swing_index = cali_info->default_cck_index + cali_info->absolute_ofdm_swing_idx[rf_path]; + + if (final_ofdm_swing_index >= pwr_tracking_limit_ofdm) + final_ofdm_swing_index = pwr_tracking_limit_ofdm; + else if (final_ofdm_swing_index <= 0) + final_ofdm_swing_index = 0; + + if (final_cck_swing_index >= CCK_TABLE_SIZE) + final_cck_swing_index = CCK_TABLE_SIZE - 1; + else if (cali_info->bb_swing_idx_cck <= 0) + final_cck_swing_index = 0; + + /* Adjust BB swing by OFDM IQ matrix */ + if (rf_path == RF_PATH_A) { + set_iqk_matrix_8188e(dm, final_ofdm_swing_index, RF_PATH_A, + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][0], + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][1]); + /* Adjust BB swing by CCK filter coefficient */ + if (*dm->channel != 14) { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch1_ch13_new[final_cck_swing_index][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch1_ch13_new[final_cck_swing_index][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch1_ch13_new[final_cck_swing_index][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch1_ch13_new[final_cck_swing_index][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch1_ch13_new[final_cck_swing_index][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch1_ch13_new[final_cck_swing_index][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch1_ch13_new[final_cck_swing_index][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch1_ch13_new[final_cck_swing_index][7]); + } else { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch14_new[final_cck_swing_index][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch14_new[final_cck_swing_index][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch14_new[final_cck_swing_index][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch14_new[final_cck_swing_index][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch14_new[final_cck_swing_index][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch14_new[final_cck_swing_index][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch14_new[final_cck_swing_index][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch14_new[final_cck_swing_index][7]); + } + } + } else if (method == MIX_MODE) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "cali_info->default_ofdm_index=%d, dm->DefaultCCKIndex=%d, cali_info->absolute_ofdm_swing_idx[rf_path]=%d, rf_path = %d\n", + cali_info->default_ofdm_index, + cali_info->default_cck_index, + cali_info->absolute_ofdm_swing_idx[rf_path], rf_path); + + final_cck_swing_index = cali_info->default_cck_index + cali_info->absolute_ofdm_swing_idx[rf_path]; + final_ofdm_swing_index = cali_info->default_ofdm_index + cali_info->absolute_ofdm_swing_idx[rf_path]; + + if (final_ofdm_swing_index > pwr_tracking_limit_ofdm) { /* BBSwing higher then Limit */ + cali_info->remnant_ofdm_swing_idx[rf_path] = final_ofdm_swing_index - pwr_tracking_limit_ofdm; + + set_iqk_matrix_8188e(dm, pwr_tracking_limit_ofdm, RF_PATH_A, + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][0], + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][1]); + + cali_info->modify_tx_agc_flag_path_a = true; + + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, OFDM); + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, HT_MCS0_MCS7); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Path_A Over BBSwing Limit, pwr_tracking_limit = %d, Remnant tx_agc value = %d\n", + pwr_tracking_limit_ofdm, + cali_info->remnant_ofdm_swing_idx[rf_path]); + } else if (final_ofdm_swing_index <= 0) { + cali_info->remnant_ofdm_swing_idx[rf_path] = final_ofdm_swing_index; + + set_iqk_matrix_8188e(dm, 0, RF_PATH_A, + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][0], + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][1]); + + cali_info->modify_tx_agc_flag_path_a = true; + + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, OFDM); + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, HT_MCS0_MCS7); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Path_A Lower then BBSwing lower bound 0, Remnant tx_agc value = %d\n", + cali_info->remnant_ofdm_swing_idx[rf_path]); + } else { + set_iqk_matrix_8188e(dm, final_ofdm_swing_index, RF_PATH_A, + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][0], + dm->rf_calibrate_info.iqk_matrix_reg_setting[channel_mapped_index].value[0][1]); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Path_A Compensate with BBSwing, final_ofdm_swing_index = %d\n", + final_ofdm_swing_index); + + if (cali_info->modify_tx_agc_flag_path_a) { /*If tx_agc has changed, reset tx_agc again*/ + cali_info->remnant_ofdm_swing_idx[rf_path] = 0; + + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, OFDM); + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, HT_MCS0_MCS7); + + cali_info->modify_tx_agc_flag_path_a = false; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Path_A dm->Modify_TxAGC_Flag = false\n"); + } + } + + if (final_cck_swing_index > pwr_tracking_limit_cck) { + cali_info->remnant_cck_swing_idx = final_cck_swing_index - pwr_tracking_limit_cck; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Path_A CCK Over Limit, pwr_tracking_limit_cck = %d, cali_info->remnant_cck_swing_idx = %d\n", + pwr_tracking_limit_cck, + cali_info->remnant_cck_swing_idx); + + /* Adjust BB swing by CCK filter coefficient */ + + if (*dm->channel != 14) { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][7]); + } else { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch14_new[pwr_tracking_limit_cck][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch14_new[pwr_tracking_limit_cck][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch14_new[pwr_tracking_limit_cck][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch14_new[pwr_tracking_limit_cck][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch14_new[pwr_tracking_limit_cck][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch14_new[pwr_tracking_limit_cck][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch14_new[pwr_tracking_limit_cck][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch14_new[pwr_tracking_limit_cck][7]); + } + + cali_info->modify_tx_agc_flag_path_a_cck = true; + + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, CCK); + + } else if (final_cck_swing_index <= 0) { /* Lowest CCK index = 0 */ + cali_info->remnant_cck_swing_idx = final_cck_swing_index; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Path_A CCK Under Limit, pwr_tracking_limit_cck = %d, cali_info->remnant_cck_swing_idx = %d\n", + 0, cali_info->remnant_cck_swing_idx); + + if (*dm->channel != 14) { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch1_ch13_new[0][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch1_ch13_new[0][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch1_ch13_new[0][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch1_ch13_new[0][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch1_ch13_new[0][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch1_ch13_new[0][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch1_ch13_new[0][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch1_ch13_new[0][7]); + } else { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch14_new[0][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch14_new[0][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch14_new[0][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch14_new[0][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch14_new[0][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch14_new[0][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch14_new[0][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch14_new[0][7]); + } + + cali_info->modify_tx_agc_flag_path_a_cck = true; + + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, CCK); + + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Path_A CCK Compensate with BBSwing, final_cck_swing_index = %d\n", + final_cck_swing_index); + + if (*dm->channel != 14) { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch1_ch13_new[final_cck_swing_index][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch1_ch13_new[final_cck_swing_index][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch1_ch13_new[final_cck_swing_index][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch1_ch13_new[final_cck_swing_index][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch1_ch13_new[final_cck_swing_index][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch1_ch13_new[final_cck_swing_index][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch1_ch13_new[final_cck_swing_index][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch1_ch13_new[final_cck_swing_index][7]); + } else { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch14_new[final_cck_swing_index][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch14_new[final_cck_swing_index][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch14_new[final_cck_swing_index][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch14_new[final_cck_swing_index][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch14_new[final_cck_swing_index][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch14_new[final_cck_swing_index][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch14_new[final_cck_swing_index][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch14_new[final_cck_swing_index][7]); + } + + if (cali_info->modify_tx_agc_flag_path_a_cck) { /*If tx_agc has changed, reset tx_agc again*/ + cali_info->remnant_cck_swing_idx = 0; + phy_set_tx_power_index_by_rate_section(adapter, RF_PATH_A, *dm->channel, CCK); + cali_info->modify_tx_agc_flag_path_a_cck = false; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, + "******Path_A dm->Modify_TxAGC_Flag_CCK = false\n"); + } + } + } else + return; +} /* odm_TxPwrTrackSetPwr88E */ + +void get_delta_swing_table_8188e(void *dm_void, u8 **temperature_up_a, + u8 **temperature_down_a, u8 **temperature_up_b, + u8 **temperature_down_b) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _ADAPTER *adapter = dm->adapter; + PHAL_DATA_TYPE hal_data = GET_HAL_DATA(adapter); + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + struct _hal_rf_ *rf = &(dm->rf_table); + + u8 tx_rate = 0xFF; + u8 channel = *dm->channel; + + if (*dm->mp_mode == true) { +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) +#if (MP_DRIVER == 1) + PMPT_CONTEXT p_mpt_ctx = &(adapter->mpt_ctx); + + tx_rate = mpt_to_mgnt_rate(p_mpt_ctx->mpt_rate_index); +#endif +#elif (DM_ODM_SUPPORT_TYPE & ODM_CE) +#ifdef CONFIG_MP_INCLUDED + PMPT_CONTEXT p_mpt_ctx = &(adapter->mppriv.mpt_ctx); + + tx_rate = mpt_to_mgnt_rate(p_mpt_ctx->mpt_rate_index); +#endif +#endif +#endif + } else { + u16 rate = *(dm->forced_data_rate); + + if (!rate) { /*auto rate*/ +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) + tx_rate = adapter->HalFunc.GetHwRateFromMRateHandler(dm->tx_rate); +#elif (DM_ODM_SUPPORT_TYPE & ODM_CE) + if (dm->number_linked_client != 0) + tx_rate = hw_rate_to_m_rate(dm->tx_rate); + else + tx_rate = rf->p_rate_index; +#endif + } else /*force rate*/ + tx_rate = (u8)rate; + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Power Tracking tx_rate=0x%X\n", + tx_rate); + + if (1 <= channel && channel <= 14) { + if (IS_CCK_RATE(tx_rate)) { + *temperature_up_a = cali_info->delta_swing_table_idx_2g_cck_a_p; + *temperature_down_a = cali_info->delta_swing_table_idx_2g_cck_a_n; + } else { + *temperature_up_a = cali_info->delta_swing_table_idx_2ga_p; + *temperature_down_a = cali_info->delta_swing_table_idx_2ga_n; + } + } else { + *temperature_up_a = (u8 *)delta_swing_table_idx_2ga_p_8188e; + *temperature_down_a = (u8 *)delta_swing_table_idx_2ga_n_8188e; + } +} + +void configure_txpower_track_8188e(struct txpwrtrack_cfg *config) +{ + config->swing_table_size_cck = CCK_TABLE_SIZE; + config->swing_table_size_ofdm = OFDM_TABLE_SIZE; + config->threshold_iqk = IQK_THRESHOLD; + config->average_thermal_num = AVG_THERMAL_NUM_88E; + config->rf_path_count = MAX_PATH_NUM_8188E; + config->thermal_reg_addr = RF_T_METER_88E; + + config->odm_tx_pwr_track_set_pwr = odm_tx_pwr_track_set_pwr88_e; + config->do_iqk = do_iqk_8188e; + config->phy_lc_calibrate = halrf_lck_trigger; + config->get_delta_swing_table = get_delta_swing_table_8188e; +} + +/* 1 7. IQK */ +#define MAX_TOLERANCE 5 +#define IQK_DELAY_TIME 1 /* ms */ + +u8 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ + phy_path_a_iqk_8188e( + struct dm_struct *dm, + boolean config_path_b) +{ + u32 reg_eac, reg_e94, reg_e9c, reg_ea4; + u8 result = 0x00; + RF_DBG(dm, DBG_RF_IQK, "path A IQK!\n"); + + /* 1 Tx IQK */ + /* path-A IQK setting */ + RF_DBG(dm, DBG_RF_IQK, "path-A IQK setting!\n"); + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x10008c1c); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x30008c1c); + odm_set_bb_reg(dm, REG_TX_IQK_PI_A, MASKDWORD, 0x8214032a); + odm_set_bb_reg(dm, REG_RX_IQK_PI_A, MASKDWORD, 0x28160000); + + /* LO calibration setting */ + RF_DBG(dm, DBG_RF_IQK, "LO calibration setting!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_RSP, MASKDWORD, 0x00462911); + + /* One shot, path A LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf9000000); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf8000000); + + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path A LOK & IQK.\n", + IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E); + + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_e94 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe94 = 0x%x\n", reg_e94); + reg_e9c = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe9c = 0x%x\n", reg_e9c); + reg_ea4 = odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xea4 = 0x%x\n", reg_ea4); + + if (!(reg_eac & BIT(28)) && + (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && + (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + else /* if Tx not OK, ignore Rx */ + return result; + +#if 0 + if (!(reg_eac & BIT(27)) && /* if Tx is OK, check whether Rx is OK */ + (((reg_ea4 & 0x03FF0000) >> 16) != 0x132) && + (((reg_eac & 0x03FF0000) >> 16) != 0x36)) + result |= 0x02; + else + RT_DISP(FINIT, INIT_IQK, ("path A Rx IQK fail!!\n")); +#endif + + return result; +} + +u8 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ + phy_path_a_rx_iqk( + struct dm_struct *dm, + boolean config_path_b) +{ + u32 reg_eac, reg_e94, reg_e9c, reg_ea4, u4tmp; + u8 result = 0x00; + + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK!\n"); + /* 1 Get TXIMR setting */ + /* modify RXIQK mode table */ + RF_DBG(dm, DBG_RF_IQK, "path-A Rx IQK modify RXIQK mode table!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, MASKH3BYTES, 0x000000); + odm_set_rf_reg(dm, RF_PATH_A, RF_WE_LUT, RFREGOFFSETMASK, 0x800a0); + odm_set_rf_reg(dm, RF_PATH_A, RF_RCK_OS, RFREGOFFSETMASK, 0x30000); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G1, RFREGOFFSETMASK, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G2, RFREGOFFSETMASK, 0xf117B); + odm_set_bb_reg(dm, REG_FPGA0_IQK, MASKH3BYTES, 0x808000); + + /* IQK setting */ + odm_set_bb_reg(dm, REG_TX_IQK, MASKDWORD, 0x01007c00); + odm_set_bb_reg(dm, REG_RX_IQK, MASKDWORD, 0x81004800); + + /* path-A IQK setting */ + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x10008c1c); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x30008c1c); + odm_set_bb_reg(dm, REG_TX_IQK_PI_A, MASKDWORD, 0x82160804); + odm_set_bb_reg(dm, REG_RX_IQK_PI_A, MASKDWORD, 0x28160000); + + /* LO calibration setting */ + RF_DBG(dm, DBG_RF_IQK, "LO calibration setting!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_RSP, MASKDWORD, 0x0046a911); + + /* One shot, path A LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf9000000); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf8000000); + + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path A LOK & IQK.\n", + IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E); + + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_e94 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe94 = 0x%x\n", reg_e94); + reg_e9c = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe9c = 0x%x\n", reg_e9c); + + if (!(reg_eac & BIT(28)) && + (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && + (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + else /* if Tx not OK, ignore Rx */ + return result; + + u4tmp = 0x80007C00 | (reg_e94 & 0x3FF0000) | ((reg_e9c & 0x3FF0000) >> 16); + odm_set_bb_reg(dm, REG_TX_IQK, MASKDWORD, u4tmp); + RF_DBG(dm, DBG_RF_IQK, "0xe40 = 0x%x u4tmp = 0x%x\n", + odm_get_bb_reg(dm, REG_TX_IQK, MASKDWORD), u4tmp); + + /* 1 RX IQK */ + /* modify RXIQK mode table */ + RF_DBG(dm, DBG_RF_IQK, "path-A Rx IQK modify RXIQK mode table 2!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, MASKH3BYTES, 0x000000); + odm_set_rf_reg(dm, RF_PATH_A, RF_WE_LUT, RFREGOFFSETMASK, 0x800a0); + odm_set_rf_reg(dm, RF_PATH_A, RF_RCK_OS, RFREGOFFSETMASK, 0x30000); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G1, RFREGOFFSETMASK, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G2, RFREGOFFSETMASK, 0xf7ffa); + odm_set_bb_reg(dm, REG_FPGA0_IQK, MASKH3BYTES, 0x808000); + + /* IQK setting */ + odm_set_bb_reg(dm, REG_RX_IQK, MASKDWORD, 0x01004800); + + /* path-A IQK setting */ + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x30008c1c); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x10008c1c); + odm_set_bb_reg(dm, REG_TX_IQK_PI_A, MASKDWORD, 0x82160c05); + odm_set_bb_reg(dm, REG_RX_IQK_PI_A, MASKDWORD, 0x28160c05); + + /* LO calibration setting */ + RF_DBG(dm, DBG_RF_IQK, "LO calibration setting!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_RSP, MASKDWORD, 0x0046a911); + + /* One shot, path A LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf9000000); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf8000000); + + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path A LOK & IQK.\n", + IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E); + + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_e94 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe94 = 0x%x\n", reg_e94); + reg_e9c = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe9c = 0x%x\n", reg_e9c); + reg_ea4 = odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xea4 = 0x%x\n", reg_ea4); + +#if 0 + if (!(reg_eac & BIT(28)) && + (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && + (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + else /* if Tx not OK, ignore Rx */ + return result; +#endif + + if (!(reg_eac & BIT(27)) && /* if Tx is OK, check whether Rx is OK */ + (((reg_ea4 & 0x03FF0000) >> 16) != 0x132) && + (((reg_eac & 0x03FF0000) >> 16) != 0x36)) + result |= 0x02; + else + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK fail!!\n"); + + return result; +} + +u8 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ + phy_path_b_iqk_8188e( + struct dm_struct *dm) +{ + u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc; + u8 result = 0x00; + + RF_DBG(dm, DBG_RF_IQK, "path B IQK!\n"); + + /* One shot, path B LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_CONT, MASKDWORD, 0x00000002); + odm_set_bb_reg(dm, REG_IQK_AGC_CONT, MASKDWORD, 0x00000000); + + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path B LOK & IQK.\n", + IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E); + + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_eb4 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_B, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeb4 = 0x%x\n", reg_eb4); + reg_ebc = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_B, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xebc = 0x%x\n", reg_ebc); + reg_ec4 = odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_B_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xec4 = 0x%x\n", reg_ec4); + reg_ecc = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_B_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xecc = 0x%x\n", reg_ecc); + + if (!(reg_eac & BIT(31)) && + (((reg_eb4 & 0x03FF0000) >> 16) != 0x142) && + (((reg_ebc & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + else + return result; + + if (!(reg_eac & BIT(30)) && + (((reg_ec4 & 0x03FF0000) >> 16) != 0x132) && + (((reg_ecc & 0x03FF0000) >> 16) != 0x36)) + result |= 0x02; + else + RF_DBG(dm, DBG_RF_IQK, "path B Rx IQK fail!!\n"); + + return result; +} + +void _phy_path_a_fill_iqk_matrix(struct dm_struct *dm, boolean is_iqk_ok, + s32 result[][8], u8 final_candidate, + boolean is_tx_only) +{ + u32 oldval_0, X, TX0_A, reg; + s32 Y, TX0_C; + + RF_DBG(dm, DBG_RF_IQK, "path A IQ Calibration %s !\n", + (is_iqk_ok) ? "Success" : "Failed"); + + if (final_candidate == 0xFF) + return; + + else if (is_iqk_ok) { + oldval_0 = (odm_get_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD) >> 22) & 0x3FF; + + X = result[final_candidate][0]; + if ((X & 0x00000200) != 0) + X = X | 0xFFFFFC00; + TX0_A = (X * oldval_0) >> 8; + RF_DBG(dm, DBG_RF_IQK, + "X = 0x%x, TX0_A = 0x%x, oldval_0 0x%x\n", X, TX0_A, + oldval_0); + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 0x3FF, TX0_A); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(31), ((X * oldval_0 >> 7) & 0x1)); + + Y = result[final_candidate][1]; + if ((Y & 0x00000200) != 0) + Y = Y | 0xFFFFFC00; + + TX0_C = (Y * oldval_0) >> 8; + RF_DBG(dm, DBG_RF_IQK, "Y = 0x%x, TX = 0x%x\n", Y, TX0_C); + odm_set_bb_reg(dm, REG_OFDM_0_XC_TX_AFE, 0xF0000000, ((TX0_C & 0x3C0) >> 6)); + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 0x003F0000, (TX0_C & 0x3F)); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(29), ((Y * oldval_0 >> 7) & 0x1)); + + if (is_tx_only) { + RF_DBG(dm, DBG_RF_IQK, "%s only Tx OK\n", __func__); + return; + } + + reg = result[final_candidate][2]; +#if (DM_ODM_SUPPORT_TYPE == ODM_AP) + if (RTL_ABS(reg, 0x100) >= 16) + reg = 0x100; +#endif + odm_set_bb_reg(dm, REG_OFDM_0_XA_RX_IQ_IMBALANCE, 0x3FF, reg); + + reg = result[final_candidate][3] & 0x3F; + odm_set_bb_reg(dm, REG_OFDM_0_XA_RX_IQ_IMBALANCE, 0xFC00, reg); + + reg = (result[final_candidate][3] >> 6) & 0xF; + odm_set_bb_reg(dm, REG_OFDM_0_RX_IQ_EXT_ANTA, 0xF0000000, reg); + } +} + +void _phy_path_b_fill_iqk_matrix(struct dm_struct *dm, boolean is_iqk_ok, + s32 result[][8], u8 final_candidate, + boolean is_tx_only /* do Tx only */) +{ + u32 oldval_1, X, TX1_A, reg; + s32 Y, TX1_C; + + RF_DBG(dm, DBG_RF_IQK, "path B IQ Calibration %s !\n", + (is_iqk_ok) ? "Success" : "Failed"); + + if (final_candidate == 0xFF) + return; + + else if (is_iqk_ok) { + oldval_1 = (odm_get_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD) >> 22) & 0x3FF; + + X = result[final_candidate][4]; + if ((X & 0x00000200) != 0) + X = X | 0xFFFFFC00; + TX1_A = (X * oldval_1) >> 8; + RF_DBG(dm, DBG_RF_IQK, "X = 0x%x, TX1_A = 0x%x\n", X, TX1_A); + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, 0x3FF, TX1_A); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(27), ((X * oldval_1 >> 7) & 0x1)); + + Y = result[final_candidate][5]; + if ((Y & 0x00000200) != 0) + Y = Y | 0xFFFFFC00; + + TX1_C = (Y * oldval_1) >> 8; + RF_DBG(dm, DBG_RF_IQK, "Y = 0x%x, TX1_C = 0x%x\n", Y, TX1_C); + odm_set_bb_reg(dm, REG_OFDM_0_XD_TX_AFE, 0xF0000000, ((TX1_C & 0x3C0) >> 6)); + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, 0x003F0000, (TX1_C & 0x3F)); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(25), ((Y * oldval_1 >> 7) & 0x1)); + + if (is_tx_only) + return; + + reg = result[final_candidate][6]; + odm_set_bb_reg(dm, REG_OFDM_0_XB_RX_IQ_IMBALANCE, 0x3FF, reg); + + reg = result[final_candidate][7] & 0x3F; + odm_set_bb_reg(dm, REG_OFDM_0_XB_RX_IQ_IMBALANCE, 0xFC00, reg); + + reg = (result[final_candidate][7] >> 6) & 0xF; + odm_set_bb_reg(dm, REG_OFDM_0_AGC_RSSI_TABLE, 0x0000F000, reg); + } +} + +void _phy_save_adda_registers(struct dm_struct *dm, u32 *adda_reg, + u32 *adda_backup, u32 register_num) +{ + u32 i; + + RF_DBG(dm, DBG_RF_IQK, "Save ADDA parameters.\n"); + for (i = 0; i < register_num; i++) + adda_backup[i] = odm_get_bb_reg(dm, adda_reg[i], MASKDWORD); +} + +void _phy_save_mac_registers(struct dm_struct *dm, u32 *mac_reg, + u32 *mac_backup) +{ + u32 i; + + RF_DBG(dm, DBG_RF_IQK, "Save MAC parameters.\n"); + for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++) + mac_backup[i] = odm_read_1byte(dm, mac_reg[i]); + mac_backup[i] = odm_read_4byte(dm, mac_reg[i]); +} + +void _phy_reload_adda_registers(struct dm_struct *dm, u32 *adda_reg, + u32 *adda_backup, u32 regiester_num) +{ + u32 i; + + RF_DBG(dm, DBG_RF_IQK, "Reload ADDA power saving parameters !\n"); + for (i = 0; i < regiester_num; i++) + odm_set_bb_reg(dm, adda_reg[i], MASKDWORD, adda_backup[i]); +} + +void _phy_reload_mac_registers(struct dm_struct *dm, u32 *mac_reg, + u32 *mac_backup) +{ + u32 i; + + RF_DBG(dm, DBG_RF_IQK, "Reload MAC parameters !\n"); + for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++) + odm_write_1byte(dm, mac_reg[i], (u8)mac_backup[i]); + odm_write_4byte(dm, mac_reg[i], mac_backup[i]); +} + +void _phy_path_adda_on(struct dm_struct *dm, u32 *adda_reg, + boolean is_path_a_on, boolean is2T) +{ + u32 path_on; + u32 i; + + RF_DBG(dm, DBG_RF_IQK, "ADDA ON.\n"); + + path_on = is_path_a_on ? 0x04db25a4 : 0x0b1b25a4; + if (false == is2T) { + path_on = 0x0bdb25a0; + odm_set_bb_reg(dm, adda_reg[0], MASKDWORD, 0x0b1b25a0); + } else + odm_set_bb_reg(dm, adda_reg[0], MASKDWORD, path_on); + + for (i = 1; i < IQK_ADDA_REG_NUM; i++) + odm_set_bb_reg(dm, adda_reg[i], MASKDWORD, path_on); +} + +void _phy_mac_setting_calibration(struct dm_struct *dm, u32 *mac_reg, + u32 *mac_backup) +{ + u32 i = 0; + + RF_DBG(dm, DBG_RF_IQK, "MAC settings for Calibration.\n"); + + odm_write_1byte(dm, mac_reg[i], 0x3F); + + for (i = 1; i < (IQK_MAC_REG_NUM - 1); i++) + odm_write_1byte(dm, mac_reg[i], (u8)(mac_backup[i] & (~BIT(3)))); + odm_write_1byte(dm, mac_reg[i], (u8)(mac_backup[i] & (~BIT(5)))); +} + +void _phy_path_a_stand_by(struct dm_struct *dm) +{ + RF_DBG(dm, DBG_RF_IQK, "path-A standby mode!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, MASKH3BYTES, 0x0); + odm_set_bb_reg(dm, R_0x840, MASKDWORD, 0x00010000); + odm_set_bb_reg(dm, REG_FPGA0_IQK, MASKH3BYTES, 0x808000); +} + +void _phy_pi_mode_switch(struct dm_struct *dm, boolean pi_mode) +{ + u32 mode; + RF_DBG(dm, DBG_RF_IQK, "BB Switch to %s mode!\n", + (pi_mode ? "PI" : "SI")); + mode = pi_mode ? 0x01000100 : 0x01000000; + odm_set_bb_reg(dm, REG_FPGA0_XA_HSSI_PARAMETER1, MASKDWORD, mode); + odm_set_bb_reg(dm, REG_FPGA0_XB_HSSI_PARAMETER1, MASKDWORD, mode); +} + +boolean +phy_simularity_compare_8188e(struct dm_struct *dm, s32 result[][8], u8 c1, + u8 c2, boolean is2t) +{ + u32 i, j, diff, simularity_bit_map, bound = 0; + u8 final_candidate[2] = {0xFF, 0xFF}; /* for path A and path B */ + boolean is_result = true; + + if (is2t) + bound = 8; + else + bound = 4; + + RF_DBG(dm, DBG_RF_IQK, "===> IQK:%s c1 %d c2 %d!!!\n", __func__, c1, + c2); + simularity_bit_map = 0; + for (i = 0; i < bound; i++) { + diff = (result[c1][i] > result[c2][i]) ? (result[c1][i] - result[c2][i]) : (result[c2][i] - result[c1][i]); + if (diff > MAX_TOLERANCE) { + RF_DBG(dm, DBG_RF_IQK, + "IQK:%s differnece overflow index %d compare1 0x%x compare2 0x%x!!!\n", + __func__, i, result[c1][i], result[c2][i]); + + if ((i == 2 || i == 6) && !simularity_bit_map) { + if (result[c1][i] + result[c1][i + 1] == 0) + final_candidate[(i / 4)] = c2; + else if (result[c2][i] + result[c2][i + 1] == 0) + final_candidate[(i / 4)] = c1; + else + simularity_bit_map = simularity_bit_map | (1 << i); + } else + simularity_bit_map = simularity_bit_map | (1 << i); + } + } + + RF_DBG(dm, DBG_RF_IQK, "IQK:%s simularity_bit_map %d !!!\n", __func__, + simularity_bit_map); + + if (simularity_bit_map == 0) { + for (i = 0; i < (bound / 4); i++) { + if (final_candidate[i] != 0xFF) { + for (j = i * 4; j < (i + 1) * 4 - 2; j++) + result[3][j] = result[final_candidate[i]][j]; + is_result = false; + } + } + return is_result; + } else if (!(simularity_bit_map & 0x0F)) { /* path A OK */ + for (i = 0; i < 4; i++) + result[3][i] = result[c1][i]; + return false; + } else if (!(simularity_bit_map & 0xF0) && is2t) { /* path B OK */ + for (i = 4; i < 8; i++) + result[3][i] = result[c1][i]; + return false; + } else + return false; +} + +void _phy_iq_calibrate_8188e(struct dm_struct *dm, s32 result[][8], u8 t, + boolean is2T) +{ + u32 i; + u8 path_aok = 0, path_bok = 0; + u32 ADDA_REG[IQK_ADDA_REG_NUM] = { + REG_FPGA0_XCD_SWITCH_CONTROL, REG_BLUE_TOOTH, + REG_RX_WAIT_CCA, REG_TX_CCK_RFON, + REG_TX_CCK_BBON, REG_TX_OFDM_RFON, + REG_TX_OFDM_BBON, REG_TX_TO_RX, + REG_TX_TO_TX, REG_RX_CCK, + REG_RX_OFDM, REG_RX_WAIT_RIFS, + REG_RX_TO_RX, REG_STANDBY, + REG_SLEEP, REG_PMPD_ANAEN}; + u32 IQK_MAC_REG[IQK_MAC_REG_NUM] = { + REG_TXPAUSE, REG_BCN_CTRL, + REG_BCN_CTRL_1, REG_GPIO_MUXCFG}; + + /* since 92C & 92D have the different define in IQK_BB_REG */ + u32 IQK_BB_REG_92C[IQK_BB_REG_NUM] = { + REG_OFDM_0_TRX_PATH_ENABLE, REG_OFDM_0_TR_MUX_PAR, + REG_FPGA0_XCD_RF_INTERFACE_SW, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B, + REG_FPGA0_XAB_RF_INTERFACE_SW, REG_FPGA0_XA_RF_INTERFACE_OE, + REG_FPGA0_XB_RF_INTERFACE_OE, REG_CCK_0_AFE_SETTING}; + + u32 retry_count = 2; + + if (*dm->mp_mode == true) + retry_count = 9; + + /* Note: IQ calibration must be performed after loading */ + /* PHY_REG.txt , and radio_a, radio_b.txt */ + + /* u32 bbvalue; */ + + if (t == 0) { + /* bbvalue = odm_get_bb_reg(dm, REG_FPGA0_RFMOD, MASKDWORD); + * RT_DISP(FINIT, INIT_IQK, ("_phy_iq_calibrate_8188e()==>0x%08x\n",bbvalue)); */ + + RF_DBG(dm, DBG_RF_IQK, "IQ Calibration for %s for %d times\n", + (is2T ? "2T2R" : "1T1R"), t); + + /* Save ADDA parameters, turn path A ADDA on */ + _phy_save_adda_registers(dm, ADDA_REG, dm->rf_calibrate_info.ADDA_backup, IQK_ADDA_REG_NUM); + _phy_save_mac_registers(dm, IQK_MAC_REG, dm->rf_calibrate_info.IQK_MAC_backup); + _phy_save_adda_registers(dm, IQK_BB_REG_92C, dm->rf_calibrate_info.IQK_BB_backup, IQK_BB_REG_NUM); + } + RF_DBG(dm, DBG_RF_IQK, "IQ Calibration for %s for %d times\n", + (is2T ? "2T2R" : "1T1R"), t); + _phy_path_adda_on(dm, ADDA_REG, true, is2T); + + if (t == 0) + dm->rf_calibrate_info.is_rf_pi_enable = (u8)odm_get_bb_reg(dm, REG_FPGA0_XA_HSSI_PARAMETER1, BIT(8)); + + if (!dm->rf_calibrate_info.is_rf_pi_enable) { + /* Switch BB to PI mode to do IQ Calibration. */ + _phy_pi_mode_switch(dm, true); + } + /* MAC settings */ + _phy_mac_setting_calibration(dm, IQK_MAC_REG, dm->rf_calibrate_info.IQK_MAC_backup); + /* BB setting */ + /* odm_set_bb_reg(dm, REG_FPGA0_RFMOD, BIT24, 0x00); */ + odm_set_bb_reg(dm, REG_CCK_0_AFE_SETTING, 0x0f000000, 0xf); + odm_set_bb_reg(dm, REG_OFDM_0_TRX_PATH_ENABLE, MASKDWORD, 0x03a05600); + odm_set_bb_reg(dm, REG_OFDM_0_TR_MUX_PAR, MASKDWORD, 0x000800e4); + odm_set_bb_reg(dm, REG_FPGA0_XCD_RF_INTERFACE_SW, MASKDWORD, 0x22204000); + + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_INTERFACE_SW, BIT(10), 0x01); + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_INTERFACE_SW, BIT(26), 0x01); + odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(10), 0x00); + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(10), 0x00); + + if (is2T) { + odm_set_bb_reg(dm, REG_FPGA0_XA_LSSI_PARAMETER, MASKDWORD, 0x00010000); + odm_set_bb_reg(dm, REG_FPGA0_XB_LSSI_PARAMETER, MASKDWORD, 0x00010000); + } + /* Page B init */ + /* AP or IQK */ + odm_set_bb_reg(dm, REG_CONFIG_ANT_A, MASKDWORD, 0x0f600000); + if (is2T) + odm_set_bb_reg(dm, REG_CONFIG_ANT_B, MASKDWORD, 0x0f600000); + + /* IQ calibration setting */ + RF_DBG(dm, DBG_RF_IQK, "IQK setting!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, MASKH3BYTES, 0x808000); + odm_set_bb_reg(dm, REG_TX_IQK, MASKDWORD, 0x01007c00); + odm_set_bb_reg(dm, REG_RX_IQK, MASKDWORD, 0x81004800); + + for (i = 0; i < retry_count; i++) { + path_aok = phy_path_a_iqk_8188e(dm, is2T); + /* if(path_aok == 0x03){ */ + if (path_aok == 0x01) { + RF_DBG(dm, DBG_RF_IQK, "path A Tx IQK Success!!\n"); + result[t][0] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + result[t][1] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + break; + } +#if 0 + else if (i == (retry_count - 1) && path_aok == 0x01) { /* Tx IQK OK */ + RT_DISP(FINIT, INIT_IQK, ("path A IQK Only Tx Success!!\n")); + + result[t][0] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + result[t][1] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + } +#endif + } + + for (i = 0; i < retry_count; i++) { + path_aok = phy_path_a_rx_iqk(dm, is2T); + if (path_aok == 0x03) { + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK Success!!\n"); + /* result[t][0] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD)&0x3FF0000)>>16; + * result[t][1] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD)&0x3FF0000)>>16; */ + result[t][2] = (odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_A_2, MASKDWORD) & 0x3FF0000) >> 16; + result[t][3] = (odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD) & 0x3FF0000) >> 16; + break; + } + + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK Fail!!\n"); + } + + if (0x00 == path_aok) + RF_DBG(dm, DBG_RF_IQK, "path A IQK failed!!\n"); + + if (is2T) { + _phy_path_a_stand_by(dm); + /* Turn path B ADDA on */ + _phy_path_adda_on(dm, ADDA_REG, false, is2T); + + for (i = 0; i < retry_count; i++) { + path_bok = phy_path_b_iqk_8188e(dm); + if (path_bok == 0x03) { + RF_DBG(dm, DBG_RF_IQK, + "path B IQK Success!!\n"); + result[t][4] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + result[t][5] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + result[t][6] = (odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_B_2, MASKDWORD) & 0x3FF0000) >> 16; + result[t][7] = (odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_B_2, MASKDWORD) & 0x3FF0000) >> 16; + break; + } else if (i == (retry_count - 1) && path_bok == 0x01) { /* Tx IQK OK */ + RF_DBG(dm, DBG_RF_IQK, + "path B Only Tx IQK Success!!\n"); + result[t][4] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + result[t][5] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + } + } + + if (0x00 == path_bok) + RF_DBG(dm, DBG_RF_IQK, "path B IQK failed!!\n"); + } + + /* Back to BB mode, load original value */ + RF_DBG(dm, DBG_RF_IQK, "IQK:Back to BB mode, load original value!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, MASKH3BYTES, 0); + + if (t != 0) { + if (!dm->rf_calibrate_info.is_rf_pi_enable) { + /* Switch back BB to SI mode after finish IQ Calibration. */ + _phy_pi_mode_switch(dm, false); + } + /* Reload ADDA power saving parameters */ + _phy_reload_adda_registers(dm, ADDA_REG, dm->rf_calibrate_info.ADDA_backup, IQK_ADDA_REG_NUM); + /* Reload MAC parameters */ + _phy_reload_mac_registers(dm, IQK_MAC_REG, dm->rf_calibrate_info.IQK_MAC_backup); + _phy_reload_adda_registers(dm, IQK_BB_REG_92C, dm->rf_calibrate_info.IQK_BB_backup, IQK_BB_REG_NUM); + /* Restore RX initial gain */ + odm_set_bb_reg(dm, REG_FPGA0_XA_LSSI_PARAMETER, MASKDWORD, 0x00032ed3); + if (is2T) + odm_set_bb_reg(dm, REG_FPGA0_XB_LSSI_PARAMETER, MASKDWORD, 0x00032ed3); + + /* load 0xe30 IQC default value */ + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x01008c00); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x01008c00); + } + RF_DBG(dm, DBG_RF_IQK, "%s <==\n", __func__); +} + +void _phy_lc_calibrate_8188e(struct dm_struct *dm, boolean is2T) +{ + u8 tmp_reg; + u32 rf_amode = 0, rf_bmode = 0, lc_cal, cnt; + + /* Check continuous TX and Packet TX */ + tmp_reg = odm_read_1byte(dm, 0xd03); + + if ((tmp_reg & 0x70) != 0) /* Deal with contisuous TX case */ + odm_write_1byte(dm, 0xd03, tmp_reg & 0x8F); /* disable all continuous TX */ + else /* Deal with Packet TX case */ + odm_write_1byte(dm, REG_TXPAUSE, 0xFF); /* block all queues */ + + if ((tmp_reg & 0x70) != 0) { + /* 1. Read original RF mode */ + /* path-A */ + rf_amode = odm_get_rf_reg(dm, RF_PATH_A, RF_AC, MASK12BITS); + /* path-B */ + if (is2T) + rf_bmode = odm_get_rf_reg(dm, RF_PATH_B, RF_AC, MASK12BITS); + /* 2. Set RF mode = standby mode */ + /* path-A */ + odm_set_rf_reg(dm, RF_PATH_A, RF_AC, MASK12BITS, (rf_amode & 0x8FFFF) | 0x10000); + /* path-B */ + if (is2T) + odm_set_rf_reg(dm, RF_PATH_B, RF_AC, MASK12BITS, (rf_bmode & 0x8FFFF) | 0x10000); + } + + /* 3. Read RF reg18 */ + lc_cal = odm_get_rf_reg(dm, RF_PATH_A, RF_CHNLBW, MASK12BITS); + + /* 4. Set LC calibration begin bit15 */ + odm_set_rf_reg(dm, RF_PATH_A, RF_CHNLBW, MASK12BITS, lc_cal | 0x08000); + ODM_delay_ms(100); + for (cnt = 0; cnt < 5; cnt++) { + if (odm_get_rf_reg(dm, RF_PATH_A, RF_CHNLBW, 0x8000) != 0x1) + break; + ODM_delay_ms(10); + } + + if (cnt == 5) + RF_DBG(dm, DBG_RF_LCK, "LCK time out\n"); + + /*recover channel number*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_CHNLBW, MASK20BITS, lc_cal); + + /* Restore original situation */ + if ((tmp_reg & 0x70) != 0) { /* Deal with contisuous TX case */ + /* path-A */ + odm_write_1byte(dm, 0xd03, tmp_reg); + odm_set_rf_reg(dm, RF_PATH_A, RF_AC, MASK12BITS, rf_amode); + + /* path-B */ + if (is2T) + odm_set_rf_reg(dm, RF_PATH_B, RF_AC, MASK12BITS, rf_bmode); + } else /* Deal with Packet TX case */ + odm_write_1byte(dm, REG_TXPAUSE, 0x00); +} + +void phy_iq_calibrate_8188e(void *dm_void, boolean is_recovery) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + s32 result[4][8]; /* last is final result */ + u8 i, final_candidate, indexforchannel; + u8 channel_to_iqk = 7; + boolean is_patha_ok, is_pathb_ok; + s32 rege94, rege9c, regea4, regeac, regeb4, regebc, regec4, regecc, reg_tmp = 0; + boolean is12simular, is13simular, is23simular; + u32 IQK_BB_REG_92C[IQK_BB_REG_NUM] = { + REG_OFDM_0_XA_RX_IQ_IMBALANCE, REG_OFDM_0_XB_RX_IQ_IMBALANCE, + REG_OFDM_0_ECCA_THRESHOLD, REG_OFDM_0_AGC_RSSI_TABLE, + REG_OFDM_0_XA_TX_IQ_IMBALANCE, REG_OFDM_0_XB_TX_IQ_IMBALANCE, + REG_OFDM_0_XC_TX_AFE, REG_OFDM_0_XD_TX_AFE, + REG_OFDM_0_RX_IQ_EXT_ANTA}; + + if (is_recovery) { + RF_DBG(dm, DBG_RF_INIT, "%s: Return due to is_recovery!\n", + __func__); + _phy_reload_adda_registers(dm, IQK_BB_REG_92C, dm->rf_calibrate_info.IQK_BB_backup_recover, 9); + return; + } + RF_DBG(dm, DBG_RF_IQK, "IQK:Start!!!\n"); + + for (i = 0; i < 8; i++) { + result[0][i] = 0; + result[1][i] = 0; + result[2][i] = 0; + result[3][i] = 0; + } + final_candidate = 0xff; + is_patha_ok = false; + is_pathb_ok = false; + is12simular = false; + is23simular = false; + is13simular = false; + + for (i = 0; i < 3; i++) { + _phy_iq_calibrate_8188e(dm, result, i, false); + if (i == 1) { + is12simular = phy_simularity_compare_8188e(dm, result, 0, 1, false); + if (is12simular) { + final_candidate = 0; + RF_DBG(dm, DBG_RF_IQK, + "IQK: is12simular final_candidate is %x\n", + final_candidate); + break; + } + } + + if (i == 2) { + is13simular = phy_simularity_compare_8188e(dm, result, 0, 2, false); + if (is13simular) { + final_candidate = 0; + RF_DBG(dm, DBG_RF_IQK, + "IQK: is13simular final_candidate is %x\n", + final_candidate); + break; + } + is23simular = phy_simularity_compare_8188e(dm, result, 1, 2, false); + if (is23simular) { + final_candidate = 1; + RF_DBG(dm, DBG_RF_IQK, + "IQK: is23simular final_candidate is %x\n", + final_candidate); + } else { + for (i = 0; i < 8; i++) + reg_tmp += result[3][i]; + + if (reg_tmp != 0) + final_candidate = 3; + else + final_candidate = 0xFF; + } + } + } + /* RT_TRACE(COMP_INIT,DBG_LOUD,("Release Mutex in IQCalibrate\n")); */ + + for (i = 0; i < 4; i++) { + rege94 = result[i][0]; + rege9c = result[i][1]; + regea4 = result[i][2]; + regeac = result[i][3]; + regeb4 = result[i][4]; + regebc = result[i][5]; + regec4 = result[i][6]; + regecc = result[i][7]; + RF_DBG(dm, DBG_RF_IQK, + "IQK: rege94=%x rege9c=%x regea4=%x regeac=%x regeb4=%x regebc=%x regec4=%x regecc=%x\n ", + rege94, rege9c, regea4, regeac, regeb4, regebc, regec4, + regecc); + } + + if (final_candidate != 0xff) { + dm->rf_calibrate_info.rege94 = rege94 = result[final_candidate][0]; + dm->rf_calibrate_info.rege9c = rege9c = result[final_candidate][1]; + regea4 = result[final_candidate][2]; + regeac = result[final_candidate][3]; + dm->rf_calibrate_info.regeb4 = regeb4 = result[final_candidate][4]; + dm->rf_calibrate_info.regebc = regebc = result[final_candidate][5]; + regec4 = result[final_candidate][6]; + regecc = result[final_candidate][7]; + RF_DBG(dm, DBG_RF_IQK, "IQK: final_candidate is %x\n", + final_candidate); + RF_DBG(dm, DBG_RF_IQK, + "IQK: rege94=%x rege9c=%x regea4=%x regeac=%x regeb4=%x regebc=%x regec4=%x regecc=%x\n ", + rege94, rege9c, regea4, regeac, regeb4, regebc, regec4, + regecc); + is_patha_ok = is_pathb_ok = true; + } else { + RF_DBG(dm, DBG_RF_IQK, "IQK: FAIL use default value\n"); + + dm->rf_calibrate_info.rege94 = dm->rf_calibrate_info.regeb4 = 0x100; /* X default value */ + dm->rf_calibrate_info.rege9c = dm->rf_calibrate_info.regebc = 0x0; /* Y default value */ + } + + if ((rege94 != 0) /*&&(regea4 != 0)*/) + _phy_path_a_fill_iqk_matrix(dm, is_patha_ok, result, final_candidate, (regea4 == 0)); + + indexforchannel = odm_get_right_chnl_place_for_iqk(*dm->channel); + + /* To Fix BSOD when final_candidate is 0xff + * by sherry 20120321 */ + if (final_candidate < 4) { + for (i = 0; i < iqk_matrix_reg_num; i++) + dm->rf_calibrate_info.iqk_matrix_reg_setting[indexforchannel].value[0][i] = result[final_candidate][i]; + dm->rf_calibrate_info.iqk_matrix_reg_setting[indexforchannel].is_iqk_done = true; + } + /* RT_DISP(FINIT, INIT_IQK, ("\nIQK OK indexforchannel %d.\n", indexforchannel)); */ + RF_DBG(dm, DBG_RF_IQK, "\nIQK OK indexforchannel %d.\n", + indexforchannel); + _phy_save_adda_registers(dm, IQK_BB_REG_92C, dm->rf_calibrate_info.IQK_BB_backup_recover, IQK_BB_REG_NUM); + RF_DBG(dm, DBG_RF_IQK, "IQK finished\n"); +} + +void phy_lc_calibrate_8188e(void *dm_void) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + _phy_lc_calibrate_8188e(dm, false); +} + +void _phy_set_rf_path_switch_8188e( +#if ((DM_ODM_SUPPORT_TYPE & ODM_AP) || (DM_ODM_SUPPORT_TYPE == ODM_CE)) + struct dm_struct *dm, +#else + void *adapter, +#endif + boolean is_main, boolean is2T) +{ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter); + struct dm_struct *dm = &hal_data->DM_OutSrc; +#endif + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + if (!adapter->bHWInitReady) +#elif (DM_ODM_SUPPORT_TYPE == ODM_CE) + void *adapter = dm->adapter; + if (!rtw_is_hw_init_completed(adapter)) +#endif + { + u8 u1b_tmp; + u1b_tmp = odm_read_1byte(dm, REG_LEDCFG2) | BIT(7); + odm_write_1byte(dm, REG_LEDCFG2, u1b_tmp); + /* odm_set_bb_reg(dm, REG_LEDCFG0, BIT23, 0x01); */ + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_PARAMETER, BIT(13), 0x01); + } + +#endif + + if (is2T) { /* 92C */ + if (is_main) + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(6), 0x1); /* 92C_Path_A */ + else + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(6), 0x2); /* BT */ + } else { /* 88C */ + #ifdef CONFIG_PHYDM_ANTENNA_DIVERSITY + /* <20120504, Kordan> [8188E] We should make AntDiversity controlled by HW (0x870[9:8] = 0), */ + /* otherwise the following action has no effect. (0x860[9:8] has the effect only if AntDiversity controlled by SW) */ + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_INTERFACE_SW, BIT(8) | BIT(9), 0x0); + odm_set_bb_reg(dm, R_0x914, MASKLWORD, 0x0201); /* Set up the ant mapping table */ + + if (is_main) { + /* odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(8)|BIT9, 0x2); */ /* Tx Main (SW control)(The right antenna) */ + /* 4 [ Tx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(14) | BIT(13) | BIT(12), 0x1); /* Tx Main (HW control)(The right antenna) */ + + /* 4 [ Rx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(4) | BIT(3), 0x1); /* ant_div_type = TRDiv, right antenna */ + if (dm->ant_div_type == CGCS_RX_HW_ANTDIV) + odm_set_bb_reg(dm, R_0xb2c, BIT(31), 0x1); /* RxCG, Default is RxCG. ant_div_type = 2RDiv, left antenna */ + + } else { + /* odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(8)|BIT9, 0x1); */ /* Tx Aux (SW control)(The left antenna) */ + /* 4 [ Tx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(14) | BIT(13) | BIT(12), 0x0); /* Tx Aux (HW control)(The left antenna) */ + + /* 4 [ Rx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(4) | BIT(3), 0x0); /* ant_div_type = TRDiv, left antenna */ + if (dm->ant_div_type == CGCS_RX_HW_ANTDIV) + odm_set_bb_reg(dm, R_0xb2c, BIT(31), 0x0); /* RxCS, ant_div_type = 2RDiv, right antenna */ + } + #endif + } +} +void phy_set_rf_path_switch_8188e( +#if ((DM_ODM_SUPPORT_TYPE & ODM_AP) || (DM_ODM_SUPPORT_TYPE == ODM_CE)) + struct dm_struct *dm, +#else + void *adapter, +#endif + boolean is_main) +{ +#if !((DM_ODM_SUPPORT_TYPE & ODM_AP) || (DM_ODM_SUPPORT_TYPE & ODM_CE)) + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter); +#endif + +#if DISABLE_BB_RF + return; +#endif + + { +/* For 88C 1T1R */ +#if !((DM_ODM_SUPPORT_TYPE & ODM_AP) || (DM_ODM_SUPPORT_TYPE & ODM_CE)) + _phy_set_rf_path_switch_8188e(adapter, is_main, false); +#else + _phy_set_rf_path_switch_8188e(dm, is_main, false); +#endif + } +} + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) +/* return value true => Main; false => Aux */ +boolean _phy_query_rf_path_switch_8188e( +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + struct dm_struct *dm, +#else + void *adapter, +#endif + boolean is2T) +{ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter); +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) + struct dm_struct *dm = &hal_data->odmpriv; +#endif +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + struct dm_struct *dm = &hal_data->DM_OutSrc; +#endif +#endif + if (!adapter->is_hw_init_ready) { + u8 u1b_tmp; + u1b_tmp = odm_read_1byte(dm, REG_LEDCFG2) | BIT(7); + odm_write_1byte(dm, REG_LEDCFG2, u1b_tmp); + /* odm_set_bb_reg(dm, REG_LEDCFG0, BIT23, 0x01); */ + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_PARAMETER, BIT(13), 0x01); + } + + if (is2T) { + if (odm_get_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(6)) == 0x01) + return true; + else + return false; + } else { + if ((odm_get_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(4) | BIT(3)) == 0x1)) + return true; + else + return false; + } +} + +/* return value true => Main; false => Aux */ +boolean phy_query_rf_path_switch_8188e( +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + struct dm_struct *dm +#else + void *adapter +#endif + ) +{ + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter); + +#if DISABLE_BB_RF + return true; +#endif +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + if (IS_2T2R(hal_data->version_id)) + return _phy_query_rf_path_switch_8188e(adapter, true); +#endif +/* For 88C 1T1R */ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + return _phy_query_rf_path_switch_8188e(adapter, false); +#else + return _phy_query_rf_path_switch_8188e(dm, false); +#endif +} +#endif diff --git a/hal/phydm/halrf/rtl8188e/halrf_8188e_ce.h b/hal/phydm/halrf/rtl8188e/halrf_8188e_ce.h new file mode 100644 index 0000000..273b5c0 --- /dev/null +++ b/hal/phydm/halrf/rtl8188e/halrf_8188e_ce.h @@ -0,0 +1,59 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#ifndef __HALRF_8188E_H__ +#define __HALRF_8188E_H__ + +/*--------------------------Define Parameters-------------------------------*/ +#define IQK_DELAY_TIME_88E 10 /* ms */ +#define index_mapping_NUM_88E 15 +#define AVG_THERMAL_NUM_88E 4 + +#include "../halphyrf_ce.h" + +void configure_txpower_track_8188e(struct txpwrtrack_cfg *config); + +void get_delta_swing_table_8188e(void *dm_void, u8 **temperature_up_a, + u8 **temperature_down_a, u8 **temperature_up_b, + u8 **temperature_down_b); + +void do_iqk_8188e(void *dm_void, u8 delta_thermal_index, u8 thermal_value, + u8 threshold); + +void odm_tx_pwr_track_set_pwr88_e(void *dm_void, enum pwrtrack_method method, + u8 rf_path, u8 channel_mapped_index); + +/* 1 7. IQK */ + +void phy_iq_calibrate_8188e(void *dm_void, boolean is_recovery); + +/* + * LC calibrate + * */ +void phy_lc_calibrate_8188e(void *dm_void); + +void _phy_save_adda_registers(struct dm_struct *dm, u32 *adda_reg, + u32 *adda_backup, u32 register_num); + +void _phy_path_adda_on(struct dm_struct *dm, u32 *adda_reg, + boolean is_path_a_on, boolean is2T); + +void _phy_mac_setting_calibration(struct dm_struct *dm, u32 *mac_reg, + u32 *mac_backup); + +void _phy_path_a_stand_by(struct dm_struct *dm); +void halrf_rf_lna_setting_8188e(struct dm_struct *dm, enum halrf_lna_set type); + +#endif /*#ifndef __HALRF_8188E_H__*/ diff --git a/hal/phydm/halrf/rtl8188e/halrf_8188e_win.c b/hal/phydm/halrf/rtl8188e/halrf_8188e_win.c new file mode 100644 index 0000000..3b8a3f2 --- /dev/null +++ b/hal/phydm/halrf/rtl8188e/halrf_8188e_win.c @@ -0,0 +1,1799 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#include "mp_precomp.h" + +#if RT_PLATFORM==PLATFORM_MACOSX +#include "phydm_precomp.h" +#else +#include "../phydm_precomp.h" +#endif + +#if (RTL8188E_SUPPORT == 1) + +/*---------------------------Define Local Constant---------------------------*/ +/* 2010/04/25 MH Define the max tx power tracking tx agc power. */ +#define ODM_TXPWRTRACK_MAX_IDX_88E 6 + +/*---------------------------Define Local Constant---------------------------*/ + + +/* 3============================================================ + * 3 Tx Power Tracking + * 3============================================================ */ + +void halrf_rf_lna_setting_8188e( + struct dm_struct *dm, + enum halrf_lna_set type +) +{ +/*phydm_disable_lna*/ + if (type == HALRF_LNA_DISABLE) { + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x30, 0xfffff, 0x18000); /*select Rx mode*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x32, 0xfffff, 0x37f82); /*disable LNA*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x0); + if (dm->rf_type > RF_1T1R) { + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x30, 0xfffff, 0x18000); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x32, 0xfffff, 0x37f82); + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x0); + } + } else if (type == HALRF_LNA_ENABLE) { + /*phydm_enable_lna*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x30, 0xfffff, 0x18000); /*select Rx mode*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x32, 0xfffff, 0x77f82); /*back to normal*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xef, 0x80000, 0x0); + if (dm->rf_type > RF_1T1R) { + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x1); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x30, 0xfffff, 0x18000); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x31, 0xfffff, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_B, RF_0x32, 0xfffff, 0x77f82); + odm_set_rf_reg(dm, RF_PATH_B, RF_0xef, 0x80000, 0x0); + } + + } +} + +void set_iqk_matrix_8188e( + struct dm_struct *dm, + u8 OFDM_index, + u8 rf_path, + s32 iqk_result_x, + s32 iqk_result_y +) +{ + s32 ele_A = 0, ele_D, ele_C = 0, value32; + + ele_D = (ofdm_swing_table_new[OFDM_index] & 0xFFC00000) >> 22; + + /* new element A = element D x X */ + if ((iqk_result_x != 0) && (*(dm->band_type) == ODM_BAND_2_4G)) { + if ((iqk_result_x & 0x00000200) != 0) /* consider minus */ + iqk_result_x = iqk_result_x | 0xFFFFFC00; + ele_A = ((iqk_result_x * ele_D) >> 8) & 0x000003FF; + + /* new element C = element D x Y */ + if ((iqk_result_y & 0x00000200) != 0) + iqk_result_y = iqk_result_y | 0xFFFFFC00; + ele_C = ((iqk_result_y * ele_D) >> 8) & 0x000003FF; + + if (rf_path == RF_PATH_A) + switch (rf_path) { + case RF_PATH_A: + /* wirte new elements A, C, D to regC80 and regC94, element B is always 0 */ + value32 = (ele_D << 22) | ((ele_C & 0x3F) << 16) | ele_A; + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD, value32); + + value32 = (ele_C & 0x000003C0) >> 6; + odm_set_bb_reg(dm, REG_OFDM_0_XC_TX_AFE, MASKH4BITS, value32); + + value32 = ((iqk_result_x * ele_D) >> 7) & 0x01; + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), value32); + break; + case RF_PATH_B: + /* wirte new elements A, C, D to regC88 and regC9C, element B is always 0 */ + value32 = (ele_D << 22) | ((ele_C & 0x3F) << 16) | ele_A; + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD, value32); + + value32 = (ele_C & 0x000003C0) >> 6; + odm_set_bb_reg(dm, REG_OFDM_0_XD_TX_AFE, MASKH4BITS, value32); + + value32 = ((iqk_result_x * ele_D) >> 7) & 0x01; + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), value32); + + break; + default: + break; + } + } else { + switch (rf_path) { + case RF_PATH_A: + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD, ofdm_swing_table_new[OFDM_index]); + odm_set_bb_reg(dm, REG_OFDM_0_XC_TX_AFE, MASKH4BITS, 0x00); + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(24), 0x00); + break; + + case RF_PATH_B: + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD, ofdm_swing_table_new[OFDM_index]); + odm_set_bb_reg(dm, REG_OFDM_0_XD_TX_AFE, MASKH4BITS, 0x00); + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(28), 0x00); + break; + + default: + break; + } + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "TxPwrTracking path B: X = 0x%x, Y = 0x%x ele_A = 0x%x ele_C = 0x%x ele_D = 0x%x 0xeb4 = 0x%x 0xebc = 0x%x\n", + (u32)iqk_result_x, (u32)iqk_result_y, (u32)ele_A, (u32)ele_C, (u32)ele_D, (u32)iqk_result_x, (u32)iqk_result_y); +} + +void do_iqk_8188e( + void *dm_void, + u8 delta_thermal_index, + u8 thermal_value, + u8 threshold +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + odm_reset_iqk_result(dm); + dm->rf_calibrate_info.thermal_value_iqk = thermal_value; + halrf_iqk_trigger(dm, false); +} + +/*----------------------------------------------------------------------------- + * Function: odm_TxPwrTrackSetPwr88E() + * + * Overview: 88E change all channel tx power accordign to flag. + * OFDM & CCK are all different. + * + * Input: NONE + * + * Output: NONE + * + * Return: NONE + * + * Revised History: + * When Who Remark + * 04/23/2012 MHC Create version 0. + * + *---------------------------------------------------------------------------*/ +void +odm_tx_pwr_track_set_pwr88_e( + void *dm_void, + enum pwrtrack_method method, + u8 rf_path, + u8 channel_mapped_index +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _ADAPTER *adapter = dm->adapter; + u8 pwr_tracking_limit_ofdm = 30; /* +0dB */ + u8 pwr_tracking_limit_cck = 28; /* -2dB */ + u8 tx_rate = 0xFF; + u8 final_ofdm_swing_index = 0; + u8 final_cck_swing_index = 0; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + + + if (*(dm->mp_mode) == true) { +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) +#if (MP_DRIVER == 1) + PMPT_CONTEXT p_mpt_ctx = &(adapter->MptCtx); + + tx_rate = MptToMgntRate(p_mpt_ctx->MptRateIndex); +#endif +#elif (DM_ODM_SUPPORT_TYPE & ODM_CE) +#ifdef CONFIG_MP_INCLUDED + PMPT_CONTEXT p_mpt_ctx = &(adapter->mppriv.mpt_ctx); + + tx_rate = mpt_to_mgnt_rate(p_mpt_ctx->mpt_rate_index); +#endif +#endif +#endif + } else { + u16 rate = *(dm->forced_data_rate); + + if (!rate) { /*auto rate*/ +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) + tx_rate = ((PADAPTER)adapter)->HalFunc.GetHwRateFromMRateHandler(dm->tx_rate); +#elif (DM_ODM_SUPPORT_TYPE & ODM_CE) + tx_rate = hw_rate_to_m_rate(dm->tx_rate); +#endif + } else /*force rate*/ + tx_rate = (u8)rate; + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Power Tracking tx_rate=0x%X\n", tx_rate); + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "===>ODM_TxPwrTrackSetPwr8188E\n"); + + if (tx_rate != 0xFF) { + /* 2 CCK */ + if (((tx_rate >= MGN_1M) && (tx_rate <= MGN_5_5M)) || (tx_rate == MGN_11M)) + pwr_tracking_limit_cck = 28; /* -2dB */ + /* 2 OFDM */ + else if ((tx_rate >= MGN_6M) && (tx_rate <= MGN_48M)) + pwr_tracking_limit_ofdm = 36; /* +3dB */ + else if (tx_rate == MGN_54M) + pwr_tracking_limit_ofdm = 34; /* +2dB */ + + /* 2 HT */ + else if ((tx_rate >= MGN_MCS0) && (tx_rate <= MGN_MCS2)) /* QPSK/BPSK */ + pwr_tracking_limit_ofdm = 38; /* +4dB */ + else if ((tx_rate >= MGN_MCS3) && (tx_rate <= MGN_MCS4)) /* 16QAM */ + pwr_tracking_limit_ofdm = 36; /* +3dB */ + else if ((tx_rate >= MGN_MCS5) && (tx_rate <= MGN_MCS7)) /* 64QAM */ + pwr_tracking_limit_ofdm = 34; /* +2dB */ + + else + pwr_tracking_limit_ofdm = cali_info->default_ofdm_index; /* Default OFDM index = 30 */ + } + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "tx_rate=0x%x, pwr_tracking_limit=%d\n", tx_rate, pwr_tracking_limit_ofdm); + + if (method == TXAGC) { + u32 pwr = 0, tx_agc = 0; + void *adapter = dm->adapter; + + cali_info->remnant_ofdm_swing_idx[rf_path] = cali_info->absolute_ofdm_swing_idx[rf_path]; /* Remnant index equal to aboslute compensate value. */ + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "odm_TxPwrTrackSetPwr88E CH=%d\n", *(dm->channel)); + +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) + +#if (MP_DRIVER != 1) + /* phy_set_tx_power_level8188e(dm->adapter, *dm->channel); */ + + cali_info->modify_tx_agc_flag_path_a = true; + cali_info->modify_tx_agc_flag_path_a_cck = true; + + if (rf_path == RF_PATH_A) { + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, CCK); + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, OFDM); + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, HT_MCS0_MCS7); + } + +#else + pwr = PHY_QueryBBReg(adapter, REG_TX_AGC_A_RATE18_06, 0xFF); + pwr += cali_info->power_index_offset[RF_PATH_A]; + PHY_SetBBReg(adapter, REG_TX_AGC_A_CCK_1_MCS32, MASKBYTE1, pwr); + tx_agc = (pwr << 16) | (pwr << 8) | (pwr); + PHY_SetBBReg(adapter, REG_TX_AGC_B_CCK_11_A_CCK_2_11, 0xffffff00, tx_agc); + RT_DISP(FPHY, PHY_TXPWR, ("odm_tx_pwr_track_set_pwr88_e: CCK Tx-rf(A) Power = 0x%x\n", tx_agc)); + + pwr = PHY_QueryBBReg(adapter, REG_TX_AGC_A_RATE18_06, 0xFF); + pwr += (cali_info->bb_swing_idx_ofdm[RF_PATH_A] - cali_info->bb_swing_idx_ofdm_base[RF_PATH_A]); + tx_agc |= ((pwr << 24) | (pwr << 16) | (pwr << 8) | pwr); + PHY_SetBBReg(adapter, REG_TX_AGC_A_RATE18_06, MASKDWORD, tx_agc); + PHY_SetBBReg(adapter, REG_TX_AGC_A_RATE54_24, MASKDWORD, tx_agc); + PHY_SetBBReg(adapter, REG_TX_AGC_A_MCS03_MCS00, MASKDWORD, tx_agc); + PHY_SetBBReg(adapter, REG_TX_AGC_A_MCS07_MCS04, MASKDWORD, tx_agc); + PHY_SetBBReg(adapter, REG_TX_AGC_A_MCS11_MCS08, MASKDWORD, tx_agc); + PHY_SetBBReg(adapter, REG_TX_AGC_A_MCS15_MCS12, MASKDWORD, tx_agc); + RT_DISP(FPHY, PHY_TXPWR, ("odm_tx_pwr_track_set_pwr88_e: OFDM Tx-rf(A) Power = 0x%x\n", tx_agc)); +#endif + +#endif +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + /* phy_rf6052_set_cck_tx_power(dm->priv, *(dm->channel)); */ + /* phy_rf6052_set_ofdm_tx_power(dm->priv, *(dm->channel)); */ +#endif + + } else if (method == BBSWING) { + final_ofdm_swing_index = cali_info->default_ofdm_index + cali_info->absolute_ofdm_swing_idx[rf_path]; + final_cck_swing_index = cali_info->default_cck_index + cali_info->absolute_ofdm_swing_idx[rf_path]; + + if (final_ofdm_swing_index >= pwr_tracking_limit_ofdm) + final_ofdm_swing_index = pwr_tracking_limit_ofdm; + else if (final_ofdm_swing_index < 0) + final_ofdm_swing_index = 0; + + if (final_cck_swing_index >= CCK_TABLE_SIZE) + final_cck_swing_index = CCK_TABLE_SIZE - 1; + else if (cali_info->bb_swing_idx_cck < 0) + final_cck_swing_index = 0; + + /* Adjust BB swing by OFDM IQ matrix */ + if (rf_path == RF_PATH_A) { + set_iqk_matrix_8188e(dm, final_ofdm_swing_index, RF_PATH_A, + cali_info->iqk_matrix_reg_setting[channel_mapped_index].value[0][0], + cali_info->iqk_matrix_reg_setting[channel_mapped_index].value[0][1]); + /* Adjust BB swing by CCK filter coefficient */ + if (*dm->channel != 14) { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch1_ch13_new[final_cck_swing_index][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch1_ch13_new[final_cck_swing_index][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch1_ch13_new[final_cck_swing_index][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch1_ch13_new[final_cck_swing_index][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch1_ch13_new[final_cck_swing_index][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch1_ch13_new[final_cck_swing_index][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch1_ch13_new[final_cck_swing_index][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch1_ch13_new[final_cck_swing_index][7]); + } else { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch14_new[final_cck_swing_index][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch14_new[final_cck_swing_index][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch14_new[final_cck_swing_index][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch14_new[final_cck_swing_index][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch14_new[final_cck_swing_index][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch14_new[final_cck_swing_index][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch14_new[final_cck_swing_index][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch14_new[final_cck_swing_index][7]); + } + } + } else if (method == MIX_MODE) { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "cali_info->default_ofdm_index=%d, dm->DefaultCCKIndex=%d, cali_info->absolute_ofdm_swing_idx[rf_path]=%d, rf_path = %d\n", + cali_info->default_ofdm_index, cali_info->default_cck_index, cali_info->absolute_ofdm_swing_idx[rf_path], rf_path); + + final_cck_swing_index = cali_info->default_cck_index + cali_info->absolute_ofdm_swing_idx[rf_path]; + final_ofdm_swing_index = cali_info->default_ofdm_index + cali_info->absolute_ofdm_swing_idx[rf_path]; + + if (final_ofdm_swing_index > pwr_tracking_limit_ofdm) { /* BBSwing higher then Limit */ + cali_info->remnant_ofdm_swing_idx[rf_path] = final_ofdm_swing_index - pwr_tracking_limit_ofdm; + + set_iqk_matrix_8188e(dm, pwr_tracking_limit_ofdm, RF_PATH_A, + cali_info->iqk_matrix_reg_setting[channel_mapped_index].value[0][0], + cali_info->iqk_matrix_reg_setting[channel_mapped_index].value[0][1]); + + cali_info->modify_tx_agc_flag_path_a = true; + + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, OFDM); + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, HT_MCS0_MCS7); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "******Path_A Over BBSwing Limit, pwr_tracking_limit = %d, Remnant tx_agc value = %d\n", pwr_tracking_limit_ofdm, cali_info->remnant_ofdm_swing_idx[rf_path]); + } else if (final_ofdm_swing_index < 0) { + cali_info->remnant_ofdm_swing_idx[rf_path] = final_ofdm_swing_index ; + + set_iqk_matrix_8188e(dm, 0, RF_PATH_A, + cali_info->iqk_matrix_reg_setting[channel_mapped_index].value[0][0], + cali_info->iqk_matrix_reg_setting[channel_mapped_index].value[0][1]); + + cali_info->modify_tx_agc_flag_path_a = true; + + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, OFDM); + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, HT_MCS0_MCS7); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "******Path_A Lower then BBSwing lower bound 0, Remnant tx_agc value = %d\n", cali_info->remnant_ofdm_swing_idx[rf_path]); + } else { + set_iqk_matrix_8188e(dm, final_ofdm_swing_index, RF_PATH_A, + cali_info->iqk_matrix_reg_setting[channel_mapped_index].value[0][0], + cali_info->iqk_matrix_reg_setting[channel_mapped_index].value[0][1]); + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "******Path_A Compensate with BBSwing, final_ofdm_swing_index = %d\n", final_ofdm_swing_index); + + if (cali_info->modify_tx_agc_flag_path_a) { /* If tx_agc has changed, reset tx_agc again */ + cali_info->remnant_ofdm_swing_idx[rf_path] = 0; + + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, OFDM); + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, HT_MCS0_MCS7); + + cali_info->modify_tx_agc_flag_path_a = false; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "******Path_A dm->Modify_TxAGC_Flag = false\n"); + } + } + + if (final_cck_swing_index > pwr_tracking_limit_cck) { + cali_info->remnant_cck_swing_idx = final_cck_swing_index - pwr_tracking_limit_cck; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "******Path_A CCK Over Limit, pwr_tracking_limit_cck = %d, cali_info->remnant_cck_swing_idx = %d\n", pwr_tracking_limit_cck, cali_info->remnant_cck_swing_idx); + + /* Adjust BB swing by CCK filter coefficient */ + + if (*dm->channel != 14) { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch1_ch13_new[pwr_tracking_limit_cck][7]); + } else { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch14_new[pwr_tracking_limit_cck][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch14_new[pwr_tracking_limit_cck][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch14_new[pwr_tracking_limit_cck][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch14_new[pwr_tracking_limit_cck][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch14_new[pwr_tracking_limit_cck][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch14_new[pwr_tracking_limit_cck][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch14_new[pwr_tracking_limit_cck][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch14_new[pwr_tracking_limit_cck][7]); + } + + cali_info->modify_tx_agc_flag_path_a_cck = true; + + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, CCK); + + } else if (final_cck_swing_index < 0) { /* Lowest CCK index = 0 */ + cali_info->remnant_cck_swing_idx = final_cck_swing_index; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "******Path_A CCK Under Limit, pwr_tracking_limit_cck = %d, cali_info->remnant_cck_swing_idx = %d\n", 0, cali_info->remnant_cck_swing_idx); + + if (*dm->channel != 14) { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch1_ch13_new[0][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch1_ch13_new[0][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch1_ch13_new[0][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch1_ch13_new[0][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch1_ch13_new[0][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch1_ch13_new[0][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch1_ch13_new[0][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch1_ch13_new[0][7]); + } else { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch14_new[0][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch14_new[0][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch14_new[0][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch14_new[0][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch14_new[0][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch14_new[0][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch14_new[0][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch14_new[0][7]); + } + + cali_info->modify_tx_agc_flag_path_a_cck = true; + + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, CCK); + + } else { + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "******Path_A CCK Compensate with BBSwing, final_cck_swing_index = %d\n", final_cck_swing_index); + + if (*dm->channel != 14) { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch1_ch13_new[final_cck_swing_index][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch1_ch13_new[final_cck_swing_index][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch1_ch13_new[final_cck_swing_index][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch1_ch13_new[final_cck_swing_index][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch1_ch13_new[final_cck_swing_index][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch1_ch13_new[final_cck_swing_index][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch1_ch13_new[final_cck_swing_index][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch1_ch13_new[final_cck_swing_index][7]); + } else { + odm_write_1byte(dm, 0xa22, cck_swing_table_ch14_new[final_cck_swing_index][0]); + odm_write_1byte(dm, 0xa23, cck_swing_table_ch14_new[final_cck_swing_index][1]); + odm_write_1byte(dm, 0xa24, cck_swing_table_ch14_new[final_cck_swing_index][2]); + odm_write_1byte(dm, 0xa25, cck_swing_table_ch14_new[final_cck_swing_index][3]); + odm_write_1byte(dm, 0xa26, cck_swing_table_ch14_new[final_cck_swing_index][4]); + odm_write_1byte(dm, 0xa27, cck_swing_table_ch14_new[final_cck_swing_index][5]); + odm_write_1byte(dm, 0xa28, cck_swing_table_ch14_new[final_cck_swing_index][6]); + odm_write_1byte(dm, 0xa29, cck_swing_table_ch14_new[final_cck_swing_index][7]); + } + + if (cali_info->modify_tx_agc_flag_path_a_cck) { /* If tx_agc has changed, reset tx_agc again */ + cali_info->remnant_cck_swing_idx = 0; + PHY_SetTxPowerIndexByRateSection(adapter, RF_PATH_A, *dm->channel, CCK); + cali_info->modify_tx_agc_flag_path_a_cck = false; + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "******Path_A dm->Modify_TxAGC_Flag_CCK = false\n"); + } + + } + } else + return; +} /* odm_TxPwrTrackSetPwr88E */ + +void +get_delta_swing_table_8188e( + void *dm_void, + u8 **temperature_up_a, + u8 **temperature_down_a, + u8 **temperature_up_b, + u8 **temperature_down_b +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct _ADAPTER *adapter = dm->adapter; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + u8 tx_rate = 0xFF; + u8 channel = *dm->channel; + + if (*(dm->mp_mode) == true) { +#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE)) +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) +#if (MP_DRIVER == 1) + PMPT_CONTEXT p_mpt_ctx = &(adapter->MptCtx); + + tx_rate = MptToMgntRate(p_mpt_ctx->MptRateIndex); +#endif +#elif (DM_ODM_SUPPORT_TYPE & ODM_CE) +#ifdef CONFIG_MP_INCLUDED + PMPT_CONTEXT p_mpt_ctx = &(adapter->mppriv.mpt_ctx); + + tx_rate = mpt_to_mgnt_rate(p_mpt_ctx->mpt_rate_index); +#endif +#endif +#endif + } else { + u16 rate = *(dm->forced_data_rate); + + if (!rate) { /*auto rate*/ +#if (DM_ODM_SUPPORT_TYPE & ODM_WIN) + tx_rate = ((PADAPTER)adapter)->HalFunc.GetHwRateFromMRateHandler(dm->tx_rate); +#elif (DM_ODM_SUPPORT_TYPE & ODM_CE) + tx_rate = hw_rate_to_m_rate(dm->tx_rate); +#endif + } else /*force rate*/ + tx_rate = (u8)rate; + } + + RF_DBG(dm, DBG_RF_TX_PWR_TRACK, "Power Tracking tx_rate=0x%X\n", tx_rate); + + if (1 <= channel && channel <= 14) { + if (IS_CCK_RATE(tx_rate)) { + *temperature_up_a = cali_info->delta_swing_table_idx_2g_cck_a_p; + *temperature_down_a = cali_info->delta_swing_table_idx_2g_cck_a_n; + } else { + *temperature_up_a = cali_info->delta_swing_table_idx_2ga_p; + *temperature_down_a = cali_info->delta_swing_table_idx_2ga_n; + } + } else { + *temperature_up_a = (u8 *)delta_swing_table_idx_2ga_p_8188e; + *temperature_down_a = (u8 *)delta_swing_table_idx_2ga_n_8188e; + } +} + +void configure_txpower_track_8188e( + struct txpwrtrack_cfg *config +) +{ + config->swing_table_size_cck = CCK_TABLE_SIZE; + config->swing_table_size_ofdm = OFDM_TABLE_SIZE; + config->threshold_iqk = IQK_THRESHOLD; + config->average_thermal_num = AVG_THERMAL_NUM_88E; + config->rf_path_count = MAX_PATH_NUM_8188E; + config->thermal_reg_addr = RF_T_METER_88E; + + config->odm_tx_pwr_track_set_pwr = odm_tx_pwr_track_set_pwr88_e; + config->do_iqk = do_iqk_8188e; + config->phy_lc_calibrate = halrf_lck_trigger; + config->get_delta_swing_table = get_delta_swing_table_8188e; +} + +/* 1 7. IQK */ +#define MAX_TOLERANCE 5 +#define IQK_DELAY_TIME 1 /* ms */ + +u8 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ +phy_path_a_iqk_8188e( + + struct dm_struct *dm, + boolean config_path_b, + u32 ktimes +) +{ + u32 reg_eac, reg_e94, reg_e9c, reg_ea4; + u8 result = 0x00; + RF_DBG(dm, DBG_RF_IQK, "path A IQK!\n"); + + /* 1 Tx IQK */ + /* path-A IQK setting */ + RF_DBG(dm, DBG_RF_IQK, "path-A IQK setting!\n"); + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x18008c1c); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x38008c1c); + odm_set_bb_reg(dm, REG_TX_IQK_PI_A, MASKDWORD, 0x821403ff); + odm_set_bb_reg(dm, REG_RX_IQK_PI_A, MASKDWORD, 0x28160000); + + if (ktimes == 0x0) { + /* LO calibration on */ + RF_DBG(dm, DBG_RF_IQK, "LO calibration setting!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_RSP, MASKDWORD, 0x00462911); + } else { + /* LO calibration off */ + RF_DBG(dm, DBG_RF_IQK, "LO calibration setting!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_RSP, MASKDWORD, 0x0046a911); + } + + /* TX IQK mode setting */ + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x000000); + odm_set_rf_reg(dm, RF_PATH_A, RF_WE_LUT, RFREGOFFSETMASK, 0x800a0); + odm_set_rf_reg(dm, RF_PATH_A, RF_RCK_OS, RFREGOFFSETMASK, 0x20000); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G1, RFREGOFFSETMASK, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G2, RFREGOFFSETMASK, 0x07f7f); + + /* PA,PAD gain adjust */ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xdf, RFREGOFFSETMASK, 0x980); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x56, RFREGOFFSETMASK, 0x510f0); + + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x808000); + + /* One shot, path A LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf9000000); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf8000000); + + if (ktimes == 0) { + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path A LOK & IQK.\n", IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E * 2); + + } else { + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path A LOK & IQK.\n", IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E); + + } + + /* reload RF 0xdf */ + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x000000); + odm_set_rf_reg(dm, RF_PATH_A, RF_0xdf, RFREGOFFSETMASK, 0x180); + + + + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_e94 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe94 = 0x%x\n", reg_e94); + reg_e9c = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe9c = 0x%x\n", reg_e9c); + reg_ea4 = odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xea4 = 0x%x\n", reg_ea4); + + if (!(reg_eac & BIT(28)) && + (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && + (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + else /* if Tx not OK, ignore Rx */ + return result; + +#if 0 + if (!(reg_eac & BIT(27)) && /* if Tx is OK, check whether Rx is OK */ + (((reg_ea4 & 0x03FF0000) >> 16) != 0x132) && + (((reg_eac & 0x03FF0000) >> 16) != 0x36)) + result |= 0x02; + else + RT_DISP(FINIT, INIT_IQK, ("path A Rx IQK fail!!\n")); +#endif + + return result; + + +} + +u8 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ +phy_path_a_rx_iqk( + struct dm_struct *dm, + boolean config_path_b +) +{ + u32 reg_eac, reg_e94, reg_e9c, reg_ea4, u4tmp; + u8 result = 0x00; + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK!\n"); + + /* 1 Get TXIMR setting */ + /* modify RXIQK mode table */ + RF_DBG(dm, DBG_RF_IQK, "path-A Rx IQK modify RXIQK mode table!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x000000); + odm_set_rf_reg(dm, RF_PATH_A, RF_WE_LUT, RFREGOFFSETMASK, 0x800a0); + odm_set_rf_reg(dm, RF_PATH_A, RF_RCK_OS, RFREGOFFSETMASK, 0x30000); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G1, RFREGOFFSETMASK, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G2, RFREGOFFSETMASK, 0xf117b); + + /* PA,PAD gain adjust */ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xdf, RFREGOFFSETMASK, 0x980); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x56, RFREGOFFSETMASK, 0x510f0); + + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x808000); + + /* IQK setting */ + odm_set_bb_reg(dm, REG_TX_IQK, MASKDWORD, 0x01007c00); + odm_set_bb_reg(dm, REG_RX_IQK, MASKDWORD, 0x81004800); + + /* path-A IQK setting */ + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x18008c1c); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x38008c1c); + odm_set_bb_reg(dm, REG_TX_IQK_PI_A, MASKDWORD, 0x82160fff); + odm_set_bb_reg(dm, REG_RX_IQK_PI_A, MASKDWORD, 0x28160000); + + /* LO calibration setting */ + RF_DBG(dm, DBG_RF_IQK, "LO calibration setting!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_RSP, MASKDWORD, 0x0046a911); + + /* One shot, path A LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf9000000); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf8000000); + + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path A LOK & IQK.\n", IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E); + + /* reload RF 0xdf */ + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x000000); + odm_set_rf_reg(dm, RF_PATH_A, RF_0xdf, RFREGOFFSETMASK, 0x180); + + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_e94 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe94 = 0x%x\n", reg_e94); + reg_e9c = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe9c = 0x%x\n", reg_e9c); + + if (!(reg_eac & BIT(28)) && + (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && + (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + else /* if Tx not OK, ignore Rx */ + return result; + + u4tmp = 0x80007C00 | (reg_e94 & 0x3FF0000) | ((reg_e9c & 0x3FF0000) >> 16); + odm_set_bb_reg(dm, REG_TX_IQK, MASKDWORD, u4tmp); + RF_DBG(dm, DBG_RF_IQK, "0xe40 = 0x%x u4tmp = 0x%x\n", odm_get_bb_reg(dm, REG_TX_IQK, MASKDWORD), u4tmp); + + + /* 1 RX IQK */ + /* modify RXIQK mode table */ + RF_DBG(dm, DBG_RF_IQK, "path-A Rx IQK modify RXIQK mode table 2!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x000000); + odm_set_rf_reg(dm, RF_PATH_A, RF_WE_LUT, RFREGOFFSETMASK, 0x800a0); + odm_set_rf_reg(dm, RF_PATH_A, RF_RCK_OS, RFREGOFFSETMASK, 0x30000); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G1, RFREGOFFSETMASK, 0x0000f); + odm_set_rf_reg(dm, RF_PATH_A, RF_TXPA_G2, RFREGOFFSETMASK, 0xf7ffa); + + /* PA,PAD gain adjust */ + odm_set_rf_reg(dm, RF_PATH_A, RF_0xdf, RFREGOFFSETMASK, 0x980); + odm_set_rf_reg(dm, RF_PATH_A, RF_0x56, RFREGOFFSETMASK, 0x51000); + + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x808000); + + /* IQK setting */ + odm_set_bb_reg(dm, REG_RX_IQK, MASKDWORD, 0x01004800); + + /* path-A IQK setting */ + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x38008c1c); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x18008c1c); + odm_set_bb_reg(dm, REG_TX_IQK_PI_A, MASKDWORD, 0x82160000); + odm_set_bb_reg(dm, REG_RX_IQK_PI_A, MASKDWORD, 0x28160fff); + + /* LO calibration setting */ + RF_DBG(dm, DBG_RF_IQK, "LO calibration setting!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_RSP, MASKDWORD, 0x0046a911); + + /* One shot, path A LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf9000000); + odm_set_bb_reg(dm, REG_IQK_AGC_PTS, MASKDWORD, 0xf8000000); + + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path A LOK & IQK.\n", IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E); + + /* reload RF 0xdf */ + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x000000); + odm_set_rf_reg(dm, RF_PATH_A, RF_0xdf, RFREGOFFSETMASK, 0x180); + + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_e94 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe94 = 0x%x\n", reg_e94); + reg_e9c = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xe9c = 0x%x\n", reg_e9c); + reg_ea4 = odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xea4 = 0x%x\n", reg_ea4); + +#if 0 + if (!(reg_eac & BIT(28)) && + (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && + (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + else /* if Tx not OK, ignore Rx */ + return result; +#endif + + if (!(reg_eac & BIT(27)) && /* if Tx is OK, check whether Rx is OK */ + (((reg_ea4 & 0x03FF0000) >> 16) != 0x132) && + (((reg_eac & 0x03FF0000) >> 16) != 0x36)) + result |= 0x02; + else + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK fail!!\n"); + + return result; + + +} + +u8 /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */ +phy_path_b_iqk_8188e( + struct dm_struct *dm +) +{ + u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc; + u8 result = 0x00; + RF_DBG(dm, DBG_RF_IQK, "path B IQK!\n"); + + /* One shot, path B LOK & IQK */ + RF_DBG(dm, DBG_RF_IQK, "One shot, path A LOK & IQK!\n"); + odm_set_bb_reg(dm, REG_IQK_AGC_CONT, MASKDWORD, 0x00000002); + odm_set_bb_reg(dm, REG_IQK_AGC_CONT, MASKDWORD, 0x00000000); + + /* delay x ms */ + RF_DBG(dm, DBG_RF_IQK, "delay %d ms for One shot, path B LOK & IQK.\n", IQK_DELAY_TIME_88E); + /* platform_stall_execution(IQK_DELAY_TIME_88E*1000); */ + ODM_delay_ms(IQK_DELAY_TIME_88E); + + /* Check failed */ + reg_eac = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeac = 0x%x\n", reg_eac); + reg_eb4 = odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_B, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xeb4 = 0x%x\n", reg_eb4); + reg_ebc = odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_B, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xebc = 0x%x\n", reg_ebc); + reg_ec4 = odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_B_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xec4 = 0x%x\n", reg_ec4); + reg_ecc = odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_B_2, MASKDWORD); + RF_DBG(dm, DBG_RF_IQK, "0xecc = 0x%x\n", reg_ecc); + + if (!(reg_eac & BIT(31)) && + (((reg_eb4 & 0x03FF0000) >> 16) != 0x142) && + (((reg_ebc & 0x03FF0000) >> 16) != 0x42)) + result |= 0x01; + else + return result; + + if (!(reg_eac & BIT(30)) && + (((reg_ec4 & 0x03FF0000) >> 16) != 0x132) && + (((reg_ecc & 0x03FF0000) >> 16) != 0x36)) + result |= 0x02; + else + RF_DBG(dm, DBG_RF_IQK, "path B Rx IQK fail!!\n"); + + + return result; + +} + +void +_phy_path_a_fill_iqk_matrix( + struct dm_struct *dm, + boolean is_iqk_ok, + s32 result[][8], + u8 final_candidate, + boolean is_tx_only +) +{ + u32 oldval_0, X, TX0_A, reg; + s32 Y, TX0_C; + RF_DBG(dm, DBG_RF_IQK, "path A IQ Calibration %s !\n", (is_iqk_ok) ? "Success" : "Failed"); + + if (final_candidate == 0xFF) + return; + + else if (is_iqk_ok) { + oldval_0 = (odm_get_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, MASKDWORD) >> 22) & 0x3FF; + + X = result[final_candidate][0]; + if ((X & 0x00000200) != 0) + X = X | 0xFFFFFC00; + TX0_A = (X * oldval_0) >> 8; + RF_DBG(dm, DBG_RF_IQK, "X = 0x%x, TX0_A = 0x%x, oldval_0 0x%x\n", X, TX0_A, oldval_0); + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 0x3FF, TX0_A); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(31), ((X * oldval_0 >> 7) & 0x1)); + + Y = result[final_candidate][1]; + if ((Y & 0x00000200) != 0) + Y = Y | 0xFFFFFC00; + + + TX0_C = (Y * oldval_0) >> 8; + RF_DBG(dm, DBG_RF_IQK, "Y = 0x%x, TX = 0x%x\n", Y, TX0_C); + odm_set_bb_reg(dm, REG_OFDM_0_XC_TX_AFE, 0xF0000000, ((TX0_C & 0x3C0) >> 6)); + odm_set_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 0x003F0000, (TX0_C & 0x3F)); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(29), ((Y * oldval_0 >> 7) & 0x1)); + + if (is_tx_only) { + RF_DBG(dm, DBG_RF_IQK, "_phy_path_a_fill_iqk_matrix only Tx OK\n"); + return; + } + + reg = result[final_candidate][2]; +#if (DM_ODM_SUPPORT_TYPE == ODM_AP) + if (RTL_ABS(reg, 0x100) >= 16) + reg = 0x100; +#endif + odm_set_bb_reg(dm, REG_OFDM_0_XA_RX_IQ_IMBALANCE, 0x3FF, reg); + + reg = result[final_candidate][3] & 0x3F; + odm_set_bb_reg(dm, REG_OFDM_0_XA_RX_IQ_IMBALANCE, 0xFC00, reg); + + reg = (result[final_candidate][3] >> 6) & 0xF; + odm_set_bb_reg(dm, REG_OFDM_0_RX_IQ_EXT_ANTA, 0xF0000000, reg); + } +} + +void +_phy_path_b_fill_iqk_matrix( + struct dm_struct *dm, + boolean is_iqk_ok, + s32 result[][8], + u8 final_candidate, + boolean is_tx_only /* do Tx only */ +) +{ + u32 oldval_1, X, TX1_A, reg; + s32 Y, TX1_C; + + RF_DBG(dm, DBG_RF_IQK, "path B IQ Calibration %s !\n", (is_iqk_ok) ? "Success" : "Failed"); + + if (final_candidate == 0xFF) + return; + + else if (is_iqk_ok) { + oldval_1 = (odm_get_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, MASKDWORD) >> 22) & 0x3FF; + + X = result[final_candidate][4]; + if ((X & 0x00000200) != 0) + X = X | 0xFFFFFC00; + TX1_A = (X * oldval_1) >> 8; + RF_DBG(dm, DBG_RF_IQK, "X = 0x%x, TX1_A = 0x%x\n", X, TX1_A); + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, 0x3FF, TX1_A); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(27), ((X * oldval_1 >> 7) & 0x1)); + + Y = result[final_candidate][5]; + if ((Y & 0x00000200) != 0) + Y = Y | 0xFFFFFC00; + + TX1_C = (Y * oldval_1) >> 8; + RF_DBG(dm, DBG_RF_IQK, "Y = 0x%x, TX1_C = 0x%x\n", Y, TX1_C); + odm_set_bb_reg(dm, REG_OFDM_0_XD_TX_AFE, 0xF0000000, ((TX1_C & 0x3C0) >> 6)); + odm_set_bb_reg(dm, REG_OFDM_0_XB_TX_IQ_IMBALANCE, 0x003F0000, (TX1_C & 0x3F)); + + odm_set_bb_reg(dm, REG_OFDM_0_ECCA_THRESHOLD, BIT(25), ((Y * oldval_1 >> 7) & 0x1)); + + if (is_tx_only) + return; + + reg = result[final_candidate][6]; + odm_set_bb_reg(dm, REG_OFDM_0_XB_RX_IQ_IMBALANCE, 0x3FF, reg); + + reg = result[final_candidate][7] & 0x3F; + odm_set_bb_reg(dm, REG_OFDM_0_XB_RX_IQ_IMBALANCE, 0xFC00, reg); + + reg = (result[final_candidate][7] >> 6) & 0xF; + odm_set_bb_reg(dm, REG_OFDM_0_AGC_RSSI_TABLE, 0x0000F000, reg); + } +} + +void +_phy_save_adda_registers( + struct dm_struct *dm, + u32 *adda_reg, + u32 *adda_backup, + u32 register_num +) +{ + u32 i; + + if (odm_check_power_status(dm) == false) + return; + RF_DBG(dm, DBG_RF_IQK, "Save ADDA parameters.\n"); + for (i = 0 ; i < register_num ; i++) + adda_backup[i] = odm_get_bb_reg(dm, adda_reg[i], MASKDWORD); +} + + +void +_phy_save_mac_registers( + struct dm_struct *dm, + u32 *mac_reg, + u32 *mac_backup +) +{ + u32 i; + + RF_DBG(dm, DBG_RF_IQK, "Save MAC parameters.\n"); + for (i = 0 ; i < (IQK_MAC_REG_NUM - 1); i++) + mac_backup[i] = odm_read_1byte(dm, mac_reg[i]); + mac_backup[i] = odm_read_4byte(dm, mac_reg[i]); + +} + + +void +_phy_reload_adda_registers( + struct dm_struct *dm, + u32 *adda_reg, + u32 *adda_backup, + u32 regiester_num +) +{ + u32 i; + + RF_DBG(dm, DBG_RF_IQK, "Reload ADDA power saving parameters !\n"); + for (i = 0 ; i < regiester_num; i++) + odm_set_bb_reg(dm, adda_reg[i], MASKDWORD, adda_backup[i]); +} + +void +_phy_reload_mac_registers( + struct dm_struct *dm, + u32 *mac_reg, + u32 *mac_backup +) +{ + u32 i; + + RF_DBG(dm, DBG_RF_IQK, "Reload MAC parameters !\n"); + for (i = 0 ; i < (IQK_MAC_REG_NUM - 1); i++) + odm_write_1byte(dm, mac_reg[i], (u8)mac_backup[i]); + odm_write_4byte(dm, mac_reg[i], mac_backup[i]); +} + + +void +_phy_path_adda_on( + struct dm_struct *dm, + u32 *adda_reg, + boolean is_path_a_on, + boolean is2T +) +{ + u32 path_on; + u32 i; + + RF_DBG(dm, DBG_RF_IQK, "ADDA ON.\n"); + + path_on = is_path_a_on ? 0x04db25a4 : 0x0b1b25a4; + if (false == is2T) { + path_on = 0x0bdb25a0; + odm_set_bb_reg(dm, adda_reg[0], MASKDWORD, 0x0b1b25a0); + } else + odm_set_bb_reg(dm, adda_reg[0], MASKDWORD, path_on); + + for (i = 1 ; i < IQK_ADDA_REG_NUM ; i++) + odm_set_bb_reg(dm, adda_reg[i], MASKDWORD, path_on); + +} + +void +_phy_mac_setting_calibration( + + struct dm_struct *dm, + u32 *mac_reg, + u32 *mac_backup +) +{ + u32 i = 0; + + RF_DBG(dm, DBG_RF_IQK, "MAC settings for Calibration.\n"); + + odm_write_1byte(dm, mac_reg[i], 0x3F); + + for (i = 1 ; i < (IQK_MAC_REG_NUM - 1); i++) + odm_write_1byte(dm, mac_reg[i], (u8)(mac_backup[i] & (~BIT(3)))); + odm_write_1byte(dm, mac_reg[i], (u8)(mac_backup[i] & (~BIT(5)))); + +} + +void +_phy_path_a_stand_by( + struct dm_struct *dm +) +{ + RF_DBG(dm, DBG_RF_IQK, "path-A standby mode!\n"); + + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x000000); + odm_set_bb_reg(dm, R_0x840, MASKDWORD, 0x00010000); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x808000); +} + +void +_phy_pi_mode_switch( + struct dm_struct *dm, + boolean pi_mode +) +{ + u32 mode; + + RF_DBG(dm, DBG_RF_IQK, "BB Switch to %s mode!\n", (pi_mode ? "PI" : "SI")); + + mode = pi_mode ? 0x01000100 : 0x01000000; + odm_set_bb_reg(dm, REG_FPGA0_XA_HSSI_PARAMETER1, MASKDWORD, mode); + odm_set_bb_reg(dm, REG_FPGA0_XB_HSSI_PARAMETER1, MASKDWORD, mode); +} + +boolean +phy_simularity_compare_8188e( + struct dm_struct *dm, + s32 result[][8], + u8 c1, + u8 c2 +) +{ + u32 i, j, diff, simularity_bit_map, bound = 0; + u8 final_candidate[2] = {0xFF, 0xFF}; /* for path A and path B */ + boolean is_result = true; + boolean is2T = false; + + if (is2T) + bound = 8; + else + bound = 4; + + RF_DBG(dm, DBG_RF_IQK, "===> IQK:phy_simularity_compare_8188e c1 %d c2 %d!!!\n", c1, c2); + + + simularity_bit_map = 0; + + for (i = 0; i < bound; i++) { + diff = (result[c1][i] > result[c2][i]) ? (result[c1][i] - result[c2][i]) : (result[c2][i] - result[c1][i]); + if (diff > MAX_TOLERANCE) { + RF_DBG(dm, DBG_RF_IQK, "IQK:phy_simularity_compare_8188e differnece overflow index %d compare1 0x%x compare2 0x%x!!!\n", i, result[c1][i], result[c2][i]); + + if ((i == 2 || i == 6) && !simularity_bit_map) { + if (result[c1][i] + result[c1][i + 1] == 0) + final_candidate[(i / 4)] = c2; + else if (result[c2][i] + result[c2][i + 1] == 0) + final_candidate[(i / 4)] = c1; + else + simularity_bit_map = simularity_bit_map | (1 << i); + } else + simularity_bit_map = simularity_bit_map | (1 << i); + } + } + + RF_DBG(dm, DBG_RF_IQK, "IQK:phy_simularity_compare_8188e simularity_bit_map %d !!!\n", simularity_bit_map); + + if (simularity_bit_map == 0) { + for (i = 0; i < (bound / 4); i++) { + if (final_candidate[i] != 0xFF) { + for (j = i * 4; j < (i + 1) * 4 - 2; j++) + result[3][j] = result[final_candidate[i]][j]; + is_result = false; + } + } + return is_result; + } else if (!(simularity_bit_map & 0x0F)) { /* path A OK */ + for (i = 0; i < 4; i++) + result[3][i] = result[c1][i]; + return false; + } else if (!(simularity_bit_map & 0xF0) && is2T) { /* path B OK */ + for (i = 4; i < 8; i++) + result[3][i] = result[c1][i]; + return false; + } else + return false; + +} + + + +void +_phy_iq_calibrate_8188e( + struct dm_struct *dm, + s32 result[][8], + u8 t, + boolean is2T +) +{ + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + u32 i; + u8 path_aok, path_bok; + u32 ADDA_REG[IQK_ADDA_REG_NUM] = { + REG_FPGA0_XCD_SWITCH_CONTROL, REG_BLUE_TOOTH, + REG_RX_WAIT_CCA, REG_TX_CCK_RFON, + REG_TX_CCK_BBON, REG_TX_OFDM_RFON, + REG_TX_OFDM_BBON, REG_TX_TO_RX, + REG_TX_TO_TX, REG_RX_CCK, + REG_RX_OFDM, REG_RX_WAIT_RIFS, + REG_RX_TO_RX, REG_STANDBY, + REG_SLEEP, REG_PMPD_ANAEN + }; + u32 IQK_MAC_REG[IQK_MAC_REG_NUM] = { + REG_TXPAUSE, REG_BCN_CTRL, + REG_BCN_CTRL_1, REG_GPIO_MUXCFG + }; + + /* since 92C & 92D have the different define in IQK_BB_REG */ + u32 IQK_BB_REG_92C[IQK_BB_REG_NUM] = { + REG_OFDM_0_TRX_PATH_ENABLE, REG_OFDM_0_TR_MUX_PAR, + REG_FPGA0_XCD_RF_INTERFACE_SW, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B, + REG_FPGA0_XAB_RF_INTERFACE_SW, REG_FPGA0_XA_RF_INTERFACE_OE, + REG_FPGA0_XB_RF_INTERFACE_OE, REG_CCK_0_AFE_SETTING + }; + +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) + u32 retry_count = 2; +#else +#if MP_DRIVER + const u32 retry_count = 2; +#else + const u32 retry_count = 2; +#endif +#endif + + /* Note: IQ calibration must be performed after loading */ + /* PHY_REG.txt , and radio_a, radio_b.txt */ + + /* u32 bbvalue; */ + +#if (DM_ODM_SUPPORT_TYPE & (ODM_AP)) +#ifdef MP_TEST + if (*(dm->mp_mode)) + retry_count = 9; +#endif +#endif + + + if (t == 0) { + /* bbvalue = odm_get_bb_reg(dm, REG_FPGA0_RFMOD, MASKDWORD); + * RT_DISP(FINIT, INIT_IQK, ("_phy_iq_calibrate_8188e()==>0x%08x\n",bbvalue)); */ + + RF_DBG(dm, DBG_RF_IQK, "IQ Calibration for %s for %d times\n", (is2T ? "2T2R" : "1T1R"), t); + + /* Save ADDA parameters, turn path A ADDA on */ + _phy_save_adda_registers(dm, ADDA_REG, cali_info->ADDA_backup, IQK_ADDA_REG_NUM); + _phy_save_mac_registers(dm, IQK_MAC_REG, cali_info->IQK_MAC_backup); + _phy_save_adda_registers(dm, IQK_BB_REG_92C, cali_info->IQK_BB_backup, IQK_BB_REG_NUM); + } + RF_DBG(dm, DBG_RF_IQK, "IQ Calibration for %s for %d times\n", (is2T ? "2T2R" : "1T1R"), t); + + _phy_path_adda_on(dm, ADDA_REG, true, is2T); + + if (t == 0) + cali_info->is_rf_pi_enable = (u8)odm_get_bb_reg(dm, REG_FPGA0_XA_HSSI_PARAMETER1, BIT(8)); + + if (!cali_info->is_rf_pi_enable) { + /* Switch BB to PI mode to do IQ Calibration. */ + _phy_pi_mode_switch(dm, true); + } + + /* MAC settings */ + _phy_mac_setting_calibration(dm, IQK_MAC_REG, cali_info->IQK_MAC_backup); + + /* BB setting */ + /* odm_set_bb_reg(dm, REG_FPGA0_RFMOD, BIT24, 0x00); */ + odm_set_bb_reg(dm, REG_CCK_0_AFE_SETTING, 0x0f000000, 0xf); + odm_set_bb_reg(dm, REG_OFDM_0_TRX_PATH_ENABLE, MASKDWORD, 0x03a05600); + odm_set_bb_reg(dm, REG_OFDM_0_TR_MUX_PAR, MASKDWORD, 0x000800e4); + odm_set_bb_reg(dm, REG_FPGA0_XCD_RF_INTERFACE_SW, MASKDWORD, 0x22204000); + + + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_INTERFACE_SW, BIT(10), 0x01); + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_INTERFACE_SW, BIT(26), 0x01); + odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(10), 0x00); + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(10), 0x00); + + + if (is2T) { + odm_set_bb_reg(dm, REG_FPGA0_XA_LSSI_PARAMETER, MASKDWORD, 0x00010000); + odm_set_bb_reg(dm, REG_FPGA0_XB_LSSI_PARAMETER, MASKDWORD, 0x00010000); + } + + + + + /* Page B init */ + /* AP or IQK */ + odm_set_bb_reg(dm, REG_CONFIG_ANT_A, MASKDWORD, 0x0f600000); + + if (is2T) + odm_set_bb_reg(dm, REG_CONFIG_ANT_B, MASKDWORD, 0x0f600000); + + /* IQ calibration setting */ + RF_DBG(dm, DBG_RF_IQK, "IQK setting!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x808000); + odm_set_bb_reg(dm, REG_TX_IQK, MASKDWORD, 0x01007c00); + odm_set_bb_reg(dm, REG_RX_IQK, MASKDWORD, 0x81004800); + + + for (i = 0 ; i < retry_count ; i++) { + path_aok = phy_path_a_iqk_8188e(dm, is2T, t + i); + + /* if(path_aok == 0x03){ */ + if (path_aok == 0x01) { + RF_DBG(dm, DBG_RF_IQK, "path A Tx IQK Success!!\n"); + result[t][0] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + result[t][1] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + break; + } +#if 0 + else if (i == (retry_count - 1) && path_aok == 0x01) { /* Tx IQK OK */ + RT_DISP(FINIT, INIT_IQK, ("path A IQK Only Tx Success!!\n")); + + result[t][0] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + result[t][1] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD) & 0x3FF0000) >> 16; + } +#endif + } + + for (i = 0 ; i < retry_count ; i++) { + path_aok = phy_path_a_rx_iqk(dm, is2T); + + if (path_aok == 0x03) { + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK Success!!\n"); + /* result[t][0] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_A, MASKDWORD)&0x3FF0000)>>16; + * result[t][1] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_A, MASKDWORD)&0x3FF0000)>>16; */ + result[t][2] = (odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_A_2, MASKDWORD) & 0x3FF0000) >> 16; + result[t][3] = (odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_A_2, MASKDWORD) & 0x3FF0000) >> 16; + break; + } else + RF_DBG(dm, DBG_RF_IQK, "path A Rx IQK Fail!!\n"); + } + + if (0x00 == path_aok) + RF_DBG(dm, DBG_RF_IQK, "path A IQK failed!!\n"); + + if (is2T) { + _phy_path_a_stand_by(dm); + + /* Turn path B ADDA on */ + _phy_path_adda_on(dm, ADDA_REG, false, is2T); + + for (i = 0 ; i < retry_count ; i++) { + path_bok = phy_path_b_iqk_8188e(dm); + + if (path_bok == 0x03) { + RF_DBG(dm, DBG_RF_IQK, "path B IQK Success!!\n"); + result[t][4] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + result[t][5] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + result[t][6] = (odm_get_bb_reg(dm, REG_RX_POWER_BEFORE_IQK_B_2, MASKDWORD) & 0x3FF0000) >> 16; + result[t][7] = (odm_get_bb_reg(dm, REG_RX_POWER_AFTER_IQK_B_2, MASKDWORD) & 0x3FF0000) >> 16; + break; + } else if (i == (retry_count - 1) && path_bok == 0x01) { /* Tx IQK OK */ + RF_DBG(dm, DBG_RF_IQK, "path B Only Tx IQK Success!!\n"); + result[t][4] = (odm_get_bb_reg(dm, REG_TX_POWER_BEFORE_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + result[t][5] = (odm_get_bb_reg(dm, REG_TX_POWER_AFTER_IQK_B, MASKDWORD) & 0x3FF0000) >> 16; + } + } + + if (0x00 == path_bok) + RF_DBG(dm, DBG_RF_IQK, "path B IQK failed!!\n"); + } + + /* Back to BB mode, load original value */ + RF_DBG(dm, DBG_RF_IQK, "IQK:Back to BB mode, load original value!\n"); + odm_set_bb_reg(dm, REG_FPGA0_IQK, 0xffffff00, 0x000000); + + if (t != 0) { + if (!cali_info->is_rf_pi_enable) { + /* Switch back BB to SI mode after finish IQ Calibration. */ + _phy_pi_mode_switch(dm, false); + } + /* Reload ADDA power saving parameters */ + _phy_reload_adda_registers(dm, ADDA_REG, cali_info->ADDA_backup, IQK_ADDA_REG_NUM); + /* Reload MAC parameters */ + _phy_reload_mac_registers(dm, IQK_MAC_REG, cali_info->IQK_MAC_backup); + _phy_reload_adda_registers(dm, IQK_BB_REG_92C, cali_info->IQK_BB_backup, IQK_BB_REG_NUM); + + /* Restore RX initial gain */ + odm_set_bb_reg(dm, REG_FPGA0_XA_LSSI_PARAMETER, MASKDWORD, 0x00032ed3); + if (is2T) + odm_set_bb_reg(dm, REG_FPGA0_XB_LSSI_PARAMETER, MASKDWORD, 0x00032ed3); + + /* load 0xe30 IQC default value */ + odm_set_bb_reg(dm, REG_TX_IQK_TONE_A, MASKDWORD, 0x01008c00); + odm_set_bb_reg(dm, REG_RX_IQK_TONE_A, MASKDWORD, 0x01008c00); + + } + RF_DBG(dm, DBG_RF_IQK, "_phy_iq_calibrate_8188e() <==\n"); + +} + + +void +_phy_lc_calibrate_8188e( + struct dm_struct *dm, + boolean is2T +) +{ + u8 tmp_reg; + u32 rf_amode = 0, rf_bmode = 0, lc_cal, cnt; + + /* Check continuous TX and Packet TX */ + tmp_reg = odm_read_1byte(dm, 0xd03); + + if ((tmp_reg & 0x70) != 0) /* Deal with contisuous TX case */ + odm_write_1byte(dm, 0xd03, tmp_reg & 0x8F); /* disable all continuous TX */ + else /* Deal with Packet TX case */ + odm_write_1byte(dm, REG_TXPAUSE, 0xFF); /* block all queues */ + + if ((tmp_reg & 0x70) != 0) { + /* 1. Read original RF mode */ + /* path-A */ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + rf_amode = odm_get_rf_reg(dm, RF_PATH_A, RF_AC, MASK12BITS); + + /* path-B */ + if (is2T) + rf_bmode = odm_get_rf_reg(dm, RF_PATH_B, RF_AC, MASK12BITS); +#else + rf_amode = odm_get_rf_reg(dm, RF_PATH_A, RF_AC, MASK12BITS); + + /* path-B */ + if (is2T) + rf_bmode = odm_get_rf_reg(dm, RF_PATH_B, RF_AC, MASK12BITS); +#endif + + /* 2. Set RF mode = standby mode */ + /* path-A */ + odm_set_rf_reg(dm, RF_PATH_A, RF_AC, MASK12BITS, (rf_amode & 0x8FFFF) | 0x10000); + + /* path-B */ + if (is2T) + odm_set_rf_reg(dm, RF_PATH_B, RF_AC, MASK12BITS, (rf_bmode & 0x8FFFF) | 0x10000); + } + + /* 3. Read RF reg18 */ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + lc_cal = odm_get_rf_reg(dm, RF_PATH_A, RF_CHNLBW, MASK12BITS); +#else + lc_cal = odm_get_rf_reg(dm, RF_PATH_A, RF_CHNLBW, MASK12BITS); +#endif + + /* 4. Set LC calibration begin bit15 */ + odm_set_rf_reg(dm, RF_PATH_A, RF_CHNLBW, MASK12BITS, lc_cal | 0x08000); + ODM_delay_ms(100); + for (cnt = 0; cnt < 5; cnt++) { + if (odm_get_rf_reg(dm, RF_PATH_A, RF_CHNLBW, 0x8000) != 0x1) + break; + ODM_delay_ms(10); + } + if (cnt == 5) + RF_DBG(dm, DBG_RF_LCK, "LCK time out\n"); + + /*recover channel number*/ + odm_set_rf_reg(dm, RF_PATH_A, RF_CHNLBW, MASK20BITS, lc_cal); + + /* Restore original situation */ + if ((tmp_reg & 0x70) != 0) { /* Deal with contisuous TX case */ + /* path-A */ + odm_write_1byte(dm, 0xd03, tmp_reg); + odm_set_rf_reg(dm, RF_PATH_A, RF_AC, MASK12BITS, rf_amode); + + /* path-B */ + if (is2T) + odm_set_rf_reg(dm, RF_PATH_B, RF_AC, MASK12BITS, rf_bmode); + } else /* Deal with Packet TX case */ + odm_write_1byte(dm, REG_TXPAUSE, 0x00); +} + +/* 20131031*/ +/* IQK:0x14*/ +/* 1.fine tune TXIQK/RXIQK loop gain for SMIC.*/ +/* 2.LOK only perform 1 time.*/ +/* 3.IQK retry count 10-->2 */ +void +phy_iq_calibrate_8188e( + void *dm_void, + boolean is_recovery +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + struct dm_rf_calibration_struct *cali_info = &(dm->rf_calibrate_info); + + s32 result[4][8]; /* last is final result */ + u8 i, final_candidate, indexforchannel; + boolean is_patha_ok, is_pathb_ok; + s32 rege94, rege9c, regea4, regeac, regeb4, regebc, regec4, regecc, reg_tmp = 0; + boolean is12simular, is13simular, is23simular; + u32 IQK_BB_REG_92C[IQK_BB_REG_NUM] = { + REG_OFDM_0_XA_RX_IQ_IMBALANCE, REG_OFDM_0_XB_RX_IQ_IMBALANCE, + REG_OFDM_0_ECCA_THRESHOLD, REG_OFDM_0_AGC_RSSI_TABLE, + REG_OFDM_0_XA_TX_IQ_IMBALANCE, REG_OFDM_0_XB_TX_IQ_IMBALANCE, + REG_OFDM_0_XC_TX_AFE, REG_OFDM_0_XD_TX_AFE, + REG_OFDM_0_RX_IQ_EXT_ANTA + }; + +#if (DM_ODM_SUPPORT_TYPE & (ODM_CE | ODM_AP)) + if (is_recovery) +#else/* for ODM_WIN */ + if (is_recovery && (!dm->is_in_hct_test)) /* YJ,add for PowerTest,120405 */ +#endif + { + RF_DBG(dm, DBG_RF_INIT, "phy_iq_calibrate_8188e: Return due to is_recovery!\n"); + _phy_reload_adda_registers(dm, IQK_BB_REG_92C, cali_info->IQK_BB_backup_recover, 9); + return; + } + RF_DBG(dm, DBG_RF_IQK, "IQK:Start!!!\n"); + + for (i = 0; i < 8; i++) { + result[0][i] = 0; + result[1][i] = 0; + result[2][i] = 0; + result[3][i] = 0; + } + final_candidate = 0xff; + is_patha_ok = false; + is_pathb_ok = false; + is12simular = false; + is23simular = false; + is13simular = false; + + + for (i = 0; i < 3; i++) { + _phy_iq_calibrate_8188e(dm, result, i, false); + + if (i == 1) { + is12simular = phy_simularity_compare_8188e(dm, result, 0, 1); + if (is12simular) { + final_candidate = 0; + RF_DBG(dm, DBG_RF_IQK, "IQK: is12simular final_candidate is %x\n", final_candidate); + break; + } + } + + if (i == 2) { + is13simular = phy_simularity_compare_8188e(dm, result, 0, 2); + if (is13simular) { + final_candidate = 0; + RF_DBG(dm, DBG_RF_IQK, "IQK: is13simular final_candidate is %x\n", final_candidate); + + break; + } + is23simular = phy_simularity_compare_8188e(dm, result, 1, 2); + if (is23simular) { + final_candidate = 1; + RF_DBG(dm, DBG_RF_IQK, "IQK: is23simular final_candidate is %x\n", final_candidate); + } else { + for (i = 0; i < 8; i++) + reg_tmp += result[3][i]; + + if (reg_tmp != 0) + final_candidate = 3; + else + final_candidate = 0xFF; + } + } + } + /* RT_TRACE(COMP_INIT,DBG_LOUD,("Release Mutex in IQCalibrate\n")); */ + + for (i = 0; i < 4; i++) { + rege94 = result[i][0]; + rege9c = result[i][1]; + regea4 = result[i][2]; + regeac = result[i][3]; + regeb4 = result[i][4]; + regebc = result[i][5]; + regec4 = result[i][6]; + regecc = result[i][7]; + RF_DBG(dm, DBG_RF_IQK, "IQK: rege94=%x rege9c=%x regea4=%x regeac=%x regeb4=%x regebc=%x regec4=%x regecc=%x\n ", rege94, rege9c, regea4, regeac, regeb4, regebc, regec4, regecc); + } + + if (final_candidate != 0xff) { + cali_info->rege94 = rege94 = result[final_candidate][0]; + cali_info->rege9c = rege9c = result[final_candidate][1]; + regea4 = result[final_candidate][2]; + regeac = result[final_candidate][3]; + cali_info->regeb4 = regeb4 = result[final_candidate][4]; + cali_info->regebc = regebc = result[final_candidate][5]; + regec4 = result[final_candidate][6]; + regecc = result[final_candidate][7]; + RF_DBG(dm, DBG_RF_IQK, "IQK: final_candidate is %x\n", final_candidate); + RF_DBG(dm, DBG_RF_IQK, "IQK: rege94=%x rege9c=%x regea4=%x regeac=%x regeb4=%x regebc=%x regec4=%x regecc=%x\n ", rege94, rege9c, regea4, regeac, regeb4, regebc, regec4, regecc); + is_patha_ok = is_pathb_ok = true; + } else { + RF_DBG(dm, DBG_RF_IQK, "IQK: FAIL use default value\n"); + + cali_info->rege94 = cali_info->regeb4 = 0x100; /* X default value */ + cali_info->rege9c = cali_info->regebc = 0x0; /* Y default value */ + } + + if ((rege94 != 0)/*&&(regea4 != 0)*/) + _phy_path_a_fill_iqk_matrix(dm, is_patha_ok, result, final_candidate, (regea4 == 0)); + + + indexforchannel = odm_get_right_chnl_place_for_iqk(*dm->channel); + + /* To Fix BSOD when final_candidate is 0xff + * by sherry 20120321 */ + if (final_candidate < 4) { + for (i = 0; i < iqk_matrix_reg_num; i++) + cali_info->iqk_matrix_reg_setting[indexforchannel].value[0][i] = result[final_candidate][i]; + cali_info->iqk_matrix_reg_setting[indexforchannel].is_iqk_done = true; + } + /* RT_DISP(FINIT, INIT_IQK, ("\nIQK OK indexforchannel %d.\n", indexforchannel)); */ + RF_DBG(dm, DBG_RF_IQK, "\nIQK OK indexforchannel %d.\n", indexforchannel); + _phy_save_adda_registers(dm, IQK_BB_REG_92C, cali_info->IQK_BB_backup_recover, IQK_BB_REG_NUM); + RF_DBG(dm, DBG_RF_IQK, "IQK finished\n"); +} + + +void +phy_lc_calibrate_8188e( + void *dm_void +) +{ + struct dm_struct *dm = (struct dm_struct *)dm_void; + + _phy_lc_calibrate_8188e(dm, false); +} + + + +void _phy_set_rf_path_switch_8188e( +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + struct dm_struct *dm, +#else + void *adapter, +#endif + boolean is_main, + boolean is2T +) +{ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) + struct dm_struct *dm = &hal_data->odmpriv; +#elif (DM_ODM_SUPPORT_TYPE == ODM_WIN) + struct dm_struct *dm = &hal_data->DM_OutSrc; +#endif + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + if (!(((PADAPTER)(adapter))->bHWInitReady)) +#elif (DM_ODM_SUPPORT_TYPE == ODM_CE) + if (adapter->hw_init_completed == false) +#endif + { + u8 u1b_tmp; + u1b_tmp = odm_read_1byte(dm, REG_LEDCFG2) | BIT(7); + odm_write_1byte(dm, REG_LEDCFG2, u1b_tmp); + /* odm_set_bb_reg(dm, REG_LEDCFG0, BIT23, 0x01); */ + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_PARAMETER, BIT(13), 0x01); + } + +#endif + + if (is2T) { /* 92C */ + if (is_main) + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(6), 0x1); /* 92C_Path_A */ + else + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(6), 0x2); /* BT */ + } else { /* 88C */ + + /* <20120504, Kordan> [8188E] We should make AntDiversity controlled by HW (0x870[9:8] = 0), */ + /* otherwise the following action has no effect. (0x860[9:8] has the effect only if AntDiversity controlled by SW) */ + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_INTERFACE_SW, BIT(8) | BIT(9), 0x0); + odm_set_bb_reg(dm, R_0x914, MASKLWORD, 0x0201); /* Set up the ant mapping table */ + + if (is_main) { + /* odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(8)|BIT9, 0x2); */ /* Tx Main (SW control)(The right antenna) */ + /* 4 [ Tx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(14) | BIT(13) | BIT(12), 0x1); /* Tx Main (HW control)(The right antenna) */ + + /* 4 [ Rx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(4) | BIT(3), 0x1); /* ant_div_type = TRDiv, right antenna */ + if (dm->ant_div_type == CGCS_RX_HW_ANTDIV) + odm_set_bb_reg(dm, R_0xb2c, BIT(31), 0x1); /* RxCG, Default is RxCG. ant_div_type = 2RDiv, left antenna */ + + } else { + /* odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(8)|BIT9, 0x1); */ /* Tx Aux (SW control)(The left antenna) */ + /* 4 [ Tx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XA_RF_INTERFACE_OE, BIT(14) | BIT(13) | BIT(12), 0x0); /* Tx Aux (HW control)(The left antenna) */ + + /* 4 [ Rx ] */ + odm_set_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(4) | BIT(3), 0x0); /* ant_div_type = TRDiv, left antenna */ + if (dm->ant_div_type == CGCS_RX_HW_ANTDIV) + odm_set_bb_reg(dm, R_0xb2c, BIT(31), 0x0); /* RxCS, ant_div_type = 2RDiv, right antenna */ + } + + } +} +void phy_set_rf_path_switch_8188e( +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + struct dm_struct *dm, +#else + void *adapter, +#endif + boolean is_main +) +{ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); +#endif + +#if DISABLE_BB_RF + return; +#endif + +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + if (IS_92C_SERIAL(hal_data->VersionID)) + _phy_set_rf_path_switch_8188e(adapter, is_main, true); + else +#endif + { + /* For 88C 1T1R */ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + _phy_set_rf_path_switch_8188e(adapter, is_main, false); +#else + _phy_set_rf_path_switch_8188e(dm, is_main, false); +#endif + } +} + +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) +/* return value true => Main; false => Aux */ +boolean _phy_query_rf_path_switch_8188e( +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + struct dm_struct *dm, +#else + void *adapter, +#endif + boolean is2T +) +{ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); +#if (DM_ODM_SUPPORT_TYPE == ODM_CE) + struct dm_struct *dm = &hal_data->odmpriv; +#endif +#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) + struct dm_struct *dm = &hal_data->DM_OutSrc; +#endif +#endif + if (!(((PADAPTER)(adapter))->bHWInitReady)){ + u8 u1b_tmp; + u1b_tmp = odm_read_1byte(dm, REG_LEDCFG2) | BIT(7); + odm_write_1byte(dm, REG_LEDCFG2, u1b_tmp); + /* odm_set_bb_reg(dm, REG_LEDCFG0, BIT23, 0x01); */ + odm_set_bb_reg(dm, REG_FPGA0_XAB_RF_PARAMETER, BIT(13), 0x01); + } + + if (is2T) { + if (odm_get_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(6)) == 0x01) + return true; + else + return false; + } else { + if ((odm_get_bb_reg(dm, REG_FPGA0_XB_RF_INTERFACE_OE, BIT(5) | BIT(4) | BIT(3)) == 0x1)) + return true; + else + return false; + } +} + + + +/* return value true => Main; false => Aux */ +boolean phy_query_rf_path_switch_8188e( +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + struct dm_struct *dm +#else + void *adapter +#endif +) +{ + HAL_DATA_TYPE *hal_data = GET_HAL_DATA(((PADAPTER)adapter)); + +#if DISABLE_BB_RF + return true; +#endif +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + + /* if(IS_92C_SERIAL( hal_data->version_id)) { */ + if (IS_2T2R(hal_data->VersionID)) + return _phy_query_rf_path_switch_8188e(adapter, true); + else +#endif + { + /* For 88C 1T1R */ +#if !(DM_ODM_SUPPORT_TYPE & ODM_AP) + return _phy_query_rf_path_switch_8188e(adapter, false); +#else + return _phy_query_rf_path_switch_8188e(dm, false); +#endif + } +} +#endif +#endif diff --git a/hal/phydm/halrf/rtl8188e/halrf_8188e_win.h b/hal/phydm/halrf/rtl8188e/halrf_8188e_win.h new file mode 100644 index 0000000..6fbc5fb --- /dev/null +++ b/hal/phydm/halrf/rtl8188e/halrf_8188e_win.h @@ -0,0 +1,136 @@ +/****************************************************************************** + * + * Copyright(c) 2007 - 2017 Realtek Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + *****************************************************************************/ + +#ifndef __HALRF_8188E_H__ +#define __HALRF_8188E_H__ + +/*--------------------------Define Parameters-------------------------------*/ +#define IQK_DELAY_TIME_88E 15 /* ms */ +#define IQK_DELAY_TIME_8723B 10 /* ms */ + +#define index_mapping_NUM_88E 15 +#define AVG_THERMAL_NUM_88E 4 + +#include "halrf/halphyrf_win.h" + +void configure_txpower_track_8188e( + struct txpwrtrack_cfg *config +); + +void +get_delta_swing_table_8188e( + void *dm_void, + u8 **temperature_up_a, + u8 **temperature_down_a, + u8 **temperature_up_b, + u8 **temperature_down_b +); + +void do_iqk_8188e( + void *dm_void, + u8 delta_thermal_index, + u8 thermal_value, + u8 threshold +); + +void +odm_tx_pwr_track_set_pwr88_e( + void *dm_void, + enum pwrtrack_method method, + u8 rf_path, + u8 channel_mapped_index +); + +/* 1 7. IQK */ + +void +phy_iq_calibrate_8188e( + void *dm_void, + boolean is_recovery); + + +/* + * LC calibrate + * */ +void +phy_lc_calibrate_8188e( + void *dm_void +); + +/* + * AP calibrate + * */ +#if 0 +void +phy_ap_calibrate_8188e( +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + struct dm_struct *dm, +#else + void *adapter, +#endif + s8 delta); +void +phy_digital_predistortion_8188e(void *adapter); + +#endif + +#define phy_dp_calibrate_8821a phy_dp_calibrate_8812a + +void +_phy_save_adda_registers( + struct dm_struct *dm, + u32 *adda_reg, + u32 *adda_backup, + u32 register_num +); + +void +_phy_path_adda_on( + struct dm_struct *dm, + u32 *adda_reg, + boolean is_path_a_on, + boolean is2T +); + +void +_phy_mac_setting_calibration( + struct dm_struct *dm, + u32 *mac_reg, + u32 *mac_backup +); + + +void +_phy_path_a_stand_by( + struct dm_struct *dm +); + + +void phy_set_rf_path_switch_8188e( +#if (DM_ODM_SUPPORT_TYPE & ODM_AP) + struct dm_struct *dm, +#else + void *adapter, +#endif + boolean is_main +); + +void +halrf_rf_lna_setting_8188e( + struct dm_struct *dm, + enum halrf_lna_set type +); + +#endif /*#ifndef __HALRF_8188E_H__*/