mbox series

[v7,0/7] rockchip: clk: improve GATE_LINK support

Message ID 20231213185114.47565-1-sebastian.reichel@collabora.com
Headers show
Series rockchip: clk: improve GATE_LINK support | expand

Message

Sebastian Reichel Dec. 13, 2023, 6:46 p.m. UTC
Hi,

I've send this as v7 for the series from Elaine [0], since it kinds of is. These
patches are written from scratch, though. There are two parts:

part 1:
Elaine's series used to contain patches for the VO1GRF handling, but they were
dropped at some point because of the CLK_NR_CLKS feedback from the DT
maintainers. I added some code, that should hopefully fix everyones concerns by
figuring out the right number at runtime. I also moved the correct handling of
pclk_vo0grf/pclk_vo1grf before proper handling of GATE_LINK clocks, so that it
can be merged ASAP. These patches are needed for HDMI RX/TX support on RK3588
and should not be blocked by the GATE_LINK discussion.

part 2:
For proper GATE_LINK support I tried implementing the suggestion from Stephen
Boyd to use clk PM operations by creating MFD dynamically. This required some
restructuring, since CLK_OF_DECLARE() is called before devices are available.
All of this can be found in the last patch of this series.

[0] https://lore.kernel.org/linux-clk/20231110020358.12840-1-zhangqing@rock-chips.com/

Greetings,

-- Sebstian

Sebastian Reichel (7):
  clk: rockchip: rk3588: fix CLK_NR_CLKS usage
  dt-bindings: clock: rk3588: drop CLK_NR_CLKS
  dt-bindings: clock: rk3588: add missing PCLK_VO1GRF
  clk: rockchip: rk3588: fix pclk_vo0grf and pclk_vo1grf
  clk: rockchip: rk3588: fix indent
  clk: rockchip: rk3588: use linked clock ID for GATE_LINK
  clk: rockchip: implement proper GATE_LINK support

 drivers/clk/rockchip/clk-rk3588.c             | 163 ++++++++----------
 drivers/clk/rockchip/clk.c                    |  85 ++++++++-
 drivers/clk/rockchip/clk.h                    |  18 ++
 .../dt-bindings/clock/rockchip,rk3588-cru.h   |   3 +-
 4 files changed, 178 insertions(+), 91 deletions(-)

Comments

Tao Huang Dec. 14, 2023, 8:42 a.m. UTC | #1
On 2023/12/14 上午2:46, Sebastian Reichel wrote:
> CLK_NR_CLKS is not part of the DT bindings and needs to be removed
> from it, just like it recently happened for other platforms. This
> takes care of it by introducing a new function identifying the
> maximum used clock ID at runtime.
>
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
>  drivers/clk/rockchip/clk-rk3588.c |  5 ++++-
>  drivers/clk/rockchip/clk.c        | 17 +++++++++++++++++
>  drivers/clk/rockchip/clk.h        |  2 ++
>  3 files changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/rockchip/clk-rk3588.c b/drivers/clk/rockchip/clk-rk3588.c
> index 6994165e0395..0b60ae78f9d8 100644
> --- a/drivers/clk/rockchip/clk-rk3588.c
> +++ b/drivers/clk/rockchip/clk-rk3588.c
> @@ -2458,15 +2458,18 @@ static struct rockchip_clk_branch rk3588_clk_branches[] __initdata = {
>  static void __init rk3588_clk_init(struct device_node *np)
>  {
>  	struct rockchip_clk_provider *ctx;
> +	unsigned long clk_nr_clks;
>  	void __iomem *reg_base;
>  
> +	clk_nr_clks = rockchip_clk_find_max_clk_id(rk3588_clk_branches,
> +					ARRAY_SIZE(rk3588_clk_branches)) + 1;
>  	reg_base = of_iomap(np, 0);
>  	if (!reg_base) {
>  		pr_err("%s: could not map cru region\n", __func__);
>  		return;
>  	}
>  
> -	ctx = rockchip_clk_init(np, reg_base, CLK_NR_CLKS);
> +	ctx = rockchip_clk_init(np, reg_base, clk_nr_clks);
>  	if (IS_ERR(ctx)) {
>  		pr_err("%s: rockchip clk init failed\n", __func__);
>  		iounmap(reg_base);
> diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
> index 4059d9365ae6..043458b7c579 100644
> --- a/drivers/clk/rockchip/clk.c
> +++ b/drivers/clk/rockchip/clk.c
> @@ -429,6 +429,23 @@ void rockchip_clk_register_plls(struct rockchip_clk_provider *ctx,
>  }
>  EXPORT_SYMBOL_GPL(rockchip_clk_register_plls);
>  
> +unsigned long rockchip_clk_find_max_clk_id(struct rockchip_clk_branch *list,
> +					   unsigned int nr_clk)
> +{
> +	unsigned int idx;
> +	unsigned long max;

smatch report warning: uninitialized symbol 'max'.
And make sure this function return correct number, for example, when nr_clk == 0.

> +
> +	for (idx = 0; idx < nr_clk; idx++, list++) {
> +		if (list->id > max)
> +			max = list->id;
> +		if (list->child && list->child->id > max)
> +			max = list->id;
> +	}
> +
> +	return max;
> +}
> +EXPORT_SYMBOL_GPL(rockchip_clk_find_max_clk_id);
> +
>  void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx,
>  				    struct rockchip_clk_branch *list,
>  				    unsigned int nr_clk)
> diff --git a/drivers/clk/rockchip/clk.h b/drivers/clk/rockchip/clk.h
> index 758ebaf2236b..fd3b476dedda 100644
> --- a/drivers/clk/rockchip/clk.h
> +++ b/drivers/clk/rockchip/clk.h
> @@ -973,6 +973,8 @@ struct rockchip_clk_provider *rockchip_clk_init(struct device_node *np,
>  			void __iomem *base, unsigned long nr_clks);
>  void rockchip_clk_of_add_provider(struct device_node *np,
>  				struct rockchip_clk_provider *ctx);
> +unsigned long rockchip_clk_find_max_clk_id(struct rockchip_clk_branch *list,
> +					   unsigned int nr_clk);
>  void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx,
>  				    struct rockchip_clk_branch *list,
>  				    unsigned int nr_clk);