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; |
| 60 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame^] | 61 | if (ctrl_num) { |
| 62 | printf("Wrong parameter for controller number %d", ctrl_num); |
| 63 | return; |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 64 | } |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame^] | 65 | if (!pdimm->n_ranks) |
| 66 | return; |
| 67 | |
| 68 | pbsp = dimm0; |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 69 | |
| 70 | /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr |
| 71 | * freqency and n_banks specified in board_specific_parameters table. |
| 72 | */ |
| 73 | ddr_freq = get_ddr_freq(0) / 1000000; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame^] | 74 | while (pbsp->datarate_mhz_high) { |
| 75 | if (pbsp->n_ranks == pdimm->n_ranks) { |
| 76 | if (ddr_freq <= pbsp->datarate_mhz_high) { |
| 77 | popts->clk_adjust = pbsp->clk_adjust; |
| 78 | popts->cpo_override = pbsp->cpo; |
| 79 | popts->write_data_delay = |
| 80 | pbsp->write_data_delay; |
| 81 | popts->twoT_en = pbsp->force_2T; |
| 82 | goto found; |
| 83 | } |
| 84 | pbsp_highest = pbsp; |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 85 | } |
| 86 | pbsp++; |
| 87 | } |
| 88 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame^] | 89 | if (pbsp_highest) { |
| 90 | printf("Error: board specific timing not found " |
| 91 | "for data rate %lu MT/s!\n" |
| 92 | "Trying to use the highest speed (%u) parameters\n", |
| 93 | ddr_freq, pbsp_highest->datarate_mhz_high); |
| 94 | popts->clk_adjust = pbsp_highest->clk_adjust; |
| 95 | popts->cpo_override = pbsp_highest->cpo; |
| 96 | popts->write_data_delay = pbsp_highest->write_data_delay; |
| 97 | popts->twoT_en = pbsp_highest->force_2T; |
| 98 | } else { |
| 99 | panic("DIMM is not supported by this board"); |
York Sun | 24b66e5 | 2011-06-27 13:30:55 -0700 | [diff] [blame] | 100 | } |
| 101 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame^] | 102 | found: |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 103 | /* |
| 104 | * Factors to consider for half-strength driver enable: |
| 105 | * - number of DIMMs installed |
| 106 | */ |
| 107 | popts->half_strength_driver_enable = 0; |
york | cc1415c | 2010-07-02 22:25:58 +0000 | [diff] [blame] | 108 | popts->wrlvl_en = 1; |
| 109 | /* Write leveling override */ |
| 110 | popts->wrlvl_override = 1; |
| 111 | popts->wrlvl_sample = 0xa; |
York Sun | 5207e77 | 2010-08-27 16:25:56 -0500 | [diff] [blame] | 112 | popts->wrlvl_start = 0x8; |
york | cc1415c | 2010-07-02 22:25:58 +0000 | [diff] [blame] | 113 | /* Rtt and Rtt_WR override */ |
| 114 | popts->rtt_override = 1; |
| 115 | popts->rtt_override_value = DDR3_RTT_120_OHM; |
| 116 | popts->rtt_wr_override_value = 0; /* Rtt_WR= dynamic ODT off */ |
Srikanth Srinivasan | 949a2d5 | 2009-04-03 15:36:13 -0500 | [diff] [blame] | 117 | } |