* [PATCH v2 0/6] i2c: designware: Enable mode swapping
@ 2025-12-18 15:14 Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 1/6] i2c: designware: Remove useless driver specific option for I2C target Heikki Krogerus
` (7 more replies)
0 siblings, 8 replies; 16+ messages in thread
From: Heikki Krogerus @ 2025-12-18 15:14 UTC (permalink / raw)
To: Andi Shyti, Mika Westerberg
Cc: Andy Shevchenko, Jan Dabros, Raag Jadav, linux-i2c, linux-kernel
Hi,
Changed since v1:
- The init cb is replaced with i2c_dw_init() also in i2c-designware-amdisp.c
- Checking I2C_FUNC_SLAVE in i2c_dw_reg_slave()
The original cover letter:
It's currently not possible to support MCTP or any other protocol that
requires support for both modes with the DesignWare I2C because the
driver can only be used in one mode. I'm assuming that the driver was
designed this way because the DesignWare I2C can not be operated as
I2C master and I2C slave simultaneously, however, that does not
actually mean both modes could not be supported at the same time. See
the patch 5/6 for more detailed explanation.
This series will enable support for both modes in the driver by
utilising a simple mode swap method, and that way make it possible to
support MCTP, IPMI, SMBus Host Notification Protocol, and any other
protocol requires the support for both modes with the DesignWare I2C.
thanks,
Heikki Krogerus (6):
i2c: designware: Remove useless driver specific option for I2C target
i2c: designware: Remove unnecessary function exports
i2c: designware: Combine some of the common functions
i2c: designware: Combine the init functions
i2c: designware: Enable mode swapping
i2c: designware: Remove an unnecessary condition
drivers/i2c/busses/Kconfig | 10 +-
drivers/i2c/busses/Makefile | 2 +-
drivers/i2c/busses/i2c-designware-amdisp.c | 4 +-
drivers/i2c/busses/i2c-designware-common.c | 211 +++++++++++++++++++--
drivers/i2c/busses/i2c-designware-core.h | 25 +--
drivers/i2c/busses/i2c-designware-master.c | 174 ++---------------
drivers/i2c/busses/i2c-designware-slave.c | 127 ++-----------
7 files changed, 254 insertions(+), 299 deletions(-)
--
2.50.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 1/6] i2c: designware: Remove useless driver specific option for I2C target
2025-12-18 15:14 [PATCH v2 0/6] i2c: designware: Enable mode swapping Heikki Krogerus
@ 2025-12-18 15:15 ` Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 2/6] i2c: designware: Remove unnecessary function exports Heikki Krogerus
` (6 subsequent siblings)
7 siblings, 0 replies; 16+ messages in thread
From: Heikki Krogerus @ 2025-12-18 15:15 UTC (permalink / raw)
To: Andi Shyti, Mika Westerberg
Cc: Andy Shevchenko, Jan Dabros, Raag Jadav, linux-i2c, linux-kernel
The generic option for I2C target is already user selectable,
which makes the DesignWare specific option completely
unnecessary. The DesignWare option also silently selected
I2C_SLAVE instead of depending on it without any real need
for it.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/i2c/busses/Kconfig | 10 ++--------
drivers/i2c/busses/Makefile | 2 +-
drivers/i2c/busses/i2c-designware-core.h | 2 +-
3 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 09ba55bae1fa..860812e224a0 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -569,20 +569,14 @@ config I2C_DESIGNWARE_CORE
help
This option enables support for the Synopsys DesignWare I2C adapter.
This driver includes support for the I2C host on the Synopsys
- Designware I2C adapter.
+ Designware I2C adapter, and the I2C slave when enabled (select
+ I2C_SLAVE).
To compile the driver as a module, choose M here: the module will be
called i2c-designware-core.
if I2C_DESIGNWARE_CORE
-config I2C_DESIGNWARE_SLAVE
- bool "Synopsys DesignWare Slave"
- select I2C_SLAVE
- help
- If you say yes to this option, support will be included for the
- Synopsys DesignWare I2C slave adapter.
-
config I2C_DESIGNWARE_PLATFORM
tristate "Synopsys DesignWare Platform driver"
depends on (ACPI && COMMON_CLK) || !ACPI
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index fb985769f5ff..547123ab351f 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -53,7 +53,7 @@ obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o
obj-$(CONFIG_I2C_DESIGNWARE_CORE) += i2c-designware-core.o
i2c-designware-core-y := i2c-designware-common.o
i2c-designware-core-y += i2c-designware-master.o
-i2c-designware-core-$(CONFIG_I2C_DESIGNWARE_SLAVE) += i2c-designware-slave.o
+i2c-designware-core-$(CONFIG_I2C_SLAVE) += i2c-designware-slave.o
obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += i2c-designware-platform.o
i2c-designware-platform-y := i2c-designware-platdrv.o
i2c-designware-platform-$(CONFIG_I2C_DESIGNWARE_AMDPSP) += i2c-designware-amdpsp.o
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index bb5ce0a382f9..2a7decc24931 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -386,7 +386,7 @@ void i2c_dw_disable(struct dw_i2c_dev *dev);
extern void i2c_dw_configure_master(struct dw_i2c_dev *dev);
extern int i2c_dw_probe_master(struct dw_i2c_dev *dev);
-#if IS_ENABLED(CONFIG_I2C_DESIGNWARE_SLAVE)
+#if IS_ENABLED(CONFIG_I2C_SLAVE)
extern void i2c_dw_configure_slave(struct dw_i2c_dev *dev);
extern int i2c_dw_probe_slave(struct dw_i2c_dev *dev);
#else
--
2.50.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 2/6] i2c: designware: Remove unnecessary function exports
2025-12-18 15:14 [PATCH v2 0/6] i2c: designware: Enable mode swapping Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 1/6] i2c: designware: Remove useless driver specific option for I2C target Heikki Krogerus
@ 2025-12-18 15:15 ` Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 3/6] i2c: designware: Combine some of the common functions Heikki Krogerus
` (5 subsequent siblings)
7 siblings, 0 replies; 16+ messages in thread
From: Heikki Krogerus @ 2025-12-18 15:15 UTC (permalink / raw)
To: Andi Shyti, Mika Westerberg
Cc: Andy Shevchenko, Jan Dabros, Raag Jadav, linux-i2c, linux-kernel
The master and slave probe functions are only called from
the core.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/i2c/busses/i2c-designware-master.c | 1 -
drivers/i2c/busses/i2c-designware-slave.c | 1 -
2 files changed, 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index f247cf323207..15b3a46f0132 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -1101,7 +1101,6 @@ int i2c_dw_probe_master(struct dw_i2c_dev *dev)
return ret;
}
-EXPORT_SYMBOL_GPL(i2c_dw_probe_master);
MODULE_DESCRIPTION("Synopsys DesignWare I2C bus master adapter");
MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-designware-slave.c b/drivers/i2c/busses/i2c-designware-slave.c
index 6eb16b7d75a6..1995be79544d 100644
--- a/drivers/i2c/busses/i2c-designware-slave.c
+++ b/drivers/i2c/busses/i2c-designware-slave.c
@@ -277,7 +277,6 @@ int i2c_dw_probe_slave(struct dw_i2c_dev *dev)
return ret;
}
-EXPORT_SYMBOL_GPL(i2c_dw_probe_slave);
MODULE_AUTHOR("Luis Oliveira <lolivei@synopsys.com>");
MODULE_DESCRIPTION("Synopsys DesignWare I2C bus slave adapter");
--
2.50.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 3/6] i2c: designware: Combine some of the common functions
2025-12-18 15:14 [PATCH v2 0/6] i2c: designware: Enable mode swapping Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 1/6] i2c: designware: Remove useless driver specific option for I2C target Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 2/6] i2c: designware: Remove unnecessary function exports Heikki Krogerus
@ 2025-12-18 15:15 ` Heikki Krogerus
2025-12-27 15:52 ` Andy Shevchenko
2025-12-18 15:15 ` [PATCH v2 4/6] i2c: designware: Combine the init functions Heikki Krogerus
` (4 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Heikki Krogerus @ 2025-12-18 15:15 UTC (permalink / raw)
To: Andi Shyti, Mika Westerberg
Cc: Andy Shevchenko, Jan Dabros, Raag Jadav, linux-i2c, linux-kernel
The adapter can be registered just in the core instead of
separately in the master and slave drivers. The same applies
to the interrupt.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/i2c/busses/i2c-designware-common.c | 108 +++++++++++++++++++--
drivers/i2c/busses/i2c-designware-core.h | 11 ++-
drivers/i2c/busses/i2c-designware-master.c | 97 +++---------------
drivers/i2c/busses/i2c-designware-slave.c | 53 ++--------
4 files changed, 126 insertions(+), 143 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
index 5b1e8f74c4ac..1823e4b71004 100644
--- a/drivers/i2c/busses/i2c-designware-common.c
+++ b/drivers/i2c/busses/i2c-designware-common.c
@@ -131,7 +131,7 @@ static int dw_reg_write_word(void *context, unsigned int reg, unsigned int val)
*
* Return: 0 on success, or negative errno otherwise.
*/
-int i2c_dw_init_regmap(struct dw_i2c_dev *dev)
+static int i2c_dw_init_regmap(struct dw_i2c_dev *dev)
{
struct regmap_config map_cfg = {
.reg_bits = 32,
@@ -457,7 +457,7 @@ u32 i2c_dw_scl_lcnt(struct dw_i2c_dev *dev, unsigned int reg, u32 ic_clk,
return DIV_ROUND_CLOSEST_ULL((u64)ic_clk * (tLOW + tf), MICRO) - 1 + offset;
}
-int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev)
+static int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev)
{
unsigned int reg;
int ret;
@@ -672,7 +672,7 @@ int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev)
return -EIO;
}
-int i2c_dw_set_fifo_size(struct dw_i2c_dev *dev)
+static int i2c_dw_set_fifo_size(struct dw_i2c_dev *dev)
{
u32 tx_fifo_depth, rx_fifo_depth;
unsigned int param;
@@ -741,19 +741,113 @@ void i2c_dw_disable(struct dw_i2c_dev *dev)
}
EXPORT_SYMBOL_GPL(i2c_dw_disable);
+static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
+{
+ struct dw_i2c_dev *dev = dev_id;
+
+ if (dev->mode == DW_IC_SLAVE)
+ return i2c_dw_isr_slave(dev);
+
+ return i2c_dw_isr_master(dev);
+}
+
+static const struct i2c_algorithm i2c_dw_algo = {
+ .xfer = i2c_dw_xfer,
+ .functionality = i2c_dw_func,
+#if IS_ENABLED(CONFIG_I2C_SLAVE)
+ .reg_slave = i2c_dw_reg_slave,
+ .unreg_slave = i2c_dw_unreg_slave,
+#endif
+};
+
+static const struct i2c_adapter_quirks i2c_dw_quirks = {
+ .flags = I2C_AQ_NO_ZERO_LEN,
+};
+
int i2c_dw_probe(struct dw_i2c_dev *dev)
{
+ struct i2c_adapter *adap = &dev->adapter;
+ unsigned long irq_flags;
+ int ret;
+
device_set_node(&dev->adapter.dev, dev_fwnode(dev->dev));
+ ret = i2c_dw_init_regmap(dev);
+ if (ret)
+ return ret;
+
+ ret = i2c_dw_set_sda_hold(dev);
+ if (ret)
+ return ret;
+
+ ret = i2c_dw_set_fifo_size(dev);
+ if (ret)
+ return ret;
+
switch (dev->mode) {
case DW_IC_SLAVE:
- return i2c_dw_probe_slave(dev);
+ ret = i2c_dw_probe_slave(dev);
+ break;
case DW_IC_MASTER:
- return i2c_dw_probe_master(dev);
+ ret = i2c_dw_probe_master(dev);
+ break;
default:
- dev_err(dev->dev, "Wrong operation mode: %d\n", dev->mode);
- return -EINVAL;
+ ret = -EINVAL;
+ break;
}
+ if (ret)
+ return ret;
+
+ ret = dev->init(dev);
+ if (ret)
+ return ret;
+
+ if (!adap->name[0])
+ strscpy(adap->name, "Synopsys DesignWare I2C adapter");
+
+ adap->retries = 3;
+ adap->algo = &i2c_dw_algo;
+ adap->quirks = &i2c_dw_quirks;
+ adap->dev.parent = dev->dev;
+ i2c_set_adapdata(adap, dev);
+
+ /*
+ * REVISIT: The mode check may not be necessary.
+ * For now keeping the flags as they were originally.
+ */
+ if (dev->mode == DW_IC_SLAVE)
+ irq_flags = IRQF_SHARED;
+ else if (dev->flags & ACCESS_NO_IRQ_SUSPEND)
+ irq_flags = IRQF_NO_SUSPEND;
+ else
+ irq_flags = IRQF_SHARED | IRQF_COND_SUSPEND;
+
+ ret = i2c_dw_acquire_lock(dev);
+ if (ret)
+ return ret;
+
+ __i2c_dw_write_intr_mask(dev, 0);
+ i2c_dw_release_lock(dev);
+
+ if (!(dev->flags & ACCESS_POLLING)) {
+ ret = devm_request_irq(dev->dev, dev->irq, i2c_dw_isr,
+ irq_flags, dev_name(dev->dev), dev);
+ if (ret)
+ return ret;
+ }
+
+ /*
+ * Increment PM usage count during adapter registration in order to
+ * avoid possible spurious runtime suspend when adapter device is
+ * registered to the device core and immediate resume in case bus has
+ * registered I2C slaves that do I2C transfers in their probe.
+ */
+ ACQUIRE(pm_runtime_noresume, pm)(dev->dev);
+ ret = ACQUIRE_ERR(pm_runtime_noresume, &pm);
+ if (ret)
+ return ret;
+
+ return i2c_add_numbered_adapter(adap);
}
EXPORT_SYMBOL_GPL(i2c_dw_probe);
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 2a7decc24931..0f58c4b50377 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -13,6 +13,7 @@
#include <linux/completion.h>
#include <linux/errno.h>
#include <linux/i2c.h>
+#include <linux/irqreturn.h>
#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/types.h>
@@ -333,20 +334,18 @@ struct i2c_dw_semaphore_callbacks {
int (*probe)(struct dw_i2c_dev *dev);
};
-int i2c_dw_init_regmap(struct dw_i2c_dev *dev);
u32 i2c_dw_scl_hcnt(struct dw_i2c_dev *dev, unsigned int reg, u32 ic_clk,
u32 tSYMBOL, u32 tf, int offset);
u32 i2c_dw_scl_lcnt(struct dw_i2c_dev *dev, unsigned int reg, u32 ic_clk,
u32 tLOW, u32 tf, int offset);
-int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev);
u32 i2c_dw_clk_rate(struct dw_i2c_dev *dev);
int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare);
int i2c_dw_acquire_lock(struct dw_i2c_dev *dev);
void i2c_dw_release_lock(struct dw_i2c_dev *dev);
int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev);
int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev);
-int i2c_dw_set_fifo_size(struct dw_i2c_dev *dev);
u32 i2c_dw_func(struct i2c_adapter *adap);
+irqreturn_t i2c_dw_isr_master(struct dw_i2c_dev *dev);
extern const struct dev_pm_ops i2c_dw_dev_pm_ops;
@@ -386,12 +385,18 @@ void i2c_dw_disable(struct dw_i2c_dev *dev);
extern void i2c_dw_configure_master(struct dw_i2c_dev *dev);
extern int i2c_dw_probe_master(struct dw_i2c_dev *dev);
+int i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
+
#if IS_ENABLED(CONFIG_I2C_SLAVE)
extern void i2c_dw_configure_slave(struct dw_i2c_dev *dev);
extern int i2c_dw_probe_slave(struct dw_i2c_dev *dev);
+irqreturn_t i2c_dw_isr_slave(struct dw_i2c_dev *dev);
+int i2c_dw_reg_slave(struct i2c_client *client);
+int i2c_dw_unreg_slave(struct i2c_client *client);
#else
static inline void i2c_dw_configure_slave(struct dw_i2c_dev *dev) { }
static inline int i2c_dw_probe_slave(struct dw_i2c_dev *dev) { return -EINVAL; }
+static inline irqreturn_t i2c_dw_isr_slave(struct dw_i2c_dev *dev) { return IRQ_NONE; }
#endif
static inline void i2c_dw_configure(struct dw_i2c_dev *dev)
diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 15b3a46f0132..91540a4520a3 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -191,10 +191,6 @@ static int i2c_dw_set_timings_master(struct dw_i2c_dev *dev)
dev->hs_hcnt, dev->hs_lcnt);
}
- ret = i2c_dw_set_sda_hold(dev);
- if (ret)
- return ret;
-
dev_dbg(dev->dev, "Bus speed: %s\n", i2c_freq_mode_string(t->bus_freq_hz));
return 0;
}
@@ -353,9 +349,8 @@ static int i2c_dw_status(struct dw_i2c_dev *dev)
* Initiate and continue master read/write transaction with polling
* based transfer routine afterward write messages into the Tx buffer.
*/
-static int amd_i2c_dw_xfer_quirk(struct i2c_adapter *adap, struct i2c_msg *msgs, int num_msgs)
+static int amd_i2c_dw_xfer_quirk(struct dw_i2c_dev *dev, struct i2c_msg *msgs, int num_msgs)
{
- struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
int msg_wrt_idx, msg_itr_lmt, buf_len, data_idx;
int cmd = 0, status;
u8 *tx_buf;
@@ -752,9 +747,8 @@ static void i2c_dw_process_transfer(struct dw_i2c_dev *dev, unsigned int stat)
* Interrupt service routine. This gets called whenever an I2C master interrupt
* occurs.
*/
-static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
+irqreturn_t i2c_dw_isr_master(struct dw_i2c_dev *dev)
{
- struct dw_i2c_dev *dev = dev_id;
unsigned int stat, enabled;
regmap_read(dev->map, DW_IC_ENABLE, &enabled);
@@ -815,9 +809,8 @@ static int i2c_dw_wait_transfer(struct dw_i2c_dev *dev)
* Prepare controller for a transaction and call i2c_dw_xfer_msg.
*/
static int
-i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
+i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)
{
- struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
int ret;
dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
@@ -908,19 +901,15 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
return ret;
}
-static const struct i2c_algorithm i2c_dw_algo = {
- .xfer = i2c_dw_xfer,
- .functionality = i2c_dw_func,
-};
+int i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
+{
+ struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
-static const struct i2c_algorithm amd_i2c_dw_algo = {
- .xfer = amd_i2c_dw_xfer_quirk,
- .functionality = i2c_dw_func,
-};
+ if ((dev->flags & MODEL_MASK) == MODEL_AMD_NAVI_GPU)
+ return amd_i2c_dw_xfer_quirk(dev, msgs, num);
-static const struct i2c_adapter_quirks i2c_dw_quirks = {
- .flags = I2C_AQ_NO_ZERO_LEN,
-};
+ return i2c_dw_xfer_common(dev, msgs, num);
+}
void i2c_dw_configure_master(struct dw_i2c_dev *dev)
{
@@ -1005,8 +994,6 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
int i2c_dw_probe_master(struct dw_i2c_dev *dev)
{
- struct i2c_adapter *adap = &dev->adapter;
- unsigned long irq_flags;
unsigned int ic_con;
int ret;
@@ -1014,18 +1001,10 @@ int i2c_dw_probe_master(struct dw_i2c_dev *dev)
dev->init = i2c_dw_init_master;
- ret = i2c_dw_init_regmap(dev);
- if (ret)
- return ret;
-
ret = i2c_dw_set_timings_master(dev);
if (ret)
return ret;
- ret = i2c_dw_set_fifo_size(dev);
- if (ret)
- return ret;
-
/* Lock the bus for accessing DW_IC_CON */
ret = i2c_dw_acquire_lock(dev);
if (ret)
@@ -1045,61 +1024,7 @@ int i2c_dw_probe_master(struct dw_i2c_dev *dev)
if (ic_con & DW_IC_CON_BUS_CLEAR_CTRL)
dev->master_cfg |= DW_IC_CON_BUS_CLEAR_CTRL;
- ret = dev->init(dev);
- if (ret)
- return ret;
-
- if (!adap->name[0])
- scnprintf(adap->name, sizeof(adap->name),
- "Synopsys DesignWare I2C adapter");
- adap->retries = 3;
- 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);
-
- if (dev->flags & ACCESS_NO_IRQ_SUSPEND) {
- irq_flags = IRQF_NO_SUSPEND;
- } else {
- irq_flags = IRQF_SHARED | IRQF_COND_SUSPEND;
- }
-
- ret = i2c_dw_acquire_lock(dev);
- if (ret)
- return ret;
-
- __i2c_dw_write_intr_mask(dev, 0);
- i2c_dw_release_lock(dev);
-
- if (!(dev->flags & ACCESS_POLLING)) {
- ret = devm_request_irq(dev->dev, dev->irq, i2c_dw_isr,
- irq_flags, dev_name(dev->dev), dev);
- if (ret)
- return dev_err_probe(dev->dev, ret,
- "failure requesting irq %i: %d\n",
- dev->irq, ret);
- }
-
- ret = i2c_dw_init_recovery_info(dev);
- if (ret)
- return ret;
-
- /*
- * Increment PM usage count during adapter registration in order to
- * avoid possible spurious runtime suspend when adapter device is
- * registered to the device core and immediate resume in case bus has
- * registered I2C slaves that do I2C transfers in their probe.
- */
- pm_runtime_get_noresume(dev->dev);
- ret = i2c_add_numbered_adapter(adap);
- if (ret)
- dev_err(dev->dev, "failure adding adapter: %d\n", ret);
- pm_runtime_put_noidle(dev->dev);
-
- return ret;
+ return i2c_dw_init_recovery_info(dev);
}
MODULE_DESCRIPTION("Synopsys DesignWare I2C bus master adapter");
diff --git a/drivers/i2c/busses/i2c-designware-slave.c b/drivers/i2c/busses/i2c-designware-slave.c
index 1995be79544d..c0baf53e97d8 100644
--- a/drivers/i2c/busses/i2c-designware-slave.c
+++ b/drivers/i2c/busses/i2c-designware-slave.c
@@ -63,7 +63,7 @@ static int i2c_dw_init_slave(struct dw_i2c_dev *dev)
return 0;
}
-static int i2c_dw_reg_slave(struct i2c_client *slave)
+int i2c_dw_reg_slave(struct i2c_client *slave)
{
struct dw_i2c_dev *dev = i2c_get_adapdata(slave->adapter);
@@ -88,7 +88,7 @@ static int i2c_dw_reg_slave(struct i2c_client *slave)
return 0;
}
-static int i2c_dw_unreg_slave(struct i2c_client *slave)
+int i2c_dw_unreg_slave(struct i2c_client *slave)
{
struct dw_i2c_dev *dev = i2c_get_adapdata(slave->adapter);
@@ -152,9 +152,8 @@ static u32 i2c_dw_read_clear_intrbits_slave(struct dw_i2c_dev *dev)
* Interrupt service routine. This gets called whenever an I2C slave interrupt
* occurs.
*/
-static irqreturn_t i2c_dw_isr_slave(int this_irq, void *dev_id)
+irqreturn_t i2c_dw_isr_slave(struct dw_i2c_dev *dev)
{
- struct dw_i2c_dev *dev = dev_id;
unsigned int raw_stat, stat, enabled, tmp;
u8 val = 0, slave_activity;
@@ -217,12 +216,6 @@ static irqreturn_t i2c_dw_isr_slave(int this_irq, void *dev_id)
return IRQ_HANDLED;
}
-static const struct i2c_algorithm i2c_dw_algo = {
- .functionality = i2c_dw_func,
- .reg_slave = i2c_dw_reg_slave,
- .unreg_slave = i2c_dw_unreg_slave,
-};
-
void i2c_dw_configure_slave(struct dw_i2c_dev *dev)
{
dev->functionality = I2C_FUNC_SLAVE;
@@ -236,46 +229,12 @@ EXPORT_SYMBOL_GPL(i2c_dw_configure_slave);
int i2c_dw_probe_slave(struct dw_i2c_dev *dev)
{
- struct i2c_adapter *adap = &dev->adapter;
- int ret;
+ if (dev->flags & ACCESS_POLLING)
+ return -EOPNOTSUPP;
dev->init = i2c_dw_init_slave;
- ret = i2c_dw_init_regmap(dev);
- if (ret)
- return ret;
-
- ret = i2c_dw_set_sda_hold(dev);
- if (ret)
- return ret;
-
- ret = i2c_dw_set_fifo_size(dev);
- if (ret)
- return ret;
-
- ret = dev->init(dev);
- if (ret)
- return ret;
-
- snprintf(adap->name, sizeof(adap->name),
- "Synopsys DesignWare I2C Slave adapter");
- adap->retries = 3;
- adap->algo = &i2c_dw_algo;
- adap->dev.parent = dev->dev;
- i2c_set_adapdata(adap, dev);
-
- ret = devm_request_irq(dev->dev, dev->irq, i2c_dw_isr_slave,
- IRQF_SHARED, dev_name(dev->dev), dev);
- if (ret)
- return dev_err_probe(dev->dev, ret,
- "failure requesting IRQ %i: %d\n",
- dev->irq, ret);
-
- ret = i2c_add_numbered_adapter(adap);
- if (ret)
- dev_err(dev->dev, "failure adding adapter: %d\n", ret);
-
- return ret;
+ return 0;
}
MODULE_AUTHOR("Luis Oliveira <lolivei@synopsys.com>");
--
2.50.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 4/6] i2c: designware: Combine the init functions
2025-12-18 15:14 [PATCH v2 0/6] i2c: designware: Enable mode swapping Heikki Krogerus
` (2 preceding siblings ...)
2025-12-18 15:15 ` [PATCH v2 3/6] i2c: designware: Combine some of the common functions Heikki Krogerus
@ 2025-12-18 15:15 ` Heikki Krogerus
2025-12-27 15:53 ` Andy Shevchenko
2025-12-18 15:15 ` [PATCH v2 5/6] i2c: designware: Enable mode swapping Heikki Krogerus
` (3 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Heikki Krogerus @ 2025-12-18 15:15 UTC (permalink / raw)
To: Andi Shyti, Mika Westerberg
Cc: Andy Shevchenko, Jan Dabros, Raag Jadav, linux-i2c, linux-kernel
Providing a single function for controller initialisation.
The controller initialisation has the same steps for master
and slave modes, except the timing parameters are only
needed in master mode.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/i2c/busses/i2c-designware-amdisp.c | 4 +-
drivers/i2c/busses/i2c-designware-common.c | 81 +++++++++++++++++++++-
drivers/i2c/busses/i2c-designware-core.h | 3 +-
drivers/i2c/busses/i2c-designware-master.c | 70 +------------------
drivers/i2c/busses/i2c-designware-slave.c | 44 ------------
5 files changed, 85 insertions(+), 117 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-amdisp.c b/drivers/i2c/busses/i2c-designware-amdisp.c
index 450793d5f839..ec9259dd2a4f 100644
--- a/drivers/i2c/busses/i2c-designware-amdisp.c
+++ b/drivers/i2c/busses/i2c-designware-amdisp.c
@@ -163,8 +163,8 @@ static int amd_isp_dw_i2c_plat_runtime_resume(struct device *dev)
if (!i_dev->shared_with_punit)
i2c_dw_prepare_clk(i_dev, true);
- if (i_dev->init)
- i_dev->init(i_dev);
+
+ i2c_dw_init(i_dev);
return 0;
}
diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
index 1823e4b71004..8e99549b37a3 100644
--- a/drivers/i2c/busses/i2c-designware-common.c
+++ b/drivers/i2c/busses/i2c-designware-common.c
@@ -358,6 +358,83 @@ static inline u32 i2c_dw_acpi_round_bus_speed(struct device *device) { return 0;
#endif /* CONFIG_ACPI */
+static void i2c_dw_configure_mode(struct dw_i2c_dev *dev)
+{
+ switch (dev->mode) {
+ case DW_IC_MASTER:
+ regmap_write(dev->map, DW_IC_TX_TL, dev->tx_fifo_depth / 2);
+ regmap_write(dev->map, DW_IC_RX_TL, 0);
+ regmap_write(dev->map, DW_IC_CON, dev->master_cfg);
+ break;
+ case DW_IC_SLAVE:
+ regmap_write(dev->map, DW_IC_TX_TL, 0);
+ regmap_write(dev->map, DW_IC_RX_TL, 0);
+ regmap_write(dev->map, DW_IC_CON, dev->slave_cfg);
+ regmap_write(dev->map, DW_IC_INTR_MASK, DW_IC_INTR_SLAVE_MASK);
+ break;
+ default:
+ return;
+ }
+}
+
+static void i2c_dw_write_timings(struct dw_i2c_dev *dev)
+{
+ /* Write standard speed timing parameters */
+ regmap_write(dev->map, DW_IC_SS_SCL_HCNT, dev->ss_hcnt);
+ regmap_write(dev->map, DW_IC_SS_SCL_LCNT, dev->ss_lcnt);
+
+ /* Write fast mode/fast mode plus timing parameters */
+ regmap_write(dev->map, DW_IC_FS_SCL_HCNT, dev->fs_hcnt);
+ regmap_write(dev->map, DW_IC_FS_SCL_LCNT, dev->fs_lcnt);
+
+ /* Write high speed timing parameters if supported */
+ if (dev->hs_hcnt && dev->hs_lcnt) {
+ regmap_write(dev->map, DW_IC_HS_SCL_HCNT, dev->hs_hcnt);
+ regmap_write(dev->map, DW_IC_HS_SCL_LCNT, dev->hs_lcnt);
+ }
+}
+
+/**
+ * i2c_dw_init() - Initialize the DesignWare I2C hardware
+ * @dev: device private data
+ *
+ * This functions configures and enables the DesigWare I2C hardware.
+ *
+ * Return: 0 on success, or negative errno otherwise.
+ */
+int i2c_dw_init(struct dw_i2c_dev *dev)
+{
+ int ret;
+
+ ret = i2c_dw_acquire_lock(dev);
+ if (ret)
+ return ret;
+
+ /* Disable the adapter */
+ __i2c_dw_disable(dev);
+
+ /*
+ * Mask SMBus interrupts to block storms from broken
+ * firmware that leaves IC_SMBUS=1; the handler never
+ * services them.
+ */
+ regmap_write(dev->map, DW_IC_SMBUS_INTR_MASK, 0);
+
+ if (dev->mode == DW_IC_MASTER)
+ i2c_dw_write_timings(dev);
+
+ /* Write SDA hold time if supported */
+ if (dev->sda_hold_time)
+ regmap_write(dev->map, DW_IC_SDA_HOLD, dev->sda_hold_time);
+
+ i2c_dw_configure_mode(dev);
+
+ i2c_dw_release_lock(dev);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(i2c_dw_init);
+
static void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev)
{
u32 acpi_speed = i2c_dw_acpi_round_bus_speed(dev->dev);
@@ -798,7 +875,7 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)
if (ret)
return ret;
- ret = dev->init(dev);
+ ret = i2c_dw_init(dev);
if (ret)
return ret;
@@ -891,7 +968,7 @@ static int i2c_dw_runtime_resume(struct device *device)
if (!dev->shared_with_punit)
i2c_dw_prepare_clk(dev, true);
- dev->init(dev);
+ i2c_dw_init(dev);
return 0;
}
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 0f58c4b50377..82465b134c34 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -240,7 +240,6 @@ struct reset_control;
* @semaphore_idx: Index of table with semaphore type attached to the bus. It's
* -1 if there is no semaphore.
* @shared_with_punit: true if this bus is shared with the SoC's PUNIT
- * @init: function to initialize the I2C hardware
* @set_sda_hold_time: callback to retrieve IP specific SDA hold timing
* @mode: operation mode - DW_IC_MASTER or DW_IC_SLAVE
* @rinfo: I²C GPIO recovery information
@@ -301,7 +300,6 @@ struct dw_i2c_dev {
void (*release_lock)(void);
int semaphore_idx;
bool shared_with_punit;
- int (*init)(struct dw_i2c_dev *dev);
int (*set_sda_hold_time)(struct dw_i2c_dev *dev);
int mode;
struct i2c_bus_recovery_info rinfo;
@@ -408,6 +406,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);
#if IS_ENABLED(CONFIG_I2C_DESIGNWARE_BAYTRAIL)
int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev);
diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 91540a4520a3..33432bbaec1f 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -31,16 +31,6 @@
#define AMD_TIMEOUT_MAX_US 250
#define AMD_MASTERCFG_MASK GENMASK(15, 0)
-static void i2c_dw_configure_fifo_master(struct dw_i2c_dev *dev)
-{
- /* Configure Tx/Rx FIFO threshold levels */
- regmap_write(dev->map, DW_IC_TX_TL, dev->tx_fifo_depth / 2);
- regmap_write(dev->map, DW_IC_RX_TL, 0);
-
- /* Configure the I2C master */
- regmap_write(dev->map, DW_IC_CON, dev->master_cfg);
-}
-
static int i2c_dw_set_timings_master(struct dw_i2c_dev *dev)
{
unsigned int comp_param1;
@@ -195,58 +185,6 @@ static int i2c_dw_set_timings_master(struct dw_i2c_dev *dev)
return 0;
}
-/**
- * i2c_dw_init_master() - Initialize the DesignWare I2C master hardware
- * @dev: device private data
- *
- * This functions configures and enables the I2C master.
- * This function is called during I2C init function, and in case of timeout at
- * run time.
- *
- * Return: 0 on success, or negative errno otherwise.
- */
-static int i2c_dw_init_master(struct dw_i2c_dev *dev)
-{
- int ret;
-
- ret = i2c_dw_acquire_lock(dev);
- if (ret)
- return ret;
-
- /* Disable the adapter */
- __i2c_dw_disable(dev);
-
- /*
- * Mask SMBus interrupts to block storms from broken
- * firmware that leaves IC_SMBUS=1; the handler never
- * services them.
- */
- regmap_write(dev->map, DW_IC_SMBUS_INTR_MASK, 0);
-
- /* Write standard speed timing parameters */
- regmap_write(dev->map, DW_IC_SS_SCL_HCNT, dev->ss_hcnt);
- regmap_write(dev->map, DW_IC_SS_SCL_LCNT, dev->ss_lcnt);
-
- /* Write fast mode/fast mode plus timing parameters */
- regmap_write(dev->map, DW_IC_FS_SCL_HCNT, dev->fs_hcnt);
- regmap_write(dev->map, DW_IC_FS_SCL_LCNT, dev->fs_lcnt);
-
- /* Write high speed timing parameters if supported */
- if (dev->hs_hcnt && dev->hs_lcnt) {
- regmap_write(dev->map, DW_IC_HS_SCL_HCNT, dev->hs_hcnt);
- regmap_write(dev->map, DW_IC_HS_SCL_LCNT, dev->hs_lcnt);
- }
-
- /* Write SDA hold time if supported */
- if (dev->sda_hold_time)
- regmap_write(dev->map, DW_IC_SDA_HOLD, dev->sda_hold_time);
-
- i2c_dw_configure_fifo_master(dev);
- i2c_dw_release_lock(dev);
-
- return 0;
-}
-
static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
{
struct i2c_msg *msgs = dev->msgs;
@@ -843,9 +781,9 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)
ret = i2c_dw_wait_transfer(dev);
if (ret) {
dev_err(dev->dev, "controller timed out\n");
- /* i2c_dw_init_master() implicitly disables the adapter */
+ /* i2c_dw_init() implicitly disables the adapter */
i2c_recover_bus(&dev->adapter);
- i2c_dw_init_master(dev);
+ i2c_dw_init(dev);
goto done;
}
@@ -950,7 +888,7 @@ static void i2c_dw_unprepare_recovery(struct i2c_adapter *adap)
i2c_dw_prepare_clk(dev, true);
reset_control_deassert(dev->rst);
- i2c_dw_init_master(dev);
+ i2c_dw_init(dev);
}
static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
@@ -999,8 +937,6 @@ int i2c_dw_probe_master(struct dw_i2c_dev *dev)
init_completion(&dev->cmd_complete);
- dev->init = i2c_dw_init_master;
-
ret = i2c_dw_set_timings_master(dev);
if (ret)
return ret;
diff --git a/drivers/i2c/busses/i2c-designware-slave.c b/drivers/i2c/busses/i2c-designware-slave.c
index c0baf53e97d8..9fc8faa33735 100644
--- a/drivers/i2c/busses/i2c-designware-slave.c
+++ b/drivers/i2c/busses/i2c-designware-slave.c
@@ -21,48 +21,6 @@
#include "i2c-designware-core.h"
-static void i2c_dw_configure_fifo_slave(struct dw_i2c_dev *dev)
-{
- /* Configure Tx/Rx FIFO threshold levels. */
- regmap_write(dev->map, DW_IC_TX_TL, 0);
- regmap_write(dev->map, DW_IC_RX_TL, 0);
-
- /* Configure the I2C slave. */
- regmap_write(dev->map, DW_IC_CON, dev->slave_cfg);
- regmap_write(dev->map, DW_IC_INTR_MASK, DW_IC_INTR_SLAVE_MASK);
-}
-
-/**
- * i2c_dw_init_slave() - Initialize the DesignWare i2c slave hardware
- * @dev: device private data
- *
- * This function configures and enables the I2C in slave mode.
- * This function is called during I2C init function, and in case of timeout at
- * run time.
- *
- * Return: 0 on success, or negative errno otherwise.
- */
-static int i2c_dw_init_slave(struct dw_i2c_dev *dev)
-{
- int ret;
-
- ret = i2c_dw_acquire_lock(dev);
- if (ret)
- return ret;
-
- /* Disable the adapter. */
- __i2c_dw_disable(dev);
-
- /* Write SDA hold time if supported */
- if (dev->sda_hold_time)
- regmap_write(dev->map, DW_IC_SDA_HOLD, dev->sda_hold_time);
-
- i2c_dw_configure_fifo_slave(dev);
- i2c_dw_release_lock(dev);
-
- return 0;
-}
-
int i2c_dw_reg_slave(struct i2c_client *slave)
{
struct dw_i2c_dev *dev = i2c_get_adapdata(slave->adapter);
@@ -232,8 +190,6 @@ int i2c_dw_probe_slave(struct dw_i2c_dev *dev)
if (dev->flags & ACCESS_POLLING)
return -EOPNOTSUPP;
- dev->init = i2c_dw_init_slave;
-
return 0;
}
--
2.50.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 5/6] i2c: designware: Enable mode swapping
2025-12-18 15:14 [PATCH v2 0/6] i2c: designware: Enable mode swapping Heikki Krogerus
` (3 preceding siblings ...)
2025-12-18 15:15 ` [PATCH v2 4/6] i2c: designware: Combine the init functions Heikki Krogerus
@ 2025-12-18 15:15 ` Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 6/6] i2c: designware: Remove an unnecessary condition Heikki Krogerus
` (2 subsequent siblings)
7 siblings, 0 replies; 16+ messages in thread
From: Heikki Krogerus @ 2025-12-18 15:15 UTC (permalink / raw)
To: Andi Shyti, Mika Westerberg
Cc: Andy Shevchenko, Jan Dabros, Raag Jadav, linux-i2c, linux-kernel
The DesignWare I2C can not be operated as I2C master and
I2C slave simultaneously, but that does not actually mean
master and slave modes can not be supported at the same
time. It just means an explicit mode swap needs to be
executed when the mode is changed. The DesignWare I2C
documentation actually describes a couple of cases where the
mode is excepted to be changed.
The I2C master will now always be supported. Both modes are
now always configured in i2c_dw_configure(), but the slave
mode will continue to be available only when the Kconfig
option I2C_SLAVE is enabled.
The driver will now start in master mode and then swap to
slave mode when a slave device is registered. After a slave
device is registered, the controller is swapped to master
mode when a transfer in master mode is started and then back
to slave mode again after the transfer is completed.
The DesignWare I2C can now be used with protocols such as
MCTP (drivers/net/mctp/mctp-i2c.c) and IPMI
(drivers/char/ipmi/) that require support for both I2C
master and I2C slave. It is now also possible to support the
SMBus Host Notification Protocol as I2C master if needed.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/i2c/busses/i2c-designware-common.c | 50 +++++++++++++++-------
drivers/i2c/busses/i2c-designware-core.h | 9 ++--
drivers/i2c/busses/i2c-designware-master.c | 6 ++-
drivers/i2c/busses/i2c-designware-slave.c | 35 +++++++--------
4 files changed, 57 insertions(+), 43 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
index 8e99549b37a3..aac7b1f4710f 100644
--- a/drivers/i2c/busses/i2c-designware-common.c
+++ b/drivers/i2c/busses/i2c-designware-common.c
@@ -358,21 +358,25 @@ static inline u32 i2c_dw_acpi_round_bus_speed(struct device *device) { return 0;
#endif /* CONFIG_ACPI */
-static void i2c_dw_configure_mode(struct dw_i2c_dev *dev)
+static void i2c_dw_configure_mode(struct dw_i2c_dev *dev, int mode)
{
- switch (dev->mode) {
+ switch (mode) {
case DW_IC_MASTER:
regmap_write(dev->map, DW_IC_TX_TL, dev->tx_fifo_depth / 2);
regmap_write(dev->map, DW_IC_RX_TL, 0);
regmap_write(dev->map, DW_IC_CON, dev->master_cfg);
break;
case DW_IC_SLAVE:
+ dev->status = 0;
regmap_write(dev->map, DW_IC_TX_TL, 0);
regmap_write(dev->map, DW_IC_RX_TL, 0);
regmap_write(dev->map, DW_IC_CON, dev->slave_cfg);
+ regmap_write(dev->map, DW_IC_SAR, dev->slave->addr);
regmap_write(dev->map, DW_IC_INTR_MASK, DW_IC_INTR_SLAVE_MASK);
+ __i2c_dw_enable(dev);
break;
default:
+ WARN(1, "Invalid mode %d\n", mode);
return;
}
}
@@ -394,6 +398,31 @@ static void i2c_dw_write_timings(struct dw_i2c_dev *dev)
}
}
+/**
+ * i2c_dw_set_mode() - Select the controller mode of operation - master or slave
+ * @dev: device private data
+ * @mode: I2C mode of operation
+ *
+ * Configures the controller to operate in @mode. This function needs to be
+ * called when ever a mode swap is required.
+ *
+ * Setting the slave mode does not have an effect before a slave device is
+ * registered. So before the slave device is registered, the controller is kept
+ * in master mode regardless of @mode.
+ *
+ * The controller must be disabled before this function is called.
+ */
+void i2c_dw_set_mode(struct dw_i2c_dev *dev, int mode)
+{
+ if (mode == DW_IC_SLAVE && !dev->slave)
+ mode = DW_IC_MASTER;
+ if (dev->mode == mode)
+ return;
+
+ i2c_dw_configure_mode(dev, mode);
+ dev->mode = mode;
+}
+
/**
* i2c_dw_init() - Initialize the DesignWare I2C hardware
* @dev: device private data
@@ -420,14 +449,13 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
*/
regmap_write(dev->map, DW_IC_SMBUS_INTR_MASK, 0);
- if (dev->mode == DW_IC_MASTER)
- i2c_dw_write_timings(dev);
+ i2c_dw_write_timings(dev);
/* Write SDA hold time if supported */
if (dev->sda_hold_time)
regmap_write(dev->map, DW_IC_SDA_HOLD, dev->sda_hold_time);
- i2c_dw_configure_mode(dev);
+ i2c_dw_configure_mode(dev, dev->mode);
i2c_dw_release_lock(dev);
@@ -861,17 +889,7 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)
if (ret)
return ret;
- switch (dev->mode) {
- case DW_IC_SLAVE:
- ret = i2c_dw_probe_slave(dev);
- break;
- case DW_IC_MASTER:
- ret = i2c_dw_probe_master(dev);
- break;
- default:
- ret = -EINVAL;
- break;
- }
+ ret = i2c_dw_probe_master(dev);
if (ret)
return ret;
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 82465b134c34..5d783d585406 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -387,26 +387,23 @@ int i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
#if IS_ENABLED(CONFIG_I2C_SLAVE)
extern void i2c_dw_configure_slave(struct dw_i2c_dev *dev);
-extern int i2c_dw_probe_slave(struct dw_i2c_dev *dev);
irqreturn_t i2c_dw_isr_slave(struct dw_i2c_dev *dev);
int i2c_dw_reg_slave(struct i2c_client *client);
int i2c_dw_unreg_slave(struct i2c_client *client);
#else
static inline void i2c_dw_configure_slave(struct dw_i2c_dev *dev) { }
-static inline int i2c_dw_probe_slave(struct dw_i2c_dev *dev) { return -EINVAL; }
static inline irqreturn_t i2c_dw_isr_slave(struct dw_i2c_dev *dev) { return IRQ_NONE; }
#endif
static inline void i2c_dw_configure(struct dw_i2c_dev *dev)
{
- if (i2c_detect_slave_mode(dev->dev))
- i2c_dw_configure_slave(dev);
- else
- i2c_dw_configure_master(dev);
+ i2c_dw_configure_slave(dev);
+ i2c_dw_configure_master(dev);
}
int i2c_dw_probe(struct dw_i2c_dev *dev);
int i2c_dw_init(struct dw_i2c_dev *dev);
+void i2c_dw_set_mode(struct dw_i2c_dev *dev, int mode);
#if IS_ENABLED(CONFIG_I2C_DESIGNWARE_BAYTRAIL)
int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev);
diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 33432bbaec1f..ba2ee526ecc6 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -194,6 +194,8 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
/* Disable the adapter */
__i2c_dw_disable(dev);
+ i2c_dw_set_mode(dev, DW_IC_MASTER);
+
/* If the slave address is ten bit address, enable 10BITADDR */
if (msgs[dev->msg_write_idx].flags & I2C_M_TEN) {
ic_con = DW_IC_CON_10BITADDR_MASTER;
@@ -831,6 +833,8 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)
ret = -EIO;
done:
+ i2c_dw_set_mode(dev, DW_IC_SLAVE);
+
i2c_dw_release_lock(dev);
done_nolock:
@@ -853,7 +857,7 @@ void i2c_dw_configure_master(struct dw_i2c_dev *dev)
{
struct i2c_timings *t = &dev->timings;
- dev->functionality = I2C_FUNC_10BIT_ADDR | DW_IC_DEFAULT_FUNCTIONALITY;
+ dev->functionality |= I2C_FUNC_10BIT_ADDR | DW_IC_DEFAULT_FUNCTIONALITY;
dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
DW_IC_CON_RESTART_EN;
diff --git a/drivers/i2c/busses/i2c-designware-slave.c b/drivers/i2c/busses/i2c-designware-slave.c
index 9fc8faa33735..ad0d5fbfa6d5 100644
--- a/drivers/i2c/busses/i2c-designware-slave.c
+++ b/drivers/i2c/busses/i2c-designware-slave.c
@@ -24,24 +24,25 @@
int i2c_dw_reg_slave(struct i2c_client *slave)
{
struct dw_i2c_dev *dev = i2c_get_adapdata(slave->adapter);
+ int ret;
+ if (!i2c_check_functionality(slave->adapter, I2C_FUNC_SLAVE))
+ return -EOPNOTSUPP;
if (dev->slave)
return -EBUSY;
if (slave->flags & I2C_CLIENT_TEN)
return -EAFNOSUPPORT;
- pm_runtime_get_sync(dev->dev);
- /*
- * Set slave address in the IC_SAR register,
- * the address to which the DW_apb_i2c responds.
- */
+ ret = i2c_dw_acquire_lock(dev);
+ if (ret)
+ return ret;
+
+ pm_runtime_get_sync(dev->dev);
__i2c_dw_disable_nowait(dev);
- regmap_write(dev->map, DW_IC_SAR, slave->addr);
dev->slave = slave;
+ i2c_dw_set_mode(dev, DW_IC_SLAVE);
- __i2c_dw_enable(dev);
-
- dev->status = 0;
+ i2c_dw_release_lock(dev);
return 0;
}
@@ -54,6 +55,7 @@ int i2c_dw_unreg_slave(struct i2c_client *slave)
i2c_dw_disable(dev);
synchronize_irq(dev->irq);
dev->slave = NULL;
+ i2c_dw_set_mode(dev, DW_IC_MASTER);
pm_runtime_put_sync_suspend(dev->dev);
return 0;
@@ -176,23 +178,16 @@ irqreturn_t i2c_dw_isr_slave(struct dw_i2c_dev *dev)
void i2c_dw_configure_slave(struct dw_i2c_dev *dev)
{
- dev->functionality = I2C_FUNC_SLAVE;
+ if (dev->flags & ACCESS_POLLING)
+ return;
+
+ dev->functionality |= I2C_FUNC_SLAVE;
dev->slave_cfg = DW_IC_CON_RX_FIFO_FULL_HLD_CTRL |
DW_IC_CON_RESTART_EN | DW_IC_CON_STOP_DET_IFADDRESSED;
-
- dev->mode = DW_IC_SLAVE;
}
EXPORT_SYMBOL_GPL(i2c_dw_configure_slave);
-int i2c_dw_probe_slave(struct dw_i2c_dev *dev)
-{
- if (dev->flags & ACCESS_POLLING)
- return -EOPNOTSUPP;
-
- return 0;
-}
-
MODULE_AUTHOR("Luis Oliveira <lolivei@synopsys.com>");
MODULE_DESCRIPTION("Synopsys DesignWare I2C bus slave adapter");
MODULE_LICENSE("GPL v2");
--
2.50.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 6/6] i2c: designware: Remove an unnecessary condition
2025-12-18 15:14 [PATCH v2 0/6] i2c: designware: Enable mode swapping Heikki Krogerus
` (4 preceding siblings ...)
2025-12-18 15:15 ` [PATCH v2 5/6] i2c: designware: Enable mode swapping Heikki Krogerus
@ 2025-12-18 15:15 ` Heikki Krogerus
2025-12-27 15:32 ` Andy Shevchenko
2025-12-19 7:43 ` [PATCH v2 0/6] i2c: designware: Enable mode swapping Mika Westerberg
2025-12-27 20:17 ` Andi Shyti
7 siblings, 1 reply; 16+ messages in thread
From: Heikki Krogerus @ 2025-12-18 15:15 UTC (permalink / raw)
To: Andi Shyti, Mika Westerberg
Cc: Andy Shevchenko, Jan Dabros, Raag Jadav, linux-i2c, linux-kernel
Writing also the high speed timing registers unconditionally.
The reset value for these registers is 0, so this should
always be safe.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/i2c/busses/i2c-designware-common.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
index aac7b1f4710f..1981dbfa260f 100644
--- a/drivers/i2c/busses/i2c-designware-common.c
+++ b/drivers/i2c/busses/i2c-designware-common.c
@@ -391,11 +391,9 @@ static void i2c_dw_write_timings(struct dw_i2c_dev *dev)
regmap_write(dev->map, DW_IC_FS_SCL_HCNT, dev->fs_hcnt);
regmap_write(dev->map, DW_IC_FS_SCL_LCNT, dev->fs_lcnt);
- /* Write high speed timing parameters if supported */
- if (dev->hs_hcnt && dev->hs_lcnt) {
- regmap_write(dev->map, DW_IC_HS_SCL_HCNT, dev->hs_hcnt);
- regmap_write(dev->map, DW_IC_HS_SCL_LCNT, dev->hs_lcnt);
- }
+ /* Write high speed timing parameters */
+ regmap_write(dev->map, DW_IC_HS_SCL_HCNT, dev->hs_hcnt);
+ regmap_write(dev->map, DW_IC_HS_SCL_LCNT, dev->hs_lcnt);
}
/**
--
2.50.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v2 0/6] i2c: designware: Enable mode swapping
2025-12-18 15:14 [PATCH v2 0/6] i2c: designware: Enable mode swapping Heikki Krogerus
` (5 preceding siblings ...)
2025-12-18 15:15 ` [PATCH v2 6/6] i2c: designware: Remove an unnecessary condition Heikki Krogerus
@ 2025-12-19 7:43 ` Mika Westerberg
2025-12-27 20:17 ` Andi Shyti
7 siblings, 0 replies; 16+ messages in thread
From: Mika Westerberg @ 2025-12-19 7:43 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Andi Shyti, Andy Shevchenko, Jan Dabros, Raag Jadav, linux-i2c,
linux-kernel
On Thu, Dec 18, 2025 at 04:14:59PM +0100, Heikki Krogerus wrote:
> Hi,
>
> Changed since v1:
> - The init cb is replaced with i2c_dw_init() also in i2c-designware-amdisp.c
> - Checking I2C_FUNC_SLAVE in i2c_dw_reg_slave()
>
> The original cover letter:
>
> It's currently not possible to support MCTP or any other protocol that
> requires support for both modes with the DesignWare I2C because the
> driver can only be used in one mode. I'm assuming that the driver was
> designed this way because the DesignWare I2C can not be operated as
> I2C master and I2C slave simultaneously, however, that does not
> actually mean both modes could not be supported at the same time. See
> the patch 5/6 for more detailed explanation.
>
> This series will enable support for both modes in the driver by
> utilising a simple mode swap method, and that way make it possible to
> support MCTP, IPMI, SMBus Host Notification Protocol, and any other
> protocol requires the support for both modes with the DesignWare I2C.
>
> thanks,
>
> Heikki Krogerus (6):
> i2c: designware: Remove useless driver specific option for I2C target
> i2c: designware: Remove unnecessary function exports
> i2c: designware: Combine some of the common functions
> i2c: designware: Combine the init functions
> i2c: designware: Enable mode swapping
> i2c: designware: Remove an unnecessary condition
For the whole series,
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 6/6] i2c: designware: Remove an unnecessary condition
2025-12-18 15:15 ` [PATCH v2 6/6] i2c: designware: Remove an unnecessary condition Heikki Krogerus
@ 2025-12-27 15:32 ` Andy Shevchenko
0 siblings, 0 replies; 16+ messages in thread
From: Andy Shevchenko @ 2025-12-27 15:32 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Andi Shyti, Mika Westerberg, Jan Dabros, Raag Jadav, linux-i2c,
linux-kernel
On Thu, Dec 18, 2025 at 04:15:05PM +0100, Heikki Krogerus wrote:
> Writing also the high speed timing registers unconditionally.
> The reset value for these registers is 0, so this should
> always be safe.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/6] i2c: designware: Combine some of the common functions
2025-12-18 15:15 ` [PATCH v2 3/6] i2c: designware: Combine some of the common functions Heikki Krogerus
@ 2025-12-27 15:52 ` Andy Shevchenko
2025-12-30 14:14 ` Heikki Krogerus
0 siblings, 1 reply; 16+ messages in thread
From: Andy Shevchenko @ 2025-12-27 15:52 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Andi Shyti, Mika Westerberg, Jan Dabros, Raag Jadav, linux-i2c,
linux-kernel
On Thu, Dec 18, 2025 at 04:15:02PM +0100, Heikki Krogerus wrote:
> The adapter can be registered just in the core instead of
> separately in the master and slave drivers. The same applies
> to the interrupt.
...
> int i2c_dw_probe(struct dw_i2c_dev *dev)
> {
> + struct i2c_adapter *adap = &dev->adapter;
> + unsigned long irq_flags;
> + int ret;
> +
> device_set_node(&dev->adapter.dev, dev_fwnode(dev->dev));
>
> + ret = i2c_dw_init_regmap(dev);
> + if (ret)
> + return ret;
> +
> + ret = i2c_dw_set_sda_hold(dev);
> + if (ret)
> + return ret;
> +
> + ret = i2c_dw_set_fifo_size(dev);
> + if (ret)
> + return ret;
> +
> switch (dev->mode) {
> case DW_IC_SLAVE:
> - return i2c_dw_probe_slave(dev);
> + ret = i2c_dw_probe_slave(dev);
> + break;
> case DW_IC_MASTER:
> - return i2c_dw_probe_master(dev);
> + ret = i2c_dw_probe_master(dev);
> + break;
> default:
> - dev_err(dev->dev, "Wrong operation mode: %d\n", dev->mode);
> - return -EINVAL;
> + ret = -EINVAL;
> + break;
> }
> + if (ret)
> + return ret;
> +
> + ret = dev->init(dev);
> + if (ret)
> + return ret;
> + if (!adap->name[0])
> + strscpy(adap->name, "Synopsys DesignWare I2C adapter");
Hmm... See below.
> + adap->retries = 3;
> + adap->algo = &i2c_dw_algo;
> + adap->quirks = &i2c_dw_quirks;
> + adap->dev.parent = dev->dev;
> + i2c_set_adapdata(adap, dev);
> +
> + /*
> + * REVISIT: The mode check may not be necessary.
> + * For now keeping the flags as they were originally.
> + */
> + if (dev->mode == DW_IC_SLAVE)
> + irq_flags = IRQF_SHARED;
> + else if (dev->flags & ACCESS_NO_IRQ_SUSPEND)
> + irq_flags = IRQF_NO_SUSPEND;
> + else
> + irq_flags = IRQF_SHARED | IRQF_COND_SUSPEND;
> +
> + ret = i2c_dw_acquire_lock(dev);
> + if (ret)
> + return ret;
> +
> + __i2c_dw_write_intr_mask(dev, 0);
> + i2c_dw_release_lock(dev);
> +
> + if (!(dev->flags & ACCESS_POLLING)) {
> + ret = devm_request_irq(dev->dev, dev->irq, i2c_dw_isr,
> + irq_flags, dev_name(dev->dev), dev);
> + if (ret)
> + return ret;
> + }
> +
> + /*
> + * Increment PM usage count during adapter registration in order to
> + * avoid possible spurious runtime suspend when adapter device is
> + * registered to the device core and immediate resume in case bus has
> + * registered I2C slaves that do I2C transfers in their probe.
> + */
> + ACQUIRE(pm_runtime_noresume, pm)(dev->dev);
> + ret = ACQUIRE_ERR(pm_runtime_noresume, &pm);
> + if (ret)
> + return ret;
> +
> + return i2c_add_numbered_adapter(adap);
> }
...
> - snprintf(adap->name, sizeof(adap->name),
> - "Synopsys DesignWare I2C Slave adapter");
This patch changes the user visible strings (via `i2cdetect`) or module names
in case we want to find it by name (note, we already have such precedents for
other adapters). Currently we have three variants if I not miss anything:
Generic for master (as in this change), Generic for slave, and AMD platform
driver case. If you think this is okay change, then just drop the AMD case
as well, and hence remove the no more needed conditional. Otherwise I would
somehow group this naming in one place, if possible.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 4/6] i2c: designware: Combine the init functions
2025-12-18 15:15 ` [PATCH v2 4/6] i2c: designware: Combine the init functions Heikki Krogerus
@ 2025-12-27 15:53 ` Andy Shevchenko
0 siblings, 0 replies; 16+ messages in thread
From: Andy Shevchenko @ 2025-12-27 15:53 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Andi Shyti, Mika Westerberg, Jan Dabros, Raag Jadav, linux-i2c,
linux-kernel
On Thu, Dec 18, 2025 at 04:15:03PM +0100, Heikki Krogerus wrote:
> Providing a single function for controller initialisation.
> The controller initialisation has the same steps for master
> and slave modes, except the timing parameters are only
> needed in master mode.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 0/6] i2c: designware: Enable mode swapping
2025-12-18 15:14 [PATCH v2 0/6] i2c: designware: Enable mode swapping Heikki Krogerus
` (6 preceding siblings ...)
2025-12-19 7:43 ` [PATCH v2 0/6] i2c: designware: Enable mode swapping Mika Westerberg
@ 2025-12-27 20:17 ` Andi Shyti
7 siblings, 0 replies; 16+ messages in thread
From: Andi Shyti @ 2025-12-27 20:17 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Mika Westerberg, Andy Shevchenko, Jan Dabros, Raag Jadav,
linux-i2c, linux-kernel
Hi Heikki,
> Heikki Krogerus (6):
> i2c: designware: Remove useless driver specific option for I2C target
> i2c: designware: Remove unnecessary function exports
to unburden you a little, I applied the first two patches.
Andi
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/6] i2c: designware: Combine some of the common functions
2025-12-27 15:52 ` Andy Shevchenko
@ 2025-12-30 14:14 ` Heikki Krogerus
2026-01-19 13:18 ` Heikki Krogerus
0 siblings, 1 reply; 16+ messages in thread
From: Heikki Krogerus @ 2025-12-30 14:14 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Andi Shyti, Mika Westerberg, Jan Dabros, Raag Jadav, linux-i2c,
linux-kernel
Hi Andy,
> > - snprintf(adap->name, sizeof(adap->name),
> > - "Synopsys DesignWare I2C Slave adapter");
>
> This patch changes the user visible strings (via `i2cdetect`) or module names
> in case we want to find it by name (note, we already have such precedents for
> other adapters). Currently we have three variants if I not miss anything:
> Generic for master (as in this change), Generic for slave, and AMD platform
> driver case. If you think this is okay change, then just drop the AMD case
> as well, and hence remove the no more needed conditional. Otherwise I would
> somehow group this naming in one place, if possible.
The only thing that this will change is, it removes the common
slave/target only description, because after this that setup is no
longer possible - master mode is now always supported. So this is the
correct thing to do.
I don't think the user space should ever rely on a description like
this except possibly with some customised/non-common systems that the
user space really has to handle in some specific way, but if something
really did rely on this common "target only" description, it could
have only used it to determine that it basically can't use the device
for anything as it's slave/target only - so basically to use it to
check the functionality (same as i2cdetect -F). But as said, this is
no longer a problem.
As for the AMD case, if I understood what you are proposing, I
disagree with you. The glue drivers should always be allowed to assign
the name (these would be the "non-common" systems that the user space
may actually need to know about). I'm also against grouping the
naming. The glue drivers must handle the platform specifics including
the naming if needed, not the core.
thanks,
--
heikki
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/6] i2c: designware: Combine some of the common functions
2025-12-30 14:14 ` Heikki Krogerus
@ 2026-01-19 13:18 ` Heikki Krogerus
2026-01-19 13:44 ` Andy Shevchenko
0 siblings, 1 reply; 16+ messages in thread
From: Heikki Krogerus @ 2026-01-19 13:18 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Andi Shyti, Mika Westerberg, Jan Dabros, Raag Jadav, linux-i2c,
linux-kernel
Tue, Dec 30, 2025 at 04:14:32PM +0200, Heikki Krogerus kirjoitti:
> Hi Andy,
>
> > > - snprintf(adap->name, sizeof(adap->name),
> > > - "Synopsys DesignWare I2C Slave adapter");
> >
> > This patch changes the user visible strings (via `i2cdetect`) or module names
> > in case we want to find it by name (note, we already have such precedents for
> > other adapters). Currently we have three variants if I not miss anything:
> > Generic for master (as in this change), Generic for slave, and AMD platform
> > driver case. If you think this is okay change, then just drop the AMD case
> > as well, and hence remove the no more needed conditional. Otherwise I would
> > somehow group this naming in one place, if possible.
>
> The only thing that this will change is, it removes the common
> slave/target only description, because after this that setup is no
> longer possible - master mode is now always supported. So this is the
> correct thing to do.
>
> I don't think the user space should ever rely on a description like
> this except possibly with some customised/non-common systems that the
> user space really has to handle in some specific way, but if something
> really did rely on this common "target only" description, it could
> have only used it to determine that it basically can't use the device
> for anything as it's slave/target only - so basically to use it to
> check the functionality (same as i2cdetect -F). But as said, this is
> no longer a problem.
>
> As for the AMD case, if I understood what you are proposing, I
> disagree with you. The glue drivers should always be allowed to assign
> the name (these would be the "non-common" systems that the user space
> may actually need to know about). I'm also against grouping the
> naming. The glue drivers must handle the platform specifics including
> the naming if needed, not the core.
Ping.
--
heikki
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/6] i2c: designware: Combine some of the common functions
2026-01-19 13:18 ` Heikki Krogerus
@ 2026-01-19 13:44 ` Andy Shevchenko
2026-01-19 13:49 ` Heikki Krogerus
0 siblings, 1 reply; 16+ messages in thread
From: Andy Shevchenko @ 2026-01-19 13:44 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Andi Shyti, Mika Westerberg, Jan Dabros, Raag Jadav, linux-i2c,
linux-kernel
On Mon, Jan 19, 2026 at 03:18:34PM +0200, Heikki Krogerus wrote:
> Tue, Dec 30, 2025 at 04:14:32PM +0200, Heikki Krogerus kirjoitti:
...
> > > > - snprintf(adap->name, sizeof(adap->name),
> > > > - "Synopsys DesignWare I2C Slave adapter");
> > >
> > > This patch changes the user visible strings (via `i2cdetect`) or module names
> > > in case we want to find it by name (note, we already have such precedents for
> > > other adapters). Currently we have three variants if I not miss anything:
> > > Generic for master (as in this change), Generic for slave, and AMD platform
> > > driver case. If you think this is okay change, then just drop the AMD case
> > > as well, and hence remove the no more needed conditional. Otherwise I would
> > > somehow group this naming in one place, if possible.
> >
> > The only thing that this will change is, it removes the common
> > slave/target only description, because after this that setup is no
> > longer possible - master mode is now always supported. So this is the
> > correct thing to do.
> >
> > I don't think the user space should ever rely on a description like
> > this except possibly with some customised/non-common systems that the
> > user space really has to handle in some specific way, but if something
> > really did rely on this common "target only" description, it could
> > have only used it to determine that it basically can't use the device
> > for anything as it's slave/target only - so basically to use it to
> > check the functionality (same as i2cdetect -F). But as said, this is
> > no longer a problem.
> >
> > As for the AMD case, if I understood what you are proposing, I
> > disagree with you. The glue drivers should always be allowed to assign
> > the name (these would be the "non-common" systems that the user space
> > may actually need to know about). I'm also against grouping the
> > naming. The glue drivers must handle the platform specifics including
> > the naming if needed, not the core.
>
> Ping.
Do you need my input on this? If you think this is good change, make sure the
summary of the above goes to the commit message.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/6] i2c: designware: Combine some of the common functions
2026-01-19 13:44 ` Andy Shevchenko
@ 2026-01-19 13:49 ` Heikki Krogerus
0 siblings, 0 replies; 16+ messages in thread
From: Heikki Krogerus @ 2026-01-19 13:49 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Andi Shyti, Mika Westerberg, Jan Dabros, Raag Jadav, linux-i2c,
linux-kernel
Mon, Jan 19, 2026 at 03:44:22PM +0200, Andy Shevchenko kirjoitti:
> On Mon, Jan 19, 2026 at 03:18:34PM +0200, Heikki Krogerus wrote:
> > Tue, Dec 30, 2025 at 04:14:32PM +0200, Heikki Krogerus kirjoitti:
>
> ...
>
> > > > > - snprintf(adap->name, sizeof(adap->name),
> > > > > - "Synopsys DesignWare I2C Slave adapter");
> > > >
> > > > This patch changes the user visible strings (via `i2cdetect`) or module names
> > > > in case we want to find it by name (note, we already have such precedents for
> > > > other adapters). Currently we have three variants if I not miss anything:
> > > > Generic for master (as in this change), Generic for slave, and AMD platform
> > > > driver case. If you think this is okay change, then just drop the AMD case
> > > > as well, and hence remove the no more needed conditional. Otherwise I would
> > > > somehow group this naming in one place, if possible.
> > >
> > > The only thing that this will change is, it removes the common
> > > slave/target only description, because after this that setup is no
> > > longer possible - master mode is now always supported. So this is the
> > > correct thing to do.
> > >
> > > I don't think the user space should ever rely on a description like
> > > this except possibly with some customised/non-common systems that the
> > > user space really has to handle in some specific way, but if something
> > > really did rely on this common "target only" description, it could
> > > have only used it to determine that it basically can't use the device
> > > for anything as it's slave/target only - so basically to use it to
> > > check the functionality (same as i2cdetect -F). But as said, this is
> > > no longer a problem.
> > >
> > > As for the AMD case, if I understood what you are proposing, I
> > > disagree with you. The glue drivers should always be allowed to assign
> > > the name (these would be the "non-common" systems that the user space
> > > may actually need to know about). I'm also against grouping the
> > > naming. The glue drivers must handle the platform specifics including
> > > the naming if needed, not the core.
> >
> > Ping.
>
> Do you need my input on this? If you think this is good change, make sure the
> summary of the above goes to the commit message.
Got it.
Thanks Andy,
--
heikki
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2026-01-19 13:49 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-18 15:14 [PATCH v2 0/6] i2c: designware: Enable mode swapping Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 1/6] i2c: designware: Remove useless driver specific option for I2C target Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 2/6] i2c: designware: Remove unnecessary function exports Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 3/6] i2c: designware: Combine some of the common functions Heikki Krogerus
2025-12-27 15:52 ` Andy Shevchenko
2025-12-30 14:14 ` Heikki Krogerus
2026-01-19 13:18 ` Heikki Krogerus
2026-01-19 13:44 ` Andy Shevchenko
2026-01-19 13:49 ` Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 4/6] i2c: designware: Combine the init functions Heikki Krogerus
2025-12-27 15:53 ` Andy Shevchenko
2025-12-18 15:15 ` [PATCH v2 5/6] i2c: designware: Enable mode swapping Heikki Krogerus
2025-12-18 15:15 ` [PATCH v2 6/6] i2c: designware: Remove an unnecessary condition Heikki Krogerus
2025-12-27 15:32 ` Andy Shevchenko
2025-12-19 7:43 ` [PATCH v2 0/6] i2c: designware: Enable mode swapping Mika Westerberg
2025-12-27 20:17 ` Andi Shyti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox