Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008-2009 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * Version 2 as published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 10 | |
| 11 | #include <asm/fsl_ddr_sdram.h> |
| 12 | #include <asm/fsl_ddr_dimm_params.h> |
| 13 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 14 | struct board_specific_parameters { |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 15 | u32 n_ranks; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 16 | u32 datarate_mhz_high; |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 17 | u32 clk_adjust; |
| 18 | u32 cpo; |
| 19 | u32 write_data_delay; |
| 20 | u32 force_2T; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 21 | }; |
| 22 | |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 23 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 24 | /* |
| 25 | * This table contains all valid speeds we want to override with board |
| 26 | * specific parameters. datarate_mhz_high values need to be in ascending order |
| 27 | * for each n_ranks group. |
| 28 | * |
| 29 | * ranges for parameters: |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 30 | * wr_data_delay = 0-6 |
| 31 | * clk adjust = 0-8 |
| 32 | * cpo 2-0x1E (30) |
| 33 | */ |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 34 | static const struct board_specific_parameters dimm0[] = { |
| 35 | /* |
| 36 | * memory controller 0 |
| 37 | * num| hi| clk| cpo|wrdata|2T |
| 38 | * ranks| mhz|adjst| | delay| |
| 39 | */ |
york | cc1415c | 2010-07-02 22:25:58 +0000 | [diff] [blame] | 40 | #ifdef CONFIG_FSL_DDR2 |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 41 | {2, 549, 4, 0x1f, 2, 0}, |
| 42 | {2, 680, 4, 0x1f, 3, 0}, |
| 43 | {2, 850, 4, 0x1f, 4, 0}, |
| 44 | {1, 549, 4, 0x1f, 2, 0}, |
| 45 | {1, 680, 4, 0x1f, 3, 0}, |
| 46 | {1, 850, 4, 0x1f, 4, 0}, |
york | cc1415c | 2010-07-02 22:25:58 +0000 | [diff] [blame] | 47 | #else |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 48 | {2, 850, 6, 0x1f, 4, 0}, |
| 49 | {1, 850, 4, 0x1f, 4, 0}, |
york | cc1415c | 2010-07-02 22:25:58 +0000 | [diff] [blame] | 50 | #endif |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 51 | {} |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | void fsl_ddr_board_options(memctl_options_t *popts, |
| 55 | dimm_params_t *pdimm, |
| 56 | unsigned int ctrl_num) |
| 57 | { |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 58 | const struct board_specific_parameters *pbsp, *pbsp_highest = NULL; |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 59 | ulong ddr_freq; |
Kumar Gala | a01c929 | 2011-10-18 01:31:08 -0500 | [diff] [blame] | 60 | int i; |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 61 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 62 | if (ctrl_num) { |
| 63 | printf("Wrong parameter for controller number %d", ctrl_num); |
| 64 | return; |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 65 | } |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 66 | if (!pdimm->n_ranks) |
| 67 | return; |
| 68 | |
Kumar Gala | a01c929 | 2011-10-18 01:31:08 -0500 | [diff] [blame] | 69 | /* |
| 70 | * set odt_rd_cfg and odt_wr_cfg. If the there is only one dimm in |
| 71 | * that controller, set odt_wr_cfg to 4 for CS0, and 0 to CS1. If |
| 72 | * there are two dimms in the controller, set odt_rd_cfg to 3 and |
| 73 | * odt_wr_cfg to 3 for the even CS, 0 for the odd CS. |
| 74 | */ |
| 75 | for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) { |
| 76 | popts->cs_local_opts[i].odt_rd_cfg = 0; |
| 77 | popts->cs_local_opts[i].odt_wr_cfg = 1; |
| 78 | } |
| 79 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 80 | pbsp = dimm0; |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 81 | |
| 82 | /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr |
| 83 | * freqency and n_banks specified in board_specific_parameters table. |
| 84 | */ |
| 85 | ddr_freq = get_ddr_freq(0) / 1000000; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 86 | while (pbsp->datarate_mhz_high) { |
| 87 | if (pbsp->n_ranks == pdimm->n_ranks) { |
| 88 | if (ddr_freq <= pbsp->datarate_mhz_high) { |
| 89 | popts->clk_adjust = pbsp->clk_adjust; |
| 90 | popts->cpo_override = pbsp->cpo; |
| 91 | popts->write_data_delay = |
| 92 | pbsp->write_data_delay; |
| 93 | popts->twoT_en = pbsp->force_2T; |
| 94 | goto found; |
| 95 | } |
| 96 | pbsp_highest = pbsp; |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 97 | } |
| 98 | pbsp++; |
| 99 | } |
| 100 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 101 | if (pbsp_highest) { |
| 102 | printf("Error: board specific timing not found " |
| 103 | "for data rate %lu MT/s!\n" |
| 104 | "Trying to use the highest speed (%u) parameters\n", |
| 105 | ddr_freq, pbsp_highest->datarate_mhz_high); |
| 106 | popts->clk_adjust = pbsp_highest->clk_adjust; |
| 107 | popts->cpo_override = pbsp_highest->cpo; |
| 108 | popts->write_data_delay = pbsp_highest->write_data_delay; |
| 109 | popts->twoT_en = pbsp_highest->force_2T; |
| 110 | } else { |
| 111 | panic("DIMM is not supported by this board"); |
York Sun | 24b66e5 | 2011-06-27 13:30:55 -0700 | [diff] [blame] | 112 | } |
| 113 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 114 | found: |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 115 | /* |
| 116 | * Factors to consider for half-strength driver enable: |
| 117 | * - number of DIMMs installed |
| 118 | */ |
| 119 | popts->half_strength_driver_enable = 0; |
york | cc1415c | 2010-07-02 22:25:58 +0000 | [diff] [blame] | 120 | popts->wrlvl_en = 1; |
| 121 | /* Write leveling override */ |
| 122 | popts->wrlvl_override = 1; |
| 123 | popts->wrlvl_sample = 0xa; |
York Sun | 5207e77 | 2010-08-27 16:25:56 -0500 | [diff] [blame] | 124 | popts->wrlvl_start = 0x8; |
york | cc1415c | 2010-07-02 22:25:58 +0000 | [diff] [blame] | 125 | /* Rtt and Rtt_WR override */ |
| 126 | popts->rtt_override = 1; |
| 127 | popts->rtt_override_value = DDR3_RTT_120_OHM; |
| 128 | popts->rtt_wr_override_value = 0; /* Rtt_WR= dynamic ODT off */ |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 129 | } |