blob: fdb46b1f3598530fd37cef2ab135f1d0ff339cd5 [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
wdenk180d3f72004-01-04 16:28:35 +00002 * (C) Copyright 2000-2004
wdenkfe8c2802002-11-03 00:38:21 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
wdenk180d3f72004-01-04 16:28:35 +00005 * Modified by, Yuli Barcohen, Arabella Software Ltd., yuli@arabellasw.com
6 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
wdenkfe8c2802002-11-03 00:38:21 +00008 */
9
wdenkfe8c2802002-11-03 00:38:21 +000010#include <config.h>
wdenk180d3f72004-01-04 16:28:35 +000011#include <common.h>
wdenkfe8c2802002-11-03 00:38:21 +000012#include <mpc8xx.h>
wdenk11142572004-06-06 21:35:06 +000013#include <pcmcia.h>
wdenkfe8c2802002-11-03 00:38:21 +000014
15#define _NOT_USED_ 0xFFFFFFFF
16
wdenk180d3f72004-01-04 16:28:35 +000017/* ========================================================================= */
18
wdenk11142572004-06-06 21:35:06 +000019#ifndef CONFIG_MPC885ADS /* No old DRAM on MPC885ADS */
wdenk180d3f72004-01-04 16:28:35 +000020
wdenkfe8c2802002-11-03 00:38:21 +000021#if defined(CONFIG_DRAM_50MHZ)
22/* 50MHz tables */
wdenk2535d602003-07-17 23:16:40 +000023static const uint dram_60ns[] =
wdenkfe8c2802002-11-03 00:38:21 +000024{ 0x8fffec24, 0x0fffec04, 0x0cffec04, 0x00ffec04,
wdenk2535d602003-07-17 23:16:40 +000025 0x00ffec00, 0x37ffec47, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000026 0x8fffec24, 0x0fffec04, 0x08ffec04, 0x00ffec0c,
27 0x03ffec00, 0x00ffec44, 0x00ffcc08, 0x0cffcc44,
28 0x00ffec0c, 0x03ffec00, 0x00ffec44, 0x00ffcc00,
wdenk2535d602003-07-17 23:16:40 +000029 0x3fffc847, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000030 0x8fafcc24, 0x0fafcc04, 0x0cafcc00, 0x11bfcc47,
wdenk2535d602003-07-17 23:16:40 +000031 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000032 0x8fafcc24, 0x0fafcc04, 0x0cafcc00, 0x03afcc4c,
33 0x0cafcc00, 0x03afcc4c, 0x0cafcc00, 0x03afcc4c,
wdenk2535d602003-07-17 23:16:40 +000034 0x0cafcc00, 0x33bfcc4f, _NOT_USED_, _NOT_USED_,
35 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000036 0xc0ffcc84, 0x00ffcc04, 0x07ffcc04, 0x3fffcc06,
wdenk2535d602003-07-17 23:16:40 +000037 0xffffcc85, 0xffffcc05, _NOT_USED_, _NOT_USED_,
38 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
39 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
wdenkfe8c2802002-11-03 00:38:21 +000040
wdenk2535d602003-07-17 23:16:40 +000041static const uint dram_70ns[] =
wdenkfe8c2802002-11-03 00:38:21 +000042{ 0x8fffcc24, 0x0fffcc04, 0x0cffcc04, 0x00ffcc04,
wdenk2535d602003-07-17 23:16:40 +000043 0x00ffcc00, 0x37ffcc47, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000044 0x8fffcc24, 0x0fffcc04, 0x0cffcc04, 0x00ffcc04,
45 0x00ffcc08, 0x0cffcc44, 0x00ffec0c, 0x03ffec00,
46 0x00ffec44, 0x00ffcc08, 0x0cffcc44, 0x00ffec04,
wdenk2535d602003-07-17 23:16:40 +000047 0x00ffec00, 0x3fffec47, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000048 0x8fafcc24, 0x0fafcc04, 0x0cafcc00, 0x11bfcc47,
wdenk2535d602003-07-17 23:16:40 +000049 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000050 0x8fafcc24, 0x0fafcc04, 0x0cafcc00, 0x03afcc4c,
51 0x0cafcc00, 0x03afcc4c, 0x0cafcc00, 0x03afcc4c,
wdenk2535d602003-07-17 23:16:40 +000052 0x0cafcc00, 0x33bfcc4f, _NOT_USED_, _NOT_USED_,
53 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000054 0xe0ffcc84, 0x00ffcc04, 0x00ffcc04, 0x0fffcc04,
wdenk2535d602003-07-17 23:16:40 +000055 0x7fffcc06, 0xffffcc85, 0xffffcc05, _NOT_USED_,
56 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
57 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
wdenkfe8c2802002-11-03 00:38:21 +000058
wdenk2535d602003-07-17 23:16:40 +000059static const uint edo_60ns[] =
wdenkfe8c2802002-11-03 00:38:21 +000060{ 0x8ffbec24, 0x0ff3ec04, 0x0cf3ec04, 0x00f3ec04,
wdenk2535d602003-07-17 23:16:40 +000061 0x00f3ec00, 0x37f7ec47, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000062 0x8fffec24, 0x0ffbec04, 0x0cf3ec04, 0x00f3ec0c,
63 0x0cf3ec00, 0x00f3ec4c, 0x0cf3ec00, 0x00f3ec4c,
64 0x0cf3ec00, 0x00f3ec44, 0x03f3ec00, 0x3ff7ec47,
wdenk2535d602003-07-17 23:16:40 +000065 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000066 0x8fffcc24, 0x0fefcc04, 0x0cafcc00, 0x11bfcc47,
wdenk2535d602003-07-17 23:16:40 +000067 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000068 0x8fffcc24, 0x0fefcc04, 0x0cafcc00, 0x03afcc4c,
69 0x0cafcc00, 0x03afcc4c, 0x0cafcc00, 0x03afcc4c,
wdenk2535d602003-07-17 23:16:40 +000070 0x0cafcc00, 0x33bfcc4f, _NOT_USED_, _NOT_USED_,
71 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000072 0xc0ffcc84, 0x00ffcc04, 0x07ffcc04, 0x3fffcc06,
wdenk2535d602003-07-17 23:16:40 +000073 0xffffcc85, 0xffffcc05, _NOT_USED_, _NOT_USED_,
74 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
75 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
wdenkfe8c2802002-11-03 00:38:21 +000076
wdenk2535d602003-07-17 23:16:40 +000077static const uint edo_70ns[] =
wdenkfe8c2802002-11-03 00:38:21 +000078{ 0x8ffbcc24, 0x0ff3cc04, 0x0cf3cc04, 0x00f3cc04,
wdenk2535d602003-07-17 23:16:40 +000079 0x00f3cc00, 0x37f7cc47, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000080 0x8fffcc24, 0x0ffbcc04, 0x0cf3cc04, 0x00f3cc0c,
81 0x03f3cc00, 0x00f3cc44, 0x00f3ec0c, 0x0cf3ec00,
82 0x00f3ec4c, 0x03f3ec00, 0x00f3ec44, 0x00f3cc00,
wdenk2535d602003-07-17 23:16:40 +000083 0x33f7cc47, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000084 0x8fffcc24, 0x0fefcc04, 0x0cafcc00, 0x11bfcc47,
wdenk2535d602003-07-17 23:16:40 +000085 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000086 0x8fffcc24, 0x0fefcc04, 0x0cafcc00, 0x03afcc4c,
87 0x0cafcc00, 0x03afcc4c, 0x0cafcc00, 0x03afcc4c,
wdenk2535d602003-07-17 23:16:40 +000088 0x0cafcc00, 0x33bfcc47, _NOT_USED_, _NOT_USED_,
89 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +000090 0xe0ffcc84, 0x00ffcc04, 0x00ffcc04, 0x0fffcc04,
wdenk2535d602003-07-17 23:16:40 +000091 0x7fffcc04, 0xffffcc86, 0xffffcc05, _NOT_USED_,
92 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
93 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
wdenkfe8c2802002-11-03 00:38:21 +000094
95#elif defined(CONFIG_DRAM_25MHZ)
96
97/* 25MHz tables */
98
wdenk2535d602003-07-17 23:16:40 +000099static const uint dram_60ns[] =
100{ 0x0fffcc04, 0x08ffcc00, 0x33ffcc47, _NOT_USED_,
101 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000102 0x0fffcc24, 0x0fffcc04, 0x08ffcc00, 0x03ffcc4c,
103 0x08ffcc00, 0x03ffcc4c, 0x08ffcc00, 0x03ffcc4c,
wdenk2535d602003-07-17 23:16:40 +0000104 0x08ffcc00, 0x33ffcc47, _NOT_USED_, _NOT_USED_,
105 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
106 0x0fafcc04, 0x08afcc00, 0x3fbfcc47, _NOT_USED_,
107 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000108 0x0fafcc04, 0x0cafcc00, 0x01afcc4c, 0x0cafcc00,
109 0x01afcc4c, 0x0cafcc00, 0x01afcc4c, 0x0cafcc00,
wdenk2535d602003-07-17 23:16:40 +0000110 0x31bfcc43, _NOT_USED_, _NOT_USED_, _NOT_USED_,
111 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000112 0x80ffcc84, 0x13ffcc04, 0xffffcc87, 0xffffcc05,
wdenk2535d602003-07-17 23:16:40 +0000113 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
114 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
115 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
wdenkfe8c2802002-11-03 00:38:21 +0000116
wdenk2535d602003-07-17 23:16:40 +0000117static const uint dram_70ns[] =
wdenkfe8c2802002-11-03 00:38:21 +0000118{ 0x0fffec04, 0x08ffec04, 0x00ffec00, 0x3fffcc47,
wdenk2535d602003-07-17 23:16:40 +0000119 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000120 0x0fffcc24, 0x0fffcc04, 0x08ffcc00, 0x03ffcc4c,
121 0x08ffcc00, 0x03ffcc4c, 0x08ffcc00, 0x03ffcc4c,
wdenk2535d602003-07-17 23:16:40 +0000122 0x08ffcc00, 0x33ffcc47, _NOT_USED_, _NOT_USED_,
123 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
124 0x0fafcc04, 0x08afcc00, 0x3fbfcc47, _NOT_USED_,
125 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000126 0x0fafcc04, 0x0cafcc00, 0x01afcc4c, 0x0cafcc00,
127 0x01afcc4c, 0x0cafcc00, 0x01afcc4c, 0x0cafcc00,
wdenk2535d602003-07-17 23:16:40 +0000128 0x31bfcc43, _NOT_USED_, _NOT_USED_, _NOT_USED_,
129 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000130 0xc0ffcc84, 0x01ffcc04, 0x7fffcc86, 0xffffcc05,
wdenk2535d602003-07-17 23:16:40 +0000131 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
132 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
133 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
wdenkfe8c2802002-11-03 00:38:21 +0000134
wdenk2535d602003-07-17 23:16:40 +0000135static const uint edo_60ns[] =
wdenkfe8c2802002-11-03 00:38:21 +0000136{ 0x0ffbcc04, 0x0cf3cc04, 0x00f3cc00, 0x33f7cc47,
wdenk2535d602003-07-17 23:16:40 +0000137 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000138 0x0ffbcc04, 0x09f3cc0c, 0x09f3cc0c, 0x09f3cc0c,
wdenk2535d602003-07-17 23:16:40 +0000139 0x08f3cc00, 0x3ff7cc47, _NOT_USED_, _NOT_USED_,
140 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
141 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000142 0x0fefcc04, 0x08afcc04, 0x00afcc00, 0x3fbfcc47,
wdenk2535d602003-07-17 23:16:40 +0000143 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000144 0x0fefcc04, 0x08afcc00, 0x07afcc48, 0x08afcc48,
wdenk2535d602003-07-17 23:16:40 +0000145 0x08afcc48, 0x39bfcc47, _NOT_USED_, _NOT_USED_,
146 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
147 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000148 0x80ffcc84, 0x13ffcc04, 0xffffcc87, 0xffffcc05,
wdenk2535d602003-07-17 23:16:40 +0000149 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
150 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
151 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
wdenkfe8c2802002-11-03 00:38:21 +0000152
wdenk2535d602003-07-17 23:16:40 +0000153static const uint edo_70ns[] =
wdenkfe8c2802002-11-03 00:38:21 +0000154{ 0x0ffbcc04, 0x0cf3cc04, 0x00f3cc00, 0x33f7cc47,
wdenk2535d602003-07-17 23:16:40 +0000155 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000156 0x0ffbec04, 0x08f3ec04, 0x03f3ec48, 0x08f3cc00,
157 0x0ff3cc4c, 0x08f3cc00, 0x0ff3cc4c, 0x08f3cc00,
wdenk2535d602003-07-17 23:16:40 +0000158 0x3ff7cc47, _NOT_USED_, _NOT_USED_, _NOT_USED_,
159 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000160 0x0fefcc04, 0x08afcc04, 0x00afcc00, 0x3fbfcc47,
wdenk2535d602003-07-17 23:16:40 +0000161 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000162 0x0fefcc04, 0x08afcc00, 0x07afcc4c, 0x08afcc00,
163 0x07afcc4c, 0x08afcc00, 0x07afcc4c, 0x08afcc00,
wdenk2535d602003-07-17 23:16:40 +0000164 0x37bfcc47, _NOT_USED_, _NOT_USED_, _NOT_USED_,
165 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000166 0xc0ffcc84, 0x01ffcc04, 0x7fffcc86, 0xffffcc05,
wdenk2535d602003-07-17 23:16:40 +0000167 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
168 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
169 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
wdenkfe8c2802002-11-03 00:38:21 +0000170#else
wdenk2535d602003-07-17 23:16:40 +0000171#error dram not correctly defined - use CONFIG_DRAM_25MHZ or CONFIG_DRAM_50MHZ
wdenkfe8c2802002-11-03 00:38:21 +0000172#endif
173
174/* ------------------------------------------------------------------------- */
wdenk2535d602003-07-17 23:16:40 +0000175static int _draminit (uint base, uint noMbytes, uint edo, uint delay)
176{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200177 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenkfe8c2802002-11-03 00:38:21 +0000178 volatile memctl8xx_t *memctl = &immap->im_memctl;
179
180 /* init upm */
181
wdenk2535d602003-07-17 23:16:40 +0000182 switch (delay) {
183 case 70:
184 if (edo) {
185 upmconfig (UPMA, (uint *) edo_70ns,
186 sizeof (edo_70ns) / sizeof (uint));
187 } else {
188 upmconfig (UPMA, (uint *) dram_70ns,
189 sizeof (dram_70ns) / sizeof (uint));
wdenkfe8c2802002-11-03 00:38:21 +0000190 }
191
wdenk2535d602003-07-17 23:16:40 +0000192 break;
wdenkfe8c2802002-11-03 00:38:21 +0000193
wdenk2535d602003-07-17 23:16:40 +0000194 case 60:
195 if (edo) {
196 upmconfig (UPMA, (uint *) edo_60ns,
197 sizeof (edo_60ns) / sizeof (uint));
198 } else {
199 upmconfig (UPMA, (uint *) dram_60ns,
200 sizeof (dram_60ns) / sizeof (uint));
wdenkfe8c2802002-11-03 00:38:21 +0000201 }
202
wdenk2535d602003-07-17 23:16:40 +0000203 break;
204
205 default:
206 return -1;
wdenkfe8c2802002-11-03 00:38:21 +0000207 }
208
wdenk2535d602003-07-17 23:16:40 +0000209 memctl->memc_mptpr = 0x0400; /* divide by 16 */
wdenkfe8c2802002-11-03 00:38:21 +0000210
wdenk2535d602003-07-17 23:16:40 +0000211 switch (noMbytes) {
212 case 4: /* 4 Mbyte uses only CS2 */
213 memctl->memc_mamr = 0x13a01114; /* PTA 0x13 AMA 010 */
214 memctl->memc_or2 = 0xffc00800; /* 4M */
215 break;
wdenkfe8c2802002-11-03 00:38:21 +0000216
wdenk2535d602003-07-17 23:16:40 +0000217 case 8: /* 8 Mbyte uses both CS3 and CS2 */
218 memctl->memc_mamr = 0x13a01114; /* PTA 0x13 AMA 010 */
219 memctl->memc_or3 = 0xffc00800; /* 4M */
220 memctl->memc_br3 = 0x00400081 + base;
221 memctl->memc_or2 = 0xffc00800; /* 4M */
222 break;
wdenkfe8c2802002-11-03 00:38:21 +0000223
wdenk2535d602003-07-17 23:16:40 +0000224 case 16: /* 16 Mbyte uses only CS2 */
wdenk2535d602003-07-17 23:16:40 +0000225 memctl->memc_mamr = 0x13b01114; /* PTA 0x13 AMA 011 */
wdenk2535d602003-07-17 23:16:40 +0000226 memctl->memc_or2 = 0xff000800; /* 16M */
227 break;
wdenkfe8c2802002-11-03 00:38:21 +0000228
wdenk2535d602003-07-17 23:16:40 +0000229 case 32: /* 32 Mbyte uses both CS3 and CS2 */
230 memctl->memc_mamr = 0x13b01114; /* PTA 0x13 AMA 011 */
231 memctl->memc_or3 = 0xff000800; /* 16M */
232 memctl->memc_br3 = 0x01000081 + base;
233 memctl->memc_or2 = 0xff000800; /* 16M */
234 break;
235
236 default:
237 return -1;
wdenkfe8c2802002-11-03 00:38:21 +0000238 }
239
wdenk2535d602003-07-17 23:16:40 +0000240 memctl->memc_br2 = 0x81 + base; /* use upma */
241
wdenkb028f712003-12-07 21:39:28 +0000242 *((uint *) BCSR1) &= ~BCSR1_DRAM_EN; /* enable dram */
243
wdenk2535d602003-07-17 23:16:40 +0000244 /* if no dimm is inserted, noMbytes is still detected as 8m, so
245 * sanity check top and bottom of memory */
246
wdenkc83bf6a2004-01-06 22:38:14 +0000247 /* check bytes / 2 because get_ram_size tests at base+bytes, which
wdenk2535d602003-07-17 23:16:40 +0000248 * is not mapped */
wdenkb028f712003-12-07 21:39:28 +0000249 if (noMbytes == 8)
wdenkc83bf6a2004-01-06 22:38:14 +0000250 if (get_ram_size ((long *) base, noMbytes << 19) != noMbytes << 19) {
wdenkb028f712003-12-07 21:39:28 +0000251 *((uint *) BCSR1) |= BCSR1_DRAM_EN; /* disable dram */
252 return -1;
253 }
wdenk2535d602003-07-17 23:16:40 +0000254
wdenkfe8c2802002-11-03 00:38:21 +0000255 return 0;
256}
257
258/* ------------------------------------------------------------------------- */
259
wdenk2535d602003-07-17 23:16:40 +0000260static void _dramdisable(void)
wdenkfe8c2802002-11-03 00:38:21 +0000261{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200262 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
wdenkfe8c2802002-11-03 00:38:21 +0000263 volatile memctl8xx_t *memctl = &immap->im_memctl;
264
265 memctl->memc_br2 = 0x00000000;
266 memctl->memc_br3 = 0x00000000;
267
268 /* maybe we should turn off upma here or something */
269}
wdenk11142572004-06-06 21:35:06 +0000270#endif /* !CONFIG_MPC885ADS */
wdenkfe8c2802002-11-03 00:38:21 +0000271
wdenk180d3f72004-01-04 16:28:35 +0000272/* ========================================================================= */
273
274#ifdef CONFIG_FADS /* SDRAM exists on FADS and newer boards */
wdenk2535d602003-07-17 23:16:40 +0000275
wdenkfe8c2802002-11-03 00:38:21 +0000276#if defined(CONFIG_SDRAM_100MHZ)
277
278/* ------------------------------------------------------------------------- */
279/* sdram table by Dan Malek */
280
281/* This has the stretched early timing so the 50 MHz
282 * processor can make the 100 MHz timing. This will
283 * work at all processor speeds.
284 */
285
wdenk2535d602003-07-17 23:16:40 +0000286#ifdef SDRAM_ALT_INIT_SEQENCE
287# define SDRAM_MBMRVALUE0 0xc3802114 /* PTx=195,PTxE,AMx=0,DSx=1,A11,RLFx=1,WLFx=1,TLFx=4 */
wdenkfe8c2802002-11-03 00:38:21 +0000288#define SDRAM_MBMRVALUE1 SDRAM_MBMRVALUE0
wdenk2535d602003-07-17 23:16:40 +0000289# define SDRAM_MCRVALUE0 0x80808111 /* run upmb cs4 loop 1 addr 0x11 MRS */
290# define SDRAM_MCRVALUE1 SDRAM_MCRVALUE0 /* ??? why not 0x80808130? */
291#else
292# define SDRAM_MxMR_PTx 195
293# define UPM_MRS_ADDR 0x11
294# define UPM_REFRESH_ADDR 0x30 /* or 0x11 if we want to be like above? */
295#endif /* !SDRAM_ALT_INIT_SEQUENCE */
wdenkfe8c2802002-11-03 00:38:21 +0000296
wdenk2535d602003-07-17 23:16:40 +0000297static const uint sdram_table[] =
wdenkfe8c2802002-11-03 00:38:21 +0000298{
299 /* single read. (offset 0 in upm RAM) */
300 0xefebfc24, 0x1f07fc24, 0xeeaefc04, 0x11adfc04,
wdenk2535d602003-07-17 23:16:40 +0000301 0xefbbbc00, 0x1ff77c45, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000302
303 /* burst read. (offset 8 in upm RAM) */
304 0xefebfc24, 0x1f07fc24, 0xeeaefc04, 0x10adfc04,
305 0xf0affc00, 0xf0affc00, 0xf1affc00, 0xefbbbc00,
wdenk2535d602003-07-17 23:16:40 +0000306 0x1ff77c45,
307
308 /* precharge + MRS. (offset 11 in upm RAM) */
309 0xeffbbc04, 0x1ff77c34, 0xefeabc34,
310 0x1fb57c35, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000311
312 /* single write. (offset 18 in upm RAM) */
313 0xefebfc24, 0x1f07fc24, 0xeeaebc00, 0x01b93c04,
wdenk2535d602003-07-17 23:16:40 +0000314 0x1ff77c45, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000315
316 /* burst write. (offset 20 in upm RAM) */
317 0xefebfc24, 0x1f07fc24, 0xeeaebc00, 0x10ad7c00,
318 0xf0affc00, 0xf0affc00, 0xe1bbbc04, 0x1ff77c45,
wdenk2535d602003-07-17 23:16:40 +0000319 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
320 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000321
322 /* refresh. (offset 30 in upm RAM) */
323 0xeffafc84, 0x1ff5fc04, 0xfffffc04, 0xfffffc04,
wdenk2535d602003-07-17 23:16:40 +0000324 0xfffffc84, 0xfffffc07, _NOT_USED_, _NOT_USED_,
325 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000326
327 /* exception. (offset 3c in upm RAM) */
wdenk2535d602003-07-17 23:16:40 +0000328 0xeffffc06, 0x1ffffc07, _NOT_USED_, _NOT_USED_ };
wdenkfe8c2802002-11-03 00:38:21 +0000329
330#elif defined(CONFIG_SDRAM_50MHZ)
331
332/* ------------------------------------------------------------------------- */
333/* sdram table stolen from the fads manual */
334/* for chip MB811171622A-100 */
335
336/* this table is for 32-50MHz operation */
wdenk2535d602003-07-17 23:16:40 +0000337#ifdef SDRAM_ALT_INIT_SEQENCE
338# define SDRAM_MBMRVALUE0 0x80802114 /* PTx=128,PTxE,AMx=0,DSx=1,A11,RLFx=1,WLFx=1,TLFx=4 */
339# define SDRAM_MBMRVALUE1 0x80802118 /* PTx=128,PTxE,AMx=0,DSx=1,A11,RLFx=1,WLFx=1,TLFx=8 */
340# define SDRAM_MCRVALUE0 0x80808105 /* run upmb cs4 loop 1 addr 0x5 MRS */
341# define SDRAM_MCRVALUE1 0x80808130 /* run upmb cs4 loop 1 addr 0x30 REFRESH */
342# define SDRAM_MPTRVALUE 0x400
wdenkfe8c2802002-11-03 00:38:21 +0000343#define SDRAM_MARVALUE 0x88
wdenk2535d602003-07-17 23:16:40 +0000344#else
345# define SDRAM_MxMR_PTx 128
346# define UPM_MRS_ADDR 0x5
347# define UPM_REFRESH_ADDR 0x30
348#endif /* !SDRAM_ALT_INIT_SEQUENCE */
wdenkfe8c2802002-11-03 00:38:21 +0000349
wdenk2535d602003-07-17 23:16:40 +0000350static const uint sdram_table[] =
wdenkfe8c2802002-11-03 00:38:21 +0000351{
352 /* single read. (offset 0 in upm RAM) */
353 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00,
354 0x1ff77c47,
355
wdenk2535d602003-07-17 23:16:40 +0000356 /* precharge + MRS. (offset 5 in upm RAM) */
wdenkfe8c2802002-11-03 00:38:21 +0000357 0x1ff77c34, 0xefeabc34, 0x1fb57c35,
358
359 /* burst read. (offset 8 in upm RAM) */
360 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00,
361 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47,
wdenk2535d602003-07-17 23:16:40 +0000362 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
363 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000364
365 /* single write. (offset 18 in upm RAM) */
366 0x1f27fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47,
wdenk2535d602003-07-17 23:16:40 +0000367 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000368
369 /* burst write. (offset 20 in upm RAM) */
370 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00,
wdenk2535d602003-07-17 23:16:40 +0000371 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, _NOT_USED_,
372 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
373 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000374
375 /* refresh. (offset 30 in upm RAM) */
376 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04,
wdenk2535d602003-07-17 23:16:40 +0000377 0xfffffc84, 0xfffffc07, _NOT_USED_, _NOT_USED_,
378 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenkfe8c2802002-11-03 00:38:21 +0000379
380 /* exception. (offset 3c in upm RAM) */
wdenk2535d602003-07-17 23:16:40 +0000381 0x7ffffc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
wdenkfe8c2802002-11-03 00:38:21 +0000382
383/* ------------------------------------------------------------------------- */
384#else
385#error SDRAM not correctly configured
386#endif
wdenk2535d602003-07-17 23:16:40 +0000387/* ------------------------------------------------------------------------- */
wdenkfe8c2802002-11-03 00:38:21 +0000388
wdenk2535d602003-07-17 23:16:40 +0000389/*
390 * Memory Periodic Timer Prescaler
391 */
392
393#define SDRAM_OR4VALUE 0x00000a00 /* SAM,GL5A/S=01,addr mask or'ed on later */
394#define SDRAM_BR4VALUE 0x000000c1 /* UPMB,base addr or'ed on later */
395
396/* ------------------------------------------------------------------------- */
397#ifdef SDRAM_ALT_INIT_SEQENCE
398/* ------------------------------------------------------------------------- */
399
400static int _initsdram(uint base, uint noMbytes)
wdenkfe8c2802002-11-03 00:38:21 +0000401{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200402 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
wdenkfe8c2802002-11-03 00:38:21 +0000403 volatile memctl8xx_t *memctl = &immap->im_memctl;
404
wdenkfe8c2802002-11-03 00:38:21 +0000405 upmconfig(UPMB, (uint *)sdram_table,sizeof(sdram_table)/sizeof(uint));
406
407 memctl->memc_mptpr = SDRAM_MPTPRVALUE;
408
409 /* Configure the refresh (mostly). This needs to be
410 * based upon processor clock speed and optimized to provide
411 * the highest level of performance. For multiple banks,
412 * this time has to be divided by the number of banks.
413 * Although it is not clear anywhere, it appears the
414 * refresh steps through the chip selects for this UPM
415 * on each refresh cycle.
416 * We have to be careful changing
417 * UPM registers after we ask it to run these commands.
418 */
419
wdenk2535d602003-07-17 23:16:40 +0000420 memctl->memc_mbmr = SDRAM_MBMRVALUE0; /* TLF 4 */
wdenkfe8c2802002-11-03 00:38:21 +0000421 memctl->memc_mar = SDRAM_MARVALUE; /* MRS code */
422
423 udelay(200);
424
425 /* Now run the precharge/nop/mrs commands.
426 */
427
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200428 memctl->memc_mcr = 0x80808111; /* run umpb cs4 1 count 1, addr 0x11 ??? (50MHz) */
Wolfgang Denk93e14592013-10-04 17:43:24 +0200429 /* run umpb cs4 1 count 1, addr 0x11 precharge+MRS (100MHz) */
wdenkfe8c2802002-11-03 00:38:21 +0000430 udelay(200);
431
432 /* Run 8 refresh cycles */
433
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200434 memctl->memc_mcr = SDRAM_MCRVALUE0; /* run upmb cs4 loop 1 addr 0x5 precharge+MRS (50 MHz)*/
wdenk2535d602003-07-17 23:16:40 +0000435 /* run upmb cs4 loop 1 addr 0x11 precharge+MRS (100MHz) */
wdenkfe8c2802002-11-03 00:38:21 +0000436
437 udelay(200);
438
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200439 memctl->memc_mbmr = SDRAM_MBMRVALUE1; /* TLF 4 (100 MHz) or TLF 8 (50MHz) */
440 memctl->memc_mcr = SDRAM_MCRVALUE1; /* run upmb cs4 loop 1 addr 0x30 refr (50 MHz) */
wdenk2535d602003-07-17 23:16:40 +0000441 /* run upmb cs4 loop 1 addr 0x11 precharge+MRS ??? (100MHz) */
wdenkfe8c2802002-11-03 00:38:21 +0000442
443 udelay(200);
444
wdenk2535d602003-07-17 23:16:40 +0000445 memctl->memc_mbmr = SDRAM_MBMRVALUE0; /* TLF 4 */
wdenkfe8c2802002-11-03 00:38:21 +0000446
wdenk2535d602003-07-17 23:16:40 +0000447 memctl->memc_or4 = SDRAM_OR4VALUE | ~((noMbytes<<20)-1);
wdenkfe8c2802002-11-03 00:38:21 +0000448 memctl->memc_br4 = SDRAM_BR4VALUE | base;
449
450 return 0;
451}
452
453/* ------------------------------------------------------------------------- */
wdenk2535d602003-07-17 23:16:40 +0000454#else /* !SDRAM_ALT_INIT_SEQUENCE */
455/* ------------------------------------------------------------------------- */
wdenkfe8c2802002-11-03 00:38:21 +0000456
wdenk2535d602003-07-17 23:16:40 +0000457/* refresh rate 15.6 us (= 64 ms / 4K = 62.4 / quad bursts) for <= 128 MBit */
458# define MPTPR_2BK_4K MPTPR_PTP_DIV16 /* setting for 2 banks */
459# define MPTPR_1BK_4K MPTPR_PTP_DIV32 /* setting for 1 bank */
460
461/* refresh rate 7.8 us (= 64 ms / 8K = 31.2 / quad bursts) for 256 MBit */
462# define MPTPR_2BK_8K MPTPR_PTP_DIV8 /* setting for 2 banks */
463# define MPTPR_1BK_8K MPTPR_PTP_DIV16 /* setting for 1 bank */
464
465/*
466 * MxMR settings for SDRAM
467 */
468
469/* 8 column SDRAM */
470# define SDRAM_MxMR_8COL ((SDRAM_MxMR_PTx << MBMR_PTB_SHIFT) | MBMR_PTBE | \
471 MBMR_AMB_TYPE_0 | MBMR_DSB_1_CYCL | MBMR_G0CLB_A11 | \
472 MBMR_RLFB_1X | MBMR_WLFB_1X | MBMR_TLFB_4X)
473/* 9 column SDRAM */
474# define SDRAM_MxMR_9COL ((SDRAM_MxMR_PTx << MBMR_PTB_SHIFT) | MBMR_PTAE | \
475 MBMR_AMB_TYPE_1 | MBMR_DSB_1_CYCL | MBMR_G0CLB_A10 | \
476 MBMR_RLFB_1X | MBMR_WLFB_1X | MBMR_TLFB_4X)
477
478static int _initsdram(uint base, uint noMbytes)
479{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200480 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
wdenk2535d602003-07-17 23:16:40 +0000481 volatile memctl8xx_t *memctl = &immap->im_memctl;
482
483 upmconfig(UPMB, (uint *)sdram_table,sizeof(sdram_table)/sizeof(uint));
484
485 memctl->memc_mptpr = MPTPR_2BK_4K;
486 memctl->memc_mbmr = SDRAM_MxMR_8COL & (~(MBMR_PTBE)); /* no refresh yet */
487
488 /* map CS 4 */
489 memctl->memc_or4 = SDRAM_OR4VALUE | ~((noMbytes<<20)-1);
490 memctl->memc_br4 = SDRAM_BR4VALUE | base;
491
492 /* Perform SDRAM initilization */
493# ifdef UPM_NOP_ADDR /* not currently in UPM table */
494 /* step 1: nop */
495 memctl->memc_mar = 0x00000000;
496 memctl->memc_mcr = MCR_UPM_B | MCR_OP_RUN | MCR_MB_CS4 |
497 MCR_MLCF(0) | UPM_NOP_ADDR;
498# endif
499
500 /* step 2: delay */
501 udelay(200);
502
503# ifdef UPM_PRECHARGE_ADDR /* merged with MRS in UPM table */
504 /* step 3: precharge */
505 memctl->memc_mar = 0x00000000;
506 memctl->memc_mcr = MCR_UPM_B | MCR_OP_RUN | MCR_MB_CS4 |
507 MCR_MLCF(4) | UPM_PRECHARGE_ADDR;
508# endif
509
510 /* step 4: refresh */
511 memctl->memc_mar = 0x00000000;
512 memctl->memc_mcr = MCR_UPM_B | MCR_OP_RUN | MCR_MB_CS4 |
513 MCR_MLCF(2) | UPM_REFRESH_ADDR;
514
515 /*
516 * note: for some reason, the UPM values we are using include
517 * precharge with MRS
518 */
519
520 /* step 5: mrs */
521 memctl->memc_mar = 0x00000088;
522 memctl->memc_mcr = MCR_UPM_B | MCR_OP_RUN | MCR_MB_CS4 |
523 MCR_MLCF(1) | UPM_MRS_ADDR;
524
525# ifdef UPM_NOP_ADDR
526 memctl->memc_mar = 0x00000000;
527 memctl->memc_mcr = MCR_UPM_B | MCR_OP_RUN | MCR_MB_CS4 |
528 MCR_MLCF(0) | UPM_NOP_ADDR;
529# endif
530 /*
531 * Enable refresh
532 */
533
534 memctl->memc_mbmr |= MBMR_PTBE;
535 return 0;
536}
537#endif /* !SDRAM_ALT_INIT_SEQUENCE */
538
539/* ------------------------------------------------------------------------- */
540
541static void _sdramdisable(void)
wdenkfe8c2802002-11-03 00:38:21 +0000542{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200543 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
wdenkfe8c2802002-11-03 00:38:21 +0000544 volatile memctl8xx_t *memctl = &immap->im_memctl;
545
546 memctl->memc_br4 = 0x00000000;
547
548 /* maybe we should turn off upmb here or something */
549}
550
551/* ------------------------------------------------------------------------- */
552
wdenk2535d602003-07-17 23:16:40 +0000553static int initsdram(uint base, uint *noMbytes)
wdenkfe8c2802002-11-03 00:38:21 +0000554{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200555 uint m = CONFIG_SYS_SDRAM_SIZE>>20;
wdenkfe8c2802002-11-03 00:38:21 +0000556
wdenk2535d602003-07-17 23:16:40 +0000557 /* _initsdram needs access to sdram */
wdenkfe8c2802002-11-03 00:38:21 +0000558 *((uint *)BCSR1) |= BCSR1_SDRAM_EN; /* enable sdram */
wdenkfe8c2802002-11-03 00:38:21 +0000559
560 if(!_initsdram(base, m))
561 {
Wolfgang Denk93e14592013-10-04 17:43:24 +0200562 *noMbytes += m;
wdenkfe8c2802002-11-03 00:38:21 +0000563 return 0;
564 }
565 else
566 {
567 *((uint *)BCSR1) &= ~BCSR1_SDRAM_EN; /* disable sdram */
568
569 _sdramdisable();
570
571 return -1;
572 }
573}
574
wdenk2535d602003-07-17 23:16:40 +0000575#endif /* CONFIG_FADS */
576
wdenk180d3f72004-01-04 16:28:35 +0000577/* ========================================================================= */
578
Becky Bruce9973e3c2008-06-09 16:03:40 -0500579phys_size_t initdram (int board_type)
wdenkfe8c2802002-11-03 00:38:21 +0000580{
wdenk2535d602003-07-17 23:16:40 +0000581 uint sdramsz = 0; /* size of sdram in Mbytes */
wdenk2535d602003-07-17 23:16:40 +0000582 uint m = 0; /* size of dram in Mbytes */
wdenk11142572004-06-06 21:35:06 +0000583#ifndef CONFIG_MPC885ADS
Wolfgang Denkbfdd1e12011-11-04 15:55:45 +0000584 uint base = 0; /* base of dram in bytes */
wdenk2535d602003-07-17 23:16:40 +0000585 uint k, s;
wdenk180d3f72004-01-04 16:28:35 +0000586#endif
wdenk2535d602003-07-17 23:16:40 +0000587
588#ifdef CONFIG_FADS
589 if (!initsdram (0x00000000, &sdramsz)) {
Wolfgang Denkbfdd1e12011-11-04 15:55:45 +0000590#ifndef CONFIG_MPC885ADS
wdenk2535d602003-07-17 23:16:40 +0000591 base = sdramsz << 20;
Wolfgang Denkbfdd1e12011-11-04 15:55:45 +0000592#endif
wdenk2535d602003-07-17 23:16:40 +0000593 printf ("(%u MB SDRAM) ", sdramsz);
594 }
wdenkfe8c2802002-11-03 00:38:21 +0000595#endif
wdenk11142572004-06-06 21:35:06 +0000596#ifndef CONFIG_MPC885ADS /* No old DRAM on MPC885ADS */
wdenk2535d602003-07-17 23:16:40 +0000597 k = (*((uint *) BCSR2) >> 23) & 0x0f;
wdenkfe8c2802002-11-03 00:38:21 +0000598
wdenk2535d602003-07-17 23:16:40 +0000599 switch (k & 0x3) {
wdenkfe8c2802002-11-03 00:38:21 +0000600 /* "MCM36100 / MT8D132X" */
wdenk2535d602003-07-17 23:16:40 +0000601 case 0x00:
602 m = 4;
603 break;
wdenkfe8c2802002-11-03 00:38:21 +0000604
605 /* "MCM36800 / MT16D832X" */
wdenk2535d602003-07-17 23:16:40 +0000606 case 0x01:
607 m = 32;
608 break;
wdenkfe8c2802002-11-03 00:38:21 +0000609 /* "MCM36400 / MT8D432X" */
wdenk2535d602003-07-17 23:16:40 +0000610 case 0x02:
611 m = 16;
612 break;
wdenkfe8c2802002-11-03 00:38:21 +0000613 /* "MCM36200 / MT16D832X ?" */
wdenk2535d602003-07-17 23:16:40 +0000614 case 0x03:
615 m = 8;
616 break;
wdenkfe8c2802002-11-03 00:38:21 +0000617
618 }
619
wdenk2535d602003-07-17 23:16:40 +0000620 switch (k >> 2) {
621 case 0x02:
622 k = 70;
623 break;
wdenkfe8c2802002-11-03 00:38:21 +0000624
wdenk2535d602003-07-17 23:16:40 +0000625 case 0x03:
626 k = 60;
627 break;
wdenkfe8c2802002-11-03 00:38:21 +0000628
wdenk2535d602003-07-17 23:16:40 +0000629 default:
630 printf ("unknown dramdelay (0x%x) - defaulting to 70 ns", k);
631 k = 70;
wdenkfe8c2802002-11-03 00:38:21 +0000632 }
633
634#ifdef CONFIG_FADS
635 /* the FADS is missing this bit, all rams treated as non-edo */
636 s = 0;
637#else
wdenk2535d602003-07-17 23:16:40 +0000638 s = (*((uint *) BCSR2) >> 27) & 0x01;
wdenkfe8c2802002-11-03 00:38:21 +0000639#endif
640
wdenk2535d602003-07-17 23:16:40 +0000641 if (!_draminit (base, m, s, k)) {
642 printf ("%dM %dns %sDRAM: ", m, k, s ? "EDO " : "");
643 } else {
644 _dramdisable ();
645 m = 0;
wdenkfe8c2802002-11-03 00:38:21 +0000646 }
wdenk11142572004-06-06 21:35:06 +0000647#endif /* !CONFIG_MPC885ADS */
wdenk2535d602003-07-17 23:16:40 +0000648 m += sdramsz; /* add sdram size to total */
649
wdenk2535d602003-07-17 23:16:40 +0000650 return (m << 20);
wdenkfe8c2802002-11-03 00:38:21 +0000651}
652
653/* ------------------------------------------------------------------------- */
654
655int testdram (void)
656{
657 /* TODO: XXX XXX XXX */
658 printf ("test: 16 MB - ok\n");
659
660 return (0);
661}
662
wdenk180d3f72004-01-04 16:28:35 +0000663/* ========================================================================= */
664
665/*
666 * Check Board Identity:
667 */
668
wdenk180d3f72004-01-04 16:28:35 +0000669int checkboard (void)
670{
Wolfgang Denk8ff02082006-03-12 01:55:43 +0100671#if defined(CONFIG_MPC86xADS)
672 puts ("Board: MPC86xADS\n");
673#elif defined(CONFIG_MPC885ADS)
674 puts ("Board: MPC885ADS\n");
675#else /* Only old ADS/FADS have got revision ID in BCSR3 */
wdenk180d3f72004-01-04 16:28:35 +0000676 uint r = (((*((uint *) BCSR3) >> 23) & 1) << 3)
677 | (((*((uint *) BCSR3) >> 19) & 1) << 2)
678 | (((*((uint *) BCSR3) >> 16) & 3));
679
680 puts ("Board: ");
Wolfgang Denk8ff02082006-03-12 01:55:43 +0100681#if defined(CONFIG_FADS)
wdenk180d3f72004-01-04 16:28:35 +0000682 puts ("FADS");
683 checkdboard ();
684#else
685 puts ("ADS");
686#endif
Wolfgang Denk8ff02082006-03-12 01:55:43 +0100687
wdenk180d3f72004-01-04 16:28:35 +0000688 puts (" rev ");
689
690 switch (r) {
wdenk180d3f72004-01-04 16:28:35 +0000691 case 0x00:
692 puts ("ENG\n");
693 break;
694 case 0x01:
695 puts ("PILOT\n");
696 break;
wdenk180d3f72004-01-04 16:28:35 +0000697 default:
698 printf ("unknown (0x%x)\n", r);
699 return -1;
700 }
Wolfgang Denk8ff02082006-03-12 01:55:43 +0100701#endif /* CONFIG_MPC86xADS */
wdenk180d3f72004-01-04 16:28:35 +0000702
703 return 0;
704}
705
706/* ========================================================================= */
wdenkfe8c2802002-11-03 00:38:21 +0000707
Jon Loeligerc508a4c2007-07-09 18:31:28 -0500708#if defined(CONFIG_CMD_PCMCIA)
wdenkfe8c2802002-11-03 00:38:21 +0000709
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200710#ifdef CONFIG_SYS_PCMCIA_MEM_ADDR
711volatile unsigned char *pcmcia_mem = (unsigned char*)CONFIG_SYS_PCMCIA_MEM_ADDR;
wdenkfe8c2802002-11-03 00:38:21 +0000712#endif
713
714int pcmcia_init(void)
715{
716 volatile pcmconf8xx_t *pcmp;
wdenk11142572004-06-06 21:35:06 +0000717 uint v, slota = 0, slotb = 0;
wdenkfe8c2802002-11-03 00:38:21 +0000718
719 /*
720 ** Enable the PCMCIA for a Flash card.
721 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200722 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
wdenkfe8c2802002-11-03 00:38:21 +0000723
724#if 0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200725 pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_MEM_ADDR;
wdenkfe8c2802002-11-03 00:38:21 +0000726 pcmp->pcmc_por0 = 0xc00ff05d;
727#endif
728
729 /* Set all slots to zero by default. */
730 pcmp->pcmc_pgcra = 0;
731 pcmp->pcmc_pgcrb = 0;
wdenk11142572004-06-06 21:35:06 +0000732#ifdef CONFIG_PCMCIA_SLOT_A
wdenkfe8c2802002-11-03 00:38:21 +0000733 pcmp->pcmc_pgcra = 0x40;
734#endif
wdenk11142572004-06-06 21:35:06 +0000735#ifdef CONFIG_PCMCIA_SLOT_B
wdenkfe8c2802002-11-03 00:38:21 +0000736 pcmp->pcmc_pgcrb = 0x40;
737#endif
738
739 /* enable PCMCIA buffers */
740 *((uint *)BCSR1) &= ~BCSR1_PCCEN;
741
742 /* Check if any PCMCIA card is plugged in. */
743
wdenk11142572004-06-06 21:35:06 +0000744#ifdef CONFIG_PCMCIA_SLOT_A
wdenkfe8c2802002-11-03 00:38:21 +0000745 slota = (pcmp->pcmc_pipr & 0x18000000) == 0 ;
wdenk11142572004-06-06 21:35:06 +0000746#endif
747#ifdef CONFIG_PCMCIA_SLOT_B
wdenkfe8c2802002-11-03 00:38:21 +0000748 slotb = (pcmp->pcmc_pipr & 0x00001800) == 0 ;
wdenk11142572004-06-06 21:35:06 +0000749#endif
wdenkfe8c2802002-11-03 00:38:21 +0000750
wdenk2535d602003-07-17 23:16:40 +0000751 if (!(slota || slotb)) {
wdenkfe8c2802002-11-03 00:38:21 +0000752 printf("No card present\n");
wdenkfe8c2802002-11-03 00:38:21 +0000753 pcmp->pcmc_pgcra = 0;
wdenkfe8c2802002-11-03 00:38:21 +0000754 pcmp->pcmc_pgcrb = 0;
wdenkfe8c2802002-11-03 00:38:21 +0000755 return -1;
756 }
757 else
758 printf("Card present (");
759
760 v = 0;
761
762 /* both the ADS and the FADS have a 5V keyed pcmcia connector (?)
763 **
764 ** Paolo - Yes, but i have to insert some 3.3V card in that slot on
765 ** my FADS... :-)
766 */
767
wdenk2535d602003-07-17 23:16:40 +0000768#if defined(CONFIG_MPC86x)
769 switch ((pcmp->pcmc_pipr >> 30) & 3)
wdenkfe8c2802002-11-03 00:38:21 +0000770#elif defined(CONFIG_MPC823) || defined(CONFIG_MPC850)
wdenk2535d602003-07-17 23:16:40 +0000771 switch ((pcmp->pcmc_pipr >> 14) & 3)
wdenkfe8c2802002-11-03 00:38:21 +0000772#endif
773 {
Wolfgang Denk8ff02082006-03-12 01:55:43 +0100774 case 0x03 :
wdenk2535d602003-07-17 23:16:40 +0000775 printf("5V");
776 v = 5;
777 break;
778 case 0x01 :
779 printf("5V and 3V");
wdenkfe8c2802002-11-03 00:38:21 +0000780#ifdef CONFIG_FADS
wdenk2535d602003-07-17 23:16:40 +0000781 v = 3; /* User lower voltage if supported! */
wdenkfe8c2802002-11-03 00:38:21 +0000782#else
wdenk2535d602003-07-17 23:16:40 +0000783 v = 5;
wdenkfe8c2802002-11-03 00:38:21 +0000784#endif
wdenk2535d602003-07-17 23:16:40 +0000785 break;
Wolfgang Denk8ff02082006-03-12 01:55:43 +0100786 case 0x00 :
wdenk2535d602003-07-17 23:16:40 +0000787 printf("5V, 3V and x.xV");
wdenkfe8c2802002-11-03 00:38:21 +0000788#ifdef CONFIG_FADS
wdenk2535d602003-07-17 23:16:40 +0000789 v = 3; /* User lower voltage if supported! */
wdenkfe8c2802002-11-03 00:38:21 +0000790#else
wdenk2535d602003-07-17 23:16:40 +0000791 v = 5;
wdenkfe8c2802002-11-03 00:38:21 +0000792#endif
wdenk2535d602003-07-17 23:16:40 +0000793 break;
wdenkfe8c2802002-11-03 00:38:21 +0000794 }
795
wdenk2535d602003-07-17 23:16:40 +0000796 switch (v) {
wdenkfe8c2802002-11-03 00:38:21 +0000797#ifdef CONFIG_FADS
798 case 3:
wdenk2535d602003-07-17 23:16:40 +0000799 printf("; using 3V");
800 /*
801 ** Enable 3 volt Vcc.
802 */
803 *((uint *)BCSR1) &= ~BCSR1_PCCVCC1;
804 *((uint *)BCSR1) |= BCSR1_PCCVCC0;
805 break;
wdenkfe8c2802002-11-03 00:38:21 +0000806#endif
807 case 5:
wdenk2535d602003-07-17 23:16:40 +0000808 printf("; using 5V");
wdenkfe8c2802002-11-03 00:38:21 +0000809#ifdef CONFIG_FADS
wdenk2535d602003-07-17 23:16:40 +0000810 /*
811 ** Enable 5 volt Vcc.
812 */
813 *((uint *)BCSR1) &= ~BCSR1_PCCVCC0;
814 *((uint *)BCSR1) |= BCSR1_PCCVCC1;
wdenkfe8c2802002-11-03 00:38:21 +0000815#endif
wdenk2535d602003-07-17 23:16:40 +0000816 break;
wdenkfe8c2802002-11-03 00:38:21 +0000817
818 default:
819 *((uint *)BCSR1) |= BCSR1_PCCEN; /* disable pcmcia */
820
821 printf("; unknown voltage");
822 return -1;
823 }
824 printf(")\n");
825 /* disable pcmcia reset after a while */
826
827 udelay(20);
828
wdenk11142572004-06-06 21:35:06 +0000829#ifdef CONFIG_PCMCIA_SLOT_A
wdenkfe8c2802002-11-03 00:38:21 +0000830 pcmp->pcmc_pgcra = 0;
wdenk11142572004-06-06 21:35:06 +0000831#endif
832#ifdef CONFIG_PCMCIA_SLOT_B
wdenkfe8c2802002-11-03 00:38:21 +0000833 pcmp->pcmc_pgcrb = 0;
834#endif
835
836 /* If you using a real hd you should give a short
837 * spin-up time. */
838#ifdef CONFIG_DISK_SPINUP_TIME
839 udelay(CONFIG_DISK_SPINUP_TIME);
840#endif
841
842 return 0;
843}
844
Jon Loeliger77a31852007-07-10 10:39:10 -0500845#endif
wdenkfe8c2802002-11-03 00:38:21 +0000846
wdenk180d3f72004-01-04 16:28:35 +0000847/* ========================================================================= */
wdenkfe8c2802002-11-03 00:38:21 +0000848
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200849#ifdef CONFIG_SYS_PC_IDE_RESET
wdenkfe8c2802002-11-03 00:38:21 +0000850
851void ide_set_reset(int on)
852{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200853 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkfe8c2802002-11-03 00:38:21 +0000854
855 /*
856 * Configure PC for IDE Reset Pin
857 */
858 if (on) { /* assert RESET */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200859 immr->im_ioport.iop_pcdat &= ~(CONFIG_SYS_PC_IDE_RESET);
wdenkfe8c2802002-11-03 00:38:21 +0000860 } else { /* release RESET */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200861 immr->im_ioport.iop_pcdat |= CONFIG_SYS_PC_IDE_RESET;
wdenkfe8c2802002-11-03 00:38:21 +0000862 }
863
864 /* program port pin as GPIO output */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200865 immr->im_ioport.iop_pcpar &= ~(CONFIG_SYS_PC_IDE_RESET);
866 immr->im_ioport.iop_pcso &= ~(CONFIG_SYS_PC_IDE_RESET);
867 immr->im_ioport.iop_pcdir |= CONFIG_SYS_PC_IDE_RESET;
wdenkfe8c2802002-11-03 00:38:21 +0000868}
869
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200870#endif /* CONFIG_SYS_PC_IDE_RESET */