Skip to content

Commit

Permalink
hwrng: pic32 - use devm_clk_get_enabled
Browse files Browse the repository at this point in the history
[ Upstream commit 6755ad7 ]

Use devm_clk_get_enabled in the pic32 driver. Ensure that the clock is
enabled as long as the driver is registered with the hwrng core.

Fixes: 7ea3997 ("hwrng: pic32 - Use device-managed registration API")
Signed-off-by: Martin Kaiser <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
martin-kaiser authored and gregkh committed Sep 13, 2023
1 parent 9681618 commit 69dfa8c
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions drivers/char/hw_random/pic32-rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
struct pic32_rng {
void __iomem *base;
struct hwrng rng;
struct clk *clk;
};

/*
Expand Down Expand Up @@ -70,6 +69,7 @@ static int pic32_rng_read(struct hwrng *rng, void *buf, size_t max,
static int pic32_rng_probe(struct platform_device *pdev)
{
struct pic32_rng *priv;
struct clk *clk;
u32 v;
int ret;

Expand All @@ -81,13 +81,9 @@ static int pic32_rng_probe(struct platform_device *pdev)
if (IS_ERR(priv->base))
return PTR_ERR(priv->base);

priv->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(priv->clk))
return PTR_ERR(priv->clk);

ret = clk_prepare_enable(priv->clk);
if (ret)
return ret;
clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(clk))
return PTR_ERR(clk);

/* enable TRNG in enhanced mode */
v = TRNGEN | TRNGMOD;
Expand All @@ -98,23 +94,18 @@ static int pic32_rng_probe(struct platform_device *pdev)

ret = devm_hwrng_register(&pdev->dev, &priv->rng);
if (ret)
goto err_register;
return ret;

platform_set_drvdata(pdev, priv);

return 0;

err_register:
clk_disable_unprepare(priv->clk);
return ret;
}

static int pic32_rng_remove(struct platform_device *pdev)
{
struct pic32_rng *rng = platform_get_drvdata(pdev);

writel(0, rng->base + RNGCON);
clk_disable_unprepare(rng->clk);
return 0;
}

Expand Down

0 comments on commit 69dfa8c

Please sign in to comment.