developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 1 | From c499d09d496d723dab109aee2e3af8a28278a54c Mon Sep 17 00:00:00 2001 |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 2 | From: "Allen.Ye" <allen.ye@mediatek.com> |
| 3 | Date: Fri, 11 Aug 2023 16:46:53 +0800 |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 4 | Subject: [PATCH 1036/1040] wifi: mt76: mt7915: Disable RegDB when enable |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 5 | single sku |
| 6 | |
| 7 | --- |
| 8 | eeprom.c | 3 ++- |
| 9 | mt76.h | 3 +++ |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 10 | mt7915/debugfs.c | 49 +++++++++++++++++++++++++++++++++++++++++++----- |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 11 | mt7915/init.c | 9 ++++++++- |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 12 | mt7915/regs.h | 8 ++++---- |
| 13 | 5 files changed, 61 insertions(+), 11 deletions(-) |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 14 | |
| 15 | diff --git a/eeprom.c b/eeprom.c |
| 16 | index 4189525..38b0a58 100644 |
| 17 | --- a/eeprom.c |
| 18 | +++ b/eeprom.c |
| 19 | @@ -216,7 +216,7 @@ static bool mt76_string_prop_find(struct property *prop, const char *str) |
| 20 | return false; |
| 21 | } |
| 22 | |
| 23 | -static struct device_node * |
| 24 | +struct device_node * |
| 25 | mt76_find_power_limits_node(struct mt76_dev *dev) |
| 26 | { |
| 27 | struct device_node *np = dev->dev->of_node; |
| 28 | @@ -255,6 +255,7 @@ mt76_find_power_limits_node(struct mt76_dev *dev) |
| 29 | of_node_put(np); |
| 30 | return fallback; |
| 31 | } |
| 32 | +EXPORT_SYMBOL_GPL(mt76_find_power_limits_node); |
| 33 | |
| 34 | static const __be32 * |
| 35 | mt76_get_of_array(struct device_node *np, char *name, size_t *len, int min) |
| 36 | diff --git a/mt76.h b/mt76.h |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 37 | index 05c1874..91da8c5 100644 |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 38 | --- a/mt76.h |
| 39 | +++ b/mt76.h |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 40 | @@ -1673,6 +1673,9 @@ mt76_mcu_skb_send_msg(struct mt76_dev *dev, struct sk_buff *skb, int cmd, |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 41 | |
| 42 | void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr, u32 clear, u32 set); |
| 43 | |
| 44 | +struct device_node * |
| 45 | +mt76_find_power_limits_node(struct mt76_dev *dev); |
| 46 | + |
| 47 | s8 mt76_get_rate_power_limits(struct mt76_phy *phy, |
| 48 | struct ieee80211_channel *chan, |
| 49 | struct mt76_power_limits *dest, |
| 50 | diff --git a/mt7915/debugfs.c b/mt7915/debugfs.c |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 51 | index 2bf907c..6dcee10 100644 |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 52 | --- a/mt7915/debugfs.c |
| 53 | +++ b/mt7915/debugfs.c |
| 54 | @@ -1019,10 +1019,16 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf, |
| 55 | { |
| 56 | struct mt7915_phy *phy = file->private_data; |
| 57 | struct mt7915_dev *dev = phy->dev; |
| 58 | + struct ieee80211_channel *chan = phy->mt76->chandef.chan; |
| 59 | + struct ieee80211_supported_band sband; |
| 60 | s8 txpwr[MT7915_SKU_RATE_NUM]; |
| 61 | - static const size_t sz = 2048; |
| 62 | + static const size_t sz = 4096; |
| 63 | u8 band = phy->mt76->band_idx; |
| 64 | int i, offs = 0, len = 0; |
| 65 | + u32 target_power = 0; |
| 66 | + int n_chains = hweight16(phy->mt76->chainmask); |
| 67 | + int nss_delta = mt76_tx_power_nss_delta(n_chains); |
| 68 | + int pwr_delta; |
| 69 | ssize_t ret; |
| 70 | char *buf; |
| 71 | u32 reg; |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 72 | @@ -1081,11 +1087,38 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf, |
| 73 | len += scnprintf(buf + len, sz - len, "BW160/"); |
| 74 | mt7915_txpower_puts(HE_RU2x996, 17); |
| 75 | |
| 76 | - reg = is_mt7915(&dev->mt76) ? MT_WF_PHY_TPC_CTRL_STAT(band) : |
| 77 | - MT_WF_PHY_TPC_CTRL_STAT_MT7916(band); |
| 78 | + reg = is_mt7915(&dev->mt76) ? MT_WF_IRPI_TPC_CTRL_STAT(band) : |
| 79 | + MT_WF_IRPI_TPC_CTRL_STAT_MT7916(band); |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 80 | |
| 81 | - len += scnprintf(buf + len, sz - len, "\nTx power (bbp) : %6ld\n", |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 82 | - mt76_get_field(dev, reg, MT_WF_PHY_TPC_POWER)); |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 83 | + len += scnprintf(buf + len, sz - len, "\nTx power (bbp) : %6ld [0.5 dBm]\n", |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 84 | + mt76_get_field(dev, reg, MT_WF_IRPI_TPC_POWER)); |
| 85 | + |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 86 | + len += scnprintf(buf + len, sz - len, "RegDB maximum power:\t%d [dBm]\n", |
| 87 | + chan->max_reg_power); |
| 88 | + |
| 89 | + if (chan->band == NL80211_BAND_2GHZ) |
| 90 | + sband = phy->mt76->sband_2g.sband; |
| 91 | + else if (chan->band == NL80211_BAND_5GHZ) |
| 92 | + sband = phy->mt76->sband_5g.sband; |
| 93 | + else if (chan->band == NL80211_BAND_6GHZ) |
| 94 | + sband = phy->mt76->sband_6g.sband; |
| 95 | + |
| 96 | + pwr_delta = mt7915_eeprom_get_power_delta(dev, sband.band); |
| 97 | + |
| 98 | + for (i = 0; i < n_chains; i++) { |
| 99 | + u32 val; |
| 100 | + |
| 101 | + val = mt7915_eeprom_get_target_power(dev, chan, i); |
| 102 | + target_power = max(target_power, val); |
| 103 | + } |
| 104 | + |
| 105 | + target_power += pwr_delta + nss_delta; |
| 106 | + target_power = DIV_ROUND_UP(target_power, 2); |
| 107 | + len += scnprintf(buf + len, sz - len, "eeprom maximum power:\t%d [dBm]\n", |
| 108 | + target_power); |
| 109 | + |
| 110 | + len += scnprintf(buf + len, sz - len, "nss_delta:\t%d [0.5 dBm]\n", |
| 111 | + nss_delta); |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 112 | |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 113 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 114 | |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 115 | @@ -1262,6 +1295,8 @@ static int |
| 116 | mt7915_txpower_info_show(struct seq_file *file, void *data) |
| 117 | { |
| 118 | struct mt7915_phy *phy = file->private; |
| 119 | + struct mt76_phy *mphy = phy->mt76; |
| 120 | + struct mt76_dev *dev = mphy->dev; |
| 121 | struct { |
| 122 | u8 category; |
| 123 | u8 rsv1; |
| 124 | @@ -1303,6 +1338,7 @@ mt7915_txpower_info_show(struct seq_file *file, void *data) |
| 125 | s8 mu_tx_power_manual; |
| 126 | u8 rsv3; |
| 127 | } __packed basic_info = {}; |
| 128 | + struct device_node *np; |
| 129 | int ret; |
| 130 | |
| 131 | ret = mt7915_mcu_get_txpower_sku(phy, (s8 *)&basic_info, sizeof(basic_info), |
| 132 | @@ -1337,6 +1373,9 @@ mt7915_txpower_info_show(struct seq_file *file, void *data) |
| 133 | seq_printf(file, " Theraml Compensation Value: %d\n", |
| 134 | basic_info.thermal_compensate_value); |
| 135 | |
| 136 | + np = mt76_find_power_limits_node(dev); |
| 137 | + seq_printf(file, " RegDB: %s\n", !np ? "enable" : "disable"); |
| 138 | + |
| 139 | out: |
| 140 | return ret; |
| 141 | } |
| 142 | diff --git a/mt7915/init.c b/mt7915/init.c |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 143 | index a942bc2..82fe443 100644 |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 144 | --- a/mt7915/init.c |
| 145 | +++ b/mt7915/init.c |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 146 | @@ -283,7 +283,9 @@ void __mt7915_init_txpower(struct mt7915_phy *phy, |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 147 | int nss_delta = mt76_tx_power_nss_delta(n_chains); |
| 148 | int pwr_delta = mt7915_eeprom_get_power_delta(dev, sband->band); |
| 149 | struct mt76_power_limits limits; |
| 150 | + struct device_node *np; |
| 151 | |
| 152 | + np = mt76_find_power_limits_node(&dev->mt76); |
| 153 | for (i = 0; i < sband->n_channels; i++) { |
| 154 | struct ieee80211_channel *chan = &sband->channels[i]; |
| 155 | u32 target_power = 0; |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 156 | @@ -302,8 +304,13 @@ void __mt7915_init_txpower(struct mt7915_phy *phy, |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 157 | target_power); |
| 158 | target_power += nss_delta; |
| 159 | target_power = DIV_ROUND_UP(target_power, 2); |
| 160 | - chan->max_power = min_t(int, chan->max_reg_power, |
| 161 | + |
| 162 | + /* can NOT find country node in dts */ |
| 163 | + if (!np) |
| 164 | + chan->max_power = min_t(int, chan->max_reg_power, |
| 165 | target_power); |
| 166 | + else |
| 167 | + chan->max_power = target_power; |
| 168 | chan->orig_mpwr = target_power; |
| 169 | } |
| 170 | } |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 171 | diff --git a/mt7915/regs.h b/mt7915/regs.h |
| 172 | index 1f1f8b9..3c2fd2d 100644 |
| 173 | --- a/mt7915/regs.h |
| 174 | +++ b/mt7915/regs.h |
| 175 | @@ -1213,6 +1213,10 @@ enum offs_rev { |
| 176 | #define MT_WF_IRPI_NSS(phy, nss) MT_WF_IRPI(0x6000 + ((phy) << 20) + ((nss) << 16)) |
| 177 | #define MT_WF_IRPI_NSS_MT7916(phy, nss) MT_WF_IRPI(0x1000 + ((phy) << 20) + ((nss) << 16)) |
| 178 | |
| 179 | +#define MT_WF_IRPI_TPC_CTRL_STAT(_phy) MT_WF_IRPI(0xc794 + ((_phy) << 16)) |
| 180 | +#define MT_WF_IRPI_TPC_CTRL_STAT_MT7916(_phy) MT_WF_IRPI(0xc794 + ((_phy) << 20)) |
| 181 | +#define MT_WF_IRPI_TPC_POWER GENMASK(31, 24) |
| 182 | + |
| 183 | #define MT_WF_IPI_RESET 0x831a3008 |
| 184 | |
| 185 | /* PHY */ |
| 186 | @@ -1229,10 +1233,6 @@ enum offs_rev { |
| 187 | #define MT_WF_PHY_RXTD12_IRPI_SW_CLR_ONLY BIT(18) |
| 188 | #define MT_WF_PHY_RXTD12_IRPI_SW_CLR BIT(29) |
| 189 | |
| 190 | -#define MT_WF_PHY_TPC_CTRL_STAT(_phy) MT_WF_PHY(0xe7a0 + ((_phy) << 16)) |
| 191 | -#define MT_WF_PHY_TPC_CTRL_STAT_MT7916(_phy) MT_WF_PHY(0xe7a0 + ((_phy) << 20)) |
| 192 | -#define MT_WF_PHY_TPC_POWER GENMASK(15, 8) |
| 193 | - |
| 194 | #define MT_MCU_WM_CIRQ_BASE 0x89010000 |
| 195 | #define MT_MCU_WM_CIRQ(ofs) (MT_MCU_WM_CIRQ_BASE + (ofs)) |
| 196 | #define MT_MCU_WM_CIRQ_IRQ_MASK_CLR_ADDR MT_MCU_WM_CIRQ(0x80) |
developer | dff5277 | 2023-08-18 17:03:34 +0800 | [diff] [blame] | 197 | -- |
| 198 | 2.18.0 |
| 199 | |