Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ASoC driver for TI DAVINCI EVM platform |
| 3 | * |
Vladimir Barinov | d6b5203 | 2008-09-29 23:14:11 +0400 | [diff] [blame] | 4 | * Author: Vladimir Barinov, <vbarinov@embeddedalley.com> |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 5 | * 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 Dooks | aa6b904 | 2009-08-20 22:50:42 +0100 | [diff] [blame] | 17 | #include <linux/i2c.h> |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 18 | #include <linux/of_platform.h> |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 19 | #include <linux/clk.h> |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 20 | #include <sound/core.h> |
| 21 | #include <sound/pcm.h> |
| 22 | #include <sound/soc.h> |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 23 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 24 | #include <asm/dma.h> |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 25 | #include <asm/mach-types.h> |
| 26 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 27 | #include "davinci-pcm.h" |
| 28 | #include "davinci-i2s.h" |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 29 | |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 30 | struct snd_soc_card_drvdata_davinci { |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 31 | struct clk *mclk; |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 32 | unsigned sysclk; |
| 33 | }; |
| 34 | |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 35 | static int evm_startup(struct snd_pcm_substream *substream) |
| 36 | { |
| 37 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Lars-Peter Clausen | 2896b8b4 | 2014-05-19 11:41:47 +0200 | [diff] [blame] | 38 | struct snd_soc_card *soc_card = rtd->card; |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 39 | 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 | |
| 48 | static void evm_shutdown(struct snd_pcm_substream *substream) |
| 49 | { |
| 50 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Lars-Peter Clausen | 2896b8b4 | 2014-05-19 11:41:47 +0200 | [diff] [blame] | 51 | struct snd_soc_card *soc_card = rtd->card; |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 52 | 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 Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 59 | static 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 Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 63 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 64 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Lars-Peter Clausen | 2896b8b4 | 2014-05-19 11:41:47 +0200 | [diff] [blame] | 65 | struct snd_soc_card *soc_card = rtd->card; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 66 | int ret = 0; |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 67 | unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *) |
| 68 | snd_soc_card_get_drvdata(soc_card))->sysclk; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 69 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 70 | /* set the codec system clock */ |
David Brownell | 05d5e99 | 2009-01-04 02:50:10 -0800 | [diff] [blame] | 71 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 72 | if (ret < 0) |
| 73 | return ret; |
| 74 | |
Daniel Mack | 5b66aa2 | 2012-10-04 15:08:41 +0200 | [diff] [blame] | 75 | /* 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 Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static struct snd_soc_ops evm_ops = { |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 84 | .startup = evm_startup, |
| 85 | .shutdown = evm_shutdown, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 86 | .hw_params = evm_hw_params, |
| 87 | }; |
| 88 | |
| 89 | /* davinci-evm machine dapm widgets */ |
| 90 | static 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 Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 98 | static const struct snd_soc_dapm_route audio_map[] = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 99 | /* 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 Gururaja | e2e8bfd | 2013-01-31 18:23:04 +0530 | [diff] [blame] | 108 | {"MIC3L", NULL, "Mic Bias"}, |
| 109 | {"MIC3R", NULL, "Mic Bias"}, |
| 110 | {"Mic Bias", NULL, "Mic Jack"}, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 111 | |
| 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 Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | /* Logic for a aic3x as connected on a davinci-evm */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 120 | static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 121 | { |
Lars-Peter Clausen | d343a66 | 2014-03-12 15:27:35 +0100 | [diff] [blame] | 122 | struct snd_soc_card *card = rtd->card; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 123 | struct snd_soc_codec *codec = rtd->codec; |
Lars-Peter Clausen | 2896b8b4 | 2014-05-19 11:41:47 +0200 | [diff] [blame] | 124 | struct device_node *np = card->dev->of_node; |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 125 | int ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 126 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 127 | /* Add davinci-evm specific widgets */ |
Lars-Peter Clausen | d343a66 | 2014-03-12 15:27:35 +0100 | [diff] [blame] | 128 | snd_soc_dapm_new_controls(&card->dapm, aic3x_dapm_widgets, |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 129 | ARRAY_SIZE(aic3x_dapm_widgets)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 130 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 131 | if (np) { |
Lars-Peter Clausen | d343a66 | 2014-03-12 15:27:35 +0100 | [diff] [blame] | 132 | ret = snd_soc_of_parse_audio_routing(card, "ti,audio-routing"); |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 133 | if (ret) |
| 134 | return ret; |
| 135 | } else { |
| 136 | /* Set up davinci-evm specific audio path audio_map */ |
Lars-Peter Clausen | d343a66 | 2014-03-12 15:27:35 +0100 | [diff] [blame] | 137 | snd_soc_dapm_add_routes(&card->dapm, audio_map, |
| 138 | ARRAY_SIZE(audio_map)); |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 139 | } |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 140 | |
| 141 | /* not connected */ |
Lars-Peter Clausen | d343a66 | 2014-03-12 15:27:35 +0100 | [diff] [blame] | 142 | 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 Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 145 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | /* davinci-evm digital audio interface glue - connects codec <--> CPU */ |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 150 | static struct snd_soc_dai_link dm6446_evm_dai = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 151 | .name = "TLV320AIC3X", |
| 152 | .stream_name = "AIC3X", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 153 | .cpu_dai_name = "davinci-mcbsp", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 154 | .codec_dai_name = "tlv320aic3x-hifi", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 155 | .codec_name = "tlv320aic3x-codec.1-001b", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 156 | .platform_name = "davinci-mcbsp", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 157 | .init = evm_aic3x_init, |
| 158 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 159 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 160 | SND_SOC_DAIFMT_IB_NF, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | static 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, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 169 | .platform_name = "davinci-mcbsp.1", |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 170 | .init = evm_aic3x_init, |
| 171 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 172 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 173 | SND_SOC_DAIFMT_IB_NF, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 174 | }; |
| 175 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 176 | static struct snd_soc_dai_link dm365_evm_dai = { |
| 177 | #ifdef CONFIG_SND_DM365_AIC3X_CODEC |
| 178 | .name = "TLV320AIC3X", |
| 179 | .stream_name = "AIC3X", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 180 | .cpu_dai_name = "davinci-mcbsp", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 181 | .codec_dai_name = "tlv320aic3x-hifi", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 182 | .codec_name = "tlv320aic3x-codec.1-0018", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 183 | .platform_name = "davinci-mcbsp", |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 184 | .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 Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 188 | #elif defined(CONFIG_SND_DM365_VOICE_CODEC) |
| 189 | .name = "Voice Codec - CQ93VC", |
| 190 | .stream_name = "CQ93", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 191 | .cpu_dai_name = "davinci-vcif", |
| 192 | .codec_dai_name = "cq93vc-hifi", |
| 193 | .codec_name = "cq93vc-codec", |
Hebbar, Gururaja | ffb690d | 2012-08-31 18:20:59 +0530 | [diff] [blame] | 194 | .platform_name = "davinci-vcif", |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 195 | #endif |
| 196 | }; |
| 197 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 198 | static struct snd_soc_dai_link dm6467_evm_dai[] = { |
| 199 | { |
| 200 | .name = "TLV320AIC3X", |
| 201 | .stream_name = "AIC3X", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 202 | .cpu_dai_name= "davinci-mcasp.0", |
| 203 | .codec_dai_name = "tlv320aic3x-hifi", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 204 | .platform_name = "davinci-mcasp.0", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 205 | .codec_name = "tlv320aic3x-codec.0-001a", |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 206 | .init = evm_aic3x_init, |
| 207 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 208 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 209 | SND_SOC_DAIFMT_IB_NF, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 210 | }, |
| 211 | { |
| 212 | .name = "McASP", |
| 213 | .stream_name = "spdif", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 214 | .cpu_dai_name= "davinci-mcasp.1", |
| 215 | .codec_dai_name = "dit-hifi", |
| 216 | .codec_name = "spdif_dit", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 217 | .platform_name = "davinci-mcasp.1", |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 218 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 219 | SND_SOC_DAIFMT_IB_NF, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 220 | }, |
| 221 | }; |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 222 | |
| 223 | static 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, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 229 | .platform_name = "davinci-mcasp.1", |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 230 | .init = evm_aic3x_init, |
| 231 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 232 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 233 | SND_SOC_DAIFMT_IB_NF, |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | static struct snd_soc_dai_link da850_evm_dai = { |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 237 | .name = "TLV320AIC3X", |
| 238 | .stream_name = "AIC3X", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 239 | .cpu_dai_name= "davinci-mcasp.0", |
| 240 | .codec_dai_name = "tlv320aic3x-hifi", |
Rajashekhara, Sudhakar | dc5a460 | 2011-01-21 20:10:01 +0530 | [diff] [blame] | 241 | .codec_name = "tlv320aic3x-codec.1-0018", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 242 | .platform_name = "davinci-mcasp.0", |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 243 | .init = evm_aic3x_init, |
| 244 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 245 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 246 | SND_SOC_DAIFMT_IB_NF, |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 247 | }; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 248 | |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 249 | /* davinci dm6446 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 250 | /* |
| 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 | */ |
| 255 | static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata = { |
| 256 | .sysclk = 12288000, |
| 257 | }; |
| 258 | |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 259 | static struct snd_soc_card dm6446_snd_soc_card_evm = { |
| 260 | .name = "DaVinci DM6446 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 261 | .owner = THIS_MODULE, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 262 | .dai_link = &dm6446_evm_dai, |
| 263 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 264 | .drvdata = &dm6446_snd_soc_card_drvdata, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 265 | }; |
| 266 | |
| 267 | /* davinci dm355 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 268 | /* ASP1 on DM355 EVM is clocked by an external oscillator */ |
| 269 | static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata = { |
| 270 | .sysclk = 27000000, |
| 271 | }; |
| 272 | |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 273 | static struct snd_soc_card dm355_snd_soc_card_evm = { |
| 274 | .name = "DaVinci DM355 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 275 | .owner = THIS_MODULE, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 276 | .dai_link = &dm355_evm_dai, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 277 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 278 | .drvdata = &dm355_snd_soc_card_drvdata, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 279 | }; |
| 280 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 281 | /* davinci dm365 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 282 | static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata = { |
| 283 | .sysclk = 27000000, |
| 284 | }; |
| 285 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 286 | static struct snd_soc_card dm365_snd_soc_card_evm = { |
| 287 | .name = "DaVinci DM365 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 288 | .owner = THIS_MODULE, |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 289 | .dai_link = &dm365_evm_dai, |
| 290 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 291 | .drvdata = &dm365_snd_soc_card_drvdata, |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 292 | }; |
| 293 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 294 | /* davinci dm6467 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 295 | static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata = { |
| 296 | .sysclk = 27000000, |
| 297 | }; |
| 298 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 299 | static struct snd_soc_card dm6467_snd_soc_card_evm = { |
| 300 | .name = "DaVinci DM6467 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 301 | .owner = THIS_MODULE, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 302 | .dai_link = dm6467_evm_dai, |
| 303 | .num_links = ARRAY_SIZE(dm6467_evm_dai), |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 304 | .drvdata = &dm6467_snd_soc_card_drvdata, |
| 305 | }; |
| 306 | |
| 307 | static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata = { |
| 308 | .sysclk = 24576000, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 309 | }; |
| 310 | |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 311 | static struct snd_soc_card da830_snd_soc_card = { |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 312 | .name = "DA830/OMAP-L137 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 313 | .owner = THIS_MODULE, |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 314 | .dai_link = &da830_evm_dai, |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 315 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 316 | .drvdata = &da830_snd_soc_card_drvdata, |
| 317 | }; |
| 318 | |
| 319 | static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata = { |
| 320 | .sysclk = 24576000, |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 321 | }; |
| 322 | |
| 323 | static struct snd_soc_card da850_snd_soc_card = { |
| 324 | .name = "DA850/OMAP-L138 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 325 | .owner = THIS_MODULE, |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 326 | .dai_link = &da850_evm_dai, |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 327 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 328 | .drvdata = &da850_snd_soc_card_drvdata, |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 329 | }; |
| 330 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 331 | #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 | */ |
| 337 | static 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 Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 343 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 344 | SND_SOC_DAIFMT_IB_NF, |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | static 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 | }; |
| 354 | MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids); |
| 355 | |
| 356 | /* davinci evm audio machine driver */ |
| 357 | static struct snd_soc_card evm_soc_card = { |
| 358 | .owner = THIS_MODULE, |
| 359 | .num_links = 1, |
| 360 | }; |
| 361 | |
| 362 | static 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 Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 369 | struct clk *mclk; |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 370 | 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 Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 389 | 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, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 397 | drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); |
| 398 | if (!drvdata) |
| 399 | return -ENOMEM; |
| 400 | |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 401 | drvdata->mclk = mclk; |
| 402 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 403 | ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk); |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 404 | |
| 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, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 421 | |
| 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 | |
| 431 | static 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 | |
| 440 | static struct platform_driver davinci_evm_driver = { |
| 441 | .probe = davinci_evm_probe, |
| 442 | .remove = davinci_evm_remove, |
| 443 | .driver = { |
| 444 | .name = "davinci_evm", |
Peter Ujfalusi | fb6d208 | 2014-01-30 15:21:31 +0200 | [diff] [blame] | 445 | .pm = &snd_soc_pm_ops, |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 446 | .of_match_table = of_match_ptr(davinci_evm_dt_ids), |
| 447 | }, |
| 448 | }; |
| 449 | #endif |
| 450 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 451 | static struct platform_device *evm_snd_device; |
| 452 | |
| 453 | static int __init evm_init(void) |
| 454 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 455 | struct snd_soc_card *evm_snd_dev_data; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 456 | int index; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 457 | int ret; |
| 458 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 459 | /* |
| 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 Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 468 | if (machine_is_davinci_evm()) { |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 469 | evm_snd_dev_data = &dm6446_snd_soc_card_evm; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 470 | index = 0; |
| 471 | } else if (machine_is_davinci_dm355_evm()) { |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 472 | evm_snd_dev_data = &dm355_snd_soc_card_evm; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 473 | index = 1; |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 474 | } else if (machine_is_davinci_dm365_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 475 | evm_snd_dev_data = &dm365_snd_soc_card_evm; |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 476 | index = 0; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 477 | } else if (machine_is_davinci_dm6467_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 478 | evm_snd_dev_data = &dm6467_snd_soc_card_evm; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 479 | index = 0; |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 480 | } else if (machine_is_davinci_da830_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 481 | evm_snd_dev_data = &da830_snd_soc_card; |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 482 | index = 1; |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 483 | } else if (machine_is_davinci_da850_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 484 | evm_snd_dev_data = &da850_snd_soc_card; |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 485 | index = 0; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 486 | } else |
| 487 | return -EINVAL; |
| 488 | |
| 489 | evm_snd_device = platform_device_alloc("soc-audio", index); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 490 | if (!evm_snd_device) |
| 491 | return -ENOMEM; |
| 492 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 493 | platform_set_drvdata(evm_snd_device, evm_snd_dev_data); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 494 | ret = platform_device_add(evm_snd_device); |
| 495 | if (ret) |
| 496 | platform_device_put(evm_snd_device); |
| 497 | |
| 498 | return ret; |
| 499 | } |
| 500 | |
| 501 | static void __exit evm_exit(void) |
| 502 | { |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 503 | #if defined(CONFIG_OF) |
| 504 | if (of_have_populated_dt()) { |
| 505 | platform_driver_unregister(&davinci_evm_driver); |
| 506 | return; |
| 507 | } |
| 508 | #endif |
| 509 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 510 | platform_device_unregister(evm_snd_device); |
| 511 | } |
| 512 | |
| 513 | module_init(evm_init); |
| 514 | module_exit(evm_exit); |
| 515 | |
| 516 | MODULE_AUTHOR("Vladimir Barinov"); |
| 517 | MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver"); |
| 518 | MODULE_LICENSE("GPL"); |