2019-09-14 23:34:37

by Tony Lindgren

[permalink] [raw]
Subject: [PATCHv2 0/7] Non-urgent fixes and improvments for omap3-rom-rng

Hi all,

Here are fixes and improvments for omap3-rom-rng that's been broken for
a while.

The first four patches get it working, and then the last two patches add
support for runtime PM.

I did not add Sebastian's acks from v1 set as many of the patches
changed. Please review again :)

Regards,

Tony

Changes since v1:
- Use clk_prepare_enable() as pointed out by Sebastian
- Simplify runtime PM changes patch
- Add a new patch for devm changes as suggested by Sebastian


Tony Lindgren (7):
ARM: OMAP2+: Check omap3-rom-rng for GP device instead of HS device
hwrng: omap3-rom - Fix missing clock by probing with device tree
hwrng: omap3-rom - Call clk_disable_unprepare() on exit only if not
idled
hwrng: omap3-rom - Initialize default quality to get data
hwrng: omap3-rom - Update to use standard driver data
hwrng: omap3-rom - Use runtime PM instead of custom functions
hwrng: omap3-rom - Use devm hwrng and runtime PM

.../devicetree/bindings/rng/omap3_rom_rng.txt | 27 +++
arch/arm/boot/dts/omap3-n900.dts | 6 +
arch/arm/mach-omap2/pdata-quirks.c | 14 +-
drivers/char/hw_random/omap3-rom-rng.c | 168 +++++++++++-------
4 files changed, 139 insertions(+), 76 deletions(-)
create mode 100644 Documentation/devicetree/bindings/rng/omap3_rom_rng.txt

--
2.23.0


2019-09-14 23:35:45

by Tony Lindgren

[permalink] [raw]
Subject: [PATCH 2/7] hwrng: omap3-rom - Fix missing clock by probing with device tree

Commit 0ed266d7ae5e ("clk: ti: omap3: cleanup unnecessary clock aliases")
removed old omap3 clock framework aliases but caused omap3-rom-rng to
stop working with clock not found error.

Based on discussions on the mailing list it was requested by Tero Kristo
that it would be best to fix this issue by probing omap3-rom-rng using
device tree to provide a proper clk property. The other option would be
to add back the missing clock alias, but that does not help moving things
forward with removing old legacy platform_data.

Let's also add a proper device tree binding and keep it together with
the fix.

Cc: [email protected]
Cc: Aaro Koskinen <[email protected]>
Cc: Adam Ford <[email protected]>
Cc: Pali Rohár <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: Tero Kristo <[email protected]>
Fixes: 0ed266d7ae5e ("clk: ti: omap3: cleanup unnecessary clock aliases")
Reported-by: Aaro Koskinen <[email protected]>
Signed-off-by: Tony Lindgren <[email protected]>
---
.../devicetree/bindings/rng/omap3_rom_rng.txt | 27 +++++++++++++++++++
arch/arm/boot/dts/omap3-n900.dts | 6 +++++
arch/arm/mach-omap2/pdata-quirks.c | 12 +--------
drivers/char/hw_random/omap3-rom-rng.c | 17 ++++++++++--
4 files changed, 49 insertions(+), 13 deletions(-)
create mode 100644 Documentation/devicetree/bindings/rng/omap3_rom_rng.txt

diff --git a/Documentation/devicetree/bindings/rng/omap3_rom_rng.txt b/Documentation/devicetree/bindings/rng/omap3_rom_rng.txt
new file mode 100644
--- /dev/null
+++ b/Documentation/devicetree/bindings/rng/omap3_rom_rng.txt
@@ -0,0 +1,27 @@
+OMAP ROM RNG driver binding
+
+Secure SoCs may provide RNG via secure ROM calls like Nokia N900 does. The
+implementation can depend on the SoC secure ROM used.
+
+- compatible:
+ Usage: required
+ Value type: <string>
+ Definition: must be "nokia,n900-rom-rng"
+
+- clocks:
+ Usage: required
+ Value type: <prop-encoded-array>
+ Definition: reference to the the RNG interface clock
+
+- clock-names:
+ Usage: required
+ Value type: <stringlist>
+ Definition: must be "ick"
+
+Example:
+
+ rom_rng: rng {
+ compatible = "nokia,n900-rom-rng";
+ clocks = <&rng_ick>;
+ clock-names = "ick";
+ };
diff --git a/arch/arm/boot/dts/omap3-n900.dts b/arch/arm/boot/dts/omap3-n900.dts
--- a/arch/arm/boot/dts/omap3-n900.dts
+++ b/arch/arm/boot/dts/omap3-n900.dts
@@ -155,6 +155,12 @@
pwms = <&pwm9 0 26316 0>; /* 38000 Hz */
};

+ rom_rng: rng {
+ compatible = "nokia,n900-rom-rng";
+ clocks = <&rng_ick>;
+ clock-names = "ick";
+ };
+
/* controlled (enabled/disabled) directly by bcm2048 and wl1251 */
vctcxo: vctcxo {
compatible = "fixed-clock";
diff --git a/arch/arm/mach-omap2/pdata-quirks.c b/arch/arm/mach-omap2/pdata-quirks.c
--- a/arch/arm/mach-omap2/pdata-quirks.c
+++ b/arch/arm/mach-omap2/pdata-quirks.c
@@ -262,14 +262,6 @@ static void __init am3517_evm_legacy_init(void)
am35xx_emac_reset();
}

-static struct platform_device omap3_rom_rng_device = {
- .name = "omap3-rom-rng",
- .id = -1,
- .dev = {
- .platform_data = rx51_secure_rng_call,
- },
-};
-
static void __init nokia_n900_legacy_init(void)
{
hsmmc2_internal_input_clk();
@@ -285,9 +277,6 @@ static void __init nokia_n900_legacy_init(void)
pr_warn("RX-51: Not enabling ARM errata 430973 workaround\n");
pr_warn("Thumb binaries may crash randomly without this workaround\n");
}
-
- pr_info("RX-51: Registering OMAP3 HWRNG device\n");
- platform_device_register(&omap3_rom_rng_device);
}
}

@@ -627,6 +616,7 @@ static struct of_dev_auxdata omap_auxdata_lookup[] = {
OF_DEV_AUXDATA("ti,davinci_mdio", 0x5c030000, "davinci_mdio.0", NULL),
OF_DEV_AUXDATA("ti,am3517-emac", 0x5c000000, "davinci_emac.0",
&am35xx_emac_pdata),
+ OF_DEV_AUXDATA("nokia,n900-rom-rng", 0, NULL, rx51_secure_rng_call),
/* McBSP modules with sidetone core */
#if IS_ENABLED(CONFIG_SND_SOC_OMAP_MCBSP)
OF_DEV_AUXDATA("ti,omap3-mcbsp", 0x49022000, "49022000.mcbsp", &mcbsp_pdata),
diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
--- a/drivers/char/hw_random/omap3-rom-rng.c
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -20,6 +20,8 @@
#include <linux/workqueue.h>
#include <linux/clk.h>
#include <linux/err.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/platform_device.h>

#define RNG_RESET 0x01
@@ -86,14 +88,18 @@ static int omap3_rom_rng_read(struct hwrng *rng, void *data, size_t max, bool w)

static struct hwrng omap3_rom_rng_ops = {
.name = "omap3-rom",
- .read = omap3_rom_rng_read,
};

static int omap3_rom_rng_probe(struct platform_device *pdev)
{
int ret = 0;

- pr_info("initializing\n");
+ omap3_rom_rng_ops.read = of_device_get_match_data(&pdev->dev);
+ if (!omap3_rom_rng_ops.read) {
+ dev_err(&pdev->dev, "missing rom code handler\n");
+
+ return -ENODEV;
+ }

omap3_rom_rng_call = pdev->dev.platform_data;
if (!omap3_rom_rng_call) {
@@ -125,9 +131,16 @@ static int omap3_rom_rng_remove(struct platform_device *pdev)
return 0;
}

+static const struct of_device_id omap_rom_rng_match[] = {
+ { .compatible = "nokia,n900-rom-rng", .data = omap3_rom_rng_read, },
+ { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, omap_rom_rng_match);
+
static struct platform_driver omap3_rom_rng_driver = {
.driver = {
.name = "omap3-rom-rng",
+ .of_match_table = omap_rom_rng_match,
},
.probe = omap3_rom_rng_probe,
.remove = omap3_rom_rng_remove,
--
2.23.0

2019-09-14 23:36:24

by Tony Lindgren

[permalink] [raw]
Subject: [PATCH 1/7] ARM: OMAP2+: Check omap3-rom-rng for GP device instead of HS device

In general we should check for GP device instead of HS device unless
the other options such as EMU are also checked. Otherwise omap3-rom-rng
won't probe on few of the old n900 macro boards still in service in
automated build and boot test systems.

Cc: Aaro Koskinen <[email protected]>
Cc: Adam Ford <[email protected]>
Cc: Pali Rohár <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: Tero Kristo <[email protected]>
Signed-off-by: Tony Lindgren <[email protected]>
---
arch/arm/mach-omap2/pdata-quirks.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap2/pdata-quirks.c b/arch/arm/mach-omap2/pdata-quirks.c
--- a/arch/arm/mach-omap2/pdata-quirks.c
+++ b/arch/arm/mach-omap2/pdata-quirks.c
@@ -276,7 +276,7 @@ static void __init nokia_n900_legacy_init(void)
mmc_pdata[0].name = "external";
mmc_pdata[1].name = "internal";

- if (omap_type() == OMAP2_DEVICE_TYPE_SEC) {
+ if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
if (IS_ENABLED(CONFIG_ARM_ERRATA_430973)) {
pr_info("RX-51: Enabling ARM errata 430973 workaround\n");
/* set IBE to 1 */
--
2.23.0

2019-09-14 23:37:18

by Tony Lindgren

[permalink] [raw]
Subject: [PATCH 4/7] hwrng: omap3-rom - Initialize default quality to get data

Similar to commit 62f95ae805fa ("hwrng: omap - Set default quality")
we need to initialize the default quality for the RNG to be used.

The symptoms of this problem is that doing hd /dev/random does not
produce much data at all.

Cc: Aaro Koskinen <[email protected]>
Cc: Adam Ford <[email protected]>
Cc: Pali Rohár <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: Tero Kristo <[email protected]>
Signed-off-by: Tony Lindgren <[email protected]>
---
drivers/char/hw_random/omap3-rom-rng.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
--- a/drivers/char/hw_random/omap3-rom-rng.c
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -88,6 +88,7 @@ static int omap3_rom_rng_read(struct hwrng *rng, void *data, size_t max, bool w)

static struct hwrng omap3_rom_rng_ops = {
.name = "omap3-rom",
+ .quality = 900,
};

static int omap3_rom_rng_probe(struct platform_device *pdev)
--
2.23.0

2019-09-14 23:37:58

by Tony Lindgren

[permalink] [raw]
Subject: [PATCH 5/7] hwrng: omap3-rom - Update to use standard driver data

Let's update omap3-rom-rng to use standard driver data to make it easier
to add runtime PM support in the following patch. Just use it for the
rng ops and clock for now. Let's still keep also old rng_clk still around,
we will remove delayed work and rng_clk with runtime PM in the next patch.

Cc: Aaro Koskinen <[email protected]>
Cc: Adam Ford <[email protected]>
Cc: Pali Rohár <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: Tero Kristo <[email protected]>
Signed-off-by: Tony Lindgren <[email protected]>
---
drivers/char/hw_random/omap3-rom-rng.c | 45 +++++++++++++++++---------
1 file changed, 30 insertions(+), 15 deletions(-)

diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
--- a/drivers/char/hw_random/omap3-rom-rng.c
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -31,6 +31,12 @@
/* param1: ptr, param2: count, param3: flag */
static u32 (*omap3_rom_rng_call)(u32, u32, u32);

+struct omap_rom_rng {
+ struct clk *clk;
+ struct device *dev;
+ struct hwrng ops;
+};
+
static struct delayed_work idle_work;
static int rng_idle;
static struct clk *rng_clk;
@@ -86,48 +92,57 @@ static int omap3_rom_rng_read(struct hwrng *rng, void *data, size_t max, bool w)
return 4;
}

-static struct hwrng omap3_rom_rng_ops = {
- .name = "omap3-rom",
- .quality = 900,
-};
-
static int omap3_rom_rng_probe(struct platform_device *pdev)
{
+ struct omap_rom_rng *ddata;
int ret = 0;

- omap3_rom_rng_ops.read = of_device_get_match_data(&pdev->dev);
- if (!omap3_rom_rng_ops.read) {
+ ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
+ if (!ddata)
+ return -ENOMEM;
+
+ ddata->dev = &pdev->dev;
+ ddata->ops.priv = (unsigned long)ddata;
+ ddata->ops.name = "omap3-rom";
+ ddata->ops.read = of_device_get_match_data(&pdev->dev);
+ ddata->ops.quality = 900;
+ if (!ddata->ops.read) {
dev_err(&pdev->dev, "missing rom code handler\n");

return -ENODEV;
}
+ dev_set_drvdata(ddata->dev, ddata);

omap3_rom_rng_call = pdev->dev.platform_data;
if (!omap3_rom_rng_call) {
- pr_err("omap3_rom_rng_call is NULL\n");
+ dev_err(ddata->dev, "rom_rng_call is NULL\n");
return -EINVAL;
}

INIT_DELAYED_WORK(&idle_work, omap3_rom_rng_idle);
- rng_clk = devm_clk_get(&pdev->dev, "ick");
- if (IS_ERR(rng_clk)) {
- pr_err("unable to get RNG clock\n");
- return PTR_ERR(rng_clk);
+ ddata->clk = devm_clk_get(ddata->dev, "ick");
+ if (IS_ERR(ddata->clk)) {
+ dev_err(ddata->dev, "unable to get RNG clock\n");
+ return PTR_ERR(ddata->clk);
}
+ rng_clk = ddata->clk;

/* Leave the RNG in reset state. */
- ret = clk_prepare_enable(rng_clk);
+ ret = clk_prepare_enable(ddata->clk);
if (ret)
return ret;
omap3_rom_rng_idle(0);

- return hwrng_register(&omap3_rom_rng_ops);
+ return hwrng_register(&ddata->ops);
}

static int omap3_rom_rng_remove(struct platform_device *pdev)
{
+ struct omap_rom_rng *ddata;
+
+ ddata = dev_get_drvdata(&pdev->dev);
cancel_delayed_work_sync(&idle_work);
- hwrng_unregister(&omap3_rom_rng_ops);
+ hwrng_unregister(&ddata->ops);
if (!rng_idle)
clk_disable_unprepare(rng_clk);
return 0;
--
2.23.0

2019-09-14 23:38:03

by Tony Lindgren

[permalink] [raw]
Subject: [PATCH 6/7] hwrng: omap3-rom - Use runtime PM instead of custom functions

Nowadays we have runtime PM, and we can use it with autosuspend_timeout
to idle things automatically. This allows us to get rid of the custom
PM implementation.

We enable clocks and init RNG in runtime_resume, and reset RNG and
disable clocks in runtime_suspend. And then omap3_rom_rng_read()
becomes very simple and we don't need the old functions for
omap3_rom_rng_idle() and omap3_rom_rng_get_random(). We can now also
get rid of pr_fmt as we're using dev_err instead.

Cc: Aaro Koskinen <[email protected]>
Cc: Adam Ford <[email protected]>
Cc: Pali Rohár <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: Tero Kristo <[email protected]>
Signed-off-by: Tony Lindgren <[email protected]>
---
drivers/char/hw_random/omap3-rom-rng.c | 126 ++++++++++++++-----------
1 file changed, 73 insertions(+), 53 deletions(-)

diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
--- a/drivers/char/hw_random/omap3-rom-rng.c
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -11,8 +11,6 @@
* warranty of any kind, whether express or implied.
*/

-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
#include <linux/module.h>
#include <linux/init.h>
#include <linux/random.h>
@@ -23,73 +21,83 @@
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>

#define RNG_RESET 0x01
#define RNG_GEN_PRNG_HW_INIT 0x02
#define RNG_GEN_HW 0x08

-/* param1: ptr, param2: count, param3: flag */
-static u32 (*omap3_rom_rng_call)(u32, u32, u32);
-
struct omap_rom_rng {
struct clk *clk;
struct device *dev;
struct hwrng ops;
+ u32 (*rom_rng_call)(u32 ptr, u32 count, u32 flag);
};

-static struct delayed_work idle_work;
-static int rng_idle;
-static struct clk *rng_clk;
-
-static void omap3_rom_rng_idle(struct work_struct *work)
+static int omap3_rom_rng_read(struct hwrng *rng, void *data, size_t max, bool w)
{
+ struct omap_rom_rng *ddata;
+ u32 ptr;
int r;

- r = omap3_rom_rng_call(0, 0, RNG_RESET);
- if (r != 0) {
- pr_err("reset failed: %d\n", r);
- return;
+ ddata = (struct omap_rom_rng *)rng->priv;
+
+ r = pm_runtime_get_sync(ddata->dev);
+ if (r < 0) {
+ pm_runtime_put_noidle(ddata->dev);
+
+ return r;
}
- clk_disable_unprepare(rng_clk);
- rng_idle = 1;
+
+ ptr = virt_to_phys(data);
+ r = ddata->rom_rng_call(ptr, 4, RNG_GEN_HW);
+ if (r != 0)
+ r = -EINVAL;
+ else
+ r = 4;
+
+ pm_runtime_mark_last_busy(ddata->dev);
+ pm_runtime_put_autosuspend(ddata->dev);
+
+ return r;
}

-static int omap3_rom_rng_get_random(void *buf, unsigned int count)
+static int omap_rom_rng_runtime_suspend(struct device *dev)
{
- u32 r;
- u32 ptr;
+ struct omap_rom_rng *ddata;
+ int r;

- cancel_delayed_work_sync(&idle_work);
- if (rng_idle) {
- r = clk_prepare_enable(rng_clk);
- if (r)
- return r;
-
- r = omap3_rom_rng_call(0, 0, RNG_GEN_PRNG_HW_INIT);
- if (r != 0) {
- clk_disable_unprepare(rng_clk);
- pr_err("HW init failed: %d\n", r);
- return -EIO;
- }
- rng_idle = 0;
- }
+ ddata = dev_get_drvdata(dev);

- ptr = virt_to_phys(buf);
- r = omap3_rom_rng_call(ptr, count, RNG_GEN_HW);
- schedule_delayed_work(&idle_work, msecs_to_jiffies(500));
+ r = ddata->rom_rng_call(0, 0, RNG_RESET);
if (r != 0)
- return -EINVAL;
+ dev_err(dev, "reset failed: %d\n", r);
+
+ clk_disable_unprepare(ddata->clk);
+
return 0;
}

-static int omap3_rom_rng_read(struct hwrng *rng, void *data, size_t max, bool w)
+static int omap_rom_rng_runtime_resume(struct device *dev)
{
+ struct omap_rom_rng *ddata;
int r;

- r = omap3_rom_rng_get_random(data, 4);
+ ddata = dev_get_drvdata(dev);
+
+ r = clk_prepare_enable(ddata->clk);
if (r < 0)
return r;
- return 4;
+
+ r = ddata->rom_rng_call(0, 0, RNG_GEN_PRNG_HW_INIT);
+ if (r != 0) {
+ clk_disable(ddata->clk);
+ dev_err(dev, "HW init failed: %d\n", r);
+
+ return -EIO;
+ }
+
+ return 0;
}

static int omap3_rom_rng_probe(struct platform_device *pdev)
@@ -113,27 +121,33 @@ static int omap3_rom_rng_probe(struct platform_device *pdev)
}
dev_set_drvdata(ddata->dev, ddata);

- omap3_rom_rng_call = pdev->dev.platform_data;
- if (!omap3_rom_rng_call) {
+ ddata->rom_rng_call = pdev->dev.platform_data;
+ if (!ddata->rom_rng_call) {
dev_err(ddata->dev, "rom_rng_call is NULL\n");
return -EINVAL;
}

- INIT_DELAYED_WORK(&idle_work, omap3_rom_rng_idle);
ddata->clk = devm_clk_get(ddata->dev, "ick");
if (IS_ERR(ddata->clk)) {
dev_err(ddata->dev, "unable to get RNG clock\n");
return PTR_ERR(ddata->clk);
}
- rng_clk = ddata->clk;

- /* Leave the RNG in reset state. */
- ret = clk_prepare_enable(ddata->clk);
- if (ret)
- return ret;
- omap3_rom_rng_idle(0);
+ pm_runtime_enable(ddata->dev);
+
+ ret = hwrng_register(&ddata->ops);
+ if (!ret)
+ goto err_disable;
+
+ pm_runtime_set_autosuspend_delay(ddata->dev, 500);
+ pm_runtime_use_autosuspend(ddata->dev);
+
+ return 0;

- return hwrng_register(&ddata->ops);
+err_disable:
+ pm_runtime_disable(ddata->dev);
+
+ return ret;
}

static int omap3_rom_rng_remove(struct platform_device *pdev)
@@ -141,10 +155,10 @@ static int omap3_rom_rng_remove(struct platform_device *pdev)
struct omap_rom_rng *ddata;

ddata = dev_get_drvdata(&pdev->dev);
- cancel_delayed_work_sync(&idle_work);
hwrng_unregister(&ddata->ops);
- if (!rng_idle)
- clk_disable_unprepare(rng_clk);
+ pm_runtime_dont_use_autosuspend(ddata->dev);
+ pm_runtime_disable(ddata->dev);
+
return 0;
}

@@ -154,10 +168,16 @@ static const struct of_device_id omap_rom_rng_match[] = {
};
MODULE_DEVICE_TABLE(of, omap_rom_rng_match);

+static const struct dev_pm_ops omap_rom_rng_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(omap_rom_rng_runtime_suspend,
+ omap_rom_rng_runtime_resume)
+};
+
static struct platform_driver omap3_rom_rng_driver = {
.driver = {
.name = "omap3-rom-rng",
.of_match_table = omap_rom_rng_match,
+ .pm = &omap_rom_rng_pm_ops,
},
.probe = omap3_rom_rng_probe,
.remove = omap3_rom_rng_remove,
--
2.23.0

2019-09-14 23:40:34

by Tony Lindgren

[permalink] [raw]
Subject: [PATCH 7/7] hwrng: omap3-rom - Use devm hwrng and runtime PM

This allows us to simplify things more for probe and exit.

Cc: Aaro Koskinen <[email protected]>
Cc: Adam Ford <[email protected]>
Cc: Pali Rohár <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: Tero Kristo <[email protected]>
Suggested-by: Sebastian Reichel <[email protected]>
Signed-off-by: Tony Lindgren <[email protected]>
---
drivers/char/hw_random/omap3-rom-rng.c | 42 ++++++++++----------------
1 file changed, 16 insertions(+), 26 deletions(-)

diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
--- a/drivers/char/hw_random/omap3-rom-rng.c
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -100,6 +100,14 @@ static int omap_rom_rng_runtime_resume(struct device *dev)
return 0;
}

+static void omap_rom_rng_finish(void *data)
+{
+ struct omap_rom_rng *ddata = data;
+
+ pm_runtime_dont_use_autosuspend(ddata->dev);
+ pm_runtime_disable(ddata->dev);
+}
+
static int omap3_rom_rng_probe(struct platform_device *pdev)
{
struct omap_rom_rng *ddata;
@@ -133,33 +141,16 @@ static int omap3_rom_rng_probe(struct platform_device *pdev)
return PTR_ERR(ddata->clk);
}

- pm_runtime_enable(ddata->dev);
-
- ret = hwrng_register(&ddata->ops);
- if (!ret)
- goto err_disable;
-
- pm_runtime_set_autosuspend_delay(ddata->dev, 500);
- pm_runtime_use_autosuspend(ddata->dev);
-
- return 0;
-
-err_disable:
- pm_runtime_disable(ddata->dev);
-
- return ret;
-}
-
-static int omap3_rom_rng_remove(struct platform_device *pdev)
-{
- struct omap_rom_rng *ddata;
+ pm_runtime_enable(&pdev->dev);
+ pm_runtime_set_autosuspend_delay(&pdev->dev, 500);
+ pm_runtime_use_autosuspend(&pdev->dev);

- ddata = dev_get_drvdata(&pdev->dev);
- hwrng_unregister(&ddata->ops);
- pm_runtime_dont_use_autosuspend(ddata->dev);
- pm_runtime_disable(ddata->dev);
+ ret = devm_add_action_or_reset(ddata->dev, omap_rom_rng_finish,
+ ddata);
+ if (ret)
+ return ret;

- return 0;
+ return devm_hwrng_register(ddata->dev, &ddata->ops);
}

static const struct of_device_id omap_rom_rng_match[] = {
@@ -180,7 +171,6 @@ static struct platform_driver omap3_rom_rng_driver = {
.pm = &omap_rom_rng_pm_ops,
},
.probe = omap3_rom_rng_probe,
- .remove = omap3_rom_rng_remove,
};

module_platform_driver(omap3_rom_rng_driver);
--
2.23.0

2019-09-16 07:40:06

by Tero Kristo

[permalink] [raw]
Subject: Re: [PATCHv2 0/7] Non-urgent fixes and improvments for omap3-rom-rng

On 15/09/2019 00:02, Tony Lindgren wrote:
> Hi all,
>
> Here are fixes and improvments for omap3-rom-rng that's been broken for
> a while.
>
> The first four patches get it working, and then the last two patches add
> support for runtime PM.
>
> I did not add Sebastian's acks from v1 set as many of the patches
> changed. Please review again :)

Series looks fine to me also, don't have possibility to test omap3 ROM
RNG though (don't have HW for this.) For the whole series:

Reviewed-by: Tero Kristo <[email protected]>



> Regards,
>
> Tony
>
> Changes since v1:
> - Use clk_prepare_enable() as pointed out by Sebastian
> - Simplify runtime PM changes patch
> - Add a new patch for devm changes as suggested by Sebastian
>
>
> Tony Lindgren (7):
> ARM: OMAP2+: Check omap3-rom-rng for GP device instead of HS device
> hwrng: omap3-rom - Fix missing clock by probing with device tree
> hwrng: omap3-rom - Call clk_disable_unprepare() on exit only if not
> idled
> hwrng: omap3-rom - Initialize default quality to get data
> hwrng: omap3-rom - Update to use standard driver data
> hwrng: omap3-rom - Use runtime PM instead of custom functions
> hwrng: omap3-rom - Use devm hwrng and runtime PM
>
> .../devicetree/bindings/rng/omap3_rom_rng.txt | 27 +++
> arch/arm/boot/dts/omap3-n900.dts | 6 +
> arch/arm/mach-omap2/pdata-quirks.c | 14 +-
> drivers/char/hw_random/omap3-rom-rng.c | 168 +++++++++++-------
> 4 files changed, 139 insertions(+), 76 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/rng/omap3_rom_rng.txt
>

--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

2019-09-16 21:42:09

by Sebastian Reichel

[permalink] [raw]
Subject: Re: [PATCHv2 0/7] Non-urgent fixes and improvments for omap3-rom-rng

Hi,

On Sat, Sep 14, 2019 at 02:02:53PM -0700, Tony Lindgren wrote:
> Hi all,
>
> Here are fixes and improvments for omap3-rom-rng that's been broken for
> a while.
>
> The first four patches get it working, and then the last two patches add
> support for runtime PM.
>
> I did not add Sebastian's acks from v1 set as many of the patches
> changed. Please review again :)
>
> Regards,
>
> Tony
>
> Changes since v1:
> - Use clk_prepare_enable() as pointed out by Sebastian
> - Simplify runtime PM changes patch
> - Add a new patch for devm changes as suggested by Sebastian
>
>
> Tony Lindgren (7):
> ARM: OMAP2+: Check omap3-rom-rng for GP device instead of HS device
> hwrng: omap3-rom - Fix missing clock by probing with device tree
> hwrng: omap3-rom - Call clk_disable_unprepare() on exit only if not
> idled
> hwrng: omap3-rom - Initialize default quality to get data
> hwrng: omap3-rom - Update to use standard driver data
> hwrng: omap3-rom - Use runtime PM instead of custom functions
> hwrng: omap3-rom - Use devm hwrng and runtime PM
>
> .../devicetree/bindings/rng/omap3_rom_rng.txt | 27 +++
> arch/arm/boot/dts/omap3-n900.dts | 6 +
> arch/arm/mach-omap2/pdata-quirks.c | 14 +-
> drivers/char/hw_random/omap3-rom-rng.c | 168 +++++++++++-------
> 4 files changed, 139 insertions(+), 76 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/rng/omap3_rom_rng.txt

For the series:

Reviewed-by: Sebastian Reichel <[email protected]>

-- Sebastian


Attachments:
(No filename) (1.56 kB)
signature.asc (849.00 B)
Download all attachments

2019-09-16 22:03:09

by Aaro Koskinen

[permalink] [raw]
Subject: Re: [PATCHv2 0/7] Non-urgent fixes and improvments for omap3-rom-rng

Hi,

On Sat, Sep 14, 2019 at 02:02:53PM -0700, Tony Lindgren wrote:
> Here are fixes and improvments for omap3-rom-rng that's been broken for
> a while.

Thanks, for the whole series:

Tested-by: Aaro Koskinen <[email protected]>

A.

2019-10-04 16:06:08

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCHv2 0/7] Non-urgent fixes and improvments for omap3-rom-rng

On Sat, Sep 14, 2019 at 02:02:53PM -0700, Tony Lindgren wrote:
> Hi all,
>
> Here are fixes and improvments for omap3-rom-rng that's been broken for
> a while.
>
> The first four patches get it working, and then the last two patches add
> support for runtime PM.
>
> I did not add Sebastian's acks from v1 set as many of the patches
> changed. Please review again :)
>
> Regards,
>
> Tony
>
> Changes since v1:
> - Use clk_prepare_enable() as pointed out by Sebastian
> - Simplify runtime PM changes patch
> - Add a new patch for devm changes as suggested by Sebastian
>
>
> Tony Lindgren (7):
> ARM: OMAP2+: Check omap3-rom-rng for GP device instead of HS device
> hwrng: omap3-rom - Fix missing clock by probing with device tree
> hwrng: omap3-rom - Call clk_disable_unprepare() on exit only if not
> idled
> hwrng: omap3-rom - Initialize default quality to get data
> hwrng: omap3-rom - Update to use standard driver data
> hwrng: omap3-rom - Use runtime PM instead of custom functions
> hwrng: omap3-rom - Use devm hwrng and runtime PM
>
> .../devicetree/bindings/rng/omap3_rom_rng.txt | 27 +++
> arch/arm/boot/dts/omap3-n900.dts | 6 +
> arch/arm/mach-omap2/pdata-quirks.c | 14 +-
> drivers/char/hw_random/omap3-rom-rng.c | 168 +++++++++++-------
> 4 files changed, 139 insertions(+), 76 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/rng/omap3_rom_rng.txt

All applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt