hw.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. * Copyright (c) 2014-2015 Qualcomm Atheros, 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/types.h>
  17. #include "core.h"
  18. #include "hw.h"
  19. #include "hif.h"
  20. #include "wmi-ops.h"
  21. #include "bmi.h"
  22. const struct ath10k_hw_regs qca988x_regs = {
  23. .rtc_soc_base_address = 0x00004000,
  24. .rtc_wmac_base_address = 0x00005000,
  25. .soc_core_base_address = 0x00009000,
  26. .wlan_mac_base_address = 0x00020000,
  27. .ce_wrapper_base_address = 0x00057000,
  28. .ce0_base_address = 0x00057400,
  29. .ce1_base_address = 0x00057800,
  30. .ce2_base_address = 0x00057c00,
  31. .ce3_base_address = 0x00058000,
  32. .ce4_base_address = 0x00058400,
  33. .ce5_base_address = 0x00058800,
  34. .ce6_base_address = 0x00058c00,
  35. .ce7_base_address = 0x00059000,
  36. .soc_reset_control_si0_rst_mask = 0x00000001,
  37. .soc_reset_control_ce_rst_mask = 0x00040000,
  38. .soc_chip_id_address = 0x000000ec,
  39. .scratch_3_address = 0x00000030,
  40. .fw_indicator_address = 0x00009030,
  41. .pcie_local_base_address = 0x00080000,
  42. .ce_wrap_intr_sum_host_msi_lsb = 0x00000008,
  43. .ce_wrap_intr_sum_host_msi_mask = 0x0000ff00,
  44. .pcie_intr_fw_mask = 0x00000400,
  45. .pcie_intr_ce_mask_all = 0x0007f800,
  46. .pcie_intr_clr_address = 0x00000014,
  47. };
  48. const struct ath10k_hw_regs qca6174_regs = {
  49. .rtc_soc_base_address = 0x00000800,
  50. .rtc_wmac_base_address = 0x00001000,
  51. .soc_core_base_address = 0x0003a000,
  52. .wlan_mac_base_address = 0x00010000,
  53. .ce_wrapper_base_address = 0x00034000,
  54. .ce0_base_address = 0x00034400,
  55. .ce1_base_address = 0x00034800,
  56. .ce2_base_address = 0x00034c00,
  57. .ce3_base_address = 0x00035000,
  58. .ce4_base_address = 0x00035400,
  59. .ce5_base_address = 0x00035800,
  60. .ce6_base_address = 0x00035c00,
  61. .ce7_base_address = 0x00036000,
  62. .soc_reset_control_si0_rst_mask = 0x00000000,
  63. .soc_reset_control_ce_rst_mask = 0x00000001,
  64. .soc_chip_id_address = 0x000000f0,
  65. .scratch_3_address = 0x00000028,
  66. .fw_indicator_address = 0x0003a028,
  67. .pcie_local_base_address = 0x00080000,
  68. .ce_wrap_intr_sum_host_msi_lsb = 0x00000008,
  69. .ce_wrap_intr_sum_host_msi_mask = 0x0000ff00,
  70. .pcie_intr_fw_mask = 0x00000400,
  71. .pcie_intr_ce_mask_all = 0x0007f800,
  72. .pcie_intr_clr_address = 0x00000014,
  73. .cpu_pll_init_address = 0x00404020,
  74. .cpu_speed_address = 0x00404024,
  75. .core_clk_div_address = 0x00404028,
  76. };
  77. const struct ath10k_hw_regs qca99x0_regs = {
  78. .rtc_soc_base_address = 0x00080000,
  79. .rtc_wmac_base_address = 0x00000000,
  80. .soc_core_base_address = 0x00082000,
  81. .wlan_mac_base_address = 0x00030000,
  82. .ce_wrapper_base_address = 0x0004d000,
  83. .ce0_base_address = 0x0004a000,
  84. .ce1_base_address = 0x0004a400,
  85. .ce2_base_address = 0x0004a800,
  86. .ce3_base_address = 0x0004ac00,
  87. .ce4_base_address = 0x0004b000,
  88. .ce5_base_address = 0x0004b400,
  89. .ce6_base_address = 0x0004b800,
  90. .ce7_base_address = 0x0004bc00,
  91. /* Note: qca99x0 supports upto 12 Copy Engines. Other than address of
  92. * CE0 and CE1 no other copy engine is directly referred in the code.
  93. * It is not really necessary to assign address for newly supported
  94. * CEs in this address table.
  95. * Copy Engine Address
  96. * CE8 0x0004c000
  97. * CE9 0x0004c400
  98. * CE10 0x0004c800
  99. * CE11 0x0004cc00
  100. */
  101. .soc_reset_control_si0_rst_mask = 0x00000001,
  102. .soc_reset_control_ce_rst_mask = 0x00000100,
  103. .soc_chip_id_address = 0x000000ec,
  104. .scratch_3_address = 0x00040050,
  105. .fw_indicator_address = 0x00040050,
  106. .pcie_local_base_address = 0x00000000,
  107. .ce_wrap_intr_sum_host_msi_lsb = 0x0000000c,
  108. .ce_wrap_intr_sum_host_msi_mask = 0x00fff000,
  109. .pcie_intr_fw_mask = 0x00100000,
  110. .pcie_intr_ce_mask_all = 0x000fff00,
  111. .pcie_intr_clr_address = 0x00000010,
  112. };
  113. const struct ath10k_hw_regs qca4019_regs = {
  114. .rtc_soc_base_address = 0x00080000,
  115. .soc_core_base_address = 0x00082000,
  116. .wlan_mac_base_address = 0x00030000,
  117. .ce_wrapper_base_address = 0x0004d000,
  118. .ce0_base_address = 0x0004a000,
  119. .ce1_base_address = 0x0004a400,
  120. .ce2_base_address = 0x0004a800,
  121. .ce3_base_address = 0x0004ac00,
  122. .ce4_base_address = 0x0004b000,
  123. .ce5_base_address = 0x0004b400,
  124. .ce6_base_address = 0x0004b800,
  125. .ce7_base_address = 0x0004bc00,
  126. /* qca4019 supports upto 12 copy engines. Since base address
  127. * of ce8 to ce11 are not directly referred in the code,
  128. * no need have them in separate members in this table.
  129. * Copy Engine Address
  130. * CE8 0x0004c000
  131. * CE9 0x0004c400
  132. * CE10 0x0004c800
  133. * CE11 0x0004cc00
  134. */
  135. .soc_reset_control_si0_rst_mask = 0x00000001,
  136. .soc_reset_control_ce_rst_mask = 0x00000100,
  137. .soc_chip_id_address = 0x000000ec,
  138. .fw_indicator_address = 0x0004f00c,
  139. .ce_wrap_intr_sum_host_msi_lsb = 0x0000000c,
  140. .ce_wrap_intr_sum_host_msi_mask = 0x00fff000,
  141. .pcie_intr_fw_mask = 0x00100000,
  142. .pcie_intr_ce_mask_all = 0x000fff00,
  143. .pcie_intr_clr_address = 0x00000010,
  144. };
  145. const struct ath10k_hw_values qca988x_values = {
  146. .rtc_state_val_on = 3,
  147. .ce_count = 8,
  148. .msi_assign_ce_max = 7,
  149. .num_target_ce_config_wlan = 7,
  150. .ce_desc_meta_data_mask = 0xFFFC,
  151. .ce_desc_meta_data_lsb = 2,
  152. };
  153. const struct ath10k_hw_values qca6174_values = {
  154. .rtc_state_val_on = 3,
  155. .ce_count = 8,
  156. .msi_assign_ce_max = 7,
  157. .num_target_ce_config_wlan = 7,
  158. .ce_desc_meta_data_mask = 0xFFFC,
  159. .ce_desc_meta_data_lsb = 2,
  160. };
  161. const struct ath10k_hw_values qca99x0_values = {
  162. .rtc_state_val_on = 5,
  163. .ce_count = 12,
  164. .msi_assign_ce_max = 12,
  165. .num_target_ce_config_wlan = 10,
  166. .ce_desc_meta_data_mask = 0xFFF0,
  167. .ce_desc_meta_data_lsb = 4,
  168. };
  169. const struct ath10k_hw_values qca9888_values = {
  170. .rtc_state_val_on = 3,
  171. .ce_count = 12,
  172. .msi_assign_ce_max = 12,
  173. .num_target_ce_config_wlan = 10,
  174. .ce_desc_meta_data_mask = 0xFFF0,
  175. .ce_desc_meta_data_lsb = 4,
  176. };
  177. const struct ath10k_hw_values qca4019_values = {
  178. .ce_count = 12,
  179. .num_target_ce_config_wlan = 10,
  180. .ce_desc_meta_data_mask = 0xFFF0,
  181. .ce_desc_meta_data_lsb = 4,
  182. };
  183. const struct ath10k_hw_clk_params qca6174_clk[ATH10K_HW_REFCLK_COUNT] = {
  184. {
  185. .refclk = 48000000,
  186. .div = 0xe,
  187. .rnfrac = 0x2aaa8,
  188. .settle_time = 2400,
  189. .refdiv = 0,
  190. .outdiv = 1,
  191. },
  192. {
  193. .refclk = 19200000,
  194. .div = 0x24,
  195. .rnfrac = 0x2aaa8,
  196. .settle_time = 960,
  197. .refdiv = 0,
  198. .outdiv = 1,
  199. },
  200. {
  201. .refclk = 24000000,
  202. .div = 0x1d,
  203. .rnfrac = 0x15551,
  204. .settle_time = 1200,
  205. .refdiv = 0,
  206. .outdiv = 1,
  207. },
  208. {
  209. .refclk = 26000000,
  210. .div = 0x1b,
  211. .rnfrac = 0x4ec4,
  212. .settle_time = 1300,
  213. .refdiv = 0,
  214. .outdiv = 1,
  215. },
  216. {
  217. .refclk = 37400000,
  218. .div = 0x12,
  219. .rnfrac = 0x34b49,
  220. .settle_time = 1870,
  221. .refdiv = 0,
  222. .outdiv = 1,
  223. },
  224. {
  225. .refclk = 38400000,
  226. .div = 0x12,
  227. .rnfrac = 0x15551,
  228. .settle_time = 1920,
  229. .refdiv = 0,
  230. .outdiv = 1,
  231. },
  232. {
  233. .refclk = 40000000,
  234. .div = 0x12,
  235. .rnfrac = 0x26665,
  236. .settle_time = 2000,
  237. .refdiv = 0,
  238. .outdiv = 1,
  239. },
  240. {
  241. .refclk = 52000000,
  242. .div = 0x1b,
  243. .rnfrac = 0x4ec4,
  244. .settle_time = 2600,
  245. .refdiv = 0,
  246. .outdiv = 1,
  247. },
  248. };
  249. void ath10k_hw_fill_survey_time(struct ath10k *ar, struct survey_info *survey,
  250. u32 cc, u32 rcc, u32 cc_prev, u32 rcc_prev)
  251. {
  252. u32 cc_fix = 0;
  253. u32 rcc_fix = 0;
  254. enum ath10k_hw_cc_wraparound_type wraparound_type;
  255. survey->filled |= SURVEY_INFO_TIME |
  256. SURVEY_INFO_TIME_BUSY;
  257. wraparound_type = ar->hw_params.cc_wraparound_type;
  258. if (cc < cc_prev || rcc < rcc_prev) {
  259. switch (wraparound_type) {
  260. case ATH10K_HW_CC_WRAP_SHIFTED_ALL:
  261. if (cc < cc_prev) {
  262. cc_fix = 0x7fffffff;
  263. survey->filled &= ~SURVEY_INFO_TIME_BUSY;
  264. }
  265. break;
  266. case ATH10K_HW_CC_WRAP_SHIFTED_EACH:
  267. if (cc < cc_prev)
  268. cc_fix = 0x7fffffff;
  269. if (rcc < rcc_prev)
  270. rcc_fix = 0x7fffffff;
  271. break;
  272. case ATH10K_HW_CC_WRAP_DISABLED:
  273. break;
  274. }
  275. }
  276. cc -= cc_prev - cc_fix;
  277. rcc -= rcc_prev - rcc_fix;
  278. survey->time = CCNT_TO_MSEC(ar, cc);
  279. survey->time_busy = CCNT_TO_MSEC(ar, rcc);
  280. }
  281. /* The firmware does not support setting the coverage class. Instead this
  282. * function monitors and modifies the corresponding MAC registers.
  283. */
  284. static void ath10k_hw_qca988x_set_coverage_class(struct ath10k *ar,
  285. s16 value)
  286. {
  287. u32 slottime_reg;
  288. u32 slottime;
  289. u32 timeout_reg;
  290. u32 ack_timeout;
  291. u32 cts_timeout;
  292. u32 phyclk_reg;
  293. u32 phyclk;
  294. u64 fw_dbglog_mask;
  295. u32 fw_dbglog_level;
  296. mutex_lock(&ar->conf_mutex);
  297. /* Only modify registers if the core is started. */
  298. if ((ar->state != ATH10K_STATE_ON) &&
  299. (ar->state != ATH10K_STATE_RESTARTED))
  300. goto unlock;
  301. /* Retrieve the current values of the two registers that need to be
  302. * adjusted.
  303. */
  304. slottime_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
  305. WAVE1_PCU_GBL_IFS_SLOT);
  306. timeout_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
  307. WAVE1_PCU_ACK_CTS_TIMEOUT);
  308. phyclk_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
  309. WAVE1_PHYCLK);
  310. phyclk = MS(phyclk_reg, WAVE1_PHYCLK_USEC) + 1;
  311. if (value < 0)
  312. value = ar->fw_coverage.coverage_class;
  313. /* Break out if the coverage class and registers have the expected
  314. * value.
  315. */
  316. if (value == ar->fw_coverage.coverage_class &&
  317. slottime_reg == ar->fw_coverage.reg_slottime_conf &&
  318. timeout_reg == ar->fw_coverage.reg_ack_cts_timeout_conf &&
  319. phyclk_reg == ar->fw_coverage.reg_phyclk)
  320. goto unlock;
  321. /* Store new initial register values from the firmware. */
  322. if (slottime_reg != ar->fw_coverage.reg_slottime_conf)
  323. ar->fw_coverage.reg_slottime_orig = slottime_reg;
  324. if (timeout_reg != ar->fw_coverage.reg_ack_cts_timeout_conf)
  325. ar->fw_coverage.reg_ack_cts_timeout_orig = timeout_reg;
  326. ar->fw_coverage.reg_phyclk = phyclk_reg;
  327. /* Calculat new value based on the (original) firmware calculation. */
  328. slottime_reg = ar->fw_coverage.reg_slottime_orig;
  329. timeout_reg = ar->fw_coverage.reg_ack_cts_timeout_orig;
  330. /* Do some sanity checks on the slottime register. */
  331. if (slottime_reg % phyclk) {
  332. ath10k_warn(ar,
  333. "failed to set coverage class: expected integer microsecond value in register\n");
  334. goto store_regs;
  335. }
  336. slottime = MS(slottime_reg, WAVE1_PCU_GBL_IFS_SLOT);
  337. slottime = slottime / phyclk;
  338. if (slottime != 9 && slottime != 20) {
  339. ath10k_warn(ar,
  340. "failed to set coverage class: expected slot time of 9 or 20us in HW register. It is %uus.\n",
  341. slottime);
  342. goto store_regs;
  343. }
  344. /* Recalculate the register values by adding the additional propagation
  345. * delay (3us per coverage class).
  346. */
  347. slottime = MS(slottime_reg, WAVE1_PCU_GBL_IFS_SLOT);
  348. slottime += value * 3 * phyclk;
  349. slottime = min_t(u32, slottime, WAVE1_PCU_GBL_IFS_SLOT_MAX);
  350. slottime = SM(slottime, WAVE1_PCU_GBL_IFS_SLOT);
  351. slottime_reg = (slottime_reg & ~WAVE1_PCU_GBL_IFS_SLOT_MASK) | slottime;
  352. /* Update ack timeout (lower halfword). */
  353. ack_timeout = MS(timeout_reg, WAVE1_PCU_ACK_CTS_TIMEOUT_ACK);
  354. ack_timeout += 3 * value * phyclk;
  355. ack_timeout = min_t(u32, ack_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_MAX);
  356. ack_timeout = SM(ack_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_ACK);
  357. /* Update cts timeout (upper halfword). */
  358. cts_timeout = MS(timeout_reg, WAVE1_PCU_ACK_CTS_TIMEOUT_CTS);
  359. cts_timeout += 3 * value * phyclk;
  360. cts_timeout = min_t(u32, cts_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_MAX);
  361. cts_timeout = SM(cts_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_CTS);
  362. timeout_reg = ack_timeout | cts_timeout;
  363. ath10k_hif_write32(ar,
  364. WLAN_MAC_BASE_ADDRESS + WAVE1_PCU_GBL_IFS_SLOT,
  365. slottime_reg);
  366. ath10k_hif_write32(ar,
  367. WLAN_MAC_BASE_ADDRESS + WAVE1_PCU_ACK_CTS_TIMEOUT,
  368. timeout_reg);
  369. /* Ensure we have a debug level of WARN set for the case that the
  370. * coverage class is larger than 0. This is important as we need to
  371. * set the registers again if the firmware does an internal reset and
  372. * this way we will be notified of the event.
  373. */
  374. fw_dbglog_mask = ath10k_debug_get_fw_dbglog_mask(ar);
  375. fw_dbglog_level = ath10k_debug_get_fw_dbglog_level(ar);
  376. if (value > 0) {
  377. if (fw_dbglog_level > ATH10K_DBGLOG_LEVEL_WARN)
  378. fw_dbglog_level = ATH10K_DBGLOG_LEVEL_WARN;
  379. fw_dbglog_mask = ~0;
  380. }
  381. ath10k_wmi_dbglog_cfg(ar, fw_dbglog_mask, fw_dbglog_level);
  382. store_regs:
  383. /* After an error we will not retry setting the coverage class. */
  384. spin_lock_bh(&ar->data_lock);
  385. ar->fw_coverage.coverage_class = value;
  386. spin_unlock_bh(&ar->data_lock);
  387. ar->fw_coverage.reg_slottime_conf = slottime_reg;
  388. ar->fw_coverage.reg_ack_cts_timeout_conf = timeout_reg;
  389. unlock:
  390. mutex_unlock(&ar->conf_mutex);
  391. }
  392. /**
  393. * ath10k_hw_qca6174_enable_pll_clock() - enable the qca6174 hw pll clock
  394. * @ar: the ath10k blob
  395. *
  396. * This function is very hardware specific, the clock initialization
  397. * steps is very sensitive and could lead to unknown crash, so they
  398. * should be done in sequence.
  399. *
  400. * *** Be aware if you planned to refactor them. ***
  401. *
  402. * Return: 0 if successfully enable the pll, otherwise EINVAL
  403. */
  404. static int ath10k_hw_qca6174_enable_pll_clock(struct ath10k *ar)
  405. {
  406. int ret, wait_limit;
  407. u32 clk_div_addr, pll_init_addr, speed_addr;
  408. u32 addr, reg_val, mem_val;
  409. struct ath10k_hw_params *hw;
  410. const struct ath10k_hw_clk_params *hw_clk;
  411. hw = &ar->hw_params;
  412. if (ar->regs->core_clk_div_address == 0 ||
  413. ar->regs->cpu_pll_init_address == 0 ||
  414. ar->regs->cpu_speed_address == 0)
  415. return -EINVAL;
  416. clk_div_addr = ar->regs->core_clk_div_address;
  417. pll_init_addr = ar->regs->cpu_pll_init_address;
  418. speed_addr = ar->regs->cpu_speed_address;
  419. /* Read efuse register to find out the right hw clock configuration */
  420. addr = (RTC_SOC_BASE_ADDRESS | EFUSE_OFFSET);
  421. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  422. if (ret)
  423. return -EINVAL;
  424. /* sanitize if the hw refclk index is out of the boundary */
  425. if (MS(reg_val, EFUSE_XTAL_SEL) > ATH10K_HW_REFCLK_COUNT)
  426. return -EINVAL;
  427. hw_clk = &hw->hw_clk[MS(reg_val, EFUSE_XTAL_SEL)];
  428. /* Set the rnfrac and outdiv params to bb_pll register */
  429. addr = (RTC_SOC_BASE_ADDRESS | BB_PLL_CONFIG_OFFSET);
  430. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  431. if (ret)
  432. return -EINVAL;
  433. reg_val &= ~(BB_PLL_CONFIG_FRAC_MASK | BB_PLL_CONFIG_OUTDIV_MASK);
  434. reg_val |= (SM(hw_clk->rnfrac, BB_PLL_CONFIG_FRAC) |
  435. SM(hw_clk->outdiv, BB_PLL_CONFIG_OUTDIV));
  436. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  437. if (ret)
  438. return -EINVAL;
  439. /* Set the correct settle time value to pll_settle register */
  440. addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_SETTLE_OFFSET);
  441. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  442. if (ret)
  443. return -EINVAL;
  444. reg_val &= ~WLAN_PLL_SETTLE_TIME_MASK;
  445. reg_val |= SM(hw_clk->settle_time, WLAN_PLL_SETTLE_TIME);
  446. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  447. if (ret)
  448. return -EINVAL;
  449. /* Set the clock_ctrl div to core_clk_ctrl register */
  450. addr = (RTC_SOC_BASE_ADDRESS | SOC_CORE_CLK_CTRL_OFFSET);
  451. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  452. if (ret)
  453. return -EINVAL;
  454. reg_val &= ~SOC_CORE_CLK_CTRL_DIV_MASK;
  455. reg_val |= SM(1, SOC_CORE_CLK_CTRL_DIV);
  456. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  457. if (ret)
  458. return -EINVAL;
  459. /* Set the clock_div register */
  460. mem_val = 1;
  461. ret = ath10k_bmi_write_memory(ar, clk_div_addr, &mem_val,
  462. sizeof(mem_val));
  463. if (ret)
  464. return -EINVAL;
  465. /* Configure the pll_control register */
  466. addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_CONTROL_OFFSET);
  467. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  468. if (ret)
  469. return -EINVAL;
  470. reg_val |= (SM(hw_clk->refdiv, WLAN_PLL_CONTROL_REFDIV) |
  471. SM(hw_clk->div, WLAN_PLL_CONTROL_DIV) |
  472. SM(1, WLAN_PLL_CONTROL_NOPWD));
  473. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  474. if (ret)
  475. return -EINVAL;
  476. /* busy wait (max 1s) the rtc_sync status register indicate ready */
  477. wait_limit = 100000;
  478. addr = (RTC_WMAC_BASE_ADDRESS | RTC_SYNC_STATUS_OFFSET);
  479. do {
  480. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  481. if (ret)
  482. return -EINVAL;
  483. if (!MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
  484. break;
  485. wait_limit--;
  486. udelay(10);
  487. } while (wait_limit > 0);
  488. if (MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
  489. return -EINVAL;
  490. /* Unset the pll_bypass in pll_control register */
  491. addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_CONTROL_OFFSET);
  492. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  493. if (ret)
  494. return -EINVAL;
  495. reg_val &= ~WLAN_PLL_CONTROL_BYPASS_MASK;
  496. reg_val |= SM(0, WLAN_PLL_CONTROL_BYPASS);
  497. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  498. if (ret)
  499. return -EINVAL;
  500. /* busy wait (max 1s) the rtc_sync status register indicate ready */
  501. wait_limit = 100000;
  502. addr = (RTC_WMAC_BASE_ADDRESS | RTC_SYNC_STATUS_OFFSET);
  503. do {
  504. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  505. if (ret)
  506. return -EINVAL;
  507. if (!MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
  508. break;
  509. wait_limit--;
  510. udelay(10);
  511. } while (wait_limit > 0);
  512. if (MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
  513. return -EINVAL;
  514. /* Enable the hardware cpu clock register */
  515. addr = (RTC_SOC_BASE_ADDRESS | SOC_CPU_CLOCK_OFFSET);
  516. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  517. if (ret)
  518. return -EINVAL;
  519. reg_val &= ~SOC_CPU_CLOCK_STANDARD_MASK;
  520. reg_val |= SM(1, SOC_CPU_CLOCK_STANDARD);
  521. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  522. if (ret)
  523. return -EINVAL;
  524. /* unset the nopwd from pll_control register */
  525. addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_CONTROL_OFFSET);
  526. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  527. if (ret)
  528. return -EINVAL;
  529. reg_val &= ~WLAN_PLL_CONTROL_NOPWD_MASK;
  530. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  531. if (ret)
  532. return -EINVAL;
  533. /* enable the pll_init register */
  534. mem_val = 1;
  535. ret = ath10k_bmi_write_memory(ar, pll_init_addr, &mem_val,
  536. sizeof(mem_val));
  537. if (ret)
  538. return -EINVAL;
  539. /* set the target clock frequency to speed register */
  540. ret = ath10k_bmi_write_memory(ar, speed_addr, &hw->target_cpu_freq,
  541. sizeof(hw->target_cpu_freq));
  542. if (ret)
  543. return -EINVAL;
  544. return 0;
  545. }
  546. const struct ath10k_hw_ops qca988x_ops = {
  547. .set_coverage_class = ath10k_hw_qca988x_set_coverage_class,
  548. };
  549. static int ath10k_qca99x0_rx_desc_get_l3_pad_bytes(struct htt_rx_desc *rxd)
  550. {
  551. return MS(__le32_to_cpu(rxd->msdu_end.qca99x0.info1),
  552. RX_MSDU_END_INFO1_L3_HDR_PAD);
  553. }
  554. const struct ath10k_hw_ops qca99x0_ops = {
  555. .rx_desc_get_l3_pad_bytes = ath10k_qca99x0_rx_desc_get_l3_pad_bytes,
  556. };
  557. const struct ath10k_hw_ops qca6174_ops = {
  558. .set_coverage_class = ath10k_hw_qca988x_set_coverage_class,
  559. .enable_pll_clk = ath10k_hw_qca6174_enable_pll_clock,
  560. };