[RFC v3 08/16] clk: starfive: Add JH8100 North-West clock generator driver

Stephen Boyd sboyd at kernel.org
Thu Apr 11 00:49:25 PDT 2024


Quoting Sia Jee Heng (2024-01-10 05:31:20)
> diff --git a/drivers/clk/starfive/clk-starfive-jh8100-nw.c b/drivers/clk/starfive/clk-starfive-jh8100-nw.c
> new file mode 100644
> index 000000000000..018f5af6c777
> --- /dev/null
> +++ b/drivers/clk/starfive/clk-starfive-jh8100-nw.c
> @@ -0,0 +1,237 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * StarFive JH8100 North-West Clock Driver
> + *
> + * Copyright (C) 2023 StarFive Technology Co., Ltd.
[...]
> +
> +static int jh8100_nwcrg_probe(struct platform_device *pdev)
> +{
> +       struct starfive_clk_priv *priv;
> +       unsigned int idx;
> +       int ret;
> +
> +       priv = devm_kzalloc(&pdev->dev,
> +                           struct_size(priv, reg, JH8100_NWCLK_NUM_CLKS),
> +                           GFP_KERNEL);
> +       if (!priv)
> +               return -ENOMEM;
> +
> +       spin_lock_init(&priv->rmw_lock);
> +       priv->dev = &pdev->dev;
> +       priv->base = devm_platform_ioremap_resource(pdev, 0);
> +       if (IS_ERR(priv->base))
> +               return PTR_ERR(priv->base);
> +
> +       for (idx = 0; idx < JH8100_NWCLK_NUM_CLKS; idx++) {
> +               u32 max = jh8100_nwcrg_clk_data[idx].max;
> +               struct clk_parent_data parents[4] = {};
> +               struct clk_init_data init = {
> +                       .name = jh8100_nwcrg_clk_data[idx].name,
> +                       .ops = starfive_clk_ops(max),
> +                       .parent_data = parents,
> +                       .num_parents =
> +                               ((max & STARFIVE_CLK_MUX_MASK) >> STARFIVE_CLK_MUX_SHIFT) + 1,
> +                       .flags = jh8100_nwcrg_clk_data[idx].flags,
> +               };
> +               struct starfive_clk *clk = &priv->reg[idx];
> +               unsigned int i;
> +
> +               for (i = 0; i < init.num_parents; i++) {
> +                       unsigned int pidx = jh8100_nwcrg_clk_data[idx].parents[i];
> +
> +                       if (pidx < JH8100_NWCLK_NUM_CLKS)
> +                               parents[i].hw = &priv->reg[pidx].hw;
> +                       else if (pidx == JH8100_NWCLK_OSC)
> +                               parents[i].fw_name = "osc";

Please generate this one time with structures and use an index instead
of string names. This is faster in multiple ways, and the parent data is
copied anyway.

> +                       else if (pidx == JH8100_NWCLK_APB_BUS)
> +                               parents[i].fw_name = "apb_bus";
> +                       else if (pidx == JH8100_NWCLK_APB_BUS_PER4)
> +                               parents[i].fw_name = "apb_bus_per4";



More information about the linux-riscv mailing list