aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhengxing <zhengxing@rock-chips.com>2015-07-19 07:33:48 -0400
committerMark Brown <broonie@kernel.org>2015-07-20 13:15:07 -0400
commit49bdb0440541ad1144ad08d5613f9a28bcd2a8dc (patch)
tree867751ced03f3b0a0d1e00e2a77eaedd9cda4c66
parentbc0195aad0daa2ad5b0d76cce22b167bc3435590 (diff)
ASoC: rockchip: Add machine driver for max98090 codec
The driver is used for rockchip board using a max98090. Reviewed-by: Dylan Reid <dgreid@chromium.org> Signed-off-by: zhengxing <zhengxing@rock-chips.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--Documentation/devicetree/bindings/sound/rockchip-max98090.txt19
-rw-r--r--sound/soc/rockchip/Kconfig10
-rw-r--r--sound/soc/rockchip/Makefile4
-rw-r--r--sound/soc/rockchip/rockchip_max98090.c236
4 files changed, 269 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/sound/rockchip-max98090.txt b/Documentation/devicetree/bindings/sound/rockchip-max98090.txt
new file mode 100644
index 000000000000..a805aa99ad75
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/rockchip-max98090.txt
@@ -0,0 +1,19 @@
1ROCKCHIP with MAX98090 CODEC
2
3Required properties:
4- compatible: "rockchip,rockchip-audio-max98090"
5- rockchip,model: The user-visible name of this sound complex
6- rockchip,i2s-controller: The phandle of the Rockchip I2S controller that's
7 connected to the CODEC
8- rockchip,audio-codec: The phandle of the MAX98090 audio codec
9- rockchip,headset-codec: The phandle of Ext chip for jack detection
10
11Example:
12
13sound {
14 compatible = "rockchip,rockchip-audio-max98090";
15 rockchip,model = "ROCKCHIP-I2S";
16 rockchip,i2s-controller = <&i2s>;
17 rockchip,audio-codec = <&max98090>;
18 rockchip,headset-codec = <&headsetcodec>;
19};
diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig
index e18182699d83..d12356617fc7 100644
--- a/sound/soc/rockchip/Kconfig
+++ b/sound/soc/rockchip/Kconfig
@@ -14,3 +14,13 @@ config SND_SOC_ROCKCHIP_I2S
14 Say Y or M if you want to add support for I2S driver for 14 Say Y or M if you want to add support for I2S driver for
15 Rockchip I2S device. The device supports upto maximum of 15 Rockchip I2S device. The device supports upto maximum of
16 8 channels each for play and record. 16 8 channels each for play and record.
17
18config SND_SOC_ROCKCHIP_MAX98090
19 tristate "ASoC support for Rockchip boards using a MAX98090 codec"
20 depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB
21 select SND_SOC_ROCKCHIP_I2S
22 select SND_SOC_MAX98090
23 select SND_SOC_TS3A227E
24 help
25 Say Y or M here if you want to add support for SoC audio on Rockchip
26 boards using the MAX98090 codec, such as Veyron.
diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile
index b9219092b47f..df3445b53806 100644
--- a/sound/soc/rockchip/Makefile
+++ b/sound/soc/rockchip/Makefile
@@ -2,3 +2,7 @@
2snd-soc-i2s-objs := rockchip_i2s.o 2snd-soc-i2s-objs := rockchip_i2s.o
3 3
4obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-i2s.o 4obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-i2s.o
5
6snd-soc-rockchip-max98090-objs := rockchip_max98090.o
7
8obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o
diff --git a/sound/soc/rockchip/rockchip_max98090.c b/sound/soc/rockchip/rockchip_max98090.c
new file mode 100644
index 000000000000..acace20d4127
--- /dev/null
+++ b/sound/soc/rockchip/rockchip_max98090.c
@@ -0,0 +1,236 @@
1/*
2 * Rockchip machine ASoC driver for boards using a MAX90809 CODEC.
3 *
4 * Copyright (c) 2014, 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
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/slab.h>
23#include <linux/gpio.h>
24#include <linux/of_gpio.h>
25#include <sound/core.h>
26#include <sound/jack.h>
27#include <sound/pcm.h>
28#include <sound/pcm_params.h>
29#include <sound/soc.h>
30
31#include "rockchip_i2s.h"
32#include "../codecs/ts3a227e.h"
33
34#define DRV_NAME "rockchip-snd-max98090"
35
36static struct snd_soc_jack headset_jack;
37static struct snd_soc_jack_pin headset_jack_pins[] = {
38 {
39 .pin = "Headset Jack",
40 .mask = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
41 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
42 SND_JACK_BTN_2 | SND_JACK_BTN_3,
43 },
44};
45
46static const struct snd_soc_dapm_widget rk_dapm_widgets[] = {
47 SND_SOC_DAPM_HP("Headphone", NULL),
48 SND_SOC_DAPM_MIC("Headset Mic", NULL),
49 SND_SOC_DAPM_MIC("Int Mic", NULL),
50 SND_SOC_DAPM_SPK("Speaker", NULL),
51};
52
53static const struct snd_soc_dapm_route rk_audio_map[] = {
54 {"IN34", NULL, "Headset Mic"},
55 {"IN34", NULL, "MICBIAS"},
56 {"MICBIAS", NULL, "Headset Mic"},
57 {"DMICL", NULL, "Int Mic"},
58 {"Headphone", NULL, "HPL"},
59 {"Headphone", NULL, "HPR"},
60 {"Speaker", NULL, "SPKL"},
61 {"Speaker", NULL, "SPKR"},
62};
63
64static const struct snd_kcontrol_new rk_mc_controls[] = {
65 SOC_DAPM_PIN_SWITCH("Headphone"),
66 SOC_DAPM_PIN_SWITCH("Headset Mic"),
67 SOC_DAPM_PIN_SWITCH("Int Mic"),
68 SOC_DAPM_PIN_SWITCH("Speaker"),
69};
70
71static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
72 struct snd_pcm_hw_params *params)
73{
74 int ret = 0;
75 struct snd_soc_pcm_runtime *rtd = substream->private_data;
76 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
77 struct snd_soc_dai *codec_dai = rtd->codec_dai;
78 int mclk;
79
80 switch (params_rate(params)) {
81 case 8000:
82 case 16000:
83 case 48000:
84 case 96000:
85 mclk = 12288000;
86 break;
87 case 44100:
88 mclk = 11289600;
89 break;
90 default:
91 return -EINVAL;
92 }
93
94 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
95 SND_SOC_CLOCK_OUT);
96 if (ret < 0) {
97 dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret);
98 return ret;
99 }
100
101 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
102 SND_SOC_CLOCK_IN);
103 if (ret < 0) {
104 dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret);
105 return ret;
106 }
107
108 return ret;
109}
110
111static int rk_init(struct snd_soc_pcm_runtime *runtime)
112{
113 /* Enable Headset and 4 Buttons Jack detection */
114 return snd_soc_card_jack_new(runtime->card, "Headset Jack",
115 SND_JACK_HEADSET |
116 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
117 SND_JACK_BTN_2 | SND_JACK_BTN_3,
118 &headset_jack,
119 headset_jack_pins,
120 ARRAY_SIZE(headset_jack_pins));
121}
122
123static int rk_98090_headset_init(struct snd_soc_component *component)
124{
125 return ts3a227e_enable_jack_detect(component, &headset_jack);
126}
127
128static struct snd_soc_ops rk_aif1_ops = {
129 .hw_params = rk_aif1_hw_params,
130};
131
132static struct snd_soc_aux_dev rk_98090_headset_dev = {
133 .name = "Headset Chip",
134 .init = rk_98090_headset_init,
135};
136
137static struct snd_soc_dai_link rk_dailink = {
138 .name = "max98090",
139 .stream_name = "Audio",
140 .codec_dai_name = "HiFi",
141 .init = rk_init,
142 .ops = &rk_aif1_ops,
143 /* set max98090 as slave */
144 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
145 SND_SOC_DAIFMT_CBS_CFS,
146};
147
148static struct snd_soc_card snd_soc_card_rk = {
149 .name = "ROCKCHIP-I2S",
150 .dai_link = &rk_dailink,
151 .num_links = 1,
152 .aux_dev = &rk_98090_headset_dev,
153 .num_aux_devs = 1,
154 .dapm_widgets = rk_dapm_widgets,
155 .num_dapm_widgets = ARRAY_SIZE(rk_dapm_widgets),
156 .dapm_routes = rk_audio_map,
157 .num_dapm_routes = ARRAY_SIZE(rk_audio_map),
158 .controls = rk_mc_controls,
159 .num_controls = ARRAY_SIZE(rk_mc_controls),
160};
161
162static int snd_rk_mc_probe(struct platform_device *pdev)
163{
164 int ret = 0;
165 struct snd_soc_card *card = &snd_soc_card_rk;
166 struct device_node *np = pdev->dev.of_node;
167
168 /* register the soc card */
169 card->dev = &pdev->dev;
170
171 rk_dailink.codec_of_node = of_parse_phandle(np,
172 "rockchip,audio-codec", 0);
173 if (!rk_dailink.codec_of_node) {
174 dev_err(&pdev->dev,
175 "Property 'rockchip,audio-codec' missing or invalid\n");
176 return -EINVAL;
177 }
178
179 rk_dailink.cpu_of_node = of_parse_phandle(np,
180 "rockchip,i2s-controller", 0);
181 if (!rk_dailink.cpu_of_node) {
182 dev_err(&pdev->dev,
183 "Property 'rockchip,i2s-controller' missing or invalid\n");
184 return -EINVAL;
185 }
186
187 rk_dailink.platform_of_node = rk_dailink.cpu_of_node;
188
189 rk_98090_headset_dev.codec_of_node = of_parse_phandle(np,
190 "rockchip,headset-codec", 0);
191 if (!rk_98090_headset_dev.codec_of_node) {
192 dev_err(&pdev->dev,
193 "Property 'rockchip,headset-codec' missing/invalid\n");
194 return -EINVAL;
195 }
196
197 ret = snd_soc_of_parse_card_name(card, "rockchip,model");
198 if (ret) {
199 dev_err(&pdev->dev,
200 "Soc parse card name failed %d\n", ret);
201 return ret;
202 }
203
204 ret = devm_snd_soc_register_card(&pdev->dev, card);
205 if (ret) {
206 dev_err(&pdev->dev,
207 "Soc register card failed %d\n", ret);
208 return ret;
209 }
210
211 return ret;
212}
213
214static const struct of_device_id rockchip_max98090_of_match[] = {
215 { .compatible = "rockchip,rockchip-audio-max98090", },
216 {},
217};
218
219MODULE_DEVICE_TABLE(of, rockchip_max98090_of_match);
220
221static struct platform_driver snd_rk_mc_driver = {
222 .probe = snd_rk_mc_probe,
223 .driver = {
224 .name = DRV_NAME,
225 .owner = THIS_MODULE,
226 .pm = &snd_soc_pm_ops,
227 .of_match_table = rockchip_max98090_of_match,
228 },
229};
230
231module_platform_driver(snd_rk_mc_driver);
232
233MODULE_AUTHOR("jianqun <jay.xu@rock-chips.com>");
234MODULE_DESCRIPTION("Rockchip max98090 machine ASoC driver");
235MODULE_LICENSE("GPL v2");
236MODULE_ALIAS("platform:" DRV_NAME);