blob: d55e6477bff0c9a855379d26db50538ff7b5e178 [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
Vladimir Barinov310355c2008-02-18 11:40:22 +010025#include "davinci-pcm.h"
26#include "davinci-i2s.h"
Chaithrika U S04f80f52009-06-05 06:28:49 -040027#include "davinci-mcasp.h"
Vladimir Barinov310355c2008-02-18 11:40:22 +010028
Troy Kiskyd6f83392008-12-19 13:05:25 -070029#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
30 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
Vladimir Barinov310355c2008-02-18 11:40:22 +010031static int evm_hw_params(struct snd_pcm_substream *substream,
32 struct snd_pcm_hw_params *params)
33{
34 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000035 struct snd_soc_dai *codec_dai = rtd->codec_dai;
36 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Vladimir Barinov310355c2008-02-18 11:40:22 +010037 int ret = 0;
David Brownell05d5e992009-01-04 02:50:10 -080038 unsigned sysclk;
39
40 /* ASP1 on DM355 EVM is clocked by an external oscillator */
Miguel Aguilar9b95b162009-09-02 15:33:59 -060041 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
42 machine_is_davinci_dm365_evm())
David Brownell05d5e992009-01-04 02:50:10 -080043 sysclk = 27000000;
44
45 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
46 * board-dm644x-evm.c using GPIOs from U18. There are six
47 * options; here we "know" we use a 48 KHz sample rate.
48 */
49 else if (machine_is_davinci_evm())
50 sysclk = 12288000;
51
Chaithrika U S30230f42009-08-11 16:59:21 -040052 else if (machine_is_davinci_da830_evm() ||
53 machine_is_davinci_da850_evm())
Chaithrika U S7ae59452009-08-07 10:07:51 -040054 sysclk = 24576000;
55
David Brownell05d5e992009-01-04 02:50:10 -080056 else
57 return -EINVAL;
Vladimir Barinov310355c2008-02-18 11:40:22 +010058
59 /* set codec DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070060 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010061 if (ret < 0)
62 return ret;
63
64 /* set cpu DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070065 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010066 if (ret < 0)
67 return ret;
68
69 /* set the codec system clock */
David Brownell05d5e992009-01-04 02:50:10 -080070 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010071 if (ret < 0)
72 return ret;
73
Daniel Mack5b66aa22012-10-04 15:08:41 +020074 /* set the CPU system clock */
75 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
76 if (ret < 0)
77 return ret;
78
Vladimir Barinov310355c2008-02-18 11:40:22 +010079 return 0;
80}
81
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053082static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
83 struct snd_pcm_hw_params *params)
84{
85 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000086 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053087
88 /* set cpu DAI configuration */
89 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
90}
91
Vladimir Barinov310355c2008-02-18 11:40:22 +010092static struct snd_soc_ops evm_ops = {
93 .hw_params = evm_hw_params,
94};
95
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053096static struct snd_soc_ops evm_spdif_ops = {
97 .hw_params = evm_spdif_hw_params,
98};
99
Vladimir Barinov310355c2008-02-18 11:40:22 +0100100/* davinci-evm machine dapm widgets */
101static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
102 SND_SOC_DAPM_HP("Headphone Jack", NULL),
103 SND_SOC_DAPM_LINE("Line Out", NULL),
104 SND_SOC_DAPM_MIC("Mic Jack", NULL),
105 SND_SOC_DAPM_LINE("Line In", NULL),
106};
107
108/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +0200109static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100110 /* Headphone connected to HPLOUT, HPROUT */
111 {"Headphone Jack", NULL, "HPLOUT"},
112 {"Headphone Jack", NULL, "HPROUT"},
113
114 /* Line Out connected to LLOUT, RLOUT */
115 {"Line Out", NULL, "LLOUT"},
116 {"Line Out", NULL, "RLOUT"},
117
118 /* Mic connected to (MIC3L | MIC3R) */
119 {"MIC3L", NULL, "Mic Bias 2V"},
120 {"MIC3R", NULL, "Mic Bias 2V"},
121 {"Mic Bias 2V", NULL, "Mic Jack"},
122
123 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
124 {"LINE1L", NULL, "Line In"},
125 {"LINE2L", NULL, "Line In"},
126 {"LINE1R", NULL, "Line In"},
127 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100128};
129
130/* Logic for a aic3x as connected on a davinci-evm */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000131static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
Vladimir Barinov310355c2008-02-18 11:40:22 +0100132{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000133 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200134 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000135
Vladimir Barinov310355c2008-02-18 11:40:22 +0100136 /* Add davinci-evm specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200137 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
Mark Brownacf497f2008-05-13 14:58:30 +0200138 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100139
140 /* Set up davinci-evm specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200141 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100142
143 /* not connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200144 snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
145 snd_soc_dapm_disable_pin(dapm, "HPLCOM");
146 snd_soc_dapm_disable_pin(dapm, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100147
148 /* always connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200149 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
150 snd_soc_dapm_enable_pin(dapm, "Line Out");
151 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
152 snd_soc_dapm_enable_pin(dapm, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100153
Vladimir Barinov310355c2008-02-18 11:40:22 +0100154 return 0;
155}
156
157/* davinci-evm digital audio interface glue - connects codec <--> CPU */
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000158static struct snd_soc_dai_link dm6446_evm_dai = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100159 .name = "TLV320AIC3X",
160 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000161 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000162 .codec_dai_name = "tlv320aic3x-hifi",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000163 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530164 .platform_name = "davinci-mcbsp",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000165 .init = evm_aic3x_init,
166 .ops = &evm_ops,
167};
168
169static struct snd_soc_dai_link dm355_evm_dai = {
170 .name = "TLV320AIC3X",
171 .stream_name = "AIC3X",
172 .cpu_dai_name = "davinci-mcbsp.1",
173 .codec_dai_name = "tlv320aic3x-hifi",
174 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530175 .platform_name = "davinci-mcbsp.1",
Vladimir Barinov310355c2008-02-18 11:40:22 +0100176 .init = evm_aic3x_init,
177 .ops = &evm_ops,
178};
179
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600180static struct snd_soc_dai_link dm365_evm_dai = {
181#ifdef CONFIG_SND_DM365_AIC3X_CODEC
182 .name = "TLV320AIC3X",
183 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000184 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000185 .codec_dai_name = "tlv320aic3x-hifi",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600186 .init = evm_aic3x_init,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000187 .codec_name = "tlv320aic3x-codec.1-0018",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600188 .ops = &evm_ops,
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530189 .platform_name = "davinci-mcbsp",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600190#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
191 .name = "Voice Codec - CQ93VC",
192 .stream_name = "CQ93",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000193 .cpu_dai_name = "davinci-vcif",
194 .codec_dai_name = "cq93vc-hifi",
195 .codec_name = "cq93vc-codec",
Hebbar, Gururajaffb690d2012-08-31 18:20:59 +0530196 .platform_name = "davinci-vcif",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600197#endif
198};
199
Chaithrika U S04f80f52009-06-05 06:28:49 -0400200static struct snd_soc_dai_link dm6467_evm_dai[] = {
201 {
202 .name = "TLV320AIC3X",
203 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000204 .cpu_dai_name= "davinci-mcasp.0",
205 .codec_dai_name = "tlv320aic3x-hifi",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530206 .platform_name = "davinci-mcasp.0",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000207 .codec_name = "tlv320aic3x-codec.0-001a",
Chaithrika U S04f80f52009-06-05 06:28:49 -0400208 .init = evm_aic3x_init,
209 .ops = &evm_ops,
210 },
211 {
212 .name = "McASP",
213 .stream_name = "spdif",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000214 .cpu_dai_name= "davinci-mcasp.1",
215 .codec_dai_name = "dit-hifi",
216 .codec_name = "spdif_dit",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530217 .platform_name = "davinci-mcasp.1",
Chaithrika U S8d43d1b2010-03-10 14:48:33 +0530218 .ops = &evm_spdif_ops,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400219 },
220};
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530221
222static struct snd_soc_dai_link da830_evm_dai = {
223 .name = "TLV320AIC3X",
224 .stream_name = "AIC3X",
225 .cpu_dai_name = "davinci-mcasp.1",
226 .codec_dai_name = "tlv320aic3x-hifi",
227 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530228 .platform_name = "davinci-mcasp.1",
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530229 .init = evm_aic3x_init,
230 .ops = &evm_ops,
231};
232
233static struct snd_soc_dai_link da850_evm_dai = {
Chaithrika U S7ae59452009-08-07 10:07:51 -0400234 .name = "TLV320AIC3X",
235 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000236 .cpu_dai_name= "davinci-mcasp.0",
237 .codec_dai_name = "tlv320aic3x-hifi",
Rajashekhara, Sudhakardc5a4602011-01-21 20:10:01 +0530238 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530239 .platform_name = "davinci-mcasp.0",
Chaithrika U S7ae59452009-08-07 10:07:51 -0400240 .init = evm_aic3x_init,
241 .ops = &evm_ops,
242};
Chaithrika U S04f80f52009-06-05 06:28:49 -0400243
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000244/* davinci dm6446 evm audio machine driver */
245static struct snd_soc_card dm6446_snd_soc_card_evm = {
246 .name = "DaVinci DM6446 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800247 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000248 .dai_link = &dm6446_evm_dai,
249 .num_links = 1,
250};
251
252/* davinci dm355 evm audio machine driver */
253static struct snd_soc_card dm355_snd_soc_card_evm = {
254 .name = "DaVinci DM355 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800255 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000256 .dai_link = &dm355_evm_dai,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100257 .num_links = 1,
258};
259
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600260/* davinci dm365 evm audio machine driver */
261static struct snd_soc_card dm365_snd_soc_card_evm = {
262 .name = "DaVinci DM365 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800263 .owner = THIS_MODULE,
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600264 .dai_link = &dm365_evm_dai,
265 .num_links = 1,
266};
267
Chaithrika U S04f80f52009-06-05 06:28:49 -0400268/* davinci dm6467 evm audio machine driver */
269static struct snd_soc_card dm6467_snd_soc_card_evm = {
270 .name = "DaVinci DM6467 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800271 .owner = THIS_MODULE,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400272 .dai_link = dm6467_evm_dai,
273 .num_links = ARRAY_SIZE(dm6467_evm_dai),
274};
275
Chaithrika U S7ae59452009-08-07 10:07:51 -0400276static struct snd_soc_card da830_snd_soc_card = {
Chaithrika U S30230f42009-08-11 16:59:21 -0400277 .name = "DA830/OMAP-L137 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800278 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530279 .dai_link = &da830_evm_dai,
Chaithrika U S30230f42009-08-11 16:59:21 -0400280 .num_links = 1,
281};
282
283static struct snd_soc_card da850_snd_soc_card = {
284 .name = "DA850/OMAP-L138 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800285 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530286 .dai_link = &da850_evm_dai,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400287 .num_links = 1,
288};
289
Vladimir Barinov310355c2008-02-18 11:40:22 +0100290static struct platform_device *evm_snd_device;
291
292static int __init evm_init(void)
293{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000294 struct snd_soc_card *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700295 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100296 int ret;
297
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600298 if (machine_is_davinci_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000299 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700300 index = 0;
301 } else if (machine_is_davinci_dm355_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000302 evm_snd_dev_data = &dm355_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700303 index = 1;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600304 } else if (machine_is_davinci_dm365_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000305 evm_snd_dev_data = &dm365_snd_soc_card_evm;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600306 index = 0;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400307 } else if (machine_is_davinci_dm6467_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000308 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400309 index = 0;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400310 } else if (machine_is_davinci_da830_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000311 evm_snd_dev_data = &da830_snd_soc_card;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400312 index = 1;
Chaithrika U S30230f42009-08-11 16:59:21 -0400313 } else if (machine_is_davinci_da850_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000314 evm_snd_dev_data = &da850_snd_soc_card;
Chaithrika U S30230f42009-08-11 16:59:21 -0400315 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700316 } else
317 return -EINVAL;
318
319 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100320 if (!evm_snd_device)
321 return -ENOMEM;
322
Chaithrika U S04f80f52009-06-05 06:28:49 -0400323 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100324 ret = platform_device_add(evm_snd_device);
325 if (ret)
326 platform_device_put(evm_snd_device);
327
328 return ret;
329}
330
331static void __exit evm_exit(void)
332{
333 platform_device_unregister(evm_snd_device);
334}
335
336module_init(evm_init);
337module_exit(evm_exit);
338
339MODULE_AUTHOR("Vladimir Barinov");
340MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
341MODULE_LICENSE("GPL");