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> |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 18 | #include <sound/core.h> |
| 19 | #include <sound/pcm.h> |
| 20 | #include <sound/soc.h> |
| 21 | #include <sound/soc-dapm.h> |
| 22 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 23 | #include <asm/dma.h> |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 24 | #include <asm/mach-types.h> |
| 25 | |
| 26 | #include <mach/asp.h> |
| 27 | #include <mach/edma.h> |
| 28 | #include <mach/mux.h> |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 29 | |
| 30 | #include "../codecs/tlv320aic3x.h" |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 31 | #include "../codecs/spdif_transciever.h" |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 32 | #include "davinci-pcm.h" |
| 33 | #include "davinci-i2s.h" |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 34 | #include "davinci-mcasp.h" |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 35 | |
Troy Kisky | d6f8339 | 2008-12-19 13:05:25 -0700 | [diff] [blame] | 36 | #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \ |
| 37 | SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 38 | static int evm_hw_params(struct snd_pcm_substream *substream, |
| 39 | struct snd_pcm_hw_params *params) |
| 40 | { |
| 41 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | 9cb132d | 2008-07-07 16:07:42 +0100 | [diff] [blame] | 42 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; |
| 43 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 44 | int ret = 0; |
David Brownell | 05d5e99 | 2009-01-04 02:50:10 -0800 | [diff] [blame] | 45 | unsigned sysclk; |
| 46 | |
| 47 | /* ASP1 on DM355 EVM is clocked by an external oscillator */ |
Miguel Aguilar | 9b95b16 | 2009-09-02 15:33:59 -0600 | [diff] [blame] | 48 | if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() || |
| 49 | machine_is_davinci_dm365_evm()) |
David Brownell | 05d5e99 | 2009-01-04 02:50:10 -0800 | [diff] [blame] | 50 | sysclk = 27000000; |
| 51 | |
| 52 | /* ASP0 in DM6446 EVM is clocked by U55, as configured by |
| 53 | * board-dm644x-evm.c using GPIOs from U18. There are six |
| 54 | * options; here we "know" we use a 48 KHz sample rate. |
| 55 | */ |
| 56 | else if (machine_is_davinci_evm()) |
| 57 | sysclk = 12288000; |
| 58 | |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 59 | else if (machine_is_davinci_da830_evm() || |
| 60 | machine_is_davinci_da850_evm()) |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 61 | sysclk = 24576000; |
| 62 | |
David Brownell | 05d5e99 | 2009-01-04 02:50:10 -0800 | [diff] [blame] | 63 | else |
| 64 | return -EINVAL; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 65 | |
| 66 | /* set codec DAI configuration */ |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 67 | ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 68 | if (ret < 0) |
| 69 | return ret; |
| 70 | |
| 71 | /* set cpu DAI configuration */ |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 72 | ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 73 | if (ret < 0) |
| 74 | return ret; |
| 75 | |
| 76 | /* set the codec system clock */ |
David Brownell | 05d5e99 | 2009-01-04 02:50:10 -0800 | [diff] [blame] | 77 | 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] | 78 | if (ret < 0) |
| 79 | return ret; |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
Chaithrika U S | 8d43d1b | 2010-03-10 14:48:33 +0530 | [diff] [blame^] | 84 | static int evm_spdif_hw_params(struct snd_pcm_substream *substream, |
| 85 | struct snd_pcm_hw_params *params) |
| 86 | { |
| 87 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 88 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
| 89 | |
| 90 | /* set cpu DAI configuration */ |
| 91 | return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT); |
| 92 | } |
| 93 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 94 | static struct snd_soc_ops evm_ops = { |
| 95 | .hw_params = evm_hw_params, |
| 96 | }; |
| 97 | |
Chaithrika U S | 8d43d1b | 2010-03-10 14:48:33 +0530 | [diff] [blame^] | 98 | static struct snd_soc_ops evm_spdif_ops = { |
| 99 | .hw_params = evm_spdif_hw_params, |
| 100 | }; |
| 101 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 102 | /* davinci-evm machine dapm widgets */ |
| 103 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { |
| 104 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 105 | SND_SOC_DAPM_LINE("Line Out", NULL), |
| 106 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 107 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 108 | }; |
| 109 | |
| 110 | /* davinci-evm machine audio_mapnections to the codec pins */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 111 | static const struct snd_soc_dapm_route audio_map[] = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 112 | /* Headphone connected to HPLOUT, HPROUT */ |
| 113 | {"Headphone Jack", NULL, "HPLOUT"}, |
| 114 | {"Headphone Jack", NULL, "HPROUT"}, |
| 115 | |
| 116 | /* Line Out connected to LLOUT, RLOUT */ |
| 117 | {"Line Out", NULL, "LLOUT"}, |
| 118 | {"Line Out", NULL, "RLOUT"}, |
| 119 | |
| 120 | /* Mic connected to (MIC3L | MIC3R) */ |
| 121 | {"MIC3L", NULL, "Mic Bias 2V"}, |
| 122 | {"MIC3R", NULL, "Mic Bias 2V"}, |
| 123 | {"Mic Bias 2V", NULL, "Mic Jack"}, |
| 124 | |
| 125 | /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */ |
| 126 | {"LINE1L", NULL, "Line In"}, |
| 127 | {"LINE2L", NULL, "Line In"}, |
| 128 | {"LINE1R", NULL, "Line In"}, |
| 129 | {"LINE2R", NULL, "Line In"}, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | /* Logic for a aic3x as connected on a davinci-evm */ |
| 133 | static int evm_aic3x_init(struct snd_soc_codec *codec) |
| 134 | { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 135 | /* Add davinci-evm specific widgets */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 136 | snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets, |
| 137 | ARRAY_SIZE(aic3x_dapm_widgets)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 138 | |
| 139 | /* Set up davinci-evm specific audio path audio_map */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 140 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 141 | |
| 142 | /* not connected */ |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 143 | snd_soc_dapm_disable_pin(codec, "MONO_LOUT"); |
| 144 | snd_soc_dapm_disable_pin(codec, "HPLCOM"); |
| 145 | snd_soc_dapm_disable_pin(codec, "HPRCOM"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 146 | |
| 147 | /* always connected */ |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 148 | snd_soc_dapm_enable_pin(codec, "Headphone Jack"); |
| 149 | snd_soc_dapm_enable_pin(codec, "Line Out"); |
| 150 | snd_soc_dapm_enable_pin(codec, "Mic Jack"); |
| 151 | snd_soc_dapm_enable_pin(codec, "Line In"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 152 | |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 153 | snd_soc_dapm_sync(codec); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | /* davinci-evm digital audio interface glue - connects codec <--> CPU */ |
| 159 | static struct snd_soc_dai_link evm_dai = { |
| 160 | .name = "TLV320AIC3X", |
| 161 | .stream_name = "AIC3X", |
| 162 | .cpu_dai = &davinci_i2s_dai, |
| 163 | .codec_dai = &aic3x_dai, |
| 164 | .init = evm_aic3x_init, |
| 165 | .ops = &evm_ops, |
| 166 | }; |
| 167 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 168 | static struct snd_soc_dai_link dm6467_evm_dai[] = { |
| 169 | { |
| 170 | .name = "TLV320AIC3X", |
| 171 | .stream_name = "AIC3X", |
| 172 | .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI], |
| 173 | .codec_dai = &aic3x_dai, |
| 174 | .init = evm_aic3x_init, |
| 175 | .ops = &evm_ops, |
| 176 | }, |
| 177 | { |
| 178 | .name = "McASP", |
| 179 | .stream_name = "spdif", |
| 180 | .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI], |
| 181 | .codec_dai = &dit_stub_dai, |
Chaithrika U S | 8d43d1b | 2010-03-10 14:48:33 +0530 | [diff] [blame^] | 182 | .ops = &evm_spdif_ops, |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 183 | }, |
| 184 | }; |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 185 | static struct snd_soc_dai_link da8xx_evm_dai = { |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 186 | .name = "TLV320AIC3X", |
| 187 | .stream_name = "AIC3X", |
| 188 | .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI], |
| 189 | .codec_dai = &aic3x_dai, |
| 190 | .init = evm_aic3x_init, |
| 191 | .ops = &evm_ops, |
| 192 | }; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 193 | |
Miguel Aguilar | 9b95b16 | 2009-09-02 15:33:59 -0600 | [diff] [blame] | 194 | /* davinci dm6446, dm355 or dm365 evm audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 195 | static struct snd_soc_card snd_soc_card_evm = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 196 | .name = "DaVinci EVM", |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 197 | .platform = &davinci_soc_platform, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 198 | .dai_link = &evm_dai, |
| 199 | .num_links = 1, |
| 200 | }; |
| 201 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 202 | /* davinci dm6467 evm audio machine driver */ |
| 203 | static struct snd_soc_card dm6467_snd_soc_card_evm = { |
| 204 | .name = "DaVinci DM6467 EVM", |
| 205 | .platform = &davinci_soc_platform, |
| 206 | .dai_link = dm6467_evm_dai, |
| 207 | .num_links = ARRAY_SIZE(dm6467_evm_dai), |
| 208 | }; |
| 209 | |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 210 | static struct snd_soc_card da830_snd_soc_card = { |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 211 | .name = "DA830/OMAP-L137 EVM", |
| 212 | .dai_link = &da8xx_evm_dai, |
| 213 | .platform = &davinci_soc_platform, |
| 214 | .num_links = 1, |
| 215 | }; |
| 216 | |
| 217 | static struct snd_soc_card da850_snd_soc_card = { |
| 218 | .name = "DA850/OMAP-L138 EVM", |
| 219 | .dai_link = &da8xx_evm_dai, |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 220 | .platform = &davinci_soc_platform, |
| 221 | .num_links = 1, |
| 222 | }; |
| 223 | |
Chaithrika U S | f4890b5 | 2009-08-25 15:22:21 +0300 | [diff] [blame] | 224 | static struct aic3x_setup_data aic3x_setup; |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 225 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 226 | /* evm audio subsystem */ |
| 227 | static struct snd_soc_device evm_snd_devdata = { |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 228 | .card = &snd_soc_card_evm, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 229 | .codec_dev = &soc_codec_dev_aic3x, |
Chaithrika U S | f4890b5 | 2009-08-25 15:22:21 +0300 | [diff] [blame] | 230 | .codec_data = &aic3x_setup, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 231 | }; |
| 232 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 233 | /* evm audio subsystem */ |
| 234 | static struct snd_soc_device dm6467_evm_snd_devdata = { |
| 235 | .card = &dm6467_snd_soc_card_evm, |
| 236 | .codec_dev = &soc_codec_dev_aic3x, |
Chaithrika U S | f4890b5 | 2009-08-25 15:22:21 +0300 | [diff] [blame] | 237 | .codec_data = &aic3x_setup, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 238 | }; |
| 239 | |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 240 | /* evm audio subsystem */ |
| 241 | static struct snd_soc_device da830_evm_snd_devdata = { |
| 242 | .card = &da830_snd_soc_card, |
| 243 | .codec_dev = &soc_codec_dev_aic3x, |
Chaithrika U S | f4890b5 | 2009-08-25 15:22:21 +0300 | [diff] [blame] | 244 | .codec_data = &aic3x_setup, |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | static struct snd_soc_device da850_evm_snd_devdata = { |
| 248 | .card = &da850_snd_soc_card, |
| 249 | .codec_dev = &soc_codec_dev_aic3x, |
Chaithrika U S | f4890b5 | 2009-08-25 15:22:21 +0300 | [diff] [blame] | 250 | .codec_data = &aic3x_setup, |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 251 | }; |
| 252 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 253 | static struct platform_device *evm_snd_device; |
| 254 | |
| 255 | static int __init evm_init(void) |
| 256 | { |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 257 | struct snd_soc_device *evm_snd_dev_data; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 258 | int index; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 259 | int ret; |
| 260 | |
Miguel Aguilar | 9b95b16 | 2009-09-02 15:33:59 -0600 | [diff] [blame] | 261 | if (machine_is_davinci_evm() || machine_is_davinci_dm365_evm()) { |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 262 | evm_snd_dev_data = &evm_snd_devdata; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 263 | index = 0; |
| 264 | } else if (machine_is_davinci_dm355_evm()) { |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 265 | evm_snd_dev_data = &evm_snd_devdata; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 266 | index = 1; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 267 | } else if (machine_is_davinci_dm6467_evm()) { |
| 268 | evm_snd_dev_data = &dm6467_evm_snd_devdata; |
| 269 | index = 0; |
Chaithrika U S | 7ae5945 | 2009-08-07 10:07:51 -0400 | [diff] [blame] | 270 | } else if (machine_is_davinci_da830_evm()) { |
| 271 | evm_snd_dev_data = &da830_evm_snd_devdata; |
| 272 | index = 1; |
Chaithrika U S | 30230f4 | 2009-08-11 16:59:21 -0400 | [diff] [blame] | 273 | } else if (machine_is_davinci_da850_evm()) { |
| 274 | evm_snd_dev_data = &da850_evm_snd_devdata; |
| 275 | index = 0; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 276 | } else |
| 277 | return -EINVAL; |
| 278 | |
| 279 | evm_snd_device = platform_device_alloc("soc-audio", index); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 280 | if (!evm_snd_device) |
| 281 | return -ENOMEM; |
| 282 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 283 | platform_set_drvdata(evm_snd_device, evm_snd_dev_data); |
| 284 | evm_snd_dev_data->dev = &evm_snd_device->dev; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 285 | ret = platform_device_add(evm_snd_device); |
| 286 | if (ret) |
| 287 | platform_device_put(evm_snd_device); |
| 288 | |
| 289 | return ret; |
| 290 | } |
| 291 | |
| 292 | static void __exit evm_exit(void) |
| 293 | { |
| 294 | platform_device_unregister(evm_snd_device); |
| 295 | } |
| 296 | |
| 297 | module_init(evm_init); |
| 298 | module_exit(evm_exit); |
| 299 | |
| 300 | MODULE_AUTHOR("Vladimir Barinov"); |
| 301 | MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver"); |
| 302 | MODULE_LICENSE("GPL"); |