irq.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
  3. * JZ4740 platform IRQ support
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * You should have received a copy of the GNU General Public License along
  11. * with this program; if not, write to the Free Software Foundation, Inc.,
  12. * 675 Mass Ave, Cambridge, MA 02139, USA.
  13. *
  14. */
  15. #include <linux/errno.h>
  16. #include <linux/init.h>
  17. #include <linux/types.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/ioport.h>
  20. #include <linux/timex.h>
  21. #include <linux/slab.h>
  22. #include <linux/delay.h>
  23. #include <linux/debugfs.h>
  24. #include <linux/seq_file.h>
  25. #include <asm/io.h>
  26. #include <asm/mipsregs.h>
  27. #include <asm/irq_cpu.h>
  28. #include <asm/mach-jz4740/base.h>
  29. static void __iomem *jz_intc_base;
  30. static uint32_t jz_intc_wakeup;
  31. static uint32_t jz_intc_saved;
  32. #define JZ_REG_INTC_STATUS 0x00
  33. #define JZ_REG_INTC_MASK 0x04
  34. #define JZ_REG_INTC_SET_MASK 0x08
  35. #define JZ_REG_INTC_CLEAR_MASK 0x0c
  36. #define JZ_REG_INTC_PENDING 0x10
  37. #define IRQ_BIT(x) BIT((x) - JZ4740_IRQ_BASE)
  38. static void intc_irq_unmask(unsigned int irq)
  39. {
  40. writel(IRQ_BIT(irq), jz_intc_base + JZ_REG_INTC_CLEAR_MASK);
  41. }
  42. static void intc_irq_mask(unsigned int irq)
  43. {
  44. writel(IRQ_BIT(irq), jz_intc_base + JZ_REG_INTC_SET_MASK);
  45. }
  46. static int intc_irq_set_wake(unsigned int irq, unsigned int on)
  47. {
  48. if (on)
  49. jz_intc_wakeup |= IRQ_BIT(irq);
  50. else
  51. jz_intc_wakeup &= ~IRQ_BIT(irq);
  52. return 0;
  53. }
  54. static struct irq_chip intc_irq_type = {
  55. .name = "INTC",
  56. .mask = intc_irq_mask,
  57. .mask_ack = intc_irq_mask,
  58. .unmask = intc_irq_unmask,
  59. .set_wake = intc_irq_set_wake,
  60. };
  61. static irqreturn_t jz4740_cascade(int irq, void *data)
  62. {
  63. uint32_t irq_reg;
  64. irq_reg = readl(jz_intc_base + JZ_REG_INTC_PENDING);
  65. if (irq_reg)
  66. generic_handle_irq(__fls(irq_reg) + JZ4740_IRQ_BASE);
  67. return IRQ_HANDLED;
  68. }
  69. static struct irqaction jz4740_cascade_action = {
  70. .handler = jz4740_cascade,
  71. .name = "JZ4740 cascade interrupt",
  72. };
  73. void __init arch_init_irq(void)
  74. {
  75. int i;
  76. mips_cpu_irq_init();
  77. jz_intc_base = ioremap(JZ4740_INTC_BASE_ADDR, 0x14);
  78. for (i = JZ4740_IRQ_BASE; i < JZ4740_IRQ_BASE + 32; i++) {
  79. intc_irq_mask(i);
  80. set_irq_chip_and_handler(i, &intc_irq_type, handle_level_irq);
  81. }
  82. setup_irq(2, &jz4740_cascade_action);
  83. }
  84. asmlinkage void plat_irq_dispatch(void)
  85. {
  86. unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  87. if (pending & STATUSF_IP2)
  88. do_IRQ(2);
  89. else if (pending & STATUSF_IP3)
  90. do_IRQ(3);
  91. else
  92. spurious_interrupt();
  93. }
  94. void jz4740_intc_suspend(void)
  95. {
  96. jz_intc_saved = readl(jz_intc_base + JZ_REG_INTC_MASK);
  97. writel(~jz_intc_wakeup, jz_intc_base + JZ_REG_INTC_SET_MASK);
  98. writel(jz_intc_wakeup, jz_intc_base + JZ_REG_INTC_CLEAR_MASK);
  99. }
  100. void jz4740_intc_resume(void)
  101. {
  102. writel(~jz_intc_saved, jz_intc_base + JZ_REG_INTC_CLEAR_MASK);
  103. writel(jz_intc_saved, jz_intc_base + JZ_REG_INTC_SET_MASK);
  104. }
  105. #ifdef CONFIG_DEBUG_FS
  106. static inline void intc_seq_reg(struct seq_file *s, const char *name,
  107. unsigned int reg)
  108. {
  109. seq_printf(s, "%s:\t\t%08x\n", name, readl(jz_intc_base + reg));
  110. }
  111. static int intc_regs_show(struct seq_file *s, void *unused)
  112. {
  113. intc_seq_reg(s, "Status", JZ_REG_INTC_STATUS);
  114. intc_seq_reg(s, "Mask", JZ_REG_INTC_MASK);
  115. intc_seq_reg(s, "Pending", JZ_REG_INTC_PENDING);
  116. return 0;
  117. }
  118. static int intc_regs_open(struct inode *inode, struct file *file)
  119. {
  120. return single_open(file, intc_regs_show, NULL);
  121. }
  122. static const struct file_operations intc_regs_operations = {
  123. .open = intc_regs_open,
  124. .read = seq_read,
  125. .llseek = seq_lseek,
  126. .release = single_release,
  127. };
  128. static int __init intc_debugfs_init(void)
  129. {
  130. (void) debugfs_create_file("jz_regs_intc", S_IFREG | S_IRUGO,
  131. NULL, NULL, &intc_regs_operations);
  132. return 0;
  133. }
  134. subsys_initcall(intc_debugfs_init);
  135. #endif