Skip to content

Commit

Permalink
ASoC: audio-graph-card: tidyup mclk-fs method
Browse files Browse the repository at this point in the history
Current audio-graph-card is handling "mclk-fs" by many way.
But, it is not useful and readable.
We want to do is that allow having mclk-fs everywere.
This patch support it.
It will be overwrote if lower node has it.

sound {
	mclk-fs = <xxx>; // initial
};

codec {
	ports {
		mclk-fs = <xxx>; // overwrite
		port {
			mclk-fs = <xxx>; // overwrite
			endpoint {
				mclk-fs = <xxx>; // overwrite
			};
		};
	};
};

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Kuninori Morimoto authored and Mark Brown committed Dec 14, 2018
1 parent ae3cb57 commit 56eb818
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions sound/soc/generic/audio-graph-card.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct graph_card_data {
struct snd_soc_codec_conf *codec_conf;
unsigned int mclk_fs;
} *dai_props;
unsigned int mclk_fs;
struct asoc_simple_jack hp_jack;
struct asoc_simple_jack mic_jack;
struct snd_soc_dai_link *dai_link;
Expand Down Expand Up @@ -115,9 +114,7 @@ static int asoc_graph_card_hw_params(struct snd_pcm_substream *substream,
unsigned int mclk, mclk_fs = 0;
int ret = 0;

if (priv->mclk_fs)
mclk_fs = priv->mclk_fs;
else if (dai_props->mclk_fs)
if (dai_props->mclk_fs)
mclk_fs = dai_props->mclk_fs;

if (mclk_fs) {
Expand Down Expand Up @@ -176,7 +173,8 @@ static int asoc_graph_card_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
return 0;
}

static int asoc_graph_card_dai_link_of_dpcm(struct device_node *cpu_ep,
static int asoc_graph_card_dai_link_of_dpcm(struct device_node *top,
struct device_node *cpu_ep,
struct device_node *codec_ep,
struct graph_card_data *priv,
int *dai_idx, int link_idx,
Expand All @@ -187,12 +185,21 @@ static int asoc_graph_card_dai_link_of_dpcm(struct device_node *cpu_ep,
struct graph_dai_props *dai_props = graph_priv_to_props(priv, link_idx);
struct snd_soc_card *card = graph_priv_to_card(priv);
struct device_node *ep = is_cpu ? cpu_ep : codec_ep;
struct device_node *port = of_get_parent(ep);
struct device_node *ports = of_get_parent(port);
struct device_node *node = of_graph_get_port_parent(ep);
struct asoc_simple_dai *dai;
int ret;

dev_dbg(dev, "link_of DPCM (for %s)\n", is_cpu ? "CPU" : "Codec");

of_property_read_u32(top, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(ports, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(port, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(ep, "mclk-fs", &dai_props->mclk_fs);
of_node_put(ports);
of_node_put(port);

if (is_cpu) {
struct snd_soc_dai_link_component *codecs;

Expand Down Expand Up @@ -279,8 +286,6 @@ static int asoc_graph_card_dai_link_of_dpcm(struct device_node *cpu_ep,
if (ret < 0)
return ret;

of_property_read_u32(ep, "mclk-fs", &dai_props->mclk_fs);

ret = asoc_simple_card_parse_daifmt(dev, cpu_ep, codec_ep,
NULL, &dai_link->dai_fmt);
if (ret < 0)
Expand All @@ -294,14 +299,19 @@ static int asoc_graph_card_dai_link_of_dpcm(struct device_node *cpu_ep,
return 0;
}

static int asoc_graph_card_dai_link_of(struct device_node *cpu_ep,
static int asoc_graph_card_dai_link_of(struct device_node *top,
struct device_node *cpu_ep,
struct device_node *codec_ep,
struct graph_card_data *priv,
int *dai_idx, int link_idx)
{
struct device *dev = graph_priv_to_dev(priv);
struct snd_soc_dai_link *dai_link = graph_priv_to_link(priv, link_idx);
struct graph_dai_props *dai_props = graph_priv_to_props(priv, link_idx);
struct device_node *cpu_port = of_get_parent(cpu_ep);
struct device_node *codec_port = of_get_parent(codec_ep);
struct device_node *cpu_ports = of_get_parent(cpu_port);
struct device_node *codec_ports = of_get_parent(codec_port);
struct asoc_simple_dai *cpu_dai;
struct asoc_simple_dai *codec_dai;
int ret;
Expand All @@ -313,14 +323,24 @@ static int asoc_graph_card_dai_link_of(struct device_node *cpu_ep,
codec_dai =
dai_props->codec_dai = &priv->dais[(*dai_idx)++];

/* Factor to mclk, used in hw_params() */
of_property_read_u32(top, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(cpu_ports, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(codec_ports, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(cpu_port, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(codec_port, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(cpu_ep, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(codec_ep, "mclk-fs", &dai_props->mclk_fs);
of_node_put(cpu_port);
of_node_put(cpu_ports);
of_node_put(codec_port);
of_node_put(codec_ports);

ret = asoc_simple_card_parse_daifmt(dev, cpu_ep, codec_ep,
NULL, &dai_link->dai_fmt);
if (ret < 0)
return ret;

of_property_read_u32(cpu_ep, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(codec_ep, "mclk-fs", &dai_props->mclk_fs);

ret = asoc_simple_card_parse_graph_cpu(cpu_ep, dai_link);
if (ret < 0)
return ret;
Expand Down Expand Up @@ -370,7 +390,8 @@ static int asoc_graph_card_parse_of(struct graph_card_data *priv)
struct of_phandle_iterator it;
struct device *dev = graph_priv_to_dev(priv);
struct snd_soc_card *card = graph_priv_to_card(priv);
struct device_node *node = dev->of_node;
struct device_node *top = dev->of_node;
struct device_node *node = top;
struct device_node *cpu_port;
struct device_node *cpu_ep = NULL;
struct device_node *codec_ep = NULL;
Expand All @@ -390,9 +411,6 @@ static int asoc_graph_card_parse_of(struct graph_card_data *priv)

asoc_simple_card_parse_convert(dev, node, NULL, &priv->adata);

/* Factor to mclk, used in hw_params() */
of_property_read_u32(node, "mclk-fs", &priv->mclk_fs);

link_idx = 0;
dai_idx = 0;
conf_idx = 0;
Expand Down Expand Up @@ -436,15 +454,15 @@ static int asoc_graph_card_parse_of(struct graph_card_data *priv)
codec_port_old = codec_port;
}
ret = asoc_graph_card_dai_link_of_dpcm(
cpu_ep, codec_ep, priv,
top, cpu_ep, codec_ep, priv,
&dai_idx, link_idx++,
&conf_idx, cpu);
} else if (cpu) {
/*
* for Normal sound
*/
ret = asoc_graph_card_dai_link_of(
cpu_ep, codec_ep, priv,
top, cpu_ep, codec_ep, priv,
&dai_idx, link_idx++);
}
if (ret < 0)
Expand Down

0 comments on commit 56eb818

Please sign in to comment.