ddr.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * Copyright 2011-2012 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * Version 2 or later as published by the Free Software Foundation.
  7. */
  8. #include <common.h>
  9. #include <i2c.h>
  10. #include <hwconfig.h>
  11. #include <asm/mmu.h>
  12. #include <asm/fsl_ddr_sdram.h>
  13. #include <asm/fsl_ddr_dimm_params.h>
  14. #include <asm/fsl_law.h>
  15. #include <../arch/powerpc/cpu/mpc8xxx/ddr/ddr.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. dimm_params_t ddr_raw_timing = {
  18. .n_ranks = 2,
  19. .rank_density = 2147483648u,
  20. .capacity = 4294967296u,
  21. .primary_sdram_width = 64,
  22. .ec_sdram_width = 8,
  23. .registered_dimm = 0,
  24. .mirrored_dimm = 1,
  25. .n_row_addr = 15,
  26. .n_col_addr = 10,
  27. .n_banks_per_sdram_device = 8,
  28. .edc_config = 2, /* ECC */
  29. .burst_lengths_bitmask = 0x0c,
  30. .tckmin_x_ps = 1071,
  31. .caslat_x = 0x2fe << 4, /* 5,6,7,8,9,10,11,13 */
  32. .taa_ps = 13910,
  33. .twr_ps = 15000,
  34. .trcd_ps = 13910,
  35. .trrd_ps = 6000,
  36. .trp_ps = 13910,
  37. .tras_ps = 34000,
  38. .trc_ps = 48910,
  39. .trfc_ps = 260000,
  40. .twtr_ps = 7500,
  41. .trtp_ps = 7500,
  42. .refresh_rate_ps = 7800000,
  43. .tfaw_ps = 35000,
  44. };
  45. int fsl_ddr_get_dimm_params(dimm_params_t *pdimm,
  46. unsigned int controller_number,
  47. unsigned int dimm_number)
  48. {
  49. const char dimm_model[] = "RAW timing DDR";
  50. if ((controller_number == 0) && (dimm_number == 0)) {
  51. memcpy(pdimm, &ddr_raw_timing, sizeof(dimm_params_t));
  52. memset(pdimm->mpart, 0, sizeof(pdimm->mpart));
  53. memcpy(pdimm->mpart, dimm_model, sizeof(dimm_model) - 1);
  54. }
  55. return 0;
  56. }
  57. struct board_specific_parameters {
  58. u32 n_ranks;
  59. u32 datarate_mhz_high;
  60. u32 clk_adjust;
  61. u32 wrlvl_start;
  62. u32 wrlvl_ctl_2;
  63. u32 wrlvl_ctl_3;
  64. u32 cpo;
  65. u32 write_data_delay;
  66. u32 force_2t;
  67. };
  68. /*
  69. * This table contains all valid speeds we want to override with board
  70. * specific parameters. datarate_mhz_high values need to be in ascending order
  71. * for each n_ranks group.
  72. */
  73. static const struct board_specific_parameters udimm0[] = {
  74. /*
  75. * memory controller 0
  76. * num| hi| clk| wrlvl | wrlvl | wrlvl | cpo |wrdata|2T
  77. * ranks| mhz|adjst| start | ctl2 | ctl3 | |delay |
  78. */
  79. {2, 1350, 4, 7, 0x09080807, 0x07060607, 0xff, 2, 0},
  80. {2, 1666, 4, 7, 0x09080806, 0x06050607, 0xff, 2, 0},
  81. {2, 1900, 3, 7, 0x08070706, 0x06040507, 0xff, 2, 0},
  82. {1, 1350, 4, 7, 0x09080807, 0x07060607, 0xff, 2, 0},
  83. {1, 1700, 4, 7, 0x09080806, 0x06050607, 0xff, 2, 0},
  84. {1, 1900, 3, 7, 0x08070706, 0x06040507, 0xff, 2, 0},
  85. {}
  86. };
  87. static const struct board_specific_parameters *udimms[] = {
  88. udimm0,
  89. };
  90. void fsl_ddr_board_options(memctl_options_t *popts,
  91. dimm_params_t *pdimm,
  92. unsigned int ctrl_num)
  93. {
  94. const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
  95. ulong ddr_freq;
  96. if (ctrl_num > 2) {
  97. printf("Not supported controller number %d\n", ctrl_num);
  98. return;
  99. }
  100. if (!pdimm->n_ranks)
  101. return;
  102. pbsp = udimms[0];
  103. /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
  104. * freqency and n_banks specified in board_specific_parameters table.
  105. */
  106. ddr_freq = get_ddr_freq(0) / 1000000;
  107. while (pbsp->datarate_mhz_high) {
  108. if (pbsp->n_ranks == pdimm->n_ranks) {
  109. if (ddr_freq <= pbsp->datarate_mhz_high) {
  110. popts->cpo_override = pbsp->cpo;
  111. popts->write_data_delay =
  112. pbsp->write_data_delay;
  113. popts->clk_adjust = pbsp->clk_adjust;
  114. popts->wrlvl_start = pbsp->wrlvl_start;
  115. popts->wrlvl_ctl_2 = pbsp->wrlvl_ctl_2;
  116. popts->wrlvl_ctl_3 = pbsp->wrlvl_ctl_3;
  117. popts->twot_en = pbsp->force_2t;
  118. goto found;
  119. }
  120. pbsp_highest = pbsp;
  121. }
  122. pbsp++;
  123. }
  124. if (pbsp_highest) {
  125. printf("Error: board specific timing not found "
  126. "for data rate %lu MT/s\n"
  127. "Trying to use the highest speed (%u) parameters\n",
  128. ddr_freq, pbsp_highest->datarate_mhz_high);
  129. popts->cpo_override = pbsp_highest->cpo;
  130. popts->write_data_delay = pbsp_highest->write_data_delay;
  131. popts->clk_adjust = pbsp_highest->clk_adjust;
  132. popts->wrlvl_start = pbsp_highest->wrlvl_start;
  133. popts->twot_en = pbsp_highest->force_2t;
  134. } else {
  135. panic("DIMM is not supported by this board");
  136. }
  137. found:
  138. /*
  139. * Factors to consider for half-strength driver enable:
  140. * - number of DIMMs installed
  141. */
  142. popts->half_strength_driver_enable = 0;
  143. /*
  144. * Write leveling override
  145. */
  146. popts->wrlvl_override = 1;
  147. popts->wrlvl_sample = 0xf;
  148. /*
  149. * Rtt and Rtt_WR override
  150. */
  151. popts->rtt_override = 0;
  152. /* Enable ZQ calibration */
  153. popts->zq_en = 1;
  154. /* DHC_EN =1, ODT = 75 Ohm */
  155. popts->ddr_cdr1 = DDR_CDR1_DHC_EN | DDR_CDR1_ODT(DDR_CDR_ODT_75ohm);
  156. popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_75ohm);
  157. }
  158. phys_size_t initdram(int board_type)
  159. {
  160. phys_size_t dram_size;
  161. puts("Initializing....using SPD\n");
  162. dram_size = fsl_ddr_sdram();
  163. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  164. dram_size *= 0x100000;
  165. puts(" DDR: ");
  166. return dram_size;
  167. }
  168. unsigned long long step_assign_addresses(fsl_ddr_info_t *pinfo,
  169. unsigned int dbw_cap_adj[])
  170. {
  171. int i, j;
  172. unsigned long long total_mem, current_mem_base, total_ctlr_mem;
  173. unsigned long long rank_density, ctlr_density = 0;
  174. current_mem_base = 0ull;
  175. total_mem = 0;
  176. /*
  177. * This board has soldered DDR chips. DDRC1 has two rank.
  178. * DDRC2 has only one rank.
  179. * Assigning DDRC2 to lower address and DDRC1 to higher address.
  180. */
  181. if (pinfo->memctl_opts[0].memctl_interleaving) {
  182. rank_density = pinfo->dimm_params[0][0].rank_density >>
  183. dbw_cap_adj[0];
  184. ctlr_density = rank_density;
  185. debug("rank density is 0x%llx, ctlr density is 0x%llx\n",
  186. rank_density, ctlr_density);
  187. for (i = CONFIG_NUM_DDR_CONTROLLERS - 1; i >= 0; i--) {
  188. switch (pinfo->memctl_opts[i].memctl_interleaving_mode) {
  189. case FSL_DDR_CACHE_LINE_INTERLEAVING:
  190. case FSL_DDR_PAGE_INTERLEAVING:
  191. case FSL_DDR_BANK_INTERLEAVING:
  192. case FSL_DDR_SUPERBANK_INTERLEAVING:
  193. total_ctlr_mem = 2 * ctlr_density;
  194. break;
  195. default:
  196. panic("Unknown interleaving mode");
  197. }
  198. pinfo->common_timing_params[i].base_address =
  199. current_mem_base;
  200. pinfo->common_timing_params[i].total_mem =
  201. total_ctlr_mem;
  202. total_mem = current_mem_base + total_ctlr_mem;
  203. debug("ctrl %d base 0x%llx\n", i, current_mem_base);
  204. debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem);
  205. }
  206. } else {
  207. /*
  208. * Simple linear assignment if memory
  209. * controllers are not interleaved.
  210. */
  211. for (i = CONFIG_NUM_DDR_CONTROLLERS - 1; i >= 0; i--) {
  212. total_ctlr_mem = 0;
  213. pinfo->common_timing_params[i].base_address =
  214. current_mem_base;
  215. for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
  216. /* Compute DIMM base addresses. */
  217. unsigned long long cap =
  218. pinfo->dimm_params[i][j].capacity;
  219. pinfo->dimm_params[i][j].base_address =
  220. current_mem_base;
  221. debug("ctrl %d dimm %d base 0x%llx\n",
  222. i, j, current_mem_base);
  223. current_mem_base += cap;
  224. total_ctlr_mem += cap;
  225. }
  226. debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem);
  227. pinfo->common_timing_params[i].total_mem =
  228. total_ctlr_mem;
  229. total_mem += total_ctlr_mem;
  230. }
  231. }
  232. debug("Total mem by %s is 0x%llx\n", __func__, total_mem);
  233. return total_mem;
  234. }