public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Daniel Lezcano <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: alexandre.torgue@st.com, linux-kernel@vger.kernel.org,
	tglx@linutronix.de, hpa@zytor.com, mcoquelin.stm32@gmail.com,
	benjamin.gaignard@st.com, mingo@kernel.org, peterz@infradead.org,
	daniel.lezcano@linaro.org, torvalds@linux-foundation.org
Subject: [tip:timers/core] clocksource/drivers/stm32: Factor out the timer width sorting code
Date: Mon, 8 Jan 2018 09:31:48 -0800	[thread overview]
Message-ID: <tip-70c62cf910aeba7cb79f4ebc7e6c8edbb37a77f6@git.kernel.org> (raw)
In-Reply-To: <1515418139-23276-14-git-send-email-daniel.lezcano@linaro.org>

Commit-ID:  70c62cf910aeba7cb79f4ebc7e6c8edbb37a77f6
Gitweb:     https://git.kernel.org/tip/70c62cf910aeba7cb79f4ebc7e6c8edbb37a77f6
Author:     Daniel Lezcano <daniel.lezcano@linaro.org>
AuthorDate: Mon, 8 Jan 2018 14:28:53 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 8 Jan 2018 17:57:25 +0100

clocksource/drivers/stm32: Factor out the timer width sorting code

In order to clarify and encapsulate the code for upcoming changes, move the
timer width check into a function and add some documentation.

Tested-by: Benjamin Gaignard <benjamin.gaignard@st.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Acked-by: Benjamin Gaignard <benjamin.gaignard@st.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1515418139-23276-14-git-send-email-daniel.lezcano@linaro.org
[ Spelling fixes. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 drivers/clocksource/timer-stm32.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c
index 14b7a2b..33c7c90 100644
--- a/drivers/clocksource/timer-stm32.c
+++ b/drivers/clocksource/timer-stm32.c
@@ -80,9 +80,27 @@ static irqreturn_t stm32_clock_event_handler(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+/**
+ * stm32_timer_width - Sort out the timer width (32/16)
+ * @to: a pointer to a timer-of structure
+ *
+ * Write the 32-bit max value and read/return the result. If the timer
+ * is 32 bits wide, the result will be UINT_MAX, otherwise it will
+ * be truncated by the 16-bit register to USHRT_MAX.
+ *
+ * Returns UINT_MAX if the timer is 32 bits wide, USHRT_MAX if it is a
+ * 16 bits wide.
+ */
+static u32 __init stm32_timer_width(struct timer_of *to)
+{
+	writel_relaxed(UINT_MAX, timer_of_base(to) + TIM_ARR);
+
+	return readl_relaxed(timer_of_base(to) + TIM_ARR);
+}
+
 static void __init stm32_clockevent_init(struct timer_of *to)
 {
-	unsigned long max_delta;
+	u32 width = 0;
 	int prescaler;
 
 	to->clkevt.name = to->np->full_name;
@@ -93,10 +111,8 @@ static void __init stm32_clockevent_init(struct timer_of *to)
 	to->clkevt.tick_resume = stm32_clock_event_shutdown;
 	to->clkevt.set_next_event = stm32_clock_event_set_next_event;
 
-	/* Detect whether the timer is 16 or 32 bits */
-	writel_relaxed(~0U, timer_of_base(to) + TIM_ARR);
-	max_delta = readl_relaxed(timer_of_base(to) + TIM_ARR);
-	if (max_delta == ~0U) {
+	width = stm32_timer_width(to);
+	if (width == UINT_MAX) {
 		prescaler = 1;
 		to->clkevt.rating = 250;
 	} else {
@@ -115,10 +131,10 @@ static void __init stm32_clockevent_init(struct timer_of *to)
 	to->of_clk.period = DIV_ROUND_UP(to->of_clk.rate, HZ);
 
 	clockevents_config_and_register(&to->clkevt,
-					timer_of_rate(to), 0x1, max_delta);
+					timer_of_rate(to), 0x1, width);
 
 	pr_info("%pOF: STM32 clockevent driver initialized (%d bits)\n",
-		to->np, max_delta == UINT_MAX ? 32 : 16);
+		to->np, width == UINT_MAX ? 32 : 16);
 }
 
 static int __init stm32_timer_init(struct device_node *node)

  reply	other threads:[~2018-01-08 17:36 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-08 13:27 [PULL] clockevents for 4.16 Daniel Lezcano
2018-01-08 13:28 ` [PATCH 01/20] dt-bindings: timer: Add Actions Semi S700 Daniel Lezcano
2018-01-08 13:28   ` [PATCH 02/20] clocksource/drivers/owl: Adopt TIMER_OF_DECLARE() Daniel Lezcano
2018-01-08 13:28   ` [PATCH 03/20] clocksource/drivers/owl: Add the S700 Daniel Lezcano
2018-01-08 13:28   ` [PATCH 04/20] clocksource/drivers/tcb_clksrc: Fix clock speed message Daniel Lezcano
2018-01-08 17:27     ` [tip:timers/core] " tip-bot for Romain Izard
2018-01-08 13:28   ` [PATCH 05/20] clocksource/drivers/timer-of: Fix function names Daniel Lezcano
2018-01-08 17:27     ` [tip:timers/core] " tip-bot for Daniel Lezcano
2018-01-08 13:28   ` [PATCH 06/20] clocksource/drivers/timer-of: Add kernel documentation Daniel Lezcano
2018-01-08 17:28     ` [tip:timers/core] " tip-bot for Daniel Lezcano
2018-01-08 13:28   ` [PATCH 07/20] dt-bindings: clocksource: Add Spreadtrum SC9860 timer Daniel Lezcano
2018-01-08 17:28     ` [tip:timers/core] dt-bindings/clocksource: Add Spreadtrum SC9860 timer documentation tip-bot for Baolin Wang
2018-01-08 13:28   ` [PATCH 08/20] clocksource/drivers/spreadtrum: Add timer driver for Spreadtrum SC9860 platform Daniel Lezcano
2018-01-08 17:29     ` [tip:timers/core] clocksource/drivers/spreadtrum: Add timer driver for the " tip-bot for Baolin Wang
2018-01-08 13:28   ` [PATCH 09/20] clocksource/drivers/timer-of: Store the device node pointer Daniel Lezcano
2018-01-08 17:29     ` [tip:timers/core] clocksource/drivers/timer-of: Store the device node pointer in 'struct timer_of' tip-bot for Daniel Lezcano
2018-01-08 13:28   ` [PATCH 10/20] clocksource/drivers/timer-of: Don't request the resource by name Daniel Lezcano
2018-01-08 17:30     ` [tip:timers/core] " tip-bot for Daniel Lezcano
2018-01-08 13:28   ` [PATCH 11/20] clocksource/drivers/stm32: Fix kernel panic with multiple timers Daniel Lezcano
2018-01-08 17:30     ` [tip:timers/core] " tip-bot for Daniel Lezcano
2018-01-08 13:28   ` [PATCH 12/20] clocksource/drivers/stm32: Convert the driver to timer-of Daniel Lezcano
2018-01-08 17:30     ` [tip:timers/core] clocksource/drivers/stm32: Convert the driver to timer_of primitives tip-bot for Benjamin Gaignard
2018-01-08 13:28   ` [PATCH 13/20] clocksource/drivers/stm32: Use the node name as timer name Daniel Lezcano
2018-01-08 17:31     ` [tip:timers/core] " tip-bot for Daniel Lezcano
2018-01-08 13:28   ` [PATCH 14/20] clocksource/drivers/stm32: Encapsulate the timer width sorting out function Daniel Lezcano
2018-01-08 17:31     ` tip-bot for Daniel Lezcano [this message]
2018-01-08 13:28   ` [PATCH 15/20] clocksource/drivers/stm32: Compute a prescaler value with a targeted rate Daniel Lezcano
2018-01-08 17:32     ` [tip:timers/core] " tip-bot for Benjamin Gaignard
2018-01-08 13:28   ` [PATCH 16/20] clocksource/drivers/stm32: Add the oneshot mode Daniel Lezcano
2018-01-08 17:32     ` [tip:timers/core] clocksource/drivers/stm32: Add " tip-bot for Benjamin Gaignard
2018-01-08 13:28   ` [PATCH 17/20] clocksource/drivers/stm32: Encapsulate more the clockevent code Daniel Lezcano
2018-01-08 17:33     ` [tip:timers/core] clocksource/drivers/stm32: Factor out more of " tip-bot for Daniel Lezcano
2018-01-08 13:28   ` [PATCH 18/20] clocksource/drivers/stm32: Add the clocksource Daniel Lezcano
2018-01-08 17:33     ` [tip:timers/core] clocksource/drivers/stm32: Add clocksource functionality tip-bot for Benjamin Gaignard
2018-01-08 13:28   ` [PATCH 19/20] clocksource/drivers/stm32: Add the timer delay Daniel Lezcano
2018-01-08 17:33     ` [tip:timers/core] clocksource/drivers/stm32: Add the timer delay callback tip-bot for Daniel Lezcano
2018-01-08 13:28   ` [PATCH 20/20] clocksource/drivers/stm32: Start the timer's counter sooner Daniel Lezcano
2018-01-08 17:34     ` [tip:timers/core] " tip-bot for Daniel Lezcano
2018-01-08 16:58 ` [PULL] clockevents for 4.16 Ingo Molnar
2018-01-08 17:07   ` Daniel Lezcano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-70c62cf910aeba7cb79f4ebc7e6c8edbb37a77f6@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=alexandre.torgue@st.com \
    --cc=benjamin.gaignard@st.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox