]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/xe/pm: Wire up suspend/resume for I2C controller
authorRaag Jadav <raag.jadav@intel.com>
Tue, 1 Jul 2025 12:22:51 +0000 (15:22 +0300)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 10 Jul 2025 14:19:41 +0000 (10:19 -0400)
Wire up suspend/resume handles for I2C controller to match its power
state with SGUnit.

Signed-off-by: Raag Jadav <raag.jadav@intel.com>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Karthik Poosa <karthik.poosa@intel.com>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Link: https://lore.kernel.org/r/20250701122252.2590230-5-heikki.krogerus@linux.intel.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/regs/xe_i2c_regs.h
drivers/gpu/drm/xe/xe_i2c.c
drivers/gpu/drm/xe/xe_i2c.h
drivers/gpu/drm/xe/xe_pm.c

index 92dae4487614369c612484c160a8e938ed27ee41..af781c8e4a804131d9387605e3c8a757babc1aee 100644 (file)
@@ -2,6 +2,8 @@
 #ifndef _XE_I2C_REGS_H_
 #define _XE_I2C_REGS_H_
 
+#include <linux/pci_regs.h>
+
 #include "xe_reg_defs.h"
 #include "xe_regs.h"
 
@@ -12,4 +14,7 @@
 #define REG_SG_REMAP_ADDR_PREFIX       XE_REG(SOC_BASE + 0x0164)
 #define REG_SG_REMAP_ADDR_POSTFIX      XE_REG(SOC_BASE + 0x0168)
 
+#define I2C_CONFIG_CMD                 XE_REG(I2C_CONFIG_SPACE_OFFSET + PCI_COMMAND)
+#define I2C_CONFIG_PMCSR               XE_REG(I2C_CONFIG_SPACE_OFFSET + 0x84)
+
 #endif /* _XE_I2C_REGS_H_ */
index 6f05142a8abf58cf411b56097badf80867000dd3..db9c0340be5c4083062b20677b873e9ce9630aeb 100644 (file)
@@ -226,6 +226,31 @@ static const struct regmap_config i2c_regmap_config = {
        .fast_io = true,
 };
 
+void xe_i2c_pm_suspend(struct xe_device *xe)
+{
+       struct xe_mmio *mmio = xe_root_tile_mmio(xe);
+
+       if (!xe->i2c || xe->i2c->ep.cookie != XE_I2C_EP_COOKIE_DEVICE)
+               return;
+
+       xe_mmio_rmw32(mmio, I2C_CONFIG_PMCSR, PCI_PM_CTRL_STATE_MASK, (__force u32)PCI_D3hot);
+       drm_dbg(&xe->drm, "pmcsr: 0x%08x\n", xe_mmio_read32(mmio, I2C_CONFIG_PMCSR));
+}
+
+void xe_i2c_pm_resume(struct xe_device *xe, bool d3cold)
+{
+       struct xe_mmio *mmio = xe_root_tile_mmio(xe);
+
+       if (!xe->i2c || xe->i2c->ep.cookie != XE_I2C_EP_COOKIE_DEVICE)
+               return;
+
+       if (d3cold)
+               xe_mmio_rmw32(mmio, I2C_CONFIG_CMD, 0, PCI_COMMAND_MEMORY);
+
+       xe_mmio_rmw32(mmio, I2C_CONFIG_PMCSR, PCI_PM_CTRL_STATE_MASK, (__force u32)PCI_D0);
+       drm_dbg(&xe->drm, "pmcsr: 0x%08x\n", xe_mmio_read32(mmio, I2C_CONFIG_PMCSR));
+}
+
 static void xe_i2c_remove(void *data)
 {
        struct xe_i2c *i2c = data;
@@ -270,6 +295,10 @@ int xe_i2c_probe(struct xe_device *xe)
        i2c->mmio = xe_root_tile_mmio(xe);
        i2c->drm_dev = drm_dev;
        i2c->ep = ep;
+       xe->i2c = i2c;
+
+       /* PCI PM isn't aware of this device, bring it up and match it with SGUnit state. */
+       xe_i2c_pm_resume(xe, true);
 
        regmap = devm_regmap_init(drm_dev, NULL, i2c, &i2c_regmap_config);
        if (IS_ERR(regmap))
index 7ea40f4e4aa4f561121e9a7767ea3c6ed31ea1c7..b767ed8ce52b641c3d9c3fb66e6914126ccc0373 100644 (file)
@@ -50,9 +50,13 @@ struct xe_i2c {
 #if IS_ENABLED(CONFIG_I2C)
 int xe_i2c_probe(struct xe_device *xe);
 void xe_i2c_irq_handler(struct xe_device *xe, u32 master_ctl);
+void xe_i2c_pm_suspend(struct xe_device *xe);
+void xe_i2c_pm_resume(struct xe_device *xe, bool d3cold);
 #else
 static inline int xe_i2c_probe(struct xe_device *xe) { return 0; }
 static inline void xe_i2c_irq_handler(struct xe_device *xe, u32 master_ctl) { }
+static inline void xe_i2c_pm_suspend(struct xe_device *xe) { }
+static inline void xe_i2c_pm_resume(struct xe_device *xe, bool d3cold) { }
 #endif
 
 #endif
index bcfda545e74f80dbf53facd1aa6f0451d530150d..f171a91b849c14bfa5a5a23791936b8c6bf0f804 100644 (file)
@@ -19,6 +19,7 @@
 #include "xe_ggtt.h"
 #include "xe_gt.h"
 #include "xe_guc.h"
+#include "xe_i2c.h"
 #include "xe_irq.h"
 #include "xe_pcode.h"
 #include "xe_pxp.h"
@@ -146,6 +147,8 @@ int xe_pm_suspend(struct xe_device *xe)
 
        xe_display_pm_suspend_late(xe);
 
+       xe_i2c_pm_suspend(xe);
+
        drm_dbg(&xe->drm, "Device suspended\n");
        return 0;
 
@@ -190,6 +193,8 @@ int xe_pm_resume(struct xe_device *xe)
        if (err)
                goto err;
 
+       xe_i2c_pm_resume(xe, xe->d3cold.allowed);
+
        xe_irq_resume(xe);
 
        for_each_gt(gt, xe, id)
@@ -487,6 +492,8 @@ int xe_pm_runtime_suspend(struct xe_device *xe)
 
        xe_display_pm_runtime_suspend_late(xe);
 
+       xe_i2c_pm_suspend(xe);
+
        xe_rpm_lockmap_release(xe);
        xe_pm_write_callback_task(xe, NULL);
        return 0;
@@ -534,6 +541,8 @@ int xe_pm_runtime_resume(struct xe_device *xe)
                        goto out;
        }
 
+       xe_i2c_pm_resume(xe, xe->d3cold.allowed);
+
        xe_irq_resume(xe);
 
        for_each_gt(gt, xe, id)