diff mbox

[v2,2/3] hwrng: OMAP3 ROM Random Number Generator support

Message ID 1379683507-30793-3-git-send-email-pali.rohar@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Pali Rohár Sept. 20, 2013, 1:25 p.m. UTC
This driver provides kernel-side support for the Random Number
Generator hardware found on OMAP34xx processors.

This driver comes from Maemo 2.6.28 kernel and was tested on Nokia RX-51.
It is platform device because it needs board specific function for smc calls.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Juha Yrjola <juha.yrjola@solidboot.com>
---
 drivers/char/hw_random/Kconfig         |   13 +++
 drivers/char/hw_random/Makefile        |    1 +
 drivers/char/hw_random/omap3-rom-rng.c |  141 ++++++++++++++++++++++++++++++++
 3 files changed, 155 insertions(+)
 create mode 100644 drivers/char/hw_random/omap3-rom-rng.c

Comments

Tony Lindgren Oct. 8, 2013, 7:04 p.m. UTC | #1
* Pali Rohár <pali.rohar@gmail.com> [130920 06:33]:
> This driver provides kernel-side support for the Random Number
> Generator hardware found on OMAP34xx processors.
> 
> This driver comes from Maemo 2.6.28 kernel and was tested on Nokia RX-51.
> It is platform device because it needs board specific function for smc calls.

This one is should be merged via the hw_random patches seprately:

Acked-by: Tony Lindgren <tony@atomide.com>
 
> Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
> Signed-off-by: Juha Yrjola <juha.yrjola@solidboot.com>
> ---
>  drivers/char/hw_random/Kconfig         |   13 +++
>  drivers/char/hw_random/Makefile        |    1 +
>  drivers/char/hw_random/omap3-rom-rng.c |  141 ++++++++++++++++++++++++++++++++
>  3 files changed, 155 insertions(+)
>  create mode 100644 drivers/char/hw_random/omap3-rom-rng.c
> 
> diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
> index 0aa9d91..0a331c3 100644
> --- a/drivers/char/hw_random/Kconfig
> +++ b/drivers/char/hw_random/Kconfig
> @@ -165,6 +165,19 @@ config HW_RANDOM_OMAP
>  
>   	  If unsure, say Y.
>  
> +config HW_RANDOM_OMAP3_ROM
> +	tristate "OMAP3 ROM Random Number Generator support"
> +	depends on HW_RANDOM && ARCH_OMAP3
> +	default HW_RANDOM
> +	---help---
> +	  This driver provides kernel-side support for the Random Number
> +	  Generator hardware found on OMAP34xx processors.
> +
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called omap3-rom-rng.
> +
> +	  If unsure, say Y.
> +
>  config HW_RANDOM_OCTEON
>  	tristate "Octeon Random Number Generator support"
>  	depends on HW_RANDOM && CAVIUM_OCTEON_SOC
> diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
> index bed467c..7c8aa80 100644
> --- a/drivers/char/hw_random/Makefile
> +++ b/drivers/char/hw_random/Makefile
> @@ -15,6 +15,7 @@ n2-rng-y := n2-drv.o n2-asm.o
>  obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o
>  obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
>  obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
> +obj-$(CONFIG_HW_RANDOM_OMAP3_ROM) += omap3-rom-rng.o
>  obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
>  obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
>  obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
> diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
> new file mode 100644
> index 0000000..c853e9e
> --- /dev/null
> +++ b/drivers/char/hw_random/omap3-rom-rng.c
> @@ -0,0 +1,141 @@
> +/*
> + * omap3-rom-rng.c - RNG driver for TI OMAP3 CPU family
> + *
> + * Copyright (C) 2009 Nokia Corporation
> + * Author: Juha Yrjola <juha.yrjola@solidboot.com>
> + *
> + * Copyright (C) 2013 Pali Rohár <pali.rohar@gmail.com>
> + *
> + * This file is licensed under  the terms of the GNU General Public
> + * License version 2. This program is licensed "as is" without any
> + * warranty of any kind, whether express or implied.
> + */
> +
> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/random.h>
> +#include <linux/hw_random.h>
> +#include <linux/timer.h>
> +#include <linux/clk.h>
> +#include <linux/err.h>
> +#include <linux/platform_device.h>
> +
> +#define RNG_RESET			0x01
> +#define RNG_GEN_PRNG_HW_INIT		0x02
> +#define RNG_GEN_HW			0x08
> +
> +/* param1: ptr, param2: count, param3: flag */
> +static u32 (*omap3_rom_rng_call)(u32, u32, u32);
> +
> +static struct timer_list idle_timer;
> +static int rng_idle;
> +static struct clk *rng_clk;
> +
> +static void omap3_rom_rng_idle(unsigned long data)
> +{
> +	int r;
> +
> +	r = omap3_rom_rng_call(0, 0, RNG_RESET);
> +	if (r != 0) {
> +		pr_err("reset failed: %d\n", r);
> +		return;
> +	}
> +	clk_disable_unprepare(rng_clk);
> +	rng_idle = 1;
> +}
> +
> +static int omap3_rom_rng_get_random(void *buf, unsigned int count)
> +{
> +	u32 r;
> +	u32 ptr;
> +
> +	del_timer_sync(&idle_timer);
> +	if (rng_idle) {
> +		clk_prepare_enable(rng_clk);
> +		r = omap3_rom_rng_call(0, 0, RNG_GEN_PRNG_HW_INIT);
> +		if (r != 0) {
> +			clk_disable_unprepare(rng_clk);
> +			pr_err("HW init failed: %d\n", r);
> +			return -EIO;
> +		}
> +		rng_idle = 0;
> +	}
> +
> +	ptr = virt_to_phys(buf);
> +	r = omap3_rom_rng_call(ptr, count, RNG_GEN_HW);
> +	mod_timer(&idle_timer, jiffies + msecs_to_jiffies(500));
> +	if (r != 0)
> +		return -EINVAL;
> +	return 0;
> +}
> +
> +static int omap3_rom_rng_data_present(struct hwrng *rng, int wait)
> +{
> +	return 1;
> +}
> +
> +static int omap3_rom_rng_data_read(struct hwrng *rng, u32 *data)
> +{
> +	int r;
> +
> +	r = omap3_rom_rng_get_random(data, 4);
> +	if (r < 0)
> +		return r;
> +	return 4;
> +}
> +
> +static struct hwrng omap3_rom_rng_ops = {
> +	.name		= "omap3-rom",
> +	.data_present	= omap3_rom_rng_data_present,
> +	.data_read	= omap3_rom_rng_data_read,
> +};
> +
> +static int omap3_rom_rng_probe(struct platform_device *pdev)
> +{
> +	pr_info("initializing\n");
> +
> +	omap3_rom_rng_call = pdev->dev.platform_data;
> +	if (!omap3_rom_rng_call) {
> +		pr_err("omap3_rom_rng_call is NULL\n");
> +		return -EINVAL;
> +	}
> +
> +	setup_timer(&idle_timer, omap3_rom_rng_idle, 0);
> +	rng_clk = clk_get(&pdev->dev, "ick");
> +	if (IS_ERR(rng_clk)) {
> +		pr_err("unable to get RNG clock\n");
> +		return PTR_ERR(rng_clk);
> +	}
> +
> +	/* Leave the RNG in reset state. */
> +	clk_prepare_enable(rng_clk);
> +	omap3_rom_rng_idle(0);
> +
> +	return hwrng_register(&omap3_rom_rng_ops);
> +}
> +
> +static int omap3_rom_rng_remove(struct platform_device *pdev)
> +{
> +	hwrng_unregister(&omap3_rom_rng_ops);
> +	clk_disable_unprepare(rng_clk);
> +	clk_put(rng_clk);
> +	return 0;
> +}
> +
> +static struct platform_driver omap3_rom_rng_driver = {
> +	.driver = {
> +		.name		= "omap3-rom-rng",
> +		.owner		= THIS_MODULE,
> +	},
> +	.probe		= omap3_rom_rng_probe,
> +	.remove		= omap3_rom_rng_remove,
> +};
> +
> +module_platform_driver(omap3_rom_rng_driver);
> +
> +MODULE_ALIAS("platform:omap3-rom-rng");
> +MODULE_AUTHOR("Juha Yrjola");
> +MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
> +MODULE_LICENSE("GPL");
> -- 
> 1.7.10.4
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Herbert Xu Oct. 16, 2013, 12:57 p.m. UTC | #2
On Tue, Oct 08, 2013 at 12:04:09PM -0700, Tony Lindgren wrote:
> * Pali Rohár <pali.rohar@gmail.com> [130920 06:33]:
> > This driver provides kernel-side support for the Random Number
> > Generator hardware found on OMAP34xx processors.
> > 
> > This driver comes from Maemo 2.6.28 kernel and was tested on Nokia RX-51.
> > It is platform device because it needs board specific function for smc calls.
> 
> This one is should be merged via the hw_random patches seprately:
> 
> Acked-by: Tony Lindgren <tony@atomide.com>

Patch applied.  Thanks!
Pali Rohár Nov. 18, 2013, 9:51 p.m. UTC | #3
On Wednesday 16 October 2013 14:57:34 Herbert Xu wrote:
> On Tue, Oct 08, 2013 at 12:04:09PM -0700, Tony Lindgren wrote:
> > * Pali Rohár <pali.rohar@gmail.com> [130920 06:33]:
> > > This driver provides kernel-side support for the Random
> > > Number Generator hardware found on OMAP34xx processors.
> > > 
> > > This driver comes from Maemo 2.6.28 kernel and was tested
> > > on Nokia RX-51. It is platform device because it needs
> > > board specific function for smc calls.
> > 
> > This one is should be merged via the hw_random patches
> > seprately:
> > 
> > Acked-by: Tony Lindgren <tony@atomide.com>
> 
> Patch applied.  Thanks!

Hello, I still do not see this patch (2/3) in linus tree. But 
patch 1/3 and 3/3 are already merged. So is there any problem?
Herbert Xu Nov. 19, 2013, 2:14 a.m. UTC | #4
On Mon, Nov 18, 2013 at 10:51:30PM +0100, Pali Rohár wrote:
> On Wednesday 16 October 2013 14:57:34 Herbert Xu wrote:
> > On Tue, Oct 08, 2013 at 12:04:09PM -0700, Tony Lindgren wrote:
> > > * Pali Rohár <pali.rohar@gmail.com> [130920 06:33]:
> > > > This driver provides kernel-side support for the Random
> > > > Number Generator hardware found on OMAP34xx processors.
> > > > 
> > > > This driver comes from Maemo 2.6.28 kernel and was tested
> > > > on Nokia RX-51. It is platform device because it needs
> > > > board specific function for smc calls.
> > > 
> > > This one is should be merged via the hw_random patches
> > > seprately:
> > > 
> > > Acked-by: Tony Lindgren <tony@atomide.com>
> > 
> > Patch applied.  Thanks!
> 
> Hello, I still do not see this patch (2/3) in linus tree. But 
> patch 1/3 and 3/3 are already merged. So is there any problem?

2/3 is still in my tree so when Linus pulls it it'll be there.

Cheers,
Pali Rohár Nov. 23, 2013, 9:37 a.m. UTC | #5
On Tuesday 19 November 2013 03:14:09 Herbert Xu wrote:
> On Mon, Nov 18, 2013 at 10:51:30PM +0100, Pali Rohár wrote:
> > On Wednesday 16 October 2013 14:57:34 Herbert Xu wrote:
> > > On Tue, Oct 08, 2013 at 12:04:09PM -0700, Tony Lindgren 
wrote:
> > > > * Pali Rohár <pali.rohar@gmail.com> [130920 06:33]:
> > > > > This driver provides kernel-side support for the
> > > > > Random Number Generator hardware found on OMAP34xx
> > > > > processors.
> > > > > 
> > > > > This driver comes from Maemo 2.6.28 kernel and was
> > > > > tested on Nokia RX-51. It is platform device because
> > > > > it needs board specific function for smc calls.
> > > > 
> > > > This one is should be merged via the hw_random patches
> > > > seprately:
> > > > 
> > > > Acked-by: Tony Lindgren <tony@atomide.com>
> > > 
> > > Patch applied.  Thanks!
> > 
> > Hello, I still do not see this patch (2/3) in linus tree.
> > But patch 1/3 and 3/3 are already merged. So is there any
> > problem?
> 
> 2/3 is still in my tree so when Linus pulls it it'll be there.
> 
> Cheers,

Now 3.13-rc1 is out [1], but your tree was not merged. Can you 
try to ping Linus what happened?

[1] - https://lkml.org/lkml/2013/11/22/439
Sebastian Reichel Nov. 23, 2013, 12:09 p.m. UTC | #6
On Sat, Nov 23, 2013 at 10:37:13AM +0100, Pali Rohár wrote:
> Now 3.13-rc1 is out, but your tree was not merged. Can you 
> try to ping Linus what happened?

See here: http://www.spinics.net/lists/arm-kernel/msg288508.html

-- Sebastian
diff mbox

Patch

diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 0aa9d91..0a331c3 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -165,6 +165,19 @@  config HW_RANDOM_OMAP
 
  	  If unsure, say Y.
 
+config HW_RANDOM_OMAP3_ROM
+	tristate "OMAP3 ROM Random Number Generator support"
+	depends on HW_RANDOM && ARCH_OMAP3
+	default HW_RANDOM
+	---help---
+	  This driver provides kernel-side support for the Random Number
+	  Generator hardware found on OMAP34xx processors.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called omap3-rom-rng.
+
+	  If unsure, say Y.
+
 config HW_RANDOM_OCTEON
 	tristate "Octeon Random Number Generator support"
 	depends on HW_RANDOM && CAVIUM_OCTEON_SOC
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index bed467c..7c8aa80 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -15,6 +15,7 @@  n2-rng-y := n2-drv.o n2-asm.o
 obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o
 obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
 obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
+obj-$(CONFIG_HW_RANDOM_OMAP3_ROM) += omap3-rom-rng.o
 obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
 obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
 obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
new file mode 100644
index 0000000..c853e9e
--- /dev/null
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -0,0 +1,141 @@ 
+/*
+ * omap3-rom-rng.c - RNG driver for TI OMAP3 CPU family
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ * Author: Juha Yrjola <juha.yrjola@solidboot.com>
+ *
+ * Copyright (C) 2013 Pali Rohár <pali.rohar@gmail.com>
+ *
+ * This file is licensed under  the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/random.h>
+#include <linux/hw_random.h>
+#include <linux/timer.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+
+#define RNG_RESET			0x01
+#define RNG_GEN_PRNG_HW_INIT		0x02
+#define RNG_GEN_HW			0x08
+
+/* param1: ptr, param2: count, param3: flag */
+static u32 (*omap3_rom_rng_call)(u32, u32, u32);
+
+static struct timer_list idle_timer;
+static int rng_idle;
+static struct clk *rng_clk;
+
+static void omap3_rom_rng_idle(unsigned long data)
+{
+	int r;
+
+	r = omap3_rom_rng_call(0, 0, RNG_RESET);
+	if (r != 0) {
+		pr_err("reset failed: %d\n", r);
+		return;
+	}
+	clk_disable_unprepare(rng_clk);
+	rng_idle = 1;
+}
+
+static int omap3_rom_rng_get_random(void *buf, unsigned int count)
+{
+	u32 r;
+	u32 ptr;
+
+	del_timer_sync(&idle_timer);
+	if (rng_idle) {
+		clk_prepare_enable(rng_clk);
+		r = omap3_rom_rng_call(0, 0, RNG_GEN_PRNG_HW_INIT);
+		if (r != 0) {
+			clk_disable_unprepare(rng_clk);
+			pr_err("HW init failed: %d\n", r);
+			return -EIO;
+		}
+		rng_idle = 0;
+	}
+
+	ptr = virt_to_phys(buf);
+	r = omap3_rom_rng_call(ptr, count, RNG_GEN_HW);
+	mod_timer(&idle_timer, jiffies + msecs_to_jiffies(500));
+	if (r != 0)
+		return -EINVAL;
+	return 0;
+}
+
+static int omap3_rom_rng_data_present(struct hwrng *rng, int wait)
+{
+	return 1;
+}
+
+static int omap3_rom_rng_data_read(struct hwrng *rng, u32 *data)
+{
+	int r;
+
+	r = omap3_rom_rng_get_random(data, 4);
+	if (r < 0)
+		return r;
+	return 4;
+}
+
+static struct hwrng omap3_rom_rng_ops = {
+	.name		= "omap3-rom",
+	.data_present	= omap3_rom_rng_data_present,
+	.data_read	= omap3_rom_rng_data_read,
+};
+
+static int omap3_rom_rng_probe(struct platform_device *pdev)
+{
+	pr_info("initializing\n");
+
+	omap3_rom_rng_call = pdev->dev.platform_data;
+	if (!omap3_rom_rng_call) {
+		pr_err("omap3_rom_rng_call is NULL\n");
+		return -EINVAL;
+	}
+
+	setup_timer(&idle_timer, omap3_rom_rng_idle, 0);
+	rng_clk = clk_get(&pdev->dev, "ick");
+	if (IS_ERR(rng_clk)) {
+		pr_err("unable to get RNG clock\n");
+		return PTR_ERR(rng_clk);
+	}
+
+	/* Leave the RNG in reset state. */
+	clk_prepare_enable(rng_clk);
+	omap3_rom_rng_idle(0);
+
+	return hwrng_register(&omap3_rom_rng_ops);
+}
+
+static int omap3_rom_rng_remove(struct platform_device *pdev)
+{
+	hwrng_unregister(&omap3_rom_rng_ops);
+	clk_disable_unprepare(rng_clk);
+	clk_put(rng_clk);
+	return 0;
+}
+
+static struct platform_driver omap3_rom_rng_driver = {
+	.driver = {
+		.name		= "omap3-rom-rng",
+		.owner		= THIS_MODULE,
+	},
+	.probe		= omap3_rom_rng_probe,
+	.remove		= omap3_rom_rng_remove,
+};
+
+module_platform_driver(omap3_rom_rng_driver);
+
+MODULE_ALIAS("platform:omap3-rom-rng");
+MODULE_AUTHOR("Juha Yrjola");
+MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
+MODULE_LICENSE("GPL");