ar9003_hw.c 11 KB

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