pmsu.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * Power Management Service Unit(PMSU) support for Armada 370/XP platforms.
  3. *
  4. * Copyright (C) 2012 Marvell
  5. *
  6. * Yehuda Yitschak <yehuday@marvell.com>
  7. * Gregory Clement <gregory.clement@free-electrons.com>
  8. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  9. *
  10. * This file is licensed under the terms of the GNU General Public
  11. * License version 2. This program is licensed "as is" without any
  12. * warranty of any kind, whether express or implied.
  13. *
  14. * The Armada 370 and Armada XP SOCs have a power management service
  15. * unit which is responsible for powering down and waking up CPUs and
  16. * other SOC units
  17. */
  18. #define pr_fmt(fmt) "mvebu-pmsu: " fmt
  19. #include <linux/clk.h>
  20. #include <linux/cpu_pm.h>
  21. #include <linux/delay.h>
  22. #include <linux/init.h>
  23. #include <linux/io.h>
  24. #include <linux/kernel.h>
  25. #include <linux/mbus.h>
  26. #include <linux/mvebu-pmsu.h>
  27. #include <linux/of_address.h>
  28. #include <linux/of_device.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/resource.h>
  31. #include <linux/slab.h>
  32. #include <linux/smp.h>
  33. #include <asm/cacheflush.h>
  34. #include <asm/cp15.h>
  35. #include <asm/smp_scu.h>
  36. #include <asm/smp_plat.h>
  37. #include <asm/suspend.h>
  38. #include <asm/tlbflush.h>
  39. #include "common.h"
  40. #include "pmsu.h"
  41. #define PMSU_BASE_OFFSET 0x100
  42. #define PMSU_REG_SIZE 0x1000
  43. /* PMSU MP registers */
  44. #define PMSU_CONTROL_AND_CONFIG(cpu) ((cpu * 0x100) + 0x104)
  45. #define PMSU_CONTROL_AND_CONFIG_DFS_REQ BIT(18)
  46. #define PMSU_CONTROL_AND_CONFIG_PWDDN_REQ BIT(16)
  47. #define PMSU_CONTROL_AND_CONFIG_L2_PWDDN BIT(20)
  48. #define PMSU_CPU_POWER_DOWN_CONTROL(cpu) ((cpu * 0x100) + 0x108)
  49. #define PMSU_CPU_POWER_DOWN_DIS_SNP_Q_SKIP BIT(0)
  50. #define PMSU_STATUS_AND_MASK(cpu) ((cpu * 0x100) + 0x10c)
  51. #define PMSU_STATUS_AND_MASK_CPU_IDLE_WAIT BIT(16)
  52. #define PMSU_STATUS_AND_MASK_SNP_Q_EMPTY_WAIT BIT(17)
  53. #define PMSU_STATUS_AND_MASK_IRQ_WAKEUP BIT(20)
  54. #define PMSU_STATUS_AND_MASK_FIQ_WAKEUP BIT(21)
  55. #define PMSU_STATUS_AND_MASK_DBG_WAKEUP BIT(22)
  56. #define PMSU_STATUS_AND_MASK_IRQ_MASK BIT(24)
  57. #define PMSU_STATUS_AND_MASK_FIQ_MASK BIT(25)
  58. #define PMSU_EVENT_STATUS_AND_MASK(cpu) ((cpu * 0x100) + 0x120)
  59. #define PMSU_EVENT_STATUS_AND_MASK_DFS_DONE BIT(1)
  60. #define PMSU_EVENT_STATUS_AND_MASK_DFS_DONE_MASK BIT(17)
  61. #define PMSU_BOOT_ADDR_REDIRECT_OFFSET(cpu) ((cpu * 0x100) + 0x124)
  62. /* PMSU fabric registers */
  63. #define L2C_NFABRIC_PM_CTL 0x4
  64. #define L2C_NFABRIC_PM_CTL_PWR_DOWN BIT(20)
  65. /* PMSU delay registers */
  66. #define PMSU_POWERDOWN_DELAY 0xF04
  67. #define PMSU_POWERDOWN_DELAY_PMU BIT(1)
  68. #define PMSU_POWERDOWN_DELAY_MASK 0xFFFE
  69. #define PMSU_DFLT_ARMADA38X_DELAY 0x64
  70. /* CA9 MPcore SoC Control registers */
  71. #define MPCORE_RESET_CTL 0x64
  72. #define MPCORE_RESET_CTL_L2 BIT(0)
  73. #define MPCORE_RESET_CTL_DEBUG BIT(16)
  74. #define SRAM_PHYS_BASE 0xFFFF0000
  75. #define BOOTROM_BASE 0xFFF00000
  76. #define BOOTROM_SIZE 0x100000
  77. #define ARMADA_370_CRYPT0_ENG_TARGET 0x9
  78. #define ARMADA_370_CRYPT0_ENG_ATTR 0x1
  79. extern void ll_disable_coherency(void);
  80. extern void ll_enable_coherency(void);
  81. extern void armada_370_xp_cpu_resume(void);
  82. extern void armada_38x_cpu_resume(void);
  83. static phys_addr_t pmsu_mp_phys_base;
  84. static void __iomem *pmsu_mp_base;
  85. static void *mvebu_cpu_resume;
  86. static const struct of_device_id of_pmsu_table[] = {
  87. { .compatible = "marvell,armada-370-pmsu", },
  88. { .compatible = "marvell,armada-370-xp-pmsu", },
  89. { .compatible = "marvell,armada-380-pmsu", },
  90. { /* end of list */ },
  91. };
  92. void mvebu_pmsu_set_cpu_boot_addr(int hw_cpu, void *boot_addr)
  93. {
  94. writel(__pa_symbol(boot_addr), pmsu_mp_base +
  95. PMSU_BOOT_ADDR_REDIRECT_OFFSET(hw_cpu));
  96. }
  97. extern unsigned char mvebu_boot_wa_start[];
  98. extern unsigned char mvebu_boot_wa_end[];
  99. /*
  100. * This function sets up the boot address workaround needed for SMP
  101. * boot on Armada 375 Z1 and cpuidle on Armada 370. It unmaps the
  102. * BootROM Mbus window, and instead remaps a crypto SRAM into which a
  103. * custom piece of code is copied to replace the problematic BootROM.
  104. */
  105. int mvebu_setup_boot_addr_wa(unsigned int crypto_eng_target,
  106. unsigned int crypto_eng_attribute,
  107. phys_addr_t resume_addr_reg)
  108. {
  109. void __iomem *sram_virt_base;
  110. u32 code_len = mvebu_boot_wa_end - mvebu_boot_wa_start;
  111. mvebu_mbus_del_window(BOOTROM_BASE, BOOTROM_SIZE);
  112. mvebu_mbus_add_window_by_id(crypto_eng_target, crypto_eng_attribute,
  113. SRAM_PHYS_BASE, SZ_64K);
  114. sram_virt_base = ioremap(SRAM_PHYS_BASE, SZ_64K);
  115. if (!sram_virt_base) {
  116. pr_err("Unable to map SRAM to setup the boot address WA\n");
  117. return -ENOMEM;
  118. }
  119. memcpy(sram_virt_base, &mvebu_boot_wa_start, code_len);
  120. /*
  121. * The last word of the code copied in SRAM must contain the
  122. * physical base address of the PMSU register. We
  123. * intentionally store this address in the native endianness
  124. * of the system.
  125. */
  126. __raw_writel((unsigned long)resume_addr_reg,
  127. sram_virt_base + code_len - 4);
  128. iounmap(sram_virt_base);
  129. return 0;
  130. }
  131. static int __init mvebu_v7_pmsu_init(void)
  132. {
  133. struct device_node *np;
  134. struct resource res;
  135. int ret = 0;
  136. np = of_find_matching_node(NULL, of_pmsu_table);
  137. if (!np)
  138. return 0;
  139. pr_info("Initializing Power Management Service Unit\n");
  140. if (of_address_to_resource(np, 0, &res)) {
  141. pr_err("unable to get resource\n");
  142. ret = -ENOENT;
  143. goto out;
  144. }
  145. if (of_device_is_compatible(np, "marvell,armada-370-xp-pmsu")) {
  146. pr_warn(FW_WARN "deprecated pmsu binding\n");
  147. res.start = res.start - PMSU_BASE_OFFSET;
  148. res.end = res.start + PMSU_REG_SIZE - 1;
  149. }
  150. if (!request_mem_region(res.start, resource_size(&res),
  151. np->full_name)) {
  152. pr_err("unable to request region\n");
  153. ret = -EBUSY;
  154. goto out;
  155. }
  156. pmsu_mp_phys_base = res.start;
  157. pmsu_mp_base = ioremap(res.start, resource_size(&res));
  158. if (!pmsu_mp_base) {
  159. pr_err("unable to map registers\n");
  160. release_mem_region(res.start, resource_size(&res));
  161. ret = -ENOMEM;
  162. goto out;
  163. }
  164. out:
  165. of_node_put(np);
  166. return ret;
  167. }
  168. static void mvebu_v7_pmsu_enable_l2_powerdown_onidle(void)
  169. {
  170. u32 reg;
  171. if (pmsu_mp_base == NULL)
  172. return;
  173. /* Enable L2 & Fabric powerdown in Deep-Idle mode - Fabric */
  174. reg = readl(pmsu_mp_base + L2C_NFABRIC_PM_CTL);
  175. reg |= L2C_NFABRIC_PM_CTL_PWR_DOWN;
  176. writel(reg, pmsu_mp_base + L2C_NFABRIC_PM_CTL);
  177. }
  178. enum pmsu_idle_prepare_flags {
  179. PMSU_PREPARE_NORMAL = 0,
  180. PMSU_PREPARE_DEEP_IDLE = BIT(0),
  181. PMSU_PREPARE_SNOOP_DISABLE = BIT(1),
  182. };
  183. /* No locking is needed because we only access per-CPU registers */
  184. static int mvebu_v7_pmsu_idle_prepare(unsigned long flags)
  185. {
  186. unsigned int hw_cpu = cpu_logical_map(smp_processor_id());
  187. u32 reg;
  188. if (pmsu_mp_base == NULL)
  189. return -EINVAL;
  190. /*
  191. * Adjust the PMSU configuration to wait for WFI signal, enable
  192. * IRQ and FIQ as wakeup events, set wait for snoop queue empty
  193. * indication and mask IRQ and FIQ from CPU
  194. */
  195. reg = readl(pmsu_mp_base + PMSU_STATUS_AND_MASK(hw_cpu));
  196. reg |= PMSU_STATUS_AND_MASK_CPU_IDLE_WAIT |
  197. PMSU_STATUS_AND_MASK_IRQ_WAKEUP |
  198. PMSU_STATUS_AND_MASK_FIQ_WAKEUP |
  199. PMSU_STATUS_AND_MASK_SNP_Q_EMPTY_WAIT |
  200. PMSU_STATUS_AND_MASK_IRQ_MASK |
  201. PMSU_STATUS_AND_MASK_FIQ_MASK;
  202. writel(reg, pmsu_mp_base + PMSU_STATUS_AND_MASK(hw_cpu));
  203. reg = readl(pmsu_mp_base + PMSU_CONTROL_AND_CONFIG(hw_cpu));
  204. /* ask HW to power down the L2 Cache if needed */
  205. if (flags & PMSU_PREPARE_DEEP_IDLE)
  206. reg |= PMSU_CONTROL_AND_CONFIG_L2_PWDDN;
  207. /* request power down */
  208. reg |= PMSU_CONTROL_AND_CONFIG_PWDDN_REQ;
  209. writel(reg, pmsu_mp_base + PMSU_CONTROL_AND_CONFIG(hw_cpu));
  210. if (flags & PMSU_PREPARE_SNOOP_DISABLE) {
  211. /* Disable snoop disable by HW - SW is taking care of it */
  212. reg = readl(pmsu_mp_base + PMSU_CPU_POWER_DOWN_CONTROL(hw_cpu));
  213. reg |= PMSU_CPU_POWER_DOWN_DIS_SNP_Q_SKIP;
  214. writel(reg, pmsu_mp_base + PMSU_CPU_POWER_DOWN_CONTROL(hw_cpu));
  215. }
  216. return 0;
  217. }
  218. int armada_370_xp_pmsu_idle_enter(unsigned long deepidle)
  219. {
  220. unsigned long flags = PMSU_PREPARE_SNOOP_DISABLE;
  221. int ret;
  222. if (deepidle)
  223. flags |= PMSU_PREPARE_DEEP_IDLE;
  224. ret = mvebu_v7_pmsu_idle_prepare(flags);
  225. if (ret)
  226. return ret;
  227. v7_exit_coherency_flush(all);
  228. ll_disable_coherency();
  229. dsb();
  230. wfi();
  231. /* If we are here, wfi failed. As processors run out of
  232. * coherency for some time, tlbs might be stale, so flush them
  233. */
  234. local_flush_tlb_all();
  235. ll_enable_coherency();
  236. /* Test the CR_C bit and set it if it was cleared */
  237. asm volatile(
  238. "mrc p15, 0, r0, c1, c0, 0 \n\t"
  239. "tst r0, %0 \n\t"
  240. "orreq r0, r0, #(1 << 2) \n\t"
  241. "mcreq p15, 0, r0, c1, c0, 0 \n\t"
  242. "isb "
  243. : : "Ir" (CR_C) : "r0");
  244. pr_debug("Failed to suspend the system\n");
  245. return 0;
  246. }
  247. static int armada_370_xp_cpu_suspend(unsigned long deepidle)
  248. {
  249. return cpu_suspend(deepidle, armada_370_xp_pmsu_idle_enter);
  250. }
  251. int armada_38x_do_cpu_suspend(unsigned long deepidle)
  252. {
  253. unsigned long flags = 0;
  254. if (deepidle)
  255. flags |= PMSU_PREPARE_DEEP_IDLE;
  256. mvebu_v7_pmsu_idle_prepare(flags);
  257. /*
  258. * Already flushed cache, but do it again as the outer cache
  259. * functions dirty the cache with spinlocks
  260. */
  261. v7_exit_coherency_flush(louis);
  262. scu_power_mode(mvebu_get_scu_base(), SCU_PM_POWEROFF);
  263. cpu_do_idle();
  264. return 1;
  265. }
  266. static int armada_38x_cpu_suspend(unsigned long deepidle)
  267. {
  268. return cpu_suspend(false, armada_38x_do_cpu_suspend);
  269. }
  270. /* No locking is needed because we only access per-CPU registers */
  271. void mvebu_v7_pmsu_idle_exit(void)
  272. {
  273. unsigned int hw_cpu = cpu_logical_map(smp_processor_id());
  274. u32 reg;
  275. if (pmsu_mp_base == NULL)
  276. return;
  277. /* cancel ask HW to power down the L2 Cache if possible */
  278. reg = readl(pmsu_mp_base + PMSU_CONTROL_AND_CONFIG(hw_cpu));
  279. reg &= ~PMSU_CONTROL_AND_CONFIG_L2_PWDDN;
  280. writel(reg, pmsu_mp_base + PMSU_CONTROL_AND_CONFIG(hw_cpu));
  281. /* cancel Enable wakeup events and mask interrupts */
  282. reg = readl(pmsu_mp_base + PMSU_STATUS_AND_MASK(hw_cpu));
  283. reg &= ~(PMSU_STATUS_AND_MASK_IRQ_WAKEUP | PMSU_STATUS_AND_MASK_FIQ_WAKEUP);
  284. reg &= ~PMSU_STATUS_AND_MASK_CPU_IDLE_WAIT;
  285. reg &= ~PMSU_STATUS_AND_MASK_SNP_Q_EMPTY_WAIT;
  286. reg &= ~(PMSU_STATUS_AND_MASK_IRQ_MASK | PMSU_STATUS_AND_MASK_FIQ_MASK);
  287. writel(reg, pmsu_mp_base + PMSU_STATUS_AND_MASK(hw_cpu));
  288. }
  289. static int mvebu_v7_cpu_pm_notify(struct notifier_block *self,
  290. unsigned long action, void *hcpu)
  291. {
  292. if (action == CPU_PM_ENTER) {
  293. unsigned int hw_cpu = cpu_logical_map(smp_processor_id());
  294. mvebu_pmsu_set_cpu_boot_addr(hw_cpu, mvebu_cpu_resume);
  295. } else if (action == CPU_PM_EXIT) {
  296. mvebu_v7_pmsu_idle_exit();
  297. }
  298. return NOTIFY_OK;
  299. }
  300. static struct notifier_block mvebu_v7_cpu_pm_notifier = {
  301. .notifier_call = mvebu_v7_cpu_pm_notify,
  302. };
  303. static struct platform_device mvebu_v7_cpuidle_device;
  304. static int broken_idle(struct device_node *np)
  305. {
  306. if (of_property_read_bool(np, "broken-idle")) {
  307. pr_warn("CPU idle is currently broken: disabling\n");
  308. return 1;
  309. }
  310. return 0;
  311. }
  312. static __init int armada_370_cpuidle_init(void)
  313. {
  314. struct device_node *np;
  315. phys_addr_t redirect_reg;
  316. np = of_find_compatible_node(NULL, NULL, "marvell,coherency-fabric");
  317. if (!np)
  318. return -ENODEV;
  319. if (broken_idle(np))
  320. goto end;
  321. /*
  322. * On Armada 370, there is "a slow exit process from the deep
  323. * idle state due to heavy L1/L2 cache cleanup operations
  324. * performed by the BootROM software". To avoid this, we
  325. * replace the restart code of the bootrom by a a simple jump
  326. * to the boot address. Then the code located at this boot
  327. * address will take care of the initialization.
  328. */
  329. redirect_reg = pmsu_mp_phys_base + PMSU_BOOT_ADDR_REDIRECT_OFFSET(0);
  330. mvebu_setup_boot_addr_wa(ARMADA_370_CRYPT0_ENG_TARGET,
  331. ARMADA_370_CRYPT0_ENG_ATTR,
  332. redirect_reg);
  333. mvebu_cpu_resume = armada_370_xp_cpu_resume;
  334. mvebu_v7_cpuidle_device.dev.platform_data = armada_370_xp_cpu_suspend;
  335. mvebu_v7_cpuidle_device.name = "cpuidle-armada-370";
  336. end:
  337. of_node_put(np);
  338. return 0;
  339. }
  340. static __init int armada_38x_cpuidle_init(void)
  341. {
  342. struct device_node *np;
  343. void __iomem *mpsoc_base;
  344. u32 reg;
  345. pr_warn("CPU idle is currently broken on Armada 38x: disabling\n");
  346. return 0;
  347. np = of_find_compatible_node(NULL, NULL,
  348. "marvell,armada-380-coherency-fabric");
  349. if (!np)
  350. return -ENODEV;
  351. if (broken_idle(np))
  352. goto end;
  353. of_node_put(np);
  354. np = of_find_compatible_node(NULL, NULL,
  355. "marvell,armada-380-mpcore-soc-ctrl");
  356. if (!np)
  357. return -ENODEV;
  358. mpsoc_base = of_iomap(np, 0);
  359. BUG_ON(!mpsoc_base);
  360. /* Set up reset mask when powering down the cpus */
  361. reg = readl(mpsoc_base + MPCORE_RESET_CTL);
  362. reg |= MPCORE_RESET_CTL_L2;
  363. reg |= MPCORE_RESET_CTL_DEBUG;
  364. writel(reg, mpsoc_base + MPCORE_RESET_CTL);
  365. iounmap(mpsoc_base);
  366. /* Set up delay */
  367. reg = readl(pmsu_mp_base + PMSU_POWERDOWN_DELAY);
  368. reg &= ~PMSU_POWERDOWN_DELAY_MASK;
  369. reg |= PMSU_DFLT_ARMADA38X_DELAY;
  370. reg |= PMSU_POWERDOWN_DELAY_PMU;
  371. writel(reg, pmsu_mp_base + PMSU_POWERDOWN_DELAY);
  372. mvebu_cpu_resume = armada_38x_cpu_resume;
  373. mvebu_v7_cpuidle_device.dev.platform_data = armada_38x_cpu_suspend;
  374. mvebu_v7_cpuidle_device.name = "cpuidle-armada-38x";
  375. end:
  376. of_node_put(np);
  377. return 0;
  378. }
  379. static __init int armada_xp_cpuidle_init(void)
  380. {
  381. struct device_node *np;
  382. np = of_find_compatible_node(NULL, NULL, "marvell,coherency-fabric");
  383. if (!np)
  384. return -ENODEV;
  385. if (broken_idle(np))
  386. goto end;
  387. mvebu_cpu_resume = armada_370_xp_cpu_resume;
  388. mvebu_v7_cpuidle_device.dev.platform_data = armada_370_xp_cpu_suspend;
  389. mvebu_v7_cpuidle_device.name = "cpuidle-armada-xp";
  390. end:
  391. of_node_put(np);
  392. return 0;
  393. }
  394. static int __init mvebu_v7_cpu_pm_init(void)
  395. {
  396. struct device_node *np;
  397. int ret;
  398. np = of_find_matching_node(NULL, of_pmsu_table);
  399. if (!np)
  400. return 0;
  401. of_node_put(np);
  402. /*
  403. * Currently the CPU idle support for Armada 38x is broken, as
  404. * the CPU hotplug uses some of the CPU idle functions it is
  405. * broken too, so let's disable it
  406. */
  407. if (of_machine_is_compatible("marvell,armada380")) {
  408. cpu_hotplug_disable();
  409. pr_warn("CPU hotplug support is currently broken on Armada 38x: disabling\n");
  410. }
  411. if (of_machine_is_compatible("marvell,armadaxp"))
  412. ret = armada_xp_cpuidle_init();
  413. else if (of_machine_is_compatible("marvell,armada370"))
  414. ret = armada_370_cpuidle_init();
  415. else if (of_machine_is_compatible("marvell,armada380"))
  416. ret = armada_38x_cpuidle_init();
  417. else
  418. return 0;
  419. if (ret)
  420. return ret;
  421. mvebu_v7_pmsu_enable_l2_powerdown_onidle();
  422. if (mvebu_v7_cpuidle_device.name)
  423. platform_device_register(&mvebu_v7_cpuidle_device);
  424. cpu_pm_register_notifier(&mvebu_v7_cpu_pm_notifier);
  425. return 0;
  426. }
  427. arch_initcall(mvebu_v7_cpu_pm_init);
  428. early_initcall(mvebu_v7_pmsu_init);
  429. static void mvebu_pmsu_dfs_request_local(void *data)
  430. {
  431. u32 reg;
  432. u32 cpu = smp_processor_id();
  433. unsigned long flags;
  434. local_irq_save(flags);
  435. /* Prepare to enter idle */
  436. reg = readl(pmsu_mp_base + PMSU_STATUS_AND_MASK(cpu));
  437. reg |= PMSU_STATUS_AND_MASK_CPU_IDLE_WAIT |
  438. PMSU_STATUS_AND_MASK_IRQ_MASK |
  439. PMSU_STATUS_AND_MASK_FIQ_MASK;
  440. writel(reg, pmsu_mp_base + PMSU_STATUS_AND_MASK(cpu));
  441. /* Request the DFS transition */
  442. reg = readl(pmsu_mp_base + PMSU_CONTROL_AND_CONFIG(cpu));
  443. reg |= PMSU_CONTROL_AND_CONFIG_DFS_REQ;
  444. writel(reg, pmsu_mp_base + PMSU_CONTROL_AND_CONFIG(cpu));
  445. /* The fact of entering idle will trigger the DFS transition */
  446. wfi();
  447. /*
  448. * We're back from idle, the DFS transition has completed,
  449. * clear the idle wait indication.
  450. */
  451. reg = readl(pmsu_mp_base + PMSU_STATUS_AND_MASK(cpu));
  452. reg &= ~PMSU_STATUS_AND_MASK_CPU_IDLE_WAIT;
  453. writel(reg, pmsu_mp_base + PMSU_STATUS_AND_MASK(cpu));
  454. local_irq_restore(flags);
  455. }
  456. int mvebu_pmsu_dfs_request(int cpu)
  457. {
  458. unsigned long timeout;
  459. int hwcpu = cpu_logical_map(cpu);
  460. u32 reg;
  461. /* Clear any previous DFS DONE event */
  462. reg = readl(pmsu_mp_base + PMSU_EVENT_STATUS_AND_MASK(hwcpu));
  463. reg &= ~PMSU_EVENT_STATUS_AND_MASK_DFS_DONE;
  464. writel(reg, pmsu_mp_base + PMSU_EVENT_STATUS_AND_MASK(hwcpu));
  465. /* Mask the DFS done interrupt, since we are going to poll */
  466. reg = readl(pmsu_mp_base + PMSU_EVENT_STATUS_AND_MASK(hwcpu));
  467. reg |= PMSU_EVENT_STATUS_AND_MASK_DFS_DONE_MASK;
  468. writel(reg, pmsu_mp_base + PMSU_EVENT_STATUS_AND_MASK(hwcpu));
  469. /* Trigger the DFS on the appropriate CPU */
  470. smp_call_function_single(cpu, mvebu_pmsu_dfs_request_local,
  471. NULL, false);
  472. /* Poll until the DFS done event is generated */
  473. timeout = jiffies + HZ;
  474. while (time_before(jiffies, timeout)) {
  475. reg = readl(pmsu_mp_base + PMSU_EVENT_STATUS_AND_MASK(hwcpu));
  476. if (reg & PMSU_EVENT_STATUS_AND_MASK_DFS_DONE)
  477. break;
  478. udelay(10);
  479. }
  480. if (time_after(jiffies, timeout))
  481. return -ETIME;
  482. /* Restore the DFS mask to its original state */
  483. reg = readl(pmsu_mp_base + PMSU_EVENT_STATUS_AND_MASK(hwcpu));
  484. reg &= ~PMSU_EVENT_STATUS_AND_MASK_DFS_DONE_MASK;
  485. writel(reg, pmsu_mp_base + PMSU_EVENT_STATUS_AND_MASK(hwcpu));
  486. return 0;
  487. }