mirror of https://github.com/torvalds/linux.git
spi: bcm63xx-hsspi: Simplify clock handling with devm_clk_get_enabled()
Replace devm_clk_get() followed by clk_prepare_enable() with devm_clk_get_enabled() for both the "hsspi" and "pll" clocks. This reduces boilerplate code and error handling, as the managed API automatically disables the clocks when the device is removed or if probe fails. Remove the now-unnecessary clk_disable_unprepare() calls from the probe error paths and the remove callback. Accordingly, adjust the error handling labels to direct returns where possible. Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn> Link: https://patch.msgid.link/3a187be6d9963645f01caebc1169e06f8804b7a6.1773885292.git.xiaopei01@kylinos.cn Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
a37fb5166b
commit
e532e21a24
|
|
@ -758,8 +758,7 @@ static int bcm63xx_hsspi_probe(struct platform_device *pdev)
|
|||
if (IS_ERR(regs))
|
||||
return PTR_ERR(regs);
|
||||
|
||||
clk = devm_clk_get(dev, "hsspi");
|
||||
|
||||
clk = devm_clk_get_enabled(dev, "hsspi");
|
||||
if (IS_ERR(clk))
|
||||
return PTR_ERR(clk);
|
||||
|
||||
|
|
@ -767,41 +766,26 @@ static int bcm63xx_hsspi_probe(struct platform_device *pdev)
|
|||
if (IS_ERR(reset))
|
||||
return PTR_ERR(reset);
|
||||
|
||||
ret = clk_prepare_enable(clk);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = reset_control_reset(reset);
|
||||
if (ret) {
|
||||
dev_err(dev, "unable to reset device: %d\n", ret);
|
||||
goto out_disable_clk;
|
||||
}
|
||||
if (ret)
|
||||
return dev_err_probe(dev, ret, "unable to reset device: %d\n", ret);
|
||||
|
||||
rate = clk_get_rate(clk);
|
||||
if (!rate) {
|
||||
pll_clk = devm_clk_get(dev, "pll");
|
||||
|
||||
if (IS_ERR(pll_clk)) {
|
||||
ret = PTR_ERR(pll_clk);
|
||||
goto out_disable_clk;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(pll_clk);
|
||||
if (ret)
|
||||
goto out_disable_clk;
|
||||
pll_clk = devm_clk_get_enabled(dev, "pll");
|
||||
if (IS_ERR(pll_clk))
|
||||
return dev_err_probe(dev, PTR_ERR(pll_clk),
|
||||
"failed enable pll clk\n");
|
||||
|
||||
rate = clk_get_rate(pll_clk);
|
||||
if (!rate) {
|
||||
ret = -EINVAL;
|
||||
goto out_disable_pll_clk;
|
||||
}
|
||||
if (!rate)
|
||||
return dev_err_probe(dev, -EINVAL,
|
||||
"failed get pll clk rate\n");
|
||||
}
|
||||
|
||||
host = spi_alloc_host(&pdev->dev, sizeof(*bs));
|
||||
if (!host) {
|
||||
ret = -ENOMEM;
|
||||
goto out_disable_pll_clk;
|
||||
}
|
||||
if (!host)
|
||||
return dev_err_probe(dev, -ENOMEM, "alloc host no mem\n");
|
||||
|
||||
bs = spi_controller_get_devdata(host);
|
||||
bs->pdev = pdev;
|
||||
|
|
@ -887,10 +871,6 @@ static int bcm63xx_hsspi_probe(struct platform_device *pdev)
|
|||
pm_runtime_disable(&pdev->dev);
|
||||
out_put_host:
|
||||
spi_controller_put(host);
|
||||
out_disable_pll_clk:
|
||||
clk_disable_unprepare(pll_clk);
|
||||
out_disable_clk:
|
||||
clk_disable_unprepare(clk);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -902,8 +882,6 @@ static void bcm63xx_hsspi_remove(struct platform_device *pdev)
|
|||
|
||||
/* reset the hardware and block queue progress */
|
||||
__raw_writel(0, bs->regs + HSSPI_INT_MASK_REG);
|
||||
clk_disable_unprepare(bs->pll_clk);
|
||||
clk_disable_unprepare(bs->clk);
|
||||
sysfs_remove_group(&pdev->dev.kobj, &bcm63xx_hsspi_group);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue