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