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 /* Public functions */
48 * voltdm_get_voltage() - Gets the current non-auto-compensated voltage
49 * @voltdm: pointer to the voltdm for which current voltage info is needed
51 * API to get the current non-auto-compensated voltage for a voltage domain.
52 * Returns 0 in case of error else returns the current voltage.
54 unsigned long voltdm_get_voltage(struct voltagedomain *voltdm)
56 if (!voltdm || IS_ERR(voltdm)) {
57 pr_warning("%s: VDD specified does not exist!\n", __func__);
61 return voltdm->nominal_volt;
65 * voltdm_scale() - API to scale voltage of a particular voltage domain.
66 * @voltdm: pointer to the voltage domain which is to be scaled.
67 * @target_volt: The target voltage of the voltage domain
69 * This API should be called by the kernel to do the voltage scaling
70 * for a particular voltage domain during DVFS.
72 int voltdm_scale(struct voltagedomain *voltdm,
73 unsigned long target_volt)
77 if (!voltdm || IS_ERR(voltdm)) {
78 pr_warning("%s: VDD specified does not exist!\n", __func__);
83 pr_err("%s: No voltage scale API registered for vdd_%s\n",
84 __func__, voltdm->name);
88 ret = voltdm->scale(voltdm, target_volt);
90 voltdm->nominal_volt = target_volt;
96 * voltdm_reset() - Resets the voltage of a particular voltage domain
97 * to that of the current OPP.
98 * @voltdm: pointer to the voltage domain whose voltage is to be reset.
100 * This API finds out the correct voltage the voltage domain is supposed
101 * to be at and resets the voltage to that level. Should be used especially
102 * while disabling any voltage compensation modules.
104 void voltdm_reset(struct voltagedomain *voltdm)
106 unsigned long target_volt;
108 if (!voltdm || IS_ERR(voltdm)) {
109 pr_warning("%s: VDD specified does not exist!\n", __func__);
113 target_volt = voltdm_get_voltage(voltdm);
115 pr_err("%s: unable to find current voltage for vdd_%s\n",
116 __func__, voltdm->name);
120 voltdm_scale(voltdm, target_volt);
124 * omap_voltage_get_volttable() - API to get the voltage table associated with a
125 * particular voltage domain.
126 * @voltdm: pointer to the VDD for which the voltage table is required
127 * @volt_data: the voltage table for the particular vdd which is to be
128 * populated by this API
130 * This API populates the voltage table associated with a VDD into the
131 * passed parameter pointer. Returns the count of distinct voltages
132 * supported by this vdd.
135 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
136 struct omap_volt_data **volt_data)
138 if (!voltdm || IS_ERR(voltdm)) {
139 pr_warning("%s: VDD specified does not exist!\n", __func__);
143 *volt_data = voltdm->volt_data;
147 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
149 * @voltdm: pointer to the VDD whose voltage table has to be searched
150 * @volt: the voltage to be searched in the voltage table
152 * This API searches through the voltage table for the required voltage
153 * domain and tries to find a matching entry for the passed voltage volt.
154 * If a matching entry is found volt_data is populated with that entry.
155 * This API searches only through the non-compensated voltages int the
157 * Returns pointer to the voltage table entry corresponding to volt on
158 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
159 * domain or if there is no matching entry.
161 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
166 if (!voltdm || IS_ERR(voltdm)) {
167 pr_warning("%s: VDD specified does not exist!\n", __func__);
168 return ERR_PTR(-EINVAL);
171 if (!voltdm->volt_data) {
172 pr_warning("%s: voltage table does not exist for vdd_%s\n",
173 __func__, voltdm->name);
174 return ERR_PTR(-ENODATA);
177 for (i = 0; voltdm->volt_data[i].volt_nominal != 0; i++) {
178 if (voltdm->volt_data[i].volt_nominal == volt)
179 return &voltdm->volt_data[i];
182 pr_notice("%s: Unable to match the current voltage with the voltage"
183 "table for vdd_%s\n", __func__, voltdm->name);
185 return ERR_PTR(-ENODATA);
189 * omap_voltage_register_pmic() - API to register PMIC specific data
190 * @voltdm: pointer to the VDD for which the PMIC specific data is
192 * @pmic: the structure containing pmic info
194 * This API is to be called by the SOC/PMIC file to specify the
195 * pmic specific info as present in omap_voltdm_pmic structure.
197 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
198 struct omap_voltdm_pmic *pmic)
200 if (!voltdm || IS_ERR(voltdm)) {
201 pr_warning("%s: VDD specified does not exist!\n", __func__);
211 * omap_change_voltscale_method() - API to change the voltage scaling method.
212 * @voltdm: pointer to the VDD whose voltage scaling method
214 * @voltscale_method: the method to be used for voltage scaling.
216 * This API can be used by the board files to change the method of voltage
217 * scaling between vpforceupdate and vcbypass. The parameter values are
218 * defined in voltage.h
220 void omap_change_voltscale_method(struct voltagedomain *voltdm,
221 int voltscale_method)
223 if (!voltdm || IS_ERR(voltdm)) {
224 pr_warning("%s: VDD specified does not exist!\n", __func__);
228 switch (voltscale_method) {
229 case VOLTSCALE_VPFORCEUPDATE:
230 voltdm->scale = omap_vp_forceupdate_scale;
232 case VOLTSCALE_VCBYPASS:
233 voltdm->scale = omap_vc_bypass_scale;
236 pr_warning("%s: Trying to change the method of voltage scaling"
237 "to an unsupported one!\n", __func__);
242 * omap_voltage_late_init() - Init the various voltage parameters
244 * This API is to be called in the later stages of the
245 * system boot to init the voltage controller and
246 * voltage processors.
248 int __init omap_voltage_late_init(void)
250 struct voltagedomain *voltdm;
252 if (list_empty(&voltdm_list)) {
253 pr_err("%s: Voltage driver support not added\n",
258 list_for_each_entry(voltdm, &voltdm_list, node) {
261 if (!voltdm->scalable)
264 sys_ck = clk_get(NULL, voltdm->sys_clk.name);
265 if (IS_ERR(sys_ck)) {
266 pr_warning("%s: Could not get sys clk.\n", __func__);
269 voltdm->sys_clk.rate = clk_get_rate(sys_ck);
270 WARN_ON(!voltdm->sys_clk.rate);
274 voltdm->scale = omap_vc_bypass_scale;
275 omap_vc_init_channel(voltdm);
279 voltdm->scale = omap_vp_forceupdate_scale;
280 omap_vp_init(voltdm);
287 static struct voltagedomain *_voltdm_lookup(const char *name)
289 struct voltagedomain *voltdm, *temp_voltdm;
293 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
294 if (!strcmp(name, temp_voltdm->name)) {
295 voltdm = temp_voltdm;
304 * voltdm_add_pwrdm - add a powerdomain to a voltagedomain
305 * @voltdm: struct voltagedomain * to add the powerdomain to
306 * @pwrdm: struct powerdomain * to associate with a voltagedomain
308 * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This
309 * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if
310 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
313 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm)
315 if (!voltdm || !pwrdm)
318 pr_debug("voltagedomain: associating powerdomain %s with voltagedomain "
319 "%s\n", pwrdm->name, voltdm->name);
321 list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list);
327 * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
328 * @voltdm: struct voltagedomain * to iterate over
329 * @fn: callback function *
331 * Call the supplied function @fn for each powerdomain in the
332 * voltagedomain @voltdm. Returns -EINVAL if presented with invalid
333 * pointers; or passes along the last return value of the callback
334 * function, which should be 0 for success or anything else to
337 int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
338 int (*fn)(struct voltagedomain *voltdm,
339 struct powerdomain *pwrdm))
341 struct powerdomain *pwrdm;
347 list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node)
348 ret = (*fn)(voltdm, pwrdm);
354 * voltdm_for_each - call function on each registered voltagedomain
355 * @fn: callback function *
357 * Call the supplied function @fn for each registered voltagedomain.
358 * The callback function @fn can return anything but 0 to bail out
359 * early from the iterator. Returns the last return value of the
360 * callback function, which should be 0 for success or anything else
361 * to indicate failure; or -EINVAL if the function pointer is null.
363 int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
366 struct voltagedomain *temp_voltdm;
372 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
373 ret = (*fn)(temp_voltdm, user);
381 static int _voltdm_register(struct voltagedomain *voltdm)
383 if (!voltdm || !voltdm->name)
386 INIT_LIST_HEAD(&voltdm->pwrdm_list);
387 list_add(&voltdm->node, &voltdm_list);
389 pr_debug("voltagedomain: registered %s\n", voltdm->name);
395 * voltdm_lookup - look up a voltagedomain by name, return a pointer
396 * @name: name of voltagedomain
398 * Find a registered voltagedomain by its name @name. Returns a pointer
399 * to the struct voltagedomain if found, or NULL otherwise.
401 struct voltagedomain *voltdm_lookup(const char *name)
403 struct voltagedomain *voltdm ;
408 voltdm = _voltdm_lookup(name);
414 * voltdm_init - set up the voltagedomain layer
415 * @voltdm_list: array of struct voltagedomain pointers to register
417 * Loop through the array of voltagedomains @voltdm_list, registering all
418 * that are available on the current CPU. If voltdm_list is supplied
419 * and not null, all of the referenced voltagedomains will be
420 * registered. No return value.
422 void voltdm_init(struct voltagedomain **voltdms)
424 struct voltagedomain **v;
427 for (v = voltdms; *v; v++)
428 _voltdm_register(*v);