您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ath9k_ar9002_hw.c 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
  5. * Original from Linux kernel 3.0.1
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include "hw.h"
  20. #include "ar5008_initvals.h"
  21. #include "ar9001_initvals.h"
  22. #include "ar9002_initvals.h"
  23. #include "ar9002_phy.h"
  24. int modparam_force_new_ani;
  25. /* General hardware code for the A5008/AR9001/AR9002 hadware families */
  26. static void ar9002_hw_init_mode_regs(struct ath_hw *ah)
  27. {
  28. if (AR_SREV_9271(ah)) {
  29. INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
  30. ARRAY_SIZE(ar9271Modes_9271), 6);
  31. INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
  32. ARRAY_SIZE(ar9271Common_9271), 2);
  33. INIT_INI_ARRAY(&ah->iniCommon_normal_cck_fir_coeff_9271,
  34. ar9271Common_normal_cck_fir_coeff_9271,
  35. ARRAY_SIZE(ar9271Common_normal_cck_fir_coeff_9271), 2);
  36. INIT_INI_ARRAY(&ah->iniCommon_japan_2484_cck_fir_coeff_9271,
  37. ar9271Common_japan_2484_cck_fir_coeff_9271,
  38. ARRAY_SIZE(ar9271Common_japan_2484_cck_fir_coeff_9271), 2);
  39. INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
  40. ar9271Modes_9271_1_0_only,
  41. ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
  42. INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg,
  43. ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 6);
  44. INIT_INI_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
  45. ar9271Modes_high_power_tx_gain_9271,
  46. ARRAY_SIZE(ar9271Modes_high_power_tx_gain_9271), 6);
  47. INIT_INI_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
  48. ar9271Modes_normal_power_tx_gain_9271,
  49. ARRAY_SIZE(ar9271Modes_normal_power_tx_gain_9271), 6);
  50. return;
  51. }
  52. if (AR_SREV_9287_11_OR_LATER(ah)) {
  53. INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
  54. ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
  55. INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
  56. ARRAY_SIZE(ar9287Common_9287_1_1), 2);
  57. if (ah->config.pcie_clock_req)
  58. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  59. ar9287PciePhy_clkreq_off_L1_9287_1_1,
  60. ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
  61. else
  62. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  63. ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
  64. ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
  65. 2);
  66. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  67. INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
  68. ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
  69. INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
  70. ARRAY_SIZE(ar9285Common_9285_1_2), 2);
  71. if (ah->config.pcie_clock_req) {
  72. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  73. ar9285PciePhy_clkreq_off_L1_9285_1_2,
  74. ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
  75. } else {
  76. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  77. ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
  78. ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
  79. 2);
  80. }
  81. } else if (AR_SREV_9280_20_OR_LATER(ah)) {
  82. INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
  83. ARRAY_SIZE(ar9280Modes_9280_2), 6);
  84. INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
  85. ARRAY_SIZE(ar9280Common_9280_2), 2);
  86. if (ah->config.pcie_clock_req) {
  87. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  88. ar9280PciePhy_clkreq_off_L1_9280,
  89. ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280), 2);
  90. } else {
  91. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  92. ar9280PciePhy_clkreq_always_on_L1_9280,
  93. ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
  94. }
  95. INIT_INI_ARRAY(&ah->iniModesAdditional,
  96. ar9280Modes_fast_clock_9280_2,
  97. ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
  98. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  99. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
  100. ARRAY_SIZE(ar5416Modes_9160), 6);
  101. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
  102. ARRAY_SIZE(ar5416Common_9160), 2);
  103. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
  104. ARRAY_SIZE(ar5416Bank0_9160), 2);
  105. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
  106. ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
  107. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
  108. ARRAY_SIZE(ar5416Bank1_9160), 2);
  109. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
  110. ARRAY_SIZE(ar5416Bank2_9160), 2);
  111. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
  112. ARRAY_SIZE(ar5416Bank3_9160), 3);
  113. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
  114. ARRAY_SIZE(ar5416Bank6_9160), 3);
  115. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
  116. ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
  117. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
  118. ARRAY_SIZE(ar5416Bank7_9160), 2);
  119. if (AR_SREV_9160_11(ah)) {
  120. INIT_INI_ARRAY(&ah->iniAddac,
  121. ar5416Addac_9160_1_1,
  122. ARRAY_SIZE(ar5416Addac_9160_1_1), 2);
  123. } else {
  124. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
  125. ARRAY_SIZE(ar5416Addac_9160), 2);
  126. }
  127. } else if (AR_SREV_9100_OR_LATER(ah)) {
  128. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
  129. ARRAY_SIZE(ar5416Modes_9100), 6);
  130. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
  131. ARRAY_SIZE(ar5416Common_9100), 2);
  132. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
  133. ARRAY_SIZE(ar5416Bank0_9100), 2);
  134. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
  135. ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
  136. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
  137. ARRAY_SIZE(ar5416Bank1_9100), 2);
  138. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
  139. ARRAY_SIZE(ar5416Bank2_9100), 2);
  140. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
  141. ARRAY_SIZE(ar5416Bank3_9100), 3);
  142. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
  143. ARRAY_SIZE(ar5416Bank6_9100), 3);
  144. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
  145. ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
  146. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
  147. ARRAY_SIZE(ar5416Bank7_9100), 2);
  148. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
  149. ARRAY_SIZE(ar5416Addac_9100), 2);
  150. } else {
  151. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
  152. ARRAY_SIZE(ar5416Modes), 6);
  153. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
  154. ARRAY_SIZE(ar5416Common), 2);
  155. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
  156. ARRAY_SIZE(ar5416Bank0), 2);
  157. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
  158. ARRAY_SIZE(ar5416BB_RfGain), 3);
  159. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
  160. ARRAY_SIZE(ar5416Bank1), 2);
  161. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
  162. ARRAY_SIZE(ar5416Bank2), 2);
  163. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
  164. ARRAY_SIZE(ar5416Bank3), 3);
  165. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
  166. ARRAY_SIZE(ar5416Bank6), 3);
  167. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
  168. ARRAY_SIZE(ar5416Bank6TPC), 3);
  169. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
  170. ARRAY_SIZE(ar5416Bank7), 2);
  171. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
  172. ARRAY_SIZE(ar5416Addac), 2);
  173. }
  174. }
  175. /* Support for Japan ch.14 (2484) spread */
  176. void ar9002_hw_cck_chan14_spread(struct ath_hw *ah)
  177. {
  178. if (AR_SREV_9287_11_OR_LATER(ah)) {
  179. INIT_INI_ARRAY(&ah->iniCckfirNormal,
  180. ar9287Common_normal_cck_fir_coeff_9287_1_1,
  181. ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_9287_1_1),
  182. 2);
  183. INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
  184. ar9287Common_japan_2484_cck_fir_coeff_9287_1_1,
  185. ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_9287_1_1),
  186. 2);
  187. }
  188. }
  189. static void ar9280_20_hw_init_rxgain_ini(struct ath_hw *ah)
  190. {
  191. u32 rxgain_type;
  192. if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >=
  193. AR5416_EEP_MINOR_VER_17) {
  194. rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
  195. if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
  196. INIT_INI_ARRAY(&ah->iniModesRxGain,
  197. ar9280Modes_backoff_13db_rxgain_9280_2,
  198. ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
  199. else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
  200. INIT_INI_ARRAY(&ah->iniModesRxGain,
  201. ar9280Modes_backoff_23db_rxgain_9280_2,
  202. ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
  203. else
  204. INIT_INI_ARRAY(&ah->iniModesRxGain,
  205. ar9280Modes_original_rxgain_9280_2,
  206. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
  207. } else {
  208. INIT_INI_ARRAY(&ah->iniModesRxGain,
  209. ar9280Modes_original_rxgain_9280_2,
  210. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
  211. }
  212. }
  213. static void ar9280_20_hw_init_txgain_ini(struct ath_hw *ah)
  214. {
  215. u32 txgain_type;
  216. if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >=
  217. AR5416_EEP_MINOR_VER_19) {
  218. txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  219. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
  220. INIT_INI_ARRAY(&ah->iniModesTxGain,
  221. ar9280Modes_high_power_tx_gain_9280_2,
  222. ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
  223. else
  224. INIT_INI_ARRAY(&ah->iniModesTxGain,
  225. ar9280Modes_original_tx_gain_9280_2,
  226. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
  227. } else {
  228. INIT_INI_ARRAY(&ah->iniModesTxGain,
  229. ar9280Modes_original_tx_gain_9280_2,
  230. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
  231. }
  232. }
  233. static void ar9002_hw_init_mode_gain_regs(struct ath_hw *ah)
  234. {
  235. if (AR_SREV_9287_11_OR_LATER(ah))
  236. INIT_INI_ARRAY(&ah->iniModesRxGain,
  237. ar9287Modes_rx_gain_9287_1_1,
  238. ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
  239. else if (AR_SREV_9280_20(ah))
  240. ar9280_20_hw_init_rxgain_ini(ah);
  241. if (AR_SREV_9287_11_OR_LATER(ah)) {
  242. INIT_INI_ARRAY(&ah->iniModesTxGain,
  243. ar9287Modes_tx_gain_9287_1_1,
  244. ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
  245. } else if (AR_SREV_9280_20(ah)) {
  246. ar9280_20_hw_init_txgain_ini(ah);
  247. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  248. u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  249. /* txgain table */
  250. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
  251. if (AR_SREV_9285E_20(ah)) {
  252. INIT_INI_ARRAY(&ah->iniModesTxGain,
  253. ar9285Modes_XE2_0_high_power,
  254. ARRAY_SIZE(
  255. ar9285Modes_XE2_0_high_power), 6);
  256. } else {
  257. INIT_INI_ARRAY(&ah->iniModesTxGain,
  258. ar9285Modes_high_power_tx_gain_9285_1_2,
  259. ARRAY_SIZE(
  260. ar9285Modes_high_power_tx_gain_9285_1_2), 6);
  261. }
  262. } else {
  263. if (AR_SREV_9285E_20(ah)) {
  264. INIT_INI_ARRAY(&ah->iniModesTxGain,
  265. ar9285Modes_XE2_0_normal_power,
  266. ARRAY_SIZE(
  267. ar9285Modes_XE2_0_normal_power), 6);
  268. } else {
  269. INIT_INI_ARRAY(&ah->iniModesTxGain,
  270. ar9285Modes_original_tx_gain_9285_1_2,
  271. ARRAY_SIZE(
  272. ar9285Modes_original_tx_gain_9285_1_2), 6);
  273. }
  274. }
  275. }
  276. }
  277. /*
  278. * Helper for ASPM support.
  279. *
  280. * Disable PLL when in L0s as well as receiver clock when in L1.
  281. * This power saving option must be enabled through the SerDes.
  282. *
  283. * Programming the SerDes must go through the same 288 bit serial shift
  284. * register as the other analog registers. Hence the 9 writes.
  285. */
  286. static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
  287. int restore,
  288. int power_off)
  289. {
  290. u8 i;
  291. u32 val;
  292. if (ah->is_pciexpress != 1)
  293. return;
  294. /* Do not touch SerDes registers */
  295. if (ah->config.pcie_powersave_enable == 2)
  296. return;
  297. /* Nothing to do on restore for 11N */
  298. if (!restore) {
  299. if (AR_SREV_9280_20_OR_LATER(ah)) {
  300. /*
  301. * AR9280 2.0 or later chips use SerDes values from the
  302. * initvals.h initialized depending on chipset during
  303. * __ath9k_hw_init()
  304. */
  305. for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
  306. REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
  307. INI_RA(&ah->iniPcieSerdes, i, 1));
  308. }
  309. } else {
  310. ENABLE_REGWRITE_BUFFER(ah);
  311. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  312. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  313. /* RX shut off when elecidle is asserted */
  314. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
  315. REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
  316. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
  317. /*
  318. * Ignore ah->ah_config.pcie_clock_req setting for
  319. * pre-AR9280 11n
  320. */
  321. REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
  322. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  323. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  324. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
  325. /* Load the new settings */
  326. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  327. REGWRITE_BUFFER_FLUSH(ah);
  328. }
  329. udelay(1000);
  330. }
  331. if (power_off) {
  332. /* clear bit 19 to disable L1 */
  333. REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  334. val = REG_READ(ah, AR_WA);
  335. /*
  336. * Set PCIe workaround bits
  337. * In AR9280 and AR9285, bit 14 in WA register (disable L1)
  338. * should only be set when device enters D3 and be
  339. * cleared when device comes back to D0.
  340. */
  341. if (ah->config.pcie_waen) {
  342. if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
  343. val |= AR_WA_D3_L1_DISABLE;
  344. } else {
  345. if (((AR_SREV_9285(ah) ||
  346. AR_SREV_9271(ah) ||
  347. AR_SREV_9287(ah)) &&
  348. (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
  349. (AR_SREV_9280(ah) &&
  350. (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
  351. val |= AR_WA_D3_L1_DISABLE;
  352. }
  353. }
  354. if (AR_SREV_9280(ah) || AR_SREV_9285(ah) || AR_SREV_9287(ah)) {
  355. /*
  356. * Disable bit 6 and 7 before entering D3 to
  357. * prevent system hang.
  358. */
  359. val &= ~(AR_WA_BIT6 | AR_WA_BIT7);
  360. }
  361. if (AR_SREV_9280(ah))
  362. val |= AR_WA_BIT22;
  363. if (AR_SREV_9285E_20(ah))
  364. val |= AR_WA_BIT23;
  365. REG_WRITE(ah, AR_WA, val);
  366. } else {
  367. if (ah->config.pcie_waen) {
  368. val = ah->config.pcie_waen;
  369. if (!power_off)
  370. val &= (~AR_WA_D3_L1_DISABLE);
  371. } else {
  372. if (AR_SREV_9285(ah) ||
  373. AR_SREV_9271(ah) ||
  374. AR_SREV_9287(ah)) {
  375. val = AR9285_WA_DEFAULT;
  376. if (!power_off)
  377. val &= (~AR_WA_D3_L1_DISABLE);
  378. }
  379. else if (AR_SREV_9280(ah)) {
  380. /*
  381. * For AR9280 chips, bit 22 of 0x4004
  382. * needs to be set.
  383. */
  384. val = AR9280_WA_DEFAULT;
  385. if (!power_off)
  386. val &= (~AR_WA_D3_L1_DISABLE);
  387. } else {
  388. val = AR_WA_DEFAULT;
  389. }
  390. }
  391. /* WAR for ASPM system hang */
  392. if (AR_SREV_9285(ah) || AR_SREV_9287(ah))
  393. val |= (AR_WA_BIT6 | AR_WA_BIT7);
  394. if (AR_SREV_9285E_20(ah))
  395. val |= AR_WA_BIT23;
  396. REG_WRITE(ah, AR_WA, val);
  397. /* set bit 19 to allow forcing of pcie core into L1 state */
  398. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  399. }
  400. }
  401. static int ar9002_hw_get_radiorev(struct ath_hw *ah)
  402. {
  403. u32 val;
  404. int i;
  405. ENABLE_REGWRITE_BUFFER(ah);
  406. REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
  407. for (i = 0; i < 8; i++)
  408. REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
  409. REGWRITE_BUFFER_FLUSH(ah);
  410. val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
  411. val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
  412. return ath9k_hw_reverse_bits(val, 8);
  413. }
  414. int ar9002_hw_rf_claim(struct ath_hw *ah)
  415. {
  416. u32 val;
  417. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  418. val = ar9002_hw_get_radiorev(ah);
  419. switch (val & AR_RADIO_SREV_MAJOR) {
  420. case 0:
  421. val = AR_RAD5133_SREV_MAJOR;
  422. break;
  423. case AR_RAD5133_SREV_MAJOR:
  424. case AR_RAD5122_SREV_MAJOR:
  425. case AR_RAD2133_SREV_MAJOR:
  426. case AR_RAD2122_SREV_MAJOR:
  427. break;
  428. default:
  429. DBG("ath9k: "
  430. "Radio Chip Rev 0x%02X not supported\n",
  431. val & AR_RADIO_SREV_MAJOR);
  432. return -EOPNOTSUPP;
  433. }
  434. ah->hw_version.analog5GhzRev = val;
  435. return 0;
  436. }
  437. void ar9002_hw_enable_async_fifo(struct ath_hw *ah)
  438. {
  439. if (AR_SREV_9287_13_OR_LATER(ah)) {
  440. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  441. AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
  442. REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
  443. REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  444. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  445. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  446. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  447. }
  448. }
  449. /*
  450. * If Async FIFO is enabled, the following counters change as MAC now runs
  451. * at 117 Mhz instead of 88/44MHz when async FIFO is disabled.
  452. *
  453. * The values below tested for ht40 2 chain.
  454. * Overwrite the delay/timeouts initialized in process ini.
  455. */
  456. void ar9002_hw_update_async_fifo(struct ath_hw *ah)
  457. {
  458. if (AR_SREV_9287_13_OR_LATER(ah)) {
  459. REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
  460. AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
  461. REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
  462. AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
  463. REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
  464. AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
  465. REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
  466. REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
  467. REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
  468. AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
  469. REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
  470. AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
  471. }
  472. }
  473. /*
  474. * We don't enable WEP aggregation on mac80211 but we keep this
  475. * around for HAL unification purposes.
  476. */
  477. void ar9002_hw_enable_wep_aggregation(struct ath_hw *ah)
  478. {
  479. if (AR_SREV_9287_13_OR_LATER(ah)) {
  480. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  481. AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
  482. }
  483. }
  484. /* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
  485. void ar9002_hw_attach_ops(struct ath_hw *ah)
  486. {
  487. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  488. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  489. priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
  490. priv_ops->init_mode_gain_regs = ar9002_hw_init_mode_gain_regs;
  491. ops->config_pci_powersave = ar9002_hw_configpcipowersave;
  492. ar5008_hw_attach_phy_ops(ah);
  493. if (AR_SREV_9280_20_OR_LATER(ah))
  494. ar9002_hw_attach_phy_ops(ah);
  495. ar9002_hw_attach_calib_ops(ah);
  496. ar9002_hw_attach_mac_ops(ah);
  497. }
  498. void ar9002_hw_load_ani_reg(struct ath_hw *ah, struct ath9k_channel *chan)
  499. {
  500. u32 modesIndex;
  501. unsigned int i;
  502. switch (chan->chanmode) {
  503. case CHANNEL_A:
  504. case CHANNEL_A_HT20:
  505. modesIndex = 1;
  506. break;
  507. case CHANNEL_A_HT40PLUS:
  508. case CHANNEL_A_HT40MINUS:
  509. modesIndex = 2;
  510. break;
  511. case CHANNEL_G:
  512. case CHANNEL_G_HT20:
  513. case CHANNEL_B:
  514. modesIndex = 4;
  515. break;
  516. case CHANNEL_G_HT40PLUS:
  517. case CHANNEL_G_HT40MINUS:
  518. modesIndex = 3;
  519. break;
  520. default:
  521. return;
  522. }
  523. ENABLE_REGWRITE_BUFFER(ah);
  524. for (i = 0; i < ah->iniModes_9271_ANI_reg.ia_rows; i++) {
  525. u32 reg = INI_RA(&ah->iniModes_9271_ANI_reg, i, 0);
  526. u32 val = INI_RA(&ah->iniModes_9271_ANI_reg, i, modesIndex);
  527. u32 val_orig;
  528. if (reg == AR_PHY_CCK_DETECT) {
  529. val_orig = REG_READ(ah, reg);
  530. val &= AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
  531. val_orig &= ~AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
  532. REG_WRITE(ah, reg, val|val_orig);
  533. } else
  534. REG_WRITE(ah, reg, val);
  535. }
  536. REGWRITE_BUFFER_FLUSH(ah);
  537. }