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