blob: 2c5a21806a31cd6072d45c464c425cde77a87f0e [file] [log] [blame]
Stefan Roese42fbddd2006-09-07 11:51:23 +02001/*
2 * (C) Copyright 2006
Stefan Roese5684da02007-01-05 10:38:05 +01003 * Sylvie Gohl, AMCC/IBM, gohl.sylvie@fr.ibm.com
4 * Jacqueline Pira-Ferriol, AMCC/IBM, jpira-ferriol@fr.ibm.com
5 * Thierry Roman, AMCC/IBM, thierry_roman@fr.ibm.com
6 * Alain Saurel, AMCC/IBM, alain.saurel@fr.ibm.com
7 * Robert Snyder, AMCC/IBM, rob.snyder@fr.ibm.com
8 *
Stefan Roese50b6c4e2007-03-06 07:47:04 +01009 * (C) Copyright 2006-2007
Stefan Roese42fbddd2006-09-07 11:51:23 +020010 * Stefan Roese, DENX Software Engineering, sr@denx.de.
11 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese42fbddd2006-09-07 11:51:23 +020013 */
14
Stefan Roese5684da02007-01-05 10:38:05 +010015/* define DEBUG for debug output */
16#undef DEBUG
17
Stefan Roese42fbddd2006-09-07 11:51:23 +020018#include <common.h>
19#include <asm/processor.h>
Stefan Roese5684da02007-01-05 10:38:05 +010020#include <asm/io.h>
Stefan Roese247e9d72010-09-09 19:18:00 +020021#include <asm/ppc440.h>
Stefan Roese42fbddd2006-09-07 11:51:23 +020022
Stefan Roese5684da02007-01-05 10:38:05 +010023/*-----------------------------------------------------------------------------+
Larry Johnson27bc9972007-12-30 01:00:50 -050024 * Prototypes
25 *-----------------------------------------------------------------------------*/
26extern int denali_wait_for_dlllock(void);
27extern void denali_core_search_data_eye(void);
Stefan Roese5684da02007-01-05 10:38:05 +010028
Stefan Roese10d7d6e2007-05-05 08:29:01 +020029#if defined(CONFIG_NAND_SPL)
Stefan Roese88fbf932010-04-15 16:07:28 +020030/* Using arch/powerpc/cpu/ppc4xx/speed.c to calculate the bus frequency is too big
Stefan Roese10d7d6e2007-05-05 08:29:01 +020031 * for the 4k NAND boot image so define bus_frequency to 133MHz here
32 * which is save for the refresh counter setup.
33 */
Stefan Roese8f1bb192009-04-15 11:32:53 +020034#define get_bus_freq(val) 133333333
Stefan Roese10d7d6e2007-05-05 08:29:01 +020035#endif
36
Stefan Roese42fbddd2006-09-07 11:51:23 +020037/*************************************************************************
38 *
39 * initdram -- 440EPx's DDR controller is a DENALI Core
40 *
41 ************************************************************************/
Becky Brucebd99ae72008-06-09 16:03:40 -050042phys_size_t initdram (int board_type)
Stefan Roese42fbddd2006-09-07 11:51:23 +020043{
Stefan Roesec20ef322009-05-11 13:46:14 +020044#if !(defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_SYS_RAMBOOT)) || \
45 defined(CONFIG_NAND_SPL)
Stefan Roese50b6c4e2007-03-06 07:47:04 +010046 ulong speed = get_bus_freq(0);
47
Stefan Roese42fbddd2006-09-07 11:51:23 +020048 mtsdram(DDR0_02, 0x00000000);
49
Stefan Roese42fbddd2006-09-07 11:51:23 +020050 mtsdram(DDR0_00, 0x0000190A);
51 mtsdram(DDR0_01, 0x01000000);
52 mtsdram(DDR0_03, 0x02030602);
Stefan Roese50b6c4e2007-03-06 07:47:04 +010053 mtsdram(DDR0_04, 0x0A020200);
54 mtsdram(DDR0_05, 0x02020308);
55 mtsdram(DDR0_06, 0x0102C812);
Stefan Roese42fbddd2006-09-07 11:51:23 +020056 mtsdram(DDR0_07, 0x000D0100);
Stefan Roese50b6c4e2007-03-06 07:47:04 +010057 mtsdram(DDR0_08, 0x02430001);
Stefan Roese42fbddd2006-09-07 11:51:23 +020058 mtsdram(DDR0_09, 0x00011D5F);
Mikhail Zolotaryovf270b822009-03-11 10:54:46 +020059 mtsdram(DDR0_10, 0x00000100);
Stefan Roese42fbddd2006-09-07 11:51:23 +020060 mtsdram(DDR0_11, 0x0027C800);
61 mtsdram(DDR0_12, 0x00000003);
62 mtsdram(DDR0_14, 0x00000000);
63 mtsdram(DDR0_17, 0x19000000);
64 mtsdram(DDR0_18, 0x19191919);
65 mtsdram(DDR0_19, 0x19191919);
66 mtsdram(DDR0_20, 0x0B0B0B0B);
67 mtsdram(DDR0_21, 0x0B0B0B0B);
68 mtsdram(DDR0_22, 0x00267F0B);
69 mtsdram(DDR0_23, 0x00000000);
70 mtsdram(DDR0_24, 0x01010002);
Stefan Roese10d7d6e2007-05-05 08:29:01 +020071 if (speed > 133333334)
Stefan Roese50b6c4e2007-03-06 07:47:04 +010072 mtsdram(DDR0_26, 0x5B26050C);
73 else
74 mtsdram(DDR0_26, 0x5B260408);
Stefan Roese42fbddd2006-09-07 11:51:23 +020075 mtsdram(DDR0_27, 0x0000682B);
76 mtsdram(DDR0_28, 0x00000000);
77 mtsdram(DDR0_31, 0x00000000);
78 mtsdram(DDR0_42, 0x01000006);
Stefan Roese50b6c4e2007-03-06 07:47:04 +010079 mtsdram(DDR0_43, 0x030A0200);
80 mtsdram(DDR0_44, 0x00000003);
Stefan Roese42fbddd2006-09-07 11:51:23 +020081 mtsdram(DDR0_02, 0x00000001);
82
Larry Johnson27bc9972007-12-30 01:00:50 -050083 denali_wait_for_dlllock();
Stefan Roese42fbddd2006-09-07 11:51:23 +020084#endif /* #ifndef CONFIG_NAND_U_BOOT */
85
Stefan Roese5684da02007-01-05 10:38:05 +010086#ifdef CONFIG_DDR_DATA_EYE
87 /* -----------------------------------------------------------+
88 * Perform data eye search if requested.
89 * ----------------------------------------------------------*/
Larry Johnson27bc9972007-12-30 01:00:50 -050090 denali_core_search_data_eye();
Stefan Roese5684da02007-01-05 10:38:05 +010091#endif
92
Stefan Roese3c726cf2008-01-11 15:53:58 +010093 /*
94 * Clear possible errors resulting from data-eye-search.
95 * If not done, then we could get an interrupt later on when
96 * exceptions are enabled.
97 */
98 set_mcsr(get_mcsr());
99
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200100 return (CONFIG_SYS_MBYTES_SDRAM << 20);
Stefan Roese42fbddd2006-09-07 11:51:23 +0200101}