imx8_mu.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <lib/mmio.h>
  7. #include "imx8_mu.h"
  8. void MU_Resume(uint32_t base)
  9. {
  10. uint32_t reg, i;
  11. reg = mmio_read_32(base + MU_ACR_OFFSET1);
  12. /* Clear GIEn, RIEn, TIEn, GIRn and ABFn. */
  13. reg &= ~(MU_CR_GIEn_MASK1 | MU_CR_RIEn_MASK1 | MU_CR_TIEn_MASK1
  14. | MU_CR_GIRn_MASK1 | MU_CR_Fn_MASK1);
  15. mmio_write_32(base + MU_ACR_OFFSET1, reg);
  16. /* Enable all RX interrupts */
  17. for (i = 0; i < MU_RR_COUNT; i++)
  18. MU_EnableRxFullInt(base, i);
  19. }
  20. void MU_EnableRxFullInt(uint32_t base, uint32_t index)
  21. {
  22. uint32_t reg = mmio_read_32(base + MU_ACR_OFFSET1);
  23. reg &= ~(MU_CR_GIRn_MASK1 | MU_CR_NMI_MASK1);
  24. reg |= MU_CR_RIE0_MASK1 >> index;
  25. mmio_write_32(base + MU_ACR_OFFSET1, reg);
  26. }
  27. void MU_EnableGeneralInt(uint32_t base, uint32_t index)
  28. {
  29. uint32_t reg = mmio_read_32(base + MU_ACR_OFFSET1);
  30. reg &= ~(MU_CR_GIRn_MASK1 | MU_CR_NMI_MASK1);
  31. reg |= MU_CR_GIE0_MASK1 >> index;
  32. mmio_write_32(base + MU_ACR_OFFSET1, reg);
  33. }
  34. void MU_SendMessage(uint32_t base, uint32_t regIndex, uint32_t msg)
  35. {
  36. uint32_t mask = MU_SR_TE0_MASK1 >> regIndex;
  37. /* Wait TX register to be empty. */
  38. while (!(mmio_read_32(base + MU_ASR_OFFSET1) & mask))
  39. ;
  40. mmio_write_32(base + MU_ATR0_OFFSET1 + (regIndex * 4), msg);
  41. }
  42. void MU_ReceiveMsg(uint32_t base, uint32_t regIndex, uint32_t *msg)
  43. {
  44. uint32_t mask = MU_SR_RF0_MASK1 >> regIndex;
  45. /* Wait RX register to be full. */
  46. while (!(mmio_read_32(base + MU_ASR_OFFSET1) & mask))
  47. ;
  48. *msg = mmio_read_32(base + MU_ARR0_OFFSET1 + (regIndex * 4));
  49. }
  50. void MU_Init(uint32_t base)
  51. {
  52. uint32_t reg;
  53. reg = mmio_read_32(base + MU_ACR_OFFSET1);
  54. /* Clear GIEn, RIEn, TIEn, GIRn and ABFn. */
  55. reg &= ~(MU_CR_GIEn_MASK1 | MU_CR_RIEn_MASK1 | MU_CR_TIEn_MASK1
  56. | MU_CR_GIRn_MASK1 | MU_CR_Fn_MASK1);
  57. mmio_write_32(base + MU_ACR_OFFSET1, reg);
  58. }