void vpd_init(void) { volatile immap_t *im = (immap_t *)CFG_IMMR; volatile cpm8xx_t *cp = &(im->im_cpm); volatile i2c8xx_t *i2c = (i2c8xx_t *)&(im->im_i2c); volatile iic_t *iip; #ifdef WITH_MICROCODE_PATCH ulong reloc = 0; #endif iip = (iic_t *)&cp->cp_dparam[PROFF_IIC]; /* * kludge: when running from flash, no microcode patch can be * installed. However, the DPMEM usually contains non-zero * garbage at the relocatable patch base location, so lets clear * it now. This way the rest of the code can support the microcode * patch dynamically. */ if ((ulong)vpd_init & 0xff000000) iip->iic_rpbase = 0; #ifdef WITH_MICROCODE_PATCH /* Check for and use a microcode relocation patch. */ if ((reloc = iip->iic_rpbase)) iip = (iic_t *)&cp->cp_dpmem[iip->iic_rpbase]; #endif /* Initialize Port B IIC pins */ cp->cp_pbpar |= 0x00000030; cp->cp_pbdir |= 0x00000030; cp->cp_pbodr |= 0x00000030; i2c->i2c_i2mod = 0x04; /* filter clock */ i2c->i2c_i2add = 0x34; /* select an arbitrary (unique) address */ i2c->i2c_i2brg = 0x07; /* make clock run maximum slow */ i2c->i2c_i2cmr = 0x00; /* disable interrupts */ i2c->i2c_i2cer = 0x1f; /* clear events */ i2c->i2c_i2com = 0x01; /* configure i2c to work as master */ if (vpd_read(0xa4, (uchar*)VPD_P, VPD_EEPROM_SIZE, 0) != VPD_EEPROM_SIZE) { hang(); } }
long int initdram (int board_type) { volatile immap_t *immap = (immap_t *)CFG_IMMR; volatile memctl8xx_t *memctl = &immap->im_memctl; unsigned long ram_sz = 0; unsigned long dimm_sz = 0; dimm_t vpd_dimm, vpd_dram; unsigned int speed = board_get_cpufreq() / 1000000; if (vpd_read(0xa2, (uchar*)&vpd_dimm, sizeof(vpd_dimm), 0) > 0) { dimm_sz = get_ramsize(&vpd_dimm); } if (vpd_read(0xa6, (uchar*)&vpd_dram, sizeof(vpd_dram), 0) > 0) { ram_sz = get_ramsize(&vpd_dram); } /* * Only initialize memory controller when running from FLASH. * When running from RAM, don't touch it. */ if ((ulong)initdram & 0xff000000) { ulong dimm_bank; ulong br0_32 = memctl->memc_br0 & 0x400; switch(speed) { case 40: upmconfig(UPMA, (uint *)sdram_table_40, sizeof(sdram_table_40) / sizeof(uint)); memctl->memc_mptpr = 0x0200; memctl->memc_mamr = dimm_sz ? 0x06801000 : 0x13801000; memctl->memc_br0 = 0xfe000000 | br0_32 | 1; memctl->memc_or0 = 0xff800930; memctl->memc_br7 = 0xfc000000 | (br0_32 ^ br0_32) | 1; memctl->memc_or7 = 0xff800930; break; case 50: upmconfig(UPMA, (uint *)sdram_table_50, sizeof(sdram_table_50) / sizeof(uint)); memctl->memc_mptpr = 0x0200; memctl->memc_mamr = dimm_sz ? 0x08801000 : 0x1880100; memctl->memc_br0 = 0xfe000000 | br0_32 | 1; memctl->memc_or0 = 0xff800940; memctl->memc_br7 = 0xfc000000 | (br0_32 ^ br0_32) | 1; memctl->memc_or7 = 0xff800940; break; default: hang(); break; } /* now map ram and dimm, largest one first */ dimm_bank = dimm_sz / 2; if (!dimm_sz) { memctl->memc_br1 = CFG_SDRAM_BASE | 0x81; memctl->memc_or1 = ~(ram_sz - 1) | 0x400; memctl->memc_br2 = 0; memctl->memc_br3 = 0; } else if (ram_sz > dimm_bank) { memctl->memc_br1 = CFG_SDRAM_BASE | 0x81; memctl->memc_or1 = ~(ram_sz - 1) | 0x400; memctl->memc_br2 = (CFG_SDRAM_BASE + ram_sz) | 0x81; memctl->memc_or2 = ~(dimm_bank - 1) | 0x400; memctl->memc_br3 = (CFG_SDRAM_BASE + ram_sz + dimm_bank) | 0x81; memctl->memc_or3 = ~(dimm_bank - 1) | 0x400; } else { memctl->memc_br2 = CFG_SDRAM_BASE | 0x81; memctl->memc_or2 = ~(dimm_bank - 1) | 0x400; memctl->memc_br3 = (CFG_SDRAM_BASE + dimm_bank) | 0x81; memctl->memc_or3 = ~(dimm_bank - 1) | 0x400; memctl->memc_br1 = (CFG_SDRAM_BASE + dimm_sz) | 0x81; memctl->memc_or1 = ~(ram_sz - 1) | 0x400; } } return ram_sz + dimm_sz; }