0001
0002 #include <linux/kernel.h>
0003 #include <linux/init.h>
0004
0005 #include "common.h"
0006
0007 #include "voltage.h"
0008 #include "vp.h"
0009 #include "prm-regbits-34xx.h"
0010 #include "prm-regbits-44xx.h"
0011 #include "prm44xx.h"
0012
0013 static u32 _vp_set_init_voltage(struct voltagedomain *voltdm, u32 volt)
0014 {
0015 struct omap_vp_instance *vp = voltdm->vp;
0016 u32 vpconfig;
0017 char vsel;
0018
0019 vsel = voltdm->pmic->uv_to_vsel(volt);
0020
0021 vpconfig = voltdm->read(vp->vpconfig);
0022 vpconfig &= ~(vp->common->vpconfig_initvoltage_mask |
0023 vp->common->vpconfig_forceupdate |
0024 vp->common->vpconfig_initvdd);
0025 vpconfig |= vsel << __ffs(vp->common->vpconfig_initvoltage_mask);
0026 voltdm->write(vpconfig, vp->vpconfig);
0027
0028
0029 voltdm->write((vpconfig | vp->common->vpconfig_initvdd),
0030 vp->vpconfig);
0031
0032
0033 voltdm->write(vpconfig, vp->vpconfig);
0034
0035 return vpconfig;
0036 }
0037
0038
0039 void __init omap_vp_init(struct voltagedomain *voltdm)
0040 {
0041 struct omap_vp_instance *vp = voltdm->vp;
0042 u32 val, sys_clk_rate, timeout, waittime;
0043 u32 vddmin, vddmax, vstepmin, vstepmax;
0044
0045 if (!voltdm->pmic || !voltdm->pmic->uv_to_vsel) {
0046 pr_err("%s: No PMIC info for vdd_%s\n", __func__, voltdm->name);
0047 return;
0048 }
0049
0050 if (!voltdm->read || !voltdm->write) {
0051 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
0052 __func__, voltdm->name);
0053 return;
0054 }
0055
0056 vp->enabled = false;
0057
0058
0059 sys_clk_rate = voltdm->sys_clk.rate / 1000;
0060
0061 timeout = (sys_clk_rate * voltdm->pmic->vp_timeout_us) / 1000;
0062 vddmin = max(voltdm->vp_param->vddmin, voltdm->pmic->vddmin);
0063 vddmax = min(voltdm->vp_param->vddmax, voltdm->pmic->vddmax);
0064 vddmin = voltdm->pmic->uv_to_vsel(vddmin);
0065 vddmax = voltdm->pmic->uv_to_vsel(vddmax);
0066
0067 waittime = DIV_ROUND_UP(voltdm->pmic->step_size * sys_clk_rate,
0068 1000 * voltdm->pmic->slew_rate);
0069 vstepmin = voltdm->pmic->vp_vstepmin;
0070 vstepmax = voltdm->pmic->vp_vstepmax;
0071
0072
0073
0074
0075
0076 val = (voltdm->pmic->vp_erroroffset <<
0077 __ffs(voltdm->vp->common->vpconfig_erroroffset_mask)) |
0078 vp->common->vpconfig_timeouten;
0079 voltdm->write(val, vp->vpconfig);
0080
0081
0082 val = (waittime << vp->common->vstepmin_smpswaittimemin_shift) |
0083 (vstepmin << vp->common->vstepmin_stepmin_shift);
0084 voltdm->write(val, vp->vstepmin);
0085
0086
0087 val = (vstepmax << vp->common->vstepmax_stepmax_shift) |
0088 (waittime << vp->common->vstepmax_smpswaittimemax_shift);
0089 voltdm->write(val, vp->vstepmax);
0090
0091
0092 val = (vddmax << vp->common->vlimitto_vddmax_shift) |
0093 (vddmin << vp->common->vlimitto_vddmin_shift) |
0094 (timeout << vp->common->vlimitto_timeout_shift);
0095 voltdm->write(val, vp->vlimitto);
0096 }
0097
0098 int omap_vp_update_errorgain(struct voltagedomain *voltdm,
0099 unsigned long target_volt)
0100 {
0101 struct omap_volt_data *volt_data;
0102
0103 if (!voltdm->vp)
0104 return -EINVAL;
0105
0106
0107 volt_data = omap_voltage_get_voltdata(voltdm, target_volt);
0108 if (IS_ERR(volt_data))
0109 return -EINVAL;
0110
0111
0112 voltdm->rmw(voltdm->vp->common->vpconfig_errorgain_mask,
0113 volt_data->vp_errgain <<
0114 __ffs(voltdm->vp->common->vpconfig_errorgain_mask),
0115 voltdm->vp->vpconfig);
0116
0117 return 0;
0118 }
0119
0120
0121 int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
0122 unsigned long target_volt)
0123 {
0124 struct omap_vp_instance *vp = voltdm->vp;
0125 u32 vpconfig;
0126 u8 target_vsel, current_vsel;
0127 int ret, timeout = 0;
0128
0129 ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, ¤t_vsel);
0130 if (ret)
0131 return ret;
0132
0133
0134
0135
0136
0137 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
0138 vp->common->ops->clear_txdone(vp->id);
0139 if (!vp->common->ops->check_txdone(vp->id))
0140 break;
0141 udelay(1);
0142 }
0143 if (timeout >= VP_TRANXDONE_TIMEOUT) {
0144 pr_warn("%s: vdd_%s TRANXDONE timeout exceeded. Voltage change aborted\n",
0145 __func__, voltdm->name);
0146 return -ETIMEDOUT;
0147 }
0148
0149 vpconfig = _vp_set_init_voltage(voltdm, target_volt);
0150
0151
0152 voltdm->write(vpconfig | vp->common->vpconfig_forceupdate,
0153 voltdm->vp->vpconfig);
0154
0155
0156
0157
0158
0159 timeout = 0;
0160 omap_test_timeout(vp->common->ops->check_txdone(vp->id),
0161 VP_TRANXDONE_TIMEOUT, timeout);
0162 if (timeout >= VP_TRANXDONE_TIMEOUT)
0163 pr_err("%s: vdd_%s TRANXDONE timeout exceeded. TRANXDONE never got set after the voltage update\n",
0164 __func__, voltdm->name);
0165
0166 omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel);
0167
0168
0169
0170
0171
0172 timeout = 0;
0173 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
0174 vp->common->ops->clear_txdone(vp->id);
0175 if (!vp->common->ops->check_txdone(vp->id))
0176 break;
0177 udelay(1);
0178 }
0179
0180 if (timeout >= VP_TRANXDONE_TIMEOUT)
0181 pr_warn("%s: vdd_%s TRANXDONE timeout exceeded while trying to clear the TRANXDONE status\n",
0182 __func__, voltdm->name);
0183
0184
0185 voltdm->write(vpconfig, vp->vpconfig);
0186
0187 return 0;
0188 }
0189
0190
0191
0192
0193
0194
0195
0196
0197 void omap_vp_enable(struct voltagedomain *voltdm)
0198 {
0199 struct omap_vp_instance *vp;
0200 u32 vpconfig, volt;
0201
0202 if (!voltdm || IS_ERR(voltdm)) {
0203 pr_warn("%s: VDD specified does not exist!\n", __func__);
0204 return;
0205 }
0206
0207 vp = voltdm->vp;
0208 if (!voltdm->read || !voltdm->write) {
0209 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
0210 __func__, voltdm->name);
0211 return;
0212 }
0213
0214
0215 if (vp->enabled)
0216 return;
0217
0218 volt = voltdm_get_voltage(voltdm);
0219 if (!volt) {
0220 pr_warn("%s: unable to find current voltage for %s\n",
0221 __func__, voltdm->name);
0222 return;
0223 }
0224
0225 vpconfig = _vp_set_init_voltage(voltdm, volt);
0226
0227
0228 vpconfig |= vp->common->vpconfig_vpenable;
0229 voltdm->write(vpconfig, vp->vpconfig);
0230
0231 vp->enabled = true;
0232 }
0233
0234
0235
0236
0237
0238
0239
0240
0241 void omap_vp_disable(struct voltagedomain *voltdm)
0242 {
0243 struct omap_vp_instance *vp;
0244 u32 vpconfig;
0245 int timeout;
0246
0247 if (!voltdm || IS_ERR(voltdm)) {
0248 pr_warn("%s: VDD specified does not exist!\n", __func__);
0249 return;
0250 }
0251
0252 vp = voltdm->vp;
0253 if (!voltdm->read || !voltdm->write) {
0254 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
0255 __func__, voltdm->name);
0256 return;
0257 }
0258
0259
0260 if (!vp->enabled) {
0261 pr_warn("%s: Trying to disable VP for vdd_%s when it is already disabled\n",
0262 __func__, voltdm->name);
0263 return;
0264 }
0265
0266
0267 vpconfig = voltdm->read(vp->vpconfig);
0268 vpconfig &= ~vp->common->vpconfig_vpenable;
0269 voltdm->write(vpconfig, vp->vpconfig);
0270
0271
0272
0273
0274 omap_test_timeout((voltdm->read(vp->vstatus)),
0275 VP_IDLE_TIMEOUT, timeout);
0276
0277 if (timeout >= VP_IDLE_TIMEOUT)
0278 pr_warn("%s: vdd_%s idle timedout\n", __func__, voltdm->name);
0279
0280 vp->enabled = false;
0281
0282 return;
0283 }