Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2011 Freescale Semiconductor, Inc. |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <i2c.h> |
| 8 | #include <hwconfig.h> |
| 9 | #include <asm/mmu.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 10 | #include <fsl_ddr_sdram.h> |
| 11 | #include <fsl_ddr_dimm_params.h> |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 12 | #include <asm/fsl_law.h> |
| 13 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 16 | struct board_specific_parameters { |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 17 | u32 n_ranks; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 18 | u32 datarate_mhz_high; |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 19 | u32 clk_adjust; |
| 20 | u32 wrlvl_start; |
| 21 | u32 cpo; |
| 22 | u32 write_data_delay; |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 23 | u32 force_2t; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 24 | }; |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 25 | |
| 26 | /* |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 27 | * This table contains all valid speeds we want to override with board |
| 28 | * specific parameters. datarate_mhz_high values need to be in ascending order |
| 29 | * for each n_ranks group. |
| 30 | * |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 31 | * ranges for parameters: |
| 32 | * wr_data_delay = 0-6 |
| 33 | * clk adjust = 0-8 |
| 34 | * cpo 2-0x1E (30) |
| 35 | */ |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 36 | static const struct board_specific_parameters dimm0[] = { |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 37 | /* |
| 38 | * memory controller 0 |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 39 | * num| hi| clk| wrlvl | cpo |wrdata|2T |
| 40 | * ranks| mhz|adjst| start | delay| |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 41 | */ |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 42 | {2, 750, 3, 5, 0xff, 2, 0}, |
| 43 | {2, 1250, 4, 6, 0xff, 2, 0}, |
| 44 | {2, 1350, 5, 7, 0xff, 2, 0}, |
| 45 | {2, 1666, 5, 8, 0xff, 2, 0}, |
| 46 | {} |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | void fsl_ddr_board_options(memctl_options_t *popts, |
| 50 | dimm_params_t *pdimm, |
| 51 | unsigned int ctrl_num) |
| 52 | { |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 53 | const struct board_specific_parameters *pbsp, *pbsp_highest = NULL; |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 54 | ulong ddr_freq; |
| 55 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 56 | if (ctrl_num) { |
| 57 | printf("Wrong parameter for controller number %d", ctrl_num); |
| 58 | return; |
| 59 | } |
| 60 | if (!pdimm->n_ranks) |
| 61 | return; |
| 62 | |
| 63 | pbsp = dimm0; |
| 64 | |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 65 | /* |
| 66 | * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr |
| 67 | * freqency and n_banks specified in board_specific_parameters table. |
| 68 | */ |
| 69 | ddr_freq = get_ddr_freq(0) / 1000000; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 70 | while (pbsp->datarate_mhz_high) { |
| 71 | if (pbsp->n_ranks == pdimm->n_ranks) { |
| 72 | if (ddr_freq <= pbsp->datarate_mhz_high) { |
| 73 | popts->cpo_override = pbsp->cpo; |
| 74 | popts->write_data_delay = |
| 75 | pbsp->write_data_delay; |
| 76 | popts->clk_adjust = pbsp->clk_adjust; |
| 77 | popts->wrlvl_start = pbsp->wrlvl_start; |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 78 | popts->twot_en = pbsp->force_2t; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 79 | goto found; |
| 80 | } |
| 81 | pbsp_highest = pbsp; |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 82 | } |
| 83 | pbsp++; |
| 84 | } |
| 85 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 86 | if (pbsp_highest) { |
| 87 | printf("Error: board specific timing not found " |
| 88 | "for data rate %lu MT/s!\n" |
| 89 | "Trying to use the highest speed (%u) parameters\n", |
| 90 | ddr_freq, pbsp_highest->datarate_mhz_high); |
| 91 | popts->cpo_override = pbsp_highest->cpo; |
| 92 | popts->write_data_delay = pbsp_highest->write_data_delay; |
| 93 | popts->clk_adjust = pbsp_highest->clk_adjust; |
| 94 | popts->wrlvl_start = pbsp_highest->wrlvl_start; |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 95 | popts->twot_en = pbsp_highest->force_2t; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 96 | } else { |
| 97 | panic("DIMM is not supported by this board"); |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 98 | } |
| 99 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 100 | found: |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 101 | /* |
| 102 | * Factors to consider for half-strength driver enable: |
| 103 | * - number of DIMMs installed |
| 104 | */ |
| 105 | popts->half_strength_driver_enable = 0; |
| 106 | /* Write leveling override */ |
| 107 | popts->wrlvl_override = 1; |
| 108 | popts->wrlvl_sample = 0xf; |
| 109 | |
| 110 | /* Rtt and Rtt_WR override */ |
| 111 | popts->rtt_override = 0; |
| 112 | |
| 113 | /* Enable ZQ calibration */ |
| 114 | popts->zq_en = 1; |
| 115 | |
| 116 | /* DHC_EN =1, ODT = 60 Ohm */ |
| 117 | popts->ddr_cdr1 = DDR_CDR1_DHC_EN; |
| 118 | } |
| 119 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 120 | int dram_init(void) |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 121 | { |
| 122 | phys_size_t dram_size = 0; |
| 123 | |
| 124 | puts("Initializing...."); |
| 125 | |
| 126 | if (fsl_use_spd()) { |
| 127 | puts("using SPD\n"); |
| 128 | dram_size = fsl_ddr_sdram(); |
| 129 | } else { |
| 130 | puts("no SPD and fixed parameters\n"); |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 131 | return -ENXIO; |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | dram_size = setup_ddr_tlbs(dram_size / 0x100000); |
| 135 | dram_size *= 0x100000; |
| 136 | |
Wolfgang Denk | f2bbb53 | 2011-07-25 10:13:53 +0200 | [diff] [blame] | 137 | debug(" DDR: "); |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 138 | gd->ram_size = dram_size; |
| 139 | |
| 140 | return 0; |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 141 | } |