···158158159159#define DDR_GET_VAL(val, mask, shift) (((val) >> (shift)) & (mask))160160161161+/*162162+ * Some U-Boot versions set the number of chipselects to two163163+ * for Sequoia/Rainier boards while they only have one chipselect164164+ * hardwired. Hardcode the number of chipselects to one165165+ * for sequioa/rainer board models or read the actual value166166+ * from the memory controller register DDR0_10 otherwise.167167+ */168168+static inline u32 ibm4xx_denali_get_cs(void)169169+{170170+ void *devp;171171+ char model[64];172172+ u32 val, cs;173173+174174+ devp = finddevice("/");175175+ if (!devp)176176+ goto read_cs;177177+178178+ if (getprop(devp, "model", model, sizeof(model)) <= 0)179179+ goto read_cs;180180+181181+ model[sizeof(model)-1] = 0;182182+183183+ if (!strcmp(model, "amcc,sequoia") ||184184+ !strcmp(model, "amcc,rainier"))185185+ return 1;186186+187187+read_cs:188188+ /* get CS value */189189+ val = SDRAM0_READ(DDR0_10);190190+191191+ val = DDR_GET_VAL(val, DDR_CS_MAP, DDR_CS_MAP_SHIFT);192192+ cs = 0;193193+ while (val) {194194+ if (val & 0x1)195195+ cs++;196196+ val = val >> 1;197197+ }198198+ return cs;199199+}200200+161201void ibm4xx_denali_fixup_memsize(void)162202{163203 u32 val, max_cs, max_col, max_row;···213173 max_col = DDR_GET_VAL(val, DDR_MAX_COL_REG, DDR_MAX_COL_REG_SHIFT);214174 max_row = DDR_GET_VAL(val, DDR_MAX_ROW_REG, DDR_MAX_ROW_REG_SHIFT);215175216216- /* get CS value */217217- val = SDRAM0_READ(DDR0_10);218218-219219- val = DDR_GET_VAL(val, DDR_CS_MAP, DDR_CS_MAP_SHIFT);220220- cs = 0;221221- while (val) {222222- if (val & 0x1)223223- cs++;224224- val = val >> 1;225225- }226226-176176+ cs = ibm4xx_denali_get_cs();227177 if (!cs)228178 fatal("No memory installed\n");229179 if (cs > max_cs)···223193 val = SDRAM0_READ(DDR0_14);224194225195 if (DDR_GET_VAL(val, DDR_REDUC, DDR_REDUC_SHIFT))226226- dpath = 8; /* 64 bits */227227- else228196 dpath = 4; /* 32 bits */197197+ else198198+ dpath = 8; /* 64 bits */229199230200 /* get address pins (rows) */231201 val = SDRAM0_READ(DDR0_42);