[PATCH] wifi: mt76: mt7996: add thermal zone device registration
Ryan Leung <[email protected]>
| Newsgroups | org.infradead.lists.linux-mediatek,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-wireless |
|---|---|
| Message-ID | <[email protected]> |
Register the mt7996 phy as a thermal zone sensor using devm_thermal_of_zone_register() so that device tree thermal-zones nodes can reference the Wi-Fi chip as a temperature source. This allows the kernel thermal governor to control external cooling devices such as PWM fans based on Wi-Fi chip temperature. Registration is non-fatal: -ENODEV is returned when no thermal-sensors DT property references this device, which is the expected case on platforms without a thermal zone configured. Signed-off-by: Ryan Leung <[email protected]> --- This is essentially the same as the previous patch for mt7915 [1] but calls mt7996_mcu_get_temperature without mutex, consistent with the existing hwmon mt7996_thermal_temp_show callback. I don't know if mt7996 also needs mutex locks such as those in commit e733647566ec ("wifi: mt76: mt7915: hold dev->mutex while interacting with the thermal state") [2] [1] https://patch.msgid.link/20260719-mt7915-thermal-zone-device-registration-v2-1-0eac68c2741e@protonmail.com [2] https://patch.msgid.link/[email protected] --- drivers/net/wireless/mediatek/mt76/mt7996/init.c | 28 ++++++++++++++++++++++ drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h | 1 + 2 files changed, 29 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c index d6f9aa1ab52d..115145f993d0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c @@ -236,6 +236,23 @@ static const struct thermal_cooling_device_ops mt7996_thermal_ops = { .set_cur_state = mt7996_thermal_set_cur_throttle_state, }; +static int mt7996_thermal_get_temp(struct thermal_zone_device *tz, int *temp) +{ + struct mt7996_phy *phy = thermal_zone_device_priv(tz); + int val; + + val = mt7996_mcu_get_temperature(phy); + if (val < 0) + return val; + + *temp = val * 1000; + return 0; +} + +static const struct thermal_zone_device_ops mt7996_tz_ops = { + .get_temp = mt7996_thermal_get_temp, +}; + static void mt7996_unregister_thermal(struct mt7996_phy *phy) { struct wiphy *wiphy = phy->mt76->hw->wiphy; @@ -277,6 +294,17 @@ static int mt7996_thermal_init(struct mt7996_phy *phy) phy->throttle_temp[MT7996_CRIT_TEMP_IDX] = MT7996_CRIT_TEMP; phy->throttle_temp[MT7996_MAX_TEMP_IDX] = MT7996_MAX_TEMP; + phy->tzone = devm_thermal_of_zone_register(phy->dev->mt76.dev, + phy->mt76->band_idx, phy, + &mt7996_tz_ops); + if (IS_ERR(phy->tzone)) { + if (PTR_ERR(phy->tzone) != -ENODEV) + dev_warn(phy->dev->mt76.dev, + "failed to register thermal zone%d: %ld\n", + phy->mt76->band_idx, PTR_ERR(phy->tzone)); + phy->tzone = NULL; + } + if (!IS_REACHABLE(CONFIG_HWMON)) return 0; diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h index 0d6488522ba7..1207b5c7e98b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h @@ -372,6 +372,7 @@ struct mt7996_phy { struct ieee80211_sband_iftype_data iftype[NUM_NL80211_BANDS][NUM_NL80211_IFTYPES]; + struct thermal_zone_device *tzone; struct thermal_cooling_device *cdev; u8 cdev_state; u8 throttle_state; --- base-commit: 69bd85e933c617a84fa54fcc80e628e98afdc45d change-id: 20260722-mt7996-thermal-zone-a1de7cb1d728 Best regards, -- Ryan Leung <[email protected]>