forked from Minki/linux
e6b5be2be4
Here's the set of driver core patches for 3.19-rc1. They are dominated by the removal of the .owner field in platform drivers. They touch a lot of files, but they are "simple" changes, just removing a line in a structure. Other than that, a few minor driver core and debugfs changes. There are some ath9k patches coming in through this tree that have been acked by the wireless maintainers as they relied on the debugfs changes. Everything has been in linux-next for a while. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEABECAAYFAlSOD20ACgkQMUfUDdst+ylLPACg2QrW1oHhdTMT9WI8jihlHVRM 53kAoLeteByQ3iVwWurwwseRPiWa8+MI =OVRS -----END PGP SIGNATURE----- Merge tag 'driver-core-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core Pull driver core update from Greg KH: "Here's the set of driver core patches for 3.19-rc1. They are dominated by the removal of the .owner field in platform drivers. They touch a lot of files, but they are "simple" changes, just removing a line in a structure. Other than that, a few minor driver core and debugfs changes. There are some ath9k patches coming in through this tree that have been acked by the wireless maintainers as they relied on the debugfs changes. Everything has been in linux-next for a while" * tag 'driver-core-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (324 commits) Revert "ath: ath9k: use debugfs_create_devm_seqfile() helper for seq_file entries" fs: debugfs: add forward declaration for struct device type firmware class: Deletion of an unnecessary check before the function call "vunmap" firmware loader: fix hung task warning dump devcoredump: provide a one-way disable function device: Add dev_<level>_once variants ath: ath9k: use debugfs_create_devm_seqfile() helper for seq_file entries ath: use seq_file api for ath9k debugfs files debugfs: add helper function to create device related seq_file drivers/base: cacheinfo: remove noisy error boot message Revert "core: platform: add warning if driver has no owner" drivers: base: support cpu cache information interface to userspace via sysfs drivers: base: add cpu_device_create to support per-cpu devices topology: replace custom attribute macros with standard DEVICE_ATTR* cpumask: factor out show_cpumap into separate helper function driver core: Fix unbalanced device reference in drivers_probe driver core: fix race with userland in device_add() sysfs/kernfs: make read requests on pre-alloc files use the buffer. sysfs/kernfs: allow attributes to request write buffer be pre-allocated. fs: sysfs: return EGBIG on write if offset is larger than file size ...
149 lines
3.3 KiB
C
149 lines
3.3 KiB
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;
|
|
}
|
|
|
|
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;
|
|
|
|
writel(TRNG_KEY | 1, trng->base + TRNG_CR);
|
|
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(trng->clk);
|
|
return ret;
|
|
}
|
|
|
|
static int atmel_trng_remove(struct platform_device *pdev)
|
|
{
|
|
struct atmel_trng *trng = platform_get_drvdata(pdev);
|
|
|
|
hwrng_unregister(&trng->rng);
|
|
|
|
writel(TRNG_KEY, trng->base + TRNG_CR);
|
|
clk_disable_unprepare(trng->clk);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_PM
|
|
static int atmel_trng_suspend(struct device *dev)
|
|
{
|
|
struct atmel_trng *trng = dev_get_drvdata(dev);
|
|
|
|
clk_disable_unprepare(trng->clk);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int atmel_trng_resume(struct device *dev)
|
|
{
|
|
struct atmel_trng *trng = dev_get_drvdata(dev);
|
|
|
|
return clk_prepare_enable(trng->clk);
|
|
}
|
|
|
|
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");
|