ar9003_hw.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 "ar9003_mac.h"
  18. #include "ar9003_2p2_initvals.h"
  19. #include "ar9485_initvals.h"
  20. #include "ar9340_initvals.h"
  21. /* General hardware code for the AR9003 hadware family */
  22. /*
  23. * The AR9003 family uses a new INI format (pre, core, post
  24. * arrays per subsystem). This provides support for the
  25. * AR9003 2.2 chipsets.
  26. */
  27. static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
  28. {
  29. if (AR_SREV_9340(ah)) {
  30. /* mac */
  31. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_PRE], NULL, 0, 0);
  32. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
  33. ar9340_1p0_mac_core,
  34. ARRAY_SIZE(ar9340_1p0_mac_core), 2);
  35. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
  36. ar9340_1p0_mac_postamble,
  37. ARRAY_SIZE(ar9340_1p0_mac_postamble), 5);
  38. /* bb */
  39. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_PRE], NULL, 0, 0);
  40. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
  41. ar9340_1p0_baseband_core,
  42. ARRAY_SIZE(ar9340_1p0_baseband_core), 2);
  43. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
  44. ar9340_1p0_baseband_postamble,
  45. ARRAY_SIZE(ar9340_1p0_baseband_postamble), 5);
  46. /* radio */
  47. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_PRE], NULL, 0, 0);
  48. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
  49. ar9340_1p0_radio_core,
  50. ARRAY_SIZE(ar9340_1p0_radio_core), 2);
  51. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
  52. ar9340_1p0_radio_postamble,
  53. ARRAY_SIZE(ar9340_1p0_radio_postamble), 5);
  54. /* soc */
  55. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
  56. ar9340_1p0_soc_preamble,
  57. ARRAY_SIZE(ar9340_1p0_soc_preamble), 2);
  58. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_CORE], NULL, 0, 0);
  59. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
  60. ar9340_1p0_soc_postamble,
  61. ARRAY_SIZE(ar9340_1p0_soc_postamble), 5);
  62. /* rx/tx gain */
  63. INIT_INI_ARRAY(&ah->iniModesRxGain,
  64. ar9340Common_wo_xlna_rx_gain_table_1p0,
  65. ARRAY_SIZE(ar9340Common_wo_xlna_rx_gain_table_1p0),
  66. 5);
  67. INIT_INI_ARRAY(&ah->iniModesTxGain,
  68. ar9340Modes_high_ob_db_tx_gain_table_1p0,
  69. ARRAY_SIZE(ar9340Modes_high_ob_db_tx_gain_table_1p0),
  70. 5);
  71. INIT_INI_ARRAY(&ah->iniModesAdditional,
  72. ar9340Modes_fast_clock_1p0,
  73. ARRAY_SIZE(ar9340Modes_fast_clock_1p0),
  74. 3);
  75. INIT_INI_ARRAY(&ah->iniModesAdditional_40M,
  76. ar9340_1p0_radio_core_40M,
  77. ARRAY_SIZE(ar9340_1p0_radio_core_40M),
  78. 2);
  79. } else if (AR_SREV_9485_11(ah)) {
  80. /* mac */
  81. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_PRE], NULL, 0, 0);
  82. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
  83. ar9485_1_1_mac_core,
  84. ARRAY_SIZE(ar9485_1_1_mac_core), 2);
  85. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
  86. ar9485_1_1_mac_postamble,
  87. ARRAY_SIZE(ar9485_1_1_mac_postamble), 5);
  88. /* bb */
  89. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_PRE], ar9485_1_1,
  90. ARRAY_SIZE(ar9485_1_1), 2);
  91. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
  92. ar9485_1_1_baseband_core,
  93. ARRAY_SIZE(ar9485_1_1_baseband_core), 2);
  94. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
  95. ar9485_1_1_baseband_postamble,
  96. ARRAY_SIZE(ar9485_1_1_baseband_postamble), 5);
  97. /* radio */
  98. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_PRE], NULL, 0, 0);
  99. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
  100. ar9485_1_1_radio_core,
  101. ARRAY_SIZE(ar9485_1_1_radio_core), 2);
  102. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
  103. ar9485_1_1_radio_postamble,
  104. ARRAY_SIZE(ar9485_1_1_radio_postamble), 2);
  105. /* soc */
  106. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
  107. ar9485_1_1_soc_preamble,
  108. ARRAY_SIZE(ar9485_1_1_soc_preamble), 2);
  109. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_CORE], NULL, 0, 0);
  110. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST], NULL, 0, 0);
  111. /* rx/tx gain */
  112. INIT_INI_ARRAY(&ah->iniModesRxGain,
  113. ar9485Common_wo_xlna_rx_gain_1_1,
  114. ARRAY_SIZE(ar9485Common_wo_xlna_rx_gain_1_1), 2);
  115. INIT_INI_ARRAY(&ah->iniModesTxGain,
  116. ar9485_modes_lowest_ob_db_tx_gain_1_1,
  117. ARRAY_SIZE(ar9485_modes_lowest_ob_db_tx_gain_1_1),
  118. 5);
  119. /* Load PCIE SERDES settings from INI */
  120. /* Awake Setting */
  121. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  122. ar9485_1_1_pcie_phy_clkreq_disable_L1,
  123. ARRAY_SIZE(ar9485_1_1_pcie_phy_clkreq_disable_L1),
  124. 2);
  125. /* Sleep Setting */
  126. INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
  127. ar9485_1_1_pcie_phy_clkreq_disable_L1,
  128. ARRAY_SIZE(ar9485_1_1_pcie_phy_clkreq_disable_L1),
  129. 2);
  130. } else {
  131. /* mac */
  132. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_PRE], NULL, 0, 0);
  133. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
  134. ar9300_2p2_mac_core,
  135. ARRAY_SIZE(ar9300_2p2_mac_core), 2);
  136. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
  137. ar9300_2p2_mac_postamble,
  138. ARRAY_SIZE(ar9300_2p2_mac_postamble), 5);
  139. /* bb */
  140. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_PRE], NULL, 0, 0);
  141. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
  142. ar9300_2p2_baseband_core,
  143. ARRAY_SIZE(ar9300_2p2_baseband_core), 2);
  144. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
  145. ar9300_2p2_baseband_postamble,
  146. ARRAY_SIZE(ar9300_2p2_baseband_postamble), 5);
  147. /* radio */
  148. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_PRE], NULL, 0, 0);
  149. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
  150. ar9300_2p2_radio_core,
  151. ARRAY_SIZE(ar9300_2p2_radio_core), 2);
  152. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
  153. ar9300_2p2_radio_postamble,
  154. ARRAY_SIZE(ar9300_2p2_radio_postamble), 5);
  155. /* soc */
  156. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
  157. ar9300_2p2_soc_preamble,
  158. ARRAY_SIZE(ar9300_2p2_soc_preamble), 2);
  159. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_CORE], NULL, 0, 0);
  160. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
  161. ar9300_2p2_soc_postamble,
  162. ARRAY_SIZE(ar9300_2p2_soc_postamble), 5);
  163. /* rx/tx gain */
  164. INIT_INI_ARRAY(&ah->iniModesRxGain,
  165. ar9300Common_rx_gain_table_2p2,
  166. ARRAY_SIZE(ar9300Common_rx_gain_table_2p2), 2);
  167. INIT_INI_ARRAY(&ah->iniModesTxGain,
  168. ar9300Modes_lowest_ob_db_tx_gain_table_2p2,
  169. ARRAY_SIZE(ar9300Modes_lowest_ob_db_tx_gain_table_2p2),
  170. 5);
  171. /* Load PCIE SERDES settings from INI */
  172. /* Awake Setting */
  173. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  174. ar9300PciePhy_pll_on_clkreq_disable_L1_2p2,
  175. ARRAY_SIZE(ar9300PciePhy_pll_on_clkreq_disable_L1_2p2),
  176. 2);
  177. /* Sleep Setting */
  178. INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
  179. ar9300PciePhy_pll_on_clkreq_disable_L1_2p2,
  180. ARRAY_SIZE(ar9300PciePhy_pll_on_clkreq_disable_L1_2p2),
  181. 2);
  182. /* Fast clock modal settings */
  183. INIT_INI_ARRAY(&ah->iniModesAdditional,
  184. ar9300Modes_fast_clock_2p2,
  185. ARRAY_SIZE(ar9300Modes_fast_clock_2p2),
  186. 3);
  187. }
  188. }
  189. static void ar9003_tx_gain_table_apply(struct ath_hw *ah)
  190. {
  191. switch (ar9003_hw_get_tx_gain_idx(ah)) {
  192. case 0:
  193. default:
  194. if (AR_SREV_9340(ah))
  195. INIT_INI_ARRAY(&ah->iniModesTxGain,
  196. ar9340Modes_lowest_ob_db_tx_gain_table_1p0,
  197. ARRAY_SIZE(ar9340Modes_lowest_ob_db_tx_gain_table_1p0),
  198. 5);
  199. else if (AR_SREV_9485_11(ah))
  200. INIT_INI_ARRAY(&ah->iniModesTxGain,
  201. ar9485_modes_lowest_ob_db_tx_gain_1_1,
  202. ARRAY_SIZE(ar9485_modes_lowest_ob_db_tx_gain_1_1),
  203. 5);
  204. else
  205. INIT_INI_ARRAY(&ah->iniModesTxGain,
  206. ar9300Modes_lowest_ob_db_tx_gain_table_2p2,
  207. ARRAY_SIZE(ar9300Modes_lowest_ob_db_tx_gain_table_2p2),
  208. 5);
  209. break;
  210. case 1:
  211. if (AR_SREV_9340(ah))
  212. INIT_INI_ARRAY(&ah->iniModesTxGain,
  213. ar9340Modes_lowest_ob_db_tx_gain_table_1p0,
  214. ARRAY_SIZE(ar9340Modes_lowest_ob_db_tx_gain_table_1p0),
  215. 5);
  216. else if (AR_SREV_9485_11(ah))
  217. INIT_INI_ARRAY(&ah->iniModesTxGain,
  218. ar9485Modes_high_ob_db_tx_gain_1_1,
  219. ARRAY_SIZE(ar9485Modes_high_ob_db_tx_gain_1_1),
  220. 5);
  221. else
  222. INIT_INI_ARRAY(&ah->iniModesTxGain,
  223. ar9300Modes_high_ob_db_tx_gain_table_2p2,
  224. ARRAY_SIZE(ar9300Modes_high_ob_db_tx_gain_table_2p2),
  225. 5);
  226. break;
  227. case 2:
  228. if (AR_SREV_9340(ah))
  229. INIT_INI_ARRAY(&ah->iniModesTxGain,
  230. ar9340Modes_lowest_ob_db_tx_gain_table_1p0,
  231. ARRAY_SIZE(ar9340Modes_lowest_ob_db_tx_gain_table_1p0),
  232. 5);
  233. else if (AR_SREV_9485_11(ah))
  234. INIT_INI_ARRAY(&ah->iniModesTxGain,
  235. ar9485Modes_low_ob_db_tx_gain_1_1,
  236. ARRAY_SIZE(ar9485Modes_low_ob_db_tx_gain_1_1),
  237. 5);
  238. else
  239. INIT_INI_ARRAY(&ah->iniModesTxGain,
  240. ar9300Modes_low_ob_db_tx_gain_table_2p2,
  241. ARRAY_SIZE(ar9300Modes_low_ob_db_tx_gain_table_2p2),
  242. 5);
  243. break;
  244. case 3:
  245. if (AR_SREV_9340(ah))
  246. INIT_INI_ARRAY(&ah->iniModesTxGain,
  247. ar9340Modes_lowest_ob_db_tx_gain_table_1p0,
  248. ARRAY_SIZE(ar9340Modes_lowest_ob_db_tx_gain_table_1p0),
  249. 5);
  250. else if (AR_SREV_9485_11(ah))
  251. INIT_INI_ARRAY(&ah->iniModesTxGain,
  252. ar9485Modes_high_power_tx_gain_1_1,
  253. ARRAY_SIZE(ar9485Modes_high_power_tx_gain_1_1),
  254. 5);
  255. else
  256. INIT_INI_ARRAY(&ah->iniModesTxGain,
  257. ar9300Modes_high_power_tx_gain_table_2p2,
  258. ARRAY_SIZE(ar9300Modes_high_power_tx_gain_table_2p2),
  259. 5);
  260. break;
  261. }
  262. }
  263. static void ar9003_rx_gain_table_apply(struct ath_hw *ah)
  264. {
  265. switch (ar9003_hw_get_rx_gain_idx(ah)) {
  266. case 0:
  267. default:
  268. if (AR_SREV_9340(ah))
  269. INIT_INI_ARRAY(&ah->iniModesRxGain,
  270. ar9340Common_rx_gain_table_1p0,
  271. ARRAY_SIZE(ar9340Common_rx_gain_table_1p0),
  272. 2);
  273. else if (AR_SREV_9485_11(ah))
  274. INIT_INI_ARRAY(&ah->iniModesRxGain,
  275. ar9485Common_wo_xlna_rx_gain_1_1,
  276. ARRAY_SIZE(ar9485Common_wo_xlna_rx_gain_1_1),
  277. 2);
  278. else
  279. INIT_INI_ARRAY(&ah->iniModesRxGain,
  280. ar9300Common_rx_gain_table_2p2,
  281. ARRAY_SIZE(ar9300Common_rx_gain_table_2p2),
  282. 2);
  283. break;
  284. case 1:
  285. if (AR_SREV_9340(ah))
  286. INIT_INI_ARRAY(&ah->iniModesRxGain,
  287. ar9340Common_wo_xlna_rx_gain_table_1p0,
  288. ARRAY_SIZE(ar9340Common_wo_xlna_rx_gain_table_1p0),
  289. 2);
  290. else if (AR_SREV_9485_11(ah))
  291. INIT_INI_ARRAY(&ah->iniModesRxGain,
  292. ar9485Common_wo_xlna_rx_gain_1_1,
  293. ARRAY_SIZE(ar9485Common_wo_xlna_rx_gain_1_1),
  294. 2);
  295. else
  296. INIT_INI_ARRAY(&ah->iniModesRxGain,
  297. ar9300Common_wo_xlna_rx_gain_table_2p2,
  298. ARRAY_SIZE(ar9300Common_wo_xlna_rx_gain_table_2p2),
  299. 2);
  300. break;
  301. }
  302. }
  303. /* set gain table pointers according to values read from the eeprom */
  304. static void ar9003_hw_init_mode_gain_regs(struct ath_hw *ah)
  305. {
  306. ar9003_tx_gain_table_apply(ah);
  307. ar9003_rx_gain_table_apply(ah);
  308. }
  309. /*
  310. * Helper for ASPM support.
  311. *
  312. * Disable PLL when in L0s as well as receiver clock when in L1.
  313. * This power saving option must be enabled through the SerDes.
  314. *
  315. * Programming the SerDes must go through the same 288 bit serial shift
  316. * register as the other analog registers. Hence the 9 writes.
  317. */
  318. static void ar9003_hw_configpcipowersave(struct ath_hw *ah,
  319. int restore,
  320. int power_off)
  321. {
  322. if (ah->is_pciexpress != true)
  323. return;
  324. /* Do not touch SerDes registers */
  325. if (ah->config.pcie_powersave_enable == 2)
  326. return;
  327. /* Nothing to do on restore for 11N */
  328. if (!restore) {
  329. /* set bit 19 to allow forcing of pcie core into L1 state */
  330. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  331. /* Several PCIe massages to ensure proper behaviour */
  332. if (ah->config.pcie_waen)
  333. REG_WRITE(ah, AR_WA, ah->config.pcie_waen);
  334. else
  335. REG_WRITE(ah, AR_WA, ah->WARegVal);
  336. }
  337. /*
  338. * Configire PCIE after Ini init. SERDES values now come from ini file
  339. * This enables PCIe low power mode.
  340. */
  341. if (ah->config.pcieSerDesWrite) {
  342. unsigned int i;
  343. struct ar5416IniArray *array;
  344. array = power_off ? &ah->iniPcieSerdes :
  345. &ah->iniPcieSerdesLowPower;
  346. for (i = 0; i < array->ia_rows; i++) {
  347. REG_WRITE(ah,
  348. INI_RA(array, i, 0),
  349. INI_RA(array, i, 1));
  350. }
  351. }
  352. }
  353. /* Sets up the AR9003 hardware familiy callbacks */
  354. void ar9003_hw_attach_ops(struct ath_hw *ah)
  355. {
  356. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  357. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  358. priv_ops->init_mode_regs = ar9003_hw_init_mode_regs;
  359. priv_ops->init_mode_gain_regs = ar9003_hw_init_mode_gain_regs;
  360. ops->config_pci_powersave = ar9003_hw_configpcipowersave;
  361. ar9003_hw_attach_phy_ops(ah);
  362. ar9003_hw_attach_calib_ops(ah);
  363. ar9003_hw_attach_mac_ops(ah);
  364. }