Skip to contentSkip to conversation

Introduce Nuvoton ma35d1 SoC

PATCH Applied Jacky Huang 9 participants 56 messages Mar 28, 2023 – Apr 25, 2023

Subsystems (8)

v6 of 16 Applied Latest is v16 →

lore
Share & tools
lore
#0 lore raw

v6 cover Introduce Nuvoton ma35d1 SoC

From: Jacky Huang <[email protected]>

This patchset adds initial support for the Nuvoton ma35d1 SoC, including initial device tree, clock driver, reset driver, and serial driver.

This patchset cover letter is based from the initial support for Nuvoton ma35d1 to keep tracking the version history.

This patchset had been applied to Linux kernel 6.3-rc3 and tested on the Nuvoton ma35d1 SOM evaluation board.

(ma35d1 information: https://www.nuvoton.com/products/microprocessors/arm-cortex-a35-mpus/)
MA35D1 porting on linux-5.10.y can be found at: https://github.com/OpenNuvoton/MPU-Family

v6:
- Combine nuvoton,ma35d1-clk.yaml and nuvoton,ma35d1-clk.h into one patch
- Combine nuvoton,ma35d1-reset.yaml and nuvoton,ma35d1-reset.h into one patch
- rename Documentation/devicetree/bindings/arm/npcm directory as nuvoton
- Remove patch for adding include/linux/mfd/ma35d1-sys.h as it's not required
- Update dtsi & dts files and move board-specific nodes to dts
- Modify reset driver
- Modify serial driver, fix coding style issues
- Modify clock driver, rewrite the PLL calculation functions

v5:
- Add ARCH_NUVOTON to arm64 Kconfig
- Add ARCH_NUVOTON to defconfig
- Add the clock driver
- Add the reset driver
- Add the serial driver
- Add us to the maintainer

v4:
- patch 4/5 is a resend
- Fixed dt_binding_check errors of nuvoton,ma35d1-clk.yaml
- Modify ma35d1.dtsi
1. Add a node hxt_24m
2. Fixed the base address of gic node
3. Add clocks and clock-names to clock node
- Fixed borad binding mistakes of nuvoton.yaml

v3:
- added patch 4/5 and 5/5
- introduce CONFIG_ARCH_NUVOTON option
- add initial bindings for Nuvoton Platform boards
- fixed coding style problem of nuvoton,ma35d1-clk.h
- added CAPLL to clock-controller node
- modify the chosen node of ma35d1-evb.dts
- modify clock yaml "clk-pll-mode" to "nuvoton,clk-pll-mode"

v2:
- fixed dt_binding_check failed of nuvoton,ma35d1-clk.yaml

Jacky Huang (12):
arm64: Kconfig.platforms: Add config for Nuvoton MA35 platform
arm64: defconfig: Add support for Nuvoton MA35 family SoCs
dt-bindings: clock: nuvoton: add binding for ma35d1 clock controller
dt-bindings: reset: nuvoton: add binding for ma35d1 IP reset control
dt-bindings: mfd: syscon: Add nuvoton,ma35d1-sys compatible
dt-bindings: arm: Add initial bindings for Nuvoton platform
dt-bindings: serial: Document ma35d1 uart controller
arm64: dts: nuvoton: Add initial ma35d1 device tree
clk: nuvoton: Add clock driver for ma35d1 clock controller
reset: Add Nuvoton ma35d1 reset driver support
tty: serial: Add Nuvoton ma35d1 serial driver support
MAINTAINERS: Add entry for NUVOTON MA35

 .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  |  30 +
 .../nuvoton,npcm-gcr.yaml}                    |   2 +-
 .../npcm.yaml => nuvoton/nuvoton,npcm.yaml}   |   2 +-
 .../bindings/clock/nuvoton,ma35d1-clk.yaml    |  72 ++
 .../devicetree/bindings/mfd/syscon.yaml       |   1 +
 .../bindings/reset/nuvoton,ma35d1-reset.yaml  |  44 +
 .../serial/nuvoton,ma35d1-serial.yaml         |  48 +
 MAINTAINERS                                   |   9 +
 arch/arm64/Kconfig.platforms                  |   9 +
 arch/arm64/boot/dts/nuvoton/Makefile          |   2 +
 .../boot/dts/nuvoton/ma35d1-iot-512m.dts      |  56 +
 .../boot/dts/nuvoton/ma35d1-som-256m.dts      |  56 +
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       | 231 +++++
 arch/arm64/configs/defconfig                  |   1 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/nuvoton/Kconfig                   |  19 +
 drivers/clk/nuvoton/Makefile                  |   4 +
 drivers/clk/nuvoton/clk-ma35d1-divider.c      | 140 +++
 drivers/clk/nuvoton/clk-ma35d1-pll.c          | 350 +++++++
 drivers/clk/nuvoton/clk-ma35d1.c              | 963 ++++++++++++++++++
 drivers/clk/nuvoton/clk-ma35d1.h              | 123 +++
 drivers/reset/Kconfig                         |   6 +
 drivers/reset/Makefile                        |   1 +
 drivers/reset/reset-ma35d1.c                  | 152 +++
 drivers/tty/serial/Kconfig                    |  18 +
 drivers/tty/serial/Makefile                   |   1 +
 drivers/tty/serial/ma35d1_serial.c            | 802 +++++++++++++++
 .../dt-bindings/clock/nuvoton,ma35d1-clk.h    | 253 +++++
 .../dt-bindings/reset/nuvoton,ma35d1-reset.h  | 108 ++
 29 files changed, 3502 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml
 rename Documentation/devicetree/bindings/arm/{npcm/nuvoton,gcr.yaml => nuvoton/nuvoton,npcm-gcr.yaml} (93%)
 rename Documentation/devicetree/bindings/arm/{npcm/npcm.yaml => nuvoton/nuvoton,npcm.yaml} (93%)
 create mode 100644 Documentation/devicetree/bindings/clock/nuvoton,ma35d1-clk.yaml
 create mode 100644 Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml
 create mode 100644 Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.yaml
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi
 create mode 100644 drivers/clk/nuvoton/Kconfig
 create mode 100644 drivers/clk/nuvoton/Makefile
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1-divider.c
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1-pll.c
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1.c
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1.h
 create mode 100644 drivers/reset/reset-ma35d1.c
 create mode 100644 drivers/tty/serial/ma35d1_serial.c
 create mode 100644 include/dt-bindings/clock/nuvoton,ma35d1-clk.h
 create mode 100644 include/dt-bindings/reset/nuvoton,ma35d1-reset.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH v6 1/12 arm64: Kconfig.platforms: Add config for Nuvoton MA35 platform

From: Jacky Huang <[email protected]>

Add ARCH_NUVOTON configuration option for Nuvoton MA35 family SoCs.

---
 arch/arm64/Kconfig.platforms | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/Kconfig.platforms +9 -0
index 89a0b13b058d..c1f277c05569 100644
@@ -236,6 +236,15 @@ config ARCH_NPCM
 	  General support for NPCM8xx BMC (Arbel).
 	  Nuvoton NPCM8xx BMC based on the Cortex A35.
 
+config ARCH_NUVOTON
+	bool "Nuvoton MA35 Platforms"
+	select GPIOLIB
+	select PINCTRL
+	select RESET_CONTROLLER
+	help
+	  This enables support for the ARMv8 based Nuvoton SoCs such
+	  as MA35D1.
+
 config ARCH_QCOM
 	bool "Qualcomm Platforms"
 	select GPIOLIB
Signature · 1 line
2.34.1
#2 lore raw

PATCH v6 2/12 arm64: defconfig: Add support for Nuvoton MA35 family SoCs

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

This adds support for the Nuvoton MA35 family SoCs which are based on the Cortex-A35 Armv8-A 64-bit architecture.

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index 7790ee42c68a..c96189acb02c 100644
@@ -53,6 +53,7 @@ CONFIG_ARCH_LAYERSCAPE=y
 CONFIG_ARCH_MXC=y
 CONFIG_ARCH_S32=y
 CONFIG_ARCH_NPCM=y
+CONFIG_ARCH_NUVOTON=y
 CONFIG_ARCH_QCOM=y
 CONFIG_ARCH_RENESAS=y
 CONFIG_ARCH_ROCKCHIP=y
Signature · 1 line
2.34.1
#3 lore raw

PATCH v6 3/12 dt-bindings: clock: nuvoton: add binding for ma35d1 clock controller

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Add the dt-bindings header for Nuvoton ma35d1, that gets shared between the clock controller and clock references in the dts. Add documentation to describe nuvoton ma35d1 clock driver.

---
 .../bindings/clock/nuvoton,ma35d1-clk.yaml    |  72 +++++
 .../dt-bindings/clock/nuvoton,ma35d1-clk.h    | 253 ++++++++++++++++++
 2 files changed, 325 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/nuvoton,ma35d1-clk.yaml
 create mode 100644 include/dt-bindings/clock/nuvoton,ma35d1-clk.h
Documentation/devicetree/bindings/clock/nuvoton,ma35d1-clk.yaml new file +72 -0
new file mode 100644
index 000000000000..0a9c2a115e6b
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/nuvoton,ma35d1-clk.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 Clock Controller Module
+
+maintainers:
+  - Chi-Fang Li <[email protected]>
+  - Jacky Huang <[email protected]>
+
+description: |
+  The MA35D1 clock controller generates clocks for the whole chip,
+  including system clocks and all peripheral clocks.
+
+  See also:
+    include/dt-bindings/clock/ma35d1-clk.h
+
+properties:
+  compatible:
+    items:
+      - const: nuvoton,ma35d1-clk
+      - const: syscon
+
+  reg:
+    maxItems: 1
+
+  "#clock-cells":
+    const: 1
+
+  clocks:
+    maxItems: 1
+
+  nuvoton,pll-mode:
+    description:
+      A list of PLL operation mode corresponding to CAPLL, DDRPLL, APLL,
+      EPLL, and VPLL in sequential.
+    maxItems: 5
+    items:
+      enum:
+        - integer
+        - fractional
+        - spread-spectrum
+    $ref: /schemas/types.yaml#/definitions/non-unique-string-array
+
+  nuvoton,sys:
+    description:
+      Use to unlock and lock some clock controller registers. The lock
+      control register is in system controller.
+    $ref: /schemas/types.yaml#/definitions/phandle
+
+required:
+  - compatible
+  - reg
+  - "#clock-cells"
+  - clocks
+  - nuvoton,sys
+
+additionalProperties: false
+
+examples:
+  - |
+
+    clock-controller@40460200 {
+        compatible = "nuvoton,ma35d1-clk", "syscon";
+        reg = <0x40460200 0x100>;
+        #clock-cells = <1>;
+        clocks = <&clk_hxt>;
+        nuvoton,sys = <&sys>;
+    };
+...
include/dt-bindings/clock/nuvoton,ma35d1-clk.h new file +253 -0

253 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v6 3/12
#4 lore raw

Re: [PATCH v6 03/12] dt-bindings: clock: nuvoton: add binding for ma35d1 clock controller

Quoted 8 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Add the dt-bindings header for Nuvoton ma35d1, that gets shared between the clock controller and clock references in the dts. Add documentation to describe nuvoton ma35d1 clock driver.

---

Best regards,
Krzysztof

#5 lore raw

PATCH v6 4/12 dt-bindings: reset: nuvoton: add binding for ma35d1 IP reset control

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Add the dt-bindings header for Nuvoton ma35d1, that gets shared between the reset controller and reset references in the dts. Add documentation to describe nuvoton ma35d1 reset driver.

---
 .../bindings/reset/nuvoton,ma35d1-reset.yaml  |  44 +++++++
 .../dt-bindings/reset/nuvoton,ma35d1-reset.h  | 108 ++++++++++++++++++
 2 files changed, 152 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml
 create mode 100644 include/dt-bindings/reset/nuvoton,ma35d1-reset.h
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +44 -0
new file mode 100644
index 000000000000..342717257e5c
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/reset/nuvoton,ma35d1-reset.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 Reset Controller
+
+maintainers:
+  - Chi-Fang Li <[email protected]>
+  - Jacky Huang <[email protected]>
+
+description:
+  The system reset controller can be used to reset various peripheral
+  controllers in MA35D1 SoC.
+
+properties:
+  compatible:
+    const: nuvoton,ma35d1-reset
+
+  '#reset-cells':
+    const: 1
+
+required:
+  - compatible
+  - '#reset-cells'
+
+additionalProperties: false
+
+examples:
+  # system reset controller node:
+  - |
+
+    system-management@40460000 {
+        compatible = "nuvoton,ma35d1-sys", "syscon", "simple-mfd";
+        reg = <0x40460000 0x200>;
+
+        reset-controller {
+            compatible = "nuvoton,ma35d1-reset";
+            #reset-cells = <1>;
+        };
+    };
+...
+
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +108 -0

108 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#6 lore raw

Re: [PATCH v6 04/12] dt-bindings: reset: nuvoton: add binding for ma35d1 IP reset control

Quoting Jacky Huang (2023-03-27 19:19:04)

Quoted 19 lines
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +19 -0
+description:
+  The system reset controller can be used to reset various peripheral
+  controllers in MA35D1 SoC.
+
+properties:
+  compatible:
+    const: nuvoton,ma35d1-reset
+
+  '#reset-cells':
+    const: 1
+
+required:
+  - compatible
+  - '#reset-cells'
+
+additionalProperties: false
+
+examples:
+  # system reset controller node:

Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml line 41

Quoted 10 lines
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +10 -0
+  - |
+
+    system-management@40460000 {
+        compatible = "nuvoton,ma35d1-sys", "syscon", "simple-mfd";
+        reg = <0x40460000 0x200>;
+
+        reset-controller {
+            compatible = "nuvoton,ma35d1-reset";
+            #reset-cells = <1>;
+        };

This is prescribing driver details to the system-management node. The reset-controller node should be removed, the #reset-cells moved up one level, and the "nuvoton,ma35d1-sys" should match a driver that registers an auxiliary device for reset functionality. Is anything besides child nodes like 'reset-controller' using the syscon@40460000?

#7 lore raw

Re: [PATCH v6 04/12] dt-bindings: reset: nuvoton: add binding for ma35d1 IP reset control

Dear Stephen,

Quoted 27 lines · Stephen Boyd

Quoting Jacky Huang (2023-03-27 19:19:04)

Quoted 26 lines
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +26 -0
+description:
+  The system reset controller can be used to reset various peripheral
+  controllers in MA35D1 SoC.
+
+properties:
+  compatible:
+    const: nuvoton,ma35d1-reset
+
+  '#reset-cells':
+    const: 1
+
+required:
+  - compatible
+  - '#reset-cells'
+
+additionalProperties: false
+
+examples:
+  # system reset controller node:
+  - |
+
+    system-management@40460000 {
+        compatible = "nuvoton,ma35d1-sys", "syscon", "simple-mfd";
+        reg = <0x40460000 0x200>;
+
+        reset-controller {
Quoted 8 lines

Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml line 41

Quoted 3 lines
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +3 -0
+            compatible = "nuvoton,ma35d1-reset";
+            #reset-cells = <1>;
+        };

This is prescribing driver details to the system-management node. The reset-controller node should be removed, the #reset-cells moved up one level, and the "nuvoton,ma35d1-sys" should match a driver that registers an auxiliary device for reset functionality. Is anything besides child nodes like 'reset-controller' using the syscon@40460000?

OK, I will modify it as:

    sys: system-management@40460000 { compatible = "nuvoton,ma35d1-sys", "syscon",; reg = <0x0 0x40460000 0x0 0x200>; #reset-cells = <1>;
        };
    };

And my reset driver will use compatible "nuvoton,ma35d1-sys", instead of "nuvoton,ma35d1-reset". There' no other node like reset-controller.

Best regards,
Jack Huang

#8 lore raw

Re: [PATCH v6 04/12] dt-bindings: reset: nuvoton: add binding for ma35d1 IP reset control

In reply to Jacky Huang
Quoted 1 line · Jacky Huang

From: Jacky Huang <[email protected]>

Subject: drop second/last, redundant "bindings". The "dt-bindings" prefix is already stating that these are bindings.

This is a friendly reminder during the review process.

It seems my previous comments were not fully addressed. Maybe my feedback got lost between the quotes, maybe you just forgot to apply it. Please go back to the previous discussion and either implement all requested changes or keep discussing them.

Thank you.

Quoted 49 lines

Add the dt-bindings header for Nuvoton ma35d1, that gets shared between the reset controller and reset references in the dts. Add documentation to describe nuvoton ma35d1 reset driver.

---
 .../bindings/reset/nuvoton,ma35d1-reset.yaml  |  44 +++++++
 .../dt-bindings/reset/nuvoton,ma35d1-reset.h  | 108 ++++++++++++++++++
 2 files changed, 152 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml
 create mode 100644 include/dt-bindings/reset/nuvoton,ma35d1-reset.h
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +30 -0
new file mode 100644
index 000000000000..342717257e5c
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/reset/nuvoton,ma35d1-reset.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 Reset Controller
+
+maintainers:
+  - Chi-Fang Li <[email protected]>
+  - Jacky Huang <[email protected]>
+
+description:
+  The system reset controller can be used to reset various peripheral
+  controllers in MA35D1 SoC.
+
+properties:
+  compatible:
+    const: nuvoton,ma35d1-reset
+
+  '#reset-cells':
+    const: 1
+
+required:
+  - compatible
+  - '#reset-cells'
+
+additionalProperties: false
+
+examples:

Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml line 40

Quoted 10 lines
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +10 -0
+  # system reset controller node:
+  - |
+
+    system-management@40460000 {
+        compatible = "nuvoton,ma35d1-sys", "syscon", "simple-mfd";
+        reg = <0x40460000 0x200>;
+
+        reset-controller {
+            compatible = "nuvoton,ma35d1-reset";
+            #reset-cells = <1>;

You do not take any resources here, thus this should be rather part of the parent node.

include/dt-bindings/reset/nuvoton,ma35d1-reset.h line 1

Quoted 11 lines
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +4 -0
+        };
+    };
+...
+
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +1 -0
new file mode 100644
index 000000000000..f3088bc0afec
@@ -0,0 +1,108 @@
+/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-2-Clause) */

Weird license, why 2.0+?

You already got here comment about license in previous version of this patch.

Quoted 53 lines
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +53 -0
+/*
+ * Copyright (C) 2023 Nuvoton Technologies.
+ * Author: Chi-Fen Li <[email protected]>
+ *
+ * Device Tree binding constants for MA35D1 reset controller.
+ */
+
+#ifndef __DT_BINDINGS_RESET_MA35D1_H
+#define __DT_BINDINGS_RESET_MA35D1_H
+
+#define MA35D1_RESET_CHIP	0
+#define MA35D1_RESET_CA35CR0	1
+#define MA35D1_RESET_CA35CR1	2
+#define MA35D1_RESET_CM4	3
+#define MA35D1_RESET_PDMA0	4
+#define MA35D1_RESET_PDMA1	5
+#define MA35D1_RESET_PDMA2	6
+#define MA35D1_RESET_PDMA3	7
+#define MA35D1_RESET_DISP	9
+#define MA35D1_RESET_VCAP0	10
+#define MA35D1_RESET_VCAP1	11
+#define MA35D1_RESET_GFX	12
+#define MA35D1_RESET_VDEC	13
+#define MA35D1_RESET_WHC0	14
+#define MA35D1_RESET_WHC1	15
+#define MA35D1_RESET_GMAC0	16
+#define MA35D1_RESET_GMAC1	17
+#define MA35D1_RESET_HWSEM	18
+#define MA35D1_RESET_EBI	19
+#define MA35D1_RESET_HSUSBH0	20
+#define MA35D1_RESET_HSUSBH1	21
+#define MA35D1_RESET_HSUSBD	22
+#define MA35D1_RESET_USBHL	23
+#define MA35D1_RESET_SDH0	24
+#define MA35D1_RESET_SDH1	25
+#define MA35D1_RESET_NAND	26
+#define MA35D1_RESET_GPIO	27
+#define MA35D1_RESET_MCTLP	28
+#define MA35D1_RESET_MCTLC	29
+#define MA35D1_RESET_DDRPUB	30
+#define MA35D1_RESET_TMR0	34
+#define MA35D1_RESET_TMR1	35
+#define MA35D1_RESET_TMR2	36
+#define MA35D1_RESET_TMR3	37
+#define MA35D1_RESET_I2C0	40
+#define MA35D1_RESET_I2C1	41
+#define MA35D1_RESET_I2C2	42
+#define MA35D1_RESET_I2C3	43
+#define MA35D1_RESET_QSPI0	44
+#define MA35D1_RESET_SPI0	45
+#define MA35D1_RESET_SPI1	46
+#define MA35D1_RESET_SPI2	47
+#define MA35D1_RESET_UART0	48

include/dt-bindings/reset/nuvoton,ma35d1-reset.h line 64

Quoted 10 lines
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +10 -0
+#define MA35D1_RESET_UART1	49
+#define MA35D1_RESET_UART2	50
+#define MA35D1_RESET_UAER3	51
+#define MA35D1_RESET_UART4	52
+#define MA35D1_RESET_UART5	53
+#define MA35D1_RESET_UART6	54
+#define MA35D1_RESET_UART7	55
+#define MA35D1_RESET_CANFD0	56
+#define MA35D1_RESET_CANFD1	57
+#define MA35D1_RESET_EADC0	60

Why do you have gaps here? These should be IDs, not register offsets.

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH v6 04/12] dt-bindings: reset: nuvoton: add binding for ma35d1 IP reset control

Dear Krzysztof,

Quoted 66 lines · Krzysztof Kozlowski
Quoted 1 line · Jacky Huang

From: Jacky Huang <[email protected]>

Subject: drop second/last, redundant "bindings". The "dt-bindings" prefix is already stating that these are bindings.

This is a friendly reminder during the review process.

It seems my previous comments were not fully addressed. Maybe my feedback got lost between the quotes, maybe you just forgot to apply it. Please go back to the previous discussion and either implement all requested changes or keep discussing them.

Thank you.

Quoted 52 lines

Add the dt-bindings header for Nuvoton ma35d1, that gets shared between the reset controller and reset references in the dts. Add documentation to describe nuvoton ma35d1 reset driver.

---
  .../bindings/reset/nuvoton,ma35d1-reset.yaml  |  44 +++++++
  .../dt-bindings/reset/nuvoton,ma35d1-reset.h  | 108 ++++++++++++++++++
  2 files changed, 152 insertions(+)

create mode 100644 Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml create mode 100644 include/dt-bindings/reset/nuvoton,ma35d1-reset.h

Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +34 -0
new file mode 100644
index 000000000000..342717257e5c
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/reset/nuvoton,ma35d1-reset.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 Reset Controller
+
+maintainers:
+  - Chi-Fang Li <[email protected]>
+  - Jacky Huang <[email protected]>
+
+description:
+  The system reset controller can be used to reset various peripheral
+  controllers in MA35D1 SoC.
+
+properties:
+  compatible:
+    const: nuvoton,ma35d1-reset
+
+  '#reset-cells':
+    const: 1
+
+required:
+  - compatible
+  - '#reset-cells'
+
+additionalProperties: false
+
+examples:
+  # system reset controller node:
+  - |
+
+    system-management@40460000 {
Quoted 8 lines

Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml line 40

Quoted 6 lines
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +6 -0
+        compatible = "nuvoton,ma35d1-sys", "syscon", "simple-mfd";
+        reg = <0x40460000 0x200>;
+
+        reset-controller {
+            compatible = "nuvoton,ma35d1-reset";
+            #reset-cells = <1>;

You do not take any resources here, thus this should be rather part of the parent node.

I will modify it as:
    sys: system-management@40460000 { compatible = "nuvoton,ma35d1-sys", "syscon",; reg = <0x0 0x40460000 0x0 0x200>; #reset-cells = <1>;
        };
    };

Quoted 13 lines

include/dt-bindings/reset/nuvoton,ma35d1-reset.h line 1

Quoted 11 lines
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +4 -0
+        };
+    };
+...
+
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +1 -0
new file mode 100644
index 000000000000..f3088bc0afec
@@ -0,0 +1,108 @@
+/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-2-Clause) */

Weird license, why 2.0+?

Quoted 3 lines

You already got here comment about license in previous version of this patch.

In fact, I always be confused with the license.
It should be right if I just copy one from the same directory /include/dt-bindings/reset/. But, when I find there are several versions there, I was confused and just select one of them.

/* SPDX-License-Identifier: GPL-2.0-only */
/* SPDX-License-Identifier: GPL-2.0+ */
/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)*/ /* SPDX-License-Identifier: (GPL-2.0+ or MIT) */
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */

So, should I fix the license as

/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */

just remove the '+' ?

Quoted 65 lines
Quoted 53 lines
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +53 -0
+/*
+ * Copyright (C) 2023 Nuvoton Technologies.
+ * Author: Chi-Fen Li <[email protected]>
+ *
+ * Device Tree binding constants for MA35D1 reset controller.
+ */
+
+#ifndef __DT_BINDINGS_RESET_MA35D1_H
+#define __DT_BINDINGS_RESET_MA35D1_H
+
+#define MA35D1_RESET_CHIP	0
+#define MA35D1_RESET_CA35CR0	1
+#define MA35D1_RESET_CA35CR1	2
+#define MA35D1_RESET_CM4	3
+#define MA35D1_RESET_PDMA0	4
+#define MA35D1_RESET_PDMA1	5
+#define MA35D1_RESET_PDMA2	6
+#define MA35D1_RESET_PDMA3	7
+#define MA35D1_RESET_DISP	9
+#define MA35D1_RESET_VCAP0	10
+#define MA35D1_RESET_VCAP1	11
+#define MA35D1_RESET_GFX	12
+#define MA35D1_RESET_VDEC	13
+#define MA35D1_RESET_WHC0	14
+#define MA35D1_RESET_WHC1	15
+#define MA35D1_RESET_GMAC0	16
+#define MA35D1_RESET_GMAC1	17
+#define MA35D1_RESET_HWSEM	18
+#define MA35D1_RESET_EBI	19
+#define MA35D1_RESET_HSUSBH0	20
+#define MA35D1_RESET_HSUSBH1	21
+#define MA35D1_RESET_HSUSBD	22
+#define MA35D1_RESET_USBHL	23
+#define MA35D1_RESET_SDH0	24
+#define MA35D1_RESET_SDH1	25
+#define MA35D1_RESET_NAND	26
+#define MA35D1_RESET_GPIO	27
+#define MA35D1_RESET_MCTLP	28
+#define MA35D1_RESET_MCTLC	29
+#define MA35D1_RESET_DDRPUB	30
+#define MA35D1_RESET_TMR0	34
+#define MA35D1_RESET_TMR1	35
+#define MA35D1_RESET_TMR2	36
+#define MA35D1_RESET_TMR3	37
+#define MA35D1_RESET_I2C0	40
+#define MA35D1_RESET_I2C1	41
+#define MA35D1_RESET_I2C2	42
+#define MA35D1_RESET_I2C3	43
+#define MA35D1_RESET_QSPI0	44
+#define MA35D1_RESET_SPI0	45
+#define MA35D1_RESET_SPI1	46
+#define MA35D1_RESET_SPI2	47
+#define MA35D1_RESET_UART0	48

include/dt-bindings/reset/nuvoton,ma35d1-reset.h line 64

Quoted 10 lines
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +10 -0
+#define MA35D1_RESET_UART1	49
+#define MA35D1_RESET_UART2	50
+#define MA35D1_RESET_UAER3	51
+#define MA35D1_RESET_UART4	52
+#define MA35D1_RESET_UART5	53
+#define MA35D1_RESET_UART6	54
+#define MA35D1_RESET_UART7	55
+#define MA35D1_RESET_CANFD0	56
+#define MA35D1_RESET_CANFD1	57
+#define MA35D1_RESET_EADC0	60

Why do you have gaps here? These should be IDs, not register offsets.

Quoted 3 lines

Best regards,
Krzysztof

The reset controller registers are composed of four 32-bits register. And the ID will be translated into the corresponding bit of these register. Each ID is mapped to a unique bit position.

Best regards,
Jacky Huang

#10 lore raw

Re: [PATCH v6 04/12] dt-bindings: reset: nuvoton: add binding for ma35d1 IP reset control

Quoted 29 lines · Jacky Huang
Quoted 13 lines

include/dt-bindings/reset/nuvoton,ma35d1-reset.h line 1

Quoted 11 lines
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +4 -0
+        };
+    };
+...
+
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +1 -0
new file mode 100644
index 000000000000..f3088bc0afec
@@ -0,0 +1,108 @@
+/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-2-Clause) */

Weird license, why 2.0+?

Quoted 3 lines

You already got here comment about license in previous version of this patch.

In fact, I always be confused with the license.
It should be right if I just copy one from the same directory /include/dt-bindings/reset/.
But, when I find there are several versions there, I was confused and just select one of them.

/* SPDX-License-Identifier: GPL-2.0-only */
/* SPDX-License-Identifier: GPL-2.0+ */
/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)*/ /* SPDX-License-Identifier: (GPL-2.0+ or MIT) */
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */

Quoted 5 lines

So, should I fix the license as

/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */

just remove the '+' ?

The simplest is to use the same license as your binding, so (GPL-2.0-only OR BSD-2-Clause) .

Quoted 66 lines
Quoted 66 lines
Quoted 54 lines
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +53 -0
+/*
+ * Copyright (C) 2023 Nuvoton Technologies.
+ * Author: Chi-Fen Li <[email protected]>
+ *
+ * Device Tree binding constants for MA35D1 reset controller.
+ */
+
+#ifndef __DT_BINDINGS_RESET_MA35D1_H
+#define __DT_BINDINGS_RESET_MA35D1_H
+
+#define MA35D1_RESET_CHIP	0
+#define MA35D1_RESET_CA35CR0	1
+#define MA35D1_RESET_CA35CR1	2
+#define MA35D1_RESET_CM4	3
+#define MA35D1_RESET_PDMA0	4
+#define MA35D1_RESET_PDMA1	5
+#define MA35D1_RESET_PDMA2	6
+#define MA35D1_RESET_PDMA3	7
+#define MA35D1_RESET_DISP	9
+#define MA35D1_RESET_VCAP0	10
+#define MA35D1_RESET_VCAP1	11
+#define MA35D1_RESET_GFX	12
+#define MA35D1_RESET_VDEC	13
+#define MA35D1_RESET_WHC0	14
+#define MA35D1_RESET_WHC1	15
+#define MA35D1_RESET_GMAC0	16
+#define MA35D1_RESET_GMAC1	17
+#define MA35D1_RESET_HWSEM	18
+#define MA35D1_RESET_EBI	19
+#define MA35D1_RESET_HSUSBH0	20
+#define MA35D1_RESET_HSUSBH1	21
+#define MA35D1_RESET_HSUSBD	22
+#define MA35D1_RESET_USBHL	23
+#define MA35D1_RESET_SDH0	24
+#define MA35D1_RESET_SDH1	25
+#define MA35D1_RESET_NAND	26
+#define MA35D1_RESET_GPIO	27
+#define MA35D1_RESET_MCTLP	28
+#define MA35D1_RESET_MCTLC	29
+#define MA35D1_RESET_DDRPUB	30
+#define MA35D1_RESET_TMR0	34
+#define MA35D1_RESET_TMR1	35
+#define MA35D1_RESET_TMR2	36
+#define MA35D1_RESET_TMR3	37
+#define MA35D1_RESET_I2C0	40
+#define MA35D1_RESET_I2C1	41
+#define MA35D1_RESET_I2C2	42
+#define MA35D1_RESET_I2C3	43
+#define MA35D1_RESET_QSPI0	44
+#define MA35D1_RESET_SPI0	45
+#define MA35D1_RESET_SPI1	46
+#define MA35D1_RESET_SPI2	47
+#define MA35D1_RESET_UART0	48

include/dt-bindings/reset/nuvoton,ma35d1-reset.h line 64

Quoted 10 lines
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +10 -0
+#define MA35D1_RESET_UART1	49
+#define MA35D1_RESET_UART2	50
+#define MA35D1_RESET_UAER3	51
+#define MA35D1_RESET_UART4	52
+#define MA35D1_RESET_UART5	53
+#define MA35D1_RESET_UART6	54
+#define MA35D1_RESET_UART7	55
+#define MA35D1_RESET_CANFD0	56
+#define MA35D1_RESET_CANFD1	57
+#define MA35D1_RESET_EADC0	60

Why do you have gaps here? These should be IDs, not register offsets.

Quoted 7 lines
Quoted 3 lines

Best regards,
Krzysztof

The reset controller registers are composed of four 32-bits register. And the ID will be translated into the corresponding bit of these register. Each ID is mapped to a unique bit position.

That's not the usual way. IDs start from 0 or 1 and gets incremented by 1, without gaps. Remember that IDs cannot change and your register bits could have some changes (e.g. HW errata).

Best regards,
Krzysztof

#11 lore raw

Re: [PATCH v6 04/12] dt-bindings: reset: nuvoton: add binding for ma35d1 IP reset control

Dear Krzysztof,

Quoted 29 lines · Krzysztof Kozlowski
Quoted 28 lines · Jacky Huang
Quoted 13 lines

include/dt-bindings/reset/nuvoton,ma35d1-reset.h line 1

Quoted 11 lines
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +4 -0
+        };
+    };
+...
+
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +1 -0
new file mode 100644
index 000000000000..f3088bc0afec
@@ -0,0 +1,108 @@
+/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-2-Clause) */

Weird license, why 2.0+?

Quoted 3 lines

You already got here comment about license in previous version of this patch.

In fact, I always be confused with the license.
It should be right if I just copy one from the same directory /include/dt-bindings/reset/.
But, when I find there are several versions there, I was confused and just select one of them.

/* SPDX-License-Identifier: GPL-2.0-only */
/* SPDX-License-Identifier: GPL-2.0+ */
/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)*/ /* SPDX-License-Identifier: (GPL-2.0+ or MIT) */
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */

Quoted 7 lines
Quoted 5 lines

So, should I fix the license as

/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */

just remove the '+' ?

The simplest is to use the same license as your binding, so (GPL-2.0-only OR BSD-2-Clause) .

OK, I got it. Thank you very much.

Quoted 71 lines
Quoted 65 lines
Quoted 65 lines
Quoted 53 lines
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +53 -0
+/*
+ * Copyright (C) 2023 Nuvoton Technologies.
+ * Author: Chi-Fen Li <[email protected]>
+ *
+ * Device Tree binding constants for MA35D1 reset controller.
+ */
+
+#ifndef __DT_BINDINGS_RESET_MA35D1_H
+#define __DT_BINDINGS_RESET_MA35D1_H
+
+#define MA35D1_RESET_CHIP	0
+#define MA35D1_RESET_CA35CR0	1
+#define MA35D1_RESET_CA35CR1	2
+#define MA35D1_RESET_CM4	3
+#define MA35D1_RESET_PDMA0	4
+#define MA35D1_RESET_PDMA1	5
+#define MA35D1_RESET_PDMA2	6
+#define MA35D1_RESET_PDMA3	7
+#define MA35D1_RESET_DISP	9
+#define MA35D1_RESET_VCAP0	10
+#define MA35D1_RESET_VCAP1	11
+#define MA35D1_RESET_GFX	12
+#define MA35D1_RESET_VDEC	13
+#define MA35D1_RESET_WHC0	14
+#define MA35D1_RESET_WHC1	15
+#define MA35D1_RESET_GMAC0	16
+#define MA35D1_RESET_GMAC1	17
+#define MA35D1_RESET_HWSEM	18
+#define MA35D1_RESET_EBI	19
+#define MA35D1_RESET_HSUSBH0	20
+#define MA35D1_RESET_HSUSBH1	21
+#define MA35D1_RESET_HSUSBD	22
+#define MA35D1_RESET_USBHL	23
+#define MA35D1_RESET_SDH0	24
+#define MA35D1_RESET_SDH1	25
+#define MA35D1_RESET_NAND	26
+#define MA35D1_RESET_GPIO	27
+#define MA35D1_RESET_MCTLP	28
+#define MA35D1_RESET_MCTLC	29
+#define MA35D1_RESET_DDRPUB	30
+#define MA35D1_RESET_TMR0	34
+#define MA35D1_RESET_TMR1	35
+#define MA35D1_RESET_TMR2	36
+#define MA35D1_RESET_TMR3	37
+#define MA35D1_RESET_I2C0	40
+#define MA35D1_RESET_I2C1	41
+#define MA35D1_RESET_I2C2	42
+#define MA35D1_RESET_I2C3	43
+#define MA35D1_RESET_QSPI0	44
+#define MA35D1_RESET_SPI0	45
+#define MA35D1_RESET_SPI1	46
+#define MA35D1_RESET_SPI2	47
+#define MA35D1_RESET_UART0	48

include/dt-bindings/reset/nuvoton,ma35d1-reset.h line 64

Quoted 10 lines
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +10 -0
+#define MA35D1_RESET_UART1	49
+#define MA35D1_RESET_UART2	50
+#define MA35D1_RESET_UAER3	51
+#define MA35D1_RESET_UART4	52
+#define MA35D1_RESET_UART5	53
+#define MA35D1_RESET_UART6	54
+#define MA35D1_RESET_UART7	55
+#define MA35D1_RESET_CANFD0	56
+#define MA35D1_RESET_CANFD1	57
+#define MA35D1_RESET_EADC0	60

Why do you have gaps here? These should be IDs, not register offsets.

Quoted 6 lines
Quoted 3 lines

Best regards,
Krzysztof

The reset controller registers are composed of four 32-bits register. And the ID will be translated into the corresponding bit of these register. Each ID is mapped to a unique bit position.

Quoted 8 lines

That's not the usual way. IDs start from 0 or 1 and gets incremented by 1, without gaps. Remember that IDs cannot change and your register bits could have some changes (e.g. HW errata).

Best regards,
Krzysztof

OK, I will modify the ID as contiguous number, and create a lookup table to translate ID into bitmap.

Best Regards,
Jacky Huang

#12 lore raw

PATCH v6 5/12 dt-bindings: mfd: syscon: Add nuvoton,ma35d1-sys compatible

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Add Nuvoton ma35d1 system registers compatible.

---
 Documentation/devicetree/bindings/mfd/syscon.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/mfd/syscon.yaml +1 -0
index c828c4f5e4a7..7ee1d27f59dd 100644
@@ -56,6 +56,7 @@ properties:
               - microchip,lan966x-cpu-syscon
               - microchip,sparx5-cpu-syscon
               - mstar,msc313-pmsleep
+              - nuvoton,ma35d1-sys
               - nuvoton,wpcm450-shm
               - rockchip,px30-qos
               - rockchip,rk3036-qos
Signature · 1 line
2.34.1
maintainer Applied
#13 lore raw

Re: [PATCH v6 05/12] dt-bindings: mfd: syscon: Add nuvoton,ma35d1-sys compatible

Quoted 8 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Add Nuvoton ma35d1 system registers compatible.

---
 Documentation/devicetree/bindings/mfd/syscon.yaml | 1 +
 1 file changed, 1 insertion(+)

Applied, thanks

--
Lee Jones [李琼斯]

#14 lore raw

PATCH v6 6/12 dt-bindings: arm: Add initial bindings for Nuvoton platform

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Rename the bindings/arm/npcm directory as nuvoton. Add binding for ARMv8 based Nuvotn SoCs and platform boards. Add initial bindings for ma35d1 series development boards.

---
 .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  | 30 +++++++++++++++++++
 .../nuvoton,npcm-gcr.yaml}                    |  2 +-
 .../npcm.yaml => nuvoton/nuvoton,npcm.yaml}   |  2 +-
 3 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml
 rename Documentation/devicetree/bindings/arm/{npcm/nuvoton,gcr.yaml => nuvoton/nuvoton,npcm-gcr.yaml} (93%)
 rename Documentation/devicetree/bindings/arm/{npcm/npcm.yaml => nuvoton/nuvoton,npcm.yaml} (93%)
Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml new file +30 -0
new file mode 100644
index 000000000000..fb190db61525
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/nuvoton/nuvoton,ma35d1.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35 series SoC based platforms
+
+maintainers:
+  - Jacky Huang <[email protected]>
+
+description: |
+  Boards with an ARMv8 based Nuvoton MA35 series SoC shall have
+  the following properties.
+
+properties:
+  $nodename:
+    const: '/'
+  compatible:
+    oneOf:
+
+      - description: MA35D1 based boards
+        items:
+          - enum:
+              - nuvoton,ma35d1-iot
+              - nuvoton,ma35d1-som
+          - const: nuvoton,ma35d1
+
+additionalProperties: true
+...
Documentation/devicetree/bindings/arm/nuvoton/nuvoton,npcm-gcr.yaml renamed from Documentation/devicetree/bindings/arm/npcm/nuvoton,gcr.yaml +1 -1
similarity index 93%
rename from Documentation/devicetree/bindings/arm/npcm/nuvoton,gcr.yaml
rename to Documentation/devicetree/bindings/arm/nuvoton/nuvoton,npcm-gcr.yaml
index 94e72f25b331..1f354aa900ea 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
 %YAML 1.2
 ---
-$id: http://devicetree.org/schemas/arm/npcm/nuvoton,gcr.yaml#
+$id: http://devicetree.org/schemas/arm/nuvoton/nuvoton,npcm-gcr.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
 title: Global Control Registers block in Nuvoton SoCs
Documentation/devicetree/bindings/arm/nuvoton/nuvoton,npcm.yaml renamed from Documentation/devicetree/bindings/arm/npcm/npcm.yaml +1 -1
similarity index 93%
rename from Documentation/devicetree/bindings/arm/npcm/npcm.yaml
rename to Documentation/devicetree/bindings/arm/nuvoton/nuvoton,npcm.yaml
index 6871483947c5..d386744c8815 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
 %YAML 1.2
 ---
-$id: http://devicetree.org/schemas/arm/npcm/npcm.yaml#
+$id: http://devicetree.org/schemas/arm/nuvoton/nuvoton,npcm.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
 title: NPCM Platforms
Signature · 1 line
2.34.1
#15 lore raw

Re: [PATCH v6 06/12] dt-bindings: arm: Add initial bindings for Nuvoton platform

Thank you for the patch! Perhaps something to improve:

Hi Jacky,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on robh/for-next]
[also build test WARNING on clk/clk-next linus/master pza/reset/next v6.3-rc4 next-20230328] [cannot apply to pza/imx-drm/next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jacky-Huang/arm64-Kconfig-platforms-Add-config-for-Nuvoton-MA35-platform/20230328-102245
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20230328021912.177301-7-ychuang570808%40gmail.com
patch subject: [PATCH v6 06/12] dt-bindings: arm: Add initial bindings for Nuvoton platform
reproduce:
        # https://github.com/intel-lab-lkp/linux/commit/d023e63cdc203398c5db3c81ca76d34d22e23fe5
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jacky-Huang/arm64-Kconfig-platforms-Add-config-for-Nuvoton-MA35-platform/20230328-102245
        git checkout d023e63cdc203398c5db3c81ca76d34d22e23fe5
        make menuconfig
        # enable CONFIG_COMPILE_TEST, CONFIG_WARN_MISSING_DOCUMENTS, CONFIG_WARN_ABI_ERRORS
        make htmldocs

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> Warning: MAINTAINERS references a file that doesn't exist: Documentation/devicetree/bindings/arm/npcm/*
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#16 lore raw

Re: [PATCH v6 06/12] dt-bindings: arm: Add initial bindings for Nuvoton platform

In reply to Jacky Huang
Quoted 4 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Rename the bindings/arm/npcm directory as nuvoton. Add binding for ARMv8 based Nuvotn SoCs and platform boards.

Typo: Nucotn?

Quoted 5 lines

Add initial bindings for ma35d1 series development boards.

---
 .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  | 30 +++++++++++++++++++

Anyway robot pointed to issues here...

Best regards,
Krzysztof

#17 lore raw

Re: [PATCH v6 06/12] dt-bindings: arm: Add initial bindings for Nuvoton platform

Dear Krzysztof,

Quoted 6 lines · Krzysztof Kozlowski
Quoted 4 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Rename the bindings/arm/npcm directory as nuvoton. Add binding for ARMv8 based Nuvotn SoCs and platform boards.

Typo: Nucotn?

I will fix it. Thank you.

Quoted 11 lines
Quoted 5 lines

Add initial bindings for ma35d1 series development boards.

---
  .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  | 30 +++++++++++++++++++

Anyway robot pointed to issues here...

Best regards,
Krzysztof

The robot report path error in MAINTAINER. I should modify it when I rename the npcm directory.

Best regards,
Jacky Huang

#18 lore raw

Re: [PATCH v6 06/12] dt-bindings: arm: Add initial bindings for Nuvoton platform

In reply to Jacky Huang
Quoted 7 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Rename the bindings/arm/npcm directory as nuvoton. Add binding for ARMv8 based Nuvotn SoCs and platform boards. Add initial bindings for ma35d1 series development boards.

Quoted 8 lines
---
 .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  | 30 +++++++++++++++++++
 .../nuvoton,npcm-gcr.yaml}                    |  2 +-
 .../npcm.yaml => nuvoton/nuvoton,npcm.yaml}   |  2 +-
 3 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml
 rename Documentation/devicetree/bindings/arm/{npcm/nuvoton,gcr.yaml => nuvoton/nuvoton,npcm-gcr.yaml} (93%)

Since you are moving it, this one should be moved to bindings/soc/nuvoton/

Quoted 1 line
 rename Documentation/devicetree/bindings/arm/{npcm/npcm.yaml => nuvoton/nuvoton,npcm.yaml} (93%)
#19 lore raw

Re: [PATCH v6 06/12] dt-bindings: arm: Add initial bindings for Nuvoton platform

Dear Rob,

Quoted 15 lines · Rob Herring
Quoted 6 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Rename the bindings/arm/npcm directory as nuvoton. Add binding for ARMv8 based Nuvotn SoCs and platform boards. Add initial bindings for ma35d1 series development boards.

Quoted 8 lines
---
  .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  | 30 +++++++++++++++++++
  .../nuvoton,npcm-gcr.yaml}                    |  2 +-
  .../npcm.yaml => nuvoton/nuvoton,npcm.yaml}   |  2 +-
  3 files changed, 32 insertions(+), 2 deletions(-)

create mode 100644 Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml rename Documentation/devicetree/bindings/arm/{npcm/nuvoton,gcr.yaml => nuvoton/nuvoton,npcm-gcr.yaml} (93%)

Quoted 3 lines

Since you are moving it, this one should be moved to bindings/soc/nuvoton/

Quoted 1 line

rename Documentation/devicetree/bindings/arm/{npcm/npcm.yaml => nuvoton/nuvoton,npcm.yaml} (93%)

OK, I will move "Documentation/devicetree/bindings/arm/npcm" to "Documentation/devicetree/bindings/soc/nuvoton".

Best regards,
Jacky Huang

#20 lore raw

Re: [PATCH v6 06/12] dt-bindings: arm: Add initial bindings for Nuvoton platform

Quoted 19 lines · Jacky Huang

Dear Rob,

Quoted 15 lines · Rob Herring
Quoted 14 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Rename the bindings/arm/npcm directory as nuvoton. Add binding for ARMv8 based Nuvotn SoCs and platform boards. Add initial bindings for ma35d1 series development boards.

---
  .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  | 30 +++++++++++++++++++
  .../nuvoton,npcm-gcr.yaml}                    |  2 +-
  .../npcm.yaml => nuvoton/nuvoton,npcm.yaml}   |  2 +-
  3 files changed, 32 insertions(+), 2 deletions(-)

create mode 100644 Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml rename Documentation/devicetree/bindings/arm/{npcm/nuvoton,gcr.yaml => nuvoton/nuvoton,npcm-gcr.yaml} (93%)

Quoted 6 lines
Quoted 3 lines

Since you are moving it, this one should be moved to bindings/soc/nuvoton/

Quoted 1 line

rename Documentation/devicetree/bindings/arm/{npcm/npcm.yaml => nuvoton/nuvoton,npcm.yaml} (93%)

OK, I will move "Documentation/devicetree/bindings/arm/npcm" to "Documentation/devicetree/bindings/soc/nuvoton".

To clarify - Rob asked *this one*. Not all.

Best regards,
Krzysztof

#21 lore raw

Re: [PATCH v6 06/12] dt-bindings: arm: Add initial bindings for Nuvoton platform

Quoted 23 lines · Krzysztof Kozlowski
Quoted 22 lines · Jacky Huang

Dear Rob,

Quoted 18 lines · Rob Herring
Quoted 6 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Rename the bindings/arm/npcm directory as nuvoton. Add binding for ARMv8 based Nuvotn SoCs and platform boards. Add initial bindings for ma35d1 series development boards.

Quoted 8 lines
---
   .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  | 30 +++++++++++++++++++
   .../nuvoton,npcm-gcr.yaml}                    |  2 +-
   .../npcm.yaml => nuvoton/nuvoton,npcm.yaml}   |  2 +-
   3 files changed, 32 insertions(+), 2 deletions(-)

create mode 100644 Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml rename Documentation/devicetree/bindings/arm/{npcm/nuvoton,gcr.yaml => nuvoton/nuvoton,npcm-gcr.yaml} (93%)

Since you are moving it, this one should be moved to bindings/soc/nuvoton/

Quoted 1 line

rename Documentation/devicetree/bindings/arm/{npcm/npcm.yaml => nuvoton/nuvoton,npcm.yaml} (93%)

Quoted 9 lines
Quoted 2 lines

OK, I will move "Documentation/devicetree/bindings/arm/npcm" to "Documentation/devicetree/bindings/soc/nuvoton".

To clarify - Rob asked *this one*. Not all.

Best regards,
Krzysztof

Dear Krzysztof,

I am sorry that still cannot get it exactly.

1. Just only submit  the nuvoton,ma35d1.yaml to Documentation/devicetree/bindings/soc/nuvoton/nuvoton,ma35d1.yaml and keep Documentation/devicetree/bindings/arm/npcm unchanged

2. Move the directory "Documentation/devicetree/bindings/arm/npcm" to "Documentation/devicetree/bindings/soc/nuvoton" and submit  the nuvoton,ma35d1.yaml to "Documentation/devicetree/bindings/soc/nuvoton"

I should do 1 or 2?  Thank you very much.

Best regards,
Jacky Huang

maintainer
#22 lore raw

Re: [PATCH v6 06/12] dt-bindings: arm: Add initial bindings for Nuvoton platform

Quoted 23 lines · Jacky Huang
Quoted 20 lines · Krzysztof Kozlowski
Quoted 19 lines · Jacky Huang

Dear Rob,

Quoted 15 lines · Rob Herring
Quoted 14 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Rename the bindings/arm/npcm directory as nuvoton. Add binding for ARMv8 based Nuvotn SoCs and platform boards. Add initial bindings for ma35d1 series development boards.

---
   .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  | 30 +++++++++++++++++++
   .../nuvoton,npcm-gcr.yaml}                    |  2 +-
   .../npcm.yaml => nuvoton/nuvoton,npcm.yaml}   |  2 +-
   3 files changed, 32 insertions(+), 2 deletions(-)

create mode 100644 Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml rename Documentation/devicetree/bindings/arm/{npcm/nuvoton,gcr.yaml => nuvoton/nuvoton,npcm-gcr.yaml} (93%)

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Since you are moving it, this one should be moved to bindings/soc/nuvoton/

Quoted 1 line

rename Documentation/devicetree/bindings/arm/{npcm/npcm.yaml => nuvoton/nuvoton,npcm.yaml} (93%)

OK, I will move "Documentation/devicetree/bindings/arm/npcm" to "Documentation/devicetree/bindings/soc/nuvoton".

To clarify - Rob asked *this one*. Not all.

nuvoton,gcr.yaml is what should be moved to bindings/soc/... The rest are the correct locations.

Quoted 15 lines
Quoted 6 lines

Best regards,
Krzysztof

Dear Krzysztof,

I am sorry that still cannot get it exactly.

1. Just only submit  the nuvoton,ma35d1.yaml to Documentation/devicetree/bindings/soc/nuvoton/nuvoton,ma35d1.yaml and keep Documentation/devicetree/bindings/arm/npcm unchanged

Quoted 6 lines

2. Move the directory "Documentation/devicetree/bindings/arm/npcm" to "Documentation/devicetree/bindings/soc/nuvoton"
   and submit  the nuvoton,ma35d1.yaml to "Documentation/devicetree/bindings/soc/nuvoton"

I should do 1 or 2?  Thank you very much.

Neither.

Arm board and soc root node bindings go in bindings/arm/...

Miscellaneous system registers that don't fit into any other bindings/* subsystem directory go in bindings/soc/

Rob

#23 lore raw

Re: [PATCH v6 06/12] dt-bindings: arm: Add initial bindings for Nuvoton platform

Quoted 51 lines · Rob Herring
Quoted 22 lines · Jacky Huang
Quoted 20 lines · Krzysztof Kozlowski
Quoted 19 lines · Jacky Huang

Dear Rob,

Quoted 15 lines · Rob Herring
Quoted 14 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Rename the bindings/arm/npcm directory as nuvoton. Add binding for ARMv8 based Nuvotn SoCs and platform boards. Add initial bindings for ma35d1 series development boards.

---
    .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  | 30 +++++++++++++++++++
    .../nuvoton,npcm-gcr.yaml}                    |  2 +-
    .../npcm.yaml => nuvoton/nuvoton,npcm.yaml}   |  2 +-
    3 files changed, 32 insertions(+), 2 deletions(-)

create mode 100644 Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml rename Documentation/devicetree/bindings/arm/{npcm/nuvoton,gcr.yaml => nuvoton/nuvoton,npcm-gcr.yaml} (93%)

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Since you are moving it, this one should be moved to bindings/soc/nuvoton/

Quoted 1 line

rename Documentation/devicetree/bindings/arm/{npcm/npcm.yaml => nuvoton/nuvoton,npcm.yaml} (93%)

OK, I will move "Documentation/devicetree/bindings/arm/npcm" to "Documentation/devicetree/bindings/soc/nuvoton".

To clarify - Rob asked *this one*. Not all.

nuvoton,gcr.yaml is what should be moved to bindings/soc/... The rest are the correct locations.

Quoted 13 lines
Quoted 5 lines

Best regards,
Krzysztof

Dear Krzysztof,

I am sorry that still cannot get it exactly.

1. Just only submit  the nuvoton,ma35d1.yaml to Documentation/devicetree/bindings/soc/nuvoton/nuvoton,ma35d1.yaml and keep Documentation/devicetree/bindings/arm/npcm unchanged

Quoted 6 lines

2. Move the directory "Documentation/devicetree/bindings/arm/npcm" to "Documentation/devicetree/bindings/soc/nuvoton"
   and submit  the nuvoton,ma35d1.yaml to
"Documentation/devicetree/bindings/soc/nuvoton"

I should do 1 or 2?  Thank you very much.

Quoted 8 lines

Neither.

Arm board and soc root node bindings go in bindings/arm/...

Miscellaneous system registers that don't fit into any other bindings/* subsystem directory go in bindings/soc/

Rob

Dear Rob,

Thank you very much. I got it now.

Best regards,
Jacky Huang

#24 lore raw

PATCH v6 7/12 dt-bindings: serial: Document ma35d1 uart controller

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Add documentation to describe nuvoton ma35d1 uart driver bindings.

---
 .../serial/nuvoton,ma35d1-serial.yaml         | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.yaml
Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.yaml new file +48 -0
new file mode 100644
index 000000000000..a76af0f6009b
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/serial/nuvoton,ma35d1-serial.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 Universal Asynchronous Receiver/Transmitter (UART)
+
+maintainers:
+  - Min-Jen Chen <[email protected]>
+  - Jacky Huang <[email protected]>
+
+allOf:
+  - $ref: serial.yaml
+
+properties:
+  compatible:
+    const: nuvoton,ma35d1-uart
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
+
+    serial@40700000 {
+        compatible = "nuvoton,ma35d1-uart";
+        reg = <0x40700000 0x100>;
+        interrupts = <GIC_SPI 59 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clk UART0_GATE>;
+    };
+...
Signature · 1 line
2.34.1
#26 lore raw

Re: [PATCH v6 07/12] dt-bindings: serial: Document ma35d1 uart controller

Dear Krzysztof,

Thanks for your review.

Quoted 12 lines · Krzysztof Kozlowski
Quoted 4 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Add documentation to describe nuvoton ma35d1 uart driver bindings.

This depends on clock patches, so it must be taken together.

Best regards,
Krzysztof

OK, I will combine this patch with the clock patch.

Best regards,
Jacky Huang

#27 lore raw

Re: [PATCH v6 07/12] dt-bindings: serial: Document ma35d1 uart controller

Quoted 14 lines · Jacky Huang

Dear Krzysztof,

Thanks for your review.

Quoted 7 lines · Krzysztof Kozlowski
Quoted 4 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Add documentation to describe nuvoton ma35d1 uart driver bindings.

This depends on clock patches, so it must be taken together.

Quoted 7 lines
Quoted 5 lines

Best regards,
Krzysztof

OK, I will combine this patch with the clock patch.

I don't know what you mean by "combine", but I don't think this is what we want. You must clearly state all dependencies and patch merging strategy/way.

Best regards,
Krzysztof

#28 lore raw

Re: [PATCH v6 07/12] dt-bindings: serial: Document ma35d1 uart controller

Quoted 20 lines · Krzysztof Kozlowski
Quoted 19 lines · Jacky Huang

Dear Krzysztof,

Thanks for your review.

Quoted 12 lines · Krzysztof Kozlowski
Quoted 4 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Add documentation to describe nuvoton ma35d1 uart driver bindings.

This depends on clock patches, so it must be taken together.

Best regards,
Krzysztof

Quoted 8 lines
Quoted 1 line

OK, I will combine this patch with the clock patch.

I don't know what you mean by "combine", but I don't think this is what we want. You must clearly state all dependencies and patch merging strategy/way.

Best regards,
Krzysztof

Dear Krzysztof,

I may be misunderstanding your request.
I thought it was moving the "nuvoton,ma35d1-serial.yaml" to the patch of nuvoton,ma35d1-clk.h. Would you please provide guidance what should I do next on this [PATCH v6 07/12]. Thank you.

Best regards,
Jacky Huang

maintainer
#29 lore raw

Re: [PATCH v6 07/12] dt-bindings: serial: Document ma35d1 uart controller

Quoted 32 lines · Jacky Huang
Quoted 20 lines · Krzysztof Kozlowski
Quoted 19 lines · Jacky Huang

Dear Krzysztof,

Thanks for your review.

Quoted 12 lines · Krzysztof Kozlowski
Quoted 4 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Add documentation to describe nuvoton ma35d1 uart driver bindings.

This depends on clock patches, so it must be taken together.

Best regards,
Krzysztof

Quoted 8 lines
Quoted 1 line

OK, I will combine this patch with the clock patch.

I don't know what you mean by "combine", but I don't think this is what we want. You must clearly state all dependencies and patch merging strategy/way.

Best regards,
Krzysztof

Quoted 8 lines

Dear Krzysztof,

I may be misunderstanding your request.
I thought it was moving the "nuvoton,ma35d1-serial.yaml" to the patch of nuvoton,ma35d1-clk.h.
Would you please provide guidance what should I do next on this [PATCH v6 07/12]. Thank you.

The only combining you should do is putting the 2 patches in the same series. Combining to 1 patch would be wrong.

Your other option is just drop the header in the example and use the raw numbers. Then there is no dependency to manage and each subsystem maintainer can take the relevant patches.

Rob

#30 lore raw

Re: [PATCH v6 07/12] dt-bindings: serial: Document ma35d1 uart controller

Quoted 39 lines · Rob Herring
Quoted 30 lines · Jacky Huang
Quoted 20 lines · Krzysztof Kozlowski
Quoted 19 lines · Jacky Huang

Dear Krzysztof,

Thanks for your review.

Quoted 12 lines · Krzysztof Kozlowski
Quoted 4 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Add documentation to describe nuvoton ma35d1 uart driver bindings.

This depends on clock patches, so it must be taken together.

Best regards,
Krzysztof

Quoted 8 lines
Quoted 1 line

OK, I will combine this patch with the clock patch.

I don't know what you mean by "combine", but I don't think this is what we want. You must clearly state all dependencies and patch merging strategy/way.

Best regards,
Krzysztof

Quoted 8 lines

Dear Krzysztof,

I may be misunderstanding your request.
I thought it was moving the "nuvoton,ma35d1-serial.yaml" to the patch of nuvoton,ma35d1-clk.h.
Would you please provide guidance what should I do next on this [PATCH v6 07/12]. Thank you.

Quoted 8 lines

The only combining you should do is putting the 2 patches in the same series. Combining to 1 patch would be wrong.

Your other option is just drop the header in the example and use the raw numbers. Then there is no dependency to manage and each subsystem maintainer can take the relevant patches.

Rob

Dear Rob,

Thanks for your detailed explanation. I got it now.

Best regards,
Jacky Huang

#31 lore raw

PATCH v6 8/12 arm64: dts: nuvoton: Add initial ma35d1 device tree

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Add initial device tree support for Nuvoton ma35d1 SoC, including cpu, clock, reset, and serial controllers.
Add reference boards som-256m and iot-512m.

---
 arch/arm64/boot/dts/nuvoton/Makefile          |   2 +
 .../boot/dts/nuvoton/ma35d1-iot-512m.dts      |  56 +++++
 .../boot/dts/nuvoton/ma35d1-som-256m.dts      |  56 +++++
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       | 231 ++++++++++++++++++
 4 files changed, 345 insertions(+)
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi
arch/arm64/boot/dts/nuvoton/Makefile +2 -0
index a99dab90472a..c11ab4eac9c7 100644
@@ -1,2 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 dtb-$(CONFIG_ARCH_NPCM) += nuvoton-npcm845-evb.dtb
+dtb-$(CONFIG_ARCH_NUVOTON) += ma35d1-iot-512m.dtb
+dtb-$(CONFIG_ARCH_NUVOTON) += ma35d1-som-256m.dtb
arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts new file +56 -0

56 lines not on this page · raw message

arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts new file +56 -0

56 lines not on this page · raw message

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +231 -0

231 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#32 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Quoting Jacky Huang (2023-03-27 19:19:08)

Quoted 36 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +30 -0
new file mode 100644
index 000000000000..0740b0b218a7
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 Nuvoton Technology Corp.
+ * Author: Shan-Chun Hung <[email protected]>
+ *         Jacky huang <[email protected]>
+ */
+
+#include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <dt-bindings/input/input.h>
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
+#include <dt-bindings/reset/nuvoton,ma35d1-reset.h>
+
+/ {
+       compatible = "nuvoton,ma35d1";
+       interrupt-parent = <&gic>;
+       #address-cells = <2>;
+       #size-cells = <2>;
+
+       cpus {
+               #address-cells = <2>;
+               #size-cells = <0>;
+
+               cpu0: cpu@0 {
+                       device_type = "cpu";
+                       compatible = "arm,cortex-a35";
+                       reg = <0x0 0x0>;
+                       enable-method = "psci";
+                       next-level-cache = <&L2_0>;
+               };

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 40

Quoted 10 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +10 -0
+
+               cpu1: cpu@1 {
+                       device_type = "cpu";
+                       compatible = "arm,cortex-a35";
+                       reg = <0x0 0x1>;
+                       enable-method = "psci";
+                       next-level-cache = <&L2_0>;
+               };
+
+               L2_0: l2-cache0 {

Just l2-cache for the node name. Doesn't it go under the cpu0 node as well?

Quoted 11 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +11 -0
+                       compatible = "cache";
+                       cache-level = <2>;
+               };
+       };
+
+       psci {
+               compatible = "arm,psci-0.2";
+               method = "smc";
+       };
+
+       timer {

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 61

Quoted 10 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +10 -0
+               compatible = "arm,armv8-timer";
+               interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(4) |
+                             IRQ_TYPE_LEVEL_LOW)>, /* Physical Secure */
+                            <GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(4) |
+                             IRQ_TYPE_LEVEL_LOW)>, /* Physical Non-Secure */
+                            <GIC_PPI 11 (GIC_CPU_MASK_SIMPLE(4) |
+                             IRQ_TYPE_LEVEL_LOW)>, /* Virtual */
+                            <GIC_PPI 10 (GIC_CPU_MASK_SIMPLE(4) |
+                             IRQ_TYPE_LEVEL_LOW)>; /* Hypervisor */
+               clock-frequency = <12000000>;

Remove this property. The frequency should be read by the driver.

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 63

Quoted 2 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +2 -0
+               interrupt-parent = <&gic>;
+       };

Please create an 'soc' node for the SoC to hold all the nodes that have a reg property.

Quoted 8 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +8 -0
+
+       sys: system-management@40460000 {
+               compatible = "nuvoton,ma35d1-sys", "syscon", "simple-mfd";
+               reg = <0x0 0x40460000 0x0 0x200>;
+
+               reset: reset-controller {
+                       compatible = "nuvoton,ma35d1-reset";
+                       #reset-cells = <1>;

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 81

Quoted 10 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +10 -0
+               };
+       };
+
+       clk: clock-controller@40460200 {
+               compatible = "nuvoton,ma35d1-clk", "syscon";
+               reg = <0x00000000 0x40460200 0x0 0x100>;
+               #clock-cells = <1>;
+               clocks = <&clk_hxt>;
+               nuvoton,sys = <&sys>;
+       };

It looks like the device at 40460000 is a reset and clock controller. Just make it one node and register the clk or reset device as an auxiliary device.

Quoted 5 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +5 -0
+
+       gic: interrupt-controller@50801000 {
+               compatible = "arm,gic-400";
+               reg =   <0x0 0x50801000 0 0x1000>, /* GICD */
+                       <0x0 0x50802000 0 0x2000>, /* GICC */

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 96

Quoted 10 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +10 -0
+                       <0x0 0x50804000 0 0x2000>, /* GICH */
+                       <0x0 0x50806000 0 0x2000>; /* GICV */
+               #interrupt-cells = <3>;
+               interrupt-parent = <&gic>;
+               interrupt-controller;
+               interrupts = <GIC_PPI 9 (GIC_CPU_MASK_RAW(0x13) |
+                             IRQ_TYPE_LEVEL_HIGH)>;
+       };
+
+       uart0:serial@40700000 {

Add a space after :

Quoted 6 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +6 -0
+               compatible = "nuvoton,ma35d1-uart";
+               reg = <0x0 0x40700000 0x0 0x100>;
+               interrupts = <GIC_SPI 59 IRQ_TYPE_LEVEL_HIGH>;
+               clocks = <&clk UART0_GATE>;
+               status = "disabled";
+       };
#33 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Dear Stephen,

Thanks for your advice.

Quoted 41 lines · Stephen Boyd

Quoting Jacky Huang (2023-03-27 19:19:08)

Quoted 40 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +34 -0
new file mode 100644
index 000000000000..0740b0b218a7
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 Nuvoton Technology Corp.
+ * Author: Shan-Chun Hung <[email protected]>
+ *         Jacky huang <[email protected]>
+ */
+
+#include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <dt-bindings/input/input.h>
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
+#include <dt-bindings/reset/nuvoton,ma35d1-reset.h>
+
+/ {
+       compatible = "nuvoton,ma35d1";
+       interrupt-parent = <&gic>;
+       #address-cells = <2>;
+       #size-cells = <2>;
+
+       cpus {
+               #address-cells = <2>;
+               #size-cells = <0>;
+
+               cpu0: cpu@0 {
+                       device_type = "cpu";
+                       compatible = "arm,cortex-a35";
+                       reg = <0x0 0x0>;
+                       enable-method = "psci";
+                       next-level-cache = <&L2_0>;
+               };
+
+               cpu1: cpu@1 {
+                       device_type = "cpu";
+                       compatible = "arm,cortex-a35";
Quoted 8 lines

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 40

Quoted 6 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +6 -0
+                       reg = <0x0 0x1>;
+                       enable-method = "psci";
+                       next-level-cache = <&L2_0>;
+               };
+
+               L2_0: l2-cache0 {

Just l2-cache for the node name. Doesn't it go under the cpu0 node as well?

This describes the level-2 cache which is external to and shared by cpu0 & cpu1. And only level-1 cache is inside of CPU core.
L2_0 is must, because both cpu0 and cpu1 has a next-level-cache = <&L2_0> property.

Many identical example of l2-cache node can be found in arm64 dts, such as k3-arm642.dtsi, rk3328.dtsi, mt8195.dtsi, etc. Here is just a copy of similar arm64 multi-core SoCs.

So we would like to keep this unchanged. Is it OK for you? Thanks.

Quoted 14 lines
Quoted 14 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +14 -0
+                       compatible = "cache";
+                       cache-level = <2>;
+               };
+       };
+
+       psci {
+               compatible = "arm,psci-0.2";
+               method = "smc";
+       };
+
+       timer {
+               compatible = "arm,armv8-timer";
+               interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(4) |
+                             IRQ_TYPE_LEVEL_LOW)>, /* Physical Secure */
Quoted 8 lines

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 61

Quoted 7 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +7 -0
+                            <GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(4) |
+                             IRQ_TYPE_LEVEL_LOW)>, /* Physical Non-Secure */
+                            <GIC_PPI 11 (GIC_CPU_MASK_SIMPLE(4) |
+                             IRQ_TYPE_LEVEL_LOW)>, /* Virtual */
+                            <GIC_PPI 10 (GIC_CPU_MASK_SIMPLE(4) |
+                             IRQ_TYPE_LEVEL_LOW)>; /* Hypervisor */
+               clock-frequency = <12000000>;

Remove this property. The frequency should be read by the driver.

I will remove it.

Quoted 4 lines

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 63

Quoted 2 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +2 -0
+               interrupt-parent = <&gic>;
+       };

Please create an 'soc' node for the SoC to hold all the nodes that have a reg property.

OK, we will use soc node in the next version.

Quoted 13 lines
Quoted 13 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +13 -0
+
+       sys: system-management@40460000 {
+               compatible = "nuvoton,ma35d1-sys", "syscon", "simple-mfd";
+               reg = <0x0 0x40460000 0x0 0x200>;
+
+               reset: reset-controller {
+                       compatible = "nuvoton,ma35d1-reset";
+                       #reset-cells = <1>;
+               };
+       };
+
+       clk: clock-controller@40460200 {
+               compatible = "nuvoton,ma35d1-clk", "syscon";
Quoted 8 lines

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 81

Quoted 5 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +5 -0
+               reg = <0x00000000 0x40460200 0x0 0x100>;
+               #clock-cells = <1>;
+               clocks = <&clk_hxt>;
+               nuvoton,sys = <&sys>;
+       };

It looks like the device at 40460000 is a reset and clock controller. Just make it one node and register the clk or reset device as an auxiliary device.

40460000 is for system control registers, including power contrl, multifunction pin control, usb phy control, IP reset control, power-on setting information, and many other miscellaneous controls. The registers of reset controller is only a subset of system control registers.

40460200 is for clock controller which is independent of the system control integration
The register base of clock controller is very close to system controller, but in fact the two are independent.

Quoted 8 lines
Quoted 8 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +8 -0
+
+       gic: interrupt-controller@50801000 {
+               compatible = "arm,gic-400";
+               reg =   <0x0 0x50801000 0 0x1000>, /* GICD */
+                       <0x0 0x50802000 0 0x2000>, /* GICC */
+                       <0x0 0x50804000 0 0x2000>, /* GICH */
+                       <0x0 0x50806000 0 0x2000>; /* GICV */
+               #interrupt-cells = <3>;
Quoted 8 lines

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 96

Quoted 7 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +7 -0
+               interrupt-parent = <&gic>;
+               interrupt-controller;
+               interrupts = <GIC_PPI 9 (GIC_CPU_MASK_RAW(0x13) |
+                             IRQ_TYPE_LEVEL_HIGH)>;
+       };
+
+       uart0:serial@40700000 {

Add a space after :

I will fix it. Thank you.

Quoted 6 lines

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 102

Quoted 6 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +6 -0
+               compatible = "nuvoton,ma35d1-uart";
+               reg = <0x0 0x40700000 0x0 0x100>;
+               interrupts = <GIC_SPI 59 IRQ_TYPE_LEVEL_HIGH>;
+               clocks = <&clk UART0_GATE>;
+               status = "disabled";
+       };

Best regards,
Jacky Huang

maintainer
#34 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Quoting Jacky Huang (2023-03-28 19:03:24)

Quoted 8 lines · Stephen Boyd
Quoted 7 lines

Quoting Jacky Huang (2023-03-27 19:19:08)

Quoted 6 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +0 -0
new file mode 100644
index 000000000000..0740b0b218a7
@@ -0,0 +1,231 @@

[...]

Quoted 10 lines
Quoted 4 lines

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi

Quoted 2 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +2 -0
+
+               L2_0: l2-cache0 {

Just l2-cache for the node name. Doesn't it go under the cpu0 node as well?

This describes the level-2 cache which is external to and shared by cpu0 & cpu1.
And only level-1 cache is inside of CPU core.
L2_0 is must, because both cpu0 and cpu1 has a next-level-cache = <&L2_0> property.

Ok. The name should just be l2-cache then, not l2-cache0.

Quoted 8 lines

Many identical example of l2-cache node can be found in arm64 dts, such as k3-arm642.dtsi,
rk3328.dtsi, mt8195.dtsi, etc. Here is just a copy of similar arm64 multi-core SoCs.

So we would like to keep this unchanged. Is it OK for you? Thanks.

Mostly ok, yes.

Quoted 30 lines
Quoted 14 lines
Quoted 14 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +13 -0
+
+       sys: system-management@40460000 {
+               compatible = "nuvoton,ma35d1-sys", "syscon", "simple-mfd";
+               reg = <0x0 0x40460000 0x0 0x200>;
+
+               reset: reset-controller {
+                       compatible = "nuvoton,ma35d1-reset";
+                       #reset-cells = <1>;
+               };
+       };
+
+       clk: clock-controller@40460200 {
+               compatible = "nuvoton,ma35d1-clk", "syscon";
Quoted 8 lines

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 81

Quoted 5 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +5 -0
+               reg = <0x00000000 0x40460200 0x0 0x100>;
+               #clock-cells = <1>;
+               clocks = <&clk_hxt>;
+               nuvoton,sys = <&sys>;
+       };

It looks like the device at 40460000 is a reset and clock controller. Just make it one node and register the clk or reset device as an auxiliary device.

40460000 is for system control registers, including power contrl, multifunction pin control,
usb phy control, IP reset control, power-on setting information, and many other miscellaneous controls.
The registers of reset controller is only a subset of system control registers.

Quoted 4 lines

40460200 is for clock controller which is independent of the system control integration
The register base of clock controller is very close to system controller, but in fact the two are independent.

What do you use the syscon for then? The clock driver must want to use the syscon for something, implying that they are the same device.

#35 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Dear Stephen,

Quoted 12 lines · Stephen Boyd

Quoting Jacky Huang (2023-03-28 19:03:24)

Quoted 8 lines · Stephen Boyd
Quoted 7 lines

Quoting Jacky Huang (2023-03-27 19:19:08)

Quoted 6 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +0 -0
new file mode 100644
index 000000000000..0740b0b218a7
@@ -0,0 +1,231 @@

[...]

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +2 -0
+
+               L2_0: l2-cache0 {
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Just l2-cache for the node name. Doesn't it go under the cpu0 node as well?

This describes the level-2 cache which is external to and shared by cpu0 & cpu1.
And only level-1 cache is inside of CPU core.
L2_0 is must, because both cpu0 and cpu1 has a next-level-cache = <&L2_0> property.

Ok. The name should just be l2-cache then, not l2-cache0.

OK, I will fix it.

Quoted 8 lines
Quoted 7 lines

Many identical example of l2-cache node can be found in arm64 dts, such as k3-arm642.dtsi,
rk3328.dtsi, mt8195.dtsi, etc. Here is just a copy of similar arm64 multi-core SoCs.

So we would like to keep this unchanged. Is it OK for you? Thanks.

Mostly ok, yes.

Thank you for the agreement.

Quoted 29 lines
Quoted 29 lines
Quoted 14 lines
Quoted 14 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +13 -0
+
+       sys: system-management@40460000 {
+               compatible = "nuvoton,ma35d1-sys", "syscon", "simple-mfd";
+               reg = <0x0 0x40460000 0x0 0x200>;
+
+               reset: reset-controller {
+                       compatible = "nuvoton,ma35d1-reset";
+                       #reset-cells = <1>;
+               };
+       };
+
+       clk: clock-controller@40460200 {
+               compatible = "nuvoton,ma35d1-clk", "syscon";
Quoted 8 lines

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 81

Quoted 5 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +5 -0
+               reg = <0x00000000 0x40460200 0x0 0x100>;
+               #clock-cells = <1>;
+               clocks = <&clk_hxt>;
+               nuvoton,sys = <&sys>;
+       };

It looks like the device at 40460000 is a reset and clock controller. Just make it one node and register the clk or reset device as an auxiliary device.

40460000 is for system control registers, including power contrl, multifunction pin control,
usb phy control, IP reset control, power-on setting information, and many other miscellaneous controls.
The registers of reset controller is only a subset of system control registers.

Quoted 6 lines
Quoted 4 lines

40460200 is for clock controller which is independent of the system control integration
The register base of clock controller is very close to system controller, but in fact the two are independent.

What do you use the syscon for then? The clock driver must want to use the syscon for something, implying that they are the same device.

The register lock mechanism is applied to protect many critical registers from false written. The register lock control register is one register in system controller.
Some registers of the clock controller are lock protected. Not only clock controller, but other IP such as RTC, PWM, ADC, etc, also have lock protected registers. All these IP requires syscon to access the lock/unlock control register in the system controller. That's why we add a <&sys> to the clock controller.

Should we implement a ma35d1-sysctl driver to protect register_lock() and register_unlock() and export to those drivers?  If yes, we can remove the <&sys> from clock controller.

Best regards,
Jacky Huang

maintainer
#36 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Quoting Jacky Huang (2023-03-28 19:39:36)

Quoted 14 lines · Stephen Boyd
Quoted 2 lines

What do you use the syscon for then? The clock driver must want to use the syscon for something, implying that they are the same device.

The register lock mechanism is applied to protect many critical registers from false written.
The register lock control register is one register in system controller. Some registers of the clock controller are lock protected. Not only clock controller, but other
IP such as RTC, PWM, ADC, etc, also have lock protected registers. All these IP requires
syscon to access the lock/unlock control register in the system controller. That's why we add a <&sys> to the clock controller.

Quoted 5 lines

Should we implement a ma35d1-sysctl driver to protect register_lock() and register_unlock()
and export to those drivers?  If yes, we can remove the <&sys> from clock controller.

You can implement the lock and unlock in the hwspinlock framework. See drivers/hwspinlock.

#37 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Dear Stephen,

Quoted 14 lines · Stephen Boyd

Quoting Jacky Huang (2023-03-28 19:39:36)

Quoted 13 lines · Stephen Boyd
Quoted 2 lines

What do you use the syscon for then? The clock driver must want to use the syscon for something, implying that they are the same device.

The register lock mechanism is applied to protect many critical registers from false written.
The register lock control register is one register in system controller. Some registers of the clock controller are lock protected. Not only clock controller, but other
IP such as RTC, PWM, ADC, etc, also have lock protected registers. All these IP requires
syscon to access the lock/unlock control register in the system controller. That's why we add a <&sys> to the clock controller.

Quoted 7 lines
Quoted 5 lines

Should we implement a ma35d1-sysctl driver to protect register_lock() and register_unlock()
and export to those drivers?  If yes, we can remove the <&sys> from clock controller.

You can implement the lock and unlock in the hwspinlock framework. See drivers/hwspinlock.

I may not explain clearly enough. The lock/unlock register of system controller is more like a kind of write protection for specific registers, rather than preventing hetero-core CPU access. In many different IP of ma35d1 contain write protected registers.
In fact, ma35d1 has a "hardware semaphore" IP, and we have implemented the driver in drivers/hwspinlock. Even the control register of "hardware semaphore" is also write protected.

So, should we implement a system controller driver to provide register_unlock() function? Is it OK to have such a driver in drivers/mfd?
Or, just use syscon in device tree for those devices that have write protect registers.

Best regards,
Jacky Huang

maintainer
#38 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Quoting Jacky Huang (2023-03-28 20:13:11)

Quoted 26 lines

Dear Stephen,

Quoted 14 lines · Stephen Boyd

Quoting Jacky Huang (2023-03-28 19:39:36)

Quoted 13 lines · Stephen Boyd
Quoted 2 lines

What do you use the syscon for then? The clock driver must want to use the syscon for something, implying that they are the same device.

The register lock mechanism is applied to protect many critical registers from false written.
The register lock control register is one register in system controller. Some registers of the clock controller are lock protected. Not only clock controller, but other
IP such as RTC, PWM, ADC, etc, also have lock protected registers. All these IP requires
syscon to access the lock/unlock control register in the system controller. That's why we add a <&sys> to the clock controller.

Quoted 7 lines
Quoted 5 lines

Should we implement a ma35d1-sysctl driver to protect register_lock() and register_unlock()
and export to those drivers?  If yes, we can remove the <&sys> from clock controller.

You can implement the lock and unlock in the hwspinlock framework. See drivers/hwspinlock.

Quoted 8 lines

I may not explain clearly enough. The lock/unlock register of system controller is more like
a kind of write protection for specific registers, rather than preventing hetero-core CPU access.
In many different IP of ma35d1 contain write protected registers. In fact, ma35d1 has a "hardware semaphore" IP, and we have implemented the driver in drivers/hwspinlock.
Even the control register of "hardware semaphore" is also write protected.

What's the need to lock and unlock the registers? Is some other processor also writing to the registers that we need to synchronize against? Or is Linux the only entity reading and writing the registers? I'm wondering if we should simply unlock the registers and never lock them.

Quoted 7 lines

So, should we implement a system controller driver to provide register_unlock() function?
Is it OK to have such a driver in drivers/mfd?
Or, just use syscon in device tree for those devices that have write protect registers.

The hwspinlock framework doesn't require there to be another entity accessing some resource. It's there to implement hardware locks. I don't see why it can't be used here.

#39 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Dear Stephen,

Quoted 46 lines · Stephen Boyd

Quoting Jacky Huang (2023-03-28 20:13:11)

Quoted 25 lines

Dear Stephen,

Quoted 14 lines · Stephen Boyd

Quoting Jacky Huang (2023-03-28 19:39:36)

Quoted 13 lines · Stephen Boyd
Quoted 2 lines

What do you use the syscon for then? The clock driver must want to use the syscon for something, implying that they are the same device.

The register lock mechanism is applied to protect many critical registers from false written.
The register lock control register is one register in system controller. Some registers of the clock controller are lock protected. Not only clock controller, but other
IP such as RTC, PWM, ADC, etc, also have lock protected registers. All these IP requires
syscon to access the lock/unlock control register in the system controller. That's why we add a <&sys> to the clock controller.

Quoted 7 lines
Quoted 5 lines

Should we implement a ma35d1-sysctl driver to protect register_lock() and register_unlock()
and export to those drivers?  If yes, we can remove the <&sys> from clock controller.

You can implement the lock and unlock in the hwspinlock framework. See drivers/hwspinlock.

Quoted 8 lines

I may not explain clearly enough. The lock/unlock register of system controller is more like
a kind of write protection for specific registers, rather than preventing hetero-core CPU access.
In many different IP of ma35d1 contain write protected registers. In fact, ma35d1 has a "hardware semaphore" IP, and we have implemented the driver in drivers/hwspinlock.
Even the control register of "hardware semaphore" is also write protected.

What's the need to lock and unlock the registers? Is some other processor also writing to the registers that we need to synchronize against? Or is Linux the only entity reading and writing the registers? I'm wondering if we should simply unlock the registers and never lock them.

Quoted 6 lines

So, should we implement a system controller driver to provide register_unlock() function?
Is it OK to have such a driver in drivers/mfd?
Or, just use syscon in device tree for those devices that have write protect registers.

Quoted 3 lines

The hwspinlock framework doesn't require there to be another entity accessing some resource. It's there to implement hardware locks. I don't see why it can't be used here.

The current usage of register lock/unlock protect is as the following code:

static void ma35d1_unlock_regs(struct ma35d1_clk_pll *pll) {
    int ret;

    do {
        regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x59); regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x16); regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x88); regmap_read(pll->regmap, REG_SYS_RLKTZNS, &ret); } while (ret == 0);
}

static void ma35d1_lock_regs(struct ma35d1_clk_pll *pll) {
    regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x0); }

And the following code is to unlock registers for write and then lock again.

    ma35d1_unlock_regs(pll);
    writel_relaxed(reg_ctl[0], pll->ctl0_base);
    writel_relaxed(reg_ctl[1], pll->ctl1_base);
    writel_relaxed(reg_ctl[2], pll->ctl2_base);
    ma35d1_lock_regs(pll);

The above code is from the clk-ma35d1-pll.c from this patchset.

We just employ regmap mechansim for the access to REG_SYS_RLKTZNS register. Is this implementation OK for you?  Thank you.

Best regards,
Jacky Huang

maintainer
#40 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Quoting Jacky Huang (2023-03-28 20:43:23)

Quoted 10 lines · Stephen Boyd
Quoted 9 lines

Quoting Jacky Huang (2023-03-28 20:13:11)

Quoted 8 lines

I may not explain clearly enough. The lock/unlock register of system controller is more like
a kind of write protection for specific registers, rather than preventing hetero-core CPU access.
In many different IP of ma35d1 contain write protected registers. In fact, ma35d1 has a "hardware semaphore" IP, and we have implemented the driver in drivers/hwspinlock.
Even the control register of "hardware semaphore" is also write protected.

Quoted 5 lines
Quoted 5 lines

What's the need to lock and unlock the registers? Is some other processor also writing to the registers that we need to synchronize against? Or is Linux the only entity reading and writing the registers? I'm wondering if we should simply unlock the registers and never lock them.

Can you answer this question?

Quoted 32 lines
Quoted 10 lines
Quoted 7 lines

So, should we implement a system controller driver to provide register_unlock() function?
Is it OK to have such a driver in drivers/mfd?
Or, just use syscon in device tree for those devices that have write protect registers.

The hwspinlock framework doesn't require there to be another entity accessing some resource. It's there to implement hardware locks. I don't see why it can't be used here.

The current usage of register lock/unlock protect is as the following code:

static void ma35d1_unlock_regs(struct ma35d1_clk_pll *pll) {
    int ret;

    do {
        regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x59); regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x16); regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x88); regmap_read(pll->regmap, REG_SYS_RLKTZNS, &ret); } while (ret == 0);
}

static void ma35d1_lock_regs(struct ma35d1_clk_pll *pll) {
    regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x0);
}

And the following code is to unlock registers for write and then lock again.

Quoted 7 lines

    ma35d1_unlock_regs(pll);
    writel_relaxed(reg_ctl[0], pll->ctl0_base);
    writel_relaxed(reg_ctl[1], pll->ctl1_base);
    writel_relaxed(reg_ctl[2], pll->ctl2_base);
    ma35d1_lock_regs(pll);

The above code is from the clk-ma35d1-pll.c from this patchset.

Yeah I understand that you write some registers in the syscon to lock the registers.

Quoted 4 lines

We just employ regmap mechansim for the access to REG_SYS_RLKTZNS register. Is this implementation OK for you?  Thank you.

No. Why can't that be a hwspinlock? Or why can't it be unlocked all the time and rely on software spinlocks in the kernel to prevent concurrent access to the registers accessed by a driver, like a lock for the clk registers and a lock for the reset registers, etc. Or if no two clks or resets exist within one 32-bit word then no lock is necessary.

#41 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Dear Stephen,

Quoted 11 lines · Stephen Boyd

Quoting Jacky Huang (2023-03-28 20:43:23)

Quoted 10 lines · Stephen Boyd
Quoted 9 lines

Quoting Jacky Huang (2023-03-28 20:13:11)

Quoted 8 lines

I may not explain clearly enough. The lock/unlock register of system controller is more like
a kind of write protection for specific registers, rather than preventing hetero-core CPU access.
In many different IP of ma35d1 contain write protected registers. In fact, ma35d1 has a "hardware semaphore" IP, and we have implemented the driver in drivers/hwspinlock.
Even the control register of "hardware semaphore" is also write protected.

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

What's the need to lock and unlock the registers? Is some other processor also writing to the registers that we need to synchronize against? Or is Linux the only entity reading and writing the registers? I'm wondering if we should simply unlock the registers and never lock them.

Can you answer this question?

Sorry, I miss this.
The lock and unlock register mechanism is a hardware design of ma35d1 SoC. The purpose is to prevent from unexpected write to some registers. However, I think this is a redundant design if s/w is done properly.
Even though I think it's a redundant design, it's out there and we have to deal with it. And of course we have unlock and lock pair, I just lost to write in the above.

Quoted 40 lines
Quoted 30 lines
Quoted 9 lines
Quoted 6 lines

So, should we implement a system controller driver to provide register_unlock() function?
Is it OK to have such a driver in drivers/mfd?
Or, just use syscon in device tree for those devices that have write protect registers.

The hwspinlock framework doesn't require there to be another entity accessing some resource. It's there to implement hardware locks. I don't see why it can't be used here.

The current usage of register lock/unlock protect is as the following code:

static void ma35d1_unlock_regs(struct ma35d1_clk_pll *pll) {
    int ret;

    do {
        regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x59); regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x16); regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x88); regmap_read(pll->regmap, REG_SYS_RLKTZNS, &ret); } while (ret == 0);
}

static void ma35d1_lock_regs(struct ma35d1_clk_pll *pll) {
    regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x0);
}

And the following code is to unlock registers for write and then lock again.

Quoted 7 lines
      ma35d1_unlock_regs(pll);
      writel_relaxed(reg_ctl[0], pll->ctl0_base);
      writel_relaxed(reg_ctl[1], pll->ctl1_base);
      writel_relaxed(reg_ctl[2], pll->ctl2_base);
      ma35d1_lock_regs(pll);

The above code is from the clk-ma35d1-pll.c from this patchset.

Yeah I understand that you write some registers in the syscon to lock the registers.

Quoted 8 lines
Quoted 3 lines

We just employ regmap mechansim for the access to REG_SYS_RLKTZNS register. Is this implementation OK for you?  Thank you.

No. Why can't that be a hwspinlock? Or why can't it be unlocked all the time and rely on software spinlocks in the kernel to prevent concurrent access to the registers accessed by a driver, like a lock for the clk registers and a lock for the reset registers, etc. Or if no two clks or resets exist within one 32-bit word then no lock is necessary.

You gave a good suggestion here. Yes, of course we can let it be unlocked all the time. We can unlock the "register lock" before entering Linux.
As a result, the unlonk and lock register related code is not required. Thus, we can remove syscon from the clock controller node.

If you agree with this, we will modify it in the next version.

Best regards,
Jacky Huang

maintainer
#42 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Quoting Jacky Huang (2023-03-28 23:02:31)

Quoted 13 lines · Stephen Boyd
Quoted 10 lines

Quoting Jacky Huang (2023-03-28 20:43:23)

Quoted 3 lines

We just employ regmap mechansim for the access to REG_SYS_RLKTZNS register. Is this implementation OK for you?  Thank you.

No. Why can't that be a hwspinlock? Or why can't it be unlocked all the time and rely on software spinlocks in the kernel to prevent concurrent access to the registers accessed by a driver, like a lock for the clk registers and a lock for the reset registers, etc. Or if no two clks or resets exist within one 32-bit word then no lock is necessary.

Quoted 8 lines

You gave a good suggestion here. Yes, of course we can let it be unlocked all the time.
We can unlock the "register lock" before entering Linux.
As a result, the unlonk and lock register related code is not required. Thus, we can remove syscon from the clock controller node.

If you agree with this, we will modify it in the next version.

Sure, that works.

#43 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

In reply to Jacky Huang
Quoted 14 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Add initial device tree support for Nuvoton ma35d1 SoC, including cpu, clock, reset, and serial controllers.
Add reference boards som-256m and iot-512m.

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +4 -0
+	gic: interrupt-controller@50801000 {
+		compatible = "arm,gic-400";
+		reg =   <0x0 0x50801000 0 0x1000>, /* GICD */
+			<0x0 0x50802000 0 0x2000>, /* GICC */

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 96

Quoted 10 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +10 -0
+			<0x0 0x50804000 0 0x2000>, /* GICH */
+			<0x0 0x50806000 0 0x2000>; /* GICV */
+		#interrupt-cells = <3>;
+		interrupt-parent = <&gic>;
+		interrupt-controller;
+		interrupts = <GIC_PPI 9 (GIC_CPU_MASK_RAW(0x13) |
+			      IRQ_TYPE_LEVEL_HIGH)>;
+	};
+
+	uart0:serial@40700000 {

There is always space after label:.

Best regards,
Krzysztof

#44 lore raw

Re: [PATCH v6 08/12] arm64: dts: nuvoton: Add initial ma35d1 device tree

Dear Krzysztof,

Quoted 27 lines · Krzysztof Kozlowski
Quoted 13 lines · Jacky Huang

From: Jacky Huang <[email protected]>

Add initial device tree support for Nuvoton ma35d1 SoC, including cpu, clock, reset, and serial controllers.
Add reference boards som-256m and iot-512m.

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +4 -0
+	gic: interrupt-controller@50801000 {
+		compatible = "arm,gic-400";
+		reg =   <0x0 0x50801000 0 0x1000>, /* GICD */
+			<0x0 0x50802000 0 0x2000>, /* GICC */

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi line 96

Quoted 10 lines
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +10 -0
+			<0x0 0x50804000 0 0x2000>, /* GICH */
+			<0x0 0x50806000 0 0x2000>; /* GICV */
+		#interrupt-cells = <3>;
+		interrupt-parent = <&gic>;
+		interrupt-controller;
+		interrupts = <GIC_PPI 9 (GIC_CPU_MASK_RAW(0x13) |
+			      IRQ_TYPE_LEVEL_HIGH)>;
+	};
+
+	uart0:serial@40700000 {

There is always space after label:.

Quoted 3 lines

Best regards,
Krzysztof

I will fix them all.

Best regards,
Jacky Huang

#45 lore raw

PATCH v6 9/12 clk: nuvoton: Add clock driver for ma35d1 clock controller

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

The clock controller generates clocks for the whole chip, including system clocks and all peripheral clocks. This driver support ma35d1 clock gating, divider, and individual PLL configuration.

There are 6 PLLs in ma35d1 SoC:
- CA-PLL for the two Cortex-A35 CPU clock
- SYS-PLL for system bus, which comes from the companion MCU and cannot be programmed by clock controller.
- DDR-PLL for DDR
- EPLL for GMAC and GFX, Display, and VDEC IPs.
- VPLL for video output pixel clock
- APLL for SDHC, I2S audio, and other IPs.
CA-PLL has only one operation mode.
DDR-PLL, EPLL, VPLL, and APLL are advanced PLLs which have 3 operation modes: integer mode, fraction mode, and spread specturm mode.

---
 drivers/clk/Makefile                     |   1 +
 drivers/clk/nuvoton/Kconfig              |  19 +
 drivers/clk/nuvoton/Makefile             |   4 +
 drivers/clk/nuvoton/clk-ma35d1-divider.c | 140 ++++
 drivers/clk/nuvoton/clk-ma35d1-pll.c     | 350 ++++++++
 drivers/clk/nuvoton/clk-ma35d1.c         | 963 +++++++++++++++++++++++
 drivers/clk/nuvoton/clk-ma35d1.h         | 123 +++
 7 files changed, 1600 insertions(+)
 create mode 100644 drivers/clk/nuvoton/Kconfig
 create mode 100644 drivers/clk/nuvoton/Makefile
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1-divider.c
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1-pll.c
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1.c
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1.h
drivers/clk/Makefile +1 -0
index e3ca0d058a25..2e7916d269e1 100644
@@ -103,6 +103,7 @@ endif
 obj-y					+= mstar/
 obj-y					+= mvebu/
 obj-$(CONFIG_ARCH_MXS)			+= mxs/
+obj-$(CONFIG_ARCH_NUVOTON)		+= nuvoton/
 obj-$(CONFIG_COMMON_CLK_NXP)		+= nxp/
 obj-$(CONFIG_COMMON_CLK_PISTACHIO)	+= pistachio/
 obj-$(CONFIG_COMMON_CLK_PXA)		+= pxa/
drivers/clk/nuvoton/Kconfig new file +19 -0
new file mode 100644
index 000000000000..c1324efedcb9
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0
+# common clock support for Nuvoton SoC family.
+
+config COMMON_CLK_NUVOTON
+	bool "Nuvoton clock controller common support"
+	depends on ARCH_NUVOTON
+	default ARCH_NUVOTON
+	help
+	  Say y here to enable common clock controller for Nuvoton platforms.
+
+if COMMON_CLK_NUVOTON
+config CLK_MA35D1
+	bool "Nuvoton MA35D1 clock controller support"
+	depends on ARM64 || COMPILE_TEST
+	default y
+	help
+	  Build the driver for MA35D1 Clock Driver.
+
+endif
drivers/clk/nuvoton/Makefile new file +4 -0
new file mode 100644
index 000000000000..d2c092541b8d
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_ARCH_NUVOTON) += clk-ma35d1.o
+obj-$(CONFIG_ARCH_NUVOTON) += clk-ma35d1-divider.o
+obj-$(CONFIG_ARCH_NUVOTON) += clk-ma35d1-pll.o
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +140 -0

140 lines not on this page · raw message

drivers/clk/nuvoton/clk-ma35d1-pll.c new file +350 -0

350 lines not on this page · raw message

drivers/clk/nuvoton/clk-ma35d1.c new file +963 -0

963 lines not on this page · raw message

drivers/clk/nuvoton/clk-ma35d1.h new file +123 -0

123 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#46 lore raw

Re: [PATCH v6 09/12] clk: nuvoton: Add clock driver for ma35d1 clock controller

Quoting Jacky Huang (2023-03-27 19:19:09)

drivers/clk/nuvoton/Kconfig line 6

Quoted 12 lines
drivers/clk/nuvoton/Kconfig new file +6 -0
new file mode 100644
index 000000000000..c1324efedcb9
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0
+# common clock support for Nuvoton SoC family.
+
+config COMMON_CLK_NUVOTON
+       bool "Nuvoton clock controller common support"
+       depends on ARCH_NUVOTON

Add || COMPILE_TEST

drivers/clk/nuvoton/Kconfig line 11

Quoted 5 lines
drivers/clk/nuvoton/Kconfig new file +5 -0
+       default ARCH_NUVOTON
+       help
+         Say y here to enable common clock controller for Nuvoton platforms.
+
+if COMMON_CLK_NUVOTON

Add a newline here.

drivers/clk/nuvoton/Kconfig line 14

Quoted 3 lines
drivers/clk/nuvoton/Kconfig new file +3 -0
+config CLK_MA35D1
+       bool "Nuvoton MA35D1 clock controller support"
+       depends on ARM64 || COMPILE_TEST

Drop this

drivers/clk/nuvoton/Kconfig line 15

Quoted 1 line
drivers/clk/nuvoton/Kconfig new file +1 -0
+       default y

And this.

drivers/clk/nuvoton/Kconfig line 17

Quoted 2 lines
drivers/clk/nuvoton/Kconfig new file +2 -0
+       help
+         Build the driver for MA35D1 Clock Driver.

This says driver twice. "Build the clk driver for MA35D1 SoCs"?

Quoted 12 lines
drivers/clk/nuvoton/Kconfig new file +2 -0
+
+endif
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +4 -0
new file mode 100644
index 000000000000..340a889a1417
@@ -0,0 +1,140 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 Nuvoton Technology Corp.
+ * Author: Chi-Fang Li <[email protected]>

drivers/clk/nuvoton/clk-ma35d1-divider.c line 14

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +10 -0
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/device.h>
+#include <linux/regmap.h>
+#include <linux/spinlock.h>
+
+#include "clk-ma35d1.h"
+
+#define clk_div_mask(width)    ((1 << (width)) - 1)

clk-provider.h defines this already, use that?

Quoted 44 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +44 -0
+
+struct ma35d1_adc_clk_div {
+       struct clk_hw hw;
+       void __iomem *reg;
+       u8 shift;
+       u8 width;
+       u32 mask;
+       const struct clk_div_table *table;
+       /* protects concurrent access to clock divider registers */
+       spinlock_t *lock;
+};
+
+static inline struct ma35d1_adc_clk_div *to_ma35d1_adc_clk_div(struct clk_hw *_hw)
+{
+       return container_of(_hw, struct ma35d1_adc_clk_div, hw);
+}
+
+static inline unsigned long ma35d1_clkdiv_recalc_rate(struct clk_hw *hw,
+                                                     unsigned long parent_rate)
+{
+       unsigned int val;
+       struct ma35d1_adc_clk_div *dclk = to_ma35d1_adc_clk_div(hw);
+
+       val = readl_relaxed(dclk->reg) >> dclk->shift;
+       val &= clk_div_mask(dclk->width);
+       val += 1;
+       return divider_recalc_rate(hw, parent_rate, val, dclk->table,
+                                  CLK_DIVIDER_ROUND_CLOSEST, dclk->width);
+}
+
+static inline long ma35d1_clkdiv_round_rate(struct clk_hw *hw,
+                                           unsigned long rate,
+                                           unsigned long *prate)
+{
+       struct ma35d1_adc_clk_div *dclk = to_ma35d1_adc_clk_div(hw);
+
+       return divider_round_rate(hw, rate, prate, dclk->table,
+                                 dclk->width, CLK_DIVIDER_ROUND_CLOSEST);
+}
+
+static inline int ma35d1_clkdiv_set_rate(struct clk_hw *hw,
+                                        unsigned long rate,
+                                        unsigned long parent_rate)
+{

drivers/clk/nuvoton/clk-ma35d1-divider.c line 68

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +10 -0
+       int value;
+       unsigned long flags = 0;
+       u32 data;
+       struct ma35d1_adc_clk_div *dclk = to_ma35d1_adc_clk_div(hw);
+
+       value = divider_get_val(rate, parent_rate, dclk->table,
+                               dclk->width, CLK_DIVIDER_ROUND_CLOSEST);
+
+       if (dclk->lock)
+               spin_lock_irqsave(dclk->lock, flags);

Can you just always lock? That makes the conditional locking go away.

Quoted 37 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +37 -0
+
+       data = readl_relaxed(dclk->reg);
+       data &= ~(clk_div_mask(dclk->width) << dclk->shift);
+       data |= (value - 1) << dclk->shift;
+       data |= dclk->mask;
+
+       writel_relaxed(data, dclk->reg);
+
+       if (dclk->lock)
+               spin_unlock_irqrestore(dclk->lock, flags);
+
+       return 0;
+}
+
+static const struct clk_ops ma35d1_adc_clkdiv_ops = {
+       .recalc_rate = ma35d1_clkdiv_recalc_rate,
+       .round_rate = ma35d1_clkdiv_round_rate,
+       .set_rate = ma35d1_clkdiv_set_rate,
+};
+
+struct clk_hw *ma35d1_reg_adc_clkdiv(struct device *dev, const char *name,
+                                    const char *parent_name,
+                                    spinlock_t *lock,
+                                    unsigned long flags, void __iomem *reg,
+                                    u8 shift, u8 width, u32 mask_bit)
+{
+       struct ma35d1_adc_clk_div *div;
+       struct clk_init_data init;
+       struct clk_div_table *table;
+       u32 max_div, min_div;
+       struct clk_hw *hw;
+       int ret;
+       int i;
+
+       div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL);
+       if (!div)
+               return ERR_PTR(-ENOMEM);

drivers/clk/nuvoton/clk-ma35d1-divider.c line 115

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +10 -0
+
+       max_div = clk_div_mask(width) + 1;
+       min_div = 1;
+
+       table = devm_kcalloc(dev, max_div + 1, sizeof(*table), GFP_KERNEL);
+       if (!table)
+               return ERR_PTR(-ENOMEM);
+
+       for (i = 0; i < max_div; i++) {
+               table[i].val = (min_div + i);

Drop useless parenthesis.

Quoted 12 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +12 -0
+               table[i].div = 2 * table[i].val;
+       }
+       table[max_div].val = 0;
+       table[max_div].div = 0;
+
+       init.name = name;
+       init.ops = &ma35d1_adc_clkdiv_ops;
+       init.flags |= flags;
+       init.parent_names = parent_name ? &parent_name : NULL;
+       init.num_parents = parent_name ? 1 : 0;
+
+       div->reg = reg;

drivers/clk/nuvoton/clk-ma35d1-divider.c line 137

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +10 -0
+       div->shift = shift;
+       div->width = width;
+       div->mask = mask_bit ? BIT(mask_bit) : 0;
+       div->lock = lock;
+       div->hw.init = &init;
+       div->table = table;
+
+       hw = &div->hw;
+       ret = devm_clk_hw_register(dev, hw);
+       if (ret < 0)

Use if (ret) instead.

Quoted 20 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +3 -0
+               return ERR_PTR(ret);
+       return hw;
+}
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +11 -0
new file mode 100644
index 000000000000..b36fbda4fa0a
@@ -0,0 +1,350 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 Nuvoton Technology Corp.
+ * Author: Chi-Fang Li <[email protected]>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk-provider.h>
+#include <linux/slab.h>
+#include <linux/regmap.h>
+

drivers/clk/nuvoton/clk-ma35d1-pll.c line 21

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+#include "clk-ma35d1.h"
+
+#define REG_SYS_RLKTZNS                0x1a4 /* Register Lock Control */
+
+struct ma35d1_clk_pll {
+       struct clk_hw hw;
+       u8 type;
+       u8 mode;
+       unsigned long rate;
+       void __iomem *ctl0_base;

This needs an include for __iomem define. Just include kernel.h for now.

drivers/clk/nuvoton/clk-ma35d1-pll.c line 29

Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +8 -0
+       void __iomem *ctl1_base;
+       void __iomem *ctl2_base;
+       struct regmap *regmap;
+};
+
+static inline struct ma35d1_clk_pll *to_ma35d1_clk_pll(struct clk_hw *_hw)
+{
+       return container_of(_hw, struct ma35d1_clk_pll, hw);

Missing include as well.

drivers/clk/nuvoton/clk-ma35d1-pll.c line 41

Quoted 12 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +12 -0
+}
+
+static void ma35d1_unlock_regs(struct ma35d1_clk_pll *pll)
+{
+       int ret;
+
+       do {
+               regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x59);
+               regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x16);
+               regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x88);
+               regmap_read(pll->regmap, REG_SYS_RLKTZNS, &ret);
+       } while (ret == 0);

Any sort of timeout?

drivers/clk/nuvoton/clk-ma35d1-pll.c line 54

Quoted 13 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +13 -0
+}
+
+static void ma35d1_lock_regs(struct ma35d1_clk_pll *pll)
+{
+       regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x0);
+}
+
+static unsigned long ma35d1_calc_smic_pll_freq(u32 pll0_ctl0,
+                                              unsigned long parent_rate)
+{
+       u32 m, n, p, outdiv;
+       u64 pll_freq;
+       u32 clk_div_table[] = { 1, 2, 4, 8 };

const

drivers/clk/nuvoton/clk-ma35d1-pll.c line 65

Quoted 11 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +11 -0
+
+       if (pll0_ctl0 & SPLL0_CTL0_BP)
+               return parent_rate;
+
+       n = FIELD_GET(SPLL0_CTL0_FBDIV, pll0_ctl0);
+       m = FIELD_GET(SPLL0_CTL0_INDIV, pll0_ctl0);
+       p = FIELD_GET(SPLL0_CTL0_OUTDIV, pll0_ctl0);
+       outdiv = clk_div_table[p];
+       pll_freq = (u64)parent_rate * n;
+       do_div(pll_freq, m * outdiv);
+       return (unsigned long)pll_freq;

Remove useless cast.

Quoted 11 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +11 -0
+}
+
+static unsigned long ma35d1_calc_pll_freq(u8 mode, u32 *reg_ctl,
+                                         unsigned long parent_rate)
+{
+       u32 m, n, p;
+       u64 pll_freq, x;
+
+       if (reg_ctl[1] & PLL_CTL1_BP)
+               return parent_rate;
+

drivers/clk/nuvoton/clk-ma35d1-pll.c line 86

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+       if (mode == PLL_MODE_INT) {
+               n = FIELD_GET(PLL_CTL0_FBDIV, reg_ctl[0]);
+               m = FIELD_GET(PLL_CTL0_INDIV, reg_ctl[0]);
+               p = FIELD_GET(PLL_CTL1_OUTDIV, reg_ctl[1]);
+               pll_freq = (u64)parent_rate * n;
+               do_div(pll_freq, m * p);
+       } else {
+               n = FIELD_GET(PLL_CTL0_FBDIV, reg_ctl[0]);
+               m = FIELD_GET(PLL_CTL0_INDIV, reg_ctl[0]);
+               p = FIELD_GET(PLL_CTL1_OUTDIV, reg_ctl[1]);

The n, m, p are the same, so pull them out of the if-else to deduplicate.

drivers/clk/nuvoton/clk-ma35d1-pll.c line 89

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +3 -0
+               x = FIELD_GET(PLL_CTL1_FRAC, reg_ctl[1]);
+               /* 2 decimal places floating to integer (ex. 1.23 to 123) */
+               n = n * 100 + ((x * 100) / FIELD_MAX(PLL_CTL1_FRAC));

Is this mult_frac()?

drivers/clk/nuvoton/clk-ma35d1-pll.c line 91

Quoted 2 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +2 -0
+               pll_freq = ((u64)parent_rate * n) / 100 / m / p;
+       }

Add a newline

drivers/clk/nuvoton/clk-ma35d1-pll.c line 92

Quoted 1 line
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +1 -0
+       return (unsigned long)pll_freq;

Remove useless cast.

Quoted 65 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +65 -0
+}
+
+static int ma35d1_pll_find_closest(struct ma35d1_clk_pll *pll,
+                                  unsigned long rate,
+                                  unsigned long parent_rate,
+                                  u32 *reg_ctl, unsigned long *freq)
+{
+       int p, m, n;
+       int fbdiv_min, fbdiv_max;
+       unsigned long diff = 0xffffffff;
+
+       *freq = 0;
+       if ((rate < PLL_FCLKO_MIN_FREQ) || (rate > PLL_FCLKO_MAX_FREQ))
+               return -EINVAL;
+
+       if (pll->mode == PLL_MODE_INT) {
+               fbdiv_min = FBDIV_MIN;
+               fbdiv_max = FBDIV_MAX;
+       } else {
+               fbdiv_min = FBDIV_FRAC_MIN;
+               fbdiv_max = FBDIV_FRAC_MAX;
+       }
+
+       for (m = INDIV_MIN; m <= INDIV_MAX; m++) {
+               for (n = fbdiv_min; n <= fbdiv_max; n++) {
+                       for (p = OUTDIV_MIN; p <= OUTDIV_MAX; p++) {
+                               unsigned long tmp, fout;
+                               u64 fclk;
+
+                               tmp = parent_rate / m;
+                               if (tmp < PLL_FREF_M_MIN_FREQ ||
+                                   tmp > PLL_FREF_M_MAX_FREQ)
+                                       continue; /* constrain */
+
+                               fclk = (u64)parent_rate * n / m;
+                               /* for 2 decimal places */
+                               if (pll->mode != PLL_MODE_INT)
+                                       fclk /= 100;
+
+                               if (fclk < PLL_FCLK_MIN_FREQ ||
+                                   fclk > PLL_FCLK_MAX_FREQ)
+                                       continue; /* constrain */
+
+                               fout = (unsigned long)(fclk / p);
+                               if (fout < PLL_FCLKO_MIN_FREQ ||
+                                   fout > PLL_FCLKO_MAX_FREQ)
+                                       continue; /* constrain */
+
+                               if (abs(rate - fout) < diff) {
+                                       reg_ctl[0] = FIELD_PREP(PLL_CTL0_INDIV, m) |
+                                                    FIELD_PREP(PLL_CTL0_FBDIV, n);
+                                       reg_ctl[1] = FIELD_PREP(PLL_CTL1_OUTDIV, p);
+                                       *freq = fout;
+                                       diff = abs(rate - fout);
+                                       if (diff == 0)
+                                               break;
+                               }
+                       }
+               }
+       }
+       if (*freq == 0)
+               return -EINVAL; /* cannot find even one valid setting */
+       return 0;
+}
+

drivers/clk/nuvoton/clk-ma35d1-pll.c line 167

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+static int ma35d1_clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
+                                  unsigned long parent_rate)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 reg_ctl[3] = { 0 };
+       unsigned long pll_freq;
+       int ret;
+
+       if ((parent_rate < PLL_FREF_MIN_FREQ) ||
+           (parent_rate > PLL_FREF_MAX_FREQ))

Remove useless parenthesis.

drivers/clk/nuvoton/clk-ma35d1-pll.c line 170

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +3 -0
+               return -EINVAL;
+
+       if ((pll->type == MA35D1_CAPLL) || (pll->type == MA35D1_DDRPLL)) {

Remove useless parenthesis.

Quoted 30 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +30 -0
+               pr_warn("Nuvoton MA35D1 CAPLL/DDRPLL is read only.\n");
+               return -EACCES;
+       }
+
+       ret = ma35d1_pll_find_closest(pll, rate, parent_rate, reg_ctl, &pll_freq);
+       if (ret != 0)
+               return ret;
+       pll->rate = pll_freq;
+
+       switch (pll->mode) {
+       case PLL_MODE_INT:
+               reg_ctl[0] |= FIELD_PREP(PLL_CTL0_MODE, PLL_MODE_INT);
+               break;
+       case PLL_MODE_FRAC:
+               reg_ctl[0] |= FIELD_PREP(PLL_CTL0_MODE, PLL_MODE_FRAC);
+               break;
+       case PLL_MODE_SS:
+               reg_ctl[0] |= FIELD_PREP(PLL_CTL0_MODE, PLL_MODE_SS) |
+                             FIELD_PREP(PLL_CTL0_SSRATE, PLL_SS_RATE);
+               reg_ctl[2] = FIELD_PREP(PLL_CTL2_SLOPE, PLL_SLOPE);
+               break;
+       }
+       reg_ctl[1] |= PLL_CTL1_PD;
+
+       ma35d1_unlock_regs(pll);
+       writel_relaxed(reg_ctl[0], pll->ctl0_base);
+       writel_relaxed(reg_ctl[1], pll->ctl1_base);
+       writel_relaxed(reg_ctl[2], pll->ctl2_base);
+       ma35d1_lock_regs(pll);
+       return 0;

drivers/clk/nuvoton/clk-ma35d1-pll.c line 210

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+}
+
+static unsigned long ma35d1_clk_pll_recalc_rate(struct clk_hw *hw,
+                                               unsigned long parent_rate)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 reg_ctl[3];
+       unsigned long pll_freq;
+
+       if ((parent_rate < PLL_FREF_MIN_FREQ) || (parent_rate > PLL_FREF_MAX_FREQ))

Remove useless parenthesis.

drivers/clk/nuvoton/clk-ma35d1-pll.c line 216

Quoted 6 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +6 -0
+               return 0;
+
+       switch (pll->type) {
+       case MA35D1_CAPLL:
+               reg_ctl[0] = readl_relaxed(pll->ctl0_base);
+               pll_freq = ma35d1_calc_smic_pll_freq(reg_ctl[0], parent_rate);

return?

drivers/clk/nuvoton/clk-ma35d1-pll.c line 224

Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +8 -0
+               break;
+       case MA35D1_DDRPLL:
+       case MA35D1_APLL:
+       case MA35D1_EPLL:
+       case MA35D1_VPLL:
+               reg_ctl[0] = readl_relaxed(pll->ctl0_base);
+               reg_ctl[1] = readl_relaxed(pll->ctl1_base);
+               pll_freq = ma35d1_calc_pll_freq(pll->mode, reg_ctl, parent_rate);

return?

drivers/clk/nuvoton/clk-ma35d1-pll.c line 227

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +3 -0
+               break;
+       }
+       return pll_freq;

return 0?

Quoted 11 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +11 -0
+}
+
+static long ma35d1_clk_pll_round_rate(struct clk_hw *hw, unsigned long rate,
+                                     unsigned long *parent_rate)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 reg_ctl[3] = { 0 };
+       unsigned long pll_freq;
+       long ret;
+
+       if (*parent_rate < PLL_FREF_MIN_FREQ || *parent_rate > PLL_FREF_MAX_FREQ)

drivers/clk/nuvoton/clk-ma35d1-pll.c line 248

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+               return -EINVAL;
+
+       ret = ma35d1_pll_find_closest(pll, rate, *parent_rate, reg_ctl, &pll_freq);
+       if (ret != 0)
+               return ret;
+
+       switch (pll->type) {
+       case MA35D1_CAPLL:
+               reg_ctl[0] = readl_relaxed(pll->ctl0_base);
+               pll_freq = ma35d1_calc_smic_pll_freq(reg_ctl[0], *parent_rate);

return?

drivers/clk/nuvoton/clk-ma35d1-pll.c line 256

Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +8 -0
+               break;
+       case MA35D1_DDRPLL:
+       case MA35D1_APLL:
+       case MA35D1_EPLL:
+       case MA35D1_VPLL:
+               reg_ctl[0] = readl_relaxed(pll->ctl0_base);
+               reg_ctl[1] = readl_relaxed(pll->ctl1_base);
+               pll_freq = ma35d1_calc_pll_freq(pll->mode, reg_ctl, *parent_rate);

return?

drivers/clk/nuvoton/clk-ma35d1-pll.c line 227

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +3 -0
+               break;
+       }
+       return pll_freq;

return 0?

Quoted 6 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +6 -0
+}
+
+static int ma35d1_clk_pll_is_prepared(struct clk_hw *hw)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 val = readl_relaxed(pll->ctl1_base);

drivers/clk/nuvoton/clk-ma35d1-pll.c line 275

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+
+       return val & PLL_CTL1_PD ? 0 : 1;
+}
+
+static int ma35d1_clk_pll_prepare(struct clk_hw *hw)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 val;
+
+       if ((pll->type == MA35D1_CAPLL) || (pll->type == MA35D1_DDRPLL)) {

Drop useless parenthesis.

Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +8 -0
+               pr_warn("Nuvoton MA35D1 CAPLL/DDRPLL is read only.\n");
+               return -EACCES;
+       }
+
+       ma35d1_unlock_regs(pll);
+       val = readl_relaxed(pll->ctl1_base);
+       val &= ~PLL_CTL1_PD;
+       writel_relaxed(val, pll->ctl1_base);

drivers/clk/nuvoton/clk-ma35d1-pll.c line 293

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+       ma35d1_lock_regs(pll);
+       return 0;
+}
+
+static void ma35d1_clk_pll_unprepare(struct clk_hw *hw)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 val;
+
+       if ((pll->type == MA35D1_CAPLL) || (pll->type == MA35D1_DDRPLL)) {

Drop useless parenthesis.

drivers/clk/nuvoton/clk-ma35d1-pll.c line 294

Quoted 1 line
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +1 -0
+               pr_warn("Nuvoton MA35D1 CAPLL/DDRPLL is read only.\n");

These read-only checks should be removed and different clk_ops should be assigned for the read-only type of clks.

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7 -0
+       } else {
+               val = readl_relaxed(pll->ctl1_base);
+               val |= PLL_CTL1_PD;
+               writel_relaxed(val, pll->ctl1_base);
+       }
+}
+

drivers/clk/nuvoton/clk-ma35d1-pll.c line 311

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+static const struct clk_ops ma35d1_clk_pll_ops = {
+       .is_prepared = ma35d1_clk_pll_is_prepared,
+       .prepare = ma35d1_clk_pll_prepare,
+       .unprepare = ma35d1_clk_pll_unprepare,
+       .set_rate = ma35d1_clk_pll_set_rate,
+       .recalc_rate = ma35d1_clk_pll_recalc_rate,
+       .round_rate = ma35d1_clk_pll_round_rate,
+};
+
+struct clk_hw *ma35d1_reg_clk_pll(enum ma35d1_pll_type type,

Pass a device here.

drivers/clk/nuvoton/clk-ma35d1-pll.c line 320

Quoted 9 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +9 -0
+                                 u8 u8mode, const char *name,
+                                 const char *parent,
+                                 unsigned long targetFreq,
+                                 void __iomem *base,
+                                 struct regmap *regmap)
+{
+       struct ma35d1_clk_pll *pll;
+       struct clk_hw *hw;
+       struct clk_init_data init;

init = {};

drivers/clk/nuvoton/clk-ma35d1-pll.c line 323

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +3 -0
+       int ret;
+
+       pll = kmalloc(sizeof(*pll), GFP_KERNEL);

Just use kzalloc(). This isn't a hot path.

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+       if (!pll)
+               return ERR_PTR(-ENOMEM);
+
+       pll->type = type;
+       pll->mode = u8mode;
+       pll->rate = targetFreq;
+       pll->ctl0_base = base + REG_PLL_CTL0_OFFSET;
+       pll->ctl1_base = base + REG_PLL_CTL1_OFFSET;
+       pll->ctl2_base = base + REG_PLL_CTL2_OFFSET;
+       pll->regmap = regmap;

drivers/clk/nuvoton/clk-ma35d1-pll.c line 343

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+
+       init.name = name;
+       init.flags = 0;
+       init.parent_names = &parent;
+       init.num_parents = 1;
+       init.ops = &ma35d1_clk_pll_ops;
+       pll->hw.init = &init;
+       hw = &pll->hw;
+
+       ret = clk_hw_register(NULL, hw);

Use devm_

drivers/clk/nuvoton/clk-ma35d1-pll.c line 345

Quoted 2 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +2 -0
+       if (ret) {
+               pr_err("failed to register vsi-pll clock!!!\n");

I'm going to put a dev_err_probe() into clk registration code. Remove this printk.

Quoted 21 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +5 -0
+               kfree(pll);
+               return ERR_PTR(ret);
+       }
+       return hw;
+}
drivers/clk/nuvoton/clk-ma35d1.c new file +10 -0
new file mode 100644
index 000000000000..e4d3ced396a3
@@ -0,0 +1,963 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 Nuvoton Technology Corp.
+ * Author: Chi-Fang Li <[email protected]>
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>

drivers/clk/nuvoton/clk-ma35d1.c line 20

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +10 -0
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/spinlock.h>
+#include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
+
+#include "clk-ma35d1.h"
+
+static DEFINE_SPINLOCK(ma35d1_lock);
+
+static const char *const ca35clk_sel_clks[] = {

Use clk_parent_data instead.

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +3 -0
+       "hxt", "capll", "ddrpll", "dummy"
+};
+

[...]

Quoted 53 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +53 -0
+
+static inline struct clk_hw *ma35d1_clk_fixed(const char *name, int rate)
+{
+       return clk_hw_register_fixed_rate(NULL, name, NULL, 0, rate);
+}
+
+static inline struct clk_hw *ma35d1_clk_mux(const char *name,
+                                           void __iomem *reg,
+                                           u8 shift, u8 width,
+                                           const char *const *parents,
+                                           int num_parents)
+{
+       return clk_hw_register_mux(NULL, name, parents, num_parents,
+                                  CLK_SET_RATE_NO_REPARENT, reg, shift,
+                                  width, 0, &ma35d1_lock);
+}
+
+static inline struct clk_hw *ma35d1_clk_divider(const char *name,
+                                               const char *parent,
+                                               void __iomem *reg, u8 shift,
+                                               u8 width)
+{
+       return clk_hw_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
+                                      reg, shift, width, 0, &ma35d1_lock);
+}
+
+static inline struct clk_hw *ma35d1_clk_divider_pow2(const char *name,
+                                                    const char *parent,
+                                                    void __iomem *reg,
+                                                    u8 shift, u8 width)
+{
+       return clk_hw_register_divider(NULL, name, parent,
+                                      CLK_DIVIDER_POWER_OF_TWO, reg, shift,
+                                      width, 0, &ma35d1_lock);
+}
+
+static inline struct clk_hw *ma35d1_clk_divider_table(const char *name,
+                                       const char *parent,
+                                       void __iomem *reg,
+                                       u8 shift, u8 width,
+                                       const struct clk_div_table *table)
+{
+       return clk_hw_register_divider_table(NULL, name, parent, 0,
+                                            reg, shift, width, 0, table,
+                                            &ma35d1_lock);
+}
+
+static inline struct clk_hw *ma35d1_clk_fixed_factor(const char *name,
+                                                    const char *parent,
+                                                    unsigned int mult,
+                                                    unsigned int div)
+{
+       return clk_hw_register_fixed_factor(NULL, name, parent,

drivers/clk/nuvoton/clk-ma35d1.c line 255

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +10 -0
+                                           CLK_SET_RATE_PARENT, mult, div);
+}
+
+static inline struct clk_hw *ma35d1_clk_gate(const char *name,
+                                            const char *parent,
+                                            void __iomem *reg, u8 shift)
+{
+       return clk_hw_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT,
+                                   reg, shift, 0, &ma35d1_lock);
+}

These need to use devm_ to unregister on failure.

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +10 -0
+
+static int ma35d1_get_pll_setting(struct device_node *clk_node,
+                                 u32 *pllmode, u32 *pllfreq)
+{
+       const char *of_str;
+       int i;
+
+       for (i = 0; i < PLL_MAX_NUM; i++) {
+               if (of_property_read_string_index(clk_node, "nuvoton,pll-mode", i, &of_str))
+                       return -EINVAL;

drivers/clk/nuvoton/clk-ma35d1.c line 275

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +10 -0
+               if (!strcmp(of_str, "integer"))
+                       pllmode[i] = PLL_MODE_INT;
+               else if (!strcmp(of_str, "fractional"))
+                       pllmode[i] = PLL_MODE_FRAC;
+               else if (!strcmp(of_str, "spread-spectrum"))
+                       pllmode[i] = PLL_MODE_SS;
+               else
+                       return -EINVAL;
+       }
+       return of_property_read_u32_array(clk_node, "assigned-clock-rates",

The clk framework looks at this property. Why is the driver looking at it too?

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +3 -0
+                                         pllfreq, PLL_MAX_NUM);
+}
+
#47 lore raw

Re: [PATCH v6 09/12] clk: nuvoton: Add clock driver for ma35d1 clock controller

Dear Stephen,

Thanks for your advice.

Quoted 25 lines · Stephen Boyd

Quoting Jacky Huang (2023-03-27 19:19:09)

drivers/clk/nuvoton/Kconfig line 6

Quoted 12 lines
drivers/clk/nuvoton/Kconfig new file +6 -0
new file mode 100644
index 000000000000..c1324efedcb9
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0
+# common clock support for Nuvoton SoC family.
+
+config COMMON_CLK_NUVOTON
+       bool "Nuvoton clock controller common support"
+       depends on ARCH_NUVOTON

Add || COMPILE_TEST

drivers/clk/nuvoton/Kconfig line 11

Quoted 5 lines
drivers/clk/nuvoton/Kconfig new file +5 -0
+       default ARCH_NUVOTON
+       help
+         Say y here to enable common clock controller for Nuvoton platforms.
+
+if COMMON_CLK_NUVOTON

Add a newline here.

drivers/clk/nuvoton/Kconfig line 14

Quoted 3 lines
drivers/clk/nuvoton/Kconfig new file +3 -0
+config CLK_MA35D1
+       bool "Nuvoton MA35D1 clock controller support"
+       depends on ARM64 || COMPILE_TEST
Quoted 8 lines

Drop this

drivers/clk/nuvoton/Kconfig line 15

Quoted 1 line
drivers/clk/nuvoton/Kconfig new file +1 -0
+       default y

And this.

drivers/clk/nuvoton/Kconfig line 17

Quoted 2 lines
drivers/clk/nuvoton/Kconfig new file +2 -0
+       help
+         Build the driver for MA35D1 Clock Driver.

This says driver twice. "Build the clk driver for MA35D1 SoCs"?

I will fix all above of Kconfig file. Thank you.

Quoted 15 lines
Quoted 15 lines
drivers/clk/nuvoton/Kconfig new file +2 -0
+
+endif
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +7 -0
new file mode 100644
index 000000000000..340a889a1417
@@ -0,0 +1,140 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 Nuvoton Technology Corp.
+ * Author: Chi-Fang Li <[email protected]>
+ */
+
+#include <linux/clk-provider.h>
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-divider.c line 14

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +7 -0
+#include <linux/device.h>
+#include <linux/regmap.h>
+#include <linux/spinlock.h>
+
+#include "clk-ma35d1.h"
+
+#define clk_div_mask(width)    ((1 << (width)) - 1)

clk-provider.h defines this already, use that?

Yes, I will remove this.

Quoted 47 lines
Quoted 47 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +47 -0
+
+struct ma35d1_adc_clk_div {
+       struct clk_hw hw;
+       void __iomem *reg;
+       u8 shift;
+       u8 width;
+       u32 mask;
+       const struct clk_div_table *table;
+       /* protects concurrent access to clock divider registers */
+       spinlock_t *lock;
+};
+
+static inline struct ma35d1_adc_clk_div *to_ma35d1_adc_clk_div(struct clk_hw *_hw)
+{
+       return container_of(_hw, struct ma35d1_adc_clk_div, hw);
+}
+
+static inline unsigned long ma35d1_clkdiv_recalc_rate(struct clk_hw *hw,
+                                                     unsigned long parent_rate)
+{
+       unsigned int val;
+       struct ma35d1_adc_clk_div *dclk = to_ma35d1_adc_clk_div(hw);
+
+       val = readl_relaxed(dclk->reg) >> dclk->shift;
+       val &= clk_div_mask(dclk->width);
+       val += 1;
+       return divider_recalc_rate(hw, parent_rate, val, dclk->table,
+                                  CLK_DIVIDER_ROUND_CLOSEST, dclk->width);
+}
+
+static inline long ma35d1_clkdiv_round_rate(struct clk_hw *hw,
+                                           unsigned long rate,
+                                           unsigned long *prate)
+{
+       struct ma35d1_adc_clk_div *dclk = to_ma35d1_adc_clk_div(hw);
+
+       return divider_round_rate(hw, rate, prate, dclk->table,
+                                 dclk->width, CLK_DIVIDER_ROUND_CLOSEST);
+}
+
+static inline int ma35d1_clkdiv_set_rate(struct clk_hw *hw,
+                                        unsigned long rate,
+                                        unsigned long parent_rate)
+{
+       int value;
+       unsigned long flags = 0;
+       u32 data;
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-divider.c line 68

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +7 -0
+       struct ma35d1_adc_clk_div *dclk = to_ma35d1_adc_clk_div(hw);
+
+       value = divider_get_val(rate, parent_rate, dclk->table,
+                               dclk->width, CLK_DIVIDER_ROUND_CLOSEST);
+
+       if (dclk->lock)
+               spin_lock_irqsave(dclk->lock, flags);

Can you just always lock? That makes the conditional locking go away.

OK, I will remove the "if (dclk->lock)" check.

Quoted 41 lines
Quoted 41 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +40 -0
+
+       data = readl_relaxed(dclk->reg);
+       data &= ~(clk_div_mask(dclk->width) << dclk->shift);
+       data |= (value - 1) << dclk->shift;
+       data |= dclk->mask;
+
+       writel_relaxed(data, dclk->reg);
+
+       if (dclk->lock)
+               spin_unlock_irqrestore(dclk->lock, flags);
+
+       return 0;
+}
+
+static const struct clk_ops ma35d1_adc_clkdiv_ops = {
+       .recalc_rate = ma35d1_clkdiv_recalc_rate,
+       .round_rate = ma35d1_clkdiv_round_rate,
+       .set_rate = ma35d1_clkdiv_set_rate,
+};
+
+struct clk_hw *ma35d1_reg_adc_clkdiv(struct device *dev, const char *name,
+                                    const char *parent_name,
+                                    spinlock_t *lock,
+                                    unsigned long flags, void __iomem *reg,
+                                    u8 shift, u8 width, u32 mask_bit)
+{
+       struct ma35d1_adc_clk_div *div;
+       struct clk_init_data init;
+       struct clk_div_table *table;
+       u32 max_div, min_div;
+       struct clk_hw *hw;
+       int ret;
+       int i;
+
+       div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL);
+       if (!div)
+               return ERR_PTR(-ENOMEM);
+
+       max_div = clk_div_mask(width) + 1;
+       min_div = 1;
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-divider.c line 115

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +7 -0
+
+       table = devm_kcalloc(dev, max_div + 1, sizeof(*table), GFP_KERNEL);
+       if (!table)
+               return ERR_PTR(-ENOMEM);
+
+       for (i = 0; i < max_div; i++) {
+               table[i].val = (min_div + i);

Drop useless parenthesis.

I will fix it.

Quoted 16 lines
Quoted 16 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +15 -0
+               table[i].div = 2 * table[i].val;
+       }
+       table[max_div].val = 0;
+       table[max_div].div = 0;
+
+       init.name = name;
+       init.ops = &ma35d1_adc_clkdiv_ops;
+       init.flags |= flags;
+       init.parent_names = parent_name ? &parent_name : NULL;
+       init.num_parents = parent_name ? 1 : 0;
+
+       div->reg = reg;
+       div->shift = shift;
+       div->width = width;
+       div->mask = mask_bit ? BIT(mask_bit) : 0;
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-divider.c line 137

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +7 -0
+       div->lock = lock;
+       div->hw.init = &init;
+       div->table = table;
+
+       hw = &div->hw;
+       ret = devm_clk_hw_register(dev, hw);
+       if (ret < 0)

Use if (ret) instead.

I will fix it.

Quoted 24 lines
Quoted 24 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +3 -0
+               return ERR_PTR(ret);
+       return hw;
+}
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +14 -0
new file mode 100644
index 000000000000..b36fbda4fa0a
@@ -0,0 +1,350 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 Nuvoton Technology Corp.
+ * Author: Chi-Fang Li <[email protected]>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk-provider.h>
+#include <linux/slab.h>
+#include <linux/regmap.h>
+
+#include "clk-ma35d1.h"
+
+#define REG_SYS_RLKTZNS                0x1a4 /* Register Lock Control */
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 21

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7 -0
+
+struct ma35d1_clk_pll {
+       struct clk_hw hw;
+       u8 type;
+       u8 mode;
+       unsigned long rate;
+       void __iomem *ctl0_base;

This needs an include for __iomem define. Just include kernel.h for now.

OK, I will add it.

Quoted 9 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 29

Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +8 -0
+       void __iomem *ctl1_base;
+       void __iomem *ctl2_base;
+       struct regmap *regmap;
+};
+
+static inline struct ma35d1_clk_pll *to_ma35d1_clk_pll(struct clk_hw *_hw)
+{
+       return container_of(_hw, struct ma35d1_clk_pll, hw);

Missing include as well.

I will add the
#include <linux/container_of.h>

Quoted 14 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 41

Quoted 13 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +12 -0
+}
+
+static void ma35d1_unlock_regs(struct ma35d1_clk_pll *pll)
+{
+       int ret;
+
+       do {
+               regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x59);
+               regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x16);
+               regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x88);
+               regmap_read(pll->regmap, REG_SYS_RLKTZNS, &ret);
+       } while (ret == 0);

Any sort of timeout?

As we have discussed in [PATCH v6 08/12] of this patchset, we will remove the register lock. So, this function will be removed in the next version.

Quoted 6 lines
Quoted 6 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +6 -0
+}
+
+static void ma35d1_lock_regs(struct ma35d1_clk_pll *pll)
+{
+       regmap_write(pll->regmap, REG_SYS_RLKTZNS, 0x0);
+}
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 54

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7 -0
+
+static unsigned long ma35d1_calc_smic_pll_freq(u32 pll0_ctl0,
+                                              unsigned long parent_rate)
+{
+       u32 m, n, p, outdiv;
+       u64 pll_freq;
+       u32 clk_div_table[] = { 1, 2, 4, 8 };

const

OK, I will add const to the clk_div_table[].

Quoted 13 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 65

Quoted 12 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +11 -0
+
+       if (pll0_ctl0 & SPLL0_CTL0_BP)
+               return parent_rate;
+
+       n = FIELD_GET(SPLL0_CTL0_FBDIV, pll0_ctl0);
+       m = FIELD_GET(SPLL0_CTL0_INDIV, pll0_ctl0);
+       p = FIELD_GET(SPLL0_CTL0_OUTDIV, pll0_ctl0);
+       outdiv = clk_div_table[p];
+       pll_freq = (u64)parent_rate * n;
+       do_div(pll_freq, m * outdiv);
+       return (unsigned long)pll_freq;

Remove useless cast.

I will fix it.

Quoted 14 lines
Quoted 14 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +14 -0
+}
+
+static unsigned long ma35d1_calc_pll_freq(u8 mode, u32 *reg_ctl,
+                                         unsigned long parent_rate)
+{
+       u32 m, n, p;
+       u64 pll_freq, x;
+
+       if (reg_ctl[1] & PLL_CTL1_BP)
+               return parent_rate;
+
+       if (mode == PLL_MODE_INT) {
+               n = FIELD_GET(PLL_CTL0_FBDIV, reg_ctl[0]);
+               m = FIELD_GET(PLL_CTL0_INDIV, reg_ctl[0]);
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 86

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7 -0
+               p = FIELD_GET(PLL_CTL1_OUTDIV, reg_ctl[1]);
+               pll_freq = (u64)parent_rate * n;
+               do_div(pll_freq, m * p);
+       } else {
+               n = FIELD_GET(PLL_CTL0_FBDIV, reg_ctl[0]);
+               m = FIELD_GET(PLL_CTL0_INDIV, reg_ctl[0]);
+               p = FIELD_GET(PLL_CTL1_OUTDIV, reg_ctl[1]);

The n, m, p are the same, so pull them out of the if-else to deduplicate.

Ok, I will modify it.

Quoted 5 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 89

Quoted 4 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +3 -0
+               x = FIELD_GET(PLL_CTL1_FRAC, reg_ctl[1]);
+               /* 2 decimal places floating to integer (ex. 1.23 to 123) */
+               n = n * 100 + ((x * 100) / FIELD_MAX(PLL_CTL1_FRAC));

Is this mult_frac()?

Not exactly. The number is represented as n.x.
Suppose the number is 123.45, then n is 123 and x is 45. We have it be multiplied with 100 to be integer 12345, which is n.

In the following
pll_freq = ((u64)parent_rate * n) / 100 / m / p;

We can keep precision of n.

It seems not applicable to mult_frac().

Quoted 7 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 91

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +2 -0
+               pll_freq = ((u64)parent_rate * n) / 100 / m / p;
+       }

Add a newline

drivers/clk/nuvoton/clk-ma35d1-pll.c line 92

Quoted 1 line
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +1 -0
+       return (unsigned long)pll_freq;

Remove useless cast.

I will fix them.

Quoted 77 lines
Quoted 65 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +65 -0
+}
+
+static int ma35d1_pll_find_closest(struct ma35d1_clk_pll *pll,
+                                  unsigned long rate,
+                                  unsigned long parent_rate,
+                                  u32 *reg_ctl, unsigned long *freq)
+{
+       int p, m, n;
+       int fbdiv_min, fbdiv_max;
+       unsigned long diff = 0xffffffff;
+
+       *freq = 0;
+       if ((rate < PLL_FCLKO_MIN_FREQ) || (rate > PLL_FCLKO_MAX_FREQ))
+               return -EINVAL;
+
+       if (pll->mode == PLL_MODE_INT) {
+               fbdiv_min = FBDIV_MIN;
+               fbdiv_max = FBDIV_MAX;
+       } else {
+               fbdiv_min = FBDIV_FRAC_MIN;
+               fbdiv_max = FBDIV_FRAC_MAX;
+       }
+
+       for (m = INDIV_MIN; m <= INDIV_MAX; m++) {
+               for (n = fbdiv_min; n <= fbdiv_max; n++) {
+                       for (p = OUTDIV_MIN; p <= OUTDIV_MAX; p++) {
+                               unsigned long tmp, fout;
+                               u64 fclk;
+
+                               tmp = parent_rate / m;
+                               if (tmp < PLL_FREF_M_MIN_FREQ ||
+                                   tmp > PLL_FREF_M_MAX_FREQ)
+                                       continue; /* constrain */
+
+                               fclk = (u64)parent_rate * n / m;
+                               /* for 2 decimal places */
+                               if (pll->mode != PLL_MODE_INT)
+                                       fclk /= 100;
+
+                               if (fclk < PLL_FCLK_MIN_FREQ ||
+                                   fclk > PLL_FCLK_MAX_FREQ)
+                                       continue; /* constrain */
+
+                               fout = (unsigned long)(fclk / p);
+                               if (fout < PLL_FCLKO_MIN_FREQ ||
+                                   fout > PLL_FCLKO_MAX_FREQ)
+                                       continue; /* constrain */
+
+                               if (abs(rate - fout) < diff) {
+                                       reg_ctl[0] = FIELD_PREP(PLL_CTL0_INDIV, m) |
+                                                    FIELD_PREP(PLL_CTL0_FBDIV, n);
+                                       reg_ctl[1] = FIELD_PREP(PLL_CTL1_OUTDIV, p);
+                                       *freq = fout;
+                                       diff = abs(rate - fout);
+                                       if (diff == 0)
+                                               break;
+                               }
+                       }
+               }
+       }
+       if (*freq == 0)
+               return -EINVAL; /* cannot find even one valid setting */
+       return 0;
+}
+

drivers/clk/nuvoton/clk-ma35d1-pll.c line 167

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+static int ma35d1_clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
+                                  unsigned long parent_rate)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 reg_ctl[3] = { 0 };
+       unsigned long pll_freq;
+       int ret;
+
+       if ((parent_rate < PLL_FREF_MIN_FREQ) ||
+           (parent_rate > PLL_FREF_MAX_FREQ))

Remove useless parenthesis.

Quoted 4 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 170

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +3 -0
+               return -EINVAL;
+
+       if ((pll->type == MA35D1_CAPLL) || (pll->type == MA35D1_DDRPLL)) {

Remove useless parenthesis.

I will fix them.

Quoted 33 lines
Quoted 33 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +33 -0
+               pr_warn("Nuvoton MA35D1 CAPLL/DDRPLL is read only.\n");
+               return -EACCES;
+       }
+
+       ret = ma35d1_pll_find_closest(pll, rate, parent_rate, reg_ctl, &pll_freq);
+       if (ret != 0)
+               return ret;
+       pll->rate = pll_freq;
+
+       switch (pll->mode) {
+       case PLL_MODE_INT:
+               reg_ctl[0] |= FIELD_PREP(PLL_CTL0_MODE, PLL_MODE_INT);
+               break;
+       case PLL_MODE_FRAC:
+               reg_ctl[0] |= FIELD_PREP(PLL_CTL0_MODE, PLL_MODE_FRAC);
+               break;
+       case PLL_MODE_SS:
+               reg_ctl[0] |= FIELD_PREP(PLL_CTL0_MODE, PLL_MODE_SS) |
+                             FIELD_PREP(PLL_CTL0_SSRATE, PLL_SS_RATE);
+               reg_ctl[2] = FIELD_PREP(PLL_CTL2_SLOPE, PLL_SLOPE);
+               break;
+       }
+       reg_ctl[1] |= PLL_CTL1_PD;
+
+       ma35d1_unlock_regs(pll);
+       writel_relaxed(reg_ctl[0], pll->ctl0_base);
+       writel_relaxed(reg_ctl[1], pll->ctl1_base);
+       writel_relaxed(reg_ctl[2], pll->ctl2_base);
+       ma35d1_lock_regs(pll);
+       return 0;
+}
+
+static unsigned long ma35d1_clk_pll_recalc_rate(struct clk_hw *hw,
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 210

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7 -0
+                                               unsigned long parent_rate)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 reg_ctl[3];
+       unsigned long pll_freq;
+
+       if ((parent_rate < PLL_FREF_MIN_FREQ) || (parent_rate > PLL_FREF_MAX_FREQ))

Remove useless parenthesis.

I will fix it.

Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 216

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +6 -0
+               return 0;
+
+       switch (pll->type) {
+       case MA35D1_CAPLL:
+               reg_ctl[0] = readl_relaxed(pll->ctl0_base);
+               pll_freq = ma35d1_calc_smic_pll_freq(reg_ctl[0], parent_rate);

return?

Yes, I will have it return here.

Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 224

Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +8 -0
+               break;
+       case MA35D1_DDRPLL:
+       case MA35D1_APLL:
+       case MA35D1_EPLL:
+       case MA35D1_VPLL:
+               reg_ctl[0] = readl_relaxed(pll->ctl0_base);
+               reg_ctl[1] = readl_relaxed(pll->ctl1_base);
+               pll_freq = ma35d1_calc_pll_freq(pll->mode, reg_ctl, parent_rate);
Quoted 6 lines

return?

drivers/clk/nuvoton/clk-ma35d1-pll.c line 227

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +3 -0
+               break;
+       }
+       return pll_freq;

return 0?

Yes, I will fix them.

Quoted 32 lines
Quoted 12 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +11 -0
+}
+
+static long ma35d1_clk_pll_round_rate(struct clk_hw *hw, unsigned long rate,
+                                     unsigned long *parent_rate)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 reg_ctl[3] = { 0 };
+       unsigned long pll_freq;
+       long ret;
+
+       if (*parent_rate < PLL_FREF_MIN_FREQ || *parent_rate > PLL_FREF_MAX_FREQ)

drivers/clk/nuvoton/clk-ma35d1-pll.c line 248

Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+               return -EINVAL;
+
+       ret = ma35d1_pll_find_closest(pll, rate, *parent_rate, reg_ctl, &pll_freq);
+       if (ret != 0)
+               return ret;
+
+       switch (pll->type) {
+       case MA35D1_CAPLL:
+               reg_ctl[0] = readl_relaxed(pll->ctl0_base);
+               pll_freq = ma35d1_calc_smic_pll_freq(reg_ctl[0], *parent_rate);

return?

drivers/clk/nuvoton/clk-ma35d1-pll.c line 256

Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +8 -0
+               break;
+       case MA35D1_DDRPLL:
+       case MA35D1_APLL:
+       case MA35D1_EPLL:
+       case MA35D1_VPLL:
+               reg_ctl[0] = readl_relaxed(pll->ctl0_base);
+               reg_ctl[1] = readl_relaxed(pll->ctl1_base);
+               pll_freq = ma35d1_calc_pll_freq(pll->mode, reg_ctl, *parent_rate);
Quoted 6 lines

return?

drivers/clk/nuvoton/clk-ma35d1-pll.c line 227

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +3 -0
+               break;
+       }
+       return pll_freq;

return 0?

Yes, I will fix them.

Quoted 9 lines
Quoted 9 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +9 -0
+}
+
+static int ma35d1_clk_pll_is_prepared(struct clk_hw *hw)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 val = readl_relaxed(pll->ctl1_base);
+
+       return val & PLL_CTL1_PD ? 0 : 1;
+}
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 275

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7 -0
+
+static int ma35d1_clk_pll_prepare(struct clk_hw *hw)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 val;
+
+       if ((pll->type == MA35D1_CAPLL) || (pll->type == MA35D1_DDRPLL)) {

Drop useless parenthesis.

I will fix it.

Quoted 12 lines
Quoted 12 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +11 -0
+               pr_warn("Nuvoton MA35D1 CAPLL/DDRPLL is read only.\n");
+               return -EACCES;
+       }
+
+       ma35d1_unlock_regs(pll);
+       val = readl_relaxed(pll->ctl1_base);
+       val &= ~PLL_CTL1_PD;
+       writel_relaxed(val, pll->ctl1_base);
+       ma35d1_lock_regs(pll);
+       return 0;
+}
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 293

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7 -0
+
+static void ma35d1_clk_pll_unprepare(struct clk_hw *hw)
+{
+       struct ma35d1_clk_pll *pll = to_ma35d1_clk_pll(hw);
+       u32 val;
+
+       if ((pll->type == MA35D1_CAPLL) || (pll->type == MA35D1_DDRPLL)) {

Drop useless parenthesis.

I will fix it.

Quoted 4 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 294

Quoted 2 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +1 -0
+               pr_warn("Nuvoton MA35D1 CAPLL/DDRPLL is read only.\n");

These read-only checks should be removed and different clk_ops should be assigned for the read-only type of clks.

OK, I will fix it.

Quoted 10 lines
Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10 -0
+       } else {
+               val = readl_relaxed(pll->ctl1_base);
+               val |= PLL_CTL1_PD;
+               writel_relaxed(val, pll->ctl1_base);
+       }
+}
+
+static const struct clk_ops ma35d1_clk_pll_ops = {
+       .is_prepared = ma35d1_clk_pll_is_prepared,
+       .prepare = ma35d1_clk_pll_prepare,
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 311

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7 -0
+       .unprepare = ma35d1_clk_pll_unprepare,
+       .set_rate = ma35d1_clk_pll_set_rate,
+       .recalc_rate = ma35d1_clk_pll_recalc_rate,
+       .round_rate = ma35d1_clk_pll_round_rate,
+};
+
+struct clk_hw *ma35d1_reg_clk_pll(enum ma35d1_pll_type type,

Pass a device here.

OK, I will add it.

Quoted 9 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 320

Quoted 9 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +9 -0
+                                 u8 u8mode, const char *name,
+                                 const char *parent,
+                                 unsigned long targetFreq,
+                                 void __iomem *base,
+                                 struct regmap *regmap)
+{
+       struct ma35d1_clk_pll *pll;
+       struct clk_hw *hw;
+       struct clk_init_data init;
Quoted 6 lines

init = {};

drivers/clk/nuvoton/clk-ma35d1-pll.c line 323

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +3 -0
+       int ret;
+
+       pll = kmalloc(sizeof(*pll), GFP_KERNEL);

Just use kzalloc(). This isn't a hot path.

I will use devm_kzalloc().

Quoted 13 lines
Quoted 13 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +13 -0
+       if (!pll)
+               return ERR_PTR(-ENOMEM);
+
+       pll->type = type;
+       pll->mode = u8mode;
+       pll->rate = targetFreq;
+       pll->ctl0_base = base + REG_PLL_CTL0_OFFSET;
+       pll->ctl1_base = base + REG_PLL_CTL1_OFFSET;
+       pll->ctl2_base = base + REG_PLL_CTL2_OFFSET;
+       pll->regmap = regmap;
+
+       init.name = name;
+       init.flags = 0;
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 343

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7 -0
+       init.parent_names = &parent;
+       init.num_parents = 1;
+       init.ops = &ma35d1_clk_pll_ops;
+       pll->hw.init = &init;
+       hw = &pll->hw;
+
+       ret = clk_hw_register(NULL, hw);

Use devm_

OK, I will fix it.

Quoted 5 lines

drivers/clk/nuvoton/clk-ma35d1-pll.c line 345

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +2 -0
+       if (ret) {
+               pr_err("failed to register vsi-pll clock!!!\n");

I'm going to put a dev_err_probe() into clk registration code. Remove this printk.

OK, I will remove it.

Quoted 24 lines
Quoted 24 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +5 -0
+               kfree(pll);
+               return ERR_PTR(ret);
+       }
+       return hw;
+}
drivers/clk/nuvoton/clk-ma35d1.c new file +13 -0
new file mode 100644
index 000000000000..e4d3ced396a3
@@ -0,0 +1,963 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 Nuvoton Technology Corp.
+ * Author: Chi-Fang Li <[email protected]>
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/spinlock.h>
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1.c line 20

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +7 -0
+#include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
+
+#include "clk-ma35d1.h"
+
+static DEFINE_SPINLOCK(ma35d1_lock);
+
+static const char *const ca35clk_sel_clks[] = {

Use clk_parent_data instead.

I will fix it.

Quoted 61 lines
Quoted 4 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +3 -0
+       "hxt", "capll", "ddrpll", "dummy"
+};
+

[...]

Quoted 56 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +56 -0
+
+static inline struct clk_hw *ma35d1_clk_fixed(const char *name, int rate)
+{
+       return clk_hw_register_fixed_rate(NULL, name, NULL, 0, rate);
+}
+
+static inline struct clk_hw *ma35d1_clk_mux(const char *name,
+                                           void __iomem *reg,
+                                           u8 shift, u8 width,
+                                           const char *const *parents,
+                                           int num_parents)
+{
+       return clk_hw_register_mux(NULL, name, parents, num_parents,
+                                  CLK_SET_RATE_NO_REPARENT, reg, shift,
+                                  width, 0, &ma35d1_lock);
+}
+
+static inline struct clk_hw *ma35d1_clk_divider(const char *name,
+                                               const char *parent,
+                                               void __iomem *reg, u8 shift,
+                                               u8 width)
+{
+       return clk_hw_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
+                                      reg, shift, width, 0, &ma35d1_lock);
+}
+
+static inline struct clk_hw *ma35d1_clk_divider_pow2(const char *name,
+                                                    const char *parent,
+                                                    void __iomem *reg,
+                                                    u8 shift, u8 width)
+{
+       return clk_hw_register_divider(NULL, name, parent,
+                                      CLK_DIVIDER_POWER_OF_TWO, reg, shift,
+                                      width, 0, &ma35d1_lock);
+}
+
+static inline struct clk_hw *ma35d1_clk_divider_table(const char *name,
+                                       const char *parent,
+                                       void __iomem *reg,
+                                       u8 shift, u8 width,
+                                       const struct clk_div_table *table)
+{
+       return clk_hw_register_divider_table(NULL, name, parent, 0,
+                                            reg, shift, width, 0, table,
+                                            &ma35d1_lock);
+}
+
+static inline struct clk_hw *ma35d1_clk_fixed_factor(const char *name,
+                                                    const char *parent,
+                                                    unsigned int mult,
+                                                    unsigned int div)
+{
+       return clk_hw_register_fixed_factor(NULL, name, parent,
+                                           CLK_SET_RATE_PARENT, mult, div);
+}
+
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1.c line 255

Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +7 -0
+static inline struct clk_hw *ma35d1_clk_gate(const char *name,
+                                            const char *parent,
+                                            void __iomem *reg, u8 shift)
+{
+       return clk_hw_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT,
+                                   reg, shift, 0, &ma35d1_lock);
+}

These need to use devm_ to unregister on failure.

OK, I will fix them all.

Quoted 14 lines
Quoted 14 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +14 -0
+
+static int ma35d1_get_pll_setting(struct device_node *clk_node,
+                                 u32 *pllmode, u32 *pllfreq)
+{
+       const char *of_str;
+       int i;
+
+       for (i = 0; i < PLL_MAX_NUM; i++) {
+               if (of_property_read_string_index(clk_node, "nuvoton,pll-mode", i, &of_str))
+                       return -EINVAL;
+               if (!strcmp(of_str, "integer"))
+                       pllmode[i] = PLL_MODE_INT;
+               else if (!strcmp(of_str, "fractional"))
+                       pllmode[i] = PLL_MODE_FRAC;
Quoted 8 lines

drivers/clk/nuvoton/clk-ma35d1.c line 275

Quoted 6 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +6 -0
+               else if (!strcmp(of_str, "spread-spectrum"))
+                       pllmode[i] = PLL_MODE_SS;
+               else
+                       return -EINVAL;
+       }
+       return of_property_read_u32_array(clk_node, "assigned-clock-rates",

The clk framework looks at this property. Why is the driver looking at it too?

We should not use "assigned-clock-rates", instead we should create a vendor-specific property to describe the pll frequency array.

I will fix it in the next version.

Quoted 3 lines

drivers/clk/nuvoton/clk-ma35d1.c line 278

Quoted 3 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +3 -0
+                                         pllfreq, PLL_MAX_NUM);
+}
+

Best regards,
Jacky Huang

#48 lore raw

PATCH v6 10/12 reset: Add Nuvoton ma35d1 reset driver support

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

This driver supports individual IP reset for ma35d1. The reset control registers is a subset of system control registers.

---
 drivers/reset/Kconfig        |   6 ++
 drivers/reset/Makefile       |   1 +
 drivers/reset/reset-ma35d1.c | 152 +++++++++++++++++++++++++++++++++++
 3 files changed, 159 insertions(+)
 create mode 100644 drivers/reset/reset-ma35d1.c
drivers/reset/Kconfig +6 -0
index 2a52c990d4fe..58477c6ca9b8 100644
@@ -143,6 +143,12 @@ config RESET_NPCM
 	  This enables the reset controller driver for Nuvoton NPCM
 	  BMC SoCs.
 
+config RESET_NUVOTON_MA35D1
+	bool "Nuvton MA35D1 Reset Driver"
+	default ARCH_NUVOTON || COMPILE_TEST
+	help
+	  This enables the reset controller driver for Nuvoton MA35D1 SoC.
+
 config RESET_OXNAS
 	bool
 
drivers/reset/Makefile +1 -0
index 3e7e5fd633a8..fd52dcf66a99 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_RESET_MCHP_SPARX5) += reset-microchip-sparx5.o
 obj-$(CONFIG_RESET_MESON) += reset-meson.o
 obj-$(CONFIG_RESET_MESON_AUDIO_ARB) += reset-meson-audio-arb.o
 obj-$(CONFIG_RESET_NPCM) += reset-npcm.o
+obj-$(CONFIG_RESET_NUVOTON_MA35D1) += reset-ma35d1.o
 obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o
 obj-$(CONFIG_RESET_PISTACHIO) += reset-pistachio.o
 obj-$(CONFIG_RESET_POLARFIRE_SOC) += reset-mpfs.o
drivers/reset/reset-ma35d1.c new file +152 -0

152 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#49 lore raw

Re: [PATCH v6 10/12] reset: Add Nuvoton ma35d1 reset driver support

Hi Jacky,

Quoted 13 lines · Jacky Huang

From: Jacky Huang <[email protected]>

This driver supports individual IP reset for ma35d1. The reset control registers is a subset of system control registers.

---
 drivers/reset/Kconfig        |   6 ++
 drivers/reset/Makefile       |   1 +
 drivers/reset/reset-ma35d1.c | 152 +++++++++++++++++++++++++++++++++++
 3 files changed, 159 insertions(+)
 create mode 100644 drivers/reset/reset-ma35d1.c

[...]

Quoted 6 lines
drivers/reset/reset-ma35d1.c new file +0 -0
new file mode 100644
index 000000000000..221299e7b873
@@ -0,0 +1,152 @@

[...]

Quoted 8 lines
drivers/reset/reset-ma35d1.c new file +8 -0
+static int ma35d1_reset_update(struct reset_controller_dev *rcdev,
+			       unsigned long id, bool assert)
+{
+	unsigned int reg;
+	int ret;
+	int offset = (id / RST_PRE_REG) * 4;
+	struct ma35d1_reset_data *data =
+			container_of(rcdev, struct ma35d1_reset_data, rcdev);

drivers/reset/reset-ma35d1.c line 59

Quoted 10 lines
drivers/reset/reset-ma35d1.c new file +10 -0
+
+	ret = regmap_read(data->regmap, REG_SYS_IPRST0 + offset, &reg);
+	if (ret < 0)
+		return ret;
+	if (assert)
+		reg |= 1 << (id % RST_PRE_REG);
+	else
+		reg &= ~(1 << (id % RST_PRE_REG));
+
+	return regmap_write(data->regmap, REG_SYS_IPRST0 + offset, reg);

This should use regmap_update_bits().

[...]

drivers/reset/reset-ma35d1.c line 78

Quoted 5 lines
drivers/reset/reset-ma35d1.c new file +5 -0
+static int ma35d1_reset_status(struct reset_controller_dev *rcdev,
+			      unsigned long id)
+{
+	int reg, ret;
+	int offset = id / RST_PRE_REG;

Should this be

	int offset = (id / RST_PRE_REG) * 4;

?

Quoted 10 lines
drivers/reset/reset-ma35d1.c new file +10 -0
+static int ma35d1_reset_probe(struct platform_device *pdev)
+{
+	int err;
+	struct device *dev = &pdev->dev;
+	struct device_node *parent;
+	struct ma35d1_reset_data *reset_data;
+	struct ma35d1_reboot_data *reboot_data;
+
+	if (!pdev->dev.of_node) {
+		dev_err(&pdev->dev, "Device tree node not found\n");

drivers/reset/reset-ma35d1.c line 118

Quoted 10 lines
drivers/reset/reset-ma35d1.c new file +10 -0
+		return -EINVAL;
+	}
+
+	reset_data = devm_kzalloc(dev, sizeof(*reset_data), GFP_KERNEL);
+	if (!reset_data)
+		return -ENOMEM;
+
+	reboot_data = devm_kzalloc(dev, sizeof(*reboot_data), GFP_KERNEL);
+	if (!reboot_data)
+		return -ENOMEM;

These structures could be combined into one.

regards
Philipp

#50 lore raw

Re: [PATCH v6 10/12] reset: Add Nuvoton ma35d1 reset driver support

Dear Philipp,

Quoted 52 lines · Philipp Zabel

Hi Jacky,

Quoted 13 lines · Jacky Huang

From: Jacky Huang <[email protected]>

This driver supports individual IP reset for ma35d1. The reset control registers is a subset of system control registers.

---
  drivers/reset/Kconfig        |   6 ++
  drivers/reset/Makefile       |   1 +
  drivers/reset/reset-ma35d1.c | 152 +++++++++++++++++++++++++++++++++++
  3 files changed, 159 insertions(+)

create mode 100644 drivers/reset/reset-ma35d1.c

[...]

Quoted 6 lines
drivers/reset/reset-ma35d1.c new file +0 -0
new file mode 100644
index 000000000000..221299e7b873
@@ -0,0 +1,152 @@

[...]

Quoted 8 lines
drivers/reset/reset-ma35d1.c new file +8 -0
+static int ma35d1_reset_update(struct reset_controller_dev *rcdev,
+			       unsigned long id, bool assert)
+{
+	unsigned int reg;
+	int ret;
+	int offset = (id / RST_PRE_REG) * 4;
+	struct ma35d1_reset_data *data =
+			container_of(rcdev, struct ma35d1_reset_data, rcdev);

drivers/reset/reset-ma35d1.c line 59

Quoted 10 lines
drivers/reset/reset-ma35d1.c new file +10 -0
+
+	ret = regmap_read(data->regmap, REG_SYS_IPRST0 + offset, &reg);
+	if (ret < 0)
+		return ret;
+	if (assert)
+		reg |= 1 << (id % RST_PRE_REG);
+	else
+		reg &= ~(1 << (id % RST_PRE_REG));
+
+	return regmap_write(data->regmap, REG_SYS_IPRST0 + offset, reg);

This should use regmap_update_bits().

[...]

drivers/reset/reset-ma35d1.c line 78

Quoted 5 lines
drivers/reset/reset-ma35d1.c new file +5 -0
+static int ma35d1_reset_status(struct reset_controller_dev *rcdev,
+			      unsigned long id)
+{
+	int reg, ret;
+	int offset = id / RST_PRE_REG;

Should this be

Quoted 3 lines
	int offset = (id / RST_PRE_REG) * 4;

?

Yes, here is a coding mistake.
As the register offset was modified to be indexed by lookup table in v7, this code was obsoleted.
Thank you for pointing out this.

Quoted 13 lines
Quoted 13 lines
drivers/reset/reset-ma35d1.c new file +13 -0
+static int ma35d1_reset_probe(struct platform_device *pdev)
+{
+	int err;
+	struct device *dev = &pdev->dev;
+	struct device_node *parent;
+	struct ma35d1_reset_data *reset_data;
+	struct ma35d1_reboot_data *reboot_data;
+
+	if (!pdev->dev.of_node) {
+		dev_err(&pdev->dev, "Device tree node not found\n");
+		return -EINVAL;
+	}
+
Quoted 8 lines

drivers/reset/reset-ma35d1.c line 118

Quoted 7 lines
drivers/reset/reset-ma35d1.c new file +7 -0
+	reset_data = devm_kzalloc(dev, sizeof(*reset_data), GFP_KERNEL);
+	if (!reset_data)
+		return -ENOMEM;
+
+	reboot_data = devm_kzalloc(dev, sizeof(*reboot_data), GFP_KERNEL);
+	if (!reboot_data)
+		return -ENOMEM;

These structures could be combined into one.

OK, we will combine them into one.

Quoted 2 lines

regards
Philipp

Best regards,
Jacky Huang

#51 lore raw

PATCH v6 11/12 tty: serial: Add Nuvoton ma35d1 serial driver support

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

This adds UART and console driver for Nuvoton ma35d1 Soc. It supports full-duplex communication, FIFO control, and hardware flow control.

---
 drivers/tty/serial/Kconfig         |  18 +
 drivers/tty/serial/Makefile        |   1 +
 drivers/tty/serial/ma35d1_serial.c | 802 +++++++++++++++++++++++++++++
 3 files changed, 821 insertions(+)
 create mode 100644 drivers/tty/serial/ma35d1_serial.c
drivers/tty/serial/Kconfig +18 -0
index 0072892ca7fc..daa4ae6bc08e 100644
@@ -1562,6 +1562,24 @@ config SERIAL_SUNPLUS_CONSOLE
 	  you can alter that using a kernel command line option such as
 	  "console=ttySUPx".
 
+config SERIAL_NUVOTON_MA35D1
+	tristate "Nuvoton MA35D1 family UART support"
+	depends on ARCH_NUVOTON || COMPILE_TEST
+	select SERIAL_CORE
+	help
+	  This driver supports Nuvoton MA35D1 family UART ports. If you would
+	  like to use them, you must answer Y or M to this option. Note that
+	  for use as console, it must be included in kernel and not as a
+	  module
+
+config SERIAL_NUVOTON_MA35D1_CONSOLE
+	bool "Console on a Nuvotn MA35D1 family UART port"
+	depends on SERIAL_NUVOTON_MA35D1=y
+	select SERIAL_CORE_CONSOLE
+	help
+	  Select this options if you'd like to use the UART port0 of the
+	  Nuvoton MA35D1 family as a console.
+
 endmenu
 
 config SERIAL_MCTRL_GPIO
drivers/tty/serial/Makefile +1 -0
index cd9afd9e3018..71ebeba06ff2 100644
@@ -93,3 +93,4 @@ obj-$(CONFIG_SERIAL_MCTRL_GPIO)	+= serial_mctrl_gpio.o
 
 obj-$(CONFIG_SERIAL_KGDB_NMI) += kgdb_nmi.o
 obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o
+obj-$(CONFIG_SERIAL_NUVOTON_MA35D1)	+= ma35d1_serial.o
drivers/tty/serial/ma35d1_serial.c new file +802 -0

802 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#52 lore raw

Re: [PATCH v6 11/12] tty: serial: Add Nuvoton ma35d1 serial driver support

Quoted 4 lines · Jacky Huang
drivers/tty/serial/ma35d1_serial.c new file +4 -0
+static void transmit_chars(struct uart_ma35d1_port *up)
+{
+	struct circ_buf *xmit = &up->port.state->xmit;
+	int count;

drivers/tty/serial/ma35d1_serial.c line 197

Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10 -0
+	u8 ch;
+
+	if (uart_tx_stopped(&up->port)) {
+		ma35d1serial_stop_tx(&up->port);
+		return;
+	}
+	if (uart_circ_empty(xmit)) {
+		__stop_tx(up);
+		return;
+	}

Why is this necessary?

drivers/tty/serial/ma35d1_serial.c line 210

Quoted 12 lines
drivers/tty/serial/ma35d1_serial.c new file +12 -0
+	count = UART_FIFO_DEPTH - ((serial_in(up, UART_REG_FSR) & FSR_TXPTR_MSK) >> 16);
+
+	uart_port_tx_limited(&up->port, ch, count,
+			     !(serial_in(up, UART_REG_FSR) & FSR_TX_FULL),
+			     serial_out(up, UART_REG_THR, ch),
+			     ({}));
+
+	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+		uart_write_wakeup(&up->port);
+
+	if (uart_circ_empty(xmit))
+		__stop_tx(up);

uart_port_tx_limited() should take care about the above and this too, right?

Quoted 1 line

+}

...

drivers/tty/serial/ma35d1_serial.c line 235

Quoted 5 lines
drivers/tty/serial/ma35d1_serial.c new file +5 -0
+static void receive_chars(struct uart_ma35d1_port *up)
+{
+	u8 flag;
+	u32 fsr;
+	unsigned int ch;

Shouldn't ch be u8 too?

Quoted 46 lines
drivers/tty/serial/ma35d1_serial.c new file +46 -0
+	int max_count = 256;
+
+	fsr = serial_in(up, UART_REG_FSR);
+	do {
+		flag = TTY_NORMAL;
+		up->port.icount.rx++;
+
+		if (unlikely(fsr & (FSR_BIF | FSR_FEF | FSR_PEF | FSR_RX_OVER_IF))) {
+			if (fsr & FSR_BIF) {
+				up->port.icount.brk++;
+				if (uart_handle_break(&up->port))
+					continue;
+			}
+			if (fsr & FSR_FEF)
+				up->port.icount.frame++;
+			if (fsr & FSR_PEF)
+				up->port.icount.parity++;
+			if (fsr & FSR_RX_OVER_IF)
+				up->port.icount.overrun++;
+
+			serial_out(up, UART_REG_FSR, fsr &
+				   (FSR_BIF | FSR_FEF | FSR_PEF | FSR_RX_OVER_IF));
+
+			if (fsr & FSR_BIF)
+				flag = TTY_BREAK;
+			else if (fsr & FSR_PEF)
+				flag = TTY_PARITY;
+			else if (fsr & FSR_FEF)
+				flag = TTY_FRAME;
+		}
+
+		ch = serial_in(up, UART_REG_RBR);
+		if (uart_handle_sysrq_char(&up->port, ch))
+			continue;
+
+		spin_lock(&up->port.lock);
+		uart_insert_char(&up->port, fsr, FSR_RX_OVER_IF, ch, flag);
+		spin_unlock(&up->port.lock);
+
+		fsr = serial_in(up, UART_REG_FSR);
+	} while (!(fsr & FSR_RX_EMPTY) && (max_count-- > 0));
+
+	spin_lock(&up->port.lock);
+	tty_flip_buffer_push(&up->port.state->port);
+	spin_unlock(&up->port.lock);
+}

...

drivers/tty/serial/ma35d1_serial.c line 718

Quoted 5 lines
drivers/tty/serial/ma35d1_serial.c new file +5 -0
+static int ma35d1serial_remove(struct platform_device *dev)
+{
+	struct uart_port *port = platform_get_drvdata(dev);
+
+	if (port) {

Can this ever be NULL?

Quoted 8 lines
drivers/tty/serial/ma35d1_serial.c new file +8 -0
+		uart_remove_one_port(&ma35d1serial_reg, port);
+		free_irq(port->irq, port);
+	}
+	return 0;
+}
+
+static int ma35d1serial_suspend(struct platform_device *dev, pm_message_t state)
+{

drivers/tty/serial/ma35d1_serial.c line 736

Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10 -0
+	int i;
+	struct uart_ma35d1_port *up;
+
+	if (dev->dev.of_node)
+		i = of_alias_get_id(dev->dev.of_node, "serial");
+	if (i < 0) {
+		dev_err(&dev->dev, "failed to get alias/pdev id, errno %d\n", i);
+		return i;
+	}
+	up = &ma35d1serial_ports[i];

platform_get_drvdata(dev) ?

Quoted 17 lines
drivers/tty/serial/ma35d1_serial.c new file +17 -0
+	if (i == 0) {
+		up->console_baud_rate = serial_in(up, UART_REG_BAUD);
+		up->console_line = serial_in(up, UART_REG_LCR);
+		up->console_int = serial_in(up, UART_REG_IER);
+	}
+	return 0;
+}
+
+static int ma35d1serial_resume(struct platform_device *dev)
+{
+	int i;
+	struct uart_ma35d1_port *up;
+
+	if (dev->dev.of_node)
+		i = of_alias_get_id(dev->dev.of_node, "serial");
+	if (i < 0) {
+		dev_err(&dev->dev, "failed to get alias/pdev id, errno %d\n", i);

drivers/tty/serial/ma35d1_serial.c line 763

Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10 -0
+		return i;
+	}
+	up = &ma35d1serial_ports[i];
+	if (i == 0) {
+		serial_out(up, UART_REG_BAUD, up->console_baud_rate);
+		serial_out(up, UART_REG_LCR, up->console_line);
+		serial_out(up, UART_REG_IER, up->console_int);
+	}
+	return 0;
+}

No uart_suspend_port()/uart_resume_port()? You don't wait for transmitter to be empty in suspend. You don't stop tx etc.

Quoted 29 lines
drivers/tty/serial/ma35d1_serial.c new file +29 -0
+static struct platform_driver ma35d1serial_driver = {
+	.probe      = ma35d1serial_probe,
+	.remove     = ma35d1serial_remove,
+	.suspend    = ma35d1serial_suspend,
+	.resume     = ma35d1serial_resume,
+	.driver     = {
+		.name   = "ma35d1-uart",
+		.owner  = THIS_MODULE,
+		.of_match_table = of_match_ptr(ma35d1_serial_of_match),
+	},
+};
+
+static int __init ma35d1serial_init(void)
+{
+	int ret;
+
+	ret = uart_register_driver(&ma35d1serial_reg);
+	if (ret)
+		return ret;
+	ret = platform_driver_register(&ma35d1serial_driver);
+	if (ret)
+		uart_unregister_driver(&ma35d1serial_reg);
+	return ret;
+}
+
+static void __exit ma35d1serial_exit(void)
+{
+	platform_driver_unregister(&ma35d1serial_driver);
+	uart_unregister_driver(&ma35d1serial_reg);

drivers/tty/serial/ma35d1_serial.c line 801

Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +8 -0
+}
+
+module_init(ma35d1serial_init);
+module_exit(ma35d1serial_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("MA35D1 serial driver");
 
 
+MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);

Why is this needed? How are other platform drivers autoloaded?

thanks,

Signature · 2 lines
js
suse labs
#53 lore raw

Re: [PATCH v6 11/12] tty: serial: Add Nuvoton ma35d1 serial driver support

Dear Jiri,

Thanks for your advice.

Quoted 18 lines · Jiri Slaby
Quoted 4 lines · Jacky Huang
drivers/tty/serial/ma35d1_serial.c new file +4 -0
+static void transmit_chars(struct uart_ma35d1_port *up)
+{
+    struct circ_buf *xmit = &up->port.state->xmit;
+    int count;

drivers/tty/serial/ma35d1_serial.c line 197

Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10 -0
+    u8 ch;
+
+    if (uart_tx_stopped(&up->port)) {
+        ma35d1serial_stop_tx(&up->port);
+        return;
+    }
+    if (uart_circ_empty(xmit)) {
+        __stop_tx(up);
+        return;
+    }

Why is this necessary?

I will remove this reduntant uart_circ_empty() check.

Quoted 7 lines
Quoted 7 lines

+    count = UART_FIFO_DEPTH - ((serial_in(up, UART_REG_FSR) & FSR_TXPTR_MSK) >> 16);
+
+    uart_port_tx_limited(&up->port, ch, count,
+                 !(serial_in(up, UART_REG_FSR) & FSR_TX_FULL), +                 serial_out(up, UART_REG_THR, ch),
+                 ({}));

Quoted 8 lines

drivers/tty/serial/ma35d1_serial.c line 210

Quoted 6 lines
drivers/tty/serial/ma35d1_serial.c new file +6 -0
+
+    if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+        uart_write_wakeup(&up->port);
+
+    if (uart_circ_empty(xmit))
+        __stop_tx(up);

uart_port_tx_limited() should take care about the above and this too, right?

Yes, you are right. These two are also redundant. I will remove them. Thank you.

Quoted 10 lines
Quoted 2 lines

+}

...

drivers/tty/serial/ma35d1_serial.c line 235

Quoted 5 lines
drivers/tty/serial/ma35d1_serial.c new file +5 -0
+static void receive_chars(struct uart_ma35d1_port *up)
+{
+    u8 flag;
+    u32 fsr;
+    unsigned int ch;

Shouldn't ch be u8 too?

OK, I will fix it as u8.

Quoted 49 lines
Quoted 48 lines

+    int max_count = 256;

drivers/tty/serial/ma35d1_serial.c new file +7 -0
+
+    fsr = serial_in(up, UART_REG_FSR);
+    do {
+        flag = TTY_NORMAL;
+        up->port.icount.rx++;
+
+        if (unlikely(fsr & (FSR_BIF | FSR_FEF | FSR_PEF | 

FSR_RX_OVER_IF))) {
+            if (fsr & FSR_BIF) {
+                up->port.icount.brk++;
+                if (uart_handle_break(&up->port)) +                    continue;
+            }
+            if (fsr & FSR_FEF)
+                up->port.icount.frame++; +            if (fsr & FSR_PEF)
+                up->port.icount.parity++; +            if (fsr & FSR_RX_OVER_IF)
+                up->port.icount.overrun++;

drivers/tty/serial/ma35d1_serial.c new file +27 -0
+
+            serial_out(up, UART_REG_FSR, fsr &
+                   (FSR_BIF | FSR_FEF | FSR_PEF | FSR_RX_OVER_IF));
+
+            if (fsr & FSR_BIF)
+                flag = TTY_BREAK;
+            else if (fsr & FSR_PEF)
+                flag = TTY_PARITY;
+            else if (fsr & FSR_FEF)
+                flag = TTY_FRAME;
+        }
+
+        ch = serial_in(up, UART_REG_RBR);
+        if (uart_handle_sysrq_char(&up->port, ch))
+            continue;
+
+        spin_lock(&up->port.lock);
+        uart_insert_char(&up->port, fsr, FSR_RX_OVER_IF, ch, flag);
+        spin_unlock(&up->port.lock);
+
+        fsr = serial_in(up, UART_REG_FSR);
+    } while (!(fsr & FSR_RX_EMPTY) && (max_count-- > 0));
+
+    spin_lock(&up->port.lock);
+    tty_flip_buffer_push(&up->port.state->port);
+    spin_unlock(&up->port.lock);
+}

...

Quoted 7 lines

drivers/tty/serial/ma35d1_serial.c line 718

Quoted 5 lines
drivers/tty/serial/ma35d1_serial.c new file +5 -0
+static int ma35d1serial_remove(struct platform_device *dev)
+{
+    struct uart_port *port = platform_get_drvdata(dev);
+
+    if (port) {

Can this ever be NULL?

OK, I will remove this NULL check.

Quoted 15 lines
Quoted 15 lines

+ uart_remove_one_port(&ma35d1serial_reg, port);
+        free_irq(port->irq, port);
+    }
+    return 0;

drivers/tty/serial/ma35d1_serial.c new file +3 -0
+}
+
+static int ma35d1serial_suspend(struct platform_device *dev, 

pm_message_t state)

drivers/tty/serial/ma35d1_serial.c new file +6 -0
+{
+    int i;
+    struct uart_ma35d1_port *up;
+
+    if (dev->dev.of_node)
+        i = of_alias_get_id(dev->dev.of_node, "serial");
Quoted 8 lines
Quoted 6 lines

+    if (i < 0) {
+        dev_err(&dev->dev, "failed to get alias/pdev id, errno %d\n", i);
+        return i;
+    }
+    up = &ma35d1serial_ports[i];

platform_get_drvdata(dev) ?

We will fix it.

Quoted 23 lines
Quoted 23 lines

+    if (i == 0) {
+        up->console_baud_rate = serial_in(up, UART_REG_BAUD); +        up->console_line = serial_in(up, UART_REG_LCR); +        up->console_int = serial_in(up, UART_REG_IER); +    }
+    return 0;

drivers/tty/serial/ma35d1_serial.c new file +11 -0
+}
+
+static int ma35d1serial_resume(struct platform_device *dev)
+{
+    int i;
+    struct uart_ma35d1_port *up;
+
+    if (dev->dev.of_node)
+        i = of_alias_get_id(dev->dev.of_node, "serial");
+    if (i < 0) {
+        dev_err(&dev->dev, "failed to get alias/pdev id, errno 

%d\n", i);
+        return i;
+    }
+    up = &ma35d1serial_ports[i];
+    if (i == 0) {

Quoted 9 lines
Quoted 6 lines

+        serial_out(up, UART_REG_BAUD, up->console_baud_rate); +        serial_out(up, UART_REG_LCR, up->console_line); +        serial_out(up, UART_REG_IER, up->console_int); +    }
+    return 0;
+}

No uart_suspend_port()/uart_resume_port()? You don't wait for transmitter to be empty in suspend. You don't stop tx etc.

We will fix it in the next version.

Quoted 38 lines
Quoted 36 lines
drivers/tty/serial/ma35d1_serial.c new file +36 -0
+static struct platform_driver ma35d1serial_driver = {
+    .probe      = ma35d1serial_probe,
+    .remove     = ma35d1serial_remove,
+    .suspend    = ma35d1serial_suspend,
+    .resume     = ma35d1serial_resume,
+    .driver     = {
+        .name   = "ma35d1-uart",
+        .owner  = THIS_MODULE,
+        .of_match_table = of_match_ptr(ma35d1_serial_of_match),
+    },
+};
+
+static int __init ma35d1serial_init(void)
+{
+    int ret;
+
+    ret = uart_register_driver(&ma35d1serial_reg);
+    if (ret)
+        return ret;
+    ret = platform_driver_register(&ma35d1serial_driver);
+    if (ret)
+        uart_unregister_driver(&ma35d1serial_reg);
+    return ret;
+}
+
+static void __exit ma35d1serial_exit(void)
+{
+    platform_driver_unregister(&ma35d1serial_driver);
+    uart_unregister_driver(&ma35d1serial_reg);
+}
+
+module_init(ma35d1serial_init);
+module_exit(ma35d1serial_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("MA35D1 serial driver");
Quoted 5 lines
Quoted 1 line

+MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);

Why is this needed? How are other platform drivers autoloaded?

thanks,

Yes, it's not needed. I will remove it.

Best regards,
Jacky Huang

#54 lore raw

Re: [PATCH v6 11/12] tty: serial: Add Nuvoton ma35d1 serial driver support

In reply to Jacky Huang
Thank you for the patch! Perhaps something to improve:

Hi Jacky,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on robh/for-next]
[also build test WARNING on clk/clk-next linus/master] [cannot apply to pza/reset/next pza/imx-drm/next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jacky-Huang/arm64-Kconfig-platforms-Add-config-for-Nuvoton-MA35-platform/20230328-102245
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20230328021912.177301-12-ychuang570808%40gmail.com
patch subject: [PATCH v6 11/12] tty: serial: Add Nuvoton ma35d1 serial driver support
config: powerpc-allyesconfig (https://download.01.org/0day-ci/archive/20230331/[email protected]/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 67409911353323ca5edf2049ef0df54132fa1ca7)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc cross compiling tool for clang build
# apt-get install binutils-powerpc-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/380d83a62e873855024ca4c660865c654a62748a
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jacky-Huang/arm64-Kconfig-platforms-Add-config-for-Nuvoton-MA35-platform/20230328-102245 git checkout 380d83a62e873855024ca4c660865c654a62748a
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash drivers/tty/serial/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/tty/serial/ma35d1_serial.c:672:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
           if (pdev->dev.of_node) {
               ^~~~~~~~~~~~~~~~~
   drivers/tty/serial/ma35d1_serial.c:679:27: note: uninitialized use occurs here
           up = &ma35d1serial_ports[ret];
                                    ^~~
   drivers/tty/serial/ma35d1_serial.c:672:2: note: remove the 'if' if its condition is always true
           if (pdev->dev.of_node) {
           ^~~~~~~~~~~~~~~~~~~~~~~
   drivers/tty/serial/ma35d1_serial.c:668:9: note: initialize the variable 'ret' to silence this warning
           int ret;
                  ^
                   = 0
>> drivers/tty/serial/ma35d1_serial.c:730:6: warning: variable 'i' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
           if (dev->dev.of_node)
               ^~~~~~~~~~~~~~~~
   drivers/tty/serial/ma35d1_serial.c:732:6: note: uninitialized use occurs here
           if (i < 0) {
               ^
   drivers/tty/serial/ma35d1_serial.c:730:2: note: remove the 'if' if its condition is always true
           if (dev->dev.of_node)
           ^~~~~~~~~~~~~~~~~~~~~
   drivers/tty/serial/ma35d1_serial.c:727:7: note: initialize the variable 'i' to silence this warning
           int i;
                ^
                 = 0
   drivers/tty/serial/ma35d1_serial.c:750:6: warning: variable 'i' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
           if (dev->dev.of_node)
               ^~~~~~~~~~~~~~~~
   drivers/tty/serial/ma35d1_serial.c:752:6: note: uninitialized use occurs here
           if (i < 0) {
               ^
   drivers/tty/serial/ma35d1_serial.c:750:2: note: remove the 'if' if its condition is always true
           if (dev->dev.of_node)
           ^~~~~~~~~~~~~~~~~~~~~
   drivers/tty/serial/ma35d1_serial.c:747:7: note: initialize the variable 'i' to silence this warning
           int i;
                ^
                 = 0

3 warnings generated.

vim +672 drivers/tty/serial/ma35d1_serial.c

658
659 /*
660 * Register a set of serial devices attached to a platform device.
661 * The list is terminated with a zero flags entry, which means we expect
662 * all entries to have at least UPF_BOOT_AUTOCONF set.
663 */
664 static int ma35d1serial_probe(struct platform_device *pdev)
665 {
666 struct resource *res_mem;
667 struct uart_ma35d1_port *up;
668 int ret;
669 struct clk *clk;
670 int err;
671

 > 672		if (pdev->dev.of_node) {
   673			ret = of_alias_get_id(pdev->dev.of_node, "serial");
   674			if (ret < 0) {
   675				dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", ret);
   676				return ret;
   677			}
   678		}
   679		up = &ma35d1serial_ports[ret];
   680		up->port.line = ret;
   681		res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   682		if (!res_mem)
   683			return -ENODEV;
   684	
   685		up->port.iobase = res_mem->start;
   686		up->port.membase = ioremap(up->port.iobase, UART_REG_SIZE);
   687		up->port.ops = &ma35d1serial_ops;
   688	
   689		spin_lock_init(&up->port.lock);
   690	
   691		clk = of_clk_get(pdev->dev.of_node, 0);
   692		if (IS_ERR(clk)) {
   693			err = PTR_ERR(clk);
   694			dev_err(&pdev->dev, "failed to get core clk: %d\n", err);
   695			return -ENOENT;
   696		}
   697		err = clk_prepare_enable(clk);
   698		if (err)
   699			return -ENOENT;
   700	
   701		if (up->port.line != 0)
   702			up->port.uartclk = clk_get_rate(clk);
   703		up->port.irq = platform_get_irq(pdev, 0);
   704		up->port.dev = &pdev->dev;
   705		up->port.flags = UPF_BOOT_AUTOCONF;
   706		ret = uart_add_one_port(&ma35d1serial_reg, &up->port);
   707		platform_set_drvdata(pdev, up);
   708		return 0;
   709	}
   710	
   711	/*
   712	 * Remove serial ports registered against a platform device.
   713	 */
   714	static int ma35d1serial_remove(struct platform_device *dev)
   715	{
   716		struct uart_port *port = platform_get_drvdata(dev);
   717	
   718		if (port) {
   719			uart_remove_one_port(&ma35d1serial_reg, port);
   720			free_irq(port->irq, port);
   721		}
   722		return 0;
   723	}
   724	
   725	static int ma35d1serial_suspend(struct platform_device *dev, pm_message_t state)
   726	{
   727		int i;
   728		struct uart_ma35d1_port *up;
   729	
 > 730		if (dev->dev.of_node)

731 i = of_alias_get_id(dev->dev.of_node, "serial");
732 if (i < 0) {
733 dev_err(&dev->dev, "failed to get alias/pdev id, errno %d\n", i);
734 return i;
735 }
736 up = &ma35d1serial_ports[i];
737 if (i == 0) {
738 up->console_baud_rate = serial_in(up, UART_REG_BAUD);
739 up->console_line = serial_in(up, UART_REG_LCR);
740 up->console_int = serial_in(up, UART_REG_IER);
741 }
742 return 0;
743 }
744

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#55 lore raw

PATCH v6 12/12 MAINTAINERS: Add entry for NUVOTON MA35

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Add entry for Nuvton ma35d1 maintainer and files.

---
 MAINTAINERS | 9 +++++++++
 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
index 1dc8bd26b6cf..a3912717f1da 100644
@@ -2501,6 +2501,15 @@ F:	drivers/rtc/rtc-ab8500.c
 F:	drivers/rtc/rtc-pl031.c
 F:	drivers/soc/ux500/
 
+ARM/NUVOTON MA35 ARCHITECTURE
+M:	Jacky Huang <[email protected]>
+M:	Shan-Chun Hung <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+S:	Supported
+F:	Documentation/devicetree/bindings/*/*nuvoton*
+F:	arch/arm64/boot/dts/nuvoton/*ma35*
+K:	ma35d1
+
 ARM/NUVOTON NPCM ARCHITECTURE
 M:	Avi Fishman <[email protected]>
 M:	Tomer Maimon <[email protected]>
Signature · 1 line
2.34.1