All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
Cc: linux-crypto@vger.kernel.org, devicetree@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, mpm@selenic.com,
	herbert@gondor.apana.org.au, robh+dt@kernel.org,
	mark.rutland@arm.com, nicolas.ferre@microchip.com,
	ludovic.desroches@microchip.com, arnd@arndb.de,
	Tudor.Ambarus@microchip.com
Subject: Re: [PATCH 2/2] hwrng: atmel: add new platform support for sam9x60
Date: Fri, 25 Oct 2019 10:01:36 +0200	[thread overview]
Message-ID: <20191025080136.GA3125@piout.net> (raw)
In-Reply-To: <20191024170452.2145-2-codrin.ciubotariu@microchip.com>

On 24/10/2019 20:04:52+0300, Codrin Ciubotariu wrote:
> Add platform support for the new IP found on sam9x60 SoC. For this
> version, if the peripheral clk is above 100MHz, the HALFR bit must be
> set. This bit is available only if the IP can generate a random number
> every 168 cycles (instead of 84).
> 
> Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
> ---
>  drivers/char/hw_random/atmel-rng.c | 39 ++++++++++++++++++++++++++++--
>  1 file changed, 37 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c
> index e55705745d5e..0aa9425e6c3e 100644
> --- a/drivers/char/hw_random/atmel-rng.c
> +++ b/drivers/char/hw_random/atmel-rng.c
> @@ -14,14 +14,22 @@
>  #include <linux/clk.h>
>  #include <linux/io.h>
>  #include <linux/hw_random.h>
> +#include <linux/of_device.h>
>  #include <linux/platform_device.h>
>  
>  #define TRNG_CR		0x00
> +#define TRNG_MR		0x04
>  #define TRNG_ISR	0x1c
>  #define TRNG_ODATA	0x50
>  
>  #define TRNG_KEY	0x524e4700 /* RNG */
>  
> +#define TRNG_HALFR	BIT(0) /* generate RN every 168 cycles */
> +
> +struct atmel_trng_pdata {

Could that be just atmel_trng_data?

There is no platform data in this driver and it is DT only.

> +	bool has_half_rate;
> +};
> +
>  struct atmel_trng {
>  	struct clk *clk;
>  	void __iomem *base;
> @@ -63,6 +71,7 @@ static int atmel_trng_probe(struct platform_device *pdev)
>  {
>  	struct atmel_trng *trng;
>  	struct resource *res;
> +	const struct atmel_trng_pdata *pdata;
>  	int ret;
>  
>  	trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL);
> @@ -77,6 +86,17 @@ static int atmel_trng_probe(struct platform_device *pdev)
>  	trng->clk = devm_clk_get(&pdev->dev, NULL);
>  	if (IS_ERR(trng->clk))
>  		return PTR_ERR(trng->clk);
> +	pdata = of_device_get_match_data(&pdev->dev);
> +	if (!pdata)
> +		return -ENODEV;
> +
> +	if (pdata->has_half_rate) {
> +		unsigned long rate = clk_get_rate(trng->clk);
> +
> +		/* if peripheral clk is above 100MHz, set HALFR */
> +		if (rate > 100000000)
> +			writel(TRNG_HALFR, trng->base + TRNG_MR);
> +	}
>  
>  	ret = clk_prepare_enable(trng->clk);
>  	if (ret)
> @@ -141,9 +161,24 @@ static const struct dev_pm_ops atmel_trng_pm_ops = {
>  };
>  #endif /* CONFIG_PM */
>  
> +static struct atmel_trng_pdata at91sam9g45_config = {
> +	.has_half_rate = false,
> +};
> +
> +static struct atmel_trng_pdata sam9x60_config = {
> +	.has_half_rate = true,
> +};
> +
>  static const struct of_device_id atmel_trng_dt_ids[] = {
> -	{ .compatible = "atmel,at91sam9g45-trng" },
> -	{ /* sentinel */ }
> +	{
> +		.compatible = "atmel,at91sam9g45-trng",
> +		.data = &at91sam9g45_config,
> +	}, {
> +		.compatible = "microchip,sam9x60-trng",
> +		.data = &sam9x60_config,
> +	}, {
> +		/* sentinel */
> +	}
>  };
>  MODULE_DEVICE_TABLE(of, atmel_trng_dt_ids);
>  
> -- 
> 2.20.1
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

WARNING: multiple messages have this Message-ID (diff)
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
Cc: mark.rutland@arm.com, devicetree@vger.kernel.org,
	herbert@gondor.apana.org.au, arnd@arndb.de,
	Tudor.Ambarus@microchip.com, linux-kernel@vger.kernel.org,
	ludovic.desroches@microchip.com, robh+dt@kernel.org,
	linux-crypto@vger.kernel.org, mpm@selenic.com,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 2/2] hwrng: atmel: add new platform support for sam9x60
Date: Fri, 25 Oct 2019 10:01:36 +0200	[thread overview]
Message-ID: <20191025080136.GA3125@piout.net> (raw)
In-Reply-To: <20191024170452.2145-2-codrin.ciubotariu@microchip.com>

On 24/10/2019 20:04:52+0300, Codrin Ciubotariu wrote:
> Add platform support for the new IP found on sam9x60 SoC. For this
> version, if the peripheral clk is above 100MHz, the HALFR bit must be
> set. This bit is available only if the IP can generate a random number
> every 168 cycles (instead of 84).
> 
> Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
> ---
>  drivers/char/hw_random/atmel-rng.c | 39 ++++++++++++++++++++++++++++--
>  1 file changed, 37 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c
> index e55705745d5e..0aa9425e6c3e 100644
> --- a/drivers/char/hw_random/atmel-rng.c
> +++ b/drivers/char/hw_random/atmel-rng.c
> @@ -14,14 +14,22 @@
>  #include <linux/clk.h>
>  #include <linux/io.h>
>  #include <linux/hw_random.h>
> +#include <linux/of_device.h>
>  #include <linux/platform_device.h>
>  
>  #define TRNG_CR		0x00
> +#define TRNG_MR		0x04
>  #define TRNG_ISR	0x1c
>  #define TRNG_ODATA	0x50
>  
>  #define TRNG_KEY	0x524e4700 /* RNG */
>  
> +#define TRNG_HALFR	BIT(0) /* generate RN every 168 cycles */
> +
> +struct atmel_trng_pdata {

Could that be just atmel_trng_data?

There is no platform data in this driver and it is DT only.

> +	bool has_half_rate;
> +};
> +
>  struct atmel_trng {
>  	struct clk *clk;
>  	void __iomem *base;
> @@ -63,6 +71,7 @@ static int atmel_trng_probe(struct platform_device *pdev)
>  {
>  	struct atmel_trng *trng;
>  	struct resource *res;
> +	const struct atmel_trng_pdata *pdata;
>  	int ret;
>  
>  	trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL);
> @@ -77,6 +86,17 @@ static int atmel_trng_probe(struct platform_device *pdev)
>  	trng->clk = devm_clk_get(&pdev->dev, NULL);
>  	if (IS_ERR(trng->clk))
>  		return PTR_ERR(trng->clk);
> +	pdata = of_device_get_match_data(&pdev->dev);
> +	if (!pdata)
> +		return -ENODEV;
> +
> +	if (pdata->has_half_rate) {
> +		unsigned long rate = clk_get_rate(trng->clk);
> +
> +		/* if peripheral clk is above 100MHz, set HALFR */
> +		if (rate > 100000000)
> +			writel(TRNG_HALFR, trng->base + TRNG_MR);
> +	}
>  
>  	ret = clk_prepare_enable(trng->clk);
>  	if (ret)
> @@ -141,9 +161,24 @@ static const struct dev_pm_ops atmel_trng_pm_ops = {
>  };
>  #endif /* CONFIG_PM */
>  
> +static struct atmel_trng_pdata at91sam9g45_config = {
> +	.has_half_rate = false,
> +};
> +
> +static struct atmel_trng_pdata sam9x60_config = {
> +	.has_half_rate = true,
> +};
> +
>  static const struct of_device_id atmel_trng_dt_ids[] = {
> -	{ .compatible = "atmel,at91sam9g45-trng" },
> -	{ /* sentinel */ }
> +	{
> +		.compatible = "atmel,at91sam9g45-trng",
> +		.data = &at91sam9g45_config,
> +	}, {
> +		.compatible = "microchip,sam9x60-trng",
> +		.data = &sam9x60_config,
> +	}, {
> +		/* sentinel */
> +	}
>  };
>  MODULE_DEVICE_TABLE(of, atmel_trng_dt_ids);
>  
> -- 
> 2.20.1
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-10-25  8:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-24 17:04 [PATCH 1/2] dt-bindings: rng: atmel-trng: add new compatible Codrin Ciubotariu
2019-10-24 17:04 ` Codrin Ciubotariu
2019-10-24 17:04 ` [PATCH 2/2] hwrng: atmel: add new platform support for sam9x60 Codrin Ciubotariu
2019-10-24 17:04   ` Codrin Ciubotariu
2019-10-25  8:01   ` Alexandre Belloni [this message]
2019-10-25  8:01     ` Alexandre Belloni
2019-10-25  9:07   ` Claudiu.Beznea
2019-10-25  9:07     ` Claudiu.Beznea
2019-10-29 21:34 ` [PATCH 1/2] dt-bindings: rng: atmel-trng: add new compatible Rob Herring
2019-10-29 21:34   ` Rob Herring

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=20191025080136.GA3125@piout.net \
    --to=alexandre.belloni@bootlin.com \
    --cc=Tudor.Ambarus@microchip.com \
    --cc=arnd@arndb.de \
    --cc=codrin.ciubotariu@microchip.com \
    --cc=devicetree@vger.kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ludovic.desroches@microchip.com \
    --cc=mark.rutland@arm.com \
    --cc=mpm@selenic.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=robh+dt@kernel.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 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.