Lines Matching refs:timer
166 static inline u32 dmtimer_read(struct dmtimer *timer, u32 reg) in dmtimer_read() argument
174 if (wp && timer->posted) in dmtimer_read()
175 while (readl_relaxed(timer->pend) & wp) in dmtimer_read()
178 return readl_relaxed(timer->func_base + offset); in dmtimer_read()
191 static inline void dmtimer_write(struct dmtimer *timer, u32 reg, u32 val) in dmtimer_write() argument
199 if (wp && timer->posted) in dmtimer_write()
200 while (readl_relaxed(timer->pend) & wp) in dmtimer_write()
203 writel_relaxed(val, timer->func_base + offset); in dmtimer_write()
206 static inline void __omap_dm_timer_init_regs(struct dmtimer *timer) in __omap_dm_timer_init_regs() argument
211 tidr = readl_relaxed(timer->io_base); in __omap_dm_timer_init_regs()
213 timer->revision = 1; in __omap_dm_timer_init_regs()
214 timer->irq_stat = OMAP_TIMER_V1_STAT_OFFSET; in __omap_dm_timer_init_regs()
215 timer->irq_ena = OMAP_TIMER_V1_INT_EN_OFFSET; in __omap_dm_timer_init_regs()
216 timer->irq_dis = OMAP_TIMER_V1_INT_EN_OFFSET; in __omap_dm_timer_init_regs()
217 timer->pend = timer->io_base + _OMAP_TIMER_WRITE_PEND_OFFSET; in __omap_dm_timer_init_regs()
218 timer->func_base = timer->io_base; in __omap_dm_timer_init_regs()
220 timer->revision = 2; in __omap_dm_timer_init_regs()
221 timer->irq_stat = OMAP_TIMER_V2_IRQSTATUS - OMAP_TIMER_V2_FUNC_OFFSET; in __omap_dm_timer_init_regs()
222 timer->irq_ena = OMAP_TIMER_V2_IRQENABLE_SET - OMAP_TIMER_V2_FUNC_OFFSET; in __omap_dm_timer_init_regs()
223 timer->irq_dis = OMAP_TIMER_V2_IRQENABLE_CLR - OMAP_TIMER_V2_FUNC_OFFSET; in __omap_dm_timer_init_regs()
224 timer->pend = timer->io_base + in __omap_dm_timer_init_regs()
227 timer->func_base = timer->io_base + OMAP_TIMER_V2_FUNC_OFFSET; in __omap_dm_timer_init_regs()
241 static inline void __omap_dm_timer_enable_posted(struct dmtimer *timer) in __omap_dm_timer_enable_posted() argument
243 if (timer->posted) in __omap_dm_timer_enable_posted()
246 if (timer->errata & OMAP_TIMER_ERRATA_I103_I767) { in __omap_dm_timer_enable_posted()
247 timer->posted = OMAP_TIMER_NONPOSTED; in __omap_dm_timer_enable_posted()
248 dmtimer_write(timer, OMAP_TIMER_IF_CTRL_REG, 0); in __omap_dm_timer_enable_posted()
252 dmtimer_write(timer, OMAP_TIMER_IF_CTRL_REG, OMAP_TIMER_CTRL_POSTED); in __omap_dm_timer_enable_posted()
253 timer->context.tsicr = OMAP_TIMER_CTRL_POSTED; in __omap_dm_timer_enable_posted()
254 timer->posted = OMAP_TIMER_POSTED; in __omap_dm_timer_enable_posted()
257 static inline void __omap_dm_timer_stop(struct dmtimer *timer) in __omap_dm_timer_stop() argument
261 l = dmtimer_read(timer, OMAP_TIMER_CTRL_REG); in __omap_dm_timer_stop()
264 dmtimer_write(timer, OMAP_TIMER_CTRL_REG, l); in __omap_dm_timer_stop()
267 dmtimer_read(timer, OMAP_TIMER_CTRL_REG); in __omap_dm_timer_stop()
272 udelay(3500000 / timer->fclk_rate + 1); in __omap_dm_timer_stop()
277 dmtimer_write(timer, timer->irq_stat, OMAP_TIMER_INT_OVERFLOW); in __omap_dm_timer_stop()
280 static inline void __omap_dm_timer_int_enable(struct dmtimer *timer, in __omap_dm_timer_int_enable() argument
283 dmtimer_write(timer, timer->irq_ena, value); in __omap_dm_timer_int_enable()
284 dmtimer_write(timer, OMAP_TIMER_WAKEUP_EN_REG, value); in __omap_dm_timer_int_enable()
288 __omap_dm_timer_read_counter(struct dmtimer *timer) in __omap_dm_timer_read_counter() argument
290 return dmtimer_read(timer, OMAP_TIMER_COUNTER_REG); in __omap_dm_timer_read_counter()
293 static inline void __omap_dm_timer_write_status(struct dmtimer *timer, in __omap_dm_timer_write_status() argument
296 dmtimer_write(timer, timer->irq_stat, value); in __omap_dm_timer_write_status()
299 static void omap_timer_restore_context(struct dmtimer *timer) in omap_timer_restore_context() argument
301 dmtimer_write(timer, OMAP_TIMER_OCP_CFG_OFFSET, timer->context.ocp_cfg); in omap_timer_restore_context()
303 dmtimer_write(timer, OMAP_TIMER_WAKEUP_EN_REG, timer->context.twer); in omap_timer_restore_context()
304 dmtimer_write(timer, OMAP_TIMER_COUNTER_REG, timer->context.tcrr); in omap_timer_restore_context()
305 dmtimer_write(timer, OMAP_TIMER_LOAD_REG, timer->context.tldr); in omap_timer_restore_context()
306 dmtimer_write(timer, OMAP_TIMER_MATCH_REG, timer->context.tmar); in omap_timer_restore_context()
307 dmtimer_write(timer, OMAP_TIMER_IF_CTRL_REG, timer->context.tsicr); in omap_timer_restore_context()
308 dmtimer_write(timer, timer->irq_ena, timer->context.tier); in omap_timer_restore_context()
309 dmtimer_write(timer, OMAP_TIMER_CTRL_REG, timer->context.tclr); in omap_timer_restore_context()
312 static void omap_timer_save_context(struct dmtimer *timer) in omap_timer_save_context() argument
314 timer->context.ocp_cfg = dmtimer_read(timer, OMAP_TIMER_OCP_CFG_OFFSET); in omap_timer_save_context()
316 timer->context.tclr = dmtimer_read(timer, OMAP_TIMER_CTRL_REG); in omap_timer_save_context()
317 timer->context.twer = dmtimer_read(timer, OMAP_TIMER_WAKEUP_EN_REG); in omap_timer_save_context()
318 timer->context.tldr = dmtimer_read(timer, OMAP_TIMER_LOAD_REG); in omap_timer_save_context()
319 timer->context.tmar = dmtimer_read(timer, OMAP_TIMER_MATCH_REG); in omap_timer_save_context()
320 timer->context.tier = dmtimer_read(timer, timer->irq_ena); in omap_timer_save_context()
321 timer->context.tsicr = dmtimer_read(timer, OMAP_TIMER_IF_CTRL_REG); in omap_timer_save_context()
327 struct dmtimer *timer; in omap_timer_context_notifier() local
329 timer = container_of(nb, struct dmtimer, nb); in omap_timer_context_notifier()
333 if ((timer->capability & OMAP_TIMER_ALWON) || in omap_timer_context_notifier()
334 !atomic_read(&timer->enabled)) in omap_timer_context_notifier()
336 omap_timer_save_context(timer); in omap_timer_context_notifier()
341 if ((timer->capability & OMAP_TIMER_ALWON) || in omap_timer_context_notifier()
342 !atomic_read(&timer->enabled)) in omap_timer_context_notifier()
344 omap_timer_restore_context(timer); in omap_timer_context_notifier()
355 struct dmtimer *timer = container_of(nb, struct dmtimer, fclk_nb); in omap_timer_fclk_notifier() local
359 timer->fclk_rate = clk_data->new_rate; in omap_timer_fclk_notifier()
366 static int omap_dm_timer_reset(struct dmtimer *timer) in omap_dm_timer_reset() argument
370 if (timer->revision != 1) in omap_dm_timer_reset()
373 dmtimer_write(timer, OMAP_TIMER_IF_CTRL_REG, 0x06); in omap_dm_timer_reset()
376 l = dmtimer_read(timer, OMAP_TIMER_V1_SYS_STAT_OFFSET); in omap_dm_timer_reset()
380 dev_err(&timer->pdev->dev, "Timer failed to reset\n"); in omap_dm_timer_reset()
385 l = dmtimer_read(timer, OMAP_TIMER_OCP_CFG_OFFSET); in omap_dm_timer_reset()
387 dmtimer_write(timer, OMAP_TIMER_OCP_CFG_OFFSET, l); in omap_dm_timer_reset()
389 timer->posted = 0; in omap_dm_timer_reset()
414 struct dmtimer *timer; in omap_dm_timer_set_source() local
416 timer = to_dmtimer(cookie); in omap_dm_timer_set_source()
417 if (unlikely(!timer) || IS_ERR(timer->fclk)) in omap_dm_timer_set_source()
434 pdata = timer->pdev->dev.platform_data; in omap_dm_timer_set_source()
441 if (timer->omap1 && pdata && pdata->set_timer_src) in omap_dm_timer_set_source()
442 return pdata->set_timer_src(timer->pdev, source); in omap_dm_timer_set_source()
446 if (clk_hw_get_num_parents(__clk_get_hw(timer->fclk)) < 2) in omap_dm_timer_set_source()
450 parent = clk_get(&timer->pdev->dev, parent_name); in omap_dm_timer_set_source()
456 ret = clk_set_parent(timer->fclk, parent); in omap_dm_timer_set_source()
468 struct dmtimer *timer = to_dmtimer(cookie); in omap_dm_timer_enable() local
469 struct device *dev = &timer->pdev->dev; in omap_dm_timer_enable()
479 struct dmtimer *timer = to_dmtimer(cookie); in omap_dm_timer_disable() local
480 struct device *dev = &timer->pdev->dev; in omap_dm_timer_disable()
485 static int omap_dm_timer_prepare(struct dmtimer *timer) in omap_dm_timer_prepare() argument
487 struct device *dev = &timer->pdev->dev; in omap_dm_timer_prepare()
494 if (timer->capability & OMAP_TIMER_NEEDS_RESET) { in omap_dm_timer_prepare()
495 rc = omap_dm_timer_reset(timer); in omap_dm_timer_prepare()
502 __omap_dm_timer_enable_posted(timer); in omap_dm_timer_prepare()
515 struct dmtimer *timer = NULL, *t; in _omap_dm_timer_request() local
544 timer = t; in _omap_dm_timer_request()
545 timer->reserved = 1; in _omap_dm_timer_request()
559 if (timer) in _omap_dm_timer_request()
560 timer->reserved = 0; in _omap_dm_timer_request()
561 timer = t; in _omap_dm_timer_request()
562 timer->reserved = 1; in _omap_dm_timer_request()
571 timer = t; in _omap_dm_timer_request()
572 timer->reserved = 1; in _omap_dm_timer_request()
578 timer = t; in _omap_dm_timer_request()
579 timer->reserved = 1; in _omap_dm_timer_request()
586 if (timer && omap_dm_timer_prepare(timer)) { in _omap_dm_timer_request()
587 timer->reserved = 0; in _omap_dm_timer_request()
588 timer = NULL; in _omap_dm_timer_request()
591 if (!timer) in _omap_dm_timer_request()
594 return timer; in _omap_dm_timer_request()
599 struct dmtimer *timer; in omap_dm_timer_request() local
601 timer = _omap_dm_timer_request(REQUEST_ANY, NULL); in omap_dm_timer_request()
602 if (!timer) in omap_dm_timer_request()
605 return &timer->cookie; in omap_dm_timer_request()
610 struct dmtimer *timer; in omap_dm_timer_request_specific() local
619 timer = _omap_dm_timer_request(REQUEST_BY_ID, &id); in omap_dm_timer_request_specific()
620 if (!timer) in omap_dm_timer_request_specific()
623 return &timer->cookie; in omap_dm_timer_request_specific()
635 struct dmtimer *timer; in omap_dm_timer_request_by_node() local
640 timer = _omap_dm_timer_request(REQUEST_BY_NODE, np); in omap_dm_timer_request_by_node()
641 if (!timer) in omap_dm_timer_request_by_node()
644 return &timer->cookie; in omap_dm_timer_request_by_node()
649 struct dmtimer *timer; in omap_dm_timer_free() local
653 timer = to_dmtimer(cookie); in omap_dm_timer_free()
654 if (unlikely(!timer)) in omap_dm_timer_free()
657 WARN_ON(!timer->reserved); in omap_dm_timer_free()
658 timer->reserved = 0; in omap_dm_timer_free()
660 dev = &timer->pdev->dev; in omap_dm_timer_free()
666 dmtimer_write(timer, OMAP_TIMER_CTRL_REG, 0); in omap_dm_timer_free()
675 struct dmtimer *timer = to_dmtimer(cookie); in omap_dm_timer_get_irq() local
676 if (timer) in omap_dm_timer_get_irq()
677 return timer->irq; in omap_dm_timer_get_irq()
696 struct dmtimer *timer = NULL; in omap_dm_timer_modify_idlect_mask() local
705 list_for_each_entry(timer, &omap_timer_list, node) { in omap_dm_timer_modify_idlect_mask()
708 l = dmtimer_read(timer, OMAP_TIMER_CTRL_REG); in omap_dm_timer_modify_idlect_mask()
726 struct dmtimer *timer = to_dmtimer(cookie); in omap_dm_timer_get_fclk() local
728 if (timer && !IS_ERR(timer->fclk)) in omap_dm_timer_get_fclk()
729 return timer->fclk; in omap_dm_timer_get_fclk()
744 struct dmtimer *timer; in omap_dm_timer_start() local
749 timer = to_dmtimer(cookie); in omap_dm_timer_start()
750 if (unlikely(!timer)) in omap_dm_timer_start()
753 dev = &timer->pdev->dev; in omap_dm_timer_start()
759 l = dmtimer_read(timer, OMAP_TIMER_CTRL_REG); in omap_dm_timer_start()
762 dmtimer_write(timer, OMAP_TIMER_CTRL_REG, l); in omap_dm_timer_start()
770 struct dmtimer *timer; in omap_dm_timer_stop() local
773 timer = to_dmtimer(cookie); in omap_dm_timer_stop()
774 if (unlikely(!timer)) in omap_dm_timer_stop()
777 dev = &timer->pdev->dev; in omap_dm_timer_stop()
779 __omap_dm_timer_stop(timer); in omap_dm_timer_stop()
789 struct dmtimer *timer; in omap_dm_timer_set_load() local
793 timer = to_dmtimer(cookie); in omap_dm_timer_set_load()
794 if (unlikely(!timer)) in omap_dm_timer_set_load()
797 dev = &timer->pdev->dev; in omap_dm_timer_set_load()
802 dmtimer_write(timer, OMAP_TIMER_LOAD_REG, load); in omap_dm_timer_set_load()
812 struct dmtimer *timer; in omap_dm_timer_set_match() local
817 timer = to_dmtimer(cookie); in omap_dm_timer_set_match()
818 if (unlikely(!timer)) in omap_dm_timer_set_match()
821 dev = &timer->pdev->dev; in omap_dm_timer_set_match()
826 l = dmtimer_read(timer, OMAP_TIMER_CTRL_REG); in omap_dm_timer_set_match()
831 dmtimer_write(timer, OMAP_TIMER_MATCH_REG, match); in omap_dm_timer_set_match()
832 dmtimer_write(timer, OMAP_TIMER_CTRL_REG, l); in omap_dm_timer_set_match()
842 struct dmtimer *timer; in omap_dm_timer_set_pwm() local
847 timer = to_dmtimer(cookie); in omap_dm_timer_set_pwm()
848 if (unlikely(!timer)) in omap_dm_timer_set_pwm()
851 dev = &timer->pdev->dev; in omap_dm_timer_set_pwm()
856 l = dmtimer_read(timer, OMAP_TIMER_CTRL_REG); in omap_dm_timer_set_pwm()
866 dmtimer_write(timer, OMAP_TIMER_CTRL_REG, l); in omap_dm_timer_set_pwm()
875 struct dmtimer *timer; in omap_dm_timer_get_pwm_status() local
880 timer = to_dmtimer(cookie); in omap_dm_timer_get_pwm_status()
881 if (unlikely(!timer)) in omap_dm_timer_get_pwm_status()
884 dev = &timer->pdev->dev; in omap_dm_timer_get_pwm_status()
889 l = dmtimer_read(timer, OMAP_TIMER_CTRL_REG); in omap_dm_timer_get_pwm_status()
899 struct dmtimer *timer; in omap_dm_timer_set_prescaler() local
904 timer = to_dmtimer(cookie); in omap_dm_timer_set_prescaler()
905 if (unlikely(!timer) || prescaler < -1 || prescaler > 7) in omap_dm_timer_set_prescaler()
908 dev = &timer->pdev->dev; in omap_dm_timer_set_prescaler()
913 l = dmtimer_read(timer, OMAP_TIMER_CTRL_REG); in omap_dm_timer_set_prescaler()
919 dmtimer_write(timer, OMAP_TIMER_CTRL_REG, l); in omap_dm_timer_set_prescaler()
929 struct dmtimer *timer; in omap_dm_timer_set_int_enable() local
933 timer = to_dmtimer(cookie); in omap_dm_timer_set_int_enable()
934 if (unlikely(!timer)) in omap_dm_timer_set_int_enable()
937 dev = &timer->pdev->dev; in omap_dm_timer_set_int_enable()
942 __omap_dm_timer_int_enable(timer, value); in omap_dm_timer_set_int_enable()
958 struct dmtimer *timer; in omap_dm_timer_set_int_disable() local
963 timer = to_dmtimer(cookie); in omap_dm_timer_set_int_disable()
964 if (unlikely(!timer)) in omap_dm_timer_set_int_disable()
967 dev = &timer->pdev->dev; in omap_dm_timer_set_int_disable()
972 if (timer->revision == 1) in omap_dm_timer_set_int_disable()
973 l = dmtimer_read(timer, timer->irq_ena) & ~mask; in omap_dm_timer_set_int_disable()
975 dmtimer_write(timer, timer->irq_dis, l); in omap_dm_timer_set_int_disable()
976 l = dmtimer_read(timer, OMAP_TIMER_WAKEUP_EN_REG) & ~mask; in omap_dm_timer_set_int_disable()
977 dmtimer_write(timer, OMAP_TIMER_WAKEUP_EN_REG, l); in omap_dm_timer_set_int_disable()
986 struct dmtimer *timer; in omap_dm_timer_read_status() local
989 timer = to_dmtimer(cookie); in omap_dm_timer_read_status()
990 if (unlikely(!timer || !atomic_read(&timer->enabled))) { in omap_dm_timer_read_status()
995 l = dmtimer_read(timer, timer->irq_stat); in omap_dm_timer_read_status()
1002 struct dmtimer *timer; in omap_dm_timer_write_status() local
1004 timer = to_dmtimer(cookie); in omap_dm_timer_write_status()
1005 if (unlikely(!timer || !atomic_read(&timer->enabled))) in omap_dm_timer_write_status()
1008 __omap_dm_timer_write_status(timer, value); in omap_dm_timer_write_status()
1015 struct dmtimer *timer; in omap_dm_timer_read_counter() local
1017 timer = to_dmtimer(cookie); in omap_dm_timer_read_counter()
1018 if (unlikely(!timer || !atomic_read(&timer->enabled))) { in omap_dm_timer_read_counter()
1023 return __omap_dm_timer_read_counter(timer); in omap_dm_timer_read_counter()
1028 struct dmtimer *timer; in omap_dm_timer_write_counter() local
1030 timer = to_dmtimer(cookie); in omap_dm_timer_write_counter()
1031 if (unlikely(!timer || !atomic_read(&timer->enabled))) { in omap_dm_timer_write_counter()
1036 dmtimer_write(timer, OMAP_TIMER_COUNTER_REG, value); in omap_dm_timer_write_counter()
1039 timer->context.tcrr = value; in omap_dm_timer_write_counter()
1045 struct dmtimer *timer = dev_get_drvdata(dev); in omap_dm_timer_runtime_suspend() local
1047 atomic_set(&timer->enabled, 0); in omap_dm_timer_runtime_suspend()
1049 if (timer->capability & OMAP_TIMER_ALWON || !timer->func_base) in omap_dm_timer_runtime_suspend()
1052 omap_timer_save_context(timer); in omap_dm_timer_runtime_suspend()
1059 struct dmtimer *timer = dev_get_drvdata(dev); in omap_dm_timer_runtime_resume() local
1061 if (!(timer->capability & OMAP_TIMER_ALWON) && timer->func_base) in omap_dm_timer_runtime_resume()
1062 omap_timer_restore_context(timer); in omap_dm_timer_runtime_resume()
1064 atomic_set(&timer->enabled, 1); in omap_dm_timer_runtime_resume()
1086 struct dmtimer *timer; in omap_dm_timer_probe() local
1102 timer = devm_kzalloc(dev, sizeof(*timer), GFP_KERNEL); in omap_dm_timer_probe()
1103 if (!timer) in omap_dm_timer_probe()
1106 timer->irq = platform_get_irq(pdev, 0); in omap_dm_timer_probe()
1107 if (timer->irq < 0) in omap_dm_timer_probe()
1108 return timer->irq; in omap_dm_timer_probe()
1110 timer->io_base = devm_platform_ioremap_resource(pdev, 0); in omap_dm_timer_probe()
1111 if (IS_ERR(timer->io_base)) in omap_dm_timer_probe()
1112 return PTR_ERR(timer->io_base); in omap_dm_timer_probe()
1114 platform_set_drvdata(pdev, timer); in omap_dm_timer_probe()
1118 timer->capability |= OMAP_TIMER_ALWON; in omap_dm_timer_probe()
1120 timer->capability |= OMAP_TIMER_HAS_DSP_IRQ; in omap_dm_timer_probe()
1122 timer->capability |= OMAP_TIMER_HAS_PWM; in omap_dm_timer_probe()
1124 timer->capability |= OMAP_TIMER_SECURE; in omap_dm_timer_probe()
1126 timer->id = pdev->id; in omap_dm_timer_probe()
1127 timer->capability = pdata->timer_capability; in omap_dm_timer_probe()
1128 timer->reserved = omap_dm_timer_reserved_systimer(timer->id); in omap_dm_timer_probe()
1131 timer->omap1 = timer->capability & OMAP_TIMER_NEEDS_RESET; in omap_dm_timer_probe()
1134 if (!timer->omap1) { in omap_dm_timer_probe()
1135 timer->fclk = devm_clk_get(dev, "fck"); in omap_dm_timer_probe()
1136 if (IS_ERR(timer->fclk)) in omap_dm_timer_probe()
1137 return PTR_ERR(timer->fclk); in omap_dm_timer_probe()
1139 timer->fclk_nb.notifier_call = omap_timer_fclk_notifier; in omap_dm_timer_probe()
1140 ret = devm_clk_notifier_register(dev, timer->fclk, in omap_dm_timer_probe()
1141 &timer->fclk_nb); in omap_dm_timer_probe()
1145 timer->fclk_rate = clk_get_rate(timer->fclk); in omap_dm_timer_probe()
1147 timer->fclk = ERR_PTR(-ENODEV); in omap_dm_timer_probe()
1150 if (!(timer->capability & OMAP_TIMER_ALWON)) { in omap_dm_timer_probe()
1151 timer->nb.notifier_call = omap_timer_context_notifier; in omap_dm_timer_probe()
1152 cpu_pm_register_notifier(&timer->nb); in omap_dm_timer_probe()
1155 timer->errata = pdata->timer_errata; in omap_dm_timer_probe()
1157 timer->pdev = pdev; in omap_dm_timer_probe()
1161 if (!timer->reserved) { in omap_dm_timer_probe()
1168 __omap_dm_timer_init_regs(timer); in omap_dm_timer_probe()
1171 dmtimer_write(timer, OMAP_TIMER_CTRL_REG, 0); in omap_dm_timer_probe()
1178 list_add_tail(&timer->node, &omap_timer_list); in omap_dm_timer_probe()
1200 struct dmtimer *timer; in omap_dm_timer_remove() local
1205 list_for_each_entry(timer, &omap_timer_list, node) in omap_dm_timer_remove()
1206 if (!strcmp(dev_name(&timer->pdev->dev), in omap_dm_timer_remove()
1208 if (!(timer->capability & OMAP_TIMER_ALWON)) in omap_dm_timer_remove()
1209 cpu_pm_unregister_notifier(&timer->nb); in omap_dm_timer_remove()
1210 list_del(&timer->node); in omap_dm_timer_remove()