ar9002_hw.c 19 KB

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