Skip to contentSkip to conversation

Add Qualcomm I2C target controller driver

PATCH In review Viken Dadhaniya 3 participants 6 messages Oct 5 – Oct 14

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v5 cover Add Qualcomm I2C target controller driver

QDU1000 and related Qualcomm SoCs include a dedicated I2C target controller that operates exclusively in target mode and is not supported by the existing Qualcomm I2C master controller drivers (GENI, QUP).

This series adds DT binding and driver support for this IP. The driver uses the standard Linux I2C slave framework (reg_target/unreg_target, i2c_slave_event) so any slave backend (e.g. slave-24c02) can be attached via i2c_slave_register().

The series is structured as follows:

Patch 1: DT binding document
Patch 2: Driver implementation including Kconfig, Makefile and
MAINTAINERS entries

The driver has been tested on QDU1000 hardware.

---
Changes in v5:
- Handle errors returned from I2C_SLAVE_WRITE_REQUESTED and NACK
subsequent write data until the transaction ends.
- Use target/adapter terminology for driver-internal structures, members, callbacks, and comments while retaining the existing I2C_SLAVE_* API names.
- Initialize the I2C adapter owner with THIS_MODULE.
- Express the interconnect bandwidth vote using the ICC kilobytes-per-second units through Bps_to_icc().
- Make clock enable and disable ordering consistent across probe, remove, suspend, and resume.
- Keep the interrupt disabled when resume fails before the clocks and
controller state are fully restored.
- Mark system sleep callbacks as __maybe_unused for configurations without CONFIG_PM_SLEEP.
- Reject 10-bit target addresses before programming the controller.
- Update short-write handling to use the common write-request event path
before delivering the STOP event.
- Link to v4: https://patch.msgid.link/[email protected]

Changes in v4:
- Replaced usleep_range() with udelay(20) in the reset path, since
reset is invoked from the hardirq error handler.
- Avoided releasing clock stretch on RESTART_DETECTED when STRCH_RD is co-asserted; TX FIFO is now loaded before ACK_RESUME is written.
- Added cleanup for both clocks on all probe failures after they are
enabled.
- Explicitly freed the IRQ before clock teardown in remove(), preventing IRQ-handler register accesses after clocks are disabled.
- Replaced noirq PM callbacks with regular system suspend/resume callbacks
and quiesced the IRQ while clocks are disabled.
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- Rename file to match compatible (qcom,qdu1000-i2c-target.yaml)
- Remove interconnect-names property
- Remove allOf reference to i2c-controller.yaml
- Remove #address-cells and #size-cells from example
- Add minItems: 1 to pinctrl-names
- Move I2C_S_CORE_EN out of hw_init; enable core only in reg_slave
and hw_reset
- Add usleep_range(10, 20) after SW_RESET before reconfiguring hardware
- Fix RESTART_DETECTED dispatch order; handle before STRCH_RD and
Rx data phases
- Use test_and_set_bit in write_requested and handle_strch_rd
- Loop drain_rx_fifo until FIFO is empty to close post-STOP data race
- Disable core before clearing slave pointer in unreg_slave
- Clear target->status on resume
- Switch from devm_clk_get_enabled to devm_clk_get with manual
clk_prepare_enable
- Remove unbalanced disable_irq from remove
- Update struct kdoc to note I2C_LOCK_ROOT_ADAPTER serialises
reg/unreg_target
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Rename driver and binding from "slave" to "target" terminology
- Use SoC-specific compatible string (qcom,qdu1000-i2c-target) instead of
generic qcom,i2c-slave; add allOf/$ref to i2c-controller.yaml
- Replace SMBus layer (smbus_xfer, I2C_FUNC_SMBUS_*) with native Linux I2C
slave framework (reg_target/unreg_target, I2C_SLAVE_* events)
- Remove qcom,slave-addr DT property; slave address taken from the
registered i2c_client at reg_target() time
- Remove staging buffers and spinlock; bytes delivered directly to backend
via i2c_slave_event() per STRCH_RD/RX/STOP event
- Use SET_NOIRQ_SYSTEM_SLEEP_PM_OPS; PM core quiesces IRQs at noirq stage, removing need for manual disable_irq/enable_irq in suspend
- Simplify clock-names (xo/ahb) and interconnect-names (i2c)
- Replace icc_enable/icc_disable with icc_set_bw() vote/unvote
- Merge MAINTAINERS entry into the dt-bindings patch
- Link to v1: https://patch.msgid.link/[email protected]

---
Viken Dadhaniya (2):
dt-bindings: i2c: Add Qualcomm I2C target controller
i2c: qcom-target: Add driver for Qualcomm I2C target controller

 .../bindings/i2c/qcom,qdu1000-i2c-target.yaml      |  75 +++
 MAINTAINERS                                        |   9 +
 drivers/i2c/busses/Kconfig                         |  15 +
 drivers/i2c/busses/Makefile                        |   1 +
 drivers/i2c/busses/i2c-qcom-target.c               | 638 +++++++++++++++++++++
 5 files changed, 738 insertions(+)

---
base-commit: bf1ee2bd5c2da8992f33c8950ef194aaff74ed6c
change-id: 20260628-i2c-qcom-slave-c382ff4e8691

Best regards,

Signature · 1 line
Viken Dadhaniya <[email protected]>
#1 lore raw

PATCH v5 1/2 dt-bindings: i2c: Add Qualcomm I2C target controller

QDU1000 and related Qualcomm SoCs include a dedicated I2C target controller that operates exclusively in target mode. It is a distinct IP from the Qualcomm I2C master controllers (GENI, QUP) with a different register interface, so it requires its own binding.

Document the MMIO region, interrupt, XO and AHB clocks, interconnect path, and optional pinctrl states for the controller.

---
 .../bindings/i2c/qcom,qdu1000-i2c-target.yaml      | 75 ++++++++++++++++++++++
 1 file changed, 75 insertions(+)
Documentation/devicetree/bindings/i2c/qcom,qdu1000-i2c-target.yaml new file +75 -0
new file mode 100644
index 000000000000..9a6b08f0ab0e
@@ -0,0 +1,75 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/qcom,qdu1000-i2c-target.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm I2C Target Controller
+
+maintainers:
+  - Mukesh Kumar Savaliya <[email protected]>
+  - Viken Dadhaniya <[email protected]>
+
+description:
+  Dedicated hardware IP found on Qualcomm SoCs that operates exclusively
+  as an I2C target (slave) device on the bus. Supports FIFO (PIO) mode
+  for data transfer.
+
+properties:
+  compatible:
+    enum:
+      - qcom,qdu1000-i2c-target
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: XO reference clock
+      - description: AHB bus clock
+
+  clock-names:
+    items:
+      - const: xo
+      - const: ahb
+
+  interconnects:
+    maxItems: 1
+
+  pinctrl-0: true
+  pinctrl-1: true
+
+  pinctrl-names:
+    minItems: 1
+    items:
+      - const: default
+      - const: sleep
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - interconnects
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/qcom,qdu1000-gcc.h>
+    #include <dt-bindings/interconnect/qcom,qdu1000-rpmh.h>
+
+    i2c@88ca000 {
+        compatible = "qcom,qdu1000-i2c-target";
+        reg = <0x88ca000 0x64>;
+        clocks = <&gcc GCC_SM_BUS_XO_CLK>, <&gcc GCC_SM_BUS_AHB_CLK>;
+        clock-names = "xo", "ahb";
+        interrupts = <GIC_SPI 358 IRQ_TYPE_LEVEL_HIGH>;
+        interconnects = <&gem_noc MASTER_APPSS_PROC 0 &config_noc SLAVE_SMBUS_CFG 0>;
+    };
+...
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 1/2] dt-bindings: i2c: Add Qualcomm I2C target controller

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dt-bindings: i2c: missing i2c-controller.yaml ref blocks child nodes --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dt-bindings: i2c: missing i2c-controller.yaml ref blocks child nodes --

commit 2517ccf310dd7ed641c5e449dcf2f13f3b127674
Author: Viken Dadhaniya <[email protected]>

dt-bindings: i2c: Add Qualcomm I2C target controller

This commit documents the device tree bindings for the dedicated I2C target controller hardware found on Qualcomm QDU1000 and related SoCs.

Quoted 5 lines
Documentation/devicetree/bindings/i2c/qcom,qdu1000-i2c-target.yaml new file +0 -0
new file mode 100644
index 0000000000000..9a6b08f0ab0e7

[ ... ]

Documentation/devicetree/bindings/i2c/qcom,qdu1000-i2c-target.yaml line 59

Quoted 9 lines
Documentation/devicetree/bindings/i2c/qcom,qdu1000-i2c-target.yaml new file +9 -0
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - interconnects
+
+additionalProperties: false

[Severity: Low]
Does using additionalProperties: false in Documentation/devicetree/bindings/i2c/qcom,qdu1000-i2c-target.yaml without inheriting from /schemas/i2c/i2c-controller.yaml# strictly reject standard I2C bus properties and forbid child nodes?

If a developer defines a static I2C target backend (such as slave-eeprom) as a child node of this controller in a device tree, it appears this regression would cause a dt_binding_check validation failure.

Quoted 2 lines
Documentation/devicetree/bindings/i2c/qcom,qdu1000-i2c-target.yaml new file +2 -0
+
+examples:

[ ... ]

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

PATCH v5 2/2 i2c: qcom-target: Add driver for Qualcomm I2C target controller

In reply to Viken Dadhaniya

QDU1000 and related Qualcomm SoCs include a dedicated I2C target controller that operates exclusively in target mode. The existing Qualcomm I2C controller drivers, GENI and QUP, are master-only and cannot serve systems where the SoC must respond as an I2C target on the bus.

Register the controller with the Linux I2C slave framework through i2c_algorithm.reg_slave and i2c_algorithm.unreg_slave. This allows standard slave backends, such as slave-24c02, to be attached at runtime through i2c_slave_register().

Handle IRQ events for RX FIFO service, clock stretching during read and write phases, STOP and repeated-start conditions, and error recovery through a software reset.

Enable the required AHB and XO clocks and vote for interconnect bandwidth. Restore the hardware state across system suspend and resume using regular system-sleep PM callbacks.

---
 MAINTAINERS                          |   9 +
 drivers/i2c/busses/Kconfig           |  15 +
 drivers/i2c/busses/Makefile          |   1 +
 drivers/i2c/busses/i2c-qcom-target.c | 638 +++++++++++++++++++++++++++++++++++
 4 files changed, 663 insertions(+)
MAINTAINERS +9 -0
index ff3bfd42d3f3..309c27d627ba 100644
@@ -22837,6 +22837,15 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/i2c/qcom,i2c-geni-qcom.yaml
 F:	drivers/i2c/busses/i2c-qcom-geni.c
 
+QUALCOMM I2C TARGET CONTROLLER DRIVER
+M:	Viken Dadhaniya <[email protected]>
+M:	Mukesh Kumar Savaliya <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/i2c/qcom,qdu1000-i2c-target.yaml
+F:	drivers/i2c/busses/i2c-qcom-target.c
+
 QUALCOMM I2C CCI DRIVER
 M:	Loic Poulain <[email protected]>
 M:	Robert Foss <[email protected]>
drivers/i2c/busses/Kconfig +15 -0
index 9d60d4b650ec..63428b16de7e 100644
@@ -1070,6 +1070,21 @@ config I2C_QCOM_GENI
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-qcom-geni.
 
+config I2C_QCOM_TARGET
+	tristate "Qualcomm I2C target controller"
+	depends on ARCH_QCOM || COMPILE_TEST
+	depends on COMMON_CLK
+	depends on INTERCONNECT
+	select I2C_SLAVE
+	help
+	  This driver supports I2C target mode on Qualcomm Technologies
+	  SoCs. If you say yes to this option, support will be included
+	  for the built-in I2C target controller on QDU1000 and other
+	  compatible Qualcomm SoCs.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called i2c-qcom-target.
+
 config I2C_QUP
 	tristate "Qualcomm QUP based I2C controller"
 	depends on ARCH_QCOM || COMPILE_TEST
drivers/i2c/busses/Makefile +1 -0
index 3755c54b3d82..ab3070cdb144 100644
@@ -101,6 +101,7 @@ obj-$(CONFIG_I2C_PXA)		+= i2c-pxa.o
 obj-$(CONFIG_I2C_PXA_PCI)	+= i2c-pxa-pci.o
 obj-$(CONFIG_I2C_QCOM_CCI)	+= i2c-qcom-cci.o
 obj-$(CONFIG_I2C_QCOM_GENI)	+= i2c-qcom-geni.o
+obj-$(CONFIG_I2C_QCOM_TARGET)	+= i2c-qcom-target.o
 obj-$(CONFIG_I2C_QUP)		+= i2c-qup.o
 obj-$(CONFIG_I2C_RIIC)		+= i2c-riic.o
 obj-$(CONFIG_I2C_RK3X)		+= i2c-rk3x.o
drivers/i2c/busses/i2c-qcom-target.c new file +638 -0

638 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH v5 2/2] i2c: qcom-target: Add driver for Qualcomm I2C target controller

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] i2c: incorrect IRQ handling order on repeated start - [High] i2c: infinite hardirq storm during…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] i2c: incorrect IRQ handling order on repeated start
- [High] i2c: infinite hardirq storm during unreg_target
- [Medium] i2c: missing WRITE_NACK state update on backend NACK
- [Medium] i2c: unbalanced disable_irq() on resume error path
--

commit 29b70e5539395d79b43b6b6c3ed75d84c373f1f3
Author: Viken Dadhaniya <[email protected]>

i2c: qcom-target: Add driver for Qualcomm I2C target controller

QDU1000 and related Qualcomm SoCs include a dedicated I2C target controller that operates exclusively in target mode. This commit adds a driver to register the controller with the Linux I2C slave framework and handles IRQ events, clock stretching, and error recovery.

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-target.c new file +0 -0
new file mode 100644
index 0000000000000..c72fca068f5e1
@@ -0,0 +1,638 @@

[ ... ]

Quoted 7 lines
drivers/i2c/busses/i2c-qcom-target.c new file +7 -0
+static void qcom_i2c_target_handle_rx_data(struct qcom_i2c_target *target,
+					   u32 rx_irq_bits)
+{
+	int ret;
+
+	dev_dbg(target->dev, "Rx data event (rx_irq_bits=0x%x)\n", rx_irq_bits);
+	ret = qcom_i2c_target_write_requested(target);

drivers/i2c/busses/i2c-qcom-target.c line 283

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-target.c new file +10 -0
+	if (ret || test_bit(WRITE_NACK, &target->status)) {
+		dev_dbg(target->dev, "Backend requested NACK\n");
+		writel(NACK | CLEAR_RX_FIFO, target->base + I2C_S_CONTROL);
+		writel(rx_irq_bits, target->base + I2C_S_IRQ_CLR);
+		return;
+	}
+
+	ret = qcom_i2c_target_drain_rx_fifo(target);
+	if (ret)
+		dev_dbg(target->dev, "Backend requested NACK\n");

[Severity: Medium]
Will this lead to extra data bytes from the RX FIFO being improperly fed to the backend after it has already returned an error (NACK)?

If the backend returns a non-zero value during I2C_SLAVE_WRITE_RECEIVED, qcom_i2c_target_handle_rx_data() correctly commands a NACK and clears the hardware FIFO, but fails to set the WRITE_NACK bit in target->status.

Then, when the STOP event arrives, qcom_i2c_target_handle_stop() incorrectly evaluates !test_bit(WRITE_NACK, &target->status) as true and attempts to drain the RX FIFO again.

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-target.c new file +5 -0
+
+	writel(ret ? NACK | CLEAR_RX_FIFO : ACK_RESUME,
+	       target->base + I2C_S_CONTROL);
+	writel(rx_irq_bits, target->base + I2C_S_IRQ_CLR);
+}

[ ... ]

Quoted 2 lines
drivers/i2c/busses/i2c-qcom-target.c new file +2 -0
+static irqreturn_t qcom_i2c_target_irq(int irq, void *dev)
+{

[ ... ]

drivers/i2c/busses/i2c-qcom-target.c line 341

Quoted 12 lines
drivers/i2c/busses/i2c-qcom-target.c new file +12 -0
+	/*
+	 * Load target->target once. Both reg_target() and unreg_target() disable
+	 * the IRQ before writing the pointer, so it cannot change while this
+	 * handler runs. Sub-handlers may dereference target->target directly.
+	 *
+	 * The core is enabled only in reg_target() and disabled in unreg_target(),
+	 * so no bus activity is expected here. Clear and discard any stale IRQ.
+	 */
+	if (!READ_ONCE(target->target)) {
+		writel(irq_stat, target->base + I2C_S_IRQ_CLR);
+		return IRQ_HANDLED;
+	}

[Severity: High]
Could this result in an infinite interrupt storm that locks up the CPU?

When target->target is set to NULL in qcom_i2c_target_unreg_target(), the hardware interrupt is left enabled because I2C_S_IRQ_EN is not cleared.

If a level-triggered interrupt condition like RX_DATA_AVAIL or RX_FIFO_FULL is active, this early-exit check clears the IRQ status register but does not drain the FIFO or disable the hardware interrupt enable. The hardware will immediately re-assert the interrupt, causing a continuous loop.

drivers/i2c/busses/i2c-qcom-target.c line 351

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-target.c new file +10 -0
+
+	if (irq_stat & (BIT(ERR_CONDITION) | BIT(CLOCK_LOW_TIMEOUT)))
+		return qcom_i2c_target_handle_error(target, irq_stat);
+
+	if (irq_stat & BIT(STOP_DETECTED))
+		return qcom_i2c_target_handle_stop(target, irq_stat);
+
+	if (irq_stat & BIT(RESTART_DETECTED)) {
+		dev_dbg(target->dev, "Repeated start bit detected\n");
+		target->status = 0;

[Severity: High]
Does this wipe the state too early, before the old RX data is processed?

In qcom_i2c_target_irq(), RESTART_DETECTED is checked and processed before rx_bits. If a repeated start and write-phase RX data are co-asserted in the same irq_stat snapshot, the state is wiped here before the trailing RX data is drained.

The subsequent drain incorrectly treats the old data as part of the new phase, and the backend receives I2C_SLAVE_WRITE_REQUESTED followed by old data from the previous phase, which scrambles the I2C backend state machine.

Quoted 8 lines
drivers/i2c/busses/i2c-qcom-target.c new file +8 -0
+		/*
+		 * Keep clock stretch asserted when STRCH_RD is co-asserted so
+		 * qcom_i2c_target_handle_strch_rd() can fill TX FIFO first.
+		 */
+		if (!(irq_stat & BIT(STRCH_RD)))
+			writel(ACK_RESUME, target->base + I2C_S_CONTROL);
+		writel(BIT(RESTART_DETECTED), target->base + I2C_S_IRQ_CLR);
+	}

[ ... ]

Quoted 2 lines
drivers/i2c/busses/i2c-qcom-target.c new file +2 -0
+static int __maybe_unused qcom_i2c_target_resume(struct device *dev)
+{

[ ... ]

drivers/i2c/busses/i2c-qcom-target.c line 538

Quoted 7 lines
drivers/i2c/busses/i2c-qcom-target.c new file +7 -0
+err_disable_ahb:
+	clk_disable_unprepare(target->ahb_clk);
+err_disable_xo:
+	clk_disable_unprepare(target->xo_clk);
+
+	return ret;
+}

[Severity: Medium]
Are we missing a call to re-enable the IRQ on this error path?

The suspend callback disables the IRQ, but this error path in resume returns without re-enabling it. This leaves the IRQ permanently disabled and the IRQ descriptor's depth counter unbalanced, which can trigger a WARN trace in the core IRQ subsystem.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Reviewed-by on v5 2/2
#5 lore raw

Re: [PATCH v5 2/2] i2c: qcom-target: Add driver for Qualcomm I2C target controller

In reply to Viken Dadhaniya
Quoted 15 lines · Viken Dadhaniya

QDU1000 and related Qualcomm SoCs include a dedicated I2C target controller that operates exclusively in target mode. The existing Qualcomm I2C controller drivers, GENI and QUP, are master-only and cannot serve systems where the SoC must respond as an I2C target on the bus.

Register the controller with the Linux I2C slave framework through i2c_algorithm.reg_slave and i2c_algorithm.unreg_slave. This allows standard slave backends, such as slave-24c02, to be attached at runtime through i2c_slave_register().

Handle IRQ events for RX FIFO service, clock stretching during read and write phases, STOP and repeated-start conditions, and error recovery through a software reset.

Quoted 6 lines

Enable the required AHB and XO clocks and vote for interconnect bandwidth. Restore the hardware state across system suspend and resume using regular system-sleep PM callbacks.

---