Release 4.11 arch/arm/kernel/smp_twd.c
/*
* linux/arch/arm/kernel/smp_twd.c
*
* Copyright (C) 2002 ARM Ltd.
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/clk.h>
#include <linux/cpu.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/smp.h>
#include <linux/jiffies.h>
#include <linux/clockchips.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/of_irq.h>
#include <linux/of_address.h>
#include <asm/smp_twd.h>
/* set up by the platform code */
static void __iomem *twd_base;
static struct clk *twd_clk;
static unsigned long twd_timer_rate;
static DEFINE_PER_CPU(bool, percpu_setup_called);
static struct clock_event_device __percpu *twd_evt;
static unsigned int twd_features =
CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
static int twd_ppi;
static int twd_shutdown(struct clock_event_device *clk)
{
writel_relaxed(0, twd_base + TWD_TIMER_CONTROL);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Viresh Kumar | 22 | 95.65% | 1 | 50.00% |
Russell King | 1 | 4.35% | 1 | 50.00% |
Total | 23 | 100.00% | 2 | 100.00% |
static int twd_set_oneshot(struct clock_event_device *clk)
{
/* period set, and timer enabled in 'next_event' hook */
writel_relaxed(TWD_TIMER_CONTROL_IT_ENABLE | TWD_TIMER_CONTROL_ONESHOT,
twd_base + TWD_TIMER_CONTROL);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Viresh Kumar | 26 | 100.00% | 1 | 100.00% |
Total | 26 | 100.00% | 1 | 100.00% |
static int twd_set_periodic(struct clock_event_device *clk)
{
unsigned long ctrl = TWD_TIMER_CONTROL_ENABLE |
TWD_TIMER_CONTROL_IT_ENABLE |
TWD_TIMER_CONTROL_PERIODIC;
writel_relaxed(DIV_ROUND_CLOSEST(twd_timer_rate, HZ),
twd_base + TWD_TIMER_LOAD);
writel_relaxed(ctrl, twd_base + TWD_TIMER_CONTROL);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 33 | 70.21% | 2 | 40.00% |
Viresh Kumar | 8 | 17.02% | 1 | 20.00% |
Linus Walleij | 4 | 8.51% | 1 | 20.00% |
Ben Dooks | 2 | 4.26% | 1 | 20.00% |
Total | 47 | 100.00% | 5 | 100.00% |
static int twd_set_next_event(unsigned long evt,
struct clock_event_device *unused)
{
unsigned long ctrl = readl_relaxed(twd_base + TWD_TIMER_CONTROL);
ctrl |= TWD_TIMER_CONTROL_ENABLE;
writel_relaxed(evt, twd_base + TWD_TIMER_COUNTER);
writel_relaxed(ctrl, twd_base + TWD_TIMER_CONTROL);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 48 | 94.12% | 2 | 66.67% |
Ben Dooks | 3 | 5.88% | 1 | 33.33% |
Total | 51 | 100.00% | 3 | 100.00% |
/*
* local_timer_ack: checks for a local timer interrupt.
*
* If a local timer interrupt has occurred, acknowledge and return 1.
* Otherwise, return 0.
*/
static int twd_timer_ack(void)
{
if (readl_relaxed(twd_base + TWD_TIMER_INTSTAT)) {
writel_relaxed(1, twd_base + TWD_TIMER_INTSTAT);
return 1;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 31 | 91.18% | 1 | 33.33% |
Ben Dooks | 2 | 5.88% | 1 | 33.33% |
Marc Zyngier | 1 | 2.94% | 1 | 33.33% |
Total | 34 | 100.00% | 3 | 100.00% |
static void twd_timer_stop(void)
{
struct clock_event_device *clk = raw_cpu_ptr(twd_evt);
twd_shutdown(clk);
disable_percpu_irq(clk->irq);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Marc Zyngier | 20 | 66.67% | 2 | 40.00% |
Stephen Boyd | 8 | 26.67% | 1 | 20.00% |
Viresh Kumar | 1 | 3.33% | 1 | 20.00% |
Christoph Lameter | 1 | 3.33% | 1 | 20.00% |
Total | 30 | 100.00% | 5 | 100.00% |
#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 twd_update_frequency(void *new_rate)
{
twd_timer_rate = *((unsigned long *) new_rate);
clockevents_update_freq(raw_cpu_ptr(twd_evt), twd_timer_rate);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Michael Turquette | 25 | 78.12% | 1 | 33.33% |
Linus Walleij | 6 | 18.75% | 1 | 33.33% |
Christoph Lameter | 1 | 3.12% | 1 | 33.33% |
Total | 32 | 100.00% | 3 | 100.00% |
static int twd_rate_change(struct notifier_block *nb,
unsigned long flags, void *data)
{
struct clk_notifier_data *cnd = data;
/*
* The twd 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(twd_update_frequency,
(void *)&cnd->new_rate, 1);
return NOTIFY_OK;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Michael Turquette | 51 | 98.08% | 1 | 50.00% |
Jason Liu | 1 | 1.92% | 1 | 50.00% |
Total | 52 | 100.00% | 2 | 100.00% |
static struct notifier_block twd_clk_nb = {
.notifier_call = twd_rate_change,
};
static int twd_clk_init(void)
{
if (twd_evt && raw_cpu_ptr(twd_evt) && !IS_ERR(twd_clk))
return clk_notifier_register(twd_clk, &twd_clk_nb);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Michael Turquette | 34 | 97.14% | 1 | 50.00% |
Christoph Lameter | 1 | 2.86% | 1 | 50.00% |
Total | 35 | 100.00% | 2 | 100.00% |
core_initcall(twd_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 twd_update_frequency(void *data)
{
twd_timer_rate = clk_get_rate(twd_clk);
clockevents_update_freq(raw_cpu_ptr(twd_evt), twd_timer_rate);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Walleij | 20 | 74.07% | 1 | 33.33% |
Michael Turquette | 6 | 22.22% | 1 | 33.33% |
Christoph Lameter | 1 | 3.70% | 1 | 33.33% |
Total | 27 | 100.00% | 3 | 100.00% |
static int twd_cpufreq_transition(struct notifier_block *nb,
unsigned long state, void *data)
{
struct cpufreq_freqs *freqs = data;
/*
* The twd 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, twd_update_frequency,
NULL, 1);
return NOTIFY_OK;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Walleij | 47 | 95.92% | 1 | 50.00% |
Russell King | 2 | 4.08% | 1 | 50.00% |
Total | 49 | 100.00% | 2 | 100.00% |
static struct notifier_block twd_cpufreq_nb = {
.notifier_call = twd_cpufreq_transition,
};
static int twd_cpufreq_init(void)
{
if (twd_evt && raw_cpu_ptr(twd_evt) && !IS_ERR(twd_clk))
return cpufreq_register_notifier(&twd_cpufreq_nb,
CPUFREQ_TRANSITION_NOTIFIER);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Walleij | 28 | 80.00% | 1 | 33.33% |
Santosh Shilimkar | 6 | 17.14% | 1 | 33.33% |
Christoph Lameter | 1 | 2.86% | 1 | 33.33% |
Total | 35 | 100.00% | 3 | 100.00% |
core_initcall(twd_cpufreq_init);
#endif
static void twd_calibrate_rate(void)
{
unsigned long count;
u64 waitjiffies;
/*
* If this is the first time round, we need to work out how fast
* the timer ticks
*/
if (twd_timer_rate == 0) {
pr_info("Calibrating local timer... ");
/* Wait for a tick to start */
waitjiffies = get_jiffies_64() + 1;
while (get_jiffies_64() < waitjiffies)
udelay(10);
/* OK, now the tick has started, let's get the timer going */
waitjiffies += 5;
/* enable, no interrupt or reload */
writel_relaxed(0x1, twd_base + TWD_TIMER_CONTROL);
/* maximum value */
writel_relaxed(0xFFFFFFFFU, twd_base + TWD_TIMER_COUNTER);
while (get_jiffies_64() < waitjiffies)
udelay(10);
count = readl_relaxed(twd_base + TWD_TIMER_COUNTER);
twd_timer_rate = (0xFFFFFFFFU - count) * (HZ / 5);
pr_cont("%lu.%02luMHz.\n", twd_timer_rate / 1000000,
(twd_timer_rate / 10000) % 100);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 122 | 96.83% | 2 | 50.00% |
Ben Dooks | 3 | 2.38% | 1 | 25.00% |
Vitaly Kuzmichev | 1 | 0.79% | 1 | 25.00% |
Total | 126 | 100.00% | 4 | 100.00% |
static irqreturn_t twd_handler(int irq, void *dev_id)
{
struct clock_event_device *evt = dev_id;
if (twd_timer_ack()) {
evt->event_handler(evt);
return IRQ_HANDLED;
}
return IRQ_NONE;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Marc Zyngier | 40 | 100.00% | 1 | 100.00% |
Total | 40 | 100.00% | 1 | 100.00% |
static void twd_get_clock(struct device_node *np)
{
int err;
if (np)
twd_clk = of_clk_get(np, 0);
else
twd_clk = clk_get_sys("smp_twd", NULL);
if (IS_ERR(twd_clk)) {
pr_err("smp_twd: clock not found %d\n", (int) PTR_ERR(twd_clk));
return;
}
err = clk_prepare_enable(twd_clk);
if (err) {
pr_err("smp_twd: clock failed to prepare+enable: %d\n", err);
clk_put(twd_clk);
return;
}
twd_timer_rate = clk_get_rate(twd_clk);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Walleij | 60 | 64.52% | 2 | 66.67% |
Rob Herring | 33 | 35.48% | 1 | 33.33% |
Total | 93 | 100.00% | 3 | 100.00% |
/*
* Setup the local clock events for a CPU.
*/
static void twd_timer_setup(void)
{
struct clock_event_device *clk = raw_cpu_ptr(twd_evt);
int cpu = smp_processor_id();
/*
* If the basic setup for this CPU has been done before don't
* bother with the below.
*/
if (per_cpu(percpu_setup_called, cpu)) {
writel_relaxed(0, twd_base + TWD_TIMER_CONTROL);
clockevents_register_device(clk);
enable_percpu_irq(clk->irq, 0);
return;
}
per_cpu(percpu_setup_called, cpu) = true;
twd_calibrate_rate();
/*
* The following is done once per CPU the first time .setup() is
* called.
*/
writel_relaxed(0, twd_base + TWD_TIMER_CONTROL);
clk->name = "local_timer";
clk->features = twd_features;
clk->rating = 350;
clk->set_state_shutdown = twd_shutdown;
clk->set_state_periodic = twd_set_periodic;
clk->set_state_oneshot = twd_set_oneshot;
clk->tick_resume = twd_shutdown;
clk->set_next_event = twd_set_next_event;
clk->irq = twd_ppi;
clk->cpumask = cpumask_of(cpu);
clockevents_config_and_register(clk, twd_timer_rate,
0xf, 0xffffffff);
enable_percpu_irq(clk->irq, 0);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Walleij | 56 | 33.94% | 2 | 14.29% |
Russell King | 40 | 24.24% | 2 | 14.29% |
Marc Zyngier | 26 | 15.76% | 4 | 28.57% |
Viresh Kumar | 20 | 12.12% | 1 | 7.14% |
Stephen Boyd | 15 | 9.09% | 1 | 7.14% |
Varun Swara | 3 | 1.82% | 1 | 7.14% |
Will Deacon | 2 | 1.21% | 1 | 7.14% |
Ben Dooks | 2 | 1.21% | 1 | 7.14% |
Christoph Lameter | 1 | 0.61% | 1 | 7.14% |
Total | 165 | 100.00% | 14 | 100.00% |
static int twd_timer_starting_cpu(unsigned int cpu)
{
twd_timer_setup();
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Stephen Boyd | 9 | 56.25% | 1 | 50.00% |
Richard Cochran | 7 | 43.75% | 1 | 50.00% |
Total | 16 | 100.00% | 2 | 100.00% |
static int twd_timer_dying_cpu(unsigned int cpu)
{
twd_timer_stop();
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Richard Cochran | 10 | 62.50% | 1 | 33.33% |
Stephen Boyd | 3 | 18.75% | 1 | 33.33% |
Marc Zyngier | 3 | 18.75% | 1 | 33.33% |
Total | 16 | 100.00% | 3 | 100.00% |
static int __init twd_local_timer_common_register(struct device_node *np)
{
int err;
twd_evt = alloc_percpu(struct clock_event_device);
if (!twd_evt) {
err = -ENOMEM;
goto out_free;
}
err = request_percpu_irq(twd_ppi, twd_handler, "twd", twd_evt);
if (err) {
pr_err("twd: can't register interrupt %d (%d)\n", twd_ppi, err);
goto out_free;
}
cpuhp_setup_state_nocalls(CPUHP_AP_ARM_TWD_STARTING,
"arm/timer/twd:starting",
twd_timer_starting_cpu, twd_timer_dying_cpu);
twd_get_clock(np);
if (!of_property_read_bool(np, "always-on"))
twd_features |= CLOCK_EVT_FEAT_C3STOP;
/*
* Immediately configure the timer on the boot CPU, unless we need
* jiffies to be incrementing to calibrate the rate in which case
* setup the timer in late_time_init.
*/
if (twd_timer_rate)
twd_timer_setup();
else
late_time_init = twd_timer_setup;
return 0;
out_free:
iounmap(twd_base);
twd_base = NULL;
free_percpu(twd_evt);
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Marc Zyngier | 90 | 67.16% | 1 | 14.29% |
Stephen Boyd | 13 | 9.70% | 1 | 14.29% |
Marc Gonzalez | 12 | 8.96% | 1 | 14.29% |
Rob Herring | 9 | 6.72% | 1 | 14.29% |
Richard Cochran | 7 | 5.22% | 1 | 14.29% |
Russell King | 2 | 1.49% | 1 | 14.29% |
Thomas Gleixner | 1 | 0.75% | 1 | 14.29% |
Total | 134 | 100.00% | 7 | 100.00% |
int __init twd_local_timer_register(struct twd_local_timer *tlt)
{
if (twd_base || twd_evt)
return -EBUSY;
twd_ppi = tlt->res[1].start;
twd_base = ioremap(tlt->res[0].start, resource_size(&tlt->res[0]));
if (!twd_base)
return -ENOMEM;
return twd_local_timer_common_register(NULL);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Marc Zyngier | 69 | 95.83% | 2 | 66.67% |
Rob Herring | 3 | 4.17% | 1 | 33.33% |
Total | 72 | 100.00% | 3 | 100.00% |
#ifdef CONFIG_OF
static int __init twd_local_timer_of_register(struct device_node *np)
{
int err;
twd_ppi = irq_of_parse_and_map(np, 0);
if (!twd_ppi) {
err = -EINVAL;
goto out;
}
twd_base = of_iomap(np, 0);
if (!twd_base) {
err = -ENOMEM;
goto out;
}
err = twd_local_timer_common_register(np);
out:
WARN(err, "twd_local_timer_of_register failed (%d)\n", err);
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Marc Zyngier | 73 | 86.90% | 2 | 33.33% |
Rob Herring | 6 | 7.14% | 2 | 33.33% |
Daniel Lezcano | 4 | 4.76% | 1 | 16.67% |
Russell King | 1 | 1.19% | 1 | 16.67% |
Total | 84 | 100.00% | 6 | 100.00% |
CLOCKSOURCE_OF_DECLARE(arm_twd_a9, "arm,cortex-a9-twd-timer", twd_local_timer_of_register);
CLOCKSOURCE_OF_DECLARE(arm_twd_a5, "arm,cortex-a5-twd-timer", twd_local_timer_of_register);
CLOCKSOURCE_OF_DECLARE(arm_twd_11mp, "arm,arm11mp-twd-timer", twd_local_timer_of_register);
#endif
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Marc Zyngier | 346 | 25.39% | 6 | 17.14% |
Russell King | 329 | 24.14% | 6 | 17.14% |
Linus Walleij | 263 | 19.30% | 6 | 17.14% |
Michael Turquette | 144 | 10.56% | 1 | 2.86% |
Viresh Kumar | 77 | 5.65% | 1 | 2.86% |
Rob Herring | 75 | 5.50% | 2 | 5.71% |
Stephen Boyd | 51 | 3.74% | 1 | 2.86% |
Richard Cochran | 24 | 1.76% | 1 | 2.86% |
Marc Gonzalez | 15 | 1.10% | 1 | 2.86% |
Ben Dooks | 12 | 0.88% | 1 | 2.86% |
Daniel Lezcano | 7 | 0.51% | 2 | 5.71% |
Santosh Shilimkar | 6 | 0.44% | 1 | 2.86% |
Christoph Lameter | 6 | 0.44% | 1 | 2.86% |
Varun Swara | 3 | 0.22% | 1 | 2.86% |
Will Deacon | 2 | 0.15% | 1 | 2.86% |
Vitaly Kuzmichev | 1 | 0.07% | 1 | 2.86% |
Jason Liu | 1 | 0.07% | 1 | 2.86% |
Thomas Gleixner | 1 | 0.07% | 1 | 2.86% |
Total | 1363 | 100.00% | 35 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.