aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/davinci
diff options
context:
space:
mode:
authorMiguel Aguilar <miguel.aguilar@ridgerun.com>2010-03-11 10:32:42 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2010-03-12 06:12:21 -0500
commite155fcc23c918f5d78a35d1eb6f3f0d523f51991 (patch)
tree20e6af0382d156fea93cd9903fbadc0b6a34a168 /sound/soc/davinci
parentca26308c2223cb424c297a70fb7b6c7530a563ba (diff)
ASoC: DaVinci: Voice Codec Interface
This patch adds the support for the interface needed by the DaVinci Voice Codec CQ93VC. Signed-off-by: Miguel Aguilar <miguel.aguilar@ridgerun.com> Acked-by: Liam Girdwood <lrg@slimlogic.co.uk> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/davinci')
-rw-r--r--sound/soc/davinci/Kconfig3
-rw-r--r--sound/soc/davinci/Makefile2
-rw-r--r--sound/soc/davinci/davinci-vcif.c272
-rw-r--r--sound/soc/davinci/davinci-vcif.h28
4 files changed, 305 insertions, 0 deletions
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig
index 047ee39418c0..47e7ccecc577 100644
--- a/sound/soc/davinci/Kconfig
+++ b/sound/soc/davinci/Kconfig
@@ -12,6 +12,9 @@ config SND_DAVINCI_SOC_I2S
12config SND_DAVINCI_SOC_MCASP 12config SND_DAVINCI_SOC_MCASP
13 tristate 13 tristate
14 14
15config SND_DAVINCI_SOC_VCIF
16 tristate
17
15config SND_DAVINCI_SOC_EVM 18config SND_DAVINCI_SOC_EVM
16 tristate "SoC Audio support for DaVinci DM6446, DM355 or DM365 EVM" 19 tristate "SoC Audio support for DaVinci DM6446, DM355 or DM365 EVM"
17 depends on SND_DAVINCI_SOC 20 depends on SND_DAVINCI_SOC
diff --git a/sound/soc/davinci/Makefile b/sound/soc/davinci/Makefile
index a6939d71b988..a93679d618cd 100644
--- a/sound/soc/davinci/Makefile
+++ b/sound/soc/davinci/Makefile
@@ -2,10 +2,12 @@
2snd-soc-davinci-objs := davinci-pcm.o 2snd-soc-davinci-objs := davinci-pcm.o
3snd-soc-davinci-i2s-objs := davinci-i2s.o 3snd-soc-davinci-i2s-objs := davinci-i2s.o
4snd-soc-davinci-mcasp-objs:= davinci-mcasp.o 4snd-soc-davinci-mcasp-objs:= davinci-mcasp.o
5snd-soc-davinci-vcif-objs:= davinci-vcif.o
5 6
6obj-$(CONFIG_SND_DAVINCI_SOC) += snd-soc-davinci.o 7obj-$(CONFIG_SND_DAVINCI_SOC) += snd-soc-davinci.o
7obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o 8obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o
8obj-$(CONFIG_SND_DAVINCI_SOC_MCASP) += snd-soc-davinci-mcasp.o 9obj-$(CONFIG_SND_DAVINCI_SOC_MCASP) += snd-soc-davinci-mcasp.o
10obj-$(CONFIG_SND_DAVINCI_SOC_VCIF) += snd-soc-davinci-vcif.o
9 11
10# DAVINCI Machine Support 12# DAVINCI Machine Support
11snd-soc-evm-objs := davinci-evm.o 13snd-soc-evm-objs := davinci-evm.o
diff --git a/sound/soc/davinci/davinci-vcif.c b/sound/soc/davinci/davinci-vcif.c
new file mode 100644
index 000000000000..03f3feb0fe2f
--- /dev/null
+++ b/sound/soc/davinci/davinci-vcif.c
@@ -0,0 +1,272 @@
1/*
2 * ALSA SoC Voice Codec Interface for TI DAVINCI processor
3 *
4 * Copyright (C) 2010 Texas Instruments.
5 *
6 * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/device.h>
26#include <linux/delay.h>
27#include <linux/io.h>
28#include <linux/mfd/davinci_voicecodec.h>
29
30#include <sound/core.h>
31#include <sound/pcm.h>
32#include <sound/pcm_params.h>
33#include <sound/initval.h>
34#include <sound/soc.h>
35
36#include "davinci-pcm.h"
37#include "davinci-i2s.h"
38#include "davinci-vcif.h"
39
40#define MOD_REG_BIT(val, mask, set) do { \
41 if (set) { \
42 val |= mask; \
43 } else { \
44 val &= ~mask; \
45 } \
46} while (0)
47
48struct davinci_vcif_dev {
49 struct davinci_vc *davinci_vc;
50 struct davinci_pcm_dma_params dma_params[2];
51};
52
53static void davinci_vcif_start(struct snd_pcm_substream *substream)
54{
55 struct snd_soc_pcm_runtime *rtd = substream->private_data;
56 struct davinci_vcif_dev *davinci_vcif_dev =
57 rtd->dai->cpu_dai->private_data;
58 struct davinci_vc *davinci_vc = davinci_vcif_dev->davinci_vc;
59 u32 w;
60
61 /* Start the sample generator and enable transmitter/receiver */
62 w = readl(davinci_vc->base + DAVINCI_VC_CTRL);
63
64 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
65 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTDAC, 1);
66 else
67 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTADC, 1);
68
69 writel(w, davinci_vc->base + DAVINCI_VC_CTRL);
70}
71
72static void davinci_vcif_stop(struct snd_pcm_substream *substream)
73{
74 struct snd_soc_pcm_runtime *rtd = substream->private_data;
75 struct davinci_vcif_dev *davinci_vcif_dev =
76 rtd->dai->cpu_dai->private_data;
77 struct davinci_vc *davinci_vc = davinci_vcif_dev->davinci_vc;
78 u32 w;
79
80 /* Reset transmitter/receiver and sample rate/frame sync generators */
81 w = readl(davinci_vc->base + DAVINCI_VC_CTRL);
82 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
83 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTDAC, 0);
84 else
85 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTADC, 0);
86
87 writel(w, davinci_vc->base + DAVINCI_VC_CTRL);
88}
89
90static int davinci_vcif_hw_params(struct snd_pcm_substream *substream,
91 struct snd_pcm_hw_params *params,
92 struct snd_soc_dai *dai)
93{
94 struct davinci_vcif_dev *davinci_vcif_dev = dai->private_data;
95 struct davinci_vc *davinci_vc = davinci_vcif_dev->davinci_vc;
96 struct davinci_pcm_dma_params *dma_params =
97 &davinci_vcif_dev->dma_params[substream->stream];
98 u32 w;
99
100 /* Restart the codec before setup */
101 davinci_vcif_stop(substream);
102 davinci_vcif_start(substream);
103
104 /* General line settings */
105 writel(DAVINCI_VC_CTRL_MASK, davinci_vc->base + DAVINCI_VC_CTRL);
106
107 writel(DAVINCI_VC_INT_MASK, davinci_vc->base + DAVINCI_VC_INTCLR);
108
109 writel(DAVINCI_VC_INT_MASK, davinci_vc->base + DAVINCI_VC_INTEN);
110
111 w = readl(davinci_vc->base + DAVINCI_VC_CTRL);
112
113 /* Determine xfer data type */
114 switch (params_format(params)) {
115 case SNDRV_PCM_FORMAT_U8:
116 dma_params->data_type = 0;
117
118 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
119 DAVINCI_VC_CTRL_RD_UNSIGNED |
120 DAVINCI_VC_CTRL_WD_BITS_8 |
121 DAVINCI_VC_CTRL_WD_UNSIGNED, 1);
122 break;
123 case SNDRV_PCM_FORMAT_S8:
124 dma_params->data_type = 1;
125
126 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
127 DAVINCI_VC_CTRL_WD_BITS_8, 1);
128
129 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_UNSIGNED |
130 DAVINCI_VC_CTRL_WD_UNSIGNED, 0);
131 break;
132 case SNDRV_PCM_FORMAT_S16_LE:
133 dma_params->data_type = 2;
134
135 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
136 DAVINCI_VC_CTRL_RD_UNSIGNED |
137 DAVINCI_VC_CTRL_WD_BITS_8 |
138 DAVINCI_VC_CTRL_WD_UNSIGNED, 0);
139 break;
140 default:
141 printk(KERN_WARNING "davinci-vcif: unsupported PCM format");
142 return -EINVAL;
143 }
144
145 dma_params->acnt = dma_params->data_type;
146
147 writel(w, davinci_vc->base + DAVINCI_VC_CTRL);
148
149 return 0;
150}
151
152static int davinci_vcif_trigger(struct snd_pcm_substream *substream, int cmd,
153 struct snd_soc_dai *dai)
154{
155 int ret = 0;
156
157 switch (cmd) {
158 case SNDRV_PCM_TRIGGER_START:
159 case SNDRV_PCM_TRIGGER_RESUME:
160 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
161 davinci_vcif_start(substream);
162 case SNDRV_PCM_TRIGGER_STOP:
163 case SNDRV_PCM_TRIGGER_SUSPEND:
164 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
165 davinci_vcif_stop(substream);
166 break;
167 default:
168 ret = -EINVAL;
169 }
170
171 return ret;
172}
173
174#define DAVINCI_VCIF_RATES SNDRV_PCM_RATE_8000_48000
175
176static struct snd_soc_dai_ops davinci_vcif_dai_ops = {
177 .trigger = davinci_vcif_trigger,
178 .hw_params = davinci_vcif_hw_params,
179};
180
181struct snd_soc_dai davinci_vcif_dai = {
182 .name = "davinci-vcif",
183 .playback = {
184 .channels_min = 1,
185 .channels_max = 2,
186 .rates = DAVINCI_VCIF_RATES,
187 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
188 .capture = {
189 .channels_min = 1,
190 .channels_max = 2,
191 .rates = DAVINCI_VCIF_RATES,
192 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
193 .ops = &davinci_vcif_dai_ops,
194
195};
196EXPORT_SYMBOL_GPL(davinci_vcif_dai);
197
198static int davinci_vcif_probe(struct platform_device *pdev)
199{
200 struct davinci_vc *davinci_vc = platform_get_drvdata(pdev);
201 struct davinci_vcif_dev *davinci_vcif_dev;
202 int ret;
203
204 davinci_vcif_dev = kzalloc(sizeof(struct davinci_vcif_dev), GFP_KERNEL);
205 if (!davinci_vc) {
206 dev_dbg(&pdev->dev,
207 "could not allocate memory for private data\n");
208 return -ENOMEM;
209 }
210
211 /* DMA tx params */
212 davinci_vcif_dev->davinci_vc = davinci_vc;
213 davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].channel =
214 davinci_vc->davinci_vcif.dma_tx_channel;
215 davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].dma_addr =
216 davinci_vc->davinci_vcif.dma_tx_addr;
217
218 /* DMA rx params */
219 davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel =
220 davinci_vc->davinci_vcif.dma_rx_channel;
221 davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].dma_addr =
222 davinci_vc->davinci_vcif.dma_rx_addr;
223
224 davinci_vcif_dai.dev = &pdev->dev;
225 davinci_vcif_dai.dma_data = davinci_vcif_dev->dma_params;
226 davinci_vcif_dai.private_data = davinci_vcif_dev;
227
228 ret = snd_soc_register_dai(&davinci_vcif_dai);
229 if (ret != 0) {
230 dev_err(&pdev->dev, "could not register dai\n");
231 goto fail;
232 }
233
234 return 0;
235
236fail:
237 kfree(davinci_vcif_dev);
238
239 return ret;
240}
241
242static int davinci_vcif_remove(struct platform_device *pdev)
243{
244 snd_soc_unregister_dai(&davinci_vcif_dai);
245
246 return 0;
247}
248
249static struct platform_driver davinci_vcif_driver = {
250 .probe = davinci_vcif_probe,
251 .remove = davinci_vcif_remove,
252 .driver = {
253 .name = "davinci_vcif",
254 .owner = THIS_MODULE,
255 },
256};
257
258static int __init davinci_vcif_init(void)
259{
260 return platform_driver_probe(&davinci_vcif_driver, davinci_vcif_probe);
261}
262module_init(davinci_vcif_init);
263
264static void __exit davinci_vcif_exit(void)
265{
266 platform_driver_unregister(&davinci_vcif_driver);
267}
268module_exit(davinci_vcif_exit);
269
270MODULE_AUTHOR("Miguel Aguilar");
271MODULE_DESCRIPTION("Texas Instruments DaVinci ASoC Voice Codec Interface");
272MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-vcif.h b/sound/soc/davinci/davinci-vcif.h
new file mode 100644
index 000000000000..571c9948724f
--- /dev/null
+++ b/sound/soc/davinci/davinci-vcif.h
@@ -0,0 +1,28 @@
1/*
2 * ALSA SoC Voice Codec Interface for TI DAVINCI processor
3 *
4 * Copyright (C) 2010 Texas Instruments.
5 *
6 * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef _DAVINCI_VCIF_H
24#define _DAVINCI_VCIF_H
25
26extern struct snd_soc_dai davinci_vcif_dai;
27
28#endif