Skip to contentSkip to conversation

MIPS: BCM63XX: add support for hardware RNG

PATCH New Florian Fainelli 1 participant 6 messages Jan 31, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover MIPS: BCM63XX: add support for hardware RNG

This patch set depends on the serie "MIPS: BCM63XX: add support for SPI" and adds support for the RNG block found in BCM6368 SoCs.

Herbert, Matt, this will probably better to get this merged via the MIPS tree considering the patches it depends on.

Florian Fainelli (5):
MIPS: BCM63XX: fix BCM6368 IPSec clock bit
MIPS: BCM63XX: add support for "ipsec" clock
MIPS: BCM63XX: add RNG peripheral definitions
MIPS: BCM63XX: add RNG driver platform_device stub
hw_random: add Broadcom BCM63xx RNG driver

 arch/mips/bcm63xx/Makefile                        |    4 +-
 arch/mips/bcm63xx/clk.c                           |   14 ++
 arch/mips/bcm63xx/dev-rng.c                       |   40 +++++
 arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h  |    9 +
 arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h |   16 ++-
 drivers/char/hw_random/Kconfig                    |   14 ++
 drivers/char/hw_random/Makefile                   |    1 +
 drivers/char/hw_random/bcm63xx-rng.c              |  175 +++++++++++++++++++++
 8 files changed, 270 insertions(+), 3 deletions(-)
 create mode 100644 arch/mips/bcm63xx/dev-rng.c
 create mode 100644 drivers/char/hw_random/bcm63xx-rng.c
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH v2 1/5 MIPS: BCM63XX: fix BCM6368 IPSec clock bit

The IPsec clock bit is 18 and not 17.

---
Changes since v1:
- rebased against "MIPS: BCM63XX: misc cleanup"

 arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h +1 -1
index c21aa34..be107e9 100644
@@ -99,7 +99,7 @@
 #define CKCTL_6368_USBH_EN		(1 << 15)
 #define CKCTL_6368_DISABLE_GLESS_EN	(1 << 16)
 #define CKCTL_6368_NAND_EN		(1 << 17)
-#define CKCTL_6368_IPSEC_EN		(1 << 17)
+#define CKCTL_6368_IPSEC_EN		(1 << 18)
 
 #define CKCTL_6368_ALL_SAFE_EN		(CKCTL_6368_SWPKT_USB_EN |	\
 					CKCTL_6368_SWPKT_SAR_EN |	\
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH v2 2/5 MIPS: BCM63XX: add support for "ipsec" clock

In reply to Florian Fainelli

This module is only available on BCM6368 so far and does not require resetting the block.

---
Changes since v1:
- rebased against "MIPS: BCM63XX: misc cleanup"

 arch/mips/bcm63xx/clk.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
arch/mips/bcm63xx/clk.c +14 -0
index be49b9a..1db48ad 100644
@@ -224,6 +224,18 @@ static struct clk clk_xtm = {
 };
 
 /*
+ * IPsec clock
+ */
+static void ipsec_set(struct clk *clk, int enable)
+{
+	bcm_hwclock_set(CKCTL_6368_IPSEC_EN, enable);
+}
+
+static struct clk clk_ipsec = {
+	.set	= ipsec_set,
+};
+
+/*
  * Internal peripheral clock
  */
 static struct clk clk_periph = {
@@ -280,6 +292,8 @@ struct clk *clk_get(struct device *dev, const char *id)
 		return &clk_periph;
 	if (BCMCPU_IS_6358() && !strcmp(id, "pcm"))
 		return &clk_pcm;
+	if (BCMCPU_IS_6368() && !strcmp(id, "ipsec"))
+		return &clk_ipsec;
 	return ERR_PTR(-ENOENT);
 }
 
Signature · 1 line
1.7.5.4
#3 lore raw

PATCH v2 3/5 MIPS: BCM63XX: add RNG peripheral definitions

In reply to Florian Fainelli

---
Changes since v1:
- renamed TRNG -> RNG to be consistent everywhere

 arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h  |    9 +++++++++
 arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h |   14 ++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)
arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h +9 -0
index 82a8175..0c981aa 100644
@@ -129,6 +129,7 @@ enum bcm63xx_regs_set {
 	RSET_PCMDMA,
 	RSET_PCMDMAC,
 	RSET_PCMDMAS,
+	RSET_RNG
 };
 
 #define RSET_DSL_LMEM_SIZE		(64 * 1024 * 4)
@@ -152,6 +153,7 @@ enum bcm63xx_regs_set {
 #define RSET_XTMDMA_SIZE		256
 #define RSET_XTMDMAC_SIZE(chans)	(16 * (chans))
 #define RSET_XTMDMAS_SIZE(chans)	(16 * (chans))
+#define RSET_RNG_SIZE			20
 
 /*
  * 6338 register sets base address
@@ -195,6 +197,7 @@ enum bcm63xx_regs_set {
 #define BCM_6338_PCMDMA_BASE		(0xdeadbeef)
 #define BCM_6338_PCMDMAC_BASE		(0xdeadbeef)
 #define BCM_6338_PCMDMAS_BASE		(0xdeadbeef)
+#define BCM_6338_RNG_BASE		(0xdeadbeef)
 
 /*
  * 6345 register sets base address
@@ -238,6 +241,7 @@ enum bcm63xx_regs_set {
 #define BCM_6345_PCMDMA_BASE		(0xdeadbeef)
 #define BCM_6345_PCMDMAC_BASE		(0xdeadbeef)
 #define BCM_6345_PCMDMAS_BASE		(0xdeadbeef)
+#define BCM_6345_RNG_BASE		(0xdeadbeef)
 
 /*
  * 6348 register sets base address
@@ -278,6 +282,7 @@ enum bcm63xx_regs_set {
 #define BCM_6348_PCMDMA_BASE		(0xdeadbeef)
 #define BCM_6348_PCMDMAC_BASE		(0xdeadbeef)
 #define BCM_6348_PCMDMAS_BASE		(0xdeadbeef)
+#define BCM_6348_RNG_BASE		(0xdeadbeef)
 
 /*
  * 6358 register sets base address
@@ -318,6 +323,7 @@ enum bcm63xx_regs_set {
 #define BCM_6358_PCMDMA_BASE		(0xfffe1800)
 #define BCM_6358_PCMDMAC_BASE		(0xfffe1900)
 #define BCM_6358_PCMDMAS_BASE		(0xfffe1a00)
+#define BCM_6358_RNG_BASE		(0xdeadbeef)
 
 
 /*
@@ -359,6 +365,7 @@ enum bcm63xx_regs_set {
 #define BCM_6368_PCMDMA_BASE		(0xb0005800)
 #define BCM_6368_PCMDMAC_BASE		(0xb0005a00)
 #define BCM_6368_PCMDMAS_BASE		(0xb0005c00)
+#define BCM_6368_RNG_BASE		(0xb0004180)
 
 
 extern const unsigned long *bcm63xx_regs_base;
@@ -404,6 +411,7 @@ extern const unsigned long *bcm63xx_regs_base;
 	__GEN_RSET_BASE(__cpu, PCMDMA)					\
 	__GEN_RSET_BASE(__cpu, PCMDMAC)					\
 	__GEN_RSET_BASE(__cpu, PCMDMAS)					\
+	__GEN_RSET_BASE(__cpu, RNG)					\
 	}
 
 #define __GEN_CPU_REGS_TABLE(__cpu)					\
@@ -442,6 +450,7 @@ extern const unsigned long *bcm63xx_regs_base;
 	[RSET_PCMDMA]		= BCM_## __cpu ##_PCMDMA_BASE,		\
 	[RSET_PCMDMAC]		= BCM_## __cpu ##_PCMDMAC_BASE,		\
 	[RSET_PCMDMAS]		= BCM_## __cpu ##_PCMDMAS_BASE,		\
+	[RSET_RNG]		= BCM_## __cpu ##_RNG_BASE,		\
 
 
 static inline unsigned long bcm63xx_regset_address(enum bcm63xx_regs_set set)
arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h +14 -0
index be107e9..6fdde35 100644
@@ -1092,4 +1092,18 @@
 #define SPI_SSOFFTIME_SHIFT		3
 #define SPI_BYTE_SWAP			0x80
 
+/*************************************************************************
+ * _REG relative to RSET_RNG
+ *************************************************************************/
+
+#define RNG_CTRL			0x00
+#define RNG_EN				(1 << 0)
+
+#define RNG_STAT			0x04
+#define RNG_AVAIL_MASK			(0xff000000)
+
+#define RNG_DATA			0x08
+#define RNG_THRES			0x0c
+#define RNG_MASK			0x10
+
 #endif /* BCM63XX_REGS_H_ */
Signature · 1 line
1.7.5.4
#4 lore raw

PATCH v2 4/5 MIPS: BCM63XX: add RNG driver platform_device stub

In reply to Florian Fainelli

---
Changes since v1:
- renamed TRNG -> RNG, trng -> rng
- fixed platform_device identifier since there is only one device

 arch/mips/bcm63xx/Makefile  |    4 ++--
 arch/mips/bcm63xx/dev-rng.c |   40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)
 create mode 100644 arch/mips/bcm63xx/dev-rng.c
arch/mips/bcm63xx/Makefile +2 -2
index 4049cd5..349b206 100644
@@ -1,6 +1,6 @@
 obj-y		+= clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o \
-		   dev-dsp.o dev-enet.o dev-pcmcia.o dev-spi.o dev-uart.o \
-		   dev-wdt.o
+		   dev-dsp.o dev-enet.o dev-pcmcia.o dev-rng.o dev-spi.o \
+		   dev-uart.o dev-wdt.o
 obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 
 obj-y		+= boards/
arch/mips/bcm63xx/dev-rng.c new file +40 -0
new file mode 100644
index 0000000..d277b4d
@@ -0,0 +1,40 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2011 Florian Fainelli <[email protected]>
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <bcm63xx_cpu.h>
+
+static struct resource rng_resources[] = {
+	{
+		.start		= -1, /* filled at runtime */
+		.end		= -1, /* filled at runtime */
+		.flags		= IORESOURCE_MEM,
+	},
+};
+
+static struct platform_device bcm63xx_rng_device = {
+	.name		= "bcm63xx-rng",
+	.id		= -1,
+	.num_resources	= ARRAY_SIZE(rng_resources),
+	.resource	= rng_resources,
+};
+
+int __init bcm63xx_rng_register(void)
+{
+	if (!BCMCPU_IS_6368())
+		return -ENODEV;
+
+	rng_resources[0].start = bcm63xx_regset_address(RSET_RNG);
+	rng_resources[0].end = rng_resources[0].start;
+	rng_resources[0].end += RSET_RNG_SIZE - 1;
+
+	return platform_device_register(&bcm63xx_rng_device);
+}
+arch_initcall(bcm63xx_rng_register);
Signature · 1 line
1.7.5.4
#5 lore raw

PATCH v2 5/5 hw_random: add Broadcom BCM63xx RNG driver

In reply to Florian Fainelli

---
Changes since v1:
- renamed TRNG -> RNG and trng -> rng

 drivers/char/hw_random/Kconfig       |   14 +++
 drivers/char/hw_random/Makefile      |    1 +
 drivers/char/hw_random/bcm63xx-rng.c |  175 ++++++++++++++++++++++++++++++++++
 3 files changed, 190 insertions(+), 0 deletions(-)
 create mode 100644 drivers/char/hw_random/bcm63xx-rng.c
drivers/char/hw_random/Kconfig +14 -0
index 0689bf6..f29d1bc 100644
@@ -73,6 +73,20 @@ config HW_RANDOM_ATMEL
 
 	  If unsure, say Y.
 
+config HW_RANDOM_BCM63XX
+	tristate "Broadcom BCM63xx Random Number Generator support"
+	depends on HW_RANDOM && BCM63XX
+	default HW_RANDOM
+	---help---
+	  This driver provides kernel-side support for the Random Number
+	  Generator hardware found on the Broadcom BCM63xx SoCs.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called bcm63xx-rng
+
+	  If unusure, say Y.
+
+
 config HW_RANDOM_GEODE
 	tristate "AMD Geode HW Random Number Generator support"
 	depends on HW_RANDOM && X86_32 && PCI
drivers/char/hw_random/Makefile +1 -0
index b2ff526..8cfac60 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_HW_RANDOM_TIMERIOMEM) += timeriomem-rng.o
 obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o
 obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o
 obj-$(CONFIG_HW_RANDOM_ATMEL) += atmel-rng.o
+obj-$(CONFIG_HW_RANDOM_BCM63XX)	+= bcm63xx-rng.o
 obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o
 obj-$(CONFIG_HW_RANDOM_N2RNG) += n2-rng.o
 n2-rng-y := n2-drv.o n2-asm.o
drivers/char/hw_random/bcm63xx-rng.c new file +175 -0

175 lines not on this page · raw message

Signature · 1 line
1.7.5.4