blob: d1a8b6e3ac3bdd8d17b0d1efe2afdf111f33051d [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>
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +030018#include <linux/of_platform.h>
Jyri Sarha5ad88652014-01-27 17:37:51 +020019#include <linux/clk.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
Vladimir Barinov310355c2008-02-18 11:40:22 +010027#include "davinci-pcm.h"
28#include "davinci-i2s.h"
Vladimir Barinov310355c2008-02-18 11:40:22 +010029
Jyri Sarhabcf25562013-09-17 12:26:00 +030030struct snd_soc_card_drvdata_davinci {
Jyri Sarha5ad88652014-01-27 17:37:51 +020031 struct clk *mclk;
Jyri Sarhabcf25562013-09-17 12:26:00 +030032 unsigned sysclk;
33};
34
Jyri Sarha5ad88652014-01-27 17:37:51 +020035static int evm_startup(struct snd_pcm_substream *substream)
36{
37 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Lars-Peter Clausen2896b8b42014-05-19 11:41:47 +020038 struct snd_soc_card *soc_card = rtd->card;
Jyri Sarha5ad88652014-01-27 17:37:51 +020039 struct snd_soc_card_drvdata_davinci *drvdata =
40 snd_soc_card_get_drvdata(soc_card);
41
42 if (drvdata->mclk)
43 return clk_prepare_enable(drvdata->mclk);
44
45 return 0;
46}
47
48static void evm_shutdown(struct snd_pcm_substream *substream)
49{
50 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Lars-Peter Clausen2896b8b42014-05-19 11:41:47 +020051 struct snd_soc_card *soc_card = rtd->card;
Jyri Sarha5ad88652014-01-27 17:37:51 +020052 struct snd_soc_card_drvdata_davinci *drvdata =
53 snd_soc_card_get_drvdata(soc_card);
54
55 if (drvdata->mclk)
56 clk_disable_unprepare(drvdata->mclk);
57}
58
Vladimir Barinov310355c2008-02-18 11:40:22 +010059static int evm_hw_params(struct snd_pcm_substream *substream,
60 struct snd_pcm_hw_params *params)
61{
62 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000063 struct snd_soc_dai *codec_dai = rtd->codec_dai;
64 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Lars-Peter Clausen2896b8b42014-05-19 11:41:47 +020065 struct snd_soc_card *soc_card = rtd->card;
Vladimir Barinov310355c2008-02-18 11:40:22 +010066 int ret = 0;
Jyri Sarhabcf25562013-09-17 12:26:00 +030067 unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *)
68 snd_soc_card_get_drvdata(soc_card))->sysclk;
Vladimir Barinov310355c2008-02-18 11:40:22 +010069
Vladimir Barinov310355c2008-02-18 11:40:22 +010070 /* 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
83static struct snd_soc_ops evm_ops = {
Jyri Sarha5ad88652014-01-27 17:37:51 +020084 .startup = evm_startup,
85 .shutdown = evm_shutdown,
Vladimir Barinov310355c2008-02-18 11:40:22 +010086 .hw_params = evm_hw_params,
87};
88
89/* davinci-evm machine dapm widgets */
90static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
91 SND_SOC_DAPM_HP("Headphone Jack", NULL),
92 SND_SOC_DAPM_LINE("Line Out", NULL),
93 SND_SOC_DAPM_MIC("Mic Jack", NULL),
94 SND_SOC_DAPM_LINE("Line In", NULL),
95};
96
97/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +020098static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +010099 /* Headphone connected to HPLOUT, HPROUT */
100 {"Headphone Jack", NULL, "HPLOUT"},
101 {"Headphone Jack", NULL, "HPROUT"},
102
103 /* Line Out connected to LLOUT, RLOUT */
104 {"Line Out", NULL, "LLOUT"},
105 {"Line Out", NULL, "RLOUT"},
106
107 /* Mic connected to (MIC3L | MIC3R) */
Hebbar Gururajae2e8bfd2013-01-31 18:23:04 +0530108 {"MIC3L", NULL, "Mic Bias"},
109 {"MIC3R", NULL, "Mic Bias"},
110 {"Mic Bias", NULL, "Mic Jack"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100111
112 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
113 {"LINE1L", NULL, "Line In"},
114 {"LINE2L", NULL, "Line In"},
115 {"LINE1R", NULL, "Line In"},
116 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +0100117};
118
119/* Logic for a aic3x as connected on a davinci-evm */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000120static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
Vladimir Barinov310355c2008-02-18 11:40:22 +0100121{
Lars-Peter Clausend343a662014-03-12 15:27:35 +0100122 struct snd_soc_card *card = rtd->card;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000123 struct snd_soc_codec *codec = rtd->codec;
Lars-Peter Clausen2896b8b42014-05-19 11:41:47 +0200124 struct device_node *np = card->dev->of_node;
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300125 int ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000126
Vladimir Barinov310355c2008-02-18 11:40:22 +0100127 /* Add davinci-evm specific widgets */
Lars-Peter Clausend343a662014-03-12 15:27:35 +0100128 snd_soc_dapm_new_controls(&card->dapm, aic3x_dapm_widgets,
Mark Brownacf497f2008-05-13 14:58:30 +0200129 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100130
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300131 if (np) {
Lars-Peter Clausend343a662014-03-12 15:27:35 +0100132 ret = snd_soc_of_parse_audio_routing(card, "ti,audio-routing");
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300133 if (ret)
134 return ret;
135 } else {
136 /* Set up davinci-evm specific audio path audio_map */
Lars-Peter Clausend343a662014-03-12 15:27:35 +0100137 snd_soc_dapm_add_routes(&card->dapm, audio_map,
138 ARRAY_SIZE(audio_map));
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300139 }
Vladimir Barinov310355c2008-02-18 11:40:22 +0100140
141 /* not connected */
Lars-Peter Clausend343a662014-03-12 15:27:35 +0100142 snd_soc_dapm_nc_pin(&codec->dapm, "MONO_LOUT");
143 snd_soc_dapm_nc_pin(&codec->dapm, "HPLCOM");
144 snd_soc_dapm_nc_pin(&codec->dapm, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100145
Vladimir Barinov310355c2008-02-18 11:40:22 +0100146 return 0;
147}
148
149/* davinci-evm digital audio interface glue - connects codec <--> CPU */
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000150static struct snd_soc_dai_link dm6446_evm_dai = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100151 .name = "TLV320AIC3X",
152 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000153 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000154 .codec_dai_name = "tlv320aic3x-hifi",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000155 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530156 .platform_name = "davinci-mcbsp",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000157 .init = evm_aic3x_init,
158 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200159 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
160 SND_SOC_DAIFMT_IB_NF,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000161};
162
163static struct snd_soc_dai_link dm355_evm_dai = {
164 .name = "TLV320AIC3X",
165 .stream_name = "AIC3X",
166 .cpu_dai_name = "davinci-mcbsp.1",
167 .codec_dai_name = "tlv320aic3x-hifi",
168 .codec_name = "tlv320aic3x-codec.1-001b",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530169 .platform_name = "davinci-mcbsp.1",
Vladimir Barinov310355c2008-02-18 11:40:22 +0100170 .init = evm_aic3x_init,
171 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200172 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
173 SND_SOC_DAIFMT_IB_NF,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100174};
175
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600176static struct snd_soc_dai_link dm365_evm_dai = {
177#ifdef CONFIG_SND_DM365_AIC3X_CODEC
178 .name = "TLV320AIC3X",
179 .stream_name = "AIC3X",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000180 .cpu_dai_name = "davinci-mcbsp",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000181 .codec_dai_name = "tlv320aic3x-hifi",
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000182 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530183 .platform_name = "davinci-mcbsp",
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200184 .init = evm_aic3x_init,
185 .ops = &evm_ops,
186 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
187 SND_SOC_DAIFMT_IB_NF,
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, Gururajaffb690d2012-08-31 18:20:59 +0530194 .platform_name = "davinci-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,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200208 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
209 SND_SOC_DAIFMT_IB_NF,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400210 },
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",
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200218 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
219 SND_SOC_DAIFMT_IB_NF,
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,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200232 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
233 SND_SOC_DAIFMT_IB_NF,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530234};
235
236static struct snd_soc_dai_link da850_evm_dai = {
Chaithrika U S7ae59452009-08-07 10:07:51 -0400237 .name = "TLV320AIC3X",
238 .stream_name = "AIC3X",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000239 .cpu_dai_name= "davinci-mcasp.0",
240 .codec_dai_name = "tlv320aic3x-hifi",
Rajashekhara, Sudhakardc5a4602011-01-21 20:10:01 +0530241 .codec_name = "tlv320aic3x-codec.1-0018",
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530242 .platform_name = "davinci-mcasp.0",
Chaithrika U S7ae59452009-08-07 10:07:51 -0400243 .init = evm_aic3x_init,
244 .ops = &evm_ops,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200245 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
246 SND_SOC_DAIFMT_IB_NF,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400247};
Chaithrika U S04f80f52009-06-05 06:28:49 -0400248
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000249/* davinci dm6446 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300250/*
251 * ASP0 in DM6446 EVM is clocked by U55, as configured by
252 * board-dm644x-evm.c using GPIOs from U18. There are six
253 * options; here we "know" we use a 48 KHz sample rate.
254 */
255static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata = {
256 .sysclk = 12288000,
257};
258
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000259static struct snd_soc_card dm6446_snd_soc_card_evm = {
260 .name = "DaVinci DM6446 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800261 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000262 .dai_link = &dm6446_evm_dai,
263 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300264 .drvdata = &dm6446_snd_soc_card_drvdata,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000265};
266
267/* davinci dm355 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300268/* ASP1 on DM355 EVM is clocked by an external oscillator */
269static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata = {
270 .sysclk = 27000000,
271};
272
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000273static struct snd_soc_card dm355_snd_soc_card_evm = {
274 .name = "DaVinci DM355 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800275 .owner = THIS_MODULE,
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000276 .dai_link = &dm355_evm_dai,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100277 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300278 .drvdata = &dm355_snd_soc_card_drvdata,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100279};
280
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600281/* davinci dm365 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300282static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata = {
283 .sysclk = 27000000,
284};
285
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600286static struct snd_soc_card dm365_snd_soc_card_evm = {
287 .name = "DaVinci DM365 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800288 .owner = THIS_MODULE,
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600289 .dai_link = &dm365_evm_dai,
290 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300291 .drvdata = &dm365_snd_soc_card_drvdata,
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600292};
293
Chaithrika U S04f80f52009-06-05 06:28:49 -0400294/* davinci dm6467 evm audio machine driver */
Jyri Sarhabcf25562013-09-17 12:26:00 +0300295static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata = {
296 .sysclk = 27000000,
297};
298
Chaithrika U S04f80f52009-06-05 06:28:49 -0400299static struct snd_soc_card dm6467_snd_soc_card_evm = {
300 .name = "DaVinci DM6467 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800301 .owner = THIS_MODULE,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400302 .dai_link = dm6467_evm_dai,
303 .num_links = ARRAY_SIZE(dm6467_evm_dai),
Jyri Sarhabcf25562013-09-17 12:26:00 +0300304 .drvdata = &dm6467_snd_soc_card_drvdata,
305};
306
307static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata = {
308 .sysclk = 24576000,
Chaithrika U S04f80f52009-06-05 06:28:49 -0400309};
310
Chaithrika U S7ae59452009-08-07 10:07:51 -0400311static struct snd_soc_card da830_snd_soc_card = {
Chaithrika U S30230f42009-08-11 16:59:21 -0400312 .name = "DA830/OMAP-L137 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800313 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530314 .dai_link = &da830_evm_dai,
Chaithrika U S30230f42009-08-11 16:59:21 -0400315 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300316 .drvdata = &da830_snd_soc_card_drvdata,
317};
318
319static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata = {
320 .sysclk = 24576000,
Chaithrika U S30230f42009-08-11 16:59:21 -0400321};
322
323static struct snd_soc_card da850_snd_soc_card = {
324 .name = "DA850/OMAP-L138 EVM",
Axel Lin36a16d12011-12-22 21:19:42 +0800325 .owner = THIS_MODULE,
Vaibhav Bediaf9eb9dd2011-02-03 16:42:25 +0530326 .dai_link = &da850_evm_dai,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400327 .num_links = 1,
Jyri Sarhabcf25562013-09-17 12:26:00 +0300328 .drvdata = &da850_snd_soc_card_drvdata,
Chaithrika U S7ae59452009-08-07 10:07:51 -0400329};
330
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300331#if defined(CONFIG_OF)
332
333/*
334 * The struct is used as place holder. It will be completely
335 * filled with data from dt node.
336 */
337static struct snd_soc_dai_link evm_dai_tlv320aic3x = {
338 .name = "TLV320AIC3X",
339 .stream_name = "AIC3X",
340 .codec_dai_name = "tlv320aic3x-hifi",
341 .ops = &evm_ops,
342 .init = evm_aic3x_init,
Peter Ujfalusid38970e2013-11-14 11:35:21 +0200343 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM |
344 SND_SOC_DAIFMT_IB_NF,
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300345};
346
347static const struct of_device_id davinci_evm_dt_ids[] = {
348 {
349 .compatible = "ti,da830-evm-audio",
350 .data = (void *) &evm_dai_tlv320aic3x,
351 },
352 { /* sentinel */ }
353};
354MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids);
355
356/* davinci evm audio machine driver */
357static struct snd_soc_card evm_soc_card = {
358 .owner = THIS_MODULE,
359 .num_links = 1,
360};
361
362static int davinci_evm_probe(struct platform_device *pdev)
363{
364 struct device_node *np = pdev->dev.of_node;
365 const struct of_device_id *match =
366 of_match_device(of_match_ptr(davinci_evm_dt_ids), &pdev->dev);
367 struct snd_soc_dai_link *dai = (struct snd_soc_dai_link *) match->data;
368 struct snd_soc_card_drvdata_davinci *drvdata = NULL;
Jyri Sarha5ad88652014-01-27 17:37:51 +0200369 struct clk *mclk;
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300370 int ret = 0;
371
372 evm_soc_card.dai_link = dai;
373
374 dai->codec_of_node = of_parse_phandle(np, "ti,audio-codec", 0);
375 if (!dai->codec_of_node)
376 return -EINVAL;
377
378 dai->cpu_of_node = of_parse_phandle(np, "ti,mcasp-controller", 0);
379 if (!dai->cpu_of_node)
380 return -EINVAL;
381
382 dai->platform_of_node = dai->cpu_of_node;
383
384 evm_soc_card.dev = &pdev->dev;
385 ret = snd_soc_of_parse_card_name(&evm_soc_card, "ti,model");
386 if (ret)
387 return ret;
388
Jyri Sarha5ad88652014-01-27 17:37:51 +0200389 mclk = devm_clk_get(&pdev->dev, "mclk");
390 if (PTR_ERR(mclk) == -EPROBE_DEFER) {
391 return -EPROBE_DEFER;
392 } else if (IS_ERR(mclk)) {
393 dev_dbg(&pdev->dev, "mclk not found.\n");
394 mclk = NULL;
395 }
396
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300397 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
398 if (!drvdata)
399 return -ENOMEM;
400
Jyri Sarha5ad88652014-01-27 17:37:51 +0200401 drvdata->mclk = mclk;
402
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300403 ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk);
Jyri Sarha5ad88652014-01-27 17:37:51 +0200404
405 if (ret < 0) {
406 if (!drvdata->mclk) {
407 dev_err(&pdev->dev,
408 "No clock or clock rate defined.\n");
409 return -EINVAL;
410 }
411 drvdata->sysclk = clk_get_rate(drvdata->mclk);
412 } else if (drvdata->mclk) {
413 unsigned int requestd_rate = drvdata->sysclk;
414 clk_set_rate(drvdata->mclk, drvdata->sysclk);
415 drvdata->sysclk = clk_get_rate(drvdata->mclk);
416 if (drvdata->sysclk != requestd_rate)
417 dev_warn(&pdev->dev,
418 "Could not get requested rate %u using %u.\n",
419 requestd_rate, drvdata->sysclk);
420 }
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300421
422 snd_soc_card_set_drvdata(&evm_soc_card, drvdata);
423 ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card);
424
425 if (ret)
426 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
427
428 return ret;
429}
430
431static int davinci_evm_remove(struct platform_device *pdev)
432{
433 struct snd_soc_card *card = platform_get_drvdata(pdev);
434
435 snd_soc_unregister_card(card);
436
437 return 0;
438}
439
440static struct platform_driver davinci_evm_driver = {
441 .probe = davinci_evm_probe,
442 .remove = davinci_evm_remove,
443 .driver = {
444 .name = "davinci_evm",
Peter Ujfalusifb6d2082014-01-30 15:21:31 +0200445 .pm = &snd_soc_pm_ops,
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300446 .of_match_table = of_match_ptr(davinci_evm_dt_ids),
447 },
448};
449#endif
450
Vladimir Barinov310355c2008-02-18 11:40:22 +0100451static struct platform_device *evm_snd_device;
452
453static int __init evm_init(void)
454{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000455 struct snd_soc_card *evm_snd_dev_data;
David Brownellf492ec92009-05-14 13:01:59 -0700456 int index;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100457 int ret;
458
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300459 /*
460 * If dtb is there, the devices will be created dynamically.
461 * Only register platfrom driver structure.
462 */
463#if defined(CONFIG_OF)
464 if (of_have_populated_dt())
465 return platform_driver_register(&davinci_evm_driver);
466#endif
467
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600468 if (machine_is_davinci_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000469 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700470 index = 0;
471 } else if (machine_is_davinci_dm355_evm()) {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000472 evm_snd_dev_data = &dm355_snd_soc_card_evm;
David Brownellf492ec92009-05-14 13:01:59 -0700473 index = 1;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600474 } else if (machine_is_davinci_dm365_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000475 evm_snd_dev_data = &dm365_snd_soc_card_evm;
Miguel Aguilaraa9b88e2010-03-11 09:33:40 -0600476 index = 0;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400477 } else if (machine_is_davinci_dm6467_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000478 evm_snd_dev_data = &dm6467_snd_soc_card_evm;
Chaithrika U S04f80f52009-06-05 06:28:49 -0400479 index = 0;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400480 } else if (machine_is_davinci_da830_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000481 evm_snd_dev_data = &da830_snd_soc_card;
Chaithrika U S7ae59452009-08-07 10:07:51 -0400482 index = 1;
Chaithrika U S30230f42009-08-11 16:59:21 -0400483 } else if (machine_is_davinci_da850_evm()) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000484 evm_snd_dev_data = &da850_snd_soc_card;
Chaithrika U S30230f42009-08-11 16:59:21 -0400485 index = 0;
David Brownellf492ec92009-05-14 13:01:59 -0700486 } else
487 return -EINVAL;
488
489 evm_snd_device = platform_device_alloc("soc-audio", index);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100490 if (!evm_snd_device)
491 return -ENOMEM;
492
Chaithrika U S04f80f52009-06-05 06:28:49 -0400493 platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100494 ret = platform_device_add(evm_snd_device);
495 if (ret)
496 platform_device_put(evm_snd_device);
497
498 return ret;
499}
500
501static void __exit evm_exit(void)
502{
Hebbar, Gururajaee2f6152013-10-23 15:30:14 +0300503#if defined(CONFIG_OF)
504 if (of_have_populated_dt()) {
505 platform_driver_unregister(&davinci_evm_driver);
506 return;
507 }
508#endif
509
Vladimir Barinov310355c2008-02-18 11:40:22 +0100510 platform_device_unregister(evm_snd_device);
511}
512
513module_init(evm_init);
514module_exit(evm_exit);
515
516MODULE_AUTHOR("Vladimir Barinov");
517MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
518MODULE_LICENSE("GPL");