suspend.c 18 KB

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