Skip to contentSkip to conversation

i2c: Add Cortina Systems CS75xx I2C controller driver

PATCH Superseded Fil Dunsky 2 participants 4 messages Nov 20

Subsystems (2)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Fil Dunsky

author
#0 lore raw

v5 cover i2c: Add Cortina Systems CS75xx I2C controller driver

The I2C ("Bi-Wire") controller of the Cortina Systems CS75xx ("Goldengate G2") SoCs transfers one byte per command, with a command register much like the OpenCores one, and raises an interrupt when a command has completed. This series adds the binding and a driver for plain I2C and emulated SMBus, without quick commands (every message carries at least one data byte) and without 10-bit addresses.

The driver used to be part of a series with the interrupt controller, GPIO and watchdog drivers and the device tree changes. That series is now split per subsystem. The driver depends on OF and HAS_IOMEM and has no dependency on the platform series [1], which is under review separately. The device tree nodes will follow with the other CS75xx dts changes once the platform is merged.

There is no public documentation; the register layout comes from the GPL vendor kernels. Tested on a Securifi Almond+ (CS7542) with the SX8650 touchscreen controller at 0x48: reads are ACKed, an empty address returns -ENXIO without timeouts. The v5 late-interrupt change was checked with a host regression test of the transfer state machine; it has not been exercised on the board. Repeated START between messages has not been exercised on the board.

[1] https://lore.kernel.org/all/[email protected]/

---
Changes in v5:
- replace the dependency on ARCH_CORTINA_ACCESS || COMPILE_TEST with OF, retaining HAS_IOMEM, so the driver can be merged without the platform
- build built-in and modular on ARM and x86-64 with COMPILE_TEST=n, without the platform series
- ignore a late interrupt of a timed out transfer before looking at the arbitration lost bit (sashiko-bot)
- Link to v4: https://patch.msgid.link/[email protected]

Changes in v4:
- rebase on v7.4-rc1
- split out of "Cortina Systems CS75xx: interrupt controller, GPIO, I2C and TWD watchdog" so that each driver can go through its own tree; no longer based on the platform series
- binding: limit clock-frequency to 400 kHz instead of listing 100 and
400 kHz, which is what the driver accepts; I kept Rob's Reviewed-by
from v3 for this one-line change
- collect Reviewed-by tags
- use fsleep() and device_set_node(); sort the Kconfig and Makefile entries
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- rebase on v6 of the platform series
- reset the controller with its interrupt disabled, check the prescaler against the field width exactly, wait for a bus held by another master up to the adapter timeout (sashiko-bot)
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- rebase on v5 of the platform series
- do not include <linux/mod_devicetable.h> (Uwe)
- complete a failed transfer only once its stop condition is done, so
that the stop interrupt cannot race with the next transfer; take the lock over the whole interrupt handler; report a NACK of the last byte
of a write; enable the interrupt again after a reset on timeout; fail with -EBUSY when the bus stays busy (sashiko-bot)
- Link to v1: https://patch.msgid.link/[email protected]

To: Andi Shyti <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Fil Dunsky (2):
dt-bindings: i2c: Add Cortina Systems CS7542 I2C controller
i2c: Add Cortina Systems CS75xx I2C controller driver

 .../bindings/i2c/cortina,cs7542-i2c.yaml           |  56 +++
 drivers/i2c/busses/Kconfig                         |  11 +
 drivers/i2c/busses/Makefile                        |   1 +
 drivers/i2c/busses/i2c-cs75xx.c                    | 394 +++++++++++++++++++++
 4 files changed, 462 insertions(+)

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261015-cs75xx-i2c-944d27231b4c

Best regards,

Signature · 1 line
Fil Dunsky <[email protected]>
author
#1 lore raw

PATCH v5 1/2 dt-bindings: i2c: Add Cortina Systems CS7542 I2C controller

Add a binding for the I2C ("Bi-Wire") controller of the Cortina Systems CS75xx SoCs.

---
 .../bindings/i2c/cortina,cs7542-i2c.yaml           | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)
Documentation/devicetree/bindings/i2c/cortina,cs7542-i2c.yaml new file +56 -0
new file mode 100644
index 000000000..095e24379
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/cortina,cs7542-i2c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cortina Systems CS7542 I2C controller
+
+maintainers:
+  - Fil Dunsky <[email protected]>
+
+description:
+  The I2C ("Bi-Wire") controller of the Cortina Systems CS75xx (Goldengate
+  G2) SoCs. It transfers one byte per command and runs from the peripheral
+  (APB) clock through a 16-bit prescaler.
+
+allOf:
+  - $ref: /schemas/i2c/i2c-controller.yaml#
+
+properties:
+  compatible:
+    const: cortina,cs7542-i2c
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-frequency:
+    maximum: 400000
+    default: 100000
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c@f00700e8 {
+        compatible = "cortina,cs7542-i2c";
+        reg = <0xf00700e8 0x28>;
+        interrupt-parent = <&intc>;
+        interrupts = <11>;
+        clocks = <&apb_clk>;
+        clock-frequency = <400000>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+    };
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH v5 2/2 i2c: Add Cortina Systems CS75xx I2C controller driver

In reply to Fil Dunsky

The I2C ("Bi-Wire") controller of the Cortina Systems CS75xx SoCs transfers one byte per command, with a command register much like the OpenCores one (start, stop, read, write, acknowledge), and raises an interrupt when a command has completed.

Messages are sent with a repeated start between them and a stop after the last one. Every message needs at least one data byte, so SMBus quick commands are not supported. Arbitration loss is reported as -EAGAIN and retried by the core.

The driver depends on OF and HAS_IOMEM and uses generic platform and I2C APIs, so it can be enabled without the CS75xx platform series.

---
 drivers/i2c/busses/Kconfig      |  11 ++
 drivers/i2c/busses/Makefile     |   1 +
 drivers/i2c/busses/i2c-cs75xx.c | 394 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 406 insertions(+)
drivers/i2c/busses/Kconfig +11 -0
index 275aaa7f3..1bebffc7d 100644
@@ -550,6 +550,17 @@ config I2C_CPM
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-cpm.
 
+config I2C_CS75XX
+	tristate "Cortina Systems CS75xx I2C controller"
+	depends on OF
+	depends on HAS_IOMEM
+	help
+	  Say yes here to support the I2C ("Bi-Wire") controller of the
+	  Cortina Systems CS75xx SoCs.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called i2c-cs75xx.
+
 config I2C_DAVINCI
 	tristate "DaVinci I2C driver"
 	depends on ARCH_DAVINCI || ARCH_KEYSTONE || COMPILE_TEST
drivers/i2c/busses/Makefile +1 -0
index e5440de0f..f19df25eb 100644
@@ -49,6 +49,7 @@ obj-$(CONFIG_I2C_CADENCE)	+= i2c-cadence.o
 obj-$(CONFIG_I2C_CBUS_GPIO)	+= i2c-cbus-gpio.o
 obj-$(CONFIG_I2C_CGBC)		+= i2c-cgbc.o
 obj-$(CONFIG_I2C_CPM)		+= i2c-cpm.o
+obj-$(CONFIG_I2C_CS75XX)	+= i2c-cs75xx.o
 obj-$(CONFIG_I2C_DAVINCI)	+= i2c-davinci.o
 obj-$(CONFIG_I2C_DESIGNWARE_CORE)			+= i2c-designware-core.o
 i2c-designware-core-y					:= i2c-designware-common.o
drivers/i2c/busses/i2c-cs75xx.c new file +394 -0

394 lines not on this page · raw message

Signature · 1 line
2.53.0
#3 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] i2c: cs75xx: unused CS75XX_I2C_CTRL_DONE macro in cs75xx_i2c_isr() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] i2c: cs75xx: unused CS75XX_I2C_CTRL_DONE macro in cs75xx_i2c_isr()
--

commit 3aed5f86a535b38a31abe106e39e42d273af7fd9
Author: Fil Dunsky <[email protected]>

i2c: Add Cortina Systems CS75xx I2C controller driver

This commit adds an I2C bus driver for the byte-oriented Bi-Wire controller on Cortina Systems CS75xx SoCs.

Quoted 6 lines
drivers/i2c/busses/i2c-cs75xx.c new file +0 -0
new file mode 100644
index 0000000000000..69e4c9b01d15f
@@ -0,0 +1,394 @@

[ ... ]

Quoted 6 lines
drivers/i2c/busses/i2c-cs75xx.c new file +6 -0
+#define CS75XX_I2C_CTRL_DONE	BIT(0)
+#define CS75XX_I2C_CTRL_NACK	BIT(3)
+#define CS75XX_I2C_CTRL_WRITE	BIT(4)
+#define CS75XX_I2C_CTRL_READ	BIT(5)
+#define CS75XX_I2C_CTRL_STOP	BIT(6)
+#define CS75XX_I2C_CTRL_START	BIT(7)

[ ... ]

Quoted 5 lines
drivers/i2c/busses/i2c-cs75xx.c new file +5 -0
+static irqreturn_t cs75xx_i2c_isr(int irq, void *dev_id)
+{
+	struct cs75xx_i2c *i2c = dev_id;
+	u32 ctrl, ack;
+

drivers/i2c/busses/i2c-cs75xx.c line 212

Quoted 10 lines
drivers/i2c/busses/i2c-cs75xx.c new file +10 -0
+	guard(spinlock)(&i2c->lock);
+
+	if (!(readl(i2c->base + CS75XX_I2C_INT) & CS75XX_I2C_INT_DONE))
+		return IRQ_NONE;
+
+	writel(CS75XX_I2C_INT_DONE, i2c->base + CS75XX_I2C_INT);
+
+	/* The done flag is cleared by writing it back */
+	ctrl = readl(i2c->base + CS75XX_I2C_CTRL);
+	writel(ctrl, i2c->base + CS75XX_I2C_CTRL);

[Severity: Low]
Should this write CS75XX_I2C_CTRL_DONE to CS75XX_I2C_CTRL instead of writing back the full ctrl value? CS75XX_I2C_CTRL_DONE is defined above but never used, and writing the whole register back could re-assert any control bits in CS75XX_I2C_CTRL that do not self-clear.

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