summaryrefslogtreecommitdiffstats
path: root/sound/soc/generic
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2019-03-20 00:55:39 -0400
committerMark Brown <broonie@kernel.org>2019-03-21 10:51:43 -0400
commitf48dcbb6d47d870cf3a03f453c923dd262158c66 (patch)
treebff3a7142fc2ddd2ecf8a27904c0f86de3252ae3 /sound/soc/generic
parent686911b46fb5a08df142fe22b6c06dc6fbd3ba65 (diff)
ASoC: simple-card-utils: share asoc_simple_hw_param()
The difference between simple-card / audio-graph are just using OF graph style, or not. In other words, other things should be same. This means, simple-card/audio-graph common functions should be implemented at simple-card-utils, and its own functions should be implemented at each files. Current simple-card / audio-graph have almost same functions. This patch shares asoc_simple_hw_param() between in these 2 drivers. One note is that only simple-card supports simple_set_clk_rate() at hw_param from commit e9be4ffd4f40fcb ("ASoC: simple-card: set cpu dai clk in hw_params"). By this patch, audio-graph has same feature. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/generic')
-rw-r--r--sound/soc/generic/audio-graph-card.c33
-rw-r--r--sound/soc/generic/simple-card-utils.c57
-rw-r--r--sound/soc/generic/simple-card.c58
3 files changed, 59 insertions, 89 deletions
diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c
index f3577b5bf14c..51160adaf5bb 100644
--- a/sound/soc/generic/audio-graph-card.c
+++ b/sound/soc/generic/audio-graph-card.c
@@ -56,41 +56,10 @@ static const struct snd_soc_dapm_widget graph_dapm_widgets[] = {
56 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), 56 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
57}; 57};
58 58
59static int graph_hw_params(struct snd_pcm_substream *substream,
60 struct snd_pcm_hw_params *params)
61{
62 struct snd_soc_pcm_runtime *rtd = substream->private_data;
63 struct snd_soc_dai *codec_dai = rtd->codec_dai;
64 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
65 struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
66 struct simple_dai_props *dai_props = simple_priv_to_props(priv, rtd->num);
67 unsigned int mclk, mclk_fs = 0;
68 int ret = 0;
69
70 if (dai_props->mclk_fs)
71 mclk_fs = dai_props->mclk_fs;
72
73 if (mclk_fs) {
74 mclk = params_rate(params) * mclk_fs;
75 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
76 SND_SOC_CLOCK_IN);
77 if (ret && ret != -ENOTSUPP)
78 goto err;
79
80 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
81 SND_SOC_CLOCK_OUT);
82 if (ret && ret != -ENOTSUPP)
83 goto err;
84 }
85 return 0;
86err:
87 return ret;
88}
89
90static const struct snd_soc_ops graph_ops = { 59static const struct snd_soc_ops graph_ops = {
91 .startup = asoc_simple_startup, 60 .startup = asoc_simple_startup,
92 .shutdown = asoc_simple_shutdown, 61 .shutdown = asoc_simple_shutdown,
93 .hw_params = graph_hw_params, 62 .hw_params = asoc_simple_hw_params,
94}; 63};
95 64
96static int graph_dai_init(struct snd_soc_pcm_runtime *rtd) 65static int graph_dai_init(struct snd_soc_pcm_runtime *rtd)
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 7ede16347ea8..de23cf8bffbd 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -236,6 +236,63 @@ void asoc_simple_shutdown(struct snd_pcm_substream *substream)
236} 236}
237EXPORT_SYMBOL_GPL(asoc_simple_shutdown); 237EXPORT_SYMBOL_GPL(asoc_simple_shutdown);
238 238
239static int asoc_simple_set_clk_rate(struct asoc_simple_dai *simple_dai,
240 unsigned long rate)
241{
242 if (!simple_dai)
243 return 0;
244
245 if (!simple_dai->clk)
246 return 0;
247
248 if (clk_get_rate(simple_dai->clk) == rate)
249 return 0;
250
251 return clk_set_rate(simple_dai->clk, rate);
252}
253
254int asoc_simple_hw_params(struct snd_pcm_substream *substream,
255 struct snd_pcm_hw_params *params)
256{
257 struct snd_soc_pcm_runtime *rtd = substream->private_data;
258 struct snd_soc_dai *codec_dai = rtd->codec_dai;
259 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
260 struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
261 struct simple_dai_props *dai_props =
262 simple_priv_to_props(priv, rtd->num);
263 unsigned int mclk, mclk_fs = 0;
264 int ret = 0;
265
266 if (dai_props->mclk_fs)
267 mclk_fs = dai_props->mclk_fs;
268
269 if (mclk_fs) {
270 mclk = params_rate(params) * mclk_fs;
271
272 ret = asoc_simple_set_clk_rate(dai_props->codec_dai, mclk);
273 if (ret < 0)
274 return ret;
275
276 ret = asoc_simple_set_clk_rate(dai_props->cpu_dai, mclk);
277 if (ret < 0)
278 return ret;
279
280 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
281 SND_SOC_CLOCK_IN);
282 if (ret && ret != -ENOTSUPP)
283 goto err;
284
285 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
286 SND_SOC_CLOCK_OUT);
287 if (ret && ret != -ENOTSUPP)
288 goto err;
289 }
290 return 0;
291err:
292 return ret;
293}
294EXPORT_SYMBOL_GPL(asoc_simple_hw_params);
295
239int asoc_simple_card_parse_dai(struct device_node *node, 296int asoc_simple_card_parse_dai(struct device_node *node,
240 struct snd_soc_dai_link_component *dlc, 297 struct snd_soc_dai_link_component *dlc,
241 struct device_node **dai_of_node, 298 struct device_node **dai_of_node,
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index bb57c482eac8..7e836473eb11 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -26,66 +26,10 @@ struct link_info {
26#define CELL "#sound-dai-cells" 26#define CELL "#sound-dai-cells"
27#define PREFIX "simple-audio-card," 27#define PREFIX "simple-audio-card,"
28 28
29static int simple_set_clk_rate(struct asoc_simple_dai *simple_dai,
30 unsigned long rate)
31{
32 if (!simple_dai)
33 return 0;
34
35 if (!simple_dai->clk)
36 return 0;
37
38 if (clk_get_rate(simple_dai->clk) == rate)
39 return 0;
40
41 return clk_set_rate(simple_dai->clk, rate);
42}
43
44static int simple_hw_params(struct snd_pcm_substream *substream,
45 struct snd_pcm_hw_params *params)
46{
47 struct snd_soc_pcm_runtime *rtd = substream->private_data;
48 struct snd_soc_dai *codec_dai = rtd->codec_dai;
49 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
50 struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
51 struct simple_dai_props *dai_props =
52 simple_priv_to_props(priv, rtd->num);
53 unsigned int mclk, mclk_fs = 0;
54 int ret = 0;
55
56 if (dai_props->mclk_fs)
57 mclk_fs = dai_props->mclk_fs;
58
59 if (mclk_fs) {
60 mclk = params_rate(params) * mclk_fs;
61
62 ret = simple_set_clk_rate(dai_props->codec_dai, mclk);
63 if (ret < 0)
64 return ret;
65
66 ret = simple_set_clk_rate(dai_props->cpu_dai, mclk);
67 if (ret < 0)
68 return ret;
69
70 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
71 SND_SOC_CLOCK_IN);
72 if (ret && ret != -ENOTSUPP)
73 goto err;
74
75 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
76 SND_SOC_CLOCK_OUT);
77 if (ret && ret != -ENOTSUPP)
78 goto err;
79 }
80 return 0;
81err:
82 return ret;
83}
84
85static const struct snd_soc_ops simple_ops = { 29static const struct snd_soc_ops simple_ops = {
86 .startup = asoc_simple_startup, 30 .startup = asoc_simple_startup,
87 .shutdown = asoc_simple_shutdown, 31 .shutdown = asoc_simple_shutdown,
88 .hw_params = simple_hw_params, 32 .hw_params = asoc_simple_hw_params,
89}; 33};
90 34
91static int simple_dai_init(struct snd_soc_pcm_runtime *rtd) 35static int simple_dai_init(struct snd_soc_pcm_runtime *rtd)