2 * ASoC driver for TI DAVINCI EVM platform
4 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
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.
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>
23 #include <mach/hardware.h>
25 #include "../codecs/tlv320aic3x.h"
26 #include "davinci-pcm.h"
27 #include "davinci-i2s.h"
30 #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
31 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
32 static int evm_hw_params(struct snd_pcm_substream *substream,
33 struct snd_pcm_hw_params *params)
35 struct snd_soc_pcm_runtime *rtd = substream->private_data;
36 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
37 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
41 /* ASP1 on DM355 EVM is clocked by an external oscillator */
42 if (machine_is_davinci_dm355_evm())
45 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
46 * board-dm644x-evm.c using GPIOs from U18. There are six
47 * options; here we "know" we use a 48 KHz sample rate.
49 else if (machine_is_davinci_evm())
55 /* set codec DAI configuration */
56 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
60 /* set cpu DAI configuration */
61 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
65 /* set the codec system clock */
66 ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
73 static struct snd_soc_ops evm_ops = {
74 .hw_params = evm_hw_params,
77 /* davinci-evm machine dapm widgets */
78 static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
79 SND_SOC_DAPM_HP("Headphone Jack", NULL),
80 SND_SOC_DAPM_LINE("Line Out", NULL),
81 SND_SOC_DAPM_MIC("Mic Jack", NULL),
82 SND_SOC_DAPM_LINE("Line In", NULL),
85 /* davinci-evm machine audio_mapnections to the codec pins */
86 static const struct snd_soc_dapm_route audio_map[] = {
87 /* Headphone connected to HPLOUT, HPROUT */
88 {"Headphone Jack", NULL, "HPLOUT"},
89 {"Headphone Jack", NULL, "HPROUT"},
91 /* Line Out connected to LLOUT, RLOUT */
92 {"Line Out", NULL, "LLOUT"},
93 {"Line Out", NULL, "RLOUT"},
95 /* Mic connected to (MIC3L | MIC3R) */
96 {"MIC3L", NULL, "Mic Bias 2V"},
97 {"MIC3R", NULL, "Mic Bias 2V"},
98 {"Mic Bias 2V", NULL, "Mic Jack"},
100 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
101 {"LINE1L", NULL, "Line In"},
102 {"LINE2L", NULL, "Line In"},
103 {"LINE1R", NULL, "Line In"},
104 {"LINE2R", NULL, "Line In"},
107 /* Logic for a aic3x as connected on a davinci-evm */
108 static int evm_aic3x_init(struct snd_soc_codec *codec)
110 /* Add davinci-evm specific widgets */
111 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
112 ARRAY_SIZE(aic3x_dapm_widgets));
114 /* Set up davinci-evm specific audio path audio_map */
115 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
118 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
119 snd_soc_dapm_disable_pin(codec, "HPLCOM");
120 snd_soc_dapm_disable_pin(codec, "HPRCOM");
122 /* always connected */
123 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
124 snd_soc_dapm_enable_pin(codec, "Line Out");
125 snd_soc_dapm_enable_pin(codec, "Mic Jack");
126 snd_soc_dapm_enable_pin(codec, "Line In");
128 snd_soc_dapm_sync(codec);
133 /* davinci-evm digital audio interface glue - connects codec <--> CPU */
134 static struct snd_soc_dai_link evm_dai = {
135 .name = "TLV320AIC3X",
136 .stream_name = "AIC3X",
137 .cpu_dai = &davinci_i2s_dai,
138 .codec_dai = &aic3x_dai,
139 .init = evm_aic3x_init,
143 /* davinci-evm audio machine driver */
144 static struct snd_soc_card snd_soc_card_evm = {
145 .name = "DaVinci EVM",
146 .platform = &davinci_soc_platform,
147 .dai_link = &evm_dai,
151 /* evm audio private data */
152 static struct aic3x_setup_data evm_aic3x_setup = {
157 /* evm audio subsystem */
158 static struct snd_soc_device evm_snd_devdata = {
159 .card = &snd_soc_card_evm,
160 .codec_dev = &soc_codec_dev_aic3x,
161 .codec_data = &evm_aic3x_setup,
164 static struct resource evm_snd_resources[] = {
166 .start = DAVINCI_MCBSP_BASE,
167 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
168 .flags = IORESOURCE_MEM,
172 static struct evm_snd_platform_data evm_snd_data = {
173 .tx_dma_ch = DM644X_DMACH_MCBSP_TX,
174 .rx_dma_ch = DM644X_DMACH_MCBSP_RX,
177 static struct platform_device *evm_snd_device;
179 static int __init evm_init(void)
183 evm_snd_device = platform_device_alloc("soc-audio", 0);
187 platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
188 evm_snd_devdata.dev = &evm_snd_device->dev;
189 evm_snd_device->dev.platform_data = &evm_snd_data;
191 ret = platform_device_add_resources(evm_snd_device, evm_snd_resources,
192 ARRAY_SIZE(evm_snd_resources));
194 platform_device_put(evm_snd_device);
198 ret = platform_device_add(evm_snd_device);
200 platform_device_put(evm_snd_device);
205 static void __exit evm_exit(void)
207 platform_device_unregister(evm_snd_device);
210 module_init(evm_init);
211 module_exit(evm_exit);
213 MODULE_AUTHOR("Vladimir Barinov");
214 MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
215 MODULE_LICENSE("GPL");