All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] rt2x00: set registers based on current band
@ 2018-09-17 16:32 Tomislav Požega
  2018-09-17 16:32 ` [PATCH 2/5] rt2x00: rework channel config function Tomislav Požega
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: Tomislav Požega @ 2018-09-17 16:32 UTC (permalink / raw)
  To: linux-wireless

Use curr_band instead of rf->channel among various subroutines -
mostly for 2.4GHz band but in some circumstances for 5GHz band too.

Signed-off-by: Tomislav Požega <pozega.tomislav@gmail.com>
---
 drivers/net/wireless/ralink/rt2x00/rt2800lib.c |  130 +++++++++++++-----------
 1 files changed, 72 insertions(+), 58 deletions(-)

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
index a567bc2..33968ab 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
@@ -2033,7 +2033,7 @@ static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev,
 	u16 eeprom;
 	short lna_gain;
 
-	if (libconf->rf.channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		eeprom = rt2800_eeprom_read(rt2x00dev, EEPROM_LNA);
 		lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
 	} else if (libconf->rf.channel <= 64) {
@@ -2122,7 +2122,7 @@ static void rt2800_config_channel_rf2xxx(struct rt2x00_dev *rt2x00dev,
 	} else if (rt2x00dev->default_ant.rx_chain_num == 2)
 		rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
 
-	if (rf->channel > 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
 		/*
 		 * When TX power is below 0, we should increase it by 7 to
 		 * make it a positive value (Minimum value is -7).
@@ -2271,21 +2271,21 @@ static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev,
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 6);
 	rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2);
-	if (rf->channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 2);
 	else
 		rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 1);
 	rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 5);
-	if (rf->channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		rt2x00_set_field8(&rfcsr, RFCSR5_R1, 1);
 	else
 		rt2x00_set_field8(&rfcsr, RFCSR5_R1, 2);
 	rt2800_rfcsr_write(rt2x00dev, 5, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 12);
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 3);
 		rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
 				  info->default_power1);
@@ -2298,7 +2298,7 @@ static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev,
 	rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 13);
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 3);
 		rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER,
 				  info->default_power2);
@@ -2318,7 +2318,7 @@ static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev,
 	rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
 	rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
 	if (rt2x00_has_cap_bt_coexist(rt2x00dev)) {
-		if (rf->channel <= 14) {
+		if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 			rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
 			rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
 		}
@@ -2355,7 +2355,7 @@ static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev,
 		rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw20);
 	}
 
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rt2800_rfcsr_write(rt2x00dev, 7, 0xd8);
 		rt2800_rfcsr_write(rt2x00dev, 9, 0xc3);
 		rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
@@ -2408,7 +2408,7 @@ static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev,
 
 	reg = rt2800_register_read(rt2x00dev, GPIO_CTRL);
 	rt2x00_set_field32(&reg, GPIO_CTRL_DIR7, 0);
-	if (rf->channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		rt2x00_set_field32(&reg, GPIO_CTRL_VAL7, 1);
 	else
 		rt2x00_set_field32(&reg, GPIO_CTRL_VAL7, 0);
@@ -2441,7 +2441,7 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 	rt2x00_set_field8(&bbp, BBP110_TX2_POWER, 0);
 	rt2800_bbp_write(rt2x00dev, 110, bbp);
 
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		/* Restore BBP 25 & 26 for 2.4 GHz */
 		rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25);
 		rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26);
@@ -2463,14 +2463,14 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 11);
 	rt2x00_set_field8(&rfcsr, RFCSR11_PLL_IDOH, 1);
-	if (rf->channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		rt2x00_set_field8(&rfcsr, RFCSR11_PLL_MOD, 1);
 	else
 		rt2x00_set_field8(&rfcsr, RFCSR11_PLL_MOD, 2);
 	rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 53);
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rfcsr = 0;
 		rt2x00_set_field8(&rfcsr, RFCSR53_TX_POWER,
 				  info->default_power1 & 0x1f);
@@ -2485,7 +2485,7 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 	rt2800_rfcsr_write(rt2x00dev, 53, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 55);
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rfcsr = 0;
 		rt2x00_set_field8(&rfcsr, RFCSR55_TX_POWER,
 				  info->default_power2 & 0x1f);
@@ -2500,7 +2500,7 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 	rt2800_rfcsr_write(rt2x00dev, 55, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 54);
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rfcsr = 0;
 		rt2x00_set_field8(&rfcsr, RFCSR54_TX_POWER,
 				  info->default_power3 & 0x1f);
@@ -2569,7 +2569,7 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 32);
 	rt2x00_set_field8(&rfcsr, RFCSR32_TX_AGC_FC, txrx_agc_fc);
 
-	if (rf->channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		rfcsr = 0xa0;
 	else
 		rfcsr = 0x80;
@@ -2582,28 +2582,28 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 
 	/* Band selection */
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 36);
-	if (rf->channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 1);
 	else
 		rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 0);
 	rt2800_rfcsr_write(rt2x00dev, 36, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 34);
-	if (rf->channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		rfcsr = 0x3c;
 	else
 		rfcsr = 0x20;
 	rt2800_rfcsr_write(rt2x00dev, 34, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 12);
-	if (rf->channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		rfcsr = 0x1a;
 	else
 		rfcsr = 0x12;
 	rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 6);
-	if (rf->channel >= 1 && rf->channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 1);
 	else if (rf->channel >= 36 && rf->channel <= 64)
 		rt2x00_set_field8(&rfcsr, RFCSR6_VCO_IC, 2);
@@ -2619,7 +2619,7 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 
 	rt2800_rfcsr_write(rt2x00dev, 46, 0x60);
 
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rt2800_rfcsr_write(rt2x00dev, 10, 0xd3);
 		rt2800_rfcsr_write(rt2x00dev, 13, 0x12);
 	} else {
@@ -2632,7 +2632,7 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 	rt2800_rfcsr_write(rt2x00dev, 51, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 51);
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rt2x00_set_field8(&rfcsr, RFCSR51_BITS24, 5);
 		rt2x00_set_field8(&rfcsr, RFCSR51_BITS57, 3);
 	} else {
@@ -2642,7 +2642,7 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 	rt2800_rfcsr_write(rt2x00dev, 51, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 49);
-	if (rf->channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		rt2x00_set_field8(&rfcsr, RFCSR49_TX_LO1_IC, 3);
 	else
 		rt2x00_set_field8(&rfcsr, RFCSR49_TX_LO1_IC, 2);
@@ -2657,13 +2657,13 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 	rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
 
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 57);
-	if (rf->channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		rt2x00_set_field8(&rfcsr, RFCSR57_DRV_CC, 0x1b);
 	else
 		rt2x00_set_field8(&rfcsr, RFCSR57_DRV_CC, 0x0f);
 	rt2800_rfcsr_write(rt2x00dev, 57, rfcsr);
 
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rt2800_rfcsr_write(rt2x00dev, 44, 0x93);
 		rt2800_rfcsr_write(rt2x00dev, 52, 0x45);
 	} else {
@@ -2673,7 +2673,7 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 
 	/* Initiate VCO calibration */
 	rfcsr = rt2800_rfcsr_read(rt2x00dev, 3);
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
 	} else {
 		rt2x00_set_field8(&rfcsr, RFCSR3_BIT1, 1);
@@ -2685,7 +2685,7 @@ static void rt2800_config_channel_rf3053(struct rt2x00_dev *rt2x00dev,
 	}
 	rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
 
-	if (rf->channel >= 1 && rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rfcsr = 0x23;
 		if (txbf_enabled)
 			rt2x00_set_field8(&rfcsr, RFCSR39_RX_DIV, 1);
@@ -2741,7 +2741,7 @@ static void rt2800_config_channel_rf3290(struct rt2x00_dev *rt2x00dev,
 
 	rt2800_freq_cal_mode1(rt2x00dev);
 
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		if (rf->channel == 6)
 			rt2800_bbp_write(rt2x00dev, 68, 0x0c);
 		else
@@ -2786,12 +2786,12 @@ static void rt2800_config_channel_rf3322(struct rt2x00_dev *rt2x00dev,
 	rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
 	rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
 
-	if ( rt2x00dev->default_ant.tx_chain_num == 2 )
+	if (rt2x00dev->default_ant.tx_chain_num == 2)
 		rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
 	else
 		rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
 
-	if ( rt2x00dev->default_ant.rx_chain_num == 2 )
+	if (rt2x00dev->default_ant.rx_chain_num == 2)
 		rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
 	else
 		rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
@@ -2920,7 +2920,8 @@ static void rt2800_config_channel_rf55xx(struct rt2x00_dev *rt2x00dev,
 
 	reg = rt2800_register_read(rt2x00dev, LDO_CFG0);
 	rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL,
-			   (rf->channel > 14 || conf_is_ht40(conf)) ? 5 : 0);
+			   (rt2x00dev->curr_band == NL80211_BAND_5GHZ ||
+			   			conf_is_ht40(conf)) ? 5 : 0);
 	rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
 
 	/* Order of values on rf_channel entry: N, K, mod, R */
@@ -2937,7 +2938,7 @@ static void rt2800_config_channel_rf55xx(struct rt2x00_dev *rt2x00dev,
 	rt2x00_set_field8(&rfcsr, RFCSR11_MOD, (rf->rf3 - 8) & 0x3);
 	rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
 
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		rt2800_rfcsr_write(rt2x00dev, 10, 0x90);
 		/* FIXME: RF11 owerwrite ? */
 		rt2800_rfcsr_write(rt2x00dev, 11, 0x4A);
@@ -3160,24 +3161,34 @@ static void rt2800_config_channel_rf55xx(struct rt2x00_dev *rt2x00dev,
 	rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
 	rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
 
-	rt2800_bbp_write(rt2x00dev, 79, (rf->channel <= 14) ? 0x1C : 0x18);
-	rt2800_bbp_write(rt2x00dev, 80, (rf->channel <= 14) ? 0x0E : 0x08);
-	rt2800_bbp_write(rt2x00dev, 81, (rf->channel <= 14) ? 0x3A : 0x38);
-	rt2800_bbp_write(rt2x00dev, 82, (rf->channel <= 14) ? 0x62 : 0x92);
+	rt2800_bbp_write(rt2x00dev, 79, (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
+								? 0x1C : 0x18);
+	rt2800_bbp_write(rt2x00dev, 80, (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
+								? 0x0E : 0x08);
+	rt2800_bbp_write(rt2x00dev, 81, (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
+								? 0x3A : 0x38);
+	rt2800_bbp_write(rt2x00dev, 82, (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
+								? 0x62 : 0x92);
 
 	/* GLRT band configuration */
 	rt2800_bbp_write(rt2x00dev, 195, 128);
-	rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0xE0 : 0xF0);
+	rt2800_bbp_write(rt2x00dev, 196, (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
+								? 0xE0 : 0xF0);
 	rt2800_bbp_write(rt2x00dev, 195, 129);
-	rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x1F : 0x1E);
+	rt2800_bbp_write(rt2x00dev, 196, (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
+								? 0x1F : 0x1E);
 	rt2800_bbp_write(rt2x00dev, 195, 130);
-	rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x38 : 0x28);
+	rt2800_bbp_write(rt2x00dev, 196, (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
+								? 0x38 : 0x28);
 	rt2800_bbp_write(rt2x00dev, 195, 131);
-	rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x32 : 0x20);
+	rt2800_bbp_write(rt2x00dev, 196, (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
+								? 0x32 : 0x20);
 	rt2800_bbp_write(rt2x00dev, 195, 133);
-	rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x28 : 0x7F);
+	rt2800_bbp_write(rt2x00dev, 196, (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
+								? 0x28 : 0x7F);
 	rt2800_bbp_write(rt2x00dev, 195, 124);
-	rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x19 : 0x7F);
+	rt2800_bbp_write(rt2x00dev, 196, (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
+								? 0x19 : 0x7F);
 }
 
 static void rt2800_config_channel_rf7620(struct rt2x00_dev *rt2x00dev,
@@ -3438,7 +3449,7 @@ static void rt2800_iq_calibrate(struct rt2x00_dev *rt2x00dev, int channel)
 
 	/* TX0 IQ Gain */
 	rt2800_bbp_write(rt2x00dev, 158, 0x2c);
-	if (channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX0_2G);
 	else if (channel >= 36 && channel <= 64)
 		cal = rt2x00_eeprom_byte(rt2x00dev,
@@ -3455,7 +3466,7 @@ static void rt2800_iq_calibrate(struct rt2x00_dev *rt2x00dev, int channel)
 
 	/* TX0 IQ Phase */
 	rt2800_bbp_write(rt2x00dev, 158, 0x2d);
-	if (channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX0_2G);
 	else if (channel >= 36 && channel <= 64)
 		cal = rt2x00_eeprom_byte(rt2x00dev,
@@ -3472,7 +3483,7 @@ static void rt2800_iq_calibrate(struct rt2x00_dev *rt2x00dev, int channel)
 
 	/* TX1 IQ Gain */
 	rt2800_bbp_write(rt2x00dev, 158, 0x4a);
-	if (channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX1_2G);
 	else if (channel >= 36 && channel <= 64)
 		cal = rt2x00_eeprom_byte(rt2x00dev,
@@ -3489,7 +3500,7 @@ static void rt2800_iq_calibrate(struct rt2x00_dev *rt2x00dev, int channel)
 
 	/* TX1 IQ Phase */
 	rt2800_bbp_write(rt2x00dev, 158, 0x4b);
-	if (channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX1_2G);
 	else if (channel >= 36 && channel <= 64)
 		cal = rt2x00_eeprom_byte(rt2x00dev,
@@ -3525,7 +3536,7 @@ static char rt2800_txpower_to_dev(struct rt2x00_dev *rt2x00dev,
 	if (rt2x00_rt(rt2x00dev, RT3593))
 		txpower = rt2x00_get_field8(txpower, EEPROM_TXPOWER_ALC);
 
-	if (channel <= 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 		return clamp_t(char, txpower, MIN_G_TXPOWER, MAX_G_TXPOWER);
 
 	if (rt2x00_rt(rt2x00dev, RT3593))
@@ -3638,7 +3649,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
 		rt2800_bbp_write(rt2x00dev, 86, 0x38);
 		rt2800_bbp_write(rt2x00dev, 83, 0x6a);
 	} else if (rt2x00_rt(rt2x00dev, RT3593)) {
-		if (rf->channel > 14) {
+		if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
 			/* Disable CCK Packet detection on 5GHz */
 			rt2800_bbp_write(rt2x00dev, 70, 0x00);
 		} else {
@@ -3661,7 +3672,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
 		rt2800_bbp_write(rt2x00dev, 86, 0);
 	}
 
-	if (rf->channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		if (!rt2x00_rt(rt2x00dev, RT5390) &&
 		    !rt2x00_rt(rt2x00dev, RT5392) &&
 		    !rt2x00_rt(rt2x00dev, RT6352)) {
@@ -3698,8 +3709,10 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
 
 	reg = rt2800_register_read(rt2x00dev, TX_BAND_CFG);
 	rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_MINUS, conf_is_ht40_minus(conf));
-	rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
-	rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
+	rt2x00_set_field32(&reg, TX_BAND_CFG_A, rt2x00dev->curr_band ==
+							NL80211_BAND_5GHZ);
+	rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rt2x00dev->curr_band ==
+							NL80211_BAND_2GHZ);
 	rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg);
 
 	if (rt2x00_rt(rt2x00dev, RT3572))
@@ -3765,7 +3778,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
 		rt2800_rfcsr_write(rt2x00dev, 8, 0x80);
 
 		/* AGC init */
-		if (rf->channel <= 14)
+		if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 			reg = 0x1c + (2 * rt2x00dev->lna_gain);
 		else
 			reg = 0x22 + ((rt2x00dev->lna_gain * 5) / 3);
@@ -3781,7 +3794,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
 		    rt2x00_is_pcie(rt2x00dev)) {
 			/* GPIO #8 controls all paths */
 			rt2x00_set_field32(&reg, GPIO_CTRL_DIR8, 0);
-			if (rf->channel <= 14)
+			if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 				rt2x00_set_field32(&reg, GPIO_CTRL_VAL8, 1);
 			else
 				rt2x00_set_field32(&reg, GPIO_CTRL_VAL8, 0);
@@ -3806,7 +3819,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
 		rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
 
 		/* AGC init */
-		if (rf->channel <= 14)
+		if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
 			reg = 0x1c + 2 * rt2x00dev->lna_gain;
 		else
 			reg = 0x22 + ((rt2x00dev->lna_gain * 5) / 3);
@@ -3833,7 +3846,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
 		if (rt2x00_rt(rt2x00dev, RT6352))
 			reg = 0x04;
 		else
-			reg = rf->channel <= 14 ? 0x1c : 0x24;
+			reg = rt2x00dev->curr_band == NL80211_BAND_2GHZ ? 0x1c : 0x24;
 
 		reg += 2 * rt2x00dev->lna_gain;
 		rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
@@ -4915,7 +4928,7 @@ void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
 		usleep_range(min_sleep, min_sleep * 2);
 
 	tx_pin = rt2800_register_read(rt2x00dev, TX_PIN_CFG);
-	if (rt2x00dev->rf_channel <= 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ) {
 		switch (rt2x00dev->default_ant.tx_chain_num) {
 		case 3:
 			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, 1);
@@ -9265,8 +9278,9 @@ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
 	if (WARN_ON_ONCE(!spec->channels))
 		return -ENODEV;
 
-	spec->supported_bands = SUPPORT_BAND_2GHZ;
-	if (spec->num_channels > 14)
+	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
+		spec->supported_bands = SUPPORT_BAND_2GHZ;
+	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ)
 		spec->supported_bands |= SUPPORT_BAND_5GHZ;
 
 	/*
@@ -9336,7 +9350,7 @@ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
 			info[i].default_power3 = default_power3[i];
 	}
 
-	if (spec->num_channels > 14) {
+	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
 		default_power1 = rt2800_eeprom_addr(rt2x00dev,
 						    EEPROM_TXPOWER_A1);
 		default_power2 = rt2800_eeprom_addr(rt2x00dev,
-- 
1.7.0.4

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

* [PATCH 2/5] rt2x00: rework channel config function
  2018-09-17 16:32 [PATCH 1/5] rt2x00: set registers based on current band Tomislav Požega
@ 2018-09-17 16:32 ` Tomislav Požega
  2018-09-18 12:22   ` Stanislaw Gruszka
  2018-10-09 10:57   ` Stanislaw Gruszka
  2018-09-17 16:32 ` [PATCH 3/5] rt2x00: remove unneeded check Tomislav Požega
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 17+ messages in thread
From: Tomislav Požega @ 2018-09-17 16:32 UTC (permalink / raw)
  To: linux-wireless

Enable LNAs only for the current operating band. Change power
amplifiers enabling style to the one in vco calibration routine
and drop redundant cap_bt_coexist enable of PA0.

Signed-off-by: Tomislav Požega <pozega.tomislav@gmail.com>
---
 drivers/net/wireless/ralink/rt2x00/rt2800lib.c |   75 ++++++++++++------------
 1 files changed, 37 insertions(+), 38 deletions(-)

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
index 33968ab..5546bd8 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
@@ -3723,49 +3723,48 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
 	else
 		tx_pin = 0;
 
-	switch (rt2x00dev->default_ant.tx_chain_num) {
-	case 3:
-		/* Turn on tertiary PAs */
-		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN,
-				   rf->channel > 14);
-		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN,
-				   rf->channel <= 14);
-		/* fall-through */
-	case 2:
-		/* Turn on secondary PAs */
-		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN,
-				   rf->channel > 14);
-		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN,
-				   rf->channel <= 14);
-		/* fall-through */
-	case 1:
-		/* Turn on primary PAs */
-		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN,
-				   rf->channel > 14);
-		if (rt2x00_has_cap_bt_coexist(rt2x00dev))
+	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
+		switch (rt2x00dev->default_ant.tx_chain_num) {
+		case 3:
+			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, 1);
+		case 2:
+			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
+		case 1:
+			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1);
+		break;
+		}
+	} else {
+		switch (rt2x00dev->default_ant.tx_chain_num) {
+		case 3:
+			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, 1);
+		case 2:
+			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
+		case 1:
 			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
-		else
-			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN,
-					   rf->channel <= 14);
 		break;
+		}
 	}
 
-	switch (rt2x00dev->default_ant.rx_chain_num) {
-	case 3:
-		/* Turn on tertiary LNAs */
-		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A2_EN, 1);
-		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G2_EN, 1);
-		/* fall-through */
-	case 2:
-		/* Turn on secondary LNAs */
-		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
-		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
-		/* fall-through */
-	case 1:
-		/* Turn on primary LNAs */
-		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
-		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
+	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
+		switch (rt2x00dev->default_ant.rx_chain_num) {
+		case 3:
+			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A2_EN, 1);
+		case 2:
+			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
+		case 1:
+			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
+		break;
+		}
+	} else {
+		switch (rt2x00dev->default_ant.rx_chain_num) {
+		case 3:
+			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G2_EN, 1);
+		case 2:
+			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
+		case 1:
+			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
 		break;
+		}
 	}
 
 	rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
-- 
1.7.0.4

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

* [PATCH 3/5] rt2x00: remove unneeded check
  2018-09-17 16:32 [PATCH 1/5] rt2x00: set registers based on current band Tomislav Požega
  2018-09-17 16:32 ` [PATCH 2/5] rt2x00: rework channel config function Tomislav Požega
@ 2018-09-17 16:32 ` Tomislav Požega
  2018-09-17 16:32 ` [PATCH 4/5] rt2x00: remove confusing AGC register Tomislav Požega
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 17+ messages in thread
From: Tomislav Požega @ 2018-09-17 16:32 UTC (permalink / raw)
  To: linux-wireless

Remove band check from rf53xx channel config routine since all chips
using it are single band.

Signed-off-by: Tomislav Požega <pozega.tomislav@gmail.com>
---
 drivers/net/wireless/ralink/rt2x00/rt2800lib.c |  103 ++++++++++++------------
 1 files changed, 50 insertions(+), 53 deletions(-)

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
index 5546bd8..a47bbb6 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
@@ -2809,6 +2809,7 @@ static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev,
 					 struct rf_channel *rf,
 					 struct channel_info *info)
 {
+	int idx = rf->channel-1;
 	u8 rfcsr;
 
 	rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
@@ -2847,60 +2848,56 @@ static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev,
 
 	rt2800_freq_cal_mode1(rt2x00dev);
 
-	if (rf->channel <= 14) {
-		int idx = rf->channel-1;
-
-		if (rt2x00_has_cap_bt_coexist(rt2x00dev)) {
-			if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
-				/* r55/r59 value array of channel 1~14 */
-				static const char r55_bt_rev[] = {0x83, 0x83,
-					0x83, 0x73, 0x73, 0x63, 0x53, 0x53,
-					0x53, 0x43, 0x43, 0x43, 0x43, 0x43};
-				static const char r59_bt_rev[] = {0x0e, 0x0e,
-					0x0e, 0x0e, 0x0e, 0x0b, 0x0a, 0x09,
-					0x07, 0x07, 0x07, 0x07, 0x07, 0x07};
-
-				rt2800_rfcsr_write(rt2x00dev, 55,
-						   r55_bt_rev[idx]);
-				rt2800_rfcsr_write(rt2x00dev, 59,
-						   r59_bt_rev[idx]);
-			} else {
-				static const char r59_bt[] = {0x8b, 0x8b, 0x8b,
-					0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x89,
-					0x88, 0x88, 0x86, 0x85, 0x84};
-
-				rt2800_rfcsr_write(rt2x00dev, 59, r59_bt[idx]);
-			}
+	if (rt2x00_has_cap_bt_coexist(rt2x00dev)) {
+		if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
+			/* r55/r59 value array of channel 1~14 */
+			static const char r55_bt_rev[] = {0x83, 0x83,
+				0x83, 0x73, 0x73, 0x63, 0x53, 0x53,
+				0x53, 0x43, 0x43, 0x43, 0x43, 0x43};
+			static const char r59_bt_rev[] = {0x0e, 0x0e,
+				0x0e, 0x0e, 0x0e, 0x0b, 0x0a, 0x09,
+				0x07, 0x07, 0x07, 0x07, 0x07, 0x07};
+
+			rt2800_rfcsr_write(rt2x00dev, 55,
+					   r55_bt_rev[idx]);
+			rt2800_rfcsr_write(rt2x00dev, 59,
+					   r59_bt_rev[idx]);
 		} else {
-			if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
-				static const char r55_nonbt_rev[] = {0x23, 0x23,
-					0x23, 0x23, 0x13, 0x13, 0x03, 0x03,
-					0x03, 0x03, 0x03, 0x03, 0x03, 0x03};
-				static const char r59_nonbt_rev[] = {0x07, 0x07,
-					0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
-					0x07, 0x07, 0x06, 0x05, 0x04, 0x04};
-
-				rt2800_rfcsr_write(rt2x00dev, 55,
-						   r55_nonbt_rev[idx]);
-				rt2800_rfcsr_write(rt2x00dev, 59,
-						   r59_nonbt_rev[idx]);
-			} else if (rt2x00_rt(rt2x00dev, RT5390) ||
-				   rt2x00_rt(rt2x00dev, RT5392) ||
-				   rt2x00_rt(rt2x00dev, RT6352)) {
-				static const char r59_non_bt[] = {0x8f, 0x8f,
-					0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d,
-					0x8a, 0x88, 0x88, 0x87, 0x87, 0x86};
-
-				rt2800_rfcsr_write(rt2x00dev, 59,
-						   r59_non_bt[idx]);
-			} else if (rt2x00_rt(rt2x00dev, RT5350)) {
-				static const char r59_non_bt[] = {0x0b, 0x0b,
-					0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0a,
-					0x0a, 0x09, 0x08, 0x07, 0x07, 0x06};
-
-				rt2800_rfcsr_write(rt2x00dev, 59,
-						   r59_non_bt[idx]);
-			}
+			static const char r59_bt[] = {0x8b, 0x8b, 0x8b,
+				0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x89,
+				0x88, 0x88, 0x86, 0x85, 0x84};
+
+			rt2800_rfcsr_write(rt2x00dev, 59, r59_bt[idx]);
+		}
+	} else {
+		if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
+			static const char r55_nonbt_rev[] = {0x23, 0x23,
+				0x23, 0x23, 0x13, 0x13, 0x03, 0x03,
+				0x03, 0x03, 0x03, 0x03, 0x03, 0x03};
+			static const char r59_nonbt_rev[] = {0x07, 0x07,
+				0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
+				0x07, 0x07, 0x06, 0x05, 0x04, 0x04};
+
+			rt2800_rfcsr_write(rt2x00dev, 55,
+					   r55_nonbt_rev[idx]);
+			rt2800_rfcsr_write(rt2x00dev, 59,
+					   r59_nonbt_rev[idx]);
+		} else if (rt2x00_rt(rt2x00dev, RT5390) ||
+			   rt2x00_rt(rt2x00dev, RT5392) ||
+			   rt2x00_rt(rt2x00dev, RT6352)) {
+			static const char r59_non_bt[] = {0x8f, 0x8f,
+				0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d,
+				0x8a, 0x88, 0x88, 0x87, 0x87, 0x86};
+
+			rt2800_rfcsr_write(rt2x00dev, 59,
+					   r59_non_bt[idx]);
+		} else if (rt2x00_rt(rt2x00dev, RT5350)) {
+			static const char r59_non_bt[] = {0x0b, 0x0b,
+				0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0a,
+				0x0a, 0x09, 0x08, 0x07, 0x07, 0x06};
+
+			rt2800_rfcsr_write(rt2x00dev, 59,
+					   r59_non_bt[idx]);
 		}
 	}
 }
-- 
1.7.0.4

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

* [PATCH 4/5] rt2x00: remove confusing AGC register
  2018-09-17 16:32 [PATCH 1/5] rt2x00: set registers based on current band Tomislav Požega
  2018-09-17 16:32 ` [PATCH 2/5] rt2x00: rework channel config function Tomislav Požega
  2018-09-17 16:32 ` [PATCH 3/5] rt2x00: remove unneeded check Tomislav Požega
@ 2018-09-17 16:32 ` Tomislav Požega
  2018-09-17 16:32 ` [PATCH 5/5] rt2x00: update TX_SW_CFG2 value Tomislav Požega
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 17+ messages in thread
From: Tomislav Požega @ 2018-09-17 16:32 UTC (permalink / raw)
  To: linux-wireless

Register 66 was causing issues on RT6352 if set to the same value as
in MTK driver. With 1c reg value device was working fine in both HT20
and HT40 modes.

Signed-off-by: Tomislav Požega <pozega.tomislav@gmail.com>
---
 drivers/net/wireless/ralink/rt2x00/rt2800lib.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
index a47bbb6..a5eb17a 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
@@ -3839,10 +3839,7 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
 		rt2800_bbp_write(rt2x00dev, 196, reg);
 
 		/* AGC init */
-		if (rt2x00_rt(rt2x00dev, RT6352))
-			reg = 0x04;
-		else
-			reg = rt2x00dev->curr_band == NL80211_BAND_2GHZ ? 0x1c : 0x24;
+		reg = rt2x00dev->curr_band == NL80211_BAND_2GHZ ? 0x1c : 0x24;
 
 		reg += 2 * rt2x00dev->lna_gain;
 		rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
-- 
1.7.0.4

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

* [PATCH 5/5] rt2x00: update TX_SW_CFG2 value
  2018-09-17 16:32 [PATCH 1/5] rt2x00: set registers based on current band Tomislav Požega
                   ` (2 preceding siblings ...)
  2018-09-17 16:32 ` [PATCH 4/5] rt2x00: remove confusing AGC register Tomislav Požega
@ 2018-09-17 16:32 ` Tomislav Požega
  2018-09-18 12:20 ` [PATCH 1/5] rt2x00: set registers based on current band Stanislaw Gruszka
  2018-10-09 11:00 ` Stanislaw Gruszka
  5 siblings, 0 replies; 17+ messages in thread
From: Tomislav Požega @ 2018-09-17 16:32 UTC (permalink / raw)
  To: linux-wireless

Use default value of TX_SW_CFG2 register that is in charge
of LNA timings. Works for somewhat higher RX throughput.

Signed-off-by: Tomislav Požega <pozega.tomislav@gmail.com>
---
 drivers/net/wireless/ralink/rt2x00/rt2800lib.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
index a5eb17a..c5d0fb1 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
@@ -5324,7 +5324,7 @@ static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
 	} else if (rt2x00_rt(rt2x00dev, RT6352)) {
 		rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000401);
 		rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x000C0000);
-		rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
+		rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x000C0408);
 		rt2800_register_write(rt2x00dev, MIMO_PS_CFG, 0x00000002);
 		rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0x00150F0F);
 		rt2800_register_write(rt2x00dev, TX_ALC_VGA3, 0x06060606);
-- 
1.7.0.4

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

* Re: [PATCH 1/5] rt2x00: set registers based on current band
  2018-09-17 16:32 [PATCH 1/5] rt2x00: set registers based on current band Tomislav Požega
                   ` (3 preceding siblings ...)
  2018-09-17 16:32 ` [PATCH 5/5] rt2x00: update TX_SW_CFG2 value Tomislav Požega
@ 2018-09-18 12:20 ` Stanislaw Gruszka
  2018-09-18 14:14   ` Tomislav Požega
  2018-10-09 11:00 ` Stanislaw Gruszka
  5 siblings, 1 reply; 17+ messages in thread
From: Stanislaw Gruszka @ 2018-09-18 12:20 UTC (permalink / raw)
  To: Tomislav Požega; +Cc: linux-wireless

On Mon, Sep 17, 2018 at 06:32:51PM +0200, Tomislav Požega wrote:
> Use curr_band instead of rf->channel among various subroutines -
> mostly for 2.4GHz band but in some circumstances for 5GHz band too.

What is the reason for that change ?

> @@ -9265,8 +9278,9 @@ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
>  	if (WARN_ON_ONCE(!spec->channels))
>  		return -ENODEV;
>  
> -	spec->supported_bands = SUPPORT_BAND_2GHZ;
> -	if (spec->num_channels > 14)
> +	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
> +		spec->supported_bands = SUPPORT_BAND_2GHZ;
> +	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ)
>  		spec->supported_bands |= SUPPORT_BAND_5GHZ;
>  
>  	/*
> @@ -9336,7 +9350,7 @@ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
>  			info[i].default_power3 = default_power3[i];
>  	}
>  
> -	if (spec->num_channels > 14) {
> +	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
>  		default_power1 = rt2800_eeprom_addr(rt2x00dev,
>  						    EEPROM_TXPOWER_A1);
>  		default_power2 = rt2800_eeprom_addr(rt2x00dev,

Above looks wrong.

Thanks
Stanislaw

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

* Re: [PATCH 2/5] rt2x00: rework channel config function
  2018-09-17 16:32 ` [PATCH 2/5] rt2x00: rework channel config function Tomislav Požega
@ 2018-09-18 12:22   ` Stanislaw Gruszka
  2018-10-09 10:57   ` Stanislaw Gruszka
  1 sibling, 0 replies; 17+ messages in thread
From: Stanislaw Gruszka @ 2018-09-18 12:22 UTC (permalink / raw)
  To: Tomislav Požega; +Cc: linux-wireless

On Mon, Sep 17, 2018 at 06:32:52PM +0200, Tomislav Požega wrote:
> -	switch (rt2x00dev->default_ant.tx_chain_num) {
> -	case 3:
> -		/* Turn on tertiary PAs */
> -		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN,
> -				   rf->channel > 14);
> -		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN,
> -				   rf->channel <= 14);
> -		/* fall-through */
> -	case 2:
> -		/* Turn on secondary PAs */
> -		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN,
> -				   rf->channel > 14);
> -		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN,
> -				   rf->channel <= 14);
> -		/* fall-through */
> -	case 1:
> -		/* Turn on primary PAs */
> -		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN,
> -				   rf->channel > 14);
> -		if (rt2x00_has_cap_bt_coexist(rt2x00dev))
> +	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
> +		switch (rt2x00dev->default_ant.tx_chain_num) {
> +		case 3:
> +			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, 1);
> +		case 2:
> +			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
> +		case 1:
> +			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1);
> +		break;

Please keep /* fall-through */ comments, this is needed 
for some automatic code checkers tools.

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

* Re: [PATCH 1/5] rt2x00: set registers based on current band
  2018-09-18 12:20 ` [PATCH 1/5] rt2x00: set registers based on current band Stanislaw Gruszka
@ 2018-09-18 14:14   ` Tomislav Požega
  2018-09-19 11:05     ` Stanislaw Gruszka
  0 siblings, 1 reply; 17+ messages in thread
From: Tomislav Požega @ 2018-09-18 14:14 UTC (permalink / raw)
  To: sgruszka; +Cc: linux-wireless

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1509 bytes --]

On Tue, 18 Sep 2018 14:20:16 +0200, Stanislaw Gruszka wrote:

>On Mon, Sep 17, 2018 at 06:32:51PM +0200, Tomislav Požega wrote:
>> Use curr_band instead of rf->channel among various subroutines -
>> mostly for 2.4GHz band but in some circumstances for 5GHz band too.
>
>What is the reason for that change ?

Operating band should be fetched from device capabilities, not from userspace
variables. More changes will needed to be made to accomplish that.

>
>> @@ -9265,8 +9278,9 @@ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
>>  	if (WARN_ON_ONCE(!spec->channels))
>>  		return -ENODEV;
>>  
>> -	spec->supported_bands = SUPPORT_BAND_2GHZ;
>> -	if (spec->num_channels > 14)
>> +	if (rt2x00dev->curr_band == NL80211_BAND_2GHZ)
>> +		spec->supported_bands = SUPPORT_BAND_2GHZ;
>> +	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ)
>>  		spec->supported_bands |= SUPPORT_BAND_5GHZ;
>>  
>>  	/*
>> @@ -9336,7 +9350,7 @@ static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
>>  			info[i].default_power3 = default_power3[i];
>>  	}
>>  
>> -	if (spec->num_channels > 14) {
>> +	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
>>  		default_power1 = rt2800_eeprom_addr(rt2x00dev,
>>  						    EEPROM_TXPOWER_A1);
>>  		default_power2 = rt2800_eeprom_addr(rt2x00dev,
>
>Above looks wrong.
>
>Thanks
>Stanislaw

Worked fine when I tried run two USB cards (RT3070-RF0005, RT5390-RF5370).
Why do you think it's wrong? Is there a dual-band card that operates on
both bands at the same time?

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

* Re: [PATCH 1/5] rt2x00: set registers based on current band
  2018-09-18 14:14   ` Tomislav Požega
@ 2018-09-19 11:05     ` Stanislaw Gruszka
  2018-09-19 12:17       ` Tomislav Požega
  0 siblings, 1 reply; 17+ messages in thread
From: Stanislaw Gruszka @ 2018-09-19 11:05 UTC (permalink / raw)
  To: Tomislav Požega; +Cc: linux-wireless

On Tue, Sep 18, 2018 at 04:14:33PM +0200, Tomislav Požega wrote:
> On Tue, 18 Sep 2018 14:20:16 +0200, Stanislaw Gruszka wrote:
> 
> >On Mon, Sep 17, 2018 at 06:32:51PM +0200, Tomislav Požega wrote:
> >> Use curr_band instead of rf->channel among various subroutines -
> >> mostly for 2.4GHz band but in some circumstances for 5GHz band too.
> >
> >What is the reason for that change ?
> 
> Operating band should be fetched from device capabilities, not from userspace
> variables. More changes will needed to be made to accomplish that.

Driver should provide on what channels are supported to mac80211, but
user space decide what channel to use and that imply band 2.4GHz or
5GHz. ->curr_band is just shortcut for band of current channel. Is set 
in rt2x00lib_config() after we call rt2x00dev->ops->lib->config()
[rt2800_config() for rt2800] . So patch is wrong. Either ->curr_band 
should be set before ->config call or we need to consistently use
rf->channel <= 14 for band check in any rt2800_config() function and
all it's subroutines. I prefer the second solution (i.e. rf->channel)
and now I can see few places when we use ->curr_band, what is a bug.

> >> -	if (spec->num_channels > 14) {
> >> +	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
> >>  		default_power1 = rt2800_eeprom_addr(rt2x00dev,
> >>  						    EEPROM_TXPOWER_A1);
> >>  		default_power2 = rt2800_eeprom_addr(rt2x00dev,
> >
> >Above looks wrong.
> >
> >Thanks
> >Stanislaw
> 
> Worked fine when I tried run two USB cards (RT3070-RF0005, RT5390-RF5370).
> Why do you think it's wrong? Is there a dual-band card that operates on
> both bands at the same time?

It's because ->curr_band initialize to 0 and NL80211_BAND_2GHZ
happen to be 0. Also problem will not trigger on single band
2.4GHz devices.

Regards
Stanislaw

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

* Re: [PATCH 1/5] rt2x00: set registers based on current band
  2018-09-19 11:05     ` Stanislaw Gruszka
@ 2018-09-19 12:17       ` Tomislav Požega
  2018-09-19 12:47         ` Stanislaw Gruszka
  0 siblings, 1 reply; 17+ messages in thread
From: Tomislav Požega @ 2018-09-19 12:17 UTC (permalink / raw)
  To: sgruszka; +Cc: linux-wireless

On Wed, 19 Sep 2018 13:05:41 +0200, Stanislaw Gruszka wrote:

>Driver should provide on what channels are supported to mac80211, but
>user space decide what channel to use and that imply band 2.4GHz or
>5GHz. ->curr_band is just shortcut for band of current channel. Is set 
>in rt2x00lib_config() after we call rt2x00dev->ops->lib->config()
>[rt2800_config() for rt2800] . So patch is wrong. Either ->curr_band 
>should be set before ->config call or we need to consistently use
>rf->channel <= 14 for band check in any rt2800_config() function and
>all it's subroutines. I prefer the second solution (i.e. rf->channel)
>and now I can see few places when we use ->curr_band, what is a bug.

Works fine, no any kind of regression, especially not performance ones.
So I don't see a reason to claim it is wrong or bug just because you
prefer current solution.

>It's because ->curr_band initialize to 0 and NL80211_BAND_2GHZ
>happen to be 0. Also problem will not trigger on single band
>2.4GHz devices.

Can you show us how will the problem trigger on dual band devices?

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

* Re: [PATCH 1/5] rt2x00: set registers based on current band
  2018-09-19 12:17       ` Tomislav Požega
@ 2018-09-19 12:47         ` Stanislaw Gruszka
  2018-09-19 13:04           ` Stanislaw Gruszka
  0 siblings, 1 reply; 17+ messages in thread
From: Stanislaw Gruszka @ 2018-09-19 12:47 UTC (permalink / raw)
  To: Tomislav Požega; +Cc: linux-wireless

On Wed, Sep 19, 2018 at 02:17:30PM +0200, Tomislav Požega wrote:
> On Wed, 19 Sep 2018 13:05:41 +0200, Stanislaw Gruszka wrote:
> 
> >Driver should provide on what channels are supported to mac80211, but
> >user space decide what channel to use and that imply band 2.4GHz or
> >5GHz. ->curr_band is just shortcut for band of current channel. Is set 
> >in rt2x00lib_config() after we call rt2x00dev->ops->lib->config()
> >[rt2800_config() for rt2800] . So patch is wrong. Either ->curr_band 
> >should be set before ->config call or we need to consistently use
> >rf->channel <= 14 for band check in any rt2800_config() function and
> >all it's subroutines. I prefer the second solution (i.e. rf->channel)
> >and now I can see few places when we use ->curr_band, what is a bug.
> 
> Works fine, no any kind of regression, especially not performance ones.
Did you test on dual band devices ?

> So I don't see a reason to claim it is wrong or bug just because you
> prefer current solution.
It's not wrong bacause I prefer current solution. It's because 
->curr_band is not updated when you call rt2800_config().

> >It's because ->curr_band initialize to 0 and NL80211_BAND_2GHZ
> >happen to be 0. Also problem will not trigger on single band
> >2.4GHz devices.
> 
> Can you show us how will the problem trigger on dual band devices?

When you switch from some 2.4GHz channel to 5GHz channel (or vice versa)
->curr_band will point to old band not the new one. To fix that you 
have to move curr_band assignemt before ->config() in
rt2x00lib_config() i.e:

rt2x00dev->curr_band = conf->chandef.chan->band; 
rt2x00dev->ops->lib->config(rt2x00dev, &libconf, ieee80211_flags);

However I do not see the point of replacyng rf->channel check 
to ->curr_band check. What you can do is oposite thing, replace
wrong usage of ->curr_band in very few places in rt2800_config()
subroutines to rf->channel check.

Also replacing spec->num_channels is wrong because this will
stop reporting device support 5GHz band.

Regards
Stanislaw 

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

* Re: [PATCH 1/5] rt2x00: set registers based on current band
  2018-09-19 12:47         ` Stanislaw Gruszka
@ 2018-09-19 13:04           ` Stanislaw Gruszka
  2018-09-29  9:26             ` Tom Psyborg
  0 siblings, 1 reply; 17+ messages in thread
From: Stanislaw Gruszka @ 2018-09-19 13:04 UTC (permalink / raw)
  To: Tomislav Požega; +Cc: linux-wireless

On Wed, Sep 19, 2018 at 02:47:18PM +0200, Stanislaw Gruszka wrote:
> > Can you show us how will the problem trigger on dual band devices?
> 
> When you switch from some 2.4GHz channel to 5GHz channel (or vice versa)
> ->curr_band will point to old band not the new one. To fix that you 
> have to move curr_band assignemt before ->config() in
> rt2x00lib_config() i.e:
> 
> rt2x00dev->curr_band = conf->chandef.chan->band; 
> rt2x00dev->ops->lib->config(rt2x00dev, &libconf, ieee80211_flags);
> 
> However I do not see the point of replacyng rf->channel check 
> to ->curr_band check. What you can do is oposite thing, replace
> wrong usage of ->curr_band in very few places in rt2800_config()
> subroutines to rf->channel check.

Actually ->curr_band is used in rt2800_config_ant() subroutines
not in rt2800_config() subroutines so things looks ok.

Stanislaw

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

* Re: [PATCH 1/5] rt2x00: set registers based on current band
  2018-09-19 13:04           ` Stanislaw Gruszka
@ 2018-09-29  9:26             ` Tom Psyborg
  0 siblings, 0 replies; 17+ messages in thread
From: Tom Psyborg @ 2018-09-29  9:26 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: linux-wireless

On 19/09/2018, Stanislaw Gruszka <sgruszka@redhat.com> wrote:
> On Wed, Sep 19, 2018 at 02:47:18PM +0200, Stanislaw Gruszka wrote:
>> > Can you show us how will the problem trigger on dual band devices?
>>
>> When you switch from some 2.4GHz channel to 5GHz channel (or vice versa)
>> ->curr_band will point to old band not the new one. To fix that you
>> have to move curr_band assignemt before ->config() in
>> rt2x00lib_config() i.e:
>>
>> rt2x00dev->curr_band = conf->chandef.chan->band;
>> rt2x00dev->ops->lib->config(rt2x00dev, &libconf, ieee80211_flags);
>>
>> However I do not see the point of replacyng rf->channel check
>> to ->curr_band check. What you can do is oposite thing, replace
>> wrong usage of ->curr_band in very few places in rt2800_config()
>> subroutines to rf->channel check.
>
> Actually ->curr_band is used in rt2800_config_ant() subroutines
> not in rt2800_config() subroutines so things looks ok.
>
> Stanislaw
>

Things should be ok, still if you have some of these cards, it'd be
better to verify that.
At least my MS150N usb card would panic when I did the very same
change in rf53xx channel config, probably because of the way the
btcoex idx value has been set.
Luckily I figured that chipset is single-band only and the patch3 was
enough to handle that:
https://www.spinics.net/lists/linux-wireless/msg177430.html

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

* Re: [PATCH 2/5] rt2x00: rework channel config function
  2018-09-17 16:32 ` [PATCH 2/5] rt2x00: rework channel config function Tomislav Požega
  2018-09-18 12:22   ` Stanislaw Gruszka
@ 2018-10-09 10:57   ` Stanislaw Gruszka
  1 sibling, 0 replies; 17+ messages in thread
From: Stanislaw Gruszka @ 2018-10-09 10:57 UTC (permalink / raw)
  To: Tomislav Požega; +Cc: linux-wireless

On Mon, Sep 17, 2018 at 06:32:52PM +0200, Tomislav Požega wrote:
> Enable LNAs only for the current operating band. Change power
> amplifiers enabling style to the one in vco calibration routine
> and drop redundant cap_bt_coexist enable of PA0.
<snip>
> -		rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN,
> -				   rf->channel > 14);
> -		if (rt2x00_has_cap_bt_coexist(rt2x00dev))
> +	if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) {
> +		switch (rt2x00dev->default_ant.tx_chain_num) {
> +		case 3:
> +			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, 1);
> +		case 2:
> +			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
> +		case 1:
> +			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1);
> +		break;
> +		}
> +	} else {
> +		switch (rt2x00dev->default_ant.tx_chain_num) {
> +		case 3:
> +			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, 1);
> +		case 2:
> +			rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
> +		case 1:

So we never disable PA_PE_Gx_EN bits for RT6352 since tx_pin variable
is not nulifed, but read from register. I don't think this was intended.

Thanks
Stanislaw

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

* Re: [PATCH 1/5] rt2x00: set registers based on current band
  2018-09-17 16:32 [PATCH 1/5] rt2x00: set registers based on current band Tomislav Požega
                   ` (4 preceding siblings ...)
  2018-09-18 12:20 ` [PATCH 1/5] rt2x00: set registers based on current band Stanislaw Gruszka
@ 2018-10-09 11:00 ` Stanislaw Gruszka
  2018-10-09 22:14   ` Tom Psyborg
  5 siblings, 1 reply; 17+ messages in thread
From: Stanislaw Gruszka @ 2018-10-09 11:00 UTC (permalink / raw)
  To: Tomislav Požega; +Cc: linux-wireless

Patches 3-5 looks ok to me, I'll rebase and resend them.

Thanks
Stanislaw

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

* Re: [PATCH 1/5] rt2x00: set registers based on current band
  2018-10-09 11:00 ` Stanislaw Gruszka
@ 2018-10-09 22:14   ` Tom Psyborg
  2018-10-10  8:49     ` Stanislaw Gruszka
  0 siblings, 1 reply; 17+ messages in thread
From: Tom Psyborg @ 2018-10-09 22:14 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: linux-wireless

On 09/10/2018, Stanislaw Gruszka <sgruszka@redhat.com> wrote:
> Patches 3-5 looks ok to me, I'll rebase and resend them.
>
> Thanks
> Stanislaw
>

and what about patches 1-2 ? did you find any regression?

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

* Re: [PATCH 1/5] rt2x00: set registers based on current band
  2018-10-09 22:14   ` Tom Psyborg
@ 2018-10-10  8:49     ` Stanislaw Gruszka
  0 siblings, 0 replies; 17+ messages in thread
From: Stanislaw Gruszka @ 2018-10-10  8:49 UTC (permalink / raw)
  To: Tom Psyborg; +Cc: linux-wireless

On Wed, Oct 10, 2018 at 12:14:28AM +0200, Tom Psyborg wrote:
> On 09/10/2018, Stanislaw Gruszka <sgruszka@redhat.com> wrote:
> > Patches 3-5 looks ok to me, I'll rebase and resend them.
> >
> > Thanks
> > Stanislaw
> >
> 
> and what about patches 1-2 ? did you find any regression?

I don't think they are correct nor needed. I belive you got
my comments on those patches.

Thanks
Stanislaw


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

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

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-17 16:32 [PATCH 1/5] rt2x00: set registers based on current band Tomislav Požega
2018-09-17 16:32 ` [PATCH 2/5] rt2x00: rework channel config function Tomislav Požega
2018-09-18 12:22   ` Stanislaw Gruszka
2018-10-09 10:57   ` Stanislaw Gruszka
2018-09-17 16:32 ` [PATCH 3/5] rt2x00: remove unneeded check Tomislav Požega
2018-09-17 16:32 ` [PATCH 4/5] rt2x00: remove confusing AGC register Tomislav Požega
2018-09-17 16:32 ` [PATCH 5/5] rt2x00: update TX_SW_CFG2 value Tomislav Požega
2018-09-18 12:20 ` [PATCH 1/5] rt2x00: set registers based on current band Stanislaw Gruszka
2018-09-18 14:14   ` Tomislav Požega
2018-09-19 11:05     ` Stanislaw Gruszka
2018-09-19 12:17       ` Tomislav Požega
2018-09-19 12:47         ` Stanislaw Gruszka
2018-09-19 13:04           ` Stanislaw Gruszka
2018-09-29  9:26             ` Tom Psyborg
2018-10-09 11:00 ` Stanislaw Gruszka
2018-10-09 22:14   ` Tom Psyborg
2018-10-10  8:49     ` Stanislaw Gruszka

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.