mt_cirq.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2020-2022, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef PLAT_MT_CIRQ_H
  7. #define PLAT_MT_CIRQ_H
  8. #include <stdint.h>
  9. #include <platform_def.h>
  10. enum {
  11. IRQ_MASK_HEADER = 0xF1F1F1F1,
  12. IRQ_MASK_FOOTER = 0xF2F2F2F2
  13. };
  14. struct mtk_irq_mask {
  15. uint32_t header; /* for error checking */
  16. uint32_t mask0;
  17. uint32_t mask1;
  18. uint32_t mask2;
  19. uint32_t mask3;
  20. uint32_t mask4;
  21. uint32_t mask5;
  22. uint32_t mask6;
  23. uint32_t mask7;
  24. uint32_t mask8;
  25. uint32_t mask9;
  26. uint32_t mask10;
  27. uint32_t mask11;
  28. uint32_t mask12;
  29. uint32_t footer; /* for error checking */
  30. };
  31. /*
  32. * Define hardware register
  33. */
  34. #define CIRQ_STA_BASE (SYS_CIRQ_BASE + U(0x000))
  35. #define CIRQ_ACK_BASE (SYS_CIRQ_BASE + U(0x080))
  36. #define CIRQ_MASK_BASE (SYS_CIRQ_BASE + U(0x100))
  37. #define CIRQ_MASK_SET_BASE (SYS_CIRQ_BASE + U(0x180))
  38. #define CIRQ_MASK_CLR_BASE (SYS_CIRQ_BASE + U(0x200))
  39. #define CIRQ_SENS_BASE (SYS_CIRQ_BASE + U(0x280))
  40. #define CIRQ_SENS_SET_BASE (SYS_CIRQ_BASE + U(0x300))
  41. #define CIRQ_SENS_CLR_BASE (SYS_CIRQ_BASE + U(0x380))
  42. #define CIRQ_POL_BASE (SYS_CIRQ_BASE + U(0x400))
  43. #define CIRQ_POL_SET_BASE (SYS_CIRQ_BASE + U(0x480))
  44. #define CIRQ_POL_CLR_BASE (SYS_CIRQ_BASE + U(0x500))
  45. #define CIRQ_CON (SYS_CIRQ_BASE + U(0x600))
  46. /*
  47. * Register placement
  48. */
  49. #define CIRQ_CON_EN_BITS U(0)
  50. #define CIRQ_CON_EDGE_ONLY_BITS U(1)
  51. #define CIRQ_CON_FLUSH_BITS U(2)
  52. #define CIRQ_CON_SW_RST_BITS U(20)
  53. #define CIRQ_CON_EVENT_BITS U(31)
  54. #define CIRQ_CON_BITS_MASK U(0x7)
  55. /*
  56. * Register setting
  57. */
  58. #define CIRQ_CON_EN U(0x1)
  59. #define CIRQ_CON_EDGE_ONLY U(0x1)
  60. #define CIRQ_CON_FLUSH U(0x1)
  61. #define CIRQ_SW_RESET U(0x1)
  62. /*
  63. * Define constant
  64. */
  65. #define CIRQ_CTRL_REG_NUM ((CIRQ_IRQ_NUM + 31U) / 32U)
  66. #define MT_CIRQ_POL_NEG U(0)
  67. #define MT_CIRQ_POL_POS U(1)
  68. #define IRQ_TO_CIRQ_NUM(irq) ((irq) - (32U + CIRQ_SPI_START))
  69. #define CIRQ_TO_IRQ_NUM(cirq) ((cirq) + (32U + CIRQ_SPI_START))
  70. /* GIC sensitive */
  71. #define SENS_EDGE U(0x2)
  72. #define SENS_LEVEL U(0x1)
  73. /*
  74. * Define function prototypes.
  75. */
  76. int mt_cirq_test(void);
  77. void mt_cirq_dump_reg(void);
  78. int mt_irq_mask_restore(struct mtk_irq_mask *mask);
  79. int mt_irq_mask_all(struct mtk_irq_mask *mask);
  80. void mt_cirq_clone_gic(void);
  81. void mt_cirq_enable(void);
  82. void mt_cirq_flush(void);
  83. void mt_cirq_disable(void);
  84. void mt_irq_unmask_for_sleep_ex(uint32_t irq);
  85. void set_wakeup_sources(uint32_t *list, uint32_t num_of_events);
  86. void mt_cirq_sw_reset(void);
  87. struct cirq_reg {
  88. uint32_t reg_num;
  89. uint32_t used;
  90. uint32_t mask;
  91. uint32_t pol;
  92. uint32_t sen;
  93. uint32_t pending;
  94. uint32_t the_link;
  95. };
  96. struct cirq_events {
  97. uint32_t num_reg;
  98. uint32_t spi_start;
  99. uint32_t num_of_events;
  100. uint32_t *wakeup_events;
  101. struct cirq_reg table[CIRQ_REG_NUM];
  102. uint32_t dist_base;
  103. uint32_t cirq_base;
  104. uint32_t used_reg_head;
  105. };
  106. #endif /* PLAT_MT_CIRQ_H */