blob: 89f94aa6aa890057ee8ddcb594ffd698151b6a04 [file] [log] [blame]
stroese771e05b2004-12-16 18:21:17 +00001/*
2 * (C) Copyright 2001
3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
stroese771e05b2004-12-16 18:21:17 +00006 */
7
8/*************************************************************************
9 * adaption for the Marvell DB64360 Board
10 * Ingo Assmus (ingo.assmus@keymile.com)
11 *
12 * adaption for the cpci750 Board
13 * Reinhard Arlt (reinhard.arlt@esd-electronics.com)
14 *************************************************************************/
15
16
17/* sdram_init.c - automatic memory sizing */
18
19#include <common.h>
20#include <74xx_7xx.h>
21#include "../../Marvell/include/memory.h"
22#include "../../Marvell/include/pci.h"
23#include "../../Marvell/include/mv_gen_reg.h"
24#include <net.h>
25
26#include "eth.h"
27#include "mpsc.h"
28#include "../../Marvell/common/i2c.h"
29#include "64360.h"
30#include "mv_regs.h"
31
Wolfgang Denkd87080b2006-03-31 18:32:53 +020032DECLARE_GLOBAL_DATA_PTR;
stroese771e05b2004-12-16 18:21:17 +000033
stroese771e05b2004-12-16 18:21:17 +000034int set_dfcdlInit(void); /* setup delay line of Mv64360 */
35
36/* ------------------------------------------------------------------------- */
37
38int
39memory_map_bank(unsigned int bankNo,
40 unsigned int bankBase,
41 unsigned int bankLength)
42{
43#ifdef MAP_PCI
44 PCI_HOST host;
45#endif
46
47
48#ifdef DEBUG
49 if (bankLength > 0) {
50 printf("mapping bank %d at %08x - %08x\n",
51 bankNo, bankBase, bankBase + bankLength - 1);
52 } else {
53 printf("unmapping bank %d\n", bankNo);
54 }
55#endif
56
57 memoryMapBank(bankNo, bankBase, bankLength);
58
59#ifdef MAP_PCI
60 for (host=PCI_HOST0;host<=PCI_HOST1;host++) {
61 const int features=
62 PREFETCH_ENABLE |
63 DELAYED_READ_ENABLE |
64 AGGRESSIVE_PREFETCH |
65 READ_LINE_AGGRESSIVE_PREFETCH |
66 READ_MULTI_AGGRESSIVE_PREFETCH |
67 MAX_BURST_4 |
68 PCI_NO_SWAP;
69
70 pciMapMemoryBank(host, bankNo, bankBase, bankLength);
71
72 pciSetRegionSnoopMode(host, bankNo, PCI_SNOOP_WB, bankBase,
73 bankLength);
74
75 pciSetRegionFeatures(host, bankNo, features, bankBase, bankLength);
76 }
77#endif
78 return 0;
79}
80
Wolfgang Denk53677ef2008-05-20 16:00:29 +020081#define GB (1 << 30)
stroese771e05b2004-12-16 18:21:17 +000082
83/* much of this code is based on (or is) the code in the pip405 port */
84/* thanks go to the authors of said port - Josh */
85
86/* structure to store the relevant information about an sdram bank */
87typedef struct sdram_info {
88 uchar drb_size;
89 uchar registered, ecc;
90 uchar tpar;
91 uchar tras_clocks;
92 uchar burst_len;
93 uchar banks, slot;
94} sdram_info_t;
95
96/* Typedefs for 'gtAuxilGetDIMMinfo' function */
97
98typedef enum _memoryType {SDRAM, DDR} MEMORY_TYPE;
99
100typedef enum _voltageInterface {TTL_5V_TOLERANT, LVTTL, HSTL_1_5V,
wdenkefe2a4d2004-12-16 21:44:03 +0000101 SSTL_3_3V, SSTL_2_5V, VOLTAGE_UNKNOWN,
102 } VOLTAGE_INTERFACE;
stroese771e05b2004-12-16 18:21:17 +0000103
104typedef enum _max_CL_supported_DDR {DDR_CL_1=1, DDR_CL_1_5=2, DDR_CL_2=4, DDR_CL_2_5=8, DDR_CL_3=16, DDR_CL_3_5=32, DDR_CL_FAULT} MAX_CL_SUPPORTED_DDR;
105typedef enum _max_CL_supported_SD {SD_CL_1=1, SD_CL_2, SD_CL_3, SD_CL_4, SD_CL_5, SD_CL_6, SD_CL_7, SD_FAULT} MAX_CL_SUPPORTED_SD;
106
107
108/* SDRAM/DDR information struct */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200109typedef struct _gtMemoryDimmInfo {
110 MEMORY_TYPE memoryType;
111 unsigned int numOfRowAddresses;
112 unsigned int numOfColAddresses;
113 unsigned int numOfModuleBanks;
114 unsigned int dataWidth;
115 VOLTAGE_INTERFACE voltageInterface;
116 unsigned int errorCheckType; /* ECC , PARITY.. */
117 unsigned int sdramWidth; /* 4,8,16 or 32 */ ;
118 unsigned int errorCheckDataWidth; /* 0 - no, 1 - Yes */
119 unsigned int minClkDelay;
120 unsigned int burstLengthSupported;
121 unsigned int numOfBanksOnEachDevice;
122 unsigned int suportedCasLatencies;
123 unsigned int RefreshInterval;
124 unsigned int maxCASlatencySupported_LoP; /* LoP left of point (measured in ns) */
125 unsigned int maxCASlatencySupported_RoP; /* RoP right of point (measured in ns) */
126 MAX_CL_SUPPORTED_DDR maxClSupported_DDR;
127 MAX_CL_SUPPORTED_SD maxClSupported_SD;
128 unsigned int moduleBankDensity;
129 /* module attributes (true for yes) */
130 bool bufferedAddrAndControlInputs;
131 bool registeredAddrAndControlInputs;
132 bool onCardPLL;
133 bool bufferedDQMBinputs;
134 bool registeredDQMBinputs;
135 bool differentialClockInput;
136 bool redundantRowAddressing;
stroese771e05b2004-12-16 18:21:17 +0000137
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200138 /* module general attributes */
139 bool suportedAutoPreCharge;
140 bool suportedPreChargeAll;
141 bool suportedEarlyRasPreCharge;
142 bool suportedWrite1ReadBurst;
143 bool suported5PercentLowVCC;
144 bool suported5PercentUpperVCC;
145 /* module timing parameters */
146 unsigned int minRasToCasDelay;
147 unsigned int minRowActiveRowActiveDelay;
148 unsigned int minRasPulseWidth;
149 unsigned int minRowPrechargeTime; /* measured in ns */
stroese771e05b2004-12-16 18:21:17 +0000150
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200151 int addrAndCommandHoldTime; /* LoP left of point (measured in ns) */
152 int addrAndCommandSetupTime; /* (measured in ns/100) */
153 int dataInputSetupTime; /* LoP left of point (measured in ns) */
154 int dataInputHoldTime; /* LoP left of point (measured in ns) */
stroese771e05b2004-12-16 18:21:17 +0000155/* tAC times for highest 2nd and 3rd highest CAS Latency values */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200156 unsigned int clockToDataOut_LoP; /* LoP left of point (measured in ns) */
157 unsigned int clockToDataOut_RoP; /* RoP right of point (measured in ns) */
158 unsigned int clockToDataOutMinus1_LoP; /* LoP left of point (measured in ns) */
159 unsigned int clockToDataOutMinus1_RoP; /* RoP right of point (measured in ns) */
160 unsigned int clockToDataOutMinus2_LoP; /* LoP left of point (measured in ns) */
161 unsigned int clockToDataOutMinus2_RoP; /* RoP right of point (measured in ns) */
stroese771e05b2004-12-16 18:21:17 +0000162
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200163 unsigned int minimumCycleTimeAtMaxCasLatancy_LoP; /* LoP left of point (measured in ns) */
164 unsigned int minimumCycleTimeAtMaxCasLatancy_RoP; /* RoP right of point (measured in ns) */
stroese771e05b2004-12-16 18:21:17 +0000165
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200166 unsigned int minimumCycleTimeAtMaxCasLatancyMinus1_LoP; /* LoP left of point (measured in ns) */
167 unsigned int minimumCycleTimeAtMaxCasLatancyMinus1_RoP; /* RoP right of point (measured in ns) */
stroese771e05b2004-12-16 18:21:17 +0000168
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200169 unsigned int minimumCycleTimeAtMaxCasLatancyMinus2_LoP; /* LoP left of point (measured in ns) */
170 unsigned int minimumCycleTimeAtMaxCasLatancyMinus2_RoP; /* RoP right of point (measured in ns) */
stroese771e05b2004-12-16 18:21:17 +0000171
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200172 /* Parameters calculated from
173 the extracted DIMM information */
174 unsigned int size;
175 unsigned int deviceDensity; /* 16,64,128,256 or 512 Mbit */
176 unsigned int numberOfDevices;
177 uchar drb_size; /* DRAM size in n*64Mbit */
178 uchar slot; /* Slot Number this module is inserted in */
179 uchar spd_raw_data[128]; /* Content of SPD-EEPROM copied 1:1 */
stroese771e05b2004-12-16 18:21:17 +0000180#ifdef DEBUG
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200181 uchar manufactura[8]; /* Content of SPD-EEPROM Byte 64-71 */
182 uchar modul_id[18]; /* Content of SPD-EEPROM Byte 73-90 */
183 uchar vendor_data[27]; /* Content of SPD-EEPROM Byte 99-125 */
184 unsigned long modul_serial_no; /* Content of SPD-EEPROM Byte 95-98 */
185 unsigned int manufac_date; /* Content of SPD-EEPROM Byte 93-94 */
186 unsigned int modul_revision; /* Content of SPD-EEPROM Byte 91-92 */
187 uchar manufac_place; /* Content of SPD-EEPROM Byte 72 */
stroese771e05b2004-12-16 18:21:17 +0000188
189#endif
190} AUX_MEM_DIMM_INFO;
191
192
193/*
194 * translate ns.ns/10 coding of SPD timing values
195 * into 10 ps unit values
196 */
197static inline unsigned short
198NS10to10PS(unsigned char spd_byte)
199{
200 unsigned short ns, ns10;
201
202 /* isolate upper nibble */
203 ns = (spd_byte >> 4) & 0x0F;
204 /* isolate lower nibble */
205 ns10 = (spd_byte & 0x0F);
206
207 return(ns*100 + ns10*10);
208}
209
210/*
211 * translate ns coding of SPD timing values
212 * into 10 ps unit values
213 */
214static inline unsigned short
215NSto10PS(unsigned char spd_byte)
216{
217 return(spd_byte*100);
218}
219
220/* This code reads the SPD chip on the sdram and populates
221 * the array which is passed in with the relevant information */
222/* static int check_dimm(uchar slot, AUX_MEM_DIMM_INFO *info) */
wdenkefe2a4d2004-12-16 21:44:03 +0000223static int check_dimm (uchar slot, AUX_MEM_DIMM_INFO * dimmInfo)
stroese771e05b2004-12-16 18:21:17 +0000224{
stroese771e05b2004-12-16 18:21:17 +0000225 uchar addr = slot == 0 ? DIMM0_I2C_ADDR : DIMM1_I2C_ADDR;
226 int ret;
wdenkefe2a4d2004-12-16 21:44:03 +0000227 unsigned int i, j, density = 1, devicesForErrCheck = 0;
228
stroese771e05b2004-12-16 18:21:17 +0000229#ifdef DEBUG
wdenkefe2a4d2004-12-16 21:44:03 +0000230 unsigned int k;
stroese771e05b2004-12-16 18:21:17 +0000231#endif
wdenkefe2a4d2004-12-16 21:44:03 +0000232 unsigned int rightOfPoint = 0, leftOfPoint = 0, mult, div, time_tmp;
233 int sign = 1, shift, maskLeftOfPoint, maskRightOfPoint;
stroese771e05b2004-12-16 18:21:17 +0000234 uchar supp_cal, cal_val;
235 ulong memclk, tmemclk;
236 ulong tmp;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000237 uchar trp_clocks = 0, tras_clocks;
stroese771e05b2004-12-16 18:21:17 +0000238 uchar data[128];
239
240 memclk = gd->bus_clk;
wdenkefe2a4d2004-12-16 21:44:03 +0000241 tmemclk = 1000000000 / (memclk / 100); /* in 10 ps units */
stroese771e05b2004-12-16 18:21:17 +0000242
wdenkefe2a4d2004-12-16 21:44:03 +0000243 memset (data, 0, sizeof (data));
stroese771e05b2004-12-16 18:21:17 +0000244
245
246 ret = 0;
247
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000248 debug("before i2c read\n");
stroese771e05b2004-12-16 18:21:17 +0000249
wdenkefe2a4d2004-12-16 21:44:03 +0000250 ret = i2c_read (addr, 0, 2, data, 128);
stroese771e05b2004-12-16 18:21:17 +0000251
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000252 debug("after i2c read\n");
stroese771e05b2004-12-16 18:21:17 +0000253
wdenkefe2a4d2004-12-16 21:44:03 +0000254 if ((data[64] != 'e') || (data[65] != 's') || (data[66] != 'd')
255 || (data[67] != '-') || (data[68] != 'g') || (data[69] != 'm')
256 || (data[70] != 'b') || (data[71] != 'h')) {
257 ret = -1;
258 }
stroese771e05b2004-12-16 18:21:17 +0000259
wdenkefe2a4d2004-12-16 21:44:03 +0000260 if ((ret != 0) && (slot == 0)) {
261 memset (data, 0, sizeof (data));
262 data[0] = 0x80;
263 data[1] = 0x08;
264 data[2] = 0x07;
265 data[3] = 0x0c;
266 data[4] = 0x09;
267 data[5] = 0x01;
268 data[6] = 0x48;
269 data[7] = 0x00;
270 data[8] = 0x04;
271 data[9] = 0x75;
272 data[10] = 0x80;
273 data[11] = 0x02;
274 data[12] = 0x80;
275 data[13] = 0x10;
276 data[14] = 0x08;
277 data[15] = 0x01;
278 data[16] = 0x0e;
279 data[17] = 0x04;
280 data[18] = 0x0c;
281 data[19] = 0x01;
282 data[20] = 0x02;
283 data[21] = 0x20;
284 data[22] = 0x00;
285 data[23] = 0xa0;
286 data[24] = 0x80;
287 data[25] = 0x00;
288 data[26] = 0x00;
289 data[27] = 0x50;
290 data[28] = 0x3c;
291 data[29] = 0x50;
292 data[30] = 0x32;
293 data[31] = 0x10;
294 data[32] = 0xb0;
295 data[33] = 0xb0;
296 data[34] = 0x60;
297 data[35] = 0x60;
298 data[64] = 'e';
299 data[65] = 's';
300 data[66] = 'd';
301 data[67] = '-';
302 data[68] = 'g';
303 data[69] = 'm';
304 data[70] = 'b';
305 data[71] = 'h';
306 ret = 0;
307 }
stroese771e05b2004-12-16 18:21:17 +0000308
309 /* zero all the values */
wdenkefe2a4d2004-12-16 21:44:03 +0000310 memset (dimmInfo, 0, sizeof (*dimmInfo));
stroese771e05b2004-12-16 18:21:17 +0000311
wdenkefe2a4d2004-12-16 21:44:03 +0000312 /* copy the SPD content 1:1 into the dimmInfo structure */
313 for (i = 0; i <= 127; i++) {
314 dimmInfo->spd_raw_data[i] = data[i];
315 }
stroese771e05b2004-12-16 18:21:17 +0000316
317 if (ret) {
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000318 debug("No DIMM in slot %d [err = %x]\n", slot, ret);
stroese771e05b2004-12-16 18:21:17 +0000319 return 0;
wdenkefe2a4d2004-12-16 21:44:03 +0000320 } else
321 dimmInfo->slot = slot; /* start to fill up dimminfo for this "slot" */
stroese771e05b2004-12-16 18:21:17 +0000322
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200323#ifdef CONFIG_SYS_DISPLAY_DIMM_SPD_CONTENT
stroese771e05b2004-12-16 18:21:17 +0000324
wdenkefe2a4d2004-12-16 21:44:03 +0000325 for (i = 0; i <= 127; i++) {
326 printf ("SPD-EEPROM Byte %3d = %3x (%3d)\n", i, data[i],
327 data[i]);
328 }
stroese771e05b2004-12-16 18:21:17 +0000329
330#endif
331#ifdef DEBUG
wdenkefe2a4d2004-12-16 21:44:03 +0000332 /* find Manufacturer of Dimm Module */
333 for (i = 0; i < sizeof (dimmInfo->manufactura); i++) {
334 dimmInfo->manufactura[i] = data[64 + i];
335 }
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200336 printf ("\nThis RAM-Module is produced by: %s\n",
wdenkefe2a4d2004-12-16 21:44:03 +0000337 dimmInfo->manufactura);
stroese771e05b2004-12-16 18:21:17 +0000338
wdenkefe2a4d2004-12-16 21:44:03 +0000339 /* find Manul-ID of Dimm Module */
340 for (i = 0; i < sizeof (dimmInfo->modul_id); i++) {
341 dimmInfo->modul_id[i] = data[73 + i];
342 }
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200343 printf ("The Module-ID of this RAM-Module is: %s\n",
wdenkefe2a4d2004-12-16 21:44:03 +0000344 dimmInfo->modul_id);
stroese771e05b2004-12-16 18:21:17 +0000345
wdenkefe2a4d2004-12-16 21:44:03 +0000346 /* find Vendor-Data of Dimm Module */
347 for (i = 0; i < sizeof (dimmInfo->vendor_data); i++) {
348 dimmInfo->vendor_data[i] = data[99 + i];
349 }
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200350 printf ("Vendor Data of this RAM-Module is: %s\n",
wdenkefe2a4d2004-12-16 21:44:03 +0000351 dimmInfo->vendor_data);
stroese771e05b2004-12-16 18:21:17 +0000352
wdenkefe2a4d2004-12-16 21:44:03 +0000353 /* find modul_serial_no of Dimm Module */
354 dimmInfo->modul_serial_no = (*((unsigned long *) (&data[95])));
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200355 printf ("Serial No. of this RAM-Module is: %ld (%lx)\n",
wdenkefe2a4d2004-12-16 21:44:03 +0000356 dimmInfo->modul_serial_no, dimmInfo->modul_serial_no);
stroese771e05b2004-12-16 18:21:17 +0000357
wdenkefe2a4d2004-12-16 21:44:03 +0000358 /* find Manufac-Data of Dimm Module */
359 dimmInfo->manufac_date = (*((unsigned int *) (&data[93])));
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200360 printf ("Manufactoring Date of this RAM-Module is: %d.%d\n", data[93], data[94]); /*dimmInfo->manufac_date */
stroese771e05b2004-12-16 18:21:17 +0000361
wdenkefe2a4d2004-12-16 21:44:03 +0000362 /* find modul_revision of Dimm Module */
363 dimmInfo->modul_revision = (*((unsigned int *) (&data[91])));
364 printf ("Module Revision of this RAM-Module is: %d.%d\n", data[91], data[92]); /* dimmInfo->modul_revision */
stroese771e05b2004-12-16 18:21:17 +0000365
wdenkefe2a4d2004-12-16 21:44:03 +0000366 /* find manufac_place of Dimm Module */
367 dimmInfo->manufac_place = (*((unsigned char *) (&data[72])));
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200368 printf ("manufac_place of this RAM-Module is: %d\n",
wdenkefe2a4d2004-12-16 21:44:03 +0000369 dimmInfo->manufac_place);
stroese771e05b2004-12-16 18:21:17 +0000370
371#endif
372/*------------------------------------------------------------------------------------------------------------------------------*/
373/* calculate SPD checksum */
374/*------------------------------------------------------------------------------------------------------------------------------*/
wdenkefe2a4d2004-12-16 21:44:03 +0000375#if 0 /* test-only */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000376 spd_checksum = 0;
377
wdenkefe2a4d2004-12-16 21:44:03 +0000378 for (i = 0; i <= 62; i++) {
379 spd_checksum += data[i];
380 }
stroese771e05b2004-12-16 18:21:17 +0000381
wdenkefe2a4d2004-12-16 21:44:03 +0000382 if ((spd_checksum & 0xff) != data[63]) {
383 printf ("### Error in SPD Checksum !!! Is_value: %2x should value %2x\n", (unsigned int) (spd_checksum & 0xff), data[63]);
384 hang ();
385 }
stroese771e05b2004-12-16 18:21:17 +0000386
wdenkefe2a4d2004-12-16 21:44:03 +0000387 else
388 printf ("SPD Checksum ok!\n");
stroese771e05b2004-12-16 18:21:17 +0000389#endif /* test-only */
390
391/*------------------------------------------------------------------------------------------------------------------------------*/
wdenkefe2a4d2004-12-16 21:44:03 +0000392 for (i = 2; i <= 35; i++) {
393 switch (i) {
394 case 2: /* Memory type (DDR / SDRAM) */
395 dimmInfo->memoryType = (data[i] == 0x7) ? DDR : SDRAM;
396#ifdef DEBUG
397 if (dimmInfo->memoryType == 0)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000398 debug("Dram_type in slot %d is: SDRAM\n",
399 dimmInfo->slot);
wdenkefe2a4d2004-12-16 21:44:03 +0000400 if (dimmInfo->memoryType == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000401 debug("Dram_type in slot %d is: DDRAM\n",
402 dimmInfo->slot);
wdenkefe2a4d2004-12-16 21:44:03 +0000403#endif
404 break;
stroese771e05b2004-12-16 18:21:17 +0000405/*------------------------------------------------------------------------------------------------------------------------------*/
406
wdenkefe2a4d2004-12-16 21:44:03 +0000407 case 3: /* Number Of Row Addresses */
408 dimmInfo->numOfRowAddresses = data[i];
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000409 debug("Module Number of row addresses: %d\n",
410 dimmInfo->numOfRowAddresses);
wdenkefe2a4d2004-12-16 21:44:03 +0000411 break;
stroese771e05b2004-12-16 18:21:17 +0000412/*------------------------------------------------------------------------------------------------------------------------------*/
413
wdenkefe2a4d2004-12-16 21:44:03 +0000414 case 4: /* Number Of Column Addresses */
415 dimmInfo->numOfColAddresses = data[i];
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000416 debug("Module Number of col addresses: %d\n",
417 dimmInfo->numOfColAddresses);
wdenkefe2a4d2004-12-16 21:44:03 +0000418 break;
stroese771e05b2004-12-16 18:21:17 +0000419/*------------------------------------------------------------------------------------------------------------------------------*/
420
wdenkefe2a4d2004-12-16 21:44:03 +0000421 case 5: /* Number Of Module Banks */
422 dimmInfo->numOfModuleBanks = data[i];
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000423 debug("Number of Banks on Mod. : %d\n",
424 dimmInfo->numOfModuleBanks);
wdenkefe2a4d2004-12-16 21:44:03 +0000425 break;
stroese771e05b2004-12-16 18:21:17 +0000426/*------------------------------------------------------------------------------------------------------------------------------*/
427
wdenkefe2a4d2004-12-16 21:44:03 +0000428 case 6: /* Data Width */
429 dimmInfo->dataWidth = data[i];
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000430 debug("Module Data Width: %d\n",
431 dimmInfo->dataWidth);
wdenkefe2a4d2004-12-16 21:44:03 +0000432 break;
stroese771e05b2004-12-16 18:21:17 +0000433/*------------------------------------------------------------------------------------------------------------------------------*/
434
wdenkefe2a4d2004-12-16 21:44:03 +0000435 case 8: /* Voltage Interface */
436 switch (data[i]) {
437 case 0x0:
438 dimmInfo->voltageInterface = TTL_5V_TOLERANT;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000439 debug("Module is TTL_5V_TOLERANT\n");
wdenkefe2a4d2004-12-16 21:44:03 +0000440 break;
441 case 0x1:
442 dimmInfo->voltageInterface = LVTTL;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000443 debug("Module is LVTTL\n");
wdenkefe2a4d2004-12-16 21:44:03 +0000444 break;
445 case 0x2:
446 dimmInfo->voltageInterface = HSTL_1_5V;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000447 debug("Module is TTL_5V_TOLERANT\n");
wdenkefe2a4d2004-12-16 21:44:03 +0000448 break;
449 case 0x3:
450 dimmInfo->voltageInterface = SSTL_3_3V;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000451 debug("Module is HSTL_1_5V\n");
wdenkefe2a4d2004-12-16 21:44:03 +0000452 break;
453 case 0x4:
454 dimmInfo->voltageInterface = SSTL_2_5V;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000455 debug("Module is SSTL_2_5V\n");
wdenkefe2a4d2004-12-16 21:44:03 +0000456 break;
457 default:
458 dimmInfo->voltageInterface = VOLTAGE_UNKNOWN;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000459 debug("Module is VOLTAGE_UNKNOWN\n");
wdenkefe2a4d2004-12-16 21:44:03 +0000460 break;
461 }
462 break;
stroese771e05b2004-12-16 18:21:17 +0000463/*------------------------------------------------------------------------------------------------------------------------------*/
464
wdenkefe2a4d2004-12-16 21:44:03 +0000465 case 9: /* Minimum Cycle Time At Max CasLatancy */
466 shift = (dimmInfo->memoryType == DDR) ? 4 : 2;
467 mult = (dimmInfo->memoryType == DDR) ? 10 : 25;
468 maskLeftOfPoint =
469 (dimmInfo->memoryType == DDR) ? 0xf0 : 0xfc;
470 maskRightOfPoint =
471 (dimmInfo->memoryType == DDR) ? 0xf : 0x03;
472 leftOfPoint = (data[i] & maskLeftOfPoint) >> shift;
473 rightOfPoint = (data[i] & maskRightOfPoint) * mult;
474 dimmInfo->minimumCycleTimeAtMaxCasLatancy_LoP =
475 leftOfPoint;
476 dimmInfo->minimumCycleTimeAtMaxCasLatancy_RoP =
477 rightOfPoint;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000478 debug("Minimum Cycle Time At Max CasLatancy: %d.%d [ns]\n",
479 leftOfPoint, rightOfPoint);
wdenkefe2a4d2004-12-16 21:44:03 +0000480 break;
stroese771e05b2004-12-16 18:21:17 +0000481/*------------------------------------------------------------------------------------------------------------------------------*/
482
wdenkefe2a4d2004-12-16 21:44:03 +0000483 case 10: /* Clock To Data Out */
484 div = (dimmInfo->memoryType == DDR) ? 100 : 10;
485 time_tmp =
486 (((data[i] & 0xf0) >> 4) * 10) +
487 ((data[i] & 0x0f));
488 leftOfPoint = time_tmp / div;
489 rightOfPoint = time_tmp % div;
490 dimmInfo->clockToDataOut_LoP = leftOfPoint;
491 dimmInfo->clockToDataOut_RoP = rightOfPoint;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000492 debug("Clock To Data Out: %d.%2d [ns]\n",
493 leftOfPoint, rightOfPoint);
wdenkefe2a4d2004-12-16 21:44:03 +0000494 /*dimmInfo->clockToDataOut */
495 break;
stroese771e05b2004-12-16 18:21:17 +0000496/*------------------------------------------------------------------------------------------------------------------------------*/
497
Reinhard Arlt0738e242010-04-13 09:59:09 +0200498#ifdef CONFIG_MV64360_ECC
wdenkefe2a4d2004-12-16 21:44:03 +0000499 case 11: /* Error Check Type */
500 dimmInfo->errorCheckType = data[i];
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000501 debug("Error Check Type (0=NONE): %d\n",
502 dimmInfo->errorCheckType);
wdenkefe2a4d2004-12-16 21:44:03 +0000503 break;
Reinhard Arlt0738e242010-04-13 09:59:09 +0200504#endif /* of ifdef CONFIG_MV64360_ECC */
stroese771e05b2004-12-16 18:21:17 +0000505/*------------------------------------------------------------------------------------------------------------------------------*/
506
wdenkefe2a4d2004-12-16 21:44:03 +0000507 case 12: /* Refresh Interval */
508 dimmInfo->RefreshInterval = data[i];
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000509 debug("RefreshInterval (80= Self refresh Normal, 15.625us) : %x\n",
510 dimmInfo->RefreshInterval);
wdenkefe2a4d2004-12-16 21:44:03 +0000511 break;
stroese771e05b2004-12-16 18:21:17 +0000512/*------------------------------------------------------------------------------------------------------------------------------*/
513
wdenkefe2a4d2004-12-16 21:44:03 +0000514 case 13: /* Sdram Width */
515 dimmInfo->sdramWidth = data[i];
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000516 debug("Sdram Width: %d\n",
517 dimmInfo->sdramWidth);
wdenkefe2a4d2004-12-16 21:44:03 +0000518 break;
stroese771e05b2004-12-16 18:21:17 +0000519/*------------------------------------------------------------------------------------------------------------------------------*/
520
wdenkefe2a4d2004-12-16 21:44:03 +0000521 case 14: /* Error Check Data Width */
522 dimmInfo->errorCheckDataWidth = data[i];
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000523 debug("Error Check Data Width: %d\n",
524 dimmInfo->errorCheckDataWidth);
wdenkefe2a4d2004-12-16 21:44:03 +0000525 break;
stroese771e05b2004-12-16 18:21:17 +0000526/*------------------------------------------------------------------------------------------------------------------------------*/
527
wdenkefe2a4d2004-12-16 21:44:03 +0000528 case 15: /* Minimum Clock Delay */
529 dimmInfo->minClkDelay = data[i];
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000530 debug("Minimum Clock Delay: %d\n",
531 dimmInfo->minClkDelay);
wdenkefe2a4d2004-12-16 21:44:03 +0000532 break;
stroese771e05b2004-12-16 18:21:17 +0000533/*------------------------------------------------------------------------------------------------------------------------------*/
534
wdenkefe2a4d2004-12-16 21:44:03 +0000535 case 16: /* Burst Length Supported */
536 /******-******-******-*******
537 * bit3 | bit2 | bit1 | bit0 *
538 *******-******-******-*******
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200539 burst length = * 8 | 4 | 2 | 1 *
wdenkefe2a4d2004-12-16 21:44:03 +0000540 *****************************
stroese771e05b2004-12-16 18:21:17 +0000541
wdenkefe2a4d2004-12-16 21:44:03 +0000542 If for example bit0 and bit2 are set, the burst
543 length supported are 1 and 4. */
stroese771e05b2004-12-16 18:21:17 +0000544
wdenkefe2a4d2004-12-16 21:44:03 +0000545 dimmInfo->burstLengthSupported = data[i];
stroese771e05b2004-12-16 18:21:17 +0000546#ifdef DEBUG
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000547 debug("Burst Length Supported: ");
wdenkefe2a4d2004-12-16 21:44:03 +0000548 if (dimmInfo->burstLengthSupported & 0x01)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000549 debug("1, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000550 if (dimmInfo->burstLengthSupported & 0x02)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000551 debug("2, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000552 if (dimmInfo->burstLengthSupported & 0x04)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000553 debug("4, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000554 if (dimmInfo->burstLengthSupported & 0x08)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000555 debug("8, ");
556 debug(" Bit \n");
stroese771e05b2004-12-16 18:21:17 +0000557#endif
wdenkefe2a4d2004-12-16 21:44:03 +0000558 break;
stroese771e05b2004-12-16 18:21:17 +0000559/*------------------------------------------------------------------------------------------------------------------------------*/
560
wdenkefe2a4d2004-12-16 21:44:03 +0000561 case 17: /* Number Of Banks On Each Device */
562 dimmInfo->numOfBanksOnEachDevice = data[i];
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000563 debug("Number Of Banks On Each Chip: %d\n",
564 dimmInfo->numOfBanksOnEachDevice);
wdenkefe2a4d2004-12-16 21:44:03 +0000565 break;
stroese771e05b2004-12-16 18:21:17 +0000566/*------------------------------------------------------------------------------------------------------------------------------*/
567
wdenkefe2a4d2004-12-16 21:44:03 +0000568 case 18: /* Suported Cas Latencies */
stroese771e05b2004-12-16 18:21:17 +0000569
wdenkefe2a4d2004-12-16 21:44:03 +0000570 /* DDR:
571 *******-******-******-******-******-******-******-*******
572 * bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 *
573 *******-******-******-******-******-******-******-*******
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200574 CAS = * TBD | TBD | 3.5 | 3 | 2.5 | 2 | 1.5 | 1 *
wdenkefe2a4d2004-12-16 21:44:03 +0000575 *********************************************************
576 SDRAM:
577 *******-******-******-******-******-******-******-*******
578 * bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 *
579 *******-******-******-******-******-******-******-*******
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200580 CAS = * TBD | 7 | 6 | 5 | 4 | 3 | 2 | 1 *
wdenkefe2a4d2004-12-16 21:44:03 +0000581 ********************************************************/
582 dimmInfo->suportedCasLatencies = data[i];
stroese771e05b2004-12-16 18:21:17 +0000583#ifdef DEBUG
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000584 debug("Suported Cas Latencies: (CL) ");
wdenkefe2a4d2004-12-16 21:44:03 +0000585 if (dimmInfo->memoryType == 0) { /* SDRAM */
586 for (k = 0; k <= 7; k++) {
587 if (dimmInfo->
588 suportedCasLatencies & (1 << k))
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000589 debug("%d, ",
590 k + 1);
wdenkefe2a4d2004-12-16 21:44:03 +0000591 }
stroese771e05b2004-12-16 18:21:17 +0000592
wdenkefe2a4d2004-12-16 21:44:03 +0000593 } else { /* DDR-RAM */
stroese771e05b2004-12-16 18:21:17 +0000594
wdenkefe2a4d2004-12-16 21:44:03 +0000595 if (dimmInfo->suportedCasLatencies & 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000596 debug("1, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000597 if (dimmInfo->suportedCasLatencies & 2)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000598 debug("1.5, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000599 if (dimmInfo->suportedCasLatencies & 4)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000600 debug("2, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000601 if (dimmInfo->suportedCasLatencies & 8)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000602 debug("2.5, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000603 if (dimmInfo->suportedCasLatencies & 16)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000604 debug("3, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000605 if (dimmInfo->suportedCasLatencies & 32)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000606 debug("3.5, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000607
608 }
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000609 debug("\n");
stroese771e05b2004-12-16 18:21:17 +0000610#endif
wdenkefe2a4d2004-12-16 21:44:03 +0000611 /* Calculating MAX CAS latency */
612 for (j = 7; j > 0; j--) {
613 if (((dimmInfo->
614 suportedCasLatencies >> j) & 0x1) ==
615 1) {
616 switch (dimmInfo->memoryType) {
617 case DDR:
618 /* CAS latency 1, 1.5, 2, 2.5, 3, 3.5 */
619 switch (j) {
620 case 7:
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000621 debug("Max. Cas Latencies (DDR): ERROR !!!\n");
wdenkefe2a4d2004-12-16 21:44:03 +0000622 dimmInfo->
623 maxClSupported_DDR
624 =
625 DDR_CL_FAULT;
626 hang ();
627 break;
628 case 6:
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000629 debug("Max. Cas Latencies (DDR): ERROR !!!\n");
wdenkefe2a4d2004-12-16 21:44:03 +0000630 dimmInfo->
631 maxClSupported_DDR
632 =
633 DDR_CL_FAULT;
634 hang ();
635 break;
636 case 5:
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000637 debug("Max. Cas Latencies (DDR): 3.5 clk's\n");
wdenkefe2a4d2004-12-16 21:44:03 +0000638 dimmInfo->
639 maxClSupported_DDR
640 = DDR_CL_3_5;
641 break;
642 case 4:
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000643 debug("Max. Cas Latencies (DDR): 3 clk's \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000644 dimmInfo->
645 maxClSupported_DDR
646 = DDR_CL_3;
647 break;
648 case 3:
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000649 debug("Max. Cas Latencies (DDR): 2.5 clk's \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000650 dimmInfo->
651 maxClSupported_DDR
652 = DDR_CL_2_5;
653 break;
654 case 2:
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000655 debug("Max. Cas Latencies (DDR): 2 clk's \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000656 dimmInfo->
657 maxClSupported_DDR
658 = DDR_CL_2;
659 break;
660 case 1:
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000661 debug("Max. Cas Latencies (DDR): 1.5 clk's \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000662 dimmInfo->
663 maxClSupported_DDR
664 = DDR_CL_1_5;
665 break;
666 }
667 dimmInfo->
668 maxCASlatencySupported_LoP
669 =
670 1 +
671 (int) (5 * j / 10);
672 if (((5 * j) % 10) != 0)
673 dimmInfo->
674 maxCASlatencySupported_RoP
675 = 5;
676 else
677 dimmInfo->
678 maxCASlatencySupported_RoP
679 = 0;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000680 debug("Max. Cas Latencies (DDR LoP.RoP Notation): %d.%d \n",
wdenkefe2a4d2004-12-16 21:44:03 +0000681 dimmInfo->
682 maxCASlatencySupported_LoP,
683 dimmInfo->
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000684 maxCASlatencySupported_RoP);
wdenkefe2a4d2004-12-16 21:44:03 +0000685 break;
686 case SDRAM:
687 /* CAS latency 1, 2, 3, 4, 5, 6, 7 */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200688 dimmInfo->maxClSupported_SD = j; /* Cas Latency DDR-RAM Coded */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000689 debug("Max. Cas Latencies (SD): %d\n",
wdenkefe2a4d2004-12-16 21:44:03 +0000690 dimmInfo->
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000691 maxClSupported_SD);
wdenkefe2a4d2004-12-16 21:44:03 +0000692 dimmInfo->
693 maxCASlatencySupported_LoP
694 = j;
695 dimmInfo->
696 maxCASlatencySupported_RoP
697 = 0;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000698 debug("Max. Cas Latencies (DDR LoP.RoP Notation): %d.%d \n",
wdenkefe2a4d2004-12-16 21:44:03 +0000699 dimmInfo->
700 maxCASlatencySupported_LoP,
701 dimmInfo->
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000702 maxCASlatencySupported_RoP);
wdenkefe2a4d2004-12-16 21:44:03 +0000703 break;
704 }
705 break;
706 }
707 }
708 break;
709/*------------------------------------------------------------------------------------------------------------------------------*/
710
711 case 21: /* Buffered Address And Control Inputs */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000712 debug("\nModul Attributes (SPD Byte 21): \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000713 dimmInfo->bufferedAddrAndControlInputs =
714 data[i] & BIT0;
715 dimmInfo->registeredAddrAndControlInputs =
716 (data[i] & BIT1) >> 1;
717 dimmInfo->onCardPLL = (data[i] & BIT2) >> 2;
718 dimmInfo->bufferedDQMBinputs = (data[i] & BIT3) >> 3;
719 dimmInfo->registeredDQMBinputs =
720 (data[i] & BIT4) >> 4;
721 dimmInfo->differentialClockInput =
722 (data[i] & BIT5) >> 5;
723 dimmInfo->redundantRowAddressing =
724 (data[i] & BIT6) >> 6;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000725
wdenkefe2a4d2004-12-16 21:44:03 +0000726 if (dimmInfo->bufferedAddrAndControlInputs == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000727 debug(" - Buffered Address/Control Input: Yes \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000728 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000729 debug(" - Buffered Address/Control Input: No \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000730
731 if (dimmInfo->registeredAddrAndControlInputs == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000732 debug(" - Registered Address/Control Input: Yes \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000733 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000734 debug(" - Registered Address/Control Input: No \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000735
736 if (dimmInfo->onCardPLL == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000737 debug(" - On-Card PLL (clock): Yes \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000738 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000739 debug(" - On-Card PLL (clock): No \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000740
741 if (dimmInfo->bufferedDQMBinputs == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000742 debug(" - Bufferd DQMB Inputs: Yes \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000743 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000744 debug(" - Bufferd DQMB Inputs: No \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000745
746 if (dimmInfo->registeredDQMBinputs == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000747 debug(" - Registered DQMB Inputs: Yes \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000748 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000749 debug(" - Registered DQMB Inputs: No \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000750
751 if (dimmInfo->differentialClockInput == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000752 debug(" - Differential Clock Input: Yes \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000753 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000754 debug(" - Differential Clock Input: No \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000755
756 if (dimmInfo->redundantRowAddressing == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000757 debug(" - redundant Row Addressing: Yes \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000758 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000759 debug(" - redundant Row Addressing: No \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000760
wdenkefe2a4d2004-12-16 21:44:03 +0000761 break;
762/*------------------------------------------------------------------------------------------------------------------------------*/
763
764 case 22: /* Suported AutoPreCharge */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000765 debug("\nModul Attributes (SPD Byte 22): \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000766 dimmInfo->suportedEarlyRasPreCharge = data[i] & BIT0;
767 dimmInfo->suportedAutoPreCharge =
768 (data[i] & BIT1) >> 1;
769 dimmInfo->suportedPreChargeAll =
770 (data[i] & BIT2) >> 2;
771 dimmInfo->suportedWrite1ReadBurst =
772 (data[i] & BIT3) >> 3;
773 dimmInfo->suported5PercentLowVCC =
774 (data[i] & BIT4) >> 4;
775 dimmInfo->suported5PercentUpperVCC =
776 (data[i] & BIT5) >> 5;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000777
wdenkefe2a4d2004-12-16 21:44:03 +0000778 if (dimmInfo->suportedEarlyRasPreCharge == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000779 debug(" - Early Ras Precharge: Yes \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000780 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000781 debug(" - Early Ras Precharge: No \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000782
783 if (dimmInfo->suportedAutoPreCharge == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000784 debug(" - AutoPreCharge: Yes \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000785 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000786 debug(" - AutoPreCharge: No \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000787
788 if (dimmInfo->suportedPreChargeAll == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000789 debug(" - Precharge All: Yes \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000790 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000791 debug(" - Precharge All: No \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000792
793 if (dimmInfo->suportedWrite1ReadBurst == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000794 debug(" - Write 1/ReadBurst: Yes \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000795 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000796 debug(" - Write 1/ReadBurst: No \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000797
798 if (dimmInfo->suported5PercentLowVCC == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000799 debug(" - lower VCC tolerance: 5 Percent \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000800 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000801 debug(" - lower VCC tolerance: 10 Percent \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000802
803 if (dimmInfo->suported5PercentUpperVCC == 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000804 debug(" - upper VCC tolerance: 5 Percent \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000805 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000806 debug(" - upper VCC tolerance: 10 Percent \n");
wdenkefe2a4d2004-12-16 21:44:03 +0000807
wdenkefe2a4d2004-12-16 21:44:03 +0000808 break;
809/*------------------------------------------------------------------------------------------------------------------------------*/
810
811 case 23: /* Minimum Cycle Time At Maximum Cas Latancy Minus 1 (2nd highest CL) */
812 shift = (dimmInfo->memoryType == DDR) ? 4 : 2;
813 mult = (dimmInfo->memoryType == DDR) ? 10 : 25;
814 maskLeftOfPoint =
815 (dimmInfo->memoryType == DDR) ? 0xf0 : 0xfc;
816 maskRightOfPoint =
817 (dimmInfo->memoryType == DDR) ? 0xf : 0x03;
818 leftOfPoint = (data[i] & maskLeftOfPoint) >> shift;
819 rightOfPoint = (data[i] & maskRightOfPoint) * mult;
820 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus1_LoP =
821 leftOfPoint;
822 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus1_RoP =
823 rightOfPoint;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000824 debug("Minimum Cycle Time At 2nd highest CasLatancy (0 = Not supported): %d.%d [ns]\n",
825 leftOfPoint, rightOfPoint);
wdenkefe2a4d2004-12-16 21:44:03 +0000826 /*dimmInfo->minimumCycleTimeAtMaxCasLatancy */
827 break;
828/*------------------------------------------------------------------------------------------------------------------------------*/
829
830 case 24: /* Clock To Data Out 2nd highest Cas Latency Value */
831 div = (dimmInfo->memoryType == DDR) ? 100 : 10;
832 time_tmp =
833 (((data[i] & 0xf0) >> 4) * 10) +
834 ((data[i] & 0x0f));
835 leftOfPoint = time_tmp / div;
836 rightOfPoint = time_tmp % div;
837 dimmInfo->clockToDataOutMinus1_LoP = leftOfPoint;
838 dimmInfo->clockToDataOutMinus1_RoP = rightOfPoint;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000839 debug("Clock To Data Out (2nd CL value): %d.%2d [ns]\n",
840 leftOfPoint, rightOfPoint);
wdenkefe2a4d2004-12-16 21:44:03 +0000841 break;
842/*------------------------------------------------------------------------------------------------------------------------------*/
843
844 case 25: /* Minimum Cycle Time At Maximum Cas Latancy Minus 2 (3rd highest CL) */
845 shift = (dimmInfo->memoryType == DDR) ? 4 : 2;
846 mult = (dimmInfo->memoryType == DDR) ? 10 : 25;
847 maskLeftOfPoint =
848 (dimmInfo->memoryType == DDR) ? 0xf0 : 0xfc;
849 maskRightOfPoint =
850 (dimmInfo->memoryType == DDR) ? 0xf : 0x03;
851 leftOfPoint = (data[i] & maskLeftOfPoint) >> shift;
852 rightOfPoint = (data[i] & maskRightOfPoint) * mult;
853 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus2_LoP =
854 leftOfPoint;
855 dimmInfo->minimumCycleTimeAtMaxCasLatancyMinus2_RoP =
856 rightOfPoint;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000857 debug("Minimum Cycle Time At 3rd highest CasLatancy (0 = Not supported): %d.%d [ns]\n",
858 leftOfPoint, rightOfPoint);
wdenkefe2a4d2004-12-16 21:44:03 +0000859 /*dimmInfo->minimumCycleTimeAtMaxCasLatancy */
860 break;
861/*------------------------------------------------------------------------------------------------------------------------------*/
862
863 case 26: /* Clock To Data Out 3rd highest Cas Latency Value */
864 div = (dimmInfo->memoryType == DDR) ? 100 : 10;
865 time_tmp =
866 (((data[i] & 0xf0) >> 4) * 10) +
867 ((data[i] & 0x0f));
868 leftOfPoint = time_tmp / div;
869 rightOfPoint = time_tmp % div;
870 dimmInfo->clockToDataOutMinus2_LoP = leftOfPoint;
871 dimmInfo->clockToDataOutMinus2_RoP = rightOfPoint;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000872 debug("Clock To Data Out (3rd CL value): %d.%2d [ns]\n",
873 leftOfPoint, rightOfPoint);
wdenkefe2a4d2004-12-16 21:44:03 +0000874 break;
875/*------------------------------------------------------------------------------------------------------------------------------*/
876
877 case 27: /* Minimum Row Precharge Time */
878 shift = (dimmInfo->memoryType == DDR) ? 2 : 0;
879 maskLeftOfPoint =
880 (dimmInfo->memoryType == DDR) ? 0xfc : 0xff;
881 maskRightOfPoint =
882 (dimmInfo->memoryType == DDR) ? 0x03 : 0x00;
883 leftOfPoint = ((data[i] & maskLeftOfPoint) >> shift);
884 rightOfPoint = (data[i] & maskRightOfPoint) * 25;
885
886 dimmInfo->minRowPrechargeTime = ((leftOfPoint * 100) + rightOfPoint); /* measured in n times 10ps Intervals */
887 trp_clocks =
888 (dimmInfo->minRowPrechargeTime +
889 (tmemclk - 1)) / tmemclk;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000890 debug("*** 1 clock cycle = %ld 10ps intervalls = %ld.%ld ns****\n",
891 tmemclk, tmemclk / 100, tmemclk % 100);
892 debug("Minimum Row Precharge Time [ns]: %d.%2d = in Clk cycles %d\n",
893 leftOfPoint, rightOfPoint, trp_clocks);
wdenkefe2a4d2004-12-16 21:44:03 +0000894 break;
895/*------------------------------------------------------------------------------------------------------------------------------*/
896
897 case 28: /* Minimum Row Active to Row Active Time */
898 shift = (dimmInfo->memoryType == DDR) ? 2 : 0;
899 maskLeftOfPoint =
900 (dimmInfo->memoryType == DDR) ? 0xfc : 0xff;
901 maskRightOfPoint =
902 (dimmInfo->memoryType == DDR) ? 0x03 : 0x00;
903 leftOfPoint = ((data[i] & maskLeftOfPoint) >> shift);
904 rightOfPoint = (data[i] & maskRightOfPoint) * 25;
905
906 dimmInfo->minRowActiveRowActiveDelay = ((leftOfPoint * 100) + rightOfPoint); /* measured in 100ns Intervals */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000907 debug("Minimum Row Active -To- Row Active Delay [ns]: %d.%2d = in Clk cycles %d\n",
908 leftOfPoint, rightOfPoint, trp_clocks);
wdenkefe2a4d2004-12-16 21:44:03 +0000909 break;
910/*------------------------------------------------------------------------------------------------------------------------------*/
911
912 case 29: /* Minimum Ras-To-Cas Delay */
913 shift = (dimmInfo->memoryType == DDR) ? 2 : 0;
914 maskLeftOfPoint =
915 (dimmInfo->memoryType == DDR) ? 0xfc : 0xff;
916 maskRightOfPoint =
917 (dimmInfo->memoryType == DDR) ? 0x03 : 0x00;
918 leftOfPoint = ((data[i] & maskLeftOfPoint) >> shift);
919 rightOfPoint = (data[i] & maskRightOfPoint) * 25;
920
921 dimmInfo->minRowActiveRowActiveDelay = ((leftOfPoint * 100) + rightOfPoint); /* measured in 100ns Intervals */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000922 debug("Minimum Ras-To-Cas Delay [ns]: %d.%2d = in Clk cycles %d\n",
923 leftOfPoint, rightOfPoint, trp_clocks);
wdenkefe2a4d2004-12-16 21:44:03 +0000924 break;
925/*------------------------------------------------------------------------------------------------------------------------------*/
926
927 case 30: /* Minimum Ras Pulse Width */
928 dimmInfo->minRasPulseWidth = data[i];
929 tras_clocks =
930 (NSto10PS (data[i]) +
931 (tmemclk - 1)) / tmemclk;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000932 debug("Minimum Ras Pulse Width [ns]: %d = in Clk cycles %d\n",
933 dimmInfo->minRasPulseWidth, tras_clocks);
wdenkefe2a4d2004-12-16 21:44:03 +0000934
935 break;
936/*------------------------------------------------------------------------------------------------------------------------------*/
937
938 case 31: /* Module Bank Density */
939 dimmInfo->moduleBankDensity = data[i];
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000940 debug("Module Bank Density: %d\n",
941 dimmInfo->moduleBankDensity);
wdenkefe2a4d2004-12-16 21:44:03 +0000942#ifdef DEBUG
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000943 debug("*** Offered Densities (more than 1 = Multisize-Module): ");
stroese771e05b2004-12-16 18:21:17 +0000944 {
wdenkefe2a4d2004-12-16 21:44:03 +0000945 if (dimmInfo->moduleBankDensity & 1)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000946 debug("4MB, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000947 if (dimmInfo->moduleBankDensity & 2)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000948 debug("8MB, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000949 if (dimmInfo->moduleBankDensity & 4)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000950 debug("16MB, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000951 if (dimmInfo->moduleBankDensity & 8)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000952 debug("32MB, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000953 if (dimmInfo->moduleBankDensity & 16)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000954 debug("64MB, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000955 if (dimmInfo->moduleBankDensity & 32)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000956 debug("128MB, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000957 if ((dimmInfo->moduleBankDensity & 64)
958 || (dimmInfo->moduleBankDensity & 128)) {
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000959 debug("ERROR, ");
wdenkefe2a4d2004-12-16 21:44:03 +0000960 hang ();
961 }
stroese771e05b2004-12-16 18:21:17 +0000962 }
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000963 debug("\n");
wdenkefe2a4d2004-12-16 21:44:03 +0000964#endif
965 break;
966/*------------------------------------------------------------------------------------------------------------------------------*/
967
968 case 32: /* Address And Command Setup Time (measured in ns/1000) */
969 sign = 1;
970 switch (dimmInfo->memoryType) {
971 case DDR:
972 time_tmp =
973 (((data[i] & 0xf0) >> 4) * 10) +
974 ((data[i] & 0x0f));
975 leftOfPoint = time_tmp / 100;
976 rightOfPoint = time_tmp % 100;
977 break;
978 case SDRAM:
979 leftOfPoint = (data[i] & 0xf0) >> 4;
980 if (leftOfPoint > 7) {
981 leftOfPoint = data[i] & 0x70 >> 4;
982 sign = -1;
983 }
984 rightOfPoint = (data[i] & 0x0f);
985 break;
986 }
987 dimmInfo->addrAndCommandSetupTime =
988 (leftOfPoint * 100 + rightOfPoint) * sign;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +0000989 debug("Address And Command Setup Time [ns]: %d.%d\n",
990 sign * leftOfPoint, rightOfPoint);
wdenkefe2a4d2004-12-16 21:44:03 +0000991 break;
992/*------------------------------------------------------------------------------------------------------------------------------*/
993
994 case 33: /* Address And Command Hold Time */
995 sign = 1;
996 switch (dimmInfo->memoryType) {
997 case DDR:
998 time_tmp =
999 (((data[i] & 0xf0) >> 4) * 10) +
1000 ((data[i] & 0x0f));
1001 leftOfPoint = time_tmp / 100;
1002 rightOfPoint = time_tmp % 100;
1003 break;
1004 case SDRAM:
1005 leftOfPoint = (data[i] & 0xf0) >> 4;
1006 if (leftOfPoint > 7) {
1007 leftOfPoint = data[i] & 0x70 >> 4;
1008 sign = -1;
1009 }
1010 rightOfPoint = (data[i] & 0x0f);
1011 break;
1012 }
1013 dimmInfo->addrAndCommandHoldTime =
1014 (leftOfPoint * 100 + rightOfPoint) * sign;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001015 debug("Address And Command Hold Time [ns]: %d.%d\n",
1016 sign * leftOfPoint, rightOfPoint);
wdenkefe2a4d2004-12-16 21:44:03 +00001017 break;
1018/*------------------------------------------------------------------------------------------------------------------------------*/
1019
1020 case 34: /* Data Input Setup Time */
1021 sign = 1;
1022 switch (dimmInfo->memoryType) {
1023 case DDR:
1024 time_tmp =
1025 (((data[i] & 0xf0) >> 4) * 10) +
1026 ((data[i] & 0x0f));
1027 leftOfPoint = time_tmp / 100;
1028 rightOfPoint = time_tmp % 100;
1029 break;
1030 case SDRAM:
1031 leftOfPoint = (data[i] & 0xf0) >> 4;
1032 if (leftOfPoint > 7) {
1033 leftOfPoint = data[i] & 0x70 >> 4;
1034 sign = -1;
1035 }
1036 rightOfPoint = (data[i] & 0x0f);
1037 break;
1038 }
1039 dimmInfo->dataInputSetupTime =
1040 (leftOfPoint * 100 + rightOfPoint) * sign;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001041 debug("Data Input Setup Time [ns]: %d.%d\n",
1042 sign * leftOfPoint, rightOfPoint);
wdenkefe2a4d2004-12-16 21:44:03 +00001043 break;
1044/*------------------------------------------------------------------------------------------------------------------------------*/
1045
1046 case 35: /* Data Input Hold Time */
1047 sign = 1;
1048 switch (dimmInfo->memoryType) {
1049 case DDR:
1050 time_tmp =
1051 (((data[i] & 0xf0) >> 4) * 10) +
1052 ((data[i] & 0x0f));
1053 leftOfPoint = time_tmp / 100;
1054 rightOfPoint = time_tmp % 100;
1055 break;
1056 case SDRAM:
1057 leftOfPoint = (data[i] & 0xf0) >> 4;
1058 if (leftOfPoint > 7) {
1059 leftOfPoint = data[i] & 0x70 >> 4;
1060 sign = -1;
1061 }
1062 rightOfPoint = (data[i] & 0x0f);
1063 break;
1064 }
1065 dimmInfo->dataInputHoldTime =
1066 (leftOfPoint * 100 + rightOfPoint) * sign;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001067 debug("Data Input Hold Time [ns]: %d.%d\n\n",
1068 sign * leftOfPoint, rightOfPoint);
wdenkefe2a4d2004-12-16 21:44:03 +00001069 break;
1070/*------------------------------------------------------------------------------------------------------------------------------*/
stroese771e05b2004-12-16 18:21:17 +00001071 }
stroese771e05b2004-12-16 18:21:17 +00001072 }
wdenkefe2a4d2004-12-16 21:44:03 +00001073 /* calculating the sdram density */
1074 for (i = 0;
1075 i < dimmInfo->numOfRowAddresses + dimmInfo->numOfColAddresses;
1076 i++) {
1077 density = density * 2;
1078 }
1079 dimmInfo->deviceDensity = density * dimmInfo->numOfBanksOnEachDevice *
1080 dimmInfo->sdramWidth;
1081 dimmInfo->numberOfDevices =
1082 (dimmInfo->dataWidth / dimmInfo->sdramWidth) *
1083 dimmInfo->numOfModuleBanks;
1084 devicesForErrCheck =
1085 (dimmInfo->dataWidth - 64) / dimmInfo->sdramWidth;
1086 if ((dimmInfo->errorCheckType == 0x1)
1087 || (dimmInfo->errorCheckType == 0x2)
1088 || (dimmInfo->errorCheckType == 0x3)) {
1089 dimmInfo->size =
1090 (dimmInfo->deviceDensity / 8) *
1091 (dimmInfo->numberOfDevices - devicesForErrCheck);
1092 } else {
1093 dimmInfo->size =
1094 (dimmInfo->deviceDensity / 8) *
1095 dimmInfo->numberOfDevices;
1096 }
stroese771e05b2004-12-16 18:21:17 +00001097
wdenkefe2a4d2004-12-16 21:44:03 +00001098 /* compute the module DRB size */
1099 tmp = (1 <<
1100 (dimmInfo->numOfRowAddresses + dimmInfo->numOfColAddresses));
1101 tmp *= dimmInfo->numOfModuleBanks;
1102 tmp *= dimmInfo->sdramWidth;
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001103 tmp = tmp >> 24; /* div by 0x4000000 (64M) */
wdenkefe2a4d2004-12-16 21:44:03 +00001104 dimmInfo->drb_size = (uchar) tmp;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001105 debug("Module DRB size (n*64Mbit): %d\n", dimmInfo->drb_size);
stroese771e05b2004-12-16 18:21:17 +00001106
1107 /* try a CAS latency of 3 first... */
1108
1109 /* bit 1 is CL2, bit 2 is CL3 */
1110 supp_cal = (dimmInfo->suportedCasLatencies & 0x1c) >> 1;
1111
1112 cal_val = 0;
1113 if (supp_cal & 8) {
wdenkefe2a4d2004-12-16 21:44:03 +00001114 if (NS10to10PS (data[9]) <= tmemclk)
stroese771e05b2004-12-16 18:21:17 +00001115 cal_val = 6;
1116 }
1117 if (supp_cal & 4) {
wdenkefe2a4d2004-12-16 21:44:03 +00001118 if (NS10to10PS (data[9]) <= tmemclk)
stroese771e05b2004-12-16 18:21:17 +00001119 cal_val = 5;
1120 }
1121
1122 /* then 2... */
1123 if (supp_cal & 2) {
wdenkefe2a4d2004-12-16 21:44:03 +00001124 if (NS10to10PS (data[23]) <= tmemclk)
stroese771e05b2004-12-16 18:21:17 +00001125 cal_val = 4;
1126 }
1127
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001128 debug("cal_val = %d\n", cal_val * 5);
stroese771e05b2004-12-16 18:21:17 +00001129
1130 /* bummer, did't work... */
1131 if (cal_val == 0) {
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001132 debug("Couldn't find a good CAS latency\n");
wdenkefe2a4d2004-12-16 21:44:03 +00001133 hang ();
stroese771e05b2004-12-16 18:21:17 +00001134 return 0;
1135 }
1136
wdenkefe2a4d2004-12-16 21:44:03 +00001137 return true;
stroese771e05b2004-12-16 18:21:17 +00001138}
1139
1140/* sets up the GT properly with information passed in */
wdenkefe2a4d2004-12-16 21:44:03 +00001141int setup_sdram (AUX_MEM_DIMM_INFO * info)
stroese771e05b2004-12-16 18:21:17 +00001142{
Wolfgang Denkcdd917a2007-08-02 00:48:45 +02001143 ulong tmp;
wdenkefe2a4d2004-12-16 21:44:03 +00001144 ulong tmp_sdram_mode = 0; /* 0x141c */
1145 ulong tmp_dunit_control_low = 0; /* 0x1404 */
Reinhard Arlt0738e242010-04-13 09:59:09 +02001146 uint sdram_config_reg = CONFIG_SYS_SDRAM_CONFIG;
stroese771e05b2004-12-16 18:21:17 +00001147 int i;
1148
1149 /* sanity checking */
wdenkefe2a4d2004-12-16 21:44:03 +00001150 if (!info->numOfModuleBanks) {
1151 printf ("setup_sdram called with 0 banks\n");
stroese771e05b2004-12-16 18:21:17 +00001152 return 1;
1153 }
1154
1155 /* delay line */
1156
1157 /* Program the GT with the discovered data */
1158 if (info->registeredAddrAndControlInputs == true)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001159 debug("Module is registered, but we do not support registered Modules !!!\n");
stroese771e05b2004-12-16 18:21:17 +00001160
stroese771e05b2004-12-16 18:21:17 +00001161 /* delay line */
wdenkefe2a4d2004-12-16 21:44:03 +00001162 set_dfcdlInit (); /* may be its not needed */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001163 debug("Delay line set done\n");
stroese771e05b2004-12-16 18:21:17 +00001164
wdenkefe2a4d2004-12-16 21:44:03 +00001165 /* set SDRAM mode NOP */ /* To_do check it */
1166 GT_REG_WRITE (SDRAM_OPERATION, 0x5);
1167 while (GTREGREAD (SDRAM_OPERATION) != 0) {
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001168 debug("\n*** SDRAM_OPERATION 1418: Module still busy ... please wait... ***\n");
wdenkefe2a4d2004-12-16 21:44:03 +00001169 }
stroese771e05b2004-12-16 18:21:17 +00001170
Reinhard Arlt0738e242010-04-13 09:59:09 +02001171#ifdef CONFIG_MV64360_ECC
1172 if ((info->errorCheckType == 0x2) && (CPCI750_ECC_TEST)) {
1173 /* DRAM has ECC, so turn it on */
1174 sdram_config_reg |= BIT18;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001175 debug("Enabling ECC\n");
Reinhard Arlt0738e242010-04-13 09:59:09 +02001176 }
1177#endif /* of ifdef CONFIG_MV64360_ECC */
1178
stroese771e05b2004-12-16 18:21:17 +00001179 /* SDRAM configuration */
Reinhard Arlt0738e242010-04-13 09:59:09 +02001180 GT_REG_WRITE(SDRAM_CONFIG, sdram_config_reg);
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001181 debug("sdram_conf 0x1400: %08x\n", GTREGREAD (SDRAM_CONFIG));
stroese771e05b2004-12-16 18:21:17 +00001182
wdenkefe2a4d2004-12-16 21:44:03 +00001183 /* SDRAM open pages controll keep open as much as I can */
1184 GT_REG_WRITE (SDRAM_OPEN_PAGES_CONTROL, 0x0);
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001185 debug("sdram_open_pages_controll 0x1414: %08x\n",
1186 GTREGREAD (SDRAM_OPEN_PAGES_CONTROL));
stroese771e05b2004-12-16 18:21:17 +00001187
1188
1189 /* SDRAM D_UNIT_CONTROL_LOW 0x1404 */
wdenkefe2a4d2004-12-16 21:44:03 +00001190 tmp = (GTREGREAD (D_UNIT_CONTROL_LOW) & 0x01); /* Clock Domain Sync from power on reset */
stroese771e05b2004-12-16 18:21:17 +00001191 if (tmp == 0)
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001192 debug("Core Signals are sync (by HW-Setting)!!!\n");
stroese771e05b2004-12-16 18:21:17 +00001193 else
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001194 debug("Core Signals syncs. are bypassed (by HW-Setting)!!!\n");
stroese771e05b2004-12-16 18:21:17 +00001195
wdenkefe2a4d2004-12-16 21:44:03 +00001196 /* SDRAM set CAS Lentency according to SPD information */
1197 switch (info->memoryType) {
1198 case SDRAM:
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001199 debug("### SD-RAM not supported yet !!!\n");
wdenkefe2a4d2004-12-16 21:44:03 +00001200 hang ();
1201 /* ToDo fill SD-RAM if needed !!!!! */
stroese771e05b2004-12-16 18:21:17 +00001202 break;
1203
wdenkefe2a4d2004-12-16 21:44:03 +00001204 case DDR:
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001205 debug("### SET-CL for DDR-RAM\n");
stroese771e05b2004-12-16 18:21:17 +00001206
wdenkefe2a4d2004-12-16 21:44:03 +00001207 switch (info->maxClSupported_DDR) {
1208 case DDR_CL_3:
1209 tmp_dunit_control_low = 0x3c000000; /* Read-Data sampled on falling edge of Clk */
1210 tmp_sdram_mode = 0x32; /* CL=3 Burstlength = 4 */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001211 debug("Max. CL is 3 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1212 tmp_sdram_mode, tmp_dunit_control_low);
wdenkefe2a4d2004-12-16 21:44:03 +00001213 break;
stroese771e05b2004-12-16 18:21:17 +00001214
wdenkefe2a4d2004-12-16 21:44:03 +00001215 case DDR_CL_2_5:
1216 if (tmp == 1) { /* clocks sync */
1217 tmp_dunit_control_low = 0x24000000; /* Read-Data sampled on falling edge of Clk */
1218 tmp_sdram_mode = 0x62; /* CL=2,5 Burstlength = 4 */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001219 debug("Max. CL is 2,5s CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1220 tmp_sdram_mode, tmp_dunit_control_low);
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001221 } else { /* clk sync. bypassed */
stroese771e05b2004-12-16 18:21:17 +00001222
wdenkefe2a4d2004-12-16 21:44:03 +00001223 tmp_dunit_control_low = 0x03000000; /* Read-Data sampled on rising edge of Clk */
1224 tmp_sdram_mode = 0x62; /* CL=2,5 Burstlength = 4 */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001225 debug("Max. CL is 2,5 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1226 tmp_sdram_mode, tmp_dunit_control_low);
wdenkefe2a4d2004-12-16 21:44:03 +00001227 }
1228 break;
1229
1230 case DDR_CL_2:
1231 if (tmp == 1) { /* Sync */
1232 tmp_dunit_control_low = 0x03000000; /* Read-Data sampled on rising edge of Clk */
1233 tmp_sdram_mode = 0x22; /* CL=2 Burstlength = 4 */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001234 debug("Max. CL is 2s CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1235 tmp_sdram_mode, tmp_dunit_control_low);
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001236 } else { /* Not sync. */
wdenkefe2a4d2004-12-16 21:44:03 +00001237
1238 tmp_dunit_control_low = 0x3b000000; /* Read-Data sampled on rising edge of Clk */
1239 tmp_sdram_mode = 0x22; /* CL=2 Burstlength = 4 */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001240 debug("Max. CL is 2 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1241 tmp_sdram_mode, tmp_dunit_control_low);
wdenkefe2a4d2004-12-16 21:44:03 +00001242 }
1243 break;
1244
1245 case DDR_CL_1_5:
1246 if (tmp == 1) { /* Sync */
1247 tmp_dunit_control_low = 0x23000000; /* Read-Data sampled on falling edge of Clk */
1248 tmp_sdram_mode = 0x52; /* CL=1,5 Burstlength = 4 */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001249 debug("Max. CL is 1,5s CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1250 tmp_sdram_mode, tmp_dunit_control_low);
wdenkefe2a4d2004-12-16 21:44:03 +00001251 } else { /* not sync */
1252
1253 tmp_dunit_control_low = 0x1a000000; /* Read-Data sampled on rising edge of Clk */
1254 tmp_sdram_mode = 0x52; /* CL=1,5 Burstlength = 4 */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001255 debug("Max. CL is 1,5 CLKs 0x141c= %08lx, 0x1404 = %08lx\n",
1256 tmp_sdram_mode, tmp_dunit_control_low);
wdenkefe2a4d2004-12-16 21:44:03 +00001257 }
1258 break;
1259
1260 default:
1261 printf ("Max. CL is out of range %d\n",
1262 info->maxClSupported_DDR);
1263 hang ();
1264 break;
1265 }
stroese771e05b2004-12-16 18:21:17 +00001266 break;
wdenkefe2a4d2004-12-16 21:44:03 +00001267 }
stroese771e05b2004-12-16 18:21:17 +00001268
1269 /* Write results of CL detection procedure */
wdenkefe2a4d2004-12-16 21:44:03 +00001270 GT_REG_WRITE (SDRAM_MODE, tmp_sdram_mode);
1271 /* set SDRAM mode SetCommand 0x1418 */
1272 GT_REG_WRITE (SDRAM_OPERATION, 0x3);
1273 while (GTREGREAD (SDRAM_OPERATION) != 0) {
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001274 debug("\n*** SDRAM_OPERATION 1418 after SDRAM_MODE: Module still busy ... please wait... ***\n");
wdenkefe2a4d2004-12-16 21:44:03 +00001275 }
stroese771e05b2004-12-16 18:21:17 +00001276
1277
1278 /* SDRAM D_UNIT_CONTROL_LOW 0x1404 */
wdenkefe2a4d2004-12-16 21:44:03 +00001279 tmp = (GTREGREAD (D_UNIT_CONTROL_LOW) & 0x01); /* Clock Domain Sync from power on reset */
1280 if (tmp != 1) { /*clocks are not sync */
1281 /* asyncmode */
1282 GT_REG_WRITE (D_UNIT_CONTROL_LOW,
1283 (GTREGREAD (D_UNIT_CONTROL_LOW) & 0x7F) |
1284 0x18110780 | tmp_dunit_control_low);
1285 } else {
1286 /* syncmode */
1287 GT_REG_WRITE (D_UNIT_CONTROL_LOW,
1288 (GTREGREAD (D_UNIT_CONTROL_LOW) & 0x7F) |
1289 0x00110000 | tmp_dunit_control_low);
1290 }
stroese771e05b2004-12-16 18:21:17 +00001291
wdenkefe2a4d2004-12-16 21:44:03 +00001292 /* set SDRAM mode SetCommand 0x1418 */
1293 GT_REG_WRITE (SDRAM_OPERATION, 0x3);
1294 while (GTREGREAD (SDRAM_OPERATION) != 0) {
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001295 debug("\n*** SDRAM_OPERATION 1418 after D_UNIT_CONTROL_LOW: Module still busy ... please wait... ***\n");
wdenkefe2a4d2004-12-16 21:44:03 +00001296 }
stroese771e05b2004-12-16 18:21:17 +00001297
1298/*------------------------------------------------------------------------------ */
1299
1300
1301 /* bank parameters */
1302 /* SDRAM address decode register */
1303 /* program this with the default value */
1304 tmp = 0x02;
1305
1306
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001307 debug("drb_size (n*64Mbit): %d\n", info->drb_size);
stroese771e05b2004-12-16 18:21:17 +00001308 switch (info->drb_size) {
wdenkefe2a4d2004-12-16 21:44:03 +00001309 case 1: /* 64 Mbit */
1310 case 2: /* 128 Mbit */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001311 debug("RAM-Device_size 64Mbit or 128Mbit)\n");
stroese771e05b2004-12-16 18:21:17 +00001312 tmp |= (0x00 << 4);
1313 break;
wdenkefe2a4d2004-12-16 21:44:03 +00001314 case 4: /* 256 Mbit */
1315 case 8: /* 512 Mbit */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001316 debug("RAM-Device_size 256Mbit or 512Mbit)\n");
stroese771e05b2004-12-16 18:21:17 +00001317 tmp |= (0x01 << 4);
1318 break;
wdenkefe2a4d2004-12-16 21:44:03 +00001319 case 16: /* 1 Gbit */
1320 case 32: /* 2 Gbit */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001321 debug("RAM-Device_size 1Gbit or 2Gbit)\n");
stroese771e05b2004-12-16 18:21:17 +00001322 tmp |= (0x02 << 4);
1323 break;
1324 default:
wdenkefe2a4d2004-12-16 21:44:03 +00001325 printf ("Error in dram size calculation\n");
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001326 debug("Assume: RAM-Device_size 1Gbit or 2Gbit)\n");
stroese771e05b2004-12-16 18:21:17 +00001327 tmp |= (0x02 << 4);
1328 return 1;
1329 }
1330
1331 /* SDRAM bank parameters */
1332 /* the param registers for slot 1 (banks 2+3) are offset by 0x8 */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001333 debug("setting up slot %d config with: %08lx \n", info->slot, tmp);
wdenkefe2a4d2004-12-16 21:44:03 +00001334 GT_REG_WRITE (SDRAM_ADDR_CONTROL, tmp);
stroese771e05b2004-12-16 18:21:17 +00001335
1336/* ------------------------------------------------------------------------------ */
1337
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001338 debug("setting up sdram_timing_control_low with: %08x \n",
1339 0x11511220);
wdenkefe2a4d2004-12-16 21:44:03 +00001340 GT_REG_WRITE (SDRAM_TIMING_CONTROL_LOW, 0x11511220);
stroese771e05b2004-12-16 18:21:17 +00001341
1342
1343/* ------------------------------------------------------------------------------ */
1344
1345 /* SDRAM configuration */
wdenkefe2a4d2004-12-16 21:44:03 +00001346 tmp = GTREGREAD (SDRAM_CONFIG);
stroese771e05b2004-12-16 18:21:17 +00001347
wdenkefe2a4d2004-12-16 21:44:03 +00001348 if (info->registeredAddrAndControlInputs
1349 || info->registeredDQMBinputs) {
1350 tmp |= (1 << 17);
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001351 debug("SPD says: registered Addr. and Cont.: %d; registered DQMBinputs: %d\n",
wdenkefe2a4d2004-12-16 21:44:03 +00001352 info->registeredAddrAndControlInputs,
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001353 info->registeredDQMBinputs);
stroese771e05b2004-12-16 18:21:17 +00001354 }
1355
1356 /* Use buffer 1 to return read data to the CPU
1357 * Page 426 MV64360 */
1358 tmp |= (1 << 26);
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001359 debug("Before Buffer assignment - sdram_conf: %08x\n",
1360 GTREGREAD (SDRAM_CONFIG));
1361 debug("After Buffer assignment - sdram_conf: %08x\n",
1362 GTREGREAD (SDRAM_CONFIG));
stroese771e05b2004-12-16 18:21:17 +00001363
wdenkefe2a4d2004-12-16 21:44:03 +00001364 /* SDRAM timing To_do: */
stroese771e05b2004-12-16 18:21:17 +00001365
1366
wdenkefe2a4d2004-12-16 21:44:03 +00001367 tmp = GTREGREAD (SDRAM_TIMING_CONTROL_HIGH);
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001368 debug("# sdram_timing_control_high is : %08lx \n", tmp);
stroese771e05b2004-12-16 18:21:17 +00001369
1370 /* SDRAM address decode register */
1371 /* program this with the default value */
wdenkefe2a4d2004-12-16 21:44:03 +00001372 tmp = GTREGREAD (SDRAM_ADDR_CONTROL);
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001373 debug("SDRAM address control (before: decode): %08x ",
1374 GTREGREAD (SDRAM_ADDR_CONTROL));
wdenkefe2a4d2004-12-16 21:44:03 +00001375 GT_REG_WRITE (SDRAM_ADDR_CONTROL, (tmp | 0x2));
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001376 debug("SDRAM address control (after: decode): %08x\n",
1377 GTREGREAD (SDRAM_ADDR_CONTROL));
stroese771e05b2004-12-16 18:21:17 +00001378
1379 /* set the SDRAM configuration for each bank */
1380
1381/* for (i = info->slot * 2; i < ((info->slot * 2) + info->banks); i++) */
1382 {
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001383 int l, l1;
Stefan Roesed5ea2872007-01-31 16:38:04 +01001384
stroese771e05b2004-12-16 18:21:17 +00001385 i = info->slot;
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001386 debug("\n*** Running a MRS cycle for bank %d ***\n", i);
stroese771e05b2004-12-16 18:21:17 +00001387
1388 /* map the bank */
wdenkefe2a4d2004-12-16 21:44:03 +00001389 memory_map_bank (i, 0, GB / 4);
1390#if 1 /* test only */
stroese771e05b2004-12-16 18:21:17 +00001391
Stefan Roesed5ea2872007-01-31 16:38:04 +01001392 tmp = GTREGREAD (SDRAM_MODE);
1393 GT_REG_WRITE (EXTENDED_DRAM_MODE, 0x0);
1394 GT_REG_WRITE (SDRAM_OPERATION, 0x4);
1395 while (GTREGREAD (SDRAM_OPERATION) != 0) {
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001396 debug("\n*** SDRAM_OPERATION 1418 after SDRAM_MODE: Module still busy ... please wait... ***\n");
Stefan Roesed5ea2872007-01-31 16:38:04 +01001397 }
1398
1399 GT_REG_WRITE (SDRAM_MODE, tmp | 0x80);
1400 GT_REG_WRITE (SDRAM_OPERATION, 0x3);
1401 while (GTREGREAD (SDRAM_OPERATION) != 0) {
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001402 debug("\n*** SDRAM_OPERATION 1418 after SDRAM_MODE: Module still busy ... please wait... ***\n");
Stefan Roesed5ea2872007-01-31 16:38:04 +01001403 }
1404 l1 = 0;
1405 for (l=0;l<200;l++)
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001406 l1 += GTREGREAD (SDRAM_OPERATION);
Stefan Roesed5ea2872007-01-31 16:38:04 +01001407
1408 GT_REG_WRITE (SDRAM_MODE, tmp);
1409 GT_REG_WRITE (SDRAM_OPERATION, 0x3);
1410 while (GTREGREAD (SDRAM_OPERATION) != 0) {
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001411 debug("\n*** SDRAM_OPERATION 1418 after SDRAM_MODE: Module still busy ... please wait... ***\n");
Stefan Roesed5ea2872007-01-31 16:38:04 +01001412 }
stroese771e05b2004-12-16 18:21:17 +00001413
1414 /* switch back to normal operation mode */
Stefan Roesed5ea2872007-01-31 16:38:04 +01001415 GT_REG_WRITE (SDRAM_OPERATION, 0x5);
1416 while (GTREGREAD (SDRAM_OPERATION) != 0) {
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001417 debug("\n*** SDRAM_OPERATION 1418 after SDRAM_MODE: Module still busy ... please wait... ***\n");
Stefan Roesed5ea2872007-01-31 16:38:04 +01001418 }
1419
stroese771e05b2004-12-16 18:21:17 +00001420#endif /* test only */
1421 /* unmap the bank */
wdenkefe2a4d2004-12-16 21:44:03 +00001422 memory_map_bank (i, 0, 0);
stroese771e05b2004-12-16 18:21:17 +00001423 }
1424
1425 return 0;
1426}
1427
1428/*
1429 * Check memory range for valid RAM. A simple memory test determines
1430 * the actually available RAM size between addresses `base' and
1431 * `base + maxsize'. Some (not all) hardware errors are detected:
1432 * - short between address lines
1433 * - short between data lines
1434 */
1435long int
1436dram_size(long int *base, long int maxsize)
1437{
1438 volatile long int *addr, *b=base;
1439 long int cnt, val, save1, save2;
1440
1441#define STARTVAL (1<<20) /* start test at 1M */
1442 for (cnt = STARTVAL/sizeof(long); cnt < maxsize/sizeof(long); cnt <<= 1) {
1443 addr = base + cnt; /* pointer arith! */
1444
Wolfgang Denkd0ff51b2008-07-14 15:19:07 +02001445 save1 = *addr; /* save contents of addr */
1446 save2 = *b; /* save contents of base */
stroese771e05b2004-12-16 18:21:17 +00001447
1448 *addr=cnt; /* write cnt to addr */
1449 *b=0; /* put null at base */
1450
1451 /* check at base address */
1452 if ((*b) != 0) {
1453 *addr=save1; /* restore *addr */
1454 *b=save2; /* restore *b */
1455 return (0);
1456 }
1457 val = *addr; /* read *addr */
1458 val = *addr; /* read *addr */
1459
1460 *addr=save1;
1461 *b=save2;
1462
1463 if (val != cnt) {
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001464 debug("Found %08x at Address %08x (failure)\n", (unsigned int)val, (unsigned int) addr);
stroese771e05b2004-12-16 18:21:17 +00001465 /* fix boundary condition.. STARTVAL means zero */
1466 if(cnt==STARTVAL/sizeof(long)) cnt=0;
1467 return (cnt * sizeof(long));
1468 }
1469 }
1470 return maxsize;
1471}
1472
Reinhard Arlt0738e242010-04-13 09:59:09 +02001473#ifdef CONFIG_MV64360_ECC
1474/*
1475 * mv_dma_is_channel_active:
1476 * Checks if a engine is busy.
1477 */
1478int mv_dma_is_channel_active(int engine)
1479{
1480 ulong data;
1481
1482 data = GTREGREAD(MV64360_DMA_CHANNEL0_CONTROL + 4 * engine);
1483 if (data & BIT14) /* activity status */
1484 return 1;
1485
1486 return 0;
1487}
1488
1489/*
1490 * mv_dma_set_memory_space:
1491 * Set a DMA memory window for the DMA's address decoding map.
1492 */
1493int mv_dma_set_memory_space(ulong mem_space, ulong mem_space_target,
1494 ulong mem_space_attr, ulong base_address,
1495 ulong size)
1496{
1497 ulong temp;
1498
1499 /* The base address must be aligned to the size. */
1500 if (base_address % size != 0)
1501 return 0;
1502
1503 if (size >= 0x10000) {
1504 size &= 0xffff0000;
1505 base_address = (base_address & 0xffff0000);
1506 /* Set the new attributes */
1507 GT_REG_WRITE(MV64360_DMA_BASE_ADDR_REG0 + mem_space * 8,
1508 (base_address | mem_space_target |
1509 mem_space_attr));
1510 GT_REG_WRITE((MV64360_DMA_SIZE_REG0 + mem_space * 8),
1511 (size - 1) & 0xffff0000);
1512 temp = GTREGREAD(MV64360_DMA_BASE_ADDR_ENABLE_REG);
1513 GT_REG_WRITE(DMA_BASE_ADDR_ENABLE_REG,
1514 (temp & ~(BIT0 << mem_space)));
1515 return 1;
1516 }
1517
1518 return 0;
1519}
1520
1521
1522/*
1523 * mv_dma_transfer:
1524 * Transfer data from source_addr to dest_addr on one of the 4 DMA channels.
1525 */
1526int mv_dma_transfer(int engine, ulong source_addr,
1527 ulong dest_addr, ulong bytes, ulong command)
1528{
1529 ulong eng_off_reg; /* Engine Offset Register */
1530
1531 if (bytes > 0xffff)
1532 command = command | BIT31; /* DMA_16M_DESCRIPTOR_MODE */
1533
1534 command = command | ((command >> 6) & 0x7);
1535 eng_off_reg = engine * 4;
1536 GT_REG_WRITE(MV64360_DMA_CHANNEL0_BYTE_COUNT + eng_off_reg,
1537 bytes);
1538 GT_REG_WRITE(MV64360_DMA_CHANNEL0_SOURCE_ADDR + eng_off_reg,
1539 source_addr);
1540 GT_REG_WRITE(MV64360_DMA_CHANNEL0_DESTINATION_ADDR + eng_off_reg,
1541 dest_addr);
1542 command |= BIT12 /* DMA_CHANNEL_ENABLE */
1543 | BIT9; /* DMA_NON_CHAIN_MODE */
1544
1545 /* Activate DMA engine By writting to mv_dma_control_register */
1546 GT_REG_WRITE(MV64360_DMA_CHANNEL0_CONTROL + eng_off_reg, command);
1547
1548 return 1;
1549}
1550#endif /* of ifdef CONFIG_MV64360_ECC */
stroese771e05b2004-12-16 18:21:17 +00001551
1552/* ppcboot interface function to SDRAM init - this is where all the
1553 * controlling logic happens */
Becky Bruce9973e3c2008-06-09 16:03:40 -05001554phys_size_t
stroese771e05b2004-12-16 18:21:17 +00001555initdram(int board_type)
1556{
stroese771e05b2004-12-16 18:21:17 +00001557 int checkbank[4] = { [0 ... 3] = 0 };
Reinhard Arlt0738e242010-04-13 09:59:09 +02001558 ulong realsize, total, check;
stroese771e05b2004-12-16 18:21:17 +00001559 AUX_MEM_DIMM_INFO dimmInfo1;
1560 AUX_MEM_DIMM_INFO dimmInfo2;
Reinhard Arlt0738e242010-04-13 09:59:09 +02001561 int bank_no, nhr;
1562#ifdef CONFIG_MV64360_ECC
1563 ulong dest, mem_space_attr;
1564#endif /* of ifdef CONFIG_MV64360_ECC */
stroese771e05b2004-12-16 18:21:17 +00001565
1566 /* first, use the SPD to get info about the SDRAM/ DDRRAM */
1567
1568 /* check the NHR bit and skip mem init if it's already done */
1569 nhr = get_hid0() & (1 << 16);
1570
1571 if (nhr) {
1572 printf("Skipping SD- DDRRAM setup due to NHR bit being set\n");
1573 } else {
1574 /* DIMM0 */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001575 (void)check_dimm(0, &dimmInfo1);
stroese771e05b2004-12-16 18:21:17 +00001576
1577 /* DIMM1 */
Wolfgang Denk2595fdd2011-11-09 09:29:06 +00001578 (void)check_dimm(1, &dimmInfo2);
stroese771e05b2004-12-16 18:21:17 +00001579
1580 memory_map_bank(0, 0, 0);
1581 memory_map_bank(1, 0, 0);
1582 memory_map_bank(2, 0, 0);
1583 memory_map_bank(3, 0, 0);
1584
1585 if (dimmInfo1.numOfModuleBanks && setup_sdram(&dimmInfo1)) {
1586 printf("Setup for DIMM1 failed.\n");
1587 }
1588
1589 if (dimmInfo2.numOfModuleBanks && setup_sdram(&dimmInfo2)) {
1590 printf("Setup for DIMM2 failed.\n");
1591 }
1592
1593 /* set the NHR bit */
1594 set_hid0(get_hid0() | (1 << 16));
1595 }
1596 /* next, size the SDRAM banks */
1597
1598 realsize = total = 0;
1599 check = GB/4;
1600 if (dimmInfo1.numOfModuleBanks > 0) {checkbank[0] = 1; printf("-- DIMM1 has 1 bank\n");}
1601 if (dimmInfo1.numOfModuleBanks > 1) {checkbank[1] = 1; printf("-- DIMM1 has 2 banks\n");}
1602 if (dimmInfo1.numOfModuleBanks > 2)
1603 printf("Error, SPD claims DIMM1 has >2 banks\n");
1604
1605 if (dimmInfo2.numOfModuleBanks > 0) {checkbank[2] = 1; printf("-- DIMM2 has 1 bank\n");}
1606 if (dimmInfo2.numOfModuleBanks > 1) {checkbank[3] = 1; printf("-- DIMM2 has 2 banks\n");}
1607 if (dimmInfo2.numOfModuleBanks > 2)
1608 printf("Error, SPD claims DIMM2 has >2 banks\n");
1609
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001610 for (bank_no = 0; bank_no < CONFIG_SYS_DRAM_BANKS; bank_no++) {
stroese771e05b2004-12-16 18:21:17 +00001611 /* skip over banks that are not populated */
1612 if (! checkbank[bank_no])
1613 continue;
1614
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001615 if ((total + check) > CONFIG_SYS_GT_REGS)
1616 check = CONFIG_SYS_GT_REGS - total;
stroese771e05b2004-12-16 18:21:17 +00001617
1618 memory_map_bank(bank_no, total, check);
1619 realsize = dram_size((long int *)total, check);
1620 memory_map_bank(bank_no, total, realsize);
1621
Reinhard Arlt0738e242010-04-13 09:59:09 +02001622#ifdef CONFIG_MV64360_ECC
1623 if (((dimmInfo1.errorCheckType != 0) &&
1624 ((dimmInfo2.errorCheckType != 0) ||
1625 (dimmInfo2.numOfModuleBanks == 0))) &&
1626 (CPCI750_ECC_TEST)) {
1627 printf("ECC Initialization of Bank %d:", bank_no);
1628 mem_space_attr = ((~(BIT0 << bank_no)) & 0xf) << 8;
1629 mv_dma_set_memory_space(0, 0, mem_space_attr, total,
1630 realsize);
1631 for (dest = total; dest < total + realsize;
1632 dest += _8M) {
1633 mv_dma_transfer(0, total, dest, _8M,
1634 BIT8 | /* DMA_DTL_128BYTES */
1635 BIT3 | /* DMA_HOLD_SOURCE_ADDR */
1636 BIT11); /* DMA_BLOCK_TRANSFER_MODE */
1637 while (mv_dma_is_channel_active(0))
1638 ;
1639 }
1640 printf(" PASS\n");
1641 }
1642#endif /* of ifdef CONFIG_MV64360_ECC */
1643
stroese771e05b2004-12-16 18:21:17 +00001644 total += realsize;
1645 }
1646
1647/* Setup Ethernet DMA Adress window to DRAM Area */
wdenkefe2a4d2004-12-16 21:44:03 +00001648 return(total);
stroese771e05b2004-12-16 18:21:17 +00001649}
1650
1651/* ***************************************************************************************
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001652! * SDRAM INIT *
1653! * This procedure detect all Sdram types: 64, 128, 256, 512 Mbit, 1Gbit and 2Gb *
1654! * This procedure fits only the Atlantis *
1655! * *
stroese771e05b2004-12-16 18:21:17 +00001656! *************************************************************************************** */
1657
1658
1659/* ***************************************************************************************
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001660! * DFCDL initialize MV643xx Design Considerations *
1661! * *
stroese771e05b2004-12-16 18:21:17 +00001662! *************************************************************************************** */
wdenkefe2a4d2004-12-16 21:44:03 +00001663int set_dfcdlInit (void)
stroese771e05b2004-12-16 18:21:17 +00001664{
wdenkefe2a4d2004-12-16 21:44:03 +00001665 int i;
1666 unsigned int dfcdl_word = 0x0000014f;
1667
1668 for (i = 0; i < 64; i++) {
1669 GT_REG_WRITE (SRAM_DATA0, dfcdl_word);
1670 }
1671 GT_REG_WRITE (DFCDL_CONFIG0, 0x00300000); /* enable dynamic delay line updating */
stroese771e05b2004-12-16 18:21:17 +00001672
1673
wdenkefe2a4d2004-12-16 21:44:03 +00001674 return (0);
stroese771e05b2004-12-16 18:21:17 +00001675}
Reinhard Arlt0738e242010-04-13 09:59:09 +02001676
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001677int do_show_ecc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Reinhard Arlt0738e242010-04-13 09:59:09 +02001678{
1679 unsigned int ecc_counter;
1680 unsigned int ecc_addr;
1681
1682 GT_REG_READ(0x1458, &ecc_counter);
1683 GT_REG_READ(0x1450, &ecc_addr);
1684 GT_REG_WRITE(0x1450, 0);
1685
1686 printf("Error Counter since Reset: %8d\n", ecc_counter);
1687 printf("Last error address :0x%08x (" , ecc_addr & 0xfffffff8);
1688 if (ecc_addr & 0x01)
1689 printf("double");
1690 else
1691 printf("single");
1692 printf(" bit) at DDR-RAM CS#%d\n", ((ecc_addr & 0x6) >> 1));
1693
1694 return 0;
1695}
1696
1697
1698U_BOOT_CMD(
1699 show_ecc, 1, 1, do_show_ecc,
1700 "Show Marvell MV64360 ECC Info",
1701 "Show Marvell MV64360 ECC Counter and last error."
1702);