mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: daniel.lezcano@linaro.org, tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org, benjamin.gaignard@linaro.org,
	Benjamin Gaignard <benjamin.gaignard@st.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@st.com>,
	linux-arm-kernel@lists.infradead.org (moderated list:ARM/STM32
	ARCHITECTURE)
Subject: [PATCH 10/12] clocksource/drivers/stm32: Add the clocksource
Date: Thu,  4 Jan 2018 13:50:26 +0100	[thread overview]
Message-ID: <1515070228-10481-11-git-send-email-daniel.lezcano@linaro.org> (raw)
In-Reply-To: <1515070228-10481-1-git-send-email-daniel.lezcano@linaro.org>

From: Benjamin Gaignard <benjamin.gaignard@st.com>

The scene is set for the clocksource, let's add it for this driver.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@st.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/clocksource/timer-stm32.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c
index 1891924..4634f4d 100644
--- a/drivers/clocksource/timer-stm32.c
+++ b/drivers/clocksource/timer-stm32.c
@@ -16,6 +16,7 @@
 #include <linux/of_irq.h>
 #include <linux/clk.h>
 #include <linux/reset.h>
+#include <linux/sched_clock.h>
 #include <linux/slab.h>
 
 #include "timer-of.h"
@@ -80,6 +81,13 @@ static int stm32_timer_of_bits_get(struct timer_of *to)
 	return pd->bits;
 }
 
+static void __iomem *stm32_timer_cnt __read_mostly;
+
+static u64 notrace stm32_read_sched_clock(void)
+{
+	return readl_relaxed(stm32_timer_cnt);
+}
+
 static void stm32_clock_event_disable(struct timer_of *to)
 {
 	writel_relaxed(0, timer_of_base(to) + TIM_DIER);
@@ -204,6 +212,31 @@ static void __init stm32_timer_set_prescaler(struct timer_of *to)
 	to->of_clk.period = DIV_ROUND_UP(to->of_clk.rate, HZ);
 }
 
+static int __init stm32_clocksource_init(struct timer_of *to)
+{
+        u32 bits = stm32_timer_of_bits_get(to);
+	const char *name = to->np->full_name;
+
+	/*
+	 * This driver allows to register several timers and relies on
+	 * the generic time framework to select the right one.
+	 * However, nothing allows to do the same for the
+	 * sched_clock. We are not interested in a sched_clock for the
+	 * 16bits timers but only for the 32bits, so if no 32bits
+	 * timer registered yet, we select this 32bits timer as a
+	 * sched_clock.
+	 */
+	if (bits == 32 && !stm32_timer_cnt) {
+		stm32_timer_cnt = timer_of_base(to) + TIM_CNT;
+		sched_clock_register(stm32_read_sched_clock, bits, timer_of_rate(to));
+		pr_info("%s: STM32 sched_clock registered\n", name);
+	}
+
+	return clocksource_mmio_init(timer_of_base(to) + TIM_CNT, name,
+				     timer_of_rate(to), bits == 32 ? 250 : 100,
+				     bits, clocksource_mmio_readl_up);
+}
+
 static void __init stm32_clockevent_init(struct timer_of *to)
 {
 	u32 bits = stm32_timer_of_bits_get(to);
@@ -256,6 +289,10 @@ static int __init stm32_timer_init(struct device_node *node)
 
 	stm32_timer_set_prescaler(to);
 
+	ret = stm32_clocksource_init(to);
+	if (ret)
+		goto deinit;
+
 	stm32_clockevent_init(to);
 	return 0;
 
-- 
2.7.4

  parent reply	other threads:[~2018-01-04 12:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-04 12:50 [PATCH 00/12] clocksource/drivers/stm32: Consolidate the timer Daniel Lezcano
2018-01-04 12:50 ` [PATCH 01/12] clocksource/drivers/timer-of: Store the device node pointer Daniel Lezcano
2018-01-04 12:50 ` [PATCH 02/12] clocksource/drivers/timer-of: Don't request the resource by name Daniel Lezcano
2018-01-04 12:50 ` [PATCH 03/12] clocksource/drivers/stm32: Fix kernel panic with multiple timers Daniel Lezcano
2018-01-04 12:50 ` [PATCH 04/12] clocksource/drivers/stm32: Convert the driver to timer-of Daniel Lezcano
2018-01-04 12:50 ` [PATCH 05/12] clocksource/drivers/stm32: Use the node name as timer name Daniel Lezcano
2018-01-04 12:50 ` [PATCH 06/12] clocksource/drivers/stm32: Encapsulate the timer width sorting out function Daniel Lezcano
2018-01-04 12:50 ` [PATCH 07/12] clocksource/drivers/stm32: Compute a prescaler value with a targeted rate Daniel Lezcano
2018-01-04 12:50 ` [PATCH 08/12] clocksource/drivers/stm32: Add the oneshot mode Daniel Lezcano
2018-01-04 12:50 ` [PATCH 09/12] clocksource/drivers/stm32: Encapsulate more the clockevent code Daniel Lezcano
2018-01-04 12:50 ` Daniel Lezcano [this message]
2018-01-04 12:50 ` [PATCH 11/12] clocksource/drivers/stm32: Add the timer delay Daniel Lezcano
2018-01-04 12:50 ` [PATCH 12/12] clocksource/drivers/stm32: Start the timer's counter sooner 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=1515070228-10481-11-git-send-email-daniel.lezcano@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=alexandre.torgue@st.com \
    --cc=benjamin.gaignard@linaro.org \
    --cc=benjamin.gaignard@st.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome