ar9003_hw.c 30.1 KB
Newer Older
1
/*
2
 * Copyright (c) 2008-2011 Atheros Communications Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "hw.h"
18
#include "ar9003_mac.h"
19
#include "ar9003_2p2_initvals.h"
20
#include "ar9003_buffalo_initvals.h"
21
#include "ar9485_initvals.h"
22
#include "ar9340_initvals.h"
23 24
#include "ar9330_1p1_initvals.h"
#include "ar9330_1p2_initvals.h"
G
Gabor Juhos 已提交
25
#include "ar955x_1p0_initvals.h"
L
Luis R. Rodriguez 已提交
26
#include "ar9580_1p0_initvals.h"
27
#include "ar9462_2p0_initvals.h"
28
#include "ar9462_2p1_initvals.h"
S
Sujith Manoharan 已提交
29
#include "ar9565_1p0_initvals.h"
30
#include "ar9565_1p1_initvals.h"
31 32 33

/* General hardware code for the AR9003 hadware family */

34 35 36 37 38 39
/*
 * The AR9003 family uses a new INI format (pre, core, post
 * arrays per subsystem). This provides support for the
 * AR9003 2.2 chipsets.
 */
static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
40
{
41 42 43
	if (AR_SREV_9330_11(ah)) {
		/* mac */
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
44
				ar9331_1p1_mac_core);
45
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
46
				ar9331_1p1_mac_postamble);
47 48 49

		/* bb */
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
50
				ar9331_1p1_baseband_core);
51
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
52
				ar9331_1p1_baseband_postamble);
53 54 55

		/* radio */
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
56
				ar9331_1p1_radio_core);
57 58 59

		/* soc */
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
60
				ar9331_1p1_soc_preamble);
61
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
62
				ar9331_1p1_soc_postamble);
63 64 65

		/* rx/tx gain */
		INIT_INI_ARRAY(&ah->iniModesRxGain,
66
				ar9331_common_rx_gain_1p1);
67
		INIT_INI_ARRAY(&ah->iniModesTxGain,
68
				ar9331_modes_lowest_ob_db_tx_gain_1p1);
69

70 71 72 73
		/* Japan 2484 Mhz CCK */
		INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
			       ar9331_1p1_baseband_core_txfir_coeff_japan_2484);

74 75
		/* additional clock settings */
		if (ah->is_clk_25mhz)
76
			INIT_INI_ARRAY(&ah->iniAdditional,
77
					ar9331_1p1_xtal_25M);
78
		else
79
			INIT_INI_ARRAY(&ah->iniAdditional,
80
					ar9331_1p1_xtal_40M);
81 82 83
	} else if (AR_SREV_9330_12(ah)) {
		/* mac */
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
84
				ar9331_1p2_mac_core);
85
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
86
				ar9331_1p2_mac_postamble);
87 88 89

		/* bb */
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
90
				ar9331_1p2_baseband_core);
91
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
92
				ar9331_1p2_baseband_postamble);
93 94 95

		/* radio */
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
96
				ar9331_1p2_radio_core);
97 98 99

		/* soc */
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
100
				ar9331_1p2_soc_preamble);
101
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
102
				ar9331_1p2_soc_postamble);
103 104 105

		/* rx/tx gain */
		INIT_INI_ARRAY(&ah->iniModesRxGain,
106
				ar9331_common_rx_gain_1p2);
107
		INIT_INI_ARRAY(&ah->iniModesTxGain,
108
				ar9331_modes_lowest_ob_db_tx_gain_1p2);
109

110 111 112 113
		/* Japan 2484 Mhz CCK */
		INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
			       ar9331_1p2_baseband_core_txfir_coeff_japan_2484);

114 115
		/* additional clock settings */
		if (ah->is_clk_25mhz)
116
			INIT_INI_ARRAY(&ah->iniAdditional,
117
					ar9331_1p2_xtal_25M);
118
		else
119
			INIT_INI_ARRAY(&ah->iniAdditional,
120
					ar9331_1p2_xtal_40M);
121
	} else if (AR_SREV_9340(ah)) {
122 123
		/* mac */
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
124
				ar9340_1p0_mac_core);
125
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
126
				ar9340_1p0_mac_postamble);
127 128 129

		/* bb */
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
130
				ar9340_1p0_baseband_core);
131
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
132
				ar9340_1p0_baseband_postamble);
133 134 135

		/* radio */
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
136
				ar9340_1p0_radio_core);
137
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
138
				ar9340_1p0_radio_postamble);
139 140 141

		/* soc */
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
142
				ar9340_1p0_soc_preamble);
143
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
144
				ar9340_1p0_soc_postamble);
145 146 147

		/* rx/tx gain */
		INIT_INI_ARRAY(&ah->iniModesRxGain,
148
				ar9340Common_wo_xlna_rx_gain_table_1p0);
149
		INIT_INI_ARRAY(&ah->iniModesTxGain,
150
				ar9340Modes_high_ob_db_tx_gain_table_1p0);
151

152
		INIT_INI_ARRAY(&ah->iniModesFastClock,
153 154 155
			       ar9340Modes_fast_clock_1p0);
		INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
			       ar9340_1p0_baseband_core_txfir_coeff_japan_2484);
156 157
		INIT_INI_ARRAY(&ah->ini_dfs,
			       ar9340_1p0_baseband_postamble_dfs_channel);
158

159 160
		if (!ah->is_clk_25mhz)
			INIT_INI_ARRAY(&ah->iniAdditional,
161
				       ar9340_1p0_radio_core_40M);
162
	} else if (AR_SREV_9485_11_OR_LATER(ah)) {
163 164
		/* mac */
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
165
				ar9485_1_1_mac_core);
166
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
167
				ar9485_1_1_mac_postamble);
168 169

		/* bb */
170
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_PRE], ar9485_1_1);
171
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
172
				ar9485_1_1_baseband_core);
173
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
174
				ar9485_1_1_baseband_postamble);
175 176 177

		/* radio */
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
178
				ar9485_1_1_radio_core);
179
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
180
				ar9485_1_1_radio_postamble);
181 182 183

		/* soc */
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
184
				ar9485_1_1_soc_preamble);
185 186 187

		/* rx/tx gain */
		INIT_INI_ARRAY(&ah->iniModesRxGain,
188
				ar9485Common_wo_xlna_rx_gain_1_1);
189
		INIT_INI_ARRAY(&ah->iniModesTxGain,
190
				ar9485_modes_lowest_ob_db_tx_gain_1_1);
191

192 193 194 195
		/* Japan 2484 Mhz CCK */
		INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
			       ar9485_1_1_baseband_core_txfir_coeff_japan_2484);

196 197 198 199 200 201 202 203 204 205 206
		if (ah->config.no_pll_pwrsave) {
			INIT_INI_ARRAY(&ah->iniPcieSerdes,
				       ar9485_1_1_pcie_phy_clkreq_disable_L1);
			INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
				       ar9485_1_1_pcie_phy_clkreq_disable_L1);
		} else {
			INIT_INI_ARRAY(&ah->iniPcieSerdes,
				       ar9485_1_1_pll_on_cdr_on_clkreq_disable_L1);
			INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
				       ar9485_1_1_pll_on_cdr_on_clkreq_disable_L1);
		}
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
	} else if (AR_SREV_9462_21(ah)) {
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
			       ar9462_2p1_mac_core);
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
			       ar9462_2p1_mac_postamble);
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
			       ar9462_2p1_baseband_core);
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
			       ar9462_2p1_baseband_postamble);
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
			       ar9462_2p1_radio_core);
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
			       ar9462_2p1_radio_postamble);
		INIT_INI_ARRAY(&ah->ini_radio_post_sys2ant,
			       ar9462_2p1_radio_postamble_sys2ant);
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
			       ar9462_2p1_soc_preamble);
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
			       ar9462_2p1_soc_postamble);
		INIT_INI_ARRAY(&ah->iniModesRxGain,
			       ar9462_2p1_common_rx_gain);
		INIT_INI_ARRAY(&ah->iniModesFastClock,
			       ar9462_2p1_modes_fast_clock);
		INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
			       ar9462_2p1_baseband_core_txfir_coeff_japan_2484);
232 233 234 235
		INIT_INI_ARRAY(&ah->iniPcieSerdes,
			       ar9462_2p1_pciephy_clkreq_disable_L1);
		INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
			       ar9462_2p1_pciephy_clkreq_disable_L1);
236
	} else if (AR_SREV_9462_20(ah)) {
237

238
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE], ar9462_2p0_mac_core);
239
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
240
				ar9462_2p0_mac_postamble);
241 242

		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
243
				ar9462_2p0_baseband_core);
244
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
245
				ar9462_2p0_baseband_postamble);
246 247

		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
248
				ar9462_2p0_radio_core);
249
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
250
				ar9462_2p0_radio_postamble);
251
		INIT_INI_ARRAY(&ah->ini_radio_post_sys2ant,
252
				ar9462_2p0_radio_postamble_sys2ant);
253 254

		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
255
				ar9462_2p0_soc_preamble);
256
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
257
				ar9462_2p0_soc_postamble);
258 259

		INIT_INI_ARRAY(&ah->iniModesRxGain,
260
				ar9462_2p0_common_rx_gain);
261 262 263

		/* Awake -> Sleep Setting */
		INIT_INI_ARRAY(&ah->iniPcieSerdes,
264
			       ar9462_2p0_pciephy_clkreq_disable_L1);
265 266
		/* Sleep -> Awake Setting */
		INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
267
			       ar9462_2p0_pciephy_clkreq_disable_L1);
268 269

		/* Fast clock modal settings */
270
		INIT_INI_ARRAY(&ah->iniModesFastClock,
271
				ar9462_2p0_modes_fast_clock);
272 273

		INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
274
			       ar9462_2p0_baseband_core_txfir_coeff_japan_2484);
275 276 277
	} else if (AR_SREV_9550(ah)) {
		/* mac */
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
278
				ar955x_1p0_mac_core);
279
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
280
				ar955x_1p0_mac_postamble);
281 282 283

		/* bb */
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
284
				ar955x_1p0_baseband_core);
285
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
286
				ar955x_1p0_baseband_postamble);
287 288 289

		/* radio */
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
290
				ar955x_1p0_radio_core);
291
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
292
				ar955x_1p0_radio_postamble);
293 294 295

		/* soc */
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
296
				ar955x_1p0_soc_preamble);
297
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
298
				ar955x_1p0_soc_postamble);
299

300 301
		/* rx/tx gain */
		INIT_INI_ARRAY(&ah->iniModesRxGain,
302
			ar955x_1p0_common_wo_xlna_rx_gain_table);
303
		INIT_INI_ARRAY(&ah->ini_modes_rx_gain_bounds,
304
			ar955x_1p0_common_wo_xlna_rx_gain_bounds);
305
		INIT_INI_ARRAY(&ah->iniModesTxGain,
306
				ar955x_1p0_modes_xpa_tx_gain_table);
307 308 309

		/* Fast clock modal settings */
		INIT_INI_ARRAY(&ah->iniModesFastClock,
310
				ar955x_1p0_modes_fast_clock);
L
Luis R. Rodriguez 已提交
311 312 313
	} else if (AR_SREV_9580(ah)) {
		/* mac */
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
314
				ar9580_1p0_mac_core);
L
Luis R. Rodriguez 已提交
315
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
316
				ar9580_1p0_mac_postamble);
L
Luis R. Rodriguez 已提交
317 318 319

		/* bb */
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
320
				ar9580_1p0_baseband_core);
L
Luis R. Rodriguez 已提交
321
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
322
				ar9580_1p0_baseband_postamble);
L
Luis R. Rodriguez 已提交
323 324 325

		/* radio */
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
326
				ar9580_1p0_radio_core);
L
Luis R. Rodriguez 已提交
327
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
328
				ar9580_1p0_radio_postamble);
L
Luis R. Rodriguez 已提交
329 330 331

		/* soc */
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
332
				ar9580_1p0_soc_preamble);
L
Luis R. Rodriguez 已提交
333
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
334
				ar9580_1p0_soc_postamble);
L
Luis R. Rodriguez 已提交
335 336 337

		/* rx/tx gain */
		INIT_INI_ARRAY(&ah->iniModesRxGain,
338
				ar9580_1p0_rx_gain_table);
L
Luis R. Rodriguez 已提交
339
		INIT_INI_ARRAY(&ah->iniModesTxGain,
340
				ar9580_1p0_low_ob_db_tx_gain_table);
L
Luis R. Rodriguez 已提交
341

342
		INIT_INI_ARRAY(&ah->iniModesFastClock,
343 344 345
			       ar9580_1p0_modes_fast_clock);
		INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
			       ar9580_1p0_baseband_core_txfir_coeff_japan_2484);
346 347
		INIT_INI_ARRAY(&ah->ini_dfs,
			       ar9580_1p0_baseband_postamble_dfs_channel);
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
	} else if (AR_SREV_9565_11_OR_LATER(ah)) {
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
			       ar9565_1p1_mac_core);
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
			       ar9565_1p1_mac_postamble);

		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
			       ar9565_1p1_baseband_core);
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
			       ar9565_1p1_baseband_postamble);

		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
			       ar9565_1p1_radio_core);
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
			       ar9565_1p1_radio_postamble);

		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
			       ar9565_1p1_soc_preamble);
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
			       ar9565_1p1_soc_postamble);

		INIT_INI_ARRAY(&ah->iniModesRxGain,
			       ar9565_1p1_Common_rx_gain_table);
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			       ar9565_1p1_Modes_lowest_ob_db_tx_gain_table);

		INIT_INI_ARRAY(&ah->iniPcieSerdes,
			       ar9565_1p1_pciephy_clkreq_disable_L1);
		INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
			       ar9565_1p1_pciephy_clkreq_disable_L1);

		INIT_INI_ARRAY(&ah->iniModesFastClock,
				ar9565_1p1_modes_fast_clock);
		INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
			       ar9565_1p1_baseband_core_txfir_coeff_japan_2484);
S
Sujith Manoharan 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
	} else if (AR_SREV_9565(ah)) {
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
			       ar9565_1p0_mac_core);
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
			       ar9565_1p0_mac_postamble);

		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
			       ar9565_1p0_baseband_core);
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
			       ar9565_1p0_baseband_postamble);

		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
			       ar9565_1p0_radio_core);
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
			       ar9565_1p0_radio_postamble);

		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
			       ar9565_1p0_soc_preamble);
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
			       ar9565_1p0_soc_postamble);

		INIT_INI_ARRAY(&ah->iniModesRxGain,
			       ar9565_1p0_Common_rx_gain_table);
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			       ar9565_1p0_Modes_lowest_ob_db_tx_gain_table);

		INIT_INI_ARRAY(&ah->iniPcieSerdes,
410
			       ar9565_1p0_pciephy_clkreq_disable_L1);
S
Sujith Manoharan 已提交
411
		INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
412
			       ar9565_1p0_pciephy_clkreq_disable_L1);
S
Sujith Manoharan 已提交
413 414 415

		INIT_INI_ARRAY(&ah->iniModesFastClock,
				ar9565_1p0_modes_fast_clock);
416 417
		INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
			       ar9565_1p0_baseband_core_txfir_coeff_japan_2484);
418 419 420
	} else {
		/* mac */
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
421
				ar9300_2p2_mac_core);
422
		INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
423
				ar9300_2p2_mac_postamble);
424 425 426

		/* bb */
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
427
				ar9300_2p2_baseband_core);
428
		INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
429
				ar9300_2p2_baseband_postamble);
430 431 432

		/* radio */
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
433
				ar9300_2p2_radio_core);
434
		INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
435
				ar9300_2p2_radio_postamble);
436 437 438

		/* soc */
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
439
				ar9300_2p2_soc_preamble);
440
		INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
441
				ar9300_2p2_soc_postamble);
442 443 444

		/* rx/tx gain */
		INIT_INI_ARRAY(&ah->iniModesRxGain,
445
				ar9300Common_rx_gain_table_2p2);
446
		INIT_INI_ARRAY(&ah->iniModesTxGain,
447
				ar9300Modes_lowest_ob_db_tx_gain_table_2p2);
448 449 450 451 452 453

		/* Load PCIE SERDES settings from INI */

		/* Awake Setting */

		INIT_INI_ARRAY(&ah->iniPcieSerdes,
454
				ar9300PciePhy_pll_on_clkreq_disable_L1_2p2);
455 456 457 458

		/* Sleep Setting */

		INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
459
				ar9300PciePhy_pll_on_clkreq_disable_L1_2p2);
460 461

		/* Fast clock modal settings */
462
		INIT_INI_ARRAY(&ah->iniModesFastClock,
463 464 465
			       ar9300Modes_fast_clock_2p2);
		INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
			       ar9300_2p2_baseband_core_txfir_coeff_japan_2484);
466 467
		INIT_INI_ARRAY(&ah->ini_dfs,
			       ar9300_2p2_baseband_postamble_dfs_channel);
468
	}
469 470
}

471 472 473 474
static void ar9003_tx_gain_table_mode0(struct ath_hw *ah)
{
	if (AR_SREV_9330_12(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
475
			ar9331_modes_lowest_ob_db_tx_gain_1p2);
476 477
	else if (AR_SREV_9330_11(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
478
			ar9331_modes_lowest_ob_db_tx_gain_1p1);
479 480
	else if (AR_SREV_9340(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
481
			ar9340Modes_lowest_ob_db_tx_gain_table_1p0);
482
	else if (AR_SREV_9485_11_OR_LATER(ah))
483
		INIT_INI_ARRAY(&ah->iniModesTxGain,
484
			ar9485_modes_lowest_ob_db_tx_gain_1_1);
485 486
	else if (AR_SREV_9550(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
487
			ar955x_1p0_modes_xpa_tx_gain_table);
488 489
	else if (AR_SREV_9580(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
490
			ar9580_1p0_lowest_ob_db_tx_gain_table);
491 492 493
	else if (AR_SREV_9462_21(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			ar9462_2p1_modes_low_ob_db_tx_gain);
494
	else if (AR_SREV_9462_20(ah))
495
		INIT_INI_ARRAY(&ah->iniModesTxGain,
496
			ar9462_2p0_modes_low_ob_db_tx_gain);
497 498 499
	else if (AR_SREV_9565_11(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			       ar9565_1p1_modes_low_ob_db_tx_gain_table);
S
Sujith Manoharan 已提交
500 501 502
	else if (AR_SREV_9565(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			       ar9565_1p0_modes_low_ob_db_tx_gain_table);
503 504
	else
		INIT_INI_ARRAY(&ah->iniModesTxGain,
505
			ar9300Modes_lowest_ob_db_tx_gain_table_2p2);
506 507 508 509 510 511
}

static void ar9003_tx_gain_table_mode1(struct ath_hw *ah)
{
	if (AR_SREV_9330_12(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
512
			ar9331_modes_high_ob_db_tx_gain_1p2);
513 514
	else if (AR_SREV_9330_11(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
515
			ar9331_modes_high_ob_db_tx_gain_1p1);
516 517
	else if (AR_SREV_9340(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
518
			ar9340Modes_high_ob_db_tx_gain_table_1p0);
519
	else if (AR_SREV_9485_11_OR_LATER(ah))
520
		INIT_INI_ARRAY(&ah->iniModesTxGain,
521
			ar9485Modes_high_ob_db_tx_gain_1_1);
522 523
	else if (AR_SREV_9580(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
524
			ar9580_1p0_high_ob_db_tx_gain_table);
525 526
	else if (AR_SREV_9550(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
527
			ar955x_1p0_modes_no_xpa_tx_gain_table);
528 529 530
	else if (AR_SREV_9462_21(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			ar9462_2p1_modes_high_ob_db_tx_gain);
531
	else if (AR_SREV_9462_20(ah))
532
		INIT_INI_ARRAY(&ah->iniModesTxGain,
533
			ar9462_2p0_modes_high_ob_db_tx_gain);
534 535 536
	else if (AR_SREV_9565_11(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			       ar9565_1p1_modes_high_ob_db_tx_gain_table);
S
Sujith Manoharan 已提交
537 538 539
	else if (AR_SREV_9565(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			       ar9565_1p0_modes_high_ob_db_tx_gain_table);
540 541
	else
		INIT_INI_ARRAY(&ah->iniModesTxGain,
542
			ar9300Modes_high_ob_db_tx_gain_table_2p2);
543 544 545 546 547 548
}

static void ar9003_tx_gain_table_mode2(struct ath_hw *ah)
{
	if (AR_SREV_9330_12(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
549
			ar9331_modes_low_ob_db_tx_gain_1p2);
550 551
	else if (AR_SREV_9330_11(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
552
			ar9331_modes_low_ob_db_tx_gain_1p1);
553 554
	else if (AR_SREV_9340(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
555
			ar9340Modes_low_ob_db_tx_gain_table_1p0);
556
	else if (AR_SREV_9485_11_OR_LATER(ah))
557
		INIT_INI_ARRAY(&ah->iniModesTxGain,
558
			ar9485Modes_low_ob_db_tx_gain_1_1);
559 560
	else if (AR_SREV_9580(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
561
			ar9580_1p0_low_ob_db_tx_gain_table);
562 563 564
	else if (AR_SREV_9565_11(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			       ar9565_1p1_modes_low_ob_db_tx_gain_table);
S
Sujith Manoharan 已提交
565 566 567
	else if (AR_SREV_9565(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			       ar9565_1p0_modes_low_ob_db_tx_gain_table);
568 569
	else
		INIT_INI_ARRAY(&ah->iniModesTxGain,
570
			ar9300Modes_low_ob_db_tx_gain_table_2p2);
571 572 573 574 575 576
}

static void ar9003_tx_gain_table_mode3(struct ath_hw *ah)
{
	if (AR_SREV_9330_12(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
577
			ar9331_modes_high_power_tx_gain_1p2);
578 579
	else if (AR_SREV_9330_11(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
580
			ar9331_modes_high_power_tx_gain_1p1);
581 582
	else if (AR_SREV_9340(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
583
			ar9340Modes_high_power_tx_gain_table_1p0);
584
	else if (AR_SREV_9485_11_OR_LATER(ah))
585
		INIT_INI_ARRAY(&ah->iniModesTxGain,
586
			ar9485Modes_high_power_tx_gain_1_1);
587 588
	else if (AR_SREV_9580(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
589
			ar9580_1p0_high_power_tx_gain_table);
590 591 592
	else if (AR_SREV_9565_11(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			       ar9565_1p1_modes_high_power_tx_gain_table);
S
Sujith Manoharan 已提交
593 594 595
	else if (AR_SREV_9565(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			       ar9565_1p0_modes_high_power_tx_gain_table);
596 597 598 599 600 601 602 603
	else {
		if (ah->config.tx_gain_buffalo)
			INIT_INI_ARRAY(&ah->iniModesTxGain,
				       ar9300Modes_high_power_tx_gain_table_buffalo);
		else
			INIT_INI_ARRAY(&ah->iniModesTxGain,
				       ar9300Modes_high_power_tx_gain_table_2p2);
	}
604 605
}

606 607 608 609
static void ar9003_tx_gain_table_mode4(struct ath_hw *ah)
{
	if (AR_SREV_9340(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
610
			ar9340Modes_mixed_ob_db_tx_gain_table_1p0);
611 612
	else if (AR_SREV_9580(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
613
			ar9580_1p0_mixed_ob_db_tx_gain_table);
614 615 616
	else if (AR_SREV_9462_21(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
		       ar9462_2p1_modes_mix_ob_db_tx_gain);
617 618
	else if (AR_SREV_9462_20(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
619
		       ar9462_2p0_modes_mix_ob_db_tx_gain);
620 621 622 623 624 625 626
	else
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			ar9300Modes_mixed_ob_db_tx_gain_table_2p2);
}

static void ar9003_tx_gain_table_mode5(struct ath_hw *ah)
{
627
	if (AR_SREV_9485_11_OR_LATER(ah))
628 629 630 631 632 633 634 635 636 637 638
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			ar9485Modes_green_ob_db_tx_gain_1_1);
	else if (AR_SREV_9340(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			ar9340Modes_ub124_tx_gain_table_1p0);
	else if (AR_SREV_9580(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			ar9580_1p0_type5_tx_gain_table);
	else if (AR_SREV_9300_22(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			ar9300Modes_type5_tx_gain_table_2p2);
639 640
}

641 642 643 644 645
static void ar9003_tx_gain_table_mode6(struct ath_hw *ah)
{
	if (AR_SREV_9340(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			ar9340Modes_low_ob_db_and_spur_tx_gain_table_1p0);
646
	else if (AR_SREV_9485_11_OR_LATER(ah))
647 648 649 650 651 652 653
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			ar9485Modes_green_spur_ob_db_tx_gain_1_1);
	else if (AR_SREV_9580(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			ar9580_1p0_type6_tx_gain_table);
}

654 655 656 657 658 659 660
static void ar9003_tx_gain_table_mode7(struct ath_hw *ah)
{
	if (AR_SREV_9340(ah))
		INIT_INI_ARRAY(&ah->iniModesTxGain,
			       ar9340_cus227_tx_gain_table_1p0);
}

661 662
typedef void (*ath_txgain_tab)(struct ath_hw *ah);

663 664
static void ar9003_tx_gain_table_apply(struct ath_hw *ah)
{
665 666 667 668 669 670 671 672
	static const ath_txgain_tab modes[] = {
		ar9003_tx_gain_table_mode0,
		ar9003_tx_gain_table_mode1,
		ar9003_tx_gain_table_mode2,
		ar9003_tx_gain_table_mode3,
		ar9003_tx_gain_table_mode4,
		ar9003_tx_gain_table_mode5,
		ar9003_tx_gain_table_mode6,
673
		ar9003_tx_gain_table_mode7,
674 675 676 677 678 679 680
	};
	int idx = ar9003_hw_get_tx_gain_idx(ah);

	if (idx >= ARRAY_SIZE(modes))
		idx = 0;

	modes[idx](ah);
681 682
}

683 684 685 686
static void ar9003_rx_gain_table_mode0(struct ath_hw *ah)
{
	if (AR_SREV_9330_12(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
687
				ar9331_common_rx_gain_1p2);
688 689
	else if (AR_SREV_9330_11(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
690
				ar9331_common_rx_gain_1p1);
691 692
	else if (AR_SREV_9340(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
693
				ar9340Common_rx_gain_table_1p0);
694
	else if (AR_SREV_9485_11_OR_LATER(ah))
695
		INIT_INI_ARRAY(&ah->iniModesRxGain,
696
			       ar9485_common_rx_gain_1_1);
697 698
	else if (AR_SREV_9550(ah)) {
		INIT_INI_ARRAY(&ah->iniModesRxGain,
699
				ar955x_1p0_common_rx_gain_table);
700
		INIT_INI_ARRAY(&ah->ini_modes_rx_gain_bounds,
701
				ar955x_1p0_common_rx_gain_bounds);
702
	} else if (AR_SREV_9580(ah))
703
		INIT_INI_ARRAY(&ah->iniModesRxGain,
704
				ar9580_1p0_rx_gain_table);
705 706 707
	else if (AR_SREV_9462_21(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
				ar9462_2p1_common_rx_gain);
708
	else if (AR_SREV_9462_20(ah))
709
		INIT_INI_ARRAY(&ah->iniModesRxGain,
710
				ar9462_2p0_common_rx_gain);
711 712 713
	else if (AR_SREV_9565_11(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
			       ar9565_1p1_Common_rx_gain_table);
714 715 716
	else if (AR_SREV_9565(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
			       ar9565_1p0_Common_rx_gain_table);
717 718
	else
		INIT_INI_ARRAY(&ah->iniModesRxGain,
719
				ar9300Common_rx_gain_table_2p2);
720 721 722 723 724 725
}

static void ar9003_rx_gain_table_mode1(struct ath_hw *ah)
{
	if (AR_SREV_9330_12(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
726
			ar9331_common_wo_xlna_rx_gain_1p2);
727 728
	else if (AR_SREV_9330_11(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
729
			ar9331_common_wo_xlna_rx_gain_1p1);
730 731
	else if (AR_SREV_9340(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
732
			ar9340Common_wo_xlna_rx_gain_table_1p0);
733
	else if (AR_SREV_9485_11_OR_LATER(ah))
734
		INIT_INI_ARRAY(&ah->iniModesRxGain,
735
			ar9485Common_wo_xlna_rx_gain_1_1);
736 737 738
	else if (AR_SREV_9462_21(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
			ar9462_2p1_common_wo_xlna_rx_gain);
739
	else if (AR_SREV_9462_20(ah))
740
		INIT_INI_ARRAY(&ah->iniModesRxGain,
741
			ar9462_2p0_common_wo_xlna_rx_gain);
742 743
	else if (AR_SREV_9550(ah)) {
		INIT_INI_ARRAY(&ah->iniModesRxGain,
744
			ar955x_1p0_common_wo_xlna_rx_gain_table);
745
		INIT_INI_ARRAY(&ah->ini_modes_rx_gain_bounds,
746
			ar955x_1p0_common_wo_xlna_rx_gain_bounds);
747
	} else if (AR_SREV_9580(ah))
748
		INIT_INI_ARRAY(&ah->iniModesRxGain,
749
			ar9580_1p0_wo_xlna_rx_gain_table);
750 751 752
	else if (AR_SREV_9565_11(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
			       ar9565_1p1_common_wo_xlna_rx_gain_table);
S
Sujith Manoharan 已提交
753 754 755
	else if (AR_SREV_9565(ah))
		INIT_INI_ARRAY(&ah->iniModesRxGain,
			       ar9565_1p0_common_wo_xlna_rx_gain_table);
756 757
	else
		INIT_INI_ARRAY(&ah->iniModesRxGain,
758
			ar9300Common_wo_xlna_rx_gain_table_2p2);
759 760
}

761 762
static void ar9003_rx_gain_table_mode2(struct ath_hw *ah)
{
763 764 765 766 767 768 769 770 771 772
	if (AR_SREV_9462_21(ah)) {
		INIT_INI_ARRAY(&ah->iniModesRxGain,
			       ar9462_2p1_common_mixed_rx_gain);
		INIT_INI_ARRAY(&ah->ini_modes_rxgain_bb_core,
			       ar9462_2p1_baseband_core_mix_rxgain);
		INIT_INI_ARRAY(&ah->ini_modes_rxgain_bb_postamble,
			       ar9462_2p1_baseband_postamble_mix_rxgain);
		INIT_INI_ARRAY(&ah->ini_modes_rxgain_5g_xlna,
			       ar9462_2p1_baseband_postamble_5g_xlna);
	} else if (AR_SREV_9462_20(ah)) {
773
		INIT_INI_ARRAY(&ah->iniModesRxGain,
774
			       ar9462_2p0_common_mixed_rx_gain);
775 776 777 778
		INIT_INI_ARRAY(&ah->ini_modes_rxgain_bb_core,
			       ar9462_2p0_baseband_core_mix_rxgain);
		INIT_INI_ARRAY(&ah->ini_modes_rxgain_bb_postamble,
			       ar9462_2p0_baseband_postamble_mix_rxgain);
779 780 781 782 783 784 785
		INIT_INI_ARRAY(&ah->ini_modes_rxgain_5g_xlna,
			       ar9462_2p0_baseband_postamble_5g_xlna);
	}
}

static void ar9003_rx_gain_table_mode3(struct ath_hw *ah)
{
786 787
	if (AR_SREV_9462_21(ah)) {
		INIT_INI_ARRAY(&ah->iniModesRxGain,
788
			       ar9462_2p1_common_5g_xlna_only_rxgain);
789 790 791
		INIT_INI_ARRAY(&ah->ini_modes_rxgain_5g_xlna,
			       ar9462_2p1_baseband_postamble_5g_xlna);
	} else if (AR_SREV_9462_20(ah)) {
792
		INIT_INI_ARRAY(&ah->iniModesRxGain,
793
			       ar9462_2p0_common_5g_xlna_only_rxgain);
794 795 796
		INIT_INI_ARRAY(&ah->ini_modes_rxgain_5g_xlna,
			       ar9462_2p0_baseband_postamble_5g_xlna);
	}
797 798
}

799 800 801 802 803
static void ar9003_rx_gain_table_apply(struct ath_hw *ah)
{
	switch (ar9003_hw_get_rx_gain_idx(ah)) {
	case 0:
	default:
804
		ar9003_rx_gain_table_mode0(ah);
805 806
		break;
	case 1:
807
		ar9003_rx_gain_table_mode1(ah);
808
		break;
809 810 811
	case 2:
		ar9003_rx_gain_table_mode2(ah);
		break;
812 813 814
	case 3:
		ar9003_rx_gain_table_mode3(ah);
		break;
815 816 817 818 819 820 821 822 823 824
	}
}

/* set gain table pointers according to values read from the eeprom */
static void ar9003_hw_init_mode_gain_regs(struct ath_hw *ah)
{
	ar9003_tx_gain_table_apply(ah);
	ar9003_rx_gain_table_apply(ah);
}

825 826 827 828 829 830 831 832 833 834
/*
 * Helper for ASPM support.
 *
 * Disable PLL when in L0s as well as receiver clock when in L1.
 * This power saving option must be enabled through the SerDes.
 *
 * Programming the SerDes must go through the same 288 bit serial shift
 * register as the other analog registers.  Hence the 9 writes.
 */
static void ar9003_hw_configpcipowersave(struct ath_hw *ah,
835
					 bool power_off)
836
{
S
Sujith Manoharan 已提交
837 838 839
	unsigned int i;
	struct ar5416IniArray *array;

S
Sujith Manoharan 已提交
840 841 842 843 844 845 846 847 848 849 850 851 852 853
	/*
	 * Increase L1 Entry Latency. Some WB222 boards don't have
	 * this change in eeprom/OTP.
	 *
	 */
	if (AR_SREV_9462(ah)) {
		u32 val = ah->config.aspm_l1_fix;
		if ((val & 0xff000000) == 0x17000000) {
			val &= 0x00ffffff;
			val |= 0x27000000;
			REG_WRITE(ah, 0x570c, val);
		}
	}

854
	/* Nothing to do on restore for 11N */
855
	if (!power_off /* !restore */) {
856 857
		/* set bit 19 to allow forcing of pcie core into L1 state */
		REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
858
		REG_WRITE(ah, AR_WA, ah->WARegVal);
859
	}
860 861 862 863 864

	/*
	 * Configire PCIE after Ini init. SERDES values now come from ini file
	 * This enables PCIe low power mode.
	 */
S
Sujith Manoharan 已提交
865 866
	array = power_off ? &ah->iniPcieSerdes :
		&ah->iniPcieSerdesLowPower;
867

S
Sujith Manoharan 已提交
868 869 870 871
	for (i = 0; i < array->ia_rows; i++) {
		REG_WRITE(ah,
			  INI_RA(array, i, 0),
			  INI_RA(array, i, 1));
872
	}
873 874
}

875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
static void ar9003_hw_init_hang_checks(struct ath_hw *ah)
{
	/*
	 * All chips support detection of BB/MAC hangs.
	 */
	ah->config.hw_hang_checks |= HW_BB_WATCHDOG;
	ah->config.hw_hang_checks |= HW_MAC_HANG;

	/*
	 * This is not required for AR9580 1.0
	 */
	if (AR_SREV_9300_22(ah))
		ah->config.hw_hang_checks |= HW_PHYRESTART_CLC_WAR;

	if (AR_SREV_9330(ah))
		ah->bb_watchdog_timeout_ms = 85;
	else
		ah->bb_watchdog_timeout_ms = 25;
}

895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
/*
 * MAC HW hang check
 * =================
 *
 * Signature: dcu_chain_state is 0x6 and dcu_complete_state is 0x1.
 *
 * The state of each DCU chain (mapped to TX queues) is available from these
 * DMA debug registers:
 *
 * Chain 0 state : Bits 4:0   of AR_DMADBG_4
 * Chain 1 state : Bits 9:5   of AR_DMADBG_4
 * Chain 2 state : Bits 14:10 of AR_DMADBG_4
 * Chain 3 state : Bits 19:15 of AR_DMADBG_4
 * Chain 4 state : Bits 24:20 of AR_DMADBG_4
 * Chain 5 state : Bits 29:25 of AR_DMADBG_4
 * Chain 6 state : Bits 4:0   of AR_DMADBG_5
 * Chain 7 state : Bits 9:5   of AR_DMADBG_5
 * Chain 8 state : Bits 14:10 of AR_DMADBG_5
 * Chain 9 state : Bits 19:15 of AR_DMADBG_5
 *
 * The DCU chain state "0x6" means "WAIT_FRDONE" - wait for TX frame to be done.
 */
917

918
#define NUM_STATUS_READS 50
919

920
static bool ath9k_hw_verify_hang(struct ath_hw *ah, unsigned int queue)
921
{
922 923 924
	u32 dma_dbg_chain, dma_dbg_complete;
	u8 dcu_chain_state, dcu_complete_state;
	int i;
925

926 927 928 929 930
	for (i = 0; i < NUM_STATUS_READS; i++) {
		if (queue < 6)
			dma_dbg_chain = REG_READ(ah, AR_DMADBG_4);
		else
			dma_dbg_chain = REG_READ(ah, AR_DMADBG_5);
931

932
		dma_dbg_complete = REG_READ(ah, AR_DMADBG_6);
933

934 935
		dcu_chain_state = (dma_dbg_chain >> (5 * queue)) & 0x1f;
		dcu_complete_state = dma_dbg_complete & 0x3;
936

937 938 939
		if ((dcu_chain_state != 0x6) || (dcu_complete_state != 0x1))
			return false;
	}
940 941

	ath_dbg(ath9k_hw_common(ah), RESET,
942
		"MAC Hang signature found for queue: %d\n", queue);
943

944 945
	return true;
}
946

947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
static bool ar9003_hw_detect_mac_hang(struct ath_hw *ah)
{
	u32 dma_dbg_4, dma_dbg_5, dma_dbg_6, chk_dbg;
	u8 dcu_chain_state, dcu_complete_state;
	bool dcu_wait_frdone = false;
	unsigned long chk_dcu = 0;
	unsigned int i = 0;

	dma_dbg_4 = REG_READ(ah, AR_DMADBG_4);
	dma_dbg_5 = REG_READ(ah, AR_DMADBG_5);
	dma_dbg_6 = REG_READ(ah, AR_DMADBG_6);

	dcu_complete_state = dma_dbg_6 & 0x3;
	if (dcu_complete_state != 0x1)
		goto exit;

	for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
		if (i < 6)
			chk_dbg = dma_dbg_4;
		else
			chk_dbg = dma_dbg_5;
968

969 970 971 972 973
		dcu_chain_state = (chk_dbg >> (5 * i)) & 0x1f;
		if (dcu_chain_state == 0x6) {
			dcu_wait_frdone = true;
			chk_dcu |= BIT(i);
		}
974 975
	}

976 977 978 979 980 981 982 983
	if ((dcu_complete_state == 0x1) && dcu_wait_frdone) {
		for_each_set_bit(i, &chk_dcu, ATH9K_NUM_TX_QUEUES) {
			if (ath9k_hw_verify_hang(ah, i))
				return true;
		}
	}
exit:
	return false;
984 985
}

986 987 988 989 990 991
/* Sets up the AR9003 hardware familiy callbacks */
void ar9003_hw_attach_ops(struct ath_hw *ah)
{
	struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
	struct ath_hw_ops *ops = ath9k_hw_ops(ah);

992
	ar9003_hw_init_mode_regs(ah);
993
	priv_ops->init_mode_gain_regs = ar9003_hw_init_mode_gain_regs;
994
	priv_ops->init_hang_checks = ar9003_hw_init_hang_checks;
995
	priv_ops->detect_mac_hang = ar9003_hw_detect_mac_hang;
996 997 998 999 1000 1001 1002

	ops->config_pci_powersave = ar9003_hw_configpcipowersave;

	ar9003_hw_attach_phy_ops(ah);
	ar9003_hw_attach_calib_ops(ah);
	ar9003_hw_attach_mac_ops(ah);
}