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> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 41 | #include <plat/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 | |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 44 | static int dm_timer_count; |
| 45 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 46 | #ifdef CONFIG_ARCH_OMAP1 |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 47 | static struct omap_dm_timer omap1_dm_timers[] = { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 48 | { .phys_base = 0xfffb1400, .irq = INT_1610_GPTIMER1 }, |
| 49 | { .phys_base = 0xfffb1c00, .irq = INT_1610_GPTIMER2 }, |
| 50 | { .phys_base = 0xfffb2400, .irq = INT_1610_GPTIMER3 }, |
| 51 | { .phys_base = 0xfffb2c00, .irq = INT_1610_GPTIMER4 }, |
| 52 | { .phys_base = 0xfffb3400, .irq = INT_1610_GPTIMER5 }, |
| 53 | { .phys_base = 0xfffb3c00, .irq = INT_1610_GPTIMER6 }, |
Matthew Percival | 53037f4 | 2007-01-25 16:24:29 -0800 | [diff] [blame] | 54 | { .phys_base = 0xfffb7400, .irq = INT_1610_GPTIMER7 }, |
| 55 | { .phys_base = 0xfffbd400, .irq = INT_1610_GPTIMER8 }, |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 58 | static const int omap1_dm_timer_count = ARRAY_SIZE(omap1_dm_timers); |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 59 | |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 60 | #else |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 61 | #define omap1_dm_timers NULL |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 62 | #define omap1_dm_timer_count 0 |
| 63 | #endif /* CONFIG_ARCH_OMAP1 */ |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 64 | |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 65 | #ifdef CONFIG_ARCH_OMAP2 |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 66 | static struct omap_dm_timer omap2_dm_timers[] = { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 67 | { .phys_base = 0x48028000, .irq = INT_24XX_GPTIMER1 }, |
| 68 | { .phys_base = 0x4802a000, .irq = INT_24XX_GPTIMER2 }, |
| 69 | { .phys_base = 0x48078000, .irq = INT_24XX_GPTIMER3 }, |
| 70 | { .phys_base = 0x4807a000, .irq = INT_24XX_GPTIMER4 }, |
| 71 | { .phys_base = 0x4807c000, .irq = INT_24XX_GPTIMER5 }, |
| 72 | { .phys_base = 0x4807e000, .irq = INT_24XX_GPTIMER6 }, |
| 73 | { .phys_base = 0x48080000, .irq = INT_24XX_GPTIMER7 }, |
| 74 | { .phys_base = 0x48082000, .irq = INT_24XX_GPTIMER8 }, |
| 75 | { .phys_base = 0x48084000, .irq = INT_24XX_GPTIMER9 }, |
| 76 | { .phys_base = 0x48086000, .irq = INT_24XX_GPTIMER10 }, |
| 77 | { .phys_base = 0x48088000, .irq = INT_24XX_GPTIMER11 }, |
| 78 | { .phys_base = 0x4808a000, .irq = INT_24XX_GPTIMER12 }, |
| 79 | }; |
| 80 | |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 81 | static const char *omap2_dm_source_names[] __initdata = { |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 82 | "sys_ck", |
| 83 | "func_32k_ck", |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 84 | "alt_ck", |
| 85 | NULL |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Santosh Shilimkar | aea2a5b | 2009-05-25 11:08:36 -0700 | [diff] [blame] | 88 | static struct clk *omap2_dm_source_clocks[3]; |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 89 | static const int omap2_dm_timer_count = ARRAY_SIZE(omap2_dm_timers); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 90 | |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 91 | #else |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 92 | #define omap2_dm_timers NULL |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 93 | #define omap2_dm_timer_count 0 |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 94 | #define omap2_dm_source_names NULL |
| 95 | #define omap2_dm_source_clocks NULL |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 96 | #endif /* CONFIG_ARCH_OMAP2 */ |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 97 | |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 98 | #ifdef CONFIG_ARCH_OMAP3 |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 99 | static struct omap_dm_timer omap3_dm_timers[] = { |
| 100 | { .phys_base = 0x48318000, .irq = INT_24XX_GPTIMER1 }, |
| 101 | { .phys_base = 0x49032000, .irq = INT_24XX_GPTIMER2 }, |
| 102 | { .phys_base = 0x49034000, .irq = INT_24XX_GPTIMER3 }, |
| 103 | { .phys_base = 0x49036000, .irq = INT_24XX_GPTIMER4 }, |
| 104 | { .phys_base = 0x49038000, .irq = INT_24XX_GPTIMER5 }, |
| 105 | { .phys_base = 0x4903A000, .irq = INT_24XX_GPTIMER6 }, |
| 106 | { .phys_base = 0x4903C000, .irq = INT_24XX_GPTIMER7 }, |
| 107 | { .phys_base = 0x4903E000, .irq = INT_24XX_GPTIMER8 }, |
| 108 | { .phys_base = 0x49040000, .irq = INT_24XX_GPTIMER9 }, |
| 109 | { .phys_base = 0x48086000, .irq = INT_24XX_GPTIMER10 }, |
| 110 | { .phys_base = 0x48088000, .irq = INT_24XX_GPTIMER11 }, |
Paul Walmsley | 9198a40 | 2009-04-23 21:11:08 -0600 | [diff] [blame] | 111 | { .phys_base = 0x48304000, .irq = INT_34XX_GPT12_IRQ }, |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | static const char *omap3_dm_source_names[] __initdata = { |
| 115 | "sys_ck", |
| 116 | "omap_32k_fck", |
| 117 | NULL |
| 118 | }; |
| 119 | |
Santosh Shilimkar | aea2a5b | 2009-05-25 11:08:36 -0700 | [diff] [blame] | 120 | static struct clk *omap3_dm_source_clocks[2]; |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 121 | static const int omap3_dm_timer_count = ARRAY_SIZE(omap3_dm_timers); |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 122 | |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 123 | #else |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 124 | #define omap3_dm_timers NULL |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 125 | #define omap3_dm_timer_count 0 |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 126 | #define omap3_dm_source_names NULL |
| 127 | #define omap3_dm_source_clocks NULL |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 128 | #endif /* CONFIG_ARCH_OMAP3 */ |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 129 | |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 130 | #ifdef CONFIG_ARCH_OMAP4 |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 131 | static struct omap_dm_timer omap4_dm_timers[] = { |
Santosh Shilimkar | 5772ca7 | 2010-02-18 03:14:12 +0530 | [diff] [blame] | 132 | { .phys_base = 0x4a318000, .irq = OMAP44XX_IRQ_GPT1 }, |
| 133 | { .phys_base = 0x48032000, .irq = OMAP44XX_IRQ_GPT2 }, |
| 134 | { .phys_base = 0x48034000, .irq = OMAP44XX_IRQ_GPT3 }, |
| 135 | { .phys_base = 0x48036000, .irq = OMAP44XX_IRQ_GPT4 }, |
| 136 | { .phys_base = 0x40138000, .irq = OMAP44XX_IRQ_GPT5 }, |
| 137 | { .phys_base = 0x4013a000, .irq = OMAP44XX_IRQ_GPT6 }, |
| 138 | { .phys_base = 0x4013a000, .irq = OMAP44XX_IRQ_GPT7 }, |
| 139 | { .phys_base = 0x4013e000, .irq = OMAP44XX_IRQ_GPT8 }, |
| 140 | { .phys_base = 0x4803e000, .irq = OMAP44XX_IRQ_GPT9 }, |
| 141 | { .phys_base = 0x48086000, .irq = OMAP44XX_IRQ_GPT10 }, |
| 142 | { .phys_base = 0x48088000, .irq = OMAP44XX_IRQ_GPT11 }, |
| 143 | { .phys_base = 0x4a320000, .irq = OMAP44XX_IRQ_GPT12 }, |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 144 | }; |
| 145 | static const char *omap4_dm_source_names[] __initdata = { |
Rajendra Nayak | 1dc993b | 2010-05-18 20:24:00 -0600 | [diff] [blame] | 146 | "sys_clkin_ck", |
| 147 | "sys_32k_ck", |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 148 | NULL |
| 149 | }; |
| 150 | static struct clk *omap4_dm_source_clocks[2]; |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 151 | static const int omap4_dm_timer_count = ARRAY_SIZE(omap4_dm_timers); |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 152 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 153 | #else |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 154 | #define omap4_dm_timers NULL |
| 155 | #define omap4_dm_timer_count 0 |
| 156 | #define omap4_dm_source_names NULL |
| 157 | #define omap4_dm_source_clocks NULL |
| 158 | #endif /* CONFIG_ARCH_OMAP4 */ |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 159 | |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 160 | static struct omap_dm_timer *dm_timers; |
Santosh Shilimkar | aea2a5b | 2009-05-25 11:08:36 -0700 | [diff] [blame] | 161 | static const char **dm_source_names; |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 162 | static struct clk **dm_source_clocks; |
| 163 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 164 | static spinlock_t dm_timer_lock; |
| 165 | |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 166 | /* |
| 167 | * Reads timer registers in posted and non-posted mode. The posted mode bit |
| 168 | * is encoded in reg. Note that in posted mode write pending bit must be |
| 169 | * checked. Otherwise a read of a non completed write will produce an error. |
| 170 | */ |
| 171 | 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] | 172 | { |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 173 | WARN_ON((reg & 0xff) < _OMAP_TIMER_WAKEUP_EN_OFFSET); |
| 174 | return __omap_dm_timer_read(timer, reg, timer->posted); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 177 | /* |
| 178 | * Writes timer registers in posted and non-posted mode. The posted mode bit |
| 179 | * is encoded in reg. Note that in posted mode the write pending bit must be |
| 180 | * checked. Otherwise a write on a register which has a pending write will be |
| 181 | * lost. |
| 182 | */ |
| 183 | static void omap_dm_timer_write_reg(struct omap_dm_timer *timer, u32 reg, |
| 184 | u32 value) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 185 | { |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 186 | WARN_ON((reg & 0xff) < _OMAP_TIMER_WAKEUP_EN_OFFSET); |
| 187 | __omap_dm_timer_write(timer, reg, value, timer->posted); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 190 | 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] | 191 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 192 | int c; |
| 193 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 194 | if (!timer->sys_stat) |
| 195 | return; |
| 196 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 197 | c = 0; |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 198 | while (!(__raw_readl(timer->sys_stat) & 1)) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 199 | c++; |
| 200 | if (c > 100000) { |
| 201 | printk(KERN_ERR "Timer failed to reset\n"); |
| 202 | return; |
| 203 | } |
| 204 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 205 | } |
| 206 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 207 | static void omap_dm_timer_reset(struct omap_dm_timer *timer) |
| 208 | { |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 209 | int autoidle = 0, wakeup = 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 210 | |
Juha Yrjola | 3902084 | 2006-09-25 12:41:44 +0300 | [diff] [blame] | 211 | if (!cpu_class_is_omap2() || timer != &dm_timers[0]) { |
Timo Teras | e32f7ec | 2006-06-26 16:16:13 -0700 | [diff] [blame] | 212 | omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, 0x06); |
| 213 | omap_dm_timer_wait_for_reset(timer); |
| 214 | } |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 215 | omap_dm_timer_set_source(timer, OMAP_TIMER_SRC_32_KHZ); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 216 | |
Ambresh K | ba50348 | 2011-06-15 21:12:35 +0000 | [diff] [blame] | 217 | /* Enable autoidle on OMAP2+ */ |
| 218 | if (cpu_class_is_omap2()) |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 219 | autoidle = 1; |
Tero Kristo | 4ce1e5e | 2011-03-10 03:50:54 -0700 | [diff] [blame] | 220 | |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 221 | /* |
Kevin Hilman | 219c5b9 | 2009-04-23 21:11:08 -0600 | [diff] [blame] | 222 | * Enable wake-up on OMAP2 CPUs. |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 223 | */ |
Kevin Hilman | 219c5b9 | 2009-04-23 21:11:08 -0600 | [diff] [blame] | 224 | if (cpu_class_is_omap2()) |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 225 | wakeup = 1; |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 226 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 227 | __omap_dm_timer_reset(timer, autoidle, wakeup); |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 228 | timer->posted = 1; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 231 | void omap_dm_timer_prepare(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 232 | { |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 233 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 234 | omap_dm_timer_reset(timer); |
| 235 | } |
| 236 | |
| 237 | struct omap_dm_timer *omap_dm_timer_request(void) |
| 238 | { |
| 239 | struct omap_dm_timer *timer = NULL; |
| 240 | unsigned long flags; |
| 241 | int i; |
| 242 | |
| 243 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 244 | for (i = 0; i < dm_timer_count; i++) { |
| 245 | if (dm_timers[i].reserved) |
| 246 | continue; |
| 247 | |
| 248 | timer = &dm_timers[i]; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 249 | timer->reserved = 1; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 250 | break; |
| 251 | } |
| 252 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 253 | |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 254 | if (timer != NULL) |
| 255 | omap_dm_timer_prepare(timer); |
| 256 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 257 | return timer; |
| 258 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 259 | EXPORT_SYMBOL_GPL(omap_dm_timer_request); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 260 | |
| 261 | struct omap_dm_timer *omap_dm_timer_request_specific(int id) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 262 | { |
| 263 | struct omap_dm_timer *timer; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 264 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 265 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 266 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 267 | if (id <= 0 || id > dm_timer_count || dm_timers[id-1].reserved) { |
| 268 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 269 | 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] | 270 | __FILE__, __LINE__, __func__, id); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 271 | dump_stack(); |
| 272 | return NULL; |
| 273 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 274 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 275 | timer = &dm_timers[id-1]; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 276 | timer->reserved = 1; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 277 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 278 | |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 279 | omap_dm_timer_prepare(timer); |
| 280 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 281 | return timer; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 282 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 283 | EXPORT_SYMBOL_GPL(omap_dm_timer_request_specific); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 284 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 285 | void omap_dm_timer_free(struct omap_dm_timer *timer) |
| 286 | { |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 287 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 288 | omap_dm_timer_reset(timer); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 289 | omap_dm_timer_disable(timer); |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 290 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 291 | WARN_ON(!timer->reserved); |
| 292 | timer->reserved = 0; |
| 293 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 294 | EXPORT_SYMBOL_GPL(omap_dm_timer_free); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 295 | |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 296 | void omap_dm_timer_enable(struct omap_dm_timer *timer) |
| 297 | { |
| 298 | if (timer->enabled) |
| 299 | return; |
| 300 | |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 301 | #ifdef CONFIG_ARCH_OMAP2PLUS |
| 302 | if (cpu_class_is_omap2()) { |
| 303 | clk_enable(timer->fclk); |
| 304 | clk_enable(timer->iclk); |
| 305 | } |
| 306 | #endif |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 307 | |
| 308 | timer->enabled = 1; |
| 309 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 310 | EXPORT_SYMBOL_GPL(omap_dm_timer_enable); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 311 | |
| 312 | void omap_dm_timer_disable(struct omap_dm_timer *timer) |
| 313 | { |
| 314 | if (!timer->enabled) |
| 315 | return; |
| 316 | |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 317 | #ifdef CONFIG_ARCH_OMAP2PLUS |
| 318 | if (cpu_class_is_omap2()) { |
| 319 | clk_disable(timer->iclk); |
| 320 | clk_disable(timer->fclk); |
| 321 | } |
| 322 | #endif |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 323 | |
| 324 | timer->enabled = 0; |
| 325 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 326 | EXPORT_SYMBOL_GPL(omap_dm_timer_disable); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 327 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 328 | int omap_dm_timer_get_irq(struct omap_dm_timer *timer) |
| 329 | { |
| 330 | return timer->irq; |
| 331 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 332 | EXPORT_SYMBOL_GPL(omap_dm_timer_get_irq); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 333 | |
| 334 | #if defined(CONFIG_ARCH_OMAP1) |
| 335 | |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 336 | /** |
| 337 | * omap_dm_timer_modify_idlect_mask - Check if any running timers use ARMXOR |
| 338 | * @inputmask: current value of idlect mask |
| 339 | */ |
| 340 | __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask) |
| 341 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 342 | int i; |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 343 | |
| 344 | /* If ARMXOR cannot be idled this function call is unnecessary */ |
| 345 | if (!(inputmask & (1 << 1))) |
| 346 | return inputmask; |
| 347 | |
| 348 | /* If any active timer is using ARMXOR return modified mask */ |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 349 | for (i = 0; i < dm_timer_count; i++) { |
| 350 | u32 l; |
| 351 | |
Tony Lindgren | 35912c7 | 2006-07-01 19:56:42 +0100 | [diff] [blame] | 352 | 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] | 353 | if (l & OMAP_TIMER_CTRL_ST) { |
| 354 | if (((omap_readl(MOD_CONF_CTRL_1) >> (i * 2)) & 0x03) == 0) |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 355 | inputmask &= ~(1 << 1); |
| 356 | else |
| 357 | inputmask &= ~(1 << 2); |
| 358 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 359 | } |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 360 | |
| 361 | return inputmask; |
| 362 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 363 | EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask); |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 364 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 365 | #else |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 366 | |
| 367 | struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer) |
| 368 | { |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 369 | return timer->fclk; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 370 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 371 | EXPORT_SYMBOL_GPL(omap_dm_timer_get_fclk); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 372 | |
| 373 | __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask) |
| 374 | { |
| 375 | BUG(); |
Dirk Behme | 2121880 | 2006-12-06 17:14:00 -0800 | [diff] [blame] | 376 | |
| 377 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 378 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 379 | EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 380 | |
| 381 | #endif |
| 382 | |
| 383 | void omap_dm_timer_trigger(struct omap_dm_timer *timer) |
| 384 | { |
| 385 | omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0); |
| 386 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 387 | EXPORT_SYMBOL_GPL(omap_dm_timer_trigger); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 388 | |
| 389 | void omap_dm_timer_start(struct omap_dm_timer *timer) |
| 390 | { |
| 391 | u32 l; |
| 392 | |
| 393 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 394 | if (!(l & OMAP_TIMER_CTRL_ST)) { |
| 395 | l |= OMAP_TIMER_CTRL_ST; |
| 396 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 397 | } |
| 398 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 399 | EXPORT_SYMBOL_GPL(omap_dm_timer_start); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 400 | |
| 401 | void omap_dm_timer_stop(struct omap_dm_timer *timer) |
| 402 | { |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 403 | unsigned long rate = 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 404 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 405 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 406 | rate = clk_get_rate(timer->fclk); |
Tero Kristo | 5c3db36 | 2009-10-23 19:03:47 +0300 | [diff] [blame] | 407 | #endif |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 408 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 409 | __omap_dm_timer_stop(timer, timer->posted, rate); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 410 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 411 | EXPORT_SYMBOL_GPL(omap_dm_timer_stop); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 412 | |
| 413 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 414 | |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 415 | 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] | 416 | { |
| 417 | int n = (timer - dm_timers) << 1; |
| 418 | u32 l; |
| 419 | |
| 420 | l = omap_readl(MOD_CONF_CTRL_1) & ~(0x03 << n); |
| 421 | l |= source << n; |
| 422 | omap_writel(l, MOD_CONF_CTRL_1); |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 423 | |
| 424 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 425 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 426 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_source); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 427 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 428 | #else |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 429 | |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 430 | 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] | 431 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 432 | if (source < 0 || source >= 3) |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 433 | return -EINVAL; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 434 | |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 435 | return __omap_dm_timer_set_source(timer->fclk, |
| 436 | dm_source_clocks[source]); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 437 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 438 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_source); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 439 | |
| 440 | #endif |
| 441 | |
| 442 | void omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, |
| 443 | unsigned int load) |
| 444 | { |
| 445 | u32 l; |
| 446 | |
| 447 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 448 | if (autoreload) |
| 449 | l |= OMAP_TIMER_CTRL_AR; |
| 450 | else |
| 451 | l &= ~OMAP_TIMER_CTRL_AR; |
| 452 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 453 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load); |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 454 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 455 | omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0); |
| 456 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 457 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_load); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 458 | |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 459 | /* Optimized set_load which removes costly spin wait in timer_start */ |
| 460 | void omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload, |
| 461 | unsigned int load) |
| 462 | { |
| 463 | u32 l; |
| 464 | |
| 465 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 466 | if (autoreload) { |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 467 | l |= OMAP_TIMER_CTRL_AR; |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 468 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load); |
| 469 | } else { |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 470 | l &= ~OMAP_TIMER_CTRL_AR; |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 471 | } |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 472 | l |= OMAP_TIMER_CTRL_ST; |
| 473 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 474 | __omap_dm_timer_load_start(timer, l, load, timer->posted); |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 475 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 476 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_load_start); |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 477 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 478 | void omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable, |
| 479 | unsigned int match) |
| 480 | { |
| 481 | u32 l; |
| 482 | |
| 483 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 484 | if (enable) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 485 | l |= OMAP_TIMER_CTRL_CE; |
| 486 | else |
| 487 | l &= ~OMAP_TIMER_CTRL_CE; |
| 488 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 489 | omap_dm_timer_write_reg(timer, OMAP_TIMER_MATCH_REG, match); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 490 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 491 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_match); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 492 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 493 | void omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on, |
| 494 | int toggle, int trigger) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 495 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 496 | u32 l; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 497 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 498 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 499 | l &= ~(OMAP_TIMER_CTRL_GPOCFG | OMAP_TIMER_CTRL_SCPWM | |
| 500 | OMAP_TIMER_CTRL_PT | (0x03 << 10)); |
| 501 | if (def_on) |
| 502 | l |= OMAP_TIMER_CTRL_SCPWM; |
| 503 | if (toggle) |
| 504 | l |= OMAP_TIMER_CTRL_PT; |
| 505 | l |= trigger << 10; |
| 506 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 507 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 508 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_pwm); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 509 | |
| 510 | void omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler) |
| 511 | { |
| 512 | u32 l; |
| 513 | |
| 514 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 515 | l &= ~(OMAP_TIMER_CTRL_PRE | (0x07 << 2)); |
| 516 | if (prescaler >= 0x00 && prescaler <= 0x07) { |
| 517 | l |= OMAP_TIMER_CTRL_PRE; |
| 518 | l |= prescaler << 2; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 519 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 520 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 521 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 522 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_prescaler); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 523 | |
| 524 | void omap_dm_timer_set_int_enable(struct omap_dm_timer *timer, |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 525 | unsigned int value) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 526 | { |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 527 | __omap_dm_timer_int_enable(timer, value); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 528 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 529 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_int_enable); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 530 | |
| 531 | unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer) |
| 532 | { |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 533 | unsigned int l; |
| 534 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 535 | l = __raw_readl(timer->irq_stat); |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 536 | |
| 537 | return l; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 538 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 539 | EXPORT_SYMBOL_GPL(omap_dm_timer_read_status); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 540 | |
| 541 | void omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value) |
| 542 | { |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 543 | __omap_dm_timer_write_status(timer, value); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 544 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 545 | EXPORT_SYMBOL_GPL(omap_dm_timer_write_status); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 546 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 547 | unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer) |
| 548 | { |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 549 | return __omap_dm_timer_read_counter(timer, timer->posted); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 550 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 551 | EXPORT_SYMBOL_GPL(omap_dm_timer_read_counter); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 552 | |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 553 | void omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value) |
| 554 | { |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 555 | omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, value); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 556 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 557 | EXPORT_SYMBOL_GPL(omap_dm_timer_write_counter); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 558 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 559 | int omap_dm_timers_active(void) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 560 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 561 | int i; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 562 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 563 | for (i = 0; i < dm_timer_count; i++) { |
| 564 | struct omap_dm_timer *timer; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 565 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 566 | timer = &dm_timers[i]; |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 567 | |
| 568 | if (!timer->enabled) |
| 569 | continue; |
| 570 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 571 | if (omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG) & |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 572 | OMAP_TIMER_CTRL_ST) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 573 | return 1; |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 574 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 575 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 576 | return 0; |
| 577 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 578 | EXPORT_SYMBOL_GPL(omap_dm_timers_active); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 579 | |
Tony Lindgren | 11a0186 | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 580 | static int __init omap_dm_timer_init(void) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 581 | { |
| 582 | struct omap_dm_timer *timer; |
Tony Lindgren | 3566fc6 | 2009-10-19 15:25:18 -0700 | [diff] [blame] | 583 | 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] | 584 | |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 585 | if (!(cpu_is_omap16xx() || cpu_class_is_omap2())) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 586 | return -ENODEV; |
| 587 | |
| 588 | spin_lock_init(&dm_timer_lock); |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 589 | |
Tony Lindgren | 3566fc6 | 2009-10-19 15:25:18 -0700 | [diff] [blame] | 590 | if (cpu_class_is_omap1()) { |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 591 | dm_timers = omap1_dm_timers; |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 592 | dm_timer_count = omap1_dm_timer_count; |
Tony Lindgren | 3566fc6 | 2009-10-19 15:25:18 -0700 | [diff] [blame] | 593 | map_size = SZ_2K; |
| 594 | } else if (cpu_is_omap24xx()) { |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 595 | dm_timers = omap2_dm_timers; |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 596 | dm_timer_count = omap2_dm_timer_count; |
Santosh Shilimkar | aea2a5b | 2009-05-25 11:08:36 -0700 | [diff] [blame] | 597 | dm_source_names = omap2_dm_source_names; |
| 598 | dm_source_clocks = omap2_dm_source_clocks; |
Syed Mohammed, Khasim | ce2df9c | 2007-06-25 22:55:39 -0700 | [diff] [blame] | 599 | } else if (cpu_is_omap34xx()) { |
| 600 | dm_timers = omap3_dm_timers; |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 601 | dm_timer_count = omap3_dm_timer_count; |
Santosh Shilimkar | aea2a5b | 2009-05-25 11:08:36 -0700 | [diff] [blame] | 602 | dm_source_names = omap3_dm_source_names; |
| 603 | dm_source_clocks = omap3_dm_source_clocks; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 604 | } else if (cpu_is_omap44xx()) { |
| 605 | dm_timers = omap4_dm_timers; |
Tony Lindgren | 882c051 | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 606 | dm_timer_count = omap4_dm_timer_count; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 607 | dm_source_names = omap4_dm_source_names; |
| 608 | dm_source_clocks = omap4_dm_source_clocks; |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 609 | |
| 610 | pr_err("dmtimers disabled for omap4 until hwmod conversion\n"); |
| 611 | return -ENODEV; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 612 | } |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 613 | |
| 614 | if (cpu_class_is_omap2()) |
| 615 | for (i = 0; dm_source_names[i] != NULL; i++) |
| 616 | dm_source_clocks[i] = clk_get(NULL, dm_source_names[i]); |
| 617 | |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 618 | if (cpu_is_omap243x()) |
| 619 | dm_timers[0].phys_base = 0x49018000; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 620 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 621 | for (i = 0; i < dm_timer_count; i++) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 622 | timer = &dm_timers[i]; |
Tony Lindgren | 3566fc6 | 2009-10-19 15:25:18 -0700 | [diff] [blame] | 623 | |
| 624 | /* Static mapping, never released */ |
| 625 | timer->io_base = ioremap(timer->phys_base, map_size); |
| 626 | BUG_ON(!timer->io_base); |
| 627 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 628 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Syed Mohammed, Khasim | 471b3aa | 2007-06-21 21:48:07 -0700 | [diff] [blame] | 629 | if (cpu_class_is_omap2()) { |
| 630 | char clk_name[16]; |
| 631 | sprintf(clk_name, "gpt%d_ick", i + 1); |
| 632 | timer->iclk = clk_get(NULL, clk_name); |
| 633 | sprintf(clk_name, "gpt%d_fck", i + 1); |
| 634 | timer->fclk = clk_get(NULL, clk_name); |
| 635 | } |
Tony Lindgren | 11a0186 | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 636 | |
| 637 | /* One or two timers may be set up early for sys_timer */ |
| 638 | if (sys_timer_reserved & (1 << i)) { |
| 639 | timer->reserved = 1; |
| 640 | timer->posted = 1; |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 641 | continue; |
Tony Lindgren | 11a0186 | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 642 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 643 | #endif |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame^] | 644 | omap_dm_timer_enable(timer); |
| 645 | __omap_dm_timer_init_regs(timer); |
| 646 | omap_dm_timer_disable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | return 0; |
| 650 | } |
Tony Lindgren | 11a0186 | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 651 | |
| 652 | arch_initcall(omap_dm_timer_init); |