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;
49 u32 sys_clk_rate, timeout_val, waittime;
51 /* Divide to avoid overflow */
52 sys_clk_rate = voltdm->sys_clk.rate / 1000;
53 WARN_ON(!sys_clk_rate);
55 /* Generic voltage parameters */
56 vdd->volt_scale = omap_vp_forceupdate_scale;
57 voltdm->vp->enabled = false;
59 vdd->vp_rt_data.vpconfig_erroroffset =
60 (voltdm->pmic->vp_erroroffset <<
61 __ffs(voltdm->vp->common->vpconfig_erroroffset_mask));
63 timeout_val = (sys_clk_rate * voltdm->pmic->vp_timeout_us) / 1000;
64 vdd->vp_rt_data.vlimitto_timeout = timeout_val;
65 vdd->vp_rt_data.vlimitto_vddmin = voltdm->pmic->vp_vddmin;
66 vdd->vp_rt_data.vlimitto_vddmax = voltdm->pmic->vp_vddmax;
68 waittime = ((voltdm->pmic->step_size / voltdm->pmic->slew_rate) *
70 vdd->vp_rt_data.vstepmin_smpswaittimemin = waittime;
71 vdd->vp_rt_data.vstepmax_smpswaittimemax = waittime;
72 vdd->vp_rt_data.vstepmin_stepmin = voltdm->pmic->vp_vstepmin;
73 vdd->vp_rt_data.vstepmax_stepmax = voltdm->pmic->vp_vstepmax;
78 static int __init omap_vdd_data_configure(struct voltagedomain *voltdm)
83 pr_err("%s: PMIC info requried to configure vdd_%s not"
84 "populated.Hence cannot initialize vdd_%s\n",
85 __func__, voltdm->name, voltdm->name);
89 if (IS_ERR_VALUE(_config_common_vdd_data(voltdm)))
98 /* Public functions */
100 * omap_voltage_get_nom_volt() - Gets the current non-auto-compensated voltage
101 * @voltdm: pointer to the VDD for which current voltage info is needed
103 * API to get the current non-auto-compensated voltage for a VDD.
104 * Returns 0 in case of error else returns the current voltage for the VDD.
106 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm)
108 struct omap_vdd_info *vdd;
110 if (!voltdm || IS_ERR(voltdm)) {
111 pr_warning("%s: VDD specified does not exist!\n", __func__);
117 return vdd->curr_volt;
121 * omap_voltage_scale_vdd() - API to scale voltage of a particular
123 * @voltdm: pointer to the VDD which is to be scaled.
124 * @target_volt: The target voltage of the voltage domain
126 * This API should be called by the kernel to do the voltage scaling
127 * for a particular voltage domain during dvfs or any other situation.
129 int omap_voltage_scale_vdd(struct voltagedomain *voltdm,
130 unsigned long target_volt)
132 struct omap_vdd_info *vdd;
134 if (!voltdm || IS_ERR(voltdm)) {
135 pr_warning("%s: VDD specified does not exist!\n", __func__);
141 if (!vdd->volt_scale) {
142 pr_err("%s: No voltage scale API registered for vdd_%s\n",
143 __func__, voltdm->name);
147 return vdd->volt_scale(voltdm, target_volt);
151 * omap_voltage_reset() - Resets the voltage of a particular voltage domain
152 * to that of the current OPP.
153 * @voltdm: pointer to the VDD whose voltage is to be reset.
155 * This API finds out the correct voltage the voltage domain is supposed
156 * to be at and resets the voltage to that level. Should be used especially
157 * while disabling any voltage compensation modules.
159 void omap_voltage_reset(struct voltagedomain *voltdm)
161 unsigned long target_uvdc;
163 if (!voltdm || IS_ERR(voltdm)) {
164 pr_warning("%s: VDD specified does not exist!\n", __func__);
168 target_uvdc = omap_voltage_get_nom_volt(voltdm);
170 pr_err("%s: unable to find current voltage for vdd_%s\n",
171 __func__, voltdm->name);
175 omap_voltage_scale_vdd(voltdm, target_uvdc);
179 * omap_voltage_get_volttable() - API to get the voltage table associated with a
180 * particular voltage domain.
181 * @voltdm: pointer to the VDD for which the voltage table is required
182 * @volt_data: the voltage table for the particular vdd which is to be
183 * populated by this API
185 * This API populates the voltage table associated with a VDD into the
186 * passed parameter pointer. Returns the count of distinct voltages
187 * supported by this vdd.
190 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
191 struct omap_volt_data **volt_data)
193 struct omap_vdd_info *vdd;
195 if (!voltdm || IS_ERR(voltdm)) {
196 pr_warning("%s: VDD specified does not exist!\n", __func__);
202 *volt_data = vdd->volt_data;
206 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
208 * @voltdm: pointer to the VDD whose voltage table has to be searched
209 * @volt: the voltage to be searched in the voltage table
211 * This API searches through the voltage table for the required voltage
212 * domain and tries to find a matching entry for the passed voltage volt.
213 * If a matching entry is found volt_data is populated with that entry.
214 * This API searches only through the non-compensated voltages int the
216 * Returns pointer to the voltage table entry corresponding to volt on
217 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
218 * domain or if there is no matching entry.
220 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
223 struct omap_vdd_info *vdd;
226 if (!voltdm || IS_ERR(voltdm)) {
227 pr_warning("%s: VDD specified does not exist!\n", __func__);
228 return ERR_PTR(-EINVAL);
233 if (!vdd->volt_data) {
234 pr_warning("%s: voltage table does not exist for vdd_%s\n",
235 __func__, voltdm->name);
236 return ERR_PTR(-ENODATA);
239 for (i = 0; vdd->volt_data[i].volt_nominal != 0; i++) {
240 if (vdd->volt_data[i].volt_nominal == volt)
241 return &vdd->volt_data[i];
244 pr_notice("%s: Unable to match the current voltage with the voltage"
245 "table for vdd_%s\n", __func__, voltdm->name);
247 return ERR_PTR(-ENODATA);
251 * omap_voltage_register_pmic() - API to register PMIC specific data
252 * @voltdm: pointer to the VDD for which the PMIC specific data is
254 * @pmic: the structure containing pmic info
256 * This API is to be called by the SOC/PMIC file to specify the
257 * pmic specific info as present in omap_voltdm_pmic structure.
259 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
260 struct omap_voltdm_pmic *pmic)
262 if (!voltdm || IS_ERR(voltdm)) {
263 pr_warning("%s: VDD specified does not exist!\n", __func__);
273 * omap_change_voltscale_method() - API to change the voltage scaling method.
274 * @voltdm: pointer to the VDD whose voltage scaling method
276 * @voltscale_method: the method to be used for voltage scaling.
278 * This API can be used by the board files to change the method of voltage
279 * scaling between vpforceupdate and vcbypass. The parameter values are
280 * defined in voltage.h
282 void omap_change_voltscale_method(struct voltagedomain *voltdm,
283 int voltscale_method)
285 struct omap_vdd_info *vdd;
287 if (!voltdm || IS_ERR(voltdm)) {
288 pr_warning("%s: VDD specified does not exist!\n", __func__);
294 switch (voltscale_method) {
295 case VOLTSCALE_VPFORCEUPDATE:
296 vdd->volt_scale = omap_vp_forceupdate_scale;
298 case VOLTSCALE_VCBYPASS:
299 vdd->volt_scale = omap_vc_bypass_scale;
302 pr_warning("%s: Trying to change the method of voltage scaling"
303 "to an unsupported one!\n", __func__);
308 * omap_voltage_late_init() - Init the various voltage parameters
310 * This API is to be called in the later stages of the
311 * system boot to init the voltage controller and
312 * voltage processors.
314 int __init omap_voltage_late_init(void)
316 struct voltagedomain *voltdm;
318 if (list_empty(&voltdm_list)) {
319 pr_err("%s: Voltage driver support not added\n",
324 list_for_each_entry(voltdm, &voltdm_list, node) {
327 if (!voltdm->scalable)
330 sys_ck = clk_get(NULL, voltdm->sys_clk.name);
331 if (IS_ERR(sys_ck)) {
332 pr_warning("%s: Could not get sys clk.\n", __func__);
335 voltdm->sys_clk.rate = clk_get_rate(sys_ck);
336 WARN_ON(!voltdm->sys_clk.rate);
340 voltdm->vdd->volt_scale = omap_vc_bypass_scale;
341 omap_vc_init_channel(voltdm);
345 if (omap_vdd_data_configure(voltdm))
347 omap_vp_init(voltdm);
354 static struct voltagedomain *_voltdm_lookup(const char *name)
356 struct voltagedomain *voltdm, *temp_voltdm;
360 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
361 if (!strcmp(name, temp_voltdm->name)) {
362 voltdm = temp_voltdm;
371 * voltdm_add_pwrdm - add a powerdomain to a voltagedomain
372 * @voltdm: struct voltagedomain * to add the powerdomain to
373 * @pwrdm: struct powerdomain * to associate with a voltagedomain
375 * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This
376 * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if
377 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
380 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm)
382 if (!voltdm || !pwrdm)
385 pr_debug("voltagedomain: associating powerdomain %s with voltagedomain "
386 "%s\n", pwrdm->name, voltdm->name);
388 list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list);
394 * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
395 * @voltdm: struct voltagedomain * to iterate over
396 * @fn: callback function *
398 * Call the supplied function @fn for each powerdomain in the
399 * voltagedomain @voltdm. Returns -EINVAL if presented with invalid
400 * pointers; or passes along the last return value of the callback
401 * function, which should be 0 for success or anything else to
404 int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
405 int (*fn)(struct voltagedomain *voltdm,
406 struct powerdomain *pwrdm))
408 struct powerdomain *pwrdm;
414 list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node)
415 ret = (*fn)(voltdm, pwrdm);
421 * voltdm_for_each - call function on each registered voltagedomain
422 * @fn: callback function *
424 * Call the supplied function @fn for each registered voltagedomain.
425 * The callback function @fn can return anything but 0 to bail out
426 * early from the iterator. Returns the last return value of the
427 * callback function, which should be 0 for success or anything else
428 * to indicate failure; or -EINVAL if the function pointer is null.
430 int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
433 struct voltagedomain *temp_voltdm;
439 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
440 ret = (*fn)(temp_voltdm, user);
448 static int _voltdm_register(struct voltagedomain *voltdm)
450 if (!voltdm || !voltdm->name)
453 INIT_LIST_HEAD(&voltdm->pwrdm_list);
454 list_add(&voltdm->node, &voltdm_list);
456 pr_debug("voltagedomain: registered %s\n", voltdm->name);
462 * voltdm_lookup - look up a voltagedomain by name, return a pointer
463 * @name: name of voltagedomain
465 * Find a registered voltagedomain by its name @name. Returns a pointer
466 * to the struct voltagedomain if found, or NULL otherwise.
468 struct voltagedomain *voltdm_lookup(const char *name)
470 struct voltagedomain *voltdm ;
475 voltdm = _voltdm_lookup(name);
481 * voltdm_init - set up the voltagedomain layer
482 * @voltdm_list: array of struct voltagedomain pointers to register
484 * Loop through the array of voltagedomains @voltdm_list, registering all
485 * that are available on the current CPU. If voltdm_list is supplied
486 * and not null, all of the referenced voltagedomains will be
487 * registered. No return value.
489 void voltdm_init(struct voltagedomain **voltdms)
491 struct voltagedomain **v;
494 for (v = voltdms; *v; v++)
495 _voltdm_register(*v);