ar9003_hw.c 6.6 KB

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