blob: 0e25df4fa9e5cf20e380582a36082e23596d2f0b [file] [log] [blame]
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -06001/*
2 * omap-mcpdm.c -- OMAP ALSA SoC DAI driver using McPDM port
3 *
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +03004 * Copyright (C) 2009 - 2011 Texas Instruments
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -06005 *
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +03006 * Author: Misael Lopez Cruz <misael.lopez@ti.com>
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -06007 * Contact: Jorge Eduardo Candelaria <x0107209@ti.com>
8 * Margarita Olaya <magi.olaya@ti.com>
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +03009 * Peter Ujfalusi <peter.ujfalusi@ti.com>
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -060010 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * version 2 as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 * 02110-1301 USA
24 *
25 */
26
27#include <linux/init.h>
28#include <linux/module.h>
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +030029#include <linux/platform_device.h>
30#include <linux/interrupt.h>
31#include <linux/err.h>
32#include <linux/io.h>
33#include <linux/irq.h>
34#include <linux/slab.h>
35#include <linux/pm_runtime.h>
36
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -060037#include <sound/core.h>
38#include <sound/pcm.h>
39#include <sound/pcm_params.h>
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -060040#include <sound/soc.h>
41
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -060042#include <plat/dma.h>
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +030043#include <plat/omap_hwmod.h>
44#include "omap-mcpdm.h"
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -060045#include "omap-pcm.h"
46
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +030047struct omap_mcpdm {
48 struct device *dev;
49 unsigned long phys_base;
50 void __iomem *io_base;
51 int irq;
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -060052
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +030053 struct mutex mutex;
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -060054
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +030055 /* channel data */
56 u32 dn_channels;
57 u32 up_channels;
58
59 /* McPDM FIFO thresholds */
60 u32 dn_threshold;
61 u32 up_threshold;
Peter Ujfalusi89b0d552011-09-26 16:05:58 +030062
63 /* McPDM dn offsets for rx1, and 2 channels */
64 u32 dn_rx_offset;
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -060065};
66
67/*
68 * Stream DMA parameters
69 */
70static struct omap_pcm_dma_data omap_mcpdm_dai_dma_params[] = {
71 {
72 .name = "Audio playback",
73 .dma_req = OMAP44XX_DMA_MCPDM_DL,
74 .data_type = OMAP_DMA_DATA_TYPE_S32,
75 .sync_mode = OMAP_DMA_SYNC_PACKET,
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +030076 .port_addr = OMAP44XX_MCPDM_L3_BASE + MCPDM_REG_DN_DATA,
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -060077 },
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,
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +030083 .port_addr = OMAP44XX_MCPDM_L3_BASE + MCPDM_REG_UP_DATA,
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -060084 },
85};
86
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +030087static inline void omap_mcpdm_write(struct omap_mcpdm *mcpdm, u16 reg, u32 val)
88{
89 __raw_writel(val, mcpdm->io_base + reg);
90}
91
92static inline int omap_mcpdm_read(struct omap_mcpdm *mcpdm, u16 reg)
93{
94 return __raw_readl(mcpdm->io_base + reg);
95}
96
97#ifdef DEBUG
98static void omap_mcpdm_reg_dump(struct omap_mcpdm *mcpdm)
99{
100 dev_dbg(mcpdm->dev, "***********************\n");
101 dev_dbg(mcpdm->dev, "IRQSTATUS_RAW: 0x%04x\n",
102 omap_mcpdm_read(mcpdm, MCPDM_REG_IRQSTATUS_RAW));
103 dev_dbg(mcpdm->dev, "IRQSTATUS: 0x%04x\n",
104 omap_mcpdm_read(mcpdm, MCPDM_REG_IRQSTATUS));
105 dev_dbg(mcpdm->dev, "IRQENABLE_SET: 0x%04x\n",
106 omap_mcpdm_read(mcpdm, MCPDM_REG_IRQENABLE_SET));
107 dev_dbg(mcpdm->dev, "IRQENABLE_CLR: 0x%04x\n",
108 omap_mcpdm_read(mcpdm, MCPDM_REG_IRQENABLE_CLR));
109 dev_dbg(mcpdm->dev, "IRQWAKE_EN: 0x%04x\n",
110 omap_mcpdm_read(mcpdm, MCPDM_REG_IRQWAKE_EN));
111 dev_dbg(mcpdm->dev, "DMAENABLE_SET: 0x%04x\n",
112 omap_mcpdm_read(mcpdm, MCPDM_REG_DMAENABLE_SET));
113 dev_dbg(mcpdm->dev, "DMAENABLE_CLR: 0x%04x\n",
114 omap_mcpdm_read(mcpdm, MCPDM_REG_DMAENABLE_CLR));
115 dev_dbg(mcpdm->dev, "DMAWAKEEN: 0x%04x\n",
116 omap_mcpdm_read(mcpdm, MCPDM_REG_DMAWAKEEN));
117 dev_dbg(mcpdm->dev, "CTRL: 0x%04x\n",
118 omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL));
119 dev_dbg(mcpdm->dev, "DN_DATA: 0x%04x\n",
120 omap_mcpdm_read(mcpdm, MCPDM_REG_DN_DATA));
121 dev_dbg(mcpdm->dev, "UP_DATA: 0x%04x\n",
122 omap_mcpdm_read(mcpdm, MCPDM_REG_UP_DATA));
123 dev_dbg(mcpdm->dev, "FIFO_CTRL_DN: 0x%04x\n",
124 omap_mcpdm_read(mcpdm, MCPDM_REG_FIFO_CTRL_DN));
125 dev_dbg(mcpdm->dev, "FIFO_CTRL_UP: 0x%04x\n",
126 omap_mcpdm_read(mcpdm, MCPDM_REG_FIFO_CTRL_UP));
127 dev_dbg(mcpdm->dev, "***********************\n");
128}
129#else
130static void omap_mcpdm_reg_dump(struct omap_mcpdm *mcpdm) {}
131#endif
132
133/*
134 * Enables the transfer through the PDM interface to/from the Phoenix
135 * codec by enabling the corresponding UP or DN channels.
136 */
137static void omap_mcpdm_start(struct omap_mcpdm *mcpdm)
138{
139 u32 ctrl = omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL);
140
141 ctrl |= (MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
142 omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
143
144 ctrl |= mcpdm->dn_channels | mcpdm->up_channels;
145 omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
146
147 ctrl &= ~(MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
148 omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
149}
150
151/*
152 * Disables the transfer through the PDM interface to/from the Phoenix
153 * codec by disabling the corresponding UP or DN channels.
154 */
155static void omap_mcpdm_stop(struct omap_mcpdm *mcpdm)
156{
157 u32 ctrl = omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL);
158
159 ctrl |= (MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
160 omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
161
162 ctrl &= ~(mcpdm->dn_channels | mcpdm->up_channels);
163 omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
164
165 ctrl &= ~(MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
166 omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
167
168}
169
170/*
171 * Is the physical McPDM interface active.
172 */
173static inline int omap_mcpdm_active(struct omap_mcpdm *mcpdm)
174{
175 return omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL) &
176 (MCPDM_PDM_DN_MASK | MCPDM_PDM_UP_MASK);
177}
178
179/*
180 * Configures McPDM uplink, and downlink for audio.
181 * This function should be called before omap_mcpdm_start.
182 */
183static void omap_mcpdm_open_streams(struct omap_mcpdm *mcpdm)
184{
185 omap_mcpdm_write(mcpdm, MCPDM_REG_IRQENABLE_SET,
186 MCPDM_DN_IRQ_EMPTY | MCPDM_DN_IRQ_FULL |
187 MCPDM_UP_IRQ_EMPTY | MCPDM_UP_IRQ_FULL);
188
Peter Ujfalusi89b0d552011-09-26 16:05:58 +0300189 /* Enable DN RX1/2 offset cancellation feature, if configured */
190 if (mcpdm->dn_rx_offset) {
191 u32 dn_offset = mcpdm->dn_rx_offset;
192
193 omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, dn_offset);
194 dn_offset |= (MCPDM_DN_OFST_RX1_EN | MCPDM_DN_OFST_RX2_EN);
195 omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, dn_offset);
196 }
197
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300198 omap_mcpdm_write(mcpdm, MCPDM_REG_FIFO_CTRL_DN, mcpdm->dn_threshold);
199 omap_mcpdm_write(mcpdm, MCPDM_REG_FIFO_CTRL_UP, mcpdm->up_threshold);
200
201 omap_mcpdm_write(mcpdm, MCPDM_REG_DMAENABLE_SET,
202 MCPDM_DMA_DN_ENABLE | MCPDM_DMA_UP_ENABLE);
203}
204
205/*
206 * Cleans McPDM uplink, and downlink configuration.
207 * This function should be called when the stream is closed.
208 */
209static void omap_mcpdm_close_streams(struct omap_mcpdm *mcpdm)
210{
211 /* Disable irq request generation for downlink */
212 omap_mcpdm_write(mcpdm, MCPDM_REG_IRQENABLE_CLR,
213 MCPDM_DN_IRQ_EMPTY | MCPDM_DN_IRQ_FULL);
214
215 /* Disable DMA request generation for downlink */
216 omap_mcpdm_write(mcpdm, MCPDM_REG_DMAENABLE_CLR, MCPDM_DMA_DN_ENABLE);
217
218 /* Disable irq request generation for uplink */
219 omap_mcpdm_write(mcpdm, MCPDM_REG_IRQENABLE_CLR,
220 MCPDM_UP_IRQ_EMPTY | MCPDM_UP_IRQ_FULL);
221
222 /* Disable DMA request generation for uplink */
223 omap_mcpdm_write(mcpdm, MCPDM_REG_DMAENABLE_CLR, MCPDM_DMA_UP_ENABLE);
Peter Ujfalusi89b0d552011-09-26 16:05:58 +0300224
225 /* Disable RX1/2 offset cancellation */
226 if (mcpdm->dn_rx_offset)
227 omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, 0);
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300228}
229
230static irqreturn_t omap_mcpdm_irq_handler(int irq, void *dev_id)
231{
232 struct omap_mcpdm *mcpdm = dev_id;
233 int irq_status;
234
235 irq_status = omap_mcpdm_read(mcpdm, MCPDM_REG_IRQSTATUS);
236
237 /* Acknowledge irq event */
238 omap_mcpdm_write(mcpdm, MCPDM_REG_IRQSTATUS, irq_status);
239
240 if (irq_status & MCPDM_DN_IRQ_FULL)
241 dev_dbg(mcpdm->dev, "DN (playback) FIFO Full\n");
242
243 if (irq_status & MCPDM_DN_IRQ_EMPTY)
244 dev_dbg(mcpdm->dev, "DN (playback) FIFO Empty\n");
245
246 if (irq_status & MCPDM_DN_IRQ)
247 dev_dbg(mcpdm->dev, "DN (playback) write request\n");
248
249 if (irq_status & MCPDM_UP_IRQ_FULL)
250 dev_dbg(mcpdm->dev, "UP (capture) FIFO Full\n");
251
252 if (irq_status & MCPDM_UP_IRQ_EMPTY)
253 dev_dbg(mcpdm->dev, "UP (capture) FIFO Empty\n");
254
255 if (irq_status & MCPDM_UP_IRQ)
256 dev_dbg(mcpdm->dev, "UP (capture) write request\n");
257
258 return IRQ_HANDLED;
259}
260
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600261static int omap_mcpdm_dai_startup(struct snd_pcm_substream *substream,
262 struct snd_soc_dai *dai)
263{
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300264 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600265
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300266 mutex_lock(&mcpdm->mutex);
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600267
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300268 if (!dai->active) {
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300269 /* Enable watch dog for ES above ES 1.0 to avoid saturation */
270 if (omap_rev() != OMAP4430_REV_ES1_0) {
271 u32 ctrl = omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL);
272
273 omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL,
274 ctrl | MCPDM_WD_EN);
275 }
276 omap_mcpdm_open_streams(mcpdm);
277 }
278
279 mutex_unlock(&mcpdm->mutex);
280
281 return 0;
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600282}
283
284static void omap_mcpdm_dai_shutdown(struct snd_pcm_substream *substream,
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600285 struct snd_soc_dai *dai)
286{
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300287 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600288
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300289 mutex_lock(&mcpdm->mutex);
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600290
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300291 if (!dai->active) {
292 if (omap_mcpdm_active(mcpdm)) {
293 omap_mcpdm_stop(mcpdm);
294 omap_mcpdm_close_streams(mcpdm);
295 }
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600296 }
297
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300298 mutex_unlock(&mcpdm->mutex);
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600299}
300
301static int omap_mcpdm_dai_hw_params(struct snd_pcm_substream *substream,
302 struct snd_pcm_hw_params *params,
303 struct snd_soc_dai *dai)
304{
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300305 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600306 int stream = substream->stream;
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300307 struct omap_pcm_dma_data *dma_data;
308 int channels;
309 int link_mask = 0;
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600310
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600311 channels = params_channels(params);
312 switch (channels) {
Peter Ujfalusi3b5b516f2011-09-23 09:49:43 +0300313 case 5:
314 if (stream == SNDRV_PCM_STREAM_CAPTURE)
315 /* up to 3 channels for capture */
316 return -EINVAL;
317 link_mask |= 1 << 4;
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600318 case 4:
319 if (stream == SNDRV_PCM_STREAM_CAPTURE)
Peter Ujfalusi3b5b516f2011-09-23 09:49:43 +0300320 /* up to 3 channels for capture */
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600321 return -EINVAL;
322 link_mask |= 1 << 3;
323 case 3:
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600324 link_mask |= 1 << 2;
325 case 2:
326 link_mask |= 1 << 1;
327 case 1:
328 link_mask |= 1 << 0;
329 break;
330 default:
331 /* unsupported number of channels */
332 return -EINVAL;
333 }
334
Peter Ujfalusib199adf2011-08-02 13:35:30 +0300335 dma_data = &omap_mcpdm_dai_dma_params[stream];
Peter Ujfalusib199adf2011-08-02 13:35:30 +0300336
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300337 /* Configure McPDM channels, and DMA packet size */
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600338 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300339 mcpdm->dn_channels = link_mask << 3;
340 dma_data->packet_size =
341 (MCPDM_DN_THRES_MAX - mcpdm->dn_threshold) * channels;
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600342 } else {
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300343 mcpdm->up_channels = link_mask << 0;
344 dma_data->packet_size = mcpdm->up_threshold * channels;
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600345 }
346
Peter Ujfalusib199adf2011-08-02 13:35:30 +0300347 snd_soc_dai_set_dma_data(dai, substream, dma_data);
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300348
349 return 0;
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600350}
351
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300352static int omap_mcpdm_prepare(struct snd_pcm_substream *substream,
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600353 struct snd_soc_dai *dai)
354{
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300355 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600356
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300357 if (!omap_mcpdm_active(mcpdm)) {
358 omap_mcpdm_start(mcpdm);
359 omap_mcpdm_reg_dump(mcpdm);
360 }
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600361
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300362 return 0;
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600363}
364
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100365static const struct snd_soc_dai_ops omap_mcpdm_dai_ops = {
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600366 .startup = omap_mcpdm_dai_startup,
367 .shutdown = omap_mcpdm_dai_shutdown,
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600368 .hw_params = omap_mcpdm_dai_hw_params,
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300369 .prepare = omap_mcpdm_prepare,
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600370};
371
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300372static int omap_mcpdm_probe(struct snd_soc_dai *dai)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000373{
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300374 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
375 int ret;
376
377 pm_runtime_enable(mcpdm->dev);
378
379 /* Disable lines while request is ongoing */
380 pm_runtime_get_sync(mcpdm->dev);
381 omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, 0x00);
382
383 ret = request_irq(mcpdm->irq, omap_mcpdm_irq_handler,
384 0, "McPDM", (void *)mcpdm);
385
386 pm_runtime_put_sync(mcpdm->dev);
387
388 if (ret) {
389 dev_err(mcpdm->dev, "Request for IRQ failed\n");
390 pm_runtime_disable(mcpdm->dev);
391 }
392
393 /* Configure McPDM threshold values */
394 mcpdm->dn_threshold = 2;
395 mcpdm->up_threshold = MCPDM_UP_THRES_MAX - 3;
396 return ret;
397}
398
399static int omap_mcpdm_remove(struct snd_soc_dai *dai)
400{
401 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
402
403 free_irq(mcpdm->irq, (void *)mcpdm);
404 pm_runtime_disable(mcpdm->dev);
405
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000406 return 0;
407}
408
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300409#define OMAP_MCPDM_RATES (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
410#define OMAP_MCPDM_FORMATS SNDRV_PCM_FMTBIT_S32_LE
411
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000412static struct snd_soc_dai_driver omap_mcpdm_dai = {
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300413 .probe = omap_mcpdm_probe,
414 .remove = omap_mcpdm_remove,
415 .probe_order = SND_SOC_COMP_ORDER_LATE,
416 .remove_order = SND_SOC_COMP_ORDER_EARLY,
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600417 .playback = {
418 .channels_min = 1,
Peter Ujfalusi3b5b516f2011-09-23 09:49:43 +0300419 .channels_max = 5,
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600420 .rates = OMAP_MCPDM_RATES,
421 .formats = OMAP_MCPDM_FORMATS,
422 },
423 .capture = {
424 .channels_min = 1,
Peter Ujfalusi3b5b516f2011-09-23 09:49:43 +0300425 .channels_max = 3,
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600426 .rates = OMAP_MCPDM_RATES,
427 .formats = OMAP_MCPDM_FORMATS,
428 },
429 .ops = &omap_mcpdm_dai_ops,
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600430};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000431
Peter Ujfalusi89b0d552011-09-26 16:05:58 +0300432void omap_mcpdm_configure_dn_offsets(struct snd_soc_pcm_runtime *rtd,
433 u8 rx1, u8 rx2)
434{
435 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(rtd->cpu_dai);
436
437 mcpdm->dn_rx_offset = MCPDM_DNOFST_RX1(rx1) | MCPDM_DNOFST_RX2(rx2);
438}
439EXPORT_SYMBOL_GPL(omap_mcpdm_configure_dn_offsets);
440
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000441static __devinit int asoc_mcpdm_probe(struct platform_device *pdev)
442{
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300443 struct omap_mcpdm *mcpdm;
444 struct resource *res;
445 int ret = 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000446
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300447 mcpdm = kzalloc(sizeof(struct omap_mcpdm), GFP_KERNEL);
448 if (!mcpdm)
449 return -ENOMEM;
450
451 platform_set_drvdata(pdev, mcpdm);
452
453 mutex_init(&mcpdm->mutex);
454
455 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
456 if (res == NULL) {
457 dev_err(&pdev->dev, "no resource\n");
458 goto err_res;
459 }
460
461 if (!request_mem_region(res->start, resource_size(res), "McPDM")) {
462 ret = -EBUSY;
463 goto err_res;
464 }
465
466 mcpdm->io_base = ioremap(res->start, resource_size(res));
467 if (!mcpdm->io_base) {
468 ret = -ENOMEM;
469 goto err_iomap;
470 }
471
472 mcpdm->irq = platform_get_irq(pdev, 0);
473 if (mcpdm->irq < 0) {
474 ret = mcpdm->irq;
475 goto err_irq;
476 }
477
478 mcpdm->dev = &pdev->dev;
479
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000480 ret = snd_soc_register_dai(&pdev->dev, &omap_mcpdm_dai);
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300481 if (!ret)
482 return 0;
483
484err_irq:
485 iounmap(mcpdm->io_base);
486err_iomap:
487 release_mem_region(res->start, resource_size(res));
488err_res:
489 kfree(mcpdm);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000490 return ret;
491}
492
493static int __devexit asoc_mcpdm_remove(struct platform_device *pdev)
494{
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300495 struct omap_mcpdm *mcpdm = platform_get_drvdata(pdev);
496 struct resource *res;
497
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000498 snd_soc_unregister_dai(&pdev->dev);
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300499
500 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
501 iounmap(mcpdm->io_base);
502 release_mem_region(res->start, resource_size(res));
503
504 kfree(mcpdm);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000505 return 0;
506}
507
508static struct platform_driver asoc_mcpdm_driver = {
509 .driver = {
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300510 .name = "omap-mcpdm",
511 .owner = THIS_MODULE,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000512 },
513
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300514 .probe = asoc_mcpdm_probe,
515 .remove = __devexit_p(asoc_mcpdm_remove),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000516};
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600517
Axel Linbeda5bf52011-11-25 10:12:16 +0800518module_platform_driver(asoc_mcpdm_driver);
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600519
Misael Lopez Cruzf5f9d7b2011-07-05 19:50:45 +0300520MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");
Misael Lopez Cruzdb72c2f2010-02-22 15:09:22 -0600521MODULE_DESCRIPTION("OMAP PDM SoC Interface");
522MODULE_LICENSE("GPL");