blob: 53d6018fa6780449ec2e434f2159320a4edbf076 [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{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070017 struct omap_vp_instance *vp = voltdm->vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -070018 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 Hilmanb7ea8032011-04-04 15:25:07 -070038 vpconfig &= ~(vp->common->vpconfig_initvoltage_mask |
39 vp->common->vpconfig_initvdd);
40 vpconfig |= vsel << vp->common->vpconfig_initvoltage_shift;
Kevin Hilman01f48d32011-03-21 14:29:13 -070041
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 Hilmanb7ea8032011-04-04 15:25:07 -070045 voltdm->write((vpconfig | vp->common->vpconfig_initvdd),
Kevin Hilman4bcc4752011-03-28 10:40:15 -070046 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{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070055 struct omap_vp_instance *vp = voltdm->vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -070056 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 <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070067 vp->common->vpconfig_errorgain_shift) |
68 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 <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070072 vp->common->vstepmin_smpswaittimemin_shift) |
Kevin Hilman01f48d32011-03-21 14:29:13 -070073 (vdd->vp_rt_data.vstepmin_stepmin <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070074 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 <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070078 vp->common->vstepmax_smpswaittimemax_shift) |
Kevin Hilman01f48d32011-03-21 14:29:13 -070079 (vdd->vp_rt_data.vstepmax_stepmax <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070080 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 <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070084 vp->common->vlimitto_vddmax_shift) |
Kevin Hilman01f48d32011-03-21 14:29:13 -070085 (vdd->vp_rt_data.vlimitto_vddmin <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070086 vp->common->vlimitto_vddmin_shift) |
Kevin Hilman01f48d32011-03-21 14:29:13 -070087 (vdd->vp_rt_data.vlimitto_timeout <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070088 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{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070098 struct omap_vp_instance *vp = voltdm->vp;
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 Hilmanb7ea8032011-04-04 15:25:07 -0700112 vp->common->ops->clear_txdone(vp->id);
113 if (!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 Hilmanb7ea8032011-04-04 15:25:07 -0700125 vpconfig &= ~(vp->common->vpconfig_initvdd |
126 vp->common->vpconfig_forceupdate |
127 vp->common->vpconfig_initvoltage_mask);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700128 vpconfig |= ((target_vsel <<
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700129 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 */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700133 vpconfig |= 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 */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700137 vpconfig |= 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 Hilmanb7ea8032011-04-04 15:25:07 -0700145 omap_test_timeout(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 Hilmanb7ea8032011-04-04 15:25:07 -0700160 vp->common->ops->clear_txdone(vp->id);
161 if (!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 */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700173 vpconfig &= ~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 */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700176 vpconfig &= ~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{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700190 struct omap_vp_instance *vp = voltdm->vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700191 u8 curr_vsel;
192
193 if (!voltdm || IS_ERR(voltdm)) {
194 pr_warning("%s: VDD specified does not exist!\n", __func__);
195 return 0;
196 }
197
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700198 if (!voltdm->read) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700199 pr_err("%s: No read API for reading vdd_%s regs\n",
200 __func__, voltdm->name);
201 return 0;
202 }
203
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700204 curr_vsel = voltdm->read(vp->voltage);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700205
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700206 if (!voltdm->pmic || !voltdm->pmic->vsel_to_uv) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700207 pr_warning("%s: PMIC function to convert vsel to voltage"
208 "in uV not registerd\n", __func__);
209 return 0;
210 }
211
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700212 return voltdm->pmic->vsel_to_uv(curr_vsel);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700213}
214
215/**
216 * omap_vp_enable() - API to enable a particular VP
217 * @voltdm: pointer to the VDD whose VP is to be enabled.
218 *
219 * This API enables a particular voltage processor. Needed by the smartreflex
220 * class drivers.
221 */
222void omap_vp_enable(struct voltagedomain *voltdm)
223{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700224 struct omap_vp_instance *vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700225 u32 vpconfig;
226
227 if (!voltdm || IS_ERR(voltdm)) {
228 pr_warning("%s: VDD specified does not exist!\n", __func__);
229 return;
230 }
231
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700232 vp = voltdm->vp;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700233 if (!voltdm->read || !voltdm->write) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700234 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
235 __func__, voltdm->name);
236 return;
237 }
238
239 /* If VP is already enabled, do nothing. Return */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700240 if (vp->enabled)
Kevin Hilman01f48d32011-03-21 14:29:13 -0700241 return;
242
243 vp_latch_vsel(voltdm);
244
245 /* Enable VP */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700246 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700247 vpconfig |= vp->common->vpconfig_vpenable;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700248 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700249 vp->enabled = true;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700250}
251
252/**
253 * omap_vp_disable() - API to disable a particular VP
254 * @voltdm: pointer to the VDD whose VP is to be disabled.
255 *
256 * This API disables a particular voltage processor. Needed by the smartreflex
257 * class drivers.
258 */
259void omap_vp_disable(struct voltagedomain *voltdm)
260{
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700261 struct omap_vp_instance *vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700262 u32 vpconfig;
263 int timeout;
264
265 if (!voltdm || IS_ERR(voltdm)) {
266 pr_warning("%s: VDD specified does not exist!\n", __func__);
267 return;
268 }
269
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700270 vp = voltdm->vp;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700271 if (!voltdm->read || !voltdm->write) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700272 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
273 __func__, voltdm->name);
274 return;
275 }
276
277 /* If VP is already disabled, do nothing. Return */
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700278 if (!vp->enabled) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700279 pr_warning("%s: Trying to disable VP for vdd_%s when"
280 "it is already disabled\n", __func__, voltdm->name);
281 return;
282 }
283
284 /* Disable VP */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700285 vpconfig = voltdm->read(vp->vpconfig);
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700286 vpconfig &= ~vp->common->vpconfig_vpenable;
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700287 voltdm->write(vpconfig, vp->vpconfig);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700288
289 /*
290 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
291 */
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700292 omap_test_timeout((voltdm->read(vp->vstatus)),
293 VP_IDLE_TIMEOUT, timeout);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700294
295 if (timeout >= VP_IDLE_TIMEOUT)
296 pr_warning("%s: vdd_%s idle timedout\n",
297 __func__, voltdm->name);
298
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700299 vp->enabled = false;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700300
301 return;
302}
303
304/* Voltage debugfs support */
305static int vp_volt_debug_get(void *data, u64 *val)
306{
307 struct voltagedomain *voltdm = (struct voltagedomain *)data;
Kevin Hilmanb7ea8032011-04-04 15:25:07 -0700308 struct omap_vp_instance *vp = voltdm->vp;
Kevin Hilman01f48d32011-03-21 14:29:13 -0700309 struct omap_vdd_info *vdd = voltdm->vdd;
310 u8 vsel;
311
312 if (!vdd) {
313 pr_warning("Wrong paramater passed\n");
314 return -EINVAL;
315 }
316
Kevin Hilman4bcc4752011-03-28 10:40:15 -0700317 vsel = voltdm->read(vp->voltage);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700318
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700319 if (!voltdm->pmic->vsel_to_uv) {
Kevin Hilman01f48d32011-03-21 14:29:13 -0700320 pr_warning("PMIC function to convert vsel to voltage"
321 "in uV not registerd\n");
322 return -EINVAL;
323 }
324
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700325 *val = voltdm->pmic->vsel_to_uv(vsel);
Kevin Hilman01f48d32011-03-21 14:29:13 -0700326 return 0;
327}
328
329DEFINE_SIMPLE_ATTRIBUTE(vp_volt_debug_fops, vp_volt_debug_get, NULL, "%llu\n");
330
331static void __init vp_debugfs_init(struct voltagedomain *voltdm)
332{
333 struct omap_vdd_info *vdd = voltdm->vdd;
334 struct dentry *debug_dir;
335
336 debug_dir = debugfs_create_dir("vp", vdd->debug_dir);
337 if (IS_ERR(debug_dir))
338 pr_err("%s: Unable to create VP debugfs dir dir\n", __func__);
339
340 (void) debugfs_create_x16("errorgain", S_IRUGO, debug_dir,
341 &(vdd->vp_rt_data.vpconfig_errorgain));
342 (void) debugfs_create_x16("smpswaittimemin", S_IRUGO,
343 debug_dir,
344 &(vdd->vp_rt_data.vstepmin_smpswaittimemin));
345 (void) debugfs_create_x8("stepmin", S_IRUGO, debug_dir,
346 &(vdd->vp_rt_data.vstepmin_stepmin));
347 (void) debugfs_create_x16("smpswaittimemax", S_IRUGO,
348 debug_dir,
349 &(vdd->vp_rt_data.vstepmax_smpswaittimemax));
350 (void) debugfs_create_x8("stepmax", S_IRUGO, debug_dir,
351 &(vdd->vp_rt_data.vstepmax_stepmax));
352 (void) debugfs_create_x8("vddmax", S_IRUGO, debug_dir,
353 &(vdd->vp_rt_data.vlimitto_vddmax));
354 (void) debugfs_create_x8("vddmin", S_IRUGO, debug_dir,
355 &(vdd->vp_rt_data.vlimitto_vddmin));
356 (void) debugfs_create_x16("timeout", S_IRUGO, debug_dir,
357 &(vdd->vp_rt_data.vlimitto_timeout));
358 (void) debugfs_create_file("curr_volt", S_IRUGO, debug_dir,
359 (void *) voltdm, &vp_volt_debug_fops);
360}