ASoC: multi-component - ASoC Multi-Component Support
[deliverable/linux.git] / sound / soc / omap / omap-mcpdm.c
CommitLineData
db72c2f8
MLC
1/*
2 * omap-mcpdm.c -- OMAP ALSA SoC DAI driver using McPDM port
3 *
4 * Copyright (C) 2009 Texas Instruments
5 *
6 * Author: Misael Lopez Cruz <x0052729@ti.com>
7 * Contact: Jorge Eduardo Candelaria <x0107209@ti.com>
8 * Margarita Olaya <magi.olaya@ti.com>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 *
24 */
25
26#include <linux/init.h>
27#include <linux/module.h>
28#include <linux/device.h>
29#include <sound/core.h>
30#include <sound/pcm.h>
31#include <sound/pcm_params.h>
32#include <sound/initval.h>
33#include <sound/soc.h>
34
35#include <plat/control.h>
36#include <plat/dma.h>
37#include <plat/mcbsp.h>
38#include "mcpdm.h"
db72c2f8
MLC
39#include "omap-pcm.h"
40
41struct omap_mcpdm_data {
42 struct omap_mcpdm_link *links;
43 int active;
44};
45
46static struct omap_mcpdm_link omap_mcpdm_links[] = {
47 /* downlink */
48 {
49 .irq_mask = MCPDM_DN_IRQ_EMPTY | MCPDM_DN_IRQ_FULL,
50 .threshold = 1,
51 .format = PDMOUTFORMAT_LJUST,
52 },
53 /* uplink */
54 {
55 .irq_mask = MCPDM_UP_IRQ_EMPTY | MCPDM_UP_IRQ_FULL,
56 .threshold = 1,
57 .format = PDMOUTFORMAT_LJUST,
58 },
59};
60
61static struct omap_mcpdm_data mcpdm_data = {
62 .links = omap_mcpdm_links,
63 .active = 0,
64};
65
66/*
67 * Stream DMA parameters
68 */
69static struct omap_pcm_dma_data omap_mcpdm_dai_dma_params[] = {
70 {
71 .name = "Audio playback",
72 .dma_req = OMAP44XX_DMA_MCPDM_DL,
73 .data_type = OMAP_DMA_DATA_TYPE_S32,
74 .sync_mode = OMAP_DMA_SYNC_PACKET,
75 .packet_size = 16,
76 .port_addr = OMAP44XX_MCPDM_L3_BASE + MCPDM_DN_DATA,
77 },
78 {
79 .name = "Audio capture",
80 .dma_req = OMAP44XX_DMA_MCPDM_UP,
81 .data_type = OMAP_DMA_DATA_TYPE_S32,
82 .sync_mode = OMAP_DMA_SYNC_PACKET,
83 .packet_size = 16,
84 .port_addr = OMAP44XX_MCPDM_L3_BASE + MCPDM_UP_DATA,
85 },
86};
87
88static int omap_mcpdm_dai_startup(struct snd_pcm_substream *substream,
89 struct snd_soc_dai *dai)
90{
db72c2f8
MLC
91 int err = 0;
92
f0fba2ad 93 if (!dai->active)
db72c2f8
MLC
94 err = omap_mcpdm_request();
95
96 return err;
97}
98
99static void omap_mcpdm_dai_shutdown(struct snd_pcm_substream *substream,
100 struct snd_soc_dai *dai)
101{
f0fba2ad 102 if (!dai->active)
db72c2f8
MLC
103 omap_mcpdm_free();
104}
105
106static int omap_mcpdm_dai_trigger(struct snd_pcm_substream *substream, int cmd,
107 struct snd_soc_dai *dai)
108{
f0fba2ad 109 struct omap_mcpdm_data *mcpdm_priv = snd_soc_dai_get_drvdata(dai);
db72c2f8
MLC
110 int stream = substream->stream;
111 int err = 0;
112
113 switch (cmd) {
114 case SNDRV_PCM_TRIGGER_START:
115 case SNDRV_PCM_TRIGGER_RESUME:
116 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
117 if (!mcpdm_priv->active++)
118 omap_mcpdm_start(stream);
119 break;
120
121 case SNDRV_PCM_TRIGGER_STOP:
122 case SNDRV_PCM_TRIGGER_SUSPEND:
123 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
124 if (!--mcpdm_priv->active)
125 omap_mcpdm_stop(stream);
126 break;
127 default:
128 err = -EINVAL;
129 }
130
131 return err;
132}
133
134static int omap_mcpdm_dai_hw_params(struct snd_pcm_substream *substream,
135 struct snd_pcm_hw_params *params,
136 struct snd_soc_dai *dai)
137{
f0fba2ad 138 struct omap_mcpdm_data *mcpdm_priv = snd_soc_dai_get_drvdata(dai);
db72c2f8
MLC
139 struct omap_mcpdm_link *mcpdm_links = mcpdm_priv->links;
140 int stream = substream->stream;
141 int channels, err, link_mask = 0;
142
f0fba2ad 143 snd_soc_dai_set_dma_data(dai, substream,
5f712b2b 144 &omap_mcpdm_dai_dma_params[stream]);
db72c2f8
MLC
145
146 channels = params_channels(params);
147 switch (channels) {
148 case 4:
149 if (stream == SNDRV_PCM_STREAM_CAPTURE)
150 /* up to 2 channels for capture */
151 return -EINVAL;
152 link_mask |= 1 << 3;
153 case 3:
154 if (stream == SNDRV_PCM_STREAM_CAPTURE)
155 /* up to 2 channels for capture */
156 return -EINVAL;
157 link_mask |= 1 << 2;
158 case 2:
159 link_mask |= 1 << 1;
160 case 1:
161 link_mask |= 1 << 0;
162 break;
163 default:
164 /* unsupported number of channels */
165 return -EINVAL;
166 }
167
168 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
169 mcpdm_links[stream].channels = link_mask << 3;
170 err = omap_mcpdm_playback_open(&mcpdm_links[stream]);
171 } else {
172 mcpdm_links[stream].channels = link_mask << 0;
173 err = omap_mcpdm_capture_open(&mcpdm_links[stream]);
174 }
175
176 return err;
177}
178
179static int omap_mcpdm_dai_hw_free(struct snd_pcm_substream *substream,
180 struct snd_soc_dai *dai)
181{
f0fba2ad 182 struct omap_mcpdm_data *mcpdm_priv = snd_soc_dai_get_drvdata(dai);
db72c2f8
MLC
183 struct omap_mcpdm_link *mcpdm_links = mcpdm_priv->links;
184 int stream = substream->stream;
185 int err;
186
187 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
188 err = omap_mcpdm_playback_close(&mcpdm_links[stream]);
189 else
190 err = omap_mcpdm_capture_close(&mcpdm_links[stream]);
191
192 return err;
193}
194
195static struct snd_soc_dai_ops omap_mcpdm_dai_ops = {
196 .startup = omap_mcpdm_dai_startup,
197 .shutdown = omap_mcpdm_dai_shutdown,
198 .trigger = omap_mcpdm_dai_trigger,
199 .hw_params = omap_mcpdm_dai_hw_params,
200 .hw_free = omap_mcpdm_dai_hw_free,
201};
202
203#define OMAP_MCPDM_RATES (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
204#define OMAP_MCPDM_FORMATS (SNDRV_PCM_FMTBIT_S32_LE)
205
f0fba2ad
LG
206static int omap_mcpdm_dai_probe(struct snd_soc_dai *dai)
207{
208 snd_soc_dai_set_drvdata(dai, &mcpdm_data);
209 return 0;
210}
211
212static struct snd_soc_dai_driver omap_mcpdm_dai = {
213 .probe = omap_mcpdm_dai_probe,
db72c2f8
MLC
214 .playback = {
215 .channels_min = 1,
216 .channels_max = 4,
217 .rates = OMAP_MCPDM_RATES,
218 .formats = OMAP_MCPDM_FORMATS,
219 },
220 .capture = {
221 .channels_min = 1,
222 .channels_max = 2,
223 .rates = OMAP_MCPDM_RATES,
224 .formats = OMAP_MCPDM_FORMATS,
225 },
226 .ops = &omap_mcpdm_dai_ops,
db72c2f8 227};
f0fba2ad
LG
228
229static __devinit int asoc_mcpdm_probe(struct platform_device *pdev)
230{
231 int ret;
232
233 ret = omap_mcpdm_probe(pdev);
234 if (ret < 0)
235 return ret;
236 ret = snd_soc_register_dai(&pdev->dev, &omap_mcpdm_dai);
237 if (ret < 0)
238 omap_mcpdm_remove(pdev);
239 return ret;
240}
241
242static int __devexit asoc_mcpdm_remove(struct platform_device *pdev)
243{
244 snd_soc_unregister_dai(&pdev->dev);
245 omap_mcpdm_remove(pdev);
246 return 0;
247}
248
249static struct platform_driver asoc_mcpdm_driver = {
250 .driver = {
251 .name = "omap-mcpdm-dai",
252 .owner = THIS_MODULE,
253 },
254
255 .probe = asoc_mcpdm_probe,
256 .remove = __devexit_p(asoc_mcpdm_remove),
257};
db72c2f8
MLC
258
259static int __init snd_omap_mcpdm_init(void)
260{
f0fba2ad 261 return platform_driver_register(&asoc_mcpdm_driver);
db72c2f8
MLC
262}
263module_init(snd_omap_mcpdm_init);
264
265static void __exit snd_omap_mcpdm_exit(void)
266{
f0fba2ad 267 platform_driver_unregister(&asoc_mcpdm_driver);
db72c2f8
MLC
268}
269module_exit(snd_omap_mcpdm_exit);
270
271MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
272MODULE_DESCRIPTION("OMAP PDM SoC Interface");
273MODULE_LICENSE("GPL");
This page took 0.056713 seconds and 5 git commands to generate.