Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Keystone2: DDR3 initialization |
| 3 | * |
| 4 | * (C) Copyright 2012-2014 |
| 5 | * Texas Instruments Incorporated, <www.ti.com> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 11 | #include "ddr3_cfg.h" |
Khoronzhuk, Ivan | 0b86858 | 2014-07-09 19:48:40 +0300 | [diff] [blame] | 12 | #include <asm/arch/ddr3.h> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 13 | #include <asm/arch/hardware.h> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 14 | |
| 15 | struct pll_init_data ddr3a_333 = DDR3_PLL_333(A); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 16 | struct pll_init_data ddr3a_400 = DDR3_PLL_400(A); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 17 | |
Vitaly Andrianov | 66c98a0 | 2015-02-11 14:07:58 -0500 | [diff] [blame] | 18 | u32 ddr3_init(void) |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 19 | { |
| 20 | char dimm_name[32]; |
Vitaly Andrianov | 66c98a0 | 2015-02-11 14:07:58 -0500 | [diff] [blame] | 21 | u32 ddr3_size; |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 22 | |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 23 | ddr3_get_dimm_params(dimm_name); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 24 | |
| 25 | printf("Detected SO-DIMM [%s]\n", dimm_name); |
| 26 | |
| 27 | if (!strcmp(dimm_name, "18KSF1G72HZ-1G6E2 ")) { |
| 28 | init_pll(&ddr3a_400); |
| 29 | if (cpu_revision() > 0) { |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 30 | if (cpu_revision() > 1) { |
| 31 | /* PG 2.0 */ |
| 32 | /* Reset DDR3A PHY after PLL enabled */ |
| 33 | ddr3_reset_ddrphy(); |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 34 | ddr3phy_1600_8g.zq0cr1 |= 0x10000; |
| 35 | ddr3phy_1600_8g.zq1cr1 |= 0x10000; |
| 36 | ddr3phy_1600_8g.zq2cr1 |= 0x10000; |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 37 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 38 | &ddr3phy_1600_8g); |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 39 | } else { |
| 40 | /* PG 1.1 */ |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 41 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 42 | &ddr3phy_1600_8g); |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 43 | } |
| 44 | |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 45 | ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 46 | &ddr3_1600_8g); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 47 | printf("DRAM: Capacity 8 GiB (includes reported below)\n"); |
Vitaly Andrianov | 89f44bb | 2014-10-22 17:47:58 +0300 | [diff] [blame] | 48 | ddr3_size = 8; |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 49 | } else { |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 50 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, &ddr3phy_1600_8g); |
| 51 | ddr3_1600_8g.sdcfg |= 0x1000; |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 52 | ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 53 | &ddr3_1600_8g); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 54 | printf("DRAM: Capacity 4 GiB (includes reported below)\n"); |
Vitaly Andrianov | 89f44bb | 2014-10-22 17:47:58 +0300 | [diff] [blame] | 55 | ddr3_size = 4; |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 56 | } |
| 57 | } else if (!strcmp(dimm_name, "SQR-SD3T-2G1333SED")) { |
| 58 | init_pll(&ddr3a_333); |
| 59 | if (cpu_revision() > 0) { |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 60 | if (cpu_revision() > 1) { |
| 61 | /* PG 2.0 */ |
| 62 | /* Reset DDR3A PHY after PLL enabled */ |
| 63 | ddr3_reset_ddrphy(); |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 64 | ddr3phy_1333_2g.zq0cr1 |= 0x10000; |
| 65 | ddr3phy_1333_2g.zq1cr1 |= 0x10000; |
| 66 | ddr3phy_1333_2g.zq2cr1 |= 0x10000; |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 67 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 68 | &ddr3phy_1333_2g); |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 69 | } else { |
| 70 | /* PG 1.1 */ |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 71 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 72 | &ddr3phy_1333_2g); |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 73 | } |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 74 | ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 75 | &ddr3_1333_2g); |
Vitaly Andrianov | 89f44bb | 2014-10-22 17:47:58 +0300 | [diff] [blame] | 76 | ddr3_size = 2; |
| 77 | printf("DRAM: 2 GiB"); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 78 | } else { |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 79 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, &ddr3phy_1333_2g); |
| 80 | ddr3_1333_2g.sdcfg |= 0x1000; |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 81 | ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 82 | &ddr3_1333_2g); |
Vitaly Andrianov | 89f44bb | 2014-10-22 17:47:58 +0300 | [diff] [blame] | 83 | ddr3_size = 1; |
| 84 | printf("DRAM: 1 GiB"); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 85 | } |
| 86 | } else { |
| 87 | printf("Unknown SO-DIMM. Cannot configure DDR3\n"); |
| 88 | while (1) |
| 89 | ; |
| 90 | } |
Murali Karicheri | 6c34382 | 2014-09-10 15:54:59 +0300 | [diff] [blame] | 91 | |
| 92 | /* Apply the workaround for PG 1.0 and 1.1 Silicons */ |
| 93 | if (cpu_revision() <= 1) |
| 94 | ddr3_err_reset_workaround(); |
Vitaly Andrianov | 89f44bb | 2014-10-22 17:47:58 +0300 | [diff] [blame] | 95 | |
Vitaly Andrianov | 89f44bb | 2014-10-22 17:47:58 +0300 | [diff] [blame] | 96 | return ddr3_size; |
| 97 | } |