From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: "Matthew Brost" <matthew.brost@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Raag Jadav" <raag.jadav@intel.com>,
"Michael J . Ruhl" <michael.j.ruhl@intel.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Mika Westerberg" <mika.westerberg@linux.intel.com>,
"Riana Tauro" <riana.tauro@intel.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v1 2/2] drm/xe/mcu_i2c: Take over control of the controller enabling
Date: Mon, 22 Jun 2026 13:47:59 +0200 [thread overview]
Message-ID: <20260622114759.3464047-3-heikki.krogerus@linux.intel.com> (raw)
In-Reply-To: <20260622114759.3464047-1-heikki.krogerus@linux.intel.com>
Some platforms make an assumption that the i2c controller's
enabled state indicates also the power state of the
controller. This can create a problem when the controller is
in disabled state, because the hardware may assume
incorrectly that it is then also in low-power state.
To fix this, the controller is kept enabled by taking over
the IC_ENABLE register. The controller has to be disabled
when the configuration is updated and when the target
address or the slave address are assigned, so disabling it
when IC_CON, IC_TAR or IC_SAR registers are programmed, and
then re-enabling it again.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/gpu/drm/xe/xe_i2c.c | 65 +++++++++++++++++++++++++++++++++++--
drivers/gpu/drm/xe/xe_i2c.h | 1 +
2 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_i2c.c b/drivers/gpu/drm/xe/xe_i2c.c
index 732ad6ee05e9c..45fa9094b6142 100644
--- a/drivers/gpu/drm/xe/xe_i2c.c
+++ b/drivers/gpu/drm/xe/xe_i2c.c
@@ -8,6 +8,7 @@
#include <drm/drm_print.h>
#include <linux/array_size.h>
#include <linux/container_of.h>
+#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/i2c.h>
@@ -261,11 +262,49 @@ static void xe_i2c_remove_irq(struct xe_i2c *i2c)
irq_domain_remove(i2c->irqdomain);
}
+#define IC_CON 0x00
+#define IC_TAR 0x04
+#define IC_SAR 0x08
+#define IC_ENABLE 0x6c
+#define IC_ENABLE_STATUS 0x9c
+
+/* See "Disabling DW_apb_i2c" in the DesignWare DW_abp_i2c databook. */
+static int xe_i2c_disable(struct xe_i2c *i2c)
+{
+ int timeout = 100;
+ u32 status;
+
+ do {
+ /* Disable.*/
+ xe_mmio_rmw32(i2c->mmio, XE_REG(IC_ENABLE + I2C_MEM_SPACE_OFFSET), 1, 0);
+
+ /* Verify. */
+ status = xe_mmio_read32(i2c->mmio, XE_REG(IC_ENABLE_STATUS + I2C_MEM_SPACE_OFFSET));
+ if (!(status & 1))
+ return 0;
+
+ /* Repeat. */
+ usleep_range(25, 250);
+ } while (timeout--);
+
+ return -ETIMEDOUT;
+}
+
static int xe_i2c_read(void *context, unsigned int reg, unsigned int *val)
{
struct xe_i2c *i2c = context;
- *val = xe_mmio_read32(i2c->mmio, XE_REG(reg + I2C_MEM_SPACE_OFFSET));
+ switch (reg) {
+ case IC_ENABLE:
+ *val = i2c->ic_enable;
+ break;
+ case IC_ENABLE_STATUS:
+ *val = i2c->ic_enable & 1; /* NOTE: Checking only the enable bit */
+ break;
+ default:
+ *val = xe_mmio_read32(i2c->mmio, XE_REG(reg + I2C_MEM_SPACE_OFFSET));
+ break;
+ }
return 0;
}
@@ -273,8 +312,30 @@ static int xe_i2c_read(void *context, unsigned int reg, unsigned int *val)
static int xe_i2c_write(void *context, unsigned int reg, unsigned int val)
{
struct xe_i2c *i2c = context;
+ int ret;
- xe_mmio_write32(i2c->mmio, XE_REG(reg + I2C_MEM_SPACE_OFFSET), val);
+ switch (reg) {
+ case IC_CON:
+ case IC_TAR:
+ case IC_SAR:
+ /* Disable the controller. */
+ ret = xe_i2c_disable(i2c);
+ if (ret)
+ return ret;
+
+ /* Write the register. */
+ xe_mmio_write32(i2c->mmio, XE_REG(reg + I2C_MEM_SPACE_OFFSET), val);
+
+ /* Enable the controller. */
+ xe_mmio_rmw32(i2c->mmio, XE_REG(IC_ENABLE + I2C_MEM_SPACE_OFFSET), 0, 1);
+ break;
+ case IC_ENABLE:
+ i2c->ic_enable = val;
+ break;
+ default:
+ xe_mmio_write32(i2c->mmio, XE_REG(reg + I2C_MEM_SPACE_OFFSET), val);
+ break;
+ }
return 0;
}
diff --git a/drivers/gpu/drm/xe/xe_i2c.h b/drivers/gpu/drm/xe/xe_i2c.h
index fdbad51950423..e28279f0ebec7 100644
--- a/drivers/gpu/drm/xe/xe_i2c.h
+++ b/drivers/gpu/drm/xe/xe_i2c.h
@@ -36,6 +36,7 @@ struct xe_i2c {
struct platform_device *pdev;
struct i2c_adapter *adapter;
struct i2c_client *client[XE_I2C_MAX_CLIENTS];
+ unsigned int ic_enable;
struct notifier_block bus_notifier;
struct work_struct work;
--
2.50.1
next prev parent reply other threads:[~2026-06-22 11:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 11:47 [PATCH v1 0/2] drm/xe/i2c: alerts and controller enabling modifications Heikki Krogerus
2026-06-22 11:47 ` [PATCH v1 1/2] drm/xe/i2c: Handler for SMBus Alerts Heikki Krogerus
2026-06-23 10:54 ` Andy Shevchenko
2026-06-23 11:44 ` Heikki Krogerus
2026-06-23 14:34 ` Raag Jadav
2026-06-24 9:23 ` Heikki Krogerus
2026-06-22 11:47 ` Heikki Krogerus [this message]
2026-06-23 10:56 ` [PATCH v1 2/2] drm/xe/mcu_i2c: Take over control of the controller enabling Andy Shevchenko
2026-06-23 14:58 ` Raag Jadav
2026-06-23 18:10 ` Andy Shevchenko
2026-06-24 9:27 ` Heikki Krogerus
2026-06-23 14:39 ` Raag Jadav
2026-06-24 10:13 ` Heikki Krogerus
2026-06-24 11:14 ` Raag Jadav
2026-06-24 11:28 ` Heikki Krogerus
2026-06-23 10:15 ` [PATCH v1 0/2] drm/xe/i2c: alerts and controller enabling modifications Heikki Krogerus
2026-06-23 14:40 ` Raag Jadav
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=20260622114759.3464047-3-heikki.krogerus@linux.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=airlied@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew.brost@intel.com \
--cc=michael.j.ruhl@intel.com \
--cc=mika.westerberg@linux.intel.com \
--cc=raag.jadav@intel.com \
--cc=riana.tauro@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@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