2 * OMAP3/OMAP4 Voltage Management Routines
4 * Author: Thara Gopinath <thara@ti.com>
6 * Copyright (C) 2007 Texas Instruments, Inc.
7 * Rajendra Nayak <rnayak@ti.com>
8 * Lesly A M <x0080970@ti.com>
10 * Copyright (C) 2008, 2011 Nokia Corporation
14 * Copyright (C) 2010 Texas Instruments, Inc.
15 * Thara Gopinath <thara@ti.com>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
22 #include <linux/delay.h>
24 #include <linux/clk.h>
25 #include <linux/err.h>
26 #include <linux/debugfs.h>
27 #include <linux/slab.h>
29 #include <plat/common.h>
31 #include "prm-regbits-34xx.h"
32 #include "prm-regbits-44xx.h"
35 #include "prminst44xx.h"
39 #include "powerdomain.h"
44 static LIST_HEAD(voltdm_list);
46 #define VOLTAGE_DIR_SIZE 16
47 static struct dentry *voltage_dir;
49 /* Init function pointers */
50 static int vp_forceupdate_scale_voltage(struct voltagedomain *voltdm,
51 unsigned long target_volt);
53 static u32 omap3_voltage_read_reg(u16 mod, u8 offset)
55 return omap2_prm_read_mod_reg(mod, offset);
58 static void omap3_voltage_write_reg(u32 val, u16 mod, u8 offset)
60 omap2_prm_write_mod_reg(val, mod, offset);
63 static u32 omap4_voltage_read_reg(u16 mod, u8 offset)
65 return omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
69 static void omap4_voltage_write_reg(u32 val, u16 mod, u8 offset)
71 omap4_prminst_write_inst_reg(val, OMAP4430_PRM_PARTITION, mod, offset);
74 static int __init _config_common_vdd_data(struct voltagedomain *voltdm)
78 u32 sys_clk_speed, timeout_val, waittime;
79 struct omap_vdd_info *vdd = voltdm->vdd;
82 * XXX Clockfw should handle this, or this should be in a
85 if (cpu_is_omap24xx() || cpu_is_omap34xx())
86 sys_ck_name = "sys_ck";
87 else if (cpu_is_omap44xx())
88 sys_ck_name = "sys_clkin_ck";
93 * Sys clk rate is require to calculate vp timeout value and
94 * smpswaittimemin and smpswaittimemax.
96 sys_ck = clk_get(NULL, sys_ck_name);
98 pr_warning("%s: Could not get the sys clk to calculate"
99 "various vdd_%s params\n", __func__, voltdm->name);
102 sys_clk_speed = clk_get_rate(sys_ck);
104 /* Divide to avoid overflow */
105 sys_clk_speed /= 1000;
107 /* Generic voltage parameters */
108 vdd->volt_scale = vp_forceupdate_scale_voltage;
109 vdd->vp_enabled = false;
111 vdd->vp_rt_data.vpconfig_erroroffset =
112 (vdd->pmic_info->vp_erroroffset <<
113 vdd->vp_data->vp_common->vpconfig_erroroffset_shift);
115 timeout_val = (sys_clk_speed * vdd->pmic_info->vp_timeout_us) / 1000;
116 vdd->vp_rt_data.vlimitto_timeout = timeout_val;
117 vdd->vp_rt_data.vlimitto_vddmin = vdd->pmic_info->vp_vddmin;
118 vdd->vp_rt_data.vlimitto_vddmax = vdd->pmic_info->vp_vddmax;
120 waittime = ((vdd->pmic_info->step_size / vdd->pmic_info->slew_rate) *
121 sys_clk_speed) / 1000;
122 vdd->vp_rt_data.vstepmin_smpswaittimemin = waittime;
123 vdd->vp_rt_data.vstepmax_smpswaittimemax = waittime;
124 vdd->vp_rt_data.vstepmin_stepmin = vdd->pmic_info->vp_vstepmin;
125 vdd->vp_rt_data.vstepmax_stepmax = vdd->pmic_info->vp_vstepmax;
130 /* Voltage debugfs support */
131 static int vp_volt_debug_get(void *data, u64 *val)
133 struct voltagedomain *voltdm = (struct voltagedomain *)data;
134 struct omap_vdd_info *vdd = voltdm->vdd;
138 pr_warning("Wrong paramater passed\n");
142 vsel = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->voltage);
144 if (!vdd->pmic_info->vsel_to_uv) {
145 pr_warning("PMIC function to convert vsel to voltage"
146 "in uV not registerd\n");
150 *val = vdd->pmic_info->vsel_to_uv(vsel);
154 static int nom_volt_debug_get(void *data, u64 *val)
156 struct voltagedomain *voltdm = (struct voltagedomain *)data;
159 pr_warning("Wrong paramater passed\n");
163 *val = omap_voltage_get_nom_volt(voltdm);
168 DEFINE_SIMPLE_ATTRIBUTE(vp_volt_debug_fops, vp_volt_debug_get, NULL, "%llu\n");
169 DEFINE_SIMPLE_ATTRIBUTE(nom_volt_debug_fops, nom_volt_debug_get, NULL,
171 static void vp_latch_vsel(struct voltagedomain *voltdm)
176 struct omap_vdd_info *vdd = voltdm->vdd;
178 uvdc = omap_voltage_get_nom_volt(voltdm);
180 pr_warning("%s: unable to find current voltage for vdd_%s\n",
181 __func__, voltdm->name);
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__);
191 vsel = vdd->pmic_info->uv_to_vsel(uvdc);
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;
198 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
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);
204 /* Clear initVDD copy trigger bit */
205 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
208 /* Generic voltage init functions */
209 static void __init vp_init(struct voltagedomain *voltdm)
211 struct omap_vdd_info *vdd = voltdm->vdd;
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);
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);
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);
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);
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);
247 static void __init vdd_debugfs_init(struct voltagedomain *voltdm)
250 struct omap_vdd_info *vdd = voltdm->vdd;
252 name = kzalloc(VOLTAGE_DIR_SIZE, GFP_KERNEL);
254 pr_warning("%s: Unable to allocate memory for debugfs"
255 " directory name for vdd_%s",
256 __func__, voltdm->name);
259 strcpy(name, "vdd_");
260 strcat(name, voltdm->name);
262 vdd->debug_dir = debugfs_create_dir(name, voltage_dir);
264 if (IS_ERR(vdd->debug_dir)) {
265 pr_warning("%s: Unable to create debugfs directory for"
266 " vdd_%s\n", __func__, voltdm->name);
267 vdd->debug_dir = NULL;
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,
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,
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,
292 vdd->debug_dir, (void *) voltdm,
293 &nom_volt_debug_fops);
296 /* VP force update method of voltage scaling */
297 static int vp_forceupdate_scale_voltage(struct voltagedomain *voltdm,
298 unsigned long target_volt)
300 struct omap_vdd_info *vdd = voltdm->vdd;
302 u8 target_vsel, current_vsel;
303 int ret, timeout = 0;
305 ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, ¤t_vsel);
310 * Clear all pending TransactionDone interrupt/status. Typical latency
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))
321 if (timeout >= VP_TRANXDONE_TIMEOUT) {
322 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
323 "Voltage change aborted", __func__, voltdm->name);
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);
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);
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);
345 * Wait for TransactionDone. Typical latency is <200us.
346 * Depends on SMPSWAITTIMEMIN/MAX and voltage change
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);
358 omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel);
361 * Disable TransactionDone interrupt , clear all status, clear
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))
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);
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);
390 static int __init omap_vdd_data_configure(struct voltagedomain *voltdm)
392 struct omap_vdd_info *vdd = voltdm->vdd;
395 if (!vdd->pmic_info) {
396 pr_err("%s: PMIC info requried to configure vdd_%s not"
397 "populated.Hence cannot initialize vdd_%s\n",
398 __func__, voltdm->name, voltdm->name);
402 if (IS_ERR_VALUE(_config_common_vdd_data(voltdm)))
405 if (cpu_is_omap34xx()) {
406 vdd->read_reg = omap3_voltage_read_reg;
407 vdd->write_reg = omap3_voltage_write_reg;
409 } else if (cpu_is_omap44xx()) {
410 vdd->read_reg = omap4_voltage_read_reg;
411 vdd->write_reg = omap4_voltage_write_reg;
419 /* Public functions */
421 * omap_voltage_get_nom_volt() - Gets the current non-auto-compensated voltage
422 * @voltdm: pointer to the VDD for which current voltage info is needed
424 * API to get the current non-auto-compensated voltage for a VDD.
425 * Returns 0 in case of error else returns the current voltage for the VDD.
427 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm)
429 struct omap_vdd_info *vdd;
431 if (!voltdm || IS_ERR(voltdm)) {
432 pr_warning("%s: VDD specified does not exist!\n", __func__);
438 return vdd->curr_volt;
442 * omap_vp_get_curr_volt() - API to get the current vp voltage.
443 * @voltdm: pointer to the VDD.
445 * This API returns the current voltage for the specified voltage processor
447 unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
449 struct omap_vdd_info *vdd;
452 if (!voltdm || IS_ERR(voltdm)) {
453 pr_warning("%s: VDD specified does not exist!\n", __func__);
458 if (!vdd->read_reg) {
459 pr_err("%s: No read API for reading vdd_%s regs\n",
460 __func__, voltdm->name);
464 curr_vsel = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->voltage);
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__);
472 return vdd->pmic_info->vsel_to_uv(curr_vsel);
476 * omap_vp_enable() - API to enable a particular VP
477 * @voltdm: pointer to the VDD whose VP is to be enabled.
479 * This API enables a particular voltage processor. Needed by the smartreflex
482 void omap_vp_enable(struct voltagedomain *voltdm)
484 struct omap_vdd_info *vdd;
487 if (!voltdm || IS_ERR(voltdm)) {
488 pr_warning("%s: VDD specified does not exist!\n", __func__);
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);
499 /* If VP is already enabled, do nothing. Return */
503 vp_latch_vsel(voltdm);
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;
513 * omap_vp_disable() - API to disable a particular VP
514 * @voltdm: pointer to the VDD whose VP is to be disabled.
516 * This API disables a particular voltage processor. Needed by the smartreflex
519 void omap_vp_disable(struct voltagedomain *voltdm)
521 struct omap_vdd_info *vdd;
525 if (!voltdm || IS_ERR(voltdm)) {
526 pr_warning("%s: VDD specified does not exist!\n", __func__);
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);
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);
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);
550 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
552 omap_test_timeout((vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vstatus)),
553 VP_IDLE_TIMEOUT, timeout);
555 if (timeout >= VP_IDLE_TIMEOUT)
556 pr_warning("%s: vdd_%s idle timedout\n",
557 __func__, voltdm->name);
559 vdd->vp_enabled = false;
565 * omap_voltage_scale_vdd() - API to scale voltage of a particular
567 * @voltdm: pointer to the VDD which is to be scaled.
568 * @target_volt: The target voltage of the voltage domain
570 * This API should be called by the kernel to do the voltage scaling
571 * for a particular voltage domain during dvfs or any other situation.
573 int omap_voltage_scale_vdd(struct voltagedomain *voltdm,
574 unsigned long target_volt)
576 struct omap_vdd_info *vdd;
578 if (!voltdm || IS_ERR(voltdm)) {
579 pr_warning("%s: VDD specified does not exist!\n", __func__);
585 if (!vdd->volt_scale) {
586 pr_err("%s: No voltage scale API registered for vdd_%s\n",
587 __func__, voltdm->name);
591 return vdd->volt_scale(voltdm, target_volt);
595 * omap_voltage_reset() - Resets the voltage of a particular voltage domain
596 * to that of the current OPP.
597 * @voltdm: pointer to the VDD whose voltage is to be reset.
599 * This API finds out the correct voltage the voltage domain is supposed
600 * to be at and resets the voltage to that level. Should be used especially
601 * while disabling any voltage compensation modules.
603 void omap_voltage_reset(struct voltagedomain *voltdm)
605 unsigned long target_uvdc;
607 if (!voltdm || IS_ERR(voltdm)) {
608 pr_warning("%s: VDD specified does not exist!\n", __func__);
612 target_uvdc = omap_voltage_get_nom_volt(voltdm);
614 pr_err("%s: unable to find current voltage for vdd_%s\n",
615 __func__, voltdm->name);
619 omap_voltage_scale_vdd(voltdm, target_uvdc);
623 * omap_voltage_get_volttable() - API to get the voltage table associated with a
624 * particular voltage domain.
625 * @voltdm: pointer to the VDD for which the voltage table is required
626 * @volt_data: the voltage table for the particular vdd which is to be
627 * populated by this API
629 * This API populates the voltage table associated with a VDD into the
630 * passed parameter pointer. Returns the count of distinct voltages
631 * supported by this vdd.
634 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
635 struct omap_volt_data **volt_data)
637 struct omap_vdd_info *vdd;
639 if (!voltdm || IS_ERR(voltdm)) {
640 pr_warning("%s: VDD specified does not exist!\n", __func__);
646 *volt_data = vdd->volt_data;
650 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
652 * @voltdm: pointer to the VDD whose voltage table has to be searched
653 * @volt: the voltage to be searched in the voltage table
655 * This API searches through the voltage table for the required voltage
656 * domain and tries to find a matching entry for the passed voltage volt.
657 * If a matching entry is found volt_data is populated with that entry.
658 * This API searches only through the non-compensated voltages int the
660 * Returns pointer to the voltage table entry corresponding to volt on
661 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
662 * domain or if there is no matching entry.
664 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
667 struct omap_vdd_info *vdd;
670 if (!voltdm || IS_ERR(voltdm)) {
671 pr_warning("%s: VDD specified does not exist!\n", __func__);
672 return ERR_PTR(-EINVAL);
677 if (!vdd->volt_data) {
678 pr_warning("%s: voltage table does not exist for vdd_%s\n",
679 __func__, voltdm->name);
680 return ERR_PTR(-ENODATA);
683 for (i = 0; vdd->volt_data[i].volt_nominal != 0; i++) {
684 if (vdd->volt_data[i].volt_nominal == volt)
685 return &vdd->volt_data[i];
688 pr_notice("%s: Unable to match the current voltage with the voltage"
689 "table for vdd_%s\n", __func__, voltdm->name);
691 return ERR_PTR(-ENODATA);
695 * omap_voltage_register_pmic() - API to register PMIC specific data
696 * @voltdm: pointer to the VDD for which the PMIC specific data is
698 * @pmic_info: the structure containing pmic info
700 * This API is to be called by the SOC/PMIC file to specify the
701 * pmic specific info as present in omap_volt_pmic_info structure.
703 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
704 struct omap_volt_pmic_info *pmic_info)
706 struct omap_vdd_info *vdd;
708 if (!voltdm || IS_ERR(voltdm)) {
709 pr_warning("%s: VDD specified does not exist!\n", __func__);
715 vdd->pmic_info = pmic_info;
721 * omap_voltage_get_dbgdir() - API to get pointer to the debugfs directory
722 * corresponding to a voltage domain.
724 * @voltdm: pointer to the VDD whose debug directory is required.
726 * This API returns pointer to the debugfs directory corresponding
727 * to the voltage domain. Should be used by drivers requiring to
728 * add any debug entry for a particular voltage domain. Returns NULL
731 struct dentry *omap_voltage_get_dbgdir(struct voltagedomain *voltdm)
733 struct omap_vdd_info *vdd;
735 if (!voltdm || IS_ERR(voltdm)) {
736 pr_warning("%s: VDD specified does not exist!\n", __func__);
742 return vdd->debug_dir;
746 * omap_change_voltscale_method() - API to change the voltage scaling method.
747 * @voltdm: pointer to the VDD whose voltage scaling method
749 * @voltscale_method: the method to be used for voltage scaling.
751 * This API can be used by the board files to change the method of voltage
752 * scaling between vpforceupdate and vcbypass. The parameter values are
753 * defined in voltage.h
755 void omap_change_voltscale_method(struct voltagedomain *voltdm,
756 int voltscale_method)
758 struct omap_vdd_info *vdd;
760 if (!voltdm || IS_ERR(voltdm)) {
761 pr_warning("%s: VDD specified does not exist!\n", __func__);
767 switch (voltscale_method) {
768 case VOLTSCALE_VPFORCEUPDATE:
769 vdd->volt_scale = vp_forceupdate_scale_voltage;
771 case VOLTSCALE_VCBYPASS:
772 vdd->volt_scale = omap_vc_bypass_scale;
775 pr_warning("%s: Trying to change the method of voltage scaling"
776 "to an unsupported one!\n", __func__);
781 * omap_voltage_late_init() - Init the various voltage parameters
783 * This API is to be called in the later stages of the
784 * system boot to init the voltage controller and
785 * voltage processors.
787 int __init omap_voltage_late_init(void)
789 struct voltagedomain *voltdm;
791 if (list_empty(&voltdm_list)) {
792 pr_err("%s: Voltage driver support not added\n",
797 voltage_dir = debugfs_create_dir("voltage", NULL);
798 if (IS_ERR(voltage_dir))
799 pr_err("%s: Unable to create voltage debugfs main dir\n",
801 list_for_each_entry(voltdm, &voltdm_list, node) {
802 if (!voltdm->scalable)
806 voltdm->vdd->volt_scale = omap_vc_bypass_scale;
807 omap_vc_init_channel(voltdm);
811 if (omap_vdd_data_configure(voltdm))
814 vdd_debugfs_init(voltdm);
821 static struct voltagedomain *_voltdm_lookup(const char *name)
823 struct voltagedomain *voltdm, *temp_voltdm;
827 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
828 if (!strcmp(name, temp_voltdm->name)) {
829 voltdm = temp_voltdm;
838 * voltdm_add_pwrdm - add a powerdomain to a voltagedomain
839 * @voltdm: struct voltagedomain * to add the powerdomain to
840 * @pwrdm: struct powerdomain * to associate with a voltagedomain
842 * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This
843 * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if
844 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
847 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm)
849 if (!voltdm || !pwrdm)
852 pr_debug("voltagedomain: associating powerdomain %s with voltagedomain "
853 "%s\n", pwrdm->name, voltdm->name);
855 list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list);
861 * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
862 * @voltdm: struct voltagedomain * to iterate over
863 * @fn: callback function *
865 * Call the supplied function @fn for each powerdomain in the
866 * voltagedomain @voltdm. Returns -EINVAL if presented with invalid
867 * pointers; or passes along the last return value of the callback
868 * function, which should be 0 for success or anything else to
871 int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
872 int (*fn)(struct voltagedomain *voltdm,
873 struct powerdomain *pwrdm))
875 struct powerdomain *pwrdm;
881 list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node)
882 ret = (*fn)(voltdm, pwrdm);
888 * voltdm_for_each - call function on each registered voltagedomain
889 * @fn: callback function *
891 * Call the supplied function @fn for each registered voltagedomain.
892 * The callback function @fn can return anything but 0 to bail out
893 * early from the iterator. Returns the last return value of the
894 * callback function, which should be 0 for success or anything else
895 * to indicate failure; or -EINVAL if the function pointer is null.
897 int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
900 struct voltagedomain *temp_voltdm;
906 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
907 ret = (*fn)(temp_voltdm, user);
915 static int _voltdm_register(struct voltagedomain *voltdm)
917 if (!voltdm || !voltdm->name)
920 INIT_LIST_HEAD(&voltdm->pwrdm_list);
921 list_add(&voltdm->node, &voltdm_list);
923 pr_debug("voltagedomain: registered %s\n", voltdm->name);
929 * voltdm_lookup - look up a voltagedomain by name, return a pointer
930 * @name: name of voltagedomain
932 * Find a registered voltagedomain by its name @name. Returns a pointer
933 * to the struct voltagedomain if found, or NULL otherwise.
935 struct voltagedomain *voltdm_lookup(const char *name)
937 struct voltagedomain *voltdm ;
942 voltdm = _voltdm_lookup(name);
948 * voltdm_init - set up the voltagedomain layer
949 * @voltdm_list: array of struct voltagedomain pointers to register
951 * Loop through the array of voltagedomains @voltdm_list, registering all
952 * that are available on the current CPU. If voltdm_list is supplied
953 * and not null, all of the referenced voltagedomains will be
954 * registered. No return value.
956 void voltdm_init(struct voltagedomain **voltdms)
958 struct voltagedomain **v;
961 for (v = voltdms; *v; v++)
962 _voltdm_register(*v);