pm-core.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * S3C64XX - PM core support for arch/arm/plat-s3c/pm.c
  9. */
  10. #ifndef __MACH_S3C64XX_PM_CORE_H
  11. #define __MACH_S3C64XX_PM_CORE_H __FILE__
  12. #include <linux/serial_s3c.h>
  13. #include <linux/delay.h>
  14. #include <mach/regs-gpio.h>
  15. #include <mach/regs-clock.h>
  16. #include <mach/map.h>
  17. static inline void s3c_pm_debug_init_uart(void)
  18. {
  19. u32 tmp = __raw_readl(S3C_PCLK_GATE);
  20. /* As a note, since the S3C64XX UARTs generally have multiple
  21. * clock sources, we simply enable PCLK at the moment and hope
  22. * that the resume settings for the UART are suitable for the
  23. * use with PCLK.
  24. */
  25. tmp |= S3C_CLKCON_PCLK_UART0;
  26. tmp |= S3C_CLKCON_PCLK_UART1;
  27. tmp |= S3C_CLKCON_PCLK_UART2;
  28. tmp |= S3C_CLKCON_PCLK_UART3;
  29. __raw_writel(tmp, S3C_PCLK_GATE);
  30. udelay(10);
  31. }
  32. static inline void s3c_pm_arch_prepare_irqs(void)
  33. {
  34. /* VIC should have already been taken care of */
  35. /* clear any pending EINT0 interrupts */
  36. __raw_writel(__raw_readl(S3C64XX_EINT0PEND), S3C64XX_EINT0PEND);
  37. }
  38. static inline void s3c_pm_arch_stop_clocks(void)
  39. {
  40. }
  41. static inline void s3c_pm_arch_show_resume_irqs(void)
  42. {
  43. }
  44. /* make these defines, we currently do not have any need to change
  45. * the IRQ wake controls depending on the CPU we are running on */
  46. #ifdef CONFIG_PM_SLEEP
  47. #define s3c_irqwake_eintallow ((1 << 28) - 1)
  48. #define s3c_irqwake_intallow (~0)
  49. #else
  50. #define s3c_irqwake_eintallow 0
  51. #define s3c_irqwake_intallow 0
  52. #endif
  53. static inline void s3c_pm_arch_update_uart(void __iomem *regs,
  54. struct pm_uart_save *save)
  55. {
  56. u32 ucon = __raw_readl(regs + S3C2410_UCON);
  57. u32 ucon_clk = ucon & S3C6400_UCON_CLKMASK;
  58. u32 save_clk = save->ucon & S3C6400_UCON_CLKMASK;
  59. u32 new_ucon;
  60. u32 delta;
  61. /* S3C64XX UART blocks only support level interrupts, so ensure that
  62. * when we restore unused UART blocks we force the level interrupt
  63. * settigs. */
  64. save->ucon |= S3C2410_UCON_TXILEVEL | S3C2410_UCON_RXILEVEL;
  65. /* We have a constraint on changing the clock type of the UART
  66. * between UCLKx and PCLK, so ensure that when we restore UCON
  67. * that the CLK field is correctly modified if the bootloader
  68. * has changed anything.
  69. */
  70. if (ucon_clk != save_clk) {
  71. new_ucon = save->ucon;
  72. delta = ucon_clk ^ save_clk;
  73. /* change from UCLKx => wrong PCLK,
  74. * either UCLK can be tested for by a bit-test
  75. * with UCLK0 */
  76. if (ucon_clk & S3C6400_UCON_UCLK0 &&
  77. !(save_clk & S3C6400_UCON_UCLK0) &&
  78. delta & S3C6400_UCON_PCLK2) {
  79. new_ucon &= ~S3C6400_UCON_UCLK0;
  80. } else if (delta == S3C6400_UCON_PCLK2) {
  81. /* as an precaution, don't change from
  82. * PCLK2 => PCLK or vice-versa */
  83. new_ucon ^= S3C6400_UCON_PCLK2;
  84. }
  85. S3C_PMDBG("ucon change %04x => %04x (save=%04x)\n",
  86. ucon, new_ucon, save->ucon);
  87. save->ucon = new_ucon;
  88. }
  89. }
  90. static inline void s3c_pm_restored_gpios(void)
  91. {
  92. /* ensure sleep mode has been cleared from the system */
  93. __raw_writel(0, S3C64XX_SLPEN);
  94. }
  95. static inline void samsung_pm_saved_gpios(void)
  96. {
  97. /* turn on the sleep mode and keep it there, as it seems that during
  98. * suspend the xCON registers get re-set and thus you can end up with
  99. * problems between going to sleep and resuming.
  100. */
  101. __raw_writel(S3C64XX_SLPEN_USE_xSLP, S3C64XX_SLPEN);
  102. }
  103. #endif /* __MACH_S3C64XX_PM_CORE_H */