blob: 53e0f202101ce0eeaeb290a7ca0af4113a4d2a27 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkabf7a7c2003-12-08 01:34:36 +00002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenkabf7a7c2003-12-08 01:34:36 +00005 */
6
7#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
TsiChungLiew1692b482007-08-15 20:32:06 -050010#include <asm/immap.h>
11
12DECLARE_GLOBAL_DATA_PTR;
wdenkabf7a7c2003-12-08 01:34:36 +000013
14int checkboard (void)
15{
TsiChungLiew1692b482007-08-15 20:32:06 -050016 puts ("Board: Freescale M5282EVB Evaluation Board\n");
wdenkabf7a7c2003-12-08 01:34:36 +000017 return 0;
18}
19
Simon Glassd35f3382017-04-06 12:47:05 -060020int dram_init(void)
wdenkabf7a7c2003-12-08 01:34:36 +000021{
TsiChungLiew1692b482007-08-15 20:32:06 -050022 u32 dramsize, i, dramclk;
23
Tom Rinibb4dd962022-11-16 13:10:37 -050024 dramsize = CFG_SYS_SDRAM_SIZE * 0x100000;
TsiChungLiew1692b482007-08-15 20:32:06 -050025 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-VILLARD03836942008-10-16 15:01:15 +020033 dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ);
TsiChungLiew1692b482007-08-15 20:32:06 -050034
35 /* Initialize DRAM Control Register: DCR */
36 MCFSDRAMC_DCR = (0
37 | MCFSDRAMC_DCR_RTIM_6
38 | MCFSDRAMC_DCR_RC((15 * dramclk)>>4));
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000039 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050040
41 /* Initialize DACR0 */
42 MCFSDRAMC_DACR0 = (0
Tom Rinibb4dd962022-11-16 13:10:37 -050043 | MCFSDRAMC_DACR_BASE(CFG_SYS_SDRAM_BASE)
TsiChungLiew1692b482007-08-15 20:32:06 -050044 | MCFSDRAMC_DACR_CASL(1)
45 | MCFSDRAMC_DACR_CBM(3)
46 | MCFSDRAMC_DACR_PS_32);
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000047 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050048
49 /* Initialize DMR0 */
50 MCFSDRAMC_DMR0 = (0
51 | ((dramsize - 1) & 0xFFFC0000)
52 | MCFSDRAMC_DMR_V);
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000053 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050054
55 /* Set IP (bit 3) in DACR */
56 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP;
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000057 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050058
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 */
Tom Rinibb4dd962022-11-16 13:10:37 -050065 *(u32 *)(CFG_SYS_SDRAM_BASE) = 0xA5A59696;
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000066 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050067
68 /* Set RE (bit 15) in DACR */
69 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE;
TsiChung Liewfcd4aac2008-08-11 15:54:25 +000070 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050071
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 Liewfcd4aac2008-08-11 15:54:25 +000079 asm("nop");
TsiChungLiew1692b482007-08-15 20:32:06 -050080
81 /* Write to the SDRAM Mode Register */
Tom Rinibb4dd962022-11-16 13:10:37 -050082 *(u32 *)(CFG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696;
TsiChungLiew1692b482007-08-15 20:32:06 -050083 }
Simon Glass39f90ba2017-03-31 08:40:25 -060084 gd->ram_size = dramsize;
85
86 return 0;
wdenkabf7a7c2003-12-08 01:34:36 +000087}