1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/m68k/hp300/time.c
5 * Copyright (C) 1998 Philip Blundell <philb@gnu.org>
7 * This file contains the HP300-specific time handling code.
10 #include <asm/ptrace.h>
11 #include <linux/clocksource.h>
12 #include <linux/types.h>
13 #include <linux/init.h>
14 #include <linux/sched.h>
15 #include <linux/kernel_stat.h>
16 #include <linux/interrupt.h>
17 #include <asm/machdep.h>
20 #include <asm/traps.h>
21 #include <asm/blinken.h>
25 static u64 hp300_read_clk(struct clocksource *cs);
27 static struct clocksource hp300_clk = {
30 .read = hp300_read_clk,
31 .mask = CLOCKSOURCE_MASK(32),
32 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
35 static u32 clk_total, clk_offset;
37 /* Clock hardware definitions */
39 #define CLOCKBASE 0xf05f8000
50 #define CLKSR_INT1 BIT(0)
52 /* This is for machines which generate the exact clock. */
54 #define HP300_TIMER_CLOCK_FREQ 250000
55 #define HP300_TIMER_CYCLES (HP300_TIMER_CLOCK_FREQ / HZ)
56 #define INTVAL (HP300_TIMER_CYCLES - 1)
58 static irqreturn_t hp300_tick(int irq, void *dev_id)
63 local_irq_save(flags);
64 in_8(CLOCKBASE + CLKSR);
65 asm volatile ("movpw %1@(5),%0" : "=d" (tmp) : "a" (CLOCKBASE));
70 local_irq_restore(flags);
72 /* Turn off the network and SCSI leds */
73 blinken_leds(0, 0xe0);
77 static u64 hp300_read_clk(struct clocksource *cs)
80 unsigned char lsb, msb, msb_new;
83 local_irq_save(flags);
84 /* Read current timer 1 value */
85 msb = in_8(CLOCKBASE + CLKMSB1);
87 if ((in_8(CLOCKBASE + CLKSR) & CLKSR_INT1) && msb > 0)
89 lsb = in_8(CLOCKBASE + CLKLSB1);
90 msb_new = in_8(CLOCKBASE + CLKMSB1);
96 ticks = INTVAL - ((msb << 8) | lsb);
97 ticks += clk_offset + clk_total;
98 local_irq_restore(flags);
103 void __init hp300_sched_init(void)
105 out_8(CLOCKBASE + CLKCR2, 0x1); /* select CR1 */
106 out_8(CLOCKBASE + CLKCR1, 0x1); /* reset */
108 asm volatile(" movpw %0,%1@(5)" : : "d" (INTVAL), "a" (CLOCKBASE));
110 if (request_irq(IRQ_AUTO_6, hp300_tick, IRQF_TIMER, "timer tick", NULL))
111 pr_err("Couldn't register timer interrupt\n");
113 out_8(CLOCKBASE + CLKCR2, 0x1); /* select CR1 */
114 out_8(CLOCKBASE + CLKCR1, 0x40); /* enable irq */
116 clocksource_register_hz(&hp300_clk, HP300_TIMER_CLOCK_FREQ);