suspend.c 18 KB

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