Commit 3a090284 authored by Paul Walmsley's avatar Paul Walmsley

ARM: OMAP2+: powerdomain/clockdomain: add a per-powerdomain spinlock

Add a per-powerdomain spinlock.  Use that instead of the clockdomain
spinlock.  Add pwrdm_lock()/pwrdm_unlock() functions to allow other
code to acquire or release the powerdomain spinlock without reaching
directly into the struct powerdomain.
Signed-off-by: default avatarPaul Walmsley <paul@pwsan.com>
Cc: Jean Pihet <jean.pihet@newoldbits.com>
parent c4978fba
...@@ -92,8 +92,6 @@ static int _clkdm_register(struct clockdomain *clkdm) ...@@ -92,8 +92,6 @@ static int _clkdm_register(struct clockdomain *clkdm)
pwrdm_add_clkdm(pwrdm, clkdm); pwrdm_add_clkdm(pwrdm, clkdm);
spin_lock_init(&clkdm->lock);
pr_debug("clockdomain: registered %s\n", clkdm->name); pr_debug("clockdomain: registered %s\n", clkdm->name);
return 0; return 0;
...@@ -734,18 +732,17 @@ int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm) ...@@ -734,18 +732,17 @@ int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm)
} }
/** /**
* clkdm_sleep - force clockdomain sleep transition * clkdm_sleep_nolock - force clockdomain sleep transition (lockless)
* @clkdm: struct clockdomain * * @clkdm: struct clockdomain *
* *
* Instruct the CM to force a sleep transition on the specified * Instruct the CM to force a sleep transition on the specified
* clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if * clockdomain @clkdm. Only for use by the powerdomain code. Returns
* clockdomain does not support software-initiated sleep; 0 upon * -EINVAL if @clkdm is NULL or if clockdomain does not support
* success. * software-initiated sleep; 0 upon success.
*/ */
int clkdm_sleep(struct clockdomain *clkdm) int clkdm_sleep_nolock(struct clockdomain *clkdm)
{ {
int ret; int ret;
unsigned long flags;
if (!clkdm) if (!clkdm)
return -EINVAL; return -EINVAL;
...@@ -761,27 +758,45 @@ int clkdm_sleep(struct clockdomain *clkdm) ...@@ -761,27 +758,45 @@ int clkdm_sleep(struct clockdomain *clkdm)
pr_debug("clockdomain: forcing sleep on %s\n", clkdm->name); pr_debug("clockdomain: forcing sleep on %s\n", clkdm->name);
spin_lock_irqsave(&clkdm->lock, flags);
clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED; clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
ret = arch_clkdm->clkdm_sleep(clkdm); ret = arch_clkdm->clkdm_sleep(clkdm);
ret |= pwrdm_state_switch(clkdm->pwrdm.ptr); ret |= pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
spin_unlock_irqrestore(&clkdm->lock, flags);
return ret; return ret;
} }
/** /**
* clkdm_wakeup - force clockdomain wakeup transition * clkdm_sleep - force clockdomain sleep transition
* @clkdm: struct clockdomain * * @clkdm: struct clockdomain *
* *
* Instruct the CM to force a wakeup transition on the specified * Instruct the CM to force a sleep transition on the specified
* clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if the * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if
* clockdomain does not support software-controlled wakeup; 0 upon * clockdomain does not support software-initiated sleep; 0 upon
* success. * success.
*/ */
int clkdm_wakeup(struct clockdomain *clkdm) int clkdm_sleep(struct clockdomain *clkdm)
{
int ret;
pwrdm_lock(clkdm->pwrdm.ptr);
ret = clkdm_sleep_nolock(clkdm);
pwrdm_unlock(clkdm->pwrdm.ptr);
return ret;
}
/**
* clkdm_wakeup_nolock - force clockdomain wakeup transition (lockless)
* @clkdm: struct clockdomain *
*
* Instruct the CM to force a wakeup transition on the specified
* clockdomain @clkdm. Only for use by the powerdomain code. Returns
* -EINVAL if @clkdm is NULL or if the clockdomain does not support
* software-controlled wakeup; 0 upon success.
*/
int clkdm_wakeup_nolock(struct clockdomain *clkdm)
{ {
int ret; int ret;
unsigned long flags;
if (!clkdm) if (!clkdm)
return -EINVAL; return -EINVAL;
...@@ -797,28 +812,46 @@ int clkdm_wakeup(struct clockdomain *clkdm) ...@@ -797,28 +812,46 @@ int clkdm_wakeup(struct clockdomain *clkdm)
pr_debug("clockdomain: forcing wakeup on %s\n", clkdm->name); pr_debug("clockdomain: forcing wakeup on %s\n", clkdm->name);
spin_lock_irqsave(&clkdm->lock, flags);
clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED; clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
ret = arch_clkdm->clkdm_wakeup(clkdm); ret = arch_clkdm->clkdm_wakeup(clkdm);
ret |= pwrdm_state_switch(clkdm->pwrdm.ptr); ret |= pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
spin_unlock_irqrestore(&clkdm->lock, flags);
return ret; return ret;
} }
/** /**
* clkdm_allow_idle - enable hwsup idle transitions for clkdm * clkdm_wakeup - force clockdomain wakeup transition
* @clkdm: struct clockdomain * * @clkdm: struct clockdomain *
* *
* Allow the hardware to automatically switch the clockdomain @clkdm into * Instruct the CM to force a wakeup transition on the specified
* active or idle states, as needed by downstream clocks. If the * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if the
* clockdomain does not support software-controlled wakeup; 0 upon
* success.
*/
int clkdm_wakeup(struct clockdomain *clkdm)
{
int ret;
pwrdm_lock(clkdm->pwrdm.ptr);
ret = clkdm_wakeup_nolock(clkdm);
pwrdm_unlock(clkdm->pwrdm.ptr);
return ret;
}
/**
* clkdm_allow_idle_nolock - enable hwsup idle transitions for clkdm
* @clkdm: struct clockdomain *
*
* Allow the hardware to automatically switch the clockdomain @clkdm
* into active or idle states, as needed by downstream clocks. If the
* clockdomain has any downstream clocks enabled in the clock * clockdomain has any downstream clocks enabled in the clock
* framework, wkdep/sleepdep autodependencies are added; this is so * framework, wkdep/sleepdep autodependencies are added; this is so
* device drivers can read and write to the device. No return value. * device drivers can read and write to the device. Only for use by
* the powerdomain code. No return value.
*/ */
void clkdm_allow_idle(struct clockdomain *clkdm) void clkdm_allow_idle_nolock(struct clockdomain *clkdm)
{ {
unsigned long flags;
if (!clkdm) if (!clkdm)
return; return;
...@@ -834,11 +867,26 @@ void clkdm_allow_idle(struct clockdomain *clkdm) ...@@ -834,11 +867,26 @@ void clkdm_allow_idle(struct clockdomain *clkdm)
pr_debug("clockdomain: enabling automatic idle transitions for %s\n", pr_debug("clockdomain: enabling automatic idle transitions for %s\n",
clkdm->name); clkdm->name);
spin_lock_irqsave(&clkdm->lock, flags);
clkdm->_flags |= _CLKDM_FLAG_HWSUP_ENABLED; clkdm->_flags |= _CLKDM_FLAG_HWSUP_ENABLED;
arch_clkdm->clkdm_allow_idle(clkdm); arch_clkdm->clkdm_allow_idle(clkdm);
pwrdm_state_switch(clkdm->pwrdm.ptr); pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
spin_unlock_irqrestore(&clkdm->lock, flags); }
/**
* clkdm_allow_idle - enable hwsup idle transitions for clkdm
* @clkdm: struct clockdomain *
*
* Allow the hardware to automatically switch the clockdomain @clkdm into
* active or idle states, as needed by downstream clocks. If the
* clockdomain has any downstream clocks enabled in the clock
* framework, wkdep/sleepdep autodependencies are added; this is so
* device drivers can read and write to the device. No return value.
*/
void clkdm_allow_idle(struct clockdomain *clkdm)
{
pwrdm_lock(clkdm->pwrdm.ptr);
clkdm_allow_idle_nolock(clkdm);
pwrdm_unlock(clkdm->pwrdm.ptr);
} }
/** /**
...@@ -848,12 +896,11 @@ void clkdm_allow_idle(struct clockdomain *clkdm) ...@@ -848,12 +896,11 @@ void clkdm_allow_idle(struct clockdomain *clkdm)
* Prevent the hardware from automatically switching the clockdomain * Prevent the hardware from automatically switching the clockdomain
* @clkdm into inactive or idle states. If the clockdomain has * @clkdm into inactive or idle states. If the clockdomain has
* downstream clocks enabled in the clock framework, wkdep/sleepdep * downstream clocks enabled in the clock framework, wkdep/sleepdep
* autodependencies are removed. No return value. * autodependencies are removed. Only for use by the powerdomain
* code. No return value.
*/ */
void clkdm_deny_idle(struct clockdomain *clkdm) void clkdm_deny_idle_nolock(struct clockdomain *clkdm)
{ {
unsigned long flags;
if (!clkdm) if (!clkdm)
return; return;
...@@ -869,11 +916,25 @@ void clkdm_deny_idle(struct clockdomain *clkdm) ...@@ -869,11 +916,25 @@ void clkdm_deny_idle(struct clockdomain *clkdm)
pr_debug("clockdomain: disabling automatic idle transitions for %s\n", pr_debug("clockdomain: disabling automatic idle transitions for %s\n",
clkdm->name); clkdm->name);
spin_lock_irqsave(&clkdm->lock, flags);
clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED; clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
arch_clkdm->clkdm_deny_idle(clkdm); arch_clkdm->clkdm_deny_idle(clkdm);
pwrdm_state_switch(clkdm->pwrdm.ptr); pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
spin_unlock_irqrestore(&clkdm->lock, flags); }
/**
* clkdm_deny_idle - disable hwsup idle transitions for clkdm
* @clkdm: struct clockdomain *
*
* Prevent the hardware from automatically switching the clockdomain
* @clkdm into inactive or idle states. If the clockdomain has
* downstream clocks enabled in the clock framework, wkdep/sleepdep
* autodependencies are removed. No return value.
*/
void clkdm_deny_idle(struct clockdomain *clkdm)
{
pwrdm_lock(clkdm->pwrdm.ptr);
clkdm_deny_idle_nolock(clkdm);
pwrdm_unlock(clkdm->pwrdm.ptr);
} }
/** /**
...@@ -890,14 +951,11 @@ void clkdm_deny_idle(struct clockdomain *clkdm) ...@@ -890,14 +951,11 @@ void clkdm_deny_idle(struct clockdomain *clkdm)
bool clkdm_in_hwsup(struct clockdomain *clkdm) bool clkdm_in_hwsup(struct clockdomain *clkdm)
{ {
bool ret; bool ret;
unsigned long flags;
if (!clkdm) if (!clkdm)
return false; return false;
spin_lock_irqsave(&clkdm->lock, flags);
ret = (clkdm->_flags & _CLKDM_FLAG_HWSUP_ENABLED) ? true : false; ret = (clkdm->_flags & _CLKDM_FLAG_HWSUP_ENABLED) ? true : false;
spin_unlock_irqrestore(&clkdm->lock, flags);
return ret; return ret;
} }
...@@ -923,12 +981,10 @@ bool clkdm_missing_idle_reporting(struct clockdomain *clkdm) ...@@ -923,12 +981,10 @@ bool clkdm_missing_idle_reporting(struct clockdomain *clkdm)
static int _clkdm_clk_hwmod_enable(struct clockdomain *clkdm) static int _clkdm_clk_hwmod_enable(struct clockdomain *clkdm)
{ {
unsigned long flags;
if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_enable) if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_enable)
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&clkdm->lock, flags); pwrdm_lock(clkdm->pwrdm.ptr);
/* /*
* For arch's with no autodeps, clkcm_clk_enable * For arch's with no autodeps, clkcm_clk_enable
...@@ -936,13 +992,13 @@ static int _clkdm_clk_hwmod_enable(struct clockdomain *clkdm) ...@@ -936,13 +992,13 @@ static int _clkdm_clk_hwmod_enable(struct clockdomain *clkdm)
* enabled, so the clkdm can be force woken up. * enabled, so the clkdm can be force woken up.
*/ */
if ((atomic_inc_return(&clkdm->usecount) > 1) && autodeps) { if ((atomic_inc_return(&clkdm->usecount) > 1) && autodeps) {
spin_unlock_irqrestore(&clkdm->lock, flags); pwrdm_unlock(clkdm->pwrdm.ptr);
return 0; return 0;
} }
arch_clkdm->clkdm_clk_enable(clkdm); arch_clkdm->clkdm_clk_enable(clkdm);
pwrdm_state_switch(clkdm->pwrdm.ptr); pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
spin_unlock_irqrestore(&clkdm->lock, flags); pwrdm_unlock(clkdm->pwrdm.ptr);
pr_debug("clockdomain: %s: enabled\n", clkdm->name); pr_debug("clockdomain: %s: enabled\n", clkdm->name);
...@@ -991,12 +1047,10 @@ int clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk) ...@@ -991,12 +1047,10 @@ int clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk)
*/ */
int clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk) int clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk)
{ {
unsigned long flags;
if (!clkdm || !clk || !arch_clkdm || !arch_clkdm->clkdm_clk_disable) if (!clkdm || !clk || !arch_clkdm || !arch_clkdm->clkdm_clk_disable)
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&clkdm->lock, flags); pwrdm_lock(clkdm->pwrdm.ptr);
/* corner case: disabling unused clocks */ /* corner case: disabling unused clocks */
if ((__clk_get_enable_count(clk) == 0) && if ((__clk_get_enable_count(clk) == 0) &&
...@@ -1004,23 +1058,23 @@ int clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk) ...@@ -1004,23 +1058,23 @@ int clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk)
goto ccd_exit; goto ccd_exit;
if (atomic_read(&clkdm->usecount) == 0) { if (atomic_read(&clkdm->usecount) == 0) {
spin_unlock_irqrestore(&clkdm->lock, flags); pwrdm_unlock(clkdm->pwrdm.ptr);
WARN_ON(1); /* underflow */ WARN_ON(1); /* underflow */
return -ERANGE; return -ERANGE;
} }
if (atomic_dec_return(&clkdm->usecount) > 0) { if (atomic_dec_return(&clkdm->usecount) > 0) {
spin_unlock_irqrestore(&clkdm->lock, flags); pwrdm_unlock(clkdm->pwrdm.ptr);
return 0; return 0;
} }
arch_clkdm->clkdm_clk_disable(clkdm); arch_clkdm->clkdm_clk_disable(clkdm);
pwrdm_state_switch(clkdm->pwrdm.ptr); pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
pr_debug("clockdomain: %s: disabled\n", clkdm->name); pr_debug("clockdomain: %s: disabled\n", clkdm->name);
ccd_exit: ccd_exit:
spin_unlock_irqrestore(&clkdm->lock, flags); pwrdm_unlock(clkdm->pwrdm.ptr);
return 0; return 0;
} }
...@@ -1073,8 +1127,6 @@ int clkdm_hwmod_enable(struct clockdomain *clkdm, struct omap_hwmod *oh) ...@@ -1073,8 +1127,6 @@ int clkdm_hwmod_enable(struct clockdomain *clkdm, struct omap_hwmod *oh)
*/ */
int clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh) int clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh)
{ {
unsigned long flags;
/* The clkdm attribute does not exist yet prior OMAP4 */ /* The clkdm attribute does not exist yet prior OMAP4 */
if (cpu_is_omap24xx() || cpu_is_omap34xx()) if (cpu_is_omap24xx() || cpu_is_omap34xx())
return 0; return 0;
...@@ -1087,22 +1139,22 @@ int clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh) ...@@ -1087,22 +1139,22 @@ int clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh)
if (!clkdm || !oh || !arch_clkdm || !arch_clkdm->clkdm_clk_disable) if (!clkdm || !oh || !arch_clkdm || !arch_clkdm->clkdm_clk_disable)
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&clkdm->lock, flags); pwrdm_lock(clkdm->pwrdm.ptr);
if (atomic_read(&clkdm->usecount) == 0) { if (atomic_read(&clkdm->usecount) == 0) {
spin_unlock_irqrestore(&clkdm->lock, flags); pwrdm_unlock(clkdm->pwrdm.ptr);
WARN_ON(1); /* underflow */ WARN_ON(1); /* underflow */
return -ERANGE; return -ERANGE;
} }
if (atomic_dec_return(&clkdm->usecount) > 0) { if (atomic_dec_return(&clkdm->usecount) > 0) {
spin_unlock_irqrestore(&clkdm->lock, flags); pwrdm_unlock(clkdm->pwrdm.ptr);
return 0; return 0;
} }
arch_clkdm->clkdm_clk_disable(clkdm); arch_clkdm->clkdm_clk_disable(clkdm);
pwrdm_state_switch(clkdm->pwrdm.ptr); pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
spin_unlock_irqrestore(&clkdm->lock, flags); pwrdm_unlock(clkdm->pwrdm.ptr);
pr_debug("clockdomain: %s: disabled\n", clkdm->name); pr_debug("clockdomain: %s: disabled\n", clkdm->name);
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#define __ARCH_ARM_MACH_OMAP2_CLOCKDOMAIN_H #define __ARCH_ARM_MACH_OMAP2_CLOCKDOMAIN_H
#include <linux/init.h> #include <linux/init.h>
#include <linux/spinlock.h>
#include "powerdomain.h" #include "powerdomain.h"
#include "clock.h" #include "clock.h"
...@@ -139,7 +138,6 @@ struct clockdomain { ...@@ -139,7 +138,6 @@ struct clockdomain {
struct clkdm_dep *sleepdep_srcs; struct clkdm_dep *sleepdep_srcs;
atomic_t usecount; atomic_t usecount;
struct list_head node; struct list_head node;
spinlock_t lock;
}; };
/** /**
...@@ -196,12 +194,16 @@ int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2); ...@@ -196,12 +194,16 @@ int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2); int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm); int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm);
void clkdm_allow_idle_nolock(struct clockdomain *clkdm);
void clkdm_allow_idle(struct clockdomain *clkdm); void clkdm_allow_idle(struct clockdomain *clkdm);
void clkdm_deny_idle_nolock(struct clockdomain *clkdm);
void clkdm_deny_idle(struct clockdomain *clkdm); void clkdm_deny_idle(struct clockdomain *clkdm);
bool clkdm_in_hwsup(struct clockdomain *clkdm); bool clkdm_in_hwsup(struct clockdomain *clkdm);
bool clkdm_missing_idle_reporting(struct clockdomain *clkdm); bool clkdm_missing_idle_reporting(struct clockdomain *clkdm);
int clkdm_wakeup_nolock(struct clockdomain *clkdm);
int clkdm_wakeup(struct clockdomain *clkdm); int clkdm_wakeup(struct clockdomain *clkdm);
int clkdm_sleep_nolock(struct clockdomain *clkdm);
int clkdm_sleep(struct clockdomain *clkdm); int clkdm_sleep(struct clockdomain *clkdm);
int clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk); int clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/list.h> #include <linux/list.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/spinlock.h>
#include <trace/events/power.h> #include <trace/events/power.h>
#include "cm2xxx_3xxx.h" #include "cm2xxx_3xxx.h"
...@@ -111,6 +112,7 @@ static int _pwrdm_register(struct powerdomain *pwrdm) ...@@ -111,6 +112,7 @@ static int _pwrdm_register(struct powerdomain *pwrdm)
pwrdm->voltdm.ptr = voltdm; pwrdm->voltdm.ptr = voltdm;
INIT_LIST_HEAD(&pwrdm->voltdm_node); INIT_LIST_HEAD(&pwrdm->voltdm_node);
voltdm_add_pwrdm(voltdm, pwrdm); voltdm_add_pwrdm(voltdm, pwrdm);
spin_lock_init(&pwrdm->_lock);
list_add(&pwrdm->node, &pwrdm_list); list_add(&pwrdm->node, &pwrdm_list);
...@@ -241,7 +243,7 @@ static u8 _pwrdm_save_clkdm_state_and_activate(struct powerdomain *pwrdm, ...@@ -241,7 +243,7 @@ static u8 _pwrdm_save_clkdm_state_and_activate(struct powerdomain *pwrdm,
sleep_switch = LOWPOWERSTATE_SWITCH; sleep_switch = LOWPOWERSTATE_SWITCH;
} else { } else {
*hwsup = clkdm_in_hwsup(pwrdm->pwrdm_clkdms[0]); *hwsup = clkdm_in_hwsup(pwrdm->pwrdm_clkdms[0]);
clkdm_wakeup(pwrdm->pwrdm_clkdms[0]); clkdm_wakeup_nolock(pwrdm->pwrdm_clkdms[0]);
sleep_switch = FORCEWAKEUP_SWITCH; sleep_switch = FORCEWAKEUP_SWITCH;
} }
} else { } else {
...@@ -271,15 +273,15 @@ static void _pwrdm_restore_clkdm_state(struct powerdomain *pwrdm, ...@@ -271,15 +273,15 @@ static void _pwrdm_restore_clkdm_state(struct powerdomain *pwrdm,
switch (sleep_switch) { switch (sleep_switch) {
case FORCEWAKEUP_SWITCH: case FORCEWAKEUP_SWITCH:
if (hwsup) if (hwsup)
clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]); clkdm_allow_idle_nolock(pwrdm->pwrdm_clkdms[0]);
else else
clkdm_sleep(pwrdm->pwrdm_clkdms[0]); clkdm_sleep_nolock(pwrdm->pwrdm_clkdms[0]);
break; break;
case LOWPOWERSTATE_SWITCH: case LOWPOWERSTATE_SWITCH:
if (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE && if (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE &&
arch_pwrdm->pwrdm_set_lowpwrstchange) arch_pwrdm->pwrdm_set_lowpwrstchange)
arch_pwrdm->pwrdm_set_lowpwrstchange(pwrdm); arch_pwrdm->pwrdm_set_lowpwrstchange(pwrdm);
pwrdm_state_switch(pwrdm); pwrdm_state_switch_nolock(pwrdm);
break; break;
} }
} }
...@@ -359,6 +361,30 @@ int pwrdm_complete_init(void) ...@@ -359,6 +361,30 @@ int pwrdm_complete_init(void)
return 0; return 0;
} }
/**
* pwrdm_lock - acquire a Linux spinlock on a powerdomain
* @pwrdm: struct powerdomain * to lock
*
* Acquire the powerdomain spinlock on @pwrdm. No return value.
*/
void pwrdm_lock(struct powerdomain *pwrdm)
__acquires(&pwrdm->_lock)
{
spin_lock_irqsave(&pwrdm->_lock, pwrdm->_lock_flags);
}
/**
* pwrdm_unlock - release a Linux spinlock on a powerdomain
* @pwrdm: struct powerdomain * to unlock
*
* Release the powerdomain spinlock on @pwrdm. No return value.
*/
void pwrdm_unlock(struct powerdomain *pwrdm)
__releases(&pwrdm->_lock)
{
spin_unlock_irqrestore(&pwrdm->_lock, pwrdm->_lock_flags);
}
/** /**
* pwrdm_lookup - look up a powerdomain by name, return a pointer * pwrdm_lookup - look up a powerdomain by name, return a pointer
* @name: name of powerdomain * @name: name of powerdomain
...@@ -1005,7 +1031,7 @@ bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm) ...@@ -1005,7 +1031,7 @@ bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm)
return (pwrdm && pwrdm->flags & PWRDM_HAS_HDWR_SAR) ? 1 : 0; return (pwrdm && pwrdm->flags & PWRDM_HAS_HDWR_SAR) ? 1 : 0;
} }
int pwrdm_state_switch(struct powerdomain *pwrdm) int pwrdm_state_switch_nolock(struct powerdomain *pwrdm)
{ {
int ret; int ret;
...@@ -1019,6 +1045,17 @@ int pwrdm_state_switch(struct powerdomain *pwrdm) ...@@ -1019,6 +1045,17 @@ int pwrdm_state_switch(struct powerdomain *pwrdm)
return ret; return ret;
} }
int __deprecated pwrdm_state_switch(struct powerdomain *pwrdm)
{
int ret;
pwrdm_lock(pwrdm);
ret = pwrdm_state_switch_nolock(pwrdm);
pwrdm_unlock(pwrdm);
return ret;
}
int pwrdm_pre_transition(struct powerdomain *pwrdm) int pwrdm_pre_transition(struct powerdomain *pwrdm)
{ {
if (pwrdm) if (pwrdm)
...@@ -1067,15 +1104,19 @@ int omap_set_pwrdm_state(struct powerdomain *pwrdm, u8 pwrst) ...@@ -1067,15 +1104,19 @@ int omap_set_pwrdm_state(struct powerdomain *pwrdm, u8 pwrst)
pwrst--; pwrst--;
} }
pwrdm_lock(pwrdm);
curr_pwrst = pwrdm_read_pwrst(pwrdm); curr_pwrst = pwrdm_read_pwrst(pwrdm);
next_pwrst = pwrdm_read_next_pwrst(pwrdm); next_pwrst = pwrdm_read_next_pwrst(pwrdm);
if (curr_pwrst == pwrst && next_pwrst == pwrst) if (curr_pwrst == pwrst && next_pwrst == pwrst)
return ret; goto osps_out;
sleep_switch = _pwrdm_save_clkdm_state_and_activate(pwrdm, curr_pwrst, sleep_switch = _pwrdm_save_clkdm_state_and_activate(pwrdm, curr_pwrst,
pwrst, &hwsup); pwrst, &hwsup);
if (sleep_switch == ERROR_SWITCH) if (sleep_switch == ERROR_SWITCH) {
return -EINVAL; ret = -EINVAL;
goto osps_out;
}
ret = pwrdm_set_next_pwrst(pwrdm, pwrst); ret = pwrdm_set_next_pwrst(pwrdm, pwrst);
if (ret) if (ret)
...@@ -1084,6 +1125,9 @@ int omap_set_pwrdm_state(struct powerdomain *pwrdm, u8 pwrst) ...@@ -1084,6 +1125,9 @@ int omap_set_pwrdm_state(struct powerdomain *pwrdm, u8 pwrst)
_pwrdm_restore_clkdm_state(pwrdm, sleep_switch, hwsup); _pwrdm_restore_clkdm_state(pwrdm, sleep_switch, hwsup);
osps_out:
pwrdm_unlock(pwrdm);
return ret; return ret;
} }
......
...@@ -19,8 +19,7 @@ ...@@ -19,8 +19,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/atomic.h>
#include "voltage.h" #include "voltage.h"
...@@ -103,6 +102,8 @@ struct powerdomain; ...@@ -103,6 +102,8 @@ struct powerdomain;
* @state_counter: * @state_counter:
* @timer: * @timer:
* @state_timer: * @state_timer:
* @_lock: spinlock used to serialize powerdomain and some clockdomain ops
* @_lock_flags: stored flags when @_lock is taken
* *
* @prcm_partition possible values are defined in mach-omap2/prcm44xx.h. * @prcm_partition possible values are defined in mach-omap2/prcm44xx.h.
*/ */
...@@ -127,7 +128,8 @@ struct powerdomain { ...@@ -127,7 +128,8 @@ struct powerdomain {
unsigned state_counter[PWRDM_MAX_PWRSTS]; unsigned state_counter[PWRDM_MAX_PWRSTS];
unsigned ret_logic_off_counter; unsigned ret_logic_off_counter;
unsigned ret_mem_off_counter[PWRDM_MAX_MEM_BANKS]; unsigned ret_mem_off_counter[PWRDM_MAX_MEM_BANKS];
spinlock_t _lock;
unsigned long _lock_flags;
const u8 pwrstctrl_offs; const u8 pwrstctrl_offs;
const u8 pwrstst_offs; const u8 pwrstst_offs;
const u32 logicretstate_mask; const u32 logicretstate_mask;
...@@ -235,6 +237,7 @@ int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm); ...@@ -235,6 +237,7 @@ int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm);
int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm); int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm);
bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm); bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm);
int pwrdm_state_switch_nolock(struct powerdomain *pwrdm);
int pwrdm_state_switch(struct powerdomain *pwrdm); int pwrdm_state_switch(struct powerdomain *pwrdm);
int pwrdm_pre_transition(struct powerdomain *pwrdm); int pwrdm_pre_transition(struct powerdomain *pwrdm);
int pwrdm_post_transition(struct powerdomain *pwrdm); int pwrdm_post_transition(struct powerdomain *pwrdm);
...@@ -262,5 +265,7 @@ extern u32 omap2_pwrdm_get_mem_bank_stst_mask(u8 bank); ...@@ -262,5 +265,7 @@ extern u32 omap2_pwrdm_get_mem_bank_stst_mask(u8 bank);
extern struct powerdomain wkup_omap2_pwrdm; extern struct powerdomain wkup_omap2_pwrdm;
extern struct powerdomain gfx_omap2_pwrdm; extern struct powerdomain gfx_omap2_pwrdm;
extern void pwrdm_lock(struct powerdomain *pwrdm);
extern void pwrdm_unlock(struct powerdomain *pwrdm);
#endif #endif
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