ar9002_hw.c 19 KB

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