Re: [PATCH 2/4] clk: ingenic: Add Ingenic X1600 CGU clock driver support

From: Brian Masney

Date: Wed Nov 11 2026 - 16:45:45 EST


> Introduce clock driver support for the Clock Generation Unit (CGU)
> found in the Ingenic X1600 SoC.
>
> To support the X1600 platform, update the common Ingenic CGU core
> framework to accommodate a secondary post-VCO divider (OD1) within
> the PLL configuration registers. Additionally, prevent a NULL pointer
> dereference in the rate determination path by properly supplying the
> secondary divider tracking during PLL calculation calls.
>
> Implement custom handling for the I2S clocks on the X1600. Since
> complex compound hardware dividers are not yet natively supported by the
> core framework, explicit M-divider (mdiv) and N/D-divider (nddiv)
> structures are introduced to describe these specialized fields. This
> avoids a compilation failure and enables a stable, though limited,
> division encoding suitable for current needs.
>
> Furthermore, this patch:
> - Fixes the gating of the I2S0 and I2S1 clocks, matching the control
> bit behavior which functions as a clock enable flag.
> - Introduces the custom OTG PHY clock operations and initialisation
> routines utilizing the hardware's OPCR registers.
> - Registers the independent I2S0 RX and TX gate clocks employed by the
> X1600 peripheral block.

Just from reading the commit message this patch needs to be split up
further into several smaller patches to make it easier to review.
Ideally try to make the different bullet points separate patches.

> Tested successfully on the LX16 (X1600) boards and CI20 (JZ4780) to
> not interefere.
>
> Checkpatch complains about not 4 lines of help paragraph but the
> style is the same as for the other machines. It also recommends
> using 'unsigned int' for the new struct ingenic_cgu_mdiv_info
> and struct ingenic_cgu_nddiv_info but this follows the style 'unsigned'
> of all other structs in cgu.h. Finally it complains about the empty
> line between struct ingenic_cgu_clk_info x1600_cgu_clocks[] = {
> and the comment. But I think it is more readable this way.

The checkpatch note can go below the --- below.

>
> Co-developed-by: H. Nikolaus Schaller <hns@xxxxxxxxxxxxx>
> Signed-off-by: H. Nikolaus Schaller <hns@xxxxxxxxxxxxx>
> Co-developed-by: Paul Boddie <paul@xxxxxxxxxxxxx>
> Signed-off-by: Paul Boddie <paul@xxxxxxxxxxxxx>
> ---
> drivers/clk/ingenic/Kconfig | 10 +
> drivers/clk/ingenic/Makefile | 1 +
> drivers/clk/ingenic/cgu.c | 150 +++++++---
> drivers/clk/ingenic/cgu.h | 42 ++-
> drivers/clk/ingenic/x1600-cgu.c | 476 ++++++++++++++++++++++++++++++++
> 5 files changed, 646 insertions(+), 33 deletions(-)
> create mode 100644 drivers/clk/ingenic/x1600-cgu.c
>
> diff --git a/drivers/clk/ingenic/Kconfig b/drivers/clk/ingenic/Kconfig
> index f80ac4f2992b..9b8b00c9e6d1 100644
> --- a/drivers/clk/ingenic/Kconfig
> +++ b/drivers/clk/ingenic/Kconfig
> @@ -75,6 +75,16 @@ config INGENIC_CGU_X1000
>
> If building for a X1000 SoC, you want to say Y here.
>
> +config INGENIC_CGU_X1600
> + bool "Ingenic X1600 CGU driver"
> + default MACH_X1600
> + select INGENIC_CGU_COMMON
> + help
> + Support the clocks provided by the CGU hardware on Ingenic X1600
> + and compatible SoCs.
> +
> + If building for a X1600 SoC, you want to say Y here.
> +
> config INGENIC_CGU_X1830
> bool "Ingenic X1830 CGU driver"
> default MACH_X1830
> diff --git a/drivers/clk/ingenic/Makefile b/drivers/clk/ingenic/Makefile
> index 81d8e23c2636..7e93e0893abe 100644
> --- a/drivers/clk/ingenic/Makefile
> +++ b/drivers/clk/ingenic/Makefile
> @@ -7,5 +7,6 @@ obj-$(CONFIG_INGENIC_CGU_JZ4760) += jz4760-cgu.o
> obj-$(CONFIG_INGENIC_CGU_JZ4770) += jz4770-cgu.o
> obj-$(CONFIG_INGENIC_CGU_JZ4780) += jz4780-cgu.o
> obj-$(CONFIG_INGENIC_CGU_X1000) += x1000-cgu.o
> +obj-$(CONFIG_INGENIC_CGU_X1600) += x1600-cgu.o
> obj-$(CONFIG_INGENIC_CGU_X1830) += x1830-cgu.o
> obj-$(CONFIG_INGENIC_TCU_CLK) += tcu.o
> diff --git a/drivers/clk/ingenic/cgu.c b/drivers/clk/ingenic/cgu.c
> index ad223aa20e8d..c4fbee32c3b9 100644
> --- a/drivers/clk/ingenic/cgu.c
> +++ b/drivers/clk/ingenic/cgu.c
> @@ -4,6 +4,7 @@
> *
> * Copyright (c) 2013-2015 Imagination Technologies
> * Author: Paul Burton <paul.burton@xxxxxxxx>
> + * Copyright (c) 2023, 2024 Paul Boddie <paul@xxxxxxxxxxxxx>
> */
>
> #include <linux/bitops.h>
> @@ -76,6 +77,40 @@ ingenic_cgu_gate_set(struct ingenic_cgu *cgu,
> * PLL operations
> */
>
> +static unsigned
> +ingenic_pll_recalc_rate_od(u32 ctl, u8 od_shift, u8 od_bits, u8 od_max,
> + const s8 *od_encoding)
> +{
> + unsigned int od, od_enc = 0;
> +
> + if (od_bits > 0) {
> + od_enc = ctl >> od_shift;
> + od_enc &= GENMASK(od_bits - 1, 0);
> + }
> +
> + /*
> + * Use the encoding table if indicated. Otherwise, use the value
> + * directly, interpreting an encoded value of zero as a divider
> + * value of one.
> + */
> + if (od_encoding) {
> + for (od = 0; od < od_max; od++)
> + if (od_encoding[od] == od_enc)
> + break;
> + od++;

So if the entry is not found, then od will be set to od_max + 1, and it
will pass through the warning checks.

I started to look through the rest of the driver but I stopped because
there's just too many unrelated changes here. This needs to be split up
further into separate patches to make it easier to review. If your
commit message has the word 'and' then that's a hint that you may want
to consider splitting it up further.

Also be sure to go through all of the feedback from Sashiko.

Brian

--
Brian Masney <masneyb@xxxxxxxxxx>