Skip to content

Commit dc2044e

Browse files
Pei Xiaogregkh
authored andcommitted
spi: zynq-qspi: Simplify clock handling with devm_clk_get_enabled()
[ Upstream commit 1f8fd94 ] Replace devm_clk_get() followed by clk_prepare_enable() with devm_clk_get_enabled() for both "pclk" and "ref_clk". This removes the need for explicit clock enable and disable calls, as the managed API automatically disables the clocks on device removal or probe failure. Remove the now-unnecessary clk_disable_unprepare() calls from the probe error paths and the remove callback. Simplify error handling by jumping directly to the remove_ctlr label. Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn> Acked-by: Michal Simek <michal.simek@amd.com> Link: https://patch.msgid.link/24043625f89376da36feca2408f990a85be7ab36.1775555500.git.xiaopei01@kylinos.cn Signed-off-by: Mark Brown <broonie@kernel.org> Stable-dep-of: c9c0127 ("spi: zynq-qspi: fix controller deregistration") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ae6ee9f commit dc2044e

1 file changed

Lines changed: 6 additions & 36 deletions

File tree

drivers/spi/spi-zynq-qspi.c

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -379,21 +379,10 @@ static int zynq_qspi_setup_op(struct spi_device *spi)
379379
{
380380
struct spi_controller *ctlr = spi->controller;
381381
struct zynq_qspi *qspi = spi_controller_get_devdata(ctlr);
382-
int ret;
383382

384383
if (ctlr->busy)
385384
return -EBUSY;
386385

387-
ret = clk_enable(qspi->refclk);
388-
if (ret)
389-
return ret;
390-
391-
ret = clk_enable(qspi->pclk);
392-
if (ret) {
393-
clk_disable(qspi->refclk);
394-
return ret;
395-
}
396-
397386
zynq_qspi_write(qspi, ZYNQ_QSPI_ENABLE_OFFSET,
398387
ZYNQ_QSPI_ENABLE_ENABLE_MASK);
399388

@@ -659,7 +648,7 @@ static int zynq_qspi_probe(struct platform_device *pdev)
659648
goto remove_ctlr;
660649
}
661650

662-
xqspi->pclk = devm_clk_get(&pdev->dev, "pclk");
651+
xqspi->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
663652
if (IS_ERR(xqspi->pclk)) {
664653
dev_err(&pdev->dev, "pclk clock not found.\n");
665654
ret = PTR_ERR(xqspi->pclk);
@@ -668,36 +657,24 @@ static int zynq_qspi_probe(struct platform_device *pdev)
668657

669658
init_completion(&xqspi->data_completion);
670659

671-
xqspi->refclk = devm_clk_get(&pdev->dev, "ref_clk");
660+
xqspi->refclk = devm_clk_get_enabled(&pdev->dev, "ref_clk");
672661
if (IS_ERR(xqspi->refclk)) {
673662
dev_err(&pdev->dev, "ref_clk clock not found.\n");
674663
ret = PTR_ERR(xqspi->refclk);
675664
goto remove_ctlr;
676665
}
677666

678-
ret = clk_prepare_enable(xqspi->pclk);
679-
if (ret) {
680-
dev_err(&pdev->dev, "Unable to enable APB clock.\n");
681-
goto remove_ctlr;
682-
}
683-
684-
ret = clk_prepare_enable(xqspi->refclk);
685-
if (ret) {
686-
dev_err(&pdev->dev, "Unable to enable device clock.\n");
687-
goto clk_dis_pclk;
688-
}
689-
690667
xqspi->irq = platform_get_irq(pdev, 0);
691668
if (xqspi->irq < 0) {
692669
ret = xqspi->irq;
693-
goto clk_dis_all;
670+
goto remove_ctlr;
694671
}
695672
ret = devm_request_irq(&pdev->dev, xqspi->irq, zynq_qspi_irq,
696673
0, pdev->name, xqspi);
697674
if (ret != 0) {
698675
ret = -ENXIO;
699676
dev_err(&pdev->dev, "request_irq failed\n");
700-
goto clk_dis_all;
677+
goto remove_ctlr;
701678
}
702679

703680
ret = of_property_read_u32(np, "num-cs",
@@ -707,7 +684,7 @@ static int zynq_qspi_probe(struct platform_device *pdev)
707684
} else if (num_cs > ZYNQ_QSPI_MAX_NUM_CS) {
708685
ret = -EINVAL;
709686
dev_err(&pdev->dev, "only 2 chip selects are available\n");
710-
goto clk_dis_all;
687+
goto remove_ctlr;
711688
} else {
712689
ctlr->num_chipselect = num_cs;
713690
}
@@ -725,15 +702,11 @@ static int zynq_qspi_probe(struct platform_device *pdev)
725702
ret = devm_spi_register_controller(&pdev->dev, ctlr);
726703
if (ret) {
727704
dev_err(&pdev->dev, "devm_spi_register_controller failed\n");
728-
goto clk_dis_all;
705+
goto remove_ctlr;
729706
}
730707

731708
return ret;
732709

733-
clk_dis_all:
734-
clk_disable_unprepare(xqspi->refclk);
735-
clk_dis_pclk:
736-
clk_disable_unprepare(xqspi->pclk);
737710
remove_ctlr:
738711
spi_controller_put(ctlr);
739712

@@ -755,9 +728,6 @@ static void zynq_qspi_remove(struct platform_device *pdev)
755728
struct zynq_qspi *xqspi = platform_get_drvdata(pdev);
756729

757730
zynq_qspi_write(xqspi, ZYNQ_QSPI_ENABLE_OFFSET, 0);
758-
759-
clk_disable_unprepare(xqspi->refclk);
760-
clk_disable_unprepare(xqspi->pclk);
761731
}
762732

763733
static const struct of_device_id zynq_qspi_of_match[] = {

0 commit comments

Comments
 (0)