2 * linux/arch/arm/plat-omap/dmtimer.c
4 * OMAP Dual-Mode Timers
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>
10 * dmtimer adaptation to platform_driver.
12 * Copyright (C) 2005 Nokia Corporation
13 * OMAP2 support by Juha Yrjola
14 * API improvements and OMAP2 clock framework support by Timo Teras
16 * Copyright (C) 2009 Texas Instruments
17 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
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.
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.
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.
38 #include <linux/clk.h>
39 #include <linux/clk-provider.h>
40 #include <linux/module.h>
42 #include <linux/device.h>
43 #include <linux/err.h>
44 #include <linux/pm_runtime.h>
46 #include <linux/of_device.h>
47 #include <linux/platform_device.h>
48 #include <linux/platform_data/dmtimer-omap.h>
50 #include <plat/dmtimer.h>
52 static u32 omap_reserved_systimers
;
53 static LIST_HEAD(omap_timer_list
);
54 static DEFINE_SPINLOCK(dm_timer_lock
);
64 * omap_dm_timer_read_reg - read timer registers in posted and non-posted mode
65 * @timer: timer pointer over which read operation to perform
66 * @reg: lowest byte holds the register offset
68 * The posted mode bit is encoded in reg. Note that in posted mode write
69 * pending bit must be checked. Otherwise a read of a non completed write
70 * will produce an error.
72 static inline u32
omap_dm_timer_read_reg(struct omap_dm_timer
*timer
, u32 reg
)
74 WARN_ON((reg
& 0xff) < _OMAP_TIMER_WAKEUP_EN_OFFSET
);
75 return __omap_dm_timer_read(timer
, reg
, timer
->posted
);
79 * omap_dm_timer_write_reg - write timer registers in posted and non-posted mode
80 * @timer: timer pointer over which write operation is to perform
81 * @reg: lowest byte holds the register offset
82 * @value: data to write into the register
84 * The posted mode bit is encoded in reg. Note that in posted mode the write
85 * pending bit must be checked. Otherwise a write on a register which has a
86 * pending write will be lost.
88 static void omap_dm_timer_write_reg(struct omap_dm_timer
*timer
, u32 reg
,
91 WARN_ON((reg
& 0xff) < _OMAP_TIMER_WAKEUP_EN_OFFSET
);
92 __omap_dm_timer_write(timer
, reg
, value
, timer
->posted
);
95 static void omap_timer_restore_context(struct omap_dm_timer
*timer
)
97 omap_dm_timer_write_reg(timer
, OMAP_TIMER_WAKEUP_EN_REG
,
99 omap_dm_timer_write_reg(timer
, OMAP_TIMER_COUNTER_REG
,
100 timer
->context
.tcrr
);
101 omap_dm_timer_write_reg(timer
, OMAP_TIMER_LOAD_REG
,
102 timer
->context
.tldr
);
103 omap_dm_timer_write_reg(timer
, OMAP_TIMER_MATCH_REG
,
104 timer
->context
.tmar
);
105 omap_dm_timer_write_reg(timer
, OMAP_TIMER_IF_CTRL_REG
,
106 timer
->context
.tsicr
);
107 writel_relaxed(timer
->context
.tier
, timer
->irq_ena
);
108 omap_dm_timer_write_reg(timer
, OMAP_TIMER_CTRL_REG
,
109 timer
->context
.tclr
);
112 static int omap_dm_timer_reset(struct omap_dm_timer
*timer
)
114 u32 l
, timeout
= 100000;
116 if (timer
->revision
!= 1)
119 omap_dm_timer_write_reg(timer
, OMAP_TIMER_IF_CTRL_REG
, 0x06);
122 l
= __omap_dm_timer_read(timer
,
123 OMAP_TIMER_V1_SYS_STAT_OFFSET
, 0);
124 } while (!l
&& timeout
--);
127 dev_err(&timer
->pdev
->dev
, "Timer failed to reset\n");
131 /* Configure timer for smart-idle mode */
132 l
= __omap_dm_timer_read(timer
, OMAP_TIMER_OCP_CFG_OFFSET
, 0);
134 __omap_dm_timer_write(timer
, OMAP_TIMER_OCP_CFG_OFFSET
, l
, 0);
141 static int omap_dm_timer_of_set_source(struct omap_dm_timer
*timer
)
147 * FIXME: OMAP1 devices do not use the clock framework for dmtimers so
148 * do not call clk_get() for these devices.
153 parent
= clk_get(&timer
->pdev
->dev
, NULL
);
157 ret
= clk_set_parent(timer
->fclk
, parent
);
159 pr_err("%s: failed to set parent\n", __func__
);
166 static int omap_dm_timer_prepare(struct omap_dm_timer
*timer
)
171 * FIXME: OMAP1 devices do not use the clock framework for dmtimers so
172 * do not call clk_get() for these devices.
174 if (!(timer
->capability
& OMAP_TIMER_NEEDS_RESET
)) {
175 timer
->fclk
= clk_get(&timer
->pdev
->dev
, "fck");
176 if (WARN_ON_ONCE(IS_ERR(timer
->fclk
))) {
177 dev_err(&timer
->pdev
->dev
, ": No fclk handle.\n");
182 omap_dm_timer_enable(timer
);
184 if (timer
->capability
& OMAP_TIMER_NEEDS_RESET
) {
185 rc
= omap_dm_timer_reset(timer
);
187 omap_dm_timer_disable(timer
);
192 __omap_dm_timer_enable_posted(timer
);
193 omap_dm_timer_disable(timer
);
195 rc
= omap_dm_timer_of_set_source(timer
);
197 return omap_dm_timer_set_source(timer
, OMAP_TIMER_SRC_32_KHZ
);
202 static inline u32
omap_dm_timer_reserved_systimer(int id
)
204 return (omap_reserved_systimers
& (1 << (id
- 1))) ? 1 : 0;
207 int omap_dm_timer_reserve_systimer(int id
)
209 if (omap_dm_timer_reserved_systimer(id
))
212 omap_reserved_systimers
|= (1 << (id
- 1));
217 static struct omap_dm_timer
*_omap_dm_timer_request(int req_type
, void *data
)
219 struct omap_dm_timer
*timer
= NULL
, *t
;
220 struct device_node
*np
= NULL
;
232 case REQUEST_BY_NODE
:
233 np
= (struct device_node
*)data
;
240 spin_lock_irqsave(&dm_timer_lock
, flags
);
241 list_for_each_entry(t
, &omap_timer_list
, node
) {
247 if (id
== t
->pdev
->id
) {
254 if (cap
== (t
->capability
& cap
)) {
256 * If timer is not NULL, we have already found
257 * one timer but it was not an exact match
258 * because it had more capabilites that what
259 * was required. Therefore, unreserve the last
260 * timer found and see if this one is a better
268 /* Exit loop early if we find an exact match */
269 if (t
->capability
== cap
)
273 case REQUEST_BY_NODE
:
274 if (np
== t
->pdev
->dev
.of_node
) {
288 spin_unlock_irqrestore(&dm_timer_lock
, flags
);
290 if (timer
&& omap_dm_timer_prepare(timer
)) {
296 pr_debug("%s: timer request failed!\n", __func__
);
301 struct omap_dm_timer
*omap_dm_timer_request(void)
303 return _omap_dm_timer_request(REQUEST_ANY
, NULL
);
305 EXPORT_SYMBOL_GPL(omap_dm_timer_request
);
307 struct omap_dm_timer
*omap_dm_timer_request_specific(int id
)
309 /* Requesting timer by ID is not supported when device tree is used */
310 if (of_have_populated_dt()) {
311 pr_warn("%s: Please use omap_dm_timer_request_by_cap/node()\n",
316 return _omap_dm_timer_request(REQUEST_BY_ID
, &id
);
318 EXPORT_SYMBOL_GPL(omap_dm_timer_request_specific
);
321 * omap_dm_timer_request_by_cap - Request a timer by capability
322 * @cap: Bit mask of capabilities to match
324 * Find a timer based upon capabilities bit mask. Callers of this function
325 * should use the definitions found in the plat/dmtimer.h file under the
326 * comment "timer capabilities used in hwmod database". Returns pointer to
327 * timer handle on success and a NULL pointer on failure.
329 struct omap_dm_timer
*omap_dm_timer_request_by_cap(u32 cap
)
331 return _omap_dm_timer_request(REQUEST_BY_CAP
, &cap
);
333 EXPORT_SYMBOL_GPL(omap_dm_timer_request_by_cap
);
336 * omap_dm_timer_request_by_node - Request a timer by device-tree node
337 * @np: Pointer to device-tree timer node
339 * Request a timer based upon a device node pointer. Returns pointer to
340 * timer handle on success and a NULL pointer on failure.
342 struct omap_dm_timer
*omap_dm_timer_request_by_node(struct device_node
*np
)
347 return _omap_dm_timer_request(REQUEST_BY_NODE
, np
);
349 EXPORT_SYMBOL_GPL(omap_dm_timer_request_by_node
);
351 int omap_dm_timer_free(struct omap_dm_timer
*timer
)
353 if (unlikely(!timer
))
356 clk_put(timer
->fclk
);
358 WARN_ON(!timer
->reserved
);
362 EXPORT_SYMBOL_GPL(omap_dm_timer_free
);
364 void omap_dm_timer_enable(struct omap_dm_timer
*timer
)
368 pm_runtime_get_sync(&timer
->pdev
->dev
);
370 if (!(timer
->capability
& OMAP_TIMER_ALWON
)) {
371 if (timer
->get_context_loss_count
) {
372 c
= timer
->get_context_loss_count(&timer
->pdev
->dev
);
373 if (c
!= timer
->ctx_loss_count
) {
374 omap_timer_restore_context(timer
);
375 timer
->ctx_loss_count
= c
;
378 omap_timer_restore_context(timer
);
382 EXPORT_SYMBOL_GPL(omap_dm_timer_enable
);
384 void omap_dm_timer_disable(struct omap_dm_timer
*timer
)
386 pm_runtime_put_sync(&timer
->pdev
->dev
);
388 EXPORT_SYMBOL_GPL(omap_dm_timer_disable
);
390 int omap_dm_timer_get_irq(struct omap_dm_timer
*timer
)
396 EXPORT_SYMBOL_GPL(omap_dm_timer_get_irq
);
398 #if defined(CONFIG_ARCH_OMAP1)
399 #include <mach/hardware.h>
401 * omap_dm_timer_modify_idlect_mask - Check if any running timers use ARMXOR
402 * @inputmask: current value of idlect mask
404 __u32
omap_dm_timer_modify_idlect_mask(__u32 inputmask
)
407 struct omap_dm_timer
*timer
= NULL
;
410 /* If ARMXOR cannot be idled this function call is unnecessary */
411 if (!(inputmask
& (1 << 1)))
414 /* If any active timer is using ARMXOR return modified mask */
415 spin_lock_irqsave(&dm_timer_lock
, flags
);
416 list_for_each_entry(timer
, &omap_timer_list
, node
) {
419 l
= omap_dm_timer_read_reg(timer
, OMAP_TIMER_CTRL_REG
);
420 if (l
& OMAP_TIMER_CTRL_ST
) {
421 if (((omap_readl(MOD_CONF_CTRL_1
) >> (i
* 2)) & 0x03) == 0)
422 inputmask
&= ~(1 << 1);
424 inputmask
&= ~(1 << 2);
428 spin_unlock_irqrestore(&dm_timer_lock
, flags
);
432 EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask
);
436 struct clk
*omap_dm_timer_get_fclk(struct omap_dm_timer
*timer
)
438 if (timer
&& !IS_ERR(timer
->fclk
))
442 EXPORT_SYMBOL_GPL(omap_dm_timer_get_fclk
);
444 __u32
omap_dm_timer_modify_idlect_mask(__u32 inputmask
)
450 EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask
);
454 int omap_dm_timer_trigger(struct omap_dm_timer
*timer
)
456 if (unlikely(!timer
|| pm_runtime_suspended(&timer
->pdev
->dev
))) {
457 pr_err("%s: timer not available or enabled.\n", __func__
);
461 omap_dm_timer_write_reg(timer
, OMAP_TIMER_TRIGGER_REG
, 0);
464 EXPORT_SYMBOL_GPL(omap_dm_timer_trigger
);
466 int omap_dm_timer_start(struct omap_dm_timer
*timer
)
470 if (unlikely(!timer
))
473 omap_dm_timer_enable(timer
);
475 l
= omap_dm_timer_read_reg(timer
, OMAP_TIMER_CTRL_REG
);
476 if (!(l
& OMAP_TIMER_CTRL_ST
)) {
477 l
|= OMAP_TIMER_CTRL_ST
;
478 omap_dm_timer_write_reg(timer
, OMAP_TIMER_CTRL_REG
, l
);
481 /* Save the context */
482 timer
->context
.tclr
= l
;
485 EXPORT_SYMBOL_GPL(omap_dm_timer_start
);
487 int omap_dm_timer_stop(struct omap_dm_timer
*timer
)
489 unsigned long rate
= 0;
491 if (unlikely(!timer
))
494 if (!(timer
->capability
& OMAP_TIMER_NEEDS_RESET
))
495 rate
= clk_get_rate(timer
->fclk
);
497 __omap_dm_timer_stop(timer
, timer
->posted
, rate
);
500 * Since the register values are computed and written within
501 * __omap_dm_timer_stop, we need to use read to retrieve the
504 timer
->context
.tclr
=
505 omap_dm_timer_read_reg(timer
, OMAP_TIMER_CTRL_REG
);
506 omap_dm_timer_disable(timer
);
509 EXPORT_SYMBOL_GPL(omap_dm_timer_stop
);
511 int omap_dm_timer_set_source(struct omap_dm_timer
*timer
, int source
)
514 char *parent_name
= NULL
;
516 struct dmtimer_platform_data
*pdata
;
518 if (unlikely(!timer
))
521 pdata
= timer
->pdev
->dev
.platform_data
;
523 if (source
< 0 || source
>= 3)
527 * FIXME: Used for OMAP1 devices only because they do not currently
528 * use the clock framework to set the parent clock. To be removed
529 * once OMAP1 migrated to using clock framework for dmtimers
531 if (pdata
&& pdata
->set_timer_src
)
532 return pdata
->set_timer_src(timer
->pdev
, source
);
534 if (IS_ERR(timer
->fclk
))
537 #if defined(CONFIG_COMMON_CLK)
538 /* Check if the clock has configurable parents */
539 if (clk_hw_get_num_parents(__clk_get_hw(timer
->fclk
)) < 2)
544 case OMAP_TIMER_SRC_SYS_CLK
:
545 parent_name
= "timer_sys_ck";
548 case OMAP_TIMER_SRC_32_KHZ
:
549 parent_name
= "timer_32k_ck";
552 case OMAP_TIMER_SRC_EXT_CLK
:
553 parent_name
= "timer_ext_ck";
557 parent
= clk_get(&timer
->pdev
->dev
, parent_name
);
558 if (IS_ERR(parent
)) {
559 pr_err("%s: %s not found\n", __func__
, parent_name
);
563 ret
= clk_set_parent(timer
->fclk
, parent
);
565 pr_err("%s: failed to set %s as parent\n", __func__
,
572 EXPORT_SYMBOL_GPL(omap_dm_timer_set_source
);
574 int omap_dm_timer_set_load(struct omap_dm_timer
*timer
, int autoreload
,
579 if (unlikely(!timer
))
582 omap_dm_timer_enable(timer
);
583 l
= omap_dm_timer_read_reg(timer
, OMAP_TIMER_CTRL_REG
);
585 l
|= OMAP_TIMER_CTRL_AR
;
587 l
&= ~OMAP_TIMER_CTRL_AR
;
588 omap_dm_timer_write_reg(timer
, OMAP_TIMER_CTRL_REG
, l
);
589 omap_dm_timer_write_reg(timer
, OMAP_TIMER_LOAD_REG
, load
);
591 omap_dm_timer_write_reg(timer
, OMAP_TIMER_TRIGGER_REG
, 0);
592 /* Save the context */
593 timer
->context
.tclr
= l
;
594 timer
->context
.tldr
= load
;
595 omap_dm_timer_disable(timer
);
598 EXPORT_SYMBOL_GPL(omap_dm_timer_set_load
);
600 /* Optimized set_load which removes costly spin wait in timer_start */
601 int omap_dm_timer_set_load_start(struct omap_dm_timer
*timer
, int autoreload
,
606 if (unlikely(!timer
))
609 omap_dm_timer_enable(timer
);
611 l
= omap_dm_timer_read_reg(timer
, OMAP_TIMER_CTRL_REG
);
613 l
|= OMAP_TIMER_CTRL_AR
;
614 omap_dm_timer_write_reg(timer
, OMAP_TIMER_LOAD_REG
, load
);
616 l
&= ~OMAP_TIMER_CTRL_AR
;
618 l
|= OMAP_TIMER_CTRL_ST
;
620 __omap_dm_timer_load_start(timer
, l
, load
, timer
->posted
);
622 /* Save the context */
623 timer
->context
.tclr
= l
;
624 timer
->context
.tldr
= load
;
625 timer
->context
.tcrr
= load
;
628 EXPORT_SYMBOL_GPL(omap_dm_timer_set_load_start
);
630 int omap_dm_timer_set_match(struct omap_dm_timer
*timer
, int enable
,
635 if (unlikely(!timer
))
638 omap_dm_timer_enable(timer
);
639 l
= omap_dm_timer_read_reg(timer
, OMAP_TIMER_CTRL_REG
);
641 l
|= OMAP_TIMER_CTRL_CE
;
643 l
&= ~OMAP_TIMER_CTRL_CE
;
644 omap_dm_timer_write_reg(timer
, OMAP_TIMER_MATCH_REG
, match
);
645 omap_dm_timer_write_reg(timer
, OMAP_TIMER_CTRL_REG
, l
);
647 /* Save the context */
648 timer
->context
.tclr
= l
;
649 timer
->context
.tmar
= match
;
650 omap_dm_timer_disable(timer
);
653 EXPORT_SYMBOL_GPL(omap_dm_timer_set_match
);
655 int omap_dm_timer_set_pwm(struct omap_dm_timer
*timer
, int def_on
,
656 int toggle
, int trigger
)
660 if (unlikely(!timer
))
663 omap_dm_timer_enable(timer
);
664 l
= omap_dm_timer_read_reg(timer
, OMAP_TIMER_CTRL_REG
);
665 l
&= ~(OMAP_TIMER_CTRL_GPOCFG
| OMAP_TIMER_CTRL_SCPWM
|
666 OMAP_TIMER_CTRL_PT
| (0x03 << 10));
668 l
|= OMAP_TIMER_CTRL_SCPWM
;
670 l
|= OMAP_TIMER_CTRL_PT
;
672 omap_dm_timer_write_reg(timer
, OMAP_TIMER_CTRL_REG
, l
);
674 /* Save the context */
675 timer
->context
.tclr
= l
;
676 omap_dm_timer_disable(timer
);
679 EXPORT_SYMBOL_GPL(omap_dm_timer_set_pwm
);
681 int omap_dm_timer_set_prescaler(struct omap_dm_timer
*timer
, int prescaler
)
685 if (unlikely(!timer
))
688 omap_dm_timer_enable(timer
);
689 l
= omap_dm_timer_read_reg(timer
, OMAP_TIMER_CTRL_REG
);
690 l
&= ~(OMAP_TIMER_CTRL_PRE
| (0x07 << 2));
691 if (prescaler
>= 0x00 && prescaler
<= 0x07) {
692 l
|= OMAP_TIMER_CTRL_PRE
;
695 omap_dm_timer_write_reg(timer
, OMAP_TIMER_CTRL_REG
, l
);
697 /* Save the context */
698 timer
->context
.tclr
= l
;
699 omap_dm_timer_disable(timer
);
702 EXPORT_SYMBOL_GPL(omap_dm_timer_set_prescaler
);
704 int omap_dm_timer_set_int_enable(struct omap_dm_timer
*timer
,
707 if (unlikely(!timer
))
710 omap_dm_timer_enable(timer
);
711 __omap_dm_timer_int_enable(timer
, value
);
713 /* Save the context */
714 timer
->context
.tier
= value
;
715 timer
->context
.twer
= value
;
716 omap_dm_timer_disable(timer
);
719 EXPORT_SYMBOL_GPL(omap_dm_timer_set_int_enable
);
722 * omap_dm_timer_set_int_disable - disable timer interrupts
723 * @timer: pointer to timer handle
724 * @mask: bit mask of interrupts to be disabled
726 * Disables the specified timer interrupts for a timer.
728 int omap_dm_timer_set_int_disable(struct omap_dm_timer
*timer
, u32 mask
)
732 if (unlikely(!timer
))
735 omap_dm_timer_enable(timer
);
737 if (timer
->revision
== 1)
738 l
= readl_relaxed(timer
->irq_ena
) & ~mask
;
740 writel_relaxed(l
, timer
->irq_dis
);
741 l
= omap_dm_timer_read_reg(timer
, OMAP_TIMER_WAKEUP_EN_REG
) & ~mask
;
742 omap_dm_timer_write_reg(timer
, OMAP_TIMER_WAKEUP_EN_REG
, l
);
744 /* Save the context */
745 timer
->context
.tier
&= ~mask
;
746 timer
->context
.twer
&= ~mask
;
747 omap_dm_timer_disable(timer
);
750 EXPORT_SYMBOL_GPL(omap_dm_timer_set_int_disable
);
752 unsigned int omap_dm_timer_read_status(struct omap_dm_timer
*timer
)
756 if (unlikely(!timer
|| pm_runtime_suspended(&timer
->pdev
->dev
))) {
757 pr_err("%s: timer not available or enabled.\n", __func__
);
761 l
= readl_relaxed(timer
->irq_stat
);
765 EXPORT_SYMBOL_GPL(omap_dm_timer_read_status
);
767 int omap_dm_timer_write_status(struct omap_dm_timer
*timer
, unsigned int value
)
769 if (unlikely(!timer
|| pm_runtime_suspended(&timer
->pdev
->dev
)))
772 __omap_dm_timer_write_status(timer
, value
);
776 EXPORT_SYMBOL_GPL(omap_dm_timer_write_status
);
778 unsigned int omap_dm_timer_read_counter(struct omap_dm_timer
*timer
)
780 if (unlikely(!timer
|| pm_runtime_suspended(&timer
->pdev
->dev
))) {
781 pr_err("%s: timer not iavailable or enabled.\n", __func__
);
785 return __omap_dm_timer_read_counter(timer
, timer
->posted
);
787 EXPORT_SYMBOL_GPL(omap_dm_timer_read_counter
);
789 int omap_dm_timer_write_counter(struct omap_dm_timer
*timer
, unsigned int value
)
791 if (unlikely(!timer
|| pm_runtime_suspended(&timer
->pdev
->dev
))) {
792 pr_err("%s: timer not available or enabled.\n", __func__
);
796 omap_dm_timer_write_reg(timer
, OMAP_TIMER_COUNTER_REG
, value
);
798 /* Save the context */
799 timer
->context
.tcrr
= value
;
802 EXPORT_SYMBOL_GPL(omap_dm_timer_write_counter
);
804 int omap_dm_timers_active(void)
806 struct omap_dm_timer
*timer
;
808 list_for_each_entry(timer
, &omap_timer_list
, node
) {
809 if (!timer
->reserved
)
812 if (omap_dm_timer_read_reg(timer
, OMAP_TIMER_CTRL_REG
) &
813 OMAP_TIMER_CTRL_ST
) {
819 EXPORT_SYMBOL_GPL(omap_dm_timers_active
);
821 static const struct of_device_id omap_timer_match
[];
824 * omap_dm_timer_probe - probe function called for every registered device
825 * @pdev: pointer to current timer platform device
827 * Called by driver framework at the end of device registration for all
830 static int omap_dm_timer_probe(struct platform_device
*pdev
)
833 struct omap_dm_timer
*timer
;
834 struct resource
*mem
, *irq
;
835 struct device
*dev
= &pdev
->dev
;
836 const struct of_device_id
*match
;
837 const struct dmtimer_platform_data
*pdata
;
840 match
= of_match_device(of_match_ptr(omap_timer_match
), dev
);
841 pdata
= match
? match
->data
: dev
->platform_data
;
843 if (!pdata
&& !dev
->of_node
) {
844 dev_err(dev
, "%s: no platform data.\n", __func__
);
848 irq
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
849 if (unlikely(!irq
)) {
850 dev_err(dev
, "%s: no IRQ resource.\n", __func__
);
854 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
855 if (unlikely(!mem
)) {
856 dev_err(dev
, "%s: no memory resource.\n", __func__
);
860 timer
= devm_kzalloc(dev
, sizeof(struct omap_dm_timer
), GFP_KERNEL
);
862 dev_err(dev
, "%s: memory alloc failed!\n", __func__
);
866 timer
->fclk
= ERR_PTR(-ENODEV
);
867 timer
->io_base
= devm_ioremap_resource(dev
, mem
);
868 if (IS_ERR(timer
->io_base
))
869 return PTR_ERR(timer
->io_base
);
872 if (of_find_property(dev
->of_node
, "ti,timer-alwon", NULL
))
873 timer
->capability
|= OMAP_TIMER_ALWON
;
874 if (of_find_property(dev
->of_node
, "ti,timer-dsp", NULL
))
875 timer
->capability
|= OMAP_TIMER_HAS_DSP_IRQ
;
876 if (of_find_property(dev
->of_node
, "ti,timer-pwm", NULL
))
877 timer
->capability
|= OMAP_TIMER_HAS_PWM
;
878 if (of_find_property(dev
->of_node
, "ti,timer-secure", NULL
))
879 timer
->capability
|= OMAP_TIMER_SECURE
;
881 timer
->id
= pdev
->id
;
882 timer
->capability
= pdata
->timer_capability
;
883 timer
->reserved
= omap_dm_timer_reserved_systimer(timer
->id
);
884 timer
->get_context_loss_count
= pdata
->get_context_loss_count
;
888 timer
->errata
= pdata
->timer_errata
;
890 timer
->irq
= irq
->start
;
893 /* Skip pm_runtime_enable for OMAP1 */
894 if (!(timer
->capability
& OMAP_TIMER_NEEDS_RESET
)) {
895 pm_runtime_enable(dev
);
896 pm_runtime_irq_safe(dev
);
899 if (!timer
->reserved
) {
900 ret
= pm_runtime_get_sync(dev
);
902 dev_err(dev
, "%s: pm_runtime_get_sync failed!\n",
906 __omap_dm_timer_init_regs(timer
);
910 /* add the timer element to the list */
911 spin_lock_irqsave(&dm_timer_lock
, flags
);
912 list_add_tail(&timer
->node
, &omap_timer_list
);
913 spin_unlock_irqrestore(&dm_timer_lock
, flags
);
915 dev_dbg(dev
, "Device Probed.\n");
920 pm_runtime_put_noidle(dev
);
921 pm_runtime_disable(dev
);
926 * omap_dm_timer_remove - cleanup a registered timer device
927 * @pdev: pointer to current timer platform device
929 * Called by driver framework whenever a timer device is unregistered.
930 * In addition to freeing platform resources it also deletes the timer
931 * entry from the local list.
933 static int omap_dm_timer_remove(struct platform_device
*pdev
)
935 struct omap_dm_timer
*timer
;
939 spin_lock_irqsave(&dm_timer_lock
, flags
);
940 list_for_each_entry(timer
, &omap_timer_list
, node
)
941 if (!strcmp(dev_name(&timer
->pdev
->dev
),
942 dev_name(&pdev
->dev
))) {
943 list_del(&timer
->node
);
947 spin_unlock_irqrestore(&dm_timer_lock
, flags
);
949 pm_runtime_disable(&pdev
->dev
);
954 static const struct dmtimer_platform_data omap3plus_pdata
= {
955 .timer_errata
= OMAP_TIMER_ERRATA_I103_I767
,
958 static const struct of_device_id omap_timer_match
[] = {
960 .compatible
= "ti,omap2420-timer",
963 .compatible
= "ti,omap3430-timer",
964 .data
= &omap3plus_pdata
,
967 .compatible
= "ti,omap4430-timer",
968 .data
= &omap3plus_pdata
,
971 .compatible
= "ti,omap5430-timer",
972 .data
= &omap3plus_pdata
,
975 .compatible
= "ti,am335x-timer",
976 .data
= &omap3plus_pdata
,
979 .compatible
= "ti,am335x-timer-1ms",
980 .data
= &omap3plus_pdata
,
983 .compatible
= "ti,dm816-timer",
984 .data
= &omap3plus_pdata
,
988 MODULE_DEVICE_TABLE(of
, omap_timer_match
);
990 static struct platform_driver omap_dm_timer_driver
= {
991 .probe
= omap_dm_timer_probe
,
992 .remove
= omap_dm_timer_remove
,
994 .name
= "omap_timer",
995 .of_match_table
= of_match_ptr(omap_timer_match
),
999 early_platform_init("earlytimer", &omap_dm_timer_driver
);
1000 module_platform_driver(omap_dm_timer_driver
);
1002 MODULE_DESCRIPTION("OMAP Dual-Mode Timer Driver");
1003 MODULE_LICENSE("GPL");
1004 MODULE_ALIAS("platform:" DRIVER_NAME
);
1005 MODULE_AUTHOR("Texas Instruments Inc");