Commit bc206802 authored by Vasanthakumar Thiagarajan's avatar Vasanthakumar Thiagarajan Committed by John W. Linville

ath9k_hw: Add helper function for interpolation

Also round off interpolated values this would improve power
accuracy by 0.5dB in some cases.
Signed-off-by: default avatarVasanthakumar Thiagarajan <vasanth@atheros.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 15cbbc44
...@@ -2982,6 +2982,16 @@ static int ath9k_hw_ar9300_check_eeprom(struct ath_hw *ah) ...@@ -2982,6 +2982,16 @@ static int ath9k_hw_ar9300_check_eeprom(struct ath_hw *ah)
return 0; return 0;
} }
static int interpolate(int x, int xa, int xb, int ya, int yb)
{
int bf, factor, plus;
bf = 2 * (yb - ya) * (x - xa) / (xb - xa);
factor = bf / 2;
plus = bf % 2;
return ya + factor + plus;
}
static u32 ath9k_hw_ar9300_get_eeprom(struct ath_hw *ah, static u32 ath9k_hw_ar9300_get_eeprom(struct ath_hw *ah,
enum eeprom_param param) enum eeprom_param param)
{ {
...@@ -3614,7 +3624,7 @@ static int ar9003_hw_power_interpolate(int32_t x, ...@@ -3614,7 +3624,7 @@ static int ar9003_hw_power_interpolate(int32_t x,
if (hx == lx) if (hx == lx)
y = ly; y = ly;
else /* interpolate */ else /* interpolate */
y = ly + (((x - lx) * (hy - ly)) / (hx - lx)); y = interpolate(x, lx, hx, ly, hy);
} else /* only low is good, use it */ } else /* only low is good, use it */
y = ly; y = ly;
} else if (hhave) /* only high is good, use it */ } else if (hhave) /* only high is good, use it */
...@@ -4204,25 +4214,23 @@ static int ar9003_hw_calibration_apply(struct ath_hw *ah, int frequency) ...@@ -4204,25 +4214,23 @@ static int ar9003_hw_calibration_apply(struct ath_hw *ah, int frequency)
/* so is the high frequency, interpolate */ /* so is the high frequency, interpolate */
if (hfrequency[ichain] - frequency < 1000) { if (hfrequency[ichain] - frequency < 1000) {
correction[ichain] = lcorrection[ichain] + correction[ichain] = interpolate(frequency,
(((frequency - lfrequency[ichain]) * lfrequency[ichain],
(hcorrection[ichain] - hfrequency[ichain],
lcorrection[ichain])) / lcorrection[ichain],
(hfrequency[ichain] - lfrequency[ichain])); hcorrection[ichain]);
temperature[ichain] = ltemperature[ichain] + temperature[ichain] = interpolate(frequency,
(((frequency - lfrequency[ichain]) * lfrequency[ichain],
(htemperature[ichain] - hfrequency[ichain],
ltemperature[ichain])) / ltemperature[ichain],
(hfrequency[ichain] - lfrequency[ichain])); htemperature[ichain]);
voltage[ichain] = voltage[ichain] = interpolate(frequency,
lvoltage[ichain] + lfrequency[ichain],
(((frequency - hfrequency[ichain],
lfrequency[ichain]) * (hvoltage[ichain] - lvoltage[ichain],
lvoltage[ichain])) hvoltage[ichain]);
/ (hfrequency[ichain] -
lfrequency[ichain]));
} }
/* only low is good, use it */ /* only low is good, use it */
else { else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment