From ac4f21631be94b18b9618bf909e50c3ba534149f Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Sun, 1 Oct 2017 18:14:43 +0200 Subject: nb/intel/sandybridge: Refactor dram_dimm_mapping() Remove no-op statements and code-rephrasing comments, apply some cosmetic changes to improve readability. Change-Id: I124a6bc338c2589fab66ca91bf53139b4413d10b Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/21823 Tested-by: build bot (Jenkins) Reviewed-by: Arthur Heymans --- src/northbridge/intel/sandybridge/raminit_common.c | 42 +++++++++------------- 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'src/northbridge/intel') diff --git a/src/northbridge/intel/sandybridge/raminit_common.c b/src/northbridge/intel/sandybridge/raminit_common.c index 3e69f4da72..b7340362c5 100644 --- a/src/northbridge/intel/sandybridge/raminit_common.c +++ b/src/northbridge/intel/sandybridge/raminit_common.c @@ -295,49 +295,39 @@ void dram_timing_regs(ramctr_timing *ctrl) void dram_dimm_mapping(ramctr_timing *ctrl) { - u32 reg, val32; int channel; dimm_info *info = &ctrl->info; FOR_ALL_CHANNELS { - dimm_attr *dimmA = 0; - dimm_attr *dimmB = 0; - reg = 0; - val32 = 0; + dimm_attr *dimmA, *dimmB; + u32 reg = 0; + if (info->dimm[channel][0].size_mb >= info->dimm[channel][1].size_mb) { - // dimm 0 is bigger, set it to dimmA dimmA = &info->dimm[channel][0]; dimmB = &info->dimm[channel][1]; - reg |= (0 << 16); + reg |= 0 << 16; } else { - // dimm 1 is bigger, set it to dimmA dimmA = &info->dimm[channel][1]; dimmB = &info->dimm[channel][0]; - reg |= (1 << 16); + reg |= 1 << 16; } - // dimmA + if (dimmA && (dimmA->ranks > 0)) { - val32 = dimmA->size_mb / 256; - reg = (reg & ~0xff) | val32; - val32 = dimmA->ranks - 1; - reg = (reg & ~0x20000) | (val32 << 17); - val32 = (dimmA->width / 8) - 1; - reg = (reg & ~0x80000) | (val32 << 19); + reg |= dimmA->size_mb / 256; + reg |= (dimmA->ranks - 1) << 17; + reg |= (dimmA->width / 8 - 1) << 19; } - // dimmB + if (dimmB && (dimmB->ranks > 0)) { - val32 = dimmB->size_mb / 256; - reg = (reg & ~0xff00) | (val32 << 8); - val32 = dimmB->ranks - 1; - reg = (reg & ~0x40000) | (val32 << 18); - val32 = (dimmB->width / 8) - 1; - reg = (reg & ~0x100000) | (val32 << 20); + reg |= (dimmB->size_mb / 256) << 8; + reg |= (dimmB->ranks - 1) << 18; + reg |= (dimmB->width / 8 - 1) << 20; } - reg = (reg & ~0x200000) | (1 << 21); // rank interleave - reg = (reg & ~0x400000) | (1 << 22); // enhanced interleave - // Save MAD-DIMM register + reg |= 1 << 21; /* rank interleave */ + reg |= 1 << 22; /* enhanced interleave */ + if ((dimmA && (dimmA->ranks > 0)) || (dimmB && (dimmB->ranks > 0))) { ctrl->mad_dimm[channel] = reg; -- cgit v1.2.3