Skip to content

Commit

Permalink
hwrng: imx-rngc - use devm_clk_get_enabled
Browse files Browse the repository at this point in the history
[ Upstream commit 6a2bc44 ]

Use the new devm_clk_get_enabled function to get our clock.

We don't have to disable and unprepare the clock ourselves any more in
error paths and in the remove function.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Stable-dep-of: 10a2199 ("hwrng: imx-rngc - Moving IRQ handler registering after imx_rngc_irq_mask_clear()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
martin-kaiser authored and gregkh committed Oct 21, 2022
1 parent 28b4235 commit 9061fae
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions drivers/char/hw_random/imx-rngc.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static int imx_rngc_probe(struct platform_device *pdev)
if (IS_ERR(rngc->base))
return PTR_ERR(rngc->base);

rngc->clk = devm_clk_get(&pdev->dev, NULL);
rngc->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(rngc->clk)) {
dev_err(&pdev->dev, "Can not get rng_clk\n");
return PTR_ERR(rngc->clk);
Expand All @@ -255,26 +255,20 @@ static int imx_rngc_probe(struct platform_device *pdev)
if (irq < 0)
return irq;

ret = clk_prepare_enable(rngc->clk);
if (ret)
return ret;

ver_id = readl(rngc->base + RNGC_VER_ID);
rng_type = ver_id >> RNGC_TYPE_SHIFT;
/*
* This driver supports only RNGC and RNGB. (There's a different
* driver for RNGA.)
*/
if (rng_type != RNGC_TYPE_RNGC && rng_type != RNGC_TYPE_RNGB) {
ret = -ENODEV;
goto err;
}
if (rng_type != RNGC_TYPE_RNGC && rng_type != RNGC_TYPE_RNGB)
return -ENODEV;

ret = devm_request_irq(&pdev->dev,
irq, imx_rngc_irq, 0, pdev->name, (void *)rngc);
if (ret) {
dev_err(rngc->dev, "Can't get interrupt working.\n");
goto err;
return ret;
}

init_completion(&rngc->rng_op_done);
Expand All @@ -294,26 +288,21 @@ static int imx_rngc_probe(struct platform_device *pdev)
ret = imx_rngc_self_test(rngc);
if (ret) {
dev_err(rngc->dev, "self test failed\n");
goto err;
return ret;
}
}

ret = hwrng_register(&rngc->rng);
if (ret) {
dev_err(&pdev->dev, "hwrng registration failed\n");
goto err;
return ret;
}

dev_info(&pdev->dev,
"Freescale RNG%c registered (HW revision %d.%02d)\n",
rng_type == RNGC_TYPE_RNGB ? 'B' : 'C',
(ver_id >> RNGC_VER_MAJ_SHIFT) & 0xff, ver_id & 0xff);
return 0;

err:
clk_disable_unprepare(rngc->clk);

return ret;
}

static int __exit imx_rngc_remove(struct platform_device *pdev)
Expand All @@ -322,8 +311,6 @@ static int __exit imx_rngc_remove(struct platform_device *pdev)

hwrng_unregister(&rngc->rng);

clk_disable_unprepare(rngc->clk);

return 0;
}

Expand Down

0 comments on commit 9061fae

Please sign in to comment.