38 #include <linux/module.h>
40 #include <linux/device.h>
47 #include <mach/hardware.h>
49 static u32 omap_reserved_systimers;
65 return __omap_dm_timer_read(timer, reg, timer->
posted);
82 __omap_dm_timer_write(timer, reg, value, timer->
posted);
85 static void omap_timer_restore_context(
struct omap_dm_timer *timer)
106 static void omap_dm_timer_wait_for_reset(
struct omap_dm_timer *timer)
126 if (timer->
pdev->id != 1) {
128 omap_dm_timer_wait_for_reset(timer);
131 __omap_dm_timer_reset(timer, 0, 0);
154 omap_dm_timer_reset(timer);
162 static inline u32 omap_dm_timer_reserved_systimer(
int id)
164 return (omap_reserved_systimers & (1 << (
id - 1))) ? 1 : 0;
169 if (omap_dm_timer_reserved_systimer(
id))
172 omap_reserved_systimers |= (1 << (
id - 1));
192 spin_unlock_irqrestore(&dm_timer_lock, flags);
203 pr_debug(
"%s: timer request failed!\n", __func__);
217 if (t->pdev->id ==
id && !t->reserved) {
223 spin_unlock_irqrestore(&dm_timer_lock, flags);
234 pr_debug(
"%s: timer%d request failed!\n", __func__,
id);
255 pm_runtime_get_sync(&timer->
pdev->dev);
261 pm_runtime_put_sync(&timer->
pdev->dev);
273 #if defined(CONFIG_ARCH_OMAP1)
286 if (!(inputmask & (1 << 1)))
297 inputmask &= ~(1 << 1);
299 inputmask &= ~(1 << 2);
303 spin_unlock_irqrestore(&dm_timer_lock, flags);
331 if (
unlikely(!timer || pm_runtime_suspended(&timer->
pdev->dev))) {
332 pr_err(
"%s: timer not available or enabled.\n", __func__);
353 omap_timer_restore_context(timer);
357 if (!(l & OMAP_TIMER_CTRL_ST)) {
370 unsigned long rate = 0;
378 __omap_dm_timer_stop(timer, timer->
posted, rate);
400 char *parent_name =
NULL;
407 pdata = timer->
pdev->dev.platform_data;
409 if (source < 0 || source >= 3)
421 if (IS_ERR_OR_NULL(fclk)) {
422 pr_err(
"%s: fck not found\n", __func__);
428 parent_name =
"timer_sys_ck";
432 parent_name =
"timer_32k_ck";
436 parent_name =
"timer_ext_ck";
441 if (IS_ERR_OR_NULL(parent)) {
442 pr_err(
"%s: %s not found\n", __func__, parent_name);
449 pr_err(
"%s: failed to set %s as parent\n", __func__,
500 omap_timer_restore_context(timer);
512 __omap_dm_timer_load_start(timer, l, load, timer->
posted);
583 if (prescaler >= 0x00 && prescaler <= 0x07) {
603 __omap_dm_timer_int_enable(timer, value);
617 if (
unlikely(!timer || pm_runtime_suspended(&timer->
pdev->dev))) {
618 pr_err(
"%s: timer not available or enabled.\n", __func__);
630 if (
unlikely(!timer || pm_runtime_suspended(&timer->
pdev->dev)))
633 __omap_dm_timer_write_status(timer, value);
642 if (
unlikely(!timer || pm_runtime_suspended(&timer->
pdev->dev))) {
643 pr_err(
"%s: timer not iavailable or enabled.\n", __func__);
647 return __omap_dm_timer_read_counter(timer, timer->
posted);
653 if (
unlikely(!timer || pm_runtime_suspended(&timer->
pdev->dev))) {
654 pr_err(
"%s: timer not available or enabled.\n", __func__);
675 OMAP_TIMER_CTRL_ST) {
699 dev_err(dev,
"%s: no platform data.\n", __func__);
705 dev_err(dev,
"%s: no IRQ resource.\n", __func__);
711 dev_err(dev,
"%s: no memory resource.\n", __func__);
717 dev_err(dev,
"%s: memory alloc failed!\n", __func__);
723 dev_err(dev,
"%s: region already claimed.\n", __func__);
727 timer->
id = pdev->
id;
729 timer->
reserved = omap_dm_timer_reserved_systimer(timer->
id);
740 pm_runtime_get_sync(dev);
741 __omap_dm_timer_init_regs(timer);
748 spin_unlock_irqrestore(&dm_timer_lock, flags);
750 dev_dbg(dev,
"Device Probed.\n");
771 if (timer->pdev->
id == pdev->
id) {
776 spin_unlock_irqrestore(&dm_timer_lock, flags);
782 .probe = omap_dm_timer_probe,
785 .name =
"omap_timer",
789 static int __init omap_dm_timer_driver_init(
void)
794 static void __exit omap_dm_timer_driver_exit(
void)