Commit d8b33534 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: fsi: merge fsi_data_push/pop to fsi_fifo_data_ctrl

Current FSI driver had data push/pop functions.
But the main operation of these 2 were very similar.
This mean it is possible to merge these to 1 function.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Acked-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 5bfb9ad0
...@@ -560,16 +560,18 @@ static void fsi_soft_all_reset(struct fsi_master *master) ...@@ -560,16 +560,18 @@ static void fsi_soft_all_reset(struct fsi_master *master)
mdelay(10); mdelay(10);
} }
/* playback interrupt */ static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int is_play)
static int fsi_data_push(struct fsi_priv *fsi, int startup)
{ {
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
struct snd_pcm_substream *substream = NULL; struct snd_pcm_substream *substream = NULL;
u32 status; u32 status;
int push_num; u32 status_reg = is_play ? DOFF_ST : DIFF_ST;
int push_num_max; int data_residue_num;
int data_num;
int data_num_max;
int ch_width; int ch_width;
int over_period; int over_period;
void (*fn)(struct fsi_priv *fsi, int size);
if (!fsi || if (!fsi ||
!fsi->substream || !fsi->substream ||
...@@ -596,104 +598,63 @@ static int fsi_data_push(struct fsi_priv *fsi, int startup) ...@@ -596,104 +598,63 @@ static int fsi_data_push(struct fsi_priv *fsi, int startup)
/* get 1 channel data width */ /* get 1 channel data width */
ch_width = frames_to_bytes(runtime, 1) / fsi->chan_num; ch_width = frames_to_bytes(runtime, 1) / fsi->chan_num;
/* number of push data */ /* get residue data number of alsa */
push_num = fsi_len2num(fsi->buff_len - fsi->buff_offset, ch_width); data_residue_num = fsi_len2num(fsi->buff_len - fsi->buff_offset,
ch_width);
/* max number of push data */ if (is_play) {
push_num_max = (fsi->fifo_max_num * fsi->chan_num) - /*
fsi_get_fifo_data_num(fsi, 1); * for play-back
*
* data_num_max : number of FSI fifo free space
* data_num : number of ALSA residue data
*/
data_num_max = fsi->fifo_max_num * fsi->chan_num;
data_num_max -= fsi_get_fifo_data_num(fsi, is_play);
push_num = min(push_num, push_num_max); data_num = data_residue_num;
switch (ch_width) { switch (ch_width) {
case 2: case 2:
fsi_dma_soft_push16(fsi, push_num); fn = fsi_dma_soft_push16;
break; break;
case 4: case 4:
fsi_dma_soft_push32(fsi, push_num); fn = fsi_dma_soft_push32;
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
} else {
fsi->buff_offset += fsi_num2offset(push_num, ch_width); /*
* for capture
status = fsi_reg_read(fsi, DOFF_ST); *
if (!startup) { * data_num_max : number of ALSA free space
struct snd_soc_dai *dai = fsi_get_dai(substream); * data_num : number of data in FSI fifo
if (status & ERR_OVER)
dev_err(dai->dev, "over run\n");
if (status & ERR_UNDER)
dev_err(dai->dev, "under run\n");
}
fsi_reg_write(fsi, DOFF_ST, 0);
fsi_irq_enable(fsi, 1);
if (over_period)
snd_pcm_period_elapsed(substream);
return 0;
}
static int fsi_data_pop(struct fsi_priv *fsi, int startup)
{
struct snd_pcm_runtime *runtime;
struct snd_pcm_substream *substream = NULL;
u32 status;
int pop_num;
int pop_num_max;
int ch_width;
int over_period;
if (!fsi ||
!fsi->substream ||
!fsi->substream->runtime)
return -EINVAL;
over_period = 0;
substream = fsi->substream;
runtime = substream->runtime;
/* FSI FIFO has limit.
* So, this driver can not send periods data at a time
*/ */
if (fsi->buff_offset >= data_num_max = data_residue_num;
fsi_num2offset(fsi->period_num + 1, fsi->period_len)) { data_num = fsi_get_fifo_data_num(fsi, is_play);
over_period = 1;
fsi->period_num = (fsi->period_num + 1) % runtime->periods;
if (0 == fsi->period_num)
fsi->buff_offset = 0;
}
/* get 1 channel data width */
ch_width = frames_to_bytes(runtime, 1) / fsi->chan_num;
/* get free space for alsa */
pop_num_max = fsi_len2num(fsi->buff_len - fsi->buff_offset, ch_width);
/* get recv size */
pop_num = fsi_get_fifo_data_num(fsi, 0);
pop_num = min(pop_num_max, pop_num);
switch (ch_width) { switch (ch_width) {
case 2: case 2:
fsi_dma_soft_pop16(fsi, pop_num); fn = fsi_dma_soft_pop16;
break; break;
case 4: case 4:
fsi_dma_soft_pop32(fsi, pop_num); fn = fsi_dma_soft_pop32;
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
}
data_num = min(data_num, data_num_max);
fn(fsi, data_num);
fsi->buff_offset += fsi_num2offset(pop_num, ch_width); /* update buff_offset */
fsi->buff_offset += fsi_num2offset(data_num, ch_width);
status = fsi_reg_read(fsi, DIFF_ST); /* check fifo status */
status = fsi_reg_read(fsi, status_reg);
if (!startup) { if (!startup) {
struct snd_soc_dai *dai = fsi_get_dai(substream); struct snd_soc_dai *dai = fsi_get_dai(substream);
...@@ -702,9 +663,10 @@ static int fsi_data_pop(struct fsi_priv *fsi, int startup) ...@@ -702,9 +663,10 @@ static int fsi_data_pop(struct fsi_priv *fsi, int startup)
if (status & ERR_UNDER) if (status & ERR_UNDER)
dev_err(dai->dev, "under run\n"); dev_err(dai->dev, "under run\n");
} }
fsi_reg_write(fsi, DIFF_ST, 0); fsi_reg_write(fsi, status_reg, 0);
fsi_irq_enable(fsi, 0); /* re-enable irq */
fsi_irq_enable(fsi, is_play);
if (over_period) if (over_period)
snd_pcm_period_elapsed(substream); snd_pcm_period_elapsed(substream);
...@@ -712,6 +674,16 @@ static int fsi_data_pop(struct fsi_priv *fsi, int startup) ...@@ -712,6 +674,16 @@ static int fsi_data_pop(struct fsi_priv *fsi, int startup)
return 0; return 0;
} }
static int fsi_data_pop(struct fsi_priv *fsi, int startup)
{
return fsi_fifo_data_ctrl(fsi, startup, 0);
}
static int fsi_data_push(struct fsi_priv *fsi, int startup)
{
return fsi_fifo_data_ctrl(fsi, startup, 1);
}
static irqreturn_t fsi_interrupt(int irq, void *data) static irqreturn_t fsi_interrupt(int irq, void *data)
{ {
struct fsi_master *master = data; struct fsi_master *master = data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment