MLK-21447: ASoC: fsl_rpmsg_i2s: underrun in m4 for msg delayed
With small buffer size, the resume will be triggered after suspend immediately, if we reserve the period done message to be sent with the next command, one period time later, it will cause underrun in m4 side, for ALSA thought the appl_ptr is updated, but the command won't be sent to M4 immediately, M4 don't have enough data to play. In this patch, we check that if the left size in the buffer is less that one period, the work queue will be triggered to send the period done message immediately. Fixes:348d476956("MLK-21307: ASoC: fsl_rpmsg_i2s: optimize the message sent to m4") Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com> (cherry picked from commit3dfecae407)
This commit is contained in:
committed by
Leonard Crestez
parent
d9410ace75
commit
f5f2f38018
@ -144,6 +144,7 @@ static void rpmsg_i2s_work(struct work_struct *work)
|
||||
{
|
||||
struct work_of_rpmsg *work_of_rpmsg;
|
||||
struct i2s_info *i2s_info;
|
||||
bool is_period_done = false;
|
||||
|
||||
work_of_rpmsg = container_of(work, struct work_of_rpmsg, work);
|
||||
i2s_info = work_of_rpmsg->i2s_info;
|
||||
@ -158,7 +159,13 @@ static void rpmsg_i2s_work(struct work_struct *work)
|
||||
i2s_info->period_done_msg_enabled[1] = false;
|
||||
}
|
||||
|
||||
i2s_send_message(&work_of_rpmsg->msg, i2s_info);
|
||||
if (work_of_rpmsg->msg.send_msg.header.type == I2S_TYPE_C &&
|
||||
(work_of_rpmsg->msg.send_msg.header.cmd == I2S_TX_PERIOD_DONE ||
|
||||
work_of_rpmsg->msg.send_msg.header.cmd == I2S_RX_PERIOD_DONE))
|
||||
is_period_done = true;
|
||||
|
||||
if (!is_period_done)
|
||||
i2s_send_message(&work_of_rpmsg->msg, i2s_info);
|
||||
|
||||
i2s_info->work_read_index++;
|
||||
i2s_info->work_read_index %= WORK_MAX_NUM;
|
||||
|
||||
@ -579,7 +579,10 @@ int imx_rpmsg_pcm_ack(struct snd_pcm_substream *substream)
|
||||
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 buffer_tail = 0;
|
||||
int writen_num = 0;
|
||||
snd_pcm_sframes_t avail;
|
||||
|
||||
if (!rpmsg_i2s->force_lpa)
|
||||
return 0;
|
||||
@ -601,10 +604,32 @@ int imx_rpmsg_pcm_ack(struct snd_pcm_substream *substream)
|
||||
buffer_tail = buffer_tail / snd_pcm_lib_period_bytes(substream);
|
||||
|
||||
if (buffer_tail != rpmsg->send_msg.param.buffer_tail) {
|
||||
writen_num = buffer_tail - rpmsg->send_msg.param.buffer_tail;
|
||||
if (writen_num < 0)
|
||||
writen_num += runtime->periods;
|
||||
|
||||
rpmsg->send_msg.param.buffer_tail = buffer_tail;
|
||||
memcpy(&i2s_info->period_done_msg[substream->stream], rpmsg,
|
||||
sizeof(struct i2s_rpmsg_s));
|
||||
i2s_info->period_done_msg_enabled[substream->stream] = true;
|
||||
|
||||
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
||||
avail = snd_pcm_playback_hw_avail(runtime);
|
||||
else
|
||||
avail = snd_pcm_capture_hw_avail(runtime);
|
||||
|
||||
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));
|
||||
queue_work(i2s_info->rpmsg_wq,
|
||||
&i2s_info->work_list[index].work);
|
||||
i2s_info->work_write_index++;
|
||||
i2s_info->work_write_index %= WORK_MAX_NUM;
|
||||
} else
|
||||
i2s_info->msg_drop_count[substream->stream]++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user