58c8723d45d3b233f8077f1834fea74b798edb1d
[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-3.0 / pm-wip / voltdm / 0099-OMAP2-voltage-start-towards-a-new-voltagedomain-laye.patch
1 From 1de34a7da5240cb0ab762a7fbb9d9f0f6ab35253 Mon Sep 17 00:00:00 2001
2 From: Kevin Hilman <khilman@ti.com>
3 Date: Wed, 16 Mar 2011 14:25:45 -0700
4 Subject: [PATCH 099/149] OMAP2+: voltage: start towards a new voltagedomain layer
6 Start cleaning up the voltage layer to have a voltage domain layer
7 that resembles the structure of the existing clock and power domain
8 layers. To that end:
10 - move the 'struct voltagedomain' out of 'struct omap_vdd_info' to
11 become the primary data structure.
13 - convert any functions taking a pointer to struct omap_vdd_info into
14 functions taking a struct voltagedomain pointer.
16 - convert the register & initialize of voltage domains to look like
17 that of powerdomains
19 - convert omap_voltage_domain_lookup() to voltdm_lookup(), modeled
20 after the current powerdomain and clockdomain lookup functions.
22 - omap_voltage_late_init(): only configure VDD info when
23 the vdd_info struct is non-NULL
25 Signed-off-by: Kevin Hilman <khilman@ti.com>
26 ---
27 arch/arm/mach-omap2/io.c | 3 +
28 arch/arm/mach-omap2/omap_twl.c | 10 +-
29 arch/arm/mach-omap2/pm.c | 2 +-
30 arch/arm/mach-omap2/sr_device.c | 2 +-
31 arch/arm/mach-omap2/voltage.c | 257 ++++++++++++++-----------
32 arch/arm/mach-omap2/voltage.h | 27 ++--
33 arch/arm/mach-omap2/voltagedomains3xxx_data.c | 34 ++--
34 arch/arm/mach-omap2/voltagedomains44xx_data.c | 44 ++--
35 8 files changed, 207 insertions(+), 172 deletions(-)
37 diff --git a/arch/arm/mach-omap2/io.c b/arch/arm/mach-omap2/io.c
38 index 2ce1ce6..9f5a846 100644
39 --- a/arch/arm/mach-omap2/io.c
40 +++ b/arch/arm/mach-omap2/io.c
41 @@ -38,6 +38,7 @@
42 #include "io.h"
44 #include <plat/omap-pm.h>
45 +#include "voltage.h"
46 #include "powerdomain.h"
48 #include "clockdomain.h"
49 @@ -349,10 +350,12 @@ void __init omap2_init_common_infrastructure(void)
50 omap2xxx_clockdomains_init();
51 omap2430_hwmod_init();
52 } else if (cpu_is_omap34xx()) {
53 + omap3xxx_voltagedomains_init();
54 omap3xxx_powerdomains_init();
55 omap3xxx_clockdomains_init();
56 omap3xxx_hwmod_init();
57 } else if (cpu_is_omap44xx()) {
58 + omap44xx_voltagedomains_init();
59 omap44xx_powerdomains_init();
60 omap44xx_clockdomains_init();
61 omap44xx_hwmod_init();
62 diff --git a/arch/arm/mach-omap2/omap_twl.c b/arch/arm/mach-omap2/omap_twl.c
63 index 07d6140..fcd2f62 100644
64 --- a/arch/arm/mach-omap2/omap_twl.c
65 +++ b/arch/arm/mach-omap2/omap_twl.c
66 @@ -250,13 +250,13 @@ int __init omap4_twl_init(void)
67 if (!cpu_is_omap44xx())
68 return -ENODEV;
70 - voltdm = omap_voltage_domain_lookup("mpu");
71 + voltdm = voltdm_lookup("mpu");
72 omap_voltage_register_pmic(voltdm, &omap4_mpu_volt_info);
74 - voltdm = omap_voltage_domain_lookup("iva");
75 + voltdm = voltdm_lookup("iva");
76 omap_voltage_register_pmic(voltdm, &omap4_iva_volt_info);
78 - voltdm = omap_voltage_domain_lookup("core");
79 + voltdm = voltdm_lookup("core");
80 omap_voltage_register_pmic(voltdm, &omap4_core_volt_info);
82 return 0;
83 @@ -288,10 +288,10 @@ int __init omap3_twl_init(void)
84 if (!twl_sr_enable_autoinit)
85 omap3_twl_set_sr_bit(true);
87 - voltdm = omap_voltage_domain_lookup("mpu");
88 + voltdm = voltdm_lookup("mpu");
89 omap_voltage_register_pmic(voltdm, &omap3_mpu_volt_info);
91 - voltdm = omap_voltage_domain_lookup("core");
92 + voltdm = voltdm_lookup("core");
93 omap_voltage_register_pmic(voltdm, &omap3_core_volt_info);
95 return 0;
96 diff --git a/arch/arm/mach-omap2/pm.c b/arch/arm/mach-omap2/pm.c
97 index 3feb359..3bce29b 100644
98 --- a/arch/arm/mach-omap2/pm.c
99 +++ b/arch/arm/mach-omap2/pm.c
100 @@ -183,7 +183,7 @@ static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
101 goto exit;
102 }
104 - voltdm = omap_voltage_domain_lookup(vdd_name);
105 + voltdm = voltdm_lookup(vdd_name);
106 if (IS_ERR(voltdm)) {
107 printk(KERN_ERR "%s: Unable to get vdd pointer for vdd_%s\n",
108 __func__, vdd_name);
109 diff --git a/arch/arm/mach-omap2/sr_device.c b/arch/arm/mach-omap2/sr_device.c
110 index 10d3c5e..2782d3f 100644
111 --- a/arch/arm/mach-omap2/sr_device.c
112 +++ b/arch/arm/mach-omap2/sr_device.c
113 @@ -102,7 +102,7 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
114 sr_data->senn_mod = 0x1;
115 sr_data->senp_mod = 0x1;
117 - sr_data->voltdm = omap_voltage_domain_lookup(oh->vdd_name);
118 + sr_data->voltdm = voltdm_lookup(oh->vdd_name);
119 if (IS_ERR(sr_data->voltdm)) {
120 pr_err("%s: Unable to get voltage domain pointer for VDD %s\n",
121 __func__, oh->vdd_name);
122 diff --git a/arch/arm/mach-omap2/voltage.c b/arch/arm/mach-omap2/voltage.c
123 index a366a6b..4f0361a 100644
124 --- a/arch/arm/mach-omap2/voltage.c
125 +++ b/arch/arm/mach-omap2/voltage.c
126 @@ -40,20 +40,13 @@
127 #include "vc.h"
128 #include "vp.h"
130 -#define VOLTAGE_DIR_SIZE 16
131 -
132 -
133 -static struct omap_vdd_info **vdd_info;
134 -
135 -/*
136 - * Number of scalable voltage domains.
137 - */
138 -static int nr_scalable_vdd;
139 +static LIST_HEAD(voltdm_list);
141 +#define VOLTAGE_DIR_SIZE 16
142 static struct dentry *voltage_dir;
144 /* Init function pointers */
145 -static int vp_forceupdate_scale_voltage(struct omap_vdd_info *vdd,
146 +static int vp_forceupdate_scale_voltage(struct voltagedomain *voltdm,
147 unsigned long target_volt);
149 static u32 omap3_voltage_read_reg(u16 mod, u8 offset)
150 @@ -77,11 +70,12 @@ static void omap4_voltage_write_reg(u32 val, u16 mod, u8 offset)
151 omap4_prminst_write_inst_reg(val, OMAP4430_PRM_PARTITION, mod, offset);
152 }
154 -static int __init _config_common_vdd_data(struct omap_vdd_info *vdd)
155 +static int __init _config_common_vdd_data(struct voltagedomain *voltdm)
156 {
157 char *sys_ck_name;
158 struct clk *sys_ck;
159 u32 sys_clk_speed, timeout_val, waittime;
160 + struct omap_vdd_info *vdd = voltdm->vdd;
162 /*
163 * XXX Clockfw should handle this, or this should be in a
164 @@ -101,7 +95,7 @@ static int __init _config_common_vdd_data(struct omap_vdd_info *vdd)
165 sys_ck = clk_get(NULL, sys_ck_name);
166 if (IS_ERR(sys_ck)) {
167 pr_warning("%s: Could not get the sys clk to calculate"
168 - "various vdd_%s params\n", __func__, vdd->voltdm.name);
169 + "various vdd_%s params\n", __func__, voltdm->name);
170 return -EINVAL;
171 }
172 sys_clk_speed = clk_get_rate(sys_ck);
173 @@ -135,7 +129,8 @@ static int __init _config_common_vdd_data(struct omap_vdd_info *vdd)
174 /* Voltage debugfs support */
175 static int vp_volt_debug_get(void *data, u64 *val)
176 {
177 - struct omap_vdd_info *vdd = (struct omap_vdd_info *) data;
178 + struct voltagedomain *voltdm = (struct voltagedomain *)data;
179 + struct omap_vdd_info *vdd = voltdm->vdd;
180 u8 vsel;
182 if (!vdd) {
183 @@ -157,14 +152,14 @@ static int vp_volt_debug_get(void *data, u64 *val)
185 static int nom_volt_debug_get(void *data, u64 *val)
186 {
187 - struct omap_vdd_info *vdd = (struct omap_vdd_info *) data;
188 + struct voltagedomain *voltdm = (struct voltagedomain *)data;
190 - if (!vdd) {
191 + if (!voltdm) {
192 pr_warning("Wrong paramater passed\n");
193 return -EINVAL;
194 }
196 - *val = omap_voltage_get_nom_volt(&vdd->voltdm);
197 + *val = omap_voltage_get_nom_volt(voltdm);
199 return 0;
200 }
201 @@ -172,16 +167,17 @@ static int nom_volt_debug_get(void *data, u64 *val)
202 DEFINE_SIMPLE_ATTRIBUTE(vp_volt_debug_fops, vp_volt_debug_get, NULL, "%llu\n");
203 DEFINE_SIMPLE_ATTRIBUTE(nom_volt_debug_fops, nom_volt_debug_get, NULL,
204 "%llu\n");
205 -static void vp_latch_vsel(struct omap_vdd_info *vdd)
206 +static void vp_latch_vsel(struct voltagedomain *voltdm)
207 {
208 u32 vpconfig;
209 unsigned long uvdc;
210 char vsel;
211 + struct omap_vdd_info *vdd = voltdm->vdd;
213 - uvdc = omap_voltage_get_nom_volt(&vdd->voltdm);
214 + uvdc = omap_voltage_get_nom_volt(voltdm);
215 if (!uvdc) {
216 pr_warning("%s: unable to find current voltage for vdd_%s\n",
217 - __func__, vdd->voltdm.name);
218 + __func__, voltdm->name);
219 return;
220 }
222 @@ -209,13 +205,14 @@ static void vp_latch_vsel(struct omap_vdd_info *vdd)
223 }
225 /* Generic voltage init functions */
226 -static void __init vp_init(struct omap_vdd_info *vdd)
227 +static void __init vp_init(struct voltagedomain *voltdm)
228 {
229 + struct omap_vdd_info *vdd = voltdm->vdd;
230 u32 vp_val;
232 if (!vdd->read_reg || !vdd->write_reg) {
233 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
234 - __func__, vdd->voltdm.name);
235 + __func__, voltdm->name);
236 return;
237 }
239 @@ -246,25 +243,26 @@ static void __init vp_init(struct omap_vdd_info *vdd)
240 vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vlimitto);
241 }
243 -static void __init vdd_debugfs_init(struct omap_vdd_info *vdd)
244 +static void __init vdd_debugfs_init(struct voltagedomain *voltdm)
245 {
246 char *name;
247 + struct omap_vdd_info *vdd = voltdm->vdd;
249 name = kzalloc(VOLTAGE_DIR_SIZE, GFP_KERNEL);
250 if (!name) {
251 pr_warning("%s: Unable to allocate memory for debugfs"
252 " directory name for vdd_%s",
253 - __func__, vdd->voltdm.name);
254 + __func__, voltdm->name);
255 return;
256 }
257 strcpy(name, "vdd_");
258 - strcat(name, vdd->voltdm.name);
259 + strcat(name, voltdm->name);
261 vdd->debug_dir = debugfs_create_dir(name, voltage_dir);
262 kfree(name);
263 if (IS_ERR(vdd->debug_dir)) {
264 pr_warning("%s: Unable to create debugfs directory for"
265 - " vdd_%s\n", __func__, vdd->voltdm.name);
266 + " vdd_%s\n", __func__, voltdm->name);
267 vdd->debug_dir = NULL;
268 return;
269 }
270 @@ -288,16 +286,17 @@ static void __init vdd_debugfs_init(struct omap_vdd_info *vdd)
271 (void) debugfs_create_x16("vp_timeout", S_IRUGO, vdd->debug_dir,
272 &(vdd->vp_rt_data.vlimitto_timeout));
273 (void) debugfs_create_file("curr_vp_volt", S_IRUGO, vdd->debug_dir,
274 - (void *) vdd, &vp_volt_debug_fops);
275 + (void *) voltdm, &vp_volt_debug_fops);
276 (void) debugfs_create_file("curr_nominal_volt", S_IRUGO,
277 - vdd->debug_dir, (void *) vdd,
278 + vdd->debug_dir, (void *) voltdm,
279 &nom_volt_debug_fops);
280 }
282 /* Voltage scale and accessory APIs */
283 -static int _pre_volt_scale(struct omap_vdd_info *vdd,
284 +static int _pre_volt_scale(struct voltagedomain *voltdm,
285 unsigned long target_volt, u8 *target_vsel, u8 *current_vsel)
286 {
287 + struct omap_vdd_info *vdd = voltdm->vdd;
288 struct omap_volt_data *volt_data;
289 const struct omap_vc_common_data *vc_common;
290 const struct omap_vp_common_data *vp_common;
291 @@ -309,25 +308,25 @@ static int _pre_volt_scale(struct omap_vdd_info *vdd,
292 /* Check if suffiecient pmic info is available for this vdd */
293 if (!vdd->pmic_info) {
294 pr_err("%s: Insufficient pmic info to scale the vdd_%s\n",
295 - __func__, vdd->voltdm.name);
296 + __func__, voltdm->name);
297 return -EINVAL;
298 }
300 if (!vdd->pmic_info->uv_to_vsel) {
301 pr_err("%s: PMIC function to convert voltage in uV to"
302 "vsel not registered. Hence unable to scale voltage"
303 - "for vdd_%s\n", __func__, vdd->voltdm.name);
304 + "for vdd_%s\n", __func__, voltdm->name);
305 return -ENODATA;
306 }
308 if (!vdd->read_reg || !vdd->write_reg) {
309 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
310 - __func__, vdd->voltdm.name);
311 + __func__, voltdm->name);
312 return -EINVAL;
313 }
315 /* Get volt_data corresponding to target_volt */
316 - volt_data = omap_voltage_get_voltdata(&vdd->voltdm, target_volt);
317 + volt_data = omap_voltage_get_voltdata(voltdm, target_volt);
318 if (IS_ERR(volt_data))
319 volt_data = NULL;
321 @@ -355,9 +354,10 @@ static int _pre_volt_scale(struct omap_vdd_info *vdd,
322 return 0;
323 }
325 -static void _post_volt_scale(struct omap_vdd_info *vdd,
326 +static void _post_volt_scale(struct voltagedomain *voltdm,
327 unsigned long target_volt, u8 target_vsel, u8 current_vsel)
328 {
329 + struct omap_vdd_info *vdd = voltdm->vdd;
330 u32 smps_steps = 0, smps_delay = 0;
332 smps_steps = abs(target_vsel - current_vsel);
333 @@ -370,15 +370,16 @@ static void _post_volt_scale(struct omap_vdd_info *vdd,
334 }
336 /* vc_bypass_scale_voltage - VC bypass method of voltage scaling */
337 -static int vc_bypass_scale_voltage(struct omap_vdd_info *vdd,
338 +static int vc_bypass_scale_voltage(struct voltagedomain *voltdm,
339 unsigned long target_volt)
340 {
341 + struct omap_vdd_info *vdd = voltdm->vdd;
342 u32 loop_cnt = 0, retries_cnt = 0;
343 u32 vc_valid, vc_bypass_val_reg, vc_bypass_value;
344 u8 target_vsel, current_vsel;
345 int ret;
347 - ret = _pre_volt_scale(vdd, target_volt, &target_vsel, ¤t_vsel);
348 + ret = _pre_volt_scale(voltdm, target_volt, &target_vsel, ¤t_vsel);
349 if (ret)
350 return ret;
352 @@ -417,19 +418,20 @@ static int vc_bypass_scale_voltage(struct omap_vdd_info *vdd,
353 vc_bypass_val_reg);
354 }
356 - _post_volt_scale(vdd, target_volt, target_vsel, current_vsel);
357 + _post_volt_scale(voltdm, target_volt, target_vsel, current_vsel);
358 return 0;
359 }
361 /* VP force update method of voltage scaling */
362 -static int vp_forceupdate_scale_voltage(struct omap_vdd_info *vdd,
363 +static int vp_forceupdate_scale_voltage(struct voltagedomain *voltdm,
364 unsigned long target_volt)
365 {
366 + struct omap_vdd_info *vdd = voltdm->vdd;
367 u32 vpconfig;
368 u8 target_vsel, current_vsel;
369 int ret, timeout = 0;
371 - ret = _pre_volt_scale(vdd, target_volt, &target_vsel, ¤t_vsel);
372 + ret = _pre_volt_scale(voltdm, target_volt, &target_vsel, ¤t_vsel);
373 if (ret)
374 return ret;
376 @@ -447,7 +449,7 @@ static int vp_forceupdate_scale_voltage(struct omap_vdd_info *vdd,
377 }
378 if (timeout >= VP_TRANXDONE_TIMEOUT) {
379 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
380 - "Voltage change aborted", __func__, vdd->voltdm.name);
381 + "Voltage change aborted", __func__, voltdm->name);
382 return -ETIMEDOUT;
383 }
385 @@ -480,9 +482,9 @@ static int vp_forceupdate_scale_voltage(struct omap_vdd_info *vdd,
386 if (timeout >= VP_TRANXDONE_TIMEOUT)
387 pr_err("%s: vdd_%s TRANXDONE timeout exceeded."
388 "TRANXDONE never got set after the voltage update\n",
389 - __func__, vdd->voltdm.name);
390 + __func__, voltdm->name);
392 - _post_volt_scale(vdd, target_volt, target_vsel, current_vsel);
393 + _post_volt_scale(voltdm, target_volt, target_vsel, current_vsel);
395 /*
396 * Disable TransactionDone interrupt , clear all status, clear
397 @@ -501,7 +503,7 @@ static int vp_forceupdate_scale_voltage(struct omap_vdd_info *vdd,
398 if (timeout >= VP_TRANXDONE_TIMEOUT)
399 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying"
400 "to clear the TRANXDONE status\n",
401 - __func__, vdd->voltdm.name);
402 + __func__, voltdm->name);
404 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
405 /* Clear initVDD copy trigger bit */
406 @@ -514,8 +516,10 @@ static int vp_forceupdate_scale_voltage(struct omap_vdd_info *vdd,
407 return 0;
408 }
410 -static void __init omap3_vfsm_init(struct omap_vdd_info *vdd)
411 +static void __init omap3_vfsm_init(struct voltagedomain *voltdm)
412 {
413 + struct omap_vdd_info *vdd = voltdm->vdd;
414 +
415 /*
416 * Voltage Manager FSM parameters init
417 * XXX This data should be passed in from the board file
418 @@ -527,8 +531,9 @@ static void __init omap3_vfsm_init(struct omap_vdd_info *vdd)
419 OMAP3_PRM_VOLTSETUP2_OFFSET);
420 }
422 -static void __init omap3_vc_init(struct omap_vdd_info *vdd)
423 +static void __init omap3_vc_init(struct voltagedomain *voltdm)
424 {
425 + struct omap_vdd_info *vdd = voltdm->vdd;
426 static bool is_initialized;
427 u8 on_vsel, onlp_vsel, ret_vsel, off_vsel;
428 u32 vc_val;
429 @@ -556,15 +561,16 @@ static void __init omap3_vc_init(struct omap_vdd_info *vdd)
430 vdd->write_reg(OMAP3430_MCODE_SHIFT | OMAP3430_HSEN_MASK, vdd->vc_data->vc_common->prm_mod,
431 OMAP3_PRM_VC_I2C_CFG_OFFSET);
433 - omap3_vfsm_init(vdd);
434 + omap3_vfsm_init(voltdm);
436 is_initialized = true;
437 }
440 /* OMAP4 specific voltage init functions */
441 -static void __init omap4_vc_init(struct omap_vdd_info *vdd)
442 +static void __init omap4_vc_init(struct voltagedomain *voltdm)
443 {
444 + struct omap_vdd_info *vdd = voltdm->vdd;
445 static bool is_initialized;
446 u32 vc_val;
448 @@ -589,20 +595,21 @@ static void __init omap4_vc_init(struct omap_vdd_info *vdd)
449 is_initialized = true;
450 }
452 -static void __init omap_vc_init(struct omap_vdd_info *vdd)
453 +static void __init omap_vc_init(struct voltagedomain *voltdm)
454 {
455 + struct omap_vdd_info *vdd = voltdm->vdd;
456 u32 vc_val;
458 if (!vdd->pmic_info || !vdd->pmic_info->uv_to_vsel) {
459 pr_err("%s: PMIC info requried to configure vc for"
460 "vdd_%s not populated.Hence cannot initialize vc\n",
461 - __func__, vdd->voltdm.name);
462 + __func__, voltdm->name);
463 return;
464 }
466 if (!vdd->read_reg || !vdd->write_reg) {
467 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
468 - __func__, vdd->voltdm.name);
469 + __func__, voltdm->name);
470 return;
471 }
473 @@ -630,23 +637,24 @@ static void __init omap_vc_init(struct omap_vdd_info *vdd)
474 vdd->write_reg(vc_val, vdd->vc_data->vc_common->prm_mod, vdd->vfsm->voltsetup_reg);
476 if (cpu_is_omap34xx())
477 - omap3_vc_init(vdd);
478 + omap3_vc_init(voltdm);
479 else if (cpu_is_omap44xx())
480 - omap4_vc_init(vdd);
481 + omap4_vc_init(voltdm);
482 }
484 -static int __init omap_vdd_data_configure(struct omap_vdd_info *vdd)
485 +static int __init omap_vdd_data_configure(struct voltagedomain *voltdm)
486 {
487 + struct omap_vdd_info *vdd = voltdm->vdd;
488 int ret = -EINVAL;
490 if (!vdd->pmic_info) {
491 pr_err("%s: PMIC info requried to configure vdd_%s not"
492 "populated.Hence cannot initialize vdd_%s\n",
493 - __func__, vdd->voltdm.name, vdd->voltdm.name);
494 + __func__, voltdm->name, voltdm->name);
495 goto ovdc_out;
496 }
498 - if (IS_ERR_VALUE(_config_common_vdd_data(vdd)))
499 + if (IS_ERR_VALUE(_config_common_vdd_data(voltdm)))
500 goto ovdc_out;
502 if (cpu_is_omap34xx()) {
503 @@ -680,7 +688,7 @@ unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm)
504 return 0;
505 }
507 - vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
508 + vdd = voltdm->vdd;
510 return vdd->curr_volt;
511 }
512 @@ -701,7 +709,7 @@ unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
513 return 0;
514 }
516 - vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
517 + vdd = voltdm->vdd;
518 if (!vdd->read_reg) {
519 pr_err("%s: No read API for reading vdd_%s regs\n",
520 __func__, voltdm->name);
521 @@ -736,7 +744,7 @@ void omap_vp_enable(struct voltagedomain *voltdm)
522 return;
523 }
525 - vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
526 + vdd = voltdm->vdd;
527 if (!vdd->read_reg || !vdd->write_reg) {
528 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
529 __func__, voltdm->name);
530 @@ -747,7 +755,7 @@ void omap_vp_enable(struct voltagedomain *voltdm)
531 if (vdd->vp_enabled)
532 return;
534 - vp_latch_vsel(vdd);
535 + vp_latch_vsel(voltdm);
537 /* Enable VP */
538 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
539 @@ -774,7 +782,7 @@ void omap_vp_disable(struct voltagedomain *voltdm)
540 return;
541 }
543 - vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
544 + vdd = voltdm->vdd;
545 if (!vdd->read_reg || !vdd->write_reg) {
546 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
547 __func__, voltdm->name);
548 @@ -827,7 +835,7 @@ int omap_voltage_scale_vdd(struct voltagedomain *voltdm,
549 return -EINVAL;
550 }
552 - vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
553 + vdd = voltdm->vdd;
555 if (!vdd->volt_scale) {
556 pr_err("%s: No voltage scale API registered for vdd_%s\n",
557 @@ -835,7 +843,7 @@ int omap_voltage_scale_vdd(struct voltagedomain *voltdm,
558 return -ENODATA;
559 }
561 - return vdd->volt_scale(vdd, target_volt);
562 + return vdd->volt_scale(voltdm, target_volt);
563 }
565 /**
566 @@ -888,7 +896,7 @@ void omap_voltage_get_volttable(struct voltagedomain *voltdm,
567 return;
568 }
570 - vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
571 + vdd = voltdm->vdd;
573 *volt_data = vdd->volt_data;
574 }
575 @@ -919,7 +927,7 @@ struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
576 return ERR_PTR(-EINVAL);
577 }
579 - vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
580 + vdd = voltdm->vdd;
582 if (!vdd->volt_data) {
583 pr_warning("%s: voltage table does not exist for vdd_%s\n",
584 @@ -957,7 +965,7 @@ int omap_voltage_register_pmic(struct voltagedomain *voltdm,
585 return -EINVAL;
586 }
588 - vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
589 + vdd = voltdm->vdd;
591 vdd->pmic_info = pmic_info;
593 @@ -984,7 +992,7 @@ struct dentry *omap_voltage_get_dbgdir(struct voltagedomain *voltdm)
594 return NULL;
595 }
597 - vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
598 + vdd = voltdm->vdd;
600 return vdd->debug_dir;
601 }
602 @@ -1009,7 +1017,7 @@ void omap_change_voltscale_method(struct voltagedomain *voltdm,
603 return;
604 }
606 - vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
607 + vdd = voltdm->vdd;
609 switch (voltscale_method) {
610 case VOLTSCALE_VPFORCEUPDATE:
611 @@ -1025,38 +1033,6 @@ void omap_change_voltscale_method(struct voltagedomain *voltdm,
612 }
614 /**
615 - * omap_voltage_domain_lookup() - API to get the voltage domain pointer
616 - * @name: Name of the voltage domain
617 - *
618 - * This API looks up in the global vdd_info struct for the
619 - * existence of voltage domain <name>. If it exists, the API returns
620 - * a pointer to the voltage domain structure corresponding to the
621 - * VDD<name>. Else retuns error pointer.
622 - */
623 -struct voltagedomain *omap_voltage_domain_lookup(char *name)
624 -{
625 - int i;
626 -
627 - if (!vdd_info) {
628 - pr_err("%s: Voltage driver init not yet happened.Faulting!\n",
629 - __func__);
630 - return ERR_PTR(-EINVAL);
631 - }
632 -
633 - if (!name) {
634 - pr_err("%s: No name to get the votage domain!\n", __func__);
635 - return ERR_PTR(-EINVAL);
636 - }
637 -
638 - for (i = 0; i < nr_scalable_vdd; i++) {
639 - if (!(strcmp(name, vdd_info[i]->voltdm.name)))
640 - return &vdd_info[i]->voltdm;
641 - }
642 -
643 - return ERR_PTR(-EINVAL);
644 -}
645 -
646 -/**
647 * omap_voltage_late_init() - Init the various voltage parameters
648 *
649 * This API is to be called in the later stages of the
650 @@ -1065,9 +1041,9 @@ struct voltagedomain *omap_voltage_domain_lookup(char *name)
651 */
652 int __init omap_voltage_late_init(void)
653 {
654 - int i;
655 + struct voltagedomain *voltdm;
657 - if (!vdd_info) {
658 + if (list_empty(&voltdm_list)) {
659 pr_err("%s: Voltage driver support not added\n",
660 __func__);
661 return -EINVAL;
662 @@ -1077,22 +1053,81 @@ int __init omap_voltage_late_init(void)
663 if (IS_ERR(voltage_dir))
664 pr_err("%s: Unable to create voltage debugfs main dir\n",
665 __func__);
666 - for (i = 0; i < nr_scalable_vdd; i++) {
667 - if (omap_vdd_data_configure(vdd_info[i]))
668 - continue;
669 - omap_vc_init(vdd_info[i]);
670 - vp_init(vdd_info[i]);
671 - vdd_debugfs_init(vdd_info[i]);
672 + list_for_each_entry(voltdm, &voltdm_list, node) {
673 + if (voltdm->vdd) {
674 + if (omap_vdd_data_configure(voltdm))
675 + continue;
676 + omap_vc_init(voltdm);
677 + vp_init(voltdm);
678 + vdd_debugfs_init(voltdm);
679 + }
680 }
682 return 0;
683 }
685 -/* XXX document */
686 -int __init omap_voltage_early_init(struct omap_vdd_info *omap_vdd_array[],
687 - u8 omap_vdd_count)
688 +static struct voltagedomain *_voltdm_lookup(const char *name)
689 {
690 - vdd_info = omap_vdd_array;
691 - nr_scalable_vdd = omap_vdd_count;
692 + struct voltagedomain *voltdm, *temp_voltdm;
693 +
694 + voltdm = NULL;
695 +
696 + list_for_each_entry(temp_voltdm, &voltdm_list, node) {
697 + if (!strcmp(name, temp_voltdm->name)) {
698 + voltdm = temp_voltdm;
699 + break;
700 + }
701 + }
702 +
703 + return voltdm;
704 +}
705 +
706 +static int _voltdm_register(struct voltagedomain *voltdm)
707 +{
708 + if (!voltdm || !voltdm->name)
709 + return -EINVAL;
710 +
711 + list_add(&voltdm->node, &voltdm_list);
712 +
713 + pr_debug("voltagedomain: registered %s\n", voltdm->name);
714 +
715 return 0;
716 }
717 +
718 +/**
719 + * voltdm_lookup - look up a voltagedomain by name, return a pointer
720 + * @name: name of voltagedomain
721 + *
722 + * Find a registered voltagedomain by its name @name. Returns a pointer
723 + * to the struct voltagedomain if found, or NULL otherwise.
724 + */
725 +struct voltagedomain *voltdm_lookup(const char *name)
726 +{
727 + struct voltagedomain *voltdm ;
728 +
729 + if (!name)
730 + return NULL;
731 +
732 + voltdm = _voltdm_lookup(name);
733 +
734 + return voltdm;
735 +}
736 +
737 +/**
738 + * voltdm_init - set up the voltagedomain layer
739 + * @voltdm_list: array of struct voltagedomain pointers to register
740 + *
741 + * Loop through the array of voltagedomains @voltdm_list, registering all
742 + * that are available on the current CPU. If voltdm_list is supplied
743 + * and not null, all of the referenced voltagedomains will be
744 + * registered. No return value.
745 + */
746 +void voltdm_init(struct voltagedomain **voltdms)
747 +{
748 + struct voltagedomain **v;
749 +
750 + if (voltdms) {
751 + for (v = voltdms; *v; v++)
752 + _voltdm_register(*v);
753 + }
754 +}
755 diff --git a/arch/arm/mach-omap2/voltage.h b/arch/arm/mach-omap2/voltage.h
756 index db23d49..5440298 100644
757 --- a/arch/arm/mach-omap2/voltage.h
758 +++ b/arch/arm/mach-omap2/voltage.h
759 @@ -31,6 +31,8 @@
760 #define OMAP3_VOLTOFFSET 0xff
761 #define OMAP3_VOLTSETUP2 0xff
763 +struct omap_vdd_info;
764 +
765 /**
766 * struct omap_vfsm_instance_data - per-voltage manager FSM register/bitfield
767 * data
768 @@ -50,11 +52,14 @@ struct omap_vfsm_instance_data {
770 /**
771 * struct voltagedomain - omap voltage domain global structure.
772 - * @name: Name of the voltage domain which can be used as a unique
773 - * identifier.
774 + * @name: Name of the voltage domain which can be used as a unique identifier.
775 + * @node: list_head linking all voltage domains
776 + * @vdd: to be removed
777 */
778 struct voltagedomain {
779 char *name;
780 + struct list_head node;
781 + struct omap_vdd_info *vdd;
782 };
784 /**
785 @@ -116,7 +121,6 @@ struct omap_volt_pmic_info {
786 * @vc_data : structure containing various various vc registers,
787 * shifts, masks etc.
788 * @vfsm : voltage manager FSM data
789 - * @voltdm : pointer to the voltage domain structure
790 * @debug_dir : debug directory for this voltage domain.
791 * @curr_volt : current voltage for this vdd.
792 * @prm_irqst_mod : PRM module id used for PRM IRQ status register access
793 @@ -130,7 +134,6 @@ struct omap_vdd_info {
794 struct omap_vp_runtime_data vp_rt_data;
795 struct omap_vc_instance_data *vc_data;
796 const struct omap_vfsm_instance_data *vfsm;
797 - struct voltagedomain voltdm;
798 struct dentry *debug_dir;
799 u32 curr_volt;
800 bool vp_enabled;
801 @@ -139,7 +142,7 @@ struct omap_vdd_info {
802 u8 prm_irqst_reg;
803 u32 (*read_reg) (u16 mod, u8 offset);
804 void (*write_reg) (u32 val, u16 mod, u8 offset);
805 - int (*volt_scale) (struct omap_vdd_info *vdd,
806 + int (*volt_scale) (struct voltagedomain *voltdm,
807 unsigned long target_volt);
808 };
810 @@ -155,16 +158,11 @@ struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
811 unsigned long volt);
812 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm);
813 struct dentry *omap_voltage_get_dbgdir(struct voltagedomain *voltdm);
814 -int __init omap_voltage_early_init(struct omap_vdd_info *omap_vdd_array[],
815 - u8 omap_vdd_count);
816 #ifdef CONFIG_PM
817 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
818 struct omap_volt_pmic_info *pmic_info);
819 void omap_change_voltscale_method(struct voltagedomain *voltdm,
820 int voltscale_method);
821 -/* API to get the voltagedomain pointer */
822 -struct voltagedomain *omap_voltage_domain_lookup(char *name);
823 -
824 int omap_voltage_late_init(void);
825 #else
826 static inline int omap_voltage_register_pmic(struct voltagedomain *voltdm,
827 @@ -178,10 +176,11 @@ static inline int omap_voltage_late_init(void)
828 {
829 return -EINVAL;
830 }
831 -static inline struct voltagedomain *omap_voltage_domain_lookup(char *name)
832 -{
833 - return ERR_PTR(-EINVAL);
834 -}
835 #endif
837 +extern void omap3xxx_voltagedomains_init(void);
838 +extern void omap44xx_voltagedomains_init(void);
839 +
840 +struct voltagedomain *voltdm_lookup(const char *name);
841 +void voltdm_init(struct voltagedomain **voltdm_list);
842 #endif
843 diff --git a/arch/arm/mach-omap2/voltagedomains3xxx_data.c b/arch/arm/mach-omap2/voltagedomains3xxx_data.c
844 index f831f9a..4bee412 100644
845 --- a/arch/arm/mach-omap2/voltagedomains3xxx_data.c
846 +++ b/arch/arm/mach-omap2/voltagedomains3xxx_data.c
847 @@ -43,9 +43,6 @@ static struct omap_vdd_info omap3_vdd1_info = {
848 .vp_data = &omap3_vp1_data,
849 .vc_data = &omap3_vc1_data,
850 .vfsm = &omap3_vdd1_vfsm_data,
851 - .voltdm = {
852 - .name = "mpu",
853 - },
854 };
856 static const struct omap_vfsm_instance_data omap3_vdd2_vfsm_data = {
857 @@ -60,23 +57,26 @@ static struct omap_vdd_info omap3_vdd2_info = {
858 .vp_data = &omap3_vp2_data,
859 .vc_data = &omap3_vc2_data,
860 .vfsm = &omap3_vdd2_vfsm_data,
861 - .voltdm = {
862 - .name = "core",
863 - },
864 };
866 -/* OMAP3 VDD structures */
867 -static struct omap_vdd_info *omap3_vdd_info[] = {
868 - &omap3_vdd1_info,
869 - &omap3_vdd2_info,
870 +static struct voltagedomain omap3_voltdm_mpu = {
871 + .name = "mpu",
872 + .vdd = &omap3_vdd1_info,
873 };
875 -/* OMAP3 specific voltage init functions */
876 -static int __init omap3xxx_voltage_early_init(void)
877 -{
878 - if (!cpu_is_omap34xx())
879 - return 0;
880 +static struct voltagedomain omap3_voltdm_core = {
881 + .name = "core",
882 + .vdd = &omap3_vdd2_info,
883 +};
885 +static struct voltagedomain *voltagedomains_omap3[] __initdata = {
886 + &omap3_voltdm_mpu,
887 + &omap3_voltdm_core,
888 + NULL,
889 +};
890 +
891 +void __init omap3xxx_voltagedomains_init(void)
892 +{
893 /*
894 * XXX Will depend on the process, validation, and binning
895 * for the currently-running IC
896 @@ -89,7 +89,5 @@ static int __init omap3xxx_voltage_early_init(void)
897 omap3_vdd2_info.volt_data = omap34xx_vddcore_volt_data;
898 }
900 - return omap_voltage_early_init(omap3_vdd_info,
901 - ARRAY_SIZE(omap3_vdd_info));
902 + voltdm_init(voltagedomains_omap3);
903 };
904 -core_initcall(omap3xxx_voltage_early_init);
905 diff --git a/arch/arm/mach-omap2/voltagedomains44xx_data.c b/arch/arm/mach-omap2/voltagedomains44xx_data.c
906 index 64dc265..245fdf9 100644
907 --- a/arch/arm/mach-omap2/voltagedomains44xx_data.c
908 +++ b/arch/arm/mach-omap2/voltagedomains44xx_data.c
909 @@ -42,9 +42,6 @@ static struct omap_vdd_info omap4_vdd_mpu_info = {
910 .vp_data = &omap4_vp_mpu_data,
911 .vc_data = &omap4_vc_mpu_data,
912 .vfsm = &omap4_vdd_mpu_vfsm_data,
913 - .voltdm = {
914 - .name = "mpu",
915 - },
916 };
918 static const struct omap_vfsm_instance_data omap4_vdd_iva_vfsm_data = {
919 @@ -57,9 +54,6 @@ static struct omap_vdd_info omap4_vdd_iva_info = {
920 .vp_data = &omap4_vp_iva_data,
921 .vc_data = &omap4_vc_iva_data,
922 .vfsm = &omap4_vdd_iva_vfsm_data,
923 - .voltdm = {
924 - .name = "iva",
925 - },
926 };
928 static const struct omap_vfsm_instance_data omap4_vdd_core_vfsm_data = {
929 @@ -72,24 +66,32 @@ static struct omap_vdd_info omap4_vdd_core_info = {
930 .vp_data = &omap4_vp_core_data,
931 .vc_data = &omap4_vc_core_data,
932 .vfsm = &omap4_vdd_core_vfsm_data,
933 - .voltdm = {
934 - .name = "core",
935 - },
936 };
938 -/* OMAP4 VDD structures */
939 -static struct omap_vdd_info *omap4_vdd_info[] = {
940 - &omap4_vdd_mpu_info,
941 - &omap4_vdd_iva_info,
942 - &omap4_vdd_core_info,
943 +static struct voltagedomain omap4_voltdm_mpu = {
944 + .name = "mpu",
945 + .vdd = &omap4_vdd_mpu_info,
946 };
948 -/* OMAP4 specific voltage init functions */
949 -static int __init omap44xx_voltage_early_init(void)
950 -{
951 - if (!cpu_is_omap44xx())
952 - return 0;
953 +static struct voltagedomain omap4_voltdm_iva = {
954 + .name = "iva",
955 + .vdd = &omap4_vdd_iva_info,
956 +};
957 +
958 +static struct voltagedomain omap4_voltdm_core = {
959 + .name = "core",
960 + .vdd = &omap4_vdd_core_info,
961 +};
963 +static struct voltagedomain *voltagedomains_omap4[] __initdata = {
964 + &omap4_voltdm_mpu,
965 + &omap4_voltdm_iva,
966 + &omap4_voltdm_core,
967 + NULL,
968 +};
969 +
970 +void __init omap44xx_voltagedomains_init(void)
971 +{
972 /*
973 * XXX Will depend on the process, validation, and binning
974 * for the currently-running IC
975 @@ -98,7 +100,5 @@ static int __init omap44xx_voltage_early_init(void)
976 omap4_vdd_iva_info.volt_data = omap44xx_vdd_iva_volt_data;
977 omap4_vdd_core_info.volt_data = omap44xx_vdd_core_volt_data;
979 - return omap_voltage_early_init(omap4_vdd_info,
980 - ARRAY_SIZE(omap4_vdd_info));
981 + voltdm_init(voltagedomains_omap4);
982 };
983 -core_initcall(omap44xx_voltage_early_init);
984 --
985 1.6.6.1