Commit fafc05aa authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: simple-card-utils: use for_each_prop_xxx()

ASoC is now supporting multi DAI, but, current
simple-card / audio-graph are assuming fixed single DAI.

This patch uses for_each_prop_xxx() to support multi DAI.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87r1jgwf9y.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent f899006d
...@@ -74,6 +74,34 @@ struct asoc_simple_priv { ...@@ -74,6 +74,34 @@ struct asoc_simple_priv {
#define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev) #define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev)
#define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i)) #define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i))
#define for_each_prop_dlc_cpus(props, i, cpu) \
for ((i) = 0; \
((i) < (props)->num.cpus) && ((cpu) = &(props)->cpus[i]); \
(i)++)
#define for_each_prop_dlc_codecs(props, i, codec) \
for ((i) = 0; \
((i) < (props)->num.codecs) && ((codec) = &(props)->codecs[i]); \
(i)++)
#define for_each_prop_dlc_platforms(props, i, platform) \
for ((i) = 0; \
((i) < (props)->num.platforms) && ((platform) = &(props)->platforms[i]); \
(i)++)
#define for_each_prop_codec_conf(props, i, conf) \
for ((i) = 0; \
((i) < (props)->num.codecs) && \
(props)->codec_conf && \
((conf) = &(props)->codec_conf[i]); \
(i)++)
#define for_each_prop_dai_cpu(props, i, cpu) \
for ((i) = 0; \
((i) < (props)->num.cpus) && ((cpu) = &(props)->cpu_dai[i]); \
(i)++)
#define for_each_prop_dai_codec(props, i, codec) \
for ((i) = 0; \
((i) < (props)->num.codecs) && ((codec) = &(props)->codec_dai[i]); \
(i)++)
struct link_info { struct link_info {
int link; /* number of link */ int link; /* number of link */
int cpu; /* turn for CPU / Codec */ int cpu; /* turn for CPU / Codec */
...@@ -192,11 +220,16 @@ static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv) ...@@ -192,11 +220,16 @@ static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
for (i = 0; i < card->num_links; i++) { for (i = 0; i < card->num_links; i++) {
struct simple_dai_props *props = simple_priv_to_props(priv, i); struct simple_dai_props *props = simple_priv_to_props(priv, i);
struct snd_soc_dai_link *link = simple_priv_to_link(priv, i); struct snd_soc_dai_link *link = simple_priv_to_link(priv, i);
struct asoc_simple_dai *dai;
struct snd_soc_codec_conf *cnf;
int j;
dev_dbg(dev, "DAI%d\n", i); dev_dbg(dev, "DAI%d\n", i);
asoc_simple_debug_dai(priv, "cpu", props->cpu_dai); for_each_prop_dai_cpu(props, j, dai)
asoc_simple_debug_dai(priv, "codec", props->codec_dai); asoc_simple_debug_dai(priv, "cpu", dai);
for_each_prop_dai_codec(props, j, dai)
asoc_simple_debug_dai(priv, "codec", dai);
if (link->name) if (link->name)
dev_dbg(dev, "dai name = %s\n", link->name); dev_dbg(dev, "dai name = %s\n", link->name);
...@@ -209,9 +242,9 @@ static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv) ...@@ -209,9 +242,9 @@ static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
if (props->adata.convert_channels) if (props->adata.convert_channels)
dev_dbg(dev, "convert_channels = %d\n", dev_dbg(dev, "convert_channels = %d\n",
props->adata.convert_channels); props->adata.convert_channels);
if (props->codec_conf && props->codec_conf->name_prefix) for_each_prop_codec_conf(props, j, cnf)
dev_dbg(dev, "name prefix = %s\n", if (cnf->name_prefix)
props->codec_conf->name_prefix); dev_dbg(dev, "name prefix = %s\n", cnf->name_prefix);
if (props->mclk_fs) if (props->mclk_fs)
dev_dbg(dev, "mclk-fs = %d\n", dev_dbg(dev, "mclk-fs = %d\n",
props->mclk_fs); props->mclk_fs);
......
...@@ -195,17 +195,37 @@ int asoc_simple_startup(struct snd_pcm_substream *substream) ...@@ -195,17 +195,37 @@ int asoc_simple_startup(struct snd_pcm_substream *substream)
{ {
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card); struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct simple_dai_props *dai_props = simple_priv_to_props(priv, rtd->num); struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num);
struct asoc_simple_dai *dai;
int i1, i2, i;
int ret; int ret;
ret = asoc_simple_clk_enable(dai_props->cpu_dai); for_each_prop_dai_cpu(props, i1, dai) {
ret = asoc_simple_clk_enable(dai);
if (ret) if (ret)
return ret; goto cpu_err;
}
ret = asoc_simple_clk_enable(dai_props->codec_dai); for_each_prop_dai_codec(props, i2, dai) {
ret = asoc_simple_clk_enable(dai);
if (ret) if (ret)
asoc_simple_clk_disable(dai_props->cpu_dai); goto codec_err;
}
return 0;
codec_err:
for_each_prop_dai_codec(props, i, dai) {
if (i >= i2)
break;
asoc_simple_clk_disable(dai);
}
cpu_err:
for_each_prop_dai_cpu(props, i, dai) {
if (i >= i1)
break;
asoc_simple_clk_disable(dai);
}
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(asoc_simple_startup); EXPORT_SYMBOL_GPL(asoc_simple_startup);
...@@ -216,17 +236,19 @@ void asoc_simple_shutdown(struct snd_pcm_substream *substream) ...@@ -216,17 +236,19 @@ void asoc_simple_shutdown(struct snd_pcm_substream *substream)
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card); struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct simple_dai_props *dai_props = struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num);
simple_priv_to_props(priv, rtd->num); struct asoc_simple_dai *dai;
int i;
if (dai_props->mclk_fs) { if (props->mclk_fs) {
snd_soc_dai_set_sysclk(codec_dai, 0, 0, SND_SOC_CLOCK_IN); snd_soc_dai_set_sysclk(codec_dai, 0, 0, SND_SOC_CLOCK_IN);
snd_soc_dai_set_sysclk(cpu_dai, 0, 0, SND_SOC_CLOCK_OUT); snd_soc_dai_set_sysclk(cpu_dai, 0, 0, SND_SOC_CLOCK_OUT);
} }
asoc_simple_clk_disable(dai_props->cpu_dai); for_each_prop_dai_cpu(props, i, dai)
asoc_simple_clk_disable(dai);
asoc_simple_clk_disable(dai_props->codec_dai); for_each_prop_dai_codec(props, i, dai)
asoc_simple_clk_disable(dai);
} }
EXPORT_SYMBOL_GPL(asoc_simple_shutdown); EXPORT_SYMBOL_GPL(asoc_simple_shutdown);
...@@ -249,41 +271,41 @@ int asoc_simple_hw_params(struct snd_pcm_substream *substream, ...@@ -249,41 +271,41 @@ int asoc_simple_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); struct asoc_simple_dai *pdai;
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); struct snd_soc_dai *sdai;
struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card); struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct simple_dai_props *dai_props = struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num);
simple_priv_to_props(priv, rtd->num);
unsigned int mclk, mclk_fs = 0; unsigned int mclk, mclk_fs = 0;
int ret; int i, ret;
if (dai_props->mclk_fs) if (props->mclk_fs)
mclk_fs = dai_props->mclk_fs; mclk_fs = props->mclk_fs;
if (mclk_fs) { if (mclk_fs) {
mclk = params_rate(params) * mclk_fs; mclk = params_rate(params) * mclk_fs;
ret = asoc_simple_set_clk_rate(dai_props->codec_dai, mclk); for_each_prop_dai_codec(props, i, pdai) {
ret = asoc_simple_set_clk_rate(pdai, mclk);
if (ret < 0) if (ret < 0)
return ret; return ret;
}
ret = asoc_simple_set_clk_rate(dai_props->cpu_dai, mclk); for_each_prop_dai_cpu(props, i, pdai) {
ret = asoc_simple_set_clk_rate(pdai, mclk);
if (ret < 0) if (ret < 0)
return ret; return ret;
}
ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, for_each_rtd_codec_dais(rtd, i, sdai) {
SND_SOC_CLOCK_IN); ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, SND_SOC_CLOCK_IN);
if (ret && ret != -ENOTSUPP) if (ret && ret != -ENOTSUPP)
goto err; return ret;
}
ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, for_each_rtd_cpu_dais(rtd, i, sdai) {
SND_SOC_CLOCK_OUT); ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, SND_SOC_CLOCK_OUT);
if (ret && ret != -ENOTSUPP) if (ret && ret != -ENOTSUPP)
goto err; return ret;
}
} }
return 0; return 0;
err:
return ret;
} }
EXPORT_SYMBOL_GPL(asoc_simple_hw_params); EXPORT_SYMBOL_GPL(asoc_simple_hw_params);
...@@ -378,20 +400,22 @@ static int asoc_simple_init_dai_link_params(struct snd_soc_pcm_runtime *rtd, ...@@ -378,20 +400,22 @@ static int asoc_simple_init_dai_link_params(struct snd_soc_pcm_runtime *rtd,
int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd) int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd)
{ {
struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card); struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct simple_dai_props *dai_props = simple_priv_to_props(priv, rtd->num); struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num);
int ret; struct asoc_simple_dai *dai;
int i, ret;
ret = asoc_simple_init_dai(asoc_rtd_to_codec(rtd, 0), for_each_prop_dai_codec(props, i, dai) {
dai_props->codec_dai); ret = asoc_simple_init_dai(asoc_rtd_to_codec(rtd, i), dai);
if (ret < 0) if (ret < 0)
return ret; return ret;
}
ret = asoc_simple_init_dai(asoc_rtd_to_cpu(rtd, 0), for_each_prop_dai_cpu(props, i, dai) {
dai_props->cpu_dai); ret = asoc_simple_init_dai(asoc_rtd_to_cpu(rtd, i), dai);
if (ret < 0) if (ret < 0)
return ret; return ret;
}
ret = asoc_simple_init_dai_link_params(rtd, dai_props); ret = asoc_simple_init_dai_link_params(rtd, props);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment