1 #include <linux/kernel.h>
2 #include <linux/init.h>
4 #include <plat/common.h>
8 #include "prm-regbits-34xx.h"
9 #include "prm-regbits-44xx.h"
12 static void vp_latch_vsel(struct voltagedomain *voltdm)
14 struct omap_vp_instance *vp = voltdm->vp;
19 uvdc = omap_voltage_get_nom_volt(voltdm);
21 pr_warning("%s: unable to find current voltage for vdd_%s\n",
22 __func__, voltdm->name);
26 if (!voltdm->pmic || !voltdm->pmic->uv_to_vsel) {
27 pr_warning("%s: PMIC function to convert voltage in uV to"
28 " vsel not registered\n", __func__);
32 vsel = voltdm->pmic->uv_to_vsel(uvdc);
34 vpconfig = voltdm->read(vp->vpconfig);
35 vpconfig &= ~(vp->common->vpconfig_initvoltage_mask |
36 vp->common->vpconfig_initvdd);
37 vpconfig |= vsel << __ffs(vp->common->vpconfig_initvoltage_mask);
38 voltdm->write(vpconfig, vp->vpconfig);
40 /* Trigger initVDD value copy to voltage processor */
41 voltdm->write((vpconfig | vp->common->vpconfig_initvdd),
44 /* Clear initVDD copy trigger bit */
45 voltdm->write(vpconfig, vp->vpconfig);
48 /* Generic voltage init functions */
49 void __init omap_vp_init(struct voltagedomain *voltdm)
51 struct omap_vp_instance *vp = voltdm->vp;
52 struct omap_vdd_info *vdd = voltdm->vdd;
53 u32 vp_val, sys_clk_rate, timeout_val, waittime;
55 if (!voltdm->read || !voltdm->write) {
56 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
57 __func__, voltdm->name);
63 /* Divide to avoid overflow */
64 sys_clk_rate = voltdm->sys_clk.rate / 1000;
66 vdd->vp_rt_data.vpconfig_erroroffset =
67 (voltdm->pmic->vp_erroroffset <<
68 __ffs(voltdm->vp->common->vpconfig_erroroffset_mask));
70 timeout_val = (sys_clk_rate * voltdm->pmic->vp_timeout_us) / 1000;
71 vdd->vp_rt_data.vlimitto_timeout = timeout_val;
72 vdd->vp_rt_data.vlimitto_vddmin = voltdm->pmic->vp_vddmin;
73 vdd->vp_rt_data.vlimitto_vddmax = voltdm->pmic->vp_vddmax;
75 waittime = ((voltdm->pmic->step_size / voltdm->pmic->slew_rate) *
77 vdd->vp_rt_data.vstepmin_smpswaittimemin = waittime;
78 vdd->vp_rt_data.vstepmax_smpswaittimemax = waittime;
79 vdd->vp_rt_data.vstepmin_stepmin = voltdm->pmic->vp_vstepmin;
80 vdd->vp_rt_data.vstepmax_stepmax = voltdm->pmic->vp_vstepmax;
82 vp_val = vdd->vp_rt_data.vpconfig_erroroffset |
83 (vdd->vp_rt_data.vpconfig_errorgain <<
84 __ffs(vp->common->vpconfig_errorgain_mask)) |
85 vp->common->vpconfig_timeouten;
86 voltdm->write(vp_val, vp->vpconfig);
88 vp_val = ((vdd->vp_rt_data.vstepmin_smpswaittimemin <<
89 vp->common->vstepmin_smpswaittimemin_shift) |
90 (vdd->vp_rt_data.vstepmin_stepmin <<
91 vp->common->vstepmin_stepmin_shift));
92 voltdm->write(vp_val, vp->vstepmin);
94 vp_val = ((vdd->vp_rt_data.vstepmax_smpswaittimemax <<
95 vp->common->vstepmax_smpswaittimemax_shift) |
96 (vdd->vp_rt_data.vstepmax_stepmax <<
97 vp->common->vstepmax_stepmax_shift));
98 voltdm->write(vp_val, vp->vstepmax);
100 vp_val = ((vdd->vp_rt_data.vlimitto_vddmax <<
101 vp->common->vlimitto_vddmax_shift) |
102 (vdd->vp_rt_data.vlimitto_vddmin <<
103 vp->common->vlimitto_vddmin_shift) |
104 (vdd->vp_rt_data.vlimitto_timeout <<
105 vp->common->vlimitto_timeout_shift));
106 voltdm->write(vp_val, vp->vlimitto);
109 /* VP force update method of voltage scaling */
110 int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
111 unsigned long target_volt)
113 struct omap_vp_instance *vp = voltdm->vp;
115 u8 target_vsel, current_vsel;
116 int ret, timeout = 0;
118 ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, ¤t_vsel);
123 * Clear all pending TransactionDone interrupt/status. Typical latency
126 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
127 vp->common->ops->clear_txdone(vp->id);
128 if (!vp->common->ops->check_txdone(vp->id))
132 if (timeout >= VP_TRANXDONE_TIMEOUT) {
133 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
134 "Voltage change aborted", __func__, voltdm->name);
138 /* Configure for VP-Force Update */
139 vpconfig = voltdm->read(vp->vpconfig);
140 vpconfig &= ~(vp->common->vpconfig_initvdd |
141 vp->common->vpconfig_forceupdate |
142 vp->common->vpconfig_initvoltage_mask);
143 vpconfig |= ((target_vsel <<
144 __ffs(vp->common->vpconfig_initvoltage_mask)));
145 voltdm->write(vpconfig, vp->vpconfig);
147 /* Trigger initVDD value copy to voltage processor */
148 vpconfig |= vp->common->vpconfig_initvdd;
149 voltdm->write(vpconfig, vp->vpconfig);
151 /* Force update of voltage */
152 vpconfig |= vp->common->vpconfig_forceupdate;
153 voltdm->write(vpconfig, vp->vpconfig);
156 * Wait for TransactionDone. Typical latency is <200us.
157 * Depends on SMPSWAITTIMEMIN/MAX and voltage change
160 omap_test_timeout(vp->common->ops->check_txdone(vp->id),
161 VP_TRANXDONE_TIMEOUT, timeout);
162 if (timeout >= VP_TRANXDONE_TIMEOUT)
163 pr_err("%s: vdd_%s TRANXDONE timeout exceeded."
164 "TRANXDONE never got set after the voltage update\n",
165 __func__, voltdm->name);
167 omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel);
170 * Disable TransactionDone interrupt , clear all status, clear
174 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
175 vp->common->ops->clear_txdone(vp->id);
176 if (!vp->common->ops->check_txdone(vp->id))
181 if (timeout >= VP_TRANXDONE_TIMEOUT)
182 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying"
183 "to clear the TRANXDONE status\n",
184 __func__, voltdm->name);
186 vpconfig = voltdm->read(vp->vpconfig);
187 /* Clear initVDD copy trigger bit */
188 vpconfig &= ~vp->common->vpconfig_initvdd;
189 voltdm->write(vpconfig, vp->vpconfig);
190 /* Clear force bit */
191 vpconfig &= ~vp->common->vpconfig_forceupdate;
192 voltdm->write(vpconfig, vp->vpconfig);
198 * omap_vp_get_curr_volt() - API to get the current vp voltage.
199 * @voltdm: pointer to the VDD.
201 * This API returns the current voltage for the specified voltage processor
203 unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
205 struct omap_vp_instance *vp = voltdm->vp;
208 if (!voltdm || IS_ERR(voltdm)) {
209 pr_warning("%s: VDD specified does not exist!\n", __func__);
214 pr_err("%s: No read API for reading vdd_%s regs\n",
215 __func__, voltdm->name);
219 curr_vsel = voltdm->read(vp->voltage);
221 if (!voltdm->pmic || !voltdm->pmic->vsel_to_uv) {
222 pr_warning("%s: PMIC function to convert vsel to voltage"
223 "in uV not registerd\n", __func__);
227 return voltdm->pmic->vsel_to_uv(curr_vsel);
231 * omap_vp_enable() - API to enable a particular VP
232 * @voltdm: pointer to the VDD whose VP is to be enabled.
234 * This API enables a particular voltage processor. Needed by the smartreflex
237 void omap_vp_enable(struct voltagedomain *voltdm)
239 struct omap_vp_instance *vp;
242 if (!voltdm || IS_ERR(voltdm)) {
243 pr_warning("%s: VDD specified does not exist!\n", __func__);
248 if (!voltdm->read || !voltdm->write) {
249 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
250 __func__, voltdm->name);
254 /* If VP is already enabled, do nothing. Return */
258 vp_latch_vsel(voltdm);
261 vpconfig = voltdm->read(vp->vpconfig);
262 vpconfig |= vp->common->vpconfig_vpenable;
263 voltdm->write(vpconfig, vp->vpconfig);
268 * omap_vp_disable() - API to disable a particular VP
269 * @voltdm: pointer to the VDD whose VP is to be disabled.
271 * This API disables a particular voltage processor. Needed by the smartreflex
274 void omap_vp_disable(struct voltagedomain *voltdm)
276 struct omap_vp_instance *vp;
280 if (!voltdm || IS_ERR(voltdm)) {
281 pr_warning("%s: VDD specified does not exist!\n", __func__);
286 if (!voltdm->read || !voltdm->write) {
287 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
288 __func__, voltdm->name);
292 /* If VP is already disabled, do nothing. Return */
294 pr_warning("%s: Trying to disable VP for vdd_%s when"
295 "it is already disabled\n", __func__, voltdm->name);
300 vpconfig = voltdm->read(vp->vpconfig);
301 vpconfig &= ~vp->common->vpconfig_vpenable;
302 voltdm->write(vpconfig, vp->vpconfig);
305 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
307 omap_test_timeout((voltdm->read(vp->vstatus)),
308 VP_IDLE_TIMEOUT, timeout);
310 if (timeout >= VP_IDLE_TIMEOUT)
311 pr_warning("%s: vdd_%s idle timedout\n",
312 __func__, voltdm->name);