ASoC: atmel: mchp-spdifrx: Improve driver cleanup and error handling
cover ASoC: atmel: mchp-spdifrx: Improve driver cleanup and error handling
From: bui duc phuc <[email protected]>
Hi all,
This series improves probe error handling and runtime PM cleanup, adjusts IRQ registration order, and fixes error propagation in the ulock get callback.
Compile-tested only.
Best regards,
Phuc
bui duc phuc (4):
ASoC: atmel: mchp-spdifrx: Improve probe error handling
ASoC: atmel: mchp-spdifrx: Use devm helpers for runtime PM
ASoC: atmel: mchp-spdifrx: Move IRQ request after runtime PM setup
ASoC: atmel: mchp-spdifrx: Propagate runtime PM errors in ulock get
sound/soc/atmel/mchp-spdifrx.c | 81 ++++++++++++++++------------------ 1 file changed, 39 insertions(+), 42 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/4 ASoC: atmel: mchp-spdifrx: Improve probe error handling
From: bui duc phuc <[email protected]>
Use dev_err_probe() when retrieving clocks to avoid logging errors for deferred probes.
--- sound/soc/atmel/mchp-spdifrx.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
sound/soc/atmel/mchp-spdifrx.c +6 -12
@@ -1116,21 +1116,15 @@ static int mchp_spdifrx_probe(struct platform_device *pdev)/* Get the peripheral clock */ dev->pclk =devm_clk_get (&pdev->dev,"pclk" ); -if (IS_ERR (dev->pclk)) { - err =PTR_ERR (dev->pclk); -dev_err (&pdev->dev,"failed to get the peripheral clock: %d\n" , - err); -return err; - } +if (IS_ERR (dev->pclk)) +return dev_err_probe (&pdev->dev,PTR_ERR (dev->pclk), +"failed to get the peripheral clock\n" );/* Get the generated clock */ dev->gclk =devm_clk_get (&pdev->dev,"gclk" ); -if (IS_ERR (dev->gclk)) { - err =PTR_ERR (dev->gclk); -dev_err (&pdev->dev, -"failed to get the PMC generated clock: %d\n" , err); -return err; - } +if (IS_ERR (dev->gclk)) +return dev_err_probe (&pdev->dev,PTR_ERR (dev->gclk), +"failed to get the PMC generated clock\n" );/* * Signal control need a valid rate on gclk. hw_params() configures
Signature · 1 line
2.43.0
PATCH 2/4 ASoC: atmel: mchp-spdifrx: Use devm helpers for runtime PM
In reply to [email protected]From: bui duc phuc <[email protected]>
Use devm_pm_runtime_enable() and a devm action to handle runtime PM cleanup automatically.
This removes the manual runtime PM cleanup from the probe error paths and the remove callback.
--- sound/soc/atmel/mchp-spdifrx.c | 47 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-)
sound/soc/atmel/mchp-spdifrx.c +25 -22
@@ -1079,6 +1079,15 @@ static const struct dev_pm_ops mchp_spdifrx_pm_ops = { NULL) }; +/* Runtime suspend the device on cleanup if necessary */ +static void mchp_spdifrx_runtime_suspend_action (void *data) +{ +struct device *dev = data; + +if (!pm_runtime_status_suspended (dev)) +mchp_spdifrx_runtime_suspend (dev); +} +static int mchp_spdifrx_probe (struct platform_device *pdev) {struct mchp_spdifrx_dev *dev;
@@ -1141,11 +1150,22 @@ static int mchp_spdifrx_probe(struct platform_device *pdev) dev->regmap = regmap;platform_set_drvdata (pdev, dev); -pm_runtime_enable (dev->dev); + err =devm_add_action (dev->dev, mchp_spdifrx_runtime_suspend_action, + dev->dev); +if (err) +return err; + + err =devm_pm_runtime_enable (dev->dev); +if (err) +return err;if (!pm_runtime_enabled (dev->dev)) { err =mchp_spdifrx_runtime_resume (dev->dev); -if (err) - goto pm_runtime_disable; +if (err) { +devm_remove_action (dev->dev, + mchp_spdifrx_runtime_suspend_action, + dev->dev); +return err; + } } dev->capture.addr = (dma_addr_t )mem->start +SPDIFRX_RHR ;
@@ -1154,7 +1174,7 @@ static int mchp_spdifrx_probe(struct platform_device *pdev) err =devm_snd_dmaengine_pcm_register (&pdev->dev,NULL ,0 );if (err) {dev_err (&pdev->dev,"failed to register PCM: %d\n" , err); - goto pm_runtime_suspend; +return err; } err = devm_snd_soc_register_component(&pdev->dev,
@@ -1162,34 +1182,17 @@ static int mchp_spdifrx_probe(struct platform_device *pdev) &mchp_spdifrx_dai, 1);if (err) {dev_err (&pdev->dev,"fail to register dai\n" ); - goto pm_runtime_suspend; +return err; }regmap_read (regmap,SPDIFRX_VERSION , &vers);dev_info (&pdev->dev,"hw version: %#lx\n" , vers &SPDIFRX_VERSION_MASK );return 0 ; - -pm_runtime_suspend: -if (!pm_runtime_status_suspended (dev->dev)) -mchp_spdifrx_runtime_suspend (dev->dev); -pm_runtime_disable: -pm_runtime_disable (dev->dev); -return err; -} - -static void mchp_spdifrx_remove (struct platform_device *pdev) -{ -struct mchp_spdifrx_dev *dev =platform_get_drvdata (pdev); - -pm_runtime_disable (dev->dev); -if (!pm_runtime_status_suspended (dev->dev)) -mchp_spdifrx_runtime_suspend (dev->dev); }static struct platform_driver mchp_spdifrx_driver = { .probe = mchp_spdifrx_probe, - .remove = mchp_spdifrx_remove, .driver = { .name ="mchp_spdifrx" , .of_match_table = mchp_spdifrx_dt_ids,
Signature · 1 line
2.43.0
PATCH 3/4 ASoC: atmel: mchp-spdifrx: Move IRQ request after runtime PM setup
In reply to [email protected]From: bui duc phuc <[email protected]>
Move devm_request_irq() after runtime PM setup to ensure the IRQ is released before the runtime suspend action runs during cleanup.
--- sound/soc/atmel/mchp-spdifrx.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
sound/soc/atmel/mchp-spdifrx.c +7 -6
@@ -1113,16 +1113,11 @@ static int mchp_spdifrx_probe(struct platform_device *pdev)if (IS_ERR (regmap))return PTR_ERR (regmap); -/* Request IRQ. */ +/* Get IRQ. */ irq =platform_get_irq (pdev,0 );if (irq <0 )return irq; - err =devm_request_irq (&pdev->dev, irq, mchp_spdif_interrupt,0 , -dev_name (&pdev->dev), dev); -if (err) -return err; -/* Get the peripheral clock */ dev->pclk =devm_clk_get (&pdev->dev,"pclk" );if (IS_ERR (dev->pclk))
@@ -1168,6 +1163,12 @@ static int mchp_spdifrx_probe(struct platform_device *pdev) } } +/* Request IRQ. */ + err =devm_request_irq (&pdev->dev, irq, mchp_spdif_interrupt,0 , +dev_name (&pdev->dev), dev); +if (err) +return err; + dev->capture.addr = (dma_addr_t )mem->start +SPDIFRX_RHR ; dev->capture.maxburst =1 ;
Signature · 1 line
2.43.0
PATCH 4/4 ASoC: atmel: mchp-spdifrx: Propagate runtime PM errors in ulock get
In reply to [email protected]From: bui duc phuc <[email protected]>
Return the result of pm_runtime_resume_and_get() instead of comparing the old and current ulock values.
This ensures runtime PM errors are propagated to the caller.
--- sound/soc/atmel/mchp-spdifrx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/atmel/mchp-spdifrx.c +1 -2
@@ -709,7 +709,6 @@ static int mchp_spdifrx_ulock_get(struct snd_kcontrol *kcontrol,struct mchp_spdifrx_mixer_control *ctrl = &dev->control;u32 val;int ret; -bool ulock_old = ctrl->ulock;mutex_lock (&dev->mlock);
@@ -735,7 +734,7 @@ static int mchp_spdifrx_ulock_get(struct snd_kcontrol *kcontrol, unlock:mutex_unlock (&dev->mlock); -return ulock_old != ctrl->ulock; +return ret; } static int mchp_spdifrx_badf_get(struct snd_kcontrol *kcontrol,
Signature · 1 line
2.43.0