The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "William A. Kennington III" <william@wkennington.com>
To: Mika Westerberg <mika.westerberg@linux.intel.com>,
	 Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	 Jan Dabros <jsd@semihalf.com>,
	Andi Shyti <andi.shyti@kernel.org>
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	 "William A. Kennington III" <william@wkennington.com>
Subject: [PATCH v4 1/4] i2c: designware: Introduce shutdown exported function
Date: Thu, 07 May 2026 20:05:15 +0000	[thread overview]
Message-ID: <20260507-dw-i2c-v4-1-9a447b23bfdf@wkennington.com> (raw)
In-Reply-To: <20260507-dw-i2c-v4-0-9a447b23bfdf@wkennington.com>

Introduce an exported shutdown function to safely shutdown the
DesignWare I2C controller.

This shutdown hook gracefully sets the target disable bit before disabling
the controller. This guarantees that any incoming requests from the
controller are immediately NACKed during shutdown, preventing the bus from
hanging.

Signed-off-by: William A. Kennington III <william@wkennington.com>
---
 drivers/i2c/busses/i2c-designware-common.c | 24 ++++++++++++++++++++++++
 drivers/i2c/busses/i2c-designware-core.h   |  1 +
 2 files changed, 25 insertions(+)

diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
index 4dc57fd56170..886f4dad166a 100644
--- a/drivers/i2c/busses/i2c-designware-common.c
+++ b/drivers/i2c/busses/i2c-designware-common.c
@@ -1028,5 +1028,29 @@ EXPORT_GPL_DEV_PM_OPS(i2c_dw_dev_pm_ops) = {
 	RUNTIME_PM_OPS(i2c_dw_runtime_suspend, i2c_dw_runtime_resume, NULL)
 };
 
+void i2c_dw_shutdown(struct dw_i2c_dev *dev)
+{
+	unsigned int con;
+
+	/*
+	 * We only need to handle shutdown for target mode to ensure
+	 * we NACK any incoming controller requests. Master mode cleanup
+	 * is handled after each transfer in i2c_dw_xfer().
+	 */
+	if (dev->mode != DW_IC_SLAVE)
+		return;
+
+	/*
+	 * To quickly NACK the controller during shutdown, we set the target
+	 * disable bit while the controller is still enabled.
+	 */
+	regmap_read(dev->map, DW_IC_CON, &con);
+	con |= DW_IC_CON_SLAVE_DISABLE;
+	regmap_write(dev->map, DW_IC_CON, con);
+
+	i2c_dw_disable(dev);
+}
+EXPORT_SYMBOL_GPL(i2c_dw_shutdown);
+
 MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter core");
 MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 9d8d104cc391..c71aa2dd368d 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -417,6 +417,7 @@ static inline void i2c_dw_configure(struct dw_i2c_dev *dev)
 
 int i2c_dw_probe(struct dw_i2c_dev *dev);
 int i2c_dw_init(struct dw_i2c_dev *dev);
+void i2c_dw_shutdown(struct dw_i2c_dev *dev);
 void i2c_dw_set_mode(struct dw_i2c_dev *dev, int mode);
 
 #if IS_ENABLED(CONFIG_I2C_DESIGNWARE_BAYTRAIL)

-- 
2.54.0.563.g4f69b47b94-goog


  reply	other threads:[~2026-05-07 20:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07 20:05 [PATCH v4 0/4] i2c: designware: Improve device disable handling William A. Kennington III
2026-05-07 20:05 ` William A. Kennington III [this message]
2026-05-08  8:12   ` [PATCH v4 1/4] i2c: designware: Introduce shutdown exported function Andy Shevchenko
2026-05-08 10:01     ` Andy Shevchenko
2026-05-07 20:05 ` [PATCH v4 2/4] i2c: designware: Convert PCI driver to use shutdown hook William A. Kennington III
2026-05-08  8:15   ` Andy Shevchenko
2026-05-11 19:55     ` William A. Kennington III
2026-05-07 20:05 ` [PATCH v4 3/4] i2c: designware: Convert platform " William A. Kennington III
2026-05-08  8:15   ` Andy Shevchenko
2026-05-11 19:55     ` William A. Kennington III
2026-05-07 20:05 ` [PATCH v4 4/4] i2c: designware: Handle active target cleanly William A. Kennington III
2026-05-08 10:01   ` Andy Shevchenko

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=20260507-dw-i2c-v4-1-9a447b23bfdf@wkennington.com \
    --to=william@wkennington.com \
    --cc=andi.shyti@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jsd@semihalf.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.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