mirror of
https://github.com/torvalds/linux.git
synced 2024-12-25 04:11:49 +00:00
mt76x0: unify lna_gain parsing
Unify lna gain parsing with mt76x2 driver using eeprom utility routines available in mt76x02-lib module Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
e59ad99b04
commit
2daa67588f
@ -109,10 +109,7 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data)
|
||||
dev->ee->rssi_offset_5ghz[0], dev->ee->rssi_offset_5ghz[1],
|
||||
dev->ee->rssi_offset_5ghz[2]);
|
||||
seq_printf(file, "Temperature offset: %hhx\n", dev->ee->temp_off);
|
||||
seq_printf(file, "LNA gain 2Ghz: %hhx\n", dev->ee->lna_gain_2ghz);
|
||||
seq_printf(file, "LNA gain 5Ghz: %hhx %hhx %hhx\n",
|
||||
dev->ee->lna_gain_5ghz[0], dev->ee->lna_gain_5ghz[1],
|
||||
dev->ee->lna_gain_5ghz[2]);
|
||||
seq_printf(file, "LNA gain: %x\n", dev->caldata.lna_gain);
|
||||
|
||||
val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0);
|
||||
seq_printf(file, "Power Amplifier type %lx\n",
|
||||
|
@ -122,25 +122,18 @@ mt76x0_set_rf_freq_off(struct mt76x0_dev *dev, u8 *eeprom)
|
||||
dev->ee->rf_freq_off += comp;
|
||||
}
|
||||
|
||||
static void
|
||||
mt76x0_set_lna_gain(struct mt76x0_dev *dev, u8 *eeprom)
|
||||
void mt76x0_read_rx_gain(struct mt76x0_dev *dev)
|
||||
{
|
||||
u8 gain;
|
||||
struct ieee80211_channel *chan = dev->mt76.chandef.chan;
|
||||
struct mt76x0_caldata *caldata = &dev->caldata;
|
||||
s8 lna_5g[3], lna_2g;
|
||||
u16 rssi_offset;
|
||||
|
||||
dev->ee->lna_gain_2ghz = eeprom[MT_EE_LNA_GAIN];
|
||||
dev->ee->lna_gain_5ghz[0] = eeprom[MT_EE_LNA_GAIN + 1];
|
||||
mt76x02_get_rx_gain(&dev->mt76, chan->band, &rssi_offset,
|
||||
&lna_2g, lna_5g);
|
||||
caldata->lna_gain = mt76x02_get_lna_gain(&dev->mt76, &lna_2g,
|
||||
lna_5g, chan);
|
||||
|
||||
gain = eeprom[MT_EE_LNA_GAIN_5GHZ_1];
|
||||
if (gain == 0xff || gain == 0)
|
||||
dev->ee->lna_gain_5ghz[1] = dev->ee->lna_gain_5ghz[0];
|
||||
else
|
||||
dev->ee->lna_gain_5ghz[1] = gain;
|
||||
|
||||
gain = eeprom[MT_EE_LNA_GAIN_5GHZ_2];
|
||||
if (gain == 0xff || gain == 0)
|
||||
dev->ee->lna_gain_5ghz[2] = dev->ee->lna_gain_5ghz[0];
|
||||
else
|
||||
dev->ee->lna_gain_5ghz[2] = gain;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -318,7 +311,6 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev)
|
||||
mt76x0_set_chip_cap(dev, eeprom);
|
||||
mt76x0_set_rf_freq_off(dev, eeprom);
|
||||
mt76x0_set_temp_offset(dev, eeprom);
|
||||
mt76x0_set_lna_gain(dev, eeprom);
|
||||
mt76x0_set_rssi_offset(dev, eeprom);
|
||||
dev->chainmask = 0x0101;
|
||||
|
||||
|
@ -28,13 +28,15 @@ struct reg_channel_bounds {
|
||||
u8 num;
|
||||
};
|
||||
|
||||
struct mt76x0_caldata {
|
||||
s8 lna_gain;
|
||||
};
|
||||
|
||||
struct mt76x0_eeprom_params {
|
||||
u8 rf_freq_off;
|
||||
s16 temp_off;
|
||||
s8 rssi_offset_2ghz[2];
|
||||
s8 rssi_offset_5ghz[3];
|
||||
s8 lna_gain_2ghz;
|
||||
s8 lna_gain_5ghz[3];
|
||||
|
||||
/* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */
|
||||
u32 tx_pwr_cfg_2g[5][2];
|
||||
@ -44,6 +46,7 @@ struct mt76x0_eeprom_params {
|
||||
};
|
||||
|
||||
int mt76x0_eeprom_init(struct mt76x0_dev *dev);
|
||||
void mt76x0_read_rx_gain(struct mt76x0_dev *dev);
|
||||
|
||||
static inline u32 s6_validate(u32 reg)
|
||||
{
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "../mt76.h"
|
||||
#include "../mt76x02_regs.h"
|
||||
#include "../mt76x02_mac.h"
|
||||
#include "eeprom.h"
|
||||
|
||||
#define MT_CALIBRATE_INTERVAL (4 * HZ)
|
||||
|
||||
@ -89,6 +90,7 @@ struct mt76x0_dev {
|
||||
const u16 *beacon_offsets;
|
||||
|
||||
struct mt76x0_eeprom_params *ee;
|
||||
struct mt76x0_caldata caldata;
|
||||
|
||||
struct mutex reg_atomic_mutex;
|
||||
struct mutex hw_atomic_mutex;
|
||||
|
@ -228,18 +228,17 @@ mt76x0_bbp_set_ctrlch(struct mt76x0_dev *dev, enum nl80211_chan_width width,
|
||||
|
||||
int mt76x0_phy_get_rssi(struct mt76x0_dev *dev, struct mt76x02_rxwi *rxwi)
|
||||
{
|
||||
s8 lna_gain, rssi_offset;
|
||||
struct mt76x0_caldata *caldata = &dev->caldata;
|
||||
s8 rssi_offset;
|
||||
int val;
|
||||
|
||||
if (dev->mt76.chandef.chan->band == NL80211_BAND_2GHZ) {
|
||||
lna_gain = dev->ee->lna_gain_2ghz;
|
||||
rssi_offset = dev->ee->rssi_offset_2ghz[0];
|
||||
} else {
|
||||
lna_gain = dev->ee->lna_gain_5ghz[0];
|
||||
rssi_offset = dev->ee->rssi_offset_5ghz[0];
|
||||
}
|
||||
|
||||
val = rxwi->rssi[0] + rssi_offset - lna_gain;
|
||||
val = rxwi->rssi[0] + rssi_offset - caldata->lna_gain;
|
||||
|
||||
return val;
|
||||
}
|
||||
@ -545,20 +544,10 @@ mt76x0_phy_set_chan_bbp_params(struct mt76x0_dev *dev, u8 channel, u16 rf_bw_ban
|
||||
|
||||
if (pair->reg == MT_BBP(AGC, 8)) {
|
||||
u32 val = pair->value;
|
||||
u8 gain = FIELD_GET(MT_BBP_AGC_GAIN, val);
|
||||
|
||||
if (channel > 14) {
|
||||
if (channel < 100)
|
||||
gain -= dev->ee->lna_gain_5ghz[0]*2;
|
||||
else if (channel < 137)
|
||||
gain -= dev->ee->lna_gain_5ghz[1]*2;
|
||||
else
|
||||
gain -= dev->ee->lna_gain_5ghz[2]*2;
|
||||
|
||||
} else {
|
||||
gain -= dev->ee->lna_gain_2ghz*2;
|
||||
}
|
||||
u8 gain;
|
||||
|
||||
gain = FIELD_GET(MT_BBP_AGC_GAIN, val);
|
||||
gain -= dev->caldata.lna_gain * 2;
|
||||
val &= ~MT_BBP_AGC_GAIN;
|
||||
val |= FIELD_PREP(MT_BBP_AGC_GAIN, gain);
|
||||
mt76_wr(dev, pair->reg, val);
|
||||
@ -737,6 +726,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev,
|
||||
|
||||
mt76x0_phy_set_band(dev, chandef->chan->band);
|
||||
mt76x0_phy_set_chan_rf_params(dev, channel, rf_bw_band);
|
||||
mt76x0_read_rx_gain(dev);
|
||||
|
||||
/* set Japan Tx filter at channel 14 */
|
||||
val = mt76_rr(dev, MT_BBP(CORE, 1));
|
||||
|
Loading…
Reference in New Issue
Block a user