]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ASoC: rsnd: Support hyphen or dot in indexed clock and reset names
authorJohn Madieu <john.madieu.xa@bp.renesas.com>
Mon, 25 May 2026 11:02:16 +0000 (11:02 +0000)
committerMark Brown <broonie@kernel.org>
Mon, 1 Jun 2026 14:30:14 +0000 (15:30 +0100)
The rsnd driver historically looks up per-instance clocks and resets
using dot-separated names matching the ones declared in R-Car device
tree bindings ("ssi.0", "src.0", "adg.ssi.0", ...). The dot separator
is unusual for device tree clock-names / reset-names and newer
Renesas SoC bindings (RZ/G3E and later) use the more standard hyphen
form ("ssi-0", "src-0", ...).

Rather than force every existing R-Car user to rename their DT entries,
add a small set of helpers that try the hyphen form first and fall
back to the dot form. While at it, convert the existing indexed
devm_clk_get() call sites in the SSI, SRC, CTU, DVC and MIX probes to use
the new helpers and drop the now unused per-module name buffers and
NAME_SIZE defines.

Signed-off-by: John Madieu <john.madieu.xa@bp.renesas.com>
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://patch.msgid.link/20260525110230.4014435-5-john.madieu.xa@bp.renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/renesas/rcar/core.c
sound/soc/renesas/rcar/ctu.c
sound/soc/renesas/rcar/dvc.c
sound/soc/renesas/rcar/mix.c
sound/soc/renesas/rcar/rsnd.h
sound/soc/renesas/rcar/src.c
sound/soc/renesas/rcar/ssi.c

index 2038e3079a9a5b252ff35d4dc5195ab6ad5ae331..a60b7a5d90ad4d920dbc09513649703277131bc9 100644 (file)
@@ -1232,6 +1232,73 @@ int rsnd_node_count(struct rsnd_priv *priv, struct device_node *node, char *name
        return i;
 }
 
+/*
+ * Build "<base>-<index>" or "<base>.<index>" and try the hyphen form first,
+ * falling back to the dot form if the hyphen form is not present. This lets
+ * the driver accept both the new DT convention ("ssi-0", "src-0", ...) and
+ * the legacy R-Car convention ("ssi.0", "src.0", ...) transparently.
+ *
+ * @base: name prefix ("ssi", "src", "ctu", "mix", "dvc", "adg.ssi", ...)
+ * @index: integer suffix
+ *
+ * On -ENOENT from the hyphen form, the dot form is tried. All other errors
+ * (including -EPROBE_DEFER) are returned to the caller unchanged, so
+ * behaviour against the clock and reset frameworks is preserved.
+ */
+#define RSND_INDEXED_NAME_MAX  32
+
+static void rsnd_format_indexed_name(char *buf, size_t buflen, char sep,
+                                    const char *base, int index)
+{
+       snprintf(buf, buflen, "%s%c%d", base, sep, index);
+}
+
+struct clk *rsnd_devm_clk_get_indexed(struct device *dev,
+                                     const char *base, int index)
+{
+       char name[RSND_INDEXED_NAME_MAX];
+       struct clk *clk;
+
+       rsnd_format_indexed_name(name, sizeof(name), '-', base, index);
+       clk = devm_clk_get(dev, name);
+       if (!IS_ERR(clk) || PTR_ERR(clk) != -ENOENT)
+               return clk;
+
+       rsnd_format_indexed_name(name, sizeof(name), '.', base, index);
+       return devm_clk_get(dev, name);
+}
+
+struct clk *rsnd_devm_clk_get_optional_indexed(struct device *dev,
+                                              const char *base, int index)
+{
+       char name[RSND_INDEXED_NAME_MAX];
+       struct clk *clk;
+
+       rsnd_format_indexed_name(name, sizeof(name), '-', base, index);
+       clk = devm_clk_get_optional(dev, name);
+       if (IS_ERR(clk) || clk)
+               return clk;
+
+       rsnd_format_indexed_name(name, sizeof(name), '.', base, index);
+       return devm_clk_get_optional(dev, name);
+}
+
+struct reset_control *
+rsnd_devm_reset_control_get_optional_indexed(struct device *dev,
+                                            const char *base, int index)
+{
+       char name[RSND_INDEXED_NAME_MAX];
+       struct reset_control *rstc;
+
+       rsnd_format_indexed_name(name, sizeof(name), '-', base, index);
+       rstc = devm_reset_control_get_optional(dev, name);
+       if (IS_ERR(rstc) || rstc)
+               return rstc;
+
+       rsnd_format_indexed_name(name, sizeof(name), '.', base, index);
+       return devm_reset_control_get_optional(dev, name);
+}
+
 static struct device_node*
        rsnd_pick_endpoint_node_for_ports(struct device_node *e_ports,
                                          struct device_node *e_port)
index 81bba6a1af6e5c3f6f1a7c3c3e54506c367e2a78..293b0eec1dedc9bd34ac508bc55038206c9a5479 100644 (file)
@@ -6,7 +6,6 @@
 
 #include "rsnd.h"
 
-#define CTU_NAME_SIZE  16
 #define CTU_NAME "ctu"
 
 /*
@@ -319,7 +318,6 @@ int rsnd_ctu_probe(struct rsnd_priv *priv)
        struct device *dev = rsnd_priv_to_dev(priv);
        struct rsnd_ctu *ctu;
        struct clk *clk;
-       char name[CTU_NAME_SIZE];
        int i, nr, ret;
 
        node = rsnd_ctu_of_node(priv);
@@ -350,10 +348,7 @@ int rsnd_ctu_probe(struct rsnd_priv *priv)
                 * CTU00, CTU01, CTU02, CTU03 => CTU0
                 * CTU10, CTU11, CTU12, CTU13 => CTU1
                 */
-               snprintf(name, CTU_NAME_SIZE, "%s.%d",
-                        CTU_NAME, i / 4);
-
-               clk = devm_clk_get(dev, name);
+               clk = rsnd_devm_clk_get_indexed(dev, CTU_NAME, i / 4);
                if (IS_ERR(clk)) {
                        ret = PTR_ERR(clk);
                        goto rsnd_ctu_probe_done;
index bf7146ceb5f62181d5f7bf66e3f039a9d0c0c4c0..26f80d542da87e7fd6d6bb971c6a070e1f6165ce 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "rsnd.h"
 
-#define RSND_DVC_NAME_SIZE     16
 
 #define DVC_NAME "dvc"
 
@@ -327,7 +326,6 @@ int rsnd_dvc_probe(struct rsnd_priv *priv)
        struct device *dev = rsnd_priv_to_dev(priv);
        struct rsnd_dvc *dvc;
        struct clk *clk;
-       char name[RSND_DVC_NAME_SIZE];
        int i, nr, ret;
 
        node = rsnd_dvc_of_node(priv);
@@ -354,10 +352,7 @@ int rsnd_dvc_probe(struct rsnd_priv *priv)
        for_each_child_of_node_scoped(node, np) {
                dvc = rsnd_dvc_get(priv, i);
 
-               snprintf(name, RSND_DVC_NAME_SIZE, "%s.%d",
-                        DVC_NAME, i);
-
-               clk = devm_clk_get(dev, name);
+               clk = rsnd_devm_clk_get_indexed(dev, DVC_NAME, i);
                if (IS_ERR(clk)) {
                        ret = PTR_ERR(clk);
                        goto rsnd_dvc_probe_done;
index 566e9b2a488cdf3bf2bd3a0ad18369e8ab7d1347..9ffa591aa4a433fee1b3ddf817c59795ed6ec89d 100644 (file)
@@ -32,7 +32,6 @@
 
 #include "rsnd.h"
 
-#define MIX_NAME_SIZE  16
 #define MIX_NAME "mix"
 
 struct rsnd_mix {
@@ -291,7 +290,6 @@ int rsnd_mix_probe(struct rsnd_priv *priv)
        struct device *dev = rsnd_priv_to_dev(priv);
        struct rsnd_mix *mix;
        struct clk *clk;
-       char name[MIX_NAME_SIZE];
        int i, nr, ret;
 
        node = rsnd_mix_of_node(priv);
@@ -318,10 +316,7 @@ int rsnd_mix_probe(struct rsnd_priv *priv)
        for_each_child_of_node_scoped(node, np) {
                mix = rsnd_mix_get(priv, i);
 
-               snprintf(name, MIX_NAME_SIZE, "%s.%d",
-                        MIX_NAME, i);
-
-               clk = devm_clk_get(dev, name);
+               clk = rsnd_devm_clk_get_indexed(dev, MIX_NAME, i);
                if (IS_ERR(clk)) {
                        ret = PTR_ERR(clk);
                        goto rsnd_mix_probe_done;
index 3d419b31cf405ac501afe9e0ae1daa5cf924c537..f3f1ad1180f8878cffed7860513389f707a02f79 100644 (file)
@@ -476,6 +476,25 @@ int rsnd_runtime_is_multi_ssi(struct rsnd_dai_stream *io);
 int rsnd_runtime_is_tdm(struct rsnd_dai_stream *io);
 int rsnd_runtime_is_tdm_split(struct rsnd_dai_stream *io);
 
+/*
+ * Indexed clock and reset name helpers.
+ *
+ * Historically the rsnd driver has looked up per-instance clocks and
+ * resets using dot-separated names (e.g. "ssi.0", "src.0", "adg.ssi.0").
+ * Newer Renesas SoC bindings (RZ/G3E and later) use hyphen-separated
+ * names ("ssi-0", "src-0", ...) to follow the standard Device Tree
+ * naming convention. These helpers look up the hyphenated name first
+ * and transparently fall back to the dotted name, so a single driver
+ * build supports both conventions.
+ */
+struct clk *rsnd_devm_clk_get_indexed(struct device *dev,
+                                     const char *base, int index);
+struct clk *rsnd_devm_clk_get_optional_indexed(struct device *dev,
+                                              const char *base, int index);
+struct reset_control *
+rsnd_devm_reset_control_get_optional_indexed(struct device *dev,
+                                            const char *base, int index);
+
 /*
  * DT
  */
index 8b58cc20e7a836bb983866b3b7d77fa15b3d0131..43abe13137bfd7960294daae3f9b89e10caea67f 100644 (file)
@@ -39,7 +39,6 @@ struct rsnd_src {
        int irq;
 };
 
-#define RSND_SRC_NAME_SIZE 16
 
 #define rsnd_src_get(priv, id) ((struct rsnd_src *)(priv->src) + id)
 #define rsnd_src_nr(priv) ((priv)->src_nr)
@@ -715,7 +714,6 @@ int rsnd_src_probe(struct rsnd_priv *priv)
        struct device *dev = rsnd_priv_to_dev(priv);
        struct rsnd_src *src;
        struct clk *clk;
-       char name[RSND_SRC_NAME_SIZE];
        int i, nr, ret;
 
        node = rsnd_src_of_node(priv);
@@ -750,16 +748,13 @@ int rsnd_src_probe(struct rsnd_priv *priv)
 
                src = rsnd_src_get(priv, i);
 
-               snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
-                        SRC_NAME, i);
-
                src->irq = irq_of_parse_and_map(np, 0);
                if (!src->irq) {
                        ret = -EINVAL;
                        goto rsnd_src_probe_done;
                }
 
-               clk = devm_clk_get(dev, name);
+               clk = rsnd_devm_clk_get_indexed(dev, SRC_NAME, i);
                if (IS_ERR(clk)) {
                        ret = PTR_ERR(clk);
                        goto rsnd_src_probe_done;
index c06cebb36170ca261303fcb543be69cc66249e1b..cf98cc9ee44c3dc5cacb8d55a1115362729850da 100644 (file)
@@ -21,7 +21,6 @@
 #include <linux/of_irq.h>
 #include <linux/delay.h>
 #include "rsnd.h"
-#define RSND_SSI_NAME_SIZE 16
 
 /*
  * SSICR
@@ -1163,7 +1162,6 @@ int rsnd_ssi_probe(struct rsnd_priv *priv)
        struct rsnd_mod_ops *ops;
        struct clk *clk;
        struct rsnd_ssi *ssi;
-       char name[RSND_SSI_NAME_SIZE];
        int i, nr, ret;
 
        node = rsnd_ssi_of_node(priv);
@@ -1198,10 +1196,7 @@ int rsnd_ssi_probe(struct rsnd_priv *priv)
 
                ssi = rsnd_ssi_get(priv, i);
 
-               snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
-                        SSI_NAME, i);
-
-               clk = devm_clk_get(dev, name);
+               clk = rsnd_devm_clk_get_indexed(dev, SSI_NAME, i);
                if (IS_ERR(clk)) {
                        ret = PTR_ERR(clk);
                        goto rsnd_ssi_probe_done;