Skip to content

Commit 1f8fd94

Browse files
Pei Xiaobroonie
authored andcommitted
spi: zynq-qspi: Simplify clock handling with devm_clk_get_enabled()
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>
1 parent 591cd65 commit 1f8fd94

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
@@ -381,21 +381,10 @@ static int zynq_qspi_setup_op(struct spi_device *spi)
381381
{
382382
struct spi_controller *ctlr = spi->controller;
383383
struct zynq_qspi *qspi = spi_controller_get_devdata(ctlr);
384-
int ret;
385384

386385
if (ctlr->busy)
387386
return -EBUSY;
388387

389-
ret = clk_enable(qspi->refclk);
390-
if (ret)
391-
return ret;
392-
393-
ret = clk_enable(qspi->pclk);
394-
if (ret) {
395-
clk_disable(qspi->refclk);
396-
return ret;
397-
}
398-
399388
zynq_qspi_write(qspi, ZYNQ_QSPI_ENABLE_OFFSET,
400389
ZYNQ_QSPI_ENABLE_ENABLE_MASK);
401390

@@ -661,7 +650,7 @@ static int zynq_qspi_probe(struct platform_device *pdev)
661650
goto remove_ctlr;
662651
}
663652

664-
xqspi->pclk = devm_clk_get(&pdev->dev, "pclk");
653+
xqspi->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
665654
if (IS_ERR(xqspi->pclk)) {
666655
dev_err(&pdev->dev, "pclk clock not found.\n");
667656
ret = PTR_ERR(xqspi->pclk);
@@ -670,36 +659,24 @@ static int zynq_qspi_probe(struct platform_device *pdev)
670659

671660
init_completion(&xqspi->data_completion);
672661

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

680-
ret = clk_prepare_enable(xqspi->pclk);
681-
if (ret) {
682-
dev_err(&pdev->dev, "Unable to enable APB clock.\n");
683-
goto remove_ctlr;
684-
}
685-
686-
ret = clk_prepare_enable(xqspi->refclk);
687-
if (ret) {
688-
dev_err(&pdev->dev, "Unable to enable device clock.\n");
689-
goto clk_dis_pclk;
690-
}
691-
692669
xqspi->irq = platform_get_irq(pdev, 0);
693670
if (xqspi->irq < 0) {
694671
ret = xqspi->irq;
695-
goto clk_dis_all;
672+
goto remove_ctlr;
696673
}
697674
ret = devm_request_irq(&pdev->dev, xqspi->irq, zynq_qspi_irq,
698675
0, pdev->name, xqspi);
699676
if (ret != 0) {
700677
ret = -ENXIO;
701678
dev_err(&pdev->dev, "request_irq failed\n");
702-
goto clk_dis_all;
679+
goto remove_ctlr;
703680
}
704681

705682
ret = of_property_read_u32(np, "num-cs",
@@ -709,7 +686,7 @@ static int zynq_qspi_probe(struct platform_device *pdev)
709686
} else if (num_cs > ZYNQ_QSPI_MAX_NUM_CS) {
710687
ret = -EINVAL;
711688
dev_err(&pdev->dev, "only 2 chip selects are available\n");
712-
goto clk_dis_all;
689+
goto remove_ctlr;
713690
} else {
714691
ctlr->num_chipselect = num_cs;
715692
}
@@ -728,15 +705,11 @@ static int zynq_qspi_probe(struct platform_device *pdev)
728705
ret = devm_spi_register_controller(&pdev->dev, ctlr);
729706
if (ret) {
730707
dev_err(&pdev->dev, "devm_spi_register_controller failed\n");
731-
goto clk_dis_all;
708+
goto remove_ctlr;
732709
}
733710

734711
return ret;
735712

736-
clk_dis_all:
737-
clk_disable_unprepare(xqspi->refclk);
738-
clk_dis_pclk:
739-
clk_disable_unprepare(xqspi->pclk);
740713
remove_ctlr:
741714
spi_controller_put(ctlr);
742715

@@ -758,9 +731,6 @@ static void zynq_qspi_remove(struct platform_device *pdev)
758731
struct zynq_qspi *xqspi = platform_get_drvdata(pdev);
759732

760733
zynq_qspi_write(xqspi, ZYNQ_QSPI_ENABLE_OFFSET, 0);
761-
762-
clk_disable_unprepare(xqspi->refclk);
763-
clk_disable_unprepare(xqspi->pclk);
764734
}
765735

766736
static const struct of_device_id zynq_qspi_of_match[] = {

0 commit comments

Comments
 (0)