msm-pcm-lpa: 8960: Issue EOS to DSP after playback is complete
Issue an EOS command to ensure that dsp is completely flushed
before closing the stream. This command is only issued if the
the routing is still enabled.
Change-Id: Id36f2b1a2e5e3fef5dcde759277f3ca4417c17e7
CRs-Fixed: 331532
Signed-off-by: Tejas Shikhare <tshikhar@codeaurora.org>
diff --git a/sound/soc/msm/msm-pcm-lpa.c b/sound/soc/msm/msm-pcm-lpa.c
index 0a29016..83fd691 100644
--- a/sound/soc/msm/msm-pcm-lpa.c
+++ b/sound/soc/msm/msm-pcm-lpa.c
@@ -99,6 +99,8 @@
break;
} else
atomic_set(&prtd->pending_buffer, 0);
+ if (runtime->status->hw_ptr >= runtime->control->appl_ptr)
+ break;
pr_debug("%s:writing %d bytes of buffer to dsp 2\n",
__func__, prtd->pcm_count);
@@ -134,6 +136,9 @@
case ASM_SESSION_CMD_RUN: {
if (!atomic_read(&prtd->pending_buffer))
break;
+ if (runtime->status->hw_ptr >=
+ runtime->control->appl_ptr)
+ break;
pr_debug("%s:writing %d bytes"
" of buffer to dsp\n",
__func__, prtd->pcm_count);
@@ -340,8 +345,26 @@
struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
struct msm_audio *prtd = runtime->private_data;
int dir = 0;
+ int rc = 0;
- pr_debug("%s\n", __func__);
+ /*
+ If routing is still enabled, we need to issue EOS to
+ the DSP
+ To issue EOS to dsp, we need to be run state otherwise
+ EOS is not honored.
+ */
+ if (msm_routing_check_backend_enabled(soc_prtd->dai_link->be_id)) {
+ rc = q6asm_run(prtd->audio_client, 0, 0, 0);
+ atomic_set(&prtd->pending_buffer, 0);
+ prtd->cmd_ack = 0;
+ q6asm_cmd_nowait(prtd->audio_client, CMD_EOS);
+ pr_debug("%s\n", __func__);
+ rc = wait_event_timeout(the_locks.eos_wait,
+ prtd->cmd_ack, 5 * HZ);
+ if (rc < 0)
+ pr_err("EOS cmd timeout\n");
+ prtd->pcm_irq_pos = 0;
+ }
dir = IN;
atomic_set(&prtd->pending_buffer, 0);
@@ -462,6 +485,7 @@
switch (cmd) {
case SNDRV_PCM_IOCTL1_RESET:
+ prtd->cmd_ack = 0;
rc = q6asm_cmd(prtd->audio_client, CMD_FLUSH);
if (rc < 0)
pr_err("%s: flush cmd failed rc=%d\n", __func__, rc);
diff --git a/sound/soc/msm/msm-pcm-routing.c b/sound/soc/msm/msm-pcm-routing.c
index 8b6b5f1..f99cf6e 100644
--- a/sound/soc/msm/msm-pcm-routing.c
+++ b/sound/soc/msm/msm-pcm-routing.c
@@ -1636,6 +1636,23 @@
.remove = __devexit_p(msm_routing_pcm_remove),
};
+int msm_routing_check_backend_enabled(int fedai_id)
+{
+ int i;
+ if (fedai_id >= MSM_FRONTEND_DAI_MM_MAX_ID) {
+ /* bad ID assigned in machine driver */
+ pr_err("%s: bad MM ID\n", __func__);
+ return 0;
+ }
+ for (i = 0; i < MSM_BACKEND_DAI_MAX; i++) {
+ if ((test_bit(fedai_id,
+ &msm_bedais[i].fe_sessions))) {
+ return msm_bedais[i].active;
+ }
+ }
+ return 0;
+}
+
static int __init msm_soc_routing_platform_init(void)
{
mutex_init(&routing_lock);
diff --git a/sound/soc/msm/msm-pcm-routing.h b/sound/soc/msm/msm-pcm-routing.h
index 25efb58..5a93796 100644
--- a/sound/soc/msm/msm-pcm-routing.h
+++ b/sound/soc/msm/msm-pcm-routing.h
@@ -85,4 +85,6 @@
void msm_pcm_routing_dereg_phy_stream(int fedai_id, int stream_type);
int lpa_set_volume(unsigned volume);
+
+int msm_routing_check_backend_enabled(int fedai_id);
#endif /*_MSM_PCM_H*/