Skip to content

Commit 5e20931

Browse files
tmlinddlezcano
authored andcommitted
clocksource/drivers/timer-ti-dm: Prepare for using cpuidle
Let's add runtime_suspend and resume functions and atomic enabled flag. This way we can use these when converting to use cpuidle for saving and restoring device context. And we need to maintain the driver state in the driver as documented in "9. Autosuspend, or automatically-delayed suspends" in the Documentation/power/runtime_pm.rst document related to using driver private lock and races with runtime_suspend(). Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Lokesh Vutla <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 341e8cb commit 5e20931

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

drivers/clocksource/timer-ti-dm.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask)
491491

492492
int omap_dm_timer_trigger(struct omap_dm_timer *timer)
493493
{
494-
if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
494+
if (unlikely(!timer || !atomic_read(&timer->enabled))) {
495495
pr_err("%s: timer not available or enabled.\n", __func__);
496496
return -EINVAL;
497497
}
@@ -690,7 +690,7 @@ static unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer)
690690
{
691691
unsigned int l;
692692

693-
if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
693+
if (unlikely(!timer || !atomic_read(&timer->enabled))) {
694694
pr_err("%s: timer not available or enabled.\n", __func__);
695695
return 0;
696696
}
@@ -702,7 +702,7 @@ static unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer)
702702

703703
static int omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value)
704704
{
705-
if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev)))
705+
if (unlikely(!timer || !atomic_read(&timer->enabled)))
706706
return -EINVAL;
707707

708708
__omap_dm_timer_write_status(timer, value);
@@ -712,7 +712,7 @@ static int omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int
712712

713713
static unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer)
714714
{
715-
if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
715+
if (unlikely(!timer || !atomic_read(&timer->enabled))) {
716716
pr_err("%s: timer not iavailable or enabled.\n", __func__);
717717
return 0;
718718
}
@@ -722,7 +722,7 @@ static unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer)
722722

723723
static int omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value)
724724
{
725-
if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
725+
if (unlikely(!timer || !atomic_read(&timer->enabled))) {
726726
pr_err("%s: timer not available or enabled.\n", __func__);
727727
return -EINVAL;
728728
}
@@ -750,6 +750,29 @@ int omap_dm_timers_active(void)
750750
return 0;
751751
}
752752

753+
static int __maybe_unused omap_dm_timer_runtime_suspend(struct device *dev)
754+
{
755+
struct omap_dm_timer *timer = dev_get_drvdata(dev);
756+
757+
atomic_set(&timer->enabled, 0);
758+
759+
return 0;
760+
}
761+
762+
static int __maybe_unused omap_dm_timer_runtime_resume(struct device *dev)
763+
{
764+
struct omap_dm_timer *timer = dev_get_drvdata(dev);
765+
766+
atomic_set(&timer->enabled, 1);
767+
768+
return 0;
769+
}
770+
771+
static const struct dev_pm_ops omap_dm_timer_pm_ops = {
772+
SET_RUNTIME_PM_OPS(omap_dm_timer_runtime_suspend,
773+
omap_dm_timer_runtime_resume, NULL)
774+
};
775+
753776
static const struct of_device_id omap_timer_match[];
754777

755778
/**
@@ -791,6 +814,8 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
791814
if (IS_ERR(timer->io_base))
792815
return PTR_ERR(timer->io_base);
793816

817+
platform_set_drvdata(pdev, timer);
818+
794819
if (dev->of_node) {
795820
if (of_find_property(dev->of_node, "ti,timer-alwon", NULL))
796821
timer->capability |= OMAP_TIMER_ALWON;
@@ -936,6 +961,7 @@ static struct platform_driver omap_dm_timer_driver = {
936961
.driver = {
937962
.name = "omap_timer",
938963
.of_match_table = of_match_ptr(omap_timer_match),
964+
.pm = &omap_dm_timer_pm_ops,
939965
},
940966
};
941967

include/clocksource/timer-ti-dm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ struct omap_dm_timer {
105105
void __iomem *pend; /* write pending */
106106
void __iomem *func_base; /* function register base */
107107

108+
atomic_t enabled;
108109
unsigned long rate;
109110
unsigned reserved:1;
110111
unsigned posted:1;

0 commit comments

Comments
 (0)