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"
43 static LIST_HEAD(voltdm_list);
45 #define VOLTAGE_DIR_SIZE 16
46 static struct dentry *voltage_dir;
48 /* Init function pointers */
49 static int vp_forceupdate_scale_voltage(struct voltagedomain *voltdm,
50 unsigned long target_volt);
52 static u32 omap3_voltage_read_reg(u16 mod, u8 offset)
54 return omap2_prm_read_mod_reg(mod, offset);
57 static void omap3_voltage_write_reg(u32 val, u16 mod, u8 offset)
59 omap2_prm_write_mod_reg(val, mod, offset);
62 static u32 omap4_voltage_read_reg(u16 mod, u8 offset)
64 return omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
68 static void omap4_voltage_write_reg(u32 val, u16 mod, u8 offset)
70 omap4_prminst_write_inst_reg(val, OMAP4430_PRM_PARTITION, mod, offset);
73 static int __init _config_common_vdd_data(struct voltagedomain *voltdm)
77 u32 sys_clk_speed, timeout_val, waittime;
78 struct omap_vdd_info *vdd = voltdm->vdd;
81 * XXX Clockfw should handle this, or this should be in a
84 if (cpu_is_omap24xx() || cpu_is_omap34xx())
85 sys_ck_name = "sys_ck";
86 else if (cpu_is_omap44xx())
87 sys_ck_name = "sys_clkin_ck";
92 * Sys clk rate is require to calculate vp timeout value and
93 * smpswaittimemin and smpswaittimemax.
95 sys_ck = clk_get(NULL, sys_ck_name);
97 pr_warning("%s: Could not get the sys clk to calculate"
98 "various vdd_%s params\n", __func__, voltdm->name);
101 sys_clk_speed = clk_get_rate(sys_ck);
103 /* Divide to avoid overflow */
104 sys_clk_speed /= 1000;
106 /* Generic voltage parameters */
107 vdd->volt_scale = vp_forceupdate_scale_voltage;
108 vdd->vp_enabled = false;
110 vdd->vp_rt_data.vpconfig_erroroffset =
111 (vdd->pmic_info->vp_erroroffset <<
112 vdd->vp_data->vp_common->vpconfig_erroroffset_shift);
114 timeout_val = (sys_clk_speed * vdd->pmic_info->vp_timeout_us) / 1000;
115 vdd->vp_rt_data.vlimitto_timeout = timeout_val;
116 vdd->vp_rt_data.vlimitto_vddmin = vdd->pmic_info->vp_vddmin;
117 vdd->vp_rt_data.vlimitto_vddmax = vdd->pmic_info->vp_vddmax;
119 waittime = ((vdd->pmic_info->step_size / vdd->pmic_info->slew_rate) *
120 sys_clk_speed) / 1000;
121 vdd->vp_rt_data.vstepmin_smpswaittimemin = waittime;
122 vdd->vp_rt_data.vstepmax_smpswaittimemax = waittime;
123 vdd->vp_rt_data.vstepmin_stepmin = vdd->pmic_info->vp_vstepmin;
124 vdd->vp_rt_data.vstepmax_stepmax = vdd->pmic_info->vp_vstepmax;
129 /* Voltage debugfs support */
130 static int vp_volt_debug_get(void *data, u64 *val)
132 struct voltagedomain *voltdm = (struct voltagedomain *)data;
133 struct omap_vdd_info *vdd = voltdm->vdd;
137 pr_warning("Wrong paramater passed\n");
141 vsel = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->voltage);
143 if (!vdd->pmic_info->vsel_to_uv) {
144 pr_warning("PMIC function to convert vsel to voltage"
145 "in uV not registerd\n");
149 *val = vdd->pmic_info->vsel_to_uv(vsel);
153 static int nom_volt_debug_get(void *data, u64 *val)
155 struct voltagedomain *voltdm = (struct voltagedomain *)data;
158 pr_warning("Wrong paramater passed\n");
162 *val = omap_voltage_get_nom_volt(voltdm);
167 DEFINE_SIMPLE_ATTRIBUTE(vp_volt_debug_fops, vp_volt_debug_get, NULL, "%llu\n");
168 DEFINE_SIMPLE_ATTRIBUTE(nom_volt_debug_fops, nom_volt_debug_get, NULL,
170 static void vp_latch_vsel(struct voltagedomain *voltdm)
175 struct omap_vdd_info *vdd = voltdm->vdd;
177 uvdc = omap_voltage_get_nom_volt(voltdm);
179 pr_warning("%s: unable to find current voltage for vdd_%s\n",
180 __func__, voltdm->name);
184 if (!vdd->pmic_info || !vdd->pmic_info->uv_to_vsel) {
185 pr_warning("%s: PMIC function to convert voltage in uV to"
186 " vsel not registered\n", __func__);
190 vsel = vdd->pmic_info->uv_to_vsel(uvdc);
192 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
193 vpconfig &= ~(vdd->vp_data->vp_common->vpconfig_initvoltage_mask |
194 vdd->vp_data->vp_common->vpconfig_initvdd);
195 vpconfig |= vsel << vdd->vp_data->vp_common->vpconfig_initvoltage_shift;
197 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
199 /* Trigger initVDD value copy to voltage processor */
200 vdd->write_reg((vpconfig | vdd->vp_data->vp_common->vpconfig_initvdd),
201 vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
203 /* Clear initVDD copy trigger bit */
204 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
207 /* Generic voltage init functions */
208 static void __init vp_init(struct voltagedomain *voltdm)
210 struct omap_vdd_info *vdd = voltdm->vdd;
213 if (!vdd->read_reg || !vdd->write_reg) {
214 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
215 __func__, voltdm->name);
219 vp_val = vdd->vp_rt_data.vpconfig_erroroffset |
220 (vdd->vp_rt_data.vpconfig_errorgain <<
221 vdd->vp_data->vp_common->vpconfig_errorgain_shift) |
222 vdd->vp_data->vp_common->vpconfig_timeouten;
223 vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
225 vp_val = ((vdd->vp_rt_data.vstepmin_smpswaittimemin <<
226 vdd->vp_data->vp_common->vstepmin_smpswaittimemin_shift) |
227 (vdd->vp_rt_data.vstepmin_stepmin <<
228 vdd->vp_data->vp_common->vstepmin_stepmin_shift));
229 vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vstepmin);
231 vp_val = ((vdd->vp_rt_data.vstepmax_smpswaittimemax <<
232 vdd->vp_data->vp_common->vstepmax_smpswaittimemax_shift) |
233 (vdd->vp_rt_data.vstepmax_stepmax <<
234 vdd->vp_data->vp_common->vstepmax_stepmax_shift));
235 vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vstepmax);
237 vp_val = ((vdd->vp_rt_data.vlimitto_vddmax <<
238 vdd->vp_data->vp_common->vlimitto_vddmax_shift) |
239 (vdd->vp_rt_data.vlimitto_vddmin <<
240 vdd->vp_data->vp_common->vlimitto_vddmin_shift) |
241 (vdd->vp_rt_data.vlimitto_timeout <<
242 vdd->vp_data->vp_common->vlimitto_timeout_shift));
243 vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vlimitto);
246 static void __init vdd_debugfs_init(struct voltagedomain *voltdm)
249 struct omap_vdd_info *vdd = voltdm->vdd;
251 name = kzalloc(VOLTAGE_DIR_SIZE, GFP_KERNEL);
253 pr_warning("%s: Unable to allocate memory for debugfs"
254 " directory name for vdd_%s",
255 __func__, voltdm->name);
258 strcpy(name, "vdd_");
259 strcat(name, voltdm->name);
261 vdd->debug_dir = debugfs_create_dir(name, voltage_dir);
263 if (IS_ERR(vdd->debug_dir)) {
264 pr_warning("%s: Unable to create debugfs directory for"
265 " vdd_%s\n", __func__, voltdm->name);
266 vdd->debug_dir = NULL;
270 (void) debugfs_create_x16("vp_errorgain", S_IRUGO, vdd->debug_dir,
271 &(vdd->vp_rt_data.vpconfig_errorgain));
272 (void) debugfs_create_x16("vp_smpswaittimemin", S_IRUGO,
274 &(vdd->vp_rt_data.vstepmin_smpswaittimemin));
275 (void) debugfs_create_x8("vp_stepmin", S_IRUGO, vdd->debug_dir,
276 &(vdd->vp_rt_data.vstepmin_stepmin));
277 (void) debugfs_create_x16("vp_smpswaittimemax", S_IRUGO,
279 &(vdd->vp_rt_data.vstepmax_smpswaittimemax));
280 (void) debugfs_create_x8("vp_stepmax", S_IRUGO, vdd->debug_dir,
281 &(vdd->vp_rt_data.vstepmax_stepmax));
282 (void) debugfs_create_x8("vp_vddmax", S_IRUGO, vdd->debug_dir,
283 &(vdd->vp_rt_data.vlimitto_vddmax));
284 (void) debugfs_create_x8("vp_vddmin", S_IRUGO, vdd->debug_dir,
285 &(vdd->vp_rt_data.vlimitto_vddmin));
286 (void) debugfs_create_x16("vp_timeout", S_IRUGO, vdd->debug_dir,
287 &(vdd->vp_rt_data.vlimitto_timeout));
288 (void) debugfs_create_file("curr_vp_volt", S_IRUGO, vdd->debug_dir,
289 (void *) voltdm, &vp_volt_debug_fops);
290 (void) debugfs_create_file("curr_nominal_volt", S_IRUGO,
291 vdd->debug_dir, (void *) voltdm,
292 &nom_volt_debug_fops);
295 /* Voltage scale and accessory APIs */
296 static int _pre_volt_scale(struct voltagedomain *voltdm,
297 unsigned long target_volt, u8 *target_vsel, u8 *current_vsel)
299 struct omap_vdd_info *vdd = voltdm->vdd;
300 struct omap_volt_data *volt_data;
301 const struct omap_vc_common_data *vc_common;
302 const struct omap_vp_common_data *vp_common;
303 u32 vc_cmdval, vp_errgain_val;
305 vc_common = vdd->vc_data->vc_common;
306 vp_common = vdd->vp_data->vp_common;
308 /* Check if suffiecient pmic info is available for this vdd */
309 if (!vdd->pmic_info) {
310 pr_err("%s: Insufficient pmic info to scale the vdd_%s\n",
311 __func__, voltdm->name);
315 if (!vdd->pmic_info->uv_to_vsel) {
316 pr_err("%s: PMIC function to convert voltage in uV to"
317 "vsel not registered. Hence unable to scale voltage"
318 "for vdd_%s\n", __func__, voltdm->name);
322 if (!vdd->read_reg || !vdd->write_reg) {
323 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
324 __func__, voltdm->name);
328 /* Get volt_data corresponding to target_volt */
329 volt_data = omap_voltage_get_voltdata(voltdm, target_volt);
330 if (IS_ERR(volt_data))
333 *target_vsel = vdd->pmic_info->uv_to_vsel(target_volt);
334 *current_vsel = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->voltage);
336 /* Setting the ON voltage to the new target voltage */
337 vc_cmdval = vdd->read_reg(vdd->vc_data->vc_common->prm_mod, vdd->vc_data->cmdval_reg);
338 vc_cmdval &= ~vc_common->cmd_on_mask;
339 vc_cmdval |= (*target_vsel << vc_common->cmd_on_shift);
340 vdd->write_reg(vc_cmdval, vdd->vc_data->vc_common->prm_mod, vdd->vc_data->cmdval_reg);
342 /* Setting vp errorgain based on the voltage */
344 vp_errgain_val = vdd->read_reg(vdd->vp_data->vp_common->prm_mod,
345 vdd->vp_data->vpconfig);
346 vdd->vp_rt_data.vpconfig_errorgain = volt_data->vp_errgain;
347 vp_errgain_val &= ~vp_common->vpconfig_errorgain_mask;
348 vp_errgain_val |= vdd->vp_rt_data.vpconfig_errorgain <<
349 vp_common->vpconfig_errorgain_shift;
350 vdd->write_reg(vp_errgain_val, vdd->vp_data->vp_common->prm_mod,
351 vdd->vp_data->vpconfig);
357 static void _post_volt_scale(struct voltagedomain *voltdm,
358 unsigned long target_volt, u8 target_vsel, u8 current_vsel)
360 struct omap_vdd_info *vdd = voltdm->vdd;
361 u32 smps_steps = 0, smps_delay = 0;
363 smps_steps = abs(target_vsel - current_vsel);
364 /* SMPS slew rate / step size. 2us added as buffer. */
365 smps_delay = ((smps_steps * vdd->pmic_info->step_size) /
366 vdd->pmic_info->slew_rate) + 2;
369 vdd->curr_volt = target_volt;
372 /* vc_bypass_scale_voltage - VC bypass method of voltage scaling */
373 static int vc_bypass_scale_voltage(struct voltagedomain *voltdm,
374 unsigned long target_volt)
376 struct omap_vdd_info *vdd = voltdm->vdd;
377 u32 loop_cnt = 0, retries_cnt = 0;
378 u32 vc_valid, vc_bypass_val_reg, vc_bypass_value;
379 u8 target_vsel, current_vsel;
382 ret = _pre_volt_scale(voltdm, target_volt, &target_vsel, ¤t_vsel);
386 vc_valid = vdd->vc_data->vc_common->valid;
387 vc_bypass_val_reg = vdd->vc_data->vc_common->bypass_val_reg;
388 vc_bypass_value = (target_vsel << vdd->vc_data->vc_common->data_shift) |
389 (vdd->pmic_info->pmic_reg <<
390 vdd->vc_data->vc_common->regaddr_shift) |
391 (vdd->pmic_info->i2c_slave_addr <<
392 vdd->vc_data->vc_common->slaveaddr_shift);
394 vdd->write_reg(vc_bypass_value, vdd->vc_data->vc_common->prm_mod, vc_bypass_val_reg);
395 vdd->write_reg(vc_bypass_value | vc_valid, vdd->vc_data->vc_common->prm_mod,
398 vc_bypass_value = vdd->read_reg(vdd->vc_data->vc_common->prm_mod, vc_bypass_val_reg);
400 * Loop till the bypass command is acknowledged from the SMPS.
401 * NOTE: This is legacy code. The loop count and retry count needs
404 while (!(vc_bypass_value & vc_valid)) {
407 if (retries_cnt > 10) {
408 pr_warning("%s: Retry count exceeded\n", __func__);
417 vc_bypass_value = vdd->read_reg(vdd->vc_data->vc_common->prm_mod,
421 _post_volt_scale(voltdm, target_volt, target_vsel, current_vsel);
425 /* VP force update method of voltage scaling */
426 static int vp_forceupdate_scale_voltage(struct voltagedomain *voltdm,
427 unsigned long target_volt)
429 struct omap_vdd_info *vdd = voltdm->vdd;
431 u8 target_vsel, current_vsel;
432 int ret, timeout = 0;
434 ret = _pre_volt_scale(voltdm, target_volt, &target_vsel, ¤t_vsel);
439 * Clear all pending TransactionDone interrupt/status. Typical latency
442 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
443 vdd->write_reg(vdd->vp_data->prm_irqst_data->tranxdone_status,
444 vdd->prm_irqst_mod, vdd->prm_irqst_reg);
445 if (!(vdd->read_reg(vdd->prm_irqst_mod, vdd->prm_irqst_reg) &
446 vdd->vp_data->prm_irqst_data->tranxdone_status))
450 if (timeout >= VP_TRANXDONE_TIMEOUT) {
451 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
452 "Voltage change aborted", __func__, voltdm->name);
456 /* Configure for VP-Force Update */
457 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
458 vpconfig &= ~(vdd->vp_data->vp_common->vpconfig_initvdd |
459 vdd->vp_data->vp_common->vpconfig_forceupdate |
460 vdd->vp_data->vp_common->vpconfig_initvoltage_mask);
461 vpconfig |= ((target_vsel <<
462 vdd->vp_data->vp_common->vpconfig_initvoltage_shift));
463 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
465 /* Trigger initVDD value copy to voltage processor */
466 vpconfig |= vdd->vp_data->vp_common->vpconfig_initvdd;
467 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
469 /* Force update of voltage */
470 vpconfig |= vdd->vp_data->vp_common->vpconfig_forceupdate;
471 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
474 * Wait for TransactionDone. Typical latency is <200us.
475 * Depends on SMPSWAITTIMEMIN/MAX and voltage change
478 omap_test_timeout((vdd->read_reg(vdd->prm_irqst_mod,
479 vdd->prm_irqst_reg) &
480 vdd->vp_data->prm_irqst_data->tranxdone_status),
481 VP_TRANXDONE_TIMEOUT, timeout);
482 if (timeout >= VP_TRANXDONE_TIMEOUT)
483 pr_err("%s: vdd_%s TRANXDONE timeout exceeded."
484 "TRANXDONE never got set after the voltage update\n",
485 __func__, voltdm->name);
487 _post_volt_scale(voltdm, target_volt, target_vsel, current_vsel);
490 * Disable TransactionDone interrupt , clear all status, clear
494 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
495 vdd->write_reg(vdd->vp_data->prm_irqst_data->tranxdone_status,
496 vdd->prm_irqst_mod, vdd->prm_irqst_reg);
497 if (!(vdd->read_reg(vdd->prm_irqst_mod, vdd->prm_irqst_reg) &
498 vdd->vp_data->prm_irqst_data->tranxdone_status))
503 if (timeout >= VP_TRANXDONE_TIMEOUT)
504 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying"
505 "to clear the TRANXDONE status\n",
506 __func__, voltdm->name);
508 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
509 /* Clear initVDD copy trigger bit */
510 vpconfig &= ~vdd->vp_data->vp_common->vpconfig_initvdd;
511 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
512 /* Clear force bit */
513 vpconfig &= ~vdd->vp_data->vp_common->vpconfig_forceupdate;
514 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
519 static void __init omap3_vfsm_init(struct voltagedomain *voltdm)
521 struct omap_vdd_info *vdd = voltdm->vdd;
524 * Voltage Manager FSM parameters init
525 * XXX This data should be passed in from the board file
527 vdd->write_reg(OMAP3_CLKSETUP, vdd->vc_data->vc_common->prm_mod, OMAP3_PRM_CLKSETUP_OFFSET);
528 vdd->write_reg(OMAP3_VOLTOFFSET, vdd->vc_data->vc_common->prm_mod,
529 OMAP3_PRM_VOLTOFFSET_OFFSET);
530 vdd->write_reg(OMAP3_VOLTSETUP2, vdd->vc_data->vc_common->prm_mod,
531 OMAP3_PRM_VOLTSETUP2_OFFSET);
534 static void __init omap3_vc_init(struct voltagedomain *voltdm)
536 struct omap_vdd_info *vdd = voltdm->vdd;
537 static bool is_initialized;
538 u8 on_vsel, onlp_vsel, ret_vsel, off_vsel;
544 /* Set up the on, inactive, retention and off voltage */
545 on_vsel = vdd->pmic_info->uv_to_vsel(vdd->pmic_info->on_volt);
546 onlp_vsel = vdd->pmic_info->uv_to_vsel(vdd->pmic_info->onlp_volt);
547 ret_vsel = vdd->pmic_info->uv_to_vsel(vdd->pmic_info->ret_volt);
548 off_vsel = vdd->pmic_info->uv_to_vsel(vdd->pmic_info->off_volt);
549 vc_val = ((on_vsel << vdd->vc_data->vc_common->cmd_on_shift) |
550 (onlp_vsel << vdd->vc_data->vc_common->cmd_onlp_shift) |
551 (ret_vsel << vdd->vc_data->vc_common->cmd_ret_shift) |
552 (off_vsel << vdd->vc_data->vc_common->cmd_off_shift));
553 vdd->write_reg(vc_val, vdd->vc_data->vc_common->prm_mod, vdd->vc_data->cmdval_reg);
556 * Generic VC parameters init
557 * XXX This data should be abstracted out
559 vdd->write_reg(OMAP3430_CMD1_MASK | OMAP3430_RAV1_MASK, vdd->vc_data->vc_common->prm_mod,
560 OMAP3_PRM_VC_CH_CONF_OFFSET);
561 vdd->write_reg(OMAP3430_MCODE_SHIFT | OMAP3430_HSEN_MASK, vdd->vc_data->vc_common->prm_mod,
562 OMAP3_PRM_VC_I2C_CFG_OFFSET);
564 omap3_vfsm_init(voltdm);
566 is_initialized = true;
570 /* OMAP4 specific voltage init functions */
571 static void __init omap4_vc_init(struct voltagedomain *voltdm)
573 struct omap_vdd_info *vdd = voltdm->vdd;
574 static bool is_initialized;
580 /* TODO: Configure setup times and CMD_VAL values*/
583 * Generic VC parameters init
584 * XXX This data should be abstracted out
586 vc_val = (OMAP4430_RAV_VDD_MPU_L_MASK | OMAP4430_CMD_VDD_MPU_L_MASK |
587 OMAP4430_RAV_VDD_IVA_L_MASK | OMAP4430_CMD_VDD_IVA_L_MASK |
588 OMAP4430_RAV_VDD_CORE_L_MASK | OMAP4430_CMD_VDD_CORE_L_MASK);
589 vdd->write_reg(vc_val, vdd->vc_data->vc_common->prm_mod, OMAP4_PRM_VC_CFG_CHANNEL_OFFSET);
591 /* XXX These are magic numbers and do not belong! */
592 vc_val = (0x60 << OMAP4430_SCLL_SHIFT | 0x26 << OMAP4430_SCLH_SHIFT);
593 vdd->write_reg(vc_val, vdd->vc_data->vc_common->prm_mod, OMAP4_PRM_VC_CFG_I2C_CLK_OFFSET);
595 is_initialized = true;
598 static void __init omap_vc_init(struct voltagedomain *voltdm)
600 struct omap_vdd_info *vdd = voltdm->vdd;
603 if (!vdd->pmic_info || !vdd->pmic_info->uv_to_vsel) {
604 pr_err("%s: PMIC info requried to configure vc for"
605 "vdd_%s not populated.Hence cannot initialize vc\n",
606 __func__, voltdm->name);
610 if (!vdd->read_reg || !vdd->write_reg) {
611 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
612 __func__, voltdm->name);
616 /* Set up the SMPS_SA(i2c slave address in VC */
617 vc_val = vdd->read_reg(vdd->vc_data->vc_common->prm_mod,
618 vdd->vc_data->vc_common->smps_sa_reg);
619 vc_val &= ~vdd->vc_data->smps_sa_mask;
620 vc_val |= vdd->pmic_info->i2c_slave_addr << vdd->vc_data->smps_sa_shift;
621 vdd->write_reg(vc_val, vdd->vc_data->vc_common->prm_mod,
622 vdd->vc_data->vc_common->smps_sa_reg);
624 /* Setup the VOLRA(pmic reg addr) in VC */
625 vc_val = vdd->read_reg(vdd->vc_data->vc_common->prm_mod,
626 vdd->vc_data->vc_common->smps_volra_reg);
627 vc_val &= ~vdd->vc_data->smps_volra_mask;
628 vc_val |= vdd->pmic_info->pmic_reg << vdd->vc_data->smps_volra_shift;
629 vdd->write_reg(vc_val, vdd->vc_data->vc_common->prm_mod,
630 vdd->vc_data->vc_common->smps_volra_reg);
632 /* Configure the setup times */
633 vc_val = vdd->read_reg(vdd->vc_data->vc_common->prm_mod, vdd->vfsm->voltsetup_reg);
634 vc_val &= ~vdd->vfsm->voltsetup_mask;
635 vc_val |= vdd->pmic_info->volt_setup_time <<
636 vdd->vfsm->voltsetup_shift;
637 vdd->write_reg(vc_val, vdd->vc_data->vc_common->prm_mod, vdd->vfsm->voltsetup_reg);
639 if (cpu_is_omap34xx())
640 omap3_vc_init(voltdm);
641 else if (cpu_is_omap44xx())
642 omap4_vc_init(voltdm);
645 static int __init omap_vdd_data_configure(struct voltagedomain *voltdm)
647 struct omap_vdd_info *vdd = voltdm->vdd;
650 if (!vdd->pmic_info) {
651 pr_err("%s: PMIC info requried to configure vdd_%s not"
652 "populated.Hence cannot initialize vdd_%s\n",
653 __func__, voltdm->name, voltdm->name);
657 if (IS_ERR_VALUE(_config_common_vdd_data(voltdm)))
660 if (cpu_is_omap34xx()) {
661 vdd->read_reg = omap3_voltage_read_reg;
662 vdd->write_reg = omap3_voltage_write_reg;
664 } else if (cpu_is_omap44xx()) {
665 vdd->read_reg = omap4_voltage_read_reg;
666 vdd->write_reg = omap4_voltage_write_reg;
674 /* Public functions */
676 * omap_voltage_get_nom_volt() - Gets the current non-auto-compensated voltage
677 * @voltdm: pointer to the VDD for which current voltage info is needed
679 * API to get the current non-auto-compensated voltage for a VDD.
680 * Returns 0 in case of error else returns the current voltage for the VDD.
682 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm)
684 struct omap_vdd_info *vdd;
686 if (!voltdm || IS_ERR(voltdm)) {
687 pr_warning("%s: VDD specified does not exist!\n", __func__);
693 return vdd->curr_volt;
697 * omap_vp_get_curr_volt() - API to get the current vp voltage.
698 * @voltdm: pointer to the VDD.
700 * This API returns the current voltage for the specified voltage processor
702 unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
704 struct omap_vdd_info *vdd;
707 if (!voltdm || IS_ERR(voltdm)) {
708 pr_warning("%s: VDD specified does not exist!\n", __func__);
713 if (!vdd->read_reg) {
714 pr_err("%s: No read API for reading vdd_%s regs\n",
715 __func__, voltdm->name);
719 curr_vsel = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->voltage);
721 if (!vdd->pmic_info || !vdd->pmic_info->vsel_to_uv) {
722 pr_warning("%s: PMIC function to convert vsel to voltage"
723 "in uV not registerd\n", __func__);
727 return vdd->pmic_info->vsel_to_uv(curr_vsel);
731 * omap_vp_enable() - API to enable a particular VP
732 * @voltdm: pointer to the VDD whose VP is to be enabled.
734 * This API enables a particular voltage processor. Needed by the smartreflex
737 void omap_vp_enable(struct voltagedomain *voltdm)
739 struct omap_vdd_info *vdd;
742 if (!voltdm || IS_ERR(voltdm)) {
743 pr_warning("%s: VDD specified does not exist!\n", __func__);
748 if (!vdd->read_reg || !vdd->write_reg) {
749 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
750 __func__, voltdm->name);
754 /* If VP is already enabled, do nothing. Return */
758 vp_latch_vsel(voltdm);
761 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
762 vpconfig |= vdd->vp_data->vp_common->vpconfig_vpenable;
763 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
764 vdd->vp_enabled = true;
768 * omap_vp_disable() - API to disable a particular VP
769 * @voltdm: pointer to the VDD whose VP is to be disabled.
771 * This API disables a particular voltage processor. Needed by the smartreflex
774 void omap_vp_disable(struct voltagedomain *voltdm)
776 struct omap_vdd_info *vdd;
780 if (!voltdm || IS_ERR(voltdm)) {
781 pr_warning("%s: VDD specified does not exist!\n", __func__);
786 if (!vdd->read_reg || !vdd->write_reg) {
787 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
788 __func__, voltdm->name);
792 /* If VP is already disabled, do nothing. Return */
793 if (!vdd->vp_enabled) {
794 pr_warning("%s: Trying to disable VP for vdd_%s when"
795 "it is already disabled\n", __func__, voltdm->name);
800 vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
801 vpconfig &= ~vdd->vp_data->vp_common->vpconfig_vpenable;
802 vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig);
805 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
807 omap_test_timeout((vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vstatus)),
808 VP_IDLE_TIMEOUT, timeout);
810 if (timeout >= VP_IDLE_TIMEOUT)
811 pr_warning("%s: vdd_%s idle timedout\n",
812 __func__, voltdm->name);
814 vdd->vp_enabled = false;
820 * omap_voltage_scale_vdd() - API to scale voltage of a particular
822 * @voltdm: pointer to the VDD which is to be scaled.
823 * @target_volt: The target voltage of the voltage domain
825 * This API should be called by the kernel to do the voltage scaling
826 * for a particular voltage domain during dvfs or any other situation.
828 int omap_voltage_scale_vdd(struct voltagedomain *voltdm,
829 unsigned long target_volt)
831 struct omap_vdd_info *vdd;
833 if (!voltdm || IS_ERR(voltdm)) {
834 pr_warning("%s: VDD specified does not exist!\n", __func__);
840 if (!vdd->volt_scale) {
841 pr_err("%s: No voltage scale API registered for vdd_%s\n",
842 __func__, voltdm->name);
846 return vdd->volt_scale(voltdm, target_volt);
850 * omap_voltage_reset() - Resets the voltage of a particular voltage domain
851 * to that of the current OPP.
852 * @voltdm: pointer to the VDD whose voltage is to be reset.
854 * This API finds out the correct voltage the voltage domain is supposed
855 * to be at and resets the voltage to that level. Should be used especially
856 * while disabling any voltage compensation modules.
858 void omap_voltage_reset(struct voltagedomain *voltdm)
860 unsigned long target_uvdc;
862 if (!voltdm || IS_ERR(voltdm)) {
863 pr_warning("%s: VDD specified does not exist!\n", __func__);
867 target_uvdc = omap_voltage_get_nom_volt(voltdm);
869 pr_err("%s: unable to find current voltage for vdd_%s\n",
870 __func__, voltdm->name);
874 omap_voltage_scale_vdd(voltdm, target_uvdc);
878 * omap_voltage_get_volttable() - API to get the voltage table associated with a
879 * particular voltage domain.
880 * @voltdm: pointer to the VDD for which the voltage table is required
881 * @volt_data: the voltage table for the particular vdd which is to be
882 * populated by this API
884 * This API populates the voltage table associated with a VDD into the
885 * passed parameter pointer. Returns the count of distinct voltages
886 * supported by this vdd.
889 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
890 struct omap_volt_data **volt_data)
892 struct omap_vdd_info *vdd;
894 if (!voltdm || IS_ERR(voltdm)) {
895 pr_warning("%s: VDD specified does not exist!\n", __func__);
901 *volt_data = vdd->volt_data;
905 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
907 * @voltdm: pointer to the VDD whose voltage table has to be searched
908 * @volt: the voltage to be searched in the voltage table
910 * This API searches through the voltage table for the required voltage
911 * domain and tries to find a matching entry for the passed voltage volt.
912 * If a matching entry is found volt_data is populated with that entry.
913 * This API searches only through the non-compensated voltages int the
915 * Returns pointer to the voltage table entry corresponding to volt on
916 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
917 * domain or if there is no matching entry.
919 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
922 struct omap_vdd_info *vdd;
925 if (!voltdm || IS_ERR(voltdm)) {
926 pr_warning("%s: VDD specified does not exist!\n", __func__);
927 return ERR_PTR(-EINVAL);
932 if (!vdd->volt_data) {
933 pr_warning("%s: voltage table does not exist for vdd_%s\n",
934 __func__, voltdm->name);
935 return ERR_PTR(-ENODATA);
938 for (i = 0; vdd->volt_data[i].volt_nominal != 0; i++) {
939 if (vdd->volt_data[i].volt_nominal == volt)
940 return &vdd->volt_data[i];
943 pr_notice("%s: Unable to match the current voltage with the voltage"
944 "table for vdd_%s\n", __func__, voltdm->name);
946 return ERR_PTR(-ENODATA);
950 * omap_voltage_register_pmic() - API to register PMIC specific data
951 * @voltdm: pointer to the VDD for which the PMIC specific data is
953 * @pmic_info: the structure containing pmic info
955 * This API is to be called by the SOC/PMIC file to specify the
956 * pmic specific info as present in omap_volt_pmic_info structure.
958 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
959 struct omap_volt_pmic_info *pmic_info)
961 struct omap_vdd_info *vdd;
963 if (!voltdm || IS_ERR(voltdm)) {
964 pr_warning("%s: VDD specified does not exist!\n", __func__);
970 vdd->pmic_info = pmic_info;
976 * omap_voltage_get_dbgdir() - API to get pointer to the debugfs directory
977 * corresponding to a voltage domain.
979 * @voltdm: pointer to the VDD whose debug directory is required.
981 * This API returns pointer to the debugfs directory corresponding
982 * to the voltage domain. Should be used by drivers requiring to
983 * add any debug entry for a particular voltage domain. Returns NULL
986 struct dentry *omap_voltage_get_dbgdir(struct voltagedomain *voltdm)
988 struct omap_vdd_info *vdd;
990 if (!voltdm || IS_ERR(voltdm)) {
991 pr_warning("%s: VDD specified does not exist!\n", __func__);
997 return vdd->debug_dir;
1001 * omap_change_voltscale_method() - API to change the voltage scaling method.
1002 * @voltdm: pointer to the VDD whose voltage scaling method
1003 * has to be changed.
1004 * @voltscale_method: the method to be used for voltage scaling.
1006 * This API can be used by the board files to change the method of voltage
1007 * scaling between vpforceupdate and vcbypass. The parameter values are
1008 * defined in voltage.h
1010 void omap_change_voltscale_method(struct voltagedomain *voltdm,
1011 int voltscale_method)
1013 struct omap_vdd_info *vdd;
1015 if (!voltdm || IS_ERR(voltdm)) {
1016 pr_warning("%s: VDD specified does not exist!\n", __func__);
1022 switch (voltscale_method) {
1023 case VOLTSCALE_VPFORCEUPDATE:
1024 vdd->volt_scale = vp_forceupdate_scale_voltage;
1026 case VOLTSCALE_VCBYPASS:
1027 vdd->volt_scale = vc_bypass_scale_voltage;
1030 pr_warning("%s: Trying to change the method of voltage scaling"
1031 "to an unsupported one!\n", __func__);
1036 * omap_voltage_late_init() - Init the various voltage parameters
1038 * This API is to be called in the later stages of the
1039 * system boot to init the voltage controller and
1040 * voltage processors.
1042 int __init omap_voltage_late_init(void)
1044 struct voltagedomain *voltdm;
1046 if (list_empty(&voltdm_list)) {
1047 pr_err("%s: Voltage driver support not added\n",
1052 voltage_dir = debugfs_create_dir("voltage", NULL);
1053 if (IS_ERR(voltage_dir))
1054 pr_err("%s: Unable to create voltage debugfs main dir\n",
1056 list_for_each_entry(voltdm, &voltdm_list, node) {
1058 if (omap_vdd_data_configure(voltdm))
1060 omap_vc_init(voltdm);
1062 vdd_debugfs_init(voltdm);
1069 static struct voltagedomain *_voltdm_lookup(const char *name)
1071 struct voltagedomain *voltdm, *temp_voltdm;
1075 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
1076 if (!strcmp(name, temp_voltdm->name)) {
1077 voltdm = temp_voltdm;
1085 static int _voltdm_register(struct voltagedomain *voltdm)
1087 if (!voltdm || !voltdm->name)
1090 list_add(&voltdm->node, &voltdm_list);
1092 pr_debug("voltagedomain: registered %s\n", voltdm->name);
1098 * voltdm_lookup - look up a voltagedomain by name, return a pointer
1099 * @name: name of voltagedomain
1101 * Find a registered voltagedomain by its name @name. Returns a pointer
1102 * to the struct voltagedomain if found, or NULL otherwise.
1104 struct voltagedomain *voltdm_lookup(const char *name)
1106 struct voltagedomain *voltdm ;
1111 voltdm = _voltdm_lookup(name);
1117 * voltdm_init - set up the voltagedomain layer
1118 * @voltdm_list: array of struct voltagedomain pointers to register
1120 * Loop through the array of voltagedomains @voltdm_list, registering all
1121 * that are available on the current CPU. If voltdm_list is supplied
1122 * and not null, all of the referenced voltagedomains will be
1123 * registered. No return value.
1125 void voltdm_init(struct voltagedomain **voltdms)
1127 struct voltagedomain **v;
1130 for (v = voltdms; *v; v++)
1131 _voltdm_register(*v);