Skip to contentSkip to conversation

OMAP2+ system timer cleanup series

PATCH In review Joel Fernandes 2 participants 14 messages Apr 23, 2014 – Jul 21, 2014

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

cover OMAP2+ system timer cleanup series

Here is a clean up series that attempts to separate out some of the DT-only vs legacy system timer usage for OMAP2+. Emphasis is on separating legacy stuff, and abstracting annoyances such as hwmod to give us the flexibilty for the migration. The series will relieve some of the difficulties in moving out the timer code from mach layer. As such it is incremental and there is a bit of duplication for fallback cases, but emphasis is on keeping things working during the migration.

Earlier series posted for dmtimer cleanup, and changes for OMAP1 is at [1].

[1] https://lkml.org/lkml/2014/4/16/737

Joel Fernandes (8):
ARM: OMAP2+: timer: Add a powerup function
ARM: OMAP2+: timer: Simplify clock event/source name setting
ARM: OMAP2+: timer: Add comment on timer clk parenting
ARM: OMAP2+: timer: Remove hwmod look-up dependency for DT-boot
ARM: OMAP2+: timer: Use of_clk_get for DT platforms
ARM: OMAP2+: timer: Fix error message to not use hwmod structure
ARM: OMAP2+: timer: Add fallback for of_clk_get
ARM: OMAP2+: timer: Add legacy code for old way of getting fclk

 arch/arm/mach-omap2/timer.c |  111 +++++++++++++++++++++++++++++++++----------
 1 file changed, 85 insertions(+), 26 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/8 ARM: OMAP2+: timer: Add a powerup function

In an effort to isolate the time power initialization for future purposes, add a function to do the same. This primarily involves a hwmod lookup, setup and enable.

---
 arch/arm/mach-omap2/timer.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
arch/arm/mach-omap2/timer.c +25 -0
index dfb19df..ec427e6 100644
@@ -210,6 +210,31 @@ static void __init omap_dmtimer_init(void)
 	}
 }
 
+int __init omap_dmtimer_powerup(struct device_node *np)
+{
+	struct omap_hwmod *oh;
+	const char *oh_name = NULL;
+	int ret;
+
+	of_property_read_string_index(np, "ti,hwmods", 0, &oh_name);
+	if (!oh_name)
+		return -ENODEV;
+
+	oh = omap_hwmod_lookup(oh_name);
+	if (!oh)
+		return -ENODEV;
+
+	ret = omap_hwmod_setup_one(oh_name);
+	if (ret)
+		return ret;
+
+	ret = omap_hwmod_enable(oh);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 /**
  * omap_dm_timer_get_errata - get errata flags for a timer
  *
Signature · 1 line
1.7.9.5
maintainer
#2 lore raw

Re: [PATCH 1/8] ARM: OMAP2+: timer: Add a powerup function

Quoted 3 lines · Joel Fernandes

In an effort to isolate the time power initialization for future purposes, add a function to do the same. This primarily involves a hwmod lookup, setup and enable.

No users yet for this function? Can you remove the same code from somewhere else in this patch?

Regards,

Tony

Quoted 44 lines
---
 arch/arm/mach-omap2/timer.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
arch/arm/mach-omap2/timer.c +25 -0
index dfb19df..ec427e6 100644
@@ -210,6 +210,31 @@ static void __init omap_dmtimer_init(void)
 	}
 }
 
+int __init omap_dmtimer_powerup(struct device_node *np)
+{
+	struct omap_hwmod *oh;
+	const char *oh_name = NULL;
+	int ret;
+
+	of_property_read_string_index(np, "ti,hwmods", 0, &oh_name);
+	if (!oh_name)
+		return -ENODEV;
+
+	oh = omap_hwmod_lookup(oh_name);
+	if (!oh)
+		return -ENODEV;
+
+	ret = omap_hwmod_setup_one(oh_name);
+	if (ret)
+		return ret;
+
+	ret = omap_hwmod_enable(oh);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 /**
  * omap_dm_timer_get_errata - get errata flags for a timer
  *
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 2/8 ARM: OMAP2+: timer: Simplify clock event/source name setting

In reply to Joel Fernandes

For the OMAPs, we're setting up only one clockevent and clocksource. Further, for DT boot there's no easy way to get the timer name and currently this is done in an ugly way by reading a hwmod entry. So let's just set it to a simpler name like timer_clkev and timer_clksrc.

---
 arch/arm/mach-omap2/timer.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm/mach-omap2/timer.c +5 -5
index ec427e6..f192a41 100644
@@ -251,7 +251,6 @@ static u32 __init omap_dm_timer_get_errata(void)
 static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 					 const char *fck_source,
 					 const char *property,
-					 const char **timer_name,
 					 int posted)
 {
 	char name[10]; /* 10 = sizeof("gptXX_Xck0") */
@@ -290,8 +289,6 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 	if (!oh)
 		return -ENODEV;
 
-	*timer_name = oh->name;
-
 	if (!of_have_populated_dt()) {
 		r = omap_hwmod_get_resource_byname(oh, IORESOURCE_IRQ, NULL,
 						   &irq);
@@ -365,8 +362,10 @@ static void __init omap2_gp_clockevent_init(int gptimer_id,
 	 */
 	__omap_dm_timer_override_errata(&clkev, OMAP_TIMER_ERRATA_I103_I767);
 
+	clockevent_gpt.name = "timer_clkev";
+
 	res = omap_dm_timer_init_one(&clkev, fck_source, property,
-				     &clockevent_gpt.name, OMAP_TIMER_POSTED);
+				     OMAP_TIMER_POSTED);
 	BUG_ON(res);
 
 	omap2_gp_timer_irq.dev_id = &clkev;
@@ -489,10 +488,11 @@ static void __init omap2_gptimer_clocksource_init(int gptimer_id,
 	clksrc.errata = omap_dm_timer_get_errata();
 
 	res = omap_dm_timer_init_one(&clksrc, fck_source, property,
-				     &clocksource_gpt.name,
 				     OMAP_TIMER_NONPOSTED);
 	BUG_ON(res);
 
+	clocksource_gpt.name = "timer_clksrc";
+
 	__omap_dm_timer_load_start(&clksrc,
 				   OMAP_TIMER_CTRL_AR, 0,
 				   OMAP_TIMER_NONPOSTED);
Signature · 1 line
1.7.9.5
maintainer
#4 lore raw

Re: [PATCH 2/8] ARM: OMAP2+: timer: Simplify clock event/source name setting

Quoted 46 lines · Joel Fernandes

For the OMAPs, we're setting up only one clockevent and clocksource. Further, for DT boot there's no easy way to get the timer name and currently this is done in an ugly way by reading a hwmod entry. So let's just set it to a simpler name like timer_clkev and timer_clksrc.

---
 arch/arm/mach-omap2/timer.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm/mach-omap2/timer.c +3 -4
index ec427e6..f192a41 100644
@@ -251,7 +251,6 @@ static u32 __init omap_dm_timer_get_errata(void)
 static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 					 const char *fck_source,
 					 const char *property,
-					 const char **timer_name,
 					 int posted)
 {
 	char name[10]; /* 10 = sizeof("gptXX_Xck0") */
@@ -290,8 +289,6 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 	if (!oh)
 		return -ENODEV;
 
-	*timer_name = oh->name;
-
 	if (!of_have_populated_dt()) {
 		r = omap_hwmod_get_resource_byname(oh, IORESOURCE_IRQ, NULL,
 						   &irq);
@@ -365,8 +362,10 @@ static void __init omap2_gp_clockevent_init(int gptimer_id,
 	 */
 	__omap_dm_timer_override_errata(&clkev, OMAP_TIMER_ERRATA_I103_I767);
 
+	clockevent_gpt.name = "timer_clkev";
+
 	res = omap_dm_timer_init_one(&clkev, fck_source, property,
-				     &clockevent_gpt.name, OMAP_TIMER_POSTED);
+				     OMAP_TIMER_POSTED);
 	BUG_ON(res);
 
 	omap2_gp_timer_irq.dev_id = &clkev;
@@ -489,10 +488,11 @@ static void __init omap2_gptimer_clocksource_init(int gptimer_id,
 	clksrc.errata = omap_dm_timer_get_errata();
 

arch/arm/mach-omap2/timer.c static void __init omap2_gptimer_clocksource_init(int gptimer_id, · line 498

Quoted 10 lines
arch/arm/mach-omap2/timer.c +2 -1
 	res = omap_dm_timer_init_one(&clksrc, fck_source, property,
-				     &clocksource_gpt.name,
 				     OMAP_TIMER_NONPOSTED);
 	BUG_ON(res);
 
+	clocksource_gpt.name = "timer_clksrc";
+
 	__omap_dm_timer_load_start(&clksrc,
 				   OMAP_TIMER_CTRL_AR, 0,
 				   OMAP_TIMER_NONPOSTED);

Hmm aren't we losing information now about which timer we are using?

Might be worth checking if these new names are getting copied somewhere or what happens after init?

Regards,

Tony

#5 lore raw

PATCH 3/8 ARM: OMAP2+: timer: Add comment on timer clk parenting

In reply to Joel Fernandes

Add a comment describing the state of system timer clock parenting. The code following the comment should be deleted once all platforms can do DT boot, and specially should not be executed for DT platforms once we can specify default clock parents through DT.

---
 arch/arm/mach-omap2/timer.c |    4 ++++
 1 file changed, 4 insertions(+)
arch/arm/mach-omap2/timer.c +4 -0
index f192a41..9fdff5b 100644
@@ -313,6 +313,10 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 	if (IS_ERR(timer->fclk))
 		return PTR_ERR(timer->fclk);
 
+	/*
+	 * Clock reparenting code, goes away for DT-boot atleast,
+	 * once clock layer can do it through DT.
+	 */
 	src = clk_get(NULL, fck_source);
 	if (IS_ERR(src))
 		return PTR_ERR(src);
Signature · 1 line
1.7.9.5
maintainer
#6 lore raw

Re: [PATCH 3/8] ARM: OMAP2+: timer: Add comment on timer clk parenting

Quoted 4 lines · Joel Fernandes

Add a comment describing the state of system timer clock parenting. The code following the comment should be deleted once all platforms can do DT boot, and specially should not be executed for DT platforms once we can specify default clock parents through DT.

I think we can do it already for DT based booting?

Regards,

Tony

Quoted 23 lines
---
 arch/arm/mach-omap2/timer.c |    4 ++++
 1 file changed, 4 insertions(+)
arch/arm/mach-omap2/timer.c +4 -0
index f192a41..9fdff5b 100644
@@ -313,6 +313,10 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 	if (IS_ERR(timer->fclk))
 		return PTR_ERR(timer->fclk);
 
+	/*
+	 * Clock reparenting code, goes away for DT-boot atleast,
+	 * once clock layer can do it through DT.
+	 */
 	src = clk_get(NULL, fck_source);
 	if (IS_ERR(src))
 		return PTR_ERR(src);
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH 4/8 ARM: OMAP2+: timer: Remove hwmod look-up dependency for DT-boot

In reply to Joel Fernandes

hwmod look ups should no longer directly happen for dmtimer users of DT-boot platforms. We separate out the code for platforms that are still non-DT. Ultimately this code should be deleted if all platforms are converted to DT-boot.

We use omap_dmtimer_powerup introduced earlier in the series to abstract out the hwmod dependency for the same. This will help us move the generic DT specific code out into drivers/clocksource/ later.

---
 arch/arm/mach-omap2/timer.c |   33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
arch/arm/mach-omap2/timer.c +17 -16
index 9fdff5b..ea91ef9 100644
@@ -266,10 +266,6 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 		if (!np)
 			return -ENODEV;
 
-		of_property_read_string_index(np, "ti,hwmods", 0, &oh_name);
-		if (!oh_name)
-			return -ENODEV;
-
 		timer->irq = irq_of_parse_and_map(np, 0);
 		if (!timer->irq)
 			return -ENXIO;
@@ -277,19 +273,24 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 		timer->io_base = of_iomap(np, 0);
 
 		of_node_put(np);
+
+		if (!timer->io_base)
+			return -ENXIO;
+
+		r = omap_dmtimer_powerup(np);
+		if (r)
+			return r;
 	} else {
 		if (omap_dm_timer_reserve_systimer(timer->id))
 			return -ENODEV;
 
 		sprintf(name, "timer%d", timer->id);
 		oh_name = name;
-	}
 
-	oh = omap_hwmod_lookup(oh_name);
-	if (!oh)
-		return -ENODEV;
+		oh = omap_hwmod_lookup(oh_name);
+		if (!oh)
+			return -ENODEV;
 
-	if (!of_have_populated_dt()) {
 		r = omap_hwmod_get_resource_byname(oh, IORESOURCE_IRQ, NULL,
 						   &irq);
 		if (r)
@@ -303,11 +304,14 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 
 		/* Static mapping, never released */
 		timer->io_base = ioremap(mem.start, mem.end - mem.start);
+
+		if (!timer->io_base)
+			return -ENXIO;
+
+
+		omap_hwmod_setup_one(oh_name);
+		omap_hwmod_enable(oh);
 	}
-
-	if (!timer->io_base)
-		return -ENXIO;
-
 	/* After the dmtimer is using hwmod these clocks won't be needed */
 	timer->fclk = clk_get(NULL, omap_hwmod_get_main_clk(oh));
 	if (IS_ERR(timer->fclk))
@@ -333,10 +337,7 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 
 	clk_put(src);
 
-	omap_hwmod_setup_one(oh_name);
-	omap_hwmod_enable(oh);
 	__omap_dm_timer_init_regs(timer);
-
 	if (posted)
 		__omap_dm_timer_enable_posted(timer);
 
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH 5/8 ARM: OMAP2+: timer: Use of_clk_get for DT platforms

In reply to Joel Fernandes

For DT-booting platforms, use of_clk_get to get the fclk for system timers. Separate out the legacy code for non-DT platform use.

---
 arch/arm/mach-omap2/timer.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
arch/arm/mach-omap2/timer.c +7 -4
index ea91ef9..4fcfd7a 100644
@@ -277,6 +277,10 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 		if (!timer->io_base)
 			return -ENXIO;
 
+		timer->fclk = of_clk_get(np, 0);
+		if (IS_ERR(timer->fclk))
+			return PTR_ERR(timer->fclk);
+
 		r = omap_dmtimer_powerup(np);
 		if (r)
 			return r;
@@ -308,14 +312,13 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 		if (!timer->io_base)
 			return -ENXIO;
 
+		timer->fclk = clk_get(NULL, omap_hwmod_get_main_clk(oh));
+		if (IS_ERR(timer->fclk))
+			return PTR_ERR(timer->fclk);
 
 		omap_hwmod_setup_one(oh_name);
 		omap_hwmod_enable(oh);
 	}
-	/* After the dmtimer is using hwmod these clocks won't be needed */
-	timer->fclk = clk_get(NULL, omap_hwmod_get_main_clk(oh));
-	if (IS_ERR(timer->fclk))
-		return PTR_ERR(timer->fclk);
 
 	/*
 	 * Clock reparenting code, goes away for DT-boot atleast,
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH 6/8 ARM: OMAP2+: timer: Fix error message to not use hwmod structure

In reply to Joel Fernandes

oh->name is no longer used, correct the error message.

---
 arch/arm/mach-omap2/timer.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/timer.c +2 -2
index 4fcfd7a..519ccfd 100644
@@ -331,8 +331,8 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 	if (clk_get_parent(timer->fclk) != src) {
 		r = clk_set_parent(timer->fclk, src);
 		if (r < 0) {
-			pr_warn("%s: %s cannot set source\n", __func__,
-				oh->name);
+			pr_warn("%s: cannot set timer's source\n", __func__);
+			WARN_ON(1);
 			clk_put(src);
 			return r;
 		}
Signature · 1 line
1.7.9.5
maintainer
#10 lore raw

Re: [PATCH 6/8] ARM: OMAP2+: timer: Fix error message to not use hwmod structure

Quoted 1 line · Joel Fernandes

oh->name is no longer used, correct the error message.

I guess this error is created by one of the patchs in this series? So maybe fold it into the patch creating this error?

Regards,

Tony

Quoted 23 lines
---
 arch/arm/mach-omap2/timer.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/timer.c +2 -2
index 4fcfd7a..519ccfd 100644
@@ -331,8 +331,8 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 	if (clk_get_parent(timer->fclk) != src) {
 		r = clk_set_parent(timer->fclk, src);
 		if (r < 0) {
-			pr_warn("%s: %s cannot set source\n", __func__,
-				oh->name);
+			pr_warn("%s: cannot set timer's source\n", __func__);
+			WARN_ON(1);
 			clk_put(src);
 			return r;
 		}
Signature · 1 line
1.7.9.5
#11 lore raw

PATCH 7/8 ARM: OMAP2+: timer: Add fallback for of_clk_get

In reply to Joel Fernandes

Not all platforms currently will support of_clk_get on timer because they may not have clock property in their DT nodes. Add code to handle this case so that things are kept working. Finally we can delete this code once all system timer nodes have a clock property.

---
 arch/arm/mach-omap2/timer.c |   27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
arch/arm/mach-omap2/timer.c +19 -8
index 519ccfd..b3db1da 100644
@@ -277,13 +277,19 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 		if (!timer->io_base)
 			return -ENXIO;
 
-		timer->fclk = of_clk_get(np, 0);
-		if (IS_ERR(timer->fclk))
-			return PTR_ERR(timer->fclk);
-
 		r = omap_dmtimer_powerup(np);
 		if (r)
 			return r;
+
+		timer->fclk = of_clk_get(np, 0);
+		if (IS_ERR(timer->fclk)) {
+			/*
+			 * Support DT platforms temporarily that don't have
+			 * clock property in their dts yet. Ultimately this
+			 * fall back code is to be deleted and we're to return
+			 * PTR_ERR(timer->fclk) here.
+			 */
+		}
 	} else {
 		if (omap_dm_timer_reserve_systimer(timer->id))
 			return -ENODEV;
@@ -312,14 +318,19 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 		if (!timer->io_base)
 			return -ENXIO;
 
-		timer->fclk = clk_get(NULL, omap_hwmod_get_main_clk(oh));
-		if (IS_ERR(timer->fclk))
-			return PTR_ERR(timer->fclk);
-
 		omap_hwmod_setup_one(oh_name);
 		omap_hwmod_enable(oh);
 	}
 
+	if (!timer->fclk || IS_ERR(timer->fclk)) {
+		oh = omap_hwmod_lookup(oh_name);
+		if (!oh)
+			return -ENODEV;
+		timer->fclk = clk_get(NULL, omap_hwmod_get_main_clk(oh));
+		if (IS_ERR(timer->fclk))
+			return PTR_ERR(timer->fclk);
+	}
+
 	/*
 	 * Clock reparenting code, goes away for DT-boot atleast,
 	 * once clock layer can do it through DT.
Signature · 1 line
1.7.9.5
maintainer
#12 lore raw

Re: [PATCH 7/8] ARM: OMAP2+: timer: Add fallback for of_clk_get

Quoted 5 lines · Joel Fernandes

Not all platforms currently will support of_clk_get on timer because they may not have clock property in their DT nodes. Add code to handle this case so that things are kept working. Finally we can delete this code once all system timer nodes have a clock property.

I think this needs updating now too? Might be best to fix the platforms that don't have clocks available yet via DT instead :)

Regards,

Tony

#13 lore raw

PATCH 8/8 ARM: OMAP2+: timer: Add legacy code for old way of getting fclk

In reply to Joel Fernandes

Separate out legacy code for getting timer->fclk and reuse it for the DT-case as a fallback. All DT users should ideally be specifying a clock property with a phandle of its clock node. Till the migration is complete, add a legacy function to keep things working.

---
 arch/arm/mach-omap2/timer.c |   32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)
arch/arm/mach-omap2/timer.c +24 -8
index b3db1da..81a29b1 100644
@@ -248,6 +248,19 @@ static u32 __init omap_dm_timer_get_errata(void)
 	return OMAP_TIMER_ERRATA_I103_I767;
 }
 
+static int legacy_hwmod_clkget(struct omap_dm_timer *timer, const char *oh_name)
+{
+	struct omap_hwmod *oh;
+
+	oh = omap_hwmod_lookup(oh_name);
+	if (!oh)
+		return -ENODEV;
+
+	timer->fclk = clk_get(NULL, omap_hwmod_get_main_clk(oh));
+	if (IS_ERR(timer->fclk))
+		return PTR_ERR(timer->fclk);
+}
+
 static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 					 const char *fck_source,
 					 const char *property,
@@ -289,6 +302,14 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 			 * fall back code is to be deleted and we're to return
 			 * PTR_ERR(timer->fclk) here.
 			 */
+			of_property_read_string_index(np, "ti,hwmods", 0,
+						      &oh_name);
+			if (!oh_name)
+				return -ENODEV;
+
+			r = legacy_hwmod_clkget(timer, oh_name);
+			if (r)
+				return r;
 		}
 	} else {
 		if (omap_dm_timer_reserve_systimer(timer->id))
@@ -320,15 +341,10 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
 
 		omap_hwmod_setup_one(oh_name);
 		omap_hwmod_enable(oh);
-	}
 
-	if (!timer->fclk || IS_ERR(timer->fclk)) {
-		oh = omap_hwmod_lookup(oh_name);
-		if (!oh)
-			return -ENODEV;
-		timer->fclk = clk_get(NULL, omap_hwmod_get_main_clk(oh));
-		if (IS_ERR(timer->fclk))
-			return PTR_ERR(timer->fclk);
+		r = legacy_hwmod_clkget(timer, oh_name);
+		if (r)
+			return r;
 	}
 
 	/*
Signature · 1 line
1.7.9.5