blob: df0dfc1a0d39500e9430b6dcfcdcdf9549bb20a2 [file] [log] [blame]
Stefan Roese42743512007-06-01 15:27:11 +02001/*
2 * (C) Copyright 2007
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese42743512007-06-01 15:27:11 +02006 */
7
8#include <common.h>
Stefan Roese247e9d72010-09-09 19:18:00 +02009#include <asm/ppc4xx.h>
Stefan Roese42743512007-06-01 15:27:11 +020010#include <asm/processor.h>
11#include <asm/io.h>
12
13static void wait_init_complete(void)
14{
15 u32 val;
16
17 do {
Stefan Roese6987e652009-09-24 13:59:57 +020018 mfsdram(SDRAM0_MCSTS, val);
Stefan Roese42743512007-06-01 15:27:11 +020019 } while (!(val & 0x80000000));
20}
21
22/*
Becky Brucebd99ae72008-06-09 16:03:40 -050023 * phys_size_t initdram(int board_type)
Stefan Roese42743512007-06-01 15:27:11 +020024 *
25 * As the name already indicates, this function is called very early
26 * from start.S and configures the SDRAM with fixed values. This is needed,
27 * since the 440EP has no internal SRAM and the 4kB NAND_SPL loader has
28 * not enough free space to implement the complete I2C SPD DDR autodetection
29 * routines. Therefore the Bamboo only supports the onboard 64MBytes of SDRAM
30 * when booting from NAND flash.
Eugene O'Brienc8fd2002007-10-23 08:29:10 +020031 *
32 * Note:
33 * As found out by Eugene O'Brien <eugene.obrien@advantechamt.com>, the fixed
34 * DDR setup has problems (U-Boot crashes randomly upon TFTP), when the DIMM
35 * modules are still plugged in. So it is recommended to remove the DIMM
36 * modules while using the NAND booting code with the fixed SDRAM setup!
Stefan Roese42743512007-06-01 15:27:11 +020037 */
Becky Brucebd99ae72008-06-09 16:03:40 -050038phys_size_t initdram(int board_type)
Stefan Roese42743512007-06-01 15:27:11 +020039{
40 /*
41 * Soft-reset SDRAM controller.
42 */
Stefan Roese918010a2009-09-09 16:25:29 +020043 mtsdr(SDR0_SRST, SDR0_SRST_DMC);
44 mtsdr(SDR0_SRST, 0x00000000);
Stefan Roese42743512007-06-01 15:27:11 +020045
46 /*
47 * Disable memory controller.
48 */
Stefan Roese6987e652009-09-24 13:59:57 +020049 mtsdram(SDRAM0_CFG0, 0x00000000);
Stefan Roese42743512007-06-01 15:27:11 +020050
51 /*
52 * Setup some default
53 */
Stefan Roese6987e652009-09-24 13:59:57 +020054 mtsdram(SDRAM0_UABBA, 0x00000000); /* ubba=0 (default) */
55 mtsdram(SDRAM0_SLIO, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
56 mtsdram(SDRAM0_DEVOPT, 0x00000000); /* dll=0 ds=0 (normal) */
57 mtsdram(SDRAM0_WDDCTR, 0x00000000); /* wrcp=0 dcd=0 */
58 mtsdram(SDRAM0_CLKTR, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */
Stefan Roese42743512007-06-01 15:27:11 +020059
60 /*
61 * Following for CAS Latency = 2.5 @ 133 MHz PLB
62 */
Stefan Roese6987e652009-09-24 13:59:57 +020063 mtsdram(SDRAM0_B0CR, 0x00082001);
64 mtsdram(SDRAM0_TR0, 0x41094012);
65 mtsdram(SDRAM0_TR1, 0x8080083d); /* SS=T2 SL=STAGE 3 CD=1 CT=0x00*/
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +020066 mtsdram(SDRAM0_RTR, 0x04100000); /* Interval 7.8µs @ 133MHz PLB */
Stefan Roese6987e652009-09-24 13:59:57 +020067 mtsdram(SDRAM0_CFG1, 0x00000000); /* Self-refresh exit, disable PM*/
Stefan Roese42743512007-06-01 15:27:11 +020068
69 /*
70 * Enable the controller, then wait for DCEN to complete
71 */
Stefan Roese6987e652009-09-24 13:59:57 +020072 mtsdram(SDRAM0_CFG0, 0x80000000); /* DCEN=1, PMUD=0*/
Stefan Roese42743512007-06-01 15:27:11 +020073 wait_init_complete();
Stefan Roese42743512007-06-01 15:27:11 +020074
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020075 return CONFIG_SYS_MBYTES_SDRAM << 20;
Stefan Roese42743512007-06-01 15:27:11 +020076}