Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/plat-omap/dmtimer.c |
| 3 | * |
| 4 | * OMAP Dual-Mode Timers |
| 5 | * |
| 6 | * Copyright (C) 2005 Nokia Corporation |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 7 | * OMAP2 support by Juha Yrjola |
| 8 | * API improvements and OMAP2 clock framework support by Timo Teras |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 16 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 17 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
| 18 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License along |
| 25 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 26 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 27 | */ |
| 28 | |
| 29 | #include <linux/init.h> |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 30 | #include <linux/spinlock.h> |
| 31 | #include <linux/errno.h> |
| 32 | #include <linux/list.h> |
| 33 | #include <linux/clk.h> |
| 34 | #include <linux/delay.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 35 | #include <linux/io.h> |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 36 | #include <linux/module.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 37 | #include <mach/hardware.h> |
| 38 | #include <mach/dmtimer.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 39 | #include <mach/irqs.h> |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 40 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 41 | /* register offsets */ |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 42 | #define _OMAP_TIMER_ID_OFFSET 0x00 |
| 43 | #define _OMAP_TIMER_OCP_CFG_OFFSET 0x10 |
| 44 | #define _OMAP_TIMER_SYS_STAT_OFFSET 0x14 |
| 45 | #define _OMAP_TIMER_STAT_OFFSET 0x18 |
| 46 | #define _OMAP_TIMER_INT_EN_OFFSET 0x1c |
| 47 | #define _OMAP_TIMER_WAKEUP_EN_OFFSET 0x20 |
| 48 | #define _OMAP_TIMER_CTRL_OFFSET 0x24 |
| 49 | #define OMAP_TIMER_CTRL_GPOCFG (1 << 14) |
| 50 | #define OMAP_TIMER_CTRL_CAPTMODE (1 << 13) |
| 51 | #define OMAP_TIMER_CTRL_PT (1 << 12) |
| 52 | #define OMAP_TIMER_CTRL_TCM_LOWTOHIGH (0x1 << 8) |
| 53 | #define OMAP_TIMER_CTRL_TCM_HIGHTOLOW (0x2 << 8) |
| 54 | #define OMAP_TIMER_CTRL_TCM_BOTHEDGES (0x3 << 8) |
| 55 | #define OMAP_TIMER_CTRL_SCPWM (1 << 7) |
| 56 | #define OMAP_TIMER_CTRL_CE (1 << 6) /* compare enable */ |
| 57 | #define OMAP_TIMER_CTRL_PRE (1 << 5) /* prescaler enable */ |
| 58 | #define OMAP_TIMER_CTRL_PTV_SHIFT 2 /* prescaler value shift */ |
| 59 | #define OMAP_TIMER_CTRL_POSTED (1 << 2) |
| 60 | #define OMAP_TIMER_CTRL_AR (1 << 1) /* auto-reload enable */ |
| 61 | #define OMAP_TIMER_CTRL_ST (1 << 0) /* start timer */ |
| 62 | #define _OMAP_TIMER_COUNTER_OFFSET 0x28 |
| 63 | #define _OMAP_TIMER_LOAD_OFFSET 0x2c |
| 64 | #define _OMAP_TIMER_TRIGGER_OFFSET 0x30 |
| 65 | #define _OMAP_TIMER_WRITE_PEND_OFFSET 0x34 |
| 66 | #define WP_NONE 0 /* no write pending bit */ |
| 67 | #define WP_TCLR (1 << 0) |
| 68 | #define WP_TCRR (1 << 1) |
| 69 | #define WP_TLDR (1 << 2) |
| 70 | #define WP_TTGR (1 << 3) |
| 71 | #define WP_TMAR (1 << 4) |
| 72 | #define WP_TPIR (1 << 5) |
| 73 | #define WP_TNIR (1 << 6) |
| 74 | #define WP_TCVR (1 << 7) |
| 75 | #define WP_TOCR (1 << 8) |
| 76 | #define WP_TOWR (1 << 9) |
| 77 | #define _OMAP_TIMER_MATCH_OFFSET 0x38 |
| 78 | #define _OMAP_TIMER_CAPTURE_OFFSET 0x3c |
| 79 | #define _OMAP_TIMER_IF_CTRL_OFFSET 0x40 |
| 80 | #define _OMAP_TIMER_CAPTURE2_OFFSET 0x44 /* TCAR2, 34xx only */ |
| 81 | #define _OMAP_TIMER_TICK_POS_OFFSET 0x48 /* TPIR, 34xx only */ |
| 82 | #define _OMAP_TIMER_TICK_NEG_OFFSET 0x4c /* TNIR, 34xx only */ |
| 83 | #define _OMAP_TIMER_TICK_COUNT_OFFSET 0x50 /* TCVR, 34xx only */ |
| 84 | #define _OMAP_TIMER_TICK_INT_MASK_SET_OFFSET 0x54 /* TOCR, 34xx only */ |
| 85 | #define _OMAP_TIMER_TICK_INT_MASK_COUNT_OFFSET 0x58 /* TOWR, 34xx only */ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 86 | |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 87 | /* register offsets with the write pending bit encoded */ |
| 88 | #define WPSHIFT 16 |
| 89 | |
| 90 | #define OMAP_TIMER_ID_REG (_OMAP_TIMER_ID_OFFSET \ |
| 91 | | (WP_NONE << WPSHIFT)) |
| 92 | |
| 93 | #define OMAP_TIMER_OCP_CFG_REG (_OMAP_TIMER_OCP_CFG_OFFSET \ |
| 94 | | (WP_NONE << WPSHIFT)) |
| 95 | |
| 96 | #define OMAP_TIMER_SYS_STAT_REG (_OMAP_TIMER_SYS_STAT_OFFSET \ |
| 97 | | (WP_NONE << WPSHIFT)) |
| 98 | |
| 99 | #define OMAP_TIMER_STAT_REG (_OMAP_TIMER_STAT_OFFSET \ |
| 100 | | (WP_NONE << WPSHIFT)) |
| 101 | |
| 102 | #define OMAP_TIMER_INT_EN_REG (_OMAP_TIMER_INT_EN_OFFSET \ |
| 103 | | (WP_NONE << WPSHIFT)) |
| 104 | |
| 105 | #define OMAP_TIMER_WAKEUP_EN_REG (_OMAP_TIMER_WAKEUP_EN_OFFSET \ |
| 106 | | (WP_NONE << WPSHIFT)) |
| 107 | |
| 108 | #define OMAP_TIMER_CTRL_REG (_OMAP_TIMER_CTRL_OFFSET \ |
| 109 | | (WP_TCLR << WPSHIFT)) |
| 110 | |
| 111 | #define OMAP_TIMER_COUNTER_REG (_OMAP_TIMER_COUNTER_OFFSET \ |
| 112 | | (WP_TCRR << WPSHIFT)) |
| 113 | |
| 114 | #define OMAP_TIMER_LOAD_REG (_OMAP_TIMER_LOAD_OFFSET \ |
| 115 | | (WP_TLDR << WPSHIFT)) |
| 116 | |
| 117 | #define OMAP_TIMER_TRIGGER_REG (_OMAP_TIMER_TRIGGER_OFFSET \ |
| 118 | | (WP_TTGR << WPSHIFT)) |
| 119 | |
| 120 | #define OMAP_TIMER_WRITE_PEND_REG (_OMAP_TIMER_WRITE_PEND_OFFSET \ |
| 121 | | (WP_NONE << WPSHIFT)) |
| 122 | |
| 123 | #define OMAP_TIMER_MATCH_REG (_OMAP_TIMER_MATCH_OFFSET \ |
| 124 | | (WP_TMAR << WPSHIFT)) |
| 125 | |
| 126 | #define OMAP_TIMER_CAPTURE_REG (_OMAP_TIMER_CAPTURE_OFFSET \ |
| 127 | | (WP_NONE << WPSHIFT)) |
| 128 | |
| 129 | #define OMAP_TIMER_IF_CTRL_REG (_OMAP_TIMER_IF_CTRL_OFFSET \ |
| 130 | | (WP_NONE << WPSHIFT)) |
| 131 | |
| 132 | #define OMAP_TIMER_CAPTURE2_REG (_OMAP_TIMER_CAPTURE2_OFFSET \ |
| 133 | | (WP_NONE << WPSHIFT)) |
| 134 | |
| 135 | #define OMAP_TIMER_TICK_POS_REG (_OMAP_TIMER_TICK_POS_OFFSET \ |
| 136 | | (WP_TPIR << WPSHIFT)) |
| 137 | |
| 138 | #define OMAP_TIMER_TICK_NEG_REG (_OMAP_TIMER_TICK_NEG_OFFSET \ |
| 139 | | (WP_TNIR << WPSHIFT)) |
| 140 | |
| 141 | #define OMAP_TIMER_TICK_COUNT_REG (_OMAP_TIMER_TICK_COUNT_OFFSET \ |
| 142 | | (WP_TCVR << WPSHIFT)) |
| 143 | |
| 144 | #define OMAP_TIMER_TICK_INT_MASK_SET_REG \ |
| 145 | (_OMAP_TIMER_TICK_INT_MASK_SET_OFFSET | (WP_TOCR << WPSHIFT)) |
| 146 | |
| 147 | #define OMAP_TIMER_TICK_INT_MASK_COUNT_REG \ |
| 148 | (_OMAP_TIMER_TICK_INT_MASK_COUNT_OFFSET | (WP_TOWR << WPSHIFT)) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 149 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 150 | struct omap_dm_timer { |
| 151 | unsigned long phys_base; |
| 152 | int irq; |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 153 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 154 | struct clk *iclk, *fclk; |
| 155 | #endif |
| 156 | void __iomem *io_base; |
| 157 | unsigned reserved:1; |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 158 | unsigned enabled:1; |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 159 | unsigned posted:1; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 160 | }; |
| 161 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 162 | #ifdef CONFIG_ARCH_OMAP1 |
| 163 | |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 164 | #define omap_dm_clk_enable(x) |
| 165 | #define omap_dm_clk_disable(x) |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 166 | #define omap2_dm_timers NULL |
| 167 | #define omap2_dm_source_names NULL |
| 168 | #define omap2_dm_source_clocks NULL |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 169 | #define omap3_dm_timers NULL |
| 170 | #define omap3_dm_source_names NULL |
| 171 | #define omap3_dm_source_clocks NULL |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 172 | |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 173 | static struct omap_dm_timer omap1_dm_timers[] = { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 174 | { .phys_base = 0xfffb1400, .irq = INT_1610_GPTIMER1 }, |
| 175 | { .phys_base = 0xfffb1c00, .irq = INT_1610_GPTIMER2 }, |
| 176 | { .phys_base = 0xfffb2400, .irq = INT_1610_GPTIMER3 }, |
| 177 | { .phys_base = 0xfffb2c00, .irq = INT_1610_GPTIMER4 }, |
| 178 | { .phys_base = 0xfffb3400, .irq = INT_1610_GPTIMER5 }, |
| 179 | { .phys_base = 0xfffb3c00, .irq = INT_1610_GPTIMER6 }, |
Matthew Percival | 53037f4 | 2007-01-25 16:24:29 -0800 | [diff] [blame] | 180 | { .phys_base = 0xfffb7400, .irq = INT_1610_GPTIMER7 }, |
| 181 | { .phys_base = 0xfffbd400, .irq = INT_1610_GPTIMER8 }, |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 184 | static const int dm_timer_count = ARRAY_SIZE(omap1_dm_timers); |
| 185 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 186 | #elif defined(CONFIG_ARCH_OMAP2) |
| 187 | |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 188 | #define omap_dm_clk_enable(x) clk_enable(x) |
| 189 | #define omap_dm_clk_disable(x) clk_disable(x) |
| 190 | #define omap1_dm_timers NULL |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 191 | #define omap3_dm_timers NULL |
| 192 | #define omap3_dm_source_names NULL |
| 193 | #define omap3_dm_source_clocks NULL |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 194 | |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 195 | static struct omap_dm_timer omap2_dm_timers[] = { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 196 | { .phys_base = 0x48028000, .irq = INT_24XX_GPTIMER1 }, |
| 197 | { .phys_base = 0x4802a000, .irq = INT_24XX_GPTIMER2 }, |
| 198 | { .phys_base = 0x48078000, .irq = INT_24XX_GPTIMER3 }, |
| 199 | { .phys_base = 0x4807a000, .irq = INT_24XX_GPTIMER4 }, |
| 200 | { .phys_base = 0x4807c000, .irq = INT_24XX_GPTIMER5 }, |
| 201 | { .phys_base = 0x4807e000, .irq = INT_24XX_GPTIMER6 }, |
| 202 | { .phys_base = 0x48080000, .irq = INT_24XX_GPTIMER7 }, |
| 203 | { .phys_base = 0x48082000, .irq = INT_24XX_GPTIMER8 }, |
| 204 | { .phys_base = 0x48084000, .irq = INT_24XX_GPTIMER9 }, |
| 205 | { .phys_base = 0x48086000, .irq = INT_24XX_GPTIMER10 }, |
| 206 | { .phys_base = 0x48088000, .irq = INT_24XX_GPTIMER11 }, |
| 207 | { .phys_base = 0x4808a000, .irq = INT_24XX_GPTIMER12 }, |
| 208 | }; |
| 209 | |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 210 | static const char *omap2_dm_source_names[] __initdata = { |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 211 | "sys_ck", |
| 212 | "func_32k_ck", |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 213 | "alt_ck", |
| 214 | NULL |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 217 | static struct clk **omap2_dm_source_clocks[3]; |
| 218 | static const int dm_timer_count = ARRAY_SIZE(omap2_dm_timers); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 219 | |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 220 | #elif defined(CONFIG_ARCH_OMAP3) |
| 221 | |
| 222 | #define omap_dm_clk_enable(x) clk_enable(x) |
| 223 | #define omap_dm_clk_disable(x) clk_disable(x) |
| 224 | #define omap1_dm_timers NULL |
| 225 | #define omap2_dm_timers NULL |
| 226 | #define omap2_dm_source_names NULL |
| 227 | #define omap2_dm_source_clocks NULL |
| 228 | |
| 229 | static struct omap_dm_timer omap3_dm_timers[] = { |
| 230 | { .phys_base = 0x48318000, .irq = INT_24XX_GPTIMER1 }, |
| 231 | { .phys_base = 0x49032000, .irq = INT_24XX_GPTIMER2 }, |
| 232 | { .phys_base = 0x49034000, .irq = INT_24XX_GPTIMER3 }, |
| 233 | { .phys_base = 0x49036000, .irq = INT_24XX_GPTIMER4 }, |
| 234 | { .phys_base = 0x49038000, .irq = INT_24XX_GPTIMER5 }, |
| 235 | { .phys_base = 0x4903A000, .irq = INT_24XX_GPTIMER6 }, |
| 236 | { .phys_base = 0x4903C000, .irq = INT_24XX_GPTIMER7 }, |
| 237 | { .phys_base = 0x4903E000, .irq = INT_24XX_GPTIMER8 }, |
| 238 | { .phys_base = 0x49040000, .irq = INT_24XX_GPTIMER9 }, |
| 239 | { .phys_base = 0x48086000, .irq = INT_24XX_GPTIMER10 }, |
| 240 | { .phys_base = 0x48088000, .irq = INT_24XX_GPTIMER11 }, |
Paul Walmsley | 9198a40 | 2009-04-23 21:11:08 -0600 | [diff] [blame] | 241 | { .phys_base = 0x48304000, .irq = INT_34XX_GPT12_IRQ }, |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | static const char *omap3_dm_source_names[] __initdata = { |
| 245 | "sys_ck", |
| 246 | "omap_32k_fck", |
| 247 | NULL |
| 248 | }; |
| 249 | |
| 250 | static struct clk **omap3_dm_source_clocks[2]; |
| 251 | static const int dm_timer_count = ARRAY_SIZE(omap3_dm_timers); |
| 252 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 253 | #else |
| 254 | |
| 255 | #error OMAP architecture not supported! |
| 256 | |
| 257 | #endif |
| 258 | |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 259 | static struct omap_dm_timer *dm_timers; |
| 260 | static char **dm_source_names; |
| 261 | static struct clk **dm_source_clocks; |
| 262 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 263 | static spinlock_t dm_timer_lock; |
| 264 | |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 265 | /* |
| 266 | * Reads timer registers in posted and non-posted mode. The posted mode bit |
| 267 | * is encoded in reg. Note that in posted mode write pending bit must be |
| 268 | * checked. Otherwise a read of a non completed write will produce an error. |
| 269 | */ |
| 270 | static inline u32 omap_dm_timer_read_reg(struct omap_dm_timer *timer, u32 reg) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 271 | { |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 272 | if (timer->posted) |
| 273 | while (readl(timer->io_base + (OMAP_TIMER_WRITE_PEND_REG & 0xff)) |
| 274 | & (reg >> WPSHIFT)) |
| 275 | cpu_relax(); |
| 276 | return readl(timer->io_base + (reg & 0xff)); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 279 | /* |
| 280 | * Writes timer registers in posted and non-posted mode. The posted mode bit |
| 281 | * is encoded in reg. Note that in posted mode the write pending bit must be |
| 282 | * checked. Otherwise a write on a register which has a pending write will be |
| 283 | * lost. |
| 284 | */ |
| 285 | static void omap_dm_timer_write_reg(struct omap_dm_timer *timer, u32 reg, |
| 286 | u32 value) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 287 | { |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 288 | if (timer->posted) |
| 289 | while (readl(timer->io_base + (OMAP_TIMER_WRITE_PEND_REG & 0xff)) |
| 290 | & (reg >> WPSHIFT)) |
| 291 | cpu_relax(); |
| 292 | writel(value, timer->io_base + (reg & 0xff)); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 293 | } |
| 294 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 295 | static void omap_dm_timer_wait_for_reset(struct omap_dm_timer *timer) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 296 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 297 | int c; |
| 298 | |
| 299 | c = 0; |
| 300 | while (!(omap_dm_timer_read_reg(timer, OMAP_TIMER_SYS_STAT_REG) & 1)) { |
| 301 | c++; |
| 302 | if (c > 100000) { |
| 303 | printk(KERN_ERR "Timer failed to reset\n"); |
| 304 | return; |
| 305 | } |
| 306 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 307 | } |
| 308 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 309 | static void omap_dm_timer_reset(struct omap_dm_timer *timer) |
| 310 | { |
| 311 | u32 l; |
| 312 | |
Juha Yrjola | 3902084 | 2006-09-25 12:41:44 +0300 | [diff] [blame] | 313 | if (!cpu_class_is_omap2() || timer != &dm_timers[0]) { |
Timo Teras | e32f7ec | 2006-06-26 16:16:13 -0700 | [diff] [blame] | 314 | omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, 0x06); |
| 315 | omap_dm_timer_wait_for_reset(timer); |
| 316 | } |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 317 | omap_dm_timer_set_source(timer, OMAP_TIMER_SRC_32_KHZ); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 318 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 319 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_OCP_CFG_REG); |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 320 | l |= 0x02 << 3; /* Set to smart-idle mode */ |
| 321 | l |= 0x2 << 8; /* Set clock activity to perserve f-clock on idle */ |
Juha Yrjola | 3902084 | 2006-09-25 12:41:44 +0300 | [diff] [blame] | 322 | |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 323 | /* |
Kevin Hilman | 219c5b9 | 2009-04-23 21:11:08 -0600 | [diff] [blame^] | 324 | * Enable wake-up on OMAP2 CPUs. |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 325 | */ |
Kevin Hilman | 219c5b9 | 2009-04-23 21:11:08 -0600 | [diff] [blame^] | 326 | if (cpu_class_is_omap2()) |
Juha Yrjola | 3902084 | 2006-09-25 12:41:44 +0300 | [diff] [blame] | 327 | l |= 1 << 2; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 328 | omap_dm_timer_write_reg(timer, OMAP_TIMER_OCP_CFG_REG, l); |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 329 | |
| 330 | /* Match hardware reset default of posted mode */ |
| 331 | omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, |
| 332 | OMAP_TIMER_CTRL_POSTED); |
| 333 | timer->posted = 1; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 336 | static void omap_dm_timer_prepare(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 337 | { |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 338 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 339 | omap_dm_timer_reset(timer); |
| 340 | } |
| 341 | |
| 342 | struct omap_dm_timer *omap_dm_timer_request(void) |
| 343 | { |
| 344 | struct omap_dm_timer *timer = NULL; |
| 345 | unsigned long flags; |
| 346 | int i; |
| 347 | |
| 348 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 349 | for (i = 0; i < dm_timer_count; i++) { |
| 350 | if (dm_timers[i].reserved) |
| 351 | continue; |
| 352 | |
| 353 | timer = &dm_timers[i]; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 354 | timer->reserved = 1; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 355 | break; |
| 356 | } |
| 357 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 358 | |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 359 | if (timer != NULL) |
| 360 | omap_dm_timer_prepare(timer); |
| 361 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 362 | return timer; |
| 363 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 364 | EXPORT_SYMBOL_GPL(omap_dm_timer_request); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 365 | |
| 366 | struct omap_dm_timer *omap_dm_timer_request_specific(int id) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 367 | { |
| 368 | struct omap_dm_timer *timer; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 369 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 370 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 371 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 372 | if (id <= 0 || id > dm_timer_count || dm_timers[id-1].reserved) { |
| 373 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 374 | printk("BUG: warning at %s:%d/%s(): unable to get timer %d\n", |
Harvey Harrison | 8e86f42 | 2008-03-04 15:08:02 -0800 | [diff] [blame] | 375 | __FILE__, __LINE__, __func__, id); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 376 | dump_stack(); |
| 377 | return NULL; |
| 378 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 379 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 380 | timer = &dm_timers[id-1]; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 381 | timer->reserved = 1; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 382 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 383 | |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 384 | omap_dm_timer_prepare(timer); |
| 385 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 386 | return timer; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 387 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 388 | EXPORT_SYMBOL_GPL(omap_dm_timer_request_specific); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 389 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 390 | void omap_dm_timer_free(struct omap_dm_timer *timer) |
| 391 | { |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 392 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 393 | omap_dm_timer_reset(timer); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 394 | omap_dm_timer_disable(timer); |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 395 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 396 | WARN_ON(!timer->reserved); |
| 397 | timer->reserved = 0; |
| 398 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 399 | EXPORT_SYMBOL_GPL(omap_dm_timer_free); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 400 | |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 401 | void omap_dm_timer_enable(struct omap_dm_timer *timer) |
| 402 | { |
| 403 | if (timer->enabled) |
| 404 | return; |
| 405 | |
| 406 | omap_dm_clk_enable(timer->fclk); |
| 407 | omap_dm_clk_enable(timer->iclk); |
| 408 | |
| 409 | timer->enabled = 1; |
| 410 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 411 | EXPORT_SYMBOL_GPL(omap_dm_timer_enable); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 412 | |
| 413 | void omap_dm_timer_disable(struct omap_dm_timer *timer) |
| 414 | { |
| 415 | if (!timer->enabled) |
| 416 | return; |
| 417 | |
| 418 | omap_dm_clk_disable(timer->iclk); |
| 419 | omap_dm_clk_disable(timer->fclk); |
| 420 | |
| 421 | timer->enabled = 0; |
| 422 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 423 | EXPORT_SYMBOL_GPL(omap_dm_timer_disable); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 424 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 425 | int omap_dm_timer_get_irq(struct omap_dm_timer *timer) |
| 426 | { |
| 427 | return timer->irq; |
| 428 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 429 | EXPORT_SYMBOL_GPL(omap_dm_timer_get_irq); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 430 | |
| 431 | #if defined(CONFIG_ARCH_OMAP1) |
| 432 | |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 433 | /** |
| 434 | * omap_dm_timer_modify_idlect_mask - Check if any running timers use ARMXOR |
| 435 | * @inputmask: current value of idlect mask |
| 436 | */ |
| 437 | __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask) |
| 438 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 439 | int i; |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 440 | |
| 441 | /* If ARMXOR cannot be idled this function call is unnecessary */ |
| 442 | if (!(inputmask & (1 << 1))) |
| 443 | return inputmask; |
| 444 | |
| 445 | /* If any active timer is using ARMXOR return modified mask */ |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 446 | for (i = 0; i < dm_timer_count; i++) { |
| 447 | u32 l; |
| 448 | |
Tony Lindgren | 35912c7 | 2006-07-01 19:56:42 +0100 | [diff] [blame] | 449 | l = omap_dm_timer_read_reg(&dm_timers[i], OMAP_TIMER_CTRL_REG); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 450 | if (l & OMAP_TIMER_CTRL_ST) { |
| 451 | if (((omap_readl(MOD_CONF_CTRL_1) >> (i * 2)) & 0x03) == 0) |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 452 | inputmask &= ~(1 << 1); |
| 453 | else |
| 454 | inputmask &= ~(1 << 2); |
| 455 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 456 | } |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 457 | |
| 458 | return inputmask; |
| 459 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 460 | EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask); |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 461 | |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 462 | #elif defined(CONFIG_ARCH_OMAP2) || defined (CONFIG_ARCH_OMAP3) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 463 | |
| 464 | struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer) |
| 465 | { |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 466 | return timer->fclk; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 467 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 468 | EXPORT_SYMBOL_GPL(omap_dm_timer_get_fclk); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 469 | |
| 470 | __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask) |
| 471 | { |
| 472 | BUG(); |
Dirk Behme | 2121880 | 2006-12-06 17:14:00 -0800 | [diff] [blame] | 473 | |
| 474 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 475 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 476 | EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 477 | |
| 478 | #endif |
| 479 | |
| 480 | void omap_dm_timer_trigger(struct omap_dm_timer *timer) |
| 481 | { |
| 482 | omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0); |
| 483 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 484 | EXPORT_SYMBOL_GPL(omap_dm_timer_trigger); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 485 | |
| 486 | void omap_dm_timer_start(struct omap_dm_timer *timer) |
| 487 | { |
| 488 | u32 l; |
| 489 | |
| 490 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 491 | if (!(l & OMAP_TIMER_CTRL_ST)) { |
| 492 | l |= OMAP_TIMER_CTRL_ST; |
| 493 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 494 | } |
| 495 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 496 | EXPORT_SYMBOL_GPL(omap_dm_timer_start); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 497 | |
| 498 | void omap_dm_timer_stop(struct omap_dm_timer *timer) |
| 499 | { |
| 500 | u32 l; |
| 501 | |
| 502 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 503 | if (l & OMAP_TIMER_CTRL_ST) { |
| 504 | l &= ~0x1; |
| 505 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 506 | } |
| 507 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 508 | EXPORT_SYMBOL_GPL(omap_dm_timer_stop); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 509 | |
| 510 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 511 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 512 | void omap_dm_timer_set_source(struct omap_dm_timer *timer, int source) |
| 513 | { |
| 514 | int n = (timer - dm_timers) << 1; |
| 515 | u32 l; |
| 516 | |
| 517 | l = omap_readl(MOD_CONF_CTRL_1) & ~(0x03 << n); |
| 518 | l |= source << n; |
| 519 | omap_writel(l, MOD_CONF_CTRL_1); |
| 520 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 521 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_source); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 522 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 523 | #else |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 524 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 525 | void omap_dm_timer_set_source(struct omap_dm_timer *timer, int source) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 526 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 527 | if (source < 0 || source >= 3) |
| 528 | return; |
| 529 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 530 | clk_disable(timer->fclk); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 531 | clk_set_parent(timer->fclk, dm_source_clocks[source]); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 532 | clk_enable(timer->fclk); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 533 | |
| 534 | /* When the functional clock disappears, too quick writes seem to |
| 535 | * cause an abort. */ |
Tony Lindgren | c40fae9 | 2006-12-07 13:58:10 -0800 | [diff] [blame] | 536 | __delay(150000); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 537 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 538 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_source); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 539 | |
| 540 | #endif |
| 541 | |
| 542 | void omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, |
| 543 | unsigned int load) |
| 544 | { |
| 545 | u32 l; |
| 546 | |
| 547 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 548 | if (autoreload) |
| 549 | l |= OMAP_TIMER_CTRL_AR; |
| 550 | else |
| 551 | l &= ~OMAP_TIMER_CTRL_AR; |
| 552 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 553 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load); |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 554 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 555 | omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0); |
| 556 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 557 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_load); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 558 | |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 559 | /* Optimized set_load which removes costly spin wait in timer_start */ |
| 560 | void omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload, |
| 561 | unsigned int load) |
| 562 | { |
| 563 | u32 l; |
| 564 | |
| 565 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 566 | if (autoreload) { |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 567 | l |= OMAP_TIMER_CTRL_AR; |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 568 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load); |
| 569 | } else { |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 570 | l &= ~OMAP_TIMER_CTRL_AR; |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 571 | } |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 572 | l |= OMAP_TIMER_CTRL_ST; |
| 573 | |
| 574 | omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, load); |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 575 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 576 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 577 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_load_start); |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 578 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 579 | void omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable, |
| 580 | unsigned int match) |
| 581 | { |
| 582 | u32 l; |
| 583 | |
| 584 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 585 | if (enable) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 586 | l |= OMAP_TIMER_CTRL_CE; |
| 587 | else |
| 588 | l &= ~OMAP_TIMER_CTRL_CE; |
| 589 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 590 | omap_dm_timer_write_reg(timer, OMAP_TIMER_MATCH_REG, match); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 591 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 592 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_match); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 593 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 594 | void omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on, |
| 595 | int toggle, int trigger) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 596 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 597 | u32 l; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 598 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 599 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 600 | l &= ~(OMAP_TIMER_CTRL_GPOCFG | OMAP_TIMER_CTRL_SCPWM | |
| 601 | OMAP_TIMER_CTRL_PT | (0x03 << 10)); |
| 602 | if (def_on) |
| 603 | l |= OMAP_TIMER_CTRL_SCPWM; |
| 604 | if (toggle) |
| 605 | l |= OMAP_TIMER_CTRL_PT; |
| 606 | l |= trigger << 10; |
| 607 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 608 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 609 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_pwm); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 610 | |
| 611 | void omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler) |
| 612 | { |
| 613 | u32 l; |
| 614 | |
| 615 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 616 | l &= ~(OMAP_TIMER_CTRL_PRE | (0x07 << 2)); |
| 617 | if (prescaler >= 0x00 && prescaler <= 0x07) { |
| 618 | l |= OMAP_TIMER_CTRL_PRE; |
| 619 | l |= prescaler << 2; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 620 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 621 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 622 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 623 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_prescaler); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 624 | |
| 625 | void omap_dm_timer_set_int_enable(struct omap_dm_timer *timer, |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 626 | unsigned int value) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 627 | { |
| 628 | omap_dm_timer_write_reg(timer, OMAP_TIMER_INT_EN_REG, value); |
Juha Yrjola | 3902084 | 2006-09-25 12:41:44 +0300 | [diff] [blame] | 629 | omap_dm_timer_write_reg(timer, OMAP_TIMER_WAKEUP_EN_REG, value); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 630 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 631 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_int_enable); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 632 | |
| 633 | unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer) |
| 634 | { |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 635 | unsigned int l; |
| 636 | |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 637 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_STAT_REG); |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 638 | |
| 639 | return l; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 640 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 641 | EXPORT_SYMBOL_GPL(omap_dm_timer_read_status); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 642 | |
| 643 | void omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value) |
| 644 | { |
| 645 | omap_dm_timer_write_reg(timer, OMAP_TIMER_STAT_REG, value); |
| 646 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 647 | EXPORT_SYMBOL_GPL(omap_dm_timer_write_status); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 648 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 649 | unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer) |
| 650 | { |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 651 | unsigned int l; |
| 652 | |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 653 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_COUNTER_REG); |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 654 | |
| 655 | return l; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 656 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 657 | EXPORT_SYMBOL_GPL(omap_dm_timer_read_counter); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 658 | |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 659 | void omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value) |
| 660 | { |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 661 | omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, value); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 662 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 663 | EXPORT_SYMBOL_GPL(omap_dm_timer_write_counter); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 664 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 665 | int omap_dm_timers_active(void) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 666 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 667 | int i; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 668 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 669 | for (i = 0; i < dm_timer_count; i++) { |
| 670 | struct omap_dm_timer *timer; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 671 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 672 | timer = &dm_timers[i]; |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 673 | |
| 674 | if (!timer->enabled) |
| 675 | continue; |
| 676 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 677 | if (omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG) & |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 678 | OMAP_TIMER_CTRL_ST) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 679 | return 1; |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 680 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 681 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 682 | return 0; |
| 683 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 684 | EXPORT_SYMBOL_GPL(omap_dm_timers_active); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 685 | |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 686 | int __init omap_dm_timer_init(void) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 687 | { |
| 688 | struct omap_dm_timer *timer; |
| 689 | int i; |
| 690 | |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 691 | if (!(cpu_is_omap16xx() || cpu_class_is_omap2())) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 692 | return -ENODEV; |
| 693 | |
| 694 | spin_lock_init(&dm_timer_lock); |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 695 | |
| 696 | if (cpu_class_is_omap1()) |
| 697 | dm_timers = omap1_dm_timers; |
| 698 | else if (cpu_is_omap24xx()) { |
| 699 | dm_timers = omap2_dm_timers; |
| 700 | dm_source_names = (char **)omap2_dm_source_names; |
| 701 | dm_source_clocks = (struct clk **)omap2_dm_source_clocks; |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 702 | } else if (cpu_is_omap34xx()) { |
| 703 | dm_timers = omap3_dm_timers; |
| 704 | dm_source_names = (char **)omap3_dm_source_names; |
| 705 | dm_source_clocks = (struct clk **)omap3_dm_source_clocks; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 706 | } |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 707 | |
| 708 | if (cpu_class_is_omap2()) |
| 709 | for (i = 0; dm_source_names[i] != NULL; i++) |
| 710 | dm_source_clocks[i] = clk_get(NULL, dm_source_names[i]); |
| 711 | |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 712 | if (cpu_is_omap243x()) |
| 713 | dm_timers[0].phys_base = 0x49018000; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 714 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 715 | for (i = 0; i < dm_timer_count; i++) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 716 | timer = &dm_timers[i]; |
Russell King | e8a91c9 | 2008-09-01 22:07:37 +0100 | [diff] [blame] | 717 | timer->io_base = IO_ADDRESS(timer->phys_base); |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 718 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 719 | if (cpu_class_is_omap2()) { |
| 720 | char clk_name[16]; |
| 721 | sprintf(clk_name, "gpt%d_ick", i + 1); |
| 722 | timer->iclk = clk_get(NULL, clk_name); |
| 723 | sprintf(clk_name, "gpt%d_fck", i + 1); |
| 724 | timer->fclk = clk_get(NULL, clk_name); |
| 725 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 726 | #endif |
| 727 | } |
| 728 | |
| 729 | return 0; |
| 730 | } |