i2c: ma35d1: Add support for MA35D1 I2C controller
Subsystems (4)
v11 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 v12:
- Synchronize IRQs while initializing transfer state and issuing START.
- Clear wake-up control if enabling IRQ wake fails.
v11: https://lore.kernel.org/all/[email protected]/
Changes in v11:
According to Andi's comments:
- Prefix the remaining timeout macros with MA35_.
- Handle errors returned by i2c_slave_event() by sending NACK when the target driver rejects a request.
- Use dev_err_probe() consistently in probe error paths.
v10: https://lore.kernel.org/r/[email protected]/
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 | 800 ++++++++++++++++++ 6 files changed, 969 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
PATCH v12 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
@@ -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
PATCH v12 2/3 i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support
In reply to Zi-Yu ChenAdd 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 | 800 ++++++++++++++++++++++++++++++++ 3 files changed, 814 insertions(+) create mode 100644 drivers/i2c/busses/i2c-ma35d1.c
drivers/i2c/busses/Kconfig +13 -0
@@ -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
@@ -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 +800 -0
800 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v12 2/3] i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] i2c: ignored return value of I2C_SLAVE_WRITE_RECEIVED breaks flow control - [High] i2c…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] i2c: ignored return value of I2C_SLAVE_WRITE_RECEIVED breaks flow control
- [High] i2c: zero-message transfers bypass wait logic causing OOB reads or bus lockups
- [Medium] i2c: ma35d1: multi-master target arbitration broken by clearing AA bit --
commit cb2d83f6d803405066915dfcc01410b98bdff1a8
Author: Zi-Yu Chen <[email protected]>
i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support
This commit adds I2C support for the Nuvoton MA35D1 SoC, including standard, fast, and fast-plus modes, and provides controller and target functionality.
Quoted 5 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0
[ ... ]
Quoted 13 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0@@ -125,12 +125,12 @@ static inline bool ma35d1_is_controller_status(unsigned int status)/* * ma35d1_i2c_write_ctl - Update the I2C control register * @i2c: Pointer to the ma35d1 i2c instance * @ctl: Control bits to set (e.g., MA35_CTL_STA, SI, AA) * * Read-modify-write the CTL0 register while preserving unrelated bits. */ static void ma35d1_i2c_write_ctl (struct ma35d1_i2c *i2c,unsigned int ctl) {unsigned int val;guard (spinlock_irqsave)(&i2c->lock);
drivers/i2c/busses/i2c-ma35d1.c
Quoted 3 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0val =readl (i2c->regs +MA35_CTL0 ); val &= ~(MA35_CTL_SI_AA ); val |= ctl;
[Severity: Medium]
Does this unconditionally clear the Assert Acknowledge (MA35_CTL_AA) bit unless it is explicitly passed in the ctl argument?
If arbitration is lost during the START or address phase of a transfer, the controller will read AA as 0 and NACK its own target address, causing the winning master's transfer to fail.
Quoted 2 lines
writel(val, i2c->regs + MA35_CTL0);
}
[ ... ]
Quoted 7 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0@@ -262,17 +262,17 @@ static irqreturn_t ma35d1_i2c_irq_target_trx(struct ma35d1_i2c *i2c,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. */
drivers/i2c/busses/i2c-ma35d1.c static irqreturn_t ma35d1_i2c_irq_target_trx(struct ma35d1_i2c *i2c, · line 277
Quoted 10 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0i2c->target_reject = false;break ;case MA35_S_RECE_DATA_ACK :/* * Previously address with own SLA address Data has been received; * ACK has been returned */ byte =readb (i2c->regs +MA35_DAT );i2c_slave_event (i2c->target,I2C_SLAVE_WRITE_RECEIVED , &byte);
[Severity: High]
Does this code ignore the return value of i2c_slave_event in ma35d1_i2c_irq_target_trx?
If the backend cannot accept more data, for example when the backend buffer is full, it returns a non-zero value. Because this is ignored, the driver unconditionally writes MA35_CTL_SI_AA at the end of the ISR to ACK the byte, which breaks flow control and allows an external I2C master to overrun the backend buffer.
Should the return value be checked and i2c->target_reject set to true to properly NACK the next incoming byte on error?
Quoted 3 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0break ;case
MA35_ADDR_TRAN_ARB_LOST:
[ ... ]
drivers/i2c/busses/i2c-ma35d1.c static irqreturn_t ma35d1_i2c_irq_controller_trx(struct ma35d1_i2c *i2c, · line 343
Quoted 12 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0@@ -333,13 +333,13 @@ static irqreturn_t ma35d1_i2c_irq_controller_trx(struct ma35d1_i2c *i2c,if (unlikely (!i2c->msg)) {dev_err (i2c->dev,"Spurious controller interrupt (status: 0x%02lx)\n" , i2c_status);ma35d1_i2c_restore_idle (i2c);return IRQ_HANDLED ; }switch (i2c_status) {case MA35_M_START :case MA35_M_REPEAT_START :ma35d1_i2c_set_addr (i2c);ma35d1_i2c_write_ctl (i2c,MA35_CTL_SI );
[Severity: Medium]
Since MA35_CTL_AA is omitted here in ma35d1_i2c_irq_controller_trx, the AA bit is cleared during address transmission. If arbitration is lost during SLA+R/W, will the target fallback fail to ACK its own address?
Quoted 3 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0break ;case
MA35_M_TRAN_ADDR_ACK:
[ ... ]
Quoted 5 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0@@ -438,15 +438,15 @@ static int ma35d1_i2c_doxfer(struct ma35d1_i2c *i2c, struct i2c_msg *msgs, int num) {unsigned long timeout;unsigned int val;
drivers/i2c/busses/i2c-ma35d1.c static int ma35d1_i2c_doxfer(struct ma35d1_i2c *i2c, struct i2c_msg *msgs, · line 451
Quoted 10 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0int ret, err;disable_irq (i2c->irq); i2c->msg = msgs; i2c->msg_num = num; i2c->msg_ptr =0 ; i2c->msg_idx =0 ; i2c->err =0 ;ma35d1_i2c_write_ctl (i2c,MA35_CTL_STA );
[Severity: Medium]
Will this omit the AA bit and thus clear it when initiating a master transfer in ma35d1_i2c_doxfer?
Quoted 3 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0enable_irq (i2c->irq);timeout =
wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
[Severity: High]
If a caller invokes i2c_transfer with num = 0 to probe the bus, does this wait evaluate to true immediately?
When num = 0, i2c->msg_num is set to 0. This causes wait_event_timeout to complete instantly while the hardware is still initiating the START. If msgs is a zero-length array pointer or NULL, the subsequent interrupt could either read out-of-bounds from i2c->msg or fail to assert a STOP condition, leaving the bus permanently locked up in a START state.
Quoted 3 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0ret = i2c->msg_idx;if (timeout ==0 ) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v12 2/3] i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support
[email protected] 於 2026/10/16 上午 09:17 寫道:
Quoted 2 lines
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] i2c: ignored return value ofI2C_SLAVE_WRITE_RECEIVEDbreaks flow control
As in the previous reply.
When MA35D1 reports MA35_S_RECE_DATA_ACK, the byte has already been received and ACKed, so the driver can no longer NACK it. Propagating the callback error to the next byte is also incorrect, as I2C_SLAVE_WRITE_RECEIVED applies only to the current byte.
Quoted 1 line
- [High] i2c: zero-message transfers bypass wait logic causing OOB reads or bus lockups
core rejects transfers with num < 1 in __i2c_transfer() and returns -EINVAL before calling the adapter's master_xfer() callback.
Quoted 1 line
- [Medium] i2c: ma35d1: multi-master target arbitration broken by clearing AA bit
The MA35D1 hardware supports both controller and target modes. When a target is registered, this driver intentionally clears AA while initiating a controller transfer, so it does not accept transactions addressed to its target address during that period. Preserving AA would change the current coexistence behavior and require validation of the arbitration and target state transitions. We would prefer to address that as a separate multi-master enhancement in a follow-up patch.
Quoted 129 lines
--
commit
cb2d83f6d803405066915dfcc01410b98bdff1a8
Author: Zi-Yu Chen <[email protected]>i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support
This commit adds I2C support for the Nuvoton MA35D1 SoC, including standard, fast, and fast-plus modes, and provides controller and target functionality.
Quoted 5 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0[ ... ]
Quoted 13 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0@@ -125,12 +125,12 @@ static inline bool ma35d1_is_controller_status(unsigned int status)/* * ma35d1_i2c_write_ctl - Update the I2C control register * @i2c: Pointer to the ma35d1 i2c instance * @ctl: Control bits to set (e.g., MA35_CTL_STA, SI, AA) * * Read-modify-write the CTL0 register while preserving unrelated bits. */ static void ma35d1_i2c_write_ctl (struct ma35d1_i2c *i2c,unsigned int ctl) {unsigned int val;guard (spinlock_irqsave)(&i2c->lock);drivers/i2c/busses/i2c-ma35d1.c
Quoted 3 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0val =readl (i2c->regs +MA35_CTL0 ); val &= ~(MA35_CTL_SI_AA ); val |= ctl;[Severity: Medium]
Does this unconditionally clear the Assert Acknowledge (MA35_CTL_AA) bit unless it is explicitly passed in the ctl argument?If arbitration is lost during the START or address phase of a transfer, the controller will read AA as 0 and NACK its own target address, causing the winning master's transfer to fail.
Quoted 2 lines
writel(val, i2c->regs + MA35_CTL0);
}[ ... ]
Quoted 7 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0@@ -262,17 +262,17 @@ static irqreturn_t ma35d1_i2c_irq_target_trx(struct ma35d1_i2c *i2c,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. */ drivers/i2c/busses/i2c-ma35d1.c static irqreturn_t ma35d1_i2c_irq_target_trx(struct ma35d1_i2c *i2c, · line 277
Quoted 10 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0i2c->target_reject = false;break ;case MA35_S_RECE_DATA_ACK :/* * Previously address with own SLA address Data has been received; * ACK has been returned */ byte =readb (i2c->regs +MA35_DAT );i2c_slave_event (i2c->target,I2C_SLAVE_WRITE_RECEIVED , &byte);[Severity: High]
Does this code ignore the return value ofi2c_slave_eventinma35d1_i2c_irq_target_trx?If the backend cannot accept more data, for example when the backend buffer is full, it returns a non-zero value. Because this is ignored, the driver unconditionally writes
MA35_CTL_SI_AAat the end of the ISR to ACK the byte, which breaks flow control and allows an external I2C master to overrun the backend buffer.Should the return value be checked and
i2c->target_rejectset to true to properly NACK the next incoming byte on error?Quoted 3 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0break ;case
MA35_ADDR_TRAN_ARB_LOST:[ ... ]
drivers/i2c/busses/i2c-ma35d1.c static irqreturn_t ma35d1_i2c_irq_controller_trx(struct ma35d1_i2c *i2c, · line 343
Quoted 12 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0@@ -333,13 +333,13 @@ static irqreturn_t ma35d1_i2c_irq_controller_trx(struct ma35d1_i2c *i2c,if (unlikely (!i2c->msg)) {dev_err (i2c->dev,"Spurious controller interrupt (status: 0x%02lx)\n" , i2c_status);ma35d1_i2c_restore_idle (i2c);return IRQ_HANDLED ; }switch (i2c_status) {case MA35_M_START :case MA35_M_REPEAT_START :ma35d1_i2c_set_addr (i2c);ma35d1_i2c_write_ctl (i2c,MA35_CTL_SI );[Severity: Medium]
SinceMA35_CTL_AAis omitted here inma35d1_i2c_irq_controller_trx, the AA bit is cleared during address transmission. If arbitration is lost during SLA+R/W, will the target fallback fail to ACK its own address?Quoted 3 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0break ;case
MA35_M_TRAN_ADDR_ACK:[ ... ]
Quoted 5 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0@@ -438,15 +438,15 @@ static int ma35d1_i2c_doxfer(struct ma35d1_i2c *i2c, struct i2c_msg *msgs, int num) {unsigned long timeout;unsigned int val;drivers/i2c/busses/i2c-ma35d1.c static int ma35d1_i2c_doxfer(struct ma35d1_i2c *i2c, struct i2c_msg *msgs, · line 451
Quoted 10 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0int ret, err;disable_irq (i2c->irq); i2c->msg = msgs; i2c->msg_num = num; i2c->msg_ptr =0 ; i2c->msg_idx =0 ; i2c->err =0 ;ma35d1_i2c_write_ctl (i2c,MA35_CTL_STA );[Severity: Medium]
Will this omit the AA bit and thus clear it when initiating a master transfer inma35d1_i2c_doxfer?Quoted 3 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0enable_irq (i2c->irq);timeout =
wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);[Severity: High]
If a caller invokesi2c_transferwith num = 0 to probe the bus, does this wait evaluate to true immediately?
Quoted 10 lines
When num = 0,
i2c->msg_numis set to 0. This causeswait_event_timeoutto complete instantly while the hardware is still initiating the START. If msgs is a zero-length array pointer or NULL, the subsequent interrupt could either read out-of-bounds fromi2c->msgor fail to assert a STOP condition, leaving the bus permanently locked up in a START state.Quoted 3 lines
drivers/i2c/busses/i2c-ma35d1.c new file +0
-0ret = i2c->msg_idx;if (timeout ==0 ) {
Best regards,
Zi-Yu
PATCH v12 3/3 arm64: dts: nuvoton: Add I2C nodes for MA35D1 SoC
In reply to Zi-Yu ChenAdd 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
@@ -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
Hi all,
Sorry, the cover letter subject contains a typo: it should be [PATCH v12 0/3], not [PATCH v11 0/3].
The cover letter content and all three patches are from v12.
Sorry for the confusion.
Best regards,
Zi-Yu
Zi-Yu Chen 於 2026/10/16 上午 09:04 寫道:
Quoted 129 lines
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.
Signed-off-by Zi-Yu Chen <[email protected]>---
Changes in v12:
- Synchronize IRQs while initializing transfer state and issuing START.
- Clear wake-up control if enabling IRQ wake fails.
v11: https://lore.kernel.org/all/[email protected]/Changes in v11:
According to Andi's comments:
- Prefix the remaining timeout macros withMA35_.
- Handle errors returned byi2c_slave_event()by sending NACK when the target driver rejects a request.
- Usedev_err_probe()consistently in probe error paths.
v10: https://lore.kernel.org/r/[email protected]/Changes in v10:
- Handleenable_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.
- Addreset_control_deassert()during probe.
v8: https://lore.kernel.org/r/[email protected]/Changes in v8:
- Removerpm_putavoid duplicate processing.
- Addsynchronize_irqwait for interrupt to finish beforei2c->target= NULL.
- Addma35d1_i2c_restore_idle()to handle bus errors or spurious interrupts.
- Change return types of TRX helper functions toirqreturn_t, returningIRQ_NONEfor unhandled status codes.
v7: https://lore.kernel.org/r/[email protected]/Changes in v7:
- Disable IRQ before clearingi2c->msg.
- SupportCONFIG_PM=n, and simplify runtime PM setup accordingly.
- Remove redundant register access in runtime suspend/resume callbacks.
- Defer clearingi2c->targetuntil afterpm_runtime_put_sync()inma35d1_unreg_target().
- Enable interrupts alongside I2C enable inma35d1_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.
- Seti2c->msgto 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 incorrectI2C_M_IGNORE_NAKhandling.
- 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 forMA35_CTL0register access.
- Add NULL pointer check fori2c->msgin 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 unsupportedI2C_FUNC_PROTOCOL_MANGLINGflag.
- Clean upreadl_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 inma35d1_i2c_reset().
- Refactor IRQ handler for multi-msg reads and NACK/IGNORE_NAK.
- Fix timeout UAF via explicit IRQ disabling during recovery.
- DropIRQF_SHAREDand 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.
- Addeddev_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 | 800 ++++++++++++++++++ 6 files changed, 969 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/nuvoton,ma35d1-i2c.yaml create mode 100644 drivers/i2c/busses/i2c-ma35d1.c