Skip to contentSkip to conversation

ARM timer clock api support

PATCH Superseded Rob Herring 3 participants 13 messages Mar 8, 2011 – Mar 15, 2011

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover ARM timer clock api support

From: Rob Herring <[email protected]>

This patch series converts ARM sp804 timer and smp_twd timer to use the clock api.

v3: Rebased to rmk's init_early clock init changes.

Applies to rmk's for-next branch.

Rob Herring (7):
ARM: integrator cp: add sp804 clock
ARM: realview: add sp804 clock
ARM: versatile: add sp804 clock
ARM: vexpress: add sp804 clock
ARM: timer-sp: support timer clock freq other than 1MHz
ARM: smp_twd: add clock api support
ARM: vexpress: add smp_twd clock

 arch/arm/common/timer-sp.c               |   43 +++++++++++++++++++++---------
 arch/arm/include/asm/hardware/timer-sp.h |    4 +-
 arch/arm/include/asm/smp_twd.h           |    1 +
 arch/arm/kernel/smp_twd.c                |   14 +++++++++
 arch/arm/mach-integrator/integrator_cp.c |   12 ++++++--
 arch/arm/mach-realview/core.c            |   11 ++++++-
 arch/arm/mach-versatile/core.c           |   11 ++++++-
 arch/arm/mach-vexpress/ct-ca9x4.c        |   14 ++++++---
 arch/arm/mach-vexpress/v2m.c             |   11 ++++++-
 9 files changed, 92 insertions(+), 29 deletions(-)
#1 lore raw

PATCH v3 1/7 ARM: integrator cp: add sp804 clock

From: Rob Herring <[email protected]>

Add a clock for sp804 timer.

---
 arch/arm/mach-integrator/integrator_cp.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
arch/arm/mach-integrator/integrator_cp.c +7 -1
index 9e3ce26..a9cec65 100644
@@ -228,12 +228,18 @@ static struct clk cp_auxclk = {
 	.params	= &cp_auxvco_params,
 	.vcoreg	= CM_AUXOSC,
 };
+static struct clk sp804_clk = {
+	.rate = 1000000,
+};
 
 static struct clk_lookup cp_lookups[] = {
 	{	/* CLCD */
 		.dev_id		= "mb:c0",
 		.clk		= &cp_auxclk,
-	},
+	}, {	/* SP804 Timer */
+		.dev_id		= "sp804",
+		.clk		= &sp804_clk,
+	}
 };
 
 /*
Signature · 1 line
1.7.1
#2 lore raw

PATCH v3 2/7 ARM: realview: add sp804 clock

In reply to Rob Herring

From: Rob Herring <[email protected]>

Add a clock for sp804 timer.

---
 arch/arm/mach-realview/core.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
arch/arm/mach-realview/core.c +7 -0
index 75dbc87..ee07755 100644
@@ -315,6 +315,10 @@ static struct clk ref24_clk = {
 	.rate	= 24000000,
 };
 
+static struct clk sp804_clk = {
+	.rate	= 1000000,
+};
+
 static struct clk dummy_apb_pclk;
 
 static struct clk_lookup lookups[] = {
@@ -357,6 +361,9 @@ static struct clk_lookup lookups[] = {
 	}, {	/* SSP */
 		.dev_id		= "dev:ssp0",
 		.clk		= &ref24_clk,
+	}, {	/* SP804 Timer */
+		.dev_id		= "sp804",
+		.clk		= &sp804_clk,
 	}
 };
 
Signature · 1 line
1.7.1
#3 lore raw

PATCH v3 3/7 ARM: versatile: add sp804 clock

In reply to Rob Herring

From: Rob Herring <[email protected]>

Add a clock for sp804 timer.

---
 arch/arm/mach-versatile/core.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
arch/arm/mach-versatile/core.c +7 -0
index eb7ffa0..e9c5a17 100644
@@ -375,6 +375,10 @@ static struct clk ref24_clk = {
 	.rate	= 24000000,
 };
 
+static struct clk sp804_clk = {
+	.rate	= 1000000,
+};
+
 static struct clk dummy_apb_pclk;
 
 static struct clk_lookup lookups[] = {
@@ -411,6 +415,9 @@ static struct clk_lookup lookups[] = {
 	}, {	/* CLCD */
 		.dev_id		= "dev:20",
 		.clk		= &osc4_clk,
+	}, {	/* SP804 Timer */
+		.dev_id		= "sp804",
+		.clk		= &sp804_clk,
 	}
 };
 
Signature · 1 line
1.7.1
#4 lore raw

PATCH v3 4/7 ARM: vexpress: add sp804 clock

In reply to Rob Herring

From: Rob Herring <[email protected]>

Add a clock for sp804 timer.

---
 arch/arm/mach-vexpress/ct-ca9x4.c |    4 ++--
 arch/arm/mach-vexpress/v2m.c      |    7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)
arch/arm/mach-vexpress/ct-ca9x4.c +2 -2
index 30d5a5b..3528b1a 100644
@@ -73,8 +73,8 @@ static void __init ct_ca9x4_timer_init(void)
 	writel(0, MMIO_P2V(CT_CA9X4_TIMER0) + TIMER_CTRL);
 	writel(0, MMIO_P2V(CT_CA9X4_TIMER1) + TIMER_CTRL);
 
-	sp804_clocksource_init(MMIO_P2V(CT_CA9X4_TIMER1));
-	sp804_clockevents_init(MMIO_P2V(CT_CA9X4_TIMER0), IRQ_CT_CA9X4_TIMER0);
+	sp804_clocksource_init(MMIO_P2V(CT_CA9X4_TIMER1), NULL);
+	sp804_clockevents_init(MMIO_P2V(CT_CA9X4_TIMER0), IRQ_CT_CA9X4_TIMER0, NULL);
 }
 
 static struct sys_timer ct_ca9x4_timer = {
arch/arm/mach-vexpress/v2m.c +7 -0
index 63ef663..c056259 100644
@@ -335,6 +335,10 @@ static struct clk osc2_clk = {
 	.rate	= 24000000,
 };
 
+static struct clk sp804_clk = {
+	.rate	= 1000000,
+};
+
 static struct clk dummy_apb_pclk;
 
 static struct clk_lookup v2m_lookups[] = {
@@ -365,6 +369,9 @@ static struct clk_lookup v2m_lookups[] = {
 	}, {	/* CLCD */
 		.dev_id		= "mb:clcd",
 		.clk		= &osc1_clk,
+	}, {	/* SP804 Timer */
+		.dev_id		= "sp804",
+		.clk		= &sp804_clk,
 	},
 };
 
Signature · 1 line
1.7.1
#5 lore raw

PATCH v3 5/7 ARM: timer-sp: support timer clock freq other than 1MHz

In reply to Rob Herring

From: Rob Herring <[email protected]>

The timer-sp code is fixed to 1MHz timer clock. Add clock api calls to get the timer clock frequency and support for independent clock frequencies.

Rename timer names for clocksource and clockevent to timer-sp or the clock connection ID string if provided.

Compile tested on integrator, realview, versatile, and vexpress. Boot tested on vexpress.

---
 arch/arm/common/timer-sp.c               |   43 +++++++++++++++++++++---------
 arch/arm/include/asm/hardware/timer-sp.h |    4 +-
 arch/arm/mach-integrator/integrator_cp.c |    4 +-
 arch/arm/mach-realview/core.c            |    4 +-
 arch/arm/mach-versatile/core.c           |    4 +-
 arch/arm/mach-vexpress/v2m.c             |    4 +-
 6 files changed, 40 insertions(+), 23 deletions(-)
arch/arm/common/timer-sp.c +30 -13
index 6ef3342..c5572d0 100644
@@ -18,6 +18,8 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+#include <linux/clk.h>
+#include <linux/err.h>
 #include <linux/clocksource.h>
 #include <linux/clockchips.h>
 #include <linux/interrupt.h>
@@ -26,12 +28,7 @@
 
 #include <asm/hardware/arm_timer.h>
 
-/*
- * These timers are currently always setup to be clocked at 1MHz.
- */
-#define TIMER_FREQ_KHZ	(1000)
-#define TIMER_RELOAD	(TIMER_FREQ_KHZ * 1000 / HZ)
-
+static unsigned long sp804_clksrc_rate;
 static void __iomem *clksrc_base;
 
 static cycle_t sp804_read(struct clocksource *cs)
@@ -40,19 +37,28 @@ static cycle_t sp804_read(struct clocksource *cs)
 }
 
 static struct clocksource clocksource_sp804 = {
-	.name		= "timer3",
 	.rating		= 200,
 	.read		= sp804_read,
 	.mask		= CLOCKSOURCE_MASK(32),
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-void __init sp804_clocksource_init(void __iomem *base)
+void __init sp804_clocksource_init(void __iomem *base, char *clk_id)
 {
+	struct clk *clk;
 	struct clocksource *cs = &clocksource_sp804;
 
+	cs->name = clk_id ? clk_id : "timer-sp";
+
 	clksrc_base = base;
 
+	clk = clk_get_sys("sp804", clk_id);
+	if (IS_ERR(clk) || clk_enable(clk))
+		panic("sp804 clksrc: cannot get clock\n");
+
+	clk_enable(clk);
+	sp804_clksrc_rate = clk_get_rate(clk);
+
 	/* setup timer 0 as free-running clocksource */
 	writel(0, clksrc_base + TIMER_CTRL);
 	writel(0xffffffff, clksrc_base + TIMER_LOAD);
@@ -60,10 +66,11 @@ void __init sp804_clocksource_init(void __iomem *base)
 	writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
 		clksrc_base + TIMER_CTRL);
 
-	clocksource_register_khz(cs, TIMER_FREQ_KHZ);
+	clocksource_register_hz(cs, sp804_clksrc_rate);
 }
 
 
+static unsigned long sp804_clkevt_rate;
 static void __iomem *clkevt_base;
 
 /*
@@ -90,7 +97,7 @@ static void sp804_set_mode(enum clock_event_mode mode,
 
 	switch (mode) {
 	case CLOCK_EVT_MODE_PERIODIC:
-		writel(TIMER_RELOAD, clkevt_base + TIMER_LOAD);
+		writel(sp804_clkevt_rate / HZ, clkevt_base + TIMER_LOAD);
 		ctrl |= TIMER_CTRL_PERIODIC | TIMER_CTRL_ENABLE;
 		break;
 
@@ -120,7 +127,6 @@ static int sp804_set_next_event(unsigned long next,
 }
 
 static struct clock_event_device sp804_clockevent = {
-	.name		= "timer0",
 	.shift		= 32,
 	.features       = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
 	.set_mode	= sp804_set_mode,
@@ -136,14 +142,25 @@ static struct irqaction sp804_timer_irq = {
 	.dev_id		= &sp804_clockevent,
 };
 
-void __init sp804_clockevents_init(void __iomem *base, unsigned int timer_irq)
+void __init sp804_clockevents_init(void __iomem *base, unsigned int timer_irq,
+				   char *clk_id)
 {
+	struct clk *clk;
 	struct clock_event_device *evt = &sp804_clockevent;
 
+	evt->name = clk_id ? clk_id : "timer-sp";
+
 	clkevt_base = base;
 
+	clk = clk_get_sys("sp804", clk_id);
+	if (IS_ERR(clk) || clk_enable(clk))
+		panic("sp804 clkevt: cannot get clock\n");
+
+	clk_enable(clk);
+	sp804_clkevt_rate = clk_get_rate(clk);
+
 	evt->irq = timer_irq;
-	evt->mult = div_sc(TIMER_FREQ_KHZ, NSEC_PER_MSEC, evt->shift);
+	evt->mult = div_sc(sp804_clkevt_rate, NSEC_PER_SEC, evt->shift);
 	evt->max_delta_ns = clockevent_delta2ns(0xffffffff, evt);
 	evt->min_delta_ns = clockevent_delta2ns(0xf, evt);
 
arch/arm/include/asm/hardware/timer-sp.h +2 -2
index 21e75e3..dc31cb0 100644
@@ -1,2 +1,2 @@
-void sp804_clocksource_init(void __iomem *);
-void sp804_clockevents_init(void __iomem *, unsigned int);
+void sp804_clocksource_init(void __iomem *, char *);
+void sp804_clockevents_init(void __iomem *, unsigned int, char *);
arch/arm/mach-integrator/integrator_cp.c +2 -2
index a9cec65..977788f 100644
@@ -482,8 +482,8 @@ static void __init intcp_timer_init(void)
 	writel(0, TIMER1_VA_BASE + TIMER_CTRL);
 	writel(0, TIMER2_VA_BASE + TIMER_CTRL);
 
-	sp804_clocksource_init(TIMER2_VA_BASE);
-	sp804_clockevents_init(TIMER1_VA_BASE, IRQ_TIMERINT1);
+	sp804_clocksource_init(TIMER2_VA_BASE, NULL);
+	sp804_clockevents_init(TIMER1_VA_BASE, IRQ_TIMERINT1, NULL);
 }
 
 static struct sys_timer cp_timer = {
arch/arm/mach-realview/core.c +2 -2
index ee07755..70316c6 100644
@@ -552,8 +552,8 @@ void __init realview_timer_init(unsigned int timer_irq)
 	writel(0, timer2_va_base + TIMER_CTRL);
 	writel(0, timer3_va_base + TIMER_CTRL);
 
-	sp804_clocksource_init(timer3_va_base);
-	sp804_clockevents_init(timer0_va_base, timer_irq);
+	sp804_clocksource_init(timer3_va_base, NULL);
+	sp804_clockevents_init(timer0_va_base, timer_irq, NULL);
 }
 
 /*
arch/arm/mach-versatile/core.c +2 -2
index e9c5a17..b3094a7 100644
@@ -771,8 +771,8 @@ static void __init versatile_timer_init(void)
 	writel(0, TIMER2_VA_BASE + TIMER_CTRL);
 	writel(0, TIMER3_VA_BASE + TIMER_CTRL);
 
-	sp804_clocksource_init(TIMER3_VA_BASE);
-	sp804_clockevents_init(TIMER0_VA_BASE, IRQ_TIMERINT0_1);
+	sp804_clocksource_init(TIMER3_VA_BASE, NULL);
+	sp804_clockevents_init(TIMER0_VA_BASE, IRQ_TIMERINT0_1, NULL);
 }
 
 struct sys_timer versatile_timer = {
arch/arm/mach-vexpress/v2m.c +2 -2
index c056259..f5e9ab0 100644
@@ -67,8 +67,8 @@ static void __init v2m_timer_init(void)
 	writel(0, MMIO_P2V(V2M_TIMER0) + TIMER_CTRL);
 	writel(0, MMIO_P2V(V2M_TIMER1) + TIMER_CTRL);
 
-	sp804_clocksource_init(MMIO_P2V(V2M_TIMER1));
-	sp804_clockevents_init(MMIO_P2V(V2M_TIMER0), IRQ_V2M_TIMER0);
+	sp804_clocksource_init(MMIO_P2V(V2M_TIMER1), NULL);
+	sp804_clockevents_init(MMIO_P2V(V2M_TIMER0), IRQ_V2M_TIMER0, NULL);
 }
 
 struct sys_timer v2m_timer = {
Signature · 1 line
1.7.1
#6 lore raw

PATCH v3 6/7 ARM: smp_twd: add clock api support

In reply to Rob Herring

From: Rob Herring <[email protected]>

The private timer freq is currently dynamically detected using jiffies count to determine the rate. This method adds a delay to boot-up, so use the clock api instead to get the clock rate.

---
v3: Save struct clk pointer for later use (cpufreq).

 arch/arm/include/asm/smp_twd.h |    1 +
 arch/arm/kernel/smp_twd.c      |   14 ++++++++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)
arch/arm/include/asm/smp_twd.h +1 -0
index fed9981..6b0f591 100644
@@ -24,5 +24,6 @@ extern void __iomem *twd_base;
 
 int twd_timer_ack(void);
 void twd_timer_setup(struct clock_event_device *);
+void twd_timer_init(void __iomem *base);
 
 #endif
arch/arm/kernel/smp_twd.c +14 -0
index 60636f4..cce1171 100644
@@ -8,6 +8,8 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#include <linux/clk.h>
+#include <linux/err.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
@@ -24,6 +26,7 @@
 /* set up by the platform code */
 void __iomem *twd_base;
 
+static struct clk *twd_clk;
 static unsigned long twd_timer_rate;
 
 static void twd_set_mode(enum clock_event_mode mode,
@@ -142,3 +145,14 @@ void __cpuinit twd_timer_setup(struct clock_event_device *clk)
 
 	clockevents_register_device(clk);
 }
+
+void __init twd_timer_init(void __iomem *base)
+{
+	twd_clk = clk_get_sys("smp_twd", NULL);
+	if (!IS_ERR(twd_clk))
+		twd_timer_rate = clk_get_rate(twd_clk);
+	else
+		twd_clk = NULL;
+
+	twd_base = base;
+}
Signature · 1 line
1.7.1
#7 lore raw

PATCH v3 6/7 ARM: smp_twd: add clock api support

Quoted 52 lines · Rob Herring

From: Rob Herring <[email protected]>

The private timer freq is currently dynamically detected using jiffies count to determine the rate. This method adds a delay to boot-up, so use the clock api instead to get the clock rate.

---
v3: Save struct clk pointer for later use (cpufreq).

?arch/arm/include/asm/smp_twd.h | ? ?1 + ?arch/arm/kernel/smp_twd.c ? ? ?| ? 14 ++++++++++++++ ?2 files changed, 15 insertions(+), 0 deletions(-)

arch/arm/include/asm/smp_twd.h +1 -0
index fed9981..6b0f591 100644
@@ -24,5 +24,6 @@ extern void __iomem *twd_base;
 
 ?int twd_timer_ack(void);
 ?void twd_timer_setup(struct clock_event_device *);
+void twd_timer_init(void __iomem *base);
 

?#endif

arch/arm/kernel/smp_twd.c +0 -0
index 60636f4..cce1171 100644
@@ -8,6 +8,8 @@

?* it under the terms of the GNU General Public License version 2 as ?* published by the Free Software Foundation.
?*/

arch/arm/kernel/smp_twd.c +2 -0
+#include <linux/clk.h>
+#include <linux/err.h>

?#include <linux/init.h>
?#include <linux/kernel.h>
?#include <linux/delay.h>

arch/arm/kernel/smp_twd.c +0 -0
@@ -24,6 +26,7 @@

?/* set up by the platform code */
?void __iomem *twd_base;

+static struct clk *twd_clk;
?static unsigned long twd_timer_rate;

?static void twd_set_mode(enum clock_event_mode mode,

arch/arm/kernel/smp_twd.c +1 -0
@@ -142,3 +145,14 @@ void __cpuinit twd_timer_setup(struct clock_event_device *clk)
 
 ? ? ? ?clockevents_register_device(clk);
 ?}
+

arch/arm/kernel/smp_twd.c void __cpuinit twd_timer_setup(struct clock_event_device *clk) · line 158

Quoted 10 lines
arch/arm/kernel/smp_twd.c +10 -0
+void __init twd_timer_init(void __iomem *base)
+{
+ ? ? ? twd_clk = clk_get_sys("smp_twd", NULL);
+ ? ? ? if (!IS_ERR(twd_clk))
+ ? ? ? ? ? ? ? twd_timer_rate = clk_get_rate(twd_clk);
+ ? ? ? else
+ ? ? ? ? ? ? ? twd_clk = NULL;
+
+ ? ? ? twd_base = base;
+}

Why not leave the old twd_base intitialization and put the clock stuff in twd_timer_setup?

Would it make sense to drop twd_calibrate_rate entirely and require a twd clock?

#8 lore raw

PATCH v3 6/7 ARM: smp_twd: add clock api support

Colin,

Quoted 50 lines · Colin Cross
Quoted 49 lines · Rob Herring

From: Rob Herring<[email protected]>

The private timer freq is currently dynamically detected using jiffies count to determine the rate. This method adds a delay to boot-up, so use the clock api instead to get the clock rate.

---
v3: Save struct clk pointer for later use (cpufreq).

  arch/arm/include/asm/smp_twd.h |    1 +
  arch/arm/kernel/smp_twd.c      |   14 ++++++++++++++
  2 files changed, 15 insertions(+), 0 deletions(-)
arch/arm/include/asm/smp_twd.h +1 -0
index fed9981..6b0f591 100644
@@ -24,5 +24,6 @@ extern void __iomem *twd_base;
 
  int twd_timer_ack(void);
  void twd_timer_setup(struct clock_event_device *);
+void twd_timer_init(void __iomem *base);
 
  #endif
arch/arm/kernel/smp_twd.c +3 -0
index 60636f4..cce1171 100644
@@ -8,6 +8,8 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#include<linux/clk.h>
+#include<linux/err.h>
  #include<linux/init.h>
  #include<linux/kernel.h>
  #include<linux/delay.h>
@@ -24,6 +26,7 @@
  /* set up by the platform code */
  void __iomem *twd_base;
 
+static struct clk *twd_clk;
  static unsigned long twd_timer_rate;
 
  static void twd_set_mode(enum clock_event_mode mode,
@@ -142,3 +145,14 @@ void __cpuinit twd_timer_setup(struct clock_event_device *clk)
 
Quoted 15 lines

arch/arm/kernel/smp_twd.c void __cpuinit twd_timer_setup(struct clock_event_device *clk) · line 158

Quoted 13 lines
arch/arm/kernel/smp_twd.c +11 -0
        clockevents_register_device(clk);
  }
+
+void __init twd_timer_init(void __iomem *base)
+{
+       twd_clk = clk_get_sys("smp_twd", NULL);
+       if (!IS_ERR(twd_clk))
+               twd_timer_rate = clk_get_rate(twd_clk);
+       else
+               twd_clk = NULL;
+
+       twd_base = base;
+}

Why not leave the old twd_base intitialization and put the clock stuff in twd_timer_setup?

Well the original patch had base addr and a struct clk pointer passed in for this function. So replacing the variable setting in platform code with this function made sense then. Setting variables like twd_base directly is generally disliked.

twd_timer_setup is called for each core, so it is probably cleaner to have global init and per core init separate. Although, the clock could be per core in future chips.

Quoted 2 lines

Would it make sense to drop twd_calibrate_rate entirely and require a twd clock?

Yes I would like to, but the clock needs to be added to every platform before twd_calibrate_rate could be removed.

Rob

#9 lore raw

PATCH v3 7/7 ARM: vexpress: add smp_twd clock

In reply to Rob Herring

From: Rob Herring <[email protected]>

Add smp_twd clock and call twd_timer_init to enable using it.

---
 arch/arm/mach-vexpress/ct-ca9x4.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
arch/arm/mach-vexpress/ct-ca9x4.c +7 -3
index 3528b1a..7366c5b 100644
@@ -55,9 +55,6 @@ static struct map_desc ct_ca9x4_io_desc[] __initdata = {
 
 static void __init ct_ca9x4_map_io(void)
 {
-#ifdef CONFIG_LOCAL_TIMERS
-	twd_base = MMIO_P2V(A9_MPCORE_TWD);
-#endif
 	v2m_map_io(ct_ca9x4_io_desc, ARRAY_SIZE(ct_ca9x4_io_desc));
 }
 
@@ -143,10 +140,17 @@ static struct clk osc1_clk = {
 	.rate	= 24000000,
 };
 
+static struct clk twd_clk = {
+	.rate	= 200000000,
+};
+
 static struct clk_lookup lookups[] = {
 	{	/* CLCD */
 		.dev_id		= "ct:clcd",
 		.clk		= &osc1_clk,
+	}, {	/* TWD */
+		.dev_id		= "smp_twd",
+		.clk		= &twd_clk,
 	},
 };
 
Signature · 1 line
1.7.1
#10 lore raw

v3 cover ARM timer clock api support

In reply to Rob Herring
Quoted 4 lines · Rob Herring

From: Rob Herring <[email protected]>

This patch series converts ARM sp804 timer and smp_twd timer to use the clock api.

This is what I came up with - I've still not sorted these patches out, the second is a superset of the first.
-------------- next part --------------

arch/arm/common/timer-sp.c +4 -2
index 6ef3342..0480acb 100644
@@ -40,19 +40,21 @@ static cycle_t sp804_read(struct clocksource *cs)
 }
 
 static struct clocksource clocksource_sp804 = {
-	.name		= "timer3",
 	.rating		= 200,
 	.read		= sp804_read,
 	.mask		= CLOCKSOURCE_MASK(32),
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-void __init sp804_clocksource_init(void __iomem *base)
+void __init sp804_clocksource_init(void __iomem *base, const char *name)
 {
 	struct clocksource *cs = &clocksource_sp804;
 
 	clksrc_base = base;
 
+	/* FIXME: cs->name should be const */
+	cs->name = (char *)name;
+
 	/* setup timer 0 as free-running clocksource */
 	writel(0, clksrc_base + TIMER_CTRL);
 	writel(0xffffffff, clksrc_base + TIMER_LOAD);
arch/arm/include/asm/hardware/timer-sp.h +1 -1
index 21e75e3..11c386b 100644
@@ -1,2 +1,2 @@
-void sp804_clocksource_init(void __iomem *);
+void sp804_clocksource_init(void __iomem *, const char *);
 void sp804_clockevents_init(void __iomem *, unsigned int);
arch/arm/mach-integrator/integrator_cp.c +1 -1
index 545d98a..51c29d3 100644
@@ -476,7 +476,7 @@ static void __init intcp_timer_init(void)
 	writel(0, TIMER1_VA_BASE + TIMER_CTRL);
 	writel(0, TIMER2_VA_BASE + TIMER_CTRL);
 
-	sp804_clocksource_init(TIMER2_VA_BASE);
+	sp804_clocksource_init(TIMER2_VA_BASE, "timer2");
 	sp804_clockevents_init(TIMER1_VA_BASE, IRQ_TIMERINT1);
 }
 
arch/arm/mach-realview/core.c +1 -1
index 7066c60..1b6c1b8 100644
@@ -545,7 +545,7 @@ void __init realview_timer_init(unsigned int timer_irq)
 	writel(0, timer2_va_base + TIMER_CTRL);
 	writel(0, timer3_va_base + TIMER_CTRL);
 
-	sp804_clocksource_init(timer3_va_base);
+	sp804_clocksource_init(timer3_va_base, "timer3");
 	sp804_clockevents_init(timer0_va_base, timer_irq);
 }
 
arch/arm/mach-versatile/core.c +1 -1
index ee63dc9..b9cd3ff 100644
@@ -764,7 +764,7 @@ static void __init versatile_timer_init(void)
 	writel(0, TIMER2_VA_BASE + TIMER_CTRL);
 	writel(0, TIMER3_VA_BASE + TIMER_CTRL);
 
-	sp804_clocksource_init(TIMER3_VA_BASE);
+	sp804_clocksource_init(TIMER3_VA_BASE, "timer3");
 	sp804_clockevents_init(TIMER0_VA_BASE, IRQ_TIMERINT0_1);
 }
 
arch/arm/mach-vexpress/ct-ca9x4.c +1 -1
index 7f2c3a3..51fcb0a 100644
@@ -73,7 +73,7 @@ static void __init ct_ca9x4_timer_init(void)
 	writel(0, MMIO_P2V(CT_CA9X4_TIMER0) + TIMER_CTRL);
 	writel(0, MMIO_P2V(CT_CA9X4_TIMER1) + TIMER_CTRL);
 
-	sp804_clocksource_init(MMIO_P2V(CT_CA9X4_TIMER1));
+	sp804_clocksource_init(MMIO_P2V(CT_CA9X4_TIMER1), "timer1");
 	sp804_clockevents_init(MMIO_P2V(CT_CA9X4_TIMER0), IRQ_CT_CA9X4_TIMER0);
 }
 

-------------- next part --------------

arch/arm/common/timer-sp.c +26 -4
index 6ef3342..ae265be 100644
@@ -18,8 +18,10 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+#include <linux/clk.h>
 #include <linux/clocksource.h>
 #include <linux/clockchips.h>
+#include <linux/err.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/io.h>
@@ -29,7 +31,8 @@
 /*
  * These timers are currently always setup to be clocked at 1MHz.
  */
-#define TIMER_FREQ_KHZ	(1000)
+#define TIMER_FREQ_HZ	(1000000)
+#define TIMER_FREQ_KHZ	(TIMER_FREQ_HZ / 1000)
 #define TIMER_RELOAD	(TIMER_FREQ_KHZ * 1000 / HZ)
 
 static void __iomem *clksrc_base;
@@ -40,19 +43,38 @@ static cycle_t sp804_read(struct clocksource *cs)
 }
 
 static struct clocksource clocksource_sp804 = {
-	.name		= "timer3",
 	.rating		= 200,
 	.read		= sp804_read,
 	.mask		= CLOCKSOURCE_MASK(32),
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-void __init sp804_clocksource_init(void __iomem *base)
+void __init sp804_clocksource_init(void __iomem *base, const char *name)
 {
 	struct clocksource *cs = &clocksource_sp804;
+	unsigned long rate = TIMER_FREQ_HZ;
+	struct clk *clk;
+
+	clk = clk_get_sys(name, NULL);
+	if (IS_ERR(clk)) {
+		pr_err("sp804: %s clock not found, defaulting to 1MHz: %d\n",
+			name, ERR_PTR(clk));
+	} else {
+		int err = clk_enable(clk);
+		if (err != 0) {
+			pr_err("sp804: %s clock failed to enable: %d\n",
+				name, err);
+			clk_put(clk);
+		} else {
+			rate = clk_get_rate(clk);
+		}
+	}
 
 	clksrc_base = base;
 
+	/* FIXME: cs->name should be const */
+	cs->name = (char *)name;
+
 	/* setup timer 0 as free-running clocksource */
 	writel(0, clksrc_base + TIMER_CTRL);
 	writel(0xffffffff, clksrc_base + TIMER_LOAD);
@@ -60,7 +82,7 @@ void __init sp804_clocksource_init(void __iomem *base)
 	writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
 		clksrc_base + TIMER_CTRL);
 
-	clocksource_register_khz(cs, TIMER_FREQ_KHZ);
+	clocksource_register_hz(cs, rate);
 }
 
 
arch/arm/include/asm/hardware/timer-sp.h +1 -1
index 21e75e3..11c386b 100644
@@ -1,2 +1,2 @@
-void sp804_clocksource_init(void __iomem *);
+void sp804_clocksource_init(void __iomem *, const char *);
 void sp804_clockevents_init(void __iomem *, unsigned int);
arch/arm/mach-integrator/integrator_cp.c +8 -1
index 545d98a..3563e0c 100644
@@ -229,10 +229,17 @@ static struct clk cp_auxclk = {
 	.vcoreg	= CM_AUXOSC,
 };
 
+static struct clk timer2_clk = {
+	.rate	= 1000000,
+};
+
 static struct clk_lookup cp_lookups[] = {
 	{	/* CLCD */
 		.dev_id		= "mb:c0",
 		.clk		= &cp_auxclk,
+	}, {	/* Timer 2 */
+		.dev_id		= "timer2",
+		.clk		= &timer2_clk,
 	},
 };
 
@@ -476,7 +483,7 @@ static void __init intcp_timer_init(void)
 	writel(0, TIMER1_VA_BASE + TIMER_CTRL);
 	writel(0, TIMER2_VA_BASE + TIMER_CTRL);
 
-	sp804_clocksource_init(TIMER2_VA_BASE);
+	sp804_clocksource_init(TIMER2_VA_BASE, "timer2");
 	sp804_clockevents_init(TIMER1_VA_BASE, IRQ_TIMERINT1);
 }
 
arch/arm/mach-realview/core.c +9 -2
index 7066c60..0cfba16 100644
@@ -315,6 +315,10 @@ static struct clk ref24_clk = {
 	.rate	= 24000000,
 };
 
+static struct clk timer3_clk = {
+	.rate	= 1000000,
+};
+
 static struct clk dummy_apb_pclk;
 
 static struct clk_lookup lookups[] = {
@@ -357,7 +361,10 @@ static struct clk_lookup lookups[] = {
 	}, {	/* SSP */
 		.dev_id		= "dev:ssp0",
 		.clk		= &ref24_clk,
-	}
+	}, {	/* Timer 3 */
+		.dev_id		= "timer3",
+		.clk		= &timer3_clk,
+	},
 };
 
 void __init realview_init_early(void)
@@ -545,7 +552,7 @@ void __init realview_timer_init(unsigned int timer_irq)
 	writel(0, timer2_va_base + TIMER_CTRL);
 	writel(0, timer3_va_base + TIMER_CTRL);
 
-	sp804_clocksource_init(timer3_va_base);
+	sp804_clocksource_init(timer3_va_base, "timer3");
 	sp804_clockevents_init(timer0_va_base, timer_irq);
 }
 
arch/arm/mach-versatile/core.c +9 -2
index ee63dc9..cca9b80 100644
@@ -375,6 +375,10 @@ static struct clk ref24_clk = {
 	.rate	= 24000000,
 };
 
+static struct clk timer3_clk = {
+	.rate	= 1000000,
+};
+
 static struct clk dummy_apb_pclk;
 
 static struct clk_lookup lookups[] = {
@@ -411,7 +415,10 @@ static struct clk_lookup lookups[] = {
 	}, {	/* CLCD */
 		.dev_id		= "dev:20",
 		.clk		= &osc4_clk,
-	}
+	}, {	/* Timer3 */
+		.dev_id		= "timer3",
+		.clk		= &timer3_clk,
+	},
 };
 
 /*
@@ -764,7 +771,7 @@ static void __init versatile_timer_init(void)
 	writel(0, TIMER2_VA_BASE + TIMER_CTRL);
 	writel(0, TIMER3_VA_BASE + TIMER_CTRL);
 
-	sp804_clocksource_init(TIMER3_VA_BASE);
+	sp804_clocksource_init(TIMER3_VA_BASE, "timer3");
 	sp804_clockevents_init(TIMER0_VA_BASE, IRQ_TIMERINT0_1);
 }
 
arch/arm/mach-vexpress/ct-ca9x4.c +1 -1
index 7f2c3a3..51fcb0a 100644
@@ -73,7 +73,7 @@ static void __init ct_ca9x4_timer_init(void)
 	writel(0, MMIO_P2V(CT_CA9X4_TIMER0) + TIMER_CTRL);
 	writel(0, MMIO_P2V(CT_CA9X4_TIMER1) + TIMER_CTRL);
 
-	sp804_clocksource_init(MMIO_P2V(CT_CA9X4_TIMER1));
+	sp804_clocksource_init(MMIO_P2V(CT_CA9X4_TIMER1), "timer1");
 	sp804_clockevents_init(MMIO_P2V(CT_CA9X4_TIMER0), IRQ_CT_CA9X4_TIMER0);
 }
 
#11 lore raw

v3 cover ARM timer clock api support

Russell,

Quoted 8 lines · Russell King - ARM Linux
Quoted 4 lines · Rob Herring

From: Rob Herring<[email protected]>

This patch series converts ARM sp804 timer and smp_twd timer to use the clock api.

This is what I came up with - I've still not sorted these patches out, the second is a superset of the first.

Any comments on the smp_twd patch? Colin plans to base his cpufreq patches on it.

arch/arm/common/timer-sp.c static cycle_t sp804_read(struct clocksource *cs) · line 70

Quoted 13 lines
arch/arm/common/timer-sp.c +13 -0
+	clk = clk_get_sys(name, NULL);
+	if (IS_ERR(clk)) {
+		pr_err("sp804: %s clock not found, defaulting to 1MHz: %d\n",
+			name, ERR_PTR(clk));
+	} else {
+		int err = clk_enable(clk);
+		if (err != 0) {
+			pr_err("sp804: %s clock failed to enable: %d\n",
+				name, err);
+			clk_put(clk);
+		} else {
+			rate = clk_get_rate(clk);
+		}

You previously said this should fully move to using the clock api. Presumably, that meant no default freq of 1MHz.

Also, my patch allows for clksrc and clkevent timers to have different clocks. Currently, no h/w needs that, but it could happen. Even if they are the same clk, you are introducing a requirement on the calling order of sp804_clocksource_init and sp804_clockevents_init.

Rob

#12 lore raw

v3 cover ARM timer clock api support

Quoted 32 lines · Rob Herring

Russell,

Quoted 8 lines · Russell King - ARM Linux
Quoted 4 lines · Rob Herring

From: Rob Herring<[email protected]>

This patch series converts ARM sp804 timer and smp_twd timer to use the clock api.

This is what I came up with - I've still not sorted these patches out, the second is a superset of the first.

Any comments on the smp_twd patch? Colin plans to base his cpufreq patches on it.

arch/arm/common/timer-sp.c static cycle_t sp804_read(struct clocksource *cs) · line 70

Quoted 13 lines
arch/arm/common/timer-sp.c +13 -0
+	clk = clk_get_sys(name, NULL);
+	if (IS_ERR(clk)) {
+		pr_err("sp804: %s clock not found, defaulting to 1MHz: %d\n",
+			name, ERR_PTR(clk));
+	} else {
+		int err = clk_enable(clk);
+		if (err != 0) {
+			pr_err("sp804: %s clock failed to enable: %d\n",
+				name, err);
+			clk_put(clk);
+		} else {
+			rate = clk_get_rate(clk);
+		}

You previously said this should fully move to using the clock api. Presumably, that meant no default freq of 1MHz.

Quoted 2 lines

Also, my patch allows for clksrc and clkevent timers to have different clocks.

So will mine. Note that 'name' is passed in, which is the clocksource name, and is also used for clk_sys_get(). The same thing will happen with clockevents too.

Quoted 3 lines

Currently, no h/w needs that, but it could happen. Even if they are the same clk, you are introducing a requirement on the calling order of sp804_clocksource_init and sp804_clockevents_init.

No I'm not, and I've no idea where you got that idea from. You'll notice that nothing to do with the clk is stored in a global variable.