From f6bc7130d2ab45c5f7220da2eb56686fb0571bb8 Mon Sep 17 00:00:00 2001 From: Banajit Goswami Date: Fri, 20 Oct 2017 22:29:42 -0700 Subject: [PATCH 1/2] asoc: wcd9xxx-core: avoid slimbus read/write during ADSP SSR This reverts commit 40bc50d768038c04f8c1 ("mfd: wcd9xxx-core: Synchronize codec down and reset calls from slimbus."). This is to make sure that the dev_up flag is set right after device_down is called from Slimbus after ADSP SSR. This flag helps make sure that all read/write calls over slimbus are blocked until ADSP and Slimbus are fully up post-SSR. Change-Id: I5595a23a0b51f2ca392ddfb5773b057204185b54 Signed-off-by: Banajit Goswami --- asoc/codecs/core.h | 2 +- asoc/codecs/wcd9xxx-core.c | 49 +++++++++++++------------------------- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/asoc/codecs/core.h b/asoc/codecs/core.h index b994010f52..b4c1be40ff 100644 --- a/asoc/codecs/core.h +++ b/asoc/codecs/core.h @@ -350,7 +350,7 @@ struct wcd9xxx { int (*post_reset)(struct wcd9xxx *wcd9xxx); void *ssr_priv; - unsigned long dev_up; + bool dev_up; u32 num_of_supplies; struct regulator_bulk_data *supplies; diff --git a/asoc/codecs/wcd9xxx-core.c b/asoc/codecs/wcd9xxx-core.c index 7f74aef8f0..49be43a3e1 100644 --- a/asoc/codecs/wcd9xxx-core.c +++ b/asoc/codecs/wcd9xxx-core.c @@ -228,7 +228,7 @@ static int wcd9xxx_slim_read_device(struct wcd9xxx *wcd9xxx, unsigned short reg, if (!wcd9xxx->dev_up) { dev_dbg_ratelimited( - wcd9xxx->dev, "%s: No read allowed. dev_up = %lu\n", + wcd9xxx->dev, "%s: No read allowed. dev_up = %d\n", __func__, wcd9xxx->dev_up); return 0; } @@ -268,7 +268,7 @@ static int wcd9xxx_slim_write_device(struct wcd9xxx *wcd9xxx, if (!wcd9xxx->dev_up) { dev_dbg_ratelimited( - wcd9xxx->dev, "%s: No write allowed. dev_up = %lu\n", + wcd9xxx->dev, "%s: No write allowed. dev_up = %d\n", __func__, wcd9xxx->dev_up); return 0; } @@ -345,7 +345,7 @@ int wcd9xxx_slim_write_repeat(struct wcd9xxx *wcd9xxx, unsigned short reg, if (!wcd9xxx->dev_up) { dev_dbg_ratelimited( - wcd9xxx->dev, "%s: No write allowed. dev_up = %lu\n", + wcd9xxx->dev, "%s: No write allowed. dev_up = %d\n", __func__, wcd9xxx->dev_up); ret = 0; goto done; @@ -426,7 +426,7 @@ int wcd9xxx_slim_bulk_write(struct wcd9xxx *wcd9xxx, if (!wcd9xxx->dev_up) { dev_dbg_ratelimited( - wcd9xxx->dev, "%s: No write allowed. dev_up = %lu\n", + wcd9xxx->dev, "%s: No write allowed. dev_up = %d\n", __func__, wcd9xxx->dev_up); return 0; } @@ -1484,27 +1484,12 @@ static int wcd9xxx_slim_device_reset(struct slim_device *sldev) return -EINVAL; } - /* - * Wait for 500 ms for device down to complete. Observed delay - * of ~200ms for device down to complete after being called, - * due to context switch issue. - */ - ret = wait_on_bit_timeout(&wcd9xxx->dev_up, 0, - TASK_INTERRUPTIBLE, - msecs_to_jiffies(500)); - if (ret) - pr_err("%s: slim device down not complete in 500 msec\n", - __func__); + dev_info(wcd9xxx->dev, "%s: device reset, dev_up = %d\n", + __func__, wcd9xxx->dev_up); + if (wcd9xxx->dev_up) + return 0; mutex_lock(&wcd9xxx->reset_lock); - - dev_info(wcd9xxx->dev, "%s: device reset, dev_up = %lu\n", - __func__, wcd9xxx->dev_up); - if (wcd9xxx->dev_up) { - mutex_unlock(&wcd9xxx->reset_lock); - return 0; - } - ret = wcd9xxx_reset(wcd9xxx->dev); if (ret) dev_err(wcd9xxx->dev, "%s: Resetting Codec failed\n", __func__); @@ -1522,8 +1507,8 @@ static int wcd9xxx_slim_device_up(struct slim_device *sldev) pr_err("%s: wcd9xxx is NULL\n", __func__); return -EINVAL; } - dev_info(wcd9xxx->dev, "%s: slim device up, dev_up = %lu\n", - __func__, wcd9xxx->dev_up); + dev_info(wcd9xxx->dev, "%s: slim device up, dev_up = %d\n", + __func__, wcd9xxx->dev_up); if (wcd9xxx->dev_up) return 0; @@ -1545,20 +1530,18 @@ static int wcd9xxx_slim_device_down(struct slim_device *sldev) return -EINVAL; } - mutex_lock(&wcd9xxx->reset_lock); - - dev_info(wcd9xxx->dev, "%s: device down, dev_up = %lu\n", - __func__, wcd9xxx->dev_up); - if (!wcd9xxx->dev_up) { - mutex_unlock(&wcd9xxx->reset_lock); + dev_info(wcd9xxx->dev, "%s: device down, dev_up = %d\n", + __func__, wcd9xxx->dev_up); + if (!wcd9xxx->dev_up) return 0; - } + wcd9xxx->dev_up = false; + + mutex_lock(&wcd9xxx->reset_lock); if (wcd9xxx->dev_down) wcd9xxx->dev_down(wcd9xxx); wcd9xxx_irq_exit(&wcd9xxx->core_res); wcd9xxx_reset_low(wcd9xxx->dev); - wcd9xxx->dev_up = false; mutex_unlock(&wcd9xxx->reset_lock); return 0; From 15fffc6b9b8ab71e2bbed8caced567c61523afc1 Mon Sep 17 00:00:00 2001 From: Banajit Goswami Date: Sat, 21 Oct 2017 01:12:47 -0700 Subject: [PATCH 2/2] asoc: wcd934x: set bus down flag right when notification reaches Set bus_down_in_recovery flag as soon as possible when BUS down notification reaches codec driver. This is to avoid any unwanted slimbus transaction while BUS is still not recovered. Change-Id: I77917975372bf51e6aa881cbfc63c479478db375 Signed-off-by: Banajit Goswami --- asoc/codecs/wcd934x/wcd934x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asoc/codecs/wcd934x/wcd934x.c b/asoc/codecs/wcd934x/wcd934x.c index d6eb22d579..1f751ec4b5 100644 --- a/asoc/codecs/wcd934x/wcd934x.c +++ b/asoc/codecs/wcd934x/wcd934x.c @@ -9203,13 +9203,13 @@ static int tavil_device_down(struct wcd9xxx *wcd9xxx) codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv); priv = snd_soc_codec_get_drvdata(codec); + for (count = 0; count < NUM_CODEC_DAIS; count++) + priv->dai[count].bus_down_in_recovery = true; if (priv->swr.ctrl_data) swrm_wcd_notify(priv->swr.ctrl_data[0].swr_pdev, SWR_DEVICE_DOWN, NULL); tavil_dsd_reset(priv->dsd_config); snd_soc_card_change_online_state(codec->component.card, 0); - for (count = 0; count < NUM_CODEC_DAIS; count++) - priv->dai[count].bus_down_in_recovery = true; wcd_dsp_ssr_event(priv->wdsp_cntl, WCD_CDC_DOWN_EVENT); wcd_resmgr_set_sido_input_src_locked(priv->resmgr, SIDO_SOURCE_INTERNAL);