Skip to contentSkip to conversation

clocksource: Add ast2600 support to fttmr010

PATCH Applied Joel Stanley 3 participants 14 messages Nov 7, 2019 – Mar 19, 2020

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

v2 cover clocksource: Add ast2600 support to fttmr010

This series adds support for the AST2600 timer.

v2 adds r-b tags from Rob, Linus and Cédric (who reviewed the patches on the openbmc mailing list[1]). I made two small naming changes in this version that were suggested in review.

[1] https://patchwork.ozlabs.org/project/openbmc/list/?series=140990

Joel Stanley (4):
clocksource: fttmr010: Parametrise shutdown
clocksource: fttmr010: Set interrupt and shutdown
clocksource: fttmr010: Add support for ast2600
dt-bindings: fttmr010: Add ast2600 compatible

 .../bindings/timer/faraday,fttmr010.txt       |  1 +
 drivers/clocksource/timer-fttmr010.c          | 68 +++++++++++++++----
 2 files changed, 54 insertions(+), 15 deletions(-)
Signature · 1 line
2.24.0.rc1
#1 lore raw

PATCH v2 1/4 clocksource: fttmr010: Parametrise shutdown

In preparation for supporting the ast2600 which uses a different method to clear bits in the control register, use a callback for performing the shutdown sequence.

---
 drivers/clocksource/timer-fttmr010.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/clocksource/timer-fttmr010.c +8 -11
index fadff7915dd9..c2d30eb9dc72 100644
@@ -97,6 +97,7 @@ struct fttmr010 {
 	bool is_aspeed;
 	u32 t1_enable_val;
 	struct clock_event_device clkevt;
+	int (*timer_shutdown)(struct clock_event_device *evt);
 #ifdef CONFIG_ARM
 	struct delay_timer delay_timer;
 #endif
@@ -140,9 +141,7 @@ static int fttmr010_timer_set_next_event(unsigned long cycles,
 	u32 cr;
 
 	/* Stop */
-	cr = readl(fttmr010->base + TIMER_CR);
-	cr &= ~fttmr010->t1_enable_val;
-	writel(cr, fttmr010->base + TIMER_CR);
+	fttmr010->timer_shutdown(evt);
 
 	if (fttmr010->is_aspeed) {
 		/*
@@ -183,9 +182,7 @@ static int fttmr010_timer_set_oneshot(struct clock_event_device *evt)
 	u32 cr;
 
 	/* Stop */
-	cr = readl(fttmr010->base + TIMER_CR);
-	cr &= ~fttmr010->t1_enable_val;
-	writel(cr, fttmr010->base + TIMER_CR);
+	fttmr010->timer_shutdown(evt);
 
 	/* Setup counter start from 0 or ~0 */
 	writel(0, fttmr010->base + TIMER1_COUNT);
@@ -211,9 +208,7 @@ static int fttmr010_timer_set_periodic(struct clock_event_device *evt)
 	u32 cr;
 
 	/* Stop */
-	cr = readl(fttmr010->base + TIMER_CR);
-	cr &= ~fttmr010->t1_enable_val;
-	writel(cr, fttmr010->base + TIMER_CR);
+	fttmr010->timer_shutdown(evt);
 
 	/* Setup timer to fire at 1/HZ intervals. */
 	if (fttmr010->is_aspeed) {
@@ -350,6 +345,8 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
 				     fttmr010->tick_rate);
 	}
 
+	fttmr010->timer_shutdown = fttmr010_timer_shutdown;
+
 	/*
 	 * Setup clockevent timer (interrupt-driven) on timer 1.
 	 */
@@ -370,10 +367,10 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
 	fttmr010->clkevt.features = CLOCK_EVT_FEAT_PERIODIC |
 		CLOCK_EVT_FEAT_ONESHOT;
 	fttmr010->clkevt.set_next_event = fttmr010_timer_set_next_event;
-	fttmr010->clkevt.set_state_shutdown = fttmr010_timer_shutdown;
+	fttmr010->clkevt.set_state_shutdown = fttmr010->timer_shutdown;
 	fttmr010->clkevt.set_state_periodic = fttmr010_timer_set_periodic;
 	fttmr010->clkevt.set_state_oneshot = fttmr010_timer_set_oneshot;
-	fttmr010->clkevt.tick_resume = fttmr010_timer_shutdown;
+	fttmr010->clkevt.tick_resume = fttmr010->timer_shutdown;
 	fttmr010->clkevt.cpumask = cpumask_of(0);
 	fttmr010->clkevt.irq = irq;
 	clockevents_config_and_register(&fttmr010->clkevt,
Signature · 1 line
2.24.0.rc1
#2 lore raw

Re: [PATCH v2 1/4] clocksource: fttmr010: Parametrise shutdown

Quoted 7 lines · Joel Stanley

In preparation for supporting the ast2600 which uses a different method to clear bits in the control register, use a callback for performing the shutdown sequence.

It will be cleaner if you create a struct of_device_id array where you store the different variant data.

eg.

struct myops {
	int (*shutdown)(struct clock_event_device *evt);
};
struct fttmr010 {
	...
	struct myops *ops;
};

...

static const struct of_device_id fttmr010_of_match[] = {
	{ .compatible = "faraday,fttmr010",     .data = &fttmr010_ops },
	...
	{ .compatible = "aspeed,ast2600-timer", .data = &as2600_ops, },
	{ /* sentinel */ }
};

Keep the generic timer_shutdown function, get the ops from there and then call the shutdown callback.

At init time:

...

const struct of_device_id *match;

...

match = of_match_node(fttmr010_of_match, node);
fttmr010->ops = (struct myops *)match->data;

...

(also if you have time, remove the is_aspeed boolean test by a corresponding callback).

Quoted 72 lines
---
 drivers/clocksource/timer-fttmr010.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/clocksource/timer-fttmr010.c +8 -11
index fadff7915dd9..c2d30eb9dc72 100644
@@ -97,6 +97,7 @@ struct fttmr010 {
 	bool is_aspeed;
 	u32 t1_enable_val;
 	struct clock_event_device clkevt;
+	int (*timer_shutdown)(struct clock_event_device *evt);
 #ifdef CONFIG_ARM
 	struct delay_timer delay_timer;
 #endif
@@ -140,9 +141,7 @@ static int fttmr010_timer_set_next_event(unsigned long cycles,
 	u32 cr;
 
 	/* Stop */
-	cr = readl(fttmr010->base + TIMER_CR);
-	cr &= ~fttmr010->t1_enable_val;
-	writel(cr, fttmr010->base + TIMER_CR);
+	fttmr010->timer_shutdown(evt);
 
 	if (fttmr010->is_aspeed) {
 		/*
@@ -183,9 +182,7 @@ static int fttmr010_timer_set_oneshot(struct clock_event_device *evt)
 	u32 cr;
 
 	/* Stop */
-	cr = readl(fttmr010->base + TIMER_CR);
-	cr &= ~fttmr010->t1_enable_val;
-	writel(cr, fttmr010->base + TIMER_CR);
+	fttmr010->timer_shutdown(evt);
 
 	/* Setup counter start from 0 or ~0 */
 	writel(0, fttmr010->base + TIMER1_COUNT);
@@ -211,9 +208,7 @@ static int fttmr010_timer_set_periodic(struct clock_event_device *evt)
 	u32 cr;
 
 	/* Stop */
-	cr = readl(fttmr010->base + TIMER_CR);
-	cr &= ~fttmr010->t1_enable_val;
-	writel(cr, fttmr010->base + TIMER_CR);
+	fttmr010->timer_shutdown(evt);
 
 	/* Setup timer to fire at 1/HZ intervals. */
 	if (fttmr010->is_aspeed) {
@@ -350,6 +345,8 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
 				     fttmr010->tick_rate);
 	}
 
+	fttmr010->timer_shutdown = fttmr010_timer_shutdown;
+
 	/*
 	 * Setup clockevent timer (interrupt-driven) on timer 1.
 	 */
@@ -370,10 +367,10 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
 	fttmr010->clkevt.features = CLOCK_EVT_FEAT_PERIODIC |
 		CLOCK_EVT_FEAT_ONESHOT;
 	fttmr010->clkevt.set_next_event = fttmr010_timer_set_next_event;
-	fttmr010->clkevt.set_state_shutdown = fttmr010_timer_shutdown;
+	fttmr010->clkevt.set_state_shutdown = fttmr010->timer_shutdown;
 	fttmr010->clkevt.set_state_periodic = fttmr010_timer_set_periodic;
 	fttmr010->clkevt.set_state_oneshot = fttmr010_timer_set_oneshot;
-	fttmr010->clkevt.tick_resume = fttmr010_timer_shutdown;
+	fttmr010->clkevt.tick_resume = fttmr010->timer_shutdown;
 	fttmr010->clkevt.cpumask = cpumask_of(0);
 	fttmr010->clkevt.irq = irq;
 	clockevents_config_and_register(&fttmr010->clkevt,
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#3 lore raw

Re: [PATCH v2 1/4] clocksource: fttmr010: Parametrise shutdown

Quoted 6 lines · Daniel Lezcano
Quoted 4 lines · Joel Stanley

In preparation for supporting the ast2600 which uses a different method to clear bits in the control register, use a callback for performing the shutdown sequence.

Quoted 6 lines
Quoted 3 lines

It will be cleaner if you create a struct of_device_id array where you store the different variant data.

I agree, and that's the path I would have taken when writing a normal driver. However as the timer drivers probe with the TIMER_OF_DECLARE/timer_probe infrastructure, we can't register our own .data pointer (TIMER_OF_DECLARE uses .data to store the _init function).

Unless I'm missing something?

Cheers,

Joel

Quoted 120 lines

eg.

struct myops {
        int (*shutdown)(struct clock_event_device *evt);
};
struct fttmr010 {
        ...
        struct myops *ops;
};

...

static const struct of_device_id fttmr010_of_match[] = {
        { .compatible = "faraday,fttmr010",     .data = &fttmr010_ops },
        ...
        { .compatible = "aspeed,ast2600-timer", .data = &as2600_ops, },
        { /* sentinel */ }
};

Keep the generic timer_shutdown function, get the ops from there and then call the shutdown callback.

At init time:

...

const struct of_device_id *match;

...

match = of_match_node(fttmr010_of_match, node);
fttmr010->ops = (struct myops *)match->data;

...

(also if you have time, remove the is_aspeed boolean test by a corresponding callback).

Quoted 62 lines
---
 drivers/clocksource/timer-fttmr010.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/clocksource/timer-fttmr010.c +6 -9
index fadff7915dd9..c2d30eb9dc72 100644
@@ -97,6 +97,7 @@ struct fttmr010 {
      bool is_aspeed;
      u32 t1_enable_val;
      struct clock_event_device clkevt;
+     int (*timer_shutdown)(struct clock_event_device *evt);
 #ifdef CONFIG_ARM
      struct delay_timer delay_timer;
 #endif
@@ -140,9 +141,7 @@ static int fttmr010_timer_set_next_event(unsigned long cycles,
      u32 cr;
 
      /* Stop */
-     cr = readl(fttmr010->base + TIMER_CR);
-     cr &= ~fttmr010->t1_enable_val;
-     writel(cr, fttmr010->base + TIMER_CR);
+     fttmr010->timer_shutdown(evt);
 
      if (fttmr010->is_aspeed) {
              /*
@@ -183,9 +182,7 @@ static int fttmr010_timer_set_oneshot(struct clock_event_device *evt)
      u32 cr;
 
      /* Stop */
-     cr = readl(fttmr010->base + TIMER_CR);
-     cr &= ~fttmr010->t1_enable_val;
-     writel(cr, fttmr010->base + TIMER_CR);
+     fttmr010->timer_shutdown(evt);
 
      /* Setup counter start from 0 or ~0 */
      writel(0, fttmr010->base + TIMER1_COUNT);
@@ -211,9 +208,7 @@ static int fttmr010_timer_set_periodic(struct clock_event_device *evt)
      u32 cr;
 
      /* Stop */
-     cr = readl(fttmr010->base + TIMER_CR);
-     cr &= ~fttmr010->t1_enable_val;
-     writel(cr, fttmr010->base + TIMER_CR);
+     fttmr010->timer_shutdown(evt);
 
      /* Setup timer to fire at 1/HZ intervals. */
      if (fttmr010->is_aspeed) {
@@ -350,6 +345,8 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
                                   fttmr010->tick_rate);
      }
 
+     fttmr010->timer_shutdown = fttmr010_timer_shutdown;
+
      /*
       * Setup clockevent timer (interrupt-driven) on timer 1.
       */
@@ -370,10 +367,10 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
      fttmr010->clkevt.features = CLOCK_EVT_FEAT_PERIODIC |
              CLOCK_EVT_FEAT_ONESHOT;

drivers/clocksource/timer-fttmr010.c static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed) · line 376

Quoted 10 lines
drivers/clocksource/timer-fttmr010.c +2 -2
      fttmr010->clkevt.set_next_event = fttmr010_timer_set_next_event;
-     fttmr010->clkevt.set_state_shutdown = fttmr010_timer_shutdown;
+     fttmr010->clkevt.set_state_shutdown = fttmr010->timer_shutdown;
      fttmr010->clkevt.set_state_periodic = fttmr010_timer_set_periodic;
      fttmr010->clkevt.set_state_oneshot = fttmr010_timer_set_oneshot;
-     fttmr010->clkevt.tick_resume = fttmr010_timer_shutdown;
+     fttmr010->clkevt.tick_resume = fttmr010->timer_shutdown;
      fttmr010->clkevt.cpumask = cpumask_of(0);
      fttmr010->clkevt.irq = irq;
      clockevents_config_and_register(&fttmr010->clkevt,

--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

#4 lore raw

Re: [PATCH v2 1/4] clocksource: fttmr010: Parametrise shutdown

Quoted 14 lines · Joel Stanley
Quoted 6 lines · Daniel Lezcano
Quoted 4 lines · Joel Stanley

In preparation for supporting the ast2600 which uses a different method to clear bits in the control register, use a callback for performing the shutdown sequence.

Quoted 6 lines
Quoted 3 lines

It will be cleaner if you create a struct of_device_id array where you store the different variant data.

Quoted 7 lines

I agree, and that's the path I would have taken when writing a normal driver. However as the timer drivers probe with the TIMER_OF_DECLARE/timer_probe infrastructure, we can't register our own .data pointer (TIMER_OF_DECLARE uses .data to store the _init function).

Unless I'm missing something?

I was suggesting to add the array like:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/clocksource/timer-atmel-tcb.c#n351

TIMER_OF_DECLARE is used and the probe functions relies on the match array:

match = of_match_node(atmel_tcb_of_match, node->parent);

(note in this case, it is the node parent).

Quoted 120 lines
Quoted 120 lines

eg.

struct myops {
        int (*shutdown)(struct clock_event_device *evt);
};
struct fttmr010 {
        ...
        struct myops *ops;
};

...

static const struct of_device_id fttmr010_of_match[] = {
        { .compatible = "faraday,fttmr010",     .data = &fttmr010_ops },
        ...
        { .compatible = "aspeed,ast2600-timer", .data = &as2600_ops, },
        { /* sentinel */ }
};

Keep the generic timer_shutdown function, get the ops from there and then call the shutdown callback.

At init time:

...

const struct of_device_id *match;

...

match = of_match_node(fttmr010_of_match, node);
fttmr010->ops = (struct myops *)match->data;

...

(also if you have time, remove the is_aspeed boolean test by a corresponding callback).

Quoted 62 lines
---
 drivers/clocksource/timer-fttmr010.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/clocksource/timer-fttmr010.c +6 -9
index fadff7915dd9..c2d30eb9dc72 100644
@@ -97,6 +97,7 @@ struct fttmr010 {
      bool is_aspeed;
      u32 t1_enable_val;
      struct clock_event_device clkevt;
+     int (*timer_shutdown)(struct clock_event_device *evt);
 #ifdef CONFIG_ARM
      struct delay_timer delay_timer;
 #endif
@@ -140,9 +141,7 @@ static int fttmr010_timer_set_next_event(unsigned long cycles,
      u32 cr;
 
      /* Stop */
-     cr = readl(fttmr010->base + TIMER_CR);
-     cr &= ~fttmr010->t1_enable_val;
-     writel(cr, fttmr010->base + TIMER_CR);
+     fttmr010->timer_shutdown(evt);
 
      if (fttmr010->is_aspeed) {
              /*
@@ -183,9 +182,7 @@ static int fttmr010_timer_set_oneshot(struct clock_event_device *evt)
      u32 cr;
 
      /* Stop */
-     cr = readl(fttmr010->base + TIMER_CR);
-     cr &= ~fttmr010->t1_enable_val;
-     writel(cr, fttmr010->base + TIMER_CR);
+     fttmr010->timer_shutdown(evt);
 
      /* Setup counter start from 0 or ~0 */
      writel(0, fttmr010->base + TIMER1_COUNT);
@@ -211,9 +208,7 @@ static int fttmr010_timer_set_periodic(struct clock_event_device *evt)
      u32 cr;
 
      /* Stop */
-     cr = readl(fttmr010->base + TIMER_CR);
-     cr &= ~fttmr010->t1_enable_val;
-     writel(cr, fttmr010->base + TIMER_CR);
+     fttmr010->timer_shutdown(evt);
 
      /* Setup timer to fire at 1/HZ intervals. */
      if (fttmr010->is_aspeed) {
@@ -350,6 +345,8 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
                                   fttmr010->tick_rate);
      }
 
+     fttmr010->timer_shutdown = fttmr010_timer_shutdown;
+
      /*
       * Setup clockevent timer (interrupt-driven) on timer 1.
       */
@@ -370,10 +367,10 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
      fttmr010->clkevt.features = CLOCK_EVT_FEAT_PERIODIC |
              CLOCK_EVT_FEAT_ONESHOT;

drivers/clocksource/timer-fttmr010.c static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed) · line 376

Quoted 10 lines
drivers/clocksource/timer-fttmr010.c +2 -2
      fttmr010->clkevt.set_next_event = fttmr010_timer_set_next_event;
-     fttmr010->clkevt.set_state_shutdown = fttmr010_timer_shutdown;
+     fttmr010->clkevt.set_state_shutdown = fttmr010->timer_shutdown;
      fttmr010->clkevt.set_state_periodic = fttmr010_timer_set_periodic;
      fttmr010->clkevt.set_state_oneshot = fttmr010_timer_set_oneshot;
-     fttmr010->clkevt.tick_resume = fttmr010_timer_shutdown;
+     fttmr010->clkevt.tick_resume = fttmr010->timer_shutdown;
      fttmr010->clkevt.cpumask = cpumask_of(0);
      fttmr010->clkevt.irq = irq;
      clockevents_config_and_register(&fttmr010->clkevt,

--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#5 lore raw

Re: [PATCH v2 1/4] clocksource: fttmr010: Parametrise shutdown

Quoted 24 lines · Daniel Lezcano
Quoted 14 lines · Joel Stanley
Quoted 6 lines · Daniel Lezcano
Quoted 4 lines · Joel Stanley

In preparation for supporting the ast2600 which uses a different method to clear bits in the control register, use a callback for performing the shutdown sequence.

Quoted 6 lines
Quoted 3 lines

It will be cleaner if you create a struct of_device_id array where you store the different variant data.

Quoted 7 lines

I agree, and that's the path I would have taken when writing a normal driver. However as the timer drivers probe with the TIMER_OF_DECLARE/timer_probe infrastructure, we can't register our own .data pointer (TIMER_OF_DECLARE uses .data to store the _init function).

Unless I'm missing something?

Quoted 7 lines

I was suggesting to add the array like:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/clocksource/timer-atmel-tcb.c#n351

TIMER_OF_DECLARE is used and the probe functions relies on the match array:

match = of_match_node(atmel_tcb_of_match, node->parent);

I see. So we don't use this table for probing the driver, just getting the associated data.

I'm not convinced that's an improvement over what we have. If you have a strong preference I can try it out.

merge bot Applied
#6 lore raw

[tip: timers/core] clocksource/drivers/fttmr010: Parametrise shutdown

In reply to Joel Stanley
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     84fb64c28acd85ae4d29b9c81926bdfa5f1bf25e
Gitweb:        https://git.kernel.org/tip/84fb64c28acd85ae4d29b9c81926bdfa5f1bf25e
Author:        Joel Stanley <[email protected]>
AuthorDate:    Thu, 07 Nov 2019 20:12:15 +10:30
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Fri, 21 Feb 2020 09:28:38 +01:00

clocksource/drivers/fttmr010: Parametrise shutdown

In preparation for supporting the ast2600 which uses a different method to clear bits in the control register, use a callback for performing the shutdown sequence.

---
 drivers/clocksource/timer-fttmr010.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/clocksource/timer-fttmr010.c +8 -11
index fadff79..c2d30eb 100644
@@ -97,6 +97,7 @@ struct fttmr010 {
 	bool is_aspeed;
 	u32 t1_enable_val;
 	struct clock_event_device clkevt;
+	int (*timer_shutdown)(struct clock_event_device *evt);
 #ifdef CONFIG_ARM
 	struct delay_timer delay_timer;
 #endif
@@ -140,9 +141,7 @@ static int fttmr010_timer_set_next_event(unsigned long cycles,
 	u32 cr;
 
 	/* Stop */
-	cr = readl(fttmr010->base + TIMER_CR);
-	cr &= ~fttmr010->t1_enable_val;
-	writel(cr, fttmr010->base + TIMER_CR);
+	fttmr010->timer_shutdown(evt);
 
 	if (fttmr010->is_aspeed) {
 		/*
@@ -183,9 +182,7 @@ static int fttmr010_timer_set_oneshot(struct clock_event_device *evt)
 	u32 cr;
 
 	/* Stop */
-	cr = readl(fttmr010->base + TIMER_CR);
-	cr &= ~fttmr010->t1_enable_val;
-	writel(cr, fttmr010->base + TIMER_CR);
+	fttmr010->timer_shutdown(evt);
 
 	/* Setup counter start from 0 or ~0 */
 	writel(0, fttmr010->base + TIMER1_COUNT);
@@ -211,9 +208,7 @@ static int fttmr010_timer_set_periodic(struct clock_event_device *evt)
 	u32 cr;
 
 	/* Stop */
-	cr = readl(fttmr010->base + TIMER_CR);
-	cr &= ~fttmr010->t1_enable_val;
-	writel(cr, fttmr010->base + TIMER_CR);
+	fttmr010->timer_shutdown(evt);
 
 	/* Setup timer to fire at 1/HZ intervals. */
 	if (fttmr010->is_aspeed) {
@@ -350,6 +345,8 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
 				     fttmr010->tick_rate);
 	}
 
+	fttmr010->timer_shutdown = fttmr010_timer_shutdown;
+
 	/*
 	 * Setup clockevent timer (interrupt-driven) on timer 1.
 	 */
@@ -370,10 +367,10 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
 	fttmr010->clkevt.features = CLOCK_EVT_FEAT_PERIODIC |
 		CLOCK_EVT_FEAT_ONESHOT;
 	fttmr010->clkevt.set_next_event = fttmr010_timer_set_next_event;
-	fttmr010->clkevt.set_state_shutdown = fttmr010_timer_shutdown;
+	fttmr010->clkevt.set_state_shutdown = fttmr010->timer_shutdown;
 	fttmr010->clkevt.set_state_periodic = fttmr010_timer_set_periodic;
 	fttmr010->clkevt.set_state_oneshot = fttmr010_timer_set_oneshot;
-	fttmr010->clkevt.tick_resume = fttmr010_timer_shutdown;
+	fttmr010->clkevt.tick_resume = fttmr010->timer_shutdown;
 	fttmr010->clkevt.cpumask = cpumask_of(0);
 	fttmr010->clkevt.irq = irq;
 	clockevents_config_and_register(&fttmr010->clkevt,
#7 lore raw

PATCH v2 2/4 clocksource: fttmr010: Set interrupt and shutdown

In reply to Joel Stanley

In preparation for supporting the ast2600, pass the shutdown and interrupt functions to the common init callback.

--
v2: call parameter 'irq_handler' instead of 'handler'

---
 drivers/clocksource/timer-fttmr010.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/clocksource/timer-fttmr010.c +12 -5
index c2d30eb9dc72..7c20a3debd96 100644
@@ -244,7 +244,10 @@ static irqreturn_t fttmr010_timer_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
+static int __init fttmr010_common_init(struct device_node *np,
+		bool is_aspeed,
+		int (*timer_shutdown)(struct clock_event_device *),
+		irq_handler_t irq_handler)
 {
 	struct fttmr010 *fttmr010;
 	int irq;
@@ -345,7 +348,7 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
 				     fttmr010->tick_rate);
 	}
 
-	fttmr010->timer_shutdown = fttmr010_timer_shutdown;
+	fttmr010->timer_shutdown = timer_shutdown;
 
 	/*
 	 * Setup clockevent timer (interrupt-driven) on timer 1.
@@ -354,7 +357,7 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
 	writel(0, fttmr010->base + TIMER1_LOAD);
 	writel(0, fttmr010->base + TIMER1_MATCH1);
 	writel(0, fttmr010->base + TIMER1_MATCH2);
-	ret = request_irq(irq, fttmr010_timer_interrupt, IRQF_TIMER,
+	ret = request_irq(irq, irq_handler, IRQF_TIMER,
 			  "FTTMR010-TIMER1", &fttmr010->clkevt);
 	if (ret) {
 		pr_err("FTTMR010-TIMER1 no IRQ\n");
@@ -403,12 +406,16 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
 
 static __init int aspeed_timer_init(struct device_node *np)
 {
-	return fttmr010_common_init(np, true);
+	return fttmr010_common_init(np, true,
+			fttmr010_timer_shutdown,
+			fttmr010_timer_interrupt);
 }
 
 static __init int fttmr010_timer_init(struct device_node *np)
 {
-	return fttmr010_common_init(np, false);
+	return fttmr010_common_init(np, false,
+			fttmr010_timer_shutdown,
+			fttmr010_timer_interrupt);
 }
 
 TIMER_OF_DECLARE(fttmr010, "faraday,fttmr010", fttmr010_timer_init);
Signature · 1 line
2.24.0.rc1
merge bot Applied
#8 lore raw

[tip: timers/core] clocksource/drivers/fttmr010: Set interrupt and shutdown

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     5422413ce56877f35415f6e4b53171e6e13ec4c1
Gitweb:        https://git.kernel.org/tip/5422413ce56877f35415f6e4b53171e6e13ec4c1
Author:        Joel Stanley <[email protected]>
AuthorDate:    Thu, 07 Nov 2019 20:12:16 +10:30
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Fri, 21 Feb 2020 09:28:38 +01:00

clocksource/drivers/fttmr010: Set interrupt and shutdown

In preparation for supporting the ast2600, pass the shutdown and interrupt functions to the common init callback.

---
 drivers/clocksource/timer-fttmr010.c | 51 ++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 5 deletions(-)
drivers/clocksource/timer-fttmr010.c +46 -5
index c2d30eb..edb1d5f 100644
@@ -38,6 +38,11 @@
 #define TIMER_CR		(0x30)
 
 /*
+ * Control register set to clear for ast2600 only.
+ */
+#define AST2600_TIMER_CR_CLR	(0x3c)
+
+/*
  * Control register (TMC30) bit fields for fttmr010/gemini/moxart timers.
  */
 #define TIMER_1_CR_ENABLE	BIT(0)
@@ -163,6 +168,16 @@ static int fttmr010_timer_set_next_event(unsigned long cycles,
 	return 0;
 }
 
+static int ast2600_timer_shutdown(struct clock_event_device *evt)
+{
+	struct fttmr010 *fttmr010 = to_fttmr010(evt);
+
+	/* Stop */
+	writel(fttmr010->t1_enable_val, fttmr010->base + AST2600_TIMER_CR_CLR);
+
+	return 0;
+}
+
 static int fttmr010_timer_shutdown(struct clock_event_device *evt)
 {
 	struct fttmr010 *fttmr010 = to_fttmr010(evt);
@@ -244,7 +259,21 @@ static irqreturn_t fttmr010_timer_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
+static irqreturn_t ast2600_timer_interrupt(int irq, void *dev_id)
+{
+	struct clock_event_device *evt = dev_id;
+	struct fttmr010 *fttmr010 = to_fttmr010(evt);
+
+	writel(0x1, fttmr010->base + TIMER_INTR_STATE);
+
+	evt->event_handler(evt);
+	return IRQ_HANDLED;
+}
+
+static int __init fttmr010_common_init(struct device_node *np,
+		bool is_aspeed,
+		int (*timer_shutdown)(struct clock_event_device *),
+		irq_handler_t irq_handler)
 {
 	struct fttmr010 *fttmr010;
 	int irq;
@@ -345,7 +374,7 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
 				     fttmr010->tick_rate);
 	}
 
-	fttmr010->timer_shutdown = fttmr010_timer_shutdown;
+	fttmr010->timer_shutdown = timer_shutdown;
 
 	/*
 	 * Setup clockevent timer (interrupt-driven) on timer 1.
@@ -354,7 +383,7 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)
 	writel(0, fttmr010->base + TIMER1_LOAD);
 	writel(0, fttmr010->base + TIMER1_MATCH1);
 	writel(0, fttmr010->base + TIMER1_MATCH2);
-	ret = request_irq(irq, fttmr010_timer_interrupt, IRQF_TIMER,
+	ret = request_irq(irq, irq_handler, IRQF_TIMER,
 			  "FTTMR010-TIMER1", &fttmr010->clkevt);
 	if (ret) {
 		pr_err("FTTMR010-TIMER1 no IRQ\n");
@@ -401,14 +430,25 @@ out_disable_clock:
 	return ret;
 }
 
+static __init int ast2600_timer_init(struct device_node *np)
+{
+	return fttmr010_common_init(np, true,
+			ast2600_timer_shutdown,
+			ast2600_timer_interrupt);
+}
+
 static __init int aspeed_timer_init(struct device_node *np)
 {
-	return fttmr010_common_init(np, true);
+	return fttmr010_common_init(np, true,
+			fttmr010_timer_shutdown,
+			fttmr010_timer_interrupt);
 }
 
 static __init int fttmr010_timer_init(struct device_node *np)
 {
-	return fttmr010_common_init(np, false);
+	return fttmr010_common_init(np, false,
+			fttmr010_timer_shutdown,
+			fttmr010_timer_interrupt);
 }
 
 TIMER_OF_DECLARE(fttmr010, "faraday,fttmr010", fttmr010_timer_init);
@@ -416,3 +456,4 @@ TIMER_OF_DECLARE(gemini, "cortina,gemini-timer", fttmr010_timer_init);
 TIMER_OF_DECLARE(moxart, "moxa,moxart-timer", fttmr010_timer_init);
 TIMER_OF_DECLARE(ast2400, "aspeed,ast2400-timer", aspeed_timer_init);
 TIMER_OF_DECLARE(ast2500, "aspeed,ast2500-timer", aspeed_timer_init);
+TIMER_OF_DECLARE(ast2600, "aspeed,ast2600-timer", ast2600_timer_init);
#9 lore raw

PATCH v2 3/4 clocksource: fttmr010: Add support for ast2600

In reply to Joel Stanley

The ast2600 has some minor differences to previous versions. The interrupt handler must acknowledge the timer interrupt in a status register. Secondly the control register becomes write to set only, requiring the use of a separate set to clear register.

--
v2: Add ast2600 prefix to define to make it clear it's for ast2600 only

---
 drivers/clocksource/timer-fttmr010.c | 34 ++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/clocksource/timer-fttmr010.c +34 -0
index 7c20a3debd96..1510ee106e8d 100644
@@ -37,6 +37,11 @@
 #define TIMER3_MATCH2		(0x2c)
 #define TIMER_CR		(0x30)
 
+/*
+  Control register set to clear for ast2600 only.
+ */
+#define AST2600_TIMER_CR_CLR	(0x3c)
+
 /*
  * Control register (TMC30) bit fields for fttmr010/gemini/moxart timers.
  */
@@ -163,6 +168,16 @@ static int fttmr010_timer_set_next_event(unsigned long cycles,
 	return 0;
 }
 
+static int ast2600_timer_shutdown(struct clock_event_device *evt)
+{
+	struct fttmr010 *fttmr010 = to_fttmr010(evt);
+
+	/* Stop */
+	writel(fttmr010->t1_enable_val, fttmr010->base + AST2600_TIMER_CR_CLR);
+
+	return 0;
+}
+
 static int fttmr010_timer_shutdown(struct clock_event_device *evt)
 {
 	struct fttmr010 *fttmr010 = to_fttmr010(evt);
@@ -244,6 +259,17 @@ static irqreturn_t fttmr010_timer_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static irqreturn_t ast2600_timer_interrupt(int irq, void *dev_id)
+{
+	struct clock_event_device *evt = dev_id;
+	struct fttmr010 *fttmr010 = to_fttmr010(evt);
+
+	writel(0x1, fttmr010->base + TIMER_INTR_STATE);
+
+	evt->event_handler(evt);
+	return IRQ_HANDLED;
+}
+
 static int __init fttmr010_common_init(struct device_node *np,
 		bool is_aspeed,
 		int (*timer_shutdown)(struct clock_event_device *),
@@ -404,6 +430,13 @@ static int __init fttmr010_common_init(struct device_node *np,
 	return ret;
 }
 
+static __init int ast2600_timer_init(struct device_node *np)
+{
+	return fttmr010_common_init(np, true,
+			ast2600_timer_shutdown,
+			ast2600_timer_interrupt);
+}
+
 static __init int aspeed_timer_init(struct device_node *np)
 {
 	return fttmr010_common_init(np, true,
@@ -423,3 +456,4 @@ TIMER_OF_DECLARE(gemini, "cortina,gemini-timer", fttmr010_timer_init);
 TIMER_OF_DECLARE(moxart, "moxa,moxart-timer", fttmr010_timer_init);
 TIMER_OF_DECLARE(ast2400, "aspeed,ast2400-timer", aspeed_timer_init);
 TIMER_OF_DECLARE(ast2500, "aspeed,ast2500-timer", aspeed_timer_init);
+TIMER_OF_DECLARE(ast2600, "aspeed,ast2600-timer", ast2600_timer_init);
Signature · 1 line
2.24.0.rc1
#10 lore raw

PATCH v2 4/4 dt-bindings: fttmr010: Add ast2600 compatible

In reply to Joel Stanley

The ast2600 contains a fttmr010 derivative.

---
 Documentation/devicetree/bindings/timer/faraday,fttmr010.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/timer/faraday,fttmr010.txt +1 -0
index 195792270414..3cb2f4c98d64 100644
@@ -11,6 +11,7 @@ Required properties:
   "moxa,moxart-timer", "faraday,fttmr010"
   "aspeed,ast2400-timer"
   "aspeed,ast2500-timer"
+  "aspeed,ast2600-timer"
 
 - reg : Should contain registers location and length
 - interrupts : Should contain the three timer interrupts usually with
Signature · 1 line
2.24.0.rc1
merge bot Applied
#11 lore raw

[tip: timers/core] dt-bindings: fttmr010: Add ast2600 compatible

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     5be8badcb64be4c6ac5b0e8b882eca8eb175ec2d
Gitweb:        https://git.kernel.org/tip/5be8badcb64be4c6ac5b0e8b882eca8eb175ec2d
Author:        Joel Stanley <[email protected]>
AuthorDate:    Thu, 07 Nov 2019 20:12:18 +10:30
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Fri, 21 Feb 2020 09:28:38 +01:00

dt-bindings: fttmr010: Add ast2600 compatible

The ast2600 contains a fttmr010 derivative.

---
 Documentation/devicetree/bindings/timer/faraday,fttmr010.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/timer/faraday,fttmr010.txt +1 -0
index 1957922..3cb2f4c 100644
@@ -11,6 +11,7 @@ Required properties:
   "moxa,moxart-timer", "faraday,fttmr010"
   "aspeed,ast2400-timer"
   "aspeed,ast2500-timer"
+  "aspeed,ast2600-timer"
 
 - reg : Should contain registers location and length
 - interrupts : Should contain the three timer interrupts usually with
#12 lore raw
In reply to Joel Stanley

Hi Daniel, Thomas, I noticed that this series never made it into the timer tree. Are you able to pick it up?

https://lore.kernel.org/lkml/[email protected]/

Cheers,

Joel

Quoted 22 lines · Joel Stanley

This series adds support for the AST2600 timer.

v2 adds r-b tags from Rob, Linus and Cédric (who reviewed the patches on the openbmc mailing list[1]). I made two small naming changes in this version that were suggested in review.

[1] https://patchwork.ozlabs.org/project/openbmc/list/?series=140990

Joel Stanley (4):
clocksource: fttmr010: Parametrise shutdown
clocksource: fttmr010: Set interrupt and shutdown
clocksource: fttmr010: Add support for ast2600
dt-bindings: fttmr010: Add ast2600 compatible

 .../bindings/timer/faraday,fttmr010.txt       |  1 +
 drivers/clocksource/timer-fttmr010.c          | 68 +++++++++++++++----
 2 files changed, 54 insertions(+), 15 deletions(-)

--
2.24.0.rc1

#13 lore raw
Quoted 2 lines · Joel Stanley

Hi Daniel, Thomas, I noticed that this series never made it into the timer tree. Are you able to pick it up?

Oops, missed it.

Incoming comments.

Quoted 29 lines

https://lore.kernel.org/lkml/[email protected]/

Cheers,

Joel

Quoted 22 lines · Joel Stanley

This series adds support for the AST2600 timer.

v2 adds r-b tags from Rob, Linus and Cédric (who reviewed the patches on the openbmc mailing list[1]). I made two small naming changes in this version that were suggested in review.

[1] https://patchwork.ozlabs.org/project/openbmc/list/?series=140990

Joel Stanley (4):
clocksource: fttmr010: Parametrise shutdown
clocksource: fttmr010: Set interrupt and shutdown
clocksource: fttmr010: Add support for ast2600
dt-bindings: fttmr010: Add ast2600 compatible

 .../bindings/timer/faraday,fttmr010.txt       |  1 +
 drivers/clocksource/timer-fttmr010.c          | 68 +++++++++++++++----
 2 files changed, 54 insertions(+), 15 deletions(-)

--
2.24.0.rc1

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog