Skip to contentSkip to conversation

i2c: Add Loongson-2K0300 I2C controller support

PATCH Superseded Binbin Zhou 3 participants 7 messages Mar 10 – Mar 17

Subsystems (4)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Binbin Zhou

author maintainer
#0 lore raw

v5 cover i2c: Add Loongson-2K0300 I2C controller support

Hi all:

This patch set describes the I2C controller integrated the Loongson-2K0300 chip.

It has a significantly different design from the previous I2C controller(i2c-ls2x), such as support for master-slave transfer mode, and DMA transfers (implementation in progress), etc. Therefore, we try to name it i2c-ls2x-v2.

Thanks.

======
V5:
- Rebase on linux-i2c/i2c-next;
Patch (2/2):
- Add time.h header file;
- Add the MHz suffix to parent_rate and freq;
- Define an iterator within the for loop, with its type being

    `unsigned int`;

- Use dev_err_probe() in loongson2_i2c_adjust_bus_speed();
- i2c_adapter_set_node()->device_set_node().

Link to V4:
https://lore.kernel.org/all/[email protected]/

V4:
- Rebase on linux-i2c/i2c-next;
Patch (2/2):
- The parent_rate parameter type should be unsigned long;
- Drop fallthrough and add missing break;
- device_set_node()->i2c_adapter_set_node();
- Use i2c_parse_fw_timings();
- Use i2c_t.bus_freq_hz instead of priv->speed;
- Sperate loongson2_i2c_handle_read() into loongson2_i2c_handle_read() and loongson2_i2c_handle_rx_done().

Link to V3:
https://lore.kernel.org/all/[email protected]/

V3:
- Rebase on linux-i2c/i2c-next;
Patch (2/2):
- Reorder header file follow IWYU principle;
- Better indentation and coding style;
- Use generic macro definitions;
- Amend *all* struct data types;
- Correct unreasonable variable type definitions;
- Refact loongson2_i2c_isr_error();
- of_property_read_u32()->device_property_read_u32();
- Remove meaningless blank lines and output.

Link to V2:
https://lore.kernel.org/all/[email protected]/

V2:
Patch (1/2):
- Add Acked-by tag from Conor, thanks.

Patch (2/2):
- Reorder the definitions of read() and write();
- Adjust the calculation method for bus speed.

Link to V1:
https://lore.kernel.org/all/[email protected]/

Binbin Zhou (2):
dt-bindings: i2c: loongson,ls2x: Add ls2k0300-i2c compatible
i2c: ls2x-v2: Add driver for Loongson-2K0300 I2C controller

 .../bindings/i2c/loongson,ls2x-i2c.yaml       |   4 +
 MAINTAINERS                                   |   1 +
 drivers/i2c/busses/Kconfig                    |  10 +
 drivers/i2c/busses/Makefile                   |   1 +
 drivers/i2c/busses/i2c-ls2x-v2.c              | 544 ++++++++++++++++++
 5 files changed, 560 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ls2x-v2.c

base-commit: b82316862bea929265725c077dffcec42e3dc20b

Signature · 1 line
2.52.0
author maintainer
#1 lore raw

PATCH v5 1/2 dt-bindings: i2c: loongson,ls2x: Add ls2k0300-i2c compatible

Add "loongson,ls2k0300-i2c" dedicated compatible for representing I2C of Loongson-2K0300 chip, because its HW integration is quiet different from others.

---
 Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml +4 -0
index 67882ec6e06a..ee09c6d9c5f0 100644
@@ -16,6 +16,7 @@ properties:
   compatible:
     enum:
       - loongson,ls2k-i2c
+      - loongson,ls2k0300-i2c
       - loongson,ls7a-i2c
 
   reg:
@@ -24,6 +25,9 @@ properties:
   interrupts:
     maxItems: 1
 
+  clocks:
+    maxItems: 1
+
 required:
   - compatible
   - reg
Signature · 1 line
2.52.0
author maintainer
#2 lore raw

PATCH v5 2/2 i2c: ls2x-v2: Add driver for Loongson-2K0300 I2C controller

In reply to Binbin Zhou

This I2C module is integrated into the Loongson-2K0300 SoCs.

It provides multi-master functionality and controls all I2C bus-specific timing, protocols, arbitration, and timing. It supports both standard and fast modes.

---
 MAINTAINERS                      |   1 +
 drivers/i2c/busses/Kconfig       |  10 +
 drivers/i2c/busses/Makefile      |   1 +
 drivers/i2c/busses/i2c-ls2x-v2.c | 544 +++++++++++++++++++++++++++++++
 4 files changed, 556 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ls2x-v2.c
MAINTAINERS +1 -0
index 77fdfcb55f06..90d4b24b0966 100644
@@ -14955,6 +14955,7 @@ M:	Binbin Zhou <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml
+F:	drivers/i2c/busses/i2c-ls2x-v2.c
 F:	drivers/i2c/busses/i2c-ls2x.c
 
 LOONGSON PWM DRIVER
drivers/i2c/busses/Kconfig +10 -0
index e11d50750e63..5cad2d0d2569 100644
@@ -850,6 +850,16 @@ config I2C_LS2X
 	  This driver can also be built as a module. If so, the module
 	  will be called i2c-ls2x.
 
+config I2C_LS2X_V2
+	tristate "Loongson-2 Fast Speed I2C adapter"
+	depends on LOONGARCH || COMPILE_TEST
+	help
+	  If you say yes to this option, support will be included for the
+	  I2C interface on the Loongson-2K0300 SoCs.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called i2c-ls2x-v2.
+
 config I2C_MLXBF
         tristate "Mellanox BlueField I2C controller"
         depends on (MELLANOX_PLATFORM && ARM64) || COMPILE_TEST
drivers/i2c/busses/Makefile +1 -0
index 547123ab351f..3755c54b3d82 100644
@@ -80,6 +80,7 @@ obj-$(CONFIG_I2C_KEBA)		+= i2c-keba.o
 obj-$(CONFIG_I2C_KEMPLD)	+= i2c-kempld.o
 obj-$(CONFIG_I2C_LPC2K)		+= i2c-lpc2k.o
 obj-$(CONFIG_I2C_LS2X)		+= i2c-ls2x.o
+obj-$(CONFIG_I2C_LS2X_V2)	+= i2c-ls2x-v2.o
 obj-$(CONFIG_I2C_MESON)		+= i2c-meson.o
 obj-$(CONFIG_I2C_MICROCHIP_CORE)	+= i2c-microchip-corei2c.o
 obj-$(CONFIG_I2C_MPC)		+= i2c-mpc.o
drivers/i2c/busses/i2c-ls2x-v2.c new file +544 -0

544 lines not on this page · raw message

Signature · 1 line
2.52.0
#3 lore raw

Re: [PATCH v5 2/2] i2c: ls2x-v2: Add driver for Loongson-2K0300 I2C controller

Quoted 5 lines · Binbin Zhou

This I2C module is integrated into the Loongson-2K0300 SoCs.

It provides multi-master functionality and controls all I2C bus-specific timing, protocols, arbitration, and timing. It supports both standard and fast modes.

Nothing really worrying, this version only has an issue to access embedded struct device in the i2c_adapter. See below.

...

Quoted 7 lines

+/**
+ * struct loongson2_i2c_priv - private data of the controller
+ * @adapter: I2C adapter for this controller
+ * @complete: completion of I2C message
+ * @clk: hw i2c clock
+ * @regmap: regmap of the I2C device
+ * @parent_rate_MHz: I2C clock parent rate in MHz

' in MHz' now is redundant.

Quoted 2 lines

+ * @msg: I2C transfer information
+ */

...

drivers/i2c/busses/i2c-ls2x-v2.c line 211

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +3 -0
+	/*
+	 * Acknowledge failure:
+	 * In master transmitter mode a Stop must be generated by software

Missing period.

Quoted 1 line
(quoted diff) +1 -0
+	 */

...

drivers/i2c/busses/i2c-ls2x-v2.c line 287

Quoted 5 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +5 -0
+	case 3:
+		/*
+		 * In order to generate the NACK after the last received data byte, enable NACK
+		 * before reading N-2 data
+		 */

Ditto.

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +3 -0
+		regmap_update_bits(priv->regmap, LOONGSON2_I2C_CR1, LOONGSON2_I2C_CR1_ACK, 0);
+		loongson2_i2c_read_msg(priv);
+		break;

...

drivers/i2c/busses/i2c-ls2x-v2.c line 320

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +3 -0
+	event = status & possible_status;
+	if (!event) {
+		dev_dbg(dev, "spurious evt irq (status=0x%08x, ien=0x%08x)\n", status, ien);

IRQ

Quoted 2 lines
(quoted diff) +2 -0
+		return IRQ_NONE;
+	}

...

drivers/i2c/busses/i2c-ls2x-v2.c line 349

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +3 -0
+	/*
+	 * The BTF (Byte Transfer finished) event occurs when:
+	 * - in reception : a new byte is received in the shift register

Extra space before :.

Quoted 4 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +4 -0
+	 * but the previous byte has not been read yet from data register
+	 * - in transmission: a new byte should be sent but the data register
+	 * has not been written yet
+	 */

...

drivers/i2c/busses/i2c-ls2x-v2.c line 432

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +3 -0
+static int loongson2_i2c_adjust_bus_speed(struct loongson2_i2c_priv *priv)
+{
+	struct device *dev = priv->adapter.dev.parent;

Derive it from regmap (and check elsewhere) as accessing dev in the adapter may lead to issues related to the object lifetime.

Quoted 34 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +34 -0
+	struct i2c_timings i2c_t;
+	u32 val, freq_MHz, ccr;
+
+	i2c_parse_fw_timings(dev, &i2c_t, true);
+	priv->parent_rate_MHz = clk_get_rate(priv->clk);
+
+	if (i2c_t.bus_freq_hz == I2C_MAX_STANDARD_MODE_FREQ) {
+		 /* Select Standard mode */
+		ccr = 0;
+		val = DIV_ROUND_UP(priv->parent_rate_MHz, i2c_t.bus_freq_hz * 2);
+	} else if (i2c_t.bus_freq_hz == I2C_MAX_FAST_MODE_FREQ) {
+		/* Select Fast mode */
+		ccr = LOONGSON2_I2C_CCR_FS;
+		val = DIV_ROUND_UP(priv->parent_rate_MHz, i2c_t.bus_freq_hz * 3);
+	} else {
+		return dev_err_probe(dev, -EINVAL, "Unsupported speed (%uHz)\n", i2c_t.bus_freq_hz);
+	}
+
+	FIELD_MODIFY(LOONGSON2_I2C_CCR_CCR, &ccr, val);
+	regmap_write(priv->regmap, LOONGSON2_I2C_CCR, ccr);
+
+	freq_MHz = DIV_ROUND_UP(priv->parent_rate_MHz, HZ_PER_MHZ);
+	regmap_update_bits(priv->regmap, LOONGSON2_I2C_CR2, LOONGSON2_I2C_CR2_FREQ,
+			   FIELD_GET(LOONGSON2_I2C_CR2_FREQ, freq_MHz));
+
+	regmap_update_bits(priv->regmap, LOONGSON2_I2C_TRISE, LOONGSON2_I2C_TRISE_SCL,
+			   LOONGSON2_I2C_TRISE_SCL);
+
+	/* Enable I2C */
+	regmap_update_bits(priv->regmap, LOONGSON2_I2C_CR1, LOONGSON2_I2C_CR1_PE,
+			   LOONGSON2_I2C_CR1_PE);
+
+	return 0;
+}

...

Quoted 27 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +27 -0
+static int loongson2_i2c_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct loongson2_i2c_priv *priv;
+	struct i2c_adapter *adap;
+	void __iomem *base;
+	int irq, ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	priv->regmap = devm_regmap_init_mmio(dev, base, &loongson2_i2c_regmap_config);
+	if (IS_ERR(priv->regmap))
+		return dev_err_probe(dev, PTR_ERR(priv->regmap), "Failed to init regmap.\n");
+
+	priv->clk = devm_clk_get_enabled(dev, NULL);
+	if (IS_ERR(priv->clk))
+		return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to enable clock.\n");
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;

drivers/i2c/busses/i2c-ls2x-v2.c line 510

Quoted 10 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +9 -0
+
+	adap = &priv->adapter;
+	adap->retries = 5;
+	adap->nr = pdev->id;
+	adap->dev.parent = dev;
+	adap->owner = THIS_MODULE;
+	adap->algo = &loongson2_i2c_algo;
+	adap->timeout = 2 * HZ;
 
+	device_set_node(&adap->dev, dev_fwnode(dev));

Why?! i2c_adapter_set_node() is part of the i2c-next.

Quoted 15 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +15 -0
+	i2c_set_adapdata(adap, priv);
+	strscpy(adap->name, pdev->name);
+	init_completion(&priv->complete);
+	platform_set_drvdata(pdev, priv);
+
+	ret = loongson2_i2c_adjust_bus_speed(priv);
+	if (ret)
+		return ret;
+
+	ret = devm_request_irq(dev, irq, loongson2_i2c_isr_event, IRQF_SHARED, pdev->name, priv);
+	if (ret)
+		return ret;
+
+	return devm_i2c_add_adapter(dev, adap);
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v5 2/2] i2c: ls2x-v2: Add driver for Loongson-2K0300 I2C controller

Hi Andy:

Thanks for your detailed review.

Quoted 74 lines · Andy Shevchenko
Quoted 5 lines · Binbin Zhou

This I2C module is integrated into the Loongson-2K0300 SoCs.

It provides multi-master functionality and controls all I2C bus-specific timing, protocols, arbitration, and timing. It supports both standard and fast modes.

Nothing really worrying, this version only has an issue to access embedded struct device in the i2c_adapter. See below.

...

Quoted 7 lines

+/**
+ * struct loongson2_i2c_priv - private data of the controller
+ * @adapter: I2C adapter for this controller
+ * @complete: completion of I2C message
+ * @clk: hw i2c clock
+ * @regmap: regmap of the I2C device
+ * @parent_rate_MHz: I2C clock parent rate in MHz

' in MHz' now is redundant.

Quoted 2 lines

+ * @msg: I2C transfer information
+ */

...

drivers/i2c/busses/i2c-ls2x-v2.c line 211

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +3 -0
+     /*
+      * Acknowledge failure:
+      * In master transmitter mode a Stop must be generated by software

Missing period.

Quoted 1 line

+ */

...

drivers/i2c/busses/i2c-ls2x-v2.c line 287

Quoted 5 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +5 -0
+     case 3:
+             /*
+              * In order to generate the NACK after the last received data byte, enable NACK
+              * before reading N-2 data
+              */

Ditto.

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +3 -0
+             regmap_update_bits(priv->regmap, LOONGSON2_I2C_CR1, LOONGSON2_I2C_CR1_ACK, 0);
+             loongson2_i2c_read_msg(priv);
+             break;

...

drivers/i2c/busses/i2c-ls2x-v2.c line 320

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +3 -0
+     event = status & possible_status;
+     if (!event) {
+             dev_dbg(dev, "spurious evt irq (status=0x%08x, ien=0x%08x)\n", status, ien);

IRQ

Quoted 2 lines
(quoted diff) +2 -0
+             return IRQ_NONE;
+     }

...

drivers/i2c/busses/i2c-ls2x-v2.c line 349

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +3 -0
+     /*
+      * The BTF (Byte Transfer finished) event occurs when:
+      * - in reception : a new byte is received in the shift register

Extra space before :.

drivers/i2c/busses/i2c-ls2x-v2.c line 353

Quoted 4 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +4 -0
+      * but the previous byte has not been read yet from data register
+      * - in transmission: a new byte should be sent but the data register
+      * has not been written yet
+      */
Quoted 8 lines

...

drivers/i2c/busses/i2c-ls2x-v2.c line 432

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +3 -0
+static int loongson2_i2c_adjust_bus_speed(struct loongson2_i2c_priv *priv)
+{
+     struct device *dev = priv->adapter.dev.parent;

Derive it from regmap (and check elsewhere) as accessing dev in the adapter may lead to issues related to the object lifetime.

Do you mean regmap_get_device() API?

Also, similar references exist in loongson2_i2c_xfer() and loongson2_i2c_isr_event(), requiring synchronized updates.

Quoted 74 lines
Quoted 35 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +34 -0
+     struct i2c_timings i2c_t;
+     u32 val, freq_MHz, ccr;
+
+     i2c_parse_fw_timings(dev, &i2c_t, true);
+     priv->parent_rate_MHz = clk_get_rate(priv->clk);
+
+     if (i2c_t.bus_freq_hz == I2C_MAX_STANDARD_MODE_FREQ) {
+              /* Select Standard mode */
+             ccr = 0;
+             val = DIV_ROUND_UP(priv->parent_rate_MHz, i2c_t.bus_freq_hz * 2);
+     } else if (i2c_t.bus_freq_hz == I2C_MAX_FAST_MODE_FREQ) {
+             /* Select Fast mode */
+             ccr = LOONGSON2_I2C_CCR_FS;
+             val = DIV_ROUND_UP(priv->parent_rate_MHz, i2c_t.bus_freq_hz * 3);
+     } else {
+             return dev_err_probe(dev, -EINVAL, "Unsupported speed (%uHz)\n", i2c_t.bus_freq_hz);
+     }
+
+     FIELD_MODIFY(LOONGSON2_I2C_CCR_CCR, &ccr, val);
+     regmap_write(priv->regmap, LOONGSON2_I2C_CCR, ccr);
+
+     freq_MHz = DIV_ROUND_UP(priv->parent_rate_MHz, HZ_PER_MHZ);
+     regmap_update_bits(priv->regmap, LOONGSON2_I2C_CR2, LOONGSON2_I2C_CR2_FREQ,
+                        FIELD_GET(LOONGSON2_I2C_CR2_FREQ, freq_MHz));
+
+     regmap_update_bits(priv->regmap, LOONGSON2_I2C_TRISE, LOONGSON2_I2C_TRISE_SCL,
+                        LOONGSON2_I2C_TRISE_SCL);
+
+     /* Enable I2C */
+     regmap_update_bits(priv->regmap, LOONGSON2_I2C_CR1, LOONGSON2_I2C_CR1_PE,
+                        LOONGSON2_I2C_CR1_PE);
+
+     return 0;
+}

...

Quoted 35 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +35 -0
+static int loongson2_i2c_probe(struct platform_device *pdev)
+{
+     struct device *dev = &pdev->dev;
+     struct loongson2_i2c_priv *priv;
+     struct i2c_adapter *adap;
+     void __iomem *base;
+     int irq, ret;
+
+     priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+     if (!priv)
+             return -ENOMEM;
+
+     base = devm_platform_ioremap_resource(pdev, 0);
+     if (IS_ERR(base))
+             return PTR_ERR(base);
+
+     priv->regmap = devm_regmap_init_mmio(dev, base, &loongson2_i2c_regmap_config);
+     if (IS_ERR(priv->regmap))
+             return dev_err_probe(dev, PTR_ERR(priv->regmap), "Failed to init regmap.\n");
+
+     priv->clk = devm_clk_get_enabled(dev, NULL);
+     if (IS_ERR(priv->clk))
+             return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to enable clock.\n");
+
+     irq = platform_get_irq(pdev, 0);
+     if (irq < 0)
+             return irq;
+
+     adap = &priv->adapter;
+     adap->retries = 5;
+     adap->nr = pdev->id;
+     adap->dev.parent = dev;
+     adap->owner = THIS_MODULE;
+     adap->algo = &loongson2_i2c_algo;
+     adap->timeout = 2 * HZ;
Quoted 3 lines
Quoted 1 line

+ device_set_node(&adap->dev, dev_fwnode(dev));

Why?! i2c_adapter_set_node() is part of the i2c-next.

Indeed, when I rebased the v4 patchset, i2c_adapter_set_node() existed in the i2c-next[1]. However, when I prepared the v5 patchset, it was removed[2].

[1]: base commit: 6117e1ba1db78a52a4161208ea403d3769ad73c6 [2]: base commit: b82316862bea929265725c077dffcec42e3dc20b

Quoted 12 lines
Quoted 12 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +11 -0
+     i2c_set_adapdata(adap, priv);
+     strscpy(adap->name, pdev->name);
+     init_completion(&priv->complete);
+     platform_set_drvdata(pdev, priv);
+
+     ret = loongson2_i2c_adjust_bus_speed(priv);
+     if (ret)
+             return ret;
+
+     ret = devm_request_irq(dev, irq, loongson2_i2c_isr_event, IRQF_SHARED, pdev->name, priv);
+     if (ret)
Quoted 10 lines

drivers/i2c/busses/i2c-ls2x-v2.c line 525

Quoted 4 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +4 -0
+             return ret;
+
+     return devm_i2c_add_adapter(dev, adap);
+}

--
With Best Regards,
Andy Shevchenko

--
Thanks.
Binbin

#5 lore raw

Re: [PATCH v5 2/2] i2c: ls2x-v2: Add driver for Loongson-2K0300 I2C controller

+Cc: Bart (what's going on with i2c_adapter_set_node()?)

Quoted 3 lines · Binbin Zhou
Quoted 1 line · Andy Shevchenko

On Tue, Mar 10, 2026 at 07:48:53PM +0800, Binbin Zhou wrote:

...

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+ struct device *dev = priv->adapter.dev.parent;

Derive it from regmap (and check elsewhere) as accessing dev in the adapter may lead to issues related to the object lifetime.

Do you mean regmap_get_device() API?

Yes.

Quoted 2 lines

Also, similar references exist in loongson2_i2c_xfer() and loongson2_i2c_isr_event(), requiring synchronized updates.

Correct.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +14 -0
+             return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to enable clock.\n");
+
+     irq = platform_get_irq(pdev, 0);
+     if (irq < 0)
+             return irq;
+
+     adap = &priv->adapter;
+     adap->retries = 5;
+     adap->nr = pdev->id;
+     adap->dev.parent = dev;
+     adap->owner = THIS_MODULE;
+     adap->algo = &loongson2_i2c_algo;
+     adap->timeout = 2 * HZ;
 
+     device_set_node(&adap->dev, dev_fwnode(dev));
Quoted 8 lines
Quoted 1 line

Why?! i2c_adapter_set_node() is part of the i2c-next.

Indeed, when I rebased the v4 patchset, i2c_adapter_set_node() existed in the i2c-next[1]. However, when I prepared the v5 patchset, it was removed[2].

[1]: base commit: 6117e1ba1db78a52a4161208ea403d3769ad73c6 [2]: base commit: b82316862bea929265725c077dffcec42e3dc20b

Bart?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH v5 2/2] i2c: ls2x-v2: Add driver for Loongson-2K0300 I2C controller

Hi all:

Quoted 15 lines · Andy Shevchenko

+Cc: Bart (what's going on with i2c_adapter_set_node()?)

Quoted 3 lines · Binbin Zhou
Quoted 1 line · Andy Shevchenko

On Tue, Mar 10, 2026 at 07:48:53PM +0800, Binbin Zhou wrote:

...

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

+ struct device *dev = priv->adapter.dev.parent;

Derive it from regmap (and check elsewhere) as accessing dev in the adapter may lead to issues related to the object lifetime.

Quoted 33 lines
Quoted 1 line

Do you mean regmap_get_device() API?

Yes.

Quoted 2 lines

Also, similar references exist in loongson2_i2c_xfer() and loongson2_i2c_isr_event(), requiring synchronized updates.

Correct.

Quoted 24 lines
Quoted 14 lines
Quoted 13 lines
drivers/i2c/busses/i2c-ls2x-v2.c new file +13 -0
+             return dev_err_probe(dev, PTR_ERR(priv->clk), "Failed to enable clock.\n");
+
+     irq = platform_get_irq(pdev, 0);
+     if (irq < 0)
+             return irq;
+
+     adap = &priv->adapter;
+     adap->retries = 5;
+     adap->nr = pdev->id;
+     adap->dev.parent = dev;
+     adap->owner = THIS_MODULE;
+     adap->algo = &loongson2_i2c_algo;
+     adap->timeout = 2 * HZ;
Quoted 3 lines
Quoted 1 line

+ device_set_node(&adap->dev, dev_fwnode(dev));

Why?! i2c_adapter_set_node() is part of the i2c-next.

Indeed, when I rebased the v4 patchset, i2c_adapter_set_node() existed in the i2c-next[1]. However, when I prepared the v5 patchset, it was removed[2].

[1]: base commit: 6117e1ba1db78a52a4161208ea403d3769ad73c6 [2]: base commit: b82316862bea929265725c077dffcec42e3dc20b

Excuse me, I’d like to inquire about the current status of merging the i2c_adapter_set_node() API.
If there hasn’t been any concrete progress yet, I’ll try to keep things as they are and prepare the V6 patchset.

Quoted 8 lines

Bart?

--
With Best Regards,
Andy Shevchenko

Signature · 2 lines
Thanks.
Binbin