ar9002_hw.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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(ah, EEP_MINOR_REV) >=
  98. AR5416_EEP_MINOR_VER_17) {
  99. rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
  100. if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
  101. INIT_INI_ARRAY(&ah->iniModesRxGain,
  102. ar9280Modes_backoff_13db_rxgain_9280_2);
  103. else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
  104. INIT_INI_ARRAY(&ah->iniModesRxGain,
  105. ar9280Modes_backoff_23db_rxgain_9280_2);
  106. else
  107. INIT_INI_ARRAY(&ah->iniModesRxGain,
  108. ar9280Modes_original_rxgain_9280_2);
  109. } else {
  110. INIT_INI_ARRAY(&ah->iniModesRxGain,
  111. ar9280Modes_original_rxgain_9280_2);
  112. }
  113. }
  114. static void ar9280_20_hw_init_txgain_ini(struct ath_hw *ah, u32 txgain_type)
  115. {
  116. if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >=
  117. AR5416_EEP_MINOR_VER_19) {
  118. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
  119. INIT_INI_ARRAY(&ah->iniModesTxGain,
  120. ar9280Modes_high_power_tx_gain_9280_2);
  121. else
  122. INIT_INI_ARRAY(&ah->iniModesTxGain,
  123. ar9280Modes_original_tx_gain_9280_2);
  124. } else {
  125. INIT_INI_ARRAY(&ah->iniModesTxGain,
  126. ar9280Modes_original_tx_gain_9280_2);
  127. }
  128. }
  129. static void ar9271_hw_init_txgain_ini(struct ath_hw *ah, u32 txgain_type)
  130. {
  131. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
  132. INIT_INI_ARRAY(&ah->iniModesTxGain,
  133. ar9271Modes_high_power_tx_gain_9271);
  134. else
  135. INIT_INI_ARRAY(&ah->iniModesTxGain,
  136. ar9271Modes_normal_power_tx_gain_9271);
  137. }
  138. static void ar9002_hw_init_mode_gain_regs(struct ath_hw *ah)
  139. {
  140. u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  141. if (AR_SREV_9287_11_OR_LATER(ah))
  142. INIT_INI_ARRAY(&ah->iniModesRxGain,
  143. ar9287Modes_rx_gain_9287_1_1);
  144. else if (AR_SREV_9280_20(ah))
  145. ar9280_20_hw_init_rxgain_ini(ah);
  146. if (AR_SREV_9271(ah)) {
  147. ar9271_hw_init_txgain_ini(ah, txgain_type);
  148. } else if (AR_SREV_9287_11_OR_LATER(ah)) {
  149. INIT_INI_ARRAY(&ah->iniModesTxGain,
  150. ar9287Modes_tx_gain_9287_1_1);
  151. } else if (AR_SREV_9280_20(ah)) {
  152. ar9280_20_hw_init_txgain_ini(ah, txgain_type);
  153. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  154. /* txgain table */
  155. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
  156. if (AR_SREV_9285E_20(ah)) {
  157. INIT_INI_ARRAY(&ah->iniModesTxGain,
  158. ar9285Modes_XE2_0_high_power);
  159. } else {
  160. INIT_INI_ARRAY(&ah->iniModesTxGain,
  161. ar9285Modes_high_power_tx_gain_9285_1_2);
  162. }
  163. } else {
  164. if (AR_SREV_9285E_20(ah)) {
  165. INIT_INI_ARRAY(&ah->iniModesTxGain,
  166. ar9285Modes_XE2_0_normal_power);
  167. } else {
  168. INIT_INI_ARRAY(&ah->iniModesTxGain,
  169. ar9285Modes_original_tx_gain_9285_1_2);
  170. }
  171. }
  172. }
  173. }
  174. /*
  175. * Helper for ASPM support.
  176. *
  177. * Disable PLL when in L0s as well as receiver clock when in L1.
  178. * This power saving option must be enabled through the SerDes.
  179. *
  180. * Programming the SerDes must go through the same 288 bit serial shift
  181. * register as the other analog registers. Hence the 9 writes.
  182. */
  183. static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
  184. bool power_off)
  185. {
  186. u8 i;
  187. u32 val;
  188. /* Nothing to do on restore for 11N */
  189. if (!power_off /* !restore */) {
  190. if (AR_SREV_9280_20_OR_LATER(ah)) {
  191. /*
  192. * AR9280 2.0 or later chips use SerDes values from the
  193. * initvals.h initialized depending on chipset during
  194. * __ath9k_hw_init()
  195. */
  196. for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
  197. REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
  198. INI_RA(&ah->iniPcieSerdes, i, 1));
  199. }
  200. } else {
  201. ENABLE_REGWRITE_BUFFER(ah);
  202. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  203. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  204. /* RX shut off when elecidle is asserted */
  205. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
  206. REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
  207. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
  208. /*
  209. * Ignore ah->ah_config.pcie_clock_req setting for
  210. * pre-AR9280 11n
  211. */
  212. REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
  213. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  214. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  215. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
  216. /* Load the new settings */
  217. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  218. REGWRITE_BUFFER_FLUSH(ah);
  219. }
  220. udelay(1000);
  221. }
  222. if (power_off) {
  223. /* clear bit 19 to disable L1 */
  224. REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  225. val = REG_READ(ah, AR_WA);
  226. /*
  227. * Set PCIe workaround bits
  228. * In AR9280 and AR9285, bit 14 in WA register (disable L1)
  229. * should only be set when device enters D3 and be
  230. * cleared when device comes back to D0.
  231. */
  232. if (ah->config.pcie_waen) {
  233. if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
  234. val |= AR_WA_D3_L1_DISABLE;
  235. } else {
  236. if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) {
  237. if (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)
  238. val |= AR_WA_D3_L1_DISABLE;
  239. } else if (AR_SREV_9280(ah)) {
  240. if (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE)
  241. val |= AR_WA_D3_L1_DISABLE;
  242. }
  243. }
  244. if (AR_SREV_9280(ah) || AR_SREV_9285(ah) || AR_SREV_9287(ah)) {
  245. /*
  246. * Disable bit 6 and 7 before entering D3 to
  247. * prevent system hang.
  248. */
  249. val &= ~(AR_WA_BIT6 | AR_WA_BIT7);
  250. }
  251. if (AR_SREV_9280(ah))
  252. val |= AR_WA_BIT22;
  253. if (AR_SREV_9285E_20(ah))
  254. val |= AR_WA_BIT23;
  255. REG_WRITE(ah, AR_WA, val);
  256. } else {
  257. if (ah->config.pcie_waen) {
  258. val = ah->config.pcie_waen;
  259. val &= (~AR_WA_D3_L1_DISABLE);
  260. } else {
  261. if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) {
  262. val = AR9285_WA_DEFAULT;
  263. val &= (~AR_WA_D3_L1_DISABLE);
  264. } else if (AR_SREV_9280(ah)) {
  265. /*
  266. * For AR9280 chips, bit 22 of 0x4004
  267. * needs to be set.
  268. */
  269. val = AR9280_WA_DEFAULT;
  270. val &= (~AR_WA_D3_L1_DISABLE);
  271. } else {
  272. val = AR_WA_DEFAULT;
  273. }
  274. }
  275. /* WAR for ASPM system hang */
  276. if (AR_SREV_9285(ah) || AR_SREV_9287(ah))
  277. val |= (AR_WA_BIT6 | AR_WA_BIT7);
  278. if (AR_SREV_9285E_20(ah))
  279. val |= AR_WA_BIT23;
  280. REG_WRITE(ah, AR_WA, val);
  281. /* set bit 19 to allow forcing of pcie core into L1 state */
  282. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  283. }
  284. }
  285. static int ar9002_hw_get_radiorev(struct ath_hw *ah)
  286. {
  287. u32 val;
  288. int i;
  289. ENABLE_REGWRITE_BUFFER(ah);
  290. REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
  291. for (i = 0; i < 8; i++)
  292. REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
  293. REGWRITE_BUFFER_FLUSH(ah);
  294. val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
  295. val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
  296. return ath9k_hw_reverse_bits(val, 8);
  297. }
  298. int ar9002_hw_rf_claim(struct ath_hw *ah)
  299. {
  300. u32 val;
  301. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  302. val = ar9002_hw_get_radiorev(ah);
  303. switch (val & AR_RADIO_SREV_MAJOR) {
  304. case 0:
  305. val = AR_RAD5133_SREV_MAJOR;
  306. break;
  307. case AR_RAD5133_SREV_MAJOR:
  308. case AR_RAD5122_SREV_MAJOR:
  309. case AR_RAD2133_SREV_MAJOR:
  310. case AR_RAD2122_SREV_MAJOR:
  311. break;
  312. default:
  313. ath_err(ath9k_hw_common(ah),
  314. "Radio Chip Rev 0x%02X not supported\n",
  315. val & AR_RADIO_SREV_MAJOR);
  316. return -EOPNOTSUPP;
  317. }
  318. ah->hw_version.analog5GhzRev = val;
  319. return 0;
  320. }
  321. void ar9002_hw_enable_async_fifo(struct ath_hw *ah)
  322. {
  323. if (AR_SREV_9287_13_OR_LATER(ah)) {
  324. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  325. AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
  326. REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
  327. REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  328. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  329. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  330. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  331. }
  332. }
  333. static void ar9002_hw_init_hang_checks(struct ath_hw *ah)
  334. {
  335. if (AR_SREV_9100(ah) || AR_SREV_9160(ah)) {
  336. ah->config.hw_hang_checks |= HW_BB_RIFS_HANG;
  337. ah->config.hw_hang_checks |= HW_BB_DFS_HANG;
  338. }
  339. if (AR_SREV_9280(ah))
  340. ah->config.hw_hang_checks |= HW_BB_RX_CLEAR_STUCK_HANG;
  341. if (AR_SREV_5416(ah) || AR_SREV_9100(ah) || AR_SREV_9160(ah))
  342. ah->config.hw_hang_checks |= HW_MAC_HANG;
  343. }
  344. /* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
  345. int ar9002_hw_attach_ops(struct ath_hw *ah)
  346. {
  347. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  348. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  349. int ret;
  350. ret = ar9002_hw_init_mode_regs(ah);
  351. if (ret)
  352. return ret;
  353. priv_ops->init_mode_gain_regs = ar9002_hw_init_mode_gain_regs;
  354. priv_ops->init_hang_checks = ar9002_hw_init_hang_checks;
  355. ops->config_pci_powersave = ar9002_hw_configpcipowersave;
  356. ret = ar5008_hw_attach_phy_ops(ah);
  357. if (ret)
  358. return ret;
  359. if (AR_SREV_9280_20_OR_LATER(ah))
  360. ar9002_hw_attach_phy_ops(ah);
  361. ar9002_hw_attach_calib_ops(ah);
  362. ar9002_hw_attach_mac_ops(ah);
  363. return 0;
  364. }
  365. void ar9002_hw_load_ani_reg(struct ath_hw *ah, struct ath9k_channel *chan)
  366. {
  367. u32 modesIndex;
  368. int i;
  369. if (IS_CHAN_5GHZ(chan))
  370. modesIndex = IS_CHAN_HT40(chan) ? 2 : 1;
  371. else
  372. modesIndex = IS_CHAN_HT40(chan) ? 3 : 4;
  373. ENABLE_REGWRITE_BUFFER(ah);
  374. for (i = 0; i < ah->iniModes_9271_ANI_reg.ia_rows; i++) {
  375. u32 reg = INI_RA(&ah->iniModes_9271_ANI_reg, i, 0);
  376. u32 val = INI_RA(&ah->iniModes_9271_ANI_reg, i, modesIndex);
  377. u32 val_orig;
  378. if (reg == AR_PHY_CCK_DETECT) {
  379. val_orig = REG_READ(ah, reg);
  380. val &= AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
  381. val_orig &= ~AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK;
  382. REG_WRITE(ah, reg, val|val_orig);
  383. } else
  384. REG_WRITE(ah, reg, val);
  385. }
  386. REGWRITE_BUFFER_FLUSH(ah);
  387. }