suspend.c 18 KB

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