aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXing Zheng <zhengxing@rock-chips.com>2016-08-03 04:10:00 -0400
committerMark Brown <broonie@kernel.org>2016-08-08 06:55:10 -0400
commitc6eac8a36a845e52ba520060a807044964ad9de5 (patch)
treedf1c55474854cdef7b3a2b0e392f3c32c9493a3d
parent29b4817d4018df78086157ea3a55c1d9424a7cfc (diff)
ASoC: rockchip: Add machine driver for RK3399 GRU Boards
Because we need to support the multiple codecs (MAX98357A/RT5514/DA7219) on the RK3399 GRU boards, this patch can help us to support these codecs. Signed-off-by: Xing Zheng <zhengxing@rock-chips.com> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--Documentation/devicetree/bindings/sound/rockchip,rk3399-gru-sound.txt15
-rw-r--r--sound/soc/rockchip/Kconfig11
-rw-r--r--sound/soc/rockchip/Makefile2
-rw-r--r--sound/soc/rockchip/rk3399_gru_sound.c337
4 files changed, 365 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/sound/rockchip,rk3399-gru-sound.txt b/Documentation/devicetree/bindings/sound/rockchip,rk3399-gru-sound.txt
new file mode 100644
index 000000000000..f19b6c830a34
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/rockchip,rk3399-gru-sound.txt
@@ -0,0 +1,15 @@
1ROCKCHIP with MAX98357A/RT5514/DA7219 codecs on GRU boards
2
3Required properties:
4- compatible: "rockchip,rk3399-gru-sound"
5- rockchip,cpu: The phandle of the Rockchip I2S controller that's
6 connected to the codecs
7- rockchip,codec: The phandle of the MAX98357A/RT5514/DA7219 codecs
8
9Example:
10
11sound {
12 compatible = "rockchip,rk3399-gru-sound";
13 rockchip,cpu = <&i2s0>;
14 rockchip,codec = <&max98357a &rt5514 &da7219>;
15};
diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig
index f1e0c703e0d2..6d3903284a07 100644
--- a/sound/soc/rockchip/Kconfig
+++ b/sound/soc/rockchip/Kconfig
@@ -41,3 +41,14 @@ config SND_SOC_ROCKCHIP_RT5645
41 help 41 help
42 Say Y or M here if you want to add support for SoC audio on Rockchip 42 Say Y or M here if you want to add support for SoC audio on Rockchip
43 boards using the RT5645/RT5650 codec, such as Veyron. 43 boards using the RT5645/RT5650 codec, such as Veyron.
44
45config SND_SOC_RK3399_GRU_SOUND
46 tristate "ASoC support multiple codecs for Rockchip RK3399 GRU boards"
47 depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP
48 select SND_SOC_ROCKCHIP_I2S
49 select SND_SOC_MAX98357A
50 select SND_SOC_RT5514
51 select SND_SOC_DA7219
52 help
53 Say Y or M here if you want to add support multiple codecs for SoC
54 audio on Rockchip RK3399 GRU boards.
diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile
index c0bf560125f3..84e5c7c700e7 100644
--- a/sound/soc/rockchip/Makefile
+++ b/sound/soc/rockchip/Makefile
@@ -7,6 +7,8 @@ obj-$(CONFIG_SND_SOC_ROCKCHIP_SPDIF) += snd-soc-rockchip-spdif.o
7 7
8snd-soc-rockchip-max98090-objs := rockchip_max98090.o 8snd-soc-rockchip-max98090-objs := rockchip_max98090.o
9snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o 9snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o
10snd-soc-rk3399-gru-sound-objs := rk3399_gru_sound.o
10 11
11obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o 12obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o
12obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o 13obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o
14obj-$(CONFIG_SND_SOC_RK3399_GRU_SOUND) += snd-soc-rk3399-gru-sound.o
diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
new file mode 100644
index 000000000000..9933703f7d44
--- /dev/null
+++ b/sound/soc/rockchip/rk3399_gru_sound.c
@@ -0,0 +1,337 @@
1/*
2 * Rockchip machine ASoC driver for boards using MAX98357A/RT5514/DA7219
3 *
4 * Copyright (c) 2016, ROCKCHIP CORPORATION. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/slab.h>
22#include <linux/gpio.h>
23#include <linux/of_gpio.h>
24#include <linux/delay.h>
25#include <linux/spi/spi.h>
26#include <sound/core.h>
27#include <sound/jack.h>
28#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/soc.h>
31#include "rockchip_i2s.h"
32#include "../codecs/da7219.h"
33#include "../codecs/da7219-aad.h"
34#include "../codecs/rt5514.h"
35
36#define DRV_NAME "rk3399-gru-sound"
37
38#define SOUND_FS 256
39
40static struct snd_soc_jack rockchip_sound_jack;
41
42static const struct snd_soc_dapm_widget rockchip_dapm_widgets[] = {
43 SND_SOC_DAPM_HP("Headphones", NULL),
44 SND_SOC_DAPM_SPK("Speakers", NULL),
45 SND_SOC_DAPM_MIC("Headset Mic", NULL),
46 SND_SOC_DAPM_MIC("Int Mic", NULL),
47};
48
49static const struct snd_soc_dapm_route rockchip_dapm_routes[] = {
50 /* Input Lines */
51 {"MIC", NULL, "Headset Mic"},
52 {"DMIC1L", NULL, "Int Mic"},
53 {"DMIC1R", NULL, "Int Mic"},
54
55 /* Output Lines */
56 {"Headphones", NULL, "HPL"},
57 {"Headphones", NULL, "HPR"},
58 {"Speakers", NULL, "Speaker"},
59};
60
61static const struct snd_kcontrol_new rockchip_controls[] = {
62 SOC_DAPM_PIN_SWITCH("Headphones"),
63 SOC_DAPM_PIN_SWITCH("Speakers"),
64 SOC_DAPM_PIN_SWITCH("Headset Mic"),
65 SOC_DAPM_PIN_SWITCH("Int Mic"),
66};
67
68static int rockchip_sound_max98357a_hw_params(struct snd_pcm_substream *substream,
69 struct snd_pcm_hw_params *params)
70{
71 struct snd_soc_pcm_runtime *rtd = substream->private_data;
72 unsigned int mclk;
73 int ret;
74
75 /* max98357a supports these sample rates */
76 switch (params_rate(params)) {
77 case 8000:
78 case 16000:
79 case 48000:
80 case 96000:
81 mclk = params_rate(params) * SOUND_FS;
82 break;
83 default:
84 dev_err(rtd->card->dev, "%s() doesn't support this sample rate: %d\n",
85 __func__, params_rate(params));
86 return -EINVAL;
87 }
88
89 ret = snd_soc_dai_set_sysclk(rtd->cpu_dai, 0, mclk, 0);
90 if (ret) {
91 dev_err(rtd->card->dev, "%s() error setting sysclk to %u: %d\n",
92 __func__, mclk, ret);
93 return ret;
94 }
95
96 return 0;
97}
98
99static int rockchip_sound_rt5514_hw_params(struct snd_pcm_substream *substream,
100 struct snd_pcm_hw_params *params)
101{
102 struct snd_soc_pcm_runtime *rtd = substream->private_data;
103 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
104 struct snd_soc_dai *codec_dai = rtd->codec_dai;
105 unsigned int mclk;
106 int ret;
107
108 mclk = params_rate(params) * SOUND_FS;
109
110 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
111 SND_SOC_CLOCK_OUT);
112 if (ret < 0) {
113 dev_err(rtd->card->dev, "Can't set cpu clock out %d\n", ret);
114 return ret;
115 }
116
117 ret = snd_soc_dai_set_sysclk(codec_dai, RT5514_SCLK_S_MCLK,
118 mclk, SND_SOC_CLOCK_IN);
119 if (ret) {
120 dev_err(rtd->card->dev, "%s() error setting sysclk to %u: %d\n",
121 __func__, params_rate(params) * 512, ret);
122 return ret;
123 }
124
125 return 0;
126}
127
128static int rockchip_sound_da7219_hw_params(struct snd_pcm_substream *substream,
129 struct snd_pcm_hw_params *params)
130{
131 struct snd_soc_pcm_runtime *rtd = substream->private_data;
132 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
133 struct snd_soc_dai *codec_dai = rtd->codec_dai;
134 int mclk, ret;
135
136 /* in bypass mode, the mclk has to be one of the frequencies below */
137 switch (params_rate(params)) {
138 case 8000:
139 case 16000:
140 case 24000:
141 case 32000:
142 case 48000:
143 case 64000:
144 case 96000:
145 mclk = 12288000;
146 break;
147 case 11025:
148 case 22050:
149 case 44100:
150 case 88200:
151 mclk = 11289600;
152 break;
153 default:
154 return -EINVAL;
155 }
156
157 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
158 SND_SOC_CLOCK_OUT);
159 if (ret < 0) {
160 dev_err(codec_dai->dev, "Can't set cpu clock out %d\n", ret);
161 return ret;
162 }
163
164 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
165 SND_SOC_CLOCK_IN);
166 if (ret < 0) {
167 dev_err(codec_dai->dev, "Can't set codec clock in %d\n", ret);
168 return ret;
169 }
170
171 ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_MCLK, 0, 0);
172 if (ret < 0) {
173 dev_err(codec_dai->dev, "Can't set pll sysclk mclk %d\n", ret);
174 return ret;
175 }
176
177 return 0;
178}
179
180static int rockchip_sound_da7219_init(struct snd_soc_pcm_runtime *rtd)
181{
182 struct snd_soc_codec *codec = rtd->codec_dais[0]->codec;
183 struct snd_soc_dai *codec_dai = rtd->codec_dai;
184 int ret;
185
186 /* We need default MCLK and PLL settings for the accessory detection */
187 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 12288000,
188 SND_SOC_CLOCK_IN);
189 if (ret < 0) {
190 dev_err(codec_dai->dev, "Init can't set codec clock in %d\n", ret);
191 return ret;
192 }
193
194 ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_MCLK, 0, 0);
195 if (ret < 0) {
196 dev_err(codec_dai->dev, "Init can't set pll sysclk mclk %d\n", ret);
197 return ret;
198 }
199
200 /* Enable Headset and 4 Buttons Jack detection */
201 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
202 SND_JACK_HEADSET | SND_JACK_LINEOUT |
203 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
204 SND_JACK_BTN_2 | SND_JACK_BTN_3,
205 &rockchip_sound_jack, NULL, 0);
206
207 if (ret) {
208 dev_err(rtd->card->dev, "New Headset Jack failed! (%d)\n", ret);
209 return ret;
210 }
211
212 da7219_aad_jack_det(codec, &rockchip_sound_jack);
213
214 return 0;
215}
216
217static struct snd_soc_ops rockchip_sound_max98357a_ops = {
218 .hw_params = rockchip_sound_max98357a_hw_params,
219};
220
221static struct snd_soc_ops rockchip_sound_rt5514_ops = {
222 .hw_params = rockchip_sound_rt5514_hw_params,
223};
224
225static struct snd_soc_ops rockchip_sound_da7219_ops = {
226 .hw_params = rockchip_sound_da7219_hw_params,
227};
228
229enum {
230 DAILINK_MAX98357A,
231 DAILINK_RT5514,
232 DAILINK_DA7219,
233};
234
235static struct snd_soc_dai_link rockchip_dailinks[] = {
236 [DAILINK_MAX98357A] = {
237 .name = "MAX98357A",
238 .stream_name = "MAX98357A PCM",
239 .codec_dai_name = "HiFi",
240 .ops = &rockchip_sound_max98357a_ops,
241 /* set max98357a as slave */
242 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
243 SND_SOC_DAIFMT_CBS_CFS,
244 },
245 [DAILINK_RT5514] = {
246 .name = "RT5514",
247 .stream_name = "RT5514 PCM",
248 .codec_dai_name = "rt5514-aif1",
249 .ops = &rockchip_sound_rt5514_ops,
250 /* set rt5514 as slave */
251 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
252 SND_SOC_DAIFMT_CBS_CFS,
253 },
254 [DAILINK_DA7219] = {
255 .name = "DA7219",
256 .stream_name = "DA7219 PCM",
257 .codec_dai_name = "da7219-hifi",
258 .init = rockchip_sound_da7219_init,
259 .ops = &rockchip_sound_da7219_ops,
260 /* set da7219 as slave */
261 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
262 SND_SOC_DAIFMT_CBS_CFS,
263 },
264};
265
266static struct snd_soc_card rockchip_sound_card = {
267 .name = "rk3399-gru-sound",
268 .owner = THIS_MODULE,
269 .dai_link = rockchip_dailinks,
270 .num_links = ARRAY_SIZE(rockchip_dailinks),
271 .dapm_widgets = rockchip_dapm_widgets,
272 .num_dapm_widgets = ARRAY_SIZE(rockchip_dapm_widgets),
273 .dapm_routes = rockchip_dapm_routes,
274 .num_dapm_routes = ARRAY_SIZE(rockchip_dapm_routes),
275 .controls = rockchip_controls,
276 .num_controls = ARRAY_SIZE(rockchip_controls),
277};
278
279static int rockchip_sound_probe(struct platform_device *pdev)
280{
281 struct snd_soc_card *card = &rockchip_sound_card;
282 struct device_node *cpu_node;
283 int i, ret;
284
285 cpu_node = of_parse_phandle(pdev->dev.of_node, "rockchip,cpu", 0);
286 if (!cpu_node) {
287 dev_err(&pdev->dev, "Property 'rockchip,cpu' missing or invalid\n");
288 return -EINVAL;
289 }
290
291 for (i = 0; i < card->num_links; i++) {
292 rockchip_dailinks[i].platform_of_node = cpu_node;
293 rockchip_dailinks[i].cpu_of_node = cpu_node;
294
295 rockchip_dailinks[i].codec_of_node =
296 of_parse_phandle(pdev->dev.of_node, "rockchip,codec", i);
297 if (!rockchip_dailinks[i].codec_of_node) {
298 dev_err(&pdev->dev,
299 "Property[%d] 'rockchip,codec' missing or invalid\n", i);
300 return -EINVAL;
301 }
302 }
303
304 card->dev = &pdev->dev;
305 platform_set_drvdata(pdev, card);
306
307 ret = devm_snd_soc_register_card(&pdev->dev, card);
308 if (ret)
309 dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n",
310 __func__, ret);
311
312 return ret;
313}
314
315static const struct of_device_id rockchip_sound_of_match[] = {
316 { .compatible = "rockchip,rk3399-gru-sound", },
317 {},
318};
319
320static struct platform_driver rockchip_sound_driver = {
321 .probe = rockchip_sound_probe,
322 .driver = {
323 .name = DRV_NAME,
324 .of_match_table = rockchip_sound_of_match,
325#ifdef CONFIG_PM
326 .pm = &snd_soc_pm_ops,
327#endif
328 },
329};
330
331module_platform_driver(rockchip_sound_driver);
332
333MODULE_AUTHOR("Xing Zheng <zhengxing@rock-chips.com>");
334MODULE_DESCRIPTION("Rockchip ASoC Machine Driver");
335MODULE_LICENSE("GPL v2");
336MODULE_ALIAS("platform:" DRV_NAME);
337MODULE_DEVICE_TABLE(of, rockchip_sound_of_match);