developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 1 | From 49d072013ef5a88ca6040d18085885773967d5d4 Mon Sep 17 00:00:00 2001 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 2 | From: Howard Hsu <howard-yh.hsu@mediatek.com> |
| 3 | Date: Thu, 27 Jul 2023 19:35:32 +0800 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 4 | Subject: [PATCH 083/199] mtk: mt76: mt7996: support enable/disable thermal |
| 5 | protection mechanism |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 6 | |
| 7 | This commit adds a new debugfs thermal_enable to enable/disable thermal |
| 8 | protection mechanism. The purpose of this commit is for autotest to |
| 9 | verify thermal protection mechanism. |
| 10 | |
| 11 | [Usage] |
| 12 | Enable thermal protection: echo 1 > thermal_enable |
| 13 | Disable thermal protection: echo 0 > thermal_enable |
| 14 | |
| 15 | Please note that if you re-enable thermal protection mechanism, all the |
| 16 | configuration values will be retained from the exising configuration, |
| 17 | rather than using the default values. |
| 18 | |
| 19 | Signed-off-by: Howard Hsu <howard-yh.hsu@mediatek.com> |
| 20 | --- |
| 21 | mt7996/main.c | 1 + |
| 22 | mt7996/mt7996.h | 1 + |
| 23 | mt7996/mtk_debugfs.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ |
| 24 | 3 files changed, 47 insertions(+) |
| 25 | |
| 26 | diff --git a/mt7996/main.c b/mt7996/main.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 27 | index 534a476a..8c93297a 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 28 | --- a/mt7996/main.c |
| 29 | +++ b/mt7996/main.c |
| 30 | @@ -91,6 +91,7 @@ int mt7996_run(struct ieee80211_hw *hw) |
| 31 | #ifdef CONFIG_MTK_DEBUG |
| 32 | phy->sr_enable = true; |
| 33 | phy->enhanced_sr_enable = true; |
| 34 | + phy->thermal_protection_enable = true; |
| 35 | |
| 36 | ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_SKU_POWER_LIMIT_CTRL, |
| 37 | dev->dbg.sku_disable ? 0 : phy->sku_limit_en); |
| 38 | diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 39 | index d17b169a..6e96194b 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 40 | --- a/mt7996/mt7996.h |
| 41 | +++ b/mt7996/mt7996.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 42 | @@ -489,6 +489,7 @@ struct mt7996_phy { |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 43 | #ifdef CONFIG_MTK_DEBUG |
| 44 | bool sr_enable:1; |
| 45 | bool enhanced_sr_enable:1; |
| 46 | + bool thermal_protection_enable:1; |
| 47 | #endif |
| 48 | }; |
| 49 | |
| 50 | diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 51 | index 275beb48..66ab74d2 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 52 | --- a/mt7996/mtk_debugfs.c |
| 53 | +++ b/mt7996/mtk_debugfs.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 54 | @@ -3128,6 +3128,49 @@ mt7996_show_rro_mib(struct seq_file *s, void *data) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | +static int |
| 59 | +mt7996_thermal_enable_get(void *data, u64 *enable) |
| 60 | +{ |
| 61 | + struct mt7996_phy *phy = data; |
| 62 | + |
| 63 | + *enable = phy->thermal_protection_enable; |
| 64 | + |
| 65 | + return 0; |
| 66 | +} |
| 67 | + |
| 68 | +static int |
| 69 | +mt7996_thermal_enable_set(void *data, u64 action) |
| 70 | +{ |
| 71 | + struct mt7996_phy *phy = data; |
| 72 | + int ret; |
| 73 | + u8 throttling; |
| 74 | + |
| 75 | + if (action > 1) |
| 76 | + return -EINVAL; |
| 77 | + |
| 78 | + if (!!action == phy->thermal_protection_enable) |
| 79 | + return 0; |
| 80 | + |
| 81 | + ret = mt7996_mcu_set_thermal_protect(phy, !!action); |
| 82 | + if (ret) |
| 83 | + return ret; |
| 84 | + |
| 85 | + if (!!!action) |
| 86 | + goto out; |
| 87 | + |
| 88 | + throttling = MT7996_THERMAL_THROTTLE_MAX - phy->cdev_state; |
| 89 | + ret = mt7996_mcu_set_thermal_throttling(phy, throttling); |
| 90 | + if (ret) |
| 91 | + return ret; |
| 92 | + |
| 93 | +out: |
| 94 | + phy->thermal_protection_enable = !!action; |
| 95 | + |
| 96 | + return 0; |
| 97 | +} |
| 98 | +DEFINE_DEBUGFS_ATTRIBUTE(fops_thermal_enable, mt7996_thermal_enable_get, |
| 99 | + mt7996_thermal_enable_set, "%lld\n"); |
| 100 | + |
| 101 | int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
| 102 | { |
| 103 | struct mt7996_dev *dev = phy->dev; |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 104 | @@ -3234,6 +3277,8 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 105 | mt7996_show_rro_mib); |
| 106 | } |
| 107 | |
| 108 | + debugfs_create_file("thermal_enable", 0600, dir, phy, &fops_thermal_enable); |
| 109 | + |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | -- |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 114 | 2.18.0 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 115 | |