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> |
Matt Porter | 3ad7a42 | 2013-03-06 11:15:31 -0500 | [diff] [blame] | 17 | #include <linux/platform_data/edma.h> |
Ben Dooks | aa6b904 | 2009-08-20 22:50:42 +0100 | [diff] [blame] | 18 | #include <linux/i2c.h> |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 19 | #include <linux/of_platform.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 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 27 | #include <linux/edma.h> |
| 28 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 29 | #include "davinci-pcm.h" |
| 30 | #include "davinci-i2s.h" |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 31 | |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 32 | struct snd_soc_card_drvdata_davinci { |
| 33 | unsigned sysclk; |
| 34 | }; |
| 35 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 36 | static 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 Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 40 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 41 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 42 | struct snd_soc_codec *codec = rtd->codec; |
| 43 | struct snd_soc_card *soc_card = codec->card; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 44 | int ret = 0; |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 45 | unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *) |
| 46 | snd_soc_card_get_drvdata(soc_card))->sysclk; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 47 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 48 | /* set the codec system clock */ |
David Brownell | 05d5e99 | 2009-01-04 02:50:10 -0800 | [diff] [blame] | 49 | 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] | 50 | if (ret < 0) |
| 51 | return ret; |
| 52 | |
Daniel Mack | 5b66aa2 | 2012-10-04 15:08:41 +0200 | [diff] [blame] | 53 | /* 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 Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static struct snd_soc_ops evm_ops = { |
| 62 | .hw_params = evm_hw_params, |
| 63 | }; |
| 64 | |
| 65 | /* davinci-evm machine dapm widgets */ |
| 66 | static 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 Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 74 | static const struct snd_soc_dapm_route audio_map[] = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 75 | /* 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 Gururaja | e2e8bfd | 2013-01-31 18:23:04 +0530 | [diff] [blame] | 84 | {"MIC3L", NULL, "Mic Bias"}, |
| 85 | {"MIC3R", NULL, "Mic Bias"}, |
| 86 | {"Mic Bias", NULL, "Mic Jack"}, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 87 | |
| 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 Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /* Logic for a aic3x as connected on a davinci-evm */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 96 | static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 97 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 98 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 99 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 100 | struct device_node *np = codec->card->dev->of_node; |
| 101 | int ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 102 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 103 | /* Add davinci-evm specific widgets */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 104 | snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets, |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 105 | ARRAY_SIZE(aic3x_dapm_widgets)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 106 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 107 | 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 Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 116 | |
| 117 | /* not connected */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 118 | 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 Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 121 | |
| 122 | /* always connected */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 123 | 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 Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 127 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /* davinci-evm digital audio interface glue - connects codec <--> CPU */ |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 132 | static struct snd_soc_dai_link dm6446_evm_dai = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 133 | .name = "TLV320AIC3X", |
| 134 | .stream_name = "AIC3X", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 135 | .cpu_dai_name = "davinci-mcbsp", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 136 | .codec_dai_name = "tlv320aic3x-hifi", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 137 | .codec_name = "tlv320aic3x-codec.1-001b", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 138 | .platform_name = "davinci-mcbsp", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 139 | .init = evm_aic3x_init, |
| 140 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 141 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 142 | SND_SOC_DAIFMT_IB_NF, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | static 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, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 151 | .platform_name = "davinci-mcbsp.1", |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 152 | .init = evm_aic3x_init, |
| 153 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 154 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 155 | SND_SOC_DAIFMT_IB_NF, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 156 | }; |
| 157 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 158 | static struct snd_soc_dai_link dm365_evm_dai = { |
| 159 | #ifdef CONFIG_SND_DM365_AIC3X_CODEC |
| 160 | .name = "TLV320AIC3X", |
| 161 | .stream_name = "AIC3X", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 162 | .cpu_dai_name = "davinci-mcbsp", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 163 | .codec_dai_name = "tlv320aic3x-hifi", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 164 | .codec_name = "tlv320aic3x-codec.1-0018", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 165 | .platform_name = "davinci-mcbsp", |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 166 | .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 Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 170 | #elif defined(CONFIG_SND_DM365_VOICE_CODEC) |
| 171 | .name = "Voice Codec - CQ93VC", |
| 172 | .stream_name = "CQ93", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 173 | .cpu_dai_name = "davinci-vcif", |
| 174 | .codec_dai_name = "cq93vc-hifi", |
| 175 | .codec_name = "cq93vc-codec", |
Hebbar, Gururaja | ffb690d | 2012-08-31 18:20:59 +0530 | [diff] [blame] | 176 | .platform_name = "davinci-vcif", |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 177 | #endif |
| 178 | }; |
| 179 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 180 | static struct snd_soc_dai_link dm6467_evm_dai[] = { |
| 181 | { |
| 182 | .name = "TLV320AIC3X", |
| 183 | .stream_name = "AIC3X", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 184 | .cpu_dai_name= "davinci-mcasp.0", |
| 185 | .codec_dai_name = "tlv320aic3x-hifi", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 186 | .platform_name = "davinci-mcasp.0", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 187 | .codec_name = "tlv320aic3x-codec.0-001a", |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 188 | .init = evm_aic3x_init, |
| 189 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 190 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 191 | SND_SOC_DAIFMT_IB_NF, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 192 | }, |
| 193 | { |
| 194 | .name = "McASP", |
| 195 | .stream_name = "spdif", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 196 | .cpu_dai_name= "davinci-mcasp.1", |
| 197 | .codec_dai_name = "dit-hifi", |
| 198 | .codec_name = "spdif_dit", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 199 | .platform_name = "davinci-mcasp.1", |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 200 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 201 | SND_SOC_DAIFMT_IB_NF, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 202 | }, |
| 203 | }; |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 204 | |
| 205 | static 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, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 211 | .platform_name = "davinci-mcasp.1", |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 212 | .init = evm_aic3x_init, |
| 213 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 214 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 215 | SND_SOC_DAIFMT_IB_NF, |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | static struct snd_soc_dai_link da850_evm_dai = { |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 219 | .name = "TLV320AIC3X", |
| 220 | .stream_name = "AIC3X", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 221 | .cpu_dai_name= "davinci-mcasp.0", |
| 222 | .codec_dai_name = "tlv320aic3x-hifi", |
Rajashekhara, Sudhakar | dc5a460 | 2011-01-21 20:10:01 +0530 | [diff] [blame] | 223 | .codec_name = "tlv320aic3x-codec.1-0018", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 224 | .platform_name = "davinci-mcasp.0", |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 225 | .init = evm_aic3x_init, |
| 226 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 227 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 228 | SND_SOC_DAIFMT_IB_NF, |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 229 | }; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 230 | |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 231 | /* davinci dm6446 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 232 | /* |
| 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 | */ |
| 237 | static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata = { |
| 238 | .sysclk = 12288000, |
| 239 | }; |
| 240 | |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 241 | static struct snd_soc_card dm6446_snd_soc_card_evm = { |
| 242 | .name = "DaVinci DM6446 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 243 | .owner = THIS_MODULE, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 244 | .dai_link = &dm6446_evm_dai, |
| 245 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 246 | .drvdata = &dm6446_snd_soc_card_drvdata, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | /* davinci dm355 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 250 | /* ASP1 on DM355 EVM is clocked by an external oscillator */ |
| 251 | static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata = { |
| 252 | .sysclk = 27000000, |
| 253 | }; |
| 254 | |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 255 | static struct snd_soc_card dm355_snd_soc_card_evm = { |
| 256 | .name = "DaVinci DM355 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 257 | .owner = THIS_MODULE, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 258 | .dai_link = &dm355_evm_dai, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 259 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 260 | .drvdata = &dm355_snd_soc_card_drvdata, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 261 | }; |
| 262 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 263 | /* davinci dm365 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 264 | static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata = { |
| 265 | .sysclk = 27000000, |
| 266 | }; |
| 267 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 268 | static struct snd_soc_card dm365_snd_soc_card_evm = { |
| 269 | .name = "DaVinci DM365 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 270 | .owner = THIS_MODULE, |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 271 | .dai_link = &dm365_evm_dai, |
| 272 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 273 | .drvdata = &dm365_snd_soc_card_drvdata, |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 274 | }; |
| 275 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 276 | /* davinci dm6467 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 277 | static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata = { |
| 278 | .sysclk = 27000000, |
| 279 | }; |
| 280 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 281 | static struct snd_soc_card dm6467_snd_soc_card_evm = { |
| 282 | .name = "DaVinci DM6467 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 283 | .owner = THIS_MODULE, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 284 | .dai_link = dm6467_evm_dai, |
| 285 | .num_links = ARRAY_SIZE(dm6467_evm_dai), |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 286 | .drvdata = &dm6467_snd_soc_card_drvdata, |
| 287 | }; |
| 288 | |
| 289 | static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata = { |
| 290 | .sysclk = 24576000, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 291 | }; |
| 292 | |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 293 | static struct snd_soc_card da830_snd_soc_card = { |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 294 | .name = "DA830/OMAP-L137 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 295 | .owner = THIS_MODULE, |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 296 | .dai_link = &da830_evm_dai, |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 297 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 298 | .drvdata = &da830_snd_soc_card_drvdata, |
| 299 | }; |
| 300 | |
| 301 | static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata = { |
| 302 | .sysclk = 24576000, |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | static struct snd_soc_card da850_snd_soc_card = { |
| 306 | .name = "DA850/OMAP-L138 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 307 | .owner = THIS_MODULE, |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 308 | .dai_link = &da850_evm_dai, |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 309 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 310 | .drvdata = &da850_snd_soc_card_drvdata, |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 311 | }; |
| 312 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 313 | #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 | */ |
| 319 | static 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 Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 325 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 326 | SND_SOC_DAIFMT_IB_NF, |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | static 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 | }; |
| 336 | MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids); |
| 337 | |
| 338 | /* davinci evm audio machine driver */ |
| 339 | static struct snd_soc_card evm_soc_card = { |
| 340 | .owner = THIS_MODULE, |
| 341 | .num_links = 1, |
| 342 | }; |
| 343 | |
| 344 | static 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 | |
| 387 | static 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 | |
| 396 | static 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 Ujfalusi | fb6d208 | 2014-01-30 15:21:31 +0200 | [diff] [blame] | 402 | .pm = &snd_soc_pm_ops, |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 403 | .of_match_table = of_match_ptr(davinci_evm_dt_ids), |
| 404 | }, |
| 405 | }; |
| 406 | #endif |
| 407 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 408 | static struct platform_device *evm_snd_device; |
| 409 | |
| 410 | static int __init evm_init(void) |
| 411 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 412 | struct snd_soc_card *evm_snd_dev_data; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 413 | int index; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 414 | int ret; |
| 415 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 416 | /* |
| 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 Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 425 | if (machine_is_davinci_evm()) { |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 426 | evm_snd_dev_data = &dm6446_snd_soc_card_evm; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 427 | index = 0; |
| 428 | } else if (machine_is_davinci_dm355_evm()) { |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 429 | evm_snd_dev_data = &dm355_snd_soc_card_evm; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 430 | index = 1; |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 431 | } else if (machine_is_davinci_dm365_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 432 | evm_snd_dev_data = &dm365_snd_soc_card_evm; |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 433 | index = 0; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 434 | } else if (machine_is_davinci_dm6467_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 435 | evm_snd_dev_data = &dm6467_snd_soc_card_evm; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 436 | index = 0; |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 437 | } else if (machine_is_davinci_da830_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 438 | evm_snd_dev_data = &da830_snd_soc_card; |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 439 | index = 1; |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 440 | } else if (machine_is_davinci_da850_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 441 | evm_snd_dev_data = &da850_snd_soc_card; |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 442 | index = 0; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 443 | } else |
| 444 | return -EINVAL; |
| 445 | |
| 446 | evm_snd_device = platform_device_alloc("soc-audio", index); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 447 | if (!evm_snd_device) |
| 448 | return -ENOMEM; |
| 449 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 450 | platform_set_drvdata(evm_snd_device, evm_snd_dev_data); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 451 | ret = platform_device_add(evm_snd_device); |
| 452 | if (ret) |
| 453 | platform_device_put(evm_snd_device); |
| 454 | |
| 455 | return ret; |
| 456 | } |
| 457 | |
| 458 | static void __exit evm_exit(void) |
| 459 | { |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 460 | #if defined(CONFIG_OF) |
| 461 | if (of_have_populated_dt()) { |
| 462 | platform_driver_unregister(&davinci_evm_driver); |
| 463 | return; |
| 464 | } |
| 465 | #endif |
| 466 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 467 | platform_device_unregister(evm_snd_device); |
| 468 | } |
| 469 | |
| 470 | module_init(evm_init); |
| 471 | module_exit(evm_exit); |
| 472 | |
| 473 | MODULE_AUTHOR("Vladimir Barinov"); |
| 474 | MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver"); |
| 475 | MODULE_LICENSE("GPL"); |