memoryOperation.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * OMAP2+ common Power & Reset Management (PRM) IP block functions
  3. *
  4. * Copyright (C) 2011 Texas Instruments, Inc.
  5. * Tero Kristo <t-kristo@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. *
  12. * For historical purposes, the API used to configure the PRM
  13. * interrupt handler refers to it as the "PRCM interrupt." The
  14. * underlying registers are located in the PRM on OMAP3/4.
  15. *
  16. * XXX This code should eventually be moved to a PRM driver.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/io.h>
  22. #include <linux/irq.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/slab.h>
  25. #include "prm2xxx_3xxx.h"
  26. #include "prm2xxx.h"
  27. #include "prm3xxx.h"
  28. #include "prm44xx.h"
  29. #include "common.h"
  30. /*
  31. * OMAP_PRCM_MAX_NR_PENDING_REG: maximum number of PRM_IRQ*_MPU regs
  32. * XXX this is technically not needed, since
  33. * omap_prcm_register_chain_handler() could allocate this based on the
  34. * actual amount of memory needed for the SoC
  35. */
  36. #define OMAP_PRCM_MAX_NR_PENDING_REG 2
  37. /*
  38. * prcm_irq_chips: an array of all of the "generic IRQ chips" in use
  39. * by the PRCM interrupt handler code. There will be one 'chip' per
  40. * PRM_{IRQSTATUS,IRQENABLE}_MPU register pair. (So OMAP3 will have
  41. * one "chip" and OMAP4 will have two.)
  42. */
  43. static struct irq_chip_generic **prcm_irq_chips;
  44. /*
  45. * prcm_irq_setup: the PRCM IRQ parameters for the hardware the code
  46. * is currently running on. Defined and passed by initialization code
  47. * that calls omap_prcm_register_chain_handler().
  48. */
  49. static struct omap_prcm_irq_setup *prcm_irq_setup;
  50. /* prm_base: base virtual address of the PRM IP block */
  51. void __iomem *prm_base;
  52. /*
  53. * prm_ll_data: function pointers to SoC-specific implementations of
  54. * common PRM functions
  55. */
  56. static struct prm_ll_data null_prm_ll_data;
  57. static struct prm_ll_data *prm_ll_data = &null_prm_ll_data;
  58. /* Private functions */
  59. /*
  60. * Move priority events from events to priority_events array
  61. */
  62. static void omap_prcm_events_filter_priority(unsigned long *events,
  63. unsigned long *priority_events)
  64. {
  65. int i;
  66. for (i = 0; i < prcm_irq_setup->nr_regs; i++) {
  67. priority_events[i] =
  68. events[i] & prcm_irq_setup->priority_mask[i];
  69. events[i] ^= priority_events[i];
  70. }
  71. }
  72. /*
  73. * PRCM Interrupt Handler
  74. *
  75. * This is a common handler for the OMAP PRCM interrupts. Pending
  76. * interrupts are detected by a call to prcm_pending_events and
  77. * dispatched accordingly. Clearing of the wakeup events should be
  78. * done by the SoC specific individual handlers.
  79. */
  80. static void omap_prcm_irq_handler(unsigned int irq, struct irq_desc *desc)
  81. {
  82. unsigned long pending[OMAP_PRCM_MAX_NR_PENDING_REG];
  83. unsigned long priority_pending[OMAP_PRCM_MAX_NR_PENDING_REG];
  84. struct irq_chip *chip = irq_desc_get_chip(desc);
  85. unsigned int virtirq;
  86. int nr_irq = prcm_irq_setup->nr_regs * 32;
  87. /*
  88. * If we are suspended, mask all interrupts from PRCM level,
  89. * this does not ack them, and they will be pending until we
  90. * re-enable the interrupts, at which point the
  91. * omap_prcm_irq_handler will be executed again. The
  92. * _save_and_clear_irqen() function must ensure that the PRM
  93. * write to disable all IRQs has reached the PRM before
  94. * returning, or spurious PRCM interrupts may occur during
  95. * suspend.
  96. */
  97. if (prcm_irq_setup->suspended) {
  98. prcm_irq_setup->save_and_clear_irqen(prcm_irq_setup->saved_mask);
  99. prcm_irq_setup->suspend_save_flag = true;
  100. }
  101. /*
  102. * Loop until all pending irqs are handled, since
  103. * generic_handle_irq() can cause new irqs to come
  104. */
  105. while (!prcm_irq_setup->suspended) {
  106. prcm_irq_setup->read_pending_irqs(pending);
  107. /* No bit set, then all IRQs are handled */
  108. if (find_first_bit(pending, nr_irq) >= nr_irq)
  109. break;
  110. omap_prcm_events_filter_priority(pending, priority_pending);
  111. /*
  112. * Loop on all currently pending irqs so that new irqs
  113. * cannot starve previously pending irqs
  114. */
  115. /* Serve priority events first */
  116. for_each_set_bit(virtirq, priority_pending, nr_irq)
  117. generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
  118. /* Serve normal events next */
  119. for_each_set_bit(virtirq, pending, nr_irq)
  120. generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
  121. }
  122. if (chip->irq_ack)
  123. chip->irq_ack(&desc->irq_data);
  124. if (chip->irq_eoi)
  125. chip->irq_eoi(&desc->irq_data);
  126. chip->irq_unmask(&desc->irq_data);