arm64: allwinner: a523: Enable CPU clocks
Subsystems (3)
cover arm64: allwinner: a523: Enable CPU clocks
Hi,
this series adds support for the CPU clock controller in the Allwinner A523/A527/T527 family of SoCs.
In contrast to all earlier Allwinner SoCs, this chip features a separate CCU for the CPU clocks (one for each of the two clusters) and the DSU clock.
Patch 1/5 adds the binding document for the new CCU. This builds on top of Chen-Yu's recent patch for the MCU PRCM, listed as a prerequisite below.
Patch 2 and 3 add some slight enhancements to the sunxi-ng clock driver framework, to generalise the update bit and allow clocks with just a power-of-2 divider.
Patch 4 adds the actual clock driver, and patch 5 makes use of that by adding the clock description to the SoC .dtsi.
Please have a look and test!
Cheers,
Andre
Andre Przywara (5):
dt-bindings: clock: sun55i-a523-ccu: Add A523 CPU CCU clock controller
clk: sunxi-ng: generalise update bit
clk: sunxi-ng: mp: support clocks with just a shift register
clk: sunxi-ng: add support for the A523/T527 CPU CCU
arm64: dts: allwinner: a523: add CPU clocks
.../clock/allwinner,sun55i-a523-ccu.yaml | 25 ++ .../arm64/boot/dts/allwinner/sun55i-a523.dtsi | 22 ++ drivers/clk/sunxi-ng/Kconfig | 5 + drivers/clk/sunxi-ng/Makefile | 2 + drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.c | 338 ++++++++++++++++++ drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.h | 24 ++ drivers/clk/sunxi-ng/ccu-sun55i-a523.c | 12 +- drivers/clk/sunxi-ng/ccu_common.h | 5 +- drivers/clk/sunxi-ng/ccu_div.c | 3 +- drivers/clk/sunxi-ng/ccu_gate.c | 6 +- drivers/clk/sunxi-ng/ccu_mp.c | 6 +- drivers/clk/sunxi-ng/ccu_mp.h | 8 +- drivers/clk/sunxi-ng/ccu_mux.c | 3 +- drivers/clk/sunxi-ng/ccu_nm.c | 1 + .../dt-bindings/clock/sun55i-a523-cpu-ccu.h | 13 + 15 files changed, 450 insertions(+), 23 deletions(-) create mode 100644 drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.c create mode 100644 drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.h create mode 100644 include/dt-bindings/clock/sun55i-a523-cpu-ccu.h
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
prerequisite-patch-id: 874f647e4961983cbcfda05d2fd906256b008327
Signature · 1 line
2.46.3
PATCH 1/5 dt-bindings: clock: sun55i-a523-ccu: Add A523 CPU CCU clock controller
There are four clock controllers in the A523 SoC, but only three are described in the DT binding so far.
Add a description for the CPU CCU, which provides separate clocks for the two CPU clusters and the DSU interconnect.
--- .../clock/allwinner,sun55i-a523-ccu.yaml | 25 +++++++++++++++++++ .../dt-bindings/clock/sun55i-a523-cpu-ccu.h | 13 ++++++++++ 2 files changed, 38 insertions(+) create mode 100644 include/dt-bindings/clock/sun55i-a523-cpu-ccu.h
Documentation/devicetree/bindings/clock/allwinner,sun55i-a523-ccu.yaml +25 -0
@@ -19,6 +19,7 @@ properties: compatible: enum: - allwinner,sun55i-a523-ccu + - allwinner,sun55i-a523-cpu-ccu - allwinner,sun55i-a523-mcu-ccu - allwinner,sun55i-a523-r-ccu
@@ -64,6 +65,30 @@ allOf: - const: iosc - const: losc-fanout + - if: + properties: + compatible: + enum: + - allwinner,sun55i-a523-cpu-ccu + + then: + properties: + clocks: + items: + - description: High Frequency Oscillator (usually at 24MHz) + - description: Low Frequency Oscillator (usually at 32kHz) + - description: Internal Oscillator + - description: Peripherals PLL 0 (1200 MHz output) + - description: Peripherals PLL 0 (600 MHz output) + + clock-names: + items: + - const: hosc + - const: losc + - const: iosc + - const: pll-periph0-2x + - const: pll-periph0-600m + - if: properties: compatible:
include/dt-bindings/clock/sun55i-a523-cpu-ccu.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR MIT) */ +/* +* Copyright 2025 Arm Ltd. +*/ + +#ifndef _DT_BINDINGS_CLK_SUN55I_A523_CPU_CCU_H_ +#define _DT_BINDINGS_CLK_SUN55I_A523_CPU_CCU_H_ + +#define CLK_CPU_L 7 +#define CLK_CPU_DSU 8 +#define CLK_CPU_B 9 + +#endif /* _DT_BINDINGS_CLK_SUN55I_A523_CPU_CCU_H_ */
Signature · 1 line
2.46.3
Re: [PATCH 1/5] dt-bindings: clock: sun55i-a523-ccu: Add A523 CPU CCU clock controller
include/dt-bindings/clock/sun55i-a523-cpu-ccu.h
Quoted 61 lines · Andre Przywara
There are four clock controllers in the A523 SoC, but only three are described in the DT binding so far.
Add a description for the CPU CCU, which provides separate clocks for the two CPU clusters and the DSU interconnect.
Signed-off-by Andre Przywara <[email protected]>--- .../clock/allwinner,sun55i-a523-ccu.yaml | 25 +++++++++++++++++++ .../dt-bindings/clock/sun55i-a523-cpu-ccu.h | 13 ++++++++++ 2 files changed, 38 insertions(+) create mode 100644 include/dt-bindings/clock/sun55i-a523-cpu-ccu.hDocumentation/devicetree/bindings/clock/allwinner,sun55i-a523-ccu.yaml +25
-0@@ -19,6 +19,7 @@ properties: compatible: enum: - allwinner,sun55i-a523-ccu + - allwinner,sun55i-a523-cpu-ccu - allwinner,sun55i-a523-mcu-ccu - allwinner,sun55i-a523-r-ccu@@ -64,6 +65,30 @@ allOf: - const: iosc - const: losc-fanout + - if: + properties: + compatible: + enum: + - allwinner,sun55i-a523-cpu-ccu + + then: + properties: + clocks: + items: + - description: High Frequency Oscillator (usually at 24MHz) + - description: Low Frequency Oscillator (usually at 32kHz) + - description: Internal Oscillator + - description: Peripherals PLL 0 (1200 MHz output) + - description: Peripherals PLL 0 (600 MHz output) + + clock-names: + items: + - const: hosc + - const: losc + - const: iosc + - const: pll-periph0-2x + - const: pll-periph0-600m + - if: properties: compatible:include/dt-bindings/clock/sun55i-a523-cpu-ccu.h new file +0
-0
Filename based on compatible.
include/dt-bindings/clock/sun55i-a523-cpu-ccu.h line 11
Quoted 12 lines
include/dt-bindings/clock/sun55i-a523-cpu-ccu.h new file +11
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR MIT) */ +/* +* Copyright 2025 Arm Ltd. +*/ + +#ifndef _DT_BINDINGS_CLK_SUN55I_A523_CPU_CCU_H_ +#define _DT_BINDINGS_CLK_SUN55I_A523_CPU_CCU_H_ + +#define CLK_CPU_L 7 +#define CLK_CPU_DSU 8 +#define CLK_CPU_B 9
I don't see the header being used by the driver and odd numbers (they should start from 0 or 1) suggest these are not bindings.
Otherwise please explain in commit msg what exactly are you binding here.
Best regards,
Krzysztof
Re: [PATCH 1/5] dt-bindings: clock: sun55i-a523-ccu: Add A523 CPU CCU clock controller
On Wed, 3 Sep 2025 10:08:33 +0200
Krzysztof Kozlowski <[email protected]> wrote:
Hi,
Quoted 66 lines · Andre Przywara
include/dt-bindings/clock/sun55i-a523-cpu-ccu.h
Quoted 61 lines
There are four clock controllers in the A523 SoC, but only three are described in the DT binding so far.
Add a description for the CPU CCU, which provides separate clocks for the two CPU clusters and the DSU interconnect.
Signed-off-by Andre Przywara <[email protected]>--- .../clock/allwinner,sun55i-a523-ccu.yaml | 25 +++++++++++++++++++ .../dt-bindings/clock/sun55i-a523-cpu-ccu.h | 13 ++++++++++ 2 files changed, 38 insertions(+) create mode 100644 include/dt-bindings/clock/sun55i-a523-cpu-ccu.hDocumentation/devicetree/bindings/clock/allwinner,sun55i-a523-ccu.yaml +25
-0@@ -19,6 +19,7 @@ properties: compatible: enum: - allwinner,sun55i-a523-ccu + - allwinner,sun55i-a523-cpu-ccu - allwinner,sun55i-a523-mcu-ccu - allwinner,sun55i-a523-r-ccu@@ -64,6 +65,30 @@ allOf: - const: iosc - const: losc-fanout + - if: + properties: + compatible: + enum: + - allwinner,sun55i-a523-cpu-ccu + + then: + properties: + clocks: + items: + - description: High Frequency Oscillator (usually at 24MHz) + - description: Low Frequency Oscillator (usually at 32kHz) + - description: Internal Oscillator + - description: Peripherals PLL 0 (1200 MHz output) + - description: Peripherals PLL 0 (600 MHz output) + + clock-names: + items: + - const: hosc + - const: losc + - const: iosc + - const: pll-periph0-2x + - const: pll-periph0-600m + - if: properties: compatible:include/dt-bindings/clock/sun55i-a523-cpu-ccu.h new file +0
-0Filename based on compatible.
Quoted 15 lines
include/dt-bindings/clock/sun55i-a523-cpu-ccu.h line 11
Quoted 12 lines
include/dt-bindings/clock/sun55i-a523-cpu-ccu.h new file +11
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR MIT) */ +/* +* Copyright 2025 Arm Ltd. +*/ + +#ifndef _DT_BINDINGS_CLK_SUN55I_A523_CPU_CCU_H_ +#define _DT_BINDINGS_CLK_SUN55I_A523_CPU_CCU_H_ + +#define CLK_CPU_L 7 +#define CLK_CPU_DSU 8 +#define CLK_CPU_B 9I don't see the header being used by the driver and odd numbers (they should start from 0 or 1) suggest these are not bindings.
This header is included by the private header (at the end of patch 4/5). The private header is then included by the driver.
Happy to change that, but that's the pattern used in all the other drivers.
Those numbers represent the publicly exposed clocks, the other clocks are internal. Having gaps in those numbers is somewhat common in sunxi-ng (check sun50i-h616-ccu.h). This large gap at the beginning here is mostly due to the somewhat extreme design of this CCU, which requires quite some helper clocks to get to the actual ones.
We could sort the identifiers to have the public clocks first, but that would only be the case until we discover a missed clock (which seems to happen from times to times). And again, that's the pattern used in the sibling drivers, so I'd rather stay consistent here.
Cheers,
Andre
Quoted 6 lines
Otherwise please explain in commit msg what exactly are you binding here.
Best regards,
Krzysztof
Re: [PATCH 1/5] dt-bindings: clock: sun55i-a523-ccu: Add A523 CPU CCU clock controller
Quoted 18 lines · Andre Przywara
Quoted 17 lines
Quoted 4 lines
include/dt-bindings/clock/sun55i-a523-cpu-ccu.h new file +1
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR MIT) */ include/dt-bindings/clock/sun55i-a523-cpu-ccu.h line 11
Quoted 10 lines
include/dt-bindings/clock/sun55i-a523-cpu-ccu.h new file +10
-0+/* +* Copyright 2025 Arm Ltd. +*/ + +#ifndef _DT_BINDINGS_CLK_SUN55I_A523_CPU_CCU_H_ +#define _DT_BINDINGS_CLK_SUN55I_A523_CPU_CCU_H_ + +#define CLK_CPU_L 7 +#define CLK_CPU_DSU 8 +#define CLK_CPU_B 9I don't see the header being used by the driver and odd numbers (they should start from 0 or 1) suggest these are not bindings.
Quoted 2 lines
This header is included by the private header (at the end of patch 4/5). The private header is then included by the driver.
Ah, I see now.
Quoted 1 line
Best regards,
Krzysztof
PATCH 2/5 clk: sunxi-ng: generalise update bit
In reply to Andre PrzywaraA few of the Allwinner A523 CCU clock registers introduced an "update" bit, which must be set for changes to the other bits to take effect. Of the three clocks where this was used, it was always bit 27, so we just encoded this as a single bit feature flag.
Now the CPU PLL also features the update bit, but puts it at bit 26, so this flag trick won't work anymore.
Add an "update_bit" field to the common sunxi clock struct, which takes a bitmask, so we can encode any bit to use, even potentially multiple of them. As uninitialised fields are set to 0, we can use this as a default bitmask to set, so can OR this in unconditionally.
Change the existing update bit users to use this new encoding, and add support for the ccu_nm clock on the way, since we will need it there shortly.
--- drivers/clk/sunxi-ng/ccu-sun55i-a523.c | 12 ++++++------ drivers/clk/sunxi-ng/ccu_common.h | 5 +---- drivers/clk/sunxi-ng/ccu_div.c | 3 +-- drivers/clk/sunxi-ng/ccu_gate.c | 6 ++---- drivers/clk/sunxi-ng/ccu_mp.h | 8 +++++--- drivers/clk/sunxi-ng/ccu_mux.c | 3 +-- drivers/clk/sunxi-ng/ccu_nm.c | 1 + 7 files changed, 17 insertions(+), 21 deletions(-)
drivers/clk/sunxi-ng/ccu-sun55i-a523.c +6 -6
@@ -385,8 +385,8 @@ static SUNXI_CCU_MP_DATA_WITH_MUX_GATE_FEAT(mbus_clk, "mbus", mbus_parents,0 ,0 ,/* no P */ 24 ,3 ,/* mux */ BIT (31 ),/* gate */ -CLK_IS_CRITICAL , - CCU_FEATURE_UPDATE_BIT); +BIT (27 ),/* update*/ + CLK_IS_CRITICAL, 0);static const struct clk_hw *mbus_hws[] = { &mbus_clk.common.hw };
@@ -577,8 +577,8 @@ static SUNXI_CCU_MP_DATA_WITH_MUX_GATE_FEAT(iommu_clk, "iommu", iommu_parents,0 ,0 ,/* no P */ 24 ,3 ,/* mux */ BIT (31 ),/* gate */ -CLK_SET_RATE_PARENT , - CCU_FEATURE_UPDATE_BIT); +BIT (27 ),/* update */ + CLK_SET_RATE_PARENT, 0); static SUNXI_CCU_GATE_HWS(bus_iommu_clk, "bus-iommu", apb0_hws, 0x7bc, BIT(0), 0);
@@ -596,8 +596,8 @@ static SUNXI_CCU_MP_DATA_WITH_MUX_GATE_FEAT(dram_clk, "dram", dram_parents,0 ,0 ,/* no P */ 24 ,3 ,/* mux */ BIT (31 ),/* gate */ -CLK_IS_CRITICAL , - CCU_FEATURE_UPDATE_BIT); +BIT (27 ),/* update*/ + CLK_IS_CRITICAL, 0); static SUNXI_CCU_GATE_HWS(mbus_dma_clk, "mbus-dma", mbus_hws, 0x804, BIT(0), 0);
drivers/clk/sunxi-ng/ccu_common.h +1 -4
@@ -20,14 +20,10 @@#define CCU_FEATURE_KEY_FIELD BIT(8)#define CCU_FEATURE_CLOSEST_RATE BIT(9)#define CCU_FEATURE_DUAL_DIV BIT(10) -#define CCU_FEATURE_UPDATE_BIT BIT(11)/* MMC timing mode switch bit */ #define CCU_MMC_NEW_TIMING_MODE BIT(30) -/* Some clocks need this bit to actually apply register changes */ -#define CCU_SUNXI_UPDATE_BIT BIT(27) -struct device_node ;struct ccu_common {
@@ -35,6 +31,7 @@ struct ccu_common {u16 reg;u16 lock_reg;u32 prediv; +u32 update_bit;unsigned long min_rate;unsigned long max_rate;
drivers/clk/sunxi-ng/ccu_div.c +1 -2
@@ -106,8 +106,7 @@ static int ccu_div_set_rate(struct clk_hw *hw, unsigned long rate, reg =readl (cd->common.base + cd->common.reg); reg &= ~GENMASK (cd->div.width + cd->div.shift -1 , cd->div.shift); -if (cd->common.features &CCU_FEATURE_UPDATE_BIT ) - reg |=CCU_SUNXI_UPDATE_BIT ; + reg |= cd->common.update_bit;writel (reg | (val << cd->div.shift), cd->common.base + cd->common.reg);
drivers/clk/sunxi-ng/ccu_gate.c +2 -4
@@ -20,8 +20,7 @@ void ccu_gate_helper_disable(struct ccu_common *common, u32 gate)spin_lock_irqsave (common->lock, flags); reg =readl (common->base + common->reg); -if (common->features &CCU_FEATURE_UPDATE_BIT ) - reg |=CCU_SUNXI_UPDATE_BIT ; + reg |= common->update_bit;writel (reg & ~gate, common->base + common->reg);spin_unlock_irqrestore (common->lock, flags);
@@ -46,8 +45,7 @@ int ccu_gate_helper_enable(struct ccu_common *common, u32 gate)spin_lock_irqsave (common->lock, flags); reg =readl (common->base + common->reg); -if (common->features &CCU_FEATURE_UPDATE_BIT ) - reg |=CCU_SUNXI_UPDATE_BIT ; + reg |= common->update_bit;writel (reg | gate, common->base + common->reg);spin_unlock_irqrestore (common->lock, flags);
drivers/clk/sunxi-ng/ccu_mp.h +5 -3
@@ -131,7 +131,8 @@ struct ccu_mp { _mshift, _mwidth, \ _pshift, _pwidth, \ _muxshift, _muxwidth, \ - _gate, _flags, _features) \ + _gate, _update, \ + _flags, _features) \ struct ccu_mp _struct = { \ .enable = _gate, \ .m =_SUNXI_CCU_DIV (_mshift, _mwidth), \
@@ -140,6 +141,7 @@ struct ccu_mp { .common = { \ .reg = _reg, \ .features = _features, \ + .update_bit = _update, \ .hw.init = CLK_HW_INIT_PARENTS_DATA(_name, \ _parents, \ &ccu_mp_ops, \
@@ -156,7 +158,7 @@ struct ccu_mp { _reg, _mshift, _mwidth, \ _pshift, _pwidth, \ _muxshift, _muxwidth, \ - _gate, _flags, 0) + _gate, 0, _flags, 0) #define SUNXI_CCU_DUALDIV_MUX_GATE(_struct, _name, _parents, _reg, \ _mshift, _mwidth, \
@@ -167,7 +169,7 @@ struct ccu_mp { _reg, _mshift, _mwidth, \ _pshift, _pwidth, \ _muxshift, _muxwidth, \ - _gate, _flags, \ + _gate, 0, _flags, \ CCU_FEATURE_DUAL_DIV) #define SUNXI_CCU_MP_DATA_WITH_MUX(_struct, _name, _parents, _reg, \
drivers/clk/sunxi-ng/ccu_mux.c +1 -2
@@ -197,8 +197,7 @@ int ccu_mux_helper_set_parent(struct ccu_common *common,/* The key field always reads as zero. */ if (common->features &CCU_FEATURE_KEY_FIELD ) reg |=CCU_MUX_KEY_VALUE ; -if (common->features &CCU_FEATURE_UPDATE_BIT ) - reg |=CCU_SUNXI_UPDATE_BIT ; + reg |= common->update_bit; reg &= ~GENMASK (cm->width + cm->shift -1 , cm->shift);writel (reg | (index << cm->shift), common->base + common->reg);
drivers/clk/sunxi-ng/ccu_nm.c +1 -0
@@ -219,6 +219,7 @@ static int ccu_nm_set_rate(struct clk_hw *hw, unsigned long rate, reg |= (_nm.n - nm->n.offset) << nm->n.shift; reg |= (_nm.m - nm->m.offset) << nm->m.shift; + reg |= nm->common.update_bit;writel (reg, nm->common.base + nm->common.reg);spin_unlock_irqrestore (nm->common.lock, flags);
Signature · 1 line
2.46.3
Re: [PATCH 2/5] clk: sunxi-ng: generalise update bit
Quoted 14 lines · Andre Przywara
A few of the Allwinner A523 CCU clock registers introduced an "update" bit, which must be set for changes to the other bits to take effect. Of the three clocks where this was used, it was always bit 27, so we just encoded this as a single bit feature flag.
Now the CPU PLL also features the update bit, but puts it at bit 26, so this flag trick won't work anymore.
Add an "
update_bit" field to the common sunxi clock struct, which takes a bitmask, so we can encode any bit to use, even potentially multiple of them. As uninitialised fields are set to 0, we can use this as a default bitmask to set, so can OR this in unconditionally.
Quoted 5 lines
Change the existing update bit users to use this new encoding, and add support for the
ccu_nmclock on the way, since we will need it there shortly.Signed-off-by Andre Przywara <[email protected]>
Re: [PATCH 2/5] clk: sunxi-ng: generalise update bit
Quoted 16 lines · Chen-Yu Tsai
Quoted 14 lines · Andre Przywara
A few of the Allwinner A523 CCU clock registers introduced an "update" bit, which must be set for changes to the other bits to take effect. Of the three clocks where this was used, it was always bit 27, so we just encoded this as a single bit feature flag.
Now the CPU PLL also features the update bit, but puts it at bit 26, so this flag trick won't work anymore.
Add an "
update_bit" field to the common sunxi clock struct, which takes a bitmask, so we can encode any bit to use, even potentially multiple of them. As uninitialised fields are set to 0, we can use this as a default bitmask to set, so can OR this in unconditionally.
Quoted 7 lines
Quoted 5 lines
Change the existing update bit users to use this new encoding, and add support for the
ccu_nmclock on the way, since we will need it there shortly.Signed-off-by Andre Przywara <[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>
Hmm, actually, we also have the "key field" feature. Maybe we should generalize that one and merge the two?
What do you think?
ChenYu
Re: [PATCH 2/5] clk: sunxi-ng: generalise update bit
Quoted 21 lines · On Wed, 10 Sep 2025 00:06:07 +0800 Chen-Yu Tsai <[email protected]> wrote:
Quoted 20 lines · Chen-Yu Tsai
Quoted 18 lines · Andre Przywara
A few of the Allwinner A523 CCU clock registers introduced an "update" bit, which must be set for changes to the other bits to take effect. Of the three clocks where this was used, it was always bit 27, so we just encoded this as a single bit feature flag.
Now the CPU PLL also features the update bit, but puts it at bit 26, so this flag trick won't work anymore.
Add an "
update_bit" field to the common sunxi clock struct, which takes a bitmask, so we can encode any bit to use, even potentially multiple of them. As uninitialised fields are set to 0, we can use this as a default bitmask to set, so can OR this in unconditionally.Change the existing update bit users to use this new encoding, and add support for the
ccu_nmclock on the way, since we will need it there shortly.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Andre Przywara <[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>Hmm, actually, we also have the "key field" feature. Maybe we should generalize that one and merge the two?
Ah, that's a good idea! Somewhat obvious now when looking at the code in ccu_mux.c, where there are two "reg |= MAGIC_VALUE;" lines next to each other. Will hack something up for this.
Thanks,
Andre
PATCH 3/5 clk: sunxi-ng: mp: support clocks with just a shift register
In reply to Andre PrzywaraThe "mp" clock models a mod clock with divider and a shift field. At least one clock in the Allwinner A523 features just a power-of-2 divider field, so support an initialisation of the clock without providing an actual divider field.
Add a check whether the "width" field is 0, and skip the divider handling in this case, as the GENMASK macro will not work with a zero length.
--- drivers/clk/sunxi-ng/ccu_mp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/clk/sunxi-ng/ccu_mp.c +4 -2
@@ -236,9 +236,11 @@ static int ccu_mp_set_rate(struct clk_hw *hw, unsigned long rate,spin_lock_irqsave (cmp->common.lock, flags); reg =readl (cmp->common.base + cmp->common.reg); - reg &= ~GENMASK (cmp->m.width + cmp->m.shift -1 , cmp->m.shift); +if (cmp->m.width) + reg &= ~GENMASK (cmp->m.width + cmp->m.shift -1 , cmp->m.shift); reg &= ~GENMASK (cmp->p.width + cmp->p.shift -1 , cmp->p.shift); - reg |= (m - cmp->m.offset) << cmp->m.shift; +if (cmp->m.width) + reg |= (m - cmp->m.offset) << cmp->m.shift;if (shift) reg |=ilog2 (p) << cmp->p.shift;else
Signature · 1 line
2.46.3
Re: [PATCH 3/5] clk: sunxi-ng: mp: support clocks with just a shift register
Quoted 6 lines · Andre Przywara
The "mp" clock models a mod clock with divider and a shift field. At least one clock in the Allwinner A523 features just a power-of-2 divider field, so support an initialisation of the clock without providing an actual divider field.
Quoted 6 lines
Add a check whether the "width" field is 0, and skip the divider handling in this case, as the GENMASK macro will not work with a zero length.
Signed-off-by Andre Przywara <[email protected]>---
In my series I have a patch that adds this to the divider clocks, thus adding a P-clock type to the M-clock bits.
Maybe use that instead? I prefer we use actual matching types instead of disabling one part of a complex clock type.
ChenYu
Quoted 24 lines
drivers/clk/sunxi-ng/ccu_mp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/clk/sunxi-ng/ccu_mp.c +4
-3@@ -236,9 +236,11 @@ static int ccu_mp_set_rate(struct clk_hw *hw, unsigned long rate,spin_lock_irqsave (cmp->common.lock, flags); reg =readl (cmp->common.base + cmp->common.reg); - reg &= ~GENMASK (cmp->m.width + cmp->m.shift -1 , cmp->m.shift); +if (cmp->m.width) + reg &= ~GENMASK (cmp->m.width + cmp->m.shift -1 , cmp->m.shift); reg &= ~GENMASK (cmp->p.width + cmp->p.shift -1 , cmp->p.shift); - reg |= (m - cmp->m.offset) << cmp->m.shift; +if (cmp->m.width) + reg |= (m - cmp->m.offset) << cmp->m.shift;if (shift) reg |=ilog2 (p) << cmp->p.shift;else --2.46.3
Re: [PATCH 3/5] clk: sunxi-ng: mp: support clocks with just a shift register
Quoted 11 lines · On Wed, 3 Sep 2025 12:20:55 +0800 Chen-Yu Tsai <[email protected]> wrote:
Quoted 10 lines · Andre Przywara
The "mp" clock models a mod clock with divider and a shift field. At least one clock in the Allwinner A523 features just a power-of-2 divider field, so support an initialisation of the clock without providing an actual divider field.
Add a check whether the "width" field is 0, and skip the divider handling in this case, as the GENMASK macro will not work with a zero length.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Andre Przywara <[email protected]>---
In my series I have a patch that adds this to the divider clocks, thus adding a P-clock type to the M-clock bits.
Yeah, I saw that, but wasn't convinced this would be better. Hence wanted to post my version as an alternative.
Quoted 2 lines
Maybe use that instead? I prefer we use actual matching types instead of disabling one part of a complex clock type.
Good that you bring up that topic: when looking for matching clocks I saw we have a lot of them, though often one is just a subset of some others, with some code duplication. And we use the pattern of "use type A, but without feature X" already, for instance for "NKMP without the K".
So I was wondering if we should revisit this and clean this up. IIUC those clocks were all modelled after the H3 and earlier generation, and the clocks have changed since then. For instance I don't see PLLs with two multipliers (NK) after the A64 anymore.
So what about we consolidate the various types into just a few distinct ones, like NKMP for all PLLs, for instance, and provides macros that disable fields as needed? This could ideally be done under the hood, leaving the per-SoC drivers mostly alone, hopefully.
What do people think about that?
Cheers,
Andre
Quoted 24 lines
Quoted 24 lines
drivers/clk/sunxi-ng/ccu_mp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/clk/sunxi-ng/ccu_mp.c +4
-3@@ -236,9 +236,11 @@ static int ccu_mp_set_rate(struct clk_hw *hw, unsigned long rate,spin_lock_irqsave (cmp->common.lock, flags); reg =readl (cmp->common.base + cmp->common.reg); - reg &= ~GENMASK (cmp->m.width + cmp->m.shift -1 , cmp->m.shift); +if (cmp->m.width) + reg &= ~GENMASK (cmp->m.width + cmp->m.shift -1 , cmp->m.shift); reg &= ~GENMASK (cmp->p.width + cmp->p.shift -1 , cmp->p.shift); - reg |= (m - cmp->m.offset) << cmp->m.shift; +if (cmp->m.width) + reg |= (m - cmp->m.offset) << cmp->m.shift;if (shift) reg |=ilog2 (p) << cmp->p.shift;else --2.46.3
Re: [PATCH 3/5] clk: sunxi-ng: mp: support clocks with just a shift register
Quoted 37 lines · Andre Przywara
Quoted 11 lines · On Wed, 3 Sep 2025 12:20:55 +0800 Chen-Yu Tsai <[email protected]> wrote:
Quoted 10 lines · Andre Przywara
The "mp" clock models a mod clock with divider and a shift field. At least one clock in the Allwinner A523 features just a power-of-2 divider field, so support an initialisation of the clock without providing an actual divider field.
Add a check whether the "width" field is 0, and skip the divider handling in this case, as the GENMASK macro will not work with a zero length.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Andre Przywara <[email protected]>---
In my series I have a patch that adds this to the divider clocks, thus adding a P-clock type to the M-clock bits.
Yeah, I saw that, but wasn't convinced this would be better. Hence wanted to post my version as an alternative.
Quoted 2 lines
Maybe use that instead? I prefer we use actual matching types instead of disabling one part of a complex clock type.
Good that you bring up that topic: when looking for matching clocks I saw we have a lot of them, though often one is just a subset of some others, with some code duplication. And we use the pattern of "use type A, but without feature X" already, for instance for "NKMP without the K".
So I was wondering if we should revisit this and clean this up. IIUC those clocks were all modelled after the H3 and earlier generation, and the clocks have changed since then. For instance I don't see PLLs with two multipliers (NK) after the A64 anymore.
Quoted 6 lines
So what about we consolidate the various types into just a few distinct ones, like NKMP for all PLLs, for instance, and provides macros that disable fields as needed? This could ideally be done under the hood, leaving the per-SoC drivers mostly alone, hopefully.
What do people think about that?
I guess we could combine the NK* types, since those are relatively few.
I would like to keep the basic ones, those with just one multiplier or one divider, possibly combined with a mux and/or a gate, alone. These are based on core clk helpers. We only add features like fixed post dividers or update bit support on top of them.
ChenYu
Quoted 28 lines
Cheers,
AndreQuoted 24 lines
Quoted 24 lines
drivers/clk/sunxi-ng/ccu_mp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/clk/sunxi-ng/ccu_mp.c +4
-3@@ -236,9 +236,11 @@ static int ccu_mp_set_rate(struct clk_hw *hw, unsigned long rate,spin_lock_irqsave (cmp->common.lock, flags); reg =readl (cmp->common.base + cmp->common.reg); - reg &= ~GENMASK (cmp->m.width + cmp->m.shift -1 , cmp->m.shift); +if (cmp->m.width) + reg &= ~GENMASK (cmp->m.width + cmp->m.shift -1 , cmp->m.shift); reg &= ~GENMASK (cmp->p.width + cmp->p.shift -1 , cmp->p.shift); - reg |= (m - cmp->m.offset) << cmp->m.shift; +if (cmp->m.width) + reg |= (m - cmp->m.offset) << cmp->m.shift;if (shift) reg |=ilog2 (p) << cmp->p.shift;else --2.46.3
PATCH 4/5 clk: sunxi-ng: add support for the A523/T527 CPU CCU
In reply to Andre PrzywaraThe A523 contains a separate CCU block for the CPU PLLs. This includes one CPU clock per cluster, plus the DSU PLL, which clocks the part that connects the two clusters, and in particular the L3 cache. There is also an undocumented PLL0, which is a simper model that can apparently be used as an interim clock while re-locking the original PLLs.
Add the PLL clocks for the CPU PLLs. This particular clock tree is a bit weird, as there is a divider field for the just the PLL, but inside the mux clock. The ASCII art should explain this better. Model those as three separate clocks, and expose just the final mux clock for both clusters and the DSU.
--- drivers/clk/sunxi-ng/Kconfig | 5 + drivers/clk/sunxi-ng/Makefile | 2 + drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.c | 338 +++++++++++++++++++++ drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.h | 24 ++ 4 files changed, 369 insertions(+) create mode 100644 drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.c create mode 100644 drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.h
drivers/clk/sunxi-ng/Kconfig +5 -0
@@ -62,6 +62,11 @@ config SUN55I_A523_R_CCU default ARCH_SUNXI depends on ARM64 || COMPILE_TEST +config SUN55I_A523_CPU_CCU + tristate "Support for the Allwinner A523/T527 CPU CCU" + default y + depends on ARM64 || COMPILE_TEST + config SUN4I_A10_CCU tristate "Support for the Allwinner A10/A20 CCU" default ARCH_SUNXI
drivers/clk/sunxi-ng/Makefile +2 -0
@@ -35,6 +35,7 @@ obj-$(CONFIG_SUN50I_H6_R_CCU) += sun50i-h6-r-ccu.o obj-$(CONFIG_SUN50I_H616_CCU) += sun50i-h616-ccu.o obj-$(CONFIG_SUN55I_A523_CCU) += sun55i-a523-ccu.o obj-$(CONFIG_SUN55I_A523_R_CCU) += sun55i-a523-r-ccu.o +obj-$(CONFIG_SUN55I_A523_CPU_CCU) += sun55i-a523-cpu-ccu.o obj-$(CONFIG_SUN4I_A10_CCU) += sun4i-a10-ccu.o obj-$(CONFIG_SUN5I_CCU) += sun5i-ccu.o obj-$(CONFIG_SUN6I_A31_CCU) += sun6i-a31-ccu.o
@@ -62,6 +63,7 @@ sun50i-h6-r-ccu-y += ccu-sun50i-h6-r.o sun50i-h616-ccu-y += ccu-sun50i-h616.o sun55i-a523-ccu-y += ccu-sun55i-a523.o sun55i-a523-r-ccu-y += ccu-sun55i-a523-r.o +sun55i-a523-cpu-ccu-y += ccu-sun55i-a523-cpu.o sun4i-a10-ccu-y += ccu-sun4i-a10.o sun5i-ccu-y += ccu-sun5i.o sun6i-a31-ccu-y += ccu-sun6i-a31.o
drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.c new file +338 -0
338 lines not on this page · raw message
drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright 2025 Arm Ltd. +*/ + +#ifndef _CCU_SUN55I_A523_CPU_H +#define _CCU_SUN55I_A523_CPU_H + +#include <dt-bindings/clock/sun55i-a523-cpu-ccu.h> + +/* The PLL clocks itself and the pure divider clocks are not exported. */ + +#define CLK_PLL_CPU_0 0 +#define CLK_PLL_CPU_L 1 +#define CLK_PLL_CPU_DSU 2 +#define CLK_PLL_CPU_B 3 + +#define CLK_DIV_CPU_L 4 +#define CLK_DIV_CPU_DSU 5 +#define CLK_DIV_CPU_B 6 + +#define CLK_NUMBER (CLK_CPU_B + 1) + +#endif /* _CCU_SUN55I_A523_CPU_H */
Signature · 1 line
2.46.3
Re: [PATCH 4/5] clk: sunxi-ng: add support for the A523/T527 CPU CCU
drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.c line 55
Quoted 10 lines · Andre Przywara
drivers/clk/sunxi-ng/ccu-sun55i-a523-cpu.c new file +10
-0+#include "ccu_common.h" +#include "ccu_reset.h" + +#include "ccu_div.h" +#include "ccu_gate.h" +#include "ccu_mp.h" +#include "ccu_nm.h" +#include "ccu_mult.h" + +#include "ccu-sun55i-a523-cpu.h"
You should not rely on some other headers pulling other headers. You use here bindings, so you should include here bindings header as well.
Best regards,
Krzysztof
PATCH 5/5 arm64: dts: allwinner: a523: add CPU clocks
In reply to Andre PrzywaraThe Allwinner A523 family of SoCs feature a separate clock unit for the CPU PLLs and muxes, including one for the DSU interconnect.
Add a DT node for the CPU clock controller, and list all the clocks from the other CCUs that this controller needs.
Also list the clock source for each CPU: there is one clock for each cluster of four cores, suffixed L and B, for little and big (although all cores are of the same Cortex-A55 type).
--- .../arm64/boot/dts/allwinner/sun55i-a523.dtsi | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+)
arch/arm64/boot/dts/allwinner/sun55i-a523.dtsi +22 -0
@@ -5,6 +5,7 @@ #include <dt-bindings/clock/sun6i-rtc.h> #include <dt-bindings/clock/sun55i-a523-ccu.h> #include <dt-bindings/clock/sun55i-a523-r-ccu.h> +#include <dt-bindings/clock/sun55i-a523-cpu-ccu.h> #include <dt-bindings/reset/sun55i-a523-ccu.h> #include <dt-bindings/reset/sun55i-a523-r-ccu.h> #include <dt-bindings/power/allwinner,sun55i-a523-ppu.h>
@@ -24,6 +25,7 @@ cpu0: cpu@0 { device_type = "cpu"; reg = <0x000>; enable-method = "psci"; + clocks = <&cpu_ccu CLK_CPU_L>; }; cpu1: cpu@100 {
@@ -31,6 +33,7 @@ cpu1: cpu@100 { device_type = "cpu"; reg = <0x100>; enable-method = "psci"; + clocks = <&cpu_ccu CLK_CPU_L>; }; cpu2: cpu@200 {
@@ -38,6 +41,7 @@ cpu2: cpu@200 { device_type = "cpu"; reg = <0x200>; enable-method = "psci"; + clocks = <&cpu_ccu CLK_CPU_L>; }; cpu3: cpu@300 {
@@ -45,6 +49,7 @@ cpu3: cpu@300 { device_type = "cpu"; reg = <0x300>; enable-method = "psci"; + clocks = <&cpu_ccu CLK_CPU_L>; }; cpu4: cpu@400 {
@@ -52,6 +57,7 @@ cpu4: cpu@400 { device_type = "cpu"; reg = <0x400>; enable-method = "psci"; + clocks = <&cpu_ccu CLK_CPU_B>; }; cpu5: cpu@500 {
@@ -59,6 +65,7 @@ cpu5: cpu@500 { device_type = "cpu"; reg = <0x500>; enable-method = "psci"; + clocks = <&cpu_ccu CLK_CPU_B>; }; cpu6: cpu@600 {
@@ -66,6 +73,7 @@ cpu6: cpu@600 { device_type = "cpu"; reg = <0x600>; enable-method = "psci"; + clocks = <&cpu_ccu CLK_CPU_B>; }; cpu7: cpu@700 {
@@ -73,6 +81,7 @@ cpu7: cpu@700 { device_type = "cpu"; reg = <0x700>; enable-method = "psci"; + clocks = <&cpu_ccu CLK_CPU_B>; }; };
@@ -690,5 +699,18 @@ rtc: rtc@7090000 { clock-names = "bus", "hosc", "ahb"; #clock-cells = <1>; }; + + cpu_ccu: clock-controller@8817000 { + compatible = "allwinner,sun55i-a523-cpu-ccu"; + reg = <0x08817000 0x80>; + clocks = <&osc24M>, <&rtc CLK_OSC32K>, + <&rtc CLK_IOSC>, <&ccu CLK_PLL_PERIPH0_2X>, + <&ccu CLK_PLL_PERIPH0_600M>; + clock-names = "hosc", "losc", + "iosc", "pll-periph0-2x", + "pll-periph0-600M"; + #clock-cells = <1>; + #reset-cells = <1>; + }; }; };
Signature · 1 line
2.46.3