aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorKevin Hilman <khilman@ti.com>2011-03-21 17:29:13 -0400
committerKevin Hilman <khilman@ti.com>2011-09-15 14:39:11 -0400
commit01f48d308db1cfcfb0151d8d91153fd73e84ae40 (patch)
tree2b36a459bb9ea482cdf60cfaf79c4e4996d599dc /arch
parent4d47506a85a9f2e745dc63215594e9f799aff3dc (diff)
OMAP2+: voltage: split out voltage processor (VP) code into new layer
This patch is primarily a move of VP specific code from voltage.c into its own code in vp.c and adds prototypes to vp.h No functional changes, except debugfs... VP debugfs moved to 'vp' subdir of <debugfs>/voltage/ and 'vp_' prefixes removed from all debugfs filenames. Signed-off-by: Kevin Hilman <khilman@ti.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/mach-omap2/Makefile2
-rw-r--r--arch/arm/mach-omap2/voltage.c348
-rw-r--r--arch/arm/mach-omap2/voltage.h3
-rw-r--r--arch/arm/mach-omap2/vp.c374
-rw-r--r--arch/arm/mach-omap2/vp.h9
5 files changed, 387 insertions, 349 deletions
diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index 59db6d9ba244..824718969e31 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -90,7 +90,7 @@ obj-$(CONFIG_ARCH_OMAP4) += prcm.o cm2xxx_3xxx.o cminst44xx.o \
90 90
91# OMAP voltage domains 91# OMAP voltage domains
92ifeq ($(CONFIG_PM),y) 92ifeq ($(CONFIG_PM),y)
93voltagedomain-common := voltage.o vc.o 93voltagedomain-common := voltage.o vc.o vp.o
94obj-$(CONFIG_ARCH_OMAP2) += $(voltagedomain-common) \ 94obj-$(CONFIG_ARCH_OMAP2) += $(voltagedomain-common) \
95 voltagedomains2xxx_data.o 95 voltagedomains2xxx_data.o
96obj-$(CONFIG_ARCH_OMAP3) += $(voltagedomain-common) \ 96obj-$(CONFIG_ARCH_OMAP3) += $(voltagedomain-common) \
diff --git a/arch/arm/mach-omap2/voltage.c b/arch/arm/mach-omap2/voltage.c
index e1a22a3d2f03..9b9f01973d12 100644
--- a/arch/arm/mach-omap2/voltage.c
+++ b/arch/arm/mach-omap2/voltage.c
@@ -46,10 +46,6 @@ static LIST_HEAD(voltdm_list);
46#define VOLTAGE_DIR_SIZE 16 46#define VOLTAGE_DIR_SIZE 16
47static struct dentry *voltage_dir; 47static struct dentry *voltage_dir;
48 48
49/* Init function pointers */
50static int vp_forceupdate_scale_voltage(struct voltagedomain *voltdm,
51 unsigned long target_volt);
52
53static u32 omap3_voltage_read_reg(u16 mod, u8 offset) 49static u32 omap3_voltage_read_reg(u16 mod, u8 offset)
54{ 50{
55 return omap2_prm_read_mod_reg(mod, offset); 51 return omap2_prm_read_mod_reg(mod, offset);
@@ -105,7 +101,7 @@ static int __init _config_common_vdd_data(struct voltagedomain *voltdm)
105 sys_clk_speed /= 1000; 101 sys_clk_speed /= 1000;
106 102
107 /* Generic voltage parameters */ 103 /* Generic voltage parameters */
108 vdd->volt_scale = vp_forceupdate_scale_voltage; 104 vdd->volt_scale = omap_vp_forceupdate_scale;
109 vdd->vp_enabled = false; 105 vdd->vp_enabled = false;
110 106
111 vdd->vp_rt_data.vpconfig_erroroffset = 107 vdd->vp_rt_data.vpconfig_erroroffset =
@@ -127,30 +123,6 @@ static int __init _config_common_vdd_data(struct voltagedomain *voltdm)
127 return 0; 123 return 0;
128} 124}
129 125
130/* Voltage debugfs support */
131static int vp_volt_debug_get(void *data, u64 *val)
132{
133 struct voltagedomain *voltdm = (struct voltagedomain *)data;
134 struct omap_vdd_info *vdd = voltdm->vdd;
135 u8 vsel;
136
137 if (!vdd) {
138 pr_warning("Wrong paramater passed\n");
139 return -EINVAL;
140 }
141
142 vsel = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->voltage);
143
144 if (!vdd->pmic_info->vsel_to_uv) {
145 pr_warning("PMIC function to convert vsel to voltage"
146 "in uV not registerd\n");
147 return -EINVAL;
148 }
149
150 *val = vdd->pmic_info->vsel_to_uv(vsel);
151 return 0;
152}
153
154static int nom_volt_debug_get(void *data, u64 *val) 126static int nom_volt_debug_get(void *data, u64 *val)
155{ 127{
156 struct voltagedomain *voltdm = (struct voltagedomain *)data; 128 struct voltagedomain *voltdm = (struct voltagedomain *)data;
@@ -165,85 +137,8 @@ static int nom_volt_debug_get(void *data, u64 *val)
165 return 0; 137 return 0;
166} 138}
167 139
168DEFINE_SIMPLE_ATTRIBUTE(vp_volt_debug_fops, vp_volt_debug_get, NULL, "%llu\n");
169DEFINE_SIMPLE_ATTRIBUTE(nom_volt_debug_fops, nom_volt_debug_get, NULL, 140DEFINE_SIMPLE_ATTRIBUTE(nom_volt_debug_fops, nom_volt_debug_get, NULL,
170 "%llu\n"); 141 "%llu\n");
171static void vp_latch_vsel(struct voltagedomain *voltdm)
172{
173 u32 vpconfig;
174 unsigned long uvdc;
175 char vsel;
176 struct omap_vdd_info *vdd = voltdm->vdd;
177
178 uvdc = omap_voltage_get_nom_volt(voltdm);
179 if (!uvdc) {
180 pr_warning("%s: unable to find current voltage for vdd_%s\n",
181 __func__, voltdm->name);
182 return;
183 }
184
185 if (!vdd->pmic_info || !vdd->pmic_info->uv_to_vsel) {
186 pr_warning("%s: PMIC function to convert voltage in uV to"
187 " vsel not registered\n", __func__);
188 return;
189 }
190
191 vsel = vdd->pmic_info->uv_to_vsel(uvdc);
192
193 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
194 vpconfig &= ~(vdd->vp_data->vp_common->vpconfig_initvoltage_mask |
195 vdd->vp_data->vp_common->vpconfig_initvdd);
196 vpconfig |= vsel << vdd->vp_data->vp_common->vpconfig_initvoltage_shift;
197
198 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
199
200 /* Trigger initVDD value copy to voltage processor */
201 vdd->write_reg((vpconfig | vdd->vp_data->vp_common->vpconfig_initvdd),
202 vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
203
204 /* Clear initVDD copy trigger bit */
205 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
206}
207
208/* Generic voltage init functions */
209static void __init vp_init(struct voltagedomain *voltdm)
210{
211 struct omap_vdd_info *vdd = voltdm->vdd;
212 u32 vp_val;
213
214 if (!vdd->read_reg || !vdd->write_reg) {
215 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
216 __func__, voltdm->name);
217 return;
218 }
219
220 vp_val = vdd->vp_rt_data.vpconfig_erroroffset |
221 (vdd->vp_rt_data.vpconfig_errorgain <<
222 vdd->vp_data->vp_common->vpconfig_errorgain_shift) |
223 vdd->vp_data->vp_common->vpconfig_timeouten;
224 vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
225
226 vp_val = ((vdd->vp_rt_data.vstepmin_smpswaittimemin <<
227 vdd->vp_data->vp_common->vstepmin_smpswaittimemin_shift) |
228 (vdd->vp_rt_data.vstepmin_stepmin <<
229 vdd->vp_data->vp_common->vstepmin_stepmin_shift));
230 vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vstepmin);
231
232 vp_val = ((vdd->vp_rt_data.vstepmax_smpswaittimemax <<
233 vdd->vp_data->vp_common->vstepmax_smpswaittimemax_shift) |
234 (vdd->vp_rt_data.vstepmax_stepmax <<
235 vdd->vp_data->vp_common->vstepmax_stepmax_shift));
236 vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vstepmax);
237
238 vp_val = ((vdd->vp_rt_data.vlimitto_vddmax <<
239 vdd->vp_data->vp_common->vlimitto_vddmax_shift) |
240 (vdd->vp_rt_data.vlimitto_vddmin <<
241 vdd->vp_data->vp_common->vlimitto_vddmin_shift) |
242 (vdd->vp_rt_data.vlimitto_timeout <<
243 vdd->vp_data->vp_common->vlimitto_timeout_shift));
244 vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vlimitto);
245}
246
247static void __init vdd_debugfs_init(struct voltagedomain *voltdm) 142static void __init vdd_debugfs_init(struct voltagedomain *voltdm)
248{ 143{
249 char *name; 144 char *name;
@@ -268,125 +163,11 @@ static void __init vdd_debugfs_init(struct voltagedomain *voltdm)
268 return; 163 return;
269 } 164 }
270 165
271 (void) debugfs_create_x16("vp_errorgain", S_IRUGO, vdd->debug_dir,
272 &(vdd->vp_rt_data.vpconfig_errorgain));
273 (void) debugfs_create_x16("vp_smpswaittimemin", S_IRUGO,
274 vdd->debug_dir,
275 &(vdd->vp_rt_data.vstepmin_smpswaittimemin));
276 (void) debugfs_create_x8("vp_stepmin", S_IRUGO, vdd->debug_dir,
277 &(vdd->vp_rt_data.vstepmin_stepmin));
278 (void) debugfs_create_x16("vp_smpswaittimemax", S_IRUGO,
279 vdd->debug_dir,
280 &(vdd->vp_rt_data.vstepmax_smpswaittimemax));
281 (void) debugfs_create_x8("vp_stepmax", S_IRUGO, vdd->debug_dir,
282 &(vdd->vp_rt_data.vstepmax_stepmax));
283 (void) debugfs_create_x8("vp_vddmax", S_IRUGO, vdd->debug_dir,
284 &(vdd->vp_rt_data.vlimitto_vddmax));
285 (void) debugfs_create_x8("vp_vddmin", S_IRUGO, vdd->debug_dir,
286 &(vdd->vp_rt_data.vlimitto_vddmin));
287 (void) debugfs_create_x16("vp_timeout", S_IRUGO, vdd->debug_dir,
288 &(vdd->vp_rt_data.vlimitto_timeout));
289 (void) debugfs_create_file("curr_vp_volt", S_IRUGO, vdd->debug_dir,
290 (void *) voltdm, &vp_volt_debug_fops);
291 (void) debugfs_create_file("curr_nominal_volt", S_IRUGO, 166 (void) debugfs_create_file("curr_nominal_volt", S_IRUGO,
292 vdd->debug_dir, (void *) voltdm, 167 vdd->debug_dir, (void *) voltdm,
293 &nom_volt_debug_fops); 168 &nom_volt_debug_fops);
294} 169}
295 170
296/* VP force update method of voltage scaling */
297static int vp_forceupdate_scale_voltage(struct voltagedomain *voltdm,
298 unsigned long target_volt)
299{
300 struct omap_vdd_info *vdd = voltdm->vdd;
301 u32 vpconfig;
302 u8 target_vsel, current_vsel;
303 int ret, timeout = 0;
304
305 ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, &current_vsel);
306 if (ret)
307 return ret;
308
309 /*
310 * Clear all pending TransactionDone interrupt/status. Typical latency
311 * is <3us
312 */
313 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
314 vdd->write_reg(vdd->vp_data->prm_irqst_data->tranxdone_status,
315 vdd->prm_irqst_mod, vdd->prm_irqst_reg);
316 if (!(vdd->read_reg(vdd->prm_irqst_mod, vdd->prm_irqst_reg) &
317 vdd->vp_data->prm_irqst_data->tranxdone_status))
318 break;
319 udelay(1);
320 }
321 if (timeout >= VP_TRANXDONE_TIMEOUT) {
322 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
323 "Voltage change aborted", __func__, voltdm->name);
324 return -ETIMEDOUT;
325 }
326
327 /* Configure for VP-Force Update */
328 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
329 vpconfig &= ~(vdd->vp_data->vp_common->vpconfig_initvdd |
330 vdd->vp_data->vp_common->vpconfig_forceupdate |
331 vdd->vp_data->vp_common->vpconfig_initvoltage_mask);
332 vpconfig |= ((target_vsel <<
333 vdd->vp_data->vp_common->vpconfig_initvoltage_shift));
334 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
335
336 /* Trigger initVDD value copy to voltage processor */
337 vpconfig |= vdd->vp_data->vp_common->vpconfig_initvdd;
338 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
339
340 /* Force update of voltage */
341 vpconfig |= vdd->vp_data->vp_common->vpconfig_forceupdate;
342 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
343
344 /*
345 * Wait for TransactionDone. Typical latency is <200us.
346 * Depends on SMPSWAITTIMEMIN/MAX and voltage change
347 */
348 timeout = 0;
349 omap_test_timeout((vdd->read_reg(vdd->prm_irqst_mod,
350 vdd->prm_irqst_reg) &
351 vdd->vp_data->prm_irqst_data->tranxdone_status),
352 VP_TRANXDONE_TIMEOUT, timeout);
353 if (timeout >= VP_TRANXDONE_TIMEOUT)
354 pr_err("%s: vdd_%s TRANXDONE timeout exceeded."
355 "TRANXDONE never got set after the voltage update\n",
356 __func__, voltdm->name);
357
358 omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel);
359
360 /*
361 * Disable TransactionDone interrupt , clear all status, clear
362 * control registers
363 */
364 timeout = 0;
365 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
366 vdd->write_reg(vdd->vp_data->prm_irqst_data->tranxdone_status,
367 vdd->prm_irqst_mod, vdd->prm_irqst_reg);
368 if (!(vdd->read_reg(vdd->prm_irqst_mod, vdd->prm_irqst_reg) &
369 vdd->vp_data->prm_irqst_data->tranxdone_status))
370 break;
371 udelay(1);
372 }
373
374 if (timeout >= VP_TRANXDONE_TIMEOUT)
375 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying"
376 "to clear the TRANXDONE status\n",
377 __func__, voltdm->name);
378
379 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
380 /* Clear initVDD copy trigger bit */
381 vpconfig &= ~vdd->vp_data->vp_common->vpconfig_initvdd;
382 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
383 /* Clear force bit */
384 vpconfig &= ~vdd->vp_data->vp_common->vpconfig_forceupdate;
385 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
386
387 return 0;
388}
389
390static int __init omap_vdd_data_configure(struct voltagedomain *voltdm) 171static int __init omap_vdd_data_configure(struct voltagedomain *voltdm)
391{ 172{
392 struct omap_vdd_info *vdd = voltdm->vdd; 173 struct omap_vdd_info *vdd = voltdm->vdd;
@@ -439,129 +220,6 @@ unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm)
439} 220}
440 221
441/** 222/**
442 * omap_vp_get_curr_volt() - API to get the current vp voltage.
443 * @voltdm: pointer to the VDD.
444 *
445 * This API returns the current voltage for the specified voltage processor
446 */
447unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
448{
449 struct omap_vdd_info *vdd;
450 u8 curr_vsel;
451
452 if (!voltdm || IS_ERR(voltdm)) {
453 pr_warning("%s: VDD specified does not exist!\n", __func__);
454 return 0;
455 }
456
457 vdd = voltdm->vdd;
458 if (!vdd->read_reg) {
459 pr_err("%s: No read API for reading vdd_%s regs\n",
460 __func__, voltdm->name);
461 return 0;
462 }
463
464 curr_vsel = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->voltage);
465
466 if (!vdd->pmic_info || !vdd->pmic_info->vsel_to_uv) {
467 pr_warning("%s: PMIC function to convert vsel to voltage"
468 "in uV not registerd\n", __func__);
469 return 0;
470 }
471
472 return vdd->pmic_info->vsel_to_uv(curr_vsel);
473}
474
475/**
476 * omap_vp_enable() - API to enable a particular VP
477 * @voltdm: pointer to the VDD whose VP is to be enabled.
478 *
479 * This API enables a particular voltage processor. Needed by the smartreflex
480 * class drivers.
481 */
482void omap_vp_enable(struct voltagedomain *voltdm)
483{
484 struct omap_vdd_info *vdd;
485 u32 vpconfig;
486
487 if (!voltdm || IS_ERR(voltdm)) {
488 pr_warning("%s: VDD specified does not exist!\n", __func__);
489 return;
490 }
491
492 vdd = voltdm->vdd;
493 if (!vdd->read_reg || !vdd->write_reg) {
494 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
495 __func__, voltdm->name);
496 return;
497 }
498
499 /* If VP is already enabled, do nothing. Return */
500 if (vdd->vp_enabled)
501 return;
502
503 vp_latch_vsel(voltdm);
504
505 /* Enable VP */
506 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
507 vpconfig |= vdd->vp_data->vp_common->vpconfig_vpenable;
508 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
509 vdd->vp_enabled = true;
510}
511
512/**
513 * omap_vp_disable() - API to disable a particular VP
514 * @voltdm: pointer to the VDD whose VP is to be disabled.
515 *
516 * This API disables a particular voltage processor. Needed by the smartreflex
517 * class drivers.
518 */
519void omap_vp_disable(struct voltagedomain *voltdm)
520{
521 struct omap_vdd_info *vdd;
522 u32 vpconfig;
523 int timeout;
524
525 if (!voltdm || IS_ERR(voltdm)) {
526 pr_warning("%s: VDD specified does not exist!\n", __func__);
527 return;
528 }
529
530 vdd = voltdm->vdd;
531 if (!vdd->read_reg || !vdd->write_reg) {
532 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
533 __func__, voltdm->name);
534 return;
535 }
536
537 /* If VP is already disabled, do nothing. Return */
538 if (!vdd->vp_enabled) {
539 pr_warning("%s: Trying to disable VP for vdd_%s when"
540 "it is already disabled\n", __func__, voltdm->name);
541 return;
542 }
543
544 /* Disable VP */
545 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
546 vpconfig &= ~vdd->vp_data->vp_common->vpconfig_vpenable;
547 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
548
549 /*
550 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
551 */
552 omap_test_timeout((vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vstatus)),
553 VP_IDLE_TIMEOUT, timeout);
554
555 if (timeout >= VP_IDLE_TIMEOUT)
556 pr_warning("%s: vdd_%s idle timedout\n",
557 __func__, voltdm->name);
558
559 vdd->vp_enabled = false;
560
561 return;
562}
563
564/**
565 * omap_voltage_scale_vdd() - API to scale voltage of a particular 223 * omap_voltage_scale_vdd() - API to scale voltage of a particular
566 * voltage domain. 224 * voltage domain.
567 * @voltdm: pointer to the VDD which is to be scaled. 225 * @voltdm: pointer to the VDD which is to be scaled.
@@ -766,7 +424,7 @@ void omap_change_voltscale_method(struct voltagedomain *voltdm,
766 424
767 switch (voltscale_method) { 425 switch (voltscale_method) {
768 case VOLTSCALE_VPFORCEUPDATE: 426 case VOLTSCALE_VPFORCEUPDATE:
769 vdd->volt_scale = vp_forceupdate_scale_voltage; 427 vdd->volt_scale = omap_vp_forceupdate_scale;
770 return; 428 return;
771 case VOLTSCALE_VCBYPASS: 429 case VOLTSCALE_VCBYPASS:
772 vdd->volt_scale = omap_vc_bypass_scale; 430 vdd->volt_scale = omap_vc_bypass_scale;
@@ -810,8 +468,8 @@ int __init omap_voltage_late_init(void)
810 if (voltdm->vdd) { 468 if (voltdm->vdd) {
811 if (omap_vdd_data_configure(voltdm)) 469 if (omap_vdd_data_configure(voltdm))
812 continue; 470 continue;
813 vp_init(voltdm);
814 vdd_debugfs_init(voltdm); 471 vdd_debugfs_init(voltdm);
472 omap_vp_init(voltdm);
815 } 473 }
816 } 474 }
817 475
diff --git a/arch/arm/mach-omap2/voltage.h b/arch/arm/mach-omap2/voltage.h
index 488576497c88..ea6bb98c63f8 100644
--- a/arch/arm/mach-omap2/voltage.h
+++ b/arch/arm/mach-omap2/voltage.h
@@ -152,9 +152,6 @@ struct omap_vdd_info {
152 unsigned long target_volt); 152 unsigned long target_volt);
153}; 153};
154 154
155unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm);
156void omap_vp_enable(struct voltagedomain *voltdm);
157void omap_vp_disable(struct voltagedomain *voltdm);
158int omap_voltage_scale_vdd(struct voltagedomain *voltdm, 155int omap_voltage_scale_vdd(struct voltagedomain *voltdm,
159 unsigned long target_volt); 156 unsigned long target_volt);
160void omap_voltage_reset(struct voltagedomain *voltdm); 157void omap_voltage_reset(struct voltagedomain *voltdm);
diff --git a/arch/arm/mach-omap2/vp.c b/arch/arm/mach-omap2/vp.c
new file mode 100644
index 000000000000..f3503de5d8fd
--- /dev/null
+++ b/arch/arm/mach-omap2/vp.c
@@ -0,0 +1,374 @@
1#include <linux/kernel.h>
2#include <linux/init.h>
3#include <linux/debugfs.h>
4
5#include <plat/common.h>
6
7#include "voltage.h"
8#include "vp.h"
9#include "prm-regbits-34xx.h"
10#include "prm-regbits-44xx.h"
11#include "prm44xx.h"
12
13static void __init vp_debugfs_init(struct voltagedomain *voltdm);
14
15static void vp_latch_vsel(struct voltagedomain *voltdm)
16{
17 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
18 u32 vpconfig;
19 unsigned long uvdc;
20 char vsel;
21 struct omap_vdd_info *vdd = voltdm->vdd;
22
23 uvdc = omap_voltage_get_nom_volt(voltdm);
24 if (!uvdc) {
25 pr_warning("%s: unable to find current voltage for vdd_%s\n",
26 __func__, voltdm->name);
27 return;
28 }
29
30 if (!vdd->pmic_info || !vdd->pmic_info->uv_to_vsel) {
31 pr_warning("%s: PMIC function to convert voltage in uV to"
32 " vsel not registered\n", __func__);
33 return;
34 }
35
36 vsel = vdd->pmic_info->uv_to_vsel(uvdc);
37
38 vpconfig = vdd->read_reg(vp->vp_common->prm_mod, vp->vpconfig);
39 vpconfig &= ~(vp->vp_common->vpconfig_initvoltage_mask |
40 vp->vp_common->vpconfig_initvdd);
41 vpconfig |= vsel << vp->vp_common->vpconfig_initvoltage_shift;
42
43 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
44
45 /* Trigger initVDD value copy to voltage processor */
46 vdd->write_reg((vpconfig | vp->vp_common->vpconfig_initvdd),
47 vp->vp_common->prm_mod, vp->vpconfig);
48
49 /* Clear initVDD copy trigger bit */
50 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
51}
52
53/* Generic voltage init functions */
54void __init omap_vp_init(struct voltagedomain *voltdm)
55{
56 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
57 struct omap_vdd_info *vdd = voltdm->vdd;
58 u32 vp_val;
59
60 if (!vdd->read_reg || !vdd->write_reg) {
61 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
62 __func__, voltdm->name);
63 return;
64 }
65
66 vp_val = vdd->vp_rt_data.vpconfig_erroroffset |
67 (vdd->vp_rt_data.vpconfig_errorgain <<
68 vp->vp_common->vpconfig_errorgain_shift) |
69 vp->vp_common->vpconfig_timeouten;
70 vdd->write_reg(vp_val, vp->vp_common->prm_mod, vp->vpconfig);
71
72 vp_val = ((vdd->vp_rt_data.vstepmin_smpswaittimemin <<
73 vp->vp_common->vstepmin_smpswaittimemin_shift) |
74 (vdd->vp_rt_data.vstepmin_stepmin <<
75 vp->vp_common->vstepmin_stepmin_shift));
76 vdd->write_reg(vp_val, vp->vp_common->prm_mod, vp->vstepmin);
77
78 vp_val = ((vdd->vp_rt_data.vstepmax_smpswaittimemax <<
79 vp->vp_common->vstepmax_smpswaittimemax_shift) |
80 (vdd->vp_rt_data.vstepmax_stepmax <<
81 vp->vp_common->vstepmax_stepmax_shift));
82 vdd->write_reg(vp_val, vp->vp_common->prm_mod, vp->vstepmax);
83
84 vp_val = ((vdd->vp_rt_data.vlimitto_vddmax <<
85 vp->vp_common->vlimitto_vddmax_shift) |
86 (vdd->vp_rt_data.vlimitto_vddmin <<
87 vp->vp_common->vlimitto_vddmin_shift) |
88 (vdd->vp_rt_data.vlimitto_timeout <<
89 vp->vp_common->vlimitto_timeout_shift));
90 vdd->write_reg(vp_val, vp->vp_common->prm_mod, vp->vlimitto);
91
92 vp_debugfs_init(voltdm);
93}
94
95/* VP force update method of voltage scaling */
96int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
97 unsigned long target_volt)
98{
99 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
100 struct omap_vdd_info *vdd = voltdm->vdd;
101 u32 vpconfig;
102 u8 target_vsel, current_vsel;
103 int ret, timeout = 0;
104
105 ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, &current_vsel);
106 if (ret)
107 return ret;
108
109 /*
110 * Clear all pending TransactionDone interrupt/status. Typical latency
111 * is <3us
112 */
113 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
114 vdd->write_reg(vp->prm_irqst_data->tranxdone_status,
115 vdd->prm_irqst_mod, vdd->prm_irqst_reg);
116 if (!(vdd->read_reg(vdd->prm_irqst_mod, vdd->prm_irqst_reg) &
117 vp->prm_irqst_data->tranxdone_status))
118 break;
119 udelay(1);
120 }
121 if (timeout >= VP_TRANXDONE_TIMEOUT) {
122 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
123 "Voltage change aborted", __func__, voltdm->name);
124 return -ETIMEDOUT;
125 }
126
127 /* Configure for VP-Force Update */
128 vpconfig = vdd->read_reg(vp->vp_common->prm_mod, vp->vpconfig);
129 vpconfig &= ~(vp->vp_common->vpconfig_initvdd |
130 vp->vp_common->vpconfig_forceupdate |
131 vp->vp_common->vpconfig_initvoltage_mask);
132 vpconfig |= ((target_vsel <<
133 vp->vp_common->vpconfig_initvoltage_shift));
134 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
135
136 /* Trigger initVDD value copy to voltage processor */
137 vpconfig |= vp->vp_common->vpconfig_initvdd;
138 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
139
140 /* Force update of voltage */
141 vpconfig |= vp->vp_common->vpconfig_forceupdate;
142 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
143
144 /*
145 * Wait for TransactionDone. Typical latency is <200us.
146 * Depends on SMPSWAITTIMEMIN/MAX and voltage change
147 */
148 timeout = 0;
149 omap_test_timeout((vdd->read_reg(vdd->prm_irqst_mod,
150 vdd->prm_irqst_reg) &
151 vp->prm_irqst_data->tranxdone_status),
152 VP_TRANXDONE_TIMEOUT, timeout);
153 if (timeout >= VP_TRANXDONE_TIMEOUT)
154 pr_err("%s: vdd_%s TRANXDONE timeout exceeded."
155 "TRANXDONE never got set after the voltage update\n",
156 __func__, voltdm->name);
157
158 omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel);
159
160 /*
161 * Disable TransactionDone interrupt , clear all status, clear
162 * control registers
163 */
164 timeout = 0;
165 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
166 vdd->write_reg(vp->prm_irqst_data->tranxdone_status,
167 vdd->prm_irqst_mod, vdd->prm_irqst_reg);
168 if (!(vdd->read_reg(vdd->prm_irqst_mod, vdd->prm_irqst_reg) &
169 vp->prm_irqst_data->tranxdone_status))
170 break;
171 udelay(1);
172 }
173
174 if (timeout >= VP_TRANXDONE_TIMEOUT)
175 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying"
176 "to clear the TRANXDONE status\n",
177 __func__, voltdm->name);
178
179 vpconfig = vdd->read_reg(vp->vp_common->prm_mod, vp->vpconfig);
180 /* Clear initVDD copy trigger bit */
181 vpconfig &= ~vp->vp_common->vpconfig_initvdd;
182 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
183 /* Clear force bit */
184 vpconfig &= ~vp->vp_common->vpconfig_forceupdate;
185 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
186
187 return 0;
188}
189
190/**
191 * omap_vp_get_curr_volt() - API to get the current vp voltage.
192 * @voltdm: pointer to the VDD.
193 *
194 * This API returns the current voltage for the specified voltage processor
195 */
196unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
197{
198 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
199 struct omap_vdd_info *vdd;
200 u8 curr_vsel;
201
202 if (!voltdm || IS_ERR(voltdm)) {
203 pr_warning("%s: VDD specified does not exist!\n", __func__);
204 return 0;
205 }
206
207 vdd = voltdm->vdd;
208 if (!vdd->read_reg) {
209 pr_err("%s: No read API for reading vdd_%s regs\n",
210 __func__, voltdm->name);
211 return 0;
212 }
213
214 curr_vsel = vdd->read_reg(vp->vp_common->prm_mod, vp->voltage);
215
216 if (!vdd->pmic_info || !vdd->pmic_info->vsel_to_uv) {
217 pr_warning("%s: PMIC function to convert vsel to voltage"
218 "in uV not registerd\n", __func__);
219 return 0;
220 }
221
222 return vdd->pmic_info->vsel_to_uv(curr_vsel);
223}
224
225/**
226 * omap_vp_enable() - API to enable a particular VP
227 * @voltdm: pointer to the VDD whose VP is to be enabled.
228 *
229 * This API enables a particular voltage processor. Needed by the smartreflex
230 * class drivers.
231 */
232void omap_vp_enable(struct voltagedomain *voltdm)
233{
234 struct omap_vp_instance_data *vp;
235 struct omap_vdd_info *vdd;
236 u32 vpconfig;
237
238 if (!voltdm || IS_ERR(voltdm)) {
239 pr_warning("%s: VDD specified does not exist!\n", __func__);
240 return;
241 }
242
243 vdd = voltdm->vdd;
244 vp = voltdm->vdd->vp_data;
245 if (!vdd->read_reg || !vdd->write_reg) {
246 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
247 __func__, voltdm->name);
248 return;
249 }
250
251 /* If VP is already enabled, do nothing. Return */
252 if (vdd->vp_enabled)
253 return;
254
255 vp_latch_vsel(voltdm);
256
257 /* Enable VP */
258 vpconfig = vdd->read_reg(vp->vp_common->prm_mod, vp->vpconfig);
259 vpconfig |= vp->vp_common->vpconfig_vpenable;
260 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
261 vdd->vp_enabled = true;
262}
263
264/**
265 * omap_vp_disable() - API to disable a particular VP
266 * @voltdm: pointer to the VDD whose VP is to be disabled.
267 *
268 * This API disables a particular voltage processor. Needed by the smartreflex
269 * class drivers.
270 */
271void omap_vp_disable(struct voltagedomain *voltdm)
272{
273 struct omap_vp_instance_data *vp;
274 struct omap_vdd_info *vdd;
275 u32 vpconfig;
276 int timeout;
277
278 if (!voltdm || IS_ERR(voltdm)) {
279 pr_warning("%s: VDD specified does not exist!\n", __func__);
280 return;
281 }
282
283 vdd = voltdm->vdd;
284 vp = voltdm->vdd->vp_data;
285 if (!vdd->read_reg || !vdd->write_reg) {
286 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
287 __func__, voltdm->name);
288 return;
289 }
290
291 /* If VP is already disabled, do nothing. Return */
292 if (!vdd->vp_enabled) {
293 pr_warning("%s: Trying to disable VP for vdd_%s when"
294 "it is already disabled\n", __func__, voltdm->name);
295 return;
296 }
297
298 /* Disable VP */
299 vpconfig = vdd->read_reg(vp->vp_common->prm_mod, vp->vpconfig);
300 vpconfig &= ~vp->vp_common->vpconfig_vpenable;
301 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
302
303 /*
304 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
305 */
306 omap_test_timeout((vdd->read_reg(vp->vp_common->prm_mod, vp->vstatus)),
307 VP_IDLE_TIMEOUT, timeout);
308
309 if (timeout >= VP_IDLE_TIMEOUT)
310 pr_warning("%s: vdd_%s idle timedout\n",
311 __func__, voltdm->name);
312
313 vdd->vp_enabled = false;
314
315 return;
316}
317
318/* Voltage debugfs support */
319static int vp_volt_debug_get(void *data, u64 *val)
320{
321 struct voltagedomain *voltdm = (struct voltagedomain *)data;
322 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
323 struct omap_vdd_info *vdd = voltdm->vdd;
324 u8 vsel;
325
326 if (!vdd) {
327 pr_warning("Wrong paramater passed\n");
328 return -EINVAL;
329 }
330
331 vsel = vdd->read_reg(vp->vp_common->prm_mod, vp->voltage);
332
333 if (!vdd->pmic_info->vsel_to_uv) {
334 pr_warning("PMIC function to convert vsel to voltage"
335 "in uV not registerd\n");
336 return -EINVAL;
337 }
338
339 *val = vdd->pmic_info->vsel_to_uv(vsel);
340 return 0;
341}
342
343DEFINE_SIMPLE_ATTRIBUTE(vp_volt_debug_fops, vp_volt_debug_get, NULL, "%llu\n");
344
345static void __init vp_debugfs_init(struct voltagedomain *voltdm)
346{
347 struct omap_vdd_info *vdd = voltdm->vdd;
348 struct dentry *debug_dir;
349
350 debug_dir = debugfs_create_dir("vp", vdd->debug_dir);
351 if (IS_ERR(debug_dir))
352 pr_err("%s: Unable to create VP debugfs dir dir\n", __func__);
353
354 (void) debugfs_create_x16("errorgain", S_IRUGO, debug_dir,
355 &(vdd->vp_rt_data.vpconfig_errorgain));
356 (void) debugfs_create_x16("smpswaittimemin", S_IRUGO,
357 debug_dir,
358 &(vdd->vp_rt_data.vstepmin_smpswaittimemin));
359 (void) debugfs_create_x8("stepmin", S_IRUGO, debug_dir,
360 &(vdd->vp_rt_data.vstepmin_stepmin));
361 (void) debugfs_create_x16("smpswaittimemax", S_IRUGO,
362 debug_dir,
363 &(vdd->vp_rt_data.vstepmax_smpswaittimemax));
364 (void) debugfs_create_x8("stepmax", S_IRUGO, debug_dir,
365 &(vdd->vp_rt_data.vstepmax_stepmax));
366 (void) debugfs_create_x8("vddmax", S_IRUGO, debug_dir,
367 &(vdd->vp_rt_data.vlimitto_vddmax));
368 (void) debugfs_create_x8("vddmin", S_IRUGO, debug_dir,
369 &(vdd->vp_rt_data.vlimitto_vddmin));
370 (void) debugfs_create_x16("timeout", S_IRUGO, debug_dir,
371 &(vdd->vp_rt_data.vlimitto_timeout));
372 (void) debugfs_create_file("curr_volt", S_IRUGO, debug_dir,
373 (void *) voltdm, &vp_volt_debug_fops);
374}
diff --git a/arch/arm/mach-omap2/vp.h b/arch/arm/mach-omap2/vp.h
index 5406b08463b6..025cf164da71 100644
--- a/arch/arm/mach-omap2/vp.h
+++ b/arch/arm/mach-omap2/vp.h
@@ -19,6 +19,8 @@
19 19
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21 21
22struct voltagedomain;
23
22/* XXX document */ 24/* XXX document */
23#define VP_IDLE_TIMEOUT 200 25#define VP_IDLE_TIMEOUT 200
24#define VP_TRANXDONE_TIMEOUT 300 26#define VP_TRANXDONE_TIMEOUT 300
@@ -139,4 +141,11 @@ extern struct omap_vp_instance_data omap4_vp_mpu_data;
139extern struct omap_vp_instance_data omap4_vp_iva_data; 141extern struct omap_vp_instance_data omap4_vp_iva_data;
140extern struct omap_vp_instance_data omap4_vp_core_data; 142extern struct omap_vp_instance_data omap4_vp_core_data;
141 143
144void omap_vp_init(struct voltagedomain *voltdm);
145void omap_vp_enable(struct voltagedomain *voltdm);
146void omap_vp_disable(struct voltagedomain *voltdm);
147unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm);
148int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
149 unsigned long target_volt);
150
142#endif 151#endif