rtl8xxxu: Split USB quirks into gen1 and gen2 quirks
authorJes Sorensen <Jes.Sorensen@redhat.com>
Thu, 14 Apr 2016 18:59:04 +0000 (14:59 -0400)
committerKalle Valo <kvalo@codeaurora.org>
Fri, 15 Apr 2016 18:36:44 +0000 (21:36 +0300)
This removes a bunch of if () spaghetti and re-applies the USB bus
quirks for 8188/8192 that had gotten lost.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.c
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h

index 3e3ca28d5709ffb9b9624e980c66b1fbc8162793..821be872525661c21a76fa68a7434cd956ef4591 100644 (file)
@@ -6899,6 +6899,50 @@ static int rtl8xxxu_flush_fifo(struct rtl8xxxu_priv *priv)
        return retval;
 }
 
+static void rtl8xxxu_gen1_usb_quirks(struct rtl8xxxu_priv *priv)
+{
+       /* Fix USB interface interference issue */
+       rtl8xxxu_write8(priv, 0xfe40, 0xe0);
+       rtl8xxxu_write8(priv, 0xfe41, 0x8d);
+       rtl8xxxu_write8(priv, 0xfe42, 0x80);
+       /*
+        * This sets TXDMA_OFFSET_DROP_DATA_EN (bit 9) as well as bits
+        * 8 and 5, for which I have found no documentation.
+        */
+       rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, 0xfd0320);
+
+       /*
+        * Solve too many protocol error on USB bus.
+        * Can't do this for 8188/8192 UMC A cut parts
+        */
+       if (!(!priv->chip_cut && priv->vendor_umc)) {
+               rtl8xxxu_write8(priv, 0xfe40, 0xe6);
+               rtl8xxxu_write8(priv, 0xfe41, 0x94);
+               rtl8xxxu_write8(priv, 0xfe42, 0x80);
+
+               rtl8xxxu_write8(priv, 0xfe40, 0xe0);
+               rtl8xxxu_write8(priv, 0xfe41, 0x19);
+               rtl8xxxu_write8(priv, 0xfe42, 0x80);
+
+               rtl8xxxu_write8(priv, 0xfe40, 0xe5);
+               rtl8xxxu_write8(priv, 0xfe41, 0x91);
+               rtl8xxxu_write8(priv, 0xfe42, 0x80);
+
+               rtl8xxxu_write8(priv, 0xfe40, 0xe2);
+               rtl8xxxu_write8(priv, 0xfe41, 0x81);
+               rtl8xxxu_write8(priv, 0xfe42, 0x80);
+       }
+}
+
+static void rtl8xxxu_gen2_usb_quirks(struct rtl8xxxu_priv *priv)
+{
+       u32 val32;
+
+       val32 = rtl8xxxu_read32(priv, REG_TXDMA_OFFSET_CHK);
+       val32 |= TXDMA_OFFSET_DROP_DATA_EN;
+       rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, val32);
+}
+
 static int rtl8723au_power_on(struct rtl8xxxu_priv *priv)
 {
        u8 val8;
@@ -7563,29 +7607,6 @@ static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
        if (ret)
                goto exit;
 
-       /* Solve too many protocol error on USB bus */
-       /* Can't do this for 8188/8192 UMC A cut parts */
-       if (priv->rtl_chip == RTL8723A ||
-           ((priv->rtl_chip == RTL8192C || priv->rtl_chip == RTL8191C ||
-             priv->rtl_chip == RTL8188C) &&
-            (priv->chip_cut || !priv->vendor_umc))) {
-               rtl8xxxu_write8(priv, 0xfe40, 0xe6);
-               rtl8xxxu_write8(priv, 0xfe41, 0x94);
-               rtl8xxxu_write8(priv, 0xfe42, 0x80);
-
-               rtl8xxxu_write8(priv, 0xfe40, 0xe0);
-               rtl8xxxu_write8(priv, 0xfe41, 0x19);
-               rtl8xxxu_write8(priv, 0xfe42, 0x80);
-
-               rtl8xxxu_write8(priv, 0xfe40, 0xe5);
-               rtl8xxxu_write8(priv, 0xfe41, 0x91);
-               rtl8xxxu_write8(priv, 0xfe42, 0x80);
-
-               rtl8xxxu_write8(priv, 0xfe40, 0xe2);
-               rtl8xxxu_write8(priv, 0xfe41, 0x81);
-               rtl8xxxu_write8(priv, 0xfe42, 0x80);
-       }
-
        if (priv->fops->phy_init_antenna_selection)
                priv->fops->phy_init_antenna_selection(priv);
 
@@ -7604,6 +7625,12 @@ static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
        case RTL8723A:
                rftable = rtl8723au_radioa_1t_init_table;
                ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
+
+               /* Reduce 80M spur */
+               rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, 0x0381808d);
+               rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
+               rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff82);
+               rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
                break;
        case RTL8723B:
                rftable = rtl8723bu_radioa_1t_init_table;
@@ -7706,23 +7733,7 @@ static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
                /*
                 * Chip specific quirks
                 */
-               if (priv->rtl_chip == RTL8723A) {
-                       /* Fix USB interface interference issue */
-                       rtl8xxxu_write8(priv, 0xfe40, 0xe0);
-                       rtl8xxxu_write8(priv, 0xfe41, 0x8d);
-                       rtl8xxxu_write8(priv, 0xfe42, 0x80);
-                       rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, 0xfd0320);
-
-                       /* Reduce 80M spur */
-                       rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, 0x0381808d);
-                       rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
-                       rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff82);
-                       rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
-               } else {
-                       val32 = rtl8xxxu_read32(priv, REG_TXDMA_OFFSET_CHK);
-                       val32 |= TXDMA_OFFSET_DROP_DATA_EN;
-                       rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, val32);
-               }
+               priv->fops->usb_quirks(priv);
 
                /*
                 * Presumably this is for 8188EU as well
@@ -9712,6 +9723,7 @@ static struct rtl8xxxu_fileops rtl8723au_fops = {
        .parse_rx_desc = rtl8xxxu_parse_rxdesc16,
        .enable_rf = rtl8723a_enable_rf,
        .disable_rf = rtl8723a_disable_rf,
+       .usb_quirks = rtl8xxxu_gen1_usb_quirks,
        .set_tx_power = rtl8723a_set_tx_power,
        .update_rate_mask = rtl8723au_update_rate_mask,
        .report_connect = rtl8723au_report_connect,
@@ -9746,6 +9758,7 @@ static struct rtl8xxxu_fileops rtl8723bu_fops = {
        .init_statistics = rtl8723bu_init_statistics,
        .enable_rf = rtl8723b_enable_rf,
        .disable_rf = rtl8723b_disable_rf,
+       .usb_quirks = rtl8xxxu_gen2_usb_quirks,
        .set_tx_power = rtl8723b_set_tx_power,
        .update_rate_mask = rtl8723bu_update_rate_mask,
        .report_connect = rtl8723bu_report_connect,
@@ -9780,6 +9793,7 @@ static struct rtl8xxxu_fileops rtl8192cu_fops = {
        .parse_rx_desc = rtl8xxxu_parse_rxdesc16,
        .enable_rf = rtl8723a_enable_rf,
        .disable_rf = rtl8723a_disable_rf,
+       .usb_quirks = rtl8xxxu_gen1_usb_quirks,
        .set_tx_power = rtl8723a_set_tx_power,
        .update_rate_mask = rtl8723au_update_rate_mask,
        .report_connect = rtl8723au_report_connect,
@@ -9813,6 +9827,7 @@ static struct rtl8xxxu_fileops rtl8192eu_fops = {
        .parse_rx_desc = rtl8xxxu_parse_rxdesc24,
        .enable_rf = rtl8723b_enable_rf,
        .disable_rf = rtl8723b_disable_rf,
+       .usb_quirks = rtl8xxxu_gen2_usb_quirks,
        .set_tx_power = rtl8192e_set_tx_power,
        .update_rate_mask = rtl8723bu_update_rate_mask,
        .report_connect = rtl8723bu_report_connect,
index 8064b264ad0b829b10ad33f3af7663b6475451da..da86f3f528b4909581e97e7965962b4989e327f6 100644 (file)
@@ -1293,6 +1293,7 @@ struct rtl8xxxu_fileops {
        void (*init_statistics) (struct rtl8xxxu_priv *priv);
        void (*enable_rf) (struct rtl8xxxu_priv *priv);
        void (*disable_rf) (struct rtl8xxxu_priv *priv);
+       void (*usb_quirks) (struct rtl8xxxu_priv *priv);
        void (*set_tx_power) (struct rtl8xxxu_priv *priv, int channel,
                              bool ht40);
        void (*update_rate_mask) (struct rtl8xxxu_priv *priv,