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