.. | .. |
---|
8 | 8 | */ |
---|
9 | 9 | |
---|
10 | 10 | #include <asm/ptrace.h> |
---|
| 11 | +#include <linux/clocksource.h> |
---|
11 | 12 | #include <linux/types.h> |
---|
12 | 13 | #include <linux/init.h> |
---|
13 | 14 | #include <linux/sched.h> |
---|
.. | .. |
---|
19 | 20 | #include <asm/traps.h> |
---|
20 | 21 | #include <asm/blinken.h> |
---|
21 | 22 | |
---|
| 23 | +static u64 hp300_read_clk(struct clocksource *cs); |
---|
| 24 | + |
---|
| 25 | +static struct clocksource hp300_clk = { |
---|
| 26 | + .name = "timer", |
---|
| 27 | + .rating = 250, |
---|
| 28 | + .read = hp300_read_clk, |
---|
| 29 | + .mask = CLOCKSOURCE_MASK(32), |
---|
| 30 | + .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
---|
| 31 | +}; |
---|
| 32 | + |
---|
| 33 | +static u32 clk_total, clk_offset; |
---|
| 34 | + |
---|
22 | 35 | /* Clock hardware definitions */ |
---|
23 | 36 | |
---|
24 | 37 | #define CLOCKBASE 0xf05f8000 |
---|
.. | .. |
---|
28 | 41 | #define CLKCR3 CLKCR1 |
---|
29 | 42 | #define CLKSR CLKCR2 |
---|
30 | 43 | #define CLKMSB1 0x5 |
---|
| 44 | +#define CLKLSB1 0x7 |
---|
31 | 45 | #define CLKMSB2 0x9 |
---|
32 | 46 | #define CLKMSB3 0xD |
---|
33 | 47 | |
---|
34 | | -/* This is for machines which generate the exact clock. */ |
---|
35 | | -#define USECS_PER_JIFFY (1000000/HZ) |
---|
| 48 | +#define CLKSR_INT1 BIT(0) |
---|
36 | 49 | |
---|
37 | | -#define INTVAL ((10000 / 4) - 1) |
---|
| 50 | +/* This is for machines which generate the exact clock. */ |
---|
| 51 | + |
---|
| 52 | +#define HP300_TIMER_CLOCK_FREQ 250000 |
---|
| 53 | +#define HP300_TIMER_CYCLES (HP300_TIMER_CLOCK_FREQ / HZ) |
---|
| 54 | +#define INTVAL (HP300_TIMER_CYCLES - 1) |
---|
38 | 55 | |
---|
39 | 56 | static irqreturn_t hp300_tick(int irq, void *dev_id) |
---|
40 | 57 | { |
---|
.. | .. |
---|
45 | 62 | local_irq_save(flags); |
---|
46 | 63 | in_8(CLOCKBASE + CLKSR); |
---|
47 | 64 | asm volatile ("movpw %1@(5),%0" : "=d" (tmp) : "a" (CLOCKBASE)); |
---|
| 65 | + clk_total += INTVAL; |
---|
| 66 | + clk_offset = 0; |
---|
48 | 67 | timer_routine(0, NULL); |
---|
49 | 68 | local_irq_restore(flags); |
---|
50 | 69 | |
---|
.. | .. |
---|
53 | 72 | return IRQ_HANDLED; |
---|
54 | 73 | } |
---|
55 | 74 | |
---|
56 | | -u32 hp300_gettimeoffset(void) |
---|
| 75 | +static u64 hp300_read_clk(struct clocksource *cs) |
---|
57 | 76 | { |
---|
58 | | - /* Read current timer 1 value */ |
---|
59 | | - unsigned char lsb, msb1, msb2; |
---|
60 | | - unsigned short ticks; |
---|
| 77 | + unsigned long flags; |
---|
| 78 | + unsigned char lsb, msb, msb_new; |
---|
| 79 | + u32 ticks; |
---|
61 | 80 | |
---|
62 | | - msb1 = in_8(CLOCKBASE + 5); |
---|
63 | | - lsb = in_8(CLOCKBASE + 7); |
---|
64 | | - msb2 = in_8(CLOCKBASE + 5); |
---|
65 | | - if (msb1 != msb2) |
---|
66 | | - /* A carry happened while we were reading. Read it again */ |
---|
67 | | - lsb = in_8(CLOCKBASE + 7); |
---|
68 | | - ticks = INTVAL - ((msb2 << 8) | lsb); |
---|
69 | | - return ((USECS_PER_JIFFY * ticks) / INTVAL) * 1000; |
---|
| 81 | + local_irq_save(flags); |
---|
| 82 | + /* Read current timer 1 value */ |
---|
| 83 | + msb = in_8(CLOCKBASE + CLKMSB1); |
---|
| 84 | +again: |
---|
| 85 | + if ((in_8(CLOCKBASE + CLKSR) & CLKSR_INT1) && msb > 0) |
---|
| 86 | + clk_offset = INTVAL; |
---|
| 87 | + lsb = in_8(CLOCKBASE + CLKLSB1); |
---|
| 88 | + msb_new = in_8(CLOCKBASE + CLKMSB1); |
---|
| 89 | + if (msb_new != msb) { |
---|
| 90 | + msb = msb_new; |
---|
| 91 | + goto again; |
---|
| 92 | + } |
---|
| 93 | + |
---|
| 94 | + ticks = INTVAL - ((msb << 8) | lsb); |
---|
| 95 | + ticks += clk_offset + clk_total; |
---|
| 96 | + local_irq_restore(flags); |
---|
| 97 | + |
---|
| 98 | + return ticks; |
---|
70 | 99 | } |
---|
71 | 100 | |
---|
72 | 101 | void __init hp300_sched_init(irq_handler_t vector) |
---|
.. | .. |
---|
76 | 105 | |
---|
77 | 106 | asm volatile(" movpw %0,%1@(5)" : : "d" (INTVAL), "a" (CLOCKBASE)); |
---|
78 | 107 | |
---|
79 | | - if (request_irq(IRQ_AUTO_6, hp300_tick, 0, "timer tick", vector)) |
---|
| 108 | + if (request_irq(IRQ_AUTO_6, hp300_tick, IRQF_TIMER, "timer tick", vector)) |
---|
80 | 109 | pr_err("Couldn't register timer interrupt\n"); |
---|
81 | 110 | |
---|
82 | 111 | out_8(CLOCKBASE + CLKCR2, 0x1); /* select CR1 */ |
---|
83 | 112 | out_8(CLOCKBASE + CLKCR1, 0x40); /* enable irq */ |
---|
| 113 | + |
---|
| 114 | + clocksource_register_hz(&hp300_clk, HP300_TIMER_CLOCK_FREQ); |
---|
84 | 115 | } |
---|