blob: 4b37e2ac4685d4e7e8977889eabbf968b157ea88 [file] [log] [blame]
Vladimir Barinov310355c2008-02-18 11:40:22 +01001/*
2 * ASoC driver for TI DAVINCI EVM platform
3 *
Vladimir Barinovd6b52032008-09-29 23:14:11 +04004 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
Vladimir Barinov310355c2008-02-18 11:40:22 +01005 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.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 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/timer.h>
15#include <linux/interrupt.h>
16#include <linux/platform_device.h>
Ben Dooksaa6b9042009-08-20 22:50:42 +010017#include <linux/i2c.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010018#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/soc.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010021
Vladimir Barinov310355c2008-02-18 11:40:22 +010022#include <asm/dma.h>
David Brownellf492ec92009-05-14 13:01:59 -070023#include <asm/mach-types.h>
24
25#include <mach/asp.h>
26#include <mach/edma.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010027
Vladimir Barinov310355c2008-02-18 11:40:22 +010028#include "davinci-pcm.h"
29#include "davinci-i2s.h"
Chaithrika U S04f80f52009-06-05 06:28:49 -040030#include "davinci-mcasp.h"
Vladimir Barinov310355c2008-02-18 11:40:22 +010031
Troy Kiskyd6f83392008-12-19 13:05:25 -070032#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
33 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
Vladimir Barinov310355c2008-02-18 11:40:22 +010034static int evm_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;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000038 struct snd_soc_dai *codec_dai = rtd->codec_dai;
39 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Vladimir Barinov310355c2008-02-18 11:40:22 +010040 int ret = 0;
David Brownell05d5e992009-01-04 02:50:10 -080041 unsigned sysclk;
42
43 /* ASP1 on DM355 EVM is clocked by an external oscillator */
Miguel Aguilar9b95b162009-09-02 15:33:59 -060044 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
45 machine_is_davinci_dm365_evm())
David Brownell05d5e992009-01-04 02:50:10 -080046 sysclk = 27000000;
47
48 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
49 * board-dm644x-evm.c using GPIOs from U18. There are six
50 * options; here we "know" we use a 48 KHz sample rate.
51 */
52 else if (machine_is_davinci_evm())
53 sysclk = 12288000;
54
Chaithrika U S30230f42009-08-11 16:59:21 -040055 else if (machine_is_davinci_da830_evm() ||
56 machine_is_davinci_da850_evm())
Chaithrika U S7ae59452009-08-07 10:07:51 -040057 sysclk = 24576000;
58
David Brownell05d5e992009-01-04 02:50:10 -080059 else
60 return -EINVAL;
Vladimir Barinov310355c2008-02-18 11:40:22 +010061
62 /* set codec DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070063 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010064 if (ret < 0)
65 return ret;
66
67 /* set cpu DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070068 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010069 if (ret < 0)
70 return ret;
71
72 /* set the codec system clock */
David Brownell05d5e992009-01-04 02:50:10 -080073 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010074 if (ret < 0)
75 return ret;
76
77 return 0;
78}
79
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053080static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
81 struct snd_pcm_hw_params *params)
82{
83 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000084 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053085
86 /* set cpu DAI configuration */
87 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
88}
89
Vladimir Barinov310355c2008-02-18 11:40:22 +010090static struct snd_soc_ops evm_ops = {
91 .hw_params = evm_hw_params,
92};
93
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053094static struct snd_soc_ops evm_spdif_ops = {
95 .hw_params = evm_spdif_hw_params,
96};
97
Vladimir Barinov310355c2008-02-18 11:40:22 +010098/* davinci-evm machine dapm widgets */
99static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
100 SND_SOC_DAPM_HP("Headphone Jack", NULL),
101 SND_SOC_DAPM_LINE("Line Out", NULL),
102 SND_SOC_DAPM_MIC("Mic Jack", NULL),
103 SND_SOC_DAPM_LINE("Line In", NULL),
104};
105
106/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +0200107static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100108 /* Headphone connected to HPLOUT, HPROUT */
109 {"Headphone Jack", NULL, "HPLOUT"},
110 {"Headphone Jack", NULL, "HPROUT"},
111
112 /* Line Out connected to LLOUT, RLOUT */
113 {"Line Out", NULL, "LLOUT"},
114 {"Line Out", NULL, "RLOUT"},
115
116 /* Mic connected to (MIC3L | MIC3R) */
117 {"MIC3L", NULL, "Mic Bias 2V"},
118 {"MIC3R", NULL, "Mic Bias 2V"},
119 {"Mic Bias 2V", NULL, "Mic Jack"},
120
121 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
122 {"LINE1L", NULL, "Line In"},
123 {"LINE2L", NULL, "Line In"},
124 {"LINE1R", NULL, "Line In"},
125 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100126};
127
128/* Logic for a aic3x as connected on a davinci-evm */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000129static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
Vladimir Barinov310355c2008-02-18 11:40:22 +0100130{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000131 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200132 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000133
Vladimir Barinov310355c2008-02-18 11:40:22 +0100134 /* Add davinci-evm specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200135 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
Mark Brownacf497f2008-05-13 14:58:30 +0200136 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100137
138 /* Set up davinci-evm specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200139 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100140
141 /* not connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200142 snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
143 snd_soc_dapm_disable_pin(dapm, "HPLCOM");
144 snd_soc_dapm_disable_pin(dapm, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100145
146 /* always connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200147 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
148 snd_soc_dapm_enable_pin(dapm, "Line Out");
149 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
150 snd_soc_dapm_enable_pin(dapm, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100151
Vladimir Barinov310355c2008-02-18 11:40:22 +0100152 return 0;
153}
154
155/* davinci-evm digital audio interface glue - connects codec <--> CPU */
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000156static struct snd_soc_dai_link dm6446_evm_dai = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100157 .name = "TLV320AIC3X",
158 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000159 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000160 .codec_dai_name = "tlv320aic3x-hifi",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000161 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530162 .platform_name = "davinci-mcbsp",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000163 .init = evm_aic3x_init,
164 .ops = &evm_ops,
165};
166
167static struct snd_soc_dai_link dm355_evm_dai = {
168 .name = "TLV320AIC3X",
169 .stream_name = "AIC3X",
170 .cpu_dai_name = "davinci-mcbsp.1",
171 .codec_dai_name = "tlv320aic3x-hifi",
172 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530173 .platform_name = "davinci-mcbsp.1",
Vladimir Barinov310355c2008-02-18 11:40:22 +0100174 .init = evm_aic3x_init,
175 .ops = &evm_ops,
176};
177
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600178static struct snd_soc_dai_link dm365_evm_dai = {
179#ifdef CONFIG_SND_DM365_AIC3X_CODEC
180 .name = "TLV320AIC3X",
181 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000182 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000183 .codec_dai_name = "tlv320aic3x-hifi",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600184 .init = evm_aic3x_init,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000185 .codec_name = "tlv320aic3x-codec.1-0018",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600186 .ops = &evm_ops,
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530187 .platform_name = "davinci-mcbsp",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600188#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
189 .name = "Voice Codec - CQ93VC",
190 .stream_name = "CQ93",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000191 .cpu_dai_name = "davinci-vcif",
192 .codec_dai_name = "cq93vc-hifi",
193 .codec_name = "cq93vc-codec",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530194 .platform_name = "avinci-vcif",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600195#endif
196};
197
Chaithrika U S04f80f52009-06-05 06:28:49 -0400198static struct snd_soc_dai_link dm6467_evm_dai[] = {
199 {
200 .name = "TLV320AIC3X",
201 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000202 .cpu_dai_name= "davinci-mcasp.0",
203 .codec_dai_name = "tlv320aic3x-hifi",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530204 .platform_name = "davinci-mcasp.0",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000205 .codec_name = "tlv320aic3x-codec.0-001a",
Chaithrika U S04f80f52009-06-05 06:28:49 -0400206 .init = evm_aic3x_init,
207 .ops = &evm_ops,
208 },
209 {
210 .name = "McASP",
211 .stream_name = "spdif",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000212 .cpu_dai_name= "davinci-mcasp.1",
213 .codec_dai_name = "dit-hifi",
214 .codec_name = "spdif_dit",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530215 .platform_name = "davinci-mcasp.1",
Chaithrika U S8d43d1b2010-03-10 14:48:33 +0530216 .ops = &evm_spdif_ops,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400217 },
218};
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530219
220static struct snd_soc_dai_link da830_evm_dai = {
221 .name = "TLV320AIC3X",
222 .stream_name = "AIC3X",
223 .cpu_dai_name = "davinci-mcasp.1",
224 .codec_dai_name = "tlv320aic3x-hifi",
225 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530226 .platform_name = "davinci-mcasp.1",
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530227 .init = evm_aic3x_init,
228 .ops = &evm_ops,
229};
230
231static struct snd_soc_dai_link da850_evm_dai = {
Chaithrika U S7ae59452009-08-07 10:07:51 -0400232 .name = "TLV320AIC3X",
233 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000234 .cpu_dai_name= "davinci-mcasp.0",
235 .codec_dai_name = "tlv320aic3x-hifi",
Rajashekhara, Sudhakardc5a4602011-01-21 20:10:01 +0530236 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530237 .platform_name = "davinci-mcasp.0",
Chaithrika U S7ae59452009-08-07 10:07:51 -0400238 .init = evm_aic3x_init,
239 .ops = &evm_ops,
240};
Chaithrika U S04f80f52009-06-05 06:28:49 -0400241
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000242/* davinci dm6446 evm audio machine driver */
243static struct snd_soc_card dm6446_snd_soc_card_evm = {
244 .name = "DaVinci DM6446 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800245 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000246 .dai_link = &dm6446_evm_dai,
247 .num_links = 1,
248};
249
250/* davinci dm355 evm audio machine driver */
251static struct snd_soc_card dm355_snd_soc_card_evm = {
252 .name = "DaVinci DM355 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800253 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000254 .dai_link = &dm355_evm_dai,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100255 .num_links = 1,
256};
257
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600258/* davinci dm365 evm audio machine driver */
259static struct snd_soc_card dm365_snd_soc_card_evm = {
260 .name = "DaVinci DM365 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800261 .owner = THIS_MODULE,
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600262 .dai_link = &dm365_evm_dai,
263 .num_links = 1,
264};
265
Chaithrika U S04f80f52009-06-05 06:28:49 -0400266/* davinci dm6467 evm audio machine driver */
267static struct snd_soc_card dm6467_snd_soc_card_evm = {
268 .name = "DaVinci DM6467 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800269 .owner = THIS_MODULE,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400270 .dai_link = dm6467_evm_dai,
271 .num_links = ARRAY_SIZE(dm6467_evm_dai),
272};
273
Chaithrika U S7ae59452009-08-07 10:07:51 -0400274static struct snd_soc_card da830_snd_soc_card = {
Chaithrika U S30230f42009-08-11 16:59:21 -0400275 .name = "DA830/OMAP-L137 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800276 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530277 .dai_link = &da830_evm_dai,
Chaithrika U S30230f42009-08-11 16:59:21 -0400278 .num_links = 1,
279};
280
281static struct snd_soc_card da850_snd_soc_card = {
282 .name = "DA850/OMAP-L138 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800283 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530284 .dai_link = &da850_evm_dai,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400285 .num_links = 1,
286};
287
Vladimir Barinov310355c2008-02-18 11:40:22 +0100288static struct platform_device *evm_snd_device;
289
290static int __init evm_init(void)
291{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000292 struct snd_soc_card *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700293 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100294 int ret;
295
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600296 if (machine_is_davinci_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000297 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700298 index = 0;
299 } else if (machine_is_davinci_dm355_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000300 evm_snd_dev_data = &dm355_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700301 index = 1;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600302 } else if (machine_is_davinci_dm365_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000303 evm_snd_dev_data = &dm365_snd_soc_card_evm;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600304 index = 0;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400305 } else if (machine_is_davinci_dm6467_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000306 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400307 index = 0;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400308 } else if (machine_is_davinci_da830_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000309 evm_snd_dev_data = &da830_snd_soc_card;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400310 index = 1;
Chaithrika U S30230f42009-08-11 16:59:21 -0400311 } else if (machine_is_davinci_da850_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000312 evm_snd_dev_data = &da850_snd_soc_card;
Chaithrika U S30230f42009-08-11 16:59:21 -0400313 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700314 } else
315 return -EINVAL;
316
317 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100318 if (!evm_snd_device)
319 return -ENOMEM;
320
Chaithrika U S04f80f52009-06-05 06:28:49 -0400321 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100322 ret = platform_device_add(evm_snd_device);
323 if (ret)
324 platform_device_put(evm_snd_device);
325
326 return ret;
327}
328
329static void __exit evm_exit(void)
330{
331 platform_device_unregister(evm_snd_device);
332}
333
334module_init(evm_init);
335module_exit(evm_exit);
336
337MODULE_AUTHOR("Vladimir Barinov");
338MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
339MODULE_LICENSE("GPL");