irq.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * linux/arch/sh/boards/se/7724/irq.c
  3. *
  4. * Copyright (C) 2009 Renesas Solutions Corp.
  5. *
  6. * Kuninori Morimoto <morimoto.kuninori@renesas.com>
  7. *
  8. * Based on linux/arch/sh/boards/se/7722/irq.c
  9. * Copyright (C) 2007 Nobuhiro Iwamatsu
  10. *
  11. * Hitachi UL SolutionEngine 7724 Support.
  12. *
  13. * This file is subject to the terms and conditions of the GNU General Public
  14. * License. See the file "COPYING" in the main directory of this archive
  15. * for more details.
  16. */
  17. #include <linux/init.h>
  18. #include <linux/irq.h>
  19. #include <linux/interrupt.h>
  20. #include <asm/irq.h>
  21. #include <asm/io.h>
  22. #include <mach-se/mach/se7724.h>
  23. struct fpga_irq {
  24. unsigned long sraddr;
  25. unsigned long mraddr;
  26. unsigned short mask;
  27. unsigned int base;
  28. };
  29. static unsigned int fpga2irq(unsigned int irq)
  30. {
  31. if (irq >= IRQ0_BASE &&
  32. irq <= IRQ0_END)
  33. return IRQ0_IRQ;
  34. else if (irq >= IRQ1_BASE &&
  35. irq <= IRQ1_END)
  36. return IRQ1_IRQ;
  37. else
  38. return IRQ2_IRQ;
  39. }
  40. static struct fpga_irq get_fpga_irq(unsigned int irq)
  41. {
  42. struct fpga_irq set;
  43. switch (irq) {
  44. case IRQ0_IRQ:
  45. set.sraddr = IRQ0_SR;
  46. set.mraddr = IRQ0_MR;
  47. set.mask = IRQ0_MASK;
  48. set.base = IRQ0_BASE;
  49. break;
  50. case IRQ1_IRQ:
  51. set.sraddr = IRQ1_SR;
  52. set.mraddr = IRQ1_MR;
  53. set.mask = IRQ1_MASK;
  54. set.base = IRQ1_BASE;
  55. break;
  56. default:
  57. set.sraddr = IRQ2_SR;
  58. set.mraddr = IRQ2_MR;
  59. set.mask = IRQ2_MASK;
  60. set.base = IRQ2_BASE;
  61. break;
  62. }
  63. return set;
  64. }
  65. static void disable_se7724_irq(unsigned int irq)
  66. {
  67. struct fpga_irq set = get_fpga_irq(fpga2irq(irq));
  68. unsigned int bit = irq - set.base;
  69. ctrl_outw(ctrl_inw(set.mraddr) | 0x0001 << bit, set.mraddr);
  70. }
  71. static void enable_se7724_irq(unsigned int irq)
  72. {
  73. struct fpga_irq set = get_fpga_irq(fpga2irq(irq));
  74. unsigned int bit = irq - set.base;
  75. ctrl_outw(ctrl_inw(set.mraddr) & ~(0x0001 << bit), set.mraddr);
  76. }
  77. static struct irq_chip se7724_irq_chip __read_mostly = {
  78. .name = "SE7724-FPGA",
  79. .mask = disable_se7724_irq,
  80. .unmask = enable_se7724_irq,
  81. .mask_ack = disable_se7724_irq,
  82. };
  83. static void se7724_irq_demux(unsigned int irq, struct irq_desc *desc)
  84. {
  85. struct fpga_irq set = get_fpga_irq(irq);
  86. unsigned short intv = ctrl_inw(set.sraddr);
  87. struct irq_desc *ext_desc;
  88. unsigned int ext_irq = set.base;
  89. intv &= set.mask;
  90. while (intv) {
  91. if (intv & 0x0001) {
  92. ext_desc = irq_desc + ext_irq;
  93. handle_level_irq(ext_irq, ext_desc);
  94. }
  95. intv >>= 1;
  96. ext_irq++;
  97. }
  98. }
  99. /*
  100. * Initialize IRQ setting
  101. */
  102. void __init init_se7724_IRQ(void)
  103. {
  104. int i;
  105. ctrl_outw(0xffff, IRQ0_MR); /* mask all */
  106. ctrl_outw(0xffff, IRQ1_MR); /* mask all */
  107. ctrl_outw(0xffff, IRQ2_MR); /* mask all */
  108. ctrl_outw(0x0000, IRQ0_SR); /* clear irq */
  109. ctrl_outw(0x0000, IRQ1_SR); /* clear irq */
  110. ctrl_outw(0x0000, IRQ2_SR); /* clear irq */
  111. ctrl_outw(0x002a, IRQ_MODE); /* set irq type */
  112. for (i = 0; i < SE7724_FPGA_IRQ_NR; i++)
  113. set_irq_chip_and_handler_name(SE7724_FPGA_IRQ_BASE + i,
  114. &se7724_irq_chip,
  115. handle_level_irq, "level");
  116. set_irq_chained_handler(IRQ0_IRQ, se7724_irq_demux);
  117. set_irq_type(IRQ0_IRQ, IRQ_TYPE_LEVEL_LOW);
  118. set_irq_chained_handler(IRQ1_IRQ, se7724_irq_demux);
  119. set_irq_type(IRQ1_IRQ, IRQ_TYPE_LEVEL_LOW);
  120. set_irq_chained_handler(IRQ2_IRQ, se7724_irq_demux);
  121. set_irq_type(IRQ2_IRQ, IRQ_TYPE_LEVEL_LOW);
  122. }