/drivers/staging/westbridge/astoria/api/src/cyasintr.c

https://bitbucket.org/wisechild/galaxy-nexus · C · 143 lines · 80 code · 30 blank · 33 comment · 18 complexity · a42b3ec087b7fae7871c4c38e027f651 MD5 · raw file

  1. /* Cypress West Bridge API source file (cyasintr.c)
  2. ## ===========================
  3. ## Copyright (C) 2010 Cypress Semiconductor
  4. ##
  5. ## This program is free software; you can redistribute it and/or
  6. ## modify it under the terms of the GNU General Public License
  7. ## as published by the Free Software Foundation; either version 2
  8. ## of the License, or (at your option) any later version.
  9. ##
  10. ## This program is distributed in the hope that it will be useful,
  11. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ## GNU General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with this program; if not, write to the Free Software
  17. ## Foundation, Inc., 51 Franklin Street, Fifth Floor
  18. ## Boston, MA 02110-1301, USA.
  19. ## ===========================
  20. */
  21. #include "../../include/linux/westbridge/cyashal.h"
  22. #include "../../include/linux/westbridge/cyasdevice.h"
  23. #include "../../include/linux/westbridge/cyasregs.h"
  24. #include "../../include/linux/westbridge/cyaserr.h"
  25. extern void cy_as_mail_box_interrupt_handler(cy_as_device *);
  26. void
  27. cy_as_mcu_interrupt_handler(cy_as_device *dev_p)
  28. {
  29. /* Read and clear the interrupt. */
  30. uint16_t v;
  31. v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_P0_MCU_STAT);
  32. v = v;
  33. }
  34. void
  35. cy_as_power_management_interrupt_handler(cy_as_device *dev_p)
  36. {
  37. uint16_t v;
  38. v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_PWR_MAGT_STAT);
  39. v = v;
  40. }
  41. void
  42. cy_as_pll_lock_loss_interrupt_handler(cy_as_device *dev_p)
  43. {
  44. uint16_t v;
  45. v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_PLL_LOCK_LOSS_STAT);
  46. v = v;
  47. }
  48. uint32_t cy_as_intr_start(cy_as_device *dev_p, cy_bool dmaintr)
  49. {
  50. uint16_t v;
  51. cy_as_hal_assert(dev_p->sig == CY_AS_DEVICE_HANDLE_SIGNATURE);
  52. if (cy_as_device_is_intr_running(dev_p) != 0)
  53. return CY_AS_ERROR_ALREADY_RUNNING;
  54. v = CY_AS_MEM_P0_INT_MASK_REG_MMCUINT |
  55. CY_AS_MEM_P0_INT_MASK_REG_MMBINT |
  56. CY_AS_MEM_P0_INT_MASK_REG_MPMINT;
  57. if (dmaintr)
  58. v |= CY_AS_MEM_P0_INT_MASK_REG_MDRQINT;
  59. /* Enable the interrupts of interest */
  60. cy_as_hal_write_register(dev_p->tag, CY_AS_MEM_P0_INT_MASK_REG, v);
  61. /* Mark the interrupt module as initialized */
  62. cy_as_device_set_intr_running(dev_p);
  63. return CY_AS_ERROR_SUCCESS;
  64. }
  65. uint32_t cy_as_intr_stop(cy_as_device *dev_p)
  66. {
  67. cy_as_hal_assert(dev_p->sig == CY_AS_DEVICE_HANDLE_SIGNATURE);
  68. if (cy_as_device_is_intr_running(dev_p) == 0)
  69. return CY_AS_ERROR_NOT_RUNNING;
  70. cy_as_hal_write_register(dev_p->tag, CY_AS_MEM_P0_INT_MASK_REG, 0);
  71. cy_as_device_set_intr_stopped(dev_p);
  72. return CY_AS_ERROR_SUCCESS;
  73. }
  74. void cy_as_intr_service_interrupt(cy_as_hal_device_tag tag)
  75. {
  76. uint16_t v;
  77. cy_as_device *dev_p;
  78. dev_p = cy_as_device_find_from_tag(tag);
  79. /*
  80. * only power management interrupts can occur before the
  81. * antioch API setup is complete. if this is a PM interrupt
  82. * handle it here; otherwise output a warning message.
  83. */
  84. if (dev_p == 0) {
  85. v = cy_as_hal_read_register(tag, CY_AS_MEM_P0_INTR_REG);
  86. if (v == CY_AS_MEM_P0_INTR_REG_PMINT) {
  87. /* Read the PWR_MAGT_STAT register
  88. * to clear this interrupt. */
  89. v = cy_as_hal_read_register(tag,
  90. CY_AS_MEM_PWR_MAGT_STAT);
  91. } else
  92. cy_as_hal_print_message("stray antioch "
  93. "interrupt detected"
  94. ", tag not associated "
  95. "with any created device.");
  96. return;
  97. }
  98. /* Make sure we got a valid object from CyAsDeviceFindFromTag */
  99. cy_as_hal_assert(dev_p->sig == CY_AS_DEVICE_HANDLE_SIGNATURE);
  100. v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_P0_INTR_REG);
  101. if (v & CY_AS_MEM_P0_INTR_REG_MCUINT)
  102. cy_as_mcu_interrupt_handler(dev_p);
  103. if (v & CY_AS_MEM_P0_INTR_REG_PMINT)
  104. cy_as_power_management_interrupt_handler(dev_p);
  105. if (v & CY_AS_MEM_P0_INTR_REG_PLLLOCKINT)
  106. cy_as_pll_lock_loss_interrupt_handler(dev_p);
  107. /* If the interrupt module is not running, no mailbox
  108. * interrupts are expected from the west bridge. */
  109. if (cy_as_device_is_intr_running(dev_p) == 0)
  110. return;
  111. if (v & CY_AS_MEM_P0_INTR_REG_MBINT)
  112. cy_as_mail_box_interrupt_handler(dev_p);
  113. }