irq.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Hitachi UL SolutionEngine 7722 FPGA IRQ Support.
  3. *
  4. * Copyright (C) 2007 Nobuhiro Iwamatsu
  5. * Copyright (C) 2012 Paul Mundt
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #define DRV_NAME "SE7722-FPGA"
  12. #define pr_fmt(fmt) DRV_NAME ": " fmt
  13. #define irq_reg_readl ioread16
  14. #define irq_reg_writel iowrite16
  15. #include <linux/init.h>
  16. #include <linux/irq.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/irqdomain.h>
  19. #include <linux/io.h>
  20. #include <linux/err.h>
  21. #include <asm/sizes.h>
  22. #include <mach-se/mach/se7722.h>
  23. #define IRQ01_BASE_ADDR 0x11800000
  24. #define IRQ01_MODE_REG 0
  25. #define IRQ01_STS_REG 4
  26. #define IRQ01_MASK_REG 8
  27. static void __iomem *se7722_irq_regs;
  28. struct irq_domain *se7722_irq_domain;
  29. static void se7722_irq_demux(unsigned int irq, struct irq_desc *desc)
  30. {
  31. struct irq_data *data = irq_get_irq_data(irq);
  32. struct irq_chip *chip = irq_data_get_irq_chip(data);
  33. unsigned long mask;
  34. int bit;
  35. chip->irq_mask_ack(data);
  36. mask = ioread16(se7722_irq_regs + IRQ01_STS_REG);
  37. for_each_set_bit(bit, &mask, SE7722_FPGA_IRQ_NR)
  38. generic_handle_irq(irq_linear_revmap(se7722_irq_domain, bit));
  39. chip->irq_unmask(data);
  40. }
  41. static void __init se7722_domain_init(void)
  42. {
  43. int i;
  44. se7722_irq_domain = irq_domain_add_linear(NULL, SE7722_FPGA_IRQ_NR,
  45. &irq_domain_simple_ops, NULL);
  46. if (unlikely(!se7722_irq_domain)) {
  47. printk("Failed to get IRQ domain\n");
  48. return;
  49. }
  50. for (i = 0; i < SE7722_FPGA_IRQ_NR; i++) {
  51. int irq = irq_create_mapping(se7722_irq_domain, i);
  52. if (unlikely(irq == 0)) {
  53. printk("Failed to allocate IRQ %d\n", i);
  54. return;
  55. }
  56. }
  57. }
  58. static void __init se7722_gc_init(void)
  59. {
  60. struct irq_chip_generic *gc;
  61. struct irq_chip_type *ct;
  62. unsigned int irq_base;
  63. irq_base = irq_linear_revmap(se7722_irq_domain, 0);
  64. gc = irq_alloc_generic_chip(DRV_NAME, 1, irq_base, se7722_irq_regs,
  65. handle_level_irq);
  66. if (unlikely(!gc))
  67. return;
  68. ct = gc->chip_types;
  69. ct->chip.irq_mask = irq_gc_mask_set_bit;
  70. ct->chip.irq_unmask = irq_gc_mask_clr_bit;
  71. ct->regs.mask = IRQ01_MASK_REG;
  72. irq_setup_generic_chip(gc, IRQ_MSK(SE7722_FPGA_IRQ_NR),
  73. IRQ_GC_INIT_MASK_CACHE,
  74. IRQ_NOREQUEST | IRQ_NOPROBE, 0);
  75. irq_set_chained_handler(IRQ0_IRQ, se7722_irq_demux);
  76. irq_set_irq_type(IRQ0_IRQ, IRQ_TYPE_LEVEL_LOW);
  77. irq_set_chained_handler(IRQ1_IRQ, se7722_irq_demux);
  78. irq_set_irq_type(IRQ1_IRQ, IRQ_TYPE_LEVEL_LOW);
  79. }
  80. /*
  81. * Initialize FPGA IRQs
  82. */
  83. void __init init_se7722_IRQ(void)
  84. {
  85. se7722_irq_regs = ioremap(IRQ01_BASE_ADDR, SZ_16);
  86. if (unlikely(!se7722_irq_regs)) {
  87. printk("Failed to remap IRQ01 regs\n");
  88. return;
  89. }
  90. /*
  91. * All FPGA IRQs disabled by default
  92. */
  93. iowrite16(0, se7722_irq_regs + IRQ01_MASK_REG);
  94. __raw_writew(0x2000, 0xb03fffec); /* mrshpc irq enable */
  95. se7722_domain_init();
  96. se7722_gc_init();
  97. }