wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 9 | #include <asm/immap.h> |
| 10 | |
| 11 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 12 | |
| 13 | int checkboard (void) |
| 14 | { |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 15 | puts ("Board: Freescale M5282EVB Evaluation Board\n"); |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 16 | return 0; |
| 17 | } |
| 18 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 19 | phys_size_t initdram (int board_type) |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 20 | { |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 21 | u32 dramsize, i, dramclk; |
| 22 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000; |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 24 | for (i = 0x13; i < 0x20; i++) { |
| 25 | if (dramsize == (1 << i)) |
| 26 | break; |
| 27 | } |
| 28 | i--; |
| 29 | |
| 30 | if (!(MCFSDRAMC_DACR0 & MCFSDRAMC_DACR_RE)) |
| 31 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 32 | dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 33 | |
| 34 | /* Initialize DRAM Control Register: DCR */ |
| 35 | MCFSDRAMC_DCR = (0 |
| 36 | | MCFSDRAMC_DCR_RTIM_6 |
| 37 | | MCFSDRAMC_DCR_RC((15 * dramclk)>>4)); |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 38 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 39 | |
| 40 | /* Initialize DACR0 */ |
| 41 | MCFSDRAMC_DACR0 = (0 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | | MCFSDRAMC_DACR_BASE(CONFIG_SYS_SDRAM_BASE) |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 43 | | MCFSDRAMC_DACR_CASL(1) |
| 44 | | MCFSDRAMC_DACR_CBM(3) |
| 45 | | MCFSDRAMC_DACR_PS_32); |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 46 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 47 | |
| 48 | /* Initialize DMR0 */ |
| 49 | MCFSDRAMC_DMR0 = (0 |
| 50 | | ((dramsize - 1) & 0xFFFC0000) |
| 51 | | MCFSDRAMC_DMR_V); |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 52 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 53 | |
| 54 | /* Set IP (bit 3) in DACR */ |
| 55 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP; |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 56 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 57 | |
| 58 | /* Wait 30ns to allow banks to precharge */ |
| 59 | for (i = 0; i < 5; i++) { |
| 60 | asm ("nop"); |
| 61 | } |
| 62 | |
| 63 | /* Write to this block to initiate precharge */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 64 | *(u32 *)(CONFIG_SYS_SDRAM_BASE) = 0xA5A59696; |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 65 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 66 | |
| 67 | /* Set RE (bit 15) in DACR */ |
| 68 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE; |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 69 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 70 | |
| 71 | /* Wait for at least 8 auto refresh cycles to occur */ |
| 72 | for (i = 0; i < 2000; i++) { |
| 73 | asm(" nop"); |
| 74 | } |
| 75 | |
| 76 | /* Finish the configuration by issuing the IMRS. */ |
| 77 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IMRS; |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 78 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 79 | |
| 80 | /* Write to the SDRAM Mode Register */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | *(u32 *)(CONFIG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696; |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 82 | } |
TsiChungLiew | 2acefa7 | 2007-10-25 17:09:17 -0500 | [diff] [blame] | 83 | return dramsize; |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 84 | } |