linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Add support for the RNG in Ingenic JZ4780 and X1000.
@ 2020-07-22 16:40 周琰杰 (Zhou Yanjie)
  2020-07-22 16:40 ` [PATCH 1/2] dt-bindings: RNG: Add Ingenic RNG bindings 周琰杰 (Zhou Yanjie)
  2020-07-22 16:40 ` [PATCH 2/2] crypto: Ingenic: Add hardware RNG for Ingenic JZ4780 and X1000 周琰杰 (Zhou Yanjie)
  0 siblings, 2 replies; 5+ messages in thread
From: 周琰杰 (Zhou Yanjie) @ 2020-07-22 16:40 UTC (permalink / raw)
  To: arnd, gregkh, mpm, herbert, robh+dt
  Cc: linux-crypto, linux-kernel, devicetree, hadar.gat,
	prasannatsmkumar, krzk, masahiroy, rdunlap, xuzaibo,
	daniel.thompson, tmaimon77, dongsheng.qiu, aric.pzqi, rick.tyliu,
	yanfei.li, sernia.zhou, zhenwenjin

1.Add the RNG bindings for the JZ4780 SoC and the X1000 SoC
  from Ingenic.
2.Add JZ4780 SoC and X1000 SoC random number generator driver,
  based on PrasannaKumar Muralidharan's JZ4780 RNG driver.

周琰杰 (Zhou Yanjie) (2):
  dt-bindings: RNG: Add Ingenic RNG bindings.
  crypto: Ingenic: Add hardware RNG for Ingenic JZ4780 and X1000.

 .../devicetree/bindings/rng/ingenic,rng.yaml       |  36 +++++
 drivers/char/hw_random/Kconfig                     |  15 ++
 drivers/char/hw_random/Makefile                    |   1 +
 drivers/char/hw_random/ingenic-rng.c               | 154 +++++++++++++++++++++
 4 files changed, 206 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rng/ingenic,rng.yaml
 create mode 100644 drivers/char/hw_random/ingenic-rng.c

-- 
2.11.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] dt-bindings: RNG: Add Ingenic RNG bindings.
  2020-07-22 16:40 [PATCH 0/2] Add support for the RNG in Ingenic JZ4780 and X1000 周琰杰 (Zhou Yanjie)
@ 2020-07-22 16:40 ` 周琰杰 (Zhou Yanjie)
  2020-07-22 16:40 ` [PATCH 2/2] crypto: Ingenic: Add hardware RNG for Ingenic JZ4780 and X1000 周琰杰 (Zhou Yanjie)
  1 sibling, 0 replies; 5+ messages in thread
From: 周琰杰 (Zhou Yanjie) @ 2020-07-22 16:40 UTC (permalink / raw)
  To: arnd, gregkh, mpm, herbert, robh+dt
  Cc: linux-crypto, linux-kernel, devicetree, hadar.gat,
	prasannatsmkumar, krzk, masahiroy, rdunlap, xuzaibo,
	daniel.thompson, tmaimon77, dongsheng.qiu, aric.pzqi, rick.tyliu,
	yanfei.li, sernia.zhou, zhenwenjin

Add the RNG bindings for the JZ4780 SoC and
the X1000 SoC from Ingenic.

Signed-off-by: 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>
---
 .../devicetree/bindings/rng/ingenic,rng.yaml       | 36 ++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rng/ingenic,rng.yaml

diff --git a/Documentation/devicetree/bindings/rng/ingenic,rng.yaml b/Documentation/devicetree/bindings/rng/ingenic,rng.yaml
new file mode 100644
index 000000000000..b2e4a6a7f93a
--- /dev/null
+++ b/Documentation/devicetree/bindings/rng/ingenic,rng.yaml
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rng/ingenic,rng.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Bindings for RNG in Ingenic SoCs
+
+maintainers:
+  - 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>
+
+description:
+  The Random Number Generator in Ingenic SoCs.
+
+properties:
+  compatible:
+    enum:
+      - ingenic,jz4780-rng
+      - ingenic,x1000-rng
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    rng: rng@d8 {
+        compatible = "ingenic,jz4780-rng";
+        reg = <0xd8 0x8>;
+    };
+...
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] crypto: Ingenic: Add hardware RNG for Ingenic JZ4780 and X1000.
  2020-07-22 16:40 [PATCH 0/2] Add support for the RNG in Ingenic JZ4780 and X1000 周琰杰 (Zhou Yanjie)
  2020-07-22 16:40 ` [PATCH 1/2] dt-bindings: RNG: Add Ingenic RNG bindings 周琰杰 (Zhou Yanjie)
@ 2020-07-22 16:40 ` 周琰杰 (Zhou Yanjie)
  2020-07-22 18:27   ` Randy Dunlap
  1 sibling, 1 reply; 5+ messages in thread
From: 周琰杰 (Zhou Yanjie) @ 2020-07-22 16:40 UTC (permalink / raw)
  To: arnd, gregkh, mpm, herbert, robh+dt
  Cc: linux-crypto, linux-kernel, devicetree, hadar.gat,
	prasannatsmkumar, krzk, masahiroy, rdunlap, xuzaibo,
	daniel.thompson, tmaimon77, dongsheng.qiu, aric.pzqi, rick.tyliu,
	yanfei.li, sernia.zhou, zhenwenjin

Add JZ4780 SoC and X1000 SoC random number generator driver,
based on PrasannaKumar Muralidharan's JZ4780 RNG driver.

Tested-by: 周正 (Zhou Zheng) <sernia.zhou@foxmail.com>
Tested-by: Mathieu Malaterre <malat@debian.org>
Suggested-by: Jeffrey Walton <noloader@gmail.com>
Signed-off-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
Signed-off-by: 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>
---
 drivers/char/hw_random/Kconfig       |  15 ++++
 drivers/char/hw_random/Makefile      |   1 +
 drivers/char/hw_random/ingenic-rng.c | 154 +++++++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+)
 create mode 100644 drivers/char/hw_random/ingenic-rng.c

diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 0ad17efc96df..fcb06027cd88 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -257,6 +257,21 @@ config HW_RANDOM_IMX_RNGC
 
 	  If unsure, say Y.
 
+config HW_RANDOM_INGENIC_RNG
+	tristate "Ingenic Random Number Generator support"
+	depends on HW_RANDOM
+	depends on MACH_JZ4780 || MACH_X1000
+	default HW_RANDOM
+	---help---
+	  This driver provides kernel-side support for the Random Number Generator
+	  hardware found in ingenic JZ4780 and X1000 SoC. MIPS Creator CI20 uses
+	  JZ4780 SoC, YSH & ATIL CU1000-Neo uses X1000 SoC.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ingenic-rng.
+
+	  If unsure, say Y.
+
 config HW_RANDOM_NOMADIK
 	tristate "ST-Ericsson Nomadik Random Number Generator support"
 	depends on ARCH_NOMADIK
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index 2c6724735345..acb1a1978d23 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
 obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
 obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o
 obj-$(CONFIG_HW_RANDOM_IMX_RNGC) += imx-rngc.o
+obj-$(CONFIG_HW_RANDOM_INGENIC_RNG) += ingenic-rng.o
 obj-$(CONFIG_HW_RANDOM_OCTEON) += octeon-rng.o
 obj-$(CONFIG_HW_RANDOM_NOMADIK) += nomadik-rng.o
 obj-$(CONFIG_HW_RANDOM_PSERIES) += pseries-rng.o
diff --git a/drivers/char/hw_random/ingenic-rng.c b/drivers/char/hw_random/ingenic-rng.c
new file mode 100644
index 000000000000..d704cef64b64
--- /dev/null
+++ b/drivers/char/hw_random/ingenic-rng.c
@@ -0,0 +1,154 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Ingenic Random Number Generator driver
+ * Copyright (c) 2017 PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
+ * Copyright (c) 2020 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>
+ */
+
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/hw_random.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+/* RNG register offsets */
+#define RNG_REG_ERNG_OFFSET		0x0
+#define RNG_REG_RNG_OFFSET		0x4
+
+/* bits within the ERND register */
+#define ERNG_READY				BIT(31)
+#define ERNG_ENABLE				BIT(0)
+
+enum ingenic_rng_version {
+	ID_JZ4780,
+	ID_X1000,
+};
+
+/* Device associated memory */
+struct ingenic_rng {
+	enum ingenic_rng_version version;
+
+	void __iomem *base;
+	struct hwrng rng;
+};
+
+static int ingenic_rng_init(struct hwrng *rng)
+{
+	struct ingenic_rng *priv = container_of(rng, struct ingenic_rng, rng);
+
+	writel(ERNG_ENABLE, priv->base + RNG_REG_ERNG_OFFSET);
+
+	return 0;
+}
+
+static void ingenic_rng_cleanup(struct hwrng *rng)
+{
+	struct ingenic_rng *priv = container_of(rng, struct ingenic_rng, rng);
+
+	writel(0, priv->base + RNG_REG_ERNG_OFFSET);
+}
+
+static int ingenic_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
+{
+	struct ingenic_rng *priv = container_of(rng, struct ingenic_rng, rng);
+	u32 *data = buf;
+	u32 status;
+	int ret;
+
+	if (priv->version >= ID_X1000) {
+		ret = readl_poll_timeout(priv->base + RNG_REG_ERNG_OFFSET, status,
+					 status & ERNG_READY, 10, 1000);
+		if (ret == -ETIMEDOUT) {
+			pr_err("%s: Wait for RNG data ready timeout\n", __func__);
+			return ret;
+		}
+	} else {
+		/*
+		 * A delay is required so that the current RNG data is not bit shifted
+		 * version of previous RNG data which could happen if random data is
+		 * read continuously from this device.
+		 */
+		udelay(20);
+	}
+
+	*data = readl(priv->base + RNG_REG_RNG_OFFSET);
+
+	return 4;
+}
+
+static int ingenic_rng_probe(struct platform_device *pdev)
+{
+	struct ingenic_rng *priv;
+	int ret;
+
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->base)) {
+		pr_err("%s: Failed to map RNG registers\n", __func__);
+		ret = PTR_ERR(priv->base);
+		goto err_free_rng;
+	}
+
+	priv->version = (enum ingenic_rng_version)of_device_get_match_data(&pdev->dev);
+
+	priv->rng.name = pdev->name;
+	priv->rng.init = ingenic_rng_init;
+	priv->rng.cleanup = ingenic_rng_cleanup;
+	priv->rng.read = ingenic_rng_read;
+
+	ret = hwrng_register(&priv->rng);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to register hwrng\n");
+		goto err_free_rng;
+	}
+
+	platform_set_drvdata(pdev, priv);
+
+	dev_info(&pdev->dev, "Ingenic RNG driver registered\n");
+	return 0;
+
+err_free_rng:
+	kfree(priv);
+	return ret;
+}
+
+static int ingenic_rng_remove(struct platform_device *pdev)
+{
+	struct ingenic_rng *priv = platform_get_drvdata(pdev);
+
+	hwrng_unregister(&priv->rng);
+
+	writel(0, priv->base + RNG_REG_ERNG_OFFSET);
+
+	return 0;
+}
+
+static const struct of_device_id ingenic_rng_of_match[] = {
+	{ .compatible = "ingenic,jz4780-rng", .data = (void *) ID_JZ4780 },
+	{ .compatible = "ingenic,x1000-rng", .data = (void *) ID_X1000 },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, ingenic_rng_of_match);
+
+static struct platform_driver ingenic_rng_driver = {
+	.probe		= ingenic_rng_probe,
+	.remove		= ingenic_rng_remove,
+	.driver		= {
+		.name	= "ingenic-rng",
+		.of_match_table = ingenic_rng_of_match,
+	},
+};
+
+module_platform_driver(ingenic_rng_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>");
+MODULE_AUTHOR("周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>");
+MODULE_DESCRIPTION("Ingenic Random Number Generator driver");
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] crypto: Ingenic: Add hardware RNG for Ingenic JZ4780 and X1000.
  2020-07-22 16:40 ` [PATCH 2/2] crypto: Ingenic: Add hardware RNG for Ingenic JZ4780 and X1000 周琰杰 (Zhou Yanjie)
@ 2020-07-22 18:27   ` Randy Dunlap
  2020-07-23  6:16     ` Zhou Yanjie
  0 siblings, 1 reply; 5+ messages in thread
From: Randy Dunlap @ 2020-07-22 18:27 UTC (permalink / raw)
  To: 周琰杰 (Zhou Yanjie),
	arnd, gregkh, mpm, herbert, robh+dt
  Cc: linux-crypto, linux-kernel, devicetree, hadar.gat,
	prasannatsmkumar, krzk, masahiroy, xuzaibo, daniel.thompson,
	tmaimon77, dongsheng.qiu, aric.pzqi, rick.tyliu, yanfei.li,
	sernia.zhou, zhenwenjin

On 7/22/20 9:40 AM, 周琰杰 (Zhou Yanjie) wrote:
> diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
> index 0ad17efc96df..fcb06027cd88 100644
> --- a/drivers/char/hw_random/Kconfig
> +++ b/drivers/char/hw_random/Kconfig
> @@ -257,6 +257,21 @@ config HW_RANDOM_IMX_RNGC
>  
>  	  If unsure, say Y.
>  
> +config HW_RANDOM_INGENIC_RNG
> +	tristate "Ingenic Random Number Generator support"
> +	depends on HW_RANDOM
> +	depends on MACH_JZ4780 || MACH_X1000
> +	default HW_RANDOM
> +	---help---

Just use:
	help
here. See this for why:

commit 8f268881d7d278047b00eed54bbb9288dbd6ab23
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Tue Dec 17 20:51:51 2019 +0900

    kconfig: remove ---help--- from documentation
    
    Since commit 84af7a6194e4 ("checkpatch: kconfig: prefer 'help' over
    '---help---'"), scripts/checkpatch.pl warns the use of ---help---.
    
    Kconfig still supports ---help---, but new code should avoid using it.
    Let's stop advertising it in documentation.

> +	  This driver provides kernel-side support for the Random Number Generator
> +	  hardware found in ingenic JZ4780 and X1000 SoC. MIPS Creator CI20 uses
> +	  JZ4780 SoC, YSH & ATIL CU1000-Neo uses X1000 SoC.
> +
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called ingenic-rng.
> +
> +	  If unsure, say Y.
> +
>  config HW_RANDOM_NOMADIK
>  	tristate "ST-Ericsson Nomadik Random Number Generator support"
>  	depends on ARCH_NOMADIK

thanks.
-- 
~Randy


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] crypto: Ingenic: Add hardware RNG for Ingenic JZ4780 and X1000.
  2020-07-22 18:27   ` Randy Dunlap
@ 2020-07-23  6:16     ` Zhou Yanjie
  0 siblings, 0 replies; 5+ messages in thread
From: Zhou Yanjie @ 2020-07-23  6:16 UTC (permalink / raw)
  To: Randy Dunlap, arnd, gregkh, mpm, herbert, robh+dt
  Cc: linux-crypto, linux-kernel, devicetree, hadar.gat,
	prasannatsmkumar, krzk, masahiroy, xuzaibo, daniel.thompson,
	tmaimon77, dongsheng.qiu, aric.pzqi, rick.tyliu, yanfei.li,
	sernia.zhou, zhenwenjin

Hello Randy,

在 2020/7/23 上午2:27, Randy Dunlap 写道:
> On 7/22/20 9:40 AM, 周琰杰 (Zhou Yanjie) wrote:
>> diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
>> index 0ad17efc96df..fcb06027cd88 100644
>> --- a/drivers/char/hw_random/Kconfig
>> +++ b/drivers/char/hw_random/Kconfig
>> @@ -257,6 +257,21 @@ config HW_RANDOM_IMX_RNGC
>>   
>>   	  If unsure, say Y.
>>   
>> +config HW_RANDOM_INGENIC_RNG
>> +	tristate "Ingenic Random Number Generator support"
>> +	depends on HW_RANDOM
>> +	depends on MACH_JZ4780 || MACH_X1000
>> +	default HW_RANDOM
>> +	---help---
> Just use:
> 	help
> here. See this for why:
>
> commit 8f268881d7d278047b00eed54bbb9288dbd6ab23
> Author: Masahiro Yamada <masahiroy@kernel.org>
> Date:   Tue Dec 17 20:51:51 2019 +0900
>
>      kconfig: remove ---help--- from documentation
>      
>      Since commit 84af7a6194e4 ("checkpatch: kconfig: prefer 'help' over
>      '---help---'"), scripts/checkpatch.pl warns the use of ---help---.
>      
>      Kconfig still supports ---help---, but new code should avoid using it.
>      Let's stop advertising it in documentation.
>

Sure, I will change it in v2.

Thanks and best regards!


>> +	  This driver provides kernel-side support for the Random Number Generator
>> +	  hardware found in ingenic JZ4780 and X1000 SoC. MIPS Creator CI20 uses
>> +	  JZ4780 SoC, YSH & ATIL CU1000-Neo uses X1000 SoC.
>> +
>> +	  To compile this driver as a module, choose M here: the
>> +	  module will be called ingenic-rng.
>> +
>> +	  If unsure, say Y.
>> +
>>   config HW_RANDOM_NOMADIK
>>   	tristate "ST-Ericsson Nomadik Random Number Generator support"
>>   	depends on ARCH_NOMADIK
> thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-23  6:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22 16:40 [PATCH 0/2] Add support for the RNG in Ingenic JZ4780 and X1000 周琰杰 (Zhou Yanjie)
2020-07-22 16:40 ` [PATCH 1/2] dt-bindings: RNG: Add Ingenic RNG bindings 周琰杰 (Zhou Yanjie)
2020-07-22 16:40 ` [PATCH 2/2] crypto: Ingenic: Add hardware RNG for Ingenic JZ4780 and X1000 周琰杰 (Zhou Yanjie)
2020-07-22 18:27   ` Randy Dunlap
2020-07-23  6:16     ` Zhou Yanjie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).