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: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Lorenzo Bianconi 2018-09-09 23:58:04 +02:00 committed by Felix Fietkau
parent bc36690172
commit edaa580bc8
11 changed files with 68 additions and 97 deletions

View File

@ -41,22 +41,6 @@ static inline void skb_put_le32(struct sk_buff *skb, u32 val)
put_unaligned_le32(val, skb_put(skb, 4)); 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 mt76_fw {
struct mt76x02_fw_header hdr; struct mt76x02_fw_header hdr;
u8 ivb[MT_MCU_IVB_SIZE]; u8 ivb[MT_MCU_IVB_SIZE];

View File

@ -44,7 +44,4 @@ enum mcu_calibrate {
int mt76x0_mcu_init(struct mt76x0_dev *dev); int mt76x0_mcu_init(struct mt76x0_dev *dev);
int mt76x0_mcu_cmd_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 #endif

View File

@ -760,7 +760,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev,
mt76x0_vco_cal(dev, channel); mt76x0_vco_cal(dev, channel);
if (scan) 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); 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; u8 channel = dev->mt76.chandef.chan->hw_value;
int is_5ghz = (dev->mt76.chandef.chan->band == NL80211_BAND_5GHZ) ? 1 : 0; 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); mt76x0_vco_cal(dev, channel);
@ -798,20 +798,22 @@ void mt76x0_phy_recalibrate_after_assoc(struct mt76x0_dev *dev)
reg_val &= 0xffffff7e; reg_val &= 0xffffff7e;
mt76_wr(dev, 0x2124, reg_val); 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); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_LC, is_5ghz, false);
mt76x0_mcu_calibrate(dev, MCU_CAL_LOFT, is_5ghz); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_LOFT, is_5ghz, false);
mt76x0_mcu_calibrate(dev, MCU_CAL_TXIQ, is_5ghz); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TXIQ, is_5ghz, false);
mt76x0_mcu_calibrate(dev, MCU_CAL_TX_GROUP_DELAY, is_5ghz); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TX_GROUP_DELAY,
mt76x0_mcu_calibrate(dev, MCU_CAL_RXIQ, is_5ghz); is_5ghz, false);
mt76x0_mcu_calibrate(dev, MCU_CAL_RX_GROUP_DELAY, is_5ghz); 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, 0x2124, reg_val);
mt76_wr(dev, MT_TX_ALC_CFG_0, tx_alc); mt76_wr(dev, MT_TX_ALC_CFG_0, tx_alc);
msleep(100); 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) void mt76x0_agc_save(struct mt76x0_dev *dev)

View File

@ -168,6 +168,36 @@ int mt76x02_mcu_set_radio_state(struct mt76_dev *dev, bool on,
} }
EXPORT_SYMBOL_GPL(mt76x02_mcu_set_radio_state); 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) int mt76x02_mcu_cleanup(struct mt76_dev *dev)
{ {
struct sk_buff *skb; struct sk_buff *skb;

View File

@ -86,6 +86,8 @@ struct mt76x02_patch_header {
}; };
int mt76x02_mcu_cleanup(struct mt76_dev *dev); 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); 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 mt76x02_mcu_msg_send(struct mt76_dev *dev, struct sk_buff *skb,
int cmd, bool wait_resp); int cmd, bool wait_resp);

View File

@ -165,33 +165,6 @@ error:
return -ENOENT; return -ENOENT;
} }
int mt76x2_mcu_calibrate(struct mt76x2_dev *dev, enum mcu_calibration type,
u32 param)
{
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;
mt76_clear(dev, MT_MCU_COM_REG0, BIT(31));
skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg));
ret = mt76_mcu_send_msg(dev, skb, CMD_CALIBRATION_OP, true);
if (ret)
return ret;
if (WARN_ON(!mt76_poll_msec(dev, MT_MCU_COM_REG0,
BIT(31), BIT(31), 100)))
return -ETIMEDOUT;
return 0;
}
int mt76x2_mcu_init(struct mt76x2_dev *dev) int mt76x2_mcu_init(struct mt76x2_dev *dev)
{ {
static const struct mt76_mcu_ops mt76x2_mcu_ops = { static const struct mt76_mcu_ops mt76x2_mcu_ops = {

View File

@ -101,8 +101,6 @@ struct mt76x2_tssi_comp {
u8 offset1; u8 offset1;
} __packed __aligned(4); } __packed __aligned(4);
int mt76x2_mcu_calibrate(struct mt76x2_dev *dev, enum mcu_calibration type,
u32 param);
int mt76x2_mcu_tssi_comp(struct mt76x2_dev *dev, struct mt76x2_tssi_comp *tssi_data); int mt76x2_mcu_tssi_comp(struct mt76x2_dev *dev, struct mt76x2_tssi_comp *tssi_data);
int mt76x2_mcu_init_gain(struct mt76x2_dev *dev, u8 channel, u32 gain, int mt76x2_mcu_init_gain(struct mt76x2_dev *dev, u8 channel, u32 gain,
bool force); bool force);

View File

@ -37,7 +37,7 @@ mt76x2_phy_tssi_init_cal(struct mt76x2_dev *dev)
if (mt76x2_ext_pa_enabled(dev, chan->band)) if (mt76x2_ext_pa_enabled(dev, chan->band))
flag |= BIT(8); flag |= BIT(8);
mt76x2_mcu_calibrate(dev, MCU_CAL_TSSI, flag); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TSSI, flag, true);
dev->cal.tssi_cal_done = true; dev->cal.tssi_cal_done = true;
return true; return true;
} }
@ -61,13 +61,13 @@ mt76x2_phy_channel_calibrate(struct mt76x2_dev *dev, bool mac_stopped)
mt76x2_mac_stop(dev, false); mt76x2_mac_stop(dev, false);
if (is_5ghz) if (is_5ghz)
mt76x2_mcu_calibrate(dev, MCU_CAL_LC, 0); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_LC, 0, true);
mt76x2_mcu_calibrate(dev, MCU_CAL_TX_LOFT, is_5ghz); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TX_LOFT, is_5ghz, true);
mt76x2_mcu_calibrate(dev, MCU_CAL_TXIQ, is_5ghz); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TXIQ, is_5ghz, true);
mt76x2_mcu_calibrate(dev, MCU_CAL_RXIQC_FI, is_5ghz); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXIQC_FI, is_5ghz, true);
mt76x2_mcu_calibrate(dev, MCU_CAL_TEMP_SENSOR, 0); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TEMP_SENSOR, 0, true);
mt76x2_mcu_calibrate(dev, MCU_CAL_TX_SHAPING, 0); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TX_SHAPING, 0, true);
if (!mac_stopped) if (!mac_stopped)
mt76x2_mac_resume(dev); mt76x2_mac_resume(dev);
@ -363,14 +363,14 @@ int mt76x2_phy_set_channel(struct mt76x2_dev *dev,
u8 val = mt76x2_eeprom_get(dev, MT_EE_BT_RCAL_RESULT); u8 val = mt76x2_eeprom_get(dev, MT_EE_BT_RCAL_RESULT);
if (val != 0xff) if (val != 0xff)
mt76x2_mcu_calibrate(dev, MCU_CAL_R, 0); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_R, 0, true);
} }
mt76x2_mcu_calibrate(dev, MCU_CAL_RXDCOC, channel); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXDCOC, channel, true);
/* Rx LPF calibration */ /* Rx LPF calibration */
if (!dev->cal.init_cal_done) if (!dev->cal.init_cal_done)
mt76x2_mcu_calibrate(dev, MCU_CAL_RC, 0); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RC, 0, true);
dev->cal.init_cal_done = true; dev->cal.init_cal_done = true;
@ -439,7 +439,7 @@ mt76x2_phy_tssi_compensate(struct mt76x2_dev *dev)
return; return;
usleep_range(10000, 20000); usleep_range(10000, 20000);
mt76x2_mcu_calibrate(dev, MCU_CAL_DPD, chan->hw_value); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_DPD, chan->hw_value, true);
dev->cal.dpd_cal_done = true; dev->cal.dpd_cal_done = true;
} }
} }

View File

@ -50,8 +50,6 @@ void mt76x2u_phy_set_txdac(struct mt76x2_dev *dev);
void mt76x2u_phy_set_rxpath(struct mt76x2_dev *dev); void mt76x2u_phy_set_rxpath(struct mt76x2_dev *dev);
void mt76x2u_mcu_complete_urb(struct urb *urb); void mt76x2u_mcu_complete_urb(struct urb *urb);
int mt76x2u_mcu_calibrate(struct mt76x2_dev *dev, enum mcu_calibration type,
u32 val);
int mt76x2u_mcu_set_dynamic_vga(struct mt76x2_dev *dev, u8 channel, bool ap, int mt76x2u_mcu_set_dynamic_vga(struct mt76x2_dev *dev, u8 channel, bool ap,
bool ext, int rssi, u32 false_cca); bool ext, int rssi, u32 false_cca);
int mt76x2u_mcu_init(struct mt76x2_dev *dev); int mt76x2u_mcu_init(struct mt76x2_dev *dev);

View File

@ -29,22 +29,6 @@
#define MT76U_MCU_DLM_OFFSET 0x110000 #define MT76U_MCU_DLM_OFFSET 0x110000
#define MT76U_MCU_ROM_PATCH_OFFSET 0x90000 #define MT76U_MCU_ROM_PATCH_OFFSET 0x90000
int mt76x2u_mcu_calibrate(struct mt76x2_dev *dev, enum mcu_calibration type,
u32 val)
{
struct {
__le32 id;
__le32 value;
} __packed __aligned(4) msg = {
.id = cpu_to_le32(type),
.value = cpu_to_le32(val),
};
struct sk_buff *skb;
skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg));
return mt76_mcu_send_msg(dev, skb, CMD_CALIBRATION_OP, true);
}
int mt76x2u_mcu_set_dynamic_vga(struct mt76x2_dev *dev, u8 channel, bool ap, int mt76x2u_mcu_set_dynamic_vga(struct mt76x2_dev *dev, u8 channel, bool ap,
bool ext, int rssi, u32 false_cca) bool ext, int rssi, u32 false_cca)
{ {

View File

@ -61,12 +61,12 @@ void mt76x2u_phy_channel_calibrate(struct mt76x2_dev *dev)
mt76x2u_mac_stop(dev); mt76x2u_mac_stop(dev);
if (is_5ghz) if (is_5ghz)
mt76x2u_mcu_calibrate(dev, MCU_CAL_LC, 0); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_LC, 0, false);
mt76x2u_mcu_calibrate(dev, MCU_CAL_TX_LOFT, is_5ghz); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TX_LOFT, is_5ghz, false);
mt76x2u_mcu_calibrate(dev, MCU_CAL_TXIQ, is_5ghz); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TXIQ, is_5ghz, false);
mt76x2u_mcu_calibrate(dev, MCU_CAL_RXIQC_FI, is_5ghz); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXIQC_FI, is_5ghz, false);
mt76x2u_mcu_calibrate(dev, MCU_CAL_TEMP_SENSOR, 0); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TEMP_SENSOR, 0, false);
mt76x2u_mac_resume(dev); mt76x2u_mac_resume(dev);
} }
@ -107,7 +107,8 @@ mt76x2u_phy_tssi_compensate(struct mt76x2_dev *dev)
return; return;
usleep_range(10000, 20000); usleep_range(10000, 20000);
mt76x2u_mcu_calibrate(dev, MCU_CAL_DPD, chan->hw_value); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_DPD,
chan->hw_value, false);
dev->cal.dpd_cal_done = true; dev->cal.dpd_cal_done = true;
} }
} }
@ -253,14 +254,15 @@ int mt76x2u_phy_set_channel(struct mt76x2_dev *dev,
u8 val = mt76x2_eeprom_get(dev, MT_EE_BT_RCAL_RESULT); u8 val = mt76x2_eeprom_get(dev, MT_EE_BT_RCAL_RESULT);
if (val != 0xff) if (val != 0xff)
mt76x2u_mcu_calibrate(dev, MCU_CAL_R, 0); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_R,
0, false);
} }
mt76x2u_mcu_calibrate(dev, MCU_CAL_RXDCOC, channel); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXDCOC, channel, false);
/* Rx LPF calibration */ /* Rx LPF calibration */
if (!dev->cal.init_cal_done) if (!dev->cal.init_cal_done)
mt76x2u_mcu_calibrate(dev, MCU_CAL_RC, 0); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RC, 0, false);
dev->cal.init_cal_done = true; dev->cal.init_cal_done = true;
mt76_wr(dev, MT_BBP(AGC, 61), 0xff64a4e2); mt76_wr(dev, MT_BBP(AGC, 61), 0xff64a4e2);
@ -292,7 +294,8 @@ int mt76x2u_phy_set_channel(struct mt76x2_dev *dev,
flag |= BIT(0); flag |= BIT(0);
if (mt76x2_ext_pa_enabled(dev, chan->band)) if (mt76x2_ext_pa_enabled(dev, chan->band))
flag |= BIT(8); flag |= BIT(8);
mt76x2u_mcu_calibrate(dev, MCU_CAL_TSSI, flag); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TSSI,
flag, false);
dev->cal.tssi_cal_done = true; dev->cal.tssi_cal_done = true;
} }
} }