f31fd5dd9b05342e2d58c7ab839be94c27fcc2cc
[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-3.0 / pm-wip / voltdm / 0108-OMAP2-voltage-keep-track-of-powerdomains-in-each-vol.patch
1 From 6575b52f36e82696802c1eee40bbad5bebedeab7 Mon Sep 17 00:00:00 2001
2 From: Kevin Hilman <khilman@ti.com>
3 Date: Wed, 16 Mar 2011 16:13:15 -0700
4 Subject: [PATCH 108/149] OMAP2+: voltage: keep track of powerdomains in each voltagedomain
6 When a powerdomain is registered and it has an associated voltage domain,
7 add the powerdomain to the voltagedomain using voltdm_add_pwrdm().
9 Also add voltagedomain iterator helper functions to iterate over all
10 registered voltagedomains and all powerdomains associated with a
11 voltagedomain.
13 Modeled after a similar relationship between clockdomains and powerdomains.
15 Signed-off-by: Kevin Hilman <khilman@ti.com>
16 ---
17 arch/arm/mach-omap2/powerdomain.c | 2 +
18 arch/arm/mach-omap2/powerdomain.h | 2 +
19 arch/arm/mach-omap2/voltage.c | 80 +++++++++++++++++++++++++++++++++++++
20 arch/arm/mach-omap2/voltage.h | 10 +++++
21 4 files changed, 94 insertions(+), 0 deletions(-)
23 diff --git a/arch/arm/mach-omap2/powerdomain.c b/arch/arm/mach-omap2/powerdomain.c
24 index 1d3013d..12135e2 100644
25 --- a/arch/arm/mach-omap2/powerdomain.c
26 +++ b/arch/arm/mach-omap2/powerdomain.c
27 @@ -102,6 +102,8 @@ static int _pwrdm_register(struct powerdomain *pwrdm)
28 return -EINVAL;
29 }
30 pwrdm->voltdm.ptr = voltdm;
31 + INIT_LIST_HEAD(&pwrdm->voltdm_node);
32 + voltdm_add_pwrdm(voltdm, pwrdm);
34 list_add(&pwrdm->node, &pwrdm_list);
36 diff --git a/arch/arm/mach-omap2/powerdomain.h b/arch/arm/mach-omap2/powerdomain.h
37 index 25bef48..2c685a5 100644
38 --- a/arch/arm/mach-omap2/powerdomain.h
39 +++ b/arch/arm/mach-omap2/powerdomain.h
40 @@ -92,6 +92,7 @@ struct powerdomain;
41 * @pwrsts_mem_on: Possible memory bank pwrstates when pwrdm in ON
42 * @pwrdm_clkdms: Clockdomains in this powerdomain
43 * @node: list_head linking all powerdomains
44 + * @voltdm_node: list_head linking all powerdomains in a voltagedomain
45 * @state:
46 * @state_counter:
47 * @timer:
48 @@ -116,6 +117,7 @@ struct powerdomain {
49 const u8 prcm_partition;
50 struct clockdomain *pwrdm_clkdms[PWRDM_MAX_CLKDMS];
51 struct list_head node;
52 + struct list_head voltdm_node;
53 int state;
54 unsigned state_counter[PWRDM_MAX_PWRSTS];
55 unsigned ret_logic_off_counter;
56 diff --git a/arch/arm/mach-omap2/voltage.c b/arch/arm/mach-omap2/voltage.c
57 index 48a2593..1e5c122 100644
58 --- a/arch/arm/mach-omap2/voltage.c
59 +++ b/arch/arm/mach-omap2/voltage.c
60 @@ -36,6 +36,7 @@
61 #include "control.h"
63 #include "voltage.h"
64 +#include "powerdomain.h"
66 #include "vc.h"
67 #include "vp.h"
68 @@ -1085,11 +1086,90 @@ static struct voltagedomain *_voltdm_lookup(const char *name)
69 return voltdm;
70 }
72 +/**
73 + * voltdm_add_pwrdm - add a powerdomain to a voltagedomain
74 + * @voltdm: struct voltagedomain * to add the powerdomain to
75 + * @pwrdm: struct powerdomain * to associate with a voltagedomain
76 + *
77 + * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This
78 + * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if
79 + * presented with invalid pointers; -ENOMEM if memory could not be allocated;
80 + * or 0 upon success.
81 + */
82 +int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm)
83 +{
84 + if (!voltdm || !pwrdm)
85 + return -EINVAL;
86 +
87 + pr_debug("voltagedomain: associating powerdomain %s with voltagedomain "
88 + "%s\n", pwrdm->name, voltdm->name);
89 +
90 + list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list);
91 +
92 + return 0;
93 +}
94 +
95 +/**
96 + * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
97 + * @voltdm: struct voltagedomain * to iterate over
98 + * @fn: callback function *
99 + *
100 + * Call the supplied function @fn for each powerdomain in the
101 + * voltagedomain @voltdm. Returns -EINVAL if presented with invalid
102 + * pointers; or passes along the last return value of the callback
103 + * function, which should be 0 for success or anything else to
104 + * indicate failure.
105 + */
106 +int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
107 + int (*fn)(struct voltagedomain *voltdm,
108 + struct powerdomain *pwrdm))
109 +{
110 + struct powerdomain *pwrdm;
111 + int ret = 0;
112 +
113 + if (!fn)
114 + return -EINVAL;
115 +
116 + list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node)
117 + ret = (*fn)(voltdm, pwrdm);
118 +
119 + return ret;
120 +}
121 +
122 +/**
123 + * voltdm_for_each - call function on each registered voltagedomain
124 + * @fn: callback function *
125 + *
126 + * Call the supplied function @fn for each registered voltagedomain.
127 + * The callback function @fn can return anything but 0 to bail out
128 + * early from the iterator. Returns the last return value of the
129 + * callback function, which should be 0 for success or anything else
130 + * to indicate failure; or -EINVAL if the function pointer is null.
131 + */
132 +int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
133 + void *user)
134 +{
135 + struct voltagedomain *temp_voltdm;
136 + int ret = 0;
137 +
138 + if (!fn)
139 + return -EINVAL;
140 +
141 + list_for_each_entry(temp_voltdm, &voltdm_list, node) {
142 + ret = (*fn)(temp_voltdm, user);
143 + if (ret)
144 + break;
145 + }
146 +
147 + return ret;
148 +}
149 +
150 static int _voltdm_register(struct voltagedomain *voltdm)
151 {
152 if (!voltdm || !voltdm->name)
153 return -EINVAL;
155 + INIT_LIST_HEAD(&voltdm->pwrdm_list);
156 list_add(&voltdm->node, &voltdm_list);
158 pr_debug("voltagedomain: registered %s\n", voltdm->name);
159 diff --git a/arch/arm/mach-omap2/voltage.h b/arch/arm/mach-omap2/voltage.h
160 index 966aa88..b41d9f1 100644
161 --- a/arch/arm/mach-omap2/voltage.h
162 +++ b/arch/arm/mach-omap2/voltage.h
163 @@ -19,6 +19,8 @@
164 #include "vc.h"
165 #include "vp.h"
167 +struct powerdomain;
168 +
169 /* XXX document */
170 #define VOLTSCALE_VPFORCEUPDATE 1
171 #define VOLTSCALE_VCBYPASS 2
172 @@ -55,12 +57,15 @@ struct omap_vfsm_instance_data {
173 * @name: Name of the voltage domain which can be used as a unique identifier.
174 * @scalable: Whether or not this voltage domain is scalable
175 * @node: list_head linking all voltage domains
176 + * @pwrdm_node: list_head linking all powerdomains in this voltagedomain
177 * @vdd: to be removed
178 + * @pwrdms: powerdomains in this voltagedomain
179 */
180 struct voltagedomain {
181 char *name;
182 bool scalable;
183 struct list_head node;
184 + struct list_head pwrdm_list;
185 struct omap_vdd_info *vdd;
186 };
188 @@ -187,4 +192,9 @@ extern void omap44xx_voltagedomains_init(void);
189 struct voltagedomain *voltdm_lookup(const char *name);
190 void voltdm_init(struct voltagedomain **voltdm_list);
191 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm);
192 +int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
193 + void *user);
194 +int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
195 + int (*fn)(struct voltagedomain *voltdm,
196 + struct powerdomain *pwrdm));
197 #endif
198 --
199 1.6.6.1