Merge branch 'semaphore' of git://git.kernel.org/pub/scm/linux/kernel/git/willy/misc
[sfrench/cifs-2.6.git] / arch / arm / plat-omap / clock.c
index 7f45c7c3e673d1898902fbac743de5e7cb655fd8..72d34a23a2ec6276073af8906e916075b6808945 100644 (file)
@@ -23,7 +23,6 @@
 #include <linux/platform_device.h>
 
 #include <asm/io.h>
-#include <asm/semaphore.h>
 
 #include <asm/arch/clock.h>
 
@@ -33,6 +32,41 @@ static DEFINE_SPINLOCK(clockfw_lock);
 
 static struct clk_functions *arch_clock;
 
+#ifdef CONFIG_PM_DEBUG
+
+static void print_parents(struct clk *clk)
+{
+       struct clk *p;
+       int printed = 0;
+
+       list_for_each_entry(p, &clocks, node) {
+               if (p->parent == clk && p->usecount) {
+                       if (!clk->usecount && !printed) {
+                               printk("MISMATCH: %s\n", clk->name);
+                               printed = 1;
+                       }
+                       printk("\t%-15s\n", p->name);
+               }
+       }
+}
+
+void clk_print_usecounts(void)
+{
+       unsigned long flags;
+       struct clk *p;
+
+       spin_lock_irqsave(&clockfw_lock, flags);
+       list_for_each_entry(p, &clocks, node) {
+               if (p->usecount)
+                       printk("%-15s: %d\n", p->name, p->usecount);
+               print_parents(p);
+
+       }
+       spin_unlock_irqrestore(&clockfw_lock, flags);
+}
+
+#endif
+
 /*-------------------------------------------------------------------------
  * Standard clock functions defined in include/linux/clk.h
  *-------------------------------------------------------------------------*/
@@ -100,6 +134,7 @@ void clk_disable(struct clk *clk)
                return;
 
        spin_lock_irqsave(&clockfw_lock, flags);
+       BUG_ON(clk->usecount == 0);
        if (arch_clock->clk_disable)
                arch_clock->clk_disable(clk);
        spin_unlock_irqrestore(&clockfw_lock, flags);
@@ -248,6 +283,8 @@ void followparent_recalc(struct clk *clk)
                return;
 
        clk->rate = clk->parent->rate;
+       if (unlikely(clk->flags & RATE_PROPAGATES))
+               propagate_rate(clk);
 }
 
 /* Propagate rate to children */
@@ -266,6 +303,23 @@ void propagate_rate(struct clk * tclk)
        }
 }
 
+/**
+ * recalculate_root_clocks - recalculate and propagate all root clocks
+ *
+ * Recalculates all root clocks (clocks with no parent), which if the
+ * clock's .recalc is set correctly, should also propagate their rates.
+ * Called at init.
+ */
+void recalculate_root_clocks(void)
+{
+       struct clk *clkp;
+
+       list_for_each_entry(clkp, &clocks, node) {
+               if (unlikely(!clkp->parent) && likely((u32)clkp->recalc))
+                       clkp->recalc(clkp);
+       }
+}
+
 int clk_register(struct clk *clk)
 {
        if (clk == NULL || IS_ERR(clk))
@@ -320,8 +374,57 @@ void clk_allow_idle(struct clk *clk)
 }
 EXPORT_SYMBOL(clk_allow_idle);
 
+void clk_enable_init_clocks(void)
+{
+       struct clk *clkp;
+
+       list_for_each_entry(clkp, &clocks, node) {
+               if (clkp->flags & ENABLE_ON_INIT)
+                       clk_enable(clkp);
+       }
+}
+EXPORT_SYMBOL(clk_enable_init_clocks);
+
+#ifdef CONFIG_CPU_FREQ
+void clk_init_cpufreq_table(struct cpufreq_frequency_table **table)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&clockfw_lock, flags);
+       if (arch_clock->clk_init_cpufreq_table)
+               arch_clock->clk_init_cpufreq_table(table);
+       spin_unlock_irqrestore(&clockfw_lock, flags);
+}
+EXPORT_SYMBOL(clk_init_cpufreq_table);
+#endif
+
 /*-------------------------------------------------------------------------*/
 
+#ifdef CONFIG_OMAP_RESET_CLOCKS
+/*
+ * Disable any unused clocks left on by the bootloader
+ */
+static int __init clk_disable_unused(void)
+{
+       struct clk *ck;
+       unsigned long flags;
+
+       list_for_each_entry(ck, &clocks, node) {
+               if (ck->usecount > 0 || (ck->flags & ALWAYS_ENABLED) ||
+                       ck->enable_reg == 0)
+                       continue;
+
+               spin_lock_irqsave(&clockfw_lock, flags);
+               if (arch_clock->clk_disable_unused)
+                       arch_clock->clk_disable_unused(ck);
+               spin_unlock_irqrestore(&clockfw_lock, flags);
+       }
+
+       return 0;
+}
+late_initcall(clk_disable_unused);
+#endif
+
 int __init clk_init(struct clk_functions * custom_clocks)
 {
        if (!custom_clocks) {
@@ -333,3 +436,4 @@ int __init clk_init(struct clk_functions * custom_clocks)
 
        return 0;
 }
+