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 | |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 27 | struct snd_soc_card_drvdata_davinci { |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 28 | struct clk *mclk; |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 29 | unsigned sysclk; |
| 30 | }; |
| 31 | |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 32 | static int evm_startup(struct snd_pcm_substream *substream) |
| 33 | { |
| 34 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Lars-Peter Clausen | 2896b8b4 | 2014-05-19 11:41:47 +0200 | [diff] [blame] | 35 | struct snd_soc_card *soc_card = rtd->card; |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 36 | struct snd_soc_card_drvdata_davinci *drvdata = |
| 37 | snd_soc_card_get_drvdata(soc_card); |
| 38 | |
| 39 | if (drvdata->mclk) |
| 40 | return clk_prepare_enable(drvdata->mclk); |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static void evm_shutdown(struct snd_pcm_substream *substream) |
| 46 | { |
| 47 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Lars-Peter Clausen | 2896b8b4 | 2014-05-19 11:41:47 +0200 | [diff] [blame] | 48 | struct snd_soc_card *soc_card = rtd->card; |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 49 | struct snd_soc_card_drvdata_davinci *drvdata = |
| 50 | snd_soc_card_get_drvdata(soc_card); |
| 51 | |
| 52 | if (drvdata->mclk) |
| 53 | clk_disable_unprepare(drvdata->mclk); |
| 54 | } |
| 55 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 56 | static int evm_hw_params(struct snd_pcm_substream *substream, |
| 57 | struct snd_pcm_hw_params *params) |
| 58 | { |
| 59 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 60 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 61 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Lars-Peter Clausen | 2896b8b4 | 2014-05-19 11:41:47 +0200 | [diff] [blame] | 62 | struct snd_soc_card *soc_card = rtd->card; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 63 | int ret = 0; |
Jyri Sarha | bcf2556 | 2013-09-17 12:26:00 +0300 | [diff] [blame] | 64 | unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *) |
| 65 | snd_soc_card_get_drvdata(soc_card))->sysclk; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 66 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 67 | /* set the codec system clock */ |
David Brownell | 05d5e99 | 2009-01-04 02:50:10 -0800 | [diff] [blame] | 68 | 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] | 69 | if (ret < 0) |
| 70 | return ret; |
| 71 | |
Daniel Mack | 5b66aa2 | 2012-10-04 15:08:41 +0200 | [diff] [blame] | 72 | /* set the CPU system clock */ |
| 73 | ret = snd_soc_dai_set_sysclk(cpu_dai, 0, sysclk, SND_SOC_CLOCK_OUT); |
| 74 | if (ret < 0) |
| 75 | return ret; |
| 76 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | static struct snd_soc_ops evm_ops = { |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 81 | .startup = evm_startup, |
| 82 | .shutdown = evm_shutdown, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 83 | .hw_params = evm_hw_params, |
| 84 | }; |
| 85 | |
| 86 | /* davinci-evm machine dapm widgets */ |
| 87 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { |
| 88 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 89 | SND_SOC_DAPM_LINE("Line Out", NULL), |
| 90 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 91 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 92 | }; |
| 93 | |
| 94 | /* davinci-evm machine audio_mapnections to the codec pins */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 95 | static const struct snd_soc_dapm_route audio_map[] = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 96 | /* Headphone connected to HPLOUT, HPROUT */ |
| 97 | {"Headphone Jack", NULL, "HPLOUT"}, |
| 98 | {"Headphone Jack", NULL, "HPROUT"}, |
| 99 | |
| 100 | /* Line Out connected to LLOUT, RLOUT */ |
| 101 | {"Line Out", NULL, "LLOUT"}, |
| 102 | {"Line Out", NULL, "RLOUT"}, |
| 103 | |
| 104 | /* Mic connected to (MIC3L | MIC3R) */ |
Hebbar Gururaja | e2e8bfd | 2013-01-31 18:23:04 +0530 | [diff] [blame] | 105 | {"MIC3L", NULL, "Mic Bias"}, |
| 106 | {"MIC3R", NULL, "Mic Bias"}, |
| 107 | {"Mic Bias", NULL, "Mic Jack"}, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 108 | |
| 109 | /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */ |
| 110 | {"LINE1L", NULL, "Line In"}, |
| 111 | {"LINE2L", NULL, "Line In"}, |
| 112 | {"LINE1R", NULL, "Line In"}, |
| 113 | {"LINE2R", NULL, "Line In"}, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | /* Logic for a aic3x as connected on a davinci-evm */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 117 | static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 118 | { |
Lars-Peter Clausen | d343a66 | 2014-03-12 15:27:35 +0100 | [diff] [blame] | 119 | struct snd_soc_card *card = rtd->card; |
Lars-Peter Clausen | 2896b8b4 | 2014-05-19 11:41:47 +0200 | [diff] [blame] | 120 | struct device_node *np = card->dev->of_node; |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 121 | int ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 122 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 123 | /* Add davinci-evm specific widgets */ |
Lars-Peter Clausen | d343a66 | 2014-03-12 15:27:35 +0100 | [diff] [blame] | 124 | snd_soc_dapm_new_controls(&card->dapm, aic3x_dapm_widgets, |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 125 | ARRAY_SIZE(aic3x_dapm_widgets)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 126 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 127 | if (np) { |
Lars-Peter Clausen | d343a66 | 2014-03-12 15:27:35 +0100 | [diff] [blame] | 128 | ret = snd_soc_of_parse_audio_routing(card, "ti,audio-routing"); |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 129 | if (ret) |
| 130 | return ret; |
| 131 | } else { |
| 132 | /* Set up davinci-evm specific audio path audio_map */ |
Lars-Peter Clausen | d343a66 | 2014-03-12 15:27:35 +0100 | [diff] [blame] | 133 | snd_soc_dapm_add_routes(&card->dapm, audio_map, |
| 134 | ARRAY_SIZE(audio_map)); |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 135 | } |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 136 | |
| 137 | /* not connected */ |
Lars-Peter Clausen | b213b44 | 2015-04-11 13:11:28 +0200 | [diff] [blame] | 138 | snd_soc_dapm_nc_pin(&card->dapm, "MONO_LOUT"); |
| 139 | snd_soc_dapm_nc_pin(&card->dapm, "HPLCOM"); |
| 140 | snd_soc_dapm_nc_pin(&card->dapm, "HPRCOM"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 141 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | /* davinci-evm digital audio interface glue - connects codec <--> CPU */ |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 146 | static struct snd_soc_dai_link dm6446_evm_dai = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 147 | .name = "TLV320AIC3X", |
| 148 | .stream_name = "AIC3X", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 149 | .cpu_dai_name = "davinci-mcbsp", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 150 | .codec_dai_name = "tlv320aic3x-hifi", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 151 | .codec_name = "tlv320aic3x-codec.1-001b", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 152 | .platform_name = "davinci-mcbsp", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 153 | .init = evm_aic3x_init, |
| 154 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 155 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 156 | SND_SOC_DAIFMT_IB_NF, |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | static struct snd_soc_dai_link dm355_evm_dai = { |
| 160 | .name = "TLV320AIC3X", |
| 161 | .stream_name = "AIC3X", |
| 162 | .cpu_dai_name = "davinci-mcbsp.1", |
| 163 | .codec_dai_name = "tlv320aic3x-hifi", |
| 164 | .codec_name = "tlv320aic3x-codec.1-001b", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 165 | .platform_name = "davinci-mcbsp.1", |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 166 | .init = evm_aic3x_init, |
| 167 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 168 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 169 | SND_SOC_DAIFMT_IB_NF, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 170 | }; |
| 171 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 172 | static struct snd_soc_dai_link dm365_evm_dai = { |
| 173 | #ifdef CONFIG_SND_DM365_AIC3X_CODEC |
| 174 | .name = "TLV320AIC3X", |
| 175 | .stream_name = "AIC3X", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 176 | .cpu_dai_name = "davinci-mcbsp", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 177 | .codec_dai_name = "tlv320aic3x-hifi", |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 178 | .codec_name = "tlv320aic3x-codec.1-0018", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 179 | .platform_name = "davinci-mcbsp", |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 180 | .init = evm_aic3x_init, |
| 181 | .ops = &evm_ops, |
| 182 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 183 | SND_SOC_DAIFMT_IB_NF, |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 184 | #elif defined(CONFIG_SND_DM365_VOICE_CODEC) |
| 185 | .name = "Voice Codec - CQ93VC", |
| 186 | .stream_name = "CQ93", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 187 | .cpu_dai_name = "davinci-vcif", |
| 188 | .codec_dai_name = "cq93vc-hifi", |
| 189 | .codec_name = "cq93vc-codec", |
Hebbar, Gururaja | ffb690d | 2012-08-31 18:20:59 +0530 | [diff] [blame] | 190 | .platform_name = "davinci-vcif", |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 191 | #endif |
| 192 | }; |
| 193 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 194 | static struct snd_soc_dai_link dm6467_evm_dai[] = { |
| 195 | { |
| 196 | .name = "TLV320AIC3X", |
| 197 | .stream_name = "AIC3X", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 198 | .cpu_dai_name= "davinci-mcasp.0", |
| 199 | .codec_dai_name = "tlv320aic3x-hifi", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 200 | .platform_name = "davinci-mcasp.0", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 201 | .codec_name = "tlv320aic3x-codec.0-001a", |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 202 | .init = evm_aic3x_init, |
| 203 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 204 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 205 | SND_SOC_DAIFMT_IB_NF, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 206 | }, |
| 207 | { |
| 208 | .name = "McASP", |
| 209 | .stream_name = "spdif", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 210 | .cpu_dai_name= "davinci-mcasp.1", |
| 211 | .codec_dai_name = "dit-hifi", |
| 212 | .codec_name = "spdif_dit", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 213 | .platform_name = "davinci-mcasp.1", |
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, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 216 | }, |
| 217 | }; |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 218 | |
| 219 | static struct snd_soc_dai_link da830_evm_dai = { |
| 220 | .name = "TLV320AIC3X", |
| 221 | .stream_name = "AIC3X", |
| 222 | .cpu_dai_name = "davinci-mcasp.1", |
| 223 | .codec_dai_name = "tlv320aic3x-hifi", |
| 224 | .codec_name = "tlv320aic3x-codec.1-0018", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 225 | .platform_name = "davinci-mcasp.1", |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 226 | .init = evm_aic3x_init, |
| 227 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 228 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 229 | SND_SOC_DAIFMT_IB_NF, |
Vaibhav Bedia | f9eb9dd | 2011-02-03 16:42:25 +0530 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | static struct snd_soc_dai_link da850_evm_dai = { |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 233 | .name = "TLV320AIC3X", |
| 234 | .stream_name = "AIC3X", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 235 | .cpu_dai_name= "davinci-mcasp.0", |
| 236 | .codec_dai_name = "tlv320aic3x-hifi", |
Rajashekhara, Sudhakar | dc5a460 | 2011-01-21 20:10:01 +0530 | [diff] [blame] | 237 | .codec_name = "tlv320aic3x-codec.1-0018", |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 238 | .platform_name = "davinci-mcasp.0", |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 239 | .init = evm_aic3x_init, |
| 240 | .ops = &evm_ops, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 241 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 242 | SND_SOC_DAIFMT_IB_NF, |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 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, |
Peter Ujfalusi | d38970e | 2013-11-14 11:35:21 +0200 | [diff] [blame] | 339 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | |
| 340 | SND_SOC_DAIFMT_IB_NF, |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 341 | }; |
| 342 | |
| 343 | static const struct of_device_id davinci_evm_dt_ids[] = { |
| 344 | { |
| 345 | .compatible = "ti,da830-evm-audio", |
| 346 | .data = (void *) &evm_dai_tlv320aic3x, |
| 347 | }, |
| 348 | { /* sentinel */ } |
| 349 | }; |
| 350 | MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids); |
| 351 | |
| 352 | /* davinci evm audio machine driver */ |
| 353 | static struct snd_soc_card evm_soc_card = { |
| 354 | .owner = THIS_MODULE, |
| 355 | .num_links = 1, |
| 356 | }; |
| 357 | |
| 358 | static int davinci_evm_probe(struct platform_device *pdev) |
| 359 | { |
| 360 | struct device_node *np = pdev->dev.of_node; |
Shailendra Verma | 3f81d9a | 2017-01-27 16:40:57 +0530 | [diff] [blame] | 361 | const struct of_device_id *match; |
| 362 | struct snd_soc_dai_link *dai; |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 363 | struct snd_soc_card_drvdata_davinci *drvdata = NULL; |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 364 | struct clk *mclk; |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 365 | int ret = 0; |
| 366 | |
Shailendra Verma | 3f81d9a | 2017-01-27 16:40:57 +0530 | [diff] [blame] | 367 | match = of_match_device(of_match_ptr(davinci_evm_dt_ids), &pdev->dev); |
| 368 | if (!match) { |
| 369 | dev_err(&pdev->dev, "Error: No device match found\n"); |
| 370 | return -ENODEV; |
| 371 | } |
| 372 | |
| 373 | dai = (struct snd_soc_dai_link *) match->data; |
| 374 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 375 | evm_soc_card.dai_link = dai; |
| 376 | |
| 377 | dai->codec_of_node = of_parse_phandle(np, "ti,audio-codec", 0); |
| 378 | if (!dai->codec_of_node) |
| 379 | return -EINVAL; |
| 380 | |
| 381 | dai->cpu_of_node = of_parse_phandle(np, "ti,mcasp-controller", 0); |
| 382 | if (!dai->cpu_of_node) |
| 383 | return -EINVAL; |
| 384 | |
| 385 | dai->platform_of_node = dai->cpu_of_node; |
| 386 | |
| 387 | evm_soc_card.dev = &pdev->dev; |
| 388 | ret = snd_soc_of_parse_card_name(&evm_soc_card, "ti,model"); |
| 389 | if (ret) |
| 390 | return ret; |
| 391 | |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 392 | mclk = devm_clk_get(&pdev->dev, "mclk"); |
| 393 | if (PTR_ERR(mclk) == -EPROBE_DEFER) { |
| 394 | return -EPROBE_DEFER; |
| 395 | } else if (IS_ERR(mclk)) { |
| 396 | dev_dbg(&pdev->dev, "mclk not found.\n"); |
| 397 | mclk = NULL; |
| 398 | } |
| 399 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 400 | drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); |
| 401 | if (!drvdata) |
| 402 | return -ENOMEM; |
| 403 | |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 404 | drvdata->mclk = mclk; |
| 405 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 406 | ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk); |
Jyri Sarha | 5ad8865 | 2014-01-27 17:37:51 +0200 | [diff] [blame] | 407 | |
| 408 | if (ret < 0) { |
| 409 | if (!drvdata->mclk) { |
| 410 | dev_err(&pdev->dev, |
| 411 | "No clock or clock rate defined.\n"); |
| 412 | return -EINVAL; |
| 413 | } |
| 414 | drvdata->sysclk = clk_get_rate(drvdata->mclk); |
| 415 | } else if (drvdata->mclk) { |
| 416 | unsigned int requestd_rate = drvdata->sysclk; |
| 417 | clk_set_rate(drvdata->mclk, drvdata->sysclk); |
| 418 | drvdata->sysclk = clk_get_rate(drvdata->mclk); |
| 419 | if (drvdata->sysclk != requestd_rate) |
| 420 | dev_warn(&pdev->dev, |
| 421 | "Could not get requested rate %u using %u.\n", |
| 422 | requestd_rate, drvdata->sysclk); |
| 423 | } |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 424 | |
| 425 | snd_soc_card_set_drvdata(&evm_soc_card, drvdata); |
| 426 | ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card); |
| 427 | |
| 428 | if (ret) |
| 429 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); |
| 430 | |
| 431 | return ret; |
| 432 | } |
| 433 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 434 | static struct platform_driver davinci_evm_driver = { |
| 435 | .probe = davinci_evm_probe, |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 436 | .driver = { |
| 437 | .name = "davinci_evm", |
Peter Ujfalusi | fb6d208 | 2014-01-30 15:21:31 +0200 | [diff] [blame] | 438 | .pm = &snd_soc_pm_ops, |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 439 | .of_match_table = of_match_ptr(davinci_evm_dt_ids), |
| 440 | }, |
| 441 | }; |
| 442 | #endif |
| 443 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 444 | static struct platform_device *evm_snd_device; |
| 445 | |
| 446 | static int __init evm_init(void) |
| 447 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 448 | struct snd_soc_card *evm_snd_dev_data; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 449 | int index; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 450 | int ret; |
| 451 | |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 452 | /* |
| 453 | * If dtb is there, the devices will be created dynamically. |
| 454 | * Only register platfrom driver structure. |
| 455 | */ |
| 456 | #if defined(CONFIG_OF) |
| 457 | if (of_have_populated_dt()) |
| 458 | return platform_driver_register(&davinci_evm_driver); |
| 459 | #endif |
| 460 | |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 461 | if (machine_is_davinci_evm()) { |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 462 | evm_snd_dev_data = &dm6446_snd_soc_card_evm; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 463 | index = 0; |
| 464 | } else if (machine_is_davinci_dm355_evm()) { |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 465 | evm_snd_dev_data = &dm355_snd_soc_card_evm; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 466 | index = 1; |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 467 | } else if (machine_is_davinci_dm365_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 468 | evm_snd_dev_data = &dm365_snd_soc_card_evm; |
Miguel Aguilar | aa9b88e | 2010-03-11 09:33:40 -0600 | [diff] [blame] | 469 | index = 0; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 470 | } else if (machine_is_davinci_dm6467_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 471 | evm_snd_dev_data = &dm6467_snd_soc_card_evm; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 472 | index = 0; |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 473 | } else if (machine_is_davinci_da830_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 474 | evm_snd_dev_data = &da830_snd_soc_card; |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 475 | index = 1; |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 476 | } else if (machine_is_davinci_da850_evm()) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 477 | evm_snd_dev_data = &da850_snd_soc_card; |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 478 | index = 0; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 479 | } else |
| 480 | return -EINVAL; |
| 481 | |
| 482 | evm_snd_device = platform_device_alloc("soc-audio", index); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 483 | if (!evm_snd_device) |
| 484 | return -ENOMEM; |
| 485 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 486 | platform_set_drvdata(evm_snd_device, evm_snd_dev_data); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 487 | ret = platform_device_add(evm_snd_device); |
| 488 | if (ret) |
| 489 | platform_device_put(evm_snd_device); |
| 490 | |
| 491 | return ret; |
| 492 | } |
| 493 | |
| 494 | static void __exit evm_exit(void) |
| 495 | { |
Hebbar, Gururaja | ee2f615 | 2013-10-23 15:30:14 +0300 | [diff] [blame] | 496 | #if defined(CONFIG_OF) |
| 497 | if (of_have_populated_dt()) { |
| 498 | platform_driver_unregister(&davinci_evm_driver); |
| 499 | return; |
| 500 | } |
| 501 | #endif |
| 502 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 503 | platform_device_unregister(evm_snd_device); |
| 504 | } |
| 505 | |
| 506 | module_init(evm_init); |
| 507 | module_exit(evm_exit); |
| 508 | |
| 509 | MODULE_AUTHOR("Vladimir Barinov"); |
| 510 | MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver"); |
| 511 | MODULE_LICENSE("GPL"); |