Skip to contentSkip to conversation

Add support for MA35D1 I2C controller

PATCH Superseded Zi-Yu Chen 2 participants 10 messages Mar 2 – Mar 3

Subsystems (4)

v1 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Zi-Yu Chen

author
#0 lore raw

cover Add support for MA35D1 I2C controller

This series adds support for the I2C controller found in the Nuvoton MA35D1 SoC. The driver supports master/slave modes, bus recovery, and runtime power management.

The implementation has been tested on the Nuvoton MA35D1 SOM board.

Zi-Yu Chen (3):
dt-bindings: i2c: nuvoton,ma35d1-i2c: Add MA35D1 I2C controller
i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support
arm64: dts: nuvoton: Add I2C nodes for MA35D1 SoC

 .../bindings/i2c/nuvoton,ma35d1-i2c.yaml      |  65 ++
 .../boot/dts/nuvoton/ma35d1-som-256m.dts      |  14 +
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       |  65 ++
 drivers/i2c/busses/Kconfig                    |  13 +
 drivers/i2c/busses/Makefile                   |   1 +
 drivers/i2c/busses/i2c-ma35d1.c               | 819 ++++++++++++++++++
 6 files changed, 977 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml
 create mode 100644 drivers/i2c/busses/i2c-ma35d1.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/3 dt-bindings: i2c: nuvoton,ma35d1-i2c: Add MA35D1 I2C controller

Add device tree binding documentation for the I2C controller found in the Nuvoton MA35D1 SoC.

---
 .../bindings/i2c/nuvoton,ma35d1-i2c.yaml      | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml
Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml new file +65 -0
new file mode 100644
index 000000000000..fa8b01e2c5b1
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/nuvoton,ma35d1-i2c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 I2C Controller
+
+maintainers:
+  - Zi-Yu Chen <[email protected]>
+
+description: |
+  The Nuvoton MA35D1 I2C controller supports master mode and optional
+  slave mode operation. The controller is configured via Device Tree
+  and supports interrupt-driven I2C transfers.
+
+allOf:
+  - $ref: /schemas/i2c/i2c-controller.yaml#
+
+properties:
+  compatible:
+    const: nuvoton,ma35d1-i2c
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-frequency:
+    description:
+      Desired I2C bus clock frequency in Hz. The absence of this property
+      indicates the default frequency 100 kHz.
+
+  resets:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
+    #include <dt-bindings/reset/nuvoton,ma35d1-reset.h>
+
+    i2c0: i2c@40800000 {
+      compatible = "nuvoton,ma35d1-i2c";
+      reg = <0x40800000 0x10000>;
+      interrupts = <GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH>;
+      clocks = <&clk I2C0_GATE>;
+      clock-frequency = <100000>;
+      resets = <&sys MA35D1_RESET_I2C0>;
+      #address-cells = <1>;
+      #size-cells = <0>;
+    };
Signature · 1 line
2.34.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] dt-bindings: i2c: nuvoton,ma35d1-i2c: Add MA35D1 I2C controller

Quoted 17 lines · Zi-Yu Chen

Add device tree binding documentation for the I2C controller found in the Nuvoton MA35D1 SoC.

---
 .../bindings/i2c/nuvoton,ma35d1-i2c.yaml      | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml
Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml new file +2 -0
new file mode 100644
index 000000000000..fa8b01e2c5b1
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2

Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml line 12

Quoted 10 lines
Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml new file +10 -0
+---
+$id: http://devicetree.org/schemas/i2c/nuvoton,ma35d1-i2c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 I2C Controller
+
+maintainers:
+  - Zi-Yu Chen <[email protected]>
+
+description: |

Do not need '|' unless you need to preserve formatting.

Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml line 14

Quoted 2 lines
Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml new file +2 -0
+  The Nuvoton MA35D1 I2C controller supports master mode and optional
+  slave mode operation. The controller is configured via Device Tree

Use modern naming, not master/slave.

Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml line 15

Quoted 1 line
Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml new file +1 -0
+  and supports interrupt-driven I2C transfers.

Drop "The controller is configured via Device Tree", because it is completely irrelevant. Why telling in DT binding that you use DT? Can you use ACPI here?

And with dropping this it could be one simple sentence.

With these changes:

Best regards,
Krzysztof

author
#3 lore raw

Re: [PATCH 1/3] dt-bindings: i2c: nuvoton,ma35d1-i2c: Add MA35D1 I2C controller

Krzysztof Kozlowski 於 2026/3/2 下午 03:20 寫道:

Quoted 22 lines · Zi-Yu Chen
Quoted 21 lines

Add device tree binding documentation for the I2C controller found in the Nuvoton MA35D1 SoC.

---
 .../bindings/i2c/nuvoton,ma35d1-i2c.yaml      | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml
Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml new file +6 -0
new file mode 100644
index 000000000000..fa8b01e2c5b1
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/nuvoton,ma35d1-i2c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
Quoted 8 lines

Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml line 12

Quoted 6 lines
Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml new file +6 -0
+title: Nuvoton MA35D1 I2C Controller
+
+maintainers:
+  - Zi-Yu Chen <[email protected]>
+
+description: |

Do not need '|' unless you need to preserve formatting.

will fix in v2.

Quoted 6 lines

Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml line 14

Quoted 3 lines
Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml new file +2 -0
+  The Nuvoton MA35D1 I2C controller supports master mode and optional
+  slave mode operation. The controller is configured via Device Tree

Use modern naming, not master/slave.

Quoted 8 lines

Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml line 15

Quoted 1 line
Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml new file +1 -0
+  and supports interrupt-driven I2C transfers.

Drop "The controller is configured via Device Tree", because it is completely irrelevant. Why telling in DT binding that you use DT? Can you use ACPI here?

And with dropping this it could be one simple sentence.

Acknowledged. I plan to simplify the description in v2 as follows:

'The Nuvoton MA35D1 I2C controller supports controller and optional target mode.'

Quoted 7 lines

With these changes:

Best regards,
Krzysztof

Thanks!

author
#4 lore raw

PATCH 2/3 i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support

In reply to Zi-Yu Chen

Add I2C support for Nuvoton MA35D1 SoC.
The controller supports standard, fast and fast-plus modes, and provides master/slave functionality.

---
 drivers/i2c/busses/Kconfig      |  13 +
 drivers/i2c/busses/Makefile     |   1 +
 drivers/i2c/busses/i2c-ma35d1.c | 819 ++++++++++++++++++++++++++++++++
 3 files changed, 833 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ma35d1.c
drivers/i2c/busses/Kconfig +13 -0
index e11d50750e63..6bf8be1d2575 100644
@@ -1589,4 +1589,17 @@ config I2C_VIRTIO
           This driver can also be built as a module. If so, the module
           will be called i2c-virtio.
 
+config I2C_MA35D1
+	tristate "Nuvoton MA35D1 I2C driver"
+	depends on ARCH_MA35
+	select I2C_SLAVE
+	help
+	  If you say yes to this option, support will be included for the
+	  I2C controller in the Nuvoton MA35D1 SoC. This driver
+	  supports the standard I2C bus protocols, including master and
+	  slave modes.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called i2c-ma35d1.
+
 endmenu
drivers/i2c/busses/Makefile +1 -0
index 547123ab351f..264f6f3f608d 100644
@@ -130,6 +130,7 @@ obj-$(CONFIG_I2C_XILINX)	+= i2c-xiic.o
 obj-$(CONFIG_I2C_XLP9XX)	+= i2c-xlp9xx.o
 obj-$(CONFIG_I2C_RCAR)		+= i2c-rcar.o
 obj-$(CONFIG_I2C_GXP)		+= i2c-gxp.o
+obj-$(CONFIG_I2C_MA35D1)	+= i2c-ma35d1.o
 
 # External I2C/SMBus adapter drivers
 obj-$(CONFIG_I2C_DIOLAN_U2C)	+= i2c-diolan-u2c.o
drivers/i2c/busses/i2c-ma35d1.c new file +819 -0

819 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 2/3] i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support

Quoted 17 lines · Zi-Yu Chen

Add I2C support for Nuvoton MA35D1 SoC.
The controller supports standard, fast and fast-plus modes, and provides master/slave functionality.

---
 drivers/i2c/busses/Kconfig      |  13 +
 drivers/i2c/busses/Makefile     |   1 +
 drivers/i2c/busses/i2c-ma35d1.c | 819 ++++++++++++++++++++++++++++++++
 3 files changed, 833 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ma35d1.c
drivers/i2c/busses/Kconfig +0 -0
index e11d50750e63..6bf8be1d2575 100644

drivers/i2c/busses/Kconfig config I2C_VIRTIO · line 1594

Quoted 6 lines
drivers/i2c/busses/Kconfig +3 -0
@@ -1589,4 +1589,17 @@ config I2C_VIRTIO
           This driver can also be built as a module. If so, the module
           will be called i2c-virtio.
 
+config I2C_MA35D1
+	tristate "Nuvoton MA35D1 I2C driver"
+	depends on ARCH_MA35

Missing COMPILE_TEST

...

Quoted 34 lines
drivers/i2c/busses/Kconfig +34 -0
+	/* Setup info block for the I2C core */
+	strscpy(i2c->adap.name, "ma35d1-i2c", sizeof(i2c->adap.name));
+	i2c->adap.owner = THIS_MODULE;
+	i2c->adap.algo = &ma35d1_i2c_algorithm;
+	i2c->adap.retries = 2;
+	i2c->adap.algo_data = i2c;
+	i2c->adap.dev.parent = &pdev->dev;
+	i2c->adap.dev.of_node = pdev->dev.of_node;
+	i2c_set_adapdata(&i2c->adap, i2c);
+
+	ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
+				   &busfreq);
+	if (ret) {
+		dev_err(i2c->dev, "clock-frequency not specified in DT\n");
+		return ret;
+	}
+
+	/* Calculate divider based on the current peripheral clock rate */
+	clkdiv = DIV_ROUND_CLOSEST(clk_get_rate(i2c->clk), busfreq * 4) - 1;
+	if (clkdiv < 0 || clkdiv > 0xffff) {
+		dev_err(dev, "invalid clkdiv value: %d\n", clkdiv);
+		return -EINVAL;
+	}
+
+	i2c->irq = platform_get_irq(pdev, 0);
+	if (i2c->irq < 0)
+		return i2c->irq;
+
+	platform_set_drvdata(pdev, i2c);
+
+	pm_runtime_set_autosuspend_delay(dev, I2C_PM_TIMEOUT);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);

drivers/i2c/busses/Kconfig config I2C_VIRTIO

Quoted 10 lines
drivers/i2c/busses/Kconfig +10 -0
+
+	ret = pm_runtime_get_sync(dev);
+	if (ret < 0)
+		goto rpm_disable;
+
+	writel(clkdiv & 0xffff, i2c->regs + MA35_CLKDIV);
+
+	ret = devm_request_irq(dev, i2c->irq, ma35d1_i2c_irq, IRQF_SHARED,
+			       dev_name(dev), i2c);
+

No blank line ever between call and if()

drivers/i2c/busses/Kconfig

Quoted 1 line
drivers/i2c/busses/Kconfig +1 -0
+	if (ret != 0) {

Write simple and obvious code.

if (ret)

drivers/i2c/busses/Kconfig

Quoted 6 lines
drivers/i2c/busses/Kconfig +6 -0
+		dev_err(dev, "cannot claim IRQ %d\n", i2c->irq);
+		goto rpm_disable;
+	}
+
+	/* Give it another chance if pinctrl used is not ready yet */
+	if (ret == -EPROBE_DEFER)

Pointless and dead code.

Quoted 116 lines
drivers/i2c/busses/Kconfig +116 -0
+		goto rpm_disable;
+
+	ret = i2c_add_adapter(&i2c->adap);
+	if (ret) {
+		dev_err(dev, "failed to add bus to i2c core: %d\n", ret);
+		goto rpm_disable;
+	}
+
+	pm_runtime_put_autosuspend(dev);
+
+	return 0;
+
+rpm_disable:
+	pm_runtime_put_noidle(dev);
+	pm_runtime_disable(dev);
+	pm_runtime_set_suspended(dev);
+	pm_runtime_dont_use_autosuspend(dev);
+	return ret;
+}
+
+static void ma35d1_i2c_remove(struct platform_device *pdev)
+{
+	struct ma35d1_i2c *i2c = platform_get_drvdata(pdev);
+
+	i2c_del_adapter(&i2c->adap);
+	pm_runtime_disable(&pdev->dev);
+}
+
+static int ma35d1_i2c_suspend(struct device *dev)
+{
+	struct ma35d1_i2c *i2c = dev_get_drvdata(dev);
+	unsigned int val;
+
+	spin_lock_irq(&i2c->lock);
+
+	/* Prepare for wake-up from I2C events if slave mode is active */
+	if (i2c->slave) {
+		val = readl(i2c->regs + MA35_CTL0);
+		val |= (MA35_CTL_SI | MA35_CTL_AA);
+		writel(val, i2c->regs + MA35_CTL0);
+		ma35d1_i2c_enable_irq(i2c);
+	}
+
+	spin_unlock_irq(&i2c->lock);
+
+	/* Setup wake-up control */
+	writel(0x1, i2c->regs + MA35_WKCTL);
+
+	/* Clear pending wake-up flags */
+	val = readl(i2c->regs + MA35_WKSTS);
+	writel(val, i2c->regs + MA35_WKSTS);
+
+	enable_irq_wake(i2c->irq);
+
+	return 0;
+}
+
+static int ma35d1_i2c_resume(struct device *dev)
+{
+	struct ma35d1_i2c *i2c = dev_get_drvdata(dev);
+	unsigned int val;
+
+	/* Disable wake-up */
+	writel(0x0, i2c->regs + MA35_WKCTL);
+
+	/* Clear pending wake-up flags */
+	val = readl(i2c->regs + MA35_WKSTS);
+	writel(val, i2c->regs + MA35_WKSTS);
+
+	disable_irq_wake(i2c->irq);
+	return 0;
+}
+
+static int ma35d1_i2c_runtime_suspend(struct device *dev)
+{
+	struct ma35d1_i2c *i2c = dev_get_drvdata(dev);
+	unsigned int val;
+
+	/* Disable I2C controller */
+	val = readl(i2c->regs + MA35_CTL0);
+	val &= ~MA35_CTL_I2CEN;
+	writel(val, i2c->regs + MA35_CTL0);
+
+	clk_disable_unprepare(i2c->clk);
+
+	return 0;
+}
+
+static int ma35d1_i2c_runtime_resume(struct device *dev)
+{
+	struct ma35d1_i2c *i2c = dev_get_drvdata(dev);
+	unsigned int val;
+	int ret;
+
+	ret = clk_prepare_enable(i2c->clk);
+	if (ret) {
+		dev_err(dev, "failed to enable clock in resume\n");
+		return ret;
+	}
+
+	/* Enable I2C controller */
+	val = readl(i2c->regs + MA35_CTL0);
+	val |= MA35_CTL_I2CEN;
+	writel(val, i2c->regs + MA35_CTL0);
+
+	return 0;
+}
+
+static const struct dev_pm_ops ma35d1_i2c_pmops = {
+	SYSTEM_SLEEP_PM_OPS(ma35d1_i2c_suspend, ma35d1_i2c_resume)
+		RUNTIME_PM_OPS(ma35d1_i2c_runtime_suspend,
+			       ma35d1_i2c_runtime_resume, NULL)
+};
+
+static const struct of_device_id ma35d1_i2c_of_match[] = {
+	{ .compatible = "nuvoton,ma35d1-i2c" },

drivers/i2c/busses/Kconfig

Quoted 10 lines
drivers/i2c/busses/Kconfig +10 -0
+	{},
+};
+MODULE_DEVICE_TABLE(of, ma35d1_i2c_of_match);
+
+static struct platform_driver ma35d1_i2c_driver = {
+	.probe      = ma35d1_i2c_probe,
+	.remove     = ma35d1_i2c_remove,
+	.driver     = {
+		.name   = "ma35d1-i2c",
+		.owner  = THIS_MODULE,

Do not upstream 12-year-old code. We fixed all these issues long time. Please write your driver from scratch, so you will not repeat/reintroduce all the issues which we already fixed.

drivers/i2c/busses/Kconfig

Quoted 3 lines
drivers/i2c/busses/Kconfig +3 -0
+		.of_match_table = ma35d1_i2c_of_match,
+		.pm = pm_ptr(&ma35d1_i2c_pmops),
+	},

Best regards,
Krzysztof

author
#6 lore raw

Re: [PATCH 2/3] i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support

Hi Krzysztof,
Thank you for the review.

Krzysztof Kozlowski 於 2026/3/2 下午 03:24 寫道:

Quoted 21 lines · Zi-Yu Chen
Quoted 20 lines

Add I2C support for Nuvoton MA35D1 SoC.
The controller supports standard, fast and fast-plus modes, and provides master/slave functionality.

---
 drivers/i2c/busses/Kconfig      |  13 +
 drivers/i2c/busses/Makefile     |   1 +
 drivers/i2c/busses/i2c-ma35d1.c | 819 ++++++++++++++++++++++++++++++++
 3 files changed, 833 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ma35d1.c
drivers/i2c/busses/Kconfig +0 -0
index e11d50750e63..6bf8be1d2575 100644
@@ -1589,4 +1589,17 @@ config I2C_VIRTIO
           This driver can also be built as a module. If so, the module
           will be called i2c-virtio.
 
Quoted 6 lines

drivers/i2c/busses/Kconfig config I2C_VIRTIO · line 1594

Quoted 3 lines
drivers/i2c/busses/Kconfig +3 -0
+config I2C_MA35D1
+	tristate "Nuvoton MA35D1 I2C driver"
+	depends on ARCH_MA35

Missing COMPILE_TEST

Will add || COMPILE_TEST to the dependency in v2.

Quoted 41 lines

...

Quoted 38 lines
drivers/i2c/busses/Kconfig +38 -0
+	/* Setup info block for the I2C core */
+	strscpy(i2c->adap.name, "ma35d1-i2c", sizeof(i2c->adap.name));
+	i2c->adap.owner = THIS_MODULE;
+	i2c->adap.algo = &ma35d1_i2c_algorithm;
+	i2c->adap.retries = 2;
+	i2c->adap.algo_data = i2c;
+	i2c->adap.dev.parent = &pdev->dev;
+	i2c->adap.dev.of_node = pdev->dev.of_node;
+	i2c_set_adapdata(&i2c->adap, i2c);
+
+	ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
+				   &busfreq);
+	if (ret) {
+		dev_err(i2c->dev, "clock-frequency not specified in DT\n");
+		return ret;
+	}
+
+	/* Calculate divider based on the current peripheral clock rate */
+	clkdiv = DIV_ROUND_CLOSEST(clk_get_rate(i2c->clk), busfreq * 4) - 1;
+	if (clkdiv < 0 || clkdiv > 0xffff) {
+		dev_err(dev, "invalid clkdiv value: %d\n", clkdiv);
+		return -EINVAL;
+	}
+
+	i2c->irq = platform_get_irq(pdev, 0);
+	if (i2c->irq < 0)
+		return i2c->irq;
+
+	platform_set_drvdata(pdev, i2c);
+
+	pm_runtime_set_autosuspend_delay(dev, I2C_PM_TIMEOUT);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+
+	ret = pm_runtime_get_sync(dev);
+	if (ret < 0)
+		goto rpm_disable;
Quoted 8 lines

drivers/i2c/busses/Kconfig

Quoted 6 lines
drivers/i2c/busses/Kconfig +6 -0
+
+	writel(clkdiv & 0xffff, i2c->regs + MA35_CLKDIV);
+
+	ret = devm_request_irq(dev, i2c->irq, ma35d1_i2c_irq, IRQF_SHARED,
+			       dev_name(dev), i2c);
+

No blank line ever between call and if()

Acknowledged. Will fix in v2.

Quoted 7 lines

drivers/i2c/busses/Kconfig

Quoted 2 lines
drivers/i2c/busses/Kconfig +1 -0
+	if (ret != 0) {

Write simple and obvious code.

if (ret)

Acknowledged. I will simplify the error check to if (ret) in v2.

Quoted 8 lines

drivers/i2c/busses/Kconfig

Quoted 6 lines
drivers/i2c/busses/Kconfig +6 -0
+		dev_err(dev, "cannot claim IRQ %d\n", i2c->irq);
+		goto rpm_disable;
+	}
+
+	/* Give it another chance if pinctrl used is not ready yet */
+	if (ret == -EPROBE_DEFER)

Pointless and dead code.

Acknowledged. I will remove the redundant -EPROBE_DEFER check and its associated comment in v2

Quoted 123 lines
Quoted 123 lines
drivers/i2c/busses/Kconfig +122 -0
+		goto rpm_disable;
+
+	ret = i2c_add_adapter(&i2c->adap);
+	if (ret) {
+		dev_err(dev, "failed to add bus to i2c core: %d\n", ret);
+		goto rpm_disable;
+	}
+
+	pm_runtime_put_autosuspend(dev);
+
+	return 0;
+
+rpm_disable:
+	pm_runtime_put_noidle(dev);
+	pm_runtime_disable(dev);
+	pm_runtime_set_suspended(dev);
+	pm_runtime_dont_use_autosuspend(dev);
+	return ret;
+}
+
+static void ma35d1_i2c_remove(struct platform_device *pdev)
+{
+	struct ma35d1_i2c *i2c = platform_get_drvdata(pdev);
+
+	i2c_del_adapter(&i2c->adap);
+	pm_runtime_disable(&pdev->dev);
+}
+
+static int ma35d1_i2c_suspend(struct device *dev)
+{
+	struct ma35d1_i2c *i2c = dev_get_drvdata(dev);
+	unsigned int val;
+
+	spin_lock_irq(&i2c->lock);
+
+	/* Prepare for wake-up from I2C events if slave mode is active */
+	if (i2c->slave) {
+		val = readl(i2c->regs + MA35_CTL0);
+		val |= (MA35_CTL_SI | MA35_CTL_AA);
+		writel(val, i2c->regs + MA35_CTL0);
+		ma35d1_i2c_enable_irq(i2c);
+	}
+
+	spin_unlock_irq(&i2c->lock);
+
+	/* Setup wake-up control */
+	writel(0x1, i2c->regs + MA35_WKCTL);
+
+	/* Clear pending wake-up flags */
+	val = readl(i2c->regs + MA35_WKSTS);
+	writel(val, i2c->regs + MA35_WKSTS);
+
+	enable_irq_wake(i2c->irq);
+
+	return 0;
+}
+
+static int ma35d1_i2c_resume(struct device *dev)
+{
+	struct ma35d1_i2c *i2c = dev_get_drvdata(dev);
+	unsigned int val;
+
+	/* Disable wake-up */
+	writel(0x0, i2c->regs + MA35_WKCTL);
+
+	/* Clear pending wake-up flags */
+	val = readl(i2c->regs + MA35_WKSTS);
+	writel(val, i2c->regs + MA35_WKSTS);
+
+	disable_irq_wake(i2c->irq);
+	return 0;
+}
+
+static int ma35d1_i2c_runtime_suspend(struct device *dev)
+{
+	struct ma35d1_i2c *i2c = dev_get_drvdata(dev);
+	unsigned int val;
+
+	/* Disable I2C controller */
+	val = readl(i2c->regs + MA35_CTL0);
+	val &= ~MA35_CTL_I2CEN;
+	writel(val, i2c->regs + MA35_CTL0);
+
+	clk_disable_unprepare(i2c->clk);
+
+	return 0;
+}
+
+static int ma35d1_i2c_runtime_resume(struct device *dev)
+{
+	struct ma35d1_i2c *i2c = dev_get_drvdata(dev);
+	unsigned int val;
+	int ret;
+
+	ret = clk_prepare_enable(i2c->clk);
+	if (ret) {
+		dev_err(dev, "failed to enable clock in resume\n");
+		return ret;
+	}
+
+	/* Enable I2C controller */
+	val = readl(i2c->regs + MA35_CTL0);
+	val |= MA35_CTL_I2CEN;
+	writel(val, i2c->regs + MA35_CTL0);
+
+	return 0;
+}
+
+static const struct dev_pm_ops ma35d1_i2c_pmops = {
+	SYSTEM_SLEEP_PM_OPS(ma35d1_i2c_suspend, ma35d1_i2c_resume)
+		RUNTIME_PM_OPS(ma35d1_i2c_runtime_suspend,
+			       ma35d1_i2c_runtime_resume, NULL)
+};
+
+static const struct of_device_id ma35d1_i2c_of_match[] = {
+	{ .compatible = "nuvoton,ma35d1-i2c" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, ma35d1_i2c_of_match);
+
+static struct platform_driver ma35d1_i2c_driver = {
+	.probe      = ma35d1_i2c_probe,
Quoted 9 lines

drivers/i2c/busses/Kconfig

Quoted 4 lines
drivers/i2c/busses/Kconfig +4 -0
+	.remove     = ma35d1_i2c_remove,
+	.driver     = {
+		.name   = "ma35d1-i2c",
+		.owner  = THIS_MODULE,

Do not upstream 12-year-old code. We fixed all these issues long time. Please write your driver from scratch, so you will not repeat/reintroduce all the issues which we already fixed.

I will address these issues in V2 by:

Removing the redundant .owner = THIS_MODULE.

Reviewing the entire driver to ensure all APIs and patterns align with current upstream standards.

I am performing a "from-scratch" review to eliminate legacy patterns.

Quoted 7 lines

drivers/i2c/busses/Kconfig

Quoted 3 lines
drivers/i2c/busses/Kconfig +3 -0
+		.of_match_table = ma35d1_i2c_of_match,
+		.pm = pm_ptr(&ma35d1_i2c_pmops),
+	},

Best regards,
Krzysztof

author
#7 lore raw

PATCH 3/3 arm64: dts: nuvoton: Add I2C nodes for MA35D1 SoC

In reply to Zi-Yu Chen

Add I2C controller nodes to the MA35D1 SoC dtsi. Also enable the I2C interfaces on the MA35D1 SOM board to allow communication with onboard peripherals.

---
 .../boot/dts/nuvoton/ma35d1-som-256m.dts      | 14 ++++
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       | 65 +++++++++++++++++++
 2 files changed, 79 insertions(+)
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +14 -0
index f6f20a17e501..2a8f0fd90ded 100644
@@ -98,6 +98,14 @@ pinctrl_uart16: uart16-pins {
 			power-source = <1>;
 		};
 	};
+	i2c-grp {
+		pinctrl_i2c1: i2c1-pins {
+			nuvoton,pins = <1 10 12>,
+				       <1 11 12>;
+			bias-disable;
+		};
+
+	};
 };
 
 &uart0 {
@@ -129,3 +137,9 @@ &uart16 {
 	pinctrl-0 = <&pinctrl_uart16>;
 	status = "okay";
 };
+
+&i2c1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c1>;
+	status = "okay";
+};
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +65 -0

82 lines not on this page · raw message

Signature · 1 line
2.34.1
#8 lore raw

Re: [PATCH 3/3] arm64: dts: nuvoton: Add I2C nodes for MA35D1 SoC

Quoted 15 lines · Zi-Yu Chen

Add I2C controller nodes to the MA35D1 SoC dtsi. Also enable the I2C interfaces on the MA35D1 SOM board to allow communication with onboard peripherals.

---
 .../boot/dts/nuvoton/ma35d1-som-256m.dts      | 14 ++++
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       | 65 +++++++++++++++++++
 2 files changed, 79 insertions(+)
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +0 -0
index f6f20a17e501..2a8f0fd90ded 100644

arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts pinctrl_uart16: uart16-pins { · line 100

Quoted 3 lines
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +0 -0
@@ -98,6 +98,14 @@ pinctrl_uart16: uart16-pins {
 			power-source = <1>;
 		};
 	};

Missing blank line

Quoted 12 lines
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +8 -0
+	i2c-grp {
+		pinctrl_i2c1: i2c1-pins {
+			nuvoton,pins = <1 10 12>,
+				       <1 11 12>;
+			bias-disable;
+		};
+
+	};
 };
 
 &uart0 {

arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts &uart16 { · line 141

Quoted 5 lines
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +2 -0
@@ -129,3 +137,9 @@ &uart16 {
 	pinctrl-0 = <&pinctrl_uart16>;
 	status = "okay";
 };
+
+&i2c1 {

Why 'i' is after 'u'? Please read DTS coding style.

Quoted 9 lines
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +4 -0
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c1>;
+	status = "okay";
+};
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +0 -0
index e51b98f5bdce..36bd19e37b57 100644

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi / { · line 21

Quoted 5 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +2 -0
@@ -17,6 +17,10 @@ / {
 	#address-cells = <2>;
 	#size-cells = <2>;
 
+	aliases {
+		i2c0 = &i2c2;

Not a property of DTSI, but DTS.

Quoted 73 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +62 -0
+	};
+
 	cpus {
 		#address-cells = <2>;
 		#size-cells = <0>;
@@ -372,6 +376,66 @@ uart15: serial@407f0000 {
 			status = "disabled";
 		};
 
+		i2c1: i2c@40810000 {
+			compatible = "nuvoton,ma35d1-i2c";
+			reg = <0x0 0x40810000 0x0 0x1000>;
+			interrupts = <GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk I2C1_GATE>;
+			clock-frequency = <100000>;
+			resets = <&sys MA35D1_RESET_I2C1>;
+			status = "disabled";
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c2: i2c@40820000 {
+			compatible = "nuvoton,ma35d1-i2c";
+			reg = <0x0 0x40820000 0x0 0x1000>;
+			interrupts = <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk I2C2_GATE>;
+			clock-frequency = <100000>;
+			resets = <&sys MA35D1_RESET_I2C2>;
+			status = "disabled";
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c3: i2c@40830000 {
+			compatible = "nuvoton,ma35d1-i2c";
+			reg = <0x0 0x40830000 0x0 0x1000>;
+			interrupts = <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk I2C3_GATE>;
+			clock-frequency = <100000>;
+			resets = <&sys MA35D1_RESET_I2C3>;
+			status = "disabled";
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c4: i2c@40840000 {
+			compatible = "nuvoton,ma35d1-i2c";
+			reg = <0x0 0x40840000 0x0 0x1000>;
+			interrupts = <GIC_SPI 123 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk I2C4_GATE>;
+			clock-frequency = <100000>;
+			resets = <&sys MA35D1_RESET_I2C4>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "disabled";
+		};
+
+		i2c5: i2c@40850000 {
+			compatible = "nuvoton,ma35d1-i2c";
+			reg = <0x0 0x40850000 0x0 0x1000>;
+			interrupts = <GIC_SPI 124 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk I2C5_GATE>;
+			clock-frequency = <100000>;
+			resets = <&sys MA35D1_RESET_I2C5>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "disabled";
+		};
+
 		uart16: serial@40880000 {
 			compatible = "nuvoton,ma35d1-uart";
 			reg = <0x0 0x40880000 0x0 0x100>;

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi uart16: serial@40880000 { · line 446

Quoted 4 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +1 -0
@@ -379,5 +443,6 @@ uart16: serial@40880000 {
 			clocks = <&clk UART16_GATE>;
 			status = "disabled";
 		};
+

Why? Do not introduce random changes.

Best regards,
Krzysztof

author
#9 lore raw

Re: [PATCH 3/3] arm64: dts: nuvoton: Add I2C nodes for MA35D1 SoC

Hi Krzysztof,
Thanks for your review.

Krzysztof Kozlowski 於 2026/3/2 下午 03:25 寫道:

Quoted 11 lines · Zi-Yu Chen
Quoted 10 lines

Add I2C controller nodes to the MA35D1 SoC dtsi. Also enable the I2C interfaces on the MA35D1 SOM board to allow communication with onboard peripherals.

---
 .../boot/dts/nuvoton/ma35d1-som-256m.dts      | 14 ++++
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       | 65 +++++++++++++++++++
 2 files changed, 79 insertions(+)
Quoted 10 lines

arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts pinctrl_uart16: uart16-pins { · line 100

Quoted 8 lines
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +0 -0
index f6f20a17e501..2a8f0fd90ded 100644
@@ -98,6 +98,14 @@ pinctrl_uart16: uart16-pins {
 			power-source = <1>;
 		};
 	};

Missing blank line

Will fix in v2.

Quoted 11 lines
Quoted 11 lines
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +8 -0
+	i2c-grp {
+		pinctrl_i2c1: i2c1-pins {
+			nuvoton,pins = <1 10 12>,
+				       <1 11 12>;
+			bias-disable;
+		};
+
+	};
 };
 
Quoted 9 lines

arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts &uart16 { · line 141

Quoted 7 lines
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +2 -0
 &uart0 {
@@ -129,3 +137,9 @@ &uart16 {
 	pinctrl-0 = <&pinctrl_uart16>;
 	status = "okay";
 };
+
+&i2c1 {

Why 'i' is after 'u'? Please read DTS coding style.

Will move &i2c1 after &clk and before &pinctrl in v2 to follow alphabetical order.

Quoted 13 lines
Quoted 13 lines
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +4 -0
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c1>;
+	status = "okay";
+};
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +0 -0
index e51b98f5bdce..36bd19e37b57 100644
@@ -17,6 +17,10 @@ / {
 	#address-cells = <2>;
 	#size-cells = <2>;
 
Quoted 4 lines

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi / { · line 21

Quoted 2 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +2 -0
+	aliases {
+		i2c0 = &i2c2;

Not a property of DTSI, but DTS.

Will move to DTSI in v2.

Quoted 72 lines
Quoted 72 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +62 -0
+	};
+
 	cpus {
 		#address-cells = <2>;
 		#size-cells = <0>;
@@ -372,6 +376,66 @@ uart15: serial@407f0000 {
 			status = "disabled";
 		};
 
+		i2c1: i2c@40810000 {
+			compatible = "nuvoton,ma35d1-i2c";
+			reg = <0x0 0x40810000 0x0 0x1000>;
+			interrupts = <GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk I2C1_GATE>;
+			clock-frequency = <100000>;
+			resets = <&sys MA35D1_RESET_I2C1>;
+			status = "disabled";
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c2: i2c@40820000 {
+			compatible = "nuvoton,ma35d1-i2c";
+			reg = <0x0 0x40820000 0x0 0x1000>;
+			interrupts = <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk I2C2_GATE>;
+			clock-frequency = <100000>;
+			resets = <&sys MA35D1_RESET_I2C2>;
+			status = "disabled";
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c3: i2c@40830000 {
+			compatible = "nuvoton,ma35d1-i2c";
+			reg = <0x0 0x40830000 0x0 0x1000>;
+			interrupts = <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk I2C3_GATE>;
+			clock-frequency = <100000>;
+			resets = <&sys MA35D1_RESET_I2C3>;
+			status = "disabled";
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c4: i2c@40840000 {
+			compatible = "nuvoton,ma35d1-i2c";
+			reg = <0x0 0x40840000 0x0 0x1000>;
+			interrupts = <GIC_SPI 123 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk I2C4_GATE>;
+			clock-frequency = <100000>;
+			resets = <&sys MA35D1_RESET_I2C4>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "disabled";
+		};
+
+		i2c5: i2c@40850000 {
+			compatible = "nuvoton,ma35d1-i2c";
+			reg = <0x0 0x40850000 0x0 0x1000>;
+			interrupts = <GIC_SPI 124 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk I2C5_GATE>;
+			clock-frequency = <100000>;
+			resets = <&sys MA35D1_RESET_I2C5>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "disabled";
+		};
+
 		uart16: serial@40880000 {
 			compatible = "nuvoton,ma35d1-uart";
Quoted 8 lines

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi uart16: serial@40880000 { · line 446

Quoted 6 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +1 -0
 			reg = <0x0 0x40880000 0x0 0x100>;
@@ -379,5 +443,6 @@ uart16: serial@40880000 {
 			clocks = <&clk UART16_GATE>;
 			status = "disabled";
 		};
+

Why? Do not introduce random changes.

Will fix in v2.

Quoted 4 lines

Best regards,
Krzysztof