clk: ti: add a usecount for autoidle
authorAndreas Kemnade <andreas@kemnade.info>
Wed, 16 Jan 2019 22:04:27 +0000 (23:04 +0100)
committerTero Kristo <t-kristo@ti.com>
Fri, 15 Feb 2019 14:47:55 +0000 (16:47 +0200)
Multiple users might deny autoidle on a clock. So we should have some
counting here, also according to the comment in  _setup_iclk_autoidle().
Also setting autoidle regs is not atomic, so there is another reason
for locking.

Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
Acked-by: Tony Lindgren <tony@atomide.com>
Tested-by: Keerthy <j-keerthy@ti.com>
Signed-off-by: Tero Kristo <t-kristo@ti.com>
drivers/clk/ti/autoidle.c
include/linux/clk/ti.h

index a129b4b36ea3bcd66e643d1dffab5835c851054c..964e97b5478a6edcefb66e1dfb3d027c4f351fce 100644 (file)
@@ -36,17 +36,41 @@ struct clk_ti_autoidle {
 
 static LIST_HEAD(autoidle_clks);
 
+/*
+ * we have some non-atomic read/write
+ * operations behind it, so lets
+ * take one lock for handling autoidle
+ * of all clocks
+ */
+static DEFINE_SPINLOCK(autoidle_spinlock);
+
 static int _omap2_clk_deny_idle(struct clk_hw_omap *clk)
 {
-       if (clk->ops && clk->ops->deny_idle)
-               clk->ops->deny_idle(clk);
+       if (clk->ops && clk->ops->deny_idle) {
+               unsigned long irqflags;
+
+               spin_lock_irqsave(&autoidle_spinlock, irqflags);
+               clk->autoidle_count++;
+               if (clk->autoidle_count == 1)
+                       clk->ops->deny_idle(clk);
+
+               spin_unlock_irqrestore(&autoidle_spinlock, irqflags);
+       }
        return 0;
 }
 
 static int _omap2_clk_allow_idle(struct clk_hw_omap *clk)
 {
-       if (clk->ops && clk->ops->allow_idle)
-               clk->ops->allow_idle(clk);
+       if (clk->ops && clk->ops->allow_idle) {
+               unsigned long irqflags;
+
+               spin_lock_irqsave(&autoidle_spinlock, irqflags);
+               clk->autoidle_count--;
+               if (clk->autoidle_count == 0)
+                       clk->ops->allow_idle(clk);
+
+               spin_unlock_irqrestore(&autoidle_spinlock, irqflags);
+       }
        return 0;
 }
 
index eacc5df57b99fd28cba56081e03f8fa0cccf576b..78872efc7be09fa9cd16e090ef17ae998cac06e1 100644 (file)
@@ -160,6 +160,7 @@ struct clk_hw_omap {
        struct clockdomain      *clkdm;
        const struct clk_hw_omap_ops    *ops;
        u32                     context;
+       int                     autoidle_count;
 };
 
 /*