Add clock controller support for SpacemiT K1
Subsystems (4)
v7 cover Add clock controller support for SpacemiT K1
The clock tree of SpacemiT K1 is managed by several independent multifunction devices, some of them are
- Application Power Manage Unit, APMU
- Main Power Manage Unit, MPMU
- APB Bus Clock Unit, APBC
- APB Spare, APBS
These four devices provide hardware bits for three purposes: power management, reset signals and clocks. Not every device is capable of all the three functionalities,
- APMU, MPMU: power, reset, clock
- APBC: clock, reset
- APBS: clock (PLL clocks)
This series adds support for clock hardwares in these four regions, which covers most peripherals except DDR and the realtime processor.
Tested on BananaPi-F3 board. With some out-of-tree drivers, I've successfully brought up I2C, RTC, MMC and ethernet controllers.
It has been a very long time since I sent v1 of the series, thanks for everyone making suggestions and keeping track. I'm looking forward for furthermore reviews, or getting it finally merged.
Changed from v6
- Update copyright date
- Collect reviewed-by tags
- k1-pll binding
- replace tabs with space in binding header
- driver
- remove the file accidentally added in v6
- remove undesired rates from PLL2 configuration entries
- update comment for PLL{1,2} rates
- misc style changes
- remove CLK_IS_CRITICAL from uart0 clocks and cpu_c1_hi_clk
- TWSI8 support
- Add a comment to describe the quirk
- defconfig change
- improve the commit message
- Link to v6: https://lore.kernel.org/all/[email protected]/
Changed from v5
- Correct "Spacemit" to "SpacemiT" in commit messages and code
- Always use space instead of TAB in comments for consistency
- dt-bindings
- Rename binding header to "spacemit,k1-syscon.h"
- apply review tags
- driver code
- remove "default" properties from Kconfig
- misc style and naming improvements
- make ccu_read() directly return the read value, drop ccu_poll() and reorder the arguments to ccu_{read,update} macros
- drop ccu_common.reg_swcr2
- clock tree for K1
- define PLL3 with the correct offset of SWCR3 register
- synchronize PLL configuration entries with the vendor kernel
- reformat clocks definitions
- explain why PLLs require the MPMU syscon to function
- log a message when failing to register a clock
- simplify clock registration with ARRAY_SIZE()
- ddn
- correctly handle masks which doesn't start from BIT(0) when calculating the best rate
- improve precision of frequency calculation
- derive _{den,num}_shift from corresponding masks with __ffs()
- mix
- match the full mask of gate in ccu_gate_is_enabled()
- add a note about "frequency change" bit and simplify FC-triggering logic
- drop unnecessary local variables and initialization from clock operations
- round to the closest rate in ccu_mix_calc_best_rate()
- change names of all mix subtypes to follow the order of mux -> factor/div -> gate -> fc
- drop unused _flags argument from CCU_GATE_FACTOR_DEFINE()
- pll
- ensure PLLs are initialized to a known state
- drop extra check in ccu_pll_enable()
- round to the closest rate in ccu_pll_round_rate()
- TWSI8 support
- Split cleanly from the main driver commit
- devicetree
- drop extra "*-cells" and "ranges" properties
- Enable SpacemiT K1 CCU in RISC-V defconfig
- Link to v5: https://lore.kernel.org/all/[email protected]/
Changed from v4
- bindings:
- Drop CLK_*_NUM macros from binding headers
- Rename spacemit,k1-ccu.yaml to spacemit,k1-pll.yaml, change to describe only the PLL in APBS region
- k1-syscon.yaml
- drop spacemit,k1-syscon-apbs, it should be the PLL device
- drop child nodes
- describe the syscons as clock, reset and power-domain controllers
- drop "syscon" from the compatible list, as these syscons aren't compatible with the generic one
- driver:
- misc style fixes and naming improvements
- drop unused fields from data structures
- drop unused clock types: CCU_DDN_GATE
- ddn type:
- improve the comments
- dynamically calculate appropriate rates
- hardcode the x2 factor
- mix type
- drop val_{disable,enable} for gate subtype
- drop unncessary polling when enabling a gate
- encode subtypes directly in struct ccu_mix
- generate clock names from identifiers of the data structure
- rename CCU_DIV2_FC_MUX_GATE_DEFINE to CCU_DIV_SPLIT_FC_MUX_GATE
- pll type:
- correctly claim the parent clock
- make rate tables const
- drop SWCR2-related fields
- combine fields of registers as a whole instead of working with each field
- clock tree for k1:
- removed duplicated offsets
- drop the placeholder 1:1 factor, pll1_d7_351p8
- workaround the quirk of TWSI8 clocks
- fix the definition of ripc_clk, wdt_bus_clk, dpu_bit_clk and timers_*_clk
- drop structure spacemit_ccu_priv and spacemit_ccu_data
- rework clock registration
- split the PCIe clocks correctly (there're three distinct clocks for each PCIe port)
- devicetree:
- adapt the new binding
- Link to v4: https://lore.kernel.org/all/[email protected]/
Changed from v3
- spacemit,k1-ccu binding
- allow spacemit,mpmu property only for controllers requiring it
(spacemit,k1-ccu-apbs)
- spacemit,k1-syscon binding
- drop unnecessary *-cells properties
- drop unrelated nodes in the example
- driver
- remove unnecessary divisions during rate calucalation in ccu_ddn.c
- use independent clk_ops for different ddn/mix variants, drop reg_type field in struct ccu_common
- make the register containing frequency change bit a sperate field in ccu_common
- unify DIV_MFC_MUX_GATE and DIV_FC_MUX_GATE
- implement a correct determine_rate() for mix type
- avoid reparenting in set_rate() for mix type
- fix build failure when SPACEMIT_CCU and SPACEMIT_CCU_K1 are configured differently
- use "osc" instead of "osc_32k" in clock input names
- misc style fixes
- Link to v3: https://lore.kernel.org/all/[email protected]/
Changed from v2
- dt-binding fixes
- drop clocks marked as deprecated by the vendor (CLK_JPF_4KAFBC and
CLK_JPF_2KAFBC)
- add binding of missing bus clocks
- change input clocks to use frequency-aware and more precise names
- mark input clocks and their names as required
- move the example to the (parent) syscon node and complete it
- misc style fixes
- misc improvements in code
- drop unnecessary spinlock in the driver
- implement missing bus clocks
- Link to v2: https://lore.kernel.org/all/SEYPR01MB4221829A2CD4D4C1704BABD7D7602@SEYPR01MB4221.apcprd01.prod.exchangelabs.com/
Changed from v1
- add SoC prefix (k1)
- relicense dt-binding header
- misc fixes and style improvements for dt-binding
- document spacemit,k1-syscon
- implement all APBS, MPMU, APBC and APMU clocks
- code cleanup
- Link to v1: https://lore.kernel.org/all/SEYPR01MB4221B3178F5233EAB5149E41D7902@SEYPR01MB4221.apcprd01.prod.exchangelabs.com/
Haylen Chu (6):
dt-bindings: soc: spacemit: Add spacemit,k1-syscon
dt-bindings: clock: spacemit: Add spacemit,k1-pll
clk: spacemit: Add clock support for SpacemiT K1 SoC
clk: spacemit: k1: Add TWSI8 bus and function clocks
riscv: dts: spacemit: Add clock tree for SpacemiT K1
riscv: defconfig: spacemit: enable clock controller driver for
SpacemiT K1
.../bindings/clock/spacemit,k1-pll.yaml | 50 + .../soc/spacemit/spacemit,k1-syscon.yaml | 80 ++ arch/riscv/boot/dts/spacemit/k1.dtsi | 75 ++ arch/riscv/configs/defconfig | 2 + drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/spacemit/Kconfig | 18 + drivers/clk/spacemit/Makefile | 5 + drivers/clk/spacemit/ccu-k1.c | 1164 +++++++++++++++++ drivers/clk/spacemit/ccu_common.h | 48 + drivers/clk/spacemit/ccu_ddn.c | 83 ++ drivers/clk/spacemit/ccu_ddn.h | 47 + drivers/clk/spacemit/ccu_mix.c | 268 ++++ drivers/clk/spacemit/ccu_mix.h | 218 +++ drivers/clk/spacemit/ccu_pll.c | 157 +++ drivers/clk/spacemit/ccu_pll.h | 86 ++ .../dt-bindings/clock/spacemit,k1-syscon.h | 247 ++++ 17 files changed, 2550 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/spacemit,k1-pll.yaml create mode 100644 Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml create mode 100644 drivers/clk/spacemit/Kconfig create mode 100644 drivers/clk/spacemit/Makefile create mode 100644 drivers/clk/spacemit/ccu-k1.c create mode 100644 drivers/clk/spacemit/ccu_common.h create mode 100644 drivers/clk/spacemit/ccu_ddn.c create mode 100644 drivers/clk/spacemit/ccu_ddn.h create mode 100644 drivers/clk/spacemit/ccu_mix.c create mode 100644 drivers/clk/spacemit/ccu_mix.h create mode 100644 drivers/clk/spacemit/ccu_pll.c create mode 100644 drivers/clk/spacemit/ccu_pll.h create mode 100644 include/dt-bindings/clock/spacemit,k1-syscon.h
Signature · 1 line
2.49.0
PATCH v7 1/6 dt-bindings: soc: spacemit: Add spacemit,k1-syscon
Document APMU, MPMU and APBC syscons found on SpacemiT K1 SoC, which are capable of generating clock and reset signals. Additionally, APMU and MPMU manage power domains.
--- .../soc/spacemit/spacemit,k1-syscon.yaml | 80 +++++++ .../dt-bindings/clock/spacemit,k1-syscon.h | 210 ++++++++++++++++++ 2 files changed, 290 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml create mode 100644 include/dt-bindings/clock/spacemit,k1-syscon.h
Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml new file +80 -0
@@ -0,0 +1,80 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/soc/spacemit/spacemit,k1-syscon.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SpacemiT K1 SoC System Controller + +maintainers: + - Haylen Chu <[email protected]> + +description: + System controllers found on SpacemiT K1 SoC, which are capable of + clock, reset and power-management functions. + +properties: + compatible: + enum: + - spacemit,k1-syscon-apbc + - spacemit,k1-syscon-apmu + - spacemit,k1-syscon-mpmu + + reg: + maxItems: 1 + + clocks: + maxItems: 4 + + clock-names: + items: + - const: osc + - const: vctcxo_1m + - const: vctcxo_3m + - const: vctcxo_24m + + "#clock-cells": + const: 1 + description: + See <dt-bindings/clock/spacemit,k1-syscon.h> for valid indices. + + "#power-domain-cells": + const: 1 + + "#reset-cells": + const: 1 + +required: + - compatible + - reg + - clocks + - clock-names + - "#clock-cells" + - "#reset-cells" + +allOf: + - if: + properties: + compatible: + contains: + const: spacemit,k1-syscon-apbc + then: + properties: + "#power-domain-cells": false + else: + required: + - "#power-domain-cells" + +additionalProperties: false + +examples: + - | + system-controller@d4050000 { + compatible = "spacemit,k1-syscon-mpmu"; + reg = <0xd4050000 0x209c>; + clocks = <&osc>, <&vctcxo_1m>, <&vctcxo_3m>, <&vctcxo_24m>; + clock-names = "osc", "vctcxo_1m", "vctcxo_3m", "vctcxo_24m"; + #clock-cells = <1>; + #power-domain-cells = <1>; + #reset-cells = <1>; + };
include/dt-bindings/clock/spacemit,k1-syscon.h new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH v7 2/6 dt-bindings: clock: spacemit: Add spacemit,k1-pll
In reply to Haylen ChuAdd definition for the PLL found on SpacemiT K1 SoC, which takes the external 24MHz oscillator as input and generates clocks in various frequencies for the system.
--- .../bindings/clock/spacemit,k1-pll.yaml | 50 +++++++++++++++++++ .../dt-bindings/clock/spacemit,k1-syscon.h | 37 ++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/spacemit,k1-pll.yaml
Documentation/devicetree/bindings/clock/spacemit,k1-pll.yaml new file +50 -0
@@ -0,0 +1,50 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/spacemit,k1-pll.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SpacemiT K1 PLL + +maintainers: + - Haylen Chu <[email protected]> + +properties: + compatible: + const: spacemit,k1-pll + + reg: + maxItems: 1 + + clocks: + description: External 24MHz oscillator + + spacemit,mpmu: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Phandle to the "Main PMU (MPMU)" syscon. It is used to check PLL + lock status. + + "#clock-cells": + const: 1 + description: + See <dt-bindings/clock/spacemit,k1-syscon.h> for valid indices. + +required: + - compatible + - reg + - clocks + - spacemit,mpmu + - "#clock-cells" + +additionalProperties: false + +examples: + - | + clock-controller@d4090000 { + compatible = "spacemit,k1-pll"; + reg = <0xd4090000 0x1000>; + clocks = <&vctcxo_24m>; + spacemit,mpmu = <&sysctl_mpmu>; + #clock-cells = <1>; + };
include/dt-bindings/clock/spacemit,k1-syscon.h +37 -0
@@ -6,6 +6,43 @@#ifndef _DT_BINDINGS_SPACEMIT_CCU_H_#define _DT_BINDINGS_SPACEMIT_CCU_H_ +/* APBS (PLL) clocks */ +#define CLK_PLL1 0 +#define CLK_PLL2 1 +#define CLK_PLL3 2 +#define CLK_PLL1_D2 3 +#define CLK_PLL1_D3 4 +#define CLK_PLL1_D4 5 +#define CLK_PLL1_D5 6 +#define CLK_PLL1_D6 7 +#define CLK_PLL1_D7 8 +#define CLK_PLL1_D8 9 +#define CLK_PLL1_D11 10 +#define CLK_PLL1_D13 11 +#define CLK_PLL1_D23 12 +#define CLK_PLL1_D64 13 +#define CLK_PLL1_D10_AUD 14 +#define CLK_PLL1_D100_AUD 15 +#define CLK_PLL2_D1 16 +#define CLK_PLL2_D2 17 +#define CLK_PLL2_D3 18 +#define CLK_PLL2_D4 19 +#define CLK_PLL2_D5 20 +#define CLK_PLL2_D6 21 +#define CLK_PLL2_D7 22 +#define CLK_PLL2_D8 23 +#define CLK_PLL3_D1 24 +#define CLK_PLL3_D2 25 +#define CLK_PLL3_D3 26 +#define CLK_PLL3_D4 27 +#define CLK_PLL3_D5 28 +#define CLK_PLL3_D6 29 +#define CLK_PLL3_D7 30 +#define CLK_PLL3_D8 31 +#define CLK_PLL3_80 32 +#define CLK_PLL3_40 33 +#define CLK_PLL3_20 34 +/* MPMU clocks */ #define CLK_PLL1_307P2 0#define CLK_PLL1_76P8 1
Signature · 1 line
2.49.0
PATCH v7 3/6 clk: spacemit: Add clock support for SpacemiT K1 SoC
In reply to Haylen ChuThe clock tree of K1 SoC contains three main types of clock hardware (PLL/DDN/MIX) and has control registers split into several multifunction
devices: APBS (PLLs), MPMU, APBC and APMU.
All register operations are done through regmap to ensure atomiciy between concurrent operations of clock driver and reset, power-domain driver that will be introduced in the future.
--- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/spacemit/Kconfig | 18 + drivers/clk/spacemit/Makefile | 5 + drivers/clk/spacemit/ccu-k1.c | 1154 +++++++++++++++++++++++++++++ drivers/clk/spacemit/ccu_common.h | 48 ++ drivers/clk/spacemit/ccu_ddn.c | 83 +++ drivers/clk/spacemit/ccu_ddn.h | 47 ++ drivers/clk/spacemit/ccu_mix.c | 268 +++++++ drivers/clk/spacemit/ccu_mix.h | 218 ++++++ drivers/clk/spacemit/ccu_pll.c | 157 ++++ drivers/clk/spacemit/ccu_pll.h | 86 +++ 12 files changed, 2086 insertions(+) create mode 100644 drivers/clk/spacemit/Kconfig create mode 100644 drivers/clk/spacemit/Makefile create mode 100644 drivers/clk/spacemit/ccu-k1.c create mode 100644 drivers/clk/spacemit/ccu_common.h create mode 100644 drivers/clk/spacemit/ccu_ddn.c create mode 100644 drivers/clk/spacemit/ccu_ddn.h create mode 100644 drivers/clk/spacemit/ccu_mix.c create mode 100644 drivers/clk/spacemit/ccu_mix.h create mode 100644 drivers/clk/spacemit/ccu_pll.c create mode 100644 drivers/clk/spacemit/ccu_pll.h
drivers/clk/Kconfig +1 -0
@@ -517,6 +517,7 @@ source "drivers/clk/samsung/Kconfig" source "drivers/clk/sifive/Kconfig" source "drivers/clk/socfpga/Kconfig" source "drivers/clk/sophgo/Kconfig" +source "drivers/clk/spacemit/Kconfig" source "drivers/clk/sprd/Kconfig" source "drivers/clk/starfive/Kconfig" source "drivers/clk/sunxi/Kconfig"
drivers/clk/Makefile +1 -0
@@ -145,6 +145,7 @@ obj-$(CONFIG_COMMON_CLK_SAMSUNG) += samsung/ obj-$(CONFIG_CLK_SIFIVE) += sifive/ obj-y += socfpga/ obj-y += sophgo/ +obj-y += spacemit/ obj-$(CONFIG_PLAT_SPEAR) += spear/ obj-y += sprd/ obj-$(CONFIG_ARCH_STI) += st/
drivers/clk/spacemit/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config SPACEMIT_CCU + tristate "Clock support for SpacemiT SoCs" + depends on ARCH_SPACEMIT || COMPILE_TEST + select MFD_SYSCON + help + Say Y to enable clock controller unit support for SpacemiT SoCs. + +if SPACEMIT_CCU + +config SPACEMIT_K1_CCU + tristate "Support for SpacemiT K1 SoC" + depends on ARCH_SPACEMIT || COMPILE_TEST + help + Support for clock controller unit in SpacemiT K1 SoC. + +endif
drivers/clk/spacemit/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_SPACEMIT_K1_CCU) = spacemit-ccu-k1.o +spacemit-ccu-k1-y = ccu_pll.o ccu_mix.o ccu_ddn.o +spacemit-ccu-k1-y += ccu-k1.o
drivers/clk/spacemit/ccu-k1.c new file +1154 -0
1,154 lines not on this page · raw message
drivers/clk/spacemit/ccu_common.h new file +48 -0
48 lines not on this page · raw message
drivers/clk/spacemit/ccu_ddn.c new file +83 -0
83 lines not on this page · raw message
drivers/clk/spacemit/ccu_ddn.h new file +47 -0
47 lines not on this page · raw message
drivers/clk/spacemit/ccu_mix.c new file +268 -0
268 lines not on this page · raw message
drivers/clk/spacemit/ccu_mix.h new file +218 -0
218 lines not on this page · raw message
drivers/clk/spacemit/ccu_pll.c new file +157 -0
157 lines not on this page · raw message
drivers/clk/spacemit/ccu_pll.h new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.49.0
Re: [PATCH v7 3/6] clk: spacemit: Add clock support for SpacemiT K1 SoC
Quoted 5 lines · Haylen Chu
The clock tree of K1 SoC contains three main types of clock hardware (PLL/DDN/MIX) and has control registers split into several multifunction
devices: APBS (PLLs), MPMU, APBC and APMU.All register operations are done through regmap to ensure atomiciy
s/atomiciy/atomicity/
I think Yixun can tweak that for you.
Quoted 4 lines
between concurrent operations of clock driver and reset, power-domain driver that will be introduced in the future.
Signed-off-by Haylen Chu <[email protected]>
This looks good to me!
Quoted 14 lines
--- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/spacemit/Kconfig | 18 + drivers/clk/spacemit/Makefile | 5 + drivers/clk/spacemit/ccu-k1.c | 1154 +++++++++++++++++++++++++++++ drivers/clk/spacemit/ccu_common.h | 48 ++ drivers/clk/spacemit/ccu_ddn.c | 83 +++ drivers/clk/spacemit/ccu_ddn.h | 47 ++ drivers/clk/spacemit/ccu_mix.c | 268 +++++++ drivers/clk/spacemit/ccu_mix.h | 218 ++++++ drivers/clk/spacemit/ccu_pll.c | 157 ++++ drivers/clk/spacemit/ccu_pll.h | 86 +++ 12 files changed, 2086 insertions(+)
Quoted 10 lines
create mode 100644
drivers/clk/spacemit/Kconfigcreate mode 100644drivers/clk/spacemit/Makefilecreate mode 100644drivers/clk/spacemit/ccu-k1.ccreate mode 100644drivers/clk/spacemit/ccu_common.hcreate mode 100644drivers/clk/spacemit/ccu_ddn.ccreate mode 100644drivers/clk/spacemit/ccu_ddn.hcreate mode 100644drivers/clk/spacemit/ccu_mix.ccreate mode 100644drivers/clk/spacemit/ccu_mix.hcreate mode 100644drivers/clk/spacemit/ccu_pll.ccreate mode 100644drivers/clk/spacemit/ccu_pll.h
. . .
Re: [PATCH v7 3/6] clk: spacemit: Add clock support for SpacemiT K1 SoC
Quoted 11 lines · Alex Elder
Quoted 5 lines · Haylen Chu
The clock tree of K1 SoC contains three main types of clock hardware (PLL/DDN/MIX) and has control registers split into several multifunction
devices: APBS (PLLs), MPMU, APBC and APMU.All register operations are done through regmap to ensure atomiciy
s/atomiciy/atomicity/
I think Yixun can tweak that for you.
sure, I will take care of it..
(if there is no more iteration)
Quoted 9 lines
Quoted 4 lines
between concurrent operations of clock driver and reset, power-domain driver that will be introduced in the future.
Signed-off-by Haylen Chu <[email protected]>This looks good to me!
Reviewed-by Alex Elder <[email protected]>
thanks
Signature · 3 lines
Yixun Lan (dlan) Gentoo Linux Developer GPG Key ID AABEFD55
Re: [PATCH v7 3/6] clk: spacemit: Add clock support for SpacemiT K1 SoC
In reply to Haylen ChuQuoted 25 lines · Haylen Chu
The clock tree of K1 SoC contains three main types of clock hardware (PLL/DDN/MIX) and has control registers split into several multifunction
devices: APBS (PLLs), MPMU, APBC and APMU.All register operations are done through regmap to ensure atomiciy between concurrent operations of clock driver and reset, power-domain driver that will be introduced in the future.
Signed-off-by Haylen Chu <[email protected]>--- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/spacemit/Kconfig | 18 + drivers/clk/spacemit/Makefile | 5 + drivers/clk/spacemit/ccu-k1.c | 1154 +++++++++++++++++++++++++++++ drivers/clk/spacemit/ccu_common.h | 48 ++ drivers/clk/spacemit/ccu_ddn.c | 83 +++ drivers/clk/spacemit/ccu_ddn.h | 47 ++ drivers/clk/spacemit/ccu_mix.c | 268 +++++++ drivers/clk/spacemit/ccu_mix.h | 218 ++++++ drivers/clk/spacemit/ccu_pll.c | 157 ++++ drivers/clk/spacemit/ccu_pll.h | 86 +++ 12 files changed, 2086 insertions(+) create mode 100644 drivers/clk/spacemit/Kconfig create mode 100644 drivers/clk/spacemit/Makefile
Quoted 9 lines
create mode 100644 drivers/clk/spacemit/ccu-k1.c create mode 100644 drivers/clk/spacemit/ccu_common.h create mode 100644 drivers/clk/spacemit/ccu_ddn.c create mode 100644 drivers/clk/spacemit/ccu_ddn.h create mode 100644 drivers/clk/spacemit/ccu_mix.c create mode 100644 drivers/clk/spacemit/ccu_mix.h create mode 100644 drivers/clk/spacemit/ccu_pll.c create mode 100644 drivers/clk/spacemit/ccu_pll.h
If possible, split the patch into multiple one by the compatible so others can review easily. Otherwise, it is LGTM.
PATCH v7 4/6 clk: spacemit: k1: Add TWSI8 bus and function clocks
In reply to Haylen ChuThe control register for TWSI8 clocks, APBC_TWSI8_CLK_RST, contains mux selection bits, reset assertion bit and enable bits for function and bus clocks. It has a quirk that reading always results in zero.
As a workaround, let's hardcode the mux value as zero to select pll1_d78_31p5 as parent and treat twsi8_clk as a gate, whose enable mask is combined from the real bus and function clocks to avoid the write-only register being shared between two clk_hws, in which case updates of one clk_hw zero the other's bits.
With a 1:1 factor serving as placeholder for the bus clock, the I2C-8 controller could be brought up, which is essential for boards attaching power-management chips to it.
--- drivers/clk/spacemit/ccu-k1.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/clk/spacemit/ccu-k1.c +10 -0
@@ -328,6 +328,12 @@ CCU_MUX_GATE_DEFINE(twsi4_clk, twsi_parents, APBC_TWSI4_CLK_RST, 4, 3, BIT(1), 0CCU_MUX_GATE_DEFINE (twsi5_clk, twsi_parents,APBC_TWSI5_CLK_RST ,4 ,3 ,BIT (1 ),0 );CCU_MUX_GATE_DEFINE (twsi6_clk, twsi_parents,APBC_TWSI6_CLK_RST ,4 ,3 ,BIT (1 ),0 );CCU_MUX_GATE_DEFINE (twsi7_clk, twsi_parents,APBC_TWSI7_CLK_RST ,4 ,3 ,BIT (1 ),0 ); +/* +* APBC_TWSI8_CLK_RST has a quirk that reading always results in zero. +* Combine functional and bus bits together as a gate to avoid sharing the +* write-only register between different clock hardwares. +*/ +CCU_GATE_DEFINE (twsi8_clk,CCU_PARENT_HW (pll1_d78_31p5),APBC_TWSI8_CLK_RST ,BIT (1 ) |BIT (0 ),0 );static const struct clk_parent_data timer_parents[] = {CCU_PARENT_HW (pll1_d192_12p8),
@@ -412,6 +418,8 @@ CCU_GATE_DEFINE(twsi4_bus_clk, CCU_PARENT_HW(apb_clk), APBC_TWSI4_CLK_RST, BIT(0CCU_GATE_DEFINE (twsi5_bus_clk,CCU_PARENT_HW (apb_clk),APBC_TWSI5_CLK_RST ,BIT (0 ),0 );CCU_GATE_DEFINE (twsi6_bus_clk,CCU_PARENT_HW (apb_clk),APBC_TWSI6_CLK_RST ,BIT (0 ),0 );CCU_GATE_DEFINE (twsi7_bus_clk,CCU_PARENT_HW (apb_clk),APBC_TWSI7_CLK_RST ,BIT (0 ),0 ); +/* Placeholder to workaround quirk of the register */ +CCU_FACTOR_DEFINE (twsi8_bus_clk,CCU_PARENT_HW (apb_clk),1 ,1 );CCU_GATE_DEFINE (timers1_bus_clk,CCU_PARENT_HW (apb_clk),APBC_TIMERS1_CLK_RST ,BIT (0 ),0 );CCU_GATE_DEFINE (timers2_bus_clk,CCU_PARENT_HW (apb_clk),APBC_TIMERS2_CLK_RST ,BIT (0 ),0 );
@@ -896,6 +904,7 @@ static struct clk_hw *k1_ccu_apbc_hws[] = { [CLK_TWSI5] = &twsi5_clk.common.hw, [CLK_TWSI6] = &twsi6_clk.common.hw, [CLK_TWSI7] = &twsi7_clk.common.hw, + [CLK_TWSI8] = &twsi8_clk.common.hw, [CLK_TIMERS1] = &timers1_clk.common.hw, [CLK_TIMERS2] = &timers2_clk.common.hw, [CLK_AIB] = &aib_clk.common.hw,
@@ -947,6 +956,7 @@ static struct clk_hw *k1_ccu_apbc_hws[] = { [CLK_TWSI5_BUS] = &twsi5_bus_clk.common.hw, [CLK_TWSI6_BUS] = &twsi6_bus_clk.common.hw, [CLK_TWSI7_BUS] = &twsi7_bus_clk.common.hw, + [CLK_TWSI8_BUS] = &twsi8_bus_clk.common.hw, [CLK_TIMERS1_BUS] = &timers1_bus_clk.common.hw, [CLK_TIMERS2_BUS] = &timers2_bus_clk.common.hw, [CLK_AIB_BUS] = &aib_bus_clk.common.hw,
Signature · 1 line
2.49.0
PATCH v7 5/6 riscv: dts: spacemit: Add clock tree for SpacemiT K1
In reply to Haylen ChuDescribe the PLL and system controllers that're capable of generating clock signals in the devicetree.
--- arch/riscv/boot/dts/spacemit/k1.dtsi | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
arch/riscv/boot/dts/spacemit/k1.dtsi +75 -0
@@ -3,6 +3,8 @@ * Copyright (C) 2024 Yangyu Chen <[email protected]> */ +#include <dt-bindings/clock/spacemit,k1-syscon.h> + /dts-v1/; / { #address-cells = <2>;
@@ -306,6 +308,36 @@ cluster1_l2_cache: l2-cache1 { }; }; + clocks { + vctcxo_1m: clock-1m { + compatible = "fixed-clock"; + clock-frequency = <1000000>; + clock-output-names = "vctcxo_1m"; + #clock-cells = <0>; + }; + + vctcxo_24m: clock-24m { + compatible = "fixed-clock"; + clock-frequency = <24000000>; + clock-output-names = "vctcxo_24m"; + #clock-cells = <0>; + }; + + vctcxo_3m: clock-3m { + compatible = "fixed-clock"; + clock-frequency = <3000000>; + clock-output-names = "vctcxo_3m"; + #clock-cells = <0>; + }; + + osc_32k: clock-32k { + compatible = "fixed-clock"; + clock-frequency = <32000>; + clock-output-names = "osc_32k"; + #clock-cells = <0>; + }; + }; + soc { compatible = "simple-bus"; interrupt-parent = <&plic>;
@@ -314,6 +346,17 @@ soc { dma-noncoherent; ranges; + syscon_apbc: system-control@d4015000 { + compatible = "spacemit,k1-syscon-apbc"; + reg = <0x0 0xd4015000 0x0 0x1000>; + clocks = <&osc_32k>, <&vctcxo_1m>, <&vctcxo_3m>, + <&vctcxo_24m>; + clock-names = "osc", "vctcxo_1m", "vctcxo_3m", + "vctcxo_24m"; + #clock-cells = <1>; + #reset-cells = <1>; + }; + uart0: serial@d4017000 { compatible = "spacemit,k1-uart", "intel,xscale-uart"; reg = <0x0 0xd4017000 0x0 0x100>;
@@ -409,6 +452,38 @@ pinctrl: pinctrl@d401e000 { reg = <0x0 0xd401e000 0x0 0x400>; }; + syscon_mpmu: system-controller@d4050000 { + compatible = "spacemit,k1-syscon-mpmu"; + reg = <0x0 0xd4050000 0x0 0x209c>; + clocks = <&osc_32k>, <&vctcxo_1m>, <&vctcxo_3m>, + <&vctcxo_24m>; + clock-names = "osc", "vctcxo_1m", "vctcxo_3m", + "vctcxo_24m"; + #clock-cells = <1>; + #power-domain-cells = <1>; + #reset-cells = <1>; + }; + + pll: system-control@d4090000 { + compatible = "spacemit,k1-pll"; + reg = <0x0 0xd4090000 0x0 0x1000>; + clocks = <&vctcxo_24m>; + spacemit,mpmu = <&syscon_mpmu>; + #clock-cells = <1>; + }; + + syscon_apmu: system-control@d4282800 { + compatible = "spacemit,k1-syscon-apmu"; + reg = <0x0 0xd4282800 0x0 0x400>; + clocks = <&osc_32k>, <&vctcxo_1m>, <&vctcxo_3m>, + <&vctcxo_24m>; + clock-names = "osc", "vctcxo_1m", "vctcxo_3m", + "vctcxo_24m"; + #clock-cells = <1>; + #power-domain-cells = <1>; + #reset-cells = <1>; + }; + plic: interrupt-controller@e0000000 { compatible = "spacemit,k1-plic", "sifive,plic-1.0.0"; reg = <0x0 0xe0000000 0x0 0x4000000>;
Signature · 1 line
2.49.0
PATCH v7 6/6 riscv: defconfig: spacemit: enable clock controller driver for SpacemiT K1
In reply to Haylen ChuClock controller unit, or CCU, generates various clocks frequency for peripherals integrated in SpacemiT K1 SoC and is essential for normal operation. Let's enable it as built-in driver in defconfig.
--- arch/riscv/configs/defconfig | 2 ++ 1 file changed, 2 insertions(+)
arch/riscv/configs/defconfig +2 -0
@@ -250,6 +250,8 @@ CONFIG_CLK_SOPHGO_CV1800=y CONFIG_CLK_SOPHGO_SG2042_PLL=y CONFIG_CLK_SOPHGO_SG2042_CLKGEN=y CONFIG_CLK_SOPHGO_SG2042_RPGATE=y +CONFIG_SPACEMIT_CCU=y +CONFIG_SPACEMIT_K1_CCU=y CONFIG_SUN8I_DE2_CCU=m CONFIG_SUN50I_IOMMU=y CONFIG_RPMSG_CHAR=y
Signature · 1 line
2.49.0
Re: [PATCH v7 6/6] riscv: defconfig: spacemit: enable clock controller driver for SpacemiT K1
Quoted 5 lines · Haylen Chu
Clock controller unit, or CCU, generates various clocks frequency for peripherals integrated in SpacemiT K1 SoC and is essential for normal operation. Let's enable it as built-in driver in defconfig.
Signed-off-by Haylen Chu <[email protected]>
I know Inochi wanted this to be "m", but you can see that SOPHGO sets it to "y". Meanwhile SIFIVE uses a default value for its CLK_SIFIVE and CLK_SIFIVE_PRCI config options.
I'm not going to solve this, so I'll just say this looks good.
Quoted 17 lines
--- arch/riscv/configs/defconfig | 2 ++ 1 file changed, 2 insertions(+)arch/riscv/configs/defconfig +2
-0@@ -250,6 +250,8 @@ CONFIG_CLK_SOPHGO_CV1800=y CONFIG_CLK_SOPHGO_SG2042_PLL=y CONFIG_CLK_SOPHGO_SG2042_CLKGEN=y CONFIG_CLK_SOPHGO_SG2042_RPGATE=y +CONFIG_SPACEMIT_CCU=y +CONFIG_SPACEMIT_K1_CCU=y CONFIG_SUN8I_DE2_CCU=m CONFIG_SUN50I_IOMMU=y CONFIG_RPMSG_CHAR=y
Re: [PATCH v7 6/6] riscv: defconfig: spacemit: enable clock controller driver for SpacemiT K1
Quoted 5 lines · Alex Elder
Quoted 4 lines · Haylen Chu
Clock controller unit, or CCU, generates various clocks frequency for peripherals integrated in SpacemiT K1 SoC and is essential for normal operation. Let's enable it as built-in driver in defconfig.
Quoted 9 lines
Quoted 1 line
Signed-off-by Haylen Chu <[email protected]>I know Inochi wanted this to be "m", but you can see that SOPHGO sets it to "y". Meanwhile SIFIVE uses a default value for its
CLK_SIFIVEandCLK_SIFIVE_PRCIconfig options.I'm not going to solve this, so I'll just say this looks good.
The clock and pinctrl are exceptions for me, It is OK for me to set "y" for these two device in defconfig. The thing I only asked for is a tristate entry in the kconfig, so we can go with a module if necessary.
Regards,
Inochi
Hi Haylen Chu:
I'm quite happy with this version, as all the issues are solved,
Thanks for working on this. I will give my RY and start to queue them.
Hi Stephen Boyd,
My plan to send a PR for inclusion to the clk tree in the 6.16
merge window. But, let me know if there is still problem I overlooked.
Quoted 19 lines · Haylen Chu
The clock tree of SpacemiT K1 is managed by several independent multifunction devices, some of them are
- Application Power Manage Unit, APMU
- Main Power Manage Unit, MPMU
- APB Bus Clock Unit, APBC
- APB Spare, APBSThese four devices provide hardware bits for three purposes: power management, reset signals and clocks. Not every device is capable of all the three functionalities,
- APMU, MPMU: power, reset, clock
- APBC: clock, reset
- APBS: clock (PLL clocks)This series adds support for clock hardwares in these four regions, which covers most peripherals except DDR and the realtime processor.
Quoted 7 lines
Tested on BananaPi-F3 board. With some out-of-tree drivers, I've successfully brought up I2C, RTC, MMC and ethernet controllers.
It has been a very long time since I sent v1 of the series, thanks for everyone making suggestions and keeping track. I'm looking forward for furthermore reviews, or getting it finally merged.
for the whole series
Quoted 196 lines
Changed from v6
- Update copyright date
- Collect reviewed-by tags
- k1-pll binding
- replace tabs with space in binding header
- driver
- remove the file accidentally added in v6
- remove undesired rates from PLL2 configuration entries
- update comment for PLL{1,2} rates
- misc style changes
- removeCLK_IS_CRITICALfrom uart0 clocks andcpu_c1_hi_clk
- TWSI8 support
- Add a comment to describe the quirk
- defconfig change
- improve the commit message
- Link to v6: https://lore.kernel.org/all/[email protected]/Changed from v5
- Correct "Spacemit" to "SpacemiT" in commit messages and code
- Always use space instead of TAB in comments for consistency
- dt-bindings
- Rename binding header to "spacemit,k1-syscon.h"
- apply review tags
- driver code
- remove "default" properties fromKconfig
- misc style and naming improvements
- makeccu_read()directly return the read value, dropccu_poll()and reorder the arguments to ccu_{read,update} macros
- drop ccu_common.reg_swcr2
- clock tree for K1
- define PLL3 with the correct offset of SWCR3 register
- synchronize PLL configuration entries with the vendor kernel
- reformat clocks definitions
- explain why PLLs require the MPMU syscon to function
- log a message when failing to register a clock
- simplify clock registration withARRAY_SIZE()
- ddn
- correctly handle masks which doesn't start from BIT(0) when calculating the best rate
- improve precision of frequency calculation
- derive _{den,num}_shift from corresponding masks with__ffs()
- mix
- match the full mask of gate inccu_gate_is_enabled()
- add a note about "frequency change" bit and simplify FC-triggering logic
- drop unnecessary local variables and initialization from clock operations
- round to the closest rate inccu_mix_calc_best_rate()
- change names of all mix subtypes to follow the order of mux -> factor/div -> gate -> fc
- drop unused_flagsargument fromCCU_GATE_FACTOR_DEFINE()
- pll
- ensure PLLs are initialized to a known state
- drop extra check inccu_pll_enable()
- round to the closest rate inccu_pll_round_rate()
- TWSI8 support
- Split cleanly from the main driver commit
- devicetree
- drop extra "*-cells" and "ranges" properties
- Enable SpacemiT K1 CCU in RISC-V defconfig
- Link to v5: https://lore.kernel.org/all/[email protected]/Changed from v4
- bindings:
- Drop CLK_*_NUM macros from binding headers
- Rename spacemit,k1-ccu.yaml to spacemit,k1-pll.yaml, change to describe only the PLL in APBS region
-k1-syscon.yaml
- drop spacemit,k1-syscon-apbs, it should be the PLL device
- drop child nodes
- describe the syscons as clock, reset and power-domain controllers
- drop "syscon" from the compatible list, as these syscons aren't compatible with the generic one
- driver:
- misc style fixes and naming improvements
- drop unused fields from data structures
- drop unused clock types:CCU_DDN_GATE
- ddn type:
- improve the comments
- dynamically calculate appropriate rates
- hardcode the x2 factor
- mix type
- drop val_{disable,enable} for gate subtype
- drop unncessary polling when enabling a gate
- encode subtypes directly in structccu_mix
- generate clock names from identifiers of the data structure
- renameCCU_DIV2_FC_MUX_GATE_DEFINEtoCCU_DIV_SPLIT_FC_MUX_GATE
- pll type:
- correctly claim the parent clock
- make rate tables const
- drop SWCR2-related fields
- combine fields of registers as a whole instead of working with each field
- clock tree for k1:
- removed duplicated offsets
- drop the placeholder 1:1 factor,pll1_d7_351p8
- workaround the quirk of TWSI8 clocks
- fix the definition ofripc_clk,wdt_bus_clk,dpu_bit_clkand timers_*_clk
- drop structurespacemit_ccu_privandspacemit_ccu_data
- rework clock registration
- split the PCIe clocks correctly (there're three distinct clocks for each PCIe port)
- devicetree:
- adapt the new binding
- Link to v4: https://lore.kernel.org/all/[email protected]/Changed from v3
- spacemit,k1-ccu binding
- allow spacemit,mpmu property only for controllers requiring it(spacemit,k1-ccu-apbs)- spacemit,k1-syscon binding
- drop unnecessary *-cells properties
- drop unrelated nodes in the example
- driver
- remove unnecessary divisions during rate calucalation inccu_ddn.c
- use independentclk_opsfor different ddn/mix variants, dropreg_typefield in structccu_common
- make the register containing frequency change bit a sperate field inccu_common
- unifyDIV_MFC_MUX_GATEandDIV_FC_MUX_GATE
- implement a correctdetermine_rate()for mix type
- avoid reparenting inset_rate()for mix type
- fix build failure whenSPACEMIT_CCUandSPACEMIT_CCU_K1are configured differently
- use "osc" instead of "osc_32k" in clock input names
- misc style fixes
- Link to v3: https://lore.kernel.org/all/[email protected]/Changed from v2
- dt-binding fixes
- drop clocks marked as deprecated by the vendor (CLK_JPF_4KAFBCandCLK_JPF_2KAFBC)- add binding of missing bus clocks
- change input clocks to use frequency-aware and more precise names
- mark input clocks and their names as required
- move the example to the (parent) syscon node and complete it
- misc style fixes
- misc improvements in code
- drop unnecessary spinlock in the driver
- implement missing bus clocks
- Link to v2: https://lore.kernel.org/all/SEYPR01MB4221829A2CD4D4C1704BABD7D7602@SEYPR01MB4221.apcprd01.prod.exchangelabs.com/Changed from v1
- add SoC prefix (k1)
- relicense dt-binding header
- misc fixes and style improvements for dt-binding
- document spacemit,k1-syscon
- implement all APBS, MPMU, APBC and APMU clocks
- code cleanup
- Link to v1: https://lore.kernel.org/all/SEYPR01MB4221B3178F5233EAB5149E41D7902@SEYPR01MB4221.apcprd01.prod.exchangelabs.com/Haylen Chu (6):
dt-bindings: soc: spacemit: Add spacemit,k1-syscon
dt-bindings: clock: spacemit: Add spacemit,k1-pll
clk: spacemit: Add clock support for SpacemiT K1 SoC
clk: spacemit: k1: Add TWSI8 bus and function clocks
riscv: dts: spacemit: Add clock tree for SpacemiT K1
riscv: defconfig: spacemit: enable clock controller driver for
SpacemiT K1.../bindings/clock/spacemit,k1-pll.yaml | 50 + .../soc/spacemit/spacemit,k1-syscon.yaml | 80 ++ arch/riscv/boot/dts/spacemit/k1.dtsi | 75 ++ arch/riscv/configs/defconfig | 2 + drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/spacemit/Kconfig | 18 + drivers/clk/spacemit/Makefile | 5 + drivers/clk/spacemit/ccu-k1.c | 1164 +++++++++++++++++ drivers/clk/spacemit/ccu_common.h | 48 + drivers/clk/spacemit/ccu_ddn.c | 83 ++ drivers/clk/spacemit/ccu_ddn.h | 47 + drivers/clk/spacemit/ccu_mix.c | 268 ++++ drivers/clk/spacemit/ccu_mix.h | 218 +++ drivers/clk/spacemit/ccu_pll.c | 157 +++ drivers/clk/spacemit/ccu_pll.h | 86 ++ .../dt-bindings/clock/spacemit,k1-syscon.h | 247 ++++ 17 files changed, 2550 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/spacemit,k1-pll.yaml create mode 100644 Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml create mode 100644 drivers/clk/spacemit/Kconfig create mode 100644 drivers/clk/spacemit/Makefile create mode 100644 drivers/clk/spacemit/ccu-k1.c create mode 100644 drivers/clk/spacemit/ccu_common.h create mode 100644 drivers/clk/spacemit/ccu_ddn.c create mode 100644 drivers/clk/spacemit/ccu_ddn.h create mode 100644 drivers/clk/spacemit/ccu_mix.c create mode 100644 drivers/clk/spacemit/ccu_mix.h create mode 100644 drivers/clk/spacemit/ccu_pll.c create mode 100644 drivers/clk/spacemit/ccu_pll.h create mode 100644 include/dt-bindings/clock/spacemit,k1-syscon.hSignature · 1 line
2.49.0
Signature · 3 lines
Yixun Lan (dlan) Gentoo Linux Developer GPG Key ID AABEFD55
Stephen Boyd
maintainerQuoting Yixun Lan (2025-04-14 17:46:12)
Quoted 7 lines
Hi Haylen Chu:
I'm quite happy with this version, as all the issues are solved,
Thanks for working on this. I will give my RY and start to queue them.Hi Stephen Boyd,
My plan to send a PR for inclusion to the clk tree in the 6.16
merge window. But, let me know if there is still problem I overlooked.
You should send the code now. The merge window is when subsystem maintainers like me send code to Linus, not when SoC maintainers send code to subsystem maintainers. Typically folks wait until around -rc5 or -rc6 to send it for the next merge window.
Hi Stephen,
Quoted 10 lines · Stephen Boyd
Quoting Yixun Lan (2025-04-14 17:46:12)
Quoted 7 lines
Hi Haylen Chu:
I'm quite happy with this version, as all the issues are solved,
Thanks for working on this. I will give my RY and start to queue them.Hi Stephen Boyd,
My plan to send a PR for inclusion to the clk tree in the 6.16
merge window. But, let me know if there is still problem I overlooked.You should send the code now.
Ok, will do
Quoted 3 lines
The merge window is when subsystem
maintainers like me send code to Linus, not when SoC maintainers send code to subsystem maintainers.
Sorry, I was not precise on this. the PR should target for v6.16 via clk tree
Quoted 2 lines
Typically folks wait until around -rc5 or
-rc6 to send it for the next merge window.
Thanks for the information, I was planning to send a PR to you (clk maintainer) at v6.15-rc6 which should eventually merged into v6.16 ..
Signature · 1 line
Yixun Lan (dlan)