diff mbox

[18/23] power/reset: at91-reset: get and use slow clock

Message ID 1438335599-3301-19-git-send-email-alexandre.belloni@free-electrons.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Alexandre Belloni July 31, 2015, 9:39 a.m. UTC
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 reset
controller.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
Cc: Sebastian Reichel <sre@kernel.org>
Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Cc: linux-pm@vger.kernel.org
 drivers/power/reset/at91-reset.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Sebastian Reichel Aug. 5, 2015, 6:22 p.m. UTC | #1
Hi,

On Fri, Jul 31, 2015 at 11:39:54AM +0200, Alexandre Belloni wrote:
> 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 reset
> controller.

You call clk_prepare_enable during probe without a matching
clk_disable_unprepare on module removal.

-- Sebastian
Alexandre Belloni Aug. 10, 2015, 3:50 p.m. UTC | #2
On 05/08/2015 at 20:22:20 +0200, Sebastian Reichel wrote :
> Hi,
> 
> On Fri, Jul 31, 2015 at 11:39:54AM +0200, Alexandre Belloni wrote:
> > 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 reset
> > controller.
> 
> You call clk_prepare_enable during probe without a matching
> clk_disable_unprepare on module removal.
> 

They will never be compiled as modules as the Kconfig option is a bool
so we don't have a .remove and the module will never be removed.

Do you want me to change at91-reset and at91-poweroff to work as
modules?
Sebastian Reichel Aug. 10, 2015, 5:11 p.m. UTC | #3
Hi,

On Mon, Aug 10, 2015 at 05:50:05PM +0200, Alexandre Belloni wrote:
> On 05/08/2015 at 20:22:20 +0200, Sebastian Reichel wrote :
> > On Fri, Jul 31, 2015 at 11:39:54AM +0200, Alexandre Belloni wrote:
> > > 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 reset
> > > controller.
> > 
> > You call clk_prepare_enable during probe without a matching
> > clk_disable_unprepare on module removal.
> 
> They will never be compiled as modules as the Kconfig option is a
> bool so we don't have a .remove and the module will never be removed.

In that case the module_platform_driver() statement at the bottom
should be replaced with builtin_platform_driver().

> Do you want me to change at91-reset and at91-poweroff to work as
> modules?

That would also be fine.

-- Sebastian
diff mbox

Patch

diff --git a/drivers/power/reset/at91-reset.c b/drivers/power/reset/at91-reset.c
index 3225c8590ed0..19fdd4c107dc 100644
--- a/drivers/power/reset/at91-reset.c
+++ b/drivers/power/reset/at91-reset.c
@@ -11,6 +11,7 @@ 
  * warranty of any kind, whether express or implied.
  */
 
+#include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/module.h>
 #include <linux/of_address.h>
@@ -46,6 +47,7 @@  enum reset_type {
 };
 
 static void __iomem *at91_ramc_base[2], *at91_rstc_base;
+static struct clk *sclk;
 
 /*
 * unless the SDRAM is cleanly shutdown before we hit the
@@ -193,9 +195,21 @@  static int at91_reset_probe(struct platform_device *pdev)
 	match = of_match_node(at91_reset_of_match, pdev->dev.of_node);
 	at91_restart_nb.notifier_call = match->data;
 
+	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;
+	}
+
 	ret = register_restart_handler(&at91_restart_nb);
-	if (ret)
+	if (ret) {
+		clk_disable_unprepare(sclk);
 		return ret;
+	}
 
 	at91_reset_status(pdev);