All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters
@ 2018-10-18 14:16 Felix Fietkau
  2018-10-18 14:16 ` [PATCH 2/2] mt76: mt76x0: handle chip specific initval differences Felix Fietkau
  2018-10-19  8:17 ` [PATCH 1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters Stanislaw Gruszka
  0 siblings, 2 replies; 4+ messages in thread
From: Felix Fietkau @ 2018-10-18 14:16 UTC (permalink / raw)
  To: linux-wireless; +Cc: sgruszka, lorenzo.bianconi

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(-)

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) {
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] mt76: mt76x0: handle chip specific initval differences
  2018-10-18 14:16 [PATCH 1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters Felix Fietkau
@ 2018-10-18 14:16 ` Felix Fietkau
  2018-10-19  8:17 ` [PATCH 1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters Stanislaw Gruszka
  1 sibling, 0 replies; 4+ messages in thread
From: Felix Fietkau @ 2018-10-18 14:16 UTC (permalink / raw)
  To: linux-wireless; +Cc: sgruszka, lorenzo.bianconi

Some RF registers need different values for various chips.
For at least mt76x0_rf_central_tab registers, overwriting them later does
not work, as the wrong values can cause the entire system to hang on some
devices with MT7610E

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

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
index 33475788bc26..989ed00c0b7a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
@@ -33,8 +33,10 @@
 
 static inline bool is_mt7610e(struct mt76x02_dev *dev)
 {
-	/* TODO */
-	return false;
+	if (!mt76_is_mmio(dev))
+		return false;
+
+	return mt76_chip(&dev->mt76) == 0x7610;
 }
 
 static inline bool is_mt7630(struct mt76x02_dev *dev)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index 10041e673c31..d294325221f3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -775,13 +775,56 @@ static void mt76x0_phy_calibration_work(struct work_struct *work)
 				     MT_CALIBRATE_INTERVAL);
 }
 
+static void mt76x0_rf_patch_reg_array(struct mt76x02_dev *dev,
+				      const struct mt76_reg_pair *rp, int len)
+{
+	int i;
+
+	for (i = 0; i < len; i++) {
+		u32 reg = rp[i].reg;
+		u8 val = rp[i].value;
+
+		switch (reg) {
+		case MT_RF(0, 3):
+			if (mt76_is_mmio(dev)) {
+				if (is_mt7630(dev))
+					val = 0x70;
+				else
+					val = 0x63;
+			} else {
+				val = 0x73;
+			}
+			break;
+		case MT_RF(0, 21):
+			if (is_mt7610e(dev))
+				val = 0x10;
+			else
+				val = 0x12;
+			break;
+		case MT_RF(5, 2):
+			if (is_mt7630(dev))
+				val = 0x1d;
+			else if (is_mt7610e(dev))
+				val = 0x00;
+			else
+				val = 0x0c;
+			break;
+		default:
+			break;
+		}
+		mt76x0_rf_wr(dev, reg, val);
+	}
+}
+
 static void mt76x0_phy_rf_init(struct mt76x02_dev *dev)
 {
 	int i;
 	u8 val;
 
-	RF_RANDOM_WRITE(dev, mt76x0_rf_central_tab);
-	RF_RANDOM_WRITE(dev, mt76x0_rf_2g_channel_0_tab);
+	mt76x0_rf_patch_reg_array(dev, mt76x0_rf_central_tab,
+				  ARRAY_SIZE(mt76x0_rf_central_tab));
+	mt76x0_rf_patch_reg_array(dev, mt76x0_rf_2g_channel_0_tab,
+				  ARRAY_SIZE(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);
 	mt76x0_phy_rf_switch_band(dev, NULL);
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters
  2018-10-18 14:16 [PATCH 1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters Felix Fietkau
  2018-10-18 14:16 ` [PATCH 2/2] mt76: mt76x0: handle chip specific initval differences Felix Fietkau
@ 2018-10-19  8:17 ` Stanislaw Gruszka
  2018-10-19  8:55   ` Felix Fietkau
  1 sibling, 1 reply; 4+ messages in thread
From: Stanislaw Gruszka @ 2018-10-19  8:17 UTC (permalink / raw)
  To: Felix Fietkau; +Cc: linux-wireless, lorenzo.bianconi

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters
  2018-10-19  8:17 ` [PATCH 1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters Stanislaw Gruszka
@ 2018-10-19  8:55   ` Felix Fietkau
  0 siblings, 0 replies; 4+ messages in thread
From: Felix Fietkau @ 2018-10-19  8:55 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: linux-wireless, lorenzo.bianconi

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-19  8:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-18 14:16 [PATCH 1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters Felix Fietkau
2018-10-18 14:16 ` [PATCH 2/2] mt76: mt76x0: handle chip specific initval differences Felix Fietkau
2018-10-19  8:17 ` [PATCH 1/2] mt76: mt76x0: reduce duplication in setting rf bandwidth parameters Stanislaw Gruszka
2018-10-19  8:55   ` Felix Fietkau

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.