Skip to content

Commit 9ac4a44

Browse files
Srinivas-Kandagatlavinodkoul
authored andcommitted
soundwire: qcom: wait for fifo to be empty before suspend
Wait for Fifo to be empty before going to suspend or before bank switch happens. Just to make sure that all the reads/writes are done. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Link: https://lore.kernel.org/r/20230525133812.30841-3-srinivas.kandagatla@linaro.org Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 0a207b6 commit 9ac4a44

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

drivers/soundwire/qcom.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,32 @@ static int swrm_wait_for_wr_fifo_avail(struct qcom_swrm_ctrl *ctrl)
401401
return 0;
402402
}
403403

404+
static bool swrm_wait_for_wr_fifo_done(struct qcom_swrm_ctrl *ctrl)
405+
{
406+
u32 fifo_outstanding_cmds, value;
407+
int fifo_retry_count = SWR_OVERFLOW_RETRY_COUNT;
408+
409+
/* Check for fifo overflow during write */
410+
ctrl->reg_read(ctrl, ctrl->reg_layout[SWRM_REG_CMD_FIFO_STATUS], &value);
411+
fifo_outstanding_cmds = FIELD_GET(SWRM_WR_CMD_FIFO_CNT_MASK, value);
412+
413+
if (fifo_outstanding_cmds) {
414+
while (fifo_retry_count) {
415+
usleep_range(500, 510);
416+
ctrl->reg_read(ctrl, ctrl->reg_layout[SWRM_REG_CMD_FIFO_STATUS], &value);
417+
fifo_outstanding_cmds = FIELD_GET(SWRM_WR_CMD_FIFO_CNT_MASK, value);
418+
fifo_retry_count--;
419+
if (fifo_outstanding_cmds == 0)
420+
return true;
421+
}
422+
} else {
423+
return true;
424+
}
425+
426+
427+
return false;
428+
}
429+
404430
static int qcom_swrm_cmd_fifo_wr_cmd(struct qcom_swrm_ctrl *ctrl, u8 cmd_data,
405431
u8 dev_addr, u16 reg_addr)
406432
{
@@ -431,6 +457,7 @@ static int qcom_swrm_cmd_fifo_wr_cmd(struct qcom_swrm_ctrl *ctrl, u8 cmd_data,
431457
usleep_range(150, 155);
432458

433459
if (cmd_id == SWR_BROADCAST_CMD_ID) {
460+
swrm_wait_for_wr_fifo_done(ctrl);
434461
/*
435462
* sleep for 10ms for MSM soundwire variant to allow broadcast
436463
* command to complete.
@@ -1227,6 +1254,7 @@ static void qcom_swrm_shutdown(struct snd_pcm_substream *substream,
12271254
{
12281255
struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dai->dev);
12291256

1257+
swrm_wait_for_wr_fifo_done(ctrl);
12301258
sdw_release_stream(ctrl->sruntime[dai->id]);
12311259
ctrl->sruntime[dai->id] = NULL;
12321260
pm_runtime_mark_last_busy(ctrl->dev);
@@ -1685,6 +1713,7 @@ static int __maybe_unused swrm_runtime_suspend(struct device *dev)
16851713
struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev);
16861714
int ret;
16871715

1716+
swrm_wait_for_wr_fifo_done(ctrl);
16881717
if (!ctrl->clock_stop_not_supported) {
16891718
/* Mask bus clash interrupt */
16901719
ctrl->intr_mask &= ~SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET;

0 commit comments

Comments
 (0)