power/reset: vexpress: Fix restart/power off operation
authorPawel Moll <pawel.moll@arm.com>
Thu, 24 Apr 2014 16:19:30 +0000 (17:19 +0100)
committerPawel Moll <pawel.moll@arm.com>
Thu, 24 Apr 2014 16:20:50 +0000 (17:20 +0100)
The restart/power off implementation in the vexpress driver
used to obtain the config function when necessary. This was
wrong in two respects:

1. It required memory allocation with disabled interrupts
(it worked, but lockdep - when enabled - reported warnings).

2. Used jiffies-based timeout, while jiffies are not running
at this stage of system shutdown (therefore a config
transaction error - if happened - would have never be reported).

Fixed by pre-allocating the config function per device
and using mdelay for timeout.

Signed-off-by: Pawel Moll <pawel.moll@arm.com>
drivers/power/reset/vexpress-poweroff.c

index 476aa495c110d5814fdf2e3c4ba331cb026baf4f..b95cf71ed69554e8b7c53d77271ba92e39b1e039 100644 (file)
@@ -11,7 +11,7 @@
  * Copyright (C) 2012 ARM Limited
  */
 
-#include <linux/jiffies.h>
+#include <linux/delay.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
 static void vexpress_reset_do(struct device *dev, const char *what)
 {
        int err = -ENOENT;
-       struct vexpress_config_func *func =
-                       vexpress_config_func_get_by_dev(dev);
+       struct vexpress_config_func *func = dev_get_drvdata(dev);
 
        if (func) {
-               unsigned long timeout;
-
                err = vexpress_config_write(func, 0, 0);
-
-               timeout = jiffies + HZ;
-               while (time_before(jiffies, timeout))
-                       cpu_relax();
+               if (!err)
+                       mdelay(1000);
        }
 
        dev_emerg(dev, "Unable to %s (%d)\n", what, err);
@@ -96,12 +91,18 @@ static int vexpress_reset_probe(struct platform_device *pdev)
        enum vexpress_reset_func func;
        const struct of_device_id *match =
                        of_match_device(vexpress_reset_of_match, &pdev->dev);
+       struct vexpress_config_func *config_func;
 
        if (match)
                func = (enum vexpress_reset_func)match->data;
        else
                func = pdev->id_entry->driver_data;
 
+       config_func = vexpress_config_func_get_by_dev(&pdev->dev);
+       if (!config_func)
+               return -EINVAL;
+       dev_set_drvdata(&pdev->dev, config_func);
+
        switch (func) {
        case FUNC_SHUTDOWN:
                vexpress_power_off_device = &pdev->dev;