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