ar9002_hw.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*
  2. * Copyright (c) 2008-2011 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 <linux/moduleparam.h>
  17. #include "hw.h"
  18. #include "ar5008_initvals.h"
  19. #include "ar9001_initvals.h"
  20. #include "ar9002_initvals.h"
  21. #include "ar9002_phy.h"
  22. /* General hardware code for the A5008/AR9001/AR9002 hadware families */
  23. static int ar9002_hw_init_mode_regs(struct ath_hw *ah)
  24. {
  25. if (AR_SREV_9271(ah)) {
  26. INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271);
  27. INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271);
  28. INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg);
  29. return 0;
  30. }
  31. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  32. ar9280PciePhy_clkreq_always_on_L1_9280);
  33. if (AR_SREV_9287_11_OR_LATER(ah)) {
  34. INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1);
  35. INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1);
  36. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  37. INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2);
  38. INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2);
  39. } else if (AR_SREV_9280_20_OR_LATER(ah)) {
  40. INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2);
  41. INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2);
  42. INIT_INI_ARRAY(&ah->iniModesFastClock,
  43. ar9280Modes_fast_clock_9280_2);
  44. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  45. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160);
  46. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160);
  47. if (AR_SREV_9160_11(ah)) {
  48. INIT_INI_ARRAY(&ah->iniAddac,
  49. ar5416Addac_9160_1_1);
  50. } else {
  51. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160);
  52. }
  53. } else if (AR_SREV_9100_OR_LATER(ah)) {
  54. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100);
  55. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100);
  56. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100);
  57. } else {
  58. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes);
  59. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common);
  60. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac);
  61. }
  62. if (!AR_SREV_9280_20_OR_LATER(ah)) {
  63. /* Common for AR5416, AR913x, AR9160 */
  64. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain);
  65. /* Common for AR913x, AR9160 */
  66. if (!AR_SREV_5416(ah))
  67. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6TPC_9100);
  68. else
  69. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6TPC);
  70. }
  71. /* iniAddac needs to be modified for these chips */
  72. if (AR_SREV_9160(ah) || !AR_SREV_5416_22_OR_LATER(ah)) {
  73. struct ar5416IniArray *addac = &ah->iniAddac;
  74. u32 size = sizeof(u32) * addac->ia_rows * addac->ia_columns;
  75. u32 *data;
  76. data = devm_kzalloc(ah->dev, size, GFP_KERNEL);
  77. if (!data)
  78. return -ENOMEM;
  79. memcpy(data, addac->ia_array, size);
  80. addac->ia_array = data;
  81. if (!AR_SREV_5416_22_OR_LATER(ah)) {
  82. /* override CLKDRV value */
  83. INI_RA(addac, 31,1) = 0;
  84. }
  85. }
  86. if (AR_SREV_9287_11_OR_LATER(ah)) {
  87. INIT_INI_ARRAY(&ah->iniCckfirNormal,
  88. ar9287Common_normal_cck_fir_coeff_9287_1_1);
  89. INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
  90. ar9287Common_japan_2484_cck_fir_coeff_9287_1_1);
  91. }
  92. return 0;
  93. }
  94. static void ar9280_20_hw_init_rxgain_ini(struct ath_hw *ah)
  95. {
  96. u32 rxgain_type;
  97. if (ah->eep_ops->get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_17) {
  98. rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
  99. if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
  100. INIT_INI_ARRAY(&ah->iniModesRxGain,
  101. ar9280Modes_backoff_13db_rxgain_9280_2);
  102. else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
  103. INIT_INI_ARRAY(&ah->iniModesRxGain,
  104. ar9280Modes_backoff_23db_rxgain_9280_2);
  105. else
  106. INIT_INI_ARRAY(&ah->iniModesRxGain,
  107. ar9280Modes_original_rxgain_9280_2);
  108. } else {
  109. INIT_INI_ARRAY(&ah->iniModesRxGain,
  110. ar9280Modes_original_rxgain_9280_2);
  111. }
  112. }
  113. static void ar9280_20_hw_init_txgain_ini(struct ath_hw *ah, u32 txgain_type)
  114. {
  115. if (ah->eep_ops->get_eeprom_rev(ah) >= AR5416_EEP_MINOR_VER_19) {
  116. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
  117. INIT_INI_ARRAY(&ah->iniModesTxGain,
  118. ar9280Modes_high_power_tx_gain_9280_2);
  119. else
  120. INIT_INI_ARRAY(&ah->iniModesTxGain,
  121. ar9280Modes_original_tx_gain_9280_2);
  122. } else {
  123. INIT_INI_ARRAY(&ah->iniModesTxGain,
  124. ar9280Modes_original_tx_gain_9280_2);
  125. }
  126. }
  127. static void ar9271_hw_init_txgain_ini(struct ath_hw *ah, u32 txgain_type)
  128. {
  129. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
  130. INIT_INI_ARRAY(&ah->iniModesTxGain,
  131. ar9271Modes_high_power_tx_gain_9271);
  132. else
  133. INIT_INI_ARRAY(&ah->iniModesTxGain,
  134. ar9271Modes_normal_power_tx_gain_9271);
  135. }
  136. static void ar9002_hw_init_mode_gain_regs(struct ath_hw *ah)
  137. {
  138. u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  139. if (AR_SREV_9287_11_OR_LATER(ah))
  140. INIT_INI_ARRAY(&ah->iniModesRxGain,
  141. ar9287Modes_rx_gain_9287_1_1);
  142. else if (AR_SREV_9280_20(ah))
  143. ar9280_20_hw_init_rxgain_ini(ah);
  144. if (AR_SREV_9271(ah)) {
  145. ar9271_hw_init_txgain_ini(ah, txgain_type);
  146. } else if (AR_SREV_9287_11_OR_LATER(ah)) {
  147. INIT_INI_ARRAY(&ah->iniModesTxGain,
  148. ar9287Modes_tx_gain_9287_1_1);
  149. } else if (AR_SREV_9280_20(ah)) {
  150. ar9280_20_hw_init_txgain_ini(ah, txgain_type);
  151. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  152. /* txgain table */
  153. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
  154. if (AR_SREV_9285E_20(ah)) {
  155. INIT_INI_ARRAY(&ah->iniModesTxGain,
  156. ar9285Modes_XE2_0_high_power);
  157. } else {
  158. INIT_INI_ARRAY(&ah->iniModesTxGain,
  159. ar9285Modes_high_power_tx_gain_9285_1_2);
  160. }
  161. } else {
  162. if (AR_SREV_9285E_20(ah)) {
  163. INIT_INI_ARRAY(&ah->iniModesTxGain,
  164. ar9285Modes_XE2_0_normal_power);
  165. } else {
  166. INIT_INI_ARRAY(&ah->iniModesTxGain,
  167. ar9285Modes_original_tx_gain_9285_1_2);
  168. }
  169. }
  170. }
  171. }
  172. /*
  173. * Helper for ASPM support.
  174. *
  175. * Disable PLL when in L0s as well as receiver clock when in L1.
  176. * This power saving option must be enabled through the SerDes.
  177. *
  178. * Programming the SerDes must go through the same 288 bit serial shift
  179. * register as the other analog registers. Hence the 9 writes.
  180. */
  181. static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
  182. bool power_off)
  183. {
  184. u8 i;
  185. u32 val;
  186. /* Nothing to do on restore for 11N */
  187. if (!power_off /* !restore */) {
  188. if (AR_SREV_9280_20_OR_LATER(ah)) {
  189. /*
  190. * AR9280 2.0 or later chips use SerDes values from the
  191. * initvals.h initialized depending on chipset during
  192. * __ath9k_hw_init()
  193. */
  194. for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
  195. REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
  196. INI_RA(&ah->iniPcieSerdes, i, 1));
  197. }
  198. } else {
  199. ENABLE_REGWRITE_BUFFER(ah);
  200. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  201. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  202. /* RX shut off when elecidle is asserted */
  203. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
  204. REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
  205. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
  206. /*
  207. * Ignore ah->ah_config.pcie_clock_req setting for
  208. * pre-AR9280 11n
  209. */
  210. REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
  211. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  212. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  213. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
  214. /* Load the new settings */
  215. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  216. REGWRITE_BUFFER_FLUSH(ah);
  217. }
  218. udelay(1000);
  219. }
  220. if (power_off) {
  221. /* clear bit 19 to disable L1 */
  222. REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  223. val = REG_READ(ah, AR_WA);
  224. /*
  225. * Set PCIe workaround bits
  226. * In AR9280 and AR9285, bit 14 in WA register (disable L1)
  227. * should only be set when device enters D3 and be
  228. * cleared when device comes back to D0.
  229. */
  230. if (ah->config.pcie_waen) {
  231. if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
  232. val |= AR_WA_D3_L1_DISABLE;
  233. } else {
  234. if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) {
  235. if (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)
  236. val |= AR_WA_D3_L1_DISABLE;
  237. } else if (AR_SREV_9280(ah)) {
  238. if (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE)
  239. val |= AR_WA_D3_L1_DISABLE;
  240. }
  241. }
  242. if (AR_SREV_9280(ah) || AR_SREV_9285(ah) || AR_SREV_9287(ah)) {
  243. /*
  244. * Disable bit 6 and 7 before entering D3 to
  245. * prevent system hang.
  246. */
  247. val &= ~(AR_WA_BIT6 | AR_WA_BIT7);
  248. }
  249. if (AR_SREV_9280(ah))
  250. val |= AR_WA_BIT22;
  251. if (AR_SREV_9285E_20(ah))
  252. val |= AR_WA_BIT23;
  253. REG_WRITE(ah, AR_WA, val);
  254. } else {
  255. if (ah->config.pcie_waen) {
  256. val = ah->config.pcie_waen;
  257. val &= (~AR_WA_D3_L1_DISABLE);
  258. } else {
  259. if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) {
  260. val = AR9285_WA_DEFAULT;
  261. val &= (~AR_WA_D3_L1_DISABLE);
  262. } else if (AR_SREV_9280(ah)) {
  263. /*
  264. * For AR9280 chips, bit 22 of 0x4004
  265. * needs to be set.
  266. */
  267. val = AR9280_WA_DEFAULT;
  268. val &= (~AR_WA_D3_L1_DISABLE);
  269. } else {
  270. val = AR_WA_DEFAULT;
  271. }
  272. }
  273. /* WAR for ASPM system hang */
  274. if (AR_SREV_9285(ah) || AR_SREV_9287(ah))
  275. val |= (AR_WA_BIT6 | AR_WA_BIT7);
  276. if (AR_SREV_9285E_20(ah))
  277. val |= AR_WA_BIT23;
  278. REG_WRITE(ah, AR_WA, val);
  279. /* set bit 19 to allow forcing of pcie core into L1 state */
  280. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  281. }
  282. }
  283. static int ar9002_hw_get_radiorev(struct ath_hw *ah)
  284. {
  285. u32 val;
  286. int i;
  287. ENABLE_REGWRITE_BUFFER(ah);
  288. REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
  289. for (i = 0; i < 8; i++)
  290. REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
  291. REGWRITE_BUFFER_FLUSH(ah);
  292. val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
  293. val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
  294. return ath9k_hw_reverse_bits(val, 8);
  295. }
  296. int ar9002_hw_rf_claim(struct ath_hw *ah)
  297. {
  298. u32 val;
  299. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  300. val = ar9002_hw_get_radiorev(ah);
  301. switch (val & AR_RADIO_SREV_MAJOR) {
  302. case 0:
  303. val = AR_RAD5133_SREV_MAJOR;
  304. break;
  305. case AR_RAD5133_SREV_MAJOR:
  306. case AR_RAD5122_SREV_MAJOR:
  307. case AR_RAD2133_SREV_MAJOR:
  308. case AR_RAD2122_SREV_MAJOR:
  309. break;
  310. default:
  311. ath_err(ath9k_hw_common(ah),
  312. "Radio Chip Rev 0x%02X not supported\n",
  313. val & AR_RADIO_SREV_MAJOR);
  314. return -EOPNOTSUPP;
  315. }
  316. ah->hw_version.analog5GhzRev = val;
  317. return 0;
  318. }
  319. void ar9002_hw_enable_async_fifo(struct ath_hw *ah)
  320. {
  321. if (AR_SREV_9287_13_OR_LATER(ah)) {
  322. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  323. AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
  324. REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
  325. REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  326. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  327. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  328. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  329. }
  330. }
  331. static void ar9002_hw_init_hang_checks(struct ath_hw *ah)
  332. {
  333. if (AR_SREV_9100(ah) || AR_SREV_9160(ah)) {
  334. ah->config.hw_hang_checks |= HW_BB_RIFS_HANG;
  335. ah->config.hw_hang_checks |= HW_BB_DFS_HANG;
  336. }
  337. if (AR_SREV_9280(ah))
  338. ah->config.hw_hang_checks |= HW_BB_RX_CLEAR_STUCK_HANG;
  339. if (AR_SREV_5416(ah) || AR_SREV_9100(ah) || AR_SREV_9160(ah))
  340. ah->config.hw_hang_checks |= HW_MAC_HANG;
  341. }
  342. /* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
  343. int ar9002_hw_attach_ops(struct ath_hw *ah)
  344. {
  345. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  346. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  347. int ret;
  348. ret = ar9002_hw_init_mode_regs(ah);
  349. if (ret)
  350. return ret;
  351. priv_ops->init_mode_gain_regs = ar9002_hw_init_mode_gain_regs;
  352. priv_ops->init_hang_checks = ar9002_hw_init_hang_checks;
  353. ops->config_pci_powersave = ar9002_hw_configpcipowersave;
  354. ret = ar5008_hw_attach_phy_ops(ah);
  355. if (ret)
  356. return ret;
  357. if (AR_SREV_9280_20_OR_LATER(ah))
  358. ar9002_hw_attach_phy_ops(ah);
  359. ar9002_hw_attach_calib_ops(ah);
  360. ar9002_hw_attach_mac_ops(ah);
  361. return 0;
  362. }
  363. void ar9002_hw_load_ani_reg(struct ath_hw *ah, struct ath9k_channel *chan)
  364. {
  365. u32 modesIndex;
  366. int i;
  367. if (IS_CHAN_5GHZ(chan))
  368. modesIndex = IS_CHAN_HT40(chan) ? 2 : 1;
  369. else
  370. modesIndex = IS_CHAN_HT40(chan) ? 3 : 4;
  371. ENABLE_REGWRITE_BUFFER(ah);
  372. for (i = 0; i < ah->iniModes_9271_ANI_reg.ia_rows; i++) {
  373. u32 reg = INI_RA(&ah->iniModes_9271_ANI_reg, i, 0);
  374. u32 val = INI_RA(&ah->iniModes_9271_ANI_reg, i, modesIndex);
  375. u32 val_orig;
  376. if (reg == AR_PHY_CCK_DETECT) {
  377. val_orig = REG_READ(ah, reg);
  378. val &= AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
  379. val_orig &= ~AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
  380. REG_WRITE(ah, reg, val|val_orig);
  381. } else
  382. REG_WRITE(ah, reg, val);
  383. }
  384. REGWRITE_BUFFER_FLUSH(ah);
  385. }