]> Git Repo - linux.git/blame - sound/soc/omap/omap-abe-twl6040.c
Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux.git] / sound / soc / omap / omap-abe-twl6040.c
CommitLineData
5e64d6aa 1/*
13f81d65
PU
2 * omap-abe-twl6040.c -- SoC audio for TI OMAP based boards with ABE and
3 * twl6040 codec
5e64d6aa 4 *
8747a6b7 5 * Author: Misael Lopez Cruz <[email protected]>
5e64d6aa
MLC
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include <linux/clk.h>
24#include <linux/platform_device.h>
fb34d3d5 25#include <linux/mfd/twl6040.h>
da155d5b 26#include <linux/module.h>
5ef75e71 27#include <linux/of.h>
fb34d3d5 28
5e64d6aa
MLC
29#include <sound/core.h>
30#include <sound/pcm.h>
31#include <sound/soc.h>
96dc227c 32#include <sound/jack.h>
5e64d6aa 33
6524c8e3 34#include "omap-dmic.h"
f5f9d7bf 35#include "omap-mcpdm.h"
5e64d6aa
MLC
36#include "../codecs/twl6040.h"
37
356bccbe 38struct abe_twl6040 {
76836fd3
PU
39 struct snd_soc_card card;
40 struct snd_soc_dai_link dai_links[2];
356bccbe
PU
41 int jack_detection; /* board can detect jack events */
42 int mclk_freq; /* MCLK frequency speed for twl6040 */
43};
44
510e419c 45static struct platform_device *dmic_codec_dev;
21eb45db 46
13f81d65 47static int omap_abe_hw_params(struct snd_pcm_substream *substream,
5e64d6aa
MLC
48 struct snd_pcm_hw_params *params)
49{
50 struct snd_soc_pcm_runtime *rtd = substream->private_data;
f0fba2ad 51 struct snd_soc_dai *codec_dai = rtd->codec_dai;
0596f700 52 struct snd_soc_card *card = rtd->card;
356bccbe 53 struct abe_twl6040 *priv = snd_soc_card_get_drvdata(card);
5e64d6aa
MLC
54 int clk_id, freq;
55 int ret;
56
7480389f 57 clk_id = twl6040_get_clk_id(codec_dai->component);
af958c72 58 if (clk_id == TWL6040_SYSCLK_SEL_HPPLL)
356bccbe 59 freq = priv->mclk_freq;
af958c72 60 else if (clk_id == TWL6040_SYSCLK_SEL_LPPLL)
5e64d6aa 61 freq = 32768;
af958c72
PU
62 else
63 return -EINVAL;
5e64d6aa
MLC
64
65 /* set the codec mclk */
66 ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq,
67 SND_SOC_CLOCK_IN);
68 if (ret) {
69 printk(KERN_ERR "can't set codec system clock\n");
70 return ret;
71 }
f0fba2ad 72 return ret;
5e64d6aa
MLC
73}
74
2261cf1c 75static const struct snd_soc_ops omap_abe_ops = {
13f81d65 76 .hw_params = omap_abe_hw_params,
5e64d6aa
MLC
77};
78
13f81d65 79static int omap_abe_dmic_hw_params(struct snd_pcm_substream *substream,
6524c8e3
PU
80 struct snd_pcm_hw_params *params)
81{
82 struct snd_soc_pcm_runtime *rtd = substream->private_data;
83 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
84 int ret = 0;
85
86 ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_DMIC_SYSCLK_PAD_CLKS,
87 19200000, SND_SOC_CLOCK_IN);
88 if (ret < 0) {
89 printk(KERN_ERR "can't set DMIC cpu system clock\n");
90 return ret;
91 }
92 ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_DMIC_ABE_DMIC_CLK, 2400000,
93 SND_SOC_CLOCK_OUT);
94 if (ret < 0) {
95 printk(KERN_ERR "can't set DMIC output clock\n");
96 return ret;
97 }
98 return 0;
99}
100
13f81d65
PU
101static struct snd_soc_ops omap_abe_dmic_ops = {
102 .hw_params = omap_abe_dmic_hw_params,
6524c8e3
PU
103};
104
96dc227c
JEC
105/* Headset jack */
106static struct snd_soc_jack hs_jack;
107
108/*Headset jack detection DAPM pins */
109static struct snd_soc_jack_pin hs_jack_pins[] = {
110 {
111 .pin = "Headset Mic",
112 .mask = SND_JACK_MICROPHONE,
113 },
114 {
115 .pin = "Headset Stereophone",
116 .mask = SND_JACK_HEADPHONE,
117 },
118};
119
5e64d6aa 120/* SDP4430 machine DAPM */
13f81d65 121static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
b3208839 122 /* Outputs */
5e64d6aa 123 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
7254e2bd 124 SND_SOC_DAPM_SPK("Earphone Spk", NULL),
b3208839
PU
125 SND_SOC_DAPM_SPK("Ext Spk", NULL),
126 SND_SOC_DAPM_LINE("Line Out", NULL),
127 SND_SOC_DAPM_SPK("Vibrator", NULL),
128
129 /* Inputs */
130 SND_SOC_DAPM_MIC("Headset Mic", NULL),
131 SND_SOC_DAPM_MIC("Main Handset Mic", NULL),
132 SND_SOC_DAPM_MIC("Sub Handset Mic", NULL),
133 SND_SOC_DAPM_LINE("Line In", NULL),
7d09f9e9
PU
134
135 /* Digital microphones */
136 SND_SOC_DAPM_MIC("Digital Mic", NULL),
5e64d6aa
MLC
137};
138
139static const struct snd_soc_dapm_route audio_map[] = {
b3208839
PU
140 /* Routings for outputs */
141 {"Headset Stereophone", NULL, "HSOL"},
142 {"Headset Stereophone", NULL, "HSOR"},
143
144 {"Earphone Spk", NULL, "EP"},
5e64d6aa 145
5e64d6aa
MLC
146 {"Ext Spk", NULL, "HFL"},
147 {"Ext Spk", NULL, "HFR"},
148
b3208839
PU
149 {"Line Out", NULL, "AUXL"},
150 {"Line Out", NULL, "AUXR"},
151
152 {"Vibrator", NULL, "VIBRAL"},
153 {"Vibrator", NULL, "VIBRAR"},
154
155 /* Routings for inputs */
778cee7a
PU
156 {"HSMIC", NULL, "Headset Mic"},
157 {"Headset Mic", NULL, "Headset Mic Bias"},
5e64d6aa 158
b3208839
PU
159 {"MAINMIC", NULL, "Main Handset Mic"},
160 {"Main Handset Mic", NULL, "Main Mic Bias"},
7254e2bd 161
b3208839
PU
162 {"SUBMIC", NULL, "Sub Handset Mic"},
163 {"Sub Handset Mic", NULL, "Main Mic Bias"},
23ac3b61 164
b3208839
PU
165 {"AFML", NULL, "Line In"},
166 {"AFMR", NULL, "Line In"},
5e64d6aa
MLC
167};
168
13f81d65 169static int omap_abe_twl6040_init(struct snd_soc_pcm_runtime *rtd)
5e64d6aa 170{
7480389f 171 struct snd_soc_component *component = rtd->codec_dai->component;
0596f700 172 struct snd_soc_card *card = rtd->card;
356bccbe 173 struct abe_twl6040 *priv = snd_soc_card_get_drvdata(card);
4ca07cb0
PU
174 int hs_trim;
175 int ret = 0;
176
7bf3d92c
PU
177 /*
178 * Configure McPDM offset cancellation based on the HSOTRIM value from
179 * twl6040.
180 */
7480389f 181 hs_trim = twl6040_get_trim_value(component, TWL6040_TRIM_HSOTRIM);
7bf3d92c
PU
182 omap_mcpdm_configure_dn_offsets(rtd, TWL6040_HSF_TRIM_LEFT(hs_trim),
183 TWL6040_HSF_TRIM_RIGHT(hs_trim));
184
4ca07cb0 185 /* Headset jack detection only if it is supported */
356bccbe 186 if (priv->jack_detection) {
25649592
LPC
187 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
188 SND_JACK_HEADSET, &hs_jack,
189 hs_jack_pins,
190 ARRAY_SIZE(hs_jack_pins));
4ca07cb0
PU
191 if (ret)
192 return ret;
96dc227c 193
7480389f 194 twl6040_hs_jack_detect(component, &hs_jack, SND_JACK_HEADSET);
4ca07cb0 195 }
5e64d6aa 196
25649592 197 return 0;
5e64d6aa
MLC
198}
199
6524c8e3 200static const struct snd_soc_dapm_route dmic_audio_map[] = {
778cee7a
PU
201 {"DMic", NULL, "Digital Mic"},
202 {"Digital Mic", NULL, "Digital Mic1 Bias"},
6524c8e3
PU
203};
204
13f81d65 205static int omap_abe_dmic_init(struct snd_soc_pcm_runtime *rtd)
6524c8e3 206{
7f0af4ae 207 struct snd_soc_dapm_context *dapm = &rtd->card->dapm;
6524c8e3
PU
208
209 return snd_soc_dapm_add_routes(dapm, dmic_audio_map,
210 ARRAY_SIZE(dmic_audio_map));
211}
212
7ff60006 213static int omap_abe_probe(struct platform_device *pdev)
5e64d6aa 214{
5ef75e71 215 struct device_node *node = pdev->dev.of_node;
76836fd3 216 struct snd_soc_card *card;
8fe120b5 217 struct device_node *dai_node;
356bccbe 218 struct abe_twl6040 *priv;
c2f98956 219 int num_links = 0;
5ef75e71 220 int ret = 0;
5e64d6aa 221
8fe120b5
PU
222 if (!node) {
223 dev_err(&pdev->dev, "of node is missing.\n");
224 return -ENODEV;
225 }
226
356bccbe
PU
227 priv = devm_kzalloc(&pdev->dev, sizeof(struct abe_twl6040), GFP_KERNEL);
228 if (priv == NULL)
229 return -ENOMEM;
230
76836fd3
PU
231 card = &priv->card;
232 card->dev = &pdev->dev;
233 card->owner = THIS_MODULE;
234 card->dapm_widgets = twl6040_dapm_widgets;
235 card->num_dapm_widgets = ARRAY_SIZE(twl6040_dapm_widgets);
236 card->dapm_routes = audio_map;
237 card->num_dapm_routes = ARRAY_SIZE(audio_map);
238
8fe120b5
PU
239 if (snd_soc_of_parse_card_name(card, "ti,model")) {
240 dev_err(&pdev->dev, "Card name is not provided\n");
241 return -ENODEV;
242 }
5ef75e71 243
8fe120b5
PU
244 ret = snd_soc_of_parse_audio_routing(card, "ti,audio-routing");
245 if (ret) {
246 dev_err(&pdev->dev, "Error while parsing DAPM routing\n");
247 return ret;
248 }
5ef75e71 249
8fe120b5
PU
250 dai_node = of_parse_phandle(node, "ti,mcpdm", 0);
251 if (!dai_node) {
252 dev_err(&pdev->dev, "McPDM node is not provided\n");
253 return -EINVAL;
254 }
76836fd3
PU
255
256 priv->dai_links[0].name = "DMIC";
257 priv->dai_links[0].stream_name = "TWL6040";
258 priv->dai_links[0].cpu_of_node = dai_node;
259 priv->dai_links[0].platform_of_node = dai_node;
260 priv->dai_links[0].codec_dai_name = "twl6040-legacy";
261 priv->dai_links[0].codec_name = "twl6040-codec";
262 priv->dai_links[0].init = omap_abe_twl6040_init;
263 priv->dai_links[0].ops = &omap_abe_ops;
5ef75e71 264
8fe120b5
PU
265 dai_node = of_parse_phandle(node, "ti,dmic", 0);
266 if (dai_node) {
267 num_links = 2;
76836fd3
PU
268 priv->dai_links[1].name = "TWL6040";
269 priv->dai_links[1].stream_name = "DMIC Capture";
270 priv->dai_links[1].cpu_of_node = dai_node;
271 priv->dai_links[1].platform_of_node = dai_node;
272 priv->dai_links[1].codec_dai_name = "dmic-hifi";
273 priv->dai_links[1].codec_name = "dmic-codec";
274 priv->dai_links[1].init = omap_abe_dmic_init;
275 priv->dai_links[1].ops = &omap_abe_dmic_ops;
d1be1d2f 276 } else {
8fe120b5
PU
277 num_links = 1;
278 }
279
280 priv->jack_detection = of_property_read_bool(node, "ti,jack-detection");
281 of_property_read_u32(node, "ti,mclk-freq", &priv->mclk_freq);
282 if (!priv->mclk_freq) {
283 dev_err(&pdev->dev, "MCLK frequency not provided\n");
21eb45db 284 return -EINVAL;
d1be1d2f 285 }
5e64d6aa 286
8fe120b5 287 card->fully_routed = 1;
356bccbe
PU
288
289 if (!priv->mclk_freq) {
62ba98ce 290 dev_err(&pdev->dev, "MCLK frequency missing\n");
21eb45db 291 return -ENODEV;
62ba98ce
PU
292 }
293
76836fd3 294 card->dai_link = priv->dai_links;
c2f98956 295 card->num_links = num_links;
8d946dd7 296
356bccbe
PU
297 snd_soc_card_set_drvdata(card, priv);
298
687df1ad 299 ret = devm_snd_soc_register_card(&pdev->dev, card);
21eb45db 300 if (ret)
687df1ad 301 dev_err(&pdev->dev, "devm_snd_soc_register_card() failed: %d\n",
d1be1d2f 302 ret);
5e64d6aa 303
5e64d6aa
MLC
304 return ret;
305}
5e64d6aa 306
5ef75e71
PU
307static const struct of_device_id omap_abe_of_match[] = {
308 {.compatible = "ti,abe-twl6040", },
309 { },
310};
311MODULE_DEVICE_TABLE(of, omap_abe_of_match);
312
d1be1d2f
PU
313static struct platform_driver omap_abe_driver = {
314 .driver = {
315 .name = "omap-abe-twl6040",
d1be1d2f 316 .pm = &snd_soc_pm_ops,
5ef75e71 317 .of_match_table = omap_abe_of_match,
d1be1d2f
PU
318 },
319 .probe = omap_abe_probe,
d1be1d2f
PU
320};
321
21eb45db
PU
322static int __init omap_abe_init(void)
323{
324 int ret;
325
326 dmic_codec_dev = platform_device_register_simple("dmic-codec", -1, NULL,
327 0);
328 if (IS_ERR(dmic_codec_dev)) {
329 pr_err("%s: dmic-codec device registration failed\n", __func__);
330 return PTR_ERR(dmic_codec_dev);
331 }
332
333 ret = platform_driver_register(&omap_abe_driver);
334 if (ret) {
335 pr_err("%s: platform driver registration failed\n", __func__);
336 platform_device_unregister(dmic_codec_dev);
337 }
338
339 return ret;
340}
341module_init(omap_abe_init);
342
343static void __exit omap_abe_exit(void)
344{
345 platform_driver_unregister(&omap_abe_driver);
346 platform_device_unregister(dmic_codec_dev);
347}
348module_exit(omap_abe_exit);
5e64d6aa 349
8747a6b7 350MODULE_AUTHOR("Misael Lopez Cruz <[email protected]>");
13f81d65 351MODULE_DESCRIPTION("ALSA SoC for OMAP boards with ABE and twl6040 codec");
5e64d6aa 352MODULE_LICENSE("GPL");
d1be1d2f 353MODULE_ALIAS("platform:omap-abe-twl6040");
This page took 0.389068 seconds and 4 git commands to generate.