ddr3_hws_hw_training.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) Marvell International Ltd. and its affiliates
  4. */
  5. #include <common.h>
  6. #include <i2c.h>
  7. #include <spl.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/cpu.h>
  10. #include <asm/arch/soc.h>
  11. #include "ddr3_init.h"
  12. #define REG_READ_DATA_SAMPLE_DELAYS_ADDR 0x1538
  13. #define REG_READ_DATA_SAMPLE_DELAYS_MASK 0x1f
  14. #define REG_READ_DATA_SAMPLE_DELAYS_OFFS 8
  15. #define REG_READ_DATA_READY_DELAYS_ADDR 0x153c
  16. #define REG_READ_DATA_READY_DELAYS_MASK 0x1f
  17. #define REG_READ_DATA_READY_DELAYS_OFFS 8
  18. int ddr3_if_ecc_enabled(void)
  19. {
  20. struct hws_topology_map *tm = ddr3_get_topology_map();
  21. if (DDR3_IS_ECC_PUP4_MODE(tm->bus_act_mask) ||
  22. DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask))
  23. return 1;
  24. else
  25. return 0;
  26. }
  27. int ddr3_pre_algo_config(void)
  28. {
  29. struct hws_topology_map *tm = ddr3_get_topology_map();
  30. /* Set Bus3 ECC training mode */
  31. if (DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask)) {
  32. /* Set Bus3 ECC MUX */
  33. CHECK_STATUS(ddr3_tip_if_write
  34. (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
  35. REG_SDRAM_PINS_MUX, 0x100, 0x100));
  36. }
  37. /* Set regular ECC training mode (bus4 and bus 3) */
  38. if ((DDR3_IS_ECC_PUP4_MODE(tm->bus_act_mask)) ||
  39. (DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask))) {
  40. /* Enable ECC Write MUX */
  41. CHECK_STATUS(ddr3_tip_if_write
  42. (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
  43. TRAINING_SW_2_REG, 0x100, 0x100));
  44. /* General ECC enable */
  45. CHECK_STATUS(ddr3_tip_if_write
  46. (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
  47. REG_SDRAM_CONFIG_ADDR, 0x40000, 0x40000));
  48. /* Disable Read Data ECC MUX */
  49. CHECK_STATUS(ddr3_tip_if_write
  50. (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
  51. TRAINING_SW_2_REG, 0x0, 0x2));
  52. }
  53. return MV_OK;
  54. }
  55. int ddr3_post_algo_config(void)
  56. {
  57. struct hws_topology_map *tm = ddr3_get_topology_map();
  58. int status;
  59. status = ddr3_post_run_alg();
  60. if (MV_OK != status) {
  61. printf("DDR3 Post Run Alg - FAILED 0x%x\n", status);
  62. return status;
  63. }
  64. /* Un_set ECC training mode */
  65. if ((DDR3_IS_ECC_PUP4_MODE(tm->bus_act_mask)) ||
  66. (DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask))) {
  67. /* Disable ECC Write MUX */
  68. CHECK_STATUS(ddr3_tip_if_write
  69. (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
  70. TRAINING_SW_2_REG, 0x0, 0x100));
  71. /* General ECC and Bus3 ECC MUX remains enabled */
  72. }
  73. return MV_OK;
  74. }
  75. int ddr3_hws_hw_training(void)
  76. {
  77. enum hws_algo_type algo_mode = ALGO_TYPE_DYNAMIC;
  78. int status;
  79. struct init_cntr_param init_param;
  80. status = ddr3_silicon_pre_init();
  81. if (MV_OK != status) {
  82. printf("DDR3 Pre silicon Config - FAILED 0x%x\n", status);
  83. return status;
  84. }
  85. init_param.do_mrs_phy = 1;
  86. #if defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_39X)
  87. init_param.is_ctrl64_bit = 0;
  88. #else
  89. init_param.is_ctrl64_bit = 1;
  90. #endif
  91. #if defined(CONFIG_ALLEYCAT3) || defined(CONFIG_ARMADA_38X) || \
  92. defined(CONFIG_ARMADA_39X)
  93. init_param.init_phy = 1;
  94. #else
  95. init_param.init_phy = 0;
  96. #endif
  97. init_param.msys_init = 1;
  98. status = hws_ddr3_tip_init_controller(0, &init_param);
  99. if (MV_OK != status) {
  100. printf("DDR3 init controller - FAILED 0x%x\n", status);
  101. return status;
  102. }
  103. status = ddr3_silicon_post_init();
  104. if (MV_OK != status) {
  105. printf("DDR3 Post Init - FAILED 0x%x\n", status);
  106. return status;
  107. }
  108. status = ddr3_pre_algo_config();
  109. if (MV_OK != status) {
  110. printf("DDR3 Pre Algo Config - FAILED 0x%x\n", status);
  111. return status;
  112. }
  113. /* run algorithm in order to configure the PHY */
  114. status = hws_ddr3_tip_run_alg(0, algo_mode);
  115. if (MV_OK != status) {
  116. printf("DDR3 run algorithm - FAILED 0x%x\n", status);
  117. return status;
  118. }
  119. status = ddr3_post_algo_config();
  120. if (MV_OK != status) {
  121. printf("DDR3 Post Algo Config - FAILED 0x%x\n", status);
  122. return status;
  123. }
  124. return MV_OK;
  125. }