ddr3_hws_hw_training.c 3.6 KB

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