aic.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * \file
  3. *
  4. * Implementation of Ark Interrupt Controller (AIC) controller.
  5. *
  6. */
  7. /*----------------------------------------------------------------------------
  8. * Headers
  9. *----------------------------------------------------------------------------*/
  10. #include "amt630h.h"
  11. #include "aic.h"
  12. #include "timer.h"
  13. #include <stdint.h>
  14. #include <string.h>
  15. #define ICSET 0x00
  16. #define ICPEND 0x04
  17. #define ICMODE 0x08
  18. #define ICMASK 0x0C
  19. #define ICLEVEL 0x10
  20. #define IRQISPR 0x3C
  21. #define IRQISPC 0x40
  22. #define IVEC_ADDR 0x78
  23. typedef struct {
  24. ISRFunction_t handler;
  25. void *handler_param;
  26. }IrqDesc_t;
  27. static IrqDesc_t irq_descs[MAX_IRQ_NUM];
  28. /*----------------------------------------------------------------------------
  29. * Exported functions
  30. *----------------------------------------------------------------------------*/
  31. void AIC_Initialize(void)
  32. {
  33. memset(irq_descs, 0, sizeof(irq_descs));
  34. writel(0x8, REGS_AIC_BASE + ICSET);
  35. udelay(10);
  36. writel(0x5, REGS_AIC_BASE + ICSET);
  37. writel(0x0, REGS_AIC_BASE + ICMODE);
  38. writel(0xffffffff, REGS_AIC_BASE + ICMASK);
  39. writel(0xffffffff, REGS_AIC_BASE + ICLEVEL);
  40. writel(0xffffffff, REGS_AIC_BASE + IRQISPC);
  41. }
  42. /**
  43. * \brief Enables interrupts coming from the given (unique) source (ID_xxx).
  44. *
  45. * \param source Interrupt source to enable.
  46. */
  47. void AIC_EnableIT(uint32_t source)
  48. {
  49. writel(readl(REGS_AIC_BASE + ICMASK) & ~(1 << source), REGS_AIC_BASE + ICMASK);
  50. }
  51. /**
  52. * \brief Disables interrupts coming from the given (unique) source (ID_xxx).
  53. *
  54. * \param source Interrupt source to disable.
  55. */
  56. void AIC_DisableIT(uint32_t source)
  57. {
  58. writel(readl(REGS_AIC_BASE + ICMASK) | (1 << source), REGS_AIC_BASE + ICMASK);
  59. }
  60. int32_t request_irq(uint32_t irq_source, int32_t priority, ISRFunction_t func, void *param)
  61. {
  62. if (irq_source > MAX_IRQ_NUM - 1) {
  63. return -1;
  64. }
  65. irq_descs[irq_source].handler = func;
  66. irq_descs[irq_source].handler_param = param;
  67. AIC_EnableIT(irq_source);
  68. return 0;
  69. }
  70. int32_t free_irq(uint32_t irq_source)
  71. {
  72. if (irq_source > MAX_IRQ_NUM - 1) {
  73. return -1;
  74. }
  75. irq_descs[irq_source].handler = NULL;
  76. irq_descs[irq_source].handler_param = NULL;
  77. AIC_DisableIT(irq_source);
  78. return 0;
  79. }
  80. void AIC_IrqHandler(void)
  81. {
  82. int32_t source = readl(REGS_AIC_BASE + IVEC_ADDR) >> 2;
  83. if (irq_descs[source].handler)
  84. irq_descs[source].handler(irq_descs[source].handler_param);
  85. writel(1 << source, REGS_AIC_BASE + IRQISPC);
  86. }