Lines Matching +full:timer +full:- +full:alwon

1 // SPDX-License-Identifier: GPL-2.0+
3 * linux/arch/arm/plat-omap/dmtimer.c
5 * OMAP Dual-Mode Timers
7 * Copyright (C) 2010 Texas Instruments Incorporated - https://www.ti.com/
18 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
22 #include <linux/clk-provider.h>
31 #include <linux/platform_data/dmtimer-omap.h>
33 #include <clocksource/timer-ti-dm.h>
36 * timer errata flags
40 * timer counter register is never read. For more details please refer to
158 * dmtimer_read - read timer registers in posted and non-posted mode
159 * @timer: timer pointer over which read operation to perform
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()
182 * dmtimer_write - write timer registers in posted and non-posted mode
183 * @timer: timer pointer over which write operation is to perform
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()
232 * __omap_dm_timer_enable_posted - enables write posted mode
233 * @timer: pointer to timer instance handle
235 * Enables the write posted mode for the timer. When posted mode is enabled
236 * writes to certain timer registers are immediately acknowledged by the
239 * timer registers.
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()
270 * timer is stopped 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()
371 return -EINVAL; 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()
377 } while (!l && timeout--); in omap_dm_timer_reset()
380 dev_err(&timer->pdev->dev, "Timer failed to reset\n"); in omap_dm_timer_reset()
381 return -ETIMEDOUT; in omap_dm_timer_reset()
384 /* Configure timer for smart-idle mode */ 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()
418 return -EINVAL; in omap_dm_timer_set_source()
431 return -EINVAL; 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()
453 return -EINVAL; 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()
474 dev_err(dev, "could not enable timer\n"); 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()
510 return (omap_reserved_systimers & (1 << (id - 1))) ? 1 : 0; in omap_dm_timer_reserved_systimer()
515 struct dmtimer *timer = NULL, *t; in _omap_dm_timer_request() local
538 if (t->reserved) in _omap_dm_timer_request()
543 if (id == t->pdev->id) { in _omap_dm_timer_request()
544 timer = t; in _omap_dm_timer_request()
545 timer->reserved = 1; in _omap_dm_timer_request()
550 if (cap == (t->capability & cap)) { in _omap_dm_timer_request()
552 * If timer is not NULL, we have already found in _omap_dm_timer_request()
553 * one timer. But it was not an exact match in _omap_dm_timer_request()
556 * timer found and see if this one is a better 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()
565 if (t->capability == cap) in _omap_dm_timer_request()
570 if (np == t->pdev->dev.of_node) { 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()
592 pr_debug("%s: timer request failed!\n", __func__); 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
612 /* Requesting timer by ID is not supported when device tree is used */ in omap_dm_timer_request_specific()
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()
627 * omap_dm_timer_request_by_node - Request a timer by device-tree node
628 * @np: Pointer to device-tree timer node
630 * Request a timer based upon a device node pointer. Returns pointer to
631 * timer handle on success and a NULL pointer on failure.
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()
655 return -EINVAL; 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()
665 /* Clear timer configuration */ 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()
678 return -EINVAL; in omap_dm_timer_get_irq()
682 #include <linux/soc/ti/omap1-io.h>
690 * omap_dm_timer_modify_idlect_mask - Check if any running timers use ARMXOR
696 struct dmtimer *timer = NULL; in omap_dm_timer_modify_idlect_mask() local
703 /* If any active timer is using ARMXOR return modified mask */ in omap_dm_timer_modify_idlect_mask()
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()
751 return -EINVAL; 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()
775 return -EINVAL; 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()
795 return -EINVAL; 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()
819 return -EINVAL; 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()
849 return -EINVAL; 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()
882 return -EINVAL; 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()
906 return -EINVAL; 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()
935 return -EINVAL; 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()
950 * omap_dm_timer_set_int_disable - disable timer interrupts
951 * @cookie: pointer to timer cookie
954 * Disables the specified timer interrupts for a timer.
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()
965 return -EINVAL; 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()
991 pr_err("%s: timer not available or enabled.\n", __func__); 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()
1006 return -EINVAL; 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()
1019 pr_err("%s: timer not iavailable or enabled.\n", __func__); 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()
1032 pr_err("%s: timer not available or enabled.\n", __func__); in omap_dm_timer_write_counter()
1033 return -EINVAL; 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()
1077 * omap_dm_timer_probe - probe function called for every registered device
1078 * @pdev: pointer to current timer platform device
1081 * timer devices.
1086 struct dmtimer *timer; in omap_dm_timer_probe() local
1087 struct device *dev = &pdev->dev; in omap_dm_timer_probe()
1095 dev->platform_data = (void *)pdata; in omap_dm_timer_probe()
1099 return -ENODEV; in omap_dm_timer_probe()
1102 timer = devm_kzalloc(dev, sizeof(*timer), GFP_KERNEL); in omap_dm_timer_probe()
1103 if (!timer) in omap_dm_timer_probe()
1104 return -ENOMEM; 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 if (of_property_read_bool(dev->of_node, "ti,timer-pwm")) in omap_dm_timer_probe()
1109 dev_info(dev, "Did not find timer interrupt, timer usable in PWM mode only\n"); in omap_dm_timer_probe()
1111 return timer->irq; in omap_dm_timer_probe()
1114 timer->io_base = devm_platform_ioremap_resource(pdev, 0); in omap_dm_timer_probe()
1115 if (IS_ERR(timer->io_base)) in omap_dm_timer_probe()
1116 return PTR_ERR(timer->io_base); in omap_dm_timer_probe()
1118 platform_set_drvdata(pdev, timer); in omap_dm_timer_probe()
1120 if (dev->of_node) { in omap_dm_timer_probe()
1121 if (of_property_read_bool(dev->of_node, "ti,timer-alwon")) in omap_dm_timer_probe()
1122 timer->capability |= OMAP_TIMER_ALWON; in omap_dm_timer_probe()
1123 if (of_property_read_bool(dev->of_node, "ti,timer-dsp")) in omap_dm_timer_probe()
1124 timer->capability |= OMAP_TIMER_HAS_DSP_IRQ; in omap_dm_timer_probe()
1125 if (of_property_read_bool(dev->of_node, "ti,timer-pwm")) in omap_dm_timer_probe()
1126 timer->capability |= OMAP_TIMER_HAS_PWM; in omap_dm_timer_probe()
1127 if (of_property_read_bool(dev->of_node, "ti,timer-secure")) in omap_dm_timer_probe()
1128 timer->capability |= OMAP_TIMER_SECURE; in omap_dm_timer_probe()
1130 timer->id = pdev->id; in omap_dm_timer_probe()
1131 timer->capability = pdata->timer_capability; in omap_dm_timer_probe()
1132 timer->reserved = omap_dm_timer_reserved_systimer(timer->id); in omap_dm_timer_probe()
1135 timer->omap1 = timer->capability & OMAP_TIMER_NEEDS_RESET; in omap_dm_timer_probe()
1138 if (!timer->omap1) { in omap_dm_timer_probe()
1139 timer->fclk = devm_clk_get(dev, "fck"); in omap_dm_timer_probe()
1140 if (IS_ERR(timer->fclk)) in omap_dm_timer_probe()
1141 return PTR_ERR(timer->fclk); in omap_dm_timer_probe()
1143 timer->fclk_nb.notifier_call = omap_timer_fclk_notifier; in omap_dm_timer_probe()
1144 ret = devm_clk_notifier_register(dev, timer->fclk, in omap_dm_timer_probe()
1145 &timer->fclk_nb); in omap_dm_timer_probe()
1149 timer->fclk_rate = clk_get_rate(timer->fclk); in omap_dm_timer_probe()
1151 timer->fclk = ERR_PTR(-ENODEV); in omap_dm_timer_probe()
1154 if (!(timer->capability & OMAP_TIMER_ALWON)) { in omap_dm_timer_probe()
1155 timer->nb.notifier_call = omap_timer_context_notifier; in omap_dm_timer_probe()
1156 cpu_pm_register_notifier(&timer->nb); in omap_dm_timer_probe()
1159 timer->errata = pdata->timer_errata; in omap_dm_timer_probe()
1161 timer->pdev = pdev; in omap_dm_timer_probe()
1165 if (!timer->reserved) { in omap_dm_timer_probe()
1172 __omap_dm_timer_init_regs(timer); in omap_dm_timer_probe()
1174 /* Clear timer configuration */ in omap_dm_timer_probe()
1175 dmtimer_write(timer, OMAP_TIMER_CTRL_REG, 0); in omap_dm_timer_probe()
1180 /* add the timer element to the list */ in omap_dm_timer_probe()
1182 list_add_tail(&timer->node, &omap_timer_list); in omap_dm_timer_probe()
1195 * omap_dm_timer_remove - cleanup a registered timer device
1196 * @pdev: pointer to current timer platform device
1198 * Called by driver framework whenever a timer device is unregistered.
1199 * In addition to freeing platform resources it also deletes the timer
1204 struct dmtimer *timer; in omap_dm_timer_remove() local
1206 int ret = -EINVAL; in omap_dm_timer_remove()
1209 list_for_each_entry(timer, &omap_timer_list, node) in omap_dm_timer_remove()
1210 if (!strcmp(dev_name(&timer->pdev->dev), in omap_dm_timer_remove()
1211 dev_name(&pdev->dev))) { in omap_dm_timer_remove()
1212 if (!(timer->capability & OMAP_TIMER_ALWON)) in omap_dm_timer_remove()
1213 cpu_pm_unregister_notifier(&timer->nb); in omap_dm_timer_remove()
1214 list_del(&timer->node); in omap_dm_timer_remove()
1220 pm_runtime_disable(&pdev->dev); in omap_dm_timer_remove()
1223 dev_err(&pdev->dev, "Unable to determine timer entry in list of drivers on remove\n"); in omap_dm_timer_remove()
1262 .compatible = "ti,omap2420-timer",
1265 .compatible = "ti,omap3430-timer",
1269 .compatible = "ti,omap4430-timer",
1273 .compatible = "ti,omap5430-timer",
1277 .compatible = "ti,am335x-timer",
1281 .compatible = "ti,am335x-timer-1ms",
1285 .compatible = "ti,dm816-timer",
1289 .compatible = "ti,am654-timer",
1308 MODULE_DESCRIPTION("OMAP Dual-Mode Timer Driver");