]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
OMAP2+: voltage: keep track of powerdomains in each voltagedomain
authorKevin Hilman <khilman@ti.com>
Wed, 16 Mar 2011 23:13:15 +0000 (16:13 -0700)
committerKevin Hilman <khilman@ti.com>
Thu, 15 Sep 2011 18:39:10 +0000 (11:39 -0700)
When a powerdomain is registered and it has an associated voltage domain,
add the powerdomain to the voltagedomain using voltdm_add_pwrdm().

Also add voltagedomain iterator helper functions to iterate over all
registered voltagedomains and all powerdomains associated with a
voltagedomain.

Modeled after a similar relationship between clockdomains and powerdomains.

Signed-off-by: Kevin Hilman <khilman@ti.com>
arch/arm/mach-omap2/powerdomain.c
arch/arm/mach-omap2/powerdomain.h
arch/arm/mach-omap2/voltage.c
arch/arm/mach-omap2/voltage.h

index 984457d612b71cf4027fb70f4ab6e07871ebf9a3..5164d587ef52a17fa5083c71506ed801ce9dd382 100644 (file)
@@ -99,6 +99,8 @@ static int _pwrdm_register(struct powerdomain *pwrdm)
                return -EINVAL;
        }
        pwrdm->voltdm.ptr = voltdm;
+       INIT_LIST_HEAD(&pwrdm->voltdm_node);
+       voltdm_add_pwrdm(voltdm, pwrdm);
 
        list_add(&pwrdm->node, &pwrdm_list);
 
index d8a7f914d9b369870a7cfd1b66f298bc57120163..42e6dd8f2a78dd37521f06780cc76bb5050b01de 100644 (file)
@@ -91,6 +91,7 @@ struct powerdomain;
  * @pwrsts_mem_on: Possible memory bank pwrstates when pwrdm in ON
  * @pwrdm_clkdms: Clockdomains in this powerdomain
  * @node: list_head linking all powerdomains
+ * @voltdm_node: list_head linking all powerdomains in a voltagedomain
  * @state:
  * @state_counter:
  * @timer:
@@ -114,6 +115,7 @@ struct powerdomain {
        const u8 prcm_partition;
        struct clockdomain *pwrdm_clkdms[PWRDM_MAX_CLKDMS];
        struct list_head node;
+       struct list_head voltdm_node;
        int state;
        unsigned state_counter[PWRDM_MAX_PWRSTS];
        unsigned ret_logic_off_counter;
index 48a2593878c6b4ce5e3b67e4afde78aa318c6a48..1e5c1225e2bebdbf55d70ccbf034449aec05ac5c 100644 (file)
@@ -36,6 +36,7 @@
 #include "control.h"
 
 #include "voltage.h"
+#include "powerdomain.h"
 
 #include "vc.h"
 #include "vp.h"
@@ -1085,11 +1086,90 @@ static struct voltagedomain *_voltdm_lookup(const char *name)
        return voltdm;
 }
 
+/**
+ * voltdm_add_pwrdm - add a powerdomain to a voltagedomain
+ * @voltdm: struct voltagedomain * to add the powerdomain to
+ * @pwrdm: struct powerdomain * to associate with a voltagedomain
+ *
+ * Associate the powerdomain @pwrdm with a voltagedomain @voltdm.  This
+ * enables the use of voltdm_for_each_pwrdm().  Returns -EINVAL if
+ * presented with invalid pointers; -ENOMEM if memory could not be allocated;
+ * or 0 upon success.
+ */
+int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm)
+{
+       if (!voltdm || !pwrdm)
+               return -EINVAL;
+
+       pr_debug("voltagedomain: associating powerdomain %s with voltagedomain "
+                "%s\n", pwrdm->name, voltdm->name);
+
+       list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list);
+
+       return 0;
+}
+
+/**
+ * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
+ * @voltdm: struct voltagedomain * to iterate over
+ * @fn: callback function *
+ *
+ * Call the supplied function @fn for each powerdomain in the
+ * voltagedomain @voltdm.  Returns -EINVAL if presented with invalid
+ * pointers; or passes along the last return value of the callback
+ * function, which should be 0 for success or anything else to
+ * indicate failure.
+ */
+int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
+                         int (*fn)(struct voltagedomain *voltdm,
+                                   struct powerdomain *pwrdm))
+{
+       struct powerdomain *pwrdm;
+       int ret = 0;
+
+       if (!fn)
+               return -EINVAL;
+
+       list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node)
+               ret = (*fn)(voltdm, pwrdm);
+
+       return ret;
+}
+
+/**
+ * voltdm_for_each - call function on each registered voltagedomain
+ * @fn: callback function *
+ *
+ * Call the supplied function @fn for each registered voltagedomain.
+ * The callback function @fn can return anything but 0 to bail out
+ * early from the iterator.  Returns the last return value of the
+ * callback function, which should be 0 for success or anything else
+ * to indicate failure; or -EINVAL if the function pointer is null.
+ */
+int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
+                   void *user)
+{
+       struct voltagedomain *temp_voltdm;
+       int ret = 0;
+
+       if (!fn)
+               return -EINVAL;
+
+       list_for_each_entry(temp_voltdm, &voltdm_list, node) {
+               ret = (*fn)(temp_voltdm, user);
+               if (ret)
+                       break;
+       }
+
+       return ret;
+}
+
 static int _voltdm_register(struct voltagedomain *voltdm)
 {
        if (!voltdm || !voltdm->name)
                return -EINVAL;
 
+       INIT_LIST_HEAD(&voltdm->pwrdm_list);
        list_add(&voltdm->node, &voltdm_list);
 
        pr_debug("voltagedomain: registered %s\n", voltdm->name);
index 966aa888034508991a6e2320a467cba49049cb33..5063ab33af7bc60b6539d381a1702d3929e45b74 100644 (file)
@@ -19,6 +19,8 @@
 #include "vc.h"
 #include "vp.h"
 
+struct powerdomain;
+
 /* XXX document */
 #define VOLTSCALE_VPFORCEUPDATE                1
 #define VOLTSCALE_VCBYPASS             2
@@ -55,12 +57,14 @@ struct omap_vfsm_instance_data {
  * @name: Name of the voltage domain which can be used as a unique identifier.
  * @scalable: Whether or not this voltage domain is scalable
  * @node: list_head linking all voltage domains
+ * @pwrdm_list: list_head linking all powerdomains in this voltagedomain
  * @vdd: to be removed
  */
 struct voltagedomain {
        char *name;
        bool scalable;
        struct list_head node;
+       struct list_head pwrdm_list;
        struct omap_vdd_info *vdd;
 };
 
@@ -187,4 +191,9 @@ extern void omap44xx_voltagedomains_init(void);
 struct voltagedomain *voltdm_lookup(const char *name);
 void voltdm_init(struct voltagedomain **voltdm_list);
 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm);
+int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
+                   void *user);
+int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
+                         int (*fn)(struct voltagedomain *voltdm,
+                                   struct powerdomain *pwrdm));
 #endif