Merge tag 'sunxi-dt-for-3.11-2' of git://github.com/mripard/linux into next/dt
[sfrench/cifs-2.6.git] / drivers / clocksource / cadence_ttc_timer.c
index 685bc60e210ad45ae45192376c496e3cfbf73926..4cbe28c74631eaa5ef8df596865db2a92bd02cb7 100644 (file)
@@ -51,6 +51,8 @@
 
 #define TTC_CNT_CNTRL_DISABLE_MASK     0x1
 
+#define TTC_CLK_CNTRL_CSRC_MASK                (1 << 5)        /* clock source */
+
 /*
  * Setup the timers to use pre-scaling, using a fixed value for now that will
  * work across most input frequency, but it may need to be more dynamic
@@ -396,8 +398,9 @@ static void __init ttc_timer_init(struct device_node *timer)
 {
        unsigned int irq;
        void __iomem *timer_baseaddr;
-       struct clk *clk;
+       struct clk *clk_cs, *clk_ce;
        static int initialized;
+       int clksel;
 
        if (initialized)
                return;
@@ -421,14 +424,24 @@ static void __init ttc_timer_init(struct device_node *timer)
                BUG();
        }
 
-       clk = of_clk_get_by_name(timer, "cpu_1x");
-       if (IS_ERR(clk)) {
+       clksel = __raw_readl(timer_baseaddr + TTC_CLK_CNTRL_OFFSET);
+       clksel = !!(clksel & TTC_CLK_CNTRL_CSRC_MASK);
+       clk_cs = of_clk_get(timer, clksel);
+       if (IS_ERR(clk_cs)) {
+               pr_err("ERROR: timer input clock not found\n");
+               BUG();
+       }
+
+       clksel = __raw_readl(timer_baseaddr + 4 + TTC_CLK_CNTRL_OFFSET);
+       clksel = !!(clksel & TTC_CLK_CNTRL_CSRC_MASK);
+       clk_ce = of_clk_get(timer, clksel);
+       if (IS_ERR(clk_ce)) {
                pr_err("ERROR: timer input clock not found\n");
                BUG();
        }
 
-       ttc_setup_clocksource(clk, timer_baseaddr);
-       ttc_setup_clockevent(clk, timer_baseaddr + 4, irq);
+       ttc_setup_clocksource(clk_cs, timer_baseaddr);
+       ttc_setup_clockevent(clk_ce, timer_baseaddr + 4, irq);
 
        pr_info("%s #0 at %p, irq=%d\n", timer->name, timer_baseaddr, irq);
 }