mc_rgm.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2023-2024 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <lib/mmio.h>
  7. #include <lib/utils_def.h>
  8. #include <s32cc-mc-rgm.h>
  9. #define MC_RGM_PRST(RGM, PER) ((RGM) + 0x40UL + ((PER) * 0x8UL))
  10. #define MC_RGM_PRST_PERIPH_N_RST(PER) BIT_32(PER)
  11. #define MC_RGM_PSTAT(RGM, PER) ((RGM) + 0x140UL + ((PER) * 0x8UL))
  12. #define MC_RGM_PSTAT_PERIPH(PER) BIT_32(PER)
  13. /* ERR051700
  14. * Releasing more than one Software Resettable Domain (SRD)
  15. * from reset simultaneously, by clearing the corresponding
  16. * peripheral MC_RGM_PRSTn[PERIPH_x_RST] reset control may
  17. * cause a false setting of the Fault Collection and
  18. * Control Unit (FCCU) Non-Critical Fault (NCF) flag
  19. * corresponding to a Memory-Test-Repair (MTR) Error
  20. */
  21. #if (ERRATA_S32_051700 == 1)
  22. void mc_rgm_periph_reset(uintptr_t rgm, uint32_t part, uint32_t value)
  23. {
  24. uint32_t current_bit_checked, i;
  25. uint32_t current_regs, mask;
  26. int bit_index;
  27. current_regs = mmio_read_32(MC_RGM_PRST(rgm, part));
  28. /* Create a mask with all changed bits */
  29. mask = current_regs ^ value;
  30. while (mask != 0U) {
  31. bit_index = __builtin_ffs(mask);
  32. if (bit_index < 1) {
  33. break;
  34. }
  35. i = (uint32_t)bit_index - 1U;
  36. current_bit_checked = BIT_32(i);
  37. /* Check if we assert or de-assert.
  38. * Also wait for completion.
  39. */
  40. if ((value & current_bit_checked) != 0U) {
  41. mmio_setbits_32(MC_RGM_PRST(rgm, part),
  42. current_bit_checked);
  43. while ((mmio_read_32(MC_RGM_PRST(rgm, part)) &
  44. current_bit_checked) == 0U)
  45. ;
  46. } else {
  47. mmio_clrbits_32(MC_RGM_PRST(rgm, part),
  48. current_bit_checked);
  49. while ((mmio_read_32(MC_RGM_PRST(rgm, part)) &
  50. current_bit_checked) != 0U)
  51. ;
  52. }
  53. mask &= ~current_bit_checked;
  54. }
  55. }
  56. #else /* ERRATA_S32_051700 */
  57. void mc_rgm_periph_reset(uintptr_t rgm, uint32_t part, uint32_t value)
  58. {
  59. mmio_write_32(MC_RGM_PRST(rgm, part), value);
  60. }
  61. #endif /* ERRATA_S32_051700 */
  62. void mc_rgm_release_part(uintptr_t rgm, uint32_t part)
  63. {
  64. uint32_t reg;
  65. reg = mmio_read_32(MC_RGM_PRST(rgm, part));
  66. reg &= ~MC_RGM_PRST_PERIPH_N_RST(0);
  67. mc_rgm_periph_reset(rgm, part, reg);
  68. }
  69. void mc_rgm_wait_part_deassert(uintptr_t rgm, uint32_t part)
  70. {
  71. while ((mmio_read_32(MC_RGM_PSTAT(rgm, part)) &
  72. MC_RGM_PSTAT_PERIPH(0)) != 0U) {
  73. }
  74. }