[PATCH v5 3/6] i2c: designware: Add dedicated algorithm for AMD NAVI

Benoît Monin posted 6 patches 2 weeks, 5 days ago
There is a newer version of this series
[PATCH v5 3/6] i2c: designware: Add dedicated algorithm for AMD NAVI
Posted by Benoît Monin 2 weeks, 5 days ago
Apart from runtime PM, there is nothing in common between i2c_dw_xfer()
and amd_i2c_dw_xfer_quirk(), so give AMD NAVI controller its own algorithm
instead of calling the quirk from i2c_dw_xfer().

Add runtime PM handling to amd_i2c_dw_xfer_quirk() and a dedicated
i2c_algorithm for AMD NAVI controllers. The adapter algorithm is set
during probe based on the device model.

This way we avoid checking for the device model at the start of every
transfer.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Benoît Monin <benoit.monin@bootlin.com>
---
 drivers/i2c/busses/i2c-designware-master.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 4493568e2fa3..f247cf323207 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -361,6 +361,10 @@ static int amd_i2c_dw_xfer_quirk(struct i2c_adapter *adap, struct i2c_msg *msgs,
 	u8 *tx_buf;
 	unsigned int val;
 
+	ACQUIRE(pm_runtime_active_auto_try, pm)(dev->dev);
+	if (ACQUIRE_ERR(pm_runtime_active_auto_try, &pm))
+		return -ENXIO;
+
 	/*
 	 * In order to enable the interrupt for UCSI i.e. AMD NAVI GPU card,
 	 * it is mandatory to set the right value in specific register
@@ -820,14 +824,6 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 
 	pm_runtime_get_sync(dev->dev);
 
-	switch (dev->flags & MODEL_MASK) {
-	case MODEL_AMD_NAVI_GPU:
-		ret = amd_i2c_dw_xfer_quirk(adap, msgs, num);
-		goto done_nolock;
-	default:
-		break;
-	}
-
 	reinit_completion(&dev->cmd_complete);
 	dev->msgs = msgs;
 	dev->msgs_num = num;
@@ -917,6 +913,11 @@ static const struct i2c_algorithm i2c_dw_algo = {
 	.functionality = i2c_dw_func,
 };
 
+static const struct i2c_algorithm amd_i2c_dw_algo = {
+	.xfer = amd_i2c_dw_xfer_quirk,
+	.functionality = i2c_dw_func,
+};
+
 static const struct i2c_adapter_quirks i2c_dw_quirks = {
 	.flags = I2C_AQ_NO_ZERO_LEN,
 };
@@ -1052,7 +1053,10 @@ int i2c_dw_probe_master(struct dw_i2c_dev *dev)
 		scnprintf(adap->name, sizeof(adap->name),
 			  "Synopsys DesignWare I2C adapter");
 	adap->retries = 3;
-	adap->algo = &i2c_dw_algo;
+	if ((dev->flags & MODEL_MASK) == MODEL_AMD_NAVI_GPU)
+		adap->algo = &amd_i2c_dw_algo;
+	else
+		adap->algo = &i2c_dw_algo;
 	adap->quirks = &i2c_dw_quirks;
 	adap->dev.parent = dev->dev;
 	i2c_set_adapdata(adap, dev);

-- 
2.52.0

Re: [PATCH v5 3/6] i2c: designware: Add dedicated algorithm for AMD NAVI
Posted by Andy Shevchenko 2 weeks, 5 days ago
On Tue, Jan 20, 2026 at 10:28:03AM +0100, Benoît Monin wrote:
> Apart from runtime PM, there is nothing in common between i2c_dw_xfer()
> and amd_i2c_dw_xfer_quirk(), so give AMD NAVI controller its own algorithm
> instead of calling the quirk from i2c_dw_xfer().
> 
> Add runtime PM handling to amd_i2c_dw_xfer_quirk() and a dedicated
> i2c_algorithm for AMD NAVI controllers. The adapter algorithm is set
> during probe based on the device model.
> 
> This way we avoid checking for the device model at the start of every
> transfer.

...

> +	ACQUIRE(pm_runtime_active_auto_try, pm)(dev->dev);
> +	if (ACQUIRE_ERR(pm_runtime_active_auto_try, &pm))
> +		return -ENXIO;

There are PM_ACQUIRE_*() macros available now.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v5 3/6] i2c: designware: Add dedicated algorithm for AMD NAVI
Posted by Andi Shyti 2 weeks, 3 days ago
Hi Benoit,

On Tue, Jan 20, 2026 at 11:39:46AM +0200, Andy Shevchenko wrote:
> On Tue, Jan 20, 2026 at 10:28:03AM +0100, Benoît Monin wrote:
> > Apart from runtime PM, there is nothing in common between i2c_dw_xfer()
> > and amd_i2c_dw_xfer_quirk(), so give AMD NAVI controller its own algorithm
> > instead of calling the quirk from i2c_dw_xfer().
> > 
> > Add runtime PM handling to amd_i2c_dw_xfer_quirk() and a dedicated
> > i2c_algorithm for AMD NAVI controllers. The adapter algorithm is set
> > during probe based on the device model.
> > 
> > This way we avoid checking for the device model at the start of every
> > transfer.
> 
> ...
> 
> > +	ACQUIRE(pm_runtime_active_auto_try, pm)(dev->dev);
> > +	if (ACQUIRE_ERR(pm_runtime_active_auto_try, &pm))
> > +		return -ENXIO;
> 
> There are PM_ACQUIRE_*() macros available now.

I already applied this patch. You could eventually send a new one
using the PM_ACQUIRE_*() as suggested by Andy.

Thanks,
Andi