plat_ddr.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 2024, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <errno.h>
  7. #include <drivers/st/regulator.h>
  8. #include <drivers/st/stm32mp_ddr.h>
  9. #include <drivers/st/stm32mp_pmic.h>
  10. /* configure the STPMIC1 regulators on STMicroelectronics boards */
  11. static int pmic_ddr_power_init(enum ddr_type ddr_type)
  12. {
  13. int status;
  14. uint16_t buck3_min_mv __maybe_unused;
  15. struct rdev *buck2, *buck3 __maybe_unused, *vref;
  16. struct rdev *ldo3 __maybe_unused;
  17. buck2 = regulator_get_by_name("buck2");
  18. if (buck2 == NULL) {
  19. return -ENOENT;
  20. }
  21. #if STM32MP15
  22. ldo3 = regulator_get_by_name("ldo3");
  23. if (ldo3 == NULL) {
  24. return -ENOENT;
  25. }
  26. #endif
  27. vref = regulator_get_by_name("vref_ddr");
  28. if (vref == NULL) {
  29. return -ENOENT;
  30. }
  31. switch (ddr_type) {
  32. case STM32MP_DDR3:
  33. #if STM32MP15
  34. status = regulator_set_flag(ldo3, REGUL_SINK_SOURCE);
  35. if (status != 0) {
  36. return status;
  37. }
  38. #endif
  39. status = regulator_set_min_voltage(buck2);
  40. if (status != 0) {
  41. return status;
  42. }
  43. status = regulator_enable(buck2);
  44. if (status != 0) {
  45. return status;
  46. }
  47. status = regulator_enable(vref);
  48. if (status != 0) {
  49. return status;
  50. }
  51. #if STM32MP15
  52. status = regulator_enable(ldo3);
  53. if (status != 0) {
  54. return status;
  55. }
  56. #endif
  57. break;
  58. case STM32MP_LPDDR2:
  59. case STM32MP_LPDDR3:
  60. #if STM32MP15
  61. /*
  62. * Set LDO3 to 1.8V according BUCK3 voltage
  63. * => bypass mode if BUCK3 = 1.8V
  64. * => normal mode if BUCK3 != 1.8V
  65. */
  66. buck3 = regulator_get_by_name("buck3");
  67. if (buck3 == NULL) {
  68. return -ENOENT;
  69. }
  70. regulator_get_range(buck3, &buck3_min_mv, NULL);
  71. if (buck3_min_mv != 1800) {
  72. status = regulator_set_min_voltage(ldo3);
  73. if (status != 0) {
  74. return status;
  75. }
  76. } else {
  77. status = regulator_set_flag(ldo3, REGUL_ENABLE_BYPASS);
  78. if (status != 0) {
  79. return status;
  80. }
  81. }
  82. #endif
  83. status = regulator_set_min_voltage(buck2);
  84. if (status != 0) {
  85. return status;
  86. }
  87. #if STM32MP15
  88. status = regulator_enable(ldo3);
  89. if (status != 0) {
  90. return status;
  91. }
  92. #endif
  93. status = regulator_enable(buck2);
  94. if (status != 0) {
  95. return status;
  96. }
  97. status = regulator_enable(vref);
  98. if (status != 0) {
  99. return status;
  100. }
  101. break;
  102. default:
  103. break;
  104. };
  105. return 0;
  106. }
  107. int stm32mp_board_ddr_power_init(enum ddr_type ddr_type)
  108. {
  109. if (dt_pmic_status() > 0) {
  110. return pmic_ddr_power_init(ddr_type);
  111. }
  112. return 0;
  113. }