blob: 446f102e58c2bf42d0764a8e45c9f27d8dd4a447 [file] [log] [blame]
Marian Balakowicz78b123c2006-05-09 11:54:44 +02001/*
2 * (C) Copyright 2000-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
TsiChungLiewf28e1bd2007-08-15 20:32:06 -050025#include <asm/immap.h>
Marian Balakowicz78b123c2006-05-09 11:54:44 +020026
27int checkboard (void) {
28 puts ("Board: Freescale M5271EVB\n");
29 return 0;
30};
31
Becky Bruce9973e3c2008-06-09 16:03:40 -050032phys_size_t initdram (int board_type) {
Marian Balakowicz78b123c2006-05-09 11:54:44 +020033
34 int i;
35
36 /* Enable Address lines 23-21 and lower 16bits of data path */
37 mbar_writeByte(MCF_GPIO_PAR_AD, MCF_GPIO_AD_ADDR23 |
38 MCF_GPIO_AD_ADDR22 | MCF_GPIO_AD_ADDR21 |
39 MCF_GPIO_AD_DATAL);
40
41 /* Set CS2 pin to be SD_CS0 */
42 mbar_writeByte(MCF_GPIO_PAR_CS, mbar_readByte(MCF_GPIO_PAR_CS)
43 | MCF_GPIO_PAR_CS_PAR_CS2);
44
45 /* Configure SDRAM Control Pin Assignemnt Register */
46 mbar_writeByte(MCF_GPIO_PAR_SDRAM, MCF_GPIO_SDRAM_CSSDCS_00 |
47 MCF_GPIO_SDRAM_SDWE | MCF_GPIO_SDRAM_SCAS |
48 MCF_GPIO_SDRAM_SRAS | MCF_GPIO_SDRAM_SCKE |
49 MCF_GPIO_SDRAM_SDCS_11);
TsiChung Liew53e42902010-03-10 16:14:01 -060050 asm(" nop");
Marian Balakowicz78b123c2006-05-09 11:54:44 +020051
52 /*
53 * Check to see if the SDRAM has already been initialized
54 * by a run control tool
55 */
Wolfgang Denk977b50f2006-05-10 17:43:20 +020056 if (!(mbar_readLong(MCF_SDRAMC_DACR0) & MCF_SDRAMC_DACRn_RE)) {
Marian Balakowicz78b123c2006-05-09 11:54:44 +020057 /* Initialize DRAM Control Register: DCR */
Wolfgang Denk977b50f2006-05-10 17:43:20 +020058 mbar_writeShort(MCF_SDRAMC_DCR,
TsiChung Liew53e42902010-03-10 16:14:01 -060059 MCF_SDRAMC_DCR_RTIM(2)
60 | MCF_SDRAMC_DCR_RC(0x2E));
61 asm(" nop");
Marian Balakowicz78b123c2006-05-09 11:54:44 +020062
63 /*
64 * Initialize DACR0
65 *
66 * CASL: 01
67 * CBM: cmd at A20, bank select bits 21 and up
68 * PS: 32bit port size
69 */
70 mbar_writeLong(MCF_SDRAMC_DACR0,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020071 MCF_SDRAMC_DACRn_BA(CONFIG_SYS_SDRAM_BASE>>18)
Marian Balakowicz78b123c2006-05-09 11:54:44 +020072 | MCF_SDRAMC_DACRn_CASL(1)
73 | MCF_SDRAMC_DACRn_CBM(3)
74 | MCF_SDRAMC_DACRn_PS(0));
TsiChung Liew53e42902010-03-10 16:14:01 -060075 asm(" nop");
Marian Balakowicz78b123c2006-05-09 11:54:44 +020076
77 /* Initialize DMR0 */
Wolfgang Denk977b50f2006-05-10 17:43:20 +020078 mbar_writeLong(MCF_SDRAMC_DMR0,
Marian Balakowicz78b123c2006-05-09 11:54:44 +020079 MCF_SDRAMC_DMRn_BAM_16M
80 | MCF_SDRAMC_DMRn_V);
TsiChung Liew53e42902010-03-10 16:14:01 -060081 asm(" nop");
Marian Balakowicz78b123c2006-05-09 11:54:44 +020082
83 /* Set IP bit in DACR */
84 mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0)
85 | MCF_SDRAMC_DACRn_IP);
TsiChung Liew53e42902010-03-10 16:14:01 -060086 asm(" nop");
Marian Balakowicz78b123c2006-05-09 11:54:44 +020087
88 /* Wait at least 20ns to allow banks to precharge */
89 for (i = 0; i < 5; i++)
90 asm(" nop");
91
92 /* Write to this block to initiate precharge */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020093 *(u32 *)(CONFIG_SYS_SDRAM_BASE) = 0xa5a5a5a5;
TsiChung Liew53e42902010-03-10 16:14:01 -060094 asm(" nop");
Marian Balakowicz78b123c2006-05-09 11:54:44 +020095
96 /* Set RE bit in DACR */
97 mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0)
98 | MCF_SDRAMC_DACRn_RE);
99
100 /* Wait for at least 8 auto refresh cycles to occur */
101 for (i = 0; i < 2000; i++)
102 asm(" nop");
103
104 /* Finish the configuration by issuing the MRS */
105 mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0)
106 | MCF_SDRAMC_DACRn_MRS);
TsiChung Liew53e42902010-03-10 16:14:01 -0600107 asm(" nop");
Marian Balakowicz78b123c2006-05-09 11:54:44 +0200108
109 /*
110 * Write to the SDRAM Mode Register A0-A11 = 0x400
111 *
112 * Write Burst Mode = Programmed Burst Length
113 * Op Mode = Standard Op
114 * CAS Latency = 2
115 * Burst Type = Sequential
116 * Burst Length = 1
117 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200118 *(u32 *)(CONFIG_SYS_SDRAM_BASE + 0x400) = 0xa5a5a5a5;
TsiChung Liew53e42902010-03-10 16:14:01 -0600119 asm(" nop");
Marian Balakowicz78b123c2006-05-09 11:54:44 +0200120 }
121
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200122 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
Marian Balakowicz78b123c2006-05-09 11:54:44 +0200123};
124
125int testdram (void) {
126
127 /* TODO: XXX XXX XXX */
128 printf ("DRAM test not implemented!\n");
129
130 return (0);
131}