York Sun | f749db3 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <fsl_ddr_sdram.h> |
| 9 | #include <fsl_ddr_dimm_params.h> |
| 10 | #include "ddr.h" |
| 11 | |
| 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
| 14 | void fsl_ddr_board_options(memctl_options_t *popts, |
| 15 | dimm_params_t *pdimm, |
| 16 | unsigned int ctrl_num) |
| 17 | { |
| 18 | const struct board_specific_parameters *pbsp, *pbsp_highest = NULL; |
| 19 | ulong ddr_freq; |
| 20 | |
| 21 | if (ctrl_num > 3) { |
| 22 | printf("Not supported controller number %d\n", ctrl_num); |
| 23 | return; |
| 24 | } |
| 25 | if (!pdimm->n_ranks) |
| 26 | return; |
| 27 | |
| 28 | /* |
| 29 | * we use identical timing for all slots. If needed, change the code |
| 30 | * to pbsp = rdimms[ctrl_num] or pbsp = udimms[ctrl_num]; |
| 31 | */ |
| 32 | if (popts->registered_dimm_en) |
| 33 | pbsp = rdimms[0]; |
| 34 | else |
| 35 | pbsp = udimms[0]; |
| 36 | |
| 37 | |
| 38 | /* Get clk_adjust, wrlvl_start, wrlvl_ctl, according to the board ddr |
| 39 | * freqency and n_banks specified in board_specific_parameters table. |
| 40 | */ |
| 41 | ddr_freq = get_ddr_freq(0) / 1000000; |
| 42 | while (pbsp->datarate_mhz_high) { |
| 43 | if (pbsp->n_ranks == pdimm->n_ranks && |
| 44 | (pdimm->rank_density >> 30) >= pbsp->rank_gb) { |
| 45 | if (ddr_freq <= pbsp->datarate_mhz_high) { |
| 46 | popts->clk_adjust = pbsp->clk_adjust; |
| 47 | popts->wrlvl_start = pbsp->wrlvl_start; |
| 48 | popts->wrlvl_ctl_2 = pbsp->wrlvl_ctl_2; |
| 49 | popts->wrlvl_ctl_3 = pbsp->wrlvl_ctl_3; |
| 50 | goto found; |
| 51 | } |
| 52 | pbsp_highest = pbsp; |
| 53 | } |
| 54 | pbsp++; |
| 55 | } |
| 56 | |
| 57 | if (pbsp_highest) { |
| 58 | printf("Error: board specific timing not found for data rate %lu MT/s\n" |
| 59 | "Trying to use the highest speed (%u) parameters\n", |
| 60 | ddr_freq, pbsp_highest->datarate_mhz_high); |
| 61 | popts->clk_adjust = pbsp_highest->clk_adjust; |
| 62 | popts->wrlvl_start = pbsp_highest->wrlvl_start; |
| 63 | popts->wrlvl_ctl_2 = pbsp->wrlvl_ctl_2; |
| 64 | popts->wrlvl_ctl_3 = pbsp->wrlvl_ctl_3; |
| 65 | } else { |
| 66 | panic("DIMM is not supported by this board"); |
| 67 | } |
| 68 | found: |
| 69 | debug("Found timing match: n_ranks %d, data rate %d, rank_gb %d\n" |
| 70 | "\tclk_adjust %d, wrlvl_start %d, wrlvl_ctrl_2 0x%x, wrlvl_ctrl_3 0x%x\n", |
| 71 | pbsp->n_ranks, pbsp->datarate_mhz_high, pbsp->rank_gb, |
| 72 | pbsp->clk_adjust, pbsp->wrlvl_start, pbsp->wrlvl_ctl_2, |
| 73 | pbsp->wrlvl_ctl_3); |
| 74 | |
| 75 | /* |
| 76 | * Factors to consider for half-strength driver enable: |
| 77 | * - number of DIMMs installed |
| 78 | */ |
| 79 | popts->half_strength_driver_enable = 1; |
| 80 | /* |
| 81 | * Write leveling override |
| 82 | */ |
| 83 | popts->wrlvl_override = 1; |
| 84 | popts->wrlvl_sample = 0xf; |
| 85 | |
| 86 | /* |
| 87 | * Rtt and Rtt_WR override |
| 88 | */ |
| 89 | popts->rtt_override = 0; |
| 90 | |
| 91 | /* Enable ZQ calibration */ |
| 92 | popts->zq_en = 1; |
| 93 | |
| 94 | #ifdef CONFIG_SYS_FSL_DDR4 |
| 95 | popts->ddr_cdr1 = DDR_CDR1_DHC_EN | DDR_CDR1_ODT(DDR_CDR_ODT_80ohm); |
| 96 | popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_80ohm) | |
| 97 | DDR_CDR2_VREF_OVRD(70); /* Vref = 70% */ |
| 98 | #else |
| 99 | /* DHC_EN =1, ODT = 75 Ohm */ |
| 100 | popts->ddr_cdr1 = DDR_CDR1_DHC_EN | DDR_CDR1_ODT(DDR_CDR_ODT_75ohm); |
| 101 | popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_75ohm); |
| 102 | #endif |
| 103 | } |
| 104 | |
| 105 | #ifdef CONFIG_SYS_DDR_RAW_TIMING |
| 106 | dimm_params_t ddr_raw_timing = { |
| 107 | .n_ranks = 2, |
| 108 | .rank_density = 1073741824u, |
| 109 | .capacity = 2147483648, |
| 110 | .primary_sdram_width = 64, |
| 111 | .ec_sdram_width = 0, |
| 112 | .registered_dimm = 0, |
| 113 | .mirrored_dimm = 0, |
| 114 | .n_row_addr = 14, |
| 115 | .n_col_addr = 10, |
| 116 | .n_banks_per_sdram_device = 8, |
| 117 | .edc_config = 0, |
| 118 | .burst_lengths_bitmask = 0x0c, |
| 119 | |
| 120 | .tckmin_x_ps = 937, |
| 121 | .caslat_x = 0x6FC << 4, /* 14,13,11,10,9,8,7,6 */ |
| 122 | .taa_ps = 13090, |
| 123 | .twr_ps = 15000, |
| 124 | .trcd_ps = 13090, |
| 125 | .trrd_ps = 5000, |
| 126 | .trp_ps = 13090, |
| 127 | .tras_ps = 33000, |
| 128 | .trc_ps = 46090, |
| 129 | .trfc_ps = 160000, |
| 130 | .twtr_ps = 7500, |
| 131 | .trtp_ps = 7500, |
| 132 | .refresh_rate_ps = 7800000, |
| 133 | .tfaw_ps = 25000, |
| 134 | }; |
| 135 | |
| 136 | int fsl_ddr_get_dimm_params(dimm_params_t *pdimm, |
| 137 | unsigned int controller_number, |
| 138 | unsigned int dimm_number) |
| 139 | { |
| 140 | const char dimm_model[] = "Fixed DDR on board"; |
| 141 | |
| 142 | if (((controller_number == 0) && (dimm_number == 0)) || |
| 143 | ((controller_number == 1) && (dimm_number == 0))) { |
| 144 | memcpy(pdimm, &ddr_raw_timing, sizeof(dimm_params_t)); |
| 145 | memset(pdimm->mpart, 0, sizeof(pdimm->mpart)); |
| 146 | memcpy(pdimm->mpart, dimm_model, sizeof(dimm_model) - 1); |
| 147 | } |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | #endif |
| 152 | phys_size_t initdram(int board_type) |
| 153 | { |
| 154 | phys_size_t dram_size; |
| 155 | |
| 156 | puts("Initializing DDR...."); |
| 157 | |
| 158 | puts("using SPD\n"); |
| 159 | dram_size = fsl_ddr_sdram(); |
| 160 | |
| 161 | return dram_size; |
| 162 | } |
| 163 | |
| 164 | void dram_init_banksize(void) |
| 165 | { |
| 166 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 167 | if (gd->ram_size > CONFIG_SYS_LS2_DDR_BLOCK1_SIZE) { |
| 168 | gd->bd->bi_dram[0].size = CONFIG_SYS_LS2_DDR_BLOCK1_SIZE; |
| 169 | gd->bd->bi_dram[1].start = CONFIG_SYS_DDR_BLOCK2_BASE; |
| 170 | gd->bd->bi_dram[1].size = gd->ram_size - |
| 171 | CONFIG_SYS_LS2_DDR_BLOCK1_SIZE; |
| 172 | } else { |
| 173 | gd->bd->bi_dram[0].size = gd->ram_size; |
| 174 | } |
| 175 | } |