From ec02b5a1d1c91b1e05b62f8092252137cf9be488 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Mon, 31 May 2021 13:19:09 +0900 Subject: [PATCH 1/4] ASoC: rsnd: tidyup rsnd_parse_connect_common() This patch adds "char *name" to rsnd_parse_connect_common(). It is not yet used so far, but is preparation for next "ASoC: rsnd: adjust disabled module" patch Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/87a6obk01v.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/sh/rcar/core.c | 2 +- sound/soc/sh/rcar/rsnd.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c index 2dc8aee4ac12..c85f1310a8fa 100644 --- a/sound/soc/sh/rcar/core.c +++ b/sound/soc/sh/rcar/core.c @@ -1125,7 +1125,7 @@ static void rsnd_parse_connect_graph(struct rsnd_priv *priv, of_node_put(remote_node); } -void rsnd_parse_connect_common(struct rsnd_dai *rdai, +void rsnd_parse_connect_common(struct rsnd_dai *rdai, char *name, struct rsnd_mod* (*mod_get)(struct rsnd_priv *priv, int id), struct device_node *node, struct device_node *playback, diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h index d712615c9c9f..9269ab83967c 100644 --- a/sound/soc/sh/rcar/rsnd.h +++ b/sound/soc/sh/rcar/rsnd.h @@ -460,7 +460,7 @@ struct rsnd_mod *rsnd_mod_next(int *iterator, #define for_each_rsnd_mod_array(iterator, pos, io, array) \ for_each_rsnd_mod_arrays(iterator, pos, io, array, ARRAY_SIZE(array)) -void rsnd_parse_connect_common(struct rsnd_dai *rdai, +void rsnd_parse_connect_common(struct rsnd_dai *rdai, char *name, struct rsnd_mod* (*mod_get)(struct rsnd_priv *priv, int id), struct device_node *node, struct device_node *playback, @@ -827,7 +827,7 @@ unsigned int rsnd_src_get_rate(struct rsnd_priv *priv, #define rsnd_src_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SRC) #define rsnd_parse_connect_src(rdai, playback, capture) \ - rsnd_parse_connect_common(rdai, rsnd_src_mod_get, \ + rsnd_parse_connect_common(rdai, "src", rsnd_src_mod_get, \ rsnd_src_of_node(rsnd_rdai_to_priv(rdai)), \ playback, capture) @@ -839,7 +839,7 @@ void rsnd_ctu_remove(struct rsnd_priv *priv); struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id); #define rsnd_ctu_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_CTU) #define rsnd_parse_connect_ctu(rdai, playback, capture) \ - rsnd_parse_connect_common(rdai, rsnd_ctu_mod_get, \ + rsnd_parse_connect_common(rdai, "ctu", rsnd_ctu_mod_get, \ rsnd_ctu_of_node(rsnd_rdai_to_priv(rdai)), \ playback, capture) @@ -851,7 +851,7 @@ void rsnd_mix_remove(struct rsnd_priv *priv); struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id); #define rsnd_mix_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_MIX) #define rsnd_parse_connect_mix(rdai, playback, capture) \ - rsnd_parse_connect_common(rdai, rsnd_mix_mod_get, \ + rsnd_parse_connect_common(rdai, "mix", rsnd_mix_mod_get, \ rsnd_mix_of_node(rsnd_rdai_to_priv(rdai)), \ playback, capture) @@ -863,7 +863,7 @@ void rsnd_dvc_remove(struct rsnd_priv *priv); struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id); #define rsnd_dvc_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_DVC) #define rsnd_parse_connect_dvc(rdai, playback, capture) \ - rsnd_parse_connect_common(rdai, rsnd_dvc_mod_get, \ + rsnd_parse_connect_common(rdai, "dvc", rsnd_dvc_mod_get, \ rsnd_dvc_of_node(rsnd_rdai_to_priv(rdai)), \ playback, capture) From 039f2ccc64b8a2649f54d654a4d7d92864c6fdb1 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Mon, 31 May 2021 13:19:13 +0900 Subject: [PATCH 2/4] ASoC: rsnd: tidyup rsnd_dma_request_channel() This patch adds "char *name" to rsnd_dma_request_channel(). It is not yet used so far, but is preparation for next "ASoC: rsnd: adjust disabled module" patch Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/878s3vk01q.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/sh/rcar/dma.c | 6 +++--- sound/soc/sh/rcar/dvc.c | 2 +- sound/soc/sh/rcar/rsnd.h | 4 ++-- sound/soc/sh/rcar/src.c | 2 +- sound/soc/sh/rcar/ssi.c | 2 +- sound/soc/sh/rcar/ssiu.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sound/soc/sh/rcar/dma.c b/sound/soc/sh/rcar/dma.c index 44519929a28b..d581f1424185 100644 --- a/sound/soc/sh/rcar/dma.c +++ b/sound/soc/sh/rcar/dma.c @@ -237,8 +237,8 @@ static int rsnd_dmaen_start(struct rsnd_mod *mod, return 0; } -struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, - struct rsnd_mod *mod, char *name) +struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, char *name, + struct rsnd_mod *mod, char *x) { struct dma_chan *chan = NULL; struct device_node *np; @@ -246,7 +246,7 @@ struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, for_each_child_of_node(of_node, np) { if (i == rsnd_mod_id_raw(mod) && (!chan)) - chan = of_dma_request_slave_channel(np, name); + chan = of_dma_request_slave_channel(np, x); i++; } diff --git a/sound/soc/sh/rcar/dvc.c b/sound/soc/sh/rcar/dvc.c index 1943ac1ff803..5137e03a9d7c 100644 --- a/sound/soc/sh/rcar/dvc.c +++ b/sound/soc/sh/rcar/dvc.c @@ -282,7 +282,7 @@ static struct dma_chan *rsnd_dvc_dma_req(struct rsnd_dai_stream *io, struct rsnd_priv *priv = rsnd_mod_to_priv(mod); return rsnd_dma_request_channel(rsnd_dvc_of_node(priv), - mod, "tx"); + DVC_NAME, mod, "tx"); } #ifdef CONFIG_DEBUG_FS diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h index 9269ab83967c..256a11b67eed 100644 --- a/sound/soc/sh/rcar/rsnd.h +++ b/sound/soc/sh/rcar/rsnd.h @@ -269,8 +269,8 @@ u32 rsnd_get_busif_shift(struct rsnd_dai_stream *io, struct rsnd_mod *mod); int rsnd_dma_attach(struct rsnd_dai_stream *io, struct rsnd_mod *mod, struct rsnd_mod **dma_mod); int rsnd_dma_probe(struct rsnd_priv *priv); -struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, - struct rsnd_mod *mod, char *name); +struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, char *name, + struct rsnd_mod *mod, char *x); /* * R-Car sound mod diff --git a/sound/soc/sh/rcar/src.c b/sound/soc/sh/rcar/src.c index 8f7af3e3a1cd..9ccc959c9150 100644 --- a/sound/soc/sh/rcar/src.c +++ b/sound/soc/sh/rcar/src.c @@ -82,7 +82,7 @@ static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io, int is_play = rsnd_io_is_play(io); return rsnd_dma_request_channel(rsnd_src_of_node(priv), - mod, + SRC_NAME, mod, is_play ? "rx" : "tx"); } diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index facdd8c0d419..c00e0d6bb7f4 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -1019,7 +1019,7 @@ static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io, name = is_play ? "rx" : "tx"; return rsnd_dma_request_channel(rsnd_ssi_of_node(priv), - mod, name); + SSI_NAME, mod, name); } #ifdef CONFIG_DEBUG_FS diff --git a/sound/soc/sh/rcar/ssiu.c b/sound/soc/sh/rcar/ssiu.c index 4363508e8250..c96995bb17cb 100644 --- a/sound/soc/sh/rcar/ssiu.c +++ b/sound/soc/sh/rcar/ssiu.c @@ -395,7 +395,7 @@ static struct dma_chan *rsnd_ssiu_dma_req(struct rsnd_dai_stream *io, name = is_play ? "rx" : "tx"; return rsnd_dma_request_channel(rsnd_ssiu_of_node(priv), - mod, name); + SSIU_NAME, mod, name); } #ifdef CONFIG_DEBUG_FS From 73919dbe480d0b6cf3eeb54d25cb2538b6d3b024 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Mon, 31 May 2021 13:19:18 +0900 Subject: [PATCH 3/4] ASoC: rsnd: tidyup rsnd_parse_connect_xxx() This patch tidyup rsnd_parse_connect_xxx() style. Nothing is changed, but is preparation for next "ASoC: rsnd: adjust disabled module" patch Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/877djfk01l.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/sh/rcar/core.c | 4 +++- sound/soc/sh/rcar/ssi.c | 4 +++- sound/soc/sh/rcar/ssiu.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c index c85f1310a8fa..b50812c188ed 100644 --- a/sound/soc/sh/rcar/core.c +++ b/sound/soc/sh/rcar/core.c @@ -1140,7 +1140,9 @@ void rsnd_parse_connect_common(struct rsnd_dai *rdai, char *name, i = 0; for_each_child_of_node(node, np) { - struct rsnd_mod *mod = mod_get(priv, i); + struct rsnd_mod *mod; + + mod = mod_get(priv, i); if (np == playback) rsnd_dai_connect(mod, &rdai->playback, mod->type); diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index c00e0d6bb7f4..4c91091518e3 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -1115,7 +1115,9 @@ void rsnd_parse_connect_ssi(struct rsnd_dai *rdai, i = 0; for_each_child_of_node(node, np) { - struct rsnd_mod *mod = rsnd_ssi_mod_get(priv, i); + struct rsnd_mod *mod; + + mod = rsnd_ssi_mod_get(priv, i); if (np == playback) rsnd_ssi_connect(mod, &rdai->playback); diff --git a/sound/soc/sh/rcar/ssiu.c b/sound/soc/sh/rcar/ssiu.c index c96995bb17cb..819739e18465 100644 --- a/sound/soc/sh/rcar/ssiu.c +++ b/sound/soc/sh/rcar/ssiu.c @@ -470,7 +470,9 @@ void rsnd_parse_connect_ssiu(struct rsnd_dai *rdai, int i = 0; for_each_child_of_node(node, np) { - struct rsnd_mod *mod = rsnd_ssiu_mod_get(priv, i); + struct rsnd_mod *mod; + + mod = rsnd_ssiu_mod_get(priv, i); if (np == playback) rsnd_dai_connect(mod, io_p, mod->type); From c413983eb66a0f6de37c13f7da3dd5fa488e5967 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Mon, 31 May 2021 13:19:32 +0900 Subject: [PATCH 4/4] ASoC: rsnd: adjust disabled module In general Renesas SoC's SSI/SRC are all enabled, but some SoC is not. H2 E2 SRC0 <= SRC1 SRC1 SRC2 SRC2 ... ... Renesas Sound driver is assuming that *all* modules are enabled, and thus it is using *data array* to access each modules. Because of it, we have been using "status = disabled" at DT, and using *full size* array but avoiding disabled module. ex) rcar_sound,src { src-0 { => status = "disabled"; }; src1: src-1 { ... }; ... But R-Car D3 have many disabled modules (It has SSI3/SSI4, SRC5/SRC6), and Renesas SoC maintainer don't want above style on DT. ex) rcar_sound,src { => src0: src-0 { status = "disabled"; }; => src1: src-1 { status = "disabled"; }; => src2: src-2 { status = "disabled"; }; => src3: src-3 { status = "disabled"; }; => src4: src-4 { status = "disabled"; }; src5: src-5 { ... }; src6: src-6 { ... }; }; rcar_sound,ssi { => ssi0: ssi-0 { status = "disabled"; }; => ssi1: ssi-1 { status = "disabled"; }; => ssi2: ssi-2 { status = "disabled"; }; ssi3: ssi-3 { ... }; ssi4: ssi-4 { ... }; }; To adjust it, it needs to care about related for_each_child_of_node() loop on rsnd driver, and it is used from... > grep -l for_each_child_of_node sound/soc/sh/rcar/* sound/soc/sh/rcar/core.c sound/soc/sh/rcar/ctu.c sound/soc/sh/rcar/dma.c sound/soc/sh/rcar/dvc.c sound/soc/sh/rcar/mix.c sound/soc/sh/rcar/src.c sound/soc/sh/rcar/ssi.c sound/soc/sh/rcar/ssiu.c This patch adjust to this situation. By this patch, we can avoid disabled modules on DT rcar_sound,src { src5: src-5 { ... }; src6: src-6 { ... }; }; rcar_sound,ssi { ssi3: ssi-3 { ... }; ssi4: ssi-4 { ... }; }; Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/875yyzk017.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/sh/rcar/core.c | 52 ++++++++++++++++++++++++++++++++++++++++ sound/soc/sh/rcar/dma.c | 2 ++ sound/soc/sh/rcar/rsnd.h | 2 ++ sound/soc/sh/rcar/src.c | 4 +++- sound/soc/sh/rcar/ssi.c | 6 ++++- sound/soc/sh/rcar/ssiu.c | 4 +++- 6 files changed, 67 insertions(+), 3 deletions(-) diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c index b50812c188ed..a4ed9d8f022a 100644 --- a/sound/soc/sh/rcar/core.c +++ b/sound/soc/sh/rcar/core.c @@ -1142,6 +1142,8 @@ void rsnd_parse_connect_common(struct rsnd_dai *rdai, char *name, for_each_child_of_node(node, np) { struct rsnd_mod *mod; + i = rsnd_node_fixed_index(np, name, i); + mod = mod_get(priv, i); if (np == playback) @@ -1154,6 +1156,56 @@ void rsnd_parse_connect_common(struct rsnd_dai *rdai, char *name, of_node_put(node); } +int rsnd_node_fixed_index(struct device_node *node, char *name, int idx) +{ + char node_name[16]; + + /* + * rsnd is assuming each device nodes are sequential numbering, + * but some of them are not. + * This function adjusts index for it. + * + * ex) + * Normal case, special case + * ssi-0 + * ssi-1 + * ssi-2 + * ssi-3 ssi-3 + * ssi-4 ssi-4 + * ... + * + * assume Max 64 node + */ + for (; idx < 64; idx++) { + snprintf(node_name, sizeof(node_name), "%s-%d", name, idx); + + if (strncmp(node_name, of_node_full_name(node), sizeof(node_name)) == 0) + return idx; + } + + return -EINVAL; +} + +int rsnd_node_count(struct rsnd_priv *priv, struct device_node *node, char *name) +{ + struct device *dev = rsnd_priv_to_dev(priv); + struct device_node *np; + int i; + + i = 0; + for_each_child_of_node(node, np) { + i = rsnd_node_fixed_index(np, name, i); + if (i < 0) { + dev_err(dev, "strange node numbering (%s)", + of_node_full_name(node)); + return 0; + } + i++; + } + + return i; +} + static struct device_node *rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph) { diff --git a/sound/soc/sh/rcar/dma.c b/sound/soc/sh/rcar/dma.c index d581f1424185..82d16e037d9a 100644 --- a/sound/soc/sh/rcar/dma.c +++ b/sound/soc/sh/rcar/dma.c @@ -245,6 +245,8 @@ struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, char *nam int i = 0; for_each_child_of_node(of_node, np) { + i = rsnd_node_fixed_index(np, name, i); + if (i == rsnd_mod_id_raw(mod) && (!chan)) chan = of_dma_request_slave_channel(np, x); i++; diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h index 256a11b67eed..b2fbe3bbaabd 100644 --- a/sound/soc/sh/rcar/rsnd.h +++ b/sound/soc/sh/rcar/rsnd.h @@ -465,6 +465,8 @@ void rsnd_parse_connect_common(struct rsnd_dai *rdai, char *name, struct device_node *node, struct device_node *playback, struct device_node *capture); +int rsnd_node_count(struct rsnd_priv *priv, struct device_node *node, char *name); +int rsnd_node_fixed_index(struct device_node *node, char *name, int idx); int rsnd_channel_normalization(int chan); #define rsnd_runtime_channel_original(io) \ diff --git a/sound/soc/sh/rcar/src.c b/sound/soc/sh/rcar/src.c index 9ccc959c9150..42a100c6303d 100644 --- a/sound/soc/sh/rcar/src.c +++ b/sound/soc/sh/rcar/src.c @@ -656,7 +656,7 @@ int rsnd_src_probe(struct rsnd_priv *priv) if (!node) return 0; /* not used is not error */ - nr = of_get_child_count(node); + nr = rsnd_node_count(priv, node, SRC_NAME); if (!nr) { ret = -EINVAL; goto rsnd_src_probe_done; @@ -676,6 +676,8 @@ int rsnd_src_probe(struct rsnd_priv *priv) if (!of_device_is_available(np)) goto skip; + i = rsnd_node_fixed_index(np, SRC_NAME, i); + src = rsnd_src_get(priv, i); snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d", diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index 4c91091518e3..27f34ca6059d 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -1117,6 +1117,8 @@ void rsnd_parse_connect_ssi(struct rsnd_dai *rdai, for_each_child_of_node(node, np) { struct rsnd_mod *mod; + i = rsnd_node_fixed_index(np, SSI_NAME, i); + mod = rsnd_ssi_mod_get(priv, i); if (np == playback) @@ -1160,7 +1162,7 @@ int rsnd_ssi_probe(struct rsnd_priv *priv) if (!node) return -EINVAL; - nr = of_get_child_count(node); + nr = rsnd_node_count(priv, node, SSI_NAME); if (!nr) { ret = -EINVAL; goto rsnd_ssi_probe_done; @@ -1180,6 +1182,8 @@ int rsnd_ssi_probe(struct rsnd_priv *priv) if (!of_device_is_available(np)) goto skip; + i = rsnd_node_fixed_index(np, SSI_NAME, i); + ssi = rsnd_ssi_get(priv, i); snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d", diff --git a/sound/soc/sh/rcar/ssiu.c b/sound/soc/sh/rcar/ssiu.c index 819739e18465..5682c74bb7ff 100644 --- a/sound/soc/sh/rcar/ssiu.c +++ b/sound/soc/sh/rcar/ssiu.c @@ -472,6 +472,8 @@ void rsnd_parse_connect_ssiu(struct rsnd_dai *rdai, for_each_child_of_node(node, np) { struct rsnd_mod *mod; + i = rsnd_node_fixed_index(np, SSIU_NAME, i); + mod = rsnd_ssiu_mod_get(priv, i); if (np == playback) @@ -509,7 +511,7 @@ int rsnd_ssiu_probe(struct rsnd_priv *priv) */ node = rsnd_ssiu_of_node(priv); if (node) - nr = of_get_child_count(node); + nr = rsnd_node_count(priv, node, SSIU_NAME); else nr = priv->ssi_nr;