Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | |
| 3 | /* |
Greg Ungerer | b671b65 | 2006-06-26 10:33:10 +1000 | [diff] [blame] | 4 | * pit.c -- Freescale ColdFire PIT timer. Currently this type of |
| 5 | * hardware timer only exists in the Freescale ColdFire |
Greg Ungerer | f15bf19 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 6 | * 5270/5271, 5282 and other CPUs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Greg Ungerer | 5c4525d | 2007-07-27 01:09:00 +1000 | [diff] [blame^] | 8 | * Copyright (C) 1999-2007, Greg Ungerer (gerg@snapgear.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Copyright (C) 2001-2004, SnapGear Inc. (www.snapgear.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | /***************************************************************************/ |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/sched.h> |
| 16 | #include <linux/param.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/interrupt.h> |
Greg Ungerer | 5c4525d | 2007-07-27 01:09:00 +1000 | [diff] [blame^] | 19 | #include <linux/irq.h> |
Greg Ungerer | b671b65 | 2006-06-26 10:33:10 +1000 | [diff] [blame] | 20 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/coldfire.h> |
| 22 | #include <asm/mcfpit.h> |
| 23 | #include <asm/mcfsim.h> |
| 24 | |
| 25 | /***************************************************************************/ |
| 26 | |
Greg Ungerer | b671b65 | 2006-06-26 10:33:10 +1000 | [diff] [blame] | 27 | /* |
| 28 | * By default use timer1 as the system clock timer. |
| 29 | */ |
| 30 | #define TA(a) (MCF_IPSBAR + MCFPIT_BASE1 + (a)) |
| 31 | |
| 32 | /***************************************************************************/ |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | void coldfire_pit_tick(void) |
| 35 | { |
Greg Ungerer | b671b65 | 2006-06-26 10:33:10 +1000 | [diff] [blame] | 36 | unsigned short pcsr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* Reset the ColdFire timer */ |
Greg Ungerer | b671b65 | 2006-06-26 10:33:10 +1000 | [diff] [blame] | 39 | pcsr = __raw_readw(TA(MCFPIT_PCSR)); |
| 40 | __raw_writew(pcsr | MCFPIT_PCSR_PIF, TA(MCFPIT_PCSR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | /***************************************************************************/ |
| 44 | |
Greg Ungerer | 5c4525d | 2007-07-27 01:09:00 +1000 | [diff] [blame^] | 45 | static struct irqaction coldfire_pit_irq = { |
| 46 | .name = "timer", |
| 47 | .flags = IRQF_DISABLED | IRQF_TIMER, |
| 48 | }; |
| 49 | |
Greg Ungerer | 459c6a9 | 2007-02-07 12:02:52 +1000 | [diff] [blame] | 50 | void coldfire_pit_init(irq_handler_t handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
| 52 | volatile unsigned char *icrp; |
| 53 | volatile unsigned long *imrp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Greg Ungerer | 5c4525d | 2007-07-27 01:09:00 +1000 | [diff] [blame^] | 55 | coldfire_pit_irq.handler = handler; |
| 56 | setup_irq(MCFINT_VECBASE + MCFINT_PIT1, &coldfire_pit_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | icrp = (volatile unsigned char *) (MCF_IPSBAR + MCFICM_INTC0 + |
| 59 | MCFINTC_ICR0 + MCFINT_PIT1); |
Greg Ungerer | f15bf19 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 60 | *icrp = ICR_INTRCONF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Greg Ungerer | f15bf19 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 62 | imrp = (volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFPIT_IMR); |
| 63 | *imrp &= ~MCFPIT_IMR_IBIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | /* Set up PIT timer 1 as poll clock */ |
Greg Ungerer | b671b65 | 2006-06-26 10:33:10 +1000 | [diff] [blame] | 66 | __raw_writew(MCFPIT_PCSR_DISABLE, TA(MCFPIT_PCSR)); |
| 67 | __raw_writew(((MCF_CLK / 2) / 64) / HZ, TA(MCFPIT_PMR)); |
| 68 | __raw_writew(MCFPIT_PCSR_EN | MCFPIT_PCSR_PIE | MCFPIT_PCSR_OVW | |
| 69 | MCFPIT_PCSR_RLD | MCFPIT_PCSR_CLK64, TA(MCFPIT_PCSR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /***************************************************************************/ |
| 73 | |
| 74 | unsigned long coldfire_pit_offset(void) |
| 75 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | volatile unsigned long *ipr; |
| 77 | unsigned long pmr, pcntr, offset; |
| 78 | |
Greg Ungerer | f15bf19 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 79 | ipr = (volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFPIT_IMR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Greg Ungerer | b671b65 | 2006-06-26 10:33:10 +1000 | [diff] [blame] | 81 | pmr = __raw_readw(TA(MCFPIT_PMR)); |
| 82 | pcntr = __raw_readw(TA(MCFPIT_PCNTR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * If we are still in the first half of the upcount and a |
| 86 | * timer interupt is pending, then add on a ticks worth of time. |
| 87 | */ |
| 88 | offset = ((pmr - pcntr) * (1000000 / HZ)) / pmr; |
Greg Ungerer | f15bf19 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 89 | if ((offset < (1000000 / HZ / 2)) && (*ipr & MCFPIT_IMR_IBIT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | offset += 1000000 / HZ; |
| 91 | return offset; |
| 92 | } |
| 93 | |
| 94 | /***************************************************************************/ |