Release 4.12 drivers/clocksource/timer-prima2.c
  
  
  
/*
 * System timer for CSR SiRFprimaII
 *
 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
 *
 * Licensed under GPLv2 or later.
 */
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/clockchips.h>
#include <linux/clocksource.h>
#include <linux/bitops.h>
#include <linux/irq.h>
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/of_address.h>
#include <linux/sched_clock.h>
#define PRIMA2_CLOCK_FREQ 1000000
#define SIRFSOC_TIMER_COUNTER_LO	0x0000
#define SIRFSOC_TIMER_COUNTER_HI	0x0004
#define SIRFSOC_TIMER_MATCH_0		0x0008
#define SIRFSOC_TIMER_MATCH_1		0x000C
#define SIRFSOC_TIMER_MATCH_2		0x0010
#define SIRFSOC_TIMER_MATCH_3		0x0014
#define SIRFSOC_TIMER_MATCH_4		0x0018
#define SIRFSOC_TIMER_MATCH_5		0x001C
#define SIRFSOC_TIMER_STATUS		0x0020
#define SIRFSOC_TIMER_INT_EN		0x0024
#define SIRFSOC_TIMER_WATCHDOG_EN	0x0028
#define SIRFSOC_TIMER_DIV		0x002C
#define SIRFSOC_TIMER_LATCH		0x0030
#define SIRFSOC_TIMER_LATCHED_LO	0x0034
#define SIRFSOC_TIMER_LATCHED_HI	0x0038
#define SIRFSOC_TIMER_WDT_INDEX		5
#define SIRFSOC_TIMER_LATCH_BIT	 BIT(0)
#define SIRFSOC_TIMER_REG_CNT 11
static const u32 sirfsoc_timer_reg_list[SIRFSOC_TIMER_REG_CNT] = {
	SIRFSOC_TIMER_MATCH_0, SIRFSOC_TIMER_MATCH_1, SIRFSOC_TIMER_MATCH_2,
	SIRFSOC_TIMER_MATCH_3, SIRFSOC_TIMER_MATCH_4, SIRFSOC_TIMER_MATCH_5,
	SIRFSOC_TIMER_INT_EN, SIRFSOC_TIMER_WATCHDOG_EN, SIRFSOC_TIMER_DIV,
	SIRFSOC_TIMER_LATCHED_LO, SIRFSOC_TIMER_LATCHED_HI,
};
static u32 sirfsoc_timer_reg_val[SIRFSOC_TIMER_REG_CNT];
static void __iomem *sirfsoc_timer_base;
/* timer0 interrupt handler */
static irqreturn_t sirfsoc_timer_interrupt(int irq, void *dev_id)
{
	struct clock_event_device *ce = dev_id;
	WARN_ON(!(readl_relaxed(sirfsoc_timer_base + SIRFSOC_TIMER_STATUS) &
		BIT(0)));
	/* clear timer0 interrupt */
	writel_relaxed(BIT(0), sirfsoc_timer_base + SIRFSOC_TIMER_STATUS);
	ce->event_handler(ce);
	return IRQ_HANDLED;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Binghua Duan | 61 | 100.00% | 1 | 100.00% | 
| Total | 61 | 100.00% | 1 | 100.00% | 
/* read 64-bit timer counter */
static u64 notrace sirfsoc_timer_read(struct clocksource *cs)
{
	u64 cycles;
	/* latch the 64-bit timer counter */
	writel_relaxed(SIRFSOC_TIMER_LATCH_BIT,
		sirfsoc_timer_base + SIRFSOC_TIMER_LATCH);
	cycles = readl_relaxed(sirfsoc_timer_base + SIRFSOC_TIMER_LATCHED_HI);
	cycles = (cycles << 32) |
		readl_relaxed(sirfsoc_timer_base + SIRFSOC_TIMER_LATCHED_LO);
	return cycles;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Binghua Duan | 50 | 96.15% | 1 | 33.33% | 
| Thomas Gleixner | 1 | 1.92% | 1 | 33.33% | 
| JiSheng Zhang | 1 | 1.92% | 1 | 33.33% | 
| Total | 52 | 100.00% | 3 | 100.00% | 
static int sirfsoc_timer_set_next_event(unsigned long delta,
	struct clock_event_device *ce)
{
	unsigned long now, next;
	writel_relaxed(SIRFSOC_TIMER_LATCH_BIT,
		sirfsoc_timer_base + SIRFSOC_TIMER_LATCH);
	now = readl_relaxed(sirfsoc_timer_base + SIRFSOC_TIMER_LATCHED_LO);
	next = now + delta;
	writel_relaxed(next, sirfsoc_timer_base + SIRFSOC_TIMER_MATCH_0);
	writel_relaxed(SIRFSOC_TIMER_LATCH_BIT,
		sirfsoc_timer_base + SIRFSOC_TIMER_LATCH);
	now = readl_relaxed(sirfsoc_timer_base + SIRFSOC_TIMER_LATCHED_LO);
	return next - now > delta ? -ETIME : 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Binghua Duan | 84 | 100.00% | 1 | 100.00% | 
| Total | 84 | 100.00% | 1 | 100.00% | 
static int sirfsoc_timer_shutdown(struct clock_event_device *evt)
{
	u32 val = readl_relaxed(sirfsoc_timer_base + SIRFSOC_TIMER_INT_EN);
	writel_relaxed(val & ~BIT(0),
		       sirfsoc_timer_base + SIRFSOC_TIMER_INT_EN);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Binghua Duan | 30 | 76.92% | 1 | 50.00% | 
| Viresh Kumar | 9 | 23.08% | 1 | 50.00% | 
| Total | 39 | 100.00% | 2 | 100.00% | 
static int sirfsoc_timer_set_oneshot(struct clock_event_device *evt)
{
	u32 val = readl_relaxed(sirfsoc_timer_base + SIRFSOC_TIMER_INT_EN);
	writel_relaxed(val | BIT(0), sirfsoc_timer_base + SIRFSOC_TIMER_INT_EN);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Viresh Kumar | 24 | 63.16% | 1 | 50.00% | 
| Binghua Duan | 14 | 36.84% | 1 | 50.00% | 
| Total | 38 | 100.00% | 2 | 100.00% | 
static void sirfsoc_clocksource_suspend(struct clocksource *cs)
{
	int i;
	writel_relaxed(SIRFSOC_TIMER_LATCH_BIT,
		sirfsoc_timer_base + SIRFSOC_TIMER_LATCH);
	for (i = 0; i < SIRFSOC_TIMER_REG_CNT; i++)
		sirfsoc_timer_reg_val[i] =
			readl_relaxed(sirfsoc_timer_base +
				sirfsoc_timer_reg_list[i]);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Barry Song | 51 | 100.00% | 1 | 100.00% | 
| Total | 51 | 100.00% | 1 | 100.00% | 
static void sirfsoc_clocksource_resume(struct clocksource *cs)
{
	int i;
	for (i = 0; i < SIRFSOC_TIMER_REG_CNT - 2; i++)
		writel_relaxed(sirfsoc_timer_reg_val[i],
			sirfsoc_timer_base + sirfsoc_timer_reg_list[i]);
	writel_relaxed(sirfsoc_timer_reg_val[SIRFSOC_TIMER_REG_CNT - 2],
		sirfsoc_timer_base + SIRFSOC_TIMER_COUNTER_LO);
	writel_relaxed(sirfsoc_timer_reg_val[SIRFSOC_TIMER_REG_CNT - 1],
		sirfsoc_timer_base + SIRFSOC_TIMER_COUNTER_HI);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Barry Song | 72 | 100.00% | 2 | 100.00% | 
| Total | 72 | 100.00% | 2 | 100.00% | 
static struct clock_event_device sirfsoc_clockevent = {
	.name = "sirfsoc_clockevent",
	.rating = 200,
	.features = CLOCK_EVT_FEAT_ONESHOT,
	.set_state_shutdown = sirfsoc_timer_shutdown,
	.set_state_oneshot = sirfsoc_timer_set_oneshot,
	.set_next_event = sirfsoc_timer_set_next_event,
};
static struct clocksource sirfsoc_clocksource = {
	.name = "sirfsoc_clocksource",
	.rating = 200,
	.mask = CLOCKSOURCE_MASK(64),
	.flags = CLOCK_SOURCE_IS_CONTINUOUS,
	.read = sirfsoc_timer_read,
	.suspend = sirfsoc_clocksource_suspend,
	.resume = sirfsoc_clocksource_resume,
};
static struct irqaction sirfsoc_timer_irq = {
	.name = "sirfsoc_timer0",
	.flags = IRQF_TIMER,
	.irq = 0,
	.handler = sirfsoc_timer_interrupt,
	.dev_id = &sirfsoc_clockevent,
};
/* Overwrite weak default sched_clock with more precise one */
static u64 notrace sirfsoc_read_sched_clock(void)
{
	return sirfsoc_timer_read(NULL);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Binghua Duan | 12 | 80.00% | 1 | 33.33% | 
| Marc Zyngier | 2 | 13.33% | 1 | 33.33% | 
| Stephen Boyd | 1 | 6.67% | 1 | 33.33% | 
| Total | 15 | 100.00% | 3 | 100.00% | 
static void __init sirfsoc_clockevent_init(void)
{
	sirfsoc_clockevent.cpumask = cpumask_of(0);
	clockevents_config_and_register(&sirfsoc_clockevent, PRIMA2_CLOCK_FREQ,
					2, -2);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Binghua Duan | 23 | 74.19% | 1 | 33.33% | 
| Shawn Guo | 7 | 22.58% | 1 | 33.33% | 
| Uwe Kleine-König | 1 | 3.23% | 1 | 33.33% | 
| Total | 31 | 100.00% | 3 | 100.00% | 
/* initialize the kernel jiffy timer source */
static int __init sirfsoc_prima2_timer_init(struct device_node *np)
{
	unsigned long rate;
	struct clk *clk;
	int ret;
	clk = of_clk_get(np, 0);
	if (IS_ERR(clk)) {
		pr_err("Failed to get clock\n");
		return PTR_ERR(clk);
	}
	ret = clk_prepare_enable(clk);
	if (ret) {
		pr_err("Failed to enable clock\n");
		return ret;
	}
	rate = clk_get_rate(clk);
	if (rate < PRIMA2_CLOCK_FREQ || rate % PRIMA2_CLOCK_FREQ) {
		pr_err("Invalid clock rate\n");
		return -EINVAL;
	}
	sirfsoc_timer_base = of_iomap(np, 0);
	if (!sirfsoc_timer_base) {
		pr_err("unable to map timer cpu registers\n");
		return -ENXIO;
	}
	sirfsoc_timer_irq.irq = irq_of_parse_and_map(np, 0);
	writel_relaxed(rate / PRIMA2_CLOCK_FREQ / 2 - 1,
		sirfsoc_timer_base + SIRFSOC_TIMER_DIV);
	writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_COUNTER_LO);
	writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_COUNTER_HI);
	writel_relaxed(BIT(0), sirfsoc_timer_base + SIRFSOC_TIMER_STATUS);
	ret = clocksource_register_hz(&sirfsoc_clocksource, PRIMA2_CLOCK_FREQ);
	if (ret) {
		pr_err("Failed to register clocksource\n");
		return ret;
	}
	sched_clock_register(sirfsoc_read_sched_clock, 64, PRIMA2_CLOCK_FREQ);
	ret = setup_irq(sirfsoc_timer_irq.irq, &sirfsoc_timer_irq);
	if (ret) {
		pr_err("Failed to setup irq\n");
		return ret;
	}
	sirfsoc_clockevent_init();
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Binghua Duan | 105 | 42.34% | 2 | 18.18% | 
| Daniel Lezcano | 80 | 32.26% | 1 | 9.09% | 
| Arnd Bergmann | 33 | 13.31% | 1 | 9.09% | 
| Zhiwu Song | 10 | 4.03% | 2 | 18.18% | 
| Marc Zyngier | 7 | 2.82% | 1 | 9.09% | 
| Uwe Kleine-König | 5 | 2.02% | 1 | 9.09% | 
| Rafał Miłecki | 5 | 2.02% | 1 | 9.09% | 
| Stephen Boyd | 2 | 0.81% | 1 | 9.09% | 
| Barry Song | 1 | 0.40% | 1 | 9.09% | 
| Total | 248 | 100.00% | 11 | 100.00% | 
CLOCKSOURCE_OF_DECLARE(sirfsoc_prima2_timer,
	"sirf,prima2-tick", sirfsoc_prima2_timer_init);
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Binghua Duan | 595 | 60.71% | 2 | 10.00% | 
| Barry Song | 177 | 18.06% | 3 | 15.00% | 
| Daniel Lezcano | 81 | 8.27% | 2 | 10.00% | 
| Arnd Bergmann | 40 | 4.08% | 2 | 10.00% | 
| Viresh Kumar | 40 | 4.08% | 1 | 5.00% | 
| Uwe Kleine-König | 10 | 1.02% | 1 | 5.00% | 
| Zhiwu Song | 10 | 1.02% | 2 | 10.00% | 
| Marc Zyngier | 9 | 0.92% | 1 | 5.00% | 
| Shawn Guo | 7 | 0.71% | 1 | 5.00% | 
| Rafał Miłecki | 5 | 0.51% | 1 | 5.00% | 
| Stephen Boyd | 4 | 0.41% | 2 | 10.00% | 
| Thomas Gleixner | 1 | 0.10% | 1 | 5.00% | 
| JiSheng Zhang | 1 | 0.10% | 1 | 5.00% | 
| Total | 980 | 100.00% | 20 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.