ar9002_hw.c 12 KB

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