[PATCH v7 03/10] EDAC/aspeed: Put the differences between chips in a table

Ryan Chen ryan_chen at aspeedtech.com
Sun Nov 29 23:24:30 PST 2026


Prepare for the AST2700, which has its ECC enable and DRAM type bits in
a different register and supports DDR4 and DDR5 instead of DDR3 and
DDR4. With these in a table, it only needs one more entry.

Signed-off-by: Ryan Chen <ryan_chen at aspeedtech.com>
---
 drivers/edac/aspeed_edac.c | 45 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 10 deletions(-)

diff --git a/drivers/edac/aspeed_edac.c b/drivers/edac/aspeed_edac.c
index 5bc5630b6c50..f4ef9430258a 100644
--- a/drivers/edac/aspeed_edac.c
+++ b/drivers/edac/aspeed_edac.c
@@ -8,6 +8,7 @@
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/platform_device.h>
 #include <linux/spinlock.h>
@@ -29,7 +30,16 @@
 #define ASPEED_MCR_INTR_CTRL_CNT_UNREC  GENMASK(15, 12)
 #define ASPEED_MCR_INTR_CTRL_ENABLE     (BIT(0) | BIT(1))
 
+struct aspeed_edac_chip {
+	u32 conf_reg;
+	u32 conf_ecc;
+	u32 conf_dram_type;
+	enum mem_type dram_type[2];
+	unsigned long mtype_cap;
+};
+
 struct aspeed_edac {
+	const struct aspeed_edac_chip *chip;
 	void __iomem *regs;
 	/* serializes register updates */
 	spinlock_t lock;
@@ -196,12 +206,13 @@ static int config_irq(void *ctx, struct platform_device *pdev)
 static int init_csrows(struct mem_ctl_info *mci)
 {
 	struct aspeed_edac *priv = mci->pvt_info;
+	const struct aspeed_edac_chip *chip = priv->chip;
 	struct csrow_info *csrow = mci->csrows[0];
 	u32 nr_pages, dram_type;
 	struct dimm_info *dimm;
 	struct device_node *np;
 	struct resource r;
-	u32 reg04;
+	u32 conf;
 	int rc;
 
 	/* retrieve info about physical memory from device tree */
@@ -227,8 +238,8 @@ static int init_csrows(struct mem_ctl_info *mci)
 	nr_pages = resource_size(&r) >> PAGE_SHIFT;
 	csrow->last_page = csrow->first_page + nr_pages - 1;
 
-	reg04 = readl(priv->regs + ASPEED_MCR_CONF);
-	dram_type = (reg04 & ASPEED_MCR_CONF_DRAM_TYPE) ? MEM_DDR4 : MEM_DDR3;
+	conf = readl(priv->regs + chip->conf_reg);
+	dram_type = chip->dram_type[!!(conf & chip->conf_dram_type)];
 
 	dimm = csrow->channels[0]->dimm;
 	dimm->mtype = dram_type;
@@ -244,20 +255,25 @@ static int init_csrows(struct mem_ctl_info *mci)
 
 static int aspeed_probe(struct platform_device *pdev)
 {
+	const struct aspeed_edac_chip *chip;
 	struct edac_mc_layer layers[2];
 	struct aspeed_edac *priv;
 	struct mem_ctl_info *mci;
 	void __iomem *regs;
-	u32 reg04;
+	u32 conf;
 	int rc;
 
+	chip = of_device_get_match_data(&pdev->dev);
+	if (!chip)
+		return -ENODEV;
+
 	regs = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(regs))
 		return PTR_ERR(regs);
 
 	/* bail out if ECC mode is not configured */
-	reg04 = readl(regs + ASPEED_MCR_CONF);
-	if (!(reg04 & ASPEED_MCR_CONF_ECC)) {
+	conf = readl(regs + chip->conf_reg);
+	if (!(conf & chip->conf_ecc)) {
 		dev_err(&pdev->dev, "ECC mode is not configured in u-boot\n");
 		return -EPERM;
 	}
@@ -277,11 +293,12 @@ static int aspeed_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	priv = mci->pvt_info;
+	priv->chip = chip;
 	priv->regs = regs;
 	spin_lock_init(&priv->lock);
 
 	mci->pdev = &pdev->dev;
-	mci->mtype_cap = MEM_FLAG_DDR3 | MEM_FLAG_DDR4;
+	mci->mtype_cap = chip->mtype_cap;
 	mci->edac_ctl_cap = EDAC_FLAG_SECDED;
 	mci->edac_cap = EDAC_FLAG_SECDED;
 	mci->scrub_cap = SCRUB_FLAG_HW_SRC;
@@ -337,10 +354,18 @@ static void aspeed_remove(struct platform_device *pdev)
 	edac_mc_free(mci);
 }
 
+static const struct aspeed_edac_chip ast2400_edac = {
+	.conf_reg = ASPEED_MCR_CONF,
+	.conf_ecc = ASPEED_MCR_CONF_ECC,
+	.conf_dram_type = ASPEED_MCR_CONF_DRAM_TYPE,
+	.dram_type = { MEM_DDR3, MEM_DDR4 },
+	.mtype_cap = MEM_FLAG_DDR3 | MEM_FLAG_DDR4,
+};
+
 static const struct of_device_id aspeed_of_match[] = {
-	{ .compatible = "aspeed,ast2400-sdram-edac" },
-	{ .compatible = "aspeed,ast2500-sdram-edac" },
-	{ .compatible = "aspeed,ast2600-sdram-edac" },
+	{ .compatible = "aspeed,ast2400-sdram-edac", .data = &ast2400_edac },
+	{ .compatible = "aspeed,ast2500-sdram-edac", .data = &ast2400_edac },
+	{ .compatible = "aspeed,ast2600-sdram-edac", .data = &ast2400_edac },
 	{},
 };
 

-- 
2.34.1




More information about the linux-arm-kernel mailing list