1 --- a/arch/arm/mach-cns3xxx/core.c
2 +++ b/arch/arm/mach-cns3xxx/core.c
3 @@ -118,12 +118,13 @@ static void cns3xxx_timer_set_mode(enum
6 case CLOCK_EVT_MODE_PERIODIC:
7 - reload = pclk * 20 / (3 * HZ) * 0x25000;
8 + reload = pclk * 1000000 / HZ;
9 writel(reload, cns3xxx_tmr1 + TIMER1_AUTO_RELOAD_OFFSET);
10 ctrl |= (1 << 0) | (1 << 2) | (1 << 9);
12 case CLOCK_EVT_MODE_ONESHOT:
13 /* period set, and timer enabled in 'next_event' hook */
14 + writel(0, cns3xxx_tmr1 + TIMER1_AUTO_RELOAD_OFFSET);
15 ctrl |= (1 << 2) | (1 << 9);
17 case CLOCK_EVT_MODE_UNUSED:
18 @@ -148,11 +149,11 @@ static int cns3xxx_timer_set_next_event(
20 static struct clock_event_device cns3xxx_tmr1_clockevent = {
21 .name = "cns3xxx timer1",
24 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
25 .set_mode = cns3xxx_timer_set_mode,
26 .set_next_event = cns3xxx_timer_set_next_event,
29 .cpumask = cpu_all_mask,
32 @@ -194,6 +195,35 @@ static struct irqaction cns3xxx_timer_ir
33 .handler = cns3xxx_timer_interrupt,
36 +static cycle_t cns3xxx_get_cycles(struct clocksource *cs)
40 + val = readl(cns3xxx_tmr1 + TIMER_FREERUN_CONTROL_OFFSET);
43 + return ((val << 32) | readl(cns3xxx_tmr1 + TIMER_FREERUN_OFFSET));
46 +static struct clocksource clocksource_cns3xxx = {
49 + .read = cns3xxx_get_cycles,
50 + .mask = CLOCKSOURCE_MASK(48),
52 + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
55 +static void __init cns3xxx_clocksource_init(void)
57 + /* Reset the FreeRunning counter */
58 + writel((1 << 16), cns3xxx_tmr1 + TIMER_FREERUN_CONTROL_OFFSET);
60 + clocksource_cns3xxx.mult =
61 + clocksource_khz2mult(100, clocksource_cns3xxx.shift);
62 + clocksource_register(&clocksource_cns3xxx);
66 * Set up the clock source and clock events devices
68 @@ -211,13 +241,12 @@ static void __init __cns3xxx_timer_init(
69 /* stop free running timer3 */
70 writel(0, cns3xxx_tmr1 + TIMER_FREERUN_CONTROL_OFFSET);
73 - writel(0x5C800, cns3xxx_tmr1 + TIMER1_COUNTER_OFFSET);
74 - writel(0x5C800, cns3xxx_tmr1 + TIMER1_AUTO_RELOAD_OFFSET);
76 writel(0, cns3xxx_tmr1 + TIMER1_MATCH_V1_OFFSET);
77 writel(0, cns3xxx_tmr1 + TIMER1_MATCH_V2_OFFSET);
79 + val = (cns3xxx_cpu_clock() >> 3) * 1000000 / HZ;
80 + writel(val, cns3xxx_tmr1 + TIMER1_COUNTER_OFFSET);
82 /* mask irq, non-mask timer1 overflow */
83 irq_mask = readl(cns3xxx_tmr1 + TIMER1_2_INTERRUPT_MASK_OFFSET);
84 irq_mask &= ~(1 << 2);
85 @@ -229,23 +258,9 @@ static void __init __cns3xxx_timer_init(
87 writel(val, cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
90 - writel(0, cns3xxx_tmr1 + TIMER2_MATCH_V1_OFFSET);
91 - writel(0, cns3xxx_tmr1 + TIMER2_MATCH_V2_OFFSET);
94 - irq_mask = readl(cns3xxx_tmr1 + TIMER1_2_INTERRUPT_MASK_OFFSET);
95 - irq_mask |= ((1 << 3) | (1 << 4) | (1 << 5));
96 - writel(irq_mask, cns3xxx_tmr1 + TIMER1_2_INTERRUPT_MASK_OFFSET);
99 - val = readl(cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
101 - writel(val, cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
103 - /* Make irqs happen for the system timer */
104 setup_irq(timer_irq, &cns3xxx_timer_irq);
106 + cns3xxx_clocksource_init();
107 cns3xxx_clockevents_init(timer_irq);