ath5k: eliminate CHANNEL_* macros, use AR5K_MODE_* in channel->hw_value
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / ath / ath5k / reset.c
index 9f9c2ad3ca66b9bc0b49e2c41011277e763ea57c..8bc57e4576155b377ecf7ec2e4c1f26701b1964e 100644 (file)
@@ -102,12 +102,18 @@ static void ath5k_hw_init_core_clock(struct ath5k_hw *ah)
        /*
         * Set core clock frequency
         */
-       if (channel->hw_value & CHANNEL_5GHZ)
-               clock = 40; /* 802.11a */
-       else if (channel->hw_value & CHANNEL_CCK)
-               clock = 22; /* 802.11b */
-       else
-               clock = 44; /* 802.11g */
+       switch (channel->hw_value) {
+       case AR5K_MODE_11A:
+               clock = 40;
+               break;
+       case AR5K_MODE_11B:
+               clock = 22;
+               break;
+       case AR5K_MODE_11G:
+       default:
+               clock = 44;
+               break;
+       }
 
        /* Use clock multiplier for non-default
         * bwmode */
@@ -390,7 +396,7 @@ static int ath5k_hw_wisoc_reset(struct ath5k_hw *ah, u32 flags)
        u32 val = 0;
 
        /* ah->ah_mac_srev is not available at this point yet */
-       if (ah->ah_sc->devid >= AR5K_SREV_AR2315_R6) {
+       if (ah->devid >= AR5K_SREV_AR2315_R6) {
                reg = (u32 __iomem *) AR5K_AR2315_RESET;
                if (mask & AR5K_RESET_CTL_PCU)
                        val |= AR5K_AR2315_RESET_WMAC;
@@ -398,7 +404,7 @@ static int ath5k_hw_wisoc_reset(struct ath5k_hw *ah, u32 flags)
                        val |= AR5K_AR2315_RESET_BB_WARM;
        } else {
                reg = (u32 __iomem *) AR5K_AR5312_RESET;
-               if (to_platform_device(ah->ah_sc->dev)->id == 0) {
+               if (to_platform_device(ah->dev)->id == 0) {
                        if (mask & AR5K_RESET_CTL_PCU)
                                val |= AR5K_AR5312_RESET_WMAC0;
                        if (mask & AR5K_RESET_CTL_BASEBAND)
@@ -530,7 +536,7 @@ commit:
  */
 int ath5k_hw_on_hold(struct ath5k_hw *ah)
 {
-       struct pci_dev *pdev = ah->ah_sc->pdev;
+       struct pci_dev *pdev = ah->pdev;
        u32 bus_flags;
        int ret;
 
@@ -540,7 +546,7 @@ int ath5k_hw_on_hold(struct ath5k_hw *ah)
        /* Make sure device is awake */
        ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
        if (ret) {
-               ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
+               ATH5K_ERR(ah, "failed to wakeup the MAC Chip\n");
                return ret;
        }
 
@@ -565,14 +571,14 @@ int ath5k_hw_on_hold(struct ath5k_hw *ah)
        }
 
        if (ret) {
-               ATH5K_ERR(ah->ah_sc, "failed to put device on warm reset\n");
+               ATH5K_ERR(ah, "failed to put device on warm reset\n");
                return -EIO;
        }
 
        /* ...wakeup again!*/
        ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
        if (ret) {
-               ATH5K_ERR(ah->ah_sc, "failed to put device on hold\n");
+               ATH5K_ERR(ah, "failed to put device on hold\n");
                return ret;
        }
 
@@ -581,10 +587,11 @@ int ath5k_hw_on_hold(struct ath5k_hw *ah)
 
 /*
  * Bring up MAC + PHY Chips and program PLL
+ * Channel is NULL for the initial wakeup.
  */
-int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
+int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, struct ieee80211_channel *channel)
 {
-       struct pci_dev *pdev = ah->ah_sc->pdev;
+       struct pci_dev *pdev = ah->pdev;
        u32 turbo, mode, clock, bus_flags;
        int ret;
 
@@ -592,11 +599,11 @@ int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
        mode = 0;
        clock = 0;
 
-       if ((ath5k_get_bus_type(ah) != ATH_AHB) || !initial) {
+       if ((ath5k_get_bus_type(ah) != ATH_AHB) || channel) {
                /* Wakeup the device */
                ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
                if (ret) {
-                       ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
+                       ATH5K_ERR(ah, "failed to wakeup the MAC Chip\n");
                        return ret;
                }
        }
@@ -626,14 +633,14 @@ int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
        }
 
        if (ret) {
-               ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip\n");
+               ATH5K_ERR(ah, "failed to reset the MAC Chip\n");
                return -EIO;
        }
 
        /* ...wakeup again!...*/
        ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
        if (ret) {
-               ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
+               ATH5K_ERR(ah, "failed to resume the MAC Chip\n");
                return ret;
        }
 
@@ -646,13 +653,13 @@ int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
                ret = ath5k_hw_nic_reset(ah, 0);
 
        if (ret) {
-               ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
+               ATH5K_ERR(ah, "failed to warm reset the MAC Chip\n");
                return -EIO;
        }
 
        /* On initialization skip PLL programming since we don't have
         * a channel / mode set yet */
-       if (initial)
+       if (!channel)
                return 0;
 
        if (ah->ah_version != AR5K_AR5210) {
@@ -668,13 +675,13 @@ int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
                        clock = AR5K_PHY_PLL_RF5111;            /*Zero*/
                }
 
-               if (flags & CHANNEL_2GHZ) {
+               if (channel->band == IEEE80211_BAND_2GHZ) {
                        mode |= AR5K_PHY_MODE_FREQ_2GHZ;
                        clock |= AR5K_PHY_PLL_44MHZ;
 
-                       if (flags & CHANNEL_CCK) {
+                       if (channel->hw_value == AR5K_MODE_11B) {
                                mode |= AR5K_PHY_MODE_MOD_CCK;
-                       } else if (flags & CHANNEL_OFDM) {
+                       } else {
                                /* XXX Dynamic OFDM/CCK is not supported by the
                                 * AR5211 so we set MOD_OFDM for plain g (no
                                 * CCK headers) operation. We need to test
@@ -686,29 +693,18 @@ int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
                                        mode |= AR5K_PHY_MODE_MOD_OFDM;
                                else
                                        mode |= AR5K_PHY_MODE_MOD_DYN;
-                       } else {
-                               ATH5K_ERR(ah->ah_sc,
-                                       "invalid radio modulation mode\n");
-                               return -EINVAL;
                        }
-               } else if (flags & CHANNEL_5GHZ) {
-                       mode |= AR5K_PHY_MODE_FREQ_5GHZ;
+               } else if (channel->band == IEEE80211_BAND_5GHZ) {
+                       mode |= (AR5K_PHY_MODE_FREQ_5GHZ |
+                                AR5K_PHY_MODE_MOD_OFDM);
 
                        /* Different PLL setting for 5413 */
                        if (ah->ah_radio == AR5K_RF5413)
                                clock = AR5K_PHY_PLL_40MHZ_5413;
                        else
                                clock |= AR5K_PHY_PLL_40MHZ;
-
-                       if (flags & CHANNEL_OFDM)
-                               mode |= AR5K_PHY_MODE_MOD_OFDM;
-                       else {
-                               ATH5K_ERR(ah->ah_sc,
-                                       "invalid radio modulation mode\n");
-                               return -EINVAL;
-                       }
                } else {
-                       ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
+                       ATH5K_ERR(ah, "invalid radio frequency mode\n");
                        return -EINVAL;
                }
 
@@ -822,7 +818,7 @@ static void ath5k_hw_tweak_initval_settings(struct ath5k_hw *ah,
                u32 data;
                ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
                                AR5K_PHY_CCKTXCTL);
-               if (channel->hw_value & CHANNEL_5GHZ)
+               if (channel->band == IEEE80211_BAND_5GHZ)
                        data = 0xffb81020;
                else
                        data = 0xffb80d20;
@@ -905,7 +901,7 @@ static void ath5k_hw_commit_eeprom_settings(struct ath5k_hw *ah,
        /* Set CCK to OFDM power delta on tx power
         * adjustment register */
        if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
-               if (channel->hw_value == CHANNEL_G)
+               if (channel->hw_value == AR5K_MODE_11G)
                        ath5k_hw_reg_write(ah,
                        AR5K_REG_SM((ee->ee_cck_ofdm_gain_delta * -1),
                                AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA) |
@@ -1076,7 +1072,7 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
        /* RF Bus grant won't work if we have pending
         * frames */
        if (ret && fast) {
-               ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_RESET,
+               ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
                        "DMA didn't stop, falling back to normal reset\n");
                fast = 0;
                /* Non fatal, just continue with
@@ -1084,40 +1080,26 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
                ret = 0;
        }
 
-       switch (channel->hw_value & CHANNEL_MODES) {
-       case CHANNEL_A:
-               mode = AR5K_MODE_11A;
+       mode = channel->hw_value;
+       switch (mode) {
+       case AR5K_MODE_11A:
                break;
-       case CHANNEL_G:
-
+       case AR5K_MODE_11G:
                if (ah->ah_version <= AR5K_AR5211) {
-                       ATH5K_ERR(ah->ah_sc,
+                       ATH5K_ERR(ah,
                                "G mode not available on 5210/5211");
                        return -EINVAL;
                }
-
-               mode = AR5K_MODE_11G;
                break;
-       case CHANNEL_B:
-
+       case AR5K_MODE_11B:
                if (ah->ah_version < AR5K_AR5211) {
-                       ATH5K_ERR(ah->ah_sc,
+                       ATH5K_ERR(ah,
                                "B mode not available on 5210");
                        return -EINVAL;
                }
-
-               mode = AR5K_MODE_11B;
-               break;
-       case CHANNEL_XR:
-               if (ah->ah_version == AR5K_AR5211) {
-                       ATH5K_ERR(ah->ah_sc,
-                               "XR mode not available on 5211");
-                       return -EINVAL;
-               }
-               mode = AR5K_MODE_XR;
                break;
        default:
-               ATH5K_ERR(ah->ah_sc,
+               ATH5K_ERR(ah,
                        "invalid channel: %d\n", channel->center_freq);
                return -EINVAL;
        }
@@ -1129,13 +1111,13 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
        if (fast) {
                ret = ath5k_hw_phy_init(ah, channel, mode, true);
                if (ret) {
-                       ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_RESET,
+                       ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
                                "fast chan change failed, falling back to normal reset\n");
                        /* Non fatal, can happen eg.
                         * on mode change */
                        ret = 0;
                } else {
-                       ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_RESET,
+                       ATH5K_DBG(ah, ATH5K_DEBUG_RESET,
                                "fast chan change successful\n");
                        return 0;
                }
@@ -1200,7 +1182,7 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
        }
 
        /* Wakeup the device */
-       ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
+       ret = ath5k_hw_nic_wakeup(ah, channel);
        if (ret)
                return ret;
 
@@ -1268,7 +1250,7 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
         */
        ret = ath5k_hw_phy_init(ah, channel, mode, false);
        if (ret) {
-               ATH5K_ERR(ah->ah_sc,
+               ATH5K_ERR(ah,
                        "failed to initialize PHY (%i) !\n", ret);
                return ret;
        }