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 * omap_voltage_scale_vdd() - API to scale voltage of a particular
99 * @voltdm: pointer to the VDD which is to be scaled.
100 * @target_volt: The target voltage of the voltage domain
102 * This API should be called by the kernel to do the voltage scaling
103 * for a particular voltage domain during dvfs or any other situation.
105 int omap_voltage_scale_vdd(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 if (!voltdm->scale) {
114 pr_err("%s: No voltage scale API registered for vdd_%s\n",
115 __func__, voltdm->name);
119 return voltdm->scale(voltdm, target_volt);
123 * omap_voltage_reset() - Resets the voltage of a particular voltage domain
124 * to that of the current OPP.
125 * @voltdm: pointer to the VDD whose voltage is to be reset.
127 * This API finds out the correct voltage the voltage domain is supposed
128 * to be at and resets the voltage to that level. Should be used especially
129 * while disabling any voltage compensation modules.
131 void omap_voltage_reset(struct voltagedomain *voltdm)
133 unsigned long target_uvdc;
135 if (!voltdm || IS_ERR(voltdm)) {
136 pr_warning("%s: VDD specified does not exist!\n", __func__);
140 target_uvdc = omap_voltage_get_nom_volt(voltdm);
142 pr_err("%s: unable to find current voltage for vdd_%s\n",
143 __func__, voltdm->name);
147 omap_voltage_scale_vdd(voltdm, target_uvdc);
151 * omap_voltage_get_volttable() - API to get the voltage table associated with a
152 * particular voltage domain.
153 * @voltdm: pointer to the VDD for which the voltage table is required
154 * @volt_data: the voltage table for the particular vdd which is to be
155 * populated by this API
157 * This API populates the voltage table associated with a VDD into the
158 * passed parameter pointer. Returns the count of distinct voltages
159 * supported by this vdd.
162 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
163 struct omap_volt_data **volt_data)
165 struct omap_vdd_info *vdd;
167 if (!voltdm || IS_ERR(voltdm)) {
168 pr_warning("%s: VDD specified does not exist!\n", __func__);
174 *volt_data = vdd->volt_data;
178 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
180 * @voltdm: pointer to the VDD whose voltage table has to be searched
181 * @volt: the voltage to be searched in the voltage table
183 * This API searches through the voltage table for the required voltage
184 * domain and tries to find a matching entry for the passed voltage volt.
185 * If a matching entry is found volt_data is populated with that entry.
186 * This API searches only through the non-compensated voltages int the
188 * Returns pointer to the voltage table entry corresponding to volt on
189 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
190 * domain or if there is no matching entry.
192 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
195 struct omap_vdd_info *vdd;
198 if (!voltdm || IS_ERR(voltdm)) {
199 pr_warning("%s: VDD specified does not exist!\n", __func__);
200 return ERR_PTR(-EINVAL);
205 if (!vdd->volt_data) {
206 pr_warning("%s: voltage table does not exist for vdd_%s\n",
207 __func__, voltdm->name);
208 return ERR_PTR(-ENODATA);
211 for (i = 0; vdd->volt_data[i].volt_nominal != 0; i++) {
212 if (vdd->volt_data[i].volt_nominal == volt)
213 return &vdd->volt_data[i];
216 pr_notice("%s: Unable to match the current voltage with the voltage"
217 "table for vdd_%s\n", __func__, voltdm->name);
219 return ERR_PTR(-ENODATA);
223 * omap_voltage_register_pmic() - API to register PMIC specific data
224 * @voltdm: pointer to the VDD for which the PMIC specific data is
226 * @pmic: the structure containing pmic info
228 * This API is to be called by the SOC/PMIC file to specify the
229 * pmic specific info as present in omap_voltdm_pmic structure.
231 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
232 struct omap_voltdm_pmic *pmic)
234 if (!voltdm || IS_ERR(voltdm)) {
235 pr_warning("%s: VDD specified does not exist!\n", __func__);
245 * omap_change_voltscale_method() - API to change the voltage scaling method.
246 * @voltdm: pointer to the VDD whose voltage scaling method
248 * @voltscale_method: the method to be used for voltage scaling.
250 * This API can be used by the board files to change the method of voltage
251 * scaling between vpforceupdate and vcbypass. The parameter values are
252 * defined in voltage.h
254 void omap_change_voltscale_method(struct voltagedomain *voltdm,
255 int voltscale_method)
257 if (!voltdm || IS_ERR(voltdm)) {
258 pr_warning("%s: VDD specified does not exist!\n", __func__);
262 switch (voltscale_method) {
263 case VOLTSCALE_VPFORCEUPDATE:
264 voltdm->scale = omap_vp_forceupdate_scale;
266 case VOLTSCALE_VCBYPASS:
267 voltdm->scale = omap_vc_bypass_scale;
270 pr_warning("%s: Trying to change the method of voltage scaling"
271 "to an unsupported one!\n", __func__);
276 * omap_voltage_late_init() - Init the various voltage parameters
278 * This API is to be called in the later stages of the
279 * system boot to init the voltage controller and
280 * voltage processors.
282 int __init omap_voltage_late_init(void)
284 struct voltagedomain *voltdm;
286 if (list_empty(&voltdm_list)) {
287 pr_err("%s: Voltage driver support not added\n",
292 list_for_each_entry(voltdm, &voltdm_list, node) {
295 if (!voltdm->scalable)
298 sys_ck = clk_get(NULL, voltdm->sys_clk.name);
299 if (IS_ERR(sys_ck)) {
300 pr_warning("%s: Could not get sys clk.\n", __func__);
303 voltdm->sys_clk.rate = clk_get_rate(sys_ck);
304 WARN_ON(!voltdm->sys_clk.rate);
308 voltdm->scale = omap_vc_bypass_scale;
309 omap_vc_init_channel(voltdm);
313 if (omap_vdd_data_configure(voltdm))
315 omap_vp_init(voltdm);
322 static struct voltagedomain *_voltdm_lookup(const char *name)
324 struct voltagedomain *voltdm, *temp_voltdm;
328 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
329 if (!strcmp(name, temp_voltdm->name)) {
330 voltdm = temp_voltdm;
339 * voltdm_add_pwrdm - add a powerdomain to a voltagedomain
340 * @voltdm: struct voltagedomain * to add the powerdomain to
341 * @pwrdm: struct powerdomain * to associate with a voltagedomain
343 * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This
344 * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if
345 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
348 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm)
350 if (!voltdm || !pwrdm)
353 pr_debug("voltagedomain: associating powerdomain %s with voltagedomain "
354 "%s\n", pwrdm->name, voltdm->name);
356 list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list);
362 * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
363 * @voltdm: struct voltagedomain * to iterate over
364 * @fn: callback function *
366 * Call the supplied function @fn for each powerdomain in the
367 * voltagedomain @voltdm. Returns -EINVAL if presented with invalid
368 * pointers; or passes along the last return value of the callback
369 * function, which should be 0 for success or anything else to
372 int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
373 int (*fn)(struct voltagedomain *voltdm,
374 struct powerdomain *pwrdm))
376 struct powerdomain *pwrdm;
382 list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node)
383 ret = (*fn)(voltdm, pwrdm);
389 * voltdm_for_each - call function on each registered voltagedomain
390 * @fn: callback function *
392 * Call the supplied function @fn for each registered voltagedomain.
393 * The callback function @fn can return anything but 0 to bail out
394 * early from the iterator. Returns the last return value of the
395 * callback function, which should be 0 for success or anything else
396 * to indicate failure; or -EINVAL if the function pointer is null.
398 int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
401 struct voltagedomain *temp_voltdm;
407 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
408 ret = (*fn)(temp_voltdm, user);
416 static int _voltdm_register(struct voltagedomain *voltdm)
418 if (!voltdm || !voltdm->name)
421 INIT_LIST_HEAD(&voltdm->pwrdm_list);
422 list_add(&voltdm->node, &voltdm_list);
424 pr_debug("voltagedomain: registered %s\n", voltdm->name);
430 * voltdm_lookup - look up a voltagedomain by name, return a pointer
431 * @name: name of voltagedomain
433 * Find a registered voltagedomain by its name @name. Returns a pointer
434 * to the struct voltagedomain if found, or NULL otherwise.
436 struct voltagedomain *voltdm_lookup(const char *name)
438 struct voltagedomain *voltdm ;
443 voltdm = _voltdm_lookup(name);
449 * voltdm_init - set up the voltagedomain layer
450 * @voltdm_list: array of struct voltagedomain pointers to register
452 * Loop through the array of voltagedomains @voltdm_list, registering all
453 * that are available on the current CPU. If voltdm_list is supplied
454 * and not null, all of the referenced voltagedomains will be
455 * registered. No return value.
457 void voltdm_init(struct voltagedomain **voltdms)
459 struct voltagedomain **v;
462 for (v = voltdms; *v; v++)
463 _voltdm_register(*v);