ar9002_hw.c 17 KB

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