1*572ff6f6SMatthew Dillon /*
2*572ff6f6SMatthew Dillon  * Copyright (c) 2008-2010 Atheros Communications Inc.
3*572ff6f6SMatthew Dillon  * Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd.
4*572ff6f6SMatthew Dillon  *
5*572ff6f6SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
6*572ff6f6SMatthew Dillon  * modification, are permitted provided that the following conditions
7*572ff6f6SMatthew Dillon  * are met:
8*572ff6f6SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
9*572ff6f6SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
10*572ff6f6SMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
11*572ff6f6SMatthew Dillon  *    notice, this list of conditions and the following disclaimer in the
12*572ff6f6SMatthew Dillon  *    documentation and/or other materials provided with the distribution.
13*572ff6f6SMatthew Dillon  *
14*572ff6f6SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*572ff6f6SMatthew Dillon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*572ff6f6SMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*572ff6f6SMatthew Dillon  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*572ff6f6SMatthew Dillon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*572ff6f6SMatthew Dillon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*572ff6f6SMatthew Dillon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*572ff6f6SMatthew Dillon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*572ff6f6SMatthew Dillon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*572ff6f6SMatthew Dillon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*572ff6f6SMatthew Dillon  * SUCH DAMAGE.
25*572ff6f6SMatthew Dillon  *
26*572ff6f6SMatthew Dillon  * $FreeBSD$
27*572ff6f6SMatthew Dillon  */
28*572ff6f6SMatthew Dillon #include "opt_ah.h"
29*572ff6f6SMatthew Dillon #include "ah.h"
30*572ff6f6SMatthew Dillon #include "ah_internal.h"
31*572ff6f6SMatthew Dillon 
32*572ff6f6SMatthew Dillon #include "ah_eeprom_v4k.h"
33*572ff6f6SMatthew Dillon 
34*572ff6f6SMatthew Dillon #include "ar9002/ar9285.h"
35*572ff6f6SMatthew Dillon #include "ar5416/ar5416reg.h"
36*572ff6f6SMatthew Dillon #include "ar5416/ar5416phy.h"
37*572ff6f6SMatthew Dillon #include "ar9002/ar9002phy.h"
38*572ff6f6SMatthew Dillon #include "ar9002/ar9285phy.h"
39*572ff6f6SMatthew Dillon #include "ar9002/ar9285an.h"
40*572ff6f6SMatthew Dillon 
41*572ff6f6SMatthew Dillon #include "ar9002/ar9285_cal.h"
42*572ff6f6SMatthew Dillon 
43*572ff6f6SMatthew Dillon #define	AR9285_CLCAL_REDO_THRESH	1
44*572ff6f6SMatthew Dillon #define	MAX_PACAL_SKIPCOUNT		8
45*572ff6f6SMatthew Dillon 
46*572ff6f6SMatthew Dillon #define	N(a)	(sizeof (a) / sizeof (a[0]))
47*572ff6f6SMatthew Dillon 
48*572ff6f6SMatthew Dillon static void
ar9285_hw_pa_cal(struct ath_hal * ah,HAL_BOOL is_reset)49*572ff6f6SMatthew Dillon ar9285_hw_pa_cal(struct ath_hal *ah, HAL_BOOL is_reset)
50*572ff6f6SMatthew Dillon {
51*572ff6f6SMatthew Dillon 	uint32_t regVal;
52*572ff6f6SMatthew Dillon 	int i, offset, offs_6_1, offs_0;
53*572ff6f6SMatthew Dillon 	uint32_t ccomp_org, reg_field;
54*572ff6f6SMatthew Dillon 	uint32_t regList[][2] = {
55*572ff6f6SMatthew Dillon 		{ 0x786c, 0 },
56*572ff6f6SMatthew Dillon 		{ 0x7854, 0 },
57*572ff6f6SMatthew Dillon 		{ 0x7820, 0 },
58*572ff6f6SMatthew Dillon 		{ 0x7824, 0 },
59*572ff6f6SMatthew Dillon 		{ 0x7868, 0 },
60*572ff6f6SMatthew Dillon 		{ 0x783c, 0 },
61*572ff6f6SMatthew Dillon 		{ 0x7838, 0 },
62*572ff6f6SMatthew Dillon 	};
63*572ff6f6SMatthew Dillon 
64*572ff6f6SMatthew Dillon 	/* PA CAL is not needed for high power solution */
65*572ff6f6SMatthew Dillon 	if (ath_hal_eepromGet(ah, AR_EEP_TXGAIN_TYPE, AH_NULL) ==
66*572ff6f6SMatthew Dillon 	    AR5416_EEP_TXGAIN_HIGH_POWER)
67*572ff6f6SMatthew Dillon 		return;
68*572ff6f6SMatthew Dillon 
69*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_PERCAL, "Running PA Calibration\n");
70*572ff6f6SMatthew Dillon 
71*572ff6f6SMatthew Dillon 	for (i = 0; i < N(regList); i++)
72*572ff6f6SMatthew Dillon 		regList[i][1] = OS_REG_READ(ah, regList[i][0]);
73*572ff6f6SMatthew Dillon 
74*572ff6f6SMatthew Dillon 	regVal = OS_REG_READ(ah, 0x7834);
75*572ff6f6SMatthew Dillon 	regVal &= (~(0x1));
76*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, 0x7834, regVal);
77*572ff6f6SMatthew Dillon 	regVal = OS_REG_READ(ah, 0x9808);
78*572ff6f6SMatthew Dillon 	regVal |= (0x1 << 27);
79*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, 0x9808, regVal);
80*572ff6f6SMatthew Dillon 
81*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC, 1);
82*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1, 1);
83*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I, 1);
84*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF, 1);
85*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL, 0);
86*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB, 0);
87*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL, 0);
88*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1, 0);
89*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2, 0);
90*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT, 0);
91*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G8, AR9285_AN_RF2G8_PADRVGN2TAB0, 7);
92*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PADRVGN2TAB0, 0);
93*572ff6f6SMatthew Dillon 	ccomp_org = MS(OS_REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_CCOMP);
94*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, 0xf);
95*572ff6f6SMatthew Dillon 
96*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR9285_AN_TOP2, 0xca0358a0);
97*572ff6f6SMatthew Dillon 	OS_DELAY(30);
98*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, 0);
99*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 0);
100*572ff6f6SMatthew Dillon 
101*572ff6f6SMatthew Dillon 	for (i = 6; i > 0; i--) {
102*572ff6f6SMatthew Dillon 		regVal = OS_REG_READ(ah, 0x7834);
103*572ff6f6SMatthew Dillon 		regVal |= (1 << (19 + i));
104*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, 0x7834, regVal);
105*572ff6f6SMatthew Dillon 		OS_DELAY(1);
106*572ff6f6SMatthew Dillon 		regVal = OS_REG_READ(ah, 0x7834);
107*572ff6f6SMatthew Dillon 		regVal &= (~(0x1 << (19 + i)));
108*572ff6f6SMatthew Dillon 		reg_field = MS(OS_REG_READ(ah, 0x7840), AR9285_AN_RXTXBB1_SPARE9);
109*572ff6f6SMatthew Dillon 		regVal |= (reg_field << (19 + i));
110*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, 0x7834, regVal);
111*572ff6f6SMatthew Dillon 	}
112*572ff6f6SMatthew Dillon 
113*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, 1);
114*572ff6f6SMatthew Dillon 	OS_DELAY(1);
115*572ff6f6SMatthew Dillon 	reg_field = MS(OS_REG_READ(ah, AR9285_AN_RF2G9), AR9285_AN_RXTXBB1_SPARE9);
116*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, reg_field);
117*572ff6f6SMatthew Dillon 	offs_6_1 = MS(OS_REG_READ(ah, AR9285_AN_RF2G6), AR9285_AN_RF2G6_OFFS);
118*572ff6f6SMatthew Dillon 	offs_0   = MS(OS_REG_READ(ah, AR9285_AN_RF2G3), AR9285_AN_RF2G3_PDVCCOMP);
119*572ff6f6SMatthew Dillon 
120*572ff6f6SMatthew Dillon 	offset = (offs_6_1<<1) | offs_0;
121*572ff6f6SMatthew Dillon 	offset = offset - 0;
122*572ff6f6SMatthew Dillon 	offs_6_1 = offset>>1;
123*572ff6f6SMatthew Dillon 	offs_0 = offset & 1;
124*572ff6f6SMatthew Dillon 
125*572ff6f6SMatthew Dillon 	if ((!is_reset) && (AH9285(ah)->pacal_info.prev_offset == offset)) {
126*572ff6f6SMatthew Dillon 		if (AH9285(ah)->pacal_info.max_skipcount < MAX_PACAL_SKIPCOUNT)
127*572ff6f6SMatthew Dillon 			AH9285(ah)->pacal_info.max_skipcount =
128*572ff6f6SMatthew Dillon 				2 * AH9285(ah)->pacal_info.max_skipcount;
129*572ff6f6SMatthew Dillon 		AH9285(ah)->pacal_info.skipcount = AH9285(ah)->pacal_info.max_skipcount;
130*572ff6f6SMatthew Dillon 	} else {
131*572ff6f6SMatthew Dillon 		AH9285(ah)->pacal_info.max_skipcount = 1;
132*572ff6f6SMatthew Dillon 		AH9285(ah)->pacal_info.skipcount = 0;
133*572ff6f6SMatthew Dillon 		AH9285(ah)->pacal_info.prev_offset = offset;
134*572ff6f6SMatthew Dillon 	}
135*572ff6f6SMatthew Dillon 
136*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS, offs_6_1);
137*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP, offs_0);
138*572ff6f6SMatthew Dillon 
139*572ff6f6SMatthew Dillon 	regVal = OS_REG_READ(ah, 0x7834);
140*572ff6f6SMatthew Dillon 	regVal |= 0x1;
141*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, 0x7834, regVal);
142*572ff6f6SMatthew Dillon 	regVal = OS_REG_READ(ah, 0x9808);
143*572ff6f6SMatthew Dillon 	regVal &= (~(0x1 << 27));
144*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, 0x9808, regVal);
145*572ff6f6SMatthew Dillon 
146*572ff6f6SMatthew Dillon 	for (i = 0; i < N(regList); i++)
147*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, regList[i][0], regList[i][1]);
148*572ff6f6SMatthew Dillon 
149*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR9285_AN_RF2G6, AR9285_AN_RF2G6_CCOMP, ccomp_org);
150*572ff6f6SMatthew Dillon }
151*572ff6f6SMatthew Dillon 
152*572ff6f6SMatthew Dillon void
ar9002_hw_pa_cal(struct ath_hal * ah,HAL_BOOL is_reset)153*572ff6f6SMatthew Dillon ar9002_hw_pa_cal(struct ath_hal *ah, HAL_BOOL is_reset)
154*572ff6f6SMatthew Dillon {
155*572ff6f6SMatthew Dillon 	if (AR_SREV_KITE_11_OR_LATER(ah)) {
156*572ff6f6SMatthew Dillon 		if (is_reset || !AH9285(ah)->pacal_info.skipcount)
157*572ff6f6SMatthew Dillon 			ar9285_hw_pa_cal(ah, is_reset);
158*572ff6f6SMatthew Dillon 		else
159*572ff6f6SMatthew Dillon 			AH9285(ah)->pacal_info.skipcount--;
160*572ff6f6SMatthew Dillon 	}
161*572ff6f6SMatthew Dillon }
162*572ff6f6SMatthew Dillon 
163*572ff6f6SMatthew Dillon /* Carrier leakage Calibration fix */
164*572ff6f6SMatthew Dillon static HAL_BOOL
ar9285_hw_cl_cal(struct ath_hal * ah,const struct ieee80211_channel * chan)165*572ff6f6SMatthew Dillon ar9285_hw_cl_cal(struct ath_hal *ah, const struct ieee80211_channel *chan)
166*572ff6f6SMatthew Dillon {
167*572ff6f6SMatthew Dillon 	OS_REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE);
168*572ff6f6SMatthew Dillon 	if (IEEE80211_IS_CHAN_HT20(chan)) {
169*572ff6f6SMatthew Dillon 		OS_REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE);
170*572ff6f6SMatthew Dillon 		OS_REG_SET_BIT(ah, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN);
171*572ff6f6SMatthew Dillon 		OS_REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
172*572ff6f6SMatthew Dillon 			    AR_PHY_AGC_CONTROL_FLTR_CAL);
173*572ff6f6SMatthew Dillon 		OS_REG_CLR_BIT(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_CAL_ENABLE);
174*572ff6f6SMatthew Dillon 		OS_REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL);
175*572ff6f6SMatthew Dillon 		if (!ath_hal_wait(ah, AR_PHY_AGC_CONTROL,
176*572ff6f6SMatthew Dillon 				  AR_PHY_AGC_CONTROL_CAL, 0)) {
177*572ff6f6SMatthew Dillon 			HALDEBUG(ah, HAL_DEBUG_PERCAL,
178*572ff6f6SMatthew Dillon 				"offset calibration failed to complete in 1ms; noisy environment?\n");
179*572ff6f6SMatthew Dillon 			return AH_FALSE;
180*572ff6f6SMatthew Dillon 		}
181*572ff6f6SMatthew Dillon 		OS_REG_CLR_BIT(ah, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN);
182*572ff6f6SMatthew Dillon 		OS_REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE);
183*572ff6f6SMatthew Dillon 		OS_REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE);
184*572ff6f6SMatthew Dillon 	}
185*572ff6f6SMatthew Dillon 	OS_REG_CLR_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC);
186*572ff6f6SMatthew Dillon 	OS_REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL);
187*572ff6f6SMatthew Dillon 	OS_REG_SET_BIT(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_CAL_ENABLE);
188*572ff6f6SMatthew Dillon 	OS_REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL);
189*572ff6f6SMatthew Dillon 	if (!ath_hal_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL,
190*572ff6f6SMatthew Dillon 			  0)) {
191*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_PERCAL,
192*572ff6f6SMatthew Dillon 			"offset calibration failed to complete in 1ms; noisy environment?\n");
193*572ff6f6SMatthew Dillon 		return AH_FALSE;
194*572ff6f6SMatthew Dillon 	}
195*572ff6f6SMatthew Dillon 
196*572ff6f6SMatthew Dillon 	OS_REG_SET_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC);
197*572ff6f6SMatthew Dillon 	OS_REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE);
198*572ff6f6SMatthew Dillon 	OS_REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL);
199*572ff6f6SMatthew Dillon 
200*572ff6f6SMatthew Dillon 	return AH_TRUE;
201*572ff6f6SMatthew Dillon }
202*572ff6f6SMatthew Dillon 
203*572ff6f6SMatthew Dillon static HAL_BOOL
ar9285_hw_clc(struct ath_hal * ah,const struct ieee80211_channel * chan)204*572ff6f6SMatthew Dillon ar9285_hw_clc(struct ath_hal *ah, const struct ieee80211_channel *chan)
205*572ff6f6SMatthew Dillon {
206*572ff6f6SMatthew Dillon 	int i;
207*572ff6f6SMatthew Dillon 	uint32_t txgain_max;
208*572ff6f6SMatthew Dillon 	uint32_t clc_gain, gain_mask = 0, clc_num = 0;
209*572ff6f6SMatthew Dillon 	uint32_t reg_clc_I0, reg_clc_Q0;
210*572ff6f6SMatthew Dillon 	uint32_t i0_num = 0;
211*572ff6f6SMatthew Dillon 	uint32_t q0_num = 0;
212*572ff6f6SMatthew Dillon 	uint32_t total_num = 0;
213*572ff6f6SMatthew Dillon 	uint32_t reg_rf2g5_org;
214*572ff6f6SMatthew Dillon 	HAL_BOOL retv = AH_TRUE;
215*572ff6f6SMatthew Dillon 
216*572ff6f6SMatthew Dillon 	if (!(ar9285_hw_cl_cal(ah, chan)))
217*572ff6f6SMatthew Dillon 		return AH_FALSE;
218*572ff6f6SMatthew Dillon 
219*572ff6f6SMatthew Dillon 	txgain_max = MS(OS_REG_READ(ah, AR_PHY_TX_PWRCTRL7),
220*572ff6f6SMatthew Dillon 			AR_PHY_TX_PWRCTRL_TX_GAIN_TAB_MAX);
221*572ff6f6SMatthew Dillon 
222*572ff6f6SMatthew Dillon 	for (i = 0; i < (txgain_max+1); i++) {
223*572ff6f6SMatthew Dillon 		clc_gain = (OS_REG_READ(ah, (AR_PHY_TX_GAIN_TBL1+(i<<2))) &
224*572ff6f6SMatthew Dillon 			   AR_PHY_TX_GAIN_CLC) >> AR_PHY_TX_GAIN_CLC_S;
225*572ff6f6SMatthew Dillon 		if (!(gain_mask & (1 << clc_gain))) {
226*572ff6f6SMatthew Dillon 			gain_mask |= (1 << clc_gain);
227*572ff6f6SMatthew Dillon 			clc_num++;
228*572ff6f6SMatthew Dillon 		}
229*572ff6f6SMatthew Dillon 	}
230*572ff6f6SMatthew Dillon 
231*572ff6f6SMatthew Dillon 	for (i = 0; i < clc_num; i++) {
232*572ff6f6SMatthew Dillon 		reg_clc_I0 = (OS_REG_READ(ah, (AR_PHY_CLC_TBL1 + (i << 2)))
233*572ff6f6SMatthew Dillon 			      & AR_PHY_CLC_I0) >> AR_PHY_CLC_I0_S;
234*572ff6f6SMatthew Dillon 		reg_clc_Q0 = (OS_REG_READ(ah, (AR_PHY_CLC_TBL1 + (i << 2)))
235*572ff6f6SMatthew Dillon 			      & AR_PHY_CLC_Q0) >> AR_PHY_CLC_Q0_S;
236*572ff6f6SMatthew Dillon 		if (reg_clc_I0 == 0)
237*572ff6f6SMatthew Dillon 			i0_num++;
238*572ff6f6SMatthew Dillon 
239*572ff6f6SMatthew Dillon 		if (reg_clc_Q0 == 0)
240*572ff6f6SMatthew Dillon 			q0_num++;
241*572ff6f6SMatthew Dillon 	}
242*572ff6f6SMatthew Dillon 	total_num = i0_num + q0_num;
243*572ff6f6SMatthew Dillon 	if (total_num > AR9285_CLCAL_REDO_THRESH) {
244*572ff6f6SMatthew Dillon 		reg_rf2g5_org = OS_REG_READ(ah, AR9285_RF2G5);
245*572ff6f6SMatthew Dillon 		if (AR_SREV_9285E_20(ah)) {
246*572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR9285_RF2G5,
247*572ff6f6SMatthew Dillon 				  (reg_rf2g5_org & AR9285_RF2G5_IC50TX) |
248*572ff6f6SMatthew Dillon 				  AR9285_RF2G5_IC50TX_XE_SET);
249*572ff6f6SMatthew Dillon 		} else {
250*572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR9285_RF2G5,
251*572ff6f6SMatthew Dillon 				  (reg_rf2g5_org & AR9285_RF2G5_IC50TX) |
252*572ff6f6SMatthew Dillon 				  AR9285_RF2G5_IC50TX_SET);
253*572ff6f6SMatthew Dillon 		}
254*572ff6f6SMatthew Dillon 		retv = ar9285_hw_cl_cal(ah, chan);
255*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR9285_RF2G5, reg_rf2g5_org);
256*572ff6f6SMatthew Dillon 	}
257*572ff6f6SMatthew Dillon 	return retv;
258*572ff6f6SMatthew Dillon }
259*572ff6f6SMatthew Dillon 
260*572ff6f6SMatthew Dillon HAL_BOOL
ar9285InitCalHardware(struct ath_hal * ah,const struct ieee80211_channel * chan)261*572ff6f6SMatthew Dillon ar9285InitCalHardware(struct ath_hal *ah,
262*572ff6f6SMatthew Dillon     const struct ieee80211_channel *chan)
263*572ff6f6SMatthew Dillon {
264*572ff6f6SMatthew Dillon 	if (AR_SREV_KITE(ah) && AR_SREV_KITE_10_OR_LATER(ah) &&
265*572ff6f6SMatthew Dillon 	    (! ar9285_hw_clc(ah, chan)))
266*572ff6f6SMatthew Dillon 		return AH_FALSE;
267*572ff6f6SMatthew Dillon 
268*572ff6f6SMatthew Dillon 	return AH_TRUE;
269*572ff6f6SMatthew Dillon }
270