blob: 297d094263aa5f00a9057e7200c62fc97ac6610e [file] [log] [blame]
Kevin Hilman01f48d32011-03-21 14:29:13 -07001#include <linux/kernel.h>
2#include <linux/init.h>
Kevin Hilman01f48d32011-03-21 14:29:13 -07003
4#include <plat/common.h>
5
6#include "voltage.h"
7#include "vp.h"
8#include "prm-regbits-34xx.h"
9#include "prm-regbits-44xx.h"
10#include "prm44xx.h"
11
Kevin Hilman01f48d32011-03-21 14:29:13 -070012static void vp_latch_vsel(struct voltagedomain *voltdm)
13{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070014 struct omap_vp_instance *vp = voltdm->vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -070015 u32 vpconfig;
16 unsigned long uvdc;
17 char vsel;
Kevin Hilman01f48d32011-03-21 14:29:13 -070018
19 uvdc = omap_voltage_get_nom_volt(voltdm);
20 if (!uvdc) {
21 pr_warning("%s: unable to find current voltage for vdd_%s\n",
22 __func__, voltdm->name);
23 return;
24 }
25
Kevin Hilmance8ebe02011-03-30 11:01:10 -070026 if (!voltdm->pmic || !voltdm->pmic->uv_to_vsel) {
Kevin Hilman01f48d32011-03-21 14:29:13 -070027 pr_warning("%s: PMIC function to convert voltage in uV to"
28 " vsel not registered\n", __func__);
29 return;
30 }
31
Kevin Hilmance8ebe02011-03-30 11:01:10 -070032 vsel = voltdm->pmic->uv_to_vsel(uvdc);
Kevin Hilman01f48d32011-03-21 14:29:13 -070033
Kevin Hilman4bcc4752011-03-28 10:40:15 -070034 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070035 vpconfig &= ~(vp->common->vpconfig_initvoltage_mask |
36 vp->common->vpconfig_initvdd);
Kevin Hilman0ec30412011-04-04 16:02:28 -070037 vpconfig |= vsel << __ffs(vp->common->vpconfig_initvoltage_mask);
Kevin Hilman4bcc4752011-03-28 10:40:15 -070038 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070039
40 /* Trigger initVDD value copy to voltage processor */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070041 voltdm->write((vpconfig | vp->common->vpconfig_initvdd),
Kevin Hilman4bcc4752011-03-28 10:40:15 -070042 vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070043
44 /* Clear initVDD copy trigger bit */
Kevin Hilman4bcc4752011-03-28 10:40:15 -070045 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070046}
47
48/* Generic voltage init functions */
49void __init omap_vp_init(struct voltagedomain *voltdm)
50{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070051 struct omap_vp_instance *vp = voltdm->vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -070052 struct omap_vdd_info *vdd = voltdm->vdd;
53 u32 vp_val;
54
Kevin Hilman4bcc4752011-03-28 10:40:15 -070055 if (!voltdm->read || !voltdm->write) {
Kevin Hilman01f48d32011-03-21 14:29:13 -070056 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
57 __func__, voltdm->name);
58 return;
59 }
60
61 vp_val = vdd->vp_rt_data.vpconfig_erroroffset |
62 (vdd->vp_rt_data.vpconfig_errorgain <<
Kevin Hilman0ec30412011-04-04 16:02:28 -070063 __ffs(vp->common->vpconfig_errorgain_mask)) |
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070064 vp->common->vpconfig_timeouten;
Kevin Hilman4bcc4752011-03-28 10:40:15 -070065 voltdm->write(vp_val, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070066
67 vp_val = ((vdd->vp_rt_data.vstepmin_smpswaittimemin <<
Kevin Hilman0ec30412011-04-04 16:02:28 -070068 vp->common->vstepmin_smpswaittimemin_shift) |
69 (vdd->vp_rt_data.vstepmin_stepmin <<
70 vp->common->vstepmin_stepmin_shift));
Kevin Hilman4bcc4752011-03-28 10:40:15 -070071 voltdm->write(vp_val, vp->vstepmin);
Kevin Hilman01f48d32011-03-21 14:29:13 -070072
73 vp_val = ((vdd->vp_rt_data.vstepmax_smpswaittimemax <<
Kevin Hilman0ec30412011-04-04 16:02:28 -070074 vp->common->vstepmax_smpswaittimemax_shift) |
75 (vdd->vp_rt_data.vstepmax_stepmax <<
76 vp->common->vstepmax_stepmax_shift));
Kevin Hilman4bcc4752011-03-28 10:40:15 -070077 voltdm->write(vp_val, vp->vstepmax);
Kevin Hilman01f48d32011-03-21 14:29:13 -070078
79 vp_val = ((vdd->vp_rt_data.vlimitto_vddmax <<
Kevin Hilman0ec30412011-04-04 16:02:28 -070080 vp->common->vlimitto_vddmax_shift) |
81 (vdd->vp_rt_data.vlimitto_vddmin <<
82 vp->common->vlimitto_vddmin_shift) |
83 (vdd->vp_rt_data.vlimitto_timeout <<
84 vp->common->vlimitto_timeout_shift));
Kevin Hilman4bcc4752011-03-28 10:40:15 -070085 voltdm->write(vp_val, vp->vlimitto);
Kevin Hilman01f48d32011-03-21 14:29:13 -070086}
87
88/* VP force update method of voltage scaling */
89int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
90 unsigned long target_volt)
91{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070092 struct omap_vp_instance *vp = voltdm->vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -070093 u32 vpconfig;
94 u8 target_vsel, current_vsel;
95 int ret, timeout = 0;
96
97 ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, &current_vsel);
98 if (ret)
99 return ret;
100
101 /*
102 * Clear all pending TransactionDone interrupt/status. Typical latency
103 * is <3us
104 */
105 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700106 vp->common->ops->clear_txdone(vp->id);
107 if (!vp->common->ops->check_txdone(vp->id))
Kevin Hilman01f48d32011-03-21 14:29:13 -0700108 break;
109 udelay(1);
110 }
111 if (timeout >= VP_TRANXDONE_TIMEOUT) {
112 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
113 "Voltage change aborted", __func__, voltdm->name);
114 return -ETIMEDOUT;
115 }
116
117 /* Configure for VP-Force Update */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700118 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700119 vpconfig &= ~(vp->common->vpconfig_initvdd |
120 vp->common->vpconfig_forceupdate |
121 vp->common->vpconfig_initvoltage_mask);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700122 vpconfig |= ((target_vsel <<
Kevin Hilman0ec30412011-04-04 16:02:28 -0700123 __ffs(vp->common->vpconfig_initvoltage_mask)));
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700124 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700125
126 /* Trigger initVDD value copy to voltage processor */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700127 vpconfig |= vp->common->vpconfig_initvdd;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700128 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700129
130 /* Force update of voltage */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700131 vpconfig |= vp->common->vpconfig_forceupdate;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700132 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700133
134 /*
135 * Wait for TransactionDone. Typical latency is <200us.
136 * Depends on SMPSWAITTIMEMIN/MAX and voltage change
137 */
138 timeout = 0;
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700139 omap_test_timeout(vp->common->ops->check_txdone(vp->id),
Kevin Hilman01f48d32011-03-21 14:29:13 -0700140 VP_TRANXDONE_TIMEOUT, timeout);
141 if (timeout >= VP_TRANXDONE_TIMEOUT)
142 pr_err("%s: vdd_%s TRANXDONE timeout exceeded."
143 "TRANXDONE never got set after the voltage update\n",
144 __func__, voltdm->name);
145
146 omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel);
147
148 /*
149 * Disable TransactionDone interrupt , clear all status, clear
150 * control registers
151 */
152 timeout = 0;
153 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700154 vp->common->ops->clear_txdone(vp->id);
155 if (!vp->common->ops->check_txdone(vp->id))
Kevin Hilman01f48d32011-03-21 14:29:13 -0700156 break;
157 udelay(1);
158 }
159
160 if (timeout >= VP_TRANXDONE_TIMEOUT)
161 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying"
162 "to clear the TRANXDONE status\n",
163 __func__, voltdm->name);
164
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700165 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700166 /* Clear initVDD copy trigger bit */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700167 vpconfig &= ~vp->common->vpconfig_initvdd;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700168 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700169 /* Clear force bit */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700170 vpconfig &= ~vp->common->vpconfig_forceupdate;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700171 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700172
173 return 0;
174}
175
176/**
177 * omap_vp_get_curr_volt() - API to get the current vp voltage.
178 * @voltdm: pointer to the VDD.
179 *
180 * This API returns the current voltage for the specified voltage processor
181 */
182unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
183{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700184 struct omap_vp_instance *vp = voltdm->vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700185 u8 curr_vsel;
186
187 if (!voltdm || IS_ERR(voltdm)) {
188 pr_warning("%s: VDD specified does not exist!\n", __func__);
189 return 0;
190 }
191
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700192 if (!voltdm->read) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700193 pr_err("%s: No read API for reading vdd_%s regs\n",
194 __func__, voltdm->name);
195 return 0;
196 }
197
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700198 curr_vsel = voltdm->read(vp->voltage);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700199
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700200 if (!voltdm->pmic || !voltdm->pmic->vsel_to_uv) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700201 pr_warning("%s: PMIC function to convert vsel to voltage"
202 "in uV not registerd\n", __func__);
203 return 0;
204 }
205
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700206 return voltdm->pmic->vsel_to_uv(curr_vsel);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700207}
208
209/**
210 * omap_vp_enable() - API to enable a particular VP
211 * @voltdm: pointer to the VDD whose VP is to be enabled.
212 *
213 * This API enables a particular voltage processor. Needed by the smartreflex
214 * class drivers.
215 */
216void omap_vp_enable(struct voltagedomain *voltdm)
217{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700218 struct omap_vp_instance *vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700219 u32 vpconfig;
220
221 if (!voltdm || IS_ERR(voltdm)) {
222 pr_warning("%s: VDD specified does not exist!\n", __func__);
223 return;
224 }
225
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700226 vp = voltdm->vp;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700227 if (!voltdm->read || !voltdm->write) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700228 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
229 __func__, voltdm->name);
230 return;
231 }
232
233 /* If VP is already enabled, do nothing. Return */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700234 if (vp->enabled)
Kevin Hilman01f48d32011-03-21 14:29:13 -0700235 return;
236
237 vp_latch_vsel(voltdm);
238
239 /* Enable VP */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700240 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700241 vpconfig |= vp->common->vpconfig_vpenable;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700242 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700243 vp->enabled = true;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700244}
245
246/**
247 * omap_vp_disable() - API to disable a particular VP
248 * @voltdm: pointer to the VDD whose VP is to be disabled.
249 *
250 * This API disables a particular voltage processor. Needed by the smartreflex
251 * class drivers.
252 */
253void omap_vp_disable(struct voltagedomain *voltdm)
254{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700255 struct omap_vp_instance *vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700256 u32 vpconfig;
257 int timeout;
258
259 if (!voltdm || IS_ERR(voltdm)) {
260 pr_warning("%s: VDD specified does not exist!\n", __func__);
261 return;
262 }
263
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700264 vp = voltdm->vp;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700265 if (!voltdm->read || !voltdm->write) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700266 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
267 __func__, voltdm->name);
268 return;
269 }
270
271 /* If VP is already disabled, do nothing. Return */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700272 if (!vp->enabled) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700273 pr_warning("%s: Trying to disable VP for vdd_%s when"
274 "it is already disabled\n", __func__, voltdm->name);
275 return;
276 }
277
278 /* Disable VP */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700279 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700280 vpconfig &= ~vp->common->vpconfig_vpenable;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700281 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700282
283 /*
284 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
285 */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700286 omap_test_timeout((voltdm->read(vp->vstatus)),
287 VP_IDLE_TIMEOUT, timeout);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700288
289 if (timeout >= VP_IDLE_TIMEOUT)
290 pr_warning("%s: vdd_%s idle timedout\n",
291 __func__, voltdm->name);
292
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700293 vp->enabled = false;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700294
295 return;
296}