timer.c 1.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * linux/arch/ia64/sn/kernel/sn2/timer.c
 *
 * Copyright (C) 2003 Silicon Graphics, Inc.
 * Copyright (C) 2003 Hewlett-Packard Co
 *	David Mosberger <davidm@hpl.hp.com>: updated for new timer-interpolation infrastructure
 */

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/time.h>
#include <linux/interrupt.h>
14
#include <linux/clocksource.h>
L
Linus Torvalds 已提交
15 16 17

#include <asm/hw_irq.h>
#include <asm/system.h>
18
#include <asm/timex.h>
L
Linus Torvalds 已提交
19 20 21 22 23 24 25

#include <asm/sn/leds.h>
#include <asm/sn/shub_mmr.h>
#include <asm/sn/clksupport.h>

extern unsigned long sn_rtc_cycles_per_second;

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
static void __iomem *sn2_mc;

static cycle_t read_sn2(void)
{
	return (cycle_t)readq(sn2_mc);
}

static struct clocksource clocksource_sn2 = {
        .name           = "sn2_rtc",
        .rating         = 300,
        .read           = read_sn2,
        .mask           = (1LL << 55) - 1,
        .mult           = 0,
        .shift          = 10,
        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
L
Linus Torvalds 已提交
41 42
};

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
/*
 * sn udelay uses the RTC instead of the ITC because the ITC is not
 * synchronized across all CPUs, and the thread may migrate to another CPU
 * if preemption is enabled.
 */
static void
ia64_sn_udelay (unsigned long usecs)
{
	unsigned long start = rtc_time();
	unsigned long end = start +
			usecs * sn_rtc_cycles_per_second / 1000000;

	while (time_before((unsigned long)rtc_time(), end))
		cpu_relax();
}

L
Linus Torvalds 已提交
59 60
void __init sn_timer_init(void)
{
61 62 63 64 65
	sn2_mc = RTC_COUNTER_ADDR;
	clocksource_sn2.fsys_mmio = RTC_COUNTER_ADDR;
	clocksource_sn2.mult = clocksource_hz2mult(sn_rtc_cycles_per_second,
							clocksource_sn2.shift);
	clocksource_register(&clocksource_sn2);
66 67

	ia64_udelay = &ia64_sn_udelay;
L
Linus Torvalds 已提交
68
}