2 * arch/powerpc/cpu/ppc4xx/44x_spd_ddr2.c
3 * This SPD SDRAM detection code supports AMCC PPC44x cpu's with a
4 * DDR2 controller (non Denali Core). Those currently are:
7 * 440/460: 440SP/440SPe/460EX/460GT
9 * Copyright (c) 2008 Nuovation System Designs, LLC
10 * Grant Erickson <gerickson@nuovations.com>
12 * (C) Copyright 2007-2009
13 * Stefan Roese, DENX Software Engineering, sr@denx.de.
15 * COPYRIGHT AMCC CORPORATION 2004
17 * SPDX-License-Identifier: GPL-2.0+
20 /* define DEBUG for debugging output (obviously ;-)) */
27 #include <asm/ppc4xx.h>
30 #include <asm/processor.h>
32 #include <asm/cache.h>
36 #define PPC4xx_IBM_DDR2_DUMP_REGISTER(mnemonic) \
39 mfsdram(SDRAM_##mnemonic, data); \
40 printf("%20s[%02x] = 0x%08X\n", \
41 "SDRAM_" #mnemonic, SDRAM_##mnemonic, data); \
44 #define PPC4xx_IBM_DDR2_DUMP_MQ_REGISTER(mnemonic) \
47 data = mfdcr(SDRAM_##mnemonic); \
48 printf("%20s[%02x] = 0x%08X\n", \
49 "SDRAM_" #mnemonic, SDRAM_##mnemonic, data); \
52 static void update_rdcc(void)
57 * Complete RDSS configuration as mentioned on page 7 of the AMCC
58 * PowerPC440SP/SPe DDR2 application note:
59 * "DDR1/DDR2 Initialization Sequence and Dynamic Tuning"
61 * Or item #10 "10. Complete RDSS configuration" in chapter
62 * "22.2.9 SDRAM Initialization" of AMCC PPC460EX/EXr/GT users
65 mfsdram(SDRAM_RTSR, val);
66 if ((val & SDRAM_RTSR_TRK1SM_MASK) == SDRAM_RTSR_TRK1SM_ATPLS1) {
67 mfsdram(SDRAM_RDCC, val);
68 if ((val & SDRAM_RDCC_RDSS_MASK) != SDRAM_RDCC_RDSS_T4) {
70 mtsdram(SDRAM_RDCC, val);
75 #if defined(CONFIG_440)
77 * This DDR2 setup code can dynamically setup the TLB entries for the DDR2
78 * memory region. Right now the cache should still be disabled in U-Boot
79 * because of the EMAC driver, that need its buffer descriptor to be located
80 * in non cached memory.
82 * If at some time this restriction doesn't apply anymore, just define
83 * CONFIG_4xx_DCACHE in the board config file and this code should setup
84 * everything correctly.
86 #ifdef CONFIG_4xx_DCACHE
87 /* enable caching on SDRAM */
88 #define MY_TLB_WORD2_I_ENABLE 0
90 /* disable caching on SDRAM */
91 #define MY_TLB_WORD2_I_ENABLE TLB_WORD2_I_ENABLE
92 #endif /* CONFIG_4xx_DCACHE */
94 void dcbz_area(u32 start_address, u32 num_bytes);
95 #endif /* CONFIG_440 */
100 #define MULDIV64(m1, m2, d) (u32)(((u64)(m1) * (u64)(m2)) / (u64)(d))
102 /*-----------------------------------------------------------------------------+
104 *-----------------------------------------------------------------------------*/
105 phys_size_t sdram_memsize(void)
107 phys_size_t mem_size;
108 unsigned long mcopt2;
109 unsigned long mcstat;
116 mfsdram(SDRAM_MCOPT2, mcopt2);
117 mfsdram(SDRAM_MCSTAT, mcstat);
119 /* DDR controller must be enabled and not in self-refresh. */
120 /* Otherwise memsize is zero. */
121 if (((mcopt2 & SDRAM_MCOPT2_DCEN_MASK) == SDRAM_MCOPT2_DCEN_ENABLE)
122 && ((mcopt2 & SDRAM_MCOPT2_SREN_MASK) == SDRAM_MCOPT2_SREN_EXIT)
123 && ((mcstat & (SDRAM_MCSTAT_MIC_MASK | SDRAM_MCSTAT_SRMS_MASK))
124 == (SDRAM_MCSTAT_MIC_COMP | SDRAM_MCSTAT_SRMS_NOT_SF))) {
125 for (i = 0; i < MAXBXCF; i++) {
126 mfsdram(SDRAM_MB0CF + (i << 2), mb0cf);
128 if ((mb0cf & SDRAM_BXCF_M_BE_MASK) == SDRAM_BXCF_M_BE_ENABLE) {
129 #if defined(CONFIG_440)
130 sdsz = mfdcr_any(SDRAM_R0BAS + i) & SDRAM_RXBAS_SDSZ_MASK;
132 sdsz = mb0cf & SDRAM_RXBAS_SDSZ_MASK;
135 case SDRAM_RXBAS_SDSZ_8:
138 case SDRAM_RXBAS_SDSZ_16:
141 case SDRAM_RXBAS_SDSZ_32:
144 case SDRAM_RXBAS_SDSZ_64:
147 case SDRAM_RXBAS_SDSZ_128:
150 case SDRAM_RXBAS_SDSZ_256:
153 case SDRAM_RXBAS_SDSZ_512:
156 case SDRAM_RXBAS_SDSZ_1024:
159 case SDRAM_RXBAS_SDSZ_2048:
162 case SDRAM_RXBAS_SDSZ_4096:
166 printf("WARNING: Unsupported bank size (SDSZ=0x%lx)!\n"
175 return mem_size << 20;
178 /*-----------------------------------------------------------------------------+
180 *-----------------------------------------------------------------------------*/
181 static unsigned long is_ecc_enabled(void)
185 mfsdram(SDRAM_MCOPT1, val);
187 return SDRAM_MCOPT1_MCHK_CHK_DECODE(val);
190 /*-----------------------------------------------------------------------------+
192 *-----------------------------------------------------------------------------*/
193 void board_add_ram_info(int use_default)
195 PPC4xx_SYS_INFO board_cfg;
198 if (is_ecc_enabled())
203 get_sys_info(&board_cfg);
205 #if defined(CONFIG_405EX)
206 val = board_cfg.freqPLB;
208 mfsdr(SDR0_DDR0, val);
209 val = MULDIV64((board_cfg.freqPLB), SDR0_DDR0_DDRM_DECODE(val), 1);
211 printf(" enabled, %d MHz", (val * 2) / 1000000);
213 mfsdram(SDRAM_MMODE, val);
214 val = (val & SDRAM_MMODE_DCL_MASK) >> 4;
215 printf(", CL%d)", val);
218 #if defined(CONFIG_SPD_EEPROM)
220 /*-----------------------------------------------------------------------------+
222 *-----------------------------------------------------------------------------*/
228 #define MAX_SPD_BYTES 256 /* Max number of bytes on the DIMM's SPD EEPROM */
230 #define ONE_BILLION 1000000000
232 #define CMD_NOP (7 << 19)
233 #define CMD_PRECHARGE (2 << 19)
234 #define CMD_REFRESH (1 << 19)
235 #define CMD_EMR (0 << 19)
236 #define CMD_READ (5 << 19)
237 #define CMD_WRITE (4 << 19)
239 #define SELECT_MR (0 << 16)
240 #define SELECT_EMR (1 << 16)
241 #define SELECT_EMR2 (2 << 16)
242 #define SELECT_EMR3 (3 << 16)
245 #define DLL_RESET 0x00000100
247 #define WRITE_RECOV_2 (1 << 9)
248 #define WRITE_RECOV_3 (2 << 9)
249 #define WRITE_RECOV_4 (3 << 9)
250 #define WRITE_RECOV_5 (4 << 9)
251 #define WRITE_RECOV_6 (5 << 9)
253 #define BURST_LEN_4 0x00000002
256 #define ODT_0_OHM 0x00000000
257 #define ODT_50_OHM 0x00000044
258 #define ODT_75_OHM 0x00000004
259 #define ODT_150_OHM 0x00000040
261 #define ODS_FULL 0x00000000
262 #define ODS_REDUCED 0x00000002
263 #define OCD_CALIB_DEF 0x00000380
265 /* defines for ODT (On Die Termination) of the 440SP(e) DDR2 controller */
266 #define ODT_EB0R (0x80000000 >> 8)
267 #define ODT_EB0W (0x80000000 >> 7)
268 #define CALC_ODT_R(n) (ODT_EB0R << (n << 1))
269 #define CALC_ODT_W(n) (ODT_EB0W << (n << 1))
270 #define CALC_ODT_RW(n) (CALC_ODT_R(n) | CALC_ODT_W(n))
272 /* Defines for the Read Cycle Delay test */
273 #define NUMMEMTESTS 8
274 #define NUMMEMWORDS 8
275 #define NUMLOOPS 64 /* memory test loops */
278 * Newer PPC's like 440SPe, 460EX/GT can be equipped with more than 2GB of SDRAM.
279 * To support such configurations, we "only" map the first 2GB via the TLB's. We
280 * need some free virtual address space for the remaining peripherals like, SoC
281 * devices, FLASH etc.
283 * Note that ECC is currently not supported on configurations with more than 2GB
284 * SDRAM. This is because we only map the first 2GB on such systems, and therefore
285 * the ECC parity byte of the remaining area can't be written.
289 * Board-specific Platform code can reimplement spd_ddr_init_hang () if needed
291 void __spd_ddr_init_hang (void)
295 void spd_ddr_init_hang (void) __attribute__((weak, alias("__spd_ddr_init_hang")));
298 * To provide an interface for board specific config values in this common
299 * DDR setup code, we implement he "weak" default functions here. They return
300 * the default value back to the caller.
302 * Please see include/configs/yucca.h for an example fora board specific
305 u32 __ddr_wrdtr(u32 default_val)
309 u32 ddr_wrdtr(u32) __attribute__((weak, alias("__ddr_wrdtr")));
311 u32 __ddr_clktr(u32 default_val)
315 u32 ddr_clktr(u32) __attribute__((weak, alias("__ddr_clktr")));
318 /* Private Structure Definitions */
320 /* enum only to ease code for cas latency setting */
321 typedef enum ddr_cas_id {
329 /*-----------------------------------------------------------------------------+
331 *-----------------------------------------------------------------------------*/
332 static void get_spd_info(unsigned long *dimm_populated,
333 unsigned char *iic0_dimm_addr,
334 unsigned long num_dimm_banks);
335 static void check_mem_type(unsigned long *dimm_populated,
336 unsigned char *iic0_dimm_addr,
337 unsigned long num_dimm_banks);
338 static void check_frequency(unsigned long *dimm_populated,
339 unsigned char *iic0_dimm_addr,
340 unsigned long num_dimm_banks);
341 static void check_rank_number(unsigned long *dimm_populated,
342 unsigned char *iic0_dimm_addr,
343 unsigned long num_dimm_banks);
344 static void check_voltage_type(unsigned long *dimm_populated,
345 unsigned char *iic0_dimm_addr,
346 unsigned long num_dimm_banks);
347 static void program_memory_queue(unsigned long *dimm_populated,
348 unsigned char *iic0_dimm_addr,
349 unsigned long num_dimm_banks);
350 static void program_codt(unsigned long *dimm_populated,
351 unsigned char *iic0_dimm_addr,
352 unsigned long num_dimm_banks);
353 static void program_mode(unsigned long *dimm_populated,
354 unsigned char *iic0_dimm_addr,
355 unsigned long num_dimm_banks,
356 ddr_cas_id_t *selected_cas,
357 int *write_recovery);
358 static void program_tr(unsigned long *dimm_populated,
359 unsigned char *iic0_dimm_addr,
360 unsigned long num_dimm_banks);
361 static void program_rtr(unsigned long *dimm_populated,
362 unsigned char *iic0_dimm_addr,
363 unsigned long num_dimm_banks);
364 static void program_bxcf(unsigned long *dimm_populated,
365 unsigned char *iic0_dimm_addr,
366 unsigned long num_dimm_banks);
367 static void program_copt1(unsigned long *dimm_populated,
368 unsigned char *iic0_dimm_addr,
369 unsigned long num_dimm_banks);
370 static void program_initplr(unsigned long *dimm_populated,
371 unsigned char *iic0_dimm_addr,
372 unsigned long num_dimm_banks,
373 ddr_cas_id_t selected_cas,
375 #ifdef CONFIG_DDR_ECC
376 static void program_ecc(unsigned long *dimm_populated,
377 unsigned char *iic0_dimm_addr,
378 unsigned long num_dimm_banks,
379 unsigned long tlb_word2_i_value);
381 #if !defined(CONFIG_PPC4xx_DDR_AUTOCALIBRATION)
382 static void program_DQS_calibration(unsigned long *dimm_populated,
383 unsigned char *iic0_dimm_addr,
384 unsigned long num_dimm_banks);
385 #ifdef HARD_CODED_DQS /* calibration test with hardvalues */
386 static void test(void);
388 static void DQS_calibration_process(void);
392 static unsigned char spd_read(uchar chip, uint addr)
394 unsigned char data[2];
396 if (i2c_probe(chip) == 0)
397 if (i2c_read(chip, addr, 1, data, 1) == 0)
403 /*-----------------------------------------------------------------------------+
404 * initdram. Initializes the 440SP Memory Queue and DDR SDRAM controller.
405 * Note: This routine runs from flash with a stack set up in the chip's
406 * sram space. It is important that the routine does not require .sbss, .bss or
407 * .data sections. It also cannot call routines that require these sections.
408 *-----------------------------------------------------------------------------*/
409 /*-----------------------------------------------------------------------------
411 * Description: Configures SDRAM memory banks for DDR operation.
412 * Auto Memory Configuration option reads the DDR SDRAM EEPROMs
413 * via the IIC bus and then configures the DDR SDRAM memory
414 * banks appropriately. If Auto Memory Configuration is
415 * not used, it is assumed that no DIMM is plugged
416 *-----------------------------------------------------------------------------*/
417 phys_size_t initdram(int board_type)
419 unsigned char iic0_dimm_addr[] = SPD_EEPROM_ADDRESS;
420 unsigned long dimm_populated[MAXDIMMS] = {SDRAM_NONE, SDRAM_NONE};
421 unsigned long num_dimm_banks; /* on board dimm banks */
423 ddr_cas_id_t selected_cas = DDR_CAS_5; /* preset to silence compiler */
425 phys_size_t dram_size = 0;
427 if (IS_ENABLED(CONFIG_SYS_RAMBOOT)) {
429 * Reduce RAM size to avoid overwriting memory used by
430 * current stack? Not sure what is happening.
432 return sdram_memsize() / 2;
435 num_dimm_banks = sizeof(iic0_dimm_addr);
437 /*------------------------------------------------------------------
438 * Reset the DDR-SDRAM controller.
439 *-----------------------------------------------------------------*/
440 mtsdr(SDR0_SRST, SDR0_SRST0_DMC);
441 mtsdr(SDR0_SRST, 0x00000000);
444 * Make sure I2C controller is initialized
448 /* switch to correct I2C bus */
449 i2c_set_bus_num(CONFIG_SYS_SPD_BUS_NUM);
451 /*------------------------------------------------------------------
452 * Clear out the serial presence detect buffers.
453 * Perform IIC reads from the dimm. Fill in the spds.
454 * Check to see if the dimm slots are populated
455 *-----------------------------------------------------------------*/
456 get_spd_info(dimm_populated, iic0_dimm_addr, num_dimm_banks);
458 /*------------------------------------------------------------------
459 * Check the memory type for the dimms plugged.
460 *-----------------------------------------------------------------*/
461 check_mem_type(dimm_populated, iic0_dimm_addr, num_dimm_banks);
463 /*------------------------------------------------------------------
464 * Check the frequency supported for the dimms plugged.
465 *-----------------------------------------------------------------*/
466 check_frequency(dimm_populated, iic0_dimm_addr, num_dimm_banks);
468 /*------------------------------------------------------------------
469 * Check the total rank number.
470 *-----------------------------------------------------------------*/
471 check_rank_number(dimm_populated, iic0_dimm_addr, num_dimm_banks);
473 /*------------------------------------------------------------------
474 * Check the voltage type for the dimms plugged.
475 *-----------------------------------------------------------------*/
476 check_voltage_type(dimm_populated, iic0_dimm_addr, num_dimm_banks);
478 /*------------------------------------------------------------------
479 * Program SDRAM controller options 2 register
480 * Except Enabling of the memory controller.
481 *-----------------------------------------------------------------*/
482 mfsdram(SDRAM_MCOPT2, val);
483 mtsdram(SDRAM_MCOPT2,
485 ~(SDRAM_MCOPT2_SREN_MASK | SDRAM_MCOPT2_PMEN_MASK |
486 SDRAM_MCOPT2_IPTR_MASK | SDRAM_MCOPT2_XSRP_MASK |
487 SDRAM_MCOPT2_ISIE_MASK))
488 | (SDRAM_MCOPT2_SREN_ENTER | SDRAM_MCOPT2_PMEN_DISABLE |
489 SDRAM_MCOPT2_IPTR_IDLE | SDRAM_MCOPT2_XSRP_ALLOW |
490 SDRAM_MCOPT2_ISIE_ENABLE));
492 /*------------------------------------------------------------------
493 * Program SDRAM controller options 1 register
494 * Note: Does not enable the memory controller.
495 *-----------------------------------------------------------------*/
496 program_copt1(dimm_populated, iic0_dimm_addr, num_dimm_banks);
498 /*------------------------------------------------------------------
499 * Set the SDRAM Controller On Die Termination Register
500 *-----------------------------------------------------------------*/
501 program_codt(dimm_populated, iic0_dimm_addr, num_dimm_banks);
503 /*------------------------------------------------------------------
504 * Program SDRAM refresh register.
505 *-----------------------------------------------------------------*/
506 program_rtr(dimm_populated, iic0_dimm_addr, num_dimm_banks);
508 /*------------------------------------------------------------------
509 * Program SDRAM mode register.
510 *-----------------------------------------------------------------*/
511 program_mode(dimm_populated, iic0_dimm_addr, num_dimm_banks,
512 &selected_cas, &write_recovery);
514 /*------------------------------------------------------------------
515 * Set the SDRAM Write Data/DM/DQS Clock Timing Reg
516 *-----------------------------------------------------------------*/
517 mfsdram(SDRAM_WRDTR, val);
518 mtsdram(SDRAM_WRDTR, (val & ~(SDRAM_WRDTR_LLWP_MASK | SDRAM_WRDTR_WTR_MASK)) |
519 ddr_wrdtr(SDRAM_WRDTR_LLWP_1_CYC | SDRAM_WRDTR_WTR_90_DEG_ADV));
521 /*------------------------------------------------------------------
522 * Set the SDRAM Clock Timing Register
523 *-----------------------------------------------------------------*/
524 mfsdram(SDRAM_CLKTR, val);
525 mtsdram(SDRAM_CLKTR, (val & ~SDRAM_CLKTR_CLKP_MASK) |
526 ddr_clktr(SDRAM_CLKTR_CLKP_0_DEG));
528 /*------------------------------------------------------------------
529 * Program the BxCF registers.
530 *-----------------------------------------------------------------*/
531 program_bxcf(dimm_populated, iic0_dimm_addr, num_dimm_banks);
533 /*------------------------------------------------------------------
534 * Program SDRAM timing registers.
535 *-----------------------------------------------------------------*/
536 program_tr(dimm_populated, iic0_dimm_addr, num_dimm_banks);
538 /*------------------------------------------------------------------
539 * Set the Extended Mode register
540 *-----------------------------------------------------------------*/
541 mfsdram(SDRAM_MEMODE, val);
542 mtsdram(SDRAM_MEMODE,
543 (val & ~(SDRAM_MEMODE_DIC_MASK | SDRAM_MEMODE_DLL_MASK |
544 SDRAM_MEMODE_RTT_MASK | SDRAM_MEMODE_DQS_MASK)) |
545 (SDRAM_MEMODE_DIC_NORMAL | SDRAM_MEMODE_DLL_ENABLE
546 | SDRAM_MEMODE_RTT_150OHM | SDRAM_MEMODE_DQS_ENABLE));
548 /*------------------------------------------------------------------
549 * Program Initialization preload registers.
550 *-----------------------------------------------------------------*/
551 program_initplr(dimm_populated, iic0_dimm_addr, num_dimm_banks,
552 selected_cas, write_recovery);
554 /*------------------------------------------------------------------
555 * Delay to ensure 200usec have elapsed since reset.
556 *-----------------------------------------------------------------*/
559 /*------------------------------------------------------------------
560 * Set the memory queue core base addr.
561 *-----------------------------------------------------------------*/
562 program_memory_queue(dimm_populated, iic0_dimm_addr, num_dimm_banks);
564 /*------------------------------------------------------------------
565 * Program SDRAM controller options 2 register
566 * Enable the memory controller.
567 *-----------------------------------------------------------------*/
568 mfsdram(SDRAM_MCOPT2, val);
569 mtsdram(SDRAM_MCOPT2,
570 (val & ~(SDRAM_MCOPT2_SREN_MASK | SDRAM_MCOPT2_DCEN_MASK |
571 SDRAM_MCOPT2_IPTR_MASK | SDRAM_MCOPT2_ISIE_MASK)) |
572 SDRAM_MCOPT2_IPTR_EXECUTE);
574 /*------------------------------------------------------------------
575 * Wait for IPTR_EXECUTE init sequence to complete.
576 *-----------------------------------------------------------------*/
578 mfsdram(SDRAM_MCSTAT, val);
579 } while ((val & SDRAM_MCSTAT_MIC_MASK) == SDRAM_MCSTAT_MIC_NOTCOMP);
581 /* enable the controller only after init sequence completes */
582 mfsdram(SDRAM_MCOPT2, val);
583 mtsdram(SDRAM_MCOPT2, (val | SDRAM_MCOPT2_DCEN_ENABLE));
585 /* Make sure delay-line calibration is done before proceeding */
587 mfsdram(SDRAM_DLCR, val);
588 } while (!(val & SDRAM_DLCR_DLCS_COMPLETE));
590 /* get installed memory size */
591 dram_size = sdram_memsize();
596 if (dram_size > CONFIG_MAX_MEM_MAPPED)
597 dram_size = CONFIG_MAX_MEM_MAPPED;
599 /* and program tlb entries for this size (dynamic) */
602 * Program TLB entries with caches enabled, for best performace
603 * while auto-calibrating and ECC generation
605 program_tlb(0, 0, dram_size, 0);
607 /*------------------------------------------------------------------
609 *-----------------------------------------------------------------*/
610 #if defined(CONFIG_PPC4xx_DDR_AUTOCALIBRATION)
611 DQS_autocalibration();
613 program_DQS_calibration(dimm_populated, iic0_dimm_addr, num_dimm_banks);
616 * Now complete RDSS configuration as mentioned on page 7 of the AMCC
617 * PowerPC440SP/SPe DDR2 application note:
618 * "DDR1/DDR2 Initialization Sequence and Dynamic Tuning"
622 #ifdef CONFIG_DDR_ECC
623 /*------------------------------------------------------------------
624 * If ecc is enabled, initialize the parity bits.
625 *-----------------------------------------------------------------*/
626 program_ecc(dimm_populated, iic0_dimm_addr, num_dimm_banks, 0);
630 * Flush the dcache before removing the TLB with caches
631 * enabled. Otherwise this might lead to problems later on,
632 * e.g. while booting Linux (as seen on ICON-440SPe).
637 * Now after initialization (auto-calibration and ECC generation)
638 * remove the TLB entries with caches enabled and program again with
639 * desired cache functionality
641 remove_tlb(0, dram_size);
642 program_tlb(0, 0, dram_size, MY_TLB_WORD2_I_ENABLE);
644 ppc4xx_ibm_ddr2_register_dump();
647 * Clear potential errors resulting from auto-calibration.
648 * If not done, then we could get an interrupt later on when
649 * exceptions are enabled.
651 set_mcsr(get_mcsr());
653 return sdram_memsize();
656 static void get_spd_info(unsigned long *dimm_populated,
657 unsigned char *iic0_dimm_addr,
658 unsigned long num_dimm_banks)
660 unsigned long dimm_num;
661 unsigned long dimm_found;
662 unsigned char num_of_bytes;
663 unsigned char total_size;
666 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
670 num_of_bytes = spd_read(iic0_dimm_addr[dimm_num], 0);
671 debug("\nspd_read(0x%x) returned %d\n",
672 iic0_dimm_addr[dimm_num], num_of_bytes);
673 total_size = spd_read(iic0_dimm_addr[dimm_num], 1);
674 debug("spd_read(0x%x) returned %d\n",
675 iic0_dimm_addr[dimm_num], total_size);
677 if ((num_of_bytes != 0) && (total_size != 0)) {
678 dimm_populated[dimm_num] = true;
680 debug("DIMM slot %lu: populated\n", dimm_num);
682 dimm_populated[dimm_num] = false;
683 debug("DIMM slot %lu: Not populated\n", dimm_num);
687 if (dimm_found == false) {
688 printf("ERROR - No memory installed. Install a DDR-SDRAM DIMM.\n\n");
689 spd_ddr_init_hang ();
694 /*------------------------------------------------------------------
695 * For the memory DIMMs installed, this routine verifies that they
696 * really are DDR specific DIMMs.
697 *-----------------------------------------------------------------*/
698 static void check_mem_type(unsigned long *dimm_populated,
699 unsigned char *iic0_dimm_addr,
700 unsigned long num_dimm_banks)
702 unsigned long dimm_num;
703 unsigned long dimm_type;
705 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
706 if (dimm_populated[dimm_num] == true) {
707 dimm_type = spd_read(iic0_dimm_addr[dimm_num], 2);
710 printf("ERROR: Standard Fast Page Mode DRAM DIMM detected in "
711 "slot %d.\n", (unsigned int)dimm_num);
712 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
713 printf("Replace the DIMM module with a supported DIMM.\n\n");
714 spd_ddr_init_hang ();
717 printf("ERROR: EDO DIMM detected in slot %d.\n",
718 (unsigned int)dimm_num);
719 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
720 printf("Replace the DIMM module with a supported DIMM.\n\n");
721 spd_ddr_init_hang ();
724 printf("ERROR: Pipelined Nibble DIMM detected in slot %d.\n",
725 (unsigned int)dimm_num);
726 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
727 printf("Replace the DIMM module with a supported DIMM.\n\n");
728 spd_ddr_init_hang ();
731 printf("ERROR: SDRAM DIMM detected in slot %d.\n",
732 (unsigned int)dimm_num);
733 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
734 printf("Replace the DIMM module with a supported DIMM.\n\n");
735 spd_ddr_init_hang ();
738 printf("ERROR: Multiplexed ROM DIMM detected in slot %d.\n",
739 (unsigned int)dimm_num);
740 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
741 printf("Replace the DIMM module with a supported DIMM.\n\n");
742 spd_ddr_init_hang ();
745 printf("ERROR: SGRAM DIMM detected in slot %d.\n",
746 (unsigned int)dimm_num);
747 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
748 printf("Replace the DIMM module with a supported DIMM.\n\n");
749 spd_ddr_init_hang ();
752 debug("DIMM slot %lu: DDR1 SDRAM detected\n", dimm_num);
753 dimm_populated[dimm_num] = SDRAM_DDR1;
756 debug("DIMM slot %lu: DDR2 SDRAM detected\n", dimm_num);
757 dimm_populated[dimm_num] = SDRAM_DDR2;
760 printf("ERROR: Unknown DIMM detected in slot %d.\n",
761 (unsigned int)dimm_num);
762 printf("Only DDR1 and DDR2 SDRAM DIMMs are supported.\n");
763 printf("Replace the DIMM module with a supported DIMM.\n\n");
764 spd_ddr_init_hang ();
769 for (dimm_num = 1; dimm_num < num_dimm_banks; dimm_num++) {
770 if ((dimm_populated[dimm_num-1] != SDRAM_NONE)
771 && (dimm_populated[dimm_num] != SDRAM_NONE)
772 && (dimm_populated[dimm_num-1] != dimm_populated[dimm_num])) {
773 printf("ERROR: DIMM's DDR1 and DDR2 type can not be mixed.\n");
774 spd_ddr_init_hang ();
779 /*------------------------------------------------------------------
780 * For the memory DIMMs installed, this routine verifies that
781 * frequency previously calculated is supported.
782 *-----------------------------------------------------------------*/
783 static void check_frequency(unsigned long *dimm_populated,
784 unsigned char *iic0_dimm_addr,
785 unsigned long num_dimm_banks)
787 unsigned long dimm_num;
788 unsigned long tcyc_reg;
789 unsigned long cycle_time;
790 unsigned long calc_cycle_time;
791 unsigned long sdram_freq;
792 unsigned long sdr_ddrpll;
793 PPC4xx_SYS_INFO board_cfg;
795 /*------------------------------------------------------------------
796 * Get the board configuration info.
797 *-----------------------------------------------------------------*/
798 get_sys_info(&board_cfg);
800 mfsdr(SDR0_DDR0, sdr_ddrpll);
801 sdram_freq = ((board_cfg.freqPLB) * SDR0_DDR0_DDRM_DECODE(sdr_ddrpll));
804 * calc_cycle_time is calculated from DDR frequency set by board/chip
805 * and is expressed in multiple of 10 picoseconds
806 * to match the way DIMM cycle time is calculated below.
808 calc_cycle_time = MULDIV64(ONE_BILLION, 100, sdram_freq);
810 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
811 if (dimm_populated[dimm_num] != SDRAM_NONE) {
812 tcyc_reg = spd_read(iic0_dimm_addr[dimm_num], 9);
814 * Byte 9, Cycle time for CAS Latency=X, is split into two nibbles:
815 * the higher order nibble (bits 4-7) designates the cycle time
816 * to a granularity of 1ns;
817 * the value presented by the lower order nibble (bits 0-3)
818 * has a granularity of .1ns and is added to the value designated
819 * by the higher nibble. In addition, four lines of the lower order
820 * nibble are assigned to support +.25,+.33, +.66 and +.75.
822 /* Convert from hex to decimal */
823 if ((tcyc_reg & 0x0F) == 0x0D)
824 cycle_time = (((tcyc_reg & 0xF0) >> 4) * 100) + 75;
825 else if ((tcyc_reg & 0x0F) == 0x0C)
826 cycle_time = (((tcyc_reg & 0xF0) >> 4) * 100) + 66;
827 else if ((tcyc_reg & 0x0F) == 0x0B)
828 cycle_time = (((tcyc_reg & 0xF0) >> 4) * 100) + 33;
829 else if ((tcyc_reg & 0x0F) == 0x0A)
830 cycle_time = (((tcyc_reg & 0xF0) >> 4) * 100) + 25;
832 cycle_time = (((tcyc_reg & 0xF0) >> 4) * 100) +
833 ((tcyc_reg & 0x0F)*10);
834 debug("cycle_time=%lu [10 picoseconds]\n", cycle_time);
836 if (cycle_time > (calc_cycle_time + 10)) {
838 * the provided sdram cycle_time is too small
839 * for the available DIMM cycle_time.
840 * The additionnal 100ps is here to accept a small incertainty.
842 printf("ERROR: DRAM DIMM detected with cycle_time %d ps in "
843 "slot %d \n while calculated cycle time is %d ps.\n",
844 (unsigned int)(cycle_time*10),
845 (unsigned int)dimm_num,
846 (unsigned int)(calc_cycle_time*10));
847 printf("Replace the DIMM, or change DDR frequency via "
848 "strapping bits.\n\n");
849 spd_ddr_init_hang ();
855 /*------------------------------------------------------------------
856 * For the memory DIMMs installed, this routine verifies two
857 * ranks/banks maximum are availables.
858 *-----------------------------------------------------------------*/
859 static void check_rank_number(unsigned long *dimm_populated,
860 unsigned char *iic0_dimm_addr,
861 unsigned long num_dimm_banks)
863 unsigned long dimm_num;
864 unsigned long dimm_rank;
865 unsigned long total_rank = 0;
867 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
868 if (dimm_populated[dimm_num] != SDRAM_NONE) {
869 dimm_rank = spd_read(iic0_dimm_addr[dimm_num], 5);
870 if (((unsigned long)spd_read(iic0_dimm_addr[dimm_num], 2)) == 0x08)
871 dimm_rank = (dimm_rank & 0x0F) +1;
873 dimm_rank = dimm_rank & 0x0F;
876 if (dimm_rank > MAXRANKS) {
877 printf("ERROR: DRAM DIMM detected with %lu ranks in "
878 "slot %lu is not supported.\n", dimm_rank, dimm_num);
879 printf("Only %d ranks are supported for all DIMM.\n", MAXRANKS);
880 printf("Replace the DIMM module with a supported DIMM.\n\n");
881 spd_ddr_init_hang ();
883 total_rank += dimm_rank;
885 if (total_rank > MAXRANKS) {
886 printf("ERROR: DRAM DIMM detected with a total of %d ranks "
887 "for all slots.\n", (unsigned int)total_rank);
888 printf("Only %d ranks are supported for all DIMM.\n", MAXRANKS);
889 printf("Remove one of the DIMM modules.\n\n");
890 spd_ddr_init_hang ();
895 /*------------------------------------------------------------------
896 * only support 2.5V modules.
897 * This routine verifies this.
898 *-----------------------------------------------------------------*/
899 static void check_voltage_type(unsigned long *dimm_populated,
900 unsigned char *iic0_dimm_addr,
901 unsigned long num_dimm_banks)
903 unsigned long dimm_num;
904 unsigned long voltage_type;
906 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
907 if (dimm_populated[dimm_num] != SDRAM_NONE) {
908 voltage_type = spd_read(iic0_dimm_addr[dimm_num], 8);
909 switch (voltage_type) {
911 printf("ERROR: Only DIMMs DDR 2.5V or DDR2 1.8V are supported.\n");
912 printf("This DIMM is 5.0 Volt/TTL.\n");
913 printf("Replace the DIMM module in slot %d with a supported DIMM.\n\n",
914 (unsigned int)dimm_num);
915 spd_ddr_init_hang ();
918 printf("ERROR: Only DIMMs DDR 2.5V or DDR2 1.8V are supported.\n");
919 printf("This DIMM is LVTTL.\n");
920 printf("Replace the DIMM module in slot %d with a supported DIMM.\n\n",
921 (unsigned int)dimm_num);
922 spd_ddr_init_hang ();
925 printf("ERROR: Only DIMMs DDR 2.5V or DDR2 1.8V are supported.\n");
926 printf("This DIMM is 1.5 Volt.\n");
927 printf("Replace the DIMM module in slot %d with a supported DIMM.\n\n",
928 (unsigned int)dimm_num);
929 spd_ddr_init_hang ();
932 printf("ERROR: Only DIMMs DDR 2.5V or DDR2 1.8V are supported.\n");
933 printf("This DIMM is 3.3 Volt/TTL.\n");
934 printf("Replace the DIMM module in slot %d with a supported DIMM.\n\n",
935 (unsigned int)dimm_num);
936 spd_ddr_init_hang ();
939 /* 2.5 Voltage only for DDR1 */
942 /* 1.8 Voltage only for DDR2 */
945 printf("ERROR: Only DIMMs DDR 2.5V or DDR2 1.8V are supported.\n");
946 printf("Replace the DIMM module in slot %d with a supported DIMM.\n\n",
947 (unsigned int)dimm_num);
948 spd_ddr_init_hang ();
955 /*-----------------------------------------------------------------------------+
957 *-----------------------------------------------------------------------------*/
958 static void program_copt1(unsigned long *dimm_populated,
959 unsigned char *iic0_dimm_addr,
960 unsigned long num_dimm_banks)
962 unsigned long dimm_num;
963 unsigned long mcopt1;
964 unsigned long ecc_enabled;
965 unsigned long ecc = 0;
966 unsigned long data_width = 0;
967 unsigned long dimm_32bit;
968 unsigned long dimm_64bit;
969 unsigned long registered = 0;
970 unsigned long attribute = 0;
971 unsigned long buf0, buf1; /* TODO: code to be changed for IOP1.6 to support 4 DIMMs */
972 unsigned long bankcount;
975 #ifdef CONFIG_DDR_ECC
985 /*------------------------------------------------------------------
986 * Set memory controller options reg 1, SDRAM_MCOPT1.
987 *-----------------------------------------------------------------*/
988 mfsdram(SDRAM_MCOPT1, val);
989 mcopt1 = val & ~(SDRAM_MCOPT1_MCHK_MASK | SDRAM_MCOPT1_RDEN_MASK |
990 SDRAM_MCOPT1_PMU_MASK | SDRAM_MCOPT1_DMWD_MASK |
991 SDRAM_MCOPT1_UIOS_MASK | SDRAM_MCOPT1_BCNT_MASK |
992 SDRAM_MCOPT1_DDR_TYPE_MASK | SDRAM_MCOPT1_RWOO_MASK |
993 SDRAM_MCOPT1_WOOO_MASK | SDRAM_MCOPT1_DCOO_MASK |
994 SDRAM_MCOPT1_DREF_MASK);
996 mcopt1 |= SDRAM_MCOPT1_QDEP;
997 mcopt1 |= SDRAM_MCOPT1_PMU_OPEN;
998 mcopt1 |= SDRAM_MCOPT1_RWOO_DISABLED;
999 mcopt1 |= SDRAM_MCOPT1_WOOO_DISABLED;
1000 mcopt1 |= SDRAM_MCOPT1_DCOO_DISABLED;
1001 mcopt1 |= SDRAM_MCOPT1_DREF_NORMAL;
1003 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1004 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1005 /* test ecc support */
1006 ecc = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 11);
1007 if (ecc != 0x02) /* ecc not supported */
1008 ecc_enabled = false;
1010 /* test bank count */
1011 bankcount = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 17);
1012 if (bankcount == 0x04) /* bank count = 4 */
1013 mcopt1 |= SDRAM_MCOPT1_4_BANKS;
1014 else /* bank count = 8 */
1015 mcopt1 |= SDRAM_MCOPT1_8_BANKS;
1017 /* test for buffered/unbuffered, registered, differential clocks */
1018 registered = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 20);
1019 attribute = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 21);
1021 /* TODO: code to be changed for IOP1.6 to support 4 DIMMs */
1022 if (dimm_num == 0) {
1023 if (dimm_populated[dimm_num] == SDRAM_DDR1) /* DDR1 type */
1024 mcopt1 |= SDRAM_MCOPT1_DDR1_TYPE;
1025 if (dimm_populated[dimm_num] == SDRAM_DDR2) /* DDR2 type */
1026 mcopt1 |= SDRAM_MCOPT1_DDR2_TYPE;
1027 if (registered == 1) { /* DDR2 always buffered */
1028 /* TODO: what about above comments ? */
1029 mcopt1 |= SDRAM_MCOPT1_RDEN;
1032 /* TODO: the mask 0x02 doesn't match Samsung def for byte 21. */
1033 if ((attribute & 0x02) == 0x00) {
1034 /* buffered not supported */
1037 mcopt1 |= SDRAM_MCOPT1_RDEN;
1042 else if (dimm_num == 1) {
1043 if (dimm_populated[dimm_num] == SDRAM_DDR1) /* DDR1 type */
1044 mcopt1 |= SDRAM_MCOPT1_DDR1_TYPE;
1045 if (dimm_populated[dimm_num] == SDRAM_DDR2) /* DDR2 type */
1046 mcopt1 |= SDRAM_MCOPT1_DDR2_TYPE;
1047 if (registered == 1) {
1048 /* DDR2 always buffered */
1049 mcopt1 |= SDRAM_MCOPT1_RDEN;
1052 if ((attribute & 0x02) == 0x00) {
1053 /* buffered not supported */
1056 mcopt1 |= SDRAM_MCOPT1_RDEN;
1062 /* Note that for DDR2 the byte 7 is reserved, but OK to keep code as is. */
1063 data_width = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 6) +
1064 (((unsigned long)spd_read(iic0_dimm_addr[dimm_num], 7)) << 8);
1066 switch (data_width) {
1076 printf("WARNING: Detected a DIMM with a data width of %lu bits.\n",
1078 printf("Only DIMMs with 32 or 64 bit DDR-SDRAM widths are supported.\n");
1084 /* verify matching properties */
1085 if ((dimm_populated[0] != SDRAM_NONE) && (dimm_populated[1] != SDRAM_NONE)) {
1087 printf("ERROR: DIMM's buffered/unbuffered, registered, clocking don't match.\n");
1088 spd_ddr_init_hang ();
1092 if ((dimm_64bit == true) && (dimm_32bit == true)) {
1093 printf("ERROR: Cannot mix 32 bit and 64 bit DDR-SDRAM DIMMs together.\n");
1094 spd_ddr_init_hang ();
1095 } else if ((dimm_64bit == true) && (dimm_32bit == false)) {
1096 mcopt1 |= SDRAM_MCOPT1_DMWD_64;
1097 } else if ((dimm_64bit == false) && (dimm_32bit == true)) {
1098 mcopt1 |= SDRAM_MCOPT1_DMWD_32;
1100 printf("ERROR: Please install only 32 or 64 bit DDR-SDRAM DIMMs.\n\n");
1101 spd_ddr_init_hang ();
1104 if (ecc_enabled == true)
1105 mcopt1 |= SDRAM_MCOPT1_MCHK_GEN;
1107 mcopt1 |= SDRAM_MCOPT1_MCHK_NON;
1109 mtsdram(SDRAM_MCOPT1, mcopt1);
1112 /*-----------------------------------------------------------------------------+
1114 *-----------------------------------------------------------------------------*/
1115 static void program_codt(unsigned long *dimm_populated,
1116 unsigned char *iic0_dimm_addr,
1117 unsigned long num_dimm_banks)
1120 unsigned long modt0 = 0;
1121 unsigned long modt1 = 0;
1122 unsigned long modt2 = 0;
1123 unsigned long modt3 = 0;
1124 unsigned char dimm_num;
1125 unsigned char dimm_rank;
1126 unsigned char total_rank = 0;
1127 unsigned char total_dimm = 0;
1128 unsigned char dimm_type = 0;
1129 unsigned char firstSlot = 0;
1131 /*------------------------------------------------------------------
1132 * Set the SDRAM Controller On Die Termination Register
1133 *-----------------------------------------------------------------*/
1134 mfsdram(SDRAM_CODT, codt);
1135 codt &= ~(SDRAM_CODT_DQS_SINGLE_END | SDRAM_CODT_CKSE_SINGLE_END);
1136 codt |= SDRAM_CODT_IO_NMODE;
1138 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1139 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1140 dimm_rank = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 5);
1141 if (((unsigned long)spd_read(iic0_dimm_addr[dimm_num], 2)) == 0x08) {
1142 dimm_rank = (dimm_rank & 0x0F) + 1;
1143 dimm_type = SDRAM_DDR2;
1145 dimm_rank = dimm_rank & 0x0F;
1146 dimm_type = SDRAM_DDR1;
1149 total_rank += dimm_rank;
1151 if ((dimm_num == 0) && (total_dimm == 1))
1157 if (dimm_type == SDRAM_DDR2) {
1158 codt |= SDRAM_CODT_DQS_1_8_V_DDR2;
1159 if ((total_dimm == 1) && (firstSlot == true)) {
1160 if (total_rank == 1) { /* PUUU */
1161 codt |= CALC_ODT_R(0);
1162 modt0 = CALC_ODT_W(0);
1167 if (total_rank == 2) { /* PPUU */
1168 codt |= CALC_ODT_R(0) | CALC_ODT_R(1);
1169 modt0 = CALC_ODT_W(0) | CALC_ODT_W(1);
1174 } else if ((total_dimm == 1) && (firstSlot != true)) {
1175 if (total_rank == 1) { /* UUPU */
1176 codt |= CALC_ODT_R(2);
1179 modt2 = CALC_ODT_W(2);
1182 if (total_rank == 2) { /* UUPP */
1183 codt |= CALC_ODT_R(2) | CALC_ODT_R(3);
1186 modt2 = CALC_ODT_W(2) | CALC_ODT_W(3);
1190 if (total_dimm == 2) {
1191 if (total_rank == 2) { /* PUPU */
1192 codt |= CALC_ODT_R(0) | CALC_ODT_R(2);
1193 modt0 = CALC_ODT_RW(2);
1195 modt2 = CALC_ODT_RW(0);
1198 if (total_rank == 4) { /* PPPP */
1199 codt |= CALC_ODT_R(0) | CALC_ODT_R(1) |
1200 CALC_ODT_R(2) | CALC_ODT_R(3);
1201 modt0 = CALC_ODT_RW(2) | CALC_ODT_RW(3);
1203 modt2 = CALC_ODT_RW(0) | CALC_ODT_RW(1);
1208 codt |= SDRAM_CODT_DQS_2_5_V_DDR1;
1214 if (total_dimm == 1) {
1215 if (total_rank == 1)
1217 if (total_rank == 2)
1220 if (total_dimm == 2) {
1221 if (total_rank == 2)
1223 if (total_rank == 4)
1228 debug("nb of dimm %d\n", total_dimm);
1229 debug("nb of rank %d\n", total_rank);
1230 if (total_dimm == 1)
1231 debug("dimm in slot %d\n", firstSlot);
1233 mtsdram(SDRAM_CODT, codt);
1234 mtsdram(SDRAM_MODT0, modt0);
1235 mtsdram(SDRAM_MODT1, modt1);
1236 mtsdram(SDRAM_MODT2, modt2);
1237 mtsdram(SDRAM_MODT3, modt3);
1240 /*-----------------------------------------------------------------------------+
1242 *-----------------------------------------------------------------------------*/
1243 static void program_initplr(unsigned long *dimm_populated,
1244 unsigned char *iic0_dimm_addr,
1245 unsigned long num_dimm_banks,
1246 ddr_cas_id_t selected_cas,
1260 /******************************************************
1261 ** Assumption: if more than one DIMM, all DIMMs are the same
1262 ** as already checked in check_memory_type
1263 ******************************************************/
1265 if ((dimm_populated[0] == SDRAM_DDR1) || (dimm_populated[1] == SDRAM_DDR1)) {
1266 mtsdram(SDRAM_INITPLR0, 0x81B80000);
1267 mtsdram(SDRAM_INITPLR1, 0x81900400);
1268 mtsdram(SDRAM_INITPLR2, 0x81810000);
1269 mtsdram(SDRAM_INITPLR3, 0xff800162);
1270 mtsdram(SDRAM_INITPLR4, 0x81900400);
1271 mtsdram(SDRAM_INITPLR5, 0x86080000);
1272 mtsdram(SDRAM_INITPLR6, 0x86080000);
1273 mtsdram(SDRAM_INITPLR7, 0x81000062);
1274 } else if ((dimm_populated[0] == SDRAM_DDR2) || (dimm_populated[1] == SDRAM_DDR2)) {
1275 switch (selected_cas) {
1286 printf("ERROR: ucode error on selected_cas value %d", selected_cas);
1287 spd_ddr_init_hang ();
1293 * ToDo - Still a problem with the write recovery:
1294 * On the Corsair CM2X512-5400C4 module, setting write recovery
1295 * in the INITPLR reg to the value calculated in program_mode()
1296 * results in not correctly working DDR2 memory (crash after
1299 * So for now, set the write recovery to 3. This seems to work
1300 * on the Corair module too.
1304 switch (write_recovery) {
1318 printf("ERROR: write recovery not support (%d)", write_recovery);
1319 spd_ddr_init_hang ();
1323 wr = WRITE_RECOV_3; /* test-only, see description above */
1326 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++)
1327 if (dimm_populated[dimm_num] != SDRAM_NONE)
1329 if (total_dimm == 1) {
1332 } else if (total_dimm == 2) {
1336 printf("ERROR: Unsupported number of DIMM's (%d)", total_dimm);
1337 spd_ddr_init_hang ();
1340 mr = CMD_EMR | SELECT_MR | BURST_LEN_4 | wr | cas;
1341 emr = CMD_EMR | SELECT_EMR | odt | ods;
1342 emr2 = CMD_EMR | SELECT_EMR2;
1343 emr3 = CMD_EMR | SELECT_EMR3;
1344 /* NOP - Wait 106 MemClk cycles */
1345 mtsdram(SDRAM_INITPLR0, SDRAM_INITPLR_ENABLE | CMD_NOP |
1346 SDRAM_INITPLR_IMWT_ENCODE(106));
1348 /* precharge 4 MemClk cycles */
1349 mtsdram(SDRAM_INITPLR1, SDRAM_INITPLR_ENABLE | CMD_PRECHARGE |
1350 SDRAM_INITPLR_IMWT_ENCODE(4));
1351 /* EMR2 - Wait tMRD (2 MemClk cycles) */
1352 mtsdram(SDRAM_INITPLR2, SDRAM_INITPLR_ENABLE | emr2 |
1353 SDRAM_INITPLR_IMWT_ENCODE(2));
1354 /* EMR3 - Wait tMRD (2 MemClk cycles) */
1355 mtsdram(SDRAM_INITPLR3, SDRAM_INITPLR_ENABLE | emr3 |
1356 SDRAM_INITPLR_IMWT_ENCODE(2));
1357 /* EMR DLL ENABLE - Wait tMRD (2 MemClk cycles) */
1358 mtsdram(SDRAM_INITPLR4, SDRAM_INITPLR_ENABLE | emr |
1359 SDRAM_INITPLR_IMWT_ENCODE(2));
1360 /* MR w/ DLL reset - 200 cycle wait for DLL reset */
1361 mtsdram(SDRAM_INITPLR5, SDRAM_INITPLR_ENABLE | mr | DLL_RESET |
1362 SDRAM_INITPLR_IMWT_ENCODE(200));
1364 /* precharge 4 MemClk cycles */
1365 mtsdram(SDRAM_INITPLR6, SDRAM_INITPLR_ENABLE | CMD_PRECHARGE |
1366 SDRAM_INITPLR_IMWT_ENCODE(4));
1367 /* Refresh 25 MemClk cycles */
1368 mtsdram(SDRAM_INITPLR7, SDRAM_INITPLR_ENABLE | CMD_REFRESH |
1369 SDRAM_INITPLR_IMWT_ENCODE(25));
1370 /* Refresh 25 MemClk cycles */
1371 mtsdram(SDRAM_INITPLR8, SDRAM_INITPLR_ENABLE | CMD_REFRESH |
1372 SDRAM_INITPLR_IMWT_ENCODE(25));
1373 /* Refresh 25 MemClk cycles */
1374 mtsdram(SDRAM_INITPLR9, SDRAM_INITPLR_ENABLE | CMD_REFRESH |
1375 SDRAM_INITPLR_IMWT_ENCODE(25));
1376 /* Refresh 25 MemClk cycles */
1377 mtsdram(SDRAM_INITPLR10, SDRAM_INITPLR_ENABLE | CMD_REFRESH |
1378 SDRAM_INITPLR_IMWT_ENCODE(25));
1379 /* MR w/o DLL reset - Wait tMRD (2 MemClk cycles) */
1380 mtsdram(SDRAM_INITPLR11, SDRAM_INITPLR_ENABLE | mr |
1381 SDRAM_INITPLR_IMWT_ENCODE(2));
1382 /* EMR OCD Default - Wait tMRD (2 MemClk cycles) */
1383 mtsdram(SDRAM_INITPLR12, SDRAM_INITPLR_ENABLE | OCD_CALIB_DEF |
1384 SDRAM_INITPLR_IMWT_ENCODE(2) | emr);
1386 mtsdram(SDRAM_INITPLR13, SDRAM_INITPLR_ENABLE | emr |
1387 SDRAM_INITPLR_IMWT_ENCODE(2));
1389 printf("ERROR: ucode error as unknown DDR type in program_initplr");
1390 spd_ddr_init_hang ();
1394 /*------------------------------------------------------------------
1395 * This routine programs the SDRAM_MMODE register.
1396 * the selected_cas is an output parameter, that will be passed
1397 * by caller to call the above program_initplr( )
1398 *-----------------------------------------------------------------*/
1399 static void program_mode(unsigned long *dimm_populated,
1400 unsigned char *iic0_dimm_addr,
1401 unsigned long num_dimm_banks,
1402 ddr_cas_id_t *selected_cas,
1403 int *write_recovery)
1405 unsigned long dimm_num;
1406 unsigned long sdram_ddr1;
1407 unsigned long t_wr_ns;
1408 unsigned long t_wr_clk;
1409 unsigned long cas_bit;
1410 unsigned long cas_index;
1411 unsigned long sdram_freq;
1412 unsigned long ddr_check;
1413 unsigned long mmode;
1414 unsigned long tcyc_reg;
1415 unsigned long cycle_2_0_clk;
1416 unsigned long cycle_2_5_clk;
1417 unsigned long cycle_3_0_clk;
1418 unsigned long cycle_4_0_clk;
1419 unsigned long cycle_5_0_clk;
1420 unsigned long max_2_0_tcyc_ns_x_100;
1421 unsigned long max_2_5_tcyc_ns_x_100;
1422 unsigned long max_3_0_tcyc_ns_x_100;
1423 unsigned long max_4_0_tcyc_ns_x_100;
1424 unsigned long max_5_0_tcyc_ns_x_100;
1425 unsigned long cycle_time_ns_x_100[3];
1426 PPC4xx_SYS_INFO board_cfg;
1427 unsigned char cas_2_0_available;
1428 unsigned char cas_2_5_available;
1429 unsigned char cas_3_0_available;
1430 unsigned char cas_4_0_available;
1431 unsigned char cas_5_0_available;
1432 unsigned long sdr_ddrpll;
1434 /*------------------------------------------------------------------
1435 * Get the board configuration info.
1436 *-----------------------------------------------------------------*/
1437 get_sys_info(&board_cfg);
1439 mfsdr(SDR0_DDR0, sdr_ddrpll);
1440 sdram_freq = MULDIV64((board_cfg.freqPLB), SDR0_DDR0_DDRM_DECODE(sdr_ddrpll), 1);
1441 debug("sdram_freq=%lu\n", sdram_freq);
1443 /*------------------------------------------------------------------
1444 * Handle the timing. We need to find the worst case timing of all
1445 * the dimm modules installed.
1446 *-----------------------------------------------------------------*/
1448 cas_2_0_available = true;
1449 cas_2_5_available = true;
1450 cas_3_0_available = true;
1451 cas_4_0_available = true;
1452 cas_5_0_available = true;
1453 max_2_0_tcyc_ns_x_100 = 10;
1454 max_2_5_tcyc_ns_x_100 = 10;
1455 max_3_0_tcyc_ns_x_100 = 10;
1456 max_4_0_tcyc_ns_x_100 = 10;
1457 max_5_0_tcyc_ns_x_100 = 10;
1460 /* loop through all the DIMM slots on the board */
1461 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1462 /* If a dimm is installed in a particular slot ... */
1463 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1464 if (dimm_populated[dimm_num] == SDRAM_DDR1)
1469 cas_bit = spd_read(iic0_dimm_addr[dimm_num], 18);
1470 debug("cas_bit[SPD byte 18]=%02lx\n", cas_bit);
1472 /* For a particular DIMM, grab the three CAS values it supports */
1473 for (cas_index = 0; cas_index < 3; cas_index++) {
1474 switch (cas_index) {
1476 tcyc_reg = spd_read(iic0_dimm_addr[dimm_num], 9);
1479 tcyc_reg = spd_read(iic0_dimm_addr[dimm_num], 23);
1482 tcyc_reg = spd_read(iic0_dimm_addr[dimm_num], 25);
1486 if ((tcyc_reg & 0x0F) >= 10) {
1487 if ((tcyc_reg & 0x0F) == 0x0D) {
1488 /* Convert from hex to decimal */
1489 cycle_time_ns_x_100[cas_index] =
1490 (((tcyc_reg & 0xF0) >> 4) * 100) + 75;
1492 printf("ERROR: SPD reported Tcyc is incorrect for DIMM "
1493 "in slot %d\n", (unsigned int)dimm_num);
1494 spd_ddr_init_hang ();
1497 /* Convert from hex to decimal */
1498 cycle_time_ns_x_100[cas_index] =
1499 (((tcyc_reg & 0xF0) >> 4) * 100) +
1500 ((tcyc_reg & 0x0F)*10);
1502 debug("cas_index=%lu: cycle_time_ns_x_100=%lu\n", cas_index,
1503 cycle_time_ns_x_100[cas_index]);
1506 /* The rest of this routine determines if CAS 2.0, 2.5, 3.0, 4.0 and 5.0 are */
1507 /* supported for a particular DIMM. */
1512 * DDR devices use the following bitmask for CAS latency:
1513 * Bit 7 6 5 4 3 2 1 0
1514 * TBD 4.0 3.5 3.0 2.5 2.0 1.5 1.0
1516 if (((cas_bit & 0x40) == 0x40) && (cas_index < 3) &&
1517 (cycle_time_ns_x_100[cas_index] != 0)) {
1518 max_4_0_tcyc_ns_x_100 = max(max_4_0_tcyc_ns_x_100,
1519 cycle_time_ns_x_100[cas_index]);
1524 cas_4_0_available = false;
1527 if (((cas_bit & 0x10) == 0x10) && (cas_index < 3) &&
1528 (cycle_time_ns_x_100[cas_index] != 0)) {
1529 max_3_0_tcyc_ns_x_100 = max(max_3_0_tcyc_ns_x_100,
1530 cycle_time_ns_x_100[cas_index]);
1535 cas_3_0_available = false;
1538 if (((cas_bit & 0x08) == 0x08) && (cas_index < 3) &&
1539 (cycle_time_ns_x_100[cas_index] != 0)) {
1540 max_2_5_tcyc_ns_x_100 = max(max_2_5_tcyc_ns_x_100,
1541 cycle_time_ns_x_100[cas_index]);
1546 cas_2_5_available = false;
1549 if (((cas_bit & 0x04) == 0x04) && (cas_index < 3) &&
1550 (cycle_time_ns_x_100[cas_index] != 0)) {
1551 max_2_0_tcyc_ns_x_100 = max(max_2_0_tcyc_ns_x_100,
1552 cycle_time_ns_x_100[cas_index]);
1557 cas_2_0_available = false;
1561 * DDR2 devices use the following bitmask for CAS latency:
1562 * Bit 7 6 5 4 3 2 1 0
1563 * TBD 6.0 5.0 4.0 3.0 2.0 TBD TBD
1565 if (((cas_bit & 0x20) == 0x20) && (cas_index < 3) &&
1566 (cycle_time_ns_x_100[cas_index] != 0)) {
1567 max_5_0_tcyc_ns_x_100 = max(max_5_0_tcyc_ns_x_100,
1568 cycle_time_ns_x_100[cas_index]);
1573 cas_5_0_available = false;
1576 if (((cas_bit & 0x10) == 0x10) && (cas_index < 3) &&
1577 (cycle_time_ns_x_100[cas_index] != 0)) {
1578 max_4_0_tcyc_ns_x_100 = max(max_4_0_tcyc_ns_x_100,
1579 cycle_time_ns_x_100[cas_index]);
1584 cas_4_0_available = false;
1587 if (((cas_bit & 0x08) == 0x08) && (cas_index < 3) &&
1588 (cycle_time_ns_x_100[cas_index] != 0)) {
1589 max_3_0_tcyc_ns_x_100 = max(max_3_0_tcyc_ns_x_100,
1590 cycle_time_ns_x_100[cas_index]);
1595 cas_3_0_available = false;
1601 /*------------------------------------------------------------------
1602 * Set the SDRAM mode, SDRAM_MMODE
1603 *-----------------------------------------------------------------*/
1604 mfsdram(SDRAM_MMODE, mmode);
1605 mmode = mmode & ~(SDRAM_MMODE_WR_MASK | SDRAM_MMODE_DCL_MASK);
1607 /* add 10 here because of rounding problems */
1608 cycle_2_0_clk = MULDIV64(ONE_BILLION, 100, max_2_0_tcyc_ns_x_100) + 10;
1609 cycle_2_5_clk = MULDIV64(ONE_BILLION, 100, max_2_5_tcyc_ns_x_100) + 10;
1610 cycle_3_0_clk = MULDIV64(ONE_BILLION, 100, max_3_0_tcyc_ns_x_100) + 10;
1611 cycle_4_0_clk = MULDIV64(ONE_BILLION, 100, max_4_0_tcyc_ns_x_100) + 10;
1612 cycle_5_0_clk = MULDIV64(ONE_BILLION, 100, max_5_0_tcyc_ns_x_100) + 10;
1613 debug("cycle_3_0_clk=%lu\n", cycle_3_0_clk);
1614 debug("cycle_4_0_clk=%lu\n", cycle_4_0_clk);
1615 debug("cycle_5_0_clk=%lu\n", cycle_5_0_clk);
1617 if (sdram_ddr1 == true) { /* DDR1 */
1618 if ((cas_2_0_available == true) &&
1619 (sdram_freq <= cycle_2_0_clk)) {
1620 mmode |= SDRAM_MMODE_DCL_DDR1_2_0_CLK;
1621 *selected_cas = DDR_CAS_2;
1622 } else if ((cas_2_5_available == true) &&
1623 (sdram_freq <= cycle_2_5_clk)) {
1624 mmode |= SDRAM_MMODE_DCL_DDR1_2_5_CLK;
1625 *selected_cas = DDR_CAS_2_5;
1626 } else if ((cas_3_0_available == true) &&
1627 (sdram_freq <= cycle_3_0_clk)) {
1628 mmode |= SDRAM_MMODE_DCL_DDR1_3_0_CLK;
1629 *selected_cas = DDR_CAS_3;
1631 printf("ERROR: Cannot find a supported CAS latency with the installed DIMMs.\n");
1632 printf("Only DIMMs DDR1 with CAS latencies of 2.0, 2.5, and 3.0 are supported.\n");
1633 printf("Make sure the PLB speed is within the supported range of the DIMMs.\n\n");
1634 spd_ddr_init_hang ();
1637 debug("cas_3_0_available=%d\n", cas_3_0_available);
1638 debug("cas_4_0_available=%d\n", cas_4_0_available);
1639 debug("cas_5_0_available=%d\n", cas_5_0_available);
1640 if ((cas_3_0_available == true) &&
1641 (sdram_freq <= cycle_3_0_clk)) {
1642 mmode |= SDRAM_MMODE_DCL_DDR2_3_0_CLK;
1643 *selected_cas = DDR_CAS_3;
1644 } else if ((cas_4_0_available == true) &&
1645 (sdram_freq <= cycle_4_0_clk)) {
1646 mmode |= SDRAM_MMODE_DCL_DDR2_4_0_CLK;
1647 *selected_cas = DDR_CAS_4;
1648 } else if ((cas_5_0_available == true) &&
1649 (sdram_freq <= cycle_5_0_clk)) {
1650 mmode |= SDRAM_MMODE_DCL_DDR2_5_0_CLK;
1651 *selected_cas = DDR_CAS_5;
1653 printf("ERROR: Cannot find a supported CAS latency with the installed DIMMs.\n");
1654 printf("Only DIMMs DDR2 with CAS latencies of 3.0, 4.0, and 5.0 are supported.\n");
1655 printf("Make sure the PLB speed is within the supported range of the DIMMs.\n");
1656 printf("cas3=%d cas4=%d cas5=%d\n",
1657 cas_3_0_available, cas_4_0_available, cas_5_0_available);
1658 printf("sdram_freq=%lu cycle3=%lu cycle4=%lu cycle5=%lu\n\n",
1659 sdram_freq, cycle_3_0_clk, cycle_4_0_clk, cycle_5_0_clk);
1660 spd_ddr_init_hang ();
1664 if (sdram_ddr1 == true)
1665 mmode |= SDRAM_MMODE_WR_DDR1;
1668 /* loop through all the DIMM slots on the board */
1669 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1670 /* If a dimm is installed in a particular slot ... */
1671 if (dimm_populated[dimm_num] != SDRAM_NONE)
1672 t_wr_ns = max(t_wr_ns, (unsigned long)
1673 spd_read(iic0_dimm_addr[dimm_num], 36) >> 2);
1677 * convert from nanoseconds to ddr clocks
1678 * round up if necessary
1680 t_wr_clk = MULDIV64(sdram_freq, t_wr_ns, ONE_BILLION);
1681 ddr_check = MULDIV64(ONE_BILLION, t_wr_clk, t_wr_ns);
1682 if (sdram_freq != ddr_check)
1690 mmode |= SDRAM_MMODE_WR_DDR2_3_CYC;
1693 mmode |= SDRAM_MMODE_WR_DDR2_4_CYC;
1696 mmode |= SDRAM_MMODE_WR_DDR2_5_CYC;
1699 mmode |= SDRAM_MMODE_WR_DDR2_6_CYC;
1702 *write_recovery = t_wr_clk;
1705 debug("CAS latency = %d\n", *selected_cas);
1706 debug("Write recovery = %d\n", *write_recovery);
1708 mtsdram(SDRAM_MMODE, mmode);
1711 /*-----------------------------------------------------------------------------+
1713 *-----------------------------------------------------------------------------*/
1714 static void program_rtr(unsigned long *dimm_populated,
1715 unsigned char *iic0_dimm_addr,
1716 unsigned long num_dimm_banks)
1718 PPC4xx_SYS_INFO board_cfg;
1719 unsigned long max_refresh_rate;
1720 unsigned long dimm_num;
1721 unsigned long refresh_rate_type;
1722 unsigned long refresh_rate;
1724 unsigned long sdram_freq;
1725 unsigned long sdr_ddrpll;
1728 /*------------------------------------------------------------------
1729 * Get the board configuration info.
1730 *-----------------------------------------------------------------*/
1731 get_sys_info(&board_cfg);
1733 /*------------------------------------------------------------------
1734 * Set the SDRAM Refresh Timing Register, SDRAM_RTR
1735 *-----------------------------------------------------------------*/
1736 mfsdr(SDR0_DDR0, sdr_ddrpll);
1737 sdram_freq = ((board_cfg.freqPLB) * SDR0_DDR0_DDRM_DECODE(sdr_ddrpll));
1739 max_refresh_rate = 0;
1740 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1741 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1743 refresh_rate_type = spd_read(iic0_dimm_addr[dimm_num], 12);
1744 refresh_rate_type &= 0x7F;
1745 switch (refresh_rate_type) {
1747 refresh_rate = 15625;
1750 refresh_rate = 3906;
1753 refresh_rate = 7812;
1756 refresh_rate = 31250;
1759 refresh_rate = 62500;
1762 refresh_rate = 125000;
1766 printf("ERROR: DIMM %d unsupported refresh rate/type.\n",
1767 (unsigned int)dimm_num);
1768 printf("Replace the DIMM module with a supported DIMM.\n\n");
1769 spd_ddr_init_hang ();
1773 max_refresh_rate = max(max_refresh_rate, refresh_rate);
1777 rint = MULDIV64(sdram_freq, max_refresh_rate, ONE_BILLION);
1778 mfsdram(SDRAM_RTR, val);
1779 mtsdram(SDRAM_RTR, (val & ~SDRAM_RTR_RINT_MASK) |
1780 (SDRAM_RTR_RINT_ENCODE(rint)));
1783 /*------------------------------------------------------------------
1784 * This routine programs the SDRAM_TRx registers.
1785 *-----------------------------------------------------------------*/
1786 static void program_tr(unsigned long *dimm_populated,
1787 unsigned char *iic0_dimm_addr,
1788 unsigned long num_dimm_banks)
1790 unsigned long dimm_num;
1791 unsigned long sdram_ddr1;
1792 unsigned long t_rp_ns;
1793 unsigned long t_rcd_ns;
1794 unsigned long t_rrd_ns;
1795 unsigned long t_ras_ns;
1796 unsigned long t_rc_ns;
1797 unsigned long t_rfc_ns;
1798 unsigned long t_wpc_ns;
1799 unsigned long t_wtr_ns;
1800 unsigned long t_rpc_ns;
1801 unsigned long t_rp_clk;
1802 unsigned long t_rcd_clk;
1803 unsigned long t_rrd_clk;
1804 unsigned long t_ras_clk;
1805 unsigned long t_rc_clk;
1806 unsigned long t_rfc_clk;
1807 unsigned long t_wpc_clk;
1808 unsigned long t_wtr_clk;
1809 unsigned long t_rpc_clk;
1810 unsigned long sdtr1, sdtr2, sdtr3;
1811 unsigned long ddr_check;
1812 unsigned long sdram_freq;
1813 unsigned long sdr_ddrpll;
1815 PPC4xx_SYS_INFO board_cfg;
1817 /*------------------------------------------------------------------
1818 * Get the board configuration info.
1819 *-----------------------------------------------------------------*/
1820 get_sys_info(&board_cfg);
1822 mfsdr(SDR0_DDR0, sdr_ddrpll);
1823 sdram_freq = ((board_cfg.freqPLB) * SDR0_DDR0_DDRM_DECODE(sdr_ddrpll));
1825 /*------------------------------------------------------------------
1826 * Handle the timing. We need to find the worst case timing of all
1827 * the dimm modules installed.
1828 *-----------------------------------------------------------------*/
1840 /* loop through all the DIMM slots on the board */
1841 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1842 /* If a dimm is installed in a particular slot ... */
1843 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1844 if (dimm_populated[dimm_num] == SDRAM_DDR2)
1849 t_rcd_ns = max(t_rcd_ns,
1850 (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 29) >> 2);
1851 t_rrd_ns = max(t_rrd_ns,
1852 (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 28) >> 2);
1853 t_rp_ns = max(t_rp_ns,
1854 (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 27) >> 2);
1855 t_ras_ns = max(t_ras_ns,
1856 (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 30));
1857 t_rc_ns = max(t_rc_ns,
1858 (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 41));
1859 t_rfc_ns = max(t_rfc_ns,
1860 (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 42));
1864 /*------------------------------------------------------------------
1865 * Set the SDRAM Timing Reg 1, SDRAM_TR1
1866 *-----------------------------------------------------------------*/
1867 mfsdram(SDRAM_SDTR1, sdtr1);
1868 sdtr1 &= ~(SDRAM_SDTR1_LDOF_MASK | SDRAM_SDTR1_RTW_MASK |
1869 SDRAM_SDTR1_WTWO_MASK | SDRAM_SDTR1_RTRO_MASK);
1871 /* default values */
1872 sdtr1 |= SDRAM_SDTR1_LDOF_2_CLK;
1873 sdtr1 |= SDRAM_SDTR1_RTW_2_CLK;
1875 /* normal operations */
1876 sdtr1 |= SDRAM_SDTR1_WTWO_0_CLK;
1877 sdtr1 |= SDRAM_SDTR1_RTRO_1_CLK;
1879 mtsdram(SDRAM_SDTR1, sdtr1);
1881 /*------------------------------------------------------------------
1882 * Set the SDRAM Timing Reg 2, SDRAM_TR2
1883 *-----------------------------------------------------------------*/
1884 mfsdram(SDRAM_SDTR2, sdtr2);
1885 sdtr2 &= ~(SDRAM_SDTR2_RCD_MASK | SDRAM_SDTR2_WTR_MASK |
1886 SDRAM_SDTR2_XSNR_MASK | SDRAM_SDTR2_WPC_MASK |
1887 SDRAM_SDTR2_RPC_MASK | SDRAM_SDTR2_RP_MASK |
1888 SDRAM_SDTR2_RRD_MASK);
1891 * convert t_rcd from nanoseconds to ddr clocks
1892 * round up if necessary
1894 t_rcd_clk = MULDIV64(sdram_freq, t_rcd_ns, ONE_BILLION);
1895 ddr_check = MULDIV64(ONE_BILLION, t_rcd_clk, t_rcd_ns);
1896 if (sdram_freq != ddr_check)
1899 switch (t_rcd_clk) {
1902 sdtr2 |= SDRAM_SDTR2_RCD_1_CLK;
1905 sdtr2 |= SDRAM_SDTR2_RCD_2_CLK;
1908 sdtr2 |= SDRAM_SDTR2_RCD_3_CLK;
1911 sdtr2 |= SDRAM_SDTR2_RCD_4_CLK;
1914 sdtr2 |= SDRAM_SDTR2_RCD_5_CLK;
1918 if (sdram_ddr1 == true) { /* DDR1 */
1919 if (sdram_freq < 200000000) {
1920 sdtr2 |= SDRAM_SDTR2_WTR_1_CLK;
1921 sdtr2 |= SDRAM_SDTR2_WPC_2_CLK;
1922 sdtr2 |= SDRAM_SDTR2_RPC_2_CLK;
1924 sdtr2 |= SDRAM_SDTR2_WTR_2_CLK;
1925 sdtr2 |= SDRAM_SDTR2_WPC_3_CLK;
1926 sdtr2 |= SDRAM_SDTR2_RPC_2_CLK;
1929 /* loop through all the DIMM slots on the board */
1930 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1931 /* If a dimm is installed in a particular slot ... */
1932 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1933 t_wpc_ns = max(t_wtr_ns,
1934 (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 36) >> 2);
1935 t_wtr_ns = max(t_wtr_ns,
1936 (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 37) >> 2);
1937 t_rpc_ns = max(t_rpc_ns,
1938 (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 38) >> 2);
1943 * convert from nanoseconds to ddr clocks
1944 * round up if necessary
1946 t_wpc_clk = MULDIV64(sdram_freq, t_wpc_ns, ONE_BILLION);
1947 ddr_check = MULDIV64(ONE_BILLION, t_wpc_clk, t_wpc_ns);
1948 if (sdram_freq != ddr_check)
1951 switch (t_wpc_clk) {
1955 sdtr2 |= SDRAM_SDTR2_WPC_2_CLK;
1958 sdtr2 |= SDRAM_SDTR2_WPC_3_CLK;
1961 sdtr2 |= SDRAM_SDTR2_WPC_4_CLK;
1964 sdtr2 |= SDRAM_SDTR2_WPC_5_CLK;
1967 sdtr2 |= SDRAM_SDTR2_WPC_6_CLK;
1972 * convert from nanoseconds to ddr clocks
1973 * round up if necessary
1975 t_wtr_clk = MULDIV64(sdram_freq, t_wtr_ns, ONE_BILLION);
1976 ddr_check = MULDIV64(ONE_BILLION, t_wtr_clk, t_wtr_ns);
1977 if (sdram_freq != ddr_check)
1980 switch (t_wtr_clk) {
1983 sdtr2 |= SDRAM_SDTR2_WTR_1_CLK;
1986 sdtr2 |= SDRAM_SDTR2_WTR_2_CLK;
1989 sdtr2 |= SDRAM_SDTR2_WTR_3_CLK;
1992 sdtr2 |= SDRAM_SDTR2_WTR_4_CLK;
1997 * convert from nanoseconds to ddr clocks
1998 * round up if necessary
2000 t_rpc_clk = MULDIV64(sdram_freq, t_rpc_ns, ONE_BILLION);
2001 ddr_check = MULDIV64(ONE_BILLION, t_rpc_clk, t_rpc_ns);
2002 if (sdram_freq != ddr_check)
2005 switch (t_rpc_clk) {
2009 sdtr2 |= SDRAM_SDTR2_RPC_2_CLK;
2012 sdtr2 |= SDRAM_SDTR2_RPC_3_CLK;
2015 sdtr2 |= SDRAM_SDTR2_RPC_4_CLK;
2021 sdtr2 |= SDRAM_SDTR2_XSNR_16_CLK;
2024 * convert t_rrd from nanoseconds to ddr clocks
2025 * round up if necessary
2027 t_rrd_clk = MULDIV64(sdram_freq, t_rrd_ns, ONE_BILLION);
2028 ddr_check = MULDIV64(ONE_BILLION, t_rrd_clk, t_rrd_ns);
2029 if (sdram_freq != ddr_check)
2033 sdtr2 |= SDRAM_SDTR2_RRD_3_CLK;
2035 sdtr2 |= SDRAM_SDTR2_RRD_2_CLK;
2038 * convert t_rp from nanoseconds to ddr clocks
2039 * round up if necessary
2041 t_rp_clk = MULDIV64(sdram_freq, t_rp_ns, ONE_BILLION);
2042 ddr_check = MULDIV64(ONE_BILLION, t_rp_clk, t_rp_ns);
2043 if (sdram_freq != ddr_check)
2051 sdtr2 |= SDRAM_SDTR2_RP_3_CLK;
2054 sdtr2 |= SDRAM_SDTR2_RP_4_CLK;
2057 sdtr2 |= SDRAM_SDTR2_RP_5_CLK;
2060 sdtr2 |= SDRAM_SDTR2_RP_6_CLK;
2063 sdtr2 |= SDRAM_SDTR2_RP_7_CLK;
2067 mtsdram(SDRAM_SDTR2, sdtr2);
2069 /*------------------------------------------------------------------
2070 * Set the SDRAM Timing Reg 3, SDRAM_TR3
2071 *-----------------------------------------------------------------*/
2072 mfsdram(SDRAM_SDTR3, sdtr3);
2073 sdtr3 &= ~(SDRAM_SDTR3_RAS_MASK | SDRAM_SDTR3_RC_MASK |
2074 SDRAM_SDTR3_XCS_MASK | SDRAM_SDTR3_RFC_MASK);
2077 * convert t_ras from nanoseconds to ddr clocks
2078 * round up if necessary
2080 t_ras_clk = MULDIV64(sdram_freq, t_ras_ns, ONE_BILLION);
2081 ddr_check = MULDIV64(ONE_BILLION, t_ras_clk, t_ras_ns);
2082 if (sdram_freq != ddr_check)
2085 sdtr3 |= SDRAM_SDTR3_RAS_ENCODE(t_ras_clk);
2088 * convert t_rc from nanoseconds to ddr clocks
2089 * round up if necessary
2091 t_rc_clk = MULDIV64(sdram_freq, t_rc_ns, ONE_BILLION);
2092 ddr_check = MULDIV64(ONE_BILLION, t_rc_clk, t_rc_ns);
2093 if (sdram_freq != ddr_check)
2096 sdtr3 |= SDRAM_SDTR3_RC_ENCODE(t_rc_clk);
2098 /* default xcs value */
2099 sdtr3 |= SDRAM_SDTR3_XCS;
2102 * convert t_rfc from nanoseconds to ddr clocks
2103 * round up if necessary
2105 t_rfc_clk = MULDIV64(sdram_freq, t_rfc_ns, ONE_BILLION);
2106 ddr_check = MULDIV64(ONE_BILLION, t_rfc_clk, t_rfc_ns);
2107 if (sdram_freq != ddr_check)
2110 sdtr3 |= SDRAM_SDTR3_RFC_ENCODE(t_rfc_clk);
2112 mtsdram(SDRAM_SDTR3, sdtr3);
2115 /*-----------------------------------------------------------------------------+
2117 *-----------------------------------------------------------------------------*/
2118 static void program_bxcf(unsigned long *dimm_populated,
2119 unsigned char *iic0_dimm_addr,
2120 unsigned long num_dimm_banks)
2122 unsigned long dimm_num;
2123 unsigned long num_col_addr;
2124 unsigned long num_ranks;
2125 unsigned long num_banks;
2127 unsigned long ind_rank;
2129 unsigned long ind_bank;
2130 unsigned long bank_0_populated;
2132 /*------------------------------------------------------------------
2133 * Set the BxCF regs. First, wipe out the bank config registers.
2134 *-----------------------------------------------------------------*/
2135 mtsdram(SDRAM_MB0CF, 0x00000000);
2136 mtsdram(SDRAM_MB1CF, 0x00000000);
2137 mtsdram(SDRAM_MB2CF, 0x00000000);
2138 mtsdram(SDRAM_MB3CF, 0x00000000);
2140 mode = SDRAM_BXCF_M_BE_ENABLE;
2142 bank_0_populated = 0;
2144 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
2145 if (dimm_populated[dimm_num] != SDRAM_NONE) {
2146 num_col_addr = spd_read(iic0_dimm_addr[dimm_num], 4);
2147 num_ranks = spd_read(iic0_dimm_addr[dimm_num], 5);
2148 if ((spd_read(iic0_dimm_addr[dimm_num], 2)) == 0x08)
2149 num_ranks = (num_ranks & 0x0F) +1;
2151 num_ranks = num_ranks & 0x0F;
2153 num_banks = spd_read(iic0_dimm_addr[dimm_num], 17);
2155 for (ind_bank = 0; ind_bank < 2; ind_bank++) {
2160 switch (num_col_addr) {
2162 mode |= (SDRAM_BXCF_M_AM_0 + ind);
2165 mode |= (SDRAM_BXCF_M_AM_1 + ind);
2168 mode |= (SDRAM_BXCF_M_AM_2 + ind);
2171 mode |= (SDRAM_BXCF_M_AM_3 + ind);
2174 mode |= (SDRAM_BXCF_M_AM_4 + ind);
2177 printf("DDR-SDRAM: DIMM %d BxCF configuration.\n",
2178 (unsigned int)dimm_num);
2179 printf("ERROR: Unsupported value for number of "
2180 "column addresses: %d.\n", (unsigned int)num_col_addr);
2181 printf("Replace the DIMM module with a supported DIMM.\n\n");
2182 spd_ddr_init_hang ();
2186 if ((dimm_populated[dimm_num] != SDRAM_NONE)&& (dimm_num ==1))
2187 bank_0_populated = 1;
2189 for (ind_rank = 0; ind_rank < num_ranks; ind_rank++) {
2190 mtsdram(SDRAM_MB0CF +
2191 ((dimm_num + bank_0_populated + ind_rank) << 2),
2198 /*------------------------------------------------------------------
2199 * program memory queue.
2200 *-----------------------------------------------------------------*/
2201 static void program_memory_queue(unsigned long *dimm_populated,
2202 unsigned char *iic0_dimm_addr,
2203 unsigned long num_dimm_banks)
2205 unsigned long dimm_num;
2206 phys_size_t rank_base_addr;
2207 unsigned long rank_reg;
2208 phys_size_t rank_size_bytes;
2209 unsigned long rank_size_id;
2210 unsigned long num_ranks;
2211 unsigned long baseadd_size;
2213 unsigned long bank_0_populated = 0;
2214 phys_size_t total_size = 0;
2216 /*------------------------------------------------------------------
2217 * Reset the rank_base_address.
2218 *-----------------------------------------------------------------*/
2219 rank_reg = SDRAM_R0BAS;
2221 rank_base_addr = 0x00000000;
2223 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
2224 if (dimm_populated[dimm_num] != SDRAM_NONE) {
2225 num_ranks = spd_read(iic0_dimm_addr[dimm_num], 5);
2226 if ((spd_read(iic0_dimm_addr[dimm_num], 2)) == 0x08)
2227 num_ranks = (num_ranks & 0x0F) + 1;
2229 num_ranks = num_ranks & 0x0F;
2231 rank_size_id = spd_read(iic0_dimm_addr[dimm_num], 31);
2233 /*------------------------------------------------------------------
2235 *-----------------------------------------------------------------*/
2237 switch (rank_size_id) {
2239 baseadd_size |= SDRAM_RXBAS_SDSZ_1024;
2243 baseadd_size |= SDRAM_RXBAS_SDSZ_2048;
2247 baseadd_size |= SDRAM_RXBAS_SDSZ_4096;
2251 baseadd_size |= SDRAM_RXBAS_SDSZ_32;
2255 baseadd_size |= SDRAM_RXBAS_SDSZ_64;
2259 baseadd_size |= SDRAM_RXBAS_SDSZ_128;
2263 baseadd_size |= SDRAM_RXBAS_SDSZ_256;
2267 baseadd_size |= SDRAM_RXBAS_SDSZ_512;
2271 printf("DDR-SDRAM: DIMM %d memory queue configuration.\n",
2272 (unsigned int)dimm_num);
2273 printf("ERROR: Unsupported value for the banksize: %d.\n",
2274 (unsigned int)rank_size_id);
2275 printf("Replace the DIMM module with a supported DIMM.\n\n");
2276 spd_ddr_init_hang ();
2278 rank_size_bytes = total_size << 20;
2280 if ((dimm_populated[dimm_num] != SDRAM_NONE) && (dimm_num == 1))
2281 bank_0_populated = 1;
2283 for (i = 0; i < num_ranks; i++) {
2284 mtdcr_any(rank_reg+i+dimm_num+bank_0_populated,
2285 (SDRAM_RXBAS_SDBA_ENCODE(rank_base_addr) |
2287 rank_base_addr += rank_size_bytes;
2292 #if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
2293 defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
2294 defined(CONFIG_460SX)
2296 * Enable high bandwidth access
2297 * This is currently not used, but with this setup
2298 * it is possible to use it later on in e.g. the Linux
2299 * EMAC driver for performance gain.
2301 mtdcr(SDRAM_PLBADDULL, 0x00000000); /* MQ0_BAUL */
2302 mtdcr(SDRAM_PLBADDUHB, 0x00000008); /* MQ0_BAUH */
2305 * Set optimal value for Memory Queue HB/LL Configuration registers
2307 mtdcr(SDRAM_CONF1HB, (mfdcr(SDRAM_CONF1HB) & ~SDRAM_CONF1HB_MASK) |
2308 SDRAM_CONF1HB_AAFR | SDRAM_CONF1HB_RPEN | SDRAM_CONF1HB_RFTE |
2309 SDRAM_CONF1HB_RPLM | SDRAM_CONF1HB_WRCL);
2310 mtdcr(SDRAM_CONF1LL, (mfdcr(SDRAM_CONF1LL) & ~SDRAM_CONF1LL_MASK) |
2311 SDRAM_CONF1LL_AAFR | SDRAM_CONF1LL_RPEN | SDRAM_CONF1LL_RFTE |
2312 SDRAM_CONF1LL_RPLM);
2313 mtdcr(SDRAM_CONFPATHB, mfdcr(SDRAM_CONFPATHB) | SDRAM_CONFPATHB_TPEN);
2317 #ifdef CONFIG_DDR_ECC
2318 /*-----------------------------------------------------------------------------+
2320 *-----------------------------------------------------------------------------*/
2321 static void program_ecc(unsigned long *dimm_populated,
2322 unsigned char *iic0_dimm_addr,
2323 unsigned long num_dimm_banks,
2324 unsigned long tlb_word2_i_value)
2326 unsigned long dimm_num;
2330 /* loop through all the DIMM slots on the board */
2331 for (dimm_num = 0; dimm_num < MAXDIMMS; dimm_num++) {
2332 /* If a dimm is installed in a particular slot ... */
2333 if (dimm_populated[dimm_num] != SDRAM_NONE)
2335 (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 11));
2340 do_program_ecc(tlb_word2_i_value);
2344 #if !defined(CONFIG_PPC4xx_DDR_AUTOCALIBRATION)
2345 /*-----------------------------------------------------------------------------+
2346 * program_DQS_calibration.
2347 *-----------------------------------------------------------------------------*/
2348 static void program_DQS_calibration(unsigned long *dimm_populated,
2349 unsigned char *iic0_dimm_addr,
2350 unsigned long num_dimm_banks)
2354 #ifdef HARD_CODED_DQS /* calibration test with hardvalues */
2355 mtsdram(SDRAM_RQDC, 0x80000037);
2356 mtsdram(SDRAM_RDCC, 0x40000000);
2357 mtsdram(SDRAM_RFDC, 0x000001DF);
2361 /*------------------------------------------------------------------
2362 * Program RDCC register
2363 * Read sample cycle auto-update enable
2364 *-----------------------------------------------------------------*/
2366 mfsdram(SDRAM_RDCC, val);
2368 (val & ~(SDRAM_RDCC_RDSS_MASK | SDRAM_RDCC_RSAE_MASK))
2369 | SDRAM_RDCC_RSAE_ENABLE);
2371 /*------------------------------------------------------------------
2372 * Program RQDC register
2373 * Internal DQS delay mechanism enable
2374 *-----------------------------------------------------------------*/
2375 mtsdram(SDRAM_RQDC, (SDRAM_RQDC_RQDE_ENABLE|SDRAM_RQDC_RQFD_ENCODE(0x38)));
2377 /*------------------------------------------------------------------
2378 * Program RFDC register
2379 * Set Feedback Fractional Oversample
2380 * Auto-detect read sample cycle enable
2381 * Set RFOS to 1/4 of memclk cycle (0x3f)
2382 *-----------------------------------------------------------------*/
2383 mfsdram(SDRAM_RFDC, val);
2385 (val & ~(SDRAM_RFDC_ARSE_MASK | SDRAM_RFDC_RFOS_MASK |
2386 SDRAM_RFDC_RFFD_MASK))
2387 | (SDRAM_RFDC_ARSE_ENABLE | SDRAM_RFDC_RFOS_ENCODE(0x3f) |
2388 SDRAM_RFDC_RFFD_ENCODE(0)));
2390 DQS_calibration_process();
2394 static int short_mem_test(void)
2401 phys_size_t base_addr;
2402 u32 test[NUMMEMTESTS][NUMMEMWORDS] = {
2403 {0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF,
2404 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF},
2405 {0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000,
2406 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000},
2407 {0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555,
2408 0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555},
2409 {0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA,
2410 0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA},
2411 {0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A,
2412 0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A},
2413 {0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5,
2414 0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5},
2415 {0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA,
2416 0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA},
2417 {0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55,
2418 0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55} };
2421 for (bxcr_num = 0; bxcr_num < MAXBXCF; bxcr_num++) {
2422 mfsdram(SDRAM_MB0CF + (bxcr_num << 2), bxcf);
2425 if ((bxcf & SDRAM_BXCF_M_BE_MASK) == SDRAM_BXCF_M_BE_ENABLE) {
2426 /* Bank is enabled */
2429 * Only run test on accessable memory (below 2GB)
2431 base_addr = SDRAM_RXBAS_SDBA_DECODE(mfdcr_any(SDRAM_R0BAS+bxcr_num));
2432 if (base_addr >= CONFIG_MAX_MEM_MAPPED)
2435 /*------------------------------------------------------------------
2436 * Run the short memory test.
2437 *-----------------------------------------------------------------*/
2438 membase = (u32 *)(u32)base_addr;
2440 for (i = 0; i < NUMMEMTESTS; i++) {
2441 for (j = 0; j < NUMMEMWORDS; j++) {
2442 membase[j] = test[i][j];
2443 ppcDcbf((u32)&(membase[j]));
2446 for (l=0; l<NUMLOOPS; l++) {
2447 for (j = 0; j < NUMMEMWORDS; j++) {
2448 if (membase[j] != test[i][j]) {
2449 ppcDcbf((u32)&(membase[j]));
2452 ppcDcbf((u32)&(membase[j]));
2457 } /* if bank enabled */
2458 } /* for bxcf_num */
2463 #ifndef HARD_CODED_DQS
2464 /*-----------------------------------------------------------------------------+
2465 * DQS_calibration_process.
2466 *-----------------------------------------------------------------------------*/
2467 static void DQS_calibration_process(void)
2469 unsigned long rfdc_reg;
2474 unsigned long dlycal;
2475 unsigned long dly_val;
2476 unsigned long max_pass_length;
2477 unsigned long current_pass_length;
2478 unsigned long current_fail_length;
2479 unsigned long current_start;
2481 unsigned char fail_found;
2482 unsigned char pass_found;
2483 #if !defined(CONFIG_DDR_RQDC_FIXED)
2490 char str[] = "Auto calibration -";
2491 char slash[] = "\\|/-\\|/-";
2493 /*------------------------------------------------------------------
2494 * Test to determine the best read clock delay tuning bits.
2496 * Before the DDR controller can be used, the read clock delay needs to be
2497 * set. This is SDRAM_RQDC[RQFD] and SDRAM_RFDC[RFFD].
2498 * This value cannot be hardcoded into the program because it changes
2499 * depending on the board's setup and environment.
2500 * To do this, all delay values are tested to see if they
2501 * work or not. By doing this, you get groups of fails with groups of
2502 * passing values. The idea is to find the start and end of a passing
2503 * window and take the center of it to use as the read clock delay.
2505 * A failure has to be seen first so that when we hit a pass, we know
2506 * that it is truely the start of the window. If we get passing values
2507 * to start off with, we don't know if we are at the start of the window.
2509 * The code assumes that a failure will always be found.
2510 * If a failure is not found, there is no easy way to get the middle
2511 * of the passing window. I guess we can pretty much pick any value
2512 * but some values will be better than others. Since the lowest speed
2513 * we can clock the DDR interface at is 200 MHz (2x 100 MHz PLB speed),
2514 * from experimentation it is safe to say you will always have a failure.
2515 *-----------------------------------------------------------------*/
2517 /* first fix RQDC[RQFD] to an average of 80 degre phase shift to find RFDC[RFFD] */
2518 rqfd_start = 64; /* test-only: don't know if this is the _best_ start value */
2523 mfsdram(SDRAM_RQDC, rqdc_reg);
2524 mtsdram(SDRAM_RQDC, (rqdc_reg & ~SDRAM_RQDC_RQFD_MASK) |
2525 SDRAM_RQDC_RQFD_ENCODE(rqfd_start));
2526 #else /* CONFIG_DDR_RQDC_FIXED */
2528 * On Katmai the complete auto-calibration somehow doesn't seem to
2529 * produce the best results, meaning optimal values for RQFD/RFFD.
2530 * This was discovered by GDA using a high bandwidth scope,
2531 * analyzing the DDR2 signals. GDA provided a fixed value for RQFD,
2532 * so now on Katmai "only" RFFD is auto-calibrated.
2534 mtsdram(SDRAM_RQDC, CONFIG_DDR_RQDC_FIXED);
2535 #endif /* CONFIG_DDR_RQDC_FIXED */
2539 max_pass_length = 0;
2542 current_pass_length = 0;
2543 current_fail_length = 0;
2549 * get the delay line calibration register value
2551 mfsdram(SDRAM_DLCR, dlycal);
2552 dly_val = SDRAM_DLYCAL_DLCV_DECODE(dlycal) << 2;
2554 for (rffd = 0; rffd <= SDRAM_RFDC_RFFD_MAX; rffd++) {
2555 mfsdram(SDRAM_RFDC, rfdc_reg);
2556 rfdc_reg &= ~(SDRAM_RFDC_RFFD_MASK);
2558 /*------------------------------------------------------------------
2559 * Set the timing reg for the test.
2560 *-----------------------------------------------------------------*/
2561 mtsdram(SDRAM_RFDC, rfdc_reg | SDRAM_RFDC_RFFD_ENCODE(rffd));
2563 /*------------------------------------------------------------------
2564 * See if the rffd value passed.
2565 *-----------------------------------------------------------------*/
2566 if (short_mem_test()) {
2567 if (fail_found == true) {
2569 if (current_pass_length == 0)
2570 current_start = rffd;
2572 current_fail_length = 0;
2573 current_pass_length++;
2575 if (current_pass_length > max_pass_length) {
2576 max_pass_length = current_pass_length;
2577 max_start = current_start;
2582 current_pass_length = 0;
2583 current_fail_length++;
2585 if (current_fail_length >= (dly_val >> 2)) {
2586 if (fail_found == false)
2588 else if (pass_found == true)
2594 /*------------------------------------------------------------------
2595 * Set the average RFFD value
2596 *-----------------------------------------------------------------*/
2597 rffd_average = ((max_start + max_end) >> 1);
2599 if (rffd_average < 0)
2602 if (rffd_average > SDRAM_RFDC_RFFD_MAX)
2603 rffd_average = SDRAM_RFDC_RFFD_MAX;
2604 /* now fix RFDC[RFFD] found and find RQDC[RQFD] */
2605 mtsdram(SDRAM_RFDC, rfdc_reg | SDRAM_RFDC_RFFD_ENCODE(rffd_average));
2607 #if !defined(CONFIG_DDR_RQDC_FIXED)
2608 max_pass_length = 0;
2611 current_pass_length = 0;
2612 current_fail_length = 0;
2614 window_found = false;
2618 for (rqfd = 0; rqfd <= SDRAM_RQDC_RQFD_MAX; rqfd++) {
2619 mfsdram(SDRAM_RQDC, rqdc_reg);
2620 rqdc_reg &= ~(SDRAM_RQDC_RQFD_MASK);
2622 /*------------------------------------------------------------------
2623 * Set the timing reg for the test.
2624 *-----------------------------------------------------------------*/
2625 mtsdram(SDRAM_RQDC, rqdc_reg | SDRAM_RQDC_RQFD_ENCODE(rqfd));
2627 /*------------------------------------------------------------------
2628 * See if the rffd value passed.
2629 *-----------------------------------------------------------------*/
2630 if (short_mem_test()) {
2631 if (fail_found == true) {
2633 if (current_pass_length == 0)
2634 current_start = rqfd;
2636 current_fail_length = 0;
2637 current_pass_length++;
2639 if (current_pass_length > max_pass_length) {
2640 max_pass_length = current_pass_length;
2641 max_start = current_start;
2646 current_pass_length = 0;
2647 current_fail_length++;
2649 if (fail_found == false) {
2651 } else if (pass_found == true) {
2652 window_found = true;
2658 rqfd_average = ((max_start + max_end) >> 1);
2660 /*------------------------------------------------------------------
2661 * Make sure we found the valid read passing window. Halt if not
2662 *-----------------------------------------------------------------*/
2663 if (window_found == false) {
2664 if (rqfd_start < SDRAM_RQDC_RQFD_MAX) {
2666 putc(slash[loopi++ % 8]);
2668 /* try again from with a different RQFD start value */
2670 goto calibration_loop;
2673 printf("\nERROR: Cannot determine a common read delay for the "
2674 "DIMM(s) installed.\n");
2675 debug("%s[%d] ERROR : \n", __FUNCTION__,__LINE__);
2676 ppc4xx_ibm_ddr2_register_dump();
2677 spd_ddr_init_hang ();
2680 if (rqfd_average < 0)
2683 if (rqfd_average > SDRAM_RQDC_RQFD_MAX)
2684 rqfd_average = SDRAM_RQDC_RQFD_MAX;
2687 (rqdc_reg & ~SDRAM_RQDC_RQFD_MASK) |
2688 SDRAM_RQDC_RQFD_ENCODE(rqfd_average));
2690 blank_string(strlen(str));
2691 #endif /* CONFIG_DDR_RQDC_FIXED */
2693 mfsdram(SDRAM_DLCR, val);
2694 debug("%s[%d] DLCR: 0x%08lX\n", __FUNCTION__, __LINE__, val);
2695 mfsdram(SDRAM_RQDC, val);
2696 debug("%s[%d] RQDC: 0x%08lX\n", __FUNCTION__, __LINE__, val);
2697 mfsdram(SDRAM_RFDC, val);
2698 debug("%s[%d] RFDC: 0x%08lX\n", __FUNCTION__, __LINE__, val);
2699 mfsdram(SDRAM_RDCC, val);
2700 debug("%s[%d] RDCC: 0x%08lX\n", __FUNCTION__, __LINE__, val);
2702 #else /* calibration test with hardvalues */
2703 /*-----------------------------------------------------------------------------+
2704 * DQS_calibration_process.
2705 *-----------------------------------------------------------------------------*/
2706 static void test(void)
2708 unsigned long dimm_num;
2709 unsigned long ecc_temp;
2711 unsigned long *membase;
2712 unsigned long bxcf[MAXRANKS];
2715 char begin_found[MAXDIMMS];
2716 char end_found[MAXDIMMS];
2717 char search_end[MAXDIMMS];
2718 unsigned long test[NUMMEMTESTS][NUMMEMWORDS] = {
2719 {0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF,
2720 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF},
2721 {0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000,
2722 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000},
2723 {0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555,
2724 0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555},
2725 {0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA,
2726 0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA},
2727 {0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A,
2728 0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A},
2729 {0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5,
2730 0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5},
2731 {0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA,
2732 0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA},
2733 {0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55,
2734 0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55} };
2736 /*------------------------------------------------------------------
2737 * Test to determine the best read clock delay tuning bits.
2739 * Before the DDR controller can be used, the read clock delay needs to be
2740 * set. This is SDRAM_RQDC[RQFD] and SDRAM_RFDC[RFFD].
2741 * This value cannot be hardcoded into the program because it changes
2742 * depending on the board's setup and environment.
2743 * To do this, all delay values are tested to see if they
2744 * work or not. By doing this, you get groups of fails with groups of
2745 * passing values. The idea is to find the start and end of a passing
2746 * window and take the center of it to use as the read clock delay.
2748 * A failure has to be seen first so that when we hit a pass, we know
2749 * that it is truely the start of the window. If we get passing values
2750 * to start off with, we don't know if we are at the start of the window.
2752 * The code assumes that a failure will always be found.
2753 * If a failure is not found, there is no easy way to get the middle
2754 * of the passing window. I guess we can pretty much pick any value
2755 * but some values will be better than others. Since the lowest speed
2756 * we can clock the DDR interface at is 200 MHz (2x 100 MHz PLB speed),
2757 * from experimentation it is safe to say you will always have a failure.
2758 *-----------------------------------------------------------------*/
2759 mfsdram(SDRAM_MCOPT1, ecc_temp);
2760 ecc_temp &= SDRAM_MCOPT1_MCHK_MASK;
2761 mfsdram(SDRAM_MCOPT1, val);
2762 mtsdram(SDRAM_MCOPT1, (val & ~SDRAM_MCOPT1_MCHK_MASK) |
2763 SDRAM_MCOPT1_MCHK_NON);
2765 window_found = false;
2766 begin_found[0] = false;
2767 end_found[0] = false;
2768 search_end[0] = false;
2769 begin_found[1] = false;
2770 end_found[1] = false;
2771 search_end[1] = false;
2773 for (dimm_num = 0; dimm_num < MAXDIMMS; dimm_num++) {
2774 mfsdram(SDRAM_MB0CF + (bxcr_num << 2), bxcf[bxcr_num]);
2777 if ((bxcf[dimm_num] & SDRAM_BXCF_M_BE_MASK) == SDRAM_BXCF_M_BE_ENABLE) {
2779 /* Bank is enabled */
2781 (unsigned long*)(SDRAM_RXBAS_SDBA_DECODE(mfdcr_any(SDRAM_R0BAS+dimm_num)));
2783 /*------------------------------------------------------------------
2784 * Run the short memory test.
2785 *-----------------------------------------------------------------*/
2786 for (i = 0; i < NUMMEMTESTS; i++) {
2787 for (j = 0; j < NUMMEMWORDS; j++) {
2788 membase[j] = test[i][j];
2789 ppcDcbf((u32)&(membase[j]));
2792 for (j = 0; j < NUMMEMWORDS; j++) {
2793 if (membase[j] != test[i][j]) {
2794 ppcDcbf((u32)&(membase[j]));
2797 ppcDcbf((u32)&(membase[j]));
2800 if (j < NUMMEMWORDS)
2804 /*------------------------------------------------------------------
2805 * See if the rffd value passed.
2806 *-----------------------------------------------------------------*/
2807 if (i < NUMMEMTESTS) {
2808 if ((end_found[dimm_num] == false) &&
2809 (search_end[dimm_num] == true)) {
2810 end_found[dimm_num] = true;
2812 if ((end_found[0] == true) &&
2813 (end_found[1] == true))
2816 if (begin_found[dimm_num] == false) {
2817 begin_found[dimm_num] = true;
2818 search_end[dimm_num] = true;
2822 begin_found[dimm_num] = true;
2823 end_found[dimm_num] = true;
2827 if ((begin_found[0] == true) && (begin_found[1] == true))
2828 window_found = true;
2830 /*------------------------------------------------------------------
2831 * Make sure we found the valid read passing window. Halt if not
2832 *-----------------------------------------------------------------*/
2833 if (window_found == false) {
2834 printf("ERROR: Cannot determine a common read delay for the "
2835 "DIMM(s) installed.\n");
2836 spd_ddr_init_hang ();
2839 /*------------------------------------------------------------------
2840 * Restore the ECC variable to what it originally was
2841 *-----------------------------------------------------------------*/
2842 mtsdram(SDRAM_MCOPT1,
2843 (ppcMfdcr_sdram(SDRAM_MCOPT1) & ~SDRAM_MCOPT1_MCHK_MASK)
2846 #endif /* !HARD_CODED_DQS */
2847 #endif /* !defined(CONFIG_PPC4xx_DDR_AUTOCALIBRATION) */
2849 #else /* CONFIG_SPD_EEPROM */
2851 /*-----------------------------------------------------------------------------
2852 * Function: initdram
2853 * Description: Configures the PPC4xx IBM DDR1/DDR2 SDRAM memory controller.
2854 * The configuration is performed using static, compile-
2856 * Configures the PPC405EX(r) and PPC460EX/GT
2857 *---------------------------------------------------------------------------*/
2858 phys_size_t initdram(int board_type)
2862 #if defined(CONFIG_440)
2863 mtdcr(SDRAM_R0BAS, CONFIG_SYS_SDRAM_R0BAS);
2864 mtdcr(SDRAM_R1BAS, CONFIG_SYS_SDRAM_R1BAS);
2865 mtdcr(SDRAM_R2BAS, CONFIG_SYS_SDRAM_R2BAS);
2866 mtdcr(SDRAM_R3BAS, CONFIG_SYS_SDRAM_R3BAS);
2867 mtdcr(SDRAM_PLBADDULL, CONFIG_SYS_SDRAM_PLBADDULL); /* MQ0_BAUL */
2868 mtdcr(SDRAM_PLBADDUHB, CONFIG_SYS_SDRAM_PLBADDUHB); /* MQ0_BAUH */
2869 mtdcr(SDRAM_CONF1LL, CONFIG_SYS_SDRAM_CONF1LL);
2870 mtdcr(SDRAM_CONF1HB, CONFIG_SYS_SDRAM_CONF1HB);
2871 mtdcr(SDRAM_CONFPATHB, CONFIG_SYS_SDRAM_CONFPATHB);
2874 /* Set Memory Bank Configuration Registers */
2876 mtsdram(SDRAM_MB0CF, CONFIG_SYS_SDRAM0_MB0CF);
2877 mtsdram(SDRAM_MB1CF, CONFIG_SYS_SDRAM0_MB1CF);
2878 mtsdram(SDRAM_MB2CF, CONFIG_SYS_SDRAM0_MB2CF);
2879 mtsdram(SDRAM_MB3CF, CONFIG_SYS_SDRAM0_MB3CF);
2881 /* Set Memory Clock Timing Register */
2883 mtsdram(SDRAM_CLKTR, CONFIG_SYS_SDRAM0_CLKTR);
2885 /* Set Refresh Time Register */
2887 mtsdram(SDRAM_RTR, CONFIG_SYS_SDRAM0_RTR);
2889 /* Set SDRAM Timing Registers */
2891 mtsdram(SDRAM_SDTR1, CONFIG_SYS_SDRAM0_SDTR1);
2892 mtsdram(SDRAM_SDTR2, CONFIG_SYS_SDRAM0_SDTR2);
2893 mtsdram(SDRAM_SDTR3, CONFIG_SYS_SDRAM0_SDTR3);
2895 /* Set Mode and Extended Mode Registers */
2897 mtsdram(SDRAM_MMODE, CONFIG_SYS_SDRAM0_MMODE);
2898 mtsdram(SDRAM_MEMODE, CONFIG_SYS_SDRAM0_MEMODE);
2900 /* Set Memory Controller Options 1 Register */
2902 mtsdram(SDRAM_MCOPT1, CONFIG_SYS_SDRAM0_MCOPT1);
2904 /* Set Manual Initialization Control Registers */
2906 mtsdram(SDRAM_INITPLR0, CONFIG_SYS_SDRAM0_INITPLR0);
2907 mtsdram(SDRAM_INITPLR1, CONFIG_SYS_SDRAM0_INITPLR1);
2908 mtsdram(SDRAM_INITPLR2, CONFIG_SYS_SDRAM0_INITPLR2);
2909 mtsdram(SDRAM_INITPLR3, CONFIG_SYS_SDRAM0_INITPLR3);
2910 mtsdram(SDRAM_INITPLR4, CONFIG_SYS_SDRAM0_INITPLR4);
2911 mtsdram(SDRAM_INITPLR5, CONFIG_SYS_SDRAM0_INITPLR5);
2912 mtsdram(SDRAM_INITPLR6, CONFIG_SYS_SDRAM0_INITPLR6);
2913 mtsdram(SDRAM_INITPLR7, CONFIG_SYS_SDRAM0_INITPLR7);
2914 mtsdram(SDRAM_INITPLR8, CONFIG_SYS_SDRAM0_INITPLR8);
2915 mtsdram(SDRAM_INITPLR9, CONFIG_SYS_SDRAM0_INITPLR9);
2916 mtsdram(SDRAM_INITPLR10, CONFIG_SYS_SDRAM0_INITPLR10);
2917 mtsdram(SDRAM_INITPLR11, CONFIG_SYS_SDRAM0_INITPLR11);
2918 mtsdram(SDRAM_INITPLR12, CONFIG_SYS_SDRAM0_INITPLR12);
2919 mtsdram(SDRAM_INITPLR13, CONFIG_SYS_SDRAM0_INITPLR13);
2920 mtsdram(SDRAM_INITPLR14, CONFIG_SYS_SDRAM0_INITPLR14);
2921 mtsdram(SDRAM_INITPLR15, CONFIG_SYS_SDRAM0_INITPLR15);
2923 /* Set On-Die Termination Registers */
2925 mtsdram(SDRAM_CODT, CONFIG_SYS_SDRAM0_CODT);
2926 mtsdram(SDRAM_MODT0, CONFIG_SYS_SDRAM0_MODT0);
2927 mtsdram(SDRAM_MODT1, CONFIG_SYS_SDRAM0_MODT1);
2929 /* Set Write Timing Register */
2931 mtsdram(SDRAM_WRDTR, CONFIG_SYS_SDRAM0_WRDTR);
2934 * Start Initialization by SDRAM0_MCOPT2[SREN] = 0 and
2935 * SDRAM0_MCOPT2[IPTR] = 1
2938 mtsdram(SDRAM_MCOPT2, (SDRAM_MCOPT2_SREN_EXIT |
2939 SDRAM_MCOPT2_IPTR_EXECUTE));
2942 * Poll SDRAM0_MCSTAT[MIC] for assertion to indicate the
2943 * completion of initialization.
2947 mfsdram(SDRAM_MCSTAT, val);
2948 } while ((val & SDRAM_MCSTAT_MIC_MASK) != SDRAM_MCSTAT_MIC_COMP);
2950 /* Set Delay Control Registers */
2952 mtsdram(SDRAM_DLCR, CONFIG_SYS_SDRAM0_DLCR);
2954 #if !defined(CONFIG_PPC4xx_DDR_AUTOCALIBRATION)
2955 mtsdram(SDRAM_RDCC, CONFIG_SYS_SDRAM0_RDCC);
2956 mtsdram(SDRAM_RQDC, CONFIG_SYS_SDRAM0_RQDC);
2957 mtsdram(SDRAM_RFDC, CONFIG_SYS_SDRAM0_RFDC);
2958 #endif /* !CONFIG_PPC4xx_DDR_AUTOCALIBRATION */
2961 * Enable Controller by SDRAM0_MCOPT2[DCEN] = 1:
2964 mfsdram(SDRAM_MCOPT2, val);
2965 mtsdram(SDRAM_MCOPT2, val | SDRAM_MCOPT2_DCEN_ENABLE);
2967 #if defined(CONFIG_440)
2969 * Program TLB entries with caches enabled, for best performace
2970 * while auto-calibrating and ECC generation
2972 program_tlb(0, 0, (CONFIG_SYS_MBYTES_SDRAM << 20), 0);
2975 #if defined(CONFIG_PPC4xx_DDR_AUTOCALIBRATION)
2976 /*------------------------------------------------------------------
2978 +-----------------------------------------------------------------*/
2979 DQS_autocalibration();
2980 #endif /* CONFIG_PPC4xx_DDR_AUTOCALIBRATION */
2983 * Now complete RDSS configuration as mentioned on page 7 of the AMCC
2984 * PowerPC440SP/SPe DDR2 application note:
2985 * "DDR1/DDR2 Initialization Sequence and Dynamic Tuning"
2989 #if defined(CONFIG_DDR_ECC)
2991 #endif /* defined(CONFIG_DDR_ECC) */
2993 #if defined(CONFIG_440)
2995 * Now after initialization (auto-calibration and ECC generation)
2996 * remove the TLB entries with caches enabled and program again with
2997 * desired cache functionality
2999 remove_tlb(0, (CONFIG_SYS_MBYTES_SDRAM << 20));
3000 program_tlb(0, 0, (CONFIG_SYS_MBYTES_SDRAM << 20), MY_TLB_WORD2_I_ENABLE);
3003 ppc4xx_ibm_ddr2_register_dump();
3005 #if defined(CONFIG_PPC4xx_DDR_AUTOCALIBRATION)
3007 * Clear potential errors resulting from auto-calibration.
3008 * If not done, then we could get an interrupt later on when
3009 * exceptions are enabled.
3011 set_mcsr(get_mcsr());
3012 #endif /* CONFIG_PPC4xx_DDR_AUTOCALIBRATION */
3014 return (CONFIG_SYS_MBYTES_SDRAM << 20);
3016 #endif /* CONFIG_SPD_EEPROM */
3018 #if defined(CONFIG_440)
3019 u32 mfdcr_any(u32 dcr)
3024 case SDRAM_R0BAS + 0:
3025 val = mfdcr(SDRAM_R0BAS + 0);
3027 case SDRAM_R0BAS + 1:
3028 val = mfdcr(SDRAM_R0BAS + 1);
3030 case SDRAM_R0BAS + 2:
3031 val = mfdcr(SDRAM_R0BAS + 2);
3033 case SDRAM_R0BAS + 3:
3034 val = mfdcr(SDRAM_R0BAS + 3);
3037 printf("DCR %d not defined in case statement!!!\n", dcr);
3038 val = 0; /* just to satisfy the compiler */
3044 void mtdcr_any(u32 dcr, u32 val)
3047 case SDRAM_R0BAS + 0:
3048 mtdcr(SDRAM_R0BAS + 0, val);
3050 case SDRAM_R0BAS + 1:
3051 mtdcr(SDRAM_R0BAS + 1, val);
3053 case SDRAM_R0BAS + 2:
3054 mtdcr(SDRAM_R0BAS + 2, val);
3056 case SDRAM_R0BAS + 3:
3057 mtdcr(SDRAM_R0BAS + 3, val);
3060 printf("DCR %d not defined in case statement!!!\n", dcr);
3063 #endif /* defined(CONFIG_440) */
3065 inline void ppc4xx_ibm_ddr2_register_dump(void)
3068 printf("\nPPC4xx IBM DDR2 Register Dump:\n");
3070 #if (defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
3071 defined(CONFIG_460EX) || defined(CONFIG_460GT))
3072 PPC4xx_IBM_DDR2_DUMP_MQ_REGISTER(R0BAS);
3073 PPC4xx_IBM_DDR2_DUMP_MQ_REGISTER(R1BAS);
3074 PPC4xx_IBM_DDR2_DUMP_MQ_REGISTER(R2BAS);
3075 PPC4xx_IBM_DDR2_DUMP_MQ_REGISTER(R3BAS);
3076 #endif /* (defined(CONFIG_440SP) || ... */
3077 #if defined(CONFIG_405EX)
3078 PPC4xx_IBM_DDR2_DUMP_REGISTER(BESR);
3079 PPC4xx_IBM_DDR2_DUMP_REGISTER(BEARL);
3080 PPC4xx_IBM_DDR2_DUMP_REGISTER(BEARH);
3081 PPC4xx_IBM_DDR2_DUMP_REGISTER(WMIRQ);
3082 PPC4xx_IBM_DDR2_DUMP_REGISTER(PLBOPT);
3083 PPC4xx_IBM_DDR2_DUMP_REGISTER(PUABA);
3084 #endif /* defined(CONFIG_405EX) */
3085 PPC4xx_IBM_DDR2_DUMP_REGISTER(MB0CF);
3086 PPC4xx_IBM_DDR2_DUMP_REGISTER(MB1CF);
3087 PPC4xx_IBM_DDR2_DUMP_REGISTER(MB2CF);
3088 PPC4xx_IBM_DDR2_DUMP_REGISTER(MB3CF);
3089 PPC4xx_IBM_DDR2_DUMP_REGISTER(MCSTAT);
3090 PPC4xx_IBM_DDR2_DUMP_REGISTER(MCOPT1);
3091 PPC4xx_IBM_DDR2_DUMP_REGISTER(MCOPT2);
3092 PPC4xx_IBM_DDR2_DUMP_REGISTER(MODT0);
3093 PPC4xx_IBM_DDR2_DUMP_REGISTER(MODT1);
3094 PPC4xx_IBM_DDR2_DUMP_REGISTER(MODT2);
3095 PPC4xx_IBM_DDR2_DUMP_REGISTER(MODT3);
3096 PPC4xx_IBM_DDR2_DUMP_REGISTER(CODT);
3097 #if (defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
3098 defined(CONFIG_460EX) || defined(CONFIG_460GT))
3099 PPC4xx_IBM_DDR2_DUMP_REGISTER(VVPR);
3100 PPC4xx_IBM_DDR2_DUMP_REGISTER(OPARS);
3102 * OPART is only used as a trigger register.
3104 * No data is contained in this register, and reading or writing
3105 * to is can cause bad things to happen (hangs). Just skip it and
3108 printf("%20s = N/A\n", "SDRAM_OPART");
3109 #endif /* defined(CONFIG_440SP) || ... */
3110 PPC4xx_IBM_DDR2_DUMP_REGISTER(RTR);
3111 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR0);
3112 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR1);
3113 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR2);
3114 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR3);
3115 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR4);
3116 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR5);
3117 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR6);
3118 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR7);
3119 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR8);
3120 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR9);
3121 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR10);
3122 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR11);
3123 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR12);
3124 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR13);
3125 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR14);
3126 PPC4xx_IBM_DDR2_DUMP_REGISTER(INITPLR15);
3127 PPC4xx_IBM_DDR2_DUMP_REGISTER(RQDC);
3128 PPC4xx_IBM_DDR2_DUMP_REGISTER(RFDC);
3129 PPC4xx_IBM_DDR2_DUMP_REGISTER(RDCC);
3130 PPC4xx_IBM_DDR2_DUMP_REGISTER(DLCR);
3131 PPC4xx_IBM_DDR2_DUMP_REGISTER(CLKTR);
3132 PPC4xx_IBM_DDR2_DUMP_REGISTER(WRDTR);
3133 PPC4xx_IBM_DDR2_DUMP_REGISTER(SDTR1);
3134 PPC4xx_IBM_DDR2_DUMP_REGISTER(SDTR2);
3135 PPC4xx_IBM_DDR2_DUMP_REGISTER(SDTR3);
3136 PPC4xx_IBM_DDR2_DUMP_REGISTER(MMODE);
3137 PPC4xx_IBM_DDR2_DUMP_REGISTER(MEMODE);
3138 PPC4xx_IBM_DDR2_DUMP_REGISTER(ECCES);
3139 #if (defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
3140 defined(CONFIG_460EX) || defined(CONFIG_460GT))
3141 PPC4xx_IBM_DDR2_DUMP_REGISTER(CID);
3142 #endif /* defined(CONFIG_440SP) || ... */
3143 PPC4xx_IBM_DDR2_DUMP_REGISTER(RID);
3144 PPC4xx_IBM_DDR2_DUMP_REGISTER(FCSR);
3145 PPC4xx_IBM_DDR2_DUMP_REGISTER(RTSR);
3146 #endif /* defined(DEBUG) */