All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Wahren <stefan.wahren@i2se.com>
To: Florian Fainelli <f.fainelli@gmail.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, Sean Wang <sean.wang@mediatek.com>,
	Martin Kaiser <martin@kaiser.cx>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Scott Branden <sbranden@broadcom.com>,
	Ray Jui <rjui@broadcom.com>, Matt Mackall <mpm@selenic.com>,
	Russell King <rmk+kernel@armlinux.org.uk>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	linux-kernel@vger.kernel.org, Eric Anholt <eric@anholt.net>,
	Harald Freudenberger <freude@linux.vnet.ibm.com>,
	Rob Herring <robh+dt@kernel.org>,
	bcm-kernel-feedback-list@broadcom.com,
	linux-crypto@vger.kernel.org,
	PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>,
	Steffen Trumtrar <s.trumtrar@pengutronix.de>,
	linux-arm-kernel@lists.infradead.org,
	linux-rpi-kernel@lists.infradead.org
Subject: Re: [PATCH v2 07/12] hwrng: bcm2835-rng: Manage an optional clock
Date: Wed, 8 Nov 2017 20:19:57 +0100 (CET)	[thread overview]
Message-ID: <1065382783.63901.1510168797132@email.1und1.de> (raw)
In-Reply-To: <20171108004449.32730-8-f.fainelli@gmail.com>

Hi Florian,

> Florian Fainelli <f.fainelli@gmail.com> hat am 8. November 2017 um 01:44 geschrieben:
> 
> 
> One of the last steps before bcm63xx-rng can be eliminated is to manage
> a clock during hwrng::init and hwrng::cleanup, so fetch it in the probe
> function, and manage it during these two steps when valid.
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
>  drivers/char/hw_random/bcm2835-rng.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
> index ed20e0b6b7ae..99b56fd5482c 100644
> --- a/drivers/char/hw_random/bcm2835-rng.c
> +++ b/drivers/char/hw_random/bcm2835-rng.c
> @@ -15,6 +15,7 @@
>  #include <linux/of_platform.h>
>  #include <linux/platform_device.h>
>  #include <linux/printk.h>
> +#include <linux/clk.h>
>  
>  #define RNG_CTRL	0x0
>  #define RNG_STATUS	0x4
> @@ -33,6 +34,7 @@ struct bcm2835_rng_priv {
>  	struct hwrng rng;
>  	void __iomem *base;
>  	bool mask_interrupts;
> +	struct clk *clk;
>  };
>  
>  static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng)
> @@ -66,8 +68,15 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
>  static int bcm2835_rng_init(struct hwrng *rng)
>  {
>  	struct bcm2835_rng_priv *priv = to_rng_priv(rng);
> +	int ret = 0;
>  	u32 val;
>  
> +	if (!IS_ERR(priv->clk)) {
> +		ret = clk_prepare_enable(priv->clk);
> +		if (ret)
> +			return ret;
> +	}
> +

the clocks are optional to the binding, but not for the proper function of all RNG. So shouldn't we catch the case that we cannot get the clock during probe, but the clock is required for a specific SoC?

>  	if (priv->mask_interrupts) {
>  		/* mask the interrupt */
>  		val = readl(priv->base + RNG_INT_MASK);
> @@ -79,7 +88,7 @@ static int bcm2835_rng_init(struct hwrng *rng)
>  	__raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS);
>  	__raw_writel(RNG_RBGEN, priv->base + RNG_CTRL);
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static void bcm2835_rng_cleanup(struct hwrng *rng)
> @@ -88,6 +97,9 @@ static void bcm2835_rng_cleanup(struct hwrng *rng)
>  
>  	/* disable rng hardware */
>  	__raw_writel(0, priv->base + RNG_CTRL);
> +
> +	if (!IS_ERR(priv->clk))
> +		clk_disable_unprepare(priv->clk);
>  }
>  
>  struct bcm2835_rng_of_data {
> @@ -130,6 +142,9 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
>  		return PTR_ERR(priv->base);
>  	}
>  
> +	/* Clock is optional on most platforms */
> +	priv->clk = devm_clk_get(dev, NULL);
> +

At least EPROBE_DEFER should be handled here:

if (IS_ERR(priv->clk) && PTR_ERR(priv->clk) == -EPROBE_DEFER)
	return -EPROBE_DEFER;

Regards
Stefan

WARNING: multiple messages have this Message-ID (diff)
From: Stefan Wahren <stefan.wahren@i2se.com>
To: Florian Fainelli <f.fainelli@gmail.com>
Cc: Krzysztof Kozlowski <krzk@kernel.org>,
	Ray Jui <rjui@broadcom.com>, Eric Anholt <eric@anholt.net>,
	Rob Herring <robh+dt@kernel.org>,
	Steffen Trumtrar <s.trumtrar@pengutronix.de>,
	Harald Freudenberger <freude@linux.vnet.ibm.com>,
	Russell King <rmk+kernel@armlinux.org.uk>,
	linux-arm-kernel@lists.infradead.org,
	PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>,
	Scott Branden <sbranden@broadcom.com>,
	linux-crypto@vger.kernel.org,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Martin Kaiser <martin@kaiser.cx>, Matt Mackall <mpm@selenic.com>,
	bcm-kernel-feedback-list@broadcom.com,
	Mark Rutland <mark.rutland@arm.com>,
	linux-rpi-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Sean Wang <sean.wang@mediatek.com>,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v2 07/12] hwrng: bcm2835-rng: Manage an optional clock
Date: Wed, 8 Nov 2017 20:19:57 +0100 (CET)	[thread overview]
Message-ID: <1065382783.63901.1510168797132@email.1und1.de> (raw)
In-Reply-To: <20171108004449.32730-8-f.fainelli@gmail.com>

Hi Florian,

> Florian Fainelli <f.fainelli@gmail.com> hat am 8. November 2017 um 01:44 geschrieben:
> 
> 
> One of the last steps before bcm63xx-rng can be eliminated is to manage
> a clock during hwrng::init and hwrng::cleanup, so fetch it in the probe
> function, and manage it during these two steps when valid.
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
>  drivers/char/hw_random/bcm2835-rng.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
> index ed20e0b6b7ae..99b56fd5482c 100644
> --- a/drivers/char/hw_random/bcm2835-rng.c
> +++ b/drivers/char/hw_random/bcm2835-rng.c
> @@ -15,6 +15,7 @@
>  #include <linux/of_platform.h>
>  #include <linux/platform_device.h>
>  #include <linux/printk.h>
> +#include <linux/clk.h>
>  
>  #define RNG_CTRL	0x0
>  #define RNG_STATUS	0x4
> @@ -33,6 +34,7 @@ struct bcm2835_rng_priv {
>  	struct hwrng rng;
>  	void __iomem *base;
>  	bool mask_interrupts;
> +	struct clk *clk;
>  };
>  
>  static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng)
> @@ -66,8 +68,15 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
>  static int bcm2835_rng_init(struct hwrng *rng)
>  {
>  	struct bcm2835_rng_priv *priv = to_rng_priv(rng);
> +	int ret = 0;
>  	u32 val;
>  
> +	if (!IS_ERR(priv->clk)) {
> +		ret = clk_prepare_enable(priv->clk);
> +		if (ret)
> +			return ret;
> +	}
> +

the clocks are optional to the binding, but not for the proper function of all RNG. So shouldn't we catch the case that we cannot get the clock during probe, but the clock is required for a specific SoC?

>  	if (priv->mask_interrupts) {
>  		/* mask the interrupt */
>  		val = readl(priv->base + RNG_INT_MASK);
> @@ -79,7 +88,7 @@ static int bcm2835_rng_init(struct hwrng *rng)
>  	__raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS);
>  	__raw_writel(RNG_RBGEN, priv->base + RNG_CTRL);
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static void bcm2835_rng_cleanup(struct hwrng *rng)
> @@ -88,6 +97,9 @@ static void bcm2835_rng_cleanup(struct hwrng *rng)
>  
>  	/* disable rng hardware */
>  	__raw_writel(0, priv->base + RNG_CTRL);
> +
> +	if (!IS_ERR(priv->clk))
> +		clk_disable_unprepare(priv->clk);
>  }
>  
>  struct bcm2835_rng_of_data {
> @@ -130,6 +142,9 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
>  		return PTR_ERR(priv->base);
>  	}
>  
> +	/* Clock is optional on most platforms */
> +	priv->clk = devm_clk_get(dev, NULL);
> +

At least EPROBE_DEFER should be handled here:

if (IS_ERR(priv->clk) && PTR_ERR(priv->clk) == -EPROBE_DEFER)
	return -EPROBE_DEFER;

Regards
Stefan

WARNING: multiple messages have this Message-ID (diff)
From: stefan.wahren@i2se.com (Stefan Wahren)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 07/12] hwrng: bcm2835-rng: Manage an optional clock
Date: Wed, 8 Nov 2017 20:19:57 +0100 (CET)	[thread overview]
Message-ID: <1065382783.63901.1510168797132@email.1und1.de> (raw)
In-Reply-To: <20171108004449.32730-8-f.fainelli@gmail.com>

Hi Florian,

> Florian Fainelli <f.fainelli@gmail.com> hat am 8. November 2017 um 01:44 geschrieben:
> 
> 
> One of the last steps before bcm63xx-rng can be eliminated is to manage
> a clock during hwrng::init and hwrng::cleanup, so fetch it in the probe
> function, and manage it during these two steps when valid.
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
>  drivers/char/hw_random/bcm2835-rng.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
> index ed20e0b6b7ae..99b56fd5482c 100644
> --- a/drivers/char/hw_random/bcm2835-rng.c
> +++ b/drivers/char/hw_random/bcm2835-rng.c
> @@ -15,6 +15,7 @@
>  #include <linux/of_platform.h>
>  #include <linux/platform_device.h>
>  #include <linux/printk.h>
> +#include <linux/clk.h>
>  
>  #define RNG_CTRL	0x0
>  #define RNG_STATUS	0x4
> @@ -33,6 +34,7 @@ struct bcm2835_rng_priv {
>  	struct hwrng rng;
>  	void __iomem *base;
>  	bool mask_interrupts;
> +	struct clk *clk;
>  };
>  
>  static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng)
> @@ -66,8 +68,15 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
>  static int bcm2835_rng_init(struct hwrng *rng)
>  {
>  	struct bcm2835_rng_priv *priv = to_rng_priv(rng);
> +	int ret = 0;
>  	u32 val;
>  
> +	if (!IS_ERR(priv->clk)) {
> +		ret = clk_prepare_enable(priv->clk);
> +		if (ret)
> +			return ret;
> +	}
> +

the clocks are optional to the binding, but not for the proper function of all RNG. So shouldn't we catch the case that we cannot get the clock during probe, but the clock is required for a specific SoC?

>  	if (priv->mask_interrupts) {
>  		/* mask the interrupt */
>  		val = readl(priv->base + RNG_INT_MASK);
> @@ -79,7 +88,7 @@ static int bcm2835_rng_init(struct hwrng *rng)
>  	__raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS);
>  	__raw_writel(RNG_RBGEN, priv->base + RNG_CTRL);
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static void bcm2835_rng_cleanup(struct hwrng *rng)
> @@ -88,6 +97,9 @@ static void bcm2835_rng_cleanup(struct hwrng *rng)
>  
>  	/* disable rng hardware */
>  	__raw_writel(0, priv->base + RNG_CTRL);
> +
> +	if (!IS_ERR(priv->clk))
> +		clk_disable_unprepare(priv->clk);
>  }
>  
>  struct bcm2835_rng_of_data {
> @@ -130,6 +142,9 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
>  		return PTR_ERR(priv->base);
>  	}
>  
> +	/* Clock is optional on most platforms */
> +	priv->clk = devm_clk_get(dev, NULL);
> +

At least EPROBE_DEFER should be handled here:

if (IS_ERR(priv->clk) && PTR_ERR(priv->clk) == -EPROBE_DEFER)
	return -EPROBE_DEFER;

Regards
Stefan

  parent reply	other threads:[~2017-11-08 19:19 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-08  0:44 [PATCH v2 00/12] bcm63xx-rng conversion to bcm2835-rng Florian Fainelli
2017-11-08  0:44 ` Florian Fainelli
2017-11-08  0:44 ` Florian Fainelli
2017-11-08  0:44 ` Florian Fainelli
     [not found] ` <20171108004449.32730-1-f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-11-08  0:44   ` [PATCH v2 01/12] hwrng: bcm2835-rng: Obtain base register via resource Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-29  6:30     ` [v2,01/12] hwrng: bcm2835 - " Herbert Xu
2017-11-29  6:30       ` Herbert Xu
2017-11-29  6:30       ` Herbert Xu
2017-11-29  6:30       ` Herbert Xu
2017-11-29 17:38       ` Florian Fainelli
2017-11-29 17:38         ` Florian Fainelli
2017-11-29 17:38         ` Florian Fainelli
2017-11-29 17:38         ` Florian Fainelli
2017-11-30  7:14         ` Herbert Xu
2017-11-30  7:14           ` Herbert Xu
2017-11-30  7:14           ` Herbert Xu
2017-11-30  7:14           ` Herbert Xu
2017-11-08  0:44   ` [PATCH v2 06/12] hwrng: bcm2835-rng: Rework interrupt masking Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08 18:26     ` Eric Anholt
2017-11-08 18:26       ` Eric Anholt
2017-11-08 18:26       ` Eric Anholt
2017-11-08 18:26       ` Eric Anholt
2017-11-08 18:46     ` Stefan Wahren
2017-11-08 18:46       ` Stefan Wahren
2017-11-08 18:46       ` Stefan Wahren
     [not found]       ` <1086045224.63286.1510166797078-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
2017-11-08 20:41         ` Eric Anholt
2017-11-08 20:41           ` Eric Anholt
2017-11-08 20:41           ` Eric Anholt
2017-11-08  0:44   ` [PATCH v2 08/12] hwrng: bcm2835-rng: Abstract I/O accessors Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
     [not found]     ` <20171108004449.32730-9-f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-11-08 18:33       ` Eric Anholt
2017-11-08 18:33         ` Eric Anholt
2017-11-08 18:33         ` Eric Anholt
2017-11-08 18:33         ` Eric Anholt
2017-11-13  4:54     ` [v2,08/12] " Philippe Mathieu-Daudé
2017-11-08  0:44   ` [PATCH v2 09/12] hwrng: bcm2835-rng: Add Broadcom MIPS " Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08  0:44   ` [PATCH v2 12/12] hwrng: bcm63xx-rng: Remove since bcm2835-rng takes over Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08  0:44     ` Florian Fainelli
2017-11-08 18:36     ` Eric Anholt
2017-11-08 18:36       ` Eric Anholt
2017-11-08 18:36       ` Eric Anholt
2017-11-08 18:36       ` Eric Anholt
2017-11-08  0:44 ` [PATCH v2 02/12] hwrng: bcm2835-rng: Define a driver private context Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08 18:22   ` Eric Anholt
2017-11-08 18:22     ` Eric Anholt
2017-11-08 18:22     ` Eric Anholt
2017-11-08 18:22     ` Eric Anholt
2017-11-08  0:44 ` [PATCH v2 03/12] hwrng: bcm2835-rng: Move enabling to hwrng::init Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44 ` [PATCH v2 04/12] hwrng: bcm2835-rng: Implementation cleanup callback Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44 ` [PATCH v2 05/12] hwrng: bcm2835-rng: Use device managed helpers Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08 18:24   ` Eric Anholt
2017-11-08 18:24     ` Eric Anholt
2017-11-08 18:24     ` Eric Anholt
2017-11-08 18:24     ` Eric Anholt
2017-11-08  0:44 ` [PATCH v2 07/12] hwrng: bcm2835-rng: Manage an optional clock Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08 18:31   ` Eric Anholt
2017-11-08 18:31     ` Eric Anholt
2017-11-08 18:31     ` Eric Anholt
2017-11-08 18:31     ` Eric Anholt
2017-11-08 19:19   ` Stefan Wahren [this message]
2017-11-08 19:19     ` Stefan Wahren
2017-11-08 19:19     ` Stefan Wahren
2017-11-08 19:23     ` Russell King - ARM Linux
2017-11-08 19:23       ` Russell King - ARM Linux
2017-11-08  0:44 ` [PATCH v2 10/12] dt-bindings: rng: Incorporate brcm,bcm6368.txt binding Florian Fainelli
2017-11-08  0:44   ` [PATCH v2 10/12] dt-bindings: rng: Incorporate brcm, bcm6368.txt binding Florian Fainelli
2017-11-08  0:44   ` [PATCH v2 10/12] dt-bindings: rng: Incorporate brcm,bcm6368.txt binding Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44 ` [PATCH v2 11/12] hwrng: bcm2835-rng: Enable BCM2835 RNG to work on BCM63xx platforms Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli
2017-11-08  0:44   ` Florian Fainelli

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=1065382783.63901.1510168797132@email.1und1.de \
    --to=stefan.wahren@i2se.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=devicetree@vger.kernel.org \
    --cc=eric@anholt.net \
    --cc=f.fainelli@gmail.com \
    --cc=freude@linux.vnet.ibm.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=krzk@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=martin@kaiser.cx \
    --cc=mpm@selenic.com \
    --cc=prasannatsmkumar@gmail.com \
    --cc=rjui@broadcom.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=robh+dt@kernel.org \
    --cc=s.trumtrar@pengutronix.de \
    --cc=sbranden@broadcom.com \
    --cc=sean.wang@mediatek.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.