York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Freescale Semiconductor, Inc. |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 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> |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 11 | |
| 12 | struct board_specific_parameters { |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 13 | u32 n_ranks; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 14 | u32 datarate_mhz_high; |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [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 | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 19 | }; |
| 20 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 21 | /* |
| 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. |
| 25 | */ |
| 26 | static const struct board_specific_parameters udimm0[] = { |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 27 | /* |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 28 | * memory controller 0 |
| 29 | * num| hi| clk| cpo|wrdata|2T |
| 30 | * ranks| mhz|adjst| | delay| |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 31 | */ |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 32 | {2, 300, 4, 4, 2, 0}, |
| 33 | {2, 365, 4, 6, 2, 0}, |
| 34 | {2, 450, 4, 7, 2, 0}, |
| 35 | {2, 850, 4, 31, 2, 0}, |
| 36 | {1, 300, 4, 4, 2, 0}, |
| 37 | {1, 365, 4, 6, 2, 0}, |
| 38 | {1, 450, 4, 7, 2, 0}, |
| 39 | {1, 850, 4, 31, 2, 0}, |
| 40 | {} |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | void fsl_ddr_board_options(memctl_options_t *popts, |
| 44 | dimm_params_t *pdimm, |
| 45 | unsigned int ctrl_num) |
| 46 | { |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 47 | const struct board_specific_parameters *pbsp, *pbsp_highest = NULL; |
| 48 | unsigned int i; |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 49 | ulong ddr_freq; |
| 50 | |
| 51 | if (ctrl_num != 0) /* we have only one controller */ |
| 52 | return; |
| 53 | for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) { |
| 54 | if (pdimm[i].n_ranks) |
| 55 | break; |
| 56 | } |
| 57 | if (i >= CONFIG_DIMM_SLOTS_PER_CTLR) /* no DIMM */ |
| 58 | return; |
| 59 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 60 | pbsp = udimm0; |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 61 | |
| 62 | /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr |
| 63 | * freqency and n_banks specified in board_specific_parameters table. |
| 64 | */ |
| 65 | ddr_freq = get_ddr_freq(0) / 1000000; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 66 | while (pbsp->datarate_mhz_high) { |
| 67 | if (pbsp->n_ranks == pdimm[i].n_ranks) { |
| 68 | if (ddr_freq <= pbsp->datarate_mhz_high) { |
| 69 | popts->clk_adjust = pbsp->clk_adjust; |
| 70 | popts->cpo_override = pbsp->cpo; |
| 71 | popts->write_data_delay = |
| 72 | pbsp->write_data_delay; |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 73 | popts->twot_en = pbsp->force_2t; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 74 | goto found; |
| 75 | } |
| 76 | pbsp_highest = pbsp; |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 77 | } |
| 78 | pbsp++; |
| 79 | } |
| 80 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 81 | if (pbsp_highest) { |
| 82 | printf("Error: board specific timing not found " |
| 83 | "for data rate %lu MT/s!\n" |
| 84 | "Trying to use the highest speed (%u) parameters\n", |
| 85 | ddr_freq, pbsp_highest->datarate_mhz_high); |
| 86 | popts->clk_adjust = pbsp_highest->clk_adjust; |
| 87 | popts->cpo_override = pbsp_highest->cpo; |
| 88 | popts->write_data_delay = pbsp_highest->write_data_delay; |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 89 | popts->twot_en = pbsp_highest->force_2t; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 90 | } else { |
| 91 | panic("DIMM is not supported by this board"); |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 92 | } |
| 93 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 94 | found: |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 95 | /* |
| 96 | * Factors to consider for half-strength driver enable: |
| 97 | * - number of DIMMs installed |
| 98 | */ |
| 99 | popts->half_strength_driver_enable = 0; |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 100 | popts->dqs_config = 0; /* only true DQS signal is used on board */ |
York Sun | d4b9106 | 2011-08-26 11:32:45 -0700 | [diff] [blame] | 101 | } |