mt_spm_sspm_notifier.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2020, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stddef.h>
  7. #include <lib/mmio.h>
  8. #include <mt_spm_notifier.h>
  9. #include <mt_spm_sspm_intc.h>
  10. #define MT_SPM_SSPM_MBOX_OFF(x) (SSPM_MBOX_BASE + x)
  11. #define MT_SPM_MBOX(slot) MT_SPM_SSPM_MBOX_OFF((slot << 2UL))
  12. #define SSPM_MBOX_SPM_LP_LOOKUP1 MT_SPM_MBOX(0)
  13. #define SSPM_MBOX_SPM_LP_LOOKUP2 MT_SPM_MBOX(1)
  14. #define SSPM_MBOX_SPM_LP1 MT_SPM_MBOX(2)
  15. #define SSPM_MBOX_SPM_LP2 MT_SPM_MBOX(3)
  16. #define MCUPM_MBOX_OFFSET_LP 0x0C55FDA4
  17. #define MCUPM_MBOX_ENTER_LP 0x454e0000
  18. #define MCUPM_MBOX_LEAVE_LP 0x4c450000
  19. #define MCUPM_MBOX_SLEEP_MASK 0x0000FFFF
  20. int mt_spm_sspm_notify(int type, unsigned int lp_mode)
  21. {
  22. switch (type) {
  23. case MT_SPM_NOTIFY_LP_ENTER:
  24. mmio_write_32(SSPM_MBOX_SPM_LP1, lp_mode);
  25. mmio_write_32(MCUPM_MBOX_OFFSET_LP, MCUPM_MBOX_ENTER_LP |
  26. (lp_mode & MCUPM_MBOX_SLEEP_MASK));
  27. DO_SPM_SSPM_LP_SUSPEND();
  28. break;
  29. case MT_SPM_NOTIFY_LP_LEAVE:
  30. mmio_write_32(SSPM_MBOX_SPM_LP1, lp_mode);
  31. mmio_write_32(MCUPM_MBOX_OFFSET_LP, MCUPM_MBOX_LEAVE_LP |
  32. (lp_mode & MCUPM_MBOX_SLEEP_MASK));
  33. DO_SPM_SSPM_LP_RESUME();
  34. break;
  35. default:
  36. break;
  37. }
  38. return 0;
  39. }