blob: 113c839f6e23da0e07fa7ded603ef4e4061aa1d7 [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;
21 struct omap_vdd_info *vdd = voltdm->vdd;
22
23 uvdc = omap_voltage_get_nom_volt(voltdm);
24 if (!uvdc) {
25 pr_warning("%s: unable to find current voltage for vdd_%s\n",
26 __func__, voltdm->name);
27 return;
28 }
29
30 if (!vdd->pmic_info || !vdd->pmic_info->uv_to_vsel) {
31 pr_warning("%s: PMIC function to convert voltage in uV to"
32 " vsel not registered\n", __func__);
33 return;
34 }
35
36 vsel = vdd->pmic_info->uv_to_vsel(uvdc);
37
38 vpconfig = vdd->read_reg(vp->vp_common->prm_mod, vp->vpconfig);
39 vpconfig &= ~(vp->vp_common->vpconfig_initvoltage_mask |
40 vp->vp_common->vpconfig_initvdd);
41 vpconfig |= vsel << vp->vp_common->vpconfig_initvoltage_shift;
42
43 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
44
45 /* Trigger initVDD value copy to voltage processor */
46 vdd->write_reg((vpconfig | vp->vp_common->vpconfig_initvdd),
47 vp->vp_common->prm_mod, vp->vpconfig);
48
49 /* Clear initVDD copy trigger bit */
50 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
51}
52
53/* Generic voltage init functions */
54void __init omap_vp_init(struct voltagedomain *voltdm)
55{
56 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
57 struct omap_vdd_info *vdd = voltdm->vdd;
58 u32 vp_val;
59
60 if (!vdd->read_reg || !vdd->write_reg) {
61 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
62 __func__, voltdm->name);
63 return;
64 }
65
66 vp_val = vdd->vp_rt_data.vpconfig_erroroffset |
67 (vdd->vp_rt_data.vpconfig_errorgain <<
68 vp->vp_common->vpconfig_errorgain_shift) |
69 vp->vp_common->vpconfig_timeouten;
70 vdd->write_reg(vp_val, vp->vp_common->prm_mod, vp->vpconfig);
71
72 vp_val = ((vdd->vp_rt_data.vstepmin_smpswaittimemin <<
73 vp->vp_common->vstepmin_smpswaittimemin_shift) |
74 (vdd->vp_rt_data.vstepmin_stepmin <<
75 vp->vp_common->vstepmin_stepmin_shift));
76 vdd->write_reg(vp_val, vp->vp_common->prm_mod, vp->vstepmin);
77
78 vp_val = ((vdd->vp_rt_data.vstepmax_smpswaittimemax <<
79 vp->vp_common->vstepmax_smpswaittimemax_shift) |
80 (vdd->vp_rt_data.vstepmax_stepmax <<
81 vp->vp_common->vstepmax_stepmax_shift));
82 vdd->write_reg(vp_val, vp->vp_common->prm_mod, vp->vstepmax);
83
84 vp_val = ((vdd->vp_rt_data.vlimitto_vddmax <<
85 vp->vp_common->vlimitto_vddmax_shift) |
86 (vdd->vp_rt_data.vlimitto_vddmin <<
87 vp->vp_common->vlimitto_vddmin_shift) |
88 (vdd->vp_rt_data.vlimitto_timeout <<
89 vp->vp_common->vlimitto_timeout_shift));
90 vdd->write_reg(vp_val, vp->vp_common->prm_mod, vp->vlimitto);
91
92 vp_debugfs_init(voltdm);
93}
94
95/* VP force update method of voltage scaling */
96int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
97 unsigned long target_volt)
98{
99 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
100 struct omap_vdd_info *vdd = voltdm->vdd;
101 u32 vpconfig;
102 u8 target_vsel, current_vsel;
103 int ret, timeout = 0;
104
105 ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, &current_vsel);
106 if (ret)
107 return ret;
108
109 /*
110 * Clear all pending TransactionDone interrupt/status. Typical latency
111 * is <3us
112 */
113 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
Kevin Hilman842ec222011-03-28 11:57:18 -0700114 vp->vp_common->ops->clear_txdone(vp->id);
115 if (!vp->vp_common->ops->check_txdone(vp->id))
Kevin Hilman01f48d32011-03-21 14:29:13 -0700116 break;
117 udelay(1);
118 }
119 if (timeout >= VP_TRANXDONE_TIMEOUT) {
120 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded."
121 "Voltage change aborted", __func__, voltdm->name);
122 return -ETIMEDOUT;
123 }
124
125 /* Configure for VP-Force Update */
126 vpconfig = vdd->read_reg(vp->vp_common->prm_mod, vp->vpconfig);
127 vpconfig &= ~(vp->vp_common->vpconfig_initvdd |
128 vp->vp_common->vpconfig_forceupdate |
129 vp->vp_common->vpconfig_initvoltage_mask);
130 vpconfig |= ((target_vsel <<
131 vp->vp_common->vpconfig_initvoltage_shift));
132 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
133
134 /* Trigger initVDD value copy to voltage processor */
135 vpconfig |= vp->vp_common->vpconfig_initvdd;
136 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
137
138 /* Force update of voltage */
139 vpconfig |= vp->vp_common->vpconfig_forceupdate;
140 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
141
142 /*
143 * Wait for TransactionDone. Typical latency is <200us.
144 * Depends on SMPSWAITTIMEMIN/MAX and voltage change
145 */
146 timeout = 0;
Kevin Hilman842ec222011-03-28 11:57:18 -0700147 omap_test_timeout(vp->vp_common->ops->check_txdone(vp->id),
Kevin Hilman01f48d32011-03-21 14:29:13 -0700148 VP_TRANXDONE_TIMEOUT, timeout);
149 if (timeout >= VP_TRANXDONE_TIMEOUT)
150 pr_err("%s: vdd_%s TRANXDONE timeout exceeded."
151 "TRANXDONE never got set after the voltage update\n",
152 __func__, voltdm->name);
153
154 omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel);
155
156 /*
157 * Disable TransactionDone interrupt , clear all status, clear
158 * control registers
159 */
160 timeout = 0;
161 while (timeout++ < VP_TRANXDONE_TIMEOUT) {
Kevin Hilman842ec222011-03-28 11:57:18 -0700162 vp->vp_common->ops->clear_txdone(vp->id);
163 if (!vp->vp_common->ops->check_txdone(vp->id))
Kevin Hilman01f48d32011-03-21 14:29:13 -0700164 break;
165 udelay(1);
166 }
167
168 if (timeout >= VP_TRANXDONE_TIMEOUT)
169 pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying"
170 "to clear the TRANXDONE status\n",
171 __func__, voltdm->name);
172
173 vpconfig = vdd->read_reg(vp->vp_common->prm_mod, vp->vpconfig);
174 /* Clear initVDD copy trigger bit */
175 vpconfig &= ~vp->vp_common->vpconfig_initvdd;
176 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
177 /* Clear force bit */
178 vpconfig &= ~vp->vp_common->vpconfig_forceupdate;
179 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
180
181 return 0;
182}
183
184/**
185 * omap_vp_get_curr_volt() - API to get the current vp voltage.
186 * @voltdm: pointer to the VDD.
187 *
188 * This API returns the current voltage for the specified voltage processor
189 */
190unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
191{
192 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
193 struct omap_vdd_info *vdd;
194 u8 curr_vsel;
195
196 if (!voltdm || IS_ERR(voltdm)) {
197 pr_warning("%s: VDD specified does not exist!\n", __func__);
198 return 0;
199 }
200
201 vdd = voltdm->vdd;
202 if (!vdd->read_reg) {
203 pr_err("%s: No read API for reading vdd_%s regs\n",
204 __func__, voltdm->name);
205 return 0;
206 }
207
208 curr_vsel = vdd->read_reg(vp->vp_common->prm_mod, vp->voltage);
209
210 if (!vdd->pmic_info || !vdd->pmic_info->vsel_to_uv) {
211 pr_warning("%s: PMIC function to convert vsel to voltage"
212 "in uV not registerd\n", __func__);
213 return 0;
214 }
215
216 return vdd->pmic_info->vsel_to_uv(curr_vsel);
217}
218
219/**
220 * omap_vp_enable() - API to enable a particular VP
221 * @voltdm: pointer to the VDD whose VP is to be enabled.
222 *
223 * This API enables a particular voltage processor. Needed by the smartreflex
224 * class drivers.
225 */
226void omap_vp_enable(struct voltagedomain *voltdm)
227{
228 struct omap_vp_instance_data *vp;
229 struct omap_vdd_info *vdd;
230 u32 vpconfig;
231
232 if (!voltdm || IS_ERR(voltdm)) {
233 pr_warning("%s: VDD specified does not exist!\n", __func__);
234 return;
235 }
236
237 vdd = voltdm->vdd;
238 vp = voltdm->vdd->vp_data;
239 if (!vdd->read_reg || !vdd->write_reg) {
240 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
241 __func__, voltdm->name);
242 return;
243 }
244
245 /* If VP is already enabled, do nothing. Return */
246 if (vdd->vp_enabled)
247 return;
248
249 vp_latch_vsel(voltdm);
250
251 /* Enable VP */
252 vpconfig = vdd->read_reg(vp->vp_common->prm_mod, vp->vpconfig);
253 vpconfig |= vp->vp_common->vpconfig_vpenable;
254 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
255 vdd->vp_enabled = true;
256}
257
258/**
259 * omap_vp_disable() - API to disable a particular VP
260 * @voltdm: pointer to the VDD whose VP is to be disabled.
261 *
262 * This API disables a particular voltage processor. Needed by the smartreflex
263 * class drivers.
264 */
265void omap_vp_disable(struct voltagedomain *voltdm)
266{
267 struct omap_vp_instance_data *vp;
268 struct omap_vdd_info *vdd;
269 u32 vpconfig;
270 int timeout;
271
272 if (!voltdm || IS_ERR(voltdm)) {
273 pr_warning("%s: VDD specified does not exist!\n", __func__);
274 return;
275 }
276
277 vdd = voltdm->vdd;
278 vp = voltdm->vdd->vp_data;
279 if (!vdd->read_reg || !vdd->write_reg) {
280 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
281 __func__, voltdm->name);
282 return;
283 }
284
285 /* If VP is already disabled, do nothing. Return */
286 if (!vdd->vp_enabled) {
287 pr_warning("%s: Trying to disable VP for vdd_%s when"
288 "it is already disabled\n", __func__, voltdm->name);
289 return;
290 }
291
292 /* Disable VP */
293 vpconfig = vdd->read_reg(vp->vp_common->prm_mod, vp->vpconfig);
294 vpconfig &= ~vp->vp_common->vpconfig_vpenable;
295 vdd->write_reg(vpconfig, vp->vp_common->prm_mod, vp->vpconfig);
296
297 /*
298 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
299 */
300 omap_test_timeout((vdd->read_reg(vp->vp_common->prm_mod, vp->vstatus)),
301 VP_IDLE_TIMEOUT, timeout);
302
303 if (timeout >= VP_IDLE_TIMEOUT)
304 pr_warning("%s: vdd_%s idle timedout\n",
305 __func__, voltdm->name);
306
307 vdd->vp_enabled = false;
308
309 return;
310}
311
312/* Voltage debugfs support */
313static int vp_volt_debug_get(void *data, u64 *val)
314{
315 struct voltagedomain *voltdm = (struct voltagedomain *)data;
316 struct omap_vp_instance_data *vp = voltdm->vdd->vp_data;
317 struct omap_vdd_info *vdd = voltdm->vdd;
318 u8 vsel;
319
320 if (!vdd) {
321 pr_warning("Wrong paramater passed\n");
322 return -EINVAL;
323 }
324
325 vsel = vdd->read_reg(vp->vp_common->prm_mod, vp->voltage);
326
327 if (!vdd->pmic_info->vsel_to_uv) {
328 pr_warning("PMIC function to convert vsel to voltage"
329 "in uV not registerd\n");
330 return -EINVAL;
331 }
332
333 *val = vdd->pmic_info->vsel_to_uv(vsel);
334 return 0;
335}
336
337DEFINE_SIMPLE_ATTRIBUTE(vp_volt_debug_fops, vp_volt_debug_get, NULL, "%llu\n");
338
339static void __init vp_debugfs_init(struct voltagedomain *voltdm)
340{
341 struct omap_vdd_info *vdd = voltdm->vdd;
342 struct dentry *debug_dir;
343
344 debug_dir = debugfs_create_dir("vp", vdd->debug_dir);
345 if (IS_ERR(debug_dir))
346 pr_err("%s: Unable to create VP debugfs dir dir\n", __func__);
347
348 (void) debugfs_create_x16("errorgain", S_IRUGO, debug_dir,
349 &(vdd->vp_rt_data.vpconfig_errorgain));
350 (void) debugfs_create_x16("smpswaittimemin", S_IRUGO,
351 debug_dir,
352 &(vdd->vp_rt_data.vstepmin_smpswaittimemin));
353 (void) debugfs_create_x8("stepmin", S_IRUGO, debug_dir,
354 &(vdd->vp_rt_data.vstepmin_stepmin));
355 (void) debugfs_create_x16("smpswaittimemax", S_IRUGO,
356 debug_dir,
357 &(vdd->vp_rt_data.vstepmax_smpswaittimemax));
358 (void) debugfs_create_x8("stepmax", S_IRUGO, debug_dir,
359 &(vdd->vp_rt_data.vstepmax_stepmax));
360 (void) debugfs_create_x8("vddmax", S_IRUGO, debug_dir,
361 &(vdd->vp_rt_data.vlimitto_vddmax));
362 (void) debugfs_create_x8("vddmin", S_IRUGO, debug_dir,
363 &(vdd->vp_rt_data.vlimitto_vddmin));
364 (void) debugfs_create_x16("timeout", S_IRUGO, debug_dir,
365 &(vdd->vp_rt_data.vlimitto_timeout));
366 (void) debugfs_create_file("curr_volt", S_IRUGO, debug_dir,
367 (void *) voltdm, &vp_volt_debug_fops);
368}