From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
To: broonie@kernel.org, lgirdwood@gmail.com, robh+dt@kernel.org,
krzysztof.kozlowski+dt@linaro.org,
kuninori.morimoto.gx@renesas.com
Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org,
tiwai@suse.com, linux-kernel@vger.kernel.org
Subject: [PATCH v1 1/2] ASoC: simple-card: Support custom DAI system clock IDs
Date: Sat, 22 Oct 2022 17:27:41 +0100 [thread overview]
Message-ID: <20221022162742.21671-1-aidanmacdonald.0x0@gmail.com> (raw)
Some DAIs have multiple system clock sources, which can be chosen
using the "clk_id" argument to snd_soc_dai_set_sysclk(). Currently
this is hardcoded to 0 when using simple cards, but that choice is
not always suitable.
Add the "system-clock-id" property to allow selecting a different
clock ID on a per-DAI basis.
To simplify the logic on DPCM cards, add a dummy "asoc_simple_dai"
instance and use that for the dummy components on DPCM links. This
ensures that when we're iterating over DAIs in the PCM runtime there
is always a matching "asoc_simple_dai" we can dereference.
Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
---
include/sound/simple_card_utils.h | 2 ++
sound/soc/generic/simple-card-utils.c | 26 ++++++++++++++++++++------
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index a0b827f0c2f6..9f9a72299637 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -26,6 +26,7 @@ struct asoc_simple_dai {
const char *name;
unsigned int sysclk;
int clk_direction;
+ int sysclk_id;
int slots;
int slot_width;
unsigned int tx_slot_mask;
@@ -67,6 +68,7 @@ struct asoc_simple_priv {
struct prop_nums num;
unsigned int mclk_fs;
} *dai_props;
+ struct asoc_simple_dai dummy_dai;
struct asoc_simple_jack hp_jack;
struct asoc_simple_jack mic_jack;
struct snd_soc_dai_link *dai_link;
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index bef16833c487..d4d898e06e76 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -262,6 +262,9 @@ int asoc_simple_parse_clk(struct device *dev,
if (of_property_read_bool(node, "system-clock-direction-out"))
simple_dai->clk_direction = SND_SOC_CLOCK_OUT;
+ if (!of_property_read_u32(node, "system-clock-id", &val))
+ simple_dai->sysclk_id = val;
+
return 0;
}
EXPORT_SYMBOL_GPL(asoc_simple_parse_clk);
@@ -355,7 +358,7 @@ void asoc_simple_shutdown(struct snd_pcm_substream *substream)
if (props->mclk_fs && !dai->clk_fixed && !snd_soc_dai_active(cpu_dai))
snd_soc_dai_set_sysclk(cpu_dai,
- 0, 0, SND_SOC_CLOCK_OUT);
+ dai->sysclk_id, 0, SND_SOC_CLOCK_OUT);
asoc_simple_clk_disable(dai);
}
@@ -364,7 +367,7 @@ void asoc_simple_shutdown(struct snd_pcm_substream *substream)
if (props->mclk_fs && !dai->clk_fixed && !snd_soc_dai_active(codec_dai))
snd_soc_dai_set_sysclk(codec_dai,
- 0, 0, SND_SOC_CLOCK_IN);
+ dai->sysclk_id, 0, SND_SOC_CLOCK_IN);
asoc_simple_clk_disable(dai);
}
@@ -439,7 +442,7 @@ int asoc_simple_hw_params(struct snd_pcm_substream *substream,
struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num);
unsigned int mclk, mclk_fs = 0;
- int i, ret;
+ int i, ret, sysclk_id;
if (props->mclk_fs)
mclk_fs = props->mclk_fs;
@@ -472,13 +475,21 @@ int asoc_simple_hw_params(struct snd_pcm_substream *substream,
}
for_each_rtd_codec_dais(rtd, i, sdai) {
- ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, SND_SOC_CLOCK_IN);
+ pdai = simple_props_to_dai_codec(props, i);
+ sysclk_id = pdai->sysclk_id;
+
+ ret = snd_soc_dai_set_sysclk(sdai, sysclk_id, mclk,
+ SND_SOC_CLOCK_IN);
if (ret && ret != -ENOTSUPP)
return ret;
}
for_each_rtd_cpu_dais(rtd, i, sdai) {
- ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, SND_SOC_CLOCK_OUT);
+ pdai = simple_props_to_dai_cpu(props, i);
+ sysclk_id = pdai->sysclk_id;
+
+ ret = snd_soc_dai_set_sysclk(sdai, pdai->sysclk_id, mclk,
+ SND_SOC_CLOCK_OUT);
if (ret && ret != -ENOTSUPP)
return ret;
}
@@ -523,7 +534,8 @@ static int asoc_simple_init_dai(struct snd_soc_dai *dai,
return 0;
if (simple_dai->sysclk) {
- ret = snd_soc_dai_set_sysclk(dai, 0, simple_dai->sysclk,
+ ret = snd_soc_dai_set_sysclk(dai, simple_dai->sysclk_id,
+ simple_dai->sysclk,
simple_dai->clk_direction);
if (ret && ret != -ENOTSUPP) {
dev_err(dai->dev, "simple-card: set_sysclk error\n");
@@ -858,6 +870,7 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
dai_link[i].cpus = &priv->dummy;
dai_props[i].num.cpus =
dai_link[i].num_cpus = 1;
+ dai_props[i].cpu_dai = &priv->dummy_dai;
}
if (li->num[i].codecs) {
@@ -882,6 +895,7 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
dai_link[i].codecs = &priv->dummy;
dai_props[i].num.codecs =
dai_link[i].num_codecs = 1;
+ dai_props[i].codec_dai = &priv->dummy_dai;
}
if (li->num[i].platforms) {
--
2.38.1
WARNING: multiple messages have this Message-ID (diff)
From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
To: broonie@kernel.org, lgirdwood@gmail.com, robh+dt@kernel.org,
krzysztof.kozlowski+dt@linaro.org,
kuninori.morimoto.gx@renesas.com
Cc: perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1 1/2] ASoC: simple-card: Support custom DAI system clock IDs
Date: Sat, 22 Oct 2022 17:27:41 +0100 [thread overview]
Message-ID: <20221022162742.21671-1-aidanmacdonald.0x0@gmail.com> (raw)
Some DAIs have multiple system clock sources, which can be chosen
using the "clk_id" argument to snd_soc_dai_set_sysclk(). Currently
this is hardcoded to 0 when using simple cards, but that choice is
not always suitable.
Add the "system-clock-id" property to allow selecting a different
clock ID on a per-DAI basis.
To simplify the logic on DPCM cards, add a dummy "asoc_simple_dai"
instance and use that for the dummy components on DPCM links. This
ensures that when we're iterating over DAIs in the PCM runtime there
is always a matching "asoc_simple_dai" we can dereference.
Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
---
include/sound/simple_card_utils.h | 2 ++
sound/soc/generic/simple-card-utils.c | 26 ++++++++++++++++++++------
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index a0b827f0c2f6..9f9a72299637 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -26,6 +26,7 @@ struct asoc_simple_dai {
const char *name;
unsigned int sysclk;
int clk_direction;
+ int sysclk_id;
int slots;
int slot_width;
unsigned int tx_slot_mask;
@@ -67,6 +68,7 @@ struct asoc_simple_priv {
struct prop_nums num;
unsigned int mclk_fs;
} *dai_props;
+ struct asoc_simple_dai dummy_dai;
struct asoc_simple_jack hp_jack;
struct asoc_simple_jack mic_jack;
struct snd_soc_dai_link *dai_link;
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index bef16833c487..d4d898e06e76 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -262,6 +262,9 @@ int asoc_simple_parse_clk(struct device *dev,
if (of_property_read_bool(node, "system-clock-direction-out"))
simple_dai->clk_direction = SND_SOC_CLOCK_OUT;
+ if (!of_property_read_u32(node, "system-clock-id", &val))
+ simple_dai->sysclk_id = val;
+
return 0;
}
EXPORT_SYMBOL_GPL(asoc_simple_parse_clk);
@@ -355,7 +358,7 @@ void asoc_simple_shutdown(struct snd_pcm_substream *substream)
if (props->mclk_fs && !dai->clk_fixed && !snd_soc_dai_active(cpu_dai))
snd_soc_dai_set_sysclk(cpu_dai,
- 0, 0, SND_SOC_CLOCK_OUT);
+ dai->sysclk_id, 0, SND_SOC_CLOCK_OUT);
asoc_simple_clk_disable(dai);
}
@@ -364,7 +367,7 @@ void asoc_simple_shutdown(struct snd_pcm_substream *substream)
if (props->mclk_fs && !dai->clk_fixed && !snd_soc_dai_active(codec_dai))
snd_soc_dai_set_sysclk(codec_dai,
- 0, 0, SND_SOC_CLOCK_IN);
+ dai->sysclk_id, 0, SND_SOC_CLOCK_IN);
asoc_simple_clk_disable(dai);
}
@@ -439,7 +442,7 @@ int asoc_simple_hw_params(struct snd_pcm_substream *substream,
struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num);
unsigned int mclk, mclk_fs = 0;
- int i, ret;
+ int i, ret, sysclk_id;
if (props->mclk_fs)
mclk_fs = props->mclk_fs;
@@ -472,13 +475,21 @@ int asoc_simple_hw_params(struct snd_pcm_substream *substream,
}
for_each_rtd_codec_dais(rtd, i, sdai) {
- ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, SND_SOC_CLOCK_IN);
+ pdai = simple_props_to_dai_codec(props, i);
+ sysclk_id = pdai->sysclk_id;
+
+ ret = snd_soc_dai_set_sysclk(sdai, sysclk_id, mclk,
+ SND_SOC_CLOCK_IN);
if (ret && ret != -ENOTSUPP)
return ret;
}
for_each_rtd_cpu_dais(rtd, i, sdai) {
- ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, SND_SOC_CLOCK_OUT);
+ pdai = simple_props_to_dai_cpu(props, i);
+ sysclk_id = pdai->sysclk_id;
+
+ ret = snd_soc_dai_set_sysclk(sdai, pdai->sysclk_id, mclk,
+ SND_SOC_CLOCK_OUT);
if (ret && ret != -ENOTSUPP)
return ret;
}
@@ -523,7 +534,8 @@ static int asoc_simple_init_dai(struct snd_soc_dai *dai,
return 0;
if (simple_dai->sysclk) {
- ret = snd_soc_dai_set_sysclk(dai, 0, simple_dai->sysclk,
+ ret = snd_soc_dai_set_sysclk(dai, simple_dai->sysclk_id,
+ simple_dai->sysclk,
simple_dai->clk_direction);
if (ret && ret != -ENOTSUPP) {
dev_err(dai->dev, "simple-card: set_sysclk error\n");
@@ -858,6 +870,7 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
dai_link[i].cpus = &priv->dummy;
dai_props[i].num.cpus =
dai_link[i].num_cpus = 1;
+ dai_props[i].cpu_dai = &priv->dummy_dai;
}
if (li->num[i].codecs) {
@@ -882,6 +895,7 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
dai_link[i].codecs = &priv->dummy;
dai_props[i].num.codecs =
dai_link[i].num_codecs = 1;
+ dai_props[i].codec_dai = &priv->dummy_dai;
}
if (li->num[i].platforms) {
--
2.38.1
next reply other threads:[~2022-10-22 16:28 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-22 16:27 Aidan MacDonald [this message]
2022-10-22 16:27 ` [PATCH v1 1/2] ASoC: simple-card: Support custom DAI system clock IDs Aidan MacDonald
2022-10-22 16:27 ` [PATCH v1 2/2] dt-bindings: ASoC: simple-card: Add system-clock-id property Aidan MacDonald
2022-10-22 16:27 ` Aidan MacDonald
2022-10-23 13:08 ` Krzysztof Kozlowski
2022-10-23 13:08 ` Krzysztof Kozlowski
2022-10-23 13:47 ` Aidan MacDonald
2022-10-23 13:47 ` Aidan MacDonald
2022-10-24 20:46 ` Krzysztof Kozlowski
2022-10-24 20:46 ` Krzysztof Kozlowski
2022-10-24 23:38 ` Aidan MacDonald
2022-10-24 23:38 ` Aidan MacDonald
2022-10-25 0:00 ` Krzysztof Kozlowski
2022-10-25 0:00 ` Krzysztof Kozlowski
2022-10-25 9:14 ` Aidan MacDonald
2022-10-25 9:14 ` Aidan MacDonald
2022-10-25 12:19 ` Krzysztof Kozlowski
2022-10-25 12:19 ` Krzysztof Kozlowski
2022-10-26 14:48 ` Aidan MacDonald
2022-10-26 14:48 ` Aidan MacDonald
2022-10-26 15:03 ` Krzysztof Kozlowski
2022-10-26 15:03 ` Krzysztof Kozlowski
2022-10-26 19:27 ` Aidan MacDonald
2022-10-26 19:27 ` Aidan MacDonald
2022-10-26 15:05 ` Krzysztof Kozlowski
2022-10-26 15:05 ` Krzysztof Kozlowski
2022-10-23 23:54 ` [PATCH v1 1/2] ASoC: simple-card: Support custom DAI system clock IDs Kuninori Morimoto
2022-10-23 23:54 ` Kuninori Morimoto
2022-10-24 9:18 ` Aidan MacDonald
2022-10-24 9:18 ` Aidan MacDonald
2022-10-24 11:49 ` Mark Brown
2022-10-24 11:49 ` Mark Brown
2022-10-24 23:17 ` Aidan MacDonald
2022-10-24 23:17 ` Aidan MacDonald
2022-10-25 11:03 ` Mark Brown
2022-10-25 11:03 ` Mark Brown
2022-10-26 14:42 ` Aidan MacDonald
2022-10-26 14:42 ` Aidan MacDonald
2022-10-26 15:11 ` Mark Brown
2022-10-26 15:11 ` Mark Brown
2022-10-26 19:22 ` Aidan MacDonald
2022-10-26 19:22 ` Aidan MacDonald
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=20221022162742.21671-1-aidanmacdonald.0x0@gmail.com \
--to=aidanmacdonald.0x0@gmail.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=tiwai@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.