From d577af909c4d073030d1ba2f86cebcbf9546fc8d Mon Sep 17 00:00:00 2001 From: Aditya Bavanari Date: Thu, 3 Oct 2019 21:09:19 +0530 Subject: [PATCH] asoc: codecs: Check for core votes count before accessing registers Check for core votes count before accessing swrm registers to avoid NOC errors. Change-Id: I5689d6a6db0886ed4cc791738a28290f3d953412 Signed-off-by: Aditya Bavanari --- asoc/codecs/bolero/bolero-cdc.c | 15 +++++++++++++++ asoc/codecs/bolero/bolero-cdc.h | 6 ++++++ asoc/codecs/bolero/rx-macro.c | 5 ++++- asoc/codecs/bolero/tx-macro.c | 6 ++++-- asoc/codecs/bolero/wsa-macro.c | 6 ++++-- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/asoc/codecs/bolero/bolero-cdc.c b/asoc/codecs/bolero/bolero-cdc.c index 76c9d4064276..4fe18e221229 100644 --- a/asoc/codecs/bolero/bolero-cdc.c +++ b/asoc/codecs/bolero/bolero-cdc.c @@ -1180,6 +1180,21 @@ int bolero_runtime_suspend(struct device *dev) } EXPORT_SYMBOL(bolero_runtime_suspend); +bool bolero_check_core_votes(struct device *dev) +{ + struct bolero_priv *priv = dev_get_drvdata(dev->parent); + bool ret = true; + + mutex_lock(&priv->vote_lock); + if ((priv->lpass_core_hw_vote && !priv->core_hw_vote_count) || + (priv->lpass_audio_hw_vote && !priv->core_audio_vote_count)) + ret = false; + mutex_unlock(&priv->vote_lock); + + return ret; +} +EXPORT_SYMBOL(bolero_check_core_votes); + static const struct of_device_id bolero_dt_match[] = { {.compatible = "qcom,bolero-codec"}, {} diff --git a/asoc/codecs/bolero/bolero-cdc.h b/asoc/codecs/bolero/bolero-cdc.h index 957389cea2d0..f104f88a34bb 100644 --- a/asoc/codecs/bolero/bolero-cdc.h +++ b/asoc/codecs/bolero/bolero-cdc.h @@ -84,6 +84,7 @@ int bolero_tx_clk_switch(struct snd_soc_component *component); int bolero_register_event_listener(struct snd_soc_component *component, bool enable); void bolero_wsa_pa_on(struct device *dev); +bool bolero_check_core_votes(struct device *dev); #else static inline int bolero_register_res_clk(struct device *dev, rsc_clk_cb_t cb) { @@ -158,5 +159,10 @@ static inline int bolero_register_event_listener( static void bolero_wsa_pa_on(struct device *dev) { } + +static inline bool bolero_check_core_votes(struct device *dev) +{ + return false; +} #endif /* CONFIG_SND_SOC_BOLERO */ #endif /* BOLERO_CDC_H */ diff --git a/asoc/codecs/bolero/rx-macro.c b/asoc/codecs/bolero/rx-macro.c index 9af15226efc3..e6ee4df40c33 100644 --- a/asoc/codecs/bolero/rx-macro.c +++ b/asoc/codecs/bolero/rx-macro.c @@ -3499,7 +3499,10 @@ static int rx_macro_core_vote(void *handle, bool enable) pm_runtime_mark_last_busy(rx_priv->dev); } - return 0; + if (bolero_check_core_votes(rx_priv->dev)) + return 0; + else + return -EINVAL; } static int rx_swrm_clock(void *handle, bool enable) diff --git a/asoc/codecs/bolero/tx-macro.c b/asoc/codecs/bolero/tx-macro.c index 45e0a80a309a..d5ec25c0ec50 100644 --- a/asoc/codecs/bolero/tx-macro.c +++ b/asoc/codecs/bolero/tx-macro.c @@ -1952,7 +1952,6 @@ static int tx_macro_clk_switch(struct snd_soc_component *component) static int tx_macro_core_vote(void *handle, bool enable) { struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle; - int ret = 0; if (tx_priv == NULL) { pr_err("%s: tx priv data is NULL\n", __func__); @@ -1964,7 +1963,10 @@ static int tx_macro_core_vote(void *handle, bool enable) pm_runtime_mark_last_busy(tx_priv->dev); } - return ret; + if (bolero_check_core_votes(tx_priv->dev)) + return 0; + else + return -EINVAL; } static int tx_macro_swrm_clock(void *handle, bool enable) diff --git a/asoc/codecs/bolero/wsa-macro.c b/asoc/codecs/bolero/wsa-macro.c index dfca96894e0b..c046bd5b368f 100644 --- a/asoc/codecs/bolero/wsa-macro.c +++ b/asoc/codecs/bolero/wsa-macro.c @@ -2802,7 +2802,6 @@ static void wsa_macro_init_reg(struct snd_soc_component *component) static int wsa_macro_core_vote(void *handle, bool enable) { struct wsa_macro_priv *wsa_priv = (struct wsa_macro_priv *) handle; - int ret = 0; if (wsa_priv == NULL) { pr_err("%s: wsa priv data is NULL\n", __func__); @@ -2814,7 +2813,10 @@ static int wsa_macro_core_vote(void *handle, bool enable) pm_runtime_mark_last_busy(wsa_priv->dev); } - return ret; + if (bolero_check_core_votes(wsa_priv->dev)) + return 0; + else + return -EINVAL; } static int wsa_swrm_clock(void *handle, bool enable)