* [PATCH RFC] regulator: core: Support table based mapping in regulator_set_voltage_time_sel
@ 2012-06-18 2:11 Axel Lin
2012-06-18 9:58 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Axel Lin @ 2012-06-18 2:11 UTC (permalink / raw)
To: linux-kernel; +Cc: Yadwinder Singh Brar, Liam Girdwood, Mark Brown
For table based mapping, we can calculate voltage difference by below equation:
abs(rdev->desc->volt_table[new_selector] - rdev->desc->volt_table[old_selector])
Thus we can make regulator_set_voltage_time_sel work for table based mapping.
regulator_set_voltage_time_sel() only supports linear or table based mapping.
In case it is misused, also warn if neither linear nor table based mapping
is used with regulator_set_voltage_time_sel().
Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
drivers/regulator/core.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index c9a427b..bf0306f 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2305,25 +2305,38 @@ EXPORT_SYMBOL_GPL(regulator_set_voltage_time);
* Provided with the starting and target voltage selectors, this function
* returns time in microseconds required to rise or fall to this new voltage
*
- * Drivers providing uV_step in their regulator_desc and ramp_delay in
- * regulation_constraints can use this as their set_voltage_time_sel()
- * operation.
+ * Drivers providing uV_step or volt_table in their regulator_desc and
+ * ramp_delay in regulation_constraints can use this as their
+ * set_voltage_time_sel() operation.
*/
int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
unsigned int old_selector,
unsigned int new_selector)
{
- if (rdev->desc->uV_step) {
- if (rdev->constraints->ramp_delay)
- return DIV_ROUND_UP(rdev->desc->uV_step *
- abs(new_selector - old_selector),
- rdev->constraints->ramp_delay * 1000);
- if (rdev->desc->ramp_delay)
- return DIV_ROUND_UP(rdev->desc->uV_step *
- abs(new_selector - old_selector),
- rdev->desc->ramp_delay * 1000);
+ unsigned int ramp_delay = 0;
+
+ if (rdev->constraints->ramp_delay)
+ ramp_delay = rdev->constraints->ramp_delay;
+ else if (rdev->desc->ramp_delay)
+ ramp_delay = rdev->desc->ramp_delay;
+
+ if (ramp_delay == 0) {
rdev_warn(rdev, "ramp_delay not set\n");
+ return 0;
}
+
+ if (rdev->desc->uV_step) {
+ return DIV_ROUND_UP(rdev->desc->uV_step *
+ abs(new_selector - old_selector),
+ ramp_delay * 1000);
+ } else if (rdev->desc->volt_table) {
+ return DIV_ROUND_UP(abs(rdev->desc->volt_table[new_selector] -
+ rdev->desc->volt_table[old_selector]),
+ ramp_delay * 1000);
+ } else {
+ rdev_warn(rdev, "Unsupported voltage mapping settings\n");
+ }
+
return 0;
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH RFC] regulator: core: Support table based mapping in regulator_set_voltage_time_sel
2012-06-18 2:11 [PATCH RFC] regulator: core: Support table based mapping in regulator_set_voltage_time_sel Axel Lin
@ 2012-06-18 9:58 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2012-06-18 9:58 UTC (permalink / raw)
To: Axel Lin; +Cc: linux-kernel, Yadwinder Singh Brar, Liam Girdwood
[-- Attachment #1: Type: text/plain, Size: 424 bytes --]
On Mon, Jun 18, 2012 at 10:11:28AM +0800, Axel Lin wrote:
> For table based mapping, we can calculate voltage difference by below equation:
> abs(rdev->desc->volt_table[new_selector] - rdev->desc->volt_table[old_selector])
I've applied this since it's incrementally an improvement but really the
fix here should be to just do this in terms of list_voltage() - call
that on the two selectors and then do the multiplication.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-06-18 9:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-18 2:11 [PATCH RFC] regulator: core: Support table based mapping in regulator_set_voltage_time_sel Axel Lin
2012-06-18 9:58 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox