mss_pm_ipc.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2018 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. * https://spdx.org/licenses
  6. */
  7. #include <string.h>
  8. #include <common/debug.h>
  9. #include <lib/psci/psci.h>
  10. #include <lib/mmio.h>
  11. #include <mss_pm_ipc.h>
  12. /*
  13. * SISR is 32 bit interrupt register representing 32 interrupts
  14. *
  15. * +======+=============+=============+
  16. * + Bits + 31 + 30 - 00 +
  17. * +======+=============+=============+
  18. * + Desc + MSS Msg Int + Reserved +
  19. * +======+=============+=============+
  20. */
  21. #define MSS_SISR (MVEBU_REGS_BASE + 0x5800D0)
  22. #define MSS_SISTR (MVEBU_REGS_BASE + 0x5800D8)
  23. #define MSS_MSG_INT_MASK (0x80000000)
  24. #define MSS_TIMER_BASE (MVEBU_REGS_BASE_MASK + 0x580110)
  25. #define MSS_TRIGGER_TIMEOUT (2000)
  26. /*****************************************************************************
  27. * mss_pm_ipc_msg_send
  28. *
  29. * DESCRIPTION: create and transmit IPC message
  30. *****************************************************************************
  31. */
  32. int mss_pm_ipc_msg_send(unsigned int channel_id, unsigned int msg_id,
  33. const psci_power_state_t *target_state)
  34. {
  35. /* Transmit IPC message */
  36. #ifndef DISABLE_CLUSTER_LEVEL
  37. mv_pm_ipc_msg_tx(channel_id, msg_id,
  38. (unsigned int)target_state->pwr_domain_state[
  39. MPIDR_AFFLVL1]);
  40. #else
  41. mv_pm_ipc_msg_tx(channel_id, msg_id, 0);
  42. #endif
  43. return 0;
  44. }
  45. /*****************************************************************************
  46. * mss_pm_ipc_msg_trigger
  47. *
  48. * DESCRIPTION: Trigger IPC message interrupt to MSS
  49. *****************************************************************************
  50. */
  51. int mss_pm_ipc_msg_trigger(void)
  52. {
  53. unsigned int timeout;
  54. unsigned int t_end;
  55. unsigned int t_start = mmio_read_32(MSS_TIMER_BASE);
  56. mmio_write_32(MSS_SISR, MSS_MSG_INT_MASK);
  57. do {
  58. /* wait while SCP process incoming interrupt */
  59. if (mmio_read_32(MSS_SISTR) != MSS_MSG_INT_MASK)
  60. break;
  61. /* check timeout */
  62. t_end = mmio_read_32(MSS_TIMER_BASE);
  63. timeout = ((t_start > t_end) ?
  64. (t_start - t_end) : (t_end - t_start));
  65. if (timeout > MSS_TRIGGER_TIMEOUT) {
  66. ERROR("PM MSG Trigger Timeout\n");
  67. break;
  68. }
  69. } while (1);
  70. return 0;
  71. }