Re: [PATCH 5/7] clk: amlogic: Add S7 PLL clock controller driver
From: Jerome Brunet
Date: Wed Nov 18 2026 - 05:01:38 EST
> The S7 PLL controller provides the fixed PLL with its fclk dividers,
> the GP0, HIFI0 and HIFI1 PLLs, and the HDMI PLL.
>
> Add a driver for it. The GP0 and HIFI PLLs are expected to run with
> their input divided by 2 (div0p5) and the HDMI PLL without it, as the
> firmware and the init sequences set them up.
>
> Signed-off-by: Carlo Caione <ccaione@xxxxxxxxxxxx>
> ---
> drivers/clk/meson/Kconfig | 14 +
> drivers/clk/meson/Makefile | 1 +
> drivers/clk/meson/s7-pll.c | 648 +++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 663 insertions(+)
>
> diff --git a/drivers/clk/meson/Kconfig b/drivers/clk/meson/Kconfig
> index d460514bb8a1..35f2971448af 100644
> --- a/drivers/clk/meson/Kconfig
> +++ b/drivers/clk/meson/Kconfig
> @@ -229,6 +229,20 @@ config COMMON_CLK_S4_PERIPHERALS
> Support for the peripherals clock controller on Amlogic S805X2 and S905Y4
> devices, AKA S4. Say Y if you want S4 peripherals clock controller to work.
>
> +config COMMON_CLK_S7_PLL
> + tristate "Amlogic S7 SoC PLL controller support"
> + depends on ARM64 || COMPILE_TEST
> + default ARCH_MESON
> + select COMMON_CLK_MESON_REGMAP
> + select COMMON_CLK_MESON_CLKC_UTILS
> + select COMMON_CLK_MESON_PLL
> + imply COMMON_CLK_SCMI
> + help
> + Support for the PLL clock controller on Amlogic S805X3 based
> + devices, AKA S7. This controller provides the fixed PLL and its
> + dividers, the GP0, HIFI0 and HIFI1 PLLs and the HDMI PLL. Say Y if
> + you want the S7 PLL clock controller to work.
> +
> config COMMON_CLK_T7_PLL
> tristate "Amlogic T7 SoC PLL controller support"
> depends on ARM64
> diff --git a/drivers/clk/meson/Makefile b/drivers/clk/meson/Makefile
> index 56b04254eb1a..9d439106d11c 100644
> --- a/drivers/clk/meson/Makefile
> +++ b/drivers/clk/meson/Makefile
> @@ -28,5 +28,6 @@ obj-$(CONFIG_COMMON_CLK_G12A) += g12a.o g12a-aoclk.o
> obj-$(CONFIG_COMMON_CLK_MESON8B) += meson8b.o meson8-ddr.o
> obj-$(CONFIG_COMMON_CLK_S4_PLL) += s4-pll.o
> obj-$(CONFIG_COMMON_CLK_S4_PERIPHERALS) += s4-peripherals.o
> +obj-$(CONFIG_COMMON_CLK_S7_PLL) += s7-pll.o
> obj-$(CONFIG_COMMON_CLK_T7_PLL) += t7-pll.o
> obj-$(CONFIG_COMMON_CLK_T7_PERIPHERALS) += t7-peripherals.o
> diff --git a/drivers/clk/meson/s7-pll.c b/drivers/clk/meson/s7-pll.c
> new file mode 100644
> index 000000000000..2aa253a5f211
> --- /dev/null
> +++ b/drivers/clk/meson/s7-pll.c
> @@ -0,0 +1,648 @@
> +// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
> +/*
> + * Amlogic S7 PLL Clock Controller Driver
> + *
> + * Copyright (c) 2026 BayLibre, SAS.
> + * Author: Carlo Caione <ccaione@xxxxxxxxxxxx>
> + */
> +
> +#include <linux/clk-provider.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include "clk-regmap.h"
> +#include "clk-pll.h"
> +#include "meson-clkc-utils.h"
> +#include <dt-bindings/clock/amlogic,s7-pll-clkc.h>
> +
> +#define FIXPLL_CTRL0 0x040
> +#define FIXPLL_CTRL1 0x044
> +#define FIXPLL_STS 0x05c
> +#define GP0PLL_CTRL0 0x080
> +#define GP0PLL_CTRL1 0x084
> +#define GP0PLL_CTRL2 0x088
> +#define GP0PLL_CTRL3 0x08c
> +#define GP0PLL_STS 0x09c
> +#define HIFI0PLL_CTRL0 0x100
> +#define HIFI0PLL_CTRL1 0x104
> +#define HIFI0PLL_CTRL2 0x108
> +#define HIFI0PLL_CTRL3 0x10c
> +#define HIFI1PLL_CTRL0 0x110
> +#define HIFI1PLL_CTRL1 0x114
> +#define HIFI1PLL_CTRL2 0x118
> +#define HIFI1PLL_CTRL3 0x11c
> +#define HIFI0PLL_STS 0x120
> +#define HIFI1PLL_STS 0x124
> +#define HDMIPLL_CTRL0 0x1c0
> +#define HDMIPLL_CTRL1 0x1c4
> +#define HDMIPLL_CTRL2 0x1c8
> +#define HDMIPLL_CTRL3 0x1cc
> +#define HDMIPLL_STS 0x1dc
> +
> +static struct clk_regmap s7_fixed_pll_vco = {
> + .data = &(struct meson_clk_pll_data) {
> + .en = {
> + .reg_off = FIXPLL_CTRL0,
> + .shift = 28,
> + .width = 1,
> + },
> + .m = {
> + .reg_off = FIXPLL_CTRL0,
> + .shift = 0,
> + .width = 9,
> + },
> + .n = {
> + .reg_off = FIXPLL_CTRL0,
> + .shift = 11,
> + .width = 5,
> + },
> + .l = {
> + .reg_off = FIXPLL_STS,
> + .shift = 31,
> + .width = 1,
> + },
> + .rst = {
> + .reg_off = FIXPLL_CTRL0,
> + .shift = 29,
> + .width = 1,
> + },
> + },
> + .hw.init = &(struct clk_init_data) {
> + .name = "fixed_pll_vco",
> + .ops = &meson_clk_pll_ro_ops,
> + .parent_data = &(const struct clk_parent_data) {
> + .fw_name = "fix",
> + },
> + .num_parents = 1,
> + },
> +};
> +
> +static struct clk_regmap s7_fixed_pll = {
> + .data = &(struct clk_regmap_div_data) {
> + .offset = FIXPLL_CTRL0,
> + .shift = 9,
> + .width = 2,
> + .flags = CLK_DIVIDER_POWER_OF_TWO | CLK_DIVIDER_READ_ONLY,
> + },
> + .hw.init = &(struct clk_init_data) {
> + .name = "fixed_pll",
> + .ops = &clk_regmap_divider_ro_ops,
> + .parent_hws = (const struct clk_hw *[]) {
> + &s7_fixed_pll_vco.hw
> + },
> + .num_parents = 1,
> + },
> +};
> +
> +#define S7_FCLK(_name, _mult, _divider, _reg, _bit) \
> +static struct clk_fixed_factor s7_##_name##_div = { \
Nitpick: get the static out of the macro as it is done for the other macro
used in other SoCs. This keeps things consistent and help quickly id the
macro is declaring something.
> + .mult = (_mult), \
> + .div = (_divider), \
> + .hw.init = &(struct clk_init_data) { \
> + .name = #_name "_div", \
> + .ops = &clk_fixed_factor_ops, \
> + .parent_hws = (const struct clk_hw *[]) { \
> + &s7_fixed_pll.hw \
> + }, \
> + .num_parents = 1, \
> + }, \
> +}; \
>
I don't like macros declaring multiple clocks like that. One line, one clock.
+ \
> +static struct clk_regmap s7_##_name = { \
> + .data = &(struct clk_regmap_gate_data) { \
> + .offset = (_reg), \
> + .bit_idx = (_bit), \
> + }, \
> + .hw.init = &(struct clk_init_data) { \
> + .name = #_name, \
> + .ops = &clk_regmap_gate_ro_ops, \
> + .parent_hws = (const struct clk_hw *[]) { \
> + &s7_##_name##_div.hw \
> + }, \
> + .num_parents = 1, \
> + }, \
> +}
> +
> +/* The datasheet documents FIXPLL_CTRL1[30:26] as a single fclk_en field */
Not sure what this imply ?
> +S7_FCLK(fclk_div2, 1, 2, FIXPLL_CTRL1, 30);
> +S7_FCLK(fclk_div3, 1, 3, FIXPLL_CTRL1, 26);
> +S7_FCLK(fclk_div4, 1, 4, FIXPLL_CTRL1, 27);
> +S7_FCLK(fclk_div5, 1, 5, FIXPLL_CTRL1, 28);
> +S7_FCLK(fclk_div7, 1, 7, FIXPLL_CTRL1, 29);
> +S7_FCLK(fclk_div2p5, 2, 5, FIXPLL_CTRL0, 25);
> +
> +static const struct pll_mult_range s7_pll_mult_range = {
> + .min = 134,
> + .max = 265,
> +};
> +
> +static const struct reg_sequence s7_gp0_pll_init_regs[] = {
> + { .reg = GP0PLL_CTRL0, .def = 0x02520800 },
> + { .reg = GP0PLL_CTRL1, .def = 0x09900322 },
> + { .reg = GP0PLL_CTRL2, .def = 0x00000000 },
> + { .reg = GP0PLL_CTRL3, .def = 0x00000006 },
> +};
> +
> +static struct clk_fixed_factor s7_gp0_pll_div0p5 = {
> + .mult = 1,
> + .div = 2,
> + .hw.init = &(struct clk_init_data) {
> + .name = "gp0_pll_div0p5",
> + .ops = &clk_fixed_factor_ops,
> + .parent_data = &(const struct clk_parent_data) {
> + .fw_name = "gp0",
> + },
> + .num_parents = 1,
> + },
Is it the good old predivider here ? Shouldn't it be modelled with
a read-only divider rather that a fixed factor ? just in case whatever
came before did not leave things as we first expected ?
Applies to the other PLL instances
> +};
> +
> +static struct clk_regmap s7_gp0_pll_vco = {
> + .data = &(struct meson_clk_pll_data) {
> + .en = {
> + .reg_off = GP0PLL_CTRL0,
> + .shift = 28,
> + .width = 1,
> + },
> + .m = {
> + .reg_off = GP0PLL_CTRL0,
> + .shift = 0,
> + .width = 9,
> + },
> + .frac = {
> + .reg_off = GP0PLL_CTRL2,
> + .shift = 0,
> + .width = 17,
> + },
> + .l = {
> + .reg_off = GP0PLL_STS,
> + .shift = 31,
> + .width = 1,
> + },
> + .rst = {
> + .reg_off = GP0PLL_CTRL0,
> + .shift = 29,
> + .width = 1,
> + },
> + .frac_max = 131072,
Nit: 131072 is 1 << frac.width, which is already the default.
> + .range = &s7_pll_mult_range,
> + .init_regs = s7_gp0_pll_init_regs,
> + .init_count = ARRAY_SIZE(s7_gp0_pll_init_regs),
> + .flags = CLK_MESON_PLL_NOINIT_ENABLED,
> + },
> + .hw.init = &(struct clk_init_data) {
> + .name = "gp0_pll_vco",
> + .ops = &meson_clk_pll_ops,
> + .parent_hws = (const struct clk_hw *[]) {
> + &s7_gp0_pll_div0p5.hw
> + },
> + .num_parents = 1,
> + },
> +};
> +
> +static struct clk_regmap s7_gp0_pll = {
> + .data = &(struct clk_regmap_div_data) {
> + .offset = GP0PLL_CTRL0,
> + .shift = 9,
> + .width = 2,
> + .flags = CLK_DIVIDER_POWER_OF_TWO |
> + CLK_DIVIDER_ROUND_CLOSEST,
> + },
> + .hw.init = &(struct clk_init_data) {
> + .name = "gp0_pll",
> + .ops = &clk_regmap_divider_ops,
> + .parent_hws = (const struct clk_hw *[]) {
> + &s7_gp0_pll_vco.hw
> + },
> + .num_parents = 1,
> + .flags = CLK_SET_RATE_PARENT,
> + },
> +};
> +
> +/* hifi is HIFI0 in the datasheet */
What is stopping us from calling that then ?
> +static const struct reg_sequence s7_hifi_pll_init_regs[] = {
> + { .reg = HIFI0PLL_CTRL0, .def = 0x02520800 },
> + { .reg = HIFI0PLL_CTRL1, .def = 0x09900322 },
> + { .reg = HIFI0PLL_CTRL2, .def = 0x00000000 },
> + { .reg = HIFI0PLL_CTRL3, .def = 0x00000006 },
> +};
> +
> +static struct clk_fixed_factor s7_hifi_pll_div0p5 = {
> + .mult = 1,
> + .div = 2,
> + .hw.init = &(struct clk_init_data) {
> + .name = "hifi_pll_div0p5",
> + .ops = &clk_fixed_factor_ops,
> + .parent_data = &(const struct clk_parent_data) {
> + .fw_name = "hifi",
> + },
> + .num_parents = 1,
> + },
> +};
> +
> +static struct clk_regmap s7_hifi_pll_vco = {
> + .data = &(struct meson_clk_pll_data) {
> + .en = {
> + .reg_off = HIFI0PLL_CTRL0,
> + .shift = 28,
> + .width = 1,
> + },
> + .m = {
> + .reg_off = HIFI0PLL_CTRL0,
> + .shift = 0,
> + .width = 9,
> + },
> + .frac = {
> + .reg_off = HIFI0PLL_CTRL2,
> + .shift = 0,
> + .width = 17,
> + },
> + .l = {
> + .reg_off = HIFI0PLL_STS,
> + .shift = 31,
> + .width = 1,
> + },
> + .rst = {
> + .reg_off = HIFI0PLL_CTRL0,
> + .shift = 29,
> + .width = 1,
> + },
> + .frac_max = 100000,
> + .range = &s7_pll_mult_range,
> + .init_regs = s7_hifi_pll_init_regs,
> + .init_count = ARRAY_SIZE(s7_hifi_pll_init_regs),
> + .flags = CLK_MESON_PLL_ROUND_CLOSEST |
> + CLK_MESON_PLL_NOINIT_ENABLED,
I don't why we would keep the HIFI PLL as it was from the bootloader.
GP0 could be used for inherited splash screen. I don't think this
use case applies to the HIFI pll.
> + },
> + .hw.init = &(struct clk_init_data) {
> + .name = "hifi_pll_vco",
> + .ops = &meson_clk_pll_ops,
> + .parent_hws = (const struct clk_hw *[]) {
> + &s7_hifi_pll_div0p5.hw
> + },
> + .num_parents = 1,
> + },
> +};
> +
> +static struct clk_regmap s7_hifi_pll = {
> + .data = &(struct clk_regmap_div_data) {
> + .offset = HIFI0PLL_CTRL0,
> + .shift = 9,
> + .width = 2,
> + .flags = CLK_DIVIDER_POWER_OF_TWO |
> + CLK_DIVIDER_ROUND_CLOSEST,
> + },
> + .hw.init = &(struct clk_init_data) {
> + .name = "hifi_pll",
> + .ops = &clk_regmap_divider_ops,
> + .parent_hws = (const struct clk_hw *[]) {
> + &s7_hifi_pll_vco.hw
> + },
> + .num_parents = 1,
> + .flags = CLK_SET_RATE_PARENT,
> + },
> +};
> +
> +static const struct reg_sequence s7_hifi1_pll_init_regs[] = {
> + { .reg = HIFI1PLL_CTRL0, .def = 0x02520800 },
> + { .reg = HIFI1PLL_CTRL1, .def = 0x09900322 },
> + { .reg = HIFI1PLL_CTRL2, .def = 0x00000000 },
> + { .reg = HIFI1PLL_CTRL3, .def = 0x00000006 },
> +};
> +
> +static struct clk_fixed_factor s7_hifi1_pll_div0p5 = {
> + .mult = 1,
> + .div = 2,
> + .hw.init = &(struct clk_init_data) {
> + .name = "hifi1_pll_div0p5",
> + .ops = &clk_fixed_factor_ops,
> + .parent_data = &(const struct clk_parent_data) {
> + .fw_name = "hifi1",
> + },
> + .num_parents = 1,
> + },
> +};
> +
> +static struct clk_regmap s7_hifi1_pll_vco = {
> + .data = &(struct meson_clk_pll_data) {
> + .en = {
> + .reg_off = HIFI1PLL_CTRL0,
> + .shift = 28,
> + .width = 1,
> + },
> + .m = {
> + .reg_off = HIFI1PLL_CTRL0,
> + .shift = 0,
> + .width = 9,
> + },
> + .frac = {
> + .reg_off = HIFI1PLL_CTRL2,
> + .shift = 0,
> + .width = 17,
> + },
> + .l = {
> + .reg_off = HIFI1PLL_STS,
> + .shift = 31,
> + .width = 1,
> + },
> + .rst = {
> + .reg_off = HIFI1PLL_CTRL0,
> + .shift = 29,
> + .width = 1,
> + },
> + .frac_max = 100000,
> + .range = &s7_pll_mult_range,
> + .init_regs = s7_hifi1_pll_init_regs,
> + .init_count = ARRAY_SIZE(s7_hifi1_pll_init_regs),
> + .flags = CLK_MESON_PLL_ROUND_CLOSEST |
> + CLK_MESON_PLL_NOINIT_ENABLED,
> + },
> + .hw.init = &(struct clk_init_data) {
> + .name = "hifi1_pll_vco",
> + .ops = &meson_clk_pll_ops,
> + .parent_hws = (const struct clk_hw *[]) {
> + &s7_hifi1_pll_div0p5.hw
> + },
> + .num_parents = 1,
> + },
> +};
> +
> +static struct clk_regmap s7_hifi1_pll = {
> + .data = &(struct clk_regmap_div_data) {
> + .offset = HIFI1PLL_CTRL0,
> + .shift = 9,
> + .width = 2,
> + .flags = CLK_DIVIDER_POWER_OF_TWO |
> + CLK_DIVIDER_ROUND_CLOSEST,
> + },
> + .hw.init = &(struct clk_init_data) {
> + .name = "hifi1_pll",
> + .ops = &clk_regmap_divider_ops,
> + .parent_hws = (const struct clk_hw *[]) {
> + &s7_hifi1_pll_vco.hw
> + },
> + .num_parents = 1,
> + .flags = CLK_SET_RATE_PARENT,
> + },
> +};
> +
> +static const struct pll_mult_range s7_hdmi_pll_mult_range = {
> + .min = 125,
> + .max = 249,
> +};
> +
> +static const struct reg_sequence s7_hdmi_pll_init_regs[] = {
> + { .reg = HDMIPLL_CTRL0, .def = 0x00881000 },
> + { .reg = HDMIPLL_CTRL1, .def = 0x2c6011cc },
> + { .reg = HDMIPLL_CTRL2, .def = 0x86801000 },
> + { .reg = HDMIPLL_CTRL3, .def = 0x00000000 },
> +};
> +
> +static const struct clk_div_table s7_hdmi_pll_div0p5_table[] = {
> + { .val = 0, .div = 1 },
> + { .val = 1, .div = 2 },
> + { /* sentinel */ }
> +};
> +
> +static struct clk_regmap s7_hdmi_pll_div0p5 = {
> + .data = &(struct clk_regmap_div_data) {
> + .offset = HDMIPLL_CTRL1,
> + .shift = 19,
> + .width = 1,
> + .table = s7_hdmi_pll_div0p5_table,
> + .flags = CLK_DIVIDER_READ_ONLY,
> + },
> + .hw.init = &(struct clk_init_data) {
> + .name = "hdmi_pll_div0p5",
> + .ops = &clk_regmap_divider_ro_ops,
> + .parent_data = &(const struct clk_parent_data) {
> + .fw_name = "hdmi",
> + },
> + .num_parents = 1,
> + },
> +};
> +
> +static struct clk_regmap s7_hdmi_pll_vco = {
> + .data = &(struct meson_clk_pll_data) {
> + .en = {
> + .reg_off = HDMIPLL_CTRL0,
> + .shift = 28,
> + .width = 1,
> + },
> + .m = {
> + .reg_off = HDMIPLL_CTRL0,
> + .shift = 0,
> + .width = 9,
> + },
> + .frac = {
> + .reg_off = HDMIPLL_CTRL3,
> + .shift = 0,
> + .width = 17,
> + },
> + .l = {
> + .reg_off = HDMIPLL_STS,
> + .shift = 31,
> + .width = 1,
> + },
> + .rst = {
> + .reg_off = HDMIPLL_CTRL0,
> + .shift = 29,
> + .width = 1,
> + },
> + .range = &s7_hdmi_pll_mult_range,
> + .init_regs = s7_hdmi_pll_init_regs,
> + .init_count = ARRAY_SIZE(s7_hdmi_pll_init_regs),
> + .flags = CLK_MESON_PLL_RST_ACTIVE_LOW |
> + CLK_MESON_PLL_NOINIT_ENABLED,
> + },
> + .hw.init = &(struct clk_init_data) {
> + .name = "hdmi_pll_vco",
> + .ops = &meson_clk_pll_ops,
> + .parent_hws = (const struct clk_hw *[]) {
> + &s7_hdmi_pll_div0p5.hw
> + },
> + .num_parents = 1,
> + },
> +};
> +
> +/*
> + * The datasheet documents HDMIPLL_CTRL2[22:19] and [18:15] as single fields:
> + * each is two power-of-two dividers.
This comment is somehow confusing because it only partialy matches the clocks
defined bellow. Please clarify.
--
Jerome