]> Pileus Git - ~andy/linux/commitdiff
bitops: Provide generic sign_extend32 function
authorAndreas Herrmann <andreas.herrmann3@amd.com>
Mon, 30 Aug 2010 19:04:01 +0000 (19:04 +0000)
committerJohn W. Linville <linville@tuxdriver.com>
Mon, 15 Nov 2010 18:27:04 +0000 (13:27 -0500)
This patch moves code out from wireless drivers where two different
functions are defined in three code locations for the same purpose and
provides a common function to sign extend a 32-bit value.

Signed-off-by: Andreas Herrmann <andreas.herrmann3@amd.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/ath/ath5k/phy.c
drivers/net/wireless/ath/ath9k/ar5008_phy.c
drivers/net/wireless/ath/ath9k/ar9002_phy.c
drivers/net/wireless/ath/ath9k/ar9003_phy.c
drivers/net/wireless/ath/ath9k/hw.h
drivers/net/wireless/iwlwifi/iwl-4965.c
include/linux/bitops.h

index 219367884e640a60a99a99eba59478aaba9bc1da..6b43f535ff5374d018438a809804b68ee9820eb3 100644 (file)
@@ -1102,18 +1102,12 @@ int ath5k_hw_channel(struct ath5k_hw *ah, struct ieee80211_channel *channel)
   PHY calibration
 \*****************/
 
-static int sign_extend(int val, const int nbits)
-{
-       int order = BIT(nbits-1);
-       return (val ^ order) - order;
-}
-
 static s32 ath5k_hw_read_measured_noise_floor(struct ath5k_hw *ah)
 {
        s32 val;
 
        val = ath5k_hw_reg_read(ah, AR5K_PHY_NF);
-       return sign_extend(AR5K_REG_MS(val, AR5K_PHY_NF_MINCCA_PWR), 9);
+       return sign_extend32(AR5K_REG_MS(val, AR5K_PHY_NF_MINCCA_PWR), 8);
 }
 
 void ath5k_hw_init_nfcal_hist(struct ath5k_hw *ah)
index 777a602176f244ba41800c99dd406e38c38f26b2..c83a22cfbe1ee24b4e342e34b20f026d794f8feb 100644 (file)
@@ -1490,25 +1490,25 @@ static void ar5008_hw_do_getnf(struct ath_hw *ah,
        int16_t nf;
 
        nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
-       nfarray[0] = sign_extend(nf, 9);
+       nfarray[0] = sign_extend32(nf, 8);
 
        nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR);
-       nfarray[1] = sign_extend(nf, 9);
+       nfarray[1] = sign_extend32(nf, 8);
 
        nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR);
-       nfarray[2] = sign_extend(nf, 9);
+       nfarray[2] = sign_extend32(nf, 8);
 
        if (!IS_CHAN_HT40(ah->curchan))
                return;
 
        nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
-       nfarray[3] = sign_extend(nf, 9);
+       nfarray[3] = sign_extend32(nf, 8);
 
        nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR);
-       nfarray[4] = sign_extend(nf, 9);
+       nfarray[4] = sign_extend32(nf, 8);
 
        nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR);
-       nfarray[5] = sign_extend(nf, 9);
+       nfarray[5] = sign_extend32(nf, 8);
 }
 
 /*
index c00cdc67b55ba5291f9ebc758d342f7dfb3184a1..3fb97fdc1240d7a0fb50b1b2102b0810a1d5713f 100644 (file)
@@ -473,21 +473,21 @@ static void ar9002_hw_do_getnf(struct ath_hw *ah,
        int16_t nf;
 
        nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
-       nfarray[0] = sign_extend(nf, 9);
+       nfarray[0] = sign_extend32(nf, 8);
 
        nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR9280_PHY_EXT_MINCCA_PWR);
        if (IS_CHAN_HT40(ah->curchan))
-               nfarray[3] = sign_extend(nf, 9);
+               nfarray[3] = sign_extend32(nf, 8);
 
        if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
                return;
 
        nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR9280_PHY_CH1_MINCCA_PWR);
-       nfarray[1] = sign_extend(nf, 9);
+       nfarray[1] = sign_extend32(nf, 8);
 
        nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR9280_PHY_CH1_EXT_MINCCA_PWR);
        if (IS_CHAN_HT40(ah->curchan))
-               nfarray[4] = sign_extend(nf, 9);
+               nfarray[4] = sign_extend32(nf, 8);
 }
 
 static void ar9002_hw_set_nf_limits(struct ath_hw *ah)
index 06a9c4cd2f444bbc9304827f6debd7d3e6fa1869..44c5454b2ad8273cbfa905ee7f098ead379867ae 100644 (file)
@@ -1023,25 +1023,25 @@ static void ar9003_hw_do_getnf(struct ath_hw *ah,
        int16_t nf;
 
        nf = MS(REG_READ(ah, AR_PHY_CCA_0), AR_PHY_MINCCA_PWR);
-       nfarray[0] = sign_extend(nf, 9);
+       nfarray[0] = sign_extend32(nf, 8);
 
        nf = MS(REG_READ(ah, AR_PHY_CCA_1), AR_PHY_CH1_MINCCA_PWR);
-       nfarray[1] = sign_extend(nf, 9);
+       nfarray[1] = sign_extend32(nf, 8);
 
        nf = MS(REG_READ(ah, AR_PHY_CCA_2), AR_PHY_CH2_MINCCA_PWR);
-       nfarray[2] = sign_extend(nf, 9);
+       nfarray[2] = sign_extend32(nf, 8);
 
        if (!IS_CHAN_HT40(ah->curchan))
                return;
 
        nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
-       nfarray[3] = sign_extend(nf, 9);
+       nfarray[3] = sign_extend32(nf, 8);
 
        nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_1), AR_PHY_CH1_EXT_MINCCA_PWR);
-       nfarray[4] = sign_extend(nf, 9);
+       nfarray[4] = sign_extend32(nf, 8);
 
        nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_2), AR_PHY_CH2_EXT_MINCCA_PWR);
-       nfarray[5] = sign_extend(nf, 9);
+       nfarray[5] = sign_extend32(nf, 8);
 }
 
 static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
index e5b72262fd967785ee263a7a3cb5624ee0833a11..f821a28bcda3febf568eebaf177c39f547e74b99 100644 (file)
@@ -825,12 +825,6 @@ static inline struct ath_hw_ops *ath9k_hw_ops(struct ath_hw *ah)
        return &ah->ops;
 }
 
-static inline int sign_extend(int val, const int nbits)
-{
-       int order = BIT(nbits-1);
-       return (val ^ order) - order;
-}
-
 /* Initialization, Detach, Reset */
 const char *ath9k_hw_probe(u16 vendorid, u16 devid);
 void ath9k_hw_deinit(struct ath_hw *ah);
index cd14843878ae0d04d7ef3d5ae4f2a9d4e41a8c8f..4748d067eb1dd577759b9061c128d521bfb0b2ce 100644 (file)
@@ -1686,22 +1686,6 @@ static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
                        tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] = bc_ent;
 }
 
-/**
- * sign_extend - Sign extend a value using specified bit as sign-bit
- *
- * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
- * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
- *
- * @param oper value to sign extend
- * @param index 0 based bit index (0<=index<32) to sign bit
- */
-static s32 sign_extend(u32 oper, int index)
-{
-       u8 shift = 31 - index;
-
-       return (s32)(oper << shift) >> shift;
-}
-
 /**
  * iwl4965_hw_get_temperature - return the calibrated temperature (in Kelvin)
  * @statistics: Provides the temperature reading from the uCode
@@ -1739,9 +1723,9 @@ static int iwl4965_hw_get_temperature(struct iwl_priv *priv)
         * "initialize" ALIVE response.
         */
        if (!test_bit(STATUS_TEMPERATURE, &priv->status))
-               vt = sign_extend(R4, 23);
+               vt = sign_extend32(R4, 23);
        else
-               vt = sign_extend(le32_to_cpu(priv->_agn.statistics.
+               vt = sign_extend32(le32_to_cpu(priv->_agn.statistics.
                                 general.common.temperature), 23);
 
        IWL_DEBUG_TEMP(priv, "Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt);
index 827cc95711ef82563e0f7a1718f364ce8adfd451..2184c6b97aebb699206e2eb7426bd716b8f0e54f 100644 (file)
@@ -109,6 +109,17 @@ static inline __u8 ror8(__u8 word, unsigned int shift)
        return (word >> shift) | (word << (8 - shift));
 }
 
+/**
+ * sign_extend32 - sign extend a 32-bit value using specified bit as sign-bit
+ * @value: value to sign extend
+ * @index: 0 based bit index (0<=index<32) to sign bit
+ */
+static inline __s32 sign_extend32(__u32 value, int index)
+{
+       __u8 shift = 31 - index;
+       return (__s32)(value << shift) >> shift;
+}
+
 static inline unsigned fls_long(unsigned long l)
 {
        if (sizeof(l) == 4)