blob: fd7c45b9ed5a3836323a4d54af31df6f2929d050 [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>
Matt Porter3ad7a422013-03-06 11:15:31 -050017#include <linux/platform_data/edma.h>
Ben Dooksaa6b9042009-08-20 22:50:42 +010018#include <linux/i2c.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010019#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/soc.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010022
Vladimir Barinov310355c2008-02-18 11:40:22 +010023#include <asm/dma.h>
David Brownellf492ec92009-05-14 13:01:59 -070024#include <asm/mach-types.h>
25
Vladimir Barinov310355c2008-02-18 11:40:22 +010026#include "davinci-pcm.h"
27#include "davinci-i2s.h"
Chaithrika U S04f80f52009-06-05 06:28:49 -040028#include "davinci-mcasp.h"
Vladimir Barinov310355c2008-02-18 11:40:22 +010029
Troy Kiskyd6f83392008-12-19 13:05:25 -070030#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
31 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
Vladimir Barinov310355c2008-02-18 11:40:22 +010032static int evm_hw_params(struct snd_pcm_substream *substream,
33 struct snd_pcm_hw_params *params)
34{
35 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000036 struct snd_soc_dai *codec_dai = rtd->codec_dai;
37 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Vladimir Barinov310355c2008-02-18 11:40:22 +010038 int ret = 0;
David Brownell05d5e992009-01-04 02:50:10 -080039 unsigned sysclk;
40
41 /* ASP1 on DM355 EVM is clocked by an external oscillator */
Miguel Aguilar9b95b162009-09-02 15:33:59 -060042 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
43 machine_is_davinci_dm365_evm())
David Brownell05d5e992009-01-04 02:50:10 -080044 sysclk = 27000000;
45
46 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
47 * board-dm644x-evm.c using GPIOs from U18. There are six
48 * options; here we "know" we use a 48 KHz sample rate.
49 */
50 else if (machine_is_davinci_evm())
51 sysclk = 12288000;
52
Chaithrika U S30230f42009-08-11 16:59:21 -040053 else if (machine_is_davinci_da830_evm() ||
54 machine_is_davinci_da850_evm())
Chaithrika U S7ae59452009-08-07 10:07:51 -040055 sysclk = 24576000;
56
David Brownell05d5e992009-01-04 02:50:10 -080057 else
58 return -EINVAL;
Vladimir Barinov310355c2008-02-18 11:40:22 +010059
60 /* set codec DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070061 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010062 if (ret < 0)
63 return ret;
64
65 /* set cpu DAI configuration */
Troy Kisky9e031622008-12-19 13:05:23 -070066 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010067 if (ret < 0)
68 return ret;
69
70 /* set the codec system clock */
David Brownell05d5e992009-01-04 02:50:10 -080071 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010072 if (ret < 0)
73 return ret;
74
Daniel Mack5b66aa22012-10-04 15:08:41 +020075 /* set the CPU system clock */
76 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
77 if (ret < 0)
78 return ret;
79
Vladimir Barinov310355c2008-02-18 11:40:22 +010080 return 0;
81}
82
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053083static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
84 struct snd_pcm_hw_params *params)
85{
86 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000087 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053088
89 /* set cpu DAI configuration */
90 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
91}
92
Vladimir Barinov310355c2008-02-18 11:40:22 +010093static struct snd_soc_ops evm_ops = {
94 .hw_params = evm_hw_params,
95};
96
Chaithrika U S8d43d1b2010-03-10 14:48:33 +053097static struct snd_soc_ops evm_spdif_ops = {
98 .hw_params = evm_spdif_hw_params,
99};
100
Vladimir Barinov310355c2008-02-18 11:40:22 +0100101/* davinci-evm machine dapm widgets */
102static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
103 SND_SOC_DAPM_HP("Headphone Jack", NULL),
104 SND_SOC_DAPM_LINE("Line Out", NULL),
105 SND_SOC_DAPM_MIC("Mic Jack", NULL),
106 SND_SOC_DAPM_LINE("Line In", NULL),
107};
108
109/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +0200110static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100111 /* Headphone connected to HPLOUT, HPROUT */
112 {"Headphone Jack", NULL, "HPLOUT"},
113 {"Headphone Jack", NULL, "HPROUT"},
114
115 /* Line Out connected to LLOUT, RLOUT */
116 {"Line Out", NULL, "LLOUT"},
117 {"Line Out", NULL, "RLOUT"},
118
119 /* Mic connected to (MIC3L | MIC3R) */
Hebbar Gururajae2e8bfd2013-01-31 18:23:04 +0530120 {"MIC3L", NULL, "Mic Bias"},
121 {"MIC3R", NULL, "Mic Bias"},
122 {"Mic Bias", NULL, "Mic Jack"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100123
124 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
125 {"LINE1L", NULL, "Line In"},
126 {"LINE2L", NULL, "Line In"},
127 {"LINE1R", NULL, "Line In"},
128 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100129};
130
131/* Logic for a aic3x as connected on a davinci-evm */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000132static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
Vladimir Barinov310355c2008-02-18 11:40:22 +0100133{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000134 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200135 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000136
Vladimir Barinov310355c2008-02-18 11:40:22 +0100137 /* Add davinci-evm specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200138 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
Mark Brownacf497f2008-05-13 14:58:30 +0200139 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100140
141 /* Set up davinci-evm specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200142 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100143
144 /* not connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200145 snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
146 snd_soc_dapm_disable_pin(dapm, "HPLCOM");
147 snd_soc_dapm_disable_pin(dapm, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100148
149 /* always connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200150 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
151 snd_soc_dapm_enable_pin(dapm, "Line Out");
152 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
153 snd_soc_dapm_enable_pin(dapm, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100154
Vladimir Barinov310355c2008-02-18 11:40:22 +0100155 return 0;
156}
157
158/* davinci-evm digital audio interface glue - connects codec <--> CPU */
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000159static struct snd_soc_dai_link dm6446_evm_dai = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100160 .name = "TLV320AIC3X",
161 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000162 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000163 .codec_dai_name = "tlv320aic3x-hifi",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000164 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530165 .platform_name = "davinci-mcbsp",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000166 .init = evm_aic3x_init,
167 .ops = &evm_ops,
168};
169
170static struct snd_soc_dai_link dm355_evm_dai = {
171 .name = "TLV320AIC3X",
172 .stream_name = "AIC3X",
173 .cpu_dai_name = "davinci-mcbsp.1",
174 .codec_dai_name = "tlv320aic3x-hifi",
175 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530176 .platform_name = "davinci-mcbsp.1",
Vladimir Barinov310355c2008-02-18 11:40:22 +0100177 .init = evm_aic3x_init,
178 .ops = &evm_ops,
179};
180
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600181static struct snd_soc_dai_link dm365_evm_dai = {
182#ifdef CONFIG_SND_DM365_AIC3X_CODEC
183 .name = "TLV320AIC3X",
184 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000185 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000186 .codec_dai_name = "tlv320aic3x-hifi",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600187 .init = evm_aic3x_init,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000188 .codec_name = "tlv320aic3x-codec.1-0018",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600189 .ops = &evm_ops,
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530190 .platform_name = "davinci-mcbsp",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600191#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
192 .name = "Voice Codec - CQ93VC",
193 .stream_name = "CQ93",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000194 .cpu_dai_name = "davinci-vcif",
195 .codec_dai_name = "cq93vc-hifi",
196 .codec_name = "cq93vc-codec",
Hebbar, Gururajaffb690d2012-08-31 18:20:59 +0530197 .platform_name = "davinci-vcif",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600198#endif
199};
200
Chaithrika U S04f80f52009-06-05 06:28:49 -0400201static struct snd_soc_dai_link dm6467_evm_dai[] = {
202 {
203 .name = "TLV320AIC3X",
204 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000205 .cpu_dai_name= "davinci-mcasp.0",
206 .codec_dai_name = "tlv320aic3x-hifi",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530207 .platform_name = "davinci-mcasp.0",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000208 .codec_name = "tlv320aic3x-codec.0-001a",
Chaithrika U S04f80f52009-06-05 06:28:49 -0400209 .init = evm_aic3x_init,
210 .ops = &evm_ops,
211 },
212 {
213 .name = "McASP",
214 .stream_name = "spdif",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000215 .cpu_dai_name= "davinci-mcasp.1",
216 .codec_dai_name = "dit-hifi",
217 .codec_name = "spdif_dit",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530218 .platform_name = "davinci-mcasp.1",
Chaithrika U S8d43d1b2010-03-10 14:48:33 +0530219 .ops = &evm_spdif_ops,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400220 },
221};
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530222
223static struct snd_soc_dai_link da830_evm_dai = {
224 .name = "TLV320AIC3X",
225 .stream_name = "AIC3X",
226 .cpu_dai_name = "davinci-mcasp.1",
227 .codec_dai_name = "tlv320aic3x-hifi",
228 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530229 .platform_name = "davinci-mcasp.1",
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530230 .init = evm_aic3x_init,
231 .ops = &evm_ops,
232};
233
234static struct snd_soc_dai_link da850_evm_dai = {
Chaithrika U S7ae59452009-08-07 10:07:51 -0400235 .name = "TLV320AIC3X",
236 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000237 .cpu_dai_name= "davinci-mcasp.0",
238 .codec_dai_name = "tlv320aic3x-hifi",
Rajashekhara, Sudhakardc5a4602011-01-21 20:10:01 +0530239 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530240 .platform_name = "davinci-mcasp.0",
Chaithrika U S7ae59452009-08-07 10:07:51 -0400241 .init = evm_aic3x_init,
242 .ops = &evm_ops,
243};
Chaithrika U S04f80f52009-06-05 06:28:49 -0400244
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000245/* davinci dm6446 evm audio machine driver */
246static struct snd_soc_card dm6446_snd_soc_card_evm = {
247 .name = "DaVinci DM6446 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800248 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000249 .dai_link = &dm6446_evm_dai,
250 .num_links = 1,
251};
252
253/* davinci dm355 evm audio machine driver */
254static struct snd_soc_card dm355_snd_soc_card_evm = {
255 .name = "DaVinci DM355 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800256 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000257 .dai_link = &dm355_evm_dai,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100258 .num_links = 1,
259};
260
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600261/* davinci dm365 evm audio machine driver */
262static struct snd_soc_card dm365_snd_soc_card_evm = {
263 .name = "DaVinci DM365 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800264 .owner = THIS_MODULE,
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600265 .dai_link = &dm365_evm_dai,
266 .num_links = 1,
267};
268
Chaithrika U S04f80f52009-06-05 06:28:49 -0400269/* davinci dm6467 evm audio machine driver */
270static struct snd_soc_card dm6467_snd_soc_card_evm = {
271 .name = "DaVinci DM6467 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800272 .owner = THIS_MODULE,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400273 .dai_link = dm6467_evm_dai,
274 .num_links = ARRAY_SIZE(dm6467_evm_dai),
275};
276
Chaithrika U S7ae59452009-08-07 10:07:51 -0400277static struct snd_soc_card da830_snd_soc_card = {
Chaithrika U S30230f42009-08-11 16:59:21 -0400278 .name = "DA830/OMAP-L137 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800279 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530280 .dai_link = &da830_evm_dai,
Chaithrika U S30230f42009-08-11 16:59:21 -0400281 .num_links = 1,
282};
283
284static struct snd_soc_card da850_snd_soc_card = {
285 .name = "DA850/OMAP-L138 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800286 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530287 .dai_link = &da850_evm_dai,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400288 .num_links = 1,
289};
290
Vladimir Barinov310355c2008-02-18 11:40:22 +0100291static struct platform_device *evm_snd_device;
292
293static int __init evm_init(void)
294{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000295 struct snd_soc_card *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700296 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100297 int ret;
298
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600299 if (machine_is_davinci_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000300 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700301 index = 0;
302 } else if (machine_is_davinci_dm355_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000303 evm_snd_dev_data = &dm355_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700304 index = 1;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600305 } else if (machine_is_davinci_dm365_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000306 evm_snd_dev_data = &dm365_snd_soc_card_evm;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600307 index = 0;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400308 } else if (machine_is_davinci_dm6467_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000309 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400310 index = 0;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400311 } else if (machine_is_davinci_da830_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000312 evm_snd_dev_data = &da830_snd_soc_card;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400313 index = 1;
Chaithrika U S30230f42009-08-11 16:59:21 -0400314 } else if (machine_is_davinci_da850_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000315 evm_snd_dev_data = &da850_snd_soc_card;
Chaithrika U S30230f42009-08-11 16:59:21 -0400316 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700317 } else
318 return -EINVAL;
319
320 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100321 if (!evm_snd_device)
322 return -ENOMEM;
323
Chaithrika U S04f80f52009-06-05 06:28:49 -0400324 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100325 ret = platform_device_add(evm_snd_device);
326 if (ret)
327 platform_device_put(evm_snd_device);
328
329 return ret;
330}
331
332static void __exit evm_exit(void)
333{
334 platform_device_unregister(evm_snd_device);
335}
336
337module_init(evm_init);
338module_exit(evm_exit);
339
340MODULE_AUTHOR("Vladimir Barinov");
341MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
342MODULE_LICENSE("GPL");