Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2011 Freescale Semiconductor, Inc. |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <i2c.h> |
| 8 | #include <hwconfig.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 11 | #include <asm/mmu.h> |
York Sun | 5614e71 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 12 | #include <fsl_ddr_sdram.h> |
| 13 | #include <fsl_ddr_dimm_params.h> |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 14 | #include <asm/fsl_law.h> |
| 15 | |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 18 | struct board_specific_parameters { |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 19 | u32 n_ranks; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 20 | u32 datarate_mhz_high; |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 21 | u32 clk_adjust; |
| 22 | u32 wrlvl_start; |
| 23 | u32 cpo; |
| 24 | u32 write_data_delay; |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 25 | u32 force_2t; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 26 | }; |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 27 | |
| 28 | /* |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 29 | * This table contains all valid speeds we want to override with board |
| 30 | * specific parameters. datarate_mhz_high values need to be in ascending order |
| 31 | * for each n_ranks group. |
| 32 | * |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 33 | * ranges for parameters: |
| 34 | * wr_data_delay = 0-6 |
| 35 | * clk adjust = 0-8 |
| 36 | * cpo 2-0x1E (30) |
| 37 | */ |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 38 | static const struct board_specific_parameters dimm0[] = { |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 39 | /* |
| 40 | * memory controller 0 |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 41 | * num| hi| clk| wrlvl | cpo |wrdata|2T |
| 42 | * ranks| mhz|adjst| start | delay| |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 43 | */ |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 44 | {2, 750, 3, 5, 0xff, 2, 0}, |
| 45 | {2, 1250, 4, 6, 0xff, 2, 0}, |
| 46 | {2, 1350, 5, 7, 0xff, 2, 0}, |
| 47 | {2, 1666, 5, 8, 0xff, 2, 0}, |
| 48 | {} |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | void fsl_ddr_board_options(memctl_options_t *popts, |
| 52 | dimm_params_t *pdimm, |
| 53 | unsigned int ctrl_num) |
| 54 | { |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 55 | const struct board_specific_parameters *pbsp, *pbsp_highest = NULL; |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 56 | ulong ddr_freq; |
| 57 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 58 | if (ctrl_num) { |
| 59 | printf("Wrong parameter for controller number %d", ctrl_num); |
| 60 | return; |
| 61 | } |
| 62 | if (!pdimm->n_ranks) |
| 63 | return; |
| 64 | |
| 65 | pbsp = dimm0; |
| 66 | |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 67 | /* |
| 68 | * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr |
| 69 | * freqency and n_banks specified in board_specific_parameters table. |
| 70 | */ |
| 71 | ddr_freq = get_ddr_freq(0) / 1000000; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 72 | while (pbsp->datarate_mhz_high) { |
| 73 | if (pbsp->n_ranks == pdimm->n_ranks) { |
| 74 | if (ddr_freq <= pbsp->datarate_mhz_high) { |
| 75 | popts->cpo_override = pbsp->cpo; |
| 76 | popts->write_data_delay = |
| 77 | pbsp->write_data_delay; |
| 78 | popts->clk_adjust = pbsp->clk_adjust; |
| 79 | popts->wrlvl_start = pbsp->wrlvl_start; |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 80 | popts->twot_en = pbsp->force_2t; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 81 | goto found; |
| 82 | } |
| 83 | pbsp_highest = pbsp; |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 84 | } |
| 85 | pbsp++; |
| 86 | } |
| 87 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 88 | if (pbsp_highest) { |
| 89 | printf("Error: board specific timing not found " |
| 90 | "for data rate %lu MT/s!\n" |
| 91 | "Trying to use the highest speed (%u) parameters\n", |
| 92 | ddr_freq, pbsp_highest->datarate_mhz_high); |
| 93 | popts->cpo_override = pbsp_highest->cpo; |
| 94 | popts->write_data_delay = pbsp_highest->write_data_delay; |
| 95 | popts->clk_adjust = pbsp_highest->clk_adjust; |
| 96 | popts->wrlvl_start = pbsp_highest->wrlvl_start; |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 97 | popts->twot_en = pbsp_highest->force_2t; |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 98 | } else { |
| 99 | panic("DIMM is not supported by this board"); |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 100 | } |
| 101 | |
York Sun | 712cf7a | 2011-10-03 09:19:53 -0700 | [diff] [blame] | 102 | found: |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [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; |
| 108 | /* Write leveling override */ |
| 109 | popts->wrlvl_override = 1; |
| 110 | popts->wrlvl_sample = 0xf; |
| 111 | |
| 112 | /* Rtt and Rtt_WR override */ |
| 113 | popts->rtt_override = 0; |
| 114 | |
| 115 | /* Enable ZQ calibration */ |
| 116 | popts->zq_en = 1; |
| 117 | |
| 118 | /* DHC_EN =1, ODT = 60 Ohm */ |
| 119 | popts->ddr_cdr1 = DDR_CDR1_DHC_EN; |
| 120 | } |
| 121 | |
Simon Glass | f1683aa | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 122 | int dram_init(void) |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 123 | { |
| 124 | phys_size_t dram_size = 0; |
| 125 | |
| 126 | puts("Initializing...."); |
| 127 | |
| 128 | if (fsl_use_spd()) { |
| 129 | puts("using SPD\n"); |
| 130 | dram_size = fsl_ddr_sdram(); |
| 131 | } else { |
| 132 | puts("no SPD and fixed parameters\n"); |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 133 | return -ENXIO; |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | dram_size = setup_ddr_tlbs(dram_size / 0x100000); |
| 137 | dram_size *= 0x100000; |
| 138 | |
Wolfgang Denk | 21cd581 | 2011-07-25 10:13:53 +0200 | [diff] [blame] | 139 | debug(" DDR: "); |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 140 | gd->ram_size = dram_size; |
| 141 | |
| 142 | return 0; |
Mingkai Hu | 4f1d1b7 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 143 | } |