Skip to content

Commit 22622fa

Browse files
John Madieubroonie
authored andcommitted
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>
1 parent 83c9631 commit 22622fa

7 files changed

Lines changed: 91 additions & 30 deletions

File tree

sound/soc/renesas/rcar/core.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,73 @@ int rsnd_node_count(struct rsnd_priv *priv, struct device_node *node, char *name
12321232
return i;
12331233
}
12341234

1235+
/*
1236+
* Build "<base>-<index>" or "<base>.<index>" and try the hyphen form first,
1237+
* falling back to the dot form if the hyphen form is not present. This lets
1238+
* the driver accept both the new DT convention ("ssi-0", "src-0", ...) and
1239+
* the legacy R-Car convention ("ssi.0", "src.0", ...) transparently.
1240+
*
1241+
* @base: name prefix ("ssi", "src", "ctu", "mix", "dvc", "adg.ssi", ...)
1242+
* @index: integer suffix
1243+
*
1244+
* On -ENOENT from the hyphen form, the dot form is tried. All other errors
1245+
* (including -EPROBE_DEFER) are returned to the caller unchanged, so
1246+
* behaviour against the clock and reset frameworks is preserved.
1247+
*/
1248+
#define RSND_INDEXED_NAME_MAX 32
1249+
1250+
static void rsnd_format_indexed_name(char *buf, size_t buflen, char sep,
1251+
const char *base, int index)
1252+
{
1253+
snprintf(buf, buflen, "%s%c%d", base, sep, index);
1254+
}
1255+
1256+
struct clk *rsnd_devm_clk_get_indexed(struct device *dev,
1257+
const char *base, int index)
1258+
{
1259+
char name[RSND_INDEXED_NAME_MAX];
1260+
struct clk *clk;
1261+
1262+
rsnd_format_indexed_name(name, sizeof(name), '-', base, index);
1263+
clk = devm_clk_get(dev, name);
1264+
if (!IS_ERR(clk) || PTR_ERR(clk) != -ENOENT)
1265+
return clk;
1266+
1267+
rsnd_format_indexed_name(name, sizeof(name), '.', base, index);
1268+
return devm_clk_get(dev, name);
1269+
}
1270+
1271+
struct clk *rsnd_devm_clk_get_optional_indexed(struct device *dev,
1272+
const char *base, int index)
1273+
{
1274+
char name[RSND_INDEXED_NAME_MAX];
1275+
struct clk *clk;
1276+
1277+
rsnd_format_indexed_name(name, sizeof(name), '-', base, index);
1278+
clk = devm_clk_get_optional(dev, name);
1279+
if (IS_ERR(clk) || clk)
1280+
return clk;
1281+
1282+
rsnd_format_indexed_name(name, sizeof(name), '.', base, index);
1283+
return devm_clk_get_optional(dev, name);
1284+
}
1285+
1286+
struct reset_control *
1287+
rsnd_devm_reset_control_get_optional_indexed(struct device *dev,
1288+
const char *base, int index)
1289+
{
1290+
char name[RSND_INDEXED_NAME_MAX];
1291+
struct reset_control *rstc;
1292+
1293+
rsnd_format_indexed_name(name, sizeof(name), '-', base, index);
1294+
rstc = devm_reset_control_get_optional(dev, name);
1295+
if (IS_ERR(rstc) || rstc)
1296+
return rstc;
1297+
1298+
rsnd_format_indexed_name(name, sizeof(name), '.', base, index);
1299+
return devm_reset_control_get_optional(dev, name);
1300+
}
1301+
12351302
static struct device_node*
12361303
rsnd_pick_endpoint_node_for_ports(struct device_node *e_ports,
12371304
struct device_node *e_port)

sound/soc/renesas/rcar/ctu.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "rsnd.h"
88

9-
#define CTU_NAME_SIZE 16
109
#define CTU_NAME "ctu"
1110

1211
/*
@@ -319,7 +318,6 @@ int rsnd_ctu_probe(struct rsnd_priv *priv)
319318
struct device *dev = rsnd_priv_to_dev(priv);
320319
struct rsnd_ctu *ctu;
321320
struct clk *clk;
322-
char name[CTU_NAME_SIZE];
323321
int i, nr, ret;
324322

325323
node = rsnd_ctu_of_node(priv);
@@ -350,10 +348,7 @@ int rsnd_ctu_probe(struct rsnd_priv *priv)
350348
* CTU00, CTU01, CTU02, CTU03 => CTU0
351349
* CTU10, CTU11, CTU12, CTU13 => CTU1
352350
*/
353-
snprintf(name, CTU_NAME_SIZE, "%s.%d",
354-
CTU_NAME, i / 4);
355-
356-
clk = devm_clk_get(dev, name);
351+
clk = rsnd_devm_clk_get_indexed(dev, CTU_NAME, i / 4);
357352
if (IS_ERR(clk)) {
358353
ret = PTR_ERR(clk);
359354
goto rsnd_ctu_probe_done;

sound/soc/renesas/rcar/dvc.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
#include "rsnd.h"
3131

32-
#define RSND_DVC_NAME_SIZE 16
3332

3433
#define DVC_NAME "dvc"
3534

@@ -327,7 +326,6 @@ int rsnd_dvc_probe(struct rsnd_priv *priv)
327326
struct device *dev = rsnd_priv_to_dev(priv);
328327
struct rsnd_dvc *dvc;
329328
struct clk *clk;
330-
char name[RSND_DVC_NAME_SIZE];
331329
int i, nr, ret;
332330

333331
node = rsnd_dvc_of_node(priv);
@@ -354,10 +352,7 @@ int rsnd_dvc_probe(struct rsnd_priv *priv)
354352
for_each_child_of_node_scoped(node, np) {
355353
dvc = rsnd_dvc_get(priv, i);
356354

357-
snprintf(name, RSND_DVC_NAME_SIZE, "%s.%d",
358-
DVC_NAME, i);
359-
360-
clk = devm_clk_get(dev, name);
355+
clk = rsnd_devm_clk_get_indexed(dev, DVC_NAME, i);
361356
if (IS_ERR(clk)) {
362357
ret = PTR_ERR(clk);
363358
goto rsnd_dvc_probe_done;

sound/soc/renesas/rcar/mix.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
#include "rsnd.h"
3434

35-
#define MIX_NAME_SIZE 16
3635
#define MIX_NAME "mix"
3736

3837
struct rsnd_mix {
@@ -291,7 +290,6 @@ int rsnd_mix_probe(struct rsnd_priv *priv)
291290
struct device *dev = rsnd_priv_to_dev(priv);
292291
struct rsnd_mix *mix;
293292
struct clk *clk;
294-
char name[MIX_NAME_SIZE];
295293
int i, nr, ret;
296294

297295
node = rsnd_mix_of_node(priv);
@@ -318,10 +316,7 @@ int rsnd_mix_probe(struct rsnd_priv *priv)
318316
for_each_child_of_node_scoped(node, np) {
319317
mix = rsnd_mix_get(priv, i);
320318

321-
snprintf(name, MIX_NAME_SIZE, "%s.%d",
322-
MIX_NAME, i);
323-
324-
clk = devm_clk_get(dev, name);
319+
clk = rsnd_devm_clk_get_indexed(dev, MIX_NAME, i);
325320
if (IS_ERR(clk)) {
326321
ret = PTR_ERR(clk);
327322
goto rsnd_mix_probe_done;

sound/soc/renesas/rcar/rsnd.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,25 @@ int rsnd_runtime_is_multi_ssi(struct rsnd_dai_stream *io);
476476
int rsnd_runtime_is_tdm(struct rsnd_dai_stream *io);
477477
int rsnd_runtime_is_tdm_split(struct rsnd_dai_stream *io);
478478

479+
/*
480+
* Indexed clock and reset name helpers.
481+
*
482+
* Historically the rsnd driver has looked up per-instance clocks and
483+
* resets using dot-separated names (e.g. "ssi.0", "src.0", "adg.ssi.0").
484+
* Newer Renesas SoC bindings (RZ/G3E and later) use hyphen-separated
485+
* names ("ssi-0", "src-0", ...) to follow the standard Device Tree
486+
* naming convention. These helpers look up the hyphenated name first
487+
* and transparently fall back to the dotted name, so a single driver
488+
* build supports both conventions.
489+
*/
490+
struct clk *rsnd_devm_clk_get_indexed(struct device *dev,
491+
const char *base, int index);
492+
struct clk *rsnd_devm_clk_get_optional_indexed(struct device *dev,
493+
const char *base, int index);
494+
struct reset_control *
495+
rsnd_devm_reset_control_get_optional_indexed(struct device *dev,
496+
const char *base, int index);
497+
479498
/*
480499
* DT
481500
*/

sound/soc/renesas/rcar/src.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ struct rsnd_src {
3939
int irq;
4040
};
4141

42-
#define RSND_SRC_NAME_SIZE 16
4342

4443
#define rsnd_src_get(priv, id) ((struct rsnd_src *)(priv->src) + id)
4544
#define rsnd_src_nr(priv) ((priv)->src_nr)
@@ -715,7 +714,6 @@ int rsnd_src_probe(struct rsnd_priv *priv)
715714
struct device *dev = rsnd_priv_to_dev(priv);
716715
struct rsnd_src *src;
717716
struct clk *clk;
718-
char name[RSND_SRC_NAME_SIZE];
719717
int i, nr, ret;
720718

721719
node = rsnd_src_of_node(priv);
@@ -750,16 +748,13 @@ int rsnd_src_probe(struct rsnd_priv *priv)
750748

751749
src = rsnd_src_get(priv, i);
752750

753-
snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
754-
SRC_NAME, i);
755-
756751
src->irq = irq_of_parse_and_map(np, 0);
757752
if (!src->irq) {
758753
ret = -EINVAL;
759754
goto rsnd_src_probe_done;
760755
}
761756

762-
clk = devm_clk_get(dev, name);
757+
clk = rsnd_devm_clk_get_indexed(dev, SRC_NAME, i);
763758
if (IS_ERR(clk)) {
764759
ret = PTR_ERR(clk);
765760
goto rsnd_src_probe_done;

sound/soc/renesas/rcar/ssi.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <linux/of_irq.h>
2222
#include <linux/delay.h>
2323
#include "rsnd.h"
24-
#define RSND_SSI_NAME_SIZE 16
2524

2625
/*
2726
* SSICR
@@ -1163,7 +1162,6 @@ int rsnd_ssi_probe(struct rsnd_priv *priv)
11631162
struct rsnd_mod_ops *ops;
11641163
struct clk *clk;
11651164
struct rsnd_ssi *ssi;
1166-
char name[RSND_SSI_NAME_SIZE];
11671165
int i, nr, ret;
11681166

11691167
node = rsnd_ssi_of_node(priv);
@@ -1198,10 +1196,7 @@ int rsnd_ssi_probe(struct rsnd_priv *priv)
11981196

11991197
ssi = rsnd_ssi_get(priv, i);
12001198

1201-
snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
1202-
SSI_NAME, i);
1203-
1204-
clk = devm_clk_get(dev, name);
1199+
clk = rsnd_devm_clk_get_indexed(dev, SSI_NAME, i);
12051200
if (IS_ERR(clk)) {
12061201
ret = PTR_ERR(clk);
12071202
goto rsnd_ssi_probe_done;

0 commit comments

Comments
 (0)