ipr.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Interrupt handling for IPR-based IRQ.
  4. *
  5. * Copyright (C) 1999 Niibe Yutaka & Takeshi Yaegashi
  6. * Copyright (C) 2000 Kazumoto Kojima
  7. * Copyright (C) 2003 Takashi Kusuda <[email protected]>
  8. * Copyright (C) 2006 Paul Mundt
  9. *
  10. * Supported system:
  11. * On-chip supporting modules (TMU, RTC, etc.).
  12. * On-chip supporting modules for SH7709/SH7709A/SH7729.
  13. * Hitachi SolutionEngine external I/O:
  14. * MS7709SE01, MS7709ASE01, and MS7750SE01
  15. */
  16. #include <linux/init.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/io.h>
  19. #include <linux/irq.h>
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/topology.h>
  23. static inline struct ipr_desc *get_ipr_desc(struct irq_data *data)
  24. {
  25. struct irq_chip *chip = irq_data_get_irq_chip(data);
  26. return container_of(chip, struct ipr_desc, chip);
  27. }
  28. static void disable_ipr_irq(struct irq_data *data)
  29. {
  30. struct ipr_data *p = irq_data_get_irq_chip_data(data);
  31. unsigned long addr = get_ipr_desc(data)->ipr_offsets[p->ipr_idx];
  32. /* Set the priority in IPR to 0 */
  33. __raw_writew(__raw_readw(addr) & (0xffff ^ (0xf << p->shift)), addr);
  34. (void)__raw_readw(addr); /* Read back to flush write posting */
  35. }
  36. static void enable_ipr_irq(struct irq_data *data)
  37. {
  38. struct ipr_data *p = irq_data_get_irq_chip_data(data);
  39. unsigned long addr = get_ipr_desc(data)->ipr_offsets[p->ipr_idx];
  40. /* Set priority in IPR back to original value */
  41. __raw_writew(__raw_readw(addr) | (p->priority << p->shift), addr);
  42. }
  43. /*
  44. * The shift value is now the number of bits to shift, not the number of
  45. * bits/4. This is to make it easier to read the value directly from the
  46. * datasheets. The IPR address is calculated using the ipr_offset table.
  47. */
  48. void register_ipr_controller(struct ipr_desc *desc)
  49. {
  50. int i;
  51. desc->chip.irq_mask = disable_ipr_irq;
  52. desc->chip.irq_unmask = enable_ipr_irq;
  53. for (i = 0; i < desc->nr_irqs; i++) {
  54. struct ipr_data *p = desc->ipr_data + i;
  55. int res;
  56. BUG_ON(p->ipr_idx >= desc->nr_offsets);
  57. BUG_ON(!desc->ipr_offsets[p->ipr_idx]);
  58. res = irq_alloc_desc_at(p->irq, numa_node_id());
  59. if (unlikely(res != p->irq && res != -EEXIST)) {
  60. printk(KERN_INFO "can not get irq_desc for %d\n",
  61. p->irq);
  62. continue;
  63. }
  64. disable_irq_nosync(p->irq);
  65. irq_set_chip_and_handler_name(p->irq, &desc->chip,
  66. handle_level_irq, "level");
  67. irq_set_chip_data(p->irq, p);
  68. disable_ipr_irq(irq_get_irq_data(p->irq));
  69. }
  70. }
  71. EXPORT_SYMBOL(register_ipr_controller);