summaryrefslogtreecommitdiff
path: root/drivers/clocksource
diff options
context:
space:
mode:
authorAlexander Kochetkov <al.kochet@gmail.com>2016-11-29 15:15:16 +0300
committerTao Huang <huangtao@rock-chips.com>2018-03-06 17:29:54 +0800
commit97eca46d527be335f7f1eb772aa5369a37c762a9 (patch)
treeba1f73a1b553392870c9d3d78408215ec537ecea /drivers/clocksource
parent7df9f2fba5458e2a478f82b44f7256e6bad98841 (diff)
clocksource/arm_global_timer: reconfigure clockevents after cpufreq change
After a cpufreq transition, update the clockevent's frequency by fetching the new clock rate from the clock framework and reprogram the next clock event. The clock supplying the arm-global-timer on the rk3188 is coming from the the cpu clock itself and thus changes its rate everytime cpufreq adjusts the cpu frequency. Found by code review, real impact not known. Assume what actual HZ value will be different from expected on platforms using arm-global-timer as clockevent. The patch is port of commit 4fd7f9b12810 ("ARM: 7212/1: smp_twd: reconfigure clockevents after cpufreq change") and commit 2b25d9f64b54 ("ARM: 7535/1: Reprogram smp_twd based on new common clk framework notifiers"). Change-Id: I82552f621e30254b9c48f22fb3ebd2866d4476c8 Signed-off-by: Alexander Kochetkov <al.kochet@gmail.com> Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
Diffstat (limited to 'drivers/clocksource')
-rw-r--r--drivers/clocksource/arm_global_timer.c93
1 files changed, 92 insertions, 1 deletions
diff --git a/drivers/clocksource/arm_global_timer.c b/drivers/clocksource/arm_global_timer.c
index a2cb6fae9295..949fee33eca0 100644
--- a/drivers/clocksource/arm_global_timer.c
+++ b/drivers/clocksource/arm_global_timer.c
@@ -48,6 +48,7 @@
* the units for all operations.
*/
static void __iomem *gt_base;
+static struct clk *gt_clk;
static unsigned long gt_clk_rate;
static int gt_ppi;
static struct clock_event_device __percpu *gt_evt;
@@ -136,6 +137,97 @@ static int gt_clockevent_set_next_event(unsigned long evt,
return 0;
}
+#ifdef CONFIG_COMMON_CLK
+
+/*
+ * Updates clockevent frequency when the cpu frequency changes.
+ * Called on the cpu that is changing frequency with interrupts disabled.
+ */
+static void gt_update_frequency(void *new_rate)
+{
+ gt_clk_rate = *((unsigned long *) new_rate);
+
+ clockevents_update_freq(raw_cpu_ptr(gt_evt), gt_clk_rate);
+}
+
+static int gt_rate_change(struct notifier_block *nb,
+ unsigned long flags, void *data)
+{
+ struct clk_notifier_data *cnd = data;
+
+ /*
+ * The gt clock events must be reprogrammed to account for the new
+ * frequency. The timer is local to a cpu, so cross-call to the
+ * changing cpu.
+ */
+ if (flags == POST_RATE_CHANGE)
+ on_each_cpu(gt_update_frequency,
+ (void *)&cnd->new_rate, 1);
+
+ return NOTIFY_OK;
+}
+
+static struct notifier_block gt_clk_nb = {
+ .notifier_call = gt_rate_change,
+};
+
+static int gt_clk_init(void)
+{
+ if (gt_evt && raw_cpu_ptr(gt_evt) && !IS_ERR(gt_clk))
+ return clk_notifier_register(gt_clk, &gt_clk_nb);
+
+ return 0;
+}
+core_initcall(gt_clk_init);
+
+#elif defined (CONFIG_CPU_FREQ)
+
+#include <linux/cpufreq.h>
+
+/*
+ * Updates clockevent frequency when the cpu frequency changes.
+ * Called on the cpu that is changing frequency with interrupts disabled.
+ */
+static void gt_update_frequency(void *data)
+{
+ gt_clk_rate = clk_get_rate(gt_clk);
+
+ clockevents_update_freq(raw_cpu_ptr(gt_evt), gt_clk_rate);
+}
+
+static int gt_cpufreq_transition(struct notifier_block *nb,
+ unsigned long state, void *data)
+{
+ struct cpufreq_freqs *freqs = data;
+
+ /*
+ * The gt clock events must be reprogrammed to account for the new
+ * frequency. The timer is local to a cpu, so cross-call to the
+ * changing cpu.
+ */
+ if (state == CPUFREQ_POSTCHANGE)
+ smp_call_function_single(freqs->cpu, gt_update_frequency,
+ NULL, 1);
+
+ return NOTIFY_OK;
+}
+
+static struct notifier_block gt_cpufreq_nb = {
+ .notifier_call = gt_cpufreq_transition,
+};
+
+static int gt_cpufreq_init(void)
+{
+ if (gt_evt && raw_cpu_ptr(gt_evt) && !IS_ERR(gt_clk))
+ return cpufreq_register_notifier(&gt_cpufreq_nb,
+ CPUFREQ_TRANSITION_NOTIFIER);
+
+ return 0;
+}
+core_initcall(gt_cpufreq_init);
+
+#endif
+
static irqreturn_t gt_clockevent_interrupt(int irq, void *dev_id)
{
struct clock_event_device *evt = dev_id;
@@ -244,7 +336,6 @@ static struct notifier_block gt_cpu_nb = {
static void __init global_timer_of_register(struct device_node *np)
{
- struct clk *gt_clk;
int err = 0;
/*