Linux-Crypto Archive on lore.kernel.org
 help / color / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: Matt Mackall <mpm@selenic.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org
Cc: linux-crypto@vger.kernel.org,
	"Aaro Koskinen" <aaro.koskinen@iki.fi>,
	"Adam Ford" <aford173@gmail.com>,
	"Pali Rohár" <pali.rohar@gmail.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Tero Kristo" <t-kristo@ti.com>,
	devicetree@vger.kernel.org
Subject: [PATCH 5/6] hwrng: omap3-rom - Update to use standard driver data
Date: Fri, 13 Sep 2019 15:09:21 -0700
Message-ID: <20190913220922.29501-6-tony@atomide.com> (raw)
In-Reply-To: <20190913220922.29501-1-tony@atomide.com>

Let's update omap3-rom-rng to use standard driver data to make it easier
to add runtime PM support in the following patch. Just use it for the
clock for now, but still keep also old rng_clk still around. We will
remove delayed work and rng_clk with runtime PM in the next patch.

Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/char/hw_random/omap3-rom-rng.c | 51 +++++++++++++++++---------
 1 file changed, 33 insertions(+), 18 deletions(-)

diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
--- a/drivers/char/hw_random/omap3-rom-rng.c
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -31,6 +31,12 @@
 /* param1: ptr, param2: count, param3: flag */
 static u32 (*omap3_rom_rng_call)(u32, u32, u32);
 
+struct omap_rom_rng {
+	struct clk *clk;
+	struct device *dev;
+	struct hwrng ops;
+};
+
 static struct delayed_work idle_work;
 static int rng_idle;
 static struct clk *rng_clk;
@@ -86,60 +92,69 @@ static int omap3_rom_rng_read(struct hwrng *rng, void *data, size_t max, bool w)
 	return 4;
 }
 
-static struct hwrng omap3_rom_rng_ops = {
-	.name		= "omap3-rom",
-	.quality	= 900,
-};
-
 static int omap3_rom_rng_probe(struct platform_device *pdev)
 {
+	struct omap_rom_rng *ddata;
 	int ret = 0;
 
-	omap3_rom_rng_ops.read = of_device_get_match_data(&pdev->dev);
-	if (!omap3_rom_rng_ops.read) {
+	ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
+	if (!ddata)
+		return -ENOMEM;
+
+	ddata->dev = &pdev->dev;
+	ddata->ops.priv = (unsigned long)ddata;
+	ddata->ops.name = "omap3-rom";
+	ddata->ops.read = of_device_get_match_data(&pdev->dev);
+	ddata->ops.quality = 900;
+	if (!ddata->ops.read) {
 		dev_err(&pdev->dev, "missing rom code handler\n");
 
 		return -ENODEV;
 	}
+	dev_set_drvdata(ddata->dev, ddata);
 
 	omap3_rom_rng_call = pdev->dev.platform_data;
 	if (!omap3_rom_rng_call) {
-		pr_err("omap3_rom_rng_call is NULL\n");
+		dev_err(ddata->dev, "rom_rng_call is NULL\n");
 		return -EINVAL;
 	}
 
 	INIT_DELAYED_WORK(&idle_work, omap3_rom_rng_idle);
-	rng_clk = devm_clk_get(&pdev->dev, "ick");
-	if (IS_ERR(rng_clk)) {
-		pr_err("unable to get RNG clock\n");
-		return PTR_ERR(rng_clk);
+	ddata->clk = devm_clk_get(ddata->dev, "ick");
+	if (IS_ERR(ddata->clk)) {
+		dev_err(ddata->dev, "unable to get RNG clock\n");
+		return PTR_ERR(ddata->clk);
 	}
+	rng_clk = ddata->clk;
 
-	ret = clk_prepare(rng_clk);
+	ret = clk_prepare(ddata->clk);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "clk_prepare failed: %i\n", ret);
 		return ret;
 	}
 
 	/* Leave the RNG in reset state. */
-	ret = clk_enable(rng_clk);
+	ret = clk_enable(ddata->clk);
 	if (ret)
 		goto err_unprepare;
 	omap3_rom_rng_idle(0);
 
-	return hwrng_register(&omap3_rom_rng_ops);
+	return hwrng_register(&ddata->ops);
 
 err_unprepare:
-	clk_unprepare(rng_clk);
+	clk_unprepare(ddata->clk);
 
 	return ret;
 }
 
 static int omap3_rom_rng_remove(struct platform_device *pdev)
 {
+	struct omap_rom_rng *ddata;
+
+	ddata = dev_get_drvdata(&pdev->dev);
 	cancel_delayed_work_sync(&idle_work);
-	hwrng_unregister(&omap3_rom_rng_ops);
-	clk_unprepare(rng_clk);
+	hwrng_unregister(&ddata->ops);
+	clk_unprepare(ddata->clk);
 
 	return 0;
 }
-- 
2.23.0

  parent reply index

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-13 22:09 [PATCH 0/6] Non-urgent fixes and improvments for omap3-rom-rng Tony Lindgren
2019-09-13 22:09 ` [PATCH 1/6] ARM: OMAP2+: Check omap3-rom-rng for GP device instead of HS device Tony Lindgren
2019-09-13 22:09 ` [PATCH 2/6] hwrng: omap3-rom - Fix missing clock by probing with device tree Tony Lindgren
2019-09-13 22:09 ` [PATCH 3/6] hwrng: omap3-rom - Call clk_prepare() on init and exit only Tony Lindgren
2019-09-14 12:54   ` Sebastian Reichel
2019-09-14 17:57     ` Tony Lindgren
2019-09-13 22:09 ` [PATCH 4/6] hwrng: omap3-rom - Initialize default quality to get data Tony Lindgren
2019-09-13 22:09 ` Tony Lindgren [this message]
2019-09-13 22:09 ` [PATCH 6/6] hwrng: omap3-rom - Use runtime PM instead of custom functions Tony Lindgren
2019-09-14 13:05 ` [PATCH 0/6] Non-urgent fixes and improvments for omap3-rom-rng Sebastian Reichel
2019-09-14 17:59   ` Tony Lindgren

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190913220922.29501-6-tony@atomide.com \
    --to=tony@atomide.com \
    --cc=aaro.koskinen@iki.fi \
    --cc=aford173@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=mpm@selenic.com \
    --cc=pali.rohar@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=t-kristo@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Crypto Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-crypto/0 linux-crypto/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-crypto linux-crypto/ https://lore.kernel.org/linux-crypto \
		linux-crypto@vger.kernel.org
	public-inbox-index linux-crypto

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-crypto


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git