irq.c 2.6 KB

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