OMAP: PM counter infrastructure.
authorPeter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
Wed, 15 Oct 2008 14:48:43 +0000 (17:48 +0300)
committerKevin Hilman <khilman@deeprootsystems.com>
Wed, 2 Sep 2009 22:08:23 +0000 (15:08 -0700)
This patch provides the infrastructure to count how many times a
powerdomain entered a given power state (on, inactive, retention,
off). A number of functions are provided which will be called by the
chip specific powerdomain and clockdomain code whenever a transition
might have happened.

Signed-off-by: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
arch/arm/mach-omap2/clockdomain.c
arch/arm/mach-omap2/powerdomain.c
arch/arm/plat-omap/include/mach/powerdomain.h

index 0e7d501865b602c41f65c5e13693fc078fe5ef05..26912a95dc1823025f26ac5eafa4185f4b039f3c 100644 (file)
@@ -484,6 +484,8 @@ void omap2_clkdm_allow_idle(struct clockdomain *clkdm)
                            v << __ffs(clkdm->clktrctrl_mask),
                            clkdm->pwrdm.ptr->prcm_offs,
                            CM_CLKSTCTRL);
+
+       pwrdm_clkdm_state_switch(clkdm);
 }
 
 /**
index 983f1cb676be26ad24f88c7d834035a2c5fea15c..a2d98718c6d78805871fa8db73ce68e649414d4a 100644 (file)
 #include <mach/powerdomain.h>
 #include <mach/clockdomain.h>
 
+enum {
+       PWRDM_STATE_NOW = 0,
+       PWRDM_STATE_PREV,
+};
+
 /* pwrdm_list contains all registered struct powerdomains */
 static LIST_HEAD(pwrdm_list);
 
@@ -102,6 +107,63 @@ static struct powerdomain *_pwrdm_deps_lookup(struct powerdomain *pwrdm,
        return pd->pwrdm;
 }
 
+static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)
+{
+
+       int prev;
+       int state;
+
+       if (pwrdm == NULL)
+               return -EINVAL;
+
+       state = pwrdm_read_pwrst(pwrdm);
+
+       switch (flag) {
+       case PWRDM_STATE_NOW:
+               prev = pwrdm->state;
+               break;
+       case PWRDM_STATE_PREV:
+               prev = pwrdm_read_prev_pwrst(pwrdm);
+               if (pwrdm->state != prev)
+                       pwrdm->state_counter[prev]++;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (state != prev)
+               pwrdm->state_counter[state]++;
+
+       pwrdm->state = state;
+
+       return 0;
+}
+
+static int _pwrdm_pre_transition_cb(struct powerdomain *pwrdm)
+{
+       pwrdm_clear_all_prev_pwrst(pwrdm);
+       _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
+       return 0;
+}
+
+static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm)
+{
+       _pwrdm_state_switch(pwrdm, PWRDM_STATE_PREV);
+       return 0;
+}
+
+static __init void _pwrdm_setup(struct powerdomain *pwrdm)
+{
+       int i;
+
+       for (i = 0; i < 4; i++)
+               pwrdm->state_counter[i] = 0;
+
+       pwrdm_wait_transition(pwrdm);
+       pwrdm->state = pwrdm_read_pwrst(pwrdm);
+       pwrdm->state_counter[pwrdm->state] = 1;
+
+}
 
 /* Public functions */
 
@@ -117,9 +179,12 @@ void pwrdm_init(struct powerdomain **pwrdm_list)
 {
        struct powerdomain **p = NULL;
 
-       if (pwrdm_list)
-               for (p = pwrdm_list; *p; p++)
+       if (pwrdm_list) {
+               for (p = pwrdm_list; *p; p++) {
                        pwrdm_register(*p);
+                       _pwrdm_setup(*p);
+               }
+       }
 }
 
 /**
@@ -1110,4 +1175,36 @@ int pwrdm_wait_transition(struct powerdomain *pwrdm)
        return 0;
 }
 
+int pwrdm_state_switch(struct powerdomain *pwrdm)
+{
+       return _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
+}
+
+int pwrdm_clkdm_state_switch(struct clockdomain *clkdm)
+{
+       if (clkdm != NULL && clkdm->pwrdm.ptr != NULL) {
+               pwrdm_wait_transition(clkdm->pwrdm.ptr);
+               return pwrdm_state_switch(clkdm->pwrdm.ptr);
+       }
+
+       return -EINVAL;
+}
+int pwrdm_clk_state_switch(struct clk *clk)
+{
+       if (clk != NULL && clk->clkdm != NULL)
+               return pwrdm_clkdm_state_switch(clk->clkdm);
+       return -EINVAL;
+}
+
+int pwrdm_pre_transition(void)
+{
+       pwrdm_for_each(_pwrdm_pre_transition_cb);
+       return 0;
+}
+
+int pwrdm_post_transition(void)
+{
+       pwrdm_for_each(_pwrdm_post_transition_cb);
+       return 0;
+}
 
index 69c9e675d8ee48d2dfbf488a03068011e55e657d..52663fc549d2d92224a69ee58e9b563fd9436026 100644 (file)
@@ -117,6 +117,8 @@ struct powerdomain {
 
        struct list_head node;
 
+       int state;
+       unsigned state_counter[4];
 };
 
 
@@ -164,4 +166,9 @@ bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm);
 
 int pwrdm_wait_transition(struct powerdomain *pwrdm);
 
+int pwrdm_state_switch(struct powerdomain *pwrdm);
+int pwrdm_clkdm_state_switch(struct clockdomain *clkdm);
+int pwrdm_pre_transition(void);
+int pwrdm_post_transition(void);
+
 #endif