blob: e7f8115870377f158341632a4895b9256bc5a1f0 [file] [log] [blame]
Matthias Fuchs72c5d522007-12-28 17:07:14 +01001/*
Matthias Fuchs3b4bd2d2009-09-30 11:55:04 +02002 * (C) Copyright 2009
3 * Matthias Fuchs, esd gmbh, matthias.fuchs@esd.eu
4 *
Matthias Fuchs72c5d522007-12-28 17:07:14 +01005 * (C) Copyright 2006
6 * Sylvie Gohl, AMCC/IBM, gohl.sylvie@fr.ibm.com
7 * Jacqueline Pira-Ferriol, AMCC/IBM, jpira-ferriol@fr.ibm.com
8 * Thierry Roman, AMCC/IBM, thierry_roman@fr.ibm.com
9 * Alain Saurel, AMCC/IBM, alain.saurel@fr.ibm.com
10 * Robert Snyder, AMCC/IBM, rob.snyder@fr.ibm.com
11 *
12 * (C) Copyright 2006-2007
13 * Stefan Roese, DENX Software Engineering, sr@denx.de.
14 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020015 * SPDX-License-Identifier: GPL-2.0+
Matthias Fuchs72c5d522007-12-28 17:07:14 +010016 */
17
18/* define DEBUG for debug output */
19#undef DEBUG
20
21#include <common.h>
22#include <asm/processor.h>
23#include <asm/io.h>
Matthias Fuchs3b4bd2d2009-09-30 11:55:04 +020024#include <asm/mmu.h>
Stefan Roeseb36df562010-09-09 19:18:00 +020025#include <asm/ppc440.h>
Matthias Fuchs72c5d522007-12-28 17:07:14 +010026
Matthias Fuchs34065a22008-01-02 16:48:34 +010027extern int denali_wait_for_dlllock(void);
28extern void denali_core_search_data_eye(void);
Matthias Fuchs72c5d522007-12-28 17:07:14 +010029
Matthias Fuchs3b4bd2d2009-09-30 11:55:04 +020030struct sdram_conf_s {
31 ulong size;
32 int rows;
33 int banks;
34};
Matthias Fuchs72c5d522007-12-28 17:07:14 +010035
Matthias Fuchs3b4bd2d2009-09-30 11:55:04 +020036struct sdram_conf_s sdram_conf[] = {
37 {(1024 << 20), 14, 8}, /* 1GByte: 4x2GBit, 14x10, 8 banks */
38 {(512 << 20), 13, 8}, /* 512MByte: 4x1GBit, 13x10, 8 banks */
39 {(256 << 20), 13, 4}, /* 256MByte: 4x512MBit, 13x10, 4 banks */
40};
Matthias Fuchs72c5d522007-12-28 17:07:14 +010041
Matthias Fuchs3b4bd2d2009-09-30 11:55:04 +020042/*
Matthias Fuchs72c5d522007-12-28 17:07:14 +010043 * initdram -- 440EPx's DDR controller is a DENALI Core
Matthias Fuchs3b4bd2d2009-09-30 11:55:04 +020044 */
45int initdram_by_rb(int rows, int banks)
Matthias Fuchs72c5d522007-12-28 17:07:14 +010046{
Matthias Fuchs72c5d522007-12-28 17:07:14 +010047 ulong speed = get_bus_freq(0);
Matthias Fuchs72c5d522007-12-28 17:07:14 +010048
49 mtsdram(DDR0_02, 0x00000000);
50
51 mtsdram(DDR0_00, 0x0000190A);
52 mtsdram(DDR0_01, 0x01000000);
53 mtsdram(DDR0_03, 0x02030602);
54 mtsdram(DDR0_04, 0x0A020200);
55 mtsdram(DDR0_05, 0x02020308);
56 mtsdram(DDR0_06, 0x0102C812);
57 mtsdram(DDR0_07, 0x000D0100);
58 mtsdram(DDR0_08, 0x02430001);
59 mtsdram(DDR0_09, 0x00011D5F);
Stefan Roese9199b9c2009-03-12 07:24:40 +010060 mtsdram(DDR0_10, 0x00000100);
Matthias Fuchs72c5d522007-12-28 17:07:14 +010061 mtsdram(DDR0_11, 0x0027C800);
62 mtsdram(DDR0_12, 0x00000003);
63 mtsdram(DDR0_14, 0x00000000);
64 mtsdram(DDR0_17, 0x19000000);
65 mtsdram(DDR0_18, 0x19191919);
66 mtsdram(DDR0_19, 0x19191919);
67 mtsdram(DDR0_20, 0x0B0B0B0B);
68 mtsdram(DDR0_21, 0x0B0B0B0B);
69 mtsdram(DDR0_22, 0x00267F0B);
70 mtsdram(DDR0_23, 0x00000000);
71 mtsdram(DDR0_24, 0x01010002);
72 if (speed > 133333334)
73 mtsdram(DDR0_26, 0x5B26050C);
74 else
75 mtsdram(DDR0_26, 0x5B260408);
76 mtsdram(DDR0_27, 0x0000682B);
77 mtsdram(DDR0_28, 0x00000000);
78 mtsdram(DDR0_31, 0x00000000);
Matthias Fuchs3b4bd2d2009-09-30 11:55:04 +020079
80 mtsdram(DDR0_42,
81 DDR0_42_ADDR_PINS_DECODE(14 - rows) |
82 0x00000006);
83 mtsdram(DDR0_43,
84 DDR0_43_EIGHT_BANK_MODE_ENCODE(8 == banks ? 1 : 0) |
85 0x030A0200);
86
Matthias Fuchs72c5d522007-12-28 17:07:14 +010087 mtsdram(DDR0_44, 0x00000003);
88 mtsdram(DDR0_02, 0x00000001);
89
Matthias Fuchs34065a22008-01-02 16:48:34 +010090 denali_wait_for_dlllock();
Matthias Fuchs72c5d522007-12-28 17:07:14 +010091
92#ifdef CONFIG_DDR_DATA_EYE
Matthias Fuchs3b4bd2d2009-09-30 11:55:04 +020093 /*
Matthias Fuchs72c5d522007-12-28 17:07:14 +010094 * Perform data eye search if requested.
Matthias Fuchs3b4bd2d2009-09-30 11:55:04 +020095 */
Matthias Fuchs34065a22008-01-02 16:48:34 +010096 denali_core_search_data_eye();
Matthias Fuchs72c5d522007-12-28 17:07:14 +010097#endif
Matthias Fuchse3edcb32008-01-11 14:55:08 +010098 /*
99 * Clear possible errors resulting from data-eye-search.
100 * If not done, then we could get an interrupt later on when
101 * exceptions are enabled.
102 */
103 set_mcsr(get_mcsr());
104
Matthias Fuchs3b4bd2d2009-09-30 11:55:04 +0200105 return 0;
106}
107
108phys_size_t initdram(int board_type)
109{
110 phys_size_t size;
111 int n;
112
113 /* go through supported memory configurations */
114 for (n = 0; n < ARRAY_SIZE(sdram_conf); n++) {
115 size = sdram_conf[n].size;
116
117 /* program TLB entries */
118 program_tlb(0, CONFIG_SYS_SDRAM_BASE, size,
119 TLB_WORD2_I_ENABLE);
120
121 /*
122 * setup denali core
123 */
124 initdram_by_rb(sdram_conf[n].rows,
125 sdram_conf[n].banks);
126
127 /* check for suitable configuration */
128 if (get_ram_size(CONFIG_SYS_SDRAM_BASE, size) == size)
129 return size;
130
131 /* delete TLB entries */
132 remove_tlb(CONFIG_SYS_SDRAM_BASE, size);
133 }
134
135 return 0;
Matthias Fuchs72c5d522007-12-28 17:07:14 +0100136}