Skip to content

Commit f2a2e81

Browse files
LorenzoBianconinbd168
authored andcommitted
mt76x0: remove eeprom dependency from mt76x0_get_power_info
In order to unify eeprom parsing between mt76x0 and mt76x2 drivers, remove eeprom pointer dependency from mt76x0_get_power_info routine. Remove mt76x0_eeprom_params since it is now an empty structure Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
1 parent b37bbc8 commit f2a2e81

File tree

5 files changed

+77
-81
lines changed

5 files changed

+77
-81
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data)
100100
{
101101
struct mt76x0_dev *dev = file->private;
102102
u16 val;
103-
int i;
104103

105104
seq_printf(file, "RF freq offset: %hhx\n",
106105
dev->caldata.freq_offset);
@@ -114,10 +113,6 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data)
114113
seq_printf(file, "Power Amplifier type %lx\n",
115114
val & MT_EE_NIC_CONF_0_PA_TYPE);
116115

117-
seq_puts(file, "Per channel power:\n");
118-
for (i = 0; i < 58; i++)
119-
seq_printf(file, "\t%d chan:%d pwr:%d\n", i, i,
120-
dev->ee->tx_pwr_per_chan[i]);
121116
return 0;
122117
}
123118

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

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -210,38 +210,71 @@ void mt76x0_get_tx_power_per_rate(struct mt76x0_dev *dev)
210210
mt76x02_add_rate_power_offset(t, delta);
211211
}
212212

213-
static void
214-
mt76x0_set_tx_power_per_chan(struct mt76x0_dev *dev, u8 *eeprom)
213+
void mt76x0_get_power_info(struct mt76x0_dev *dev, u8 *info)
215214
{
215+
struct mt76x0_chan_map {
216+
u8 chan;
217+
u8 offset;
218+
} chan_map[] = {
219+
{ 2, 0 }, { 4, 1 }, { 6, 2 }, { 8, 3 },
220+
{ 10, 4 }, { 12, 5 }, { 14, 6 }, { 38, 0 },
221+
{ 44, 1 }, { 48, 2 }, { 54, 3 }, { 60, 4 },
222+
{ 64, 5 }, { 102, 6 }, { 108, 7 }, { 112, 8 },
223+
{ 118, 9 }, { 124, 10 }, { 128, 11 }, { 134, 12 },
224+
{ 140, 13 }, { 151, 14 }, { 157, 15 }, { 161, 16 },
225+
{ 167, 17 }, { 171, 18 }, { 173, 19 },
226+
};
227+
struct ieee80211_channel *chan = dev->mt76.chandef.chan;
228+
u8 offset, addr;
229+
u16 data;
216230
int i;
217-
u8 tx_pwr;
218231

219-
for (i = 0; i < 14; i++) {
220-
tx_pwr = eeprom[MT_EE_TX_POWER_DELTA_BW80 + i];
221-
if (tx_pwr <= 0x3f && tx_pwr > 0)
222-
dev->ee->tx_pwr_per_chan[i] = tx_pwr;
223-
else
224-
dev->ee->tx_pwr_per_chan[i] = 5;
232+
for (i = 0; i < ARRAY_SIZE(chan_map); i++) {
233+
if (chan_map[i].chan <= chan->hw_value) {
234+
offset = chan_map[i].offset;
235+
break;
236+
}
225237
}
238+
if (i == ARRAY_SIZE(chan_map))
239+
offset = chan_map[0].offset;
226240

227-
for (i = 0; i < 40; i++) {
228-
tx_pwr = eeprom[MT_EE_TX_POWER_0_GRP4_TSSI_SLOPE + 2 + i];
229-
if (tx_pwr <= 0x3f && tx_pwr > 0)
230-
dev->ee->tx_pwr_per_chan[14 + i] = tx_pwr;
231-
else
232-
dev->ee->tx_pwr_per_chan[14 + i] = 5;
241+
if (chan->band == NL80211_BAND_2GHZ) {
242+
addr = MT_EE_TX_POWER_DELTA_BW80 + offset;
243+
} else {
244+
switch (chan->hw_value) {
245+
case 58:
246+
offset = 8;
247+
break;
248+
case 106:
249+
offset = 14;
250+
break;
251+
case 112:
252+
offset = 20;
253+
break;
254+
case 155:
255+
offset = 30;
256+
break;
257+
default:
258+
break;
259+
}
260+
addr = MT_EE_TX_POWER_0_GRP4_TSSI_SLOPE + 2 + offset;
233261
}
234262

235-
dev->ee->tx_pwr_per_chan[54] = dev->ee->tx_pwr_per_chan[22];
236-
dev->ee->tx_pwr_per_chan[55] = dev->ee->tx_pwr_per_chan[28];
237-
dev->ee->tx_pwr_per_chan[56] = dev->ee->tx_pwr_per_chan[34];
238-
dev->ee->tx_pwr_per_chan[57] = dev->ee->tx_pwr_per_chan[44];
263+
data = mt76x02_eeprom_get(&dev->mt76, addr);
264+
265+
info[0] = data;
266+
if (!info[0] || info[0] > 0x3f)
267+
info[0] = 5;
268+
269+
info[1] = data >> 8;
270+
if (!info[1] || info[1] > 0x3f)
271+
info[1] = 5;
239272
}
240273

241-
int
242-
mt76x0_eeprom_init(struct mt76x0_dev *dev)
274+
int mt76x0_eeprom_init(struct mt76x0_dev *dev)
243275
{
244-
u8 *eeprom;
276+
u8 version, fae;
277+
u16 data;
245278
int ret;
246279

247280
ret = mt76x0_efuse_physical_size_check(dev);
@@ -252,37 +285,31 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev)
252285
if (ret < 0)
253286
return ret;
254287

255-
dev->ee = devm_kzalloc(dev->mt76.dev, sizeof(*dev->ee), GFP_KERNEL);
256-
if (!dev->ee)
257-
return -ENOMEM;
258-
259-
eeprom = kmalloc(MT76X0_EEPROM_SIZE, GFP_KERNEL);
260-
if (!eeprom)
261-
return -ENOMEM;
262-
263-
ret = mt76x02_get_efuse_data(&dev->mt76, 0, eeprom,
288+
ret = mt76x02_get_efuse_data(&dev->mt76, 0, dev->mt76.eeprom.data,
264289
MT76X0_EEPROM_SIZE, MT_EE_READ);
265290
if (ret)
266-
goto out;
291+
return ret;
292+
293+
data = mt76x02_eeprom_get(&dev->mt76, MT_EE_VERSION);
294+
version = data >> 8;
295+
fae = data;
267296

268-
if (eeprom[MT_EE_VERSION + 1] > MT76X0U_EE_MAX_VER)
297+
if (version > MT76X0U_EE_MAX_VER)
269298
dev_warn(dev->mt76.dev,
270299
"Warning: unsupported EEPROM version %02hhx\n",
271-
eeprom[MT_EE_VERSION + 1]);
300+
version);
272301
dev_info(dev->mt76.dev, "EEPROM ver:%02hhx fae:%02hhx\n",
273-
eeprom[MT_EE_VERSION + 1], eeprom[MT_EE_VERSION]);
302+
version, fae);
274303

275-
mt76x02_mac_setaddr(&dev->mt76, eeprom + MT_EE_MAC_ADDR);
304+
mt76x02_mac_setaddr(&dev->mt76,
305+
dev->mt76.eeprom.data + MT_EE_MAC_ADDR);
276306
mt76x0_set_chip_cap(dev);
277307
mt76x0_set_freq_offset(dev);
278308
mt76x0_set_temp_offset(dev);
279-
dev->chainmask = 0x0101;
280309

281-
mt76x0_set_tx_power_per_chan(dev, eeprom);
310+
dev->chainmask = 0x0101;
282311

283-
out:
284-
kfree(eeprom);
285-
return ret;
312+
return 0;
286313
}
287314

288315
MODULE_LICENSE("Dual BSD/GPL");

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ struct mt76x0_dev;
2323
#define MT76X0U_EE_MAX_VER 0x0c
2424
#define MT76X0_EEPROM_SIZE 512
2525

26-
struct reg_channel_bounds {
27-
u8 start;
28-
u8 num;
29-
};
30-
3126
struct mt76x0_caldata {
3227
s8 rssi_offset[2];
3328
s8 lna_gain;
@@ -36,14 +31,10 @@ struct mt76x0_caldata {
3631
u8 freq_offset;
3732
};
3833

39-
struct mt76x0_eeprom_params {
40-
41-
u8 tx_pwr_per_chan[58];
42-
};
43-
4434
int mt76x0_eeprom_init(struct mt76x0_dev *dev);
4535
void mt76x0_read_rx_gain(struct mt76x0_dev *dev);
4636
void mt76x0_get_tx_power_per_rate(struct mt76x0_dev *dev);
37+
void mt76x0_get_power_info(struct mt76x0_dev *dev, u8 *info);
4738

4839
static inline s8 s6_to_s8(u32 val)
4940
{

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ struct mt76x0_dev {
8989

9090
const u16 *beacon_offsets;
9191

92-
struct mt76x0_eeprom_params *ee;
9392
struct mt76x0_caldata caldata;
9493

9594
struct mutex reg_atomic_mutex;

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -578,31 +578,15 @@ mt76x0_bbp_set_bw(struct mt76x0_dev *dev, enum nl80211_chan_width width)
578578
mt76x02_mcu_function_select(&dev->mt76, BW_SETTING, bw, false);
579579
}
580580

581-
static void
582-
mt76x0_phy_set_chan_pwr(struct mt76x0_dev *dev, u8 channel)
581+
static void mt76x0_phy_set_chan_pwr(struct mt76x0_dev *dev)
583582
{
584-
static const int mt76x0_tx_pwr_ch_list[] = {
585-
1,2,3,4,5,6,7,8,9,10,11,12,13,14,
586-
36,38,40,44,46,48,52,54,56,60,62,64,
587-
100,102,104,108,110,112,116,118,120,124,126,128,132,134,136,140,
588-
149,151,153,157,159,161,165,167,169,171,173,
589-
42,58,106,122,155
590-
};
591-
int i;
592-
u32 val;
593-
594-
for (i = 0; i < ARRAY_SIZE(mt76x0_tx_pwr_ch_list); i++)
595-
if (mt76x0_tx_pwr_ch_list[i] == channel)
596-
break;
597-
598-
if (WARN_ON(i == ARRAY_SIZE(mt76x0_tx_pwr_ch_list)))
599-
return;
583+
u8 info[2];
600584

601-
val = mt76_rr(dev, MT_TX_ALC_CFG_0);
602-
val &= ~0x3f3f;
603-
val |= dev->ee->tx_pwr_per_chan[i];
604-
val |= 0x2f2f << 16;
605-
mt76_wr(dev, MT_TX_ALC_CFG_0, val);
585+
mt76x0_get_power_info(dev, info);
586+
mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_0,
587+
info[0]);
588+
mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_1,
589+
info[1]);
606590
}
607591

608592
static int
@@ -699,7 +683,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev,
699683
if (scan)
700684
mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXDCOC, 1, false);
701685

702-
mt76x0_phy_set_chan_pwr(dev, channel);
686+
mt76x0_phy_set_chan_pwr(dev);
703687

704688
return 0;
705689
}

0 commit comments

Comments
 (0)