bcm63xx: add driver for the internal hw trng on bcm6368

SVN-Revision: 31131
master
Jonas Gorski 13 years ago
parent 78fb818f7c
commit 68f268a5eb
  1. 1
      target/linux/brcm63xx/config-3.3
  2. 23
      target/linux/brcm63xx/patches-3.3/101-MIPS-BCM63XX-fix-BCM6368-IPSec-clock-bit.patch
  3. 43
      target/linux/brcm63xx/patches-3.3/102-MIPS-BCM63XX-add-support-for-ipsec-clock.patch
  4. 106
      target/linux/brcm63xx/patches-3.3/103-MIPS-BCM63XX-add-TRNG-peripheral-definitions.patch
  5. 66
      target/linux/brcm63xx/patches-3.3/104-MIPS-BCM63XX-add-RNG-driver-platform_device-stub.patch
  6. 224
      target/linux/brcm63xx/patches-3.3/105-hw_random-add-Broadcom-BCM63xx-RNG-driver.patch
  7. 6
      target/linux/brcm63xx/patches-3.3/401-MIPS-BCM63XX-register-ohci-device.patch
  8. 6
      target/linux/brcm63xx/patches-3.3/403-MIPS-BCM63XX-register-ehci-device.patch
  9. 2
      target/linux/brcm63xx/patches-3.3/414-bcm63xx_enet-split-dma-registers-access.patch

@ -82,6 +82,7 @@ CONFIG_HAVE_OPROFILE=y
CONFIG_HAVE_PERF_EVENTS=y
CONFIG_HW_HAS_PCI=y
CONFIG_HW_RANDOM=y
# CONFIG_HW_RANDOM_BCM63XX is not set
CONFIG_HZ=250
# CONFIG_HZ_100 is not set
CONFIG_HZ_250=y

@ -0,0 +1,23 @@
From 41ee87b6ddd525fab54e21ede506f2084bcabed3 Mon Sep 17 00:00:00 2001
From: Florian Fainelli <florian@openwrt.org>
Date: Wed, 25 Jan 2012 17:39:52 +0100
Subject: [PATCH 14/63] MIPS: BCM63XX: fix BCM6368 IPSec clock bit
The IPsec clock bit is 18 and not 17.
Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
--- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
+++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
@@ -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 | \

@ -0,0 +1,43 @@
From 69b21096e25889d7db7cfc159202ef0a16530e6b Mon Sep 17 00:00:00 2001
From: Florian Fainelli <florian@openwrt.org>
Date: Wed, 25 Jan 2012 17:39:54 +0100
Subject: [PATCH 15/63] MIPS: BCM63XX: add support for "ipsec" clock
This module is only available on BCM6368 so far and does not require
resetting the block.
Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
arch/mips/bcm63xx/clk.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
--- a/arch/mips/bcm63xx/clk.c
+++ b/arch/mips/bcm63xx/clk.c
@@ -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,
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);
}

@ -0,0 +1,106 @@
From 913c171ebfe0d589bdf6efb8fd607258c96ea54a Mon Sep 17 00:00:00 2001
From: Florian Fainelli <florian@openwrt.org>
Date: Wed, 25 Jan 2012 17:39:58 +0100
Subject: [PATCH 16/63] MIPS: BCM63XX: add TRNG peripheral definitions
Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
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(-)
--- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h
+++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h
@@ -129,6 +129,7 @@ enum bcm63xx_regs_set {
RSET_PCMDMA,
RSET_PCMDMAC,
RSET_PCMDMAS,
+ RSET_TRNG
};
#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_TRNG_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_TRNG_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_TRNG_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_TRNG_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_TRNG_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_TRNG_BASE (0xb0004180)
extern const unsigned long *bcm63xx_regs_base;
@@ -404,6 +411,7 @@ extern const unsigned long *bcm63xx_regs
__GEN_RSET_BASE(__cpu, PCMDMA) \
__GEN_RSET_BASE(__cpu, PCMDMAC) \
__GEN_RSET_BASE(__cpu, PCMDMAS) \
+ __GEN_RSET_BASE(__cpu, TRNG) \
}
#define __GEN_CPU_REGS_TABLE(__cpu) \
@@ -442,6 +450,7 @@ extern const unsigned long *bcm63xx_regs
[RSET_PCMDMA] = BCM_## __cpu ##_PCMDMA_BASE, \
[RSET_PCMDMAC] = BCM_## __cpu ##_PCMDMAC_BASE, \
[RSET_PCMDMAS] = BCM_## __cpu ##_PCMDMAS_BASE, \
+ [RSET_TRNG] = BCM_## __cpu ##_TRNG_BASE, \
static inline unsigned long bcm63xx_regset_address(enum bcm63xx_regs_set set)
--- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
+++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h
@@ -1092,4 +1092,18 @@
#define SPI_SSOFFTIME_SHIFT 3
#define SPI_BYTE_SWAP 0x80
+/*************************************************************************
+ * _REG relative to RSET_TRNG
+ *************************************************************************/
+
+#define TRNG_CTRL 0x00
+#define TRNG_EN (1 << 0)
+
+#define TRNG_STAT 0x04
+#define TRNG_AVAIL_MASK (0xff000000)
+
+#define TRNG_DATA 0x08
+#define TRNG_THRES 0x0c
+#define TRNG_MASK 0x10
+
#endif /* BCM63XX_REGS_H_ */

@ -0,0 +1,66 @@
From cfcc8526e97bdcbfcbf945246b878262389b8842 Mon Sep 17 00:00:00 2001
From: Florian Fainelli <florian@openwrt.org>
Date: Wed, 25 Jan 2012 17:39:59 +0100
Subject: [PATCH 17/63] MIPS: BCM63XX: add RNG driver platform_device stub
Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
arch/mips/bcm63xx/Makefile | 4 ++--
arch/mips/bcm63xx/dev-trng.c | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 2 deletions(-)
create mode 100644 arch/mips/bcm63xx/dev-trng.c
--- a/arch/mips/bcm63xx/Makefile
+++ b/arch/mips/bcm63xx/Makefile
@@ -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-spi.o dev-trng.o \
+ dev-uart.o dev-wdt.o
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
obj-y += boards/
--- /dev/null
+++ b/arch/mips/bcm63xx/dev-trng.c
@@ -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 <florian@openwrt.org>
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <bcm63xx_cpu.h>
+
+static struct resource trng_resources[] = {
+ {
+ .start = -1, /* filled at runtime */
+ .end = -1, /* filled at runtime */
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static struct platform_device bcm63xx_trng_device = {
+ .name = "bcm63xx-trng",
+ .id = -1,
+ .num_resources = ARRAY_SIZE(trng_resources),
+ .resource = trng_resources,
+};
+
+int __init bcm63xx_trng_register(void)
+{
+ if (!BCMCPU_IS_6368())
+ return -ENODEV;
+
+ trng_resources[0].start = bcm63xx_regset_address(RSET_TRNG);
+ trng_resources[0].end = trng_resources[0].start;
+ trng_resources[0].end += RSET_TRNG_SIZE - 1;
+
+ return platform_device_register(&bcm63xx_trng_device);
+}
+arch_initcall(bcm63xx_trng_register);

@ -0,0 +1,224 @@
From 21a474b37f905387d8908384a24c13d4f8513113 Mon Sep 17 00:00:00 2001
From: Florian Fainelli <florian@openwrt.org>
Date: Wed, 25 Jan 2012 17:40:02 +0100
Subject: [PATCH 18/63] hw_random: add Broadcom BCM63xx RNG driver
Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
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
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -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
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_HW_RANDOM_TIMERIOMEM) += ti
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
--- /dev/null
+++ b/drivers/char/hw_random/bcm63xx-rng.c
@@ -0,0 +1,175 @@
+/*
+ * Broadcom BCM63xx Random Number Generator support
+ *
+ * Copyright (C) 2011, Florian Fainelli <florian@openwrt.org>
+ * Copyright (C) 2009, Broadcom Corporation
+ *
+ */
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/io.h>
+#include <linux/err.h>
+#include <linux/clk.h>
+#include <linux/platform_device.h>
+#include <linux/hw_random.h>
+
+#include <bcm63xx_io.h>
+#include <bcm63xx_regs.h>
+
+struct bcm63xx_trng_priv {
+ struct clk *clk;
+ void __iomem *regs;
+};
+
+#define to_trng_priv(rng) ((struct bcm63xx_trng_priv *)rng->priv)
+
+static int bcm63xx_trng_init(struct hwrng *rng)
+{
+ struct bcm63xx_trng_priv *priv = to_trng_priv(rng);
+ u32 val;
+
+ val = bcm_readl(priv->regs + TRNG_CTRL);
+ val |= TRNG_EN;
+ bcm_writel(val, priv->regs + TRNG_CTRL);
+
+ return 0;
+}
+
+static void bcm63xx_trng_cleanup(struct hwrng *rng)
+{
+ struct bcm63xx_trng_priv *priv = to_trng_priv(rng);
+ u32 val;
+
+ val = bcm_readl(priv->regs + TRNG_CTRL);
+ val &= ~TRNG_EN;
+ bcm_writel(val, priv->regs + TRNG_CTRL);
+}
+
+static int bcm63xx_trng_data_present(struct hwrng *rng, int wait)
+{
+ struct bcm63xx_trng_priv *priv = to_trng_priv(rng);
+
+ return bcm_readl(priv->regs + TRNG_STAT) & TRNG_AVAIL_MASK;
+}
+
+static int bcm63xx_trng_data_read(struct hwrng *rng, u32 *data)
+{
+ struct bcm63xx_trng_priv *priv = to_trng_priv(rng);
+
+ *data = bcm_readl(priv->regs + TRNG_DATA);
+
+ return 4;
+}
+
+static int __init bcm63xx_trng_probe(struct platform_device *pdev)
+{
+ struct resource *r;
+ struct clk *clk;
+ int ret;
+ struct bcm63xx_trng_priv *priv;
+ struct hwrng *rng;
+
+ r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!r) {
+ dev_err(&pdev->dev, "no iomem resource\n");
+ ret = -ENXIO;
+ goto out;
+ }
+
+ priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ if (!priv) {
+ dev_err(&pdev->dev, "no memory for private structure\n");
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ rng = kzalloc(sizeof(*rng), GFP_KERNEL);
+ if (!rng) {
+ dev_err(&pdev->dev, "no memory for rng structure\n");
+ ret = -ENOMEM;
+ goto out_free_priv;
+ }
+
+ platform_set_drvdata(pdev, rng);
+ rng->priv = (unsigned long)priv;
+ rng->name = pdev->name;
+ rng->init = bcm63xx_trng_init;
+ rng->cleanup = bcm63xx_trng_cleanup;
+ rng->data_present = bcm63xx_trng_data_present;
+ rng->data_read = bcm63xx_trng_data_read;
+
+ clk = clk_get(&pdev->dev, "ipsec");
+ if (IS_ERR(clk)) {
+ dev_err(&pdev->dev, "no clock for device\n");
+ ret = PTR_ERR(clk);
+ goto out_free_rng;
+ }
+
+ priv->clk = clk;
+
+ if (!devm_request_mem_region(&pdev->dev, r->start,
+ resource_size(r), pdev->name)) {
+ dev_err(&pdev->dev, "request mem failed");
+ ret = -ENOMEM;
+ goto out_free_rng;
+ }
+
+ priv->regs = devm_ioremap_nocache(&pdev->dev, r->start,
+ resource_size(r));
+ if (!priv->regs) {
+ dev_err(&pdev->dev, "ioremap failed");
+ ret = -ENOMEM;
+ goto out_free_rng;
+ }
+
+ clk_enable(clk);
+
+ ret = hwrng_register(rng);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to register rng device\n");
+ goto out_clk_disable;
+ }
+
+ dev_info(&pdev->dev, "registered RNG driver\n");
+
+ return 0;
+
+out_clk_disable:
+ clk_disable(clk);
+out_free_rng:
+ platform_set_drvdata(pdev, NULL);
+ kfree(rng);
+out_free_priv:
+ kfree(priv);
+out:
+ return ret;
+}
+
+static int __devexit bcm63xx_trng_remove(struct platform_device *pdev)
+{
+ struct hwrng *rng = platform_get_drvdata(pdev);
+ struct bcm63xx_trng_priv *priv = to_trng_priv(rng);
+
+ hwrng_unregister(rng);
+ clk_disable(priv->clk);
+ kfree(priv);
+ kfree(rng);
+ platform_set_drvdata(pdev, NULL);
+
+ return 0;
+}
+
+static struct platform_driver bcm63xx_trng_driver = {
+ .probe = bcm63xx_trng_probe,
+ .remove = __devexit_p(bcm63xx_trng_remove),
+ .driver = {
+ .name = "bcm63xx-trng",
+ .owner = THIS_MODULE,
+ },
+};
+
+module_platform_driver(bcm63xx_trng_driver);
+
+MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
+MODULE_DESCRIPTION("Broadcom BCM63xx RNG driver");
+MODULE_LICENSE("GPL");

@ -50,9 +50,9 @@ Subject: [PATCH 24/63] MIPS: BCM63XX: register ohci device.
+++ b/arch/mips/bcm63xx/Makefile
@@ -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-usb-ohci.o dev-wdt.o
dev-dsp.o dev-enet.o dev-pcmcia.o dev-spi.o dev-trng.o \
- dev-uart.o dev-wdt.o
+ dev-uart.o dev-usb-ohci.o dev-wdt.o
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
obj-y += boards/

@ -33,9 +33,9 @@ Subject: [PATCH 26/63] MIPS: BCM63XX: register ehci device.
+++ b/arch/mips/bcm63xx/Makefile
@@ -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-usb-ohci.o dev-wdt.o
+ dev-usb-ehci.o dev-usb-ohci.o dev-wdt.o
dev-dsp.o dev-enet.o dev-pcmcia.o dev-spi.o dev-trng.o \
- dev-uart.o dev-usb-ohci.o dev-wdt.o
+ dev-uart.o dev-usb-ehci.o dev-usb-ohci.o dev-wdt.o
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
obj-y += boards/

@ -50,7 +50,7 @@ Subject: [PATCH 30/63] bcm63xx_enet: split dma registers access.
if (ret)
--- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h
+++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_cpu.h
@@ -139,7 +139,9 @@ enum bcm63xx_regs_set {
@@ -140,7 +140,9 @@ enum bcm63xx_regs_set {
#define BCM_6358_RSET_SPI_SIZE 1804
#define BCM_6368_RSET_SPI_SIZE 1804
#define RSET_ENET_SIZE 2048

Loading…
Cancel
Save