blob: 56815c1d47b3fdb36f278e05894fc54a6ace93d7 [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
42#include "bf5xx-ac97-pcm.h"
43#include "bf5xx-ac97.h"
44#include "bf5xx-sport.h"
45
Cliff Cai67f854b2008-11-18 16:18:17 +080046static unsigned int ac97_chan_mask[] = {
47 SP_FL, /* Mono */
48 SP_STEREO, /* Stereo */
49 SP_2DOT1, /* 2.1*/
50 SP_QUAD,/*Quadraquic*/
51 SP_FL | SP_FR | SP_FC | SP_SL | SP_SR,/*5 channels */
52 SP_5DOT1, /* 5.1 */
53};
54
55#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +080056static void bf5xx_mmap_copy(struct snd_pcm_substream *substream,
57 snd_pcm_uframes_t count)
58{
59 struct snd_pcm_runtime *runtime = substream->runtime;
60 struct sport_device *sport = runtime->private_data;
Cliff Cai67f854b2008-11-18 16:18:17 +080061 unsigned int chan_mask = ac97_chan_mask[runtime->channels - 1];
Cliff Caiaff05102008-09-05 18:21:36 +080062 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Cliff Cai67f854b2008-11-18 16:18:17 +080063 bf5xx_pcm_to_ac97((struct ac97_frame *)sport->tx_dma_buf +
64 sport->tx_pos, (__u16 *)runtime->dma_area + sport->tx_pos *
65 runtime->channels, count, chan_mask);
Cliff Caiaff05102008-09-05 18:21:36 +080066 sport->tx_pos += runtime->period_size;
67 if (sport->tx_pos >= runtime->buffer_size)
68 sport->tx_pos %= runtime->buffer_size;
Cliff Cai6b58a822008-09-27 22:32:20 +080069 sport->tx_delay_pos = sport->tx_pos;
Cliff Caiaff05102008-09-05 18:21:36 +080070 } else {
Cliff Cai67f854b2008-11-18 16:18:17 +080071 bf5xx_ac97_to_pcm((struct ac97_frame *)sport->rx_dma_buf +
72 sport->rx_pos, (__u16 *)runtime->dma_area + sport->rx_pos *
73 runtime->channels, count);
Cliff Caiaff05102008-09-05 18:21:36 +080074 sport->rx_pos += runtime->period_size;
75 if (sport->rx_pos >= runtime->buffer_size)
76 sport->rx_pos %= runtime->buffer_size;
77 }
78}
79#endif
80
81static void bf5xx_dma_irq(void *data)
82{
83 struct snd_pcm_substream *pcm = data;
Cliff Cai67f854b2008-11-18 16:18:17 +080084#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +080085 struct snd_pcm_runtime *runtime = pcm->runtime;
Cliff Cai6b58a822008-09-27 22:32:20 +080086 struct sport_device *sport = runtime->private_data;
Cliff Caiaff05102008-09-05 18:21:36 +080087 bf5xx_mmap_copy(pcm, runtime->period_size);
Cliff Cai6b58a822008-09-27 22:32:20 +080088 if (pcm->stream == SNDRV_PCM_STREAM_PLAYBACK) {
89 if (sport->once == 0) {
90 snd_pcm_period_elapsed(pcm);
91 bf5xx_mmap_copy(pcm, runtime->period_size);
92 sport->once = 1;
93 }
94 }
Cliff Caiaff05102008-09-05 18:21:36 +080095#endif
96 snd_pcm_period_elapsed(pcm);
97}
98
99/* The memory size for pure pcm data is 128*1024 = 0x20000 bytes.
100 * The total rx/tx buffer is for ac97 frame to hold all pcm data
101 * is 0x20000 * sizeof(struct ac97_frame) / 4.
102 */
Cliff Caiaff05102008-09-05 18:21:36 +0800103static const struct snd_pcm_hardware bf5xx_pcm_hardware = {
104 .info = SNDRV_PCM_INFO_INTERLEAVED |
Bryan Wu27b9be52008-11-18 16:18:21 +0800105#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800106 SNDRV_PCM_INFO_MMAP |
107 SNDRV_PCM_INFO_MMAP_VALID |
Cliff Caiaff05102008-09-05 18:21:36 +0800108#endif
Bryan Wu27b9be52008-11-18 16:18:21 +0800109 SNDRV_PCM_INFO_BLOCK_TRANSFER,
110
Cliff Caiaff05102008-09-05 18:21:36 +0800111 .formats = SNDRV_PCM_FMTBIT_S16_LE,
112 .period_bytes_min = 32,
113 .period_bytes_max = 0x10000,
114 .periods_min = 1,
115 .periods_max = PAGE_SIZE/32,
116 .buffer_bytes_max = 0x20000, /* 128 kbytes */
117 .fifo_size = 16,
118};
119
120static int bf5xx_pcm_hw_params(struct snd_pcm_substream *substream,
121 struct snd_pcm_hw_params *params)
122{
123 size_t size = bf5xx_pcm_hardware.buffer_bytes_max
124 * sizeof(struct ac97_frame) / 4;
125
126 snd_pcm_lib_malloc_pages(substream, size);
127
128 return 0;
129}
130
131static int bf5xx_pcm_hw_free(struct snd_pcm_substream *substream)
132{
Cliff Cai67f854b2008-11-18 16:18:17 +0800133#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Cai6b58a822008-09-27 22:32:20 +0800134 struct snd_pcm_runtime *runtime = substream->runtime;
Cliff Cai67f854b2008-11-18 16:18:17 +0800135 struct sport_device *sport = runtime->private_data;
Cliff Cai6b58a822008-09-27 22:32:20 +0800136
Cliff Cai67f854b2008-11-18 16:18:17 +0800137 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
138 sport->once = 0;
139 if (runtime->dma_area)
140 memset(runtime->dma_area, 0, runtime->buffer_size);
141 memset(sport->tx_dma_buf, 0, runtime->buffer_size *
142 sizeof(struct ac97_frame));
143 } else
144 memset(sport->rx_dma_buf, 0, runtime->buffer_size *
145 sizeof(struct ac97_frame));
146#endif
Cliff Caiaff05102008-09-05 18:21:36 +0800147 snd_pcm_lib_free_pages(substream);
148 return 0;
149}
150
151static int bf5xx_pcm_prepare(struct snd_pcm_substream *substream)
152{
153 struct snd_pcm_runtime *runtime = substream->runtime;
154 struct sport_device *sport = runtime->private_data;
155
156 /* An intermediate buffer is introduced for implementing mmap for
157 * SPORT working in TMD mode(include AC97).
158 */
Cliff Cai67f854b2008-11-18 16:18:17 +0800159#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800160 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Cliff Caiaff05102008-09-05 18:21:36 +0800161 sport_set_tx_callback(sport, bf5xx_dma_irq, substream);
162 sport_config_tx_dma(sport, sport->tx_dma_buf, runtime->periods,
163 runtime->period_size * sizeof(struct ac97_frame));
164 } else {
Cliff Caiaff05102008-09-05 18:21:36 +0800165 sport_set_rx_callback(sport, bf5xx_dma_irq, substream);
166 sport_config_rx_dma(sport, sport->rx_dma_buf, runtime->periods,
167 runtime->period_size * sizeof(struct ac97_frame));
168 }
169#else
170 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
171 sport_set_tx_callback(sport, bf5xx_dma_irq, substream);
172 sport_config_tx_dma(sport, runtime->dma_area, runtime->periods,
173 runtime->period_size * sizeof(struct ac97_frame));
174 } else {
175 sport_set_rx_callback(sport, bf5xx_dma_irq, substream);
176 sport_config_rx_dma(sport, runtime->dma_area, runtime->periods,
177 runtime->period_size * sizeof(struct ac97_frame));
178 }
179#endif
180 return 0;
181}
182
183static int bf5xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
184{
185 struct snd_pcm_runtime *runtime = substream->runtime;
186 struct sport_device *sport = runtime->private_data;
187 int ret = 0;
188
189 pr_debug("%s enter\n", __func__);
190 switch (cmd) {
191 case SNDRV_PCM_TRIGGER_START:
Cliff Cai6b58a822008-09-27 22:32:20 +0800192 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Cliff Caia89e6112008-11-18 16:18:18 +0800193#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Cai6b58a822008-09-27 22:32:20 +0800194 bf5xx_mmap_copy(substream, runtime->period_size);
Cliff Cai6b58a822008-09-27 22:32:20 +0800195 sport->tx_delay_pos = 0;
Cliff Caia89e6112008-11-18 16:18:18 +0800196#endif
Cliff Caiaff05102008-09-05 18:21:36 +0800197 sport_tx_start(sport);
Cliff Cai67f854b2008-11-18 16:18:17 +0800198 } else
Cliff Caiaff05102008-09-05 18:21:36 +0800199 sport_rx_start(sport);
200 break;
201 case SNDRV_PCM_TRIGGER_STOP:
202 case SNDRV_PCM_TRIGGER_SUSPEND:
203 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
204 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Cliff Cai67f854b2008-11-18 16:18:17 +0800205#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800206 sport->tx_pos = 0;
207#endif
208 sport_tx_stop(sport);
209 } else {
Cliff Cai67f854b2008-11-18 16:18:17 +0800210#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800211 sport->rx_pos = 0;
212#endif
213 sport_rx_stop(sport);
214 }
215 break;
216 default:
217 ret = -EINVAL;
218 }
219 return ret;
220}
221
222static snd_pcm_uframes_t bf5xx_pcm_pointer(struct snd_pcm_substream *substream)
223{
224 struct snd_pcm_runtime *runtime = substream->runtime;
225 struct sport_device *sport = runtime->private_data;
226 unsigned int curr;
227
Cliff Cai67f854b2008-11-18 16:18:17 +0800228#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800229 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Cliff Cai6b58a822008-09-27 22:32:20 +0800230 curr = sport->tx_delay_pos;
Cliff Caiaff05102008-09-05 18:21:36 +0800231 else
232 curr = sport->rx_pos;
233#else
234
235 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
236 curr = sport_curr_offset_tx(sport) / sizeof(struct ac97_frame);
237 else
238 curr = sport_curr_offset_rx(sport) / sizeof(struct ac97_frame);
239
240#endif
241 return curr;
242}
243
244static int bf5xx_pcm_open(struct snd_pcm_substream *substream)
245{
Barry Song2c66cb92011-03-28 01:45:10 -0400246 struct snd_soc_pcm_runtime *rtd = substream->private_data;
247 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
248 struct sport_device *sport_handle = snd_soc_dai_get_drvdata(cpu_dai);
Cliff Caiaff05102008-09-05 18:21:36 +0800249 struct snd_pcm_runtime *runtime = substream->runtime;
250 int ret;
251
252 pr_debug("%s enter\n", __func__);
253 snd_soc_set_runtime_hwparams(substream, &bf5xx_pcm_hardware);
254
255 ret = snd_pcm_hw_constraint_integer(runtime,
256 SNDRV_PCM_HW_PARAM_PERIODS);
257 if (ret < 0)
258 goto out;
259
260 if (sport_handle != NULL)
261 runtime->private_data = sport_handle;
262 else {
263 pr_err("sport_handle is NULL\n");
264 return -1;
265 }
266 return 0;
267
268 out:
269 return ret;
270}
271
Cliff Cai67f854b2008-11-18 16:18:17 +0800272#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800273static int bf5xx_pcm_mmap(struct snd_pcm_substream *substream,
274 struct vm_area_struct *vma)
275{
276 struct snd_pcm_runtime *runtime = substream->runtime;
277 size_t size = vma->vm_end - vma->vm_start;
278 vma->vm_start = (unsigned long)runtime->dma_area;
279 vma->vm_end = vma->vm_start + size;
280 vma->vm_flags |= VM_SHARED;
281 return 0 ;
282}
283#else
284static int bf5xx_pcm_copy(struct snd_pcm_substream *substream, int channel,
285 snd_pcm_uframes_t pos,
286 void __user *buf, snd_pcm_uframes_t count)
287{
288 struct snd_pcm_runtime *runtime = substream->runtime;
Cliff Caia89e6112008-11-18 16:18:18 +0800289 unsigned int chan_mask = ac97_chan_mask[runtime->channels - 1];
Cliff Caiaff05102008-09-05 18:21:36 +0800290 pr_debug("%s copy pos:0x%lx count:0x%lx\n",
291 substream->stream ? "Capture" : "Playback", pos, count);
292
293 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Cliff Cai67f854b2008-11-18 16:18:17 +0800294 bf5xx_pcm_to_ac97((struct ac97_frame *)runtime->dma_area + pos,
295 (__u16 *)buf, count, chan_mask);
Cliff Caiaff05102008-09-05 18:21:36 +0800296 else
Cliff Cai67f854b2008-11-18 16:18:17 +0800297 bf5xx_ac97_to_pcm((struct ac97_frame *)runtime->dma_area + pos,
298 (__u16 *)buf, count);
Cliff Caiaff05102008-09-05 18:21:36 +0800299 return 0;
300}
301#endif
302
Mark Brownb2a19d02009-01-17 19:14:26 +0000303static struct snd_pcm_ops bf5xx_pcm_ac97_ops = {
Cliff Caiaff05102008-09-05 18:21:36 +0800304 .open = bf5xx_pcm_open,
Cliff Caiaff05102008-09-05 18:21:36 +0800305 .ioctl = snd_pcm_lib_ioctl,
306 .hw_params = bf5xx_pcm_hw_params,
307 .hw_free = bf5xx_pcm_hw_free,
308 .prepare = bf5xx_pcm_prepare,
309 .trigger = bf5xx_pcm_trigger,
310 .pointer = bf5xx_pcm_pointer,
Cliff Cai67f854b2008-11-18 16:18:17 +0800311#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800312 .mmap = bf5xx_pcm_mmap,
313#else
314 .copy = bf5xx_pcm_copy,
315#endif
316};
317
318static int bf5xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
319{
Barry Song2c66cb92011-03-28 01:45:10 -0400320 struct snd_soc_pcm_runtime *rtd = pcm->private_data;
321 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
322 struct sport_device *sport_handle = snd_soc_dai_get_drvdata(cpu_dai);
Cliff Caiaff05102008-09-05 18:21:36 +0800323 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
324 struct snd_dma_buffer *buf = &substream->dma_buffer;
325 size_t size = bf5xx_pcm_hardware.buffer_bytes_max
326 * sizeof(struct ac97_frame) / 4;
327
328 buf->dev.type = SNDRV_DMA_TYPE_DEV;
329 buf->dev.dev = pcm->card->dev;
330 buf->private_data = NULL;
331 buf->area = dma_alloc_coherent(pcm->card->dev, size,
332 &buf->addr, GFP_KERNEL);
333 if (!buf->area) {
334 pr_err("Failed to allocate dma memory\n");
335 pr_err("Please increase uncached DMA memory region\n");
336 return -ENOMEM;
337 }
338 buf->bytes = size;
339
340 pr_debug("%s, area:%p, size:0x%08lx\n", __func__,
341 buf->area, buf->bytes);
342
343 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
344 sport_handle->tx_buf = buf->area;
345 else
346 sport_handle->rx_buf = buf->area;
347
348/*
349 * Need to allocate local buffer when enable
350 * MMAP for SPORT working in TMD mode (include AC97).
351 */
Cliff Cai67f854b2008-11-18 16:18:17 +0800352#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800353 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
354 if (!sport_handle->tx_dma_buf) {
355 sport_handle->tx_dma_buf = dma_alloc_coherent(NULL, \
356 size, &sport_handle->tx_dma_phy, GFP_KERNEL);
357 if (!sport_handle->tx_dma_buf) {
Joe Perches2f1ff662010-01-31 12:02:12 -0800358 pr_err("Failed to allocate memory for tx dma buf - Please increase uncached DMA memory region\n");
Cliff Caiaff05102008-09-05 18:21:36 +0800359 return -ENOMEM;
360 } else
361 memset(sport_handle->tx_dma_buf, 0, size);
362 } else
363 memset(sport_handle->tx_dma_buf, 0, size);
364 } else {
365 if (!sport_handle->rx_dma_buf) {
366 sport_handle->rx_dma_buf = dma_alloc_coherent(NULL, \
367 size, &sport_handle->rx_dma_phy, GFP_KERNEL);
368 if (!sport_handle->rx_dma_buf) {
Joe Perches2f1ff662010-01-31 12:02:12 -0800369 pr_err("Failed to allocate memory for rx dma buf - Please increase uncached DMA memory region\n");
Cliff Caiaff05102008-09-05 18:21:36 +0800370 return -ENOMEM;
371 } else
372 memset(sport_handle->rx_dma_buf, 0, size);
373 } else
374 memset(sport_handle->rx_dma_buf, 0, size);
375 }
376#endif
377 return 0;
378}
379
380static void bf5xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
381{
382 struct snd_pcm_substream *substream;
383 struct snd_dma_buffer *buf;
384 int stream;
Cliff Cai67f854b2008-11-18 16:18:17 +0800385#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Barry Song2c66cb92011-03-28 01:45:10 -0400386 struct snd_soc_pcm_runtime *rtd = pcm->private_data;
387 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
388 struct sport_device *sport_handle = snd_soc_dai_get_drvdata(cpu_dai);
Cliff Caiaff05102008-09-05 18:21:36 +0800389 size_t size = bf5xx_pcm_hardware.buffer_bytes_max *
390 sizeof(struct ac97_frame) / 4;
391#endif
392 for (stream = 0; stream < 2; stream++) {
393 substream = pcm->streams[stream].substream;
394 if (!substream)
395 continue;
396
397 buf = &substream->dma_buffer;
398 if (!buf->area)
399 continue;
400 dma_free_coherent(NULL, buf->bytes, buf->area, 0);
401 buf->area = NULL;
Cliff Cai67f854b2008-11-18 16:18:17 +0800402#if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
Cliff Caiaff05102008-09-05 18:21:36 +0800403 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
404 if (sport_handle->tx_dma_buf)
405 dma_free_coherent(NULL, size, \
406 sport_handle->tx_dma_buf, 0);
407 sport_handle->tx_dma_buf = NULL;
408 } else {
409
410 if (sport_handle->rx_dma_buf)
411 dma_free_coherent(NULL, size, \
412 sport_handle->rx_dma_buf, 0);
413 sport_handle->rx_dma_buf = NULL;
414 }
415#endif
416 }
Cliff Caiaff05102008-09-05 18:21:36 +0800417}
418
Yang Hongyang284901a2009-04-06 19:01:15 -0700419static u64 bf5xx_pcm_dmamask = DMA_BIT_MASK(32);
Cliff Caiaff05102008-09-05 18:21:36 +0800420
Axel Lin3156cf72011-09-21 14:40:05 +0800421static int bf5xx_pcm_ac97_new(struct snd_soc_pcm_runtime *rtd)
Cliff Caiaff05102008-09-05 18:21:36 +0800422{
Liam Girdwood552d1ef2011-06-07 16:08:33 +0100423 struct snd_card *card = rtd->card->snd_card;
424 struct snd_soc_dai *dai = rtd->cpu_dai;
425 struct snd_pcm *pcm = rtd->pcm;
Cliff Caiaff05102008-09-05 18:21:36 +0800426 int ret = 0;
427
428 pr_debug("%s enter\n", __func__);
429 if (!card->dev->dma_mask)
430 card->dev->dma_mask = &bf5xx_pcm_dmamask;
431 if (!card->dev->coherent_dma_mask)
Yang Hongyang284901a2009-04-06 19:01:15 -0700432 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
Cliff Caiaff05102008-09-05 18:21:36 +0800433
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000434 if (dai->driver->playback.channels_min) {
Cliff Caiaff05102008-09-05 18:21:36 +0800435 ret = bf5xx_pcm_preallocate_dma_buffer(pcm,
436 SNDRV_PCM_STREAM_PLAYBACK);
437 if (ret)
438 goto out;
439 }
440
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000441 if (dai->driver->capture.channels_min) {
Cliff Caiaff05102008-09-05 18:21:36 +0800442 ret = bf5xx_pcm_preallocate_dma_buffer(pcm,
443 SNDRV_PCM_STREAM_CAPTURE);
444 if (ret)
445 goto out;
446 }
447 out:
448 return ret;
449}
450
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000451static struct snd_soc_platform_driver bf5xx_ac97_soc_platform = {
452 .ops = &bf5xx_pcm_ac97_ops,
Cliff Caiaff05102008-09-05 18:21:36 +0800453 .pcm_new = bf5xx_pcm_ac97_new,
454 .pcm_free = bf5xx_pcm_free_dma_buffers,
455};
Cliff Caiaff05102008-09-05 18:21:36 +0800456
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000457static int __devinit bf5xx_soc_platform_probe(struct platform_device *pdev)
Mark Brown958e7922008-12-03 19:58:17 +0000458{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000459 return snd_soc_register_platform(&pdev->dev, &bf5xx_ac97_soc_platform);
Mark Brown958e7922008-12-03 19:58:17 +0000460}
Mark Brown958e7922008-12-03 19:58:17 +0000461
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000462static int __devexit bf5xx_soc_platform_remove(struct platform_device *pdev)
Mark Brown958e7922008-12-03 19:58:17 +0000463{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000464 snd_soc_unregister_platform(&pdev->dev);
465 return 0;
Mark Brown958e7922008-12-03 19:58:17 +0000466}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000467
468static struct platform_driver bf5xx_pcm_driver = {
469 .driver = {
Mike Frysingerbfe4ee02011-03-28 01:45:09 -0400470 .name = "bfin-ac97-pcm-audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000471 .owner = THIS_MODULE,
472 },
473
474 .probe = bf5xx_soc_platform_probe,
475 .remove = __devexit_p(bf5xx_soc_platform_remove),
476};
477
478static int __init snd_bf5xx_pcm_init(void)
479{
480 return platform_driver_register(&bf5xx_pcm_driver);
481}
482module_init(snd_bf5xx_pcm_init);
483
484static void __exit snd_bf5xx_pcm_exit(void)
485{
486 platform_driver_unregister(&bf5xx_pcm_driver);
487}
488module_exit(snd_bf5xx_pcm_exit);
Mark Brown958e7922008-12-03 19:58:17 +0000489
Cliff Caiaff05102008-09-05 18:21:36 +0800490MODULE_AUTHOR("Cliff Cai");
491MODULE_DESCRIPTION("ADI Blackfin AC97 PCM DMA module");
492MODULE_LICENSE("GPL");