blob: eb618b54f48d57959da355a9b24e288da7a8423c [file] [log] [blame]
wdenkabf7a7c2003-12-08 01:34:36 +00001/*
2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkabf7a7c2003-12-08 01:34:36 +00006 */
7
8#include <common.h>
TsiChungLiew1692b482007-08-15 20:32:06 -05009#include <asm/immap.h>
10
11DECLARE_GLOBAL_DATA_PTR;
wdenkabf7a7c2003-12-08 01:34:36 +000012
13int checkboard (void)
14{
TsiChungLiew1692b482007-08-15 20:32:06 -050015 puts ("Board: Freescale M5282EVB Evaluation Board\n");
wdenkabf7a7c2003-12-08 01:34:36 +000016 return 0;
17}
18
Simon Glassd35f3382017-04-06 12:47:05 -060019int dram_init(void)
wdenkabf7a7c2003-12-08 01:34:36 +000020{
TsiChungLiew1692b482007-08-15 20:32:06 -050021 u32 dramsize, i, dramclk;
22
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020023 dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
TsiChungLiew1692b482007-08-15 20:32:06 -050024 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-VILLARD03836942008-10-16 15:01:15 +020032 dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ);
TsiChungLiew1692b482007-08-15 20:32:06 -050033
34 /* Initialize DRAM Control Register: DCR */
35 MCFSDRAMC_DCR = (0
36 | MCFSDRAMC_DCR_RTIM_6
37 | MCFSDRAMC_DCR_RC((15 * dramclk)>>4));
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000038 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050039
40 /* Initialize DACR0 */
41 MCFSDRAMC_DACR0 = (0
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020042 | MCFSDRAMC_DACR_BASE(CONFIG_SYS_SDRAM_BASE)
TsiChungLiew1692b482007-08-15 20:32:06 -050043 | MCFSDRAMC_DACR_CASL(1)
44 | MCFSDRAMC_DACR_CBM(3)
45 | MCFSDRAMC_DACR_PS_32);
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000046 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050047
48 /* Initialize DMR0 */
49 MCFSDRAMC_DMR0 = (0
50 | ((dramsize - 1) & 0xFFFC0000)
51 | MCFSDRAMC_DMR_V);
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000052 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050053
54 /* Set IP (bit 3) in DACR */
55 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP;
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000056 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050057
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-VILLARD03836942008-10-16 15:01:15 +020064 *(u32 *)(CONFIG_SYS_SDRAM_BASE) = 0xA5A59696;
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000065 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050066
67 /* Set RE (bit 15) in DACR */
68 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE;
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000069 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050070
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 Liewfcd4aac2008-08-11 15:54:25 +000078 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050079
80 /* Write to the SDRAM Mode Register */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020081 *(u32 *)(CONFIG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696;
TsiChungLiew1692b482007-08-15 20:32:06 -050082 }
Simon Glass39f90ba2017-03-31 08:40:25 -060083 gd->ram_size = dramsize;
84
85 return 0;
wdenkabf7a7c2003-12-08 01:34:36 +000086}