suspend.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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 <ben@simtec.co.uk>
  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(exynos4212_pmu_irq, "samsung,exynos4212-pmu");
  194. EXYNOS_PMU_IRQ(exynos4412_pmu_irq, "samsung,exynos4412-pmu");
  195. EXYNOS_PMU_IRQ(exynos5250_pmu_irq, "samsung,exynos5250-pmu");
  196. EXYNOS_PMU_IRQ(exynos5420_pmu_irq, "samsung,exynos5420-pmu");
  197. static int exynos_cpu_do_idle(void)
  198. {
  199. /* issue the standby signal into the pm unit. */
  200. cpu_do_idle();
  201. pr_info("Failed to suspend the system\n");
  202. return 1; /* Aborting suspend */
  203. }
  204. static void exynos_flush_cache_all(void)
  205. {
  206. flush_cache_all();
  207. outer_flush_all();
  208. }
  209. static int exynos_cpu_suspend(unsigned long arg)
  210. {
  211. exynos_flush_cache_all();
  212. return exynos_cpu_do_idle();
  213. }
  214. static int exynos3250_cpu_suspend(unsigned long arg)
  215. {
  216. flush_cache_all();
  217. return exynos_cpu_do_idle();
  218. }
  219. static int exynos5420_cpu_suspend(unsigned long arg)
  220. {
  221. /* MCPM works with HW CPU identifiers */
  222. unsigned int mpidr = read_cpuid_mpidr();
  223. unsigned int cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  224. unsigned int cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  225. if (IS_ENABLED(CONFIG_EXYNOS_MCPM)) {
  226. mcpm_set_entry_vector(cpu, cluster, exynos_cpu_resume);
  227. mcpm_cpu_suspend();
  228. }
  229. pr_info("Failed to suspend the system\n");
  230. /* return value != 0 means failure */
  231. return 1;
  232. }
  233. static void exynos_pm_set_wakeup_mask(void)
  234. {
  235. /*
  236. * Set wake-up mask registers
  237. * EXYNOS_EINT_WAKEUP_MASK is set by pinctrl driver in late suspend.
  238. */
  239. pmu_raw_writel(exynos_irqwake_intmask & ~BIT(31), S5P_WAKEUP_MASK);
  240. }
  241. static void exynos_pm_enter_sleep_mode(void)
  242. {
  243. /* Set value of power down register for sleep mode */
  244. exynos_sys_powerdown_conf(SYS_SLEEP);
  245. pmu_raw_writel(EXYNOS_SLEEP_MAGIC, S5P_INFORM1);
  246. }
  247. static void exynos_pm_prepare(void)
  248. {
  249. exynos_set_delayed_reset_assertion(false);
  250. /* Set wake-up mask registers */
  251. exynos_pm_set_wakeup_mask();
  252. exynos_pm_enter_sleep_mode();
  253. /* ensure at least INFORM0 has the resume address */
  254. pmu_raw_writel(__pa_symbol(exynos_cpu_resume), S5P_INFORM0);
  255. }
  256. static void exynos3250_pm_prepare(void)
  257. {
  258. unsigned int tmp;
  259. /* Set wake-up mask registers */
  260. exynos_pm_set_wakeup_mask();
  261. tmp = pmu_raw_readl(EXYNOS3_ARM_L2_OPTION);
  262. tmp &= ~EXYNOS5_OPTION_USE_RETENTION;
  263. pmu_raw_writel(tmp, EXYNOS3_ARM_L2_OPTION);
  264. exynos_pm_enter_sleep_mode();
  265. /* ensure at least INFORM0 has the resume address */
  266. pmu_raw_writel(__pa_symbol(exynos_cpu_resume), S5P_INFORM0);
  267. }
  268. static void exynos5420_pm_prepare(void)
  269. {
  270. unsigned int tmp;
  271. /* Set wake-up mask registers */
  272. exynos_pm_set_wakeup_mask();
  273. pm_state.pmu_spare3 = pmu_raw_readl(S5P_PMU_SPARE3);
  274. /*
  275. * The cpu state needs to be saved and restored so that the
  276. * secondary CPUs will enter low power start. Though the U-Boot
  277. * is setting the cpu state with low power flag, the kernel
  278. * needs to restore it back in case, the primary cpu fails to
  279. * suspend for any reason.
  280. */
  281. pm_state.cpu_state = readl_relaxed(pm_state.sysram_base +
  282. EXYNOS5420_CPU_STATE);
  283. writel_relaxed(0x0, pm_state.sysram_base + EXYNOS5420_CPU_STATE);
  284. if (pm_state.secure_firmware)
  285. exynos_smc(SMC_CMD_REG, SMC_REG_ID_SFR_W(pm_state.sysram_phys +
  286. EXYNOS5420_CPU_STATE),
  287. 0, 0);
  288. exynos_pm_enter_sleep_mode();
  289. /* ensure at least INFORM0 has the resume address */
  290. if (IS_ENABLED(CONFIG_EXYNOS_MCPM))
  291. pmu_raw_writel(__pa_symbol(mcpm_entry_point), S5P_INFORM0);
  292. tmp = pmu_raw_readl(EXYNOS_L2_OPTION(0));
  293. tmp &= ~EXYNOS_L2_USE_RETENTION;
  294. pmu_raw_writel(tmp, EXYNOS_L2_OPTION(0));
  295. tmp = pmu_raw_readl(EXYNOS5420_SFR_AXI_CGDIS1);
  296. tmp |= EXYNOS5420_UFS;
  297. pmu_raw_writel(tmp, EXYNOS5420_SFR_AXI_CGDIS1);
  298. tmp = pmu_raw_readl(EXYNOS5420_ARM_COMMON_OPTION);
  299. tmp &= ~EXYNOS5420_L2RSTDISABLE_VALUE;
  300. pmu_raw_writel(tmp, EXYNOS5420_ARM_COMMON_OPTION);
  301. tmp = pmu_raw_readl(EXYNOS5420_FSYS2_OPTION);
  302. tmp |= EXYNOS5420_EMULATION;
  303. pmu_raw_writel(tmp, EXYNOS5420_FSYS2_OPTION);
  304. tmp = pmu_raw_readl(EXYNOS5420_PSGEN_OPTION);
  305. tmp |= EXYNOS5420_EMULATION;
  306. pmu_raw_writel(tmp, EXYNOS5420_PSGEN_OPTION);
  307. }
  308. static int exynos_pm_suspend(void)
  309. {
  310. exynos_pm_central_suspend();
  311. /* Setting SEQ_OPTION register */
  312. pmu_raw_writel(S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0,
  313. S5P_CENTRAL_SEQ_OPTION);
  314. if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
  315. exynos_cpu_save_register();
  316. return 0;
  317. }
  318. static int exynos5420_pm_suspend(void)
  319. {
  320. u32 this_cluster;
  321. exynos_pm_central_suspend();
  322. /* Setting SEQ_OPTION register */
  323. this_cluster = MPIDR_AFFINITY_LEVEL(read_cpuid_mpidr(), 1);
  324. if (!this_cluster)
  325. pmu_raw_writel(EXYNOS5420_ARM_USE_STANDBY_WFI0,
  326. S5P_CENTRAL_SEQ_OPTION);
  327. else
  328. pmu_raw_writel(EXYNOS5420_KFC_USE_STANDBY_WFI0,
  329. S5P_CENTRAL_SEQ_OPTION);
  330. return 0;
  331. }
  332. static void exynos_pm_resume(void)
  333. {
  334. u32 cpuid = read_cpuid_part();
  335. if (exynos_pm_central_resume())
  336. goto early_wakeup;
  337. if (cpuid == ARM_CPU_PART_CORTEX_A9)
  338. exynos_scu_enable();
  339. if (call_firmware_op(resume) == -ENOSYS
  340. && cpuid == ARM_CPU_PART_CORTEX_A9)
  341. exynos_cpu_restore_register();
  342. early_wakeup:
  343. /* Clear SLEEP mode set in INFORM1 */
  344. pmu_raw_writel(0x0, S5P_INFORM1);
  345. exynos_set_delayed_reset_assertion(true);
  346. }
  347. static void exynos3250_pm_resume(void)
  348. {
  349. u32 cpuid = read_cpuid_part();
  350. if (exynos_pm_central_resume())
  351. goto early_wakeup;
  352. pmu_raw_writel(S5P_USE_STANDBY_WFI_ALL, S5P_CENTRAL_SEQ_OPTION);
  353. if (call_firmware_op(resume) == -ENOSYS
  354. && cpuid == ARM_CPU_PART_CORTEX_A9)
  355. exynos_cpu_restore_register();
  356. early_wakeup:
  357. /* Clear SLEEP mode set in INFORM1 */
  358. pmu_raw_writel(0x0, S5P_INFORM1);
  359. }
  360. static void exynos5420_prepare_pm_resume(void)
  361. {
  362. unsigned int mpidr, cluster;
  363. mpidr = read_cpuid_mpidr();
  364. cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  365. if (IS_ENABLED(CONFIG_EXYNOS_MCPM))
  366. WARN_ON(mcpm_cpu_powered_up());
  367. if (IS_ENABLED(CONFIG_HW_PERF_EVENTS) && cluster != 0) {
  368. /*
  369. * When system is resumed on the LITTLE/KFC core (cluster 1),
  370. * the DSCR is not properly updated until the power is turned
  371. * on also for the cluster 0. Enable it for a while to
  372. * propagate the SPNIDEN and SPIDEN signals from Secure JTAG
  373. * block and avoid undefined instruction issue on CP14 reset.
  374. */
  375. pmu_raw_writel(S5P_CORE_LOCAL_PWR_EN,
  376. EXYNOS_COMMON_CONFIGURATION(0));
  377. pmu_raw_writel(0,
  378. EXYNOS_COMMON_CONFIGURATION(0));
  379. }
  380. }
  381. static void exynos5420_pm_resume(void)
  382. {
  383. unsigned long tmp;
  384. /* Restore the CPU0 low power state register */
  385. tmp = pmu_raw_readl(EXYNOS5_ARM_CORE0_SYS_PWR_REG);
  386. pmu_raw_writel(tmp | S5P_CORE_LOCAL_PWR_EN,
  387. EXYNOS5_ARM_CORE0_SYS_PWR_REG);
  388. /* Restore the sysram cpu state register */
  389. writel_relaxed(pm_state.cpu_state,
  390. pm_state.sysram_base + EXYNOS5420_CPU_STATE);
  391. if (pm_state.secure_firmware)
  392. exynos_smc(SMC_CMD_REG,
  393. SMC_REG_ID_SFR_W(pm_state.sysram_phys +
  394. EXYNOS5420_CPU_STATE),
  395. EXYNOS_AFTR_MAGIC, 0);
  396. pmu_raw_writel(EXYNOS5420_USE_STANDBY_WFI_ALL,
  397. S5P_CENTRAL_SEQ_OPTION);
  398. if (exynos_pm_central_resume())
  399. goto early_wakeup;
  400. pmu_raw_writel(pm_state.pmu_spare3, S5P_PMU_SPARE3);
  401. early_wakeup:
  402. tmp = pmu_raw_readl(EXYNOS5420_SFR_AXI_CGDIS1);
  403. tmp &= ~EXYNOS5420_UFS;
  404. pmu_raw_writel(tmp, EXYNOS5420_SFR_AXI_CGDIS1);
  405. tmp = pmu_raw_readl(EXYNOS5420_FSYS2_OPTION);
  406. tmp &= ~EXYNOS5420_EMULATION;
  407. pmu_raw_writel(tmp, EXYNOS5420_FSYS2_OPTION);
  408. tmp = pmu_raw_readl(EXYNOS5420_PSGEN_OPTION);
  409. tmp &= ~EXYNOS5420_EMULATION;
  410. pmu_raw_writel(tmp, EXYNOS5420_PSGEN_OPTION);
  411. /* Clear SLEEP mode set in INFORM1 */
  412. pmu_raw_writel(0x0, S5P_INFORM1);
  413. }
  414. /*
  415. * Suspend Ops
  416. */
  417. static int exynos_suspend_enter(suspend_state_t state)
  418. {
  419. u32 eint_wakeup_mask = exynos_read_eint_wakeup_mask();
  420. int ret;
  421. pr_debug("%s: suspending the system...\n", __func__);
  422. pr_debug("%s: wakeup masks: %08x,%08x\n", __func__,
  423. exynos_irqwake_intmask, eint_wakeup_mask);
  424. if (exynos_irqwake_intmask == -1U
  425. && eint_wakeup_mask == EXYNOS_EINT_WAKEUP_MASK_DISABLED) {
  426. pr_err("%s: No wake-up sources!\n", __func__);
  427. pr_err("%s: Aborting sleep\n", __func__);
  428. return -EINVAL;
  429. }
  430. if (pm_data->pm_prepare)
  431. pm_data->pm_prepare();
  432. flush_cache_all();
  433. ret = call_firmware_op(suspend);
  434. if (ret == -ENOSYS)
  435. ret = cpu_suspend(0, pm_data->cpu_suspend);
  436. if (ret)
  437. return ret;
  438. if (pm_data->pm_resume_prepare)
  439. pm_data->pm_resume_prepare();
  440. pr_debug("%s: wakeup stat: %08x\n", __func__,
  441. pmu_raw_readl(S5P_WAKEUP_STAT));
  442. pr_debug("%s: resuming the system...\n", __func__);
  443. return 0;
  444. }
  445. static int exynos_suspend_prepare(void)
  446. {
  447. int ret;
  448. /*
  449. * REVISIT: It would be better if struct platform_suspend_ops
  450. * .prepare handler get the suspend_state_t as a parameter to
  451. * avoid hard-coding the suspend to mem state. It's safe to do
  452. * it now only because the suspend_valid_only_mem function is
  453. * used as the .valid callback used to check if a given state
  454. * is supported by the platform anyways.
  455. */
  456. ret = regulator_suspend_prepare(PM_SUSPEND_MEM);
  457. if (ret) {
  458. pr_err("Failed to prepare regulators for suspend (%d)\n", ret);
  459. return ret;
  460. }
  461. return 0;
  462. }
  463. static void exynos_suspend_finish(void)
  464. {
  465. int ret;
  466. ret = regulator_suspend_finish();
  467. if (ret)
  468. pr_warn("Failed to resume regulators from suspend (%d)\n", ret);
  469. }
  470. static const struct platform_suspend_ops exynos_suspend_ops = {
  471. .enter = exynos_suspend_enter,
  472. .prepare = exynos_suspend_prepare,
  473. .finish = exynos_suspend_finish,
  474. .valid = suspend_valid_only_mem,
  475. };
  476. static const struct exynos_pm_data exynos3250_pm_data = {
  477. .wkup_irq = exynos3250_wkup_irq,
  478. .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)),
  479. .pm_suspend = exynos_pm_suspend,
  480. .pm_resume = exynos3250_pm_resume,
  481. .pm_prepare = exynos3250_pm_prepare,
  482. .cpu_suspend = exynos3250_cpu_suspend,
  483. };
  484. static const struct exynos_pm_data exynos4_pm_data = {
  485. .wkup_irq = exynos4_wkup_irq,
  486. .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)),
  487. .pm_suspend = exynos_pm_suspend,
  488. .pm_resume = exynos_pm_resume,
  489. .pm_prepare = exynos_pm_prepare,
  490. .cpu_suspend = exynos_cpu_suspend,
  491. };
  492. static const struct exynos_pm_data exynos5250_pm_data = {
  493. .wkup_irq = exynos5250_wkup_irq,
  494. .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)),
  495. .pm_suspend = exynos_pm_suspend,
  496. .pm_resume = exynos_pm_resume,
  497. .pm_prepare = exynos_pm_prepare,
  498. .cpu_suspend = exynos_cpu_suspend,
  499. };
  500. static const struct exynos_pm_data exynos5420_pm_data = {
  501. .wkup_irq = exynos5250_wkup_irq,
  502. .wake_disable_mask = (0x7F << 7) | (0x1F << 1),
  503. .pm_resume_prepare = exynos5420_prepare_pm_resume,
  504. .pm_resume = exynos5420_pm_resume,
  505. .pm_suspend = exynos5420_pm_suspend,
  506. .pm_prepare = exynos5420_pm_prepare,
  507. .cpu_suspend = exynos5420_cpu_suspend,
  508. };
  509. static const struct of_device_id exynos_pmu_of_device_ids[] __initconst = {
  510. {
  511. .compatible = "samsung,exynos3250-pmu",
  512. .data = &exynos3250_pm_data,
  513. }, {
  514. .compatible = "samsung,exynos4210-pmu",
  515. .data = &exynos4_pm_data,
  516. }, {
  517. .compatible = "samsung,exynos4212-pmu",
  518. .data = &exynos4_pm_data,
  519. }, {
  520. .compatible = "samsung,exynos4412-pmu",
  521. .data = &exynos4_pm_data,
  522. }, {
  523. .compatible = "samsung,exynos5250-pmu",
  524. .data = &exynos5250_pm_data,
  525. }, {
  526. .compatible = "samsung,exynos5420-pmu",
  527. .data = &exynos5420_pm_data,
  528. },
  529. { /*sentinel*/ },
  530. };
  531. static struct syscore_ops exynos_pm_syscore_ops;
  532. void __init exynos_pm_init(void)
  533. {
  534. const struct of_device_id *match;
  535. struct device_node *np;
  536. u32 tmp;
  537. np = of_find_matching_node_and_match(NULL, exynos_pmu_of_device_ids, &match);
  538. if (!np) {
  539. pr_err("Failed to find PMU node\n");
  540. return;
  541. }
  542. if (WARN_ON(!of_property_read_bool(np, "interrupt-controller"))) {
  543. pr_warn("Outdated DT detected, suspend/resume will NOT work\n");
  544. of_node_put(np);
  545. return;
  546. }
  547. of_node_put(np);
  548. pm_data = (const struct exynos_pm_data *) match->data;
  549. /* All wakeup disable */
  550. tmp = pmu_raw_readl(S5P_WAKEUP_MASK);
  551. tmp |= pm_data->wake_disable_mask;
  552. pmu_raw_writel(tmp, S5P_WAKEUP_MASK);
  553. exynos_pm_syscore_ops.suspend = pm_data->pm_suspend;
  554. exynos_pm_syscore_ops.resume = pm_data->pm_resume;
  555. register_syscore_ops(&exynos_pm_syscore_ops);
  556. suspend_set_ops(&exynos_suspend_ops);
  557. /*
  558. * Applicable as of now only to Exynos542x. If booted under secure
  559. * firmware, the non-secure region of sysram should be used.
  560. */
  561. if (exynos_secure_firmware_available()) {
  562. pm_state.sysram_phys = sysram_base_phys;
  563. pm_state.sysram_base = sysram_ns_base_addr;
  564. pm_state.secure_firmware = true;
  565. } else {
  566. pm_state.sysram_base = sysram_base_addr;
  567. }
  568. }