aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorAndreas Herrmann <andreas.herrmann3@amd.com>2010-08-30 15:04:01 -0400
committerJohn W. Linville <linville@tuxdriver.com>2010-11-15 13:27:04 -0500
commit7919a57bc608140aa8614c19eac40c6916fb61d2 (patch)
tree0813ff8983a937eae8636808167bc59aa0e80c34 /drivers/net
parente4b3fdb80021bc0a3239bfc2a873a6d7c6ac52a1 (diff)
bitops: Provide generic sign_extend32 function
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>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/wireless/ath/ath5k/phy.c8
-rw-r--r--drivers/net/wireless/ath/ath9k/ar5008_phy.c12
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9002_phy.c8
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.c12
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c20
6 files changed, 19 insertions, 47 deletions
diff --git a/drivers/net/wireless/ath/ath5k/phy.c b/drivers/net/wireless/ath/ath5k/phy.c
index 219367884e64..6b43f535ff53 100644
--- a/drivers/net/wireless/ath/ath5k/phy.c
+++ b/drivers/net/wireless/ath/ath5k/phy.c
@@ -1102,18 +1102,12 @@ int ath5k_hw_channel(struct ath5k_hw *ah, struct ieee80211_channel *channel)
1102 PHY calibration 1102 PHY calibration
1103\*****************/ 1103\*****************/
1104 1104
1105static int sign_extend(int val, const int nbits)
1106{
1107 int order = BIT(nbits-1);
1108 return (val ^ order) - order;
1109}
1110
1111static s32 ath5k_hw_read_measured_noise_floor(struct ath5k_hw *ah) 1105static s32 ath5k_hw_read_measured_noise_floor(struct ath5k_hw *ah)
1112{ 1106{
1113 s32 val; 1107 s32 val;
1114 1108
1115 val = ath5k_hw_reg_read(ah, AR5K_PHY_NF); 1109 val = ath5k_hw_reg_read(ah, AR5K_PHY_NF);
1116 return sign_extend(AR5K_REG_MS(val, AR5K_PHY_NF_MINCCA_PWR), 9); 1110 return sign_extend32(AR5K_REG_MS(val, AR5K_PHY_NF_MINCCA_PWR), 8);
1117} 1111}
1118 1112
1119void ath5k_hw_init_nfcal_hist(struct ath5k_hw *ah) 1113void ath5k_hw_init_nfcal_hist(struct ath5k_hw *ah)
diff --git a/drivers/net/wireless/ath/ath9k/ar5008_phy.c b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
index 777a602176f2..c83a22cfbe1e 100644
--- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
@@ -1490,25 +1490,25 @@ static void ar5008_hw_do_getnf(struct ath_hw *ah,
1490 int16_t nf; 1490 int16_t nf;
1491 1491
1492 nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR); 1492 nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
1493 nfarray[0] = sign_extend(nf, 9); 1493 nfarray[0] = sign_extend32(nf, 8);
1494 1494
1495 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR); 1495 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR);
1496 nfarray[1] = sign_extend(nf, 9); 1496 nfarray[1] = sign_extend32(nf, 8);
1497 1497
1498 nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR); 1498 nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR);
1499 nfarray[2] = sign_extend(nf, 9); 1499 nfarray[2] = sign_extend32(nf, 8);
1500 1500
1501 if (!IS_CHAN_HT40(ah->curchan)) 1501 if (!IS_CHAN_HT40(ah->curchan))
1502 return; 1502 return;
1503 1503
1504 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR); 1504 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
1505 nfarray[3] = sign_extend(nf, 9); 1505 nfarray[3] = sign_extend32(nf, 8);
1506 1506
1507 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR); 1507 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR);
1508 nfarray[4] = sign_extend(nf, 9); 1508 nfarray[4] = sign_extend32(nf, 8);
1509 1509
1510 nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR); 1510 nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR);
1511 nfarray[5] = sign_extend(nf, 9); 1511 nfarray[5] = sign_extend32(nf, 8);
1512} 1512}
1513 1513
1514/* 1514/*
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_phy.c b/drivers/net/wireless/ath/ath9k/ar9002_phy.c
index c00cdc67b55b..3fb97fdc1240 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_phy.c
@@ -473,21 +473,21 @@ static void ar9002_hw_do_getnf(struct ath_hw *ah,
473 int16_t nf; 473 int16_t nf;
474 474
475 nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR); 475 nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
476 nfarray[0] = sign_extend(nf, 9); 476 nfarray[0] = sign_extend32(nf, 8);
477 477
478 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR9280_PHY_EXT_MINCCA_PWR); 478 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR9280_PHY_EXT_MINCCA_PWR);
479 if (IS_CHAN_HT40(ah->curchan)) 479 if (IS_CHAN_HT40(ah->curchan))
480 nfarray[3] = sign_extend(nf, 9); 480 nfarray[3] = sign_extend32(nf, 8);
481 481
482 if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) 482 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
483 return; 483 return;
484 484
485 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR9280_PHY_CH1_MINCCA_PWR); 485 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR9280_PHY_CH1_MINCCA_PWR);
486 nfarray[1] = sign_extend(nf, 9); 486 nfarray[1] = sign_extend32(nf, 8);
487 487
488 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR9280_PHY_CH1_EXT_MINCCA_PWR); 488 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR9280_PHY_CH1_EXT_MINCCA_PWR);
489 if (IS_CHAN_HT40(ah->curchan)) 489 if (IS_CHAN_HT40(ah->curchan))
490 nfarray[4] = sign_extend(nf, 9); 490 nfarray[4] = sign_extend32(nf, 8);
491} 491}
492 492
493static void ar9002_hw_set_nf_limits(struct ath_hw *ah) 493static void ar9002_hw_set_nf_limits(struct ath_hw *ah)
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
index 06a9c4cd2f44..44c5454b2ad8 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
@@ -1023,25 +1023,25 @@ static void ar9003_hw_do_getnf(struct ath_hw *ah,
1023 int16_t nf; 1023 int16_t nf;
1024 1024
1025 nf = MS(REG_READ(ah, AR_PHY_CCA_0), AR_PHY_MINCCA_PWR); 1025 nf = MS(REG_READ(ah, AR_PHY_CCA_0), AR_PHY_MINCCA_PWR);
1026 nfarray[0] = sign_extend(nf, 9); 1026 nfarray[0] = sign_extend32(nf, 8);
1027 1027
1028 nf = MS(REG_READ(ah, AR_PHY_CCA_1), AR_PHY_CH1_MINCCA_PWR); 1028 nf = MS(REG_READ(ah, AR_PHY_CCA_1), AR_PHY_CH1_MINCCA_PWR);
1029 nfarray[1] = sign_extend(nf, 9); 1029 nfarray[1] = sign_extend32(nf, 8);
1030 1030
1031 nf = MS(REG_READ(ah, AR_PHY_CCA_2), AR_PHY_CH2_MINCCA_PWR); 1031 nf = MS(REG_READ(ah, AR_PHY_CCA_2), AR_PHY_CH2_MINCCA_PWR);
1032 nfarray[2] = sign_extend(nf, 9); 1032 nfarray[2] = sign_extend32(nf, 8);
1033 1033
1034 if (!IS_CHAN_HT40(ah->curchan)) 1034 if (!IS_CHAN_HT40(ah->curchan))
1035 return; 1035 return;
1036 1036
1037 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR); 1037 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
1038 nfarray[3] = sign_extend(nf, 9); 1038 nfarray[3] = sign_extend32(nf, 8);
1039 1039
1040 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_1), AR_PHY_CH1_EXT_MINCCA_PWR); 1040 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_1), AR_PHY_CH1_EXT_MINCCA_PWR);
1041 nfarray[4] = sign_extend(nf, 9); 1041 nfarray[4] = sign_extend32(nf, 8);
1042 1042
1043 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_2), AR_PHY_CH2_EXT_MINCCA_PWR); 1043 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_2), AR_PHY_CH2_EXT_MINCCA_PWR);
1044 nfarray[5] = sign_extend(nf, 9); 1044 nfarray[5] = sign_extend32(nf, 8);
1045} 1045}
1046 1046
1047static void ar9003_hw_set_nf_limits(struct ath_hw *ah) 1047static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index e5b72262fd96..f821a28bcda3 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -825,12 +825,6 @@ static inline struct ath_hw_ops *ath9k_hw_ops(struct ath_hw *ah)
825 return &ah->ops; 825 return &ah->ops;
826} 826}
827 827
828static inline int sign_extend(int val, const int nbits)
829{
830 int order = BIT(nbits-1);
831 return (val ^ order) - order;
832}
833
834/* Initialization, Detach, Reset */ 828/* Initialization, Detach, Reset */
835const char *ath9k_hw_probe(u16 vendorid, u16 devid); 829const char *ath9k_hw_probe(u16 vendorid, u16 devid);
836void ath9k_hw_deinit(struct ath_hw *ah); 830void ath9k_hw_deinit(struct ath_hw *ah);
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index cd14843878ae..4748d067eb1d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -1687,22 +1687,6 @@ static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
1687} 1687}
1688 1688
1689/** 1689/**
1690 * sign_extend - Sign extend a value using specified bit as sign-bit
1691 *
1692 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
1693 * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
1694 *
1695 * @param oper value to sign extend
1696 * @param index 0 based bit index (0<=index<32) to sign bit
1697 */
1698static s32 sign_extend(u32 oper, int index)
1699{
1700 u8 shift = 31 - index;
1701
1702 return (s32)(oper << shift) >> shift;
1703}
1704
1705/**
1706 * iwl4965_hw_get_temperature - return the calibrated temperature (in Kelvin) 1690 * iwl4965_hw_get_temperature - return the calibrated temperature (in Kelvin)
1707 * @statistics: Provides the temperature reading from the uCode 1691 * @statistics: Provides the temperature reading from the uCode
1708 * 1692 *
@@ -1739,9 +1723,9 @@ static int iwl4965_hw_get_temperature(struct iwl_priv *priv)
1739 * "initialize" ALIVE response. 1723 * "initialize" ALIVE response.
1740 */ 1724 */
1741 if (!test_bit(STATUS_TEMPERATURE, &priv->status)) 1725 if (!test_bit(STATUS_TEMPERATURE, &priv->status))
1742 vt = sign_extend(R4, 23); 1726 vt = sign_extend32(R4, 23);
1743 else 1727 else
1744 vt = sign_extend(le32_to_cpu(priv->_agn.statistics. 1728 vt = sign_extend32(le32_to_cpu(priv->_agn.statistics.
1745 general.common.temperature), 23); 1729 general.common.temperature), 23);
1746 1730
1747 IWL_DEBUG_TEMP(priv, "Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt); 1731 IWL_DEBUG_TEMP(priv, "Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt);