Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-footbridge/dc21285-timer.c |
| 3 | * |
| 4 | * Copyright (C) 1998 Russell King. |
| 5 | * Copyright (C) 1998 Phil Blundell |
| 6 | */ |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 7 | #include <linux/clockchips.h> |
| 8 | #include <linux/clocksource.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/init.h> |
| 10 | #include <linux/interrupt.h> |
Thomas Gleixner | 55e8698 | 2006-07-01 22:32:17 +0100 | [diff] [blame] | 11 | #include <linux/irq.h> |
Russell King | 6cefe92 | 2013-11-29 01:03:35 +0000 | [diff] [blame] | 12 | #include <linux/sched_clock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #include <asm/irq.h> |
| 15 | |
| 16 | #include <asm/hardware/dec21285.h> |
| 17 | #include <asm/mach/time.h> |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 18 | #include <asm/system_info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #include "common.h" |
| 21 | |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 22 | static cycle_t cksrc_dc21285_read(struct clocksource *cs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | { |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 24 | return cs->mask - *CSR_TIMER2_VALUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 27 | static int cksrc_dc21285_enable(struct clocksource *cs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 29 | *CSR_TIMER2_LOAD = cs->mask; |
| 30 | *CSR_TIMER2_CLR = 0; |
| 31 | *CSR_TIMER2_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16; |
| 32 | return 0; |
| 33 | } |
| 34 | |
Thomas Gleixner | f2e0bf2 | 2011-03-28 11:25:40 +0200 | [diff] [blame] | 35 | static void cksrc_dc21285_disable(struct clocksource *cs) |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 36 | { |
| 37 | *CSR_TIMER2_CNTL = 0; |
| 38 | } |
| 39 | |
| 40 | static struct clocksource cksrc_dc21285 = { |
| 41 | .name = "dc21285_timer2", |
| 42 | .rating = 200, |
| 43 | .read = cksrc_dc21285_read, |
| 44 | .enable = cksrc_dc21285_enable, |
| 45 | .disable = cksrc_dc21285_disable, |
| 46 | .mask = CLOCKSOURCE_MASK(24), |
| 47 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
| 48 | }; |
| 49 | |
Russell King | 4808972 | 2013-11-30 12:21:21 +0000 | [diff] [blame] | 50 | static int ckevt_dc21285_set_next_event(unsigned long delta, |
| 51 | struct clock_event_device *c) |
| 52 | { |
| 53 | *CSR_TIMER1_CLR = 0; |
| 54 | *CSR_TIMER1_LOAD = delta; |
| 55 | *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16; |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 60 | static void ckevt_dc21285_set_mode(enum clock_event_mode mode, |
| 61 | struct clock_event_device *c) |
| 62 | { |
| 63 | switch (mode) { |
| 64 | case CLOCK_EVT_MODE_RESUME: |
| 65 | case CLOCK_EVT_MODE_PERIODIC: |
| 66 | *CSR_TIMER1_CLR = 0; |
| 67 | *CSR_TIMER1_LOAD = (mem_fclk_21285 + 8 * HZ) / (16 * HZ); |
| 68 | *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_AUTORELOAD | |
| 69 | TIMER_CNTL_DIV16; |
| 70 | break; |
| 71 | |
Russell King | 4808972 | 2013-11-30 12:21:21 +0000 | [diff] [blame] | 72 | case CLOCK_EVT_MODE_ONESHOT: |
| 73 | case CLOCK_EVT_MODE_UNUSED: |
| 74 | case CLOCK_EVT_MODE_SHUTDOWN: |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 75 | *CSR_TIMER1_CNTL = 0; |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | static struct clock_event_device ckevt_dc21285 = { |
| 81 | .name = "dc21285_timer1", |
Russell King | 4808972 | 2013-11-30 12:21:21 +0000 | [diff] [blame] | 82 | .features = CLOCK_EVT_FEAT_PERIODIC | |
| 83 | CLOCK_EVT_FEAT_ONESHOT, |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 84 | .rating = 200, |
| 85 | .irq = IRQ_TIMER1, |
Russell King | 4808972 | 2013-11-30 12:21:21 +0000 | [diff] [blame] | 86 | .set_next_event = ckevt_dc21285_set_next_event, |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 87 | .set_mode = ckevt_dc21285_set_mode, |
| 88 | }; |
| 89 | |
| 90 | static irqreturn_t timer1_interrupt(int irq, void *dev_id) |
| 91 | { |
| 92 | struct clock_event_device *ce = dev_id; |
| 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | *CSR_TIMER1_CLR = 0; |
| 95 | |
Russell King | 4808972 | 2013-11-30 12:21:21 +0000 | [diff] [blame] | 96 | /* Stop the timer if in one-shot mode */ |
| 97 | if (ce->mode == CLOCK_EVT_MODE_ONESHOT) |
| 98 | *CSR_TIMER1_CNTL = 0; |
| 99 | |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 100 | ce->event_handler(ce); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return IRQ_HANDLED; |
| 103 | } |
| 104 | |
| 105 | static struct irqaction footbridge_timer_irq = { |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 106 | .name = "dc21285_timer1", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | .handler = timer1_interrupt, |
Michael Opdenacker | 26632be | 2014-03-04 21:45:48 +0100 | [diff] [blame] | 108 | .flags = IRQF_TIMER | IRQF_IRQPOLL, |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 109 | .dev_id = &ckevt_dc21285, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | /* |
| 113 | * Set up timer interrupt. |
| 114 | */ |
Stephen Warren | 6bb27d7 | 2012-11-08 12:40:59 -0700 | [diff] [blame] | 115 | void __init footbridge_timer_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 117 | struct clock_event_device *ce = &ckevt_dc21285; |
Russell King | 4ff859f | 2013-12-29 12:39:50 +0000 | [diff] [blame] | 118 | unsigned rate = DIV_ROUND_CLOSEST(mem_fclk_21285, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Russell King | 4ff859f | 2013-12-29 12:39:50 +0000 | [diff] [blame] | 120 | clocksource_register_hz(&cksrc_dc21285, rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 122 | setup_irq(ce->irq, &footbridge_timer_irq); |
| 123 | |
Russell King | 7d7975a | 2011-06-11 00:46:17 +0100 | [diff] [blame] | 124 | ce->cpumask = cpumask_of(smp_processor_id()); |
Russell King | 4ff859f | 2013-12-29 12:39:50 +0000 | [diff] [blame] | 125 | clockevents_config_and_register(ce, rate, 0x4, 0xffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |
Russell King | 6cefe92 | 2013-11-29 01:03:35 +0000 | [diff] [blame] | 127 | |
Stephen Boyd | 889f172 | 2014-01-17 20:42:48 +0100 | [diff] [blame] | 128 | static u64 notrace footbridge_read_sched_clock(void) |
Russell King | 6cefe92 | 2013-11-29 01:03:35 +0000 | [diff] [blame] | 129 | { |
| 130 | return ~*CSR_TIMER3_VALUE; |
| 131 | } |
| 132 | |
| 133 | void __init footbridge_sched_clock(void) |
| 134 | { |
| 135 | unsigned rate = DIV_ROUND_CLOSEST(mem_fclk_21285, 16); |
| 136 | |
| 137 | *CSR_TIMER3_LOAD = 0; |
| 138 | *CSR_TIMER3_CLR = 0; |
| 139 | *CSR_TIMER3_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16; |
| 140 | |
Stephen Boyd | 889f172 | 2014-01-17 20:42:48 +0100 | [diff] [blame] | 141 | sched_clock_register(footbridge_read_sched_clock, 24, rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |