ar9003_hw.c 6.2 KB

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