blob: e3e22b3dc5c24533cc12799cb5506c875cdf1dda [file] [log] [blame]
Tony Lindgren92105bb2005-09-07 17:20:26 +01001/*
2 * linux/arch/arm/plat-omap/dmtimer.c
3 *
4 * OMAP Dual-Mode Timers
5 *
Tarun Kanti DebBarma97933d62011-09-20 17:00:17 +05306 * 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 Lindgren92105bb2005-09-07 17:20:26 +010012 * Copyright (C) 2005 Nokia Corporation
Timo Teras77900a22006-06-26 16:16:12 -070013 * OMAP2 support by Juha Yrjola
14 * API improvements and OMAP2 clock framework support by Timo Teras
Tony Lindgren92105bb2005-09-07 17:20:26 +010015 *
Santosh Shilimkar44169072009-05-28 14:16:04 -070016 * Copyright (C) 2009 Texas Instruments
17 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
18 *
Tony Lindgren92105bb2005-09-07 17:20:26 +010019 * 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 Lin869dec12011-11-02 09:49:46 +080038#include <linux/module.h>
Russell Kingfced80c2008-09-06 12:10:45 +010039#include <linux/io.h>
Tarun Kanti DebBarmadf284722011-09-20 17:00:19 +053040#include <linux/slab.h>
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +053041#include <linux/err.h>
Tarun Kanti DebBarmaffe07ce2011-09-20 17:00:21 +053042#include <linux/pm_runtime.h>
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +053043
Tony Lindgrence491cf2009-10-20 09:40:47 -070044#include <plat/dmtimer.h>
Jon Hunter0b30ec12012-06-05 12:34:56 -050045#include <plat/omap-pm.h>
Tony Lindgren92105bb2005-09-07 17:20:26 +010046
Tony Lindgren2c799ce2012-02-24 10:34:35 -080047#include <mach/hardware.h>
48
Jon Hunterb7b4ff72012-06-05 12:34:51 -050049static u32 omap_reserved_systimers;
Tarun Kanti DebBarmadf284722011-09-20 17:00:19 +053050static LIST_HEAD(omap_timer_list);
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +053051static DEFINE_SPINLOCK(dm_timer_lock);
Tony Lindgren92105bb2005-09-07 17:20:26 +010052
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +053053/**
54 * omap_dm_timer_read_reg - read timer registers in posted and non-posted mode
55 * @timer: timer pointer over which read operation to perform
56 * @reg: lowest byte holds the register offset
57 *
58 * The posted mode bit is encoded in reg. Note that in posted mode write
59 * pending bit must be checked. Otherwise a read of a non completed write
60 * will produce an error.
Richard Woodruff0f0d0802008-07-03 12:24:30 +030061 */
62static inline u32 omap_dm_timer_read_reg(struct omap_dm_timer *timer, u32 reg)
Tony Lindgren92105bb2005-09-07 17:20:26 +010063{
Tony Lindgrenee17f112011-09-16 15:44:20 -070064 WARN_ON((reg & 0xff) < _OMAP_TIMER_WAKEUP_EN_OFFSET);
65 return __omap_dm_timer_read(timer, reg, timer->posted);
Timo Teras77900a22006-06-26 16:16:12 -070066}
67
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +053068/**
69 * omap_dm_timer_write_reg - write timer registers in posted and non-posted mode
70 * @timer: timer pointer over which write operation is to perform
71 * @reg: lowest byte holds the register offset
72 * @value: data to write into the register
73 *
74 * The posted mode bit is encoded in reg. Note that in posted mode the write
75 * pending bit must be checked. Otherwise a write on a register which has a
76 * pending write will be lost.
Richard Woodruff0f0d0802008-07-03 12:24:30 +030077 */
78static void omap_dm_timer_write_reg(struct omap_dm_timer *timer, u32 reg,
79 u32 value)
Timo Teras77900a22006-06-26 16:16:12 -070080{
Tony Lindgrenee17f112011-09-16 15:44:20 -070081 WARN_ON((reg & 0xff) < _OMAP_TIMER_WAKEUP_EN_OFFSET);
82 __omap_dm_timer_write(timer, reg, value, timer->posted);
Tony Lindgren92105bb2005-09-07 17:20:26 +010083}
84
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +053085static void omap_timer_restore_context(struct omap_dm_timer *timer)
86{
Tarun Kanti DebBarmadffc9da2012-03-05 16:11:00 -080087 if (timer->revision == 1)
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +053088 __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 Teras77900a22006-06-26 16:16:12 -0700106static void omap_dm_timer_wait_for_reset(struct omap_dm_timer *timer)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100107{
Timo Teras77900a22006-06-26 16:16:12 -0700108 int c;
109
Tony Lindgrenee17f112011-09-16 15:44:20 -0700110 if (!timer->sys_stat)
111 return;
112
Timo Teras77900a22006-06-26 16:16:12 -0700113 c = 0;
Tony Lindgrenee17f112011-09-16 15:44:20 -0700114 while (!(__raw_readl(timer->sys_stat) & 1)) {
Timo Teras77900a22006-06-26 16:16:12 -0700115 c++;
116 if (c > 100000) {
117 printk(KERN_ERR "Timer failed to reset\n");
118 return;
119 }
120 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100121}
122
Timo Teras77900a22006-06-26 16:16:12 -0700123static void omap_dm_timer_reset(struct omap_dm_timer *timer)
124{
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530125 omap_dm_timer_enable(timer);
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530126 if (timer->pdev->id != 1) {
Timo Terase32f7ec2006-06-26 16:16:13 -0700127 omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, 0x06);
128 omap_dm_timer_wait_for_reset(timer);
129 }
Timo Teras77900a22006-06-26 16:16:12 -0700130
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530131 __omap_dm_timer_reset(timer, 0, 0);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530132 omap_dm_timer_disable(timer);
Richard Woodruff0f0d0802008-07-03 12:24:30 +0300133 timer->posted = 1;
Timo Teras77900a22006-06-26 16:16:12 -0700134}
135
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530136int omap_dm_timer_prepare(struct omap_dm_timer *timer)
Timo Teras77900a22006-06-26 16:16:12 -0700137{
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530138 int ret;
139
140 timer->fclk = clk_get(&timer->pdev->dev, "fck");
141 if (WARN_ON_ONCE(IS_ERR_OR_NULL(timer->fclk))) {
142 timer->fclk = NULL;
143 dev_err(&timer->pdev->dev, ": No fclk handle.\n");
144 return -EINVAL;
145 }
146
Jon Hunter66159752012-06-05 12:34:57 -0500147 if (timer->capability & OMAP_TIMER_NEEDS_RESET)
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530148 omap_dm_timer_reset(timer);
149
150 ret = omap_dm_timer_set_source(timer, OMAP_TIMER_SRC_32_KHZ);
151
152 timer->posted = 1;
153 return ret;
Timo Teras77900a22006-06-26 16:16:12 -0700154}
155
Jon Hunterb7b4ff72012-06-05 12:34:51 -0500156static inline u32 omap_dm_timer_reserved_systimer(int id)
157{
158 return (omap_reserved_systimers & (1 << (id - 1))) ? 1 : 0;
159}
160
161int omap_dm_timer_reserve_systimer(int id)
162{
163 if (omap_dm_timer_reserved_systimer(id))
164 return -ENODEV;
165
166 omap_reserved_systimers |= (1 << (id - 1));
167
168 return 0;
169}
170
Timo Teras77900a22006-06-26 16:16:12 -0700171struct omap_dm_timer *omap_dm_timer_request(void)
172{
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530173 struct omap_dm_timer *timer = NULL, *t;
Timo Teras77900a22006-06-26 16:16:12 -0700174 unsigned long flags;
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530175 int ret = 0;
Timo Teras77900a22006-06-26 16:16:12 -0700176
177 spin_lock_irqsave(&dm_timer_lock, flags);
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530178 list_for_each_entry(t, &omap_timer_list, node) {
179 if (t->reserved)
Timo Teras77900a22006-06-26 16:16:12 -0700180 continue;
181
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530182 timer = t;
Timo Teras83379c82006-06-26 16:16:23 -0700183 timer->reserved = 1;
Timo Teras77900a22006-06-26 16:16:12 -0700184 break;
185 }
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530186
187 if (timer) {
188 ret = omap_dm_timer_prepare(timer);
189 if (ret) {
190 timer->reserved = 0;
191 timer = NULL;
192 }
193 }
Timo Teras77900a22006-06-26 16:16:12 -0700194 spin_unlock_irqrestore(&dm_timer_lock, flags);
195
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530196 if (!timer)
197 pr_debug("%s: timer request failed!\n", __func__);
Timo Teras83379c82006-06-26 16:16:23 -0700198
Timo Teras77900a22006-06-26 16:16:12 -0700199 return timer;
200}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700201EXPORT_SYMBOL_GPL(omap_dm_timer_request);
Timo Teras77900a22006-06-26 16:16:12 -0700202
203struct omap_dm_timer *omap_dm_timer_request_specific(int id)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100204{
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530205 struct omap_dm_timer *timer = NULL, *t;
Timo Teras77900a22006-06-26 16:16:12 -0700206 unsigned long flags;
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530207 int ret = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100208
Timo Teras77900a22006-06-26 16:16:12 -0700209 spin_lock_irqsave(&dm_timer_lock, flags);
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530210 list_for_each_entry(t, &omap_timer_list, node) {
211 if (t->pdev->id == id && !t->reserved) {
212 timer = t;
213 timer->reserved = 1;
214 break;
215 }
Timo Teras77900a22006-06-26 16:16:12 -0700216 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100217
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530218 if (timer) {
219 ret = omap_dm_timer_prepare(timer);
220 if (ret) {
221 timer->reserved = 0;
222 timer = NULL;
223 }
224 }
Timo Teras77900a22006-06-26 16:16:12 -0700225 spin_unlock_irqrestore(&dm_timer_lock, flags);
226
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530227 if (!timer)
228 pr_debug("%s: timer%d request failed!\n", __func__, id);
Timo Teras83379c82006-06-26 16:16:23 -0700229
Timo Teras77900a22006-06-26 16:16:12 -0700230 return timer;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100231}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700232EXPORT_SYMBOL_GPL(omap_dm_timer_request_specific);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100233
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530234int omap_dm_timer_free(struct omap_dm_timer *timer)
Timo Teras77900a22006-06-26 16:16:12 -0700235{
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530236 if (unlikely(!timer))
237 return -EINVAL;
238
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530239 clk_put(timer->fclk);
Timo Terasfa4bb622006-09-25 12:41:35 +0300240
Timo Teras77900a22006-06-26 16:16:12 -0700241 WARN_ON(!timer->reserved);
242 timer->reserved = 0;
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530243 return 0;
Timo Teras77900a22006-06-26 16:16:12 -0700244}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700245EXPORT_SYMBOL_GPL(omap_dm_timer_free);
Timo Teras77900a22006-06-26 16:16:12 -0700246
Timo Teras12583a72006-09-25 12:41:42 +0300247void omap_dm_timer_enable(struct omap_dm_timer *timer)
248{
Tarun Kanti DebBarmaffe07ce2011-09-20 17:00:21 +0530249 pm_runtime_get_sync(&timer->pdev->dev);
Timo Teras12583a72006-09-25 12:41:42 +0300250}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700251EXPORT_SYMBOL_GPL(omap_dm_timer_enable);
Timo Teras12583a72006-09-25 12:41:42 +0300252
253void omap_dm_timer_disable(struct omap_dm_timer *timer)
254{
Tarun Kanti DebBarmaffe07ce2011-09-20 17:00:21 +0530255 pm_runtime_put(&timer->pdev->dev);
Timo Teras12583a72006-09-25 12:41:42 +0300256}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700257EXPORT_SYMBOL_GPL(omap_dm_timer_disable);
Timo Teras12583a72006-09-25 12:41:42 +0300258
Timo Teras77900a22006-06-26 16:16:12 -0700259int omap_dm_timer_get_irq(struct omap_dm_timer *timer)
260{
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530261 if (timer)
262 return timer->irq;
263 return -EINVAL;
Timo Teras77900a22006-06-26 16:16:12 -0700264}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700265EXPORT_SYMBOL_GPL(omap_dm_timer_get_irq);
Timo Teras77900a22006-06-26 16:16:12 -0700266
267#if defined(CONFIG_ARCH_OMAP1)
268
Tony Lindgrena569c6e2006-04-02 17:46:21 +0100269/**
270 * omap_dm_timer_modify_idlect_mask - Check if any running timers use ARMXOR
271 * @inputmask: current value of idlect mask
272 */
273__u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask)
274{
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530275 int i = 0;
276 struct omap_dm_timer *timer = NULL;
277 unsigned long flags;
Tony Lindgrena569c6e2006-04-02 17:46:21 +0100278
279 /* If ARMXOR cannot be idled this function call is unnecessary */
280 if (!(inputmask & (1 << 1)))
281 return inputmask;
282
283 /* If any active timer is using ARMXOR return modified mask */
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530284 spin_lock_irqsave(&dm_timer_lock, flags);
285 list_for_each_entry(timer, &omap_timer_list, node) {
Timo Teras77900a22006-06-26 16:16:12 -0700286 u32 l;
287
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530288 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
Timo Teras77900a22006-06-26 16:16:12 -0700289 if (l & OMAP_TIMER_CTRL_ST) {
290 if (((omap_readl(MOD_CONF_CTRL_1) >> (i * 2)) & 0x03) == 0)
Tony Lindgrena569c6e2006-04-02 17:46:21 +0100291 inputmask &= ~(1 << 1);
292 else
293 inputmask &= ~(1 << 2);
294 }
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530295 i++;
Timo Teras77900a22006-06-26 16:16:12 -0700296 }
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530297 spin_unlock_irqrestore(&dm_timer_lock, flags);
Tony Lindgrena569c6e2006-04-02 17:46:21 +0100298
299 return inputmask;
300}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700301EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask);
Tony Lindgrena569c6e2006-04-02 17:46:21 +0100302
Tony Lindgren140455f2010-02-12 12:26:48 -0800303#else
Timo Teras77900a22006-06-26 16:16:12 -0700304
305struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer)
306{
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530307 if (timer)
308 return timer->fclk;
309 return NULL;
Timo Teras77900a22006-06-26 16:16:12 -0700310}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700311EXPORT_SYMBOL_GPL(omap_dm_timer_get_fclk);
Timo Teras77900a22006-06-26 16:16:12 -0700312
313__u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask)
314{
315 BUG();
Dirk Behme21218802006-12-06 17:14:00 -0800316
317 return 0;
Timo Teras77900a22006-06-26 16:16:12 -0700318}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700319EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask);
Timo Teras77900a22006-06-26 16:16:12 -0700320
321#endif
322
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530323int omap_dm_timer_trigger(struct omap_dm_timer *timer)
Timo Teras77900a22006-06-26 16:16:12 -0700324{
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530325 if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
326 pr_err("%s: timer not available or enabled.\n", __func__);
327 return -EINVAL;
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530328 }
329
Timo Teras77900a22006-06-26 16:16:12 -0700330 omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530331 return 0;
Timo Teras77900a22006-06-26 16:16:12 -0700332}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700333EXPORT_SYMBOL_GPL(omap_dm_timer_trigger);
Timo Teras77900a22006-06-26 16:16:12 -0700334
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530335int omap_dm_timer_start(struct omap_dm_timer *timer)
Timo Teras77900a22006-06-26 16:16:12 -0700336{
337 u32 l;
338
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530339 if (unlikely(!timer))
340 return -EINVAL;
341
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530342 omap_dm_timer_enable(timer);
343
Jon Hunter1c2d0762012-06-05 12:34:55 -0500344 if (!(timer->capability & OMAP_TIMER_ALWON)) {
Jon Hunter0b30ec12012-06-05 12:34:56 -0500345 if (omap_pm_get_dev_context_loss_count(&timer->pdev->dev) !=
346 timer->ctx_loss_count)
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530347 omap_timer_restore_context(timer);
348 }
349
Timo Teras77900a22006-06-26 16:16:12 -0700350 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
351 if (!(l & OMAP_TIMER_CTRL_ST)) {
352 l |= OMAP_TIMER_CTRL_ST;
353 omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l);
354 }
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530355
356 /* Save the context */
357 timer->context.tclr = l;
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530358 return 0;
Timo Teras77900a22006-06-26 16:16:12 -0700359}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700360EXPORT_SYMBOL_GPL(omap_dm_timer_start);
Timo Teras77900a22006-06-26 16:16:12 -0700361
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530362int omap_dm_timer_stop(struct omap_dm_timer *timer)
Timo Teras77900a22006-06-26 16:16:12 -0700363{
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700364 unsigned long rate = 0;
Timo Teras77900a22006-06-26 16:16:12 -0700365
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530366 if (unlikely(!timer))
367 return -EINVAL;
368
Jon Hunter66159752012-06-05 12:34:57 -0500369 if (!(timer->capability & OMAP_TIMER_NEEDS_RESET))
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530370 rate = clk_get_rate(timer->fclk);
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700371
Tony Lindgrenee17f112011-09-16 15:44:20 -0700372 __omap_dm_timer_stop(timer, timer->posted, rate);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530373
Jon Hunter0b30ec12012-06-05 12:34:56 -0500374 if (!(timer->capability & OMAP_TIMER_ALWON))
Tarun Kanti DebBarmadffc9da2012-03-05 16:11:00 -0800375 timer->ctx_loss_count =
Jon Hunter0b30ec12012-06-05 12:34:56 -0500376 omap_pm_get_dev_context_loss_count(&timer->pdev->dev);
Tarun Kanti DebBarmadffc9da2012-03-05 16:11:00 -0800377
378 /*
379 * Since the register values are computed and written within
380 * __omap_dm_timer_stop, we need to use read to retrieve the
381 * context.
382 */
383 timer->context.tclr =
384 omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
385 timer->context.tisr = __raw_readl(timer->irq_stat);
386 omap_dm_timer_disable(timer);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530387 return 0;
Timo Teras77900a22006-06-26 16:16:12 -0700388}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700389EXPORT_SYMBOL_GPL(omap_dm_timer_stop);
Timo Teras77900a22006-06-26 16:16:12 -0700390
Paul Walmsleyf2480762009-04-23 21:11:10 -0600391int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100392{
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530393 int ret;
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530394 struct dmtimer_platform_data *pdata;
395
396 if (unlikely(!timer))
397 return -EINVAL;
398
399 pdata = timer->pdev->dev.platform_data;
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530400
Timo Teras77900a22006-06-26 16:16:12 -0700401 if (source < 0 || source >= 3)
Paul Walmsleyf2480762009-04-23 21:11:10 -0600402 return -EINVAL;
Timo Teras77900a22006-06-26 16:16:12 -0700403
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530404 ret = pdata->set_timer_src(timer->pdev, source);
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530405
406 return ret;
Timo Teras77900a22006-06-26 16:16:12 -0700407}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700408EXPORT_SYMBOL_GPL(omap_dm_timer_set_source);
Timo Teras77900a22006-06-26 16:16:12 -0700409
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530410int omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload,
Timo Teras77900a22006-06-26 16:16:12 -0700411 unsigned int load)
412{
413 u32 l;
414
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530415 if (unlikely(!timer))
416 return -EINVAL;
417
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530418 omap_dm_timer_enable(timer);
Timo Teras77900a22006-06-26 16:16:12 -0700419 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
420 if (autoreload)
421 l |= OMAP_TIMER_CTRL_AR;
422 else
423 l &= ~OMAP_TIMER_CTRL_AR;
424 omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l);
425 omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load);
Richard Woodruff0f0d0802008-07-03 12:24:30 +0300426
Timo Teras77900a22006-06-26 16:16:12 -0700427 omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530428 /* Save the context */
429 timer->context.tclr = l;
430 timer->context.tldr = load;
431 omap_dm_timer_disable(timer);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530432 return 0;
Timo Teras77900a22006-06-26 16:16:12 -0700433}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700434EXPORT_SYMBOL_GPL(omap_dm_timer_set_load);
Timo Teras77900a22006-06-26 16:16:12 -0700435
Richard Woodruff3fddd092008-07-03 12:24:30 +0300436/* Optimized set_load which removes costly spin wait in timer_start */
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530437int omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload,
Richard Woodruff3fddd092008-07-03 12:24:30 +0300438 unsigned int load)
439{
440 u32 l;
441
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530442 if (unlikely(!timer))
443 return -EINVAL;
444
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530445 omap_dm_timer_enable(timer);
446
Jon Hunter1c2d0762012-06-05 12:34:55 -0500447 if (!(timer->capability & OMAP_TIMER_ALWON)) {
Jon Hunter0b30ec12012-06-05 12:34:56 -0500448 if (omap_pm_get_dev_context_loss_count(&timer->pdev->dev) !=
449 timer->ctx_loss_count)
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530450 omap_timer_restore_context(timer);
451 }
452
Richard Woodruff3fddd092008-07-03 12:24:30 +0300453 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
Paul Walmsley64ce2902008-12-10 17:36:34 -0800454 if (autoreload) {
Richard Woodruff3fddd092008-07-03 12:24:30 +0300455 l |= OMAP_TIMER_CTRL_AR;
Paul Walmsley64ce2902008-12-10 17:36:34 -0800456 omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load);
457 } else {
Richard Woodruff3fddd092008-07-03 12:24:30 +0300458 l &= ~OMAP_TIMER_CTRL_AR;
Paul Walmsley64ce2902008-12-10 17:36:34 -0800459 }
Richard Woodruff3fddd092008-07-03 12:24:30 +0300460 l |= OMAP_TIMER_CTRL_ST;
461
Tony Lindgrenee17f112011-09-16 15:44:20 -0700462 __omap_dm_timer_load_start(timer, l, load, timer->posted);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530463
464 /* Save the context */
465 timer->context.tclr = l;
466 timer->context.tldr = load;
467 timer->context.tcrr = load;
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530468 return 0;
Richard Woodruff3fddd092008-07-03 12:24:30 +0300469}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700470EXPORT_SYMBOL_GPL(omap_dm_timer_set_load_start);
Richard Woodruff3fddd092008-07-03 12:24:30 +0300471
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530472int omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable,
Timo Teras77900a22006-06-26 16:16:12 -0700473 unsigned int match)
474{
475 u32 l;
476
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530477 if (unlikely(!timer))
478 return -EINVAL;
479
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530480 omap_dm_timer_enable(timer);
Timo Teras77900a22006-06-26 16:16:12 -0700481 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
Timo Teras83379c82006-06-26 16:16:23 -0700482 if (enable)
Timo Teras77900a22006-06-26 16:16:12 -0700483 l |= OMAP_TIMER_CTRL_CE;
484 else
485 l &= ~OMAP_TIMER_CTRL_CE;
486 omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l);
487 omap_dm_timer_write_reg(timer, OMAP_TIMER_MATCH_REG, match);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530488
489 /* Save the context */
490 timer->context.tclr = l;
491 timer->context.tmar = match;
492 omap_dm_timer_disable(timer);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530493 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100494}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700495EXPORT_SYMBOL_GPL(omap_dm_timer_set_match);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100496
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530497int omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on,
Timo Teras77900a22006-06-26 16:16:12 -0700498 int toggle, int trigger)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100499{
Timo Teras77900a22006-06-26 16:16:12 -0700500 u32 l;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100501
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530502 if (unlikely(!timer))
503 return -EINVAL;
504
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530505 omap_dm_timer_enable(timer);
Timo Teras77900a22006-06-26 16:16:12 -0700506 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
507 l &= ~(OMAP_TIMER_CTRL_GPOCFG | OMAP_TIMER_CTRL_SCPWM |
508 OMAP_TIMER_CTRL_PT | (0x03 << 10));
509 if (def_on)
510 l |= OMAP_TIMER_CTRL_SCPWM;
511 if (toggle)
512 l |= OMAP_TIMER_CTRL_PT;
513 l |= trigger << 10;
514 omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530515
516 /* Save the context */
517 timer->context.tclr = l;
518 omap_dm_timer_disable(timer);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530519 return 0;
Timo Teras77900a22006-06-26 16:16:12 -0700520}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700521EXPORT_SYMBOL_GPL(omap_dm_timer_set_pwm);
Timo Teras77900a22006-06-26 16:16:12 -0700522
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530523int omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler)
Timo Teras77900a22006-06-26 16:16:12 -0700524{
525 u32 l;
526
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530527 if (unlikely(!timer))
528 return -EINVAL;
529
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530530 omap_dm_timer_enable(timer);
Timo Teras77900a22006-06-26 16:16:12 -0700531 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
532 l &= ~(OMAP_TIMER_CTRL_PRE | (0x07 << 2));
533 if (prescaler >= 0x00 && prescaler <= 0x07) {
534 l |= OMAP_TIMER_CTRL_PRE;
535 l |= prescaler << 2;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100536 }
Timo Teras77900a22006-06-26 16:16:12 -0700537 omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530538
539 /* Save the context */
540 timer->context.tclr = l;
541 omap_dm_timer_disable(timer);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530542 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100543}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700544EXPORT_SYMBOL_GPL(omap_dm_timer_set_prescaler);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100545
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530546int omap_dm_timer_set_int_enable(struct omap_dm_timer *timer,
Timo Teras77900a22006-06-26 16:16:12 -0700547 unsigned int value)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100548{
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530549 if (unlikely(!timer))
550 return -EINVAL;
551
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530552 omap_dm_timer_enable(timer);
Tony Lindgrenee17f112011-09-16 15:44:20 -0700553 __omap_dm_timer_int_enable(timer, value);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530554
555 /* Save the context */
556 timer->context.tier = value;
557 timer->context.twer = value;
558 omap_dm_timer_disable(timer);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530559 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100560}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700561EXPORT_SYMBOL_GPL(omap_dm_timer_set_int_enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100562
563unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer)
564{
Timo Terasfa4bb622006-09-25 12:41:35 +0300565 unsigned int l;
566
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530567 if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
568 pr_err("%s: timer not available or enabled.\n", __func__);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530569 return 0;
570 }
571
Tony Lindgrenee17f112011-09-16 15:44:20 -0700572 l = __raw_readl(timer->irq_stat);
Timo Terasfa4bb622006-09-25 12:41:35 +0300573
574 return l;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100575}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700576EXPORT_SYMBOL_GPL(omap_dm_timer_read_status);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100577
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530578int omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100579{
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530580 if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev)))
581 return -EINVAL;
582
Tony Lindgrenee17f112011-09-16 15:44:20 -0700583 __omap_dm_timer_write_status(timer, value);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530584 /* Save the context */
585 timer->context.tisr = value;
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530586 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100587}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700588EXPORT_SYMBOL_GPL(omap_dm_timer_write_status);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100589
Tony Lindgren92105bb2005-09-07 17:20:26 +0100590unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer)
591{
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530592 if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
593 pr_err("%s: timer not iavailable or enabled.\n", __func__);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530594 return 0;
595 }
596
Tony Lindgrenee17f112011-09-16 15:44:20 -0700597 return __omap_dm_timer_read_counter(timer, timer->posted);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100598}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700599EXPORT_SYMBOL_GPL(omap_dm_timer_read_counter);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100600
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530601int omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value)
Timo Teras83379c82006-06-26 16:16:23 -0700602{
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530603 if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
604 pr_err("%s: timer not available or enabled.\n", __func__);
605 return -EINVAL;
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530606 }
607
Timo Terasfa4bb622006-09-25 12:41:35 +0300608 omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, value);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530609
610 /* Save the context */
611 timer->context.tcrr = value;
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530612 return 0;
Timo Teras83379c82006-06-26 16:16:23 -0700613}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700614EXPORT_SYMBOL_GPL(omap_dm_timer_write_counter);
Timo Teras83379c82006-06-26 16:16:23 -0700615
Timo Teras77900a22006-06-26 16:16:12 -0700616int omap_dm_timers_active(void)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100617{
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530618 struct omap_dm_timer *timer;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100619
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530620 list_for_each_entry(timer, &omap_timer_list, node) {
Tarun Kanti DebBarmaffe07ce2011-09-20 17:00:21 +0530621 if (!timer->reserved)
Timo Teras12583a72006-09-25 12:41:42 +0300622 continue;
623
Timo Teras77900a22006-06-26 16:16:12 -0700624 if (omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG) &
Timo Terasfa4bb622006-09-25 12:41:35 +0300625 OMAP_TIMER_CTRL_ST) {
Timo Teras77900a22006-06-26 16:16:12 -0700626 return 1;
Timo Terasfa4bb622006-09-25 12:41:35 +0300627 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100628 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100629 return 0;
630}
Timo Kokkonen6c366e32009-03-23 18:07:46 -0700631EXPORT_SYMBOL_GPL(omap_dm_timers_active);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100632
Tarun Kanti DebBarmadf284722011-09-20 17:00:19 +0530633/**
634 * omap_dm_timer_probe - probe function called for every registered device
635 * @pdev: pointer to current timer platform device
636 *
637 * Called by driver framework at the end of device registration for all
638 * timer devices.
639 */
640static int __devinit omap_dm_timer_probe(struct platform_device *pdev)
641{
642 int ret;
643 unsigned long flags;
644 struct omap_dm_timer *timer;
645 struct resource *mem, *irq, *ioarea;
646 struct dmtimer_platform_data *pdata = pdev->dev.platform_data;
647
648 if (!pdata) {
649 dev_err(&pdev->dev, "%s: no platform data.\n", __func__);
650 return -ENODEV;
651 }
652
653 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
654 if (unlikely(!irq)) {
655 dev_err(&pdev->dev, "%s: no IRQ resource.\n", __func__);
656 return -ENODEV;
657 }
658
659 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
660 if (unlikely(!mem)) {
661 dev_err(&pdev->dev, "%s: no memory resource.\n", __func__);
662 return -ENODEV;
663 }
664
665 ioarea = request_mem_region(mem->start, resource_size(mem),
666 pdev->name);
667 if (!ioarea) {
668 dev_err(&pdev->dev, "%s: region already claimed.\n", __func__);
669 return -EBUSY;
670 }
671
672 timer = kzalloc(sizeof(struct omap_dm_timer), GFP_KERNEL);
673 if (!timer) {
674 dev_err(&pdev->dev, "%s: no memory for omap_dm_timer.\n",
675 __func__);
676 ret = -ENOMEM;
677 goto err_free_ioregion;
678 }
679
680 timer->io_base = ioremap(mem->start, resource_size(mem));
681 if (!timer->io_base) {
682 dev_err(&pdev->dev, "%s: ioremap failed.\n", __func__);
683 ret = -ENOMEM;
684 goto err_free_mem;
685 }
686
687 timer->id = pdev->id;
688 timer->irq = irq->start;
Jon Hunterb7b4ff72012-06-05 12:34:51 -0500689 timer->reserved = omap_dm_timer_reserved_systimer(timer->id);
Tarun Kanti DebBarmadf284722011-09-20 17:00:19 +0530690 timer->pdev = pdev;
Jon Hunterd1c16912012-06-05 12:34:52 -0500691 timer->capability = pdata->timer_capability;
Tarun Kanti DebBarmadf284722011-09-20 17:00:19 +0530692
Tarun Kanti DebBarmaffe07ce2011-09-20 17:00:21 +0530693 /* Skip pm_runtime_enable for OMAP1 */
Jon Hunter66159752012-06-05 12:34:57 -0500694 if (!(timer->capability & OMAP_TIMER_NEEDS_RESET)) {
Tarun Kanti DebBarmaffe07ce2011-09-20 17:00:21 +0530695 pm_runtime_enable(&pdev->dev);
696 pm_runtime_irq_safe(&pdev->dev);
697 }
698
Tony Lindgren0dad9fa2011-09-21 16:38:51 -0700699 if (!timer->reserved) {
700 pm_runtime_get_sync(&pdev->dev);
701 __omap_dm_timer_init_regs(timer);
702 pm_runtime_put(&pdev->dev);
703 }
704
Tarun Kanti DebBarmadf284722011-09-20 17:00:19 +0530705 /* add the timer element to the list */
706 spin_lock_irqsave(&dm_timer_lock, flags);
707 list_add_tail(&timer->node, &omap_timer_list);
708 spin_unlock_irqrestore(&dm_timer_lock, flags);
709
710 dev_dbg(&pdev->dev, "Device Probed.\n");
711
712 return 0;
713
714err_free_mem:
715 kfree(timer);
716
717err_free_ioregion:
718 release_mem_region(mem->start, resource_size(mem));
719
720 return ret;
721}
722
723/**
724 * omap_dm_timer_remove - cleanup a registered timer device
725 * @pdev: pointer to current timer platform device
726 *
727 * Called by driver framework whenever a timer device is unregistered.
728 * In addition to freeing platform resources it also deletes the timer
729 * entry from the local list.
730 */
731static int __devexit omap_dm_timer_remove(struct platform_device *pdev)
732{
733 struct omap_dm_timer *timer;
734 unsigned long flags;
735 int ret = -EINVAL;
736
737 spin_lock_irqsave(&dm_timer_lock, flags);
738 list_for_each_entry(timer, &omap_timer_list, node)
739 if (timer->pdev->id == pdev->id) {
740 list_del(&timer->node);
741 kfree(timer);
742 ret = 0;
743 break;
744 }
745 spin_unlock_irqrestore(&dm_timer_lock, flags);
746
747 return ret;
748}
749
750static struct platform_driver omap_dm_timer_driver = {
751 .probe = omap_dm_timer_probe,
Arnd Bergmann4c23c8d2011-10-01 18:42:47 +0200752 .remove = __devexit_p(omap_dm_timer_remove),
Tarun Kanti DebBarmadf284722011-09-20 17:00:19 +0530753 .driver = {
754 .name = "omap_timer",
755 },
756};
757
758static int __init omap_dm_timer_driver_init(void)
759{
760 return platform_driver_register(&omap_dm_timer_driver);
761}
762
763static void __exit omap_dm_timer_driver_exit(void)
764{
765 platform_driver_unregister(&omap_dm_timer_driver);
766}
767
768early_platform_init("earlytimer", &omap_dm_timer_driver);
769module_init(omap_dm_timer_driver_init);
770module_exit(omap_dm_timer_driver_exit);
771
772MODULE_DESCRIPTION("OMAP Dual-Mode Timer Driver");
773MODULE_LICENSE("GPL");
774MODULE_ALIAS("platform:" DRIVER_NAME);
775MODULE_AUTHOR("Texas Instruments Inc");