Release 4.11 drivers/crypto/amcc/crypto4xx_trng.c
/*
* Generic PowerPC 44x RNG driver
*
* Copyright 2011 IBM Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/hw_random.h>
#include <linux/delay.h>
#include <linux/of_address.h>
#include <linux/of_platform.h>
#include <linux/io.h>
#include "crypto4xx_core.h"
#include "crypto4xx_trng.h"
#include "crypto4xx_reg_def.h"
#define PPC4XX_TRNG_CTRL 0x0008
#define PPC4XX_TRNG_CTRL_DALM 0x20
#define PPC4XX_TRNG_STAT 0x0004
#define PPC4XX_TRNG_STAT_B 0x1
#define PPC4XX_TRNG_DATA 0x0000
static int ppc4xx_trng_data_present(struct hwrng *rng, int wait)
{
struct crypto4xx_device *dev = (void *)rng->priv;
int busy, i, present = 0;
for (i = 0; i < 20; i++) {
busy = (in_le32(dev->trng_base + PPC4XX_TRNG_STAT) &
PPC4XX_TRNG_STAT_B);
if (!busy || !wait) {
present = 1;
break;
}
udelay(10);
}
return present;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Josh Boyer | 82 | 92.13% | 1 | 50.00% |
Christian Lamparter | 7 | 7.87% | 1 | 50.00% |
Total | 89 | 100.00% | 2 | 100.00% |
static int ppc4xx_trng_data_read(struct hwrng *rng, u32 *data)
{
struct crypto4xx_device *dev = (void *)rng->priv;
*data = in_le32(dev->trng_base + PPC4XX_TRNG_DATA);
return 4;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Josh Boyer | 36 | 83.72% | 1 | 50.00% |
Christian Lamparter | 7 | 16.28% | 1 | 50.00% |
Total | 43 | 100.00% | 2 | 100.00% |
static void ppc4xx_trng_enable(struct crypto4xx_device *dev, bool enable)
{
u32 device_ctrl;
device_ctrl = readl(dev->ce_base + CRYPTO4XX_DEVICE_CTRL);
if (enable)
device_ctrl |= PPC4XX_TRNG_EN;
else
device_ctrl &= ~PPC4XX_TRNG_EN;
writel(device_ctrl, dev->ce_base + CRYPTO4XX_DEVICE_CTRL);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Lamparter | 27 | 50.94% | 1 | 50.00% |
Josh Boyer | 26 | 49.06% | 1 | 50.00% |
Total | 53 | 100.00% | 2 | 100.00% |
static const struct of_device_id ppc4xx_trng_match[] = {
{ .compatible = "ppc4xx-rng", },
{ .compatible = "amcc,ppc460ex-rng", },
{ .compatible = "amcc,ppc440epx-rng", },
{},
};
void ppc4xx_trng_probe(struct crypto4xx_core_device *core_dev)
{
struct crypto4xx_device *dev = core_dev->dev;
struct device_node *trng = NULL;
struct hwrng *rng = NULL;
int err;
/* Find the TRNG device node and map it */
trng = of_find_matching_node(NULL, ppc4xx_trng_match);
if (!trng || !of_device_is_available(trng))
return;
dev->trng_base = of_iomap(trng, 0);
of_node_put(trng);
if (!dev->trng_base)
goto err_out;
rng = kzalloc(sizeof(*rng), GFP_KERNEL);
if (!rng)
goto err_out;
rng->name = MODULE_NAME;
rng->data_present = ppc4xx_trng_data_present;
rng->data_read = ppc4xx_trng_data_read;
rng->priv = (unsigned long) dev;
core_dev->trng = rng;
ppc4xx_trng_enable(dev, true);
out_le32(dev->trng_base + PPC4XX_TRNG_CTRL, PPC4XX_TRNG_CTRL_DALM);
err = devm_hwrng_register(core_dev->device, core_dev->trng);
if (err) {
ppc4xx_trng_enable(dev, false);
dev_err(core_dev->device, "failed to register hwrng (%d).\n",
err);
goto err_out;
}
return;
err_out:
of_node_put(trng);
iounmap(dev->trng_base);
kfree(rng);
dev->trng_base = NULL;
core_dev->trng = NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Lamparter | 174 | 75.98% | 1 | 50.00% |
Josh Boyer | 55 | 24.02% | 1 | 50.00% |
Total | 229 | 100.00% | 2 | 100.00% |
void ppc4xx_trng_remove(struct crypto4xx_core_device *core_dev)
{
if (core_dev && core_dev->trng) {
struct crypto4xx_device *dev = core_dev->dev;
devm_hwrng_unregister(core_dev->device, core_dev->trng);
ppc4xx_trng_enable(dev, false);
iounmap(dev->trng_base);
kfree(core_dev->trng);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Lamparter | 44 | 72.13% | 1 | 33.33% |
Josh Boyer | 13 | 21.31% | 1 | 33.33% |
Luis de Bethencourt | 4 | 6.56% | 1 | 33.33% |
Total | 61 | 100.00% | 3 | 100.00% |
MODULE_ALIAS("ppc4xx_rng");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christian Lamparter | 292 | 51.32% | 1 | 25.00% |
Josh Boyer | 270 | 47.45% | 1 | 25.00% |
Luis de Bethencourt | 4 | 0.70% | 1 | 25.00% |
Rob Herring | 3 | 0.53% | 1 | 25.00% |
Total | 569 | 100.00% | 4 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.