linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/7] ARM timer clock api support
@ 2011-03-08 23:34 Rob Herring
  2011-03-08 23:34 ` [PATCH v3 1/7] ARM: integrator cp: add sp804 clock Rob Herring
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Rob Herring @ 2011-03-08 23:34 UTC (permalink / raw)
  To: linux-arm-kernel

From: Rob Herring <rob.herring@calxeda.com>

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(-)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 1/7] ARM: integrator cp: add sp804 clock
  2011-03-08 23:34 [PATCH v3 0/7] ARM timer clock api support Rob Herring
@ 2011-03-08 23:34 ` Rob Herring
  2011-03-08 23:34 ` [PATCH v3 2/7] ARM: realview: " Rob Herring
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Rob Herring @ 2011-03-08 23:34 UTC (permalink / raw)
  To: linux-arm-kernel

From: Rob Herring <rob.herring@calxeda.com>

Add a clock for sp804 timer.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
 arch/arm/mach-integrator/integrator_cp.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/arch/arm/mach-integrator/integrator_cp.c b/arch/arm/mach-integrator/integrator_cp.c
index 9e3ce26..a9cec65 100644
--- a/arch/arm/mach-integrator/integrator_cp.c
+++ b/arch/arm/mach-integrator/integrator_cp.c
@@ -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,
+	}
 };
 
 /*
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 2/7] ARM: realview: add sp804 clock
  2011-03-08 23:34 [PATCH v3 0/7] ARM timer clock api support Rob Herring
  2011-03-08 23:34 ` [PATCH v3 1/7] ARM: integrator cp: add sp804 clock Rob Herring
@ 2011-03-08 23:34 ` Rob Herring
  2011-03-08 23:34 ` [PATCH v3 3/7] ARM: versatile: " Rob Herring
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Rob Herring @ 2011-03-08 23:34 UTC (permalink / raw)
  To: linux-arm-kernel

From: Rob Herring <rob.herring@calxeda.com>

Add a clock for sp804 timer.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
 arch/arm/mach-realview/core.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-realview/core.c b/arch/arm/mach-realview/core.c
index 75dbc87..ee07755 100644
--- a/arch/arm/mach-realview/core.c
+++ b/arch/arm/mach-realview/core.c
@@ -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,
 	}
 };
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 3/7] ARM: versatile: add sp804 clock
  2011-03-08 23:34 [PATCH v3 0/7] ARM timer clock api support Rob Herring
  2011-03-08 23:34 ` [PATCH v3 1/7] ARM: integrator cp: add sp804 clock Rob Herring
  2011-03-08 23:34 ` [PATCH v3 2/7] ARM: realview: " Rob Herring
@ 2011-03-08 23:34 ` Rob Herring
  2011-03-08 23:34 ` [PATCH v3 4/7] ARM: vexpress: " Rob Herring
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Rob Herring @ 2011-03-08 23:34 UTC (permalink / raw)
  To: linux-arm-kernel

From: Rob Herring <rob.herring@calxeda.com>

Add a clock for sp804 timer.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
 arch/arm/mach-versatile/core.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-versatile/core.c b/arch/arm/mach-versatile/core.c
index eb7ffa0..e9c5a17 100644
--- a/arch/arm/mach-versatile/core.c
+++ b/arch/arm/mach-versatile/core.c
@@ -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,
 	}
 };
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 4/7] ARM: vexpress: add sp804 clock
  2011-03-08 23:34 [PATCH v3 0/7] ARM timer clock api support Rob Herring
                   ` (2 preceding siblings ...)
  2011-03-08 23:34 ` [PATCH v3 3/7] ARM: versatile: " Rob Herring
@ 2011-03-08 23:34 ` Rob Herring
  2011-03-08 23:34 ` [PATCH v3 5/7] ARM: timer-sp: support timer clock freq other than 1MHz Rob Herring
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Rob Herring @ 2011-03-08 23:34 UTC (permalink / raw)
  To: linux-arm-kernel

From: Rob Herring <rob.herring@calxeda.com>

Add a clock for sp804 timer.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
 arch/arm/mach-vexpress/ct-ca9x4.c |    4 ++--
 arch/arm/mach-vexpress/v2m.c      |    7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-vexpress/ct-ca9x4.c b/arch/arm/mach-vexpress/ct-ca9x4.c
index 30d5a5b..3528b1a 100644
--- a/arch/arm/mach-vexpress/ct-ca9x4.c
+++ b/arch/arm/mach-vexpress/ct-ca9x4.c
@@ -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 = {
diff --git a/arch/arm/mach-vexpress/v2m.c b/arch/arm/mach-vexpress/v2m.c
index 63ef663..c056259 100644
--- a/arch/arm/mach-vexpress/v2m.c
+++ b/arch/arm/mach-vexpress/v2m.c
@@ -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,
 	},
 };
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 5/7] ARM: timer-sp: support timer clock freq other than 1MHz
  2011-03-08 23:34 [PATCH v3 0/7] ARM timer clock api support Rob Herring
                   ` (3 preceding siblings ...)
  2011-03-08 23:34 ` [PATCH v3 4/7] ARM: vexpress: " Rob Herring
@ 2011-03-08 23:34 ` Rob Herring
  2011-03-08 23:34 ` [PATCH v3 6/7] ARM: smp_twd: add clock api support Rob Herring
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Rob Herring @ 2011-03-08 23:34 UTC (permalink / raw)
  To: linux-arm-kernel

From: Rob Herring <rob.herring@calxeda.com>

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.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
 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(-)

diff --git a/arch/arm/common/timer-sp.c b/arch/arm/common/timer-sp.c
index 6ef3342..c5572d0 100644
--- a/arch/arm/common/timer-sp.c
+++ b/arch/arm/common/timer-sp.c
@@ -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);
 
diff --git a/arch/arm/include/asm/hardware/timer-sp.h b/arch/arm/include/asm/hardware/timer-sp.h
index 21e75e3..dc31cb0 100644
--- a/arch/arm/include/asm/hardware/timer-sp.h
+++ b/arch/arm/include/asm/hardware/timer-sp.h
@@ -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 *);
diff --git a/arch/arm/mach-integrator/integrator_cp.c b/arch/arm/mach-integrator/integrator_cp.c
index a9cec65..977788f 100644
--- a/arch/arm/mach-integrator/integrator_cp.c
+++ b/arch/arm/mach-integrator/integrator_cp.c
@@ -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 = {
diff --git a/arch/arm/mach-realview/core.c b/arch/arm/mach-realview/core.c
index ee07755..70316c6 100644
--- a/arch/arm/mach-realview/core.c
+++ b/arch/arm/mach-realview/core.c
@@ -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);
 }
 
 /*
diff --git a/arch/arm/mach-versatile/core.c b/arch/arm/mach-versatile/core.c
index e9c5a17..b3094a7 100644
--- a/arch/arm/mach-versatile/core.c
+++ b/arch/arm/mach-versatile/core.c
@@ -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 = {
diff --git a/arch/arm/mach-vexpress/v2m.c b/arch/arm/mach-vexpress/v2m.c
index c056259..f5e9ab0 100644
--- a/arch/arm/mach-vexpress/v2m.c
+++ b/arch/arm/mach-vexpress/v2m.c
@@ -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 = {
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 6/7] ARM: smp_twd: add clock api support
  2011-03-08 23:34 [PATCH v3 0/7] ARM timer clock api support Rob Herring
                   ` (4 preceding siblings ...)
  2011-03-08 23:34 ` [PATCH v3 5/7] ARM: timer-sp: support timer clock freq other than 1MHz Rob Herring
@ 2011-03-08 23:34 ` Rob Herring
  2011-03-15  2:35   ` Colin Cross
  2011-03-08 23:34 ` [PATCH v3 7/7] ARM: vexpress: add smp_twd clock Rob Herring
  2011-03-11  8:16 ` [PATCH v3 0/7] ARM timer clock api support Russell King - ARM Linux
  7 siblings, 1 reply; 13+ messages in thread
From: Rob Herring @ 2011-03-08 23:34 UTC (permalink / raw)
  To: linux-arm-kernel

From: Rob Herring <rob.herring@calxeda.com>

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.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
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(-)

diff --git a/arch/arm/include/asm/smp_twd.h b/arch/arm/include/asm/smp_twd.h
index fed9981..6b0f591 100644
--- a/arch/arm/include/asm/smp_twd.h
+++ b/arch/arm/include/asm/smp_twd.h
@@ -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
diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
index 60636f4..cce1171 100644
--- a/arch/arm/kernel/smp_twd.c
+++ b/arch/arm/kernel/smp_twd.c
@@ -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;
+}
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 7/7] ARM: vexpress: add smp_twd clock
  2011-03-08 23:34 [PATCH v3 0/7] ARM timer clock api support Rob Herring
                   ` (5 preceding siblings ...)
  2011-03-08 23:34 ` [PATCH v3 6/7] ARM: smp_twd: add clock api support Rob Herring
@ 2011-03-08 23:34 ` Rob Herring
  2011-03-11  8:16 ` [PATCH v3 0/7] ARM timer clock api support Russell King - ARM Linux
  7 siblings, 0 replies; 13+ messages in thread
From: Rob Herring @ 2011-03-08 23:34 UTC (permalink / raw)
  To: linux-arm-kernel

From: Rob Herring <rob.herring@calxeda.com>

Add smp_twd clock and call twd_timer_init to enable using it.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
 arch/arm/mach-vexpress/ct-ca9x4.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-vexpress/ct-ca9x4.c b/arch/arm/mach-vexpress/ct-ca9x4.c
index 3528b1a..7366c5b 100644
--- a/arch/arm/mach-vexpress/ct-ca9x4.c
+++ b/arch/arm/mach-vexpress/ct-ca9x4.c
@@ -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,
 	},
 };
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 0/7] ARM timer clock api support
  2011-03-08 23:34 [PATCH v3 0/7] ARM timer clock api support Rob Herring
                   ` (6 preceding siblings ...)
  2011-03-08 23:34 ` [PATCH v3 7/7] ARM: vexpress: add smp_twd clock Rob Herring
@ 2011-03-11  8:16 ` Russell King - ARM Linux
  2011-03-11 13:48   ` Rob Herring
  7 siblings, 1 reply; 13+ messages in thread
From: Russell King - ARM Linux @ 2011-03-11  8:16 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Mar 08, 2011 at 05:34:30PM -0600, Rob Herring wrote:
> From: Rob Herring <rob.herring@calxeda.com>
> 
> 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 --------------
diff --git a/arch/arm/common/timer-sp.c b/arch/arm/common/timer-sp.c
index 6ef3342..0480acb 100644
--- a/arch/arm/common/timer-sp.c
+++ b/arch/arm/common/timer-sp.c
@@ -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);
diff --git a/arch/arm/include/asm/hardware/timer-sp.h b/arch/arm/include/asm/hardware/timer-sp.h
index 21e75e3..11c386b 100644
--- a/arch/arm/include/asm/hardware/timer-sp.h
+++ b/arch/arm/include/asm/hardware/timer-sp.h
@@ -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);
diff --git a/arch/arm/mach-integrator/integrator_cp.c b/arch/arm/mach-integrator/integrator_cp.c
index 545d98a..51c29d3 100644
--- a/arch/arm/mach-integrator/integrator_cp.c
+++ b/arch/arm/mach-integrator/integrator_cp.c
@@ -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);
 }
 
diff --git a/arch/arm/mach-realview/core.c b/arch/arm/mach-realview/core.c
index 7066c60..1b6c1b8 100644
--- a/arch/arm/mach-realview/core.c
+++ b/arch/arm/mach-realview/core.c
@@ -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);
 }
 
diff --git a/arch/arm/mach-versatile/core.c b/arch/arm/mach-versatile/core.c
index ee63dc9..b9cd3ff 100644
--- a/arch/arm/mach-versatile/core.c
+++ b/arch/arm/mach-versatile/core.c
@@ -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);
 }
 
diff --git a/arch/arm/mach-vexpress/ct-ca9x4.c b/arch/arm/mach-vexpress/ct-ca9x4.c
index 7f2c3a3..51fcb0a 100644
--- a/arch/arm/mach-vexpress/ct-ca9x4.c
+++ b/arch/arm/mach-vexpress/ct-ca9x4.c
@@ -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 --------------
diff --git a/arch/arm/common/timer-sp.c b/arch/arm/common/timer-sp.c
index 6ef3342..ae265be 100644
--- a/arch/arm/common/timer-sp.c
+++ b/arch/arm/common/timer-sp.c
@@ -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);
 }
 
 
diff --git a/arch/arm/include/asm/hardware/timer-sp.h b/arch/arm/include/asm/hardware/timer-sp.h
index 21e75e3..11c386b 100644
--- a/arch/arm/include/asm/hardware/timer-sp.h
+++ b/arch/arm/include/asm/hardware/timer-sp.h
@@ -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);
diff --git a/arch/arm/mach-integrator/integrator_cp.c b/arch/arm/mach-integrator/integrator_cp.c
index 545d98a..3563e0c 100644
--- a/arch/arm/mach-integrator/integrator_cp.c
+++ b/arch/arm/mach-integrator/integrator_cp.c
@@ -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);
 }
 
diff --git a/arch/arm/mach-realview/core.c b/arch/arm/mach-realview/core.c
index 7066c60..0cfba16 100644
--- a/arch/arm/mach-realview/core.c
+++ b/arch/arm/mach-realview/core.c
@@ -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);
 }
 
diff --git a/arch/arm/mach-versatile/core.c b/arch/arm/mach-versatile/core.c
index ee63dc9..cca9b80 100644
--- a/arch/arm/mach-versatile/core.c
+++ b/arch/arm/mach-versatile/core.c
@@ -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);
 }
 
diff --git a/arch/arm/mach-vexpress/ct-ca9x4.c b/arch/arm/mach-vexpress/ct-ca9x4.c
index 7f2c3a3..51fcb0a 100644
--- a/arch/arm/mach-vexpress/ct-ca9x4.c
+++ b/arch/arm/mach-vexpress/ct-ca9x4.c
@@ -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);
 }
 

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 0/7] ARM timer clock api support
  2011-03-11  8:16 ` [PATCH v3 0/7] ARM timer clock api support Russell King - ARM Linux
@ 2011-03-11 13:48   ` Rob Herring
  2011-03-15  8:51     ` Russell King - ARM Linux
  0 siblings, 1 reply; 13+ messages in thread
From: Rob Herring @ 2011-03-11 13:48 UTC (permalink / raw)
  To: linux-arm-kernel

Russell,

On 03/11/2011 02:16 AM, Russell King - ARM Linux wrote:
> On Tue, Mar 08, 2011 at 05:34:30PM -0600, Rob Herring wrote:
>> From: Rob Herring<rob.herring@calxeda.com>
>>
>> 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.

> +	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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 6/7] ARM: smp_twd: add clock api support
  2011-03-08 23:34 ` [PATCH v3 6/7] ARM: smp_twd: add clock api support Rob Herring
@ 2011-03-15  2:35   ` Colin Cross
  2011-03-15 12:40     ` Rob Herring
  0 siblings, 1 reply; 13+ messages in thread
From: Colin Cross @ 2011-03-15  2:35 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Mar 8, 2011 at 3:34 PM, Rob Herring <robherring2@gmail.com> wrote:
> From: Rob Herring <rob.herring@calxeda.com>
>
> 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.
>
> Signed-off-by: Rob Herring <rob.herring@calxeda.com>
> ---
> 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(-)
>
> diff --git a/arch/arm/include/asm/smp_twd.h b/arch/arm/include/asm/smp_twd.h
> index fed9981..6b0f591 100644
> --- a/arch/arm/include/asm/smp_twd.h
> +++ b/arch/arm/include/asm/smp_twd.h
> @@ -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
> diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
> index 60636f4..cce1171 100644
> --- a/arch/arm/kernel/smp_twd.c
> +++ b/arch/arm/kernel/smp_twd.c
> @@ -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;
> +}
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?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 0/7] ARM timer clock api support
  2011-03-11 13:48   ` Rob Herring
@ 2011-03-15  8:51     ` Russell King - ARM Linux
  0 siblings, 0 replies; 13+ messages in thread
From: Russell King - ARM Linux @ 2011-03-15  8:51 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Mar 11, 2011 at 07:48:48AM -0600, Rob Herring wrote:
> Russell,
>
> On 03/11/2011 02:16 AM, Russell King - ARM Linux wrote:
>> On Tue, Mar 08, 2011 at 05:34:30PM -0600, Rob Herring wrote:
>>> From: Rob Herring<rob.herring@calxeda.com>
>>>
>>> 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.
>
>> +	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.

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.

> 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.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 6/7] ARM: smp_twd: add clock api support
  2011-03-15  2:35   ` Colin Cross
@ 2011-03-15 12:40     ` Rob Herring
  0 siblings, 0 replies; 13+ messages in thread
From: Rob Herring @ 2011-03-15 12:40 UTC (permalink / raw)
  To: linux-arm-kernel

Colin,

On 03/14/2011 09:35 PM, Colin Cross wrote:
> On Tue, Mar 8, 2011 at 3:34 PM, Rob Herring<robherring2@gmail.com>  wrote:
>> From: Rob Herring<rob.herring@calxeda.com>
>>
>> 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.
>>
>> Signed-off-by: Rob Herring<rob.herring@calxeda.com>
>> ---
>> 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(-)
>>
>> diff --git a/arch/arm/include/asm/smp_twd.h b/arch/arm/include/asm/smp_twd.h
>> index fed9981..6b0f591 100644
>> --- a/arch/arm/include/asm/smp_twd.h
>> +++ b/arch/arm/include/asm/smp_twd.h
>> @@ -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
>> diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
>> index 60636f4..cce1171 100644
>> --- a/arch/arm/kernel/smp_twd.c
>> +++ b/arch/arm/kernel/smp_twd.c
>> @@ -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;
>> +}
> 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.

>
> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-03-15 12:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-08 23:34 [PATCH v3 0/7] ARM timer clock api support Rob Herring
2011-03-08 23:34 ` [PATCH v3 1/7] ARM: integrator cp: add sp804 clock Rob Herring
2011-03-08 23:34 ` [PATCH v3 2/7] ARM: realview: " Rob Herring
2011-03-08 23:34 ` [PATCH v3 3/7] ARM: versatile: " Rob Herring
2011-03-08 23:34 ` [PATCH v3 4/7] ARM: vexpress: " Rob Herring
2011-03-08 23:34 ` [PATCH v3 5/7] ARM: timer-sp: support timer clock freq other than 1MHz Rob Herring
2011-03-08 23:34 ` [PATCH v3 6/7] ARM: smp_twd: add clock api support Rob Herring
2011-03-15  2:35   ` Colin Cross
2011-03-15 12:40     ` Rob Herring
2011-03-08 23:34 ` [PATCH v3 7/7] ARM: vexpress: add smp_twd clock Rob Herring
2011-03-11  8:16 ` [PATCH v3 0/7] ARM timer clock api support Russell King - ARM Linux
2011-03-11 13:48   ` Rob Herring
2011-03-15  8:51     ` Russell King - ARM Linux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).