ar9002_hw.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. /*
  235. * Helper for ASPM support.
  236. *
  237. * Disable PLL when in L0s as well as receiver clock when in L1.
  238. * This power saving option must be enabled through the SerDes.
  239. *
  240. * Programming the SerDes must go through the same 288 bit serial shift
  241. * register as the other analog registers. Hence the 9 writes.
  242. */
  243. static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
  244. int restore,
  245. int power_off)
  246. {
  247. u8 i;
  248. u32 val;
  249. if (ah->is_pciexpress != true)
  250. return;
  251. /* Do not touch SerDes registers */
  252. if (ah->config.pcie_powersave_enable == 2)
  253. return;
  254. /* Nothing to do on restore for 11N */
  255. if (!restore) {
  256. if (AR_SREV_9280_20_OR_LATER(ah)) {
  257. /*
  258. * AR9280 2.0 or later chips use SerDes values from the
  259. * initvals.h initialized depending on chipset during
  260. * __ath9k_hw_init()
  261. */
  262. for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
  263. REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
  264. INI_RA(&ah->iniPcieSerdes, i, 1));
  265. }
  266. } else if (AR_SREV_9280(ah) &&
  267. (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
  268. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
  269. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  270. /* RX shut off when elecidle is asserted */
  271. REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
  272. REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
  273. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
  274. /* Shut off CLKREQ active in L1 */
  275. if (ah->config.pcie_clock_req)
  276. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
  277. else
  278. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
  279. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  280. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  281. REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
  282. /* Load the new settings */
  283. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  284. } else {
  285. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  286. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  287. /* RX shut off when elecidle is asserted */
  288. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
  289. REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
  290. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
  291. /*
  292. * Ignore ah->ah_config.pcie_clock_req setting for
  293. * pre-AR9280 11n
  294. */
  295. REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
  296. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  297. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  298. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
  299. /* Load the new settings */
  300. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  301. }
  302. udelay(1000);
  303. /* set bit 19 to allow forcing of pcie core into L1 state */
  304. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  305. /* Several PCIe massages to ensure proper behaviour */
  306. if (ah->config.pcie_waen) {
  307. val = ah->config.pcie_waen;
  308. if (!power_off)
  309. val &= (~AR_WA_D3_L1_DISABLE);
  310. } else {
  311. if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
  312. AR_SREV_9287(ah)) {
  313. val = AR9285_WA_DEFAULT;
  314. if (!power_off)
  315. val &= (~AR_WA_D3_L1_DISABLE);
  316. } else if (AR_SREV_9280(ah)) {
  317. /*
  318. * On AR9280 chips bit 22 of 0x4004 needs to be
  319. * set otherwise card may disappear.
  320. */
  321. val = AR9280_WA_DEFAULT;
  322. if (!power_off)
  323. val &= (~AR_WA_D3_L1_DISABLE);
  324. } else
  325. val = AR_WA_DEFAULT;
  326. }
  327. REG_WRITE(ah, AR_WA, val);
  328. }
  329. if (power_off) {
  330. /*
  331. * Set PCIe workaround bits
  332. * bit 14 in WA register (disable L1) should only
  333. * be set when device enters D3 and be cleared
  334. * when device comes back to D0.
  335. */
  336. if (ah->config.pcie_waen) {
  337. if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
  338. REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
  339. } else {
  340. if (((AR_SREV_9285(ah) || 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. REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
  346. }
  347. }
  348. }
  349. }
  350. /* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
  351. void ar9002_hw_attach_ops(struct ath_hw *ah)
  352. {
  353. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  354. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  355. priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
  356. priv_ops->macversion_supported = ar9002_hw_macversion_supported;
  357. ops->config_pci_powersave = ar9002_hw_configpcipowersave;
  358. ar5008_hw_attach_phy_ops(ah);
  359. if (AR_SREV_9280_10_OR_LATER(ah))
  360. ar9002_hw_attach_phy_ops(ah);
  361. ar9002_hw_attach_calib_ops(ah);
  362. ar9002_hw_attach_mac_ops(ah);
  363. }