irq.c 3.1 KB

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