ipr.c 2.6 KB

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