[PATCH 02/12] ARM: OMAP2+: PM: introduce power domains functional states

2012-12-09 Thread Paul Walmsley
From: Jean Pihet 

Introduce the functional states for power domains, which include
the power states and the logic states.
This patch provides the API functions to set and read the power
domains functional state and internal functions to convert between
the functional (i.e. logical) and the internal (or registers) values.

In the new API only the functions pwrdm_set_next_fpwrst() and
pwrdm_set_fpwrst() shall be used to change a power domain target
state, along with the associated PWRDM_FUNC_* macros as the state
parameters.

Note about the power domains allowed states:
Power domains have varied capabilities, as defined by the value of
the pwrsts and pwrsts_logic_ret fields of the powerdomain struct.
When reading or setting a low power state such as OFF/RET, a specific
requested state may not be supported on the given power domain.
In the states conversion functions a power or logic state is first
looked for in the lower power states in order to maximize the power
savings, then if not found in the higher power states. An iteration
function is used, as suggested by Rajendra Nayak 
This function is temporary and will be removed later in the series.

This functionality brings consistency in the functional power states
core code and acts as a guard against hardware implementations
discrepancies, e.g. some power domains only support the RET logic
state although reading the logic state registers (previous, current
and next) always returns OFF. The DSS power domain on OMAP3 is an
example.

Signed-off-by: Jean Pihet 
Cc: Tero Kristo 
Cc: Rajendra Nayak 
Cc: Nishanth Menon 
[p...@pwsan.com: add offset for functional powerstates so it's not
 possible to confuse them with the old API; use one fn to convert func
 pwrsts to low-level hardware bits; skip hardware reads when hardware
 logic retst and logic pwrst bits are missing; fix kerneldoc and
 commit message; remove unnecessary PWRDM_LOGIC_MEM_PWRST_* macros;
 combine spinlock patch into this patch; expand the number of operations
 which take the spinlock]
Signed-off-by: Paul Walmsley 
---
 arch/arm/mach-omap2/powerdomain.c |  525 +
 arch/arm/mach-omap2/powerdomain.h |   33 ++
 2 files changed, 553 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-omap2/powerdomain.c 
b/arch/arm/mach-omap2/powerdomain.c
index 94b89a25..18f33de 100644
--- a/arch/arm/mach-omap2/powerdomain.c
+++ b/arch/arm/mach-omap2/powerdomain.c
@@ -1,7 +1,7 @@
 /*
  * OMAP powerdomain control
  *
- * Copyright (C) 2007-2008, 2011 Texas Instruments, Inc.
+ * Copyright (C) 2007-2008, 2011-2012 Texas Instruments, Inc.
  * Copyright (C) 2007-2011 Nokia Corporation
  *
  * Written by Paul Walmsley
@@ -44,12 +44,19 @@ enum {
PWRDM_STATE_PREV,
 };
 
-
 /* pwrdm_list contains all registered struct powerdomains */
 static LIST_HEAD(pwrdm_list);
 
 static struct pwrdm_ops *arch_pwrdm;
 
+/*
+ * _fpwrst_names: human-readable functional powerstate names - should match
+ *the enum pwrdm_func_state order and names
+ */
+static const char * const _fpwrst_names[] = {
+   "OFF", "OSWR", "CSWR", "INACTIVE", "ON"
+};
+
 /* Private functions */
 
 static struct powerdomain *_pwrdm_lookup(const char *name)
@@ -145,7 +152,6 @@ static void _update_logic_membank_counters(struct 
powerdomain *pwrdm)
 
 static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)
 {
-
int prev, next, state, trace_state = 0;
 
if (pwrdm == NULL)
@@ -259,6 +265,309 @@ static bool _pwrdm_logic_retst_can_change(struct 
powerdomain *pwrdm)
return _pwrdm_logic_retst_is_controllable(pwrdm);
 }
 
+/**
+ * _match_pwrst: determine the closest supported power state
+ * @pwrsts: list of allowed states, defined as a bitmask
+ * @pwrst: initial state to be used as a starting point
+ * @min: minimum (i.e. lowest consumption) allowed state
+ * @max: maximum (i.e. highest consumption) allowed state
+ *
+ * Search down then up for a valid state from a list of allowed
+ * states.  Used by states conversion functions (_pwrdm_fpwrst_to_*)
+ * to look for allowed power and logic states for a powerdomain.
+ * Returns the matching allowed state.  XXX Deprecated.  The software
+ * should not try to program unsupported powerstates.
+ */
+static int _match_pwrst(u32 pwrsts, int pwrst, int min, int max)
+{
+   int found = 1, new_pwrst = pwrst;
+
+   /*
+* If the power domain does not allow any state programmation
+* return the max state which is always allowed
+*/
+   if (!pwrsts)
+   return max;
+
+   /*
+* Search lower: if the requested state is not supported
+* try the lower states, stopping at the minimum allowed
+* state
+*/
+   while (!(pwrsts & (1 << new_pwrst))) {
+   if (new_pwrst <= min) {
+   found = 0;
+   break;
+   }
+   new_pwrst--;
+   }
+
+   /*
+* Search higher: if no lower state found

Re: [PATCH 02/12] ARM: OMAP2+: PM: introduce power domains functional states

2012-12-12 Thread Vaibhav Hiremath


On 12/9/2012 11:23 PM, Paul Walmsley wrote:
> From: Jean Pihet 
> 
> Introduce the functional states for power domains, which include
> the power states and the logic states.
> This patch provides the API functions to set and read the power
> domains functional state and internal functions to convert between
> the functional (i.e. logical) and the internal (or registers) values.
> 
> In the new API only the functions pwrdm_set_next_fpwrst() and
> pwrdm_set_fpwrst() shall be used to change a power domain target
> state, along with the associated PWRDM_FUNC_* macros as the state
> parameters.
> 
> Note about the power domains allowed states:
> Power domains have varied capabilities, as defined by the value of
> the pwrsts and pwrsts_logic_ret fields of the powerdomain struct.
> When reading or setting a low power state such as OFF/RET, a specific
> requested state may not be supported on the given power domain.
> In the states conversion functions a power or logic state is first
> looked for in the lower power states in order to maximize the power
> savings, then if not found in the higher power states. An iteration
> function is used, as suggested by Rajendra Nayak 
> This function is temporary and will be removed later in the series.
> 
> This functionality brings consistency in the functional power states
> core code and acts as a guard against hardware implementations
> discrepancies, e.g. some power domains only support the RET logic
> state although reading the logic state registers (previous, current
> and next) always returns OFF. The DSS power domain on OMAP3 is an
> example.
> 
> Signed-off-by: Jean Pihet 
> Cc: Tero Kristo 
> Cc: Rajendra Nayak 
> Cc: Nishanth Menon 
> [p...@pwsan.com: add offset for functional powerstates so it's not
>  possible to confuse them with the old API; use one fn to convert func
>  pwrsts to low-level hardware bits; skip hardware reads when hardware
>  logic retst and logic pwrst bits are missing; fix kerneldoc and
>  commit message; remove unnecessary PWRDM_LOGIC_MEM_PWRST_* macros;
>  combine spinlock patch into this patch; expand the number of operations
>  which take the spinlock]
> Signed-off-by: Paul Walmsley 
> ---
>  arch/arm/mach-omap2/powerdomain.c |  525 
> +
>  arch/arm/mach-omap2/powerdomain.h |   33 ++
>  2 files changed, 553 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm/mach-omap2/powerdomain.c 
> b/arch/arm/mach-omap2/powerdomain.c
> index 94b89a25..18f33de 100644
> --- a/arch/arm/mach-omap2/powerdomain.c
> +++ b/arch/arm/mach-omap2/powerdomain.c
> @@ -1,7 +1,7 @@
>  /*
>   * OMAP powerdomain control
>   *
> - * Copyright (C) 2007-2008, 2011 Texas Instruments, Inc.
> + * Copyright (C) 2007-2008, 2011-2012 Texas Instruments, Inc.
>   * Copyright (C) 2007-2011 Nokia Corporation
>   *
>   * Written by Paul Walmsley
> @@ -44,12 +44,19 @@ enum {
>   PWRDM_STATE_PREV,
>  };
>  
> -
>  /* pwrdm_list contains all registered struct powerdomains */
>  static LIST_HEAD(pwrdm_list);
>  
>  static struct pwrdm_ops *arch_pwrdm;
>  
> +/*
> + * _fpwrst_names: human-readable functional powerstate names - should match
> + *the enum pwrdm_func_state order and names
> + */
> +static const char * const _fpwrst_names[] = {
> + "OFF", "OSWR", "CSWR", "INACTIVE", "ON"
> +};
> +
>  /* Private functions */
>  
>  static struct powerdomain *_pwrdm_lookup(const char *name)
> @@ -145,7 +152,6 @@ static void _update_logic_membank_counters(struct 
> powerdomain *pwrdm)
>  
>  static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)
>  {
> -
>   int prev, next, state, trace_state = 0;
>  
>   if (pwrdm == NULL)
> @@ -259,6 +265,309 @@ static bool _pwrdm_logic_retst_can_change(struct 
> powerdomain *pwrdm)
>   return _pwrdm_logic_retst_is_controllable(pwrdm);
>  }
>  
> +/**
> + * _match_pwrst: determine the closest supported power state
> + * @pwrsts: list of allowed states, defined as a bitmask
> + * @pwrst: initial state to be used as a starting point
> + * @min: minimum (i.e. lowest consumption) allowed state
> + * @max: maximum (i.e. highest consumption) allowed state
> + *
> + * Search down then up for a valid state from a list of allowed
> + * states.  Used by states conversion functions (_pwrdm_fpwrst_to_*)
> + * to look for allowed power and logic states for a powerdomain.
> + * Returns the matching allowed state.  XXX Deprecated.  The software
> + * should not try to program unsupported powerstates.
> + */
> +static int _match_pwrst(u32 pwrsts, int pwrst, int min, int max)
> +{
> + int found = 1, new_pwrst = pwrst;
> +
> + /*
> +  * If the power domain does not allow any state programmation
> +  * return the max state which is always allowed
> +  */
> + if (!pwrsts)
> + return max;
> +
> + /*
> +  * Search lower: if the requested state is not supported
> +  * try the lower states, stopping at the minimum allowed
> +  * state
> +  */
> +  

Re: [PATCH 02/12] ARM: OMAP2+: PM: introduce power domains functional states

2012-12-12 Thread Jean Pihet
Hi Paul,

-resending in plain text only, sorry about that-

On Sun, Dec 9, 2012 at 6:53 PM, Paul Walmsley  wrote:
>
> From: Jean Pihet 
>
> Introduce the functional states for power domains, which include
> the power states and the logic states.
> This patch provides the API functions to set and read the power
> domains functional state and internal functions to convert between
> the functional (i.e. logical) and the internal (or registers) values.
>
> In the new API only the functions pwrdm_set_next_fpwrst() and
> pwrdm_set_fpwrst() shall be used to change a power domain target
> state, along with the associated PWRDM_FUNC_* macros as the state
> parameters.
>
> Note about the power domains allowed states:
> Power domains have varied capabilities, as defined by the value of
> the pwrsts and pwrsts_logic_ret fields of the powerdomain struct.
> When reading or setting a low power state such as OFF/RET, a specific
> requested state may not be supported on the given power domain.
> In the states conversion functions a power or logic state is first
> looked for in the lower power states in order to maximize the power
> savings, then if not found in the higher power states. An iteration
> function is used, as suggested by Rajendra Nayak 
> This function is temporary and will be removed later in the series.
>
> This functionality brings consistency in the functional power states
> core code and acts as a guard against hardware implementations
> discrepancies, e.g. some power domains only support the RET logic
> state although reading the logic state registers (previous, current
> and next) always returns OFF. The DSS power domain on OMAP3 is an
> example.
>
> Signed-off-by: Jean Pihet 
> Cc: Tero Kristo 
> Cc: Rajendra Nayak 
> Cc: Nishanth Menon 
> [p...@pwsan.com: add offset for functional powerstates so it's not
>  possible to confuse them with the old API; use one fn to convert func
>  pwrsts to low-level hardware bits; skip hardware reads when hardware
>  logic retst and logic pwrst bits are missing; fix kerneldoc and
>  commit message; remove unnecessary PWRDM_LOGIC_MEM_PWRST_* macros;
>  combine spinlock patch into this patch; expand the number of operations
>  which take the spinlock]
> Signed-off-by: Paul Walmsley 
> ---
>  arch/arm/mach-omap2/powerdomain.c |  525 
> +
>  arch/arm/mach-omap2/powerdomain.h |   33 ++
>  2 files changed, 553 insertions(+), 5 deletions(-)
>
> diff --git a/arch/arm/mach-omap2/powerdomain.c 
> b/arch/arm/mach-omap2/powerdomain.c
> index 94b89a25..18f33de 100644
> --- a/arch/arm/mach-omap2/powerdomain.c
> +++ b/arch/arm/mach-omap2/powerdomain.c
> @@ -1,7 +1,7 @@


...

> +/**
> + * _match_pwrst: determine the closest supported power state
> + * @pwrsts: list of allowed states, defined as a bitmask
> + * @pwrst: initial state to be used as a starting point
> + * @min: minimum (i.e. lowest consumption) allowed state
> + * @max: maximum (i.e. highest consumption) allowed state
> + *
> + * Search down then up for a valid state from a list of allowed
> + * states.  Used by states conversion functions (_pwrdm_fpwrst_to_*)
> + * to look for allowed power and logic states for a powerdomain.
> + * Returns the matching allowed state.  XXX Deprecated.  The software
> + * should not try to program unsupported powerstates.


Why is this new code already deprecated? Does this require a rewrite?

> + */
> +static int _match_pwrst(u32 pwrsts, int pwrst, int min, int max)
> +{
> +   int found = 1, new_pwrst = pwrst;
> +
> +   /*
> +* If the power domain does not allow any state programmation
> +* return the max state which is always allowed
> +*/
> +   if (!pwrsts)
> +   return max;
> +
> +   /*
> +* Search lower: if the requested state is not supported
> +* try the lower states, stopping at the minimum allowed
> +* state
> +*/
> +   while (!(pwrsts & (1 << new_pwrst))) {
> +   if (new_pwrst <= min) {
> +   found = 0;
> +   break;
> +   }
> +   new_pwrst--;
> +   }
> +
> +   /*
> +* Search higher: if no lower state found fallback to the higher
> +* states, stopping at the maximum allowed state
> +*/
> +   if (!found) {
> +   new_pwrst = pwrst;
> +   while (!(pwrsts & (1 << new_pwrst))) {
> +   if (new_pwrst >= max) {
> +   new_pwrst = max;
> +   break;
> +   }
> +   new_pwrst++;
> +   }
> +   }
> +
> +   return new_pwrst;
> +}
> +
> +/**
> + * _pwrdm_fpwrst_to_pwrst - Convert functional (i.e. logical) to
> + * internal (i.e. registers) values for the power domains states.
> + * @pwrdm: struct powerdomain * to convert the values for
> + * @fpwrst: functional power state
> + * @pwrdm_pwrst: ptr to u8 to ret

RE: [PATCH 02/12] ARM: OMAP2+: PM: introduce power domains functional states

2012-12-25 Thread Bedia, Vaibhav
Hi Paul,

A minor comment below.

On Sun, Dec 09, 2012 at 23:23:01, Paul Walmsley wrote:
[...]
> +
> + pr_debug("powerdomain: convert pwrst (%0x,%0x) to fpwrst %0x\n",
> +  pwrst, logic, *fpwrst);
> +

This function alone does not print the powerdomain name. Can you add that
in the final version?

Regards,
Vaibhav 

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 02/12] ARM: OMAP2+: PM: introduce power domains functional states

2013-01-04 Thread Tero Kristo
Hi Paul / Jean,

On Wed, 2012-12-12 at 11:33 +0100, Jean Pihet wrote:



> > +/**
> > + * _match_pwrst: determine the closest supported power state
> > + * @pwrsts: list of allowed states, defined as a bitmask
> > + * @pwrst: initial state to be used as a starting point
> > + * @min: minimum (i.e. lowest consumption) allowed state
> > + * @max: maximum (i.e. highest consumption) allowed state
> > + *
> > + * Search down then up for a valid state from a list of allowed
> > + * states.  Used by states conversion functions (_pwrdm_fpwrst_to_*)
> > + * to look for allowed power and logic states for a powerdomain.
> > + * Returns the matching allowed state.  XXX Deprecated.  The software
> > + * should not try to program unsupported powerstates.
> 
> 
> Why is this new code already deprecated? Does this require a rewrite?

Looks like it is removed by another patch in the same set and could
probably just be removed from this one also.

> > +   }
> > +
> > +   /* XXX deprecated */
> 
> 
> Same here

Same thing, maybe drop the code out completely.

-Tero


--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 02/12] ARM: OMAP2+: PM: introduce power domains functional states

2013-01-29 Thread Paul Walmsley
Hi 

(redacted some context)

On Wed, 12 Dec 2012, Jean Pihet wrote:

> On Sun, Dec 9, 2012 at 6:53 PM, Paul Walmsley  wrote:
> 
> +/**
> > + * _match_pwrst: determine the closest supported power state
> > + * @pwrsts: list of allowed states, defined as a bitmask
> > + * @pwrst: initial state to be used as a starting point
> > + * @min: minimum (i.e. lowest consumption) allowed state
> > + * @max: maximum (i.e. highest consumption) allowed state
> > + *
> > + * Search down then up for a valid state from a list of allowed
> > + * states.  Used by states conversion functions (_pwrdm_fpwrst_to_*)
> > + * to look for allowed power and logic states for a powerdomain.
> > + * Returns the matching allowed state.  XXX Deprecated.  The software
> > + * should not try to program unsupported powerstates.
> >
> 
> Why is this new code already deprecated? Does this require a rewrite?

The reason why is documented in the above comment.  The kernel should not 
attempt to program power states that the hardware doesn't support.  Our 
existing code will program unrequested power states, and that isn't 
predictable behavior.  If the kernel attempts to program a powerdomain to 
the CSWR power state, and the powerdomain doesn't support that state, it 
shouldn't silently program a different power state and return success.  
It should return an error, since the calling code shouldn't have tried to 
program that power state in the first place.

One of the subsequent patches removes this behavior and this code.  It's 
only being kept to ensure an orderly, functional kernel from one patch 
series to the next.


- Paul
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html