From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Stephen Boyd" <sboyd@kernel.org>,
"Brian Masney" <bmasney+clk@redhat.com>,
"Jerome Brunet" <jbrunet+clk@baylibre.com>,
"Ulf Hansson" <ulfh@kernel.org>,
"Philipp Zabel" <p.zabel@pengutronix.de>,
"Rafael J . Wysocki" <rafael@kernel.org>,
"Marek Vasut" <marek.vasut+renesas@mailbox.org>,
"Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>,
"Konrad Dybcio" <konrad.dybcio@oss.qualcomm.com>,
"Kevin Hilman" <khilman@baylibre.com>,
"Vinod Koul" <vkoul@kernel.org>,
"Wolfram Sang" <wsa+renesas@sang-engineering.com>,
"Kuninori Morimoto" <kuninori.morimoto.gx@renesas.com>,
"Paul Elder" <paul.elder+renesas@ideasonboard.com>,
"Clément Le Goffic" <clegoffic@baylibre.com>,
"Sudeep Holla" <sudeep.holla@kernel.org>,
"Cristian Marussi" <cristian.marussi@arm.com>,
arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
devicetree@vger.kernel.org, linux-clk@vger.kernel.org,
linux-pm@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH v5 04/15] clk: renesas: r8a78000: Add clk_hw to clk_map
Date: Mon, 23 Nov 2026 13:24:50 +0200 [thread overview]
Message-ID: <20261123112450.GF3010398@killaraus.ideasonboard.com> (raw)
In-Reply-To: <ea85d72ca37bc7abc59fda5aed4b8272578922c4.1795029012.git.geert+renesas@glider.be>
On Wed, Nov 18, 2026 at 08:44:52PM +0100, Geert Uytterhoeven wrote:
> Prepare for mapping to other than fixed-rate clocks by adding an array
> of clk_hw pointers, indexed by the clock map entry index, and populating
> it up-front.
>
> Move r8a78000_cpg_priv.fixed_hws into get_hws(), as it is no longer
> needed afterwards, and drop NUM_FIXED_CLKS.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
> v5:
> - Add Tested-by,
> - Rebase,
> - Use kzalloc_objs() and __free() instead of devm_k{calloc,free}() for
> the temporary array of fixed clocks,
> - Replace devm_kcalloc() by devm_kzalloc_objs(),
> - Replace unified clk_map by keeping the original clk_id_map and
> adding a separate array of clk_hw pointers,
> - Let clk_id_map_find() return an index,
> - Replace fill_clk_map() by get_hws(),
>
> v4:
> - No changes,
>
> v3:
> - New.
> ---
> drivers/clk/renesas/r8a78000-cpg.c | 71 ++++++++++++++++++++----------
> 1 file changed, 48 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/clk/renesas/r8a78000-cpg.c b/drivers/clk/renesas/r8a78000-cpg.c
> index 236c638834703f95..fd97e1558d423f95 100644
> --- a/drivers/clk/renesas/r8a78000-cpg.c
> +++ b/drivers/clk/renesas/r8a78000-cpg.c
> @@ -5,6 +5,7 @@
> * Copyright (C) 2026 Glider bv
> */
>
> +#include <linux/cleanup.h>
> #include <linux/clk.h>
> #include <linux/clk-provider.h>
> #include <linux/dev_printk.h>
> @@ -35,10 +36,9 @@ enum fixed_clk {
> FIXED_CLK_66M,
> FIXED_CLK_133M,
> FIXED_CLK_266M,
> - NUM_FIXED_CLKS
> };
>
> -static const unsigned long fixed_clk_rates[NUM_FIXED_CLKS] = {
> +static const unsigned long fixed_clk_rates[] = {
> [FIXED_CLK_66M] = 66666000,
> [FIXED_CLK_133M] = 133330000,
> [FIXED_CLK_266M] = 266660000,
> @@ -51,31 +51,30 @@ static const unsigned long fixed_clk_rates[NUM_FIXED_CLKS] = {
> *
> * @dev: CPG device
> * @map: Mapping from DT clock IDs to fixed-rate clock IDs
> - * @fixed_hws: Fixed rate clocks
> + * @hws: Clocks, indexed by @map entry index
> */
> struct r8a78000_cpg_priv {
> struct device *dev;
> const struct clk_id_map *map;
> - struct clk_hw *fixed_hws[NUM_FIXED_CLKS];
> + struct clk_hw **hws;
> };
>
> -static const struct clk_id_map_entry *clk_id_map_find(const struct clk_id_map *map,
> - u32 dt_id)
> +static int clk_id_map_find(const struct clk_id_map *map, u32 dt_id)
While at it, I'd recommend adding a r8a78000_ prefix to this and other
functions below to avoid future namespace clashes.
> {
> for (unsigned int i = 0; i < map->size; i++) {
> if (map->entries[i].dt_id == dt_id)
> - return &map->entries[i];
> + return i;
> }
>
> - return NULL;
> + return -1;
> }
>
> static struct clk_hw *r8a78000_clk_get(struct of_phandle_args *spec, void *data)
> {
> struct r8a78000_cpg_priv *priv = data;
> - const struct clk_id_map_entry *entry;
> struct device *dev = priv->dev;
> struct clk_hw *hw;
> + int idx;
> u32 id;
>
> if (spec->args_count != 1)
> @@ -83,13 +82,13 @@ static struct clk_hw *r8a78000_clk_get(struct of_phandle_args *spec, void *data)
>
> id = spec->args[0];
>
> - entry = clk_id_map_find(priv->map, id);
> - if (!entry) {
> + idx = clk_id_map_find(priv->map, id);
> + if (idx < 0) {
> dev_err(dev, "Unknown clock %u\n", id);
> return ERR_PTR(-ENOENT);
> }
>
> - hw = priv->fixed_hws[entry->fw_id];
> + hw = priv->hws[idx];
>
> dev_dbg(dev, "Mapping DT clock %u to %s at %lu Hz\n", id,
> clk_hw_get_name(hw), clk_hw_get_rate(hw));
> @@ -97,27 +96,54 @@ static struct clk_hw *r8a78000_clk_get(struct of_phandle_args *spec, void *data)
> return hw;
> }
>
> -static int register_fixed_clks(struct r8a78000_cpg_priv *priv)
> +static struct clk_hw **register_fixed_clks(struct device *dev)
I would have kept the r8a78000_cpg_priv argument for consistency. Not a
big deal, up to you.
> {
> - struct device *dev = priv->dev;
> + unsigned int n = ARRAY_SIZE(fixed_clk_rates);
> unsigned long rate;
> struct clk_hw *hw;
> const char *name;
Those three variables can be moved within the loop. Also up to you.
>
> - for (unsigned int i = 0; i < ARRAY_SIZE(fixed_clk_rates); i++) {
> + struct clk_hw **hws __free(kfree) = kzalloc_objs(*hws, n);
> + if (!hws)
> + return ERR_PTR(-ENOMEM);
> +
> + for (unsigned int i = 0; i < n; i++) {
> rate = fixed_clk_rates[i];
> name = devm_kasprintf(dev, GFP_KERNEL, "cpg-%lu", rate);
> if (!name)
> - return -ENOMEM;
> + return ERR_PTR(-ENOMEM);
>
> hw = devm_clk_hw_register_fixed_rate(dev, name, NULL, 0, rate);
> if (IS_ERR(hw))
> - return PTR_ERR(hw);
> + return ERR_CAST(hw);
> +
> + hws[i] = hw;
> + }
> +
> + return_ptr(hws);
> +}
>
> - priv->fixed_hws[i] = hw;
> +static struct clk_hw **get_hws(struct r8a78000_cpg_priv *priv)
> +{
> + const struct clk_id_map *map = priv->map;
> + struct device *dev = priv->dev;
> + struct clk_hw **hws;
> + u16 fw_id;
This can also be moved within the loop.
> +
> + struct clk_hw **fixed_hws __free(kfree) = register_fixed_clks(dev);
> + if (IS_ERR(fixed_hws))
> + return ERR_CAST(fixed_hws);
> +
> + hws = devm_kzalloc_objs(dev, *hws, map->size);
> + if (!hws)
> + return ERR_PTR(-ENOMEM);
> +
> + for (unsigned int i = 0; i < map->size; i++) {
> + fw_id = map->entries[i].fw_id;
> + hws[i] = fixed_hws[fw_id];
> }
>
> - return 0;
> + return hws;
> }
>
> static int r8a78000_cpg_probe(struct platform_device *pdev)
> @@ -125,7 +151,6 @@ static int r8a78000_cpg_probe(struct platform_device *pdev)
> struct device *dev = &pdev->dev;
> struct r8a78000_cpg_priv *priv;
> const struct clk_id_map *map;
> - int ret;
>
> map = of_device_get_match_data(dev);
> if (!map)
> @@ -138,9 +163,9 @@ static int r8a78000_cpg_probe(struct platform_device *pdev)
> priv->dev = dev;
> priv->map = map;
>
> - ret = register_fixed_clks(priv);
> - if (ret)
> - return ret;
> + priv->hws = get_hws(priv);
> + if (IS_ERR(priv->hws))
> + return PTR_ERR(priv->hws);
>
> return devm_of_clk_add_hw_provider(dev, r8a78000_clk_get, priv);
> }
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2026-11-23 11:24 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 19:44 [PATCH v5 00/15] R-Car X5H Ironhide CPG/MDLC SCMI remapping support Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 01/15] clk: renesas: r8a78000: Merge debug prints in r8a78000_clk_get() Geert Uytterhoeven
2026-11-20 2:57 ` Marek Vasut
2026-11-20 7:56 ` Geert Uytterhoeven
2026-11-23 10:57 ` Laurent Pinchart
2026-11-18 19:44 ` [PATCH v5 02/15] clk: renesas: r8a78000: Replace sentinel by explicit ID map size Geert Uytterhoeven
2026-11-20 3:02 ` Marek Vasut
2026-11-23 11:01 ` Laurent Pinchart
2026-11-18 19:44 ` [PATCH v5 03/15] clk: renesas: r8a78000: Shrink IDs to 16 bits Geert Uytterhoeven
2026-11-20 3:04 ` Marek Vasut
2026-11-23 11:12 ` Laurent Pinchart
2026-11-18 19:44 ` [PATCH v5 04/15] clk: renesas: r8a78000: Add clk_hw to clk_map Geert Uytterhoeven
2026-11-20 3:25 ` Marek Vasut
2026-11-23 11:24 ` Laurent Pinchart [this message]
2026-11-18 19:44 ` [PATCH v5 05/15] clk: renesas: r8a78000: Add SCMI remapping support Geert Uytterhoeven
2026-11-20 3:45 ` Marek Vasut
2026-11-23 11:36 ` Laurent Pinchart
2026-11-18 19:44 ` [PATCH v5 06/15] reset: Extract __reset_control_get_from_provider() Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 07/15] reset: Add reset_control_get_from_provider_exclusive() Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 08/15] pmdomain: Make genpd_get_from_provider() always return on first match Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 09/15] pmdomain: Make genpd_get_from_provider() return -EPROBE_DEFER Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 10/15] pmdomain: Make genpd_get_from_provider() public Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 11/15] pmdomain: renesas: r8a78000: Drop MDLC name comment Geert Uytterhoeven
2026-11-20 3:35 ` Marek Vasut
2026-11-23 11:37 ` Laurent Pinchart
2026-11-18 19:45 ` [PATCH v5 12/15] pmdomain: renesas: r8a78000: Replace sentinel by explicit ID map size Geert Uytterhoeven
2026-11-20 3:36 ` Marek Vasut
2026-11-23 11:39 ` Laurent Pinchart
2026-11-18 19:45 ` [PATCH v5 13/15] pmdomain: renesas: r8a78000: Shrink IDs to 16 bits Geert Uytterhoeven
2026-11-20 3:37 ` Marek Vasut
2026-11-23 11:39 ` Laurent Pinchart
2026-11-18 19:45 ` [PATCH v5 14/15] pmdomain: renesas: r8a78000: Add SCMI remapping support Geert Uytterhoeven
2026-11-18 20:22 ` sashiko-bot
2026-11-19 7:48 ` Geert Uytterhoeven
2026-11-18 19:45 ` [PATCH v5 15/15] arm64: dts: renesas: ironhide: Enable SCMI devpd, sys, clock, and reset Geert Uytterhoeven
2026-11-19 14:47 ` [PATCH v5 00/15] R-Car X5H Ironhide CPG/MDLC SCMI remapping support Clément Le Goffic
2026-11-19 23:47 ` Laurent Pinchart
2026-11-20 10:29 ` Clément Le Goffic
2026-11-20 11:10 ` Wolfram Sang
2026-11-20 14:33 ` Clément Le Goffic
2026-11-23 10:36 ` Laurent Pinchart
2026-11-23 10:31 ` Laurent Pinchart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123112450.GF3010398@killaraus.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=arm-scmi@vger.kernel.org \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=bmasney+clk@redhat.com \
--cc=clegoffic@baylibre.com \
--cc=conor+dt@kernel.org \
--cc=cristian.marussi@arm.com \
--cc=devicetree@vger.kernel.org \
--cc=geert+renesas@glider.be \
--cc=jbrunet+clk@baylibre.com \
--cc=khilman@baylibre.com \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=krzk+dt@kernel.org \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=marek.vasut+renesas@mailbox.org \
--cc=p.zabel@pengutronix.de \
--cc=paul.elder+renesas@ideasonboard.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=sudeep.holla@kernel.org \
--cc=ulfh@kernel.org \
--cc=vkoul@kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox