Root/target/linux/ubicom32/files/arch/ubicom32/kernel/timer_tick.c

1/*
2 * arch/ubicom32/kernel/timer_tick.c
3 * Impelemets a perodic timer.
4 *
5 * (C) Copyright 2009, Ubicom, Inc.
6 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
7 *
8 * This file is part of the Ubicom32 Linux Kernel Port.
9 *
10 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
11 * it and/or modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation, either version 2 of the
13 * License, or (at your option) any later version.
14 *
15 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
16 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 * the GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with the Ubicom32 Linux Kernel Port. If not,
22 * see <http://www.gnu.org/licenses/>.
23 *
24 * Ubicom32 implementation derived from (with many thanks):
25 * arch/m68knommu
26 * arch/blackfin
27 * arch/parisc
28 */
29
30#include <linux/profile.h>
31
32#include <asm/ip5000.h>
33#include <asm/machdep.h>
34#if defined(CONFIG_SMP)
35#include <asm/smp.h>
36#endif
37
38static unsigned int timervector;
39static unsigned int frequency;
40
41/*
42 * timer_tick()
43 * Kernel system timer support. Needs to keep up the real-time clock,
44 * as well as call the "do_timer()" routine every clocktick.
45 */
46static irqreturn_t timer_tick(int irq, void *dummy)
47{
48    int ticks;
49
50    BUG_ON(!irqs_disabled());
51    ticks = timer_reset(timervector, frequency);
52
53    write_seqlock(&xtime_lock);
54    do_timer(ticks);
55    write_sequnlock(&xtime_lock);
56
57    update_process_times(user_mode(get_irq_regs()));
58    profile_tick(CPU_PROFILING);
59
60#if defined(CONFIG_SMP)
61    smp_send_timer_all();
62#endif
63    return(IRQ_HANDLED);
64}
65
66/*
67 * Data used by setup_irq for the timer.
68 */
69static struct irqaction timer_irq = {
70    .name = "timer",
71    .flags = IRQF_DISABLED | IRQF_TIMER,
72    .handler = timer_tick,
73};
74
75/*
76 * timer_tick_init()
77 * Implements a periodic timer
78 *
79 * This implementation directly calls the timer_tick() and move
80 * the Linux kernel forward. This is used when the user has not
81 * selected GENERIC_CLOCKEVENTS.
82 */
83void timer_tick_init(void)
84{
85    /*
86     * Now allocate a timer to ourselves.
87     */
88    timervector = timer_alloc();
89    if (timervector == -1) {
90        printk(KERN_WARNING "where did the timer go?\n");
91        return;
92    }
93
94    setup_irq(timervector, &timer_irq);
95
96    /*
97     * Get the frequency from the processor device tree node or use
98     * the default if not available. We will store this as the frequency
99     * of the timer to avoid future calculations.
100     */
101    frequency = processor_frequency();
102    if (frequency == 0) {
103        frequency = CLOCK_TICK_RATE;
104    }
105    frequency /= CONFIG_HZ;
106
107    printk(KERN_NOTICE "timer will interrupt every: %d cycles\n", frequency);
108    timer_set(timervector, frequency);
109}
110

Archive Download this file



interactive