blob: a50010e2891f42ec870d423db7b135e0067a965e [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>
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +030019#include <linux/of_platform.h>
Jyri Sarha5ad88652014-01-27 17:37:51 +020020#include <linux/clk.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010021#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/soc.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010024
Vladimir Barinov310355c2008-02-18 11:40:22 +010025#include <asm/dma.h>
David Brownellf492ec92009-05-14 13:01:59 -070026#include <asm/mach-types.h>
27
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +030028#include <linux/edma.h>
29
Vladimir Barinov310355c2008-02-18 11:40:22 +010030#include "davinci-pcm.h"
31#include "davinci-i2s.h"
Vladimir Barinov310355c2008-02-18 11:40:22 +010032
Jyri Sarhabcf25562013-09-17 12:26:00 +030033struct snd_soc_card_drvdata_davinci {
Jyri Sarha5ad88652014-01-27 17:37:51 +020034 struct clk *mclk;
Jyri Sarhabcf25562013-09-17 12:26:00 +030035 unsigned sysclk;
36};
37
Jyri Sarha5ad88652014-01-27 17:37:51 +020038static int evm_startup(struct snd_pcm_substream *substream)
39{
40 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Lars-Peter Clausen2896b8b2014-05-19 11:41:47 +020041 struct snd_soc_card *soc_card = rtd->card;
Jyri Sarha5ad88652014-01-27 17:37:51 +020042 struct snd_soc_card_drvdata_davinci *drvdata =
43 snd_soc_card_get_drvdata(soc_card);
44
45 if (drvdata->mclk)
46 return clk_prepare_enable(drvdata->mclk);
47
48 return 0;
49}
50
51static void evm_shutdown(struct snd_pcm_substream *substream)
52{
53 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Lars-Peter Clausen2896b8b2014-05-19 11:41:47 +020054 struct snd_soc_card *soc_card = rtd->card;
Jyri Sarha5ad88652014-01-27 17:37:51 +020055 struct snd_soc_card_drvdata_davinci *drvdata =
56 snd_soc_card_get_drvdata(soc_card);
57
58 if (drvdata->mclk)
59 clk_disable_unprepare(drvdata->mclk);
60}
61
Vladimir Barinov310355c2008-02-18 11:40:22 +010062static int evm_hw_params(struct snd_pcm_substream *substream,
63 struct snd_pcm_hw_params *params)
64{
65 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000066 struct snd_soc_dai *codec_dai = rtd->codec_dai;
67 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Lars-Peter Clausen2896b8b2014-05-19 11:41:47 +020068 struct snd_soc_card *soc_card = rtd->card;
Vladimir Barinov310355c2008-02-18 11:40:22 +010069 int ret = 0;
Jyri Sarhabcf25562013-09-17 12:26:00 +030070 unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *)
71 snd_soc_card_get_drvdata(soc_card))->sysclk;
Vladimir Barinov310355c2008-02-18 11:40:22 +010072
Vladimir Barinov310355c2008-02-18 11:40:22 +010073 /* set the codec system clock */
David Brownell05d5e992009-01-04 02:50:10 -080074 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010075 if (ret < 0)
76 return ret;
77
Daniel Mack5b66aa22012-10-04 15:08:41 +020078 /* set the CPU system clock */
79 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
80 if (ret < 0)
81 return ret;
82
Vladimir Barinov310355c2008-02-18 11:40:22 +010083 return 0;
84}
85
86static struct snd_soc_ops evm_ops = {
Jyri Sarha5ad88652014-01-27 17:37:51 +020087 .startup = evm_startup,
88 .shutdown = evm_shutdown,
Vladimir Barinov310355c2008-02-18 11:40:22 +010089 .hw_params = evm_hw_params,
90};
91
92/* davinci-evm machine dapm widgets */
93static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
94 SND_SOC_DAPM_HP("Headphone Jack", NULL),
95 SND_SOC_DAPM_LINE("Line Out", NULL),
96 SND_SOC_DAPM_MIC("Mic Jack", NULL),
97 SND_SOC_DAPM_LINE("Line In", NULL),
98};
99
100/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +0200101static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100102 /* Headphone connected to HPLOUT, HPROUT */
103 {"Headphone Jack", NULL, "HPLOUT"},
104 {"Headphone Jack", NULL, "HPROUT"},
105
106 /* Line Out connected to LLOUT, RLOUT */
107 {"Line Out", NULL, "LLOUT"},
108 {"Line Out", NULL, "RLOUT"},
109
110 /* Mic connected to (MIC3L | MIC3R) */
Hebbar Gururajae2e8bfd2013-01-31 18:23:04 +0530111 {"MIC3L", NULL, "Mic Bias"},
112 {"MIC3R", NULL, "Mic Bias"},
113 {"Mic Bias", NULL, "Mic Jack"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100114
115 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
116 {"LINE1L", NULL, "Line In"},
117 {"LINE2L", NULL, "Line In"},
118 {"LINE1R", NULL, "Line In"},
119 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100120};
121
122/* Logic for a aic3x as connected on a davinci-evm */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000123static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
Vladimir Barinov310355c2008-02-18 11:40:22 +0100124{
Lars-Peter Clausend343a662014-03-12 15:27:35 +0100125 struct snd_soc_card *card = rtd->card;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000126 struct snd_soc_codec *codec = rtd->codec;
Lars-Peter Clausen2896b8b2014-05-19 11:41:47 +0200127 struct device_node *np = card->dev->of_node;
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300128 int ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000129
Vladimir Barinov310355c2008-02-18 11:40:22 +0100130 /* Add davinci-evm specific widgets */
Lars-Peter Clausend343a662014-03-12 15:27:35 +0100131 snd_soc_dapm_new_controls(&card->dapm, aic3x_dapm_widgets,
Mark Brownacf497f2008-05-13 14:58:30 +0200132 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100133
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300134 if (np) {
Lars-Peter Clausend343a662014-03-12 15:27:35 +0100135 ret = snd_soc_of_parse_audio_routing(card, "ti,audio-routing");
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300136 if (ret)
137 return ret;
138 } else {
139 /* Set up davinci-evm specific audio path audio_map */
Lars-Peter Clausend343a662014-03-12 15:27:35 +0100140 snd_soc_dapm_add_routes(&card->dapm, audio_map,
141 ARRAY_SIZE(audio_map));
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300142 }
Vladimir Barinov310355c2008-02-18 11:40:22 +0100143
144 /* not connected */
Lars-Peter Clausend343a662014-03-12 15:27:35 +0100145 snd_soc_dapm_nc_pin(&codec->dapm, "MONO_LOUT");
146 snd_soc_dapm_nc_pin(&codec->dapm, "HPLCOM");
147 snd_soc_dapm_nc_pin(&codec->dapm, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100148
Vladimir Barinov310355c2008-02-18 11:40:22 +0100149 return 0;
150}
151
152/* davinci-evm digital audio interface glue - connects codec <--> CPU */
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000153static struct snd_soc_dai_link dm6446_evm_dai = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100154 .name = "TLV320AIC3X",
155 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000156 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000157 .codec_dai_name = "tlv320aic3x-hifi",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000158 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530159 .platform_name = "davinci-mcbsp",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000160 .init = evm_aic3x_init,
161 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200162 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
163 SND_SOC_DAIFMT_IB_NF,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000164};
165
166static struct snd_soc_dai_link dm355_evm_dai = {
167 .name = "TLV320AIC3X",
168 .stream_name = "AIC3X",
169 .cpu_dai_name = "davinci-mcbsp.1",
170 .codec_dai_name = "tlv320aic3x-hifi",
171 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530172 .platform_name = "davinci-mcbsp.1",
Vladimir Barinov310355c2008-02-18 11:40:22 +0100173 .init = evm_aic3x_init,
174 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200175 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
176 SND_SOC_DAIFMT_IB_NF,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100177};
178
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600179static struct snd_soc_dai_link dm365_evm_dai = {
180#ifdef CONFIG_SND_DM365_AIC3X_CODEC
181 .name = "TLV320AIC3X",
182 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000183 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000184 .codec_dai_name = "tlv320aic3x-hifi",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000185 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530186 .platform_name = "davinci-mcbsp",
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200187 .init = evm_aic3x_init,
188 .ops = &evm_ops,
189 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
190 SND_SOC_DAIFMT_IB_NF,
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,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200211 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
212 SND_SOC_DAIFMT_IB_NF,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400213 },
214 {
215 .name = "McASP",
216 .stream_name = "spdif",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000217 .cpu_dai_name= "davinci-mcasp.1",
218 .codec_dai_name = "dit-hifi",
219 .codec_name = "spdif_dit",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530220 .platform_name = "davinci-mcasp.1",
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200221 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
222 SND_SOC_DAIFMT_IB_NF,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400223 },
224};
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530225
226static struct snd_soc_dai_link da830_evm_dai = {
227 .name = "TLV320AIC3X",
228 .stream_name = "AIC3X",
229 .cpu_dai_name = "davinci-mcasp.1",
230 .codec_dai_name = "tlv320aic3x-hifi",
231 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530232 .platform_name = "davinci-mcasp.1",
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530233 .init = evm_aic3x_init,
234 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200235 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
236 SND_SOC_DAIFMT_IB_NF,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530237};
238
239static struct snd_soc_dai_link da850_evm_dai = {
Chaithrika U S7ae59452009-08-07 10:07:51 -0400240 .name = "TLV320AIC3X",
241 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000242 .cpu_dai_name= "davinci-mcasp.0",
243 .codec_dai_name = "tlv320aic3x-hifi",
Rajashekhara, Sudhakardc5a4602011-01-21 20:10:01 +0530244 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530245 .platform_name = "davinci-mcasp.0",
Chaithrika U S7ae59452009-08-07 10:07:51 -0400246 .init = evm_aic3x_init,
247 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200248 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
249 SND_SOC_DAIFMT_IB_NF,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400250};
Chaithrika U S04f80f52009-06-05 06:28:49 -0400251
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000252/* davinci dm6446 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300253/*
254 * ASP0 in DM6446 EVM is clocked by U55, as configured by
255 * board-dm644x-evm.c using GPIOs from U18. There are six
256 * options; here we "know" we use a 48 KHz sample rate.
257 */
258static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata = {
259 .sysclk = 12288000,
260};
261
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000262static struct snd_soc_card dm6446_snd_soc_card_evm = {
263 .name = "DaVinci DM6446 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800264 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000265 .dai_link = &dm6446_evm_dai,
266 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300267 .drvdata = &dm6446_snd_soc_card_drvdata,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000268};
269
270/* davinci dm355 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300271/* ASP1 on DM355 EVM is clocked by an external oscillator */
272static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata = {
273 .sysclk = 27000000,
274};
275
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000276static struct snd_soc_card dm355_snd_soc_card_evm = {
277 .name = "DaVinci DM355 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800278 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000279 .dai_link = &dm355_evm_dai,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100280 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300281 .drvdata = &dm355_snd_soc_card_drvdata,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100282};
283
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600284/* davinci dm365 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300285static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata = {
286 .sysclk = 27000000,
287};
288
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600289static struct snd_soc_card dm365_snd_soc_card_evm = {
290 .name = "DaVinci DM365 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800291 .owner = THIS_MODULE,
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600292 .dai_link = &dm365_evm_dai,
293 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300294 .drvdata = &dm365_snd_soc_card_drvdata,
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600295};
296
Chaithrika U S04f80f52009-06-05 06:28:49 -0400297/* davinci dm6467 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300298static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata = {
299 .sysclk = 27000000,
300};
301
Chaithrika U S04f80f52009-06-05 06:28:49 -0400302static struct snd_soc_card dm6467_snd_soc_card_evm = {
303 .name = "DaVinci DM6467 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800304 .owner = THIS_MODULE,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400305 .dai_link = dm6467_evm_dai,
306 .num_links = ARRAY_SIZE(dm6467_evm_dai),
Jyri Sarhabcf25562013-09-17 12:26:00 +0300307 .drvdata = &dm6467_snd_soc_card_drvdata,
308};
309
310static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata = {
311 .sysclk = 24576000,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400312};
313
Chaithrika U S7ae59452009-08-07 10:07:51 -0400314static struct snd_soc_card da830_snd_soc_card = {
Chaithrika U S30230f42009-08-11 16:59:21 -0400315 .name = "DA830/OMAP-L137 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800316 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530317 .dai_link = &da830_evm_dai,
Chaithrika U S30230f42009-08-11 16:59:21 -0400318 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300319 .drvdata = &da830_snd_soc_card_drvdata,
320};
321
322static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata = {
323 .sysclk = 24576000,
Chaithrika U S30230f42009-08-11 16:59:21 -0400324};
325
326static struct snd_soc_card da850_snd_soc_card = {
327 .name = "DA850/OMAP-L138 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800328 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530329 .dai_link = &da850_evm_dai,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400330 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300331 .drvdata = &da850_snd_soc_card_drvdata,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400332};
333
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300334#if defined(CONFIG_OF)
335
336/*
337 * The struct is used as place holder. It will be completely
338 * filled with data from dt node.
339 */
340static struct snd_soc_dai_link evm_dai_tlv320aic3x = {
341 .name = "TLV320AIC3X",
342 .stream_name = "AIC3X",
343 .codec_dai_name = "tlv320aic3x-hifi",
344 .ops = &evm_ops,
345 .init = evm_aic3x_init,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200346 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
347 SND_SOC_DAIFMT_IB_NF,
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300348};
349
350static const struct of_device_id davinci_evm_dt_ids[] = {
351 {
352 .compatible = "ti,da830-evm-audio",
353 .data = (void *) &evm_dai_tlv320aic3x,
354 },
355 { /* sentinel */ }
356};
357MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids);
358
359/* davinci evm audio machine driver */
360static struct snd_soc_card evm_soc_card = {
361 .owner = THIS_MODULE,
362 .num_links = 1,
363};
364
365static int davinci_evm_probe(struct platform_device *pdev)
366{
367 struct device_node *np = pdev->dev.of_node;
368 const struct of_device_id *match =
369 of_match_device(of_match_ptr(davinci_evm_dt_ids), &pdev->dev);
370 struct snd_soc_dai_link *dai = (struct snd_soc_dai_link *) match->data;
371 struct snd_soc_card_drvdata_davinci *drvdata = NULL;
Jyri Sarha5ad88652014-01-27 17:37:51 +0200372 struct clk *mclk;
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300373 int ret = 0;
374
375 evm_soc_card.dai_link = dai;
376
377 dai->codec_of_node = of_parse_phandle(np, "ti,audio-codec", 0);
378 if (!dai->codec_of_node)
379 return -EINVAL;
380
381 dai->cpu_of_node = of_parse_phandle(np, "ti,mcasp-controller", 0);
382 if (!dai->cpu_of_node)
383 return -EINVAL;
384
385 dai->platform_of_node = dai->cpu_of_node;
386
387 evm_soc_card.dev = &pdev->dev;
388 ret = snd_soc_of_parse_card_name(&evm_soc_card, "ti,model");
389 if (ret)
390 return ret;
391
Jyri Sarha5ad88652014-01-27 17:37:51 +0200392 mclk = devm_clk_get(&pdev->dev, "mclk");
393 if (PTR_ERR(mclk) == -EPROBE_DEFER) {
394 return -EPROBE_DEFER;
395 } else if (IS_ERR(mclk)) {
396 dev_dbg(&pdev->dev, "mclk not found.\n");
397 mclk = NULL;
398 }
399
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300400 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
401 if (!drvdata)
402 return -ENOMEM;
403
Jyri Sarha5ad88652014-01-27 17:37:51 +0200404 drvdata->mclk = mclk;
405
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300406 ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk);
Jyri Sarha5ad88652014-01-27 17:37:51 +0200407
408 if (ret < 0) {
409 if (!drvdata->mclk) {
410 dev_err(&pdev->dev,
411 "No clock or clock rate defined.\n");
412 return -EINVAL;
413 }
414 drvdata->sysclk = clk_get_rate(drvdata->mclk);
415 } else if (drvdata->mclk) {
416 unsigned int requestd_rate = drvdata->sysclk;
417 clk_set_rate(drvdata->mclk, drvdata->sysclk);
418 drvdata->sysclk = clk_get_rate(drvdata->mclk);
419 if (drvdata->sysclk != requestd_rate)
420 dev_warn(&pdev->dev,
421 "Could not get requested rate %u using %u.\n",
422 requestd_rate, drvdata->sysclk);
423 }
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300424
425 snd_soc_card_set_drvdata(&evm_soc_card, drvdata);
426 ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card);
427
428 if (ret)
429 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
430
431 return ret;
432}
433
434static int davinci_evm_remove(struct platform_device *pdev)
435{
436 struct snd_soc_card *card = platform_get_drvdata(pdev);
437
438 snd_soc_unregister_card(card);
439
440 return 0;
441}
442
443static struct platform_driver davinci_evm_driver = {
444 .probe = davinci_evm_probe,
445 .remove = davinci_evm_remove,
446 .driver = {
447 .name = "davinci_evm",
448 .owner = THIS_MODULE,
Peter Ujfalusifb6d2082014-01-30 15:21:31 +0200449 .pm = &snd_soc_pm_ops,
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300450 .of_match_table = of_match_ptr(davinci_evm_dt_ids),
451 },
452};
453#endif
454
Vladimir Barinov310355c2008-02-18 11:40:22 +0100455static struct platform_device *evm_snd_device;
456
457static int __init evm_init(void)
458{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000459 struct snd_soc_card *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700460 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100461 int ret;
462
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300463 /*
464 * If dtb is there, the devices will be created dynamically.
465 * Only register platfrom driver structure.
466 */
467#if defined(CONFIG_OF)
468 if (of_have_populated_dt())
469 return platform_driver_register(&davinci_evm_driver);
470#endif
471
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600472 if (machine_is_davinci_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000473 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700474 index = 0;
475 } else if (machine_is_davinci_dm355_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000476 evm_snd_dev_data = &dm355_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700477 index = 1;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600478 } else if (machine_is_davinci_dm365_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000479 evm_snd_dev_data = &dm365_snd_soc_card_evm;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600480 index = 0;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400481 } else if (machine_is_davinci_dm6467_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000482 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400483 index = 0;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400484 } else if (machine_is_davinci_da830_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000485 evm_snd_dev_data = &da830_snd_soc_card;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400486 index = 1;
Chaithrika U S30230f42009-08-11 16:59:21 -0400487 } else if (machine_is_davinci_da850_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000488 evm_snd_dev_data = &da850_snd_soc_card;
Chaithrika U S30230f42009-08-11 16:59:21 -0400489 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700490 } else
491 return -EINVAL;
492
493 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100494 if (!evm_snd_device)
495 return -ENOMEM;
496
Chaithrika U S04f80f52009-06-05 06:28:49 -0400497 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100498 ret = platform_device_add(evm_snd_device);
499 if (ret)
500 platform_device_put(evm_snd_device);
501
502 return ret;
503}
504
505static void __exit evm_exit(void)
506{
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300507#if defined(CONFIG_OF)
508 if (of_have_populated_dt()) {
509 platform_driver_unregister(&davinci_evm_driver);
510 return;
511 }
512#endif
513
Vladimir Barinov310355c2008-02-18 11:40:22 +0100514 platform_device_unregister(evm_snd_device);
515}
516
517module_init(evm_init);
518module_exit(evm_exit);
519
520MODULE_AUTHOR("Vladimir Barinov");
521MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
522MODULE_LICENSE("GPL");