summaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/mediatek/mt76/mt7915/init.c
diff options
context:
space:
mode:
authorShayne Chen <shayne.chen@mediatek.com>2021-04-17 00:16:18 +0200
committerFelix Fietkau <nbd@nbd.name>2021-04-21 12:20:54 +0200
commitecb187a74e1846156fac7c14a60650130cbe3c22 (patch)
tree04c8f0a4521eddf9ddb5f8b576c3ad5a253c2d63 /drivers/net/wireless/mediatek/mt76/mt7915/init.c
parentmt76: mt7915: add support for DT rate power limits (diff)
downloadlinux-ecb187a74e1846156fac7c14a60650130cbe3c22.tar.xz
linux-ecb187a74e1846156fac7c14a60650130cbe3c22.zip
mt76: mt7915: rework the flow of txpower setting
Clean up the flow of per-rate txpower limit setting to get rid of duplicate work since it has already been handled by firmware, and set proper max_power based on different channels and regdomains. Signed-off-by: Shayne Chen <shayne.chen@mediatek.com> Signed-off-by: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'drivers/net/wireless/mediatek/mt76/mt7915/init.c')
-rw-r--r--drivers/net/wireless/mediatek/mt76/mt7915/init.c72
1 files changed, 39 insertions, 33 deletions
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/init.c b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
index 19fa9ad7d5d7..2d6b38d39356 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
@@ -68,6 +68,39 @@ static const struct ieee80211_iface_combination if_comb[] = {
};
static void
+mt7915_init_txpower(struct mt7915_dev *dev,
+ struct ieee80211_supported_band *sband)
+{
+ int i, n_chains = hweight8(dev->mphy.antenna_mask);
+ int nss_delta = mt76_tx_power_nss_delta(n_chains);
+ int pwr_delta = mt7915_eeprom_get_power_delta(dev, sband->band);
+ struct mt76_power_limits limits;
+
+ for (i = 0; i < sband->n_channels; i++) {
+ struct ieee80211_channel *chan = &sband->channels[i];
+ u32 target_power = 0;
+ int j;
+
+ for (j = 0; j < n_chains; j++) {
+ u32 val;
+
+ val = mt7915_eeprom_get_target_power(dev, chan, j);
+ target_power = max(target_power, val);
+ }
+
+ target_power += pwr_delta;
+ target_power = mt76_get_rate_power_limits(&dev->mphy, chan,
+ &limits,
+ target_power);
+ target_power += nss_delta;
+ target_power = DIV_ROUND_UP(target_power, 2);
+ chan->max_power = min_t(int, chan->max_reg_power,
+ target_power);
+ chan->orig_mpwr = target_power;
+ }
+}
+
+static void
mt7915_regd_notifier(struct wiphy *wiphy,
struct regulatory_request *request)
{
@@ -77,8 +110,12 @@ mt7915_regd_notifier(struct wiphy *wiphy,
struct mt7915_phy *phy = mphy->priv;
struct cfg80211_chan_def *chandef = &mphy->chandef;
+ memcpy(dev->mt76.alpha2, request->alpha2, sizeof(dev->mt76.alpha2));
dev->mt76.region = request->dfs_region;
+ mt7915_init_txpower(dev, &mphy->sband_2g.sband);
+ mt7915_init_txpower(dev, &mphy->sband_5g.sband);
+
if (!(chandef->chan->flags & IEEE80211_CHAN_RADAR))
return;
@@ -207,38 +244,6 @@ static int mt7915_txbf_init(struct mt7915_dev *dev)
return mt7915_mcu_set_txbf_type(dev);
}
-static void
-mt7915_init_txpower_band(struct mt7915_dev *dev,
- struct ieee80211_supported_band *sband)
-{
- int i, n_chains = hweight8(dev->mphy.antenna_mask);
-
- for (i = 0; i < sband->n_channels; i++) {
- struct ieee80211_channel *chan = &sband->channels[i];
- u32 target_power = 0;
- int j;
-
- for (j = 0; j < n_chains; j++) {
- u32 val;
-
- val = mt7915_eeprom_get_target_power(dev, chan, j);
- target_power = max(target_power, val);
- }
-
- chan->max_power = min_t(int, chan->max_reg_power,
- target_power / 2);
- chan->orig_mpwr = target_power / 2;
- }
-}
-
-static void mt7915_init_txpower(struct mt7915_dev *dev)
-{
- mt7915_init_txpower_band(dev, &dev->mphy.sband_2g.sband);
- mt7915_init_txpower_band(dev, &dev->mphy.sband_5g.sband);
-
- mt7915_eeprom_init_sku(dev);
-}
-
static int mt7915_register_ext_phy(struct mt7915_dev *dev)
{
struct mt7915_phy *phy = mt7915_ext_phy(dev);
@@ -295,7 +300,8 @@ static void mt7915_init_work(struct work_struct *work)
mt7915_mcu_set_eeprom(dev);
mt7915_mac_init(dev);
- mt7915_init_txpower(dev);
+ mt7915_init_txpower(dev, &dev->mphy.sband_2g.sband);
+ mt7915_init_txpower(dev, &dev->mphy.sband_5g.sband);
mt7915_txbf_init(dev);
}