]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
mt76: move shared mcu_calibrate routine in mt76x02-lib module
authorLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Sun, 9 Sep 2018 21:58:04 +0000 (23:58 +0200)
committerFelix Fietkau <nbd@nbd.name>
Wed, 19 Sep 2018 10:31:41 +0000 (12:31 +0200)
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>
drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c
drivers/net/wireless/mediatek/mt76/mt76x0/mcu.h
drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
drivers/net/wireless/mediatek/mt76/mt76x02_mcu.c
drivers/net/wireless/mediatek/mt76/mt76x02_mcu.h
drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c
drivers/net/wireless/mediatek/mt76/mt76x2_mcu.h
drivers/net/wireless/mediatek/mt76/mt76x2_phy.c
drivers/net/wireless/mediatek/mt76/mt76x2u.h
drivers/net/wireless/mediatek/mt76/mt76x2u_mcu.c
drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c

index 551dad6ca058d2df0b99248f85dda3af5b95c647..dc28b9b31ace60ee9e80ec777e21eb8c14d5de87 100644 (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));
 }
 
-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];
index 6ba38022d26ad6b810637fe4ce9a9fd2f82782b7..4945c6890ce787b785a528366e106b25114c942f 100644 (file)
@@ -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
index 512e637635f515a81c71b7a929a9fdd2a9a6875a..2b6d928aab89d827f8e382051111bfc063668e55 100644 (file)
@@ -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)
index 3dc36ace91da79b7e31670126c1227e1a8d0ea9f..5a2fba3462fdbdd28172a7d75fe80a57a6bb7c30 100644 (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);
 
+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;
index cbdf6fc0997120e308ecd9aac8a794a64719d9ca..2f5af3dad2bbba6dc111ba587dfc958122765529 100644 (file)
@@ -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);
index d808892a89955ba4a0a479c84efbf7f5e77f3231..f92bebfa21fd7d2e266cf5ad270b5c610b3fe0a3 100644 (file)
@@ -165,33 +165,6 @@ error:
        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)
 {
        static const struct mt76_mcu_ops mt76x2_mcu_ops = {
index c5da3293dafdb373febb5c79d62cae6fe4e61212..3de062d0b644b75615b4f53c400ce95c8b86d02c 100644 (file)
@@ -101,8 +101,6 @@ struct mt76x2_tssi_comp {
        u8 offset1;
 } __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_init_gain(struct mt76x2_dev *dev, u8 channel, u32 gain,
                         bool force);
index f7c902ad4c96b816fb8cf05a8413c82f57b4cd97..f3a4484a3efea5ea0cc10fbbff1c8ad26bf45592 100644 (file)
@@ -37,7 +37,7 @@ mt76x2_phy_tssi_init_cal(struct mt76x2_dev *dev)
        if (mt76x2_ext_pa_enabled(dev, chan->band))
                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;
        return true;
 }
@@ -61,13 +61,13 @@ mt76x2_phy_channel_calibrate(struct mt76x2_dev *dev, bool mac_stopped)
                mt76x2_mac_stop(dev, false);
 
        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);
-       mt76x2_mcu_calibrate(dev, MCU_CAL_TXIQ, is_5ghz);
-       mt76x2_mcu_calibrate(dev, MCU_CAL_RXIQC_FI, is_5ghz);
-       mt76x2_mcu_calibrate(dev, MCU_CAL_TEMP_SENSOR, 0);
-       mt76x2_mcu_calibrate(dev, MCU_CAL_TX_SHAPING, 0);
+       mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TX_LOFT, is_5ghz, true);
+       mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TXIQ, is_5ghz, true);
+       mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXIQC_FI, is_5ghz, true);
+       mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TEMP_SENSOR, 0, true);
+       mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TX_SHAPING, 0, true);
 
        if (!mac_stopped)
                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);
 
                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 */
        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;
 
@@ -439,7 +439,7 @@ mt76x2_phy_tssi_compensate(struct mt76x2_dev *dev)
                        return;
 
                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;
        }
 }
index d3bc7904dbb737b57a8cdf289da3dc85d59c4054..a0ff6472de1f1c4e5dfab831430f00d6159cb2c3 100644 (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_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,
                                bool ext, int rssi, u32 false_cca);
 int mt76x2u_mcu_init(struct mt76x2_dev *dev);
index 808e5d4579c6a746a809ae772d4ee5b4cf611dca..fe86b9c696d920eaffc24ecb4dd160722065bf7b 100644 (file)
 #define MT76U_MCU_DLM_OFFSET           0x110000
 #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,
                                bool ext, int rssi, u32 false_cca)
 {
index 89defeee4bf3d19749391c90ba6863f91ee0ae01..c18e75478a6a7499b329ae4b1fb48ddfb3c1095d 100644 (file)
@@ -61,12 +61,12 @@ void mt76x2u_phy_channel_calibrate(struct mt76x2_dev *dev)
        mt76x2u_mac_stop(dev);
 
        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);
-       mt76x2u_mcu_calibrate(dev, MCU_CAL_TXIQ, is_5ghz);
-       mt76x2u_mcu_calibrate(dev, MCU_CAL_RXIQC_FI, is_5ghz);
-       mt76x2u_mcu_calibrate(dev, MCU_CAL_TEMP_SENSOR, 0);
+       mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TX_LOFT, is_5ghz, false);
+       mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TXIQ, is_5ghz, false);
+       mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXIQC_FI, is_5ghz, false);
+       mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TEMP_SENSOR, 0, false);
 
        mt76x2u_mac_resume(dev);
 }
@@ -107,7 +107,8 @@ mt76x2u_phy_tssi_compensate(struct mt76x2_dev *dev)
                        return;
 
                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;
        }
 }
@@ -253,14 +254,15 @@ int mt76x2u_phy_set_channel(struct mt76x2_dev *dev,
                u8 val = mt76x2_eeprom_get(dev, MT_EE_BT_RCAL_RESULT);
 
                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 */
        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;
 
        mt76_wr(dev, MT_BBP(AGC, 61), 0xff64a4e2);
@@ -292,7 +294,8 @@ int mt76x2u_phy_set_channel(struct mt76x2_dev *dev,
                                flag |= BIT(0);
                        if (mt76x2_ext_pa_enabled(dev, chan->band))
                                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;
                }
        }