Commit f9ae487e authored by Thor Thayer's avatar Thor Thayer Committed by Borislav Petkov

EDAC, altera: Generalize driver to use DT Memory size

The Arria10 SOC uses a completely different SDRAM controller from the
earlier CycloneV and ArriaV SoCs. The memory size is calculated in the
bootloader and passed via the device tree. Using this device tree size
is more generic than using the register fields to calculate the memory
size for different SDRAM controllers.
Signed-off-by: default avatarThor Thayer <tthayer@opensource.altera.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: devicetree@vger.kernel.org
Cc: dinguyen@opensource.altera.com
Cc: galak@codeaurora.org
Cc: grant.likely@linaro.org
Cc: ijc+devicetree@hellion.org.uk
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-edac <linux-edac@vger.kernel.org>
Cc: m.chehab@samsung.com
Cc: mark.rutland@arm.com
Cc: pawel.moll@arm.com
Cc: robh+dt@kernel.org
Cc: tthayer.linux@gmail.com
Link: http://lkml.kernel.org/r/1433428128-7292-2-git-send-email-tthayer@opensource.altera.comSigned-off-by: default avatarBorislav Petkov <bp@suse.de>
parent 99e21fea
...@@ -219,36 +219,31 @@ static void altr_sdr_mc_create_debugfs_nodes(struct mem_ctl_info *mci) ...@@ -219,36 +219,31 @@ static void altr_sdr_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
{} {}
#endif #endif
/* Get total memory size in bytes */ /* Get total memory size from Open Firmware DTB */
static u32 altr_sdram_get_total_mem_size(struct regmap *mc_vbase) static unsigned long get_total_mem(void)
{ {
u32 size, read_reg, row, bank, col, cs, width; struct device_node *np = NULL;
const unsigned int *reg, *reg_end;
if (regmap_read(mc_vbase, DRAMADDRW_OFST, &read_reg) < 0) int len, sw, aw;
return 0; unsigned long start, size, total_mem = 0;
if (regmap_read(mc_vbase, DRAMIFWIDTH_OFST, &width) < 0) for_each_node_by_type(np, "memory") {
return 0; aw = of_n_addr_cells(np);
sw = of_n_size_cells(np);
col = (read_reg & DRAMADDRW_COLBIT_MASK) >> reg = (const unsigned int *)of_get_property(np, "reg", &len);
DRAMADDRW_COLBIT_SHIFT; reg_end = reg + (len / sizeof(u32));
row = (read_reg & DRAMADDRW_ROWBIT_MASK) >>
DRAMADDRW_ROWBIT_SHIFT; total_mem = 0;
bank = (read_reg & DRAMADDRW_BANKBIT_MASK) >> do {
DRAMADDRW_BANKBIT_SHIFT; start = of_read_number(reg, aw);
cs = (read_reg & DRAMADDRW_CSBIT_MASK) >> reg += aw;
DRAMADDRW_CSBIT_SHIFT; size = of_read_number(reg, sw);
reg += sw;
/* Correct for ECC as its not addressible */ total_mem += size;
if (width == DRAMIFWIDTH_32B_ECC) } while (reg < reg_end);
width = 32; }
if (width == DRAMIFWIDTH_16B_ECC) edac_dbg(0, "total_mem 0x%lx\n", total_mem);
width = 16; return total_mem;
/* calculate the SDRAM size base on this info */
size = 1 << (row + bank + col);
size = size * cs * (width / 8);
return size;
} }
static int altr_sdram_probe(struct platform_device *pdev) static int altr_sdram_probe(struct platform_device *pdev)
...@@ -280,10 +275,9 @@ static int altr_sdram_probe(struct platform_device *pdev) ...@@ -280,10 +275,9 @@ static int altr_sdram_probe(struct platform_device *pdev)
} }
/* Grab memory size from device tree. */ /* Grab memory size from device tree. */
mem_size = altr_sdram_get_total_mem_size(mc_vbase); mem_size = get_total_mem();
if (!mem_size) { if (!mem_size) {
edac_printk(KERN_ERR, EDAC_MC, edac_printk(KERN_ERR, EDAC_MC, "Unable to calculate memory size\n");
"Unable to calculate memory size\n");
return -ENODEV; return -ENODEV;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment