blob: a3afcbe741e3aa3711a5bf6dcf430ae6fab4387a [file] [log] [blame]
Kevin Hilman01f48d32011-03-21 14:29:13 -07001#include <linux/kernel.h>
2#include <linux/init.h>
3#include <linux/debugfs.h>
4
5#include <plat/common.h>
6
7#include "voltage.h"
8#include "vp.h"
9#include "prm-regbits-34xx.h"
10#include "prm-regbits-44xx.h"
11#include "prm44xx.h"
12
13static void __init vp_debugfs_init(struct voltagedomain *voltdm);
14
15static void vp_latch_vsel(struct voltagedomain *voltdm)
16{
17 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
18 u32 vpconfig;
19 unsigned long uvdc;
20 char vsel;
Kevin Hilman01f48d32011-03-21 14:29:13 -070021
22 uvdc = omap_voltage_get_nom_volt(voltdm);
23 if (!uvdc) {
24 pr_warning("%s: unable to find current voltage for vdd_%s\n",
25 __func__, voltdm->name);
26 return;
27 }
28
Kevin Hilmance8ebe02011-03-30 11:01:10 -070029 if (!voltdm->pmic || !voltdm->pmic->uv_to_vsel) {
Kevin Hilman01f48d32011-03-21 14:29:13 -070030 pr_warning("%s: PMIC function to convert voltage in uV to"
31 " vsel not registered\n", __func__);
32 return;
33 }
34
Kevin Hilmance8ebe02011-03-30 11:01:10 -070035 vsel = voltdm->pmic->uv_to_vsel(uvdc);
Kevin Hilman01f48d32011-03-21 14:29:13 -070036
Kevin Hilman4bcc4752011-03-28 10:40:15 -070037 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070038 vpconfig &= ~(vp->vp_common->vpconfig_initvoltage_mask |
39 vp->vp_common->vpconfig_initvdd);
40 vpconfig |= vsel << vp->vp_common->vpconfig_initvoltage_shift;
41
Kevin Hilman4bcc4752011-03-28 10:40:15 -070042 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070043
44 /* Trigger initVDD value copy to voltage processor */
Kevin Hilman4bcc4752011-03-28 10:40:15 -070045 voltdm->write((vpconfig | vp->vp_common->vpconfig_initvdd),
46 vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070047
48 /* Clear initVDD copy trigger bit */
Kevin Hilman4bcc4752011-03-28 10:40:15 -070049 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070050}
51
52/* Generic voltage init functions */
53void __init omap_vp_init(struct voltagedomain *voltdm)
54{
55 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
56 struct omap_vdd_info *vdd = voltdm->vdd;
57 u32 vp_val;
58
Kevin Hilman4bcc4752011-03-28 10:40:15 -070059 if (!voltdm->read || !voltdm->write) {
Kevin Hilman01f48d32011-03-21 14:29:13 -070060 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
61 __func__, voltdm->name);
62 return;
63 }
64
65 vp_val = vdd->vp_rt_data.vpconfig_erroroffset |
66 (vdd->vp_rt_data.vpconfig_errorgain <<
67 vp->vp_common->vpconfig_errorgain_shift) |
68 vp->vp_common->vpconfig_timeouten;
Kevin Hilman4bcc4752011-03-28 10:40:15 -070069 voltdm->write(vp_val, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -070070
71 vp_val = ((vdd->vp_rt_data.vstepmin_smpswaittimemin <<
72 vp->vp_common->vstepmin_smpswaittimemin_shift) |
73 (vdd->vp_rt_data.vstepmin_stepmin <<
74 vp->vp_common->vstepmin_stepmin_shift));
Kevin Hilman4bcc4752011-03-28 10:40:15 -070075 voltdm->write(vp_val, vp->vstepmin);
Kevin Hilman01f48d32011-03-21 14:29:13 -070076
77 vp_val = ((vdd->vp_rt_data.vstepmax_smpswaittimemax <<
78 vp->vp_common->vstepmax_smpswaittimemax_shift) |
79 (vdd->vp_rt_data.vstepmax_stepmax <<
80 vp->vp_common->vstepmax_stepmax_shift));
Kevin Hilman4bcc4752011-03-28 10:40:15 -070081 voltdm->write(vp_val, vp->vstepmax);
Kevin Hilman01f48d32011-03-21 14:29:13 -070082
83 vp_val = ((vdd->vp_rt_data.vlimitto_vddmax <<
84 vp->vp_common->vlimitto_vddmax_shift) |
85 (vdd->vp_rt_data.vlimitto_vddmin <<
86 vp->vp_common->vlimitto_vddmin_shift) |
87 (vdd->vp_rt_data.vlimitto_timeout <<
88 vp->vp_common->vlimitto_timeout_shift));
Kevin Hilman4bcc4752011-03-28 10:40:15 -070089 voltdm->write(vp_val, vp->vlimitto);
Kevin Hilman01f48d32011-03-21 14:29:13 -070090
91 vp_debugfs_init(voltdm);
92}
93
94/* VP force update method of voltage scaling */
95int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
96 unsigned long target_volt)
97{
98 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
Kevin Hilman01f48d32011-03-21 14:29:13 -070099 u32 vpconfig;
100 u8 target_vsel, current_vsel;
101 int ret, timeout = 0;
102
103 ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, &current_vsel);
104 if (ret)
105 return ret;
106
107 /*
108 * Clear all pending TransactionDone interrupt/status. Typical latency
109 * is <3us
110 */
111 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
Kevin Hilman842ec222011-03-28 11:57:18 -0700112 vp->vp_common->ops->clear_txdone(vp->id);
113 if (!vp->vp_common->ops->check_txdone(vp->id))
Kevin Hilman01f48d32011-03-21 14:29:13 -0700114 break;
115 udelay(1);
116 }
117 if (timeout >= VP_TRANXDONE_TIMEOUT) {
118 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
119 "Voltage change aborted", __func__, voltdm->name);
120 return -ETIMEDOUT;
121 }
122
123 /* Configure for VP-Force Update */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700124 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700125 vpconfig &= ~(vp->vp_common->vpconfig_initvdd |
126 vp->vp_common->vpconfig_forceupdate |
127 vp->vp_common->vpconfig_initvoltage_mask);
128 vpconfig |= ((target_vsel <<
129 vp->vp_common->vpconfig_initvoltage_shift));
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700130 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700131
132 /* Trigger initVDD value copy to voltage processor */
133 vpconfig |= vp->vp_common->vpconfig_initvdd;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700134 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700135
136 /* Force update of voltage */
137 vpconfig |= vp->vp_common->vpconfig_forceupdate;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700138 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700139
140 /*
141 * Wait for TransactionDone. Typical latency is <200us.
142 * Depends on SMPSWAITTIMEMIN/MAX and voltage change
143 */
144 timeout = 0;
Kevin Hilman842ec222011-03-28 11:57:18 -0700145 omap_test_timeout(vp->vp_common->ops->check_txdone(vp->id),
Kevin Hilman01f48d32011-03-21 14:29:13 -0700146 VP_TRANXDONE_TIMEOUT, timeout);
147 if (timeout >= VP_TRANXDONE_TIMEOUT)
148 pr_err("%s: vdd_%s TRANXDONE timeout exceeded."
149 "TRANXDONE never got set after the voltage update\n",
150 __func__, voltdm->name);
151
152 omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel);
153
154 /*
155 * Disable TransactionDone interrupt , clear all status, clear
156 * control registers
157 */
158 timeout = 0;
159 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
Kevin Hilman842ec222011-03-28 11:57:18 -0700160 vp->vp_common->ops->clear_txdone(vp->id);
161 if (!vp->vp_common->ops->check_txdone(vp->id))
Kevin Hilman01f48d32011-03-21 14:29:13 -0700162 break;
163 udelay(1);
164 }
165
166 if (timeout >= VP_TRANXDONE_TIMEOUT)
167 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying"
168 "to clear the TRANXDONE status\n",
169 __func__, voltdm->name);
170
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700171 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700172 /* Clear initVDD copy trigger bit */
173 vpconfig &= ~vp->vp_common->vpconfig_initvdd;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700174 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700175 /* Clear force bit */
176 vpconfig &= ~vp->vp_common->vpconfig_forceupdate;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700177 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700178
179 return 0;
180}
181
182/**
183 * omap_vp_get_curr_volt() - API to get the current vp voltage.
184 * @voltdm: pointer to the VDD.
185 *
186 * This API returns the current voltage for the specified voltage processor
187 */
188unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
189{
190 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
191 struct omap_vdd_info *vdd;
192 u8 curr_vsel;
193
194 if (!voltdm || IS_ERR(voltdm)) {
195 pr_warning("%s: VDD specified does not exist!\n", __func__);
196 return 0;
197 }
198
199 vdd = voltdm->vdd;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700200 if (!voltdm->read) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700201 pr_err("%s: No read API for reading vdd_%s regs\n",
202 __func__, voltdm->name);
203 return 0;
204 }
205
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700206 curr_vsel = voltdm->read(vp->voltage);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700207
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700208 if (!voltdm->pmic || !voltdm->pmic->vsel_to_uv) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700209 pr_warning("%s: PMIC function to convert vsel to voltage"
210 "in uV not registerd\n", __func__);
211 return 0;
212 }
213
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700214 return voltdm->pmic->vsel_to_uv(curr_vsel);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700215}
216
217/**
218 * omap_vp_enable() - API to enable a particular VP
219 * @voltdm: pointer to the VDD whose VP is to be enabled.
220 *
221 * This API enables a particular voltage processor. Needed by the smartreflex
222 * class drivers.
223 */
224void omap_vp_enable(struct voltagedomain *voltdm)
225{
226 struct omap_vp_instance_data *vp;
227 struct omap_vdd_info *vdd;
228 u32 vpconfig;
229
230 if (!voltdm || IS_ERR(voltdm)) {
231 pr_warning("%s: VDD specified does not exist!\n", __func__);
232 return;
233 }
234
235 vdd = voltdm->vdd;
236 vp = voltdm->vdd->vp_data;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700237 if (!voltdm->read || !voltdm->write) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700238 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
239 __func__, voltdm->name);
240 return;
241 }
242
243 /* If VP is already enabled, do nothing. Return */
244 if (vdd->vp_enabled)
245 return;
246
247 vp_latch_vsel(voltdm);
248
249 /* Enable VP */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700250 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700251 vpconfig |= vp->vp_common->vpconfig_vpenable;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700252 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700253 vdd->vp_enabled = true;
254}
255
256/**
257 * omap_vp_disable() - API to disable a particular VP
258 * @voltdm: pointer to the VDD whose VP is to be disabled.
259 *
260 * This API disables a particular voltage processor. Needed by the smartreflex
261 * class drivers.
262 */
263void omap_vp_disable(struct voltagedomain *voltdm)
264{
265 struct omap_vp_instance_data *vp;
266 struct omap_vdd_info *vdd;
267 u32 vpconfig;
268 int timeout;
269
270 if (!voltdm || IS_ERR(voltdm)) {
271 pr_warning("%s: VDD specified does not exist!\n", __func__);
272 return;
273 }
274
275 vdd = voltdm->vdd;
276 vp = voltdm->vdd->vp_data;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700277 if (!voltdm->read || !voltdm->write) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700278 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
279 __func__, voltdm->name);
280 return;
281 }
282
283 /* If VP is already disabled, do nothing. Return */
284 if (!vdd->vp_enabled) {
285 pr_warning("%s: Trying to disable VP for vdd_%s when"
286 "it is already disabled\n", __func__, voltdm->name);
287 return;
288 }
289
290 /* Disable VP */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700291 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700292 vpconfig &= ~vp->vp_common->vpconfig_vpenable;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700293 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700294
295 /*
296 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
297 */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700298 omap_test_timeout((voltdm->read(vp->vstatus)),
299 VP_IDLE_TIMEOUT, timeout);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700300
301 if (timeout >= VP_IDLE_TIMEOUT)
302 pr_warning("%s: vdd_%s idle timedout\n",
303 __func__, voltdm->name);
304
305 vdd->vp_enabled = false;
306
307 return;
308}
309
310/* Voltage debugfs support */
311static int vp_volt_debug_get(void *data, u64 *val)
312{
313 struct voltagedomain *voltdm = (struct voltagedomain *)data;
314 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
315 struct omap_vdd_info *vdd = voltdm->vdd;
316 u8 vsel;
317
318 if (!vdd) {
319 pr_warning("Wrong paramater passed\n");
320 return -EINVAL;
321 }
322
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700323 vsel = voltdm->read(vp->voltage);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700324
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700325 if (!voltdm->pmic->vsel_to_uv) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700326 pr_warning("PMIC function to convert vsel to voltage"
327 "in uV not registerd\n");
328 return -EINVAL;
329 }
330
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700331 *val = voltdm->pmic->vsel_to_uv(vsel);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700332 return 0;
333}
334
335DEFINE_SIMPLE_ATTRIBUTE(vp_volt_debug_fops, vp_volt_debug_get, NULL, "%llu\n");
336
337static void __init vp_debugfs_init(struct voltagedomain *voltdm)
338{
339 struct omap_vdd_info *vdd = voltdm->vdd;
340 struct dentry *debug_dir;
341
342 debug_dir = debugfs_create_dir("vp", vdd->debug_dir);
343 if (IS_ERR(debug_dir))
344 pr_err("%s: Unable to create VP debugfs dir dir\n", __func__);
345
346 (void) debugfs_create_x16("errorgain", S_IRUGO, debug_dir,
347 &(vdd->vp_rt_data.vpconfig_errorgain));
348 (void) debugfs_create_x16("smpswaittimemin", S_IRUGO,
349 debug_dir,
350 &(vdd->vp_rt_data.vstepmin_smpswaittimemin));
351 (void) debugfs_create_x8("stepmin", S_IRUGO, debug_dir,
352 &(vdd->vp_rt_data.vstepmin_stepmin));
353 (void) debugfs_create_x16("smpswaittimemax", S_IRUGO,
354 debug_dir,
355 &(vdd->vp_rt_data.vstepmax_smpswaittimemax));
356 (void) debugfs_create_x8("stepmax", S_IRUGO, debug_dir,
357 &(vdd->vp_rt_data.vstepmax_stepmax));
358 (void) debugfs_create_x8("vddmax", S_IRUGO, debug_dir,
359 &(vdd->vp_rt_data.vlimitto_vddmax));
360 (void) debugfs_create_x8("vddmin", S_IRUGO, debug_dir,
361 &(vdd->vp_rt_data.vlimitto_vddmin));
362 (void) debugfs_create_x16("timeout", S_IRUGO, debug_dir,
363 &(vdd->vp_rt_data.vlimitto_timeout));
364 (void) debugfs_create_file("curr_volt", S_IRUGO, debug_dir,
365 (void *) voltdm, &vp_volt_debug_fops);
366}