Release 4.11 arch/arm/mach-mmp/time.c
/*
* linux/arch/arm/mach-mmp/time.c
*
* Support for clocksource and clockevents
*
* Copyright (C) 2008 Marvell International Ltd.
* All rights reserved.
*
* 2008-04-11: Jason Chagas <Jason.chagas@marvell.com>
* 2008-10-08: Bin Yang <bin.yang@marvell.com>
*
* The timers module actually includes three timers, each timer with up to
* three match comparators. Timer #0 is used here in free-running mode as
* the clock source, and match comparator #1 used as clock event device.
*
* 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/interrupt.h>
#include <linux/clockchips.h>
#include <linux/io.h>
#include <linux/irq.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/sched_clock.h>
#include <asm/mach/time.h>
#include "addr-map.h"
#include "regs-timers.h"
#include "regs-apbc.h"
#include "irqs.h"
#include "cputype.h"
#include "clock.h"
#ifdef CONFIG_CPU_MMP2
#define MMP_CLOCK_FREQ 6500000
#else
#define MMP_CLOCK_FREQ 3250000
#endif
#define TIMERS_VIRT_BASE TIMERS1_VIRT_BASE
#define MAX_DELTA (0xfffffffe)
#define MIN_DELTA (16)
static void __iomem *mmp_timer_base = TIMERS_VIRT_BASE;
/*
* FIXME: the timer needs some delay to stablize the counter capture
*/
static inline uint32_t timer_read(void)
{
int delay = 100;
__raw_writel(1, mmp_timer_base + TMR_CVWR(1));
while (delay--)
cpu_relax();
return __raw_readl(mmp_timer_base + TMR_CVWR(1));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Miao | 41 | 91.11% | 1 | 33.33% |
Lennert Buytenhek | 2 | 4.44% | 1 | 33.33% |
Haojian Zhuang | 2 | 4.44% | 1 | 33.33% |
Total | 45 | 100.00% | 3 | 100.00% |
static u64 notrace mmp_read_sched_clock(void)
{
return timer_read();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 9 | 69.23% | 1 | 33.33% |
Marc Zyngier | 3 | 23.08% | 1 | 33.33% |
Stephen Boyd | 1 | 7.69% | 1 | 33.33% |
Total | 13 | 100.00% | 3 | 100.00% |
static irqreturn_t timer_interrupt(int irq, void *dev_id)
{
struct clock_event_device *c = dev_id;
/*
* Clear pending interrupt status.
*/
__raw_writel(0x01, mmp_timer_base + TMR_ICR(0));
/*
* Disable timer 0.
*/
__raw_writel(0x02, mmp_timer_base + TMR_CER);
c->event_handler(c);
return IRQ_HANDLED;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Miao | 45 | 84.91% | 1 | 33.33% |
Lennert Buytenhek | 6 | 11.32% | 1 | 33.33% |
Haojian Zhuang | 2 | 3.77% | 1 | 33.33% |
Total | 53 | 100.00% | 3 | 100.00% |
static int timer_set_next_event(unsigned long delta,
struct clock_event_device *dev)
{
unsigned long flags;
local_irq_save(flags);
/*
* Disable timer 0.
*/
__raw_writel(0x02, mmp_timer_base + TMR_CER);
/*
* Clear and enable timer match 0 interrupt.
*/
__raw_writel(0x01, mmp_timer_base + TMR_ICR(0));
__raw_writel(0x01, mmp_timer_base + TMR_IER(0));
/*
* Setup new clockevent timer value.
*/
__raw_writel(delta - 1, mmp_timer_base + TMR_TN_MM(0, 0));
/*
* Enable timer 0.
*/
__raw_writel(0x03, mmp_timer_base + TMR_CER);
local_irq_restore(flags);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Miao | 66 | 70.21% | 1 | 33.33% |
Lennert Buytenhek | 23 | 24.47% | 1 | 33.33% |
Haojian Zhuang | 5 | 5.32% | 1 | 33.33% |
Total | 94 | 100.00% | 3 | 100.00% |
static int timer_set_shutdown(struct clock_event_device *evt)
{
unsigned long flags;
local_irq_save(flags);
/* disable the matching interrupt */
__raw_writel(0x00, mmp_timer_base + TMR_IER(0));
local_irq_restore(flags);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Miao | 34 | 82.93% | 1 | 33.33% |
Viresh Kumar | 6 | 14.63% | 1 | 33.33% |
Haojian Zhuang | 1 | 2.44% | 1 | 33.33% |
Total | 41 | 100.00% | 3 | 100.00% |
static struct clock_event_device ckevt = {
.name = "clockevent",
.features = CLOCK_EVT_FEAT_ONESHOT,
.rating = 200,
.set_next_event = timer_set_next_event,
.set_state_shutdown = timer_set_shutdown,
.set_state_oneshot = timer_set_shutdown,
};
static u64 clksrc_read(struct clocksource *cs)
{
return timer_read();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Miao | 10 | 66.67% | 1 | 33.33% |
Coly Li | 4 | 26.67% | 1 | 33.33% |
Thomas Gleixner | 1 | 6.67% | 1 | 33.33% |
Total | 15 | 100.00% | 3 | 100.00% |
static struct clocksource cksrc = {
.name = "clocksource",
.rating = 200,
.read = clksrc_read,
.mask = CLOCKSOURCE_MASK(32),
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
};
static void __init timer_config(void)
{
uint32_t ccr = __raw_readl(mmp_timer_base + TMR_CCR);
__raw_writel(0x0, mmp_timer_base + TMR_CER); /* disable */
ccr &= (cpu_is_mmp2()) ? (TMR_CCR_CS_0(0) | TMR_CCR_CS_1(0)) :
(TMR_CCR_CS_0(3) | TMR_CCR_CS_1(3));
__raw_writel(ccr, mmp_timer_base + TMR_CCR);
/* set timer 0 to periodic mode, and timer 1 to free-running mode */
__raw_writel(0x2, mmp_timer_base + TMR_CMR);
__raw_writel(0x1, mmp_timer_base + TMR_PLCR(0)); /* periodic */
__raw_writel(0x7, mmp_timer_base + TMR_ICR(0)); /* clear status */
__raw_writel(0x0, mmp_timer_base + TMR_IER(0));
__raw_writel(0x0, mmp_timer_base + TMR_PLCR(1)); /* free-running */
__raw_writel(0x7, mmp_timer_base + TMR_ICR(1)); /* clear status */
__raw_writel(0x0, mmp_timer_base + TMR_IER(1));
/* enable timer 1 counter */
__raw_writel(0x2, mmp_timer_base + TMR_CER);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Miao | 87 | 52.73% | 1 | 20.00% |
Lennert Buytenhek | 56 | 33.94% | 2 | 40.00% |
Haojian Zhuang | 22 | 13.33% | 2 | 40.00% |
Total | 165 | 100.00% | 5 | 100.00% |
static struct irqaction timer_irq = {
.name = "timer",
.flags = IRQF_TIMER | IRQF_IRQPOLL,
.handler = timer_interrupt,
.dev_id = &ckevt,
};
void __init timer_init(int irq)
{
timer_config();
sched_clock_register(mmp_read_sched_clock, 32, MMP_CLOCK_FREQ);
ckevt.cpumask = cpumask_of(0);
setup_irq(irq, &timer_irq);
clocksource_register_hz(&cksrc, MMP_CLOCK_FREQ);
clockevents_config_and_register(&ckevt, MMP_CLOCK_FREQ,
MIN_DELTA, MAX_DELTA);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Miao | 42 | 72.41% | 1 | 14.29% |
Shawn Guo | 6 | 10.34% | 1 | 14.29% |
Russell King | 5 | 8.62% | 2 | 28.57% |
Uwe Kleine-König | 3 | 5.17% | 1 | 14.29% |
Marc Zyngier | 1 | 1.72% | 1 | 14.29% |
Stephen Boyd | 1 | 1.72% | 1 | 14.29% |
Total | 58 | 100.00% | 7 | 100.00% |
#ifdef CONFIG_OF
static const struct of_device_id mmp_timer_dt_ids[] = {
{ .compatible = "mrvl,mmp-timer", },
{}
};
void __init mmp_dt_init_timer(void)
{
struct device_node *np;
int irq, ret;
np = of_find_matching_node(NULL, mmp_timer_dt_ids);
if (!np) {
ret = -ENODEV;
goto out;
}
irq = irq_of_parse_and_map(np, 0);
if (!irq) {
ret = -EINVAL;
goto out;
}
mmp_timer_base = of_iomap(np, 0);
if (!mmp_timer_base) {
ret = -ENOMEM;
goto out;
}
timer_init(irq);
return;
out:
pr_err("Failed to get timer from device tree with error:%d\n", ret);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Haojian Zhuang | 105 | 100.00% | 1 | 100.00% |
Total | 105 | 100.00% | 1 | 100.00% |
#endif
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Miao | 462 | 57.61% | 1 | 5.26% |
Haojian Zhuang | 182 | 22.69% | 2 | 10.53% |
Lennert Buytenhek | 87 | 10.85% | 3 | 15.79% |
Uwe Kleine-König | 19 | 2.37% | 2 | 10.53% |
Russell King | 14 | 1.75% | 2 | 10.53% |
Viresh Kumar | 13 | 1.62% | 1 | 5.26% |
Arnd Bergmann | 6 | 0.75% | 1 | 5.26% |
Shawn Guo | 6 | 0.75% | 1 | 5.26% |
Coly Li | 4 | 0.50% | 1 | 5.26% |
Marc Zyngier | 4 | 0.50% | 1 | 5.26% |
Stephen Boyd | 3 | 0.37% | 2 | 10.53% |
Lucas De Marchi | 1 | 0.12% | 1 | 5.26% |
Thomas Gleixner | 1 | 0.12% | 1 | 5.26% |
Total | 802 | 100.00% | 19 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.