irq.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * arch/arm/mach-orion/irq.c
  3. *
  4. * Core IRQ functions for Marvell Orion System On Chip
  5. *
  6. * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/irq.h>
  15. #include <asm/gpio.h>
  16. #include <asm/arch/orion.h>
  17. #include "common.h"
  18. /*****************************************************************************
  19. * Orion GPIO IRQ
  20. ****************************************************************************/
  21. static void orion_gpio_irq_mask(u32 irq)
  22. {
  23. int pin = irq_to_gpio(irq);
  24. orion_clrbits(GPIO_LEVEL_MASK, 1 << pin);
  25. }
  26. static void orion_gpio_irq_unmask(u32 irq)
  27. {
  28. int pin = irq_to_gpio(irq);
  29. orion_setbits(GPIO_LEVEL_MASK, 1 << pin);
  30. }
  31. static int orion_gpio_set_irq_type(u32 irq, u32 type)
  32. {
  33. int pin = irq_to_gpio(irq);
  34. if ((orion_read(GPIO_IO_CONF) & (1 << pin)) == 0) {
  35. printk(KERN_ERR "orion_gpio_set_irq_type failed "
  36. "(irq %d, pin %d).\n", irq, pin);
  37. return -EINVAL;
  38. }
  39. switch (type) {
  40. case IRQT_HIGH:
  41. orion_clrbits(GPIO_IN_POL, (1 << pin));
  42. break;
  43. case IRQT_LOW:
  44. orion_setbits(GPIO_IN_POL, (1 << pin));
  45. break;
  46. default:
  47. printk(KERN_ERR "failed to set irq=%d (type=%d)\n", irq, type);
  48. return -EINVAL;
  49. }
  50. return 0;
  51. }
  52. static struct irq_chip orion_gpio_irq_chip = {
  53. .name = "Orion-IRQ-GPIO",
  54. .ack = orion_gpio_irq_mask,
  55. .mask = orion_gpio_irq_mask,
  56. .unmask = orion_gpio_irq_unmask,
  57. .set_type = orion_gpio_set_irq_type,
  58. };
  59. static void orion_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
  60. {
  61. int i;
  62. u32 cause, shift;
  63. BUG_ON(irq < IRQ_ORION_GPIO_0_7 || irq > IRQ_ORION_GPIO_24_31);
  64. shift = (irq - IRQ_ORION_GPIO_0_7) * 8;
  65. cause = orion_read(GPIO_EDGE_CAUSE) & orion_read(GPIO_LEVEL_MASK);
  66. cause &= (0xff << shift);
  67. for (i = shift; i < shift + 8; i++) {
  68. if (cause & (1 << i)) {
  69. int gpio_irq = i + IRQ_ORION_GPIO_START;
  70. if (gpio_irq > 0) {
  71. desc = irq_desc + gpio_irq;
  72. desc_handle_irq(gpio_irq, desc);
  73. } else {
  74. printk(KERN_ERR "orion_gpio_irq_handler error, "
  75. "invalid irq %d\n", gpio_irq);
  76. }
  77. }
  78. }
  79. }
  80. static void __init orion_init_gpio_irq(void)
  81. {
  82. int i;
  83. /*
  84. * Mask and clear GPIO IRQ interrupts
  85. */
  86. orion_write(GPIO_LEVEL_MASK, 0x0);
  87. orion_write(GPIO_EDGE_CAUSE, 0x0);
  88. /*
  89. * Register chained level handlers for GPIO IRQs
  90. */
  91. for (i = IRQ_ORION_GPIO_START; i < NR_IRQS; i++) {
  92. set_irq_chip(i, &orion_gpio_irq_chip);
  93. set_irq_handler(i, handle_level_irq);
  94. set_irq_flags(i, IRQF_VALID);
  95. }
  96. set_irq_chained_handler(IRQ_ORION_GPIO_0_7, orion_gpio_irq_handler);
  97. set_irq_chained_handler(IRQ_ORION_GPIO_8_15, orion_gpio_irq_handler);
  98. set_irq_chained_handler(IRQ_ORION_GPIO_16_23, orion_gpio_irq_handler);
  99. set_irq_chained_handler(IRQ_ORION_GPIO_24_31, orion_gpio_irq_handler);
  100. }
  101. /*****************************************************************************
  102. * Orion Main IRQ
  103. ****************************************************************************/
  104. static void orion_main_irq_mask(u32 irq)
  105. {
  106. orion_clrbits(MAIN_IRQ_MASK, 1 << irq);
  107. }
  108. static void orion_main_irq_unmask(u32 irq)
  109. {
  110. orion_setbits(MAIN_IRQ_MASK, 1 << irq);
  111. }
  112. static struct irq_chip orion_main_irq_chip = {
  113. .name = "Orion-IRQ-Main",
  114. .ack = orion_main_irq_mask,
  115. .mask = orion_main_irq_mask,
  116. .unmask = orion_main_irq_unmask,
  117. };
  118. static void __init orion_init_main_irq(void)
  119. {
  120. int i;
  121. /*
  122. * Mask and clear Main IRQ interrupts
  123. */
  124. orion_write(MAIN_IRQ_MASK, 0x0);
  125. orion_write(MAIN_IRQ_CAUSE, 0x0);
  126. /*
  127. * Register level handler for Main IRQs
  128. */
  129. for (i = 0; i < IRQ_ORION_GPIO_START; i++) {
  130. set_irq_chip(i, &orion_main_irq_chip);
  131. set_irq_handler(i, handle_level_irq);
  132. set_irq_flags(i, IRQF_VALID);
  133. }
  134. }
  135. void __init orion_init_irq(void)
  136. {
  137. orion_init_main_irq();
  138. orion_init_gpio_irq();
  139. }