Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 Freescale Semiconductor, Inc. |
| 3 | * Authors: Srikanth Srinivasan <srikanth.srinivasan@freescale.com> |
| 4 | * Timur Tabi <timur@freescale.com> |
| 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 10 | |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 11 | #include <fsl_ddr_sdram.h> |
| 12 | #include <fsl_ddr_dimm_params.h> |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 13 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 14 | struct board_specific_parameters { |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 15 | u32 n_ranks; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 16 | u32 datarate_mhz_high; |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 17 | u32 clk_adjust; /* Range: 0-8 */ |
| 18 | u32 cpo; /* Range: 2-31 */ |
| 19 | u32 write_data_delay; /* Range: 0-6 */ |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 20 | u32 force_2t; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 21 | }; |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 22 | |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 23 | /* |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 24 | * This table contains all valid speeds we want to override with board |
| 25 | * specific parameters. datarate_mhz_high values need to be in ascending order |
| 26 | * for each n_ranks group. |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 27 | */ |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 28 | static const struct board_specific_parameters dimm0[] = { |
| 29 | /* |
| 30 | * memory controller 0 |
| 31 | * num| hi| clk| cpo|wrdata|2T |
| 32 | * ranks| mhz|adjst| | delay| |
| 33 | */ |
| 34 | {1, 549, 5, 31, 3, 0}, |
| 35 | {1, 850, 5, 31, 5, 0}, |
| 36 | {2, 549, 5, 31, 3, 0}, |
| 37 | {2, 850, 5, 31, 5, 0}, |
| 38 | {} |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | void fsl_ddr_board_options(memctl_options_t *popts, dimm_params_t *pdimm, |
| 42 | unsigned int ctrl_num) |
| 43 | { |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 44 | const struct board_specific_parameters *pbsp, *pbsp_highest = NULL; |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 45 | unsigned long ddr_freq; |
| 46 | unsigned int i; |
| 47 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 48 | |
| 49 | if (ctrl_num) { |
| 50 | printf("Wrong parameter for controller number %d", ctrl_num); |
| 51 | return; |
| 52 | } |
| 53 | if (!pdimm->n_ranks) |
| 54 | return; |
| 55 | |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 56 | /* set odt_rd_cfg and odt_wr_cfg. */ |
| 57 | for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) { |
| 58 | popts->cs_local_opts[i].odt_rd_cfg = 0; |
| 59 | popts->cs_local_opts[i].odt_wr_cfg = 1; |
| 60 | } |
| 61 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 62 | pbsp = dimm0; |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 63 | /* |
| 64 | * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr |
| 65 | * freqency and n_banks specified in board_specific_parameters table. |
| 66 | */ |
| 67 | ddr_freq = get_ddr_freq(0) / 1000000; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 68 | while (pbsp->datarate_mhz_high) { |
| 69 | if (pbsp->n_ranks == pdimm->n_ranks) { |
| 70 | if (ddr_freq <= pbsp->datarate_mhz_high) { |
| 71 | popts->clk_adjust = pbsp->clk_adjust; |
| 72 | popts->cpo_override = pbsp->cpo; |
| 73 | popts->write_data_delay = |
| 74 | pbsp->write_data_delay; |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 75 | popts->twot_en = pbsp->force_2t; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 76 | goto found; |
| 77 | } |
| 78 | pbsp_highest = pbsp; |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 79 | } |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 80 | pbsp++; |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 81 | } |
| 82 | |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 83 | if (pbsp_highest) { |
| 84 | printf("Error: board specific timing not found " |
| 85 | "for data rate %lu MT/s!\n" |
| 86 | "Trying to use the highest speed (%u) parameters\n", |
| 87 | ddr_freq, pbsp_highest->datarate_mhz_high); |
| 88 | popts->clk_adjust = pbsp->clk_adjust; |
| 89 | popts->cpo_override = pbsp->cpo; |
| 90 | popts->write_data_delay = pbsp->write_data_delay; |
Priyanka Jain | 4a71741 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 91 | popts->twot_en = pbsp->force_2t; |
York Sun | b6d2ef6 | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 92 | } else { |
| 93 | panic("DIMM is not supported by this board"); |
| 94 | } |
| 95 | |
| 96 | found: |
Timur Tabi | 9b45b5a | 2010-06-14 15:28:24 -0500 | [diff] [blame] | 97 | popts->half_strength_driver_enable = 1; |
| 98 | |
| 99 | /* Per AN4039, enable ZQ calibration. */ |
| 100 | popts->zq_en = 1; |
| 101 | |
| 102 | /* |
| 103 | * For wake-up on ARP, we need auto self refresh enabled |
| 104 | */ |
| 105 | popts->auto_self_refresh_en = 1; |
| 106 | popts->sr_it = 0xb; |
| 107 | } |