Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

mt76: move shared mcu_calibrate routine in mt76x02-lib module



Move mcu_calibrate routine in mt76x02-lib module since it is
shared between USB and PCI code. Moreover remove duplicated
code

Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent bc366901
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -41,22 +41,6 @@ static inline void skb_put_le32(struct sk_buff *skb, u32 val)
	put_unaligned_le32(val, skb_put(skb, 4));
}

int
mt76x0_mcu_calibrate(struct mt76x0_dev *dev, enum mcu_calibrate cal, u32 val)
{
	struct sk_buff *skb;
	struct {
		__le32 id;
		__le32 value;
	} __packed __aligned(4) msg = {
		.id = cpu_to_le32(cal),
		.value = cpu_to_le32(val),
	};

	skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg));
	return mt76_mcu_send_msg(dev, skb, CMD_CALIBRATION_OP, true);
}

struct mt76_fw {
	struct mt76x02_fw_header hdr;
	u8 ivb[MT_MCU_IVB_SIZE];
+0 −3
Original line number Diff line number Diff line
@@ -44,7 +44,4 @@ enum mcu_calibrate {
int mt76x0_mcu_init(struct mt76x0_dev *dev);
int mt76x0_mcu_cmd_init(struct mt76x0_dev *dev);

int
mt76x0_mcu_calibrate(struct mt76x0_dev *dev, enum mcu_calibrate cal, u32 val);

#endif
+12 −10
Original line number Diff line number Diff line
@@ -760,7 +760,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev,

	mt76x0_vco_cal(dev, channel);
	if (scan)
		mt76x0_mcu_calibrate(dev, MCU_CAL_RXDCOC, 1);
		mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXDCOC, 1, false);

	mt76x0_phy_set_chan_pwr(dev, channel);

@@ -786,7 +786,7 @@ void mt76x0_phy_recalibrate_after_assoc(struct mt76x0_dev *dev)
	u8 channel = dev->mt76.chandef.chan->hw_value;
	int is_5ghz = (dev->mt76.chandef.chan->band == NL80211_BAND_5GHZ) ? 1 : 0;

	mt76x0_mcu_calibrate(dev, MCU_CAL_R, 0);
	mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_R, 0, false);

	mt76x0_vco_cal(dev, channel);

@@ -798,20 +798,22 @@ void mt76x0_phy_recalibrate_after_assoc(struct mt76x0_dev *dev)
	reg_val &= 0xffffff7e;
	mt76_wr(dev, 0x2124, reg_val);

	mt76x0_mcu_calibrate(dev, MCU_CAL_RXDCOC, 0);
	mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXDCOC, 0, false);

	mt76x0_mcu_calibrate(dev, MCU_CAL_LC, is_5ghz);
	mt76x0_mcu_calibrate(dev, MCU_CAL_LOFT, is_5ghz);
	mt76x0_mcu_calibrate(dev, MCU_CAL_TXIQ, is_5ghz);
	mt76x0_mcu_calibrate(dev, MCU_CAL_TX_GROUP_DELAY, is_5ghz);
	mt76x0_mcu_calibrate(dev, MCU_CAL_RXIQ, is_5ghz);
	mt76x0_mcu_calibrate(dev, MCU_CAL_RX_GROUP_DELAY, is_5ghz);
	mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_LC, is_5ghz, false);
	mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_LOFT, is_5ghz, false);
	mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TXIQ, is_5ghz, false);
	mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TX_GROUP_DELAY,
			      is_5ghz, false);
	mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXIQ, is_5ghz, false);
	mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RX_GROUP_DELAY,
			      is_5ghz, false);

	mt76_wr(dev, 0x2124, reg_val);
	mt76_wr(dev, MT_TX_ALC_CFG_0, tx_alc);
	msleep(100);

	mt76x0_mcu_calibrate(dev, MCU_CAL_RXDCOC, 1);
	mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXDCOC, 1, false);
}

void mt76x0_agc_save(struct mt76x0_dev *dev)
+30 −0
Original line number Diff line number Diff line
@@ -168,6 +168,36 @@ int mt76x02_mcu_set_radio_state(struct mt76_dev *dev, bool on,
}
EXPORT_SYMBOL_GPL(mt76x02_mcu_set_radio_state);

int mt76x02_mcu_calibrate(struct mt76_dev *dev, int type,
			  u32 param, bool wait)
{
	struct sk_buff *skb;
	struct {
		__le32 id;
		__le32 value;
	} __packed __aligned(4) msg = {
		.id = cpu_to_le32(type),
		.value = cpu_to_le32(param),
	};
	int ret;

	if (wait)
		dev->bus->rmw(dev, MT_MCU_COM_REG0, BIT(31), 0);

	skb = dev->mcu_ops->mcu_msg_alloc(&msg, sizeof(msg));
	ret = dev->mcu_ops->mcu_send_msg(dev, skb, CMD_CALIBRATION_OP, true);
	if (ret)
		return ret;

	if (wait &&
	    WARN_ON(!__mt76_poll_msec(dev, MT_MCU_COM_REG0,
				      BIT(31), BIT(31), 100)))
		return -ETIMEDOUT;

	return 0;
}
EXPORT_SYMBOL_GPL(mt76x02_mcu_calibrate);

int mt76x02_mcu_cleanup(struct mt76_dev *dev)
{
	struct sk_buff *skb;
+2 −0
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ struct mt76x02_patch_header {
};

int mt76x02_mcu_cleanup(struct mt76_dev *dev);
int mt76x02_mcu_calibrate(struct mt76_dev *dev, int type,
			  u32 param, bool wait);
struct sk_buff *mt76x02_mcu_msg_alloc(const void *data, int len);
int mt76x02_mcu_msg_send(struct mt76_dev *dev, struct sk_buff *skb,
			 int cmd, bool wait_resp);
Loading