drm/bridge: sii902x: Balance audio mclk enable and disable
Subsystems (3)
PATCH 1/1 drm/bridge: sii902x: Balance audio mclk enable and disable
The driver currently has an unbalanced clk enable count, as sii902x_audio_hw_params() enables the mclk, but sii902x_audio_shutdown() disables it unconditionally. This creates a few issues:
1. hdmi-codec calls audio_shutdown() on every PCM close, even if hw_params() never ran. For example, PipeWire queries the hw params at initialization, via:
aplay -D hw:0,0 --dump-hw-params /dev/zero
The clock core then hits WARN() in clk_core_disable() and clk_core_unprepare(), printing a backtrace and tainting the kernel:
sii9022-mclk already disabled
sii9022-mclk already unprepared
2. A second hw_params() without a shutdown in between enables the clock again, thus the count never returns to zero.
Therefore track whether hw_params() enabled the clock, and only disable it in that case, to keep the clock enable count balanced.
--- drivers/gpu/drm/bridge/sii902x.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/gpu/drm/bridge/sii902x.c +13 -5
@@ -186,6 +186,7 @@ struct sii902x {*/ struct mutex mutex;struct sii902x_audio { +bool mclk_enabled;struct platform_device *pdev;struct clk *mclk;u32 i2s_fifo_sequence[4 ];
@@ -681,10 +682,13 @@ static int sii902x_audio_hw_params(struct device *dev, void *data, } } - ret =clk_prepare_enable (sii902x->audio.mclk); -if (ret) { -dev_err (dev,"Enabling mclk failed: %d\n" , ret); -return ret; +if (!sii902x->audio.mclk_enabled) { + ret =clk_prepare_enable (sii902x->audio.mclk); +if (ret) { +dev_err (dev,"Enabling mclk failed: %d\n" , ret); +return ret; + } + sii902x->audio.mclk_enabled = true; }if (sii902x->audio.mclk) {
@@ -761,6 +765,7 @@ static int sii902x_audio_hw_params(struct device *dev, void *data,if (ret) {clk_disable_unprepare (sii902x->audio.mclk); + sii902x->audio.mclk_enabled = false;dev_err (dev,"%s: hdmi audio enable failed: %d\n" , __func__, ret); }
@@ -779,7 +784,10 @@ static void sii902x_audio_shutdown(struct device *dev, void *data)mutex_unlock (&sii902x->mutex); -clk_disable_unprepare (sii902x->audio.mclk); +if (sii902x->audio.mclk_enabled) { +clk_disable_unprepare (sii902x->audio.mclk); + sii902x->audio.mclk_enabled = false; + } } static int sii902x_audio_mute(struct device *dev, void *data,
Signature · 1 line
2.43.0