Commit 6034b2b0 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau
Browse files

mt76: move set_{tx,rx}_path routines in mt76x02-lib module



Move mt76x02_phy_set_rxpath and mt76x02_phy_tx_dac routines in
mt76x02_phy.c since they are shared between mt76x2 and mt76x0 drivers.
Moreover move chainmask variable from mt76x2/mt76x0 to mt76_dev data
structure

Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 4468e92c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -404,6 +404,7 @@ struct mt76_dev {
	unsigned long state;

	u8 antenna_mask;
	u16 chainmask;

	struct mt76_sband sband_2g;
	struct mt76_sband sband_5g;
+1 −1
Original line number Diff line number Diff line
@@ -313,7 +313,7 @@ int mt76x0_eeprom_init(struct mt76x0_dev *dev)
	mt76x0_set_freq_offset(dev);
	mt76x0_set_temp_offset(dev);

	dev->chainmask = 0x0101;
	dev->mt76.chainmask = 0x0101;

	return 0;
}
+0 −1
Original line number Diff line number Diff line
@@ -104,7 +104,6 @@ struct mt76x0_dev {
	int avg_rssi; /* starts at 0 and converges */

	u8 agc_save;
	u16 chainmask;

	bool no_2ghz;

+2 −29
Original line number Diff line number Diff line
@@ -855,32 +855,6 @@ void mt76x0_phy_con_cal_onoff(struct mt76x0_dev *dev,
	spin_unlock_bh(&dev->con_mon_lock);
}

static void
mt76x0_set_rx_chains(struct mt76x0_dev *dev)
{
	u32 val;

	val = mt76_rr(dev, MT_BBP(AGC, 0));
	val &= ~(BIT(3) | BIT(4));

	if (dev->chainmask & BIT(1))
		val |= BIT(3);

	mt76_wr(dev, MT_BBP(AGC, 0), val);

	mb();
	val = mt76_rr(dev, MT_BBP(AGC, 0));
}

static void
mt76x0_set_tx_dac(struct mt76x0_dev *dev)
{
	if (dev->chainmask & BIT(1))
		mt76_set(dev, MT_BBP(TXBE, 5), 3);
	else
		mt76_clear(dev, MT_BBP(TXBE, 5), 3);
}

static void
mt76x0_rf_init(struct mt76x0_dev *dev)
{
@@ -940,7 +914,6 @@ void mt76x0_phy_init(struct mt76x0_dev *dev)
	INIT_DELAYED_WORK(&dev->cal_work, mt76x0_phy_calibrate);

	mt76x0_rf_init(dev);

	mt76x0_set_rx_chains(dev);
	mt76x0_set_tx_dac(dev);
	mt76x02_phy_set_rxpath(&dev->mt76);
	mt76x02_phy_set_txdac(&dev->mt76);
}
+38 −0
Original line number Diff line number Diff line
@@ -20,6 +20,44 @@
#include "mt76.h"
#include "mt76x02_phy.h"

void mt76x02_phy_set_rxpath(struct mt76_dev *dev)
{
	u32 val;

	val = __mt76_rr(dev, MT_BBP(AGC, 0));
	val &= ~BIT(4);

	switch (dev->chainmask & 0xf) {
	case 2:
		val |= BIT(3);
		break;
	default:
		val &= ~BIT(3);
		break;
	}

	__mt76_wr(dev, MT_BBP(AGC, 0), val);
	mb();
	val = __mt76_rr(dev, MT_BBP(AGC, 0));
}
EXPORT_SYMBOL_GPL(mt76x02_phy_set_rxpath);

void mt76x02_phy_set_txdac(struct mt76_dev *dev)
{
	int txpath;

	txpath = (dev->chainmask >> 8) & 0xf;
	switch (txpath) {
	case 2:
		__mt76_set(dev, MT_BBP(TXBE, 5), 0x3);
		break;
	default:
		__mt76_clear(dev, MT_BBP(TXBE, 5), 0x3);
		break;
	}
}
EXPORT_SYMBOL_GPL(mt76x02_phy_set_txdac);

static u32
mt76x02_tx_power_mask(u8 v1, u8 v2, u8 v3, u8 v4)
{
Loading