Skip to contentSkip to conversation

Add Sunplus SP7021 SoC Support

PATCH Superseded Qin Jian 5 participants 27 messages May 12, 2022 – May 19, 2022 1 message not in the archive

Subsystems (7)

v15 of 20 Superseded Latest is v20 →

lore
Share & tools
lore

Qin Jian

author maintainer
#0 lore raw

v15 cover Add Sunplus SP7021 SoC Support

This patch series add Sunplus SP7021 SoC support.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

SP7021 consists of two chips (dies) in a package. One is called C-chip (computing chip). It is a 4-core ARM Cortex A7 CPU. It adopts high-level process (22 nm) for high performance computing. The other is called P- chip (peripheral chip). It has many peripherals and an ARM A926 added especially for real-time control. P-chip is made for customers. It adopts low-level process (ex: 0.11 um) to reduce cost.

Refer to (for documentations):
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview

Refer to (applications):
https://tibbo.com/store/plus1.html

Refer to (applications):
http://www.sinovoip.com.cn/ecp_view.asp?id=586

Changes in v15:
- Add Sunplus SP7021-demo-v3 board dts
- Refine yaml title
- Rename dt-binding header filename to match compatible string

Changes in v14:
- clock/sp-sp7021.h: Fix the comments from Krzysztof
- sunplus,sp7021-clkc.yaml: Fix the comments from Rob

Changes in v13:
- reset/sp-sp7021.h: Move HW mapping from dt-binding header to driver
- reset-sunplus.c: Move HW mapping from dt-binding header to driver
- clock/sp-sp7021.h: Move HW mapping from dt-binding header to driver
- clk-sp7021.c: Fix the comments from Arnd
- irq-sp7021-intc.c: Remove empty set_affinity callback function
- sp7021_defconfig: Fix the comments from Arnd

Changes in v12:
- sunplus,sp7021-clkc.yaml: Move 'reg' after 'compatible'
- sunplus,sp7021-intc.yaml: Move 'reg' after 'compatible'
- sunplus,reset.yaml: Move 'reg' after 'compatible'
- Remove wrong reviewed-tags

Changes in v11:
- clk-sp7021.c: Remove the dead code

Changes in v10:
- arm/sunplus,sp7021.yaml: Add SoC compatible: "sunplus,sp7021"
- clock/sunplus,sp7021-clkc.yaml: Remove the internal clock parent from DTS
- clk-sp7021.c: Refine the macro DBG_CLK
- clk-sp7021.c: Refine the clock_parent_data

Changes in v9:
- clk/Kconfig: fix the comments form Stephen Boyd
- clk-sp7021.c: fix the comments form Stephen Boyd

Changes in v8:
- clk-sp7021.c: fix the comments form Stephen Boyd

Changes in v7:
- sunplus,sp7021-clkc.yaml: Add clocks & clock-names
- clk-sp7021.c: fix the comments form Stephen Boyd
- irq-sp7021-intc.c: fix the comments from Marc

Changes in v6:
- reset-sunplus.c: fix the comments from Philipp
- irq-sp7021-intc.c: fix the comments from Marc
- mach-sunplus: fix the comments from Arnd

Changes in v5:
- reset-sunplus.c: fix strict checks
- clk/Kconfig: fix spell
- clk-sp7021.c: using bitfield ops, fix strict checks
- irqchip/Kconfig: fix spell
- irq-sp7021-intc.c: cleanup error path in probe, fix strict checks
- arm/Kconfig: fix spell & typo, remove CONFIG_SERIAL_SUNPLUS
- mach-sunplus/Kconfig: fix typo
- sp7021_defconfig: add CONFIG_SERIAL_SUNPLUS

Changes in v4:
- mach-sunplus: add initial support for SP7021
- sp7021_defconfig: add generic SP7021 defconfig
- reset-sunplus: remove Q645 support
- reset-sunplus.c: refine code based on Philipp's review
- clk-sp7021: clock defines add prefix, more clean up

Changes in v3:
- sp7021-intc: remove primary controller mode due to P-chip running Linux not supported any more.
- sp7021-intc.h: removed, not set ext through the DT but sp_intc_set_ext()
- sunplus,sp7021-intc.yaml: update descriptions for above changes
- irq-sp7021-intc.c: more cleanup based on Marc's review
- all driver's Kconfig removed default, it's selected by platform config

Changes in v2:
- sunplus,sp7021-intc.yaml: add descrption for "#interrupt-cells", interrupts
- sunplus,sp7021-intc.yaml: drop "ext0-mask"/"ext1-mask" from DT
- sunplus,sp7021-intc.yaml: fix example.dt too long error
- irq-sp7021-intc.c: major rewrite
- all files with dual license

Qin Jian (10):
dt-bindings: arm: sunplus: Add bindings for Sunplus SP7021 SoC boards
dt-bindings: reset: Add bindings for SP7021 reset driver
reset: Add Sunplus SP7021 reset driver
dt-bindings: clock: Add bindings for SP7021 clock driver
clk: Add Sunplus SP7021 clock driver
dt-bindings: interrupt-controller: Add bindings for SP7021 interrupt
controller
irqchip: Add Sunplus SP7021 interrupt controller driver
ARM: sunplus: Add initial support for Sunplus SP7021 SoC
ARM: sp7021_defconfig: Add Sunplus SP7021 defconfig
ARM: dts: Add Sunplus SP7021-Demo-V3 board device tree

 .../bindings/arm/sunplus,sp7021.yaml          |  29 +
 .../bindings/clock/sunplus,sp7021-clkc.yaml   |  51 ++
 .../sunplus,sp7021-intc.yaml                  |  62 ++
 .../bindings/reset/sunplus,reset.yaml         |  38 +
 MAINTAINERS                                   |  18 +
 arch/arm/Kconfig                              |   2 +
 arch/arm/Makefile                             |   1 +
 arch/arm/boot/dts/sunplus-sp7021-achip.dtsi   |  85 +++
 arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts  |  27 +
 arch/arm/boot/dts/sunplus-sp7021.dtsi         | 369 +++++++++
 arch/arm/configs/multi_v7_defconfig           |   1 +
 arch/arm/configs/sp7021_defconfig             |  59 ++
 arch/arm/mach-sunplus/Kconfig                 |  27 +
 arch/arm/mach-sunplus/Makefile                |   9 +
 arch/arm/mach-sunplus/sp7021.c                |  16 +
 drivers/clk/Kconfig                           |  10 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/clk-sp7021.c                      | 721 ++++++++++++++++++
 drivers/irqchip/Kconfig                       |   9 +
 drivers/irqchip/Makefile                      |   2 +
 drivers/irqchip/irq-sp7021-intc.c             | 278 +++++++
 drivers/reset/Kconfig                         |   9 +
 drivers/reset/Makefile                        |   1 +
 drivers/reset/reset-sunplus.c                 | 212 +++++
 .../dt-bindings/clock/sunplus,sp7021-clkc.h   |  88 +++
 .../dt-bindings/reset/sunplus,sp7021-reset.h  |  87 +++
 26 files changed, 2212 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
 create mode 100644 Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/sunplus,sp7021-intc.yaml
 create mode 100644 Documentation/devicetree/bindings/reset/sunplus,reset.yaml
 create mode 100644 arch/arm/boot/dts/sunplus-sp7021-achip.dtsi
 create mode 100644 arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts
 create mode 100644 arch/arm/boot/dts/sunplus-sp7021.dtsi
 create mode 100644 arch/arm/configs/sp7021_defconfig
 create mode 100644 arch/arm/mach-sunplus/Kconfig
 create mode 100644 arch/arm/mach-sunplus/Makefile
 create mode 100644 arch/arm/mach-sunplus/sp7021.c
 create mode 100644 drivers/clk/clk-sp7021.c
 create mode 100644 drivers/irqchip/irq-sp7021-intc.c
 create mode 100644 drivers/reset/reset-sunplus.c
 create mode 100644 include/dt-bindings/clock/sunplus,sp7021-clkc.h
 create mode 100644 include/dt-bindings/reset/sunplus,sp7021-reset.h
Signature · 1 line
2.33.1
author maintainer
#1 lore raw

PATCH v15 1/10 dt-bindings: arm: sunplus: Add bindings for Sunplus SP7021 SoC boards

This introduces bindings for boards based Sunplus SP7021 SoC.

---
Remove "Device Tree Bindings" from title
Add board compatible "sunplus,sp7021-demo-v3"

---
 .../bindings/arm/sunplus,sp7021.yaml          | 29 +++++++++++++++++++
 MAINTAINERS                                   |  7 +++++
 2 files changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml new file +29 -0
new file mode 100644
index 000000000..def7d0cfe
@@ -0,0 +1,29 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/sunplus,sp7021.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus SP7021 Boards
+
+maintainers:
+  - qinjian <[email protected]>
+
+description: |
+  ARM platforms using Sunplus SP7021, an ARM Cortex A7 (4-cores) based SoC.
+  Wiki: https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
+
+properties:
+  $nodename:
+    const: '/'
+  compatible:
+    items:
+      - enum:
+          - sunplus,sp7021-achip
+          - sunplus,sp7021-demo-v3
+      - const: sunplus,sp7021
+
+additionalProperties: true
+
+...
MAINTAINERS +7 -0
index cd0f68d4a..8b5e2e639 100644
@@ -2738,6 +2738,13 @@ F:	drivers/clocksource/armv7m_systick.c
 N:	stm32
 N:	stm
 
+ARM/SUNPLUS SP7021 SOC SUPPORT
+M:	Qin Jian <[email protected]>
+L:	[email protected] (moderated for mon-subscribers)
+S:	Maintained
+W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
+F:	Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
+
 ARM/Synaptics SoC support
 M:	Jisheng Zhang <[email protected]>
 M:	Sebastian Hesselbarth <[email protected]>
Signature · 1 line
2.33.1
maintainer Acked-by on v15 1/10
#2 lore raw

Re: [PATCH v15 01/10] dt-bindings: arm: sunplus: Add bindings for Sunplus SP7021 SoC boards

Quoted 4 lines · Qin Jian

This introduces bindings for boards based Sunplus SP7021 SoC.

Quoted 9 lines

---
Remove "Device Tree Bindings" from title
Add board compatible "sunplus,sp7021-demo-v3"

---
 .../bindings/arm/sunplus,sp7021.yaml          | 29 +++++++++++++++++++
 MAINTAINERS                                   |  7 +++++
 2 files changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
author maintainer
#3 lore raw

PATCH v15 2/10 dt-bindings: reset: Add bindings for SP7021 reset driver

In reply to Qin Jian

Add documentation to describe Sunplus SP7021 reset driver bindings.

---
Rename sp-sp7021.h to sunplus,sp7021-reset.h

---
 .../bindings/reset/sunplus,reset.yaml         | 38 ++++++++
 MAINTAINERS                                   |  2 +
 .../dt-bindings/reset/sunplus,sp7021-reset.h  | 87 +++++++++++++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reset/sunplus,reset.yaml
 create mode 100644 include/dt-bindings/reset/sunplus,sp7021-reset.h
Documentation/devicetree/bindings/reset/sunplus,reset.yaml new file +38 -0
new file mode 100644
index 000000000..f24646ba9
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/reset/sunplus,reset.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: Sunplus SoC Reset Controller
+
+maintainers:
+  - Qin Jian <[email protected]>
+
+properties:
+  compatible:
+    const: sunplus,sp7021-reset
+
+  reg:
+    maxItems: 1
+
+  "#reset-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - "#reset-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    rstc: reset@9c000054 {
+      compatible = "sunplus,sp7021-reset";
+      reg = <0x9c000054 0x28>;
+      #reset-cells = <1>;
+    };
+
+...
MAINTAINERS +2 -0
index 8b5e2e639..07bacd09f 100644
@@ -2744,6 +2744,8 @@ L:	[email protected] (moderated for mon-subscribers)
 S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
 F:	Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
+F:	Documentation/devicetree/bindings/reset/sunplus,reset.yaml
+F:	include/dt-bindings/reset/sunplus,sp7021-reset.h
 
 ARM/Synaptics SoC support
 M:	Jisheng Zhang <[email protected]>
include/dt-bindings/reset/sunplus,sp7021-reset.h new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.33.1
author maintainer
#4 lore raw

PATCH v15 3/10 reset: Add Sunplus SP7021 reset driver

In reply to Qin Jian

Add reset driver for Sunplus SP7021 SoC.

---
 MAINTAINERS                   |   1 +
 drivers/reset/Kconfig         |   9 ++
 drivers/reset/Makefile        |   1 +
 drivers/reset/reset-sunplus.c | 212 ++++++++++++++++++++++++++++++++++
 4 files changed, 223 insertions(+)
 create mode 100644 drivers/reset/reset-sunplus.c
MAINTAINERS +1 -0
index 07bacd09f..4988db270 100644
@@ -2745,6 +2745,7 @@ S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
 F:	Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
 F:	Documentation/devicetree/bindings/reset/sunplus,reset.yaml
+F:	drivers/reset/reset-sunplus.c
 F:	include/dt-bindings/reset/sunplus,sp7021-reset.h
 
 ARM/Synaptics SoC support
drivers/reset/Kconfig +9 -0
index 6f8ba0ddc..36825787e 100644
@@ -231,6 +231,15 @@ config RESET_STARFIVE_JH7100
 	help
 	  This enables the reset controller driver for the StarFive JH7100 SoC.
 
+config RESET_SUNPLUS
+	bool "Sunplus SoCs Reset Driver" if COMPILE_TEST
+	default ARCH_SUNPLUS
+	help
+	  This enables the reset driver support for Sunplus SoCs.
+	  The reset lines that can be asserted and deasserted by toggling bits
+	  in a contiguous, exclusive register space. The register is HIWORD_MASKED,
+	  which means each register hold 16 reset lines.
+
 config RESET_SUNXI
 	bool "Allwinner SoCs Reset Driver" if COMPILE_TEST && !ARCH_SUNXI
 	default ARCH_SUNXI
drivers/reset/Makefile +1 -0
index bd0a97be1..cadc46d3e 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_RESET_SCMI) += reset-scmi.o
 obj-$(CONFIG_RESET_SIMPLE) += reset-simple.o
 obj-$(CONFIG_RESET_SOCFPGA) += reset-socfpga.o
 obj-$(CONFIG_RESET_STARFIVE_JH7100) += reset-starfive-jh7100.o
+obj-$(CONFIG_RESET_SUNPLUS) += reset-sunplus.o
 obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o
 obj-$(CONFIG_RESET_TI_SCI) += reset-ti-sci.o
 obj-$(CONFIG_RESET_TI_SYSCON) += reset-ti-syscon.o
drivers/reset/reset-sunplus.c new file +212 -0

212 lines not on this page · raw message

Signature · 1 line
2.33.1
author maintainer
#5 lore raw

PATCH v15 4/10 dt-bindings: clock: Add bindings for SP7021 clock driver

In reply to Qin Jian

Add documentation to describe Sunplus SP7021 clock driver bindings.

---
Remove "Binding" from yaml title
Rename sp-sp7021.h to sunplus,sp7021-clkc.h

---
 .../bindings/clock/sunplus,sp7021-clkc.yaml   | 51 +++++++++++
 MAINTAINERS                                   |  2 +
 .../dt-bindings/clock/sunplus,sp7021-clkc.h   | 88 +++++++++++++++++++
 3 files changed, 141 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
 create mode 100644 include/dt-bindings/clock/sunplus,sp7021-clkc.h
Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml new file +51 -0
new file mode 100644
index 000000000..119961a17
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/sunplus,sp7021-clkc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus SP7021 SoC Clock Controller
+
+maintainers:
+  - Qin Jian <[email protected]>
+
+properties:
+  compatible:
+    const: sunplus,sp7021-clkc
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  "#clock-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - "#clock-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+
+    extclk: osc0 {
+      compatible = "fixed-clock";
+      #clock-cells = <0>;
+      clock-frequency = <27000000>;
+      clock-output-names = "extclk";
+    };
+
+    clkc: clock-controller@9c000000 {
+      compatible = "sunplus,sp7021-clkc";
+      reg = <0x9c000000 0x280>;
+      clocks = <&extclk>;
+      #clock-cells = <1>;
+    };
+
+...
MAINTAINERS +2 -0
index 4988db270..cd1b2ffc4 100644
@@ -2744,8 +2744,10 @@ L:	[email protected] (moderated for mon-subscribers)
 S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
 F:	Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
+F:	Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
 F:	Documentation/devicetree/bindings/reset/sunplus,reset.yaml
 F:	drivers/reset/reset-sunplus.c
+F:	include/dt-bindings/clock/sunplus,sp7021-clkc.h
 F:	include/dt-bindings/reset/sunplus,sp7021-reset.h
 
 ARM/Synaptics SoC support
include/dt-bindings/clock/sunplus,sp7021-clkc.h new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
2.33.1
#6 lore raw

Re: [PATCH v15 04/10] dt-bindings: clock: Add bindings for SP7021 clock driver

Quoted 6 lines · Qin Jian

Add documentation to describe Sunplus SP7021 clock driver bindings.

---
Remove "Binding" from yaml title
Rename sp-sp7021.h to sunplus,sp7021-clkc.h

Thanks.

Quoted 40 lines
---
 .../bindings/clock/sunplus,sp7021-clkc.yaml   | 51 +++++++++++
 MAINTAINERS                                   |  2 +
 .../dt-bindings/clock/sunplus,sp7021-clkc.h   | 88 +++++++++++++++++++
 3 files changed, 141 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
 create mode 100644 include/dt-bindings/clock/sunplus,sp7021-clkc.h
Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml new file +26 -0
new file mode 100644
index 000000000..119961a17
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/sunplus,sp7021-clkc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus SP7021 SoC Clock Controller
+
+maintainers:
+  - Qin Jian <[email protected]>
+
+properties:
+  compatible:
+    const: sunplus,sp7021-clkc
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  "#clock-cells":
+    const: 1
+
+required:

Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml line 36

Quoted 10 lines
Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml new file +10 -0
+  - compatible
+  - reg
+  - clocks
+  - "#clock-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+

Same as in v14. Please go through the comments thoroughly so reviewers will not waste time repeating the same twice.

Best regards,
Krzysztof

author maintainer
#7 lore raw

RE: [PATCH v15 04/10] dt-bindings: clock: Add bindings for SP7021 clock driver

Quoted 56 lines · Qin Jian
Quoted 6 lines

Add documentation to describe Sunplus SP7021 clock driver bindings.

---
Remove "Binding" from yaml title
Rename sp-sp7021.h to sunplus,sp7021-clkc.h

Thanks.

Review

Quoted 9 lines
---
 .../bindings/clock/sunplus,sp7021-clkc.yaml   | 51 +++++++++++
 MAINTAINERS                                   |  2 +
 .../dt-bindings/clock/sunplus,sp7021-clkc.h   | 88 +++++++++++++++++++
 3 files changed, 141 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
 create mode 100644 include/dt-bindings/clock/sunplus,sp7021-clkc.h
(quoted diff) +0 -0

b/Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml

Quoted 36 lines

new file mode 100644
index 000000000..119961a17

Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml new file +31 -0
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/sunplus,sp7021-clkc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus SP7021 SoC Clock Controller
+
+maintainers:
+  - Qin Jian <[email protected]>
+
+properties:
+  compatible:
+    const: sunplus,sp7021-clkc
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  "#clock-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - "#clock-cells"
+
Quoted 9 lines

Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml line 36

Quoted 5 lines
Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml new file +5 -0
+additionalProperties: false
+
+examples:
+  - |
+

Same as in v14. Please go through the comments thoroughly so reviewers will not waste time repeating the same twice.

Sorry, I don’t understand your meaning.
Could you explain more, thanks.

#8 lore raw

Re: [PATCH v15 04/10] dt-bindings: clock: Add bindings for SP7021 clock driver

Quoted 11 lines · qinjian[覃健]
Quoted 8 lines

Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml line 36

Quoted 4 lines
Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml new file +4 -0
+
+examples:
+  - |
+

Same as in v14. Please go through the comments thoroughly so reviewers will not waste time repeating the same twice.

Sorry, I don’t understand your meaning.
Could you explain more, thanks.

I commented in your v14. Please apply the comment or keep discussion running. Don't ignore my comment.

Best regards,
Krzysztof

author maintainer
#9 lore raw

RE: [PATCH v15 04/10] dt-bindings: clock: Add bindings for SP7021 clock driver

Quoted 10 lines · qinjian[覃健]
Quoted 9 lines
Quoted 8 lines

Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml line 36

Quoted 4 lines
Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml new file +4 -0
+
+examples:
+  - |
+

Same as in v14. Please go through the comments thoroughly so reviewers will not waste time repeating the same twice.

Quoted 6 lines
Quoted 2 lines

Sorry, I don’t understand your meaning.
Could you explain more, thanks.

I commented in your v14. Please apply the comment or keep discussion running. Don't ignore my comment.

Sorry, I missed your comment: "No need for blank line". I'll fix it later.

maintainer
#10 lore raw

Re: [PATCH v15 04/10] dt-bindings: clock: Add bindings for SP7021 clock driver

In reply to Qin Jian

Quoting Qin Jian (2022-05-11 23:30:59)

Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml line 46

Quoted 11 lines
Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml new file +11 -0
+
+    extclk: osc0 {
+      compatible = "fixed-clock";
+      #clock-cells = <0>;
+      clock-frequency = <27000000>;
+      clock-output-names = "extclk";
+    };
+
+    clkc: clock-controller@9c000000 {
+      compatible = "sunplus,sp7021-clkc";
+      reg = <0x9c000000 0x280>;

The question is what other device compatible is in here? The reset controller?

Quoted 4 lines
Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml new file +4 -0
+      clocks = <&extclk>;
+      #clock-cells = <1>;
+    };
+
author maintainer
#11 lore raw

RE: [PATCH v15 04/10] dt-bindings: clock: Add bindings for SP7021 clock driver

Quoted 7 lines

Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml line 46

Quoted 3 lines
Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml new file +3 -0
+    clkc: clock-controller@9c000000 {
+      compatible = "sunplus,sp7021-clkc";
+      reg = <0x9c000000 0x280>;

The question is what other device compatible is in here? The reset controller?

This reg region conflict with reset/pinmux/usbc/uphy drivers. To use devm_platform_ioremap_resource,
I must split up the origin 1 region into 4 small pieces, and call devm_platform_ioremap_resource() 4 times. Did I should follow this way?

author maintainer
#12 lore raw

PATCH v15 5/10 clk: Add Sunplus SP7021 clock driver

In reply to Qin Jian

Add clock driver for Sunplus SP7021 SoC.

---
Rename sp-sp7021.h to sunplus,sp7021-clkc.h

---
 MAINTAINERS              |   1 +
 drivers/clk/Kconfig      |  10 +
 drivers/clk/Makefile     |   1 +
 drivers/clk/clk-sp7021.c | 721 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 733 insertions(+)
 create mode 100644 drivers/clk/clk-sp7021.c
MAINTAINERS +1 -0
index cd1b2ffc4..26b77b68b 100644
@@ -2746,6 +2746,7 @@ W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
 F:	Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
 F:	Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
 F:	Documentation/devicetree/bindings/reset/sunplus,reset.yaml
+F:	drivers/clk/clk-sp7021.c
 F:	drivers/reset/reset-sunplus.c
 F:	include/dt-bindings/clock/sunplus,sp7021-clkc.h
 F:	include/dt-bindings/reset/sunplus,sp7021-reset.h
drivers/clk/Kconfig +10 -0
index d4d67fbae..9eedeea78 100644
@@ -351,6 +351,16 @@ config COMMON_CLK_VC5
 	  This driver supports the IDT VersaClock 5 and VersaClock 6
 	  programmable clock generators.
 
+config COMMON_CLK_SP7021
+	bool "Clock driver for Sunplus SP7021 SoC"
+	depends on SOC_SP7021 || COMPILE_TEST
+	default SOC_SP7021
+	help
+	  This driver supports the Sunplus SP7021 SoC clocks.
+	  It implements SP7021 PLLs/gate.
+	  Not all features of the PLL are currently supported
+	  by the driver.
+
 config COMMON_CLK_STM32MP157
 	def_bool COMMON_CLK && MACH_STM32MP157
 	help
drivers/clk/Makefile +1 -0
index 16e588630..377ea7f7b 100644
@@ -61,6 +61,7 @@ obj-$(CONFIG_COMMON_CLK_SI5351)		+= clk-si5351.o
 obj-$(CONFIG_COMMON_CLK_SI514)		+= clk-si514.o
 obj-$(CONFIG_COMMON_CLK_SI544)		+= clk-si544.o
 obj-$(CONFIG_COMMON_CLK_SI570)		+= clk-si570.o
+obj-$(CONFIG_COMMON_CLK_SP7021)		+= clk-sp7021.o
 obj-$(CONFIG_COMMON_CLK_STM32F)		+= clk-stm32f4.o
 obj-$(CONFIG_COMMON_CLK_STM32H7)	+= clk-stm32h7.o
 obj-$(CONFIG_COMMON_CLK_STM32MP157)	+= clk-stm32mp1.o
drivers/clk/clk-sp7021.c new file +721 -0

721 lines not on this page · raw message

Signature · 1 line
2.33.1
maintainer
#13 lore raw

Re: [PATCH v15 05/10] clk: Add Sunplus SP7021 clock driver

Quoting Qin Jian (2022-05-11 23:31:00)

Quoted 69 lines
drivers/clk/clk-sp7021.c new file +63 -0
new file mode 100644
index 000000000..7d71bc276
@@ -0,0 +1,721 @@
+// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+/*
+ * Copyright (C) Sunplus Technology Co., Ltd.
+ *       All rights reserved.
+ */
+#include <linux/module.h>
+#include <linux/clk-provider.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/bitfield.h>
+#include <linux/slab.h>
+#include <linux/io.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <dt-bindings/clock/sunplus,sp7021-clkc.h>
+
+#define REG(i)         (pll_regs + (i) * 4)
+
+#define PLLA_CTL       REG(7)
+#define PLLE_CTL       REG(12)
+#define PLLF_CTL       REG(13)
+#define PLLTV_CTL      REG(14)
+#define PLLSYS_CTL     REG(26)
+
+/* speical div_width values for PLLTV/PLLA */
+#define DIV_TV         33
+#define DIV_A          34
+
+/* PLLTV parameters */
+enum {
+       SEL_FRA,
+       SDM_MOD,
+       PH_SEL,
+       NFRA,
+       DIVR,
+       DIVN,
+       DIVM,
+       P_MAX
+};
+
+#define MASK_SEL_FRA   GENMASK(1, 1)
+#define MASK_SDM_MOD   GENMASK(2, 2)
+#define MASK_PH_SEL    GENMASK(4, 4)
+#define MASK_NFRA      GENMASK(12, 6)
+#define MASK_DIVR      GENMASK(8, 7)
+#define MASK_DIVN      GENMASK(7, 0)
+#define MASK_DIVM      GENMASK(14, 8)
+
+/* HIWORD_MASK FIELD_PREP */
+#define HWM_FIELD_PREP(mask, value)            \
+({                                             \
+       u32 m = mask;                           \
+       (m << 16) | FIELD_PREP(m, value);       \
+})
+
+struct sp_pll {
+       struct clk_hw hw;
+       void __iomem *reg;
+       spinlock_t *lock;       /* lock for reg */
+       int div_shift;
+       int div_width;
+       int pd_bit;             /* power down bit idx */
+       int bp_bit;             /* bypass bit idx */

drivers/clk/clk-sp7021.c line 73

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+       unsigned long brate;    /* base rate, TODO: replace brate with muldiv */
+       u32 p[P_MAX];           /* for hold PLLTV/PLLA parameters */
+};
+
+#define to_sp_pll(_hw) container_of(_hw, struct sp_pll, hw)
+
+#define clk_regs       (sp_clk_base + 0x000) /* G0 ~ CLKEN */
+#define pll_regs       (sp_clk_base + 0x200) /* G4 ~ PLL */
+static void __iomem *sp_clk_base;
+static struct clk_hw_onecell_data *sp_clk_data;

Why are these globals? Please allocate them locally in driver probe and reference them without using a global.

drivers/clk/clk-sp7021.c line 78

Quoted 5 lines
drivers/clk/clk-sp7021.c new file +5 -0
+
+#define F_EXTCLK       BIT(16) /* parent clock is EXTCLK */
+
+/* gates HW info: reg_index_shift | parent */
+static const u32 sp_clk_gates[] = {

Please make a struct sp_clk_gate_info

	struct sp_clk_gate_info {
		u16	reg;
		bool	ext_parent;
	};

Or 'ext_parent' can be u16 if struct packing with a bool on the end fails due to alignment issues.

Quoted 57 lines
drivers/clk/clk-sp7021.c new file +57 -0
+       0x12,
+       0x15,
+       0x16,
+       0x17,
+       0x19,
+       0x1b | F_EXTCLK,
+       0x1f | F_EXTCLK,
+       0x24,
+       0x25,
+       0x26,
+       0x27,
+       0x28 | F_EXTCLK,
+       0x29 | F_EXTCLK,
+       0x2a | F_EXTCLK,
+       0x2b | F_EXTCLK,
+       0x2c | F_EXTCLK,
+       0x2d | F_EXTCLK,
+       0x2e,
+       0x2f | F_EXTCLK,
+       0x30,
+       0x31,
+       0x32,
+       0x33,
+       0x34,
+       0x35,
+       0x36,
+       0x3a,
+       0x3b,
+       0x3d,
+       0x3e,
+       0x40,
+       0x41,
+       0x42,
+       0x43,
+       0x4d,
+       0x4e,
+       0x4f,
+       0x52,
+       0x54,
+       0x5b,
+       0x5c,
+       0x5d,
+       0x5e,
+       0x5f,
+       0x60,
+       0x65,
+       0x70,
+       0x71,
+       0x7a,
+       0x83,
+       0x96,
+       0x9a,
+       0x9b,
+       0x9d,
+       0x9e,
+       0x9f,
+       0xa0,

drivers/clk/clk-sp7021.c line 145

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+       0xa2,
+       0xa3,
+       0xa5,
+       0xa6,
+       0xa7,
+       0xa8,
+       0xa9,
+};
+
+static DEFINE_SPINLOCK(plla_lock);

The name of the spinlock will be inserted directly into any lockdep report. Can these locks be part of some allocated structure instead of being static globals? Then the struct name will be encoded during spin_lock_init() which will be more helpful assuming the struct name is driver specific.

Quoted 27 lines
drivers/clk/clk-sp7021.c new file +27 -0
+static DEFINE_SPINLOCK(plle_lock);
+static DEFINE_SPINLOCK(pllf_lock);
+static DEFINE_SPINLOCK(pllsys_lock);
+static DEFINE_SPINLOCK(plltv_lock);
+
+#define _M             1000000UL
+#define F_27M          (27 * _M)
+
+/*********************************** PLL_TV **********************************/
+
+/* TODO: set proper FVCO range */
+#define FVCO_MIN       (100 * _M)
+#define FVCO_MAX       (200 * _M)
+
+#define F_MIN          (FVCO_MIN / 8)
+#define F_MAX          (FVCO_MAX)
+
+static long plltv_integer_div(struct sp_pll *clk, unsigned long freq)
+{
+       /* valid m values: 27M must be divisible by m, 0 means end */
+       static const u32 m_table[] = {
+               1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 0
+       };
+       u32 m, n, r;
+       unsigned long fvco, nf;
+
+       freq = clamp(freq, F_MIN, F_MAX);

drivers/clk/clk-sp7021.c line 182

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+
+       /* DIVR 0~3 */
+       for (r = 0; r <= 3; r++) {
+               fvco = freq << r;
+               if (fvco <= FVCO_MAX)
+                       break;
+       }
+
+       /* DIVM */
+       for (m = 0; m_table[m]; m++) {

Use ARRAY_SIZE and remove the comment about and value of 0 from the end?

drivers/clk/clk-sp7021.c line 190

Quoted 8 lines
drivers/clk/clk-sp7021.c new file +8 -0
+               nf = fvco * m_table[m];
+               n = nf / F_27M;
+               if ((n * F_27M) == nf)
+                       break;
+       }
+       m = m_table[m];
+
+       if (!m) {

This can be resolved with a 'return' from a subfunction or a goto.

Quoted 9 lines
drivers/clk/clk-sp7021.c new file +9 -0
+               pr_err("%s: %s freq:%lu not found a valid setting\n",
+                      __func__, clk_hw_get_name(&clk->hw), freq);
+               return -EINVAL;
+       }
+
+       /* save parameters */
+       clk->p[SEL_FRA] = 0;
+       clk->p[DIVR]    = r;
+       clk->p[DIVN]    = n;

drivers/clk/clk-sp7021.c line 209

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+       clk->p[DIVM]    = m;
+
+       return freq;
+}
+
+/* parameters for PLLTV fractional divider */
+static const u32 pt[][5] = {
+       /* conventional fractional */
+       {
+               1,                      // factor

Don't use // for comments.

Quoted 6 lines
drivers/clk/clk-sp7021.c new file +6 -0
+               5,                      // 5 * p0 (nint)
+               1,                      // 1 * p0
+               F_27M,                  // F_27M / p0
+               1,                      // p0 / p2
+       },
+       /* phase rotation */

drivers/clk/clk-sp7021.c line 225

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+       {
+               10,                     // factor
+               54,                     // 5.4 * p0 (nint)
+               2,                      // 0.2 * p0
+               F_27M / 10,             // F_27M / p0
+               5,                      // p0 / p2
+       },
+};
+
+static const u32 mods[] = { 91, 55 }; /* SDM_MOD mod values */

Maybe call it sdm_mod_vals[] and drop the comment?

Quoted 14 lines
drivers/clk/clk-sp7021.c new file +14 -0
+
+static long plltv_fractional_div(struct sp_pll *clk, unsigned long freq)
+{
+       u32 m, r;
+       u32 nint, nfra;
+       u32 df_quotient_min = 210000000;
+       u32 df_remainder_min = 0;
+       unsigned long fvco, nf, f, fout = 0;
+       int sdm, ph;
+
+       freq = clamp(freq, F_MIN, F_MAX);
+
+       /* DIVR 0~3 */
+       for (r = 0; r <= 3; r++) {

drivers/clk/clk-sp7021.c line 249

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+               fvco = freq << r;
+               if (fvco <= FVCO_MAX)
+                       break;
+       }
+       f = F_27M >> r;
+
+       /* PH_SEL 1/0 */
+       for (ph = 1; ph >= 0; ph--) {
+               const u32 *pp = pt[ph];
+               u32 ms = 1;

this is 1

drivers/clk/clk-sp7021.c line 256

Quoted 7 lines
drivers/clk/clk-sp7021.c new file +7 -0
+
+               /* SDM_MOD 0/1 */
+               for (sdm = 0; sdm <= 1; sdm++) {
+                       u32 mod = mods[sdm];
+
+                       /* DIVM 1~32 */
+                       for (m = ms; m <= 32; m++) {

and still 1? Just use 1 instead of another local variable?

Quoted 5 lines
drivers/clk/clk-sp7021.c new file +5 -0
+                               u32 df; /* diff freq */
+                               u32 df_quotient, df_remainder;
+
+                               nf = fvco * m;
+                               nint = nf / pp[3];

drivers/clk/clk-sp7021.c line 271

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+
+                               if (nint < pp[1])
+                                       continue;
+                               if (nint > pp[1])
+                                       break;
+
+                               nfra = (((nf % pp[3]) * mod * pp[4]) + (F_27M / 2)) / F_27M;
+                               if (nfra)
+                                       df = (f * (nint + pp[2]) / pp[0]) -
+                                            (f * (mod - nfra) / mod / pp[4]);

This is quite long and I am concerned about overflow. Can we have more local variables to help break up the statement?

drivers/clk/clk-sp7021.c line 273

Quoted 2 lines
drivers/clk/clk-sp7021.c new file +2 -0
+                               else
+                                       df = (f * (nint) / pp[0]);

Drop useless parenthesis please.

drivers/clk/clk-sp7021.c line 280

Quoted 7 lines
drivers/clk/clk-sp7021.c new file +7 -0
+
+                               df_quotient  = df / m;
+                               df_remainder = ((df % m) * 1000) / m;
+
+                               if (freq > df_quotient) {
+                                       df_quotient  = freq - df_quotient - 1;
+                                       df_remainder = 1000 - df_remainder;

Where does 1000 come from?

Quoted 163 lines
drivers/clk/clk-sp7021.c new file +163 -0
+                               } else {
+                                       df_quotient = df_quotient - freq;
+                               }
+
+                               if (df_quotient_min > df_quotient ||
+                                   (df_quotient_min == df_quotient &&
+                                   df_remainder_min > df_remainder)) {
+                                       /* found a closer freq, save parameters */
+                                       clk->p[SEL_FRA] = 1;
+                                       clk->p[SDM_MOD] = sdm;
+                                       clk->p[PH_SEL]  = ph;
+                                       clk->p[NFRA]    = nfra;
+                                       clk->p[DIVR]    = r;
+                                       clk->p[DIVM]    = m;
+
+                                       fout = df / m;
+                                       df_quotient_min = df_quotient;
+                                       df_remainder_min = df_remainder;
+                               }
+                       }
+               }
+       }
+
+       if (!fout) {
+               pr_err("%s: %s freq:%lu not found a valid setting\n",
+                      __func__, clk_hw_get_name(&clk->hw), freq);
+               return -EINVAL;
+       }
+
+       return fout;
+}
+
+static long plltv_div(struct sp_pll *clk, unsigned long freq)
+{
+       if (freq % 100)
+               return plltv_fractional_div(clk, freq);
+
+       return plltv_integer_div(clk, freq);
+}
+
+static void plltv_set_rate(struct sp_pll *clk)
+{
+       u32 reg;
+
+       reg  = HWM_FIELD_PREP(MASK_SEL_FRA, clk->p[SEL_FRA]);
+       reg |= HWM_FIELD_PREP(MASK_SDM_MOD, clk->p[SDM_MOD]);
+       reg |= HWM_FIELD_PREP(MASK_PH_SEL, clk->p[PH_SEL]);
+       reg |= HWM_FIELD_PREP(MASK_NFRA, clk->p[NFRA]);
+       writel(reg, clk->reg);
+
+       reg  = HWM_FIELD_PREP(MASK_DIVR, clk->p[DIVR]);
+       writel(reg, clk->reg + 4);
+
+       reg  = HWM_FIELD_PREP(MASK_DIVN, clk->p[DIVN] - 1);
+       reg |= HWM_FIELD_PREP(MASK_DIVM, clk->p[DIVM] - 1);
+       writel(reg, clk->reg + 8);
+}
+
+/*********************************** PLL_A ***********************************/
+
+/* from Q628_PLLs_REG_setting.xlsx */
+static const struct {
+       u32 rate;
+       u32 regs[5];
+} pa[] = {
+       {
+               .rate = 135475200,
+               .regs = {
+                       0x4801,
+                       0x02df,
+                       0x248f,
+                       0x0211,
+                       0x33e9
+               }
+       },
+       {
+               .rate = 147456000,
+               .regs = {
+                       0x4801,
+                       0x1adf,
+                       0x2490,
+                       0x0349,
+                       0x33e9
+               }
+       },
+       {
+               .rate = 196608000,
+               .regs = {
+                       0x4801,
+                       0x42ef,
+                       0x2495,
+                       0x01c6,
+                       0x33e9
+               }
+       },
+};
+
+static void plla_set_rate(struct sp_pll *clk)
+{
+       const u32 *pp = pa[clk->p[0]].regs;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(pa->regs); i++)
+               writel(0xffff0000 | pp[i], clk->reg + (i * 4));
+}
+
+static long plla_round_rate(struct sp_pll *clk, unsigned long rate)
+{
+       int i = ARRAY_SIZE(pa);
+
+       while (--i) {
+               if (rate >= pa[i].rate)
+                       break;
+       }
+       clk->p[0] = i;
+
+       return pa[i].rate;
+}
+
+/********************************** SP_PLL ***********************************/
+
+static long sp_pll_calc_div(struct sp_pll *clk, unsigned long rate)
+{
+       u32 fbdiv;
+       u32 max = 1 << clk->div_width;
+
+       fbdiv = DIV_ROUND_CLOSEST(rate, clk->brate);
+       if (fbdiv > max)
+               fbdiv = max;
+
+       return fbdiv;
+}
+
+static long sp_pll_round_rate(struct clk_hw *hw, unsigned long rate,
+                             unsigned long *prate)
+{
+       struct sp_pll *clk = to_sp_pll(hw);
+       long ret;
+
+       if (rate == *prate) {
+               ret = *prate; /* bypass */
+       } else if (clk->div_width == DIV_A) {
+               ret = plla_round_rate(clk, rate);
+       } else if (clk->div_width == DIV_TV) {
+               ret = plltv_div(clk, rate);
+               if (ret < 0)
+                       ret = *prate;
+       } else {
+               ret = sp_pll_calc_div(clk, rate) * clk->brate;
+       }
+
+       return ret;
+}
+
+static unsigned long sp_pll_recalc_rate(struct clk_hw *hw,
+                                       unsigned long prate)
+{
+       struct sp_pll *clk = to_sp_pll(hw);
+       u32 reg = readl(clk->reg);
+       unsigned long ret;
+
+       if (reg & BIT(clk->bp_bit)) {
+               ret = prate; /* bypass */

drivers/clk/clk-sp7021.c line 453

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+       } else if (clk->div_width == DIV_A) {
+               ret = pa[clk->p[0]].rate;
+       } else if (clk->div_width == DIV_TV) {
+               u32 m, r, reg2;
+
+               r = FIELD_GET(MASK_DIVR, readl(clk->reg + 4));
+               reg2 = readl(clk->reg + 8);
+               m = FIELD_GET(MASK_DIVM, reg2) + 1;
+
+               if (reg & BIT(1)) { /* SEL_FRA */

Make a define for BIT(1) please. SEL_FRA?

Quoted 23 lines
drivers/clk/clk-sp7021.c new file +23 -0
+                       /* fractional divider */
+                       u32 sdm  = FIELD_GET(MASK_SDM_MOD, reg);
+                       u32 ph   = FIELD_GET(MASK_PH_SEL, reg);
+                       u32 nfra = FIELD_GET(MASK_NFRA, reg);
+                       const u32 *pp = pt[ph];
+
+                       ret = prate >> r;
+                       ret = (ret * (pp[1] + pp[2]) / pp[0]) -
+                                 (ret * (mods[sdm] - nfra) / mods[sdm] / pp[4]);
+                       ret /= m;
+               } else {
+                       /* integer divider */
+                       u32 n = FIELD_GET(MASK_DIVN, reg2) + 1;
+
+                       ret = (prate / m * n) >> r;
+               }
+       } else {
+               u32 fbdiv = ((reg >> clk->div_shift) & ((1 << clk->div_width) - 1)) + 1;
+
+               ret = clk->brate * fbdiv;
+       }
+
+       return ret;

drivers/clk/clk-sp7021.c line 486

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+}
+
+static int sp_pll_set_rate(struct clk_hw *hw, unsigned long rate,
+                          unsigned long prate)
+{
+       struct sp_pll *clk = to_sp_pll(hw);
+       unsigned long flags;
+       u32 reg;
+
+       spin_lock_irqsave(clk->lock, flags);

Please push the lock down. Maybe that means having two conditionals? Either way, it is too large because it calls into plla_set_rate() and plltv_set_rate() with the lock held.

Quoted 4 lines
drivers/clk/clk-sp7021.c new file +4 -0
+
+       reg = BIT(clk->bp_bit + 16); /* HIWORD_MASK */
+
+       if (rate == prate) {

drivers/clk/clk-sp7021.c line 500

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+               reg |= BIT(clk->bp_bit); /* bypass */
+       } else if (clk->div_width == DIV_A) {
+               plla_set_rate(clk);
+       } else if (clk->div_width == DIV_TV) {
+               plltv_set_rate(clk);
+       } else if (clk->div_width) {
+               u32 fbdiv = sp_pll_calc_div(clk, rate);
+               u32 mask = GENMASK(clk->div_shift + clk->div_width - 1, clk->div_shift);
+
+               reg |= (mask << 16) | (((fbdiv - 1) << clk->div_shift) & mask);

This is a really long line.

Quoted 4 lines
drivers/clk/clk-sp7021.c new file +4 -0
+       }
+
+       writel(reg, clk->reg);
+

drivers/clk/clk-sp7021.c line 514

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+       spin_unlock_irqrestore(clk->lock, flags);
+
+       return 0;
+}
+
+static int sp_pll_enable(struct clk_hw *hw)
+{
+       struct sp_pll *clk = to_sp_pll(hw);
+
+       writel(BIT(clk->pd_bit + 16) | BIT(clk->pd_bit), clk->reg); /* power up */

The comment is pretty useless, this is what pll enable would do.

drivers/clk/clk-sp7021.c line 523

Quoted 9 lines
drivers/clk/clk-sp7021.c new file +9 -0
+
+       return 0;
+}
+
+static void sp_pll_disable(struct clk_hw *hw)
+{
+       struct sp_pll *clk = to_sp_pll(hw);
+
+       writel(BIT(clk->pd_bit + 16), clk->reg); /* power down */

Same.

Quoted 21 lines
drivers/clk/clk-sp7021.c new file +21 -0
+}
+
+static int sp_pll_is_enabled(struct clk_hw *hw)
+{
+       struct sp_pll *clk = to_sp_pll(hw);
+
+       return readl(clk->reg) & BIT(clk->pd_bit);
+}
+
+static const struct clk_ops sp_pll_ops = {
+       .enable = sp_pll_enable,
+       .disable = sp_pll_disable,
+       .is_enabled = sp_pll_is_enabled,
+       .round_rate = sp_pll_round_rate,
+       .recalc_rate = sp_pll_recalc_rate,
+       .set_rate = sp_pll_set_rate
+};
+
+static const struct clk_ops sp_pll_sub_ops = {
+       .enable = sp_pll_enable,
+       .disable = sp_pll_disable,

drivers/clk/clk-sp7021.c line 554

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+       .is_enabled = sp_pll_is_enabled,
+       .recalc_rate = sp_pll_recalc_rate,
+};
+
+static void dbg_clk(struct clk_hw *hw)
+{
+       const char *name = clk_hw_get_name(hw);
+       unsigned long rate = clk_hw_get_rate(hw);
+
+       pr_debug("%-20s%lu\n", name, rate);

This doesn't provide anything more than normal clk debugfs so just remove?

Quoted 47 lines
drivers/clk/clk-sp7021.c new file +47 -0
+}
+
+static struct clk_hw *sp_pll_register(struct device *dev, const char *name,
+                                     const struct clk_parent_data *parent_data,
+                                     void __iomem *reg, int pd_bit, int bp_bit,
+                                     unsigned long brate, int shift, int width,
+                                     spinlock_t *lock)
+{
+       struct sp_pll *pll;
+       struct clk_hw *hw;
+       struct clk_init_data initd = {
+               .name = name,
+               .parent_data = parent_data,
+               .ops = (bp_bit >= 0) ? &sp_pll_ops : &sp_pll_sub_ops,
+               .num_parents = 1,
+               /* system clock, should not be disabled */
+               .flags = (reg == PLLSYS_CTL) ? CLK_IS_CRITICAL : 0,
+       };
+       int ret;
+
+       pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL);
+       if (!pll)
+               return ERR_PTR(-ENOMEM);
+
+       pll->hw.init = &initd;
+       pll->reg = reg;
+       pll->pd_bit = pd_bit;
+       pll->bp_bit = bp_bit;
+       pll->brate = brate;
+       pll->div_shift = shift;
+       pll->div_width = width;
+       pll->lock = lock;
+
+       hw = &pll->hw;
+       ret = devm_clk_hw_register(dev, hw);
+       if (ret) {
+               kfree(pll);
+               return ERR_PTR(ret);
+       }
+       dbg_clk(hw);
+
+       return hw;
+}
+
+static int sp7021_clk_probe(struct platform_device *pdev)
+{
+       static const u32 sp_clken[] = {

drivers/clk/clk-sp7021.c line 611

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+               0x67ef, 0x03ff, 0xff03, 0xfff0, 0x0004, /* G0.1~5  */
+               0x0000, 0x8000, 0xffff, 0x0040, 0x0000, /* G0.6~10 */
+       };
+       static struct clk_parent_data pd_ext, pd_sys, pd_e;
+       struct device *dev = &pdev->dev;
+       struct clk_hw **hws;
+       struct resource *res;
+       int i;
+
+       /* This memory region include multi HW regs in discontinuous order.

The /* should be on a line by itself.

drivers/clk/clk-sp7021.c line 613

Quoted 2 lines
drivers/clk/clk-sp7021.c new file +2 -0
+        * clk driver used some discontinuous areas in the memory region.
+        * Using devm_platform_ioremap_resource() would conflicted with other drivers.

What other drivers?

Quoted 7 lines
drivers/clk/clk-sp7021.c new file +7 -0
+        */
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       sp_clk_base = devm_ioremap(dev, res->start, resource_size(res));
+       if (!sp_clk_base)
+               return -ENXIO;
+
+       /* enable default clks */

drivers/clk/clk-sp7021.c line 630

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+       for (i = 0; i < ARRAY_SIZE(sp_clken); i++)
+               writel((sp_clken[i] << 16) | sp_clken[i], sp_clk_base + 4 * (1 + i));
+
+       sp_clk_data = devm_kzalloc(dev, struct_size(sp_clk_data, hws, CLK_MAX),
+                                  GFP_KERNEL);
+       if (!sp_clk_data)
+               return -ENOMEM;
+
+       hws = sp_clk_data->hws;
+       pd_ext.index = 0; /* clocks = <&extclk>; */

Remove comment please.

Quoted 62 lines
drivers/clk/clk-sp7021.c new file +62 -0
+
+       /* PLL_A */
+       hws[PLL_A] = sp_pll_register(dev, "plla", &pd_ext, PLLA_CTL,
+                                    11, 12, 27000000, 0, DIV_A, &plla_lock);
+       if (IS_ERR(hws[PLL_A]))
+               return PTR_ERR(hws[PLL_A]);
+
+       /* PLL_E */
+       hws[PLL_E] = sp_pll_register(dev, "plle", &pd_ext, PLLE_CTL,
+                                    6, 2, 50000000, 0, 0, &plle_lock);
+       if (IS_ERR(hws[PLL_E]))
+               return PTR_ERR(hws[PLL_E]);
+       pd_e.hw = hws[PLL_E];
+       hws[PLL_E_2P5] = sp_pll_register(dev, "plle_2p5", &pd_e, PLLE_CTL,
+                                        13, -1, 2500000, 0, 0, &plle_lock);
+       if (IS_ERR(hws[PLL_E_2P5]))
+               return PTR_ERR(hws[PLL_E_2P5]);
+       hws[PLL_E_25] = sp_pll_register(dev, "plle_25", &pd_e, PLLE_CTL,
+                                       12, -1, 25000000, 0, 0, &plle_lock);
+       if (IS_ERR(hws[PLL_E_25]))
+               return PTR_ERR(hws[PLL_E_25]);
+       hws[PLL_E_112P5] = sp_pll_register(dev, "plle_112p5", &pd_e, PLLE_CTL,
+                                          11, -1, 112500000, 0, 0, &plle_lock);
+       if (IS_ERR(hws[PLL_E_112P5]))
+               return PTR_ERR(hws[PLL_E_112P5]);
+
+       /* PLL_F */
+       hws[PLL_F] = sp_pll_register(dev, "pllf", &pd_ext, PLLF_CTL,
+                                    0, 10, 13500000, 1, 4, &pllf_lock);
+       if (IS_ERR(hws[PLL_F]))
+               return PTR_ERR(hws[PLL_F]);
+
+       /* PLL_TV */
+       hws[PLL_TV] = sp_pll_register(dev, "plltv", &pd_ext, PLLTV_CTL,
+                                     0, 15, 27000000, 0, DIV_TV, &plltv_lock);
+       if (IS_ERR(hws[PLL_TV]))
+               return PTR_ERR(hws[PLL_TV]);
+       hws[PLL_TV_A] = devm_clk_hw_register_divider(dev, "plltv_a", "plltv", 0,
+                                                    PLLTV_CTL + 4, 5, 1,
+                                                    CLK_DIVIDER_POWER_OF_TWO,
+                                                    &plltv_lock);
+       if (IS_ERR(hws[PLL_TV_A]))
+               return PTR_ERR(hws[PLL_TV_A]);
+       dbg_clk(hws[PLL_TV_A]);
+
+       /* PLL_SYS */
+       hws[PLL_SYS] = sp_pll_register(dev, "pllsys", &pd_ext, PLLSYS_CTL,
+                                      10, 9, 13500000, 0, 4, &pllsys_lock);
+       if (IS_ERR(hws[PLL_SYS]))
+               return PTR_ERR(hws[PLL_SYS]);
+       pd_sys.hw = hws[PLL_SYS];
+
+       /* gates */
+       for (i = 0; i < ARRAY_SIZE(sp_clk_gates); i++) {
+               char name[10];
+               u32 f = sp_clk_gates[i];
+               int j = f & 0xffff;
+               struct clk_parent_data *pd = (f & F_EXTCLK) ? &pd_ext : &pd_sys;
+
+               sprintf(name, "%02d_0x%02x", i, j);
+               hws[i] = clk_hw_register_gate_parent_data(dev, name, pd, 0,
+                                                         clk_regs + (j >> 4) * 4,

drivers/clk/clk-sp7021.c line 702

Quoted 10 lines
drivers/clk/clk-sp7021.c new file +10 -0
+                                                         j & 0x0f,
+                                                         CLK_GATE_HIWORD_MASK,
+                                                         NULL);
+               if (IS_ERR(hws[i]))
+                       return PTR_ERR(hws[i]);
+               dbg_clk(hws[i]);
+       }
+
+       sp_clk_data->num = CLK_MAX;
+       return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, sp_clk_data);

We leaked a bunch of clk_hw_register_gate_parent_data() calls here if this failed.

drivers/clk/clk-sp7021.c line 708

Quoted 6 lines
drivers/clk/clk-sp7021.c new file +6 -0
+}
+
+static const struct of_device_id sp7021_clk_dt_ids[] = {
+       { .compatible = "sunplus,sp7021-clkc", },
+       { }
+};

Missing MODULE_DEVICE_TABLE, but see below.

drivers/clk/clk-sp7021.c line 721

Quoted 13 lines
drivers/clk/clk-sp7021.c new file +13 -0
+
+static struct platform_driver sp7021_clk_driver = {
+       .probe  = sp7021_clk_probe,
+       .driver = {
+               .name = "sp7021-clk",
+               .of_match_table = sp7021_clk_dt_ids,
+       },
+};
+module_platform_driver(sp7021_clk_driver);
+
+MODULE_AUTHOR("Sunplus Technology");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Clock driver for Sunplus SP7021 SoC");

Is it a module? The Kconfig is bool, so either make that tristate or remove modular support from this driver. Preferably make it tristate.

author maintainer
#14 lore raw

RE: [PATCH v15 05/10] clk: Add Sunplus SP7021 clock driver

Quoted 10 lines

drivers/clk/clk-sp7021.c line 190

Quoted 8 lines
drivers/clk/clk-sp7021.c new file +8 -0
+               nf = fvco * m_table[m];
+               n = nf / F_27M;
+               if ((n * F_27M) == nf)
+                       break;
+       }
+       m = m_table[m];
+
+       if (!m) {

This can be resolved with a 'return' from a subfunction or a goto.

Sorry, Could you explain more clear?
Did you means like:

	If (!m) {
		ret = -EINVAL;
		goto err_not_found;
	}
	...
	return freq;

err_not_found:

	...
	return ret;
}
Quoted 18 lines
Quoted 14 lines
drivers/clk/clk-sp7021.c new file +13 -0
+               pr_err("%s: %s freq:%lu not found a valid setting\n",
+                      __func__, clk_hw_get_name(&clk->hw), freq);
+               return -EINVAL;
+       }
+
+       /* save parameters */
+       clk->p[SEL_FRA] = 0;
+       clk->p[DIVR]    = r;
+       clk->p[DIVN]    = n;
+       clk->p[DIVM]    = m;
+
+       return freq;
+}
Quoted 9 lines

drivers/clk/clk-sp7021.c line 280

Quoted 7 lines
drivers/clk/clk-sp7021.c new file +7 -0
+
+                               df_quotient  = df / m;
+                               df_remainder = ((df % m) * 1000) / m;
+
+                               if (freq > df_quotient) {
+                                       df_quotient  = freq - df_quotient - 1;
+                                       df_remainder = 1000 - df_remainder;

Where does 1000 come from?

1000 is come from "borrow 1" in last operation.

Quoted 9 lines
Quoted 5 lines
drivers/clk/clk-sp7021.c new file +4 -0
+                               } else {
+                                       df_quotient = df_quotient - freq;
+                               }
+
Quoted 12 lines

drivers/clk/clk-sp7021.c line 486

Quoted 8 lines
drivers/clk/clk-sp7021.c new file +8 -0
+static int sp_pll_set_rate(struct clk_hw *hw, unsigned long rate,
+                          unsigned long prate)
+{
+       struct sp_pll *clk = to_sp_pll(hw);
+       unsigned long flags;
+       u32 reg;
+
+       spin_lock_irqsave(clk->lock, flags);

Please push the lock down. Maybe that means having two conditionals? Either way, it is too large because it calls into plla_set_rate() and plltv_set_rate() with the lock held.

Sorry, I don't understand "push the lock down. Maybe that means having two conditionals?" what means. The plla_set_rate() & plltv_set_rate() is only include simple operations & HW reg writes. I think it should be called with lock held.

static void plla_set_rate(struct sp_pll *clk)

{
	const u32 *pp = pa[clk->p[0]].regs;
	int i;

	for (i = 0; i < ARRAY_SIZE(pa->regs); i++)
		writel(0xffff0000 | pp[i], clk->reg + (i * 4));
}

static void plltv_set_rate(struct sp_pll *clk)

{
	u32 reg;

	reg  = HWM_FIELD_PREP(MASK_SEL_FRA, clk->p[SEL_FRA]);
	reg |= HWM_FIELD_PREP(MASK_SDM_MOD, clk->p[SDM_MOD]);
	reg |= HWM_FIELD_PREP(MASK_PH_SEL, clk->p[PH_SEL]);
	reg |= HWM_FIELD_PREP(MASK_NFRA, clk->p[NFRA]);
	writel(reg, clk->reg);

	reg  = HWM_FIELD_PREP(MASK_DIVR, clk->p[DIVR]);
	writel(reg, clk->reg + 4);

	reg  = HWM_FIELD_PREP(MASK_DIVN, clk->p[DIVN] - 1);
	reg |= HWM_FIELD_PREP(MASK_DIVM, clk->p[DIVM] - 1);
	writel(reg, clk->reg + 8);
}

A message that is not in the archive (sent off-list or not yet received): [email protected]

author maintainer
#16 lore raw

RE: [PATCH v15 05/10] clk: Add Sunplus SP7021 clock driver

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

drivers/clk/clk-sp7021.c line 280

Quoted 7 lines
drivers/clk/clk-sp7021.c new file +7 -0
+
+                               df_quotient  = df / m;
+                               df_remainder = ((df % m) * 1000) / m;
+
+                               if (freq > df_quotient) {
+                                       df_quotient  = freq - df_quotient - 1;
+                                       df_remainder = 1000 - df_remainder;

Where does 1000 come from?

Quoted 4 lines
Quoted 1 line

1000 is come from "borrow 1" in last operation.

It's scaling the value right? What is being scaled? Are we converting units to Hz from kHz?

Here just using integer replacement floating point operation, for example:
df = 13, m = 3
13 / 3 = 4.33333333
df_quotient = 4
df_remainder = 0.3333333 * 1000 (accurate to 3 decimal places) = 333

author maintainer
#17 lore raw

PATCH v15 6/10 dt-bindings: interrupt-controller: Add bindings for SP7021 interrupt controller

In reply to Qin Jian

Add documentation to describe Sunplus SP7021 interrupt controller bindings.

---
Remove "Device Tree Bindings" from title

---
 .../sunplus,sp7021-intc.yaml                  | 62 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/sunplus,sp7021-intc.yaml
Documentation/devicetree/bindings/interrupt-controller/sunplus,sp7021-intc.yaml new file +62 -0
new file mode 100644
index 000000000..bd0021dba
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/sunplus,sp7021-intc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus SP7021 SoC Interrupt Controller
+
+maintainers:
+  - Qin Jian <[email protected]>
+
+properties:
+  compatible:
+    items:
+      - const: sunplus,sp7021-intc
+
+  reg:
+    maxItems: 2
+    description:
+      Specifies base physical address(s) and size of the controller regs.
+      The 1st region include type/polarity/priority/mask regs.
+      The 2nd region include clear/masked_ext0/masked_ext1/group regs.
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 2
+    description:
+      The first cell is the IRQ number, the second cell is the trigger
+      type as defined in interrupt.txt in this directory.
+
+  interrupts:
+    maxItems: 2
+    description:
+      EXT_INT0 & EXT_INT1, 2 interrupts references to primary interrupt
+      controller.
+
+required:
+  - compatible
+  - reg
+  - interrupt-controller
+  - "#interrupt-cells"
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    intc: interrupt-controller@9c000780 {
+        compatible = "sunplus,sp7021-intc";
+        reg = <0x9c000780 0x80>, <0x9c000a80 0x80>;
+        interrupt-controller;
+        #interrupt-cells = <2>;
+        interrupt-parent = <&gic>;
+        interrupts = <GIC_SPI 5 IRQ_TYPE_LEVEL_HIGH>, /* EXT_INT0 */
+                     <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>; /* EXT_INT1 */
+    };
+
+...
MAINTAINERS +1 -0
index 26b77b68b..8dfab70f0 100644
@@ -2745,6 +2745,7 @@ S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
 F:	Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
 F:	Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
+F:	Documentation/devicetree/bindings/interrupt-controller/sunplus,sp7021-intc.yaml
 F:	Documentation/devicetree/bindings/reset/sunplus,reset.yaml
 F:	drivers/clk/clk-sp7021.c
 F:	drivers/reset/reset-sunplus.c
Signature · 1 line
2.33.1
author maintainer
#18 lore raw

PATCH v15 7/10 irqchip: Add Sunplus SP7021 interrupt controller driver

In reply to Qin Jian

Add interrupt controller driver for Sunplus SP7021 SoC.

This is the interrupt controller in P-chip which collects all interrupt sources in P-chip and routes them to parent interrupt controller in C-chip.

---
 MAINTAINERS                       |   1 +
 drivers/irqchip/Kconfig           |   9 +
 drivers/irqchip/Makefile          |   2 +
 drivers/irqchip/irq-sp7021-intc.c | 278 ++++++++++++++++++++++++++++++
 4 files changed, 290 insertions(+)
 create mode 100644 drivers/irqchip/irq-sp7021-intc.c
MAINTAINERS +1 -0
index 8dfab70f0..762beec05 100644
@@ -2748,6 +2748,7 @@ F:	Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
 F:	Documentation/devicetree/bindings/interrupt-controller/sunplus,sp7021-intc.yaml
 F:	Documentation/devicetree/bindings/reset/sunplus,reset.yaml
 F:	drivers/clk/clk-sp7021.c
+F:	drivers/irqchip/irq-sp7021-intc.c
 F:	drivers/reset/reset-sunplus.c
 F:	include/dt-bindings/clock/sunplus,sp7021-clkc.h
 F:	include/dt-bindings/reset/sunplus,sp7021-reset.h
drivers/irqchip/Kconfig +9 -0
index 7038957f4..f5c2596bc 100644
@@ -617,4 +617,13 @@ config MCHP_EIC
 	help
 	  Support for Microchip External Interrupt Controller.
 
+config SUNPLUS_SP7021_INTC
+	bool "Sunplus SP7021 interrupt controller" if COMPILE_TEST
+	default SOC_SP7021
+	help
+	  Support for the Sunplus SP7021 Interrupt Controller IP core.
+	  SP7021 SoC has 2 Chips: C-Chip & P-Chip. This is used as a
+	  chained controller, routing all interrupt source in P-Chip to
+	  the primary controller on C-Chip.
+
 endmenu
drivers/irqchip/Makefile +2 -0
index c1f611cbf..eb0ac83ff 100644
@@ -117,3 +117,5 @@ obj-$(CONFIG_WPCM450_AIC)		+= irq-wpcm450-aic.o
 obj-$(CONFIG_IRQ_IDT3243X)		+= irq-idt3243x.o
 obj-$(CONFIG_APPLE_AIC)			+= irq-apple-aic.o
 obj-$(CONFIG_MCHP_EIC)			+= irq-mchp-eic.o
+obj-$(CONFIG_SUNPLUS_SP7021_INTC)	+= irq-sp7021-intc.o
+
drivers/irqchip/irq-sp7021-intc.c new file +278 -0

278 lines not on this page · raw message

Signature · 1 line
2.33.1
author maintainer
#19 lore raw

PATCH v15 8/10 ARM: sunplus: Add initial support for Sunplus SP7021 SoC

In reply to Qin Jian

This patch aims to add an initial support for Sunplus SP7021 SoC.

---
 MAINTAINERS                    |  1 +
 arch/arm/Kconfig               |  2 ++
 arch/arm/Makefile              |  1 +
 arch/arm/mach-sunplus/Kconfig  | 27 +++++++++++++++++++++++++++
 arch/arm/mach-sunplus/Makefile |  9 +++++++++
 arch/arm/mach-sunplus/sp7021.c | 16 ++++++++++++++++
 6 files changed, 56 insertions(+)
 create mode 100644 arch/arm/mach-sunplus/Kconfig
 create mode 100644 arch/arm/mach-sunplus/Makefile
 create mode 100644 arch/arm/mach-sunplus/sp7021.c
MAINTAINERS +1 -0
index 762beec05..ad52b0a2d 100644
@@ -2747,6 +2747,7 @@ F:	Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
 F:	Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
 F:	Documentation/devicetree/bindings/interrupt-controller/sunplus,sp7021-intc.yaml
 F:	Documentation/devicetree/bindings/reset/sunplus,reset.yaml
+F:	arch/arm/mach-sunplus/
 F:	drivers/clk/clk-sp7021.c
 F:	drivers/irqchip/irq-sp7021-intc.c
 F:	drivers/reset/reset-sunplus.c
arch/arm/Kconfig +2 -0
index 4c97cb40e..1ee9a27a3 100644
@@ -693,6 +693,8 @@ source "arch/arm/mach-sti/Kconfig"
 
 source "arch/arm/mach-stm32/Kconfig"
 
+source "arch/arm/mach-sunplus/Kconfig"
+
 source "arch/arm/mach-sunxi/Kconfig"
 
 source "arch/arm/mach-tegra/Kconfig"
arch/arm/Makefile +1 -0
index 77172d555..1e19d2f4b 100644
@@ -216,6 +216,7 @@ machine-$(CONFIG_ARCH_RENESAS)	 	+= shmobile
 machine-$(CONFIG_ARCH_INTEL_SOCFPGA)	+= socfpga
 machine-$(CONFIG_ARCH_STI)		+= sti
 machine-$(CONFIG_ARCH_STM32)		+= stm32
+machine-$(CONFIG_ARCH_SUNPLUS)		+= sunplus
 machine-$(CONFIG_ARCH_SUNXI)		+= sunxi
 machine-$(CONFIG_ARCH_TEGRA)		+= tegra
 machine-$(CONFIG_ARCH_U8500)		+= ux500
arch/arm/mach-sunplus/Kconfig new file +27 -0
new file mode 100644
index 000000000..be20425c2
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+
+menuconfig ARCH_SUNPLUS
+	bool "Sunplus SoCs"
+	depends on ARCH_MULTI_V7
+	help
+	  Support for Sunplus SoC family: SP7021 and succeeding SoC-based systems,
+	  such as the Banana Pi BPI-F2S development board (and derivatives).
+	  (<http://www.sinovoip.com.cn/ecp_view.asp?id=586>)
+	  (<https://tibbo.com/store/plus1.html>)
+
+config SOC_SP7021
+	bool "Sunplus SP7021 SoC support"
+	depends on ARCH_SUNPLUS
+	default ARCH_SUNPLUS
+	select HAVE_ARM_ARCH_TIMER
+	select ARM_GIC
+	select ARM_PSCI
+	select PINCTRL
+	select PINCTRL_SPPCTL
+	select SERIAL_SUNPLUS
+	select SERIAL_SUNPLUS_CONSOLE
+	help
+	  Support for Sunplus SP7021 SoC. It is based on ARM 4-core
+	  Cortex-A7 with various peripherals (ex: I2C, SPI, SDIO,
+	  Ethernet and etc.), FPGA interface,  chip-to-chip bus.
+	  It is designed for industrial control.
arch/arm/mach-sunplus/Makefile new file +9 -0
new file mode 100644
index 000000000..c902580a7
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the linux kernel.
+#
+
+# Object file lists.
+
+obj-$(CONFIG_SOC_SP7021)	+= sp7021.o
+
arch/arm/mach-sunplus/sp7021.c new file +16 -0
new file mode 100644
index 000000000..774d0a5bd
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+/*
+ * Copyright (C) Sunplus Technology Co., Ltd.
+ *       All rights reserved.
+ */
+#include <linux/kernel.h>
+#include <asm/mach/arch.h>
+
+static const char *sp7021_compat[] __initconst = {
+	"sunplus,sp7021",
+	NULL
+};
+
+DT_MACHINE_START(SP7021_DT, "SP7021")
+	.dt_compat	= sp7021_compat,
+MACHINE_END
Signature · 1 line
2.33.1
author maintainer
#20 lore raw

PATCH v15 9/10 ARM: sp7021_defconfig: Add Sunplus SP7021 defconfig

In reply to Qin Jian

Add generic Sunplus SP7021 based board defconfig

---
 MAINTAINERS                         |  1 +
 arch/arm/configs/multi_v7_defconfig |  1 +
 arch/arm/configs/sp7021_defconfig   | 59 +++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 arch/arm/configs/sp7021_defconfig
MAINTAINERS +1 -0
index ad52b0a2d..9cf30e776 100644
@@ -2747,6 +2747,7 @@ F:	Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
 F:	Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
 F:	Documentation/devicetree/bindings/interrupt-controller/sunplus,sp7021-intc.yaml
 F:	Documentation/devicetree/bindings/reset/sunplus,reset.yaml
+F:	arch/arm/configs/sp7021_*defconfig
 F:	arch/arm/mach-sunplus/
 F:	drivers/clk/clk-sp7021.c
 F:	drivers/irqchip/irq-sp7021-intc.c
arch/arm/configs/multi_v7_defconfig +1 -0
index 8863fa969..a3bd9dbd8 100644
@@ -86,6 +86,7 @@ CONFIG_MACH_SPEAR1310=y
 CONFIG_MACH_SPEAR1340=y
 CONFIG_ARCH_STI=y
 CONFIG_ARCH_STM32=y
+CONFIG_ARCH_SUNPLUS=y
 CONFIG_ARCH_SUNXI=y
 CONFIG_ARCH_TEGRA=y
 CONFIG_ARCH_UNIPHIER=y
arch/arm/configs/sp7021_defconfig new file +59 -0

59 lines not on this page · raw message

Signature · 1 line
2.33.1
author maintainer
#22 lore raw

PATCH v15 10/10 ARM: dts: Add Sunplus SP7021-Demo-V3 board device tree

In reply to Qin Jian

Add the basic support for Sunplus SP7021-Demo-V3 board.

---
 MAINTAINERS                                  |   1 +
 arch/arm/boot/dts/sunplus-sp7021-achip.dtsi  |  85 +++++
 arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts |  27 ++
 arch/arm/boot/dts/sunplus-sp7021.dtsi        | 369 +++++++++++++++++++
 4 files changed, 482 insertions(+)
 create mode 100644 arch/arm/boot/dts/sunplus-sp7021-achip.dtsi
 create mode 100644 arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts
 create mode 100644 arch/arm/boot/dts/sunplus-sp7021.dtsi
MAINTAINERS +1 -0
index 9cf30e776..b55ec0768 100644
@@ -2747,6 +2747,7 @@ F:	Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
 F:	Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
 F:	Documentation/devicetree/bindings/interrupt-controller/sunplus,sp7021-intc.yaml
 F:	Documentation/devicetree/bindings/reset/sunplus,reset.yaml
+F:	arch/arm/boot/dts/sunplus-sp7021*.dts*
 F:	arch/arm/configs/sp7021_*defconfig
 F:	arch/arm/mach-sunplus/
 F:	drivers/clk/clk-sp7021.c
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +85 -0

85 lines not on this page · raw message

arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts new file +27 -0
new file mode 100644
index 000000000..05e164115
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Device Tree Source for Sunplus SP7021 Demo V3 SBC board
+ *
+ * Copyright (C) Sunplus Technology Co.
+ */
+
+/dts-v1/;
+
+#include "sunplus-sp7021-achip.dtsi"
+
+/ {
+	compatible = "sunplus,sp7021-demo-v3";
+	model = "SP7021/CA7/Demo_V3";
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	chosen {
+		bootargs = "console=ttyS0,115200 loglevel=8 earlycon";
+		stdout-path = "serial0:115200n8";
+	};
+
+	memory {
+		device_type = "memory";
+		reg = <0x00000000 0x20000000>;
+	};
+};
arch/arm/boot/dts/sunplus-sp7021.dtsi new file +369 -0

369 lines not on this page · raw message

Signature · 1 line
2.33.1
#23 lore raw

Re: [PATCH v15 10/10] ARM: dts: Add Sunplus SP7021-Demo-V3 board device tree

Quoted 32 lines · Qin Jian

Add the basic support for Sunplus SP7021-Demo-V3 board.

---
 MAINTAINERS                                  |   1 +
 arch/arm/boot/dts/sunplus-sp7021-achip.dtsi  |  85 +++++
 arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts |  27 ++
 arch/arm/boot/dts/sunplus-sp7021.dtsi        | 369 +++++++++++++++++++
 4 files changed, 482 insertions(+)
 create mode 100644 arch/arm/boot/dts/sunplus-sp7021-achip.dtsi
 create mode 100644 arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts
 create mode 100644 arch/arm/boot/dts/sunplus-sp7021.dtsi
MAINTAINERS +1 -0
index 9cf30e776..b55ec0768 100644
@@ -2747,6 +2747,7 @@ F:	Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml
 F:	Documentation/devicetree/bindings/clock/sunplus,sp7021-clkc.yaml
 F:	Documentation/devicetree/bindings/interrupt-controller/sunplus,sp7021-intc.yaml
 F:	Documentation/devicetree/bindings/reset/sunplus,reset.yaml
+F:	arch/arm/boot/dts/sunplus-sp7021*.dts*
 F:	arch/arm/configs/sp7021_*defconfig
 F:	arch/arm/mach-sunplus/
 F:	drivers/clk/clk-sp7021.c
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +1 -0
new file mode 100644
index 000000000..1560c95d9
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0

arch/arm/boot/dts/sunplus-sp7021-achip.dtsi line 11

Quoted 10 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +10 -0
+/*
+ * Device Tree Source for Sunplus SP7021
+ *
+ * Copyright (C) 2021 Sunplus Technology Co.
+ */
+
+#include "sunplus-sp7021.dtsi"
+
+/ {
+	compatible = "sunplus,sp7021-achip";

This does not match your bindings.

arch/arm/boot/dts/sunplus-sp7021-achip.dtsi line 22

Quoted 11 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +11 -0
+	model = "Sunplus SP7021 (CA7)";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	interrupt-parent = <&gic>;
+
+	clocks {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+
+		extclk: clk@osc0 {

This is not a valid device tree. Please run make dtbs_check and compile dtbs with W=1.

arch/arm/boot/dts/sunplus-sp7021-achip.dtsi line 29

Quoted 7 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +7 -0
+			compatible = "fixed-clock";
+			#clock-cells = <0>;
+			clock-frequency = <27000000>;
+			clock-output-names = "extclk";
+		};
+
+		divextclk: clk@0 {

How is it suppose to pass any automated checks if there is no unit address?

arch/arm/boot/dts/sunplus-sp7021-achip.dtsi line 38

Quoted 9 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +9 -0
+			compatible = "fixed-factor-clock";
+			#clock-cells = <0>;
+			clocks  = <&extclk>;
+			clock-mult = <1>;
+			clock-div = <2>;
+			clock-output-names = "extdivclk";
+		};
+
+		A_pll0: clk@A_pll0 {

This is not a valid device tree.

Quoted 56 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +47 -0
+			compatible = "fixed-clock";
+			#clock-cells = <0>;
+			clock-frequency = <2000000000>;
+			clock-output-names = "A_pll0";
+		};
+	};
+
+	cpus {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		cpu0: cpu@0 {
+			compatible = "arm,cortex-a7";
+			device_type = "cpu";
+			reg = <0>;
+			clock-frequency = <931000000>;
+		};
+		cpu1: cpu@1 {
+			compatible = "arm,cortex-a7";
+			device_type = "cpu";
+			reg = <1>;
+			clock-frequency = <931000000>;
+		};
+		cpu2: cpu@2 {
+			compatible = "arm,cortex-a7";
+			device_type = "cpu";
+			reg = <2>;
+			clock-frequency = <931000000>;
+		};
+		cpu3: cpu@3 {
+			compatible = "arm,cortex-a7";
+			device_type = "cpu";
+			reg = <3>;
+			clock-frequency = <931000000>;
+		};
+	};
+
+	arm-pmu {
+		compatible = "arm,cortex-a7-pmu";
+		interrupts = <GIC_SPI 219 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 220 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 221 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 222 IRQ_TYPE_LEVEL_HIGH>;
+		interrupt-affinity = <&cpu0>, <&cpu1>, <&cpu2>, <&cpu3>;
+	};
+
+};
arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts new file +3 -0
new file mode 100644
index 000000000..05e164115
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Device Tree Source for Sunplus SP7021 Demo V3 SBC board

arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts line 13

Quoted 10 lines
arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts new file +10 -0
+ *
+ * Copyright (C) Sunplus Technology Co.
+ */
+
+/dts-v1/;
+
+#include "sunplus-sp7021-achip.dtsi"
+
+/ {
+	compatible = "sunplus,sp7021-demo-v3";

This does not match your bindings.

Please run make dtbs_check.

arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts line 19

Quoted 6 lines
arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts new file +6 -0
+	model = "SP7021/CA7/Demo_V3";
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	chosen {
+		bootargs = "console=ttyS0,115200 loglevel=8 earlycon";

No bootargs.

I'll stop reviewing. This either does not compile, does not work or does not pass automated checks. There is no point to use reviewers time if the tools are doing the same job, so use the tools and then submit DTS.

Best regards,
Krzysztof

author maintainer
#24 lore raw

RE: [PATCH v15 10/10] ARM: dts: Add Sunplus SP7021-Demo-V3 board device tree

Quoted 39 lines
Quoted 7 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +1 -0
new file mode 100644
index 000000000..1560c95d9
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0

arch/arm/boot/dts/sunplus-sp7021-achip.dtsi line 11

Quoted 10 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +10 -0
+/*
+ * Device Tree Source for Sunplus SP7021
+ *
+ * Copyright (C) 2021 Sunplus Technology Co.
+ */
+
+#include "sunplus-sp7021.dtsi"
+
+/ {
+	compatible = "sunplus,sp7021-achip";

This does not match your bindings.

Quoted 5 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +4 -0
+++ b/arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Device Tree Source for Sunplus SP7021 Demo V3 SBC board

arch/arm/boot/dts/sunplus-sp7021-achip.dtsi line 13

Quoted 10 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +10 -0
+ *
+ * Copyright (C) Sunplus Technology Co.
+ */
+
+/dts-v1/;
+
+#include "sunplus-sp7021-achip.dtsi"
+
+/ {
+	compatible = "sunplus,sp7021-demo-v3";

This does not match your bindings.

Quoted 1 line

Please run make dtbs_check.

I did passed the make dtbs_check.
compatible string: "sunplus,sp7021", "sunplus,sp7021-achip", "sunplus,sp7021-demo-v3" all defined @ Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml [1]

[1] https://lore.kernel.org/lkml/6107a68008f2d71d2c7868d4d94cb66c5b5fc134.1652329411.git.qinjian@cqplus1.com/

#25 lore raw

Re: [PATCH v15 10/10] ARM: dts: Add Sunplus SP7021-Demo-V3 board device tree

Quoted 39 lines · qinjian[覃健]
Quoted 39 lines
Quoted 7 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +1 -0
new file mode 100644
index 000000000..1560c95d9
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0

arch/arm/boot/dts/sunplus-sp7021-achip.dtsi line 11

Quoted 10 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +10 -0
+/*
+ * Device Tree Source for Sunplus SP7021
+ *
+ * Copyright (C) 2021 Sunplus Technology Co.
+ */
+
+#include "sunplus-sp7021.dtsi"
+
+/ {
+	compatible = "sunplus,sp7021-achip";

This does not match your bindings.

Quoted 5 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +4 -0
+++ b/arch/arm/boot/dts/sunplus-sp7021-demo-v3.dts
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Device Tree Source for Sunplus SP7021 Demo V3 SBC board

arch/arm/boot/dts/sunplus-sp7021-achip.dtsi line 13

Quoted 10 lines
arch/arm/boot/dts/sunplus-sp7021-achip.dtsi new file +10 -0
+ *
+ * Copyright (C) Sunplus Technology Co.
+ */
+
+/dts-v1/;
+
+#include "sunplus-sp7021-achip.dtsi"
+
+/ {
+	compatible = "sunplus,sp7021-demo-v3";

This does not match your bindings.

Quoted 5 lines
Quoted 1 line

Please run make dtbs_check.

I did passed the make dtbs_check.
compatible string: "sunplus,sp7021", "sunplus,sp7021-achip", "sunplus,sp7021-demo-v3" all defined @ Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml [1]

How this can pass the check if it is entirely different compatible and does not match schema? The code is not correct. If you test your DTS with dtbs_check you will see:

	sunplus-sp7021-demo-v3.dtb: /: compatible: ['sunplus,sp7021-demo-v3']

is too short

Additionally:
1. Your DTBs do not compile, missing Makefile entry.

2. You have to fix whitespace issues in your patches:

.git/rebase-apply/patch:48: new blank line at EOF.

+

warning: 1 line adds whitespace errors.

.git/rebase-apply/patch:97: new blank line at EOF.

+

warning: 1

Best regards,
Krzysztof

author maintainer
#26 lore raw

RE: [PATCH v15 10/10] ARM: dts: Add Sunplus SP7021-Demo-V3 board device tree

Quoted 9 lines
Quoted 4 lines

I did passed the make dtbs_check.
compatible string: "sunplus,sp7021", "sunplus,sp7021-achip", "sunplus,sp7021-demo-v3" all defined @ Documentation/devicetree/bindings/arm/sunplus,sp7021.yaml [1]

How this can pass the check if it is entirely different compatible and does not match schema? The code is not correct. If you test your DTS with dtbs_check you will see:

Quoted 7 lines
	sunplus-sp7021-demo-v3.dtb: /: compatible: ['sunplus,sp7021-demo-v3']

is too short

Additionally:
1. Your DTBs do not compile, missing Makefile entry.

Got it, I compiled the dtb with command: make sunplus-sp7021-demo-v3.dtb After I add it to arch/arm/boot/dts/Makefile,
make dtbs_check got the error.
Thanks for your patient guidance.

#27 lore raw
In reply to Qin Jian
Quoted 7 lines · Qin Jian

This patch series add Sunplus SP7021 SoC support.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Quoted 6 lines

SP7021 consists of two chips (dies) in a package. One is called C-chip (computing chip). It is a 4-core ARM Cortex A7 CPU. It adopts high-level process (22 nm) for high performance computing. The other is called P- chip (peripheral chip). It has many peripherals and an ARM A926 added especially for real-time control. P-chip is made for customers. It adopts low-level process (ex: 0.11 um) to reduce cost.

It looks like there are still some remaining review comments, and the clk driver is missing a review. Since we are close to 5.18-rc7, I think it's too late for the coming merge window, and you should target 5.20, with a rebase on top of v5.19-rc1 once that is out.

If you get no replies on the clk driver, maybe try splitting that out and post it separately to the clk maintainers. I know they are rather backlogged on review time.

Arnd