ar9003_hw.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. /* 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. case AR_SREV_VERSION_9485:
  25. return true;
  26. default:
  27. break;
  28. }
  29. return false;
  30. }
  31. /*
  32. * The AR9003 family uses a new INI format (pre, core, post
  33. * arrays per subsystem). This provides support for the
  34. * AR9003 2.2 chipsets.
  35. */
  36. static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
  37. {
  38. /* mac */
  39. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_PRE], NULL, 0, 0);
  40. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
  41. ar9300_2p2_mac_core,
  42. ARRAY_SIZE(ar9300_2p2_mac_core), 2);
  43. INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
  44. ar9300_2p2_mac_postamble,
  45. ARRAY_SIZE(ar9300_2p2_mac_postamble), 5);
  46. /* bb */
  47. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_PRE], NULL, 0, 0);
  48. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
  49. ar9300_2p2_baseband_core,
  50. ARRAY_SIZE(ar9300_2p2_baseband_core), 2);
  51. INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
  52. ar9300_2p2_baseband_postamble,
  53. ARRAY_SIZE(ar9300_2p2_baseband_postamble), 5);
  54. /* radio */
  55. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_PRE], NULL, 0, 0);
  56. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
  57. ar9300_2p2_radio_core,
  58. ARRAY_SIZE(ar9300_2p2_radio_core), 2);
  59. INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
  60. ar9300_2p2_radio_postamble,
  61. ARRAY_SIZE(ar9300_2p2_radio_postamble), 5);
  62. /* soc */
  63. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
  64. ar9300_2p2_soc_preamble,
  65. ARRAY_SIZE(ar9300_2p2_soc_preamble), 2);
  66. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_CORE], NULL, 0, 0);
  67. INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
  68. ar9300_2p2_soc_postamble,
  69. ARRAY_SIZE(ar9300_2p2_soc_postamble), 5);
  70. /* rx/tx gain */
  71. INIT_INI_ARRAY(&ah->iniModesRxGain,
  72. ar9300Common_rx_gain_table_2p2,
  73. ARRAY_SIZE(ar9300Common_rx_gain_table_2p2), 2);
  74. INIT_INI_ARRAY(&ah->iniModesTxGain,
  75. ar9300Modes_lowest_ob_db_tx_gain_table_2p2,
  76. ARRAY_SIZE(ar9300Modes_lowest_ob_db_tx_gain_table_2p2),
  77. 5);
  78. /* Load PCIE SERDES settings from INI */
  79. /* Awake Setting */
  80. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  81. ar9300PciePhy_pll_on_clkreq_disable_L1_2p2,
  82. ARRAY_SIZE(ar9300PciePhy_pll_on_clkreq_disable_L1_2p2),
  83. 2);
  84. /* Sleep Setting */
  85. INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
  86. ar9300PciePhy_clkreq_enable_L1_2p2,
  87. ARRAY_SIZE(ar9300PciePhy_clkreq_enable_L1_2p2),
  88. 2);
  89. /* Fast clock modal settings */
  90. INIT_INI_ARRAY(&ah->iniModesAdditional,
  91. ar9300Modes_fast_clock_2p2,
  92. ARRAY_SIZE(ar9300Modes_fast_clock_2p2),
  93. 3);
  94. }
  95. static void ar9003_tx_gain_table_apply(struct ath_hw *ah)
  96. {
  97. switch (ar9003_hw_get_tx_gain_idx(ah)) {
  98. case 0:
  99. default:
  100. INIT_INI_ARRAY(&ah->iniModesTxGain,
  101. ar9300Modes_lowest_ob_db_tx_gain_table_2p2,
  102. ARRAY_SIZE(ar9300Modes_lowest_ob_db_tx_gain_table_2p2),
  103. 5);
  104. break;
  105. case 1:
  106. INIT_INI_ARRAY(&ah->iniModesTxGain,
  107. ar9300Modes_high_ob_db_tx_gain_table_2p2,
  108. ARRAY_SIZE(ar9300Modes_high_ob_db_tx_gain_table_2p2),
  109. 5);
  110. break;
  111. case 2:
  112. INIT_INI_ARRAY(&ah->iniModesTxGain,
  113. ar9300Modes_low_ob_db_tx_gain_table_2p2,
  114. ARRAY_SIZE(ar9300Modes_low_ob_db_tx_gain_table_2p2),
  115. 5);
  116. break;
  117. }
  118. }
  119. static void ar9003_rx_gain_table_apply(struct ath_hw *ah)
  120. {
  121. switch (ar9003_hw_get_rx_gain_idx(ah)) {
  122. case 0:
  123. default:
  124. INIT_INI_ARRAY(&ah->iniModesRxGain,
  125. ar9300Common_rx_gain_table_2p2,
  126. ARRAY_SIZE(ar9300Common_rx_gain_table_2p2),
  127. 2);
  128. break;
  129. case 1:
  130. INIT_INI_ARRAY(&ah->iniModesRxGain,
  131. ar9300Common_wo_xlna_rx_gain_table_2p2,
  132. ARRAY_SIZE(ar9300Common_wo_xlna_rx_gain_table_2p2),
  133. 2);
  134. break;
  135. }
  136. }
  137. /* set gain table pointers according to values read from the eeprom */
  138. static void ar9003_hw_init_mode_gain_regs(struct ath_hw *ah)
  139. {
  140. ar9003_tx_gain_table_apply(ah);
  141. ar9003_rx_gain_table_apply(ah);
  142. }
  143. /*
  144. * Helper for ASPM support.
  145. *
  146. * Disable PLL when in L0s as well as receiver clock when in L1.
  147. * This power saving option must be enabled through the SerDes.
  148. *
  149. * Programming the SerDes must go through the same 288 bit serial shift
  150. * register as the other analog registers. Hence the 9 writes.
  151. */
  152. static void ar9003_hw_configpcipowersave(struct ath_hw *ah,
  153. int restore,
  154. int power_off)
  155. {
  156. if (ah->is_pciexpress != true)
  157. return;
  158. /* Do not touch SerDes registers */
  159. if (ah->config.pcie_powersave_enable == 2)
  160. return;
  161. /* Nothing to do on restore for 11N */
  162. if (!restore) {
  163. /* set bit 19 to allow forcing of pcie core into L1 state */
  164. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  165. /* Several PCIe massages to ensure proper behaviour */
  166. if (ah->config.pcie_waen)
  167. REG_WRITE(ah, AR_WA, ah->config.pcie_waen);
  168. else
  169. REG_WRITE(ah, AR_WA, ah->WARegVal);
  170. }
  171. /*
  172. * Configire PCIE after Ini init. SERDES values now come from ini file
  173. * This enables PCIe low power mode.
  174. */
  175. if (ah->config.pcieSerDesWrite) {
  176. unsigned int i;
  177. struct ar5416IniArray *array;
  178. array = power_off ? &ah->iniPcieSerdes :
  179. &ah->iniPcieSerdesLowPower;
  180. for (i = 0; i < array->ia_rows; i++) {
  181. REG_WRITE(ah,
  182. INI_RA(array, i, 0),
  183. INI_RA(array, i, 1));
  184. }
  185. }
  186. }
  187. /* Sets up the AR9003 hardware familiy callbacks */
  188. void ar9003_hw_attach_ops(struct ath_hw *ah)
  189. {
  190. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  191. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  192. priv_ops->init_mode_regs = ar9003_hw_init_mode_regs;
  193. priv_ops->init_mode_gain_regs = ar9003_hw_init_mode_gain_regs;
  194. priv_ops->macversion_supported = ar9003_hw_macversion_supported;
  195. ops->config_pci_powersave = ar9003_hw_configpcipowersave;
  196. ar9003_hw_attach_phy_ops(ah);
  197. ar9003_hw_attach_calib_ops(ah);
  198. ar9003_hw_attach_mac_ops(ah);
  199. }