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