Skip to contentSkip to conversation

Turris Omnia MCU driver

PATCH Superseded Marek Behún 2 participants 10 messages Aug 23, 2023 – Aug 24, 2023

Subsystems (3)

v1 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Marek Behún

author maintainer
#0 lore raw

cover Turris Omnia MCU driver

Hello Arnd, Gregory,

this series adds support for the MCU provided features on Turris Omnia:
- board poweroff and wakeup (via rtcwake),
- MCU watchdog,
- GPIOs and interrupts.

The first two parts are simple enough.

The GPIOs and interrupts part is a little bit more complicated because boards with newer MCU firmware support new interrupt reading API, but I wanted to also add support for older MCU firmwares, for users who do not use our system and won't get automatic upgrade to newer version.

There are 4 patches:
- 1st adds device-tree binding,
- 2nd adds the driver proper,
- 3rd and 4th add nodes to Omnia's device tree.

The driver is added to the drivers/platform/cznic directory.

Gregory, could you give ack/review for the device-tree patches so that they can be merged with the series if everything else is ok?

Marek

Marek Behún (4):
dt-bindings: arm: add cznic,turris-omnia-mcu binding platform/cznic: Add support for Turris Omnia MCU
ARM: dts: turris-omnia: Add MCU system-controller node
ARM: dts: turris-omnia: Add GPIO key node for front button

 .../sysfs-bus-i2c-devices-turris-omnia-mcu    |  77 ++
 .../bindings/arm/cznic,turris-omnia-mcu.yaml  |  72 ++
 MAINTAINERS                                   |   4 +
 .../dts/marvell/armada-385-turris-omnia.dts   |  37 +-
 drivers/platform/Kconfig                      |   2 +
 drivers/platform/Makefile                     |   1 +
 drivers/platform/cznic/Kconfig                |  48 +
 drivers/platform/cznic/Makefile               |   7 +
 .../platform/cznic/turris-omnia-mcu-base.c    | 275 +++++
 .../platform/cznic/turris-omnia-mcu-gpio.c    | 967 ++++++++++++++++++
 .../cznic/turris-omnia-mcu-sys-off-wakeup.c   | 245 +++++
 .../cznic/turris-omnia-mcu-watchdog.c         | 126 +++
 drivers/platform/cznic/turris-omnia-mcu.h     | 161 +++
 include/linux/turris-omnia-mcu-interface.h    | 194 ++++
 14 files changed, 2215 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c-devices-turris-omnia-mcu
 create mode 100644 Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml
 create mode 100644 drivers/platform/cznic/Kconfig
 create mode 100644 drivers/platform/cznic/Makefile
 create mode 100644 drivers/platform/cznic/turris-omnia-mcu-base.c
 create mode 100644 drivers/platform/cznic/turris-omnia-mcu-gpio.c
 create mode 100644 drivers/platform/cznic/turris-omnia-mcu-sys-off-wakeup.c
 create mode 100644 drivers/platform/cznic/turris-omnia-mcu-watchdog.c
 create mode 100644 drivers/platform/cznic/turris-omnia-mcu.h
 create mode 100644 include/linux/turris-omnia-mcu-interface.h
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH 1/4 dt-bindings: arm: add cznic,turris-omnia-mcu binding

Add binding for cznic,turris-omnia-mcu, the device-tree node representing the system-controller features provided by the MCU on the Turris Omnia router.

---
 .../bindings/arm/cznic,turris-omnia-mcu.yaml  | 72 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +72 -0
new file mode 100644
index 000000000000..055485847e71
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/cznic,turris-omnia-mcu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CZ.NIC's Turris Omnia MCU
+
+maintainers:
+  - Marek Behún <[email protected]>
+
+description:
+  The MCU on Turris Omnia acts as a system controller providing additional
+  GPIOs, interrupts, watchdog, system power off and wakeup configuration.
+
+properties:
+  compatible:
+    const: cznic,turris-omnia-mcu
+
+  reg:
+    description: MCU I2C slave address
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2
+
+  gpio-controller: true
+
+  '#gpio-cells':
+    const: 2
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-controller
+  - gpio-controller
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    ic: interrupt-controller {
+        interrupt-controller;
+        #interrupt-cells = <2>;
+    };
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        system-controller@2a {
+            compatible = "cznic,turris-omnia-mcu";
+            reg = <0x2a>;
+
+            interrupt-parent = <&ic>;
+            interrupts = <11 IRQ_TYPE_NONE>;
+
+            gpio-controller;
+            #gpio-cells = <2>;
+
+            interrupt-controller;
+            #interrupt-cells = <2>;
+        };
+    };
MAINTAINERS +1 -0
index d590ce31aa72..00db4f1d165f 100644
@@ -2077,6 +2077,7 @@ W:	https://www.turris.cz/
 F:	Documentation/ABI/testing/debugfs-moxtet
 F:	Documentation/ABI/testing/sysfs-bus-moxtet-devices
 F:	Documentation/ABI/testing/sysfs-firmware-turris-mox-rwtm
+F:	Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml
 F:	Documentation/devicetree/bindings/bus/moxtet.txt
 F:	Documentation/devicetree/bindings/firmware/cznic,turris-mox-rwtm.txt
 F:	Documentation/devicetree/bindings/gpio/gpio-moxtet.txt
Signature · 1 line
2.41.0
#2 lore raw

Re: [PATCH 1/4] dt-bindings: arm: add cznic,turris-omnia-mcu binding

Quoted 5 lines · Marek Behún

Add binding for cznic,turris-omnia-mcu, the device-tree node representing the system-controller features provided by the MCU on the Turris Omnia router.

Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC (and consider --no-git-fallback argument). It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml

Quoted 11 lines
---
 .../bindings/arm/cznic,turris-omnia-mcu.yaml  | 72 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +0 -0
new file mode 100644
index 000000000000..055485847e71

ARM directory is only for top-level bindings, so this should go to soc.

Quoted 44 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +43 -0
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/cznic,turris-omnia-mcu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CZ.NIC's Turris Omnia MCU
+
+maintainers:
+  - Marek Behún <[email protected]>
+
+description:
+  The MCU on Turris Omnia acts as a system controller providing additional
+  GPIOs, interrupts, watchdog, system power off and wakeup configuration.
+
+properties:
+  compatible:
+    const: cznic,turris-omnia-mcu
+
+  reg:
+    description: MCU I2C slave address
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2
+
+  gpio-controller: true
+
+  '#gpio-cells':
+    const: 2
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-controller
+  - gpio-controller
+

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml line 53

Quoted 10 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +10 -0
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    ic: interrupt-controller {
+        interrupt-controller;
+        #interrupt-cells = <2>;
+    };

Drop this node, not relevant.

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml line 64

Quoted 11 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +11 -0
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        system-controller@2a {
+            compatible = "cznic,turris-omnia-mcu";
+            reg = <0x2a>;
+
+            interrupt-parent = <&ic>;
+            interrupts = <11 IRQ_TYPE_NONE>;

Are you sure interrupt is type none?

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml line 71

Quoted 7 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +7 -0
+
+            gpio-controller;
+            #gpio-cells = <2>;
+
+            interrupt-controller;
+            #interrupt-cells = <2>;
+        };

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH 1/4] dt-bindings: arm: add cznic,turris-omnia-mcu binding

Hello Krzysztof,

thanks for the review.

Quoted 5 lines · On Thu, 24 Aug 2023 09:37:23 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 4 lines · Marek Behún

Add binding for cznic,turris-omnia-mcu, the device-tree node representing the system-controller features provided by the MCU on the Turris Omnia router.

Quoted 7 lines
Quoted 1 line

Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC (and consider --no-git-fallback argument). It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

I shall do that.

Quoted 6 lines
Quoted 6 lines
---
 .../bindings/arm/cznic,turris-omnia-mcu.yaml  | 72 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml
Quoted 7 lines

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml

Quoted 5 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +0 -0
new file mode 100644
index 000000000000..055485847e71

ARM directory is only for top-level bindings, so this should go to soc.

Hmm. The board uses a marvell SoC, but the board is from CZ.NIC (who does not create its own SoCs). So should this go into soc/marvell or soc/cznic?

Quoted 48 lines
Quoted 48 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +47 -0
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/cznic,turris-omnia-mcu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CZ.NIC's Turris Omnia MCU
+
+maintainers:
+  - Marek Behún <[email protected]>
+
+description:
+  The MCU on Turris Omnia acts as a system controller providing additional
+  GPIOs, interrupts, watchdog, system power off and wakeup configuration.
+
+properties:
+  compatible:
+    const: cznic,turris-omnia-mcu
+
+  reg:
+    description: MCU I2C slave address
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2
+
+  gpio-controller: true
+
+  '#gpio-cells':
+    const: 2
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-controller
+  - gpio-controller
+
+additionalProperties: false
+
+examples:
+  - |
Quoted 8 lines

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml line 53

Quoted 6 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +6 -0
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    ic: interrupt-controller {
+        interrupt-controller;
+        #interrupt-cells = <2>;
+    };  

Drop this node, not relevant.

Will the binding example compile without the ic node if the system-controller below uses it?

Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +5 -0
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
Quoted 8 lines

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml line 64

Quoted 6 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +6 -0
+        system-controller@2a {
+            compatible = "cznic,turris-omnia-mcu";
+            reg = <0x2a>;
+
+            interrupt-parent = <&ic>;
+            interrupts = <11 IRQ_TYPE_NONE>;  

Are you sure interrupt is type none?

The interrupt type is either LEVEL_LOW or EDGE_FALLING, depending on the version of the MCU firmware, so this has to be selected by the driver.

I tried setting LEVEL_LOW, since that is the one that is used by the newest MCU firmware. But then if the firmware is old and I want to select EDGE_FALLING in the driver when requesting the IRQ, it fails with message
type mismatch, failed to map hwirq-%lu for %s!
from
kernel/irq/irqdomain.c function irq_create_fwspec_mapping

I guess I can use irqd_set_trigger_type() before requesting the IRQ to avoid this error.

Should I use use LEVEL_LOW in the binding example and device-tree?

Thank you for the review.

Marek

#4 lore raw

Re: [PATCH 1/4] dt-bindings: arm: add cznic,turris-omnia-mcu binding

Quoted 14 lines · Marek Behún

Hello Krzysztof,

thanks for the review.

Quoted 7 lines · On Thu, 24 Aug 2023 09:37:23 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 5 lines · Marek Behún

Add binding for cznic,turris-omnia-mcu, the device-tree node representing the system-controller features provided by the MCU on the Turris Omnia router.

Quoted 7 lines
Quoted 5 lines

Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC (and consider --no-git-fallback argument). It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

I shall do that.

You replied only to me. Instead please reply-to-all to keep discussions public.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
---
 .../bindings/arm/cznic,turris-omnia-mcu.yaml  | 72 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml
Quoted 7 lines

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml

Quoted 5 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +0 -0
new file mode 100644
index 000000000000..055485847e71

ARM directory is only for top-level bindings, so this should go to soc.

Quoted 3 lines

Hmm. The board uses a marvell SoC, but the board is from CZ.NIC (who does not create its own SoCs). So should this go into soc/marvell or soc/cznic?

Indeed and it is a dedicated MCU (some Cortex-M or similar, right?), so maybe arm is suitable at the end.

Quoted 58 lines
Quoted 49 lines
Quoted 49 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +47 -0
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/cznic,turris-omnia-mcu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CZ.NIC's Turris Omnia MCU
+
+maintainers:
+  - Marek Behún <[email protected]>
+
+description:
+  The MCU on Turris Omnia acts as a system controller providing additional
+  GPIOs, interrupts, watchdog, system power off and wakeup configuration.
+
+properties:
+  compatible:
+    const: cznic,turris-omnia-mcu
+
+  reg:
+    description: MCU I2C slave address
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2
+
+  gpio-controller: true
+
+  '#gpio-cells':
+    const: 2
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-controller
+  - gpio-controller
+
+additionalProperties: false
+
+examples:
+  - |
Quoted 8 lines

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml line 53

Quoted 6 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +6 -0
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    ic: interrupt-controller {
+        interrupt-controller;
+        #interrupt-cells = <2>;
+    };  

Drop this node, not relevant.

Quoted 2 lines

Will the binding example compile without the ic node if the system-controller below uses it?

Yes.

Quoted 27 lines
Quoted 14 lines

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml line 64

Quoted 12 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +11 -0
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        system-controller@2a {
+            compatible = "cznic,turris-omnia-mcu";
+            reg = <0x2a>;
+
+            interrupt-parent = <&ic>;
+            interrupts = <11 IRQ_TYPE_NONE>;  

Are you sure interrupt is type none?

The interrupt type is either LEVEL_LOW or EDGE_FALLING, depending on the version of the MCU firmware, so this has to be selected by the driver.

I tried setting LEVEL_LOW, since that is the one that is used by the newest MCU firmware. But then if the firmware is old and I want to select EDGE_FALLING in the driver when requesting the IRQ, it fails with message
type mismatch, failed to map hwirq-%lu for %s!
from
kernel/irq/irqdomain.c function irq_create_fwspec_mapping

Quoted 4 lines

I guess I can use irqd_set_trigger_type() before requesting the IRQ to avoid this error.

Should I use use LEVEL_LOW in the binding example and device-tree?

I guess in such case this NONE is okay

Best regards,
Krzysztof

author maintainer
#5 lore raw

Re: [PATCH 1/4] dt-bindings: arm: add cznic,turris-omnia-mcu binding

Quoted 2 lines · On Thu, 24 Aug 2023 10:23:27 +0200 Krzysztof Kozlowski <[email protected]> wrote:

You replied only to me. Instead please reply-to-all to keep discussions public.

Sorry about that, I've redirected the messages to the other people.

Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

+++ b/Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml

ARM directory is only for top-level bindings, so this should go to soc.

Hmm. The board uses a marvell SoC, but the board is from CZ.NIC (who does not create its own SoCs). So should this go into soc/marvell or soc/cznic?

Indeed and it is a dedicated MCU (some Cortex-M or similar, right?), so maybe arm is suitable at the end.

There are three Cortex-M options (M0, M0+ or M3, from STM, NXP or GigaDevice), depending on the board revision.

The bindings/arm already contain for example amazon,al.yaml, which is platform binding (not SoC).

So I guess I will stick with bindings/arm, unless someone suggests something else.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml line 53

Quoted 8 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +8 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    ic: interrupt-controller {
+        interrupt-controller;
+        #interrupt-cells = <2>;
+    };    

Drop this node, not relevant.

Quoted 4 lines
Quoted 2 lines

Will the binding example compile without the ic node if the system-controller below uses it?

Yes.

OK

Quoted 17 lines
Quoted 17 lines
Quoted 4 lines

Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml line 64

Quoted 2 lines
Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml new file +2 -0
+            interrupt-parent = <&ic>;
+            interrupts = <11 IRQ_TYPE_NONE>;    

Are you sure interrupt is type none?

The interrupt type is either LEVEL_LOW or EDGE_FALLING, depending on the version of the MCU firmware, so this has to be selected by the driver.

I tried setting LEVEL_LOW, since that is the one that is used by the newest MCU firmware. But then if the firmware is old and I want to select EDGE_FALLING in the driver when requesting the IRQ, it fails with message
type mismatch, failed to map hwirq-%lu for %s!
from
kernel/irq/irqdomain.c function irq_create_fwspec_mapping

Quoted 6 lines
Quoted 4 lines

I guess I can use irqd_set_trigger_type() before requesting the IRQ to avoid this error.

Should I use use LEVEL_LOW in the binding example and device-tree?

I guess in such case this NONE is okay

Thx.

author maintainer
#6 lore raw

PATCH 2/4 platform/cznic: Add support for Turris Omnia MCU

In reply to Marek Behún

Add a new platform driver that exposes the features provided by the microcontroller on the Turris Omnia board.

These features include:
- Board poweroff into true low power mode - the MCU can disable almost all voltage regulators. The board can be enabled by pressing the front button.
- The ability to configure board wakeup at a specified time after the board was powered down. This ability is exposed to the userspace as a RTC driver, so that user can use the rtcwake command to configure it.
- MCU watchdog.
- GPIO pins and interrupts. The MCU has GPIOs connected to USB port voltage regulators and their fault pins (thus singaling USB port over-current conditions). Other GPIOs include the front button (which is also debounced by the MCU), MiniPCIe / mSATA card presence in MiniPCIe port 0, resets to various peripherals and finally LED output pins from WAN ethernet PHY, LAN switch and MiniPCIe ports.

---
 .../sysfs-bus-i2c-devices-turris-omnia-mcu    |  77 ++
 MAINTAINERS                                   |   3 +
 drivers/platform/Kconfig                      |   2 +
 drivers/platform/Makefile                     |   1 +
 drivers/platform/cznic/Kconfig                |  48 +
 drivers/platform/cznic/Makefile               |   7 +
 .../platform/cznic/turris-omnia-mcu-base.c    | 275 +++++
 .../platform/cznic/turris-omnia-mcu-gpio.c    | 967 ++++++++++++++++++
 .../cznic/turris-omnia-mcu-sys-off-wakeup.c   | 245 +++++
 .../cznic/turris-omnia-mcu-watchdog.c         | 126 +++
 drivers/platform/cznic/turris-omnia-mcu.h     | 161 +++
 include/linux/turris-omnia-mcu-interface.h    | 194 ++++
 12 files changed, 2106 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c-devices-turris-omnia-mcu
 create mode 100644 drivers/platform/cznic/Kconfig
 create mode 100644 drivers/platform/cznic/Makefile
 create mode 100644 drivers/platform/cznic/turris-omnia-mcu-base.c
 create mode 100644 drivers/platform/cznic/turris-omnia-mcu-gpio.c
 create mode 100644 drivers/platform/cznic/turris-omnia-mcu-sys-off-wakeup.c
 create mode 100644 drivers/platform/cznic/turris-omnia-mcu-watchdog.c
 create mode 100644 drivers/platform/cznic/turris-omnia-mcu.h
 create mode 100644 include/linux/turris-omnia-mcu-interface.h
Documentation/ABI/testing/sysfs-bus-i2c-devices-turris-omnia-mcu new file +77 -0
new file mode 100644
index 000000000000..d668b8e999e6
@@ -0,0 +1,77 @@
+What:		/sys/bus/i2c/devices/<mcu_device>/front_button_mode
+Date:		August 2023
+KernelVersion:	6.6
+Contact:	Marek Behún <[email protected]>
+Description:	(RW) The front button on the Turris Omnia router can be
+		configured either to change the intensity of all the LEDs on the
+		front panel, or to send the press event to the CPU as an
+		interrupt.
+
+		This file switches between these two modes:
+		- "mcu" makes the button press event be handled by the MCU to
+		  change the LEDs panel intensity.
+		- "cpu" makes the button press event be handled by the CPU.
+
+		Format: %s.
+
+What:		/sys/bus/i2c/devices/<mcu_device>/front_button_poweron
+Date:		August 2023
+KernelVersion:	6.6
+Contact:	Marek Behún <[email protected]>
+Description:	(RW) Newer versions of the microcontroller firmware of the
+		Turris Omnia router support powering off the router into true
+		low power mode. The router can be powered on by pressing the
+		front button.
+
+		This file configures whether front button power on is enabled.
+
+		This file is present only if the power off feature is supported
+		by the firmware.
+
+		Format: %i.
+
+What:		/sys/bus/i2c/devices/<mcu_device>/fw_features
+Date:		August 2023
+KernelVersion:	6.6
+Contact:	Marek Behún <[email protected]>
+Description:	(RO) Newer versions of the microcontroller firmware report the
+		features they support. These can be read from this file. If the
+		MCU firmware is too old, this file reads 0x0.
+
+		Format: 0x%x.
+
+What:		/sys/bus/i2c/devices/<mcu_device>/fw_version_hash_application
+Date:		August 2023
+KernelVersion:	6.6
+Contact:	Marek Behún <[email protected]>
+Description:	(RO) Contains the version hash (commit hash) of the application
+		part of the microcontroller firmware.
+
+		Format: %s.
+
+What:		/sys/bus/i2c/devices/<mcu_device>/fw_version_hash_bootloader
+Date:		August 2023
+KernelVersion:	6.6
+Contact:	Marek Behún <[email protected]>
+Description:	(RO) Contains the version hash (commit hash) of the bootloader
+		part of the microcontroller firmware.
+
+		Format: %s.
+
+What:		/sys/bus/i2c/devices/<mcu_device>/mcu_type
+Date:		August 2023
+KernelVersion:	6.6
+Contact:	Marek Behún <[email protected]>
+Description:	(RO) Contains the microcontroller type (STM32, GD32, MKL).
+
+		Format: %s.
+
+What:		/sys/bus/i2c/devices/<mcu_device>/reset_selector
+Date:		August 2023
+KernelVersion:	6.6
+Contact:	Marek Behún <[email protected]>
+Description:	(RO) Contains the selected factory reset level, determined by
+		how long the rear reset button was held by the user during board
+		reset.
+
+		Format: %i.
MAINTAINERS +3 -0
index 00db4f1d165f..25567686a2cc 100644
@@ -2075,6 +2075,7 @@ M:	Marek Behún <[email protected]>
 S:	Maintained
 W:	https://www.turris.cz/
 F:	Documentation/ABI/testing/debugfs-moxtet
+F:	Documentation/ABI/testing/sysfs-bus-i2c-devices-turris-omnia-mcu
 F:	Documentation/ABI/testing/sysfs-bus-moxtet-devices
 F:	Documentation/ABI/testing/sysfs-firmware-turris-mox-rwtm
 F:	Documentation/devicetree/bindings/arm/cznic,turris-omnia-mcu.yaml
@@ -2088,10 +2089,12 @@ F:	drivers/firmware/turris-mox-rwtm.c
 F:	drivers/gpio/gpio-moxtet.c
 F:	drivers/leds/leds-turris-omnia.c
 F:	drivers/mailbox/armada-37xx-rwtm-mailbox.c
+F:	drivers/platform/cznic/
 F:	drivers/watchdog/armada_37xx_wdt.c
 F:	include/dt-bindings/bus/moxtet.h
 F:	include/linux/armada-37xx-rwtm-mailbox.h
 F:	include/linux/moxtet.h
+F:	include/linux/turris-omnia-mcu-interface.h
 
 ARM/FARADAY FA526 PORT
 M:	Hans Ulli Kroll <[email protected]>
drivers/platform/Kconfig +2 -0
index 868b20361769..fef907a94001 100644
@@ -7,6 +7,8 @@ source "drivers/platform/goldfish/Kconfig"
 
 source "drivers/platform/chrome/Kconfig"
 
+source "drivers/platform/cznic/Kconfig"
+
 source "drivers/platform/mellanox/Kconfig"
 
 source "drivers/platform/olpc/Kconfig"
drivers/platform/Makefile +1 -0
index 41640172975a..cc66b5020a34 100644
@@ -11,3 +11,4 @@ obj-$(CONFIG_OLPC_EC)		+= olpc/
 obj-$(CONFIG_GOLDFISH)		+= goldfish/
 obj-$(CONFIG_CHROME_PLATFORMS)	+= chrome/
 obj-$(CONFIG_SURFACE_PLATFORMS)	+= surface/
+obj-$(CONFIG_CZNIC_PLATFORMS)	+= cznic/
drivers/platform/cznic/Kconfig new file +48 -0

48 lines not on this page · raw message

drivers/platform/cznic/Makefile new file +7 -0
new file mode 100644
index 000000000000..a43997a12d74
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_TURRIS_OMNIA_MCU)	+= turris-omnia-mcu.o
+turris-omnia-mcu-objs		:= turris-omnia-mcu-base.o
+turris-omnia-mcu-objs		+= turris-omnia-mcu-gpio.o
+turris-omnia-mcu-objs		+= turris-omnia-mcu-sys-off-wakeup.o
+turris-omnia-mcu-objs		+= turris-omnia-mcu-watchdog.o
drivers/platform/cznic/turris-omnia-mcu-base.c new file +275 -0

275 lines not on this page · raw message

drivers/platform/cznic/turris-omnia-mcu-gpio.c new file +967 -0

967 lines not on this page · raw message

drivers/platform/cznic/turris-omnia-mcu-sys-off-wakeup.c new file +245 -0

245 lines not on this page · raw message

drivers/platform/cznic/turris-omnia-mcu-watchdog.c new file +126 -0

126 lines not on this page · raw message

drivers/platform/cznic/turris-omnia-mcu.h new file +161 -0

161 lines not on this page · raw message

include/linux/turris-omnia-mcu-interface.h new file +194 -0

194 lines not on this page · raw message

Signature · 1 line
2.41.0
author maintainer
#7 lore raw

PATCH 3/4 ARM: dts: turris-omnia: Add MCU system-controller node

In reply to Marek Behún

Turris Omnia's MCU provides various features that can be configured over I2C at address 0x2a. Add device-tree node.

Fixes 26ca8b52d6e1 ("ARM: dts: add support for Turris Omnia")
---
 .../dts/marvell/armada-385-turris-omnia.dts   | 24 ++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts +23 -1
index 2d8d319bec83..761147f5870f 100644
@@ -218,7 +218,24 @@ i2c@0 {
 			#size-cells = <0>;
 			reg = <0>;
 
-			/* STM32F0 command interface at address 0x2a */
+			mcu: system-controller@2a {
+				compatible = "cznic,turris-omnia-mcu";
+				reg = <0x2a>;
+
+				pinctrl-names = "default";
+				pinctrl-0 = <&mcu_pins>;
+
+				interrupt-parent = <&gpio1>;
+				interrupts = <11 IRQ_TYPE_NONE>;
+
+				gpio-controller;
+				#gpio-cells = <2>;
+
+				interrupt-controller;
+				#interrupt-cells = <2>;
+
+				status = "okay";
+			};
 
 			led-controller@2b {
 				compatible = "cznic,turris-omnia-leds";
@@ -503,6 +520,11 @@ fixed-link {
 };
 
 &pinctrl {
+	mcu_pins: mcu-pins {
+		marvell,pins = "mpp43";
+		marvell,function = "gpio";
+	};
+
 	pcawan_pins: pcawan-pins {
 		marvell,pins = "mpp46";
 		marvell,function = "gpio";
Signature · 1 line
2.41.0
#8 lore raw

Re: [PATCH 3/4] ARM: dts: turris-omnia: Add MCU system-controller node

Quoted 25 lines · Marek Behún

Turris Omnia's MCU provides various features that can be configured over I2C at address 0x2a. Add device-tree node.

Fixes 26ca8b52d6e1 ("ARM: dts: add support for Turris Omnia")
---
 .../dts/marvell/armada-385-turris-omnia.dts   | 24 ++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts +7 -1
index 2d8d319bec83..761147f5870f 100644
@@ -218,7 +218,24 @@ i2c@0 {
 			#size-cells = <0>;
 			reg = <0>;
 
-			/* STM32F0 command interface at address 0x2a */
+			mcu: system-controller@2a {
+				compatible = "cznic,turris-omnia-mcu";
+				reg = <0x2a>;
+
+				pinctrl-names = "default";
+				pinctrl-0 = <&mcu_pins>;
+

arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts i2c@0 { · line 237

Quoted 10 lines
arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts +10 -0
+				interrupt-parent = <&gpio1>;
+				interrupts = <11 IRQ_TYPE_NONE>;
+
+				gpio-controller;
+				#gpio-cells = <2>;
+
+				interrupt-controller;
+				#interrupt-cells = <2>;
+
+				status = "okay";

Drop status.

Best regards,
Krzysztof

author maintainer
#9 lore raw

PATCH 4/4 ARM: dts: turris-omnia: Add GPIO key node for front button

In reply to Marek Behún

Now that we have the MCU device-tree node, which acts as a GPIO controller, add GPIO key node for the front button.

Fixes 26ca8b52d6e1 ("ARM: dts: add support for Turris Omnia")
---
 .../boot/dts/marvell/armada-385-turris-omnia.dts    | 13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts +13 -0
index 761147f5870f..3bbccbae89ab 100644
@@ -112,6 +112,19 @@ sfp: sfp {
 		status = "disabled";
 	};
 
+	gpio-keys {
+		compatible = "gpio-keys";
+
+		front-button {
+			label = "Front Button";
+			linux,code = <KEY_VENDOR>;
+			linux,can-disable;
+			gpios = <&mcu 12 GPIO_ACTIVE_HIGH>;
+			/* debouncing is done by the microcontroller */
+			debounce-interval = <0>;
+		};
+	};
+
 	sound {
 		compatible = "simple-audio-card";
 		simple-audio-card,name = "SPDIF";
Signature · 1 line
2.41.0