linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 1/2] clocksource: add common of_clksrc_init() function
@ 2012-11-20  0:27 Stephen Warren
  2012-11-20  0:27 ` [PATCH V2 2/2] ARM: tegra: move timer.c to drivers/clocksource/ Stephen Warren
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Warren @ 2012-11-20  0:27 UTC (permalink / raw)
  To: linux-arm-kernel

From: Stephen Warren <swarren@nvidia.com>

It is desirable to move all clocksource drivers to drivers/clocksource,
yet each requires its own initialization function. We'd rather not
pollute <linux/> with a header for each function. Instead, create a
single of_clksrc_init() function which will determine which clocksource
driver to initialize based on device tree.

Based on a similar patch for drivers/irqchip by Thomas Petazzoni.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
v2: New patch.

This series is based on the ARM sys_timer rework that I reposted today.

I hope that these patches can be taken through arm-soc tree for 3.9;
I will repost them based on 3.8-rc1 at the appropriate time.
---
 drivers/clocksource/Kconfig     |    3 +++
 drivers/clocksource/Makefile    |    1 +
 drivers/clocksource/clksrc-of.c |   37 +++++++++++++++++++++++++++++++++++++
 drivers/clocksource/clksrc-of.h |   20 ++++++++++++++++++++
 include/linux/clocksource.h     |    2 ++
 5 files changed, 63 insertions(+)
 create mode 100644 drivers/clocksource/clksrc-of.c
 create mode 100644 drivers/clocksource/clksrc-of.h

diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index c9f67de..4f300c5 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -1,3 +1,6 @@
+config CLKSRC_OF
+	bool
+
 config CLKSRC_I8253
 	bool
 
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 24fb888..29017a3 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -1,3 +1,4 @@
+obj-$(CONFIG_CLKSRC_OF)	+= clksrc-of.o
 obj-$(CONFIG_ATMEL_TCB_CLKSRC)	+= tcb_clksrc.o
 obj-$(CONFIG_X86_CYCLONE_TIMER)	+= cyclone.o
 obj-$(CONFIG_X86_PM_TIMER)	+= acpi_pm.o
diff --git a/drivers/clocksource/clksrc-of.c b/drivers/clocksource/clksrc-of.c
new file mode 100644
index 0000000..aeec8d2
--- /dev/null
+++ b/drivers/clocksource/clksrc-of.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/init.h>
+#include <linux/of.h>
+
+#include "clksrc-of.h"
+
+static const struct of_device_id clksrc_of_match[] __initconst = {
+	{ }
+};
+
+void __init clocksource_of_init(void)
+{
+	struct device_node *np;
+	const struct of_device_id *match;
+	void (*init_func)(void);
+
+	for_each_matching_node(np, clksrc_of_match) {
+		match = of_match_node(clksrc_of_match, np);
+		init_func = match->data;
+		init_func();
+	}
+}
diff --git a/drivers/clocksource/clksrc-of.h b/drivers/clocksource/clksrc-of.h
new file mode 100644
index 0000000..4e2191a
--- /dev/null
+++ b/drivers/clocksource/clksrc-of.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _CLKSRC_OF_H
+#define _CLKSRC_OF_H
+
+#endif
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 4dceaf8..a063b84 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -332,4 +332,6 @@ extern int clocksource_mmio_init(void __iomem *, const char *,
 
 extern int clocksource_i8253_init(void);
 
+extern void clocksource_of_init(void);
+
 #endif /* _LINUX_CLOCKSOURCE_H */
-- 
1.7.10.4

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

* [PATCH V2 2/2] ARM: tegra: move timer.c to drivers/clocksource/
  2012-11-20  0:27 [PATCH V2 1/2] clocksource: add common of_clksrc_init() function Stephen Warren
@ 2012-11-20  0:27 ` Stephen Warren
  2012-11-20  0:50   ` Josh Cartwright
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Warren @ 2012-11-20  0:27 UTC (permalink / raw)
  To: linux-arm-kernel

From: Stephen Warren <swarren@nvidia.com>

Move arch/arm/mach-tegra/timer.c to drivers/clocksource/tegra20_timer.c
so that the code is co-located with other clocksource drivers, and to
reduce the size of the mach-tegra directory.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
v2: Rebase on ARM sys_timer rework, and addition of clocksource_of_init().
---
 arch/arm/Kconfig                                                 |    1 +
 arch/arm/mach-tegra/Makefile                                     |    1 -
 arch/arm/mach-tegra/board-dt-tegra20.c                           |    3 ++-
 arch/arm/mach-tegra/board-dt-tegra30.c                           |    3 ++-
 arch/arm/mach-tegra/board.h                                      |    1 -
 drivers/clocksource/Makefile                                     |    1 +
 drivers/clocksource/clksrc-of.c                                  |    4 ++++
 drivers/clocksource/clksrc-of.h                                  |    2 ++
 .../mach-tegra/timer.c => drivers/clocksource/tegra20_timer.c    |    6 ++----
 9 files changed, 14 insertions(+), 8 deletions(-)
 rename arch/arm/mach-tegra/timer.c => drivers/clocksource/tegra20_timer.c (98%)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 14f8160..9eb54f6 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -633,6 +633,7 @@ config ARCH_TEGRA
 	select ARCH_HAS_CPUFREQ
 	select CLKDEV_LOOKUP
 	select CLKSRC_MMIO
+	select CLKSRC_OF
 	select COMMON_CLK
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_GPIO
diff --git a/arch/arm/mach-tegra/Makefile b/arch/arm/mach-tegra/Makefile
index 6f224f7..6ab3ed5 100644
--- a/arch/arm/mach-tegra/Makefile
+++ b/arch/arm/mach-tegra/Makefile
@@ -2,7 +2,6 @@ obj-y                                   += common.o
 obj-y                                   += io.o
 obj-y                                   += irq.o
 obj-y                                   += clock.o
-obj-y                                   += timer.o
 obj-y					+= fuse.o
 obj-y					+= pmc.o
 obj-y					+= flowctrl.o
diff --git a/arch/arm/mach-tegra/board-dt-tegra20.c b/arch/arm/mach-tegra/board-dt-tegra20.c
index 794a7bf..0bee85a 100644
--- a/arch/arm/mach-tegra/board-dt-tegra20.c
+++ b/arch/arm/mach-tegra/board-dt-tegra20.c
@@ -15,6 +15,7 @@
  *
  */
 
+#include <linux/clocksource.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
@@ -194,7 +195,7 @@ DT_MACHINE_START(TEGRA_DT, "nVidia Tegra20 (Flattened Device Tree)")
 	.init_early	= tegra20_init_early,
 	.init_irq	= tegra_dt_init_irq,
 	.handle_irq	= gic_handle_irq,
-	.init_time	= tegra_init_timer,
+	.init_time	= clocksource_of_init,
 	.init_machine	= tegra_dt_init,
 	.init_late	= tegra_dt_init_late,
 	.restart	= tegra_assert_system_reset,
diff --git a/arch/arm/mach-tegra/board-dt-tegra30.c b/arch/arm/mach-tegra/board-dt-tegra30.c
index 08d3b19..a2b6cf1 100644
--- a/arch/arm/mach-tegra/board-dt-tegra30.c
+++ b/arch/arm/mach-tegra/board-dt-tegra30.c
@@ -23,6 +23,7 @@
  *
  */
 
+#include <linux/clocksource.h>
 #include <linux/kernel.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
@@ -104,7 +105,7 @@ DT_MACHINE_START(TEGRA30_DT, "NVIDIA Tegra30 (Flattened Device Tree)")
 	.init_early	= tegra30_init_early,
 	.init_irq	= tegra_dt_init_irq,
 	.handle_irq	= gic_handle_irq,
-	.init_time	= tegra_init_timer,
+	.init_time	= clocksource_of_init,
 	.init_machine	= tegra30_dt_init,
 	.init_late	= tegra_init_late,
 	.restart	= tegra_assert_system_reset,
diff --git a/arch/arm/mach-tegra/board.h b/arch/arm/mach-tegra/board.h
index 744cdd2..da8f5a3 100644
--- a/arch/arm/mach-tegra/board.h
+++ b/arch/arm/mach-tegra/board.h
@@ -55,5 +55,4 @@ static inline int harmony_pcie_init(void) { return 0; }
 
 void __init tegra_paz00_wifikill_init(void);
 
-extern void tegra_init_timer(void);
 #endif
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 29017a3..ecf37f3 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -16,5 +16,6 @@ obj-$(CONFIG_CLKSRC_NOMADIK_MTU)	+= nomadik-mtu.o
 obj-$(CONFIG_CLKSRC_DBX500_PRCMU)	+= clksrc-dbx500-prcmu.o
 obj-$(CONFIG_ARMADA_370_XP_TIMER)	+= time-armada-370-xp.o
 obj-$(CONFIG_ARCH_BCM2835)	+= bcm2835_timer.o
+obj-$(CONFIG_ARCH_TEGRA)	+= tegra20_timer.o
 
 obj-$(CONFIG_CLKSRC_ARM_GENERIC)	+= arm_generic.o
diff --git a/drivers/clocksource/clksrc-of.c b/drivers/clocksource/clksrc-of.c
index aeec8d2..328d18f 100644
--- a/drivers/clocksource/clksrc-of.c
+++ b/drivers/clocksource/clksrc-of.c
@@ -20,6 +20,10 @@
 #include "clksrc-of.h"
 
 static const struct of_device_id clksrc_of_match[] __initconst = {
+	{
+		.compatible = "nvidia,tegra20-timer",
+		.data = tegra20_init_timer,
+	},
 	{ }
 };
 
diff --git a/drivers/clocksource/clksrc-of.h b/drivers/clocksource/clksrc-of.h
index 4e2191a..386644d 100644
--- a/drivers/clocksource/clksrc-of.h
+++ b/drivers/clocksource/clksrc-of.h
@@ -17,4 +17,6 @@
 #ifndef _CLKSRC_OF_H
 #define _CLKSRC_OF_H
 
+void tegra20_init_timer(void);
+
 #endif
diff --git a/arch/arm/mach-tegra/timer.c b/drivers/clocksource/tegra20_timer.c
similarity index 98%
rename from arch/arm/mach-tegra/timer.c
rename to drivers/clocksource/tegra20_timer.c
index b0036e5..9d84096 100644
--- a/arch/arm/mach-tegra/timer.c
+++ b/drivers/clocksource/tegra20_timer.c
@@ -1,6 +1,4 @@
 /*
- * arch/arch/mach-tegra/timer.c
- *
  * Copyright (C) 2010 Google, Inc.
  *
  * Author:
@@ -33,7 +31,7 @@
 #include <asm/smp_twd.h>
 #include <asm/sched_clock.h>
 
-#include "board.h"
+#include "clksrc-of.h"
 
 #define RTC_SECONDS            0x08
 #define RTC_SHADOW_SECONDS     0x0c
@@ -168,7 +166,7 @@ static const struct of_device_id rtc_match[] __initconst = {
 	{}
 };
 
-void __init tegra_init_timer(void)
+void __init tegra20_init_timer(void)
 {
 	struct device_node *np;
 	struct clk *clk;
-- 
1.7.10.4

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

* [PATCH V2 2/2] ARM: tegra: move timer.c to drivers/clocksource/
  2012-11-20  0:27 ` [PATCH V2 2/2] ARM: tegra: move timer.c to drivers/clocksource/ Stephen Warren
@ 2012-11-20  0:50   ` Josh Cartwright
  2012-11-20  8:17     ` Thomas Petazzoni
  2012-11-20 18:58     ` Stephen Warren
  0 siblings, 2 replies; 5+ messages in thread
From: Josh Cartwright @ 2012-11-20  0:50 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Nov 19, 2012 at 05:27:17PM -0700, Stephen Warren wrote:
> From: Stephen Warren <swarren@nvidia.com>
> 
> Move arch/arm/mach-tegra/timer.c to drivers/clocksource/tegra20_timer.c
> so that the code is co-located with other clocksource drivers, and to
> reduce the size of the mach-tegra directory.
> 
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
> v2: Rebase on ARM sys_timer rework, and addition of clocksource_of_init().
[..]
> diff --git a/drivers/clocksource/clksrc-of.c b/drivers/clocksource/clksrc-of.c
> index aeec8d2..328d18f 100644
> --- a/drivers/clocksource/clksrc-of.c
> +++ b/drivers/clocksource/clksrc-of.c
> @@ -20,6 +20,10 @@
>  #include "clksrc-of.h"
>  
>  static const struct of_device_id clksrc_of_match[] __initconst = {
> +	{
> +		.compatible = "nvidia,tegra20-timer",
> +		.data = tegra20_init_timer,
> +	},

Shouldn't this be wrapped in #if ARCH_TEGRA?

I had suggested this with Thomas Petazzoni's consolidated irq_chip patch
as well:

It seems like it would be a bit cleaner/easier to maintain if we relied
on the linker to stitch together a clksrc_of_match table, based on what
clocksources are being built into the image.  With that approach, at
least, a public initialization header wouldn't have to be exposed, and
this central table wouldn't have to be maintained (as more clocksrcs are
added, I forsee [admittedly trivial] merge conflicts).

Thoughts?

   Josh

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

* [PATCH V2 2/2] ARM: tegra: move timer.c to drivers/clocksource/
  2012-11-20  0:50   ` Josh Cartwright
@ 2012-11-20  8:17     ` Thomas Petazzoni
  2012-11-20 18:58     ` Stephen Warren
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Petazzoni @ 2012-11-20  8:17 UTC (permalink / raw)
  To: linux-arm-kernel

Josh,

On Mon, 19 Nov 2012 18:50:36 -0600, Josh Cartwright wrote:

> I had suggested this with Thomas Petazzoni's consolidated irq_chip patch
> as well:
> 
> It seems like it would be a bit cleaner/easier to maintain if we relied
> on the linker to stitch together a clksrc_of_match table, based on what
> clocksources are being built into the image.  With that approach, at
> least, a public initialization header wouldn't have to be exposed, and
> this central table wouldn't have to be maintained (as more clocksrcs are
> added, I forsee [admittedly trivial] merge conflicts).

... and I indeed have a new version of my irqchip patches that indeed
use the linker to merge together the of_device_id entries!

Best regards,

Thomas
-- 
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

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

* [PATCH V2 2/2] ARM: tegra: move timer.c to drivers/clocksource/
  2012-11-20  0:50   ` Josh Cartwright
  2012-11-20  8:17     ` Thomas Petazzoni
@ 2012-11-20 18:58     ` Stephen Warren
  1 sibling, 0 replies; 5+ messages in thread
From: Stephen Warren @ 2012-11-20 18:58 UTC (permalink / raw)
  To: linux-arm-kernel

On 11/19/2012 05:50 PM, Josh Cartwright wrote:
> On Mon, Nov 19, 2012 at 05:27:17PM -0700, Stephen Warren wrote:
>> From: Stephen Warren <swarren@nvidia.com>
>>
>> Move arch/arm/mach-tegra/timer.c to drivers/clocksource/tegra20_timer.c
>> so that the code is co-located with other clocksource drivers, and to
>> reduce the size of the mach-tegra directory.
>>
>> Signed-off-by: Stephen Warren <swarren@nvidia.com>
>> ---
>> v2: Rebase on ARM sys_timer rework, and addition of clocksource_of_init().
> [..]
>> diff --git a/drivers/clocksource/clksrc-of.c b/drivers/clocksource/clksrc-of.c
>> index aeec8d2..328d18f 100644
>> --- a/drivers/clocksource/clksrc-of.c
>> +++ b/drivers/clocksource/clksrc-of.c
>> @@ -20,6 +20,10 @@
>>  #include "clksrc-of.h"
>>  
>>  static const struct of_device_id clksrc_of_match[] __initconst = {
>> +	{
>> +		.compatible = "nvidia,tegra20-timer",
>> +		.data = tegra20_init_timer,
>> +	},
> 
> Shouldn't this be wrapped in #if ARCH_TEGRA?

Yes.

> I had suggested this with Thomas Petazzoni's consolidated irq_chip patch
> as well:
> 
> It seems like it would be a bit cleaner/easier to maintain if we relied
> on the linker to stitch together a clksrc_of_match table, based on what
> clocksources are being built into the image.  With that approach, at
> least, a public initialization header wouldn't have to be exposed, and
> this central table wouldn't have to be maintained (as more clocksrcs are
> added, I forsee [admittedly trivial] merge conflicts).
> 
> Thoughts?

I thought I'd wait for Thomas' revised patch and copy that, but it
turned out to be easier that I figured to implement. So, new revision
coming soon!

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

end of thread, other threads:[~2012-11-20 18:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-20  0:27 [PATCH V2 1/2] clocksource: add common of_clksrc_init() function Stephen Warren
2012-11-20  0:27 ` [PATCH V2 2/2] ARM: tegra: move timer.c to drivers/clocksource/ Stephen Warren
2012-11-20  0:50   ` Josh Cartwright
2012-11-20  8:17     ` Thomas Petazzoni
2012-11-20 18:58     ` Stephen Warren

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