irq.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2013 Altera Corporation
  4. * Copyright (C) 2011 Tobias Klauser <[email protected]>
  5. * Copyright (C) 2008 Thomas Chou <[email protected]>
  6. *
  7. * based on irq.c from m68k which is:
  8. *
  9. * Copyright (C) 2007 Greg Ungerer <[email protected]>
  10. */
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/irqdomain.h>
  14. #include <linux/of.h>
  15. static u32 ienable;
  16. asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs)
  17. {
  18. struct pt_regs *oldregs = set_irq_regs(regs);
  19. irq_enter();
  20. generic_handle_domain_irq(NULL, hwirq);
  21. irq_exit();
  22. set_irq_regs(oldregs);
  23. }
  24. static void chip_unmask(struct irq_data *d)
  25. {
  26. ienable |= (1 << d->hwirq);
  27. WRCTL(CTL_IENABLE, ienable);
  28. }
  29. static void chip_mask(struct irq_data *d)
  30. {
  31. ienable &= ~(1 << d->hwirq);
  32. WRCTL(CTL_IENABLE, ienable);
  33. }
  34. static struct irq_chip m_irq_chip = {
  35. .name = "NIOS2-INTC",
  36. .irq_unmask = chip_unmask,
  37. .irq_mask = chip_mask,
  38. };
  39. static int irq_map(struct irq_domain *h, unsigned int virq,
  40. irq_hw_number_t hw_irq_num)
  41. {
  42. irq_set_chip_and_handler(virq, &m_irq_chip, handle_level_irq);
  43. return 0;
  44. }
  45. static const struct irq_domain_ops irq_ops = {
  46. .map = irq_map,
  47. .xlate = irq_domain_xlate_onecell,
  48. };
  49. void __init init_IRQ(void)
  50. {
  51. struct irq_domain *domain;
  52. struct device_node *node;
  53. node = of_find_compatible_node(NULL, NULL, "altr,nios2-1.0");
  54. if (!node)
  55. node = of_find_compatible_node(NULL, NULL, "altr,nios2-1.1");
  56. BUG_ON(!node);
  57. domain = irq_domain_add_linear(node, NIOS2_CPU_NR_IRQS, &irq_ops, NULL);
  58. BUG_ON(!domain);
  59. irq_set_default_host(domain);
  60. of_node_put(node);
  61. /* Load the initial ienable value */
  62. ienable = RDCTL(CTL_IENABLE);
  63. }