aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2017-06-14 20:24:09 -0400
committerMark Brown <broonie@kernel.org>2017-06-15 13:14:43 -0400
commit13bb1cc0ad205b2aeeb8d2ea5c790a396135283d (patch)
tree711d88cb5bb5ff5b80651a5c88748537ae3eac93
parent616c3b15f596e1f1e6c2537a1ad3492052eecba6 (diff)
ASoC: simple-card-utils: add asoc_simple_card_convert_fixup()
Current simple/audio scu card drivers are supporting same convert-rate/convert-channels on DT, but doesn't use same function for it. Encapsulation is one of simple card util's purpose. Let's add asoc_simple_card_parse_convert/asoc_simple_card_convert_fixup Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--include/sound/simple_card_utils.h10
-rw-r--r--sound/soc/generic/simple-card-utils.c40
2 files changed, 50 insertions, 0 deletions
diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index 2679312228b3..cc318ccd6a2d 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -22,6 +22,11 @@ struct asoc_simple_dai {
22 struct clk *clk; 22 struct clk *clk;
23}; 23};
24 24
25struct asoc_simple_card_data {
26 u32 convert_rate;
27 u32 convert_channels;
28};
29
25int asoc_simple_card_parse_daifmt(struct device *dev, 30int asoc_simple_card_parse_daifmt(struct device *dev,
26 struct device_node *node, 31 struct device_node *node,
27 struct device_node *codec, 32 struct device_node *codec,
@@ -90,4 +95,9 @@ void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
90 95
91int asoc_simple_card_clean_reference(struct snd_soc_card *card); 96int asoc_simple_card_clean_reference(struct snd_soc_card *card);
92 97
98void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data,
99 struct snd_pcm_hw_params *params);
100void asoc_simple_card_parse_convert(struct device *dev, char *prefix,
101 struct asoc_simple_card_data *data);
102
93#endif /* __SIMPLE_CARD_UTILS_H */ 103#endif /* __SIMPLE_CARD_UTILS_H */
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 2ad7633292bf..948a18842e64 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -13,6 +13,46 @@
13#include <linux/of_graph.h> 13#include <linux/of_graph.h>
14#include <sound/simple_card_utils.h> 14#include <sound/simple_card_utils.h>
15 15
16void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data,
17 struct snd_pcm_hw_params *params)
18{
19 struct snd_interval *rate = hw_param_interval(params,
20 SNDRV_PCM_HW_PARAM_RATE);
21 struct snd_interval *channels = hw_param_interval(params,
22 SNDRV_PCM_HW_PARAM_CHANNELS);
23
24 if (data->convert_rate)
25 rate->min =
26 rate->max = data->convert_rate;
27
28 if (data->convert_channels)
29 channels->min =
30 channels->max = data->convert_channels;
31}
32EXPORT_SYMBOL_GPL(asoc_simple_card_convert_fixup);
33
34void asoc_simple_card_parse_convert(struct device *dev, char *prefix,
35 struct asoc_simple_card_data *data)
36{
37 struct device_node *np = dev->of_node;
38 char prop[128];
39
40 if (!prefix)
41 prefix = "";
42
43 /* sampling rate convert */
44 snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-rate");
45 of_property_read_u32(np, prop, &data->convert_rate);
46
47 /* channels transfer */
48 snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-channels");
49 of_property_read_u32(np, prop, &data->convert_channels);
50
51 dev_dbg(dev, "convert_rate %d\n", data->convert_rate);
52 dev_dbg(dev, "convert_channels %d\n", data->convert_channels);
53}
54EXPORT_SYMBOL_GPL(asoc_simple_card_parse_convert);
55
16int asoc_simple_card_parse_daifmt(struct device *dev, 56int asoc_simple_card_parse_daifmt(struct device *dev,
17 struct device_node *node, 57 struct device_node *node,
18 struct device_node *codec, 58 struct device_node *codec,