Commit 9ac4a444 authored by Srinivas Kandagatla's avatar Srinivas Kandagatla Committed by Vinod Koul

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: default avatarSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230525133812.30841-3-srinivas.kandagatla@linaro.orgSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 0a207b6b
...@@ -401,6 +401,32 @@ static int swrm_wait_for_wr_fifo_avail(struct qcom_swrm_ctrl *ctrl) ...@@ -401,6 +401,32 @@ static int swrm_wait_for_wr_fifo_avail(struct qcom_swrm_ctrl *ctrl)
return 0; return 0;
} }
static bool swrm_wait_for_wr_fifo_done(struct qcom_swrm_ctrl *ctrl)
{
u32 fifo_outstanding_cmds, value;
int fifo_retry_count = SWR_OVERFLOW_RETRY_COUNT;
/* Check for fifo overflow during write */
ctrl->reg_read(ctrl, ctrl->reg_layout[SWRM_REG_CMD_FIFO_STATUS], &value);
fifo_outstanding_cmds = FIELD_GET(SWRM_WR_CMD_FIFO_CNT_MASK, value);
if (fifo_outstanding_cmds) {
while (fifo_retry_count) {
usleep_range(500, 510);
ctrl->reg_read(ctrl, ctrl->reg_layout[SWRM_REG_CMD_FIFO_STATUS], &value);
fifo_outstanding_cmds = FIELD_GET(SWRM_WR_CMD_FIFO_CNT_MASK, value);
fifo_retry_count--;
if (fifo_outstanding_cmds == 0)
return true;
}
} else {
return true;
}
return false;
}
static int qcom_swrm_cmd_fifo_wr_cmd(struct qcom_swrm_ctrl *ctrl, u8 cmd_data, static int qcom_swrm_cmd_fifo_wr_cmd(struct qcom_swrm_ctrl *ctrl, u8 cmd_data,
u8 dev_addr, u16 reg_addr) u8 dev_addr, u16 reg_addr)
{ {
...@@ -431,6 +457,7 @@ static int qcom_swrm_cmd_fifo_wr_cmd(struct qcom_swrm_ctrl *ctrl, u8 cmd_data, ...@@ -431,6 +457,7 @@ static int qcom_swrm_cmd_fifo_wr_cmd(struct qcom_swrm_ctrl *ctrl, u8 cmd_data,
usleep_range(150, 155); usleep_range(150, 155);
if (cmd_id == SWR_BROADCAST_CMD_ID) { if (cmd_id == SWR_BROADCAST_CMD_ID) {
swrm_wait_for_wr_fifo_done(ctrl);
/* /*
* sleep for 10ms for MSM soundwire variant to allow broadcast * sleep for 10ms for MSM soundwire variant to allow broadcast
* command to complete. * command to complete.
...@@ -1227,6 +1254,7 @@ static void qcom_swrm_shutdown(struct snd_pcm_substream *substream, ...@@ -1227,6 +1254,7 @@ static void qcom_swrm_shutdown(struct snd_pcm_substream *substream,
{ {
struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dai->dev); struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dai->dev);
swrm_wait_for_wr_fifo_done(ctrl);
sdw_release_stream(ctrl->sruntime[dai->id]); sdw_release_stream(ctrl->sruntime[dai->id]);
ctrl->sruntime[dai->id] = NULL; ctrl->sruntime[dai->id] = NULL;
pm_runtime_mark_last_busy(ctrl->dev); pm_runtime_mark_last_busy(ctrl->dev);
...@@ -1685,6 +1713,7 @@ static int __maybe_unused swrm_runtime_suspend(struct device *dev) ...@@ -1685,6 +1713,7 @@ static int __maybe_unused swrm_runtime_suspend(struct device *dev)
struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev); struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev);
int ret; int ret;
swrm_wait_for_wr_fifo_done(ctrl);
if (!ctrl->clock_stop_not_supported) { if (!ctrl->clock_stop_not_supported) {
/* Mask bus clash interrupt */ /* Mask bus clash interrupt */
ctrl->intr_mask &= ~SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET; ctrl->intr_mask &= ~SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET;
......
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