Skip to contentSkip to conversation

i2c: ma35d1: Add support for MA35D1 I2C controller

PATCH Superseded Zi-Yu Chen 3 participants 9 messages Sep 21 – Sep 29

Subsystems (4)

v10 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Zi-Yu Chen

author
#0 lore raw

v10 cover i2c: ma35d1: Add support for MA35D1 I2C controller

This series adds support for the I2C controller found in the Nuvoton MA35D1 SoC. The driver supports controller and optional target mode and runtime power management.

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

---
Changes in v10:
- Handle enable_irq_wake() return value in suspend.
- Correct clock divider mask and maximum limit to 10-bit.
v9: https://lore.kernel.org/r/[email protected]/

Changes in v9:
- Centralize SI handling in the interrupt handler.
- Fix target mode comments.
- Initialize the target transmit byte.
- Add reset_control_deassert() during probe.
v8: https://lore.kernel.org/r/[email protected]/

Changes in v8:
- Remove rpm_put avoid duplicate processing.
- Add synchronize_irq wait for interrupt to finish before i2c->target = NULL.
- Add ma35d1_i2c_restore_idle() to handle bus errors or spurious interrupts.
- Change return types of TRX helper functions to irqreturn_t, returning IRQ_NONE for unhandled status codes.
v7: https://lore.kernel.org/r/[email protected]/

Changes in v7:
- Disable IRQ before clearing i2c->msg.
- Support CONFIG_PM=n, and simplify runtime PM setup accordingly.
- Remove redundant register access in runtime suspend/resume callbacks.
- Defer clearing i2c->target until after pm_runtime_put_sync() in ma35d1_unreg_target().
- Enable interrupts alongside I2C enable in ma35d1_i2c_reset().
v6: https://lore.kernel.org/r/[email protected]/

Changes in v6:
- Patch 2 (driver):
- Removed dynamic IRQ toggling helpers for simpler interrupt management. Based on Sashiko AI Feedback:
- Added zero-length read quirk.
- Set i2c->msg to NULL on timeout to avoid use-after-free.
- Cleared hardware registers on target unregistration to release the bus.
- Protected suspend-path register writes with a spinlock.
- Validated clock-frequency to prevent division-by-zero.
- Removed incorrect I2C_M_IGNORE_NAK handling.
- Corrected a comment typo in the receive data path.
- Patch 3 (dts):
- use a generic functional name audio-codec@1a
v5: https://lore.kernel.org/r/[email protected]/

Changes in v5:
- Patch 2 (driver):
- Add spinlock protection for MA35_CTL0 register access.
- Add NULL pointer check for i2c->msg in the ISR.
- Use devres-managed cleanup (devm_add_action_or_reset) for runtime PM.
- Use pm_runtime_force_suspend/resume() for Controller mode system sleep.
- Control I2CEN bit enabling/disabling via runtime PM.
- Refactor arbitration lost handling in state machines.
- Remove unsupported I2C_FUNC_PROTOCOL_MANGLING flag.
- Clean up readl_poll_timeout() parameters, retry loop, and unused macros.
v4: https://lore.kernel.org/r/[email protected]/

Changes in v4:
- Patch 1 (dt-bindings):
- Update example interrupt number.
- Patch 2 (driver):
- Remove redundant spinlocks and fix 'irq' type to signed.
- Fix target address recovery in ma35d1_i2c_reset().
- Refactor IRQ handler for multi-msg reads and NACK/IGNORE_NAK.
- Fix timeout UAF via explicit IRQ disabling during recovery.
- Drop IRQF_SHARED and fix PM paths in probe/unregistration.
- Limit suspend/resume wakeup logic to target mode only.
- Patch 3 (dts):
- Add missing i2c0 node to dtsi.
- Switch SoM configuration from i2c1 to i2c2 with updated pinctrl.
- Add nau8822 audio codec node under i2c2 on the SoM board.
- Drop redundant i2c0 alias and clean up dtsi property ordering.
v3: https://lore.kernel.org/r/[email protected]/

Changes in v3:
- Fix minor DTS formatting issues (whitespace, missing newline)
v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Overall:
- Rebase on linux-i2c/i2c-next
- Switched terminology from "master/slave" to "controller/target".
- Patch 1 (dt-bindings):
- Simplified description and fixed 'reg' size in example.
- Patch 2 (driver):
- Modernized using devm_*, generic device properties, and FIELD_PREP/GENMASK.
- Optimized power management by moving clock control to runtime PM.
- Simplified code by removing redundant .remove(), .owner, and inlines.
- Added dev_err_probe() and default bus frequency handling.
- Patch 3 (dts):
- Moved i2c aliases to board dts and reordered nodes alphabetically.
v1: https://lore.kernel.org/r/[email protected]

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      |  63 ++
 .../boot/dts/nuvoton/ma35d1-som-256m.dts      |  20 +
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       |  72 ++
 drivers/i2c/busses/Kconfig                    |  13 +
 drivers/i2c/busses/Makefile                   |   1 +
 drivers/i2c/busses/i2c-ma35d1.c               | 781 ++++++++++++++++++
 6 files changed, 950 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 v10 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      | 63 +++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml
Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml new file +63 -0
new file mode 100644
index 000000000000..0713e1c1ecb8
@@ -0,0 +1,63 @@
+# 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 controller and optional target mode.
+
+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 0x1000>;
+      interrupts = <GIC_SPI 13 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
author
#2 lore raw

PATCH v10 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 controller/target functionality.

---
 drivers/i2c/busses/Kconfig      |  13 +
 drivers/i2c/busses/Makefile     |   1 +
 drivers/i2c/busses/i2c-ma35d1.c | 781 ++++++++++++++++++++++++++++++++
 3 files changed, 795 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ma35d1.c
drivers/i2c/busses/Kconfig +13 -0
index d7b89508311f..e69120d46977 100644
@@ -1602,4 +1602,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 || COMPILE_TEST
+	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 3755c54b3d82..ca75dae4955c 100644
@@ -131,6 +131,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 +781 -0

781 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

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

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] i2c: ma35d1: missing register restore after system resume - [High] i2c: ma35d1: system suspend…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] i2c: ma35d1: missing register restore after system resume
- [High] i2c: ma35d1: system suspend aborted by enable_irq_wake failure
--

commit b259b8f6191b7d3a9bf1070672a2bb0522d35137
Author: Zi-Yu Chen <[email protected]>

i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support

This commit introduces the Nuvoton MA35D1 I2C driver, which supports standard, fast, and fast-plus modes. The driver provides both controller and target functionality.

Quoted 6 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0 -0
new file mode 100644
index 0000000000000..9b1872b8033f1
@@ -0,0 +1,781 @@

[ ... ]

drivers/i2c/busses/i2c-ma35d1.c line 162

Quoted 6 lines
drivers/i2c/busses/i2c-ma35d1.c new file +6 -0
+static void ma35d1_i2c_reset(struct ma35d1_i2c *i2c)
+{
+	unsigned int clkdiv, slvaddr;
+
+	clkdiv = readl(i2c->regs + MA35_CLKDIV);
+	slvaddr = readl(i2c->regs + MA35_ADDR0);

[Severity: High]
Does this code read a potentially corrupted CLKDIV value from hardware instead of using a saved configuration?

If the system was suspended and power was dropped, this register might be lost. The recovery function would then read a default CLKDIV of 0, which is later written back, permanently corrupting the bus frequency.

[ ... ]

Quoted 10 lines
drivers/i2c/busses/i2c-ma35d1.c new file +10 -0
+static int ma35d1_i2c_suspend(struct device *dev)
+{
+	struct ma35d1_i2c *i2c = dev_get_drvdata(dev);
+	unsigned int val;
+	int ret;
+
+	/* Prepare for wake-up from I2C events if target mode is active */
+	if (i2c->target) {
+		ma35d1_i2c_write_ctl(i2c, MA35_CTL_AA);
+

drivers/i2c/busses/i2c-ma35d1.c line 607

Quoted 10 lines
drivers/i2c/busses/i2c-ma35d1.c new file +10 -0
+		/* 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);
+
+		ret = enable_irq_wake(i2c->irq);
+		if (ret)
+			return ret;

[Severity: High]
Could this fail the entire system suspend sequence if the I2C interrupt cannot be configured as a wakeup source?

If the underlying IRQ controller does not support irq_set_wake() for this interrupt line (which is common on many ARM platforms without dedicated wake routing), enable_irq_wake() will return -ENXIO or -EINVAL.

Propagating this error to the PM core violently aborts the sleep transition whenever target mode is enabled.

[ ... ]

drivers/i2c/busses/i2c-ma35d1.c line 646

Quoted 6 lines
drivers/i2c/busses/i2c-ma35d1.c new file +6 -0
+static int ma35d1_i2c_runtime_resume(struct device *dev)
+{
+	struct ma35d1_i2c *i2c = dev_get_drvdata(dev);
+	int ret;
+
+	ret = clk_enable(i2c->clk);

[Severity: High]
Does this function need to restore the CLKDIV and CTL0 registers?

These registers are lost during a system suspend (S3) if the power domain drops power.

If the registers aren't restored, the first transfer attempted after system resume writes STA to an otherwise zeroed CTL0, leaving the controller and interrupts disabled. This results in a 5-second timeout, after which the error path resets the controller but writes back a default CLKDIV.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer
#4 lore raw

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

In reply to Zi-Yu Chen

Hi Zi-Yu,

...

drivers/i2c/busses/i2c-ma35d1.c line 98

Quoted 4 lines
drivers/i2c/busses/i2c-ma35d1.c new file +4 -0
+/* Constants */
+#define MA35_CLKDIV_MSK		GENMASK(9, 0)
+#define I2C_PM_TIMEOUT_MS	5000
+#define STOP_TIMEOUT_MS		50

these two defines are the only ones without the MA35 prefix.

...

Quoted 5 lines
drivers/i2c/busses/i2c-ma35d1.c new file +5 -0
+static irqreturn_t ma35d1_i2c_irq_target_trx(struct ma35d1_i2c *i2c,
+					     unsigned long i2c_status)
+{
+	unsigned char byte = 0;
+

drivers/i2c/busses/i2c-ma35d1.c line 243

Quoted 10 lines
drivers/i2c/busses/i2c-ma35d1.c new file +10 -0
+	switch (i2c_status) {
+	case MA35_S_RECE_ARB_LOST:
+		/*
+		 * Arbitration lost during address transmission phase.
+		 * The hardware switches to Target Transmitter mode when
+		 * our own SLA+W is detected on the bus.
+		 */
+		i2c->err = -EAGAIN;
+		ma35d1_i2c_controller_complete(i2c);
+		i2c_slave_event(i2c->target, I2C_SLAVE_WRITE_REQUESTED, &byte);

All the return values of these i2c_slave_event()'s are ignored.

Quoted 15 lines
drivers/i2c/busses/i2c-ma35d1.c new file +15 -0
+		break;
+
+	case MA35_S_RECE_ADDR_ACK:
+		/* Own SLA+W has been receive; ACK has been return */
+		i2c_slave_event(i2c->target, I2C_SLAVE_WRITE_REQUESTED, &byte);
+		break;
+
+	case MA35_S_TRAN_DATA_NACK:
+	case MA35_S_RECE_DATA_NACK:
+		/*
+		 * Data byte or last data in I2CDAT has been transmitted and NACK received,
+		 * or previously addressed with own SLA address and NACK returned.
+		 */
+		break;
+

...

drivers/i2c/busses/i2c-ma35d1.c line 305

Quoted 7 lines
drivers/i2c/busses/i2c-ma35d1.c new file +7 -0
+	default:
+		dev_err(i2c->dev, "Status 0x%02lx is NOT processed\n",
+			i2c_status);
+		ma35d1_i2c_restore_idle(i2c);
+		return IRQ_NONE;
+	}
+	ma35d1_i2c_write_ctl(i2c, MA35_CTL_SI_AA);

As far as I understood, this this is an unconditional ACK enabled for the next bytes received, right? In that case are we ignoring failed communications as above where we are supposed to send NACKs?

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

...

Quoted 38 lines
drivers/i2c/busses/i2c-ma35d1.c new file +38 -0
+	i2c->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+	if (IS_ERR(i2c->regs))
+		return PTR_ERR(i2c->regs);
+
+	i2c->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+	if (IS_ERR(i2c->rst))
+		return dev_err_probe(dev, PTR_ERR(i2c->rst),
+				     "failed to get reset control\n");
+
+	ret = reset_control_deassert(i2c->rst);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to deassert reset line\n");
+
+	/* 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.quirks = &ma35d1_i2c_quirks;
+	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);
+
+	if (!device_property_read_u32(dev, "clock-frequency", &val)) {
+		if (val != 0 && val <= MEGA)
+			busfreq = val;
+	}
+	/* 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 > 0x3ff)
+		return dev_err_probe(dev, -EINVAL, "invalid clkdiv value: %d\n",
+				     clkdiv);
+
+	i2c->irq = platform_get_irq(pdev, 0);
+	if (i2c->irq < 0)
+		return dev_err_probe(dev, i2c->irq, "failed to get irq\n");
+

drivers/i2c/busses/i2c-ma35d1.c line 734

Quoted 10 lines
drivers/i2c/busses/i2c-ma35d1.c new file +10 -0
+	platform_set_drvdata(pdev, i2c);
+
+	pm_runtime_set_autosuspend_delay(dev, I2C_PM_TIMEOUT_MS);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+
+	ret = devm_add_action_or_reset(dev, ma35d1_i2c_pm_cleanup, dev);
+	if (ret)
+		return ret;

you are printing an error message everywhere, except of here.

Quoted 5 lines
drivers/i2c/busses/i2c-ma35d1.c new file +5 -0
+
+	writel(MA35_CTL_I2CEN | MA35_CTL_INTEN, i2c->regs + MA35_CTL0);
+	writel(FIELD_PREP(MA35_CLKDIV_MSK, clkdiv), i2c->regs + MA35_CLKDIV);
+
+	ret = devm_request_irq(dev, i2c->irq, ma35d1_i2c_irq, 0, dev_name(dev),

drivers/i2c/busses/i2c-ma35d1.c line 749

Quoted 10 lines
drivers/i2c/busses/i2c-ma35d1.c new file +10 -0
+			       i2c);
+	if (ret) {
+		dev_err_probe(dev, ret, "cannot claim IRQ %d\n", i2c->irq);
+		return ret;
+	}
+
+	ret = devm_i2c_add_adapter(dev, &i2c->adap);
+	if (ret) {
+		dev_err_probe(dev, ret, "failed to add bus to i2c core\n");
+		return ret;

return dev_err_probe(...)

Thanks,
Andi

Quoted 6 lines
drivers/i2c/busses/i2c-ma35d1.c new file +6 -0
+	}
+
+	dev_info(&i2c->adap.dev, "%pa MA35D1 I2C adapter registered\n",
+		 &res->start);
+	return 0;
+}
author
#5 lore raw

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

Hi Andi,
Thanks for your review.

Andi Shyti 於 2026/9/28 下午 08:24 寫道:

Quoted 10 lines

Hi Zi-Yu,

...

drivers/i2c/busses/i2c-ma35d1.c line 98

Quoted 4 lines
drivers/i2c/busses/i2c-ma35d1.c new file +4 -0
+/* Constants */
+#define MA35_CLKDIV_MSK		GENMASK(9, 0)
+#define I2C_PM_TIMEOUT_MS	5000
+#define STOP_TIMEOUT_MS		50

these two defines are the only ones without the MA35 prefix.

Will add the MA35 prefix to these two definitions.

Quoted 39 lines

...

Quoted 5 lines
drivers/i2c/busses/i2c-ma35d1.c new file +5 -0
+static irqreturn_t ma35d1_i2c_irq_target_trx(struct ma35d1_i2c *i2c,
+					     unsigned long i2c_status)
+{
+	unsigned char byte = 0;
+

drivers/i2c/busses/i2c-ma35d1.c line 243

Quoted 10 lines
drivers/i2c/busses/i2c-ma35d1.c new file +10 -0
+	switch (i2c_status) {
+	case MA35_S_RECE_ARB_LOST:
+		/*
+		 * Arbitration lost during address transmission phase.
+		 * The hardware switches to Target Transmitter mode when
+		 * our own SLA+W is detected on the bus.
+		 */
+		i2c->err = -EAGAIN;
+		ma35d1_i2c_controller_complete(i2c);
+		i2c_slave_event(i2c->target, I2C_SLAVE_WRITE_REQUESTED, &byte);

All the return values of these i2c_slave_event()'s are ignored.

Quoted 15 lines
drivers/i2c/busses/i2c-ma35d1.c new file +15 -0
+		break;
+
+	case MA35_S_RECE_ADDR_ACK:
+		/* Own SLA+W has been receive; ACK has been return */
+		i2c_slave_event(i2c->target, I2C_SLAVE_WRITE_REQUESTED, &byte);
+		break;
+
+	case MA35_S_TRAN_DATA_NACK:
+	case MA35_S_RECE_DATA_NACK:
+		/*
+		 * Data byte or last data in I2CDAT has been transmitted and NACK received,
+		 * or previously addressed with own SLA address and NACK returned.
+		 */
+		break;
+

...

Quoted 13 lines

drivers/i2c/busses/i2c-ma35d1.c line 305

Quoted 7 lines
drivers/i2c/busses/i2c-ma35d1.c new file +7 -0
+	default:
+		dev_err(i2c->dev, "Status 0x%02lx is NOT processed\n",
+			i2c_status);
+		ma35d1_i2c_restore_idle(i2c);
+		return IRQ_NONE;
+	}
+	ma35d1_i2c_write_ctl(i2c, MA35_CTL_SI_AA);

As far as I understood, this this is an unconditional ACK enabled for the next bytes received, right? In that case are we ignoring failed communications as above where we are supposed to send NACKs?

Regarding the two comments above:
I will add handling for the return value of I2C_SLAVE_WRITE_REQUESTED. When it returns an error, subsequent bytes will be NACKed until the transfer ends.

For I2C_SLAVE_WRITE_RECEIVED, the MA35D1 hardware has already generated the ACK when this event is reported, so it is not possible to NACK the received byte at this point. Therefore, its return value can only be temporarily ignored.

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

...

Quoted 42 lines
drivers/i2c/busses/i2c-ma35d1.c new file +42 -0
+	i2c->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+	if (IS_ERR(i2c->regs))
+		return PTR_ERR(i2c->regs);
+
+	i2c->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+	if (IS_ERR(i2c->rst))
+		return dev_err_probe(dev, PTR_ERR(i2c->rst),
+				     "failed to get reset control\n");
+
+	ret = reset_control_deassert(i2c->rst);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to deassert reset line\n");
+
+	/* 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.quirks = &ma35d1_i2c_quirks;
+	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);
+
+	if (!device_property_read_u32(dev, "clock-frequency", &val)) {
+		if (val != 0 && val <= MEGA)
+			busfreq = val;
+	}
+	/* 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 > 0x3ff)
+		return dev_err_probe(dev, -EINVAL, "invalid clkdiv value: %d\n",
+				     clkdiv);
+
+	i2c->irq = platform_get_irq(pdev, 0);
+	if (i2c->irq < 0)
+		return dev_err_probe(dev, i2c->irq, "failed to get irq\n");
+
+	platform_set_drvdata(pdev, i2c);
+
+	pm_runtime_set_autosuspend_delay(dev, I2C_PM_TIMEOUT_MS);
+	pm_runtime_use_autosuspend(dev);
Quoted 8 lines

drivers/i2c/busses/i2c-ma35d1.c line 734

Quoted 6 lines
drivers/i2c/busses/i2c-ma35d1.c new file +6 -0
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+
+	ret = devm_add_action_or_reset(dev, ma35d1_i2c_pm_cleanup, dev);
+	if (ret)
+		return ret;

you are printing an error message everywhere, except of here.

Right. I’ll add an error message here as well.

Quoted 10 lines
Quoted 10 lines
drivers/i2c/busses/i2c-ma35d1.c new file +9 -0
+
+	writel(MA35_CTL_I2CEN | MA35_CTL_INTEN, i2c->regs + MA35_CTL0);
+	writel(FIELD_PREP(MA35_CLKDIV_MSK, clkdiv), i2c->regs + MA35_CLKDIV);
+
+	ret = devm_request_irq(dev, i2c->irq, ma35d1_i2c_irq, 0, dev_name(dev),
+			       i2c);
+	if (ret) {
+		dev_err_probe(dev, ret, "cannot claim IRQ %d\n", i2c->irq);
+		return ret;
Quoted 8 lines

drivers/i2c/busses/i2c-ma35d1.c line 749

Quoted 6 lines
drivers/i2c/busses/i2c-ma35d1.c new file +6 -0
+	}
+
+	ret = devm_i2c_add_adapter(dev, &i2c->adap);
+	if (ret) {
+		dev_err_probe(dev, ret, "failed to add bus to i2c core\n");
+		return ret;

return dev_err_probe(...)

will do.

Quoted 10 lines

Thanks,
Andi

Quoted 6 lines
drivers/i2c/busses/i2c-ma35d1.c new file +6 -0
+	}
+
+	dev_info(&i2c->adap.dev, "%pa MA35D1 I2C adapter registered\n",
+		 &res->start);
+	return 0;
+}
author
#6 lore raw

PATCH v10 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 file. Also, enable the I2C2 interface on the MA35D1 SOM board and configure its pinctrl to allow communication with the onboard NAU8822 audio codec

---
 .../boot/dts/nuvoton/ma35d1-som-256m.dts      | 20 ++++++
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       | 72 +++++++++++++++++++
 2 files changed, 92 insertions(+)
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +20 -0
index a029b660e8dc..422468dbc3bf 100644
@@ -57,6 +57,18 @@ &clk {
 			   "integer";
 };
 
+&i2c2 {
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c2>;
+
+	nau8822: audio-codec@1a {
+		compatible = "nuvoton,nau8822";
+		reg = <0x1a> ;
+		nuvoton,spk-btl;
+	};
+};
+
 &pinctrl {
 	uart-grp {
 		pinctrl_uart0: uart0-pins {
@@ -100,6 +112,14 @@ pinctrl_uart16: uart16-pins {
 			power-source = <1>;
 		};
 	};
+
+	i2c-grp {
+		pinctrl_i2c2: i2c2-pins {
+			nuvoton,pins = <1 8 4>,
+				       <1 9 4>;
+			bias-disable;
+		};
+	};
 };
 
 &uart0 {
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +72 -0

78 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#7 lore raw

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

Hi Zi-Yu,

...

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

Quoted 8 lines

+&i2c2 {

arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +7 -0
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c2>;
+
+	nau8822: audio-codec@1a {
+		compatible = "nuvoton,nau8822";
+		reg = <0x1a> ;

please, remove the space before the ';'

Thanks,
Andi

Quoted 3 lines
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +3 -0
+		nuvoton,spk-btl;
+	};
+};
author
#8 lore raw

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

Hi Andi,
Thanks for your review.

Andi Shyti 於 2026/9/28 下午 08:29 寫道:

Quoted 4 lines

Hi Zi-Yu,

...

Quoted 10 lines

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

Quoted 8 lines

+&i2c2 {

arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +7 -0
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c2>;
+
+	nau8822: audio-codec@1a {
+		compatible = "nuvoton,nau8822";
+		reg = <0x1a> ;

please, remove the space before the ';'

will do.>

Quoted 6 lines

Thanks,
Andi

Quoted 3 lines
arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts +3 -0
+		nuvoton,spk-btl;
+	};
+};