Release 4.11 drivers/char/hw_random/atmel-rng.c
/*
* Copyright (c) 2011 Peter Korsgaard <jacmet@sunsite.dk>
*
* 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.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/hw_random.h>
#include <linux/platform_device.h>
#define TRNG_CR 0x00
#define TRNG_ISR 0x1c
#define TRNG_ODATA 0x50
#define TRNG_KEY 0x524e4700
/* RNG */
struct atmel_trng {
struct clk *clk;
void __iomem *base;
struct hwrng rng;
};
static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max,
bool wait)
{
struct atmel_trng *trng = container_of(rng, struct atmel_trng, rng);
u32 *data = buf;
/* data ready? */
if (readl(trng->base + TRNG_ISR) & 1) {
*data = readl(trng->base + TRNG_ODATA);
/*
ensure data ready is only set again AFTER the next data
word is ready in case it got set between checking ISR
and reading ODATA, so we don't risk re-reading the
same word
*/
readl(trng->base + TRNG_ISR);
return 4;
} else
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Peter Korsgaard | 87 | 100.00% | 3 | 100.00% |
Total | 87 | 100.00% | 3 | 100.00% |
static void atmel_trng_enable(struct atmel_trng *trng)
{
writel(TRNG_KEY | 1, trng->base + TRNG_CR);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Wenyou Yang | 24 | 100.00% | 1 | 100.00% |
Total | 24 | 100.00% | 1 | 100.00% |
static void atmel_trng_disable(struct atmel_trng *trng)
{
writel(TRNG_KEY, trng->base + TRNG_CR);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Wenyou Yang | 22 | 100.00% | 1 | 100.00% |
Total | 22 | 100.00% | 1 | 100.00% |
static int atmel_trng_probe(struct platform_device *pdev)
{
struct atmel_trng *trng;
struct resource *res;
int ret;
trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL);
if (!trng)
return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
trng->base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(trng->base))
return PTR_ERR(trng->base);
trng->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(trng->clk))
return PTR_ERR(trng->clk);
ret = clk_prepare_enable(trng->clk);
if (ret)
return ret;
atmel_trng_enable(trng);
trng->rng.name = pdev->name;
trng->rng.read = atmel_trng_read;
ret = hwrng_register(&trng->rng);
if (ret)
goto err_register;
platform_set_drvdata(pdev, trng);
return 0;
err_register:
clk_disable_unprepare(trng->clk);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Peter Korsgaard | 179 | 88.61% | 1 | 16.67% |
Jingoo Han | 20 | 9.90% | 2 | 33.33% |
Boris Brezillon | 1 | 0.50% | 1 | 16.67% |
Wei Yongjun | 1 | 0.50% | 1 | 16.67% |
Wenyou Yang | 1 | 0.50% | 1 | 16.67% |
Total | 202 | 100.00% | 6 | 100.00% |
static int atmel_trng_remove(struct platform_device *pdev)
{
struct atmel_trng *trng = platform_get_drvdata(pdev);
hwrng_unregister(&trng->rng);
atmel_trng_disable(trng);
clk_disable_unprepare(trng->clk);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Peter Korsgaard | 42 | 95.45% | 1 | 33.33% |
Boris Brezillon | 1 | 2.27% | 1 | 33.33% |
Wenyou Yang | 1 | 2.27% | 1 | 33.33% |
Total | 44 | 100.00% | 3 | 100.00% |
#ifdef CONFIG_PM
static int atmel_trng_suspend(struct device *dev)
{
struct atmel_trng *trng = dev_get_drvdata(dev);
atmel_trng_disable(trng);
clk_disable_unprepare(trng->clk);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Peter Korsgaard | 30 | 83.33% | 1 | 33.33% |
Wenyou Yang | 5 | 13.89% | 1 | 33.33% |
Boris Brezillon | 1 | 2.78% | 1 | 33.33% |
Total | 36 | 100.00% | 3 | 100.00% |
static int atmel_trng_resume(struct device *dev)
{
struct atmel_trng *trng = dev_get_drvdata(dev);
int ret;
ret = clk_prepare_enable(trng->clk);
if (ret)
return ret;
atmel_trng_enable(trng);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Peter Korsgaard | 27 | 56.25% | 1 | 33.33% |
Wenyou Yang | 20 | 41.67% | 1 | 33.33% |
Boris Brezillon | 1 | 2.08% | 1 | 33.33% |
Total | 48 | 100.00% | 3 | 100.00% |
static const struct dev_pm_ops atmel_trng_pm_ops = {
.suspend = atmel_trng_suspend,
.resume = atmel_trng_resume,
};
#endif /* CONFIG_PM */
static const struct of_device_id atmel_trng_dt_ids[] = {
{ .compatible = "atmel,at91sam9g45-trng" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, atmel_trng_dt_ids);
static struct platform_driver atmel_trng_driver = {
.probe = atmel_trng_probe,
.remove = atmel_trng_remove,
.driver = {
.name = "atmel-trng",
#ifdef CONFIG_PM
.pm = &atmel_trng_pm_ops,
#endif /* CONFIG_PM */
.of_match_table = atmel_trng_dt_ids,
},
};
module_platform_driver(atmel_trng_driver);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Peter Korsgaard <jacmet@sunsite.dk>");
MODULE_DESCRIPTION("Atmel true random number generator driver");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Peter Korsgaard | 508 | 79.50% | 3 | 30.00% |
Wenyou Yang | 73 | 11.42% | 1 | 10.00% |
Boris Brezillon | 36 | 5.63% | 2 | 20.00% |
Jingoo Han | 20 | 3.13% | 2 | 20.00% |
Wei Yongjun | 1 | 0.16% | 1 | 10.00% |
Axel Lin | 1 | 0.16% | 1 | 10.00% |
Total | 639 | 100.00% | 10 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.