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/export.h>
27 #include <linux/debugfs.h>
28 #include <linux/slab.h>
30 #include <plat/common.h>
32 #include "prm-regbits-34xx.h"
33 #include "prm-regbits-44xx.h"
36 #include "prminst44xx.h"
44 #define VOLTAGE_DIR_SIZE 16
47 static struct omap_vdd_info
**vdd_info
;
50 * Number of scalable voltage domains.
52 static int nr_scalable_vdd
;
55 static s16 prm_mod_offs
;
56 static s16 prm_irqst_ocp_mod_offs
;
58 static struct dentry
*voltage_dir
;
60 /* Init function pointers */
61 static int vp_forceupdate_scale_voltage(struct omap_vdd_info
*vdd
,
62 unsigned long target_volt
);
64 static u32
omap3_voltage_read_reg(u16 mod
, u8 offset
)
66 return omap2_prm_read_mod_reg(mod
, offset
);
69 static void omap3_voltage_write_reg(u32 val
, u16 mod
, u8 offset
)
71 omap2_prm_write_mod_reg(val
, mod
, offset
);
74 static u32
omap4_voltage_read_reg(u16 mod
, u8 offset
)
76 return omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION
,
80 static void omap4_voltage_write_reg(u32 val
, u16 mod
, u8 offset
)
82 omap4_prminst_write_inst_reg(val
, OMAP4430_PRM_PARTITION
, mod
, offset
);
85 static int __init
_config_common_vdd_data(struct omap_vdd_info
*vdd
)
89 u32 sys_clk_speed
, timeout_val
, waittime
;
92 * XXX Clockfw should handle this, or this should be in a
95 if (cpu_is_omap24xx() || cpu_is_omap34xx())
96 sys_ck_name
= "sys_ck";
97 else if (cpu_is_omap44xx())
98 sys_ck_name
= "sys_clkin_ck";
103 * Sys clk rate is require to calculate vp timeout value and
104 * smpswaittimemin and smpswaittimemax.
106 sys_ck
= clk_get(NULL
, sys_ck_name
);
107 if (IS_ERR(sys_ck
)) {
108 pr_warning("%s: Could not get the sys clk to calculate"
109 "various vdd_%s params\n", __func__
, vdd
->voltdm
.name
);
112 sys_clk_speed
= clk_get_rate(sys_ck
);
114 /* Divide to avoid overflow */
115 sys_clk_speed
/= 1000;
117 /* Generic voltage parameters */
118 vdd
->volt_scale
= vp_forceupdate_scale_voltage
;
119 vdd
->vp_enabled
= false;
121 vdd
->vp_rt_data
.vpconfig_erroroffset
=
122 (vdd
->pmic_info
->vp_erroroffset
<<
123 vdd
->vp_data
->vp_common
->vpconfig_erroroffset_shift
);
125 timeout_val
= (sys_clk_speed
* vdd
->pmic_info
->vp_timeout_us
) / 1000;
126 vdd
->vp_rt_data
.vlimitto_timeout
= timeout_val
;
127 vdd
->vp_rt_data
.vlimitto_vddmin
= vdd
->pmic_info
->vp_vddmin
;
128 vdd
->vp_rt_data
.vlimitto_vddmax
= vdd
->pmic_info
->vp_vddmax
;
130 waittime
= ((vdd
->pmic_info
->step_size
/ vdd
->pmic_info
->slew_rate
) *
131 sys_clk_speed
) / 1000;
132 vdd
->vp_rt_data
.vstepmin_smpswaittimemin
= waittime
;
133 vdd
->vp_rt_data
.vstepmax_smpswaittimemax
= waittime
;
134 vdd
->vp_rt_data
.vstepmin_stepmin
= vdd
->pmic_info
->vp_vstepmin
;
135 vdd
->vp_rt_data
.vstepmax_stepmax
= vdd
->pmic_info
->vp_vstepmax
;
140 /* Voltage debugfs support */
141 static int vp_volt_debug_get(void *data
, u64
*val
)
143 struct omap_vdd_info
*vdd
= (struct omap_vdd_info
*) data
;
147 pr_warning("Wrong paramater passed\n");
151 vsel
= vdd
->read_reg(prm_mod_offs
, vdd
->vp_data
->voltage
);
153 if (!vdd
->pmic_info
->vsel_to_uv
) {
154 pr_warning("PMIC function to convert vsel to voltage"
155 "in uV not registerd\n");
159 *val
= vdd
->pmic_info
->vsel_to_uv(vsel
);
163 static int nom_volt_debug_get(void *data
, u64
*val
)
165 struct omap_vdd_info
*vdd
= (struct omap_vdd_info
*) data
;
168 pr_warning("Wrong paramater passed\n");
172 *val
= omap_voltage_get_nom_volt(&vdd
->voltdm
);
177 DEFINE_SIMPLE_ATTRIBUTE(vp_volt_debug_fops
, vp_volt_debug_get
, NULL
, "%llu\n");
178 DEFINE_SIMPLE_ATTRIBUTE(nom_volt_debug_fops
, nom_volt_debug_get
, NULL
,
180 static void vp_latch_vsel(struct omap_vdd_info
*vdd
)
186 uvdc
= omap_voltage_get_nom_volt(&vdd
->voltdm
);
188 pr_warning("%s: unable to find current voltage for vdd_%s\n",
189 __func__
, vdd
->voltdm
.name
);
193 if (!vdd
->pmic_info
|| !vdd
->pmic_info
->uv_to_vsel
) {
194 pr_warning("%s: PMIC function to convert voltage in uV to"
195 " vsel not registered\n", __func__
);
199 vsel
= vdd
->pmic_info
->uv_to_vsel(uvdc
);
201 vpconfig
= vdd
->read_reg(prm_mod_offs
, vdd
->vp_data
->vpconfig
);
202 vpconfig
&= ~(vdd
->vp_data
->vp_common
->vpconfig_initvoltage_mask
|
203 vdd
->vp_data
->vp_common
->vpconfig_initvdd
);
204 vpconfig
|= vsel
<< vdd
->vp_data
->vp_common
->vpconfig_initvoltage_shift
;
206 vdd
->write_reg(vpconfig
, prm_mod_offs
, vdd
->vp_data
->vpconfig
);
208 /* Trigger initVDD value copy to voltage processor */
209 vdd
->write_reg((vpconfig
| vdd
->vp_data
->vp_common
->vpconfig_initvdd
),
210 prm_mod_offs
, vdd
->vp_data
->vpconfig
);
212 /* Clear initVDD copy trigger bit */
213 vdd
->write_reg(vpconfig
, prm_mod_offs
, vdd
->vp_data
->vpconfig
);
216 /* Generic voltage init functions */
217 static void __init
vp_init(struct omap_vdd_info
*vdd
)
221 if (!vdd
->read_reg
|| !vdd
->write_reg
) {
222 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
223 __func__
, vdd
->voltdm
.name
);
227 vp_val
= vdd
->vp_rt_data
.vpconfig_erroroffset
|
228 (vdd
->vp_rt_data
.vpconfig_errorgain
<<
229 vdd
->vp_data
->vp_common
->vpconfig_errorgain_shift
) |
230 vdd
->vp_data
->vp_common
->vpconfig_timeouten
;
231 vdd
->write_reg(vp_val
, prm_mod_offs
, vdd
->vp_data
->vpconfig
);
233 vp_val
= ((vdd
->vp_rt_data
.vstepmin_smpswaittimemin
<<
234 vdd
->vp_data
->vp_common
->vstepmin_smpswaittimemin_shift
) |
235 (vdd
->vp_rt_data
.vstepmin_stepmin
<<
236 vdd
->vp_data
->vp_common
->vstepmin_stepmin_shift
));
237 vdd
->write_reg(vp_val
, prm_mod_offs
, vdd
->vp_data
->vstepmin
);
239 vp_val
= ((vdd
->vp_rt_data
.vstepmax_smpswaittimemax
<<
240 vdd
->vp_data
->vp_common
->vstepmax_smpswaittimemax_shift
) |
241 (vdd
->vp_rt_data
.vstepmax_stepmax
<<
242 vdd
->vp_data
->vp_common
->vstepmax_stepmax_shift
));
243 vdd
->write_reg(vp_val
, prm_mod_offs
, vdd
->vp_data
->vstepmax
);
245 vp_val
= ((vdd
->vp_rt_data
.vlimitto_vddmax
<<
246 vdd
->vp_data
->vp_common
->vlimitto_vddmax_shift
) |
247 (vdd
->vp_rt_data
.vlimitto_vddmin
<<
248 vdd
->vp_data
->vp_common
->vlimitto_vddmin_shift
) |
249 (vdd
->vp_rt_data
.vlimitto_timeout
<<
250 vdd
->vp_data
->vp_common
->vlimitto_timeout_shift
));
251 vdd
->write_reg(vp_val
, prm_mod_offs
, vdd
->vp_data
->vlimitto
);
254 static void __init
vdd_debugfs_init(struct omap_vdd_info
*vdd
)
258 name
= kzalloc(VOLTAGE_DIR_SIZE
, GFP_KERNEL
);
260 pr_warning("%s: Unable to allocate memory for debugfs"
261 " directory name for vdd_%s",
262 __func__
, vdd
->voltdm
.name
);
265 strcpy(name
, "vdd_");
266 strcat(name
, vdd
->voltdm
.name
);
268 vdd
->debug_dir
= debugfs_create_dir(name
, voltage_dir
);
270 if (IS_ERR(vdd
->debug_dir
)) {
271 pr_warning("%s: Unable to create debugfs directory for"
272 " vdd_%s\n", __func__
, vdd
->voltdm
.name
);
273 vdd
->debug_dir
= NULL
;
277 (void) debugfs_create_x16("vp_errorgain", S_IRUGO
, vdd
->debug_dir
,
278 &(vdd
->vp_rt_data
.vpconfig_errorgain
));
279 (void) debugfs_create_x16("vp_smpswaittimemin", S_IRUGO
,
281 &(vdd
->vp_rt_data
.vstepmin_smpswaittimemin
));
282 (void) debugfs_create_x8("vp_stepmin", S_IRUGO
, vdd
->debug_dir
,
283 &(vdd
->vp_rt_data
.vstepmin_stepmin
));
284 (void) debugfs_create_x16("vp_smpswaittimemax", S_IRUGO
,
286 &(vdd
->vp_rt_data
.vstepmax_smpswaittimemax
));
287 (void) debugfs_create_x8("vp_stepmax", S_IRUGO
, vdd
->debug_dir
,
288 &(vdd
->vp_rt_data
.vstepmax_stepmax
));
289 (void) debugfs_create_x8("vp_vddmax", S_IRUGO
, vdd
->debug_dir
,
290 &(vdd
->vp_rt_data
.vlimitto_vddmax
));
291 (void) debugfs_create_x8("vp_vddmin", S_IRUGO
, vdd
->debug_dir
,
292 &(vdd
->vp_rt_data
.vlimitto_vddmin
));
293 (void) debugfs_create_x16("vp_timeout", S_IRUGO
, vdd
->debug_dir
,
294 &(vdd
->vp_rt_data
.vlimitto_timeout
));
295 (void) debugfs_create_file("curr_vp_volt", S_IRUGO
, vdd
->debug_dir
,
296 (void *) vdd
, &vp_volt_debug_fops
);
297 (void) debugfs_create_file("curr_nominal_volt", S_IRUGO
,
298 vdd
->debug_dir
, (void *) vdd
,
299 &nom_volt_debug_fops
);
302 /* Voltage scale and accessory APIs */
303 static int _pre_volt_scale(struct omap_vdd_info
*vdd
,
304 unsigned long target_volt
, u8
*target_vsel
, u8
*current_vsel
)
306 struct omap_volt_data
*volt_data
;
307 const struct omap_vc_common_data
*vc_common
;
308 const struct omap_vp_common_data
*vp_common
;
309 u32 vc_cmdval
, vp_errgain_val
;
311 vc_common
= vdd
->vc_data
->vc_common
;
312 vp_common
= vdd
->vp_data
->vp_common
;
314 /* Check if suffiecient pmic info is available for this vdd */
315 if (!vdd
->pmic_info
) {
316 pr_err("%s: Insufficient pmic info to scale the vdd_%s\n",
317 __func__
, vdd
->voltdm
.name
);
321 if (!vdd
->pmic_info
->uv_to_vsel
) {
322 pr_err("%s: PMIC function to convert voltage in uV to"
323 "vsel not registered. Hence unable to scale voltage"
324 "for vdd_%s\n", __func__
, vdd
->voltdm
.name
);
328 if (!vdd
->read_reg
|| !vdd
->write_reg
) {
329 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
330 __func__
, vdd
->voltdm
.name
);
334 /* Get volt_data corresponding to target_volt */
335 volt_data
= omap_voltage_get_voltdata(&vdd
->voltdm
, target_volt
);
336 if (IS_ERR(volt_data
))
339 *target_vsel
= vdd
->pmic_info
->uv_to_vsel(target_volt
);
340 *current_vsel
= vdd
->read_reg(prm_mod_offs
, vdd
->vp_data
->voltage
);
342 /* Setting the ON voltage to the new target voltage */
343 vc_cmdval
= vdd
->read_reg(prm_mod_offs
, vdd
->vc_data
->cmdval_reg
);
344 vc_cmdval
&= ~vc_common
->cmd_on_mask
;
345 vc_cmdval
|= (*target_vsel
<< vc_common
->cmd_on_shift
);
346 vdd
->write_reg(vc_cmdval
, prm_mod_offs
, vdd
->vc_data
->cmdval_reg
);
348 /* Setting vp errorgain based on the voltage */
350 vp_errgain_val
= vdd
->read_reg(prm_mod_offs
,
351 vdd
->vp_data
->vpconfig
);
352 vdd
->vp_rt_data
.vpconfig_errorgain
= volt_data
->vp_errgain
;
353 vp_errgain_val
&= ~vp_common
->vpconfig_errorgain_mask
;
354 vp_errgain_val
|= vdd
->vp_rt_data
.vpconfig_errorgain
<<
355 vp_common
->vpconfig_errorgain_shift
;
356 vdd
->write_reg(vp_errgain_val
, prm_mod_offs
,
357 vdd
->vp_data
->vpconfig
);
363 static void _post_volt_scale(struct omap_vdd_info
*vdd
,
364 unsigned long target_volt
, u8 target_vsel
, u8 current_vsel
)
366 u32 smps_steps
= 0, smps_delay
= 0;
368 smps_steps
= abs(target_vsel
- current_vsel
);
369 /* SMPS slew rate / step size. 2us added as buffer. */
370 smps_delay
= ((smps_steps
* vdd
->pmic_info
->step_size
) /
371 vdd
->pmic_info
->slew_rate
) + 2;
374 vdd
->curr_volt
= target_volt
;
377 /* vc_bypass_scale_voltage - VC bypass method of voltage scaling */
378 static int vc_bypass_scale_voltage(struct omap_vdd_info
*vdd
,
379 unsigned long target_volt
)
381 u32 loop_cnt
= 0, retries_cnt
= 0;
382 u32 vc_valid
, vc_bypass_val_reg
, vc_bypass_value
;
383 u8 target_vsel
, current_vsel
;
386 ret
= _pre_volt_scale(vdd
, target_volt
, &target_vsel
, ¤t_vsel
);
390 vc_valid
= vdd
->vc_data
->vc_common
->valid
;
391 vc_bypass_val_reg
= vdd
->vc_data
->vc_common
->bypass_val_reg
;
392 vc_bypass_value
= (target_vsel
<< vdd
->vc_data
->vc_common
->data_shift
) |
393 (vdd
->pmic_info
->pmic_reg
<<
394 vdd
->vc_data
->vc_common
->regaddr_shift
) |
395 (vdd
->pmic_info
->i2c_slave_addr
<<
396 vdd
->vc_data
->vc_common
->slaveaddr_shift
);
398 vdd
->write_reg(vc_bypass_value
, prm_mod_offs
, vc_bypass_val_reg
);
399 vdd
->write_reg(vc_bypass_value
| vc_valid
, prm_mod_offs
,
402 vc_bypass_value
= vdd
->read_reg(prm_mod_offs
, vc_bypass_val_reg
);
404 * Loop till the bypass command is acknowledged from the SMPS.
405 * NOTE: This is legacy code. The loop count and retry count needs
408 while (!(vc_bypass_value
& vc_valid
)) {
411 if (retries_cnt
> 10) {
412 pr_warning("%s: Retry count exceeded\n", __func__
);
421 vc_bypass_value
= vdd
->read_reg(prm_mod_offs
,
425 _post_volt_scale(vdd
, target_volt
, target_vsel
, current_vsel
);
429 /* VP force update method of voltage scaling */
430 static int vp_forceupdate_scale_voltage(struct omap_vdd_info
*vdd
,
431 unsigned long target_volt
)
434 u8 target_vsel
, current_vsel
, prm_irqst_reg
;
435 int ret
, timeout
= 0;
437 ret
= _pre_volt_scale(vdd
, target_volt
, &target_vsel
, ¤t_vsel
);
441 prm_irqst_reg
= vdd
->vp_data
->prm_irqst_data
->prm_irqst_reg
;
444 * Clear all pending TransactionDone interrupt/status. Typical latency
447 while (timeout
++ < VP_TRANXDONE_TIMEOUT
) {
448 vdd
->write_reg(vdd
->vp_data
->prm_irqst_data
->tranxdone_status
,
449 prm_irqst_ocp_mod_offs
, prm_irqst_reg
);
450 if (!(vdd
->read_reg(prm_irqst_ocp_mod_offs
, prm_irqst_reg
) &
451 vdd
->vp_data
->prm_irqst_data
->tranxdone_status
))
455 if (timeout
>= VP_TRANXDONE_TIMEOUT
) {
456 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
457 "Voltage change aborted", __func__
, vdd
->voltdm
.name
);
461 /* Configure for VP-Force Update */
462 vpconfig
= vdd
->read_reg(prm_mod_offs
, vdd
->vp_data
->vpconfig
);
463 vpconfig
&= ~(vdd
->vp_data
->vp_common
->vpconfig_initvdd
|
464 vdd
->vp_data
->vp_common
->vpconfig_forceupdate
|
465 vdd
->vp_data
->vp_common
->vpconfig_initvoltage_mask
);
466 vpconfig
|= ((target_vsel
<<
467 vdd
->vp_data
->vp_common
->vpconfig_initvoltage_shift
));
468 vdd
->write_reg(vpconfig
, prm_mod_offs
, vdd
->vp_data
->vpconfig
);
470 /* Trigger initVDD value copy to voltage processor */
471 vpconfig
|= vdd
->vp_data
->vp_common
->vpconfig_initvdd
;
472 vdd
->write_reg(vpconfig
, prm_mod_offs
, vdd
->vp_data
->vpconfig
);
474 /* Force update of voltage */
475 vpconfig
|= vdd
->vp_data
->vp_common
->vpconfig_forceupdate
;
476 vdd
->write_reg(vpconfig
, prm_mod_offs
, vdd
->vp_data
->vpconfig
);
479 * Wait for TransactionDone. Typical latency is <200us.
480 * Depends on SMPSWAITTIMEMIN/MAX and voltage change
483 omap_test_timeout((vdd
->read_reg(prm_irqst_ocp_mod_offs
, prm_irqst_reg
) &
484 vdd
->vp_data
->prm_irqst_data
->tranxdone_status
),
485 VP_TRANXDONE_TIMEOUT
, timeout
);
486 if (timeout
>= VP_TRANXDONE_TIMEOUT
)
487 pr_err("%s: vdd_%s TRANXDONE timeout exceeded."
488 "TRANXDONE never got set after the voltage update\n",
489 __func__
, vdd
->voltdm
.name
);
491 _post_volt_scale(vdd
, target_volt
, target_vsel
, current_vsel
);
494 * Disable TransactionDone interrupt , clear all status, clear
498 while (timeout
++ < VP_TRANXDONE_TIMEOUT
) {
499 vdd
->write_reg(vdd
->vp_data
->prm_irqst_data
->tranxdone_status
,
500 prm_irqst_ocp_mod_offs
, prm_irqst_reg
);
501 if (!(vdd
->read_reg(prm_irqst_ocp_mod_offs
, prm_irqst_reg
) &
502 vdd
->vp_data
->prm_irqst_data
->tranxdone_status
))
507 if (timeout
>= VP_TRANXDONE_TIMEOUT
)
508 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying"
509 "to clear the TRANXDONE status\n",
510 __func__
, vdd
->voltdm
.name
);
512 vpconfig
= vdd
->read_reg(prm_mod_offs
, vdd
->vp_data
->vpconfig
);
513 /* Clear initVDD copy trigger bit */
514 vpconfig
&= ~vdd
->vp_data
->vp_common
->vpconfig_initvdd
;
515 vdd
->write_reg(vpconfig
, prm_mod_offs
, vdd
->vp_data
->vpconfig
);
516 /* Clear force bit */
517 vpconfig
&= ~vdd
->vp_data
->vp_common
->vpconfig_forceupdate
;
518 vdd
->write_reg(vpconfig
, prm_mod_offs
, vdd
->vp_data
->vpconfig
);
523 static void __init
omap3_vfsm_init(struct omap_vdd_info
*vdd
)
526 * Voltage Manager FSM parameters init
527 * XXX This data should be passed in from the board file
529 vdd
->write_reg(OMAP3_CLKSETUP
, prm_mod_offs
, OMAP3_PRM_CLKSETUP_OFFSET
);
530 vdd
->write_reg(OMAP3_VOLTOFFSET
, prm_mod_offs
,
531 OMAP3_PRM_VOLTOFFSET_OFFSET
);
532 vdd
->write_reg(OMAP3_VOLTSETUP2
, prm_mod_offs
,
533 OMAP3_PRM_VOLTSETUP2_OFFSET
);
536 static void __init
omap3_vc_init(struct omap_vdd_info
*vdd
)
538 static bool is_initialized
;
539 u8 on_vsel
, onlp_vsel
, ret_vsel
, off_vsel
;
545 /* Set up the on, inactive, retention and off voltage */
546 on_vsel
= vdd
->pmic_info
->uv_to_vsel(vdd
->pmic_info
->on_volt
);
547 onlp_vsel
= vdd
->pmic_info
->uv_to_vsel(vdd
->pmic_info
->onlp_volt
);
548 ret_vsel
= vdd
->pmic_info
->uv_to_vsel(vdd
->pmic_info
->ret_volt
);
549 off_vsel
= vdd
->pmic_info
->uv_to_vsel(vdd
->pmic_info
->off_volt
);
550 vc_val
= ((on_vsel
<< vdd
->vc_data
->vc_common
->cmd_on_shift
) |
551 (onlp_vsel
<< vdd
->vc_data
->vc_common
->cmd_onlp_shift
) |
552 (ret_vsel
<< vdd
->vc_data
->vc_common
->cmd_ret_shift
) |
553 (off_vsel
<< vdd
->vc_data
->vc_common
->cmd_off_shift
));
554 vdd
->write_reg(vc_val
, prm_mod_offs
, vdd
->vc_data
->cmdval_reg
);
557 * Generic VC parameters init
558 * XXX This data should be abstracted out
560 vdd
->write_reg(OMAP3430_CMD1_MASK
| OMAP3430_RAV1_MASK
, prm_mod_offs
,
561 OMAP3_PRM_VC_CH_CONF_OFFSET
);
562 vdd
->write_reg(OMAP3430_MCODE_SHIFT
| OMAP3430_HSEN_MASK
, prm_mod_offs
,
563 OMAP3_PRM_VC_I2C_CFG_OFFSET
);
565 omap3_vfsm_init(vdd
);
567 is_initialized
= true;
571 /* OMAP4 specific voltage init functions */
572 static void __init
omap4_vc_init(struct omap_vdd_info
*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
, prm_mod_offs
, 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
, prm_mod_offs
, OMAP4_PRM_VC_CFG_I2C_CLK_OFFSET
);
595 is_initialized
= true;
598 static void __init
omap_vc_init(struct omap_vdd_info
*vdd
)
602 if (!vdd
->pmic_info
|| !vdd
->pmic_info
->uv_to_vsel
) {
603 pr_err("%s: PMIC info requried to configure vc for"
604 "vdd_%s not populated.Hence cannot initialize vc\n",
605 __func__
, vdd
->voltdm
.name
);
609 if (!vdd
->read_reg
|| !vdd
->write_reg
) {
610 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
611 __func__
, vdd
->voltdm
.name
);
615 /* Set up the SMPS_SA(i2c slave address in VC */
616 vc_val
= vdd
->read_reg(prm_mod_offs
,
617 vdd
->vc_data
->vc_common
->smps_sa_reg
);
618 vc_val
&= ~vdd
->vc_data
->smps_sa_mask
;
619 vc_val
|= vdd
->pmic_info
->i2c_slave_addr
<< vdd
->vc_data
->smps_sa_shift
;
620 vdd
->write_reg(vc_val
, prm_mod_offs
,
621 vdd
->vc_data
->vc_common
->smps_sa_reg
);
623 /* Setup the VOLRA(pmic reg addr) in VC */
624 vc_val
= vdd
->read_reg(prm_mod_offs
,
625 vdd
->vc_data
->vc_common
->smps_volra_reg
);
626 vc_val
&= ~vdd
->vc_data
->smps_volra_mask
;
627 vc_val
|= vdd
->pmic_info
->pmic_reg
<< vdd
->vc_data
->smps_volra_shift
;
628 vdd
->write_reg(vc_val
, prm_mod_offs
,
629 vdd
->vc_data
->vc_common
->smps_volra_reg
);
631 /* Configure the setup times */
632 vc_val
= vdd
->read_reg(prm_mod_offs
, vdd
->vfsm
->voltsetup_reg
);
633 vc_val
&= ~vdd
->vfsm
->voltsetup_mask
;
634 vc_val
|= vdd
->pmic_info
->volt_setup_time
<<
635 vdd
->vfsm
->voltsetup_shift
;
636 vdd
->write_reg(vc_val
, prm_mod_offs
, vdd
->vfsm
->voltsetup_reg
);
638 if (cpu_is_omap34xx())
640 else if (cpu_is_omap44xx())
644 static int __init
omap_vdd_data_configure(struct omap_vdd_info
*vdd
)
648 if (!vdd
->pmic_info
) {
649 pr_err("%s: PMIC info requried to configure vdd_%s not"
650 "populated.Hence cannot initialize vdd_%s\n",
651 __func__
, vdd
->voltdm
.name
, vdd
->voltdm
.name
);
655 if (IS_ERR_VALUE(_config_common_vdd_data(vdd
)))
658 if (cpu_is_omap34xx()) {
659 vdd
->read_reg
= omap3_voltage_read_reg
;
660 vdd
->write_reg
= omap3_voltage_write_reg
;
662 } else if (cpu_is_omap44xx()) {
663 vdd
->read_reg
= omap4_voltage_read_reg
;
664 vdd
->write_reg
= omap4_voltage_write_reg
;
672 /* Public functions */
674 * omap_voltage_get_nom_volt() - Gets the current non-auto-compensated voltage
675 * @voltdm: pointer to the VDD for which current voltage info is needed
677 * API to get the current non-auto-compensated voltage for a VDD.
678 * Returns 0 in case of error else returns the current voltage for the VDD.
680 unsigned long omap_voltage_get_nom_volt(struct voltagedomain
*voltdm
)
682 struct omap_vdd_info
*vdd
;
684 if (!voltdm
|| IS_ERR(voltdm
)) {
685 pr_warning("%s: VDD specified does not exist!\n", __func__
);
689 vdd
= container_of(voltdm
, struct omap_vdd_info
, voltdm
);
691 return vdd
->curr_volt
;
695 * omap_vp_get_curr_volt() - API to get the current vp voltage.
696 * @voltdm: pointer to the VDD.
698 * This API returns the current voltage for the specified voltage processor
700 unsigned long omap_vp_get_curr_volt(struct voltagedomain
*voltdm
)
702 struct omap_vdd_info
*vdd
;
705 if (!voltdm
|| IS_ERR(voltdm
)) {
706 pr_warning("%s: VDD specified does not exist!\n", __func__
);
710 vdd
= container_of(voltdm
, struct omap_vdd_info
, voltdm
);
711 if (!vdd
->read_reg
) {
712 pr_err("%s: No read API for reading vdd_%s regs\n",
713 __func__
, voltdm
->name
);
717 curr_vsel
= vdd
->read_reg(prm_mod_offs
, vdd
->vp_data
->voltage
);
719 if (!vdd
->pmic_info
|| !vdd
->pmic_info
->vsel_to_uv
) {
720 pr_warning("%s: PMIC function to convert vsel to voltage"
721 "in uV not registerd\n", __func__
);
725 return vdd
->pmic_info
->vsel_to_uv(curr_vsel
);
729 * omap_vp_enable() - API to enable a particular VP
730 * @voltdm: pointer to the VDD whose VP is to be enabled.
732 * This API enables a particular voltage processor. Needed by the smartreflex
735 void omap_vp_enable(struct voltagedomain
*voltdm
)
737 struct omap_vdd_info
*vdd
;
740 if (!voltdm
|| IS_ERR(voltdm
)) {
741 pr_warning("%s: VDD specified does not exist!\n", __func__
);
745 vdd
= container_of(voltdm
, struct omap_vdd_info
, voltdm
);
746 if (!vdd
->read_reg
|| !vdd
->write_reg
) {
747 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
748 __func__
, voltdm
->name
);
752 /* If VP is already enabled, do nothing. Return */
759 vpconfig
= vdd
->read_reg(prm_mod_offs
, vdd
->vp_data
->vpconfig
);
760 vpconfig
|= vdd
->vp_data
->vp_common
->vpconfig_vpenable
;
761 vdd
->write_reg(vpconfig
, prm_mod_offs
, vdd
->vp_data
->vpconfig
);
762 vdd
->vp_enabled
= true;
766 * omap_vp_disable() - API to disable a particular VP
767 * @voltdm: pointer to the VDD whose VP is to be disabled.
769 * This API disables a particular voltage processor. Needed by the smartreflex
772 void omap_vp_disable(struct voltagedomain
*voltdm
)
774 struct omap_vdd_info
*vdd
;
778 if (!voltdm
|| IS_ERR(voltdm
)) {
779 pr_warning("%s: VDD specified does not exist!\n", __func__
);
783 vdd
= container_of(voltdm
, struct omap_vdd_info
, voltdm
);
784 if (!vdd
->read_reg
|| !vdd
->write_reg
) {
785 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
786 __func__
, voltdm
->name
);
790 /* If VP is already disabled, do nothing. Return */
791 if (!vdd
->vp_enabled
) {
792 pr_warning("%s: Trying to disable VP for vdd_%s when"
793 "it is already disabled\n", __func__
, voltdm
->name
);
798 vpconfig
= vdd
->read_reg(prm_mod_offs
, vdd
->vp_data
->vpconfig
);
799 vpconfig
&= ~vdd
->vp_data
->vp_common
->vpconfig_vpenable
;
800 vdd
->write_reg(vpconfig
, prm_mod_offs
, vdd
->vp_data
->vpconfig
);
803 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
805 omap_test_timeout((vdd
->read_reg(prm_mod_offs
, vdd
->vp_data
->vstatus
)),
806 VP_IDLE_TIMEOUT
, timeout
);
808 if (timeout
>= VP_IDLE_TIMEOUT
)
809 pr_warning("%s: vdd_%s idle timedout\n",
810 __func__
, voltdm
->name
);
812 vdd
->vp_enabled
= false;
818 * omap_voltage_scale_vdd() - API to scale voltage of a particular
820 * @voltdm: pointer to the VDD which is to be scaled.
821 * @target_volt: The target voltage of the voltage domain
823 * This API should be called by the kernel to do the voltage scaling
824 * for a particular voltage domain during dvfs or any other situation.
826 int omap_voltage_scale_vdd(struct voltagedomain
*voltdm
,
827 unsigned long target_volt
)
829 struct omap_vdd_info
*vdd
;
831 if (!voltdm
|| IS_ERR(voltdm
)) {
832 pr_warning("%s: VDD specified does not exist!\n", __func__
);
836 vdd
= container_of(voltdm
, struct omap_vdd_info
, voltdm
);
838 if (!vdd
->volt_scale
) {
839 pr_err("%s: No voltage scale API registered for vdd_%s\n",
840 __func__
, voltdm
->name
);
844 return vdd
->volt_scale(vdd
, target_volt
);
848 * omap_voltage_reset() - Resets the voltage of a particular voltage domain
849 * to that of the current OPP.
850 * @voltdm: pointer to the VDD whose voltage is to be reset.
852 * This API finds out the correct voltage the voltage domain is supposed
853 * to be at and resets the voltage to that level. Should be used especially
854 * while disabling any voltage compensation modules.
856 void omap_voltage_reset(struct voltagedomain
*voltdm
)
858 unsigned long target_uvdc
;
860 if (!voltdm
|| IS_ERR(voltdm
)) {
861 pr_warning("%s: VDD specified does not exist!\n", __func__
);
865 target_uvdc
= omap_voltage_get_nom_volt(voltdm
);
867 pr_err("%s: unable to find current voltage for vdd_%s\n",
868 __func__
, voltdm
->name
);
872 omap_voltage_scale_vdd(voltdm
, target_uvdc
);
876 * omap_voltage_get_volttable() - API to get the voltage table associated with a
877 * particular voltage domain.
878 * @voltdm: pointer to the VDD for which the voltage table is required
879 * @volt_data: the voltage table for the particular vdd which is to be
880 * populated by this API
882 * This API populates the voltage table associated with a VDD into the
883 * passed parameter pointer. Returns the count of distinct voltages
884 * supported by this vdd.
887 void omap_voltage_get_volttable(struct voltagedomain
*voltdm
,
888 struct omap_volt_data
**volt_data
)
890 struct omap_vdd_info
*vdd
;
892 if (!voltdm
|| IS_ERR(voltdm
)) {
893 pr_warning("%s: VDD specified does not exist!\n", __func__
);
897 vdd
= container_of(voltdm
, struct omap_vdd_info
, voltdm
);
899 *volt_data
= vdd
->volt_data
;
903 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
905 * @voltdm: pointer to the VDD whose voltage table has to be searched
906 * @volt: the voltage to be searched in the voltage table
908 * This API searches through the voltage table for the required voltage
909 * domain and tries to find a matching entry for the passed voltage volt.
910 * If a matching entry is found volt_data is populated with that entry.
911 * This API searches only through the non-compensated voltages int the
913 * Returns pointer to the voltage table entry corresponding to volt on
914 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
915 * domain or if there is no matching entry.
917 struct omap_volt_data
*omap_voltage_get_voltdata(struct voltagedomain
*voltdm
,
920 struct omap_vdd_info
*vdd
;
923 if (!voltdm
|| IS_ERR(voltdm
)) {
924 pr_warning("%s: VDD specified does not exist!\n", __func__
);
925 return ERR_PTR(-EINVAL
);
928 vdd
= container_of(voltdm
, struct omap_vdd_info
, voltdm
);
930 if (!vdd
->volt_data
) {
931 pr_warning("%s: voltage table does not exist for vdd_%s\n",
932 __func__
, voltdm
->name
);
933 return ERR_PTR(-ENODATA
);
936 for (i
= 0; vdd
->volt_data
[i
].volt_nominal
!= 0; i
++) {
937 if (vdd
->volt_data
[i
].volt_nominal
== volt
)
938 return &vdd
->volt_data
[i
];
941 pr_notice("%s: Unable to match the current voltage with the voltage"
942 "table for vdd_%s\n", __func__
, voltdm
->name
);
944 return ERR_PTR(-ENODATA
);
948 * omap_voltage_register_pmic() - API to register PMIC specific data
949 * @voltdm: pointer to the VDD for which the PMIC specific data is
951 * @pmic_info: the structure containing pmic info
953 * This API is to be called by the SOC/PMIC file to specify the
954 * pmic specific info as present in omap_volt_pmic_info structure.
956 int omap_voltage_register_pmic(struct voltagedomain
*voltdm
,
957 struct omap_volt_pmic_info
*pmic_info
)
959 struct omap_vdd_info
*vdd
;
961 if (!voltdm
|| IS_ERR(voltdm
)) {
962 pr_warning("%s: VDD specified does not exist!\n", __func__
);
966 vdd
= container_of(voltdm
, struct omap_vdd_info
, voltdm
);
968 vdd
->pmic_info
= pmic_info
;
974 * omap_voltage_get_dbgdir() - API to get pointer to the debugfs directory
975 * corresponding to a voltage domain.
977 * @voltdm: pointer to the VDD whose debug directory is required.
979 * This API returns pointer to the debugfs directory corresponding
980 * to the voltage domain. Should be used by drivers requiring to
981 * add any debug entry for a particular voltage domain. Returns NULL
984 struct dentry
*omap_voltage_get_dbgdir(struct voltagedomain
*voltdm
)
986 struct omap_vdd_info
*vdd
;
988 if (!voltdm
|| IS_ERR(voltdm
)) {
989 pr_warning("%s: VDD specified does not exist!\n", __func__
);
993 vdd
= container_of(voltdm
, struct omap_vdd_info
, voltdm
);
995 return vdd
->debug_dir
;
999 * omap_change_voltscale_method() - API to change the voltage scaling method.
1000 * @voltdm: pointer to the VDD whose voltage scaling method
1001 * has to be changed.
1002 * @voltscale_method: the method to be used for voltage scaling.
1004 * This API can be used by the board files to change the method of voltage
1005 * scaling between vpforceupdate and vcbypass. The parameter values are
1006 * defined in voltage.h
1008 void omap_change_voltscale_method(struct voltagedomain
*voltdm
,
1009 int voltscale_method
)
1011 struct omap_vdd_info
*vdd
;
1013 if (!voltdm
|| IS_ERR(voltdm
)) {
1014 pr_warning("%s: VDD specified does not exist!\n", __func__
);
1018 vdd
= container_of(voltdm
, struct omap_vdd_info
, voltdm
);
1020 switch (voltscale_method
) {
1021 case VOLTSCALE_VPFORCEUPDATE
:
1022 vdd
->volt_scale
= vp_forceupdate_scale_voltage
;
1024 case VOLTSCALE_VCBYPASS
:
1025 vdd
->volt_scale
= vc_bypass_scale_voltage
;
1028 pr_warning("%s: Trying to change the method of voltage scaling"
1029 "to an unsupported one!\n", __func__
);
1034 * omap_voltage_domain_lookup() - API to get the voltage domain pointer
1035 * @name: Name of the voltage domain
1037 * This API looks up in the global vdd_info struct for the
1038 * existence of voltage domain <name>. If it exists, the API returns
1039 * a pointer to the voltage domain structure corresponding to the
1040 * VDD<name>. Else retuns error pointer.
1042 struct voltagedomain
*omap_voltage_domain_lookup(char *name
)
1047 pr_err("%s: Voltage driver init not yet happened.Faulting!\n",
1049 return ERR_PTR(-EINVAL
);
1053 pr_err("%s: No name to get the votage domain!\n", __func__
);
1054 return ERR_PTR(-EINVAL
);
1057 for (i
= 0; i
< nr_scalable_vdd
; i
++) {
1058 if (!(strcmp(name
, vdd_info
[i
]->voltdm
.name
)))
1059 return &vdd_info
[i
]->voltdm
;
1062 return ERR_PTR(-EINVAL
);
1066 * omap_voltage_late_init() - Init the various voltage parameters
1068 * This API is to be called in the later stages of the
1069 * system boot to init the voltage controller and
1070 * voltage processors.
1072 int __init
omap_voltage_late_init(void)
1077 pr_err("%s: Voltage driver support not added\n",
1082 voltage_dir
= debugfs_create_dir("voltage", NULL
);
1083 if (IS_ERR(voltage_dir
))
1084 pr_err("%s: Unable to create voltage debugfs main dir\n",
1086 for (i
= 0; i
< nr_scalable_vdd
; i
++) {
1087 if (omap_vdd_data_configure(vdd_info
[i
]))
1089 omap_vc_init(vdd_info
[i
]);
1090 vp_init(vdd_info
[i
]);
1091 vdd_debugfs_init(vdd_info
[i
]);
1098 int __init
omap_voltage_early_init(s16 prm_mod
, s16 prm_irqst_ocp_mod
,
1099 struct omap_vdd_info
*omap_vdd_array
[],
1102 prm_mod_offs
= prm_mod
;
1103 prm_irqst_ocp_mod_offs
= prm_irqst_ocp_mod
;
1104 vdd_info
= omap_vdd_array
;
1105 nr_scalable_vdd
= omap_vdd_count
;