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 /* Generic voltage parameters */
49 voltdm->scale = omap_vp_forceupdate_scale;
54 static int __init omap_vdd_data_configure(struct voltagedomain *voltdm)
59 pr_err("%s: PMIC info requried to configure vdd_%s not"
60 "populated.Hence cannot initialize vdd_%s\n",
61 __func__, voltdm->name, voltdm->name);
65 if (IS_ERR_VALUE(_config_common_vdd_data(voltdm)))
74 /* Public functions */
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
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.
82 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm)
84 struct omap_vdd_info *vdd;
86 if (!voltdm || IS_ERR(voltdm)) {
87 pr_warning("%s: VDD specified does not exist!\n", __func__);
93 return vdd->curr_volt;
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
101 * This API should be called by the kernel to do the voltage scaling
102 * for a particular voltage domain during DVFS.
104 int voltdm_scale(struct voltagedomain *voltdm,
105 unsigned long target_volt)
107 if (!voltdm || IS_ERR(voltdm)) {
108 pr_warning("%s: VDD specified does not exist!\n", __func__);
112 if (!voltdm->scale) {
113 pr_err("%s: No voltage scale API registered for vdd_%s\n",
114 __func__, voltdm->name);
118 return voltdm->scale(voltdm, target_volt);
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.
126 * This API finds out the correct voltage the voltage domain is supposed
127 * to be at and resets the voltage to that level. Should be used especially
128 * while disabling any voltage compensation modules.
130 void voltdm_reset(struct voltagedomain *voltdm)
132 unsigned long target_volt;
134 if (!voltdm || IS_ERR(voltdm)) {
135 pr_warning("%s: VDD specified does not exist!\n", __func__);
139 target_volt = omap_voltage_get_nom_volt(voltdm);
141 pr_err("%s: unable to find current voltage for vdd_%s\n",
142 __func__, voltdm->name);
146 voltdm_scale(voltdm, target_volt);
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
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.
161 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
162 struct omap_volt_data **volt_data)
164 struct omap_vdd_info *vdd;
166 if (!voltdm || IS_ERR(voltdm)) {
167 pr_warning("%s: VDD specified does not exist!\n", __func__);
173 *volt_data = vdd->volt_data;
177 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
179 * @voltdm: pointer to the VDD whose voltage table has to be searched
180 * @volt: the voltage to be searched in the voltage table
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
187 * Returns pointer to the voltage table entry corresponding to volt on
188 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
189 * domain or if there is no matching entry.
191 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
194 struct omap_vdd_info *vdd;
197 if (!voltdm || IS_ERR(voltdm)) {
198 pr_warning("%s: VDD specified does not exist!\n", __func__);
199 return ERR_PTR(-EINVAL);
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);
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];
215 pr_notice("%s: Unable to match the current voltage with the voltage"
216 "table for vdd_%s\n", __func__, voltdm->name);
218 return ERR_PTR(-ENODATA);
222 * omap_voltage_register_pmic() - API to register PMIC specific data
223 * @voltdm: pointer to the VDD for which the PMIC specific data is
225 * @pmic: the structure containing pmic info
227 * This API is to be called by the SOC/PMIC file to specify the
228 * pmic specific info as present in omap_voltdm_pmic structure.
230 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
231 struct omap_voltdm_pmic *pmic)
233 if (!voltdm || IS_ERR(voltdm)) {
234 pr_warning("%s: VDD specified does not exist!\n", __func__);
244 * omap_change_voltscale_method() - API to change the voltage scaling method.
245 * @voltdm: pointer to the VDD whose voltage scaling method
247 * @voltscale_method: the method to be used for voltage scaling.
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
253 void omap_change_voltscale_method(struct voltagedomain *voltdm,
254 int voltscale_method)
256 if (!voltdm || IS_ERR(voltdm)) {
257 pr_warning("%s: VDD specified does not exist!\n", __func__);
261 switch (voltscale_method) {
262 case VOLTSCALE_VPFORCEUPDATE:
263 voltdm->scale = omap_vp_forceupdate_scale;
265 case VOLTSCALE_VCBYPASS:
266 voltdm->scale = omap_vc_bypass_scale;
269 pr_warning("%s: Trying to change the method of voltage scaling"
270 "to an unsupported one!\n", __func__);
275 * omap_voltage_late_init() - Init the various voltage parameters
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.
281 int __init omap_voltage_late_init(void)
283 struct voltagedomain *voltdm;
285 if (list_empty(&voltdm_list)) {
286 pr_err("%s: Voltage driver support not added\n",
291 list_for_each_entry(voltdm, &voltdm_list, node) {
294 if (!voltdm->scalable)
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__);
302 voltdm->sys_clk.rate = clk_get_rate(sys_ck);
303 WARN_ON(!voltdm->sys_clk.rate);
307 voltdm->scale = omap_vc_bypass_scale;
308 omap_vc_init_channel(voltdm);
312 if (omap_vdd_data_configure(voltdm))
314 omap_vp_init(voltdm);
321 static struct voltagedomain *_voltdm_lookup(const char *name)
323 struct voltagedomain *voltdm, *temp_voltdm;
327 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
328 if (!strcmp(name, temp_voltdm->name)) {
329 voltdm = temp_voltdm;
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
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;
347 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm)
349 if (!voltdm || !pwrdm)
352 pr_debug("voltagedomain: associating powerdomain %s with voltagedomain "
353 "%s\n", pwrdm->name, voltdm->name);
355 list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list);
361 * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
362 * @voltdm: struct voltagedomain * to iterate over
363 * @fn: callback function *
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
371 int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
372 int (*fn)(struct voltagedomain *voltdm,
373 struct powerdomain *pwrdm))
375 struct powerdomain *pwrdm;
381 list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node)
382 ret = (*fn)(voltdm, pwrdm);
388 * voltdm_for_each - call function on each registered voltagedomain
389 * @fn: callback function *
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.
397 int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
400 struct voltagedomain *temp_voltdm;
406 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
407 ret = (*fn)(temp_voltdm, user);
415 static int _voltdm_register(struct voltagedomain *voltdm)
417 if (!voltdm || !voltdm->name)
420 INIT_LIST_HEAD(&voltdm->pwrdm_list);
421 list_add(&voltdm->node, &voltdm_list);
423 pr_debug("voltagedomain: registered %s\n", voltdm->name);
429 * voltdm_lookup - look up a voltagedomain by name, return a pointer
430 * @name: name of voltagedomain
432 * Find a registered voltagedomain by its name @name. Returns a pointer
433 * to the struct voltagedomain if found, or NULL otherwise.
435 struct voltagedomain *voltdm_lookup(const char *name)
437 struct voltagedomain *voltdm ;
442 voltdm = _voltdm_lookup(name);
448 * voltdm_init - set up the voltagedomain layer
449 * @voltdm_list: array of struct voltagedomain pointers to register
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.
456 void voltdm_init(struct voltagedomain **voltdms)
458 struct voltagedomain **v;
461 for (v = voltdms; *v; v++)
462 _voltdm_register(*v);