dram_sub_func.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <lib/mmio.h>
  8. #include "dram_sub_func.h"
  9. #include "rcar_def.h"
  10. #if RCAR_SYSTEM_SUSPEND
  11. /* Local defines */
  12. #define DRAM_BACKUP_GPIO_USE 0
  13. #include "iic_dvfs.h"
  14. #if PMIC_ROHM_BD9571
  15. #define PMIC_SLAVE_ADDR 0x30U
  16. #define PMIC_BKUP_MODE_CNT 0x20U
  17. #define PMIC_QLLM_CNT 0x27U
  18. #define BIT_BKUP_CTRL_OUT BIT(4)
  19. #define BIT_QLLM_DDR0_EN BIT(0)
  20. #define BIT_QLLM_DDR1_EN BIT(1)
  21. #endif
  22. #define GPIO_BKUP_REQB_SHIFT_SALVATOR 9U /* GP1_9 (BKUP_REQB) */
  23. #define GPIO_BKUP_TRG_SHIFT_SALVATOR 8U /* GP1_8 (BKUP_TRG) */
  24. #define GPIO_BKUP_REQB_SHIFT_EBISU 14U /* GP6_14(BKUP_REQB) */
  25. #define GPIO_BKUP_TRG_SHIFT_EBISU 13U /* GP6_13(BKUP_TRG) */
  26. #define GPIO_BKUP_REQB_SHIFT_CONDOR 1U /* GP3_1 (BKUP_REQB) */
  27. #define GPIO_BKUP_TRG_SHIFT_CONDOR 0U /* GP3_0 (BKUP_TRG) */
  28. #define DRAM_BKUP_TRG_LOOP_CNT 1000U
  29. #endif
  30. void rcar_dram_get_boot_status(uint32_t *status)
  31. {
  32. #if RCAR_SYSTEM_SUSPEND
  33. uint32_t reg_data;
  34. uint32_t product;
  35. uint32_t shift;
  36. uint32_t gpio;
  37. product = mmio_read_32(PRR) & PRR_PRODUCT_MASK;
  38. if (product == PRR_PRODUCT_V3H) {
  39. shift = GPIO_BKUP_TRG_SHIFT_CONDOR;
  40. gpio = GPIO_INDT3;
  41. } else if (product == PRR_PRODUCT_E3) {
  42. shift = GPIO_BKUP_TRG_SHIFT_EBISU;
  43. gpio = GPIO_INDT6;
  44. } else {
  45. shift = GPIO_BKUP_TRG_SHIFT_SALVATOR;
  46. gpio = GPIO_INDT1;
  47. }
  48. reg_data = mmio_read_32(gpio);
  49. if (reg_data & BIT(shift))
  50. *status = DRAM_BOOT_STATUS_WARM;
  51. else
  52. *status = DRAM_BOOT_STATUS_COLD;
  53. #else /* RCAR_SYSTEM_SUSPEND */
  54. *status = DRAM_BOOT_STATUS_COLD;
  55. #endif /* RCAR_SYSTEM_SUSPEND */
  56. }
  57. int32_t rcar_dram_update_boot_status(uint32_t status)
  58. {
  59. int32_t ret = 0;
  60. #if RCAR_SYSTEM_SUSPEND
  61. uint32_t reg_data;
  62. #if PMIC_ROHM_BD9571
  63. #if DRAM_BACKUP_GPIO_USE == 0
  64. uint8_t bkup_mode_cnt = 0U;
  65. #else
  66. uint32_t reqb, outd;
  67. #endif
  68. uint8_t qllm_cnt = 0U;
  69. int32_t i2c_dvfs_ret = -1;
  70. #endif
  71. uint32_t loop_count;
  72. uint32_t product;
  73. uint32_t trg;
  74. uint32_t gpio;
  75. product = mmio_read_32(PRR) & PRR_PRODUCT_MASK;
  76. if (product == PRR_PRODUCT_V3H) {
  77. #if DRAM_BACKUP_GPIO_USE == 1
  78. reqb = GPIO_BKUP_REQB_SHIFT_CONDOR;
  79. outd = GPIO_OUTDT3;
  80. #endif
  81. trg = GPIO_BKUP_TRG_SHIFT_CONDOR;
  82. gpio = GPIO_INDT3;
  83. } else if (product == PRR_PRODUCT_E3) {
  84. #if DRAM_BACKUP_GPIO_USE == 1
  85. reqb = GPIO_BKUP_REQB_SHIFT_EBISU;
  86. outd = GPIO_OUTDT6;
  87. #endif
  88. trg = GPIO_BKUP_TRG_SHIFT_EBISU;
  89. gpio = GPIO_INDT6;
  90. } else {
  91. #if DRAM_BACKUP_GPIO_USE == 1
  92. reqb = GPIO_BKUP_REQB_SHIFT_SALVATOR;
  93. outd = GPIO_OUTDT1;
  94. #endif
  95. trg = GPIO_BKUP_TRG_SHIFT_SALVATOR;
  96. gpio = GPIO_INDT1;
  97. }
  98. if (status == DRAM_BOOT_STATUS_WARM) {
  99. #if DRAM_BACKUP_GPIO_USE == 1
  100. mmio_setbits_32(outd, BIT(reqb));
  101. #else
  102. #if PMIC_ROHM_BD9571
  103. /* Set BKUP_CRTL_OUT=High (BKUP mode cnt register) */
  104. i2c_dvfs_ret = rcar_iic_dvfs_receive(PMIC_SLAVE_ADDR,
  105. PMIC_BKUP_MODE_CNT,
  106. &bkup_mode_cnt);
  107. if (i2c_dvfs_ret) {
  108. ERROR("BKUP mode cnt READ ERROR.\n");
  109. ret = DRAM_UPDATE_STATUS_ERR;
  110. } else {
  111. bkup_mode_cnt &= (uint8_t)~BIT_BKUP_CTRL_OUT;
  112. i2c_dvfs_ret = rcar_iic_dvfs_send(PMIC_SLAVE_ADDR,
  113. PMIC_BKUP_MODE_CNT,
  114. bkup_mode_cnt);
  115. if (i2c_dvfs_ret) {
  116. ERROR("BKUP mode cnt WRITE ERROR. value = %d\n",
  117. bkup_mode_cnt);
  118. ret = DRAM_UPDATE_STATUS_ERR;
  119. }
  120. }
  121. #endif /* PMIC_ROHM_BD9571 */
  122. #endif /* DRAM_BACKUP_GPIO_USE == 1 */
  123. /* Wait BKUP_TRG=Low */
  124. loop_count = DRAM_BKUP_TRG_LOOP_CNT;
  125. while (loop_count > 0) {
  126. reg_data = mmio_read_32(gpio);
  127. if (!(reg_data & BIT(trg)))
  128. break;
  129. loop_count--;
  130. }
  131. if (!loop_count) {
  132. ERROR("\nWarm booting...\n"
  133. " The potential of BKUP_TRG did not switch to Low.\n"
  134. " If you expect the operation of cold boot,\n"
  135. " check the board configuration (ex, Dip-SW) and/or the H/W failure.\n");
  136. ret = DRAM_UPDATE_STATUS_ERR;
  137. }
  138. }
  139. #if PMIC_ROHM_BD9571
  140. if (!ret) {
  141. qllm_cnt = BIT_QLLM_DDR0_EN | BIT_QLLM_DDR1_EN;
  142. i2c_dvfs_ret = rcar_iic_dvfs_send(PMIC_SLAVE_ADDR,
  143. PMIC_QLLM_CNT,
  144. qllm_cnt);
  145. if (i2c_dvfs_ret) {
  146. ERROR("QLLM cnt WRITE ERROR. value = %d\n", qllm_cnt);
  147. ret = DRAM_UPDATE_STATUS_ERR;
  148. }
  149. }
  150. #endif
  151. #endif
  152. return ret;
  153. }