mt76x02: assure we update gain after scan
authorStanislaw Gruszka <sgruszka@redhat.com>
Tue, 22 Jan 2019 12:38:34 +0000 (13:38 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 31 Jan 2019 07:15:46 +0000 (08:15 +0100)
commit 4784a3cc3fffd0ba5ef6c7a23980ae0318fc1369 upstream.

Assure that after we initialize dev->cal.low_gain to -1 this
will cause update gain calibration. Otherwise this might or
might not happen depending on value of second bit of low_gain
and values read from registers in mt76x02_phy_adjust_vga_gain().

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/wireless/mediatek/mt76/mt76x0/main.c
drivers/net/wireless/mediatek/mt76/mt76x0/phy.c

index 205c3afe2aeb95dcd91682b1955a396b3c6ee098..4126ac5d9a8af1ae7dd5280d1f0747155f3b1a3f 100644 (file)
@@ -139,8 +139,11 @@ void mt76x0_sw_scan_complete(struct ieee80211_hw *hw,
 
        clear_bit(MT76_SCANNING, &dev->mt76.state);
 
-       if (dev->cal.gain_init_done)
+       if (dev->cal.gain_init_done) {
+               /* Restore AGC gain and resume calibration after scanning. */
+               dev->cal.low_gain = -1;
                ieee80211_queue_delayed_work(hw, &dev->cal_work, 0);
+       }
 }
 EXPORT_SYMBOL_GPL(mt76x0_sw_scan_complete);
 
index 771e54b39abfc8c57866f72d3c2c3cdcf552c0f2..f99097e265aacdf9a63ce387f890f3bfa6dca134 100644 (file)
@@ -834,7 +834,8 @@ mt76x0_phy_update_channel_gain(struct mt76x02_dev *dev)
        low_gain = (dev->cal.avg_rssi_all > mt76x02_get_rssi_gain_thresh(dev)) +
                   (dev->cal.avg_rssi_all > mt76x02_get_low_rssi_gain_thresh(dev));
 
-       gain_change = (dev->cal.low_gain & 2) ^ (low_gain & 2);
+       gain_change = dev->cal.low_gain < 0 ||
+                     (dev->cal.low_gain & 2) ^ (low_gain & 2);
        dev->cal.low_gain = low_gain;
 
        if (!gain_change) {