blob: c9a315f9d3d8e99a130ce3fe74670d92fa3c9d77 [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);
37 vpconfig |= vsel << vp->common->vpconfig_initvoltage_shift;
Kevin Hilman01f48d32011-03-21 14:29:13 -070038
Kevin Hilman4bcc4752011-03-28 10:40:15 -070039 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070040
41 /* Trigger initVDD value copy to voltage processor */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070042 voltdm->write((vpconfig | vp->common->vpconfig_initvdd),
Kevin Hilman4bcc4752011-03-28 10:40:15 -070043 vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070044
45 /* Clear initVDD copy trigger bit */
Kevin Hilman4bcc4752011-03-28 10:40:15 -070046 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070047}
48
49/* Generic voltage init functions */
50void __init omap_vp_init(struct voltagedomain *voltdm)
51{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070052 struct omap_vp_instance *vp = voltdm->vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -070053 struct omap_vdd_info *vdd = voltdm->vdd;
54 u32 vp_val;
55
Kevin Hilman4bcc4752011-03-28 10:40:15 -070056 if (!voltdm->read || !voltdm->write) {
Kevin Hilman01f48d32011-03-21 14:29:13 -070057 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
58 __func__, voltdm->name);
59 return;
60 }
61
62 vp_val = vdd->vp_rt_data.vpconfig_erroroffset |
63 (vdd->vp_rt_data.vpconfig_errorgain <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070064 vp->common->vpconfig_errorgain_shift) |
65 vp->common->vpconfig_timeouten;
Kevin Hilman4bcc4752011-03-28 10:40:15 -070066 voltdm->write(vp_val, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070067
68 vp_val = ((vdd->vp_rt_data.vstepmin_smpswaittimemin <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070069 vp->common->vstepmin_smpswaittimemin_shift) |
Kevin Hilman01f48d32011-03-21 14:29:13 -070070 (vdd->vp_rt_data.vstepmin_stepmin <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070071 vp->common->vstepmin_stepmin_shift));
Kevin Hilman4bcc4752011-03-28 10:40:15 -070072 voltdm->write(vp_val, vp->vstepmin);
Kevin Hilman01f48d32011-03-21 14:29:13 -070073
74 vp_val = ((vdd->vp_rt_data.vstepmax_smpswaittimemax <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070075 vp->common->vstepmax_smpswaittimemax_shift) |
Kevin Hilman01f48d32011-03-21 14:29:13 -070076 (vdd->vp_rt_data.vstepmax_stepmax <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070077 vp->common->vstepmax_stepmax_shift));
Kevin Hilman4bcc4752011-03-28 10:40:15 -070078 voltdm->write(vp_val, vp->vstepmax);
Kevin Hilman01f48d32011-03-21 14:29:13 -070079
80 vp_val = ((vdd->vp_rt_data.vlimitto_vddmax <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070081 vp->common->vlimitto_vddmax_shift) |
Kevin Hilman01f48d32011-03-21 14:29:13 -070082 (vdd->vp_rt_data.vlimitto_vddmin <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070083 vp->common->vlimitto_vddmin_shift) |
Kevin Hilman01f48d32011-03-21 14:29:13 -070084 (vdd->vp_rt_data.vlimitto_timeout <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070085 vp->common->vlimitto_timeout_shift));
Kevin Hilman4bcc4752011-03-28 10:40:15 -070086 voltdm->write(vp_val, vp->vlimitto);
Kevin Hilman01f48d32011-03-21 14:29:13 -070087}
88
89/* VP force update method of voltage scaling */
90int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
91 unsigned long target_volt)
92{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070093 struct omap_vp_instance *vp = voltdm->vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -070094 u32 vpconfig;
95 u8 target_vsel, current_vsel;
96 int ret, timeout = 0;
97
98 ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, &current_vsel);
99 if (ret)
100 return ret;
101
102 /*
103 * Clear all pending TransactionDone interrupt/status. Typical latency
104 * is <3us
105 */
106 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700107 vp->common->ops->clear_txdone(vp->id);
108 if (!vp->common->ops->check_txdone(vp->id))
Kevin Hilman01f48d32011-03-21 14:29:13 -0700109 break;
110 udelay(1);
111 }
112 if (timeout >= VP_TRANXDONE_TIMEOUT) {
113 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
114 "Voltage change aborted", __func__, voltdm->name);
115 return -ETIMEDOUT;
116 }
117
118 /* Configure for VP-Force Update */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700119 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700120 vpconfig &= ~(vp->common->vpconfig_initvdd |
121 vp->common->vpconfig_forceupdate |
122 vp->common->vpconfig_initvoltage_mask);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700123 vpconfig |= ((target_vsel <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700124 vp->common->vpconfig_initvoltage_shift));
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700125 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700126
127 /* Trigger initVDD value copy to voltage processor */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700128 vpconfig |= vp->common->vpconfig_initvdd;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700129 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700130
131 /* Force update of voltage */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700132 vpconfig |= vp->common->vpconfig_forceupdate;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700133 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700134
135 /*
136 * Wait for TransactionDone. Typical latency is <200us.
137 * Depends on SMPSWAITTIMEMIN/MAX and voltage change
138 */
139 timeout = 0;
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700140 omap_test_timeout(vp->common->ops->check_txdone(vp->id),
Kevin Hilman01f48d32011-03-21 14:29:13 -0700141 VP_TRANXDONE_TIMEOUT, timeout);
142 if (timeout >= VP_TRANXDONE_TIMEOUT)
143 pr_err("%s: vdd_%s TRANXDONE timeout exceeded."
144 "TRANXDONE never got set after the voltage update\n",
145 __func__, voltdm->name);
146
147 omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel);
148
149 /*
150 * Disable TransactionDone interrupt , clear all status, clear
151 * control registers
152 */
153 timeout = 0;
154 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700155 vp->common->ops->clear_txdone(vp->id);
156 if (!vp->common->ops->check_txdone(vp->id))
Kevin Hilman01f48d32011-03-21 14:29:13 -0700157 break;
158 udelay(1);
159 }
160
161 if (timeout >= VP_TRANXDONE_TIMEOUT)
162 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying"
163 "to clear the TRANXDONE status\n",
164 __func__, voltdm->name);
165
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700166 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700167 /* Clear initVDD copy trigger bit */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700168 vpconfig &= ~vp->common->vpconfig_initvdd;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700169 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700170 /* Clear force bit */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700171 vpconfig &= ~vp->common->vpconfig_forceupdate;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700172 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700173
174 return 0;
175}
176
177/**
178 * omap_vp_get_curr_volt() - API to get the current vp voltage.
179 * @voltdm: pointer to the VDD.
180 *
181 * This API returns the current voltage for the specified voltage processor
182 */
183unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
184{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700185 struct omap_vp_instance *vp = voltdm->vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700186 u8 curr_vsel;
187
188 if (!voltdm || IS_ERR(voltdm)) {
189 pr_warning("%s: VDD specified does not exist!\n", __func__);
190 return 0;
191 }
192
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700193 if (!voltdm->read) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700194 pr_err("%s: No read API for reading vdd_%s regs\n",
195 __func__, voltdm->name);
196 return 0;
197 }
198
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700199 curr_vsel = voltdm->read(vp->voltage);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700200
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700201 if (!voltdm->pmic || !voltdm->pmic->vsel_to_uv) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700202 pr_warning("%s: PMIC function to convert vsel to voltage"
203 "in uV not registerd\n", __func__);
204 return 0;
205 }
206
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700207 return voltdm->pmic->vsel_to_uv(curr_vsel);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700208}
209
210/**
211 * omap_vp_enable() - API to enable a particular VP
212 * @voltdm: pointer to the VDD whose VP is to be enabled.
213 *
214 * This API enables a particular voltage processor. Needed by the smartreflex
215 * class drivers.
216 */
217void omap_vp_enable(struct voltagedomain *voltdm)
218{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700219 struct omap_vp_instance *vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700220 u32 vpconfig;
221
222 if (!voltdm || IS_ERR(voltdm)) {
223 pr_warning("%s: VDD specified does not exist!\n", __func__);
224 return;
225 }
226
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700227 vp = voltdm->vp;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700228 if (!voltdm->read || !voltdm->write) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700229 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
230 __func__, voltdm->name);
231 return;
232 }
233
234 /* If VP is already enabled, do nothing. Return */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700235 if (vp->enabled)
Kevin Hilman01f48d32011-03-21 14:29:13 -0700236 return;
237
238 vp_latch_vsel(voltdm);
239
240 /* Enable VP */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700241 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700242 vpconfig |= vp->common->vpconfig_vpenable;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700243 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700244 vp->enabled = true;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700245}
246
247/**
248 * omap_vp_disable() - API to disable a particular VP
249 * @voltdm: pointer to the VDD whose VP is to be disabled.
250 *
251 * This API disables a particular voltage processor. Needed by the smartreflex
252 * class drivers.
253 */
254void omap_vp_disable(struct voltagedomain *voltdm)
255{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700256 struct omap_vp_instance *vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700257 u32 vpconfig;
258 int timeout;
259
260 if (!voltdm || IS_ERR(voltdm)) {
261 pr_warning("%s: VDD specified does not exist!\n", __func__);
262 return;
263 }
264
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700265 vp = voltdm->vp;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700266 if (!voltdm->read || !voltdm->write) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700267 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
268 __func__, voltdm->name);
269 return;
270 }
271
272 /* If VP is already disabled, do nothing. Return */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700273 if (!vp->enabled) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700274 pr_warning("%s: Trying to disable VP for vdd_%s when"
275 "it is already disabled\n", __func__, voltdm->name);
276 return;
277 }
278
279 /* Disable VP */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700280 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700281 vpconfig &= ~vp->common->vpconfig_vpenable;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700282 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700283
284 /*
285 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
286 */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700287 omap_test_timeout((voltdm->read(vp->vstatus)),
288 VP_IDLE_TIMEOUT, timeout);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700289
290 if (timeout >= VP_IDLE_TIMEOUT)
291 pr_warning("%s: vdd_%s idle timedout\n",
292 __func__, voltdm->name);
293
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700294 vp->enabled = false;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700295
296 return;
297}