ath9k: implement temperature compensation support for AR93xx and newer
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / 328-ath9k_hw-implement-temperature-compensation-support-.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Mon, 11 Jul 2016 11:35:55 +0200
3 Subject: [PATCH] ath9k_hw: implement temperature compensation support for
4 AR9003+
5
6 Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 ---
8
9 --- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
10 +++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
11 @@ -33,6 +33,7 @@ struct coeff {
12
13 enum ar9003_cal_types {
14 IQ_MISMATCH_CAL = BIT(0),
15 + TEMP_COMP_CAL = BIT(1),
16 };
17
18 static void ar9003_hw_setup_calibration(struct ath_hw *ah,
19 @@ -58,6 +59,12 @@ static void ar9003_hw_setup_calibration(
20 /* Kick-off cal */
21 REG_SET_BIT(ah, AR_PHY_TIMING4, AR_PHY_TIMING4_DO_CAL);
22 break;
23 + case TEMP_COMP_CAL:
24 + ath_dbg(common, CALIBRATE,
25 + "starting Temperature Compensation Calibration\n");
26 + REG_SET_BIT(ah, AR_CH0_THERM, AR_CH0_THERM_LOCAL);
27 + REG_SET_BIT(ah, AR_CH0_THERM, AR_CH0_THERM_START);
28 + break;
29 default:
30 ath_err(common, "Invalid calibration type\n");
31 break;
32 @@ -86,7 +93,8 @@ static bool ar9003_hw_per_calibration(st
33 /*
34 * Accumulate cal measures for active chains
35 */
36 - cur_caldata->calCollect(ah);
37 + if (cur_caldata->calCollect)
38 + cur_caldata->calCollect(ah);
39 ah->cal_samples++;
40
41 if (ah->cal_samples >= cur_caldata->calNumSamples) {
42 @@ -99,7 +107,8 @@ static bool ar9003_hw_per_calibration(st
43 /*
44 * Process accumulated data
45 */
46 - cur_caldata->calPostProc(ah, numChains);
47 + if (cur_caldata->calPostProc)
48 + cur_caldata->calPostProc(ah, numChains);
49
50 /* Calibration has finished. */
51 caldata->CalValid |= cur_caldata->calType;
52 @@ -314,9 +323,16 @@ static const struct ath9k_percal_data iq
53 ar9003_hw_iqcalibrate
54 };
55
56 +static const struct ath9k_percal_data temp_cal_single_sample = {
57 + TEMP_COMP_CAL,
58 + MIN_CAL_SAMPLES,
59 + PER_MAX_LOG_COUNT,
60 +};
61 +
62 static void ar9003_hw_init_cal_settings(struct ath_hw *ah)
63 {
64 ah->iq_caldata.calData = &iq_cal_single_sample;
65 + ah->temp_caldata.calData = &temp_cal_single_sample;
66
67 if (AR_SREV_9300_20_OR_LATER(ah)) {
68 ah->enabled_cals |= TX_IQ_CAL;
69 @@ -324,7 +340,7 @@ static void ar9003_hw_init_cal_settings(
70 ah->enabled_cals |= TX_IQ_ON_AGC_CAL;
71 }
72
73 - ah->supp_cals = IQ_MISMATCH_CAL;
74 + ah->supp_cals = IQ_MISMATCH_CAL | TEMP_COMP_CAL;
75 }
76
77 #define OFF_UPPER_LT 24
78 @@ -1383,6 +1399,9 @@ static void ar9003_hw_init_cal_common(st
79 INIT_CAL(&ah->iq_caldata);
80 INSERT_CAL(ah, &ah->iq_caldata);
81
82 + INIT_CAL(&ah->temp_caldata);
83 + INSERT_CAL(ah, &ah->temp_caldata);
84 +
85 /* Initialize current pointer to first element in list */
86 ah->cal_list_curr = ah->cal_list;
87
88 --- a/drivers/net/wireless/ath/ath9k/hw.h
89 +++ b/drivers/net/wireless/ath/ath9k/hw.h
90 @@ -830,6 +830,7 @@ struct ath_hw {
91 /* Calibration */
92 u32 supp_cals;
93 struct ath9k_cal_list iq_caldata;
94 + struct ath9k_cal_list temp_caldata;
95 struct ath9k_cal_list adcgain_caldata;
96 struct ath9k_cal_list adcdc_caldata;
97 struct ath9k_cal_list *cal_list;