]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ath9k: consistently use get_eeprom_rev(ah)
authorMartin Blumenstingl <martin.blumenstingl@googlemail.com>
Mon, 5 Dec 2016 11:27:35 +0000 (13:27 +0200)
committerKalle Valo <kvalo@qca.qualcomm.com>
Thu, 15 Dec 2016 08:26:32 +0000 (10:26 +0200)
The AR5416_VER_MASK macro does the same as get_eeprom_rev, except that
one has to know the actual EEPROM type (and providing a reference to
that in a variable named "eep"). Additionally the eeprom_*.c
implementations used the same shifting logic multiple times to get the
eeprom revision which was also unnecessary duplication of
get_eeprom_rev.

Also use the AR5416_EEP_VER_MINOR_MASK macro where needed and introduce
a similar macro (AR5416_EEP_VER_MAJOR_MASK) for the major version.
Finally drop AR9287_EEP_VER_MINOR_MASK since it simply duplicates the
already defined AR5416_EEP_VER_MINOR_MASK.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Signed-off-by: Kalle Valo <kvalo@qca.qualcomm.com>
drivers/net/wireless/ath/ath9k/eeprom.h
drivers/net/wireless/ath/ath9k/eeprom_4k.c
drivers/net/wireless/ath/ath9k/eeprom_9287.c
drivers/net/wireless/ath/ath9k/eeprom_def.c
drivers/net/wireless/ath/ath9k/xmit.c

index 8ef8090d0c9c02b847b66d2f397d617ad56b7afc..5a24fb5dc0a044c9e245b8f8abd31ea665d8bec5 100644 (file)
@@ -99,7 +99,6 @@
 #define FBIN2FREQ(x, y)                ((y) ? (2300 + x) : (4800 + 5 * x))
 #define ath9k_hw_use_flash(_ah)        (!(_ah->ah_flags & AH_USE_EEPROM))
 
-#define AR5416_VER_MASK (eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK)
 #define OLC_FOR_AR9280_20_LATER (AR_SREV_9280_20_OR_LATER(ah) && \
                                 ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
 #define OLC_FOR_AR9287_10_LATER (AR_SREV_9287_11_OR_LATER(ah) && \
 
 #define AR5416_EEP_NO_BACK_VER       0x1
 #define AR5416_EEP_VER               0xE
+#define AR5416_EEP_VER_MAJOR_SHIFT   12
+#define AR5416_EEP_VER_MAJOR_MASK    0xF000
 #define AR5416_EEP_VER_MINOR_MASK    0x0FFF
 #define AR5416_EEP_MINOR_VER_2       0x2
 #define AR5416_EEP_MINOR_VER_3       0x3
 #define AR9280_TX_GAIN_TABLE_SIZE 22
 
 #define AR9287_EEP_VER               0xE
-#define AR9287_EEP_VER_MINOR_MASK    0xFFF
 #define AR9287_EEP_MINOR_VER_1       0x1
 #define AR9287_EEP_MINOR_VER_2       0x2
 #define AR9287_EEP_MINOR_VER_3       0x3
index d4668712f866e9446496b13088c6bd2f5d49ac68..76ce109629b9b0c2543990f246fe13ac0b450c47 100644 (file)
 
 static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
 {
-       return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF);
+       u16 version = ah->eeprom.map4k.baseEepHeader.version;
+
+       return (version & AR5416_EEP_VER_MAJOR_MASK) >>
+               AR5416_EEP_VER_MAJOR_SHIFT;
 }
 
 static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
 {
-       return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF);
+       u16 version = ah->eeprom.map4k.baseEepHeader.version;
+
+       return version & AR5416_EEP_VER_MINOR_MASK;
 }
 
 #define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
@@ -136,8 +141,8 @@ static u32 ath9k_hw_4k_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
                goto out;
        }
 
-       PR_EEP("Major Version", pBase->version >> 12);
-       PR_EEP("Minor Version", pBase->version & 0xFFF);
+       PR_EEP("Major Version", ath9k_hw_4k_get_eeprom_ver(ah));
+       PR_EEP("Minor Version", ath9k_hw_4k_get_eeprom_rev(ah));
        PR_EEP("Checksum", pBase->checksum);
        PR_EEP("Length", pBase->length);
        PR_EEP("RegDomain1", pBase->regDmn[0]);
@@ -314,14 +319,12 @@ static void ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah,
 
        xpdMask = pEepData->modalHeader.xpdGain;
 
-       if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
-           AR5416_EEP_MINOR_VER_2) {
+       if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2)
                pdGainOverlap_t2 =
                        pEepData->modalHeader.pdGainOverlap;
-       } else {
+       else
                pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
                                            AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
-       }
 
        pCalBChans = pEepData->calFreqPier2G;
        numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS;
@@ -607,10 +610,8 @@ static void ath9k_hw_4k_set_txpower(struct ath_hw *ah,
 
        memset(ratesArray, 0, sizeof(ratesArray));
 
-       if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
-           AR5416_EEP_MINOR_VER_2) {
+       if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2)
                ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
-       }
 
        ath9k_hw_set_4k_power_per_rate_table(ah, chan,
                                             &ratesArray[0], cfgCtl,
@@ -730,8 +731,7 @@ static void ath9k_hw_4k_set_gain(struct ath_hw *ah,
                SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF),
                AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF | AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF);
 
-       if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
-           AR5416_EEP_MINOR_VER_3) {
+       if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_3) {
                txRxAttenLocal = pModal->txRxAttenCh[0];
 
                REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
@@ -1009,16 +1009,14 @@ static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
        REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
                      pModal->thresh62);
 
-       if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
-                                               AR5416_EEP_MINOR_VER_2) {
+       if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2) {
                REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
                              pModal->txFrameToDataStart);
                REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
                              pModal->txFrameToPaOn);
        }
 
-       if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
-                                               AR5416_EEP_MINOR_VER_3) {
+       if (ath9k_hw_4k_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_3) {
                if (IS_CHAN_HT40(chan))
                        REG_RMW_FIELD(ah, AR_PHY_SETTLING,
                                      AR_PHY_SETTLING_SWITCH,
index 7f85bd1435b294e316957d1f7928c5777a99fe81..daeaf12ca23ecff0eb2e42e037829def935577b5 100644 (file)
 
 static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
 {
-       return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF;
+       u16 version = ah->eeprom.map9287.baseEepHeader.version;
+
+       return (version & AR5416_EEP_VER_MAJOR_MASK) >>
+               AR5416_EEP_VER_MAJOR_SHIFT;
 }
 
 static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
 {
-       return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF;
+       u16 version = ah->eeprom.map9287.baseEepHeader.version;
+
+       return version & AR5416_EEP_VER_MINOR_MASK;
 }
 
 static bool __ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
@@ -132,8 +137,8 @@ static u32 ath9k_hw_ar9287_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
                goto out;
        }
 
-       PR_EEP("Major Version", pBase->version >> 12);
-       PR_EEP("Minor Version", pBase->version & 0xFFF);
+       PR_EEP("Major Version", ath9k_hw_ar9287_get_eeprom_ver(ah));
+       PR_EEP("Minor Version", ath9k_hw_ar9287_get_eeprom_rev(ah));
        PR_EEP("Checksum", pBase->checksum);
        PR_EEP("Length", pBase->length);
        PR_EEP("RegDomain1", pBase->regDmn[0]);
@@ -383,8 +388,7 @@ static void ath9k_hw_set_ar9287_power_cal_table(struct ath_hw *ah,
 
        xpdMask = pEepData->modalHeader.xpdGain;
 
-       if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
-           AR9287_EEP_MINOR_VER_2)
+       if (ath9k_hw_ar9287_get_eeprom_rev(ah) >= AR9287_EEP_MINOR_VER_2)
                pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
        else
                pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
@@ -733,8 +737,7 @@ static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
 
        memset(ratesArray, 0, sizeof(ratesArray));
 
-       if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
-           AR9287_EEP_MINOR_VER_2)
+       if (ath9k_hw_ar9287_get_eeprom_rev(ah) >= AR9287_EEP_MINOR_VER_2)
                ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
 
        ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
index e9af4a50234e169235f3898d955e89a4b891f936..bd5bd627e00acd405a85bde9ada1102b376e2e0e 100644 (file)
@@ -79,12 +79,17 @@ static void ath9k_olc_get_pdadcs(struct ath_hw *ah,
 
 static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
 {
-       return ((ah->eeprom.def.baseEepHeader.version >> 12) & 0xF);
+       u16 version = ah->eeprom.def.baseEepHeader.version;
+
+       return (version & AR5416_EEP_VER_MAJOR_MASK) >>
+               AR5416_EEP_VER_MAJOR_SHIFT;
 }
 
 static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
 {
-       return ((ah->eeprom.def.baseEepHeader.version) & 0xFFF);
+       u16 version = ah->eeprom.def.baseEepHeader.version;
+
+       return version & AR5416_EEP_VER_MINOR_MASK;
 }
 
 #define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(u16))
@@ -214,8 +219,8 @@ static u32 ath9k_hw_def_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
                goto out;
        }
 
-       PR_EEP("Major Version", pBase->version >> 12);
-       PR_EEP("Minor Version", pBase->version & 0xFFF);
+       PR_EEP("Major Version", ath9k_hw_def_get_eeprom_ver(ah));
+       PR_EEP("Minor Version", ath9k_hw_def_get_eeprom_rev(ah));
        PR_EEP("Checksum", pBase->checksum);
        PR_EEP("Length", pBase->length);
        PR_EEP("RegDomain1", pBase->regDmn[0]);
@@ -391,27 +396,27 @@ static u32 ath9k_hw_def_get_eeprom(struct ath_hw *ah,
        case EEP_TXGAIN_TYPE:
                return pBase->txGainType;
        case EEP_OL_PWRCTRL:
-               if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
+               if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_19)
                        return pBase->openLoopPwrCntl ? true : false;
                else
                        return false;
        case EEP_RC_CHAIN_MASK:
-               if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
+               if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_19)
                        return pBase->rcChainMask;
                else
                        return 0;
        case EEP_DAC_HPWR_5G:
-               if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
+               if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_20)
                        return pBase->dacHiPwrMode_5G;
                else
                        return 0;
        case EEP_FRAC_N_5G:
-               if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
+               if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_22)
                        return pBase->frac_n_5g;
                else
                        return 0;
        case EEP_PWR_TABLE_OFFSET:
-               if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_21)
+               if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_21)
                        return pBase->pwr_table_offset;
                else
                        return AR5416_PWR_TABLE_OFFSET_DB;
@@ -434,7 +439,7 @@ static void ath9k_hw_def_set_gain(struct ath_hw *ah,
                                  u8 txRxAttenLocal, int regChainOffset, int i)
 {
        ENABLE_REG_RMW_BUFFER(ah);
-       if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
+       if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_3) {
                txRxAttenLocal = pModal->txRxAttenCh[i];
 
                if (AR_SREV_9280_20_OR_LATER(ah)) {
@@ -603,7 +608,7 @@ static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
                              pModal->thresh62);
        }
 
-       if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
+       if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2) {
                REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
                              AR_PHY_TX_END_DATA_START,
                              pModal->txFrameToDataStart);
@@ -611,7 +616,7 @@ static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
                              pModal->txFrameToPaOn);
        }
 
-       if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
+       if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_3) {
                if (IS_CHAN_HT40(chan))
                        REG_RMW_FIELD(ah, AR_PHY_SETTLING,
                                      AR_PHY_SETTLING_SWITCH,
@@ -619,13 +624,14 @@ static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
        }
 
        if (AR_SREV_9280_20_OR_LATER(ah) &&
-           AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
+           ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_19)
                REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
                              AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
                              pModal->miscBits);
 
 
-       if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
+       if (AR_SREV_9280_20(ah) &&
+           ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_20) {
                if (IS_CHAN_2GHZ(chan))
                        REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
                                        eep->baseEepHeader.dacLpMode);
@@ -796,8 +802,7 @@ static void ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
 
        pwr_table_offset = ah->eep_ops->get_eeprom(ah, EEP_PWR_TABLE_OFFSET);
 
-       if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
-           AR5416_EEP_MINOR_VER_2) {
+       if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2) {
                pdGainOverlap_t2 =
                        pEepData->modalHeader[modalIdx].pdGainOverlap;
        } else {
@@ -1169,10 +1174,8 @@ static void ath9k_hw_def_set_txpower(struct ath_hw *ah,
 
        memset(ratesArray, 0, sizeof(ratesArray));
 
-       if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
-           AR5416_EEP_MINOR_VER_2) {
+       if (ath9k_hw_def_get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_2)
                ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
-       }
 
        ath9k_hw_set_def_power_per_rate_table(ah, chan,
                                               &ratesArray[0], cfgCtl,
index 486afa98a5b8d1d73a56829f6d16ecb1316cb66e..5fa98e26f0429009c32bbeb2aa92c65beeb392df 100644 (file)
@@ -1151,8 +1151,9 @@ static u8 ath_get_rate_txpower(struct ath_softc *sc, struct ath_buf *bf,
                if (is_40) {
                        u8 power_ht40delta;
                        struct ar5416_eeprom_def *eep = &ah->eeprom.def;
+                       u16 eeprom_rev = ah->eep_ops->get_eeprom_rev(ah);
 
-                       if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
+                       if (eeprom_rev >= AR5416_EEP_MINOR_VER_2) {
                                bool is_2ghz;
                                struct modal_eep_header *pmodal;