ar9003_hw.c 9.7 KB

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