Kumar Gala | 129ba61 | 2008-08-12 11:13:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Freescale Semiconductor, Inc. |
| 3 | * |
Tom Rini | 5b8031c | 2016-01-14 22:05:13 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0 |
Kumar Gala | 129ba61 | 2008-08-12 11:13:08 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Kumar Gala | 129ba61 | 2008-08-12 11:13:08 -0500 | [diff] [blame] | 8 | |
York Sun | 5614e71 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 9 | #include <fsl_ddr_sdram.h> |
| 10 | #include <fsl_ddr_dimm_params.h> |
Kumar Gala | 129ba61 | 2008-08-12 11:13:08 -0500 | [diff] [blame] | 11 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 12 | struct board_specific_parameters { |
Haiying Wang | 4ca0660 | 2008-10-03 12:37:41 -0400 | [diff] [blame] | 13 | u32 n_ranks; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 14 | u32 datarate_mhz_high; |
Haiying Wang | 4ca0660 | 2008-10-03 12:37:41 -0400 | [diff] [blame] | 15 | u32 clk_adjust; |
| 16 | u32 cpo; |
| 17 | u32 write_data_delay; |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 18 | u32 force_2t; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 19 | }; |
Haiying Wang | 4ca0660 | 2008-10-03 12:37:41 -0400 | [diff] [blame] | 20 | |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 21 | /* |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 22 | * This table contains all valid speeds we want to override with board |
| 23 | * specific parameters. datarate_mhz_high values need to be in ascending order |
| 24 | * for each n_ranks group. |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 25 | * |
| 26 | * For DDR2 DIMM, all combinations of clk_adjust and write_data_delay have been |
| 27 | * tested. For RDIMM, clk_adjust = 4 and write_data_delay = 3 is optimized for |
| 28 | * all clocks from 400MT/s to 800MT/s, verified with Kingston KVR800D2D8P6/2G. |
| 29 | * For UDIMM, clk_adjust = 8 and write_delay = 5 is optimized for all clocks |
| 30 | * from 400MT/s to 800MT/s, verified with Micron MT18HTF25672AY-800E1. |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 31 | * |
| 32 | * CPO value doesn't matter if workaround for errata 111 and 134 enabled. |
Haiying Wang | 4ca0660 | 2008-10-03 12:37:41 -0400 | [diff] [blame] | 33 | */ |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 34 | static const struct board_specific_parameters udimm0[] = { |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 35 | /* |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 36 | * memory controller 0 |
| 37 | * num| hi| clk| cpo|wrdata|2T |
| 38 | * ranks| mhz|adjst| | delay| |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 39 | */ |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 40 | {2, 333, 8, 7, 5, 0}, |
| 41 | {2, 400, 8, 9, 5, 0}, |
| 42 | {2, 549, 8, 11, 5, 0}, |
| 43 | {2, 680, 8, 10, 5, 0}, |
| 44 | {2, 850, 8, 12, 5, 1}, |
| 45 | {1, 333, 6, 7, 3, 0}, |
| 46 | {1, 400, 6, 9, 3, 0}, |
| 47 | {1, 549, 6, 11, 3, 0}, |
| 48 | {1, 680, 1, 10, 5, 0}, |
| 49 | {1, 850, 1, 12, 5, 0}, |
| 50 | {} |
Haiying Wang | 4ca0660 | 2008-10-03 12:37:41 -0400 | [diff] [blame] | 51 | }; |
| 52 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 53 | static const struct board_specific_parameters udimm1[] = { |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 54 | /* |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 55 | * memory controller 1 |
| 56 | * num| hi| clk| cpo|wrdata|2T |
| 57 | * ranks| mhz|adjst| | delay| |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 58 | */ |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 59 | {2, 333, 8, 7, 5, 0}, |
| 60 | {2, 400, 8, 9, 5, 0}, |
| 61 | {2, 549, 8, 11, 5, 0}, |
| 62 | {2, 680, 8, 11, 5, 0}, |
| 63 | {2, 850, 8, 13, 5, 1}, |
| 64 | {1, 333, 6, 7, 3, 0}, |
| 65 | {1, 400, 6, 9, 3, 0}, |
| 66 | {1, 549, 6, 11, 3, 0}, |
| 67 | {1, 680, 1, 11, 6, 0}, |
| 68 | {1, 850, 1, 13, 6, 0}, |
| 69 | {} |
| 70 | }; |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 71 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 72 | static const struct board_specific_parameters *udimms[] = { |
| 73 | udimm0, |
| 74 | udimm1, |
| 75 | }; |
| 76 | |
| 77 | static const struct board_specific_parameters rdimm0[] = { |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 78 | /* |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 79 | * memory controller 0 |
| 80 | * num| hi| clk| cpo|wrdata|2T |
| 81 | * ranks| mhz|adjst| | delay| |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 82 | */ |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 83 | {2, 333, 4, 7, 3, 0}, |
| 84 | {2, 400, 4, 9, 3, 0}, |
| 85 | {2, 549, 4, 11, 3, 0}, |
| 86 | {2, 680, 4, 10, 3, 0}, |
| 87 | {2, 850, 4, 12, 3, 1}, |
| 88 | {} |
| 89 | }; |
| 90 | |
| 91 | static const struct board_specific_parameters rdimm1[] = { |
| 92 | /* |
| 93 | * memory controller 1 |
| 94 | * num| hi| clk| cpo|wrdata|2T |
| 95 | * ranks| mhz|adjst| | delay| |
| 96 | */ |
| 97 | {2, 333, 4, 7, 3, 0}, |
| 98 | {2, 400, 4, 9, 3, 0}, |
| 99 | {2, 549, 4, 11, 3, 0}, |
| 100 | {2, 680, 4, 11, 3, 0}, |
| 101 | {2, 850, 4, 13, 3, 1}, |
| 102 | {} |
| 103 | }; |
| 104 | |
| 105 | static const struct board_specific_parameters *rdimms[] = { |
| 106 | rdimm0, |
| 107 | rdimm1, |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
Haiying Wang | dfb4910 | 2008-10-03 12:36:55 -0400 | [diff] [blame] | 110 | void fsl_ddr_board_options(memctl_options_t *popts, |
| 111 | dimm_params_t *pdimm, |
| 112 | unsigned int ctrl_num) |
Kumar Gala | 129ba61 | 2008-08-12 11:13:08 -0500 | [diff] [blame] | 113 | { |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 114 | const struct board_specific_parameters *pbsp, *pbsp_highest = NULL; |
Haiying Wang | 4ca0660 | 2008-10-03 12:37:41 -0400 | [diff] [blame] | 115 | ulong ddr_freq; |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 116 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 117 | if (ctrl_num > 1) { |
| 118 | printf("Wrong parameter for controller number %d", ctrl_num); |
| 119 | return; |
| 120 | } |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 121 | if (!pdimm->n_ranks) |
| 122 | return; |
| 123 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 124 | if (popts->registered_dimm_en) |
| 125 | pbsp = rdimms[ctrl_num]; |
| 126 | else |
| 127 | pbsp = udimms[ctrl_num]; |
Kumar Gala | 129ba61 | 2008-08-12 11:13:08 -0500 | [diff] [blame] | 128 | |
Haiying Wang | 4ca0660 | 2008-10-03 12:37:41 -0400 | [diff] [blame] | 129 | /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr |
| 130 | * freqency and n_banks specified in board_specific_parameters table. |
Kumar Gala | 129ba61 | 2008-08-12 11:13:08 -0500 | [diff] [blame] | 131 | */ |
Haiying Wang | 4ca0660 | 2008-10-03 12:37:41 -0400 | [diff] [blame] | 132 | ddr_freq = get_ddr_freq(0) / 1000000; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 133 | while (pbsp->datarate_mhz_high) { |
| 134 | if (pbsp->n_ranks == pdimm->n_ranks) { |
| 135 | if (ddr_freq <= pbsp->datarate_mhz_high) { |
| 136 | popts->clk_adjust = pbsp->clk_adjust; |
| 137 | popts->cpo_override = pbsp->cpo; |
| 138 | popts->write_data_delay = |
| 139 | pbsp->write_data_delay; |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 140 | popts->twot_en = pbsp->force_2t; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 141 | goto found; |
| 142 | } |
| 143 | pbsp_highest = pbsp; |
Haiying Wang | 4ca0660 | 2008-10-03 12:37:41 -0400 | [diff] [blame] | 144 | } |
| 145 | pbsp++; |
| 146 | } |
Kumar Gala | 129ba61 | 2008-08-12 11:13:08 -0500 | [diff] [blame] | 147 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 148 | if (pbsp_highest) { |
| 149 | printf("Error: board specific timing not found " |
| 150 | "for data rate %lu MT/s!\n" |
| 151 | "Trying to use the highest speed (%u) parameters\n", |
| 152 | ddr_freq, pbsp_highest->datarate_mhz_high); |
| 153 | popts->clk_adjust = pbsp->clk_adjust; |
| 154 | popts->cpo_override = pbsp->cpo; |
| 155 | popts->write_data_delay = pbsp->write_data_delay; |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 156 | popts->twot_en = pbsp->force_2t; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 157 | } else { |
| 158 | panic("DIMM is not supported by this board"); |
York Sun | 939e5bf | 2011-06-27 13:30:55 -0700 | [diff] [blame] | 159 | } |
York Sun | 634bc55 | 2011-03-17 11:18:11 -0700 | [diff] [blame] | 160 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 161 | found: |
Kumar Gala | 129ba61 | 2008-08-12 11:13:08 -0500 | [diff] [blame] | 162 | /* |
| 163 | * Factors to consider for half-strength driver enable: |
| 164 | * - number of DIMMs installed |
| 165 | */ |
| 166 | popts->half_strength_driver_enable = 0; |
| 167 | } |