ar9003_hw.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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_initvals.h"
  18. /* General hardware code for the AR9003 hadware family */
  19. static bool ar9003_hw_macversion_supported(u32 macversion)
  20. {
  21. switch (macversion) {
  22. case AR_SREV_VERSION_9300:
  23. return true;
  24. default:
  25. break;
  26. }
  27. return false;
  28. }
  29. /* AR9003 2.0 - new INI format (pre, core, post arrays per subsystem) */
  30. /*
  31. * XXX: move TX/RX gain INI to its own init_mode_gain_regs after
  32. * ensuring it does not affect hardware bring up
  33. */
  34. static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
  35. {
  36. /* mac */
  37. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_PRE], NULL, 0, 0);
  38. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
  39. ar9300_2p0_mac_core,
  40. ARRAY_SIZE(ar9300_2p0_mac_core), 2);
  41. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
  42. ar9300_2p0_mac_postamble,
  43. ARRAY_SIZE(ar9300_2p0_mac_postamble), 5);
  44. /* bb */
  45. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_PRE], NULL, 0, 0);
  46. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
  47. ar9300_2p0_baseband_core,
  48. ARRAY_SIZE(ar9300_2p0_baseband_core), 2);
  49. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
  50. ar9300_2p0_baseband_postamble,
  51. ARRAY_SIZE(ar9300_2p0_baseband_postamble), 5);
  52. /* radio */
  53. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_PRE], NULL, 0, 0);
  54. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
  55. ar9300_2p0_radio_core,
  56. ARRAY_SIZE(ar9300_2p0_radio_core), 2);
  57. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
  58. ar9300_2p0_radio_postamble,
  59. ARRAY_SIZE(ar9300_2p0_radio_postamble), 5);
  60. /* soc */
  61. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
  62. ar9300_2p0_soc_preamble,
  63. ARRAY_SIZE(ar9300_2p0_soc_preamble), 2);
  64. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_CORE], NULL, 0, 0);
  65. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
  66. ar9300_2p0_soc_postamble,
  67. ARRAY_SIZE(ar9300_2p0_soc_postamble), 5);
  68. /* rx/tx gain */
  69. INIT_INI_ARRAY(&ah->iniModesRxGain,
  70. ar9300Common_rx_gain_table_2p0,
  71. ARRAY_SIZE(ar9300Common_rx_gain_table_2p0), 2);
  72. INIT_INI_ARRAY(&ah->iniModesTxGain,
  73. ar9300Modes_lowest_ob_db_tx_gain_table_2p0,
  74. ARRAY_SIZE(ar9300Modes_lowest_ob_db_tx_gain_table_2p0),
  75. 5);
  76. /* Load PCIE SERDES settings from INI */
  77. /* Awake Setting */
  78. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  79. ar9300PciePhy_pll_on_clkreq_disable_L1_2p0,
  80. ARRAY_SIZE(ar9300PciePhy_pll_on_clkreq_disable_L1_2p0),
  81. 2);
  82. /* Sleep Setting */
  83. INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
  84. ar9300PciePhy_clkreq_enable_L1_2p0,
  85. ARRAY_SIZE(ar9300PciePhy_clkreq_enable_L1_2p0),
  86. 2);
  87. /* Fast clock modal settings */
  88. INIT_INI_ARRAY(&ah->iniModesAdditional,
  89. ar9300Modes_fast_clock_2p0,
  90. ARRAY_SIZE(ar9300Modes_fast_clock_2p0),
  91. 3);
  92. }
  93. static void ar9003_tx_gain_table_apply(struct ath_hw *ah)
  94. {
  95. switch (ar9003_hw_get_tx_gain_idx(ah)) {
  96. case 0:
  97. default:
  98. INIT_INI_ARRAY(&ah->iniModesTxGain,
  99. ar9300Modes_lowest_ob_db_tx_gain_table_2p0,
  100. ARRAY_SIZE(ar9300Modes_lowest_ob_db_tx_gain_table_2p0),
  101. 5);
  102. break;
  103. case 1:
  104. INIT_INI_ARRAY(&ah->iniModesTxGain,
  105. ar9300Modes_high_ob_db_tx_gain_table_2p0,
  106. ARRAY_SIZE(ar9300Modes_high_ob_db_tx_gain_table_2p0),
  107. 5);
  108. break;
  109. case 2:
  110. INIT_INI_ARRAY(&ah->iniModesTxGain,
  111. ar9300Modes_low_ob_db_tx_gain_table_2p0,
  112. ARRAY_SIZE(ar9300Modes_low_ob_db_tx_gain_table_2p0),
  113. 5);
  114. break;
  115. }
  116. }
  117. static void ar9003_rx_gain_table_apply(struct ath_hw *ah)
  118. {
  119. switch (ar9003_hw_get_rx_gain_idx(ah)) {
  120. case 0:
  121. default:
  122. INIT_INI_ARRAY(&ah->iniModesRxGain, ar9300Common_rx_gain_table_2p0,
  123. ARRAY_SIZE(ar9300Common_rx_gain_table_2p0),
  124. 2);
  125. break;
  126. case 1:
  127. INIT_INI_ARRAY(&ah->iniModesRxGain,
  128. ar9300Common_wo_xlna_rx_gain_table_2p0,
  129. ARRAY_SIZE(ar9300Common_wo_xlna_rx_gain_table_2p0),
  130. 2);
  131. break;
  132. }
  133. }
  134. /* set gain table pointers according to values read from the eeprom */
  135. static void ar9003_hw_init_mode_gain_regs(struct ath_hw *ah)
  136. {
  137. ar9003_tx_gain_table_apply(ah);
  138. ar9003_rx_gain_table_apply(ah);
  139. }
  140. /*
  141. * Helper for ASPM support.
  142. *
  143. * Disable PLL when in L0s as well as receiver clock when in L1.
  144. * This power saving option must be enabled through the SerDes.
  145. *
  146. * Programming the SerDes must go through the same 288 bit serial shift
  147. * register as the other analog registers. Hence the 9 writes.
  148. */
  149. static void ar9003_hw_configpcipowersave(struct ath_hw *ah,
  150. int restore,
  151. int power_off)
  152. {
  153. if (ah->is_pciexpress != true)
  154. return;
  155. /* Do not touch SerDes registers */
  156. if (ah->config.pcie_powersave_enable == 2)
  157. return;
  158. /* Nothing to do on restore for 11N */
  159. if (!restore) {
  160. /* set bit 19 to allow forcing of pcie core into L1 state */
  161. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  162. /* Several PCIe massages to ensure proper behaviour */
  163. if (ah->config.pcie_waen)
  164. REG_WRITE(ah, AR_WA, ah->config.pcie_waen);
  165. }
  166. }
  167. /* Sets up the AR9003 hardware familiy callbacks */
  168. void ar9003_hw_attach_ops(struct ath_hw *ah)
  169. {
  170. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  171. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  172. priv_ops->init_mode_regs = ar9003_hw_init_mode_regs;
  173. priv_ops->init_mode_gain_regs = ar9003_hw_init_mode_gain_regs;
  174. priv_ops->macversion_supported = ar9003_hw_macversion_supported;
  175. ops->config_pci_powersave = ar9003_hw_configpcipowersave;
  176. ar9003_hw_attach_phy_ops(ah);
  177. ar9003_hw_attach_calib_ops(ah);
  178. ar9003_hw_attach_mac_ops(ah);
  179. }