From: Alexander Clouter Date: Sun, 31 Mar 2013 16:34:51 +0000 (+0100) Subject: hwrng: timeriomem - added devicetree hooks X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b149a30d87d165e1079163fdab6f14e48b2f57b2;p=GitHub%2Fmt8127%2Fandroid_kernel_alcatel_ttab.git hwrng: timeriomem - added devicetree hooks This patch allows timeriomem_rng to be used via devicetree. Signed-off-by: Alexander Clouter Signed-off-by: Herbert Xu --- diff --git a/Documentation/devicetree/bindings/hwrng/timeriomem_rng.txt b/Documentation/devicetree/bindings/hwrng/timeriomem_rng.txt new file mode 100644 index 000000000000..6616d15866a3 --- /dev/null +++ b/Documentation/devicetree/bindings/hwrng/timeriomem_rng.txt @@ -0,0 +1,18 @@ +HWRNG support for the timeriomem_rng driver + +Required properties: +- compatible : "timeriomem_rng" +- reg : base address to sample from +- period : wait time in microseconds to use between samples + +N.B. currently 'reg' must be four bytes wide and aligned + +Example: + +hwrng@44 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "timeriomem_rng"; + reg = <0x44 0x04>; + period = <1000000>; +}; diff --git a/drivers/char/hw_random/timeriomem-rng.c b/drivers/char/hw_random/timeriomem-rng.c index 9dd2cadc31bd..3e75737f5fe1 100644 --- a/drivers/char/hw_random/timeriomem-rng.c +++ b/drivers/char/hw_random/timeriomem-rng.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -101,7 +102,7 @@ static int timeriomem_rng_probe(struct platform_device *pdev) int err = 0; int period; - if (!pdata) { + if (!pdev->dev.of_node && !pdata) { dev_err(&pdev->dev, "timeriomem_rng_data is missing\n"); return -EINVAL; } @@ -125,7 +126,19 @@ static int timeriomem_rng_probe(struct platform_device *pdev) platform_set_drvdata(pdev, priv); - period = pdata->period; + if (pdev->dev.of_node) { + int i; + + if (!of_property_read_u32(pdev->dev.of_node, + "period", &i)) + period = i; + else { + dev_err(&pdev->dev, "missing period\n"); + err = -EINVAL; + goto out_free; + } + } else + period = pdata->period; priv->period = usecs_to_jiffies(period); if (priv->period < 1) { @@ -202,10 +215,17 @@ static int timeriomem_rng_remove(struct platform_device *pdev) return 0; } +static const struct of_device_id timeriomem_rng_match[] = { + { .compatible = "timeriomem_rng" }, + {}, +}; +MODULE_DEVICE_TABLE(of, timeriomem_rng_match); + static struct platform_driver timeriomem_rng_driver = { .driver = { .name = "timeriomem_rng", .owner = THIS_MODULE, + .of_match_table = timeriomem_rng_match, }, .probe = timeriomem_rng_probe, .remove = timeriomem_rng_remove,