linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V
@ 2019-04-12  7:36 Sugaya Taichi
  2019-04-12  7:36 ` [PATCH v2 1/3] clocksource/drivers/timer-milbeaut: Fix to enable one-shot timer Sugaya Taichi
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Sugaya Taichi @ 2019-04-12  7:36 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, linux-kernel
  Cc: Takao Orito, Kazuhiro Kasai, Shinji Kanematsu, Jassi Brar,
	Masami Hiramatsu, Sugaya Taichi

This series fixes a bug and cleanup code about timer driver for
Milbeaut M10V.
Since it is difficult to separate, it is integrated into a series.

Changes from v1:
 -Add "Fixes" tag.

Sugaya Taichi (3):
  clocksource/drivers/timer-milbeaut: Fix to enable one-shot timer
  clocksource/drivers/timer-milbeaut: Add shutdown function
  clocksource/drivers/timer-milbeaut: Cleanup common register accesses

 drivers/clocksource/timer-milbeaut.c | 66 +++++++++++++++++++++++++-----------
 1 file changed, 47 insertions(+), 19 deletions(-)

-- 
1.9.1


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

* [PATCH v2 1/3] clocksource/drivers/timer-milbeaut: Fix to enable one-shot timer
  2019-04-12  7:36 [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V Sugaya Taichi
@ 2019-04-12  7:36 ` Sugaya Taichi
  2019-04-12  7:36 ` [PATCH v2 2/3] clocksource/drivers/timer-milbeaut: Add shutdown function Sugaya Taichi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Sugaya Taichi @ 2019-04-12  7:36 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, linux-kernel
  Cc: Takao Orito, Kazuhiro Kasai, Shinji Kanematsu, Jassi Brar,
	Masami Hiramatsu, Sugaya Taichi

Fix mlb_set_oneshot_state() to enable one-shot timer.
The function should stop and start a timer, but "start" statement was
dropped. Kick the register to start one-shot timer.

Fixes: b58f28f306db ("clocksource/drivers/timer-milbeaut: Introduce timer for Milbeaut SoCs")
Signed-off-by: Sugaya Taichi <sugaya.taichi@socionext.com>
---
 drivers/clocksource/timer-milbeaut.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/clocksource/timer-milbeaut.c b/drivers/clocksource/timer-milbeaut.c
index f2019a8..9fd5d08 100644
--- a/drivers/clocksource/timer-milbeaut.c
+++ b/drivers/clocksource/timer-milbeaut.c
@@ -80,6 +80,8 @@ static int mlb_set_state_oneshot(struct clock_event_device *clk)
 	u32 val = MLB_TMR_TMCSR_CSL_DIV2;
 
 	writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS);
+	val |= MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_TRG | MLB_TMR_TMCSR_INTE;
+	writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS);
 	return 0;
 }
 
-- 
1.9.1


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

* [PATCH v2 2/3] clocksource/drivers/timer-milbeaut: Add shutdown function
  2019-04-12  7:36 [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V Sugaya Taichi
  2019-04-12  7:36 ` [PATCH v2 1/3] clocksource/drivers/timer-milbeaut: Fix to enable one-shot timer Sugaya Taichi
@ 2019-04-12  7:36 ` Sugaya Taichi
  2019-04-12  7:36 ` [PATCH v2 3/3] clocksource/drivers/timer-milbeaut: Cleanup common register accesses Sugaya Taichi
  2019-04-12 11:09 ` [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V Daniel Lezcano
  3 siblings, 0 replies; 6+ messages in thread
From: Sugaya Taichi @ 2019-04-12  7:36 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, linux-kernel
  Cc: Takao Orito, Kazuhiro Kasai, Shinji Kanematsu, Jassi Brar,
	Masami Hiramatsu, Sugaya Taichi

Add a shutdown operation to support shutdown timer.

Signed-off-by: Sugaya Taichi <sugaya.taichi@socionext.com>
---
 drivers/clocksource/timer-milbeaut.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/clocksource/timer-milbeaut.c b/drivers/clocksource/timer-milbeaut.c
index 9fd5d08..f478061 100644
--- a/drivers/clocksource/timer-milbeaut.c
+++ b/drivers/clocksource/timer-milbeaut.c
@@ -85,6 +85,15 @@ static int mlb_set_state_oneshot(struct clock_event_device *clk)
 	return 0;
 }
 
+static int mlb_set_state_shutdown(struct clock_event_device *clk)
+{
+	struct timer_of *to = to_timer_of(clk);
+	u32 val = MLB_TMR_TMCSR_CSL_DIV2;
+
+	writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS);
+	return 0;
+}
+
 static int mlb_clkevt_next_event(unsigned long event,
 				   struct clock_event_device *clk)
 {
@@ -125,6 +134,7 @@ static int mlb_config_clock_event(struct timer_of *to)
 		.features = CLOCK_EVT_FEAT_DYNIRQ | CLOCK_EVT_FEAT_ONESHOT,
 		.set_state_oneshot = mlb_set_state_oneshot,
 		.set_state_periodic = mlb_set_state_periodic,
+		.set_state_shutdown = mlb_set_state_shutdown,
 		.set_next_event = mlb_clkevt_next_event,
 	},
 
-- 
1.9.1


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

* [PATCH v2 3/3] clocksource/drivers/timer-milbeaut: Cleanup common register accesses
  2019-04-12  7:36 [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V Sugaya Taichi
  2019-04-12  7:36 ` [PATCH v2 1/3] clocksource/drivers/timer-milbeaut: Fix to enable one-shot timer Sugaya Taichi
  2019-04-12  7:36 ` [PATCH v2 2/3] clocksource/drivers/timer-milbeaut: Add shutdown function Sugaya Taichi
@ 2019-04-12  7:36 ` Sugaya Taichi
  2019-04-12 11:09 ` [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V Daniel Lezcano
  3 siblings, 0 replies; 6+ messages in thread
From: Sugaya Taichi @ 2019-04-12  7:36 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, linux-kernel
  Cc: Takao Orito, Kazuhiro Kasai, Shinji Kanematsu, Jassi Brar,
	Masami Hiramatsu, Sugaya Taichi

Aggregate common register accesses into shared functions for
maintainability.

Signed-off-by: Sugaya Taichi <sugaya.taichi@socionext.com>
---
 drivers/clocksource/timer-milbeaut.c | 62 +++++++++++++++++++++++-------------
 1 file changed, 39 insertions(+), 23 deletions(-)

diff --git a/drivers/clocksource/timer-milbeaut.c b/drivers/clocksource/timer-milbeaut.c
index f478061..fa9fb4e 100644
--- a/drivers/clocksource/timer-milbeaut.c
+++ b/drivers/clocksource/timer-milbeaut.c
@@ -26,8 +26,8 @@
 #define MLB_TMR_TMCSR_CSL_DIV2	0
 #define MLB_TMR_DIV_CNT		2
 
-#define MLB_TMR_SRC_CH  (1)
-#define MLB_TMR_EVT_CH  (0)
+#define MLB_TMR_SRC_CH		1
+#define MLB_TMR_EVT_CH		0
 
 #define MLB_TMR_SRC_CH_OFS	(MLB_TMR_REGSZPCH * MLB_TMR_SRC_CH)
 #define MLB_TMR_EVT_CH_OFS	(MLB_TMR_REGSZPCH * MLB_TMR_EVT_CH)
@@ -43,6 +43,8 @@
 #define MLB_TMR_EVT_TMRLR2_OFS	(MLB_TMR_EVT_CH_OFS + MLB_TMR_TMRLR2_OFS)
 
 #define MLB_TIMER_RATING	500
+#define MLB_TIMER_ONESHOT	0
+#define MLB_TIMER_PERIODIC	1
 
 static irqreturn_t mlb_timer_interrupt(int irq, void *dev_id)
 {
@@ -59,38 +61,53 @@ static irqreturn_t mlb_timer_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-static int mlb_set_state_periodic(struct clock_event_device *clk)
+static void mlb_evt_timer_start(struct timer_of *to, bool periodic)
 {
-	struct timer_of *to = to_timer_of(clk);
 	u32 val = MLB_TMR_TMCSR_CSL_DIV2;
 
+	val |= MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_TRG | MLB_TMR_TMCSR_INTE;
+	if (periodic)
+		val |= MLB_TMR_TMCSR_RELD;
 	writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS);
+}
+
+static void mlb_evt_timer_stop(struct timer_of *to)
+{
+	u32 val = readl_relaxed(timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS);
 
-	writel_relaxed(to->of_clk.period, timer_of_base(to) +
-				MLB_TMR_EVT_TMRLR1_OFS);
-	val |= MLB_TMR_TMCSR_RELD | MLB_TMR_TMCSR_CNTE |
-		MLB_TMR_TMCSR_TRG | MLB_TMR_TMCSR_INTE;
+	val &= ~MLB_TMR_TMCSR_CNTE;
 	writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS);
+}
+
+static void mlb_evt_timer_register_count(struct timer_of *to, unsigned long cnt)
+{
+	writel_relaxed(cnt, timer_of_base(to) + MLB_TMR_EVT_TMRLR1_OFS);
+}
+
+static int mlb_set_state_periodic(struct clock_event_device *clk)
+{
+	struct timer_of *to = to_timer_of(clk);
+
+	mlb_evt_timer_stop(to);
+	mlb_evt_timer_register_count(to, to->of_clk.period);
+	mlb_evt_timer_start(to, MLB_TIMER_PERIODIC);
 	return 0;
 }
 
 static int mlb_set_state_oneshot(struct clock_event_device *clk)
 {
 	struct timer_of *to = to_timer_of(clk);
-	u32 val = MLB_TMR_TMCSR_CSL_DIV2;
 
-	writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS);
-	val |= MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_TRG | MLB_TMR_TMCSR_INTE;
-	writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS);
+	mlb_evt_timer_stop(to);
+	mlb_evt_timer_start(to, MLB_TIMER_ONESHOT);
 	return 0;
 }
 
 static int mlb_set_state_shutdown(struct clock_event_device *clk)
 {
 	struct timer_of *to = to_timer_of(clk);
-	u32 val = MLB_TMR_TMCSR_CSL_DIV2;
 
-	writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS);
+	mlb_evt_timer_stop(to);
 	return 0;
 }
 
@@ -99,22 +116,21 @@ static int mlb_clkevt_next_event(unsigned long event,
 {
 	struct timer_of *to = to_timer_of(clk);
 
-	writel_relaxed(event, timer_of_base(to) + MLB_TMR_EVT_TMRLR1_OFS);
-	writel_relaxed(MLB_TMR_TMCSR_CSL_DIV2 |
-			MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_INTE |
-			MLB_TMR_TMCSR_TRG, timer_of_base(to) +
-			MLB_TMR_EVT_TMCSR_OFS);
+	mlb_evt_timer_stop(to);
+	mlb_evt_timer_register_count(to, event);
+	mlb_evt_timer_start(to, MLB_TIMER_ONESHOT);
 	return 0;
 }
 
 static int mlb_config_clock_source(struct timer_of *to)
 {
-	writel_relaxed(0, timer_of_base(to) + MLB_TMR_SRC_TMCSR_OFS);
-	writel_relaxed(~0, timer_of_base(to) + MLB_TMR_SRC_TMR_OFS);
+	u32 val = MLB_TMR_TMCSR_CSL_DIV2;
+
+	writel_relaxed(val, timer_of_base(to) + MLB_TMR_SRC_TMCSR_OFS);
 	writel_relaxed(~0, timer_of_base(to) + MLB_TMR_SRC_TMRLR1_OFS);
 	writel_relaxed(~0, timer_of_base(to) + MLB_TMR_SRC_TMRLR2_OFS);
-	writel_relaxed(BIT(4) | BIT(1) | BIT(0), timer_of_base(to) +
-		MLB_TMR_SRC_TMCSR_OFS);
+	val |= MLB_TMR_TMCSR_RELD | MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_TRG;
+	writel_relaxed(val, timer_of_base(to) + MLB_TMR_SRC_TMCSR_OFS);
 	return 0;
 }
 
-- 
1.9.1


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

* Re: [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V
  2019-04-12  7:36 [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V Sugaya Taichi
                   ` (2 preceding siblings ...)
  2019-04-12  7:36 ` [PATCH v2 3/3] clocksource/drivers/timer-milbeaut: Cleanup common register accesses Sugaya Taichi
@ 2019-04-12 11:09 ` Daniel Lezcano
  2019-04-12 12:34   ` Sugaya, Taichi
  3 siblings, 1 reply; 6+ messages in thread
From: Daniel Lezcano @ 2019-04-12 11:09 UTC (permalink / raw)
  To: Sugaya Taichi, Thomas Gleixner, linux-kernel
  Cc: Takao Orito, Kazuhiro Kasai, Shinji Kanematsu, Jassi Brar,
	Masami Hiramatsu

On 12/04/2019 09:36, Sugaya Taichi wrote:
> This series fixes a bug and cleanup code about timer driver for
> Milbeaut M10V.
> Since it is difficult to separate, it is integrated into a series.
> 
> Changes from v1:
>  -Add "Fixes" tag.
> 
> Sugaya Taichi (3):
>   clocksource/drivers/timer-milbeaut: Fix to enable one-shot timer
>   clocksource/drivers/timer-milbeaut: Add shutdown function
>   clocksource/drivers/timer-milbeaut: Cleanup common register accesses
> 
>  drivers/clocksource/timer-milbeaut.c | 66 +++++++++++++++++++++++++-----------
>  1 file changed, 47 insertions(+), 19 deletions(-)

Series applied for 5.2

Thanks

  -- Daniel


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


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

* Re: [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V
  2019-04-12 11:09 ` [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V Daniel Lezcano
@ 2019-04-12 12:34   ` Sugaya, Taichi
  0 siblings, 0 replies; 6+ messages in thread
From: Sugaya, Taichi @ 2019-04-12 12:34 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, linux-kernel
  Cc: Takao Orito, Kazuhiro Kasai, Shinji Kanematsu, Jassi Brar,
	Masami Hiramatsu

Hi,

On 2019/04/12 20:09, Daniel Lezcano wrote:
> On 12/04/2019 09:36, Sugaya Taichi wrote:
>> This series fixes a bug and cleanup code about timer driver for
>> Milbeaut M10V.
>> Since it is difficult to separate, it is integrated into a series.
>>
>> Changes from v1:
>>   -Add "Fixes" tag.
>>
>> Sugaya Taichi (3):
>>    clocksource/drivers/timer-milbeaut: Fix to enable one-shot timer
>>    clocksource/drivers/timer-milbeaut: Add shutdown function
>>    clocksource/drivers/timer-milbeaut: Cleanup common register accesses
>>
>>   drivers/clocksource/timer-milbeaut.c | 66 +++++++++++++++++++++++++-----------
>>   1 file changed, 47 insertions(+), 19 deletions(-)
> 
> Series applied for 5.2
> 
> Thanks
> 
>    -- Daniel
> 
> 

Thank you!


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

end of thread, other threads:[~2019-04-12 12:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12  7:36 [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V Sugaya Taichi
2019-04-12  7:36 ` [PATCH v2 1/3] clocksource/drivers/timer-milbeaut: Fix to enable one-shot timer Sugaya Taichi
2019-04-12  7:36 ` [PATCH v2 2/3] clocksource/drivers/timer-milbeaut: Add shutdown function Sugaya Taichi
2019-04-12  7:36 ` [PATCH v2 3/3] clocksource/drivers/timer-milbeaut: Cleanup common register accesses Sugaya Taichi
2019-04-12 11:09 ` [PATCH v2 0/3] Bugfix and cleanup the timer driver for Milbeaut M10V Daniel Lezcano
2019-04-12 12:34   ` Sugaya, Taichi

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