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 | |
| 57 | else |
| 58 | return -EINVAL; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 59 | |
| 60 | /* set codec DAI configuration */ |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 61 | ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 62 | if (ret < 0) |
| 63 | return ret; |
| 64 | |
| 65 | /* set cpu DAI configuration */ |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 66 | ret = snd_soc_dai_set_fmt(cpu_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 the codec system clock */ |
David Brownell | 05d5e99 | 2009-01-04 02:50:10 -0800 | [diff] [blame] | 71 | 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] | 72 | if (ret < 0) |
| 73 | return ret; |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static struct snd_soc_ops evm_ops = { |
| 79 | .hw_params = evm_hw_params, |
| 80 | }; |
| 81 | |
| 82 | /* davinci-evm machine dapm widgets */ |
| 83 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { |
| 84 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 85 | SND_SOC_DAPM_LINE("Line Out", NULL), |
| 86 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 87 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 88 | }; |
| 89 | |
| 90 | /* davinci-evm machine audio_mapnections to the codec pins */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 91 | static const struct snd_soc_dapm_route audio_map[] = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 92 | /* Headphone connected to HPLOUT, HPROUT */ |
| 93 | {"Headphone Jack", NULL, "HPLOUT"}, |
| 94 | {"Headphone Jack", NULL, "HPROUT"}, |
| 95 | |
| 96 | /* Line Out connected to LLOUT, RLOUT */ |
| 97 | {"Line Out", NULL, "LLOUT"}, |
| 98 | {"Line Out", NULL, "RLOUT"}, |
| 99 | |
| 100 | /* Mic connected to (MIC3L | MIC3R) */ |
| 101 | {"MIC3L", NULL, "Mic Bias 2V"}, |
| 102 | {"MIC3R", NULL, "Mic Bias 2V"}, |
| 103 | {"Mic Bias 2V", NULL, "Mic Jack"}, |
| 104 | |
| 105 | /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */ |
| 106 | {"LINE1L", NULL, "Line In"}, |
| 107 | {"LINE2L", NULL, "Line In"}, |
| 108 | {"LINE1R", NULL, "Line In"}, |
| 109 | {"LINE2R", NULL, "Line In"}, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | /* Logic for a aic3x as connected on a davinci-evm */ |
| 113 | static int evm_aic3x_init(struct snd_soc_codec *codec) |
| 114 | { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 115 | /* Add davinci-evm specific widgets */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 116 | snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets, |
| 117 | ARRAY_SIZE(aic3x_dapm_widgets)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 118 | |
| 119 | /* Set up davinci-evm specific audio path audio_map */ |
Mark Brown | acf497f | 2008-05-13 14:58:30 +0200 | [diff] [blame] | 120 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 121 | |
| 122 | /* not connected */ |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 123 | snd_soc_dapm_disable_pin(codec, "MONO_LOUT"); |
| 124 | snd_soc_dapm_disable_pin(codec, "HPLCOM"); |
| 125 | snd_soc_dapm_disable_pin(codec, "HPRCOM"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 126 | |
| 127 | /* always connected */ |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 128 | snd_soc_dapm_enable_pin(codec, "Headphone Jack"); |
| 129 | snd_soc_dapm_enable_pin(codec, "Line Out"); |
| 130 | snd_soc_dapm_enable_pin(codec, "Mic Jack"); |
| 131 | snd_soc_dapm_enable_pin(codec, "Line In"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 132 | |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 133 | snd_soc_dapm_sync(codec); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | /* davinci-evm digital audio interface glue - connects codec <--> CPU */ |
| 139 | static struct snd_soc_dai_link evm_dai = { |
| 140 | .name = "TLV320AIC3X", |
| 141 | .stream_name = "AIC3X", |
| 142 | .cpu_dai = &davinci_i2s_dai, |
| 143 | .codec_dai = &aic3x_dai, |
| 144 | .init = evm_aic3x_init, |
| 145 | .ops = &evm_ops, |
| 146 | }; |
| 147 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 148 | static struct snd_soc_dai_link dm6467_evm_dai[] = { |
| 149 | { |
| 150 | .name = "TLV320AIC3X", |
| 151 | .stream_name = "AIC3X", |
| 152 | .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI], |
| 153 | .codec_dai = &aic3x_dai, |
| 154 | .init = evm_aic3x_init, |
| 155 | .ops = &evm_ops, |
| 156 | }, |
| 157 | { |
| 158 | .name = "McASP", |
| 159 | .stream_name = "spdif", |
| 160 | .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI], |
| 161 | .codec_dai = &dit_stub_dai, |
| 162 | .ops = &evm_ops, |
| 163 | }, |
| 164 | }; |
| 165 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 166 | /* davinci-evm audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 167 | static struct snd_soc_card snd_soc_card_evm = { |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 168 | .name = "DaVinci EVM", |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 169 | .platform = &davinci_soc_platform, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 170 | .dai_link = &evm_dai, |
| 171 | .num_links = 1, |
| 172 | }; |
| 173 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 174 | /* davinci dm6467 evm audio machine driver */ |
| 175 | static struct snd_soc_card dm6467_snd_soc_card_evm = { |
| 176 | .name = "DaVinci DM6467 EVM", |
| 177 | .platform = &davinci_soc_platform, |
| 178 | .dai_link = dm6467_evm_dai, |
| 179 | .num_links = ARRAY_SIZE(dm6467_evm_dai), |
| 180 | }; |
| 181 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 182 | /* evm audio private data */ |
| 183 | static struct aic3x_setup_data evm_aic3x_setup = { |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 184 | .i2c_bus = 1, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 185 | .i2c_address = 0x1b, |
| 186 | }; |
| 187 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 188 | /* dm6467 evm audio private data */ |
| 189 | static struct aic3x_setup_data dm6467_evm_aic3x_setup = { |
| 190 | .i2c_bus = 1, |
| 191 | .i2c_address = 0x18, |
| 192 | }; |
| 193 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 194 | /* evm audio subsystem */ |
| 195 | static struct snd_soc_device evm_snd_devdata = { |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 196 | .card = &snd_soc_card_evm, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 197 | .codec_dev = &soc_codec_dev_aic3x, |
| 198 | .codec_data = &evm_aic3x_setup, |
| 199 | }; |
| 200 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 201 | /* evm audio subsystem */ |
| 202 | static struct snd_soc_device dm6467_evm_snd_devdata = { |
| 203 | .card = &dm6467_snd_soc_card_evm, |
| 204 | .codec_dev = &soc_codec_dev_aic3x, |
| 205 | .codec_data = &dm6467_evm_aic3x_setup, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | static struct platform_device *evm_snd_device; |
| 209 | |
| 210 | static int __init evm_init(void) |
| 211 | { |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 212 | struct snd_soc_device *evm_snd_dev_data; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 213 | int index; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 214 | int ret; |
| 215 | |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 216 | if (machine_is_davinci_evm()) { |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 217 | evm_snd_dev_data = &evm_snd_devdata; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 218 | index = 0; |
| 219 | } else if (machine_is_davinci_dm355_evm()) { |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 220 | evm_snd_dev_data = &evm_snd_devdata; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 221 | index = 1; |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 222 | } else if (machine_is_davinci_dm6467_evm()) { |
| 223 | evm_snd_dev_data = &dm6467_evm_snd_devdata; |
| 224 | index = 0; |
David Brownell | f492ec9 | 2009-05-14 13:01:59 -0700 | [diff] [blame] | 225 | } else |
| 226 | return -EINVAL; |
| 227 | |
| 228 | evm_snd_device = platform_device_alloc("soc-audio", index); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 229 | if (!evm_snd_device) |
| 230 | return -ENOMEM; |
| 231 | |
Chaithrika U S | 04f80f5 | 2009-06-05 06:28:49 -0400 | [diff] [blame] | 232 | platform_set_drvdata(evm_snd_device, evm_snd_dev_data); |
| 233 | evm_snd_dev_data->dev = &evm_snd_device->dev; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 234 | ret = platform_device_add(evm_snd_device); |
| 235 | if (ret) |
| 236 | platform_device_put(evm_snd_device); |
| 237 | |
| 238 | return ret; |
| 239 | } |
| 240 | |
| 241 | static void __exit evm_exit(void) |
| 242 | { |
| 243 | platform_device_unregister(evm_snd_device); |
| 244 | } |
| 245 | |
| 246 | module_init(evm_init); |
| 247 | module_exit(evm_exit); |
| 248 | |
| 249 | MODULE_AUTHOR("Vladimir Barinov"); |
| 250 | MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver"); |
| 251 | MODULE_LICENSE("GPL"); |