ar9002_hw.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /*
  2. * Copyright (c) 2008-2011 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), 5);
  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), 5);
  41. INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg,
  42. ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 5);
  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), 5);
  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), 5);
  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), 5);
  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), 5);
  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), 5);
  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), 5);
  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), 5);
  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), 5);
  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), 5);
  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), 5);
  202. else
  203. INIT_INI_ARRAY(&ah->iniModesRxGain,
  204. ar9280Modes_original_rxgain_9280_2,
  205. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 5);
  206. } else {
  207. INIT_INI_ARRAY(&ah->iniModesRxGain,
  208. ar9280Modes_original_rxgain_9280_2,
  209. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 5);
  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), 5);
  222. else
  223. INIT_INI_ARRAY(&ah->iniModesTxGain,
  224. ar9280Modes_original_tx_gain_9280_2,
  225. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 5);
  226. } else {
  227. INIT_INI_ARRAY(&ah->iniModesTxGain,
  228. ar9280Modes_original_tx_gain_9280_2,
  229. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 5);
  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), 5);
  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), 5);
  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), 5);
  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), 5);
  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), 5);
  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), 5);
  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. bool power_off)
  287. {
  288. u8 i;
  289. u32 val;
  290. /* Nothing to do on restore for 11N */
  291. if (!power_off /* !restore */) {
  292. if (AR_SREV_9280_20_OR_LATER(ah)) {
  293. /*
  294. * AR9280 2.0 or later chips use SerDes values from the
  295. * initvals.h initialized depending on chipset during
  296. * __ath9k_hw_init()
  297. */
  298. for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
  299. REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
  300. INI_RA(&ah->iniPcieSerdes, i, 1));
  301. }
  302. } else {
  303. ENABLE_REGWRITE_BUFFER(ah);
  304. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  305. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  306. /* RX shut off when elecidle is asserted */
  307. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
  308. REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
  309. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
  310. /*
  311. * Ignore ah->ah_config.pcie_clock_req setting for
  312. * pre-AR9280 11n
  313. */
  314. REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
  315. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  316. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  317. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
  318. /* Load the new settings */
  319. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  320. REGWRITE_BUFFER_FLUSH(ah);
  321. }
  322. udelay(1000);
  323. }
  324. if (power_off) {
  325. /* clear bit 19 to disable L1 */
  326. REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  327. val = REG_READ(ah, AR_WA);
  328. /*
  329. * Set PCIe workaround bits
  330. * In AR9280 and AR9285, bit 14 in WA register (disable L1)
  331. * should only be set when device enters D3 and be
  332. * cleared when device comes back to D0.
  333. */
  334. if (ah->config.pcie_waen) {
  335. if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
  336. val |= AR_WA_D3_L1_DISABLE;
  337. } else {
  338. if (((AR_SREV_9285(ah) ||
  339. AR_SREV_9271(ah) ||
  340. AR_SREV_9287(ah)) &&
  341. (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
  342. (AR_SREV_9280(ah) &&
  343. (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
  344. val |= AR_WA_D3_L1_DISABLE;
  345. }
  346. }
  347. if (AR_SREV_9280(ah) || AR_SREV_9285(ah) || AR_SREV_9287(ah)) {
  348. /*
  349. * Disable bit 6 and 7 before entering D3 to
  350. * prevent system hang.
  351. */
  352. val &= ~(AR_WA_BIT6 | AR_WA_BIT7);
  353. }
  354. if (AR_SREV_9280(ah))
  355. val |= AR_WA_BIT22;
  356. if (AR_SREV_9285E_20(ah))
  357. val |= AR_WA_BIT23;
  358. REG_WRITE(ah, AR_WA, val);
  359. } else {
  360. if (ah->config.pcie_waen) {
  361. val = ah->config.pcie_waen;
  362. if (!power_off)
  363. val &= (~AR_WA_D3_L1_DISABLE);
  364. } else {
  365. if (AR_SREV_9285(ah) ||
  366. AR_SREV_9271(ah) ||
  367. AR_SREV_9287(ah)) {
  368. val = AR9285_WA_DEFAULT;
  369. if (!power_off)
  370. val &= (~AR_WA_D3_L1_DISABLE);
  371. }
  372. else if (AR_SREV_9280(ah)) {
  373. /*
  374. * For AR9280 chips, bit 22 of 0x4004
  375. * needs to be set.
  376. */
  377. val = AR9280_WA_DEFAULT;
  378. if (!power_off)
  379. val &= (~AR_WA_D3_L1_DISABLE);
  380. } else {
  381. val = AR_WA_DEFAULT;
  382. }
  383. }
  384. /* WAR for ASPM system hang */
  385. if (AR_SREV_9285(ah) || AR_SREV_9287(ah))
  386. val |= (AR_WA_BIT6 | AR_WA_BIT7);
  387. if (AR_SREV_9285E_20(ah))
  388. val |= AR_WA_BIT23;
  389. REG_WRITE(ah, AR_WA, val);
  390. /* set bit 19 to allow forcing of pcie core into L1 state */
  391. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  392. }
  393. }
  394. static int ar9002_hw_get_radiorev(struct ath_hw *ah)
  395. {
  396. u32 val;
  397. int i;
  398. ENABLE_REGWRITE_BUFFER(ah);
  399. REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
  400. for (i = 0; i < 8; i++)
  401. REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
  402. REGWRITE_BUFFER_FLUSH(ah);
  403. val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
  404. val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
  405. return ath9k_hw_reverse_bits(val, 8);
  406. }
  407. int ar9002_hw_rf_claim(struct ath_hw *ah)
  408. {
  409. u32 val;
  410. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  411. val = ar9002_hw_get_radiorev(ah);
  412. switch (val & AR_RADIO_SREV_MAJOR) {
  413. case 0:
  414. val = AR_RAD5133_SREV_MAJOR;
  415. break;
  416. case AR_RAD5133_SREV_MAJOR:
  417. case AR_RAD5122_SREV_MAJOR:
  418. case AR_RAD2133_SREV_MAJOR:
  419. case AR_RAD2122_SREV_MAJOR:
  420. break;
  421. default:
  422. ath_err(ath9k_hw_common(ah),
  423. "Radio Chip Rev 0x%02X not supported\n",
  424. val & AR_RADIO_SREV_MAJOR);
  425. return -EOPNOTSUPP;
  426. }
  427. ah->hw_version.analog5GhzRev = val;
  428. return 0;
  429. }
  430. void ar9002_hw_enable_async_fifo(struct ath_hw *ah)
  431. {
  432. if (AR_SREV_9287_13_OR_LATER(ah)) {
  433. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  434. AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
  435. REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
  436. REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  437. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  438. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  439. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  440. }
  441. }
  442. /* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
  443. void ar9002_hw_attach_ops(struct ath_hw *ah)
  444. {
  445. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  446. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  447. priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
  448. priv_ops->init_mode_gain_regs = ar9002_hw_init_mode_gain_regs;
  449. ops->config_pci_powersave = ar9002_hw_configpcipowersave;
  450. ar5008_hw_attach_phy_ops(ah);
  451. if (AR_SREV_9280_20_OR_LATER(ah))
  452. ar9002_hw_attach_phy_ops(ah);
  453. ar9002_hw_attach_calib_ops(ah);
  454. ar9002_hw_attach_mac_ops(ah);
  455. }
  456. void ar9002_hw_load_ani_reg(struct ath_hw *ah, struct ath9k_channel *chan)
  457. {
  458. u32 modesIndex;
  459. int i;
  460. switch (chan->chanmode) {
  461. case CHANNEL_A:
  462. case CHANNEL_A_HT20:
  463. modesIndex = 1;
  464. break;
  465. case CHANNEL_A_HT40PLUS:
  466. case CHANNEL_A_HT40MINUS:
  467. modesIndex = 2;
  468. break;
  469. case CHANNEL_G:
  470. case CHANNEL_G_HT20:
  471. case CHANNEL_B:
  472. modesIndex = 4;
  473. break;
  474. case CHANNEL_G_HT40PLUS:
  475. case CHANNEL_G_HT40MINUS:
  476. modesIndex = 3;
  477. break;
  478. default:
  479. return;
  480. }
  481. ENABLE_REGWRITE_BUFFER(ah);
  482. for (i = 0; i < ah->iniModes_9271_ANI_reg.ia_rows; i++) {
  483. u32 reg = INI_RA(&ah->iniModes_9271_ANI_reg, i, 0);
  484. u32 val = INI_RA(&ah->iniModes_9271_ANI_reg, i, modesIndex);
  485. u32 val_orig;
  486. if (reg == AR_PHY_CCK_DETECT) {
  487. val_orig = REG_READ(ah, reg);
  488. val &= AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
  489. val_orig &= ~AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
  490. REG_WRITE(ah, reg, val|val_orig);
  491. } else
  492. REG_WRITE(ah, reg, val);
  493. }
  494. REGWRITE_BUFFER_FLUSH(ah);
  495. }