ar9002_hw.c 17 KB

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