ar9003_hw.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. /* General hardware code for the AR9003 hadware family */
  21. /*
  22. * The AR9003 family uses a new INI format (pre, core, post
  23. * arrays per subsystem). This provides support for the
  24. * AR9003 2.2 chipsets.
  25. */
  26. static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
  27. {
  28. if (AR_SREV_9485(ah)) {
  29. /* mac */
  30. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_PRE], NULL, 0, 0);
  31. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
  32. ar9485_1_0_mac_core,
  33. ARRAY_SIZE(ar9485_1_0_mac_core), 2);
  34. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
  35. ar9485_1_0_mac_postamble,
  36. ARRAY_SIZE(ar9485_1_0_mac_postamble), 5);
  37. /* bb */
  38. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_PRE], ar9485_1_0,
  39. ARRAY_SIZE(ar9485_1_0), 2);
  40. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
  41. ar9485_1_0_baseband_core,
  42. ARRAY_SIZE(ar9485_1_0_baseband_core), 2);
  43. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
  44. ar9485_1_0_baseband_postamble,
  45. ARRAY_SIZE(ar9485_1_0_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. ar9485_1_0_radio_core,
  50. ARRAY_SIZE(ar9485_1_0_radio_core), 2);
  51. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
  52. ar9485_1_0_radio_postamble,
  53. ARRAY_SIZE(ar9485_1_0_radio_postamble), 2);
  54. /* soc */
  55. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
  56. ar9485_1_0_soc_preamble,
  57. ARRAY_SIZE(ar9485_1_0_soc_preamble), 2);
  58. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_CORE], NULL, 0, 0);
  59. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST], NULL, 0, 0);
  60. /* rx/tx gain */
  61. INIT_INI_ARRAY(&ah->iniModesRxGain,
  62. ar9485Common_rx_gain_1_0,
  63. ARRAY_SIZE(ar9485Common_rx_gain_1_0), 2);
  64. INIT_INI_ARRAY(&ah->iniModesTxGain,
  65. ar9485Modes_lowest_ob_db_tx_gain_1_0,
  66. ARRAY_SIZE(ar9485Modes_lowest_ob_db_tx_gain_1_0),
  67. 5);
  68. /* Load PCIE SERDES settings from INI */
  69. /* Awake Setting */
  70. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  71. ar9485_1_0_pcie_phy_pll_on_clkreq_disable_L1,
  72. ARRAY_SIZE(ar9485_1_0_pcie_phy_pll_on_clkreq_disable_L1),
  73. 2);
  74. /* Sleep Setting */
  75. INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
  76. ar9485_1_0_pcie_phy_pll_on_clkreq_enable_L1,
  77. ARRAY_SIZE(ar9485_1_0_pcie_phy_pll_on_clkreq_enable_L1),
  78. 2);
  79. } else {
  80. /* mac */
  81. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_PRE], NULL, 0, 0);
  82. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
  83. ar9300_2p2_mac_core,
  84. ARRAY_SIZE(ar9300_2p2_mac_core), 2);
  85. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
  86. ar9300_2p2_mac_postamble,
  87. ARRAY_SIZE(ar9300_2p2_mac_postamble), 5);
  88. /* bb */
  89. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_PRE], NULL, 0, 0);
  90. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
  91. ar9300_2p2_baseband_core,
  92. ARRAY_SIZE(ar9300_2p2_baseband_core), 2);
  93. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
  94. ar9300_2p2_baseband_postamble,
  95. ARRAY_SIZE(ar9300_2p2_baseband_postamble), 5);
  96. /* radio */
  97. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_PRE], NULL, 0, 0);
  98. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
  99. ar9300_2p2_radio_core,
  100. ARRAY_SIZE(ar9300_2p2_radio_core), 2);
  101. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
  102. ar9300_2p2_radio_postamble,
  103. ARRAY_SIZE(ar9300_2p2_radio_postamble), 5);
  104. /* soc */
  105. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
  106. ar9300_2p2_soc_preamble,
  107. ARRAY_SIZE(ar9300_2p2_soc_preamble), 2);
  108. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_CORE], NULL, 0, 0);
  109. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
  110. ar9300_2p2_soc_postamble,
  111. ARRAY_SIZE(ar9300_2p2_soc_postamble), 5);
  112. /* rx/tx gain */
  113. INIT_INI_ARRAY(&ah->iniModesRxGain,
  114. ar9300Common_rx_gain_table_2p2,
  115. ARRAY_SIZE(ar9300Common_rx_gain_table_2p2), 2);
  116. INIT_INI_ARRAY(&ah->iniModesTxGain,
  117. ar9300Modes_lowest_ob_db_tx_gain_table_2p2,
  118. ARRAY_SIZE(ar9300Modes_lowest_ob_db_tx_gain_table_2p2),
  119. 5);
  120. /* Load PCIE SERDES settings from INI */
  121. /* Awake Setting */
  122. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  123. ar9300PciePhy_pll_on_clkreq_disable_L1_2p2,
  124. ARRAY_SIZE(ar9300PciePhy_pll_on_clkreq_disable_L1_2p2),
  125. 2);
  126. /* Sleep Setting */
  127. INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
  128. ar9300PciePhy_pll_on_clkreq_disable_L1_2p2,
  129. ARRAY_SIZE(ar9300PciePhy_pll_on_clkreq_disable_L1_2p2),
  130. 2);
  131. /* Fast clock modal settings */
  132. INIT_INI_ARRAY(&ah->iniModesAdditional,
  133. ar9300Modes_fast_clock_2p2,
  134. ARRAY_SIZE(ar9300Modes_fast_clock_2p2),
  135. 3);
  136. }
  137. }
  138. static void ar9003_tx_gain_table_apply(struct ath_hw *ah)
  139. {
  140. switch (ar9003_hw_get_tx_gain_idx(ah)) {
  141. case 0:
  142. default:
  143. if (AR_SREV_9485(ah))
  144. INIT_INI_ARRAY(&ah->iniModesTxGain,
  145. ar9485Modes_lowest_ob_db_tx_gain_1_0,
  146. ARRAY_SIZE(ar9485Modes_lowest_ob_db_tx_gain_1_0),
  147. 5);
  148. else
  149. INIT_INI_ARRAY(&ah->iniModesTxGain,
  150. ar9300Modes_lowest_ob_db_tx_gain_table_2p2,
  151. ARRAY_SIZE(ar9300Modes_lowest_ob_db_tx_gain_table_2p2),
  152. 5);
  153. break;
  154. case 1:
  155. if (AR_SREV_9485(ah))
  156. INIT_INI_ARRAY(&ah->iniModesTxGain,
  157. ar9485Modes_high_ob_db_tx_gain_1_0,
  158. ARRAY_SIZE(ar9485Modes_lowest_ob_db_tx_gain_1_0),
  159. 5);
  160. else
  161. INIT_INI_ARRAY(&ah->iniModesTxGain,
  162. ar9300Modes_high_ob_db_tx_gain_table_2p2,
  163. ARRAY_SIZE(ar9300Modes_high_ob_db_tx_gain_table_2p2),
  164. 5);
  165. break;
  166. case 2:
  167. if (AR_SREV_9485(ah))
  168. INIT_INI_ARRAY(&ah->iniModesTxGain,
  169. ar9485Modes_low_ob_db_tx_gain_1_0,
  170. ARRAY_SIZE(ar9485Modes_lowest_ob_db_tx_gain_1_0),
  171. 5);
  172. else
  173. INIT_INI_ARRAY(&ah->iniModesTxGain,
  174. ar9300Modes_low_ob_db_tx_gain_table_2p2,
  175. ARRAY_SIZE(ar9300Modes_low_ob_db_tx_gain_table_2p2),
  176. 5);
  177. break;
  178. case 3:
  179. if (AR_SREV_9485(ah))
  180. INIT_INI_ARRAY(&ah->iniModesTxGain,
  181. ar9485Modes_high_power_tx_gain_1_0,
  182. ARRAY_SIZE(ar9485Modes_high_power_tx_gain_1_0),
  183. 5);
  184. else
  185. INIT_INI_ARRAY(&ah->iniModesTxGain,
  186. ar9300Modes_high_power_tx_gain_table_2p2,
  187. ARRAY_SIZE(ar9300Modes_high_power_tx_gain_table_2p2),
  188. 5);
  189. break;
  190. }
  191. }
  192. static void ar9003_rx_gain_table_apply(struct ath_hw *ah)
  193. {
  194. switch (ar9003_hw_get_rx_gain_idx(ah)) {
  195. case 0:
  196. default:
  197. if (AR_SREV_9485(ah))
  198. INIT_INI_ARRAY(&ah->iniModesRxGain,
  199. ar9485Common_rx_gain_1_0,
  200. ARRAY_SIZE(ar9485Common_rx_gain_1_0),
  201. 2);
  202. else
  203. INIT_INI_ARRAY(&ah->iniModesRxGain,
  204. ar9300Common_rx_gain_table_2p2,
  205. ARRAY_SIZE(ar9300Common_rx_gain_table_2p2),
  206. 2);
  207. break;
  208. case 1:
  209. if (AR_SREV_9485(ah))
  210. INIT_INI_ARRAY(&ah->iniModesRxGain,
  211. ar9485Common_wo_xlna_rx_gain_1_0,
  212. ARRAY_SIZE(ar9485Common_wo_xlna_rx_gain_1_0),
  213. 2);
  214. else
  215. INIT_INI_ARRAY(&ah->iniModesRxGain,
  216. ar9300Common_wo_xlna_rx_gain_table_2p2,
  217. ARRAY_SIZE(ar9300Common_wo_xlna_rx_gain_table_2p2),
  218. 2);
  219. break;
  220. }
  221. }
  222. /* set gain table pointers according to values read from the eeprom */
  223. static void ar9003_hw_init_mode_gain_regs(struct ath_hw *ah)
  224. {
  225. ar9003_tx_gain_table_apply(ah);
  226. ar9003_rx_gain_table_apply(ah);
  227. }
  228. /*
  229. * Helper for ASPM support.
  230. *
  231. * Disable PLL when in L0s as well as receiver clock when in L1.
  232. * This power saving option must be enabled through the SerDes.
  233. *
  234. * Programming the SerDes must go through the same 288 bit serial shift
  235. * register as the other analog registers. Hence the 9 writes.
  236. */
  237. static void ar9003_hw_configpcipowersave(struct ath_hw *ah,
  238. int restore,
  239. int power_off)
  240. {
  241. if (ah->is_pciexpress != true)
  242. return;
  243. /* Do not touch SerDes registers */
  244. if (ah->config.pcie_powersave_enable == 2)
  245. return;
  246. /* Nothing to do on restore for 11N */
  247. if (!restore) {
  248. /* set bit 19 to allow forcing of pcie core into L1 state */
  249. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  250. /* Several PCIe massages to ensure proper behaviour */
  251. if (ah->config.pcie_waen)
  252. REG_WRITE(ah, AR_WA, ah->config.pcie_waen);
  253. else
  254. REG_WRITE(ah, AR_WA, ah->WARegVal);
  255. }
  256. /*
  257. * Configire PCIE after Ini init. SERDES values now come from ini file
  258. * This enables PCIe low power mode.
  259. */
  260. if (ah->config.pcieSerDesWrite) {
  261. unsigned int i;
  262. struct ar5416IniArray *array;
  263. array = power_off ? &ah->iniPcieSerdes :
  264. &ah->iniPcieSerdesLowPower;
  265. for (i = 0; i < array->ia_rows; i++) {
  266. REG_WRITE(ah,
  267. INI_RA(array, i, 0),
  268. INI_RA(array, i, 1));
  269. }
  270. }
  271. }
  272. /* Sets up the AR9003 hardware familiy callbacks */
  273. void ar9003_hw_attach_ops(struct ath_hw *ah)
  274. {
  275. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  276. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  277. priv_ops->init_mode_regs = ar9003_hw_init_mode_regs;
  278. priv_ops->init_mode_gain_regs = ar9003_hw_init_mode_gain_regs;
  279. ops->config_pci_powersave = ar9003_hw_configpcipowersave;
  280. ar9003_hw_attach_phy_ops(ah);
  281. ar9003_hw_attach_calib_ops(ah);
  282. ar9003_hw_attach_mac_ops(ah);
  283. }