irq.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Interrupt routines for Gemini
  3. *
  4. * Copyright (C) 2001-2006 Storlink, Corp.
  5. * Copyright (C) 2008-2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <linux/ioport.h>
  15. #include <linux/stddef.h>
  16. #include <linux/list.h>
  17. #include <linux/sched.h>
  18. #include <asm/irq.h>
  19. #include <asm/mach/irq.h>
  20. #include <asm/system_misc.h>
  21. #include <mach/hardware.h>
  22. #define IRQ_SOURCE(base_addr) (base_addr + 0x00)
  23. #define IRQ_MASK(base_addr) (base_addr + 0x04)
  24. #define IRQ_CLEAR(base_addr) (base_addr + 0x08)
  25. #define IRQ_TMODE(base_addr) (base_addr + 0x0C)
  26. #define IRQ_TLEVEL(base_addr) (base_addr + 0x10)
  27. #define IRQ_STATUS(base_addr) (base_addr + 0x14)
  28. #define FIQ_SOURCE(base_addr) (base_addr + 0x20)
  29. #define FIQ_MASK(base_addr) (base_addr + 0x24)
  30. #define FIQ_CLEAR(base_addr) (base_addr + 0x28)
  31. #define FIQ_TMODE(base_addr) (base_addr + 0x2C)
  32. #define FIQ_LEVEL(base_addr) (base_addr + 0x30)
  33. #define FIQ_STATUS(base_addr) (base_addr + 0x34)
  34. static void gemini_ack_irq(struct irq_data *d)
  35. {
  36. __raw_writel(1 << d->irq, IRQ_CLEAR(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
  37. }
  38. static void gemini_mask_irq(struct irq_data *d)
  39. {
  40. unsigned int mask;
  41. mask = __raw_readl(IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
  42. mask &= ~(1 << d->irq);
  43. __raw_writel(mask, IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
  44. }
  45. static void gemini_unmask_irq(struct irq_data *d)
  46. {
  47. unsigned int mask;
  48. mask = __raw_readl(IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
  49. mask |= (1 << d->irq);
  50. __raw_writel(mask, IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
  51. }
  52. static struct irq_chip gemini_irq_chip = {
  53. .name = "INTC",
  54. .irq_ack = gemini_ack_irq,
  55. .irq_mask = gemini_mask_irq,
  56. .irq_unmask = gemini_unmask_irq,
  57. };
  58. static struct resource irq_resource = {
  59. .name = "irq_handler",
  60. .start = IO_ADDRESS(GEMINI_INTERRUPT_BASE),
  61. .end = IO_ADDRESS(FIQ_STATUS(GEMINI_INTERRUPT_BASE)) + 4,
  62. };
  63. void __init gemini_init_irq(void)
  64. {
  65. unsigned int i, mode = 0, level = 0;
  66. /*
  67. * Disable the idle handler by default since it is buggy
  68. * For more info see arch/arm/mach-gemini/idle.c
  69. */
  70. disable_hlt();
  71. request_resource(&iomem_resource, &irq_resource);
  72. for (i = 0; i < NR_IRQS; i++) {
  73. irq_set_chip(i, &gemini_irq_chip);
  74. if((i >= IRQ_TIMER1 && i <= IRQ_TIMER3) || (i >= IRQ_SERIRQ0 && i <= IRQ_SERIRQ1)) {
  75. irq_set_handler(i, handle_edge_irq);
  76. mode |= 1 << i;
  77. level |= 1 << i;
  78. } else {
  79. irq_set_handler(i, handle_level_irq);
  80. }
  81. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  82. }
  83. /* Disable all interrupts */
  84. __raw_writel(0, IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
  85. __raw_writel(0, FIQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
  86. /* Set interrupt mode */
  87. __raw_writel(mode, IRQ_TMODE(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
  88. __raw_writel(level, IRQ_TLEVEL(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
  89. }