blob: 065e3e71f5728180cb36c5bdc47e8d37423f619f [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk4e5ca3e2003-12-08 01:34:36 +00002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk4e5ca3e2003-12-08 01:34:36 +00005 */
6
7#include <common.h>
TsiChungLiewf28e1bd2007-08-15 20:32:06 -05008#include <asm/immap.h>
9
10DECLARE_GLOBAL_DATA_PTR;
wdenk4e5ca3e2003-12-08 01:34:36 +000011
12int checkboard (void)
13{
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050014 puts ("Board: Freescale M5282EVB Evaluation Board\n");
wdenk4e5ca3e2003-12-08 01:34:36 +000015 return 0;
16}
17
Simon Glassf1683aa2017-04-06 12:47:05 -060018int dram_init(void)
wdenk4e5ca3e2003-12-08 01:34:36 +000019{
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050020 u32 dramsize, i, dramclk;
21
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020022 dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050023 for (i = 0x13; i < 0x20; i++) {
24 if (dramsize == (1 << i))
25 break;
26 }
27 i--;
28
29 if (!(MCFSDRAMC_DACR0 & MCFSDRAMC_DACR_RE))
30 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020031 dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ);
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050032
33 /* Initialize DRAM Control Register: DCR */
34 MCFSDRAMC_DCR = (0
35 | MCFSDRAMC_DCR_RTIM_6
36 | MCFSDRAMC_DCR_RC((15 * dramclk)>>4));
TsiChung Liew4cb4e652008-08-11 15:54:25 +000037 asm("nop");
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050038
39 /* Initialize DACR0 */
40 MCFSDRAMC_DACR0 = (0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020041 | MCFSDRAMC_DACR_BASE(CONFIG_SYS_SDRAM_BASE)
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050042 | MCFSDRAMC_DACR_CASL(1)
43 | MCFSDRAMC_DACR_CBM(3)
44 | MCFSDRAMC_DACR_PS_32);
TsiChung Liew4cb4e652008-08-11 15:54:25 +000045 asm("nop");
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050046
47 /* Initialize DMR0 */
48 MCFSDRAMC_DMR0 = (0
49 | ((dramsize - 1) & 0xFFFC0000)
50 | MCFSDRAMC_DMR_V);
TsiChung Liew4cb4e652008-08-11 15:54:25 +000051 asm("nop");
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050052
53 /* Set IP (bit 3) in DACR */
54 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IP;
TsiChung Liew4cb4e652008-08-11 15:54:25 +000055 asm("nop");
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050056
57 /* Wait 30ns to allow banks to precharge */
58 for (i = 0; i < 5; i++) {
59 asm ("nop");
60 }
61
62 /* Write to this block to initiate precharge */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020063 *(u32 *)(CONFIG_SYS_SDRAM_BASE) = 0xA5A59696;
TsiChung Liew4cb4e652008-08-11 15:54:25 +000064 asm("nop");
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050065
66 /* Set RE (bit 15) in DACR */
67 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_RE;
TsiChung Liew4cb4e652008-08-11 15:54:25 +000068 asm("nop");
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050069
70 /* Wait for at least 8 auto refresh cycles to occur */
71 for (i = 0; i < 2000; i++) {
72 asm(" nop");
73 }
74
75 /* Finish the configuration by issuing the IMRS. */
76 MCFSDRAMC_DACR0 |= MCFSDRAMC_DACR_IMRS;
TsiChung Liew4cb4e652008-08-11 15:54:25 +000077 asm("nop");
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050078
79 /* Write to the SDRAM Mode Register */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020080 *(u32 *)(CONFIG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696;
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050081 }
Simon Glass088454c2017-03-31 08:40:25 -060082 gd->ram_size = dramsize;
83
84 return 0;
wdenk4e5ca3e2003-12-08 01:34:36 +000085}