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