blob: 5981a2711a44274b430337577f510062ab14519c [file] [log] [blame]
Marian Balakowiczc952aed2006-05-09 11:54:44 +02001/*
2 * (C) Copyright 2000-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Marian Balakowiczc952aed2006-05-09 11:54:44 +02006 */
7
8#include <common.h>
TsiChungLiew1692b482007-08-15 20:32:06 -05009#include <asm/immap.h>
Marian Balakowiczc952aed2006-05-09 11:54:44 +020010
11int checkboard (void) {
12 puts ("Board: Freescale M5271EVB\n");
13 return 0;
14};
15
Becky Brucebd99ae72008-06-09 16:03:40 -050016phys_size_t initdram (int board_type) {
Marian Balakowiczc952aed2006-05-09 11:54:44 +020017
18 int i;
19
20 /* Enable Address lines 23-21 and lower 16bits of data path */
21 mbar_writeByte(MCF_GPIO_PAR_AD, MCF_GPIO_AD_ADDR23 |
22 MCF_GPIO_AD_ADDR22 | MCF_GPIO_AD_ADDR21 |
23 MCF_GPIO_AD_DATAL);
24
25 /* Set CS2 pin to be SD_CS0 */
26 mbar_writeByte(MCF_GPIO_PAR_CS, mbar_readByte(MCF_GPIO_PAR_CS)
27 | MCF_GPIO_PAR_CS_PAR_CS2);
28
29 /* Configure SDRAM Control Pin Assignemnt Register */
30 mbar_writeByte(MCF_GPIO_PAR_SDRAM, MCF_GPIO_SDRAM_CSSDCS_00 |
31 MCF_GPIO_SDRAM_SDWE | MCF_GPIO_SDRAM_SCAS |
32 MCF_GPIO_SDRAM_SRAS | MCF_GPIO_SDRAM_SCKE |
33 MCF_GPIO_SDRAM_SDCS_11);
TsiChung Liew7c1822e2010-03-10 16:14:01 -060034 asm(" nop");
Marian Balakowiczc952aed2006-05-09 11:54:44 +020035
36 /*
37 * Check to see if the SDRAM has already been initialized
38 * by a run control tool
39 */
Wolfgang Denkc2c49442006-05-10 17:43:20 +020040 if (!(mbar_readLong(MCF_SDRAMC_DACR0) & MCF_SDRAMC_DACRn_RE)) {
Marian Balakowiczc952aed2006-05-09 11:54:44 +020041 /* Initialize DRAM Control Register: DCR */
Wolfgang Denkc2c49442006-05-10 17:43:20 +020042 mbar_writeShort(MCF_SDRAMC_DCR,
TsiChung Liew7c1822e2010-03-10 16:14:01 -060043 MCF_SDRAMC_DCR_RTIM(2)
44 | MCF_SDRAMC_DCR_RC(0x2E));
45 asm(" nop");
Marian Balakowiczc952aed2006-05-09 11:54:44 +020046
47 /*
48 * Initialize DACR0
49 *
50 * CASL: 01
51 * CBM: cmd at A20, bank select bits 21 and up
52 * PS: 32bit port size
53 */
54 mbar_writeLong(MCF_SDRAMC_DACR0,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020055 MCF_SDRAMC_DACRn_BA(CONFIG_SYS_SDRAM_BASE>>18)
Marian Balakowiczc952aed2006-05-09 11:54:44 +020056 | MCF_SDRAMC_DACRn_CASL(1)
57 | MCF_SDRAMC_DACRn_CBM(3)
58 | MCF_SDRAMC_DACRn_PS(0));
TsiChung Liew7c1822e2010-03-10 16:14:01 -060059 asm(" nop");
Marian Balakowiczc952aed2006-05-09 11:54:44 +020060
61 /* Initialize DMR0 */
Wolfgang Denkc2c49442006-05-10 17:43:20 +020062 mbar_writeLong(MCF_SDRAMC_DMR0,
Marian Balakowiczc952aed2006-05-09 11:54:44 +020063 MCF_SDRAMC_DMRn_BAM_16M
64 | MCF_SDRAMC_DMRn_V);
TsiChung Liew7c1822e2010-03-10 16:14:01 -060065 asm(" nop");
Marian Balakowiczc952aed2006-05-09 11:54:44 +020066
67 /* Set IP bit in DACR */
68 mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0)
69 | MCF_SDRAMC_DACRn_IP);
TsiChung Liew7c1822e2010-03-10 16:14:01 -060070 asm(" nop");
Marian Balakowiczc952aed2006-05-09 11:54:44 +020071
72 /* Wait at least 20ns to allow banks to precharge */
73 for (i = 0; i < 5; i++)
74 asm(" nop");
75
76 /* Write to this block to initiate precharge */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020077 *(u32 *)(CONFIG_SYS_SDRAM_BASE) = 0xa5a5a5a5;
TsiChung Liew7c1822e2010-03-10 16:14:01 -060078 asm(" nop");
Marian Balakowiczc952aed2006-05-09 11:54:44 +020079
80 /* Set RE bit in DACR */
81 mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0)
82 | MCF_SDRAMC_DACRn_RE);
83
84 /* Wait for at least 8 auto refresh cycles to occur */
85 for (i = 0; i < 2000; i++)
86 asm(" nop");
87
88 /* Finish the configuration by issuing the MRS */
89 mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0)
90 | MCF_SDRAMC_DACRn_MRS);
TsiChung Liew7c1822e2010-03-10 16:14:01 -060091 asm(" nop");
Marian Balakowiczc952aed2006-05-09 11:54:44 +020092
93 /*
94 * Write to the SDRAM Mode Register A0-A11 = 0x400
95 *
96 * Write Burst Mode = Programmed Burst Length
97 * Op Mode = Standard Op
98 * CAS Latency = 2
99 * Burst Type = Sequential
100 * Burst Length = 1
101 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200102 *(u32 *)(CONFIG_SYS_SDRAM_BASE + 0x400) = 0xa5a5a5a5;
TsiChung Liew7c1822e2010-03-10 16:14:01 -0600103 asm(" nop");
Marian Balakowiczc952aed2006-05-09 11:54:44 +0200104 }
105
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200106 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
Marian Balakowiczc952aed2006-05-09 11:54:44 +0200107};
108
109int testdram (void) {
110
111 /* TODO: XXX XXX XXX */
112 printf ("DRAM test not implemented!\n");
113
114 return (0);
115}