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