blob: 53f84085bf1fbd7c1daadc093ebd60d7f5dc7251 [file] [log] [blame]
Cliff Caiaff05102008-09-05 18:21:36 +08001/*
2 * File: sound/soc/blackfin/bf5xx-ac97-pcm.c
3 * Author: Cliff Cai <Cliff.Cai@analog.com>
4 *
5 * Created: Tue June 06 2008
6 * Description: DMA Driver for AC97 sound chip
7 *
8 * Modified:
9 * Copyright 2008 Analog Devices Inc.
10 *
11 * Bugs: Enter bugs at http://blackfin.uclinux.org/
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see the file COPYING, or write
25 * to the Free Software Foundation, Inc.,
26 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/platform_device.h>
Cliff Caiaff05102008-09-05 18:21:36 +080032#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/gfp.h>
Cliff Caiaff05102008-09-05 18:21:36 +080034
35#include <sound/core.h>
36#include <sound/pcm.h>
37#include <sound/pcm_params.h>
38#include <sound/soc.h>
39
40#include <asm/dma.h>
41
Cliff Caiaff05102008-09-05 18:21:36 +080042#include "bf5xx-ac97.h"
43#include "bf5xx-sport.h"
44
Cliff Cai67f854b2008-11-18 16:18:17 +080045static unsigned int ac97_chan_mask[] = {
46 SP_FL, /* Mono */
47 SP_STEREO, /* Stereo */
48 SP_2DOT1, /* 2.1*/
49 SP_QUAD,/*Quadraquic*/
50 SP_FL | SP_FR | SP_FC | SP_SL | SP_SR,/*5 channels */
51 SP_5DOT1, /* 5.1 */
52};
53
54#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +080055static void bf5xx_mmap_copy(struct snd_pcm_substream *substream,
56 snd_pcm_uframes_t count)
57{
58 struct snd_pcm_runtime *runtime = substream->runtime;
59 struct sport_device *sport = runtime->private_data;
Cliff Cai67f854b2008-11-18 16:18:17 +080060 unsigned int chan_mask = ac97_chan_mask[runtime->channels - 1];
Cliff Caiaff05102008-09-05 18:21:36 +080061 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Cliff Cai67f854b2008-11-18 16:18:17 +080062 bf5xx_pcm_to_ac97((struct ac97_frame *)sport->tx_dma_buf +
63 sport->tx_pos, (__u16 *)runtime->dma_area + sport->tx_pos *
64 runtime->channels, count, chan_mask);
Cliff Caiaff05102008-09-05 18:21:36 +080065 sport->tx_pos += runtime->period_size;
66 if (sport->tx_pos >= runtime->buffer_size)
67 sport->tx_pos %= runtime->buffer_size;
Cliff Cai6b58a822008-09-27 22:32:20 +080068 sport->tx_delay_pos = sport->tx_pos;
Cliff Caiaff05102008-09-05 18:21:36 +080069 } else {
Cliff Cai67f854b2008-11-18 16:18:17 +080070 bf5xx_ac97_to_pcm((struct ac97_frame *)sport->rx_dma_buf +
71 sport->rx_pos, (__u16 *)runtime->dma_area + sport->rx_pos *
72 runtime->channels, count);
Cliff Caiaff05102008-09-05 18:21:36 +080073 sport->rx_pos += runtime->period_size;
74 if (sport->rx_pos >= runtime->buffer_size)
75 sport->rx_pos %= runtime->buffer_size;
76 }
77}
78#endif
79
80static void bf5xx_dma_irq(void *data)
81{
82 struct snd_pcm_substream *pcm = data;
Cliff Cai67f854b2008-11-18 16:18:17 +080083#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +080084 struct snd_pcm_runtime *runtime = pcm->runtime;
Cliff Cai6b58a822008-09-27 22:32:20 +080085 struct sport_device *sport = runtime->private_data;
Cliff Caiaff05102008-09-05 18:21:36 +080086 bf5xx_mmap_copy(pcm, runtime->period_size);
Cliff Cai6b58a822008-09-27 22:32:20 +080087 if (pcm->stream == SNDRV_PCM_STREAM_PLAYBACK) {
88 if (sport->once == 0) {
89 snd_pcm_period_elapsed(pcm);
90 bf5xx_mmap_copy(pcm, runtime->period_size);
91 sport->once = 1;
92 }
93 }
Cliff Caiaff05102008-09-05 18:21:36 +080094#endif
95 snd_pcm_period_elapsed(pcm);
96}
97
98/* The memory size for pure pcm data is 128*1024 = 0x20000 bytes.
99 * The total rx/tx buffer is for ac97 frame to hold all pcm data
100 * is 0x20000 * sizeof(struct ac97_frame) / 4.
101 */
Cliff Caiaff05102008-09-05 18:21:36 +0800102static const struct snd_pcm_hardware bf5xx_pcm_hardware = {
103 .info = SNDRV_PCM_INFO_INTERLEAVED |
Bryan Wu27b9be52008-11-18 16:18:21 +0800104#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800105 SNDRV_PCM_INFO_MMAP |
106 SNDRV_PCM_INFO_MMAP_VALID |
Cliff Caiaff05102008-09-05 18:21:36 +0800107#endif
Bryan Wu27b9be52008-11-18 16:18:21 +0800108 SNDRV_PCM_INFO_BLOCK_TRANSFER,
109
Cliff Caiaff05102008-09-05 18:21:36 +0800110 .formats = SNDRV_PCM_FMTBIT_S16_LE,
111 .period_bytes_min = 32,
112 .period_bytes_max = 0x10000,
113 .periods_min = 1,
114 .periods_max = PAGE_SIZE/32,
115 .buffer_bytes_max = 0x20000, /* 128 kbytes */
116 .fifo_size = 16,
117};
118
119static int bf5xx_pcm_hw_params(struct snd_pcm_substream *substream,
120 struct snd_pcm_hw_params *params)
121{
122 size_t size = bf5xx_pcm_hardware.buffer_bytes_max
123 * sizeof(struct ac97_frame) / 4;
124
125 snd_pcm_lib_malloc_pages(substream, size);
126
127 return 0;
128}
129
130static int bf5xx_pcm_hw_free(struct snd_pcm_substream *substream)
131{
Cliff Cai67f854b2008-11-18 16:18:17 +0800132#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Cai6b58a822008-09-27 22:32:20 +0800133 struct snd_pcm_runtime *runtime = substream->runtime;
Cliff Cai67f854b2008-11-18 16:18:17 +0800134 struct sport_device *sport = runtime->private_data;
Cliff Cai6b58a822008-09-27 22:32:20 +0800135
Cliff Cai67f854b2008-11-18 16:18:17 +0800136 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
137 sport->once = 0;
138 if (runtime->dma_area)
139 memset(runtime->dma_area, 0, runtime->buffer_size);
140 memset(sport->tx_dma_buf, 0, runtime->buffer_size *
141 sizeof(struct ac97_frame));
142 } else
143 memset(sport->rx_dma_buf, 0, runtime->buffer_size *
144 sizeof(struct ac97_frame));
145#endif
Cliff Caiaff05102008-09-05 18:21:36 +0800146 snd_pcm_lib_free_pages(substream);
147 return 0;
148}
149
150static int bf5xx_pcm_prepare(struct snd_pcm_substream *substream)
151{
152 struct snd_pcm_runtime *runtime = substream->runtime;
153 struct sport_device *sport = runtime->private_data;
154
155 /* An intermediate buffer is introduced for implementing mmap for
156 * SPORT working in TMD mode(include AC97).
157 */
Cliff Cai67f854b2008-11-18 16:18:17 +0800158#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800159 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Cliff Caiaff05102008-09-05 18:21:36 +0800160 sport_set_tx_callback(sport, bf5xx_dma_irq, substream);
161 sport_config_tx_dma(sport, sport->tx_dma_buf, runtime->periods,
162 runtime->period_size * sizeof(struct ac97_frame));
163 } else {
Cliff Caiaff05102008-09-05 18:21:36 +0800164 sport_set_rx_callback(sport, bf5xx_dma_irq, substream);
165 sport_config_rx_dma(sport, sport->rx_dma_buf, runtime->periods,
166 runtime->period_size * sizeof(struct ac97_frame));
167 }
168#else
169 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
170 sport_set_tx_callback(sport, bf5xx_dma_irq, substream);
171 sport_config_tx_dma(sport, runtime->dma_area, runtime->periods,
172 runtime->period_size * sizeof(struct ac97_frame));
173 } else {
174 sport_set_rx_callback(sport, bf5xx_dma_irq, substream);
175 sport_config_rx_dma(sport, runtime->dma_area, runtime->periods,
176 runtime->period_size * sizeof(struct ac97_frame));
177 }
178#endif
179 return 0;
180}
181
182static int bf5xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
183{
184 struct snd_pcm_runtime *runtime = substream->runtime;
185 struct sport_device *sport = runtime->private_data;
186 int ret = 0;
187
188 pr_debug("%s enter\n", __func__);
189 switch (cmd) {
190 case SNDRV_PCM_TRIGGER_START:
Cliff Cai6b58a822008-09-27 22:32:20 +0800191 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Cliff Caia89e6112008-11-18 16:18:18 +0800192#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Cai6b58a822008-09-27 22:32:20 +0800193 bf5xx_mmap_copy(substream, runtime->period_size);
Cliff Cai6b58a822008-09-27 22:32:20 +0800194 sport->tx_delay_pos = 0;
Cliff Caia89e6112008-11-18 16:18:18 +0800195#endif
Cliff Caiaff05102008-09-05 18:21:36 +0800196 sport_tx_start(sport);
Cliff Cai67f854b2008-11-18 16:18:17 +0800197 } else
Cliff Caiaff05102008-09-05 18:21:36 +0800198 sport_rx_start(sport);
199 break;
200 case SNDRV_PCM_TRIGGER_STOP:
201 case SNDRV_PCM_TRIGGER_SUSPEND:
202 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
203 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Cliff Cai67f854b2008-11-18 16:18:17 +0800204#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800205 sport->tx_pos = 0;
206#endif
207 sport_tx_stop(sport);
208 } else {
Cliff Cai67f854b2008-11-18 16:18:17 +0800209#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800210 sport->rx_pos = 0;
211#endif
212 sport_rx_stop(sport);
213 }
214 break;
215 default:
216 ret = -EINVAL;
217 }
218 return ret;
219}
220
221static snd_pcm_uframes_t bf5xx_pcm_pointer(struct snd_pcm_substream *substream)
222{
223 struct snd_pcm_runtime *runtime = substream->runtime;
224 struct sport_device *sport = runtime->private_data;
225 unsigned int curr;
226
Cliff Cai67f854b2008-11-18 16:18:17 +0800227#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800228 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Cliff Cai6b58a822008-09-27 22:32:20 +0800229 curr = sport->tx_delay_pos;
Cliff Caiaff05102008-09-05 18:21:36 +0800230 else
231 curr = sport->rx_pos;
232#else
233
234 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
235 curr = sport_curr_offset_tx(sport) / sizeof(struct ac97_frame);
236 else
237 curr = sport_curr_offset_rx(sport) / sizeof(struct ac97_frame);
238
239#endif
240 return curr;
241}
242
243static int bf5xx_pcm_open(struct snd_pcm_substream *substream)
244{
Barry Song2c66cb92011-03-28 01:45:10 -0400245 struct snd_soc_pcm_runtime *rtd = substream->private_data;
246 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
247 struct sport_device *sport_handle = snd_soc_dai_get_drvdata(cpu_dai);
Cliff Caiaff05102008-09-05 18:21:36 +0800248 struct snd_pcm_runtime *runtime = substream->runtime;
249 int ret;
250
251 pr_debug("%s enter\n", __func__);
252 snd_soc_set_runtime_hwparams(substream, &bf5xx_pcm_hardware);
253
254 ret = snd_pcm_hw_constraint_integer(runtime,
255 SNDRV_PCM_HW_PARAM_PERIODS);
256 if (ret < 0)
257 goto out;
258
259 if (sport_handle != NULL)
260 runtime->private_data = sport_handle;
261 else {
262 pr_err("sport_handle is NULL\n");
263 return -1;
264 }
265 return 0;
266
267 out:
268 return ret;
269}
270
Cliff Cai67f854b2008-11-18 16:18:17 +0800271#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800272static int bf5xx_pcm_mmap(struct snd_pcm_substream *substream,
273 struct vm_area_struct *vma)
274{
275 struct snd_pcm_runtime *runtime = substream->runtime;
276 size_t size = vma->vm_end - vma->vm_start;
277 vma->vm_start = (unsigned long)runtime->dma_area;
278 vma->vm_end = vma->vm_start + size;
279 vma->vm_flags |= VM_SHARED;
280 return 0 ;
281}
282#else
283static int bf5xx_pcm_copy(struct snd_pcm_substream *substream, int channel,
284 snd_pcm_uframes_t pos,
285 void __user *buf, snd_pcm_uframes_t count)
286{
287 struct snd_pcm_runtime *runtime = substream->runtime;
Cliff Caia89e6112008-11-18 16:18:18 +0800288 unsigned int chan_mask = ac97_chan_mask[runtime->channels - 1];
Cliff Caiaff05102008-09-05 18:21:36 +0800289 pr_debug("%s copy pos:0x%lx count:0x%lx\n",
290 substream->stream ? "Capture" : "Playback", pos, count);
291
292 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Cliff Cai67f854b2008-11-18 16:18:17 +0800293 bf5xx_pcm_to_ac97((struct ac97_frame *)runtime->dma_area + pos,
294 (__u16 *)buf, count, chan_mask);
Cliff Caiaff05102008-09-05 18:21:36 +0800295 else
Cliff Cai67f854b2008-11-18 16:18:17 +0800296 bf5xx_ac97_to_pcm((struct ac97_frame *)runtime->dma_area + pos,
297 (__u16 *)buf, count);
Cliff Caiaff05102008-09-05 18:21:36 +0800298 return 0;
299}
300#endif
301
Mark Brownb2a19d02009-01-17 19:14:26 +0000302static struct snd_pcm_ops bf5xx_pcm_ac97_ops = {
Cliff Caiaff05102008-09-05 18:21:36 +0800303 .open = bf5xx_pcm_open,
Cliff Caiaff05102008-09-05 18:21:36 +0800304 .ioctl = snd_pcm_lib_ioctl,
305 .hw_params = bf5xx_pcm_hw_params,
306 .hw_free = bf5xx_pcm_hw_free,
307 .prepare = bf5xx_pcm_prepare,
308 .trigger = bf5xx_pcm_trigger,
309 .pointer = bf5xx_pcm_pointer,
Cliff Cai67f854b2008-11-18 16:18:17 +0800310#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800311 .mmap = bf5xx_pcm_mmap,
312#else
313 .copy = bf5xx_pcm_copy,
314#endif
315};
316
317static int bf5xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
318{
Barry Song2c66cb92011-03-28 01:45:10 -0400319 struct snd_soc_pcm_runtime *rtd = pcm->private_data;
320 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
321 struct sport_device *sport_handle = snd_soc_dai_get_drvdata(cpu_dai);
Cliff Caiaff05102008-09-05 18:21:36 +0800322 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
323 struct snd_dma_buffer *buf = &substream->dma_buffer;
324 size_t size = bf5xx_pcm_hardware.buffer_bytes_max
325 * sizeof(struct ac97_frame) / 4;
326
327 buf->dev.type = SNDRV_DMA_TYPE_DEV;
328 buf->dev.dev = pcm->card->dev;
329 buf->private_data = NULL;
330 buf->area = dma_alloc_coherent(pcm->card->dev, size,
331 &buf->addr, GFP_KERNEL);
332 if (!buf->area) {
333 pr_err("Failed to allocate dma memory\n");
334 pr_err("Please increase uncached DMA memory region\n");
335 return -ENOMEM;
336 }
337 buf->bytes = size;
338
339 pr_debug("%s, area:%p, size:0x%08lx\n", __func__,
340 buf->area, buf->bytes);
341
342 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
343 sport_handle->tx_buf = buf->area;
344 else
345 sport_handle->rx_buf = buf->area;
346
347/*
348 * Need to allocate local buffer when enable
349 * MMAP for SPORT working in TMD mode (include AC97).
350 */
Cliff Cai67f854b2008-11-18 16:18:17 +0800351#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800352 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
353 if (!sport_handle->tx_dma_buf) {
354 sport_handle->tx_dma_buf = dma_alloc_coherent(NULL, \
355 size, &sport_handle->tx_dma_phy, GFP_KERNEL);
356 if (!sport_handle->tx_dma_buf) {
Joe Perches2f1ff662010-01-31 12:02:12 -0800357 pr_err("Failed to allocate memory for tx dma buf - Please increase uncached DMA memory region\n");
Cliff Caiaff05102008-09-05 18:21:36 +0800358 return -ENOMEM;
359 } else
360 memset(sport_handle->tx_dma_buf, 0, size);
361 } else
362 memset(sport_handle->tx_dma_buf, 0, size);
363 } else {
364 if (!sport_handle->rx_dma_buf) {
365 sport_handle->rx_dma_buf = dma_alloc_coherent(NULL, \
366 size, &sport_handle->rx_dma_phy, GFP_KERNEL);
367 if (!sport_handle->rx_dma_buf) {
Joe Perches2f1ff662010-01-31 12:02:12 -0800368 pr_err("Failed to allocate memory for rx dma buf - Please increase uncached DMA memory region\n");
Cliff Caiaff05102008-09-05 18:21:36 +0800369 return -ENOMEM;
370 } else
371 memset(sport_handle->rx_dma_buf, 0, size);
372 } else
373 memset(sport_handle->rx_dma_buf, 0, size);
374 }
375#endif
376 return 0;
377}
378
379static void bf5xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
380{
381 struct snd_pcm_substream *substream;
382 struct snd_dma_buffer *buf;
383 int stream;
Cliff Cai67f854b2008-11-18 16:18:17 +0800384#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Barry Song2c66cb92011-03-28 01:45:10 -0400385 struct snd_soc_pcm_runtime *rtd = pcm->private_data;
386 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
387 struct sport_device *sport_handle = snd_soc_dai_get_drvdata(cpu_dai);
Cliff Caiaff05102008-09-05 18:21:36 +0800388 size_t size = bf5xx_pcm_hardware.buffer_bytes_max *
389 sizeof(struct ac97_frame) / 4;
390#endif
391 for (stream = 0; stream < 2; stream++) {
392 substream = pcm->streams[stream].substream;
393 if (!substream)
394 continue;
395
396 buf = &substream->dma_buffer;
397 if (!buf->area)
398 continue;
399 dma_free_coherent(NULL, buf->bytes, buf->area, 0);
400 buf->area = NULL;
Cliff Cai67f854b2008-11-18 16:18:17 +0800401#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800402 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
403 if (sport_handle->tx_dma_buf)
404 dma_free_coherent(NULL, size, \
405 sport_handle->tx_dma_buf, 0);
406 sport_handle->tx_dma_buf = NULL;
407 } else {
408
409 if (sport_handle->rx_dma_buf)
410 dma_free_coherent(NULL, size, \
411 sport_handle->rx_dma_buf, 0);
412 sport_handle->rx_dma_buf = NULL;
413 }
414#endif
415 }
Cliff Caiaff05102008-09-05 18:21:36 +0800416}
417
Yang Hongyang284901a2009-04-06 19:01:15 -0700418static u64 bf5xx_pcm_dmamask = DMA_BIT_MASK(32);
Cliff Caiaff05102008-09-05 18:21:36 +0800419
Axel Lin3156cf72011-09-21 14:40:05 +0800420static int bf5xx_pcm_ac97_new(struct snd_soc_pcm_runtime *rtd)
Cliff Caiaff05102008-09-05 18:21:36 +0800421{
Liam Girdwood552d1ef2011-06-07 16:08:33 +0100422 struct snd_card *card = rtd->card->snd_card;
Liam Girdwood552d1ef2011-06-07 16:08:33 +0100423 struct snd_pcm *pcm = rtd->pcm;
Cliff Caiaff05102008-09-05 18:21:36 +0800424 int ret = 0;
425
426 pr_debug("%s enter\n", __func__);
427 if (!card->dev->dma_mask)
428 card->dev->dma_mask = &bf5xx_pcm_dmamask;
429 if (!card->dev->coherent_dma_mask)
Yang Hongyang284901a2009-04-06 19:01:15 -0700430 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
Cliff Caiaff05102008-09-05 18:21:36 +0800431
Joachim Eastwood25e9e752012-01-01 01:58:44 +0100432 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
Cliff Caiaff05102008-09-05 18:21:36 +0800433 ret = bf5xx_pcm_preallocate_dma_buffer(pcm,
434 SNDRV_PCM_STREAM_PLAYBACK);
435 if (ret)
436 goto out;
437 }
438
Joachim Eastwood25e9e752012-01-01 01:58:44 +0100439 if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
Cliff Caiaff05102008-09-05 18:21:36 +0800440 ret = bf5xx_pcm_preallocate_dma_buffer(pcm,
441 SNDRV_PCM_STREAM_CAPTURE);
442 if (ret)
443 goto out;
444 }
445 out:
446 return ret;
447}
448
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000449static struct snd_soc_platform_driver bf5xx_ac97_soc_platform = {
450 .ops = &bf5xx_pcm_ac97_ops,
Cliff Caiaff05102008-09-05 18:21:36 +0800451 .pcm_new = bf5xx_pcm_ac97_new,
452 .pcm_free = bf5xx_pcm_free_dma_buffers,
453};
Cliff Caiaff05102008-09-05 18:21:36 +0800454
Bill Pembertondca66da2012-12-07 09:26:13 -0500455static int bf5xx_soc_platform_probe(struct platform_device *pdev)
Mark Brown958e7922008-12-03 19:58:17 +0000456{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000457 return snd_soc_register_platform(&pdev->dev, &bf5xx_ac97_soc_platform);
Mark Brown958e7922008-12-03 19:58:17 +0000458}
Mark Brown958e7922008-12-03 19:58:17 +0000459
Bill Pembertondca66da2012-12-07 09:26:13 -0500460static int bf5xx_soc_platform_remove(struct platform_device *pdev)
Mark Brown958e7922008-12-03 19:58:17 +0000461{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000462 snd_soc_unregister_platform(&pdev->dev);
463 return 0;
Mark Brown958e7922008-12-03 19:58:17 +0000464}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000465
466static struct platform_driver bf5xx_pcm_driver = {
467 .driver = {
Mike Frysingerbfe4ee02011-03-28 01:45:09 -0400468 .name = "bfin-ac97-pcm-audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000469 .owner = THIS_MODULE,
470 },
471
472 .probe = bf5xx_soc_platform_probe,
Bill Pembertondca66da2012-12-07 09:26:13 -0500473 .remove = bf5xx_soc_platform_remove,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000474};
475
Axel Linfb802972011-11-24 14:44:52 +0800476module_platform_driver(bf5xx_pcm_driver);
Mark Brown958e7922008-12-03 19:58:17 +0000477
Cliff Caiaff05102008-09-05 18:21:36 +0800478MODULE_AUTHOR("Cliff Cai");
479MODULE_DESCRIPTION("ADI Blackfin AC97 PCM DMA module");
480MODULE_LICENSE("GPL");