📄 sdram_init.c
字号:
info->slot = slot; return 0;}#endif /* ! CONFIG_ZUMA_V2 */static intsetup_sdram_common(sdram_info_t info[2]){ ulong tmp; int tpar=2, tras_clocks=5, registered=1, ecc=2; if(!info[0].banks && !info[1].banks) return 0; if(info[0].banks) { if(info[0].tpar>tpar) tpar=info[0].tpar; if(info[0].tras_clocks>tras_clocks) tras_clocks=info[0].tras_clocks; if(!info[0].registered) registered=0; if(info[0].ecc!=2) ecc=0; } if(info[1].banks) { if(info[1].tpar>tpar) tpar=info[1].tpar; if(info[1].tras_clocks>tras_clocks) tras_clocks=info[1].tras_clocks; if(!info[1].registered) registered=0; if(info[1].ecc!=2) ecc=0; } /* SDRAM configuration */ tmp = GTREGREAD(SDRAM_CONFIGURATION); /* Turn on physical interleave if both DIMMs * have even numbers of banks. */ if( (info[0].banks == 0 || info[0].banks == 2) && (info[1].banks == 0 || info[1].banks == 2) ) { /* physical interleave on */ tmp &= ~(1 << 15); } else { /* physical interleave off */ tmp |= (1 << 15); } tmp |= (registered << 17); /* Use buffer 1 to return read data to the CPU * See Res #12 */ tmp |= (1 << 26); GT_REG_WRITE(SDRAM_CONFIGURATION, tmp); DP(printf("SDRAM config: %08x\n", GTREGREAD(SDRAM_CONFIGURATION))); /* SDRAM timing */ tmp = (((tpar == 3) ? 2 : 1) | (((tpar == 3) ? 2 : 1) << 2) | (((tpar == 3) ? 2 : 1) << 4) | (tras_clocks << 8));#ifdef CONFIG_ECC /* Setup ECC */ if (ecc == 2) tmp |= 1<<13;#endif /* CONFIG_ECC */ GT_REG_WRITE(SDRAM_TIMING, tmp); DP(printf("SDRAM timing: %08x (%d,%d,%d,%d)\n", GTREGREAD(SDRAM_TIMING), tpar,tpar,tpar,tras_clocks)); /* SDRAM address decode register */ /* program this with the default value */ GT_REG_WRITE(SDRAM_ADDRESS_DECODE, 0x2); DP(printf("SDRAM decode: %08x\n", GTREGREAD(SDRAM_ADDRESS_DECODE))); return 0;}/* sets up the GT properly with information passed in */static intsetup_sdram(sdram_info_t *info){ ulong tmp, check; ulong *addr = 0; int i; /* sanity checking */ if (! info->banks) return 0; /* ---------------------------- */ /* Program the GT with the discovered data */ /* bank parameters */ tmp = (0xf<<16); /* leave all virt bank pages open */ DP(printf("drb_size: %d\n", info->drb_size)); switch (info->drb_size) { case 1: tmp |= (1 << 14); break; case 4: case 8: tmp |= (2 << 14); break; case 16: case 32: tmp |= (3 << 14); break; default: printf("Error in dram size calculation\n"); return 1; } /* SDRAM bank parameters */ /* the param registers for slot 1 (banks 2+3) are offset by 0x8 */ GT_REG_WRITE(SDRAM_BANK0PARAMETERS + (info->slot * 0x8), tmp); GT_REG_WRITE(SDRAM_BANK1PARAMETERS + (info->slot * 0x8), tmp); DP(printf("SDRAM bankparam slot %d (bank %d+%d): %08lx\n", info->slot, info->slot*2, (info->slot*2)+1, tmp)); /* set the SDRAM configuration for each bank */ for (i = info->slot * 2; i < ((info->slot * 2) + info->banks); i++) { DP(printf("*** Running a MRS cycle for bank %d ***\n", i)); /* map the bank */ memory_map_bank(i, 0, GB/4); /* set SDRAM mode */ GT_REG_WRITE(SDRAM_OPERATION_MODE, 0x3); check = GTREGREAD(SDRAM_OPERATION_MODE); /* dummy write */ *addr = 0; /* wait for the command to complete */ while ((GTREGREAD(SDRAM_OPERATION_MODE) & (1 << 31)) == 0) ; /* switch back to normal operation mode */ GT_REG_WRITE(SDRAM_OPERATION_MODE, 0); check = GTREGREAD(SDRAM_OPERATION_MODE); /* unmap the bank */ memory_map_bank(i, 0, 0); DP(printf("*** MRS cycle for bank %d done ***\n", i)); } return 0;}/* * Check memory range for valid RAM. A simple memory test determines * the actually available RAM size between addresses `base' and * `base + maxsize'. Some (not all) hardware errors are detected: * - short between address lines * - short between data lines */static long intdram_size(long int *base, long int maxsize){ volatile long int *addr, *b=base; long int cnt, val, save1, save2;#define STARTVAL (1<<20) /* start test at 1M */ for (cnt = STARTVAL/sizeof(long); cnt < maxsize/sizeof(long); cnt <<= 1) { addr = base + cnt; /* pointer arith! */ save1=*addr; /* save contents of addr */ save2=*b; /* save contents of base */ *addr=cnt; /* write cnt to addr */ *b=0; /* put null at base */ /* check at base address */ if ((*b) != 0) { *addr=save1; /* restore *addr */ *b=save2; /* restore *b */ return (0); } val = *addr; /* read *addr */ *addr=save1; *b=save2; if (val != cnt) { /* fix boundary condition.. STARTVAL means zero */ if(cnt==STARTVAL/sizeof(long)) cnt=0; return (cnt * sizeof(long)); } } return maxsize;}/* ------------------------------------------------------------------------- *//* U-Boot interface function to SDRAM init - this is where all the * controlling logic happens */long intinitdram(int board_type){ ulong checkbank[4] = { [0 ... 3] = 0 }; int bank_no; ulong total; int nhr; sdram_info_t dimm_info[2]; /* first, use the SPD to get info about the SDRAM */ /* check the NHR bit and skip mem init if it's already done */ nhr = get_hid0() & (1 << 16); if (nhr) { printf("Skipping SDRAM setup due to NHR bit being set\n"); } else { /* DIMM0 */ check_dimm(0, &dimm_info[0]); /* DIMM1 */#ifndef CONFIG_EVB64260_750CX /* EVB64260_750CX has only 1 DIMM */ check_dimm(1, &dimm_info[1]);#else /* CONFIG_EVB64260_750CX */ memset(&dimm_info[1], 0, sizeof(sdram_info_t));#endif /* unmap all banks */ memory_map_bank(0, 0, 0); memory_map_bank(1, 0, 0); memory_map_bank(2, 0, 0); memory_map_bank(3, 0, 0); /* Now, program the GT with the correct values */ if (setup_sdram_common(dimm_info)) { printf("Setup common failed.\n"); } if (setup_sdram(&dimm_info[0])) { printf("Setup for DIMM1 failed.\n"); } if (setup_sdram(&dimm_info[1])) { printf("Setup for DIMM2 failed.\n"); } /* set the NHR bit */ set_hid0(get_hid0() | (1 << 16)); } /* next, size the SDRAM banks */ total = 0; if (dimm_info[0].banks > 0) checkbank[0] = 1; if (dimm_info[0].banks > 1) checkbank[1] = 1; if (dimm_info[0].banks > 2) printf("Error, SPD claims DIMM1 has >2 banks\n"); if (dimm_info[1].banks > 0) checkbank[2] = 1; if (dimm_info[1].banks > 1) checkbank[3] = 1; if (dimm_info[1].banks > 2) printf("Error, SPD claims DIMM2 has >2 banks\n"); /* Generic dram sizer: works even if we don't have i2c DIMMs, * as long as the timing settings are more or less correct */ /* * pass 1: size all the banks, using first bat (0-256M) * limitation: we only support 256M per bank due to * us only having 1 BAT for all DRAM */ for (bank_no = 0; bank_no < CFG_DRAM_BANKS; bank_no++) { /* skip over banks that are not populated */ if (! checkbank[bank_no]) continue; DP(printf("checking bank %d\n", bank_no)); memory_map_bank(bank_no, 0, GB/4); checkbank[bank_no] = dram_size(NULL, GB/4); memory_map_bank(bank_no, 0, 0); DP(printf("bank %d %08lx\n", bank_no, checkbank[bank_no])); } /* * pass 2: contiguously map each bank into physical address * space. */ dimm_info[0].banks=dimm_info[1].banks=0; for (bank_no = 0; bank_no < CFG_DRAM_BANKS; bank_no++) { if(!checkbank[bank_no]) continue; dimm_info[bank_no/2].banks++; dimm_info[bank_no/2].size+=checkbank[bank_no]; memory_map_bank(bank_no, total, checkbank[bank_no]);#ifdef MAP_PCI memory_map_bank_pci(bank_no, total, checkbank[bank_no]);#endif total += checkbank[bank_no]; }#ifdef CONFIG_ECC#ifdef CONFIG_ZUMA_V2 /* * We always enable ECC when bank 2 and 3 are unpopulated * If we 2 or 3 are populated, we CAN'T support ECC. * (Zuma boards only support ECC in banks 0 and 1; assume that * in that configuration, ECC chips are mounted, even for stacked * chips) */ if (checkbank[2]==0 && checkbank[3]==0) { dimm_info[0].ecc=2; GT_REG_WRITE(SDRAM_TIMING, GTREGREAD(SDRAM_TIMING) | (1 << 13)); /* TODO: do we have to run MRS cycles again? */ }#endif /* CONFIG_ZUMA_V2 */ if (GTREGREAD(SDRAM_TIMING) & (1 << 13)) { puts("[ECC] "); }#endif /* CONFIG_ECC */#ifdef DEBUG dump_dimm_info(&dimm_info[0]); dump_dimm_info(&dimm_info[1]);#endif /* TODO: return at MOST 256M? */ /* return total > GB/4 ? GB/4 : total; */ return total;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -