aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/sound/mt8173-rt5650.txt15
-rw-r--r--sound/soc/mediatek/Kconfig10
-rw-r--r--sound/soc/mediatek/Makefile1
-rw-r--r--sound/soc/mediatek/mt8173-rt5650.c236
4 files changed, 262 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/sound/mt8173-rt5650.txt b/Documentation/devicetree/bindings/sound/mt8173-rt5650.txt
new file mode 100644
index 000000000000..fe5a5ef1714d
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/mt8173-rt5650.txt
@@ -0,0 +1,15 @@
1MT8173 with RT5650 CODECS
2
3Required properties:
4- compatible : "mediatek,mt8173-rt5650"
5- mediatek,audio-codec: the phandles of rt5650 codecs
6- mediatek,platform: the phandle of MT8173 ASoC platform
7
8Example:
9
10 sound {
11 compatible = "mediatek,mt8173-rt5650";
12 mediatek,audio-codec = <&rt5650>;
13 mediatek,platform = <&afe>;
14 };
15
diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 976967675387..6c8808798c6b 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -17,6 +17,16 @@ config SND_SOC_MT8173_MAX98090
17 Select Y if you have such device. 17 Select Y if you have such device.
18 If unsure select "N". 18 If unsure select "N".
19 19
20config SND_SOC_MT8173_RT5650
21 tristate "ASoC Audio driver for MT8173 with RT5650 codec"
22 depends on SND_SOC_MEDIATEK && I2C
23 select SND_SOC_RT5645
24 help
25 This adds ASoC driver for Mediatek MT8173 boards
26 with the RT5650 audio codec.
27 Select Y if you have such device.
28 If unsure select "N".
29
20config SND_SOC_MT8173_RT5650_RT5676 30config SND_SOC_MT8173_RT5650_RT5676
21 tristate "ASoC Audio driver for MT8173 with RT5650 RT5676 codecs" 31 tristate "ASoC Audio driver for MT8173 with RT5650 RT5676 codecs"
22 depends on SND_SOC_MEDIATEK && I2C 32 depends on SND_SOC_MEDIATEK && I2C
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile
index 75effbec438d..bcdcb062e73a 100644
--- a/sound/soc/mediatek/Makefile
+++ b/sound/soc/mediatek/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_SND_SOC_MEDIATEK) += mtk-afe-pcm.o
3# Machine support 3# Machine support
4obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o 4obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o
5obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o 5obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o
6obj-$(CONFIG_SND_SOC_MT8173_RT5650) += mt8173-rt5650.o
diff --git a/sound/soc/mediatek/mt8173-rt5650.c b/sound/soc/mediatek/mt8173-rt5650.c
new file mode 100644
index 000000000000..bb09bb1b7f1c
--- /dev/null
+++ b/sound/soc/mediatek/mt8173-rt5650.c
@@ -0,0 +1,236 @@
1/*
2 * mt8173-rt5650.c -- MT8173 machine driver with RT5650 codecs
3 *
4 * Copyright (c) 2016 MediaTek Inc.
5 * Author: Koro Chen <koro.chen@mediatek.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 and
9 * only version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/module.h>
18#include <linux/gpio.h>
19#include <linux/of_gpio.h>
20#include <sound/soc.h>
21#include <sound/jack.h>
22#include "../codecs/rt5645.h"
23
24#define MCLK_FOR_CODECS 12288000
25
26static const struct snd_soc_dapm_widget mt8173_rt5650_widgets[] = {
27 SND_SOC_DAPM_SPK("Speaker", NULL),
28 SND_SOC_DAPM_MIC("Int Mic", NULL),
29 SND_SOC_DAPM_HP("Headphone", NULL),
30 SND_SOC_DAPM_MIC("Headset Mic", NULL),
31};
32
33static const struct snd_soc_dapm_route mt8173_rt5650_routes[] = {
34 {"Speaker", NULL, "SPOL"},
35 {"Speaker", NULL, "SPOR"},
36 {"DMIC L1", NULL, "Int Mic"},
37 {"DMIC R1", NULL, "Int Mic"},
38 {"Headphone", NULL, "HPOL"},
39 {"Headphone", NULL, "HPOR"},
40 {"Headset Mic", NULL, "micbias1"},
41 {"Headset Mic", NULL, "micbias2"},
42 {"IN1P", NULL, "Headset Mic"},
43 {"IN1N", NULL, "Headset Mic"},
44};
45
46static const struct snd_kcontrol_new mt8173_rt5650_controls[] = {
47 SOC_DAPM_PIN_SWITCH("Speaker"),
48 SOC_DAPM_PIN_SWITCH("Int Mic"),
49 SOC_DAPM_PIN_SWITCH("Headphone"),
50 SOC_DAPM_PIN_SWITCH("Headset Mic"),
51};
52
53static int mt8173_rt5650_hw_params(struct snd_pcm_substream *substream,
54 struct snd_pcm_hw_params *params)
55{
56 struct snd_soc_pcm_runtime *rtd = substream->private_data;
57 int i, ret;
58
59 for (i = 0; i < rtd->num_codecs; i++) {
60 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
61
62 /* pll from mclk 12.288M */
63 ret = snd_soc_dai_set_pll(codec_dai, 0, 0, MCLK_FOR_CODECS,
64 params_rate(params) * 512);
65 if (ret)
66 return ret;
67
68 /* sysclk from pll */
69 ret = snd_soc_dai_set_sysclk(codec_dai, 1,
70 params_rate(params) * 512,
71 SND_SOC_CLOCK_IN);
72 if (ret)
73 return ret;
74 }
75 return 0;
76}
77
78static struct snd_soc_ops mt8173_rt5650_ops = {
79 .hw_params = mt8173_rt5650_hw_params,
80};
81
82static struct snd_soc_jack mt8173_rt5650_jack;
83
84static int mt8173_rt5650_init(struct snd_soc_pcm_runtime *runtime)
85{
86 struct snd_soc_card *card = runtime->card;
87 struct snd_soc_codec *codec = runtime->codec_dais[0]->codec;
88 int ret;
89
90 rt5645_sel_asrc_clk_src(codec,
91 RT5645_DA_STEREO_FILTER |
92 RT5645_AD_STEREO_FILTER,
93 RT5645_CLK_SEL_I2S1_ASRC);
94 /* enable jack detection */
95 ret = snd_soc_card_jack_new(card, "Headset Jack",
96 SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
97 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
98 SND_JACK_BTN_2 | SND_JACK_BTN_3,
99 &mt8173_rt5650_jack, NULL, 0);
100 if (ret) {
101 dev_err(card->dev, "Can't new Headset Jack %d\n", ret);
102 return ret;
103 }
104
105 return rt5645_set_jack_detect(codec,
106 &mt8173_rt5650_jack,
107 &mt8173_rt5650_jack,
108 &mt8173_rt5650_jack);
109}
110
111static struct snd_soc_dai_link_component mt8173_rt5650_codecs[] = {
112 {
113 .dai_name = "rt5645-aif1",
114 },
115};
116
117enum {
118 DAI_LINK_PLAYBACK,
119 DAI_LINK_CAPTURE,
120 DAI_LINK_CODEC_I2S,
121};
122
123/* Digital audio interface glue - connects codec <---> CPU */
124static struct snd_soc_dai_link mt8173_rt5650_dais[] = {
125 /* Front End DAI links */
126 [DAI_LINK_PLAYBACK] = {
127 .name = "rt5650 Playback",
128 .stream_name = "rt5650 Playback",
129 .cpu_dai_name = "DL1",
130 .codec_name = "snd-soc-dummy",
131 .codec_dai_name = "snd-soc-dummy-dai",
132 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
133 .dynamic = 1,
134 .dpcm_playback = 1,
135 },
136 [DAI_LINK_CAPTURE] = {
137 .name = "rt5650 Capture",
138 .stream_name = "rt5650 Capture",
139 .cpu_dai_name = "VUL",
140 .codec_name = "snd-soc-dummy",
141 .codec_dai_name = "snd-soc-dummy-dai",
142 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
143 .dynamic = 1,
144 .dpcm_capture = 1,
145 },
146 /* Back End DAI links */
147 [DAI_LINK_CODEC_I2S] = {
148 .name = "Codec",
149 .cpu_dai_name = "I2S",
150 .no_pcm = 1,
151 .codecs = mt8173_rt5650_codecs,
152 .num_codecs = 1,
153 .init = mt8173_rt5650_init,
154 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
155 SND_SOC_DAIFMT_CBS_CFS,
156 .ops = &mt8173_rt5650_ops,
157 .ignore_pmdown_time = 1,
158 .dpcm_playback = 1,
159 .dpcm_capture = 1,
160 },
161};
162
163static struct snd_soc_card mt8173_rt5650_card = {
164 .name = "mtk-rt5650",
165 .owner = THIS_MODULE,
166 .dai_link = mt8173_rt5650_dais,
167 .num_links = ARRAY_SIZE(mt8173_rt5650_dais),
168 .controls = mt8173_rt5650_controls,
169 .num_controls = ARRAY_SIZE(mt8173_rt5650_controls),
170 .dapm_widgets = mt8173_rt5650_widgets,
171 .num_dapm_widgets = ARRAY_SIZE(mt8173_rt5650_widgets),
172 .dapm_routes = mt8173_rt5650_routes,
173 .num_dapm_routes = ARRAY_SIZE(mt8173_rt5650_routes),
174};
175
176static int mt8173_rt5650_dev_probe(struct platform_device *pdev)
177{
178 struct snd_soc_card *card = &mt8173_rt5650_card;
179 struct device_node *platform_node;
180 int i, ret;
181
182 platform_node = of_parse_phandle(pdev->dev.of_node,
183 "mediatek,platform", 0);
184 if (!platform_node) {
185 dev_err(&pdev->dev, "Property 'platform' missing or invalid\n");
186 return -EINVAL;
187 }
188
189 for (i = 0; i < card->num_links; i++) {
190 if (mt8173_rt5650_dais[i].platform_name)
191 continue;
192 mt8173_rt5650_dais[i].platform_of_node = platform_node;
193 }
194
195 mt8173_rt5650_codecs[0].of_node =
196 of_parse_phandle(pdev->dev.of_node, "mediatek,audio-codec", 0);
197 if (!mt8173_rt5650_codecs[0].of_node) {
198 dev_err(&pdev->dev,
199 "Property 'audio-codec' missing or invalid\n");
200 return -EINVAL;
201 }
202 card->dev = &pdev->dev;
203 platform_set_drvdata(pdev, card);
204
205 ret = devm_snd_soc_register_card(&pdev->dev, card);
206 if (ret)
207 dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n",
208 __func__, ret);
209 return ret;
210}
211
212static const struct of_device_id mt8173_rt5650_dt_match[] = {
213 { .compatible = "mediatek,mt8173-rt5650", },
214 { }
215};
216MODULE_DEVICE_TABLE(of, mt8173_rt5650_dt_match);
217
218static struct platform_driver mt8173_rt5650_driver = {
219 .driver = {
220 .name = "mtk-rt5650",
221 .of_match_table = mt8173_rt5650_dt_match,
222#ifdef CONFIG_PM
223 .pm = &snd_soc_pm_ops,
224#endif
225 },
226 .probe = mt8173_rt5650_dev_probe,
227};
228
229module_platform_driver(mt8173_rt5650_driver);
230
231/* Module information */
232MODULE_DESCRIPTION("MT8173 RT5650 SoC machine driver");
233MODULE_AUTHOR("Koro Chen <koro.chen@mediatek.com>");
234MODULE_LICENSE("GPL v2");
235MODULE_ALIAS("platform:mtk-rt5650");
236