2011-03-22 05:29:13 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include <plat/common.h>
|
|
|
|
|
|
|
|
#include "voltage.h"
|
|
|
|
#include "vp.h"
|
|
|
|
#include "prm-regbits-34xx.h"
|
|
|
|
#include "prm-regbits-44xx.h"
|
|
|
|
#include "prm44xx.h"
|
|
|
|
|
|
|
|
static void vp_latch_vsel(struct voltagedomain *voltdm)
|
|
|
|
{
|
2011-04-05 06:25:07 +08:00
|
|
|
struct omap_vp_instance *vp = voltdm->vp;
|
2011-03-22 05:29:13 +08:00
|
|
|
u32 vpconfig;
|
|
|
|
unsigned long uvdc;
|
|
|
|
char vsel;
|
|
|
|
|
|
|
|
uvdc = omap_voltage_get_nom_volt(voltdm);
|
|
|
|
if (!uvdc) {
|
|
|
|
pr_warning("%s: unable to find current voltage for vdd_%s\n",
|
|
|
|
__func__, voltdm->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-31 02:01:10 +08:00
|
|
|
if (!voltdm->pmic || !voltdm->pmic->uv_to_vsel) {
|
2011-03-22 05:29:13 +08:00
|
|
|
pr_warning("%s: PMIC function to convert voltage in uV to"
|
|
|
|
" vsel not registered\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-31 02:01:10 +08:00
|
|
|
vsel = voltdm->pmic->uv_to_vsel(uvdc);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
2011-03-29 01:40:15 +08:00
|
|
|
vpconfig = voltdm->read(vp->vpconfig);
|
2011-04-05 06:25:07 +08:00
|
|
|
vpconfig &= ~(vp->common->vpconfig_initvoltage_mask |
|
|
|
|
vp->common->vpconfig_initvdd);
|
2011-04-05 07:02:28 +08:00
|
|
|
vpconfig |= vsel << __ffs(vp->common->vpconfig_initvoltage_mask);
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vpconfig, vp->vpconfig);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
/* Trigger initVDD value copy to voltage processor */
|
2011-04-05 06:25:07 +08:00
|
|
|
voltdm->write((vpconfig | vp->common->vpconfig_initvdd),
|
2011-03-29 01:40:15 +08:00
|
|
|
vp->vpconfig);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
/* Clear initVDD copy trigger bit */
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vpconfig, vp->vpconfig);
|
2011-03-22 05:29:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Generic voltage init functions */
|
|
|
|
void __init omap_vp_init(struct voltagedomain *voltdm)
|
|
|
|
{
|
2011-04-05 06:25:07 +08:00
|
|
|
struct omap_vp_instance *vp = voltdm->vp;
|
2011-03-22 05:29:13 +08:00
|
|
|
struct omap_vdd_info *vdd = voltdm->vdd;
|
|
|
|
u32 vp_val;
|
|
|
|
|
2011-03-29 01:40:15 +08:00
|
|
|
if (!voltdm->read || !voltdm->write) {
|
2011-03-22 05:29:13 +08:00
|
|
|
pr_err("%s: No read/write API for accessing vdd_%s regs\n",
|
|
|
|
__func__, voltdm->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vp_val = vdd->vp_rt_data.vpconfig_erroroffset |
|
|
|
|
(vdd->vp_rt_data.vpconfig_errorgain <<
|
2011-04-05 07:02:28 +08:00
|
|
|
__ffs(vp->common->vpconfig_errorgain_mask)) |
|
2011-04-05 06:25:07 +08:00
|
|
|
vp->common->vpconfig_timeouten;
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vp_val, vp->vpconfig);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
vp_val = ((vdd->vp_rt_data.vstepmin_smpswaittimemin <<
|
2011-04-05 07:02:28 +08:00
|
|
|
vp->common->vstepmin_smpswaittimemin_shift) |
|
|
|
|
(vdd->vp_rt_data.vstepmin_stepmin <<
|
|
|
|
vp->common->vstepmin_stepmin_shift));
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vp_val, vp->vstepmin);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
vp_val = ((vdd->vp_rt_data.vstepmax_smpswaittimemax <<
|
2011-04-05 07:02:28 +08:00
|
|
|
vp->common->vstepmax_smpswaittimemax_shift) |
|
|
|
|
(vdd->vp_rt_data.vstepmax_stepmax <<
|
|
|
|
vp->common->vstepmax_stepmax_shift));
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vp_val, vp->vstepmax);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
vp_val = ((vdd->vp_rt_data.vlimitto_vddmax <<
|
2011-04-05 07:02:28 +08:00
|
|
|
vp->common->vlimitto_vddmax_shift) |
|
|
|
|
(vdd->vp_rt_data.vlimitto_vddmin <<
|
|
|
|
vp->common->vlimitto_vddmin_shift) |
|
|
|
|
(vdd->vp_rt_data.vlimitto_timeout <<
|
|
|
|
vp->common->vlimitto_timeout_shift));
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vp_val, vp->vlimitto);
|
2011-03-22 05:29:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* VP force update method of voltage scaling */
|
|
|
|
int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
|
|
|
|
unsigned long target_volt)
|
|
|
|
{
|
2011-04-05 06:25:07 +08:00
|
|
|
struct omap_vp_instance *vp = voltdm->vp;
|
2011-03-22 05:29:13 +08:00
|
|
|
u32 vpconfig;
|
|
|
|
u8 target_vsel, current_vsel;
|
|
|
|
int ret, timeout = 0;
|
|
|
|
|
|
|
|
ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, ¤t_vsel);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear all pending TransactionDone interrupt/status. Typical latency
|
|
|
|
* is <3us
|
|
|
|
*/
|
|
|
|
while (timeout++ < VP_TRANXDONE_TIMEOUT) {
|
2011-04-05 06:25:07 +08:00
|
|
|
vp->common->ops->clear_txdone(vp->id);
|
|
|
|
if (!vp->common->ops->check_txdone(vp->id))
|
2011-03-22 05:29:13 +08:00
|
|
|
break;
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
if (timeout >= VP_TRANXDONE_TIMEOUT) {
|
|
|
|
pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
|
|
|
|
"Voltage change aborted", __func__, voltdm->name);
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure for VP-Force Update */
|
2011-03-29 01:40:15 +08:00
|
|
|
vpconfig = voltdm->read(vp->vpconfig);
|
2011-04-05 06:25:07 +08:00
|
|
|
vpconfig &= ~(vp->common->vpconfig_initvdd |
|
|
|
|
vp->common->vpconfig_forceupdate |
|
|
|
|
vp->common->vpconfig_initvoltage_mask);
|
2011-03-22 05:29:13 +08:00
|
|
|
vpconfig |= ((target_vsel <<
|
2011-04-05 07:02:28 +08:00
|
|
|
__ffs(vp->common->vpconfig_initvoltage_mask)));
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vpconfig, vp->vpconfig);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
/* Trigger initVDD value copy to voltage processor */
|
2011-04-05 06:25:07 +08:00
|
|
|
vpconfig |= vp->common->vpconfig_initvdd;
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vpconfig, vp->vpconfig);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
/* Force update of voltage */
|
2011-04-05 06:25:07 +08:00
|
|
|
vpconfig |= vp->common->vpconfig_forceupdate;
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vpconfig, vp->vpconfig);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for TransactionDone. Typical latency is <200us.
|
|
|
|
* Depends on SMPSWAITTIMEMIN/MAX and voltage change
|
|
|
|
*/
|
|
|
|
timeout = 0;
|
2011-04-05 06:25:07 +08:00
|
|
|
omap_test_timeout(vp->common->ops->check_txdone(vp->id),
|
2011-03-22 05:29:13 +08:00
|
|
|
VP_TRANXDONE_TIMEOUT, timeout);
|
|
|
|
if (timeout >= VP_TRANXDONE_TIMEOUT)
|
|
|
|
pr_err("%s: vdd_%s TRANXDONE timeout exceeded."
|
|
|
|
"TRANXDONE never got set after the voltage update\n",
|
|
|
|
__func__, voltdm->name);
|
|
|
|
|
|
|
|
omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable TransactionDone interrupt , clear all status, clear
|
|
|
|
* control registers
|
|
|
|
*/
|
|
|
|
timeout = 0;
|
|
|
|
while (timeout++ < VP_TRANXDONE_TIMEOUT) {
|
2011-04-05 06:25:07 +08:00
|
|
|
vp->common->ops->clear_txdone(vp->id);
|
|
|
|
if (!vp->common->ops->check_txdone(vp->id))
|
2011-03-22 05:29:13 +08:00
|
|
|
break;
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeout >= VP_TRANXDONE_TIMEOUT)
|
|
|
|
pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying"
|
|
|
|
"to clear the TRANXDONE status\n",
|
|
|
|
__func__, voltdm->name);
|
|
|
|
|
2011-03-29 01:40:15 +08:00
|
|
|
vpconfig = voltdm->read(vp->vpconfig);
|
2011-03-22 05:29:13 +08:00
|
|
|
/* Clear initVDD copy trigger bit */
|
2011-04-05 06:25:07 +08:00
|
|
|
vpconfig &= ~vp->common->vpconfig_initvdd;
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vpconfig, vp->vpconfig);
|
2011-03-22 05:29:13 +08:00
|
|
|
/* Clear force bit */
|
2011-04-05 06:25:07 +08:00
|
|
|
vpconfig &= ~vp->common->vpconfig_forceupdate;
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vpconfig, vp->vpconfig);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_vp_get_curr_volt() - API to get the current vp voltage.
|
|
|
|
* @voltdm: pointer to the VDD.
|
|
|
|
*
|
|
|
|
* This API returns the current voltage for the specified voltage processor
|
|
|
|
*/
|
|
|
|
unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
|
|
|
|
{
|
2011-04-05 06:25:07 +08:00
|
|
|
struct omap_vp_instance *vp = voltdm->vp;
|
2011-03-22 05:29:13 +08:00
|
|
|
u8 curr_vsel;
|
|
|
|
|
|
|
|
if (!voltdm || IS_ERR(voltdm)) {
|
|
|
|
pr_warning("%s: VDD specified does not exist!\n", __func__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-29 01:40:15 +08:00
|
|
|
if (!voltdm->read) {
|
2011-03-22 05:29:13 +08:00
|
|
|
pr_err("%s: No read API for reading vdd_%s regs\n",
|
|
|
|
__func__, voltdm->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-29 01:40:15 +08:00
|
|
|
curr_vsel = voltdm->read(vp->voltage);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
2011-03-31 02:01:10 +08:00
|
|
|
if (!voltdm->pmic || !voltdm->pmic->vsel_to_uv) {
|
2011-03-22 05:29:13 +08:00
|
|
|
pr_warning("%s: PMIC function to convert vsel to voltage"
|
|
|
|
"in uV not registerd\n", __func__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-31 02:01:10 +08:00
|
|
|
return voltdm->pmic->vsel_to_uv(curr_vsel);
|
2011-03-22 05:29:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_vp_enable() - API to enable a particular VP
|
|
|
|
* @voltdm: pointer to the VDD whose VP is to be enabled.
|
|
|
|
*
|
|
|
|
* This API enables a particular voltage processor. Needed by the smartreflex
|
|
|
|
* class drivers.
|
|
|
|
*/
|
|
|
|
void omap_vp_enable(struct voltagedomain *voltdm)
|
|
|
|
{
|
2011-04-05 06:25:07 +08:00
|
|
|
struct omap_vp_instance *vp;
|
2011-03-22 05:29:13 +08:00
|
|
|
u32 vpconfig;
|
|
|
|
|
|
|
|
if (!voltdm || IS_ERR(voltdm)) {
|
|
|
|
pr_warning("%s: VDD specified does not exist!\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-05 06:25:07 +08:00
|
|
|
vp = voltdm->vp;
|
2011-03-29 01:40:15 +08:00
|
|
|
if (!voltdm->read || !voltdm->write) {
|
2011-03-22 05:29:13 +08:00
|
|
|
pr_err("%s: No read/write API for accessing vdd_%s regs\n",
|
|
|
|
__func__, voltdm->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If VP is already enabled, do nothing. Return */
|
2011-04-05 06:25:07 +08:00
|
|
|
if (vp->enabled)
|
2011-03-22 05:29:13 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
vp_latch_vsel(voltdm);
|
|
|
|
|
|
|
|
/* Enable VP */
|
2011-03-29 01:40:15 +08:00
|
|
|
vpconfig = voltdm->read(vp->vpconfig);
|
2011-04-05 06:25:07 +08:00
|
|
|
vpconfig |= vp->common->vpconfig_vpenable;
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vpconfig, vp->vpconfig);
|
2011-04-05 06:25:07 +08:00
|
|
|
vp->enabled = true;
|
2011-03-22 05:29:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap_vp_disable() - API to disable a particular VP
|
|
|
|
* @voltdm: pointer to the VDD whose VP is to be disabled.
|
|
|
|
*
|
|
|
|
* This API disables a particular voltage processor. Needed by the smartreflex
|
|
|
|
* class drivers.
|
|
|
|
*/
|
|
|
|
void omap_vp_disable(struct voltagedomain *voltdm)
|
|
|
|
{
|
2011-04-05 06:25:07 +08:00
|
|
|
struct omap_vp_instance *vp;
|
2011-03-22 05:29:13 +08:00
|
|
|
u32 vpconfig;
|
|
|
|
int timeout;
|
|
|
|
|
|
|
|
if (!voltdm || IS_ERR(voltdm)) {
|
|
|
|
pr_warning("%s: VDD specified does not exist!\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-05 06:25:07 +08:00
|
|
|
vp = voltdm->vp;
|
2011-03-29 01:40:15 +08:00
|
|
|
if (!voltdm->read || !voltdm->write) {
|
2011-03-22 05:29:13 +08:00
|
|
|
pr_err("%s: No read/write API for accessing vdd_%s regs\n",
|
|
|
|
__func__, voltdm->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If VP is already disabled, do nothing. Return */
|
2011-04-05 06:25:07 +08:00
|
|
|
if (!vp->enabled) {
|
2011-03-22 05:29:13 +08:00
|
|
|
pr_warning("%s: Trying to disable VP for vdd_%s when"
|
|
|
|
"it is already disabled\n", __func__, voltdm->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable VP */
|
2011-03-29 01:40:15 +08:00
|
|
|
vpconfig = voltdm->read(vp->vpconfig);
|
2011-04-05 06:25:07 +08:00
|
|
|
vpconfig &= ~vp->common->vpconfig_vpenable;
|
2011-03-29 01:40:15 +08:00
|
|
|
voltdm->write(vpconfig, vp->vpconfig);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
|
|
|
|
*/
|
2011-03-29 01:40:15 +08:00
|
|
|
omap_test_timeout((voltdm->read(vp->vstatus)),
|
|
|
|
VP_IDLE_TIMEOUT, timeout);
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
if (timeout >= VP_IDLE_TIMEOUT)
|
|
|
|
pr_warning("%s: vdd_%s idle timedout\n",
|
|
|
|
__func__, voltdm->name);
|
|
|
|
|
2011-04-05 06:25:07 +08:00
|
|
|
vp->enabled = false;
|
2011-03-22 05:29:13 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|