Commit eaa49a8c authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

sh: TMU: Introduce clocksource/clock events suspend/resume routines

Introduce suspend/resume routines for SH TMU clock source and
clock event device such that if those devices belong to a PM domain,
the generic PM domains framework will be notified that the given
domain may be turned off (during system suspend) or that it has to
be turned on (during system resume).

This change allows the A4R domain on SH7372 to be turned off during
system suspend (tested on the Mackerel board) if the TMU clock source
and/or clock event device is in use.
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Acked-by: default avatarMagnus Damm <damm@opensource.se>
parent adc78e6b
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/pm_domain.h> #include <linux/pm_domain.h>
#include <linux/pm_runtime.h>
struct sh_tmu_priv { struct sh_tmu_priv {
void __iomem *mapbase; void __iomem *mapbase;
...@@ -43,6 +44,7 @@ struct sh_tmu_priv { ...@@ -43,6 +44,7 @@ struct sh_tmu_priv {
unsigned long periodic; unsigned long periodic;
struct clock_event_device ced; struct clock_event_device ced;
struct clocksource cs; struct clocksource cs;
bool cs_enabled;
}; };
static DEFINE_RAW_SPINLOCK(sh_tmu_lock); static DEFINE_RAW_SPINLOCK(sh_tmu_lock);
...@@ -204,14 +206,40 @@ static int sh_tmu_clocksource_enable(struct clocksource *cs) ...@@ -204,14 +206,40 @@ static int sh_tmu_clocksource_enable(struct clocksource *cs)
int ret; int ret;
ret = sh_tmu_enable(p); ret = sh_tmu_enable(p);
if (!ret) if (!ret) {
__clocksource_updatefreq_hz(cs, p->rate); __clocksource_updatefreq_hz(cs, p->rate);
p->cs_enabled = true;
}
return ret; return ret;
} }
static void sh_tmu_clocksource_disable(struct clocksource *cs) static void sh_tmu_clocksource_disable(struct clocksource *cs)
{ {
sh_tmu_disable(cs_to_sh_tmu(cs)); struct sh_tmu_priv *p = cs_to_sh_tmu(cs);
WARN_ON(!p->cs_enabled);
sh_tmu_disable(p);
p->cs_enabled = false;
}
static void sh_tmu_clocksource_suspend(struct clocksource *cs)
{
struct sh_tmu_priv *p = cs_to_sh_tmu(cs);
if (p->cs_enabled)
sh_tmu_disable(p);
pm_genpd_syscore_poweroff(&p->pdev->dev);
}
static void sh_tmu_clocksource_resume(struct clocksource *cs)
{
struct sh_tmu_priv *p = cs_to_sh_tmu(cs);
pm_genpd_syscore_poweron(&p->pdev->dev);
if (p->cs_enabled)
sh_tmu_enable(p);
} }
static int sh_tmu_register_clocksource(struct sh_tmu_priv *p, static int sh_tmu_register_clocksource(struct sh_tmu_priv *p,
...@@ -224,6 +252,8 @@ static int sh_tmu_register_clocksource(struct sh_tmu_priv *p, ...@@ -224,6 +252,8 @@ static int sh_tmu_register_clocksource(struct sh_tmu_priv *p,
cs->read = sh_tmu_clocksource_read; cs->read = sh_tmu_clocksource_read;
cs->enable = sh_tmu_clocksource_enable; cs->enable = sh_tmu_clocksource_enable;
cs->disable = sh_tmu_clocksource_disable; cs->disable = sh_tmu_clocksource_disable;
cs->suspend = sh_tmu_clocksource_suspend;
cs->resume = sh_tmu_clocksource_resume;
cs->mask = CLOCKSOURCE_MASK(32); cs->mask = CLOCKSOURCE_MASK(32);
cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; cs->flags = CLOCK_SOURCE_IS_CONTINUOUS;
...@@ -301,6 +331,16 @@ static int sh_tmu_clock_event_next(unsigned long delta, ...@@ -301,6 +331,16 @@ static int sh_tmu_clock_event_next(unsigned long delta,
return 0; return 0;
} }
static void sh_tmu_clock_event_suspend(struct clock_event_device *ced)
{
pm_genpd_syscore_poweroff(&ced_to_sh_tmu(ced)->pdev->dev);
}
static void sh_tmu_clock_event_resume(struct clock_event_device *ced)
{
pm_genpd_syscore_poweron(&ced_to_sh_tmu(ced)->pdev->dev);
}
static void sh_tmu_register_clockevent(struct sh_tmu_priv *p, static void sh_tmu_register_clockevent(struct sh_tmu_priv *p,
char *name, unsigned long rating) char *name, unsigned long rating)
{ {
...@@ -316,6 +356,8 @@ static void sh_tmu_register_clockevent(struct sh_tmu_priv *p, ...@@ -316,6 +356,8 @@ static void sh_tmu_register_clockevent(struct sh_tmu_priv *p,
ced->cpumask = cpumask_of(0); ced->cpumask = cpumask_of(0);
ced->set_next_event = sh_tmu_clock_event_next; ced->set_next_event = sh_tmu_clock_event_next;
ced->set_mode = sh_tmu_clock_event_mode; ced->set_mode = sh_tmu_clock_event_mode;
ced->suspend = sh_tmu_clock_event_suspend;
ced->resume = sh_tmu_clock_event_resume;
dev_info(&p->pdev->dev, "used for clock events\n"); dev_info(&p->pdev->dev, "used for clock events\n");
...@@ -407,8 +449,12 @@ static int __devinit sh_tmu_probe(struct platform_device *pdev) ...@@ -407,8 +449,12 @@ static int __devinit sh_tmu_probe(struct platform_device *pdev)
struct sh_tmu_priv *p = platform_get_drvdata(pdev); struct sh_tmu_priv *p = platform_get_drvdata(pdev);
int ret; int ret;
if (!is_early_platform_device(pdev)) if (!is_early_platform_device(pdev)) {
struct sh_timer_config *cfg = pdev->dev.platform_data;
if (cfg->clocksource_rating || cfg->clockevent_rating)
pm_genpd_dev_always_on(&pdev->dev, true); pm_genpd_dev_always_on(&pdev->dev, true);
}
if (p) { if (p) {
dev_info(&pdev->dev, "kept as earlytimer\n"); dev_info(&pdev->dev, "kept as earlytimer\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment