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/export.h>
26 #include <linux/debugfs.h>
27 #include <linux/slab.h>
28 #include <linux/clk.h>
32 #include "prm-regbits-34xx.h"
33 #include "prm-regbits-44xx.h"
36 #include "prminst44xx.h"
40 #include "powerdomain.h"
45 static LIST_HEAD(voltdm_list
);
47 /* Public functions */
49 * voltdm_get_voltage() - Gets the current non-auto-compensated voltage
50 * @voltdm: pointer to the voltdm for which current voltage info is needed
52 * API to get the current non-auto-compensated voltage for a voltage domain.
53 * Returns 0 in case of error else returns the current voltage.
55 unsigned long voltdm_get_voltage(struct voltagedomain
*voltdm
)
57 if (!voltdm
|| IS_ERR(voltdm
)) {
58 pr_warning("%s: VDD specified does not exist!\n", __func__
);
62 return voltdm
->nominal_volt
;
66 * voltdm_scale() - API to scale voltage of a particular voltage domain.
67 * @voltdm: pointer to the voltage domain which is to be scaled.
68 * @target_volt: The target voltage of the voltage domain
70 * This API should be called by the kernel to do the voltage scaling
71 * for a particular voltage domain during DVFS.
73 int voltdm_scale(struct voltagedomain
*voltdm
,
74 unsigned long target_volt
)
77 unsigned long volt
= 0;
79 if (!voltdm
|| IS_ERR(voltdm
)) {
80 pr_warning("%s: VDD specified does not exist!\n", __func__
);
85 pr_err("%s: No voltage scale API registered for vdd_%s\n",
86 __func__
, voltdm
->name
);
90 /* Adjust voltage to the exact voltage from the OPP table */
91 for (i
= 0; voltdm
->volt_data
[i
].volt_nominal
!= 0; i
++) {
92 if (voltdm
->volt_data
[i
].volt_nominal
>= target_volt
) {
93 volt
= voltdm
->volt_data
[i
].volt_nominal
;
99 pr_warning("%s: not scaling. OPP voltage for %lu, not found.\n",
100 __func__
, target_volt
);
104 ret
= voltdm
->scale(voltdm
, volt
);
106 voltdm
->nominal_volt
= volt
;
112 * voltdm_reset() - Resets the voltage of a particular voltage domain
113 * to that of the current OPP.
114 * @voltdm: pointer to the voltage domain whose voltage is to be reset.
116 * This API finds out the correct voltage the voltage domain is supposed
117 * to be at and resets the voltage to that level. Should be used especially
118 * while disabling any voltage compensation modules.
120 void voltdm_reset(struct voltagedomain
*voltdm
)
122 unsigned long target_volt
;
124 if (!voltdm
|| IS_ERR(voltdm
)) {
125 pr_warning("%s: VDD specified does not exist!\n", __func__
);
129 target_volt
= voltdm_get_voltage(voltdm
);
131 pr_err("%s: unable to find current voltage for vdd_%s\n",
132 __func__
, voltdm
->name
);
136 voltdm_scale(voltdm
, target_volt
);
140 * omap_voltage_get_volttable() - API to get the voltage table associated with a
141 * particular voltage domain.
142 * @voltdm: pointer to the VDD for which the voltage table is required
143 * @volt_data: the voltage table for the particular vdd which is to be
144 * populated by this API
146 * This API populates the voltage table associated with a VDD into the
147 * passed parameter pointer. Returns the count of distinct voltages
148 * supported by this vdd.
151 void omap_voltage_get_volttable(struct voltagedomain
*voltdm
,
152 struct omap_volt_data
**volt_data
)
154 if (!voltdm
|| IS_ERR(voltdm
)) {
155 pr_warning("%s: VDD specified does not exist!\n", __func__
);
159 *volt_data
= voltdm
->volt_data
;
163 * omap_voltage_get_voltdata() - API to get the voltage table entry for a
165 * @voltdm: pointer to the VDD whose voltage table has to be searched
166 * @volt: the voltage to be searched in the voltage table
168 * This API searches through the voltage table for the required voltage
169 * domain and tries to find a matching entry for the passed voltage volt.
170 * If a matching entry is found volt_data is populated with that entry.
171 * This API searches only through the non-compensated voltages int the
173 * Returns pointer to the voltage table entry corresponding to volt on
174 * success. Returns -ENODATA if no voltage table exisits for the passed voltage
175 * domain or if there is no matching entry.
177 struct omap_volt_data
*omap_voltage_get_voltdata(struct voltagedomain
*voltdm
,
182 if (!voltdm
|| IS_ERR(voltdm
)) {
183 pr_warning("%s: VDD specified does not exist!\n", __func__
);
184 return ERR_PTR(-EINVAL
);
187 if (!voltdm
->volt_data
) {
188 pr_warning("%s: voltage table does not exist for vdd_%s\n",
189 __func__
, voltdm
->name
);
190 return ERR_PTR(-ENODATA
);
193 for (i
= 0; voltdm
->volt_data
[i
].volt_nominal
!= 0; i
++) {
194 if (voltdm
->volt_data
[i
].volt_nominal
== volt
)
195 return &voltdm
->volt_data
[i
];
198 pr_notice("%s: Unable to match the current voltage with the voltage table for vdd_%s\n",
199 __func__
, voltdm
->name
);
201 return ERR_PTR(-ENODATA
);
205 * omap_voltage_register_pmic() - API to register PMIC specific data
206 * @voltdm: pointer to the VDD for which the PMIC specific data is
208 * @pmic: the structure containing pmic info
210 * This API is to be called by the SOC/PMIC file to specify the
211 * pmic specific info as present in omap_voltdm_pmic structure.
213 int omap_voltage_register_pmic(struct voltagedomain
*voltdm
,
214 struct omap_voltdm_pmic
*pmic
)
216 if (!voltdm
|| IS_ERR(voltdm
)) {
217 pr_warning("%s: VDD specified does not exist!\n", __func__
);
227 * omap_change_voltscale_method() - API to change the voltage scaling method.
228 * @voltdm: pointer to the VDD whose voltage scaling method
230 * @voltscale_method: the method to be used for voltage scaling.
232 * This API can be used by the board files to change the method of voltage
233 * scaling between vpforceupdate and vcbypass. The parameter values are
234 * defined in voltage.h
236 void omap_change_voltscale_method(struct voltagedomain
*voltdm
,
237 int voltscale_method
)
239 if (!voltdm
|| IS_ERR(voltdm
)) {
240 pr_warning("%s: VDD specified does not exist!\n", __func__
);
244 switch (voltscale_method
) {
245 case VOLTSCALE_VPFORCEUPDATE
:
246 voltdm
->scale
= omap_vp_forceupdate_scale
;
248 case VOLTSCALE_VCBYPASS
:
249 voltdm
->scale
= omap_vc_bypass_scale
;
252 pr_warn("%s: Trying to change the method of voltage scaling to an unsupported one!\n",
258 * omap_voltage_late_init() - Init the various voltage parameters
260 * This API is to be called in the later stages of the
261 * system boot to init the voltage controller and
262 * voltage processors.
264 int __init
omap_voltage_late_init(void)
266 struct voltagedomain
*voltdm
;
268 if (list_empty(&voltdm_list
)) {
269 pr_err("%s: Voltage driver support not added\n",
274 list_for_each_entry(voltdm
, &voltdm_list
, node
) {
277 if (!voltdm
->scalable
)
280 sys_ck
= clk_get(NULL
, voltdm
->sys_clk
.name
);
281 if (IS_ERR(sys_ck
)) {
282 pr_warning("%s: Could not get sys clk.\n", __func__
);
285 voltdm
->sys_clk
.rate
= clk_get_rate(sys_ck
);
286 WARN_ON(!voltdm
->sys_clk
.rate
);
290 voltdm
->scale
= omap_vc_bypass_scale
;
291 omap_vc_init_channel(voltdm
);
295 voltdm
->scale
= omap_vp_forceupdate_scale
;
296 omap_vp_init(voltdm
);
303 static struct voltagedomain
*_voltdm_lookup(const char *name
)
305 struct voltagedomain
*voltdm
, *temp_voltdm
;
309 list_for_each_entry(temp_voltdm
, &voltdm_list
, node
) {
310 if (!strcmp(name
, temp_voltdm
->name
)) {
311 voltdm
= temp_voltdm
;
320 * voltdm_add_pwrdm - add a powerdomain to a voltagedomain
321 * @voltdm: struct voltagedomain * to add the powerdomain to
322 * @pwrdm: struct powerdomain * to associate with a voltagedomain
324 * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This
325 * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if
326 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
329 int voltdm_add_pwrdm(struct voltagedomain
*voltdm
, struct powerdomain
*pwrdm
)
331 if (!voltdm
|| !pwrdm
)
334 pr_debug("voltagedomain: %s: associating powerdomain %s\n",
335 voltdm
->name
, pwrdm
->name
);
337 list_add(&pwrdm
->voltdm_node
, &voltdm
->pwrdm_list
);
343 * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm
344 * @voltdm: struct voltagedomain * to iterate over
345 * @fn: callback function *
347 * Call the supplied function @fn for each powerdomain in the
348 * voltagedomain @voltdm. Returns -EINVAL if presented with invalid
349 * pointers; or passes along the last return value of the callback
350 * function, which should be 0 for success or anything else to
353 int voltdm_for_each_pwrdm(struct voltagedomain
*voltdm
,
354 int (*fn
)(struct voltagedomain
*voltdm
,
355 struct powerdomain
*pwrdm
))
357 struct powerdomain
*pwrdm
;
363 list_for_each_entry(pwrdm
, &voltdm
->pwrdm_list
, voltdm_node
)
364 ret
= (*fn
)(voltdm
, pwrdm
);
370 * voltdm_for_each - call function on each registered voltagedomain
371 * @fn: callback function *
373 * Call the supplied function @fn for each registered voltagedomain.
374 * The callback function @fn can return anything but 0 to bail out
375 * early from the iterator. Returns the last return value of the
376 * callback function, which should be 0 for success or anything else
377 * to indicate failure; or -EINVAL if the function pointer is null.
379 int voltdm_for_each(int (*fn
)(struct voltagedomain
*voltdm
, void *user
),
382 struct voltagedomain
*temp_voltdm
;
388 list_for_each_entry(temp_voltdm
, &voltdm_list
, node
) {
389 ret
= (*fn
)(temp_voltdm
, user
);
397 static int _voltdm_register(struct voltagedomain
*voltdm
)
399 if (!voltdm
|| !voltdm
->name
)
402 INIT_LIST_HEAD(&voltdm
->pwrdm_list
);
403 list_add(&voltdm
->node
, &voltdm_list
);
405 pr_debug("voltagedomain: registered %s\n", voltdm
->name
);
411 * voltdm_lookup - look up a voltagedomain by name, return a pointer
412 * @name: name of voltagedomain
414 * Find a registered voltagedomain by its name @name. Returns a pointer
415 * to the struct voltagedomain if found, or NULL otherwise.
417 struct voltagedomain
*voltdm_lookup(const char *name
)
419 struct voltagedomain
*voltdm
;
424 voltdm
= _voltdm_lookup(name
);
430 * voltdm_init - set up the voltagedomain layer
431 * @voltdm_list: array of struct voltagedomain pointers to register
433 * Loop through the array of voltagedomains @voltdm_list, registering all
434 * that are available on the current CPU. If voltdm_list is supplied
435 * and not null, all of the referenced voltagedomains will be
436 * registered. No return value.
438 void voltdm_init(struct voltagedomain
**voltdms
)
440 struct voltagedomain
**v
;
443 for (v
= voltdms
; *v
; v
++)
444 _voltdm_register(*v
);