blob: 73660d802db632e86ac520ff15603aaad75d8be5 [file] [log] [blame]
Bartlomiej Sieka8ff81c62006-12-20 00:27:32 +01001/*
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+
Bartlomiej Sieka8ff81c62006-12-20 00:27:32 +01006 */
7
8#include <common.h>
TsiChungLiew47dfc1c2007-08-15 19:43:20 -05009#include <asm/immap.h>
Bartlomiej Sieka8ff81c62006-12-20 00:27:32 +010010
11int checkboard (void) {
12 puts ("Board: iDMR\n");
13 return 0;
14};
15
Becky Brucebd99ae72008-06-09 16:03:40 -050016phys_size_t initdram (int board_type) {
Bartlomiej Sieka8ff81c62006-12-20 00:27:32 +010017 int i;
18
19 /*
20 * After reset, CS0 is configured to cover entire address space. We
21 * need to configure it to its proper values, so that writes to
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020022 * CONFIG_SYS_SDRAM_BASE and vicinity during SDRAM controller setup below do
Bartlomiej Sieka8ff81c62006-12-20 00:27:32 +010023 * now fall under CS0 (see 16.3.1 of the MCF5271 Reference Manual).
24 */
25
26 /* Flash chipselect, CS0 */
27 /* ;CSAR0: Flash at 0xFF800000 */
28 mbar_writeShort(0x0080, 0xFF80);
29
30 /* CSCR0: Flash 6 waits, 16bit */
31 mbar_writeShort(0x008A, 0x1980);
32
33 /* CSMR0: Flash 8MB, R/W, valid */
34 mbar_writeLong(0x0084, 0x007F0001);
35
36
37 /*
38 * SDRAM configuration proper
39 */
40
41 /*
42 * Address/Data Pin Assignment Reg.: enable address lines 23-21; do
43 * not enable data pins D[15:0], as we have 16 bit port to SDRAM
44 */
45 mbar_writeByte(MCF_GPIO_PAR_AD,
46 MCF_GPIO_AD_ADDR23 |
47 MCF_GPIO_AD_ADDR22 |
48 MCF_GPIO_AD_ADDR21);
49
50 /* No need to configure BS pins - reset values are OK */
51
52 /* Chip Select Pin Assignment Reg.: set CS[1-7] to GPIO */
53 mbar_writeByte(MCF_GPIO_PAR_CS, 0x00);
54
55 /* SDRAM Control Pin Assignment Reg. */
56 mbar_writeByte(MCF_GPIO_PAR_SDRAM,
57 MCF_GPIO_SDRAM_CSSDCS_00 | /* no matter: PAR_CS=0 */
58 MCF_GPIO_SDRAM_SDWE |
59 MCF_GPIO_SDRAM_SCAS |
60 MCF_GPIO_SDRAM_SRAS |
61 MCF_GPIO_SDRAM_SCKE |
62 MCF_GPIO_SDRAM_SDCS_01);
63
64 /*
Wolfgang Denkaf0501a2008-10-19 02:35:50 +020065 * Wait 100us. We run the bus at 50MHz, one cycle is 20ns. So 5
Bartlomiej Sieka8ff81c62006-12-20 00:27:32 +010066 * iterations will do, but we do 10 just to be safe.
67 */
68 for (i = 0; i < 10; ++i)
69 asm(" nop");
70
71
72 /* 1. Initialize DRAM Control Register: DCR */
73 mbar_writeShort(MCF_SDRAMC_DCR,
74 MCF_SDRAMC_DCR_RTIM(0x10) | /* 65ns */
75 MCF_SDRAMC_DCR_RC(0x60)); /* 1562 cycles */
76
77
78 /*
79 * 2. Initialize DACR0
80 *
81 * CL: 11 (CL=3: 0x03, 0x02; CL=2: 0x1)
82 * CBM: cmd at A20, bank select bits 21 and up
83 * PS: 16 bit
84 */
85 mbar_writeLong(MCF_SDRAMC_DACR0,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020086 MCF_SDRAMC_DACRn_BA(CONFIG_SYS_SDRAM_BASE>>18) |
Bartlomiej Sieka8ff81c62006-12-20 00:27:32 +010087 MCF_SDRAMC_DACRn_BA(0x00) |
88 MCF_SDRAMC_DACRn_CASL(0x03) |
89 MCF_SDRAMC_DACRn_CBM(0x03) |
90 MCF_SDRAMC_DACRn_PS(0x03));
91
92 /* Initialize DMR0 */
93 mbar_writeLong(MCF_SDRAMC_DMR0,
94 MCF_SDRAMC_DMRn_BAM_16M |
95 MCF_SDRAMC_DMRn_V);
96
97
98 /* 3. Set IP bit in DACR to initiate PALL command */
99 mbar_writeLong(MCF_SDRAMC_DACR0,
100 mbar_readLong(MCF_SDRAMC_DACR0) |
101 MCF_SDRAMC_DACRn_IP);
102
103 /* Write to this block to initiate precharge */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200104 *(volatile u16 *)(CONFIG_SYS_SDRAM_BASE) = 0xa5a5;
Bartlomiej Sieka8ff81c62006-12-20 00:27:32 +0100105
106 /*
107 * Wait at least 20ns to allow banks to precharge (t_RP = 20ns). We
108 * wait a wee longer, just to be safe.
109 */
110 for (i = 0; i < 5; ++i)
111 asm(" nop");
112
113
114 /* 4. Set RE bit in DACR */
115 mbar_writeLong(MCF_SDRAMC_DACR0,
116 mbar_readLong(MCF_SDRAMC_DACR0) |
117 MCF_SDRAMC_DACRn_RE);
118
119 /*
120 * Wait for at least 8 auto refresh cycles to occur, i.e. at least
121 * 781 bus cycles.
122 */
123 for (i = 0; i < 1000; ++i)
124 asm(" nop");
125
126 /* Finish the configuration by issuing the MRS */
127 mbar_writeLong(MCF_SDRAMC_DACR0,
128 mbar_readLong(MCF_SDRAMC_DACR0) |
129 MCF_SDRAMC_DACRn_MRS);
130
131 /*
132 * Write to the SDRAM Mode Register A0-A11 = 0x400
133 *
134 * Write Burst Mode = Programmed Burst Length
135 * Op Mode = Standard Op
136 * CAS Latency = 3
137 * Burst Type = Sequential
138 * Burst Length = 1
139 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200140 *(volatile u32 *)(CONFIG_SYS_SDRAM_BASE + 0x1800) = 0xa5a5a5a5;
Bartlomiej Sieka8ff81c62006-12-20 00:27:32 +0100141
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200142 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
Bartlomiej Sieka8ff81c62006-12-20 00:27:32 +0100143};
144
145
146int testdram (void) {
147
148 /* TODO: XXX XXX XXX */
149 printf ("DRAM test not implemented!\n");
150
151 return (0);
152}