power/reset: at91-poweroff: get and use slow clock
authorAlexandre Belloni <alexandre.belloni@free-electrons.com>
Tue, 11 Aug 2015 09:12:50 +0000 (11:12 +0200)
committerSebastian Reichel <sre@kernel.org>
Tue, 22 Sep 2015 13:18:53 +0000 (15:18 +0200)
Commit dca1a4b5ff6e ("clk: at91: keep slow clk enabled to prevent system
hang") added a workaround for the slow clock as it is not properly handled
by its users.

Get and use the slow clock as it is necessary for the at91 shutdown
controller.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
drivers/power/reset/at91-poweroff.c

index 3e698d916c4f32a8a6a09be27662592ad96bd4df..e9e24df35f26bd8ecc68f92dac8cd2a5f26145f5 100644 (file)
@@ -10,6 +10,7 @@
  * warranty of any kind, whether express or implied.
  */
 
+#include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/module.h>
 #include <linux/of.h>
@@ -48,6 +49,7 @@ static const char *shdwc_wakeup_modes[] = {
 };
 
 static void __iomem *at91_shdwc_base;
+static struct clk *sclk;
 
 static void __init at91_wakeup_status(void)
 {
@@ -122,6 +124,7 @@ static void at91_poweroff_dt_set_wakeup_mode(struct platform_device *pdev)
 static int __init at91_poweroff_probe(struct platform_device *pdev)
 {
        struct resource *res;
+       int ret;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        at91_shdwc_base = devm_ioremap_resource(&pdev->dev, res);
@@ -130,6 +133,16 @@ static int __init at91_poweroff_probe(struct platform_device *pdev)
                return PTR_ERR(at91_shdwc_base);
        }
 
+       sclk = devm_clk_get(&pdev->dev, NULL);
+       if (IS_ERR(sclk))
+               return PTR_ERR(sclk);
+
+       ret = clk_prepare_enable(sclk);
+       if (ret) {
+               dev_err(&pdev->dev, "Could not enable slow clock\n");
+               return ret;
+       }
+
        at91_wakeup_status();
 
        if (pdev->dev.of_node)
@@ -145,6 +158,8 @@ static int __exit at91_poweroff_remove(struct platform_device *pdev)
        if (pm_power_off == at91_poweroff)
                pm_power_off = NULL;
 
+       clk_disable_unprepare(sclk);
+
        return 0;
 }