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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | #include <asm/irq.h> |
| 14 | |
| 15 | #include <asm/hardware/dec21285.h> |
| 16 | #include <asm/mach/time.h> |
| 17 | |
| 18 | #include "common.h" |
| 19 | |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 20 | static cycle_t cksrc_dc21285_read(struct clocksource *cs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 22 | return cs->mask - *CSR_TIMER2_VALUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | } |
| 24 | |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 25 | static int cksrc_dc21285_enable(struct clocksource *cs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 27 | *CSR_TIMER2_LOAD = cs->mask; |
| 28 | *CSR_TIMER2_CLR = 0; |
| 29 | *CSR_TIMER2_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16; |
| 30 | return 0; |
| 31 | } |
| 32 | |
Thomas Gleixner | f2e0bf2 | 2011-03-28 11:25:40 +0200 | [diff] [blame^] | 33 | static void cksrc_dc21285_disable(struct clocksource *cs) |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 34 | { |
| 35 | *CSR_TIMER2_CNTL = 0; |
| 36 | } |
| 37 | |
| 38 | static struct clocksource cksrc_dc21285 = { |
| 39 | .name = "dc21285_timer2", |
| 40 | .rating = 200, |
| 41 | .read = cksrc_dc21285_read, |
| 42 | .enable = cksrc_dc21285_enable, |
| 43 | .disable = cksrc_dc21285_disable, |
| 44 | .mask = CLOCKSOURCE_MASK(24), |
| 45 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
| 46 | }; |
| 47 | |
| 48 | static void ckevt_dc21285_set_mode(enum clock_event_mode mode, |
| 49 | struct clock_event_device *c) |
| 50 | { |
| 51 | switch (mode) { |
| 52 | case CLOCK_EVT_MODE_RESUME: |
| 53 | case CLOCK_EVT_MODE_PERIODIC: |
| 54 | *CSR_TIMER1_CLR = 0; |
| 55 | *CSR_TIMER1_LOAD = (mem_fclk_21285 + 8 * HZ) / (16 * HZ); |
| 56 | *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_AUTORELOAD | |
| 57 | TIMER_CNTL_DIV16; |
| 58 | break; |
| 59 | |
| 60 | default: |
| 61 | *CSR_TIMER1_CNTL = 0; |
| 62 | break; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | static struct clock_event_device ckevt_dc21285 = { |
| 67 | .name = "dc21285_timer1", |
| 68 | .features = CLOCK_EVT_FEAT_PERIODIC, |
| 69 | .rating = 200, |
| 70 | .irq = IRQ_TIMER1, |
| 71 | .set_mode = ckevt_dc21285_set_mode, |
| 72 | }; |
| 73 | |
| 74 | static irqreturn_t timer1_interrupt(int irq, void *dev_id) |
| 75 | { |
| 76 | struct clock_event_device *ce = dev_id; |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | *CSR_TIMER1_CLR = 0; |
| 79 | |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 80 | ce->event_handler(ce); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | return IRQ_HANDLED; |
| 83 | } |
| 84 | |
| 85 | static struct irqaction footbridge_timer_irq = { |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 86 | .name = "dc21285_timer1", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | .handler = timer1_interrupt, |
Bernhard Walle | b30faba | 2007-05-08 00:35:39 -0700 | [diff] [blame] | 88 | .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL, |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 89 | .dev_id = &ckevt_dc21285, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | /* |
| 93 | * Set up timer interrupt. |
| 94 | */ |
| 95 | static void __init footbridge_timer_init(void) |
| 96 | { |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 97 | struct clock_event_device *ce = &ckevt_dc21285; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 99 | clocksource_register_hz(&cksrc_dc21285, (mem_fclk_21285 + 8) / 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Russell King | 4e8d763 | 2011-01-28 21:00:39 +0000 | [diff] [blame] | 101 | setup_irq(ce->irq, &footbridge_timer_irq); |
| 102 | |
| 103 | clockevents_calc_mult_shift(ce, mem_fclk_21285, 5); |
| 104 | ce->max_delta_ns = clockevent_delta2ns(0xffffff, ce); |
| 105 | ce->min_delta_ns = clockevent_delta2ns(0x000004, ce); |
| 106 | |
| 107 | clockevents_register_device(ce); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | struct sys_timer footbridge_timer = { |
| 111 | .init = footbridge_timer_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | }; |