blob: 65fdbd81a379c022589697eda8445dd62380bf83 [file] [log] [blame]
Vladimir Barinov310355c2008-02-18 11:40:22 +01001/*
2 * ASoC driver for TI DAVINCI EVM platform
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
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 Barinov310355c2008-02-18 11:40:22 +010022#include <asm/dma.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010023#include <mach/hardware.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010024
25#include "../codecs/tlv320aic3x.h"
26#include "davinci-pcm.h"
27#include "davinci-i2s.h"
28
29#define EVM_CODEC_CLOCK 22579200
30
31static int evm_hw_params(struct snd_pcm_substream *substream,
32 struct snd_pcm_hw_params *params)
33{
34 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwood9cb132d2008-07-07 16:07:42 +010035 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
36 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
Vladimir Barinov310355c2008-02-18 11:40:22 +010037 int ret = 0;
38
39 /* set codec DAI configuration */
Liam Girdwood64105cf2008-07-08 13:19:18 +010040 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
Vladimir Barinov310355c2008-02-18 11:40:22 +010041 SND_SOC_DAIFMT_CBM_CFM);
42 if (ret < 0)
43 return ret;
44
45 /* set cpu DAI configuration */
Liam Girdwood64105cf2008-07-08 13:19:18 +010046 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
Vladimir Barinov310355c2008-02-18 11:40:22 +010047 SND_SOC_DAIFMT_IB_NF);
48 if (ret < 0)
49 return ret;
50
51 /* set the codec system clock */
Liam Girdwood64105cf2008-07-08 13:19:18 +010052 ret = snd_soc_dai_set_sysclk(codec_dai, 0, EVM_CODEC_CLOCK,
Vladimir Barinov310355c2008-02-18 11:40:22 +010053 SND_SOC_CLOCK_OUT);
54 if (ret < 0)
55 return ret;
56
57 return 0;
58}
59
60static struct snd_soc_ops evm_ops = {
61 .hw_params = evm_hw_params,
62};
63
64/* davinci-evm machine dapm widgets */
65static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
66 SND_SOC_DAPM_HP("Headphone Jack", NULL),
67 SND_SOC_DAPM_LINE("Line Out", NULL),
68 SND_SOC_DAPM_MIC("Mic Jack", NULL),
69 SND_SOC_DAPM_LINE("Line In", NULL),
70};
71
72/* davinci-evm machine audio_mapnections to the codec pins */
Mark Brownacf497f2008-05-13 14:58:30 +020073static const struct snd_soc_dapm_route audio_map[] = {
Vladimir Barinov310355c2008-02-18 11:40:22 +010074 /* Headphone connected to HPLOUT, HPROUT */
75 {"Headphone Jack", NULL, "HPLOUT"},
76 {"Headphone Jack", NULL, "HPROUT"},
77
78 /* Line Out connected to LLOUT, RLOUT */
79 {"Line Out", NULL, "LLOUT"},
80 {"Line Out", NULL, "RLOUT"},
81
82 /* Mic connected to (MIC3L | MIC3R) */
83 {"MIC3L", NULL, "Mic Bias 2V"},
84 {"MIC3R", NULL, "Mic Bias 2V"},
85 {"Mic Bias 2V", NULL, "Mic Jack"},
86
87 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
88 {"LINE1L", NULL, "Line In"},
89 {"LINE2L", NULL, "Line In"},
90 {"LINE1R", NULL, "Line In"},
91 {"LINE2R", NULL, "Line In"},
Vladimir Barinov310355c2008-02-18 11:40:22 +010092};
93
94/* Logic for a aic3x as connected on a davinci-evm */
95static int evm_aic3x_init(struct snd_soc_codec *codec)
96{
Vladimir Barinov310355c2008-02-18 11:40:22 +010097 /* Add davinci-evm specific widgets */
Mark Brownacf497f2008-05-13 14:58:30 +020098 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
99 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100100
101 /* Set up davinci-evm specific audio path audio_map */
Mark Brownacf497f2008-05-13 14:58:30 +0200102 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
Vladimir Barinov310355c2008-02-18 11:40:22 +0100103
104 /* not connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100105 snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
106 snd_soc_dapm_disable_pin(codec, "HPLCOM");
107 snd_soc_dapm_disable_pin(codec, "HPRCOM");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100108
109 /* always connected */
Liam Girdwooda5302182008-07-07 13:35:17 +0100110 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
111 snd_soc_dapm_enable_pin(codec, "Line Out");
112 snd_soc_dapm_enable_pin(codec, "Mic Jack");
113 snd_soc_dapm_enable_pin(codec, "Line In");
Vladimir Barinov310355c2008-02-18 11:40:22 +0100114
Liam Girdwooda5302182008-07-07 13:35:17 +0100115 snd_soc_dapm_sync(codec);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100116
117 return 0;
118}
119
120/* davinci-evm digital audio interface glue - connects codec <--> CPU */
121static struct snd_soc_dai_link evm_dai = {
122 .name = "TLV320AIC3X",
123 .stream_name = "AIC3X",
124 .cpu_dai = &davinci_i2s_dai,
125 .codec_dai = &aic3x_dai,
126 .init = evm_aic3x_init,
127 .ops = &evm_ops,
128};
129
130/* davinci-evm audio machine driver */
131static struct snd_soc_machine snd_soc_machine_evm = {
132 .name = "DaVinci EVM",
133 .dai_link = &evm_dai,
134 .num_links = 1,
135};
136
137/* evm audio private data */
138static struct aic3x_setup_data evm_aic3x_setup = {
139 .i2c_address = 0x1b,
140};
141
142/* evm audio subsystem */
143static struct snd_soc_device evm_snd_devdata = {
144 .machine = &snd_soc_machine_evm,
145 .platform = &davinci_soc_platform,
146 .codec_dev = &soc_codec_dev_aic3x,
147 .codec_data = &evm_aic3x_setup,
148};
149
150static struct resource evm_snd_resources[] = {
151 {
152 .start = DAVINCI_MCBSP_BASE,
153 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
154 .flags = IORESOURCE_MEM,
155 },
156};
157
158static struct evm_snd_platform_data evm_snd_data = {
159 .tx_dma_ch = DM644X_DMACH_MCBSP_TX,
160 .rx_dma_ch = DM644X_DMACH_MCBSP_RX,
161};
162
163static struct platform_device *evm_snd_device;
164
165static int __init evm_init(void)
166{
167 int ret;
168
169 evm_snd_device = platform_device_alloc("soc-audio", 0);
170 if (!evm_snd_device)
171 return -ENOMEM;
172
173 platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
174 evm_snd_devdata.dev = &evm_snd_device->dev;
175 evm_snd_device->dev.platform_data = &evm_snd_data;
176
177 ret = platform_device_add_resources(evm_snd_device, evm_snd_resources,
178 ARRAY_SIZE(evm_snd_resources));
179 if (ret) {
180 platform_device_put(evm_snd_device);
181 return ret;
182 }
183
184 ret = platform_device_add(evm_snd_device);
185 if (ret)
186 platform_device_put(evm_snd_device);
187
188 return ret;
189}
190
191static void __exit evm_exit(void)
192{
193 platform_device_unregister(evm_snd_device);
194}
195
196module_init(evm_init);
197module_exit(evm_exit);
198
199MODULE_AUTHOR("Vladimir Barinov");
200MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
201MODULE_LICENSE("GPL");