irq.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #define JZ_REG_INTC_STATUS 0x00
  31. #define JZ_REG_INTC_MASK 0x04
  32. #define JZ_REG_INTC_SET_MASK 0x08
  33. #define JZ_REG_INTC_CLEAR_MASK 0x0c
  34. #define JZ_REG_INTC_PENDING 0x10
  35. static irqreturn_t jz4740_cascade(int irq, void *data)
  36. {
  37. uint32_t irq_reg;
  38. irq_reg = readl(jz_intc_base + JZ_REG_INTC_PENDING);
  39. if (irq_reg)
  40. generic_handle_irq(__fls(irq_reg) + JZ4740_IRQ_BASE);
  41. return IRQ_HANDLED;
  42. }
  43. static void jz4740_irq_set_mask(struct irq_chip_generic *gc, uint32_t mask)
  44. {
  45. struct irq_chip_regs *regs = &gc->chip_types->regs;
  46. writel(mask, gc->reg_base + regs->enable);
  47. writel(~mask, gc->reg_base + regs->disable);
  48. }
  49. void jz4740_irq_suspend(struct irq_data *data)
  50. {
  51. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data);
  52. jz4740_irq_set_mask(gc, gc->wake_active);
  53. }
  54. void jz4740_irq_resume(struct irq_data *data)
  55. {
  56. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data);
  57. jz4740_irq_set_mask(gc, gc->mask_cache);
  58. }
  59. static struct irqaction jz4740_cascade_action = {
  60. .handler = jz4740_cascade,
  61. .name = "JZ4740 cascade interrupt",
  62. };
  63. void __init arch_init_irq(void)
  64. {
  65. struct irq_chip_generic *gc;
  66. struct irq_chip_type *ct;
  67. mips_cpu_irq_init();
  68. jz_intc_base = ioremap(JZ4740_INTC_BASE_ADDR, 0x14);
  69. /* Mask all irqs */
  70. writel(0xffffffff, jz_intc_base + JZ_REG_INTC_SET_MASK);
  71. gc = irq_alloc_generic_chip("INTC", 1, JZ4740_IRQ_BASE, jz_intc_base,
  72. handle_level_irq);
  73. gc->wake_enabled = IRQ_MSK(32);
  74. ct = gc->chip_types;
  75. ct->regs.enable = JZ_REG_INTC_CLEAR_MASK;
  76. ct->regs.disable = JZ_REG_INTC_SET_MASK;
  77. ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
  78. ct->chip.irq_mask = irq_gc_mask_disable_reg;
  79. ct->chip.irq_mask_ack = irq_gc_mask_disable_reg;
  80. ct->chip.irq_set_wake = irq_gc_set_wake;
  81. ct->chip.irq_suspend = jz4740_irq_suspend;
  82. ct->chip.irq_resume = jz4740_irq_resume;
  83. irq_setup_generic_chip(gc, IRQ_MSK(32), 0, 0, IRQ_NOPROBE | IRQ_LEVEL);
  84. setup_irq(2, &jz4740_cascade_action);
  85. }
  86. asmlinkage void plat_irq_dispatch(void)
  87. {
  88. unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  89. if (pending & STATUSF_IP2)
  90. do_IRQ(2);
  91. else if (pending & STATUSF_IP3)
  92. do_IRQ(3);
  93. else
  94. spurious_interrupt();
  95. }
  96. #ifdef CONFIG_DEBUG_FS
  97. static inline void intc_seq_reg(struct seq_file *s, const char *name,
  98. unsigned int reg)
  99. {
  100. seq_printf(s, "%s:\t\t%08x\n", name, readl(jz_intc_base + reg));
  101. }
  102. static int intc_regs_show(struct seq_file *s, void *unused)
  103. {
  104. intc_seq_reg(s, "Status", JZ_REG_INTC_STATUS);
  105. intc_seq_reg(s, "Mask", JZ_REG_INTC_MASK);
  106. intc_seq_reg(s, "Pending", JZ_REG_INTC_PENDING);
  107. return 0;
  108. }
  109. static int intc_regs_open(struct inode *inode, struct file *file)
  110. {
  111. return single_open(file, intc_regs_show, NULL);
  112. }
  113. static const struct file_operations intc_regs_operations = {
  114. .open = intc_regs_open,
  115. .read = seq_read,
  116. .llseek = seq_lseek,
  117. .release = single_release,
  118. };
  119. static int __init intc_debugfs_init(void)
  120. {
  121. (void) debugfs_create_file("jz_regs_intc", S_IFREG | S_IRUGO,
  122. NULL, NULL, &intc_regs_operations);
  123. return 0;
  124. }
  125. subsys_initcall(intc_debugfs_init);
  126. #endif