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