irq-pm-s3c64xx.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Copyright 2008 Openmoko, Inc.
  4. // Copyright 2008 Simtec Electronics
  5. // Ben Dooks <[email protected]>
  6. // http://armlinux.simtec.co.uk/
  7. //
  8. // S3C64XX - Interrupt handling Power Management
  9. /*
  10. * NOTE: Code in this file is not used when booting with Device Tree support.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/syscore_ops.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/serial_core.h>
  16. #include <linux/serial_s3c.h>
  17. #include <linux/irq.h>
  18. #include <linux/io.h>
  19. #include <linux/of.h>
  20. #include "map.h"
  21. #include "regs-gpio.h"
  22. #include "cpu.h"
  23. #include "pm.h"
  24. /* We handled all the IRQ types in this code, to save having to make several
  25. * small files to handle each different type separately. Having the EINT_GRP
  26. * code here shouldn't be as much bloat as the IRQ table space needed when
  27. * they are enabled. The added benefit is we ensure that these registers are
  28. * in the same state as we suspended.
  29. */
  30. static struct sleep_save irq_save[] = {
  31. SAVE_ITEM(S3C64XX_PRIORITY),
  32. SAVE_ITEM(S3C64XX_EINT0CON0),
  33. SAVE_ITEM(S3C64XX_EINT0CON1),
  34. SAVE_ITEM(S3C64XX_EINT0FLTCON0),
  35. SAVE_ITEM(S3C64XX_EINT0FLTCON1),
  36. SAVE_ITEM(S3C64XX_EINT0FLTCON2),
  37. SAVE_ITEM(S3C64XX_EINT0FLTCON3),
  38. SAVE_ITEM(S3C64XX_EINT0MASK),
  39. };
  40. static struct irq_grp_save {
  41. u32 fltcon;
  42. u32 con;
  43. u32 mask;
  44. } eint_grp_save[5];
  45. #ifndef CONFIG_SERIAL_SAMSUNG_UARTS
  46. #define SERIAL_SAMSUNG_UARTS 0
  47. #else
  48. #define SERIAL_SAMSUNG_UARTS CONFIG_SERIAL_SAMSUNG_UARTS
  49. #endif
  50. static u32 irq_uart_mask[SERIAL_SAMSUNG_UARTS];
  51. static int s3c64xx_irq_pm_suspend(void)
  52. {
  53. struct irq_grp_save *grp = eint_grp_save;
  54. int i;
  55. S3C_PMDBG("%s: suspending IRQs\n", __func__);
  56. s3c_pm_do_save(irq_save, ARRAY_SIZE(irq_save));
  57. for (i = 0; i < SERIAL_SAMSUNG_UARTS; i++)
  58. irq_uart_mask[i] = __raw_readl(S3C_VA_UARTx(i) + S3C64XX_UINTM);
  59. for (i = 0; i < ARRAY_SIZE(eint_grp_save); i++, grp++) {
  60. grp->con = __raw_readl(S3C64XX_EINT12CON + (i * 4));
  61. grp->mask = __raw_readl(S3C64XX_EINT12MASK + (i * 4));
  62. grp->fltcon = __raw_readl(S3C64XX_EINT12FLTCON + (i * 4));
  63. }
  64. return 0;
  65. }
  66. static void s3c64xx_irq_pm_resume(void)
  67. {
  68. struct irq_grp_save *grp = eint_grp_save;
  69. int i;
  70. S3C_PMDBG("%s: resuming IRQs\n", __func__);
  71. s3c_pm_do_restore(irq_save, ARRAY_SIZE(irq_save));
  72. for (i = 0; i < SERIAL_SAMSUNG_UARTS; i++)
  73. __raw_writel(irq_uart_mask[i], S3C_VA_UARTx(i) + S3C64XX_UINTM);
  74. for (i = 0; i < ARRAY_SIZE(eint_grp_save); i++, grp++) {
  75. __raw_writel(grp->con, S3C64XX_EINT12CON + (i * 4));
  76. __raw_writel(grp->mask, S3C64XX_EINT12MASK + (i * 4));
  77. __raw_writel(grp->fltcon, S3C64XX_EINT12FLTCON + (i * 4));
  78. }
  79. S3C_PMDBG("%s: IRQ configuration restored\n", __func__);
  80. }
  81. static struct syscore_ops s3c64xx_irq_syscore_ops = {
  82. .suspend = s3c64xx_irq_pm_suspend,
  83. .resume = s3c64xx_irq_pm_resume,
  84. };
  85. static __init int s3c64xx_syscore_init(void)
  86. {
  87. /* Appropriate drivers (pinctrl, uart) handle this when using DT. */
  88. if (of_have_populated_dt() || !soc_is_s3c64xx())
  89. return 0;
  90. register_syscore_ops(&s3c64xx_irq_syscore_ops);
  91. return 0;
  92. }
  93. core_initcall(s3c64xx_syscore_init);