OMAP3+: voltage: rename scale and reset functions using voltdm_ prefix
[deliverable/linux.git] / arch / arm / mach-omap2 / voltage.c
CommitLineData
2f34ce81
TG
1/*
2 * OMAP3/OMAP4 Voltage Management Routines
3 *
4 * Author: Thara Gopinath <thara@ti.com>
5 *
6 * Copyright (C) 2007 Texas Instruments, Inc.
7 * Rajendra Nayak <rnayak@ti.com>
8 * Lesly A M <x0080970@ti.com>
9 *
c0718df4 10 * Copyright (C) 2008, 2011 Nokia Corporation
2f34ce81 11 * Kalle Jokiniemi
c0718df4 12 * Paul Walmsley
2f34ce81
TG
13 *
14 * Copyright (C) 2010 Texas Instruments, Inc.
15 * Thara Gopinath <thara@ti.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
20 */
21
22#include <linux/delay.h>
23#include <linux/io.h>
2f34ce81
TG
24#include <linux/err.h>
25#include <linux/debugfs.h>
26#include <linux/slab.h>
0e2f3d9c 27#include <linux/clk.h>
2f34ce81
TG
28
29#include <plat/common.h>
2f34ce81
TG
30
31#include "prm-regbits-34xx.h"
bd38107b
TG
32#include "prm-regbits-44xx.h"
33#include "prm44xx.h"
34#include "prcm44xx.h"
35#include "prminst44xx.h"
2f34ce81
TG
36#include "control.h"
37
e1d6f472 38#include "voltage.h"
e69c22b1 39#include "powerdomain.h"
e1d6f472 40
c0718df4
PW
41#include "vc.h"
42#include "vp.h"
43
81a60482 44static LIST_HEAD(voltdm_list);
2f34ce81 45
81a60482 46static int __init _config_common_vdd_data(struct voltagedomain *voltdm)
c0718df4 47{
c0718df4 48 /* Generic voltage parameters */
0f01565a 49 voltdm->scale = omap_vp_forceupdate_scale;
c0718df4
PW
50
51 return 0;
52}
53
81a60482 54static int __init omap_vdd_data_configure(struct voltagedomain *voltdm)
bd38107b 55{
c0718df4 56 int ret = -EINVAL;
bd38107b 57
ce8ebe0d 58 if (!voltdm->pmic) {
bd38107b
TG
59 pr_err("%s: PMIC info requried to configure vdd_%s not"
60 "populated.Hence cannot initialize vdd_%s\n",
81a60482 61 __func__, voltdm->name, voltdm->name);
c0718df4 62 goto ovdc_out;
bd38107b
TG
63 }
64
81a60482 65 if (IS_ERR_VALUE(_config_common_vdd_data(voltdm)))
c0718df4 66 goto ovdc_out;
bd38107b 67
4bcc475e 68 ret = 0;
bd38107b 69
c0718df4
PW
70ovdc_out:
71 return ret;
bd38107b
TG
72}
73
2f34ce81
TG
74/* Public functions */
75/**
76 * omap_voltage_get_nom_volt() - Gets the current non-auto-compensated voltage
77 * @voltdm: pointer to the VDD for which current voltage info is needed
78 *
79 * API to get the current non-auto-compensated voltage for a VDD.
80 * Returns 0 in case of error else returns the current voltage for the VDD.
81 */
82unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm)
83{
84 struct omap_vdd_info *vdd;
85
86 if (!voltdm || IS_ERR(voltdm)) {
87 pr_warning("%s: VDD specified does not exist!\n", __func__);
88 return 0;
89 }
90
81a60482 91 vdd = voltdm->vdd;
2f34ce81
TG
92
93 return vdd->curr_volt;
94}
95
2f34ce81 96/**
5e5651be
KH
97 * voltdm_scale() - API to scale voltage of a particular voltage domain.
98 * @voltdm: pointer to the voltage domain which is to be scaled.
99 * @target_volt: The target voltage of the voltage domain
2f34ce81
TG
100 *
101 * This API should be called by the kernel to do the voltage scaling
5e5651be 102 * for a particular voltage domain during DVFS.
2f34ce81 103 */
5e5651be
KH
104int voltdm_scale(struct voltagedomain *voltdm,
105 unsigned long target_volt)
2f34ce81 106{
2f34ce81
TG
107 if (!voltdm || IS_ERR(voltdm)) {
108 pr_warning("%s: VDD specified does not exist!\n", __func__);
109 return -EINVAL;
110 }
111
0f01565a 112 if (!voltdm->scale) {
2f34ce81
TG
113 pr_err("%s: No voltage scale API registered for vdd_%s\n",
114 __func__, voltdm->name);
115 return -ENODATA;
116 }
117
0f01565a 118 return voltdm->scale(voltdm, target_volt);
2f34ce81
TG
119}
120
121/**
5e5651be
KH
122 * voltdm_reset() - Resets the voltage of a particular voltage domain
123 * to that of the current OPP.
124 * @voltdm: pointer to the voltage domain whose voltage is to be reset.
2f34ce81
TG
125 *
126 * This API finds out the correct voltage the voltage domain is supposed
25985edc 127 * to be at and resets the voltage to that level. Should be used especially
2f34ce81
TG
128 * while disabling any voltage compensation modules.
129 */
5e5651be 130void voltdm_reset(struct voltagedomain *voltdm)
2f34ce81 131{
5e5651be 132 unsigned long target_volt;
2f34ce81
TG
133
134 if (!voltdm || IS_ERR(voltdm)) {
135 pr_warning("%s: VDD specified does not exist!\n", __func__);
136 return;
137 }
138
5e5651be
KH
139 target_volt = omap_voltage_get_nom_volt(voltdm);
140 if (!target_volt) {
2f34ce81
TG
141 pr_err("%s: unable to find current voltage for vdd_%s\n",
142 __func__, voltdm->name);
143 return;
144 }
145
5e5651be 146 voltdm_scale(voltdm, target_volt);
2f34ce81
TG
147}
148
149/**
150 * omap_voltage_get_volttable() - API to get the voltage table associated with a
151 * particular voltage domain.
152 * @voltdm: pointer to the VDD for which the voltage table is required
153 * @volt_data: the voltage table for the particular vdd which is to be
154 * populated by this API
155 *
156 * This API populates the voltage table associated with a VDD into the
157 * passed parameter pointer. Returns the count of distinct voltages
158 * supported by this vdd.
159 *
160 */
161void omap_voltage_get_volttable(struct voltagedomain *voltdm,
162 struct omap_volt_data **volt_data)
163{
164 struct omap_vdd_info *vdd;
165
166 if (!voltdm || IS_ERR(voltdm)) {
167 pr_warning("%s: VDD specified does not exist!\n", __func__);
168 return;
169 }
170
81a60482 171 vdd = voltdm->vdd;
2f34ce81
TG
172
173 *volt_data = vdd->volt_data;
174}
175
176/**
177 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
178 * particular voltage
179 * @voltdm: pointer to the VDD whose voltage table has to be searched
180 * @volt: the voltage to be searched in the voltage table
181 *
182 * This API searches through the voltage table for the required voltage
183 * domain and tries to find a matching entry for the passed voltage volt.
184 * If a matching entry is found volt_data is populated with that entry.
185 * This API searches only through the non-compensated voltages int the
186 * voltage table.
187 * Returns pointer to the voltage table entry corresponding to volt on
25985edc 188 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
2f34ce81
TG
189 * domain or if there is no matching entry.
190 */
191struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
192 unsigned long volt)
193{
194 struct omap_vdd_info *vdd;
195 int i;
196
197 if (!voltdm || IS_ERR(voltdm)) {
198 pr_warning("%s: VDD specified does not exist!\n", __func__);
199 return ERR_PTR(-EINVAL);
200 }
201
81a60482 202 vdd = voltdm->vdd;
2f34ce81
TG
203
204 if (!vdd->volt_data) {
205 pr_warning("%s: voltage table does not exist for vdd_%s\n",
206 __func__, voltdm->name);
207 return ERR_PTR(-ENODATA);
208 }
209
210 for (i = 0; vdd->volt_data[i].volt_nominal != 0; i++) {
211 if (vdd->volt_data[i].volt_nominal == volt)
212 return &vdd->volt_data[i];
213 }
214
215 pr_notice("%s: Unable to match the current voltage with the voltage"
216 "table for vdd_%s\n", __func__, voltdm->name);
217
218 return ERR_PTR(-ENODATA);
219}
220
221/**
222 * omap_voltage_register_pmic() - API to register PMIC specific data
223 * @voltdm: pointer to the VDD for which the PMIC specific data is
224 * to be registered
ce8ebe0d 225 * @pmic: the structure containing pmic info
2f34ce81
TG
226 *
227 * This API is to be called by the SOC/PMIC file to specify the
ce8ebe0d 228 * pmic specific info as present in omap_voltdm_pmic structure.
2f34ce81
TG
229 */
230int omap_voltage_register_pmic(struct voltagedomain *voltdm,
ce8ebe0d 231 struct omap_voltdm_pmic *pmic)
2f34ce81 232{
2f34ce81
TG
233 if (!voltdm || IS_ERR(voltdm)) {
234 pr_warning("%s: VDD specified does not exist!\n", __func__);
235 return -EINVAL;
236 }
237
ce8ebe0d 238 voltdm->pmic = pmic;
2f34ce81
TG
239
240 return 0;
241}
242
2f34ce81
TG
243/**
244 * omap_change_voltscale_method() - API to change the voltage scaling method.
245 * @voltdm: pointer to the VDD whose voltage scaling method
246 * has to be changed.
247 * @voltscale_method: the method to be used for voltage scaling.
248 *
249 * This API can be used by the board files to change the method of voltage
250 * scaling between vpforceupdate and vcbypass. The parameter values are
251 * defined in voltage.h
252 */
253void omap_change_voltscale_method(struct voltagedomain *voltdm,
0f01565a 254 int voltscale_method)
2f34ce81 255{
2f34ce81
TG
256 if (!voltdm || IS_ERR(voltdm)) {
257 pr_warning("%s: VDD specified does not exist!\n", __func__);
258 return;
259 }
260
2f34ce81
TG
261 switch (voltscale_method) {
262 case VOLTSCALE_VPFORCEUPDATE:
0f01565a 263 voltdm->scale = omap_vp_forceupdate_scale;
2f34ce81
TG
264 return;
265 case VOLTSCALE_VCBYPASS:
0f01565a 266 voltdm->scale = omap_vc_bypass_scale;
2f34ce81
TG
267 return;
268 default:
269 pr_warning("%s: Trying to change the method of voltage scaling"
270 "to an unsupported one!\n", __func__);
271 }
272}
273
2f34ce81
TG
274/**
275 * omap_voltage_late_init() - Init the various voltage parameters
276 *
277 * This API is to be called in the later stages of the
278 * system boot to init the voltage controller and
279 * voltage processors.
280 */
281int __init omap_voltage_late_init(void)
282{
81a60482 283 struct voltagedomain *voltdm;
2f34ce81 284
81a60482 285 if (list_empty(&voltdm_list)) {
2f34ce81
TG
286 pr_err("%s: Voltage driver support not added\n",
287 __func__);
288 return -EINVAL;
289 }
290
81a60482 291 list_for_each_entry(voltdm, &voltdm_list, node) {
0e2f3d9c
KH
292 struct clk *sys_ck;
293
37efca7e
KH
294 if (!voltdm->scalable)
295 continue;
296
0e2f3d9c
KH
297 sys_ck = clk_get(NULL, voltdm->sys_clk.name);
298 if (IS_ERR(sys_ck)) {
299 pr_warning("%s: Could not get sys clk.\n", __func__);
300 return -EINVAL;
301 }
302 voltdm->sys_clk.rate = clk_get_rate(sys_ck);
303 WARN_ON(!voltdm->sys_clk.rate);
304 clk_put(sys_ck);
305
4d47506a 306 if (voltdm->vc) {
0f01565a 307 voltdm->scale = omap_vc_bypass_scale;
d84adcf4 308 omap_vc_init_channel(voltdm);
4d47506a 309 }
d84adcf4 310
81a60482
KH
311 if (voltdm->vdd) {
312 if (omap_vdd_data_configure(voltdm))
313 continue;
01f48d30 314 omap_vp_init(voltdm);
81a60482 315 }
2f34ce81
TG
316 }
317
318 return 0;
319}
320
81a60482 321static struct voltagedomain *_voltdm_lookup(const char *name)
2f34ce81 322{
81a60482
KH
323 struct voltagedomain *voltdm, *temp_voltdm;
324
325 voltdm = NULL;
326
327 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
328 if (!strcmp(name, temp_voltdm->name)) {
329 voltdm = temp_voltdm;
330 break;
331 }
332 }
333
334 return voltdm;
335}
336
e69c22b1
KH
337/**
338 * voltdm_add_pwrdm - add a powerdomain to a voltagedomain
339 * @voltdm: struct voltagedomain * to add the powerdomain to
340 * @pwrdm: struct powerdomain * to associate with a voltagedomain
341 *
342 * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This
343 * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if
344 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
345 * or 0 upon success.
346 */
347int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm)
348{
349 if (!voltdm || !pwrdm)
350 return -EINVAL;
351
352 pr_debug("voltagedomain: associating powerdomain %s with voltagedomain "
353 "%s\n", pwrdm->name, voltdm->name);
354
355 list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list);
356
357 return 0;
358}
359
360/**
361 * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
362 * @voltdm: struct voltagedomain * to iterate over
363 * @fn: callback function *
364 *
365 * Call the supplied function @fn for each powerdomain in the
366 * voltagedomain @voltdm. Returns -EINVAL if presented with invalid
367 * pointers; or passes along the last return value of the callback
368 * function, which should be 0 for success or anything else to
369 * indicate failure.
370 */
371int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
372 int (*fn)(struct voltagedomain *voltdm,
373 struct powerdomain *pwrdm))
374{
375 struct powerdomain *pwrdm;
376 int ret = 0;
377
378 if (!fn)
379 return -EINVAL;
380
381 list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node)
382 ret = (*fn)(voltdm, pwrdm);
383
384 return ret;
385}
386
387/**
388 * voltdm_for_each - call function on each registered voltagedomain
389 * @fn: callback function *
390 *
391 * Call the supplied function @fn for each registered voltagedomain.
392 * The callback function @fn can return anything but 0 to bail out
393 * early from the iterator. Returns the last return value of the
394 * callback function, which should be 0 for success or anything else
395 * to indicate failure; or -EINVAL if the function pointer is null.
396 */
397int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
398 void *user)
399{
400 struct voltagedomain *temp_voltdm;
401 int ret = 0;
402
403 if (!fn)
404 return -EINVAL;
405
406 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
407 ret = (*fn)(temp_voltdm, user);
408 if (ret)
409 break;
410 }
411
412 return ret;
413}
414
81a60482
KH
415static int _voltdm_register(struct voltagedomain *voltdm)
416{
417 if (!voltdm || !voltdm->name)
418 return -EINVAL;
419
e69c22b1 420 INIT_LIST_HEAD(&voltdm->pwrdm_list);
81a60482
KH
421 list_add(&voltdm->node, &voltdm_list);
422
423 pr_debug("voltagedomain: registered %s\n", voltdm->name);
424
2f34ce81
TG
425 return 0;
426}
81a60482
KH
427
428/**
429 * voltdm_lookup - look up a voltagedomain by name, return a pointer
430 * @name: name of voltagedomain
431 *
432 * Find a registered voltagedomain by its name @name. Returns a pointer
433 * to the struct voltagedomain if found, or NULL otherwise.
434 */
435struct voltagedomain *voltdm_lookup(const char *name)
436{
437 struct voltagedomain *voltdm ;
438
439 if (!name)
440 return NULL;
441
442 voltdm = _voltdm_lookup(name);
443
444 return voltdm;
445}
446
447/**
448 * voltdm_init - set up the voltagedomain layer
449 * @voltdm_list: array of struct voltagedomain pointers to register
450 *
451 * Loop through the array of voltagedomains @voltdm_list, registering all
452 * that are available on the current CPU. If voltdm_list is supplied
453 * and not null, all of the referenced voltagedomains will be
454 * registered. No return value.
455 */
456void voltdm_init(struct voltagedomain **voltdms)
457{
458 struct voltagedomain **v;
459
460 if (voltdms) {
461 for (v = voltdms; *v; v++)
462 _voltdm_register(*v);
463 }
464}
This page took 0.093873 seconds and 5 git commands to generate.