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 return voltdm->scale(voltdm, target_volt);
92 * voltdm_reset() - Resets the voltage of a particular voltage domain
93 * to that of the current OPP.
94 * @voltdm: pointer to the voltage domain whose voltage is to be reset.
96 * This API finds out the correct voltage the voltage domain is supposed
97 * to be at and resets the voltage to that level. Should be used especially
98 * while disabling any voltage compensation modules.
100 void voltdm_reset(struct voltagedomain *voltdm)
102 unsigned long target_volt;
104 if (!voltdm || IS_ERR(voltdm)) {
105 pr_warning("%s: VDD specified does not exist!\n", __func__);
109 target_volt = voltdm_get_voltage(voltdm);
111 pr_err("%s: unable to find current voltage for vdd_%s\n",
112 __func__, voltdm->name);
116 voltdm_scale(voltdm, target_volt);
120 * omap_voltage_get_volttable() - API to get the voltage table associated with a
121 * particular voltage domain.
122 * @voltdm: pointer to the VDD for which the voltage table is required
123 * @volt_data: the voltage table for the particular vdd which is to be
124 * populated by this API
126 * This API populates the voltage table associated with a VDD into the
127 * passed parameter pointer. Returns the count of distinct voltages
128 * supported by this vdd.
131 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
132 struct omap_volt_data **volt_data)
134 if (!voltdm || IS_ERR(voltdm)) {
135 pr_warning("%s: VDD specified does not exist!\n", __func__);
139 *volt_data = voltdm->volt_data;
143 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
145 * @voltdm: pointer to the VDD whose voltage table has to be searched
146 * @volt: the voltage to be searched in the voltage table
148 * This API searches through the voltage table for the required voltage
149 * domain and tries to find a matching entry for the passed voltage volt.
150 * If a matching entry is found volt_data is populated with that entry.
151 * This API searches only through the non-compensated voltages int the
153 * Returns pointer to the voltage table entry corresponding to volt on
154 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
155 * domain or if there is no matching entry.
157 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
162 if (!voltdm || IS_ERR(voltdm)) {
163 pr_warning("%s: VDD specified does not exist!\n", __func__);
164 return ERR_PTR(-EINVAL);
167 if (!voltdm->volt_data) {
168 pr_warning("%s: voltage table does not exist for vdd_%s\n",
169 __func__, voltdm->name);
170 return ERR_PTR(-ENODATA);
173 for (i = 0; voltdm->volt_data[i].volt_nominal != 0; i++) {
174 if (voltdm->volt_data[i].volt_nominal == volt)
175 return &voltdm->volt_data[i];
178 pr_notice("%s: Unable to match the current voltage with the voltage"
179 "table for vdd_%s\n", __func__, voltdm->name);
181 return ERR_PTR(-ENODATA);
185 * omap_voltage_register_pmic() - API to register PMIC specific data
186 * @voltdm: pointer to the VDD for which the PMIC specific data is
188 * @pmic: the structure containing pmic info
190 * This API is to be called by the SOC/PMIC file to specify the
191 * pmic specific info as present in omap_voltdm_pmic structure.
193 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
194 struct omap_voltdm_pmic *pmic)
196 if (!voltdm || IS_ERR(voltdm)) {
197 pr_warning("%s: VDD specified does not exist!\n", __func__);
207 * omap_change_voltscale_method() - API to change the voltage scaling method.
208 * @voltdm: pointer to the VDD whose voltage scaling method
210 * @voltscale_method: the method to be used for voltage scaling.
212 * This API can be used by the board files to change the method of voltage
213 * scaling between vpforceupdate and vcbypass. The parameter values are
214 * defined in voltage.h
216 void omap_change_voltscale_method(struct voltagedomain *voltdm,
217 int voltscale_method)
219 if (!voltdm || IS_ERR(voltdm)) {
220 pr_warning("%s: VDD specified does not exist!\n", __func__);
224 switch (voltscale_method) {
225 case VOLTSCALE_VPFORCEUPDATE:
226 voltdm->scale = omap_vp_forceupdate_scale;
228 case VOLTSCALE_VCBYPASS:
229 voltdm->scale = omap_vc_bypass_scale;
232 pr_warning("%s: Trying to change the method of voltage scaling"
233 "to an unsupported one!\n", __func__);
238 * omap_voltage_late_init() - Init the various voltage parameters
240 * This API is to be called in the later stages of the
241 * system boot to init the voltage controller and
242 * voltage processors.
244 int __init omap_voltage_late_init(void)
246 struct voltagedomain *voltdm;
248 if (list_empty(&voltdm_list)) {
249 pr_err("%s: Voltage driver support not added\n",
254 list_for_each_entry(voltdm, &voltdm_list, node) {
257 if (!voltdm->scalable)
260 sys_ck = clk_get(NULL, voltdm->sys_clk.name);
261 if (IS_ERR(sys_ck)) {
262 pr_warning("%s: Could not get sys clk.\n", __func__);
265 voltdm->sys_clk.rate = clk_get_rate(sys_ck);
266 WARN_ON(!voltdm->sys_clk.rate);
270 voltdm->scale = omap_vc_bypass_scale;
271 omap_vc_init_channel(voltdm);
275 voltdm->scale = omap_vp_forceupdate_scale;
276 omap_vp_init(voltdm);
283 static struct voltagedomain *_voltdm_lookup(const char *name)
285 struct voltagedomain *voltdm, *temp_voltdm;
289 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
290 if (!strcmp(name, temp_voltdm->name)) {
291 voltdm = temp_voltdm;
300 * voltdm_add_pwrdm - add a powerdomain to a voltagedomain
301 * @voltdm: struct voltagedomain * to add the powerdomain to
302 * @pwrdm: struct powerdomain * to associate with a voltagedomain
304 * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This
305 * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if
306 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
309 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm)
311 if (!voltdm || !pwrdm)
314 pr_debug("voltagedomain: associating powerdomain %s with voltagedomain "
315 "%s\n", pwrdm->name, voltdm->name);
317 list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list);
323 * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
324 * @voltdm: struct voltagedomain * to iterate over
325 * @fn: callback function *
327 * Call the supplied function @fn for each powerdomain in the
328 * voltagedomain @voltdm. Returns -EINVAL if presented with invalid
329 * pointers; or passes along the last return value of the callback
330 * function, which should be 0 for success or anything else to
333 int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
334 int (*fn)(struct voltagedomain *voltdm,
335 struct powerdomain *pwrdm))
337 struct powerdomain *pwrdm;
343 list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node)
344 ret = (*fn)(voltdm, pwrdm);
350 * voltdm_for_each - call function on each registered voltagedomain
351 * @fn: callback function *
353 * Call the supplied function @fn for each registered voltagedomain.
354 * The callback function @fn can return anything but 0 to bail out
355 * early from the iterator. Returns the last return value of the
356 * callback function, which should be 0 for success or anything else
357 * to indicate failure; or -EINVAL if the function pointer is null.
359 int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
362 struct voltagedomain *temp_voltdm;
368 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
369 ret = (*fn)(temp_voltdm, user);
377 static int _voltdm_register(struct voltagedomain *voltdm)
379 if (!voltdm || !voltdm->name)
382 INIT_LIST_HEAD(&voltdm->pwrdm_list);
383 list_add(&voltdm->node, &voltdm_list);
385 pr_debug("voltagedomain: registered %s\n", voltdm->name);
391 * voltdm_lookup - look up a voltagedomain by name, return a pointer
392 * @name: name of voltagedomain
394 * Find a registered voltagedomain by its name @name. Returns a pointer
395 * to the struct voltagedomain if found, or NULL otherwise.
397 struct voltagedomain *voltdm_lookup(const char *name)
399 struct voltagedomain *voltdm ;
404 voltdm = _voltdm_lookup(name);
410 * voltdm_init - set up the voltagedomain layer
411 * @voltdm_list: array of struct voltagedomain pointers to register
413 * Loop through the array of voltagedomains @voltdm_list, registering all
414 * that are available on the current CPU. If voltdm_list is supplied
415 * and not null, all of the referenced voltagedomains will be
416 * registered. No return value.
418 void voltdm_init(struct voltagedomain **voltdms)
420 struct voltagedomain **v;
423 for (v = voltdms; *v; v++)
424 _voltdm_register(*v);