[][mac80211][mt76][move temperature margin check to mt7915_thermal_temp_store()]

[Description]
Change the place to do the temperature margin check.

Originally, we would reduce the 10-degree margin to the restore
temperature, but the user would not be aware of this when setting it.
Moving the margin reduction to the user setting check allows the user to
clearly understand that there is a 10-degree difference between the
restore and trigger temperature.

[Release-log]
N/A

Change-Id: I81d14eb441229d32afb497177d750a1995a56b3a
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7744133
diff --git a/autobuild_mac80211_release/package/kernel/mt76/patches/0008-wifi-mt76-mt7915-move-temperature-margin-check-to-mt.patch b/autobuild_mac80211_release/package/kernel/mt76/patches/0008-wifi-mt76-mt7915-move-temperature-margin-check-to-mt.patch
new file mode 100644
index 0000000..112b099
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mt76/patches/0008-wifi-mt76-mt7915-move-temperature-margin-check-to-mt.patch
@@ -0,0 +1,56 @@
+From 7fdf5d384f377d0b7b1bb1aa441cebb98d3c61fa Mon Sep 17 00:00:00 2001
+From: Howard Hsu <howard-yh.hsu@mediatek.com>
+Date: Thu, 13 Jul 2023 15:50:00 +0800
+Subject: [PATCH] wifi: mt76: mt7915: move temperature margin check to
+ mt7915_thermal_temp_store()
+
+Originally, we would reduce the 10-degree margin to the restore
+temperature, but the user would not be aware of this when setting it.
+Moving the margin reduction to the user setting check allows the user to
+clearly understand that there is a 10-degree difference between the
+restore and trigger temperature.
+
+Signed-off-by: Howard Hsu <howard-yh.hsu@mediatek.com>
+---
+ mt7915/init.c | 7 ++++---
+ mt7915/mcu.c  | 3 +--
+ 2 files changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/mt7915/init.c b/mt7915/init.c
+index 75f8d96d..3e9b082c 100644
+--- a/mt7915/init.c
++++ b/mt7915/init.c
+@@ -83,12 +83,13 @@ 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);
+ 
++	/* add a safety margin ~10 */
+ 	if ((i - 1 == MT7915_CRIT_TEMP_IDX &&
+-	     val > phy->throttle_temp[MT7915_MAX_TEMP_IDX]) ||
++	     val > phy->throttle_temp[MT7915_MAX_TEMP_IDX] - 10) ||
+ 	    (i - 1 == MT7915_MAX_TEMP_IDX &&
+-	     val < phy->throttle_temp[MT7915_CRIT_TEMP_IDX])) {
++	     val - 10 < phy->throttle_temp[MT7915_CRIT_TEMP_IDX])) {
+ 		dev_err(phy->dev->mt76.dev,
+-			"temp1_max shall be greater than temp1_crit.");
++			"temp1_max shall be 10 degrees greater than temp1_crit.");
+ 		mutex_unlock(&phy->dev->mt76.mutex);
+ 		return -EINVAL;
+ 	}
+diff --git a/mt7915/mcu.c b/mt7915/mcu.c
+index 146c3d64..820eb555 100644
+--- a/mt7915/mcu.c
++++ b/mt7915/mcu.c
+@@ -3148,8 +3148,7 @@ int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy)
+ 
+ 	/* set high-temperature trigger threshold */
+ 	req.ctrl.ctrl_id = THERMAL_PROTECT_ENABLE;
+-	/* add a safety margin ~10 */
+-	req.restore_temp = cpu_to_le32(phy->throttle_temp[0] - 10);
++	req.restore_temp = cpu_to_le32(phy->throttle_temp[0]);
+ 	req.trigger_temp = cpu_to_le32(phy->throttle_temp[1]);
+ 	req.sustain_time = cpu_to_le16(10);
+ 
+-- 
+2.18.0
+