^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * ip30-timer.c: Clocksource/clockevent support for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * HEART chip in SGI Octane (IP30) systems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2004-2007 Stanislaw Skowronek <skylark@unaligned.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2009 Johannes Dickgreber <tanzy@gmx.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2011 Joshua Kinard <kumba@gentoo.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/clocksource.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sched_clock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/cevt-r4k.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/sgi/heart.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static u64 ip30_heart_counter_read(struct clocksource *cs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) return heart_read(&heart_regs->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct clocksource ip30_heart_clocksource = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .name = "HEART",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) .rating = 400,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .read = ip30_heart_counter_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) .mask = CLOCKSOURCE_MASK(52),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .flags = (CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_VALID_FOR_HRES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static u64 notrace ip30_heart_read_sched_clock(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return heart_read(&heart_regs->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static void __init ip30_heart_clocksource_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct clocksource *cs = &ip30_heart_clocksource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) clocksource_register_hz(cs, HEART_CYCLES_PER_SEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) sched_clock_register(ip30_heart_read_sched_clock, 52,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) HEART_CYCLES_PER_SEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) void __init plat_time_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int irq = get_c0_compare_int();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) cp0_timer_irq_installed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) c0_compare_irqaction.percpu_dev_id = &mips_clockevent_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) c0_compare_irqaction.flags &= ~IRQF_SHARED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) irq_set_handler(irq, handle_percpu_devid_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) irq_set_percpu_devid(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) setup_percpu_irq(irq, &c0_compare_irqaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) enable_percpu_irq(irq, IRQ_TYPE_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ip30_heart_clocksource_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }