suspend.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
  4. // http://www.samsung.com
  5. //
  6. // Exynos - Suspend support
  7. //
  8. // Based on arch/arm/mach-s3c2410/pm.c
  9. // Copyright (c) 2006 Simtec Electronics
  10. // Ben Dooks <[email protected]>
  11. #include <linux/init.h>
  12. #include <linux/suspend.h>
  13. #include <linux/syscore_ops.h>
  14. #include <linux/cpu_pm.h>
  15. #include <linux/io.h>
  16. #include <linux/irq.h>
  17. #include <linux/irqchip.h>
  18. #include <linux/irqdomain.h>
  19. #include <linux/of_address.h>
  20. #include <linux/err.h>
  21. #include <linux/regulator/machine.h>
  22. #include <linux/soc/samsung/exynos-pmu.h>
  23. #include <linux/soc/samsung/exynos-regs-pmu.h>
  24. #include <asm/cacheflush.h>
  25. #include <asm/hardware/cache-l2x0.h>
  26. #include <asm/firmware.h>
  27. #include <asm/mcpm.h>
  28. #include <asm/smp_scu.h>
  29. #include <asm/suspend.h>
  30. #include "common.h"
  31. #include "smc.h"
  32. #define REG_TABLE_END (-1U)
  33. #define EXYNOS5420_CPU_STATE 0x28
  34. /**
  35. * struct exynos_wkup_irq - PMU IRQ to mask mapping
  36. * @hwirq: Hardware IRQ signal of the PMU
  37. * @mask: Mask in PMU wake-up mask register
  38. */
  39. struct exynos_wkup_irq {
  40. unsigned int hwirq;
  41. u32 mask;
  42. };
  43. struct exynos_pm_data {
  44. const struct exynos_wkup_irq *wkup_irq;
  45. unsigned int wake_disable_mask;
  46. void (*pm_prepare)(void);
  47. void (*pm_resume_prepare)(void);
  48. void (*pm_resume)(void);
  49. int (*pm_suspend)(void);
  50. int (*cpu_suspend)(unsigned long);
  51. };
  52. /* Used only on Exynos542x/5800 */
  53. struct exynos_pm_state {
  54. int cpu_state;
  55. unsigned int pmu_spare3;
  56. void __iomem *sysram_base;
  57. phys_addr_t sysram_phys;
  58. bool secure_firmware;
  59. };
  60. static const struct exynos_pm_data *pm_data __ro_after_init;
  61. static struct exynos_pm_state pm_state;
  62. /*
  63. * GIC wake-up support
  64. */
  65. static u32 exynos_irqwake_intmask = 0xffffffff;
  66. static const struct exynos_wkup_irq exynos3250_wkup_irq[] = {
  67. { 73, BIT(1) }, /* RTC alarm */
  68. { 74, BIT(2) }, /* RTC tick */
  69. { /* sentinel */ },
  70. };
  71. static const struct exynos_wkup_irq exynos4_wkup_irq[] = {
  72. { 44, BIT(1) }, /* RTC alarm */
  73. { 45, BIT(2) }, /* RTC tick */
  74. { /* sentinel */ },
  75. };
  76. static const struct exynos_wkup_irq exynos5250_wkup_irq[] = {
  77. { 43, BIT(1) }, /* RTC alarm */
  78. { 44, BIT(2) }, /* RTC tick */
  79. { /* sentinel */ },
  80. };
  81. static u32 exynos_read_eint_wakeup_mask(void)
  82. {
  83. return pmu_raw_readl(EXYNOS_EINT_WAKEUP_MASK);
  84. }
  85. static int exynos_irq_set_wake(struct irq_data *data, unsigned int state)
  86. {
  87. const struct exynos_wkup_irq *wkup_irq;
  88. if (!pm_data->wkup_irq)
  89. return -ENOENT;
  90. wkup_irq = pm_data->wkup_irq;
  91. while (wkup_irq->mask) {
  92. if (wkup_irq->hwirq == data->hwirq) {
  93. if (!state)
  94. exynos_irqwake_intmask |= wkup_irq->mask;
  95. else
  96. exynos_irqwake_intmask &= ~wkup_irq->mask;
  97. return 0;
  98. }
  99. ++wkup_irq;
  100. }
  101. return -ENOENT;
  102. }
  103. static struct irq_chip exynos_pmu_chip = {
  104. .name = "PMU",
  105. .irq_eoi = irq_chip_eoi_parent,
  106. .irq_mask = irq_chip_mask_parent,
  107. .irq_unmask = irq_chip_unmask_parent,
  108. .irq_retrigger = irq_chip_retrigger_hierarchy,
  109. .irq_set_wake = exynos_irq_set_wake,
  110. #ifdef CONFIG_SMP
  111. .irq_set_affinity = irq_chip_set_affinity_parent,
  112. #endif
  113. };
  114. static int exynos_pmu_domain_translate(struct irq_domain *d,
  115. struct irq_fwspec *fwspec,
  116. unsigned long *hwirq,
  117. unsigned int *type)
  118. {
  119. if (is_of_node(fwspec->fwnode)) {
  120. if (fwspec->param_count != 3)
  121. return -EINVAL;
  122. /* No PPI should point to this domain */
  123. if (fwspec->param[0] != 0)
  124. return -EINVAL;
  125. *hwirq = fwspec->param[1];
  126. *type = fwspec->param[2];
  127. return 0;
  128. }
  129. return -EINVAL;
  130. }
  131. static int exynos_pmu_domain_alloc(struct irq_domain *domain,
  132. unsigned int virq,
  133. unsigned int nr_irqs, void *data)
  134. {
  135. struct irq_fwspec *fwspec = data;
  136. struct irq_fwspec parent_fwspec;
  137. irq_hw_number_t hwirq;
  138. int i;
  139. if (fwspec->param_count != 3)
  140. return -EINVAL; /* Not GIC compliant */
  141. if (fwspec->param[0] != 0)
  142. return -EINVAL; /* No PPI should point to this domain */
  143. hwirq = fwspec->param[1];
  144. for (i = 0; i < nr_irqs; i++)
  145. irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
  146. &exynos_pmu_chip, NULL);
  147. parent_fwspec = *fwspec;
  148. parent_fwspec.fwnode = domain->parent->fwnode;
  149. return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs,
  150. &parent_fwspec);
  151. }
  152. static const struct irq_domain_ops exynos_pmu_domain_ops = {
  153. .translate = exynos_pmu_domain_translate,
  154. .alloc = exynos_pmu_domain_alloc,
  155. .free = irq_domain_free_irqs_common,
  156. };
  157. static int __init exynos_pmu_irq_init(struct device_node *node,
  158. struct device_node *parent)
  159. {
  160. struct irq_domain *parent_domain, *domain;
  161. if (!parent) {
  162. pr_err("%pOF: no parent, giving up\n", node);
  163. return -ENODEV;
  164. }
  165. parent_domain = irq_find_host(parent);
  166. if (!parent_domain) {
  167. pr_err("%pOF: unable to obtain parent domain\n", node);
  168. return -ENXIO;
  169. }
  170. pmu_base_addr = of_iomap(node, 0);
  171. if (!pmu_base_addr) {
  172. pr_err("%pOF: failed to find exynos pmu register\n", node);
  173. return -ENOMEM;
  174. }
  175. domain = irq_domain_add_hierarchy(parent_domain, 0, 0,
  176. node, &exynos_pmu_domain_ops,
  177. NULL);
  178. if (!domain) {
  179. iounmap(pmu_base_addr);
  180. pmu_base_addr = NULL;
  181. return -ENOMEM;
  182. }
  183. /*
  184. * Clear the OF_POPULATED flag set in of_irq_init so that
  185. * later the Exynos PMU platform device won't be skipped.
  186. */
  187. of_node_clear_flag(node, OF_POPULATED);
  188. return 0;
  189. }
  190. #define EXYNOS_PMU_IRQ(symbol, name) IRQCHIP_DECLARE(symbol, name, exynos_pmu_irq_init)
  191. EXYNOS_PMU_IRQ(exynos3250_pmu_irq, "samsung,exynos3250-pmu");
  192. EXYNOS_PMU_IRQ(exynos4210_pmu_irq, "samsung,exynos4210-pmu");
  193. EXYNOS_PMU_IRQ(exynos4412_pmu_irq, "samsung,exynos4412-pmu");
  194. EXYNOS_PMU_IRQ(exynos5250_pmu_irq, "samsung,exynos5250-pmu");
  195. EXYNOS_PMU_IRQ(exynos5420_pmu_irq, "samsung,exynos5420-pmu");
  196. static int exynos_cpu_do_idle(void)
  197. {
  198. /* issue the standby signal into the pm unit. */
  199. cpu_do_idle();
  200. pr_info("Failed to suspend the system\n");
  201. return 1; /* Aborting suspend */
  202. }
  203. static void exynos_flush_cache_all(void)
  204. {
  205. flush_cache_all();
  206. outer_flush_all();
  207. }
  208. static int exynos_cpu_suspend(unsigned long arg)
  209. {
  210. exynos_flush_cache_all();
  211. return exynos_cpu_do_idle();
  212. }
  213. static int exynos3250_cpu_suspend(unsigned long arg)
  214. {
  215. flush_cache_all();
  216. return exynos_cpu_do_idle();
  217. }
  218. static int exynos5420_cpu_suspend(unsigned long arg)
  219. {
  220. /* MCPM works with HW CPU identifiers */
  221. unsigned int mpidr = read_cpuid_mpidr();
  222. unsigned int cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  223. unsigned int cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  224. if (IS_ENABLED(CONFIG_EXYNOS_MCPM)) {
  225. mcpm_set_entry_vector(cpu, cluster, exynos_cpu_resume);
  226. mcpm_cpu_suspend();
  227. }
  228. pr_info("Failed to suspend the system\n");
  229. /* return value != 0 means failure */
  230. return 1;
  231. }
  232. static void exynos_pm_set_wakeup_mask(void)
  233. {
  234. /*
  235. * Set wake-up mask registers
  236. * EXYNOS_EINT_WAKEUP_MASK is set by pinctrl driver in late suspend.
  237. */
  238. pmu_raw_writel(exynos_irqwake_intmask & ~BIT(31), S5P_WAKEUP_MASK);
  239. }
  240. static void exynos_pm_enter_sleep_mode(void)
  241. {
  242. /* Set value of power down register for sleep mode */
  243. exynos_sys_powerdown_conf(SYS_SLEEP);
  244. pmu_raw_writel(EXYNOS_SLEEP_MAGIC, S5P_INFORM1);
  245. }
  246. static void exynos_pm_prepare(void)
  247. {
  248. exynos_set_delayed_reset_assertion(false);
  249. /* Set wake-up mask registers */
  250. exynos_pm_set_wakeup_mask();
  251. exynos_pm_enter_sleep_mode();
  252. /* ensure at least INFORM0 has the resume address */
  253. pmu_raw_writel(__pa_symbol(exynos_cpu_resume), S5P_INFORM0);
  254. }
  255. static void exynos3250_pm_prepare(void)
  256. {
  257. unsigned int tmp;
  258. /* Set wake-up mask registers */
  259. exynos_pm_set_wakeup_mask();
  260. tmp = pmu_raw_readl(EXYNOS3_ARM_L2_OPTION);
  261. tmp &= ~EXYNOS5_OPTION_USE_RETENTION;
  262. pmu_raw_writel(tmp, EXYNOS3_ARM_L2_OPTION);
  263. exynos_pm_enter_sleep_mode();
  264. /* ensure at least INFORM0 has the resume address */
  265. pmu_raw_writel(__pa_symbol(exynos_cpu_resume), S5P_INFORM0);
  266. }
  267. static void exynos5420_pm_prepare(void)
  268. {
  269. unsigned int tmp;
  270. /* Set wake-up mask registers */
  271. exynos_pm_set_wakeup_mask();
  272. pm_state.pmu_spare3 = pmu_raw_readl(S5P_PMU_SPARE3);
  273. /*
  274. * The cpu state needs to be saved and restored so that the
  275. * secondary CPUs will enter low power start. Though the U-Boot
  276. * is setting the cpu state with low power flag, the kernel
  277. * needs to restore it back in case, the primary cpu fails to
  278. * suspend for any reason.
  279. */
  280. pm_state.cpu_state = readl_relaxed(pm_state.sysram_base +
  281. EXYNOS5420_CPU_STATE);
  282. writel_relaxed(0x0, pm_state.sysram_base + EXYNOS5420_CPU_STATE);
  283. if (pm_state.secure_firmware)
  284. exynos_smc(SMC_CMD_REG, SMC_REG_ID_SFR_W(pm_state.sysram_phys +
  285. EXYNOS5420_CPU_STATE),
  286. 0, 0);
  287. exynos_pm_enter_sleep_mode();
  288. /* ensure at least INFORM0 has the resume address */
  289. if (IS_ENABLED(CONFIG_EXYNOS_MCPM))
  290. pmu_raw_writel(__pa_symbol(mcpm_entry_point), S5P_INFORM0);
  291. tmp = pmu_raw_readl(EXYNOS_L2_OPTION(0));
  292. tmp &= ~EXYNOS_L2_USE_RETENTION;
  293. pmu_raw_writel(tmp, EXYNOS_L2_OPTION(0));
  294. tmp = pmu_raw_readl(EXYNOS5420_SFR_AXI_CGDIS1);
  295. tmp |= EXYNOS5420_UFS;
  296. pmu_raw_writel(tmp, EXYNOS5420_SFR_AXI_CGDIS1);
  297. tmp = pmu_raw_readl(EXYNOS5420_ARM_COMMON_OPTION);
  298. tmp &= ~EXYNOS5420_L2RSTDISABLE_VALUE;
  299. pmu_raw_writel(tmp, EXYNOS5420_ARM_COMMON_OPTION);
  300. tmp = pmu_raw_readl(EXYNOS5420_FSYS2_OPTION);
  301. tmp |= EXYNOS5420_EMULATION;
  302. pmu_raw_writel(tmp, EXYNOS5420_FSYS2_OPTION);
  303. tmp = pmu_raw_readl(EXYNOS5420_PSGEN_OPTION);
  304. tmp |= EXYNOS5420_EMULATION;
  305. pmu_raw_writel(tmp, EXYNOS5420_PSGEN_OPTION);
  306. }
  307. static int exynos_pm_suspend(void)
  308. {
  309. exynos_pm_central_suspend();
  310. /* Setting SEQ_OPTION register */
  311. pmu_raw_writel(S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0,
  312. S5P_CENTRAL_SEQ_OPTION);
  313. if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
  314. exynos_cpu_save_register();
  315. return 0;
  316. }
  317. static int exynos5420_pm_suspend(void)
  318. {
  319. u32 this_cluster;
  320. exynos_pm_central_suspend();
  321. /* Setting SEQ_OPTION register */
  322. this_cluster = MPIDR_AFFINITY_LEVEL(read_cpuid_mpidr(), 1);
  323. if (!this_cluster)
  324. pmu_raw_writel(EXYNOS5420_ARM_USE_STANDBY_WFI0,
  325. S5P_CENTRAL_SEQ_OPTION);
  326. else
  327. pmu_raw_writel(EXYNOS5420_KFC_USE_STANDBY_WFI0,
  328. S5P_CENTRAL_SEQ_OPTION);
  329. return 0;
  330. }
  331. static void exynos_pm_resume(void)
  332. {
  333. u32 cpuid = read_cpuid_part();
  334. if (exynos_pm_central_resume())
  335. goto early_wakeup;
  336. if (cpuid == ARM_CPU_PART_CORTEX_A9)
  337. exynos_scu_enable();
  338. if (call_firmware_op(resume) == -ENOSYS
  339. && cpuid == ARM_CPU_PART_CORTEX_A9)
  340. exynos_cpu_restore_register();
  341. early_wakeup:
  342. /* Clear SLEEP mode set in INFORM1 */
  343. pmu_raw_writel(0x0, S5P_INFORM1);
  344. exynos_set_delayed_reset_assertion(true);
  345. }
  346. static void exynos3250_pm_resume(void)
  347. {
  348. u32 cpuid = read_cpuid_part();
  349. if (exynos_pm_central_resume())
  350. goto early_wakeup;
  351. pmu_raw_writel(S5P_USE_STANDBY_WFI_ALL, S5P_CENTRAL_SEQ_OPTION);
  352. if (call_firmware_op(resume) == -ENOSYS
  353. && cpuid == ARM_CPU_PART_CORTEX_A9)
  354. exynos_cpu_restore_register();
  355. early_wakeup:
  356. /* Clear SLEEP mode set in INFORM1 */
  357. pmu_raw_writel(0x0, S5P_INFORM1);
  358. }
  359. static void exynos5420_prepare_pm_resume(void)
  360. {
  361. unsigned int mpidr, cluster;
  362. mpidr = read_cpuid_mpidr();
  363. cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  364. if (IS_ENABLED(CONFIG_EXYNOS_MCPM))
  365. WARN_ON(mcpm_cpu_powered_up());
  366. if (IS_ENABLED(CONFIG_HW_PERF_EVENTS) && cluster != 0) {
  367. /*
  368. * When system is resumed on the LITTLE/KFC core (cluster 1),
  369. * the DSCR is not properly updated until the power is turned
  370. * on also for the cluster 0. Enable it for a while to
  371. * propagate the SPNIDEN and SPIDEN signals from Secure JTAG
  372. * block and avoid undefined instruction issue on CP14 reset.
  373. */
  374. pmu_raw_writel(S5P_CORE_LOCAL_PWR_EN,
  375. EXYNOS_COMMON_CONFIGURATION(0));
  376. pmu_raw_writel(0,
  377. EXYNOS_COMMON_CONFIGURATION(0));
  378. }
  379. }
  380. static void exynos5420_pm_resume(void)
  381. {
  382. unsigned long tmp;
  383. /* Restore the CPU0 low power state register */
  384. tmp = pmu_raw_readl(EXYNOS5_ARM_CORE0_SYS_PWR_REG);
  385. pmu_raw_writel(tmp | S5P_CORE_LOCAL_PWR_EN,
  386. EXYNOS5_ARM_CORE0_SYS_PWR_REG);
  387. /* Restore the sysram cpu state register */
  388. writel_relaxed(pm_state.cpu_state,
  389. pm_state.sysram_base + EXYNOS5420_CPU_STATE);
  390. if (pm_state.secure_firmware)
  391. exynos_smc(SMC_CMD_REG,
  392. SMC_REG_ID_SFR_W(pm_state.sysram_phys +
  393. EXYNOS5420_CPU_STATE),
  394. EXYNOS_AFTR_MAGIC, 0);
  395. pmu_raw_writel(EXYNOS5420_USE_STANDBY_WFI_ALL,
  396. S5P_CENTRAL_SEQ_OPTION);
  397. if (exynos_pm_central_resume())
  398. goto early_wakeup;
  399. pmu_raw_writel(pm_state.pmu_spare3, S5P_PMU_SPARE3);
  400. early_wakeup:
  401. tmp = pmu_raw_readl(EXYNOS5420_SFR_AXI_CGDIS1);
  402. tmp &= ~EXYNOS5420_UFS;
  403. pmu_raw_writel(tmp, EXYNOS5420_SFR_AXI_CGDIS1);
  404. tmp = pmu_raw_readl(EXYNOS5420_FSYS2_OPTION);
  405. tmp &= ~EXYNOS5420_EMULATION;
  406. pmu_raw_writel(tmp, EXYNOS5420_FSYS2_OPTION);
  407. tmp = pmu_raw_readl(EXYNOS5420_PSGEN_OPTION);
  408. tmp &= ~EXYNOS5420_EMULATION;
  409. pmu_raw_writel(tmp, EXYNOS5420_PSGEN_OPTION);
  410. /* Clear SLEEP mode set in INFORM1 */
  411. pmu_raw_writel(0x0, S5P_INFORM1);
  412. }
  413. /*
  414. * Suspend Ops
  415. */
  416. static int exynos_suspend_enter(suspend_state_t state)
  417. {
  418. u32 eint_wakeup_mask = exynos_read_eint_wakeup_mask();
  419. int ret;
  420. pr_debug("%s: suspending the system...\n", __func__);
  421. pr_debug("%s: wakeup masks: %08x,%08x\n", __func__,
  422. exynos_irqwake_intmask, eint_wakeup_mask);
  423. if (exynos_irqwake_intmask == -1U
  424. && eint_wakeup_mask == EXYNOS_EINT_WAKEUP_MASK_DISABLED) {
  425. pr_err("%s: No wake-up sources!\n", __func__);
  426. pr_err("%s: Aborting sleep\n", __func__);
  427. return -EINVAL;
  428. }
  429. if (pm_data->pm_prepare)
  430. pm_data->pm_prepare();
  431. flush_cache_all();
  432. ret = call_firmware_op(suspend);
  433. if (ret == -ENOSYS)
  434. ret = cpu_suspend(0, pm_data->cpu_suspend);
  435. if (ret)
  436. return ret;
  437. if (pm_data->pm_resume_prepare)
  438. pm_data->pm_resume_prepare();
  439. pr_debug("%s: wakeup stat: %08x\n", __func__,
  440. pmu_raw_readl(S5P_WAKEUP_STAT));
  441. pr_debug("%s: resuming the system...\n", __func__);
  442. return 0;
  443. }
  444. static int exynos_suspend_prepare(void)
  445. {
  446. int ret;
  447. /*
  448. * REVISIT: It would be better if struct platform_suspend_ops
  449. * .prepare handler get the suspend_state_t as a parameter to
  450. * avoid hard-coding the suspend to mem state. It's safe to do
  451. * it now only because the suspend_valid_only_mem function is
  452. * used as the .valid callback used to check if a given state
  453. * is supported by the platform anyways.
  454. */
  455. ret = regulator_suspend_prepare(PM_SUSPEND_MEM);
  456. if (ret) {
  457. pr_err("Failed to prepare regulators for suspend (%d)\n", ret);
  458. return ret;
  459. }
  460. return 0;
  461. }
  462. static void exynos_suspend_finish(void)
  463. {
  464. int ret;
  465. ret = regulator_suspend_finish();
  466. if (ret)
  467. pr_warn("Failed to resume regulators from suspend (%d)\n", ret);
  468. }
  469. static const struct platform_suspend_ops exynos_suspend_ops = {
  470. .enter = exynos_suspend_enter,
  471. .prepare = exynos_suspend_prepare,
  472. .finish = exynos_suspend_finish,
  473. .valid = suspend_valid_only_mem,
  474. };
  475. static const struct exynos_pm_data exynos3250_pm_data = {
  476. .wkup_irq = exynos3250_wkup_irq,
  477. .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)),
  478. .pm_suspend = exynos_pm_suspend,
  479. .pm_resume = exynos3250_pm_resume,
  480. .pm_prepare = exynos3250_pm_prepare,
  481. .cpu_suspend = exynos3250_cpu_suspend,
  482. };
  483. static const struct exynos_pm_data exynos4_pm_data = {
  484. .wkup_irq = exynos4_wkup_irq,
  485. .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)),
  486. .pm_suspend = exynos_pm_suspend,
  487. .pm_resume = exynos_pm_resume,
  488. .pm_prepare = exynos_pm_prepare,
  489. .cpu_suspend = exynos_cpu_suspend,
  490. };
  491. static const struct exynos_pm_data exynos5250_pm_data = {
  492. .wkup_irq = exynos5250_wkup_irq,
  493. .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)),
  494. .pm_suspend = exynos_pm_suspend,
  495. .pm_resume = exynos_pm_resume,
  496. .pm_prepare = exynos_pm_prepare,
  497. .cpu_suspend = exynos_cpu_suspend,
  498. };
  499. static const struct exynos_pm_data exynos5420_pm_data = {
  500. .wkup_irq = exynos5250_wkup_irq,
  501. .wake_disable_mask = (0x7F << 7) | (0x1F << 1),
  502. .pm_resume_prepare = exynos5420_prepare_pm_resume,
  503. .pm_resume = exynos5420_pm_resume,
  504. .pm_suspend = exynos5420_pm_suspend,
  505. .pm_prepare = exynos5420_pm_prepare,
  506. .cpu_suspend = exynos5420_cpu_suspend,
  507. };
  508. static const struct of_device_id exynos_pmu_of_device_ids[] __initconst = {
  509. {
  510. .compatible = "samsung,exynos3250-pmu",
  511. .data = &exynos3250_pm_data,
  512. }, {
  513. .compatible = "samsung,exynos4210-pmu",
  514. .data = &exynos4_pm_data,
  515. }, {
  516. .compatible = "samsung,exynos4412-pmu",
  517. .data = &exynos4_pm_data,
  518. }, {
  519. .compatible = "samsung,exynos5250-pmu",
  520. .data = &exynos5250_pm_data,
  521. }, {
  522. .compatible = "samsung,exynos5420-pmu",
  523. .data = &exynos5420_pm_data,
  524. },
  525. { /*sentinel*/ },
  526. };
  527. static struct syscore_ops exynos_pm_syscore_ops;
  528. void __init exynos_pm_init(void)
  529. {
  530. const struct of_device_id *match;
  531. struct device_node *np;
  532. u32 tmp;
  533. np = of_find_matching_node_and_match(NULL, exynos_pmu_of_device_ids, &match);
  534. if (!np) {
  535. pr_err("Failed to find PMU node\n");
  536. return;
  537. }
  538. if (WARN_ON(!of_find_property(np, "interrupt-controller", NULL))) {
  539. pr_warn("Outdated DT detected, suspend/resume will NOT work\n");
  540. of_node_put(np);
  541. return;
  542. }
  543. of_node_put(np);
  544. pm_data = (const struct exynos_pm_data *) match->data;
  545. /* All wakeup disable */
  546. tmp = pmu_raw_readl(S5P_WAKEUP_MASK);
  547. tmp |= pm_data->wake_disable_mask;
  548. pmu_raw_writel(tmp, S5P_WAKEUP_MASK);
  549. exynos_pm_syscore_ops.suspend = pm_data->pm_suspend;
  550. exynos_pm_syscore_ops.resume = pm_data->pm_resume;
  551. register_syscore_ops(&exynos_pm_syscore_ops);
  552. suspend_set_ops(&exynos_suspend_ops);
  553. /*
  554. * Applicable as of now only to Exynos542x. If booted under secure
  555. * firmware, the non-secure region of sysram should be used.
  556. */
  557. if (exynos_secure_firmware_available()) {
  558. pm_state.sysram_phys = sysram_base_phys;
  559. pm_state.sysram_base = sysram_ns_base_addr;
  560. pm_state.secure_firmware = true;
  561. } else {
  562. pm_state.sysram_base = sysram_base_addr;
  563. }
  564. }