Fix msm8916-wcd-digital ASoC DAPM teardown crash after notification audio

This commit is contained in:
Luxferre committed 2026-11-03 13:40:42 +02:00
1 parent 06d991d4fa
commit b9e7c6847b
13 files changed
+15 -119

No files matched your search

@@ -378,120 +378,4 @@
+ wcn->hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
wcn->hw->queues = 4;
--- a/sound/soc/codecs/msm8916-wcd-digital.c
+++ b/sound/soc/codecs/msm8916-wcd-digital.c
@@ -226,6 +226,9 @@
struct msm8916_wcd_digital_priv {
struct clk *ahbclk, *mclk;
+ struct regmap *regmap;
+ struct mutex clk_lock;
+ int active_streams;
};
static const unsigned long rx_gain_reg[] = {
@@ -1075,8 +1078,27 @@
struct snd_soc_component *component = dai->component;
struct msm8916_wcd_digital_priv *msm8916_wcd;
unsigned long mclk_rate;
+ int ret;
msm8916_wcd = snd_soc_component_get_drvdata(component);
+
+ mutex_lock(&msm8916_wcd->clk_lock);
+ if (msm8916_wcd->active_streams == 0) {
+ ret = clk_prepare_enable(msm8916_wcd->ahbclk);
+ if (ret < 0) {
+ mutex_unlock(&msm8916_wcd->clk_lock);
+ return ret;
+ }
+ ret = clk_prepare_enable(msm8916_wcd->mclk);
+ if (ret < 0) {
+ clk_disable_unprepare(msm8916_wcd->ahbclk);
+ mutex_unlock(&msm8916_wcd->clk_lock);
+ return ret;
+ }
+ }
+ msm8916_wcd->active_streams++;
+ mutex_unlock(&msm8916_wcd->clk_lock);
+
snd_soc_component_update_bits(component, LPASS_CDC_CLK_MCLK_CTL,
MCLK_CTL_MCLK_EN_MASK,
MCLK_CTL_MCLK_EN_ENABLE);
@@ -1106,8 +1128,22 @@
static void msm8916_wcd_digital_shutdown(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
- snd_soc_component_update_bits(dai->component, LPASS_CDC_CLK_PDM_CTL,
+ struct snd_soc_component *component = dai->component;
+ struct msm8916_wcd_digital_priv *msm8916_wcd =
+ snd_soc_component_get_drvdata(component);
+
+ snd_soc_component_update_bits(component, LPASS_CDC_CLK_PDM_CTL,
LPASS_CDC_CLK_PDM_CTL_PDM_CLK_SEL_MASK, 0);
+ snd_soc_component_update_bits(component, LPASS_CDC_CLK_MCLK_CTL,
+ MCLK_CTL_MCLK_EN_MASK, 0);
+
+ mutex_lock(&msm8916_wcd->clk_lock);
+ if (msm8916_wcd->active_streams > 0 &&
+ --msm8916_wcd->active_streams == 0) {
+ clk_disable_unprepare(msm8916_wcd->mclk);
+ clk_disable_unprepare(msm8916_wcd->ahbclk);
+ }
+ mutex_unlock(&msm8916_wcd->clk_lock);
}
static const struct snd_soc_dai_ops msm8916_wcd_digital_dai_ops = {
@@ -1177,15 +1213,18 @@
if (!priv)
return -ENOMEM;
+ mutex_init(&priv->clk_lock);
+
base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(base))
return PTR_ERR(base);
digital_map =
- devm_regmap_init_mmio(&pdev->dev, base,
- &msm8916_codec_regmap_config);
+ devm_regmap_init_mmio_clk(&pdev->dev, "ahbix-clk", base,
+ &msm8916_codec_regmap_config);
if (IS_ERR(digital_map))
return PTR_ERR(digital_map);
+ priv->regmap = digital_map;
ret = msm8916_wcd_digital_get_clks(pdev, priv);
if (ret < 0)
@@ -1211,6 +1250,14 @@
if (ret)
goto err_mclk;
+ /*
+ * Gate mclk and ahbclk at idle; regmap_mmio_clk enables ahbix-clk
+ * on-demand for mixer reads/writes, and startup/shutdown enables
+ * both clocks while any PCM stream is active.
+ */
+ clk_disable_unprepare(priv->mclk);
+ clk_disable_unprepare(priv->ahbclk);
+
return 0;
err_mclk:
@@ -1224,8 +1271,13 @@
{
struct msm8916_wcd_digital_priv *priv = dev_get_drvdata(&pdev->dev);
- clk_disable_unprepare(priv->mclk);
- clk_disable_unprepare(priv->ahbclk);
+ mutex_lock(&priv->clk_lock);
+ if (priv->active_streams > 0) {
+ priv->active_streams = 0;
+ clk_disable_unprepare(priv->mclk);
+ clk_disable_unprepare(priv->ahbclk);
+ }
+ mutex_unlock(&priv->clk_lock);
}
static const struct of_device_id msm8916_wcd_digital_match_table[] = {