Skip to content

Commit 2daa675

Browse files
LorenzoBianconinbd168
authored andcommitted
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>
1 parent e59ad99 commit 2daa675

File tree

5 files changed

+24
-40
lines changed

5 files changed

+24
-40
lines changed

drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data)
109109
dev->ee->rssi_offset_5ghz[0], dev->ee->rssi_offset_5ghz[1],
110110
dev->ee->rssi_offset_5ghz[2]);
111111
seq_printf(file, "Temperature offset: %hhx\n", dev->ee->temp_off);
112-
seq_printf(file, "LNA gain 2Ghz: %hhx\n", dev->ee->lna_gain_2ghz);
113-
seq_printf(file, "LNA gain 5Ghz: %hhx %hhx %hhx\n",
114-
dev->ee->lna_gain_5ghz[0], dev->ee->lna_gain_5ghz[1],
115-
dev->ee->lna_gain_5ghz[2]);
112+
seq_printf(file, "LNA gain: %x\n", dev->caldata.lna_gain);
116113

117114
val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0);
118115
seq_printf(file, "Power Amplifier type %lx\n",

drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,18 @@ mt76x0_set_rf_freq_off(struct mt76x0_dev *dev, u8 *eeprom)
122122
dev->ee->rf_freq_off += comp;
123123
}
124124

125-
static void
126-
mt76x0_set_lna_gain(struct mt76x0_dev *dev, u8 *eeprom)
125+
void mt76x0_read_rx_gain(struct mt76x0_dev *dev)
127126
{
128-
u8 gain;
129-
130-
dev->ee->lna_gain_2ghz = eeprom[MT_EE_LNA_GAIN];
131-
dev->ee->lna_gain_5ghz[0] = eeprom[MT_EE_LNA_GAIN + 1];
127+
struct ieee80211_channel *chan = dev->mt76.chandef.chan;
128+
struct mt76x0_caldata *caldata = &dev->caldata;
129+
s8 lna_5g[3], lna_2g;
130+
u16 rssi_offset;
132131

133-
gain = eeprom[MT_EE_LNA_GAIN_5GHZ_1];
134-
if (gain == 0xff || gain == 0)
135-
dev->ee->lna_gain_5ghz[1] = dev->ee->lna_gain_5ghz[0];
136-
else
137-
dev->ee->lna_gain_5ghz[1] = gain;
132+
mt76x02_get_rx_gain(&dev->mt76, chan->band, &rssi_offset,
133+
&lna_2g, lna_5g);
134+
caldata->lna_gain = mt76x02_get_lna_gain(&dev->mt76, &lna_2g,
135+
lna_5g, chan);
138136

139-
gain = eeprom[MT_EE_LNA_GAIN_5GHZ_2];
140-
if (gain == 0xff || gain == 0)
141-
dev->ee->lna_gain_5ghz[2] = dev->ee->lna_gain_5ghz[0];
142-
else
143-
dev->ee->lna_gain_5ghz[2] = gain;
144137
}
145138

146139
static void
@@ -318,7 +311,6 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev)
318311
mt76x0_set_chip_cap(dev, eeprom);
319312
mt76x0_set_rf_freq_off(dev, eeprom);
320313
mt76x0_set_temp_offset(dev, eeprom);
321-
mt76x0_set_lna_gain(dev, eeprom);
322314
mt76x0_set_rssi_offset(dev, eeprom);
323315
dev->chainmask = 0x0101;
324316

drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ struct reg_channel_bounds {
2828
u8 num;
2929
};
3030

31+
struct mt76x0_caldata {
32+
s8 lna_gain;
33+
};
34+
3135
struct mt76x0_eeprom_params {
3236
u8 rf_freq_off;
3337
s16 temp_off;
3438
s8 rssi_offset_2ghz[2];
3539
s8 rssi_offset_5ghz[3];
36-
s8 lna_gain_2ghz;
37-
s8 lna_gain_5ghz[3];
3840

3941
/* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */
4042
u32 tx_pwr_cfg_2g[5][2];
@@ -44,6 +46,7 @@ struct mt76x0_eeprom_params {
4446
};
4547

4648
int mt76x0_eeprom_init(struct mt76x0_dev *dev);
49+
void mt76x0_read_rx_gain(struct mt76x0_dev *dev);
4750

4851
static inline u32 s6_validate(u32 reg)
4952
{

drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "../mt76.h"
2929
#include "../mt76x02_regs.h"
3030
#include "../mt76x02_mac.h"
31+
#include "eeprom.h"
3132

3233
#define MT_CALIBRATE_INTERVAL (4 * HZ)
3334

@@ -89,6 +90,7 @@ struct mt76x0_dev {
8990
const u16 *beacon_offsets;
9091

9192
struct mt76x0_eeprom_params *ee;
93+
struct mt76x0_caldata caldata;
9294

9395
struct mutex reg_atomic_mutex;
9496
struct mutex hw_atomic_mutex;

drivers/net/wireless/mediatek/mt76/mt76x0/phy.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,17 @@ mt76x0_bbp_set_ctrlch(struct mt76x0_dev *dev, enum nl80211_chan_width width,
228228

229229
int mt76x0_phy_get_rssi(struct mt76x0_dev *dev, struct mt76x02_rxwi *rxwi)
230230
{
231-
s8 lna_gain, rssi_offset;
231+
struct mt76x0_caldata *caldata = &dev->caldata;
232+
s8 rssi_offset;
232233
int val;
233234

234235
if (dev->mt76.chandef.chan->band == NL80211_BAND_2GHZ) {
235-
lna_gain = dev->ee->lna_gain_2ghz;
236236
rssi_offset = dev->ee->rssi_offset_2ghz[0];
237237
} else {
238-
lna_gain = dev->ee->lna_gain_5ghz[0];
239238
rssi_offset = dev->ee->rssi_offset_5ghz[0];
240239
}
241240

242-
val = rxwi->rssi[0] + rssi_offset - lna_gain;
241+
val = rxwi->rssi[0] + rssi_offset - caldata->lna_gain;
243242

244243
return val;
245244
}
@@ -545,20 +544,10 @@ mt76x0_phy_set_chan_bbp_params(struct mt76x0_dev *dev, u8 channel, u16 rf_bw_ban
545544

546545
if (pair->reg == MT_BBP(AGC, 8)) {
547546
u32 val = pair->value;
548-
u8 gain = FIELD_GET(MT_BBP_AGC_GAIN, val);
549-
550-
if (channel > 14) {
551-
if (channel < 100)
552-
gain -= dev->ee->lna_gain_5ghz[0]*2;
553-
else if (channel < 137)
554-
gain -= dev->ee->lna_gain_5ghz[1]*2;
555-
else
556-
gain -= dev->ee->lna_gain_5ghz[2]*2;
557-
558-
} else {
559-
gain -= dev->ee->lna_gain_2ghz*2;
560-
}
547+
u8 gain;
561548

549+
gain = FIELD_GET(MT_BBP_AGC_GAIN, val);
550+
gain -= dev->caldata.lna_gain * 2;
562551
val &= ~MT_BBP_AGC_GAIN;
563552
val |= FIELD_PREP(MT_BBP_AGC_GAIN, gain);
564553
mt76_wr(dev, pair->reg, val);
@@ -737,6 +726,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev,
737726

738727
mt76x0_phy_set_band(dev, chandef->chan->band);
739728
mt76x0_phy_set_chan_rf_params(dev, channel, rf_bw_band);
729+
mt76x0_read_rx_gain(dev);
740730

741731
/* set Japan Tx filter at channel 14 */
742732
val = mt76_rr(dev, MT_BBP(CORE, 1));

0 commit comments

Comments
 (0)