ASoC: Samsung: Update DMA interface

This patch adds to support the DMA PL330 driver that uses
DMA generic API. Samsung sound driver uses DMA generic API
if architecture supports it. Otherwise, use samsung specific
S3C-PL330 API driver to transfer PCM data.

Signed-off-by: Boojin Kim <boojin.kim@samsung.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Vinod Koul <vinod.koul@intel.com>
Cc: Jassi Brar <jassisinghbrar@gmail.com>
Cc: Liam Girdwood <lrg@ti.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
[kgene.kim@samsung.com: removed useless variable]
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
This commit is contained in:
Boojin Kim 2011-09-02 09:44:43 +09:00 коммит произвёл Vinod Koul
Родитель 82ab8cd7ec
Коммит 344b4c4888
6 изменённых файлов: 77 добавлений и 95 удалений

Просмотреть файл

@ -50,6 +50,11 @@ enum dma_ch {
DMACH_MAX, /* the end entry */ DMACH_MAX, /* the end entry */
}; };
static inline bool samsung_dma_has_circular(void)
{
return false;
}
static inline bool samsung_dma_is_dmadev(void) static inline bool samsung_dma_is_dmadev(void)
{ {
return false; return false;
@ -202,9 +207,4 @@ struct s3c2410_dma_chan {
typedef unsigned long dma_device_t; typedef unsigned long dma_device_t;
static inline bool s3c_dma_has_circular(void)
{
return false;
}
#endif /* __ASM_ARCH_DMA_H */ #endif /* __ASM_ARCH_DMA_H */

Просмотреть файл

@ -58,7 +58,7 @@ enum dma_ch {
DMACH_MAX /* the end */ DMACH_MAX /* the end */
}; };
static __inline__ bool s3c_dma_has_circular(void) static inline bool samsung_dma_has_circular(void)
{ {
return true; return true;
} }

Просмотреть файл

@ -89,7 +89,7 @@ struct s3c2410_dma_client {
char *name; char *name;
}; };
static inline bool s3c_dma_has_circular(void) static inline bool samsung_dma_has_circular(void)
{ {
return true; return true;
} }

Просмотреть файл

@ -271,7 +271,10 @@ static int s3c_ac97_trigger(struct snd_pcm_substream *substream, int cmd,
writel(ac_glbctrl, s3c_ac97.regs + S3C_AC97_GLBCTRL); writel(ac_glbctrl, s3c_ac97.regs + S3C_AC97_GLBCTRL);
s3c2410_dma_ctrl(dma_data->channel, S3C2410_DMAOP_STARTED); if (!dma_data->ops)
dma_data->ops = samsung_dma_get_ops();
dma_data->ops->started(dma_data->channel);
return 0; return 0;
} }
@ -317,7 +320,10 @@ static int s3c_ac97_mic_trigger(struct snd_pcm_substream *substream,
writel(ac_glbctrl, s3c_ac97.regs + S3C_AC97_GLBCTRL); writel(ac_glbctrl, s3c_ac97.regs + S3C_AC97_GLBCTRL);
s3c2410_dma_ctrl(dma_data->channel, S3C2410_DMAOP_STARTED); if (!dma_data->ops)
dma_data->ops = samsung_dma_get_ops();
dma_data->ops->started(dma_data->channel);
return 0; return 0;
} }

Просмотреть файл

@ -54,7 +54,6 @@ struct runtime_data {
spinlock_t lock; spinlock_t lock;
int state; int state;
unsigned int dma_loaded; unsigned int dma_loaded;
unsigned int dma_limit;
unsigned int dma_period; unsigned int dma_period;
dma_addr_t dma_start; dma_addr_t dma_start;
dma_addr_t dma_pos; dma_addr_t dma_pos;
@ -62,77 +61,79 @@ struct runtime_data {
struct s3c_dma_params *params; struct s3c_dma_params *params;
}; };
static void audio_buffdone(void *data);
/* dma_enqueue /* dma_enqueue
* *
* place a dma buffer onto the queue for the dma system * place a dma buffer onto the queue for the dma system
* to handle. * to handle.
*/ */
static void dma_enqueue(struct snd_pcm_substream *substream) static void dma_enqueue(struct snd_pcm_substream *substream)
{ {
struct runtime_data *prtd = substream->runtime->private_data; struct runtime_data *prtd = substream->runtime->private_data;
dma_addr_t pos = prtd->dma_pos; dma_addr_t pos = prtd->dma_pos;
unsigned int limit; unsigned int limit;
int ret; struct samsung_dma_prep_info dma_info;
pr_debug("Entered %s\n", __func__); pr_debug("Entered %s\n", __func__);
if (s3c_dma_has_circular()) limit = (prtd->dma_end - prtd->dma_start) / prtd->dma_period;
limit = (prtd->dma_end - prtd->dma_start) / prtd->dma_period;
else
limit = prtd->dma_limit;
pr_debug("%s: loaded %d, limit %d\n", pr_debug("%s: loaded %d, limit %d\n",
__func__, prtd->dma_loaded, limit); __func__, prtd->dma_loaded, limit);
while (prtd->dma_loaded < limit) { dma_info.cap = (samsung_dma_has_circular() ? DMA_CYCLIC : DMA_SLAVE);
unsigned long len = prtd->dma_period; dma_info.direction =
(substream->stream == SNDRV_PCM_STREAM_PLAYBACK
? DMA_TO_DEVICE : DMA_FROM_DEVICE);
dma_info.fp = audio_buffdone;
dma_info.fp_param = substream;
dma_info.period = prtd->dma_period;
dma_info.len = prtd->dma_period*limit;
while (prtd->dma_loaded < limit) {
pr_debug("dma_loaded: %d\n", prtd->dma_loaded); pr_debug("dma_loaded: %d\n", prtd->dma_loaded);
if ((pos + len) > prtd->dma_end) { if ((pos + dma_info.period) > prtd->dma_end) {
len = prtd->dma_end - pos; dma_info.period = prtd->dma_end - pos;
pr_debug("%s: corrected dma len %ld\n", __func__, len); pr_debug("%s: corrected dma len %ld\n",
__func__, dma_info.period);
} }
ret = s3c2410_dma_enqueue(prtd->params->channel, dma_info.buf = pos;
substream, pos, len); prtd->params->ops->prepare(prtd->params->ch, &dma_info);
if (ret == 0) { prtd->dma_loaded++;
prtd->dma_loaded++; pos += prtd->dma_period;
pos += prtd->dma_period; if (pos >= prtd->dma_end)
if (pos >= prtd->dma_end) pos = prtd->dma_start;
pos = prtd->dma_start;
} else
break;
} }
prtd->dma_pos = pos; prtd->dma_pos = pos;
} }
static void audio_buffdone(struct s3c2410_dma_chan *channel, static void audio_buffdone(void *data)
void *dev_id, int size,
enum s3c2410_dma_buffresult result)
{ {
struct snd_pcm_substream *substream = dev_id; struct snd_pcm_substream *substream = data;
struct runtime_data *prtd; struct runtime_data *prtd = substream->runtime->private_data;
pr_debug("Entered %s\n", __func__); pr_debug("Entered %s\n", __func__);
if (result == S3C2410_RES_ABORT || result == S3C2410_RES_ERR) if (prtd->state & ST_RUNNING) {
return; prtd->dma_pos += prtd->dma_period;
if (prtd->dma_pos >= prtd->dma_end)
prtd->dma_pos = prtd->dma_start;
prtd = substream->runtime->private_data; if (substream)
snd_pcm_period_elapsed(substream);
if (substream) spin_lock(&prtd->lock);
snd_pcm_period_elapsed(substream); if (!samsung_dma_has_circular()) {
prtd->dma_loaded--;
spin_lock(&prtd->lock); dma_enqueue(substream);
if (prtd->state & ST_RUNNING && !s3c_dma_has_circular()) { }
prtd->dma_loaded--; spin_unlock(&prtd->lock);
dma_enqueue(substream);
} }
spin_unlock(&prtd->lock);
} }
static int dma_hw_params(struct snd_pcm_substream *substream, static int dma_hw_params(struct snd_pcm_substream *substream,
@ -144,8 +145,7 @@ static int dma_hw_params(struct snd_pcm_substream *substream,
unsigned long totbytes = params_buffer_bytes(params); unsigned long totbytes = params_buffer_bytes(params);
struct s3c_dma_params *dma = struct s3c_dma_params *dma =
snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
int ret = 0; struct samsung_dma_info dma_info;
pr_debug("Entered %s\n", __func__); pr_debug("Entered %s\n", __func__);
@ -163,30 +163,26 @@ static int dma_hw_params(struct snd_pcm_substream *substream,
pr_debug("params %p, client %p, channel %d\n", prtd->params, pr_debug("params %p, client %p, channel %d\n", prtd->params,
prtd->params->client, prtd->params->channel); prtd->params->client, prtd->params->channel);
ret = s3c2410_dma_request(prtd->params->channel, prtd->params->ops = samsung_dma_get_ops();
prtd->params->client, NULL);
if (ret < 0) { dma_info.cap = (samsung_dma_has_circular() ?
printk(KERN_ERR "failed to get dma channel\n"); DMA_CYCLIC : DMA_SLAVE);
return ret; dma_info.client = prtd->params->client;
} dma_info.direction =
(substream->stream == SNDRV_PCM_STREAM_PLAYBACK
/* use the circular buffering if we have it available. */ ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
if (s3c_dma_has_circular()) dma_info.width = prtd->params->dma_size;
s3c2410_dma_setflags(prtd->params->channel, dma_info.fifo = prtd->params->dma_addr;
S3C2410_DMAF_CIRCULAR); prtd->params->ch = prtd->params->ops->request(
prtd->params->channel, &dma_info);
} }
s3c2410_dma_set_buffdone_fn(prtd->params->channel,
audio_buffdone);
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
runtime->dma_bytes = totbytes; runtime->dma_bytes = totbytes;
spin_lock_irq(&prtd->lock); spin_lock_irq(&prtd->lock);
prtd->dma_loaded = 0; prtd->dma_loaded = 0;
prtd->dma_limit = runtime->hw.periods_min;
prtd->dma_period = params_period_bytes(params); prtd->dma_period = params_period_bytes(params);
prtd->dma_start = runtime->dma_addr; prtd->dma_start = runtime->dma_addr;
prtd->dma_pos = prtd->dma_start; prtd->dma_pos = prtd->dma_start;
@ -206,7 +202,8 @@ static int dma_hw_free(struct snd_pcm_substream *substream)
snd_pcm_set_runtime_buffer(substream, NULL); snd_pcm_set_runtime_buffer(substream, NULL);
if (prtd->params) { if (prtd->params) {
s3c2410_dma_free(prtd->params->channel, prtd->params->client); prtd->params->ops->release(prtd->params->ch,
prtd->params->client);
prtd->params = NULL; prtd->params = NULL;
} }
@ -225,23 +222,9 @@ static int dma_prepare(struct snd_pcm_substream *substream)
if (!prtd->params) if (!prtd->params)
return 0; return 0;
/* channel needs configuring for mem=>device, increment memory addr,
* sync to pclk, half-word transfers to the IIS-FIFO. */
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
s3c2410_dma_devconfig(prtd->params->channel,
S3C2410_DMASRC_MEM,
prtd->params->dma_addr);
} else {
s3c2410_dma_devconfig(prtd->params->channel,
S3C2410_DMASRC_HW,
prtd->params->dma_addr);
}
s3c2410_dma_config(prtd->params->channel,
prtd->params->dma_size);
/* flush the DMA channel */ /* flush the DMA channel */
s3c2410_dma_ctrl(prtd->params->channel, S3C2410_DMAOP_FLUSH); prtd->params->ops->flush(prtd->params->ch);
prtd->dma_loaded = 0; prtd->dma_loaded = 0;
prtd->dma_pos = prtd->dma_start; prtd->dma_pos = prtd->dma_start;
@ -265,14 +248,14 @@ static int dma_trigger(struct snd_pcm_substream *substream, int cmd)
case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
prtd->state |= ST_RUNNING; prtd->state |= ST_RUNNING;
s3c2410_dma_ctrl(prtd->params->channel, S3C2410_DMAOP_START); prtd->params->ops->trigger(prtd->params->ch);
break; break;
case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
prtd->state &= ~ST_RUNNING; prtd->state &= ~ST_RUNNING;
s3c2410_dma_ctrl(prtd->params->channel, S3C2410_DMAOP_STOP); prtd->params->ops->stop(prtd->params->ch);
break; break;
default: default:
@ -291,21 +274,12 @@ dma_pointer(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct runtime_data *prtd = runtime->private_data; struct runtime_data *prtd = runtime->private_data;
unsigned long res; unsigned long res;
dma_addr_t src, dst;
pr_debug("Entered %s\n", __func__); pr_debug("Entered %s\n", __func__);
spin_lock(&prtd->lock); res = prtd->dma_pos - prtd->dma_start;
s3c2410_dma_getposition(prtd->params->channel, &src, &dst);
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) pr_debug("Pointer offset: %lu\n", res);
res = dst - prtd->dma_start;
else
res = src - prtd->dma_start;
spin_unlock(&prtd->lock);
pr_debug("Pointer %x %x\n", src, dst);
/* we seem to be getting the odd error from the pcm library due /* we seem to be getting the odd error from the pcm library due
* to out-of-bounds pointers. this is maybe due to the dma engine * to out-of-bounds pointers. this is maybe due to the dma engine

Просмотреть файл

@ -6,7 +6,7 @@
* Free Software Foundation; either version 2 of the License, or (at your * Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. * option) any later version.
* *
* ALSA PCM interface for the Samsung S3C24xx CPU * ALSA PCM interface for the Samsung SoC
*/ */
#ifndef _S3C_AUDIO_H #ifndef _S3C_AUDIO_H
@ -17,6 +17,8 @@ struct s3c_dma_params {
int channel; /* Channel ID */ int channel; /* Channel ID */
dma_addr_t dma_addr; dma_addr_t dma_addr;
int dma_size; /* Size of the DMA transfer */ int dma_size; /* Size of the DMA transfer */
unsigned ch;
struct samsung_dma_ops *ops;
}; };
#endif #endif