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