2 * 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 are 440SP/SPe.
7 * Stefan Roese, DENX Software Engineering, sr@denx.de.
9 * COPYRIGHT AMCC CORPORATION 2004
11 * See file CREDITS for list of people who contributed to this
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 /* define DEBUG for debugging output (obviously ;-)) */
40 #include <asm/processor.h>
43 #if defined(CONFIG_SPD_EEPROM) && \
44 (defined(CONFIG_440SP) || defined(CONFIG_440SPE))
60 #define MAX_SPD_BYTES 256 /* Max number of bytes on the DIMM's SPD EEPROM */
62 #define ONE_BILLION 1000000000
64 #define MULDIV64(m1, m2, d) (u32)(((u64)(m1) * (u64)(m2)) / (u64)(d))
67 static void ppc440sp_sdram_register_dump(void);
70 /*-----------------------------------------------------------------------------+
72 *-----------------------------------------------------------------------------*/
73 /* Defines for the Read Cycle Delay test */
77 /* Private Structure Definitions */
79 /* enum only to ease code for cas latency setting */
80 typedef enum ddr_cas_id {
88 /*-----------------------------------------------------------------------------+
90 *-----------------------------------------------------------------------------*/
91 static unsigned long sdram_memsize(void);
92 void program_tlb(u32 start, u32 size);
93 static void get_spd_info(unsigned long *dimm_populated,
94 unsigned char *iic0_dimm_addr,
95 unsigned long num_dimm_banks);
96 static void check_mem_type(unsigned long *dimm_populated,
97 unsigned char *iic0_dimm_addr,
98 unsigned long num_dimm_banks);
99 static void check_frequency(unsigned long *dimm_populated,
100 unsigned char *iic0_dimm_addr,
101 unsigned long num_dimm_banks);
102 static void check_rank_number(unsigned long *dimm_populated,
103 unsigned char *iic0_dimm_addr,
104 unsigned long num_dimm_banks);
105 static void check_voltage_type(unsigned long *dimm_populated,
106 unsigned char *iic0_dimm_addr,
107 unsigned long num_dimm_banks);
108 static void program_memory_queue(unsigned long *dimm_populated,
109 unsigned char *iic0_dimm_addr,
110 unsigned long num_dimm_banks);
111 static void program_codt(unsigned long *dimm_populated,
112 unsigned char *iic0_dimm_addr,
113 unsigned long num_dimm_banks);
114 static void program_mode(unsigned long *dimm_populated,
115 unsigned char *iic0_dimm_addr,
116 unsigned long num_dimm_banks,
117 ddr_cas_id_t *selected_cas);
118 static void program_tr(unsigned long *dimm_populated,
119 unsigned char *iic0_dimm_addr,
120 unsigned long num_dimm_banks);
121 static void program_rtr(unsigned long *dimm_populated,
122 unsigned char *iic0_dimm_addr,
123 unsigned long num_dimm_banks);
124 static void program_bxcf(unsigned long *dimm_populated,
125 unsigned char *iic0_dimm_addr,
126 unsigned long num_dimm_banks);
127 static void program_copt1(unsigned long *dimm_populated,
128 unsigned char *iic0_dimm_addr,
129 unsigned long num_dimm_banks);
130 static void program_initplr(unsigned long *dimm_populated,
131 unsigned char *iic0_dimm_addr,
132 unsigned long num_dimm_banks,
133 ddr_cas_id_t selected_cas);
134 static unsigned long is_ecc_enabled(void);
135 static void program_ecc(unsigned long *dimm_populated,
136 unsigned char *iic0_dimm_addr,
137 unsigned long num_dimm_banks);
138 static void program_ecc_addr(unsigned long start_address,
139 unsigned long num_bytes);
141 #ifdef HARD_CODED_DQS /* calibration test with hardvalues */
142 static void test(void);
144 static void DQS_calibration_process(void);
146 static void program_DQS_calibration(unsigned long *dimm_populated,
147 unsigned char *iic0_dimm_addr,
148 unsigned long num_dimm_banks);
150 static u32 mfdcr_any(u32 dcr)
155 case SDRAM_R0BAS + 0:
156 val = mfdcr(SDRAM_R0BAS + 0);
158 case SDRAM_R0BAS + 1:
159 val = mfdcr(SDRAM_R0BAS + 1);
161 case SDRAM_R0BAS + 2:
162 val = mfdcr(SDRAM_R0BAS + 2);
164 case SDRAM_R0BAS + 3:
165 val = mfdcr(SDRAM_R0BAS + 3);
168 printf("DCR %d not defined in case statement!!!\n", dcr);
169 val = 0; /* just to satisfy the compiler */
175 static void mtdcr_any(u32 dcr, u32 val)
178 case SDRAM_R0BAS + 0:
179 mtdcr(SDRAM_R0BAS + 0, val);
181 case SDRAM_R0BAS + 1:
182 mtdcr(SDRAM_R0BAS + 1, val);
184 case SDRAM_R0BAS + 2:
185 mtdcr(SDRAM_R0BAS + 2, val);
187 case SDRAM_R0BAS + 3:
188 mtdcr(SDRAM_R0BAS + 3, val);
191 printf("DCR %d not defined in case statement!!!\n", dcr);
195 static void wait_ddr_idle(void)
200 mfsdram(SDRAM_MCSTAT, val);
201 } while ((val & SDRAM_MCSTAT_IDLE_MASK) == SDRAM_MCSTAT_IDLE_NOT);
204 static unsigned char spd_read(uchar chip, uint addr)
206 unsigned char data[2];
208 if (i2c_probe(chip) == 0)
209 if (i2c_read(chip, addr, 1, data, 1) == 0)
215 /*-----------------------------------------------------------------------------+
217 *-----------------------------------------------------------------------------*/
218 static unsigned long sdram_memsize(void)
220 unsigned long mem_size;
221 unsigned long mcopt2;
222 unsigned long mcstat;
229 mfsdram(SDRAM_MCOPT2, mcopt2);
230 mfsdram(SDRAM_MCSTAT, mcstat);
232 /* DDR controller must be enabled and not in self-refresh. */
233 /* Otherwise memsize is zero. */
234 if (((mcopt2 & SDRAM_MCOPT2_DCEN_MASK) == SDRAM_MCOPT2_DCEN_ENABLE)
235 && ((mcopt2 & SDRAM_MCOPT2_SREN_MASK) == SDRAM_MCOPT2_SREN_EXIT)
236 && ((mcstat & (SDRAM_MCSTAT_MIC_MASK | SDRAM_MCSTAT_SRMS_MASK))
237 == (SDRAM_MCSTAT_MIC_COMP | SDRAM_MCSTAT_SRMS_NOT_SF))) {
238 for (i = 0; i < 4; i++) {
239 mfsdram(SDRAM_MB0CF + (i << 2), mb0cf);
241 if ((mb0cf & SDRAM_BXCF_M_BE_MASK) == SDRAM_BXCF_M_BE_ENABLE) {
242 sdsz = mfdcr_any(SDRAM_R0BAS + i) & SDRAM_RXBAS_SDSZ_MASK;
245 case SDRAM_RXBAS_SDSZ_8:
248 case SDRAM_RXBAS_SDSZ_16:
251 case SDRAM_RXBAS_SDSZ_32:
254 case SDRAM_RXBAS_SDSZ_64:
257 case SDRAM_RXBAS_SDSZ_128:
260 case SDRAM_RXBAS_SDSZ_256:
263 case SDRAM_RXBAS_SDSZ_512:
266 case SDRAM_RXBAS_SDSZ_1024:
269 case SDRAM_RXBAS_SDSZ_2048:
272 case SDRAM_RXBAS_SDSZ_4096:
283 mem_size *= 1024 * 1024;
287 /*-----------------------------------------------------------------------------+
288 * initdram. Initializes the 440SP Memory Queue and DDR SDRAM controller.
289 * Note: This routine runs from flash with a stack set up in the chip's
290 * sram space. It is important that the routine does not require .sbss, .bss or
291 * .data sections. It also cannot call routines that require these sections.
292 *-----------------------------------------------------------------------------*/
293 /*-----------------------------------------------------------------------------
295 * Description: Configures SDRAM memory banks for DDR operation.
296 * Auto Memory Configuration option reads the DDR SDRAM EEPROMs
297 * via the IIC bus and then configures the DDR SDRAM memory
298 * banks appropriately. If Auto Memory Configuration is
299 * not used, it is assumed that no DIMM is plugged
300 *-----------------------------------------------------------------------------*/
301 long int initdram(int board_type)
303 unsigned char spd0[MAX_SPD_BYTES];
304 unsigned char spd1[MAX_SPD_BYTES];
305 unsigned char *dimm_spd[MAXDIMMS];
306 unsigned long dimm_populated[MAXDIMMS];
307 unsigned char iic0_dimm_addr[MAXDIMMS];
308 unsigned long num_dimm_banks; /* on board dimm banks */
310 ddr_cas_id_t selected_cas;
311 unsigned long dram_size = 0;
313 num_dimm_banks = sizeof(iic0_dimm_addr);
315 /*------------------------------------------------------------------
316 * Set up an array of SPD matrixes.
317 *-----------------------------------------------------------------*/
321 /*------------------------------------------------------------------
322 * Set up an array of iic0 dimm addresses.
323 *-----------------------------------------------------------------*/
324 iic0_dimm_addr[0] = IIC0_DIMM0_ADDR;
325 iic0_dimm_addr[1] = IIC0_DIMM1_ADDR;
327 /*------------------------------------------------------------------
328 * Reset the DDR-SDRAM controller.
329 *-----------------------------------------------------------------*/
330 mtsdr(SDR0_SRST, 0x00200000);
331 mtsdr(SDR0_SRST, 0x00000000);
334 * Make sure I2C controller is initialized
338 /* switch to correct I2C bus */
339 I2C_SET_BUS(CFG_SPD_BUS_NUM);
340 i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE);
342 /*------------------------------------------------------------------
343 * Clear out the serial presence detect buffers.
344 * Perform IIC reads from the dimm. Fill in the spds.
345 * Check to see if the dimm slots are populated
346 *-----------------------------------------------------------------*/
347 get_spd_info(dimm_populated, iic0_dimm_addr, num_dimm_banks);
349 /*------------------------------------------------------------------
350 * Check the memory type for the dimms plugged.
351 *-----------------------------------------------------------------*/
352 check_mem_type(dimm_populated, iic0_dimm_addr, num_dimm_banks);
354 /*------------------------------------------------------------------
355 * Check the frequency supported for the dimms plugged.
356 *-----------------------------------------------------------------*/
357 check_frequency(dimm_populated, iic0_dimm_addr, num_dimm_banks);
359 /*------------------------------------------------------------------
360 * Check the total rank number.
361 *-----------------------------------------------------------------*/
362 check_rank_number(dimm_populated, iic0_dimm_addr, num_dimm_banks);
364 /*------------------------------------------------------------------
365 * Check the voltage type for the dimms plugged.
366 *-----------------------------------------------------------------*/
367 check_voltage_type(dimm_populated, iic0_dimm_addr, num_dimm_banks);
369 /*------------------------------------------------------------------
370 * Program SDRAM controller options 2 register
371 * Except Enabling of the memory controller.
372 *-----------------------------------------------------------------*/
373 mfsdram(SDRAM_MCOPT2, val);
374 mtsdram(SDRAM_MCOPT2,
376 ~(SDRAM_MCOPT2_SREN_MASK | SDRAM_MCOPT2_PMEN_MASK |
377 SDRAM_MCOPT2_IPTR_MASK | SDRAM_MCOPT2_XSRP_MASK |
378 SDRAM_MCOPT2_ISIE_MASK))
379 | (SDRAM_MCOPT2_SREN_ENTER | SDRAM_MCOPT2_PMEN_DISABLE |
380 SDRAM_MCOPT2_IPTR_IDLE | SDRAM_MCOPT2_XSRP_ALLOW |
381 SDRAM_MCOPT2_ISIE_ENABLE));
383 /*------------------------------------------------------------------
384 * Program SDRAM controller options 1 register
385 * Note: Does not enable the memory controller.
386 *-----------------------------------------------------------------*/
387 program_copt1(dimm_populated, iic0_dimm_addr, num_dimm_banks);
389 /*------------------------------------------------------------------
390 * Set the SDRAM Controller On Die Termination Register
391 *-----------------------------------------------------------------*/
392 program_codt(dimm_populated, iic0_dimm_addr, num_dimm_banks);
394 /*------------------------------------------------------------------
395 * Program SDRAM refresh register.
396 *-----------------------------------------------------------------*/
397 program_rtr(dimm_populated, iic0_dimm_addr, num_dimm_banks);
399 /*------------------------------------------------------------------
400 * Program SDRAM mode register.
401 *-----------------------------------------------------------------*/
402 program_mode(dimm_populated, iic0_dimm_addr, num_dimm_banks, &selected_cas);
404 /*------------------------------------------------------------------
405 * Set the SDRAM Write Data/DM/DQS Clock Timing Reg
406 *-----------------------------------------------------------------*/
407 mfsdram(SDRAM_WRDTR, val);
408 mtsdram(SDRAM_WRDTR, (val & ~(SDRAM_WRDTR_LLWP_MASK | SDRAM_WRDTR_WTR_MASK)) |
409 (SDRAM_WRDTR_LLWP_1_CYC | SDRAM_WRDTR_WTR_90_DEG_ADV));
411 /*------------------------------------------------------------------
412 * Set the SDRAM Clock Timing Register
413 *-----------------------------------------------------------------*/
414 mfsdram(SDRAM_CLKTR, val);
415 mtsdram(SDRAM_CLKTR, (val & ~SDRAM_CLKTR_CLKP_MASK) | SDRAM_CLKTR_CLKP_0_DEG);
417 /*------------------------------------------------------------------
418 * Program the BxCF registers.
419 *-----------------------------------------------------------------*/
420 program_bxcf(dimm_populated, iic0_dimm_addr, num_dimm_banks);
422 /*------------------------------------------------------------------
423 * Program SDRAM timing registers.
424 *-----------------------------------------------------------------*/
425 program_tr(dimm_populated, iic0_dimm_addr, num_dimm_banks);
427 /*------------------------------------------------------------------
428 * Set the Extended Mode register
429 *-----------------------------------------------------------------*/
430 mfsdram(SDRAM_MEMODE, val);
431 mtsdram(SDRAM_MEMODE,
432 (val & ~(SDRAM_MEMODE_DIC_MASK | SDRAM_MEMODE_DLL_MASK |
433 SDRAM_MEMODE_RTT_MASK | SDRAM_MEMODE_DQS_MASK)) |
434 (SDRAM_MEMODE_DIC_NORMAL | SDRAM_MEMODE_DLL_ENABLE
435 | SDRAM_MEMODE_RTT_75OHM | SDRAM_MEMODE_DQS_ENABLE));
437 /*------------------------------------------------------------------
438 * Program Initialization preload registers.
439 *-----------------------------------------------------------------*/
440 program_initplr(dimm_populated, iic0_dimm_addr, num_dimm_banks,
443 /*------------------------------------------------------------------
444 * Delay to ensure 200usec have elapsed since reset.
445 *-----------------------------------------------------------------*/
448 /*------------------------------------------------------------------
449 * Set the memory queue core base addr.
450 *-----------------------------------------------------------------*/
451 program_memory_queue(dimm_populated, iic0_dimm_addr, num_dimm_banks);
453 /*------------------------------------------------------------------
454 * Program SDRAM controller options 2 register
455 * Enable the memory controller.
456 *-----------------------------------------------------------------*/
457 mfsdram(SDRAM_MCOPT2, val);
458 mtsdram(SDRAM_MCOPT2,
459 (val & ~(SDRAM_MCOPT2_SREN_MASK | SDRAM_MCOPT2_DCEN_MASK |
460 SDRAM_MCOPT2_IPTR_MASK | SDRAM_MCOPT2_ISIE_MASK)) |
461 (SDRAM_MCOPT2_DCEN_ENABLE | SDRAM_MCOPT2_IPTR_EXECUTE));
463 /*------------------------------------------------------------------
464 * Wait for SDRAM_CFG0_DC_EN to complete.
465 *-----------------------------------------------------------------*/
467 mfsdram(SDRAM_MCSTAT, val);
468 } while ((val & SDRAM_MCSTAT_MIC_MASK) == SDRAM_MCSTAT_MIC_NOTCOMP);
470 /* get installed memory size */
471 dram_size = sdram_memsize();
473 /* and program tlb entries for this size (dynamic) */
474 program_tlb(0, dram_size);
476 #if 1 /* TODO: ECC support will come later */
477 /*------------------------------------------------------------------
478 * If ecc is enabled, initialize the parity bits.
479 *-----------------------------------------------------------------*/
480 program_ecc(dimm_populated, iic0_dimm_addr, num_dimm_banks);
483 /*------------------------------------------------------------------
485 *-----------------------------------------------------------------*/
486 program_DQS_calibration(dimm_populated, iic0_dimm_addr, num_dimm_banks);
489 ppc440sp_sdram_register_dump();
495 static void get_spd_info(unsigned long *dimm_populated,
496 unsigned char *iic0_dimm_addr,
497 unsigned long num_dimm_banks)
499 unsigned long dimm_num;
500 unsigned long dimm_found;
501 unsigned char num_of_bytes;
502 unsigned char total_size;
505 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
509 num_of_bytes = spd_read(iic0_dimm_addr[dimm_num], 0);
510 debug("\nspd_read(0x%x) returned %d\n",
511 iic0_dimm_addr[dimm_num], num_of_bytes);
512 total_size = spd_read(iic0_dimm_addr[dimm_num], 1);
513 debug("spd_read(0x%x) returned %d\n",
514 iic0_dimm_addr[dimm_num], total_size);
516 if ((num_of_bytes != 0) && (total_size != 0)) {
517 dimm_populated[dimm_num] = TRUE;
519 debug("DIMM slot %lu: populated\n", dimm_num);
521 dimm_populated[dimm_num] = FALSE;
522 debug("DIMM slot %lu: Not populated\n", dimm_num);
526 if (dimm_found == FALSE) {
527 printf("ERROR - No memory installed. Install a DDR-SDRAM DIMM.\n\n");
532 #ifdef CONFIG_ADD_RAM_INFO
533 void board_add_ram_info(int use_default)
535 if (is_ecc_enabled())
536 puts(" (ECC enabled)");
538 puts(" (ECC not enabled)");
542 /*------------------------------------------------------------------
543 * For the memory DIMMs installed, this routine verifies that they
544 * really are DDR specific DIMMs.
545 *-----------------------------------------------------------------*/
546 static void check_mem_type(unsigned long *dimm_populated,
547 unsigned char *iic0_dimm_addr,
548 unsigned long num_dimm_banks)
550 unsigned long dimm_num;
551 unsigned long dimm_type;
553 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
554 if (dimm_populated[dimm_num] == TRUE) {
555 dimm_type = spd_read(iic0_dimm_addr[dimm_num], 2);
558 printf("ERROR: Standard Fast Page Mode DRAM DIMM detected in "
559 "slot %d.\n", (unsigned int)dimm_num);
560 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
561 printf("Replace the DIMM module with a supported DIMM.\n\n");
565 printf("ERROR: EDO DIMM detected in slot %d.\n",
566 (unsigned int)dimm_num);
567 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
568 printf("Replace the DIMM module with a supported DIMM.\n\n");
572 printf("ERROR: Pipelined Nibble DIMM detected in slot %d.\n",
573 (unsigned int)dimm_num);
574 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
575 printf("Replace the DIMM module with a supported DIMM.\n\n");
579 printf("ERROR: SDRAM DIMM detected in slot %d.\n",
580 (unsigned int)dimm_num);
581 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
582 printf("Replace the DIMM module with a supported DIMM.\n\n");
586 printf("ERROR: Multiplexed ROM DIMM detected in slot %d.\n",
587 (unsigned int)dimm_num);
588 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
589 printf("Replace the DIMM module with a supported DIMM.\n\n");
593 printf("ERROR: SGRAM DIMM detected in slot %d.\n",
594 (unsigned int)dimm_num);
595 printf("Only DDR and DDR2 SDRAM DIMMs are supported.\n");
596 printf("Replace the DIMM module with a supported DIMM.\n\n");
600 debug("DIMM slot %d: DDR1 SDRAM detected\n", dimm_num);
601 dimm_populated[dimm_num] = SDRAM_DDR1;
604 debug("DIMM slot %d: DDR2 SDRAM detected\n", dimm_num);
605 dimm_populated[dimm_num] = SDRAM_DDR2;
608 printf("ERROR: Unknown DIMM detected in slot %d.\n",
609 (unsigned int)dimm_num);
610 printf("Only DDR1 and DDR2 SDRAM DIMMs are supported.\n");
611 printf("Replace the DIMM module with a supported DIMM.\n\n");
617 for (dimm_num = 1; dimm_num < num_dimm_banks; dimm_num++) {
618 if ((dimm_populated[dimm_num-1] != SDRAM_NONE)
619 && (dimm_populated[dimm_num] != SDRAM_NONE)
620 && (dimm_populated[dimm_num-1] != dimm_populated[dimm_num])) {
621 printf("ERROR: DIMM's DDR1 and DDR2 type can not be mixed.\n");
627 /*------------------------------------------------------------------
628 * For the memory DIMMs installed, this routine verifies that
629 * frequency previously calculated is supported.
630 *-----------------------------------------------------------------*/
631 static void check_frequency(unsigned long *dimm_populated,
632 unsigned char *iic0_dimm_addr,
633 unsigned long num_dimm_banks)
635 unsigned long dimm_num;
636 unsigned long tcyc_reg;
637 unsigned long cycle_time;
638 unsigned long calc_cycle_time;
639 unsigned long sdram_freq;
640 unsigned long sdr_ddrpll;
641 PPC440_SYS_INFO board_cfg;
643 /*------------------------------------------------------------------
644 * Get the board configuration info.
645 *-----------------------------------------------------------------*/
646 get_sys_info(&board_cfg);
648 mfsdr(sdr_ddr0, sdr_ddrpll);
649 sdram_freq = ((board_cfg.freqPLB) * SDR0_DDR0_DDRM_DECODE(sdr_ddrpll));
652 * calc_cycle_time is calculated from DDR frequency set by board/chip
653 * and is expressed in multiple of 10 picoseconds
654 * to match the way DIMM cycle time is calculated below.
656 calc_cycle_time = MULDIV64(ONE_BILLION, 100, sdram_freq);
658 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
659 if (dimm_populated[dimm_num] != SDRAM_NONE) {
660 tcyc_reg = spd_read(iic0_dimm_addr[dimm_num], 9);
662 * Byte 9, Cycle time for CAS Latency=X, is split into two nibbles:
663 * the higher order nibble (bits 4-7) designates the cycle time
664 * to a granularity of 1ns;
665 * the value presented by the lower order nibble (bits 0-3)
666 * has a granularity of .1ns and is added to the value designated
667 * by the higher nibble. In addition, four lines of the lower order
668 * nibble are assigned to support +.25,+.33, +.66 and +.75.
670 /* Convert from hex to decimal */
671 if ((tcyc_reg & 0x0F) == 0x0D)
672 cycle_time = (((tcyc_reg & 0xF0) >> 4) * 100) + 75;
673 else if ((tcyc_reg & 0x0F) == 0x0C)
674 cycle_time = (((tcyc_reg & 0xF0) >> 4) * 100) + 66;
675 else if ((tcyc_reg & 0x0F) == 0x0B)
676 cycle_time = (((tcyc_reg & 0xF0) >> 4) * 100) + 33;
677 else if ((tcyc_reg & 0x0F) == 0x0A)
678 cycle_time = (((tcyc_reg & 0xF0) >> 4) * 100) + 25;
680 cycle_time = (((tcyc_reg & 0xF0) >> 4) * 100) +
681 ((tcyc_reg & 0x0F)*10);
683 if (cycle_time > (calc_cycle_time + 10)) {
685 * the provided sdram cycle_time is too small
686 * for the available DIMM cycle_time.
687 * The additionnal 100ps is here to accept a small incertainty.
689 printf("ERROR: DRAM DIMM detected with cycle_time %d ps in "
690 "slot %d \n while calculated cycle time is %d ps.\n",
691 (unsigned int)(cycle_time*10),
692 (unsigned int)dimm_num,
693 (unsigned int)(calc_cycle_time*10));
694 printf("Replace the DIMM, or change DDR frequency via "
695 "strapping bits.\n\n");
702 /*------------------------------------------------------------------
703 * For the memory DIMMs installed, this routine verifies two
704 * ranks/banks maximum are availables.
705 *-----------------------------------------------------------------*/
706 static void check_rank_number(unsigned long *dimm_populated,
707 unsigned char *iic0_dimm_addr,
708 unsigned long num_dimm_banks)
710 unsigned long dimm_num;
711 unsigned long dimm_rank;
712 unsigned long total_rank = 0;
714 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
715 if (dimm_populated[dimm_num] != SDRAM_NONE) {
716 dimm_rank = spd_read(iic0_dimm_addr[dimm_num], 5);
717 if (((unsigned long)spd_read(iic0_dimm_addr[dimm_num], 2)) == 0x08)
718 dimm_rank = (dimm_rank & 0x0F) +1;
720 dimm_rank = dimm_rank & 0x0F;
723 if (dimm_rank > MAXRANKS) {
724 printf("ERROR: DRAM DIMM detected with %d ranks in "
725 "slot %d is not supported.\n", dimm_rank, dimm_num);
726 printf("Only %d ranks are supported for all DIMM.\n", MAXRANKS);
727 printf("Replace the DIMM module with a supported DIMM.\n\n");
730 total_rank += dimm_rank;
732 if (total_rank > MAXRANKS) {
733 printf("ERROR: DRAM DIMM detected with a total of %d ranks "
734 "for all slots.\n", (unsigned int)total_rank);
735 printf("Only %d ranks are supported for all DIMM.\n", MAXRANKS);
736 printf("Remove one of the DIMM modules.\n\n");
742 /*------------------------------------------------------------------
743 * only support 2.5V modules.
744 * This routine verifies this.
745 *-----------------------------------------------------------------*/
746 static void check_voltage_type(unsigned long *dimm_populated,
747 unsigned char *iic0_dimm_addr,
748 unsigned long num_dimm_banks)
750 unsigned long dimm_num;
751 unsigned long voltage_type;
753 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
754 if (dimm_populated[dimm_num] != SDRAM_NONE) {
755 voltage_type = spd_read(iic0_dimm_addr[dimm_num], 8);
756 switch (voltage_type) {
758 printf("ERROR: Only DIMMs DDR 2.5V or DDR2 1.8V are supported.\n");
759 printf("This DIMM is 5.0 Volt/TTL.\n");
760 printf("Replace the DIMM module in slot %d with a supported DIMM.\n\n",
761 (unsigned int)dimm_num);
765 printf("ERROR: Only DIMMs DDR 2.5V or DDR2 1.8V are supported.\n");
766 printf("This DIMM is LVTTL.\n");
767 printf("Replace the DIMM module in slot %d with a supported DIMM.\n\n",
768 (unsigned int)dimm_num);
772 printf("ERROR: Only DIMMs DDR 2.5V or DDR2 1.8V are supported.\n");
773 printf("This DIMM is 1.5 Volt.\n");
774 printf("Replace the DIMM module in slot %d with a supported DIMM.\n\n",
775 (unsigned int)dimm_num);
779 printf("ERROR: Only DIMMs DDR 2.5V or DDR2 1.8V are supported.\n");
780 printf("This DIMM is 3.3 Volt/TTL.\n");
781 printf("Replace the DIMM module in slot %d with a supported DIMM.\n\n",
782 (unsigned int)dimm_num);
786 /* 2.5 Voltage only for DDR1 */
789 /* 1.8 Voltage only for DDR2 */
792 printf("ERROR: Only DIMMs DDR 2.5V or DDR2 1.8V are supported.\n");
793 printf("Replace the DIMM module in slot %d with a supported DIMM.\n\n",
794 (unsigned int)dimm_num);
802 /*-----------------------------------------------------------------------------+
804 *-----------------------------------------------------------------------------*/
805 static void program_copt1(unsigned long *dimm_populated,
806 unsigned char *iic0_dimm_addr,
807 unsigned long num_dimm_banks)
809 unsigned long dimm_num;
810 unsigned long mcopt1;
811 unsigned long ecc_enabled;
812 unsigned long ecc = 0;
813 unsigned long data_width = 0;
814 unsigned long dimm_32bit;
815 unsigned long dimm_64bit;
816 unsigned long registered = 0;
817 unsigned long attribute = 0;
818 unsigned long buf0, buf1; /* TODO: code to be changed for IOP1.6 to support 4 DIMMs */
819 unsigned long bankcount;
820 unsigned long ddrtype;
829 /*------------------------------------------------------------------
830 * Set memory controller options reg 1, SDRAM_MCOPT1.
831 *-----------------------------------------------------------------*/
832 mfsdram(SDRAM_MCOPT1, val);
833 mcopt1 = val & ~(SDRAM_MCOPT1_MCHK_MASK | SDRAM_MCOPT1_RDEN_MASK |
834 SDRAM_MCOPT1_PMU_MASK | SDRAM_MCOPT1_DMWD_MASK |
835 SDRAM_MCOPT1_UIOS_MASK | SDRAM_MCOPT1_BCNT_MASK |
836 SDRAM_MCOPT1_DDR_TYPE_MASK | SDRAM_MCOPT1_RWOO_MASK |
837 SDRAM_MCOPT1_WOOO_MASK | SDRAM_MCOPT1_DCOO_MASK |
838 SDRAM_MCOPT1_DREF_MASK);
840 mcopt1 |= SDRAM_MCOPT1_QDEP;
841 mcopt1 |= SDRAM_MCOPT1_PMU_OPEN;
842 mcopt1 |= SDRAM_MCOPT1_RWOO_DISABLED;
843 mcopt1 |= SDRAM_MCOPT1_WOOO_DISABLED;
844 mcopt1 |= SDRAM_MCOPT1_DCOO_DISABLED;
845 mcopt1 |= SDRAM_MCOPT1_DREF_NORMAL;
847 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
848 if (dimm_populated[dimm_num] != SDRAM_NONE) {
849 /* test ecc support */
850 ecc = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 11);
851 if (ecc != 0x02) /* ecc not supported */
854 /* test bank count */
855 bankcount = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 17);
856 if (bankcount == 0x04) /* bank count = 4 */
857 mcopt1 |= SDRAM_MCOPT1_4_BANKS;
858 else /* bank count = 8 */
859 mcopt1 |= SDRAM_MCOPT1_8_BANKS;
862 ddrtype = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 2);
863 /* test for buffered/unbuffered, registered, differential clocks */
864 registered = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 20);
865 attribute = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 21);
867 /* TODO: code to be changed for IOP1.6 to support 4 DIMMs */
869 if (dimm_populated[dimm_num] == SDRAM_DDR1) /* DDR1 type */
870 mcopt1 |= SDRAM_MCOPT1_DDR1_TYPE;
871 if (dimm_populated[dimm_num] == SDRAM_DDR2) /* DDR2 type */
872 mcopt1 |= SDRAM_MCOPT1_DDR2_TYPE;
873 if (registered == 1) { /* DDR2 always buffered */
874 /* TODO: what about above comments ? */
875 mcopt1 |= SDRAM_MCOPT1_RDEN;
878 /* TODO: the mask 0x02 doesn't match Samsung def for byte 21. */
879 if ((attribute & 0x02) == 0x00) {
880 /* buffered not supported */
883 mcopt1 |= SDRAM_MCOPT1_RDEN;
888 else if (dimm_num == 1) {
889 if (dimm_populated[dimm_num] == SDRAM_DDR1) /* DDR1 type */
890 mcopt1 |= SDRAM_MCOPT1_DDR1_TYPE;
891 if (dimm_populated[dimm_num] == SDRAM_DDR2) /* DDR2 type */
892 mcopt1 |= SDRAM_MCOPT1_DDR2_TYPE;
893 if (registered == 1) {
894 /* DDR2 always buffered */
895 mcopt1 |= SDRAM_MCOPT1_RDEN;
898 if ((attribute & 0x02) == 0x00) {
899 /* buffered not supported */
902 mcopt1 |= SDRAM_MCOPT1_RDEN;
908 /* Note that for DDR2 the byte 7 is reserved, but OK to keep code as is. */
909 data_width = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 6) +
910 (((unsigned long)spd_read(iic0_dimm_addr[dimm_num], 7)) << 8);
912 switch (data_width) {
922 printf("WARNING: Detected a DIMM with a data width of %d bits.\n",
924 printf("Only DIMMs with 32 or 64 bit DDR-SDRAM widths are supported.\n");
930 /* verify matching properties */
931 if ((dimm_populated[0] != SDRAM_NONE) && (dimm_populated[1] != SDRAM_NONE)) {
933 printf("ERROR: DIMM's buffered/unbuffered, registered, clocking don't match.\n");
938 if ((dimm_64bit == TRUE) && (dimm_32bit == TRUE)) {
939 printf("ERROR: Cannot mix 32 bit and 64 bit DDR-SDRAM DIMMs together.\n");
942 else if ((dimm_64bit == TRUE) && (dimm_32bit == FALSE)) {
943 mcopt1 |= SDRAM_MCOPT1_DMWD_64;
944 } else if ((dimm_64bit == FALSE) && (dimm_32bit == TRUE)) {
945 mcopt1 |= SDRAM_MCOPT1_DMWD_32;
947 printf("ERROR: Please install only 32 or 64 bit DDR-SDRAM DIMMs.\n\n");
951 if (ecc_enabled == TRUE)
952 mcopt1 |= SDRAM_MCOPT1_MCHK_GEN;
954 mcopt1 |= SDRAM_MCOPT1_MCHK_NON;
956 mtsdram(SDRAM_MCOPT1, mcopt1);
959 /*-----------------------------------------------------------------------------+
961 *-----------------------------------------------------------------------------*/
962 static void program_codt(unsigned long *dimm_populated,
963 unsigned char *iic0_dimm_addr,
964 unsigned long num_dimm_banks)
967 unsigned long modt0 = 0;
968 unsigned long modt1 = 0;
969 unsigned long modt2 = 0;
970 unsigned long modt3 = 0;
971 unsigned char dimm_num;
972 unsigned char dimm_rank;
973 unsigned char total_rank = 0;
974 unsigned char total_dimm = 0;
975 unsigned char dimm_type = 0;
976 unsigned char firstSlot = 0;
978 /*------------------------------------------------------------------
979 * Set the SDRAM Controller On Die Termination Register
980 *-----------------------------------------------------------------*/
981 mfsdram(SDRAM_CODT, codt);
982 codt |= (SDRAM_CODT_IO_NMODE
983 & (~SDRAM_CODT_DQS_SINGLE_END
984 & ~SDRAM_CODT_CKSE_SINGLE_END
985 & ~SDRAM_CODT_FEEBBACK_RCV_SINGLE_END
986 & ~SDRAM_CODT_FEEBBACK_DRV_SINGLE_END));
988 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
989 if (dimm_populated[dimm_num] != SDRAM_NONE) {
990 dimm_rank = (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 5);
991 if (((unsigned long)spd_read(iic0_dimm_addr[dimm_num], 2)) == 0x08) {
992 dimm_rank = (dimm_rank & 0x0F) + 1;
993 dimm_type = SDRAM_DDR2;
995 dimm_rank = dimm_rank & 0x0F;
996 dimm_type = SDRAM_DDR1;
999 total_rank += dimm_rank;
1001 if ((dimm_num == 0) && (total_dimm == 1))
1007 if (dimm_type == SDRAM_DDR2) {
1008 codt |= SDRAM_CODT_DQS_1_8_V_DDR2;
1009 if ((total_dimm == 1) && (firstSlot == TRUE)) {
1010 if (total_rank == 1) {
1017 if (total_rank == 2) {
1025 if (total_rank == 1) {
1032 if (total_rank == 2) {
1040 if (total_dimm == 2) {
1041 if (total_rank == 2) {
1048 if (total_rank == 4) {
1057 codt |= SDRAM_CODT_DQS_2_5_V_DDR1;
1063 if (total_dimm == 1) {
1064 if (total_rank == 1)
1066 if (total_rank == 2)
1069 if (total_dimm == 2) {
1070 if (total_rank == 2)
1072 if (total_rank == 4)
1077 debug("nb of dimm %d\n", total_dimm);
1078 debug("nb of rank %d\n", total_rank);
1079 if (total_dimm == 1)
1080 debug("dimm in slot %d\n", firstSlot);
1082 mtsdram(SDRAM_CODT, codt);
1083 mtsdram(SDRAM_MODT0, modt0);
1084 mtsdram(SDRAM_MODT1, modt1);
1085 mtsdram(SDRAM_MODT2, modt2);
1086 mtsdram(SDRAM_MODT3, modt3);
1089 /*-----------------------------------------------------------------------------+
1091 *-----------------------------------------------------------------------------*/
1092 static void program_initplr(unsigned long *dimm_populated,
1093 unsigned char *iic0_dimm_addr,
1094 unsigned long num_dimm_banks,
1095 ddr_cas_id_t selected_cas)
1097 unsigned long MR_CAS_value = 0;
1099 /******************************************************
1100 ** Assumption: if more than one DIMM, all DIMMs are the same
1101 ** as already checked in check_memory_type
1102 ******************************************************/
1104 if ((dimm_populated[0] == SDRAM_DDR1) || (dimm_populated[1] == SDRAM_DDR1)) {
1105 mtsdram(SDRAM_INITPLR0, 0x81B80000);
1106 mtsdram(SDRAM_INITPLR1, 0x81900400);
1107 mtsdram(SDRAM_INITPLR2, 0x81810000);
1108 mtsdram(SDRAM_INITPLR3, 0xff800162);
1109 mtsdram(SDRAM_INITPLR4, 0x81900400);
1110 mtsdram(SDRAM_INITPLR5, 0x86080000);
1111 mtsdram(SDRAM_INITPLR6, 0x86080000);
1112 mtsdram(SDRAM_INITPLR7, 0x81000062);
1113 } else if ((dimm_populated[0] == SDRAM_DDR2) || (dimm_populated[1] == SDRAM_DDR2)) {
1114 switch (selected_cas) {
1116 * The CAS latency is a field of the Mode Reg
1117 * that need to be set from caller input.
1118 * CAS bits in Mode Reg are starting at bit 4 at least for the Micron DDR2
1119 * this is the reason of the shift.
1122 MR_CAS_value = 3 << 4;
1125 MR_CAS_value = 4 << 4;
1128 MR_CAS_value = 5 << 4;
1131 printf("ERROR: ucode error on selected_cas value %d", (unsigned char)selected_cas);
1136 mtsdram(SDRAM_INITPLR0, 0xB5380000); /* NOP */
1137 mtsdram(SDRAM_INITPLR1, 0x82100400); /* precharge 8 DDR clock cycle */
1138 mtsdram(SDRAM_INITPLR2, 0x80820000); /* EMR2 */
1139 mtsdram(SDRAM_INITPLR3, 0x80830000); /* EMR3 */
1140 mtsdram(SDRAM_INITPLR4, 0x80810000); /* EMR DLL ENABLE */
1141 mtsdram(SDRAM_INITPLR5, 0x80800502 | MR_CAS_value); /* MR w/ DLL reset */
1142 mtsdram(SDRAM_INITPLR6, 0x82100400); /* precharge 8 DDR clock cycle */
1143 mtsdram(SDRAM_INITPLR7, 0x8a080000); /* Refresh 50 DDR clock cycle */
1144 mtsdram(SDRAM_INITPLR8, 0x8a080000); /* Refresh 50 DDR clock cycle */
1145 mtsdram(SDRAM_INITPLR9, 0x8a080000); /* Refresh 50 DDR clock cycle */
1146 mtsdram(SDRAM_INITPLR10, 0x8a080000); /* Refresh 50 DDR clock cycle */
1147 mtsdram(SDRAM_INITPLR11, 0x80800402 | MR_CAS_value); /* MR w/o DLL reset */
1148 mtsdram(SDRAM_INITPLR12, 0x80810380); /* EMR OCD Default */
1149 mtsdram(SDRAM_INITPLR13, 0x80810000); /* EMR OCD Exit */
1151 printf("ERROR: ucode error as unknown DDR type in program_initplr");
1156 /*------------------------------------------------------------------
1157 * This routine programs the SDRAM_MMODE register.
1158 * the selected_cas is an output parameter, that will be passed
1159 * by caller to call the above program_initplr( )
1160 *-----------------------------------------------------------------*/
1161 static void program_mode(unsigned long *dimm_populated,
1162 unsigned char *iic0_dimm_addr,
1163 unsigned long num_dimm_banks,
1164 ddr_cas_id_t *selected_cas)
1166 unsigned long dimm_num;
1167 unsigned long sdram_ddr1;
1168 unsigned long t_wr_ns;
1169 unsigned long t_wr_clk;
1170 unsigned long cas_bit;
1171 unsigned long cas_index;
1172 unsigned long sdram_freq;
1173 unsigned long ddr_check;
1174 unsigned long mmode;
1175 unsigned long tcyc_reg;
1176 unsigned long cycle_2_0_clk;
1177 unsigned long cycle_2_5_clk;
1178 unsigned long cycle_3_0_clk;
1179 unsigned long cycle_4_0_clk;
1180 unsigned long cycle_5_0_clk;
1181 unsigned long max_2_0_tcyc_ns_x_100;
1182 unsigned long max_2_5_tcyc_ns_x_100;
1183 unsigned long max_3_0_tcyc_ns_x_100;
1184 unsigned long max_4_0_tcyc_ns_x_100;
1185 unsigned long max_5_0_tcyc_ns_x_100;
1186 unsigned long cycle_time_ns_x_100[3];
1187 PPC440_SYS_INFO board_cfg;
1188 unsigned char cas_2_0_available;
1189 unsigned char cas_2_5_available;
1190 unsigned char cas_3_0_available;
1191 unsigned char cas_4_0_available;
1192 unsigned char cas_5_0_available;
1193 unsigned long sdr_ddrpll;
1195 /*------------------------------------------------------------------
1196 * Get the board configuration info.
1197 *-----------------------------------------------------------------*/
1198 get_sys_info(&board_cfg);
1200 mfsdr(sdr_ddr0, sdr_ddrpll);
1201 sdram_freq = MULDIV64((board_cfg.freqPLB), SDR0_DDR0_DDRM_DECODE(sdr_ddrpll), 1);
1203 /*------------------------------------------------------------------
1204 * Handle the timing. We need to find the worst case timing of all
1205 * the dimm modules installed.
1206 *-----------------------------------------------------------------*/
1208 cas_2_0_available = TRUE;
1209 cas_2_5_available = TRUE;
1210 cas_3_0_available = TRUE;
1211 cas_4_0_available = TRUE;
1212 cas_5_0_available = TRUE;
1213 max_2_0_tcyc_ns_x_100 = 10;
1214 max_2_5_tcyc_ns_x_100 = 10;
1215 max_3_0_tcyc_ns_x_100 = 10;
1216 max_4_0_tcyc_ns_x_100 = 10;
1217 max_5_0_tcyc_ns_x_100 = 10;
1220 /* loop through all the DIMM slots on the board */
1221 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1222 /* If a dimm is installed in a particular slot ... */
1223 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1224 if (dimm_populated[dimm_num] == SDRAM_DDR1)
1229 /* t_wr_ns = max(t_wr_ns, (unsigned long)dimm_spd[dimm_num][36] >> 2); */ /* not used in this loop. */
1230 cas_bit = spd_read(iic0_dimm_addr[dimm_num], 18);
1232 /* For a particular DIMM, grab the three CAS values it supports */
1233 for (cas_index = 0; cas_index < 3; cas_index++) {
1234 switch (cas_index) {
1236 tcyc_reg = spd_read(iic0_dimm_addr[dimm_num], 9);
1239 tcyc_reg = spd_read(iic0_dimm_addr[dimm_num], 23);
1242 tcyc_reg = spd_read(iic0_dimm_addr[dimm_num], 25);
1246 if ((tcyc_reg & 0x0F) >= 10) {
1247 if ((tcyc_reg & 0x0F) == 0x0D) {
1248 /* Convert from hex to decimal */
1249 cycle_time_ns_x_100[cas_index] = (((tcyc_reg & 0xF0) >> 4) * 100) + 75;
1251 printf("ERROR: SPD reported Tcyc is incorrect for DIMM "
1252 "in slot %d\n", (unsigned int)dimm_num);
1256 /* Convert from hex to decimal */
1257 cycle_time_ns_x_100[cas_index] = (((tcyc_reg & 0xF0) >> 4) * 100) +
1258 ((tcyc_reg & 0x0F)*10);
1262 /* The rest of this routine determines if CAS 2.0, 2.5, 3.0, 4.0 and 5.0 are */
1263 /* supported for a particular DIMM. */
1268 * DDR devices use the following bitmask for CAS latency:
1269 * Bit 7 6 5 4 3 2 1 0
1270 * TBD 4.0 3.5 3.0 2.5 2.0 1.5 1.0
1272 if (((cas_bit & 0x40) == 0x40) && (cas_index < 3) && (cycle_time_ns_x_100[cas_index] != 0)) {
1273 max_4_0_tcyc_ns_x_100 = max(max_4_0_tcyc_ns_x_100, cycle_time_ns_x_100[cas_index]);
1278 cas_4_0_available = FALSE;
1281 if (((cas_bit & 0x10) == 0x10) && (cas_index < 3) && (cycle_time_ns_x_100[cas_index] != 0)) {
1282 max_3_0_tcyc_ns_x_100 = max(max_3_0_tcyc_ns_x_100, cycle_time_ns_x_100[cas_index]);
1287 cas_3_0_available = FALSE;
1290 if (((cas_bit & 0x08) == 0x08) && (cas_index < 3) && (cycle_time_ns_x_100[cas_index] != 0)) {
1291 max_2_5_tcyc_ns_x_100 = max(max_2_5_tcyc_ns_x_100, cycle_time_ns_x_100[cas_index]);
1296 cas_2_5_available = FALSE;
1299 if (((cas_bit & 0x04) == 0x04) && (cas_index < 3) && (cycle_time_ns_x_100[cas_index] != 0)) {
1300 max_2_0_tcyc_ns_x_100 = max(max_2_0_tcyc_ns_x_100, cycle_time_ns_x_100[cas_index]);
1305 cas_2_0_available = FALSE;
1309 * DDR2 devices use the following bitmask for CAS latency:
1310 * Bit 7 6 5 4 3 2 1 0
1311 * TBD 6.0 5.0 4.0 3.0 2.0 TBD TBD
1313 if (((cas_bit & 0x20) == 0x20) && (cas_index < 3) && (cycle_time_ns_x_100[cas_index] != 0)) {
1314 max_5_0_tcyc_ns_x_100 = max(max_5_0_tcyc_ns_x_100, cycle_time_ns_x_100[cas_index]);
1319 cas_5_0_available = FALSE;
1322 if (((cas_bit & 0x10) == 0x10) && (cas_index < 3) && (cycle_time_ns_x_100[cas_index] != 0)) {
1323 max_4_0_tcyc_ns_x_100 = max(max_4_0_tcyc_ns_x_100, cycle_time_ns_x_100[cas_index]);
1328 cas_4_0_available = FALSE;
1331 if (((cas_bit & 0x08) == 0x08) && (cas_index < 3) && (cycle_time_ns_x_100[cas_index] != 0)) {
1332 max_3_0_tcyc_ns_x_100 = max(max_3_0_tcyc_ns_x_100, cycle_time_ns_x_100[cas_index]);
1337 cas_3_0_available = FALSE;
1343 /*------------------------------------------------------------------
1344 * Set the SDRAM mode, SDRAM_MMODE
1345 *-----------------------------------------------------------------*/
1346 mfsdram(SDRAM_MMODE, mmode);
1347 mmode = mmode & ~(SDRAM_MMODE_WR_MASK | SDRAM_MMODE_DCL_MASK);
1349 cycle_2_0_clk = MULDIV64(ONE_BILLION, 100, max_2_0_tcyc_ns_x_100);
1350 cycle_2_5_clk = MULDIV64(ONE_BILLION, 100, max_2_5_tcyc_ns_x_100);
1351 cycle_3_0_clk = MULDIV64(ONE_BILLION, 100, max_3_0_tcyc_ns_x_100);
1352 cycle_4_0_clk = MULDIV64(ONE_BILLION, 100, max_4_0_tcyc_ns_x_100);
1353 cycle_5_0_clk = MULDIV64(ONE_BILLION, 100, max_5_0_tcyc_ns_x_100);
1355 if (sdram_ddr1 == TRUE) { /* DDR1 */
1356 if ((cas_2_0_available == TRUE) && (sdram_freq <= cycle_2_0_clk)) {
1357 mmode |= SDRAM_MMODE_DCL_DDR1_2_0_CLK;
1358 *selected_cas = DDR_CAS_2;
1359 } else if ((cas_2_5_available == TRUE) && (sdram_freq <= cycle_2_5_clk)) {
1360 mmode |= SDRAM_MMODE_DCL_DDR1_2_5_CLK;
1361 *selected_cas = DDR_CAS_2_5;
1362 } else if ((cas_3_0_available == TRUE) && (sdram_freq <= cycle_3_0_clk)) {
1363 mmode |= SDRAM_MMODE_DCL_DDR1_3_0_CLK;
1364 *selected_cas = DDR_CAS_3;
1366 printf("ERROR: Cannot find a supported CAS latency with the installed DIMMs.\n");
1367 printf("Only DIMMs DDR1 with CAS latencies of 2.0, 2.5, and 3.0 are supported.\n");
1368 printf("Make sure the PLB speed is within the supported range of the DIMMs.\n\n");
1372 if ((cas_3_0_available == TRUE) && (sdram_freq <= cycle_3_0_clk)) {
1373 mmode |= SDRAM_MMODE_DCL_DDR2_3_0_CLK;
1374 *selected_cas = DDR_CAS_3;
1375 } else if ((cas_4_0_available == TRUE) && (sdram_freq <= cycle_4_0_clk)) {
1376 mmode |= SDRAM_MMODE_DCL_DDR2_4_0_CLK;
1377 *selected_cas = DDR_CAS_4;
1378 } else if ((cas_5_0_available == TRUE) && (sdram_freq <= cycle_5_0_clk)) {
1379 mmode |= SDRAM_MMODE_DCL_DDR2_5_0_CLK;
1380 *selected_cas = DDR_CAS_5;
1382 printf("ERROR: Cannot find a supported CAS latency with the installed DIMMs.\n");
1383 printf("Only DIMMs DDR2 with CAS latencies of 3.0, 4.0, and 5.0 are supported.\n");
1384 printf("Make sure the PLB speed is within the supported range of the DIMMs.\n\n");
1389 if (sdram_ddr1 == TRUE)
1390 mmode |= SDRAM_MMODE_WR_DDR1;
1393 /* loop through all the DIMM slots on the board */
1394 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1395 /* If a dimm is installed in a particular slot ... */
1396 if (dimm_populated[dimm_num] != SDRAM_NONE)
1397 t_wr_ns = max(t_wr_ns,
1398 spd_read(iic0_dimm_addr[dimm_num], 36) >> 2);
1402 * convert from nanoseconds to ddr clocks
1403 * round up if necessary
1405 t_wr_clk = MULDIV64(sdram_freq, t_wr_ns, ONE_BILLION);
1406 ddr_check = MULDIV64(ONE_BILLION, t_wr_clk, t_wr_ns);
1407 if (sdram_freq != ddr_check)
1415 mmode |= SDRAM_MMODE_WR_DDR2_3_CYC;
1418 mmode |= SDRAM_MMODE_WR_DDR2_4_CYC;
1421 mmode |= SDRAM_MMODE_WR_DDR2_5_CYC;
1424 mmode |= SDRAM_MMODE_WR_DDR2_6_CYC;
1429 mtsdram(SDRAM_MMODE, mmode);
1432 /*-----------------------------------------------------------------------------+
1434 *-----------------------------------------------------------------------------*/
1435 static void program_rtr(unsigned long *dimm_populated,
1436 unsigned char *iic0_dimm_addr,
1437 unsigned long num_dimm_banks)
1439 PPC440_SYS_INFO board_cfg;
1440 unsigned long max_refresh_rate;
1441 unsigned long dimm_num;
1442 unsigned long refresh_rate_type;
1443 unsigned long refresh_rate;
1445 unsigned long sdram_freq;
1446 unsigned long sdr_ddrpll;
1449 /*------------------------------------------------------------------
1450 * Get the board configuration info.
1451 *-----------------------------------------------------------------*/
1452 get_sys_info(&board_cfg);
1454 /*------------------------------------------------------------------
1455 * Set the SDRAM Refresh Timing Register, SDRAM_RTR
1456 *-----------------------------------------------------------------*/
1457 mfsdr(sdr_ddr0, sdr_ddrpll);
1458 sdram_freq = ((board_cfg.freqPLB) * SDR0_DDR0_DDRM_DECODE(sdr_ddrpll));
1460 max_refresh_rate = 0;
1461 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1462 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1464 refresh_rate_type = spd_read(iic0_dimm_addr[dimm_num], 12);
1465 refresh_rate_type &= 0x7F;
1466 switch (refresh_rate_type) {
1468 refresh_rate = 15625;
1471 refresh_rate = 3906;
1474 refresh_rate = 7812;
1477 refresh_rate = 31250;
1480 refresh_rate = 62500;
1483 refresh_rate = 125000;
1487 printf("ERROR: DIMM %d unsupported refresh rate/type.\n",
1488 (unsigned int)dimm_num);
1489 printf("Replace the DIMM module with a supported DIMM.\n\n");
1494 max_refresh_rate = max(max_refresh_rate, refresh_rate);
1498 rint = MULDIV64(sdram_freq, max_refresh_rate, ONE_BILLION);
1499 mfsdram(SDRAM_RTR, val);
1500 mtsdram(SDRAM_RTR, (val & ~SDRAM_RTR_RINT_MASK) |
1501 (SDRAM_RTR_RINT_ENCODE(rint)));
1504 /*------------------------------------------------------------------
1505 * This routine programs the SDRAM_TRx registers.
1506 *-----------------------------------------------------------------*/
1507 static void program_tr(unsigned long *dimm_populated,
1508 unsigned char *iic0_dimm_addr,
1509 unsigned long num_dimm_banks)
1511 unsigned long dimm_num;
1512 unsigned long sdram_ddr1;
1513 unsigned long t_rp_ns;
1514 unsigned long t_rcd_ns;
1515 unsigned long t_rrd_ns;
1516 unsigned long t_ras_ns;
1517 unsigned long t_rc_ns;
1518 unsigned long t_rfc_ns;
1519 unsigned long t_wpc_ns;
1520 unsigned long t_wtr_ns;
1521 unsigned long t_rpc_ns;
1522 unsigned long t_rp_clk;
1523 unsigned long t_rcd_clk;
1524 unsigned long t_rrd_clk;
1525 unsigned long t_ras_clk;
1526 unsigned long t_rc_clk;
1527 unsigned long t_rfc_clk;
1528 unsigned long t_wpc_clk;
1529 unsigned long t_wtr_clk;
1530 unsigned long t_rpc_clk;
1531 unsigned long sdtr1, sdtr2, sdtr3;
1532 unsigned long ddr_check;
1533 unsigned long sdram_freq;
1534 unsigned long sdr_ddrpll;
1536 PPC440_SYS_INFO board_cfg;
1538 /*------------------------------------------------------------------
1539 * Get the board configuration info.
1540 *-----------------------------------------------------------------*/
1541 get_sys_info(&board_cfg);
1543 mfsdr(sdr_ddr0, sdr_ddrpll);
1544 sdram_freq = ((board_cfg.freqPLB) * SDR0_DDR0_DDRM_DECODE(sdr_ddrpll));
1546 /*------------------------------------------------------------------
1547 * Handle the timing. We need to find the worst case timing of all
1548 * the dimm modules installed.
1549 *-----------------------------------------------------------------*/
1561 /* loop through all the DIMM slots on the board */
1562 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1563 /* If a dimm is installed in a particular slot ... */
1564 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1565 if (dimm_populated[dimm_num] == SDRAM_DDR2)
1570 t_rcd_ns = max(t_rcd_ns, spd_read(iic0_dimm_addr[dimm_num], 29) >> 2);
1571 t_rrd_ns = max(t_rrd_ns, spd_read(iic0_dimm_addr[dimm_num], 28) >> 2);
1572 t_rp_ns = max(t_rp_ns, spd_read(iic0_dimm_addr[dimm_num], 27) >> 2);
1573 t_ras_ns = max(t_ras_ns, spd_read(iic0_dimm_addr[dimm_num], 30));
1574 t_rc_ns = max(t_rc_ns, spd_read(iic0_dimm_addr[dimm_num], 41));
1575 t_rfc_ns = max(t_rfc_ns, spd_read(iic0_dimm_addr[dimm_num], 42));
1579 /*------------------------------------------------------------------
1580 * Set the SDRAM Timing Reg 1, SDRAM_TR1
1581 *-----------------------------------------------------------------*/
1582 mfsdram(SDRAM_SDTR1, sdtr1);
1583 sdtr1 &= ~(SDRAM_SDTR1_LDOF_MASK | SDRAM_SDTR1_RTW_MASK |
1584 SDRAM_SDTR1_WTWO_MASK | SDRAM_SDTR1_RTRO_MASK);
1586 /* default values */
1587 sdtr1 |= SDRAM_SDTR1_LDOF_2_CLK;
1588 sdtr1 |= SDRAM_SDTR1_RTW_2_CLK;
1590 /* normal operations */
1591 sdtr1 |= SDRAM_SDTR1_WTWO_0_CLK;
1592 sdtr1 |= SDRAM_SDTR1_RTRO_1_CLK;
1594 mtsdram(SDRAM_SDTR1, sdtr1);
1596 /*------------------------------------------------------------------
1597 * Set the SDRAM Timing Reg 2, SDRAM_TR2
1598 *-----------------------------------------------------------------*/
1599 mfsdram(SDRAM_SDTR2, sdtr2);
1600 sdtr2 &= ~(SDRAM_SDTR2_RCD_MASK | SDRAM_SDTR2_WTR_MASK |
1601 SDRAM_SDTR2_XSNR_MASK | SDRAM_SDTR2_WPC_MASK |
1602 SDRAM_SDTR2_RPC_MASK | SDRAM_SDTR2_RP_MASK |
1603 SDRAM_SDTR2_RRD_MASK);
1606 * convert t_rcd from nanoseconds to ddr clocks
1607 * round up if necessary
1609 t_rcd_clk = MULDIV64(sdram_freq, t_rcd_ns, ONE_BILLION);
1610 ddr_check = MULDIV64(ONE_BILLION, t_rcd_clk, t_rcd_ns);
1611 if (sdram_freq != ddr_check)
1614 switch (t_rcd_clk) {
1617 sdtr2 |= SDRAM_SDTR2_RCD_1_CLK;
1620 sdtr2 |= SDRAM_SDTR2_RCD_2_CLK;
1623 sdtr2 |= SDRAM_SDTR2_RCD_3_CLK;
1626 sdtr2 |= SDRAM_SDTR2_RCD_4_CLK;
1629 sdtr2 |= SDRAM_SDTR2_RCD_5_CLK;
1633 if (sdram_ddr1 == TRUE) { /* DDR1 */
1634 if (sdram_freq < 200000000) {
1635 sdtr2 |= SDRAM_SDTR2_WTR_1_CLK;
1636 sdtr2 |= SDRAM_SDTR2_WPC_2_CLK;
1637 sdtr2 |= SDRAM_SDTR2_RPC_2_CLK;
1639 sdtr2 |= SDRAM_SDTR2_WTR_2_CLK;
1640 sdtr2 |= SDRAM_SDTR2_WPC_3_CLK;
1641 sdtr2 |= SDRAM_SDTR2_RPC_2_CLK;
1644 /* loop through all the DIMM slots on the board */
1645 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1646 /* If a dimm is installed in a particular slot ... */
1647 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1648 t_wpc_ns = max(t_wtr_ns, spd_read(iic0_dimm_addr[dimm_num], 36) >> 2);
1649 t_wtr_ns = max(t_wtr_ns, spd_read(iic0_dimm_addr[dimm_num], 37) >> 2);
1650 t_rpc_ns = max(t_rpc_ns, spd_read(iic0_dimm_addr[dimm_num], 38) >> 2);
1655 * convert from nanoseconds to ddr clocks
1656 * round up if necessary
1658 t_wpc_clk = MULDIV64(sdram_freq, t_wpc_ns, ONE_BILLION);
1659 ddr_check = MULDIV64(ONE_BILLION, t_wpc_clk, t_wpc_ns);
1660 if (sdram_freq != ddr_check)
1663 switch (t_wpc_clk) {
1667 sdtr2 |= SDRAM_SDTR2_WPC_2_CLK;
1670 sdtr2 |= SDRAM_SDTR2_WPC_3_CLK;
1673 sdtr2 |= SDRAM_SDTR2_WPC_4_CLK;
1676 sdtr2 |= SDRAM_SDTR2_WPC_5_CLK;
1679 sdtr2 |= SDRAM_SDTR2_WPC_6_CLK;
1684 * convert from nanoseconds to ddr clocks
1685 * round up if necessary
1687 t_wtr_clk = MULDIV64(sdram_freq, t_wtr_ns, ONE_BILLION);
1688 ddr_check = MULDIV64(ONE_BILLION, t_wtr_clk, t_wtr_ns);
1689 if (sdram_freq != ddr_check)
1692 switch (t_wtr_clk) {
1695 sdtr2 |= SDRAM_SDTR2_WTR_1_CLK;
1698 sdtr2 |= SDRAM_SDTR2_WTR_2_CLK;
1701 sdtr2 |= SDRAM_SDTR2_WTR_3_CLK;
1704 sdtr2 |= SDRAM_SDTR2_WTR_4_CLK;
1709 * convert from nanoseconds to ddr clocks
1710 * round up if necessary
1712 t_rpc_clk = MULDIV64(sdram_freq, t_rpc_ns, ONE_BILLION);
1713 ddr_check = MULDIV64(ONE_BILLION, t_rpc_clk, t_rpc_ns);
1714 if (sdram_freq != ddr_check)
1717 switch (t_rpc_clk) {
1721 sdtr2 |= SDRAM_SDTR2_RPC_2_CLK;
1724 sdtr2 |= SDRAM_SDTR2_RPC_3_CLK;
1727 sdtr2 |= SDRAM_SDTR2_RPC_4_CLK;
1733 sdtr2 |= SDRAM_SDTR2_XSNR_16_CLK;
1736 * convert t_rrd from nanoseconds to ddr clocks
1737 * round up if necessary
1739 t_rrd_clk = MULDIV64(sdram_freq, t_rrd_ns, ONE_BILLION);
1740 ddr_check = MULDIV64(ONE_BILLION, t_rrd_clk, t_rrd_ns);
1741 if (sdram_freq != ddr_check)
1745 sdtr2 |= SDRAM_SDTR2_RRD_3_CLK;
1747 sdtr2 |= SDRAM_SDTR2_RRD_2_CLK;
1750 * convert t_rp from nanoseconds to ddr clocks
1751 * round up if necessary
1753 t_rp_clk = MULDIV64(sdram_freq, t_rp_ns, ONE_BILLION);
1754 ddr_check = MULDIV64(ONE_BILLION, t_rp_clk, t_rp_ns);
1755 if (sdram_freq != ddr_check)
1763 sdtr2 |= SDRAM_SDTR2_RP_3_CLK;
1766 sdtr2 |= SDRAM_SDTR2_RP_4_CLK;
1769 sdtr2 |= SDRAM_SDTR2_RP_5_CLK;
1772 sdtr2 |= SDRAM_SDTR2_RP_6_CLK;
1775 sdtr2 |= SDRAM_SDTR2_RP_7_CLK;
1779 mtsdram(SDRAM_SDTR2, sdtr2);
1781 /*------------------------------------------------------------------
1782 * Set the SDRAM Timing Reg 3, SDRAM_TR3
1783 *-----------------------------------------------------------------*/
1784 mfsdram(SDRAM_SDTR3, sdtr3);
1785 sdtr3 &= ~(SDRAM_SDTR3_RAS_MASK | SDRAM_SDTR3_RC_MASK |
1786 SDRAM_SDTR3_XCS_MASK | SDRAM_SDTR3_RFC_MASK);
1789 * convert t_ras from nanoseconds to ddr clocks
1790 * round up if necessary
1792 t_ras_clk = MULDIV64(sdram_freq, t_ras_ns, ONE_BILLION);
1793 ddr_check = MULDIV64(ONE_BILLION, t_ras_clk, t_ras_ns);
1794 if (sdram_freq != ddr_check)
1797 sdtr3 |= SDRAM_SDTR3_RAS_ENCODE(t_ras_clk);
1800 * convert t_rc from nanoseconds to ddr clocks
1801 * round up if necessary
1803 t_rc_clk = MULDIV64(sdram_freq, t_rc_ns, ONE_BILLION);
1804 ddr_check = MULDIV64(ONE_BILLION, t_rc_clk, t_rc_ns);
1805 if (sdram_freq != ddr_check)
1808 sdtr3 |= SDRAM_SDTR3_RC_ENCODE(t_rc_clk);
1810 /* default xcs value */
1811 sdtr3 |= SDRAM_SDTR3_XCS;
1814 * convert t_rfc from nanoseconds to ddr clocks
1815 * round up if necessary
1817 t_rfc_clk = MULDIV64(sdram_freq, t_rfc_ns, ONE_BILLION);
1818 ddr_check = MULDIV64(ONE_BILLION, t_rfc_clk, t_rfc_ns);
1819 if (sdram_freq != ddr_check)
1822 sdtr3 |= SDRAM_SDTR3_RFC_ENCODE(t_rfc_clk);
1824 mtsdram(SDRAM_SDTR3, sdtr3);
1827 /*-----------------------------------------------------------------------------+
1829 *-----------------------------------------------------------------------------*/
1830 static void program_bxcf(unsigned long *dimm_populated,
1831 unsigned char *iic0_dimm_addr,
1832 unsigned long num_dimm_banks)
1834 unsigned long dimm_num;
1835 unsigned long num_col_addr;
1836 unsigned long num_ranks;
1837 unsigned long num_banks;
1839 unsigned long ind_rank;
1841 unsigned long ind_bank;
1842 unsigned long bank_0_populated;
1844 /*------------------------------------------------------------------
1845 * Set the BxCF regs. First, wipe out the bank config registers.
1846 *-----------------------------------------------------------------*/
1847 mtdcr(SDRAMC_CFGADDR, SDRAM_MB0CF);
1848 mtdcr(SDRAMC_CFGDATA, 0x00000000);
1849 mtdcr(SDRAMC_CFGADDR, SDRAM_MB1CF);
1850 mtdcr(SDRAMC_CFGDATA, 0x00000000);
1851 mtdcr(SDRAMC_CFGADDR, SDRAM_MB2CF);
1852 mtdcr(SDRAMC_CFGDATA, 0x00000000);
1853 mtdcr(SDRAMC_CFGADDR, SDRAM_MB3CF);
1854 mtdcr(SDRAMC_CFGDATA, 0x00000000);
1856 mode = SDRAM_BXCF_M_BE_ENABLE;
1858 bank_0_populated = 0;
1860 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1861 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1862 num_col_addr = spd_read(iic0_dimm_addr[dimm_num], 4);
1863 num_ranks = spd_read(iic0_dimm_addr[dimm_num], 5);
1864 if ((spd_read(iic0_dimm_addr[dimm_num], 2)) == 0x08)
1865 num_ranks = (num_ranks & 0x0F) +1;
1867 num_ranks = num_ranks & 0x0F;
1869 num_banks = spd_read(iic0_dimm_addr[dimm_num], 17);
1871 for (ind_bank = 0; ind_bank < 2; ind_bank++) {
1876 switch (num_col_addr) {
1878 mode |= (SDRAM_BXCF_M_AM_0 + ind);
1881 mode |= (SDRAM_BXCF_M_AM_1 + ind);
1884 mode |= (SDRAM_BXCF_M_AM_2 + ind);
1887 mode |= (SDRAM_BXCF_M_AM_3 + ind);
1890 mode |= (SDRAM_BXCF_M_AM_4 + ind);
1893 printf("DDR-SDRAM: DIMM %d BxCF configuration.\n",
1894 (unsigned int)dimm_num);
1895 printf("ERROR: Unsupported value for number of "
1896 "column addresses: %d.\n", (unsigned int)num_col_addr);
1897 printf("Replace the DIMM module with a supported DIMM.\n\n");
1902 if ((dimm_populated[dimm_num] != SDRAM_NONE)&& (dimm_num ==1))
1903 bank_0_populated = 1;
1905 for (ind_rank = 0; ind_rank < num_ranks; ind_rank++) {
1906 mtdcr(SDRAMC_CFGADDR, SDRAM_MB0CF + ((dimm_num + bank_0_populated + ind_rank) << 2));
1907 mtdcr(SDRAMC_CFGDATA, mode);
1913 /*------------------------------------------------------------------
1914 * program memory queue.
1915 *-----------------------------------------------------------------*/
1916 static void program_memory_queue(unsigned long *dimm_populated,
1917 unsigned char *iic0_dimm_addr,
1918 unsigned long num_dimm_banks)
1920 unsigned long dimm_num;
1921 unsigned long rank_base_addr;
1922 unsigned long rank_reg;
1923 unsigned long rank_size_bytes;
1924 unsigned long rank_size_id;
1925 unsigned long num_ranks;
1926 unsigned long baseadd_size;
1928 unsigned long bank_0_populated = 0;
1930 /*------------------------------------------------------------------
1931 * Reset the rank_base_address.
1932 *-----------------------------------------------------------------*/
1933 rank_reg = SDRAM_R0BAS;
1935 rank_base_addr = 0x00000000;
1937 for (dimm_num = 0; dimm_num < num_dimm_banks; dimm_num++) {
1938 if (dimm_populated[dimm_num] != SDRAM_NONE) {
1939 num_ranks = spd_read(iic0_dimm_addr[dimm_num], 5);
1940 if ((spd_read(iic0_dimm_addr[dimm_num], 2)) == 0x08)
1941 num_ranks = (num_ranks & 0x0F) + 1;
1943 num_ranks = num_ranks & 0x0F;
1945 rank_size_id = spd_read(iic0_dimm_addr[dimm_num], 31);
1947 /*------------------------------------------------------------------
1949 *-----------------------------------------------------------------*/
1951 rank_size_bytes = 1024 * 1024 * rank_size_id;
1952 switch (rank_size_id) {
1954 baseadd_size |= SDRAM_RXBAS_SDSZ_8;
1957 baseadd_size |= SDRAM_RXBAS_SDSZ_16;
1960 baseadd_size |= SDRAM_RXBAS_SDSZ_32;
1963 baseadd_size |= SDRAM_RXBAS_SDSZ_64;
1966 baseadd_size |= SDRAM_RXBAS_SDSZ_128;
1969 baseadd_size |= SDRAM_RXBAS_SDSZ_256;
1972 baseadd_size |= SDRAM_RXBAS_SDSZ_512;
1975 printf("DDR-SDRAM: DIMM %d memory queue configuration.\n",
1976 (unsigned int)dimm_num);
1977 printf("ERROR: Unsupported value for the banksize: %d.\n",
1978 (unsigned int)rank_size_id);
1979 printf("Replace the DIMM module with a supported DIMM.\n\n");
1983 if ((dimm_populated[dimm_num] != SDRAM_NONE) && (dimm_num == 1))
1984 bank_0_populated = 1;
1986 for (i = 0; i < num_ranks; i++) {
1987 mtdcr_any(rank_reg+i+dimm_num+bank_0_populated,
1988 (rank_base_addr & SDRAM_RXBAS_SDBA_MASK) |
1990 rank_base_addr += rank_size_bytes;
1996 /*-----------------------------------------------------------------------------+
1998 *-----------------------------------------------------------------------------*/
1999 static unsigned long is_ecc_enabled(void)
2001 unsigned long dimm_num;
2006 /* loop through all the DIMM slots on the board */
2007 for (dimm_num = 0; dimm_num < MAXDIMMS; dimm_num++) {
2008 mfsdram(SDRAM_MCOPT1, val);
2009 ecc = max(ecc, SDRAM_MCOPT1_MCHK_CHK_DECODE(val));
2015 /*-----------------------------------------------------------------------------+
2017 *-----------------------------------------------------------------------------*/
2018 static void program_ecc(unsigned long *dimm_populated,
2019 unsigned char *iic0_dimm_addr,
2020 unsigned long num_dimm_banks)
2022 unsigned long mcopt1;
2023 unsigned long mcopt2;
2024 unsigned long mcstat;
2025 unsigned long dimm_num;
2029 /* loop through all the DIMM slots on the board */
2030 for (dimm_num = 0; dimm_num < MAXDIMMS; dimm_num++) {
2031 /* If a dimm is installed in a particular slot ... */
2032 if (dimm_populated[dimm_num] != SDRAM_NONE)
2033 ecc = max(ecc, spd_read(iic0_dimm_addr[dimm_num], 11));
2038 mfsdram(SDRAM_MCOPT1, mcopt1);
2039 mfsdram(SDRAM_MCOPT2, mcopt2);
2041 if ((mcopt1 & SDRAM_MCOPT1_MCHK_MASK) != SDRAM_MCOPT1_MCHK_NON) {
2042 /* DDR controller must be enabled and not in self-refresh. */
2043 mfsdram(SDRAM_MCSTAT, mcstat);
2044 if (((mcopt2 & SDRAM_MCOPT2_DCEN_MASK) == SDRAM_MCOPT2_DCEN_ENABLE)
2045 && ((mcopt2 & SDRAM_MCOPT2_SREN_MASK) == SDRAM_MCOPT2_SREN_EXIT)
2046 && ((mcstat & (SDRAM_MCSTAT_MIC_MASK | SDRAM_MCSTAT_SRMS_MASK))
2047 == (SDRAM_MCSTAT_MIC_COMP | SDRAM_MCSTAT_SRMS_NOT_SF))) {
2049 program_ecc_addr(0, sdram_memsize());
2056 /*-----------------------------------------------------------------------------+
2058 *-----------------------------------------------------------------------------*/
2059 static void program_ecc_addr(unsigned long start_address,
2060 unsigned long num_bytes)
2062 unsigned long current_address;
2063 unsigned long end_address;
2064 unsigned long address_increment;
2065 unsigned long mcopt1;
2067 current_address = start_address;
2068 mfsdram(SDRAM_MCOPT1, mcopt1);
2069 if ((mcopt1 & SDRAM_MCOPT1_MCHK_MASK) != SDRAM_MCOPT1_MCHK_NON) {
2070 mtsdram(SDRAM_MCOPT1,
2071 (mcopt1 & ~SDRAM_MCOPT1_MCHK_MASK) | SDRAM_MCOPT1_MCHK_GEN);
2076 /* ECC bit set method for non-cached memory */
2077 if ((mcopt1 & SDRAM_MCOPT1_DMWD_MASK) == SDRAM_MCOPT1_DMWD_32)
2078 address_increment = 4;
2080 address_increment = 8;
2081 end_address = current_address + num_bytes;
2083 while (current_address < end_address) {
2084 *((unsigned long *)current_address) = 0x00000000;
2085 current_address += address_increment;
2091 mtsdram(SDRAM_MCOPT1,
2092 (mcopt1 & ~SDRAM_MCOPT1_MCHK_MASK) | SDRAM_MCOPT1_MCHK_CHK);
2099 /*-----------------------------------------------------------------------------+
2100 * program_DQS_calibration.
2101 *-----------------------------------------------------------------------------*/
2102 static void program_DQS_calibration(unsigned long *dimm_populated,
2103 unsigned char *iic0_dimm_addr,
2104 unsigned long num_dimm_banks)
2108 #ifdef HARD_CODED_DQS /* calibration test with hardvalues */
2109 mtsdram(SDRAM_RQDC, 0x80000037);
2110 mtsdram(SDRAM_RDCC, 0x40000000);
2111 mtsdram(SDRAM_RFDC, 0x000001DF);
2115 /*------------------------------------------------------------------
2116 * Program RDCC register
2117 * Read sample cycle auto-update enable
2118 *-----------------------------------------------------------------*/
2121 * Modified for the Katmai platform: with some DIMMs, the DDR2
2122 * controller automatically selects the T2 read cycle, but this
2123 * proves unreliable. Go ahead and force the DDR2 controller
2124 * to use the T4 sample and disable the automatic update of the
2127 mfsdram(SDRAM_RDCC, val);
2129 (val & ~(SDRAM_RDCC_RDSS_MASK | SDRAM_RDCC_RSAE_MASK))
2130 | (SDRAM_RDCC_RDSS_T4 | SDRAM_RDCC_RSAE_DISABLE));
2132 /*------------------------------------------------------------------
2133 * Program RQDC register
2134 * Internal DQS delay mechanism enable
2135 *-----------------------------------------------------------------*/
2136 mtsdram(SDRAM_RQDC, (SDRAM_RQDC_RQDE_ENABLE|SDRAM_RQDC_RQFD_ENCODE(0x38)));
2138 /*------------------------------------------------------------------
2139 * Program RFDC register
2140 * Set Feedback Fractional Oversample
2141 * Auto-detect read sample cycle enable
2142 *-----------------------------------------------------------------*/
2143 mfsdram(SDRAM_RFDC, val);
2145 (val & ~(SDRAM_RFDC_ARSE_MASK | SDRAM_RFDC_RFOS_MASK |
2146 SDRAM_RFDC_RFFD_MASK))
2147 | (SDRAM_RFDC_ARSE_ENABLE | SDRAM_RFDC_RFOS_ENCODE(0) |
2148 SDRAM_RFDC_RFFD_ENCODE(0)));
2150 DQS_calibration_process();
2154 static u32 short_mem_test(void)
2161 u32 test[NUMMEMTESTS][NUMMEMWORDS] = {
2162 {0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF,
2163 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF},
2164 {0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000,
2165 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000},
2166 {0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555,
2167 0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555},
2168 {0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA,
2169 0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA},
2170 {0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A,
2171 0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A},
2172 {0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5,
2173 0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5},
2174 {0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA,
2175 0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA},
2176 {0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55,
2177 0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55} };
2179 for (bxcr_num = 0; bxcr_num < MAXBXCF; bxcr_num++) {
2180 mfsdram(SDRAM_MB0CF + (bxcr_num << 2), bxcf);
2183 if ((bxcf & SDRAM_BXCF_M_BE_MASK) == SDRAM_BXCF_M_BE_ENABLE) {
2185 /* Bank is enabled */
2186 membase = (u32 *)(SDRAM_RXBAS_SDBA_DECODE(mfdcr_any(SDRAM_R0BAS+bxcr_num)));
2188 /*------------------------------------------------------------------
2189 * Run the short memory test.
2190 *-----------------------------------------------------------------*/
2191 for (i = 0; i < NUMMEMTESTS; i++) {
2192 for (j = 0; j < NUMMEMWORDS; j++) {
2193 membase[j] = test[i][j];
2194 ppcDcbf((u32)&(membase[j]));
2197 for (j = 0; j < NUMMEMWORDS; j++) {
2198 if (membase[j] != test[i][j]) {
2199 ppcDcbf((u32)&(membase[j]));
2202 ppcDcbf((u32)&(membase[j]));
2205 if (j < NUMMEMWORDS)
2208 if (i < NUMMEMTESTS)
2210 } /* if bank enabled */
2211 } /* for bxcf_num */
2216 #ifndef HARD_CODED_DQS
2217 /*-----------------------------------------------------------------------------+
2218 * DQS_calibration_process.
2219 *-----------------------------------------------------------------------------*/
2220 static void DQS_calibration_process(void)
2222 unsigned long ecc_temp;
2223 unsigned long rfdc_reg;
2225 unsigned long rqdc_reg;
2227 unsigned long bxcr_num;
2233 unsigned long begin_rqfd[MAXRANKS];
2234 unsigned long begin_rffd[MAXRANKS];
2235 unsigned long end_rqfd[MAXRANKS];
2236 unsigned long end_rffd[MAXRANKS];
2238 unsigned long dlycal;
2239 unsigned long dly_val;
2240 unsigned long max_pass_length;
2241 unsigned long current_pass_length;
2242 unsigned long current_fail_length;
2243 unsigned long current_start;
2245 unsigned char fail_found;
2246 unsigned char pass_found;
2248 /*------------------------------------------------------------------
2249 * Test to determine the best read clock delay tuning bits.
2251 * Before the DDR controller can be used, the read clock delay needs to be
2252 * set. This is SDRAM_RQDC[RQFD] and SDRAM_RFDC[RFFD].
2253 * This value cannot be hardcoded into the program because it changes
2254 * depending on the board's setup and environment.
2255 * To do this, all delay values are tested to see if they
2256 * work or not. By doing this, you get groups of fails with groups of
2257 * passing values. The idea is to find the start and end of a passing
2258 * window and take the center of it to use as the read clock delay.
2260 * A failure has to be seen first so that when we hit a pass, we know
2261 * that it is truely the start of the window. If we get passing values
2262 * to start off with, we don't know if we are at the start of the window.
2264 * The code assumes that a failure will always be found.
2265 * If a failure is not found, there is no easy way to get the middle
2266 * of the passing window. I guess we can pretty much pick any value
2267 * but some values will be better than others. Since the lowest speed
2268 * we can clock the DDR interface at is 200 MHz (2x 100 MHz PLB speed),
2269 * from experimentation it is safe to say you will always have a failure.
2270 *-----------------------------------------------------------------*/
2271 mfsdram(SDRAM_MCOPT1, ecc_temp);
2272 ecc_temp &= SDRAM_MCOPT1_MCHK_MASK;
2273 mfsdram(SDRAM_MCOPT1, val);
2274 mtsdram(SDRAM_MCOPT1, (val & ~SDRAM_MCOPT1_MCHK_MASK) |
2275 SDRAM_MCOPT1_MCHK_NON);
2287 window_found = FALSE;
2289 max_pass_length = 0;
2292 current_pass_length = 0;
2293 current_fail_length = 0;
2295 window_found = FALSE;
2299 /* first fix RQDC[RQFD] to an average of 80 degre phase shift to find RFDC[RFFD] */
2300 /* rqdc_reg = mfsdram(SDRAM_RQDC) & ~(SDRAM_RQDC_RQFD_MASK); */
2303 * get the delay line calibration register value
2305 mfsdram(SDRAM_DLCR, dlycal);
2306 dly_val = SDRAM_DLYCAL_DLCV_DECODE(dlycal) << 2;
2308 for (rffd = 0; rffd <= SDRAM_RFDC_RFFD_MAX; rffd++) {
2309 mfsdram(SDRAM_RFDC, rfdc_reg);
2310 rfdc_reg &= ~(SDRAM_RFDC_RFFD_MASK);
2312 /*------------------------------------------------------------------
2313 * Set the timing reg for the test.
2314 *-----------------------------------------------------------------*/
2315 mtsdram(SDRAM_RFDC, rfdc_reg | SDRAM_RFDC_RFFD_ENCODE(rffd));
2317 /* do the small memory test */
2318 bxcr_num = short_mem_test();
2320 /*------------------------------------------------------------------
2321 * See if the rffd value passed.
2322 *-----------------------------------------------------------------*/
2323 if (bxcr_num == MAXBXCF) {
2324 if (fail_found == TRUE) {
2326 if (current_pass_length == 0)
2327 current_start = rffd;
2329 current_fail_length = 0;
2330 current_pass_length++;
2332 if (current_pass_length > max_pass_length) {
2333 max_pass_length = current_pass_length;
2334 max_start = current_start;
2339 current_pass_length = 0;
2340 current_fail_length++;
2342 if (current_fail_length >= (dly_val >> 2)) {
2343 if (fail_found == FALSE) {
2345 } else if (pass_found == TRUE) {
2346 window_found = TRUE;
2354 /*------------------------------------------------------------------
2355 * Set the average RFFD value
2356 *-----------------------------------------------------------------*/
2357 rffd_average = ((max_start + max_end) >> 1);
2359 if (rffd_average < 0)
2362 if (rffd_average > SDRAM_RFDC_RFFD_MAX)
2363 rffd_average = SDRAM_RFDC_RFFD_MAX;
2364 /* now fix RFDC[RFFD] found and find RQDC[RQFD] */
2365 mtsdram(SDRAM_RFDC, rfdc_reg | SDRAM_RFDC_RFFD_ENCODE(rffd_average));
2367 max_pass_length = 0;
2370 current_pass_length = 0;
2371 current_fail_length = 0;
2373 window_found = FALSE;
2377 for (rqfd = 0; rqfd <= SDRAM_RQDC_RQFD_MAX; rqfd++) {
2378 mfsdram(SDRAM_RQDC, rqdc_reg);
2379 rqdc_reg &= ~(SDRAM_RQDC_RQFD_MASK);
2381 /*------------------------------------------------------------------
2382 * Set the timing reg for the test.
2383 *-----------------------------------------------------------------*/
2384 mtsdram(SDRAM_RQDC, rqdc_reg | SDRAM_RQDC_RQFD_ENCODE(rqfd));
2386 /* do the small memory test */
2387 bxcr_num = short_mem_test();
2389 /*------------------------------------------------------------------
2390 * See if the rffd value passed.
2391 *-----------------------------------------------------------------*/
2392 if (bxcr_num == MAXBXCF) {
2393 if (fail_found == TRUE) {
2395 if (current_pass_length == 0)
2396 current_start = rqfd;
2398 current_fail_length = 0;
2399 current_pass_length++;
2401 if (current_pass_length > max_pass_length) {
2402 max_pass_length = current_pass_length;
2403 max_start = current_start;
2408 current_pass_length = 0;
2409 current_fail_length++;
2411 if (fail_found == FALSE) {
2413 } else if (pass_found == TRUE) {
2414 window_found = TRUE;
2420 /*------------------------------------------------------------------
2421 * Make sure we found the valid read passing window. Halt if not
2422 *-----------------------------------------------------------------*/
2423 if (window_found == FALSE) {
2424 printf("ERROR: Cannot determine a common read delay for the "
2425 "DIMM(s) installed.\n");
2426 debug("%s[%d] ERROR : \n", __FUNCTION__,__LINE__);
2430 rqfd_average = ((max_start + max_end) >> 1);
2432 if (rqfd_average < 0)
2435 if (rqfd_average > SDRAM_RQDC_RQFD_MAX)
2436 rqfd_average = SDRAM_RQDC_RQFD_MAX;
2438 /*------------------------------------------------------------------
2439 * Restore the ECC variable to what it originally was
2440 *-----------------------------------------------------------------*/
2441 mfsdram(SDRAM_MCOPT1, val);
2442 mtsdram(SDRAM_MCOPT1, (val & ~SDRAM_MCOPT1_MCHK_MASK) | ecc_temp);
2445 (rqdc_reg & ~SDRAM_RQDC_RQFD_MASK) |
2446 SDRAM_RQDC_RQFD_ENCODE(rqfd_average));
2448 mfsdram(SDRAM_DLCR, val);
2449 debug("%s[%d] DLCR: 0x%08X\n", __FUNCTION__, __LINE__, val);
2450 mfsdram(SDRAM_RQDC, val);
2451 debug("%s[%d] RQDC: 0x%08X\n", __FUNCTION__, __LINE__, val);
2452 mfsdram(SDRAM_RFDC, val);
2453 debug("%s[%d] RFDC: 0x%08X\n", __FUNCTION__, __LINE__, val);
2455 #else /* calibration test with hardvalues */
2456 /*-----------------------------------------------------------------------------+
2457 * DQS_calibration_process.
2458 *-----------------------------------------------------------------------------*/
2459 static void test(void)
2461 unsigned long dimm_num;
2462 unsigned long ecc_temp;
2464 unsigned long *membase;
2465 unsigned long bxcf[MAXRANKS];
2468 char begin_found[MAXDIMMS];
2469 char end_found[MAXDIMMS];
2470 char search_end[MAXDIMMS];
2471 unsigned long test[NUMMEMTESTS][NUMMEMWORDS] = {
2472 {0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF,
2473 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF},
2474 {0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000,
2475 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000},
2476 {0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555,
2477 0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555},
2478 {0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA,
2479 0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA},
2480 {0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A,
2481 0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A},
2482 {0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5,
2483 0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5},
2484 {0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA,
2485 0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA},
2486 {0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55,
2487 0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55} };
2489 /*------------------------------------------------------------------
2490 * Test to determine the best read clock delay tuning bits.
2492 * Before the DDR controller can be used, the read clock delay needs to be
2493 * set. This is SDRAM_RQDC[RQFD] and SDRAM_RFDC[RFFD].
2494 * This value cannot be hardcoded into the program because it changes
2495 * depending on the board's setup and environment.
2496 * To do this, all delay values are tested to see if they
2497 * work or not. By doing this, you get groups of fails with groups of
2498 * passing values. The idea is to find the start and end of a passing
2499 * window and take the center of it to use as the read clock delay.
2501 * A failure has to be seen first so that when we hit a pass, we know
2502 * that it is truely the start of the window. If we get passing values
2503 * to start off with, we don't know if we are at the start of the window.
2505 * The code assumes that a failure will always be found.
2506 * If a failure is not found, there is no easy way to get the middle
2507 * of the passing window. I guess we can pretty much pick any value
2508 * but some values will be better than others. Since the lowest speed
2509 * we can clock the DDR interface at is 200 MHz (2x 100 MHz PLB speed),
2510 * from experimentation it is safe to say you will always have a failure.
2511 *-----------------------------------------------------------------*/
2512 mfsdram(SDRAM_MCOPT1, ecc_temp);
2513 ecc_temp &= SDRAM_MCOPT1_MCHK_MASK;
2514 mfsdram(SDRAM_MCOPT1, val);
2515 mtsdram(SDRAM_MCOPT1, (val & ~SDRAM_MCOPT1_MCHK_MASK) |
2516 SDRAM_MCOPT1_MCHK_NON);
2518 window_found = FALSE;
2519 begin_found[0] = FALSE;
2520 end_found[0] = FALSE;
2521 search_end[0] = FALSE;
2522 begin_found[1] = FALSE;
2523 end_found[1] = FALSE;
2524 search_end[1] = FALSE;
2526 for (dimm_num = 0; dimm_num < MAXDIMMS; dimm_num++) {
2527 mfsdram(SDRAM_MB0CF + (bxcr_num << 2), bxcf[bxcr_num]);
2530 if ((bxcf[dimm_num] & SDRAM_BXCF_M_BE_MASK) == SDRAM_BXCF_M_BE_ENABLE) {
2532 /* Bank is enabled */
2534 (unsigned long*)(SDRAM_RXBAS_SDBA_DECODE(mfdcr_any(SDRAM_R0BAS+dimm_num)));
2536 /*------------------------------------------------------------------
2537 * Run the short memory test.
2538 *-----------------------------------------------------------------*/
2539 for (i = 0; i < NUMMEMTESTS; i++) {
2540 for (j = 0; j < NUMMEMWORDS; j++) {
2541 membase[j] = test[i][j];
2542 ppcDcbf((u32)&(membase[j]));
2545 for (j = 0; j < NUMMEMWORDS; j++) {
2546 if (membase[j] != test[i][j]) {
2547 ppcDcbf((u32)&(membase[j]));
2550 ppcDcbf((u32)&(membase[j]));
2553 if (j < NUMMEMWORDS)
2557 /*------------------------------------------------------------------
2558 * See if the rffd value passed.
2559 *-----------------------------------------------------------------*/
2560 if (i < NUMMEMTESTS) {
2561 if ((end_found[dimm_num] == FALSE) &&
2562 (search_end[dimm_num] == TRUE)) {
2563 end_found[dimm_num] = TRUE;
2565 if ((end_found[0] == TRUE) &&
2566 (end_found[1] == TRUE))
2569 if (begin_found[dimm_num] == FALSE) {
2570 begin_found[dimm_num] = TRUE;
2571 search_end[dimm_num] = TRUE;
2575 begin_found[dimm_num] = TRUE;
2576 end_found[dimm_num] = TRUE;
2580 if ((begin_found[0] == TRUE) && (begin_found[1] == TRUE))
2581 window_found = TRUE;
2583 /*------------------------------------------------------------------
2584 * Make sure we found the valid read passing window. Halt if not
2585 *-----------------------------------------------------------------*/
2586 if (window_found == FALSE) {
2587 printf("ERROR: Cannot determine a common read delay for the "
2588 "DIMM(s) installed.\n");
2592 /*------------------------------------------------------------------
2593 * Restore the ECC variable to what it originally was
2594 *-----------------------------------------------------------------*/
2595 mtsdram(SDRAM_MCOPT1,
2596 (ppcMfdcr_sdram(SDRAM_MCOPT1) & ~SDRAM_MCOPT1_MCHK_MASK)
2602 static void ppc440sp_sdram_register_dump(void)
2604 unsigned int sdram_reg;
2605 unsigned int sdram_data;
2606 unsigned int dcr_data;
2608 printf("\n Register Dump:\n");
2609 sdram_reg = SDRAM_MCSTAT;
2610 mfsdram(sdram_reg, sdram_data);
2611 printf(" SDRAM_MCSTAT = 0x%08X", sdram_data);
2612 sdram_reg = SDRAM_MCOPT1;
2613 mfsdram(sdram_reg, sdram_data);
2614 printf(" SDRAM_MCOPT1 = 0x%08X\n", sdram_data);
2615 sdram_reg = SDRAM_MCOPT2;
2616 mfsdram(sdram_reg, sdram_data);
2617 printf(" SDRAM_MCOPT2 = 0x%08X", sdram_data);
2618 sdram_reg = SDRAM_MODT0;
2619 mfsdram(sdram_reg, sdram_data);
2620 printf(" SDRAM_MODT0 = 0x%08X\n", sdram_data);
2621 sdram_reg = SDRAM_MODT1;
2622 mfsdram(sdram_reg, sdram_data);
2623 printf(" SDRAM_MODT1 = 0x%08X", sdram_data);
2624 sdram_reg = SDRAM_MODT2;
2625 mfsdram(sdram_reg, sdram_data);
2626 printf(" SDRAM_MODT2 = 0x%08X\n", sdram_data);
2627 sdram_reg = SDRAM_MODT3;
2628 mfsdram(sdram_reg, sdram_data);
2629 printf(" SDRAM_MODT3 = 0x%08X", sdram_data);
2630 sdram_reg = SDRAM_CODT;
2631 mfsdram(sdram_reg, sdram_data);
2632 printf(" SDRAM_CODT = 0x%08X\n", sdram_data);
2633 sdram_reg = SDRAM_VVPR;
2634 mfsdram(sdram_reg, sdram_data);
2635 printf(" SDRAM_VVPR = 0x%08X", sdram_data);
2636 sdram_reg = SDRAM_OPARS;
2637 mfsdram(sdram_reg, sdram_data);
2638 printf(" SDRAM_OPARS = 0x%08X\n", sdram_data);
2640 * OPAR2 is only used as a trigger register.
2641 * No data is contained in this register, and reading or writing
2642 * to is can cause bad things to happen (hangs). Just skip it
2644 * sdram_reg = SDRAM_OPAR2;
2645 * mfsdram(sdram_reg, sdram_data);
2646 * printf(" SDRAM_OPAR2 = 0x%08X\n", sdram_data);
2648 printf(" SDRAM_OPART = N/A ");
2649 sdram_reg = SDRAM_RTR;
2650 mfsdram(sdram_reg, sdram_data);
2651 printf(" SDRAM_RTR = 0x%08X\n", sdram_data);
2652 sdram_reg = SDRAM_MB0CF;
2653 mfsdram(sdram_reg, sdram_data);
2654 printf(" SDRAM_MB0CF = 0x%08X", sdram_data);
2655 sdram_reg = SDRAM_MB1CF;
2656 mfsdram(sdram_reg, sdram_data);
2657 printf(" SDRAM_MB1CF = 0x%08X\n", sdram_data);
2658 sdram_reg = SDRAM_MB2CF;
2659 mfsdram(sdram_reg, sdram_data);
2660 printf(" SDRAM_MB2CF = 0x%08X", sdram_data);
2661 sdram_reg = SDRAM_MB3CF;
2662 mfsdram(sdram_reg, sdram_data);
2663 printf(" SDRAM_MB3CF = 0x%08X\n", sdram_data);
2664 sdram_reg = SDRAM_INITPLR0;
2665 mfsdram(sdram_reg, sdram_data);
2666 printf(" SDRAM_INITPLR0 = 0x%08X", sdram_data);
2667 sdram_reg = SDRAM_INITPLR1;
2668 mfsdram(sdram_reg, sdram_data);
2669 printf(" SDRAM_INITPLR1 = 0x%08X\n", sdram_data);
2670 sdram_reg = SDRAM_INITPLR2;
2671 mfsdram(sdram_reg, sdram_data);
2672 printf(" SDRAM_INITPLR2 = 0x%08X", sdram_data);
2673 sdram_reg = SDRAM_INITPLR3;
2674 mfsdram(sdram_reg, sdram_data);
2675 printf(" SDRAM_INITPLR3 = 0x%08X\n", sdram_data);
2676 sdram_reg = SDRAM_INITPLR4;
2677 mfsdram(sdram_reg, sdram_data);
2678 printf(" SDRAM_INITPLR4 = 0x%08X", sdram_data);
2679 sdram_reg = SDRAM_INITPLR5;
2680 mfsdram(sdram_reg, sdram_data);
2681 printf(" SDRAM_INITPLR5 = 0x%08X\n", sdram_data);
2682 sdram_reg = SDRAM_INITPLR6;
2683 mfsdram(sdram_reg, sdram_data);
2684 printf(" SDRAM_INITPLR6 = 0x%08X", sdram_data);
2685 sdram_reg = SDRAM_INITPLR7;
2686 mfsdram(sdram_reg, sdram_data);
2687 printf(" SDRAM_INITPLR7 = 0x%08X\n", sdram_data);
2688 sdram_reg = SDRAM_INITPLR8;
2689 mfsdram(sdram_reg, sdram_data);
2690 printf(" SDRAM_INITPLR8 = 0x%08X", sdram_data);
2691 sdram_reg = SDRAM_INITPLR9;
2692 mfsdram(sdram_reg, sdram_data);
2693 printf(" SDRAM_INITPLR9 = 0x%08X\n", sdram_data);
2694 sdram_reg = SDRAM_INITPLR10;
2695 mfsdram(sdram_reg, sdram_data);
2696 printf(" SDRAM_INITPLR10 = 0x%08X", sdram_data);
2697 sdram_reg = SDRAM_INITPLR11;
2698 mfsdram(sdram_reg, sdram_data);
2699 printf(" SDRAM_INITPLR11 = 0x%08X\n", sdram_data);
2700 sdram_reg = SDRAM_INITPLR12;
2701 mfsdram(sdram_reg, sdram_data);
2702 printf(" SDRAM_INITPLR12 = 0x%08X", sdram_data);
2703 sdram_reg = SDRAM_INITPLR13;
2704 mfsdram(sdram_reg, sdram_data);
2705 printf(" SDRAM_INITPLR13 = 0x%08X\n", sdram_data);
2706 sdram_reg = SDRAM_INITPLR14;
2707 mfsdram(sdram_reg, sdram_data);
2708 printf(" SDRAM_INITPLR14 = 0x%08X", sdram_data);
2709 sdram_reg = SDRAM_INITPLR15;
2710 mfsdram(sdram_reg, sdram_data);
2711 printf(" SDRAM_INITPLR15 = 0x%08X\n", sdram_data);
2712 sdram_reg = SDRAM_RQDC;
2713 mfsdram(sdram_reg, sdram_data);
2714 printf(" SDRAM_RQDC = 0x%08X", sdram_data);
2715 sdram_reg = SDRAM_RFDC;
2716 mfsdram(sdram_reg, sdram_data);
2717 printf(" SDRAM_RFDC = 0x%08X\n", sdram_data);
2718 sdram_reg = SDRAM_RDCC;
2719 mfsdram(sdram_reg, sdram_data);
2720 printf(" SDRAM_RDCC = 0x%08X", sdram_data);
2721 sdram_reg = SDRAM_DLCR;
2722 mfsdram(sdram_reg, sdram_data);
2723 printf(" SDRAM_DLCR = 0x%08X\n", sdram_data);
2724 sdram_reg = SDRAM_CLKTR;
2725 mfsdram(sdram_reg, sdram_data);
2726 printf(" SDRAM_CLKTR = 0x%08X", sdram_data);
2727 sdram_reg = SDRAM_WRDTR;
2728 mfsdram(sdram_reg, sdram_data);
2729 printf(" SDRAM_WRDTR = 0x%08X\n", sdram_data);
2730 sdram_reg = SDRAM_SDTR1;
2731 mfsdram(sdram_reg, sdram_data);
2732 printf(" SDRAM_SDTR1 = 0x%08X", sdram_data);
2733 sdram_reg = SDRAM_SDTR2;
2734 mfsdram(sdram_reg, sdram_data);
2735 printf(" SDRAM_SDTR2 = 0x%08X\n", sdram_data);
2736 sdram_reg = SDRAM_SDTR3;
2737 mfsdram(sdram_reg, sdram_data);
2738 printf(" SDRAM_SDTR3 = 0x%08X", sdram_data);
2739 sdram_reg = SDRAM_MMODE;
2740 mfsdram(sdram_reg, sdram_data);
2741 printf(" SDRAM_MMODE = 0x%08X\n", sdram_data);
2742 sdram_reg = SDRAM_MEMODE;
2743 mfsdram(sdram_reg, sdram_data);
2744 printf(" SDRAM_MEMODE = 0x%08X", sdram_data);
2745 sdram_reg = SDRAM_ECCCR;
2746 mfsdram(sdram_reg, sdram_data);
2747 printf(" SDRAM_ECCCR = 0x%08X\n\n", sdram_data);
2749 dcr_data = mfdcr(SDRAM_R0BAS);
2750 printf(" MQ0_B0BAS = 0x%08X", dcr_data);
2751 dcr_data = mfdcr(SDRAM_R1BAS);
2752 printf(" MQ1_B0BAS = 0x%08X\n", dcr_data);
2753 dcr_data = mfdcr(SDRAM_R2BAS);
2754 printf(" MQ2_B0BAS = 0x%08X", dcr_data);
2755 dcr_data = mfdcr(SDRAM_R3BAS);
2756 printf(" MQ3_B0BAS = 0x%08X\n", dcr_data);
2759 #endif /* CONFIG_SPD_EEPROM */