Skip to content

Commit 2d90ecd

Browse files
CassivsGabriellisbroonie
authored andcommitted
ASoC: rockchip: i2s: Use managed hclk and runtime PM cleanup
The Rockchip I2S driver mixes devm-managed probe resources with manual runtime PM and hclk cleanup. This leaves the remove path doing runtime PM shutdown and clock disable before devm-managed ASoC and PCM resources are released. Keep the bus clock enabled for the device lifetime with devm_clk_get_enabled(), and move the runtime PM teardown into devres so the unwind order matches the managed registrations. This also removes the remove callback, which only existed for cleanup. Use a devm action for the final runtime suspend and register it before the managed runtime PM action, so teardown disables runtime PM before forcing the device into the suspended state. Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com> Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com> Link: https://patch.msgid.link/20260521-asoc-rockchip-i2s-devm-cleanup-v1-1-9319bd781393@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent cab82ca commit 2d90ecd

1 file changed

Lines changed: 26 additions & 42 deletions

File tree

sound/soc/rockchip/rockchip_i2s.c

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,14 @@ static const struct of_device_id rockchip_i2s_match[] __maybe_unused = {
664664
};
665665
MODULE_DEVICE_TABLE(of, rockchip_i2s_match);
666666

667+
static void rockchip_i2s_suspend(void *data)
668+
{
669+
struct device *dev = data;
670+
671+
if (!pm_runtime_status_suspended(dev))
672+
i2s_runtime_suspend(dev);
673+
}
674+
667675
static int rockchip_i2s_init_dai(struct rk_i2s_dev *i2s, struct resource *res,
668676
struct snd_soc_dai_driver **dp)
669677
{
@@ -758,37 +766,28 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
758766
}
759767

760768
/* try to prepare related clocks */
761-
i2s->hclk = devm_clk_get(&pdev->dev, "i2s_hclk");
769+
i2s->hclk = devm_clk_get_enabled(&pdev->dev, "i2s_hclk");
762770
if (IS_ERR(i2s->hclk)) {
763771
dev_err(&pdev->dev, "Can't retrieve i2s bus clock\n");
764772
return PTR_ERR(i2s->hclk);
765773
}
766-
ret = clk_prepare_enable(i2s->hclk);
767-
if (ret) {
768-
dev_err(i2s->dev, "hclock enable failed %d\n", ret);
769-
return ret;
770-
}
771774

772775
i2s->mclk = devm_clk_get(&pdev->dev, "i2s_clk");
773776
if (IS_ERR(i2s->mclk)) {
774777
dev_err(&pdev->dev, "Can't retrieve i2s master clock\n");
775-
ret = PTR_ERR(i2s->mclk);
776-
goto err_clk;
778+
return PTR_ERR(i2s->mclk);
777779
}
778780

779781
regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
780-
if (IS_ERR(regs)) {
781-
ret = PTR_ERR(regs);
782-
goto err_clk;
783-
}
782+
if (IS_ERR(regs))
783+
return PTR_ERR(regs);
784784

785785
i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
786786
&rockchip_i2s_regmap_config);
787787
if (IS_ERR(i2s->regmap)) {
788788
dev_err(&pdev->dev,
789789
"Failed to initialise managed register map\n");
790-
ret = PTR_ERR(i2s->regmap);
791-
goto err_clk;
790+
return PTR_ERR(i2s->regmap);
792791
}
793792

794793
i2s->bclk_ratio = 64;
@@ -799,8 +798,7 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
799798
i2s->bclk_off = pinctrl_lookup_state(i2s->pinctrl, "bclk_off");
800799
if (IS_ERR_OR_NULL(i2s->bclk_off)) {
801800
dev_err(&pdev->dev, "failed to find i2s bclk_off\n");
802-
ret = -EINVAL;
803-
goto err_clk;
801+
return -EINVAL;
804802
}
805803
}
806804
} else {
@@ -811,53 +809,40 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
811809

812810
dev_set_drvdata(&pdev->dev, i2s);
813811

814-
pm_runtime_enable(&pdev->dev);
812+
ret = devm_add_action(&pdev->dev, rockchip_i2s_suspend, &pdev->dev);
813+
if (ret)
814+
return ret;
815+
816+
ret = devm_pm_runtime_enable(&pdev->dev);
817+
if (ret)
818+
return ret;
819+
815820
if (!pm_runtime_enabled(&pdev->dev)) {
816821
ret = i2s_runtime_resume(&pdev->dev);
817822
if (ret)
818-
goto err_pm_disable;
823+
return ret;
819824
}
820825

821826
ret = rockchip_i2s_init_dai(i2s, res, &dai);
822827
if (ret)
823-
goto err_pm_disable;
828+
return ret;
824829

825830
ret = devm_snd_soc_register_component(&pdev->dev,
826831
&rockchip_i2s_component,
827832
dai, 1);
828833

829834
if (ret) {
830835
dev_err(&pdev->dev, "Could not register DAI\n");
831-
goto err_suspend;
836+
return ret;
832837
}
833838

834839
ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
835840
if (ret) {
836841
dev_err(&pdev->dev, "Could not register PCM\n");
837-
goto err_suspend;
842+
return ret;
838843
}
839844

840845
return 0;
841-
842-
err_suspend:
843-
if (!pm_runtime_status_suspended(&pdev->dev))
844-
i2s_runtime_suspend(&pdev->dev);
845-
err_pm_disable:
846-
pm_runtime_disable(&pdev->dev);
847-
err_clk:
848-
clk_disable_unprepare(i2s->hclk);
849-
return ret;
850-
}
851-
852-
static void rockchip_i2s_remove(struct platform_device *pdev)
853-
{
854-
struct rk_i2s_dev *i2s = dev_get_drvdata(&pdev->dev);
855-
856-
pm_runtime_disable(&pdev->dev);
857-
if (!pm_runtime_status_suspended(&pdev->dev))
858-
i2s_runtime_suspend(&pdev->dev);
859-
860-
clk_disable_unprepare(i2s->hclk);
861846
}
862847

863848
static const struct dev_pm_ops rockchip_i2s_pm_ops = {
@@ -866,7 +851,6 @@ static const struct dev_pm_ops rockchip_i2s_pm_ops = {
866851

867852
static struct platform_driver rockchip_i2s_driver = {
868853
.probe = rockchip_i2s_probe,
869-
.remove = rockchip_i2s_remove,
870854
.driver = {
871855
.name = DRV_NAME,
872856
.of_match_table = of_match_ptr(rockchip_i2s_match),

0 commit comments

Comments
 (0)