ar9002_hw.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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. /* iniAddac needs to be modified for these chips */
  175. if (AR_SREV_9160(ah) || !AR_SREV_5416_22_OR_LATER(ah)) {
  176. struct ar5416IniArray *addac = &ah->iniAddac;
  177. u32 size = sizeof(u32) * addac->ia_rows * addac->ia_columns;
  178. u32 *data;
  179. data = kmalloc(size, GFP_KERNEL);
  180. if (!data)
  181. return;
  182. memcpy(data, addac->ia_array, size);
  183. addac->ia_array = data;
  184. if (!AR_SREV_5416_22_OR_LATER(ah)) {
  185. /* override CLKDRV value */
  186. INI_RA(addac, 31,1) = 0;
  187. }
  188. }
  189. }
  190. /* Support for Japan ch.14 (2484) spread */
  191. void ar9002_hw_cck_chan14_spread(struct ath_hw *ah)
  192. {
  193. if (AR_SREV_9287_11_OR_LATER(ah)) {
  194. INIT_INI_ARRAY(&ah->iniCckfirNormal,
  195. ar9287Common_normal_cck_fir_coeff_9287_1_1,
  196. ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_9287_1_1),
  197. 2);
  198. INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
  199. ar9287Common_japan_2484_cck_fir_coeff_9287_1_1,
  200. ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_9287_1_1),
  201. 2);
  202. }
  203. }
  204. static void ar9280_20_hw_init_rxgain_ini(struct ath_hw *ah)
  205. {
  206. u32 rxgain_type;
  207. if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >=
  208. AR5416_EEP_MINOR_VER_17) {
  209. rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
  210. if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
  211. INIT_INI_ARRAY(&ah->iniModesRxGain,
  212. ar9280Modes_backoff_13db_rxgain_9280_2,
  213. ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 5);
  214. else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
  215. INIT_INI_ARRAY(&ah->iniModesRxGain,
  216. ar9280Modes_backoff_23db_rxgain_9280_2,
  217. ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 5);
  218. else
  219. INIT_INI_ARRAY(&ah->iniModesRxGain,
  220. ar9280Modes_original_rxgain_9280_2,
  221. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 5);
  222. } else {
  223. INIT_INI_ARRAY(&ah->iniModesRxGain,
  224. ar9280Modes_original_rxgain_9280_2,
  225. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 5);
  226. }
  227. }
  228. static void ar9280_20_hw_init_txgain_ini(struct ath_hw *ah)
  229. {
  230. u32 txgain_type;
  231. if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >=
  232. AR5416_EEP_MINOR_VER_19) {
  233. txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  234. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
  235. INIT_INI_ARRAY(&ah->iniModesTxGain,
  236. ar9280Modes_high_power_tx_gain_9280_2,
  237. ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 5);
  238. else
  239. INIT_INI_ARRAY(&ah->iniModesTxGain,
  240. ar9280Modes_original_tx_gain_9280_2,
  241. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 5);
  242. } else {
  243. INIT_INI_ARRAY(&ah->iniModesTxGain,
  244. ar9280Modes_original_tx_gain_9280_2,
  245. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 5);
  246. }
  247. }
  248. static void ar9002_hw_init_mode_gain_regs(struct ath_hw *ah)
  249. {
  250. if (AR_SREV_9287_11_OR_LATER(ah))
  251. INIT_INI_ARRAY(&ah->iniModesRxGain,
  252. ar9287Modes_rx_gain_9287_1_1,
  253. ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 5);
  254. else if (AR_SREV_9280_20(ah))
  255. ar9280_20_hw_init_rxgain_ini(ah);
  256. if (AR_SREV_9287_11_OR_LATER(ah)) {
  257. INIT_INI_ARRAY(&ah->iniModesTxGain,
  258. ar9287Modes_tx_gain_9287_1_1,
  259. ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 5);
  260. } else if (AR_SREV_9280_20(ah)) {
  261. ar9280_20_hw_init_txgain_ini(ah);
  262. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  263. u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  264. /* txgain table */
  265. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
  266. if (AR_SREV_9285E_20(ah)) {
  267. INIT_INI_ARRAY(&ah->iniModesTxGain,
  268. ar9285Modes_XE2_0_high_power,
  269. ARRAY_SIZE(
  270. ar9285Modes_XE2_0_high_power), 5);
  271. } else {
  272. INIT_INI_ARRAY(&ah->iniModesTxGain,
  273. ar9285Modes_high_power_tx_gain_9285_1_2,
  274. ARRAY_SIZE(
  275. ar9285Modes_high_power_tx_gain_9285_1_2), 5);
  276. }
  277. } else {
  278. if (AR_SREV_9285E_20(ah)) {
  279. INIT_INI_ARRAY(&ah->iniModesTxGain,
  280. ar9285Modes_XE2_0_normal_power,
  281. ARRAY_SIZE(
  282. ar9285Modes_XE2_0_normal_power), 5);
  283. } else {
  284. INIT_INI_ARRAY(&ah->iniModesTxGain,
  285. ar9285Modes_original_tx_gain_9285_1_2,
  286. ARRAY_SIZE(
  287. ar9285Modes_original_tx_gain_9285_1_2), 5);
  288. }
  289. }
  290. }
  291. }
  292. /*
  293. * Helper for ASPM support.
  294. *
  295. * Disable PLL when in L0s as well as receiver clock when in L1.
  296. * This power saving option must be enabled through the SerDes.
  297. *
  298. * Programming the SerDes must go through the same 288 bit serial shift
  299. * register as the other analog registers. Hence the 9 writes.
  300. */
  301. static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
  302. bool power_off)
  303. {
  304. u8 i;
  305. u32 val;
  306. /* Nothing to do on restore for 11N */
  307. if (!power_off /* !restore */) {
  308. if (AR_SREV_9280_20_OR_LATER(ah)) {
  309. /*
  310. * AR9280 2.0 or later chips use SerDes values from the
  311. * initvals.h initialized depending on chipset during
  312. * __ath9k_hw_init()
  313. */
  314. for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
  315. REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
  316. INI_RA(&ah->iniPcieSerdes, i, 1));
  317. }
  318. } else {
  319. ENABLE_REGWRITE_BUFFER(ah);
  320. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  321. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  322. /* RX shut off when elecidle is asserted */
  323. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
  324. REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
  325. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
  326. /*
  327. * Ignore ah->ah_config.pcie_clock_req setting for
  328. * pre-AR9280 11n
  329. */
  330. REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
  331. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  332. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  333. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
  334. /* Load the new settings */
  335. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  336. REGWRITE_BUFFER_FLUSH(ah);
  337. }
  338. udelay(1000);
  339. }
  340. if (power_off) {
  341. /* clear bit 19 to disable L1 */
  342. REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  343. val = REG_READ(ah, AR_WA);
  344. /*
  345. * Set PCIe workaround bits
  346. * In AR9280 and AR9285, bit 14 in WA register (disable L1)
  347. * should only be set when device enters D3 and be
  348. * cleared when device comes back to D0.
  349. */
  350. if (ah->config.pcie_waen) {
  351. if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
  352. val |= AR_WA_D3_L1_DISABLE;
  353. } else {
  354. if (((AR_SREV_9285(ah) ||
  355. AR_SREV_9271(ah) ||
  356. AR_SREV_9287(ah)) &&
  357. (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
  358. (AR_SREV_9280(ah) &&
  359. (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
  360. val |= AR_WA_D3_L1_DISABLE;
  361. }
  362. }
  363. if (AR_SREV_9280(ah) || AR_SREV_9285(ah) || AR_SREV_9287(ah)) {
  364. /*
  365. * Disable bit 6 and 7 before entering D3 to
  366. * prevent system hang.
  367. */
  368. val &= ~(AR_WA_BIT6 | AR_WA_BIT7);
  369. }
  370. if (AR_SREV_9280(ah))
  371. val |= AR_WA_BIT22;
  372. if (AR_SREV_9285E_20(ah))
  373. val |= AR_WA_BIT23;
  374. REG_WRITE(ah, AR_WA, val);
  375. } else {
  376. if (ah->config.pcie_waen) {
  377. val = ah->config.pcie_waen;
  378. if (!power_off)
  379. val &= (~AR_WA_D3_L1_DISABLE);
  380. } else {
  381. if (AR_SREV_9285(ah) ||
  382. AR_SREV_9271(ah) ||
  383. AR_SREV_9287(ah)) {
  384. val = AR9285_WA_DEFAULT;
  385. if (!power_off)
  386. val &= (~AR_WA_D3_L1_DISABLE);
  387. }
  388. else if (AR_SREV_9280(ah)) {
  389. /*
  390. * For AR9280 chips, bit 22 of 0x4004
  391. * needs to be set.
  392. */
  393. val = AR9280_WA_DEFAULT;
  394. if (!power_off)
  395. val &= (~AR_WA_D3_L1_DISABLE);
  396. } else {
  397. val = AR_WA_DEFAULT;
  398. }
  399. }
  400. /* WAR for ASPM system hang */
  401. if (AR_SREV_9285(ah) || AR_SREV_9287(ah))
  402. val |= (AR_WA_BIT6 | AR_WA_BIT7);
  403. if (AR_SREV_9285E_20(ah))
  404. val |= AR_WA_BIT23;
  405. REG_WRITE(ah, AR_WA, val);
  406. /* set bit 19 to allow forcing of pcie core into L1 state */
  407. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  408. }
  409. }
  410. static int ar9002_hw_get_radiorev(struct ath_hw *ah)
  411. {
  412. u32 val;
  413. int i;
  414. ENABLE_REGWRITE_BUFFER(ah);
  415. REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
  416. for (i = 0; i < 8; i++)
  417. REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
  418. REGWRITE_BUFFER_FLUSH(ah);
  419. val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
  420. val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
  421. return ath9k_hw_reverse_bits(val, 8);
  422. }
  423. int ar9002_hw_rf_claim(struct ath_hw *ah)
  424. {
  425. u32 val;
  426. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  427. val = ar9002_hw_get_radiorev(ah);
  428. switch (val & AR_RADIO_SREV_MAJOR) {
  429. case 0:
  430. val = AR_RAD5133_SREV_MAJOR;
  431. break;
  432. case AR_RAD5133_SREV_MAJOR:
  433. case AR_RAD5122_SREV_MAJOR:
  434. case AR_RAD2133_SREV_MAJOR:
  435. case AR_RAD2122_SREV_MAJOR:
  436. break;
  437. default:
  438. ath_err(ath9k_hw_common(ah),
  439. "Radio Chip Rev 0x%02X not supported\n",
  440. val & AR_RADIO_SREV_MAJOR);
  441. return -EOPNOTSUPP;
  442. }
  443. ah->hw_version.analog5GhzRev = val;
  444. return 0;
  445. }
  446. void ar9002_hw_enable_async_fifo(struct ath_hw *ah)
  447. {
  448. if (AR_SREV_9287_13_OR_LATER(ah)) {
  449. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  450. AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
  451. REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
  452. REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  453. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  454. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  455. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  456. }
  457. }
  458. /* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
  459. void ar9002_hw_attach_ops(struct ath_hw *ah)
  460. {
  461. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  462. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  463. priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
  464. priv_ops->init_mode_gain_regs = ar9002_hw_init_mode_gain_regs;
  465. ops->config_pci_powersave = ar9002_hw_configpcipowersave;
  466. ar5008_hw_attach_phy_ops(ah);
  467. if (AR_SREV_9280_20_OR_LATER(ah))
  468. ar9002_hw_attach_phy_ops(ah);
  469. ar9002_hw_attach_calib_ops(ah);
  470. ar9002_hw_attach_mac_ops(ah);
  471. }
  472. void ar9002_hw_load_ani_reg(struct ath_hw *ah, struct ath9k_channel *chan)
  473. {
  474. u32 modesIndex;
  475. int i;
  476. switch (chan->chanmode) {
  477. case CHANNEL_A:
  478. case CHANNEL_A_HT20:
  479. modesIndex = 1;
  480. break;
  481. case CHANNEL_A_HT40PLUS:
  482. case CHANNEL_A_HT40MINUS:
  483. modesIndex = 2;
  484. break;
  485. case CHANNEL_G:
  486. case CHANNEL_G_HT20:
  487. case CHANNEL_B:
  488. modesIndex = 4;
  489. break;
  490. case CHANNEL_G_HT40PLUS:
  491. case CHANNEL_G_HT40MINUS:
  492. modesIndex = 3;
  493. break;
  494. default:
  495. return;
  496. }
  497. ENABLE_REGWRITE_BUFFER(ah);
  498. for (i = 0; i < ah->iniModes_9271_ANI_reg.ia_rows; i++) {
  499. u32 reg = INI_RA(&ah->iniModes_9271_ANI_reg, i, 0);
  500. u32 val = INI_RA(&ah->iniModes_9271_ANI_reg, i, modesIndex);
  501. u32 val_orig;
  502. if (reg == AR_PHY_CCK_DETECT) {
  503. val_orig = REG_READ(ah, reg);
  504. val &= AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
  505. val_orig &= ~AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
  506. REG_WRITE(ah, reg, val|val_orig);
  507. } else
  508. REG_WRITE(ah, reg, val);
  509. }
  510. REGWRITE_BUFFER_FLUSH(ah);
  511. }