[kernel/2.6.38] fix gcc-4.6 set but unused warnings
[openwrt.git] / target / linux / brcm63xx / patches-3.3 / 105-hw_random-add-Broadcom-BCM63xx-RNG-driver.patch
1 From 21a474b37f905387d8908384a24c13d4f8513113 Mon Sep 17 00:00:00 2001
2 From: Florian Fainelli <florian@openwrt.org>
3 Date: Wed, 25 Jan 2012 17:40:02 +0100
4 Subject: [PATCH 18/63] hw_random: add Broadcom BCM63xx RNG driver
5
6 Signed-off-by: Florian Fainelli <florian@openwrt.org>
7 ---
8 drivers/char/hw_random/Kconfig | 14 +++
9 drivers/char/hw_random/Makefile | 1 +
10 drivers/char/hw_random/bcm63xx-rng.c | 175 ++++++++++++++++++++++++++++++++++
11 3 files changed, 190 insertions(+), 0 deletions(-)
12 create mode 100644 drivers/char/hw_random/bcm63xx-rng.c
13
14 --- a/drivers/char/hw_random/Kconfig
15 +++ b/drivers/char/hw_random/Kconfig
16 @@ -73,6 +73,20 @@ config HW_RANDOM_ATMEL
17
18 If unsure, say Y.
19
20 +config HW_RANDOM_BCM63XX
21 + tristate "Broadcom BCM63xx Random Number Generator support"
22 + depends on HW_RANDOM && BCM63XX
23 + default HW_RANDOM
24 + ---help---
25 + This driver provides kernel-side support for the Random Number
26 + Generator hardware found on the Broadcom BCM63xx SoCs.
27 +
28 + To compile this driver as a module, choose M here: the
29 + module will be called bcm63xx-rng
30 +
31 + If unusure, say Y.
32 +
33 +
34 config HW_RANDOM_GEODE
35 tristate "AMD Geode HW Random Number Generator support"
36 depends on HW_RANDOM && X86_32 && PCI
37 --- a/drivers/char/hw_random/Makefile
38 +++ b/drivers/char/hw_random/Makefile
39 @@ -8,6 +8,7 @@ obj-$(CONFIG_HW_RANDOM_TIMERIOMEM) += ti
40 obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o
41 obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o
42 obj-$(CONFIG_HW_RANDOM_ATMEL) += atmel-rng.o
43 +obj-$(CONFIG_HW_RANDOM_BCM63XX) += bcm63xx-rng.o
44 obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o
45 obj-$(CONFIG_HW_RANDOM_N2RNG) += n2-rng.o
46 n2-rng-y := n2-drv.o n2-asm.o
47 --- /dev/null
48 +++ b/drivers/char/hw_random/bcm63xx-rng.c
49 @@ -0,0 +1,175 @@
50 +/*
51 + * Broadcom BCM63xx Random Number Generator support
52 + *
53 + * Copyright (C) 2011, Florian Fainelli <florian@openwrt.org>
54 + * Copyright (C) 2009, Broadcom Corporation
55 + *
56 + */
57 +#include <linux/module.h>
58 +#include <linux/slab.h>
59 +#include <linux/io.h>
60 +#include <linux/err.h>
61 +#include <linux/clk.h>
62 +#include <linux/platform_device.h>
63 +#include <linux/hw_random.h>
64 +
65 +#include <bcm63xx_io.h>
66 +#include <bcm63xx_regs.h>
67 +
68 +struct bcm63xx_trng_priv {
69 + struct clk *clk;
70 + void __iomem *regs;
71 +};
72 +
73 +#define to_trng_priv(rng) ((struct bcm63xx_trng_priv *)rng->priv)
74 +
75 +static int bcm63xx_trng_init(struct hwrng *rng)
76 +{
77 + struct bcm63xx_trng_priv *priv = to_trng_priv(rng);
78 + u32 val;
79 +
80 + val = bcm_readl(priv->regs + TRNG_CTRL);
81 + val |= TRNG_EN;
82 + bcm_writel(val, priv->regs + TRNG_CTRL);
83 +
84 + return 0;
85 +}
86 +
87 +static void bcm63xx_trng_cleanup(struct hwrng *rng)
88 +{
89 + struct bcm63xx_trng_priv *priv = to_trng_priv(rng);
90 + u32 val;
91 +
92 + val = bcm_readl(priv->regs + TRNG_CTRL);
93 + val &= ~TRNG_EN;
94 + bcm_writel(val, priv->regs + TRNG_CTRL);
95 +}
96 +
97 +static int bcm63xx_trng_data_present(struct hwrng *rng, int wait)
98 +{
99 + struct bcm63xx_trng_priv *priv = to_trng_priv(rng);
100 +
101 + return bcm_readl(priv->regs + TRNG_STAT) & TRNG_AVAIL_MASK;
102 +}
103 +
104 +static int bcm63xx_trng_data_read(struct hwrng *rng, u32 *data)
105 +{
106 + struct bcm63xx_trng_priv *priv = to_trng_priv(rng);
107 +
108 + *data = bcm_readl(priv->regs + TRNG_DATA);
109 +
110 + return 4;
111 +}
112 +
113 +static int __init bcm63xx_trng_probe(struct platform_device *pdev)
114 +{
115 + struct resource *r;
116 + struct clk *clk;
117 + int ret;
118 + struct bcm63xx_trng_priv *priv;
119 + struct hwrng *rng;
120 +
121 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
122 + if (!r) {
123 + dev_err(&pdev->dev, "no iomem resource\n");
124 + ret = -ENXIO;
125 + goto out;
126 + }
127 +
128 + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
129 + if (!priv) {
130 + dev_err(&pdev->dev, "no memory for private structure\n");
131 + ret = -ENOMEM;
132 + goto out;
133 + }
134 +
135 + rng = kzalloc(sizeof(*rng), GFP_KERNEL);
136 + if (!rng) {
137 + dev_err(&pdev->dev, "no memory for rng structure\n");
138 + ret = -ENOMEM;
139 + goto out_free_priv;
140 + }
141 +
142 + platform_set_drvdata(pdev, rng);
143 + rng->priv = (unsigned long)priv;
144 + rng->name = pdev->name;
145 + rng->init = bcm63xx_trng_init;
146 + rng->cleanup = bcm63xx_trng_cleanup;
147 + rng->data_present = bcm63xx_trng_data_present;
148 + rng->data_read = bcm63xx_trng_data_read;
149 +
150 + clk = clk_get(&pdev->dev, "ipsec");
151 + if (IS_ERR(clk)) {
152 + dev_err(&pdev->dev, "no clock for device\n");
153 + ret = PTR_ERR(clk);
154 + goto out_free_rng;
155 + }
156 +
157 + priv->clk = clk;
158 +
159 + if (!devm_request_mem_region(&pdev->dev, r->start,
160 + resource_size(r), pdev->name)) {
161 + dev_err(&pdev->dev, "request mem failed");
162 + ret = -ENOMEM;
163 + goto out_free_rng;
164 + }
165 +
166 + priv->regs = devm_ioremap_nocache(&pdev->dev, r->start,
167 + resource_size(r));
168 + if (!priv->regs) {
169 + dev_err(&pdev->dev, "ioremap failed");
170 + ret = -ENOMEM;
171 + goto out_free_rng;
172 + }
173 +
174 + clk_enable(clk);
175 +
176 + ret = hwrng_register(rng);
177 + if (ret) {
178 + dev_err(&pdev->dev, "failed to register rng device\n");
179 + goto out_clk_disable;
180 + }
181 +
182 + dev_info(&pdev->dev, "registered RNG driver\n");
183 +
184 + return 0;
185 +
186 +out_clk_disable:
187 + clk_disable(clk);
188 +out_free_rng:
189 + platform_set_drvdata(pdev, NULL);
190 + kfree(rng);
191 +out_free_priv:
192 + kfree(priv);
193 +out:
194 + return ret;
195 +}
196 +
197 +static int __devexit bcm63xx_trng_remove(struct platform_device *pdev)
198 +{
199 + struct hwrng *rng = platform_get_drvdata(pdev);
200 + struct bcm63xx_trng_priv *priv = to_trng_priv(rng);
201 +
202 + hwrng_unregister(rng);
203 + clk_disable(priv->clk);
204 + kfree(priv);
205 + kfree(rng);
206 + platform_set_drvdata(pdev, NULL);
207 +
208 + return 0;
209 +}
210 +
211 +static struct platform_driver bcm63xx_trng_driver = {
212 + .probe = bcm63xx_trng_probe,
213 + .remove = __devexit_p(bcm63xx_trng_remove),
214 + .driver = {
215 + .name = "bcm63xx-trng",
216 + .owner = THIS_MODULE,
217 + },
218 +};
219 +
220 +module_platform_driver(bcm63xx_trng_driver);
221 +
222 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
223 +MODULE_DESCRIPTION("Broadcom BCM63xx RNG driver");
224 +MODULE_LICENSE("GPL");
This page took 0.06798 seconds and 5 git commands to generate.