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