ar9002_hw.c 13 KB

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