ar9003_hw.c 10 KB

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