aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/ubicom32/files/arch/ubicom32/kernel/timer_broadcast.c
blob: 8f0cdc4d55194d19bc834a52882859081a88ca5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * arch/ubicom32/kernel/timer_broadcast.c
 *   Implements a dummy clock event for each cpu.
 *
 * Copyright (C) 2008  Paul Mundt
 * (C) Copyright 2009, Ubicom, Inc.
 *
 * This file is part of the Ubicom32 Linux Kernel Port.
 *
 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
 * it and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, either version 2 of the
 * License, or (at your option) any later version.
 *
 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 * the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Ubicom32 Linux Kernel Port.  If not,
 * see <http://www.gnu.org/licenses/>.
 *
 * Ubicom32 implementation derived from (with many thanks):
 *   arch/m68knommu
 *   arch/blackfin
 *   arch/parisc
 *   arch/arm
 *   arch/sh
 */
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/smp.h>
#include <linux/jiffies.h>
#include <linux/percpu.h>
#include <linux/clockchips.h>
#include <linux/irq.h>

static DEFINE_PER_CPU(struct clock_event_device, local_clockevent);

/*
 *  The broadcast trick only works when the timer will be used in a periodic mode.
 *  If the user has configured either NO_HZ or HIGH_RES_TIMERS they must have
 *  a per cpu timer.
 */
#if defined(CONFIG_NO_HZ) || defined(CONFIG_HIGH_RES_TIMERS)
#error "Tickless and High Resolution Timers require per-CPU local timers: CONFIG_LOCAL_TIMERS"
#endif

/*
 * local_timer_interrupt()
 *	Used on SMP for local timer interrupt sent via an IPI.
 */
void local_timer_interrupt(void)
{
	struct clock_event_device *dev = &__get_cpu_var(local_clockevent);

	dev->event_handler(dev);
}

/*
 * dummy_timer_set_next_event()
 *	Cause the timer to go off "cycles" from now.
 */
static int dummy_timer_set_next_event(unsigned long cycles, struct clock_event_device *dev)
{
	return 0;
}

/*
 * dummy_timer_set_mode()
 *	Do Nothing.
 */
static void dummy_timer_set_mode(enum clock_event_mode mode,
				 struct clock_event_device *clk)
{
}

/*
 * local_timer_setup()
 *	Adds a clock event for the specified cpu.
 */
int __cpuinit local_timer_setup(unsigned int cpu)
{
	struct clock_event_device *dev = &per_cpu(local_clockevent, cpu);

	dev->name		= "timer-dummy";
	dev->features		= CLOCK_EVT_FEAT_DUMMY;
	dev->rating		= 200;
	dev->mult		= 1;
	dev->set_mode		= dummy_timer_set_mode;
	dev->set_next_event	= dummy_timer_set_next_event;
	dev->broadcast		= smp_timer_broadcast;
	dev->cpumask		= cpumask_of_cpu(cpu);
	dev->irq		= -1;
	printk(KERN_NOTICE "timer[%d]: %s - created\n", dev->irq, dev->name);

	clockevents_register_device(dev);
	return 0;
}