]> bbs.cooldavid.org Git - net-next-2.6.git/blob - sound/soc/omap/omap-mcpdm.c
ASoC: OMAP4: MCPDM: Remove unnecessary include of plat/control.h
[net-next-2.6.git] / sound / soc / omap / omap-mcpdm.c
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/dma.h>
36 #include <plat/mcbsp.h>
37 #include "mcpdm.h"
38 #include "omap-mcpdm.h"
39 #include "omap-pcm.h"
40
41 struct omap_mcpdm_data {
42         struct omap_mcpdm_link *links;
43         int active;
44 };
45
46 static 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
61 static struct omap_mcpdm_data mcpdm_data = {
62         .links = omap_mcpdm_links,
63         .active = 0,
64 };
65
66 /*
67  * Stream DMA parameters
68  */
69 static 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
88 static int omap_mcpdm_dai_startup(struct snd_pcm_substream *substream,
89                                   struct snd_soc_dai *dai)
90 {
91         struct snd_soc_pcm_runtime *rtd = substream->private_data;
92         struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
93         int err = 0;
94
95         if (!cpu_dai->active)
96                 err = omap_mcpdm_request();
97
98         return err;
99 }
100
101 static void omap_mcpdm_dai_shutdown(struct snd_pcm_substream *substream,
102                                     struct snd_soc_dai *dai)
103 {
104         struct snd_soc_pcm_runtime *rtd = substream->private_data;
105         struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
106
107         if (!cpu_dai->active)
108                 omap_mcpdm_free();
109 }
110
111 static int omap_mcpdm_dai_trigger(struct snd_pcm_substream *substream, int cmd,
112                                   struct snd_soc_dai *dai)
113 {
114         struct snd_soc_pcm_runtime *rtd = substream->private_data;
115         struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
116         struct omap_mcpdm_data *mcpdm_priv = cpu_dai->private_data;
117         int stream = substream->stream;
118         int err = 0;
119
120         switch (cmd) {
121         case SNDRV_PCM_TRIGGER_START:
122         case SNDRV_PCM_TRIGGER_RESUME:
123         case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
124                 if (!mcpdm_priv->active++)
125                         omap_mcpdm_start(stream);
126                 break;
127
128         case SNDRV_PCM_TRIGGER_STOP:
129         case SNDRV_PCM_TRIGGER_SUSPEND:
130         case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
131                 if (!--mcpdm_priv->active)
132                         omap_mcpdm_stop(stream);
133                 break;
134         default:
135                 err = -EINVAL;
136         }
137
138         return err;
139 }
140
141 static int omap_mcpdm_dai_hw_params(struct snd_pcm_substream *substream,
142                                     struct snd_pcm_hw_params *params,
143                                     struct snd_soc_dai *dai)
144 {
145         struct snd_soc_pcm_runtime *rtd = substream->private_data;
146         struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
147         struct omap_mcpdm_data *mcpdm_priv = cpu_dai->private_data;
148         struct omap_mcpdm_link *mcpdm_links = mcpdm_priv->links;
149         int stream = substream->stream;
150         int channels, err, link_mask = 0;
151
152         snd_soc_dai_set_dma_data(cpu_dai, substream,
153                                  &omap_mcpdm_dai_dma_params[stream]);
154
155         channels = params_channels(params);
156         switch (channels) {
157         case 4:
158                 if (stream == SNDRV_PCM_STREAM_CAPTURE)
159                         /* up to 2 channels for capture */
160                         return -EINVAL;
161                 link_mask |= 1 << 3;
162         case 3:
163                 if (stream == SNDRV_PCM_STREAM_CAPTURE)
164                         /* up to 2 channels for capture */
165                         return -EINVAL;
166                 link_mask |= 1 << 2;
167         case 2:
168                 link_mask |= 1 << 1;
169         case 1:
170                 link_mask |= 1 << 0;
171                 break;
172         default:
173                 /* unsupported number of channels */
174                 return -EINVAL;
175         }
176
177         if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
178                 mcpdm_links[stream].channels = link_mask << 3;
179                 err = omap_mcpdm_playback_open(&mcpdm_links[stream]);
180         } else {
181                 mcpdm_links[stream].channels = link_mask << 0;
182                 err = omap_mcpdm_capture_open(&mcpdm_links[stream]);
183         }
184
185         return err;
186 }
187
188 static int omap_mcpdm_dai_hw_free(struct snd_pcm_substream *substream,
189                                   struct snd_soc_dai *dai)
190 {
191         struct snd_soc_pcm_runtime *rtd = substream->private_data;
192         struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
193         struct omap_mcpdm_data *mcpdm_priv = cpu_dai->private_data;
194         struct omap_mcpdm_link *mcpdm_links = mcpdm_priv->links;
195         int stream = substream->stream;
196         int err;
197
198         if (substream->stream ==  SNDRV_PCM_STREAM_PLAYBACK)
199                 err = omap_mcpdm_playback_close(&mcpdm_links[stream]);
200         else
201                 err = omap_mcpdm_capture_close(&mcpdm_links[stream]);
202
203         return err;
204 }
205
206 static struct snd_soc_dai_ops omap_mcpdm_dai_ops = {
207         .startup        = omap_mcpdm_dai_startup,
208         .shutdown       = omap_mcpdm_dai_shutdown,
209         .trigger        = omap_mcpdm_dai_trigger,
210         .hw_params      = omap_mcpdm_dai_hw_params,
211         .hw_free        = omap_mcpdm_dai_hw_free,
212 };
213
214 #define OMAP_MCPDM_RATES        (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
215 #define OMAP_MCPDM_FORMATS      (SNDRV_PCM_FMTBIT_S32_LE)
216
217 struct snd_soc_dai omap_mcpdm_dai = {
218         .name = "omap-mcpdm",
219         .id = -1,
220         .playback = {
221                 .channels_min = 1,
222                 .channels_max = 4,
223                 .rates = OMAP_MCPDM_RATES,
224                 .formats = OMAP_MCPDM_FORMATS,
225         },
226         .capture = {
227                 .channels_min = 1,
228                 .channels_max = 2,
229                 .rates = OMAP_MCPDM_RATES,
230                 .formats = OMAP_MCPDM_FORMATS,
231         },
232         .ops = &omap_mcpdm_dai_ops,
233         .private_data = &mcpdm_data,
234 };
235 EXPORT_SYMBOL_GPL(omap_mcpdm_dai);
236
237 static int __init snd_omap_mcpdm_init(void)
238 {
239         return snd_soc_register_dai(&omap_mcpdm_dai);
240 }
241 module_init(snd_omap_mcpdm_init);
242
243 static void __exit snd_omap_mcpdm_exit(void)
244 {
245         snd_soc_unregister_dai(&omap_mcpdm_dai);
246 }
247 module_exit(snd_omap_mcpdm_exit);
248
249 MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
250 MODULE_DESCRIPTION("OMAP PDM SoC Interface");
251 MODULE_LICENSE("GPL");