blob: 5e3bc3c6801a6bbf9512731f6cd094b2eb41511f [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>
Vladimir Barinov310355c2008-02-18 11:40:22 +010020#include <sound/core.h>
21#include <sound/pcm.h>
22#include <sound/soc.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010023
Vladimir Barinov310355c2008-02-18 11:40:22 +010024#include <asm/dma.h>
David Brownellf492ec92009-05-14 13:01:59 -070025#include <asm/mach-types.h>
26
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +030027#include <linux/edma.h>
28
Vladimir Barinov310355c2008-02-18 11:40:22 +010029#include "davinci-pcm.h"
30#include "davinci-i2s.h"
Vladimir Barinov310355c2008-02-18 11:40:22 +010031
Jyri Sarhabcf25562013-09-17 12:26:00 +030032struct snd_soc_card_drvdata_davinci {
33 unsigned sysclk;
34};
35
Vladimir Barinov310355c2008-02-18 11:40:22 +010036static int evm_hw_params(struct snd_pcm_substream *substream,
37 struct snd_pcm_hw_params *params)
38{
39 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000040 struct snd_soc_dai *codec_dai = rtd->codec_dai;
41 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Jyri Sarhabcf25562013-09-17 12:26:00 +030042 struct snd_soc_codec *codec = rtd->codec;
43 struct snd_soc_card *soc_card = codec->card;
Vladimir Barinov310355c2008-02-18 11:40:22 +010044 int ret = 0;
Jyri Sarhabcf25562013-09-17 12:26:00 +030045 unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *)
46 snd_soc_card_get_drvdata(soc_card))->sysclk;
Vladimir Barinov310355c2008-02-18 11:40:22 +010047
Vladimir Barinov310355c2008-02-18 11:40:22 +010048 /* set the codec system clock */
David Brownell05d5e992009-01-04 02:50:10 -080049 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
Vladimir Barinov310355c2008-02-18 11:40:22 +010050 if (ret < 0)
51 return ret;
52
Daniel Mack5b66aa22012-10-04 15:08:41 +020053 /* set the CPU system clock */
54 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
55 if (ret < 0)
56 return ret;
57
Vladimir Barinov310355c2008-02-18 11:40:22 +010058 return 0;
59}
60
61static struct snd_soc_ops evm_ops = {
62 .hw_params = evm_hw_params,
63};
64
65/* davinci-evm machine dapm widgets */
66static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
67 SND_SOC_DAPM_HP("Headphone Jack", NULL),
68 SND_SOC_DAPM_LINE("Line Out", NULL),
69 SND_SOC_DAPM_MIC("Mic Jack", NULL),
70 SND_SOC_DAPM_LINE("Line In", NULL),
71};
72
73/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +020074static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +010075 /* Headphone connected to HPLOUT, HPROUT */
76 {"Headphone Jack", NULL, "HPLOUT"},
77 {"Headphone Jack", NULL, "HPROUT"},
78
79 /* Line Out connected to LLOUT, RLOUT */
80 {"Line Out", NULL, "LLOUT"},
81 {"Line Out", NULL, "RLOUT"},
82
83 /* Mic connected to (MIC3L | MIC3R) */
Hebbar Gururajae2e8bfd2013-01-31 18:23:04 +053084 {"MIC3L", NULL, "Mic Bias"},
85 {"MIC3R", NULL, "Mic Bias"},
86 {"Mic Bias", NULL, "Mic Jack"},
Vladimir Barinov310355c2008-02-18 11:40:22 +010087
88 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
89 {"LINE1L", NULL, "Line In"},
90 {"LINE2L", NULL, "Line In"},
91 {"LINE1R", NULL, "Line In"},
92 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +010093};
94
95/* Logic for a aic3x as connected on a davinci-evm */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000096static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
Vladimir Barinov310355c2008-02-18 11:40:22 +010097{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000098 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020099 struct snd_soc_dapm_context *dapm = &codec->dapm;
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300100 struct device_node *np = codec->card->dev->of_node;
101 int ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000102
Vladimir Barinov310355c2008-02-18 11:40:22 +0100103 /* Add davinci-evm specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200104 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
Mark Brownacf497f2008-05-13 14:58:30 +0200105 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100106
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300107 if (np) {
108 ret = snd_soc_of_parse_audio_routing(codec->card,
109 "ti,audio-routing");
110 if (ret)
111 return ret;
112 } else {
113 /* Set up davinci-evm specific audio path audio_map */
114 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
115 }
Vladimir Barinov310355c2008-02-18 11:40:22 +0100116
117 /* not connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200118 snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
119 snd_soc_dapm_disable_pin(dapm, "HPLCOM");
120 snd_soc_dapm_disable_pin(dapm, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100121
122 /* always connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200123 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
124 snd_soc_dapm_enable_pin(dapm, "Line Out");
125 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
126 snd_soc_dapm_enable_pin(dapm, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100127
Vladimir Barinov310355c2008-02-18 11:40:22 +0100128 return 0;
129}
130
131/* davinci-evm digital audio interface glue - connects codec <--> CPU */
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000132static struct snd_soc_dai_link dm6446_evm_dai = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100133 .name = "TLV320AIC3X",
134 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000135 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000136 .codec_dai_name = "tlv320aic3x-hifi",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000137 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530138 .platform_name = "davinci-mcbsp",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000139 .init = evm_aic3x_init,
140 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200141 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
142 SND_SOC_DAIFMT_IB_NF,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000143};
144
145static struct snd_soc_dai_link dm355_evm_dai = {
146 .name = "TLV320AIC3X",
147 .stream_name = "AIC3X",
148 .cpu_dai_name = "davinci-mcbsp.1",
149 .codec_dai_name = "tlv320aic3x-hifi",
150 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530151 .platform_name = "davinci-mcbsp.1",
Vladimir Barinov310355c2008-02-18 11:40:22 +0100152 .init = evm_aic3x_init,
153 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200154 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
155 SND_SOC_DAIFMT_IB_NF,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100156};
157
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600158static struct snd_soc_dai_link dm365_evm_dai = {
159#ifdef CONFIG_SND_DM365_AIC3X_CODEC
160 .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-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530165 .platform_name = "davinci-mcbsp",
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200166 .init = evm_aic3x_init,
167 .ops = &evm_ops,
168 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
169 SND_SOC_DAIFMT_IB_NF,
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600170#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
171 .name = "Voice Codec - CQ93VC",
172 .stream_name = "CQ93",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000173 .cpu_dai_name = "davinci-vcif",
174 .codec_dai_name = "cq93vc-hifi",
175 .codec_name = "cq93vc-codec",
Hebbar, Gururajaffb690d2012-08-31 18:20:59 +0530176 .platform_name = "davinci-vcif",
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600177#endif
178};
179
Chaithrika U S04f80f52009-06-05 06:28:49 -0400180static struct snd_soc_dai_link dm6467_evm_dai[] = {
181 {
182 .name = "TLV320AIC3X",
183 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000184 .cpu_dai_name= "davinci-mcasp.0",
185 .codec_dai_name = "tlv320aic3x-hifi",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530186 .platform_name = "davinci-mcasp.0",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000187 .codec_name = "tlv320aic3x-codec.0-001a",
Chaithrika U S04f80f52009-06-05 06:28:49 -0400188 .init = evm_aic3x_init,
189 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200190 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
191 SND_SOC_DAIFMT_IB_NF,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400192 },
193 {
194 .name = "McASP",
195 .stream_name = "spdif",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000196 .cpu_dai_name= "davinci-mcasp.1",
197 .codec_dai_name = "dit-hifi",
198 .codec_name = "spdif_dit",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530199 .platform_name = "davinci-mcasp.1",
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200200 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
201 SND_SOC_DAIFMT_IB_NF,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400202 },
203};
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530204
205static struct snd_soc_dai_link da830_evm_dai = {
206 .name = "TLV320AIC3X",
207 .stream_name = "AIC3X",
208 .cpu_dai_name = "davinci-mcasp.1",
209 .codec_dai_name = "tlv320aic3x-hifi",
210 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530211 .platform_name = "davinci-mcasp.1",
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530212 .init = evm_aic3x_init,
213 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200214 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
215 SND_SOC_DAIFMT_IB_NF,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530216};
217
218static struct snd_soc_dai_link da850_evm_dai = {
Chaithrika U S7ae59452009-08-07 10:07:51 -0400219 .name = "TLV320AIC3X",
220 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000221 .cpu_dai_name= "davinci-mcasp.0",
222 .codec_dai_name = "tlv320aic3x-hifi",
Rajashekhara, Sudhakardc5a4602011-01-21 20:10:01 +0530223 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530224 .platform_name = "davinci-mcasp.0",
Chaithrika U S7ae59452009-08-07 10:07:51 -0400225 .init = evm_aic3x_init,
226 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200227 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
228 SND_SOC_DAIFMT_IB_NF,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400229};
Chaithrika U S04f80f52009-06-05 06:28:49 -0400230
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000231/* davinci dm6446 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300232/*
233 * ASP0 in DM6446 EVM is clocked by U55, as configured by
234 * board-dm644x-evm.c using GPIOs from U18. There are six
235 * options; here we "know" we use a 48 KHz sample rate.
236 */
237static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata = {
238 .sysclk = 12288000,
239};
240
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000241static struct snd_soc_card dm6446_snd_soc_card_evm = {
242 .name = "DaVinci DM6446 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800243 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000244 .dai_link = &dm6446_evm_dai,
245 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300246 .drvdata = &dm6446_snd_soc_card_drvdata,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000247};
248
249/* davinci dm355 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300250/* ASP1 on DM355 EVM is clocked by an external oscillator */
251static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata = {
252 .sysclk = 27000000,
253};
254
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000255static struct snd_soc_card dm355_snd_soc_card_evm = {
256 .name = "DaVinci DM355 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800257 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000258 .dai_link = &dm355_evm_dai,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100259 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300260 .drvdata = &dm355_snd_soc_card_drvdata,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100261};
262
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600263/* davinci dm365 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300264static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata = {
265 .sysclk = 27000000,
266};
267
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600268static struct snd_soc_card dm365_snd_soc_card_evm = {
269 .name = "DaVinci DM365 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800270 .owner = THIS_MODULE,
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600271 .dai_link = &dm365_evm_dai,
272 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300273 .drvdata = &dm365_snd_soc_card_drvdata,
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600274};
275
Chaithrika U S04f80f52009-06-05 06:28:49 -0400276/* davinci dm6467 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300277static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata = {
278 .sysclk = 27000000,
279};
280
Chaithrika U S04f80f52009-06-05 06:28:49 -0400281static struct snd_soc_card dm6467_snd_soc_card_evm = {
282 .name = "DaVinci DM6467 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800283 .owner = THIS_MODULE,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400284 .dai_link = dm6467_evm_dai,
285 .num_links = ARRAY_SIZE(dm6467_evm_dai),
Jyri Sarhabcf25562013-09-17 12:26:00 +0300286 .drvdata = &dm6467_snd_soc_card_drvdata,
287};
288
289static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata = {
290 .sysclk = 24576000,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400291};
292
Chaithrika U S7ae59452009-08-07 10:07:51 -0400293static struct snd_soc_card da830_snd_soc_card = {
Chaithrika U S30230f42009-08-11 16:59:21 -0400294 .name = "DA830/OMAP-L137 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800295 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530296 .dai_link = &da830_evm_dai,
Chaithrika U S30230f42009-08-11 16:59:21 -0400297 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300298 .drvdata = &da830_snd_soc_card_drvdata,
299};
300
301static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata = {
302 .sysclk = 24576000,
Chaithrika U S30230f42009-08-11 16:59:21 -0400303};
304
305static struct snd_soc_card da850_snd_soc_card = {
306 .name = "DA850/OMAP-L138 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800307 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530308 .dai_link = &da850_evm_dai,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400309 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300310 .drvdata = &da850_snd_soc_card_drvdata,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400311};
312
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300313#if defined(CONFIG_OF)
314
315/*
316 * The struct is used as place holder. It will be completely
317 * filled with data from dt node.
318 */
319static struct snd_soc_dai_link evm_dai_tlv320aic3x = {
320 .name = "TLV320AIC3X",
321 .stream_name = "AIC3X",
322 .codec_dai_name = "tlv320aic3x-hifi",
323 .ops = &evm_ops,
324 .init = evm_aic3x_init,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200325 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
326 SND_SOC_DAIFMT_IB_NF,
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300327};
328
329static const struct of_device_id davinci_evm_dt_ids[] = {
330 {
331 .compatible = "ti,da830-evm-audio",
332 .data = (void *) &evm_dai_tlv320aic3x,
333 },
334 { /* sentinel */ }
335};
336MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids);
337
338/* davinci evm audio machine driver */
339static struct snd_soc_card evm_soc_card = {
340 .owner = THIS_MODULE,
341 .num_links = 1,
342};
343
344static int davinci_evm_probe(struct platform_device *pdev)
345{
346 struct device_node *np = pdev->dev.of_node;
347 const struct of_device_id *match =
348 of_match_device(of_match_ptr(davinci_evm_dt_ids), &pdev->dev);
349 struct snd_soc_dai_link *dai = (struct snd_soc_dai_link *) match->data;
350 struct snd_soc_card_drvdata_davinci *drvdata = NULL;
351 int ret = 0;
352
353 evm_soc_card.dai_link = dai;
354
355 dai->codec_of_node = of_parse_phandle(np, "ti,audio-codec", 0);
356 if (!dai->codec_of_node)
357 return -EINVAL;
358
359 dai->cpu_of_node = of_parse_phandle(np, "ti,mcasp-controller", 0);
360 if (!dai->cpu_of_node)
361 return -EINVAL;
362
363 dai->platform_of_node = dai->cpu_of_node;
364
365 evm_soc_card.dev = &pdev->dev;
366 ret = snd_soc_of_parse_card_name(&evm_soc_card, "ti,model");
367 if (ret)
368 return ret;
369
370 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
371 if (!drvdata)
372 return -ENOMEM;
373
374 ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk);
375 if (ret < 0)
376 return -EINVAL;
377
378 snd_soc_card_set_drvdata(&evm_soc_card, drvdata);
379 ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card);
380
381 if (ret)
382 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
383
384 return ret;
385}
386
387static int davinci_evm_remove(struct platform_device *pdev)
388{
389 struct snd_soc_card *card = platform_get_drvdata(pdev);
390
391 snd_soc_unregister_card(card);
392
393 return 0;
394}
395
396static struct platform_driver davinci_evm_driver = {
397 .probe = davinci_evm_probe,
398 .remove = davinci_evm_remove,
399 .driver = {
400 .name = "davinci_evm",
401 .owner = THIS_MODULE,
Peter Ujfalusifb6d2082014-01-30 15:21:31 +0200402 .pm = &snd_soc_pm_ops,
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300403 .of_match_table = of_match_ptr(davinci_evm_dt_ids),
404 },
405};
406#endif
407
Vladimir Barinov310355c2008-02-18 11:40:22 +0100408static struct platform_device *evm_snd_device;
409
410static int __init evm_init(void)
411{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000412 struct snd_soc_card *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700413 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100414 int ret;
415
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300416 /*
417 * If dtb is there, the devices will be created dynamically.
418 * Only register platfrom driver structure.
419 */
420#if defined(CONFIG_OF)
421 if (of_have_populated_dt())
422 return platform_driver_register(&davinci_evm_driver);
423#endif
424
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600425 if (machine_is_davinci_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000426 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700427 index = 0;
428 } else if (machine_is_davinci_dm355_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000429 evm_snd_dev_data = &dm355_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700430 index = 1;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600431 } else if (machine_is_davinci_dm365_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000432 evm_snd_dev_data = &dm365_snd_soc_card_evm;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600433 index = 0;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400434 } else if (machine_is_davinci_dm6467_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000435 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400436 index = 0;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400437 } else if (machine_is_davinci_da830_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000438 evm_snd_dev_data = &da830_snd_soc_card;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400439 index = 1;
Chaithrika U S30230f42009-08-11 16:59:21 -0400440 } else if (machine_is_davinci_da850_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000441 evm_snd_dev_data = &da850_snd_soc_card;
Chaithrika U S30230f42009-08-11 16:59:21 -0400442 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700443 } else
444 return -EINVAL;
445
446 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100447 if (!evm_snd_device)
448 return -ENOMEM;
449
Chaithrika U S04f80f52009-06-05 06:28:49 -0400450 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100451 ret = platform_device_add(evm_snd_device);
452 if (ret)
453 platform_device_put(evm_snd_device);
454
455 return ret;
456}
457
458static void __exit evm_exit(void)
459{
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300460#if defined(CONFIG_OF)
461 if (of_have_populated_dt()) {
462 platform_driver_unregister(&davinci_evm_driver);
463 return;
464 }
465#endif
466
Vladimir Barinov310355c2008-02-18 11:40:22 +0100467 platform_device_unregister(evm_snd_device);
468}
469
470module_init(evm_init);
471module_exit(evm_exit);
472
473MODULE_AUTHOR("Vladimir Barinov");
474MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
475MODULE_LICENSE("GPL");