* [PATCH 0/3] i2c: add Ambarella IDC master for CV75
@ 2026-12-01 10:46 ` Long Zhao via B4 Relay
0 siblings, 0 replies; 9+ messages in thread
From: Long Zhao @ 2026-12-01 10:46 UTC (permalink / raw)
To: Andi Shyti, linux-i2c
Cc: Long Zhao, linux-kernel, Long Zhao, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, devicetree
Add the Ambarella I2C master binding and driver used on the CV75.
The driver supports standard, fast and fast-plus modes, 7-bit and
10-bit addressing, and repeated start.
Please take this series through the I2C tree. The CV75 SoC and DT
are already in linux-next; this series is the I2C binding and
driver only.
The SoC support, including ARCH_AMBARELLA and the RCT clock ID
header used by the binding example, is in the arm-soc immutable
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git/log/?h=ambarella/common
Tested on the CV75 EVK via the local cv75-mix branch: the board
boots with CONFIG_I2C_AMBARELLA=y and the four I2C controllers
probe.
To: Andi Shyti <andi.shyti@kernel.org>
To: linux-i2c@vger.kernel.org
Cc: Long Zhao <zl020895@163.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Long Zhao <longzhao@ambarella.com>
---
Long Zhao (3):
dt-bindings: i2c: add Ambarella IDC controller
i2c: ambarella: add IDC master for CV75
MAINTAINERS: add Ambarella I2C controller
.../bindings/i2c/ambarella,cv75-i2c.yaml | 63 +++
MAINTAINERS | 7 +
drivers/i2c/busses/Kconfig | 11 +
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-ambarella.c | 469 +++++++++++++++++++++
5 files changed, 551 insertions(+)
---
base-commit: 34cf6dafc47441dfb6b356a095b89c3585a93714
change-id: 20261124-cv75-i2c-a1b2c3d4e5f6
Best regards,
--
Long Zhao <longzhao@ambarella.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 0/3] i2c: add Ambarella IDC master for CV75
@ 2026-12-01 10:46 ` Long Zhao via B4 Relay
0 siblings, 0 replies; 9+ messages in thread
From: Long Zhao via B4 Relay @ 2026-12-01 10:46 UTC (permalink / raw)
To: Andi Shyti, linux-i2c
Cc: Long Zhao, linux-kernel, Long Zhao, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, devicetree
Add the Ambarella I2C master binding and driver used on the CV75.
The driver supports standard, fast and fast-plus modes, 7-bit and
10-bit addressing, and repeated start.
Please take this series through the I2C tree. The CV75 SoC and DT
are already in linux-next; this series is the I2C binding and
driver only.
The SoC support, including ARCH_AMBARELLA and the RCT clock ID
header used by the binding example, is in the arm-soc immutable
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git/log/?h=ambarella/common
Tested on the CV75 EVK via the local cv75-mix branch: the board
boots with CONFIG_I2C_AMBARELLA=y and the four I2C controllers
probe.
To: Andi Shyti <andi.shyti@kernel.org>
To: linux-i2c@vger.kernel.org
Cc: Long Zhao <zl020895@163.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Long Zhao <longzhao@ambarella.com>
---
Long Zhao (3):
dt-bindings: i2c: add Ambarella IDC controller
i2c: ambarella: add IDC master for CV75
MAINTAINERS: add Ambarella I2C controller
.../bindings/i2c/ambarella,cv75-i2c.yaml | 63 +++
MAINTAINERS | 7 +
drivers/i2c/busses/Kconfig | 11 +
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-ambarella.c | 469 +++++++++++++++++++++
5 files changed, 551 insertions(+)
---
base-commit: 34cf6dafc47441dfb6b356a095b89c3585a93714
change-id: 20261124-cv75-i2c-a1b2c3d4e5f6
Best regards,
--
Long Zhao <longzhao@ambarella.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] dt-bindings: i2c: add Ambarella IDC controller
2026-12-01 10:46 ` Long Zhao via B4 Relay
@ 2026-12-01 10:46 ` Long Zhao via B4 Relay
-1 siblings, 0 replies; 9+ messages in thread
From: Long Zhao @ 2026-12-01 10:46 UTC (permalink / raw)
To: Andi Shyti, linux-i2c
Cc: Long Zhao, linux-kernel, Long Zhao, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, devicetree
Document the Ambarella I2C master used on CV75. The compatible
is ambarella,cv75-i2c. clock-frequency is optional and accepts any
value from 1 kHz to 1 MHz (default 100 kHz).
Signed-off-by: Long Zhao <longzhao@ambarella.com>
---
Cc: Rob Herring <robh@kernel.org>
Cc: Krzysztof Kozlowski <krzk+dt@kernel.org>
Cc: Conor Dooley <conor+dt@kernel.org>
Cc: devicetree@vger.kernel.org
---
.../bindings/i2c/ambarella,cv75-i2c.yaml | 63 ++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/Documentation/devicetree/bindings/i2c/ambarella,cv75-i2c.yaml b/Documentation/devicetree/bindings/i2c/ambarella,cv75-i2c.yaml
new file mode 100644
index 000000000000..285525655dec
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/ambarella,cv75-i2c.yaml
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/ambarella,cv75-i2c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Ambarella I2C controller
+
+maintainers:
+ - Long Zhao <longzhao@ambarella.com>
+
+description:
+ Ambarella I2C master controller on media SoCs such as the CV75.
+ It supports standard, fast and fast-plus modes up to 1 MHz,
+ 7-bit and 10-bit addressing, and repeated start.
+ The controller input clock is the SoC APB clock (gclk_apb from the
+ RCT clock controller on CV75).
+
+allOf:
+ - $ref: /schemas/i2c/i2c-controller.yaml#
+
+properties:
+ compatible:
+ enum:
+ - ambarella,cv75-i2c
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+
+ clocks:
+ maxItems: 1
+ description:
+ SoC APB clock that drives the controller (CV75 gclk_apb).
+
+ clock-frequency:
+ description: Desired I2C bus clock frequency in Hz.
+ minimum: 1000
+ maximum: 1000000
+ default: 100000
+
+required:
+ - compatible
+ - reg
+ - interrupts
+ - clocks
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/clock/ambarella,cv75-rct.h>
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+ i2c@e4008000 {
+ compatible = "ambarella,cv75-i2c";
+ reg = <0xe4008000 0x1000>;
+ interrupts = <GIC_SPI 156 IRQ_TYPE_EDGE_RISING>;
+ clocks = <&rct CV75_GCLK_APB>;
+ clock-frequency = <100000>;
+ };
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 1/3] dt-bindings: i2c: add Ambarella IDC controller
@ 2026-12-01 10:46 ` Long Zhao via B4 Relay
0 siblings, 0 replies; 9+ messages in thread
From: Long Zhao via B4 Relay @ 2026-12-01 10:46 UTC (permalink / raw)
To: Andi Shyti, linux-i2c
Cc: Long Zhao, linux-kernel, Long Zhao, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, devicetree
From: Long Zhao <longzhao@ambarella.com>
Document the Ambarella I2C master used on CV75. The compatible
is ambarella,cv75-i2c. clock-frequency is optional and accepts any
value from 1 kHz to 1 MHz (default 100 kHz).
Signed-off-by: Long Zhao <longzhao@ambarella.com>
---
Cc: Rob Herring <robh@kernel.org>
Cc: Krzysztof Kozlowski <krzk+dt@kernel.org>
Cc: Conor Dooley <conor+dt@kernel.org>
Cc: devicetree@vger.kernel.org
---
.../bindings/i2c/ambarella,cv75-i2c.yaml | 63 ++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/Documentation/devicetree/bindings/i2c/ambarella,cv75-i2c.yaml b/Documentation/devicetree/bindings/i2c/ambarella,cv75-i2c.yaml
new file mode 100644
index 000000000000..285525655dec
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/ambarella,cv75-i2c.yaml
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/ambarella,cv75-i2c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Ambarella I2C controller
+
+maintainers:
+ - Long Zhao <longzhao@ambarella.com>
+
+description:
+ Ambarella I2C master controller on media SoCs such as the CV75.
+ It supports standard, fast and fast-plus modes up to 1 MHz,
+ 7-bit and 10-bit addressing, and repeated start.
+ The controller input clock is the SoC APB clock (gclk_apb from the
+ RCT clock controller on CV75).
+
+allOf:
+ - $ref: /schemas/i2c/i2c-controller.yaml#
+
+properties:
+ compatible:
+ enum:
+ - ambarella,cv75-i2c
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+
+ clocks:
+ maxItems: 1
+ description:
+ SoC APB clock that drives the controller (CV75 gclk_apb).
+
+ clock-frequency:
+ description: Desired I2C bus clock frequency in Hz.
+ minimum: 1000
+ maximum: 1000000
+ default: 100000
+
+required:
+ - compatible
+ - reg
+ - interrupts
+ - clocks
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/clock/ambarella,cv75-rct.h>
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+ i2c@e4008000 {
+ compatible = "ambarella,cv75-i2c";
+ reg = <0xe4008000 0x1000>;
+ interrupts = <GIC_SPI 156 IRQ_TYPE_EDGE_RISING>;
+ clocks = <&rct CV75_GCLK_APB>;
+ clock-frequency = <100000>;
+ };
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] i2c: ambarella: add IDC master for CV75
2026-12-01 10:46 ` Long Zhao via B4 Relay
@ 2026-12-01 10:46 ` Long Zhao via B4 Relay
-1 siblings, 0 replies; 9+ messages in thread
From: Long Zhao @ 2026-12-01 10:46 UTC (permalink / raw)
To: Andi Shyti, linux-i2c; +Cc: Long Zhao, linux-kernel, Long Zhao
Add a platform driver for the Ambarella I2C master. The transfer
path is an IRQ state machine with wait_for_completion. The APB clock
stays enabled for the lifetime of the device. Bus frequency comes
from clock-frequency and is clamped to 1 kHz .. 1 MHz.
Signed-off-by: Long Zhao <longzhao@ambarella.com>
---
drivers/i2c/busses/Kconfig | 11 +
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-ambarella.c | 469 +++++++++++++++++++++++++++++++++++++
3 files changed, 481 insertions(+)
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index d7b89508311f..11dfa070b530 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -405,6 +405,17 @@ config I2C_ALTERA
This driver can also be built as a module. If so, the module
will be called i2c-altera.
+config I2C_AMBARELLA
+ tristate "Ambarella I2C controller"
+ depends on ARCH_AMBARELLA || COMPILE_TEST
+ depends on OF
+ help
+ Say yes here to support the Ambarella I2C master
+ controller found on Ambarella media SoCs such as the CV75.
+
+ This driver can also be built as a module. If so, the module
+ will be called i2c-ambarella.
+
config I2C_ASPEED
tristate "Aspeed I2C Controller"
depends on ARCH_ASPEED || COMPILE_TEST
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 3755c54b3d82..a5b418008cce 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o
# Embedded system I2C/SMBus host controller drivers
obj-$(CONFIG_I2C_ALTERA) += i2c-altera.o
+obj-$(CONFIG_I2C_AMBARELLA) += i2c-ambarella.o
obj-$(CONFIG_I2C_AMD_MP2) += i2c-amd-mp2-pci.o i2c-amd-mp2-plat.o
obj-$(CONFIG_I2C_AMD_ASF) += i2c-amd-asf-plat.o
obj-$(CONFIG_I2C_ASPEED) += i2c-aspeed.o
diff --git a/drivers/i2c/busses/i2c-ambarella.c b/drivers/i2c/busses/i2c-ambarella.c
new file mode 100644
index 000000000000..99fed762c3ff
--- /dev/null
+++ b/drivers/i2c/busses/i2c-ambarella.c
@@ -0,0 +1,469 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/clk.h>
+#include <linux/completion.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/spinlock.h>
+#include <linux/string.h>
+#include <linux/types.h>
+
+#define IDC_ENR 0x00
+#define IDC_CTRL 0x04
+#define IDC_DATA 0x08
+#define IDC_STS 0x0c
+#define IDC_PSLL 0x10
+#define IDC_PSLH 0x14
+#define IDC_DUTYCYCLE 0x24
+#define IDC_STRETCHSCL 0x28
+
+#define IDC_ENR_ENABLE 0x01
+#define IDC_ENR_DISABLE 0x00
+
+#define IDC_CTRL_STOP 0x08
+#define IDC_CTRL_START 0x04
+#define IDC_CTRL_ACK 0x01
+#define IDC_CTRL_CLS 0x00
+
+#define IDC_STS_FIFO_EMP 0x04
+
+#define AMBARELLA_I2C_RETRIES 3
+
+#define AMBARELLA_I2C_STOP_WAIT_US 10
+#define AMBARELLA_I2C_STOP_TIMEOUT_US 500
+
+enum ambarella_i2c_state {
+ AMBA_I2C_STATE_IDLE,
+ AMBA_I2C_STATE_START,
+ AMBA_I2C_STATE_START_TEN,
+ AMBA_I2C_STATE_START_NEW,
+ AMBA_I2C_STATE_READ,
+ AMBA_I2C_STATE_READ_STOP,
+ AMBA_I2C_STATE_WRITE,
+ AMBA_I2C_STATE_WRITE_WAIT_ACK,
+ AMBA_I2C_STATE_NO_ACK,
+ AMBA_I2C_STATE_ERROR,
+};
+
+#define IDC_STS_HW_IDLE 0
+#define IDC_STS_HW_SHIFT 4
+#define IDC_STS_HW_MASK 0xf
+
+struct ambarella_i2c {
+ struct device *dev;
+ void __iomem *base;
+ struct clk *clk;
+
+ struct i2c_adapter adap;
+
+ struct i2c_msg *msgs;
+ struct completion complete;
+
+ spinlock_t lock; /* protects state and msg cursor */
+ enum ambarella_i2c_state state;
+ unsigned int num_msgs;
+ unsigned int msg_idx;
+ unsigned int bus_freq;
+ u16 addr_rw;
+};
+
+static bool ambarella_i2c_hw_idle(struct ambarella_i2c *i2c)
+{
+ u32 status = readl_relaxed(i2c->base + IDC_STS);
+
+ return ((status >> IDC_STS_HW_SHIFT) & IDC_STS_HW_MASK) ==
+ IDC_STS_HW_IDLE;
+}
+
+static void ambarella_i2c_disable(struct ambarella_i2c *i2c)
+{
+ writeb_relaxed(IDC_ENR_DISABLE, i2c->base + IDC_ENR);
+}
+
+static void ambarella_i2c_enable(struct ambarella_i2c *i2c)
+{
+ writeb_relaxed(IDC_ENR_ENABLE, i2c->base + IDC_ENR);
+}
+
+static void ambarella_i2c_set_freq(struct ambarella_i2c *i2c)
+{
+ unsigned long apb = clk_get_rate(i2c->clk);
+ u32 prescale = 0;
+ u8 duty;
+
+ ambarella_i2c_disable(i2c);
+
+ if (i2c->bus_freq <= I2C_MAX_STANDARD_MODE_FREQ)
+ duty = 0;
+ else
+ duty = 2;
+
+ if (apb >= (6UL + duty) * i2c->bus_freq)
+ prescale = ((apb / i2c->bus_freq) - 2) / (4 + duty) - 1;
+ else
+ dev_warn(i2c->dev,
+ "APB %lu Hz too low for %u Hz bus, using prescale 0\n",
+ apb, i2c->bus_freq);
+
+ writeb_relaxed(prescale & 0xff, i2c->base + IDC_PSLL);
+ writeb_relaxed((prescale >> 8) & 0xff, i2c->base + IDC_PSLH);
+ writeb_relaxed(duty, i2c->base + IDC_DUTYCYCLE);
+ writeb_relaxed(1, i2c->base + IDC_STRETCHSCL);
+
+ ambarella_i2c_enable(i2c);
+}
+
+static void ambarella_i2c_hw_init(struct ambarella_i2c *i2c)
+{
+ ambarella_i2c_set_freq(i2c);
+
+ scoped_guard(spinlock_irqsave, &i2c->lock) {
+ i2c->msgs = NULL;
+ i2c->num_msgs = 0;
+ i2c->state = AMBA_I2C_STATE_IDLE;
+ }
+}
+
+static void ambarella_i2c_stop(struct ambarella_i2c *i2c,
+ enum ambarella_i2c_state state, u32 *ctrl)
+{
+ if (state != AMBA_I2C_STATE_IDLE)
+ *ctrl |= IDC_CTRL_ACK;
+
+ i2c->state = state;
+ i2c->msgs = NULL;
+ i2c->num_msgs = 0;
+
+ *ctrl |= IDC_CTRL_STOP;
+
+ if (state == AMBA_I2C_STATE_IDLE || state == AMBA_I2C_STATE_NO_ACK)
+ complete(&i2c->complete);
+}
+
+static bool ambarella_i2c_check_ack(struct ambarella_i2c *i2c, u32 *ctrl,
+ unsigned int retries)
+{
+ if (!(*ctrl & IDC_CTRL_ACK))
+ return true;
+
+ if (i2c->msgs->flags & I2C_M_IGNORE_NAK)
+ return true;
+
+ if ((i2c->msgs->flags & I2C_M_RD) &&
+ (i2c->msgs->flags & I2C_M_NO_RD_ACK))
+ return true;
+
+ while ((*ctrl & IDC_CTRL_ACK) && retries--) {
+ udelay(100);
+ *ctrl = readl_relaxed(i2c->base + IDC_CTRL);
+ }
+
+ if (*ctrl & IDC_CTRL_ACK) {
+ *ctrl = IDC_CTRL_CLS;
+ ambarella_i2c_stop(i2c, AMBA_I2C_STATE_NO_ACK, ctrl);
+ return false;
+ }
+
+ return true;
+}
+
+static void ambarella_i2c_start_msg(struct ambarella_i2c *i2c)
+{
+ struct i2c_msg *msg = i2c->msgs;
+ u8 addr;
+
+ i2c->msg_idx = 0;
+ i2c->addr_rw = i2c_8bit_addr_from_msg(msg);
+ if (msg->flags & I2C_M_REV_DIR_ADDR)
+ i2c->addr_rw ^= 1;
+
+ if (msg->flags & I2C_M_TEN) {
+ i2c->state = AMBA_I2C_STATE_START_TEN;
+ addr = i2c_10bit_addr_hi_from_msg(msg);
+ if (msg->flags & I2C_M_REV_DIR_ADDR)
+ addr ^= I2C_M_RD;
+ writeb_relaxed(addr, i2c->base + IDC_DATA);
+ } else {
+ i2c->state = AMBA_I2C_STATE_START;
+ writeb_relaxed(i2c->addr_rw, i2c->base + IDC_DATA);
+ }
+
+ writel_relaxed(IDC_CTRL_START, i2c->base + IDC_CTRL);
+}
+
+static irqreturn_t ambarella_i2c_irq(int irq, void *dev_id)
+{
+ struct ambarella_i2c *i2c = dev_id;
+ u32 ack = IDC_CTRL_CLS;
+ u32 status;
+ u32 ctrl;
+
+ guard(spinlock)(&i2c->lock);
+
+ status = readl_relaxed(i2c->base + IDC_STS);
+ ctrl = readl_relaxed(i2c->base + IDC_CTRL);
+
+ switch (i2c->state) {
+ case AMBA_I2C_STATE_START:
+ if (!ambarella_i2c_check_ack(i2c, &ctrl, 1)) {
+ ack = ctrl;
+ break;
+ }
+
+ if (!i2c->msgs->len) {
+ ambarella_i2c_stop(i2c, AMBA_I2C_STATE_IDLE, &ack);
+ break;
+ }
+ if (i2c->msgs->flags & I2C_M_RD) {
+ if (i2c->msgs->len == 1)
+ ack |= IDC_CTRL_ACK;
+ i2c->state = AMBA_I2C_STATE_READ;
+ } else {
+ i2c->state = AMBA_I2C_STATE_WRITE;
+ writeb_relaxed(i2c->msgs->buf[i2c->msg_idx],
+ i2c->base + IDC_DATA);
+ i2c->state = AMBA_I2C_STATE_WRITE_WAIT_ACK;
+ }
+ break;
+
+ case AMBA_I2C_STATE_START_TEN:
+ i2c->state = AMBA_I2C_STATE_START;
+ writeb_relaxed(i2c_10bit_addr_lo_from_msg(i2c->msgs),
+ i2c->base + IDC_DATA);
+ break;
+
+ case AMBA_I2C_STATE_START_NEW:
+ ambarella_i2c_start_msg(i2c);
+ return IRQ_HANDLED;
+
+ case AMBA_I2C_STATE_READ:
+ i2c->msgs->buf[i2c->msg_idx] =
+ readb_relaxed(i2c->base + IDC_DATA);
+ i2c->msg_idx++;
+
+ if (i2c->msg_idx >= i2c->msgs->len - 1) {
+ if (i2c->num_msgs > 1) {
+ i2c->msgs++;
+ i2c->num_msgs--;
+ i2c->state = AMBA_I2C_STATE_START_NEW;
+ } else if (i2c->msg_idx > i2c->msgs->len - 1) {
+ ambarella_i2c_stop(i2c, AMBA_I2C_STATE_IDLE, &ack);
+ } else {
+ i2c->state = AMBA_I2C_STATE_READ_STOP;
+ ack |= IDC_CTRL_ACK;
+ }
+ }
+ break;
+
+ case AMBA_I2C_STATE_READ_STOP:
+ i2c->msgs->buf[i2c->msg_idx] =
+ readb_relaxed(i2c->base + IDC_DATA);
+ i2c->msg_idx++;
+ ambarella_i2c_stop(i2c, AMBA_I2C_STATE_IDLE, &ack);
+ break;
+
+ case AMBA_I2C_STATE_WRITE_WAIT_ACK:
+ if (!ambarella_i2c_check_ack(i2c, &ctrl, 1)) {
+ ack = ctrl;
+ break;
+ }
+ i2c->state = AMBA_I2C_STATE_WRITE;
+ i2c->msg_idx++;
+
+ if (i2c->msg_idx >= i2c->msgs->len) {
+ if (i2c->num_msgs > 1) {
+ i2c->msgs++;
+ i2c->num_msgs--;
+ i2c->state = AMBA_I2C_STATE_START_NEW;
+ ambarella_i2c_start_msg(i2c);
+ return IRQ_HANDLED;
+ }
+
+ ambarella_i2c_stop(i2c, AMBA_I2C_STATE_IDLE, &ack);
+ } else {
+ writeb_relaxed(i2c->msgs->buf[i2c->msg_idx],
+ i2c->base + IDC_DATA);
+ i2c->state = AMBA_I2C_STATE_WRITE_WAIT_ACK;
+ }
+ break;
+
+ default:
+ if ((status & IDC_STS_FIFO_EMP) &&
+ i2c->state == AMBA_I2C_STATE_IDLE)
+ return IRQ_HANDLED;
+
+ if ((status & IDC_STS_FIFO_EMP) &&
+ i2c->state == AMBA_I2C_STATE_NO_ACK) {
+ ack = IDC_CTRL_STOP | IDC_CTRL_ACK;
+ break;
+ }
+
+ dev_err(i2c->dev,
+ "irq in wrong state 0x%x, status 0x%x, control 0x%x\n",
+ i2c->state, status, ctrl);
+ ack = IDC_CTRL_STOP | IDC_CTRL_ACK;
+ i2c->state = AMBA_I2C_STATE_ERROR;
+ break;
+ }
+
+ writel_relaxed(ack, i2c->base + IDC_CTRL);
+ return IRQ_HANDLED;
+}
+
+static int ambarella_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
+ int num)
+{
+ struct ambarella_i2c *i2c = i2c_get_adapdata(adap);
+ enum ambarella_i2c_state state;
+ struct device *dev = i2c->dev;
+ unsigned long time_left;
+ bool hw_idle;
+ int wait;
+ int ret;
+
+ scoped_guard(spinlock_irqsave, &i2c->lock) {
+ reinit_completion(&i2c->complete);
+ i2c->msgs = msgs;
+ i2c->num_msgs = num;
+ i2c->state = AMBA_I2C_STATE_IDLE;
+ ambarella_i2c_start_msg(i2c);
+ }
+
+ time_left = wait_for_completion_timeout(&i2c->complete, adap->timeout);
+ if (!time_left) {
+ /*
+ * Abort the hung transfer and bounce the controller so the
+ * next xfer does not start from a stuck state machine.
+ */
+ scoped_guard(spinlock_irqsave, &i2c->lock) {
+ i2c->msgs = NULL;
+ i2c->num_msgs = 0;
+ ambarella_i2c_disable(i2c);
+ ambarella_i2c_enable(i2c);
+ i2c->state = AMBA_I2C_STATE_IDLE;
+ }
+ }
+
+ /*
+ * Wait for the controller to return to idle so a STOP is
+ * really on the bus before a mux switches the lines.
+ */
+ wait = read_poll_timeout(ambarella_i2c_hw_idle, hw_idle, hw_idle,
+ AMBARELLA_I2C_STOP_WAIT_US,
+ AMBARELLA_I2C_STOP_TIMEOUT_US, false, i2c);
+ if (wait)
+ dev_dbg(dev, "controller still busy after %u us\n",
+ AMBARELLA_I2C_STOP_TIMEOUT_US);
+
+ scoped_guard(spinlock_irqsave, &i2c->lock)
+ state = i2c->state;
+
+ if (!time_left)
+ ret = -ETIMEDOUT;
+ else if (state == AMBA_I2C_STATE_IDLE)
+ ret = num;
+ else if (state == AMBA_I2C_STATE_NO_ACK)
+ ret = -ENXIO;
+ else
+ ret = -ETIMEDOUT;
+
+ if (ret == -ENXIO)
+ dev_dbg(dev, "no ACK from address 0x%x\n", i2c->addr_rw >> 1);
+ else if (ret == -ETIMEDOUT)
+ dev_err(dev, "transfer timed out at address 0x%x\n", i2c->addr_rw >> 1);
+
+ return ret;
+}
+
+static u32 ambarella_i2c_func(struct i2c_adapter *adap)
+{
+ return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR | I2C_FUNC_SMBUS_EMUL |
+ I2C_FUNC_PROTOCOL_MANGLING;
+}
+
+static const struct i2c_algorithm ambarella_i2c_algo = {
+ .xfer = ambarella_i2c_xfer,
+ .functionality = ambarella_i2c_func,
+};
+
+static int ambarella_i2c_probe(struct platform_device *pdev)
+{
+ u32 freq = I2C_MAX_STANDARD_MODE_FREQ;
+ struct device *dev = &pdev->dev;
+ struct ambarella_i2c *i2c;
+ struct i2c_adapter *adap;
+ int ret;
+
+ i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL);
+ if (!i2c)
+ return -ENOMEM;
+
+ i2c->dev = dev;
+
+ i2c->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(i2c->base))
+ return PTR_ERR(i2c->base);
+
+ i2c->clk = devm_clk_get_enabled(dev, NULL);
+ if (IS_ERR(i2c->clk))
+ return dev_err_probe(dev, PTR_ERR(i2c->clk),
+ "failed to enable clock\n");
+
+ of_property_read_u32(dev->of_node, "clock-frequency", &freq);
+ i2c->bus_freq = clamp(freq, 1000u, I2C_MAX_FAST_MODE_PLUS_FREQ);
+
+ spin_lock_init(&i2c->lock);
+ init_completion(&i2c->complete);
+
+ ambarella_i2c_hw_init(i2c);
+
+ ret = platform_get_irq(pdev, 0);
+ if (ret < 0)
+ return ret;
+
+ ret = devm_request_irq(dev, ret, ambarella_i2c_irq, 0,
+ dev_name(dev), i2c);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to request irq\n");
+
+ adap = &i2c->adap;
+ i2c_set_adapdata(adap, i2c);
+ adap->owner = THIS_MODULE;
+ adap->dev.parent = dev;
+ adap->dev.of_node = dev->of_node;
+ strscpy(adap->name, "Ambarella I2C adapter", sizeof(adap->name));
+ adap->algo = &ambarella_i2c_algo;
+ adap->retries = AMBARELLA_I2C_RETRIES;
+
+ ret = devm_i2c_add_adapter(dev, adap);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to add i2c adapter\n");
+
+ return 0;
+}
+
+static const struct of_device_id ambarella_i2c_of_match[] = {
+ { .compatible = "ambarella,cv75-i2c" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, ambarella_i2c_of_match);
+
+static struct platform_driver ambarella_i2c_driver = {
+ .probe = ambarella_i2c_probe,
+ .driver = {
+ .name = "ambarella-i2c",
+ .of_match_table = ambarella_i2c_of_match,
+ },
+};
+module_platform_driver(ambarella_i2c_driver);
+
+MODULE_DESCRIPTION("Ambarella I2C master controller driver");
+MODULE_AUTHOR("Long Zhao <longzhao@ambarella.com>");
+MODULE_LICENSE("GPL");
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] i2c: ambarella: add IDC master for CV75
@ 2026-12-01 10:46 ` Long Zhao via B4 Relay
0 siblings, 0 replies; 9+ messages in thread
From: Long Zhao via B4 Relay @ 2026-12-01 10:46 UTC (permalink / raw)
To: Andi Shyti, linux-i2c; +Cc: Long Zhao, linux-kernel, Long Zhao
From: Long Zhao <longzhao@ambarella.com>
Add a platform driver for the Ambarella I2C master. The transfer
path is an IRQ state machine with wait_for_completion. The APB clock
stays enabled for the lifetime of the device. Bus frequency comes
from clock-frequency and is clamped to 1 kHz .. 1 MHz.
Signed-off-by: Long Zhao <longzhao@ambarella.com>
---
drivers/i2c/busses/Kconfig | 11 +
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-ambarella.c | 469 +++++++++++++++++++++++++++++++++++++
3 files changed, 481 insertions(+)
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index d7b89508311f..11dfa070b530 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -405,6 +405,17 @@ config I2C_ALTERA
This driver can also be built as a module. If so, the module
will be called i2c-altera.
+config I2C_AMBARELLA
+ tristate "Ambarella I2C controller"
+ depends on ARCH_AMBARELLA || COMPILE_TEST
+ depends on OF
+ help
+ Say yes here to support the Ambarella I2C master
+ controller found on Ambarella media SoCs such as the CV75.
+
+ This driver can also be built as a module. If so, the module
+ will be called i2c-ambarella.
+
config I2C_ASPEED
tristate "Aspeed I2C Controller"
depends on ARCH_ASPEED || COMPILE_TEST
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 3755c54b3d82..a5b418008cce 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o
# Embedded system I2C/SMBus host controller drivers
obj-$(CONFIG_I2C_ALTERA) += i2c-altera.o
+obj-$(CONFIG_I2C_AMBARELLA) += i2c-ambarella.o
obj-$(CONFIG_I2C_AMD_MP2) += i2c-amd-mp2-pci.o i2c-amd-mp2-plat.o
obj-$(CONFIG_I2C_AMD_ASF) += i2c-amd-asf-plat.o
obj-$(CONFIG_I2C_ASPEED) += i2c-aspeed.o
diff --git a/drivers/i2c/busses/i2c-ambarella.c b/drivers/i2c/busses/i2c-ambarella.c
new file mode 100644
index 000000000000..99fed762c3ff
--- /dev/null
+++ b/drivers/i2c/busses/i2c-ambarella.c
@@ -0,0 +1,469 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/clk.h>
+#include <linux/completion.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/spinlock.h>
+#include <linux/string.h>
+#include <linux/types.h>
+
+#define IDC_ENR 0x00
+#define IDC_CTRL 0x04
+#define IDC_DATA 0x08
+#define IDC_STS 0x0c
+#define IDC_PSLL 0x10
+#define IDC_PSLH 0x14
+#define IDC_DUTYCYCLE 0x24
+#define IDC_STRETCHSCL 0x28
+
+#define IDC_ENR_ENABLE 0x01
+#define IDC_ENR_DISABLE 0x00
+
+#define IDC_CTRL_STOP 0x08
+#define IDC_CTRL_START 0x04
+#define IDC_CTRL_ACK 0x01
+#define IDC_CTRL_CLS 0x00
+
+#define IDC_STS_FIFO_EMP 0x04
+
+#define AMBARELLA_I2C_RETRIES 3
+
+#define AMBARELLA_I2C_STOP_WAIT_US 10
+#define AMBARELLA_I2C_STOP_TIMEOUT_US 500
+
+enum ambarella_i2c_state {
+ AMBA_I2C_STATE_IDLE,
+ AMBA_I2C_STATE_START,
+ AMBA_I2C_STATE_START_TEN,
+ AMBA_I2C_STATE_START_NEW,
+ AMBA_I2C_STATE_READ,
+ AMBA_I2C_STATE_READ_STOP,
+ AMBA_I2C_STATE_WRITE,
+ AMBA_I2C_STATE_WRITE_WAIT_ACK,
+ AMBA_I2C_STATE_NO_ACK,
+ AMBA_I2C_STATE_ERROR,
+};
+
+#define IDC_STS_HW_IDLE 0
+#define IDC_STS_HW_SHIFT 4
+#define IDC_STS_HW_MASK 0xf
+
+struct ambarella_i2c {
+ struct device *dev;
+ void __iomem *base;
+ struct clk *clk;
+
+ struct i2c_adapter adap;
+
+ struct i2c_msg *msgs;
+ struct completion complete;
+
+ spinlock_t lock; /* protects state and msg cursor */
+ enum ambarella_i2c_state state;
+ unsigned int num_msgs;
+ unsigned int msg_idx;
+ unsigned int bus_freq;
+ u16 addr_rw;
+};
+
+static bool ambarella_i2c_hw_idle(struct ambarella_i2c *i2c)
+{
+ u32 status = readl_relaxed(i2c->base + IDC_STS);
+
+ return ((status >> IDC_STS_HW_SHIFT) & IDC_STS_HW_MASK) ==
+ IDC_STS_HW_IDLE;
+}
+
+static void ambarella_i2c_disable(struct ambarella_i2c *i2c)
+{
+ writeb_relaxed(IDC_ENR_DISABLE, i2c->base + IDC_ENR);
+}
+
+static void ambarella_i2c_enable(struct ambarella_i2c *i2c)
+{
+ writeb_relaxed(IDC_ENR_ENABLE, i2c->base + IDC_ENR);
+}
+
+static void ambarella_i2c_set_freq(struct ambarella_i2c *i2c)
+{
+ unsigned long apb = clk_get_rate(i2c->clk);
+ u32 prescale = 0;
+ u8 duty;
+
+ ambarella_i2c_disable(i2c);
+
+ if (i2c->bus_freq <= I2C_MAX_STANDARD_MODE_FREQ)
+ duty = 0;
+ else
+ duty = 2;
+
+ if (apb >= (6UL + duty) * i2c->bus_freq)
+ prescale = ((apb / i2c->bus_freq) - 2) / (4 + duty) - 1;
+ else
+ dev_warn(i2c->dev,
+ "APB %lu Hz too low for %u Hz bus, using prescale 0\n",
+ apb, i2c->bus_freq);
+
+ writeb_relaxed(prescale & 0xff, i2c->base + IDC_PSLL);
+ writeb_relaxed((prescale >> 8) & 0xff, i2c->base + IDC_PSLH);
+ writeb_relaxed(duty, i2c->base + IDC_DUTYCYCLE);
+ writeb_relaxed(1, i2c->base + IDC_STRETCHSCL);
+
+ ambarella_i2c_enable(i2c);
+}
+
+static void ambarella_i2c_hw_init(struct ambarella_i2c *i2c)
+{
+ ambarella_i2c_set_freq(i2c);
+
+ scoped_guard(spinlock_irqsave, &i2c->lock) {
+ i2c->msgs = NULL;
+ i2c->num_msgs = 0;
+ i2c->state = AMBA_I2C_STATE_IDLE;
+ }
+}
+
+static void ambarella_i2c_stop(struct ambarella_i2c *i2c,
+ enum ambarella_i2c_state state, u32 *ctrl)
+{
+ if (state != AMBA_I2C_STATE_IDLE)
+ *ctrl |= IDC_CTRL_ACK;
+
+ i2c->state = state;
+ i2c->msgs = NULL;
+ i2c->num_msgs = 0;
+
+ *ctrl |= IDC_CTRL_STOP;
+
+ if (state == AMBA_I2C_STATE_IDLE || state == AMBA_I2C_STATE_NO_ACK)
+ complete(&i2c->complete);
+}
+
+static bool ambarella_i2c_check_ack(struct ambarella_i2c *i2c, u32 *ctrl,
+ unsigned int retries)
+{
+ if (!(*ctrl & IDC_CTRL_ACK))
+ return true;
+
+ if (i2c->msgs->flags & I2C_M_IGNORE_NAK)
+ return true;
+
+ if ((i2c->msgs->flags & I2C_M_RD) &&
+ (i2c->msgs->flags & I2C_M_NO_RD_ACK))
+ return true;
+
+ while ((*ctrl & IDC_CTRL_ACK) && retries--) {
+ udelay(100);
+ *ctrl = readl_relaxed(i2c->base + IDC_CTRL);
+ }
+
+ if (*ctrl & IDC_CTRL_ACK) {
+ *ctrl = IDC_CTRL_CLS;
+ ambarella_i2c_stop(i2c, AMBA_I2C_STATE_NO_ACK, ctrl);
+ return false;
+ }
+
+ return true;
+}
+
+static void ambarella_i2c_start_msg(struct ambarella_i2c *i2c)
+{
+ struct i2c_msg *msg = i2c->msgs;
+ u8 addr;
+
+ i2c->msg_idx = 0;
+ i2c->addr_rw = i2c_8bit_addr_from_msg(msg);
+ if (msg->flags & I2C_M_REV_DIR_ADDR)
+ i2c->addr_rw ^= 1;
+
+ if (msg->flags & I2C_M_TEN) {
+ i2c->state = AMBA_I2C_STATE_START_TEN;
+ addr = i2c_10bit_addr_hi_from_msg(msg);
+ if (msg->flags & I2C_M_REV_DIR_ADDR)
+ addr ^= I2C_M_RD;
+ writeb_relaxed(addr, i2c->base + IDC_DATA);
+ } else {
+ i2c->state = AMBA_I2C_STATE_START;
+ writeb_relaxed(i2c->addr_rw, i2c->base + IDC_DATA);
+ }
+
+ writel_relaxed(IDC_CTRL_START, i2c->base + IDC_CTRL);
+}
+
+static irqreturn_t ambarella_i2c_irq(int irq, void *dev_id)
+{
+ struct ambarella_i2c *i2c = dev_id;
+ u32 ack = IDC_CTRL_CLS;
+ u32 status;
+ u32 ctrl;
+
+ guard(spinlock)(&i2c->lock);
+
+ status = readl_relaxed(i2c->base + IDC_STS);
+ ctrl = readl_relaxed(i2c->base + IDC_CTRL);
+
+ switch (i2c->state) {
+ case AMBA_I2C_STATE_START:
+ if (!ambarella_i2c_check_ack(i2c, &ctrl, 1)) {
+ ack = ctrl;
+ break;
+ }
+
+ if (!i2c->msgs->len) {
+ ambarella_i2c_stop(i2c, AMBA_I2C_STATE_IDLE, &ack);
+ break;
+ }
+ if (i2c->msgs->flags & I2C_M_RD) {
+ if (i2c->msgs->len == 1)
+ ack |= IDC_CTRL_ACK;
+ i2c->state = AMBA_I2C_STATE_READ;
+ } else {
+ i2c->state = AMBA_I2C_STATE_WRITE;
+ writeb_relaxed(i2c->msgs->buf[i2c->msg_idx],
+ i2c->base + IDC_DATA);
+ i2c->state = AMBA_I2C_STATE_WRITE_WAIT_ACK;
+ }
+ break;
+
+ case AMBA_I2C_STATE_START_TEN:
+ i2c->state = AMBA_I2C_STATE_START;
+ writeb_relaxed(i2c_10bit_addr_lo_from_msg(i2c->msgs),
+ i2c->base + IDC_DATA);
+ break;
+
+ case AMBA_I2C_STATE_START_NEW:
+ ambarella_i2c_start_msg(i2c);
+ return IRQ_HANDLED;
+
+ case AMBA_I2C_STATE_READ:
+ i2c->msgs->buf[i2c->msg_idx] =
+ readb_relaxed(i2c->base + IDC_DATA);
+ i2c->msg_idx++;
+
+ if (i2c->msg_idx >= i2c->msgs->len - 1) {
+ if (i2c->num_msgs > 1) {
+ i2c->msgs++;
+ i2c->num_msgs--;
+ i2c->state = AMBA_I2C_STATE_START_NEW;
+ } else if (i2c->msg_idx > i2c->msgs->len - 1) {
+ ambarella_i2c_stop(i2c, AMBA_I2C_STATE_IDLE, &ack);
+ } else {
+ i2c->state = AMBA_I2C_STATE_READ_STOP;
+ ack |= IDC_CTRL_ACK;
+ }
+ }
+ break;
+
+ case AMBA_I2C_STATE_READ_STOP:
+ i2c->msgs->buf[i2c->msg_idx] =
+ readb_relaxed(i2c->base + IDC_DATA);
+ i2c->msg_idx++;
+ ambarella_i2c_stop(i2c, AMBA_I2C_STATE_IDLE, &ack);
+ break;
+
+ case AMBA_I2C_STATE_WRITE_WAIT_ACK:
+ if (!ambarella_i2c_check_ack(i2c, &ctrl, 1)) {
+ ack = ctrl;
+ break;
+ }
+ i2c->state = AMBA_I2C_STATE_WRITE;
+ i2c->msg_idx++;
+
+ if (i2c->msg_idx >= i2c->msgs->len) {
+ if (i2c->num_msgs > 1) {
+ i2c->msgs++;
+ i2c->num_msgs--;
+ i2c->state = AMBA_I2C_STATE_START_NEW;
+ ambarella_i2c_start_msg(i2c);
+ return IRQ_HANDLED;
+ }
+
+ ambarella_i2c_stop(i2c, AMBA_I2C_STATE_IDLE, &ack);
+ } else {
+ writeb_relaxed(i2c->msgs->buf[i2c->msg_idx],
+ i2c->base + IDC_DATA);
+ i2c->state = AMBA_I2C_STATE_WRITE_WAIT_ACK;
+ }
+ break;
+
+ default:
+ if ((status & IDC_STS_FIFO_EMP) &&
+ i2c->state == AMBA_I2C_STATE_IDLE)
+ return IRQ_HANDLED;
+
+ if ((status & IDC_STS_FIFO_EMP) &&
+ i2c->state == AMBA_I2C_STATE_NO_ACK) {
+ ack = IDC_CTRL_STOP | IDC_CTRL_ACK;
+ break;
+ }
+
+ dev_err(i2c->dev,
+ "irq in wrong state 0x%x, status 0x%x, control 0x%x\n",
+ i2c->state, status, ctrl);
+ ack = IDC_CTRL_STOP | IDC_CTRL_ACK;
+ i2c->state = AMBA_I2C_STATE_ERROR;
+ break;
+ }
+
+ writel_relaxed(ack, i2c->base + IDC_CTRL);
+ return IRQ_HANDLED;
+}
+
+static int ambarella_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
+ int num)
+{
+ struct ambarella_i2c *i2c = i2c_get_adapdata(adap);
+ enum ambarella_i2c_state state;
+ struct device *dev = i2c->dev;
+ unsigned long time_left;
+ bool hw_idle;
+ int wait;
+ int ret;
+
+ scoped_guard(spinlock_irqsave, &i2c->lock) {
+ reinit_completion(&i2c->complete);
+ i2c->msgs = msgs;
+ i2c->num_msgs = num;
+ i2c->state = AMBA_I2C_STATE_IDLE;
+ ambarella_i2c_start_msg(i2c);
+ }
+
+ time_left = wait_for_completion_timeout(&i2c->complete, adap->timeout);
+ if (!time_left) {
+ /*
+ * Abort the hung transfer and bounce the controller so the
+ * next xfer does not start from a stuck state machine.
+ */
+ scoped_guard(spinlock_irqsave, &i2c->lock) {
+ i2c->msgs = NULL;
+ i2c->num_msgs = 0;
+ ambarella_i2c_disable(i2c);
+ ambarella_i2c_enable(i2c);
+ i2c->state = AMBA_I2C_STATE_IDLE;
+ }
+ }
+
+ /*
+ * Wait for the controller to return to idle so a STOP is
+ * really on the bus before a mux switches the lines.
+ */
+ wait = read_poll_timeout(ambarella_i2c_hw_idle, hw_idle, hw_idle,
+ AMBARELLA_I2C_STOP_WAIT_US,
+ AMBARELLA_I2C_STOP_TIMEOUT_US, false, i2c);
+ if (wait)
+ dev_dbg(dev, "controller still busy after %u us\n",
+ AMBARELLA_I2C_STOP_TIMEOUT_US);
+
+ scoped_guard(spinlock_irqsave, &i2c->lock)
+ state = i2c->state;
+
+ if (!time_left)
+ ret = -ETIMEDOUT;
+ else if (state == AMBA_I2C_STATE_IDLE)
+ ret = num;
+ else if (state == AMBA_I2C_STATE_NO_ACK)
+ ret = -ENXIO;
+ else
+ ret = -ETIMEDOUT;
+
+ if (ret == -ENXIO)
+ dev_dbg(dev, "no ACK from address 0x%x\n", i2c->addr_rw >> 1);
+ else if (ret == -ETIMEDOUT)
+ dev_err(dev, "transfer timed out at address 0x%x\n", i2c->addr_rw >> 1);
+
+ return ret;
+}
+
+static u32 ambarella_i2c_func(struct i2c_adapter *adap)
+{
+ return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR | I2C_FUNC_SMBUS_EMUL |
+ I2C_FUNC_PROTOCOL_MANGLING;
+}
+
+static const struct i2c_algorithm ambarella_i2c_algo = {
+ .xfer = ambarella_i2c_xfer,
+ .functionality = ambarella_i2c_func,
+};
+
+static int ambarella_i2c_probe(struct platform_device *pdev)
+{
+ u32 freq = I2C_MAX_STANDARD_MODE_FREQ;
+ struct device *dev = &pdev->dev;
+ struct ambarella_i2c *i2c;
+ struct i2c_adapter *adap;
+ int ret;
+
+ i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL);
+ if (!i2c)
+ return -ENOMEM;
+
+ i2c->dev = dev;
+
+ i2c->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(i2c->base))
+ return PTR_ERR(i2c->base);
+
+ i2c->clk = devm_clk_get_enabled(dev, NULL);
+ if (IS_ERR(i2c->clk))
+ return dev_err_probe(dev, PTR_ERR(i2c->clk),
+ "failed to enable clock\n");
+
+ of_property_read_u32(dev->of_node, "clock-frequency", &freq);
+ i2c->bus_freq = clamp(freq, 1000u, I2C_MAX_FAST_MODE_PLUS_FREQ);
+
+ spin_lock_init(&i2c->lock);
+ init_completion(&i2c->complete);
+
+ ambarella_i2c_hw_init(i2c);
+
+ ret = platform_get_irq(pdev, 0);
+ if (ret < 0)
+ return ret;
+
+ ret = devm_request_irq(dev, ret, ambarella_i2c_irq, 0,
+ dev_name(dev), i2c);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to request irq\n");
+
+ adap = &i2c->adap;
+ i2c_set_adapdata(adap, i2c);
+ adap->owner = THIS_MODULE;
+ adap->dev.parent = dev;
+ adap->dev.of_node = dev->of_node;
+ strscpy(adap->name, "Ambarella I2C adapter", sizeof(adap->name));
+ adap->algo = &ambarella_i2c_algo;
+ adap->retries = AMBARELLA_I2C_RETRIES;
+
+ ret = devm_i2c_add_adapter(dev, adap);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to add i2c adapter\n");
+
+ return 0;
+}
+
+static const struct of_device_id ambarella_i2c_of_match[] = {
+ { .compatible = "ambarella,cv75-i2c" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, ambarella_i2c_of_match);
+
+static struct platform_driver ambarella_i2c_driver = {
+ .probe = ambarella_i2c_probe,
+ .driver = {
+ .name = "ambarella-i2c",
+ .of_match_table = ambarella_i2c_of_match,
+ },
+};
+module_platform_driver(ambarella_i2c_driver);
+
+MODULE_DESCRIPTION("Ambarella I2C master controller driver");
+MODULE_AUTHOR("Long Zhao <longzhao@ambarella.com>");
+MODULE_LICENSE("GPL");
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] MAINTAINERS: add Ambarella I2C controller
2026-12-01 10:46 ` Long Zhao via B4 Relay
@ 2026-12-01 10:46 ` Long Zhao via B4 Relay
-1 siblings, 0 replies; 9+ messages in thread
From: Long Zhao @ 2026-12-01 10:46 UTC (permalink / raw)
To: Andi Shyti, linux-i2c; +Cc: Long Zhao, linux-kernel, Long Zhao
Add a Maintained entry for the Ambarella I2C binding and driver.
Signed-off-by: Long Zhao <longzhao@ambarella.com>
---
MAINTAINERS | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 803b60ad628f..3263bc179ae4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1017,6 +1017,13 @@ Q: https://patchwork.kernel.org/project/linux-rdma/list/
F: drivers/infiniband/hw/efa/
F: include/uapi/rdma/efa-abi.h
+AMBARELLA I2C CONTROLLER DRIVER
+M: Long Zhao <longzhao@ambarella.com>
+L: linux-i2c@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/i2c/ambarella,cv75-i2c.yaml
+F: drivers/i2c/busses/i2c-ambarella.c
+
AMD 3D V-CACHE PERFORMANCE OPTIMIZER DRIVER
M: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
R: Mario Limonciello <mario.limonciello@amd.com>
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] MAINTAINERS: add Ambarella I2C controller
@ 2026-12-01 10:46 ` Long Zhao via B4 Relay
0 siblings, 0 replies; 9+ messages in thread
From: Long Zhao via B4 Relay @ 2026-12-01 10:46 UTC (permalink / raw)
To: Andi Shyti, linux-i2c; +Cc: Long Zhao, linux-kernel, Long Zhao
From: Long Zhao <longzhao@ambarella.com>
Add a Maintained entry for the Ambarella I2C binding and driver.
Signed-off-by: Long Zhao <longzhao@ambarella.com>
---
MAINTAINERS | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 803b60ad628f..3263bc179ae4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1017,6 +1017,13 @@ Q: https://patchwork.kernel.org/project/linux-rdma/list/
F: drivers/infiniband/hw/efa/
F: include/uapi/rdma/efa-abi.h
+AMBARELLA I2C CONTROLLER DRIVER
+M: Long Zhao <longzhao@ambarella.com>
+L: linux-i2c@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/i2c/ambarella,cv75-i2c.yaml
+F: drivers/i2c/busses/i2c-ambarella.c
+
AMD 3D V-CACHE PERFORMANCE OPTIMIZER DRIVER
M: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
R: Mario Limonciello <mario.limonciello@amd.com>
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] dt-bindings: i2c: add Ambarella IDC controller
2026-12-01 10:46 ` Long Zhao via B4 Relay
(?)
@ 2026-12-01 10:56 ` sashiko-bot
-1 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-01 10:56 UTC (permalink / raw)
To: Long Zhao; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] dt-bindings: i2c: ambarella,cv75-i2c: missing
ambarella,cv75-rct.h header
- [Low] dt-bindings: i2c: ambarella,cv75-i2c: interrupts listed before
clocks
- [Low] dt-bindings: i2c: ambarella,cv75-i2c: undocumented ambarella
vendor prefix
--
commit 10b02ab07af3011c549ab6187e63cc6723edbba9
Author: Long Zhao <longzhao@ambarella.com>
dt-bindings: i2c: add Ambarella IDC controller
This commit adds a Device Tree binding schema for the Ambarella CV75 I2C
master controller.
> diff --git a/Documentation/devicetree/bindings/i2c/ambarella,cv75-i2c.yaml b/Documentation/devicetree/bindings/i2c/ambarella,cv75-i2c.yaml
> new file mode 100644
> index 0000000000000..285525655dec7
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/i2c/ambarella,cv75-i2c.yaml
> @@ -0,0 +1,63 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/i2c/ambarella,cv75-i2c.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Ambarella I2C controller
> +
> +maintainers:
> + - Long Zhao <longzhao@ambarella.com>
> +
> +description:
> + Ambarella I2C master controller on media SoCs such as the CV75.
> + It supports standard, fast and fast-plus modes up to 1 MHz,
> + 7-bit and 10-bit addressing, and repeated start.
> + The controller input clock is the SoC APB clock (gclk_apb from the
> + RCT clock controller on CV75).
> +
> +allOf:
> + - $ref: /schemas/i2c/i2c-controller.yaml#
> +
> +properties:
> + compatible:
> + enum:
> + - ambarella,cv75-i2c
[Severity: Low]
Is the ambarella vendor prefix documented in
Documentation/devicetree/bindings/vendor-prefixes.yaml? Without an entry
there, checkpatch.pl and DT schema checks report ambarella,cv75-i2c as an
undocumented vendor prefix.
> +
> + reg:
> + maxItems: 1
> +
> + interrupts:
> + maxItems: 1
> +
> + clocks:
> + maxItems: 1
> + description:
> + SoC APB clock that drives the controller (CV75 gclk_apb).
> +
> + clock-frequency:
> + description: Desired I2C bus clock frequency in Hz.
> + minimum: 1000
> + maximum: 1000000
> + default: 100000
> +
> +required:
> + - compatible
> + - reg
> + - interrupts
> + - clocks
> +
> +unevaluatedProperties: false
> +
> +examples:
> + - |
> + #include <dt-bindings/clock/ambarella,cv75-rct.h>
> + #include <dt-bindings/interrupt-controller/arm-gic.h>
> +
> + i2c@e4008000 {
> + compatible = "ambarella,cv75-i2c";
> + reg = <0xe4008000 0x1000>;
> + interrupts = <GIC_SPI 156 IRQ_TYPE_EDGE_RISING>;
> + clocks = <&rct CV75_GCLK_APB>;
[Severity: Medium]
Does this example build with make dt_binding_check?
include/dt-bindings/clock/ambarella,cv75-rct.h and CV75_GCLK_APB are not
present in the tree, so preprocessing the example fails with a missing
header error.
> + clock-frequency = <100000>;
> + };
[Severity: Low]
This isn't a bug, but interrupts is listed before clocks in properties,
required, and the example node, whereas standard DT binding property order
places clocks before interrupts.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-cv75-i2c-v1-0-729176f61836@ambarella.com?part=1
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-01 10:56 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 10:46 [PATCH 0/3] i2c: add Ambarella IDC master for CV75 Long Zhao
2026-12-01 10:46 ` Long Zhao via B4 Relay
2026-12-01 10:46 ` [PATCH 1/3] dt-bindings: i2c: add Ambarella IDC controller Long Zhao
2026-12-01 10:46 ` Long Zhao via B4 Relay
2026-12-01 10:56 ` sashiko-bot
2026-12-01 10:46 ` [PATCH 2/3] i2c: ambarella: add IDC master for CV75 Long Zhao
2026-12-01 10:46 ` Long Zhao via B4 Relay
2026-12-01 10:46 ` [PATCH 3/3] MAINTAINERS: add Ambarella I2C controller Long Zhao
2026-12-01 10:46 ` Long Zhao via B4 Relay
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.