developer | 9851a29 | 2022-12-15 17:33:43 +0800 | [diff] [blame] | 1 | From f36f3aca9bafe359947f030b787aeabec8f75644 Mon Sep 17 00:00:00 2001 |
developer | 51f6fcf | 2022-12-14 17:08:01 +0800 | [diff] [blame] | 2 | From: Howard Hsu <howard-yh.hsu@mediatek.com> |
| 3 | Date: Mon, 5 Dec 2022 14:09:18 +0800 |
developer | 9851a29 | 2022-12-15 17:33:43 +0800 | [diff] [blame] | 4 | Subject: [PATCH 2/5] wifi: mt76: mt7915: rework |
developer | 51f6fcf | 2022-12-14 17:08:01 +0800 | [diff] [blame] | 5 | mt7915_mcu_set_thermal_throttling |
| 6 | |
| 7 | This patch includes 2 changes: |
| 8 | 1. Firmware expects to disable thermal protect first before |
| 9 | reconfiguring. |
| 10 | 2. Separate setting thermal_protect and setting thermal_tx_duty into |
| 11 | different functions. These two firmware commands do not need to send |
| 12 | together. |
| 13 | |
| 14 | Fixes: 34b877d972be ("mt76: mt7915: add thermal cooling device support") |
| 15 | Reviewed-by: Ryder Lee <ryder.lee@mediatek.com> |
| 16 | Signed-off-by: Howard Hsu <howard-yh.hsu@mediatek.com> |
| 17 | --- |
| 18 | mt7915/init.c | 3 --- |
| 19 | mt7915/main.c | 5 +++++ |
| 20 | mt7915/mcu.c | 54 ++++++++++++++++++++++++++++--------------------- |
| 21 | mt7915/mt7915.h | 1 + |
| 22 | 4 files changed, 37 insertions(+), 26 deletions(-) |
| 23 | |
| 24 | diff --git a/mt7915/init.c b/mt7915/init.c |
| 25 | index a03d0b3b..df3a35d5 100644 |
| 26 | --- a/mt7915/init.c |
| 27 | +++ b/mt7915/init.c |
| 28 | @@ -134,9 +134,6 @@ mt7915_thermal_set_cur_throttle_state(struct thermal_cooling_device *cdev, |
| 29 | if (state > MT7915_CDEV_THROTTLE_MAX) |
| 30 | return -EINVAL; |
| 31 | |
| 32 | - if (phy->throttle_temp[0] > phy->throttle_temp[1]) |
| 33 | - return 0; |
| 34 | - |
| 35 | if (state == phy->cdev_state) |
| 36 | return 0; |
| 37 | |
| 38 | diff --git a/mt7915/main.c b/mt7915/main.c |
| 39 | index 98af032e..7589af4b 100644 |
| 40 | --- a/mt7915/main.c |
| 41 | +++ b/mt7915/main.c |
| 42 | @@ -60,6 +60,11 @@ int mt7915_run(struct ieee80211_hw *hw) |
| 43 | ret = mt7915_mcu_set_thermal_throttling(phy, |
| 44 | MT7915_THERMAL_THROTTLE_MAX); |
| 45 | |
| 46 | + if (ret) |
| 47 | + goto out; |
| 48 | + |
| 49 | + ret = mt7915_mcu_set_thermal_protect(phy); |
| 50 | + |
| 51 | if (ret) |
| 52 | goto out; |
| 53 | |
| 54 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
| 55 | index 35441dcb..7c14a189 100644 |
| 56 | --- a/mt7915/mcu.c |
| 57 | +++ b/mt7915/mcu.c |
| 58 | @@ -3077,6 +3077,29 @@ int mt7915_mcu_get_temperature(struct mt7915_phy *phy) |
| 59 | } |
| 60 | |
| 61 | int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state) |
| 62 | +{ |
| 63 | + struct mt7915_dev *dev = phy->dev; |
| 64 | + struct mt7915_mcu_thermal_ctrl req = { |
| 65 | + .band_idx = phy->mt76->band_idx, |
| 66 | + .ctrl_id = THERMAL_PROTECT_DUTY_CONFIG, |
| 67 | + }; |
| 68 | + int level, ret; |
| 69 | + |
| 70 | + /* set duty cycle and level */ |
| 71 | + for (level = 0; level < 4; level++) { |
| 72 | + req.duty.duty_level = level; |
| 73 | + req.duty.duty_cycle = state; |
| 74 | + state /= 2; |
| 75 | + |
| 76 | + ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT), |
| 77 | + &req, sizeof(req), false); |
| 78 | + if (ret) |
| 79 | + return ret; |
| 80 | + } |
| 81 | + return 0; |
| 82 | +} |
| 83 | + |
| 84 | +int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy) |
| 85 | { |
| 86 | struct mt7915_dev *dev = phy->dev; |
| 87 | struct { |
| 88 | @@ -3089,29 +3112,18 @@ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state) |
| 89 | } __packed req = { |
| 90 | .ctrl = { |
| 91 | .band_idx = phy->mt76->band_idx, |
| 92 | + .type.protect_type = 1, |
| 93 | + .type.trigger_type = 1, |
| 94 | }, |
| 95 | }; |
| 96 | - int level; |
| 97 | - |
| 98 | - if (!state) { |
| 99 | - req.ctrl.ctrl_id = THERMAL_PROTECT_DISABLE; |
| 100 | - goto out; |
| 101 | - } |
| 102 | - |
| 103 | - /* set duty cycle and level */ |
| 104 | - for (level = 0; level < 4; level++) { |
| 105 | - int ret; |
| 106 | + int ret; |
| 107 | |
| 108 | - req.ctrl.ctrl_id = THERMAL_PROTECT_DUTY_CONFIG; |
| 109 | - req.ctrl.duty.duty_level = level; |
| 110 | - req.ctrl.duty.duty_cycle = state; |
| 111 | - state /= 2; |
| 112 | + req.ctrl.ctrl_id = THERMAL_PROTECT_DISABLE; |
| 113 | + ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT), |
| 114 | + &req, sizeof(req.ctrl), false); |
| 115 | |
| 116 | - ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT), |
| 117 | - &req, sizeof(req.ctrl), false); |
| 118 | - if (ret) |
| 119 | - return ret; |
| 120 | - } |
| 121 | + if (ret) |
| 122 | + return ret; |
| 123 | |
| 124 | /* set high-temperature trigger threshold */ |
| 125 | req.ctrl.ctrl_id = THERMAL_PROTECT_ENABLE; |
| 126 | @@ -3120,10 +3132,6 @@ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state) |
| 127 | req.trigger_temp = cpu_to_le32(phy->throttle_temp[1]); |
| 128 | req.sustain_time = cpu_to_le16(10); |
| 129 | |
| 130 | -out: |
| 131 | - req.ctrl.type.protect_type = 1; |
| 132 | - req.ctrl.type.trigger_type = 1; |
| 133 | - |
| 134 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT), |
| 135 | &req, sizeof(req), false); |
| 136 | } |
| 137 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| 138 | index 6351feba..855779f8 100644 |
| 139 | --- a/mt7915/mt7915.h |
| 140 | +++ b/mt7915/mt7915.h |
| 141 | @@ -543,6 +543,7 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy); |
| 142 | int mt7915_mcu_get_chan_mib_info(struct mt7915_phy *phy, bool chan_switch); |
| 143 | int mt7915_mcu_get_temperature(struct mt7915_phy *phy); |
| 144 | int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state); |
| 145 | +int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy); |
| 146 | int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
| 147 | struct ieee80211_sta *sta, struct rate_info *rate); |
| 148 | int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy, |
| 149 | -- |
| 150 | 2.18.0 |
| 151 | |