ar9002_hw.c 20 KB

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