ar9002_hw.c 18 KB

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