ar9002_hw.c 13 KB

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