Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Stefan Roese | 247e9d7 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 9 | #include <asm/ppc4xx.h> |
Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 10 | #include <asm/processor.h> |
| 11 | #include <asm/io.h> |
| 12 | |
| 13 | static void wait_init_complete(void) |
| 14 | { |
| 15 | u32 val; |
| 16 | |
| 17 | do { |
Stefan Roese | 6987e65 | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 18 | mfsdram(SDRAM0_MCSTS, val); |
Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 19 | } while (!(val & 0x80000000)); |
| 20 | } |
| 21 | |
| 22 | /* |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 23 | * phys_size_t initdram(int board_type) |
Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 24 | * |
| 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'Brien | c8fd200 | 2007-10-23 08:29:10 +0200 | [diff] [blame] | 31 | * |
| 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 Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 37 | */ |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 38 | phys_size_t initdram(int board_type) |
Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 39 | { |
| 40 | /* |
| 41 | * Soft-reset SDRAM controller. |
| 42 | */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 43 | mtsdr(SDR0_SRST, SDR0_SRST_DMC); |
| 44 | mtsdr(SDR0_SRST, 0x00000000); |
Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * Disable memory controller. |
| 48 | */ |
Stefan Roese | 6987e65 | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 49 | mtsdram(SDRAM0_CFG0, 0x00000000); |
Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * Setup some default |
| 53 | */ |
Stefan Roese | 6987e65 | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 54 | 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 Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * Following for CAS Latency = 2.5 @ 133 MHz PLB |
| 62 | */ |
Stefan Roese | 6987e65 | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 63 | mtsdram(SDRAM0_B0CR, 0x00082001); |
| 64 | mtsdram(SDRAM0_TR0, 0x41094012); |
| 65 | mtsdram(SDRAM0_TR1, 0x8080083d); /* SS=T2 SL=STAGE 3 CD=1 CT=0x00*/ |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 66 | mtsdram(SDRAM0_RTR, 0x04100000); /* Interval 7.8µs @ 133MHz PLB */ |
Stefan Roese | 6987e65 | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 67 | mtsdram(SDRAM0_CFG1, 0x00000000); /* Self-refresh exit, disable PM*/ |
Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * Enable the controller, then wait for DCEN to complete |
| 71 | */ |
Stefan Roese | 6987e65 | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 72 | mtsdram(SDRAM0_CFG0, 0x80000000); /* DCEN=1, PMUD=0*/ |
Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 73 | wait_init_complete(); |
Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 74 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 75 | return CONFIG_SYS_MBYTES_SDRAM << 20; |
Stefan Roese | 4274351 | 2007-06-01 15:27:11 +0200 | [diff] [blame] | 76 | } |