Skip to content

Commit a38509f

Browse files
Bence Csókásbroonie
authored andcommitted
spi: atmel-quadspi: Use devm_ clock management
Clean up error handling by using the new devm_ clock handling functions. This should make it easier to add new code, as we can eliminate the "goto ladder" in probe(). Signed-off-by: Bence Csókás <csokas.bence@prolan.hu> Link: https://patch.msgid.link/20241219142851.430959-1-csokas.bence@prolan.hu Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent af103eb commit a38509f

File tree

1 file changed

+11
-31
lines changed

1 file changed

+11
-31
lines changed

drivers/spi/atmel-quadspi.c

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,50 +1393,37 @@ static int atmel_qspi_probe(struct platform_device *pdev)
13931393
aq->mmap_phys_base = (dma_addr_t)res->start;
13941394

13951395
/* Get the peripheral clock */
1396-
aq->pclk = devm_clk_get(&pdev->dev, "pclk");
1396+
aq->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
13971397
if (IS_ERR(aq->pclk))
1398-
aq->pclk = devm_clk_get(&pdev->dev, NULL);
1398+
aq->pclk = devm_clk_get_enabled(&pdev->dev, NULL);
13991399

14001400
if (IS_ERR(aq->pclk))
14011401
return dev_err_probe(&pdev->dev, PTR_ERR(aq->pclk),
14021402
"missing peripheral clock\n");
14031403

1404-
/* Enable the peripheral clock */
1405-
err = clk_prepare_enable(aq->pclk);
1406-
if (err)
1407-
return dev_err_probe(&pdev->dev, err,
1408-
"failed to enable the peripheral clock\n");
1409-
14101404
if (aq->caps->has_qspick) {
14111405
/* Get the QSPI system clock */
1412-
aq->qspick = devm_clk_get(&pdev->dev, "qspick");
1406+
aq->qspick = devm_clk_get_enabled(&pdev->dev, "qspick");
14131407
if (IS_ERR(aq->qspick)) {
14141408
dev_err(&pdev->dev, "missing system clock\n");
14151409
err = PTR_ERR(aq->qspick);
1416-
goto disable_pclk;
1410+
return err;
14171411
}
14181412

1419-
/* Enable the QSPI system clock */
1420-
err = clk_prepare_enable(aq->qspick);
1421-
if (err) {
1422-
dev_err(&pdev->dev,
1423-
"failed to enable the QSPI system clock\n");
1424-
goto disable_pclk;
1425-
}
14261413
} else if (aq->caps->has_gclk) {
14271414
/* Get the QSPI generic clock */
14281415
aq->gclk = devm_clk_get(&pdev->dev, "gclk");
14291416
if (IS_ERR(aq->gclk)) {
14301417
dev_err(&pdev->dev, "missing Generic clock\n");
14311418
err = PTR_ERR(aq->gclk);
1432-
goto disable_pclk;
1419+
return err;
14331420
}
14341421
}
14351422

14361423
if (aq->caps->has_dma) {
14371424
err = atmel_qspi_dma_init(ctrl);
14381425
if (err == -EPROBE_DEFER)
1439-
goto disable_qspick;
1426+
return err;
14401427
}
14411428

14421429
/* Request the IRQ */
@@ -1476,10 +1463,6 @@ static int atmel_qspi_probe(struct platform_device *pdev)
14761463
dma_release:
14771464
if (aq->caps->has_dma)
14781465
atmel_qspi_dma_release(aq);
1479-
disable_qspick:
1480-
clk_disable_unprepare(aq->qspick);
1481-
disable_pclk:
1482-
clk_disable_unprepare(aq->pclk);
14831466

14841467
return err;
14851468
}
@@ -1518,7 +1501,6 @@ static int atmel_qspi_sama7g5_suspend(struct atmel_qspi *aq)
15181501
if (ret)
15191502
return ret;
15201503

1521-
clk_disable_unprepare(aq->pclk);
15221504
return 0;
15231505
}
15241506

@@ -1543,8 +1525,6 @@ static void atmel_qspi_remove(struct platform_device *pdev)
15431525
}
15441526

15451527
atmel_qspi_write(QSPI_CR_QSPIDIS, aq, QSPI_CR);
1546-
clk_disable(aq->qspick);
1547-
clk_disable(aq->pclk);
15481528
} else {
15491529
/*
15501530
* atmel_qspi_runtime_{suspend,resume} just disable and enable
@@ -1554,9 +1534,6 @@ static void atmel_qspi_remove(struct platform_device *pdev)
15541534
dev_warn(&pdev->dev, "Failed to resume device on remove\n");
15551535
}
15561536

1557-
clk_unprepare(aq->qspick);
1558-
clk_unprepare(aq->pclk);
1559-
15601537
pm_runtime_disable(&pdev->dev);
15611538
pm_runtime_dont_use_autosuspend(&pdev->dev);
15621539
pm_runtime_put_noidle(&pdev->dev);
@@ -1572,8 +1549,11 @@ static int __maybe_unused atmel_qspi_suspend(struct device *dev)
15721549
if (ret < 0)
15731550
return ret;
15741551

1575-
if (aq->caps->has_gclk)
1576-
return atmel_qspi_sama7g5_suspend(aq);
1552+
if (aq->caps->has_gclk) {
1553+
ret = atmel_qspi_sama7g5_suspend(aq);
1554+
clk_disable_unprepare(aq->pclk);
1555+
return ret;
1556+
}
15771557

15781558
atmel_qspi_write(QSPI_CR_QSPIDIS, aq, QSPI_CR);
15791559

0 commit comments

Comments
 (0)