[PATCH v2 2/3] drm/xe/i2c: Handler for SMBus Alerts

From: Heikki Krogerus

Date: Thu Jun 25 2026 - 09:03:55 EST


Some devices that are attached to the I2C controller use the
SMBus Alert signal for example to inform the host about
thermal events, so registering the default SMBus Alert
device for them. The alert device makes sure that the alert
is processed and passed to the correct I2C client driver.

Signed-off-by: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>
---
drivers/gpu/drm/xe/Kconfig | 1 +
drivers/gpu/drm/xe/regs/xe_i2c_regs.h | 2 +
drivers/gpu/drm/xe/xe_i2c.c | 53 +++++++++++++++++++++++++--
drivers/gpu/drm/xe/xe_i2c.h | 5 +++
4 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/xe/Kconfig b/drivers/gpu/drm/xe/Kconfig
index 4d7dcaff2b915..7045ba19943e3 100644
--- a/drivers/gpu/drm/xe/Kconfig
+++ b/drivers/gpu/drm/xe/Kconfig
@@ -46,6 +46,7 @@ config DRM_XE
select WANT_DEV_COREDUMP
select AUXILIARY_BUS
select REGMAP if I2C
+ select I2C_SMBUS
help
Driver for Intel Xe2 series GPUs and later. Experimental support
for Xe series is also available.
diff --git a/drivers/gpu/drm/xe/regs/xe_i2c_regs.h b/drivers/gpu/drm/xe/regs/xe_i2c_regs.h
index f2e455e2bfe45..37550e4a20f80 100644
--- a/drivers/gpu/drm/xe/regs/xe_i2c_regs.h
+++ b/drivers/gpu/drm/xe/regs/xe_i2c_regs.h
@@ -20,4 +20,6 @@
#define I2C_CONFIG_CMD XE_REG(I2C_CONFIG_SPACE_OFFSET + PCI_COMMAND)
#define I2C_CONFIG_PMCSR XE_REG(I2C_CONFIG_SPACE_OFFSET + 0x84)

+#define I2C_REG(reg) XE_REG((reg) + I2C_MEM_SPACE_OFFSET)
+
#endif /* _XE_I2C_REGS_H_ */
diff --git a/drivers/gpu/drm/xe/xe_i2c.c b/drivers/gpu/drm/xe/xe_i2c.c
index 706783863d07d..0495b561957a2 100644
--- a/drivers/gpu/drm/xe/xe_i2c.c
+++ b/drivers/gpu/drm/xe/xe_i2c.c
@@ -9,8 +9,10 @@
#include <linux/array_size.h>
#include <linux/container_of.h>
#include <linux/device.h>
+#include <linux/designware_i2c.h>
#include <linux/err.h>
#include <linux/i2c.h>
+#include <linux/i2c-smbus.h>
#include <linux/ioport.h>
#include <linux/irq.h>
#include <linux/irqdomain.h>
@@ -30,6 +32,7 @@
#include "xe_device.h"
#include "xe_i2c.h"
#include "xe_mmio.h"
+#include "xe_platform_types.h"
#include "xe_sriov.h"
#include "xe_survivability_mode.h"

@@ -46,6 +49,7 @@
*/

static const char adapter_name[] = "i2c_designware";
+static struct i2c_smbus_alert_setup xe_i2c_smbus_setup;

static const struct property_entry xe_i2c_adapter_properties[] = {
PROPERTY_ENTRY_STRING("compatible", "intel,xe-i2c"),
@@ -61,6 +65,37 @@ static inline void xe_i2c_read_endpoint(struct xe_mmio *mmio, void *ep)
val[1] = xe_mmio_read32(mmio, REG_SG_REMAP_ADDR_POSTFIX);
}

+static void xe_i2c_handle_smbus_alert(struct xe_i2c *i2c)
+{
+ u32 stat;
+
+ stat = xe_mmio_read32(i2c->mmio, I2C_REG(DW_IC_SMBUS_INTR_STAT));
+ if (!stat)
+ return;
+
+ xe_mmio_write32(i2c->mmio, I2C_REG(DW_IC_CLR_SMBUS_INTR), stat);
+
+ if (stat & DW_IC_SMBUS_INTR_ALERT)
+ i2c_handle_smbus_alert(i2c->client[XE_I2C_CLIENT_ALERT]);
+}
+
+static int xe_i2c_register_smbus_alert(struct xe_i2c *i2c)
+{
+ struct xe_device *xe = kdev_to_xe_device(i2c->drm_dev);
+ struct i2c_client *alert;
+
+ if (xe->info.platform != XE_CRESCENTISLAND)
+ return 0;
+
+ alert = i2c_new_smbus_alert_device(i2c->adapter, &xe_i2c_smbus_setup);
+ if (IS_ERR(alert))
+ return PTR_ERR(alert);
+
+ i2c->client[XE_I2C_CLIENT_ALERT] = alert;
+
+ return 0;
+}
+
static void xe_i2c_client_work(struct work_struct *work)
{
struct xe_i2c *i2c = container_of(work, struct xe_i2c, work);
@@ -69,8 +104,13 @@ static void xe_i2c_client_work(struct work_struct *work)
.flags = I2C_CLIENT_HOST_NOTIFY,
.addr = i2c->ep.addr[1],
};
+ int ret;

- i2c->client[0] = i2c_new_client_device(i2c->adapter, &info);
+ ret = xe_i2c_register_smbus_alert(i2c);
+ if (ret)
+ dev_warn(i2c->drm_dev, "failed to register smbus alert (%d)\n", ret);
+
+ i2c->client[XE_I2C_CLIENT_AMC] = i2c_new_client_device(i2c->adapter, &info);
}

static int xe_i2c_notifier(struct notifier_block *nb, unsigned long action, void *data)
@@ -163,7 +203,7 @@ bool xe_i2c_present(struct xe_device *xe)

static bool xe_i2c_irq_present(struct xe_device *xe)
{
- return xe->i2c && xe->i2c->adapter_irq;
+ return xe->i2c && (xe->i2c->adapter_irq || xe->i2c->client[XE_I2C_CLIENT_ALERT]);
}

/**
@@ -182,7 +222,10 @@ void xe_i2c_irq_handler(struct xe_device *xe, u32 master_ctl)
return;

/* Forward interrupt to I2C adapter */
- generic_handle_irq_safe(xe->i2c->adapter_irq);
+ if (xe->info.platform == XE_CRESCENTISLAND)
+ xe_i2c_handle_smbus_alert(xe->i2c);
+ else
+ generic_handle_irq_safe(xe->i2c->adapter_irq);

/* Deassert after I2C adapter clears the interrupt */
xe_mmio_rmw32(mmio, I2C_CONFIG_CMD, 0, PCI_COMMAND_INTX_DISABLE);
@@ -307,8 +350,10 @@ static void xe_i2c_remove(void *data)
struct xe_i2c *i2c = data;
unsigned int i;

- for (i = 0; i < XE_I2C_MAX_CLIENTS; i++)
+ for (i = 0; i < XE_I2C_MAX_CLIENTS; i++) {
i2c_unregister_device(i2c->client[i]);
+ i2c->client[i] = NULL;
+ }

bus_unregister_notifier(&i2c_bus_type, &i2c->bus_notifier);
xe_i2c_unregister_adapter(i2c);
diff --git a/drivers/gpu/drm/xe/xe_i2c.h b/drivers/gpu/drm/xe/xe_i2c.h
index 425d8160835f4..b3327db998708 100644
--- a/drivers/gpu/drm/xe/xe_i2c.h
+++ b/drivers/gpu/drm/xe/xe_i2c.h
@@ -23,6 +23,11 @@ struct xe_mmio;
/* Endpoint Capabilities */
#define XE_I2C_EP_CAP_IRQ BIT(0)

+enum XE_I2C_CLIENT {
+ XE_I2C_CLIENT_AMC,
+ XE_I2C_CLIENT_ALERT,
+};
+
struct xe_i2c_endpoint {
u8 cookie;
u8 capabilities;
--
2.50.1