From: daniel.lezcano@linaro.org (Daniel Lezcano)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 06/11] clocksource: sun5i: Add clock notifiers
Date: Mon, 30 Mar 2015 22:17:08 +0200 [thread overview]
Message-ID: <1427746633-9137-6-git-send-email-daniel.lezcano@linaro.org> (raw)
In-Reply-To: <1427746633-9137-1-git-send-email-daniel.lezcano@linaro.org>
From: Maxime Ripard <maxime.ripard@free-electrons.com>
The parent clock of the sun5i timer is the AHB clock, which rate might change
because of other devices requirements.
This is for example the case on the Allwinner A31, where the DMA controller
needs a minimum rate higher than the default, that is enforced after the timer
driver has probed.
Add clock notifiers to make sure we reflect the clock rate changes in the timer
rates.
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
drivers/clocksource/timer-sun5i.c | 68 +++++++++++++++++++++++++++++++++++++--
1 file changed, 66 insertions(+), 2 deletions(-)
diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c
index 824ce2d..b3840f6 100644
--- a/drivers/clocksource/timer-sun5i.c
+++ b/drivers/clocksource/timer-sun5i.c
@@ -41,9 +41,13 @@
struct sun5i_timer {
void __iomem *base;
struct clk *clk;
+ struct notifier_block clk_rate_cb;
u32 ticks_per_jiffy;
};
+#define to_sun5i_timer(x) \
+ container_of(x, struct sun5i_timer, clk_rate_cb)
+
struct sun5i_timer_clksrc {
struct sun5i_timer timer;
struct clocksource clksrc;
@@ -152,6 +156,30 @@ static cycle_t sun5i_clksrc_read(struct clocksource *clksrc)
return ~readl(cs->timer.base + TIMER_CNTVAL_LO_REG(1));
}
+static int sun5i_rate_cb_clksrc(struct notifier_block *nb,
+ unsigned long event, void *data)
+{
+ struct clk_notifier_data *ndata = data;
+ struct sun5i_timer *timer = to_sun5i_timer(nb);
+ struct sun5i_timer_clksrc *cs = container_of(timer,
+ struct sun5i_timer_clksrc, timer);
+
+ switch (event) {
+ case PRE_RATE_CHANGE:
+ clocksource_unregister(&cs->clksrc);
+ break;
+
+ case POST_RATE_CHANGE:
+ clocksource_register_hz(&cs->clksrc, ndata->new_rate);
+ break;
+
+ default:
+ break;
+ }
+
+ return NOTIFY_DONE;
+}
+
static int __init sun5i_setup_clocksource(struct device_node *node,
void __iomem *base,
struct clk *clk, int irq)
@@ -174,6 +202,14 @@ static int __init sun5i_setup_clocksource(struct device_node *node,
cs->timer.base = base;
cs->timer.clk = clk;
+ cs->timer.clk_rate_cb.notifier_call = sun5i_rate_cb_clksrc;
+ cs->timer.clk_rate_cb.next = NULL;
+
+ ret = clk_notifier_register(clk, &cs->timer.clk_rate_cb);
+ if (ret) {
+ pr_err("Unable to register clock notifier.\n");
+ goto err_disable_clk;
+ }
writel(~0, base + TIMER_INTVAL_LO_REG(1));
writel(TIMER_CTL_ENABLE | TIMER_CTL_RELOAD,
@@ -188,11 +224,13 @@ static int __init sun5i_setup_clocksource(struct device_node *node,
ret = clocksource_register_hz(&cs->clksrc, rate);
if (ret) {
pr_err("Couldn't register clock source.\n");
- goto err_disable_clk;
+ goto err_remove_notifier;
}
return 0;
+err_remove_notifier:
+ clk_notifier_unregister(clk, &cs->timer.clk_rate_cb);
err_disable_clk:
clk_disable_unprepare(clk);
err_free:
@@ -200,6 +238,22 @@ err_free:
return ret;
}
+static int sun5i_rate_cb_clkevt(struct notifier_block *nb,
+ unsigned long event, void *data)
+{
+ struct clk_notifier_data *ndata = data;
+ struct sun5i_timer *timer = to_sun5i_timer(nb);
+ struct sun5i_timer_clkevt *ce = container_of(timer,
+ struct sun5i_timer_clkevt, timer);
+
+ if (event == POST_RATE_CHANGE) {
+ clockevents_update_freq(&ce->clkevt, ndata->new_rate);
+ ce->timer.ticks_per_jiffy = DIV_ROUND_UP(ndata->new_rate, HZ);
+ }
+
+ return NOTIFY_DONE;
+}
+
static int __init sun5i_setup_clockevent(struct device_node *node, void __iomem *base,
struct clk *clk, int irq)
{
@@ -223,6 +277,14 @@ static int __init sun5i_setup_clockevent(struct device_node *node, void __iomem
ce->timer.base = base;
ce->timer.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
ce->timer.clk = clk;
+ ce->timer.clk_rate_cb.notifier_call = sun5i_rate_cb_clkevt;
+ ce->timer.clk_rate_cb.next = NULL;
+
+ ret = clk_notifier_register(clk, &ce->timer.clk_rate_cb);
+ if (ret) {
+ pr_err("Unable to register clock notifier.\n");
+ goto err_disable_clk;
+ }
ce->clkevt.name = node->name;
ce->clkevt.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
@@ -243,11 +305,13 @@ static int __init sun5i_setup_clockevent(struct device_node *node, void __iomem
"sun5i_timer0", ce);
if (ret) {
pr_err("Unable to register interrupt\n");
- goto err_disable_clk;
+ goto err_remove_notifier;
}
return 0;
+err_remove_notifier:
+ clk_notifier_unregister(clk, &ce->timer.clk_rate_cb);
err_disable_clk:
clk_disable_unprepare(clk);
err_free:
--
1.9.1
next prev parent reply other threads:[~2015-03-30 20:17 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-30 20:14 [GIT PULL] clockevents for 4.1 Daniel Lezcano
2015-03-30 20:17 ` [PATCH 01/11] clocksource: arm_arch_timer: Rename arch_timer_probed to reflect behaviour Daniel Lezcano
2015-03-30 20:17 ` [PATCH 02/11] clocksource: sun5i: Switch to request_irq Daniel Lezcano
2015-03-30 20:17 ` [PATCH 03/11] clocksource: sun5i: Use of_io_request_and_map Daniel Lezcano
2015-03-30 20:17 ` [PATCH 04/11] clocksource: sun5i: Remove sched_clock Daniel Lezcano
2015-03-30 20:17 ` [PATCH 05/11] clocksource: sun5i: Refactor the current code Daniel Lezcano
2015-03-30 20:17 ` Daniel Lezcano [this message]
2015-03-30 20:17 ` [PATCH 07/11] clocksource: at91: Make IO endian agnostic Daniel Lezcano
2015-03-30 20:17 ` [PATCH 08/11] clocksource: sun4i-timer: Only register a sched_clock on sun4i and sun5i Daniel Lezcano
2015-03-30 20:17 ` [PATCH 09/11] clocksource: tegra: Maintain CPU endianness Daniel Lezcano
2015-03-30 20:17 ` [PATCH 10/11] clocksource: dw_apb_timer_of: Make IO endian agnostic Daniel Lezcano
2015-03-30 20:17 ` [PATCH 11/11] clocksource: efm32: Use CLOCK_EVT_FEAT_PERIODIC for defining features Daniel Lezcano
2015-03-31 7:14 ` [PATCH 01/11] clocksource: arm_arch_timer: Rename arch_timer_probed to reflect behaviour Ingo Molnar
2015-03-31 14:14 ` Laurent Pinchart
2015-03-31 15:49 ` Ingo Molnar
2015-03-31 7:17 ` [GIT PULL] clockevents for 4.1 Ingo Molnar
2015-03-31 9:37 ` Daniel Lezcano
2015-03-31 9:42 ` Ingo Molnar
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=1427746633-9137-6-git-send-email-daniel.lezcano@linaro.org \
--to=daniel.lezcano@linaro.org \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).