2 * omap-mcpdm.c -- OMAP ALSA SoC DAI driver using McPDM port
4 * Copyright (C) 2009 Texas Instruments
6 * Author: Misael Lopez Cruz <x0052729@ti.com>
7 * Contact: Jorge Eduardo Candelaria <x0107209@ti.com>
8 * Margarita Olaya <magi.olaya@ti.com>
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.
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.
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
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>
36 #include <plat/mcbsp.h>
40 struct omap_mcpdm_data
{
41 struct omap_mcpdm_link
*links
;
45 static struct omap_mcpdm_link omap_mcpdm_links
[] = {
48 .irq_mask
= MCPDM_DN_IRQ_EMPTY
| MCPDM_DN_IRQ_FULL
,
50 .format
= PDMOUTFORMAT_LJUST
,
54 .irq_mask
= MCPDM_UP_IRQ_EMPTY
| MCPDM_UP_IRQ_FULL
,
56 .format
= PDMOUTFORMAT_LJUST
,
60 static struct omap_mcpdm_data mcpdm_data
= {
61 .links
= omap_mcpdm_links
,
66 * Stream DMA parameters
68 static struct omap_pcm_dma_data omap_mcpdm_dai_dma_params
[] = {
70 .name
= "Audio playback",
71 .dma_req
= OMAP44XX_DMA_MCPDM_DL
,
72 .data_type
= OMAP_DMA_DATA_TYPE_S32
,
73 .sync_mode
= OMAP_DMA_SYNC_PACKET
,
75 .port_addr
= OMAP44XX_MCPDM_L3_BASE
+ MCPDM_DN_DATA
,
78 .name
= "Audio capture",
79 .dma_req
= OMAP44XX_DMA_MCPDM_UP
,
80 .data_type
= OMAP_DMA_DATA_TYPE_S32
,
81 .sync_mode
= OMAP_DMA_SYNC_PACKET
,
83 .port_addr
= OMAP44XX_MCPDM_L3_BASE
+ MCPDM_UP_DATA
,
87 static int omap_mcpdm_dai_startup(struct snd_pcm_substream
*substream
,
88 struct snd_soc_dai
*dai
)
93 err
= omap_mcpdm_request();
98 static void omap_mcpdm_dai_shutdown(struct snd_pcm_substream
*substream
,
99 struct snd_soc_dai
*dai
)
105 static int omap_mcpdm_dai_trigger(struct snd_pcm_substream
*substream
, int cmd
,
106 struct snd_soc_dai
*dai
)
108 struct omap_mcpdm_data
*mcpdm_priv
= snd_soc_dai_get_drvdata(dai
);
109 int stream
= substream
->stream
;
113 case SNDRV_PCM_TRIGGER_START
:
114 case SNDRV_PCM_TRIGGER_RESUME
:
115 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
116 if (!mcpdm_priv
->active
++)
117 omap_mcpdm_start(stream
);
120 case SNDRV_PCM_TRIGGER_STOP
:
121 case SNDRV_PCM_TRIGGER_SUSPEND
:
122 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
123 if (!--mcpdm_priv
->active
)
124 omap_mcpdm_stop(stream
);
133 static int omap_mcpdm_dai_hw_params(struct snd_pcm_substream
*substream
,
134 struct snd_pcm_hw_params
*params
,
135 struct snd_soc_dai
*dai
)
137 struct omap_mcpdm_data
*mcpdm_priv
= snd_soc_dai_get_drvdata(dai
);
138 struct omap_mcpdm_link
*mcpdm_links
= mcpdm_priv
->links
;
139 int stream
= substream
->stream
;
140 int channels
, err
, link_mask
= 0;
142 snd_soc_dai_set_dma_data(dai
, substream
,
143 &omap_mcpdm_dai_dma_params
[stream
]);
145 channels
= params_channels(params
);
148 if (stream
== SNDRV_PCM_STREAM_CAPTURE
)
149 /* up to 2 channels for capture */
153 if (stream
== SNDRV_PCM_STREAM_CAPTURE
)
154 /* up to 2 channels for capture */
163 /* unsupported number of channels */
167 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
168 mcpdm_links
[stream
].channels
= link_mask
<< 3;
169 err
= omap_mcpdm_playback_open(&mcpdm_links
[stream
]);
171 mcpdm_links
[stream
].channels
= link_mask
<< 0;
172 err
= omap_mcpdm_capture_open(&mcpdm_links
[stream
]);
178 static int omap_mcpdm_dai_hw_free(struct snd_pcm_substream
*substream
,
179 struct snd_soc_dai
*dai
)
181 struct omap_mcpdm_data
*mcpdm_priv
= snd_soc_dai_get_drvdata(dai
);
182 struct omap_mcpdm_link
*mcpdm_links
= mcpdm_priv
->links
;
183 int stream
= substream
->stream
;
186 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
187 err
= omap_mcpdm_playback_close(&mcpdm_links
[stream
]);
189 err
= omap_mcpdm_capture_close(&mcpdm_links
[stream
]);
194 static struct snd_soc_dai_ops omap_mcpdm_dai_ops
= {
195 .startup
= omap_mcpdm_dai_startup
,
196 .shutdown
= omap_mcpdm_dai_shutdown
,
197 .trigger
= omap_mcpdm_dai_trigger
,
198 .hw_params
= omap_mcpdm_dai_hw_params
,
199 .hw_free
= omap_mcpdm_dai_hw_free
,
202 #define OMAP_MCPDM_RATES (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
203 #define OMAP_MCPDM_FORMATS (SNDRV_PCM_FMTBIT_S32_LE)
205 static int omap_mcpdm_dai_probe(struct snd_soc_dai
*dai
)
207 snd_soc_dai_set_drvdata(dai
, &mcpdm_data
);
211 static struct snd_soc_dai_driver omap_mcpdm_dai
= {
212 .probe
= omap_mcpdm_dai_probe
,
216 .rates
= OMAP_MCPDM_RATES
,
217 .formats
= OMAP_MCPDM_FORMATS
,
222 .rates
= OMAP_MCPDM_RATES
,
223 .formats
= OMAP_MCPDM_FORMATS
,
225 .ops
= &omap_mcpdm_dai_ops
,
228 static __devinit
int asoc_mcpdm_probe(struct platform_device
*pdev
)
232 ret
= omap_mcpdm_probe(pdev
);
235 ret
= snd_soc_register_dai(&pdev
->dev
, &omap_mcpdm_dai
);
237 omap_mcpdm_remove(pdev
);
241 static int __devexit
asoc_mcpdm_remove(struct platform_device
*pdev
)
243 snd_soc_unregister_dai(&pdev
->dev
);
244 omap_mcpdm_remove(pdev
);
248 static struct platform_driver asoc_mcpdm_driver
= {
250 .name
= "omap-mcpdm-dai",
251 .owner
= THIS_MODULE
,
254 .probe
= asoc_mcpdm_probe
,
255 .remove
= __devexit_p(asoc_mcpdm_remove
),
258 static int __init
snd_omap_mcpdm_init(void)
260 return platform_driver_register(&asoc_mcpdm_driver
);
262 module_init(snd_omap_mcpdm_init
);
264 static void __exit
snd_omap_mcpdm_exit(void)
266 platform_driver_unregister(&asoc_mcpdm_driver
);
268 module_exit(snd_omap_mcpdm_exit
);
270 MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
271 MODULE_DESCRIPTION("OMAP PDM SoC Interface");
272 MODULE_LICENSE("GPL");