ARM: mm: Recreate kernel mappings in early_paging_init()
[linux/fpc-iii.git] / drivers / net / wireless / ath / ath9k / ar9002_hw.c
blobfb61b081d1721124518f7c4cad85792cedaefac0
1 /*
2 * Copyright (c) 2008-2011 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/moduleparam.h>
18 #include "hw.h"
19 #include "ar5008_initvals.h"
20 #include "ar9001_initvals.h"
21 #include "ar9002_initvals.h"
22 #include "ar9002_phy.h"
24 /* General hardware code for the A5008/AR9001/AR9002 hadware families */
26 static int ar9002_hw_init_mode_regs(struct ath_hw *ah)
28 if (AR_SREV_9271(ah)) {
29 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271);
30 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271);
31 INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg);
32 return 0;
35 if (ah->config.pcie_clock_req)
36 INIT_INI_ARRAY(&ah->iniPcieSerdes,
37 ar9280PciePhy_clkreq_off_L1_9280);
38 else
39 INIT_INI_ARRAY(&ah->iniPcieSerdes,
40 ar9280PciePhy_clkreq_always_on_L1_9280);
42 if (AR_SREV_9287_11_OR_LATER(ah)) {
43 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1);
44 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1);
45 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
46 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2);
47 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2);
48 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
49 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2);
50 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2);
52 INIT_INI_ARRAY(&ah->iniModesFastClock,
53 ar9280Modes_fast_clock_9280_2);
54 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
55 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160);
56 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160);
57 if (AR_SREV_9160_11(ah)) {
58 INIT_INI_ARRAY(&ah->iniAddac,
59 ar5416Addac_9160_1_1);
60 } else {
61 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160);
63 } else if (AR_SREV_9100_OR_LATER(ah)) {
64 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100);
65 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100);
66 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100);
67 } else {
68 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes);
69 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common);
70 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac);
73 if (!AR_SREV_9280_20_OR_LATER(ah)) {
74 /* Common for AR5416, AR913x, AR9160 */
75 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain);
77 /* Common for AR913x, AR9160 */
78 if (!AR_SREV_5416(ah))
79 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6TPC_9100);
80 else
81 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6TPC);
84 /* iniAddac needs to be modified for these chips */
85 if (AR_SREV_9160(ah) || !AR_SREV_5416_22_OR_LATER(ah)) {
86 struct ar5416IniArray *addac = &ah->iniAddac;
87 u32 size = sizeof(u32) * addac->ia_rows * addac->ia_columns;
88 u32 *data;
90 data = devm_kzalloc(ah->dev, size, GFP_KERNEL);
91 if (!data)
92 return -ENOMEM;
94 memcpy(data, addac->ia_array, size);
95 addac->ia_array = data;
97 if (!AR_SREV_5416_22_OR_LATER(ah)) {
98 /* override CLKDRV value */
99 INI_RA(addac, 31,1) = 0;
102 if (AR_SREV_9287_11_OR_LATER(ah)) {
103 INIT_INI_ARRAY(&ah->iniCckfirNormal,
104 ar9287Common_normal_cck_fir_coeff_9287_1_1);
105 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
106 ar9287Common_japan_2484_cck_fir_coeff_9287_1_1);
108 return 0;
111 static void ar9280_20_hw_init_rxgain_ini(struct ath_hw *ah)
113 u32 rxgain_type;
115 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >=
116 AR5416_EEP_MINOR_VER_17) {
117 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
119 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
120 INIT_INI_ARRAY(&ah->iniModesRxGain,
121 ar9280Modes_backoff_13db_rxgain_9280_2);
122 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
123 INIT_INI_ARRAY(&ah->iniModesRxGain,
124 ar9280Modes_backoff_23db_rxgain_9280_2);
125 else
126 INIT_INI_ARRAY(&ah->iniModesRxGain,
127 ar9280Modes_original_rxgain_9280_2);
128 } else {
129 INIT_INI_ARRAY(&ah->iniModesRxGain,
130 ar9280Modes_original_rxgain_9280_2);
134 static void ar9280_20_hw_init_txgain_ini(struct ath_hw *ah, u32 txgain_type)
136 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >=
137 AR5416_EEP_MINOR_VER_19) {
138 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
139 INIT_INI_ARRAY(&ah->iniModesTxGain,
140 ar9280Modes_high_power_tx_gain_9280_2);
141 else
142 INIT_INI_ARRAY(&ah->iniModesTxGain,
143 ar9280Modes_original_tx_gain_9280_2);
144 } else {
145 INIT_INI_ARRAY(&ah->iniModesTxGain,
146 ar9280Modes_original_tx_gain_9280_2);
150 static void ar9271_hw_init_txgain_ini(struct ath_hw *ah, u32 txgain_type)
152 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
153 INIT_INI_ARRAY(&ah->iniModesTxGain,
154 ar9271Modes_high_power_tx_gain_9271);
155 else
156 INIT_INI_ARRAY(&ah->iniModesTxGain,
157 ar9271Modes_normal_power_tx_gain_9271);
160 static void ar9002_hw_init_mode_gain_regs(struct ath_hw *ah)
162 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
164 if (AR_SREV_9287_11_OR_LATER(ah))
165 INIT_INI_ARRAY(&ah->iniModesRxGain,
166 ar9287Modes_rx_gain_9287_1_1);
167 else if (AR_SREV_9280_20(ah))
168 ar9280_20_hw_init_rxgain_ini(ah);
170 if (AR_SREV_9271(ah)) {
171 ar9271_hw_init_txgain_ini(ah, txgain_type);
172 } else if (AR_SREV_9287_11_OR_LATER(ah)) {
173 INIT_INI_ARRAY(&ah->iniModesTxGain,
174 ar9287Modes_tx_gain_9287_1_1);
175 } else if (AR_SREV_9280_20(ah)) {
176 ar9280_20_hw_init_txgain_ini(ah, txgain_type);
177 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
178 /* txgain table */
179 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
180 if (AR_SREV_9285E_20(ah)) {
181 INIT_INI_ARRAY(&ah->iniModesTxGain,
182 ar9285Modes_XE2_0_high_power);
183 } else {
184 INIT_INI_ARRAY(&ah->iniModesTxGain,
185 ar9285Modes_high_power_tx_gain_9285_1_2);
187 } else {
188 if (AR_SREV_9285E_20(ah)) {
189 INIT_INI_ARRAY(&ah->iniModesTxGain,
190 ar9285Modes_XE2_0_normal_power);
191 } else {
192 INIT_INI_ARRAY(&ah->iniModesTxGain,
193 ar9285Modes_original_tx_gain_9285_1_2);
200 * Helper for ASPM support.
202 * Disable PLL when in L0s as well as receiver clock when in L1.
203 * This power saving option must be enabled through the SerDes.
205 * Programming the SerDes must go through the same 288 bit serial shift
206 * register as the other analog registers. Hence the 9 writes.
208 static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
209 bool power_off)
211 u8 i;
212 u32 val;
214 /* Nothing to do on restore for 11N */
215 if (!power_off /* !restore */) {
216 if (AR_SREV_9280_20_OR_LATER(ah)) {
218 * AR9280 2.0 or later chips use SerDes values from the
219 * initvals.h initialized depending on chipset during
220 * __ath9k_hw_init()
222 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
223 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
224 INI_RA(&ah->iniPcieSerdes, i, 1));
226 } else {
227 ENABLE_REGWRITE_BUFFER(ah);
229 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
230 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
232 /* RX shut off when elecidle is asserted */
233 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
234 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
235 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
238 * Ignore ah->ah_config.pcie_clock_req setting for
239 * pre-AR9280 11n
241 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
243 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
244 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
245 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
247 /* Load the new settings */
248 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
250 REGWRITE_BUFFER_FLUSH(ah);
253 udelay(1000);
256 if (power_off) {
257 /* clear bit 19 to disable L1 */
258 REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
260 val = REG_READ(ah, AR_WA);
263 * Set PCIe workaround bits
264 * In AR9280 and AR9285, bit 14 in WA register (disable L1)
265 * should only be set when device enters D3 and be
266 * cleared when device comes back to D0.
268 if (ah->config.pcie_waen) {
269 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
270 val |= AR_WA_D3_L1_DISABLE;
271 } else {
272 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) {
273 if (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)
274 val |= AR_WA_D3_L1_DISABLE;
275 } else if (AR_SREV_9280(ah)) {
276 if (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE)
277 val |= AR_WA_D3_L1_DISABLE;
281 if (AR_SREV_9280(ah) || AR_SREV_9285(ah) || AR_SREV_9287(ah)) {
283 * Disable bit 6 and 7 before entering D3 to
284 * prevent system hang.
286 val &= ~(AR_WA_BIT6 | AR_WA_BIT7);
289 if (AR_SREV_9280(ah))
290 val |= AR_WA_BIT22;
292 if (AR_SREV_9285E_20(ah))
293 val |= AR_WA_BIT23;
295 REG_WRITE(ah, AR_WA, val);
296 } else {
297 if (ah->config.pcie_waen) {
298 val = ah->config.pcie_waen;
299 val &= (~AR_WA_D3_L1_DISABLE);
300 } else {
301 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) {
302 val = AR9285_WA_DEFAULT;
303 val &= (~AR_WA_D3_L1_DISABLE);
304 } else if (AR_SREV_9280(ah)) {
306 * For AR9280 chips, bit 22 of 0x4004
307 * needs to be set.
309 val = AR9280_WA_DEFAULT;
310 val &= (~AR_WA_D3_L1_DISABLE);
311 } else {
312 val = AR_WA_DEFAULT;
316 /* WAR for ASPM system hang */
317 if (AR_SREV_9285(ah) || AR_SREV_9287(ah))
318 val |= (AR_WA_BIT6 | AR_WA_BIT7);
320 if (AR_SREV_9285E_20(ah))
321 val |= AR_WA_BIT23;
323 REG_WRITE(ah, AR_WA, val);
325 /* set bit 19 to allow forcing of pcie core into L1 state */
326 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
330 static int ar9002_hw_get_radiorev(struct ath_hw *ah)
332 u32 val;
333 int i;
335 ENABLE_REGWRITE_BUFFER(ah);
337 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
338 for (i = 0; i < 8; i++)
339 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
341 REGWRITE_BUFFER_FLUSH(ah);
343 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
344 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
346 return ath9k_hw_reverse_bits(val, 8);
349 int ar9002_hw_rf_claim(struct ath_hw *ah)
351 u32 val;
353 REG_WRITE(ah, AR_PHY(0), 0x00000007);
355 val = ar9002_hw_get_radiorev(ah);
356 switch (val & AR_RADIO_SREV_MAJOR) {
357 case 0:
358 val = AR_RAD5133_SREV_MAJOR;
359 break;
360 case AR_RAD5133_SREV_MAJOR:
361 case AR_RAD5122_SREV_MAJOR:
362 case AR_RAD2133_SREV_MAJOR:
363 case AR_RAD2122_SREV_MAJOR:
364 break;
365 default:
366 ath_err(ath9k_hw_common(ah),
367 "Radio Chip Rev 0x%02X not supported\n",
368 val & AR_RADIO_SREV_MAJOR);
369 return -EOPNOTSUPP;
372 ah->hw_version.analog5GhzRev = val;
374 return 0;
377 void ar9002_hw_enable_async_fifo(struct ath_hw *ah)
379 if (AR_SREV_9287_13_OR_LATER(ah)) {
380 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
381 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
382 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
383 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
384 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
385 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
386 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
390 /* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
391 int ar9002_hw_attach_ops(struct ath_hw *ah)
393 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
394 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
395 int ret;
397 ret = ar9002_hw_init_mode_regs(ah);
398 if (ret)
399 return ret;
401 priv_ops->init_mode_gain_regs = ar9002_hw_init_mode_gain_regs;
403 ops->config_pci_powersave = ar9002_hw_configpcipowersave;
405 ret = ar5008_hw_attach_phy_ops(ah);
406 if (ret)
407 return ret;
409 if (AR_SREV_9280_20_OR_LATER(ah))
410 ar9002_hw_attach_phy_ops(ah);
412 ar9002_hw_attach_calib_ops(ah);
413 ar9002_hw_attach_mac_ops(ah);
414 return 0;
417 void ar9002_hw_load_ani_reg(struct ath_hw *ah, struct ath9k_channel *chan)
419 u32 modesIndex;
420 int i;
422 switch (chan->chanmode) {
423 case CHANNEL_A:
424 case CHANNEL_A_HT20:
425 modesIndex = 1;
426 break;
427 case CHANNEL_A_HT40PLUS:
428 case CHANNEL_A_HT40MINUS:
429 modesIndex = 2;
430 break;
431 case CHANNEL_G:
432 case CHANNEL_G_HT20:
433 case CHANNEL_B:
434 modesIndex = 4;
435 break;
436 case CHANNEL_G_HT40PLUS:
437 case CHANNEL_G_HT40MINUS:
438 modesIndex = 3;
439 break;
441 default:
442 return;
445 ENABLE_REGWRITE_BUFFER(ah);
447 for (i = 0; i < ah->iniModes_9271_ANI_reg.ia_rows; i++) {
448 u32 reg = INI_RA(&ah->iniModes_9271_ANI_reg, i, 0);
449 u32 val = INI_RA(&ah->iniModes_9271_ANI_reg, i, modesIndex);
450 u32 val_orig;
452 if (reg == AR_PHY_CCK_DETECT) {
453 val_orig = REG_READ(ah, reg);
454 val &= AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
455 val_orig &= ~AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
457 REG_WRITE(ah, reg, val|val_orig);
458 } else
459 REG_WRITE(ah, reg, val);
462 REGWRITE_BUFFER_FLUSH(ah);