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/clk.h>
25 #include <linux/err.h>
26 #include <linux/debugfs.h>
27 #include <linux/slab.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)
50 u32 sys_clk_speed, timeout_val, waittime;
51 struct omap_vdd_info *vdd = voltdm->vdd;
54 * XXX Clockfw should handle this, or this should be in a
57 if (cpu_is_omap24xx() || cpu_is_omap34xx())
58 sys_ck_name = "sys_ck";
59 else if (cpu_is_omap44xx())
60 sys_ck_name = "sys_clkin_ck";
65 * Sys clk rate is require to calculate vp timeout value and
66 * smpswaittimemin and smpswaittimemax.
68 sys_ck = clk_get(NULL, sys_ck_name);
70 pr_warning("%s: Could not get the sys clk to calculate"
71 "various vdd_%s params\n", __func__, voltdm->name);
74 sys_clk_speed = clk_get_rate(sys_ck);
76 /* Divide to avoid overflow */
77 sys_clk_speed /= 1000;
79 /* Generic voltage parameters */
80 vdd->volt_scale = omap_vp_forceupdate_scale;
81 voltdm->vp->enabled = false;
83 vdd->vp_rt_data.vpconfig_erroroffset =
84 (voltdm->pmic->vp_erroroffset <<
85 __ffs(voltdm->vp->common->vpconfig_erroroffset_mask));
87 timeout_val = (sys_clk_speed * voltdm->pmic->vp_timeout_us) / 1000;
88 vdd->vp_rt_data.vlimitto_timeout = timeout_val;
89 vdd->vp_rt_data.vlimitto_vddmin = voltdm->pmic->vp_vddmin;
90 vdd->vp_rt_data.vlimitto_vddmax = voltdm->pmic->vp_vddmax;
92 waittime = ((voltdm->pmic->step_size / voltdm->pmic->slew_rate) *
93 sys_clk_speed) / 1000;
94 vdd->vp_rt_data.vstepmin_smpswaittimemin = waittime;
95 vdd->vp_rt_data.vstepmax_smpswaittimemax = waittime;
96 vdd->vp_rt_data.vstepmin_stepmin = voltdm->pmic->vp_vstepmin;
97 vdd->vp_rt_data.vstepmax_stepmax = voltdm->pmic->vp_vstepmax;
102 static int __init omap_vdd_data_configure(struct voltagedomain *voltdm)
107 pr_err("%s: PMIC info requried to configure vdd_%s not"
108 "populated.Hence cannot initialize vdd_%s\n",
109 __func__, voltdm->name, voltdm->name);
113 if (IS_ERR_VALUE(_config_common_vdd_data(voltdm)))
122 /* Public functions */
124 * omap_voltage_get_nom_volt() - Gets the current non-auto-compensated voltage
125 * @voltdm: pointer to the VDD for which current voltage info is needed
127 * API to get the current non-auto-compensated voltage for a VDD.
128 * Returns 0 in case of error else returns the current voltage for the VDD.
130 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm)
132 struct omap_vdd_info *vdd;
134 if (!voltdm || IS_ERR(voltdm)) {
135 pr_warning("%s: VDD specified does not exist!\n", __func__);
141 return vdd->curr_volt;
145 * omap_voltage_scale_vdd() - API to scale voltage of a particular
147 * @voltdm: pointer to the VDD which is to be scaled.
148 * @target_volt: The target voltage of the voltage domain
150 * This API should be called by the kernel to do the voltage scaling
151 * for a particular voltage domain during dvfs or any other situation.
153 int omap_voltage_scale_vdd(struct voltagedomain *voltdm,
154 unsigned long target_volt)
156 struct omap_vdd_info *vdd;
158 if (!voltdm || IS_ERR(voltdm)) {
159 pr_warning("%s: VDD specified does not exist!\n", __func__);
165 if (!vdd->volt_scale) {
166 pr_err("%s: No voltage scale API registered for vdd_%s\n",
167 __func__, voltdm->name);
171 return vdd->volt_scale(voltdm, target_volt);
175 * omap_voltage_reset() - Resets the voltage of a particular voltage domain
176 * to that of the current OPP.
177 * @voltdm: pointer to the VDD whose voltage is to be reset.
179 * This API finds out the correct voltage the voltage domain is supposed
180 * to be at and resets the voltage to that level. Should be used especially
181 * while disabling any voltage compensation modules.
183 void omap_voltage_reset(struct voltagedomain *voltdm)
185 unsigned long target_uvdc;
187 if (!voltdm || IS_ERR(voltdm)) {
188 pr_warning("%s: VDD specified does not exist!\n", __func__);
192 target_uvdc = omap_voltage_get_nom_volt(voltdm);
194 pr_err("%s: unable to find current voltage for vdd_%s\n",
195 __func__, voltdm->name);
199 omap_voltage_scale_vdd(voltdm, target_uvdc);
203 * omap_voltage_get_volttable() - API to get the voltage table associated with a
204 * particular voltage domain.
205 * @voltdm: pointer to the VDD for which the voltage table is required
206 * @volt_data: the voltage table for the particular vdd which is to be
207 * populated by this API
209 * This API populates the voltage table associated with a VDD into the
210 * passed parameter pointer. Returns the count of distinct voltages
211 * supported by this vdd.
214 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
215 struct omap_volt_data **volt_data)
217 struct omap_vdd_info *vdd;
219 if (!voltdm || IS_ERR(voltdm)) {
220 pr_warning("%s: VDD specified does not exist!\n", __func__);
226 *volt_data = vdd->volt_data;
230 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
232 * @voltdm: pointer to the VDD whose voltage table has to be searched
233 * @volt: the voltage to be searched in the voltage table
235 * This API searches through the voltage table for the required voltage
236 * domain and tries to find a matching entry for the passed voltage volt.
237 * If a matching entry is found volt_data is populated with that entry.
238 * This API searches only through the non-compensated voltages int the
240 * Returns pointer to the voltage table entry corresponding to volt on
241 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
242 * domain or if there is no matching entry.
244 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
247 struct omap_vdd_info *vdd;
250 if (!voltdm || IS_ERR(voltdm)) {
251 pr_warning("%s: VDD specified does not exist!\n", __func__);
252 return ERR_PTR(-EINVAL);
257 if (!vdd->volt_data) {
258 pr_warning("%s: voltage table does not exist for vdd_%s\n",
259 __func__, voltdm->name);
260 return ERR_PTR(-ENODATA);
263 for (i = 0; vdd->volt_data[i].volt_nominal != 0; i++) {
264 if (vdd->volt_data[i].volt_nominal == volt)
265 return &vdd->volt_data[i];
268 pr_notice("%s: Unable to match the current voltage with the voltage"
269 "table for vdd_%s\n", __func__, voltdm->name);
271 return ERR_PTR(-ENODATA);
275 * omap_voltage_register_pmic() - API to register PMIC specific data
276 * @voltdm: pointer to the VDD for which the PMIC specific data is
278 * @pmic: the structure containing pmic info
280 * This API is to be called by the SOC/PMIC file to specify the
281 * pmic specific info as present in omap_voltdm_pmic structure.
283 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
284 struct omap_voltdm_pmic *pmic)
286 if (!voltdm || IS_ERR(voltdm)) {
287 pr_warning("%s: VDD specified does not exist!\n", __func__);
297 * omap_change_voltscale_method() - API to change the voltage scaling method.
298 * @voltdm: pointer to the VDD whose voltage scaling method
300 * @voltscale_method: the method to be used for voltage scaling.
302 * This API can be used by the board files to change the method of voltage
303 * scaling between vpforceupdate and vcbypass. The parameter values are
304 * defined in voltage.h
306 void omap_change_voltscale_method(struct voltagedomain *voltdm,
307 int voltscale_method)
309 struct omap_vdd_info *vdd;
311 if (!voltdm || IS_ERR(voltdm)) {
312 pr_warning("%s: VDD specified does not exist!\n", __func__);
318 switch (voltscale_method) {
319 case VOLTSCALE_VPFORCEUPDATE:
320 vdd->volt_scale = omap_vp_forceupdate_scale;
322 case VOLTSCALE_VCBYPASS:
323 vdd->volt_scale = omap_vc_bypass_scale;
326 pr_warning("%s: Trying to change the method of voltage scaling"
327 "to an unsupported one!\n", __func__);
332 * omap_voltage_late_init() - Init the various voltage parameters
334 * This API is to be called in the later stages of the
335 * system boot to init the voltage controller and
336 * voltage processors.
338 int __init omap_voltage_late_init(void)
340 struct voltagedomain *voltdm;
342 if (list_empty(&voltdm_list)) {
343 pr_err("%s: Voltage driver support not added\n",
348 list_for_each_entry(voltdm, &voltdm_list, node) {
349 if (!voltdm->scalable)
353 voltdm->vdd->volt_scale = omap_vc_bypass_scale;
354 omap_vc_init_channel(voltdm);
358 if (omap_vdd_data_configure(voltdm))
360 omap_vp_init(voltdm);
367 static struct voltagedomain *_voltdm_lookup(const char *name)
369 struct voltagedomain *voltdm, *temp_voltdm;
373 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
374 if (!strcmp(name, temp_voltdm->name)) {
375 voltdm = temp_voltdm;
384 * voltdm_add_pwrdm - add a powerdomain to a voltagedomain
385 * @voltdm: struct voltagedomain * to add the powerdomain to
386 * @pwrdm: struct powerdomain * to associate with a voltagedomain
388 * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This
389 * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if
390 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
393 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm)
395 if (!voltdm || !pwrdm)
398 pr_debug("voltagedomain: associating powerdomain %s with voltagedomain "
399 "%s\n", pwrdm->name, voltdm->name);
401 list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list);
407 * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
408 * @voltdm: struct voltagedomain * to iterate over
409 * @fn: callback function *
411 * Call the supplied function @fn for each powerdomain in the
412 * voltagedomain @voltdm. Returns -EINVAL if presented with invalid
413 * pointers; or passes along the last return value of the callback
414 * function, which should be 0 for success or anything else to
417 int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
418 int (*fn)(struct voltagedomain *voltdm,
419 struct powerdomain *pwrdm))
421 struct powerdomain *pwrdm;
427 list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node)
428 ret = (*fn)(voltdm, pwrdm);
434 * voltdm_for_each - call function on each registered voltagedomain
435 * @fn: callback function *
437 * Call the supplied function @fn for each registered voltagedomain.
438 * The callback function @fn can return anything but 0 to bail out
439 * early from the iterator. Returns the last return value of the
440 * callback function, which should be 0 for success or anything else
441 * to indicate failure; or -EINVAL if the function pointer is null.
443 int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
446 struct voltagedomain *temp_voltdm;
452 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
453 ret = (*fn)(temp_voltdm, user);
461 static int _voltdm_register(struct voltagedomain *voltdm)
463 if (!voltdm || !voltdm->name)
466 INIT_LIST_HEAD(&voltdm->pwrdm_list);
467 list_add(&voltdm->node, &voltdm_list);
469 pr_debug("voltagedomain: registered %s\n", voltdm->name);
475 * voltdm_lookup - look up a voltagedomain by name, return a pointer
476 * @name: name of voltagedomain
478 * Find a registered voltagedomain by its name @name. Returns a pointer
479 * to the struct voltagedomain if found, or NULL otherwise.
481 struct voltagedomain *voltdm_lookup(const char *name)
483 struct voltagedomain *voltdm ;
488 voltdm = _voltdm_lookup(name);
494 * voltdm_init - set up the voltagedomain layer
495 * @voltdm_list: array of struct voltagedomain pointers to register
497 * Loop through the array of voltagedomains @voltdm_list, registering all
498 * that are available on the current CPU. If voltdm_list is supplied
499 * and not null, all of the referenced voltagedomains will be
500 * registered. No return value.
502 void voltdm_init(struct voltagedomain **voltdms)
504 struct voltagedomain **v;
507 for (v = voltdms; *v; v++)
508 _voltdm_register(*v);