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" |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 31 | #include "davinci-mcasp.h" |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 32 | |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 33 | struct snd_soc_card_drvdata_davinci { |
| 34 | unsigned sysclk; |
| 35 | }; |
| 36 | |
Troy Kisky | d6f8339 | 2008-12-19 13:05:25 -0700 | [diff] [blame] | 37 | #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \ |
| 38 | SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 39 | static int evm_hw_params(struct snd_pcm_substream *substream, |
| 40 | struct snd_pcm_hw_params *params) |
| 41 | { |
| 42 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 43 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 44 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 45 | struct snd_soc_codec *codec = rtd->codec; |
| 46 | struct snd_soc_card *soc_card = codec->card; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 47 | int ret = 0; |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 48 | unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *) |
| 49 | snd_soc_card_get_drvdata(soc_card))->sysclk; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 50 | |
| 51 | /* set codec DAI configuration */ |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 52 | ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 53 | if (ret < 0) |
| 54 | return ret; |
| 55 | |
| 56 | /* set cpu DAI configuration */ |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 57 | ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 58 | if (ret < 0) |
| 59 | return ret; |
| 60 | |
| 61 | /* set the codec system clock */ |
David Brownell | 05d5e99 | 2009-01-04 02:50:10 -0800 | [diff] [blame] | 62 | 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] | 63 | if (ret < 0) |
| 64 | return ret; |
| 65 | |
Daniel Mack | 5b66aa2 | 2012-10-04 15:08:41 +0200 | [diff] [blame] | 66 | /* set the CPU system clock */ |
| 67 | ret = snd_soc_dai_set_sysclk(cpu_dai, 0, sysclk, SND_SOC_CLOCK_OUT); |
| 68 | if (ret < 0) |
| 69 | return ret; |
| 70 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 71 | return 0; |
| 72 | } |
| 73 | |
Chaithrika U S | 8d43d1b | 2010-03-10 14:48:33 +0530 | [diff] [blame] | 74 | static int evm_spdif_hw_params(struct snd_pcm_substream *substream, |
| 75 | struct snd_pcm_hw_params *params) |
| 76 | { |
| 77 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 78 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Chaithrika U S | 8d43d1b | 2010-03-10 14:48:33 +0530 | [diff] [blame] | 79 | |
| 80 | /* set cpu DAI configuration */ |
| 81 | return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT); |
| 82 | } |
| 83 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 84 | static struct snd_soc_ops evm_ops = { |
| 85 | .hw_params = evm_hw_params, |
| 86 | }; |
| 87 | |
Chaithrika U S | 8d43d1b | 2010-03-10 14:48:33 +0530 | [diff] [blame] | 88 | static struct snd_soc_ops evm_spdif_ops = { |
| 89 | .hw_params = evm_spdif_hw_params, |
| 90 | }; |
| 91 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 92 | /* davinci-evm machine dapm widgets */ |
| 93 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { |
| 94 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 95 | SND_SOC_DAPM_LINE("Line Out", NULL), |
| 96 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 97 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 98 | }; |
| 99 | |
| 100 | /* davinci-evm machine audio_mapnections to the codec pins */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 101 | static const struct snd_soc_dapm_route audio_map[] = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 102 | /* Headphone connected to HPLOUT, HPROUT */ |
| 103 | {"Headphone Jack", NULL, "HPLOUT"}, |
| 104 | {"Headphone Jack", NULL, "HPROUT"}, |
| 105 | |
| 106 | /* Line Out connected to LLOUT, RLOUT */ |
| 107 | {"Line Out", NULL, "LLOUT"}, |
| 108 | {"Line Out", NULL, "RLOUT"}, |
| 109 | |
| 110 | /* Mic connected to (MIC3L | MIC3R) */ |
Hebbar Gururaja | e2e8bfd | 2013-01-31 18:23:04 +0530 | [diff] [blame] | 111 | {"MIC3L", NULL, "Mic Bias"}, |
| 112 | {"MIC3R", NULL, "Mic Bias"}, |
| 113 | {"Mic Bias", NULL, "Mic Jack"}, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 114 | |
| 115 | /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */ |
| 116 | {"LINE1L", NULL, "Line In"}, |
| 117 | {"LINE2L", NULL, "Line In"}, |
| 118 | {"LINE1R", NULL, "Line In"}, |
| 119 | {"LINE2R", NULL, "Line In"}, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | /* Logic for a aic3x as connected on a davinci-evm */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 123 | static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 124 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 125 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 126 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 127 | struct device_node *np = codec->card->dev->of_node; |
| 128 | int ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 129 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 130 | /* Add davinci-evm specific widgets */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 131 | snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets, |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 132 | ARRAY_SIZE(aic3x_dapm_widgets)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 133 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 134 | if (np) { |
| 135 | ret = snd_soc_of_parse_audio_routing(codec->card, |
| 136 | "ti,audio-routing"); |
| 137 | if (ret) |
| 138 | return ret; |
| 139 | } else { |
| 140 | /* Set up davinci-evm specific audio path audio_map */ |
| 141 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
| 142 | } |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 143 | |
| 144 | /* not connected */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 145 | snd_soc_dapm_disable_pin(dapm, "MONO_LOUT"); |
| 146 | snd_soc_dapm_disable_pin(dapm, "HPLCOM"); |
| 147 | snd_soc_dapm_disable_pin(dapm, "HPRCOM"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 148 | |
| 149 | /* always connected */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 150 | snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); |
| 151 | snd_soc_dapm_enable_pin(dapm, "Line Out"); |
| 152 | snd_soc_dapm_enable_pin(dapm, "Mic Jack"); |
| 153 | snd_soc_dapm_enable_pin(dapm, "Line In"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 154 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | /* davinci-evm digital audio interface glue - connects codec <--> CPU */ |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 159 | static struct snd_soc_dai_link dm6446_evm_dai = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 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-001b", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 165 | .platform_name = "davinci-mcbsp", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 166 | .init = evm_aic3x_init, |
| 167 | .ops = &evm_ops, |
| 168 | }; |
| 169 | |
| 170 | static struct snd_soc_dai_link dm355_evm_dai = { |
| 171 | .name = "TLV320AIC3X", |
| 172 | .stream_name = "AIC3X", |
| 173 | .cpu_dai_name = "davinci-mcbsp.1", |
| 174 | .codec_dai_name = "tlv320aic3x-hifi", |
| 175 | .codec_name = "tlv320aic3x-codec.1-001b", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 176 | .platform_name = "davinci-mcbsp.1", |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 177 | .init = evm_aic3x_init, |
| 178 | .ops = &evm_ops, |
| 179 | }; |
| 180 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 181 | static struct snd_soc_dai_link dm365_evm_dai = { |
| 182 | #ifdef CONFIG_SND_DM365_AIC3X_CODEC |
| 183 | .name = "TLV320AIC3X", |
| 184 | .stream_name = "AIC3X", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 185 | .cpu_dai_name = "davinci-mcbsp", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 186 | .codec_dai_name = "tlv320aic3x-hifi", |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 187 | .init = evm_aic3x_init, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 188 | .codec_name = "tlv320aic3x-codec.1-0018", |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 189 | .ops = &evm_ops, |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 190 | .platform_name = "davinci-mcbsp", |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 191 | #elif defined(CONFIG_SND_DM365_VOICE_CODEC) |
| 192 | .name = "Voice Codec - CQ93VC", |
| 193 | .stream_name = "CQ93", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 194 | .cpu_dai_name = "davinci-vcif", |
| 195 | .codec_dai_name = "cq93vc-hifi", |
| 196 | .codec_name = "cq93vc-codec", |
Hebbar, Gururaja | ffb690d | 2012-08-31 18:20:59 +0530 | [diff] [blame] | 197 | .platform_name = "davinci-vcif", |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 198 | #endif |
| 199 | }; |
| 200 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 201 | static struct snd_soc_dai_link dm6467_evm_dai[] = { |
| 202 | { |
| 203 | .name = "TLV320AIC3X", |
| 204 | .stream_name = "AIC3X", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 205 | .cpu_dai_name= "davinci-mcasp.0", |
| 206 | .codec_dai_name = "tlv320aic3x-hifi", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 207 | .platform_name = "davinci-mcasp.0", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 208 | .codec_name = "tlv320aic3x-codec.0-001a", |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 209 | .init = evm_aic3x_init, |
| 210 | .ops = &evm_ops, |
| 211 | }, |
| 212 | { |
| 213 | .name = "McASP", |
| 214 | .stream_name = "spdif", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 215 | .cpu_dai_name= "davinci-mcasp.1", |
| 216 | .codec_dai_name = "dit-hifi", |
| 217 | .codec_name = "spdif_dit", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 218 | .platform_name = "davinci-mcasp.1", |
Chaithrika U S | 8d43d1b | 2010-03-10 14:48:33 +0530 | [diff] [blame] | 219 | .ops = &evm_spdif_ops, |
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, |
| 232 | }; |
| 233 | |
| 234 | static struct snd_soc_dai_link da850_evm_dai = { |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 235 | .name = "TLV320AIC3X", |
| 236 | .stream_name = "AIC3X", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 237 | .cpu_dai_name= "davinci-mcasp.0", |
| 238 | .codec_dai_name = "tlv320aic3x-hifi", |
Rajashekhara, Sudhakar | dc5a460 | 2011-01-21 20:10:01 +0530 | [diff] [blame] | 239 | .codec_name = "tlv320aic3x-codec.1-0018", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 240 | .platform_name = "davinci-mcasp.0", |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 241 | .init = evm_aic3x_init, |
| 242 | .ops = &evm_ops, |
| 243 | }; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 244 | |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 245 | /* davinci dm6446 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 246 | /* |
| 247 | * ASP0 in DM6446 EVM is clocked by U55, as configured by |
| 248 | * board-dm644x-evm.c using GPIOs from U18. There are six |
| 249 | * options; here we "know" we use a 48 KHz sample rate. |
| 250 | */ |
| 251 | static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata = { |
| 252 | .sysclk = 12288000, |
| 253 | }; |
| 254 | |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 255 | static struct snd_soc_card dm6446_snd_soc_card_evm = { |
| 256 | .name = "DaVinci DM6446 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 = &dm6446_evm_dai, |
| 259 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 260 | .drvdata = &dm6446_snd_soc_card_drvdata, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | /* davinci dm355 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 264 | /* ASP1 on DM355 EVM is clocked by an external oscillator */ |
| 265 | static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata = { |
| 266 | .sysclk = 27000000, |
| 267 | }; |
| 268 | |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 269 | static struct snd_soc_card dm355_snd_soc_card_evm = { |
| 270 | .name = "DaVinci DM355 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 271 | .owner = THIS_MODULE, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 272 | .dai_link = &dm355_evm_dai, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 273 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 274 | .drvdata = &dm355_snd_soc_card_drvdata, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 275 | }; |
| 276 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 277 | /* davinci dm365 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 278 | static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata = { |
| 279 | .sysclk = 27000000, |
| 280 | }; |
| 281 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 282 | static struct snd_soc_card dm365_snd_soc_card_evm = { |
| 283 | .name = "DaVinci DM365 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 284 | .owner = THIS_MODULE, |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 285 | .dai_link = &dm365_evm_dai, |
| 286 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 287 | .drvdata = &dm365_snd_soc_card_drvdata, |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 288 | }; |
| 289 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 290 | /* davinci dm6467 evm audio machine driver */ |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 291 | static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata = { |
| 292 | .sysclk = 27000000, |
| 293 | }; |
| 294 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 295 | static struct snd_soc_card dm6467_snd_soc_card_evm = { |
| 296 | .name = "DaVinci DM6467 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 297 | .owner = THIS_MODULE, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 298 | .dai_link = dm6467_evm_dai, |
| 299 | .num_links = ARRAY_SIZE(dm6467_evm_dai), |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 300 | .drvdata = &dm6467_snd_soc_card_drvdata, |
| 301 | }; |
| 302 | |
| 303 | static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata = { |
| 304 | .sysclk = 24576000, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 305 | }; |
| 306 | |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 307 | static struct snd_soc_card da830_snd_soc_card = { |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 308 | .name = "DA830/OMAP-L137 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 309 | .owner = THIS_MODULE, |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 310 | .dai_link = &da830_evm_dai, |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 311 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 312 | .drvdata = &da830_snd_soc_card_drvdata, |
| 313 | }; |
| 314 | |
| 315 | static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata = { |
| 316 | .sysclk = 24576000, |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | static struct snd_soc_card da850_snd_soc_card = { |
| 320 | .name = "DA850/OMAP-L138 EVM", |
Axel Lin | 36a16d1 | 2011-12-22 21:19:42 +0800 | [diff] [blame] | 321 | .owner = THIS_MODULE, |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 322 | .dai_link = &da850_evm_dai, |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 323 | .num_links = 1, |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 324 | .drvdata = &da850_snd_soc_card_drvdata, |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 325 | }; |
| 326 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 327 | #if defined(CONFIG_OF) |
| 328 | |
| 329 | /* |
| 330 | * The struct is used as place holder. It will be completely |
| 331 | * filled with data from dt node. |
| 332 | */ |
| 333 | static struct snd_soc_dai_link evm_dai_tlv320aic3x = { |
| 334 | .name = "TLV320AIC3X", |
| 335 | .stream_name = "AIC3X", |
| 336 | .codec_dai_name = "tlv320aic3x-hifi", |
| 337 | .ops = &evm_ops, |
| 338 | .init = evm_aic3x_init, |
| 339 | }; |
| 340 | |
| 341 | static const struct of_device_id davinci_evm_dt_ids[] = { |
| 342 | { |
| 343 | .compatible = "ti,da830-evm-audio", |
| 344 | .data = (void *) &evm_dai_tlv320aic3x, |
| 345 | }, |
| 346 | { /* sentinel */ } |
| 347 | }; |
| 348 | MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids); |
| 349 | |
| 350 | /* davinci evm audio machine driver */ |
| 351 | static struct snd_soc_card evm_soc_card = { |
| 352 | .owner = THIS_MODULE, |
| 353 | .num_links = 1, |
| 354 | }; |
| 355 | |
| 356 | static int davinci_evm_probe(struct platform_device *pdev) |
| 357 | { |
| 358 | struct device_node *np = pdev->dev.of_node; |
| 359 | const struct of_device_id *match = |
| 360 | of_match_device(of_match_ptr(davinci_evm_dt_ids), &pdev->dev); |
| 361 | struct snd_soc_dai_link *dai = (struct snd_soc_dai_link *) match->data; |
| 362 | struct snd_soc_card_drvdata_davinci *drvdata = NULL; |
| 363 | int ret = 0; |
| 364 | |
| 365 | evm_soc_card.dai_link = dai; |
| 366 | |
| 367 | dai->codec_of_node = of_parse_phandle(np, "ti,audio-codec", 0); |
| 368 | if (!dai->codec_of_node) |
| 369 | return -EINVAL; |
| 370 | |
| 371 | dai->cpu_of_node = of_parse_phandle(np, "ti,mcasp-controller", 0); |
| 372 | if (!dai->cpu_of_node) |
| 373 | return -EINVAL; |
| 374 | |
| 375 | dai->platform_of_node = dai->cpu_of_node; |
| 376 | |
| 377 | evm_soc_card.dev = &pdev->dev; |
| 378 | ret = snd_soc_of_parse_card_name(&evm_soc_card, "ti,model"); |
| 379 | if (ret) |
| 380 | return ret; |
| 381 | |
| 382 | drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); |
| 383 | if (!drvdata) |
| 384 | return -ENOMEM; |
| 385 | |
| 386 | ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk); |
| 387 | if (ret < 0) |
| 388 | return -EINVAL; |
| 389 | |
| 390 | snd_soc_card_set_drvdata(&evm_soc_card, drvdata); |
| 391 | ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card); |
| 392 | |
| 393 | if (ret) |
| 394 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); |
| 395 | |
| 396 | return ret; |
| 397 | } |
| 398 | |
| 399 | static int davinci_evm_remove(struct platform_device *pdev) |
| 400 | { |
| 401 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 402 | |
| 403 | snd_soc_unregister_card(card); |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | static struct platform_driver davinci_evm_driver = { |
| 409 | .probe = davinci_evm_probe, |
| 410 | .remove = davinci_evm_remove, |
| 411 | .driver = { |
| 412 | .name = "davinci_evm", |
| 413 | .owner = THIS_MODULE, |
| 414 | .of_match_table = of_match_ptr(davinci_evm_dt_ids), |
| 415 | }, |
| 416 | }; |
| 417 | #endif |
| 418 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 419 | static struct platform_device *evm_snd_device; |
| 420 | |
| 421 | static int __init evm_init(void) |
| 422 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 423 | struct snd_soc_card *evm_snd_dev_data; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 424 | int index; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 425 | int ret; |
| 426 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 427 | /* |
| 428 | * If dtb is there, the devices will be created dynamically. |
| 429 | * Only register platfrom driver structure. |
| 430 | */ |
| 431 | #if defined(CONFIG_OF) |
| 432 | if (of_have_populated_dt()) |
| 433 | return platform_driver_register(&davinci_evm_driver); |
| 434 | #endif |
| 435 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 436 | if (machine_is_davinci_evm()) { |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 437 | evm_snd_dev_data = &dm6446_snd_soc_card_evm; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 438 | index = 0; |
| 439 | } else if (machine_is_davinci_dm355_evm()) { |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 440 | evm_snd_dev_data = &dm355_snd_soc_card_evm; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 441 | index = 1; |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 442 | } else if (machine_is_davinci_dm365_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 443 | evm_snd_dev_data = &dm365_snd_soc_card_evm; |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 444 | index = 0; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 445 | } else if (machine_is_davinci_dm6467_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 446 | evm_snd_dev_data = &dm6467_snd_soc_card_evm; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 447 | index = 0; |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 448 | } else if (machine_is_davinci_da830_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 449 | evm_snd_dev_data = &da830_snd_soc_card; |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 450 | index = 1; |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 451 | } else if (machine_is_davinci_da850_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 452 | evm_snd_dev_data = &da850_snd_soc_card; |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 453 | index = 0; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 454 | } else |
| 455 | return -EINVAL; |
| 456 | |
| 457 | evm_snd_device = platform_device_alloc("soc-audio", index); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 458 | if (!evm_snd_device) |
| 459 | return -ENOMEM; |
| 460 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 461 | platform_set_drvdata(evm_snd_device, evm_snd_dev_data); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 462 | ret = platform_device_add(evm_snd_device); |
| 463 | if (ret) |
| 464 | platform_device_put(evm_snd_device); |
| 465 | |
| 466 | return ret; |
| 467 | } |
| 468 | |
| 469 | static void __exit evm_exit(void) |
| 470 | { |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 471 | #if defined(CONFIG_OF) |
| 472 | if (of_have_populated_dt()) { |
| 473 | platform_driver_unregister(&davinci_evm_driver); |
| 474 | return; |
| 475 | } |
| 476 | #endif |
| 477 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 478 | platform_device_unregister(evm_snd_device); |
| 479 | } |
| 480 | |
| 481 | module_init(evm_init); |
| 482 | module_exit(evm_exit); |
| 483 | |
| 484 | MODULE_AUTHOR("Vladimir Barinov"); |
| 485 | MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver"); |
| 486 | MODULE_LICENSE("GPL"); |