suspend.c 18 KB

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