| .. | .. |
|---|
| 17 | 17 | #include <linux/kernel.h> |
|---|
| 18 | 18 | #include <linux/mm.h> |
|---|
| 19 | 19 | #include <linux/tty.h> |
|---|
| 20 | +#include <linux/clocksource.h> |
|---|
| 20 | 21 | #include <linux/console.h> |
|---|
| 21 | 22 | #include <linux/linkage.h> |
|---|
| 22 | 23 | #include <linux/init.h> |
|---|
| .. | .. |
|---|
| 28 | 29 | #include <asm/bootinfo.h> |
|---|
| 29 | 30 | #include <asm/bootinfo-vme.h> |
|---|
| 30 | 31 | #include <asm/byteorder.h> |
|---|
| 31 | | -#include <asm/pgtable.h> |
|---|
| 32 | 32 | #include <asm/setup.h> |
|---|
| 33 | 33 | #include <asm/irq.h> |
|---|
| 34 | 34 | #include <asm/traps.h> |
|---|
| .. | .. |
|---|
| 38 | 38 | |
|---|
| 39 | 39 | static void mvme147_get_model(char *model); |
|---|
| 40 | 40 | extern void mvme147_sched_init(irq_handler_t handler); |
|---|
| 41 | | -extern u32 mvme147_gettimeoffset(void); |
|---|
| 42 | 41 | extern int mvme147_hwclk (int, struct rtc_time *); |
|---|
| 43 | 42 | extern void mvme147_reset (void); |
|---|
| 44 | 43 | |
|---|
| .. | .. |
|---|
| 84 | 83 | mach_max_dma_address = 0x01000000; |
|---|
| 85 | 84 | mach_sched_init = mvme147_sched_init; |
|---|
| 86 | 85 | mach_init_IRQ = mvme147_init_IRQ; |
|---|
| 87 | | - arch_gettimeoffset = mvme147_gettimeoffset; |
|---|
| 88 | 86 | mach_hwclk = mvme147_hwclk; |
|---|
| 89 | 87 | mach_reset = mvme147_reset; |
|---|
| 90 | 88 | mach_get_model = mvme147_get_model; |
|---|
| .. | .. |
|---|
| 94 | 92 | vme_brdtype = VME_TYPE_MVME147; |
|---|
| 95 | 93 | } |
|---|
| 96 | 94 | |
|---|
| 95 | +static u64 mvme147_read_clk(struct clocksource *cs); |
|---|
| 96 | + |
|---|
| 97 | +static struct clocksource mvme147_clk = { |
|---|
| 98 | + .name = "pcc", |
|---|
| 99 | + .rating = 250, |
|---|
| 100 | + .read = mvme147_read_clk, |
|---|
| 101 | + .mask = CLOCKSOURCE_MASK(32), |
|---|
| 102 | + .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
|---|
| 103 | +}; |
|---|
| 104 | + |
|---|
| 105 | +static u32 clk_total; |
|---|
| 106 | + |
|---|
| 107 | +#define PCC_TIMER_CLOCK_FREQ 160000 |
|---|
| 108 | +#define PCC_TIMER_CYCLES (PCC_TIMER_CLOCK_FREQ / HZ) |
|---|
| 109 | +#define PCC_TIMER_PRELOAD (0x10000 - PCC_TIMER_CYCLES) |
|---|
| 97 | 110 | |
|---|
| 98 | 111 | /* Using pcc tick timer 1 */ |
|---|
| 99 | 112 | |
|---|
| .. | .. |
|---|
| 103 | 116 | unsigned long flags; |
|---|
| 104 | 117 | |
|---|
| 105 | 118 | local_irq_save(flags); |
|---|
| 106 | | - m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR; |
|---|
| 107 | | - m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1; |
|---|
| 119 | + m147_pcc->t1_cntrl = PCC_TIMER_CLR_OVF | PCC_TIMER_COC_EN | |
|---|
| 120 | + PCC_TIMER_TIC_EN; |
|---|
| 121 | + m147_pcc->t1_int_cntrl = PCC_INT_ENAB | PCC_TIMER_INT_CLR | |
|---|
| 122 | + PCC_LEVEL_TIMER1; |
|---|
| 123 | + clk_total += PCC_TIMER_CYCLES; |
|---|
| 108 | 124 | timer_routine(0, NULL); |
|---|
| 109 | 125 | local_irq_restore(flags); |
|---|
| 110 | 126 | |
|---|
| .. | .. |
|---|
| 114 | 130 | |
|---|
| 115 | 131 | void mvme147_sched_init (irq_handler_t timer_routine) |
|---|
| 116 | 132 | { |
|---|
| 117 | | - if (request_irq(PCC_IRQ_TIMER1, mvme147_timer_int, 0, "timer 1", |
|---|
| 118 | | - timer_routine)) |
|---|
| 133 | + if (request_irq(PCC_IRQ_TIMER1, mvme147_timer_int, IRQF_TIMER, |
|---|
| 134 | + "timer 1", timer_routine)) |
|---|
| 119 | 135 | pr_err("Couldn't register timer interrupt\n"); |
|---|
| 120 | 136 | |
|---|
| 121 | 137 | /* Init the clock with a value */ |
|---|
| 122 | | - /* our clock goes off every 6.25us */ |
|---|
| 138 | + /* The clock counter increments until 0xFFFF then reloads */ |
|---|
| 123 | 139 | m147_pcc->t1_preload = PCC_TIMER_PRELOAD; |
|---|
| 124 | | - m147_pcc->t1_cntrl = 0x0; /* clear timer */ |
|---|
| 125 | | - m147_pcc->t1_cntrl = 0x3; /* start timer */ |
|---|
| 126 | | - m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR; /* clear pending ints */ |
|---|
| 127 | | - m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1; |
|---|
| 140 | + m147_pcc->t1_cntrl = PCC_TIMER_CLR_OVF | PCC_TIMER_COC_EN | |
|---|
| 141 | + PCC_TIMER_TIC_EN; |
|---|
| 142 | + m147_pcc->t1_int_cntrl = PCC_INT_ENAB | PCC_TIMER_INT_CLR | |
|---|
| 143 | + PCC_LEVEL_TIMER1; |
|---|
| 144 | + |
|---|
| 145 | + clocksource_register_hz(&mvme147_clk, PCC_TIMER_CLOCK_FREQ); |
|---|
| 128 | 146 | } |
|---|
| 129 | 147 | |
|---|
| 130 | | -/* This is always executed with interrupts disabled. */ |
|---|
| 131 | | -/* XXX There are race hazards in this code XXX */ |
|---|
| 132 | | -u32 mvme147_gettimeoffset(void) |
|---|
| 148 | +static u64 mvme147_read_clk(struct clocksource *cs) |
|---|
| 133 | 149 | { |
|---|
| 134 | | - volatile unsigned short *cp = (volatile unsigned short *)0xfffe1012; |
|---|
| 135 | | - unsigned short n; |
|---|
| 150 | + unsigned long flags; |
|---|
| 151 | + u8 overflow, tmp; |
|---|
| 152 | + u16 count; |
|---|
| 153 | + u32 ticks; |
|---|
| 136 | 154 | |
|---|
| 137 | | - n = *cp; |
|---|
| 138 | | - while (n != *cp) |
|---|
| 139 | | - n = *cp; |
|---|
| 155 | + local_irq_save(flags); |
|---|
| 156 | + tmp = m147_pcc->t1_cntrl >> 4; |
|---|
| 157 | + count = m147_pcc->t1_count; |
|---|
| 158 | + overflow = m147_pcc->t1_cntrl >> 4; |
|---|
| 159 | + if (overflow != tmp) |
|---|
| 160 | + count = m147_pcc->t1_count; |
|---|
| 161 | + count -= PCC_TIMER_PRELOAD; |
|---|
| 162 | + ticks = count + overflow * PCC_TIMER_CYCLES; |
|---|
| 163 | + ticks += clk_total; |
|---|
| 164 | + local_irq_restore(flags); |
|---|
| 140 | 165 | |
|---|
| 141 | | - n -= PCC_TIMER_PRELOAD; |
|---|
| 142 | | - return ((unsigned long)n * 25 / 4) * 1000; |
|---|
| 166 | + return ticks; |
|---|
| 143 | 167 | } |
|---|
| 144 | 168 | |
|---|
| 145 | 169 | static int bcd2int (unsigned char b) |
|---|