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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 25 | #include <asm/immap.h> |
| 26 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 28 | |
| 29 | int checkboard (void) |
| 30 | { |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 31 | puts ("Board: Freescale M5282EVB Evaluation Board\n"); |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 32 | return 0; |
| 33 | } |
| 34 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 35 | phys_size_t initdram (int board_type) |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 36 | { |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 37 | u32 dramsize, i, dramclk; |
| 38 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 39 | dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000; |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 40 | for (i = 0x13; i < 0x20; i++) { |
| 41 | if (dramsize == (1 << i)) |
| 42 | break; |
| 43 | } |
| 44 | i--; |
| 45 | |
| 46 | if (!(MCFSDRAMC_DACR0 & MCFSDRAMC_DACR_RE)) |
| 47 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 48 | dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 49 | |
| 50 | /* Initialize DRAM Control Register: DCR */ |
| 51 | MCFSDRAMC_DCR = (0 |
| 52 | | MCFSDRAMC_DCR_RTIM_6 |
| 53 | | MCFSDRAMC_DCR_RC((15 * dramclk)>>4)); |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 54 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 55 | |
| 56 | /* Initialize DACR0 */ |
| 57 | MCFSDRAMC_DACR0 = (0 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 58 | | MCFSDRAMC_DACR_BASE(CONFIG_SYS_SDRAM_BASE) |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 59 | | MCFSDRAMC_DACR_CASL(1) |
| 60 | | MCFSDRAMC_DACR_CBM(3) |
| 61 | | MCFSDRAMC_DACR_PS_32); |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 62 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 63 | |
| 64 | /* Initialize DMR0 */ |
| 65 | MCFSDRAMC_DMR0 = (0 |
| 66 | | ((dramsize - 1) & 0xFFFC0000) |
| 67 | | MCFSDRAMC_DMR_V); |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 68 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 69 | |
| 70 | /* Set IP (bit 3) in DACR */ |
| 71 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP; |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 72 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 73 | |
| 74 | /* Wait 30ns to allow banks to precharge */ |
| 75 | for (i = 0; i < 5; i++) { |
| 76 | asm ("nop"); |
| 77 | } |
| 78 | |
| 79 | /* Write to this block to initiate precharge */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 80 | *(u32 *)(CONFIG_SYS_SDRAM_BASE) = 0xA5A59696; |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 81 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 82 | |
| 83 | /* Set RE (bit 15) in DACR */ |
| 84 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE; |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 85 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 86 | |
| 87 | /* Wait for at least 8 auto refresh cycles to occur */ |
| 88 | for (i = 0; i < 2000; i++) { |
| 89 | asm(" nop"); |
| 90 | } |
| 91 | |
| 92 | /* Finish the configuration by issuing the IMRS. */ |
| 93 | MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IMRS; |
TsiChung Liew | 4cb4e65 | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 94 | asm("nop"); |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 95 | |
| 96 | /* Write to the SDRAM Mode Register */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 97 | *(u32 *)(CONFIG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696; |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 98 | } |
TsiChungLiew | 2acefa7 | 2007-10-25 17:09:17 -0500 | [diff] [blame] | 99 | return dramsize; |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 100 | } |