wifi: rtw89: 8922a: add chip_ops to get thermal value
authorPing-Ke Shih <pkshih@realtek.com>
Wed, 24 Jan 2024 03:38:02 +0000 (11:38 +0800)
committerKalle Valo <kvalo@kernel.org>
Thu, 1 Feb 2024 10:19:51 +0000 (12:19 +0200)
Get thermal value as a clue to do RF calibration if the delta is larger
than a threshold, but 8922A doesn't need this, so we only read out the
value when debugging to reduce IO.

Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://msgid.link/20240124033802.12508-1-pkshih@realtek.com
drivers/net/wireless/realtek/rtw89/reg.h
drivers/net/wireless/realtek/rtw89/rtw8922a.c

index 95c06b98192c3c5c84e848ffc230d0b3cd875038..addf11fc76d43de3c6bd91e49760019e3128ab44 100644 (file)
 #define RR_LUTWD0_LB GENMASK(5, 0)
 #define RR_TM 0x42
 #define RR_TM_TRI BIT(19)
+#define RR_TM_VAL_V1 GENMASK(7, 0)
 #define RR_TM_VAL GENMASK(6, 1)
 #define RR_TM2 0x43
 #define RR_TM2_OFF GENMASK(19, 16)
index 1c5ceb5564c387a9133a1d9ccbff320ba79bdae0..6de3c0f8d83a85d948db4d20d950dd3e3c386e4e 100644 (file)
@@ -1528,6 +1528,27 @@ static void rtw8922a_bb_cfg_txrx_path(struct rtw89_dev *rtwdev)
                                   &tx_en0, false);
 }
 
+static u8 rtw8922a_get_thermal(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path)
+{
+       struct rtw89_power_trim_info *info = &rtwdev->pwr_trim;
+       int th;
+
+       /* read thermal only if debugging */
+       if (!rtw89_debug_is_enabled(rtwdev, RTW89_DBG_CFO | RTW89_DBG_RFK_TRACK))
+               return 80;
+
+       rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x1);
+       rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x0);
+       rtw89_write_rf(rtwdev, rf_path, RR_TM, RR_TM_TRI, 0x1);
+
+       fsleep(200);
+
+       th = rtw89_read_rf(rtwdev, rf_path, RR_TM, RR_TM_VAL_V1);
+       th += (s8)info->thermal_trim[rf_path];
+
+       return clamp_t(int, th, 0, U8_MAX);
+}
+
 static void rtw8922a_fill_freq_with_ppdu(struct rtw89_dev *rtwdev,
                                         struct rtw89_rx_phy_ppdu *phy_ppdu,
                                         struct ieee80211_rx_status *status)
@@ -1603,6 +1624,7 @@ static const struct rtw89_chip_ops rtw8922a_chip_ops = {
        .set_txpwr              = rtw8922a_set_txpwr,
        .set_txpwr_ctrl         = rtw8922a_set_txpwr_ctrl,
        .init_txpwr_unit        = NULL,
+       .get_thermal            = rtw8922a_get_thermal,
        .ctrl_btg_bt_rx         = rtw8922a_ctrl_btg_bt_rx,
        .query_ppdu             = rtw8922a_query_ppdu,
        .ctrl_nbtg_bt_tx        = rtw8922a_ctrl_nbtg_bt_tx,