2 * OMAP3/OMAP4 Voltage Management Routines
4 * Author: Thara Gopinath <thara@ti.com>
6 * Copyright (C) 2007 Texas Instruments, Inc.
7 * Rajendra Nayak <rnayak@ti.com>
8 * Lesly A M <x0080970@ti.com>
10 * Copyright (C) 2008, 2011 Nokia Corporation
14 * Copyright (C) 2010 Texas Instruments, Inc.
15 * Thara Gopinath <thara@ti.com>
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.
22 #include <linux/delay.h>
24 #include <linux/err.h>
25 #include <linux/debugfs.h>
26 #include <linux/slab.h>
27 #include <linux/clk.h>
29 #include <plat/common.h>
31 #include "prm-regbits-34xx.h"
32 #include "prm-regbits-44xx.h"
35 #include "prminst44xx.h"
39 #include "powerdomain.h"
44 static LIST_HEAD(voltdm_list);
46 static int __init _config_common_vdd_data(struct voltagedomain *voltdm)
48 struct omap_vdd_info *vdd = voltdm->vdd;
50 /* Generic voltage parameters */
51 vdd->volt_scale = omap_vp_forceupdate_scale;
56 static int __init omap_vdd_data_configure(struct voltagedomain *voltdm)
61 pr_err("%s: PMIC info requried to configure vdd_%s not"
62 "populated.Hence cannot initialize vdd_%s\n",
63 __func__, voltdm->name, voltdm->name);
67 if (IS_ERR_VALUE(_config_common_vdd_data(voltdm)))
76 /* Public functions */
78 * omap_voltage_get_nom_volt() - Gets the current non-auto-compensated voltage
79 * @voltdm: pointer to the VDD for which current voltage info is needed
81 * API to get the current non-auto-compensated voltage for a VDD.
82 * Returns 0 in case of error else returns the current voltage for the VDD.
84 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm)
86 struct omap_vdd_info *vdd;
88 if (!voltdm || IS_ERR(voltdm)) {
89 pr_warning("%s: VDD specified does not exist!\n", __func__);
95 return vdd->curr_volt;
99 * omap_voltage_scale_vdd() - API to scale voltage of a particular
101 * @voltdm: pointer to the VDD which is to be scaled.
102 * @target_volt: The target voltage of the voltage domain
104 * This API should be called by the kernel to do the voltage scaling
105 * for a particular voltage domain during dvfs or any other situation.
107 int omap_voltage_scale_vdd(struct voltagedomain *voltdm,
108 unsigned long target_volt)
110 struct omap_vdd_info *vdd;
112 if (!voltdm || IS_ERR(voltdm)) {
113 pr_warning("%s: VDD specified does not exist!\n", __func__);
119 if (!vdd->volt_scale) {
120 pr_err("%s: No voltage scale API registered for vdd_%s\n",
121 __func__, voltdm->name);
125 return vdd->volt_scale(voltdm, target_volt);
129 * omap_voltage_reset() - Resets the voltage of a particular voltage domain
130 * to that of the current OPP.
131 * @voltdm: pointer to the VDD whose voltage is to be reset.
133 * This API finds out the correct voltage the voltage domain is supposed
134 * to be at and resets the voltage to that level. Should be used especially
135 * while disabling any voltage compensation modules.
137 void omap_voltage_reset(struct voltagedomain *voltdm)
139 unsigned long target_uvdc;
141 if (!voltdm || IS_ERR(voltdm)) {
142 pr_warning("%s: VDD specified does not exist!\n", __func__);
146 target_uvdc = omap_voltage_get_nom_volt(voltdm);
148 pr_err("%s: unable to find current voltage for vdd_%s\n",
149 __func__, voltdm->name);
153 omap_voltage_scale_vdd(voltdm, target_uvdc);
157 * omap_voltage_get_volttable() - API to get the voltage table associated with a
158 * particular voltage domain.
159 * @voltdm: pointer to the VDD for which the voltage table is required
160 * @volt_data: the voltage table for the particular vdd which is to be
161 * populated by this API
163 * This API populates the voltage table associated with a VDD into the
164 * passed parameter pointer. Returns the count of distinct voltages
165 * supported by this vdd.
168 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
169 struct omap_volt_data **volt_data)
171 struct omap_vdd_info *vdd;
173 if (!voltdm || IS_ERR(voltdm)) {
174 pr_warning("%s: VDD specified does not exist!\n", __func__);
180 *volt_data = vdd->volt_data;
184 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
186 * @voltdm: pointer to the VDD whose voltage table has to be searched
187 * @volt: the voltage to be searched in the voltage table
189 * This API searches through the voltage table for the required voltage
190 * domain and tries to find a matching entry for the passed voltage volt.
191 * If a matching entry is found volt_data is populated with that entry.
192 * This API searches only through the non-compensated voltages int the
194 * Returns pointer to the voltage table entry corresponding to volt on
195 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
196 * domain or if there is no matching entry.
198 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
201 struct omap_vdd_info *vdd;
204 if (!voltdm || IS_ERR(voltdm)) {
205 pr_warning("%s: VDD specified does not exist!\n", __func__);
206 return ERR_PTR(-EINVAL);
211 if (!vdd->volt_data) {
212 pr_warning("%s: voltage table does not exist for vdd_%s\n",
213 __func__, voltdm->name);
214 return ERR_PTR(-ENODATA);
217 for (i = 0; vdd->volt_data[i].volt_nominal != 0; i++) {
218 if (vdd->volt_data[i].volt_nominal == volt)
219 return &vdd->volt_data[i];
222 pr_notice("%s: Unable to match the current voltage with the voltage"
223 "table for vdd_%s\n", __func__, voltdm->name);
225 return ERR_PTR(-ENODATA);
229 * omap_voltage_register_pmic() - API to register PMIC specific data
230 * @voltdm: pointer to the VDD for which the PMIC specific data is
232 * @pmic: the structure containing pmic info
234 * This API is to be called by the SOC/PMIC file to specify the
235 * pmic specific info as present in omap_voltdm_pmic structure.
237 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
238 struct omap_voltdm_pmic *pmic)
240 if (!voltdm || IS_ERR(voltdm)) {
241 pr_warning("%s: VDD specified does not exist!\n", __func__);
251 * omap_change_voltscale_method() - API to change the voltage scaling method.
252 * @voltdm: pointer to the VDD whose voltage scaling method
254 * @voltscale_method: the method to be used for voltage scaling.
256 * This API can be used by the board files to change the method of voltage
257 * scaling between vpforceupdate and vcbypass. The parameter values are
258 * defined in voltage.h
260 void omap_change_voltscale_method(struct voltagedomain *voltdm,
261 int voltscale_method)
263 struct omap_vdd_info *vdd;
265 if (!voltdm || IS_ERR(voltdm)) {
266 pr_warning("%s: VDD specified does not exist!\n", __func__);
272 switch (voltscale_method) {
273 case VOLTSCALE_VPFORCEUPDATE:
274 vdd->volt_scale = omap_vp_forceupdate_scale;
276 case VOLTSCALE_VCBYPASS:
277 vdd->volt_scale = omap_vc_bypass_scale;
280 pr_warning("%s: Trying to change the method of voltage scaling"
281 "to an unsupported one!\n", __func__);
286 * omap_voltage_late_init() - Init the various voltage parameters
288 * This API is to be called in the later stages of the
289 * system boot to init the voltage controller and
290 * voltage processors.
292 int __init omap_voltage_late_init(void)
294 struct voltagedomain *voltdm;
296 if (list_empty(&voltdm_list)) {
297 pr_err("%s: Voltage driver support not added\n",
302 list_for_each_entry(voltdm, &voltdm_list, node) {
305 if (!voltdm->scalable)
308 sys_ck = clk_get(NULL, voltdm->sys_clk.name);
309 if (IS_ERR(sys_ck)) {
310 pr_warning("%s: Could not get sys clk.\n", __func__);
313 voltdm->sys_clk.rate = clk_get_rate(sys_ck);
314 WARN_ON(!voltdm->sys_clk.rate);
318 voltdm->vdd->volt_scale = omap_vc_bypass_scale;
319 omap_vc_init_channel(voltdm);
323 if (omap_vdd_data_configure(voltdm))
325 omap_vp_init(voltdm);
332 static struct voltagedomain *_voltdm_lookup(const char *name)
334 struct voltagedomain *voltdm, *temp_voltdm;
338 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
339 if (!strcmp(name, temp_voltdm->name)) {
340 voltdm = temp_voltdm;
349 * voltdm_add_pwrdm - add a powerdomain to a voltagedomain
350 * @voltdm: struct voltagedomain * to add the powerdomain to
351 * @pwrdm: struct powerdomain * to associate with a voltagedomain
353 * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This
354 * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if
355 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
358 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm)
360 if (!voltdm || !pwrdm)
363 pr_debug("voltagedomain: associating powerdomain %s with voltagedomain "
364 "%s\n", pwrdm->name, voltdm->name);
366 list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list);
372 * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
373 * @voltdm: struct voltagedomain * to iterate over
374 * @fn: callback function *
376 * Call the supplied function @fn for each powerdomain in the
377 * voltagedomain @voltdm. Returns -EINVAL if presented with invalid
378 * pointers; or passes along the last return value of the callback
379 * function, which should be 0 for success or anything else to
382 int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
383 int (*fn)(struct voltagedomain *voltdm,
384 struct powerdomain *pwrdm))
386 struct powerdomain *pwrdm;
392 list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node)
393 ret = (*fn)(voltdm, pwrdm);
399 * voltdm_for_each - call function on each registered voltagedomain
400 * @fn: callback function *
402 * Call the supplied function @fn for each registered voltagedomain.
403 * The callback function @fn can return anything but 0 to bail out
404 * early from the iterator. Returns the last return value of the
405 * callback function, which should be 0 for success or anything else
406 * to indicate failure; or -EINVAL if the function pointer is null.
408 int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
411 struct voltagedomain *temp_voltdm;
417 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
418 ret = (*fn)(temp_voltdm, user);
426 static int _voltdm_register(struct voltagedomain *voltdm)
428 if (!voltdm || !voltdm->name)
431 INIT_LIST_HEAD(&voltdm->pwrdm_list);
432 list_add(&voltdm->node, &voltdm_list);
434 pr_debug("voltagedomain: registered %s\n", voltdm->name);
440 * voltdm_lookup - look up a voltagedomain by name, return a pointer
441 * @name: name of voltagedomain
443 * Find a registered voltagedomain by its name @name. Returns a pointer
444 * to the struct voltagedomain if found, or NULL otherwise.
446 struct voltagedomain *voltdm_lookup(const char *name)
448 struct voltagedomain *voltdm ;
453 voltdm = _voltdm_lookup(name);
459 * voltdm_init - set up the voltagedomain layer
460 * @voltdm_list: array of struct voltagedomain pointers to register
462 * Loop through the array of voltagedomains @voltdm_list, registering all
463 * that are available on the current CPU. If voltdm_list is supplied
464 * and not null, all of the referenced voltagedomains will be
465 * registered. No return value.
467 void voltdm_init(struct voltagedomain **voltdms)
469 struct voltagedomain **v;
472 for (v = voltdms; *v; v++)
473 _voltdm_register(*v);