Skip to content

Commit 6a2277a

Browse files
committed
mtd: rawnand: renesas: Use runtime PM instead of the raw clock API
This NAND controller is part of a well defined power domain handled by the runtime PM core. Let's keep the harmony with the other RZ/N1 drivers and exclusively use the runtime PM API to enable/disable the clocks. We still need to retrieve the external clock rate in order to derive the NAND timings, but that is not a big deal, we can still do that in the probe and just save this value to reuse it later. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://lore.kernel.org/linux-mtd/20220513104957.257721-3-miquel.raynal@bootlin.com
1 parent 431cbce commit 6a2277a

1 file changed

Lines changed: 23 additions & 28 deletions

File tree

drivers/mtd/nand/raw/renesas-nand-controller.c

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/mtd/rawnand.h>
1717
#include <linux/of.h>
1818
#include <linux/platform_device.h>
19+
#include <linux/pm_runtime.h>
1920
#include <linux/slab.h>
2021

2122
#define COMMAND_REG 0x00
@@ -216,8 +217,7 @@ struct rnandc {
216217
struct nand_controller controller;
217218
struct device *dev;
218219
void __iomem *regs;
219-
struct clk *hclk;
220-
struct clk *eclk;
220+
unsigned long ext_clk_rate;
221221
unsigned long assigned_cs;
222222
struct list_head chips;
223223
struct nand_chip *selected_chip;
@@ -891,7 +891,7 @@ static int rnandc_setup_interface(struct nand_chip *chip, int chipnr,
891891
{
892892
struct rnand_chip *rnand = to_rnand(chip);
893893
struct rnandc *rnandc = to_rnandc(chip->controller);
894-
unsigned int period_ns = 1000000000 / clk_get_rate(rnandc->eclk);
894+
unsigned int period_ns = 1000000000 / rnandc->ext_clk_rate;
895895
const struct nand_sdr_timings *sdr;
896896
unsigned int cyc, cle, ale, bef_dly, ca_to_data;
897897

@@ -1319,6 +1319,7 @@ static int rnandc_chips_init(struct rnandc *rnandc)
13191319
static int rnandc_probe(struct platform_device *pdev)
13201320
{
13211321
struct rnandc *rnandc;
1322+
struct clk *eclk;
13221323
int irq, ret;
13231324

13241325
rnandc = devm_kzalloc(&pdev->dev, sizeof(*rnandc), GFP_KERNEL);
@@ -1335,57 +1336,52 @@ static int rnandc_probe(struct platform_device *pdev)
13351336
if (IS_ERR(rnandc->regs))
13361337
return PTR_ERR(rnandc->regs);
13371338

1338-
/* APB clock */
1339-
rnandc->hclk = devm_clk_get(&pdev->dev, "hclk");
1340-
if (IS_ERR(rnandc->hclk))
1341-
return PTR_ERR(rnandc->hclk);
1342-
1343-
/* External NAND bus clock */
1344-
rnandc->eclk = devm_clk_get(&pdev->dev, "eclk");
1345-
if (IS_ERR(rnandc->eclk))
1346-
return PTR_ERR(rnandc->eclk);
1347-
1348-
ret = clk_prepare_enable(rnandc->hclk);
1349-
if (ret)
1339+
devm_pm_runtime_enable(&pdev->dev);
1340+
ret = pm_runtime_resume_and_get(&pdev->dev);
1341+
if (ret < 0)
13501342
return ret;
13511343

1352-
ret = clk_prepare_enable(rnandc->eclk);
1353-
if (ret)
1354-
goto disable_hclk;
1344+
/* The external NAND bus clock rate is needed for computing timings */
1345+
eclk = clk_get(&pdev->dev, "eclk");
1346+
if (IS_ERR(eclk)) {
1347+
ret = PTR_ERR(eclk);
1348+
goto dis_runtime_pm;
1349+
}
1350+
1351+
rnandc->ext_clk_rate = clk_get_rate(eclk);
1352+
clk_put(eclk);
13551353

13561354
rnandc_dis_interrupts(rnandc);
13571355
irq = platform_get_irq_optional(pdev, 0);
13581356
if (irq == -EPROBE_DEFER) {
13591357
ret = irq;
1360-
goto disable_eclk;
1358+
goto dis_runtime_pm;
13611359
} else if (irq < 0) {
13621360
dev_info(&pdev->dev, "No IRQ found, fallback to polling\n");
13631361
rnandc->use_polling = true;
13641362
} else {
13651363
ret = devm_request_irq(&pdev->dev, irq, rnandc_irq_handler, 0,
13661364
"renesas-nand-controller", rnandc);
13671365
if (ret < 0)
1368-
goto disable_eclk;
1366+
goto dis_runtime_pm;
13691367
}
13701368

13711369
ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
13721370
if (ret)
1373-
goto disable_eclk;
1371+
goto dis_runtime_pm;
13741372

13751373
rnandc_clear_fifo(rnandc);
13761374

13771375
platform_set_drvdata(pdev, rnandc);
13781376

13791377
ret = rnandc_chips_init(rnandc);
13801378
if (ret)
1381-
goto disable_eclk;
1379+
goto dis_runtime_pm;
13821380

13831381
return 0;
13841382

1385-
disable_eclk:
1386-
clk_disable_unprepare(rnandc->eclk);
1387-
disable_hclk:
1388-
clk_disable_unprepare(rnandc->hclk);
1383+
dis_runtime_pm:
1384+
pm_runtime_put(&pdev->dev);
13891385

13901386
return ret;
13911387
}
@@ -1396,8 +1392,7 @@ static int rnandc_remove(struct platform_device *pdev)
13961392

13971393
rnandc_chips_cleanup(rnandc);
13981394

1399-
clk_disable_unprepare(rnandc->eclk);
1400-
clk_disable_unprepare(rnandc->hclk);
1395+
pm_runtime_put(&pdev->dev);
14011396

14021397
return 0;
14031398
}

0 commit comments

Comments
 (0)