diff mbox series

[1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters

Message ID 20181018141645.31484-1-nbd@nbd.name (mailing list archive)
State Changes Requested
Delegated to: Kalle Valo
Headers show
Series [1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters | expand

Commit Message

Felix Fietkau Oct. 18, 2018, 2:16 p.m. UTC
Remove initval table with duplicated registers and driver specific flags
in favor of a function that sets the registers directly

Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 .../mediatek/mt76/mt76x0/initvals_phy.h       | 45 ------------
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   | 73 +++++++++++++------
 2 files changed, 49 insertions(+), 69 deletions(-)

Comments

Stanislaw Gruszka Oct. 19, 2018, 8:17 a.m. UTC | #1
On Thu, Oct 18, 2018 at 04:16:44PM +0200, Felix Fietkau wrote:
> Remove initval table with duplicated registers and driver specific flags
> in favor of a function that sets the registers directly

There are few problems with this patch: MT_RF(7, 77) is missing and
band is not taken directly from chandef but overwriteen in
'rf_band = mt76x0_frequency_plan[i].band' . But even after fixing that
I can not make MT7610U associate with AP on 5GHz. So please drop this
patch.

Thanks
Stanislaw
Felix Fietkau Oct. 19, 2018, 8:55 a.m. UTC | #2
On 2018-10-19 10:17, Stanislaw Gruszka wrote:
> On Thu, Oct 18, 2018 at 04:16:44PM +0200, Felix Fietkau wrote:
>> Remove initval table with duplicated registers and driver specific flags
>> in favor of a function that sets the registers directly
> 
> There are few problems with this patch: MT_RF(7, 77) is missing and
> band is not taken directly from chandef but overwriteen in
> 'rf_band = mt76x0_frequency_plan[i].band' . But even after fixing that
> I can not make MT7610U associate with AP on 5GHz. So please drop this
> patch.
Will do, thanks.

- Felix
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/initvals_phy.h b/drivers/net/wireless/mediatek/mt76/mt76x0/initvals_phy.h
index 56c6fa73daf5..755dd6749b65 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/initvals_phy.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/initvals_phy.h
@@ -233,51 +233,6 @@  static const struct mt76_reg_pair mt76x0_rf_vga_channel_0_tab[] = {
 	{ MT_RF(7, 74), 0x00 },
 };
 
-static const struct mt76x0_rf_switch_item mt76x0_rf_bw_switch_tab[] = {
-	/* bank, reg	bw/band			value */
-	{ MT_RF(0, 17),	RF_G_BAND | RF_BW_20,	0x00 },
-	{ MT_RF(0, 17),	RF_G_BAND | RF_BW_40,	0x00 },
-	{ MT_RF(0, 17),	RF_A_BAND | RF_BW_20,	0x00 },
-	{ MT_RF(0, 17),	RF_A_BAND | RF_BW_40,	0x00 },
-	{ MT_RF(0, 17),	RF_A_BAND | RF_BW_80,	0x00 },
-	{ MT_RF(7,  6),	RF_G_BAND | RF_BW_20,	0x40 },
-	{ MT_RF(7,  6),	RF_G_BAND | RF_BW_40,	0x1C },
-	{ MT_RF(7,  6),	RF_A_BAND | RF_BW_20,	0x40 },
-	{ MT_RF(7,  6),	RF_A_BAND | RF_BW_40,	0x20 },
-	{ MT_RF(7,  6),	RF_A_BAND | RF_BW_80,	0x10 },
-	{ MT_RF(7,  7),	RF_G_BAND | RF_BW_20,	0x40 },
-	{ MT_RF(7,  7),	RF_G_BAND | RF_BW_40,	0x20 },
-	{ MT_RF(7,  7),	RF_A_BAND | RF_BW_20,	0x40 },
-	{ MT_RF(7,  7),	RF_A_BAND | RF_BW_40,	0x20 },
-	{ MT_RF(7,  7),	RF_A_BAND | RF_BW_80,	0x10 },
-	{ MT_RF(7,  8),	RF_G_BAND | RF_BW_20,	0x03 },
-	{ MT_RF(7,  8),	RF_G_BAND | RF_BW_40,	0x01 },
-	{ MT_RF(7,  8),	RF_A_BAND | RF_BW_20,	0x03 },
-	{ MT_RF(7,  8),	RF_A_BAND | RF_BW_40,	0x01 },
-	{ MT_RF(7,  8),	RF_A_BAND | RF_BW_80,	0x00 },
-	{ MT_RF(7, 58),	RF_G_BAND | RF_BW_20,	0x40 },
-	{ MT_RF(7, 58),	RF_G_BAND | RF_BW_40,	0x40 },
-	{ MT_RF(7, 58),	RF_A_BAND | RF_BW_20,	0x40 },
-	{ MT_RF(7, 58),	RF_A_BAND | RF_BW_40,	0x40 },
-	{ MT_RF(7, 58),	RF_A_BAND | RF_BW_80,	0x10 },
-	{ MT_RF(7, 59),	RF_G_BAND | RF_BW_20,	0x40 },
-	{ MT_RF(7, 59),	RF_G_BAND | RF_BW_40,	0x40 },
-	{ MT_RF(7, 59),	RF_A_BAND | RF_BW_20,	0x40 },
-	{ MT_RF(7, 59),	RF_A_BAND | RF_BW_40,	0x40 },
-	{ MT_RF(7, 59),	RF_A_BAND | RF_BW_80,	0x10 },
-	{ MT_RF(7, 60),	RF_G_BAND | RF_BW_20,	0xAA },
-	{ MT_RF(7, 60),	RF_G_BAND | RF_BW_40,	0xAA },
-	{ MT_RF(7, 60),	RF_A_BAND | RF_BW_20,	0xAA },
-	{ MT_RF(7, 60),	RF_A_BAND | RF_BW_40,	0xAA },
-	{ MT_RF(7, 60),	RF_A_BAND | RF_BW_80,	0xAA },
-	{ MT_RF(7, 76),	RF_BW_20,		0x40 },
-	{ MT_RF(7, 76),	RF_BW_40,		0x40 },
-	{ MT_RF(7, 76),	RF_BW_80,		0x10 },
-	{ MT_RF(7, 77),	RF_BW_20,		0x40 },
-	{ MT_RF(7, 77),	RF_BW_40,		0x40 },
-	{ MT_RF(7, 77),	RF_BW_80,		0x10 },
-};
-
 static const struct mt76x0_rf_switch_item mt76x0_rf_band_switch_tab[] = {
 	/* bank, reg		bw/band		value */
 	{ MT_RF(0,  16),	RF_G_BAND,	0x20 },
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index 37e1ead1dc85..10041e673c31 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -239,17 +239,61 @@  mt76x0_phy_set_band(struct mt76x02_dev *dev, enum nl80211_band band)
 	}
 }
 
+
+static void mt76x0_phy_rf_switch_band(struct mt76x02_dev *dev,
+				      struct cfg80211_chan_def *chandef)
+{
+	enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20;
+	enum nl80211_band band = NL80211_BAND_2GHZ;
+	u8 r6, r7, r8;
+	u8 r58_59_76 = 0x40;
+
+	if (chandef) {
+		band = chandef->chan->band;
+		width = chandef->width;
+	}
+
+	switch (width) {
+	case NL80211_CHAN_WIDTH_80:
+		r6 = r7 = 0x10;
+		r8 = 0x00;
+		r58_59_76 = 0x10;
+		break;
+	case NL80211_CHAN_WIDTH_40:
+		r6 = r7 = 0x20;
+		if (band == NL80211_BAND_2GHZ)
+			r6 = 0x1c;
+		r8 = 0x01;
+		break;
+	default:
+		r6 = r7 = 0x40;
+		r8 = 0x03;
+		break;
+	}
+
+	mt76x0_rf_wr(dev, MT_RF(0, 17), 0x00);
+	mt76x0_rf_wr(dev, MT_RF(7, 6), r6);
+	mt76x0_rf_wr(dev, MT_RF(7, 7), r7);
+	mt76x0_rf_wr(dev, MT_RF(7, 8), r8);
+	mt76x0_rf_wr(dev, MT_RF(7, 58), r58_59_76);
+	mt76x0_rf_wr(dev, MT_RF(7, 59), r58_59_76);
+	mt76x0_rf_wr(dev, MT_RF(7, 60), 0xaa);
+	mt76x0_rf_wr(dev, MT_RF(7, 76), r58_59_76);
+}
+
 static void
-mt76x0_phy_set_chan_rf_params(struct mt76x02_dev *dev, u8 channel, u16 rf_bw_band)
+mt76x0_phy_set_chan_rf_params(struct mt76x02_dev *dev,
+			      struct cfg80211_chan_def *chandef, u16 rf_bw_band)
 {
 	const struct mt76x0_freq_item *freq_item;
 	u16 rf_band = rf_bw_band & 0xff00;
-	u16 rf_bw = rf_bw_band & 0x00ff;
 	enum nl80211_band band;
 	bool b_sdm = false;
 	u32 mac_reg;
+	u8 channel;
 	int i;
 
+	channel = chandef->chan->hw_value;
 	for (i = 0; i < ARRAY_SIZE(mt76x0_sdm_channel); i++) {
 		if (channel == mt76x0_sdm_channel[i]) {
 			b_sdm = true;
@@ -344,18 +388,7 @@  mt76x0_phy_set_chan_rf_params(struct mt76x02_dev *dev, u8 channel, u16 rf_bw_ban
 		}
 	}
 
-	for (i = 0; i < ARRAY_SIZE(mt76x0_rf_bw_switch_tab); i++) {
-		if (rf_bw == mt76x0_rf_bw_switch_tab[i].bw_band) {
-			mt76x0_rf_wr(dev,
-				     mt76x0_rf_bw_switch_tab[i].rf_bank_reg,
-				     mt76x0_rf_bw_switch_tab[i].value);
-		} else if ((rf_bw == (mt76x0_rf_bw_switch_tab[i].bw_band & 0xFF)) &&
-			   (rf_band & mt76x0_rf_bw_switch_tab[i].bw_band)) {
-			mt76x0_rf_wr(dev,
-				     mt76x0_rf_bw_switch_tab[i].rf_bank_reg,
-				     mt76x0_rf_bw_switch_tab[i].value);
-		}
-	}
+	mt76x0_phy_rf_switch_band(dev, chandef);
 
 	for (i = 0; i < ARRAY_SIZE(mt76x0_rf_band_switch_tab); i++) {
 		if (mt76x0_rf_band_switch_tab[i].bw_band & rf_band) {
@@ -623,7 +656,7 @@  int mt76x0_phy_set_channel(struct mt76x02_dev *dev,
 		 ext_cca_chan[ch_group_index]);
 
 	mt76x0_phy_set_band(dev, chandef->chan->band);
-	mt76x0_phy_set_chan_rf_params(dev, channel, rf_bw_band);
+	mt76x0_phy_set_chan_rf_params(dev, chandef, rf_bw_band);
 
 	/* set Japan Tx filter at channel 14 */
 	if (channel == 14)
@@ -751,15 +784,7 @@  static void mt76x0_phy_rf_init(struct mt76x02_dev *dev)
 	RF_RANDOM_WRITE(dev, mt76x0_rf_2g_channel_0_tab);
 	RF_RANDOM_WRITE(dev, mt76x0_rf_5g_channel_0_tab);
 	RF_RANDOM_WRITE(dev, mt76x0_rf_vga_channel_0_tab);
-
-	for (i = 0; i < ARRAY_SIZE(mt76x0_rf_bw_switch_tab); i++) {
-		const struct mt76x0_rf_switch_item *item = &mt76x0_rf_bw_switch_tab[i];
-
-		if (item->bw_band == RF_BW_20)
-			mt76x0_rf_wr(dev, item->rf_bank_reg, item->value);
-		else if (((RF_G_BAND | RF_BW_20) & item->bw_band) == (RF_G_BAND | RF_BW_20))
-			mt76x0_rf_wr(dev, item->rf_bank_reg, item->value);
-	}
+	mt76x0_phy_rf_switch_band(dev, NULL);
 
 	for (i = 0; i < ARRAY_SIZE(mt76x0_rf_band_switch_tab); i++) {
 		if (mt76x0_rf_band_switch_tab[i].bw_band & RF_G_BAND) {