hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/arch/m68k/mvme147/config.c
....@@ -17,6 +17,7 @@
1717 #include <linux/kernel.h>
1818 #include <linux/mm.h>
1919 #include <linux/tty.h>
20
+#include <linux/clocksource.h>
2021 #include <linux/console.h>
2122 #include <linux/linkage.h>
2223 #include <linux/init.h>
....@@ -28,7 +29,6 @@
2829 #include <asm/bootinfo.h>
2930 #include <asm/bootinfo-vme.h>
3031 #include <asm/byteorder.h>
31
-#include <asm/pgtable.h>
3232 #include <asm/setup.h>
3333 #include <asm/irq.h>
3434 #include <asm/traps.h>
....@@ -38,7 +38,6 @@
3838
3939 static void mvme147_get_model(char *model);
4040 extern void mvme147_sched_init(irq_handler_t handler);
41
-extern u32 mvme147_gettimeoffset(void);
4241 extern int mvme147_hwclk (int, struct rtc_time *);
4342 extern void mvme147_reset (void);
4443
....@@ -84,7 +83,6 @@
8483 mach_max_dma_address = 0x01000000;
8584 mach_sched_init = mvme147_sched_init;
8685 mach_init_IRQ = mvme147_init_IRQ;
87
- arch_gettimeoffset = mvme147_gettimeoffset;
8886 mach_hwclk = mvme147_hwclk;
8987 mach_reset = mvme147_reset;
9088 mach_get_model = mvme147_get_model;
....@@ -94,6 +92,21 @@
9492 vme_brdtype = VME_TYPE_MVME147;
9593 }
9694
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)
97110
98111 /* Using pcc tick timer 1 */
99112
....@@ -103,8 +116,11 @@
103116 unsigned long flags;
104117
105118 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;
108124 timer_routine(0, NULL);
109125 local_irq_restore(flags);
110126
....@@ -114,32 +130,40 @@
114130
115131 void mvme147_sched_init (irq_handler_t timer_routine)
116132 {
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))
119135 pr_err("Couldn't register timer interrupt\n");
120136
121137 /* Init the clock with a value */
122
- /* our clock goes off every 6.25us */
138
+ /* The clock counter increments until 0xFFFF then reloads */
123139 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);
128146 }
129147
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)
133149 {
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;
136154
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);
140165
141
- n -= PCC_TIMER_PRELOAD;
142
- return ((unsigned long)n * 25 / 4) * 1000;
166
+ return ticks;
143167 }
144168
145169 static int bcd2int (unsigned char b)