diff options
author | Sylwester Nawrocki <s.nawrocki@samsung.com> | 2017-04-21 13:19:50 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2017-04-21 13:27:58 -0400 |
commit | aba611fc4c69896f1355ff0b8ff0ff21c9b5b6fb (patch) | |
tree | 0b6c7598d6fb44acee5af4ae10ea0a8720826fd5 | |
parent | 92c9f05ebc7290e638c7b1b85288918c4fc65d4e (diff) |
ASoC: samsung: Add Odroid ASoC machine driver
This dedicated driver allows to support SoC specific clock
settings and helps to ensure proper number of channels gets
negotiated in multicodec system configurations.
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | sound/soc/samsung/Kconfig | 8 | ||||
-rw-r--r-- | sound/soc/samsung/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/samsung/odroid.c | 219 |
3 files changed, 229 insertions, 0 deletions
diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig index f1f1d7959a1b..0520f5afd7cc 100644 --- a/sound/soc/samsung/Kconfig +++ b/sound/soc/samsung/Kconfig | |||
@@ -185,6 +185,14 @@ config SND_SOC_SNOW | |||
185 | Say Y if you want to add audio support for various Snow | 185 | Say Y if you want to add audio support for various Snow |
186 | boards based on Exynos5 series of SoCs. | 186 | boards based on Exynos5 series of SoCs. |
187 | 187 | ||
188 | config SND_SOC_ODROID | ||
189 | tristate "Audio support for Odroid XU3/XU4" | ||
190 | depends on SND_SOC_SAMSUNG && I2C | ||
191 | select SND_SOC_MAX98090 | ||
192 | select SND_SAMSUNG_I2S | ||
193 | help | ||
194 | Say Y here to enable audio support for the Odroid XU3/XU4. | ||
195 | |||
188 | config SND_SOC_ARNDALE_RT5631_ALC5631 | 196 | config SND_SOC_ARNDALE_RT5631_ALC5631 |
189 | tristate "Audio support for RT5631(ALC5631) on Arndale Board" | 197 | tristate "Audio support for RT5631(ALC5631) on Arndale Board" |
190 | depends on I2C | 198 | depends on I2C |
diff --git a/sound/soc/samsung/Makefile b/sound/soc/samsung/Makefile index b5df5e2e3d94..b6c2ee358333 100644 --- a/sound/soc/samsung/Makefile +++ b/sound/soc/samsung/Makefile | |||
@@ -40,6 +40,7 @@ snd-soc-tobermory-objs := tobermory.o | |||
40 | snd-soc-lowland-objs := lowland.o | 40 | snd-soc-lowland-objs := lowland.o |
41 | snd-soc-littlemill-objs := littlemill.o | 41 | snd-soc-littlemill-objs := littlemill.o |
42 | snd-soc-bells-objs := bells.o | 42 | snd-soc-bells-objs := bells.o |
43 | snd-soc-odroid-objs := odroid.o | ||
43 | snd-soc-arndale-rt5631-objs := arndale_rt5631.o | 44 | snd-soc-arndale-rt5631-objs := arndale_rt5631.o |
44 | snd-soc-tm2-wm5110-objs := tm2_wm5110.o | 45 | snd-soc-tm2-wm5110-objs := tm2_wm5110.o |
45 | 46 | ||
@@ -62,5 +63,6 @@ obj-$(CONFIG_SND_SOC_TOBERMORY) += snd-soc-tobermory.o | |||
62 | obj-$(CONFIG_SND_SOC_LOWLAND) += snd-soc-lowland.o | 63 | obj-$(CONFIG_SND_SOC_LOWLAND) += snd-soc-lowland.o |
63 | obj-$(CONFIG_SND_SOC_LITTLEMILL) += snd-soc-littlemill.o | 64 | obj-$(CONFIG_SND_SOC_LITTLEMILL) += snd-soc-littlemill.o |
64 | obj-$(CONFIG_SND_SOC_BELLS) += snd-soc-bells.o | 65 | obj-$(CONFIG_SND_SOC_BELLS) += snd-soc-bells.o |
66 | obj-$(CONFIG_SND_SOC_ODROID) += snd-soc-odroid.o | ||
65 | obj-$(CONFIG_SND_SOC_ARNDALE_RT5631_ALC5631) += snd-soc-arndale-rt5631.o | 67 | obj-$(CONFIG_SND_SOC_ARNDALE_RT5631_ALC5631) += snd-soc-arndale-rt5631.o |
66 | obj-$(CONFIG_SND_SOC_SAMSUNG_TM2_WM5110) += snd-soc-tm2-wm5110.o | 68 | obj-$(CONFIG_SND_SOC_SAMSUNG_TM2_WM5110) += snd-soc-tm2-wm5110.o |
diff --git a/sound/soc/samsung/odroid.c b/sound/soc/samsung/odroid.c new file mode 100644 index 000000000000..0c0b00e40646 --- /dev/null +++ b/sound/soc/samsung/odroid.c | |||
@@ -0,0 +1,219 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 Samsung Electronics Co., Ltd. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #include <linux/clk.h> | ||
10 | #include <linux/of.h> | ||
11 | #include <linux/of_device.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <sound/soc.h> | ||
14 | #include <sound/pcm_params.h> | ||
15 | #include "i2s.h" | ||
16 | #include "i2s-regs.h" | ||
17 | |||
18 | struct odroid_priv { | ||
19 | struct snd_soc_card card; | ||
20 | struct snd_soc_dai_link dai_link; | ||
21 | |||
22 | struct clk *pll; | ||
23 | struct clk *rclk; | ||
24 | }; | ||
25 | |||
26 | static int odroid_card_startup(struct snd_pcm_substream *substream) | ||
27 | { | ||
28 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
29 | |||
30 | snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, 2); | ||
31 | return 0; | ||
32 | } | ||
33 | |||
34 | static int odroid_card_hw_params(struct snd_pcm_substream *substream, | ||
35 | struct snd_pcm_hw_params *params) | ||
36 | { | ||
37 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
38 | struct odroid_priv *priv = snd_soc_card_get_drvdata(rtd->card); | ||
39 | unsigned int pll_freq, rclk_freq; | ||
40 | int ret; | ||
41 | |||
42 | switch (params_rate(params)) { | ||
43 | case 32000: | ||
44 | case 64000: | ||
45 | pll_freq = 131072000U; | ||
46 | break; | ||
47 | case 44100: | ||
48 | case 88200: | ||
49 | case 176400: | ||
50 | pll_freq = 180633600U; | ||
51 | break; | ||
52 | case 48000: | ||
53 | case 96000: | ||
54 | case 192000: | ||
55 | pll_freq = 196608000U; | ||
56 | break; | ||
57 | default: | ||
58 | return -EINVAL; | ||
59 | } | ||
60 | |||
61 | ret = clk_set_rate(priv->pll, pll_freq + 1); | ||
62 | if (ret < 0) | ||
63 | return ret; | ||
64 | |||
65 | rclk_freq = params_rate(params) * 256 * 4; | ||
66 | |||
67 | ret = clk_set_rate(priv->rclk, rclk_freq); | ||
68 | if (ret < 0) | ||
69 | return ret; | ||
70 | |||
71 | if (rtd->num_codecs > 1) { | ||
72 | struct snd_soc_dai *codec_dai = rtd->codec_dais[1]; | ||
73 | |||
74 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, rclk_freq, | ||
75 | SND_SOC_CLOCK_IN); | ||
76 | if (ret < 0) | ||
77 | return ret; | ||
78 | } | ||
79 | |||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | static const struct snd_soc_ops odroid_card_ops = { | ||
84 | .startup = odroid_card_startup, | ||
85 | .hw_params = odroid_card_hw_params, | ||
86 | }; | ||
87 | |||
88 | static void odroid_put_codec_of_nodes(struct snd_soc_dai_link *link) | ||
89 | { | ||
90 | struct snd_soc_dai_link_component *component = link->codecs; | ||
91 | int i; | ||
92 | |||
93 | for (i = 0; i < link->num_codecs; i++, component++) { | ||
94 | if (!component->of_node) | ||
95 | break; | ||
96 | of_node_put(component->of_node); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | static int odroid_audio_probe(struct platform_device *pdev) | ||
101 | { | ||
102 | struct device *dev = &pdev->dev; | ||
103 | struct device_node *cpu, *codec; | ||
104 | struct odroid_priv *priv; | ||
105 | struct snd_soc_dai_link *link; | ||
106 | struct snd_soc_card *card; | ||
107 | int ret; | ||
108 | |||
109 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | ||
110 | if (!priv) | ||
111 | return -ENOMEM; | ||
112 | |||
113 | card = &priv->card; | ||
114 | card->dev = dev; | ||
115 | |||
116 | card->owner = THIS_MODULE; | ||
117 | card->fully_routed = true; | ||
118 | |||
119 | snd_soc_card_set_drvdata(card, priv); | ||
120 | |||
121 | priv->pll = devm_clk_get(dev, "epll"); | ||
122 | if (IS_ERR(priv->pll)) | ||
123 | return PTR_ERR(priv->pll); | ||
124 | |||
125 | priv->rclk = devm_clk_get(dev, "i2s_rclk"); | ||
126 | if (IS_ERR(priv->rclk)) | ||
127 | return PTR_ERR(priv->rclk); | ||
128 | |||
129 | ret = snd_soc_of_parse_card_name(card, "model"); | ||
130 | if (ret < 0) | ||
131 | return ret; | ||
132 | |||
133 | if (of_property_read_bool(dev->of_node, "samsung,audio-widgets")) { | ||
134 | ret = snd_soc_of_parse_audio_simple_widgets(card, | ||
135 | "samsung,audio-widgets"); | ||
136 | if (ret < 0) | ||
137 | return ret; | ||
138 | } | ||
139 | |||
140 | if (of_property_read_bool(dev->of_node, "samsung,audio-routing")) { | ||
141 | ret = snd_soc_of_parse_audio_routing(card, | ||
142 | "samsung,audio-routing"); | ||
143 | if (ret < 0) | ||
144 | return ret; | ||
145 | } | ||
146 | |||
147 | link = &priv->dai_link; | ||
148 | |||
149 | link->ops = &odroid_card_ops; | ||
150 | link->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | | ||
151 | SND_SOC_DAIFMT_CBS_CFS; | ||
152 | |||
153 | card->dai_link = &priv->dai_link; | ||
154 | card->num_links = 1; | ||
155 | |||
156 | cpu = of_get_child_by_name(dev->of_node, "cpu"); | ||
157 | codec = of_get_child_by_name(dev->of_node, "codec"); | ||
158 | |||
159 | link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0); | ||
160 | if (!link->cpu_of_node) { | ||
161 | dev_err(dev, "Failed parsing cpu/sound-dai property\n"); | ||
162 | return -EINVAL; | ||
163 | } | ||
164 | |||
165 | ret = snd_soc_of_get_dai_link_codecs(dev, codec, link); | ||
166 | if (ret < 0) | ||
167 | goto err_put_codec_n; | ||
168 | |||
169 | link->platform_of_node = link->cpu_of_node; | ||
170 | |||
171 | link->name = "Primary"; | ||
172 | link->stream_name = link->name; | ||
173 | |||
174 | ret = devm_snd_soc_register_card(dev, card); | ||
175 | if (ret < 0) { | ||
176 | dev_err(dev, "snd_soc_register_card() failed: %d\n", ret); | ||
177 | goto err_put_i2s_n; | ||
178 | } | ||
179 | |||
180 | return 0; | ||
181 | |||
182 | err_put_i2s_n: | ||
183 | of_node_put(link->cpu_of_node); | ||
184 | err_put_codec_n: | ||
185 | odroid_put_codec_of_nodes(link); | ||
186 | return ret; | ||
187 | } | ||
188 | |||
189 | static int odroid_audio_remove(struct platform_device *pdev) | ||
190 | { | ||
191 | struct odroid_priv *priv = platform_get_drvdata(pdev); | ||
192 | |||
193 | of_node_put(priv->dai_link.cpu_of_node); | ||
194 | odroid_put_codec_of_nodes(&priv->dai_link); | ||
195 | |||
196 | return 0; | ||
197 | } | ||
198 | |||
199 | static const struct of_device_id odroid_audio_of_match[] = { | ||
200 | { .compatible = "samsung,odroid-xu3-audio" }, | ||
201 | { .compatible = "samsung,odroid-xu4-audio"}, | ||
202 | { }, | ||
203 | }; | ||
204 | MODULE_DEVICE_TABLE(of, odroid_audio_of_match); | ||
205 | |||
206 | static struct platform_driver odroid_audio_driver = { | ||
207 | .driver = { | ||
208 | .name = "odroid-audio", | ||
209 | .of_match_table = odroid_audio_of_match, | ||
210 | .pm = &snd_soc_pm_ops, | ||
211 | }, | ||
212 | .probe = odroid_audio_probe, | ||
213 | .remove = odroid_audio_remove, | ||
214 | }; | ||
215 | module_platform_driver(odroid_audio_driver); | ||
216 | |||
217 | MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>"); | ||
218 | MODULE_DESCRIPTION("Odroid XU3/XU4 audio support"); | ||
219 | MODULE_LICENSE("GPL v2"); | ||