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> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
TsiChungLiew | 1692b48 | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 9 | #include <asm/immap.h> |
| 10 | |
| 11 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 12 | |
| 13 | int checkboard (void) |
| 14 | { |
TsiChungLiew | 1692b48 | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 15 | puts ("Board: Freescale M5282EVB Evaluation Board\n"); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 16 | return 0; |
| 17 | } |
| 18 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 19 | int dram_init(void) |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 20 | { |
TsiChungLiew | 1692b48 | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 21 | u32 dramsize, i, dramclk; |
| 22 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000; |
TsiChungLiew | 1692b48 | 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 | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 32 | dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ); |
TsiChungLiew | 1692b48 | 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 | fcd4aac | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 38 | asm("nop"); |
TsiChungLiew | 1692b48 | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 39 | |
| 40 | /* Initialize DACR0 */ |
| 41 | MCFSDRAMC_DACR0 = (0 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | | MCFSDRAMC_DACR_BASE(CONFIG_SYS_SDRAM_BASE) |
TsiChungLiew | 1692b48 | 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 | fcd4aac | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 46 | asm("nop"); |
TsiChungLiew | 1692b48 | 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 | fcd4aac | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 52 | asm("nop"); |
TsiChungLiew | 1692b48 | 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 | fcd4aac | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 56 | asm("nop"); |
TsiChungLiew | 1692b48 | 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 | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 64 | *(u32 *)(CONFIG_SYS_SDRAM_BASE) = 0xA5A59696; |
TsiChung Liew | fcd4aac | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 65 | asm("nop"); |
TsiChungLiew | 1692b48 | 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 | fcd4aac | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 69 | asm("nop"); |
TsiChungLiew | 1692b48 | 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 | fcd4aac | 2008-08-11 15:54:25 +0000 | [diff] [blame] | 78 | asm("nop"); |
TsiChungLiew | 1692b48 | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 79 | |
| 80 | /* Write to the SDRAM Mode Register */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | *(u32 *)(CONFIG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696; |
TsiChungLiew | 1692b48 | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 82 | } |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 83 | gd->ram_size = dramsize; |
| 84 | |
| 85 | return 0; |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 86 | } |