MLK-22340-3: ASoC: imx-pcm-rpmsg: refine the timer

For we have dropped the cmd I2S_TX_POINTER, and M4 will send
notification every period, so we don't need to enable timer
every period to get the position of TX pointer.

But we need a timer to send the notification to M4 that is
to reduce the notificaition message number.

Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
(cherry picked from commit 900628f0d5)
This commit is contained in:
Shengjiu Wang
2019-07-29 14:48:09 +08:00
parent a5e80bf012
commit adb4b596d2

View File

@ -124,14 +124,12 @@ static void imx_rpmsg_timer_callback(struct timer_list *t)
struct stream_timer *stream_timer =
from_timer(stream_timer, t, timer);
struct snd_pcm_substream *substream = stream_timer->substream;
struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct fsl_rpmsg_i2s *rpmsg_i2s = dev_get_drvdata(cpu_dai->dev);
struct i2s_info *i2s_info = &rpmsg_i2s->i2s_info;
struct i2s_rpmsg *rpmsg;
int index = i2s_info->work_write_index;
int time_msec;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
rpmsg = &i2s_info->rpmsg[I2S_TX_PERIOD_DONE + I2S_TYPE_A_NUM];
@ -151,12 +149,6 @@ static void imx_rpmsg_timer_callback(struct timer_list *t)
i2s_info->work_write_index %= WORK_MAX_NUM;
} else
i2s_info->msg_drop_count[substream->stream]++;
if (rpmsg_i2s->force_lpa) {
time_msec = (int)(runtime->period_size*1000/runtime->rate);
mod_timer(&i2s_info->stream_timer[substream->stream].timer,
jiffies + msecs_to_jiffies(time_msec));
}
}
static int imx_rpmsg_pcm_open(struct snd_pcm_substream *substream)
@ -292,27 +284,7 @@ static int imx_rpmsg_pcm_mmap(struct snd_pcm_substream *substream,
static void imx_rpmsg_pcm_dma_complete(void *arg)
{
struct snd_pcm_substream *substream = arg;
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct fsl_rpmsg_i2s *rpmsg_i2s = dev_get_drvdata(cpu_dai->dev);
struct i2s_info *i2s_info = &rpmsg_i2s->i2s_info;
/*
* With suspend state, which is not running state, M4 will trigger
* system resume with PERIOD_DONE command, at this moment, the
* snd_pcm_period_elapsed can't update the hw ptr. so change the
* state to be running and update timer
*
*/
if (!snd_pcm_running(substream) && rpmsg_i2s->force_lpa) {
int time_msec;
substream->runtime->status->state = SNDRV_PCM_STATE_RUNNING;
time_msec = (int)(runtime->period_size*1000/runtime->rate);
mod_timer(&i2s_info->stream_timer[substream->stream].timer,
jiffies + msecs_to_jiffies(time_msec));
}
snd_pcm_period_elapsed(substream);
}
@ -361,14 +333,12 @@ static int imx_rpmsg_pcm_prepare_and_submit(struct snd_pcm_substream *substream)
static int imx_rpmsg_async_issue_pending(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct fsl_rpmsg_i2s *rpmsg_i2s = dev_get_drvdata(cpu_dai->dev);
struct i2s_info *i2s_info = &rpmsg_i2s->i2s_info;
struct i2s_rpmsg *rpmsg;
int index = i2s_info->work_write_index;
int time_msec;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
rpmsg = &i2s_info->rpmsg[I2S_TX_START];
@ -389,12 +359,6 @@ static int imx_rpmsg_async_issue_pending(struct snd_pcm_substream *substream)
} else
return -EPIPE;
if (rpmsg_i2s->force_lpa) {
time_msec = (int)(runtime->period_size*1000/runtime->rate);
mod_timer(&i2s_info->stream_timer[substream->stream].timer,
jiffies + msecs_to_jiffies(time_msec));
}
return 0;
}
@ -512,7 +476,6 @@ int imx_rpmsg_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct fsl_rpmsg_i2s *rpmsg_i2s = dev_get_drvdata(cpu_dai->dev);
struct i2s_info *i2s_info = &rpmsg_i2s->i2s_info;
int ret = 0;
switch (cmd) {
@ -523,14 +486,8 @@ int imx_rpmsg_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
ret = imx_rpmsg_async_issue_pending(substream);
break;
case SNDRV_PCM_TRIGGER_RESUME:
if (rpmsg_i2s->force_lpa) {
int time_msec;
time_msec = (int)(runtime->period_size*1000/runtime->rate);
mod_timer(&i2s_info->stream_timer[substream->stream].timer,
jiffies + msecs_to_jiffies(time_msec));
if (rpmsg_i2s->force_lpa)
break;
}
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
ret = imx_rpmsg_restart(substream);
break;
@ -540,8 +497,7 @@ int imx_rpmsg_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
ret = imx_rpmsg_pause(substream);
else
ret = imx_rpmsg_terminate_all(substream);
} else
del_timer(&i2s_info->stream_timer[substream->stream].timer);
}
break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
ret = imx_rpmsg_pause(substream);
@ -607,8 +563,7 @@ int imx_rpmsg_pcm_ack(struct snd_pcm_substream *substream)
else
avail = snd_pcm_capture_hw_avail(runtime);
if ((avail - writen_num * runtime->period_size)
<= runtime->period_size) {
if ((avail - writen_num * runtime->period_size) <= runtime->period_size) {
if (i2s_info->work_write_index != i2s_info->work_read_index) {
memcpy(&i2s_info->work_list[index].msg, rpmsg,
sizeof(struct i2s_rpmsg_s));
@ -618,6 +573,13 @@ int imx_rpmsg_pcm_ack(struct snd_pcm_substream *substream)
i2s_info->work_write_index %= WORK_MAX_NUM;
} else
i2s_info->msg_drop_count[substream->stream]++;
} else {
if (rpmsg_i2s->force_lpa && !timer_pending(&i2s_info->stream_timer[substream->stream].timer)) {
int time_msec;
time_msec = (int)(runtime->period_size*1000/runtime->rate);
mod_timer(&i2s_info->stream_timer[substream->stream].timer,
jiffies + msecs_to_jiffies(time_msec));
}
}
}