Skip to contentSkip to conversation

i2c: imx-lpi2c: avoid accessing target registers on master-only controllers

PATCH Applied [email protected] 5 participants 6 messages Aug 3 – Aug 28

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: imx-lpi2c: avoid accessing target registers on master-only controllers

From: Carlos Song <[email protected]>

Not all LPI2C controller instances implement the Target block. Since commit 90311787f483 ("i2c: imx-lpi2c: reset controller in probe stage"), the driver unconditionally resets both the Master and Target blocks during probe.

On controllers that do not support target mode, accessing the Target registers triggers an asynchronous SError and prevents the driver from probing successfully. For example on i.MX8QM:

SError Interrupt on CPU2, code 0x00000000bf000002 -- SError

  Hardware name: Freescale i.MX8QM MEK (DT)
  pc : lpi2c_imx_probe+0x280/0x594
  lr : lpi2c_imx_probe+0x224/0x594
  Kernel panic - not syncing: Asynchronous SError Interrupt

The VERID register is implemented in the Master block and can be safely accessed on all controller variants. Its FEATURE field indicates whether target mode is supported.

Read VERID during probe and use it to determine whether the Target block is present. Only access Target registers when target mode is supported and reject target registration requests with -EOPNOTSUPP otherwise.

Fixes 90311787f483 ("i2c: imx-lpi2c: reset controller in probe stage")
---
 drivers/i2c/busses/i2c-imx-lpi2c.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-imx-lpi2c.c +23 -4
index e1a4338bc51e..1cfd7a4c8237 100644
@@ -29,6 +29,7 @@
 
 #define DRIVER_NAME "imx-lpi2c"
 
+#define LPI2C_VERID	0x00	/* i2c version ID */
 #define LPI2C_PARAM	0x04	/* i2c RX/TX FIFO size */
 #define LPI2C_MCR	0x10	/* i2c contrl register */
 #define LPI2C_MSR	0x14	/* i2c status register */
@@ -136,6 +137,9 @@
 #define I2C_PM_LONG_TIMEOUT_MS	1000 /* Avoid dead lock caused by big clock prepare lock */
 #define I2C_DMA_THRESHOLD	8 /* bytes */
 
+/* Bit 0 indicates the presence of the target feature */
+#define VERID_FEATURE_TARGET_PRESENT	BIT(0)
+
 enum lpi2c_imx_mode {
 	STANDARD,	/* 100+Kbps */
 	FAST,		/* 400+Kbps */
@@ -194,6 +198,7 @@ struct lpi2c_imx_struct {
 	bool			can_use_dma;
 	struct lpi2c_imx_dma	*dma;
 	struct i2c_client	*target;
+	bool			target_supported;
 	int			irq;
 	const struct imx_lpi2c_hwdata *hwdata;
 };
@@ -1330,6 +1335,10 @@ static int lpi2c_imx_register_target(struct i2c_client *client)
 	struct lpi2c_imx_struct *lpi2c_imx = i2c_get_adapdata(client->adapter);
 	int ret;
 
+	/* Reject target-mode registration on controllers that don't support it. */
+	if (!lpi2c_imx->target_supported)
+		return -EOPNOTSUPP;
+
 	if (lpi2c_imx->target)
 		return -EBUSY;
 
@@ -1546,13 +1555,23 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
 	pm_runtime_enable(&pdev->dev);
 
 	/*
-	 * Reset all internal controller registers of both Master and Target
-	 * to avoid effects of previous status.
+	 * Reset all internal controller registers to avoid effects of any
+	 * state left over from a previous stage (e.g. the bootloader).
+	 *
+	 * The Master block (MCR) is present on every controller, so reset it
+	 * unconditionally. VERID shows whether the target feature is supported.
+	 * Do not touch the Target block (SCR) on a master-only controller to
+	 * avoid an asynchronous SError.
 	 */
 	writel(MCR_RST, lpi2c_imx->base + LPI2C_MCR);
-	writel(SCR_RST, lpi2c_imx->base + LPI2C_SCR);
 	writel(0, lpi2c_imx->base + LPI2C_MCR);
-	writel(0, lpi2c_imx->base + LPI2C_SCR);
+
+	lpi2c_imx->target_supported = !!(readl(lpi2c_imx->base + LPI2C_VERID) &
+					 VERID_FEATURE_TARGET_PRESENT);
+	if (lpi2c_imx->target_supported) {
+		writel(SCR_RST, lpi2c_imx->base + LPI2C_SCR);
+		writel(0, lpi2c_imx->base + LPI2C_SCR);
+	}
 
 	ret = devm_request_irq(&pdev->dev, lpi2c_imx->irq, lpi2c_imx_isr, IRQF_NO_SUSPEND,
 			       pdev->name, lpi2c_imx);
Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing rollback in lpi2c_imx_register_target() when pm_runtime_resume_and_get() fails, leaving a dangling pointer in lpi2c_imx->target. --

--- Patch [1]: [PATCH] i2c: imx-lpi2c: avoid accessing target registers on master-only controllers --- commit c2a5eb969b33b95968f240043a2bfa7ba6e85caf
Author: Carlos Song <[email protected]>

i2c: imx-lpi2c: avoid accessing target registers on master-only controllers

This commit reads the VERID register during probe to check for target mode support. It prevents accessing target registers on master-only controllers and rejects target registration requests if unsupported.

Quoted 3 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +0 -0

[ ... ]

Quoted 11 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +4 -0
@@ -1330,6 +1335,10 @@ static int lpi2c_imx_register_target(struct i2c_client *client)
 	struct lpi2c_imx_struct *lpi2c_imx = i2c_get_adapdata(client->adapter);
 	int ret;
 
+	/* Reject target-mode registration on controllers that don't support it. */
+	if (!lpi2c_imx->target_supported)
+		return -EOPNOTSUPP;
+
 	if (lpi2c_imx->target)
 		return -EBUSY;
 

drivers/i2c/busses/i2c-imx-lpi2c.c

Quoted 7 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +0 -0
 	lpi2c_imx->target = client;
 
 	ret = pm_runtime_resume_and_get(lpi2c_imx->adapter.dev.parent);
 	if (ret < 0) {
 		dev_err(&lpi2c_imx->adapter.dev, "failed to resume i2c controller");
 		return ret;
 	}

[Severity: High]
This is a pre-existing issue, but does this error path leave a dangling pointer in the controller data?

If pm_runtime_resume_and_get() fails in lpi2c_imx_register_target(), the function returns without clearing lpi2c_imx->target. Because the registration failed, the target driver probe will fail and the i2c_client memory can be freed (e.g., if dynamically removed or unbound).

Later, if the system is suspended and resumed, lpi2c_resume_noirq() will see that lpi2c_imx->target is non-NULL and unconditionally dereference it:

drivers/i2c/busses/i2c-imx-lpi2c.c:lpi2c_resume_noirq() {
    ...
    if (lpi2c_imx->target)
        lpi2c_imx_target_init(lpi2c_imx);
    ...
}

Should lpi2c_imx->target be set back to NULL in this error path to avoid a potential use-after-free crash?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v1 1/1
#2 lore raw
In reply to [email protected]
Quoted 21 lines · On Mon, Aug 03, 2026 at 11:27:05AM +0800, [email protected] wrote:

From: Carlos Song <[email protected]>

Not all LPI2C controller instances implement the Target block. Since commit 90311787f483 ("i2c: imx-lpi2c: reset controller in probe stage"), the driver unconditionally resets both the Master and Target blocks during probe.

On controllers that do not support target mode, accessing the Target registers triggers an asynchronous SError and prevents the driver from probing successfully. For example on i.MX8QM:

SError Interrupt on CPU2, code 0x00000000bf000002 -- SError

  Hardware name: Freescale i.MX8QM MEK (DT)
  pc : lpi2c_imx_probe+0x280/0x594
  lr : lpi2c_imx_probe+0x224/0x594
  Kernel panic - not syncing: Asynchronous SError Interrupt

The VERID register is implemented in the Master block and can be safely accessed on all controller variants. Its FEATURE field indicates whether target mode is supported.

Quoted 8 lines

Read VERID during probe and use it to determine whether the Target block is present. Only access Target registers when target mode is supported and reject target registration requests with -EOPNOTSUPP otherwise.

Fixes 90311787f483 ("i2c: imx-lpi2c: reset controller in probe stage")

---

Quoted 76 lines
 drivers/i2c/busses/i2c-imx-lpi2c.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-imx-lpi2c.c +23 -5
index e1a4338bc51e..1cfd7a4c8237 100644
@@ -29,6 +29,7 @@
 
 #define DRIVER_NAME "imx-lpi2c"
 
+#define LPI2C_VERID	0x00	/* i2c version ID */
 #define LPI2C_PARAM	0x04	/* i2c RX/TX FIFO size */
 #define LPI2C_MCR	0x10	/* i2c contrl register */
 #define LPI2C_MSR	0x14	/* i2c status register */
@@ -136,6 +137,9 @@
 #define I2C_PM_LONG_TIMEOUT_MS	1000 /* Avoid dead lock caused by big clock prepare lock */
 #define I2C_DMA_THRESHOLD	8 /* bytes */
 
+/* Bit 0 indicates the presence of the target feature */
+#define VERID_FEATURE_TARGET_PRESENT	BIT(0)
+
 enum lpi2c_imx_mode {
 	STANDARD,	/* 100+Kbps */
 	FAST,		/* 400+Kbps */
@@ -194,6 +198,7 @@ struct lpi2c_imx_struct {
 	bool			can_use_dma;
 	struct lpi2c_imx_dma	*dma;
 	struct i2c_client	*target;
+	bool			target_supported;
 	int			irq;
 	const struct imx_lpi2c_hwdata *hwdata;
 };
@@ -1330,6 +1335,10 @@ static int lpi2c_imx_register_target(struct i2c_client *client)
 	struct lpi2c_imx_struct *lpi2c_imx = i2c_get_adapdata(client->adapter);
 	int ret;
 
+	/* Reject target-mode registration on controllers that don't support it. */
+	if (!lpi2c_imx->target_supported)
+		return -EOPNOTSUPP;
+
 	if (lpi2c_imx->target)
 		return -EBUSY;
 
@@ -1546,13 +1555,23 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
 	pm_runtime_enable(&pdev->dev);
 
 	/*
-	 * Reset all internal controller registers of both Master and Target
-	 * to avoid effects of previous status.
+	 * Reset all internal controller registers to avoid effects of any
+	 * state left over from a previous stage (e.g. the bootloader).
+	 *
+	 * The Master block (MCR) is present on every controller, so reset it
+	 * unconditionally. VERID shows whether the target feature is supported.
+	 * Do not touch the Target block (SCR) on a master-only controller to
+	 * avoid an asynchronous SError.
 	 */
 	writel(MCR_RST, lpi2c_imx->base + LPI2C_MCR);
-	writel(SCR_RST, lpi2c_imx->base + LPI2C_SCR);
 	writel(0, lpi2c_imx->base + LPI2C_MCR);
-	writel(0, lpi2c_imx->base + LPI2C_SCR);
+
+	lpi2c_imx->target_supported = !!(readl(lpi2c_imx->base + LPI2C_VERID) &
+					 VERID_FEATURE_TARGET_PRESENT);
+	if (lpi2c_imx->target_supported) {
+		writel(SCR_RST, lpi2c_imx->base + LPI2C_SCR);
+		writel(0, lpi2c_imx->base + LPI2C_SCR);
+	}
 
 	ret = devm_request_irq(&pdev->dev, lpi2c_imx->irq, lpi2c_imx_isr, IRQF_NO_SUSPEND,
 			       pdev->name, lpi2c_imx);
--

2.43.0

#3 lore raw

Gentle ping to avoid missing in mail sea.

Thanks.

NXP Confidential

Quoted 126 lines

-----Original Message-----
From: Frank Li (OSS) <[email protected]>
Sent: Saturday, August 8, 2026 3:25 AM
To: Carlos Song (OSS) <[email protected]>
Cc: Aisheng Dong <[email protected]>; [email protected]; Frank Li <[email protected]>; [email protected]; [email protected]; [email protected]; Carlos Song <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] i2c: imx-lpi2c: avoid accessing target registers on master-only controllers

Quoted 26 lines · On Mon, Aug 03, 2026 at 11:27:05AM +0800, [email protected] wrote:

From: Carlos Song <[email protected]>

Not all LPI2C controller instances implement the Target block. Since commit 90311787f483 ("i2c: imx-lpi2c: reset controller in probe stage"), the driver unconditionally resets both the Master and Target blocks during probe.

On controllers that do not support target mode, accessing the Target registers triggers an asynchronous SError and prevents the driver from probing successfully. For example on i.MX8QM:

SError Interrupt on CPU2, code 0x00000000bf000002 -- SError

  Hardware name: Freescale i.MX8QM MEK (DT)
  pc : lpi2c_imx_probe+0x280/0x594
  lr : lpi2c_imx_probe+0x224/0x594
  Kernel panic - not syncing: Asynchronous SError Interrupt

The VERID register is implemented in the Master block and can be safely accessed on all controller variants. Its FEATURE field indicates whether target mode is supported.

Read VERID during probe and use it to determine whether the Target block is present. Only access Target registers when target mode is supported and reject target registration requests with -EOPNOTSUPP otherwise.

Quoted 4 lines
Fixes 90311787f483 ("i2c: imx-lpi2c: reset controller in probe

stage")

---

Quoted 17 lines
 drivers/i2c/busses/i2c-imx-lpi2c.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-imx-lpi2c.c +1 -0
index e1a4338bc51e..1cfd7a4c8237 100644
@@ -29,6 +29,7 @@
 
 #define DRIVER_NAME "imx-lpi2c"
 
+#define LPI2C_VERID        0x00    /* i2c version ID */
 #define LPI2C_PARAM        0x04    /* i2c RX/TX FIFO size */
 #define LPI2C_MCR  0x10    /* i2c contrl register */
 #define LPI2C_MSR  0x14    /* i2c status register */

drivers/i2c/busses/i2c-imx-lpi2c.c line 137

Quoted 1 line
drivers/i2c/busses/i2c-imx-lpi2c.c +0 -0
@@ -136,6 +137,9 @@
 #define I2C_PM_LONG_TIMEOUT_MS     1000 /* Avoid dead lock caused

by big clock prepare lock */

drivers/i2c/busses/i2c-imx-lpi2c.c static int lpi2c_imx_probe(struct

Quoted 27 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +4 -0
 #define I2C_DMA_THRESHOLD  8 /* bytes */
 
+/* Bit 0 indicates the presence of the target feature */
+#define VERID_FEATURE_TARGET_PRESENT       BIT(0)
+
 enum lpi2c_imx_mode {
    STANDARD,       /* 100+Kbps */
    FAST,           /* 400+Kbps */
@@ -194,6 +198,7 @@ struct lpi2c_imx_struct {
    bool                    can_use_dma;
    struct lpi2c_imx_dma    *dma;
    struct i2c_client       *target;
+   bool                    target_supported;
    int                     irq;
    const struct imx_lpi2c_hwdata *hwdata;  }; @@ -1330,6 +1335,10 @@
 static int lpi2c_imx_register_target(struct i2c_client *client)
    struct lpi2c_imx_struct *lpi2c_imx = i2c_get_adapdata(client->adapter);
    int ret;
drivers/i2c/busses/i2c-imx-lpi2c.c +4 -0
+   /* Reject target-mode registration on controllers that don't support it. */
+   if (!lpi2c_imx->target_supported)
+           return -EOPNOTSUPP;
+
    if (lpi2c_imx->target)
            return -EBUSY;
@@ -1546,13 +1555,23 @@ static int lpi2c_imx_probe(struct

platform_device *pdev)

Quoted 9 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +4 -2
    pm_runtime_enable(&pdev->dev);
 
    /*
-    * Reset all internal controller registers of both Master and Target
-    * to avoid effects of previous status.
+    * Reset all internal controller registers to avoid effects of any
+    * state left over from a previous stage (e.g. the bootloader).
+    *
+    * The Master block (MCR) is present on every controller, so reset it

drivers/i2c/busses/i2c-imx-lpi2c.c static int lpi2c_imx_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +5 -2
+    * unconditionally. VERID shows whether the target feature is supported.
+    * Do not touch the Target block (SCR) on a master-only controller to
+    * avoid an asynchronous SError.
     */
    writel(MCR_RST, lpi2c_imx->base + LPI2C_MCR);
-   writel(SCR_RST, lpi2c_imx->base + LPI2C_SCR);
    writel(0, lpi2c_imx->base + LPI2C_MCR);
-   writel(0, lpi2c_imx->base + LPI2C_SCR);
+
+   lpi2c_imx->target_supported = !!(readl(lpi2c_imx->base + LPI2C_VERID)

&

drivers/i2c/busses/i2c-imx-lpi2c.c static int lpi2c_imx_probe(struct platform_device *pdev)

Quoted 7 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +5 -0
+                                    VERID_FEATURE_TARGET_PRESENT);
+   if (lpi2c_imx->target_supported) {
+           writel(SCR_RST, lpi2c_imx->base + LPI2C_SCR);
+           writel(0, lpi2c_imx->base + LPI2C_SCR);
+   }
 
    ret = devm_request_irq(&pdev->dev, lpi2c_imx->irq, lpi2c_imx_isr,

IRQF_NO_SUSPEND,

Quoted 5 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +0 -1
                           pdev->name, lpi2c_imx);
--

2.43.0

#4 lore raw

NXP Public

Quoted 150 lines

-----Original Message-----
From: Carlos Song (OSS)
Sent: Wednesday, August 26, 2026 11:24 AM
To: Frank Li (OSS) <[email protected]>; [email protected]; [email protected]; [email protected]; Frank Li <[email protected]>; Aisheng Dong <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH] i2c: imx-lpi2c: avoid accessing target registers on master-only controllers

Gentle ping to avoid missing in mail sea.

Thanks.

Quoted 13 lines

-----Original Message-----
From: Frank Li (OSS) <[email protected]>
Sent: Saturday, August 8, 2026 3:25 AM
To: Carlos Song (OSS) <[email protected]>
Cc: Aisheng Dong <[email protected]>; [email protected]; Frank Li <[email protected]>; [email protected]; [email protected]; [email protected]; Carlos Song <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] i2c: imx-lpi2c: avoid accessing target registers on master-only controllers

On Mon, Aug 03, 2026 at 11:27:05AM +0800, [email protected]

Quoted 43 lines · wrote:
Quoted 26 lines

From: Carlos Song <[email protected]>

Not all LPI2C controller instances implement the Target block. Since commit 90311787f483 ("i2c: imx-lpi2c: reset controller in probe stage"), the driver unconditionally resets both the Master and Target blocks during probe.

On controllers that do not support target mode, accessing the Target registers triggers an asynchronous SError and prevents the driver from probing successfully. For example on i.MX8QM:

SError Interrupt on CPU2, code 0x00000000bf000002 -- SError

  Hardware name: Freescale i.MX8QM MEK (DT)
  pc : lpi2c_imx_probe+0x280/0x594
  lr : lpi2c_imx_probe+0x224/0x594
  Kernel panic - not syncing: Asynchronous SError Interrupt

The VERID register is implemented in the Master block and can be safely accessed on all controller variants. Its FEATURE field indicates whether target mode is supported.

Read VERID during probe and use it to determine whether the Target block is present. Only access Target registers when target mode is supported and reject target registration requests with -EOPNOTSUPP otherwise.

Quoted 4 lines
Fixes 90311787f483 ("i2c: imx-lpi2c: reset controller in probe

stage")

---

Quoted 10 lines
 drivers/i2c/busses/i2c-imx-lpi2c.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-imx-lpi2c.c +0 -0
index e1a4338bc51e..1cfd7a4c8237 100644
@@ -29,6 +29,7 @@
 
Quoted 8 lines

drivers/i2c/busses/i2c-imx-lpi2c.c line 137

Quoted 8 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +1 -0
 #define DRIVER_NAME "imx-lpi2c"
 
+#define LPI2C_VERID      0x00    /* i2c version ID */
 #define LPI2C_PARAM      0x04    /* i2c RX/TX FIFO size */
 #define LPI2C_MCR        0x10    /* i2c contrl register */
 #define LPI2C_MSR        0x14    /* i2c status register */
@@ -136,6 +137,9 @@
 #define I2C_PM_LONG_TIMEOUT_MS   1000 /* Avoid dead lock

caused

Quoted 16 lines

by big clock prepare lock */

Quoted 9 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +3 -0
 #define I2C_DMA_THRESHOLD        8 /* bytes */
 
+/* Bit 0 indicates the presence of the target feature */
+#define VERID_FEATURE_TARGET_PRESENT     BIT(0)
+
 enum lpi2c_imx_mode {
  STANDARD,       /* 100+Kbps */
  FAST,           /* 400+Kbps */

drivers/i2c/busses/i2c-imx-lpi2c.c struct lpi2c_imx_struct { · line 203

Quoted 6 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +1 -0
@@ -194,6 +198,7 @@ struct lpi2c_imx_struct {
  bool                    can_use_dma;
  struct lpi2c_imx_dma    *dma;
  struct i2c_client       *target;
+ bool                    target_supported;
  int                     irq;
  const struct imx_lpi2c_hwdata *hwdata;  }; @@ -1330,6 +1335,10

@@

Quoted 2 lines
Quoted 2 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +0 -0
 static int lpi2c_imx_register_target(struct i2c_client *client)

struct lpi2c_imx_struct *lpi2c_imx =

i2c_get_adapdata(client->adapter);

Quoted 3 lines
Quoted 3 lines

int ret;

+ /* Reject target-mode registration on controllers that don't support

it. */

Quoted 6 lines
Quoted 6 lines

+ if (!lpi2c_imx->target_supported)

drivers/i2c/busses/i2c-imx-lpi2c.c +2 -0
+         return -EOPNOTSUPP;
+
  if (lpi2c_imx->target)
          return -EBUSY;
Quoted 12 lines

drivers/i2c/busses/i2c-imx-lpi2c.c static int lpi2c_imx_probe(struct

Quoted 1 line
drivers/i2c/busses/i2c-imx-lpi2c.c +0 -0
@@ -1546,13 +1555,23 @@ static int lpi2c_imx_probe(struct

platform_device *pdev)

Quoted 10 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +5 -2
  pm_runtime_enable(&pdev->dev);
 
  /*
-  * Reset all internal controller registers of both Master and Target
-  * to avoid effects of previous status.
+  * Reset all internal controller registers to avoid effects of any
+  * state left over from a previous stage (e.g. the bootloader).
+  *
+  * The Master block (MCR) is present on every controller, so reset it
+  * unconditionally. VERID shows whether the target feature is

supported.

Quoted 1 line

drivers/i2c/busses/i2c-imx-lpi2c.c static int lpi2c_imx_probe(struct · line 1563

Quoted 1 line
drivers/i2c/busses/i2c-imx-lpi2c.c +1 -0
+  * Do not touch the Target block (SCR) on a master-only controller

to

Quoted 23 lines

drivers/i2c/busses/i2c-imx-lpi2c.c static int lpi2c_imx_probe(struct platform_device *pdev)

Quoted 9 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +4 -2
+  * avoid an asynchronous SError.
   */
  writel(MCR_RST, lpi2c_imx->base + LPI2C_MCR);
- writel(SCR_RST, lpi2c_imx->base + LPI2C_SCR);
  writel(0, lpi2c_imx->base + LPI2C_MCR);
- writel(0, lpi2c_imx->base + LPI2C_SCR);
+
+ lpi2c_imx->target_supported = !!(readl(lpi2c_imx->base +
+LPI2C_VERID)

&

drivers/i2c/busses/i2c-imx-lpi2c.c static int lpi2c_imx_probe(struct platform_device *pdev)

Quoted 7 lines
drivers/i2c/busses/i2c-imx-lpi2c.c +5 -0
+                                  VERID_FEATURE_TARGET_PRESENT);
+ if (lpi2c_imx->target_supported) {
+         writel(SCR_RST, lpi2c_imx->base + LPI2C_SCR);
+         writel(0, lpi2c_imx->base + LPI2C_SCR);
+ }
 
  ret = devm_request_irq(&pdev->dev, lpi2c_imx->irq, lpi2c_imx_isr,

IRQF_NO_SUSPEND,

Quoted 5 lines
                         pdev->name, lpi2c_imx);

--
2.43.0

maintainer Applied
#5 lore raw
In reply to [email protected]

Hi Carlos,

Quoted 21 lines · On Mon, Aug 03, 2026 at 11:27:05AM +0800, [email protected] wrote:

From: Carlos Song <[email protected]>

Not all LPI2C controller instances implement the Target block. Since commit 90311787f483 ("i2c: imx-lpi2c: reset controller in probe stage"), the driver unconditionally resets both the Master and Target blocks during probe.

On controllers that do not support target mode, accessing the Target registers triggers an asynchronous SError and prevents the driver from probing successfully. For example on i.MX8QM:

SError Interrupt on CPU2, code 0x00000000bf000002 -- SError

  Hardware name: Freescale i.MX8QM MEK (DT)
  pc : lpi2c_imx_probe+0x280/0x594
  lr : lpi2c_imx_probe+0x224/0x594
  Kernel panic - not syncing: Asynchronous SError Interrupt

The VERID register is implemented in the Master block and can be safely accessed on all controller variants. Its FEATURE field indicates whether target mode is supported.

Quoted 7 lines

Read VERID during probe and use it to determine whether the Target block is present. Only access Target registers when target mode is supported and reject target registration requests with -EOPNOTSUPP otherwise.

Fixes 90311787f483 ("i2c: imx-lpi2c: reset controller in probe stage")

pushed to i2c/i2c-fixes.

Thanks,
Andi