mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ryan Chen <ryan_chen@aspeedtech.com>
To: Stefan Schaeckeler <sschaeck@cisco.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>, Joel Stanley <joel@jms.id.au>,
	Andrew Jeffery <andrew@codeconstruct.com.au>,
	Borislav Petkov <bp@alien8.de>, Tony Luck <tony.luck@intel.com>,
	Billy Tsai <billy_tsai@aspeedtech.com>
Cc: <devicetree@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-aspeed@lists.ozlabs.org>, <linux-kernel@vger.kernel.org>,
	<linux-edac@vger.kernel.org>,
	Ryan Chen <ryan_chen@aspeedtech.com>
Subject: [PATCH v7 01/10] EDAC/aspeed: Stop keeping driver state in global variables
Date: Mon, 30 Nov 2026 15:24:28 +0800	[thread overview]
Message-ID: <20261130-edac-v7-1-3aaf6d243f07@aspeedtech.com> (raw)
In-Reply-To: <20261130-edac-v7-0-3aaf6d243f07@aspeedtech.com>

The register map and the interrupt number are global variables. The
following changes need to keep more state for the device, such as a
lock and the chip type, and adding more globals for that is not the
right way.

Signed-off-by: Ryan Chen <ryan_chen@aspeedtech.com>
---
 drivers/edac/aspeed_edac.c | 50 ++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/drivers/edac/aspeed_edac.c b/drivers/edac/aspeed_edac.c
index 610da8aa2a22..f0db0a221ce0 100644
--- a/drivers/edac/aspeed_edac.c
+++ b/drivers/edac/aspeed_edac.c
@@ -30,8 +30,10 @@
 #define ASPEED_MCR_INTR_CTRL_CNT_UNREC  GENMASK(15, 12)
 #define ASPEED_MCR_INTR_CTRL_ENABLE     (BIT(0) | BIT(1))
 
-static struct regmap *aspeed_regmap;
-static int aspeed_irq;
+struct aspeed_edac {
+	struct regmap *regmap;
+	int irq;
+};
 
 static int regmap_reg_write(void *context, unsigned int reg, unsigned int val)
 {
@@ -147,11 +149,12 @@ static void count_un_rec(struct mem_ctl_info *mci, u8 un_rec_cnt,
 static irqreturn_t mcr_isr(int irq, void *arg)
 {
 	struct mem_ctl_info *mci = arg;
+	struct aspeed_edac *priv = mci->pvt_info;
 	u32 rec_addr, un_rec_addr;
 	u32 reg50, reg5c, reg58;
 	u8  rec_cnt, un_rec_cnt;
 
-	regmap_read(aspeed_regmap, ASPEED_MCR_INTR_CTRL, &reg50);
+	regmap_read(priv->regmap, ASPEED_MCR_INTR_CTRL, &reg50);
 	dev_dbg(mci->pdev, "received edac interrupt w/ mcr register 50: 0x%x\n",
 		reg50);
 
@@ -162,18 +165,18 @@ static irqreturn_t mcr_isr(int irq, void *arg)
 	dev_dbg(mci->pdev, "%d recoverable interrupts and %d unrecoverable interrupts\n",
 		rec_cnt, un_rec_cnt);
 
-	regmap_read(aspeed_regmap, ASPEED_MCR_ADDR_UNREC, &reg58);
+	regmap_read(priv->regmap, ASPEED_MCR_ADDR_UNREC, &reg58);
 	un_rec_addr = reg58;
 
-	regmap_read(aspeed_regmap, ASPEED_MCR_ADDR_REC, &reg5c);
+	regmap_read(priv->regmap, ASPEED_MCR_ADDR_REC, &reg5c);
 	rec_addr = reg5c;
 
 	/* clear interrupt flags and error counters: */
-	regmap_update_bits(aspeed_regmap, ASPEED_MCR_INTR_CTRL,
+	regmap_update_bits(priv->regmap, ASPEED_MCR_INTR_CTRL,
 			   ASPEED_MCR_INTR_CTRL_CLEAR,
 			   ASPEED_MCR_INTR_CTRL_CLEAR);
 
-	regmap_update_bits(aspeed_regmap, ASPEED_MCR_INTR_CTRL,
+	regmap_update_bits(priv->regmap, ASPEED_MCR_INTR_CTRL,
 			   ASPEED_MCR_INTR_CTRL_CLEAR, 0);
 
 	/* process recoverable and unrecoverable errors */
@@ -183,7 +186,7 @@ static irqreturn_t mcr_isr(int irq, void *arg)
 	if (!rec_cnt && !un_rec_cnt)
 		dev_dbg(mci->pdev, "received edac interrupt, but did not find any ECC counters\n");
 
-	regmap_read(aspeed_regmap, ASPEED_MCR_INTR_CTRL, &reg50);
+	regmap_read(priv->regmap, ASPEED_MCR_INTR_CTRL, &reg50);
 	dev_dbg(mci->pdev, "edac interrupt handled. mcr reg 50 is now: 0x%x\n",
 		reg50);
 
@@ -192,6 +195,8 @@ static irqreturn_t mcr_isr(int irq, void *arg)
 
 static int config_irq(void *ctx, struct platform_device *pdev)
 {
+	struct mem_ctl_info *mci = ctx;
+	struct aspeed_edac *priv = mci->pvt_info;
 	int irq;
 	int rc;
 
@@ -205,10 +210,10 @@ static int config_irq(void *ctx, struct platform_device *pdev)
 	if (rc)
 		return rc;
 
-	aspeed_irq = irq;
+	priv->irq = irq;
 
 	/* enable interrupts */
-	regmap_update_bits(aspeed_regmap, ASPEED_MCR_INTR_CTRL,
+	regmap_update_bits(priv->regmap, ASPEED_MCR_INTR_CTRL,
 			   ASPEED_MCR_INTR_CTRL_ENABLE,
 			   ASPEED_MCR_INTR_CTRL_ENABLE);
 
@@ -217,6 +222,7 @@ 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;
 	struct csrow_info *csrow = mci->csrows[0];
 	u32 nr_pages, dram_type;
 	struct dimm_info *dimm;
@@ -248,7 +254,7 @@ 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;
 
-	regmap_read(aspeed_regmap, ASPEED_MCR_CONF, &reg04);
+	regmap_read(priv->regmap, ASPEED_MCR_CONF, &reg04);
 	dram_type = (reg04 & ASPEED_MCR_CONF_DRAM_TYPE) ? MEM_DDR4 : MEM_DDR3;
 
 	dimm = csrow->channels[0]->dimm;
@@ -267,7 +273,9 @@ static int aspeed_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct edac_mc_layer layers[2];
+	struct aspeed_edac *priv;
 	struct mem_ctl_info *mci;
+	struct regmap *regmap;
 	void __iomem *regs;
 	u32 reg04;
 	int rc;
@@ -276,13 +284,13 @@ static int aspeed_probe(struct platform_device *pdev)
 	if (IS_ERR(regs))
 		return PTR_ERR(regs);
 
-	aspeed_regmap = devm_regmap_init(dev, NULL, (__force void *)regs,
-					 &aspeed_regmap_config);
-	if (IS_ERR(aspeed_regmap))
-		return PTR_ERR(aspeed_regmap);
+	regmap = devm_regmap_init(dev, NULL, (__force void *)regs,
+				  &aspeed_regmap_config);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
 
 	/* bail out if ECC mode is not configured */
-	regmap_read(aspeed_regmap, ASPEED_MCR_CONF, &reg04);
+	regmap_read(regmap, ASPEED_MCR_CONF, &reg04);
 	if (!(reg04 & ASPEED_MCR_CONF_ECC)) {
 		dev_err(&pdev->dev, "ECC mode is not configured in u-boot\n");
 		return -EPERM;
@@ -298,10 +306,13 @@ static int aspeed_probe(struct platform_device *pdev)
 	layers[1].size = 1;
 	layers[1].is_virt_csrow = false;
 
-	mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, 0);
+	mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*priv));
 	if (!mci)
 		return -ENOMEM;
 
+	priv = mci->pvt_info;
+	priv->regmap = regmap;
+
 	mci->pdev = &pdev->dev;
 	mci->mtype_cap = MEM_FLAG_DDR3 | MEM_FLAG_DDR4;
 	mci->edac_ctl_cap = EDAC_FLAG_SECDED;
@@ -346,12 +357,13 @@ static int aspeed_probe(struct platform_device *pdev)
 static void aspeed_remove(struct platform_device *pdev)
 {
 	struct mem_ctl_info *mci = platform_get_drvdata(pdev);
+	struct aspeed_edac *priv = mci->pvt_info;
 
 	/* disable interrupts */
-	regmap_update_bits(aspeed_regmap, ASPEED_MCR_INTR_CTRL,
+	regmap_update_bits(priv->regmap, ASPEED_MCR_INTR_CTRL,
 			   ASPEED_MCR_INTR_CTRL_ENABLE, 0);
 
-	free_irq(aspeed_irq, mci);
+	free_irq(priv->irq, mci);
 
 	/* free resources */
 	edac_mc_del_mc(&pdev->dev);

-- 
2.34.1


  reply	other threads:[~2026-11-30  7:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  7:24 [PATCH v7 00/10] Add Aspeed AST2700 SDRAM EDAC support Ryan Chen
2026-11-30  7:24 ` Ryan Chen [this message]
2026-11-30  7:24 ` [PATCH v7 02/10] EDAC/aspeed: Replace regmap with direct register access Ryan Chen
2026-11-30  7:24 ` [PATCH v7 03/10] EDAC/aspeed: Put the differences between chips in a table Ryan Chen
2026-11-30  7:24 ` [PATCH v7 04/10] EDAC/aspeed: Don't unlock the interrupt control register on AST2600 Ryan Chen
2026-11-30  7:24 ` [PATCH v7 05/10] EDAC/aspeed: Let each chip provide its own interrupt handling Ryan Chen
2026-11-30  7:24 ` [PATCH v7 06/10] EDAC/aspeed: Allow reporting an error without an address Ryan Chen
2026-11-30  7:24 ` [PATCH v7 07/10] EDAC/aspeed: Allow error addresses above 4 GiB Ryan Chen
2026-11-30  7:24 ` [PATCH v7 08/10] EDAC/aspeed: Disable interrupts before requesting the interrupt line Ryan Chen
2026-11-30  7:24 ` [PATCH v7 09/10] EDAC/aspeed: Add AST2700 support Ryan Chen
2026-11-30  7:24 ` [PATCH v7 10/10] MAINTAINERS: Step down as Aspeed AST2500 EDAC driver maintainer Ryan Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130-edac-v7-1-3aaf6d243f07@aspeedtech.com \
    --to=ryan_chen@aspeedtech.com \
    --cc=andrew@codeconstruct.com.au \
    --cc=billy_tsai@aspeedtech.com \
    --cc=bp@alien8.de \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=joel@jms.id.au \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-aspeed@lists.ozlabs.org \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sschaeck@cisco.com \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®