developer | 82425a2 | 2023-08-14 15:30:41 +0800 | [diff] [blame] | 1 | From 4cb59dc3fc13de7cfb32800927cb586036f9ec7b Mon Sep 17 00:00:00 2001 |
| 2 | From: "Allen.Ye" <allen.ye@mediatek.com> |
| 3 | Date: Fri, 11 Aug 2023 16:46:53 +0800 |
| 4 | Subject: [PATCH 1035/1035] wifi: mt76: mt7915: Disable RegDB when enable |
| 5 | single sku |
| 6 | |
| 7 | --- |
| 8 | eeprom.c | 3 ++- |
| 9 | mt76.h | 3 +++ |
| 10 | mt7915/debugfs.c | 43 +++++++++++++++++++++++++++++++++++++++++-- |
| 11 | mt7915/init.c | 9 ++++++++- |
| 12 | 4 files changed, 54 insertions(+), 4 deletions(-) |
| 13 | |
| 14 | diff --git a/eeprom.c b/eeprom.c |
| 15 | index 4189525..38b0a58 100644 |
| 16 | --- a/eeprom.c |
| 17 | +++ b/eeprom.c |
| 18 | @@ -216,7 +216,7 @@ static bool mt76_string_prop_find(struct property *prop, const char *str) |
| 19 | return false; |
| 20 | } |
| 21 | |
| 22 | -static struct device_node * |
| 23 | +struct device_node * |
| 24 | mt76_find_power_limits_node(struct mt76_dev *dev) |
| 25 | { |
| 26 | struct device_node *np = dev->dev->of_node; |
| 27 | @@ -255,6 +255,7 @@ mt76_find_power_limits_node(struct mt76_dev *dev) |
| 28 | of_node_put(np); |
| 29 | return fallback; |
| 30 | } |
| 31 | +EXPORT_SYMBOL_GPL(mt76_find_power_limits_node); |
| 32 | |
| 33 | static const __be32 * |
| 34 | mt76_get_of_array(struct device_node *np, char *name, size_t *len, int min) |
| 35 | diff --git a/mt76.h b/mt76.h |
| 36 | index 2f801de..aece4ec 100644 |
| 37 | --- a/mt76.h |
| 38 | +++ b/mt76.h |
| 39 | @@ -1655,6 +1655,9 @@ mt76_mcu_skb_send_msg(struct mt76_dev *dev, struct sk_buff *skb, int cmd, |
| 40 | |
| 41 | void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr, u32 clear, u32 set); |
| 42 | |
| 43 | +struct device_node * |
| 44 | +mt76_find_power_limits_node(struct mt76_dev *dev); |
| 45 | + |
| 46 | s8 mt76_get_rate_power_limits(struct mt76_phy *phy, |
| 47 | struct ieee80211_channel *chan, |
| 48 | struct mt76_power_limits *dest, |
| 49 | diff --git a/mt7915/debugfs.c b/mt7915/debugfs.c |
| 50 | index 2bf907c..bb312ee 100644 |
| 51 | --- a/mt7915/debugfs.c |
| 52 | +++ b/mt7915/debugfs.c |
| 53 | @@ -1019,10 +1019,16 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf, |
| 54 | { |
| 55 | struct mt7915_phy *phy = file->private_data; |
| 56 | struct mt7915_dev *dev = phy->dev; |
| 57 | + struct ieee80211_channel *chan = phy->mt76->chandef.chan; |
| 58 | + struct ieee80211_supported_band sband; |
| 59 | s8 txpwr[MT7915_SKU_RATE_NUM]; |
| 60 | - static const size_t sz = 2048; |
| 61 | + static const size_t sz = 4096; |
| 62 | u8 band = phy->mt76->band_idx; |
| 63 | int i, offs = 0, len = 0; |
| 64 | + u32 target_power = 0; |
| 65 | + int n_chains = hweight16(phy->mt76->chainmask); |
| 66 | + int nss_delta = mt76_tx_power_nss_delta(n_chains); |
| 67 | + int pwr_delta; |
| 68 | ssize_t ret; |
| 69 | char *buf; |
| 70 | u32 reg; |
| 71 | @@ -1084,9 +1090,36 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf, |
| 72 | reg = is_mt7915(&dev->mt76) ? MT_WF_PHY_TPC_CTRL_STAT(band) : |
| 73 | MT_WF_PHY_TPC_CTRL_STAT_MT7916(band); |
| 74 | |
| 75 | - len += scnprintf(buf + len, sz - len, "\nTx power (bbp) : %6ld\n", |
| 76 | + len += scnprintf(buf + len, sz - len, "\nTx power (bbp) : %6ld [0.5 dBm]\n", |
| 77 | mt76_get_field(dev, reg, MT_WF_PHY_TPC_POWER)); |
| 78 | |
| 79 | + len += scnprintf(buf + len, sz - len, "RegDB maximum power:\t%d [dBm]\n", |
| 80 | + chan->max_reg_power); |
| 81 | + |
| 82 | + if (chan->band == NL80211_BAND_2GHZ) |
| 83 | + sband = phy->mt76->sband_2g.sband; |
| 84 | + else if (chan->band == NL80211_BAND_5GHZ) |
| 85 | + sband = phy->mt76->sband_5g.sband; |
| 86 | + else if (chan->band == NL80211_BAND_6GHZ) |
| 87 | + sband = phy->mt76->sband_6g.sband; |
| 88 | + |
| 89 | + pwr_delta = mt7915_eeprom_get_power_delta(dev, sband.band); |
| 90 | + |
| 91 | + for (i = 0; i < n_chains; i++) { |
| 92 | + u32 val; |
| 93 | + |
| 94 | + val = mt7915_eeprom_get_target_power(dev, chan, i); |
| 95 | + target_power = max(target_power, val); |
| 96 | + } |
| 97 | + |
| 98 | + target_power += pwr_delta + nss_delta; |
| 99 | + target_power = DIV_ROUND_UP(target_power, 2); |
| 100 | + len += scnprintf(buf + len, sz - len, "eeprom maximum power:\t%d [dBm]\n", |
| 101 | + target_power); |
| 102 | + |
| 103 | + len += scnprintf(buf + len, sz - len, "nss_delta:\t%d [0.5 dBm]\n", |
| 104 | + nss_delta); |
| 105 | + |
| 106 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 107 | |
| 108 | out: |
| 109 | @@ -1262,6 +1295,8 @@ static int |
| 110 | mt7915_txpower_info_show(struct seq_file *file, void *data) |
| 111 | { |
| 112 | struct mt7915_phy *phy = file->private; |
| 113 | + struct mt76_phy *mphy = phy->mt76; |
| 114 | + struct mt76_dev *dev = mphy->dev; |
| 115 | struct { |
| 116 | u8 category; |
| 117 | u8 rsv1; |
| 118 | @@ -1303,6 +1338,7 @@ mt7915_txpower_info_show(struct seq_file *file, void *data) |
| 119 | s8 mu_tx_power_manual; |
| 120 | u8 rsv3; |
| 121 | } __packed basic_info = {}; |
| 122 | + struct device_node *np; |
| 123 | int ret; |
| 124 | |
| 125 | ret = mt7915_mcu_get_txpower_sku(phy, (s8 *)&basic_info, sizeof(basic_info), |
| 126 | @@ -1337,6 +1373,9 @@ mt7915_txpower_info_show(struct seq_file *file, void *data) |
| 127 | seq_printf(file, " Theraml Compensation Value: %d\n", |
| 128 | basic_info.thermal_compensate_value); |
| 129 | |
| 130 | + np = mt76_find_power_limits_node(dev); |
| 131 | + seq_printf(file, " RegDB: %s\n", !np ? "enable" : "disable"); |
| 132 | + |
| 133 | out: |
| 134 | return ret; |
| 135 | } |
| 136 | diff --git a/mt7915/init.c b/mt7915/init.c |
| 137 | index f8ecaf3..623b070 100644 |
| 138 | --- a/mt7915/init.c |
| 139 | +++ b/mt7915/init.c |
| 140 | @@ -286,7 +286,9 @@ void __mt7915_init_txpower(struct mt7915_phy *phy, |
| 141 | int nss_delta = mt76_tx_power_nss_delta(n_chains); |
| 142 | int pwr_delta = mt7915_eeprom_get_power_delta(dev, sband->band); |
| 143 | struct mt76_power_limits limits; |
| 144 | + struct device_node *np; |
| 145 | |
| 146 | + np = mt76_find_power_limits_node(&dev->mt76); |
| 147 | for (i = 0; i < sband->n_channels; i++) { |
| 148 | struct ieee80211_channel *chan = &sband->channels[i]; |
| 149 | u32 target_power = 0; |
| 150 | @@ -305,8 +307,13 @@ void __mt7915_init_txpower(struct mt7915_phy *phy, |
| 151 | target_power); |
| 152 | target_power += nss_delta; |
| 153 | target_power = DIV_ROUND_UP(target_power, 2); |
| 154 | - chan->max_power = min_t(int, chan->max_reg_power, |
| 155 | + |
| 156 | + /* can NOT find country node in dts */ |
| 157 | + if (!np) |
| 158 | + chan->max_power = min_t(int, chan->max_reg_power, |
| 159 | target_power); |
| 160 | + else |
| 161 | + chan->max_power = target_power; |
| 162 | chan->orig_mpwr = target_power; |
| 163 | } |
| 164 | } |
| 165 | -- |
| 166 | 2.18.0 |
| 167 | |