Skip to contentSkip to conversation

mt76x0: initialize per-channel max_power

PATCH Applied Lorenzo Bianconi 2 participants 4 messages Jan 28, 2019 – Feb 11, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mt76x0: initialize per-channel max_power

Compute maximum per channel tx power at device probe. Report eeprom target power in debugfs
This patchset is based on 'mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info'
https://patchwork.kernel.org/patch/10782801/

Lorenzo Bianconi (2):
mt76x0: phy: report target_power in debugfs
mt76x0: init: introduce mt76x0_init_txpower routine

 .../wireless/mediatek/mt76/mt76x0/eeprom.c    | 10 +++----
 .../wireless/mediatek/mt76/mt76x0/eeprom.h    |  7 +++--
 .../net/wireless/mediatek/mt76/mt76x0/init.c  | 29 +++++++++++++++++--
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   |  5 ++--
 4 files changed, 40 insertions(+), 11 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 mt76x0: phy: report target_power in debugfs

Initialize target_power variable in mt76x0_phy_set_txpower in order to report target_power in debugfs

---
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +1 -0
index 1117cdc15b04..3fe2e1e28404 100644
@@ -855,6 +855,7 @@ void mt76x0_phy_set_txpower(struct mt76x02_dev *dev)
 	dev->mt76.txpower_cur = mt76x02_get_max_rate_power(t);
 	mt76x02_add_rate_power_offset(t, -info);
 
+	dev->target_power = info;
 	mt76x02_phy_set_txpower(dev, info, info);
 }
 
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/2 mt76x0: init: introduce mt76x0_init_txpower routine

In reply to Lorenzo Bianconi

Add mt76x0_init_txpower in order to initialize max_power per channel at device bootstrap. Modify mt76x0_get_tx_power_per_rate and mt76x0_get_power_info signature in order to compute tx power for non-operating channels

---
 .../wireless/mediatek/mt76/mt76x0/eeprom.c    | 10 +++----
 .../wireless/mediatek/mt76/mt76x0/eeprom.h    |  7 +++--
 .../net/wireless/mediatek/mt76/mt76x0/init.c  | 29 +++++++++++++++++--
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   |  4 +--
 4 files changed, 39 insertions(+), 11 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +5 -5
index b2cabce1d74d..952d20b8353a 100644
@@ -152,11 +152,11 @@ static s8 mt76x0_get_delta(struct mt76x02_dev *dev)
 	return mt76x02_rate_power_val(val);
 }
 
-void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev)
+void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev,
+				  struct ieee80211_channel *chan,
+				  struct mt76_rate_power *t)
 {
-	struct ieee80211_channel *chan = dev->mt76.chandef.chan;
 	bool is_2ghz = chan->band == NL80211_BAND_2GHZ;
-	struct mt76_rate_power *t = &dev->mt76.rate_power;
 	u16 val, addr;
 	s8 delta;
 
@@ -212,7 +212,8 @@ void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev)
 	mt76x02_add_rate_power_offset(t, delta);
 }
 
-void mt76x0_get_power_info(struct mt76x02_dev *dev, s8 *tp)
+void mt76x0_get_power_info(struct mt76x02_dev *dev,
+			   struct ieee80211_channel *chan, s8 *tp)
 {
 	struct mt76x0_chan_map {
 		u8 chan;
@@ -226,7 +227,6 @@ void mt76x0_get_power_info(struct mt76x02_dev *dev, s8 *tp)
 		{ 140, 26 }, { 151, 28 }, { 157, 30 }, { 161, 32 },
 		{ 167, 34 }, { 171, 36 }, { 175, 38 },
 	};
-	struct ieee80211_channel *chan = dev->mt76.chandef.chan;
 	u8 offset, addr;
 	int i, idx = 0;
 	u16 data;
drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +5 -2
index 42b259f90b6d..7f73034a23b1 100644
@@ -25,8 +25,11 @@ struct mt76x02_dev;
 
 int mt76x0_eeprom_init(struct mt76x02_dev *dev);
 void mt76x0_read_rx_gain(struct mt76x02_dev *dev);
-void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev);
-void mt76x0_get_power_info(struct mt76x02_dev *dev, s8 *tp);
+void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev,
+				  struct ieee80211_channel *chan,
+				  struct mt76_rate_power *t);
+void mt76x0_get_power_info(struct mt76x02_dev *dev,
+			   struct ieee80211_channel *chan, s8 *tp);
 
 static inline s8 s6_to_s8(u32 val)
 {
drivers/net/wireless/mediatek/mt76/mt76x0/init.c +27 -2
index 87b575fe1c74..9ef61f197303 100644
@@ -18,6 +18,7 @@
 #include "eeprom.h"
 #include "mcu.h"
 #include "initvals.h"
+#include "../mt76x02_phy.h"
 
 static void mt76x0_vht_cap_mask(struct ieee80211_supported_band *sband)
 {
@@ -284,6 +285,25 @@ mt76x0_alloc_device(struct device *pdev,
 }
 EXPORT_SYMBOL_GPL(mt76x0_alloc_device);
 
+static void
+mt76x0_init_txpower(struct mt76x02_dev *dev,
+		    struct ieee80211_supported_band *sband)
+{
+	struct ieee80211_channel *chan;
+	struct mt76_rate_power t;
+	s8 tp;
+	int i;
+
+	for (i = 0; i < sband->n_channels; i++) {
+		chan = &sband->channels[i];
+
+		mt76x0_get_tx_power_per_rate(dev, chan, &t);
+		mt76x0_get_power_info(dev, chan, &tp);
+
+		chan->max_power = (mt76x02_get_max_rate_power(&t) + tp) / 2;
+	}
+}
+
 int mt76x0_register_device(struct mt76x02_dev *dev)
 {
 	int ret;
@@ -296,9 +316,14 @@ int mt76x0_register_device(struct mt76x02_dev *dev)
 	if (ret)
 		return ret;
 
-	/* overwrite unsupported features */
-	if (dev->mt76.cap.has_5ghz)
+	if (dev->mt76.cap.has_5ghz) {
+		/* overwrite unsupported features */
 		mt76x0_vht_cap_mask(&dev->mt76.sband_5g.sband);
+		mt76x0_init_txpower(dev, &dev->mt76.sband_5g.sband);
+	}
+
+	if (dev->mt76.cap.has_2ghz)
+		mt76x0_init_txpower(dev, &dev->mt76.sband_2g.sband);
 
 	mt76x02_init_debugfs(dev);
 
drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +2 -2
index 3fe2e1e28404..e08411497a99 100644
@@ -847,8 +847,8 @@ void mt76x0_phy_set_txpower(struct mt76x02_dev *dev)
 	struct mt76_rate_power *t = &dev->mt76.rate_power;
 	s8 info;
 
-	mt76x0_get_tx_power_per_rate(dev);
-	mt76x0_get_power_info(dev, &info);
+	mt76x0_get_tx_power_per_rate(dev, dev->mt76.chandef.chan, t);
+	mt76x0_get_power_info(dev, dev->mt76.chandef.chan, &info);
 
 	mt76x02_add_rate_power_offset(t, info);
 	mt76x02_limit_rate_power(t, dev->mt76.txpower_conf);
Signature · 1 line
2.20.1
maintainer Applied
#3 lore raw
In reply to Lorenzo Bianconi
Quoted 9 lines · Lorenzo Bianconi

Compute maximum per channel tx power at device probe. Report eeprom target power in debugfs
This patchset is based on 'mt76x0: eeprom: fix chan_vs_power map in mt76x0_get_power_info'
https://patchwork.kernel.org/patch/10782801/

Lorenzo Bianconi (2):
mt76x0: phy: report target_power in debugfs
mt76x0: init: introduce mt76x0_init_txpower routine

Applied, thanks.

- Felix