clk: sunxi-ng: Allwinner D1 clock support
Subsystems (4)
Samuel Holland
maintainercover clk: sunxi-ng: Allwinner D1 clock support
This series adds support for the D1's CCU and R_CCU.
I attempted to hook up clock parents the "right" way, not using global names. To accomplish that, I added several new macros. I am open to comments on this approach. It looks a bit messier, but seems like it could be less prone to errors.
Samuel Holland (6):
dt-bindings: clk: Add compatibles for D1 CCUs
clk: sunxi-ng: div: Add macros using clk_parent_data and clk_hw
clk: sunxi-ng: mp: Add macros using clk_parent_data and clk_hw
clk: sunxi-ng: mux: Add macros using clk_parent_data and clk_hw
clk: sunxi-ng: gate: Add macros for gates with fixed dividers
clk: sunxi-ng: Add support for the D1 SoC clocks
.../clock/allwinner,sun4i-a10-ccu.yaml | 4 + drivers/clk/sunxi-ng/Kconfig | 10 + drivers/clk/sunxi-ng/Makefile | 4 + drivers/clk/sunxi-ng/ccu-sun20i-d1-r.c | 140 ++ drivers/clk/sunxi-ng/ccu-sun20i-d1-r.h | 17 + drivers/clk/sunxi-ng/ccu-sun20i-d1.c | 1390 +++++++++++++++++ drivers/clk/sunxi-ng/ccu-sun20i-d1.h | 15 + drivers/clk/sunxi-ng/ccu_div.h | 78 + drivers/clk/sunxi-ng/ccu_gate.h | 32 +- drivers/clk/sunxi-ng/ccu_mp.h | 49 + drivers/clk/sunxi-ng/ccu_mux.h | 33 + include/dt-bindings/clock/sun20i-d1-ccu.h | 156 ++ include/dt-bindings/clock/sun20i-d1-r-ccu.h | 19 + include/dt-bindings/reset/sun20i-d1-ccu.h | 77 + include/dt-bindings/reset/sun20i-d1-r-ccu.h | 16 + 15 files changed, 2039 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/sunxi-ng/ccu-sun20i-d1-r.c create mode 100644 drivers/clk/sunxi-ng/ccu-sun20i-d1-r.h create mode 100644 drivers/clk/sunxi-ng/ccu-sun20i-d1.c create mode 100644 drivers/clk/sunxi-ng/ccu-sun20i-d1.h create mode 100644 include/dt-bindings/clock/sun20i-d1-ccu.h create mode 100644 include/dt-bindings/clock/sun20i-d1-r-ccu.h create mode 100644 include/dt-bindings/reset/sun20i-d1-ccu.h create mode 100644 include/dt-bindings/reset/sun20i-d1-r-ccu.h
Signature · 1 line
2.32.0
Samuel Holland
maintainerPATCH 1/6 dt-bindings: clk: Add compatibles for D1 CCUs
The D1 has a CCU and a R_CCU (PRCM CCU) like most other sunxi SoCs, with 3 and 4 clock inputs, respectively. Add the compatibles and bindings.
---
.../clock/allwinner,sun4i-a10-ccu.yaml | 4 + include/dt-bindings/clock/sun20i-d1-ccu.h | 156 ++++++++++++++++++ include/dt-bindings/clock/sun20i-d1-r-ccu.h | 19 +++ include/dt-bindings/reset/sun20i-d1-ccu.h | 77 +++++++++ include/dt-bindings/reset/sun20i-d1-r-ccu.h | 16 ++ 5 files changed, 272 insertions(+) create mode 100644 include/dt-bindings/clock/sun20i-d1-ccu.h create mode 100644 include/dt-bindings/clock/sun20i-d1-r-ccu.h create mode 100644 include/dt-bindings/reset/sun20i-d1-ccu.h create mode 100644 include/dt-bindings/reset/sun20i-d1-r-ccu.h
Documentation/devicetree/bindings/clock/allwinner,sun4i-a10-ccu.yaml +4 -0
@@ -34,6 +34,8 @@ properties: - allwinner,sun8i-v3-ccu - allwinner,sun8i-v3s-ccu - allwinner,sun9i-a80-ccu + - allwinner,sun20i-d1-ccu + - allwinner,sun20i-d1-r-ccu - allwinner,sun50i-a64-ccu - allwinner,sun50i-a64-r-ccu - allwinner,sun50i-a100-ccu
@@ -79,6 +81,7 @@ if: enum: - allwinner,sun8i-a83t-r-ccu - allwinner,sun8i-h3-r-ccu + - allwinner,sun20i-d1-r-ccu - allwinner,sun50i-a64-r-ccu - allwinner,sun50i-a100-r-ccu - allwinner,sun50i-h6-r-ccu
@@ -99,6 +102,7 @@ else: properties: compatible: enum: + - allwinner,sun20i-d1-ccu - allwinner,sun50i-a100-ccu - allwinner,sun50i-h6-ccu - allwinner,sun50i-h616-ccu
include/dt-bindings/clock/sun20i-d1-ccu.h new file +156 -0
156 lines not on this page · raw message
include/dt-bindings/clock/sun20i-d1-r-ccu.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: (GPL-2.0+ or MIT) */ +/* +* Copyright (C) 2021 Samuel Holland <[email protected]> +*/ + +#ifndef _DT_BINDINGS_CLK_SUN20I_D1_R_CCU_H_ +#define _DT_BINDINGS_CLK_SUN20I_D1_R_CCU_H_ + +#define CLK_R_AHB 0 + +#define CLK_BUS_R_TIMER 2 +#define CLK_BUS_R_TWD 3 +#define CLK_BUS_R_PPU 4 +#define CLK_R_IR_RX 5 +#define CLK_BUS_R_IR_RX 6 +#define CLK_BUS_R_RTC 7 +#define CLK_BUS_R_CPUCFG 8 + +#endif /* _DT_BINDINGS_CLK_SUN20I_D1_R_CCU_H_ */
include/dt-bindings/reset/sun20i-d1-ccu.h new file +77 -0
77 lines not on this page · raw message
include/dt-bindings/reset/sun20i-d1-r-ccu.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: (GPL-2.0+ or MIT) */ +/* +* Copyright (C) 2021 Samuel Holland <[email protected]> +*/ + +#ifndef _DT_BINDINGS_RST_SUN20I_D1_R_CCU_H_ +#define _DT_BINDINGS_RST_SUN20I_D1_R_CCU_H_ + +#define RST_BUS_R_TIMER 0 +#define RST_BUS_R_TWD 1 +#define RST_BUS_R_PPU 2 +#define RST_BUS_R_IR_RX 3 +#define RST_BUS_R_RTC 4 +#define RST_BUS_R_CPUCFG 5 + +#endif /* _DT_BINDINGS_RST_SUN20I_D1_R_CCU_H_ */
Signature · 1 line
2.32.0
Samuel Holland
maintainerPATCH 2/6 clk: sunxi-ng: div: Add macros using clk_parent_data and clk_hw
In reply to Samuel HollandReferencing parents with clk_hw pointers is more efficient and removes the dependency on global clock names. clk_parent_data is needed when some parent clocks are provided from another driver. Add macros for declaring dividers that take advantage of these.
---
drivers/clk/sunxi-ng/ccu_div.h | 78 ++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+)
drivers/clk/sunxi-ng/ccu_div.h +78 -0
@@ -108,6 +108,22 @@ struct ccu_div { _shift, _width, _table, 0, \ _flags) +#define SUNXI_CCU_DIV_TABLE_HW (_struct, _name, _parent, _reg, \ + _shift, _width, \ + _table, _flags) \ + struct ccu_div _struct = { \ + .div = _SUNXI_CCU_DIV_TABLE(_shift, _width, \ + _table), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_HW(_name, \ + _parent, \ + &ccu_div_ops, \ + _flags), \ + } \ + } + + #define SUNXI_CCU_M_WITH_MUX_TABLE_GATE(_struct, _name, \ _parents, _table, \ _reg, \
@@ -166,6 +182,68 @@ struct ccu_div {SUNXI_CCU_M_WITH_GATE (_struct, _name, _parent, _reg, \ _mshift, _mwidth, 0, _flags) +#define SUNXI_CCU_M_DATA_WITH_MUX_GATE (_struct, _name, _parents, _reg, \ + _mshift, _mwidth, \ + _muxshift, _muxwidth, \ + _gate, _flags) \ + struct ccu_div _struct = { \ + .enable = _gate, \ + .div = _SUNXI_CCU_DIV(_mshift, _mwidth), \ + .mux = _SUNXI_CCU_MUX(_muxshift, _muxwidth), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_PARENTS_DATA(_name, \ + _parents, \ + &ccu_div_ops, \ + _flags), \ + }, \ + } + +#define SUNXI_CCU_M_DATA_WITH_MUX (_struct, _name, _parents, _reg, \ + _mshift, _mwidth, \ + _muxshift, _muxwidth, \ + _flags) \ + SUNXI_CCU_M_DATA_WITH_MUX_GATE(_struct, _name, _parents, _reg, \ + _mshift, _mwidth, \ + _muxshift, _muxwidth, \ + 0, _flags) + +#define SUNXI_CCU_M_HW_WITH_MUX_GATE (_struct, _name, _parents, _reg, \ + _mshift, _mwidth, _muxshift, _muxwidth, \ + _gate, _flags) \ + struct ccu_div _struct = { \ + .enable = _gate, \ + .div = _SUNXI_CCU_DIV(_mshift, _mwidth), \ + .mux = _SUNXI_CCU_MUX(_muxshift, _muxwidth), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_PARENTS_HW(_name, \ + _parents, \ + &ccu_div_ops, \ + _flags), \ + }, \ + } + +#define SUNXI_CCU_M_HWS_WITH_GATE (_struct, _name, _parent, _reg, \ + _mshift, _mwidth, _gate, \ + _flags) \ + struct ccu_div _struct = { \ + .enable = _gate, \ + .div = _SUNXI_CCU_DIV(_mshift, _mwidth), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_HWS(_name, \ + _parent, \ + &ccu_div_ops, \ + _flags), \ + }, \ + } + +#define SUNXI_CCU_M_HWS (_struct, _name, _parent, _reg, _mshift, \ + _mwidth, _flags) \ + SUNXI_CCU_M_HWS_WITH_GATE(_struct, _name, _parent, _reg, \ + _mshift, _mwidth, 0, _flags) +static inline struct ccu_div *hw_to_ccu_div (struct clk_hw *hw) {struct ccu_common *common =hw_to_ccu_common (hw);
Signature · 1 line
2.32.0
Samuel Holland
maintainerPATCH 3/6 clk: sunxi-ng: mp: Add macros using clk_parent_data and clk_hw
In reply to Samuel HollandReferencing parents with clk_hw pointers is more efficient and removes the dependency on global clock names. clk_parent_data is needed when some parent clocks are provided from another driver. Add macros for declaring dividers that take advantage of these.
---
drivers/clk/sunxi-ng/ccu_mp.h | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/clk/sunxi-ng/ccu_mp.h +49 -0
@@ -82,6 +82,55 @@ struct ccu_mp { _muxshift, _muxwidth, \ 0, _flags) +#define SUNXI_CCU_MP_DATA_WITH_MUX_GATE (_struct, _name, _parents, _reg, \ + _mshift, _mwidth, \ + _pshift, _pwidth, \ + _muxshift, _muxwidth, \ + _gate, _flags) \ + struct ccu_mp _struct = { \ + .enable = _gate, \ + .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \ + .p = _SUNXI_CCU_DIV(_pshift, _pwidth), \ + .mux = _SUNXI_CCU_MUX(_muxshift, _muxwidth), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_PARENTS_DATA(_name, \ + _parents, \ + &ccu_mp_ops, \ + _flags), \ + } \ + } + +#define SUNXI_CCU_MP_DATA_WITH_MUX (_struct, _name, _parents, _reg, \ + _mshift, _mwidth, \ + _pshift, _pwidth, \ + _muxshift, _muxwidth, \ + _flags) \ + SUNXI_CCU_MP_DATA_WITH_MUX_GATE(_struct, _name, _parents, _reg, \ + _mshift, _mwidth, \ + _pshift, _pwidth, \ + _muxshift, _muxwidth, \ + 0, _flags) + +#define SUNXI_CCU_MP_HW_WITH_MUX_GATE (_struct, _name, _parents, _reg, \ + _mshift, _mwidth, \ + _pshift, _pwidth, \ + _muxshift, _muxwidth, \ + _gate, _flags) \ + struct ccu_mp _struct = { \ + .enable = _gate, \ + .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \ + .p = _SUNXI_CCU_DIV(_pshift, _pwidth), \ + .mux = _SUNXI_CCU_MUX(_muxshift, _muxwidth), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_PARENTS_HW(_name, \ + _parents, \ + &ccu_mp_ops, \ + _flags), \ + } \ + } +static inline struct ccu_mp *hw_to_ccu_mp (struct clk_hw *hw) {struct ccu_common *common =hw_to_ccu_common (hw);
Signature · 1 line
2.32.0
Samuel Holland
maintainerPATCH 4/6 clk: sunxi-ng: mux: Add macros using clk_parent_data and clk_hw
In reply to Samuel HollandReferencing parents with clk_hw pointers is more efficient and removes the dependency on global clock names. clk_parent_data is needed when some parent clocks are provided from another driver. Add macros for declaring muxes that take advantage of these.
---
drivers/clk/sunxi-ng/ccu_mux.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
drivers/clk/sunxi-ng/ccu_mux.h +33 -0
@@ -72,6 +72,39 @@ struct ccu_mux {SUNXI_CCU_MUX_TABLE_WITH_GATE (_struct, _name, _parents,NULL , \ _reg, _shift, _width, 0, _flags) +#define SUNXI_CCU_MUX_DATA_WITH_GATE (_struct, _name, _parents, _reg, \ + _shift, _width, _gate, _flags) \ + struct ccu_mux _struct = { \ + .enable = _gate, \ + .mux = _SUNXI_CCU_MUX(_shift, _width), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_PARENTS_DATA(_name, \ + _parents, \ + &ccu_mux_ops, \ + _flags), \ + } \ + } + +#define SUNXI_CCU_MUX_DATA (_struct, _name, _parents, _reg, \ + _shift, _width, _flags) \ + SUNXI_CCU_MUX_DATA_WITH_GATE(_struct, _name, _parents, _reg, \ + _shift, _width, 0, _flags) + +#define SUNXI_CCU_MUX_HW_WITH_GATE (_struct, _name, _parents, _reg, \ + _shift, _width, _gate, _flags) \ + struct ccu_mux _struct = { \ + .enable = _gate, \ + .mux = _SUNXI_CCU_MUX(_shift, _width), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_PARENTS_HW(_name, \ + _parents, \ + &ccu_mux_ops, \ + _flags), \ + } \ + } +static inline struct ccu_mux *hw_to_ccu_mux (struct clk_hw *hw) {struct ccu_common *common =hw_to_ccu_common (hw);
Signature · 1 line
2.32.0
Samuel Holland
maintainerPATCH 5/6 clk: sunxi-ng: gate: Add macros for gates with fixed dividers
In reply to Samuel HollandIt is possible to declare a gate with a fixed divider, by using the CCU_FEATURE_ALL_PREDIV flag. Since this is not obvious, add a macro for declaring this type of clock.
---
drivers/clk/sunxi-ng/ccu_gate.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
drivers/clk/sunxi-ng/ccu_gate.h +31 -1
@@ -53,7 +53,7 @@ struct ccu_gate { }/* -* The following two macros allow the re-use of the data structure +* The following macros allow the re-use of the data structure * holding the parent info. */ #define SUNXI_CCU_GATE_HWS (_struct, _name, _parent, _reg, _gate, _flags) \
@@ -68,6 +68,21 @@ struct ccu_gate { } \ } +#define SUNXI_CCU_GATE_HWS_WITH_PREDIV (_struct, _name, _parent, _reg, \ + _gate, _prediv, _flags) \ + struct ccu_gate _struct = { \ + .enable = _gate, \ + .common = { \ + .reg = _reg, \ + .prediv = _prediv, \ + .features = CCU_FEATURE_ALL_PREDIV, \ + .hw.init = CLK_HW_INIT_HWS(_name, \ + _parent, \ + &ccu_gate_ops, \ + _flags), \ + } \ + } +#define SUNXI_CCU_GATE_DATA (_struct, _name, _data, _reg, _gate, _flags) \ struct ccu_gate _struct = { \ .enable = _gate, \
@@ -81,6 +96,21 @@ struct ccu_gate { } \ } +#define SUNXI_CCU_GATE_DATA_WITH_PREDIV (_struct, _name, _parent, _reg, \ + _gate, _prediv, _flags) \ + struct ccu_gate _struct = { \ + .enable = _gate, \ + .common = { \ + .reg = _reg, \ + .prediv = _prediv, \ + .features = CCU_FEATURE_ALL_PREDIV, \ + .hw.init = CLK_HW_INIT_PARENTS_DATA(_name, \ + _parent, \ + &ccu_gate_ops, \ + _flags), \ + } \ + } +static inline struct ccu_gate *hw_to_ccu_gate (struct clk_hw *hw) {struct ccu_common *common =hw_to_ccu_common (hw);
Signature · 1 line
2.32.0
Samuel Holland
maintainerPATCH 6/6 clk: sunxi-ng: Add support for the D1 SoC clocks
In reply to Samuel HollandThe D1 SoC contains a CCU and a R_CCU (PRCM CCU). Add support for them.
---
drivers/clk/sunxi-ng/Kconfig | 10 + drivers/clk/sunxi-ng/Makefile | 4 + drivers/clk/sunxi-ng/ccu-sun20i-d1-r.c | 140 +++ drivers/clk/sunxi-ng/ccu-sun20i-d1-r.h | 17 + drivers/clk/sunxi-ng/ccu-sun20i-d1.c | 1390 ++++++++++++++++++++++++ drivers/clk/sunxi-ng/ccu-sun20i-d1.h | 15 + 6 files changed, 1576 insertions(+) create mode 100644 drivers/clk/sunxi-ng/ccu-sun20i-d1-r.c create mode 100644 drivers/clk/sunxi-ng/ccu-sun20i-d1-r.h create mode 100644 drivers/clk/sunxi-ng/ccu-sun20i-d1.c create mode 100644 drivers/clk/sunxi-ng/ccu-sun20i-d1.h
drivers/clk/sunxi-ng/Kconfig +10 -0
@@ -12,6 +12,16 @@ config SUNIV_F1C100S_CCU default MACH_SUNIV depends on MACH_SUNIV || COMPILE_TEST +config SUN20I_D1_CCU + tristate "Support for the Allwinner D1 CCU" + default RISCV && ARCH_SUNXI + depends on (RISCV && ARCH_SUNXI) || COMPILE_TEST + +config SUN20I_D1_R_CCU + tristate "Support for the Allwinner D1 PRCM CCU" + default RISCV && ARCH_SUNXI + depends on (RISCV && ARCH_SUNXI) || COMPILE_TEST + config SUN50I_A64_CCU tristate "Support for the Allwinner A64 CCU" default ARM64 && ARCH_SUNXI
drivers/clk/sunxi-ng/Makefile +4 -0
@@ -25,6 +25,8 @@ sunxi-ccu-y += ccu_mp.o # SoC support obj-$(CONFIG_SUNIV_F1C100S_CCU) += suniv-f1c100s-ccu.o +obj-$(CONFIG_SUN20I_D1_CCU) += sun20i-d1-ccu.o +obj-$(CONFIG_SUN20I_D1_R_CCU) += sun20i-d1-r-ccu.o obj-$(CONFIG_SUN50I_A64_CCU) += sun50i-a64-ccu.o obj-$(CONFIG_SUN50I_A100_CCU) += sun50i-a100-ccu.o obj-$(CONFIG_SUN50I_A100_R_CCU) += sun50i-a100-r-ccu.o
@@ -47,6 +49,8 @@ obj-$(CONFIG_SUN9I_A80_CCU) += sun9i-a80-de-ccu.o obj-$(CONFIG_SUN9I_A80_CCU) += sun9i-a80-usb-ccu.o suniv-f1c100s-ccu-y += ccu-suniv-f1c100s.o +sun20i-d1-ccu-y += ccu-sun20i-d1.o +sun20i-d1-r-ccu-y += ccu-sun20i-d1-r.o sun50i-a64-ccu-y += ccu-sun50i-a64.o sun50i-a100-ccu-y += ccu-sun50i-a100.o sun50i-a100-r-ccu-y += ccu-sun50i-a100-r.o
drivers/clk/sunxi-ng/ccu-sun20i-d1-r.c new file +140 -0
140 lines not on this page · raw message
drivers/clk/sunxi-ng/ccu-sun20i-d1-r.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2020 [email protected] +* Copyright (C) 2021 Samuel Holland <[email protected]> +*/ + +#ifndef _CCU_SUN20I_D1_R_H +#define _CCU_SUN20I_D1_R_H + +#include <dt-bindings/clock/sun20i-d1-r-ccu.h> +#include <dt-bindings/reset/sun20i-d1-r-ccu.h> + +#define CLK_R_APB0 1 + +#define CLK_NUMBER (CLK_BUS_R_CPUCFG + 1) + +#endif /* _CCU_SUN20I_D1_R_H */
drivers/clk/sunxi-ng/ccu-sun20i-d1.c new file +1390 -0
1,390 lines not on this page · raw message
drivers/clk/sunxi-ng/ccu-sun20i-d1.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2020 [email protected] +* Copyright (C) 2021 Samuel Holland <[email protected]> +*/ + +#ifndef _CCU_SUN20I_D1_H_ +#define _CCU_SUN20I_D1_H_ + +#include <dt-bindings/clock/sun20i-d1-ccu.h> +#include <dt-bindings/reset/sun20i-d1-ccu.h> + +#define CLK_NUMBER (CLK_FANOUT2 + 1) + +#endif /* _CCU_SUN20I_D1_H_ */
Signature · 1 line
2.32.0
Maxime Ripard
AppliedQuoted 8 lines · Samuel Holland
This series adds support for the D1's CCU and
R_CCU.I attempted to hook up clock parents the "right" way, not using global names. To accomplish that, I added several new macros. I am open to comments on this approach. It looks a bit messier, but seems like it could be less prone to errors.
[...]
Applied to sunxi/linux.git (sunxi/clk-for-5.17).
Thanks!
Maxime