dram.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <errno.h>
  8. #include <fdtdec.h>
  9. #include <asm/mtrr.h>
  10. #include <asm/post.h>
  11. #include <asm/arch/mrc.h>
  12. #include <asm/arch/msg_port.h>
  13. #include <asm/arch/quark.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. static int mrc_configure_params(struct mrc_params *mrc_params)
  16. {
  17. const void *blob = gd->fdt_blob;
  18. int node;
  19. int mrc_flags;
  20. node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_QRK_MRC);
  21. if (node < 0) {
  22. debug("%s: Cannot find MRC node\n", __func__);
  23. return -EINVAL;
  24. }
  25. /*
  26. * TODO:
  27. *
  28. * We need support fast boot (MRC cache) in the future.
  29. *
  30. * Set boot mode to cold boot for now
  31. */
  32. mrc_params->boot_mode = BM_COLD;
  33. /*
  34. * TODO:
  35. *
  36. * We need determine ECC by pin strap state
  37. *
  38. * Disable ECC by default for now
  39. */
  40. mrc_params->ecc_enables = 0;
  41. mrc_flags = fdtdec_get_int(blob, node, "flags", 0);
  42. if (mrc_flags & MRC_FLAG_SCRAMBLE_EN)
  43. mrc_params->scrambling_enables = 1;
  44. else
  45. mrc_params->scrambling_enables = 0;
  46. mrc_params->dram_width = fdtdec_get_int(blob, node, "dram-width", 0);
  47. mrc_params->ddr_speed = fdtdec_get_int(blob, node, "dram-speed", 0);
  48. mrc_params->ddr_type = fdtdec_get_int(blob, node, "dram-type", 0);
  49. mrc_params->rank_enables = fdtdec_get_int(blob, node, "rank-mask", 0);
  50. mrc_params->channel_enables = fdtdec_get_int(blob, node,
  51. "chan-mask", 0);
  52. mrc_params->channel_width = fdtdec_get_int(blob, node,
  53. "chan-width", 0);
  54. mrc_params->address_mode = fdtdec_get_int(blob, node, "addr-mode", 0);
  55. mrc_params->refresh_rate = fdtdec_get_int(blob, node,
  56. "refresh-rate", 0);
  57. mrc_params->sr_temp_range = fdtdec_get_int(blob, node,
  58. "sr-temp-range", 0);
  59. mrc_params->ron_value = fdtdec_get_int(blob, node,
  60. "ron-value", 0);
  61. mrc_params->rtt_nom_value = fdtdec_get_int(blob, node,
  62. "rtt-nom-value", 0);
  63. mrc_params->rd_odt_value = fdtdec_get_int(blob, node,
  64. "rd-odt-value", 0);
  65. mrc_params->params.density = fdtdec_get_int(blob, node,
  66. "dram-density", 0);
  67. mrc_params->params.cl = fdtdec_get_int(blob, node, "dram-cl", 0);
  68. mrc_params->params.ras = fdtdec_get_int(blob, node, "dram-ras", 0);
  69. mrc_params->params.wtr = fdtdec_get_int(blob, node, "dram-wtr", 0);
  70. mrc_params->params.rrd = fdtdec_get_int(blob, node, "dram-rrd", 0);
  71. mrc_params->params.faw = fdtdec_get_int(blob, node, "dram-faw", 0);
  72. debug("MRC dram_width %d\n", mrc_params->dram_width);
  73. debug("MRC rank_enables %d\n", mrc_params->rank_enables);
  74. debug("MRC ddr_speed %d\n", mrc_params->ddr_speed);
  75. debug("MRC flags: %s\n",
  76. (mrc_params->scrambling_enables) ? "SCRAMBLE_EN" : "");
  77. debug("MRC density=%d tCL=%d tRAS=%d tWTR=%d tRRD=%d tFAW=%d\n",
  78. mrc_params->params.density, mrc_params->params.cl,
  79. mrc_params->params.ras, mrc_params->params.wtr,
  80. mrc_params->params.rrd, mrc_params->params.faw);
  81. return 0;
  82. }
  83. int dram_init(void)
  84. {
  85. struct mrc_params mrc_params;
  86. int ret;
  87. memset(&mrc_params, 0, sizeof(struct mrc_params));
  88. ret = mrc_configure_params(&mrc_params);
  89. if (ret)
  90. return ret;
  91. /* Set up the DRAM by calling the memory reference code */
  92. mrc_init(&mrc_params);
  93. if (mrc_params.status)
  94. return -EIO;
  95. gd->ram_size = mrc_params.mem_size;
  96. post_code(POST_DRAM);
  97. /* variable range MTRR#2: RAM area */
  98. disable_caches();
  99. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYBASE(MTRR_VAR_RAM),
  100. 0 | MTRR_TYPE_WRBACK);
  101. msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYMASK(MTRR_VAR_RAM),
  102. (~(gd->ram_size - 1)) | MTRR_PHYS_MASK_VALID);
  103. enable_caches();
  104. return 0;
  105. }
  106. void dram_init_banksize(void)
  107. {
  108. gd->bd->bi_dram[0].start = 0;
  109. gd->bd->bi_dram[0].size = gd->ram_size;
  110. }
  111. /*
  112. * This function looks for the highest region of memory lower than 4GB which
  113. * has enough space for U-Boot where U-Boot is aligned on a page boundary.
  114. * It overrides the default implementation found elsewhere which simply
  115. * picks the end of ram, wherever that may be. The location of the stack,
  116. * the relocation address, and how far U-Boot is moved by relocation are
  117. * set in the global data structure.
  118. */
  119. ulong board_get_usable_ram_top(ulong total_size)
  120. {
  121. return gd->ram_size;
  122. }