ASoC: rsnd: Support hyphen or dot in indexed clock and reset names

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>
This commit is contained in:
John Madieu 2026-05-25 11:02:16 +00:00 committed by Mark Brown
parent 83c9631e97
commit 22622faf81
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
7 changed files with 91 additions and 30 deletions

View 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)

View 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;

View 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;

View 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;

View 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
*/

View 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;

View 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;