mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
From: hkallweit1@gmail.com (Heiner Kallweit)
To: linus-amlogic@lists.infradead.org
Subject: [PATCH v3 4/4] hwrng: meson: add clock handling to driver
Date: Wed, 22 Feb 2017 08:02:31 +0100	[thread overview]
Message-ID: <a561e156-f735-7a26-120b-e6c1ba13affd@gmail.com> (raw)
In-Reply-To: <4e2d12e5-f75b-3ac6-a3f7-18e8a8b7283b@gmail.com>

Add handling of RNG0 clock to the driver.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
v2:
- consider that clock is optional
- use managed call to clk_disable_unprepare to ensure that
  cleaning up is done in the right order if driver is removed
v3:
- no changes
---
 drivers/char/hw_random/meson-rng.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/char/hw_random/meson-rng.c b/drivers/char/hw_random/meson-rng.c
index 119d6984..2e23be80 100644
--- a/drivers/char/hw_random/meson-rng.c
+++ b/drivers/char/hw_random/meson-rng.c
@@ -62,6 +62,7 @@
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/of.h>
+#include <linux/clk.h>
 
 #define RNG_DATA 0x00
 
@@ -69,6 +70,7 @@ struct meson_rng_data {
 	void __iomem *base;
 	struct platform_device *pdev;
 	struct hwrng rng;
+	struct clk *core_clk;
 };
 
 static int meson_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
@@ -81,11 +83,17 @@ static int meson_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
 	return sizeof(u32);
 }
 
+static void meson_rng_clk_disable(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int meson_rng_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct meson_rng_data *data;
 	struct resource *res;
+	int ret;
 
 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -98,6 +106,20 @@ static int meson_rng_probe(struct platform_device *pdev)
 	if (IS_ERR(data->base))
 		return PTR_ERR(data->base);
 
+	data->core_clk = devm_clk_get(dev, "core");
+	if (IS_ERR(data->core_clk))
+		data->core_clk = NULL;
+
+	if (data->core_clk) {
+		ret = clk_prepare_enable(data->core_clk);
+		if (ret)
+			return ret;
+		ret = devm_add_action_or_reset(dev, meson_rng_clk_disable,
+					       data->core_clk);
+		if (ret)
+			return ret;
+	}
+
 	data->rng.name = pdev->name;
 	data->rng.read = meson_rng_read;
 
-- 
2.11.1

  parent reply	other threads:[~2017-02-22  7:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-22  6:55 [PATCH v3 1/3] clk: meson-gxbb: expose clock CLKID_RNG0 Heiner Kallweit
2017-02-22  6:59 ` [PATCH v3 2/4] ARM64: dts: meson-gx: add clock to DT binding documentation for hwrng Heiner Kallweit
2017-02-27 22:34   ` Rob Herring
2017-02-22  7:00 ` [PATCH v3 3/4] ARM64: dts: meson-gx: add clock CLKID_RNG0 to hwrng node Heiner Kallweit
2017-02-22  7:02 ` Heiner Kallweit [this message]
2017-02-27 13:28 ` [PATCH v3 1/3] clk: meson-gxbb: expose clock CLKID_RNG0 Neil Armstrong
2017-03-16 10:07 ` Herbert Xu
2017-03-16 18:24   ` Kevin Hilman
2017-03-17  8:30     ` Herbert Xu
2017-03-17 23:05       ` Kevin Hilman
2017-03-22 15:24       ` Kevin Hilman
2017-03-23  1:43         ` Michael Turquette
2017-03-23  7:56         ` Herbert Xu
2017-03-28 22:07           ` Michael Turquette

Reply instructions:

You may reply publicly 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=a561e156-f735-7a26-120b-e6c1ba13affd@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=linus-amlogic@lists.infradead.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®