Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Keystone2: DDR3 initialization |
| 4 | * |
| 5 | * (C) Copyright 2012-2014 |
| 6 | * Texas Instruments Incorporated, <www.ti.com> |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Hao Zhang | 7f8406d | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 10 | #include "ddr3_cfg.h" |
Khoronzhuk, Ivan | 50df5cc | 2014-07-09 19:48:40 +0300 | [diff] [blame] | 11 | #include <asm/arch/ddr3.h> |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 12 | #include <asm/arch/hardware.h> |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 13 | |
| 14 | struct pll_init_data ddr3a_333 = DDR3_PLL_333(A); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 15 | struct pll_init_data ddr3a_400 = DDR3_PLL_400(A); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 16 | |
Vitaly Andrianov | a9554d6 | 2015-02-11 14:07:58 -0500 | [diff] [blame] | 17 | u32 ddr3_init(void) |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 18 | { |
Vitaly Andrianov | a9554d6 | 2015-02-11 14:07:58 -0500 | [diff] [blame] | 19 | u32 ddr3_size; |
Vitaly Andrianov | ead26f6 | 2016-03-04 10:36:42 -0600 | [diff] [blame] | 20 | struct ddr3_spd_cb spd_cb; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 21 | |
Vitaly Andrianov | ead26f6 | 2016-03-04 10:36:42 -0600 | [diff] [blame] | 22 | if (ddr3_get_dimm_params_from_spd(&spd_cb)) { |
| 23 | printf("Sorry, I don't know how to configure DDR3A.\n" |
| 24 | "Bye :(\n"); |
| 25 | for (;;) |
| 26 | ; |
| 27 | } |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 28 | |
Vitaly Andrianov | ead26f6 | 2016-03-04 10:36:42 -0600 | [diff] [blame] | 29 | printf("Detected SO-DIMM [%s]\n", spd_cb.dimm_name); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 30 | |
Vitaly Andrianov | ead26f6 | 2016-03-04 10:36:42 -0600 | [diff] [blame] | 31 | if ((cpu_revision() > 1) || |
| 32 | (__raw_readl(KS2_RSTCTRL_RSTYPE) & 0x1)) { |
| 33 | printf("DDR3 speed %d\n", spd_cb.ddrspdclock); |
| 34 | if (spd_cb.ddrspdclock == 1600) |
| 35 | init_pll(&ddr3a_400); |
| 36 | else |
| 37 | init_pll(&ddr3a_333); |
| 38 | } |
Hao Zhang | d6c508c | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 39 | |
Vitaly Andrianov | ead26f6 | 2016-03-04 10:36:42 -0600 | [diff] [blame] | 40 | if (cpu_revision() > 0) { |
| 41 | if (cpu_revision() > 1) { |
| 42 | /* PG 2.0 */ |
| 43 | /* Reset DDR3A PHY after PLL enabled */ |
| 44 | ddr3_reset_ddrphy(); |
| 45 | spd_cb.phy_cfg.zq0cr1 |= 0x10000; |
| 46 | spd_cb.phy_cfg.zq1cr1 |= 0x10000; |
| 47 | spd_cb.phy_cfg.zq2cr1 |= 0x10000; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 48 | } |
Vitaly Andrianov | ead26f6 | 2016-03-04 10:36:42 -0600 | [diff] [blame] | 49 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, &spd_cb.phy_cfg); |
| 50 | |
| 51 | ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, &spd_cb.emif_cfg); |
| 52 | |
| 53 | ddr3_size = spd_cb.ddr_size_gbyte; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 54 | } else { |
Vitaly Andrianov | ead26f6 | 2016-03-04 10:36:42 -0600 | [diff] [blame] | 55 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, &spd_cb.phy_cfg); |
| 56 | spd_cb.emif_cfg.sdcfg |= 0x1000; |
| 57 | ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, &spd_cb.emif_cfg); |
| 58 | ddr3_size = spd_cb.ddr_size_gbyte / 2; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 59 | } |
Vitaly Andrianov | ead26f6 | 2016-03-04 10:36:42 -0600 | [diff] [blame] | 60 | printf("DRAM: %d GiB (includes reported below)\n", ddr3_size); |
Murali Karicheri | 39f4520 | 2014-09-10 15:54:59 +0300 | [diff] [blame] | 61 | |
| 62 | /* Apply the workaround for PG 1.0 and 1.1 Silicons */ |
| 63 | if (cpu_revision() <= 1) |
| 64 | ddr3_err_reset_workaround(); |
Vitaly Andrianov | 1917301 | 2014-10-22 17:47:58 +0300 | [diff] [blame] | 65 | |
Vitaly Andrianov | 1917301 | 2014-10-22 17:47:58 +0300 | [diff] [blame] | 66 | return ddr3_size; |
| 67 | } |