blob: 5878df642d618299774adce83fb732bfbe510972 [file] [log] [blame]
developerf043db82022-12-21 14:59:23 +08001From 40d952371aa09e9c979a0fa198825bee104acbe0 Mon Sep 17 00:00:00 2001
developer51f6fcf2022-12-14 17:08:01 +08002From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Mon, 5 Dec 2022 14:09:18 +0800
developer30d39c22022-12-16 10:29:49 +08004Subject: [PATCH 2/6] wifi: mt76: mt7915: rework
developer51f6fcf2022-12-14 17:08:01 +08005 mt7915_mcu_set_thermal_throttling
6
7This patch includes 2 changes:
81. Firmware expects to disable thermal protect first before
9reconfiguring.
102. Separate setting thermal_protect and setting thermal_tx_duty into
11different functions. These two firmware commands do not need to send
12together.
13
14Fixes: 34b877d972be ("mt76: mt7915: add thermal cooling device support")
15Reviewed-by: Ryder Lee <ryder.lee@mediatek.com>
16Signed-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
24diff --git a/mt7915/init.c b/mt7915/init.c
developer699cda22022-12-17 15:21:57 +080025index a03d0b3..df3a35d 100644
developer51f6fcf2022-12-14 17:08:01 +080026--- 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
38diff --git a/mt7915/main.c b/mt7915/main.c
developer699cda22022-12-17 15:21:57 +080039index 98af032..7589af4 100644
developer51f6fcf2022-12-14 17:08:01 +080040--- 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
54diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developer699cda22022-12-17 15:21:57 +080055index 35441dc..7c14a18 100644
developer51f6fcf2022-12-14 17:08:01 +080056--- 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 }
137diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer699cda22022-12-17 15:21:57 +0800138index 6351feb..855779f 100644
developer51f6fcf2022-12-14 17:08:01 +0800139--- 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--
developer699cda22022-12-17 15:21:57 +08001502.36.1
developer51f6fcf2022-12-14 17:08:01 +0800151