summaryrefslogtreecommitdiff
path: root/arch/mips/sgi-ip30/ip30-timer.c
blob: d13e105478aeee77e5149d31f1328c03d949843f (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
// SPDX-License-Identifier: GPL-2.0
/*
 * ip30-timer.c: Clocksource/clockevent support for the
 *               HEART chip in SGI Octane (IP30) systems.
 *
 * Copyright (C) 2004-2007 Stanislaw Skowronek <skylark@unaligned.org>
 * Copyright (C) 2009 Johannes Dickgreber <tanzy@gmx.de>
 * Copyright (C) 2011 Joshua Kinard <kumba@gentoo.org>
 */

#include <linux/clocksource.h>
#include <linux/cpumask.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/percpu.h>
#include <linux/sched_clock.h>

#include <asm/time.h>
#include <asm/cevt-r4k.h>
#include <asm/sgi/heart.h>

static u64 ip30_heart_counter_read(struct clocksource *cs)
{
	return heart_read(&heart_regs->count);
}

struct clocksource ip30_heart_clocksource = {
	.name	= "HEART",
	.rating	= 400,
	.read	= ip30_heart_counter_read,
	.mask	= CLOCKSOURCE_MASK(52),
	.flags	= (CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_VALID_FOR_HRES),
};

static u64 notrace ip30_heart_read_sched_clock(void)
{
	return heart_read(&heart_regs->count);
}

static void __init ip30_heart_clocksource_init(void)
{
	struct clocksource *cs = &ip30_heart_clocksource;

	clocksource_register_hz(cs, HEART_CYCLES_PER_SEC);

	sched_clock_register(ip30_heart_read_sched_clock, 52,
			     HEART_CYCLES_PER_SEC);
}

void __init plat_time_init(void)
{
	int irq = get_c0_compare_int();

	cp0_timer_irq_installed = 1;
	c0_compare_irqaction.percpu_dev_id = &mips_clockevent_device;
	c0_compare_irqaction.flags &= ~IRQF_SHARED;
	irq_set_handler(irq, handle_percpu_devid_irq);
	irq_set_percpu_devid(irq);
	setup_percpu_irq(irq, &c0_compare_irqaction);
	enable_percpu_irq(irq, IRQ_TYPE_NONE);

	ip30_heart_clocksource_init();
}