Merge series "ASoC: simple-card-utils: prepare for multi support" from Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>:

Hi Mark

This patch-set is for v2 of Multi-CPU/Codec support,
and some cleanups.
v1 had patch-conflict on simple-card / audio-graph with below.
v2 was solved it.

	fa74c223b6
	("ASoC: simple-card: fix possible uninitialized single_cpu local variable")

I want to add new audio-graph-card2 driver which can support
not only DPCM, but also Multi-CPU/Codec, and Codec2Codec.
And it is also supporting audio-graph-card2 base custom driver.

But before supporting such driver, we need to cleanup existing
simple-card / audio-graph, because these and new driver are
sharing code.

Link: https://lore.kernel.org/r/87wntmod33.wl-kuninori.morimoto.gx@renesas.com
Link: https://lore.kernel.org/r/20210408141639.GA39604@sirena.org.uk

Kuninori Morimoto (12):
  ASoC: simple-card-utils: setup dai_props cpu_dai/codec_dai at initial timing
  ASoC: simple-card-utils: remove li->dais/li->conf
  ASoC: simple-card-utils: use for_each_prop_xxx()
  ASoC: simple-card-utils: remove asoc_simple_parse_xxx()
  ASoC: simple-card-utils: care multi DAI at asoc_simple_clean_reference()
  ASoC: simple-card-utils: indicate dai_fmt if exist
  ASoC: simple-card-utils: indicate missing CPU/Codec numbers for debug
  ASoC: simple-card-utils: add simple_props_to_xxx() macro
  ASoC: simple-card-utils: multi support at asoc_simple_canonicalize_cpu/platform()
  ASoC: simple-card-utils: tidyup debug info for clock
  ASoC: simple-card-utils: tidyup dev_dbg() to use 1 line
  ASoC: simple-card-utils: tidyup asoc_simple_parse_convert()

 include/sound/simple_card_utils.h     | 107 ++++++++++------
 sound/soc/generic/audio-graph-card.c  |  64 ++++------
 sound/soc/generic/simple-card-utils.c | 174 ++++++++++++++++----------
 sound/soc/generic/simple-card.c       |  70 ++++-------
 4 files changed, 226 insertions(+), 189 deletions(-)

--
2.25.1
This commit is contained in:
Mark Brown 2021-04-13 14:11:53 +01:00
commit 637251bcfe
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
4 changed files with 226 additions and 189 deletions

View File

@ -74,10 +74,49 @@ struct asoc_simple_priv {
#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_props_to_dlc_cpu(props, i) ((props)->cpus + i)
#define simple_props_to_dlc_codec(props, i) ((props)->codecs + i)
#define simple_props_to_dlc_platform(props, i) ((props)->platforms + i)
#define simple_props_to_dai_cpu(props, i) ((props)->cpu_dai + i)
#define simple_props_to_dai_codec(props, i) ((props)->codec_dai + i)
#define simple_props_to_codec_conf(props, i) ((props)->codec_conf + i)
#define for_each_prop_dlc_cpus(props, i, cpu) \
for ((i) = 0; \
((i) < (props)->num.cpus) && \
((cpu) = simple_props_to_dlc_cpu(props, i)); \
(i)++)
#define for_each_prop_dlc_codecs(props, i, codec) \
for ((i) = 0; \
((i) < (props)->num.codecs) && \
((codec) = simple_props_to_dlc_codec(props, i)); \
(i)++)
#define for_each_prop_dlc_platforms(props, i, platform) \
for ((i) = 0; \
((i) < (props)->num.platforms) && \
((platform) = simple_props_to_dlc_platform(props, i)); \
(i)++)
#define for_each_prop_codec_conf(props, i, conf) \
for ((i) = 0; \
((i) < (props)->num.codecs) && \
(props)->codec_conf && \
((conf) = simple_props_to_codec_conf(props, i)); \
(i)++)
#define for_each_prop_dai_cpu(props, i, cpu) \
for ((i) = 0; \
((i) < (props)->num.cpus) && \
((cpu) = simple_props_to_dai_cpu(props, i)); \
(i)++)
#define for_each_prop_dai_codec(props, i, codec) \
for ((i) = 0; \
((i) < (props)->num.codecs) && \
((codec) = simple_props_to_dai_codec(props, i)); \
(i)++)
struct link_info {
int dais; /* number of dai */
int link; /* number of link */
int conf; /* number of codec_conf */
int cpu; /* turn for CPU / Codec */
struct prop_nums num[SNDRV_MINOR_DEVICES];
};
@ -94,10 +133,6 @@ int asoc_simple_set_dailink_name(struct device *dev,
int asoc_simple_parse_card_name(struct snd_soc_card *card,
char *prefix);
#define asoc_simple_parse_clk_cpu(dev, node, dai_link, simple_dai) \
asoc_simple_parse_clk(dev, node, simple_dai, dai_link->cpus)
#define asoc_simple_parse_clk_codec(dev, node, dai_link, simple_dai) \
asoc_simple_parse_clk(dev, node, simple_dai, dai_link->codecs)
int asoc_simple_parse_clk(struct device *dev,
struct device_node *node,
struct asoc_simple_dai *simple_dai,
@ -110,29 +145,22 @@ int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd);
int asoc_simple_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params);
#define asoc_simple_parse_cpu(node, dai_link, is_single_link) \
asoc_simple_parse_dai(node, dai_link->cpus, is_single_link)
#define asoc_simple_parse_codec(node, dai_link) \
asoc_simple_parse_dai(node, dai_link->codecs, NULL)
#define asoc_simple_parse_platform(node, dai_link) \
asoc_simple_parse_dai(node, dai_link->platforms, NULL)
#define asoc_simple_parse_tdm(np, dai) \
snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \
&(dai)->rx_slot_mask, \
&(dai)->slots, \
&(dai)->slot_width);
void asoc_simple_canonicalize_platform(struct snd_soc_dai_link *dai_link);
void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
int is_single_links);
void asoc_simple_canonicalize_platform(struct snd_soc_dai_link_component *platforms,
struct snd_soc_dai_link_component *cpus);
void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link_component *cpus,
int is_single_links);
int asoc_simple_clean_reference(struct snd_soc_card *card);
void asoc_simple_convert_fixup(struct asoc_simple_data *data,
struct snd_pcm_hw_params *params);
void asoc_simple_parse_convert(struct device *dev,
struct device_node *np, char *prefix,
void asoc_simple_parse_convert(struct device_node *np, char *prefix,
struct asoc_simple_data *data);
int asoc_simple_parse_routing(struct snd_soc_card *card,
@ -162,12 +190,6 @@ static inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv,
if (dai->name)
dev_dbg(dev, "%s dai name = %s\n",
name, dai->name);
if (dai->sysclk)
dev_dbg(dev, "%s sysclk = %d\n",
name, dai->sysclk);
dev_dbg(dev, "%s direction = %s\n",
name, dai->clk_direction ? "OUT" : "IN");
if (dai->slots)
dev_dbg(dev, "%s slots = %d\n", name, dai->slots);
@ -179,6 +201,12 @@ static inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv,
dev_dbg(dev, "%s rx slot mask = %d\n", name, dai->rx_slot_mask);
if (dai->clk)
dev_dbg(dev, "%s clk %luHz\n", name, clk_get_rate(dai->clk));
if (dai->sysclk)
dev_dbg(dev, "%s sysclk = %dHz\n",
name, dai->sysclk);
if (dai->clk || dai->sysclk)
dev_dbg(dev, "%s direction = %s\n",
name, dai->clk_direction ? "OUT" : "IN");
}
static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
@ -194,29 +222,32 @@ static inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
for (i = 0; i < card->num_links; 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 asoc_simple_dai *dai;
struct snd_soc_codec_conf *cnf;
int j;
dev_dbg(dev, "DAI%d\n", i);
asoc_simple_debug_dai(priv, "cpu", props->cpu_dai);
asoc_simple_debug_dai(priv, "codec", props->codec_dai);
dev_dbg(dev, "cpu num = %d\n", link->num_cpus);
for_each_prop_dai_cpu(props, j, dai)
asoc_simple_debug_dai(priv, "cpu", dai);
dev_dbg(dev, "codec num = %d\n", link->num_codecs);
for_each_prop_dai_codec(props, j, dai)
asoc_simple_debug_dai(priv, "codec", dai);
if (link->name)
dev_dbg(dev, "dai name = %s\n", link->name);
dev_dbg(dev, "dai format = %04x\n", link->dai_fmt);
if (link->dai_fmt)
dev_dbg(dev, "dai format = %04x\n", link->dai_fmt);
if (props->adata.convert_rate)
dev_dbg(dev, "convert_rate = %d\n",
props->adata.convert_rate);
dev_dbg(dev, "convert_rate = %d\n", props->adata.convert_rate);
if (props->adata.convert_channels)
dev_dbg(dev, "convert_channels = %d\n",
props->adata.convert_channels);
if (props->codec_conf && props->codec_conf->name_prefix)
dev_dbg(dev, "name prefix = %s\n",
props->codec_conf->name_prefix);
dev_dbg(dev, "convert_channels = %d\n", props->adata.convert_channels);
for_each_prop_codec_conf(props, j, cnf)
if (cnf->name_prefix)
dev_dbg(dev, "name prefix = %s\n", cnf->name_prefix);
if (props->mclk_fs)
dev_dbg(dev, "mclk-fs = %d\n",
props->mclk_fs);
dev_dbg(dev, "mclk-fs = %d\n", props->mclk_fs);
}
}
#else

View File

@ -180,11 +180,11 @@ static void graph_parse_convert(struct device *dev,
struct device_node *ports = of_get_parent(port);
struct device_node *node = of_graph_get_port_parent(ep);
asoc_simple_parse_convert(dev, top, NULL, adata);
asoc_simple_parse_convert(dev, node, PREFIX, adata);
asoc_simple_parse_convert(dev, ports, NULL, adata);
asoc_simple_parse_convert(dev, port, NULL, adata);
asoc_simple_parse_convert(dev, ep, NULL, adata);
asoc_simple_parse_convert(top, NULL, adata);
asoc_simple_parse_convert(node, PREFIX, adata);
asoc_simple_parse_convert(ports, NULL, adata);
asoc_simple_parse_convert(port, NULL, adata);
asoc_simple_parse_convert(ep, NULL, adata);
of_node_put(port);
of_node_put(ports);
@ -226,6 +226,7 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
struct asoc_simple_dai *dai;
struct snd_soc_dai_link_component *cpus = dai_link->cpus;
struct snd_soc_dai_link_component *codecs = dai_link->codecs;
struct snd_soc_dai_link_component *platforms = dai_link->platforms;
int ret;
port = of_get_parent(ep);
@ -245,14 +246,13 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
dai_link->dynamic = 1;
dai_link->dpcm_merged_format = 1;
dai =
dai_props->cpu_dai = &priv->dais[li->dais++];
dai = dai_props->cpu_dai;
ret = asoc_simple_parse_cpu(ep, dai_link, &is_single_links);
ret = asoc_simple_parse_dai(ep, dai_link->cpus, &is_single_links);
if (ret)
goto out_put_node;
ret = asoc_simple_parse_clk_cpu(dev, ep, dai_link, dai);
ret = asoc_simple_parse_clk(dev, ep, dai, dai_link->cpus);
if (ret < 0)
goto out_put_node;
@ -277,8 +277,8 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
dai_link->no_pcm = 1;
/* card->num_links includes Codec */
asoc_simple_canonicalize_cpu(dai_link, is_single_links);
asoc_simple_canonicalize_platform(dai_link);
asoc_simple_canonicalize_cpu(cpus, is_single_links);
asoc_simple_canonicalize_platform(platforms, cpus);
} else {
struct snd_soc_codec_conf *cconf;
@ -288,17 +288,14 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
dai_link->no_pcm = 1;
dai_link->be_hw_params_fixup = asoc_simple_be_hw_params_fixup;
dai =
dai_props->codec_dai = &priv->dais[li->dais++];
dai = dai_props->codec_dai;
cconf = dai_props->codec_conf;
cconf =
dai_props->codec_conf = &priv->codec_conf[li->conf++];
ret = asoc_simple_parse_codec(ep, dai_link);
ret = asoc_simple_parse_dai(ep, dai_link->codecs, NULL);
if (ret < 0)
goto out_put_node;
ret = asoc_simple_parse_clk_codec(dev, ep, dai_link, dai);
ret = asoc_simple_parse_clk(dev, ep, dai, dai_link->codecs);
if (ret < 0)
goto out_put_node;
@ -358,19 +355,14 @@ static int graph_dai_link_of(struct asoc_simple_priv *priv,
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
struct device_node *top = dev->of_node;
struct asoc_simple_dai *cpu_dai;
struct asoc_simple_dai *codec_dai;
struct asoc_simple_dai *cpu_dai = dai_props->cpu_dai;
struct asoc_simple_dai *codec_dai = dai_props->codec_dai;
int ret, single_cpu = 0;
dev_dbg(dev, "link_of (%pOF)\n", cpu_ep);
li->link++;
cpu_dai =
dai_props->cpu_dai = &priv->dais[li->dais++];
codec_dai =
dai_props->codec_dai = &priv->dais[li->dais++];
/* Factor to mclk, used in hw_params() */
graph_parse_mclk_fs(top, cpu_ep, dai_props);
graph_parse_mclk_fs(top, codec_ep, dai_props);
@ -380,11 +372,11 @@ static int graph_dai_link_of(struct asoc_simple_priv *priv,
if (ret < 0)
return ret;
ret = asoc_simple_parse_cpu(cpu_ep, dai_link, &single_cpu);
ret = asoc_simple_parse_dai(cpu_ep, dai_link->cpus, &single_cpu);
if (ret < 0)
return ret;
ret = asoc_simple_parse_codec(codec_ep, dai_link);
ret = asoc_simple_parse_dai(codec_ep, dai_link->codecs, NULL);
if (ret < 0)
return ret;
@ -396,11 +388,11 @@ static int graph_dai_link_of(struct asoc_simple_priv *priv,
if (ret < 0)
return ret;
ret = asoc_simple_parse_clk_cpu(dev, cpu_ep, dai_link, cpu_dai);
ret = asoc_simple_parse_clk(dev, cpu_ep, cpu_dai, dai_link->cpus);
if (ret < 0)
return ret;
ret = asoc_simple_parse_clk_codec(dev, codec_ep, dai_link, codec_dai);
ret = asoc_simple_parse_clk(dev, codec_ep, codec_dai, dai_link->codecs);
if (ret < 0)
return ret;
@ -414,8 +406,8 @@ static int graph_dai_link_of(struct asoc_simple_priv *priv,
dai_link->ops = &graph_ops;
dai_link->init = asoc_simple_dai_init;
asoc_simple_canonicalize_cpu(dai_link, single_cpu);
asoc_simple_canonicalize_platform(dai_link);
asoc_simple_canonicalize_cpu(dai_link->cpus, single_cpu);
asoc_simple_canonicalize_platform(dai_link->platforms, dai_link->cpus);
return 0;
}
@ -561,7 +553,7 @@ int audio_graph_parse_of(struct asoc_simple_priv *priv, struct device *dev)
memset(&li, 0, sizeof(li));
graph_get_dais_count(priv, &li);
if (!li.link || !li.dais)
if (!li.link)
return -EINVAL;
ret = asoc_simple_init_priv(priv, &li);
@ -631,7 +623,6 @@ static int graph_count_noml(struct asoc_simple_priv *priv,
li->num[li->link].platforms = 1;
li->link += 1; /* 1xCPU-Codec */
li->dais += 2; /* 1xCPU + 1xCodec */
dev_dbg(dev, "Count As Normal\n");
@ -655,13 +646,10 @@ static int graph_count_dpcm(struct asoc_simple_priv *priv,
li->num[li->link].platforms = 1;
li->link++; /* 1xCPU-dummy */
li->dais++; /* 1xCPU */
} else {
li->num[li->link].codecs = 1;
li->link++; /* 1xdummy-Codec */
li->conf++; /* 1xdummy-Codec */
li->dais++; /* 1xCodec */
}
dev_dbg(dev, "Count As DPCM\n");
@ -672,8 +660,6 @@ static int graph_count_dpcm(struct asoc_simple_priv *priv,
static void graph_get_dais_count(struct asoc_simple_priv *priv,
struct link_info *li)
{
struct device *dev = simple_priv_to_dev(priv);
/*
* link_num : number of links.
* CPU-Codec / CPU-dummy / dummy-Codec
@ -723,8 +709,6 @@ static void graph_get_dais_count(struct asoc_simple_priv *priv,
graph_for_each_link(priv, li,
graph_count_noml,
graph_count_dpcm);
dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
li->link, li->dais, li->conf);
}
int audio_graph_card_probe(struct snd_soc_card *card)

View File

@ -32,8 +32,7 @@ void asoc_simple_convert_fixup(struct asoc_simple_data *data,
}
EXPORT_SYMBOL_GPL(asoc_simple_convert_fixup);
void asoc_simple_parse_convert(struct device *dev,
struct device_node *np,
void asoc_simple_parse_convert(struct device_node *np,
char *prefix,
struct asoc_simple_data *data)
{
@ -195,17 +194,37 @@ int asoc_simple_startup(struct snd_pcm_substream *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 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;
ret = asoc_simple_clk_enable(dai_props->cpu_dai);
if (ret)
return ret;
for_each_prop_dai_cpu(props, i1, dai) {
ret = asoc_simple_clk_enable(dai);
if (ret)
goto cpu_err;
}
ret = asoc_simple_clk_enable(dai_props->codec_dai);
if (ret)
asoc_simple_clk_disable(dai_props->cpu_dai);
for_each_prop_dai_codec(props, i2, dai) {
ret = asoc_simple_clk_enable(dai);
if (ret)
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;
}
EXPORT_SYMBOL_GPL(asoc_simple_startup);
@ -216,17 +235,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 *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
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 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(cpu_dai, 0, 0, SND_SOC_CLOCK_OUT);
}
asoc_simple_clk_disable(dai_props->cpu_dai);
asoc_simple_clk_disable(dai_props->codec_dai);
for_each_prop_dai_cpu(props, i, dai)
asoc_simple_clk_disable(dai);
for_each_prop_dai_codec(props, i, dai)
asoc_simple_clk_disable(dai);
}
EXPORT_SYMBOL_GPL(asoc_simple_shutdown);
@ -249,41 +270,41 @@ int asoc_simple_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
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 asoc_simple_dai *pdai;
struct snd_soc_dai *sdai;
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);
unsigned int mclk, mclk_fs = 0;
int ret;
int i, ret;
if (dai_props->mclk_fs)
mclk_fs = dai_props->mclk_fs;
if (props->mclk_fs)
mclk_fs = props->mclk_fs;
if (mclk_fs) {
mclk = params_rate(params) * mclk_fs;
ret = asoc_simple_set_clk_rate(dai_props->codec_dai, mclk);
if (ret < 0)
return ret;
ret = asoc_simple_set_clk_rate(dai_props->cpu_dai, mclk);
if (ret < 0)
return ret;
ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
SND_SOC_CLOCK_IN);
if (ret && ret != -ENOTSUPP)
goto err;
ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
SND_SOC_CLOCK_OUT);
if (ret && ret != -ENOTSUPP)
goto err;
for_each_prop_dai_codec(props, i, pdai) {
ret = asoc_simple_set_clk_rate(pdai, mclk);
if (ret < 0)
return ret;
}
for_each_prop_dai_cpu(props, i, pdai) {
ret = asoc_simple_set_clk_rate(pdai, mclk);
if (ret < 0)
return ret;
}
for_each_rtd_codec_dais(rtd, i, sdai) {
ret = snd_soc_dai_set_sysclk(sdai, 0, 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);
if (ret && ret != -ENOTSUPP)
return ret;
}
}
return 0;
err:
return ret;
}
EXPORT_SYMBOL_GPL(asoc_simple_hw_params);
@ -378,20 +399,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)
{
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);
int ret;
struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num);
struct asoc_simple_dai *dai;
int i, ret;
ret = asoc_simple_init_dai(asoc_rtd_to_codec(rtd, 0),
dai_props->codec_dai);
if (ret < 0)
return ret;
for_each_prop_dai_codec(props, i, dai) {
ret = asoc_simple_init_dai(asoc_rtd_to_codec(rtd, i), dai);
if (ret < 0)
return ret;
}
for_each_prop_dai_cpu(props, i, dai) {
ret = asoc_simple_init_dai(asoc_rtd_to_cpu(rtd, i), dai);
if (ret < 0)
return ret;
}
ret = asoc_simple_init_dai(asoc_rtd_to_cpu(rtd, 0),
dai_props->cpu_dai);
if (ret < 0)
return ret;
ret = asoc_simple_init_dai_link_params(rtd, dai_props);
ret = asoc_simple_init_dai_link_params(rtd, props);
if (ret < 0)
return ret;
@ -399,15 +422,16 @@ int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd)
}
EXPORT_SYMBOL_GPL(asoc_simple_dai_init);
void asoc_simple_canonicalize_platform(struct snd_soc_dai_link *dai_link)
void asoc_simple_canonicalize_platform(struct snd_soc_dai_link_component *platforms,
struct snd_soc_dai_link_component *cpus)
{
/* Assumes platform == cpu */
if (!dai_link->platforms->of_node)
dai_link->platforms->of_node = dai_link->cpus->of_node;
if (!platforms->of_node)
platforms->of_node = cpus->of_node;
}
EXPORT_SYMBOL_GPL(asoc_simple_canonicalize_platform);
void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link_component *cpus,
int is_single_links)
{
/*
@ -420,18 +444,22 @@ void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
* fmt_multiple_name()
*/
if (is_single_links)
dai_link->cpus->dai_name = NULL;
cpus->dai_name = NULL;
}
EXPORT_SYMBOL_GPL(asoc_simple_canonicalize_cpu);
int asoc_simple_clean_reference(struct snd_soc_card *card)
{
struct snd_soc_dai_link *dai_link;
int i;
struct snd_soc_dai_link_component *cpu;
struct snd_soc_dai_link_component *codec;
int i, j;
for_each_card_prelinks(card, i, dai_link) {
of_node_put(dai_link->cpus->of_node);
of_node_put(dai_link->codecs->of_node);
for_each_link_cpus(dai_link, j, cpu)
of_node_put(cpu->of_node);
for_each_link_codecs(dai_link, j, codec)
of_node_put(codec->of_node);
}
return 0;
}
@ -597,7 +625,7 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
struct asoc_simple_dai *dais;
struct snd_soc_dai_link_component *dlcs;
struct snd_soc_codec_conf *cconf = NULL;
int i, dai_num = 0, dlc_num = 0;
int i, dai_num = 0, dlc_num = 0, cnf_num = 0;
dai_props = devm_kcalloc(dev, li->link, sizeof(*dai_props), GFP_KERNEL);
dai_link = devm_kcalloc(dev, li->link, sizeof(*dai_link), GFP_KERNEL);
@ -613,6 +641,9 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
dai_num += cc;
dlc_num += cc + li->num[i].platforms;
if (!li->num[i].cpus)
cnf_num += li->num[i].codecs;
}
dais = devm_kcalloc(dev, dai_num, sizeof(*dais), GFP_KERNEL);
@ -620,12 +651,15 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
if (!dais || !dlcs)
return -ENOMEM;
if (li->conf) {
cconf = devm_kcalloc(dev, li->conf, sizeof(*cconf), GFP_KERNEL);
if (cnf_num) {
cconf = devm_kcalloc(dev, cnf_num, sizeof(*cconf), GFP_KERNEL);
if (!cconf)
return -ENOMEM;
}
dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
li->link, dai_num, cnf_num);
/* dummy CPU/Codec */
priv->dummy.of_node = NULL;
priv->dummy.dai_name = "snd-soc-dummy-dai";
@ -640,7 +674,7 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
card->dai_link = priv->dai_link;
card->num_links = li->link;
card->codec_conf = cconf;
card->num_configs = li->conf;
card->num_configs = cnf_num;
for (i = 0; i < li->link; i++) {
if (li->num[i].cpus) {
@ -649,8 +683,10 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
dai_link[i].cpus = dlcs;
dai_props[i].num.cpus =
dai_link[i].num_cpus = li->num[i].cpus;
dai_props[i].cpu_dai = dais;
dlcs += li->num[i].cpus;
dais += li->num[i].cpus;
} else {
/* DPCM Be's CPU = dummy */
dai_props[i].cpus =
@ -665,8 +701,16 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
dai_link[i].codecs = dlcs;
dai_props[i].num.codecs =
dai_link[i].num_codecs = li->num[i].codecs;
dai_props[i].codec_dai = dais;
dlcs += li->num[i].codecs;
dais += li->num[i].codecs;
if (!li->num[i].cpus) {
/* DPCM Be's Codec */
dai_props[i].codec_conf = cconf;
cconf += li->num[i].codecs;
}
} else {
/* DPCM Fe's Codec = dummy */
dai_props[i].codecs =

View File

@ -84,10 +84,10 @@ static void simple_parse_convert(struct device *dev,
struct device_node *top = dev->of_node;
struct device_node *node = of_get_parent(np);
asoc_simple_parse_convert(dev, top, PREFIX, adata);
asoc_simple_parse_convert(dev, node, PREFIX, adata);
asoc_simple_parse_convert(dev, node, NULL, adata);
asoc_simple_parse_convert(dev, np, NULL, adata);
asoc_simple_parse_convert(top, PREFIX, adata);
asoc_simple_parse_convert(node, PREFIX, adata);
asoc_simple_parse_convert(node, NULL, adata);
asoc_simple_parse_convert(np, NULL, adata);
of_node_put(node);
}
@ -124,6 +124,7 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
struct asoc_simple_dai *dai;
struct snd_soc_dai_link_component *cpus = dai_link->cpus;
struct snd_soc_dai_link_component *codecs = dai_link->codecs;
struct snd_soc_dai_link_component *platforms = dai_link->platforms;
struct device_node *top = dev->of_node;
struct device_node *node = of_get_parent(np);
char *prefix = "";
@ -146,14 +147,13 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
dai_link->dynamic = 1;
dai_link->dpcm_merged_format = 1;
dai =
dai_props->cpu_dai = &priv->dais[li->dais++];
dai = dai_props->cpu_dai;
ret = asoc_simple_parse_cpu(np, dai_link, &is_single_links);
ret = asoc_simple_parse_dai(np, dai_link->cpus, &is_single_links);
if (ret)
goto out_put_node;
ret = asoc_simple_parse_clk_cpu(dev, np, dai_link, dai);
ret = asoc_simple_parse_clk(dev, np, dai, dai_link->cpus);
if (ret < 0)
goto out_put_node;
@ -163,8 +163,8 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
if (ret < 0)
goto out_put_node;
asoc_simple_canonicalize_cpu(dai_link, is_single_links);
asoc_simple_canonicalize_platform(dai_link);
asoc_simple_canonicalize_cpu(cpus, is_single_links);
asoc_simple_canonicalize_platform(platforms, cpus);
} else {
struct snd_soc_codec_conf *cconf;
@ -174,17 +174,14 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
dai_link->no_pcm = 1;
dai_link->be_hw_params_fixup = asoc_simple_be_hw_params_fixup;
dai =
dai_props->codec_dai = &priv->dais[li->dais++];
dai = dai_props->codec_dai;
cconf = dai_props->codec_conf;
cconf =
dai_props->codec_conf = &priv->codec_conf[li->conf++];
ret = asoc_simple_parse_codec(np, dai_link);
ret = asoc_simple_parse_dai(np, dai_link->codecs, NULL);
if (ret < 0)
goto out_put_node;
ret = asoc_simple_parse_clk_codec(dev, np, dai_link, dai);
ret = asoc_simple_parse_clk(dev, np, dai, dai_link->codecs);
if (ret < 0)
goto out_put_node;
@ -234,8 +231,8 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
struct device *dev = simple_priv_to_dev(priv);
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
struct asoc_simple_dai *cpu_dai;
struct asoc_simple_dai *codec_dai;
struct asoc_simple_dai *cpu_dai = dai_props->cpu_dai;
struct asoc_simple_dai *codec_dai = dai_props->codec_dai;
struct device_node *top = dev->of_node;
struct device_node *cpu = NULL;
struct device_node *node = NULL;
@ -257,11 +254,6 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
snprintf(prop, sizeof(prop), "%splat", prefix);
plat = of_get_child_by_name(node, prop);
cpu_dai =
dai_props->cpu_dai = &priv->dais[li->dais++];
codec_dai =
dai_props->codec_dai = &priv->dais[li->dais++];
ret = asoc_simple_parse_daifmt(dev, node, codec,
prefix, &dai_link->dai_fmt);
if (ret < 0)
@ -269,15 +261,15 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
simple_parse_mclk_fs(top, cpu, codec, dai_props, prefix);
ret = asoc_simple_parse_cpu(cpu, dai_link, &single_cpu);
ret = asoc_simple_parse_dai(cpu, dai_link->cpus, &single_cpu);
if (ret < 0)
goto dai_link_of_err;
ret = asoc_simple_parse_codec(codec, dai_link);
ret = asoc_simple_parse_dai(codec, dai_link->codecs, NULL);
if (ret < 0)
goto dai_link_of_err;
ret = asoc_simple_parse_platform(plat, dai_link);
ret = asoc_simple_parse_dai(plat, dai_link->platforms, NULL);
if (ret < 0)
goto dai_link_of_err;
@ -289,11 +281,11 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
if (ret < 0)
goto dai_link_of_err;
ret = asoc_simple_parse_clk_cpu(dev, cpu, dai_link, cpu_dai);
ret = asoc_simple_parse_clk(dev, cpu, cpu_dai, dai_link->cpus);
if (ret < 0)
goto dai_link_of_err;
ret = asoc_simple_parse_clk_codec(dev, codec, dai_link, codec_dai);
ret = asoc_simple_parse_clk(dev, codec, codec_dai, dai_link->codecs);
if (ret < 0)
goto dai_link_of_err;
@ -307,8 +299,8 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
dai_link->ops = &simple_ops;
dai_link->init = asoc_simple_dai_init;
asoc_simple_canonicalize_cpu(dai_link, single_cpu);
asoc_simple_canonicalize_platform(dai_link);
asoc_simple_canonicalize_cpu(dai_link->cpus, single_cpu);
asoc_simple_canonicalize_platform(dai_link->platforms, dai_link->cpus);
dai_link_of_err:
of_node_put(plat);
@ -504,7 +496,6 @@ static int simple_count_noml(struct asoc_simple_priv *priv,
li->num[li->link].platforms = 1;
li->link += 1;
li->dais += 2;
return 0;
}
@ -526,13 +517,10 @@ static int simple_count_dpcm(struct asoc_simple_priv *priv,
li->num[li->link].platforms = 1;
li->link++; /* CPU-dummy */
li->dais++;
} else {
li->num[li->link].codecs = 1;
li->link++; /* dummy-Codec */
li->dais++;
li->conf++;
}
return 0;
@ -596,17 +584,12 @@ static void simple_get_dais_count(struct asoc_simple_priv *priv,
li->num[0].platforms = 1;
li->link = 1;
li->dais = 2;
li->conf = 0;
return;
}
simple_for_each_link(priv, li,
simple_count_noml,
simple_count_dpcm);
dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
li->link, li->dais, li->conf);
}
static int simple_soc_probe(struct snd_soc_card *card)
@ -646,7 +629,7 @@ static int asoc_simple_probe(struct platform_device *pdev)
memset(&li, 0, sizeof(li));
simple_get_dais_count(priv, &li);
if (!li.link || !li.dais)
if (!li.link)
return -EINVAL;
ret = asoc_simple_init_priv(priv, &li);
@ -670,8 +653,6 @@ static int asoc_simple_probe(struct platform_device *pdev)
struct snd_soc_dai_link *dai_link = priv->dai_link;
struct simple_dai_props *dai_props = priv->dai_props;
int dai_idx = 0;
cinfo = dev->platform_data;
if (!cinfo) {
dev_err(dev, "no info for asoc-simple-card\n");
@ -687,9 +668,6 @@ static int asoc_simple_probe(struct platform_device *pdev)
return -EINVAL;
}
dai_props->cpu_dai = &priv->dais[dai_idx++];
dai_props->codec_dai = &priv->dais[dai_idx++];
cpus = dai_link->cpus;
cpus->dai_name = cinfo->cpu_dai.name;