[][MAC80211][MT76][Rework Thermal Protection]

[Description]
Fix thermal protection bugs.

[Release-log]
N/A

Change-Id: I3ec0295572893c14c662a172349110e4129d1ce3
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/6923892
diff --git a/autobuild_mac80211_release/package/kernel/mt76/patches/0003-wifi-mt76-mt7915-rework-mt7915_thermal_temp_store.patch b/autobuild_mac80211_release/package/kernel/mt76/patches/0003-wifi-mt76-mt7915-rework-mt7915_thermal_temp_store.patch
new file mode 100644
index 0000000..f1c0093
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mt76/patches/0003-wifi-mt76-mt7915-rework-mt7915_thermal_temp_store.patch
@@ -0,0 +1,73 @@
+From 2cd5969305cc6ba22a1a3ffc45f46758d09bbd1e Mon Sep 17 00:00:00 2001
+From: Howard Hsu <howard-yh.hsu@mediatek.com>
+Date: Mon, 12 Dec 2022 11:30:37 +0800
+Subject: [PATCH 3/4] wifi: mt76: mt7915: rework mt7915_thermal_temp_store()
+
+Call mt7915_mcu_set_thermal_protect() through
+mt7915_thermal_temp_store() to update firmware trigger/restore temp
+directly.
+
+Fixes: 02ee68b95d81 ("mt76: mt7915: add control knobs for thermal throttling")
+Reviewed-by: Ryder Lee <ryder.lee@mediatek.com>
+Signed-off-by: Howard Hsu <howard-yh.hsu@mediatek.com>
+---
+ mt7915/init.c   | 18 ++++++++++++++++--
+ mt7915/mt7915.h |  3 +++
+ 2 files changed, 19 insertions(+), 2 deletions(-)
+
+diff --git a/mt7915/init.c b/mt7915/init.c
+index df3a35d5..98655e4d 100644
+--- a/mt7915/init.c
++++ b/mt7915/init.c
+@@ -83,9 +83,23 @@ static ssize_t mt7915_thermal_temp_store(struct device *dev,
+ 
+ 	mutex_lock(&phy->dev->mt76.mutex);
+ 	val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 60, 130);
++
++	if ((i - 1 == MT7915_CRIT_TEMP_IDX &&
++	     val > phy->throttle_temp[MT7915_MAX_TEMP_IDX]) ||
++	    (i - 1 == MT7915_MAX_TEMP_IDX &&
++	     val < phy->throttle_temp[MT7915_CRIT_TEMP_IDX])) {
++		dev_err(phy->dev->mt76.dev,
++			"temp1_max shall be greater than temp1_crit.");
++		return -EINVAL;
++	}
++
+ 	phy->throttle_temp[i - 1] = val;
+ 	mutex_unlock(&phy->dev->mt76.mutex);
+ 
++	ret = mt7915_mcu_set_thermal_protect(phy);
++	if (ret)
++		return ret;
++
+ 	return count;
+ }
+ 
+@@ -195,8 +209,8 @@ static int mt7915_thermal_init(struct mt7915_phy *phy)
+ 		return PTR_ERR(hwmon);
+ 
+ 	/* initialize critical/maximum high temperature */
+-	phy->throttle_temp[0] = 110;
+-	phy->throttle_temp[1] = 120;
++	phy->throttle_temp[MT7915_CRIT_TEMP_IDX] = 110;
++	phy->throttle_temp[MT7915_MAX_TEMP_IDX] = 120;
+ 
+ 	return 0;
+ }
+diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
+index 855779f8..e58650bb 100644
+--- a/mt7915/mt7915.h
++++ b/mt7915/mt7915.h
+@@ -70,6 +70,9 @@
+ 
+ #define MT7915_WED_RX_TOKEN_SIZE	12288
+ 
++#define MT7915_CRIT_TEMP_IDX		0
++#define MT7915_MAX_TEMP_IDX		1
++
+ struct mt7915_vif;
+ struct mt7915_sta;
+ struct mt7915_dfs_pulse;
+-- 
+2.18.0
+