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 | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 40 | #include <linux/device.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> |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 43 | #include <linux/of.h> |
| 44 | #include <linux/of_device.h> |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 45 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 46 | #include <plat/dmtimer.h> |
Tony Lindgren | 2c799ce | 2012-02-24 10:34:35 -0800 | [diff] [blame] | 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 | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 86 | omap_dm_timer_write_reg(timer, OMAP_TIMER_WAKEUP_EN_REG, |
| 87 | timer->context.twer); |
| 88 | omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, |
| 89 | timer->context.tcrr); |
| 90 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, |
| 91 | timer->context.tldr); |
| 92 | omap_dm_timer_write_reg(timer, OMAP_TIMER_MATCH_REG, |
| 93 | timer->context.tmar); |
| 94 | omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, |
| 95 | timer->context.tsicr); |
| 96 | __raw_writel(timer->context.tier, timer->irq_ena); |
| 97 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, |
| 98 | timer->context.tclr); |
| 99 | } |
| 100 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 101 | 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] | 102 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 103 | int c; |
| 104 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 105 | if (!timer->sys_stat) |
| 106 | return; |
| 107 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 108 | c = 0; |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 109 | while (!(__raw_readl(timer->sys_stat) & 1)) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 110 | c++; |
| 111 | if (c > 100000) { |
| 112 | printk(KERN_ERR "Timer failed to reset\n"); |
| 113 | return; |
| 114 | } |
| 115 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 118 | static void omap_dm_timer_reset(struct omap_dm_timer *timer) |
| 119 | { |
Jon Hunter | ffc957b | 2012-07-06 16:46:35 -0500 | [diff] [blame] | 120 | omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, 0x06); |
| 121 | omap_dm_timer_wait_for_reset(timer); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 122 | __omap_dm_timer_reset(timer, 0, 0); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 125 | int omap_dm_timer_prepare(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 126 | { |
Jon Hunter | bca4580 | 2012-06-05 12:34:58 -0500 | [diff] [blame] | 127 | /* |
| 128 | * FIXME: OMAP1 devices do not use the clock framework for dmtimers so |
| 129 | * do not call clk_get() for these devices. |
| 130 | */ |
| 131 | if (!(timer->capability & OMAP_TIMER_NEEDS_RESET)) { |
| 132 | timer->fclk = clk_get(&timer->pdev->dev, "fck"); |
| 133 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(timer->fclk))) { |
| 134 | timer->fclk = NULL; |
| 135 | dev_err(&timer->pdev->dev, ": No fclk handle.\n"); |
| 136 | return -EINVAL; |
| 137 | } |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 138 | } |
| 139 | |
Jon Hunter | 7b44cf2 | 2012-07-06 16:45:04 -0500 | [diff] [blame] | 140 | omap_dm_timer_enable(timer); |
| 141 | |
Jon Hunter | 6615975 | 2012-06-05 12:34:57 -0500 | [diff] [blame] | 142 | if (timer->capability & OMAP_TIMER_NEEDS_RESET) |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 143 | omap_dm_timer_reset(timer); |
| 144 | |
Jon Hunter | 7b44cf2 | 2012-07-06 16:45:04 -0500 | [diff] [blame] | 145 | __omap_dm_timer_enable_posted(timer); |
| 146 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 147 | |
Jon Hunter | 7b44cf2 | 2012-07-06 16:45:04 -0500 | [diff] [blame] | 148 | return omap_dm_timer_set_source(timer, OMAP_TIMER_SRC_32_KHZ); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Jon Hunter | b7b4ff7 | 2012-06-05 12:34:51 -0500 | [diff] [blame] | 151 | static inline u32 omap_dm_timer_reserved_systimer(int id) |
| 152 | { |
| 153 | return (omap_reserved_systimers & (1 << (id - 1))) ? 1 : 0; |
| 154 | } |
| 155 | |
| 156 | int omap_dm_timer_reserve_systimer(int id) |
| 157 | { |
| 158 | if (omap_dm_timer_reserved_systimer(id)) |
| 159 | return -ENODEV; |
| 160 | |
| 161 | omap_reserved_systimers |= (1 << (id - 1)); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 166 | struct omap_dm_timer *omap_dm_timer_request(void) |
| 167 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 168 | struct omap_dm_timer *timer = NULL, *t; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 169 | unsigned long flags; |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 170 | int ret = 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 171 | |
| 172 | spin_lock_irqsave(&dm_timer_lock, flags); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 173 | list_for_each_entry(t, &omap_timer_list, node) { |
| 174 | if (t->reserved) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 175 | continue; |
| 176 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 177 | timer = t; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 178 | timer->reserved = 1; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 179 | break; |
| 180 | } |
Timo Kokkonen | c5491d1 | 2012-08-12 13:45:34 +0300 | [diff] [blame] | 181 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 182 | |
| 183 | if (timer) { |
| 184 | ret = omap_dm_timer_prepare(timer); |
| 185 | if (ret) { |
| 186 | timer->reserved = 0; |
| 187 | timer = NULL; |
| 188 | } |
| 189 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 190 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 191 | if (!timer) |
| 192 | pr_debug("%s: timer request failed!\n", __func__); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 193 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 194 | return timer; |
| 195 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 196 | EXPORT_SYMBOL_GPL(omap_dm_timer_request); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 197 | |
| 198 | struct omap_dm_timer *omap_dm_timer_request_specific(int id) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 199 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 200 | struct omap_dm_timer *timer = NULL, *t; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 201 | unsigned long flags; |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 202 | int ret = 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 203 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 204 | /* Requesting timer by ID is not supported when device tree is used */ |
| 205 | if (of_have_populated_dt()) { |
| 206 | pr_warn("%s: Please use omap_dm_timer_request_by_cap()\n", |
| 207 | __func__); |
| 208 | return NULL; |
| 209 | } |
| 210 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 211 | spin_lock_irqsave(&dm_timer_lock, flags); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 212 | list_for_each_entry(t, &omap_timer_list, node) { |
| 213 | if (t->pdev->id == id && !t->reserved) { |
| 214 | timer = t; |
| 215 | timer->reserved = 1; |
| 216 | break; |
| 217 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 218 | } |
Timo Kokkonen | c5491d1 | 2012-08-12 13:45:34 +0300 | [diff] [blame] | 219 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 220 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 221 | if (timer) { |
| 222 | ret = omap_dm_timer_prepare(timer); |
| 223 | if (ret) { |
| 224 | timer->reserved = 0; |
| 225 | timer = NULL; |
| 226 | } |
| 227 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 228 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 229 | if (!timer) |
| 230 | pr_debug("%s: timer%d request failed!\n", __func__, id); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 231 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 232 | return timer; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 233 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 234 | EXPORT_SYMBOL_GPL(omap_dm_timer_request_specific); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 235 | |
Jon Hunter | 373fe0b | 2012-09-06 15:28:00 -0500 | [diff] [blame] | 236 | /** |
| 237 | * omap_dm_timer_request_by_cap - Request a timer by capability |
| 238 | * @cap: Bit mask of capabilities to match |
| 239 | * |
| 240 | * Find a timer based upon capabilities bit mask. Callers of this function |
| 241 | * should use the definitions found in the plat/dmtimer.h file under the |
| 242 | * comment "timer capabilities used in hwmod database". Returns pointer to |
| 243 | * timer handle on success and a NULL pointer on failure. |
| 244 | */ |
| 245 | struct omap_dm_timer *omap_dm_timer_request_by_cap(u32 cap) |
| 246 | { |
| 247 | struct omap_dm_timer *timer = NULL, *t; |
| 248 | unsigned long flags; |
| 249 | |
| 250 | if (!cap) |
| 251 | return NULL; |
| 252 | |
| 253 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 254 | list_for_each_entry(t, &omap_timer_list, node) { |
| 255 | if ((!t->reserved) && ((t->capability & cap) == cap)) { |
| 256 | /* |
| 257 | * If timer is not NULL, we have already found one timer |
| 258 | * but it was not an exact match because it had more |
| 259 | * capabilites that what was required. Therefore, |
| 260 | * unreserve the last timer found and see if this one |
| 261 | * is a better match. |
| 262 | */ |
| 263 | if (timer) |
| 264 | timer->reserved = 0; |
| 265 | |
| 266 | timer = t; |
| 267 | timer->reserved = 1; |
| 268 | |
| 269 | /* Exit loop early if we find an exact match */ |
| 270 | if (t->capability == cap) |
| 271 | break; |
| 272 | } |
| 273 | } |
| 274 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 275 | |
| 276 | if (timer && omap_dm_timer_prepare(timer)) { |
| 277 | timer->reserved = 0; |
| 278 | timer = NULL; |
| 279 | } |
| 280 | |
| 281 | if (!timer) |
| 282 | pr_debug("%s: timer request failed!\n", __func__); |
| 283 | |
| 284 | return timer; |
| 285 | } |
| 286 | EXPORT_SYMBOL_GPL(omap_dm_timer_request_by_cap); |
| 287 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 288 | int omap_dm_timer_free(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 289 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 290 | if (unlikely(!timer)) |
| 291 | return -EINVAL; |
| 292 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 293 | clk_put(timer->fclk); |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 294 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 295 | WARN_ON(!timer->reserved); |
| 296 | timer->reserved = 0; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 297 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 298 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 299 | EXPORT_SYMBOL_GPL(omap_dm_timer_free); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 300 | |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 301 | void omap_dm_timer_enable(struct omap_dm_timer *timer) |
| 302 | { |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 303 | pm_runtime_get_sync(&timer->pdev->dev); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 304 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 305 | EXPORT_SYMBOL_GPL(omap_dm_timer_enable); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 306 | |
| 307 | void omap_dm_timer_disable(struct omap_dm_timer *timer) |
| 308 | { |
Jon Hunter | 54f32a3 | 2012-07-13 15:12:03 -0500 | [diff] [blame] | 309 | pm_runtime_put_sync(&timer->pdev->dev); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 310 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 311 | EXPORT_SYMBOL_GPL(omap_dm_timer_disable); |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 312 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 313 | int omap_dm_timer_get_irq(struct omap_dm_timer *timer) |
| 314 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 315 | if (timer) |
| 316 | return timer->irq; |
| 317 | return -EINVAL; |
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_get_irq); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 320 | |
| 321 | #if defined(CONFIG_ARCH_OMAP1) |
Tony Lindgren | 7136f8d | 2012-10-31 12:38:43 -0700 | [diff] [blame] | 322 | #include <mach/hardware.h> |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 323 | /** |
| 324 | * omap_dm_timer_modify_idlect_mask - Check if any running timers use ARMXOR |
| 325 | * @inputmask: current value of idlect mask |
| 326 | */ |
| 327 | __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask) |
| 328 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 329 | int i = 0; |
| 330 | struct omap_dm_timer *timer = NULL; |
| 331 | unsigned long flags; |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 332 | |
| 333 | /* If ARMXOR cannot be idled this function call is unnecessary */ |
| 334 | if (!(inputmask & (1 << 1))) |
| 335 | return inputmask; |
| 336 | |
| 337 | /* If any active timer is using ARMXOR return modified mask */ |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 338 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 339 | list_for_each_entry(timer, &omap_timer_list, node) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 340 | u32 l; |
| 341 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 342 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 343 | if (l & OMAP_TIMER_CTRL_ST) { |
| 344 | if (((omap_readl(MOD_CONF_CTRL_1) >> (i * 2)) & 0x03) == 0) |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 345 | inputmask &= ~(1 << 1); |
| 346 | else |
| 347 | inputmask &= ~(1 << 2); |
| 348 | } |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 349 | i++; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 350 | } |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 351 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 352 | |
| 353 | return inputmask; |
| 354 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 355 | EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask); |
Tony Lindgren | a569c6e | 2006-04-02 17:46:21 +0100 | [diff] [blame] | 356 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 357 | #else |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 358 | |
| 359 | struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer) |
| 360 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 361 | if (timer) |
| 362 | return timer->fclk; |
| 363 | return NULL; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 364 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 365 | EXPORT_SYMBOL_GPL(omap_dm_timer_get_fclk); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 366 | |
| 367 | __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask) |
| 368 | { |
| 369 | BUG(); |
Dirk Behme | 2121880 | 2006-12-06 17:14:00 -0800 | [diff] [blame] | 370 | |
| 371 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 372 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 373 | EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 374 | |
| 375 | #endif |
| 376 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 377 | int omap_dm_timer_trigger(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 378 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 379 | if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) { |
| 380 | pr_err("%s: timer not available or enabled.\n", __func__); |
| 381 | return -EINVAL; |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 382 | } |
| 383 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 384 | omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 385 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 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 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 389 | int omap_dm_timer_start(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 390 | { |
| 391 | u32 l; |
| 392 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 393 | if (unlikely(!timer)) |
| 394 | return -EINVAL; |
| 395 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 396 | omap_dm_timer_enable(timer); |
| 397 | |
Jon Hunter | 1c2d076 | 2012-06-05 12:34:55 -0500 | [diff] [blame] | 398 | if (!(timer->capability & OMAP_TIMER_ALWON)) { |
Tony Lindgren | 6e740f9 | 2012-10-29 15:20:45 -0700 | [diff] [blame] | 399 | if (timer->get_context_loss_count && |
| 400 | timer->get_context_loss_count(&timer->pdev->dev) != |
Jon Hunter | 0b30ec1 | 2012-06-05 12:34:56 -0500 | [diff] [blame] | 401 | timer->ctx_loss_count) |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 402 | omap_timer_restore_context(timer); |
| 403 | } |
| 404 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 405 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 406 | if (!(l & OMAP_TIMER_CTRL_ST)) { |
| 407 | l |= OMAP_TIMER_CTRL_ST; |
| 408 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 409 | } |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 410 | |
| 411 | /* Save the context */ |
| 412 | timer->context.tclr = l; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 413 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 414 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 415 | EXPORT_SYMBOL_GPL(omap_dm_timer_start); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 416 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 417 | int omap_dm_timer_stop(struct omap_dm_timer *timer) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 418 | { |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 419 | unsigned long rate = 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 420 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 421 | if (unlikely(!timer)) |
| 422 | return -EINVAL; |
| 423 | |
Jon Hunter | 6615975 | 2012-06-05 12:34:57 -0500 | [diff] [blame] | 424 | if (!(timer->capability & OMAP_TIMER_NEEDS_RESET)) |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 425 | rate = clk_get_rate(timer->fclk); |
Tony Lindgren | caf64f2 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 426 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 427 | __omap_dm_timer_stop(timer, timer->posted, rate); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 428 | |
Tony Lindgren | 6e740f9 | 2012-10-29 15:20:45 -0700 | [diff] [blame] | 429 | if (!(timer->capability & OMAP_TIMER_ALWON)) { |
| 430 | if (timer->get_context_loss_count) |
| 431 | timer->ctx_loss_count = |
| 432 | timer->get_context_loss_count(&timer->pdev->dev); |
| 433 | } |
Tarun Kanti DebBarma | dffc9da | 2012-03-05 16:11:00 -0800 | [diff] [blame] | 434 | |
| 435 | /* |
| 436 | * Since the register values are computed and written within |
| 437 | * __omap_dm_timer_stop, we need to use read to retrieve the |
| 438 | * context. |
| 439 | */ |
| 440 | timer->context.tclr = |
| 441 | omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Tarun Kanti DebBarma | dffc9da | 2012-03-05 16:11:00 -0800 | [diff] [blame] | 442 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 443 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 444 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 445 | EXPORT_SYMBOL_GPL(omap_dm_timer_stop); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 446 | |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 447 | 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] | 448 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 449 | int ret; |
Jon Hunter | 2b2d352 | 2012-06-05 12:34:59 -0500 | [diff] [blame] | 450 | char *parent_name = NULL; |
Jon Hunter | d7aba55 | 2012-07-18 20:10:12 -0500 | [diff] [blame^] | 451 | struct clk *parent; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 452 | struct dmtimer_platform_data *pdata; |
| 453 | |
| 454 | if (unlikely(!timer)) |
| 455 | return -EINVAL; |
| 456 | |
| 457 | pdata = timer->pdev->dev.platform_data; |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 458 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 459 | if (source < 0 || source >= 3) |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 460 | return -EINVAL; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 461 | |
Jon Hunter | 2b2d352 | 2012-06-05 12:34:59 -0500 | [diff] [blame] | 462 | /* |
| 463 | * FIXME: Used for OMAP1 devices only because they do not currently |
| 464 | * use the clock framework to set the parent clock. To be removed |
| 465 | * once OMAP1 migrated to using clock framework for dmtimers |
| 466 | */ |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 467 | if (pdata && pdata->set_timer_src) |
Jon Hunter | 2b2d352 | 2012-06-05 12:34:59 -0500 | [diff] [blame] | 468 | return pdata->set_timer_src(timer->pdev, source); |
| 469 | |
Jon Hunter | d7aba55 | 2012-07-18 20:10:12 -0500 | [diff] [blame^] | 470 | if (!timer->fclk) |
Jon Hunter | 2b2d352 | 2012-06-05 12:34:59 -0500 | [diff] [blame] | 471 | return -EINVAL; |
Jon Hunter | 2b2d352 | 2012-06-05 12:34:59 -0500 | [diff] [blame] | 472 | |
| 473 | switch (source) { |
| 474 | case OMAP_TIMER_SRC_SYS_CLK: |
Jon Hunter | c59b537 | 2012-06-05 12:35:00 -0500 | [diff] [blame] | 475 | parent_name = "timer_sys_ck"; |
Jon Hunter | 2b2d352 | 2012-06-05 12:34:59 -0500 | [diff] [blame] | 476 | break; |
| 477 | |
| 478 | case OMAP_TIMER_SRC_32_KHZ: |
Jon Hunter | c59b537 | 2012-06-05 12:35:00 -0500 | [diff] [blame] | 479 | parent_name = "timer_32k_ck"; |
Jon Hunter | 2b2d352 | 2012-06-05 12:34:59 -0500 | [diff] [blame] | 480 | break; |
| 481 | |
| 482 | case OMAP_TIMER_SRC_EXT_CLK: |
Jon Hunter | c59b537 | 2012-06-05 12:35:00 -0500 | [diff] [blame] | 483 | parent_name = "timer_ext_ck"; |
Jon Hunter | 2b2d352 | 2012-06-05 12:34:59 -0500 | [diff] [blame] | 484 | break; |
| 485 | } |
| 486 | |
| 487 | parent = clk_get(&timer->pdev->dev, parent_name); |
| 488 | if (IS_ERR_OR_NULL(parent)) { |
| 489 | pr_err("%s: %s not found\n", __func__, parent_name); |
Jon Hunter | d7aba55 | 2012-07-18 20:10:12 -0500 | [diff] [blame^] | 490 | return -EINVAL; |
Jon Hunter | 2b2d352 | 2012-06-05 12:34:59 -0500 | [diff] [blame] | 491 | } |
| 492 | |
Jon Hunter | d7aba55 | 2012-07-18 20:10:12 -0500 | [diff] [blame^] | 493 | ret = clk_set_parent(timer->fclk, parent); |
Jon Hunter | 2b2d352 | 2012-06-05 12:34:59 -0500 | [diff] [blame] | 494 | if (IS_ERR_VALUE(ret)) |
| 495 | pr_err("%s: failed to set %s as parent\n", __func__, |
| 496 | parent_name); |
| 497 | |
| 498 | clk_put(parent); |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 499 | |
| 500 | return ret; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 501 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 502 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_source); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 503 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 504 | 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] | 505 | unsigned int load) |
| 506 | { |
| 507 | u32 l; |
| 508 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 509 | if (unlikely(!timer)) |
| 510 | return -EINVAL; |
| 511 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 512 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 513 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 514 | if (autoreload) |
| 515 | l |= OMAP_TIMER_CTRL_AR; |
| 516 | else |
| 517 | l &= ~OMAP_TIMER_CTRL_AR; |
| 518 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
| 519 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load); |
Richard Woodruff | 0f0d080 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 520 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 521 | omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 522 | /* Save the context */ |
| 523 | timer->context.tclr = l; |
| 524 | timer->context.tldr = load; |
| 525 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 526 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 527 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 528 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_load); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 529 | |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 530 | /* Optimized set_load which removes costly spin wait in timer_start */ |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 531 | 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] | 532 | unsigned int load) |
| 533 | { |
| 534 | u32 l; |
| 535 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 536 | if (unlikely(!timer)) |
| 537 | return -EINVAL; |
| 538 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 539 | omap_dm_timer_enable(timer); |
| 540 | |
Jon Hunter | 1c2d076 | 2012-06-05 12:34:55 -0500 | [diff] [blame] | 541 | if (!(timer->capability & OMAP_TIMER_ALWON)) { |
Tony Lindgren | 6e740f9 | 2012-10-29 15:20:45 -0700 | [diff] [blame] | 542 | if (timer->get_context_loss_count && |
| 543 | timer->get_context_loss_count(&timer->pdev->dev) != |
Jon Hunter | 0b30ec1 | 2012-06-05 12:34:56 -0500 | [diff] [blame] | 544 | timer->ctx_loss_count) |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 545 | omap_timer_restore_context(timer); |
| 546 | } |
| 547 | |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 548 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 549 | if (autoreload) { |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 550 | l |= OMAP_TIMER_CTRL_AR; |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 551 | omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load); |
| 552 | } else { |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 553 | l &= ~OMAP_TIMER_CTRL_AR; |
Paul Walmsley | 64ce290 | 2008-12-10 17:36:34 -0800 | [diff] [blame] | 554 | } |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 555 | l |= OMAP_TIMER_CTRL_ST; |
| 556 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 557 | __omap_dm_timer_load_start(timer, l, load, timer->posted); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 558 | |
| 559 | /* Save the context */ |
| 560 | timer->context.tclr = l; |
| 561 | timer->context.tldr = load; |
| 562 | timer->context.tcrr = load; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 563 | return 0; |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 564 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 565 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_load_start); |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 566 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 567 | 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] | 568 | unsigned int match) |
| 569 | { |
| 570 | u32 l; |
| 571 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 572 | if (unlikely(!timer)) |
| 573 | return -EINVAL; |
| 574 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 575 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 576 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 577 | if (enable) |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 578 | l |= OMAP_TIMER_CTRL_CE; |
| 579 | else |
| 580 | l &= ~OMAP_TIMER_CTRL_CE; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 581 | omap_dm_timer_write_reg(timer, OMAP_TIMER_MATCH_REG, match); |
Jon Hunter | 991ad16 | 2012-10-04 18:17:42 -0500 | [diff] [blame] | 582 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 583 | |
| 584 | /* Save the context */ |
| 585 | timer->context.tclr = l; |
| 586 | timer->context.tmar = match; |
| 587 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 588 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 589 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 590 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_match); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 591 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 592 | 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] | 593 | int toggle, int trigger) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 594 | { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 595 | u32 l; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 596 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 597 | if (unlikely(!timer)) |
| 598 | return -EINVAL; |
| 599 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 600 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 601 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 602 | l &= ~(OMAP_TIMER_CTRL_GPOCFG | OMAP_TIMER_CTRL_SCPWM | |
| 603 | OMAP_TIMER_CTRL_PT | (0x03 << 10)); |
| 604 | if (def_on) |
| 605 | l |= OMAP_TIMER_CTRL_SCPWM; |
| 606 | if (toggle) |
| 607 | l |= OMAP_TIMER_CTRL_PT; |
| 608 | l |= trigger << 10; |
| 609 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 610 | |
| 611 | /* Save the context */ |
| 612 | timer->context.tclr = l; |
| 613 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 614 | return 0; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 615 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 616 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_pwm); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 617 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 618 | 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] | 619 | { |
| 620 | u32 l; |
| 621 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 622 | if (unlikely(!timer)) |
| 623 | return -EINVAL; |
| 624 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 625 | omap_dm_timer_enable(timer); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 626 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); |
| 627 | l &= ~(OMAP_TIMER_CTRL_PRE | (0x07 << 2)); |
| 628 | if (prescaler >= 0x00 && prescaler <= 0x07) { |
| 629 | l |= OMAP_TIMER_CTRL_PRE; |
| 630 | l |= prescaler << 2; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 631 | } |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 632 | omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 633 | |
| 634 | /* Save the context */ |
| 635 | timer->context.tclr = l; |
| 636 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 637 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 638 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 639 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_prescaler); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 640 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 641 | int omap_dm_timer_set_int_enable(struct omap_dm_timer *timer, |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 642 | unsigned int value) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 643 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 644 | if (unlikely(!timer)) |
| 645 | return -EINVAL; |
| 646 | |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 647 | omap_dm_timer_enable(timer); |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 648 | __omap_dm_timer_int_enable(timer, value); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 649 | |
| 650 | /* Save the context */ |
| 651 | timer->context.tier = value; |
| 652 | timer->context.twer = value; |
| 653 | omap_dm_timer_disable(timer); |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 654 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 655 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 656 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_int_enable); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 657 | |
Jon Hunter | 4249d96 | 2012-07-13 14:03:18 -0500 | [diff] [blame] | 658 | /** |
| 659 | * omap_dm_timer_set_int_disable - disable timer interrupts |
| 660 | * @timer: pointer to timer handle |
| 661 | * @mask: bit mask of interrupts to be disabled |
| 662 | * |
| 663 | * Disables the specified timer interrupts for a timer. |
| 664 | */ |
| 665 | int omap_dm_timer_set_int_disable(struct omap_dm_timer *timer, u32 mask) |
| 666 | { |
| 667 | u32 l = mask; |
| 668 | |
| 669 | if (unlikely(!timer)) |
| 670 | return -EINVAL; |
| 671 | |
| 672 | omap_dm_timer_enable(timer); |
| 673 | |
| 674 | if (timer->revision == 1) |
| 675 | l = __raw_readl(timer->irq_ena) & ~mask; |
| 676 | |
| 677 | __raw_writel(l, timer->irq_dis); |
| 678 | l = omap_dm_timer_read_reg(timer, OMAP_TIMER_WAKEUP_EN_REG) & ~mask; |
| 679 | omap_dm_timer_write_reg(timer, OMAP_TIMER_WAKEUP_EN_REG, l); |
| 680 | |
| 681 | /* Save the context */ |
| 682 | timer->context.tier &= ~mask; |
| 683 | timer->context.twer &= ~mask; |
| 684 | omap_dm_timer_disable(timer); |
| 685 | return 0; |
| 686 | } |
| 687 | EXPORT_SYMBOL_GPL(omap_dm_timer_set_int_disable); |
| 688 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 689 | unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer) |
| 690 | { |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 691 | unsigned int l; |
| 692 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 693 | if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) { |
| 694 | pr_err("%s: timer not available or enabled.\n", __func__); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 695 | return 0; |
| 696 | } |
| 697 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 698 | l = __raw_readl(timer->irq_stat); |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 699 | |
| 700 | return l; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 701 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 702 | EXPORT_SYMBOL_GPL(omap_dm_timer_read_status); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 703 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 704 | 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] | 705 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 706 | if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) |
| 707 | return -EINVAL; |
| 708 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 709 | __omap_dm_timer_write_status(timer, value); |
Jon Hunter | 1eaff71 | 2012-10-04 17:01:14 -0500 | [diff] [blame] | 710 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 711 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 712 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 713 | EXPORT_SYMBOL_GPL(omap_dm_timer_write_status); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 714 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 715 | unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer) |
| 716 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 717 | if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) { |
| 718 | pr_err("%s: timer not iavailable or enabled.\n", __func__); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 719 | return 0; |
| 720 | } |
| 721 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 722 | return __omap_dm_timer_read_counter(timer, timer->posted); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 723 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 724 | EXPORT_SYMBOL_GPL(omap_dm_timer_read_counter); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 725 | |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 726 | 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] | 727 | { |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 728 | if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) { |
| 729 | pr_err("%s: timer not available or enabled.\n", __func__); |
| 730 | return -EINVAL; |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 731 | } |
| 732 | |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 733 | omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, value); |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 734 | |
| 735 | /* Save the context */ |
| 736 | timer->context.tcrr = value; |
Tarun Kanti DebBarma | ab4eb8b | 2011-09-20 17:00:26 +0530 | [diff] [blame] | 737 | return 0; |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 738 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 739 | EXPORT_SYMBOL_GPL(omap_dm_timer_write_counter); |
Timo Teras | 83379c8 | 2006-06-26 16:16:23 -0700 | [diff] [blame] | 740 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 741 | int omap_dm_timers_active(void) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 742 | { |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 743 | struct omap_dm_timer *timer; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 744 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 745 | list_for_each_entry(timer, &omap_timer_list, node) { |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 746 | if (!timer->reserved) |
Timo Teras | 12583a7 | 2006-09-25 12:41:42 +0300 | [diff] [blame] | 747 | continue; |
| 748 | |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 749 | if (omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG) & |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 750 | OMAP_TIMER_CTRL_ST) { |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 751 | return 1; |
Timo Teras | fa4bb62 | 2006-09-25 12:41:35 +0300 | [diff] [blame] | 752 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 753 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 754 | return 0; |
| 755 | } |
Timo Kokkonen | 6c366e3 | 2009-03-23 18:07:46 -0700 | [diff] [blame] | 756 | EXPORT_SYMBOL_GPL(omap_dm_timers_active); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 757 | |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 758 | /** |
| 759 | * omap_dm_timer_probe - probe function called for every registered device |
| 760 | * @pdev: pointer to current timer platform device |
| 761 | * |
| 762 | * Called by driver framework at the end of device registration for all |
| 763 | * timer devices. |
| 764 | */ |
| 765 | static int __devinit omap_dm_timer_probe(struct platform_device *pdev) |
| 766 | { |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 767 | unsigned long flags; |
| 768 | struct omap_dm_timer *timer; |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 769 | struct resource *mem, *irq; |
| 770 | struct device *dev = &pdev->dev; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 771 | struct dmtimer_platform_data *pdata = pdev->dev.platform_data; |
| 772 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 773 | if (!pdata && !dev->of_node) { |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 774 | dev_err(dev, "%s: no platform data.\n", __func__); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 775 | return -ENODEV; |
| 776 | } |
| 777 | |
| 778 | irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 779 | if (unlikely(!irq)) { |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 780 | dev_err(dev, "%s: no IRQ resource.\n", __func__); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 781 | return -ENODEV; |
| 782 | } |
| 783 | |
| 784 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 785 | if (unlikely(!mem)) { |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 786 | dev_err(dev, "%s: no memory resource.\n", __func__); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 787 | return -ENODEV; |
| 788 | } |
| 789 | |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 790 | timer = devm_kzalloc(dev, sizeof(struct omap_dm_timer), GFP_KERNEL); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 791 | if (!timer) { |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 792 | dev_err(dev, "%s: memory alloc failed!\n", __func__); |
| 793 | return -ENOMEM; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 794 | } |
| 795 | |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 796 | timer->io_base = devm_request_and_ioremap(dev, mem); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 797 | if (!timer->io_base) { |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 798 | dev_err(dev, "%s: region already claimed.\n", __func__); |
| 799 | return -ENOMEM; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 800 | } |
| 801 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 802 | if (dev->of_node) { |
| 803 | if (of_find_property(dev->of_node, "ti,timer-alwon", NULL)) |
| 804 | timer->capability |= OMAP_TIMER_ALWON; |
| 805 | if (of_find_property(dev->of_node, "ti,timer-dsp", NULL)) |
| 806 | timer->capability |= OMAP_TIMER_HAS_DSP_IRQ; |
| 807 | if (of_find_property(dev->of_node, "ti,timer-pwm", NULL)) |
| 808 | timer->capability |= OMAP_TIMER_HAS_PWM; |
| 809 | if (of_find_property(dev->of_node, "ti,timer-secure", NULL)) |
| 810 | timer->capability |= OMAP_TIMER_SECURE; |
| 811 | } else { |
| 812 | timer->id = pdev->id; |
Jon Hunter | bfd6d02 | 2012-09-27 12:47:43 -0500 | [diff] [blame] | 813 | timer->errata = pdata->timer_errata; |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 814 | timer->capability = pdata->timer_capability; |
| 815 | timer->reserved = omap_dm_timer_reserved_systimer(timer->id); |
Tony Lindgren | f56f52e | 2012-11-09 14:54:17 -0800 | [diff] [blame] | 816 | timer->get_context_loss_count = pdata->get_context_loss_count; |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 817 | } |
| 818 | |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 819 | timer->irq = irq->start; |
| 820 | timer->pdev = pdev; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 821 | |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 822 | /* Skip pm_runtime_enable for OMAP1 */ |
Jon Hunter | 6615975 | 2012-06-05 12:34:57 -0500 | [diff] [blame] | 823 | if (!(timer->capability & OMAP_TIMER_NEEDS_RESET)) { |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 824 | pm_runtime_enable(dev); |
| 825 | pm_runtime_irq_safe(dev); |
Tarun Kanti DebBarma | ffe07ce | 2011-09-20 17:00:21 +0530 | [diff] [blame] | 826 | } |
| 827 | |
Tony Lindgren | 0dad9fa | 2011-09-21 16:38:51 -0700 | [diff] [blame] | 828 | if (!timer->reserved) { |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 829 | pm_runtime_get_sync(dev); |
Tony Lindgren | 0dad9fa | 2011-09-21 16:38:51 -0700 | [diff] [blame] | 830 | __omap_dm_timer_init_regs(timer); |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 831 | pm_runtime_put(dev); |
Tony Lindgren | 0dad9fa | 2011-09-21 16:38:51 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 834 | /* add the timer element to the list */ |
| 835 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 836 | list_add_tail(&timer->node, &omap_timer_list); |
| 837 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 838 | |
Tarun Kanti DebBarma | 74dd9ec | 2012-04-20 18:09:20 +0530 | [diff] [blame] | 839 | dev_dbg(dev, "Device Probed.\n"); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 840 | |
| 841 | return 0; |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | /** |
| 845 | * omap_dm_timer_remove - cleanup a registered timer device |
| 846 | * @pdev: pointer to current timer platform device |
| 847 | * |
| 848 | * Called by driver framework whenever a timer device is unregistered. |
| 849 | * In addition to freeing platform resources it also deletes the timer |
| 850 | * entry from the local list. |
| 851 | */ |
| 852 | static int __devexit omap_dm_timer_remove(struct platform_device *pdev) |
| 853 | { |
| 854 | struct omap_dm_timer *timer; |
| 855 | unsigned long flags; |
| 856 | int ret = -EINVAL; |
| 857 | |
| 858 | spin_lock_irqsave(&dm_timer_lock, flags); |
| 859 | list_for_each_entry(timer, &omap_timer_list, node) |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 860 | if (!strcmp(dev_name(&timer->pdev->dev), |
| 861 | dev_name(&pdev->dev))) { |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 862 | list_del(&timer->node); |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 863 | ret = 0; |
| 864 | break; |
| 865 | } |
| 866 | spin_unlock_irqrestore(&dm_timer_lock, flags); |
| 867 | |
| 868 | return ret; |
| 869 | } |
| 870 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 871 | static const struct of_device_id omap_timer_match[] = { |
| 872 | { .compatible = "ti,omap2-timer", }, |
| 873 | {}, |
| 874 | }; |
| 875 | MODULE_DEVICE_TABLE(of, omap_timer_match); |
| 876 | |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 877 | static struct platform_driver omap_dm_timer_driver = { |
| 878 | .probe = omap_dm_timer_probe, |
Arnd Bergmann | 4c23c8d | 2011-10-01 18:42:47 +0200 | [diff] [blame] | 879 | .remove = __devexit_p(omap_dm_timer_remove), |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 880 | .driver = { |
| 881 | .name = "omap_timer", |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 882 | .of_match_table = of_match_ptr(omap_timer_match), |
Tarun Kanti DebBarma | df28472 | 2011-09-20 17:00:19 +0530 | [diff] [blame] | 883 | }, |
| 884 | }; |
| 885 | |
| 886 | static int __init omap_dm_timer_driver_init(void) |
| 887 | { |
| 888 | return platform_driver_register(&omap_dm_timer_driver); |
| 889 | } |
| 890 | |
| 891 | static void __exit omap_dm_timer_driver_exit(void) |
| 892 | { |
| 893 | platform_driver_unregister(&omap_dm_timer_driver); |
| 894 | } |
| 895 | |
| 896 | early_platform_init("earlytimer", &omap_dm_timer_driver); |
| 897 | module_init(omap_dm_timer_driver_init); |
| 898 | module_exit(omap_dm_timer_driver_exit); |
| 899 | |
| 900 | MODULE_DESCRIPTION("OMAP Dual-Mode Timer Driver"); |
| 901 | MODULE_LICENSE("GPL"); |
| 902 | MODULE_ALIAS("platform:" DRIVER_NAME); |
| 903 | MODULE_AUTHOR("Texas Instruments Inc"); |