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 | * |
Tarun Kanti DebBarma | 97933d6 | 2011-09-20 17:00:17 +0530 | [diff] [blame] | 6 | * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ |
| 7 | * Tarun Kanti DebBarma <tarun.kanti@ti.com> |
| 8 | * Thara Gopinath <thara@ti.com> |
| 9 | * |
| 10 | * dmtimer adaptation to platform_driver. |
| 11 | * |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 12 | * Copyright (C) 2005 Nokia Corporation |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 13 | * OMAP2 support by Juha Yrjola |
| 14 | * API improvements and OMAP2 clock framework support by Timo Teras |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 15 | * |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 16 | * Copyright (C) 2009 Texas Instruments |
| 17 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com> |
| 18 | * |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 19 | * This program is free software; you can redistribute it and/or modify it |
| 20 | * under the terms of the GNU General Public License as published by the |
| 21 | * Free Software Foundation; either version 2 of the License, or (at your |
| 22 | * option) any later version. |
| 23 | * |
| 24 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 25 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
| 27 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 29 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | * |
| 33 | * You should have received a copy of the GNU General Public License along |
| 34 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 35 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 36 | */ |
| 37 | |
Axel Lin | 869dec1 | 2011-11-02 09:49:46 +0800 | [diff] [blame] | 38 | #include <linux/module.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 39 | #include <linux/io.h> |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 40 | #include <linux/slab.h> |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 41 | #include <linux/err.h> |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 42 | #include <linux/pm_runtime.h> |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 43 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 44 | #include <plat/dmtimer.h> |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 45 | |
Tony Lindgren | 2c799ce | 2012-02-24 10:34:35 -0800 | [diff] [blame] | 46 | #include <mach/hardware.h> |
| 47 | |
Jon Hunter | b7b4ff7 | 2012-06-05 12:34:51 -0500 | [diff] [blame^] | 48 | static u32 omap_reserved_systimers; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 49 | static LIST_HEAD(omap_timer_list); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 50 | static DEFINE_SPINLOCK(dm_timer_lock); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 51 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 52 | /** |
| 53 | * omap_dm_timer_read_reg - read timer registers in posted and non-posted mode |
| 54 | * @timer: timer pointer over which read operation to perform |
| 55 | * @reg: lowest byte holds the register offset |
| 56 | * |
| 57 | * The posted mode bit is encoded in reg. Note that in posted mode write |
| 58 | * pending bit must be checked. Otherwise a read of a non completed write |
| 59 | * will produce an error. |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 60 | */ |
| 61 | 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] | 62 | { |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 63 | WARN_ON((reg & 0xff) < _OMAP_TIMER_WAKEUP_EN_OFFSET); |
| 64 | return __omap_dm_timer_read(timer, reg, timer->posted); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 67 | /** |
| 68 | * omap_dm_timer_write_reg - write timer registers in posted and non-posted mode |
| 69 | * @timer: timer pointer over which write operation is to perform |
| 70 | * @reg: lowest byte holds the register offset |
| 71 | * @value: data to write into the register |
| 72 | * |
| 73 | * The posted mode bit is encoded in reg. Note that in posted mode the write |
| 74 | * pending bit must be checked. Otherwise a write on a register which has a |
| 75 | * pending write will be lost. |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 76 | */ |
| 77 | static void omap_dm_timer_write_reg(struct omap_dm_timer *timer, u32 reg, |
| 78 | u32 value) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 79 | { |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 80 | WARN_ON((reg & 0xff) < _OMAP_TIMER_WAKEUP_EN_OFFSET); |
| 81 | __omap_dm_timer_write(timer, reg, value, timer->posted); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 84 | static void omap_timer_restore_context(struct omap_dm_timer *timer) |
| 85 | { |
Tarun Kanti DebBarma | dffc9da | 2012-03-05 16:11:00 -0800 | [diff] [blame] | 86 | if (timer->revision == 1) |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 87 | __raw_writel(timer->context.tistat, timer->sys_stat); |
| 88 | |
| 89 | __raw_writel(timer->context.tisr, timer->irq_stat); |
| 90 | omap_dm_timer_write_reg(timer, OMAP_TIMER_WAKEUP_EN_REG, |
| 91 | timer->context.twer); |
| 92 | omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, |
| 93 | timer->context.tcrr); |
| 94 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, |
| 95 | timer->context.tldr); |
| 96 | omap_dm_timer_write_reg(timer, OMAP_TIMER_MATCH_REG, |
| 97 | timer->context.tmar); |
| 98 | omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, |
| 99 | timer->context.tsicr); |
| 100 | __raw_writel(timer->context.tier, timer->irq_ena); |
| 101 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, |
| 102 | timer->context.tclr); |
| 103 | } |
| 104 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 105 | 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] | 106 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 107 | int c; |
| 108 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 109 | if (!timer->sys_stat) |
| 110 | return; |
| 111 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 112 | c = 0; |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 113 | while (!(__raw_readl(timer->sys_stat) & 1)) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 114 | c++; |
| 115 | if (c > 100000) { |
| 116 | printk(KERN_ERR "Timer failed to reset\n"); |
| 117 | return; |
| 118 | } |
| 119 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 122 | static void omap_dm_timer_reset(struct omap_dm_timer *timer) |
| 123 | { |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 124 | omap_dm_timer_enable(timer); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 125 | if (timer->pdev->id != 1) { |
Timo Teras | e32f7ec | 2006-06-26 16:16:13 -0700 | [diff] [blame] | 126 | omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, 0x06); |
| 127 | omap_dm_timer_wait_for_reset(timer); |
| 128 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 129 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 130 | __omap_dm_timer_reset(timer, 0, 0); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 131 | omap_dm_timer_disable(timer); |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 132 | timer->posted = 1; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 135 | int omap_dm_timer_prepare(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 136 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 137 | struct dmtimer_platform_data *pdata = timer->pdev->dev.platform_data; |
| 138 | int ret; |
| 139 | |
| 140 | timer->fclk = clk_get(&timer->pdev->dev, "fck"); |
| 141 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(timer->fclk))) { |
| 142 | timer->fclk = NULL; |
| 143 | dev_err(&timer->pdev->dev, ": No fclk handle.\n"); |
| 144 | return -EINVAL; |
| 145 | } |
| 146 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 147 | if (pdata->needs_manual_reset) |
| 148 | omap_dm_timer_reset(timer); |
| 149 | |
| 150 | ret = omap_dm_timer_set_source(timer, OMAP_TIMER_SRC_32_KHZ); |
| 151 | |
| 152 | timer->posted = 1; |
| 153 | return ret; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Jon Hunter | b7b4ff7 | 2012-06-05 12:34:51 -0500 | [diff] [blame^] | 156 | static inline u32 omap_dm_timer_reserved_systimer(int id) |
| 157 | { |
| 158 | return (omap_reserved_systimers & (1 << (id - 1))) ? 1 : 0; |
| 159 | } |
| 160 | |
| 161 | int omap_dm_timer_reserve_systimer(int id) |
| 162 | { |
| 163 | if (omap_dm_timer_reserved_systimer(id)) |
| 164 | return -ENODEV; |
| 165 | |
| 166 | omap_reserved_systimers |= (1 << (id - 1)); |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 171 | struct omap_dm_timer *omap_dm_timer_request(void) |
| 172 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 173 | struct omap_dm_timer *timer = NULL, *t; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 174 | unsigned long flags; |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 175 | int ret = 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 176 | |
| 177 | spin_lock_irqsave(&dm_timer_lock, flags); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 178 | list_for_each_entry(t, &omap_timer_list, node) { |
| 179 | if (t->reserved) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 180 | continue; |
| 181 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 182 | timer = t; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 183 | timer->reserved = 1; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 184 | break; |
| 185 | } |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 186 | |
| 187 | if (timer) { |
| 188 | ret = omap_dm_timer_prepare(timer); |
| 189 | if (ret) { |
| 190 | timer->reserved = 0; |
| 191 | timer = NULL; |
| 192 | } |
| 193 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 194 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 195 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 196 | if (!timer) |
| 197 | pr_debug("%s: timer request failed!\n", __func__); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 198 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 199 | return timer; |
| 200 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 201 | EXPORT_SYMBOL_GPL(omap_dm_timer_request); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 202 | |
| 203 | struct omap_dm_timer *omap_dm_timer_request_specific(int id) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 204 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 205 | struct omap_dm_timer *timer = NULL, *t; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 206 | unsigned long flags; |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 207 | int ret = 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 208 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 209 | spin_lock_irqsave(&dm_timer_lock, flags); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 210 | list_for_each_entry(t, &omap_timer_list, node) { |
| 211 | if (t->pdev->id == id && !t->reserved) { |
| 212 | timer = t; |
| 213 | timer->reserved = 1; |
| 214 | break; |
| 215 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 216 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 217 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 218 | if (timer) { |
| 219 | ret = omap_dm_timer_prepare(timer); |
| 220 | if (ret) { |
| 221 | timer->reserved = 0; |
| 222 | timer = NULL; |
| 223 | } |
| 224 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 225 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 226 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 227 | if (!timer) |
| 228 | pr_debug("%s: timer%d request failed!\n", __func__, id); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 229 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 230 | return timer; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 231 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 232 | EXPORT_SYMBOL_GPL(omap_dm_timer_request_specific); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 233 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 234 | int omap_dm_timer_free(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 235 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 236 | if (unlikely(!timer)) |
| 237 | return -EINVAL; |
| 238 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 239 | clk_put(timer->fclk); |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 240 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 241 | WARN_ON(!timer->reserved); |
| 242 | timer->reserved = 0; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 243 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 244 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 245 | EXPORT_SYMBOL_GPL(omap_dm_timer_free); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 246 | |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 247 | void omap_dm_timer_enable(struct omap_dm_timer *timer) |
| 248 | { |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 249 | pm_runtime_get_sync(&timer->pdev->dev); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 250 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 251 | EXPORT_SYMBOL_GPL(omap_dm_timer_enable); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 252 | |
| 253 | void omap_dm_timer_disable(struct omap_dm_timer *timer) |
| 254 | { |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 255 | pm_runtime_put(&timer->pdev->dev); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 256 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 257 | EXPORT_SYMBOL_GPL(omap_dm_timer_disable); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 258 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 259 | int omap_dm_timer_get_irq(struct omap_dm_timer *timer) |
| 260 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 261 | if (timer) |
| 262 | return timer->irq; |
| 263 | return -EINVAL; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 264 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 265 | EXPORT_SYMBOL_GPL(omap_dm_timer_get_irq); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 266 | |
| 267 | #if defined(CONFIG_ARCH_OMAP1) |
| 268 | |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 269 | /** |
| 270 | * omap_dm_timer_modify_idlect_mask - Check if any running timers use ARMXOR |
| 271 | * @inputmask: current value of idlect mask |
| 272 | */ |
| 273 | __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask) |
| 274 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 275 | int i = 0; |
| 276 | struct omap_dm_timer *timer = NULL; |
| 277 | unsigned long flags; |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 278 | |
| 279 | /* If ARMXOR cannot be idled this function call is unnecessary */ |
| 280 | if (!(inputmask & (1 << 1))) |
| 281 | return inputmask; |
| 282 | |
| 283 | /* If any active timer is using ARMXOR return modified mask */ |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 284 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 285 | list_for_each_entry(timer, &omap_timer_list, node) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 286 | u32 l; |
| 287 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 288 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 289 | if (l & OMAP_TIMER_CTRL_ST) { |
| 290 | if (((omap_readl(MOD_CONF_CTRL_1) >> (i * 2)) & 0x03) == 0) |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 291 | inputmask &= ~(1 << 1); |
| 292 | else |
| 293 | inputmask &= ~(1 << 2); |
| 294 | } |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 295 | i++; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 296 | } |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 297 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 298 | |
| 299 | return inputmask; |
| 300 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 301 | EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask); |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 302 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 303 | #else |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 304 | |
| 305 | struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer) |
| 306 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 307 | if (timer) |
| 308 | return timer->fclk; |
| 309 | return NULL; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 310 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 311 | EXPORT_SYMBOL_GPL(omap_dm_timer_get_fclk); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 312 | |
| 313 | __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask) |
| 314 | { |
| 315 | BUG(); |
Dirk Behme | 2121880 | 2006-12-06 17:14:00 -0800 | [diff] [blame] | 316 | |
| 317 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 318 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 319 | EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 320 | |
| 321 | #endif |
| 322 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 323 | int omap_dm_timer_trigger(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 324 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 325 | if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) { |
| 326 | pr_err("%s: timer not available or enabled.\n", __func__); |
| 327 | return -EINVAL; |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 328 | } |
| 329 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 330 | omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 331 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 332 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 333 | EXPORT_SYMBOL_GPL(omap_dm_timer_trigger); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 334 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 335 | int omap_dm_timer_start(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 336 | { |
| 337 | u32 l; |
| 338 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 339 | if (unlikely(!timer)) |
| 340 | return -EINVAL; |
| 341 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 342 | omap_dm_timer_enable(timer); |
| 343 | |
| 344 | if (timer->loses_context) { |
| 345 | u32 ctx_loss_cnt_after = |
| 346 | timer->get_context_loss_count(&timer->pdev->dev); |
| 347 | if (ctx_loss_cnt_after != timer->ctx_loss_count) |
| 348 | omap_timer_restore_context(timer); |
| 349 | } |
| 350 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 351 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 352 | if (!(l & OMAP_TIMER_CTRL_ST)) { |
| 353 | l |= OMAP_TIMER_CTRL_ST; |
| 354 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 355 | } |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 356 | |
| 357 | /* Save the context */ |
| 358 | timer->context.tclr = l; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 359 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 360 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 361 | EXPORT_SYMBOL_GPL(omap_dm_timer_start); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 362 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 363 | int omap_dm_timer_stop(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 364 | { |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 365 | unsigned long rate = 0; |
Paul Walmsley | eeb3711 | 2012-04-13 06:34:32 -0600 | [diff] [blame] | 366 | struct dmtimer_platform_data *pdata; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 367 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 368 | if (unlikely(!timer)) |
| 369 | return -EINVAL; |
| 370 | |
Paul Walmsley | eeb3711 | 2012-04-13 06:34:32 -0600 | [diff] [blame] | 371 | pdata = timer->pdev->dev.platform_data; |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 372 | if (!pdata->needs_manual_reset) |
| 373 | rate = clk_get_rate(timer->fclk); |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 374 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 375 | __omap_dm_timer_stop(timer, timer->posted, rate); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 376 | |
Tarun Kanti DebBarma | dffc9da | 2012-03-05 16:11:00 -0800 | [diff] [blame] | 377 | if (timer->loses_context && timer->get_context_loss_count) |
| 378 | timer->ctx_loss_count = |
| 379 | timer->get_context_loss_count(&timer->pdev->dev); |
| 380 | |
| 381 | /* |
| 382 | * Since the register values are computed and written within |
| 383 | * __omap_dm_timer_stop, we need to use read to retrieve the |
| 384 | * context. |
| 385 | */ |
| 386 | timer->context.tclr = |
| 387 | omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 388 | timer->context.tisr = __raw_readl(timer->irq_stat); |
| 389 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 390 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 391 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 392 | EXPORT_SYMBOL_GPL(omap_dm_timer_stop); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 393 | |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 394 | 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] | 395 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 396 | int ret; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 397 | struct dmtimer_platform_data *pdata; |
| 398 | |
| 399 | if (unlikely(!timer)) |
| 400 | return -EINVAL; |
| 401 | |
| 402 | pdata = timer->pdev->dev.platform_data; |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 403 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 404 | if (source < 0 || source >= 3) |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 405 | return -EINVAL; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 406 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 407 | ret = pdata->set_timer_src(timer->pdev, source); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 408 | |
| 409 | return ret; |
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_set_source); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 412 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 413 | int omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 414 | unsigned int load) |
| 415 | { |
| 416 | u32 l; |
| 417 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 418 | if (unlikely(!timer)) |
| 419 | return -EINVAL; |
| 420 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 421 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 422 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 423 | if (autoreload) |
| 424 | l |= OMAP_TIMER_CTRL_AR; |
| 425 | else |
| 426 | l &= ~OMAP_TIMER_CTRL_AR; |
| 427 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 428 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load); |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 429 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 430 | omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 431 | /* Save the context */ |
| 432 | timer->context.tclr = l; |
| 433 | timer->context.tldr = load; |
| 434 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 435 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 436 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 437 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_load); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 438 | |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 439 | /* Optimized set_load which removes costly spin wait in timer_start */ |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 440 | int omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload, |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 441 | unsigned int load) |
| 442 | { |
| 443 | u32 l; |
| 444 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 445 | if (unlikely(!timer)) |
| 446 | return -EINVAL; |
| 447 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 448 | omap_dm_timer_enable(timer); |
| 449 | |
| 450 | if (timer->loses_context) { |
| 451 | u32 ctx_loss_cnt_after = |
| 452 | timer->get_context_loss_count(&timer->pdev->dev); |
| 453 | if (ctx_loss_cnt_after != timer->ctx_loss_count) |
| 454 | omap_timer_restore_context(timer); |
| 455 | } |
| 456 | |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 457 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 458 | if (autoreload) { |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 459 | l |= OMAP_TIMER_CTRL_AR; |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 460 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load); |
| 461 | } else { |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 462 | l &= ~OMAP_TIMER_CTRL_AR; |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 463 | } |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 464 | l |= OMAP_TIMER_CTRL_ST; |
| 465 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 466 | __omap_dm_timer_load_start(timer, l, load, timer->posted); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 467 | |
| 468 | /* Save the context */ |
| 469 | timer->context.tclr = l; |
| 470 | timer->context.tldr = load; |
| 471 | timer->context.tcrr = load; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 472 | return 0; |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 473 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 474 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_load_start); |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 475 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 476 | int omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable, |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 477 | unsigned int match) |
| 478 | { |
| 479 | u32 l; |
| 480 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 481 | if (unlikely(!timer)) |
| 482 | return -EINVAL; |
| 483 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 484 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 485 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 486 | if (enable) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 487 | l |= OMAP_TIMER_CTRL_CE; |
| 488 | else |
| 489 | l &= ~OMAP_TIMER_CTRL_CE; |
| 490 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 491 | omap_dm_timer_write_reg(timer, OMAP_TIMER_MATCH_REG, match); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 492 | |
| 493 | /* Save the context */ |
| 494 | timer->context.tclr = l; |
| 495 | timer->context.tmar = match; |
| 496 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 497 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 498 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 499 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_match); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 500 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 501 | int omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on, |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 502 | int toggle, int trigger) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 503 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 504 | u32 l; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 505 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 506 | if (unlikely(!timer)) |
| 507 | return -EINVAL; |
| 508 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 509 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 510 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 511 | l &= ~(OMAP_TIMER_CTRL_GPOCFG | OMAP_TIMER_CTRL_SCPWM | |
| 512 | OMAP_TIMER_CTRL_PT | (0x03 << 10)); |
| 513 | if (def_on) |
| 514 | l |= OMAP_TIMER_CTRL_SCPWM; |
| 515 | if (toggle) |
| 516 | l |= OMAP_TIMER_CTRL_PT; |
| 517 | l |= trigger << 10; |
| 518 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 519 | |
| 520 | /* Save the context */ |
| 521 | timer->context.tclr = l; |
| 522 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 523 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 524 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 525 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_pwm); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 526 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 527 | int omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 528 | { |
| 529 | u32 l; |
| 530 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 531 | if (unlikely(!timer)) |
| 532 | return -EINVAL; |
| 533 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 534 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 535 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 536 | l &= ~(OMAP_TIMER_CTRL_PRE | (0x07 << 2)); |
| 537 | if (prescaler >= 0x00 && prescaler <= 0x07) { |
| 538 | l |= OMAP_TIMER_CTRL_PRE; |
| 539 | l |= prescaler << 2; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 540 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 541 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 542 | |
| 543 | /* Save the context */ |
| 544 | timer->context.tclr = l; |
| 545 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 546 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 547 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 548 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_prescaler); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 549 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 550 | int omap_dm_timer_set_int_enable(struct omap_dm_timer *timer, |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 551 | unsigned int value) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 552 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 553 | if (unlikely(!timer)) |
| 554 | return -EINVAL; |
| 555 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 556 | omap_dm_timer_enable(timer); |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 557 | __omap_dm_timer_int_enable(timer, value); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 558 | |
| 559 | /* Save the context */ |
| 560 | timer->context.tier = value; |
| 561 | timer->context.twer = value; |
| 562 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 563 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 564 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 565 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_int_enable); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 566 | |
| 567 | unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer) |
| 568 | { |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 569 | unsigned int l; |
| 570 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 571 | if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) { |
| 572 | pr_err("%s: timer not available or enabled.\n", __func__); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 573 | return 0; |
| 574 | } |
| 575 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 576 | l = __raw_readl(timer->irq_stat); |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 577 | |
| 578 | return l; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 579 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 580 | EXPORT_SYMBOL_GPL(omap_dm_timer_read_status); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 581 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 582 | int omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 583 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 584 | if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) |
| 585 | return -EINVAL; |
| 586 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 587 | __omap_dm_timer_write_status(timer, value); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 588 | /* Save the context */ |
| 589 | timer->context.tisr = value; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 590 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 591 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 592 | EXPORT_SYMBOL_GPL(omap_dm_timer_write_status); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 593 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 594 | unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer) |
| 595 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 596 | if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) { |
| 597 | pr_err("%s: timer not iavailable or enabled.\n", __func__); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 598 | return 0; |
| 599 | } |
| 600 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 601 | return __omap_dm_timer_read_counter(timer, timer->posted); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 602 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 603 | EXPORT_SYMBOL_GPL(omap_dm_timer_read_counter); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 604 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 605 | int omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value) |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 606 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 607 | if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) { |
| 608 | pr_err("%s: timer not available or enabled.\n", __func__); |
| 609 | return -EINVAL; |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 610 | } |
| 611 | |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 612 | omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, value); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 613 | |
| 614 | /* Save the context */ |
| 615 | timer->context.tcrr = value; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 616 | return 0; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 617 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 618 | EXPORT_SYMBOL_GPL(omap_dm_timer_write_counter); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 619 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 620 | int omap_dm_timers_active(void) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 621 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 622 | struct omap_dm_timer *timer; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 623 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 624 | list_for_each_entry(timer, &omap_timer_list, node) { |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 625 | if (!timer->reserved) |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 626 | continue; |
| 627 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 628 | if (omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG) & |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 629 | OMAP_TIMER_CTRL_ST) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 630 | return 1; |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 631 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 632 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 633 | return 0; |
| 634 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 635 | EXPORT_SYMBOL_GPL(omap_dm_timers_active); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 636 | |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 637 | /** |
| 638 | * omap_dm_timer_probe - probe function called for every registered device |
| 639 | * @pdev: pointer to current timer platform device |
| 640 | * |
| 641 | * Called by driver framework at the end of device registration for all |
| 642 | * timer devices. |
| 643 | */ |
| 644 | static int __devinit omap_dm_timer_probe(struct platform_device *pdev) |
| 645 | { |
| 646 | int ret; |
| 647 | unsigned long flags; |
| 648 | struct omap_dm_timer *timer; |
| 649 | struct resource *mem, *irq, *ioarea; |
| 650 | struct dmtimer_platform_data *pdata = pdev->dev.platform_data; |
| 651 | |
| 652 | if (!pdata) { |
| 653 | dev_err(&pdev->dev, "%s: no platform data.\n", __func__); |
| 654 | return -ENODEV; |
| 655 | } |
| 656 | |
| 657 | irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 658 | if (unlikely(!irq)) { |
| 659 | dev_err(&pdev->dev, "%s: no IRQ resource.\n", __func__); |
| 660 | return -ENODEV; |
| 661 | } |
| 662 | |
| 663 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 664 | if (unlikely(!mem)) { |
| 665 | dev_err(&pdev->dev, "%s: no memory resource.\n", __func__); |
| 666 | return -ENODEV; |
| 667 | } |
| 668 | |
| 669 | ioarea = request_mem_region(mem->start, resource_size(mem), |
| 670 | pdev->name); |
| 671 | if (!ioarea) { |
| 672 | dev_err(&pdev->dev, "%s: region already claimed.\n", __func__); |
| 673 | return -EBUSY; |
| 674 | } |
| 675 | |
| 676 | timer = kzalloc(sizeof(struct omap_dm_timer), GFP_KERNEL); |
| 677 | if (!timer) { |
| 678 | dev_err(&pdev->dev, "%s: no memory for omap_dm_timer.\n", |
| 679 | __func__); |
| 680 | ret = -ENOMEM; |
| 681 | goto err_free_ioregion; |
| 682 | } |
| 683 | |
| 684 | timer->io_base = ioremap(mem->start, resource_size(mem)); |
| 685 | if (!timer->io_base) { |
| 686 | dev_err(&pdev->dev, "%s: ioremap failed.\n", __func__); |
| 687 | ret = -ENOMEM; |
| 688 | goto err_free_mem; |
| 689 | } |
| 690 | |
| 691 | timer->id = pdev->id; |
| 692 | timer->irq = irq->start; |
Jon Hunter | b7b4ff7 | 2012-06-05 12:34:51 -0500 | [diff] [blame^] | 693 | timer->reserved = omap_dm_timer_reserved_systimer(timer->id); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 694 | timer->pdev = pdev; |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 695 | timer->loses_context = pdata->loses_context; |
| 696 | timer->get_context_loss_count = pdata->get_context_loss_count; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 697 | |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 698 | /* Skip pm_runtime_enable for OMAP1 */ |
| 699 | if (!pdata->needs_manual_reset) { |
| 700 | pm_runtime_enable(&pdev->dev); |
| 701 | pm_runtime_irq_safe(&pdev->dev); |
| 702 | } |
| 703 | |
Tony Lindgren | 0dad9fa | 2011-09-21 16:38:51 -0700 | [diff] [blame] | 704 | if (!timer->reserved) { |
| 705 | pm_runtime_get_sync(&pdev->dev); |
| 706 | __omap_dm_timer_init_regs(timer); |
| 707 | pm_runtime_put(&pdev->dev); |
| 708 | } |
| 709 | |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 710 | /* add the timer element to the list */ |
| 711 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 712 | list_add_tail(&timer->node, &omap_timer_list); |
| 713 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 714 | |
| 715 | dev_dbg(&pdev->dev, "Device Probed.\n"); |
| 716 | |
| 717 | return 0; |
| 718 | |
| 719 | err_free_mem: |
| 720 | kfree(timer); |
| 721 | |
| 722 | err_free_ioregion: |
| 723 | release_mem_region(mem->start, resource_size(mem)); |
| 724 | |
| 725 | return ret; |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * omap_dm_timer_remove - cleanup a registered timer device |
| 730 | * @pdev: pointer to current timer platform device |
| 731 | * |
| 732 | * Called by driver framework whenever a timer device is unregistered. |
| 733 | * In addition to freeing platform resources it also deletes the timer |
| 734 | * entry from the local list. |
| 735 | */ |
| 736 | static int __devexit omap_dm_timer_remove(struct platform_device *pdev) |
| 737 | { |
| 738 | struct omap_dm_timer *timer; |
| 739 | unsigned long flags; |
| 740 | int ret = -EINVAL; |
| 741 | |
| 742 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 743 | list_for_each_entry(timer, &omap_timer_list, node) |
| 744 | if (timer->pdev->id == pdev->id) { |
| 745 | list_del(&timer->node); |
| 746 | kfree(timer); |
| 747 | ret = 0; |
| 748 | break; |
| 749 | } |
| 750 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 751 | |
| 752 | return ret; |
| 753 | } |
| 754 | |
| 755 | static struct platform_driver omap_dm_timer_driver = { |
| 756 | .probe = omap_dm_timer_probe, |
Arnd Bergmann | 4c23c8d | 2011-10-01 18:42:47 +0200 | [diff] [blame] | 757 | .remove = __devexit_p(omap_dm_timer_remove), |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 758 | .driver = { |
| 759 | .name = "omap_timer", |
| 760 | }, |
| 761 | }; |
| 762 | |
| 763 | static int __init omap_dm_timer_driver_init(void) |
| 764 | { |
| 765 | return platform_driver_register(&omap_dm_timer_driver); |
| 766 | } |
| 767 | |
| 768 | static void __exit omap_dm_timer_driver_exit(void) |
| 769 | { |
| 770 | platform_driver_unregister(&omap_dm_timer_driver); |
| 771 | } |
| 772 | |
| 773 | early_platform_init("earlytimer", &omap_dm_timer_driver); |
| 774 | module_init(omap_dm_timer_driver_init); |
| 775 | module_exit(omap_dm_timer_driver_exit); |
| 776 | |
| 777 | MODULE_DESCRIPTION("OMAP Dual-Mode Timer Driver"); |
| 778 | MODULE_LICENSE("GPL"); |
| 779 | MODULE_ALIAS("platform:" DRIVER_NAME); |
| 780 | MODULE_AUTHOR("Texas Instruments Inc"); |