aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/sh/fsi.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sound/soc/sh/fsi.c201
1 files changed, 58 insertions, 143 deletions
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 710a079a7377..c76344350e44 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -232,11 +232,7 @@ struct fsi_stream {
* these are for DMAEngine
*/
struct dma_chan *chan;
- struct work_struct work;
- dma_addr_t dma;
int dma_id;
- int loop_cnt;
- int additional_pos;
};
struct fsi_clk {
@@ -264,12 +260,12 @@ struct fsi_priv {
u32 fmt;
int chan_num:16;
- int clk_master:1;
- int clk_cpg:1;
- int spdif:1;
- int enable_stream:1;
- int bit_clk_inv:1;
- int lr_clk_inv:1;
+ unsigned int clk_master:1;
+ unsigned int clk_cpg:1;
+ unsigned int spdif:1;
+ unsigned int enable_stream:1;
+ unsigned int bit_clk_inv:1;
+ unsigned int lr_clk_inv:1;
};
struct fsi_stream_handler {
@@ -1042,6 +1038,26 @@ static int fsi_clk_set_rate_cpg(struct device *dev,
return ret;
}
+static void fsi_pointer_update(struct fsi_stream *io, int size)
+{
+ io->buff_sample_pos += size;
+
+ if (io->buff_sample_pos >=
+ io->period_samples * (io->period_pos + 1)) {
+ struct snd_pcm_substream *substream = io->substream;
+ struct snd_pcm_runtime *runtime = substream->runtime;
+
+ io->period_pos++;
+
+ if (io->period_pos >= runtime->periods) {
+ io->buff_sample_pos = 0;
+ io->period_pos = 0;
+ }
+
+ snd_pcm_period_elapsed(substream);
+ }
+}
+
/*
* pio data transfer handler
*/
@@ -1108,31 +1124,11 @@ static int fsi_pio_transfer(struct fsi_priv *fsi, struct fsi_stream *io,
void (*run32)(struct fsi_priv *fsi, u8 *buf, int samples),
int samples)
{
- struct snd_pcm_runtime *runtime;
- struct snd_pcm_substream *substream;
u8 *buf;
- int over_period;
if (!fsi_stream_is_working(fsi, io))
return -EINVAL;
- over_period = 0;
- substream = io->substream;
- runtime = substream->runtime;
-
- /* FSI FIFO has limit.
- * So, this driver can not send periods data at a time
- */
- if (io->buff_sample_pos >=
- io->period_samples * (io->period_pos + 1)) {
-
- over_period = 1;
- io->period_pos = (io->period_pos + 1) % runtime->periods;
-
- if (0 == io->period_pos)
- io->buff_sample_pos = 0;
- }
-
buf = fsi_pio_get_area(fsi, io);
switch (io->sample_width) {
@@ -1146,11 +1142,7 @@ static int fsi_pio_transfer(struct fsi_priv *fsi, struct fsi_stream *io,
return -EINVAL;
}
- /* update buff_sample_pos */
- io->buff_sample_pos += samples;
-
- if (over_period)
- snd_pcm_period_elapsed(substream);
+ fsi_pointer_update(io, samples);
return 0;
}
@@ -1279,11 +1271,6 @@ static irqreturn_t fsi_interrupt(int irq, void *data)
*/
static int fsi_dma_init(struct fsi_priv *fsi, struct fsi_stream *io)
{
- struct snd_pcm_runtime *runtime = io->substream->runtime;
- struct snd_soc_dai *dai = fsi_get_dai(io->substream);
- enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ?
- DMA_TO_DEVICE : DMA_FROM_DEVICE;
-
/*
* 24bit data : 24bit bus / package in back
* 16bit data : 16bit bus / stream mode
@@ -1291,107 +1278,48 @@ static int fsi_dma_init(struct fsi_priv *fsi, struct fsi_stream *io)
io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) |
BUSOP_SET(16, PACKAGE_16BITBUS_STREAM);
- io->loop_cnt = 2; /* push 1st, 2nd period first, then 3rd, 4th... */
- io->additional_pos = 0;
- io->dma = dma_map_single(dai->dev, runtime->dma_area,
- snd_pcm_lib_buffer_bytes(io->substream), dir);
return 0;
}
-static int fsi_dma_quit(struct fsi_priv *fsi, struct fsi_stream *io)
-{
- struct snd_soc_dai *dai = fsi_get_dai(io->substream);
- enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ?
- DMA_TO_DEVICE : DMA_FROM_DEVICE;
-
- dma_unmap_single(dai->dev, io->dma,
- snd_pcm_lib_buffer_bytes(io->substream), dir);
- return 0;
-}
-
-static dma_addr_t fsi_dma_get_area(struct fsi_stream *io, int additional)
-{
- struct snd_pcm_runtime *runtime = io->substream->runtime;
- int period = io->period_pos + additional;
-
- if (period >= runtime->periods)
- period = 0;
-
- return io->dma + samples_to_bytes(runtime, period * io->period_samples);
-}
-
static void fsi_dma_complete(void *data)
{
struct fsi_stream *io = (struct fsi_stream *)data;
struct fsi_priv *fsi = fsi_stream_to_priv(io);
- struct snd_pcm_runtime *runtime = io->substream->runtime;
- struct snd_soc_dai *dai = fsi_get_dai(io->substream);
- enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ?
- DMA_TO_DEVICE : DMA_FROM_DEVICE;
- dma_sync_single_for_cpu(dai->dev, fsi_dma_get_area(io, 0),
- samples_to_bytes(runtime, io->period_samples), dir);
-
- io->buff_sample_pos += io->period_samples;
- io->period_pos++;
-
- if (io->period_pos >= runtime->periods) {
- io->period_pos = 0;
- io->buff_sample_pos = 0;
- }
+ fsi_pointer_update(io, io->period_samples);
fsi_count_fifo_err(fsi);
- fsi_stream_transfer(io);
-
- snd_pcm_period_elapsed(io->substream);
}
-static void fsi_dma_do_work(struct work_struct *work)
+static int fsi_dma_transfer(struct fsi_priv *fsi, struct fsi_stream *io)
{
- struct fsi_stream *io = container_of(work, struct fsi_stream, work);
- struct fsi_priv *fsi = fsi_stream_to_priv(io);
- struct snd_soc_dai *dai;
+ struct snd_soc_dai *dai = fsi_get_dai(io->substream);
+ struct snd_pcm_substream *substream = io->substream;
struct dma_async_tx_descriptor *desc;
- struct snd_pcm_runtime *runtime;
- enum dma_data_direction dir;
int is_play = fsi_stream_is_play(fsi, io);
- int len, i;
- dma_addr_t buf;
-
- if (!fsi_stream_is_working(fsi, io))
- return;
-
- dai = fsi_get_dai(io->substream);
- runtime = io->substream->runtime;
- dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
- len = samples_to_bytes(runtime, io->period_samples);
-
- for (i = 0; i < io->loop_cnt; i++) {
- buf = fsi_dma_get_area(io, io->additional_pos);
-
- dma_sync_single_for_device(dai->dev, buf, len, dir);
-
- desc = dmaengine_prep_slave_single(io->chan, buf, len, dir,
- DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
- if (!desc) {
- dev_err(dai->dev, "dmaengine_prep_slave_sg() fail\n");
- return;
- }
-
- desc->callback = fsi_dma_complete;
- desc->callback_param = io;
-
- if (dmaengine_submit(desc) < 0) {
- dev_err(dai->dev, "tx_submit() fail\n");
- return;
- }
+ enum dma_data_direction dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
+ int ret = -EIO;
+
+ desc = dmaengine_prep_dma_cyclic(io->chan,
+ substream->runtime->dma_addr,
+ snd_pcm_lib_buffer_bytes(substream),
+ snd_pcm_lib_period_bytes(substream),
+ dir,
+ DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
+ if (!desc) {
+ dev_err(dai->dev, "dmaengine_prep_dma_cyclic() fail\n");
+ goto fsi_dma_transfer_err;
+ }
- dma_async_issue_pending(io->chan);
+ desc->callback = fsi_dma_complete;
+ desc->callback_param = io;
- io->additional_pos = 1;
+ if (dmaengine_submit(desc) < 0) {
+ dev_err(dai->dev, "tx_submit() fail\n");
+ goto fsi_dma_transfer_err;
}
- io->loop_cnt = 1;
+ dma_async_issue_pending(io->chan);
/*
* FIXME
@@ -1408,13 +1336,11 @@ static void fsi_dma_do_work(struct work_struct *work)
fsi_reg_write(fsi, DIFF_ST, 0);
}
}
-}
-static int fsi_dma_transfer(struct fsi_priv *fsi, struct fsi_stream *io)
-{
- schedule_work(&io->work);
+ ret = 0;
- return 0;
+fsi_dma_transfer_err:
+ return ret;
}
static int fsi_dma_push_start_stop(struct fsi_priv *fsi, struct fsi_stream *io,
@@ -1475,15 +1401,11 @@ static int fsi_dma_probe(struct fsi_priv *fsi, struct fsi_stream *io, struct dev
return fsi_stream_probe(fsi, dev);
}
- INIT_WORK(&io->work, fsi_dma_do_work);
-
return 0;
}
static int fsi_dma_remove(struct fsi_priv *fsi, struct fsi_stream *io)
{
- cancel_work_sync(&io->work);
-
fsi_stream_stop(fsi, io);
if (io->chan)
@@ -1495,7 +1417,6 @@ static int fsi_dma_remove(struct fsi_priv *fsi, struct fsi_stream *io)
static struct fsi_stream_handler fsi_dma_push_handler = {
.init = fsi_dma_init,
- .quit = fsi_dma_quit,
.probe = fsi_dma_probe,
.transfer = fsi_dma_transfer,
.remove = fsi_dma_remove,
@@ -1657,9 +1578,9 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
if (!ret)
ret = fsi_hw_startup(fsi, io, dai->dev);
if (!ret)
- ret = fsi_stream_transfer(io);
+ ret = fsi_stream_start(fsi, io);
if (!ret)
- fsi_stream_start(fsi, io);
+ ret = fsi_stream_transfer(io);
break;
case SNDRV_PCM_TRIGGER_STOP:
if (!ret)
@@ -1850,16 +1771,10 @@ static void fsi_pcm_free(struct snd_pcm *pcm)
static int fsi_pcm_new(struct snd_soc_pcm_runtime *rtd)
{
- struct snd_pcm *pcm = rtd->pcm;
-
- /*
- * dont use SNDRV_DMA_TYPE_DEV, since it will oops the SH kernel
- * in MMAP mode (i.e. aplay -M)
- */
return snd_pcm_lib_preallocate_pages_for_all(
- pcm,
- SNDRV_DMA_TYPE_CONTINUOUS,
- snd_dma_continuous_data(GFP_KERNEL),
+ rtd->pcm,
+ SNDRV_DMA_TYPE_DEV,
+ rtd->card->snd_card->dev,
PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
}